[Bug] WebGPU: CascadedShadowGenerator with PCF QUALITY_LOW generates invalid WGSL (missing shadowTexture argument)

Hi all, reporting a bug in the WGSL shader include for cascaded shadow maps. We have a one-line fix and will open a PR that links back to this thread.

What happens

On the WebGPU engine, a CascadedShadowGenerator with usePercentageCloserFiltering = true and filteringQuality = ShadowGenerator.QUALITY_LOW makes every shadow-receiving material fail WGSL validation:

Error while parsing WGSL: :1037:94 error: expected expression for function call
nextShadow=computeShadowWithCSMPCF1(index0,vPositionFromLight0[index0],vDepthMetric0[index0],,shadowTexture0Sampler,light0.shadowsInfo.x,light0.shadowsInfo.w);

The invalid shader module invalidates the render pipeline, and the command buffer is rejected every frame (Invalid CommandBuffer from CommandEncoder "RenderEncoder"). So the whole frame is dropped, not only the shadow receivers. In our app this happened the moment a user switched shadow quality to low.

Repro

Playground (WebGPU engine): https://playground.babylonjs.com/#UE4NN0#4

With QUALITY_LOW nothing renders, and the console fills with the errors above. Change that one line to QUALITY_MEDIUM and the same scene renders the ground, the box and its shadow. Confirmed on Babylon.js v9.26.2.

Cause

In packages/dev/core/src/ShadersWGSL/ShadersInclude/lightFragment.fx, the cascade-blend branch for SHADOWLOWQUALITY passes an empty argument where shadowTexture{X} belongs:

nextShadow = computeShadowWithCSMPCF1(index{X}, vPositionFromLight{X}[index{X}], vDepthMetric{X}[index{X}], , shadowTexture{X}Sampler, light{X}.shadowsInfo.x, light{X}.shadowsInfo.w);

The non-blend call a few lines above, and the PCF3/PCF5 blend calls beside it, all pass shadowTexture{X}. The GLSL include is correct. The branch compiles whenever cascadeBlendPercentage is non-zero, and the default is 0.1. It looks like it came in with the WGSL port (#15003, May 2024), and it’s still present on current master.

Fix

Pass the texture: ..., vDepthMetric{X}[index{X}], shadowTexture{X}, shadowTexture{X}Sampler, .... Commit on our fork: GitHub - increasinglyHuman/Babylon.js at fix/wgsl-csm-pcf1-cascade-blend · GitHub . We’ll open the PR and link it here.

Workaround until then: use QUALITY_MEDIUM or higher with cascaded shadows on WebGPU, or set cascadeBlendPercentage = 0.

--Allen

cc @Evgeni_Popov

@increasinglyHuman Is there a reason why you closed the PR that fixed the bug? The PR looked good to me (I had approved it).

sorry - i didn’t mean to do that.