1use super::*;
2
3fn mk_comp(tools: &str) -> Comp {
4 let src = format!(
5 "Composition {{ CurrentTime = 0, RenderRange = {{ 0, 10 }}, GlobalRange = {{ 0, 10 }}, Tools = ordered() {{ {tools} }} }}"
6 );
7 Comp::from_fusion_str(&src).expect("parse surface_fx test comp")
8}
9
10fn render_rgba(comp: &Comp, name: &str, time: f64) -> Option<([u32; 2], Vec<u8>)> {
11 let mut eng = Engine::new_headless().ok()?;
12 let (tex, _) = eng.evaluate(comp, comp.find_node(name).unwrap(), time);
13 Some((tex.size, eng.readback_rgba(&tex).unwrap()))
14}
15
16fn render_f32(comp: &Comp, name: &str, time: f64) -> Option<(CachedTexture, Vec<f32>)> {
17 let mut eng = Engine::new_headless().ok()?;
18 let (tex, _) = eng.evaluate(comp, comp.find_node(name).unwrap(), time);
19 let data = eng.readback_rgba_f32(&tex).unwrap();
20 Some((tex, data))
21}
22
23fn px8(buf: &[u8], w: u32, x: u32, y: u32) -> [u8; 4] {
24 let i = ((y * w + x) * 4) as usize;
25 buf[i..i + 4].try_into().unwrap()
26}
27
28fn pxf(buf: &[f32], w: u32, x: u32, y: u32) -> [f32; 4] {
29 let i = ((y * w + x) * 4) as usize;
30 buf[i..i + 4].try_into().unwrap()
31}
32
33#[test]
34fn distort_map_edges_lens_and_mask() {
35 let comp = mk_comp(
36 r#"
37 Grad = Background {
38 Inputs = {
39 Width = Input { Value = 64, }, Height = Input { Value = 32, }, Depth = Input { Value = 4, },
40 Type = Input { Value = FuID { "Horizontal" }, },
41 TopLeftRed = Input { Value = 0.0, }, TopLeftGreen = Input { Value = 0.0, }, TopLeftBlue = Input { Value = 0.0, }, TopLeftAlpha = Input { Value = 1.0, },
42 TopRightRed = Input { Value = 1.0, }, TopRightGreen = Input { Value = 1.0, }, TopRightBlue = Input { Value = 1.0, }, TopRightAlpha = Input { Value = 1.0, },
43 },
44 },
45 DMap = Background {
46 Inputs = {
47 Width = Input { Value = 64, }, Height = Input { Value = 32, }, Depth = Input { Value = 4, },
48 TopLeftRed = Input { Value = 1.0, }, TopLeftAlpha = Input { Value = 1.0, },
49 },
50 },
51 DistDef = Distort {
52 Inputs = {
53 Input = Input { SourceOp = "Grad", Source = "Output", },
54 Distort = Input { SourceOp = "DMap", Source = "Output", },
55 },
56 },
57 DistFlip = Distort {
58 Inputs = {
59 Input = Input { SourceOp = "Grad", Source = "Output", },
60 Distort = Input { SourceOp = "DMap", Source = "Output", },
61 FlipX = Input { Value = 1, },
62 XScale = Input { Value = 4.0, },
63 },
64 },
65 DistCanvas = Distort {
66 Inputs = {
67 Input = Input { SourceOp = "Grad", Source = "Output", },
68 Distort = Input { SourceOp = "DMap", Source = "Output", },
69 XScale = Input { Value = 4.0, },
70 Edges = Input { Value = 1, },
71 },
72 },
73 DistLens = Distort {
74 Inputs = {
75 Input = Input { SourceOp = "Grad", Source = "Output", },
76 Distortion = Input { Value = 0.4, },
77 },
78 },
79 MaskL = RectangleMask {
80 Inputs = {
81 MaskWidth = Input { Value = 64, }, MaskHeight = Input { Value = 32, },
82 Center = Input { Value = { 0.25, 0.5 }, }, Width = Input { Value = 0.5, }, Height = Input { Value = 1.0, },
83 },
84 },
85 DistMasked = Distort {
86 Inputs = {
87 Input = Input { SourceOp = "Grad", Source = "Output", },
88 Distort = Input { SourceOp = "DMap", Source = "Output", },
89 XScale = Input { Value = 4.0, },
90 EffectMask = Input { SourceOp = "MaskL", Source = "Mask", },
91 },
92 },
93 "#,
94 );
95 let Some((t_grad, b_grad)) = render_f32(&comp, "Grad", 0.0) else { return };
96 let (_, b_def) = render_f32(&comp, "DistDef", 0.0).unwrap();
97 let (_, b_flip) = render_f32(&comp, "DistFlip", 0.0).unwrap();
98 let (_, b_canv) = render_f32(&comp, "DistCanvas", 0.0).unwrap();
99 let (_, b_lens) = render_f32(&comp, "DistLens", 0.0).unwrap();
100 let (_, b_mask) = render_f32(&comp, "DistMasked", 0.0).unwrap();
101
102 let w = t_grad.size[0];
103 let g_mid = pxf(&b_grad, w, 32, 16)[0];
104 let d_mid = pxf(&b_def, w, 32, 16)[0];
105 let f_mid = pxf(&b_flip, w, 32, 16)[0];
106 assert!(d_mid < g_mid - 0.02, "default XBias=-1 Distort should pull left: {d_mid} vs {g_mid}");
107 assert!(f_mid > g_mid + 0.05, "FlipX Distort should push right: {f_mid} vs {g_mid}");
108 assert_eq!(pxf(&b_canv, w, 0, 16)[3], 0.0, "Edges=Canvas out-of-bounds must be transparent");
109 assert!((pxf(&b_lens, w, 12, 16)[0] - pxf(&b_grad, w, 12, 16)[0]).abs() > 0.01, "Lens fallback should warp");
110 assert!((pxf(&b_mask, w, 50, 16)[0] - pxf(&b_grad, w, 50, 16)[0]).abs() < 1e-4, "unmasked right half untouched");
111}
112
113#[test]
114fn create_bump_and_relief_map_modes() {
115 let comp = mk_comp(
116 r#"
117 Grad = Background {
118 Inputs = {
119 Width = Input { Value = 32, }, Height = Input { Value = 32, }, Depth = Input { Value = 4, },
120 Type = Input { Value = FuID { "Horizontal" }, },
121 TopLeftRed = Input { Value = 0.0, }, TopLeftGreen = Input { Value = 0.0, }, TopLeftBlue = Input { Value = 0.0, }, TopLeftAlpha = Input { Value = 1.0, },
122 TopRightRed = Input { Value = 1.0, }, TopRightGreen = Input { Value = 1.0, }, TopRightBlue = Input { Value = 1.0, }, TopRightAlpha = Input { Value = 1.0, },
123 },
124 },
125 Bump3 = CreateBumpMap {
126 Inputs = {
127 Input = Input { SourceOp = "Grad", Source = "Output", },
128 FilterSize = Input { Value = FuID { "3" }, },
129 },
130 },
131 Bump5Signed = CreateBumpMap {
132 Inputs = {
133 Input = Input { SourceOp = "Grad", Source = "Output", },
134 FilterSize = Input { Value = FuID { "5" }, },
135 Signed = Input { Value = 1, },
136 HeightScale = Input { Value = 2.0, },
137 },
138 },
139 Relief = CreateReliefMap {
140 Inputs = {
141 Input = Input { SourceOp = "Grad", Source = "Output", },
142 MapType = Input { Value = FuID { "Relief" }, },
143 },
144 },
145 ConeFlip = CreateReliefMap {
146 Inputs = {
147 Input = Input { SourceOp = "Grad", Source = "Output", },
148 MapType = Input { Value = FuID { "Cone" }, },
149 FlipDepth = Input { Value = 1, },
150 MinScanRadius = Input { Value = 6, },
151 },
152 },
153 Emboss = CreateReliefMap {
154 Inputs = {
155 Input = Input { SourceOp = "Grad", Source = "Output", },
156 Angle = Input { Value = 0.0, },
157 Elevation = Input { Value = 45.0, },
158 Ambient = Input { Value = 0.1, },
159 Diffuse = Input { Value = 0.9, },
160 Specular = Input { Value = 0.4, },
161 },
162 },
163 "#,
164 );
165 let Some((t_b3, b_b3)) = render_f32(&comp, "Bump3", 0.0) else { return };
166 let (_, b_b5s) = render_f32(&comp, "Bump5Signed", 0.0).unwrap();
167 let (_, b_rel) = render_f32(&comp, "Relief", 0.0).unwrap();
168 let (_, b_cone) = render_f32(&comp, "ConeFlip", 0.0).unwrap();
169 let (_, b_emb) = render_f32(&comp, "Emboss", 0.0).unwrap();
170
171 let n = pxf(&b_b3, t_b3.size[0], 16, 16);
172 assert!(n[0] < 0.49 && n[0] > 0.45, "nx*0.5+0.5 should be ~0.483: {:?}", n);
173 assert!((n[1] - 0.5).abs() < 1e-4, "ny*0.5+0.5 must be 0.5 on horizontal ramp: {:?}", n);
174 assert!(n[2] > 0.98, "nz*0.5+0.5 should be near 1.0: {:?}", n);
175
176 let ns = pxf(&b_b5s, t_b3.size[0], 16, 16);
177 assert!(ns[0] < 0.0 && ns[2] > 0.9, "Signed BumpMap must emit negative nx in float: {:?}", ns);
178
179 let r_left = pxf(&b_rel, 32, 2, 16);
180 let r_right = pxf(&b_rel, 32, 29, 16);
181 assert!(r_left[3] > 0.85 && r_right[3] < 0.15, "Relief alpha = 1 - height: left={:?}, right={:?}", r_left, r_right);
182
183 let c_right = pxf(&b_cone, 32, 29, 16);
184 assert!(c_right[3] > 0.85, "FlipDepth=1 alpha = height: {:?}", c_right);
185
186 let e_mid = pxf(&b_emb, 32, 20, 16);
187 assert!(e_mid[0] > 0.2 && e_mid[3] > 0.99, "Shaded emboss output valid: {:?}", e_mid);
188}
189
190#[test]
191fn custom_filter_normalize_floor_and_matrix_sizes() {
192 let comp = mk_comp(
193 r#"
194 Grad = Background {
195 Inputs = {
196 Width = Input { Value = 32, }, Height = Input { Value = 32, }, Depth = Input { Value = 4, },
197 Type = Input { Value = FuID { "Horizontal" }, },
198 TopLeftRed = Input { Value = 0.0, }, TopLeftGreen = Input { Value = 0.0, }, TopLeftBlue = Input { Value = 0.0, }, TopLeftAlpha = Input { Value = 1.0, },
199 TopRightRed = Input { Value = 1.0, }, TopRightGreen = Input { Value = 1.0, }, TopRightBlue = Input { Value = 1.0, }, TopRightAlpha = Input { Value = 1.0, },
200 },
201 },
202 CFNorm = CustomFilter {
203 Inputs = {
204 Input = Input { SourceOp = "Grad", Source = "Output", },
205 Normalize = Input { Value = 1.0, },
206 },
207 },
208 CFFloor = CustomFilter {
209 Inputs = {
210 Input = Input { SourceOp = "Grad", Source = "Output", },
211 FloorLevel = Input { Value = 0.25, },
212 },
213 },
214 CFCustom5 = CustomFilter {
215 Inputs = {
216 Input = Input { SourceOp = "Grad", Source = "Output", },
217 MatrixSize = Input { Value = 5, },
218 c12 = Input { Value = 2.0, },
219 Scale = Input { Value = 1.0, },
220 },
221 },
222 "#,
223 );
224 let Some((_, b_grad)) = render_f32(&comp, "Grad", 0.0) else { return };
225 let (_, b_norm) = render_f32(&comp, "CFNorm", 0.0).unwrap();
226 let (_, b_flr) = render_f32(&comp, "CFFloor", 0.0).unwrap();
227 let (_, b_c5) = render_f32(&comp, "CFCustom5", 0.0).unwrap();
228
229 let g = pxf(&b_grad, 32, 16, 16)[0];
230 let n = pxf(&b_norm, 32, 16, 16)[0];
231 assert!((n / g - 256.0).abs() < 1.0, "Normalize=1.0 should scale HDR output by 256x: {n} vs {g}");
232 let fl = pxf(&b_flr, 32, 16, 16)[0];
233 assert!((fl - (g + 0.25)).abs() < 1e-3, "FloorLevel=0.25 adds bias: {fl} vs {g}");
234 let c5 = pxf(&b_c5, 32, 16, 16)[0];
235 assert!((c5 - 2.0 * g).abs() < 1e-3, "Custom 5x5 delta*2 doubles value: {c5} vs {g}");
236}
237
238#[test]
239fn cineon_log_and_light_trim_film_curves() {
240 let comp = mk_comp(
241 r#"
242 LogBG = Background {
243 Inputs = {
244 Width = Input { Value = 16, }, Height = Input { Value = 16, }, Depth = Input { Value = 4, },
245 TopLeftRed = Input { Value = 0.092864125, },
246 TopLeftGreen = Input { Value = 0.434995112, },
247 TopLeftBlue = Input { Value = 0.669599218, },
248 TopLeftAlpha = Input { Value = 1.0, },
249 },
250 },
251 CLog2Lin = CineonLog {
252 Inputs = {
253 Input = Input { SourceOp = "LogBG", Source = "Output", },
254 Mode = Input { Value = 0, },
255 },
256 },
257 CLin2Log = CineonLog {
258 Inputs = {
259 Input = Input { SourceOp = "CLog2Lin", Source = "Output", },
260 Mode = Input { Value = 1, },
261 },
262 },
263 LogBright = Background {
264 Inputs = {
265 Width = Input { Value = 16, }, Height = Input { Value = 16, }, Depth = Input { Value = 4, },
266 TopLeftRed = Input { Value = 0.782013685, },
267 TopLeftGreen = Input { Value = 0.684261975, },
268 TopLeftBlue = Input { Value = 0.669599218, },
269 TopLeftAlpha = Input { Value = 1.0, },
270 },
271 },
272 CSoft = CineonLog {
273 Inputs = {
274 Input = Input { SourceOp = "LogBright", Source = "Output", },
275 Mode = Input { Value = 0, },
276 RedSoftClipKnee = Input { Value = 20, },
277 },
278 },
279 CHdr = CineonLog {
280 Inputs = {
281 Input = Input { SourceOp = "LogBright", Source = "Output", },
282 Mode = Input { Value = 0, },
283 },
284 },
285 LinSrc = Background {
286 Inputs = {
287 Width = Input { Value = 16, }, Height = Input { Value = 16, }, Depth = Input { Value = 4, },
288 TopLeftRed = Input { Value = 0.5, }, TopLeftGreen = Input { Value = 0.25, },
289 TopLeftBlue = Input { Value = 0.1, }, TopLeftAlpha = Input { Value = 1.0, },
290 },
291 },
292 LT = LightTrim {
293 Inputs = {
294 Input = Input { SourceOp = "LinSrc", Source = "Output", },
295 LockRGBA = Input { Value = 0, },
296 RedTrim = Input { Value = 2, },
297 GreenTrim = Input { Value = -2, },
298 BlueTrim = Input { Value = 0, },
299 AlphaTrim = Input { Value = 1, },
300 },
301 },
302 LTStops = LightTrim {
303 Inputs = {
304 Input = Input { SourceOp = "LinSrc", Source = "Output", },
305 Mode = Input { Value = FuID { "Stops" }, },
306 RedLight = Input { Value = 1.0, },
307 GreenLight = Input { Value = 1.0, },
308 BlueLight = Input { Value = 1.0, },
309 },
310 },
311 "#,
312 );
313 let Some((_, b_l2l)) = render_f32(&comp, "CLog2Lin", 0.0) else { return };
314 let (_, b_rt) = render_f32(&comp, "CLin2Log", 0.0).unwrap();
315 let (_, b_soft) = render_f32(&comp, "CSoft", 0.0).unwrap();
316 let (_, b_hdr) = render_f32(&comp, "CHdr", 0.0).unwrap();
317 let (_, b_lt) = render_f32(&comp, "LT", 0.0).unwrap();
318 let (_, b_lts) = render_f32(&comp, "LTStops", 0.0).unwrap();
319
320 let l = pxf(&b_l2l, 16, 8, 8);
321 assert!(l[0].abs() < 1e-4, "95/1023 -> 0.0: {}", l[0]);
322 assert!((l[1] - 0.1493).abs() < 2e-3, "445/1023 -> ~0.1493: {}", l[1]);
323 assert!((l[2] - 1.0).abs() < 1e-3, "685/1023 -> 1.0: {}", l[2]);
324
325 let rt = pxf(&b_rt, 16, 8, 8);
326 assert!((rt[0] - 95.0 / 1023.0).abs() < 1e-3 && (rt[2] - 685.0 / 1023.0).abs() < 1e-3, "LinToLog roundtrip: {:?}", rt);
327
328 let hdr = pxf(&b_hdr, 16, 8, 8);
329 let soft = pxf(&b_soft, 16, 8, 8);
330 assert!(hdr[0] > 2.0, "800/1023 without softclip preserves HDR > 2.0: {}", hdr[0]);
331 assert!(soft[0] < 1.0 && soft[0] > 0.85, "SoftClipKnee=20 compresses >white below 1.0: {}", soft[0]);
332
333 let lt = pxf(&b_lt, 16, 8, 8);
334 assert!((lt[0] - 0.524414).abs() < 1e-3, "RedTrim=2: {}", lt[0]);
335 assert!((lt[1] - 0.225586).abs() < 1e-3, "GreenTrim=-2: {}", lt[1]);
336 assert!((lt[3] - 1.012207).abs() < 1e-3, "AlphaTrim=1: {}", lt[3]);
337
338 let lts = pxf(&b_lts, 16, 8, 8);
339 assert!((lts[0] - 1.0).abs() < 1e-3 && (lts[1] - 0.5).abs() < 1e-3, "Stops=+1 doubles RGB: {:?}", lts);
340}
341
342#[test]
343fn multipoly_ranges_and_teapot_masks() {
344 let comp = mk_comp(
345 r#"
346 MP = MultiPoly {
347 Inputs = {
348 MaskWidth = Input { Value = 64, }, MaskHeight = Input { Value = 64, },
349 PolyOrder = Input { Value = ScriptVal { { [0] = 1, 2 } }, },
350 ["PolyMask1.PaintMode"] = Input { Value = FuID { "Merge" }, },
351 ["PolyMask1.Polyline"] = Input {
352 Value = Polyline {
353 Closed = true,
354 Points = {
355 { Linear = true, X = -0.35, Y = -0.35 },
356 { Linear = true, X = 0.35, Y = -0.35 },
357 { Linear = true, X = 0.35, Y = 0.35 },
358 { Linear = true, X = -0.35, Y = 0.35 },
359 },
360 },
361 },
362 ["PolyMask2.PaintMode"] = Input { Value = FuID { "Subtract" }, },
363 ["PolyMask2.Polyline"] = Input {
364 Value = Polyline {
365 Closed = true,
366 Points = {
367 { Linear = true, X = -0.15, Y = -0.15 },
368 { Linear = true, X = 0.15, Y = -0.15 },
369 { Linear = true, X = 0.15, Y = 0.15 },
370 { Linear = true, X = -0.15, Y = 0.15 },
371 },
372 },
373 },
374 },
375 },
376 Grad = Background {
377 Inputs = {
378 Width = Input { Value = 64, }, Height = Input { Value = 32, },
379 Type = Input { Value = FuID { "Horizontal" }, },
380 TopLeftRed = Input { Value = 0.0, }, TopLeftGreen = Input { Value = 0.0, }, TopLeftBlue = Input { Value = 0.0, }, TopLeftAlpha = Input { Value = 1.0, },
381 TopRightRed = Input { Value = 1.0, }, TopRightGreen = Input { Value = 1.0, }, TopRightBlue = Input { Value = 1.0, }, TopRightAlpha = Input { Value = 1.0, },
382 },
383 },
384 RngSh = RangesMask {
385 Inputs = {
386 Image = Input { SourceOp = "Grad", Source = "Output", },
387 RangesRange = Input { Value = 0, },
388 },
389 },
390 RngMid = RangesMask {
391 Inputs = {
392 Image = Input { SourceOp = "Grad", Source = "Output", },
393 RangesRange = Input { Value = 1, },
394 },
395 },
396 RngHi = RangesMask {
397 Inputs = {
398 Image = Input { SourceOp = "Grad", Source = "Output", },
399 RangesRange = Input { Value = 2, },
400 },
401 },
402 Tea = TeapotMask {
403 Inputs = {
404 MaskWidth = Input { Value = 64, }, MaskHeight = Input { Value = 64, },
405 },
406 },
407 TeaOutline = TeapotMask {
408 Inputs = {
409 MaskWidth = Input { Value = 64, }, MaskHeight = Input { Value = 64, },
410 Solid = Input { Value = 0, }, BorderWidth = Input { Value = 0.03, },
411 },
412 },
413 "#,
414 );
415 let Some((_, b_mp)) = render_rgba(&comp, "MP", 0.0) else { return };
416 let (_, b_sh) = render_rgba(&comp, "RngSh", 0.0).unwrap();
417 let (_, b_mid) = render_rgba(&comp, "RngMid", 0.0).unwrap();
418 let (_, b_hi) = render_rgba(&comp, "RngHi", 0.0).unwrap();
419 let (_, b_tea) = render_rgba(&comp, "Tea", 0.0).unwrap();
420 let (_, b_tout) = render_rgba(&comp, "TeaOutline", 0.0).unwrap();
421
422 // MultiPoly: center subtracted out, ring solid, corner empty
423 assert_eq!(px8(&b_mp, 64, 32, 32)[3], 0, "MultiPoly inner subtracted square must be 0");
424 assert_eq!(px8(&b_mp, 64, 16, 32)[3], 255, "MultiPoly outer ring must be 255");
425 assert_eq!(px8(&b_mp, 64, 2, 2)[3], 0, "MultiPoly outside corner must be 0");
426
427 // RangesMask: Shadows bright on left, Midtones bright in middle, Highlights bright on right
428 assert!(px8(&b_sh, 64, 4, 16)[3] > 200 && px8(&b_sh, 64, 60, 16)[3] < 20);
429 assert!(px8(&b_mid, 64, 32, 16)[3] > 140 && px8(&b_mid, 64, 2, 16)[3] < 30);
430 assert!(px8(&b_hi, 64, 60, 16)[3] > 200 && px8(&b_hi, 64, 4, 16)[3] < 20);
431
432 // TeapotMask: filled center, handle hole / corner empty, outline has fewer lit pixels
433 let tea_lit = b_tea.chunks_exact(4).filter(|p| p[3] > 127).count();
434 let tout_lit = b_tout.chunks_exact(4).filter(|p| p[3] > 127).count();
435 assert!(px8(&b_tea, 64, 32, 32)[3] > 200, "Teapot body center must be solid");
436 assert_eq!(px8(&b_tea, 64, 2, 2)[3], 0, "Teapot corner must be empty");
437 assert!(tout_lit > 50 && tout_lit < tea_lit, "Teapot outline should have fewer pixels than solid: {tout_lit} vs {tea_lit}");
438}
439
440#[test]
441fn tv_auto_domain_and_frame_average() {
442 let comp = mk_comp(
443 r#"
444 Grad = Background {
445 Inputs = {
446 Width = Input { Value = 64, }, Height = Input { Value = 64, }, Depth = Input { Value = 4, },
447 Type = Input { Value = FuID { "Horizontal" }, },
448 TopLeftRed = Input { Value = 0.0, }, TopLeftGreen = Input { Value = 0.0, }, TopLeftBlue = Input { Value = 0.0, }, TopLeftAlpha = Input { Value = 1.0, },
449 TopRightRed = Input { Value = 1.0, }, TopRightGreen = Input { Value = 1.0, }, TopRightBlue = Input { Value = 1.0, }, TopRightAlpha = Input { Value = 1.0, },
450 },
451 },
452 TVNode = TV {
453 Inputs = {
454 Input = Input { SourceOp = "Grad", Source = "Output", },
455 ScanLines = Input { Value = 1, },
456 Power = Input { Value = 0.0, },
457 Horizontal = Input { Value = 0.25, },
458 },
459 },
460 Rect = RectangleMask {
461 Inputs = {
462 MaskWidth = Input { Value = 64, }, MaskHeight = Input { Value = 64, },
463 Center = Input { Value = { 0.5, 0.5 }, }, Width = Input { Value = 0.25, }, Height = Input { Value = 0.25, },
464 },
465 },
466 Patch = Background {
467 Inputs = {
468 Width = Input { Value = 64, }, Height = Input { Value = 64, }, Depth = Input { Value = 4, },
469 TopLeftRed = Input { Value = 2.5, }, TopLeftAlpha = Input { Value = 1.0, },
470 EffectMask = Input { SourceOp = "Rect", Source = "Mask", },
471 },
472 },
473 AutoDom = AutoDomain {
474 Inputs = {
475 Input = Input { SourceOp = "Patch", Source = "Output", },
476 },
477 },
478 Anim = Background {
479 Inputs = {
480 Width = Input { Value = 16, }, Height = Input { Value = 16, }, Depth = Input { Value = 4, },
481 TopLeftRed = Input { SourceOp = "AnimRed", Source = "Value", },
482 TopLeftAlpha = Input { Value = 1.0, },
483 },
484 },
485 AnimRed = BezierSpline {
486 KeyFrames = {
487 [0] = { 0.0, RH = { 0.33, 0.1 } },
488 [1] = { 0.3, LH = { 0.67, 0.2 }, RH = { 1.33, 0.5 } },
489 [2] = { 0.9, LH = { 1.67, 0.7 } },
490 },
491 },
492 FABack = Fuse.FrameAverage {
493 Inputs = {
494 Input = Input { SourceOp = "Anim", Source = "Output", },
495 Frames = Input { Value = 1, },
496 SampleDirection = Input { Value = 0, },
497 },
498 },
499 FABoth = Fuse.FrameAverage {
500 Inputs = {
501 Input = Input { SourceOp = "Anim", Source = "Output", },
502 Frames = Input { Value = 1, },
503 SampleDirection = Input { Value = 1, },
504 },
505 },
506 AnimNonZero = Background {
507 Inputs = {
508 Width = Input { Value = 16, }, Height = Input { Value = 16, }, Depth = Input { Value = 4, },
509 TopLeftRed = Input { SourceOp = "AnimNzRed", Source = "Value", },
510 TopLeftAlpha = Input { Value = 1.0, },
511 },
512 },
513 AnimNzRed = BezierSpline {
514 KeyFrames = {
515 [0] = { 0.6, RH = { 0.33, 0.7 } },
516 [1] = { 0.9, LH = { 0.67, 0.8 } },
517 },
518 },
519 FAIgn = Fuse.FrameAverage {
520 Inputs = {
521 Input = Input { SourceOp = "AnimNonZero", Source = "Output", },
522 Frames = Input { Value = 1, },
523 SampleDirection = Input { Value = 0, },
524 MissingFrames = Input { Value = 0, },
525 },
526 },
527 FABlk = Fuse.FrameAverage {
528 Inputs = {
529 Input = Input { SourceOp = "AnimNonZero", Source = "Output", },
530 Frames = Input { Value = 1, },
531 SampleDirection = Input { Value = 0, },
532 MissingFrames = Input { Value = 1, },
533 },
534 },
535 "#,
536 );
537 let Some((_, b_tv)) = render_f32(&comp, "TVNode", 0.0) else { return };
538 assert_eq!(pxf(&b_tv, 64, 32, 0)[0], 0.0, "ScanLines=1 blanks even scanline");
539 assert!(pxf(&b_tv, 64, 32, 1)[0] > 0.2 && pxf(&b_tv, 64, 32, 1)[0] < 0.3, "Horizontal=0.25 shifts right: {:?}", pxf(&b_tv, 64, 32, 1));
540
541 // Inspect AutoDomain's tight internal DoD via eval_node before evaluate crops back to canvas_size
542 {
543 let mut eng = Engine::new_headless().unwrap();
544 let mut enc = eng.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("ad-test") });
545 let mut visiting = HashSet::new();
546 let mut stats = EvalStats::default();
547 let ad_id = comp.find_node("AutoDom").unwrap();
548 let ad_raw = eng.eval_node(&comp, ad_id, 0.0, &mut enc, &mut visiting, &mut stats);
549 eng.queue.submit(Some(enc.finish()));
550 eng.reset_uniform_cursors();
551 assert_eq!(ad_raw.canvas_size, [64, 64]);
552 assert_eq!(ad_raw.origin, [24, 24], "AutoDomain should compute tight origin (got {:?})", ad_raw.origin);
553 assert_eq!(ad_raw.size, [16, 16], "AutoDomain should compute tight size (got {:?})", ad_raw.size);
554 let ad_buf = eng.readback_rgba_f32(&ad_raw).unwrap();
555 assert!((pxf(&ad_buf, 16, 8, 8)[0] - 2.5).abs() < 1e-2, "AutoDomain preserves HDR float");
556 }
557 let (ad_tex, ad_full) = render_f32(&comp, "AutoDom", 0.0).unwrap();
558 assert_eq!(ad_tex.size, [64, 64]);
559 assert!((pxf(&ad_full, 64, 32, 32)[0] - 2.5).abs() < 1e-2, "AutoDomain output cropped cleanly to canvas");
560 assert_eq!(pxf(&ad_full, 64, 4, 4)[3], 0.0, "outside AutoDomain DoD remains transparent");
561
562 let (_, b_back) = render_f32(&comp, "FABack", 1.0).unwrap();
563 let (_, b_both) = render_f32(&comp, "FABoth", 1.0).unwrap();
564 assert!((pxf(&b_back, 16, 8, 8)[0] - 0.15).abs() < 1e-3, "Backward average (0.0+0.3)/2 = 0.15");
565 assert!((pxf(&b_both, 16, 8, 8)[0] - 0.40).abs() < 1e-3, "Both average (0.0+0.3+0.9)/3 = 0.40");
566
567 let (_, b_ign) = render_f32(&comp, "FAIgn", 0.0).unwrap();
568 let (_, b_blk) = render_f32(&comp, "FABlk", 0.0).unwrap();
569 assert!((pxf(&b_ign, 16, 8, 8)[0] - 0.60).abs() < 1e-3, "MissingFrames=Ignore keeps 0.60");
570 assert!((pxf(&b_blk, 16, 8, 8)[0] - 0.30).abs() < 1e-3, "MissingFrames=Black averages 0.60 with 0.0 = 0.30");
571}