Skip to content

cvcGL: shadows at a city's scale -- a filtered depth lookup and a shadow focus - #946

Merged
transfix merged 5 commits into
masterfrom
feat/cvcgl-sun-shadows
Nov 1, 2026
Merged

transfix merged 5 commits into
masterfrom
feat/cvcgl-sun-shadows

Conversation

@transfix

Copy link
Copy Markdown
Owner

cvcdbg's demo3 has never shown a shadow. The cause is how VTK's shadow lookup behaves at a city's scale, plus a bug in VTK's bake. This fixes both, and adds a way to spend the shadow map where the camera looks.

Why nothing shadowed. VTK 9.5's vtkShadowMapPass uses exponential shadow maps. The shadow factor is exp(c * (occluder depth - receiver depth)), with both depths normalised over the light camera's whole depth range and c = 11.

  • demo3 lights a 3 km city with a StageLighting key 2.2 stage radii out (4.7 km).
  • A 50 m building there darkens the ground behind it by about a fifth of the key light.
  • A 2 m vehicle darkens it by about a hundredth.
  • The key's 62-degree cone spreads a 4096 map over about 17 km of ground, about 4 m a texel.

Changes (all in src/cvcGL/SceneGraph.cpp):

  • FilteredShadowMapPass (a vtkShadowMapPass subclass, installed by installShadowPasses):
    • VTK's maps stay exactly as baked (exp(c * depth)). The lookup reads each tap back as a depth (log(texel) / c) and depth-tests it over a 16-tap Poisson disc (percentage-closer filtering).
    • A normal offset, a depth bias, and a receiver-plane bias (the receiver's depth slope across the map, from screen derivatives) keep shadow acne off. All three are sized in shadow-map texels at the receiver, so none depends on the scene's units.
    • A texel nothing was drawn into reads lit, and the shadow fades out over the map's outer tenth.
    • SceneGraph::setShadowSoftness(texels) sets the disc's radius (default 2).
  • StridedShadowBaker bakes through its own copy of VTK's bake loop (BSD, attributed). Two changes against VTK:
    • The bake's shader keys go on every prop it draws (PreRender(&s2), where VTK has PreRender(s)). VTK keys only the props the main camera kept after culling, so a caster out of view drew its colour, not its depth, into the map. The exponential lookup happened to read that as an occluder in front of everything, so cvcgl_shadow_casters D's out-of-view slab shadowed. A depth lookup cannot read it that way.
    • The maps are cleared to 0. A drawn texel is at least 1, so an empty texel is never mistaken for a caster at the light's near plane.
  • SceneGraph::setShadowFocus(x, y, z, radius) / clearShadowFocus(). Each light's map is aimed at a sphere instead of fitted to the whole scene:
    • A spot keeps its position and narrows its view to the sphere.
    • A directional light's parallel view is centred on the sphere.
    • Both keep the whole scene's depth range, so anything between the light and the sphere still casts into it.
    • Moving the focus a fiftieth of its radius re-bakes.
    • With demo3's sun focused on a 400 m sphere, a texel is about 0.2 m.

Tests

  • New cvcgl_city_sun_shadows: a 3 km ground, a 50 m building and a 2 m box under demo3's rig (key 1.3 at azimuth -60, elevation 28, cone 62).
    • Unfocused: the building's shadow reads 104 luma against 149 sunward and 153 beside it.
    • Focused on the box: its shadow reads 102 against 153.
    • Outside the focused map the building's shadow is gone (157); clearing the focus brings it back.
    • On master all three shadow checks fail (shadow 242, sunward 196, beside 248).
  • Existing tests, Windows MSVC Release: cvcgl_shadow_casters (D's slab now shadows its footprint to 0 luma), _caster_growth, _pass_reuse, cvcgl_stage_caster_truth, cvcgl_shadow_volume, cvcgl_lighting, cvcgl_lowmem_fastdraw (traces and pixels on both draw paths), cvcgl_streaming_overlays and cvcgl_renderer all pass.
  • Full ctest -R cvcgl_: 82 of 84 pass.
    • cvcgl_lowmem_fastdraw was one of the 2, before the clear-to-0 fix; it passes now (above).
    • cvcgl_fe_interval was the other. It runs libigl-only mesh ops outside its libigl guard, so it aborts on a build without libigl, as this tree is. Not this change; the FEM session is fixing the guard separately.

…dow focus

VTK 9.5's shadow lookup is an exponential shadow map: the factor is exp(c * (occluder depth -
receiver depth)) over the light camera's whole depth range, c = 11. Over a 3 km city lit from
4.7 km out a 50 m building dims the ground behind it by a fifth of the key and a 2 m vehicle by a
hundredth, so nothing reads as shadow.

