Skip to content

Implement tile-based shadow map system (TBSM)#75

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/add-tile-based-shadowmap
Draft

Implement tile-based shadow map system (TBSM)#75
Copilot wants to merge 3 commits intomainfrom
copilot/add-tile-based-shadowmap

Conversation

Copy link

Copilot AI commented Mar 7, 2026

Adds a full tile-based shadow map system to the forward renderer. The screen is divided into 16×16 pixel tiles; each tile carries a bitmask of which shadow lights affect it, so fragment shaders skip irrelevant shadow lookups entirely.

New components

  • TileShadowPass – container (mirrors HizGenerator pattern) that owns:
    • A persistent Texture2DArray shadow atlas (1024×1024×MAX_SHADOW_LIGHTS=4, D32).
    • TileShadowPassInfo UBO – per-light view-projection matrix + type + position/radius.
    • Tile bitmask UBO – uint32_t[128×72] where bit N = shadow light N affects that tile.
    • CPU-side tile culling: directional lights mark all tiles; spot/point lights mark only tiles inside the projected screen-space bounding rect of their radius sphere.
  • ShadowSlotPass – one RasterPass per active shadow light, rendering scene depth into its atlas layer via an imported ImageView.

Pipeline integration

DefaultForwardPipeline::Collect now calls tileShadow->Setup() first (to build shadow matrices before SetupGlobal reads LightMatrix), then tileShadow->AddPasses() to enqueue slot passes before the forward pass.

Four new descriptor bindings added to the default raster layout:

Binding Name Type
12 TileShadowInfo UBO
13 TileLightBitmask UBO
14 ShadowAtlas Texture2DArray
15 ShadowAtlasSampler Sampler

Shader integration

New assets/shaders/layout/tile_shadow.hlslh (auto-included via default_pass.hlslh) provides:

// In FSMain with ENABLE_TILE_SHADOW=1:
float shadow = ComputeTileShadow(input.Pos.xy, input.WorldPos);

ComputeTileShadow looks up the tile bitmask from SV_Position, then performs 3×3 PCF sampling from ShadowAtlas for each flagged light.

New ENABLE_TILE_SHADOW pragma option added to standard_pbr.hlsl alongside the existing ENABLE_SHADOW path.

Light system additions

  • SpotLight::BuildShadowMatrix(SceneView&) – constructs a perspective shadow view from the spot light's position and cone direction.
  • SpotLight: added SetPosition, SetDirection, SetRange, GetRange.
  • LightFeatureProcessor::GetLights() – exposes the local light list for shadow light collection.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits March 7, 2026 18:42
…culling, shader support

Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tile based shadow mapping implementation Implement tile-based shadow map system (TBSM) Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants