Skip to content

WGSL implementation of VSM shadows #7599

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
Apr 24, 2025
Merged

WGSL implementation of VSM shadows #7599

merged 2 commits into from
Apr 24, 2025

Conversation

mvaligursky
Copy link
Contributor

@mvaligursky mvaligursky commented Apr 24, 2025

  • both blurring as well as sampling VSM shadows were converted to WGSL

Screenshot 2025-04-24 at 14 39 28

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements the conversion of VSM shadow blurring and sampling from GLSL to WGSL to support WebGPU. Key changes include:

  • Refactoring and extracting variable calculations in shadow functions.
  • Adapting blur shader code to use placeholder substitution (e.g. {SAMPLES}) and WGSL syntax.
  • Adding WGSL shader chunks and updating shader/chunk selection in the shadow renderer.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/scene/shader-lib/chunks/lit/frag/lighting/shadowEVSM.js Updated to extract variable Z for clarity in getShadowSpotVSM32.
src/scene/shader-lib/chunks/lit/frag/blurVSM.js Updated uniform and loop expressions to incorporate placeholder {SAMPLES}.
src/scene/shader-lib/chunks-wgsl/lit/frag/lighting/shadowEVSM.js Added WGSL implementation for EVSM shadow functions.
src/scene/shader-lib/chunks-wgsl/lit/frag/lighting/lightDeclaration.js Fixed variable declaration syntax by adding the missing colon.
src/scene/shader-lib/chunks-wgsl/lit/frag/blurVSM.js Introduced WGSL version of the blur VSM shader with WGSL-syntax adaptations.
src/scene/shader-lib/chunks-wgsl/common/vert/fullscreenQuad.js Added WGSL vertex shader for full-screen quad rendering.
src/scene/shader-lib/chunks-wgsl/chunks-wgsl.js Updated import and shader chunk exports to include WGSL shaders.
src/scene/renderer/shadow-renderer.js Modified shader selection and creation to support WGSL with proper attribute mapping.
Comments suppressed due to low confidence (3)

src/scene/shader-lib/chunks/lit/frag/blurVSM.js:8

  • Ensure that the placeholder {SAMPLES} is correctly substituted during shader preprocessing for both the uniform declaration and subsequent usage.
uniform float weight[{SAMPLES}];

src/scene/shader-lib/chunks-wgsl/lit/frag/blurVSM.js:22

  • Check that accessing the weight array element via '.element' is the intended WGSL syntax; typically, array elements are accessed directly unless a custom type wrapper is used.
moments = moments + c.xyz * uniform.weight[i].element;

src/scene/renderer/shadow-renderer.js:500

  • Verify that using '{SAMPLES}' as a placeholder in the shader code is processed correctly by the shader preprocessor and is consistent with the usage in other shader files.
let blurFS = `#define {SAMPLES} ${filterSize}\n`;

@mvaligursky mvaligursky merged commit 1c555bd into main Apr 24, 2025
7 checks passed
@mvaligursky mvaligursky deleted the mv-vsm-wgsl branch April 24, 2025 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: graphics Graphics related issue enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants