[Shaders] Fix clustered lighting shader error when using anisotropy without clearcoat#18237
Conversation
…ithout clearcoat The computeClusteredLighting function referenced clearcoatOut.specularEnvironmentR0 in the ANISOTROPIC code path, but clearcoatOut is only passed as a parameter when CLEARCOAT is defined. This caused a shader compilation error when using PBR anisotropy with ClusteredLightContainer and no clearcoat. Fixed by using the local specularEnvironmentR0 variable instead, which already contains the correct value (overwritten from clearcoatOut when clearcoat is enabled). Applied to both GLSL and WGSL shaders. Forum: https://forum.babylonjs.com/t/63040 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). |
There was a problem hiding this comment.
Pull request overview
Fixes a shader compilation error in PBR clustered lighting when ANISOTROPIC is enabled without CLEARCOAT, by avoiding an unconditional reference to clearcoatOut in the anisotropy specular path. This aligns the anisotropic path with the already-correct non-anisotropic path by using specularEnvironmentR0.
Changes:
- WGSL: Use
specularEnvironmentR0instead ofclearcoatOut.specularEnvironmentR0in the anisotropic clustered specular call. - GLSL: Apply the same fix to the clustered lighting include.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/dev/core/src/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.fx | Fixes clustered anisotropic specular path to use specularEnvironmentR0 so it compiles when CLEARCOAT is off. |
| packages/dev/core/src/Shaders/ShadersInclude/pbrClusteredLightingFunctions.fx | Same fix for GLSL clustered lighting include to prevent clearcoatOut undeclared errors. |
|
Snapshot stored with reference name: Test environment: To test a playground add it to the URL, for example: https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18237/merge/index.html#WGZLGJ#4600 Links to test your changes to core in the published versions of the Babylon tools (does not contain changes you made to the tools themselves): https://playground.babylonjs.com/?snapshot=refs/pull/18237/merge To test the snapshot in the playground with a playground ID add it after the snapshot query string: https://playground.babylonjs.com/?snapshot=refs/pull/18237/merge#BCU1XR#0 If you made changes to the sandbox or playground in this PR, additional comments will be generated soon containing links to the dev versions of those tools. |
|
WebGL2 visualization test reporter: |
|
Visualization tests for WebGPU |
Description
The computeClusteredLighting function in the PBR clustered lighting shader unconditionally accessed clearcoatOut.specularEnvironmentR0 in the ANISOTROPIC code path, but clearcoatOut is only passed as a parameter when CLEARCOAT is defined. This caused a fragment shader compilation error:
The error occurs when using PBR anisotropy with ClusteredLightContainer and no clearcoat — on both WebGL2 and WebGPU.
Fix
Use the local specularEnvironmentR0 variable instead of reading it from clearcoatOut. This variable (from the pbrBlockReflectance0 include) already contains the correct value: it is overwritten from clearcoatOut when CLEARCOAT is enabled, and retains the base reflectance value otherwise. This is consistent with how the adjacent non-ANISOTROPIC code path already works.
Applied to both GLSL and WGSL shaders.
Repro
Playground #QAD7FB#0
Forum post
https://forum.babylonjs.com/t/anisotropy-with-clusteredlightcontainer-bug/63040