- FilteredShadowMapPass reads VTK's maps (exp(c * depth)) back as depths and filters a depth test
  over a 16-tap Poisson disc, with a normal offset, a depth bias and a receiver-plane bias sized
  in shadow-map texels at the receiver; an empty texel reads lit and the shadow fades out at the
  map's border. SceneGraph::setShadowSoftness sets the disc.
- StridedShadowBaker bakes through its own copy of VTK's bake loop, which puts the bake's shader
  keys on every prop it draws (VTK keys only the props the main camera kept, so a caster out of
  view drew its colour into the map) and clears the maps to 0.
- SceneGraph::setShadowFocus aims each light's map at a sphere (a follow camera's subject) instead
  of fitting it to the whole scene; whatever lies between the light and the sphere still casts.
- cvcgl_city_sun_shadows: a building's shadow over a 3 km ground, and a 2 m box's with the map
  focused on it.
On macOS (package-macos release-grpc jobs) the held-out calibration closes the dissipation to
0.152 against a 0.15 bound and its calibrated step's twist is 1% over the uncalibrated one's, and
the gradient check's beta and gamma (a quarter of alpha there) flip sign against Jolt's finite
differences while the gradient as a whole agrees (ratio 0.92). The calibration's margins are 0.2
and 5%; the per-bias checks apply to components at least a third of the largest (all three on
Windows), and the whole-gradient check is unchanged.
…caster

The renderer clears each shadow map to its background, not to the 0 the bake asked for, so on
cvcdbg's pale sky (red 0.78) with a ground that casts nothing, every empty texel read as an
occluder in front of everything and the open ground went dark (149 -> 94 luma). The bake now
writes 1 + exp(c * depth) (at least 2, over a clear of at most 1) and the lookup decodes
log(t - 1) / c; cvcgl_city_sun_shadows C checks that case.
vtkOpenGL{Clear,Check}ErrorMacro report only without NDEBUG, so VTK's own around its bake compile
away in the VTK libcvc links; in the fork they reported, in libcvc's Debug builds, the error VTK's
low-memory mapper raises on its own: GL_INVALID_OPERATION from six draws in the first bake after
vtkOpenGLShaderCache::ReleaseGraphicsResources() (cvcgl_lowmem_fastdraw's lifecycle step), on
VTK's stock draw path and through vtkShadowMapBakerPass::Render alike. That frame's main pass
raises GL_INVALID_VALUE too. cvcgl_lowmem_fastdraw failed 'no VTK errors' on package-linux Debug.
@transfix
transfix merged commit a6d052c into master Nov 1, 2026
20 of 27 checks passed
@transfix
transfix deleted the feat/cvcgl-sun-shadows branch November 1, 2026 03:26
transfix added a commit that referenced this pull request Nov 1, 2026
The heat-stop check sent "stop" once fe.progress reached 1%. The first 3%
of a solve job's progress is the boundary walk before the solve, so on a
slow build (package-linux Debug-grpc) the stop landed there and the job
ended with nothing ('heat: stopped'), failing "heat.steps = 1e30 is
clamped, and stop interrupts it" (#944's CI, and twice on #946's).

Wait for fe.phase "stepping" instead: the time steps are under way, so a
stop ends the solve at a step, and a solve wrapped to one step is still
caught (done, busy 0, before the stop).

(cherry picked from commit 23eae43)
transfix added a commit that referenced this pull request Nov 1, 2026
Releases #946 (cvcGL shadows at a city's scale), which 3.7.6 shipped without.
transfix added a commit that referenced this pull request Nov 1, 2026
The heat-stop check sent stop at fe.progress 1%, which a slow build reaches during the boundary walk before the solver, so the job ended with nothing ('heat: stopped'). It now waits for fe.phase "stepping". package-linux Debug-grpc, where it failed on #944 and #946, passes.
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.

1 participant