Skip to content

ShadowNode: Inherit camera.layers only if shadow.camera.layers is not set #30877

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
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
24 changes: 23 additions & 1 deletion examples/jsm/tsl/shadows/TileShadowNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { min, Fn, shadow, NodeUpdateType, getShadowMaterial, getShadowRenderObje
const { resetRendererAndSceneState, restoreRendererAndSceneState } = RendererUtils;
let _rendererState;

const _cameraLayers = [];
const _vec3Temp1 = /*@__PURE__*/ new Vector3();
const _vec3Temp2 = /*@__PURE__*/ new Vector3();
const _vec3Temp3 = /*@__PURE__*/ new Vector3();
Expand Down Expand Up @@ -279,11 +280,21 @@ class TileShadowNode extends ShadowBaseNode {
scene.overrideMaterial = getShadowMaterial( light );
renderer.setRenderTarget( this.shadowMap );


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

const light = this.lights[ index ];
const shadow = light.shadow;
shadow.camera.layers.mask = camera.layers.mask;

const _shadowCameraLayer = shadow.camera.layers.mask;
_cameraLayers.push( _shadowCameraLayer );

if ( ( shadow.camera.layers.mask & 0xFFFFFFFE ) === 0 ) {

shadow.camera.layers.mask = camera.layers.mask;

}

shadow.updateMatrices( light );

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

restoreRendererAndSceneState( renderer, scene, _rendererState );

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

const light = this.lights[ index ];
const shadow = light.shadow;

shadow.camera.layers.mask = _cameraLayers[ index ];

}

_cameraLayers.length = 0;

}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/nodes/lighting/ShadowNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,13 @@ class ShadowNode extends ShadowBaseNode {
const depthVersion = shadowMap.depthTexture.version;
this._depthVersionCached = depthVersion;

shadow.camera.layers.mask = camera.layers.mask;
const _shadowCameraLayer = shadow.camera.layers.mask;

if ( ( shadow.camera.layers.mask & 0xFFFFFFFE ) === 0 ) {

shadow.camera.layers.mask = camera.layers.mask;

}

const currentRenderObjectFunction = renderer.getRenderObjectFunction();

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

}

shadow.camera.layers.mask = _shadowCameraLayer;

restoreRendererAndSceneState( renderer, scene, _rendererState );

}
Expand Down