mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-20 00:55:43 +00:00
Layer cache: masked buffers are keyed by the mask motion blur gate
A mask with Mask Motion Blur On blurs even when the layer's own switch is off, as long as the render's gate is open (Render Settings motion blur, and with Switches Affect Nested Comps the precomp layers above). The key held the layer's own motion blur state only, so a buffer blurred with the gate open was reused with it closed (and the other way round), also from the disk cache. Masked layer, input and footprint keys now tell a closed gate apart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a5e673dd6a
commit
e88b847259
3 files changed
+40
-1
No files matched your search
@@ -349,6 +349,7 @@ impl<'a> Renderer<'a> {
|
||||
pub fn adjustment_footprint(&self, ctx: &EvalCtx, layer: &Layer) -> Option<Arc<Buf>> {
|
||||
// Cached, so an accelerator sees the same buffer (and uploads it once) every frame.
|
||||
let key = self.cache.and_then(|_| cache::footprint_key(ctx, layer, self.raster_scale(ctx, layer), self.opts.draft, self.mb_on(ctx, layer)));
|
||||
let key = self.mask_gate_key(ctx, layer, key);
|
||||
if let Some((b, _)) = self.cached(key) {
|
||||
return Some(b);
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ impl<'a> Renderer<'a> {
|
||||
/// A processed-layer cache key that also covers content motion blur (the averaged source
|
||||
/// depends on the content at every sub-sample).
|
||||
pub(crate) fn content_key(&self, ctx: &EvalCtx, layer: &Layer, key: Option<u64>) -> Option<u64> {
|
||||
let k = key?;
|
||||
let k = self.mask_gate_key(ctx, layer, key)?;
|
||||
// A layer that reads other layers through its effects' layer parameters gets them drawn
|
||||
// by this renderer: the switches it passes down (Switches Affect Nested Comps, the
|
||||
// precomp layers above, motion blur on) change those pixels, not just the layers' own.
|
||||
@@ -274,6 +274,15 @@ impl<'a> Renderer<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// A cache key of a masked layer's buffer, told apart when mask motion blur can't run at all
|
||||
/// in this render ([`Self::mask_blur`]'s gate: the render options, the precomp layers above).
|
||||
/// The key has the layer's own motion blur state, but a mask set to On blurs without it.
|
||||
pub(crate) fn mask_gate_key(&self, ctx: &EvalCtx, layer: &Layer, key: Option<u64>) -> Option<u64> {
|
||||
let k = key?;
|
||||
let masked = layer.masks().is_some_and(|m| !m.children.is_empty());
|
||||
Some(if masked && !self.mask_blur(ctx, layer).allowed { cache::derive(k, 0x6d62_6f66) } else { k })
|
||||
}
|
||||
|
||||
/// Motion-blur sub-samples for a layer buffer (1 = no motion blur). As in After Effects, a 2D
|
||||
/// layer gets about one sample per output pixel its corners travel during the shutter,
|
||||
/// at least Samples Per Frame and at most the comp's Adaptive Sample Limit; a layer that
|
||||
|
||||
@@ -75,3 +75,32 @@ fn mask_motion_blur_follows_the_render_and_the_comp() {
|
||||
let (p, cid) = project(false);
|
||||
assert!(alpha_at_25(&p, cid, true) < 0.01, "the comp's switch off");
|
||||
}
|
||||
|
||||
/// Whether mask motion blur may run at all (the render options, Switches Affect Nested Comps with
|
||||
/// a precomp layer's switch off) is part of the layer cache key, also for a layer whose own
|
||||
/// switch is off: a buffer made with the gate open must not serve a render with it closed.
|
||||
#[test]
|
||||
fn the_mask_motion_blur_gate_keys_the_layer_cache() {
|
||||
let (mut p, inner) = project(true);
|
||||
let mut outer = Comp::new(100, 100, FrameRate::FPS_30, Tick::from_seconds_f64(1.0));
|
||||
outer.enable_motion_blur = true;
|
||||
let mut pre = build::layer(&mut p, &outer, "Inner", LayerSource::Comp { item: inner }, (100, 100), None);
|
||||
pre.switches.motion_blur = false;
|
||||
outer.layers.push(pre);
|
||||
let oid = p.add_item("Outer", Label::Sandstone, None, ItemKind::Comp(outer.into()));
|
||||
let half = Tick::from_seconds_f64(0.5 / 30.0);
|
||||
let cache = crate::LayerCache::default();
|
||||
let render = |cid: ItemId, opts: RenderOpts, cached: bool| {
|
||||
let mut r = Renderer::new(&p, &NoFootage, opts);
|
||||
r.cache = cached.then_some(&cache);
|
||||
r.comp_frame(cid, half).data
|
||||
};
|
||||
let on = RenderOpts { motion_blur: true, nested_switches: true, ..Default::default() };
|
||||
let off = RenderOpts { nested_switches: false, ..on };
|
||||
assert!(render(oid, on, false) != render(oid, off, false), "the precomp layer's switch closes the gate");
|
||||
assert!(render(oid, off, true) == render(oid, off, false));
|
||||
assert!(render(oid, on, true) == render(oid, on, false), "not the buffer blurred with the gate open");
|
||||
let still = RenderOpts { motion_blur: false, ..on };
|
||||
assert!(render(inner, on, true) == render(inner, on, false));
|
||||
assert!(render(inner, still, true) == render(inner, still, false), "Render Settings ▸ Motion Blur off");
|
||||
}
|
||||
Reference in new issue
Block a user