Fix double-sided normals for negative scale meshes#24395
Conversation
d188e6f to
d1c8ebf
Compare
kfc35
left a comment
There was a problem hiding this comment.
To the more rendering savvy reviewers who would know, should this fix also be put into the array_texture.wgsl files (under assets/shaders and examples/wasm/assets/shaders)? There is code there that also prepare world normals and applies normal mappings, although presumably it’s for examples / showcasing and not used by the engine itself
Beyond that, this code looks good to me and makes sense mathematically
| #else | ||
| let mesh_flags = mesh[in.instance_index].flags; | ||
| #endif | ||
| let mesh_is_front = pbr_functions::winding_corrected_front_facing(mesh_flags, is_front); |
There was a problem hiding this comment.
Nitpicking on the naming: s/mesh_is_front/is_logically_front
Indeed, either replicate this or add a comment for properly handling handedness-reversing transformations ? |
goodartistscopy
left a comment
There was a problem hiding this comment.
Looks sensible apart from a small naming nit
Objective
Fix incorrect PBR lighting for double-sided meshes with negative-scale transforms.
#8859 fixed culling for single-sided glTF materials by detecting inverted scale in the loader. Double-sided materials still need a shader-side fix, because culling is disabled and raw
front_facingis reversed by negative-scale winding.Solution
Add a winding-corrected front-facing helper in the PBR shader path.
Testing
Tested with Khronos NegativeScaleTest
The bottom-right
-1.0column should match the expected lighting/reflection behavior for double-sided materials.To validate non-regression for normal/tangent handling, reviewers can also test:
NormalTangentMirrorTest
NormalTangentTest
Showcase
Before

After
