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

Fix a couple issues with glTF tangent processing. #6302

Merged
merged 2 commits into from
Mar 2, 2018
Merged

Conversation

emackey
Copy link
Contributor

@emackey emackey commented Mar 2, 2018

Recently I created a new model, NormalTangentMirrorTest to test what happens in a rendering engine when a glTF supplies tangent vectors. A previous model called NormalTangentTest was testing an engine's ability to calculate missing tangent vectors.

Cesium does a great job of calculating any missing tangent vectors, but unfortunately, when the vectors are supplied in the model, things were very broken. Looking at the code, I found these issues:

  • Cesium was treating 'TANGENT' as VEC3 when the glTF spec says it's VEC4.
  • Cesium was multiplying tangents by u_modelViewMatrix instead of u_normalMatrix.
  • Cesium was not taking the w component of the tangent into account.

The glTF spec has this to say about using the w component of supplied tangent vectors:

Client implementations should compute the bitangent by taking the cross product of the normal and tangent xyz vectors and multiplying against the w component of the tangent: bitangent = cross(normal, tangent.xyz) * tangent.w

On master, my new tangent test model looks like this:

gltf-tangents-bad

On this branch, with the above-mentioned fixes applied, things look correct:

gltf-tangents-good

@cesium-concierge
Copy link

Signed CLA is on file.

@emackey, thanks for the pull request! Maintainers, we have a signed CLA from @emackey, so you can review this at any time.

⚠️ I noticed that CHANGES.md has not been updated. If this change updates the public API in any way, fixes a bug, or makes any non-trivial update, please add a bullet point to CHANGES.md and comment on this pull request so we know it was updated. For more info, see the Pull Request Guidelines.

⚠️ I noticed that a file in one of our ThirdParty folders (ThirdParty/, Source/ThirdParty/) has been added or modified. Please verify that it has a section in LICENSE.md and that its license information is up to date with this new version. Once you do, please confirm by commenting on this pull request.


I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome.

🌍 🌎 🌏

@mramato
Copy link
Contributor

mramato commented Mar 2, 2018

Thanks @emackey, did you open a corresponding gltf-pipeline request? This is third party code from that repository's 2.0 branch.

@emackey
Copy link
Contributor Author

emackey commented Mar 2, 2018

Yes, it's: CesiumGS/gltf-pipeline#350

@lilleyse
Copy link
Contributor

lilleyse commented Mar 2, 2018

Thanks for the fix!

@lilleyse lilleyse merged commit b1f61de into master Mar 2, 2018
@lilleyse lilleyse deleted the gltf-tangents branch March 2, 2018 20:59
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.

4 participants