Skip to content

WebGLRenderer: Implement normal bias fallback.#33391

Merged
Mugen87 merged 2 commits into
mrdoob:devfrom
Mugen87:dev5
Apr 15, 2026
Merged

WebGLRenderer: Implement normal bias fallback.#33391
Mugen87 merged 2 commits into
mrdoob:devfrom
Mugen87:dev5

Conversation

@Mugen87

@Mugen87 Mugen87 commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator

Fixed #21483.

Description

Flat shading with no vertex normals can break shadows on certain devices since shadowWorldNormal might end up with NaN values.

The PR fixes that by introducing a new define that detects whether a geometry has vertex normals or not and only then computes shadowWorldNormal. Otherwise it uses the fallback value.

In WebGPURenderer, we compute the normal bias in the fragment shader so the computation operates on valid normals. Hence, the test asset from #21483 works fine with WebGPURenderer for both WebGL and WebGPU. However, doing the same in WebGLRenderer requires more refactoring and the presented approach is a sensible fallback for this edge case (not every user enabling shadows makes use of normalBias).

@github-actions

github-actions Bot commented Apr 15, 2026

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 361.21
85.78
361.4
85.82
+191 B
+45 B
WebGPU 637.46
177.05
637.46
177.05
+0 B
+0 B
WebGPU Nodes 635.58
176.76
635.58
176.76
+0 B
+0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 493.71
120.45
493.9
120.5
+191 B
+45 B
WebGPU 709.2
191.87
709.2
191.87
+0 B
+0 B
WebGPU Nodes 658.42
179.16
658.42
179.16
+0 B
+0 B

@Mugen87

Mugen87 commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator Author

The PR actually fixes the broken self-shading of the animated horses in webgl_shadowmap_performance.

@Mugen87 Mugen87 merged commit 740dd76 into mrdoob:dev Apr 15, 2026
15 of 16 checks passed
@Mugen87 Mugen87 added this to the r184 milestone Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Certain GLTF models not receiving shadows on Windows

1 participant