Skip to content

CSMShadowNode: Fix toggle of castShadow. #31186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions examples/jsm/csm/CSMShadowNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ class CSMShadowNode extends ShadowBaseNode {
this.mainFrustum = new CSMFrustum( data );

const light = this.light;
const parent = light.parent;

for ( let i = 0; i < this.cascades; i ++ ) {

Expand All @@ -175,9 +174,6 @@ class CSMShadowNode extends ShadowBaseNode {

this.lights.push( lwLight );

parent.add( lwLight );
parent.add( lwLight.target );

lwLight.shadow = lShadow;

this._shadowNodes.push( shadow( lwLight, lShadow ) );
Expand Down Expand Up @@ -503,9 +499,26 @@ class CSMShadowNode extends ShadowBaseNode {
updateBefore( /*builder*/ ) {

const light = this.light;
const parent = light.parent;
const camera = this.camera;
const frustums = this.frustums;

// make sure the placeholder light objects which represent the
// multiple cascade shadow casters are part of the scene graph

for ( let i = 0; i < this.lights.length; i ++ ) {

const lwLight = this.lights[ i ];

if ( lwLight.parent === null ) {

parent.add( lwLight.target );
parent.add( lwLight );

}

}

_lightDirection.subVectors( light.target.position, light.position ).normalize();

// for each frustum we need to find its min-max box aligned with the light orientation
Expand Down
2 changes: 1 addition & 1 deletion examples/webgpu_shadowmap_csm.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@

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

renderer.shadowMap.enabled = value;
csmDirectionalLight.castShadow = value;
Copy link
Collaborator Author

@Mugen87 Mugen87 May 27, 2025

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).


} );

Expand Down
11 changes: 0 additions & 11 deletions src/nodes/lighting/ShadowBaseNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,6 @@ class ShadowBaseNode extends Node {

}

/**
* Can be called when the shadow isn't required anymore. That can happen when
* a lighting node stops casting shadows by setting {@link Object3D#castShadow}
* to `false`.
*/
dispose() {

this.updateBeforeType = NodeUpdateType.NONE;

}

}

/**
Expand Down