Fix incorrect Mesh2d world normal and tangent computation - #25369
Open
kevthedawg wants to merge 3 commits into
Open
Fix incorrect Mesh2d world normal and tangent computation#25369kevthedawg wants to merge 3 commits into
Mesh2d world normal and tangent computation#25369kevthedawg wants to merge 3 commits into
Conversation
Contributor
|
Welcome, new contributor! Please make sure you've read our contributing guide, as well as our policy regarding AI usage, and we look forward to reviewing your pull request shortly ✨ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
world_normalandworld_tangentcomputation is incorrect #24614.mesh2d_normal_local_to_worldandmesh2d_tangent_local_to_worlddon't normalize their result, so a scaledTransformscalesworld_normalby the inverse of the scale andworld_tangentby the scale.examples/2d/mesh2d.rsscales by 128, giving a normal of length 1/128 and a tangent of 128.wis passed through unchanged too, so mirrored transforms keep the wrong handedness. That is what makes this a breaking change.bevy_pbr, but themesh2dcopies from [Merged by Bors] - Add reusable shader functions for transforming position/normal/tangent #4901 were left behind.SpriteMaterialcalls the same functions and is affected too.Solution
Bring both functions to parity with
bevy_pbr: normalize, skipping zero vectors so they don't become NaN, and multiply the tangent'swby the sign of the model matrix determinant. That sign needs aSIGN_DETERMINANT_MODEL_3X3flag on 2D'sMeshFlags, somesh2d_tangent_local_to_worldnow takes the instance index. The flag is derived inMesh2dUniform::from_components, so custom extraction systems keep working unchanged.Testing
New
Tangentsscene inexamples/testbed/2d.rsdraws the tangent space of a scaled quad and a mirrored one, turning red where a vector is not unit length. Removing eithernormalize(), or either half of the sign correction, turns the matching band red. No existing screenshot changes, since no built-in 2D fragment shader reads these, but the new scene needs a baseline.