-
-
Notifications
You must be signed in to change notification settings - Fork 35.7k
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
TSL: Fix bitangent*
if used material.flatShading
#30837
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
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.
Pull Request Overview
This PR fixes issues with bitangent computations when materials use flat shading. It updates various accessors to conditionally assign varyings based on the material’s flatShading flag.
- Update TextureNode to pass the builder parameter to getUV
- Update Normal to conditionally assign a varying for normalWorld based on flatShading
- Update Bitangent accessor implementation to correctly handle flatShading and adjust type annotations
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/nodes/accessors/TextureNode.js | Passes builder to getUV to ensure the correct context is available |
src/nodes/accessors/Normal.js | Refactors normalWorld creation to use conditional varying assignment based on material.flatShading |
src/nodes/accessors/Bitangent.js | Wraps getBitangent in Fn, adds a varyingName argument, and standardizes bitangent types |
Comments suppressed due to low confidence (3)
src/nodes/accessors/TextureNode.js:331
- Confirm that the updated call to getUV with the additional 'builder' parameter matches the expected API and is consistent with all call sites.
uvNode = builder.context.getUV( this, builder );
src/nodes/accessors/Normal.js:78
- Ensure that omitting the varying assignment for 'normal' when flat shading is enabled is the intended behavior and aligns with the shading strategy.
if ( builder.material.flatShading !== true ) {
src/nodes/accessors/Bitangent.js:21
- Consider using the computed 'bitangent' (from crossNormalTangent.mul(tangentGeometry.w).xyz) instead of 'crossNormalTangent' when assigning the varying to ensure the correct value is propagated.
bitangent = varying( crossNormalTangent, varyingName );
If the front side is extruded by a normal map, then the back side should be indented. With this PR, both sides are extruded when tangents are present and flat shading is You can fix that in a separate PR if you wish. |
@sunag Are you planning on fixing the problem in this PR, or in another one? |
This reverts commit dcd54ba.
I agree, but apparently I'm getting these results here. gltf.scene.children[ 0 ].geometry.computeTangents();
gltf.scene.children[ 0 ].material.side = THREE.DoubleSide;
gltf.scene.children[ 0 ].material.flatShading = true; |
In fact something is wrong, it seems to be related to the camera angle, I will have to check the code. |
@WestLangley I will make this fix in another PR due to the amount of change. |
Related issue: #30828 (comment)
Description
Fix
bitangent*
if usedmaterial.flatShading
.