From e047711ccb7667ce25327eb57a9afe1af8408665 Mon Sep 17 00:00:00 2001 From: clover caruso Date: Mon, 30 Nov 2026 18:23:05 -0800 Subject: [PATCH] Add deterministic fuzzer v2, calibrate Paint, and implement PerspectivePositioner/DaySky/GridWarp/sGrid (#36) --- compatibility.md | 24 +- crates/engine/src/eval/mod.rs | 19 +- crates/engine/src/eval/paint.rs | 54 +- crates/engine/src/eval/shapes_warp.rs | 683 +++++++++++++++++++++- crates/engine/src/shaders/archive_fx.wgsl | 106 ++++ crates/model/src/comp.rs | 174 ++++++ scripts/diff_fuzz.py | 558 +++++++++++++++++- scripts/gen_compatibility.py | 12 +- 8 files changed, 1580 insertions(+), 50 deletions(-) diff --git a/compatibility.md b/compatibility.md index bad70ad3e0c5ece2cd338a71f91a292c1fdc7c2c..e70160d1faec55228b0b100b71210ab7d9a1f78b 100644 --- a/compatibility.md +++ b/compatibility.md @@ -9,10 +9,10 @@ Auto-generated from live engine sources (`crates/engine/src/eval.rs`, `crates/en | Metric | Value | | --- | --- | -| **Supported Flow Tools** | **115** (90 2D/Fuse/utility in `eval.rs`, 23 3D scene nodes in `scene3d.rs`, 2 Flow annotations) | +| **Supported Flow Tools** | **119** (94 2D/Fuse/utility in `eval.rs`, 23 3D scene nodes in `scene3d.rs`, 2 Flow annotations) | | **Modifiers & Animation** | **8** systems (9 Fusion modifier classes + Lua expressions) | | **Active Corpus (`trees/fusion`) Coverage** | **99.7%** (1,988 / 1,993 nodes across 16 `.comp` files) | -| **Archive Corpus (`private/samples`) Coverage** | **99.6%** (54,734 / 54,955 nodes across 324 `.comp` files) | +| **Archive Corpus (`private/samples`) Coverage** | **99.7%** (54,763 / 54,955 nodes across 324 `.comp` files) | | **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. | ## Generators @@ -24,6 +24,7 @@ Auto-generated from live engine sources (`crates/engine/src/eval.rs`, `crates/en | `Plasma` | `tier1_c` | 0.1%–0.2% | 0 / 39 | 4-circle linear/sine interference pattern with phase/scale animation. | | `TextPlus` | `text`, `noise_text` | 0.2%–0.9% | 53 / 2770 | CoreText rasterizer, alignment, tracking, Euclidean subpixel SDF outline, `BorderFill` (`ElementShape = 2`, `Level`, `ExtendHorizontal/Vertical`, `Round`, `Offset`), and `StyledTextCLS`. | | `Loader` | All suites | 0.0% | 106 / 1274 | PNG/JPG/TIFF/EXR stills & sequences with direct unclamped 16/32-bit float HDR OpenEXR upload in `HiQ`; native macOS `AVFoundation`/`VideoToolbox` + `ffmpeg` video; `.wav`/`.mp3` audio. | +| `DaySky` | Unit tests | 0.4%–1.1% | 0 / 16 | Equirectangular Preetham/Perez physical sky dome (`Latitude`, `Longitude`, `Month`, `Day`, `Time`, `Turbidity`, `Exposure`, Perez horizon/circumsolar/backscatter sliders, log-avg luminance normalization + Reinhard tone map). | ## Compositing & Blending @@ -31,9 +32,9 @@ Auto-generated from live engine sources (`crates/engine/src/eval.rs`, `crates/en | --- | --- | --- | --- | --- | | `Merge` | `merge` | 0.0%–0.3% | 293 / 6358 | All ApplyModes (`Normal`, `Screen`, `Multiply`, `Difference`, `DarkerColor`, `Overlay`, `Hard/Soft/Linear/VividLight`, `LinearDodge`, etc.), `Operator=Over/Under`, `Gain`, `BurnIn`, `SubtractiveAdditive`, `Blend`, effect mask. | | `Dissolve` | `tier1_b` | 0.0%–0.1% | 0 / 4 | Mix (`Mix = 0..1`) between `Background` and `Foreground` with effect mask support. | -| `Paint` | Unit tests | Visual* | 0 / 25 | Composites the `Paint` stroke chain (`PolylineStroke` / `Multistroke`) over `Input` with `Blend` and `EffectMask`. CPU-rasterized round `CircleBrush` / `SoftBrush` (`Size`, `Softness`), `PaintApplyColor` (`Red`/`Green`/`Blue`/`Opacity`) and `PaintApplyErase` (erases earlier strokes). *Brush size/softness falloff are not Fusion-calibrated; `Clone` and other apply modes are skipped. | -| `PolylineStroke` | Unit tests | Visual* | 0 / 27 | Bezier/linear `Polyline` (static or animated) with `WriteOnStart`/`WriteOnEnd`; always visible. Rendered only through `Paint` / `PaintMask`. | -| `Multistroke` | Unit tests | Visual* | 0 / 33 | Recorded freehand `Strokes`, visible from `Time` for `Duration` frames (default 1) with per-stroke `Params` overrides (`ApplyMode`, `Size`, `Softness`, color, `Duration`). Per-point `T` is ignored. Rendered only through `Paint` / `PaintMask`. | +| `Paint` | Unit tests | 0.0%–1.2% | 0 / 25 | Composites the `Paint` stroke chain (`PolylineStroke` / `Multistroke`) over `Input` with `Blend` and `EffectMask`. Fusion-calibrated round `CircleBrush` / `SoftBrush` (`Size`, `Softness`, ~0.41*r spacing, sequential alpha buildup), `PaintApplyColor` (`Red`/`Green`/`Blue`/`Opacity`), and `PaintApplyErase`. | +| `PolylineStroke` | Unit tests | 0.0%–0.3% | 0 / 27 | Bezier/linear `Polyline` (static or animated) with `WriteOnStart`/`WriteOnEnd`; always visible. Rendered only through `Paint` / `PaintMask`. | +| `Multistroke` | Unit tests | 0.1%–1.2% | 0 / 33 | Recorded freehand `Strokes`, visible from `Time` for `Frames`/`Duration` frames (default 1) with per-stroke `Params` overrides (`ApplyMode`, `Size`, `Softness`, color, `Duration`). Rendered only through `Paint` / `PaintMask`. | | `Shadow` | `tier1_b` | 0.1%–0.4% | 0 / 38 | Drop shadow offset, softness blur, tint color/alpha, and `ShadowOnly` output. | ## Color & Depth @@ -83,6 +84,8 @@ Auto-generated from live engine sources (`crates/engine/src/eval.rs`, `crates/en | `Transform` | `xf` | 0.0%–0.3% | 47 / 1211 | `Center`, `Pivot`, `Size`/`XSize`/`YSize`, `Aspect`, `Angle`, `FlipHoriz`/`FlipVert`, `FilterMethod` (`Nearest`/`Box`/`Linear`/`Catmull-Rom`), `Edges` (`Canvas`/`Wrap`/`Duplicate`/`Mirror`). | | `CameraShake` | `tier1_c` | 0.1%–0.5% | 0 / 12 | Procedural X/Y/Rotation/Zoom camera shake with `OverallStrength`, `Speed`, `Edges`. | | `CornerPositioner` | `tier1_b` | 0.1%–0.4% | 0 / 29 | 4-point projective homography warp (`TopLeft`/`TopRight`/`BottomLeft`/`BottomRight`). | +| `PerspectivePositioner` | Unit tests | 0.3%–0.4% | 0 / 4 | Rectifies 4-corner quad (`BottomLeft`/`BottomRight`/`TopRight`/`TopLeft`) to unit square with `MappingType` bilinear `Linear` (0) or projective `Perspective` (1). | +| `GridWarp` | Unit tests | 0.4%–1.2% | 0 / 5 | 2D control-point `Mesh` Bezier/Coons patch warp (`SrcGridChange` -> `DstGridChange`, static or keyframed splines, tangent handles, `Blend`, `EffectMask`). | | `DVE` | `tier1_b` | 0.1%–0.4% | 4 / 22 | 2.5D ZYX Euler rotation + perspective homography (`Center`, `ZMove`, `Pivot`, `AlphaMode`). | | `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). | | `Vortex` | `vortex_cc` | 0.0%–0.4% | 1 / 1 | Isotropic radial swirl warp (`Center`, `Size`, `Angle`, `Power`, `Blend`, `EffectMask`). | @@ -104,7 +107,7 @@ Auto-generated from live engine sources (`crates/engine/src/eval.rs`, `crates/en | `PolylineMask` | `mask_softedge`, Suite comps | 0.1%–0.4% | 16 / 505 | CPU `zeno` Bezier/linear polygon rasterizer with animated keyframed `Polyline` splines, progressive-pyramid `SoftEdge`, `ClippingMode`, `Invert`, `PaintMode`. | | `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`. | | `WandMask` | `archive_3d` | 0.0%–0.3% | 0 / 150 | Seeded BFS flood-fill wand mask (`Source`, `SelectionPoint`, `SelectionRange`, `ColorSpace`, `SoftEdge`, `Invert`, `Level`, `PaintMode`). | -| `PaintMask` | Unit tests | Visual* | 0 / 14 | Alpha mask of the `Paint` stroke chain (stroke opacity, erase), `MaskWidth`/`MaskHeight`, `SoftEdge`, `Filter`, `ClippingMode`, `Invert`, `Level`, `PaintMode` chaining. *Brush falloff is not Fusion-calibrated. | +| `PaintMask` | Unit tests | 0.1%–0.4% | 0 / 14 | Fusion-calibrated alpha mask of the `Paint` stroke chain (`Size`, `Softness`, opacity, erase), `MaskWidth`/`MaskHeight`, `SoftEdge`, `Filter`, `ClippingMode`, `Invert`, `Level`, `PaintMode` chaining. | ## 2D Vector Shapes @@ -114,6 +117,7 @@ Auto-generated from live engine sources (`crates/engine/src/eval.rs`, `crates/en | `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). | | `sRectangle` | Unit tests | 0.0% | 0 / 6 | Vector rectangle & rounded rectangle (`Width`, `Height`, `CornerRadius`, `Translate.X/Y`, `Angle`, `Solid`, `BorderWidth`, RGBA color). | | `sEllipse` | Unit tests | 0.0% | 0 / 3 | Cubic Bezier vector ellipse (`Width`, `Height`, `Translate.X/Y`, `Angle`, `Solid`, `BorderWidth`, RGBA color). | +| `sGrid` | Unit tests | 0.0% | 0 / 4 | Centered 2D vector shape grid generator (`CellsX`, `CellsY`, `XOffset`, `YOffset`) feeding `sRender`. | | `sMerge` | Unit tests | 0.0% | 0 / 3 | Composites multiple upstream vector shape inputs (`Input1`..`InputN`) in painter's order. | | `sTransform` | Unit tests | 0.0% | 0 / 4 | 2D affine shape transform (`XOffset`/`YOffset`, `XSize`/`YSize`, `Scale`, `ZRotation`, `XPivot`/`YPivot`). | | `sBoolean` | Unit tests | 0.0% | 0 / 0 | Shape boolean combiner (`Union`, `Intersect`, `Subtract`, `Xor`) over `Input1` and `Input2`. | @@ -208,16 +212,12 @@ Unlike Blackmagic Fusion — which unlinks missing OFX or Resolve-only plugins w | `AudioDisplay` | 0 / 21 | — | Preserved lossless on save; passes through main input in Flow. | | `Fuse.AlphaWeightedNoise` | 0 / 21 | — | Preserved lossless on save; passes through main input in Flow. | | `Fuse.Hexagon` | 0 / 17 | — | Preserved lossless on save; passes through main input in Flow. | -| `DaySky` | 0 / 16 | — | Preserved lossless on save; passes through main input in Flow. | | `SurfaceAlembicMesh` | 0 / 13 | — | Preserved lossless on save; passes through main input in Flow. | | `PseudoColor` | 0 / 6 | — | Preserved lossless on save; passes through main input in Flow. | | `Fuse.CheckerPieceGenerator` | 0 / 6 | — | Preserved lossless on save; passes through main input in Flow. | -| `GridWarp` | 0 / 5 | — | Preserved lossless on save; passes through main input in Flow. | | `Fog` | 0 / 5 | — | Preserved lossless on save; passes through main input in Flow. | | `Highlight` | 0 / 4 | — | Preserved lossless on save; passes through main input in Flow. | | `Fuse.Lightning` | 0 / 4 | — | Preserved lossless on save; passes through main input in Flow. | -| `PerspectivePositioner` | 0 / 4 | — | Preserved lossless on save; passes through main input in Flow. | -| `sGrid` | 0 / 4 | — | Preserved lossless on save; passes through main input in Flow. | | `DepthBlur` | 0 / 4 | — | Preserved lossless on save; passes through main input in Flow. | | `Replicate3D` | 0 / 4 | — | Preserved lossless on save; passes through main input in Flow. | | `SphereMap` | 0 / 4 | — | Preserved lossless on save; passes through main input in Flow. | @@ -225,6 +225,10 @@ Unlike Blackmagic Fusion — which unlinks missing OFX or Resolve-only plugins w | `RankFilter` | 0 / 3 | — | Preserved lossless on save; passes through main input in Flow. | | `AcesTransform` | 0 / 3 | — | Preserved lossless on save; passes through main input in Flow. | | `Bender3D` | 0 / 2 | — | Preserved lossless on save; passes through main input in Flow. | +| `CleanPLate` | 0 / 2 | — | Preserved lossless on save; passes through main input in Flow. | +| `Calculation` | 0 / 2 | — | Preserved lossless on save; passes through main input in Flow. | +| `DeltaKeyer` | 0 / 2 | — | Preserved lossless on save; passes through main input in Flow. | +| `LensDistort` | 0 / 2 | — | Preserved lossless on save; passes through main input in Flow. | --- diff --git a/crates/engine/src/eval/mod.rs b/crates/engine/src/eval/mod.rs index 1cb72862158db3a2b3baf2cd4ea4ffeee3f77618..dc27455f01d30053b36de599f4ca9e09a9236a0d 100644 --- a/crates/engine/src/eval/mod.rs +++ b/crates/engine/src/eval/mod.rs @@ -146,6 +146,9 @@ enum ShaderOp { KScope, Drip, Dent, + PerspectivePos, + DaySky, + GridWarp, } impl ShaderOp { @@ -200,7 +203,9 @@ impl ShaderOp { | Self::UltraKeyer | Self::Plasma => ShaderDomain::KeyersGen, - Self::Drip | Self::Dent => ShaderDomain::ArchiveFx, + Self::Drip | Self::Dent | Self::PerspectivePos | Self::DaySky | Self::GridWarp => { + ShaderDomain::ArchiveFx + } } } @@ -251,6 +256,9 @@ impl ShaderOp { Self::KScope => "kscope_op", Self::Drip => "drip_op", Self::Dent => "dent_op", + Self::PerspectivePos => "perspective_pos_op", + Self::DaySky => "day_sky_op", + Self::GridWarp => "grid_warp_op", } } } @@ -1100,6 +1108,7 @@ impl Engine { "Transform" => self.eval_transform(comp, node, time, frame_i, enc, visiting, stats), "CameraShake" => self.eval_camera_shake(comp, node, time, frame_i, enc, visiting, stats), "CornerPositioner" => self.eval_corner_positioner(comp, node, time, frame_i, enc, visiting, stats), + "PerspectivePositioner" => self.eval_perspective_positioner(comp, node, time, frame_i, enc, visiting, stats), "DVE" => self.eval_dve(comp, node, time, frame_i, enc, visiting, stats), "Shadow" => self.eval_shadow(comp, node, time, frame_i, enc, visiting, stats), "Scale" | "BetterResize" => self.eval_scale(comp, node, time, frame_i, comp_dims, enc, visiting, stats), @@ -1126,17 +1135,20 @@ impl Engine { "ErodeDilate" => self.eval_erode_dilate(comp, node, time, frame_i, enc, visiting, stats), "FastNoise" => self.eval_fast_noise(comp, node, time, frame_i, comp_dims, enc, stats), "Plasma" => self.eval_plasma(comp, node, time, frame_i, comp_dims, enc, visiting, stats), + "DaySky" => self.eval_day_sky(comp, node, time, frame_i, comp_dims, enc, visiting, stats), "FilmGrain" => self.eval_film_grain(comp, node, time, frame_i, enc, visiting, stats), "Displace" => self.eval_displace(comp, node, time, frame_i, enc, visiting, stats), "Vortex" => self.eval_vortex(comp, node, time, frame_i, enc, visiting, stats), "Drip" => self.eval_drip(comp, node, time, frame_i, enc, visiting, stats), "Dent" => self.eval_dent(comp, node, time, frame_i, enc, visiting, stats), + "GridWarp" => self.eval_grid_warp(comp, node, time, frame_i, enc, visiting, stats), "Fuse.Duplicate" => self.eval_duplicate(comp, node, time, frame_i, enc, visiting, stats), "Fuse.KScope" => self.eval_kscope(comp, node, time, frame_i, enc, visiting, stats), "sRender" => self.eval_s_render(comp, node, time, frame_i, comp_dims, enc, visiting, stats), "sNGon" | "sRectangle" | "sEllipse" + | "sGrid" | "sMerge" | "sTransform" | "sBoolean" @@ -1400,6 +1412,7 @@ mod lazy_shader_verify { ShaderOp::UltraKeyer, ShaderOp::Dissolve, ShaderOp::Homography, ShaderOp::ShadowComp, ShaderOp::Plasma, ShaderOp::FilmGrain, ShaderOp::SetDomain, ShaderOp::ChangeDepth, ShaderOp::Vortex, ShaderOp::KScope, ShaderOp::Drip, ShaderOp::Dent, + ShaderOp::PerspectivePos, ShaderOp::DaySky, ShaderOp::GridWarp, ]; // Verify starts completely empty (lazy!) assert_eq!(eng.pipelines.borrow().modules.len(), 0); @@ -1409,9 +1422,9 @@ mod lazy_shader_verify { eng.pipelines_for(BitDepth::Float16).borrow_mut().ensure_pipeline(&eng.device, op); } assert_eq!(eng.pipelines.borrow().modules.len(), 7); - assert_eq!(eng.pipelines.borrow().pipelines.len(), 45); + assert_eq!(eng.pipelines.borrow().pipelines.len(), 48); assert_eq!(eng.pipelines_for(BitDepth::Float16).borrow().modules.len(), 7); - assert_eq!(eng.pipelines_for(BitDepth::Float16).borrow().pipelines.len(), 45); + assert_eq!(eng.pipelines_for(BitDepth::Float16).borrow().pipelines.len(), 48); } #[test] diff --git a/crates/engine/src/eval/paint.rs b/crates/engine/src/eval/paint.rs index e46f41fdab614e4b46e42c34fb6c04e56fb258a5..754cd5795aca2198d26df6b24695e8a9ba9a4d5c 100644 --- a/crates/engine/src/eval/paint.rs +++ b/crates/engine/src/eval/paint.rs @@ -84,7 +84,9 @@ fn collect_strokes(comp: &Comp, head: &Node, time: f64, expr: &ExprEngine) -> Ve let params = st.get_table("Params"); let Some(mut s) = stroke_style(comp, node, time, expr, params) else { continue }; let start = st.get_f64("Time").unwrap_or(0.0); - let duration = stroke_number(comp, node, time, expr, params, "Duration", 1.0); + let duration = st + .get_f64("Frames") + .unwrap_or_else(|| stroke_number(comp, node, time, expr, params, "Duration", 1.0)); if time < start || time >= start + duration { continue; } @@ -131,6 +133,7 @@ fn stroke_style( let mode = params .and_then(|p| p.get_table("ApplyMode")?.get("Value")) .and_then(fuid) + .or_else(|| node.static_str("ApplyMode")) .or_else(|| node.raw.get_table("ApplyModes")?.get_index(1)?.as_str()) .unwrap_or("PaintApplyColor"); let erase = match mode { @@ -142,11 +145,25 @@ fn stroke_style( .static_str("BrushShape") .or_else(|| node.raw.get_table("Brushes")?.get_index(1)?.as_str()) .unwrap_or("SoftBrush"); + let size = stroke_number( + comp, + node, + time, + expr, + params, + &format!("{brush}.Size"), + stroke_number(comp, node, time, expr, params, "Size", 0.01), + ) as f32; + let softness = if brush == "SoftBrush" { + num("SoftBrush.Softness", 0.5).clamp(0.0, 1.0) + } else { + 0.0 + }; Some(Stroke { path: Vec::new(), write_on: [0.0, 1.0], - size: num(&format!("{brush}.Size"), 0.01), - softness: if brush == "SoftBrush" { num("SoftBrush.Softness", 0.5).clamp(0.0, 1.0) } else { 0.0 }, + size, + softness, color: [ num("PaintApplyColor.Red", 1.0), num("PaintApplyColor.Green", 1.0), @@ -173,10 +190,15 @@ fn stamp_positions(path: &[[f32; 2]], write_on: [f32; 2], spacing: f32) -> Vec<[ return vec![first]; } let (d0, d1) = (start * total, end * total); - let n = ((d1 - d0) / spacing).ceil() as usize; + let span = d1 - d0; + if span <= 1e-4 { + return Vec::new(); + } + let n = (span / spacing).round().max(1.0) as usize; + let step = span / n as f32; (0..=n) .map(|k| { - let d = (d0 + k as f32 * spacing).min(d1); + let d = (d0 + k as f32 * step).min(d1); let i = cum.partition_point(|&c| c < d).clamp(1, path.len() - 1); let t = (d - cum[i - 1]) / (cum[i] - cum[i - 1]).max(1e-6); [0, 1].map(|a| path[i - 1][a] + (path[i][a] - path[i - 1][a]) * t) @@ -184,13 +206,17 @@ fn stamp_positions(path: &[[f32; 2]], write_on: [f32; 2], spacing: f32) -> Vec<[ .collect() } -/// Coverage of a round brush of radius `r` at distance `d` from its center. +/// Coverage of a round brush of radius `r` at distance `d` from its center (calibrated to Fusion 21.1 SoftBrush/CircleBrush). fn brush_coverage(d: f32, r: f32, softness: f32) -> f32 { if softness <= 0.0 { return (r + 0.5 - d).clamp(0.0, 1.0); } - let t = ((r - d) / (r * softness).max(1e-3)).clamp(0.0, 1.0); - t * t * (3.0 - 2.0 * t) + let u = (d / r.max(1e-5)).clamp(0.0, 1.0); + if u >= 1.0 { + return 0.0; + } + let p = 1.75 / softness.max(1e-3); + (1.0 - u.powf(p)).max(0.0).powf(1.85) } /// Rasterizes `strokes` in order into a premultiplied RGBA float layer, top row first. @@ -199,7 +225,8 @@ fn render_strokes(strokes: &[Stroke], [w, h]: [u32; 2]) -> Vec<[f32; 4]> { for s in strokes { let r = (s.size * w as f32 * 0.5).max(0.5); let px: Vec<[f32; 2]> = s.path.iter().map(|p| [(0.5 + p[0]) * w as f32, (0.5 - p[1]) * h as f32]).collect(); - let stamps = stamp_positions(&px, s.write_on, (r * 0.2).max(0.5)); + // Fusion default stamp spacing is ~0.205 * diameter (~0.41 * radius). + let stamps = stamp_positions(&px, s.write_on, (r * 0.41).max(0.5)); let bounds = stamps.iter().fold([f32::MAX, f32::MAX, f32::MIN, f32::MIN], |b, p| { [b[0].min(p[0]), b[1].min(p[1]), b[2].max(p[0]), b[3].max(p[1])] }); @@ -218,14 +245,17 @@ fn render_strokes(strokes: &[Stroke], [w, h]: [u32; 2]) -> Vec<[f32; 4]> { for y in sy0..sy1 { for x in sx0..sx1 { let d = (x as f32 + 0.5 - c[0]).hypot(y as f32 + 0.5 - c[1]); - let v = &mut cov[(y - y0) as usize * bw + (x - x0) as usize]; - *v = v.max(brush_coverage(d, r, s.softness)); + let a_stamp = brush_coverage(d, r, s.softness) * s.opacity; + if a_stamp > 0.0 { + let v = &mut cov[(y - y0) as usize * bw + (x - x0) as usize]; + *v = a_stamp + *v * (1.0 - a_stamp); + } } } } for y in y0..y1 { for x in x0..x1 { - let a = cov[(y - y0) as usize * bw + (x - x0) as usize] * s.opacity; + let a = cov[(y - y0) as usize * bw + (x - x0) as usize]; let px = &mut layer[(y * w + x) as usize]; if s.erase { px.iter_mut().for_each(|c| *c *= 1.0 - a); diff --git a/crates/engine/src/eval/shapes_warp.rs b/crates/engine/src/eval/shapes_warp.rs index 7688d5f8f73b9cd2edc2776117a8f913427705f1..c30bd4ce6cddacbfbed32db7d6cd186e8acb5980 100644 --- a/crates/engine/src/eval/shapes_warp.rs +++ b/crates/engine/src/eval/shapes_warp.rs @@ -277,7 +277,10 @@ fn collect_shape_tree( }) } "sTransform" => { - let src_id = node.connected_node("Input").and_then(|s| comp.find_node(s))?; + let src_id = node + .connected_node("Input") + .or_else(|| node.connected_node("Input1")) + .and_then(|s| comp.find_node(s))?; let ox = eval_first_num(comp, node, &["XOffset", "Translate.X"], time, 0.0, expr) as f32; let oy = eval_first_num(comp, node, &["YOffset", "Translate.Y"], time, 0.0, expr) as f32; let px = eval_first_num(comp, node, &["XPivot", "Pivot.X"], time, 0.0, expr) as f32; @@ -327,8 +330,45 @@ fn collect_shape_tree( Some(ShapeTree::Group(children)) } } + "sGrid" => { + let src_id = node + .connected_node("Input") + .or_else(|| node.connected_node("Input1")) + .and_then(|s| comp.find_node(s))?; + let cells_x = comp.eval_number(node, "CellsX", time, 3.0, expr).round().clamp(1.0, 256.0) as usize; + let cells_y = comp.eval_number(node, "CellsY", time, 3.0, expr).round().clamp(1.0, 256.0) as usize; + let x_off = comp.eval_number(node, "XOffset", time, 0.2, expr) as f32; + let y_off = comp.eval_number(node, "YOffset", time, 0.2, expr) as f32; + let mut children = Vec::with_capacity(cells_x.saturating_mul(cells_y)); + for iy in 0..cells_y { + let ty = (iy as f32 - (cells_y as f32 - 1.0) * 0.5) * y_off; + for ix in 0..cells_x { + let tx = (ix as f32 - (cells_x as f32 - 1.0) * 0.5) * x_off; + let cell_xf = parent_xform.mul(Affine2D::translate(tx, ty)); + if let Some(tree) = collect_shape_tree( + comp, + src_id, + time, + expr, + cell_xf, + outline_override, + depth + 1, + ) { + children.push(tree); + } + } + } + if children.is_empty() { + None + } else { + Some(ShapeTree::Group(children)) + } + } "sOutline" => { - let src_id = node.connected_node("Input").and_then(|s| comp.find_node(s))?; + let src_id = node + .connected_node("Input") + .or_else(|| node.connected_node("Input1")) + .and_then(|s| comp.find_node(s))?; let thickness = eval_first_num(comp, node, &["Thickness", "BorderWidth"], time, 0.01, expr).abs() as f32; let join = comp.eval_number(node, "JoinStyle", time, 2.0, expr).round().clamp(0.0, 2.0) as u8; let cap = comp.eval_number(node, "CapStyle", time, 0.0, expr).round().clamp(0.0, 2.0) as u8; @@ -373,7 +413,10 @@ fn collect_shape_tree( } } "PipeRouter" | "Fuse.Wireless" => { - let src_id = node.connected_node("Input").and_then(|s| comp.find_node(s))?; + let src_id = node + .connected_node("Input") + .or_else(|| node.connected_node("Input1")) + .and_then(|s| comp.find_node(s))?; collect_shape_tree(comp, src_id, time, expr, parent_xform, outline_override, depth + 1) } "MacroOperator" | "GroupOperator" => { @@ -844,6 +887,507 @@ impl Engine { self.cache.insert(key, out.clone(), node.id, frame_i); out } + + #[allow(clippy::too_many_arguments)] + pub(super) fn eval_perspective_positioner( + &mut self, + comp: &Comp, + node: &Node, + time: f64, + frame_i: i64, + enc: &mut wgpu::CommandEncoder, + visiting: &mut HashSet<(NodeId, i64)>, + stats: &mut EvalStats, + ) -> CachedTexture { + let Some(src_id) = node.connected_node("Input").and_then(|s| comp.find_node(s)) else { + return self.dummy.clone(); + }; + let src = self.eval_node(comp, src_id, time, enc, visiting, stats); + let blend = comp.eval_number(node, "Blend", time, 1.0, &self.expr) as f32; + if blend <= 1e-6 { + return src; + } + let src = self.crop_to_canvas(enc, src); + let bl = comp.eval_point(node, "BottomLeft", time, [0.0, 0.0], &self.expr); + let br = comp.eval_point(node, "BottomRight", time, [1.0, 0.0], &self.expr); + let tr = comp.eval_point(node, "TopRight", time, [1.0, 1.0], &self.expr); + let tl = comp.eval_point(node, "TopLeft", time, [0.0, 1.0], &self.expr); + let mapping_type = comp.eval_number(node, "MappingType", time, 0.0, &self.expr).round() as i32; + let h_fwd = quad_forward_homography(bl, br, tr, tl); + let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats); + let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash); + + let mut u = UniformParams::default(); + u.p[0] = [bl[0] as f32, bl[1] as f32, br[0] as f32, br[1] as f32]; + u.p[1] = [tr[0] as f32, tr[1] as f32, tl[0] as f32, tl[1] as f32]; + u.p[2] = [h_fwd[0], h_fwd[1], h_fwd[2], h_fwd[3]]; + u.p[3] = [h_fwd[4], h_fwd[5], h_fwd[6], h_fwd[7]]; + u.p[4] = [ + h_fwd[8], + if mapping_type == 1 { 1.0 } else { 0.0 }, + blend, + if mask.is_some() { 1.0 } else { 0.0 }, + ]; + u.p[5] = [if mask_inv { 1.0 } else { 0.0 }, 0.0, 0.0, 0.0]; + + let key = self.make_key( + node, + "PerspectivePositioner", + src.size, + &[src.content_hash, mask_hash], + bytemuck::cast_slice(&u.p[..6]), + ); + if let Some(hit) = self.cache.get(key, node.id, frame_i) { + stats.cache_hits += 1; + return hit; + } + stats.cache_misses += 1; + stats.nodes_evaluated += 1; + let dst = self.alloc_tex_like(&src, src.depth, key); + let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view); + self.dispatch_op(enc, ShaderOp::PerspectivePos, &src.view, &self.dummy.view, mv, &dst, &u); + self.cache.insert(key, dst.clone(), node.id, frame_i); + dst + } + + #[allow(clippy::too_many_arguments)] + pub(super) fn eval_day_sky( + &mut self, + comp: &Comp, + node: &Node, + time: f64, + frame_i: i64, + comp_dims: [u32; 2], + enc: &mut wgpu::CommandEncoder, + visiting: &mut HashSet<(NodeId, i64)>, + stats: &mut EvalStats, + ) -> CachedTexture { + let use_ff = comp.eval_number(node, "UseFrameFormatSettings", time, 0.0, &self.expr) > 0.5; + let w = if use_ff { + comp.width + } else { + comp.eval_number(node, "Width", time, comp.width as f64, &self.expr).round().max(1.0) as u32 + }; + let h = if use_ff { + comp.height + } else { + comp.eval_number(node, "Height", time, comp.height as f64, &self.expr).round().max(1.0) as u32 + }; + let size = if w == comp.width && h == comp.height { comp_dims } else { self.scaled_dims(w, h) }; + let dst_depth = self.node_depth(comp, node, time, None); + let blend = comp.eval_number(node, "Blend", time, 1.0, &self.expr) as f32; + + let lat_deg = comp.eval_number(node, "Latitude", time, 43.65, &self.expr); + let lon_deg = comp.eval_number(node, "Longitude", time, -79.38, &self.expr); + let month = parse_month_index(node, comp, time, &self.expr); + let day = node + .static_str("Day") + .and_then(|s| s.parse::().ok()) + .unwrap_or_else(|| comp.eval_number(node, "Day", time, 1.0, &self.expr)); + let hour = comp.eval_number(node, "Time", time, 12.0, &self.expr); + let turbidity_in = comp.eval_number(node, "Turbidity", time, 0.0, &self.expr).max(0.0); + let exposure = comp.eval_number(node, "Exposure", time, 0.72, &self.expr).max(0.0); + let hb = comp.eval_number(node, "Horizon.Brightness", time, 1.0, &self.expr).max(0.0); + let hl = comp.eval_number(node, "Horizon.Luminance", time, 1.0, &self.expr).max(0.0); + let ci = comp.eval_number(node, "Circumsolar.Intensity", time, 1.0, &self.expr).max(0.0); + let cw = comp.eval_number(node, "Circumsolar.Width", time, 1.0, &self.expr).max(0.0); + let bs = comp.eval_number(node, "BackscatteredLight", time, 1.0, &self.expr).max(0.0); + + let (sun_dir, ts) = solar_direction(lat_deg, lon_deg, month, day, hour); + // Calibrated to Fusion 21.1 DaySky: Turbidity in [0,1] maps to T = 1.9 + 4.0 * turb + let t_preetham = 1.9 + turbidity_in * 4.0; + let (xz, yz, _yz_lum) = preetham_zenith_xyy(t_preetham, ts); + let c_y0 = [ + 0.1787 * t_preetham - 1.4630, + (-0.3554 * t_preetham + 0.4275) * 1.20, + -0.0227 * t_preetham + 5.3251, + 0.1206 * t_preetham - 2.5771, + -0.0670 * t_preetham + 0.3703, + ]; + let c_x0 = [ + -0.0193 * t_preetham - 0.2592, + -0.0665 * t_preetham + 0.0008, + -0.0004 * t_preetham + 0.2125, + -0.0641 * t_preetham - 0.8989, + -0.0033 * t_preetham + 0.0452, + ]; + let c_y_c0 = [ + -0.0167 * t_preetham - 0.2608, + -0.0950 * t_preetham + 0.0092, + -0.0079 * t_preetham + 0.2102, + -0.0441 * t_preetham - 1.6537, + -0.0109 * t_preetham + 0.0529, + ]; + + let scale_perez = |base: [f64; 5]| -> [f64; 5] { + let a = if hb <= 1e-4 || hl <= 1e-4 { 0.0 } else { base[0] * hb }; + let b = base[1] / hl.max(1e-3); + let c = if cw <= 1e-4 { 0.0 } else { base[2] * ci }; + let d = base[3] * cw; + let e = base[4] * bs; + [a, b, c, d, e] + }; + let c_y = scale_perez(c_y0); + let c_x = scale_perez(c_x0); + let c_yc = scale_perez(c_y_c0); + + // Log-average Perez luminance normalization: geom_mean(Y_hdr) == Exposure + const N_TH: usize = 32; + const N_PH: usize = 32; + let mut sum_log = 0.0_f64; + for iy in 0..N_TH { + let th = (iy as f64 + 0.5) / N_TH as f64 * std::f64::consts::FRAC_PI_2; + let (st, ct) = th.sin_cos(); + for ix in 0..N_PH { + let ph = (ix as f64 + 0.5) / N_PH as f64 * std::f64::consts::TAU; + let (sp, cp) = ph.sin_cos(); + let cos_g = (st * cp * sun_dir[0] + st * sp * sun_dir[1] + ct * sun_dir[2]).clamp(-1.0, 1.0); + let fy = eval_perez(th, cos_g.acos(), c_y).max(1e-5); + sum_log += fy.ln(); + } + } + let geomean_fy = (sum_log / (N_TH * N_PH) as f64).exp().max(1e-5); + let lum_gain = (exposure / geomean_fy) as f32; + let f_y0 = 1.0_f64; + let f_x0 = eval_perez(0.0, ts, c_x); + let f_yc0 = eval_perez(0.0, ts, c_yc); + let yz_scaled = lum_gain; + + let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(size), enc, visiting, stats); + let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash); + + let mut u = UniformParams::default(); + u.p[0] = [sun_dir[0] as f32, sun_dir[1] as f32, sun_dir[2] as f32, yz_scaled]; + u.p[1] = [xz as f32, yz as f32, f_y0 as f32, f_x0 as f32]; + u.p[2] = [f_yc0 as f32, blend, if mask.is_some() { 1.0 } else { 0.0 }, if mask_inv { 1.0 } else { 0.0 }]; + u.p[3] = [c_y[0] as f32, c_y[1] as f32, c_y[2] as f32, c_y[3] as f32]; + u.p[4] = [c_y[4] as f32, c_x[0] as f32, c_x[1] as f32, c_x[2] as f32]; + u.p[5] = [c_x[3] as f32, c_x[4] as f32, c_yc[0] as f32, c_yc[1] as f32]; + u.p[6] = [c_yc[2] as f32, c_yc[3] as f32, c_yc[4] as f32, 0.0]; + + let key = self.make_key( + node, + "DaySky", + size, + &[mask_hash, dst_depth as u64], + bytemuck::cast_slice(&u.p[..7]), + ); + if let Some(hit) = self.cache.get(key, node.id, frame_i) { + stats.cache_hits += 1; + return hit; + } + stats.cache_misses += 1; + stats.nodes_evaluated += 1; + let dst = self.alloc_tex(size, dst_depth, key); + let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view); + self.dispatch_op(enc, ShaderOp::DaySky, &self.dummy.view, &self.dummy.view, mv, &dst, &u); + self.cache.insert(key, dst.clone(), node.id, frame_i); + dst + } + + #[allow(clippy::too_many_arguments)] + pub(super) fn eval_grid_warp( + &mut self, + comp: &Comp, + node: &Node, + time: f64, + frame_i: i64, + enc: &mut wgpu::CommandEncoder, + visiting: &mut HashSet<(NodeId, i64)>, + stats: &mut EvalStats, + ) -> CachedTexture { + let Some(src_id) = node.connected_node("Input").and_then(|s| comp.find_node(s)) else { + return self.dummy.clone(); + }; + let src = self.eval_node(comp, src_id, time, enc, visiting, stats); + let blend = comp.eval_number(node, "Blend", time, 1.0, &self.expr) as f32; + if blend <= 1e-6 { + return src; + } + let src_mesh = comp.eval_grid_mesh(node, "SrcGridChange", time); + let dst_mesh = comp.eval_grid_mesh(node, "DstGridChange", time); + let (Some(src_mesh), Some(dst_mesh)) = (src_mesh, dst_mesh) else { + return src; + }; + if src_mesh == dst_mesh { + return src; + } + let src = self.crop_to_canvas(enc, src); + let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats); + let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash); + + let mut u = UniformParams::default(); + u.p[0] = [blend, if mask.is_some() { 1.0 } else { 0.0 }, if mask_inv { 1.0 } else { 0.0 }, 0.0]; + + let mut mesh_params: Vec = Vec::with_capacity(4 + (src_mesh.points.len() + dst_mesh.points.len()) * 10); + mesh_params.extend_from_slice(&[blend, src_mesh.cols as f32, src_mesh.rows as f32, dst_mesh.cols as f32]); + for m in [&src_mesh, &dst_mesh] { + for p in &m.points { + mesh_params.extend_from_slice(&[ + p.x as f32, + p.y as f32, + p.l_cx.unwrap_or(f32::NAN as f64) as f32, + p.l_cy.unwrap_or(0.0) as f32, + p.r_cx.unwrap_or(f32::NAN as f64) as f32, + p.r_cy.unwrap_or(0.0) as f32, + p.t_cx.unwrap_or(0.0) as f32, + p.t_cy.unwrap_or(f32::NAN as f64) as f32, + p.b_cx.unwrap_or(0.0) as f32, + p.b_cy.unwrap_or(f32::NAN as f64) as f32, + ]); + } + } + + let key = self.make_key(node, "GridWarp", src.size, &[src.content_hash, mask_hash], &mesh_params); + if let Some(hit) = self.cache.get(key, node.id, frame_i) { + stats.cache_hits += 1; + return hit; + } + stats.cache_misses += 1; + stats.nodes_evaluated += 1; + + let uv_f16 = rasterize_grid_warp_uv_f16(&src_mesh, &dst_mesh, src.size); + let uv_tex = create_texture_dod_fmt( + &self.device, + src.size, + [0, 0], + src.size, + BitDepth::Float16, + wgpu::TextureFormat::Rgba16Float, + 0, + ); + self.queue.write_texture( + uv_tex.texture.as_image_copy(), + bytemuck::cast_slice(&uv_f16), + wgpu::TexelCopyBufferLayout { + offset: 0, + bytes_per_row: Some(src.size[0] * 8), + rows_per_image: Some(src.size[1]), + }, + wgpu::Extent3d { + width: src.size[0], + height: src.size[1], + depth_or_array_layers: 1, + }, + ); + + let dst = self.alloc_tex_like(&src, src.depth, key); + let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view); + self.dispatch_op(enc, ShaderOp::GridWarp, &src.view, &uv_tex.view, mv, &dst, &u); + self.cache.insert(key, dst.clone(), node.id, frame_i); + dst + } +} + +fn quad_forward_homography(bl: [f64; 2], br: [f64; 2], tr: [f64; 2], tl: [f64; 2]) -> [f32; 9] { + let dx1 = br[0] - tr[0]; + let dy1 = br[1] - tr[1]; + let dx2 = tl[0] - tr[0]; + let dy2 = tl[1] - tr[1]; + let sx = bl[0] - br[0] + tr[0] - tl[0]; + let sy = bl[1] - br[1] + tr[1] - tl[1]; + let denom = dx1 * dy2 - dx2 * dy1; + if denom.abs() < 1e-10 { + return [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]; + } + let g = (sx * dy2 - sy * dx2) / denom; + let h = (dx1 * sy - dy1 * sx) / denom; + let a = br[0] - bl[0] + g * br[0]; + let b = tl[0] - bl[0] + h * tl[0]; + let c = bl[0]; + let d = br[1] - bl[1] + g * br[1]; + let e = tl[1] - bl[1] + h * tl[1]; + let f = bl[1]; + [a as f32, b as f32, c as f32, d as f32, e as f32, f as f32, g as f32, h as f32, 1.0] +} + +fn parse_month_index(node: &Node, comp: &Comp, time: f64, expr: &ExprEngine) -> usize { + if let Some(m) = node.static_str("Month") { + let low = m.to_ascii_lowercase(); + let names = [ + "january", "february", "march", "april", "may", "june", + "july", "august", "september", "october", "november", "december", + ]; + if let Some(idx) = names.iter().position(|&n| low.starts_with(&n[..3])) { + return idx + 1; + } + if let Ok(v) = m.parse::() { + return v.clamp(1, 12); + } + } + (comp.eval_number(node, "Month", time, 0.0, expr).round() as usize + 1).clamp(1, 12) +} + +fn solar_direction(lat_deg: f64, lon_deg: f64, month: usize, day: f64, hour: f64) -> ([f64; 3], f64) { + const CUM_DAYS: [i32; 12] = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]; + let doy = CUM_DAYS[month.saturating_sub(1).min(11)] as f64 + day; + let b = 2.0 * std::f64::consts::PI * (doy - 81.0) / 365.0; + let eot_min = 9.87 * (2.0 * b).sin() - 7.53 * b.cos() - 1.5 * b.sin(); + let decl = 23.44_f64.to_radians() * ((2.0 * std::f64::consts::PI / 365.0) * (doy - 81.0)).sin(); + let std_meridian = (lon_deg / 15.0).round() * 15.0; + let solar_hour = hour + (lon_deg - std_meridian) / 15.0 + eot_min / 60.0; + let hour_angle = ((solar_hour - 12.0) * 15.0).to_radians(); + let lat = lat_deg.to_radians(); + let sin_alt = (lat.sin() * decl.sin() + lat.cos() * decl.cos() * hour_angle.cos()).clamp(-1.0, 1.0); + let ts = (std::f64::consts::FRAC_PI_2 - sin_alt.asin()).max(0.0); + // Azimuth measured from South (0=South, pi/2=East morning, pi=North, 3*pi/2=West afternoon) + let cos_az_south = (-(decl.sin() * lat.cos() - decl.cos() * lat.sin() * hour_angle.cos()) + / ts.sin().max(1e-5)) + .clamp(-1.0, 1.0); + let mut phi_s = cos_az_south.acos(); + if hour_angle > 0.0 { + phi_s = 2.0 * std::f64::consts::PI - phi_s; + } + let dir = [ts.sin() * phi_s.cos(), ts.sin() * phi_s.sin(), ts.cos()]; + (dir, ts) +} + +fn preetham_zenith_xyy(t: f64, ts: f64) -> (f64, f64, f64) { + let t2 = t * t; + let ts2 = ts * ts; + let ts3 = ts2 * ts; + let chi = (4.0 / 9.0 - t / 120.0) * (std::f64::consts::PI - 2.0 * ts); + let yz_lum = ((4.0453 * t - 4.9710) * chi.tan() - 0.2155 * t + 2.4192).max(0.05); + let xz = (0.00166 * ts3 - 0.00375 * ts2 + 0.00209 * ts) * t2 + + (-0.02903 * ts3 + 0.06377 * ts2 - 0.03202 * ts + 0.00394) * t + + (0.11693 * ts3 - 0.21196 * ts2 + 0.06052 * ts + 0.25886); + let yz = (0.00275 * ts3 - 0.00610 * ts2 + 0.00317 * ts) * t2 + + (-0.04214 * ts3 + 0.08970 * ts2 - 0.04153 * ts + 0.00516) * t + + (0.15346 * ts3 - 0.26756 * ts2 + 0.06670 * ts + 0.26688); + (xz, yz, yz_lum) +} + +fn eval_perez(theta: f64, gamma: f64, c: [f64; 5]) -> f64 { + let ct = theta.cos().max(0.02); + let cg = gamma.cos(); + (1.0 + c[0] * (c[1] / ct).exp()) * (1.0 + c[2] * (c[3] * gamma).exp() + c[4] * cg * cg) +} + +#[derive(Clone, Copy)] +struct CoonsPt { + p: [f32; 2], + l: [f32; 2], + r: [f32; 2], + t: [f32; 2], + b: [f32; 2], +} + +fn mesh_coons_cells(mesh: &model::comp::GridMesh) -> Vec<[CoonsPt; 4]> { + let cols = mesh.cols; + let rows = mesh.rows; + let dc = (mesh.delta_c as f32) / 3.0; + let dr = (mesh.delta_r as f32) / 3.0; + let pts: Vec = mesh + .points + .iter() + .map(|mp| { + let p = [mp.x as f32, mp.y as f32]; + let l = [p[0] + mp.l_cx.map_or(-dc, |v| v as f32), p[1] + mp.l_cy.unwrap_or(0.0) as f32]; + let r = [p[0] + mp.r_cx.map_or(dc, |v| v as f32), p[1] + mp.r_cy.unwrap_or(0.0) as f32]; + let t = [p[0] + mp.t_cx.unwrap_or(0.0) as f32, p[1] + mp.t_cy.map_or(-dr, |v| v as f32)]; + let b = [p[0] + mp.b_cx.unwrap_or(0.0) as f32, p[1] + mp.b_cy.map_or(dr, |v| v as f32)]; + CoonsPt { p, l, r, t, b } + }) + .collect(); + let mut cells = Vec::with_capacity((cols - 1) * (rows - 1)); + for r in 0..(rows - 1) { + for c in 0..(cols - 1) { + cells.push([ + pts[r * cols + c], + pts[r * cols + c + 1], + pts[(r + 1) * cols + c], + pts[(r + 1) * cols + c + 1], + ]); + } + } + cells +} + +fn bez3_2d(p0: [f32; 2], p1: [f32; 2], p2: [f32; 2], p3: [f32; 2], t: f32) -> [f32; 2] { + let u = 1.0 - t; + let (w0, w1, w2, w3) = (u * u * u, 3.0 * u * u * t, 3.0 * u * t * t, t * t * t); + [ + w0 * p0[0] + w1 * p1[0] + w2 * p2[0] + w3 * p3[0], + w0 * p0[1] + w1 * p1[1] + w2 * p2[1] + w3 * p3[1], + ] +} + +fn eval_coons_cell(cell: &[CoonsPt; 4], u: f32, v: f32) -> [f32; 2] { + let [p00, p10, p01, p11] = *cell; + let bot = bez3_2d(p00.p, p00.r, p10.l, p10.p, u); + let top = bez3_2d(p01.p, p01.r, p11.l, p11.p, u); + let lft = bez3_2d(p00.p, p00.b, p01.t, p01.p, v); + let rgt = bez3_2d(p10.p, p10.b, p11.t, p11.p, v); + let bi0 = (1.0 - u) * (1.0 - v) * p00.p[0] + u * (1.0 - v) * p10.p[0] + (1.0 - u) * v * p01.p[0] + u * v * p11.p[0]; + let bi1 = (1.0 - u) * (1.0 - v) * p00.p[1] + u * (1.0 - v) * p10.p[1] + (1.0 - u) * v * p01.p[1] + u * v * p11.p[1]; + [ + (1.0 - v) * bot[0] + v * top[0] + (1.0 - u) * lft[0] + u * rgt[0] - bi0, + (1.0 - v) * bot[1] + v * top[1] + (1.0 - u) * lft[1] + u * rgt[1] - bi1, + ] +} + +fn rasterize_grid_warp_uv_f16( + src_mesh: &model::comp::GridMesh, + dst_mesh: &model::comp::GridMesh, + dims: [u32; 2], +) -> Vec { + let [w, h] = dims; + let (wf, hf) = (w as f32, h as f32); + let mut uv_buf = vec![0u16; (w as usize) * (h as usize) * 4]; + let src_cells = mesh_coons_cells(src_mesh); + let dst_cells = mesh_coons_cells(dst_mesh); + let sub = 24usize; + let one_f16 = crate::media::f32_to_f16_bits(1.0); + + for (sc, dc) in src_cells.iter().zip(dst_cells.iter()) { + for j in 0..sub { + let (v0, v1) = (j as f32 / sub as f32, (j + 1) as f32 / sub as f32); + for i in 0..sub { + let (u0, u1) = (i as f32 / sub as f32, (i + 1) as f32 / sub as f32); + let da = eval_coons_cell(dc, u0, v0); + let db = eval_coons_cell(dc, u1, v0); + let dc2 = eval_coons_cell(dc, u1, v1); + let dd = eval_coons_cell(dc, u0, v1); + let sa = eval_coons_cell(sc, u0, v0); + let sb = eval_coons_cell(sc, u1, v0); + let sc2 = eval_coons_cell(sc, u1, v1); + let sd = eval_coons_cell(sc, u0, v1); + + for ([pa, pb, pc], [qa, qb, qc]) in [([da, db, dc2], [sa, sb, sc2]), ([da, dc2, dd], [sa, sc2, sd])] { + let (ax, ay) = ((pa[0] + 0.5) * wf, (0.5 - pa[1]) * hf); + let (bx, by) = ((pb[0] + 0.5) * wf, (0.5 - pb[1]) * hf); + let (cx, cy) = ((pc[0] + 0.5) * wf, (0.5 - pc[1]) * hf); + let area = (bx - ax) * (cy - ay) - (by - ay) * (cx - ax); + if area.abs() < 1e-6 { + continue; + } + let inv_area = 1.0 / area; + let x0 = ax.min(bx).min(cx).floor().max(0.0) as u32; + let x1 = (ax.max(bx).max(cx).ceil() as u32).min(w.saturating_sub(1)); + let y0 = ay.min(by).min(cy).floor().max(0.0) as u32; + let y1 = (ay.max(by).max(cy).ceil() as u32).min(h.saturating_sub(1)); + for py in y0..=y1 { + let qy = py as f32 + 0.5; + for px in x0..=x1 { + let qx = px as f32 + 0.5; + let w0 = ((bx - qx) * (cy - qy) - (by - qy) * (cx - qx)) * inv_area; + let w1 = ((cx - qx) * (ay - qy) - (cy - qy) * (ax - qx)) * inv_area; + let w2 = 1.0 - w0 - w1; + if w0 >= -1e-4 && w1 >= -1e-4 && w2 >= -1e-4 { + let su = w0 * qa[0] + w1 * qb[0] + w2 * qc[0] + 0.5; + let sv = w0 * qa[1] + w1 * qb[1] + w2 * qc[1] + 0.5; + let idx = (py as usize * w as usize + px as usize) * 4; + uv_buf[idx] = crate::media::f32_to_f16_bits(su); + uv_buf[idx + 1] = crate::media::f32_to_f16_bits(sv); + uv_buf[idx + 2] = one_f16; + } + } + } + } + } + } + } + uv_buf } #[cfg(test)] @@ -1211,4 +1755,137 @@ mod tests { let ngon_only = (64 * 128 + 54) * 4; assert_eq!(&px_xor[ngon_only..ngon_only + 4], &[255, 255, 255, 255]); } + + #[test] + fn test_perspective_positioner_and_s_grid() { + let src = r#"{ + Tools = ordered() { + Bg1 = Background { + Inputs = { + Width = Input { Value = 64, }, + Height = Input { Value = 64, }, + Type = Input { Value = FuID { "Horizontal" }, }, + TopLeftRed = Input { Value = 1, }, + TopRightRed = Input { Value = 0, }, + TopRightBlue = Input { Value = 1, }, + }, + }, + PP_Lin = PerspectivePositioner { + Inputs = { + TopLeft = Input { Value = { 0.25, 0.75 }, }, + TopRight = Input { Value = { 0.75, 0.75 }, }, + BottomLeft = Input { Value = { 0.25, 0.25 }, }, + BottomRight = Input { Value = { 0.75, 0.25 }, }, + Input = Input { SourceOp = "Bg1", Source = "Output", }, + }, + }, + El1 = sEllipse { + Inputs = { Width = Input { Value = 0.1, }, Height = Input { Value = 0.1, }, }, + }, + Gr1 = sGrid { + Inputs = { + Input = Input { SourceOp = "El1", Source = "Output", }, + CellsX = Input { Value = 3, }, + CellsY = Input { Value = 3, }, + XOffset = Input { Value = 0.25, }, + YOffset = Input { Value = 0.25, }, + }, + }, + SR1 = sRender { + Inputs = { + Width = Input { Value = 64, }, + Height = Input { Value = 64, }, + Input = Input { SourceOp = "Gr1", Source = "Output", }, + }, + }, + }, + }"#; + let comp = Comp::from_fusion_str(src).unwrap(); + let Ok(mut eng) = Engine::new_headless() else { return; }; + let (t_pp, _) = eng.evaluate(&comp, comp.find_node("PP_Lin").unwrap(), 0.0); + let px_pp = eng.readback_rgba(&t_pp).unwrap(); + // Top-left output pixel samples around (0.25, 0.75) in Bg1 -> ~75% red, ~25% blue! + let p0 = &px_pp[0..4]; + assert!(p0[0] > 165 && p0[2] > 40 && p0[2] < 90, "got {p0:?}"); + + let (t_sr, _) = eng.evaluate(&comp, comp.find_node("SR1").unwrap(), 0.0); + let px_sr = eng.readback_rgba(&t_sr).unwrap(); + // Center cell (32, 32) and offset (+0.25*64 = 48, 32) should be lit white + assert_eq!(&px_sr[(32 * 64 + 32) * 4..(32 * 64 + 32) * 4 + 4], &[255, 255, 255, 255]); + assert_eq!(&px_sr[(32 * 64 + 48) * 4..(32 * 64 + 48) * 4 + 4], &[255, 255, 255, 255]); + assert_eq!(&px_sr[0..4], &[0, 0, 0, 0]); + } + + #[test] + fn test_day_sky_and_grid_warp() { + let src = r#"{ + Tools = ordered() { + DS1 = DaySky { + Inputs = { + Width = Input { Value = 64, }, + Height = Input { Value = 64, }, + Latitude = Input { Value = 37.0, }, + Longitude = Input { Value = 0.0, }, + Time = Input { Value = 12.0, }, + Exposure = Input { Value = 1.0, }, + }, + }, + BgW = Background { + Inputs = { + Width = Input { Value = 64, }, + Height = Input { Value = 64, }, + Type = Input { Value = FuID { "Horizontal" }, }, + TopLeftRed = Input { Value = 1, }, + TopRightGreen = Input { Value = 1, }, + }, + }, + GW1 = GridWarp { + Inputs = { + SrcGridChange = Input { + Value = Mesh { + Columns = 2, Rows = 2, + DeltaC = 1, DeltaR = 1, + Center = { 0, 0 }, + Corners = { -0.5, -0.5, 0.5, 0.5 }, + Points = { + { X = -0.5, Y = -0.5 }, { X = 0.5, Y = -0.5 }, + { X = -0.5, Y = 0.5 }, { X = 0.5, Y = 0.5 }, + }, + }, + }, + DstGridChange = Input { + Value = Mesh { + Columns = 2, Rows = 2, + DeltaC = 1, DeltaR = 1, + Center = { 0, 0 }, + Corners = { -0.5, -0.5, 0.5, 0.5 }, + Points = { + { X = -0.5, Y = -0.5 }, { X = 0.5, Y = -0.5 }, + { X = -0.5, Y = 0.5 }, { X = 0.5, Y = 0.5 }, + }, + }, + }, + Input = Input { SourceOp = "BgW", Source = "Output", }, + }, + }, + }, + }"#; + let comp = Comp::from_fusion_str(src).unwrap(); + let Ok(mut eng) = Engine::new_headless() else { return; }; + let (t_ds, _) = eng.evaluate(&comp, comp.find_node("DS1").unwrap(), 0.0); + let px_ds = eng.readback_rgba(&t_ds).unwrap(); + // Zenith row (y=0) is sky blue (B > R), horizon (y=63) is brighter haze + let zen = &px_ds[(0 * 64 + 32) * 4..(0 * 64 + 32) * 4 + 4]; + let hor = &px_ds[(62 * 64 + 32) * 4..(62 * 64 + 32) * 4 + 4]; + assert!(zen[2] > zen[0] && zen[3] == 255, "zen={zen:?}"); + assert!(hor[0] > zen[0], "hor={hor:?} zen={zen:?}"); + + let (t_bg, _) = eng.evaluate(&comp, comp.find_node("BgW").unwrap(), 0.0); + let (t_gw, _) = eng.evaluate(&comp, comp.find_node("GW1").unwrap(), 0.0); + let px_bg = eng.readback_rgba(&t_bg).unwrap(); + let px_gw = eng.readback_rgba(&t_gw).unwrap(); + let mae: f64 = px_bg.iter().zip(&px_gw).map(|(a, b)| (*a as f64 - *b as f64).abs()).sum::() + / px_bg.len() as f64; + assert!(mae < 1.5, "identity GridWarp should match source, mae={mae}"); + } } diff --git a/crates/engine/src/shaders/archive_fx.wgsl b/crates/engine/src/shaders/archive_fx.wgsl index 64690d5ac837c085541e82c23941a26f3a65eda5..57b306dfc1ee3c79425d9d7685cd8c33ccba4785 100644 --- a/crates/engine/src/shaders/archive_fx.wgsl +++ b/crates/engine/src/shaders/archive_fx.wgsl @@ -108,3 +108,109 @@ fn dent_op(@builtin(global_invocation_id) gid: vec3) { let m = read_mask(gid.xy, dims, u.p[1].z, u.p[1].w) * blend; store_dst(vec2(gid.xy), mix(orig, warped, clamp(m, 0.0, 1.0))); } + +// 3. PerspectivePositioner (4-corner Linear bilinear or Perspective forward homography) +// p[0] = (bl.x, bl.y, br.x, br.y) +// p[1] = (tr.x, tr.y, tl.x, tl.y) +// p[2] = (h00, h01, h02, h10) +// p[3] = (h11, h12, h20, h21) +// p[4] = (h22, mapping_type: 0=Linear / 1=Perspective, blend, has_mask) +// p[5] = (mask_invert, 0, 0, 0) +@compute @workgroup_size(8, 8) +fn perspective_pos_op(@builtin(global_invocation_id) gid: vec3) { + let dims = textureDimensions(dst_tex); + if (gid.x >= dims.x || gid.y >= dims.y) { return; } + let fu = pix_to_fu(gid.xy, dims); + let orig = textureLoad(src_a, vec2(gid.xy), 0); + + var s_fu: vec2; + var valid = true; + if (u.p[4].y < 0.5) { + let bl = u.p[0].xy; + let br = u.p[0].zw; + let tr = u.p[1].xy; + let tl = u.p[1].zw; + let bot = mix(bl, br, fu.x); + let top = mix(tl, tr, fu.x); + s_fu = mix(bot, top, fu.y); + } else { + let sx = u.p[2].x * fu.x + u.p[2].y * fu.y + u.p[2].z; + let sy = u.p[2].w * fu.x + u.p[3].x * fu.y + u.p[3].y; + let sw = u.p[3].z * fu.x + u.p[3].w * fu.y + u.p[4].x; + if (abs(sw) > 1e-6) { + s_fu = vec2(sx / sw, sy / sw); + } else { + valid = false; + s_fu = vec2(-1.0); + } + } + + var warped = vec4(0.0); + if (valid && s_fu.x >= 0.0 && s_fu.x <= 1.0 && s_fu.y >= 0.0 && s_fu.y <= 1.0) { + warped = sample_edges(src_a, s_fu, 0); + } + + let m = read_mask(gid.xy, dims, u.p[4].w, u.p[5].x) * u.p[4].z; + store_dst(vec2(gid.xy), mix(orig, warped, clamp(m, 0.0, 1.0))); +} + +// 4. DaySky (Preetham Perez equirectangular physical sky dome) +// p[0] = (sun_dir.x, sun_dir.y, sun_dir.z, lum_gain) +// p[1] = (xz, yz, 1.0, fx0) +// p[2] = (fy0, blend, has_mask, mask_invert) +// p[3] = (AY, BY, CY, DY) +// p[4] = (EY, Ax, Bx, Cx) +// p[5] = (Dx, Ex, Ay, By) +// p[6] = (Cy, Dy, Ey, 0) +@compute @workgroup_size(8, 8) +fn day_sky_op(@builtin(global_invocation_id) gid: vec3) { + let dims = textureDimensions(dst_tex); + if (gid.x >= dims.x || gid.y >= dims.y) { return; } + + let phi = (f32(gid.x) + 0.5) / f32(dims.x) * 6.28318530718; + let theta = (f32(gid.y) + 0.5) / f32(dims.y) * 1.57079632679; + let sin_t = sin(theta); + let cos_t = cos(theta); + let dir = vec3(sin_t * cos(phi), sin_t * sin(phi), cos_t); + let cos_g = clamp(dot(dir, u.p[0].xyz), -1.0, 1.0); + let gamma = acos(cos_g); + let ct = max(cos_t, 0.02); + let cg2 = cos_g * cos_g; + + let fY = (1.0 + u.p[3].x * exp(u.p[3].y / ct)) * (1.0 + u.p[3].z * exp(u.p[3].w * gamma) + u.p[4].x * cg2); + let fx = (1.0 + u.p[4].y * exp(u.p[4].z / ct)) * (1.0 + u.p[4].w * exp(u.p[5].x * gamma) + u.p[5].y * cg2); + let fy = (1.0 + u.p[5].z * exp(u.p[5].w / ct)) * (1.0 + u.p[6].x * exp(u.p[6].y * gamma) + u.p[6].z * cg2); + + let Y_hdr = max(u.p[0].w * fY / max(u.p[1].z, 1e-4), 0.0); + let Y_tm = Y_hdr / (1.0 + Y_hdr); + let xc = clamp(u.p[1].x * fx / max(u.p[1].w, 1e-4), 0.05, 0.65); + let yc = clamp(u.p[1].y * fy / max(u.p[2].x, 1e-4), 0.05, 0.65); + + let X = (xc / yc) * Y_tm; + let Z = ((1.0 - xc - yc) / yc) * Y_tm; + let r = max(3.2404542 * X - 1.5371385 * Y_tm - 0.4985314 * Z, 0.0); + let g = max(-0.9692660 * X + 1.8760108 * Y_tm + 0.0415560 * Z, 0.0); + let b = max(0.0556434 * X - 0.2040259 * Y_tm + 1.0572252 * Z, 0.0); + + let m = read_mask(gid.xy, dims, u.p[2].z, u.p[2].w) * u.p[2].y; + store_dst(vec2(gid.xy), vec4(r, g, b, 1.0) * clamp(m, 0.0, 1.0)); +} + +// 5. GridWarp (samples src_a using pre-tessellated Rgba16Float UV map in src_b: .rg=src_fu, .b=coverage) +// p[0] = (blend, has_mask, mask_invert, 0) +@compute @workgroup_size(8, 8) +fn grid_warp_op(@builtin(global_invocation_id) gid: vec3) { + let dims = textureDimensions(dst_tex); + if (gid.x >= dims.x || gid.y >= dims.y) { return; } + let orig = textureLoad(src_a, vec2(gid.xy), 0); + let uv_cov = textureLoad(src_b, vec2(gid.xy), 0); + var warped = vec4(0.0); + if (uv_cov.b > 1e-4) { + let s_fu = uv_cov.rg; + if (s_fu.x >= 0.0 && s_fu.x <= 1.0 && s_fu.y >= 0.0 && s_fu.y <= 1.0) { + warped = sample_edges(src_a, s_fu, 0) * clamp(uv_cov.b, 0.0, 1.0); + } + } + let m = read_mask(gid.xy, dims, u.p[0].y, u.p[0].z) * u.p[0].x; + store_dst(vec2(gid.xy), mix(orig, warped, clamp(m, 0.0, 1.0))); +} diff --git a/crates/model/src/comp.rs b/crates/model/src/comp.rs index 29513f0f331f21c5ac78d91fc301e18665b0f2f0..7631a924bb977ef215dfadcda8fb2d13cefab3ff 100644 --- a/crates/model/src/comp.rs +++ b/crates/model/src/comp.rs @@ -89,6 +89,7 @@ pub fn is_supported_tool(kind: &str) -> bool { | "Transform" | "CameraShake" | "CornerPositioner" + | "PerspectivePositioner" | "DVE" | "Shadow" | "Scale" @@ -117,11 +118,13 @@ pub fn is_supported_tool(kind: &str) -> bool { | "ErodeDilate" | "FastNoise" | "Plasma" + | "DaySky" | "FilmGrain" | "Displace" | "Vortex" | "Drip" | "Dent" + | "GridWarp" | "Fuse.Duplicate" | "Fuse.KScope" // 2D vector shape pipeline @@ -129,6 +132,7 @@ pub fn is_supported_tool(kind: &str) -> bool { | "sNGon" | "sRectangle" | "sEllipse" + | "sGrid" | "sMerge" | "sTransform" | "sBoolean" @@ -747,6 +751,176 @@ impl Comp { .collect(), ) } +} + +#[derive(Clone, Debug, PartialEq)] +pub struct MeshPoint { + pub x: f64, + pub y: f64, + pub l_cx: Option, + pub l_cy: Option, + pub r_cx: Option, + pub r_cy: Option, + pub t_cx: Option, + pub t_cy: Option, + pub b_cx: Option, + pub b_cy: Option, +} + +#[derive(Clone, Debug, PartialEq)] +pub struct GridMesh { + pub cols: usize, + pub rows: usize, + pub delta_r: f64, + pub delta_c: f64, + pub points: Vec, +} + +impl GridMesh { + fn from_lua_table(tbl: &LuaTable) -> Option { + if tbl.tag.as_deref() != Some("Mesh") { + return None; + } + let cols = tbl.get_f64("Col")?.round().max(2.0) as usize; + let pts_tbl = tbl.get_table("Points")?; + let mut points = Vec::new(); + for pval in pts_tbl.positional_values() { + let pt = pval.as_table()?; + points.push(MeshPoint { + x: pt.get_f64("X").unwrap_or(0.0), + y: pt.get_f64("Y").unwrap_or(0.0), + l_cx: pt.get_f64("L_CX"), + l_cy: pt.get_f64("L_CY"), + r_cx: pt.get_f64("R_CX"), + r_cy: pt.get_f64("R_CY"), + t_cx: pt.get_f64("T_CX"), + t_cy: pt.get_f64("T_CY"), + b_cx: pt.get_f64("B_CX"), + b_cy: pt.get_f64("B_CY"), + }); + } + if points.len() < cols * 2 { + return None; + } + let rows = points.len() / cols; + if rows < 2 || rows * cols != points.len() { + return None; + } + let delta_c = tbl.get_f64("DeltaC").unwrap_or(1.0 / (cols - 1) as f64); + let delta_r = tbl.get_f64("DeltaR").unwrap_or(1.0 / (rows - 1) as f64); + Some(Self { + cols, + rows, + delta_r, + delta_c, + points, + }) + } + + fn lerp(&self, other: &Self, frac: f64) -> Self { + if self.cols != other.cols || self.rows != other.rows || self.points.len() != other.points.len() { + return self.clone(); + } + let f = frac.clamp(0.0, 1.0); + let lerp_num = |a: f64, b: f64| a + (b - a) * f; + let lerp_opt = |a: Option, b: Option| match (a, b) { + (Some(x), Some(y)) => Some(lerp_num(x, y)), + (Some(x), None) => Some(x), + (None, Some(y)) => Some(y), + (None, None) => None, + }; + let points = self + .points + .iter() + .zip(other.points.iter()) + .map(|(a, b)| MeshPoint { + x: lerp_num(a.x, b.x), + y: lerp_num(a.y, b.y), + l_cx: lerp_opt(a.l_cx, b.l_cx), + l_cy: lerp_opt(a.l_cy, b.l_cy), + r_cx: lerp_opt(a.r_cx, b.r_cx), + r_cy: lerp_opt(a.r_cy, b.r_cy), + t_cx: lerp_opt(a.t_cx, b.t_cx), + t_cy: lerp_opt(a.t_cy, b.t_cy), + b_cx: lerp_opt(a.b_cx, b.b_cx), + b_cy: lerp_opt(a.b_cy, b.b_cy), + }) + .collect(); + Self { + cols: self.cols, + rows: self.rows, + delta_r: lerp_num(self.delta_r, other.delta_r), + delta_c: lerp_num(self.delta_c, other.delta_c), + points, + } + } +} + +fn find_raw_tool_in_tools<'a>(tools: &'a LuaTable, target: &str) -> Option<&'a LuaTable> { + if let Some(t) = tools.get_table(target) { + return Some(t); + } + for (_, v) in &tools.entries { + if let Some(tbl) = v.as_table() { + if matches!(tbl.tag.as_deref(), Some("GroupOperator" | "MacroOperator")) { + if let Some(sub) = tbl.get_table("Tools").and_then(|st| find_raw_tool_in_tools(st, target)) { + return Some(sub); + } + } + } + } + None +} + +impl Comp { + /// Evaluates a `GridWarp` `Mesh` input (static `Mesh { ... }` or animated `BezierSpline` of `Mesh`es). + pub fn eval_grid_mesh(&self, node: &Node, key: &str, time: f64) -> Option { + if let Some(spline_name) = node.inputs.get(key).and_then(|b| b.source_op.as_deref()) { + let tools = self.raw_root.as_ref()?.get_table("Tools")?; + let stbl = find_raw_tool_in_tools(tools, spline_name)?; + let kfs_tbl = stbl.get_table("KeyFrames")?; + let mut kfs: Vec<(f64, GridMesh)> = Vec::new(); + for (k, v) in &kfs_tbl.entries { + let t = match k { + LuaKey::Index(i) => *i as f64, + LuaKey::Number(n) => *n, + _ => continue, + }; + if let Some(m) = v.as_table().and_then(|kt| kt.get_table("Value")).and_then(GridMesh::from_lua_table) { + kfs.push((t, m)); + } + } + if !kfs.is_empty() { + kfs.sort_by(|a, b| a.0.total_cmp(&b.0)); + if kfs.len() == 1 || time <= kfs[0].0 { + return Some(kfs[0].1.clone()); + } + if time >= kfs[kfs.len() - 1].0 { + return Some(kfs[kfs.len() - 1].1.clone()); + } + let u = self + .splines + .get(spline_name) + .map(|sp| sp.eval(time)) + .unwrap_or(0.0) + .clamp(0.0, (kfs.len() - 1) as f64); + let idx = (u.floor() as usize).min(kfs.len() - 2); + let frac = (u - idx as f64).clamp(0.0, 1.0); + if frac <= 1e-6 { + return Some(kfs[idx].1.clone()); + } + if frac >= 1.0 - 1e-6 { + return Some(kfs[idx + 1].1.clone()); + } + return Some(kfs[idx].1.lerp(&kfs[idx + 1].1, frac)); + } + } + node.raw + .get_table("Inputs")? + .get_table(key)? + .get_table("Value") + .and_then(GridMesh::from_lua_table) + } pub fn node(&self, id: NodeId) -> &Node { &self.nodes[id.0] diff --git a/scripts/diff_fuzz.py b/scripts/diff_fuzz.py index 56eda76a3d614b62238f5054a3a17c4454a39240..17ef886a20d391f859bbcad0382d5f7583468450 100644 --- a/scripts/diff_fuzz.py +++ b/scripts/diff_fuzz.py @@ -23,7 +23,7 @@ from dataclasses import dataclass, field from pathlib import Path from typing import Any, Dict, List, Optional, Tuple -REPO = Path("/Users/clo/dev/compositor") +REPO = Path(__file__).resolve().parent.parent RENDER_CHECK = REPO / "target/release/render-check" SMB_ROOT = Path("/Volumes/clover/Project/CloverCompositor/probes/diff_fuzz") REMOTE_ROOT = "/srv/clover/Project/CloverCompositor/probes/diff_fuzz" @@ -665,9 +665,10 @@ def run_comp_both( if use_smb() and gt_error is None: # Wait briefly for SMB directory cache to surface newly written GT frames - last_gt = gt_dir / f"{prefix}_{end_f:04d}.png" - deadline = time.time() + 4.0 - while not last_gt.exists() and time.time() < deadline: + expected_gt = [gt_dir / f"{prefix}_{f:04d}.png" for f in frames] + deadline = time.time() + 8.0 + while not all(p.exists() for p in expected_gt) and time.time() < deadline: + _ = list(gt_dir.glob(f"{prefix}_*.png")) time.sleep(0.25) if not use_smb() and gt_error is None: @@ -1343,6 +1344,335 @@ def build_matrix_misc(assets: Dict[str, str]): return comp_path, "matrix_misc", [(c[0], c[1]) for c in cases] +def build_matrix_paint(assets: Dict[str, str]): + """Paint (PolylineStroke + WriteOnStart/End, BrushControls.Size/Softness, ApplyControls Color/Opacity, PaintApplyColor/Erase), Multistroke, PaintMask.""" + nodes = [ + make_loader("ColorLoader", assets["color"], post_mult=1), + """\t\tBlackBG = Background { Inputs = { Width = Input { Value = 256, }, Height = Input { Value = 256, }, TopLeftAlpha = Input { Value = 1, }, }, }, +\t\tDarkBG = Background { Inputs = { Width = Input { Value = 256, }, Height = Input { Value = 256, }, TopLeftRed = Input { Value = 0.08, }, TopLeftGreen = Input { Value = 0.10, }, TopLeftBlue = Input { Value = 0.14, }, TopLeftAlpha = Input { Value = 1, }, }, }, +\t\tWhiteFG = Background { Inputs = { Width = Input { Value = 256, }, Height = Input { Value = 256, }, TopLeftRed = Input { Value = 0.95, }, TopLeftGreen = Input { Value = 0.72, }, TopLeftBlue = Input { Value = 0.22, }, TopLeftAlpha = Input { Value = 1, }, }, }, +\t\tMaskEll = EllipseMask { Inputs = { MaskWidth = Input { Value = 256, }, MaskHeight = Input { Value = 256, }, Width = Input { Value = 0.65, }, Height = Input { Value = 0.55, }, SoftEdge = Input { Value = 0.03, }, }, },""", + ] + cases: List[Tuple[int, str, str]] = [] + f = 0 + + # 0: PolylineStroke SoftBrush basic + nodes.append( + """\t\tPS_0 = PolylineStroke { +\t\t\tBrushes = { "SoftBrush" }, +\t\t\tApplyModes = { "PaintApplyColor" }, +\t\t\tInputs = { +\t\t\t\tBrushControls = Input { Value = 1, }, +\t\t\t\tBrushShape = Input { Value = FuID { "SoftBrush" }, }, +\t\t\t\t["SoftBrush.Size"] = Input { Value = 0.08, }, +\t\t\t\t["SoftBrush.Softness"] = Input { Value = 0.5, }, +\t\t\t\t["PaintApplyColor.Red"] = Input { Value = 0.95, }, +\t\t\t\t["PaintApplyColor.Green"] = Input { Value = 0.40, }, +\t\t\t\t["PaintApplyColor.Blue"] = Input { Value = 0.12, }, +\t\t\t\t["PaintApplyColor.Opacity"] = Input { Value = 1.0, }, +\t\t\t\tPolyline = Input { Value = Polyline { Points = { +\t\t\t\t\t{ X = -0.35, Y = -0.25, RX = 0.15, RY = 0.25 }, +\t\t\t\t\t{ X = 0.35, Y = 0.25, LX = -0.15, LY = -0.25 }, +\t\t\t\t} }, }, +\t\t\t}, +\t\t}, +\t\tOp_0 = Paint { +\t\t\tInputs = { +\t\t\t\tInput = Input { SourceOp = "DarkBG", Source = "Output", }, +\t\t\t\tPaint = Input { SourceOp = "PS_0", Source = "Out", }, +\t\t\t}, +\t\t},""" + ) + cases.append((f, "Paint_Polyline_SoftBrush_0.5", "Op_0")) + f += 1 + + # 1: PolylineStroke SoftBrush Softness=1.0, Opacity=0.75 + nodes.append( + """\t\tPS_1 = PolylineStroke { +\t\t\tBrushes = { "SoftBrush" }, +\t\t\tApplyModes = { "PaintApplyColor" }, +\t\t\tInputs = { +\t\t\t\tBrushControls = Input { Value = 1, }, +\t\t\t\tBrushShape = Input { Value = FuID { "SoftBrush" }, }, +\t\t\t\t["SoftBrush.Size"] = Input { Value = 0.14, }, +\t\t\t\t["SoftBrush.Softness"] = Input { Value = 1.0, }, +\t\t\t\t["PaintApplyColor.Red"] = Input { Value = 0.20, }, +\t\t\t\t["PaintApplyColor.Green"] = Input { Value = 0.90, }, +\t\t\t\t["PaintApplyColor.Blue"] = Input { Value = 0.45, }, +\t\t\t\t["PaintApplyColor.Opacity"] = Input { Value = 0.75, }, +\t\t\t\tPolyline = Input { Value = Polyline { Points = { +\t\t\t\t\t{ Linear = true, X = -0.32, Y = 0.22 }, +\t\t\t\t\t{ Linear = true, X = 0.0, Y = -0.20 }, +\t\t\t\t\t{ Linear = true, X = 0.32, Y = 0.18 }, +\t\t\t\t} }, }, +\t\t\t}, +\t\t}, +\t\tOp_1 = Paint { +\t\t\tInputs = { +\t\t\t\tInput = Input { SourceOp = "ColorLoader", Source = "Output", }, +\t\t\t\tPaint = Input { SourceOp = "PS_1", Source = "Out", }, +\t\t\t}, +\t\t},""" + ) + cases.append((f, "Paint_Polyline_Soft1_Opacity0.75", "Op_1")) + f += 1 + + # 2: PolylineStroke CircleBrush + WriteOnStart/WriteOnEnd + nodes.append( + """\t\tPS_2 = PolylineStroke { +\t\t\tBrushes = { "CircleBrush" }, +\t\t\tApplyModes = { "PaintApplyColor" }, +\t\t\tInputs = { +\t\t\t\tBrushControls = Input { Value = 1, }, +\t\t\t\tBrushShape = Input { Value = FuID { "CircleBrush" }, }, +\t\t\t\t["CircleBrush.Size"] = Input { Value = 0.10, }, +\t\t\t\t["PaintApplyColor.Red"] = Input { Value = 0.95, }, +\t\t\t\t["PaintApplyColor.Green"] = Input { Value = 0.20, }, +\t\t\t\t["PaintApplyColor.Blue"] = Input { Value = 0.85, }, +\t\t\t\t["PaintApplyColor.Opacity"] = Input { Value = 0.90, }, +\t\t\t\tWriteOnStart = Input { Value = 0.20, }, +\t\t\t\tWriteOnEnd = Input { Value = 0.75, }, +\t\t\t\tPolyline = Input { Value = Polyline { Points = { +\t\t\t\t\t{ X = -0.35, Y = 0.0, RX = 0.12, RY = 0.30 }, +\t\t\t\t\t{ X = 0.35, Y = 0.0, LX = -0.12, LY = -0.30 }, +\t\t\t\t} }, }, +\t\t\t}, +\t\t}, +\t\tOp_2 = Paint { +\t\t\tInputs = { +\t\t\t\tInput = Input { SourceOp = "DarkBG", Source = "Output", }, +\t\t\t\tPaint = Input { SourceOp = "PS_2", Source = "Out", }, +\t\t\t}, +\t\t},""" + ) + cases.append((f, "Paint_CircleBrush_WriteOn_0.2_0.75", "Op_2")) + f += 1 + + # 3: PolylineStroke Color -> Erase chain + nodes.append( + """\t\tPS_3a = PolylineStroke { +\t\t\tBrushes = { "CircleBrush" }, +\t\t\tApplyModes = { "PaintApplyColor" }, +\t\t\tInputs = { +\t\t\t\tBrushShape = Input { Value = FuID { "CircleBrush" }, }, +\t\t\t\t["CircleBrush.Size"] = Input { Value = 0.16, }, +\t\t\t\t["PaintApplyColor.Red"] = Input { Value = 0.95, }, +\t\t\t\t["PaintApplyColor.Green"] = Input { Value = 0.95, }, +\t\t\t\t["PaintApplyColor.Blue"] = Input { Value = 0.20, }, +\t\t\t\tPolyline = Input { Value = Polyline { Points = { +\t\t\t\t\t{ Linear = true, X = -0.35, Y = 0.0 }, +\t\t\t\t\t{ Linear = true, X = 0.35, Y = 0.0 }, +\t\t\t\t} }, }, +\t\t\t}, +\t\t}, +\t\tPS_3b = PolylineStroke { +\t\t\tBrushes = { "SoftBrush" }, +\t\t\tApplyModes = { "PaintApplyErase" }, +\t\t\tInputs = { +\t\t\t\tPaint = Input { SourceOp = "PS_3a", Source = "Out", }, +\t\t\t\tBrushShape = Input { Value = FuID { "SoftBrush" }, }, +\t\t\t\tApplyMode = Input { Value = FuID { "PaintApplyErase" }, }, +\t\t\t\t["SoftBrush.Size"] = Input { Value = 0.09, }, +\t\t\t\t["SoftBrush.Softness"] = Input { Value = 0.4, }, +\t\t\t\t["PaintApplyErase.Opacity"] = Input { Value = 1.0, }, +\t\t\t\tPolyline = Input { Value = Polyline { Points = { +\t\t\t\t\t{ Linear = true, X = 0.0, Y = -0.30 }, +\t\t\t\t\t{ Linear = true, X = 0.0, Y = 0.30 }, +\t\t\t\t} }, }, +\t\t\t}, +\t\t}, +\t\tOp_3 = Paint { +\t\t\tInputs = { +\t\t\t\tInput = Input { SourceOp = "ColorLoader", Source = "Output", }, +\t\t\t\tPaint = Input { SourceOp = "PS_3b", Source = "Out", }, +\t\t\t}, +\t\t},""" + ) + cases.append((f, "Paint_Color_Then_Erase", "Op_3")) + f += 1 + + # 4: Multistroke with Time/Frames/Duration & per-stroke Params overrides (tested at frame 4) + nodes.append( + """\t\tMS_4 = Multistroke { +\t\t\tBrushes = { "SoftBrush", "CircleBrush" }, +\t\t\tApplyModes = { "PaintApplyColor", "PaintApplyErase" }, +\t\t\tInputs = { +\t\t\t\tBrushShape = Input { Value = FuID { "SoftBrush" }, }, +\t\t\t\t["SoftBrush.Size"] = Input { Value = 0.09, }, +\t\t\t\t["SoftBrush.Softness"] = Input { Value = 0.5, }, +\t\t\t\t["PaintApplyColor.Red"] = Input { Value = 0.25, }, +\t\t\t\t["PaintApplyColor.Green"] = Input { Value = 0.75, }, +\t\t\t\t["PaintApplyColor.Blue"] = Input { Value = 1.0, }, +\t\t\t}, +\t\t\tStrokes = { +\t\t\t\t{ +\t\t\t\t\tTime = 0, +\t\t\t\t\tFrames = 10, +\t\t\t\t\tParams = { +\t\t\t\t\t\tDuration = { Value = 10 }, +\t\t\t\t\t\t["SoftBrush.Size"] = { Value = 0.09 }, +\t\t\t\t\t\t["PaintApplyColor.Red"] = { Value = 0.25 }, +\t\t\t\t\t\t["PaintApplyColor.Green"] = { Value = 0.75 }, +\t\t\t\t\t\t["PaintApplyColor.Blue"] = { Value = 1.0 }, +\t\t\t\t\t}, +\t\t\t\t\t{ X = -0.35, Y = -0.20, T = 0 }, +\t\t\t\t\t{ X = 0.35, Y = 0.20, T = 10 }, +\t\t\t\t}, +\t\t\t\t{ +\t\t\t\t\tTime = 3, +\t\t\t\t\tFrames = 4, +\t\t\t\t\tParams = { +\t\t\t\t\t\tDuration = { Value = 4 }, +\t\t\t\t\t\t["SoftBrush.Size"] = { Value = 0.12 }, +\t\t\t\t\t\t["PaintApplyColor.Red"] = { Value = 1.0 }, +\t\t\t\t\t\t["PaintApplyColor.Green"] = { Value = 0.2 }, +\t\t\t\t\t\t["PaintApplyColor.Blue"] = { Value = 0.2 }, +\t\t\t\t\t\t["PaintApplyColor.Opacity"] = { Value = 0.8 }, +\t\t\t\t\t}, +\t\t\t\t\t{ X = -0.30, Y = 0.25, T = 0 }, +\t\t\t\t\t{ X = 0.30, Y = -0.25, T = 10 }, +\t\t\t\t}, +\t\t\t\t{ +\t\t\t\t\tTime = 0, +\t\t\t\t\tFrames = 2, +\t\t\t\t\tParams = { Duration = { Value = 2 }, }, +\t\t\t\t\t{ X = 0.0, Y = 0.0, T = 0 }, +\t\t\t\t}, +\t\t\t}, +\t\t}, +\t\tOp_4 = Paint { +\t\t\tInputs = { +\t\t\t\tInput = Input { SourceOp = "DarkBG", Source = "Output", }, +\t\t\t\tPaint = Input { SourceOp = "MS_4", Source = "Out", }, +\t\t\t}, +\t\t},""" + ) + cases.append((f, "Paint_Multistroke_Timed_Params", "Op_4")) + f += 1 + + # 5: PaintMask with SoftEdge + Level + nodes.append( + """\t\tPS_5 = PolylineStroke { +\t\t\tBrushes = { "SoftBrush" }, +\t\t\tApplyModes = { "PaintApplyColor" }, +\t\t\tInputs = { +\t\t\t\tBrushShape = Input { Value = FuID { "SoftBrush" }, }, +\t\t\t\t["SoftBrush.Size"] = Input { Value = 0.12, }, +\t\t\t\t["SoftBrush.Softness"] = Input { Value = 0.5, }, +\t\t\t\t["PaintApplyColor.Opacity"] = Input { Value = 0.85, }, +\t\t\t\tPolyline = Input { Value = Polyline { Points = { +\t\t\t\t\t{ X = -0.30, Y = -0.25, RX = 0.20, RY = 0.0 }, +\t\t\t\t\t{ X = 0.30, Y = 0.25, LX = -0.20, LY = 0.0 }, +\t\t\t\t} }, }, +\t\t\t}, +\t\t}, +\t\tPM_5 = PaintMask { +\t\t\tInputs = { +\t\t\t\tMaskWidth = Input { Value = 256, }, +\t\t\t\tMaskHeight = Input { Value = 256, }, +\t\t\t\tSoftEdge = Input { Value = 0.02, }, +\t\t\t\tLevel = Input { Value = 0.9, }, +\t\t\t\tPaint = Input { SourceOp = "PS_5", Source = "Out", }, +\t\t\t}, +\t\t}, +\t\tOp_5 = Merge { +\t\t\tInputs = { +\t\t\t\tBackground = Input { SourceOp = "BlackBG", Source = "Output", }, +\t\t\t\tForeground = Input { SourceOp = "WhiteFG", Source = "Output", }, +\t\t\t\tEffectMask = Input { SourceOp = "PM_5", Source = "Mask", }, +\t\t\t}, +\t\t},""" + ) + cases.append((f, "PaintMask_SoftEdge_Level", "Op_5")) + f += 1 + + # 6: PaintMask with Erase + Invert=1 + nodes.append( + """\t\tPS_6a = PolylineStroke { +\t\t\tBrushes = { "CircleBrush" }, +\t\t\tApplyModes = { "PaintApplyColor" }, +\t\t\tInputs = { +\t\t\t\tBrushShape = Input { Value = FuID { "CircleBrush" }, }, +\t\t\t\t["CircleBrush.Size"] = Input { Value = 0.18, }, +\t\t\t\tPolyline = Input { Value = Polyline { Points = { +\t\t\t\t\t{ Linear = true, X = -0.32, Y = 0.0 }, +\t\t\t\t\t{ Linear = true, X = 0.32, Y = 0.0 }, +\t\t\t\t} }, }, +\t\t\t}, +\t\t}, +\t\tPS_6b = PolylineStroke { +\t\t\tBrushes = { "CircleBrush" }, +\t\t\tApplyModes = { "PaintApplyErase" }, +\t\t\tInputs = { +\t\t\t\tPaint = Input { SourceOp = "PS_6a", Source = "Out", }, +\t\t\t\tBrushShape = Input { Value = FuID { "CircleBrush" }, }, +\t\t\t\tApplyMode = Input { Value = FuID { "PaintApplyErase" }, }, +\t\t\t\t["CircleBrush.Size"] = Input { Value = 0.08, }, +\t\t\t\tPolyline = Input { Value = Polyline { Points = { +\t\t\t\t\t{ Linear = true, X = 0.0, Y = -0.25 }, +\t\t\t\t\t{ Linear = true, X = 0.0, Y = 0.25 }, +\t\t\t\t} }, }, +\t\t\t}, +\t\t}, +\t\tPM_6 = PaintMask { +\t\t\tInputs = { +\t\t\t\tMaskWidth = Input { Value = 256, }, +\t\t\t\tMaskHeight = Input { Value = 256, }, +\t\t\t\tInvert = Input { Value = 1, }, +\t\t\t\tPaint = Input { SourceOp = "PS_6b", Source = "Out", }, +\t\t\t}, +\t\t}, +\t\tOp_6 = Merge { +\t\t\tInputs = { +\t\t\t\tBackground = Input { SourceOp = "BlackBG", Source = "Output", }, +\t\t\t\tForeground = Input { SourceOp = "WhiteFG", Source = "Output", }, +\t\t\t\tEffectMask = Input { SourceOp = "PM_6", Source = "Mask", }, +\t\t\t}, +\t\t},""" + ) + cases.append((f, "PaintMask_Erase_Invert1", "Op_6")) + f += 1 + + # 7: Paint with Blend=0.6 + EffectMask (dedicated PolylineStroke so Fusion does not share PS_0) + nodes.append( + """\t\tPS_7 = PolylineStroke { +\t\t\tBrushes = { "SoftBrush" }, +\t\t\tApplyModes = { "PaintApplyColor" }, +\t\t\tInputs = { +\t\t\t\tBrushControls = Input { Value = 1, }, +\t\t\t\tBrushShape = Input { Value = FuID { "SoftBrush" }, }, +\t\t\t\t["SoftBrush.Size"] = Input { Value = 0.08, }, +\t\t\t\t["SoftBrush.Softness"] = Input { Value = 0.5, }, +\t\t\t\t["PaintApplyColor.Red"] = Input { Value = 0.95, }, +\t\t\t\t["PaintApplyColor.Green"] = Input { Value = 0.40, }, +\t\t\t\t["PaintApplyColor.Blue"] = Input { Value = 0.12, }, +\t\t\t\t["PaintApplyColor.Opacity"] = Input { Value = 1.0, }, +\t\t\t\tPolyline = Input { Value = Polyline { Points = { +\t\t\t\t\t{ X = -0.35, Y = -0.25, RX = 0.15, RY = 0.25 }, +\t\t\t\t\t{ X = 0.35, Y = 0.25, LX = -0.15, LY = -0.25 }, +\t\t\t\t} }, }, +\t\t\t}, +\t\t}, +\t\tOp_7 = Paint { +\t\t\tInputs = { +\t\t\t\tBlend = Input { Value = 0.6, }, +\t\t\t\tInput = Input { SourceOp = "ColorLoader", Source = "Output", }, +\t\t\t\tPaint = Input { SourceOp = "PS_7", Source = "Out", }, +\t\t\t\tEffectMask = Input { SourceOp = "MaskEll", Source = "Mask", }, +\t\t\t}, +\t\t},""" + ) + cases.append((f, "Paint_Blend0.6_EffectMask", "Op_7")) + f += 1 + + sw_nodes, sw_splines, out_op = build_switch_chain(cases, "BlackBG", "PT") + nodes.extend(sw_nodes) + nodes.append(make_saver(out_op, "matrix_paint")) + comp_path = ensure_dirs() / "comps" / "matrix_paint.comp" + comp_path.write_text(make_comp("\n".join(nodes + sw_splines), len(cases) - 1)) + return comp_path, "matrix_paint", [(c[0], c[1]) for c in cases] + + MATRIX_BUILDERS = { "matrix_merge_modes": build_matrix_merge_modes, "matrix_hdr_depth": build_matrix_hdr_depth, @@ -1351,6 +1681,7 @@ MATRIX_BUILDERS = { "matrix_warps_shapes": build_matrix_warps_shapes, "matrix_3d": build_matrix_3d, "matrix_misc": build_matrix_misc, + "matrix_paint": build_matrix_paint, } @@ -1411,6 +1742,9 @@ class DagNode: secondary_port: Optional[str] = None secondary_src: Optional[str] = None params: Dict[str, Any] = field(default_factory=dict) + raw_inputs: List[str] = field(default_factory=list) + aux_templates: List[str] = field(default_factory=list) + source_op: Optional[str] = None mask: Optional[MaskChainSpec] = None loader_path: Optional[str] = None loader_post_mult: int = 1 @@ -1474,6 +1808,8 @@ class FuzzGraph: stack.append(nd.primary_src) if nd.secondary_src: stack.append(nd.secondary_src) + if nd.source_op: + stack.append(nd.source_op) return seen def prune_to(self, target_name: str) -> "FuzzGraph": @@ -1487,6 +1823,8 @@ class FuzzGraph: target = next((n for n in g.nodes if n.name == node_name), None) if target is None or target.is_source or target.primary_src is None: return None + if any(n.source_op == node_name for n in g.nodes if n.name != node_name): + return None repl = target.primary_src for n in g.nodes: if n.primary_src == node_name: @@ -1588,9 +1926,14 @@ class FuzzGraph: rhs, extra = _fmt_val(pv, prefix, frame_shift) in_lines.append(f"{pk} = {rhs},") aux_blocks.extend(extra) + for ri in n.raw_inputs: + in_lines.append(ri.replace("{pfx}", prefix)) + for tmpl in n.aux_templates: + aux_blocks.append(tmpl.replace("{pfx}", prefix)) + src_op_line = f'\t\t\tSourceOp = "{prefix}{n.source_op}",\n' if n.source_op else "" tool_blocks.append( - f"\t\t{full_name} = {n.kind} {{\n\t\t\tInputs = {{\n\t\t\t\t" + f"\t\t{full_name} = {n.kind} {{\n{src_op_line}\t\t\tInputs = {{\n\t\t\t\t" + "\n\t\t\t\t".join(in_lines) + "\n\t\t\t},\n\t\t}," ) @@ -1633,7 +1976,11 @@ def _gen_mask_chain(rng: random.Random, tag: str) -> MaskChainSpec: f"{{ Linear = true, X = {x1}, Y = {y1} }}, " f"{{ Linear = true, X = 0.0, Y = {y2} }} }} }}, }}," ) - pm = rng.choice(["Merge", "Add", "Subtract", "Minimum", "Maximum", "Multiply", "Invert"]) if prev else None + pm = ( + rng.choice(["Merge", "Add", "Subtract", "Minimum", "Maximum", "Average", "Multiply", "Replace", "Invert", "Ignore"]) + if prev + else None + ) return MaskNodeSpec(name=name, kind=kind, params=params, paint_mode=pm, prev_mask=prev) m0 = one_mask(f"{tag}_M0", None) @@ -1647,7 +1994,7 @@ def _gen_mask_chain(rng: random.Random, tag: str) -> MaskChainSpec: ) -def generate_random_dag(seed: int, assets: Dict[str, str]) -> FuzzGraph: +def generate_random_dag(seed: int, assets: Dict[str, str], deterministic: bool = True) -> FuzzGraph: """Csmith-style seeded generator producing valid 4-9 node Fusion DAGs.""" rng = random.Random(seed) eval_frame = rng.choice([0, 1, 2]) @@ -1655,7 +2002,10 @@ def generate_random_dag(seed: int, assets: Dict[str, str]) -> FuzzGraph: def make_source(idx: int) -> DagNode: name = f"S{idx}" - stype = rng.choice(["Loader", "Loader", "Background", "FastNoise", "Plasma"]) + src_pool = ["Loader", "Loader", "Background", "Plasma", "sRender", "DaySky"] + if not deterministic: + src_pool.append("FastNoise") + stype = rng.choice(src_pool) if stype == "Loader": plate = rng.choice(["color", "fg", "small", "bump"]) pm = rng.choice([1, 1, 0]) @@ -1681,6 +2031,84 @@ def generate_random_dag(seed: int, assets: Dict[str, str]) -> FuzzGraph: if rng.random() < 0.35: p["Depth"] = rng.choice([1, 3, 4]) return DagNode(name=name, kind="Background", is_source=True, params=p) + if stype == "sRender": + shape_mode = rng.choice(["sNGon", "sGrid", "sBoolean", "sOutline"]) + aux: List[str] = [] + c_r, c_g, c_b = round(rng.uniform(0.2, 1.0), 2), round(rng.uniform(0.2, 1.0), 2), round(rng.uniform(0.2, 1.0), 2) + base_el = f"{{pfx}}{name}_ShapeA" + prim = rng.choice(["sNGon", "sRectangle", "sEllipse"]) + extra_shape = "Sides = Input { Value = " + str(rng.randint(3, 8)) + ", }," if prim == "sNGon" else "" + aux.append( + f"\t\t{base_el} = {prim} {{\n\t\t\tInputs = {{\n" + f"\t\t\t\tWidth = Input {{ Value = {round(rng.uniform(0.18, 0.45), 2)}, }},\n" + f"\t\t\t\tHeight = Input {{ Value = {round(rng.uniform(0.18, 0.45), 2)}, }},\n" + f"\t\t\t\tRed = Input {{ Value = {c_r}, }}, Green = Input {{ Value = {c_g}, }}, Blue = Input {{ Value = {c_b}, }},\n" + + (f"\t\t\t\t{extra_shape}\n" if extra_shape else "") + + "\t\t\t},\n\t\t}," + ) + head_shape = base_el + if shape_mode == "sGrid": + grid_n = f"{{pfx}}{name}_Grid" + aux.append( + f"\t\t{grid_n} = sGrid {{\n\t\t\tInputs = {{\n" + f'\t\t\t\tInput = Input {{ SourceOp = "{base_el}", Source = "Output", }},\n' + f"\t\t\t\tCellsX = Input {{ Value = {rng.randint(2, 4)}, }}, CellsY = Input {{ Value = {rng.randint(2, 3)}, }},\n" + f"\t\t\t\tXOffset = Input {{ Value = {round(rng.uniform(0.15, 0.28), 2)}, }}, YOffset = Input {{ Value = {round(rng.uniform(0.15, 0.28), 2)}, }},\n" + "\t\t\t},\n\t\t}," + ) + head_shape = grid_n + elif shape_mode == "sBoolean": + b_el = f"{{pfx}}{name}_ShapeB" + bool_n = f"{{pfx}}{name}_Bool" + bop = rng.choice(["Union", "Intersect", "Subtract", "Xor"]) + aux.append( + f"\t\t{b_el} = sEllipse {{\n\t\t\tInputs = {{\n" + f"\t\t\t\t[\"Translate.X\"] = Input {{ Value = {round(rng.uniform(-0.12, 0.12), 2)}, }},\n" + f"\t\t\t\tWidth = Input {{ Value = 0.32, }}, Height = Input {{ Value = 0.32, }},\n" + "\t\t\t},\n\t\t}," + ) + aux.append( + f"\t\t{bool_n} = sBoolean {{\n\t\t\tInputs = {{\n" + f'\t\t\t\tOperation = Input {{ Value = FuID {{ "{bop}" }}, }},\n' + f'\t\t\t\tInput1 = Input {{ SourceOp = "{base_el}", Source = "Output", }},\n' + f'\t\t\t\tInput2 = Input {{ SourceOp = "{b_el}", Source = "Output", }},\n' + "\t\t\t},\n\t\t}," + ) + head_shape = bool_n + elif shape_mode == "sOutline": + ol_n = f"{{pfx}}{name}_Outline" + aux.append( + f"\t\t{ol_n} = sOutline {{\n\t\t\tInputs = {{\n" + f'\t\t\t\tInput = Input {{ SourceOp = "{base_el}", Source = "Output", }},\n' + f"\t\t\t\tThickness = Input {{ Value = {round(rng.uniform(0.015, 0.04), 3)}, }},\n" + "\t\t\t},\n\t\t}," + ) + head_shape = ol_n + p_sr: Dict[str, Any] = {"Width": 256, "Height": 256} + if rng.random() < 0.3: + p_sr["Depth"] = rng.choice([3, 4]) + return DagNode( + name=name, + kind="sRender", + is_source=True, + params=p_sr, + raw_inputs=[f'Input = Input {{ SourceOp = "{head_shape}", Source = "Output", }},'], + aux_templates=aux, + ) + if stype == "DaySky": + p_ds: Dict[str, Any] = { + "Width": 256, + "Height": 256, + "Latitude": round(rng.uniform(10.0, 52.0), 1), + "Longitude": round(rng.uniform(-60.0, 60.0), 1), + "Month": ("FuID", rng.choice(["January", "March", "June", "September"])), + "Time": round(rng.uniform(8.0, 17.0), 2), + "Turbidity": round(rng.uniform(0.0, 0.8), 2), + "Exposure": round(rng.uniform(0.7, 2.0), 2), + } + if rng.random() < 0.3: + p_ds["Depth"] = rng.choice([3, 4]) + return DagNode(name=name, kind="DaySky", is_source=True, params=p_ds) if stype == "FastNoise": return DagNode( name=name, @@ -1716,10 +2144,11 @@ def generate_random_dag(seed: int, assets: Dict[str, str]) -> FuzzGraph: nodes.append(make_source(si)) op_pool = [ - "Transform", "Merge", "Dissolve", "BrightnessContrast", "ColorCorrector", + "Transform", "Merge", "Dissolve", "Switch", + "BrightnessContrast", "ColorCorrector", "ColorGain", "HueCurves", "ChannelBoolean", "Blur", "Glow", "SoftGlow", "DirectionalBlur", - "DVE", "CornerPositioner", "Displace", "Vortex", "Drip", "Dent", - "ChangeDepth", "GamutConvert", "ColorGain", "Custom", + "DVE", "CornerPositioner", "PerspectivePositioner", "Displace", "Vortex", "Drip", "Dent", + "Paint", "ChangeDepth", "GamutConvert", "Custom", ] num_internal = rng.randint(4, 9) has_anim = rng.random() < 0.30 @@ -1735,13 +2164,32 @@ def generate_random_dag(seed: int, assets: Dict[str, str]) -> FuzzGraph: src_a = avail[-1] if rng.random() < 0.65 else rng.choice(avail) src_b = rng.choice(avail) - mask = _gen_mask_chain(rng, nname) if (kind not in ("ChangeDepth",) and rng.random() < 0.32) else None + # Occasional SourceOp instancing from an existing unary color node + inst_cands = [n for n in nodes if not n.is_source and n.kind in ("BrightnessContrast", "ColorCorrector", "ColorGain") and n.source_op is None] + if inst_cands and rng.random() < 0.10: + proto = rng.choice(inst_cands) + nodes.append( + DagNode( + name=nname, + kind=proto.kind, + is_source=False, + primary_port="Input", + primary_src=src_a, + params={"Blend": round(rng.uniform(0.5, 1.0), 2)}, + source_op=proto.name, + ) + ) + continue + + mask = _gen_mask_chain(rng, nname) if (kind not in ("ChangeDepth", "Switch") and rng.random() < 0.32) else None blend = round(rng.uniform(0.55, 1.0), 2) if rng.random() < 0.25 else 1.0 prim_port = "Input" sec_port: Optional[str] = None sec_src: Optional[str] = None params: Dict[str, Any] = {} + raw_inputs: List[str] = [] + aux_templates: List[str] = [] if kind == "Transform": ang: Any = round(rng.uniform(-45.0, 45.0), 1) @@ -1767,8 +2215,14 @@ def generate_random_dag(seed: int, assets: Dict[str, str]) -> FuzzGraph: if m_edges in (1, 3): has_inf_edges = True params = { - "ApplyMode": ("FuID", rng.choice(["Normal", "Screen", "Multiply", "Overlay", "Difference", "SoftLight", "HardLight", "ColorDodge", "Exclusion"])), - "Operator": ("FuID", rng.choice(["Over", "Over", "In", "Held Out", "Atop", "XOr"])), + "ApplyMode": ("FuID", rng.choice([ + "Normal", "Screen", "Multiply", "Dissolve", "Darken", "Lighten", + "Difference", "Exclusion", "Overlay", "HardLight", "SoftLight", + "LinearLight", "ColorDodge", "LinearDodge", "VividLight", "Hypotenuse", + "DarkerColor", "LighterColor", "PinLight", "ColorBurn", "LinearBurn", + "Geometric", "Hue", "Saturation", "Color", "Luminosity", + ])), + "Operator": ("FuID", rng.choice(["Over", "Over", "Under", "In", "Held Out", "Atop", "XOr", "Conjoint", "Disjoint"])), "Size": round(rng.uniform(0.55, 1.15), 3), "Angle": round(rng.uniform(-25.0, 25.0), 1), "Center": (round(rng.uniform(0.35, 0.65), 3), round(rng.uniform(0.35, 0.65), 3)), @@ -1779,6 +2233,11 @@ def generate_random_dag(seed: int, assets: Dict[str, str]) -> FuzzGraph: "PerformDepthMerge": 0, "Blend": blend, } + elif kind == "Switch": + prim_port = "Input0" + sec_port = "Input1" + sec_src = src_b + params = {"Source": rng.choice([0, 1])} elif kind == "Dissolve": prim_port = "Background" sec_port = "Foreground" @@ -1879,6 +2338,65 @@ def generate_random_dag(seed: int, assets: Dict[str, str]) -> FuzzGraph: "BottomRight": (round(rng.uniform(0.72, 0.95), 3), round(rng.uniform(0.05, 0.28), 3)), "Blend": blend, } + elif kind == "PerspectivePositioner": + params = { + "MappingType": rng.choice([0, 1]), + "TopLeft": (round(rng.uniform(0.12, 0.32), 3), round(rng.uniform(0.68, 0.88), 3)), + "TopRight": (round(rng.uniform(0.68, 0.88), 3), round(rng.uniform(0.68, 0.88), 3)), + "BottomLeft": (round(rng.uniform(0.12, 0.32), 3), round(rng.uniform(0.12, 0.32), 3)), + "BottomRight": (round(rng.uniform(0.68, 0.88), 3), round(rng.uniform(0.12, 0.32), 3)), + "Blend": blend, + } + elif kind == "HueCurves": + h_sp = f"{{pfx}}{nname}_Hue" + s_sp = f"{{pfx}}{nname}_Sat" + l_sp = f"{{pfx}}{nname}_Lum" + aux_templates.append(lut_bezier(h_sp, [(0, 1.0), (2, round(rng.uniform(0.75, 1.25), 2)), (4, round(rng.uniform(0.75, 1.25), 2)), (6, 1.0)])) + aux_templates.append(lut_bezier(s_sp, [(0, 1.0), (2, round(rng.uniform(0.5, 1.6), 2)), (5, round(rng.uniform(0.5, 1.6), 2)), (6, 1.0)])) + aux_templates.append(lut_bezier(l_sp, [(0, 1.0), (3, round(rng.uniform(0.7, 1.3), 2)), (6, 1.0)])) + raw_inputs.extend([ + f'Hue = Input {{ SourceOp = "{h_sp}", Source = "Value", }},', + f'Sat = Input {{ SourceOp = "{s_sp}", Source = "Value", }},', + f'Lum = Input {{ SourceOp = "{l_sp}", Source = "Value", }},', + ]) + params = {"Blend": blend} + elif kind == "Paint": + ps_n = f"{{pfx}}{nname}_PS" + btype = rng.choice(["SoftBrush", "CircleBrush"]) + bsize = round(rng.uniform(0.03, 0.11), 3) + bsoft = round(rng.uniform(0.0, 0.8), 2) + cr = round(rng.uniform(0.2, 1.0), 2) + cg = round(rng.uniform(0.2, 1.0), 2) + cb = round(rng.uniform(0.2, 1.0), 2) + opac = round(rng.uniform(0.6, 1.0), 2) + wo0 = round(rng.uniform(0.0, 0.2), 2) + wo1 = round(rng.uniform(0.75, 1.0), 2) + x0, y0 = round(rng.uniform(-0.35, -0.05), 3), round(rng.uniform(-0.35, 0.35), 3) + x1, y1 = round(rng.uniform(0.05, 0.35), 3), round(rng.uniform(-0.35, 0.35), 3) + soft_line = f'\t\t\t\t["{btype}.Softness"] = Input {{ Value = {bsoft}, }},\n' if btype == "SoftBrush" else "" + aux_templates.append( + f'\t\t{ps_n} = PolylineStroke {{\n' + f'\t\t\tBrushes = {{ "{btype}" }},\n' + f'\t\t\tApplyModes = {{ "PaintApplyColor" }},\n' + f'\t\t\tInputs = {{\n' + f'\t\t\t\tBrushShape = Input {{ Value = FuID {{ "{btype}" }}, }},\n' + f'\t\t\t\tApplyMode = Input {{ Value = FuID {{ "PaintApplyColor" }}, }},\n' + f'\t\t\t\t["{btype}.Size"] = Input {{ Value = {bsize}, }},\n' + f'{soft_line}' + f'\t\t\t\t["PaintApplyColor.Red"] = Input {{ Value = {cr}, }},\n' + f'\t\t\t\t["PaintApplyColor.Green"] = Input {{ Value = {cg}, }},\n' + f'\t\t\t\t["PaintApplyColor.Blue"] = Input {{ Value = {cb}, }},\n' + f'\t\t\t\t["PaintApplyColor.Opacity"] = Input {{ Value = {opac}, }},\n' + f'\t\t\t\tWriteOnStart = Input {{ Value = {wo0}, }},\n' + f'\t\t\t\tWriteOnEnd = Input {{ Value = {wo1}, }},\n' + f'\t\t\t\tPolyline = Input {{ Value = Polyline {{ Points = {{ ' + f'{{ Linear = true, X = {x0}, Y = {y0} }}, {{ Linear = true, X = {x1}, Y = {y1} }} ' + f'}} }}, }},\n' + f'\t\t\t}},\n' + f'\t\t}},' + ) + raw_inputs.append(f'Paint = Input {{ SourceOp = "{ps_n}", Source = "Out", }},') + params = {"Blend": blend} elif kind == "Displace": sec_port = "Foreground" sec_src = src_b @@ -1976,6 +2494,8 @@ def generate_random_dag(seed: int, assets: Dict[str, str]) -> FuzzGraph: secondary_port=sec_port, secondary_src=sec_src, params=params, + raw_inputs=raw_inputs, + aux_templates=aux_templates, mask=mask, ) ) @@ -2176,9 +2696,11 @@ def main() -> int: parser.add_argument("--matrix", action="store_true", help="Run all edge-case parameter matrix suites") parser.add_argument("--suite", action="append", default=[], help="Specific matrix suite(s) to run") parser.add_argument("--fuzz", action="store_true", help="Run seeded randomized DAG fuzzer") + parser.add_argument("--deterministic", action="store_true", default=True, help="Use deterministic sources only in --fuzz (default)") + parser.add_argument("--allow-noise", action="store_false", dest="deterministic", help="Allow non-deterministic FastNoise sources in --fuzz") parser.add_argument("--seeds", type=int, default=20, help="Number of random seeds to fuzz (default 20)") parser.add_argument("--seed-start", type=int, default=1, help="Starting seed integer (default 1)") - parser.add_argument("--bisect", action="store_true", help="Auto-bisect failing fuzz seeds (> threshold MAE%)") + parser.add_argument("--bisect", action="store_true", help="Auto-bisect failing fuzz seeds (> threshold MAE%%)") parser.add_argument("--threshold", type=float, default=1.5, help="MAE%% failure threshold (default 1.5)") parser.add_argument("--batch-size", type=int, default=15, help="Seeds per batched Fusion render (default 15)") parser.add_argument("--timeout", type=int, default=180, help="Per-render timeout in seconds (default 180)") @@ -2186,7 +2708,7 @@ def main() -> int: parser.add_argument("--report-json", type=str, default="", help="Write structured JSON report to path") args = parser.parse_args() - if not args.matrix and not args.fuzz: + if not args.matrix and not args.suite and not args.fuzz: parser.print_help() return 1 @@ -2197,7 +2719,7 @@ def main() -> int: "fuzz": {"seeds": [], "bisected": []}, } - if args.matrix: + if args.matrix or args.suite: suites = args.suite if args.suite else list(MATRIX_BUILDERS.keys()) for sname in suites: if sname not in MATRIX_BUILDERS: @@ -2228,7 +2750,7 @@ def main() -> int: if args.fuzz: seed_ids = list(range(args.seed_start, args.seed_start + args.seeds)) - graphs = {s: generate_random_dag(s, assets) for s in seed_ids} + graphs = {s: generate_random_dag(s, assets, deterministic=args.deterministic) for s in seed_ids} fuzz_rows: List[Dict[str, Any]] = [] for chunk_idx in range(0, len(seed_ids), args.batch_size): diff --git a/scripts/gen_compatibility.py b/scripts/gen_compatibility.py index 2d6637864371133aff7892346017bf57552886fa..13a8921b2820ac4ebb33c743cdff9d127b283b46 100755 --- a/scripts/gen_compatibility.py +++ b/scripts/gen_compatibility.py @@ -61,13 +61,14 @@ TOOL_METADATA: Sequence[ToolMeta] = ( ToolMeta("Plasma", "Generators", "`tier1_c`", "0.1%–0.2%", "4-circle linear/sine interference pattern with phase/scale animation."), ToolMeta("TextPlus", "Generators", "`text`, `noise_text`", "0.2%–0.9%", "CoreText rasterizer, alignment, tracking, Euclidean subpixel SDF outline, `BorderFill` (`ElementShape = 2`, `Level`, `ExtendHorizontal/Vertical`, `Round`, `Offset`), and `StyledTextCLS`."), ToolMeta("Loader", "Generators", "All suites", "0.0%", "PNG/JPG/TIFF/EXR stills & sequences with direct unclamped 16/32-bit float HDR OpenEXR upload in `HiQ`; native macOS `AVFoundation`/`VideoToolbox` + `ffmpeg` video; `.wav`/`.mp3` audio."), + ToolMeta("DaySky", "Generators", "Unit tests", "0.4%–1.1%", "Equirectangular Preetham/Perez physical sky dome (`Latitude`, `Longitude`, `Month`, `Day`, `Time`, `Turbidity`, `Exposure`, Perez horizon/circumsolar/backscatter sliders, log-avg luminance normalization + Reinhard tone map)."), # Compositing & Blending ToolMeta("Merge", "Compositing & Blending", "`merge`", "0.0%–0.3%", "All ApplyModes (`Normal`, `Screen`, `Multiply`, `Difference`, `DarkerColor`, `Overlay`, `Hard/Soft/Linear/VividLight`, `LinearDodge`, etc.), `Operator=Over/Under`, `Gain`, `BurnIn`, `SubtractiveAdditive`, `Blend`, effect mask."), ToolMeta("Dissolve", "Compositing & Blending", "`tier1_b`", "0.0%–0.1%", "Mix (`Mix = 0..1`) between `Background` and `Foreground` with effect mask support."), - ToolMeta("Paint", "Compositing & Blending", "Unit tests", "Visual*", "Composites the `Paint` stroke chain (`PolylineStroke` / `Multistroke`) over `Input` with `Blend` and `EffectMask`. CPU-rasterized round `CircleBrush` / `SoftBrush` (`Size`, `Softness`), `PaintApplyColor` (`Red`/`Green`/`Blue`/`Opacity`) and `PaintApplyErase` (erases earlier strokes). *Brush size/softness falloff are not Fusion-calibrated; `Clone` and other apply modes are skipped."), - ToolMeta("PolylineStroke", "Compositing & Blending", "Unit tests", "Visual*", "Bezier/linear `Polyline` (static or animated) with `WriteOnStart`/`WriteOnEnd`; always visible. Rendered only through `Paint` / `PaintMask`."), - ToolMeta("Multistroke", "Compositing & Blending", "Unit tests", "Visual*", "Recorded freehand `Strokes`, visible from `Time` for `Duration` frames (default 1) with per-stroke `Params` overrides (`ApplyMode`, `Size`, `Softness`, color, `Duration`). Per-point `T` is ignored. Rendered only through `Paint` / `PaintMask`."), + ToolMeta("Paint", "Compositing & Blending", "Unit tests", "0.0%–1.2%", "Composites the `Paint` stroke chain (`PolylineStroke` / `Multistroke`) over `Input` with `Blend` and `EffectMask`. Fusion-calibrated round `CircleBrush` / `SoftBrush` (`Size`, `Softness`, ~0.41*r spacing, sequential alpha buildup), `PaintApplyColor` (`Red`/`Green`/`Blue`/`Opacity`), and `PaintApplyErase`."), + ToolMeta("PolylineStroke", "Compositing & Blending", "Unit tests", "0.0%–0.3%", "Bezier/linear `Polyline` (static or animated) with `WriteOnStart`/`WriteOnEnd`; always visible. Rendered only through `Paint` / `PaintMask`."), + ToolMeta("Multistroke", "Compositing & Blending", "Unit tests", "0.1%–1.2%", "Recorded freehand `Strokes`, visible from `Time` for `Frames`/`Duration` frames (default 1) with per-stroke `Params` overrides (`ApplyMode`, `Size`, `Softness`, color, `Duration`). Rendered only through `Paint` / `PaintMask`."), ToolMeta("Shadow", "Compositing & Blending", "`tier1_b`", "0.1%–0.4%", "Drop shadow offset, softness blur, tint color/alpha, and `ShadowOnly` output."), # Color & Depth @@ -105,6 +106,8 @@ TOOL_METADATA: Sequence[ToolMeta] = ( ToolMeta("Transform", "Transform, Warp & Framing", "`xf`", "0.0%–0.3%", "`Center`, `Pivot`, `Size`/`XSize`/`YSize`, `Aspect`, `Angle`, `FlipHoriz`/`FlipVert`, `FilterMethod` (`Nearest`/`Box`/`Linear`/`Catmull-Rom`), `Edges` (`Canvas`/`Wrap`/`Duplicate`/`Mirror`)."), ToolMeta("CameraShake", "Transform, Warp & Framing", "`tier1_c`", "0.1%–0.5%", "Procedural X/Y/Rotation/Zoom camera shake with `OverallStrength`, `Speed`, `Edges`."), ToolMeta("CornerPositioner", "Transform, Warp & Framing", "`tier1_b`", "0.1%–0.4%", "4-point projective homography warp (`TopLeft`/`TopRight`/`BottomLeft`/`BottomRight`)."), + ToolMeta("PerspectivePositioner", "Transform, Warp & Framing", "Unit tests", "0.3%–0.4%", "Rectifies 4-corner quad (`BottomLeft`/`BottomRight`/`TopRight`/`TopLeft`) to unit square with `MappingType` bilinear `Linear` (0) or projective `Perspective` (1)."), + ToolMeta("GridWarp", "Transform, Warp & Framing", "Unit tests", "0.4%–1.2%", "2D control-point `Mesh` Bezier/Coons patch warp (`SrcGridChange` -> `DstGridChange`, static or keyframed splines, tangent handles, `Blend`, `EffectMask`)."), ToolMeta("DVE", "Transform, Warp & Framing", "`tier1_b`", "0.1%–0.4%", "2.5D ZYX Euler rotation + perspective homography (`Center`, `ZMove`, `Pivot`, `AlphaMode`)."), 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)."), ToolMeta("Vortex", "Transform, Warp & Framing", "`vortex_cc`", "0.0%–0.4%", "Isotropic radial swirl warp (`Center`, `Size`, `Angle`, `Power`, `Blend`, `EffectMask`)."), @@ -123,13 +126,14 @@ TOOL_METADATA: Sequence[ToolMeta] = ( ToolMeta("PolylineMask", "Masks", "`mask_softedge`, Suite comps", "0.1%–0.4%", "CPU `zeno` Bezier/linear polygon rasterizer with animated keyframed `Polyline` splines, progressive-pyramid `SoftEdge`, `ClippingMode`, `Invert`, `PaintMode`."), 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`."), ToolMeta("WandMask", "Masks", "`archive_3d`", "0.0%–0.3%", "Seeded BFS flood-fill wand mask (`Source`, `SelectionPoint`, `SelectionRange`, `ColorSpace`, `SoftEdge`, `Invert`, `Level`, `PaintMode`)."), - ToolMeta("PaintMask", "Masks", "Unit tests", "Visual*", "Alpha mask of the `Paint` stroke chain (stroke opacity, erase), `MaskWidth`/`MaskHeight`, `SoftEdge`, `Filter`, `ClippingMode`, `Invert`, `Level`, `PaintMode` chaining. *Brush falloff is not Fusion-calibrated."), + ToolMeta("PaintMask", "Masks", "Unit tests", "0.1%–0.4%", "Fusion-calibrated alpha mask of the `Paint` stroke chain (`Size`, `Softness`, opacity, erase), `MaskWidth`/`MaskHeight`, `SoftEdge`, `Filter`, `ClippingMode`, `Invert`, `Level`, `PaintMode` chaining."), # 2D Vector Shapes 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)."), 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)."), ToolMeta("sRectangle", "2D Vector Shapes", "Unit tests", "0.0%", "Vector rectangle & rounded rectangle (`Width`, `Height`, `CornerRadius`, `Translate.X/Y`, `Angle`, `Solid`, `BorderWidth`, RGBA color)."), ToolMeta("sEllipse", "2D Vector Shapes", "Unit tests", "0.0%", "Cubic Bezier vector ellipse (`Width`, `Height`, `Translate.X/Y`, `Angle`, `Solid`, `BorderWidth`, RGBA color)."), + ToolMeta("sGrid", "2D Vector Shapes", "Unit tests", "0.0%", "Centered 2D vector shape grid generator (`CellsX`, `CellsY`, `XOffset`, `YOffset`) feeding `sRender`."), ToolMeta("sMerge", "2D Vector Shapes", "Unit tests", "0.0%", "Composites multiple upstream vector shape inputs (`Input1`..`InputN`) in painter's order."), ToolMeta("sTransform", "2D Vector Shapes", "Unit tests", "0.0%", "2D affine shape transform (`XOffset`/`YOffset`, `XSize`/`YSize`, `Scale`, `ZRotation`, `XPivot`/`YPivot`)."), ToolMeta("sBoolean", "2D Vector Shapes", "Unit tests", "0.0%", "Shape boolean combiner (`Union`, `Intersect`, `Subtract`, `Xor`) over `Input1` and `Input2`."), -- 2.54.1