Skip to content

LightsNode: Fix castShadow regression. #31106

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 2 commits into from
May 15, 2025
Merged

LightsNode: Fix castShadow regression. #31106

merged 2 commits into from
May 15, 2025

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented May 14, 2025

Related issue: https://discourse.threejs.org/t/webgpu-shadow-tests-and-findings/82561

Description

Toggling light.castShadow with WebGPURenderer has currently no effect.

The bit that checks the light state per frame is LightsNode.customCacheKey(). In this method we have to implement all checks that detect state changes of lights.

Copy link

github-actions bot commented May 14, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 337.26
78.64
337.26
78.64
+0 B
+0 B
WebGPU 549.58
152.34
549.57
152.34
-16 B
+1 B
WebGPU Nodes 548.93
152.19
548.92
152.19
-16 B
+0 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 467.34
112.95
467.34
112.95
+0 B
+0 B
WebGPU 624.49
169.06
624.48
169.05
-16 B
-14 B
WebGPU Nodes 579.34
158.35
579.33
158.36
-16 B
+4 B

@Mugen87 Mugen87 requested a review from sunag May 14, 2025 16:30
return hashArray( hashData );
const cacheKey = hashArray( _hashData );

_hashData.length = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have any source that .length=0 is better than other alternatives?

I didn't do an extensive beachmark, but I had done some tests between creating a new array and using .length=0 and creating a new array worked better. It seems that both force the GC, using null values ​​after use was what worked best for small arrays.

Copy link
Collaborator Author

@Mugen87 Mugen87 May 14, 2025

Choose a reason for hiding this comment

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

I've tried to find the original issue/PR where we discussed this but without success so far. It's many years ago but at that time, setting a zero length was the fastest way to clear an array. And it does no create a new array object like the previous approach which invalidates the previous object.

I'm surprised to hear that .length=0 triggers the GC. The array itself is just empty and the reference to it is not set to null or cleared.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can revisit the array management at any point again. Merging for now so the toggling issue is fixed on dev.

@Mugen87 Mugen87 added this to the r177 milestone May 14, 2025
@Mugen87 Mugen87 merged commit 088df26 into mrdoob:dev May 15, 2025
12 checks passed
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.

2 participants