1use super::*;
2
3/// `base` carrying a constant `(vx, vy)` field in aux channel `chan`. The blue channel makes each
4/// scene's value image distinct so identical-content nodes never share cache entries.
5fn vec_scene(name: &str, base: &str, v: [f32; 2], chan: &str) -> String {
6 let tag = name.bytes().map(f32::from).sum::<f32>() * 0.001;
7 format!("{}{}", solid(&format!("{name}V"), 32, 32, [v[0], v[1], tag, 1.0]), aux_chain(name, base, &[(chan, &format!("{name}V"))]))
8}
9
10#[test]
11fn vector_transform_scales_rotates_smooths_and_attenuates_aux_vectors() {
12 let Some(mut eng) = engine() else { return };
13 let vt = |extra: &[String]| {
14 let mut v = vec![inp("Input", "Scene")];
15 v.extend_from_slice(extra);
16 v
17 };
18 let tools = [
19 solid("Base", 32, 32, [0.1, 0.2, 0.3, 1.0]),
20 solid("FV", 32, 32, [4.0, -2.0, 0.0, 1.0]),
21 solid("BV", 32, 32, [1.0, 1.0, 0.0, 1.0]),
22 aux_chain("Scene", "Base", &[("Vector", "FV"), ("BackVector", "BV")]),
23 grad("StepFV", 32, 32, [0.0, 0.0, 0.0, 1.0], [32.0, 0.0, 0.0, 1.0], false),
24 aux_chain("Step", "Base", &[("Vector", "StepFV")]),
25 node("Ident", "VectorTransform", &vt(&[])),
26 node("Size", "VectorTransform", &vt(&[val("XSize", 2.0), val("YSize", 3.0)])),
27 node("SizeAspect", "VectorTransform", &vt(&[val("UseSizeAndAspect", 1.0), val("Size", 2.0), val("Aspect", 1.5), val("XSize", 9.0)])),
28 node("Rot", "VectorTransform", &vt(&[val("Angle", 90.0)])),
29 node("Half", "VectorTransform", &vt(&[val("Angle", 90.0), val("AttenuateVect", 0.5)])),
30 node("None", "VectorTransform", &vt(&[val("Angle", 90.0), val("AttenuateVect", 0.0)])),
31 node("Smooth", "VectorTransform", &[inp("Input", "Step"), val("SmoothVector", 4.0)]),
32 node("NoVec", "VectorTransform", &[inp("Input", "Base"), val("Angle", 90.0), val("XSize", 3.0)]),
33 ]
34 .concat();
35 let comp = mk_comp(&tools);
36 let vectors = |eng: &mut Engine, name: &str| {
37 let (tex, _) = eval(eng, &comp, name, 0.0);
38 let aux = tex.aux.as_ref().unwrap_or_else(|| panic!("{name}: aux missing"));
39 (aux_px(eng, aux.vector.as_ref().unwrap()), aux.back_vector.as_ref().map(|b| aux_px(eng, b)))
40 };
41 let check = |eng: &mut Engine, name: &str, f: [f32; 2], b: [f32; 2]| {
42 let (fv, bv) = vectors(eng, name);
43 let (fv, bv) = (aux_at(&fv, 32, 16, 16), aux_at(&bv.unwrap(), 32, 16, 16));
44 assert!((fv[0] - f[0]).abs() < 0.02 && (fv[1] - f[1]).abs() < 0.02, "{name}: forward {fv:?} != {f:?}");
45 assert!((bv[0] - b[0]).abs() < 0.02 && (bv[1] - b[1]).abs() < 0.02, "{name}: back {bv:?} != {b:?}");
46 };
47 check(&mut eng, "Ident", [4.0, -2.0], [1.0, 1.0]);
48 check(&mut eng, "Size", [8.0, -6.0], [2.0, 3.0]);
49 check(&mut eng, "SizeAspect", [8.0, -6.0], [2.0, 3.0]);
50 check(&mut eng, "Rot", [2.0, 4.0], [-1.0, 1.0]);
51 check(&mut eng, "Half", [3.0, 1.0], [0.0, 1.0]);
52 check(&mut eng, "None", [4.0, -2.0], [1.0, 1.0]);
53
54 let (tex, p) = eval(&mut eng, &comp, "Size", 0.0);
55 assert_eq!(px(&p, 32, 16, 16), [0.1, 0.2, 0.3, 1.0], "colour passes through");
56 assert!(tex.aux.is_some());
57
58 let (ramp, _) = vectors(&mut eng, "Smooth");
59 assert!((aux_at(&ramp, 32, 16, 16)[0] - 16.5).abs() < 0.2, "a linear ramp is its own 3-tap average");
60 assert!((aux_at(&ramp, 32, 1, 16)[0] - 2.5).abs() < 0.2, "taps at x-4, x, x+4 clamp to the border: {:?}", aux_at(&ramp, 32, 1, 16));
61
62 let (_, no_vec) = eval(&mut eng, &comp, "NoVec", 0.0);
63 assert_eq!(px(&no_vec, 32, 16, 16), [0.1, 0.2, 0.3, 1.0], "without vectors the image is untouched, RG is never rotated");
64}
65
66#[test]
67fn vector_warp_direction_scale_edges_and_vector_input() {
68 let Some(mut eng) = engine() else { return };
69 let vw = |input: &str, extra: &[String]| {
70 let mut v = vec![inp("Input", input)];
71 v.extend_from_slice(extra);
72 v
73 };
74 let edge = |name: &str, e: &str| node(name, "VectorWarp", &vw("SceneH", &[format!("Edges = Input {{ Value = FuID {{ \"{e}\" }}, }},")]));
75 let tools = [
76 grad("RampH", 32, 32, [0.0, 0.0, 0.0, 1.0], [1.0, 1.0, 1.0, 1.0], false),
77 grad("RampV", 32, 32, [0.0, 0.0, 0.0, 1.0], [1.0, 1.0, 1.0, 1.0], true),
78 vec_scene("SceneH", "RampH", [4.0, 0.0], "Vector"),
79 vec_scene("SceneV", "RampV", [0.0, 4.0], "Vector"),
80 vec_scene("SceneB", "RampH", [4.0, 0.0], "BackVector"),
81 solid("RgVec", 32, 32, [4.0, 0.0, 0.0, 1.0]),
82 node("WarpH", "VectorWarp", &vw("SceneH", &[])),
83 node("Scale2", "VectorWarp", &vw("SceneH", &[val("Scale", 2.0)])),
84 node("Steps", "VectorWarp", &vw("SceneH", &[val("SubSteps", 4.0)])),
85 node("WarpV", "VectorWarp", &vw("SceneV", &[])),
86 edge("EBlack", "Black"),
87 edge("EDup", "Duplicate"),
88 edge("EWrap", "Wrap"),
89 edge("EMirror", "Mirror"),
90 node("Back", "VectorWarp", &vw("SceneB", &["Direction = Input { Value = FuID { \"Backward\" }, },".into()])),
91 node("BackFwd", "VectorWarp", &vw("SceneB", &[])),
92 node("External", "VectorWarp", &vw("RampH", &[inp("VectorInput", "RgVec")])),
93 node("Half", "VectorWarp", &vw("SceneH", &[val("Blend", 0.5)])),
94 rect_mask("RightHalf", [0.75, 0.5], [0.5, 1.0]),
95 node("Masked", "VectorWarp", &vw("SceneH", &[inp("EffectMask", "RightHalf").replace("Output", "Mask")])),
96 ]
97 .concat();
98 let comp = mk_comp(&tools);
99 let at = |p: &[f32], x: u32, y: u32| px(p, 32, x, y);
100 let (_, src) = eval(&mut eng, &comp, "RampH", 0.0);
101 let base = at(&src, 16, 16)[0];
102
103 let (tex, w) = eval(&mut eng, &comp, "WarpH", 0.0);
104 assert!((base - at(&w, 16, 16)[0] - 4.0 / 31.0).abs() < 0.02, "content moves +4px right: {} vs {base}", at(&w, 16, 16)[0]);
105 assert!(tex.aux.as_ref().and_then(|a| a.vector.as_ref()).is_some(), "aux preserved");
106 let (_, s2) = eval(&mut eng, &comp, "Scale2", 0.0);
107 assert!((base - at(&s2, 16, 16)[0] - 8.0 / 31.0).abs() < 0.02, "Scale=2 doubles the shift");
108 let (_, st) = eval(&mut eng, &comp, "Steps", 0.0);
109 assert!((at(&st, 16, 16)[0] - at(&w, 16, 16)[0]).abs() < 0.01, "SubSteps integrate a constant field identically");
110
111 let (_, v) = eval(&mut eng, &comp, "WarpV", 0.0);
112 let (_, srcv) = eval(&mut eng, &comp, "RampV", 0.0);
113 assert!(at(&v, 16, 16)[0] > at(&srcv, 16, 16)[0] + 0.1, "+Y vectors move content up (samples from below)");
114
115 assert!(at(&eval(&mut eng, &comp, "EBlack", 0.0).1, 1, 16)[3] < 0.01, "Black edge is transparent");
116 assert!(at(&eval(&mut eng, &comp, "EDup", 0.0).1, 1, 16)[0] < 0.05, "Duplicate holds the border");
117 assert!(at(&eval(&mut eng, &comp, "EWrap", 0.0).1, 1, 16)[0] > 0.8, "Wrap pulls from the far side");
118 let mir = at(&eval(&mut eng, &comp, "EMirror", 0.0).1, 1, 16);
119 assert!(mir[3] > 0.99 && mir[0] < 0.2, "Mirror reflects the border, got {mir:?}");
120
121 let (_, back) = eval(&mut eng, &comp, "Back", 0.0);
122 assert!((base - at(&back, 16, 16)[0] - 4.0 / 31.0).abs() < 0.02, "Direction=Backward reads aux.back_vector");
123 let (_, back_fwd) = eval(&mut eng, &comp, "BackFwd", 0.0);
124 assert!((at(&back_fwd, 16, 16)[0] - base).abs() < 1e-4, "no aux.vector -> Input unchanged");
125 let (_, ext) = eval(&mut eng, &comp, "External", 0.0);
126 assert!((at(&ext, 16, 16)[0] - at(&w, 16, 16)[0]).abs() < 0.01, "VectorInput RG drives the warp");
127 let (_, half) = eval(&mut eng, &comp, "Half", 0.0);
128 assert!((at(&half, 16, 16)[0] - (base + at(&w, 16, 16)[0]) * 0.5).abs() < 0.01, "Blend");
129 let (_, masked) = eval(&mut eng, &comp, "Masked", 0.0);
130 assert!((at(&masked, 4, 16)[0] - at(&src, 4, 16)[0]).abs() < 1e-4, "unmasked half untouched");
131 assert!((at(&masked, 28, 16)[0] - at(&w, 28, 16)[0]).abs() < 1e-4, "masked half warped");
132}
133
134#[test]
135fn smooth_motion_smooths_vectors_over_time_and_keeps_rgba() {
136 let Some(mut eng) = engine() else { return };
137 let sm = |extra: &[String]| {
138 let mut v = vec![inp("Input", "Scene")];
139 v.extend_from_slice(extra);
140 v
141 };
142 let tools = [
143 solid("Base", 16, 16, [0.1, 0.2, 0.3, 1.0]),
144 // vx(t) = t^3, vy(t) = 1: a curved track so smoothing changes the centre value.
145 bg("VecBg", 16, 16, "TopLeftRed = Input { Value = 0.0, Expression = \"time*time*time\", }, TopLeftGreen = Input { Value = 1.0, }, TopLeftAlpha = Input { Value = 1.0, },"),
146 bg("BackBg", 16, 16, "TopLeftRed = Input { Value = 0.0, Expression = \"time*time*time\", }, TopLeftAlpha = Input { Value = 1.0, },"),
147 aux_chain("Scene", "Base", &[("Vector", "VecBg"), ("BackVector", "BackBg")]),
148 node("Smooth", "Dimension.SmoothMotion", &sm(&[val("Radius", 1.0)])),
149 node("Half", "Dimension.SmoothMotion", &sm(&[val("Radius", 1.0), val("Strength", 0.5)])),
150 node("Wide", "SmoothMotion", &sm(&[val("Radius", 3.0), val("Smoothness", 3.0)])),
151 node("Zero", "Dimension.SmoothMotion", &sm(&[val("Radius", 0.0)])),
152 node("NoBlend", "Dimension.SmoothMotion", &sm(&[val("Radius", 1.0), val("Blend", 0.0)])),
153 node("Edge", "Dimension.SmoothMotion", &sm(&[val("Radius", 2.0)])),
154 node("NoAux", "Dimension.SmoothMotion", &[inp("Input", "Base")]),
155 ]
156 .concat();
157 let comp = mk_comp(&tools);
158 let read = |eng: &mut Engine, name: &str, t: f64| -> ([f32; 4], [f32; 4], CachedTexture) {
159 let (tex, _) = eval(eng, &comp, name, t);
160 let aux = tex.aux.clone().unwrap();
161 let f = aux_at(&aux_px(eng, aux.vector.as_ref().unwrap()), 16, 8, 8);
162 let b = aux_at(&aux_px(eng, aux.back_vector.as_ref().unwrap()), 16, 8, 8);
163 (f, b, tex)
164 };
165 let (f0, b0, _) = read(&mut eng, "Scene", 5.0);
166 assert!((f0[0] - 125.0).abs() < 0.2 && (b0[0] - 125.0).abs() < 0.2, "raw cubic track: {f0:?}");
167 // Gaussian taps 1, w, w with w = exp(-0.5): (64 w + 125 + 216 w) / (1 + 2w).
168 let w = (-0.5f32).exp();
169 let expect = (64.0 * w + 125.0 + 216.0 * w) / (1.0 + 2.0 * w);
170 let (f, b, tex) = read(&mut eng, "Smooth", 5.0);
171 assert!((f[0] - expect).abs() < 0.5 && (b[0] - expect).abs() < 0.5, "smoothed {f:?} / {b:?}, expected {expect}");
172 assert!((f[1] - 1.0).abs() < 0.01, "constant vy stays constant");
173 let c = px(&eng.readback_rgba_f32(&tex).unwrap(), 16, 8, 8);
174 assert!((c[0] - 0.1).abs() < 1e-4 && (c[2] - 0.3).abs() < 1e-4, "RGBA untouched");
175
176 let (fh, _, _) = read(&mut eng, "Half", 5.0);
177 assert!((fh[0] - (125.0 + expect) * 0.5).abs() < 0.5, "Strength=0.5 mixes raw and smoothed: {fh:?}");
178 let (fw, _, _) = read(&mut eng, "Wide", 5.0);
179 assert!(fw[0] > f[0], "wider window pulls harder toward the convex future: {} vs {}", fw[0], f[0]);
180 let (fz, _, _) = read(&mut eng, "Zero", 5.0);
181 assert!((fz[0] - 125.0).abs() < 0.2, "Radius 0 passes through");
182 let (fnb, _, _) = read(&mut eng, "NoBlend", 5.0);
183 assert!((fnb[0] - 125.0).abs() < 0.2, "Blend 0 passes through");
184 // At the start of the global range only in-range neighbours contribute (renormalised).
185 let (fe, _, _) = read(&mut eng, "Edge", 0.0);
186 let expect_edge = (0.0 + w * 1.0 + (-2.0f32 * 2.0 / 2.0).exp() * 8.0) / (1.0 + w + (-2.0f32).exp());
187 assert!((fe[0] - expect_edge).abs() < 0.2, "range-clamped window {fe:?}, expected {expect_edge}");
188 let (tex, _) = eval(&mut eng, &comp, "NoAux", 0.0);
189 assert!(tex.aux.is_none(), "nothing to smooth");
190}
191
192#[test]
193fn propagate_depth_warps_along_flow_and_refines() {
194 let Some(mut eng) = engine() else { return };
195 let pd = |extra: &[String]| {
196 let mut v = vec![inp("Input", "Scene"), inp("DepthInput", "DepthImg")];
197 v.extend_from_slice(extra);
198 v
199 };
200 let tools = [
201 solid("Base", 32, 32, [0.5, 0.5, 0.5, 1.0]),
202 // Pixel q in frame t matches q + (4, 0) in frame t-1.
203 vec_scene("Scene", "Base", [4.0, 0.0], "BackVector"),
204 vec_scene("SceneFwd", "Base", [4.0, 0.0], "Vector"),
205 grad("DepthImg", 32, 32, [-10.0, 0.0, 0.0, 1.0], [-2.0, 0.0, 0.0, 1.0], false),
206 rect_mask("RightHalf", [0.75, 0.5], [0.5, 1.0]),
207 node("Fwd", "PropagateDepth", &pd(&[val("ReferenceFrame", 3.0), val("Radius", 0.0)])),
208 node("Bwd", "PropagateDepth", &[inp("Input", "SceneFwd"), inp("DepthInput", "DepthImg"), val("ReferenceFrame", 5.0), val("Radius", 0.0)]),
209 node("Same", "PropagateDepth", &pd(&[val("Radius", 0.0)])),
210 node("Refined", "PropagateDepth", &pd(&[val("ReferenceFrame", 3.0)])),
211 node("Capped", "PropagateDepth", &pd(&[val("ReferenceFrame", 0.0), val("MaxFrames", 1.0), val("Radius", 0.0)])),
212 node("NoBlend", "PropagateDepth", &pd(&[val("ReferenceFrame", 3.0), val("Blend", 0.0)])),
213 node("NoDepth", "PropagateDepth", &[inp("Input", "Base")]),
214 node("Static", "PropagateDepth", &[inp("Input", "Base"), inp("DepthInput", "DepthImg"), val("ReferenceFrame", 2.0), val("Radius", 0.0)]),
215 z_scene("WithZ", 32, 32, [0.5, 0.5, 0.5, 1.0], -3.0, -3.0),
216 node("OwnZ", "PropagateDepth", &[inp("Input", "WithZ"), val("ReferenceFrame", 2.0), val("Radius", 0.0)]),
217 solid("BV4", 32, 32, [4.0, 0.0, 0.0, 1.0]),
218 aux_chain("SceneZ", "WithZ", &[("BackVector", "BV4")]),
219 node(
220 "Masked",
221 "PropagateDepth",
222 &[
223 inp("Input", "SceneZ"),
224 inp("DepthInput", "DepthImg"),
225 val("ReferenceFrame", 3.0),
226 val("Radius", 0.0),
227 inp("EffectMask", "RightHalf").replace("Output", "Mask"),
228 ],
229 ),
230 ]
231 .concat();
232 let comp = mk_comp(&tools);
233 let depth_ref = eval(&mut eng, &comp, "DepthImg", 0.0).1;
234 let z_of = |eng: &mut Engine, name: &str, t: f64| -> Vec<[f32; 4]> {
235 let (tex, _) = eval(eng, &comp, name, t);
236 aux_px(eng, tex.aux.as_ref().and_then(|a| a.z.as_ref()).unwrap_or_else(|| panic!("{name}: no aux.z")))
237 };
238
239 let fwd = z_of(&mut eng, "Fwd", 4.0);
240 for x in [2u32, 10, 20] {
241 let expected = px(&depth_ref, 32, x + 4, 16)[0];
242 assert!((aux_at(&fwd, 32, x, 16)[0] - expected).abs() < 1e-3, "x={x}: {} vs {expected}", aux_at(&fwd, 32, x, 16)[0]);
243 }
244 assert!(aux_at(&fwd, 32, 29, 16)[0] < -1.0e29, "gathered from beyond the frame -> empty depth");
245
246 // Backward propagation (reference in the future) follows `aux.vector` instead.
247 let bwd = z_of(&mut eng, "Bwd", 4.0);
248 assert!((aux_at(&bwd, 32, 10, 16)[0] - px(&depth_ref, 32, 14, 16)[0]).abs() < 1e-3);
249
250 let same = z_of(&mut eng, "Same", 4.0);
251 assert!((aux_at(&same, 32, 10, 16)[0] - px(&depth_ref, 32, 10, 16)[0]).abs() < 1e-3, "ReferenceFrame = current frame keeps the depth");
252
253 let refined = z_of(&mut eng, "Refined", 4.0);
254 assert!((aux_at(&refined, 32, 10, 16)[0] - px(&depth_ref, 32, 14, 16)[0]).abs() < 0.6, "bilateral refinement stays close on a smooth ramp");
255
256 let capped = z_of(&mut eng, "Capped", 4.0);
257 assert!((aux_at(&capped, 32, 10, 16)[0] - px(&depth_ref, 32, 14, 16)[0]).abs() < 1e-3, "MaxFrames=1 stops after one warp step (flow is constant)");
258
259 let (tex, p) = eval(&mut eng, &comp, "Fwd", 4.0);
260 assert!(tex.aux.as_ref().and_then(|a| a.back_vector.as_ref()).is_some(), "other aux channels preserved");
261 assert_eq!(px(&p, 32, 8, 8), [0.5, 0.5, 0.5, 1.0], "RGBA untouched");
262 assert!(eval(&mut eng, &comp, "NoBlend", 4.0).0.aux.as_ref().and_then(|a| a.z.as_ref()).is_none(), "Blend=0 returns the input");
263 assert!(eval(&mut eng, &comp, "NoDepth", 4.0).0.aux.is_none(), "no depth source -> pass through");
264
265 // Static content: flow is computed (zero) and depth is simply carried over.
266 let st = z_of(&mut eng, "Static", 4.0);
267 assert!((aux_at(&st, 32, 10, 16)[0] - px(&depth_ref, 32, 10, 16)[0]).abs() < 1e-3, "zero computed flow keeps depth in place");
268 let own = z_of(&mut eng, "OwnZ", 4.0);
269 assert!((aux_at(&own, 32, 5, 5)[0] - -3.0).abs() < 1e-3, "falls back to Input's aux.z at the reference frame");
270
271 let masked = z_of(&mut eng, "Masked", 4.0);
272 assert!((aux_at(&masked, 32, 20, 16)[0] - px(&depth_ref, 32, 24, 16)[0]).abs() < 1e-3, "masked half propagated");
273 assert!((aux_at(&masked, 32, 4, 16)[0] - -3.0).abs() < 1e-3, "unmasked half keeps Input's own depth");
274}
275
276#[test]
277fn repair_frame_and_tween_interpolate_neighbours() {
278 let Some(mut eng) = engine() else { return };
279 let tools = [
280 // Frame 5 is damaged (white); every other frame is time * 0.1 grey.
281 bg("Clip", 32, 32, "TopLeftRed = Input { Value = 0.0, Expression = \"iif(time == 5, 1.0, time * 0.1)\", }, TopLeftGreen = Input { Value = 0.0, Expression = \"iif(time == 5, 1.0, time * 0.1)\", }, TopLeftBlue = Input { Value = 0.0, Expression = \"iif(time == 5, 1.0, time * 0.1)\", }, TopLeftAlpha = Input { Value = 1.0, },"),
282 rect_mask("RightHalf", [0.75, 0.5], [0.5, 1.0]),
283 node("Repair", "Dimension.RepairFrame", &[inp("Input", "Clip")]),
284 node("RepairHalf", "Dimension.RepairFrame", &[inp("Input", "Clip"), val("Blend", 0.5)]),
285 node("RepairOff", "Dimension.RepairFrame", &[inp("Input", "Clip"), val("Blend", 0.0)]),
286 node("RepairMask", "Dimension.RepairFrame", &[inp("Input", "Clip"), inp("EffectMask", "RightHalf").replace("Output", "Mask")]),
287 node("RepairStart", "RepairFrame", &[inp("Input", "Clip")]),
288 solid("A", 32, 32, [0.2, 0.2, 0.2, 1.0]),
289 solid("B", 32, 32, [0.8, 0.8, 0.8, 1.0]),
290 node("Tween", "Dimension.Tween", &[inp("Input1", "A"), inp("Input2", "B"), val("Position", 0.25)]),
291 node("TweenEnd", "Dimension.Tween", &[inp("Input1", "A"), inp("Input2", "B"), val("Position", 1.0)]),
292 node("TweenBlendPos", "Dimension.Tween", &[inp("Input1", "A"), inp("Input2", "B"), val("Blend", 0.5)]),
293 node("TweenHalfBlend", "Dimension.Tween", &[inp("Input1", "A"), inp("Input2", "B"), val("Position", 1.0), val("Blend", 0.5)]),
294 node("TweenMask", "Dimension.Tween", &[inp("Input1", "A"), inp("Input2", "B"), val("Position", 1.0), inp("EffectMask", "RightHalf").replace("Output", "Mask")]),
295 node("TweenSolo", "Dimension.Tween", &[inp("Input1", "A")]),
296 ]
297 .concat();
298 let comp = mk_comp(&tools);
299 let c = |p: &[f32], x: u32| px(p, 32, x, 16);
300
301 let (_, damaged) = eval(&mut eng, &comp, "Clip", 5.0);
302 assert!(c(&damaged, 16)[0] > 0.99, "frame 5 is damaged");
303 let (_, rep) = eval(&mut eng, &comp, "Repair", 5.0);
304 assert!((c(&rep, 16)[0] - 0.5).abs() < 0.02, "midpoint of frames 4 (0.4) and 6 (0.6), got {:?}", c(&rep, 16));
305 let (_, half) = eval(&mut eng, &comp, "RepairHalf", 5.0);
306 assert!((c(&half, 16)[0] - 0.75).abs() < 0.02, "Blend=0.5 mixes damaged and repaired");
307 let (_, off) = eval(&mut eng, &comp, "RepairOff", 5.0);
308 assert!(c(&off, 16)[0] > 0.99, "Blend=0 keeps the damaged frame");
309 let (_, masked) = eval(&mut eng, &comp, "RepairMask", 5.0);
310 assert!(c(&masked, 4)[0] > 0.99 && (c(&masked, 28)[0] - 0.5).abs() < 0.02, "EffectMask selects the region to repair");
311 let (_, start) = eval(&mut eng, &comp, "RepairStart", 0.0);
312 assert!((c(&start, 16)[0] - 0.1).abs() < 0.02, "at the range start only the next frame (0.1) is held, got {:?}", c(&start, 16));
313
314 let (_, tw) = eval(&mut eng, &comp, "Tween", 0.0);
315 assert!((c(&tw, 16)[0] - 0.35).abs() < 0.02, "Position 0.25 between 0.2 and 0.8, got {:?}", c(&tw, 16));
316 let (_, end) = eval(&mut eng, &comp, "TweenEnd", 0.0);
317 assert!((c(&end, 16)[0] - 0.8).abs() < 1e-4, "Position 1 is Input2");
318 let (_, bp) = eval(&mut eng, &comp, "TweenBlendPos", 0.0);
319 assert!((c(&bp, 16)[0] - 0.5).abs() < 0.02, "Blend doubles as Position without a Position input");
320 let (_, hb) = eval(&mut eng, &comp, "TweenHalfBlend", 0.0);
321 assert!((c(&hb, 16)[0] - 0.5).abs() < 0.02, "Blend 0.5 mixes Input1 with the Position-1 tween");
322 let (_, tm) = eval(&mut eng, &comp, "TweenMask", 0.0);
323 assert!((c(&tm, 4)[0] - 0.2).abs() < 1e-3 && (c(&tm, 28)[0] - 0.8).abs() < 1e-3, "EffectMask limits the tween");
324 let (_, solo) = eval(&mut eng, &comp, "TweenSolo", 0.0);
325 assert!((c(&solo, 16)[0] - 0.2).abs() < 1e-4, "a missing input passes the other through");
326}
327
328#[test]
329fn uniform_slots_reset_between_frames() {
330 let Some(mut eng) = engine() else { return };
331 let tools = [
332 solid("Flat", 16, 16, [0.5, 0.5, 0.5, 1.0]),
333 node("S", "Shader", &[inp("Input", "Flat"), val("Elevation", 30.0)]),
334 ]
335 .concat();
336 let comp = mk_comp(&tools);
337 let (_, first) = eval(&mut eng, &comp, "S", 0.0);
338 eng.reset_uniform_cursors();
339 let (_, second) = eval(&mut eng, &comp, "S", 1.0);
340 assert_eq!(px(&first, 16, 8, 8), px(&second, 16, 8, 8));
341 assert_eq!(eng.deep_flow.get().unwrap().borrow().uniform_cursor, 0, "cursor reset after the frame");
342}
343
344#[test]
345fn temporal_tools_survive_feedback_cycles() {
346 let Some(mut eng) = engine() else { return };
347 let tools = [
348 solid("Base", 16, 16, [0.4, 0.4, 0.4, 1.0]),
349 node("Repair", "Dimension.RepairFrame", &[inp("Input", "Loop")]),
350 node("Loop", "Merge", &[inp("Background", "Base"), inp("Foreground", "Repair")]),
351 node("Smooth", "Dimension.SmoothMotion", &[inp("Input", "SLoop"), val("Radius", 2.0)]),
352 node("SLoop", "Merge", &[inp("Background", "Base"), inp("Foreground", "Smooth")]),
353 ]
354 .concat();
355 let comp = mk_comp(&tools);
356 for name in ["Repair", "Smooth"] {
357 let (tex, p) = eval(&mut eng, &comp, name, 5.0);
358 assert_eq!(tex.size, [16, 16], "{name} terminates with a frame-sized result");
359 assert!(p.iter().all(|v| v.is_finite()), "{name} output stays finite");
360 }
361}