Skip to content

WGSL shaders support PCF shadows #7586

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 23, 2025
Merged

WGSL shaders support PCF shadows #7586

merged 2 commits into from
Apr 23, 2025

Conversation

mvaligursky
Copy link
Contributor

@mvaligursky mvaligursky commented Apr 23, 2025

  • improved support for texture types during WGSL processing (depth textures mostly)
  • converted shadow related GLSL -> WGSL and got it to work
Screenshot 2025-04-23 at 15 22 48

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 introduces WGSL support for PCF shadows while also converting several GLSL shadow functions and associated declarations to WGSL syntax. Key changes include updating shadow sampling implementations (PCF1, PCF3, and PCF5), converting light function code to WGSL using pointer parameters where needed, and updating shader processor regex and uniform declarations for WGSL.

Reviewed Changes

Copilot reviewed 15 out of 15 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/shadowPCF5.js Minor cleanup in JS shadow function (removal of extraneous empty line).
src/scene/shader-lib/chunks-wgsl/lit/frag/pass-shadow/litShadowMain.js New WGSL entry point for shadow rendering with updated depth handling.
src/scene/shader-lib/chunks-wgsl/lit/frag/lighting/lightFunctionShadow.js Converted shadow-sample functions from GLSL to WGSL with pointer usage for light direction update.
src/scene/shader-lib/chunks-wgsl/lit/frag/lighting/lightDeclaration.js Updated uniform declarations to WGSL (arrays and texture/sampler types).
src/platform/graphics/webgpu/webgpu-shader-processor-wgsl.js Revised regex and texture type handling to support new WGSL syntax.
Others Similar WGSL conversion updates for PCF3, PCF1, cascaded shadows, and clustered light shadow functions.
Comments suppressed due to low confidence (4)

src/scene/shader-lib/chunks-wgsl/lit/frag/lighting/lightFunctionShadow.js:12

  • [nitpick] Consider adding an inline comment or documentation to clarify the intent and semantics of passing 'lightDir' as a pointer for modification, to ensure consistent comprehension among future maintainers.
fn getShadowSampleCoord{i}(shadowTransform: mat4x4f, shadowParams: vec4f, worldPosition: vec3f, lightPos: vec3f, lightDir: ptr<function, vec3f>, lightDirNorm: vec3f, normal: vec3f) -> vec3f {

src/scene/shader-lib/chunks-wgsl/lit/frag/lighting/lightDeclaration.js:65

  • [nitpick] Confirm that all consuming code correctly handles the array access syntax for 'light{i}_shadowMatrixPalette', as the WGSL array type differs from the previous GLSL-style declaration.
uniform light{i}_shadowMatrixPalette: array<mat4x4f, 4>;

src/platform/graphics/webgpu/webgpu-shader-processor-wgsl.js:200

  • Verify that this new regex adequately captures all intended texture declarations—in particular, types with more complex or multiple template parameters—to avoid potential mismatches during shader processing.
const TEXTURE_REGEX = /^\s*var\s+(\w+)\s*:\s*(texture_\w+)(?:<(\w+)>)?;\s*$/;

src/scene/shader-lib/chunks-wgsl/lit/frag/clusteredLight.js:306

  • Ensure that switching to the 'uniform.shadowAtlasParams' access for shadow texture parameters is compatible with all shader modules that rely on these values.
let shadowTextureResolution: f32 = uniform.shadowAtlasParams.x;

@mvaligursky mvaligursky merged commit 738b902 into main Apr 23, 2025
7 checks passed
@mvaligursky mvaligursky deleted the mv-wgsl-shadows branch April 23, 2025 14:59
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