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

Support tangent space handedness #8871

Merged
merged 4 commits into from
Jun 3, 2024
Merged

Conversation

Jhonnyg
Copy link
Contributor

@Jhonnyg Jhonnyg commented Apr 30, 2024

Tangents are now produced as vec4 in the engine, where the fourth component is the handedness of the tangent vector. This can then be used to calculate the correct tangent space vectors in a shader:

vec3 bitangent = cross(normal, tangent.xyz * tangent.w);

Fixes #8733

@Jhonnyg Jhonnyg added bug Something is not working as expected engine Issues related to the Defold engine graphics render labels Apr 30, 2024
@Jhonnyg Jhonnyg requested review from matgis and JCash May 6, 2024 14:46
Copy link
Contributor

@matgis matgis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to pass on the unaltered W component of the tangent when transforming to world space? 🤔

:semantic-type :semantic-type-tangent
:coordinate-space :coordinate-space-world
:data-type :type-float
:element-count 4}]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using world-space meshes, the tangents in :tangent-data will be transformed by the renderable-data->world-direction-v4 function. Currently, this writes a zero for the W component when it calls the geom/transf-n4 function. I think we need to update geom/transf-n4 to pass along the unaltered W component.

It seems to me, we would need to do something similar on the engine side since we presumably transform the tangents using the normal matrix somewhere there as well, but I'm not seeing it in this PR? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The engine preserves the handedness in Rig.cpp in the "GenerateNormalData" function.

JCash
JCash previously approved these changes May 8, 2024
Copy link
Contributor

@matgis matgis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Jhonnyg Jhonnyg merged commit a81024c into dev Jun 3, 2024
22 checks passed
@Jhonnyg Jhonnyg deleted the issue-8733-tangent-support-handedness branch June 3, 2024 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working as expected engine Issues related to the Defold engine graphics render
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support tangent vector handedness
3 participants