Repository navigation
cvcGL: shade a caster that moved between shadow bakes as it stood at the bake - #1466
Merged
Merged
Conversation
…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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
FilteredShadowMapPassnow 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.StridedShadowBakerrecords each caster'svtkProp3Dmatrix 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:Renderkeeps the frame's view matrix.SetShaderParameterschecks the prop. For a caster whose matrix differs from its baked one, it uploads eachshadowTransformas 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.calcShadow(cvcFwRestVC, ...)replacement still matches. The normal offset and the receiver-plane bias are carried through T·D with the point.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: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_castersand 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_realizeandcvcgl_ariadne_physics. I haven't checked it in a WebGL build yet. The low-memory mapper that WebGL uses goes through the sameSetShaderParameters, and that path is exercised natively bycvcgl_lowmem_fastdraw.The gallery's
terrain_labkeepsupdate_interval: 4. After this merges and deploys, the crates and boat should stop flashing there.