Skip to content

[Lighting Overhaul][Phase 2] Rewrite cascaded shadows and caster submission #903

Description

@MichaelFisher1997

Parent

Part of #898.

Depends on

#900. Phase 1 (#899) may proceed in parallel after Phase 0.

Goal

Replace the contradictory CSM math and sampling path while preserving the existing Vulkan shadow resource ownership and reverse-Z convention.

Scope

  • Compute practical/logarithmic cascade splits from camera near/far and configured shadow distance.
  • Fit exact frustum-slice corners or correctly sized stable spheres rather than the current camera-origin far-corner radius.
  • Use positive view-space depth consistently for fitting, selection, overlap, and final fade.
  • Stabilize X/Y translation to the real shadow texel grid and control rotational swimming from the moving sun.
  • Define explicit cascade overlap bands contained by both cascades.
  • Derive map-edge margins from the active PCF kernel radius.
  • Express caster/receiver bias in world and texel units with per-cascade scaling.
  • Build caster candidates from receiver volumes extruded toward the light instead of a camera-centered square.
  • Keep caster distance independent from receiver distance and include a chunk safety margin.
  • Implement atlas-aware alpha testing for cutout shadows; stop discarding diagonal vegetation wholesale.
  • Include supported entities in the shadow scene.
  • Replace misleading PCF settings with coherent hard/4/9/16-tap tiers.
  • Enable batched shadow submission by default once parity and overflow tests pass.
  • Repair shadow-map debug previews and retain useful cascade/caster/seam channels.

Acceptance criteria

  • Every frustum slice corner lies inside its cascade projection.
  • Reverse-Z near/far endpoints and comparisons are covered by tests.
  • Sub-texel camera motion does not move shadow edges.
  • Cascade transitions are continuous and no filter tap samples outside valid overlap.
  • Shadow distance/fade behavior matches settings without hidden 128/160-unit caps.
  • Low-sun off-screen casters remain represented.
  • Cutout vegetation casts alpha-correct shadows and entities cast supported shadows.
  • No visible acne, peter-panning, cascade lines, or detached voxel contacts in deterministic scenes.
  • High-preset shadow GPU time is targeted below 2.5 ms at 1080p on designated hardware.

Required tests

  • Frustum-corner containment and overlap containment.
  • Reverse-Z endpoint mapping.
  • Translation stability below one texel.
  • View-depth cascade selection.
  • Bias scaling across cascades.
  • Alpha-cutout discard behavior.
  • Caster extrusion and boundary chunk coverage.

Verification

nix develop --command zig fmt modules/engine-graphics/src modules/world-runtime/src
nix develop --command zig build test
nix develop --command zig build -Dskip-present
nix develop --command zig build test-robustness
nix develop --command zig build run -Dskip-present -Dshadow-test-scene -Dscreenshot-path=screenshots/lighting-phase2-shadow.png -Dscreenshot-frame=180
nix develop --command zig build benchmark -Doptimize=ReleaseFast -Dbenchmark-preset=high -Dbenchmark-duration=60 -Dbenchmark-output=lighting-phase2-high.json

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions