authoravatarclover caruso<git@paperclover.net>2026-12-01 10:00:02-08:00
committeravatarclover caruso<git@paperclover.net>2026-12-01 10:52:45-08:00
logb6ccfcc27229099569f7c6aeb0ef43d5189e7477
tree504ca14f34e2c9c4787f0f4e2e9a07ccef86e7d5
parent472baaeb7f0c565a1022bd0ff0a68630f7f6c52c
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

engine: Wave 20B TimeSpeed/TimeStretcher/Drip/FilmGrain parity and archive Loader/Merge DoD fixes


7 files changed, 425 insertions(+), 123 deletions(-)

crates/engine/src/eval/color.rs+95-8
...@@ -1169,45 +1169,78 @@ impl Engine {...@@ -1169,45 +1169,78 @@ impl Engine {
1169 };1169 };
1170 let src = self.eval_node(comp, src_id, time, enc, visiting, stats);1170 let src = self.eval_node(comp, src_id, time, enc, visiting, stats);
1171 let blend = comp.eval_number(node, "Blend", time, 1.0, &self.expr) as f32;1171 let blend = comp.eval_number(node, "Blend", time, 1.0, &self.expr) as f32;
1172 let strength = comp.eval_number(node, "MasterStrength", time, 0.05, &self.expr) as f32;1172 let strength = comp.eval_number(node, "MasterStrength", time, 0.1, &self.expr) as f32;
1173 if blend <= 1e-6 || strength.abs() <= 1e-6 {1173 let proc_zero = comp.eval_number(node, "ProcessWhenBlendIs00", time, 0.0, &self.expr) > 0.5;
1174 let mbm_flag = self.multiplies_by_mask(comp, node, time);
1175 if (blend <= 1e-6 && !proc_zero && !mbm_flag) || (strength.abs() <= 1e-6 && !mbm_flag) {
1174 return src;1176 return src;
1175 }1177 }
1176 let src = if Self::resolve_effect_mask_id(comp, node).is_some() { self.crop_to_canvas(enc, src) } else { src };1178 let src = if Self::resolve_effect_mask_id(comp, node).is_some() { self.crop_to_canvas(enc, src) } else { src };
1177 let x_size = comp.eval_number(node, "MasterXSize", time, 1.0, &self.expr) as f32;1179 let x_size = comp.eval_number(node, "MasterXSize", time, 1.0, &self.expr) as f32;
1178 let lock_size = comp.eval_number(node, "LockSize", time, 1.0, &self.expr) > 0.5;1180 let lock_size = comp.eval_number(node, "LockSizeXY", time, 1.0, &self.expr) > 0.5;
1179 let y_size = if lock_size {1181 let y_size = if lock_size {
1180 x_size1182 x_size
1181 } else {1183 } else {
1182 comp.eval_number(node, "MasterYSize", time, x_size as f64, &self.expr) as f321184 comp.eval_number(node, "MasterYSize", time, x_size as f64, &self.expr) as f32
1183 };1185 };
1184 let rough = comp.eval_number(node, "MasterRoughness", time, 0.0, &self.expr) as f32;1186 let rough = comp.eval_number(node, "MasterRoughness", time, 0.15, &self.expr) as f32;
1187 let master_off = comp.eval_number(node, "MasterOffset", time, 0.01, &self.expr) as f32;
1185 let log_proc = comp.eval_number(node, "LogProcessing", time, 1.0, &self.expr) as f32;1188 let log_proc = comp.eval_number(node, "LogProcessing", time, 1.0, &self.expr) as f32;
1189 let alpha_mult = comp.eval_number(node, "AlphaMultiply", time, 1.0, &self.expr) as f32;
1190 let color_str = comp.eval_number(node, "ColorStrength", time, 1.0, &self.expr) as f32;
1186 let time_lock = comp.eval_number(node, "TimeLockSeed", time, 0.0, &self.expr) > 0.5;1191 let time_lock = comp.eval_number(node, "TimeLockSeed", time, 0.0, &self.expr) > 0.5;
1187 let base_seed = comp.eval_number(node, "Seed", time, 0.0, &self.expr).round() as i32;1192 let base_seed = comp.eval_number(node, "Seed", time, 0.0, &self.expr).round() as i32;
1188 let seed = if time_lock { base_seed } else { base_seed.wrapping_add(frame_i as i32) };1193 let seed = if time_lock { base_seed } else { base_seed.wrapping_add(frame_i as i32) };
1189 let r_str = comp.eval_number(node, "RedStrength", time, 1.0, &self.expr) as f32;1194 let r_str = comp.eval_number(node, "RedStrength", time, 1.0, &self.expr) as f32;
1190 let g_str = comp.eval_number(node, "GreenStrength", time, 1.0, &self.expr) as f32;1195 let g_str = comp.eval_number(node, "GreenStrength", time, 1.0, &self.expr) as f32;
1191 let b_str = comp.eval_number(node, "BlueStrength", time, 1.0, &self.expr) as f32;1196 let b_str = comp.eval_number(node, "BlueStrength", time, 1.0, &self.expr) as f32;
1197 let r_x = comp.eval_number(node, "RedXSize", time, 1.0, &self.expr) as f32;
1198 let r_y = if lock_size { r_x } else { comp.eval_number(node, "RedYSize", time, r_x as f64, &self.expr) as f32 };
1199 let g_x = comp.eval_number(node, "GreenXSize", time, 1.0, &self.expr) as f32;
1200 let g_y = if lock_size { g_x } else { comp.eval_number(node, "GreenYSize", time, g_x as f64, &self.expr) as f32 };
1201 let b_x = comp.eval_number(node, "BlueXSize", time, 1.0, &self.expr) as f32;
1202 let b_y = if lock_size { b_x } else { comp.eval_number(node, "BlueYSize", time, b_x as f64, &self.expr) as f32 };
1203 let r_rough = comp.eval_number(node, "RedRoughness", time, 1.0, &self.expr) as f32;
1204 let g_rough = comp.eval_number(node, "GreenRoughness", time, 1.0, &self.expr) as f32;
1205 let b_rough = comp.eval_number(node, "BlueRoughness", time, 1.0, &self.expr) as f32;
1206 let r_off = comp.eval_number(node, "RedOffset", time, 0.0, &self.expr) as f32;
1207 let g_off = comp.eval_number(node, "GreenOffset", time, 0.0, &self.expr) as f32;
1208 let b_off = comp.eval_number(node, "BlueOffset", time, 0.0, &self.expr) as f32;
1192 let mono = comp.eval_number(node, "Monochrome", time, 1.0, &self.expr) as f32;1209 let mono = comp.eval_number(node, "Monochrome", time, 1.0, &self.expr) as f32;
1193 let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats);1210 let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats);
1194 let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash);1211 let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash);
1212 let mbm = mask.is_some() && mbm_flag;
1213 let skip = self.process_skip(comp, node, time);
11951214
1196 let mut u = UniformParams::default();1215 let mut u = UniformParams::default();
1197 u.p[0] = [strength, x_size, y_size, rough];1216 u.p[0] = [strength, x_size, y_size, rough];
1198 u.p[1] = [seed as f32, log_proc, blend, if mask.is_some() { 1.0 } else { 0.0 }];1217 u.p[1] = [seed as f32, log_proc, blend, if mask.is_some() { 1.0 } else { 0.0 }];
1199 u.p[2] = [if mask_inv { 1.0 } else { 0.0 }, r_str, g_str, b_str];1218 u.p[2] = [if mask_inv { 1.0 } else { 0.0 }, r_str, g_str, b_str];
1200 u.p[3] = [mono, 0.0, 0.0, 0.0];1219 u.p[3] = [mono, alpha_mult, master_off, color_str];
1201 let key = self.make_key(node, "FilmGrain", src.size, &[src.content_hash, mask_hash], bytemuck::cast_slice(&u.p[..4]));1220 u.p[4] = [r_x, r_y, r_rough, r_off];
1221 u.p[5] = [g_x, g_y, g_rough, g_off];
1222 u.p[6] = [b_x, b_y, b_rough, b_off];
1223 u.p[7] = [if mbm { 1.0 } else { 0.0 }, 0.0, 0.0, 0.0];
1224 u.p[8] = skip;
1225 let key = self.make_key(node, "FilmGrain", src.size, &[src.content_hash, mask_hash], bytemuck::cast_slice(&u.p[..9]));
1202 if let Some(hit) = self.cache.get(key, node.id, frame_i) {1226 if let Some(hit) = self.cache.get(key, node.id, frame_i) {
1203 stats.cache_hits += 1;1227 stats.cache_hits += 1;
1204 return hit;1228 return hit;
1205 }1229 }
1206 stats.cache_misses += 1;1230 stats.cache_misses += 1;
1207 stats.nodes_evaluated += 1;1231 stats.nodes_evaluated += 1;
1208 let dst = self.alloc_tex_like(&src, src.depth, key);1232 let clear_skip = mbm && skip.iter().any(|&s| s > 0.5);
1233 if clear_skip {
1234 u.p[8] = [0.0; 4];
1235 }
1236 let dst_raw = self.alloc_tex_like(&src, src.depth, if clear_skip { 0 } else { key });
1209 let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view);1237 let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view);
1210 self.dispatch_op(enc, ShaderOp::FilmGrain, &src.view, &self.dummy.view, mv, &dst, &u);1238 self.dispatch_op(enc, ShaderOp::FilmGrain, &src.view, &self.dummy.view, mv, &dst_raw, &u);
1239 let dst = if clear_skip {
1240 self.clear_skipped_channels(enc, &dst_raw, skip, key)
1241 } else {
1242 dst_raw
1243 };
1211 self.cache.insert(key, dst.clone(), node.id, frame_i);1244 self.cache.insert(key, dst.clone(), node.id, frame_i);
1212 dst1245 dst
1213 }1246 }
...@@ -1941,5 +1974,59 @@ mod tests {...@@ -1941,5 +1974,59 @@ mod tests {
1941 assert_eq!(px[2], 0, "MultiplyByMask=1 & ProcessBlue=0 clears unprocessed blue to 0, got {px:?}");1974 assert_eq!(px[2], 0, "MultiplyByMask=1 & ProcessBlue=0 clears unprocessed blue to 0, got {px:?}");
1942 assert_eq!(px[3], 255);1975 assert_eq!(px[3], 255);
1943 }1976 }
1977
1978 #[test]
1979 fn film_grain_alpha_multiply_and_monochrome_and_lock_size_xy() {
1980 let comp_src = r#"Composition {
1981 Tools = ordered() {
1982 SrcA0 = Background {
1983 Inputs = { Width = Input { Value = 32, }, Height = Input { Value = 32, },
1984 TopLeftRed = Input { Value = 0.5, }, TopLeftGreen = Input { Value = 0.5, }, TopLeftBlue = Input { Value = 0.5, }, TopLeftAlpha = Input { Value = 0.0, }, },
1985 },
1986 SrcA1 = Background {
1987 Inputs = { Width = Input { Value = 32, }, Height = Input { Value = 32, },
1988 TopLeftRed = Input { Value = 0.5, }, TopLeftGreen = Input { Value = 0.5, }, TopLeftBlue = Input { Value = 0.5, }, TopLeftAlpha = Input { Value = 1.0, }, },
1989 },
1990 FgMult1 = FilmGrain {
1991 Inputs = { Input = Input { SourceOp = "SrcA0", Source = "Output", }, MasterStrength = Input { Value = 0.3, }, LogProcessing = Input { Value = 0, }, AlphaMultiply = Input { Value = 1, }, },
1992 },
1993 FgMult0 = FilmGrain {
1994 Inputs = { Input = Input { SourceOp = "SrcA0", Source = "Output", }, MasterStrength = Input { Value = 0.3, }, LogProcessing = Input { Value = 0, }, AlphaMultiply = Input { Value = 0, }, },
1995 },
1996 FgColor = FilmGrain {
1997 Inputs = { Input = Input { SourceOp = "SrcA1", Source = "Output", }, MasterStrength = Input { Value = 0.3, }, Monochrome = Input { Value = 0, }, },
1998 },
1999 FgAniso = FilmGrain {
2000 Inputs = { Input = Input { SourceOp = "SrcA1", Source = "Output", }, MasterStrength = Input { Value = 0.3, }, LockSizeXY = Input { Value = 0, }, MasterXSize = Input { Value = 5.0, }, MasterYSize = Input { Value = 1.0, }, },
2001 },
2002 }
2003 }"#;
2004 let comp = Comp::from_fusion_str(comp_src).expect("parse FilmGrain test comp");
2005 let Ok(mut eng) = Engine::new_headless() else {
2006 return;
2007 };
2008 let (t1, _) = eng.evaluate(&comp, comp.find_node("FgMult1").unwrap(), 0.0);
2009 let p1 = eng.readback_rgba(&t1).unwrap();
2010 // AlphaMultiply=1 on alpha=0 preserves original RGB (128,128,128,0) everywhere.
2011 assert!(p1.chunks_exact(4).all(|p| p[0] == 128 && p[3] == 0), "AlphaMultiply=1 must leave alpha=0 RGB untouched");
2012
2013 let (t0, _) = eng.evaluate(&comp, comp.find_node("FgMult0").unwrap(), 0.0);
2014 let p0 = eng.readback_rgba(&t0).unwrap();
2015 assert!(p0.chunks_exact(4).any(|p| p[0] != 128 && p[3] == 0), "AlphaMultiply=0 must grain alpha=0 RGB");
2016
2017 let (tc, _) = eng.evaluate(&comp, comp.find_node("FgColor").unwrap(), 0.0);
2018 let pc = eng.readback_rgba(&tc).unwrap();
2019 assert!(pc.chunks_exact(4).any(|p| p[0] != p[1] || p[1] != p[2]), "Monochrome=0 must produce chromatic grain");
2020
2021 let (ta, _) = eng.evaluate(&comp, comp.find_node("FgAniso").unwrap(), 0.0);
2022 let pa = eng.readback_rgba(&ta).unwrap();
2023 let dx: u32 = (0..32).flat_map(|y| (0..31).map(move |x| (x, y)))
2024 .map(|(x, y)| pa[(y * 32 + x) * 4].abs_diff(pa[(y * 32 + x + 1) * 4]) as u32)
2025 .sum();
2026 let dy: u32 = (0..31).flat_map(|y| (0..32).map(move |x| (x, y)))
2027 .map(|(x, y)| pa[(y * 32 + x) * 4].abs_diff(pa[((y + 1) * 32 + x) * 4]) as u32)
2028 .sum();
2029 assert!(dy > dx * 2, "LockSizeXY=0 with MasterXSize=5, MasterYSize=1 must vary faster in Y ({dy}) than X ({dx})");
2030 }
1944}2031}
19452032
crates/engine/src/eval/composite.rs+32-22
...@@ -1,5 +1,27 @@...@@ -1,5 +1,27 @@
1use super::*;1use super::*;
22
3/// Expands `[bg0, bg1)` to include `[fg0, fg1)` with a 2px AA apron while
4/// clamping total span to `max_dim` without an artificial symmetric half-cap.
5fn expand_dod_axis(bg0: i32, bg1: i32, fg0: f32, fg1: f32, max_dim: i32) -> (i32, i32) {
6 let want0 = if fg0 < bg0 as f32 - 0.5 { bg0.min(fg0.floor() as i32 - 2) } else { bg0 };
7 let want1 = if fg1 > bg1 as f32 + 0.5 { bg1.max(fg1.ceil() as i32 + 2) } else { bg1 };
8 if want1 - want0 <= max_dim {
9 return (want0, want1);
10 }
11 let bg_span = bg1 - bg0;
12 if bg_span >= max_dim {
13 return (bg0, bg1);
14 }
15 let avail = max_dim - bg_span;
16 let pad0 = bg0 - want0;
17 let pad1 = want1 - bg1;
18 let total_pad = (pad0 + pad1).max(1);
19 let take0 = ((pad0 as i64 * avail as i64) / total_pad as i64) as i32;
20 let take1 = (avail - take0).min(pad1);
21 let take0 = (avail - take1).min(pad0);
22 (bg0 - take0, bg1 + take1)
23}
24
3impl Engine {25impl Engine {
4 fn flattened_fg_edge_mode(26 fn flattened_fg_edge_mode(
5 comp: &Comp,27 comp: &Comp,
...@@ -160,30 +182,12 @@ impl Engine {...@@ -160,30 +182,12 @@ impl Engine {
160 fg_y0 = fg_y0.min(py);182 fg_y0 = fg_y0.min(py);
161 fg_y1 = fg_y1.max(py);183 fg_y1 = fg_y1.max(py);
162 }184 }
163 let max_pad = 512_i32;185 let max_dim = self.device.limits().max_texture_dimension_2d.min(8192) as i32;
164 let ux0 = if fg_x0 < bg_x0 as f32 - 0.5 {186 let (ux0, ux1) = expand_dod_axis(bg_x0, bg_x1, fg_x0, fg_x1, max_dim);
165 bg_x0.min((fg_x0.floor() as i32 - 2).max(-max_pad))187 let (uy0, uy1) = expand_dod_axis(bg_y0, bg_y1, fg_y0, fg_y1, max_dim);
166 } else {
167 bg_x0
168 };
169 let uy0 = if fg_y0 < bg_y0 as f32 - 0.5 {
170 bg_y0.min((fg_y0.floor() as i32 - 2).max(-max_pad))
171 } else {
172 bg_y0
173 };
174 let ux1 = if fg_x1 > bg_x1 as f32 + 0.5 {
175 bg_x1.max((fg_x1.ceil() as i32 + 2).min(bg.canvas_size[0] as i32 + max_pad))
176 } else {
177 bg_x1
178 };
179 let uy1 = if fg_y1 > bg_y1 as f32 + 0.5 {
180 bg_y1.max((fg_y1.ceil() as i32 + 2).min(bg.canvas_size[1] as i32 + max_pad))
181 } else {
182 bg_y1
183 };
184 let uw = (ux1 - ux0).max(1) as u32;188 let uw = (ux1 - ux0).max(1) as u32;
185 let uh = (uy1 - uy0).max(1) as u32;189 let uh = (uy1 - uy0).max(1) as u32;
186 if uw <= 4096 && uh <= 4096 && (ux0 != bg_x0 || uy0 != bg_y0 || uw != bg.size[0] || uh != bg.size[1]) {190 if uw <= max_dim as u32 && uh <= max_dim as u32 && (ux0 != bg_x0 || uy0 != bg_y0 || uw != bg.size[0] || uh != bg.size[1]) {
187 dst_origin = [ux0, uy0];191 dst_origin = [ux0, uy0];
188 dst_size = [uw, uh];192 dst_size = [uw, uh];
189 }193 }
...@@ -1195,4 +1199,10 @@ mod tests {...@@ -1195,4 +1199,10 @@ mod tests {
1195 let (px, w, _) = eval_node_px(comp_src, "NoGreen");1199 let (px, w, _) = eval_node_px(comp_src, "NoGreen");
1196 assert_eq!(px_at(&px, w, 16, 16)[1], 204, "ProcessGreen=0 still outputs Foreground green at Mix=1, Blend=1");1200 assert_eq!(px_at(&px, w, 16, 16)[1], 204, "ProcessGreen=0 still outputs Foreground green at Mix=1, Blend=1");
1197 }1201 }
1202
1203 #[test]
1204 fn expand_dod_axis_allows_one_sided_extension_up_to_max_dim() {
1205 assert_eq!(super::expand_dod_axis(0, 1920, 4400.0, 6324.0, 8192), (0, 6326));
1206 assert_eq!(super::expand_dod_axis(-1000, 1920, -6000.0, 6000.0, 8192), (-3902, 4290));
1207 }
1198}1208}
crates/engine/src/eval/io.rs+50-13
...@@ -130,14 +130,14 @@ impl Engine {...@@ -130,14 +130,14 @@ impl Engine {
130 let missing_frames = comp130 let missing_frames = comp
131 .eval_number(node, "MissingFrames", time, 0.0, &self.expr)131 .eval_number(node, "MissingFrames", time, 0.0, &self.expr)
132 .round() as i32;132 .round() as i32;
133 let out_of_range_missing = missing_frames == 1133 // Outside `[GlobalStart - ExtendFirst, GlobalEnd + ExtendLast]` (with `Loop` allowing
134 && effective_clip.global_end >= effective_clip.global_start134 // playback past `GlobalEnd`), Fusion outputs no image regardless of `MissingFrames` or
135 && (effective_clip.length.unwrap_or(0) > 1135 // whether `Length == 1` (even single-frame stills return empty outside their active range).
136 || effective_clip.global_end > effective_clip.global_start)136 let out_of_range = effective_clip.global_end >= effective_clip.global_start
137 && (frame_i < effective_clip.global_start - effective_clip.extend_first.max(0)137 && (frame_i < effective_clip.global_start - effective_clip.extend_first.max(0)
138 || (!effective_clip.loop_clip138 || (!effective_clip.loop_clip
139 && frame_i > effective_clip.global_end + effective_clip.extend_last.max(0)));139 && frame_i > effective_clip.global_end + effective_clip.extend_last.max(0)));
140 let loaded = if out_of_range_missing {140 let loaded = if out_of_range {
141 None141 None
142 } else {142 } else {
143 self.media143 self.media
...@@ -337,14 +337,8 @@ impl Engine {...@@ -337,14 +337,8 @@ impl Engine {
337 }337 }
338 return None;338 return None;
339 }339 }
340 "TimeStretcher" => {340 "TimeStretcher" | "TimeSpeed" => {
341 cur_time = comp.eval_number(n, "SourceTime", cur_time, cur_time, &self.expr);341 cur_time = self.remap_time_node(comp, n, cur_time).unwrap_or(cur_time);
342 cur_id = n.connected_node("Input").and_then(|s| comp.find_node(s))?;
343 }
344 "TimeSpeed" => {
345 let speed = comp.eval_number(n, "Speed", cur_time, 1.0, &self.expr);
346 let delay = comp.eval_number(n, "Delay", cur_time, 0.0, &self.expr);
347 cur_time = (cur_time - delay) * speed;
348 cur_id = n.connected_node("Input").and_then(|s| comp.find_node(s))?;342 cur_id = n.connected_node("Input").and_then(|s| comp.find_node(s))?;
349 }343 }
350 "PipeRouter" | "Fuse.Wireless" | "Dimension.OpticalFlow" | "OpticalFlow" | "GamutConvert"344 "PipeRouter" | "Fuse.Wireless" | "Dimension.OpticalFlow" | "OpticalFlow" | "GamutConvert"
...@@ -1617,4 +1611,47 @@ Composition {{...@@ -1617,4 +1611,47 @@ Composition {{
1617 assert!(px.iter().all(|p| p.iter().any(|c| *c > 0.0)), "a NaN term would store as transparent black");1611 assert!(px.iter().all(|p| p.iter().any(|c| *c > 0.0)), "a NaN term would store as transparent black");
1618 assert!(px.iter().any(|p| *p != px[0]), "the quotient still varies across the frame");1612 assert!(px.iter().any(|p| *p != px[0]), "the quotient still varies across the frame");
1619 }1613 }
1614
1615 #[test]
1616 fn loader_single_frame_still_returns_empty_outside_range_unless_looping() {
1617 let dir = std::env::temp_dir().join("fission_loader_single_still_oob_test");
1618 let _ = std::fs::create_dir_all(&dir);
1619 let still = dir.join("still.png");
1620 write_solid_png(&still, 32, 32, [200, 80, 40, 255]);
1621 let comp_src = format!(
1622 r#"
1623Composition {{
1624 CurrentTime = 10,
1625 RenderRange = {{ 0, 30 }},
1626 GlobalRange = {{ 0, 30 }},
1627 Tools = ordered() {{
1628 Once = Loader {{
1629 Clips = {{ Clip {{ ID = "Clip1", Filename = "{}", Length = 1, Loop = 1, GlobalStart = 10, GlobalEnd = 10, }} }},
1630 Inputs = {{ GlobalIn = Input {{ Value = 10, }}, GlobalOut = Input {{ Value = 10, }}, }},
1631 }},
1632 Looped = Loader {{
1633 Clips = {{ Clip {{ ID = "Clip1", Filename = "{}", Length = 1, Loop = 0, GlobalStart = 10, GlobalEnd = 10, }} }},
1634 Inputs = {{ GlobalIn = Input {{ Value = 10, }}, GlobalOut = Input {{ Value = 10, }}, }},
1635 }},
1636 }},
1637}}"#,
1638 still.display(),
1639 still.display(),
1640 );
1641 let comp = Comp::from_fusion_str(&comp_src).expect("parse comp");
1642 let Ok(mut eng) = Engine::new_headless() else {
1643 let _ = std::fs::remove_dir_all(&dir);
1644 return;
1645 };
1646 let once = comp.find_node("Once").unwrap();
1647 let looped = comp.find_node("Looped").unwrap();
1648 let (in_range, _) = eng.evaluate(&comp, once, 10.0);
1649 assert_eq!(in_range.size, [32, 32]);
1650 let (oob_once, _) = eng.evaluate(&comp, once, 25.0);
1651 assert_eq!(oob_once.size, [1, 1]);
1652 assert_eq!(eng.readback_rgba(&oob_once).unwrap(), [0, 0, 0, 0]);
1653 let (oob_loop, _) = eng.evaluate(&comp, looped, 25.0);
1654 assert_eq!(oob_loop.size, [32, 32]);
1655 let _ = std::fs::remove_dir_all(&dir);
1656 }
1620}1657}
crates/engine/src/eval/mod.rs+163-63
...@@ -459,69 +459,8 @@ impl Engine {...@@ -459,69 +459,8 @@ impl Engine {
459 }459 }
460460
461 // TimeStretcher / TimeSpeed: remap time BEFORE evaluating upstream!461 // TimeStretcher / TimeSpeed: remap time BEFORE evaluating upstream!
462 if node.kind == "TimeStretcher" {462 if let Some(remapped) = self.remap_time_node(comp, node, time) {
463 let remapped = comp.eval_number(node, "SourceTime", time, time, &self.expr);463 return self.eval_time_remapped(comp, node, time, frame_i, remapped, enc, visiting, stats);
464 if let Some(src_id) = node.connected_node("Input").and_then(|s| comp.find_node(s)) {
465 let interp = comp
466 .eval_number(node, "InterpolateBetweenFrames", time, 1.0, &self.expr)
467 .round() as i32;
468 let f0 = remapped.floor();
469 let frac = (remapped - f0) as f32;
470 if interp >= 1 && frac > 1e-3 && frac < 1.0 - 1e-3 {
471 let src_node = comp.node(src_id);
472 let has_optflow = matches!(src_node.kind.as_str(), "Dimension.OpticalFlow" | "OpticalFlow");
473 let eval_src_id = if has_optflow {
474 src_node
475 .connected_node("Input")
476 .and_then(|s| comp.find_node(s))
477 .unwrap_or(src_id)
478 } else {
479 src_id
480 };
481 let tex_a = self.eval_node(comp, eval_src_id, f0, enc, visiting, stats);
482 let tex_b = self.eval_node(comp, eval_src_id, f0 + 1.0, enc, visiting, stats);
483 let use_flow = interp == 2 && (has_optflow || self.hiq);
484 let dst_depth = self.node_depth(comp, node, time, Some(tex_a.depth.max(tex_b.depth)));
485 let mut h = DefaultHasher::new();
486 self.cache.gpu_salt.hash(&mut h);
487 self.cache.node_salt(node.id).hash(&mut h);
488 "TimeStretcherInterp".hash(&mut h);
489 use_flow.hash(&mut h);
490 tex_a.content_hash.hash(&mut h);
491 tex_b.content_hash.hash(&mut h);
492 ((frac * 1000.0).round() as i32).hash(&mut h);
493 dst_depth.hash(&mut h);
494 let key = h.finish();
495 if let Some(hit) = self.cache.get(key, node.id, frame_i) {
496 stats.cache_hits += 1;
497 return hit;
498 }
499 stats.cache_misses += 1;
500 stats.nodes_evaluated += 1;
501 let fmt = self.texture_format_for(self.effective_depth(dst_depth));
502 let optflow = self.optflow.get_or_init(|| crate::optflow::OpticalFlowPipelines::new(&self.device));
503 let mut out = if use_flow {
504 optflow.interpolate_flow(&self.device, &self.queue, enc, &tex_a, &tex_b, frac, fmt)
505 } else {
506 optflow.blend_frames(&self.device, &self.queue, enc, &tex_a, &tex_b, frac, fmt)
507 };
508 out.depth = self.effective_depth(dst_depth);
509 out.content_hash = key;
510 self.cache.insert(key, out.clone(), node.id, frame_i);
511 return out;
512 }
513 return self.eval_node(comp, src_id, remapped, enc, visiting, stats);
514 }
515 return self.dummy.clone();
516 }
517 if node.kind == "TimeSpeed" {
518 let speed = comp.eval_number(node, "Speed", time, 1.0, &self.expr);
519 let delay = comp.eval_number(node, "Delay", time, 0.0, &self.expr);
520 let remapped = (time - delay) * speed;
521 if let Some(src_id) = node.connected_node("Input").and_then(|s| comp.find_node(s)) {
522 return self.eval_node(comp, src_id, remapped, enc, visiting, stats);
523 }
524 return self.dummy.clone();
525 }464 }
526 if node.kind == "Switch" || node.kind == "Fuse.Switch" {465 if node.kind == "Switch" || node.kind == "Fuse.Switch" {
527 let is_native_zero_indexed = node.kind == "Switch"466 let is_native_zero_indexed = node.kind == "Switch"
...@@ -708,6 +647,97 @@ impl Engine {...@@ -708,6 +647,97 @@ impl Engine {
708 (Some(out), invert)647 (Some(out), invert)
709 }648 }
710649
650 /// Computes the remapped source time for `TimeStretcher` or `TimeSpeed`.
651 pub(super) fn remap_time_node(&self, comp: &Comp, node: &Node, time: f64) -> Option<f64> {
652 match node.kind.as_str() {
653 "TimeStretcher" => Some(comp.eval_number(node, "SourceTime", time, 0.0, &self.expr)),
654 "TimeSpeed" => {
655 let speed = comp.eval_number(node, "Speed", time, 1.0, &self.expr);
656 let delay = comp.eval_number(node, "Delay", time, 0.0, &self.expr);
657 let g_start = comp.global_range[0] as f64;
658 let g_end = comp.global_range[1] as f64;
659 let raw = if speed < 0.0 {
660 // Fusion plays negative-speed clips backward from (GlobalEnd + 1) anchored at GlobalStart.
661 ((g_end + 1.0) + (time - delay - g_start) * speed).min(g_end)
662 } else {
663 g_start + (time - delay - g_start) * speed
664 };
665 Some(raw)
666 }
667 _ => None,
668 }
669 }
670
671 #[allow(clippy::too_many_arguments)]
672 fn eval_time_remapped(
673 &mut self,
674 comp: &Comp,
675 node: &Node,
676 time: f64,
677 frame_i: i64,
678 remapped: f64,
679 enc: &mut wgpu::CommandEncoder,
680 visiting: &mut HashSet<(NodeId, i64)>,
681 stats: &mut EvalStats,
682 ) -> CachedTexture {
683 let Some(src_id) = node.connected_node("Input").and_then(|s| comp.find_node(s)) else {
684 return self.dummy.clone();
685 };
686 let interp = comp
687 .eval_number(node, "InterpolateBetweenFrames", time, 1.0, &self.expr)
688 .round() as i32;
689 if interp <= 0 {
690 let snapped = (remapped + 0.5).floor();
691 return self.eval_node(comp, src_id, snapped, enc, visiting, stats);
692 }
693 let f0 = remapped.floor();
694 let frac = (remapped - f0) as f32;
695 if frac > 1e-3 && frac < 1.0 - 1e-3 {
696 let src_node = comp.node(src_id);
697 let has_optflow = matches!(src_node.kind.as_str(), "Dimension.OpticalFlow" | "OpticalFlow");
698 let eval_src_id = if has_optflow {
699 src_node
700 .connected_node("Input")
701 .and_then(|s| comp.find_node(s))
702 .unwrap_or(src_id)
703 } else {
704 src_id
705 };
706 let tex_a = self.eval_node(comp, eval_src_id, f0, enc, visiting, stats);
707 let tex_b = self.eval_node(comp, eval_src_id, f0 + 1.0, enc, visiting, stats);
708 let use_flow = interp == 2 && (has_optflow || self.hiq);
709 let dst_depth = self.node_depth(comp, node, time, Some(tex_a.depth.max(tex_b.depth)));
710 let mut h = DefaultHasher::new();
711 self.cache.gpu_salt.hash(&mut h);
712 self.cache.node_salt(node.id).hash(&mut h);
713 "TimeRemapInterp".hash(&mut h);
714 use_flow.hash(&mut h);
715 tex_a.content_hash.hash(&mut h);
716 tex_b.content_hash.hash(&mut h);
717 ((frac * 1000.0).round() as i32).hash(&mut h);
718 dst_depth.hash(&mut h);
719 let key = h.finish();
720 if let Some(hit) = self.cache.get(key, node.id, frame_i) {
721 stats.cache_hits += 1;
722 return hit;
723 }
724 stats.cache_misses += 1;
725 stats.nodes_evaluated += 1;
726 let fmt = self.texture_format_for(self.effective_depth(dst_depth));
727 let optflow = self.optflow.get_or_init(|| crate::optflow::OpticalFlowPipelines::new(&self.device));
728 let mut out = if use_flow {
729 optflow.interpolate_flow(&self.device, &self.queue, enc, &tex_a, &tex_b, frac, fmt)
730 } else {
731 optflow.blend_frames(&self.device, &self.queue, enc, &tex_a, &tex_b, frac, fmt)
732 };
733 out.depth = self.effective_depth(dst_depth);
734 out.content_hash = key;
735 self.cache.insert(key, out.clone(), node.id, frame_i);
736 return out;
737 }
738 self.eval_node(comp, src_id, remapped, enc, visiting, stats)
739 }
740
711 fn make_key(&self, node: &Node, tag: &str, size: [u32; 2], upstream: &[u64], params: &[f32]) -> u64 {741 fn make_key(&self, node: &Node, tag: &str, size: [u32; 2], upstream: &[u64], params: &[f32]) -> u64 {
712 let mut h = DefaultHasher::new();742 let mut h = DefaultHasher::new();
713 self.cache.gpu_salt.hash(&mut h);743 self.cache.gpu_salt.hash(&mut h);
...@@ -1229,4 +1259,74 @@ Composition {...@@ -1229,4 +1259,74 @@ Composition {
1229 assert_eq!(eng.vram_bytes(), 16 * 1024 * 1024);1259 assert_eq!(eng.vram_bytes(), 16 * 1024 * 1024);
1230 assert_eq!(eng.cache.budget_bytes, 56 * 1024 * 1024);1260 assert_eq!(eng.cache.budget_bytes, 56 * 1024 * 1024);
1231 }1261 }
1262
1263 #[test]
1264 fn time_speed_and_time_stretcher_match_fusion_global_range_and_defaults() {
1265 let src = r#"
1266Composition {
1267 CurrentTime = 0,
1268 RenderRange = { 0, 10 },
1269 GlobalRange = { -10, 40 },
1270 Tools = ordered() {
1271 TimeR = BezierSpline {
1272 KeyFrames = {
1273 [-10] = { 0.0, Flags = { Linear = true } },
1274 [40] = { 1.0, Flags = { Linear = true } },
1275 },
1276 },
1277 BG = Background {
1278 Inputs = {
1279 Width = Input { Value = 16, },
1280 Height = Input { Value = 16, },
1281 TopLeftRed = Input { SourceOp = "TimeR", Source = "Value", },
1282 TopLeftAlpha = Input { Value = 1.0, },
1283 },
1284 },
1285 TSNeg = TimeSpeed {
1286 Inputs = {
1287 Speed = Input { Value = -0.5, },
1288 Delay = Input { Value = 2.0, },
1289 Input = Input { SourceOp = "BG", Source = "Output", },
1290 },
1291 },
1292 TSPos = TimeSpeed {
1293 Inputs = {
1294 Speed = Input { Value = 0.5, },
1295 Input = Input { SourceOp = "BG", Source = "Output", },
1296 },
1297 },
1298 StrDef = TimeStretcher {
1299 Inputs = {
1300 Input = Input { SourceOp = "BG", Source = "Output", },
1301 },
1302 },
1303 StrSnap = TimeStretcher {
1304 Inputs = {
1305 SourceTime = Input { Value = 13.5, },
1306 InterpolateBetweenFrames = Input { Value = 0, },
1307 Input = Input { SourceOp = "BG", Source = "Output", },
1308 },
1309 },
1310 },
1311}
1312"#;
1313 let comp = Comp::from_fusion_str(src).expect("parse time remap comp");
1314 let Ok(mut eng) = Engine::new_headless() else {
1315 return;
1316 };
1317 let red_at = |e: &mut Engine, name: &str, t: f64| -> u8 {
1318 let (tex, _) = e.evaluate(&comp, comp.find_node(name).unwrap(), t);
1319 e.readback_rgba(&tex).unwrap()[0]
1320 };
1321 // Negative speed at t=4, delay=2, GlobalRange=[-10, 40]:
1322 // (40 + 1) + (4 - 2 - (-10)) * (-0.5) = 41 - 6 = 35 -> (35 - (-10))/50 = 0.90 -> 230
1323 assert!((red_at(&mut eng, "TSNeg", 4.0) as i32 - 230).abs() <= 2);
1324 // Positive speed at t=4, delay=0, GlobalRange=[-10, 40]:
1325 // -10 + (4 - (-10)) * 0.5 = -3 -> (-3 - (-10))/50 = 0.14 -> 36
1326 assert!((red_at(&mut eng, "TSPos", 4.0) as i32 - 36).abs() <= 2);
1327 // Omitted SourceTime defaults to 0.0 even at t=6 -> (0 - (-10))/50 = 0.20 -> 51
1328 assert!((red_at(&mut eng, "StrDef", 6.0) as i32 - 51).abs() <= 2);
1329 // InterpolateBetweenFrames=0 rounds half-up via floor(x + 0.5): 13.5 -> 14 -> (14 - (-10))/50 = 0.48 -> 122
1330 assert!((red_at(&mut eng, "StrSnap", 0.0) as i32 - 122).abs() <= 2);
1331 }
1232}1332}
crates/engine/src/eval/warps.rs+44-1
...@@ -84,7 +84,7 @@ impl Engine {...@@ -84,7 +84,7 @@ impl Engine {
84 }84 }
8585
86 /// Under `MultiplyByMask = 1`, Fusion clears any channel whose `Process*` toggle is off to `0.0`.86 /// Under `MultiplyByMask = 1`, Fusion clears any channel whose `Process*` toggle is off to `0.0`.
87 fn clear_skipped_channels(87 pub(super) fn clear_skipped_channels(
88 &self,88 &self,
89 enc: &mut wgpu::CommandEncoder,89 enc: &mut wgpu::CommandEncoder,
90 src: &CachedTexture,90 src: &CachedTexture,
...@@ -1401,4 +1401,47 @@ mod tests {...@@ -1401,4 +1401,47 @@ mod tests {
1401 assert_ne!(mul_px, [0, 0, 0, 0]);1401 assert_ne!(mul_px, [0, 0, 0, 0]);
1402 assert!(div_px[3] > 0, "Divide operation should produce non-degenerate output: {div_px:?}");1402 assert!(div_px[3] > 0, "Divide operation should produce non-degenerate output: {div_px:?}");
1403 }1403 }
1404
1405 #[test]
1406 fn drip_aspect_less_than_one_scales_y_and_preserves_x() {
1407 let make_comp = |aspect: f64| format!(r#"Composition {{ CurrentTime = 0, RenderRange = {{ 0, 0 }}, GlobalRange = {{ 0, 0 }}, Tools = ordered() {{
1408 BG = Background {{ Inputs = {{
1409 Width = Input {{ Value = 128, }}, Height = Input {{ Value = 128, }},
1410 Type = Input {{ Value = FuID {{ "Corner" }}, }},
1411 TopLeftRed = Input {{ Value = 0.0, }}, TopLeftGreen = Input {{ Value = 1.0, }},
1412 TopRightRed = Input {{ Value = 1.0, }}, TopRightGreen = Input {{ Value = 1.0, }},
1413 BottomLeftRed = Input {{ Value = 0.0, }}, BottomLeftGreen = Input {{ Value = 0.0, }},
1414 BottomRightRed = Input {{ Value = 1.0, }}, BottomRightGreen = Input {{ Value = 0.0, }},
1415 }}, }},
1416 D = Drip {{ Inputs = {{
1417 Input = Input {{ SourceOp = "BG", Source = "Output", }},
1418 Aspect = Input {{ Value = {aspect}, }},
1419 Amplitude = Input {{ Value = 0.15, }},
1420 Frequency = Input {{ Value = 10.0, }},
1421 }}, }},
1422 }} }}"#);
1423 let Ok(mut eng) = Engine::new_headless() else {
1424 return;
1425 };
1426 let c1 = Comp::from_fusion_str(&make_comp(1.0)).unwrap();
1427 let c05 = Comp::from_fusion_str(&make_comp(0.5)).unwrap();
1428 let (t1, _) = eng.evaluate(&c1, c1.find_node("D").unwrap(), 0.0);
1429 let (t05, _) = eng.evaluate(&c05, c05.find_node("D").unwrap(), 0.0);
1430 let p1 = eng.readback_rgba(&t1).unwrap();
1431 let p05 = eng.readback_rgba(&t05).unwrap();
1432 // Along the horizontal centerline y=64 (raw_rel.y ≈ 0), Aspect < 1 must keep X displacement unchanged.
1433 let mut x_axis_diff = 0u32;
1434 for x in 0..128 {
1435 let i = (64 * 128 + x) * 4;
1436 x_axis_diff += p1[i].abs_diff(p05[i]) as u32;
1437 }
1438 // Along the vertical centerline x=64, Aspect=0.5 halves Y frequency, producing clear differences.
1439 let mut y_axis_diff = 0u32;
1440 for y in 0..128 {
1441 let i = (y * 128 + 64) * 4;
1442 y_axis_diff += p1[i + 1].abs_diff(p05[i + 1]) as u32;
1443 }
1444 assert!(x_axis_diff <= 16, "Aspect < 1 must preserve X-axis ripples, got x_axis_diff={x_axis_diff}");
1445 assert!(y_axis_diff > 200, "Aspect=0.5 must stretch Y-axis ripples, got y_axis_diff={y_axis_diff}");
1446 }
1404}1447}
crates/engine/src/shaders/archive_fx.wgsl+7-2
...@@ -31,8 +31,13 @@ fn drip_op(@builtin(global_invocation_id) gid: vec3<u32>) {...@@ -31,8 +31,13 @@ fn drip_op(@builtin(global_invocation_id) gid: vec3<u32>) {
31 let shape = i32(u.p[2].x + 0.5);31 let shape = i32(u.p[2].x + 0.5);
32 let blend = u.p[2].y;32 let blend = u.p[2].y;
3333
34 let raw_rel = fu - center;34 let raw_rel = vec2<f32>(f32(gid.x) / f32(dims.x), f32(dims.y - 1u - gid.y) / f32(dims.y)) - center;
35 let rel = vec2<f32>(raw_rel.x / drip_aspect, raw_rel.y / canvas_aspect);35 let asp_rel = select(
36 vec2<f32>(raw_rel.x / drip_aspect, raw_rel.y),
37 vec2<f32>(raw_rel.x, raw_rel.y * drip_aspect),
38 drip_aspect < 1.0,
39 );
40 let rel = vec2<f32>(asp_rel.x, asp_rel.y / canvas_aspect);
3641
37 var src_fu = fu;42 var src_fu = fu;
38 if (shape == 2) {43 if (shape == 2) {
crates/engine/src/shaders/blur_glow.wgsl+34-14
...@@ -566,32 +566,52 @@ fn film_grain_op(@builtin(global_invocation_id) gid: vec3<u32>) {...@@ -566,32 +566,52 @@ fn film_grain_op(@builtin(global_invocation_id) gid: vec3<u32>) {
566 let seed = i32(u.p[1].x);566 let seed = i32(u.p[1].x);
567 let log_proc = u.p[1].y > 0.5;567 let log_proc = u.p[1].y > 0.5;
568 let blend = u.p[1].z;568 let blend = u.p[1].z;
569
570 let pos = vec2<f32>(f32(gid.x) / (sz_x * 1.65), f32(gid.y) / (sz_y * 1.65));
571 // Fusion FilmGrain defaults to monochrome correlated grain (Monochrome=1 -> rg_corr ~1.0)
572 let mono = u.p[3].x > 0.5;569 let mono = u.p[3].x > 0.5;
573 let n_luma = fg_gauss_field(pos, seed, rough);570 let alpha_mult = u.p[3].y > 0.5;
571 let master_off = u.p[3].z;
572 let color_str = clamp(u.p[3].w, 0.0, 1.0);
573 let mbm = u.p[7].x > 0.5;
574
575 let fg_xy = vec2<f32>(f32(gid.x), f32(gid.y));
576 let sz_r = max(vec2<f32>(sz_x * u.p[4].x, sz_y * u.p[4].y), vec2<f32>(0.25)) * 1.65;
577 let sz_g = max(vec2<f32>(sz_x * u.p[5].x, sz_y * u.p[5].y), vec2<f32>(0.25)) * 1.65;
578 let sz_b = max(vec2<f32>(sz_x * u.p[6].x, sz_y * u.p[6].y), vec2<f32>(0.25)) * 1.65;
579 let rough_r = clamp(rough * u.p[4].z, 0.0, 1.0);
580 let rough_g = clamp(rough * u.p[5].z, 0.0, 1.0);
581 let rough_b = clamp(rough * u.p[6].z, 0.0, 1.0);
582
574 var n_rgb: vec3<f32>;583 var n_rgb: vec3<f32>;
575 if (mono) {584 if (mono) {
576 n_rgb = vec3<f32>(n_luma);
577 } else {
578 n_rgb = vec3<f32>(585 n_rgb = vec3<f32>(
579 n_luma * 0.75 + fg_gauss_field(pos + vec2<f32>(31.7, 11.3), seed + 17, rough) * 0.661,586 fg_gauss_field(fg_xy / sz_r, seed, rough_r),
580 n_luma * 0.75 + fg_gauss_field(pos + vec2<f32>(-19.1, 47.9), seed + 37, rough) * 0.661,587 fg_gauss_field(fg_xy / sz_g, seed, rough_g),
581 n_luma * 0.75 + fg_gauss_field(pos + vec2<f32>(53.3, -29.7), seed + 73, rough) * 0.661,588 fg_gauss_field(fg_xy / sz_b, seed, rough_b),
582 );589 );
590 } else {
591 let n_luma = fg_gauss_field(fg_xy / (vec2<f32>(sz_x, sz_y) * 1.65), seed, clamp(rough, 0.0, 1.0));
592 let n_indep = vec3<f32>(
593 fg_gauss_field(fg_xy / sz_r + vec2<f32>(31.7, 11.3), seed + 1009, rough_r),
594 fg_gauss_field(fg_xy / sz_g + vec2<f32>(-19.1, 47.9), seed + 2027, rough_g),
595 fg_gauss_field(fg_xy / sz_b + vec2<f32>(53.3, -29.7), seed + 3037, rough_b),
596 );
597 n_rgb = mix(vec3<f32>(n_luma), n_indep, color_str);
583 }598 }
599 let ch_off = vec3<f32>(master_off) + vec3<f32>(u.p[4].w, u.p[5].w, u.p[6].w);
584 let nv = n_rgb * vec3<f32>(u.p[2].y, u.p[2].z, u.p[2].w) * strength;600 let nv = n_rgb * vec3<f32>(u.p[2].y, u.p[2].z, u.p[2].w) * strength;
585601
586 var rgb = src.rgb;602 var rgb = src.rgb;
587 if (log_proc) {603 if (log_proc) {
588 rgb = src.rgb * exp(nv * 1.08);604 rgb = (src.rgb + ch_off) * exp(nv * 0.55) - ch_off;
589 } else {605 } else {
590 rgb = src.rgb + nv * 0.55;606 rgb = src.rgb + nv * (0.55 + abs(ch_off) * 2.0);
591 }607 }
592 let m = read_mask(gid.xy, dims, u.p[1].w, u.p[2].x) * blend;608 if (alpha_mult) {
593 let out_col = mix(src, vec4<f32>(rgb, src.a), clamp(m, 0.0, 1.0));609 rgb = mix(src.rgb, rgb, clamp(src.a, 0.0, 1.0));
594 store_dst(vec2<i32>(gid.xy), out_col);610 }
611 let m = clamp(read_mask(gid.xy, dims, u.p[1].w, u.p[2].x) * blend, 0.0, 1.0);
612 let grained = vec4<f32>(rgb, src.a);
613 let res = select(mix(src, grained, m), grained * m, mbm);
614 store_dst(vec2<i32>(gid.xy), select(res, src, u.p[8] > vec4<f32>(0.5)));
595}615}
596616
597// ============================================================================617// ============================================================================