Parcourir la source

CSMShadowNode: Fix toggle of `castShadow`. (#31186)

* CSMShadowNode: Fix toggle of `castShadow`.

* CSMShadowNode: Add comment.
Michael Herzog il y a 7 mois
Parent
commit
2dba5a8116

+ 17 - 4
examples/jsm/csm/CSMShadowNode.js

@@ -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 ++ ) {
 
@@ -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 ) );
@@ -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

+ 1 - 1
examples/webgpu_shadowmap_csm.html

@@ -177,7 +177,7 @@
 
 				gui.add( params, 'shadows' ).onChange( function ( value ) {
 
-					renderer.shadowMap.enabled = value;
+					csmDirectionalLight.castShadow = value;
 
 				} );
 

+ 0 - 11
src/nodes/lighting/ShadowBaseNode.js

@@ -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;
-
-	}
-
 }
 
 /**

粤ICP备19079148号