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

Enhance checks and user experience around tangent arrays in meshes. #84252

Merged
merged 1 commit into from
Nov 2, 2023

Conversation

clayjohn
Copy link
Member

Fixes: #83236
Fixes: #83850

In both linked MRPs the user was attempting to read tangents in a shader from a mesh with no tangents. The behaviour in 4.1 was for Godot to supply a dummy tangent (1, 0, 0). That is no longer possible without a performance penalty (but it is possible see here).

Since it was never supported behaviour to read from non-existent tangents (see the strong warning in the docs for normal_texture) and the result of relying would typically look horrible. We decided not to bring back the previous behaviour and instead try to make the usage of tangents more intuitive and user-friendly.

We do that with three things:

  1. Ensure ensure_tangents option actually creates tangent array. Even if it is just a dummy array.

Previous, we gave up on generating a tangent array if there were no UVs in the mesh.

This ensures that most imported meshes have tangent arrays. It is how the "ensure tangents" option was intended to work and it aligns with the name. Users who don't want tangents can uncheck the option with no harm to their mesh. This is much preferable to the old behaviour as the tangent used will now actually be tangential to the normal.

  1. Allow mesh to generate its own tangents when using compression. This allows users to compress meshes without tangents.

Even if no tangent array is used, we need tangents to compress the mesh and we have good performance savings when using mesh compression. So this is a fallback to ensure that meshes can be compressed, even if just using normals

  1. Warn users if they are trying to read from tangents without providing tangents.

This is the needed for cases like #83236 where the user is generating their own mesh and is relying on normal mapping, but has forgotten to create tangents. This warning warns the user while pairing the material to a mesh (which only happens once).


Taken together, these 3 things should ensure that most users can carry on without any changes. Some users will run into the warning and have to generate tangents. But the end result should be much better for everyone.

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

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

Looks good to me from a cursory review.

Ensure `ensure_tangents` option actually creates tangent array. Even if it is just a dummy array.

Allow mesh to generate its own tangents when using compression. This allows users to compress meshes without tangents.

Warn users if they are trying to read from tangents without providing tangents.
@akien-mga akien-mga merged commit 44a54f4 into godotengine:master Nov 2, 2023
15 checks passed
@akien-mga
Copy link
Member

Thanks!

@clayjohn clayjohn deleted the ensure_tangents branch February 23, 2024 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants