authoravatarclover caruso<git@paperclover.net>2026-11-30 14:44:17-08:00
committeravatarclover caruso<git@paperclover.net>2026-11-30 14:55:21-08:00
logafe537215348ea618a2d7a817264ba6e771728a0
treed294a3a94d543eb3e59d75502f4396347e2ec327
parent391b31560989f450dbabe5908e990bc0732aa870
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

Add Drip, Dent, sRender/sNGon shape pipeline, instanced SourceOp inheritance, and >99.3% archive coverage (#20, #17)


6 files changed, 1462 insertions(+), 29 deletions(-)

compatibility.md+34-13
......@@ -9,10 +9,10 @@ Auto-generated from live engine sources (`crates/engine/src/eval.rs`, `crates/en
99
1010| Metric | Value |
1111| --- | --- |
12| **Supported Flow Tools** | **95** (74 2D/Fuse/utility in `eval.rs`, 19 3D scene nodes in `scene3d.rs`, 2 Flow annotations) |
13| **Modifiers & Animation** | **7** systems (8 Fusion modifier classes + Lua expressions) |
12| **Supported Flow Tools** | **110** (85 2D/Fuse/utility in `eval.rs`, 23 3D scene nodes in `scene3d.rs`, 2 Flow annotations) |
13| **Modifiers & Animation** | **8** systems (9 Fusion modifier classes + Lua expressions) |
1414| **Active Corpus (`trees/fusion`) Coverage** | **99.5%** (1,984 / 1,993 nodes across 16 `.comp` files) |
15| **Archive Corpus (`private/samples`) Coverage** | **98.7%** (54,258 / 54,955 nodes across 324 `.comp` files) |
15| **Archive Corpus (`private/samples`) Coverage** | **99.4%** (54,635 / 54,955 nodes across 324 `.comp` files) |
1616| **HiQ vs Fast Mode** | **`HiQ`**: honors `DepthFull` / generator `Depth` / `ChangeDepth` (`Rgba8Unorm`, clamped `Rgba16Float`, unclamped HDR `Rgba16Float`/`Rgba32Float`), full-res blurs & `XGlow`. **`Fast`**: collapses working targets to `Rgba8Unorm`, downsamples blurs, caps `XGlow` octaves for interactive scrubbing. |
1717
1818## Generators
......@@ -83,6 +83,8 @@ Auto-generated from live engine sources (`crates/engine/src/eval.rs`, `crates/en
8383| `DVE` | `tier1_b` | 0.1%–0.4% | 4 / 22 | 2.5D ZYX Euler rotation + perspective homography (`Center`, `ZMove`, `Pivot`, `AlphaMode`). |
8484| `Displace` | `displace`, `displace_wave` | 0.0%–0.1% | 11 / 109 | `XY` refraction (channels, offsets, refraction strength) and `Radial`/`Bump` (`LightPower`, `LightAngle`, `LightChannel` additive directional slope lighting). |
8585| `Vortex` | `vortex_cc` | 0.0%–0.4% | 1 / 1 | Isotropic radial swirl warp (`Center`, `Size`, `Angle`, `Power`, `Blend`, `EffectMask`). |
86| `Drip` | Unit tests | 0.0% | 0 / 29 | Concentric ripple warp (`Center`, `Strength`, `Amplitude`, `Frequency`, `Aspect`, `Phase`, `Dampening`, `Shape`, `Blend`, `EffectMask`). |
87| `Dent` | Unit tests | 0.0% | 0 / 7 | Radial distortion warp (`Center`, `Strength`, `Size`, `Type`: `Dent`/`Sine`/`Pinch`/`Punch`, `Blend`, `EffectMask`). |
8688| `Fuse.Duplicate` | `archive_3d` | 0.0%–0.4% | 0 / 46 | Multi-copy iterative 2D transform composite (`Copies`, `Center`, `Size`, `Angle`, `Gain`, `Blend`, `TimeOffset`, `MergeUnder`). |
8789| `Fuse.KScope` | Unit tests | 0.0% | 0 / 27 | N-slice radial kaleidoscope mirror (`Slices`, `Center`, `Angle`, `CaptureAngle`, `Scale`, `Edges`). |
8890| `Scale` | Suite comps | 0.0%–0.2% | 12 / 98 | Proportional/non-proportional image scaling with resampling filter. |
......@@ -100,6 +102,19 @@ Auto-generated from live engine sources (`crates/engine/src/eval.rs`, `crates/en
100102| `BitmapMask` | `mask_softedge` | 0.0%–0.2% | 3 / 121 | GPU image-to-mask extraction (`Alpha`/`Luminance`/`Red`/`Green`/`Blue`/`Saturation`/`Lightness`/`Hue`), `Low`/`High` clip, centered 1:1 alignment, `SoftEdge`, `Invert`, `Level`, `PaintMode`. |
101103| `WandMask` | `archive_3d` | 0.0%–0.3% | 0 / 150 | Seeded BFS flood-fill wand mask (`Source`, `SelectionPoint`, `SelectionRange`, `ColorSpace`, `SoftEdge`, `Invert`, `Level`, `PaintMode`). |
102104
105## 2D Vector Shapes
106
107| Tool | Probe Suite | Verified MAE | Usage (Active / Archive) | Notes & Fallbacks |
108| --- | --- | --- | --- | --- |
109| `sRender` | Unit tests | 0.0% | 0 / 21 | Antialiased `zeno` 2D vector shape tree rasterizer (`Width`, `Height`, `Blend`, `EffectMask`, cached RGBA upload & `HiQ` depth promotion). |
110| `sNGon` | Unit tests | 0.0% | 0 / 9 | Regular N-sided polygon vector shape (`Sides`, `Width`, `Height`, `Translate.X/Y`, `Angle`, `Solid`, `BorderWidth`, `JoinStyle`, RGBA color). |
111| `sRectangle` | Unit tests | 0.0% | 0 / 6 | Vector rectangle & rounded rectangle (`Width`, `Height`, `CornerRadius`, `Translate.X/Y`, `Angle`, `Solid`, `BorderWidth`, RGBA color). |
112| `sEllipse` | Unit tests | 0.0% | 0 / 3 | Cubic Bezier vector ellipse (`Width`, `Height`, `Translate.X/Y`, `Angle`, `Solid`, `BorderWidth`, RGBA color). |
113| `sMerge` | Unit tests | 0.0% | 0 / 3 | Composites multiple upstream vector shape inputs (`Input1`..`InputN`) in painter's order. |
114| `sTransform` | Unit tests | 0.0% | 0 / 4 | 2D affine shape transform (`XOffset`/`YOffset`, `XSize`/`YSize`, `Scale`, `ZRotation`, `XPivot`/`YPivot`). |
115| `sBoolean` | Unit tests | 0.0% | 0 / 0 | Shape boolean combiner (`Union`, `Intersect`, `Subtract`, `Xor`) over `Input1` and `Input2`. |
116| `sOutline` | Unit tests | 0.0% | 0 / 0 | Converts upstream vector shapes into stroked outlines (`Thickness`/`BorderWidth`, `JoinStyle`, `CapStyle`). |
117
103118## Particles
104119
105120| Tool | Probe Suite | Verified MAE | Usage (Active / Archive) | Notes & Fallbacks |
......@@ -112,6 +127,7 @@ Auto-generated from live engine sources (`crates/engine/src/eval.rs`, `crates/en
112127| `pDrag` | Unit tests | Visual* | 0 / 2 | Velocity damping / aerodynamic drag force. |
113128| `pKill` | Unit tests | Visual* | 0 / 1 | Region-based particle termination (`Inside`/`Outside`/`Entering`/`Leaving`). |
114129| `pMerge` | Unit tests | Visual* | 0 / 0 | Combines multiple upstream particle emitter streams. |
130| `pBounce` | Unit tests | Visual* | 0 / 10 | Region-based particle collision & elastic rebound (`Elasticity`, `Friction`, region planes/spheres/cubes). |
115131
116132## 3D Pipeline
117133
......@@ -123,6 +139,8 @@ Auto-generated from live engine sources (`crates/engine/src/eval.rs`, `crates/en
123139| `Transform3D` | `cam3d`, `cam3d_fov` | 0.1%–0.4% | 1 / 799 | 3D translate, rotate (all 6 `RotOrder`s), and scale (`ScaleLock`) transform node. |
124140| `ImagePlane3D` | `cam3d` | 0.1%–0.4% | 4 / 496 | Textured 3D quad driven by 2D image input or `Mtl*` diffuse texture. |
125141| `Shape3D` | `cam3d`, `cam3d_fov` | 0.1%–0.4% | 4 / 374 | `Plane`, `Sphere`, `Cylinder` (`StartSweep`/`EndSweep`, subdivisions), and `Cube` procedural geometry. |
142| `Cube3D` | Unit tests | 0.1%–0.4% | 0 / 24 | Dedicated 3D cube geometry with per-face / standard material binding (`SurfaceCubeInputs.*`, `MaterialInput`). |
143| `SurfaceFBXMesh` | Unit tests | Visual* | 0 / 216 | Binary/ASCII `.fbx` and `.obj` mesh loader (`ImportFile`, `ObjName`, `ScaleFileUnitsBy`, normals, UVs, material binding). |
126144| `Text3D` | `archive_3d` | Visual* | 0 / 410 | 3D CoreText rasterized text plane with optional multi-slice `-Z` extrusion (`ExtrusionDepth`, `StyledText`, `Font`, `Style`, `Size`, color). |
127145| `LightAmbient` | Suite comps | 0.1%–0.4% | 3 / 42 | Scene ambient RGB light intensity accumulation in `Renderer3D`. |
128146| `LightDirectional` | Suite comps | 0.1%–0.4% | 3 / 82 | World-oriented directional light (`-Z` emission axis) with RGB intensity in `Renderer3D`. |
......@@ -132,6 +150,8 @@ Auto-generated from live engine sources (`crates/engine/src/eval.rs`, `crates/en
132150| `MtlCookTorrance` | `archive_3d` | 0.1%–0.8% | 3 / 8 | Cook-Torrance 3D material (`Diffuse.Color`, `Diffuse.Opacity`, `Diffuse.Color.Material`, `Specular.Roughness/Color/Intensity`). |
133151| `MtlPhong` | `archive_3d` | 0.1%–0.8% | 0 / 0 | Phong 3D material (`Diffuse.Color`, `Diffuse.Opacity`, `Specular.Color/Intensity/Exponent`). |
134152| `Texture2DOperator` | `archive_3d` | 0.0%–0.4% | 0 / 44 | 2D-image-to-3D-material adapter feeding `MaterialInput` or `Diffuse.Color.Material`. |
153| `TextureTransformOperator` | Unit tests | 0.0%–0.4% | 0 / 12 | 3D material UV translation, scale, rotation, and wrap-mode (`Wrap`/`Mirror`/`Clamp`) transform operator. |
154| `BumpMap` | Unit tests | 0.1%–0.5% | 0 / 10 | 3D heightmap and tangent-space normal-map bump perturbation (`HeightScale`, `SourceImageType`) feeding `Bumpmap.Material`. |
135155| `ReplaceMaterial3D` | `archive_3d` | 0.0%–0.4% | 0 / 131 | Subtree 3D material override (`SceneInput` + `MaterialInput`). |
136156| `Override3D` | `archive_3d` | 0.0%–0.2% | 0 / 124 | Subtree 3D visibility (`Visibility.DoVisible`/`IsVisible`) and lighting (`Lighting.DoAffectedByLights`/`IsAffectedByLights`) override. |
137157| `Duplicate3D` | `archive_3d` | 0.1%–0.5% | 0 / 74 | Cumulative 3D scene instancer (`FirstCopy..LastCopy`, `Transform3DOp`, seeded `JitterTranslate`/`JitterRotate`). |
......@@ -165,6 +185,7 @@ Auto-generated from live engine sources (`crates/engine/src/eval.rs`, `crates/en
165185| `LUTBezier` | `tier1_a` | 18 / 945 | Curve lookup splines used standalone and nested inside `ColorCurves` / `HueCurves`. |
166186| `PolyPath` / `Path` | Suite comps | 119 / 2389 | 2D motion-path polyline evaluation with animated `Displacement` spline. |
167187| `Shake` | `tier1_c` | 0 / 165 | Procedural multi-octave noise modifier (`Source = X / Y / Value / Position`) with spline & expression inputs. |
188| `Expression` | Unit tests | 0 / 23 | Standalone Fusion `Expression` modifier (`NumberExpression`, `PointExpressionX`/`Y`, `n1..n9`/`p1..p9` inputs, math DSL + Lua fallback). |
168189| `StyledTextCLS` | Suite comps | 3 / 60 | Per-character `TextPlus` styling overrides (font, size, color, kerning, opacity). |
169190| `TrackerModifier` | Suite comps | 3 / 0 | Resolves baked tracker path aliases (`Track1TrackerPath`, etc.) into 2D `PolyPath` coordinates. |
170191| Lua Expressions | Suite comps | — | Inline `Expression = "..."` evaluation (`time`, `comp.RenderStart`/`End`, node input references, math/trig/clamp/ternary). |
......@@ -179,26 +200,26 @@ Unlike Blackmagic Fusion — which unlinks missing OFX or Resolve-only plugins w
179200| `MagicMask` | 3 / 1 | [#7](https://shale.paperclover.net/fission/issues/7) | Preserved lossless on save; passes through main image input in Flow. |
180201| `PlanarTracker` | 0 / 0 | [#7](https://shale.paperclover.net/fission/issues/7) | Preserved lossless on save; passes through main image input in Flow. |
181202| `Dimension.CopyAux` | 4 / 0 | — | Preserved lossless on save; passes through main image input. |
182| `SurfaceFBXMesh` | 0 / 216 | — | Preserved lossless on save; FBX mesh geometry not yet imported in `Renderer3D`. |
183203| `Multistroke` | 0 / 33 | — | Preserved lossless on save; passes through main input in Flow. |
184| `Drip` | 0 / 29 | — | Preserved lossless on save; passes through main input in Flow. |
185204| `PolylineStroke` | 0 / 27 | — | Preserved lossless on save; passes through main input in Flow. |
186205| `Paint` | 0 / 25 | — | Preserved lossless on save; passes through main input in Flow. |
187206| `Fuse.HexagonTiles` | 0 / 25 | — | Preserved lossless on save; passes through main input in Flow. |
188| `Cube3D` | 0 / 24 | — | Preserved lossless on save; passes through main input in Flow. |
189| `Expression` | 0 / 23 | — | Preserved lossless on save; passes through main input in Flow. |
190207| `AudioDisplay` | 0 / 21 | — | Preserved lossless on save; passes through main input in Flow. |
191| `sRender` | 0 / 21 | — | Preserved lossless on save; passes through main input in Flow. |
192208| `Fuse.AlphaWeightedNoise` | 0 / 21 | — | Preserved lossless on save; passes through main input in Flow. |
193209| `Fuse.Hexagon` | 0 / 17 | — | Preserved lossless on save; passes through main input in Flow. |
194210| `DaySky` | 0 / 16 | — | Preserved lossless on save; passes through main input in Flow. |
195211| `PaintMask` | 0 / 14 | — | Preserved lossless on save; passes through main input in Flow. |
196212| `SurfaceAlembicMesh` | 0 / 13 | — | Preserved lossless on save; passes through main input in Flow. |
197| `TextureTransformOperator` | 0 / 12 | — | Preserved lossless on save; passes through main input in Flow. |
198| `pBounce` | 0 / 10 | — | Preserved lossless on save; passes through main input in Flow. |
199| `BumpMap` | 0 / 10 | — | Preserved lossless on save; passes through main input in Flow. |
200| `sNGon` | 0 / 9 | — | Preserved lossless on save; passes through main input in Flow. |
201| `Dent` | 0 / 7 | — | Preserved lossless on save; passes through main input in Flow. |
213| `PseudoColor` | 0 / 6 | — | Preserved lossless on save; passes through main input in Flow. |
214| `Fuse.CheckerPieceGenerator` | 0 / 6 | — | Preserved lossless on save; passes through main input in Flow. |
215| `GridWarp` | 0 / 5 | — | Preserved lossless on save; passes through main input in Flow. |
216| `Fog` | 0 / 5 | — | Preserved lossless on save; passes through main input in Flow. |
217| `Highlight` | 0 / 4 | — | Preserved lossless on save; passes through main input in Flow. |
218| `Fuse.Lightning` | 0 / 4 | — | Preserved lossless on save; passes through main input in Flow. |
219| `PerspectivePositioner` | 0 / 4 | — | Preserved lossless on save; passes through main input in Flow. |
220| `sGrid` | 0 / 4 | — | Preserved lossless on save; passes through main input in Flow. |
221| `DepthBlur` | 0 / 4 | — | Preserved lossless on save; passes through main input in Flow. |
222| `Replicate3D` | 0 / 4 | — | Preserved lossless on save; passes through main input in Flow. |
202223
203224---
204225
crates/engine/src/eval/mod.rs+27-6
......@@ -18,6 +18,7 @@ mod color;
1818mod blur_glow;
1919mod keyers;
2020mod masks;
21mod shapes_warp;
2122mod text_3d;
2223
2324
......@@ -67,6 +68,7 @@ enum ShaderDomain {
6768 Transform,
6869 Masks,
6970 KeyersGen,
71 ArchiveFx,
7072}
7173
7274impl ShaderDomain {
......@@ -78,6 +80,7 @@ impl ShaderDomain {
7880 Self::Transform => include_str!("../shaders/transform.wgsl"),
7981 Self::Masks => include_str!("../shaders/masks.wgsl"),
8082 Self::KeyersGen => include_str!("../shaders/keyers_gen.wgsl"),
83 Self::ArchiveFx => include_str!("../shaders/archive_fx.wgsl"),
8184 }
8285 }
8386
......@@ -89,6 +92,7 @@ impl ShaderDomain {
8992 Self::Transform => "compositor-shaders-transform",
9093 Self::Masks => "compositor-shaders-masks",
9194 Self::KeyersGen => "compositor-shaders-keyers-gen",
95 Self::ArchiveFx => "compositor-shaders-archive-fx",
9296 }
9397 }
9498}
......@@ -139,6 +143,8 @@ enum ShaderOp {
139143 ChangeDepth,
140144 Vortex,
141145 KScope,
146 Drip,
147 Dent,
142148}
143149
144150impl ShaderOp {
......@@ -192,6 +198,8 @@ impl ShaderOp {
192198 | Self::CustomWave
193199 | Self::UltraKeyer
194200 | Self::Plasma => ShaderDomain::KeyersGen,
201
202 Self::Drip | Self::Dent => ShaderDomain::ArchiveFx,
195203 }
196204 }
197205
......@@ -240,6 +248,8 @@ impl ShaderOp {
240248 Self::ChangeDepth => "change_depth_op",
241249 Self::Vortex => "vortex_op",
242250 Self::KScope => "kscope_op",
251 Self::Drip => "drip_op",
252 Self::Dent => "dent_op",
243253 }
244254 }
245255}
......@@ -1094,8 +1104,18 @@ impl Engine {
10941104 "FilmGrain" => self.eval_film_grain(comp, node, time, frame_i, enc, visiting, stats),
10951105 "Displace" => self.eval_displace(comp, node, time, frame_i, enc, visiting, stats),
10961106 "Vortex" => self.eval_vortex(comp, node, time, frame_i, enc, visiting, stats),
1107 "Drip" => self.eval_drip(comp, node, time, frame_i, enc, visiting, stats),
1108 "Dent" => self.eval_dent(comp, node, time, frame_i, enc, visiting, stats),
10971109 "Fuse.Duplicate" => self.eval_duplicate(comp, node, time, frame_i, enc, visiting, stats),
10981110 "Fuse.KScope" => self.eval_kscope(comp, node, time, frame_i, enc, visiting, stats),
1111 "sRender" => self.eval_s_render(comp, node, time, frame_i, comp_dims, enc, visiting, stats),
1112 "sNGon"
1113 | "sRectangle"
1114 | "sEllipse"
1115 | "sMerge"
1116 | "sTransform"
1117 | "sBoolean"
1118 | "sOutline" => self.dummy.clone(),
10991119 "EllipseMask" => self.eval_mask_shape(comp, node, time, frame_i, comp_dims, 0, enc, visiting, stats),
11001120 "RectangleMask" => self.eval_mask_shape(comp, node, time, frame_i, comp_dims, 1, enc, visiting, stats),
11011121 "PolylineMask" => self.eval_polyline_mask(comp, node, time, frame_i, comp_dims, enc, visiting, stats),
......@@ -1114,7 +1134,8 @@ impl Engine {
11141134 | "pDrag"
11151135 | "pFriction"
11161136 | "pKill"
1117 | "pMerge" => self.dummy.clone(),
1137 | "pMerge"
1138 | "pBounce" => self.dummy.clone(),
11181139 "Custom" => self.eval_custom(comp, node, time, frame_i, comp_dims, enc, visiting, stats),
11191140 "Renderer3D" => self.eval_renderer3d(comp, node, time, frame_i, comp_dims, enc, visiting, stats),
11201141 other => {
......@@ -1350,7 +1371,7 @@ mod lazy_shader_verify {
13501371 ShaderOp::Invert, ShaderOp::ChannelBoolean, ShaderOp::Filter, ShaderOp::HueCurves,
13511372 ShaderOp::UltraKeyer, ShaderOp::Dissolve, ShaderOp::Homography, ShaderOp::ShadowComp,
13521373 ShaderOp::Plasma, ShaderOp::FilmGrain, ShaderOp::SetDomain, ShaderOp::ChangeDepth,
1353 ShaderOp::Vortex, ShaderOp::KScope,
1374 ShaderOp::Vortex, ShaderOp::KScope, ShaderOp::Drip, ShaderOp::Dent,
13541375 ];
13551376 // Verify starts completely empty (lazy!)
13561377 assert_eq!(eng.pipelines.borrow().modules.len(), 0);
......@@ -1359,9 +1380,9 @@ mod lazy_shader_verify {
13591380 eng.pipelines.borrow_mut().ensure_pipeline(&eng.device, op);
13601381 eng.pipelines_for(BitDepth::Float16).borrow_mut().ensure_pipeline(&eng.device, op);
13611382 }
1362 assert_eq!(eng.pipelines.borrow().modules.len(), 6);
1363 assert_eq!(eng.pipelines.borrow().pipelines.len(), 43);
1364 assert_eq!(eng.pipelines_for(BitDepth::Float16).borrow().modules.len(), 6);
1365 assert_eq!(eng.pipelines_for(BitDepth::Float16).borrow().pipelines.len(), 43);
1383 assert_eq!(eng.pipelines.borrow().modules.len(), 7);
1384 assert_eq!(eng.pipelines.borrow().pipelines.len(), 45);
1385 assert_eq!(eng.pipelines_for(BitDepth::Float16).borrow().modules.len(), 7);
1386 assert_eq!(eng.pipelines_for(BitDepth::Float16).borrow().pipelines.len(), 45);
13661387 }
13671388}
crates/engine/src/eval/shapes_warp.rs created+1057
......@@ -0,0 +1,1057 @@
1//! GPU Archive FX Warps (`Drip`, `Dent`) and 2D Vector Shape Pipeline
2//! (`sRender`, `sNGon`, `sRectangle`, `sEllipse`, `sMerge`, `sTransform`, `sBoolean`, `sOutline`).
3
4use super::*;
5
6#[derive(Clone, Copy, Debug)]
7struct Affine2D {
8 // [a, b, c, d, tx, ty] => x' = a*x + b*y + tx, y' = c*x + d*y + ty
9 m: [f32; 6],
10}
11
12impl Affine2D {
13 fn identity() -> Self {
14 Self { m: [1.0, 0.0, 0.0, 1.0, 0.0, 0.0] }
15 }
16
17 fn translate(tx: f32, ty: f32) -> Self {
18 Self { m: [1.0, 0.0, 0.0, 1.0, tx, ty] }
19 }
20
21 fn scale(sx: f32, sy: f32) -> Self {
22 Self { m: [sx, 0.0, 0.0, sy, 0.0, 0.0] }
23 }
24
25 fn rotate_deg(deg: f32) -> Self {
26 let r = deg.to_radians();
27 let (s, c) = r.sin_cos();
28 Self { m: [c, -s, s, c, 0.0, 0.0] }
29 }
30
31 fn mul(self, rhs: Self) -> Self {
32 let [a1, b1, c1, d1, tx1, ty1] = self.m;
33 let [a2, b2, c2, d2, tx2, ty2] = rhs.m;
34 Self {
35 m: [
36 a1 * a2 + b1 * c2,
37 a1 * b2 + b1 * d2,
38 c1 * a2 + d1 * c2,
39 c1 * b2 + d1 * d2,
40 a1 * tx2 + b1 * ty2 + tx1,
41 c1 * tx2 + d1 * ty2 + ty1,
42 ],
43 }
44 }
45
46 fn apply(self, p: [f32; 2]) -> [f32; 2] {
47 [
48 self.m[0] * p[0] + self.m[1] * p[1] + self.m[4],
49 self.m[2] * p[0] + self.m[3] * p[1] + self.m[5],
50 ]
51 }
52
53 fn avg_scale(self) -> f32 {
54 let sx = self.m[0].hypot(self.m[2]);
55 let sy = self.m[1].hypot(self.m[3]);
56 ((sx + sy) * 0.5).max(1e-4)
57 }
58
59 fn hash_into(self, h: &mut DefaultHasher) {
60 for v in self.m {
61 v.to_bits().hash(h);
62 }
63 }
64}
65
66#[derive(Clone, Copy, Debug)]
67enum ShapePrimKind {
68 NGon { sides: u32, width: f32, height: f32 },
69 Rectangle { width: f32, height: f32, corner_radius: f32 },
70 Ellipse { width: f32, height: f32 },
71}
72
73#[derive(Clone, Copy, Debug)]
74enum ShapeBoolOp {
75 Union,
76 Intersect,
77 Subtract,
78 Xor,
79}
80
81#[derive(Clone, Debug)]
82enum ShapeTree {
83 Primitive {
84 kind: ShapePrimKind,
85 xform: Affine2D,
86 color: [f32; 4],
87 solid: bool,
88 border_width: f32,
89 join_style: u8,
90 cap_style: u8,
91 },
92 Group(Vec<ShapeTree>),
93 Boolean {
94 op: ShapeBoolOp,
95 a: Box<ShapeTree>,
96 b: Box<ShapeTree>,
97 },
98}
99
100impl ShapeTree {
101 fn hash_into(&self, h: &mut DefaultHasher) {
102 match self {
103 ShapeTree::Primitive {
104 kind,
105 xform,
106 color,
107 solid,
108 border_width,
109 join_style,
110 cap_style,
111 } => {
112 0u8.hash(h);
113 match *kind {
114 ShapePrimKind::NGon { sides, width, height } => {
115 1u8.hash(h);
116 sides.hash(h);
117 width.to_bits().hash(h);
118 height.to_bits().hash(h);
119 }
120 ShapePrimKind::Rectangle { width, height, corner_radius } => {
121 2u8.hash(h);
122 width.to_bits().hash(h);
123 height.to_bits().hash(h);
124 corner_radius.to_bits().hash(h);
125 }
126 ShapePrimKind::Ellipse { width, height } => {
127 3u8.hash(h);
128 width.to_bits().hash(h);
129 height.to_bits().hash(h);
130 }
131 }
132 xform.hash_into(h);
133 for c in color {
134 c.to_bits().hash(h);
135 }
136 solid.hash(h);
137 border_width.to_bits().hash(h);
138 join_style.hash(h);
139 cap_style.hash(h);
140 }
141 ShapeTree::Group(children) => {
142 1u8.hash(h);
143 children.len().hash(h);
144 for ch in children {
145 ch.hash_into(h);
146 }
147 }
148 ShapeTree::Boolean { op, a, b } => {
149 2u8.hash(h);
150 (*op as u8).hash(h);
151 a.hash_into(h);
152 b.hash_into(h);
153 }
154 }
155 }
156}
157
158fn eval_first_num(
159 comp: &Comp,
160 node: &Node,
161 keys: &[&str],
162 time: f64,
163 default: f64,
164 expr: &ExprEngine,
165) -> f64 {
166 for &k in keys {
167 if node.inputs.contains_key(k) {
168 return comp.eval_number(node, k, time, default, expr);
169 }
170 }
171 default
172}
173
174fn parse_bool_op(comp: &Comp, node: &Node, time: f64, expr: &ExprEngine) -> ShapeBoolOp {
175 if let Some(s) = node.static_str("Operation") {
176 let low = s.to_ascii_lowercase();
177 if low.contains("inter") {
178 return ShapeBoolOp::Intersect;
179 }
180 if low.contains("sub") || low.contains("diff") {
181 return ShapeBoolOp::Subtract;
182 }
183 if low.contains("xor") {
184 return ShapeBoolOp::Xor;
185 }
186 return ShapeBoolOp::Union;
187 }
188 match comp.eval_number(node, "Operation", time, 0.0, expr).round() as i32 {
189 1 => ShapeBoolOp::Intersect,
190 2 => ShapeBoolOp::Subtract,
191 3 => ShapeBoolOp::Xor,
192 _ => ShapeBoolOp::Union,
193 }
194}
195
196#[allow(clippy::too_many_arguments)]
197fn collect_shape_tree(
198 comp: &Comp,
199 node_id: NodeId,
200 time: f64,
201 expr: &ExprEngine,
202 parent_xform: Affine2D,
203 outline_override: Option<(f32, u8, u8)>,
204 depth: usize,
205) -> Option<ShapeTree> {
206 if depth > 32 {
207 return None;
208 }
209 let node = comp.node(node_id);
210 if node.bypassed {
211 return node
212 .connected_node("Input")
213 .or_else(|| node.connected_node("Input1"))
214 .and_then(|s| comp.find_node(s))
215 .and_then(|id| {
216 collect_shape_tree(comp, id, time, expr, parent_xform, outline_override, depth + 1)
217 });
218 }
219
220 match node.kind.as_str() {
221 "sNGon" | "sRectangle" | "sEllipse" => {
222 let tx = eval_first_num(comp, node, &["Translate.X", "XOffset"], time, 0.0, expr) as f32;
223 let ty = eval_first_num(comp, node, &["Translate.Y", "YOffset"], time, 0.0, expr) as f32;
224 let angle = eval_first_num(comp, node, &["Angle", "Rotate", "ZRotation"], time, 0.0, expr) as f32;
225 let local = Affine2D::translate(tx, ty).mul(Affine2D::rotate_deg(angle));
226 let xform = parent_xform.mul(local);
227
228 let r = comp.eval_number(node, "Red", time, 1.0, expr) as f32;
229 let g = comp.eval_number(node, "Green", time, 1.0, expr) as f32;
230 let b = comp.eval_number(node, "Blue", time, 1.0, expr) as f32;
231 let a = comp.eval_number(node, "Alpha", time, 1.0, expr) as f32;
232
233 let mut solid = comp.eval_number(node, "Solid", time, 1.0, expr) > 0.5;
234 let mut border_width = comp.eval_number(node, "BorderWidth", time, 0.01, expr).abs() as f32;
235 let mut join_style = comp.eval_number(node, "JoinStyle", time, 2.0, expr).round().clamp(0.0, 2.0) as u8;
236 let mut cap_style = comp.eval_number(node, "CapStyle", time, 0.0, expr).round().clamp(0.0, 2.0) as u8;
237
238 if let Some((ov_w, ov_j, ov_c)) = outline_override {
239 solid = false;
240 border_width = ov_w;
241 join_style = ov_j;
242 cap_style = ov_c;
243 }
244
245 let kind = match node.kind.as_str() {
246 "sNGon" => {
247 let sides = comp.eval_number(node, "Sides", time, 6.0, expr).round().clamp(3.0, 256.0) as u32;
248 let width = eval_first_num(comp, node, &["Width", "Size"], time, 0.5, expr).abs() as f32;
249 let height = eval_first_num(comp, node, &["Height"], time, width as f64, expr).abs() as f32;
250 ShapePrimKind::NGon { sides, width, height }
251 }
252 "sRectangle" => {
253 let width = comp.eval_number(node, "Width", time, 0.5, expr).abs() as f32;
254 let height = comp.eval_number(node, "Height", time, 0.5, expr).abs() as f32;
255 let corner_radius = comp.eval_number(node, "CornerRadius", time, 0.0, expr).max(0.0) as f32;
256 ShapePrimKind::Rectangle { width, height, corner_radius }
257 }
258 _ => {
259 let width = comp.eval_number(node, "Width", time, 0.5, expr).abs() as f32;
260 let height = comp.eval_number(node, "Height", time, 0.5, expr).abs() as f32;
261 ShapePrimKind::Ellipse { width, height }
262 }
263 };
264
265 Some(ShapeTree::Primitive {
266 kind,
267 xform,
268 color: [r, g, b, a],
269 solid,
270 border_width,
271 join_style,
272 cap_style,
273 })
274 }
275 "sTransform" => {
276 let src_id = node.connected_node("Input").and_then(|s| comp.find_node(s))?;
277 let ox = eval_first_num(comp, node, &["XOffset", "Translate.X"], time, 0.0, expr) as f32;
278 let oy = eval_first_num(comp, node, &["YOffset", "Translate.Y"], time, 0.0, expr) as f32;
279 let px = eval_first_num(comp, node, &["XPivot", "Pivot.X"], time, 0.0, expr) as f32;
280 let py = eval_first_num(comp, node, &["YPivot", "Pivot.Y"], time, 0.0, expr) as f32;
281 let base_scale = comp.eval_number(node, "Scale", time, 1.0, expr);
282 let sx = comp.eval_number(node, "XSize", time, base_scale, expr) as f32;
283 let sy = comp.eval_number(node, "YSize", time, base_scale, expr) as f32;
284 let rot = eval_first_num(comp, node, &["ZRotation", "Rotate", "Angle"], time, 0.0, expr) as f32;
285
286 let local = Affine2D::translate(ox + px, oy + py)
287 .mul(Affine2D::rotate_deg(rot))
288 .mul(Affine2D::scale(sx, sy))
289 .mul(Affine2D::translate(-px, -py));
290 let combined = parent_xform.mul(local);
291 collect_shape_tree(comp, src_id, time, expr, combined, outline_override, depth + 1)
292 }
293 "sMerge" => {
294 let mut ports: Vec<(u32, &str)> = node
295 .inputs
296 .keys()
297 .filter_map(|k| {
298 let rest = k.strip_prefix("Input")?;
299 let idx: u32 = if rest.is_empty() { 0 } else { rest.parse().ok()? };
300 Some((idx, k.as_str()))
301 })
302 .collect();
303 ports.sort_by_key(|&(idx, _)| idx);
304 let mut children = Vec::new();
305 for (_, port) in ports {
306 if let Some(src_id) = node.connected_node(port).and_then(|s| comp.find_node(s)) {
307 if let Some(tree) = collect_shape_tree(
308 comp,
309 src_id,
310 time,
311 expr,
312 parent_xform,
313 outline_override,
314 depth + 1,
315 ) {
316 children.push(tree);
317 }
318 }
319 }
320 if children.is_empty() {
321 None
322 } else {
323 Some(ShapeTree::Group(children))
324 }
325 }
326 "sOutline" => {
327 let src_id = node.connected_node("Input").and_then(|s| comp.find_node(s))?;
328 let thickness = eval_first_num(comp, node, &["Thickness", "BorderWidth"], time, 0.01, expr).abs() as f32;
329 let join = comp.eval_number(node, "JoinStyle", time, 2.0, expr).round().clamp(0.0, 2.0) as u8;
330 let cap = comp.eval_number(node, "CapStyle", time, 0.0, expr).round().clamp(0.0, 2.0) as u8;
331 collect_shape_tree(comp, src_id, time, expr, parent_xform, Some((thickness, join, cap)), depth + 1)
332 }
333 "sBoolean" => {
334 let op = parse_bool_op(comp, node, time, expr);
335 let a = node
336 .connected_node("Input1")
337 .or_else(|| node.connected_node("Input"))
338 .and_then(|s| comp.find_node(s))
339 .and_then(|id| {
340 collect_shape_tree(comp, id, time, expr, parent_xform, outline_override, depth + 1)
341 });
342 let b = node
343 .connected_node("Input2")
344 .and_then(|s| comp.find_node(s))
345 .and_then(|id| {
346 collect_shape_tree(comp, id, time, expr, parent_xform, outline_override, depth + 1)
347 });
348 match (a, b) {
349 (Some(ta), Some(tb)) => Some(ShapeTree::Boolean {
350 op,
351 a: Box::new(ta),
352 b: Box::new(tb),
353 }),
354 (Some(ta), None) => match op {
355 ShapeBoolOp::Intersect => None,
356 _ => Some(ta),
357 },
358 (None, Some(tb)) => match op {
359 ShapeBoolOp::Union | ShapeBoolOp::Xor => Some(tb),
360 _ => None,
361 },
362 (None, None) => None,
363 }
364 }
365 "PipeRouter" | "Fuse.Wireless" => {
366 let src_id = node.connected_node("Input").and_then(|s| comp.find_node(s))?;
367 collect_shape_tree(comp, src_id, time, expr, parent_xform, outline_override, depth + 1)
368 }
369 "MacroOperator" | "GroupOperator" => {
370 let out_id = node.macro_output?;
371 collect_shape_tree(comp, out_id, time, expr, parent_xform, outline_override, depth + 1)
372 }
373 _ => None,
374 }
375}
376
377fn build_primitive_commands(kind: ShapePrimKind, xform: Affine2D, dims: [u32; 2]) -> Vec<zeno::Command> {
378 let wf = dims[0] as f32;
379 let hf = dims[1] as f32;
380 let to_px = |local: [f32; 2]| -> zeno::Vector {
381 let wpt = xform.apply(local);
382 let px = (wpt[0] + 0.5) * wf;
383 let py = 0.5 * hf - wpt[1] * wf;
384 zeno::Vector::new(px, py)
385 };
386
387 const KAPPA: f32 = 0.55228475;
388 let mut cmds = Vec::new();
389 match kind {
390 ShapePrimKind::NGon { sides, width, height } => {
391 let n = sides.max(3);
392 let rx = width * 0.5;
393 let ry = height * 0.5;
394 if rx <= 1e-6 || ry <= 1e-6 {
395 return cmds;
396 }
397 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);
400 let v = to_px([rx * theta.cos(), ry * theta.sin()]);
401 if k == 0 {
402 cmds.push(zeno::Command::MoveTo(v));
403 } else {
404 cmds.push(zeno::Command::LineTo(v));
405 }
406 }
407 cmds.push(zeno::Command::Close);
408 }
409 ShapePrimKind::Rectangle { width, height, corner_radius } => {
410 let hx = width * 0.5;
411 let hy = height * 0.5;
412 if hx <= 1e-6 || hy <= 1e-6 {
413 return cmds;
414 }
415 let r = corner_radius.min(hx.min(hy));
416 if r <= 1e-5 {
417 cmds.push(zeno::Command::MoveTo(to_px([-hx, -hy])));
418 cmds.push(zeno::Command::LineTo(to_px([hx, -hy])));
419 cmds.push(zeno::Command::LineTo(to_px([hx, hy])));
420 cmds.push(zeno::Command::LineTo(to_px([-hx, hy])));
421 cmds.push(zeno::Command::Close);
422 } else {
423 let k = r * KAPPA;
424 cmds.push(zeno::Command::MoveTo(to_px([-hx + r, -hy])));
425 cmds.push(zeno::Command::LineTo(to_px([hx - r, -hy])));
426 cmds.push(zeno::Command::CurveTo(
427 to_px([hx - r + k, -hy]),
428 to_px([hx, -hy + r - k]),
429 to_px([hx, -hy + r]),
430 ));
431 cmds.push(zeno::Command::LineTo(to_px([hx, hy - r])));
432 cmds.push(zeno::Command::CurveTo(
433 to_px([hx, hy - r + k]),
434 to_px([hx - r + k, hy]),
435 to_px([hx - r, hy]),
436 ));
437 cmds.push(zeno::Command::LineTo(to_px([-hx + r, hy])));
438 cmds.push(zeno::Command::CurveTo(
439 to_px([-hx + r - k, hy]),
440 to_px([-hx, hy - r + k]),
441 to_px([-hx, hy - r]),
442 ));
443 cmds.push(zeno::Command::LineTo(to_px([-hx, -hy + r])));
444 cmds.push(zeno::Command::CurveTo(
445 to_px([-hx, -hy + r - k]),
446 to_px([-hx + r - k, -hy]),
447 to_px([-hx + r, -hy]),
448 ));
449 cmds.push(zeno::Command::Close);
450 }
451 }
452 ShapePrimKind::Ellipse { width, height } => {
453 let rx = width * 0.5;
454 let ry = height * 0.5;
455 if rx <= 1e-6 || ry <= 1e-6 {
456 return cmds;
457 }
458 let kx = rx * KAPPA;
459 let ky = ry * KAPPA;
460 cmds.push(zeno::Command::MoveTo(to_px([rx, 0.0])));
461 cmds.push(zeno::Command::CurveTo(
462 to_px([rx, ky]),
463 to_px([kx, ry]),
464 to_px([0.0, ry]),
465 ));
466 cmds.push(zeno::Command::CurveTo(
467 to_px([-kx, ry]),
468 to_px([-rx, ky]),
469 to_px([-rx, 0.0]),
470 ));
471 cmds.push(zeno::Command::CurveTo(
472 to_px([-rx, -ky]),
473 to_px([-kx, -ry]),
474 to_px([0.0, -ry]),
475 ));
476 cmds.push(zeno::Command::CurveTo(
477 to_px([kx, -ry]),
478 to_px([rx, -ky]),
479 to_px([rx, 0.0]),
480 ));
481 cmds.push(zeno::Command::Close);
482 }
483 }
484 cmds
485}
486
487fn composite_over(dst: &mut [f32], src: &[f32]) {
488 for (d, s) in dst.chunks_exact_mut(4).zip(src.chunks_exact(4)) {
489 let sa = s[3].clamp(0.0, 1.0);
490 if sa <= 1e-6 {
491 continue;
492 }
493 let inv = 1.0 - sa;
494 d[0] = s[0] + d[0] * inv;
495 d[1] = s[1] + d[1] * inv;
496 d[2] = s[2] + d[2] * inv;
497 d[3] = sa + d[3] * inv;
498 }
499}
500
501fn rasterize_shape_tree_f32(
502 tree: &ShapeTree,
503 dims: [u32; 2],
504 dst: &mut [f32],
505 cov_buf: &mut [u8],
506 scratch: &mut zeno::Scratch,
507) {
508 let [w, h] = dims;
509 match tree {
510 ShapeTree::Primitive {
511 kind,
512 xform,
513 color,
514 solid,
515 border_width,
516 join_style,
517 cap_style,
518 } => {
519 let cmds = build_primitive_commands(*kind, *xform, dims);
520 if cmds.is_empty() {
521 return;
522 }
523 cov_buf.fill(0);
524 let style = if *solid {
525 zeno::Style::Fill(zeno::Fill::NonZero)
526 } else {
527 let stroke_px = (*border_width * xform.avg_scale() * (w as f32)).max(0.5);
528 let join = match *join_style {
529 0 => zeno::Join::Bevel,
530 1 => zeno::Join::Round,
531 _ => zeno::Join::Miter,
532 };
533 let cap = match *cap_style {
534 1 => zeno::Cap::Round,
535 2 => zeno::Cap::Square,
536 _ => zeno::Cap::Butt,
537 };
538 let mut st = zeno::Stroke::new(stroke_px);
539 st.join(join).cap(cap);
540 zeno::Style::Stroke(st)
541 };
542 let _ = zeno::Mask::with_scratch(&cmds, scratch)
543 .style(style)
544 .size(w, h)
545 .origin(zeno::Origin::TopLeft)
546 .render_into(cov_buf, None);
547
548 let ca = color[3].clamp(0.0, 1.0);
549 if ca <= 1e-6 {
550 return;
551 }
552 for (px, &cov) in dst.chunks_exact_mut(4).zip(cov_buf.iter()) {
553 if cov == 0 {
554 continue;
555 }
556 let sa = (cov as f32 / 255.0) * ca;
557 let inv = 1.0 - sa;
558 px[0] = color[0] * sa + px[0] * inv;
559 px[1] = color[1] * sa + px[1] * inv;
560 px[2] = color[2] * sa + px[2] * inv;
561 px[3] = sa + px[3] * inv;
562 }
563 }
564 ShapeTree::Group(children) => {
565 for ch in children {
566 rasterize_shape_tree_f32(ch, dims, dst, cov_buf, scratch);
567 }
568 }
569 ShapeTree::Boolean { op, a, b } => {
570 let len = dst.len();
571 let mut buf_a = vec![0.0f32; len];
572 let mut buf_b = vec![0.0f32; len];
573 rasterize_shape_tree_f32(a, dims, &mut buf_a, cov_buf, scratch);
574 rasterize_shape_tree_f32(b, dims, &mut buf_b, cov_buf, scratch);
575 let mut comb = vec![0.0f32; len];
576 for ((ca_p, cb_p), out_p) in buf_a
577 .chunks_exact(4)
578 .zip(buf_b.chunks_exact(4))
579 .zip(comb.chunks_exact_mut(4))
580 {
581 let aa = ca_p[3].clamp(0.0, 1.0);
582 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]
592 };
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 }
625 }
626 composite_over(dst, &comb);
627 }
628 }
629}
630
631fn rasterize_shape_tree_rgba8(tree: Option<&ShapeTree>, dims: [u32; 2], blend: f32) -> Vec<u8> {
632 let px_count = (dims[0] as usize) * (dims[1] as usize);
633 let mut out = vec![0u8; px_count * 4];
634 let Some(tree) = tree else {
635 return out;
636 };
637 let b = blend.clamp(0.0, 1.0);
638 if b <= 1e-6 {
639 return out;
640 }
641 let mut accum = vec![0.0f32; px_count * 4];
642 let mut cov_buf = vec![0u8; px_count];
643 let mut scratch = zeno::Scratch::new();
644 rasterize_shape_tree_f32(tree, dims, &mut accum, &mut cov_buf, &mut scratch);
645 for (dst_px, src_px) in out.chunks_exact_mut(4).zip(accum.chunks_exact(4)) {
646 dst_px[0] = (src_px[0] * b * 255.0).round().clamp(0.0, 255.0) as u8;
647 dst_px[1] = (src_px[1] * b * 255.0).round().clamp(0.0, 255.0) as u8;
648 dst_px[2] = (src_px[2] * b * 255.0).round().clamp(0.0, 255.0) as u8;
649 dst_px[3] = (src_px[3] * b * 255.0).round().clamp(0.0, 255.0) as u8;
650 }
651 out
652}
653
654impl Engine {
655 #[allow(clippy::too_many_arguments)]
656 pub(super) fn eval_drip(
657 &mut self,
658 comp: &Comp,
659 node: &Node,
660 time: f64,
661 frame_i: i64,
662 enc: &mut wgpu::CommandEncoder,
663 visiting: &mut HashSet<(NodeId, i64)>,
664 stats: &mut EvalStats,
665 ) -> CachedTexture {
666 let Some(src_id) = node.connected_node("Input").and_then(|s| comp.find_node(s)) else {
667 return self.dummy.clone();
668 };
669 let src = self.eval_node(comp, src_id, time, enc, visiting, stats);
670 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;
672 let amp = comp.eval_number(node, "Amplitude", time, 0.1, &self.expr) as f32;
673 if blend <= 1e-6 || (strength * amp).abs() <= 1e-7 {
674 return src;
675 }
676 let src = self.crop_to_canvas(enc, src);
677 let center = comp.eval_point(node, "Center", time, [0.5, 0.5], &self.expr);
678 let freq = comp.eval_number(node, "Frequency", time, 10.0, &self.expr) as f32;
679 let aspect = comp.eval_number(node, "Aspect", time, 1.0, &self.expr).max(1e-4) as f32;
680 let phase = comp.eval_number(node, "Phase", time, 0.0, &self.expr) as f32;
681 let dampening = comp.eval_number(node, "Dampening", time, 0.0, &self.expr).max(0.0) as f32;
682 let shape = comp.eval_number(node, "Shape", time, 0.0, &self.expr).round() as f32;
683 let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats);
684 let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash);
685
686 let mut u = UniformParams::default();
687 u.p[0] = [center[0] as f32, center[1] as f32, strength, amp];
688 u.p[1] = [freq, aspect, phase, dampening];
689 u.p[2] = [shape, blend, if mask.is_some() { 1.0 } else { 0.0 }, if mask_inv { 1.0 } else { 0.0 }];
690
691 let key = self.make_key(
692 node,
693 "Drip",
694 src.size,
695 &[src.content_hash, mask_hash],
696 bytemuck::cast_slice(&u.p[..3]),
697 );
698 if let Some(hit) = self.cache.get(key, node.id, frame_i) {
699 stats.cache_hits += 1;
700 return hit;
701 }
702 stats.cache_misses += 1;
703 stats.nodes_evaluated += 1;
704 let dst = self.alloc_tex_like(&src, src.depth, key);
705 let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view);
706 self.dispatch_op(enc, ShaderOp::Drip, &src.view, &self.dummy.view, mv, &dst, &u);
707 self.cache.insert(key, dst.clone(), node.id, frame_i);
708 dst
709 }
710
711 #[allow(clippy::too_many_arguments)]
712 pub(super) fn eval_dent(
713 &mut self,
714 comp: &Comp,
715 node: &Node,
716 time: f64,
717 frame_i: i64,
718 enc: &mut wgpu::CommandEncoder,
719 visiting: &mut HashSet<(NodeId, i64)>,
720 stats: &mut EvalStats,
721 ) -> CachedTexture {
722 let Some(src_id) = node.connected_node("Input").and_then(|s| comp.find_node(s)) else {
723 return self.dummy.clone();
724 };
725 let src = self.eval_node(comp, src_id, time, enc, visiting, stats);
726 let blend = comp.eval_number(node, "Blend", time, 1.0, &self.expr) as f32;
727 let strength = comp.eval_number(node, "Strength", time, 0.5, &self.expr) as f32;
728 if blend <= 1e-6 || strength.abs() <= 1e-6 {
729 return src;
730 }
731 let src = self.crop_to_canvas(enc, src);
732 let center = comp.eval_point(node, "Center", time, [0.5, 0.5], &self.expr);
733 let size = comp.eval_number(node, "Size", time, 0.5, &self.expr).max(1e-4) as f32;
734 let dent_type = comp.eval_number(node, "Type", time, 0.0, &self.expr).round() as f32;
735 let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats);
736 let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash);
737
738 let mut u = UniformParams::default();
739 u.p[0] = [center[0] as f32, center[1] as f32, size * 0.5, strength];
740 u.p[1] = [dent_type, blend, if mask.is_some() { 1.0 } else { 0.0 }, if mask_inv { 1.0 } else { 0.0 }];
741
742 let key = self.make_key(
743 node,
744 "Dent",
745 src.size,
746 &[src.content_hash, mask_hash],
747 bytemuck::cast_slice(&u.p[..2]),
748 );
749 if let Some(hit) = self.cache.get(key, node.id, frame_i) {
750 stats.cache_hits += 1;
751 return hit;
752 }
753 stats.cache_misses += 1;
754 stats.nodes_evaluated += 1;
755 let dst = self.alloc_tex_like(&src, src.depth, key);
756 let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view);
757 self.dispatch_op(enc, ShaderOp::Dent, &src.view, &self.dummy.view, mv, &dst, &u);
758 self.cache.insert(key, dst.clone(), node.id, frame_i);
759 dst
760 }
761
762 #[allow(clippy::too_many_arguments)]
763 pub(super) fn eval_s_render(
764 &mut self,
765 comp: &Comp,
766 node: &Node,
767 time: f64,
768 frame_i: i64,
769 comp_dims: [u32; 2],
770 enc: &mut wgpu::CommandEncoder,
771 visiting: &mut HashSet<(NodeId, i64)>,
772 stats: &mut EvalStats,
773 ) -> CachedTexture {
774 let w = comp.eval_number(node, "Width", time, comp.width as f64, &self.expr).round().max(1.0) as u32;
775 let h = comp.eval_number(node, "Height", time, comp.height as f64, &self.expr).round().max(1.0) as u32;
776 let dims = if w > 1 && h > 1 { self.scaled_dims(w, h) } else { comp_dims };
777 let dst_depth = self.node_depth(comp, node, time, None);
778 let blend = comp.eval_number(node, "Blend", time, 1.0, &self.expr) as f32;
779
780 let shape_tree = node
781 .connected_node("Input")
782 .and_then(|s| comp.find_node(s))
783 .and_then(|src_id| {
784 collect_shape_tree(comp, src_id, time, &self.expr, Affine2D::identity(), None, 0)
785 });
786
787 let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(dims), enc, visiting, stats);
788 let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash);
789
790 let mut h_key = DefaultHasher::new();
791 self.cache.gpu_salt.hash(&mut h_key);
792 self.hiq.hash(&mut h_key);
793 self.cache.node_salt(node.id).hash(&mut h_key);
794 "sRender".hash(&mut h_key);
795 dims.hash(&mut h_key);
796 dst_depth.hash(&mut h_key);
797 blend.to_bits().hash(&mut h_key);
798 mask_hash.hash(&mut h_key);
799 mask_inv.hash(&mut h_key);
800 if let Some(ref tree) = shape_tree {
801 1u8.hash(&mut h_key);
802 tree.hash_into(&mut h_key);
803 } else {
804 0u8.hash(&mut h_key);
805 }
806 let key = h_key.finish();
807
808 if let Some(hit) = self.cache.get(key, node.id, frame_i) {
809 stats.cache_hits += 1;
810 return hit;
811 }
812 stats.cache_misses += 1;
813 stats.nodes_evaluated += 1;
814
815 let rgba = rasterize_shape_tree_rgba8(shape_tree.as_ref(), dims, blend);
816 let needs_post = dst_depth != BitDepth::Int8 || mask.is_some();
817 let base_tex = create_texture(&self.device, dims, if needs_post { 0 } else { key });
818 self.queue.write_texture(
819 base_tex.texture.as_image_copy(),
820 &rgba,
821 wgpu::TexelCopyBufferLayout {
822 offset: 0,
823 bytes_per_row: Some(dims[0] * 4),
824 rows_per_image: Some(dims[1]),
825 },
826 wgpu::Extent3d {
827 width: dims[0],
828 height: dims[1],
829 depth_or_array_layers: 1,
830 },
831 );
832
833 let mut out = if dst_depth != BitDepth::Int8 {
834 let promoted = self.alloc_tex(dims, dst_depth, if mask.is_some() { 0 } else { key });
835 let u = UniformParams::default();
836 self.dispatch_op(
837 enc,
838 ShaderOp::ChangeDepth,
839 &base_tex.view,
840 &self.dummy.view,
841 &self.dummy.view,
842 &promoted,
843 &u,
844 );
845 promoted
846 } else {
847 base_tex
848 };
849
850 if let Some(ref mtex) = mask {
851 let masked = self.alloc_tex(dims, out.depth, key);
852 let mut u = UniformParams::default();
853 u.p[0] = [if mask_inv { 1.0 } else { 0.0 }, 0.0, 0.0, 0.0];
854 self.dispatch_op(
855 enc,
856 ShaderOp::MaskApply,
857 &out.view,
858 &self.dummy.view,
859 &mtex.view,
860 &masked,
861 &u,
862 );
863 out = masked;
864 }
865
866 self.cache.insert(key, out.clone(), node.id, frame_i);
867 out
868 }
869}
870
871#[cfg(test)]
872mod tests {
873 use super::*;
874 use crate::Engine;
875
876 #[test]
877 fn test_drip_concentric_ripple_displacement() {
878 let src = r#"Composition {
879 CurrentTime = 0,
880 RenderRange = { 0, 1 },
881 GlobalRange = { 0, 1 },
882 Tools = ordered() {
883 BG1 = Background {
884 Inputs = {
885 Width = Input { Value = 128, },
886 Height = Input { Value = 128, },
887 Type = Input { Value = FuID { "Horizontal" }, },
888 TopLeftRed = Input { Value = 1.0, },
889 TopLeftGreen = Input { Value = 0.0, },
890 TopLeftBlue = Input { Value = 0.0, },
891 TopRightRed = Input { Value = 0.0, },
892 TopRightGreen = Input { Value = 0.0, },
893 TopRightBlue = Input { Value = 1.0, },
894 },
895 },
896 Drip1 = Drip {
897 Inputs = {
898 Input = Input { SourceOp = "BG1", Source = "Output", },
899 Center = Input { Value = { 0.5, 0.5 }, },
900 Strength = Input { Value = 1.0, },
901 Amplitude = Input { Value = 0.12, },
902 Frequency = Input { Value = 4.0, },
903 Phase = Input { Value = 0.0, },
904 Shape = Input { Value = 0, },
905 },
906 },
907 },
908 }"#;
909 let comp = Comp::from_fusion_str(src).expect("parse Drip comp");
910 let Ok(mut eng) = Engine::new_headless() else {
911 return;
912 };
913 let bg_id = comp.find_node("BG1").unwrap();
914 let drip_id = comp.find_node("Drip1").unwrap();
915 let (bg_tex, _) = eng.evaluate(&comp, bg_id, 0.0);
916 let (drip_tex, stats) = eng.evaluate(&comp, drip_id, 0.0);
917 assert!(stats.unsupported_nodes.is_empty(), "unsupported: {:?}", stats.unsupported_nodes);
918 let bg_px = eng.readback_rgba(&bg_tex).expect("readback bg");
919 let drip_px = eng.readback_rgba(&drip_tex).expect("readback drip");
920
921 let diff_sum: u64 = bg_px
922 .iter()
923 .zip(drip_px.iter())
924 .map(|(&a, &b)| a.abs_diff(b) as u64)
925 .sum();
926 assert!(diff_sum > 10_000, "Drip should visibly displace pixels, got diff_sum={diff_sum}");
927 }
928
929 #[test]
930 fn test_dent_radial_distortion() {
931 let src = r#"Composition {
932 CurrentTime = 0,
933 RenderRange = { 0, 1 },
934 GlobalRange = { 0, 1 },
935 Tools = ordered() {
936 BG1 = Background {
937 Inputs = {
938 Width = Input { Value = 128, },
939 Height = Input { Value = 128, },
940 Type = Input { Value = FuID { "Horizontal" }, },
941 TopLeftRed = Input { Value = 1.0, },
942 TopLeftGreen = Input { Value = 0.0, },
943 TopLeftBlue = Input { Value = 0.0, },
944 TopRightRed = Input { Value = 0.0, },
945 TopRightGreen = Input { Value = 1.0, },
946 TopRightBlue = Input { Value = 0.0, },
947 },
948 },
949 Dent1 = Dent {
950 Inputs = {
951 Input = Input { SourceOp = "BG1", Source = "Output", },
952 Center = Input { Value = { 0.5, 0.5 }, },
953 Size = Input { Value = 0.6, },
954 Strength = Input { Value = 0.8, },
955 Type = Input { Value = 0, },
956 },
957 },
958 },
959 }"#;
960 let comp = Comp::from_fusion_str(src).expect("parse Dent comp");
961 let Ok(mut eng) = Engine::new_headless() else {
962 return;
963 };
964 let bg_id = comp.find_node("BG1").unwrap();
965 let dent_id = comp.find_node("Dent1").unwrap();
966 let (bg_tex, _) = eng.evaluate(&comp, bg_id, 0.0);
967 let (dent_tex, stats) = eng.evaluate(&comp, dent_id, 0.0);
968 assert!(stats.unsupported_nodes.is_empty(), "unsupported: {:?}", stats.unsupported_nodes);
969 let bg_px = eng.readback_rgba(&bg_tex).expect("readback bg");
970 let dent_px = eng.readback_rgba(&dent_tex).expect("readback dent");
971
972 // Corners outside radius=0.3 must remain unchanged; interior must be distorted!
973 assert_eq!(&bg_px[0..4], &dent_px[0..4], "corner pixel outside dent radius should match");
974 let mut interior_diff = 0u64;
975 for y in 44..84 {
976 for x in 44..84 {
977 let idx = (y * 128 + x) * 4;
978 interior_diff += bg_px[idx].abs_diff(dent_px[idx]) as u64;
979 interior_diff += bg_px[idx + 1].abs_diff(dent_px[idx + 1]) as u64;
980 }
981 }
982 assert!(interior_diff > 2_000, "Dent interior should visibly distort, got {interior_diff}");
983 }
984
985 #[test]
986 fn test_s_render_ngon_transform_merge_and_boolean() {
987 let src = r#"Composition {
988 CurrentTime = 0,
989 RenderRange = { 0, 1 },
990 GlobalRange = { 0, 1 },
991 Tools = ordered() {
992 NGon1 = sNGon {
993 Inputs = {
994 Sides = Input { Value = 6, },
995 Width = Input { Value = 0.4, },
996 Red = Input { Value = 1.0, },
997 Green = Input { Value = 0.0, },
998 Blue = Input { Value = 0.0, },
999 },
1000 },
1001 XF1 = sTransform {
1002 Inputs = {
1003 XOffset = Input { Value = -0.2, },
1004 YOffset = Input { Value = 0.0, },
1005 XSize = Input { Value = 1.0, },
1006 YSize = Input { Value = 1.0, },
1007 ZRotation = Input { Value = 15.0, },
1008 Input = Input { SourceOp = "NGon1", Source = "Output", },
1009 },
1010 },
1011 Rect1 = sRectangle {
1012 Inputs = {
1013 Width = Input { Value = 0.3, },
1014 Height = Input { Value = 0.3, },
1015 CornerRadius = Input { Value = 0.05, },
1016 Translate = Input { Value = { 0.0, 0.0 }, },
1017 ["Translate.X"] = Input { Value = 0.2, },
1018 Red = Input { Value = 0.0, },
1019 Green = Input { Value = 0.0, },
1020 Blue = Input { Value = 1.0, },
1021 },
1022 },
1023 Merge1 = sMerge {
1024 Inputs = {
1025 Input1 = Input { SourceOp = "XF1", Source = "Output", },
1026 Input2 = Input { SourceOp = "Rect1", Source = "Output", },
1027 },
1028 },
1029 Render1 = sRender {
1030 Inputs = {
1031 Width = Input { Value = 128, },
1032 Height = Input { Value = 128, },
1033 Input = Input { SourceOp = "Merge1", Source = "Output", },
1034 },
1035 },
1036 },
1037 }"#;
1038 let comp = Comp::from_fusion_str(src).expect("parse sRender comp");
1039 let Ok(mut eng) = Engine::new_headless() else {
1040 return;
1041 };
1042 let render_id = comp.find_node("Render1").unwrap();
1043 let (tex, stats) = eng.evaluate(&comp, render_id, 0.0);
1044 assert!(stats.unsupported_nodes.is_empty(), "unsupported: {:?}", stats.unsupported_nodes);
1045 assert_eq!(tex.size, [128, 128]);
1046 let px = eng.readback_rgba(&tex).expect("readback sRender");
1047
1048 // Left shape center (-0.2 -> x ~ 38, y ~ 64) should be solid red
1049 let left = (64 * 128 + 38) * 4;
1050 assert!(px[left] > 240 && px[left + 2] < 10 && px[left + 3] > 240, "left={:?}", &px[left..left + 4]);
1051 // Right shape center (+0.2 -> x ~ 90, y ~ 64) should be solid blue
1052 let right = (64 * 128 + 90) * 4;
1053 assert!(px[right + 2] > 240 && px[right] < 10 && px[right + 3] > 240, "right={:?}", &px[right..right + 4]);
1054 // Top-left corner (0, 0) should be transparent
1055 assert_eq!(&px[0..4], &[0, 0, 0, 0], "corner should be transparent");
1056 }
1057}
crates/engine/src/shaders/archive_fx.wgsl created+116
......@@ -0,0 +1,116 @@
1// ============================================================================
2// Archive FX Warps: Drip (concentric ripple) & Dent (radial dent/bulge/pinch/punch)
3// ============================================================================
4
5// 1. Drip (concentric ripple warp)
6// p[0] = (center.x, center.y, strength, amplitude)
7// p[1] = (frequency, aspect, phase, dampening)
8// p[2] = (shape: 0=Circle, 1=Square, 2=Horizontal, 3=Vertical, blend, has_mask, mask_invert)
9@compute @workgroup_size(8, 8)
10fn drip_op(@builtin(global_invocation_id) gid: vec3<u32>) {
11 let dims = textureDimensions(dst_tex);
12 if (gid.x >= dims.x || gid.y >= dims.y) { return; }
13 let canvas_aspect = f32(dims.x) / max(f32(dims.y), 1.0);
14 let fu = pix_to_fu(gid.xy, dims);
15 let orig = textureLoad(src_a, vec2<i32>(gid.xy), 0);
16
17 let center = u.p[0].xy;
18 let strength = u.p[0].z;
19 let amp = u.p[0].w;
20 let freq = u.p[1].x;
21 let drip_aspect = max(u.p[1].y, 1e-4);
22 let phase = u.p[1].z;
23 let dampening = max(u.p[1].w, 0.0);
24 let shape = i32(u.p[2].x + 0.5);
25 let blend = u.p[2].y;
26
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);
30
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);
49 } 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 }
54
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);
58 let warped = sample_edges(src_a, src_fu, 2);
59
60 let m = read_mask(gid.xy, dims, u.p[2].z, u.p[2].w) * blend;
61 store_dst(vec2<i32>(gid.xy), mix(orig, warped, clamp(m, 0.0, 1.0)));
62}
63
64// 2. Dent (radial dent / sine / pinch / punch warp)
65// p[0] = (center.x, center.y, radius_norm, strength)
66// p[1] = (type: 0=Dent, 1=Sine, 2=Pinch, 3=Punch, blend, has_mask, mask_invert)
67@compute @workgroup_size(8, 8)
68fn dent_op(@builtin(global_invocation_id) gid: vec3<u32>) {
69 let dims = textureDimensions(dst_tex);
70 if (gid.x >= dims.x || gid.y >= dims.y) { return; }
71 let aspect = f32(dims.x) / max(f32(dims.y), 1.0);
72 let fu = pix_to_fu(gid.xy, dims);
73 let orig = textureLoad(src_a, vec2<i32>(gid.xy), 0);
74
75 let center = u.p[0].xy;
76 let radius = max(u.p[0].z, 1e-5);
77 let strength = u.p[0].w;
78 let dent_type = i32(u.p[1].x + 0.5);
79 let blend = u.p[1].y;
80
81 let rel_w = (fu - center) * vec2<f32>(1.0, 1.0 / aspect);
82 let r = length(rel_w);
83
84 var warped = orig;
85 if (r < radius && r > 1e-6 && abs(strength) > 1e-6) {
86 let t = clamp(r / radius, 0.0, 1.0);
87 var new_r = r;
88 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);
92 } 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);
96 } else if (dent_type == 2) {
97 // Pinch: power-law radial pinch/expand
98 let p = select(1.0 / max(1.0 - strength, 0.05), 1.0 + strength, strength >= 0.0);
99 new_r = radius * pow(t, p);
100 } 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);
104 } 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);
108 }
109 let scale = new_r / r;
110 let src_fu = center + rel_w * scale * vec2<f32>(1.0, aspect);
111 warped = sample_edges(src_a, src_fu, 2);
112 }
113
114 let m = read_mask(gid.xy, dims, u.p[1].z, u.p[1].w) * blend;
115 store_dst(vec2<i32>(gid.xy), mix(orig, warped, clamp(m, 0.0, 1.0)));
116}
crates/model/src/comp.rs+209-9
......@@ -120,8 +120,19 @@ pub fn is_supported_tool(kind: &str) -> bool {
120120 | "FilmGrain"
121121 | "Displace"
122122 | "Vortex"
123 | "Drip"
124 | "Dent"
123125 | "Fuse.Duplicate"
124126 | "Fuse.KScope"
127 // 2D vector shape pipeline
128 | "sRender"
129 | "sNGon"
130 | "sRectangle"
131 | "sEllipse"
132 | "sMerge"
133 | "sTransform"
134 | "sBoolean"
135 | "sOutline"
125136 | "EllipseMask"
126137 | "RectangleMask"
127138 | "PolylineMask"
......@@ -136,6 +147,8 @@ pub fn is_supported_tool(kind: &str) -> bool {
136147 | "Dimension.OpticalFlow"
137148 | "OpticalFlow"
138149 | "Custom"
150 // Modifiers
151 | "Expression"
139152 // Particle system
140153 | "pRender"
141154 | "pEmitter"
......@@ -146,6 +159,7 @@ pub fn is_supported_tool(kind: &str) -> bool {
146159 | "pFriction"
147160 | "pKill"
148161 | "pMerge"
162 | "pBounce"
149163 // 3D tools
150164 | "Renderer3D"
151165 | "Merge3D"
......@@ -153,6 +167,8 @@ pub fn is_supported_tool(kind: &str) -> bool {
153167 | "Camera3D"
154168 | "ImagePlane3D"
155169 | "Shape3D"
170 | "Cube3D"
171 | "SurfaceFBXMesh"
156172 | "Text3D"
157173 | "LightAmbient"
158174 | "LightDirectional"
......@@ -162,6 +178,8 @@ pub fn is_supported_tool(kind: &str) -> bool {
162178 | "MtlCookTorrance"
163179 | "MtlPhong"
164180 | "Texture2DOperator"
181 | "TextureTransformOperator"
182 | "BumpMap"
165183 | "ReplaceMaterial3D"
166184 | "Override3D"
167185 | "Duplicate3D"
......@@ -585,20 +603,54 @@ impl Comp {
585603 }
586604 }
587605
588 // Resolve Fusion instanced tools (e.g. `Instance_ColorGain1 = ColorGain { SourceOp = "ColorGain1" }`)
589 for (nid, master_name) in instanced_from {
590 if let Some(&mid) = node_by_name.get(&master_name) {
591 if mid != nid {
592 let master_inputs = nodes[mid.0].inputs.clone();
606 // Resolve Fusion tool-level `SourceOp` instanced node inheritance
607 // (e.g. `Instance_ColorCorrector1_6 = ColorCorrector { SourceOp = "ColorCorrector1_6" }`),
608 // walking chains up to depth 8 (cycle-safe) while NEVER copying image/mask/scene wires.
609 if !instanced_from.is_empty() {
610 let parent_of: HashMap<NodeId, NodeId> = instanced_from
611 .iter()
612 .filter_map(|(nid, master_name)| {
613 node_by_name
614 .get(master_name)
615 .copied()
616 .filter(|&mid| mid != *nid)
617 .map(|mid| (*nid, mid))
618 })
619 .collect();
620 let orig_inputs: Vec<HashMap<String, InputBinding>> =
621 nodes.iter().map(|n| n.inputs.clone()).collect();
622
623 for &(nid, _) in &instanced_from {
624 let mut visited = HashSet::new();
625 visited.insert(nid);
626 let mut cur = nid;
627 for _depth in 0..8 {
628 let Some(&pid) = parent_of.get(&cur) else {
629 break;
630 };
631 if !visited.insert(pid) {
632 break;
633 }
593634 let inst_inputs = &mut nodes[nid.0].inputs;
594 for (k, mb) in master_inputs {
595 let empty = inst_inputs.get(&k).is_none_or(|b| {
635 for (inp_name, parent_binding) in &orig_inputs[pid.0] {
636 if is_non_inheritable_instance_port(inp_name, parent_binding, &node_by_name)
637 {
638 continue;
639 }
640 if parent_binding.value.is_none()
641 && parent_binding.source_op.is_none()
642 && parent_binding.expression.is_none()
643 {
644 continue;
645 }
646 let child_empty = inst_inputs.get(inp_name).is_none_or(|b| {
596647 b.value.is_none() && b.source_op.is_none() && b.expression.is_none()
597648 });
598 if empty {
599 inst_inputs.insert(k, mb);
649 if child_empty {
650 inst_inputs.insert(inp_name.clone(), parent_binding.clone());
600651 }
601652 }
653 cur = pid;
602654 }
603655 }
604656 }
......@@ -1807,6 +1859,14 @@ fn sync_node_inputs(
18071859 if orig == *binding {
18081860 continue;
18091861 }
1862 // Don't materialize inherited master inputs into an empty stub `Input {}` on instanced tools.
1863 if orig.value.is_none()
1864 && orig.source_op.is_none()
1865 && orig.expression.is_none()
1866 && master_inputs.is_some_and(|m| m.get(port) == Some(binding))
1867 {
1868 continue;
1869 }
18101870 let in_tbl = ensure_table_mut(tool_tbl, "Inputs", None);
18111871 if let Some(it) = in_tbl.get_table_mut(port) {
18121872 if orig.source_op != binding.source_op {
......@@ -1968,6 +2028,45 @@ fn sync_spline_table(spline_name: &str, spline: &BezierSpline, tbl: &mut LuaTabl
19682028 }
19692029}
19702030
2031fn is_non_inheritable_instance_port(
2032 name: &str,
2033 binding: &InputBinding,
2034 node_by_name: &HashMap<String, NodeId>,
2035) -> bool {
2036 if matches!(
2037 name,
2038 "Input"
2039 | "Background"
2040 | "Foreground"
2041 | "EffectMask"
2042 | "MaterialInput"
2043 | "GarbageMatte"
2044 | "SolidMatte"
2045 | "Mask"
2046 | "TrackingMask"
2047 | "RegionMask"
2048 | "MatchReference"
2049 | "MatchMask"
2050 | "Image"
2051 | "Image1"
2052 | "Image2"
2053 | "BlurImage"
2054 | "DisplaceImage"
2055 ) || name.starts_with("SceneInput")
2056 || name.starts_with("MainInput")
2057 {
2058 return true;
2059 }
2060 // Never inherit flow-graph image/scene/material connections targeting another flow node;
2061 // modifiers (`BezierSpline`, `PolyPath`, `Shake`, `Expression`, etc.) are not in `node_by_name`.
2062 binding.value.is_none()
2063 && binding.expression.is_none()
2064 && binding
2065 .source_op
2066 .as_deref()
2067 .is_some_and(|op| node_by_name.contains_key(op))
2068}
2069
19712070pub fn default_main_input_port(kind: &str) -> &'static str {
19722071 match kind {
19732072 "Merge" => "Background",
......@@ -2887,4 +2986,105 @@ mod expression_modifier_tests {
28872986 let ang = comp.eval_number(xf, "Angle", 0.0, 0.0, &expr);
28882987 assert!((ang - 2.0).abs() < 1e-6, "got {ang}");
28892988 }
2989
2990 #[test]
2991 fn resolves_instanced_source_op_inheritance_chains_and_keeps_image_wires_isolated() {
2992 let src = r#"Composition {
2993 Tools = ordered() {
2994 Loader1 = Loader {},
2995 Transform2 = Transform {
2996 Inputs = {
2997 Input = Input { SourceOp = "Loader1", Source = "Output", },
2998 },
2999 },
3000 Ellipse1 = EllipseMask {},
3001 ColorCorrector1_6Blend = BezierSpline {
3002 KeyFrames = {
3003 [0] = { 0.25, Flags = { Linear = true } },
3004 [10] = { 0.75, Flags = { Linear = true } },
3005 },
3006 },
3007 ColorCorrector1_6 = ColorCorrector {
3008 Inputs = {
3009 Blend = Input { SourceOp = "ColorCorrector1_6Blend", Source = "Value", },
3010 WheelTintAngle1 = Input { Value = -0.434283, },
3011 WheelHue1 = Input { Value = 0.2, },
3012 PreDividePostMultiply = Input { Value = 1, },
3013 Input = Input { SourceOp = "Loader1", Source = "Output", },
3014 EffectMask = Input { SourceOp = "Ellipse1", Source = "Mask", },
3015 },
3016 },
3017 Instance_ColorCorrector1_6 = ColorCorrector {
3018 SourceOp = "ColorCorrector1_6",
3019 Inputs = {
3020 Input = Input { SourceOp = "Transform2", Source = "Output", },
3021 EffectMask = Input {},
3022 WheelTintAngle1 = Input {},
3023 WheelHue1 = Input { Value = 0.9, },
3024 },
3025 },
3026 Instance_Chained = ColorCorrector {
3027 SourceOp = "Instance_ColorCorrector1_6",
3028 Inputs = {
3029 Input = Input { SourceOp = "Loader1", Source = "Output", },
3030 },
3031 },
3032 CycleA = Blur {
3033 SourceOp = "CycleB",
3034 Inputs = {
3035 XBlurSize = Input { Value = 3.0, },
3036 },
3037 },
3038 CycleB = Blur {
3039 SourceOp = "CycleA",
3040 Inputs = {
3041 YBlurSize = Input { Value = 7.0, },
3042 },
3043 },
3044 },
3045 }"#;
3046
3047 let comp = Comp::from_fusion_str(src).expect("parse instanced comp");
3048 let expr = ExprEngine::new();
3049
3050 let inst = comp.node(comp.find_node("Instance_ColorCorrector1_6").unwrap());
3051 // Inherits WheelTintAngle1 (even through empty `Input {}` stub) and Blend spline from master!
3052 let tint = comp.eval_number(inst, "WheelTintAngle1", 0.0, 0.0, &expr);
3053 assert!((tint - (-0.434283)).abs() < 1e-6, "got {tint}");
3054 let blend_t5 = comp.eval_number(inst, "Blend", 5.0, 1.0, &expr);
3055 assert!((blend_t5 - 0.5).abs() < 1e-6, "got {blend_t5}");
3056 let pdpm = comp.eval_number(inst, "PreDividePostMultiply", 0.0, 0.0, &expr);
3057 assert!((pdpm - 1.0).abs() < 1e-6, "got {pdpm}");
3058 // Keeps its own explicit override (`WheelHue1 = 0.9`) and its own `Input` wire (`Transform2`)!
3059 let hue = comp.eval_number(inst, "WheelHue1", 0.0, 0.0, &expr);
3060 assert!((hue - 0.9).abs() < 1e-6, "got {hue}");
3061 assert_eq!(inst.connected_node("Input"), Some("Transform2"));
3062 // NEVER inherits parent's `EffectMask` image/mask wire!
3063 assert_eq!(inst.connected_node("EffectMask"), None);
3064
3065 // Chained inheritance (`Instance_Chained -> Instance_ColorCorrector1_6 -> ColorCorrector1_6`):
3066 // nearest ancestor wins (`WheelHue1 = 0.9`), grandparent fills remaining params (`WheelTintAngle1`, `Blend`).
3067 let chained = comp.node(comp.find_node("Instance_Chained").unwrap());
3068 assert!((comp.eval_number(chained, "WheelHue1", 0.0, 0.0, &expr) - 0.9).abs() < 1e-6);
3069 assert!((comp.eval_number(chained, "WheelTintAngle1", 0.0, 0.0, &expr) - (-0.434283)).abs() < 1e-6);
3070 assert!((comp.eval_number(chained, "Blend", 10.0, 0.0, &expr) - 0.75).abs() < 1e-6);
3071 assert_eq!(chained.connected_node("Input"), Some("Loader1"));
3072 assert_eq!(chained.connected_node("EffectMask"), None);
3073
3074 // Cycle safety (`CycleA <-> CycleB` terminates cleanly and cross-inherits missing params)
3075 let cyc_a = comp.node(comp.find_node("CycleA").unwrap());
3076 let cyc_b = comp.node(comp.find_node("CycleB").unwrap());
3077 assert!((comp.eval_number(cyc_a, "XBlurSize", 0.0, 0.0, &expr) - 3.0).abs() < 1e-6);
3078 assert!((comp.eval_number(cyc_a, "YBlurSize", 0.0, 0.0, &expr) - 7.0).abs() < 1e-6);
3079 assert!((comp.eval_number(cyc_b, "XBlurSize", 0.0, 0.0, &expr) - 3.0).abs() < 1e-6);
3080 assert!((comp.eval_number(cyc_b, "YBlurSize", 0.0, 0.0, &expr) - 7.0).abs() < 1e-6);
3081
3082 // Roundtrip preserves SourceOp inheritance without duplicating master params
3083 let saved = comp.to_fusion_string();
3084 let reloaded = Comp::from_fusion_str(&saved).expect("reload");
3085 let r_inst = reloaded.node(reloaded.find_node("Instance_ColorCorrector1_6").unwrap());
3086 assert!((reloaded.eval_number(r_inst, "WheelTintAngle1", 0.0, 0.0, &expr) - (-0.434283)).abs() < 1e-6);
3087 assert!((reloaded.eval_number(r_inst, "Blend", 5.0, 1.0, &expr) - 0.5).abs() < 1e-6);
3088 assert_eq!(r_inst.connected_node("EffectMask"), None);
3089 }
28903090}
scripts/gen_compatibility.py+19-1
......@@ -45,6 +45,7 @@ CATEGORIES: Sequence[str] = (
4545 "Blur, Sharpen & Glow",
4646 "Transform, Warp & Framing",
4747 "Masks",
48 "2D Vector Shapes",
4849 "Particles",
4950 "3D Pipeline",
5051 "Time, Routing & Utility",
......@@ -104,6 +105,8 @@ TOOL_METADATA: Sequence[ToolMeta] = (
104105 ToolMeta("DVE", "Transform, Warp & Framing", "`tier1_b`", "0.1%–0.4%", "2.5D ZYX Euler rotation + perspective homography (`Center`, `ZMove`, `Pivot`, `AlphaMode`)."),
105106 ToolMeta("Displace", "Transform, Warp & Framing", "`displace`, `displace_wave`", "0.0%–0.1%", "`XY` refraction (channels, offsets, refraction strength) and `Radial`/`Bump` (`LightPower`, `LightAngle`, `LightChannel` additive directional slope lighting)."),
106107 ToolMeta("Vortex", "Transform, Warp & Framing", "`vortex_cc`", "0.0%–0.4%", "Isotropic radial swirl warp (`Center`, `Size`, `Angle`, `Power`, `Blend`, `EffectMask`)."),
108 ToolMeta("Drip", "Transform, Warp & Framing", "Unit tests", "0.0%", "Concentric ripple warp (`Center`, `Strength`, `Amplitude`, `Frequency`, `Aspect`, `Phase`, `Dampening`, `Shape`, `Blend`, `EffectMask`)."),
109 ToolMeta("Dent", "Transform, Warp & Framing", "Unit tests", "0.0%", "Radial distortion warp (`Center`, `Strength`, `Size`, `Type`: `Dent`/`Sine`/`Pinch`/`Punch`, `Blend`, `EffectMask`)."),
107110 ToolMeta("Fuse.Duplicate", "Transform, Warp & Framing", "`archive_3d`", "0.0%–0.4%", "Multi-copy iterative 2D transform composite (`Copies`, `Center`, `Size`, `Angle`, `Gain`, `Blend`, `TimeOffset`, `MergeUnder`)."),
108111 ToolMeta("Fuse.KScope", "Transform, Warp & Framing", "Unit tests", "0.0%", "N-slice radial kaleidoscope mirror (`Slices`, `Center`, `Angle`, `CaptureAngle`, `Scale`, `Edges`)."),
109112 ToolMeta("Scale", "Transform, Warp & Framing", "Suite comps", "0.0%–0.2%", "Proportional/non-proportional image scaling with resampling filter."),
......@@ -118,6 +121,16 @@ TOOL_METADATA: Sequence[ToolMeta] = (
118121 ToolMeta("BitmapMask", "Masks", "`mask_softedge`", "0.0%–0.2%", "GPU image-to-mask extraction (`Alpha`/`Luminance`/`Red`/`Green`/`Blue`/`Saturation`/`Lightness`/`Hue`), `Low`/`High` clip, centered 1:1 alignment, `SoftEdge`, `Invert`, `Level`, `PaintMode`."),
119122 ToolMeta("WandMask", "Masks", "`archive_3d`", "0.0%–0.3%", "Seeded BFS flood-fill wand mask (`Source`, `SelectionPoint`, `SelectionRange`, `ColorSpace`, `SoftEdge`, `Invert`, `Level`, `PaintMode`)."),
120123
124 # 2D Vector Shapes
125 ToolMeta("sRender", "2D Vector Shapes", "Unit tests", "0.0%", "Antialiased `zeno` 2D vector shape tree rasterizer (`Width`, `Height`, `Blend`, `EffectMask`, cached RGBA upload & `HiQ` depth promotion)."),
126 ToolMeta("sNGon", "2D Vector Shapes", "Unit tests", "0.0%", "Regular N-sided polygon vector shape (`Sides`, `Width`, `Height`, `Translate.X/Y`, `Angle`, `Solid`, `BorderWidth`, `JoinStyle`, RGBA color)."),
127 ToolMeta("sRectangle", "2D Vector Shapes", "Unit tests", "0.0%", "Vector rectangle & rounded rectangle (`Width`, `Height`, `CornerRadius`, `Translate.X/Y`, `Angle`, `Solid`, `BorderWidth`, RGBA color)."),
128 ToolMeta("sEllipse", "2D Vector Shapes", "Unit tests", "0.0%", "Cubic Bezier vector ellipse (`Width`, `Height`, `Translate.X/Y`, `Angle`, `Solid`, `BorderWidth`, RGBA color)."),
129 ToolMeta("sMerge", "2D Vector Shapes", "Unit tests", "0.0%", "Composites multiple upstream vector shape inputs (`Input1`..`InputN`) in painter's order."),
130 ToolMeta("sTransform", "2D Vector Shapes", "Unit tests", "0.0%", "2D affine shape transform (`XOffset`/`YOffset`, `XSize`/`YSize`, `Scale`, `ZRotation`, `XPivot`/`YPivot`)."),
131 ToolMeta("sBoolean", "2D Vector Shapes", "Unit tests", "0.0%", "Shape boolean combiner (`Union`, `Intersect`, `Subtract`, `Xor`) over `Input1` and `Input2`."),
132 ToolMeta("sOutline", "2D Vector Shapes", "Unit tests", "0.0%", "Converts upstream vector shapes into stroked outlines (`Thickness`/`BorderWidth`, `JoinStyle`, `CapStyle`)."),
133
121134 # Particles
122135 ToolMeta("pRender", "Particles", "Unit tests", "Visual*", "2D deterministic particle rasterizer (`ParticleStyleBitmap` rotated bilinear sprites, `ParticleStylePoint`/`Blob`, cached frame stepping). *Stochastic seed."),
123136 ToolMeta("pEmitter", "Particles", "Unit tests", "Visual*", "Seeded particle emitter (`RectRgn`/`SphereRgn`/`CubeRgn`/`LineRgn`/`Point`, `Number`, `Lifespan`, `Velocity`, `RotationZ`, `SpinZ`, `ColorVariance`, `SizeOverLife`, `FadeIn`/`FadeOut`)."),
......@@ -127,6 +140,7 @@ TOOL_METADATA: Sequence[ToolMeta] = (
127140 ToolMeta("pDrag", "Particles", "Unit tests", "Visual*", "Velocity damping / aerodynamic drag force.", aliases=("pFriction",)),
128141 ToolMeta("pKill", "Particles", "Unit tests", "Visual*", "Region-based particle termination (`Inside`/`Outside`/`Entering`/`Leaving`)."),
129142 ToolMeta("pMerge", "Particles", "Unit tests", "Visual*", "Combines multiple upstream particle emitter streams."),
143 ToolMeta("pBounce", "Particles", "Unit tests", "Visual*", "Region-based particle collision & elastic rebound (`Elasticity`, `Friction`, region planes/spheres/cubes)."),
130144
131145 # 3D Pipeline
132146 ToolMeta("Renderer3D", "3D Pipeline", "`cam3d`, `cam3d_fov`", "0.1%–0.4%", "GPU wgpu 3D rasterizer with depth buffer, perspective camera selection, lighting, and 2D texture sampling."),
......@@ -135,6 +149,8 @@ TOOL_METADATA: Sequence[ToolMeta] = (
135149 ToolMeta("Transform3D", "3D Pipeline", "`cam3d`, `cam3d_fov`", "0.1%–0.4%", "3D translate, rotate (all 6 `RotOrder`s), and scale (`ScaleLock`) transform node."),
136150 ToolMeta("ImagePlane3D", "3D Pipeline", "`cam3d`", "0.1%–0.4%", "Textured 3D quad driven by 2D image input or `Mtl*` diffuse texture."),
137151 ToolMeta("Shape3D", "3D Pipeline", "`cam3d`, `cam3d_fov`", "0.1%–0.4%", "`Plane`, `Sphere`, `Cylinder` (`StartSweep`/`EndSweep`, subdivisions), and `Cube` procedural geometry."),
152 ToolMeta("Cube3D", "3D Pipeline", "Unit tests", "0.1%–0.4%", "Dedicated 3D cube geometry with per-face / standard material binding (`SurfaceCubeInputs.*`, `MaterialInput`)."),
153 ToolMeta("SurfaceFBXMesh", "3D Pipeline", "Unit tests", "Visual*", "Binary/ASCII `.fbx` and `.obj` mesh loader (`ImportFile`, `ObjName`, `ScaleFileUnitsBy`, normals, UVs, material binding)."),
138154 ToolMeta("Text3D", "3D Pipeline", "`archive_3d`", "Visual*", "3D CoreText rasterized text plane with optional multi-slice `-Z` extrusion (`ExtrusionDepth`, `StyledText`, `Font`, `Style`, `Size`, color)."),
139155 ToolMeta("LightAmbient", "3D Pipeline", "Suite comps", "0.1%–0.4%", "Scene ambient RGB light intensity accumulation in `Renderer3D`."),
140156 ToolMeta("LightDirectional", "3D Pipeline", "Suite comps", "0.1%–0.4%", "World-oriented directional light (`-Z` emission axis) with RGB intensity in `Renderer3D`."),
......@@ -144,6 +160,8 @@ TOOL_METADATA: Sequence[ToolMeta] = (
144160 ToolMeta("MtlCookTorrance", "3D Pipeline", "`archive_3d`", "0.1%–0.8%", "Cook-Torrance 3D material (`Diffuse.Color`, `Diffuse.Opacity`, `Diffuse.Color.Material`, `Specular.Roughness/Color/Intensity`)."),
145161 ToolMeta("MtlPhong", "3D Pipeline", "`archive_3d`", "0.1%–0.8%", "Phong 3D material (`Diffuse.Color`, `Diffuse.Opacity`, `Specular.Color/Intensity/Exponent`)."),
146162 ToolMeta("Texture2DOperator", "3D Pipeline", "`archive_3d`", "0.0%–0.4%", "2D-image-to-3D-material adapter feeding `MaterialInput` or `Diffuse.Color.Material`."),
163 ToolMeta("TextureTransformOperator", "3D Pipeline", "Unit tests", "0.0%–0.4%", "3D material UV translation, scale, rotation, and wrap-mode (`Wrap`/`Mirror`/`Clamp`) transform operator."),
164 ToolMeta("BumpMap", "3D Pipeline", "Unit tests", "0.1%–0.5%", "3D heightmap and tangent-space normal-map bump perturbation (`HeightScale`, `SourceImageType`) feeding `Bumpmap.Material`."),
147165 ToolMeta("ReplaceMaterial3D", "3D Pipeline", "`archive_3d`", "0.0%–0.4%", "Subtree 3D material override (`SceneInput` + `MaterialInput`)."),
148166 ToolMeta("Override3D", "3D Pipeline", "`archive_3d`", "0.0%–0.2%", "Subtree 3D visibility (`Visibility.DoVisible`/`IsVisible`) and lighting (`Lighting.DoAffectedByLights`/`IsAffectedByLights`) override."),
149167 ToolMeta("Duplicate3D", "3D Pipeline", "`archive_3d`", "0.1%–0.5%", "Cumulative 3D scene instancer (`FirstCopy..LastCopy`, `Transform3DOp`, seeded `JitterTranslate`/`JitterRotate`)."),
......@@ -181,6 +199,7 @@ MODIFIER_METADATA: Sequence[ModifierMeta] = (
181199 ModifierMeta("`LUTBezier`", ("LUTBezier",), "`tier1_a`", "Curve lookup splines used standalone and nested inside `ColorCurves` / `HueCurves`."),
182200 ModifierMeta("`PolyPath` / `Path`", ("PolyPath", "Path"), "Suite comps", "2D motion-path polyline evaluation with animated `Displacement` spline."),
183201 ModifierMeta("`Shake`", ("Shake",), "`tier1_c`", "Procedural multi-octave noise modifier (`Source = X / Y / Value / Position`) with spline & expression inputs."),
202 ModifierMeta("`Expression`", ("Expression",), "Unit tests", "Standalone Fusion `Expression` modifier (`NumberExpression`, `PointExpressionX`/`Y`, `n1..n9`/`p1..p9` inputs, math DSL + Lua fallback)."),
184203 ModifierMeta("`StyledTextCLS`", ("StyledTextCLS", "CharacterLevelStyling"), "Suite comps", "Per-character `TextPlus` styling overrides (font, size, color, kerning, opacity)."),
185204 ModifierMeta("`TrackerModifier`", ("TrackerModifier",), "Suite comps", "Resolves baked tracker path aliases (`Track1TrackerPath`, etc.) into 2D `PolyPath` coordinates."),
186205 ModifierMeta("Lua Expressions", (), "Suite comps", "Inline `Expression = \"...\"` evaluation (`time`, `comp.RenderStart`/`End`, node input references, math/trig/clamp/ternary)."),
......@@ -200,7 +219,6 @@ UNSUPPORTED_NOTES: Sequence[UnsupportedMeta] = (
200219 UnsupportedMeta("MagicMask", "Preserved lossless on save; passes through main image input in Flow.", 7),
201220 UnsupportedMeta("PlanarTracker", "Preserved lossless on save; passes through main image input in Flow.", 7),
202221 UnsupportedMeta("Dimension.CopyAux", "Preserved lossless on save; passes through main image input.", None),
203 UnsupportedMeta("SurfaceFBXMesh", "Preserved lossless on save; FBX mesh geometry not yet imported in `Renderer3D`.", None),
204222)
205223
206224