Fix NodeMaterial SSS with clustered lights#18413
Fix NodeMaterial SSS with clustered lights#18413Popov72 wants to merge 5 commits intoBabylonJS:masterfrom
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Handle GLSL NodeMaterial clustered light tile mask bindings on WebGPU, propagate shader language into clustered sampler preparation, and bind a default texture for missing WebGPU TextureBlock resources. 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). |
|
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/18413/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/18413/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/18413/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 |
🟢 Memory Leak Test Results13 passed, 0 leaked out of 13 scenarios 🟢 All memory leak tests passed — no leaks detected. Passed Scenarios (13)
|
⚡ Performance Test Results❌ Failed Tests (1)
|
|
Visualization tests for WebGPU |
🟢 Memory Leak Test Results13 passed, 0 leaked out of 13 scenarios 🟢 All memory leak tests passed — no leaks detected. Passed Scenarios (13)
|
|
WebGL2 visualization test reporter: |
Pass material shader language through materials-library clustered light preparation and correct the WebGPU storage-buffer comment. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
95bc1d1 to
b07b755
Compare
|
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). |
|
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
This PR aims to make clustered-light handling shader-language-aware across core and materials-library materials, while also addressing NodeMaterial/WebGPU binding issues around subsurface scattering and missing texture resources. It fits into Babylon.js's rendering pipeline by aligning effect resource binding with whether a material is compiled as GLSL or WGSL.
Changes:
- Propagate
shaderLanguageinto light uniform/sampler preparation for core and materials-library materials. - Adjust clustered-light resource selection and NodeMaterial shader generation around SSS + clustered-light interactions.
- Add unit tests for clustered-light sampler selection, NodeMaterial shader ordering, and WebGPU default texture binding.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/dev/materials/src/water/waterMaterial.ts | Passes material shader language into light sampler preparation. |
| packages/dev/materials/src/triPlanar/triPlanarMaterial.ts | Same shader-language propagation for triplanar material. |
| packages/dev/materials/src/terrain/terrainMaterial.ts | Same shader-language propagation for terrain material. |
| packages/dev/materials/src/simple/simpleMaterial.ts | Same shader-language propagation for simple material. |
| packages/dev/materials/src/shadowOnly/shadowOnlyMaterial.ts | Same shader-language propagation for shadow-only material. |
| packages/dev/materials/src/normal/normalMaterial.ts | Same shader-language propagation for normal material. |
| packages/dev/materials/src/mix/mixMaterial.ts | Same shader-language propagation for mix material. |
| packages/dev/materials/src/lava/lavaMaterial.ts | Same shader-language propagation for lava material. |
| packages/dev/materials/src/gradient/gradientMaterial.ts | Same shader-language propagation for gradient material. |
| packages/dev/materials/src/fur/furMaterial.ts | Same shader-language propagation for fur material. |
| packages/dev/materials/src/cell/cellMaterial.ts | Same shader-language propagation for cell material. |
| packages/dev/core/test/unit/Materials/materialHelper.functions.test.ts | Adds tests for clustered-light sampler selection. |
| packages/dev/core/test/unit/Materials/Node/Blocks/textureBlock.test.ts | Adds tests for WebGPU fallback texture binding. |
| packages/dev/core/test/unit/Materials/Node/Blocks/pbrMetallicRoughnessBlock.test.ts | Adds a shader-ordering test for NodeMaterial PBR subsurface handling. |
| packages/dev/core/test/unit/Lights/Clustered/clusteredLightContainer.test.ts | Adds tests for clustered-light texture vs storage-buffer binding. |
| packages/dev/core/src/Materials/standardMaterial.ts | Passes shader language to uniform/sampler preparation. |
| packages/dev/core/src/Materials/materialHelper.functions.ts | Makes clustered-light sampler generation depend on shader language. |
| packages/dev/core/src/Materials/PBR/pbrBaseMaterial.ts | Passes shader language to light sampler preparation. |
| packages/dev/core/src/Materials/PBR/openpbrMaterial.ts | Passes shader language to light sampler preparation. |
| packages/dev/core/src/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.ts | Changes clustered-light helper emission/order and WGSL sampler selection. |
| packages/dev/core/src/Materials/Node/Blocks/Dual/textureBlock.ts | Binds a default texture on WebGPU when no texture is assigned. |
| packages/dev/core/src/Materials/Node/Blocks/Dual/lightBlock.ts | Makes NodeMaterial light sampler generation depend on shader language. |
| packages/dev/core/src/Materials/Background/backgroundMaterial.ts | Passes shader language to uniform/sampler preparation. |
| packages/dev/core/src/Lights/Clustered/clusteredLightContainer.ts | Switches tile-mask binding between texture and storage buffer by effect shader language. |
|
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/18413/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/18413/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/18413/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. |
Move WGSL direct-lighting helper emission after subsurface declarations, keep WebGPU clustered masks on the storage-buffer path, and bind a WebGPU fallback texture for missing ImageSourceBlock resources. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
WebGL2 visualization test reporter: |
|
Visualization tests for WebGPU |
|
WebGL2 visualization test reporter: |
🟢 Memory Leak Test Results13 passed, 0 leaked out of 13 scenarios 🟢 All memory leak tests passed — no leaks detected. Passed Scenarios (13)
|
⚡ Performance Test ResultsBaseline: Latest · Candidate: Dev
🔘 Not Significant — p ≥ 0.05 (1)
❌ Failed Tests (1)
|
Summary
tileMaskBuffer.TextureBlockandImageSourceBlockresources that have no texture assigned, preventing bind group creation failures.Motivation
The forum repro at https://forum.babylonjs.com/t/nodematerial-compile-error-when-using-sub-surface-scattering-with-clustered-lights/63299 failed with NodeMaterial subsurface scattering and clustered lights.
For the WebGPU playground repro (
#CSCJO2#97), the NodeMaterial snippet must be loaded as WGSL, for example by passing{ shaderLanguage: BABYLON.ShaderLanguage.WGSL }toNodeMaterial.ParseFromSnippetAsync. This preserves the WebGPU clustered-light fast path (tileMaskBuffer, batch size 32) instead of adding a slower GLSL texture fallback.Validation
TextureBlockandImageSourceBlockresources.tileMaskBuffer, and WebGPU batch size remaining 32.