Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MeshNormalNodeMaterial: Convert packed normal to working color space #30590

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

WestLangley
Copy link
Collaborator

@WestLangley WestLangley commented Feb 23, 2025

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.

@WestLangley WestLangley added this to the r174 milestone Feb 23, 2025
Copy link

github-actions bot commented Feb 23, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 336.65
78.39
336.65
78.39
+0 B
+0 B
WebGPU 522.37
144.98
522.33
145
-34 B
+19 B
WebGPU Nodes 521.83
144.88
521.8
144.9
-34 B
+19 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 465.7
112.26
465.7
112.26
+0 B
+0 B
WebGPU 592.8
160.61
592.8
160.62
+7 B
+7 B
WebGPU Nodes 547.93
150.06
547.93
150.06
+0 B
+0 B

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 ) );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind removing the SRGBColorSpace from that line. toWorkingColorSpace() has just one parameter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops... but can you explain how it converts to working color space without knowing what color space to convert from?

Copy link
Collaborator

@Mugen87 Mugen87 Feb 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

/**
* TSL function for converting a given color node from the given color space to the current working color space.
*
* @tsl
* @function
* @param {Node} node - Represents the node to convert.
* @param {string} colorSpace - The source color space.
* @returns {ColorSpaceNode}
*/
export const colorSpaceToWorking = ( node, colorSpace ) => nodeObject( new ColorSpaceNode( nodeObject( node ), colorSpace, WORKING_COLOR_SPACE ) );

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 23, 2025

It seems a few examples using WebGPURenderer and a normal material require updated E2E screenshots.

@WestLangley
Copy link
Collaborator Author

It seems a few examples using WebGPURenderer and a normal material require updated E2E screenshots.

I have been unable to successfully update screenshots for some time now, unfortunately.

@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 23, 2025

There is a trick you can use: If you open the failed CI job, you can actually download the actual and expected screenshots but only from the failed examples.

image

The artifact download link is at the bottom of the section "Upload Output Screenshots". If you now use the _actual screenshots from the downloaded zips and replace the contents in examples/screenshots, the CI should work again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MeshNormalMaterial Color Differences Across Renderers
2 participants