Skip to content

CSM Shadow: How to toggle csm shadow #31183

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

Closed
ligaofeng0901 opened this issue May 27, 2025 · 6 comments
Closed

CSM Shadow: How to toggle csm shadow #31183

ligaofeng0901 opened this issue May 27, 2025 · 6 comments
Labels
Milestone

Comments

@ligaofeng0901
Copy link
Contributor

ligaofeng0901 commented May 27, 2025

Description

(https://jsfiddle.net/ligaofeng0901/yqv21wtp/26/)
This is a modified version of offical example. if you click the toggle button to disable csm shadow, the shadow node can't be disposed, and the shadow is still here.
The main problem is the light node cann't detect the change of shadownode. And as I konw, there is no way to forcely update light. these code light.needsUpdate = true;light.shadow.needsUpdate =true;light.shadow.shadowNode.needsUpdate = true; all don't work.

Solution

Provide a way to forcely update lightnode ?

Alternatives

Additional context

No response

@Mugen87
Copy link
Collaborator

Mugen87 commented May 27, 2025

Shadows should be toggled by changing the castShadow light property. This is currently broken for CSM shadows though. The PR is trying to fix this.

@ligaofeng0901
Copy link
Contributor Author

Shadows should be toggled by changing the castShadow light property

Ok,does it mean setting castShadow to false, all shadowmaps of this light will be disposed?

In my app, shadow is a rendering feature, which allows user to enable or disable it dynamiclly, or change the shadow type, csm or default, and other types. If we disable shadow, all associated resources should be disposed.

So when shadow is set from enabled to disabled, I try to set the light.shadow.shadowNode = null; renderer.shadowMap.enabled=false; So far, it doesn't work as expect.

@Mugen87
Copy link
Collaborator

Mugen87 commented May 28, 2025

Ok,does it mean setting castShadow to false, all shadowmaps of this light will be disposed?

Yes, this happens here, btw:

if ( this.light.castShadow ) {
if ( builder.object.receiveShadow ) {
this.setupShadow( builder );
}
} else if ( this.shadowNode !== null ) {
this.shadowNode.dispose();
this.shadowNode = null;
this.shadowColorNode = null;
}

@Mugen87
Copy link
Collaborator

Mugen87 commented May 28, 2025

You can test the changes of #31186 with r177. If things works as expected, we can close the issue. Otherwise you can report your findings here 👍 .

@ligaofeng0901
Copy link
Contributor Author

You can test the changes of #31186 with r177. If things works as expected, we can close the issue. Otherwise you can report your findings here 👍 .

Thanks for the update! I've tested the changes, and things work as expected so far👍.
I also noticed that you said globally toggling shadows was never an ideal solution in the PR. Out of curiosity, will the global renderer.shadowMap.enabled approach be deprecated in the future? Just want to make sure we're aligning with the recommended usage going forward.

@Mugen87
Copy link
Collaborator

Mugen87 commented May 30, 2025

No, it won't. My comment just referred to the fact that renderer.shadowMap.enabled was used in the example because it was not possible to toggle CSM shadows so far.

@Mugen87 Mugen87 closed this as completed May 30, 2025
@Mugen87 Mugen87 added this to the r177 milestone May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants