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

WebGPURenderer: Add support for VSM. #29225

Merged
merged 8 commits into from
Sep 5, 2024
Merged

WebGPURenderer: Add support for VSM. #29225

merged 8 commits into from
Sep 5, 2024

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Aug 24, 2024

Related issue: -

Description

This PR adds support for Variance Shadow Maps (VSM) to WebGPURenderer.

This is WIP though since the current code only supports one shadow casting light. I'm not sure why the shadows of an additional shadow casting light are currently ignored. The new example illustrates this issue. You only see the shadow of the spot light but no the directional light.

Some help/support in this context would be welcome 😇 .

Side note: VSM works by preprocessing the actual shadow map with two blur passes. The render target of the second blur pass is then used as the new shadow map in the shader. The shadow information are not stored as floats in a depth texture but in special two-component distribution vectors. A smart calculation based on these data leads to the final occlusion value.

Copy link

github-actions bot commented Aug 24, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 685.2 kB
169.6 kB
685.2 kB
169.6 kB
+0 B
+0 B
WebGPU 823 kB
220.9 kB
826 kB
221.4 kB
+2.96 kB
+597 B
WebGPU Nodes 822.6 kB
220.8 kB
825.6 kB
221.4 kB
+3.38 kB
+691 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 462 kB
111.5 kB
462 kB
111.5 kB
+0 B
+0 B
WebGPU 522.3 kB
140.8 kB
525.2 kB
141.5 kB
+2.95 kB
+732 B
WebGPU Nodes 478.9 kB
130.7 kB
481.9 kB
131.4 kB
-40.39 kB
+712 B

@sunag
Copy link
Collaborator

sunag commented Aug 26, 2024

The problem was in NodeFrame which was not restoring the scene from the previous render in the call tree, I still have to see the best solution, but I already feel relieved since it was kind of difficult to find the problem :)

image

@sunag
Copy link
Collaborator

sunag commented Aug 26, 2024

I have to improve filterNode to support VSM too, I think that after we merge this PR.

@sunag
Copy link
Collaborator

sunag commented Aug 26, 2024

It looks like we have another issue in WebGLBackend.

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Aug 26, 2024

The behavior in WebGL seems odd. You can see the directional light but not its shadows. The spot light is completely missing in the scene (light + shadow).

@Mugen87 Mugen87 added this to the r169 milestone Aug 29, 2024
@Mugen87
Copy link
Collaborator Author

Mugen87 commented Sep 4, 2024

I stall the PR for the moment since I could not figure out the root cause so far. Hopefully the issue will pop up in a different, more isolated context.

@sunag
Copy link
Collaborator

sunag commented Sep 5, 2024

This PR #29326 should fix it, sorry the delay, I had to deconstruct the code step by step to find the source of the problem.

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Sep 5, 2024

Awesome, it really works!

@Mugen87 Mugen87 marked this pull request as ready for review September 5, 2024 08:58
@Mugen87 Mugen87 merged commit b5209aa into mrdoob:dev Sep 5, 2024
11 of 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