Skip to content

Commit 6bbc71e

Browse files
Mugen87RuthySheffi
authored andcommitted
CSMShadowNode: Fix toggle of castShadow. (mrdoob#31186)
* CSMShadowNode: Fix toggle of `castShadow`. * CSMShadowNode: Add comment.
1 parent 3f5b0f0 commit 6bbc71e

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

examples/jsm/csm/CSMShadowNode.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ class CSMShadowNode extends ShadowBaseNode {
163163
this.mainFrustum = new CSMFrustum( data );
164164

165165
const light = this.light;
166-
const parent = light.parent;
167166

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

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

176175
this.lights.push( lwLight );
177176

178-
parent.add( lwLight );
179-
parent.add( lwLight.target );
180-
181177
lwLight.shadow = lShadow;
182178

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

505501
const light = this.light;
502+
const parent = light.parent;
506503
const camera = this.camera;
507504
const frustums = this.frustums;
508505

506+
// make sure the placeholder light objects which represent the
507+
// multiple cascade shadow casters are part of the scene graph
508+
509+
for ( let i = 0; i < this.lights.length; i ++ ) {
510+
511+
const lwLight = this.lights[ i ];
512+
513+
if ( lwLight.parent === null ) {
514+
515+
parent.add( lwLight.target );
516+
parent.add( lwLight );
517+
518+
}
519+
520+
}
521+
509522
_lightDirection.subVectors( light.target.position, light.position ).normalize();
510523

511524
// for each frustum we need to find its min-max box aligned with the light orientation

examples/webgpu_shadowmap_csm.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177

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

180-
renderer.shadowMap.enabled = value;
180+
csmDirectionalLight.castShadow = value;
181181

182182
} );
183183

src/nodes/lighting/ShadowBaseNode.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,6 @@ class ShadowBaseNode extends Node {
6868

6969
}
7070

71-
/**
72-
* Can be called when the shadow isn't required anymore. That can happen when
73-
* a lighting node stops casting shadows by setting {@link Object3D#castShadow}
74-
* to `false`.
75-
*/
76-
dispose() {
77-
78-
this.updateBeforeType = NodeUpdateType.NONE;
79-
80-
}
81-
8271
}
8372

8473
/**

0 commit comments

Comments
 (0)