Fix inverted normal mapping on WebGPU (derivative TBN)#9099
Merged
Conversation
The derivative-based tangent frame (TBN.js) is scaled by the tbnBasis uniform, which only accounted for the projection Y flip applied when rendering with flipY. On WebGPU, screen-space dpdy has the opposite sign to WebGL's dFdy (framebuffer space is Y-down), which negates the computed tangent and bitangent and rotates the tangent-space normal 180 degrees, producing inverted normal-mapped lighting for meshes without vertex tangents. Fold the backend into the sign so it stays consistent. Fixes #5735
Build size reportThis PR changes the size of the minified bundles.
|
mvaligursky
added a commit
that referenced
this pull request
Jul 22, 2026
The derivative-based tangent frame (TBN.js) is scaled by the tbnBasis uniform, which only accounted for the projection Y flip applied when rendering with flipY. On WebGPU, screen-space dpdy has the opposite sign to WebGL's dFdy (framebuffer space is Y-down), which negates the computed tangent and bitangent and rotates the tangent-space normal 180 degrees, producing inverted normal-mapped lighting for meshes without vertex tangents. Fold the backend into the sign so it stays consistent. Fixes #5735 Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
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.
Fixes #5735, fixes #6984, fixes #8905 — inverted normal-mapped lighting on WebGPU for meshes that have no vertex tangents (the tangent frame is derived from screen-space derivatives). Confirmed against the Khronos NormalTangentTest — WebGPU now matches WebGL2 and the reference. (#6984 and #8905 are duplicate reports of the same issue.)
Cause:
TBN.jsis scaled by thetbnBasisuniform, which was set purely from the render target'sflipY(originally added to correct offscreen render-to-texture on WebGL).dpdyhas the opposite sign to WebGL'sdFdy. This negates the computed tangent and bitangent, rotating the tangent-space normal 180° and producing inverted lighting.Changes:
Renderer.setCameraUniforms: fold the backend into thetbnBasissign —(device.isWebGPU !== !!flipY) ? -1 : 1. WebGL behavior is unchanged; WebGPU picks up the extra inherent flip.Notes: