Map 3D: sun and moon shadows (cascaded shadow maps) #287

Manually merged
github merged 20 commits from gh-pr/287/head into gh-pr/287/base 2026-11-26 20:24:46 +00:00
Owner

@⁠holdmysocks on GitHub · 2026-11-25 15:14 UTC · original
holdmysocks:six-map3d-shadows → master · +648 −12 · 7 files · 20 commits · merged 2026-11-25 18:48 UTC

Stacked on #286 (the map's sky, light and exposure); this PR adds only the shadows. SIX-211.

What it does

The 3D map's sun (or the moon at night) now casts shadows:

  • Four cascaded shadow maps, 2048² each, cover the nearest 900 m. The four comes from the timecycle's dir_shadow_num_cascades.
  • Each cascade is an orthographic view from the light over the bounding sphere of its slice of the view. It is snapped to whole texels, so the shadows don't shimmer while the camera moves.
  • Lookups use a 4×4 filter of bilinear depth compares. The last tenth of each cascade blends into the next one, and past the last cascade the shadow fades out to fully lit.
  • Cascades split logarithmically from 3 m: about 12, 52, 216 and 900 m.
  • Cost: the two near cascades are drawn every frame and the two far ones on alternate frames. Each cascade draws only the models whose instances' bounding sphere can shadow it. All but the nearest skip models smaller than three of their texels, and the nearest skips map cells.
  • Casters: models and map cells, opaque and cut-out surfaces (alpha tested). Skinned, see-through and decal surfaces don't cast, and neither do coverage fallbacks.
  • The shadow multiplies the sun or moon light in the HDR shading, so it is applied everywhere that light is used: meshes, cells, terrain tiles, sheen and clear coat.
  • A sun and moon shadows checkbox, or --no-shadows, turns them off. The perf lines report shadow draws. The model viewer binds a 1-texel stand-in and is unchanged.

Known limits

  • Only what the camera draws casts. A tall caster just outside the view leaves no shadow.
  • No contact shadows or ray-traced shadows yet.

Verified

On an RTX 3090 (Vulkan), release build, city poses with all game files:

  • cargo test -p sixng-gui atmo:: shadow::: 6 passed. No panics and no wgpu validation errors.
  • 60 m up over a car park at 10h: a sharp building shadow across the lot and street, which is gone with --no-shadows. No acne on the plaza, roofs or ground. Decals show inside the shadow.
  • Slow pan at about 1 m/s, sampled every second: the shadow edges move smoothly with no crawl. Per-frame flicker can't be seen at that rate.
  • Cost: shadow draws went from 23 601 before caster culling to 2 610. Render CPU is 29.1 ms with shadows against 24.4 ms without, so the shadow pass costs about 4.7 ms. The limit is now the main pass (about 12k draws).
  • Model viewer: unchanged.
**@⁠holdmysocks** on GitHub · 2026-11-25 15:14 UTC · [original](https://github.com/holdmysocks/SixNG/pull/287) `holdmysocks:six-map3d-shadows` → `master` · +648 −12 · 7 files · 20 commits · merged 2026-11-25 18:48 UTC Stacked on #286 (the map's sky, light and exposure); this PR adds only the shadows. SIX-211. ## What it does The 3D map's sun (or the moon at night) now casts shadows: - Four cascaded shadow maps, 2048² each, cover the nearest 900 m. The four comes from the timecycle's `dir_shadow_num_cascades`. - Each cascade is an orthographic view from the light over the bounding sphere of its slice of the view. It is snapped to whole texels, so the shadows don't shimmer while the camera moves. - Lookups use a 4×4 filter of bilinear depth compares. The last tenth of each cascade blends into the next one, and past the last cascade the shadow fades out to fully lit. - Cascades split logarithmically from 3 m: about 12, 52, 216 and 900 m. - Cost: the two near cascades are drawn every frame and the two far ones on alternate frames. Each cascade draws only the models whose instances' bounding sphere can shadow it. All but the nearest skip models smaller than three of their texels, and the nearest skips map cells. - Casters: models and map cells, opaque and cut-out surfaces (alpha tested). Skinned, see-through and decal surfaces don't cast, and neither do coverage fallbacks. - The shadow multiplies the sun or moon light in the HDR shading, so it is applied everywhere that light is used: meshes, cells, terrain tiles, sheen and clear coat. - A **sun and moon shadows** checkbox, or `--no-shadows`, turns them off. The perf lines report shadow draws. The model viewer binds a 1-texel stand-in and is unchanged. ## Known limits - Only what the camera draws casts. A tall caster just outside the view leaves no shadow. - No contact shadows or ray-traced shadows yet. ## Verified On an RTX 3090 (Vulkan), release build, city poses with all game files: - `cargo test -p sixng-gui atmo:: shadow::`: 6 passed. No panics and no wgpu validation errors. - 60 m up over a car park at 10h: a sharp building shadow across the lot and street, which is gone with `--no-shadows`. No acne on the plaza, roofs or ground. Decals show inside the shadow. - Slow pan at about 1 m/s, sampled every second: the shadow edges move smoothly with no crawl. Per-frame flicker can't be seen at that rate. - Cost: shadow draws went from 23 601 before caster culling to 2 610. Render CPU is 29.1 ms with shadows against 24.4 ms without, so the shadow pass costs about 4.7 ms. The limit is now the main pass (about 12k draws). - Model viewer: unchanged.
sixng-core daylight: resolves the 12 weather types (weather type -> base
cycle GLOBAL region + modifier stack with submodifiers), interpolates the
13 time samples with their easing, and derives sun/moon direction, colour
and strength, ambient tint and strength and exposure. sixng daylight
prints them. The model view's Light section gets a weather list; viewer
default keeps the old light set-up.
Sunrise ~06:10 and sunset ~19:50 match where the cycle's directional
colours change from moonlight to sunlight; the sky stays lit down to -10
degrees.
HDR frame for the 3D map: the timecycle's atmosphere (sky_new_*) rendered
with transmittance, multiple-scattering, sky-view and aerial-perspective
tables; sun, moon, stars and air glow; surfaces lit by the sun's
illuminance through the air and the sky's ambient cube; the two height
fog layers; an exposure meter with the timecycle's percentiles, key value
and adaptation; bloom, contrast, saturation and a filmic curve. Weather
picker and --weather for Map 3D. The model viewer keeps its own light.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:24:44 +00:00
github manually merged commit f006b8d6c4 into gh-pr/287/base 2026-11-26 20:24:46 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.