feat(renderer): add tiled light culling for deferred lighting #945

Merged
SakulFlee merged 2 commits from feat/renderer-light-culling into main 2026-10-26 18:35:11 +00:00
Collaborator

Summary

Phase 4c: tiled light culling for the deferred path.

  • A compute pass builds one light-index list per 16x16 screen tile.
    • Each tile reads its depth range from the G-buffer, reconstructs a conservative world-space AABB, and keeps lights whose influence overlaps it.
    • Directional lights are always included. Point/spot lights use their range sphere; infinite-range lights stay conservative.
    • Tiles that exceed the fixed 128-light list store an overflow sentinel. The deferred shader falls back to the full light loop for those tiles, so dense scenes stay correct.
  • The deferred lighting shader loops only its tile's light list instead of every light in the scene.
  • Tile counts/indices/params buffers are persistent and resize only when the tile grid changes.
  • The shared world layout now exposes the light storage and light-count bindings to compute.
  • Culling and G-buffer bind groups are cached by texture/buffer identity; bind groups are recreated only when a pooled target or tile buffer is replaced.
  • The light contribution code is split into calculate_light_index_contribution, shared by the forward full-light loop, the deferred tile loop and the overflow fallback.
  • Naga validation covers the culling shader; graph tests include the new light-culling pass.

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_model, orbital_renderer, orbital_resources
  • 23 naga WGSL tests pass, including the culling shader
  • cargo check for the facade, app and all three example templates
  • GUI examples were not launched in this environment (no display/GPU)

Stacked on #944.

Refs #781.

## Summary Phase 4c: tiled light culling for the deferred path. - A compute pass builds one light-index list per 16x16 screen tile. - Each tile reads its depth range from the G-buffer, reconstructs a conservative world-space AABB, and keeps lights whose influence overlaps it. - Directional lights are always included. Point/spot lights use their range sphere; infinite-range lights stay conservative. - Tiles that exceed the fixed 128-light list store an overflow sentinel. The deferred shader falls back to the full light loop for those tiles, so dense scenes stay correct. - The deferred lighting shader loops only its tile's light list instead of every light in the scene. - Tile counts/indices/params buffers are persistent and resize only when the tile grid changes. - The shared world layout now exposes the light storage and light-count bindings to compute. - Culling and G-buffer bind groups are cached by texture/buffer identity; bind groups are recreated only when a pooled target or tile buffer is replaced. - The light contribution code is split into `calculate_light_index_contribution`, shared by the forward full-light loop, the deferred tile loop and the overflow fallback. - Naga validation covers the culling shader; graph tests include the new `light-culling` pass. ## 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_model`, `orbital_renderer`, `orbital_resources` - 23 naga WGSL tests pass, including the culling shader - `cargo check` for the facade, app and all three example templates - GUI examples were not launched in this environment (no display/GPU) Stacked on #944. Refs #781.
feat(renderer): add tiled light culling for deferred lighting
Some checks failed
Lint / lint (pull_request) Successful in 1m20s
PR / test (pull_request) Has been cancelled
3e118e6e42
Add a compute pass that builds per-tile light index lists from the G-buffer depth range. Each tile reconstructs a conservative world-space AABB from its min/max depth and keeps directional lights plus point/spot lights whose range overlaps the AABB.

The deferred lighting shader now evaluates only the lights listed for its tile. Tiles that exceed the fixed per-tile capacity store an overflow sentinel and fall back to the full light loop, so dense scenes remain correct. Tile buffers are persistent and resize with the render target, and the culling/G-buffer bind groups are cached by resource identity.

The shared world layout exposes the light storage and light-count bindings to compute. WGSL validation covers the culling shader, and graph tests include the new pass.
perf(material): keep blended materials on the forward path
All checks were successful
Lint / lint (pull_request) Successful in 44s
PR / test (pull_request) Successful in 2m24s
3863d785cc
Blended PBR materials no longer build an unused G-buffer pipeline, and the G-buffer pipeline always writes the renderer depth target so custom deferred materials cannot opt out of the depth state required by deferred lighting.

Smart test results

Result: PASS

Scope: orbital_material_shader, orbital_renderer, orbital_resources, orbital_shader_pbr

Reason: directly changed crates

Elapsed: 1m 36s

Workflow run

Overall: 37 tests, 37 passed, 0 failed, 0 skipped

Nextest: 37 tests, 37 passed, 0 failed, 0 skipped
Doctests: no tests reported

Crate Nextest Passed Failed Skipped Doctests Time
orbital_material_shader 2 2 0 0 - 0.01s
orbital_renderer 8 8 0 0 - 0.05s
orbital_resources 23 23 0 0 - 0.20s
orbital_shader_pbr 4 4 0 0 - 0.02s
pie showData
    title Nextest outcomes
    "Passed" : 37
xychart-beta
    title "Slowest crates (nextest seconds)"
    x-axis ["orbital_resources", "orbital_renderer", "orbital_shader_pbr", "orbital_material_shader"]
    y-axis "Seconds" 0 --> 1
    bar [0.20, 0.05, 0.02, 0.01]
<!-- orbital-ci-test-results --> ## Smart test results **Result:** PASS **Scope:** orbital_material_shader, orbital_renderer, orbital_resources, orbital_shader_pbr **Reason:** directly changed crates **Elapsed:** 1m 36s [Workflow run](https://forgejo.sakul-flee.de/SakulFlee/Orbital/actions/runs/677) **Overall:** 37 tests, 37 passed, 0 failed, 0 skipped **Nextest:** 37 tests, 37 passed, 0 failed, 0 skipped **Doctests:** no tests reported | Crate | Nextest | Passed | Failed | Skipped | Doctests | Time | | --- | ---: | ---: | ---: | ---: | ---: | ---: | | orbital_material_shader | 2 | 2 | 0 | 0 | - | 0.01s | | orbital_renderer | 8 | 8 | 0 | 0 | - | 0.05s | | orbital_resources | 23 | 23 | 0 | 0 | - | 0.20s | | orbital_shader_pbr | 4 | 4 | 0 | 0 | - | 0.02s | ```mermaid pie showData title Nextest outcomes "Passed" : 37 ``` ```mermaid xychart-beta title "Slowest crates (nextest seconds)" x-axis ["orbital_resources", "orbital_renderer", "orbital_shader_pbr", "orbital_material_shader"] y-axis "Seconds" 0 --> 1 bar [0.20, 0.05, 0.02, 0.01] ```
SakulFlee changed target branch from feat/renderer-deferred to main 2026-10-26 18:34:40 +00:00
SakulFlee deleted branch feat/renderer-light-culling 2026-10-26 18:35:13 +00:00
Sign in to join this conversation.
No description provided.