Skip to content

CSMShadowNode: Fix toggle of castShadow.#31186

Merged
Mugen87 merged 2 commits into
mrdoob:devfrom
Mugen87:dev1
May 28, 2025
Merged

CSMShadowNode: Fix toggle of castShadow.#31186
Mugen87 merged 2 commits into
mrdoob:devfrom
Mugen87:dev1

Conversation

@Mugen87

@Mugen87 Mugen87 commented May 27, 2025

Copy link
Copy Markdown
Collaborator

Related issue: #31183

Description

It was not possible so far to toggle the castShadow property of directional lights using CSMShadowNode.

AnalyticLightNode calls dispose() on shadow nodes that are not used anymore. CSMShadowNode uses its dispose() method to remove additions to the scene graph to make cascading work. If the instance of CSMShadowNode is now used again (because castShadow is set back to true), the state must be restored. The PR is doing this in updateBefore().

@sunag I have updated ShadowBaseNode by removing the dispose() method. Setting updateBeforeType to NodeUpdateType.NONE is an issue since when a shadow node is reused after a dispose, updateBefore() is never executed anymore. Because updateBefore() is not called when lights don't cast shadows, it seems better to not change updateBeforeType so shadow nodes don't have restore the update type on their own.

gui.add( params, 'shadows' ).onChange( function ( value ) {

renderer.shadowMap.enabled = value;
csmDirectionalLight.castShadow = value;

@Mugen87 Mugen87 May 27, 2025

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Globally toggling shadows was never an ideal solution. With this PR, CSM shadows can be toggled on light level which is way more intuitive (and practical).

@github-actions

github-actions Bot commented May 27, 2025

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 337.26
78.64
337.26
78.64
+0 B
+0 B
WebGPU 551.84
153.07
551.8
153.06
-40 B
-9 B
WebGPU Nodes 551.19
152.91
551.15
152.9
-40 B
-9 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 468.44
113.28
468.44
113.28
+0 B
+0 B
WebGPU 626.86
169.75
626.82
169.74
-35 B
-9 B
WebGPU Nodes 581.71
159.08
581.67
159.08
-35 B
-8 B

@sunag sunag added this to the r177 milestone May 27, 2025
@Mugen87 Mugen87 merged commit 2dba5a8 into mrdoob:dev May 28, 2025
12 checks passed
RuthySheffi pushed a commit to RuthySheffi/three.js that referenced this pull request Jun 5, 2025
* CSMShadowNode: Fix toggle of `castShadow`.

* CSMShadowNode: Add comment.
RuthySheffi pushed a commit to RuthySheffi/three.js that referenced this pull request Jun 5, 2025
* CSMShadowNode: Fix toggle of `castShadow`.

* CSMShadowNode: Add comment.
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