feat(shadow): add alpha-tested material shadow casters #947

Merged
SakulFlee merged 2 commits from feat/renderer-shadows into main 2026-10-26 23:18:13 +00:00
Collaborator

Summary

Phase 5a: shadow casters now respect PBR alpha masking, and shadow rendering no longer creates views every frame.

  • MaterialShaderDescriptor can provide a dedicated shadow source plus shadow vertex/fragment entrypoints.
  • Shadow pipelines bind the material layout at group 0 and the per-light matrix at group 1. This lets a shadow fragment sample the material's albedo alpha and apply the same cutoff as the G-buffer/forward paths.
  • PBR ships a dedicated pbr_shadow.wgsl; opaque materials skip the texture fetch because their cutoff is zero.
  • The shadow renderer uses the material shadow pipeline for masked casters and keeps the existing fast depth-only pipeline for opaque materials.
  • Shadow pipelines are cached by shader-program identity and pruned when the program is dropped.
  • Per-layer and per-cube-face TextureViews are cached and only recreated when the shadow textures grow.
  • Cached layer views means CSM/spot/point paths keep working unchanged.

Verification

  • cargo fmt --all -- --check
  • cargo clippy for the touched crates and all three example templates with --all-targets -D warnings
  • cargo test for orbital_material_shader, orbital_shader_pbr, orbital_shadow, orbital_resources
  • 24 naga WGSL tests pass, including the new PBR shadow shader
  • Examples were not launched in this environment (no display/GPU)

Refs #781, #872.

## Summary Phase 5a: shadow casters now respect PBR alpha masking, and shadow rendering no longer creates views every frame. - `MaterialShaderDescriptor` can provide a dedicated shadow source plus shadow vertex/fragment entrypoints. - Shadow pipelines bind the material layout at group 0 and the per-light matrix at group 1. This lets a shadow fragment sample the material's albedo alpha and apply the same cutoff as the G-buffer/forward paths. - PBR ships a dedicated `pbr_shadow.wgsl`; opaque materials skip the texture fetch because their cutoff is zero. - The shadow renderer uses the material shadow pipeline for masked casters and keeps the existing fast depth-only pipeline for opaque materials. - Shadow pipelines are cached by shader-program identity and pruned when the program is dropped. - Per-layer and per-cube-face `TextureView`s are cached and only recreated when the shadow textures grow. - Cached layer views means CSM/spot/point paths keep working unchanged. ## Verification - `cargo fmt --all -- --check` - `cargo clippy` for the touched crates and all three example templates with `--all-targets -D warnings` - `cargo test` for `orbital_material_shader`, `orbital_shader_pbr`, `orbital_shadow`, `orbital_resources` - 24 naga WGSL tests pass, including the new PBR shadow shader - Examples were not launched in this environment (no display/GPU) Refs #781, #872.
feat(shadow): add alpha-tested material shadow casters
All checks were successful
Lint / lint (pull_request) Successful in 59s
PR / test (pull_request) Successful in 1m59s
9a5a6135e7
Material shaders can now provide a dedicated shadow module and entrypoints. Shadow pipelines bind the material layout at group 0 and the per-light matrix at group 1, so alpha-masked PBR materials can reuse their albedo texture and factors during depth rendering.

The shadow renderer selects the material shadow pipeline for non-opaque casters and keeps the fast depth-only pipeline for opaque materials. Shadow pipelines are cached by shader-program identity and pruned when the program is dropped.

Cache per-layer and per-cube-face texture views instead of creating them every frame. PBR shadow shaders are validated with naga.

Smart test results

Result: PASS

Scope: full workspace

Reason: workspace-level change: Cargo.lock

Elapsed: 6m 40s

Workflow run

Overall: 451 tests, 441 passed, 0 failed, 10 skipped

Nextest: 440 tests, 440 passed, 0 failed, 0 skipped
Doctests: 11 tests, 1 passed, 0 failed, 10 skipped

Outcome charts are split between nextest and doctests. The timing chart covers nextest only.

Crate Nextest Passed Failed Skipped Doctests Time
orbital 1 1 0 0 - 0.83s
orbital_2d 29 29 0 0 0/1 0.27s
orbital_app 10 10 0 0 0/1 0.07s
orbital_camera 4 4 0 0 - 0.03s
orbital_core 2 2 0 0 - 0.01s
orbital_debug_render 0 0 0 0 0/1 0.00s
orbital_debug_ui 45 45 0 0 0/1 0.33s
orbital_ecs 114 114 0 0 0/2 1.01s
orbital_ecs_bridge 39 39 0 0 - 0.33s
orbital_file_manager 5 5 0 0 - 0.05s
orbital_iced 25 25 0 0 - 0.22s
orbital_importer_gltf 13 13 0 0 - 0.22s
orbital_input 11 11 0 0 - 0.08s
orbital_light 6 6 0 0 - 0.04s
orbital_macros 0 0 0 0 0/1 0.00s
orbital_material_shader 2 2 0 0 - 0.02s
orbital_math 4 4 0 0 - 0.03s
orbital_procgeo 2 2 0 0 - 0.02s
orbital_render_graph 6 6 0 0 - 0.04s
orbital_renderer 8 8 0 0 - 0.05s
orbital_resources 24 24 0 0 - 0.36s
orbital_shader_core 0 0 0 0 1/1 0.00s
orbital_shader_pbr 4 4 0 0 - 0.03s
orbital_shader_preprocessor 12 12 0 0 - 0.10s
orbital_shadow 3 3 0 0 - 0.03s
orbital_text 14 14 0 0 0/1 0.47s
orbital_texture 11 11 0 0 - 0.09s
orbital_touch_ui 1 1 0 0 0/1 0.01s
orbital_ui 32 32 0 0 0/1 0.24s
orbital_world_environment 13 13 0 0 - 0.09s
pie showData
    title Nextest outcomes
    "Passed" : 440
