Skip to content

cvcGL: shade a caster that moved between shadow bakes as it stood at the bake - #1466

Merged
transfix merged 1 commit into
masterfrom
cvcgl/shadow-at-bake-pose
Nov 23, 2026
Merged

transfix merged 1 commit into
masterfrom
cvcgl/shadow-at-bake-pose

Conversation

@transfix

Copy link
Copy Markdown
Owner

In the live gallery, terrain_lab's crates and boat flash. The scene re-bakes its shadow maps every 4th frame (update_interval: 4), and the frames between reuse the last maps. A caster that had moved since was looked up at its new pose against a map of its old one. Where it had moved behind its own baked surface it read as shadowed, and the patch cleared at the next bake.

Measured live on 2026-11-22. I read the mean luminance over each crate every frame, in the desktop app's browser pane. At interval 4 each crate's brightness jumps back up every 4th frame and dims over the three between. Its 4-frame component was 0.12-0.44, against 0.010-0.016 at interval 1 and 0.005-0.007 for open water.

Change

FilteredShadowMapPass now shades a caster that has moved since the last bake as it stood at that bake. This is the rigid-body counterpart of eaf5524, which looks a swaying tree's shadow up at its rest pose.

  • StridedShadowBaker records each caster's vtkProp3D matrix when it bakes (BakedPose). The entry holds a weak pointer, so a freed prop, or a new one at its address, reads as having no pose.
  • FilteredShadowMapPass:
    • Render keeps the frame's view matrix.
    • Per draw, SetShaderParameters checks the prop. For a caster whose matrix differs from its baked one, it uploads each shadowTransform as T·D, where D = V·M_bake·M_now⁻¹·V⁻¹ takes a view-space point on it now to where it stood at the bake.
    • The shader is unchanged, so foliage's calcShadow(cvcFwRestVC, ...) replacement still matches. The normal offset and the receiver-plane bias are carried through T·D with the point.
    • Static casters, non-casters and frames that bake keep VTK's transforms as set.
  • Unchanged: the shadows a moved caster throws on others, and the shade it receives, lag to the next bake.

The cost is a map lookup and a 16-double compare per caster draw. A caster that moved also pays two 4x4 multiplies, an inverse and one uniform upload per casting light.

Tests

cvcgl_shadow_bake_pose (new, renders, skips without GL) compares a frame that does not bake, with the maps one pose behind, against a frame that bakes at the same pose:

Check Old code (stale / fresh) This change (stale / fresh)
A. caster lowered 1.2 units: sunlit top 0.0 / 125.7 125.66 / 125.66
B. tilted 15°, lowered, moved away from the sun: top 0.0 / 118.2 118.21 / 118.21
C. a caster that did not move, and a non-caster that did: largest byte step 0 0

Run on Windows (MSVC Release, Intel Arc). The old-code column is the same test built against master's SceneGraph.cpp.

Locally, 18 cvcGL tests pass with this change: every test that renders with shadows, plus the physics scene tests. They include cvcgl_shadow_casters and its stride check, cvcgl_shadow_caster_growth, cvcgl_shadow_pass_programs (no shader rebuilds while a caster moves), cvcgl_shadow_pass_reuse, cvcgl_city_sun_shadows, cvcgl_lowmem_fastdraw, cvcgl_ariadne_realize and cvcgl_ariadne_physics. I haven't checked it in a WebGL build yet. The low-memory mapper that WebGL uses goes through the same SetShaderParameters, and that path is exercised natively by cvcgl_lowmem_fastdraw.

The gallery's terrain_lab keeps update_interval: 4. After this merges and deploys, the crates and boat should stop flashing there.

…the bake

With a strided shadow bake (update_interval > 1), the frames between bakes
reuse the last maps. A caster that had moved since was looked up at its new
pose against a map of its old one, so where it had moved behind its own
baked surface it read as shadowed until the next bake. In terrain_lab the
bobbing crates and the boat flashed every 4th frame.

StridedShadowBaker now records each caster's vtkProp3D matrix when it
bakes. Per draw, FilteredShadowMapPass uploads each shadowTransform for a
caster that moved as T*D, where D = V*M_bake*M_now^-1*V^-1, so the shader
is unchanged and foliage's rest-pose lookup still matches. Static casters,
non-casters and frames that bake keep VTK's transforms.

cvcgl_shadow_bake_pose compares a frame that does not bake against one that
bakes at the same pose; on the old code the moved caster's sunlit top read
0 against 125.7.
@transfix
transfix merged commit 93f0990 into master Nov 23, 2026
31 checks passed
@transfix
transfix deleted the cvcgl/shadow-at-bake-pose branch November 23, 2026 06:14
transfix added a commit that referenced this pull request Nov 23, 2026
…ers they drew stand

The baker notes each caster's pose when the maps draw it, and the shadow pass
shades a caster that moved since at that pose (#1466). A whole bake notes every
caster it drew; a bake of the moving casters alone notes those it redrew, so a
moving caster is shaded where it stands, and only between strided bakes at its
bake pose.
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