MeshNormalNodeMaterial: Convert packed normal to working color space#30590
MeshNormalNodeMaterial: Convert packed normal to working color space#30590Mugen87 merged 4 commits intomrdoob:devfrom
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
| diffuseColor.assign( vec4( directionToColor( transformedNormalView ), opacityNode ) ); | ||
| // By convention, a normal packed to RGB is in sRGB color space. Convert it to working color space. | ||
|
|
||
| diffuseColor.assign( toWorkingColorSpace( vec4( directionToColor( transformedNormalView ), opacityNode ), SRGBColorSpace ) ); |
There was a problem hiding this comment.
Do you mind removing the SRGBColorSpace from that line. toWorkingColorSpace() has just one parameter.
There was a problem hiding this comment.
Oops... but can you explain how it converts to working color space without knowing what color space to convert from?
There was a problem hiding this comment.
The function assumes the given color node is in output color space.
There is an alternative TSL function that is more flexible in that regard:
three.js/src/nodes/display/ColorSpaceNode.js
Lines 160 to 169 in 3bb6e70
There was a problem hiding this comment.
The function (
toWorkingColorSpace) assumes the given color node is in output color space.
Then it should be called toWorkingColorSpaceFromOutputColorSpace.
Is "output color space" the renderer's output color space?... I guess that is true...
Then the inverse method should be toOutputColorSpaceFromWorkingColorSpace.
There was a problem hiding this comment.
These are fine, since the source and destination are clear -- although I prefer using the more specific terms: targetColorSpace and sourceColorSpace.
three.js/src/nodes/display/ColorSpaceNode.js
Line 158 in 972f726
three.js/src/nodes/display/ColorSpaceNode.js
Line 169 in 972f726
//
These are also fine, for the same reason -- although I would rename them. and adhere to the same nomenclature as above: workingToColorSpace( color, targetColorSpace ) and colorSpaceToWorking( color, sourceColorSpace ).
three.js/src/math/ColorManagement.js
Lines 79 to 89 in 972f726
//
But I think these should be removed, as is it not clear from the name what they do, and it is not clear to me why they are needed.
three.js/src/nodes/display/ColorSpaceNode.js
Line 137 in 972f726
three.js/src/nodes/display/ColorSpaceNode.js
Line 147 in 972f726
/ping @gkjohnson
There was a problem hiding this comment.
But I think these should be removed, as is it not clear from the name what they do, and it is not clear to me why they are needed.
I haven't used nodes much yet but I tend to agree that more explicit functions are better and using functions that assume information about color spaces can make code unclear.
There was a problem hiding this comment.
@Mugen87 When you get a chance, can you think about this a bit? 🙏
All we need are these two methods: workingToColorSpace() and colorSpaceToWorking() -- in both ColorSpaceNode.js and ColorManagement.js. This avoids having different nomenclatures for the same thing.
There was a problem hiding this comment.
I'll try to revisit this issue when the JSDoc migration has been finished.
|
It seems a few examples using |
I have been unable to successfully update screenshots for some time now, unfortunately. |

Fixes #30575.
Also #28831 (comment).
By convention, the packed normal, when interpreted as a color, is assumed to be in sRGB color space. It must be converted to linear working color space.