Skip to content

Commit f35e494

Browse files
ShadowNode: Inherit camera.layers only if shadow.camera.layers is not set (#30877)
* ShadowNode: Inherit camera.layers only if shadow.layers is not set * Fix layers check * invert condition * restore after render * move array creation to module scope
1 parent bc7aedd commit f35e494

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

examples/jsm/tsl/shadows/TileShadowNode.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { min, Fn, shadow, NodeUpdateType, getShadowMaterial, getShadowRenderObje
1919
const { resetRendererAndSceneState, restoreRendererAndSceneState } = RendererUtils;
2020
let _rendererState;
2121

22+
const _cameraLayers = [];
2223
const _vec3Temp1 = /*@__PURE__*/ new Vector3();
2324
const _vec3Temp2 = /*@__PURE__*/ new Vector3();
2425
const _vec3Temp3 = /*@__PURE__*/ new Vector3();
@@ -279,11 +280,21 @@ class TileShadowNode extends ShadowBaseNode {
279280
scene.overrideMaterial = getShadowMaterial( light );
280281
renderer.setRenderTarget( this.shadowMap );
281282

283+
282284
for ( let index = 0; index < this.lights.length; index ++ ) {
283285

284286
const light = this.lights[ index ];
285287
const shadow = light.shadow;
286-
shadow.camera.layers.mask = camera.layers.mask;
288+
289+
const _shadowCameraLayer = shadow.camera.layers.mask;
290+
_cameraLayers.push( _shadowCameraLayer );
291+
292+
if ( ( shadow.camera.layers.mask & 0xFFFFFFFE ) === 0 ) {
293+
294+
shadow.camera.layers.mask = camera.layers.mask;
295+
296+
}
297+
287298
shadow.updateMatrices( light );
288299

289300
renderer.setRenderObjectFunction( getShadowRenderObjectFunction( renderer, shadow, shadowType, useVelocity ) );
@@ -303,6 +314,17 @@ class TileShadowNode extends ShadowBaseNode {
303314

304315
restoreRendererAndSceneState( renderer, scene, _rendererState );
305316

317+
for ( let index = 0; index < this.lights.length; index ++ ) {
318+
319+
const light = this.lights[ index ];
320+
const shadow = light.shadow;
321+
322+
shadow.camera.layers.mask = _cameraLayers[ index ];
323+
324+
}
325+
326+
_cameraLayers.length = 0;
327+
306328
}
307329

308330
/**

src/nodes/lighting/ShadowNode.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,13 @@ class ShadowNode extends ShadowBaseNode {
569569
const depthVersion = shadowMap.depthTexture.version;
570570
this._depthVersionCached = depthVersion;
571571

572-
shadow.camera.layers.mask = camera.layers.mask;
572+
const _shadowCameraLayer = shadow.camera.layers.mask;
573+
574+
if ( ( shadow.camera.layers.mask & 0xFFFFFFFE ) === 0 ) {
575+
576+
shadow.camera.layers.mask = camera.layers.mask;
577+
578+
}
573579

574580
const currentRenderObjectFunction = renderer.getRenderObjectFunction();
575581

@@ -596,6 +602,8 @@ class ShadowNode extends ShadowBaseNode {
596602

597603
}
598604

605+
shadow.camera.layers.mask = _shadowCameraLayer;
606+
599607
restoreRendererAndSceneState( renderer, scene, _rendererState );
600608

601609
}

0 commit comments

Comments
 (0)