authoravatarclover caruso<git@paperclover.net>2026-11-30 18:02:05-08:00
committeravatarclover caruso<git@paperclover.net>2026-11-30 18:09:38-08:00
loga952b35a7e933e8fb662f6357a4d35328c0f561d
treeff1a56c73843bcb40fb915e26189e8e7f3144890
parentdcec95395d6717e76dd897d10097b9735d5f9fb6
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

Fix Drip, Dent, DVE, and sBoolean Subtract/Xor parity (#31)


4 files changed, 404 insertions(+), 113 deletions(-)

crates/engine/src/eval/shapes_warp.rs+205-48
......@@ -92,6 +92,7 @@ enum ShapeTree {
9292 Group(Vec<ShapeTree>),
9393 Boolean {
9494 op: ShapeBoolOp,
95 color: [f32; 4],
9596 a: Box<ShapeTree>,
9697 b: Box<ShapeTree>,
9798 },
......@@ -145,9 +146,12 @@ impl ShapeTree {
145146 ch.hash_into(h);
146147 }
147148 }
148 ShapeTree::Boolean { op, a, b } => {
149 ShapeTree::Boolean { op, color, a, b } => {
149150 2u8.hash(h);
150151 (*op as u8).hash(h);
152 for c in color {
153 c.to_bits().hash(h);
154 }
151155 a.hash_into(h);
152156 b.hash_into(h);
153157 }
......@@ -332,6 +336,11 @@ fn collect_shape_tree(
332336 }
333337 "sBoolean" => {
334338 let op = parse_bool_op(comp, node, time, expr);
339 let r = comp.eval_number(node, "Red", time, 1.0, expr) as f32;
340 let g = comp.eval_number(node, "Green", time, 1.0, expr) as f32;
341 let b_col = comp.eval_number(node, "Blue", time, 1.0, expr) as f32;
342 let a_col = comp.eval_number(node, "Alpha", time, 1.0, expr) as f32;
343 let color = [r, g, b_col, a_col];
335344 let a = node
336345 .connected_node("Input1")
337346 .or_else(|| node.connected_node("Input"))
......@@ -348,6 +357,7 @@ fn collect_shape_tree(
348357 match (a, b) {
349358 (Some(ta), Some(tb)) => Some(ShapeTree::Boolean {
350359 op,
360 color,
351361 a: Box::new(ta),
352362 b: Box::new(tb),
353363 }),
......@@ -395,8 +405,7 @@ fn build_primitive_commands(kind: ShapePrimKind, xform: Affine2D, dims: [u32; 2]
395405 return cmds;
396406 }
397407 for k in 0..n {
398 let theta = std::f32::consts::FRAC_PI_2
399 + (k as f32) * std::f32::consts::TAU / (n as f32);
408 let theta = (k as f32) * std::f32::consts::TAU / (n as f32);
400409 let v = to_px([rx * theta.cos(), ry * theta.sin()]);
401410 if k == 0 {
402411 cmds.push(zeno::Command::MoveTo(v));
......@@ -566,13 +575,14 @@ fn rasterize_shape_tree_f32(
566575 rasterize_shape_tree_f32(ch, dims, dst, cov_buf, scratch);
567576 }
568577 }
569 ShapeTree::Boolean { op, a, b } => {
578 ShapeTree::Boolean { op, color, a, b } => {
570579 let len = dst.len();
571580 let mut buf_a = vec![0.0f32; len];
572581 let mut buf_b = vec![0.0f32; len];
573582 rasterize_shape_tree_f32(a, dims, &mut buf_a, cov_buf, scratch);
574583 rasterize_shape_tree_f32(b, dims, &mut buf_b, cov_buf, scratch);
575584 let mut comb = vec![0.0f32; len];
585 let ca = color[3].clamp(0.0, 1.0);
576586 for ((ca_p, cb_p), out_p) in buf_a
577587 .chunks_exact(4)
578588 .zip(buf_b.chunks_exact(4))
......@@ -580,48 +590,17 @@ fn rasterize_shape_tree_f32(
580590 {
581591 let aa = ca_p[3].clamp(0.0, 1.0);
582592 let ba = cb_p[3].clamp(0.0, 1.0);
583 let unpre_a = if aa > 1e-5 {
584 [ca_p[0] / aa, ca_p[1] / aa, ca_p[2] / aa]
585 } else {
586 [0.0; 3]
587 };
588 let unpre_b = if ba > 1e-5 {
589 [cb_p[0] / ba, cb_p[1] / ba, cb_p[2] / ba]
590 } else {
591 [0.0; 3]
593 let oa = match op {
594 ShapeBoolOp::Union => (aa + ba - aa * ba).clamp(0.0, 1.0),
595 ShapeBoolOp::Intersect => (aa * ba).clamp(0.0, 1.0),
596 ShapeBoolOp::Subtract => (aa * (1.0 - ba)).clamp(0.0, 1.0),
597 ShapeBoolOp::Xor => (aa * (1.0 - ba) + ba * (1.0 - aa)).clamp(0.0, 1.0),
592598 };
593 match op {
594 ShapeBoolOp::Union => {
595 let inv_b = 1.0 - ba;
596 out_p[0] = cb_p[0] + ca_p[0] * inv_b;
597 out_p[1] = cb_p[1] + ca_p[1] * inv_b;
598 out_p[2] = cb_p[2] + ca_p[2] * inv_b;
599 out_p[3] = (ba + aa * inv_b).clamp(0.0, 1.0);
600 }
601 ShapeBoolOp::Intersect => {
602 let oa = aa * ba;
603 out_p[0] = unpre_a[0] * oa;
604 out_p[1] = unpre_a[1] * oa;
605 out_p[2] = unpre_a[2] * oa;
606 out_p[3] = oa;
607 }
608 ShapeBoolOp::Subtract => {
609 let oa = aa * (1.0 - ba);
610 out_p[0] = unpre_a[0] * oa;
611 out_p[1] = unpre_a[1] * oa;
612 out_p[2] = unpre_a[2] * oa;
613 out_p[3] = oa;
614 }
615 ShapeBoolOp::Xor => {
616 let wa = aa * (1.0 - ba);
617 let wb = ba * (1.0 - aa);
618 let oa = (wa + wb).clamp(0.0, 1.0);
619 out_p[0] = unpre_a[0] * wa + unpre_b[0] * wb;
620 out_p[1] = unpre_a[1] * wa + unpre_b[1] * wb;
621 out_p[2] = unpre_a[2] * wa + unpre_b[2] * wb;
622 out_p[3] = oa;
623 }
624 }
599 let sa = oa * ca;
600 out_p[0] = color[0] * sa;
601 out_p[1] = color[1] * sa;
602 out_p[2] = color[2] * sa;
603 out_p[3] = sa;
625604 }
626605 composite_over(dst, &comb);
627606 }
......@@ -668,9 +647,8 @@ impl Engine {
668647 };
669648 let src = self.eval_node(comp, src_id, time, enc, visiting, stats);
670649 let blend = comp.eval_number(node, "Blend", time, 1.0, &self.expr) as f32;
671 let strength = comp.eval_number(node, "Strength", time, 1.0, &self.expr) as f32;
672650 let amp = comp.eval_number(node, "Amplitude", time, 0.1, &self.expr) as f32;
673 if blend <= 1e-6 || (strength * amp).abs() <= 1e-7 {
651 if blend <= 1e-6 || amp.abs() <= 1e-7 {
674652 return src;
675653 }
676654 let src = self.crop_to_canvas(enc, src);
......@@ -684,7 +662,7 @@ impl Engine {
684662 let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash);
685663
686664 let mut u = UniformParams::default();
687 u.p[0] = [center[0] as f32, center[1] as f32, strength, amp];
665 u.p[0] = [center[0] as f32, center[1] as f32, 0.0, amp];
688666 u.p[1] = [freq, aspect, phase, dampening];
689667 u.p[2] = [shape, blend, if mask.is_some() { 1.0 } else { 0.0 }, if mask_inv { 1.0 } else { 0.0 }];
690668
......@@ -1054,4 +1032,183 @@ mod tests {
10541032 // Top-left corner (0, 0) should be transparent
10551033 assert_eq!(&px[0..4], &[0, 0, 0, 0], "corner should be transparent");
10561034 }
1035
1036 #[test]
1037 fn test_drip_shapes_and_strength_independence() {
1038 let make_comp = |strength: f64, shape: i32| {
1039 format!(
1040 r#"Composition {{
1041 CurrentTime = 0,
1042 RenderRange = {{ 0, 1 }},
1043 GlobalRange = {{ 0, 1 }},
1044 Tools = ordered() {{
1045 BG1 = Background {{
1046 Inputs = {{
1047 Width = Input {{ Value = 128, }},
1048 Height = Input {{ Value = 128, }},
1049 Type = Input {{ Value = FuID {{ "Horizontal" }}, }},
1050 TopLeftRed = Input {{ Value = 1.0, }},
1051 TopRightBlue = Input {{ Value = 1.0, }},
1052 }},
1053 }},
1054 Drip1 = Drip {{
1055 Inputs = {{
1056 Input = Input {{ SourceOp = "BG1", Source = "Output", }},
1057 Center = Input {{ Value = {{ 0.4, 0.6 }}, }},
1058 Strength = Input {{ Value = {strength}, }},
1059 Amplitude = Input {{ Value = 0.08, }},
1060 Frequency = Input {{ Value = 4.0, }},
1061 Phase = Input {{ Value = 0.75, }},
1062 Shape = Input {{ Value = {shape}, }},
1063 }},
1064 }},
1065 }},
1066 }}"#
1067 )
1068 };
1069 let Ok(mut eng) = Engine::new_headless() else {
1070 return;
1071 };
1072 let comp_a = Comp::from_fusion_str(&make_comp(0.25, 1)).unwrap();
1073 let comp_b = Comp::from_fusion_str(&make_comp(1.0, 1)).unwrap();
1074 let (tex_a, _) = eng.evaluate(&comp_a, comp_a.find_node("Drip1").unwrap(), 0.0);
1075 let (tex_b, _) = eng.evaluate(&comp_b, comp_b.find_node("Drip1").unwrap(), 0.0);
1076 let px_a = eng.readback_rgba(&tex_a).unwrap();
1077 let px_b = eng.readback_rgba(&tex_b).unwrap();
1078 assert_eq!(px_a, px_b, "Fusion Drip ignores Strength and uses Amplitude directly");
1079
1080 // Center pixel (0.4*128=51, (1-0.6)*128=51) must remain smooth (raw_rel=0 -> disp=0)
1081 let (bg_tex, _) = eng.evaluate(&comp_a, comp_a.find_node("BG1").unwrap(), 0.0);
1082 let bg_px = eng.readback_rgba(&bg_tex).unwrap();
1083 let diff_sum: u64 = bg_px.iter().zip(px_a.iter()).map(|(&a, &b)| a.abs_diff(b) as u64).sum();
1084 assert!(diff_sum > 5_000, "Square Drip should displace pixels, got {diff_sum}");
1085 }
1086
1087 #[test]
1088 fn test_dent_type0_signed_inversion() {
1089 let src = r#"Composition {
1090 CurrentTime = 0,
1091 RenderRange = { 0, 1 },
1092 GlobalRange = { 0, 1 },
1093 Tools = ordered() {
1094 BG1 = Background {
1095 Inputs = {
1096 Width = Input { Value = 128, },
1097 Height = Input { Value = 128, },
1098 Type = Input { Value = FuID { "Horizontal" }, },
1099 TopLeftRed = Input { Value = 1.0, },
1100 TopLeftGreen = Input { Value = 0.0, },
1101 TopLeftBlue = Input { Value = 0.0, },
1102 TopRightRed = Input { Value = 0.0, },
1103 TopRightGreen = Input { Value = 1.0, },
1104 TopRightBlue = Input { Value = 0.0, },
1105 },
1106 },
1107 Dent1 = Dent {
1108 Inputs = {
1109 Input = Input { SourceOp = "BG1", Source = "Output", },
1110 Center = Input { Value = { 0.5, 0.5 }, },
1111 Size = Input { Value = 0.65, },
1112 Strength = Input { Value = 0.75, },
1113 Type = Input { Value = 0, },
1114 },
1115 },
1116 },
1117 }"#;
1118 let comp = Comp::from_fusion_str(src).unwrap();
1119 let Ok(mut eng) = Engine::new_headless() else {
1120 return;
1121 };
1122 let (tex, _) = eng.evaluate(&comp, comp.find_node("Dent1").unwrap(), 0.0);
1123 let px = eng.readback_rgba(&tex).unwrap();
1124 // Just right of center (x=72, r~0.066): new_r = r - 0.75*(0.325 - r) < 0,
1125 // so it samples the LEFT (red-dominant) side!
1126 let right_near = (64 * 128 + 72) * 4;
1127 assert!(
1128 px[right_near] > px[right_near + 1] + 40,
1129 "Dent Type=0 should invert radially near center: {:?}",
1130 &px[right_near..right_near + 4]
1131 );
1132 }
1133
1134 #[test]
1135 fn test_s_boolean_uses_own_color_and_subtract_xor() {
1136 let src = r#"Composition {
1137 CurrentTime = 0,
1138 RenderRange = { 0, 1 },
1139 GlobalRange = { 0, 1 },
1140 Tools = ordered() {
1141 NGon1 = sNGon {
1142 Inputs = {
1143 Sides = Input { Value = 5, },
1144 Width = Input { Value = 0.5, },
1145 Height = Input { Value = 0.5, },
1146 Red = Input { Value = 1.0, },
1147 Green = Input { Value = 0.0, },
1148 Blue = Input { Value = 0.0, },
1149 },
1150 },
1151 Rect1 = sRectangle {
1152 Inputs = {
1153 Width = Input { Value = 0.35, },
1154 Height = Input { Value = 0.35, },
1155 ["Translate.X"] = Input { Value = 0.18, },
1156 Red = Input { Value = 0.0, },
1157 Green = Input { Value = 1.0, },
1158 Blue = Input { Value = 0.0, },
1159 },
1160 },
1161 BoolSub = sBoolean {
1162 Inputs = {
1163 Operation = Input { Value = FuID { "Subtract" }, },
1164 Input1 = Input { SourceOp = "Rect1", Source = "Output", },
1165 Input2 = Input { SourceOp = "NGon1", Source = "Output", },
1166 },
1167 },
1168 BoolXor = sBoolean {
1169 Inputs = {
1170 Operation = Input { Value = FuID { "Xor" }, },
1171 Input1 = Input { SourceOp = "NGon1", Source = "Output", },
1172 Input2 = Input { SourceOp = "Rect1", Source = "Output", },
1173 },
1174 },
1175 RSub = sRender {
1176 Inputs = {
1177 Width = Input { Value = 128, },
1178 Height = Input { Value = 128, },
1179 Input = Input { SourceOp = "BoolSub", Source = "Output", },
1180 },
1181 },
1182 RXor = sRender {
1183 Inputs = {
1184 Width = Input { Value = 128, },
1185 Height = Input { Value = 128, },
1186 Input = Input { SourceOp = "BoolXor", Source = "Output", },
1187 },
1188 },
1189 },
1190 }"#;
1191 let comp = Comp::from_fusion_str(src).unwrap();
1192 let Ok(mut eng) = Engine::new_headless() else {
1193 return;
1194 };
1195 let (tex_sub, _) = eng.evaluate(&comp, comp.find_node("RSub").unwrap(), 0.0);
1196 let (tex_xor, _) = eng.evaluate(&comp, comp.find_node("RXor").unwrap(), 0.0);
1197 let px_sub = eng.readback_rgba(&tex_sub).unwrap();
1198 let px_xor = eng.readback_rgba(&tex_xor).unwrap();
1199
1200 // Far right of Rect (x=0.30 -> px=102, y=64): outside NGon (max x=0.25), inside Rect -> white!
1201 let rect_only = (64 * 128 + 102) * 4;
1202 assert_eq!(&px_sub[rect_only..rect_only + 4], &[255, 255, 255, 255]);
1203 assert_eq!(&px_xor[rect_only..rect_only + 4], &[255, 255, 255, 255]);
1204
1205 // Overlap region (x=0.10 -> px=77, y=64): subtracted/xored out -> transparent!
1206 let overlap = (64 * 128 + 77) * 4;
1207 assert_eq!(&px_sub[overlap..overlap + 4], &[0, 0, 0, 0]);
1208 assert_eq!(&px_xor[overlap..overlap + 4], &[0, 0, 0, 0]);
1209
1210 // Center (0,0 -> px=64, y=64): inside NGon, outside Rect (starts at 0.005) -> white in Xor!
1211 let ngon_only = (64 * 128 + 54) * 4;
1212 assert_eq!(&px_xor[ngon_only..ngon_only + 4], &[255, 255, 255, 255]);
1213 }
10571214}
crates/engine/src/eval/transform.rs+143-20
......@@ -867,6 +867,7 @@ impl Engine {
867867 if blend <= 1e-6 {
868868 return src;
869869 }
870 let src = self.crop_to_canvas(enc, src);
870871 let center = comp.eval_point(node, "Center", time, [0.5, 0.5], &self.expr);
871872 let pivot = comp.eval_point(node, "Pivot", time, [0.5, 0.5], &self.expr);
872873 let z_pivot = comp.eval_number(node, "ZPivot", time, 0.0, &self.expr);
......@@ -874,31 +875,48 @@ impl Engine {
874875 let rx = comp.eval_number(node, "XRotation", time, 0.0, &self.expr).to_radians();
875876 let ry = comp.eval_number(node, "YRotation", time, 0.0, &self.expr).to_radians();
876877 let rz = comp.eval_number(node, "ZRotation", time, 0.0, &self.expr).to_radians();
878 let rot_order = node.static_str("RotationOrder").unwrap_or("ZYX");
877879 let alpha_mode = comp.eval_number(node, "AlphaMode", time, 0.0, &self.expr).round() as i32;
878 let aspect = src.size[0] as f64 / src.size[1].max(1) as f64;
880 let aspect = src.canvas_size[0] as f64 / src.canvas_size[1].max(1) as f64;
879881
880 // Fusion DVE rotates card corners around Pivot in ZYX order (Rz -> Ry -> Rx), then adds Center offset before perspective
882 // Fusion DVE rotates card corners around Pivot (default ZYX: Rz -> Ry -> Rx),
883 // scales (Center - 0.5) by ZMove so 2D screen shift at the card plane stays exact,
884 // and projects from Pivot with perspective 1 / (ZMove + z + ZPivot).
881885 let (sx, cx) = rx.sin_cos();
882886 let (sy, cy) = ry.sin_cos();
883887 let (sz, cz) = rz.sin_cos();
884888 let project = |u_c: f64, v_c: f64| -> [f64; 2] {
885 let x0 = u_c - pivot[0];
886 let y0 = (v_c - pivot[1]) / aspect;
887 let z0 = -z_pivot;
888 // 1. Rz (+Z CCW)
889 let x1 = x0 * cz - y0 * sz;
890 let y1 = x0 * sz + y0 * cz;
891 // 2. Ry (+Y tilts right away +z)
892 let x2 = x1 * cy - z0 * sy;
893 let z2 = x1 * sy + z0 * cy;
894 // 3. Rx (+X tilts bottom away +z)
895 let y3 = y1 * cx + z2 * sx;
896 let z3 = -y1 * sx + z2 * cx;
897 let z_cam = (z_move + z3 + z_pivot).max(0.05);
889 let mut x = u_c - pivot[0];
890 let mut y = (v_c - pivot[1]) / aspect;
891 let mut z = -z_pivot;
892 for b in rot_order.bytes() {
893 match b {
894 b'X' | b'x' => {
895 let ny = y * cx + z * sx;
896 let nz = -y * sx + z * cx;
897 y = ny;
898 z = nz;
899 }
900 b'Y' | b'y' => {
901 let nx = x * cy - z * sy;
902 let nz = x * sy + z * cy;
903 x = nx;
904 z = nz;
905 }
906 b'Z' | b'z' => {
907 let nx = x * cz - y * sz;
908 let ny = x * sz + y * cz;
909 x = nx;
910 y = ny;
911 }
912 _ => {}
913 }
914 }
915 let z_cam = (z_move + z + z_pivot).max(0.05);
898916 let inv_z = 1.0 / z_cam;
899917 [
900 pivot[0] + (x2 + (center[0] - 0.5)) * inv_z,
901 pivot[1] + ((y3 + (center[1] - 0.5) / aspect) * aspect) * inv_z,
918 pivot[0] + (x + (center[0] - 0.5) * z_move) * inv_z,
919 pivot[1] + ((y + (center[1] - 0.5) / aspect * z_move) * aspect) * inv_z,
902920 ]
903921 };
904922 let bl = project(0.0, 0.0);
......@@ -906,7 +924,41 @@ impl Engine {
906924 let tr = project(1.0, 1.0);
907925 let tl = project(0.0, 1.0);
908926 let h_inv = Self::quad_inverse_homography(bl, br, tr, tl);
909 let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats);
927
928 // Expand DoD when projected card corners extend beyond canvas (so downstream Merge preserves edges)
929 let cw = src.canvas_size[0].max(1) as f64;
930 let ch = src.canvas_size[1].max(1) as f64;
931 let mut min_x = cw;
932 let mut max_x = 0.0_f64;
933 let mut min_y = ch;
934 let mut max_y = 0.0_f64;
935 for c in [bl, br, tr, tl] {
936 let px = c[0] * cw;
937 let py = (1.0 - c[1]) * ch;
938 min_x = min_x.min(px);
939 max_x = max_x.max(px);
940 min_y = min_y.min(py);
941 max_y = max_y.max(py);
942 }
943 let pad = 2_i32;
944 let max_pad = 1024_i32;
945 let x0 = if min_x < -0.25 { (min_x.floor() as i32 - pad).max(-max_pad) } else { 0 };
946 let y0 = if min_y < -0.25 { (min_y.floor() as i32 - pad).max(-max_pad) } else { 0 };
947 let x1 = if max_x > cw + 0.25 {
948 (max_x.ceil() as i32 + pad).min(src.canvas_size[0] as i32 + max_pad)
949 } else {
950 src.canvas_size[0] as i32
951 };
952 let y1 = if max_y > ch + 0.25 {
953 (max_y.ceil() as i32 + pad).min(src.canvas_size[1] as i32 + max_pad)
954 } else {
955 src.canvas_size[1] as i32
956 };
957 let dst_origin = [x0, y0];
958 let dst_size = [(x1 - x0).max(1) as u32, (y1 - y0).max(1) as u32];
959 let has_dst_dod = dst_origin != [0, 0] || dst_size != src.canvas_size;
960
961 let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.canvas_size), enc, visiting, stats);
910962 let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash);
911963
912964 let mut u = UniformParams::default();
......@@ -914,14 +966,22 @@ impl Engine {
914966 u.p[1] = [h_inv[4], h_inv[5], h_inv[6], h_inv[7]];
915967 u.p[2] = [h_inv[8], blend, if mask.is_some() { 1.0 } else { 0.0 }, if mask_inv { 1.0 } else { 0.0 }];
916968 u.p[3] = [if alpha_mode == 1 { 1.0 } else { 0.0 }, 0.0, 0.0, 0.0];
917 let key = self.make_key(node, "DVE", src.size, &[src.content_hash, mask_hash], bytemuck::cast_slice(&u.p[..4]));
969 if has_dst_dod {
970 u.p[4] = [
971 dst_origin[0] as f32,
972 dst_origin[1] as f32,
973 src.canvas_size[0] as f32,
974 src.canvas_size[1] as f32,
975 ];
976 }
977 let key = self.make_key(node, "DVE", dst_size, &[src.content_hash, mask_hash], bytemuck::cast_slice(&u.p[..5]));
918978 if let Some(hit) = self.cache.get(key, node.id, frame_i) {
919979 stats.cache_hits += 1;
920980 return hit;
921981 }
922982 stats.cache_misses += 1;
923983 stats.nodes_evaluated += 1;
924 let dst = self.alloc_tex_dod(src.size, src.origin, src.canvas_size, src.depth, key);
984 let dst = self.alloc_tex_dod(dst_size, dst_origin, src.canvas_size, src.depth, key);
925985 let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view);
926986 self.dispatch_op(enc, ShaderOp::Homography, &src.view, &self.dummy.view, mv, &dst, &u);
927987 self.cache.insert(key, dst.clone(), node.id, frame_i);
......@@ -1442,4 +1502,67 @@ mod tests {
14421502 "cropped FG Mirror phase should reflect across FG bounds x=4 (far={out_far_mirrored:?} bluer than near={out_near_left_fg:?})"
14431503 );
14441504 }
1505
1506 #[test]
1507 fn test_dve_pivot_center_zmove_and_dod_expansion() {
1508 // 64x48 foreground transformed by DVE (ZMove=0.75 zooms card larger than 64x48)
1509 // and merged over 128x128 black background must preserve pixels outside 64x48 via DoD!
1510 let src = r#"Composition {
1511 CurrentTime = 0,
1512 RenderRange = { 0, 1 },
1513 GlobalRange = { 0, 1 },
1514 Tools = ordered() {
1515 BG = Background {
1516 Inputs = {
1517 Width = Input { Value = 128, },
1518 Height = Input { Value = 128, },
1519 TopLeftAlpha = Input { Value = 1.0, },
1520 },
1521 },
1522 FG = Background {
1523 Inputs = {
1524 Width = Input { Value = 64, },
1525 Height = Input { Value = 48, },
1526 TopLeftRed = Input { Value = 1.0, },
1527 TopLeftGreen = Input { Value = 0.5, },
1528 TopLeftBlue = Input { Value = 0.0, },
1529 TopLeftAlpha = Input { Value = 1.0, },
1530 },
1531 },
1532 DVE1 = DVE {
1533 Inputs = {
1534 Input = Input { SourceOp = "FG", Source = "Output", },
1535 XRotation = Input { Value = 15.0, },
1536 YRotation = Input { Value = -25.0, },
1537 ZRotation = Input { Value = 10.0, },
1538 ZMove = Input { Value = 0.75, },
1539 Pivot = Input { Value = { 0.3, 0.6 }, },
1540 Center = Input { Value = { 0.45, 0.55 }, },
1541 },
1542 },
1543 Out = Merge {
1544 Inputs = {
1545 Background = Input { SourceOp = "BG", Source = "Output", },
1546 Foreground = Input { SourceOp = "DVE1", Source = "Output", },
1547 },
1548 },
1549 },
1550 }"#;
1551 let comp = Comp::from_fusion_str(src).unwrap();
1552 let Ok(mut eng) = Engine::new_headless() else {
1553 return;
1554 };
1555 let out_id = comp.find_node("Out").unwrap();
1556 let (out_tex, stats) = eng.evaluate(&comp, out_id, 0.0);
1557 assert!(stats.unsupported_nodes.is_empty());
1558 let px = eng.readback_rgba(&out_tex).unwrap();
1559 // Outside original 64x48 centered box (x in 32..96, y in 40..88) at x=110, y=64
1560 // must still show orange card due to ZMove=0.75 + YRotation=-25 DoD expansion!
1561 let expanded_right = (64 * 128 + 110) * 4;
1562 assert!(
1563 px[expanded_right] > 200 && px[expanded_right + 1] > 100,
1564 "expected expanded orange DVE region outside 64x48 at x=110, got {:?}",
1565 &px[expanded_right..expanded_right + 4]
1566 );
1567 }
14451568}
crates/engine/src/shaders/archive_fx.wgsl+36-42
......@@ -5,7 +5,7 @@
55// 1. Drip (concentric ripple warp)
66// p[0] = (center.x, center.y, strength, amplitude)
77// p[1] = (frequency, aspect, phase, dampening)
8// p[2] = (shape: 0=Circle, 1=Square, 2=Horizontal, 3=Vertical, blend, has_mask, mask_invert)
8// p[2] = (shape: 0=Circle, 1=Square, 2=Random, 3=Horizontal, 4=Vertical, blend, has_mask, mask_invert)
99@compute @workgroup_size(8, 8)
1010fn drip_op(@builtin(global_invocation_id) gid: vec3<u32>) {
1111 let dims = textureDimensions(dst_tex);
......@@ -15,7 +15,6 @@ fn drip_op(@builtin(global_invocation_id) gid: vec3<u32>) {
1515 let orig = textureLoad(src_a, vec2<i32>(gid.xy), 0);
1616
1717 let center = u.p[0].xy;
18 let strength = u.p[0].z;
1918 let amp = u.p[0].w;
2019 let freq = u.p[1].x;
2120 let drip_aspect = max(u.p[1].y, 1e-4);
......@@ -24,37 +23,35 @@ fn drip_op(@builtin(global_invocation_id) gid: vec3<u32>) {
2423 let shape = i32(u.p[2].x + 0.5);
2524 let blend = u.p[2].y;
2625
27 let rel = vec2<f32>(fu.x - center.x, (fu.y - center.y) / (canvas_aspect * drip_aspect));
28 var dist: f32 = 0.0;
29 var dir: vec2<f32> = vec2<f32>(0.0);
26 let raw_rel = fu - center;
27 let rel = vec2<f32>(raw_rel.x / drip_aspect, raw_rel.y / canvas_aspect);
3028
31 if (shape == 1) {
32 // Square ripples
33 dist = max(abs(rel.x), abs(rel.y));
34 let rl = length(rel);
35 dir = select(vec2<f32>(0.0), rel / rl, rl > 1e-5);
36 } else if (shape == 2) {
37 // Horizontal wave bands
38 dist = abs(rel.y);
39 dir = vec2<f32>(0.0, select(-1.0, 1.0, rel.y >= 0.0));
40 } else if (shape == 3) {
41 // Vertical wave bands
42 dist = abs(rel.x);
43 dir = vec2<f32>(select(-1.0, 1.0, rel.x >= 0.0), 0.0);
44 } else if (shape == 4) {
45 // Diamond / cross ripples
46 dist = abs(rel.x) + abs(rel.y);
47 let rl = length(rel);
48 dir = select(vec2<f32>(0.0), rel / rl, rl > 1e-5);
29 var src_fu = fu;
30 if (shape == 2) {
31 // Random jitter shape in Fusion Drip
32 let jx = (fg_hash(vec2<i32>(gid.xy), 13) - 0.5) * amp * 0.25;
33 let jy = (fg_hash(vec2<i32>(gid.xy), 29) - 0.5) * amp * 0.25;
34 src_fu = fu + vec2<f32>(jx, jy);
4935 } else {
50 // Circle ripples (shape == 0 and default)
51 dist = length(rel);
52 dir = select(vec2<f32>(0.0), rel / dist, dist > 1e-5);
53 }
36 var dist: f32 = 0.0;
37 if (shape == 1) {
38 // Square ripples
39 dist = max(abs(rel.x), abs(rel.y));
40 } else if (shape == 3) {
41 // Horizontal wave bands
42 dist = abs(rel.y);
43 } else if (shape == 4) {
44 // Vertical wave bands
45 dist = abs(rel.x);
46 } else {
47 // Circle ripples (shape == 0 and default), normalized to half-diagonal 1/sqrt(2)
48 dist = length(rel) * 0.70710678118;
49 }
5450
55 let falloff = exp(-dist * dampening * 2.0);
56 let disp = sin(dist * freq * 6.28318530718 + phase) * amp * strength * falloff;
57 let src_fu = fu - dir * disp * vec2<f32>(1.0, canvas_aspect);
51 let falloff = exp(-dist * dampening * 22.0);
52 let disp = sin((dist * freq - phase) * 6.28318530718) * amp * falloff;
53 src_fu = fu + raw_rel * disp;
54 }
5855 let warped = sample_edges(src_a, src_fu, 2);
5956
6057 let m = read_mask(gid.xy, dims, u.p[2].z, u.p[2].w) * blend;
......@@ -86,25 +83,22 @@ fn dent_op(@builtin(global_invocation_id) gid: vec3<u32>) {
8683 let t = clamp(r / radius, 0.0, 1.0);
8784 var new_r = r;
8885 if (dent_type == 0) {
89 // Dent: smooth quadratic bulge/indent
90 let w = (1.0 - t) * (1.0 - t);
91 new_r = r * max(0.0, 1.0 - strength * w);
86 // Dent: linear radial displacement (signed across center)
87 new_r = r - strength * (radius - r);
9288 } else if (dent_type == 1) {
93 // Sine: sinusoidal radial displacement
94 let w = sin(t * 3.14159265359);
95 new_r = r * max(0.0, 1.0 - strength * w);
89 // Type 1: pi-scaled linear radial displacement
90 new_r = r - 3.14159265359 * strength * (radius - r);
9691 } else if (dent_type == 2) {
9792 // Pinch: power-law radial pinch/expand
9893 let p = select(1.0 / max(1.0 - strength, 0.05), 1.0 + strength, strength >= 0.0);
9994 new_r = radius * pow(t, p);
10095 } else if (dent_type == 3) {
101 // Punch: spherical dome punch
102 let w = sqrt(max(0.0, 1.0 - t * t));
103 new_r = r * max(0.0, 1.0 - strength * w);
96 // Type 3: sqrt(3) * sqrt(t) * (1 - t) radial profile
97 new_r = r - strength * radius * 1.73205080757 * sqrt(t) * (1.0 - t);
10498 } else {
105 // Extended Fusion Dent modes (4..5): smooth quartic falloff
106 let w = (1.0 - t * t) * (1.0 - t * t);
107 new_r = r * max(0.0, 1.0 - strength * w);
99 // Type 4: (2 / pi) * cos^2(t * pi / 2) radial profile
100 let c = cos(t * 1.57079632679);
101 new_r = r - strength * radius * 0.63661977237 * c * c;
108102 }
109103 let scale = new_r / r;
110104 let src_fu = center + rel_w * scale * vec2<f32>(1.0, aspect);
crates/engine/src/shaders/transform.wgsl+20-3
......@@ -237,13 +237,26 @@ fn xf_chroma_op(@builtin(global_invocation_id) gid: vec3<u32>) {
237237// p[1] = (h11, h12, h20, h21)
238238// p[2] = (h22, blend, has_mask, mask_invert)
239239// p[3] = (ignore_alpha, 0, 0, 0)
240// p[4] = (dst_dod_ox, dst_dod_oy, canvas_w, canvas_h)
240241// ============================================================================
241242@compute @workgroup_size(8, 8)
242243fn homography_op(@builtin(global_invocation_id) gid: vec3<u32>) {
243244 let dims = textureDimensions(dst_tex);
244245 if (gid.x >= dims.x || gid.y >= dims.y) { return; }
245 let fu = pix_to_fu(gid.xy, dims);
246 let orig = textureLoad(src_a, vec2<i32>(gid.xy), 0);
246 let has_dod = u.p[4].z > 0.5 && u.p[4].w > 0.5;
247 let fu = select(
248 pix_to_fu(gid.xy, dims),
249 vec2<f32>(
250 (f32(gid.x) + 0.5 + u.p[4].x) / u.p[4].z,
251 1.0 - (f32(gid.y) + 0.5 + u.p[4].y) / u.p[4].w,
252 ),
253 has_dod,
254 );
255 let orig = select(
256 textureLoad(src_a, vec2<i32>(gid.xy), 0),
257 sample_edges(src_a, fu, 0),
258 has_dod,
259 );
247260
248261 let sx = u.p[0].x * fu.x + u.p[0].y * fu.y + u.p[0].z;
249262 let sy = u.p[0].w * fu.x + u.p[1].x * fu.y + u.p[1].y;
......@@ -259,7 +272,11 @@ fn homography_op(@builtin(global_invocation_id) gid: vec3<u32>) {
259272 }
260273 }
261274 }
262 let m = read_mask(gid.xy, dims, u.p[2].z, u.p[2].w) * u.p[2].y;
275 let m = select(
276 read_mask(gid.xy, dims, u.p[2].z, u.p[2].w),
277 read_mask_uv(fu_to_uv(fu), u.p[2].z, u.p[2].w),
278 has_dod,
279 ) * u.p[2].y;
263280 let out_col = mix(orig, warped, clamp(m, 0.0, 1.0));
264281 store_dst(vec2<i32>(gid.xy), out_col);
265282}