-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
MeshStandardMaterial: Remove .vertexTangents property #22146
MeshStandardMaterial: Remove .vertexTangents property #22146
Conversation
Aside, I'm also interested in removing other material boolean flags that could be inferred from context:
Are there any of these we'd prefer to keep as explicit, opt-in properties? /cc @elalish, related to mapping three.js materials to/from source glTF materials. |
Some useful test cases below. Results appear to be identical before/after in each.
|
Can we infer |
Precisely, in fact this is how the glTF standard defines this as well. Removing duplicate info is a great way to simplify code and avoid bugs, so I'm all in favor. Thanks @donmccurdy! |
I feel pretty strongly that these two properties shouldn't be removed from materials because they're used to stylistically control the rendering of the geometry and the ability to toggle them without messing with the geometry is useful (and more intuitive). For my work, for example, vertex colors are one option for rendering temperature visualizations and it's something you'd want to be able to turn off (and use the diffuse color only) when the user doesn't want to see it. I also toggle flat shading on geometry even if they have normals because flat shading helps provide more information on the structure of the geometry. Having said that I'm not against changing the flags so they use a more reasonable default inferred from context. For example |
I think we should not discuss the removal of other material flags in this PR but focus on its implementation. Otherwise this will be a hard to follow topic. |
But it sets it. Can you please further explain what you are referring to? flipNormalScaleY: ( ( material.normalMap && material.normalMap.flipY === false || material.clearcoatNormalMap && material.clearcoatNormalMap.flipY === false ) && ! ( object.geometry && object.geometry.attributes.tangent ) ) Can you please explain this line? What are the assumptions upon which this is based? Maybe @elalish can help? |
@WestLangley this PR removes the negation of // Before
materialParams.normalScale = new Vector2( materialDef.normalTexture.scale, - materialDef.normalTexture.scale );
// After
materialParams.normalScale = new Vector2( materialDef.normalTexture.scale, materialDef.normalTexture.scale ); ...unless I've missed another example? Explaining the line you mentioned: // Invert normalScale.y if ...
flipNormalScaleY: (
// ... material has flipY=false on normalMap OR clearcoatNormalMap ...
(
material.normalMap && material.normalMap.flipY === false
|| material.clearcoatNormalMap && material.clearcoatNormalMap.flipY === false
)
// ... AND the geometry does not include vertex tangents.
&& ! ( object.geometry && object.geometry.attributes.tangent )
) One edge case here would be setting both normalMap and clearcoatNormalMap, where only one of the two uses
Sounds good, I'll open a new issue. |
if ( materialDef.normalTexture.scale !== undefined ) { | ||
|
||
materialParams.normalScale.set( materialDef.normalTexture.scale, - materialDef.normalTexture.scale ); | ||
materialParams.normalScale = new Vector2( materialDef.normalTexture.scale, materialDef.normalTexture.scale ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit. optional. your choice.
new Vector2().setScalar( materialDef.normalTexture.scale );
@donmccurdy Thanks for this PR, but TBH, I don't understand the rationale behind the proposed implementation, so I'll bow out of this thread. I do not want to be a blocker -- especially if it seems OK to @mrdoob and others. :-) Once I see how this PR is resolved, I will open a new issue with my thoughts. |
@WestLangley did you mean something different by "honoring the flipY flag in the shader", in the earlier comment? Or this implementation just doesn't fully make sense? |
TBH, I am not sure what I was thinking at the time... // mapN.xy *= normalScale;
#ifdef FLIP_NORMAL_SCALE_Y
mapN.y *= -1.0;
#endif To me, having // // Invert normalScale.y if ...
flipNormalScaleY: (
// ... material has flipY=false on normalMap OR clearcoatNormalMap ...
(
material.normalMap && material.normalMap.flipY === false
|| material.clearcoatNormalMap && material.clearcoatNormalMap.flipY === false
)
// ... AND the geometry does not include vertex tangents.
&& ! ( object.geometry && object.geometry.attributes.tangent )
) I also do not understand why, if |
The user has no explicit way to tell us the tangent space convention used by the normal map, but I think it is reasonable to infer that from the |
@donmccurdy I think it is more complex than that due to the flexibility of three.js. Perhaps the demo provided in #22165 will be helpful. |
Is the purpose of Some alternatives, then...
I suppose (B) is the simpler of the two, I'm happy to switch to that if you agree. |
I'm overthinking this. 😅 Thanks for steering this in the right direction @WestLangley. It sounds like we just need this flag to be:
... and avoid the whole @elalish it does not sound likely that 1:1 glTF↔three.js material mappings are going to be possible, for several reasons. I think I would advise planning around robust 1:many mappings instead, improving GLTFLoader for that purpose if needed. |
Yeah, I pretty much expected that. We handle it now and hopefully it won't be too bug-prone. |
Started a separate issue for discussion of morphNormals and morphTargets: #22166 |
Thanks! |
Following up in #22182 to address feedback, I'd meant to revert a part of this change. |
This change is, I hope, in line with @WestLangley's comments in #11438 (comment), "we may be able to fix this automatically by honoring the flipY flag in the shader". Effects:
vertexTangents
; they're enabled automatically similarly to vertex alpha.normalScale.set(1, -1)
(previously required because all textures useflipY=false
)flipY=false
, but follow some other UV coordinate convention, may need to begin settingnormalScale.set(1, -1)
. I'm not aware of any such use.