[WGSL] lightFragment.fx -- Missing positional parameter in call to computeShadowCube()

Hey there,

While forking the (lovely :heart:) SummerFestival tutorial project and upgrading all Babylon dependencies to latest (from 5.57.1 to 7.37.0), ran into this issue, which breaks the game (white screen):

Error while parsing WGSL: :1500:8 error: too few arguments in call to 'computeShadowCube', expected 6, got 5
shadow=computeShadowCube(fragmentInputs.vPositionW,light1.vLightData.xyz,shadowTexture1Sampler,light1.shadowsInfo.x,light1.depthValues);
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


 - While validating [ShaderModuleDescriptor ""fragment""]
 - While calling [Device "BabylonWebGPUDevice0"].CreateShaderModule([ShaderModuleDescriptor ""fragment""]).
Understand this warningAI
localhost/:1 Compilation log for [Invalid ShaderModule "fragment"]:
1 error(s) generated while compiling the shader:
:1500:8 error: too few arguments in call to 'computeShadowCube', expected 6, got 5
shadow=computeShadowCube(fragmentInputs.vPositionW,light1.vLightData.xyz,shadowTexture1Sampler,light1.shadowsInfo.x,light1.depthValues);
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Understand this warningAI
chunk-XXKFNQC7.js?v=9eacb03d:52 BJS - [00:09:41]: WebGPU uncaptured error (12): [object GPUValidationError] - [Invalid ShaderModule "fragment"] is invalid.
 - While validating fragment stage ([Invalid ShaderModule "fragment"], entryPoint: "main").
 - While validating fragment state.
 - While calling [Device "BabylonWebGPUDevice0"].CreateRenderPipeline([RenderPipelineDescriptor ""RenderPipeline_bgra8unorm_depth24plus-stencil8_samples4_textureState0""]).

I traced this to packages/dev/core/src/ShadersWGSL/ShadersInclude/lightFragment.fx#L274:

shadow = computeShadowCube(fragmentInputs.vPositionW, light{X}.vLightData.xyz, shadowTexture{X}Sampler, light{X}.shadowsInfo.x, light{X}.depthValues);

computeShadowCube is defined here and expects a texture to be passed along with the sampler:

fn computeShadowCube(worldPos: vec3f, lightPosition: vec3f, shadowTexture: texture_cube<f32>, shadowSampler: sampler, darkness: f32, depthValues: vec2f) -> f32

Patching the shader to include the texture parameter used in other similar functions fixed it in my clone, so I assume a fix PR can use the same change:

 ShaderStore.IncludesShadersStoreWGSL.lightFragment = ShaderStore
            .IncludesShadersStoreWGSL.lightFragment.replace(
                "computeShadowCube(fragmentInputs.vPositionW,light{X}.vLightData.xyz,shadowTexture{X}Sampler,light{X}.shadowsInfo.x,light{X}.depthValues)",
                "computeShadowCube(fragmentInputs.vPositionW,light{X}.vLightData.xyz,shadowTexture{X},shadowTexture{X}Sampler,light{X}.shadowsInfo.x,light{X}.depthValues)",
            );

I don’t have time to track down where in the tutorial project the shader gets invoked unfortunately. Hopefully this is self-apparent enough to not need that.

Happy to make a PR if someone can confirm the issue.

Best,
Chris

Thank you for your report. Sorry, I hadn’t seen that you were proposing to make a PR, so I made one!

1 Like

That was a miss from my side! Thanks a lot @Propolisa and @Evgeni_Popov

1 Like