Skip to content
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

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

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

RenaudRohlinger
Copy link
Collaborator

@RenaudRohlinger RenaudRohlinger commented Apr 6, 2025

Fixed: #30156 #30856

Description
Only inherit the camera layers if shadow.camera.layers is not set. This allows selective real-time/static shadows and resolves #30156 and #30856. /cc @sunag

This contribution is funded by Renaud Rohlinger @ Utsubo

Copy link

github-actions bot commented Apr 6, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 336.49
78.38
336.49
78.38
+0 B
+0 B
WebGPU 542.05
150.13
542.13
150.15
+87 B
+19 B
WebGPU Nodes 541.51
150.03
541.6
150.05
+87 B
+19 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 465.42
112.22
465.42
112.22
+0 B
+0 B
WebGPU 614.89
166.17
614.98
166.2
+87 B
+31 B
WebGPU Nodes 569.88
155.58
569.96
155.62
+87 B
+31 B

@@ -569,7 +569,11 @@ class ShadowNode extends ShadowBaseNode {
const depthVersion = shadowMap.depthTexture.version;
this._depthVersionCached = depthVersion;

shadow.camera.layers.mask = camera.layers.mask;
if ( shadow.camera.layers.test( 0 ) === true ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think test() is expecting a Layer as a parameter instead of a number, it would also be necessary to restore the previous value after rendering.

Copy link
Collaborator Author

@RenaudRohlinger RenaudRohlinger Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes I forgot layers use so sort of Bit Mask. I guess ( shadow.camera.layers.mask & 0xFFFFFFFE ) === 0 is the right way to check if any layer si set then!

Regarding shadow.camera.layers.mask = camera.layers.mask; was always here and never restored. I guess I will add it too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be good now!

shadow.updateMatrices( light );

shadow.camera.layers.mask = _shadowCameraLayer;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be restored after rendering?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, should be good now!

@@ -279,11 +279,22 @@ class TileShadowNode extends ShadowBaseNode {
scene.overrideMaterial = getShadowMaterial( light );
renderer.setRenderTarget( this.shadowMap );

const cameraLayers = [];
Copy link
Collaborator

@Mugen87 Mugen87 Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This array object should not be created per update. I suggest you move it into module scope similar to the arrays we use for chain maps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Honor camera layers on light.shadow.camera for selective shadow
3 participants