Skip to content

LightsNode: Fix castShadow regression.#31106

Merged
Mugen87 merged 2 commits into
mrdoob:devfrom
Mugen87:dev1
May 15, 2025
Merged

LightsNode: Fix castShadow regression.#31106
Mugen87 merged 2 commits into
mrdoob:devfrom
Mugen87:dev1

Conversation

@Mugen87

@Mugen87 Mugen87 commented May 14, 2025

Copy link
Copy Markdown
Collaborator

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.

@github-actions

github-actions Bot commented May 14, 2025

Copy link
Copy Markdown

📦 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

Comment thread src/nodes/lighting/AnalyticLightNode.js
@Mugen87 Mugen87 requested a review from sunag May 14, 2025 16:30
return hashArray( hashData );
const cacheKey = hashArray( _hashData );

_hashData.length = 0;

Copy link
Copy Markdown
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.

@Mugen87 Mugen87 May 14, 2025

Copy link
Copy Markdown
Collaborator Author

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
Copy Markdown
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
RuthySheffi pushed a commit to RuthySheffi/three.js that referenced this pull request Jun 5, 2025
* LightsNode: Fix `castShadow` regression.

* Update AnalyticLightNode.js
RuthySheffi pushed a commit to RuthySheffi/three.js that referenced this pull request Jun 5, 2025
* LightsNode: Fix `castShadow` regression.

* Update AnalyticLightNode.js
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