Skip to content

Fix incorrect Mesh2d world normal and tangent computation - #25369

Open
kevthedawg wants to merge 3 commits into
bevyengine:mainfrom
kevthedawg:fix-mesh2d-world-normal-tangent
Open

Fix incorrect Mesh2d world normal and tangent computation#25369
kevthedawg wants to merge 3 commits into
bevyengine:mainfrom
kevthedawg:fix-mesh2d-world-normal-tangent

Conversation

@kevthedawg

@kevthedawg kevthedawg commented Aug 11, 2026

Copy link
Copy Markdown

Objective

Solution

Bring both functions to parity with bevy_pbr: normalize, skipping zero vectors so they don't become NaN, and multiply the tangent's w by the sign of the model matrix determinant. That sign needs a SIGN_DETERMINANT_MODEL_3X3 flag on 2D's MeshFlags, so mesh2d_tangent_local_to_world now takes the instance index. The flag is derived in Mesh2dUniform::from_components, so custom extraction systems keep working unchanged.

Testing

New Tangents scene in examples/testbed/2d.rs draws the tangent space of a scaled quad and a mirrored one, turning red where a vector is not unit length. Removing either normalize(), 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.

@github-actions

Copy link
Copy Markdown
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 ✨

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen A-Math Fundamental domain-agnostic mathematical operations S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 11, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering Aug 11, 2026
@alice-i-cecile alice-i-cecile added this to the 0.20 milestone Aug 11, 2026
@alice-i-cecile alice-i-cecile added X-Uncontroversial This work is generally agreed upon D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Math Fundamental domain-agnostic mathematical operations A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Uncontroversial This work is generally agreed upon

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

Mesh2d world_normal and world_tangent computation is incorrect

2 participants