Skip to content

LightsNode: Honor light version for shadow casting lights. - #34949

Merged
sunag merged 1 commit into
mrdoob:devfrom
Mugen87:dev3
Oct 11, 2026
Merged

sunag merged 1 commit into
mrdoob:devfrom
Mugen87:dev3

Conversation

@Mugen87

@Mugen87 Mugen87 commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Fixed #34942.

Description

#34942 shows a unfortunate edge case that is not obvious to fix in the renderer. It has to do with the fact how a light node manages shadow nodes.

The main problem is that a light node can outlive the shadow nodes it puts into shaders. That can happen if the user toggles castShadow. So a shadow casting light keeps its light node but the shadow node is disposed and set to null.

This procedure actually invalidates all shaders that are currently work with this shadow node. If render objects are directly updated in the next frame, they see the difference and rebuild. But #34942 describes a case where this does not work. Because of the visibility toggle, render objects can produce the same cache key and refer to the same state which is however obsolete.

Because of the way how light nodes are managed, the only way render objects see the lighting state is LightsNode.customCacheKey(). The PR adds the light node's version to this key if shadow casting is enabled. In AnalyticLightNode, the node's version is now bumped during the disposal. That makes sure render objects never see an outdated shadow node but force a rebuild with the new ones.

@Mugen87
Mugen87 requested a review from sunag October 10, 2026 12:06
@github-actions

Copy link
Copy Markdown

πŸ“¦ Bundle size

Full ESM build including core, minified and gzipped.

Before After Diff
Core 390.53
102.46
390.53
102.46
+0 B
+0 B
WebGL 776.95
194.03
776.95
194.03
+0 B
+0 B
WebGPU 1089.68
293.76
1089.69
293.78
+5 B
+20 B
WebGPU Nodes 1087.63
293.41
1087.64
293.43
+5 B
+24 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 518.47
124.58
518.47
124.58
+0 B
+0 B
WebGPU 769.32
206.26
769.32
206.28
+5 B
+15 B
WebGPU Nodes 716.57
193.02
716.58
193.04
+5 B
+16 B

@sunag
sunag merged commit 755f6e4 into mrdoob:dev Oct 11, 2026
10 checks passed
@sunag sunag added this to the r187 milestone Oct 11, 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.

ShadowNode: Cannot read properties of null (reading 'depthTexture') after a light stops and resumes casting while its only receiver is hidden

2 participants