-
-
Notifications
You must be signed in to change notification settings - Fork 36k
MeshNormalNodeMaterial: Convert packed normal to working color space #30590
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,10 +3,12 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||
import { directionToColor } from '../../nodes/utils/Packing.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import { materialOpacity } from '../../nodes/accessors/MaterialNode.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import { transformedNormalView } from '../../nodes/accessors/Normal.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import { float, vec4 } from '../../nodes/tsl/TSLBase.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import { float, vec4, toWorkingColorSpace } from '../../nodes/tsl/TSLBase.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import { SRGBColorSpace } from '../../constants.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
import { MeshNormalMaterial } from '../MeshNormalMaterial.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
const _defaultValues = /*@__PURE__*/ new MeshNormalMaterial(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -54,7 +56,9 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
const opacityNode = this.opacityNode ? float( this.opacityNode ) : materialOpacity; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mind removing the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: three.js/src/nodes/display/ColorSpaceNode.js Lines 160 to 169 in 3bb6e70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Then it should be called Is "output color space" the renderer's output color space?... I guess that is true... Then the inverse method should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are fine, since the source and destination are clear -- although I prefer using the more specific terms: 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: 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Mugen87 When you get a chance, can you think about this a bit? 🙏 All we need are these two methods: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll try to revisit this issue when the JSDoc migration has been finished. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.