Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Invalidate cached frames after shadow jitter changes

dotCooCooacc0d5fd782b
diff --cc crates/render/src/disk_cache.rs
index f867a614a,4fa2e1cb3..26e684732
--- a/crates/render/src/disk_cache.rs
+++ b/crates/render/src/disk_cache.rs
@@@ -772,7 -772,7 +772,7 @@@ fn decode_layer(p: &[u8]) -> Option<Buf
// ---------------------------------------------------------------- content keys
/// Bump when rendering changes in a way that makes old disk entries wrong.
--const RENDER_VERSION: &str = "effectcraft-render-2";
++const RENDER_VERSION: &str = "effectcraft-render-3";
fn hash_debug(h: &mut Hash128, v: &impl std::fmt::Debug) {
h.write(format!("{v:?}").as_bytes());
@@@ -1001,6 -1001,6 +1001,28 @@@ mod tests
assert!(dc.get_frame(42).is_none());
}
++ #[test]
++ fn previous_renderer_frames_are_not_reused() {
++ use effectcraft_project::{Comp, ItemKind, Project};
++ use effectcraft_time::{FrameRate, Tick};
++
++ let mut project = Project::default();
++ let comp = Comp::new(2, 2, FrameRate::FPS_30, Tick::from_seconds_f64(1.0));
++ let id = project.add_item("Cached composition", effectcraft_color::Label::None, None, ItemKind::Comp(comp.into()));
++ let key = frame_key(comp_content_key(&project, id), 0, 1000, 0);
++ let previous_key = 188276472871424236106264377269312920732;
++ let dir = tmpdir("previous-renderer");
++ {
++ let cache = DiskCache::open(&dir, 1 << 30).unwrap();
++ cache.put_frame_now(previous_key, 2, 2, &[9; 16]);
++ }
++ let cache = DiskCache::open(&dir, 1 << 30).unwrap();
++ assert_eq!(cache.get_frame(previous_key).unwrap().rgba, vec![9; 16]);
++ assert!(cache.get_frame(key).is_none());
++ cache.put_frame_now(key, 2, 2, &[17; 16]);
++ assert_eq!(cache.get_frame(key).unwrap().rgba, vec![17; 16]);
++ }
++
#[test]
fn persists_across_restarts_and_clears() {
let dir = tmpdir("persist");
diff --cc crates/render/src/three_d/adv/shade.rs
index 0168a769e,9acc852fe..ddf752e7f
--- a/crates/render/src/three_d/adv/shade.rs
+++ b/crates/render/src/three_d/adv/shade.rs
@@@ -249,11 -230,10 +249,11 @@@ const PLANE_SLOPE_MAX: f32 = 64.0
/// Fraction of light reaching `p` through shadow map `m` (1 = lit). `ng` is the
/// receiver's geometric (not normal-mapped) normal facing the viewer.
///
- /// PCF over an N×N tap grid (5 ≤ N ≤ [`PCF_MAX_TAPS`]) spread over a reach derived
+ /// PCF over an N×N tap grid (5 ≤ N ≤ `PCF_MAX_TAPS`) spread over a reach derived
/// from `radius` (the wanted penumbra in output pixels) divided by the receiver's
-/// texel footprint, each tap jittered by an integer hash of the receiver's
-/// sub-texel cell and the tap index, and each tap comparing against the four
+/// texel footprint, each tap jittered by [`tap_jitter`] (an integer hash of the
+/// receiver's sub-texel lattice and the tap index, blended across the receiver's
+/// lattice cell), and each tap comparing against the four
/// nearest texel centres with bilinear weights. The jitter detaches the tap grid
/// from the texel axes (axis-aligned binary taps are what stair-step a straight
/// shadow edge), and keying it below texel size keeps the dither finer than an