-
-
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
MikkTSpaceTangents: Generating tangents for "NormalTangentTest" glTF sample model breaks normals #25263
Comments
@gkjohnson it looks like the correct way to update the mesh for MikkTSpace tangents would be: const geometries = new Set();
const materials = new Set();
gltf.scene.traverse( ( object ) => {
if ( object.isMesh ) {
geometries.add( object.geometry );
materials.add( object.material );
}
} );
for ( const geometry of geometries ) {
BufferGeometryUtils.computeMikkTSpaceTangents( geometry, MikkTSpace );
}
for ( const material of materials ) {
if ( material.normalScale ) material.normalScale.y *= - 1;
if ( material.clearcoatNormalScale ) material.clearcoatNormalScale.y *= - 1;
} The tangent inversion is correct, but does require changes to the material properties. That would also explain why my generating tangents with glTF Transform did not cause the same issue: GLTFLoader sees the tangents in that case, and applies the necessary material changes automatically. Related: |
Perhaps it would also be fine to disable |
Okay I see - interesting. Thanks!
So if I clear the tangents and then generate them again how can I make sure they line up with the appropriate material properties appropriately? If I clear the tangents would I need to multiple the normal scale - 1 again? #18112 may answer this question but just to be sure. |
If we're talking about arbitrary three.js scenes, it might be hard to know whether a material has been configured with vertex tangents in mind, or what UV convention has been used (which would have related effects). If we're talking about glTF source models, then it's helpful to know any
|
Great, thanks! |
Description
When loading the glTF sample NormalTangentTest model and manually generating tangents using the
BufferGeometryUtils.computeMikkTSpaceTangents
function the computed normals change and the model renders incorrectly.However according to the spec - MikkTSpace tangents should produce the correct result:
It looks like the
computeMikkTSpaceTangents
function inverts the tangent direction by default here specifically noting alignment for glTF files. However disabling this behavior by passing "false" into the function fixes the issue. Is the tangent inversion correct?three.js/examples/jsm/utils/BufferGeometryUtils.js
Lines 81 to 92 in 982a715
Related to gkjohnson/three-gpu-pathtracer#210 (comment)
cc @donmccurdy
Reproduction steps
BufferGeometryUtils.computeMikkTSpaceTangents
Code
See jsfiddle
Live example
https://jsfiddle.net/kpj76ob0/2/
Screenshots
computeMikkTSpaceTangents( geometry, MikkTSpace )
computeMikkTSpaceTangents( geometry, MikkTSpace, false ) or no tangent generation
Version
r147
Device
Desktop
Browser
Chrome
OS
Windows, MacOS
The text was updated successfully, but these errors were encountered: