Skip to content

WebGLRenderer: Prepare shadow maps without rendering during compile(). - #34239

Open
hybridherbst wants to merge 3 commits into
mrdoob:devfrom
needle-tools:fix/webgl-compile-shadow-setup
Open

WebGLRenderer: Prepare shadow maps without rendering during compile().#34239
hybridherbst wants to merge 3 commits into
mrdoob:devfrom
needle-tools:fix/webgl-compile-shadow-setup

Conversation

@hybridherbst

Copy link
Copy Markdown
Contributor

Related issue: stacked on #34219

Description

When a WebGL node material receives shadows, shader setup needs the shadow map and its depth texture. compile() currently creates these resources by calling shadowMap.render().

Besides rendering actual shadow passes during precompilation (for no reason), this breaks when automatic shadow updates are disabled:

renderer.shadowMap.enabled = true;
renderer.shadowMap.autoUpdate = false;

pointLight.castShadow = true;
mesh.receiveShadow = true;

await renderer.compileAsync( mesh, camera, scene );

Since shadowMap.render() returns before allocating anything, node setup fails with:

TypeError: Cannot read properties of null (reading 'depthTexture')

This change separates shadow-map allocation from rendering, so compile() prepares the required targets without clearing or drawing into them.

I also added a new webgl_tsl_compile_async sample scene (that would fail before this PR).

This contribution is funded by Needle

@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 366.61
86.92
366.85
87.01
+238 B
+91 B
WebGPU 696.95
192.4
696.95
192.4
+0 B
+0 B
WebGPU Nodes 694.94
192.09
694.94
192.09
+0 B
+0 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 509.99
123.86
510.23
123.94
+238 B
+80 B
WebGPU 771.57
207.28
771.57
207.28
+0 B
+0 B
WebGPU Nodes 720.53
194.62
720.53
194.62
+0 B
+0 B

@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown

🖼️ E2E screenshot tests

✅ All examples render correctly again (run).

@hybridherbst

Copy link
Copy Markdown
Contributor Author

@Mugen87 turns out current dev also fails with

renderer.shadowMap.enabled = true;
renderer.shadowMap.autoUpdate = false;

so I think this adjustment to shadow code (to make it reusable and to fix the bug) is justified – let me know what you think!

@hybridherbst
hybridherbst force-pushed the fix/webgl-compile-shadow-setup branch from e7f0787 to c726e2c Compare August 14, 2026 10:22
@Mugen87

Mugen87 commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Um, I'm not yet sure it's worth the effort. I'm not supporting a 100% integration of the node materials in WebGLRenderer since that would cause massive additional maintenance effort. WebGLNodesHandler is intended to make the transition to WebGPURenderer easier. So I think it's okay if there are some limitations/restrictions. If the compile() does not work with disabled automatic shadow updates (which is an edge case), we could simply document that before doing a larger refactoring in WebGLShadowMap.

@hybridherbst
hybridherbst force-pushed the fix/webgl-compile-shadow-setup branch from c726e2c to 0139209 Compare August 14, 2026 12:52
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.

2 participants