pie showData
    title Doctest outcomes
    "Passed" : 1
    "Skipped" : 10
xychart-beta
    title "Slowest crates (nextest seconds)"
    x-axis ["orbital_ecs", "orbital", "orbital_text", "orbital_resources", "orbital_debug_ui", "orbital_ecs_bridge", "orbital_2d", "orbital_ui"]
    y-axis "Seconds" 0 --> 1.1
    bar [1.01, 0.83, 0.47, 0.36, 0.33, 0.33, 0.27, 0.24]
<!-- orbital-ci-test-results --> ## Smart test results **Result:** PASS **Scope:** full workspace **Reason:** workspace-level change: Cargo.lock **Elapsed:** 6m 40s [Workflow run](https://forgejo.sakul-flee.de/SakulFlee/Orbital/actions/runs/693) **Overall:** 451 tests, 441 passed, 0 failed, 10 skipped **Nextest:** 440 tests, 440 passed, 0 failed, 0 skipped **Doctests:** 11 tests, 1 passed, 0 failed, 10 skipped _Outcome charts are split between nextest and doctests. The timing chart covers nextest only._ | Crate | Nextest | Passed | Failed | Skipped | Doctests | Time | | --- | ---: | ---: | ---: | ---: | ---: | ---: | | orbital | 1 | 1 | 0 | 0 | - | 0.83s | | orbital_2d | 29 | 29 | 0 | 0 | 0/1 | 0.27s | | orbital_app | 10 | 10 | 0 | 0 | 0/1 | 0.07s | | orbital_camera | 4 | 4 | 0 | 0 | - | 0.03s | | orbital_core | 2 | 2 | 0 | 0 | - | 0.01s | | orbital_debug_render | 0 | 0 | 0 | 0 | 0/1 | 0.00s | | orbital_debug_ui | 45 | 45 | 0 | 0 | 0/1 | 0.33s | | orbital_ecs | 114 | 114 | 0 | 0 | 0/2 | 1.01s | | orbital_ecs_bridge | 39 | 39 | 0 | 0 | - | 0.33s | | orbital_file_manager | 5 | 5 | 0 | 0 | - | 0.05s | | orbital_iced | 25 | 25 | 0 | 0 | - | 0.22s | | orbital_importer_gltf | 13 | 13 | 0 | 0 | - | 0.22s | | orbital_input | 11 | 11 | 0 | 0 | - | 0.08s | | orbital_light | 6 | 6 | 0 | 0 | - | 0.04s | | orbital_macros | 0 | 0 | 0 | 0 | 0/1 | 0.00s | | orbital_material_shader | 2 | 2 | 0 | 0 | - | 0.02s | | orbital_math | 4 | 4 | 0 | 0 | - | 0.03s | | orbital_procgeo | 2 | 2 | 0 | 0 | - | 0.02s | | orbital_render_graph | 6 | 6 | 0 | 0 | - | 0.04s | | orbital_renderer | 8 | 8 | 0 | 0 | - | 0.05s | | orbital_resources | 24 | 24 | 0 | 0 | - | 0.36s | | orbital_shader_core | 0 | 0 | 0 | 0 | 1/1 | 0.00s | | orbital_shader_pbr | 4 | 4 | 0 | 0 | - | 0.03s | | orbital_shader_preprocessor | 12 | 12 | 0 | 0 | - | 0.10s | | orbital_shadow | 3 | 3 | 0 | 0 | - | 0.03s | | orbital_text | 14 | 14 | 0 | 0 | 0/1 | 0.47s | | orbital_texture | 11 | 11 | 0 | 0 | - | 0.09s | | orbital_touch_ui | 1 | 1 | 0 | 0 | 0/1 | 0.01s | | orbital_ui | 32 | 32 | 0 | 0 | 0/1 | 0.24s | | orbital_world_environment | 13 | 13 | 0 | 0 | - | 0.09s | ```mermaid pie showData title Nextest outcomes "Passed" : 440 ``` ```mermaid pie showData title Doctest outcomes "Passed" : 1 "Skipped" : 10 ``` ```mermaid xychart-beta title "Slowest crates (nextest seconds)" x-axis ["orbital_ecs", "orbital", "orbital_text", "orbital_resources", "orbital_debug_ui", "orbital_ecs_bridge", "orbital_2d", "orbital_ui"] y-axis "Seconds" 0 --> 1.1 bar [1.01, 0.83, 0.47, 0.36, 0.33, 0.33, 0.27, 0.24] ```
perf(shadow): cull models against each shadow frustum
All checks were successful
Lint / lint (pull_request) Successful in 1m10s
Templates / templates (pull_request) Successful in 4m16s
PR / test (pull_request) Successful in 7m30s
bfb6eac261
Build a frustum from each CSM cascade, spot matrix and point-light cube face, then skip models whose instance bounds do not intersect it. Models with no bounds are drawn conservatively, and instance-level culling is unchanged.

This reduces shadow draw calls for large scenes without changing the shadow map layout or sampling path.
SakulFlee deleted branch feat/renderer-shadows 2026-10-26 23:18:13 +00:00
Sign in to join this conversation.
No description provided.