Skip to content

Conversation

@mrdoob
Copy link
Owner

@mrdoob mrdoob commented Nov 4, 2025

Description

Changes

  • Better variable names (mean, variance, d, p_max) for clarity
  • Removed redundant outer clamp() - result is already guaranteed to be in [0,1]
  • Pre-computed constant (0.65 instead of 0.95 - 0.3)
  • Early return optimization for fully lit pixels
  • Fixed variance epsilon from 0.00000 to 0.0000001 to actually prevent division by zero

Benefits

  • Slightly better performance: Fewer operations per pixel
  • Improved numerical stability: Proper epsilon prevents division by zero and NaN issues
  • More maintainable: Clearer variable names and better code structure
  • Identical visual output: All changes are mathematically equivalent to the original

@mrdoob mrdoob added this to the r182 milestone Nov 4, 2025
@github-actions
Copy link

github-actions bot commented Nov 4, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 355.14
86.33
355.01
86.3
-136 B
-26 B
WebGPU 609.62
170.99
609.62
170.99
+0 B
+0 B
WebGPU Nodes 608.23
170.72
608.23
170.72
+0 B
+0 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 486.77
121.07
486.63
121.05
-136 B
-26 B
WebGPU 678.47
186.28
678.47
186.28
+0 B
+0 B
WebGPU Nodes 620.47
169.54
620.47
169.54
+0 B
+0 B

@mrdoob
Copy link
Owner Author

mrdoob commented Nov 4, 2025

Maybe #32180 makes VSM shadows redundant too...

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 4, 2025

VSM can blur the shadow map as a whole which a great quality advantage over PCF. Also in #32180, you see the noise structure especially with larger radii at the shadow edges because there is no denoise or temporal filtering in place. Depending on the scene and how closely you look at the shadows, that could be considered as a quality issue (and a reason for using VSM).

@mrdoob
Copy link
Owner Author

mrdoob commented Nov 6, 2025

That's true yeah. Okay, lets keep VSM 👌

@mrdoob mrdoob merged commit 46961fb into dev Nov 6, 2025
10 checks passed
@mrdoob mrdoob deleted the vsm branch November 7, 2025 05:09
mrdoob pushed a commit that referenced this pull request Nov 7, 2025
Port optimizations from PR #32181 to the WebGPU renderer:
- Extract mean variable for clarity
- Add early return optimization for fully lit pixels
- Improve variable naming (d, p_max)
- Correct variance epsilon from 0 to 0.0000001
- Pre-compute constant (0.65 instead of 0.95 - 0.3)
- Remove redundant outer clamp
- Add clarifying comments

These changes improve performance by reducing operations per pixel
while maintaining identical visual output.
mrdoob added a commit that referenced this pull request Nov 7, 2025
Port optimizations from PR #32181 to the WebGPU renderer:
- Extract mean variable for clarity
- Add early return optimization for fully lit pixels
- Improve variable naming (d, p_max)
- Correct variance epsilon from 0 to 0.0000001
- Pre-compute constant (0.65 instead of 0.95 - 0.3)
- Remove redundant outer clamp
- Add clarifying comments

These changes improve performance by reducing operations per pixel
while maintaining identical visual output.

Co-authored-by: Claude <noreply@anthropic.com>
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.

3 participants