| author | |
| committer | |
| log | 0d6ea513d427faa903a9f69c47c492564c9f90b3 |
| tree | 32034874984b00fa3ed37718b560d6239d545dcf |
| parent | 34ea37f66436efdb2c3afa20c7b79f0ff7e3dd9f |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
11 files changed, 3264 insertions(+), 246 deletions(-)
compatibility.md+11-10| ... | ... | @@ -9,10 +9,10 @@ Auto-generated from live engine sources (`crates/engine/src/eval.rs`, `crates/en |
| 9 | 9 | |
| 10 | 10 | | Metric | Value | |
| 11 | 11 | | --- | --- | |
| 12 | | **Supported Flow Tools** | **79** (70 2D/Fuse/utility in `eval.rs`, 7 3D scene nodes in `scene3d.rs`, 2 Flow annotations) | | |
| 12 | | **Supported Flow Tools** | **80** (71 2D/Fuse/utility in `eval.rs`, 7 3D scene nodes in `scene3d.rs`, 2 Flow annotations) | | |
| 13 | 13 | | **Modifiers & Animation** | **7** systems (8 Fusion modifier classes + Lua expressions) | |
| 14 | | **Active Corpus (`trees/fusion`) Coverage** | **99.3%** (1,980 / 1,993 nodes across 16 `.comp` files) | | |
| 15 | | **Archive Corpus (`private/samples`) Coverage** | **96.1%** (52,825 / 54,955 nodes across 324 `.comp` files) | | |
| 14 | | **Active Corpus (`trees/fusion`) Coverage** | **99.4%** (1,981 / 1,993 nodes across 16 `.comp` files) | | |
| 15 | | **Archive Corpus (`private/samples`) Coverage** | **96.1%** (52,826 / 54,955 nodes across 324 `.comp` files) | | |
| 16 | 16 | | **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. | |
| 17 | 17 | |
| 18 | 18 | ## Generators |
| ... | ... | @@ -38,7 +38,7 @@ Auto-generated from live engine sources (`crates/engine/src/eval.rs`, `crates/en |
| 38 | 38 | | Tool | Probe Suite | Verified MAE | Usage (Active / Archive) | Notes & Fallbacks | |
| 39 | 39 | | --- | --- | --- | --- | --- | |
| 40 | 40 | | `BrightnessContrast` | `color_ops`, `tier1_d` | 0.0%–0.1% | 29 / 231 | Gain, Lift, Gamma, Contrast, Brightness, Saturation, channel toggles, `PreDividePostMultiply`, `ClipBlack`/`ClipWhite`. | |
| 41 | | `ColorCorrector` | Suite comps | 0.1%–0.5% | 86 / 1357 | Master/Shadow/Midtone/Highlight wheel tint, Lift/Gamma/Gain/Brightness/Contrast/Saturation, `PreDividePostMultiply`. | | |
| 41 | | `ColorCorrector` | `vortex_cc`, Suite comps | 0.0%–0.4% | 86 / 1357 | Master/Shadow/Midtone/Highlight wheels, exact Fusion 21.1 `TintMode` (`0`/`1`/`2`), Lift/Gamma/Gain/Brightness/Contrast/Saturation, `PreDividePostMultiply`. | | |
| 42 | 42 | | `ColorGain` | `color_ops`, `noise_text` | 0.0%–0.1% | 2 / 4 | Per-channel Gain, Lift, Gamma, Hue, Saturation, `PreDividePostMultiply`. | |
| 43 | 43 | | `ColorCurves` | Suite comps | 0.1%–0.4% | 5 / 109 | Per-channel RGBA `LUTBezier` spline lookup tables with `PreDividePostMultiply`. | |
| 44 | 44 | | `HueCurves` | `tier1_a` | 0.1%–0.5% | 6 / 28 | 9 nested `LUTBezier` splines (Hue/Sat/Lum vs Hue, Suppression, etc.) baked to GPU LUT. | |
| ... | ... | @@ -53,7 +53,7 @@ Auto-generated from live engine sources (`crates/engine/src/eval.rs`, `crates/en |
| 53 | 53 | | Tool | Probe Suite | Verified MAE | Usage (Active / Archive) | Notes & Fallbacks | |
| 54 | 54 | | --- | --- | --- | --- | --- | |
| 55 | 55 | | `LumaKeyer` | Suite comps | 0.1%–0.4% | 4 / 95 | Luminance/channel threshold keying with low/high feathering and matte inversion. | |
| 56 | | `UltraKeyer` | `tier1_a` | 0.1%–0.6% | 16 / 66 | Chroma keying with background color pick, matte threshold/gamma, spill suppression, and post-multiply. | | |
| 56 | | `UltraKeyer` | `ultrakey`, `tier1_a` | 0.0%–0.1% | 16 / 66 | Exact Fusion 21.1 Ultimatte color-difference matte + background subtraction (`BackgroundRed/Green/Blue`, `LowMatteThreshold`/`High`, `MatteSeparation`, `SpillSuppression`, `PostMultiplyImage`). | | |
| 57 | 57 | | `Fuse.Cryptomatte` | Unit tests | 0.0% | 0 / 37 | Cryptomatte 1.2 multi-channel EXR matte extraction (manifest JSON + MurmurHash3-32 ID/coverage rank accumulation, wildcards, `MatteOnly`). | |
| 58 | 58 | |
| 59 | 59 | ## Blur, Sharpen & Glow |
| ... | ... | @@ -81,7 +81,8 @@ Auto-generated from live engine sources (`crates/engine/src/eval.rs`, `crates/en |
| 81 | 81 | | `CameraShake` | `tier1_c` | 0.1%–0.5% | 0 / 12 | Procedural X/Y/Rotation/Zoom camera shake with `OverallStrength`, `Speed`, `Edges`. | |
| 82 | 82 | | `CornerPositioner` | `tier1_b` | 0.1%–0.4% | 0 / 29 | 4-point projective homography warp (`TopLeft`/`TopRight`/`BottomLeft`/`BottomRight`). | |
| 83 | 83 | | `DVE` | `tier1_b` | 0.1%–0.4% | 4 / 22 | 2.5D ZYX Euler rotation + perspective homography (`Center`, `ZMove`, `Pivot`, `AlphaMode`). | |
| 84 | | `Displace` | `displace` | 0.0%–0.1% | 11 / 109 | `XY` refraction (channels, offsets, refraction strength) and `Radial`/`Bump` (`LightPower`, `LightAngle`, `LightChannel` additive directional slope lighting). | | |
| 84 | | `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). | | |
| 85 | | `Vortex` | `vortex_cc` | 0.0%–0.4% | 1 / 1 | Isotropic radial swirl warp (`Center`, `Size`, `Angle`, `Power`, `Blend`, `EffectMask`). | | |
| 85 | 86 | | `Scale` | Suite comps | 0.0%–0.2% | 12 / 98 | Proportional/non-proportional image scaling with resampling filter. | |
| 86 | 87 | | `BetterResize` | Suite comps | 0.0%–0.2% | 0 / 93 | Target pixel-dimension resize (`Width`, `Height`, `KeepAspect`). | |
| 87 | 88 | | `Crop` | Suite comps | 0.0%–0.1% | 3 / 168 | Region crop & canvas repositioning (`XOffset`, `YOffset`, `XSize`, `YSize`, `KeepCentered`). | |
| ... | ... | @@ -91,10 +92,10 @@ Auto-generated from live engine sources (`crates/engine/src/eval.rs`, `crates/en |
| 91 | 92 | |
| 92 | 93 | | Tool | Probe Suite | Verified MAE | Usage (Active / Archive) | Notes & Fallbacks | |
| 93 | 94 | | --- | --- | --- | --- | --- | |
| 94 | | `EllipseMask` | `mask` | 0.0%–0.2% | 33 / 109 | Center, Width, Height, Angle, `SoftEdge`, `BorderWidth`, `Solid`, `Invert`, `PaintMode` chaining. | | |
| 95 | | `RectangleMask` | `mask` | 0.0%–0.2% | 53 / 885 | Center, Width, Height, `CornerRadius`, Angle, `SoftEdge`, `BorderWidth`, `Solid`, `Invert`, `PaintMode` chaining. | | |
| 96 | | `PolylineMask` | Suite comps | 0.1%–0.5% | 16 / 505 | CPU `zeno` Bezier/linear polygon rasterizer with animated keyframed `Polyline` splines, `SoftEdge`, `Invert`, `PaintMode`. | | |
| 97 | | `BitmapMask` | Suite comps | 0.0%–0.2% | 3 / 121 | Image-to-mask extraction (`Alpha`/`Luminance`/`Red`/`Green`/`Blue`), `Low`/`High` clip, `SoftEdge`, `Invert`. | | |
| 95 | | `EllipseMask` | `mask`, `mask_softedge` | 0.0%–0.2% | 33 / 109 | Center, Width, Height, Angle, progressive-pyramid `SoftEdge`, `BorderWidth`, `Solid`, `Filter` (`Fast Gaussian`/`Box`), `ClippingMode`, `Invert`, `PaintMode` chaining. | | |
| 96 | | `RectangleMask` | `mask`, `mask_softedge` | 0.0%–0.2% | 53 / 885 | Center, Width, Height, `CornerRadius`, Angle, progressive-pyramid `SoftEdge`, `BorderWidth`, `Solid`, `Filter`, `ClippingMode`, `Invert`, `PaintMode` chaining. | | |
| 97 | | `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`. | | |
| 98 | | `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`. | | |
| 98 | 99 | |
| 99 | 100 | ## Particles |
| 100 | 101 |
crates/engine/src/cache.rs+3| ... | ... | @@ -27,6 +27,8 @@ pub struct CachedTexture { |
| 27 | 27 | pub depth: BitDepth, |
| 28 | 28 | /// Underlying GPU texture format (`Rgba8Unorm`, `Rgba16Float`, or `Rgba32Float`). |
| 29 | 29 | pub format: wgpu::TextureFormat, |
| 30 | /// Scale ratio `physical_px / logical_px` when an oversized generator (>8K) is capped to GPU limits (1.0 normally). | |
| 31 | pub tex_scale: f32, | |
| 30 | 32 | pub content_hash: u64, |
| 31 | 33 | pub bytes: u64, |
| 32 | 34 | } |
| ... | ... | @@ -76,6 +78,7 @@ impl CachedTexture { |
| 76 | 78 | canvas_size, |
| 77 | 79 | depth, |
| 78 | 80 | format, |
| 81 | tex_scale: 1.0, | |
| 79 | 82 | content_hash, |
| 80 | 83 | bytes, |
| 81 | 84 | } |
crates/engine/src/eval.rs+492-103| ... | ... | @@ -64,6 +64,7 @@ enum ShaderOp { |
| 64 | 64 | MaskShape, |
| 65 | 65 | MaskCombine, |
| 66 | 66 | MaskApply, |
| 67 | BitmapMask, | |
| 67 | 68 | Colorize, |
| 68 | 69 | ColorCurves, |
| 69 | 70 | XfChroma, |
| ... | ... | @@ -90,6 +91,7 @@ enum ShaderOp { |
| 90 | 91 | FilmGrain, |
| 91 | 92 | SetDomain, |
| 92 | 93 | ChangeDepth, |
| 94 | Vortex, | |
| 93 | 95 | } |
| 94 | 96 | |
| 95 | 97 | struct Pipelines { |
| ... | ... | @@ -109,6 +111,7 @@ struct Pipelines { |
| 109 | 111 | mask_shape: wgpu::ComputePipeline, |
| 110 | 112 | mask_combine: wgpu::ComputePipeline, |
| 111 | 113 | mask_apply: wgpu::ComputePipeline, |
| 114 | bitmap_mask: wgpu::ComputePipeline, | |
| 112 | 115 | colorize: wgpu::ComputePipeline, |
| 113 | 116 | color_curves: wgpu::ComputePipeline, |
| 114 | 117 | xf_chroma: wgpu::ComputePipeline, |
| ... | ... | @@ -135,6 +138,7 @@ struct Pipelines { |
| 135 | 138 | film_grain: wgpu::ComputePipeline, |
| 136 | 139 | set_domain: wgpu::ComputePipeline, |
| 137 | 140 | change_depth: wgpu::ComputePipeline, |
| 141 | vortex: wgpu::ComputePipeline, | |
| 138 | 142 | } |
| 139 | 143 | |
| 140 | 144 | impl Pipelines { |
| ... | ... | @@ -248,6 +252,7 @@ impl Pipelines { |
| 248 | 252 | mask_shape: make("mask_shape_op"), |
| 249 | 253 | mask_combine: make("mask_combine_op"), |
| 250 | 254 | mask_apply: make("mask_apply_op"), |
| 255 | bitmap_mask: make("bitmap_mask_op"), | |
| 251 | 256 | colorize: make("colorize_op"), |
| 252 | 257 | color_curves: make("color_curves_op"), |
| 253 | 258 | xf_chroma: make("xf_chroma_op"), |
| ... | ... | @@ -274,6 +279,7 @@ impl Pipelines { |
| 274 | 279 | film_grain: make("film_grain_op"), |
| 275 | 280 | set_domain: make("set_domain_op"), |
| 276 | 281 | change_depth: make("change_depth_op"), |
| 282 | vortex: make("vortex_op"), | |
| 277 | 283 | } |
| 278 | 284 | } |
| 279 | 285 | |
| ... | ... | @@ -293,6 +299,7 @@ impl Pipelines { |
| 293 | 299 | ShaderOp::MaskShape => &self.mask_shape, |
| 294 | 300 | ShaderOp::MaskCombine => &self.mask_combine, |
| 295 | 301 | ShaderOp::MaskApply => &self.mask_apply, |
| 302 | ShaderOp::BitmapMask => &self.bitmap_mask, | |
| 296 | 303 | ShaderOp::Colorize => &self.colorize, |
| 297 | 304 | ShaderOp::ColorCurves => &self.color_curves, |
| 298 | 305 | ShaderOp::XfChroma => &self.xf_chroma, |
| ... | ... | @@ -319,6 +326,7 @@ impl Pipelines { |
| 319 | 326 | ShaderOp::FilmGrain => &self.film_grain, |
| 320 | 327 | ShaderOp::SetDomain => &self.set_domain, |
| 321 | 328 | ShaderOp::ChangeDepth => &self.change_depth, |
| 329 | ShaderOp::Vortex => &self.vortex, | |
| 322 | 330 | } |
| 323 | 331 | } |
| 324 | 332 | } |
| ... | ... | @@ -441,6 +449,30 @@ impl Engine { |
| 441 | 449 | self.alloc_tex_dod(size, [0, 0], size, depth, content_hash) |
| 442 | 450 | } |
| 443 | 451 | |
| 452 | fn alloc_tex_like(&self, src: &CachedTexture, depth: BitDepth, content_hash: u64) -> CachedTexture { | |
| 453 | let mut t = self.alloc_tex_dod(src.size, src.origin, src.canvas_size, depth, content_hash); | |
| 454 | t.tex_scale = src.tex_scale; | |
| 455 | t | |
| 456 | } | |
| 457 | ||
| 458 | fn crop_to_canvas(&self, enc: &mut wgpu::CommandEncoder, tex: CachedTexture) -> CachedTexture { | |
| 459 | if !tex.has_dod() { | |
| 460 | return tex; | |
| 461 | } | |
| 462 | let mut cropped = self.alloc_tex(tex.canvas_size, tex.depth, tex.content_hash ^ 0xD0D0); | |
| 463 | cropped.tex_scale = tex.tex_scale; | |
| 464 | let mut params = UniformParams::default(); | |
| 465 | params.p[0] = [1.0, 1.0, 0.0, 0.0]; | |
| 466 | params.p[4] = [ | |
| 467 | tex.origin[0] as f32, | |
| 468 | tex.origin[1] as f32, | |
| 469 | tex.canvas_size[0] as f32, | |
| 470 | tex.canvas_size[1] as f32, | |
| 471 | ]; | |
| 472 | self.dispatch_op(enc, ShaderOp::DisplayBlit, &tex.view, &self.dummy.view, &self.dummy.view, &cropped, &params); | |
| 473 | cropped | |
| 474 | } | |
| 475 | ||
| 444 | 476 | fn alloc_tex_dod( |
| 445 | 477 | &self, |
| 446 | 478 | size: [u32; 2], |
| ... | ... | @@ -864,10 +896,11 @@ impl Engine { |
| 864 | 896 | "Plasma" => self.eval_plasma(comp, node, time, frame_i, comp_dims, enc, visiting, stats), |
| 865 | 897 | "FilmGrain" => self.eval_film_grain(comp, node, time, frame_i, enc, visiting, stats), |
| 866 | 898 | "Displace" => self.eval_displace(comp, node, time, frame_i, enc, visiting, stats), |
| 899 | "Vortex" => self.eval_vortex(comp, node, time, frame_i, enc, visiting, stats), | |
| 867 | 900 | "EllipseMask" => self.eval_mask_shape(comp, node, time, frame_i, comp_dims, 0, enc, visiting, stats), |
| 868 | 901 | "RectangleMask" => self.eval_mask_shape(comp, node, time, frame_i, comp_dims, 1, enc, visiting, stats), |
| 869 | 902 | "PolylineMask" => self.eval_polyline_mask(comp, node, time, frame_i, comp_dims, enc, visiting, stats), |
| 870 | "BitmapMask" => self.eval_bitmap_mask(comp, node, time, enc, visiting, stats), | |
| 903 | "BitmapMask" => self.eval_bitmap_mask(comp, node, time, frame_i, comp_dims, enc, visiting, stats), | |
| 871 | 904 | "TextPlus" => self.eval_text_plus(comp, node, time, frame_i, comp_dims, enc, stats), |
| 872 | 905 | "Fuse.Colorize" => self.eval_colorize(comp, node, time, frame_i, enc, visiting, stats), |
| 873 | 906 | "Fuse.Outline" => self.eval_outline(comp, node, time, frame_i, enc, visiting, stats), |
| ... | ... | @@ -1230,13 +1263,13 @@ impl Engine { |
| 1230 | 1263 | }; |
| 1231 | 1264 | |
| 1232 | 1265 | let out = if matte_only { |
| 1233 | let dst = self.alloc_tex(src.size, dst_depth, key); | |
| 1266 | let dst = self.alloc_tex_like(&src, dst_depth, key); | |
| 1234 | 1267 | let mut u = UniformParams::default(); |
| 1235 | 1268 | u.p[0] = [1.0, 1.0, 0.0, 0.0]; |
| 1236 | 1269 | self.dispatch_op(enc, ShaderOp::DisplayBlit, &matte_tex.view, &self.dummy.view, &self.dummy.view, &dst, &u); |
| 1237 | 1270 | dst |
| 1238 | 1271 | } else { |
| 1239 | let dst = self.alloc_tex(src.size, dst_depth, key); | |
| 1272 | let dst = self.alloc_tex_like(&src, dst_depth, key); | |
| 1240 | 1273 | let mut u = UniformParams::default(); |
| 1241 | 1274 | u.p[0] = [0.0, 0.0, 0.0, 0.0]; |
| 1242 | 1275 | self.dispatch_op(enc, ShaderOp::MaskApply, &src.view, &self.dummy.view, &matte_tex.view, &dst, &u); |
| ... | ... | @@ -1518,11 +1551,87 @@ impl Engine { |
| 1518 | 1551 | _ => 0.0, // Over |
| 1519 | 1552 | }; |
| 1520 | 1553 | |
| 1521 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(bg.size), enc, visiting, stats); | |
| 1554 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(bg.canvas_size), enc, visiting, stats); | |
| 1522 | 1555 | let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash); |
| 1523 | 1556 | |
| 1557 | let eff_size = size_s * (bg.tex_scale / fg.tex_scale.max(1e-4)); | |
| 1558 | ||
| 1559 | // Fusion Merge preserves/expands Domain of Definition (DoD) when FG extends outside BG | |
| 1560 | // (e.g. a grid of tiles placed partly above y=1.0 before a downstream Transform zooms out). | |
| 1561 | let bg_x0 = bg.origin[0]; | |
| 1562 | let bg_y0 = bg.origin[1]; | |
| 1563 | let bg_x1 = bg.origin[0] + bg.size[0] as i32; | |
| 1564 | let bg_y1 = bg.origin[1] + bg.size[1] as i32; | |
| 1565 | let mut dst_origin = bg.origin; | |
| 1566 | let mut dst_size = bg.size; | |
| 1567 | ||
| 1568 | if edges < 0.5 | |
| 1569 | && mask.is_none() | |
| 1570 | && mode_id == 0.0 | |
| 1571 | && (op_id == 0.0 || op_id == 1.0 || op_id == 5.0) | |
| 1572 | && bg.tex_scale >= 0.99 | |
| 1573 | && eff_size > 1e-4 | |
| 1574 | { | |
| 1575 | let bg_cw = bg.canvas_size[0].max(1) as f32; | |
| 1576 | let bg_ch = bg.canvas_size[1].max(1) as f32; | |
| 1577 | let fg_cw = fg.canvas_size[0].max(1) as f32; | |
| 1578 | let fg_ch = fg.canvas_size[1].max(1) as f32; | |
| 1579 | let u0 = fg.origin[0] as f32 / fg_cw; | |
| 1580 | let u1 = (fg.origin[0] + fg.size[0] as i32) as f32 / fg_cw; | |
| 1581 | let v0 = 1.0 - (fg.origin[1] + fg.size[1] as i32) as f32 / fg_ch; | |
| 1582 | let v1 = 1.0 - fg.origin[1] as f32 / fg_ch; | |
| 1583 | let ang = angle_deg.to_radians(); | |
| 1584 | let (ca, sa) = (ang.cos(), ang.sin()); | |
| 1585 | let mut fg_x0 = f32::INFINITY; | |
| 1586 | let mut fg_x1 = f32::NEG_INFINITY; | |
| 1587 | let mut fg_y0 = f32::INFINITY; | |
| 1588 | let mut fg_y1 = f32::NEG_INFINITY; | |
| 1589 | for &(fu, fv) in &[(u0, v0), (u1, v0), (u0, v1), (u1, v1)] { | |
| 1590 | let fu = if flip_h > 0.5 { 1.0 - fu } else { fu }; | |
| 1591 | let fv = if flip_v > 0.5 { 1.0 - fv } else { fv }; | |
| 1592 | let rx = (fu - 0.5) * fg_cw * eff_size; | |
| 1593 | let ry = (fv - 0.5) * fg_ch * eff_size; | |
| 1594 | let dx = rx * ca - ry * sa; | |
| 1595 | let dy = rx * sa + ry * ca; | |
| 1596 | let px = center[0] as f32 * bg_cw + dx; | |
| 1597 | let py = (1.0 - center[1] as f32) * bg_ch - dy; | |
| 1598 | fg_x0 = fg_x0.min(px); | |
| 1599 | fg_x1 = fg_x1.max(px); | |
| 1600 | fg_y0 = fg_y0.min(py); | |
| 1601 | fg_y1 = fg_y1.max(py); | |
| 1602 | } | |
| 1603 | let max_pad = 512_i32; | |
| 1604 | let ux0 = if fg_x0 < bg_x0 as f32 - 0.5 { | |
| 1605 | bg_x0.min((fg_x0.floor() as i32 - 2).max(-max_pad)) | |
| 1606 | } else { | |
| 1607 | bg_x0 | |
| 1608 | }; | |
| 1609 | let uy0 = if fg_y0 < bg_y0 as f32 - 0.5 { | |
| 1610 | bg_y0.min((fg_y0.floor() as i32 - 2).max(-max_pad)) | |
| 1611 | } else { | |
| 1612 | bg_y0 | |
| 1613 | }; | |
| 1614 | let ux1 = if fg_x1 > bg_x1 as f32 + 0.5 { | |
| 1615 | bg_x1.max((fg_x1.ceil() as i32 + 2).min(bg.canvas_size[0] as i32 + max_pad)) | |
| 1616 | } else { | |
| 1617 | bg_x1 | |
| 1618 | }; | |
| 1619 | let uy1 = if fg_y1 > bg_y1 as f32 + 0.5 { | |
| 1620 | bg_y1.max((fg_y1.ceil() as i32 + 2).min(bg.canvas_size[1] as i32 + max_pad)) | |
| 1621 | } else { | |
| 1622 | bg_y1 | |
| 1623 | }; | |
| 1624 | let uw = (ux1 - ux0).max(1) as u32; | |
| 1625 | let uh = (uy1 - uy0).max(1) as u32; | |
| 1626 | if uw <= 4096 && uh <= 4096 && (ux0 != bg_x0 || uy0 != bg_y0 || uw != bg.size[0] || uh != bg.size[1]) { | |
| 1627 | dst_origin = [ux0, uy0]; | |
| 1628 | dst_size = [uw, uh]; | |
| 1629 | } | |
| 1630 | } | |
| 1631 | let dst_has_dod = dst_origin != [0, 0] || dst_size != bg.canvas_size; | |
| 1632 | ||
| 1524 | 1633 | let mut u = UniformParams::default(); |
| 1525 | u.p[0] = [center[0] as f32, center[1] as f32, size_s, angle_deg.to_radians()]; | |
| 1634 | u.p[0] = [center[0] as f32, center[1] as f32, eff_size, angle_deg.to_radians()]; | |
| 1526 | 1635 | u.p[1] = [blend, gain, mode_id, edges]; |
| 1527 | 1636 | u.p[2] = [flip_h, flip_v, nearest, op_id]; |
| 1528 | 1637 | u.p[3] = [ |
| ... | ... | @@ -1539,20 +1648,25 @@ impl Engine { |
| 1539 | 1648 | fg.canvas_size[1] as f32, |
| 1540 | 1649 | ]; |
| 1541 | 1650 | } |
| 1542 | if bg.has_dod() { | |
| 1651 | if dst_has_dod { | |
| 1543 | 1652 | u.p[5] = [ |
| 1544 | bg.origin[0] as f32, | |
| 1545 | bg.origin[1] as f32, | |
| 1653 | dst_origin[0] as f32, | |
| 1654 | dst_origin[1] as f32, | |
| 1546 | 1655 | bg.canvas_size[0] as f32, |
| 1547 | 1656 | bg.canvas_size[1] as f32, |
| 1548 | 1657 | ]; |
| 1549 | 1658 | } |
| 1550 | u.p[6] = [burn_in, sub_add, 0.0, 0.0]; | |
| 1659 | u.p[6] = [ | |
| 1660 | burn_in, | |
| 1661 | sub_add, | |
| 1662 | (bg.origin[0] - dst_origin[0]) as f32, | |
| 1663 | (bg.origin[1] - dst_origin[1]) as f32, | |
| 1664 | ]; | |
| 1551 | 1665 | |
| 1552 | 1666 | let key = self.make_key( |
| 1553 | 1667 | node, |
| 1554 | 1668 | "Merge", |
| 1555 | bg.size, | |
| 1669 | dst_size, | |
| 1556 | 1670 | &[bg.content_hash, fg.content_hash, mask_hash], |
| 1557 | 1671 | bytemuck::cast_slice(&u.p[..7]), |
| 1558 | 1672 | ); |
| ... | ... | @@ -1563,7 +1677,8 @@ impl Engine { |
| 1563 | 1677 | stats.cache_misses += 1; |
| 1564 | 1678 | stats.nodes_evaluated += 1; |
| 1565 | 1679 | |
| 1566 | let dst = self.alloc_tex_dod(bg.size, bg.origin, bg.canvas_size, bg.depth.max(fg.depth), key); | |
| 1680 | let mut dst = self.alloc_tex_dod(dst_size, dst_origin, bg.canvas_size, bg.depth.max(fg.depth), key); | |
| 1681 | dst.tex_scale = bg.tex_scale; | |
| 1567 | 1682 | let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view); |
| 1568 | 1683 | self.dispatch_op(enc, ShaderOp::Merge, &bg.view, &fg.view, mv, &dst, &u); |
| 1569 | 1684 | self.cache.insert(key, dst.clone(), node.id, frame_i); |
| ... | ... | @@ -1740,6 +1855,7 @@ impl Engine { |
| 1740 | 1855 | if blend <= 1e-6 { |
| 1741 | 1856 | return src; |
| 1742 | 1857 | } |
| 1858 | let src = self.crop_to_canvas(enc, src); | |
| 1743 | 1859 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats); |
| 1744 | 1860 | let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash); |
| 1745 | 1861 | |
| ... | ... | @@ -1776,7 +1892,7 @@ impl Engine { |
| 1776 | 1892 | } |
| 1777 | 1893 | stats.cache_misses += 1; |
| 1778 | 1894 | stats.nodes_evaluated += 1; |
| 1779 | let dst = self.alloc_tex(src.size, src.depth, key); | |
| 1895 | let dst = self.alloc_tex_like(&src, src.depth, key); | |
| 1780 | 1896 | let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view); |
| 1781 | 1897 | self.dispatch_op(enc, ShaderOp::Bc, &src.view, &self.dummy.view, mv, &dst, &u); |
| 1782 | 1898 | self.cache.insert(key, dst.clone(), node.id, frame_i); |
| ... | ... | @@ -1801,6 +1917,7 @@ impl Engine { |
| 1801 | 1917 | if blend <= 1e-6 { |
| 1802 | 1918 | return src; |
| 1803 | 1919 | } |
| 1920 | let src = self.crop_to_canvas(enc, src); | |
| 1804 | 1921 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats); |
| 1805 | 1922 | let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash); |
| 1806 | 1923 | |
| ... | ... | @@ -1823,16 +1940,80 @@ impl Engine { |
| 1823 | 1940 | blend, |
| 1824 | 1941 | if mask.is_some() { 1.0 } else { 0.0 }, |
| 1825 | 1942 | ]; |
| 1826 | u.p[3] = [if mask_inv { 1.0 } else { 0.0 }, 0.0, 0.0, 0.0]; | |
| 1943 | // Fusion ColorCorrector TintMode: 0 = RGB cube tilt matrix, 1 = additive+luma tint, 2 (default when omitted) = luma-weighted tint. | |
| 1944 | let tint_mode = comp.eval_number(node, "TintMode", time, 2.0, &self.expr) as f32; | |
| 1945 | ||
| 1946 | // Shadows (2), Midtones (3), Highlights (4) wheels & LGG | |
| 1947 | u.p[4] = [ | |
| 1948 | comp.eval_number(node, "WheelHue2", time, 0.0, &self.expr) as f32, | |
| 1949 | comp.eval_number(node, "WheelSaturation2", time, 1.0, &self.expr) as f32, | |
| 1950 | comp.eval_number(node, "WheelTintAngle2", time, 0.0, &self.expr) as f32, | |
| 1951 | comp.eval_number(node, "WheelTintLength2", time, 0.0, &self.expr) as f32, | |
| 1952 | ]; | |
| 1953 | u.p[5] = [ | |
| 1954 | comp.eval_number(node, "ShadowsRGBGain", time, 1.0, &self.expr) as f32, | |
| 1955 | comp.eval_number(node, "ShadowsRGBLift", time, 0.0, &self.expr) as f32, | |
| 1956 | comp.eval_number(node, "ShadowsRGBGamma", time, 1.0, &self.expr) as f32, | |
| 1957 | comp.eval_number(node, "ShadowsRGBContrast", time, 1.0, &self.expr) as f32, | |
| 1958 | ]; | |
| 1959 | u.p[6] = [ | |
| 1960 | comp.eval_number(node, "WheelHue3", time, 0.0, &self.expr) as f32, | |
| 1961 | comp.eval_number(node, "WheelSaturation3", time, 1.0, &self.expr) as f32, | |
| 1962 | comp.eval_number(node, "WheelTintAngle3", time, 0.0, &self.expr) as f32, | |
| 1963 | comp.eval_number(node, "WheelTintLength3", time, 0.0, &self.expr) as f32, | |
| 1964 | ]; | |
| 1965 | u.p[7] = [ | |
| 1966 | comp.eval_number(node, "MidtonesRGBGain", time, 1.0, &self.expr) as f32, | |
| 1967 | comp.eval_number(node, "MidtonesRGBLift", time, 0.0, &self.expr) as f32, | |
| 1968 | comp.eval_number(node, "MidtonesRGBGamma", time, 1.0, &self.expr) as f32, | |
| 1969 | comp.eval_number(node, "MidtonesRGBContrast", time, 1.0, &self.expr) as f32, | |
| 1970 | ]; | |
| 1971 | u.p[8] = [ | |
| 1972 | comp.eval_number(node, "WheelHue4", time, 0.0, &self.expr) as f32, | |
| 1973 | comp.eval_number(node, "WheelSaturation4", time, 1.0, &self.expr) as f32, | |
| 1974 | comp.eval_number(node, "WheelTintAngle4", time, 0.0, &self.expr) as f32, | |
| 1975 | comp.eval_number(node, "WheelTintLength4", time, 0.0, &self.expr) as f32, | |
| 1976 | ]; | |
| 1977 | u.p[9] = [ | |
| 1978 | comp.eval_number(node, "HighlightsRGBGain", time, 1.0, &self.expr) as f32, | |
| 1979 | comp.eval_number(node, "HighlightsRGBLift", time, 0.0, &self.expr) as f32, | |
| 1980 | comp.eval_number(node, "HighlightsRGBGamma", time, 1.0, &self.expr) as f32, | |
| 1981 | comp.eval_number(node, "HighlightsRGBContrast", time, 1.0, &self.expr) as f32, | |
| 1982 | ]; | |
| 1983 | u.p[10] = [ | |
| 1984 | comp.eval_number(node, "ShadowsRGBBrightness", time, 0.0, &self.expr) as f32, | |
| 1985 | comp.eval_number(node, "MidtonesRGBBrightness", time, 0.0, &self.expr) as f32, | |
| 1986 | comp.eval_number(node, "HighlightsRGBBrightness", time, 0.0, &self.expr) as f32, | |
| 1987 | 0.0, | |
| 1988 | ]; | |
| 1989 | let wheel_is_active = |w: [f32; 4], lgg: [f32; 4], b: f32| -> bool { | |
| 1990 | w[0].abs() > 1e-5 | |
| 1991 | || (w[1] - 1.0).abs() > 1e-5 | |
| 1992 | || w[3].abs() > 1e-5 | |
| 1993 | || (lgg[0] - 1.0).abs() > 1e-5 | |
| 1994 | || lgg[1].abs() > 1e-5 | |
| 1995 | || (lgg[2] - 1.0).abs() > 1e-5 | |
| 1996 | || (lgg[3] - 1.0).abs() > 1e-5 | |
| 1997 | || b.abs() > 1e-5 | |
| 1998 | }; | |
| 1999 | let has_smh = wheel_is_active(u.p[4], u.p[5], u.p[10][0]) | |
| 2000 | || wheel_is_active(u.p[6], u.p[7], u.p[10][1]) | |
| 2001 | || wheel_is_active(u.p[8], u.p[9], u.p[10][2]); | |
| 2002 | u.p[3] = [ | |
| 2003 | if mask_inv { 1.0 } else { 0.0 }, | |
| 2004 | tint_mode, | |
| 2005 | if has_smh { 1.0 } else { 0.0 }, | |
| 2006 | 0.0, | |
| 2007 | ]; | |
| 1827 | 2008 | |
| 1828 | let key = self.make_key(node, "CC", src.size, &[src.content_hash, mask_hash], bytemuck::cast_slice(&u.p[..4])); | |
| 2009 | let key = self.make_key(node, "CC", src.size, &[src.content_hash, mask_hash], bytemuck::cast_slice(&u.p[..11])); | |
| 1829 | 2010 | if let Some(hit) = self.cache.get(key, node.id, frame_i) { |
| 1830 | 2011 | stats.cache_hits += 1; |
| 1831 | 2012 | return hit; |
| 1832 | 2013 | } |
| 1833 | 2014 | stats.cache_misses += 1; |
| 1834 | 2015 | stats.nodes_evaluated += 1; |
| 1835 | let dst = self.alloc_tex(src.size, src.depth, key); | |
| 2016 | let dst = self.alloc_tex_like(&src, src.depth, key); | |
| 1836 | 2017 | let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view); |
| 1837 | 2018 | self.dispatch_op(enc, ShaderOp::Cc, &src.view, &self.dummy.view, mv, &dst, &u); |
| 1838 | 2019 | self.cache.insert(key, dst.clone(), node.id, frame_i); |
| ... | ... | @@ -1872,7 +2053,7 @@ impl Engine { |
| 1872 | 2053 | } |
| 1873 | 2054 | stats.cache_misses += 1; |
| 1874 | 2055 | stats.nodes_evaluated += 1; |
| 1875 | let dst = self.alloc_tex(src.size, src.depth, key); | |
| 2056 | let dst = self.alloc_tex_like(&src, src.depth, key); | |
| 1876 | 2057 | let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view); |
| 1877 | 2058 | self.dispatch_op(enc, ShaderOp::LumaKey, &src.view, &self.dummy.view, mv, &dst, &u); |
| 1878 | 2059 | self.cache.insert(key, dst.clone(), node.id, frame_i); |
| ... | ... | @@ -1903,7 +2084,7 @@ impl Engine { |
| 1903 | 2084 | let y_raw = if lock_xy { |
| 1904 | 2085 | x_raw |
| 1905 | 2086 | } else { |
| 1906 | comp.eval_number(node, "YBlurSize", time, x_raw as f64, &self.expr) as f32 | |
| 2087 | comp.eval_number(node, "YBlurSize", time, 1.0, &self.expr) as f32 | |
| 1907 | 2088 | }; |
| 1908 | 2089 | let rx = x_raw * scale_ref * gauss_k; |
| 1909 | 2090 | let ry = y_raw * scale_ref * gauss_k; |
| ... | ... | @@ -1925,7 +2106,33 @@ impl Engine { |
| 1925 | 2106 | stats.cache_misses += 1; |
| 1926 | 2107 | stats.nodes_evaluated += 1; |
| 1927 | 2108 | |
| 1928 | let dst = self.alloc_tex_dod(src.size, src.origin, src.canvas_size, src.depth, key); | |
| 2109 | // When ClippingMode = "None" on an unmasked full-blend Blur, Fusion expands the DoD so the | |
| 2110 | // outer half of the Gaussian/Box falloff survives beyond the frame border for downstream Merges! | |
| 2111 | let expand_dod = clamp_edges < 0.5 && mask.is_none() && blend >= 0.999; | |
| 2112 | let (work_src, out_origin) = if expand_dod { | |
| 2113 | let pad_x = if rx >= 0.25 { (rx * 1.5).ceil().min(384.0) as u32 } else { 0 }; | |
| 2114 | let pad_y = if ry >= 0.25 { (ry * 1.5).ceil().min(384.0) as u32 } else { 0 }; | |
| 2115 | if pad_x > 0 || pad_y > 0 { | |
| 2116 | let exp_w = (src.size[0] + pad_x * 2).min(8192); | |
| 2117 | let exp_h = (src.size[1] + pad_y * 2).min(8192); | |
| 2118 | let actual_px = (exp_w.saturating_sub(src.size[0])) / 2; | |
| 2119 | let actual_py = (exp_h.saturating_sub(src.size[1])) / 2; | |
| 2120 | let exp_origin = [src.origin[0] - actual_px as i32, src.origin[1] - actual_py as i32]; | |
| 2121 | let padded = self.alloc_tex_dod([exp_w, exp_h], exp_origin, src.canvas_size, src.depth, 0); | |
| 2122 | let mut u_pad = UniformParams::default(); | |
| 2123 | u_pad.p[0] = [-100.0, -100.0, 100.0, 100.0]; | |
| 2124 | u_pad.p[1] = [exp_origin[0] as f32, exp_origin[1] as f32, src.canvas_size[0].max(1) as f32, src.canvas_size[1].max(1) as f32]; | |
| 2125 | u_pad.p[2] = [src.origin[0] as f32, src.origin[1] as f32, src.size[0] as f32, src.size[1] as f32]; | |
| 2126 | self.dispatch_op(enc, ShaderOp::SetDomain, &src.view, &self.dummy.view, &self.dummy.view, &padded, &u_pad); | |
| 2127 | (padded, exp_origin) | |
| 2128 | } else { | |
| 2129 | (src.clone(), src.origin) | |
| 2130 | } | |
| 2131 | } else { | |
| 2132 | (src.clone(), src.origin) | |
| 2133 | }; | |
| 2134 | ||
| 2135 | let dst = self.alloc_tex_dod(work_src.size, out_origin, src.canvas_size, src.depth, key); | |
| 1929 | 2136 | // Fast mode (`!self.hiq`): downsample large blurs to 1/2 or 1/4 pyramid level for 4-16x speedup! |
| 1930 | 2137 | let down = if self.hiq { |
| 1931 | 2138 | 1u32 |
| ... | ... | @@ -1938,14 +2145,14 @@ impl Engine { |
| 1938 | 2145 | }; |
| 1939 | 2146 | |
| 1940 | 2147 | if down > 1 { |
| 1941 | let work_size = [(src.size[0] / down).max(1), (src.size[1] / down).max(1)]; | |
| 2148 | let work_size = [(work_src.size[0] / down).max(1), (work_src.size[1] / down).max(1)]; | |
| 1942 | 2149 | let small = self.alloc_tex(work_size, src.depth, 0); |
| 1943 | 2150 | let tmp = self.alloc_tex(work_size, src.depth, 0); |
| 1944 | 2151 | let small_blur = self.alloc_tex(work_size, src.depth, 0); |
| 1945 | 2152 | |
| 1946 | 2153 | let mut u_blit = UniformParams::default(); |
| 1947 | 2154 | u_blit.p[0] = [1.0, 1.0, 0.0, 0.0]; |
| 1948 | self.dispatch_op(enc, ShaderOp::DisplayBlit, &src.view, &self.dummy.view, &self.dummy.view, &small, &u_blit); | |
| 2155 | self.dispatch_op(enc, ShaderOp::DisplayBlit, &work_src.view, &self.dummy.view, &self.dummy.view, &small, &u_blit); | |
| 1949 | 2156 | |
| 1950 | 2157 | let mut uh = UniformParams::default(); |
| 1951 | 2158 | uh.p[0] = [1.0, 0.0, rx / down as f32, mode]; |
| ... | ... | @@ -1963,23 +2170,23 @@ impl Engine { |
| 1963 | 2170 | let mut um = UniformParams::default(); |
| 1964 | 2171 | um.p[0] = [0.5, 0.5, 1.0, 0.0]; |
| 1965 | 2172 | um.p[1] = [blend, 1.0, 0.0, 0.0]; |
| 1966 | um.p[3] = [if mask.is_some() { 1.0 } else { 0.0 }, if mask_inv { 1.0 } else { 0.0 }, src.size[0] as f32, src.size[1] as f32]; | |
| 2173 | um.p[3] = [if mask.is_some() { 1.0 } else { 0.0 }, if mask_inv { 1.0 } else { 0.0 }, work_src.size[0] as f32, work_src.size[1] as f32]; | |
| 1967 | 2174 | let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view); |
| 1968 | self.dispatch_op(enc, ShaderOp::Merge, &src.view, &small_blur.view, mv, &dst, &um); | |
| 2175 | self.dispatch_op(enc, ShaderOp::Merge, &work_src.view, &small_blur.view, mv, &dst, &um); | |
| 1969 | 2176 | } |
| 1970 | 2177 | } else { |
| 1971 | let tmp = self.alloc_tex(src.size, src.depth, 0); | |
| 2178 | let tmp = self.alloc_tex(work_src.size, src.depth, 0); | |
| 1972 | 2179 | let mut uh = UniformParams::default(); |
| 1973 | 2180 | uh.p[0] = [1.0, 0.0, rx, mode]; |
| 1974 | 2181 | uh.p[1] = [1.0, 0.0, 0.0, clamp_edges]; |
| 1975 | self.dispatch_op(enc, ShaderOp::Blur, &src.view, &self.dummy.view, &self.dummy.view, &tmp, &uh); | |
| 2182 | self.dispatch_op(enc, ShaderOp::Blur, &work_src.view, &self.dummy.view, &self.dummy.view, &tmp, &uh); | |
| 1976 | 2183 | |
| 1977 | 2184 | let mut uv = UniformParams::default(); |
| 1978 | 2185 | uv.p[0] = [0.0, 1.0, ry, mode]; |
| 1979 | 2186 | uv.p[1] = [blend, if mask.is_some() { 1.0 } else { 0.0 }, if mask_inv { 1.0 } else { 0.0 }, clamp_edges]; |
| 1980 | 2187 | uv.p[2] = [1.0, 0.0, 0.0, 0.0]; // blend against original unblurred src in src_b! |
| 1981 | 2188 | let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view); |
| 1982 | self.dispatch_op(enc, ShaderOp::Blur, &tmp.view, &src.view, mv, &dst, &uv); | |
| 2189 | self.dispatch_op(enc, ShaderOp::Blur, &tmp.view, &work_src.view, mv, &dst, &uv); | |
| 1983 | 2190 | } |
| 1984 | 2191 | |
| 1985 | 2192 | self.cache.insert(key, dst.clone(), node.id, frame_i); |
| ... | ... | @@ -2004,6 +2211,7 @@ impl Engine { |
| 2004 | 2211 | if blend <= 1e-6 { |
| 2005 | 2212 | return src; |
| 2006 | 2213 | } |
| 2214 | let src = self.crop_to_canvas(enc, src); | |
| 2007 | 2215 | let kind = comp.eval_number(node, "Type", time, 0.0, &self.expr) as f32; |
| 2008 | 2216 | let len = comp.eval_number(node, "Length", time, 0.02, &self.expr) as f32; |
| 2009 | 2217 | let ang = (comp.eval_number(node, "Angle", time, 0.0, &self.expr) as f32).to_radians(); |
| ... | ... | @@ -2028,7 +2236,7 @@ impl Engine { |
| 2028 | 2236 | } |
| 2029 | 2237 | stats.cache_misses += 1; |
| 2030 | 2238 | stats.nodes_evaluated += 1; |
| 2031 | let dst = self.alloc_tex(src.size, src.depth, key); | |
| 2239 | let dst = self.alloc_tex_like(&src, src.depth, key); | |
| 2032 | 2240 | let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view); |
| 2033 | 2241 | self.dispatch_op(enc, ShaderOp::DirBlur, &src.view, &self.dummy.view, mv, &dst, &u); |
| 2034 | 2242 | self.cache.insert(key, dst.clone(), node.id, frame_i); |
| ... | ... | @@ -2053,6 +2261,7 @@ impl Engine { |
| 2053 | 2261 | if blend <= 1e-6 { |
| 2054 | 2262 | return src; |
| 2055 | 2263 | } |
| 2264 | let src = self.crop_to_canvas(enc, src); | |
| 2056 | 2265 | let is_soft_glow = node.kind == "SoftGlow"; |
| 2057 | 2266 | // Fusion SoftGlow/Glow sizes are in 720px-reference pixels; Glow's Gaussian kernel is |
| 2058 | 2267 | // slightly tighter (~0.86x) than SoftGlow's (~1.00x). |
| ... | ... | @@ -2179,6 +2388,7 @@ impl Engine { |
| 2179 | 2388 | if blend <= 1e-6 { |
| 2180 | 2389 | return src; |
| 2181 | 2390 | } |
| 2391 | let src = self.crop_to_canvas(enc, src); | |
| 2182 | 2392 | let prev_sz = self.mask_target_size; |
| 2183 | 2393 | self.mask_target_size = Some(src.size); |
| 2184 | 2394 | let glow_mask = node |
| ... | ... | @@ -2355,7 +2565,8 @@ impl Engine { |
| 2355 | 2565 | stats.cache_misses += 1; |
| 2356 | 2566 | stats.nodes_evaluated += 1; |
| 2357 | 2567 | let tmp = self.alloc_tex(src.size, src.depth, 0); |
| 2358 | let dst = self.alloc_tex_dod(src.size, src.origin, src.canvas_size, src.depth, key); | |
| 2568 | let mut dst = self.alloc_tex_dod(src.size, src.origin, src.canvas_size, src.depth, key); | |
| 2569 | dst.tex_scale = src.tex_scale; | |
| 2359 | 2570 | let mut uh = UniformParams::default(); |
| 2360 | 2571 | uh.p[0] = [1.0, 0.0, radius, mode]; |
| 2361 | 2572 | uh.p[1] = [1.0, 0.0, 0.0, 0.0]; |
| ... | ... | @@ -2386,8 +2597,10 @@ impl Engine { |
| 2386 | 2597 | // Cap giant procedural sky-dome FastNoise textures (e.g. 11520x4000) to 8192 in HiQ / 4096 in Fast |
| 2387 | 2598 | let cap = if self.hiq { 8192 } else { 4096 }; |
| 2388 | 2599 | let max_dim = size[0].max(size[1]); |
| 2600 | let mut tex_scale = 1.0_f32; | |
| 2389 | 2601 | if max_dim > cap { |
| 2390 | 2602 | let scale = cap as f32 / max_dim as f32; |
| 2603 | tex_scale = scale; | |
| 2391 | 2604 | size = [((size[0] as f32 * scale).round() as u32).max(1), ((size[1] as f32 * scale).round() as u32).max(1)]; |
| 2392 | 2605 | } |
| 2393 | 2606 | |
| ... | ... | @@ -2420,7 +2633,8 @@ impl Engine { |
| 2420 | 2633 | comp.eval_number(node, "Color2Blue", time, 1.0, &self.expr) as f32, |
| 2421 | 2634 | comp.eval_number(node, "Color2Alpha", time, 1.0, &self.expr) as f32, |
| 2422 | 2635 | ]; |
| 2423 | let grad = comp.eval_gradient(node, "Gradient", time); | |
| 2636 | let noise_type = comp.eval_number(node, "Type", time, 0.0, &self.expr).round() as i32; | |
| 2637 | let grad = if noise_type == 1 { comp.eval_gradient(node, "Gradient", time) } else { None }; | |
| 2424 | 2638 | |
| 2425 | 2639 | // Bake high-precision 256x1 RGBA gradient LUT so sharp thresholds (e.g. 0.95..0.96 stars) are exact! |
| 2426 | 2640 | let mut grad_bytes = [0u8; 256 * 4]; |
| ... | ... | @@ -2449,7 +2663,7 @@ impl Engine { |
| 2449 | 2663 | let mut u = UniformParams::default(); |
| 2450 | 2664 | u.p[0] = [x_scale, y_scale, detail, contrast]; |
| 2451 | 2665 | u.p[1] = [brightness, seethe, disc, center[0] as f32]; |
| 2452 | u.p[2] = [center[1] as f32, angle, inverted, 1.0]; | |
| 2666 | u.p[2] = [center[1] as f32, angle, inverted, if noise_type == 1 { 2.0 } else { 1.0 }]; | |
| 2453 | 2667 | |
| 2454 | 2668 | let key = self.make_key(node, "FastNoise", size, &[grad_hash], bytemuck::cast_slice(&u.p[..3])); |
| 2455 | 2669 | if let Some(hit) = self.cache.get(key, node.id, frame_i) { |
| ... | ... | @@ -2465,7 +2679,8 @@ impl Engine { |
| 2465 | 2679 | wgpu::TexelCopyBufferLayout { offset: 0, bytes_per_row: Some(256 * 4), rows_per_image: Some(1) }, |
| 2466 | 2680 | wgpu::Extent3d { width: 256, height: 1, depth_or_array_layers: 1 }, |
| 2467 | 2681 | ); |
| 2468 | let dst = self.alloc_tex(size, self.node_depth(comp, node, time, None), key); | |
| 2682 | let mut dst = self.alloc_tex(size, self.node_depth(comp, node, time, None), key); | |
| 2683 | dst.tex_scale = tex_scale; | |
| 2469 | 2684 | self.dispatch_op(enc, ShaderOp::FastNoise, &self.dummy.view, &lut_tex.view, &self.dummy.view, &dst, &u); |
| 2470 | 2685 | self.cache.insert(key, dst.clone(), node.id, frame_i); |
| 2471 | 2686 | dst |
| ... | ... | @@ -2488,7 +2703,9 @@ impl Engine { |
| 2488 | 2703 | let Some(fg_id) = node.connected_node("Foreground").and_then(|s| comp.find_node(s)) else { |
| 2489 | 2704 | return src; |
| 2490 | 2705 | }; |
| 2706 | let src = self.crop_to_canvas(enc, src); | |
| 2491 | 2707 | let fg = self.eval_node(comp, fg_id, time, enc, visiting, stats); |
| 2708 | let fg = self.crop_to_canvas(enc, fg); | |
| 2492 | 2709 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats); |
| 2493 | 2710 | let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash); |
| 2494 | 2711 | |
| ... | ... | @@ -2522,13 +2739,57 @@ impl Engine { |
| 2522 | 2739 | } |
| 2523 | 2740 | stats.cache_misses += 1; |
| 2524 | 2741 | stats.nodes_evaluated += 1; |
| 2525 | let dst = self.alloc_tex(src.size, src.depth, key); | |
| 2742 | let dst = self.alloc_tex_like(&src, src.depth, key); | |
| 2526 | 2743 | let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view); |
| 2527 | 2744 | self.dispatch_op(enc, ShaderOp::Displace, &src.view, &fg.view, mv, &dst, &u); |
| 2528 | 2745 | self.cache.insert(key, dst.clone(), node.id, frame_i); |
| 2529 | 2746 | dst |
| 2530 | 2747 | } |
| 2531 | 2748 | |
| 2749 | #[allow(clippy::too_many_arguments)] | |
| 2750 | fn eval_vortex( | |
| 2751 | &mut self, | |
| 2752 | comp: &Comp, | |
| 2753 | node: &Node, | |
| 2754 | time: f64, | |
| 2755 | frame_i: i64, | |
| 2756 | enc: &mut wgpu::CommandEncoder, | |
| 2757 | visiting: &mut HashSet<(NodeId, i64)>, | |
| 2758 | stats: &mut EvalStats, | |
| 2759 | ) -> CachedTexture { | |
| 2760 | let Some(src_id) = node.connected_node("Input").and_then(|s| comp.find_node(s)) else { | |
| 2761 | return self.dummy.clone(); | |
| 2762 | }; | |
| 2763 | let src = self.eval_node(comp, src_id, time, enc, visiting, stats); | |
| 2764 | let blend = comp.eval_number(node, "Blend", time, 1.0, &self.expr) as f32; | |
| 2765 | let angle_deg = comp.eval_number(node, "Angle", time, 0.0, &self.expr) as f32; | |
| 2766 | if blend <= 1e-6 || angle_deg.abs() <= 1e-5 { | |
| 2767 | return src; | |
| 2768 | } | |
| 2769 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats); | |
| 2770 | let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash); | |
| 2771 | let center = comp.eval_point(node, "Center", time, [0.5, 0.5], &self.expr); | |
| 2772 | let size = comp.eval_number(node, "Size", time, 0.5, &self.expr).max(1e-4) as f32; | |
| 2773 | let power = comp.eval_number(node, "Power", time, 5.0, &self.expr).max(0.0) as f32; | |
| 2774 | ||
| 2775 | let mut u = UniformParams::default(); | |
| 2776 | u.p[0] = [center[0] as f32, center[1] as f32, size * 0.5, angle_deg.to_radians()]; | |
| 2777 | u.p[1] = [power, blend, if mask.is_some() { 1.0 } else { 0.0 }, if mask_inv { 1.0 } else { 0.0 }]; | |
| 2778 | ||
| 2779 | let key = self.make_key(node, "Vortex", src.size, &[src.content_hash, mask_hash], bytemuck::cast_slice(&u.p[..2])); | |
| 2780 | if let Some(hit) = self.cache.get(key, node.id, frame_i) { | |
| 2781 | stats.cache_hits += 1; | |
| 2782 | return hit; | |
| 2783 | } | |
| 2784 | stats.cache_misses += 1; | |
| 2785 | stats.nodes_evaluated += 1; | |
| 2786 | let dst = self.alloc_tex_dod(src.size, src.origin, src.canvas_size, src.depth, key); | |
| 2787 | let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view); | |
| 2788 | self.dispatch_op(enc, ShaderOp::Vortex, &src.view, &self.dummy.view, mv, &dst, &u); | |
| 2789 | self.cache.insert(key, dst.clone(), node.id, frame_i); | |
| 2790 | dst | |
| 2791 | } | |
| 2792 | ||
| 2532 | 2793 | fn paint_mode_id(node: &Node) -> f32 { |
| 2533 | 2794 | match node.static_str("PaintMode").unwrap_or("Merge") { |
| 2534 | 2795 | "Add" => 1.0, |
| ... | ... | @@ -2542,6 +2803,77 @@ impl Engine { |
| 2542 | 2803 | } |
| 2543 | 2804 | } |
| 2544 | 2805 | |
| 2806 | /// Runs Fusion-calibrated separable mask `SoftEdge` blur with progressive 2x downsampling so | |
| 2807 | /// large `SoftEdge` values (up to 0.5+ / ~960px at 1080p) neither alias nor hit the 64-tap cap. | |
| 2808 | fn blur_mask_texture( | |
| 2809 | &self, | |
| 2810 | enc: &mut wgpu::CommandEncoder, | |
| 2811 | raw: &CachedTexture, | |
| 2812 | soft_px: f32, | |
| 2813 | is_box: bool, | |
| 2814 | clamp_edges: f32, | |
| 2815 | ) -> CachedTexture { | |
| 2816 | let size = raw.size; | |
| 2817 | let mode = if is_box { 1.0 } else { 0.0 }; | |
| 2818 | // Fusion mask Box filter has half-width ~0.707 * soft_px (1/sqrt(2)) vs Gaussian radius = soft_px. | |
| 2819 | let eff_r = if is_box { soft_px * 0.707 } else { soft_px }; | |
| 2820 | // Keep per-level radius <= 48px (16px in Fast mode) via progressive 2x pyramid steps so thin shapes don't alias. | |
| 2821 | let max_level_r = if self.hiq { 48.0 } else { 16.0 }; | |
| 2822 | let mut levels = 0u32; | |
| 2823 | let mut r_s = eff_r; | |
| 2824 | let mut ws = size; | |
| 2825 | while r_s > max_level_r && ws[0] >= 16 && ws[1] >= 16 && levels < 5 { | |
| 2826 | levels += 1; | |
| 2827 | r_s *= 0.5; | |
| 2828 | ws = [(ws[0] / 2).max(1), (ws[1] / 2).max(1)]; | |
| 2829 | } | |
| 2830 | ||
| 2831 | let mut u_blit = UniformParams::default(); | |
| 2832 | u_blit.p[0] = [1.0, 1.0, 0.0, 0.0]; | |
| 2833 | let mut cur = raw.clone(); | |
| 2834 | if levels > 0 { | |
| 2835 | let mut cur_sz = size; | |
| 2836 | for _ in 0..levels { | |
| 2837 | cur_sz = [(cur_sz[0] / 2).max(1), (cur_sz[1] / 2).max(1)]; | |
| 2838 | let next = create_texture(&self.device, cur_sz, 0); | |
| 2839 | self.dispatch_op(enc, ShaderOp::DisplayBlit, &cur.view, &self.dummy.view, &self.dummy.view, &next, &u_blit); | |
| 2840 | cur = next; | |
| 2841 | } | |
| 2842 | } | |
| 2843 | ||
| 2844 | let tmp1 = create_texture(&self.device, cur.size, 0); | |
| 2845 | let tmp2 = create_texture(&self.device, cur.size, 0); | |
| 2846 | let mut uh = UniformParams::default(); | |
| 2847 | uh.p[0] = [1.0, 0.0, r_s, mode]; | |
| 2848 | uh.p[1] = [1.0, 0.0, 0.0, clamp_edges]; | |
| 2849 | self.dispatch_op(enc, ShaderOp::Blur, &cur.view, &self.dummy.view, &self.dummy.view, &tmp1, &uh); | |
| 2850 | let mut uv = UniformParams::default(); | |
| 2851 | uv.p[0] = [0.0, 1.0, r_s, mode]; | |
| 2852 | uv.p[1] = [1.0, 0.0, 0.0, clamp_edges]; | |
| 2853 | self.dispatch_op(enc, ShaderOp::Blur, &tmp1.view, &self.dummy.view, &self.dummy.view, &tmp2, &uv); | |
| 2854 | ||
| 2855 | if levels > 0 { | |
| 2856 | let up = create_texture(&self.device, size, 0); | |
| 2857 | self.dispatch_op(enc, ShaderOp::DisplayBlit, &tmp2.view, &self.dummy.view, &self.dummy.view, &up, &u_blit); | |
| 2858 | up | |
| 2859 | } else { | |
| 2860 | tmp2 | |
| 2861 | } | |
| 2862 | } | |
| 2863 | ||
| 2864 | fn mask_filter_is_box(node: &Node) -> bool { | |
| 2865 | node.static_str("Filter").unwrap_or("Fast Gaussian").eq_ignore_ascii_case("Box") | |
| 2866 | } | |
| 2867 | ||
| 2868 | fn mask_clamp_edges(node: &Node) -> f32 { | |
| 2869 | // Fusion masks default to ClippingMode = "Frame" (clamp to border); "None" pads with 0 outside frame. | |
| 2870 | if node.static_str("ClippingMode").unwrap_or("Frame").eq_ignore_ascii_case("None") { | |
| 2871 | 0.0 | |
| 2872 | } else { | |
| 2873 | 1.0 | |
| 2874 | } | |
| 2875 | } | |
| 2876 | ||
| 2545 | 2877 | #[allow(clippy::too_many_arguments)] |
| 2546 | 2878 | fn eval_mask_shape( |
| 2547 | 2879 | &mut self, |
| ... | ... | @@ -2573,10 +2905,14 @@ impl Engine { |
| 2573 | 2905 | let mw = comp.eval_number(node, "Width", time, 0.5, &self.expr) as f32; |
| 2574 | 2906 | let mh = comp.eval_number(node, "Height", time, 0.5, &self.expr) as f32; |
| 2575 | 2907 | let angle = (comp.eval_number(node, "Angle", time, 0.0, &self.expr) as f32).to_radians(); |
| 2576 | let soft = comp.eval_number(node, "SoftEdge", time, 0.0, &self.expr) as f32; | |
| 2908 | let soft = comp.eval_number(node, "SoftEdge", time, 0.0, &self.expr).max(0.0) as f32; | |
| 2577 | 2909 | let corner = comp.eval_number(node, "CornerRadius", time, 0.0, &self.expr) as f32; |
| 2578 | 2910 | let invert = comp.eval_number(node, "Invert", time, 0.0, &self.expr) as f32; |
| 2579 | 2911 | let level = comp.eval_number(node, "Level", time, 1.0, &self.expr) as f32; |
| 2912 | let border_w = comp.eval_number(node, "BorderWidth", time, 0.0, &self.expr) as f32; | |
| 2913 | let solid = if comp.eval_number(node, "Solid", time, 1.0, &self.expr) > 0.5 { 1.0 } else { 0.0 }; | |
| 2914 | let is_box = Self::mask_filter_is_box(node); | |
| 2915 | let clamp_edges = Self::mask_clamp_edges(node); | |
| 2580 | 2916 | let (prev_mask, _) = self.eval_mask_input_sized(comp, node, time, Some(size), enc, visiting, stats); |
| 2581 | 2917 | let prev_hash = prev_mask.as_ref().map_or(0, |m| m.content_hash); |
| 2582 | 2918 | let paint_mode = Self::paint_mode_id(node); |
| ... | ... | @@ -2585,8 +2921,9 @@ impl Engine { |
| 2585 | 2921 | u.p[0] = [center[0] as f32, center[1] as f32, mw, mh]; |
| 2586 | 2922 | u.p[1] = [angle, soft, corner, invert]; |
| 2587 | 2923 | u.p[2] = [shape as f32, level, if prev_mask.is_some() { 1.0 } else { 0.0 }, paint_mode]; |
| 2924 | u.p[3] = [border_w, solid, if is_box { 1.0 } else { 0.0 }, clamp_edges]; | |
| 2588 | 2925 | |
| 2589 | let key = self.make_key(node, "MaskShape", size, &[prev_hash], bytemuck::cast_slice(&u.p[..3])); | |
| 2926 | let key = self.make_key(node, "MaskShape", size, &[prev_hash], bytemuck::cast_slice(&u.p[..4])); | |
| 2590 | 2927 | if let Some(hit) = self.cache.get(key, node.id, frame_i) { |
| 2591 | 2928 | stats.cache_hits += 1; |
| 2592 | 2929 | return hit; |
| ... | ... | @@ -2595,58 +2932,14 @@ impl Engine { |
| 2595 | 2932 | stats.nodes_evaluated += 1; |
| 2596 | 2933 | let mv = prev_mask.as_ref().map_or(&self.dummy.view, |m| &m.view); |
| 2597 | 2934 | let soft_px = soft * size[0] as f32; |
| 2598 | let dst = if soft_px >= 0.75 { | |
| 2599 | // Fusion Mask SoftEdge runs a true 2D Gaussian blur (sigma ~ 0.45 * SoftEdge * width) | |
| 2600 | // over the sharp shape before Invert/Level/PaintMode combine! | |
| 2935 | let dst = if soft_px >= 0.5 { | |
| 2601 | 2936 | let raw = create_texture(&self.device, size, 0); |
| 2602 | 2937 | let mut u_raw = u; |
| 2603 | 2938 | u_raw.p[1] = [angle, 0.0, corner, 0.0]; |
| 2604 | 2939 | u_raw.p[2] = [shape as f32, 1.0, 0.0, 0.0]; |
| 2605 | 2940 | self.dispatch_op(enc, ShaderOp::MaskShape, &self.dummy.view, &self.dummy.view, &self.dummy.view, &raw, &u_raw); |
| 2606 | 2941 | |
| 2607 | // Downsample for large SoftEdge radii (>24px or Fast mode) so 2048x2048 soft masks stay <0.5ms! | |
| 2608 | let down = if !self.hiq && soft_px >= 12.0 { | |
| 2609 | 4u32 | |
| 2610 | } else if soft_px >= 48.0 { | |
| 2611 | 4u32 | |
| 2612 | } else if soft_px >= 20.0 { | |
| 2613 | 2u32 | |
| 2614 | } else { | |
| 2615 | 1u32 | |
| 2616 | }; | |
| 2617 | let blurred = if down > 1 { | |
| 2618 | let ws = [(size[0] / down).max(1), (size[1] / down).max(1)]; | |
| 2619 | let small = create_texture(&self.device, ws, 0); | |
| 2620 | let tmp1 = create_texture(&self.device, ws, 0); | |
| 2621 | let tmp2 = create_texture(&self.device, ws, 0); | |
| 2622 | let up = create_texture(&self.device, size, 0); | |
| 2623 | let mut ub = UniformParams::default(); | |
| 2624 | ub.p[0] = [1.0, 1.0, 0.0, 0.0]; | |
| 2625 | self.dispatch_op(enc, ShaderOp::DisplayBlit, &raw.view, &self.dummy.view, &self.dummy.view, &small, &ub); | |
| 2626 | let r_s = soft_px / down as f32; | |
| 2627 | let mut uh = UniformParams::default(); | |
| 2628 | uh.p[0] = [1.0, 0.0, r_s, 0.0]; | |
| 2629 | uh.p[1] = [1.0, 0.0, 0.0, 0.0]; | |
| 2630 | self.dispatch_op(enc, ShaderOp::Blur, &small.view, &self.dummy.view, &self.dummy.view, &tmp1, &uh); | |
| 2631 | let mut uv = UniformParams::default(); | |
| 2632 | uv.p[0] = [0.0, 1.0, r_s, 0.0]; | |
| 2633 | uv.p[1] = [1.0, 0.0, 0.0, 0.0]; | |
| 2634 | self.dispatch_op(enc, ShaderOp::Blur, &tmp1.view, &self.dummy.view, &self.dummy.view, &tmp2, &uv); | |
| 2635 | self.dispatch_op(enc, ShaderOp::DisplayBlit, &tmp2.view, &self.dummy.view, &self.dummy.view, &up, &ub); | |
| 2636 | up | |
| 2637 | } else { | |
| 2638 | let tmp1 = create_texture(&self.device, size, 0); | |
| 2639 | let tmp2 = create_texture(&self.device, size, 0); | |
| 2640 | let mut uh = UniformParams::default(); | |
| 2641 | uh.p[0] = [1.0, 0.0, soft_px, 0.0]; | |
| 2642 | uh.p[1] = [1.0, 0.0, 0.0, 0.0]; | |
| 2643 | self.dispatch_op(enc, ShaderOp::Blur, &raw.view, &self.dummy.view, &self.dummy.view, &tmp1, &uh); | |
| 2644 | let mut uv = UniformParams::default(); | |
| 2645 | uv.p[0] = [0.0, 1.0, soft_px, 0.0]; | |
| 2646 | uv.p[1] = [1.0, 0.0, 0.0, 0.0]; | |
| 2647 | self.dispatch_op(enc, ShaderOp::Blur, &tmp1.view, &self.dummy.view, &self.dummy.view, &tmp2, &uv); | |
| 2648 | tmp2 | |
| 2649 | }; | |
| 2942 | let blurred = self.blur_mask_texture(enc, &raw, soft_px, is_box, clamp_edges); | |
| 2650 | 2943 | |
| 2651 | 2944 | let out_tex = create_texture(&self.device, size, key); |
| 2652 | 2945 | let mut uc = UniformParams::default(); |
| ... | ... | @@ -2687,6 +2980,8 @@ impl Engine { |
| 2687 | 2980 | let soft = comp.eval_number(node, "SoftEdge", time, 0.0, &self.expr).max(0.0) as f32; |
| 2688 | 2981 | let invert = comp.eval_number(node, "Invert", time, 0.0, &self.expr) > 0.5; |
| 2689 | 2982 | let level = comp.eval_number(node, "Level", time, 1.0, &self.expr) as f32; |
| 2983 | let is_box = Self::mask_filter_is_box(node); | |
| 2984 | let clamp_edges = Self::mask_clamp_edges(node); | |
| 2690 | 2985 | let (prev_mask, _) = self.eval_mask_input_sized(comp, node, time, Some(size), enc, visiting, stats); |
| 2691 | 2986 | let prev_hash = prev_mask.as_ref().map_or(0, |m| m.content_hash); |
| 2692 | 2987 | let paint_mode = Self::paint_mode_id(node); |
| ... | ... | @@ -2713,7 +3008,7 @@ impl Engine { |
| 2713 | 3008 | &[] |
| 2714 | 3009 | }; |
| 2715 | 3010 | |
| 2716 | let mut hash_floats = Vec::with_capacity(6 + points.len() * 6); | |
| 3011 | let mut hash_floats = Vec::with_capacity(8 + points.len() * 6); | |
| 2717 | 3012 | hash_floats.extend_from_slice(&[ |
| 2718 | 3013 | center[0] as f32, |
| 2719 | 3014 | center[1] as f32, |
| ... | ... | @@ -2721,6 +3016,8 @@ impl Engine { |
| 2721 | 3016 | if invert { 1.0 } else { 0.0 }, |
| 2722 | 3017 | level, |
| 2723 | 3018 | paint_mode, |
| 3019 | if is_box { 1.0 } else { 0.0 }, | |
| 3020 | clamp_edges, | |
| 2724 | 3021 | ]); |
| 2725 | 3022 | for p in points { |
| 2726 | 3023 | hash_floats.extend_from_slice(&[p.x as f32, p.y as f32, p.lx as f32, p.ly as f32, p.rx as f32, p.ry as f32]); |
| ... | ... | @@ -2733,8 +3030,8 @@ impl Engine { |
| 2733 | 3030 | stats.cache_misses += 1; |
| 2734 | 3031 | stats.nodes_evaluated += 1; |
| 2735 | 3032 | |
| 2736 | let soft_px = soft * size[0] as f32 * 1.14; | |
| 2737 | let need_post = soft_px >= 0.35 || prev_mask.is_some(); | |
| 3033 | let soft_px = soft * size[0] as f32; | |
| 3034 | let need_post = soft_px >= 0.5 || prev_mask.is_some(); | |
| 2738 | 3035 | let pixels = rasterize_polyline_mask( |
| 2739 | 3036 | size, |
| 2740 | 3037 | points, |
| ... | ... | @@ -2750,18 +3047,8 @@ impl Engine { |
| 2750 | 3047 | wgpu::Extent3d { width: size[0], height: size[1], depth_or_array_layers: 1 }, |
| 2751 | 3048 | ); |
| 2752 | 3049 | let tex = if need_post { |
| 2753 | let blurred = if soft_px >= 0.35 { | |
| 2754 | let tmp1 = create_texture(&self.device, size, 0); | |
| 2755 | let tmp2 = create_texture(&self.device, size, 0); | |
| 2756 | let mut uh = UniformParams::default(); | |
| 2757 | uh.p[0] = [1.0, 0.0, soft_px, 0.0]; | |
| 2758 | uh.p[1] = [1.0, 0.0, 0.0, 0.0]; | |
| 2759 | self.dispatch_op(enc, ShaderOp::Blur, &raw_tex.view, &self.dummy.view, &self.dummy.view, &tmp1, &uh); | |
| 2760 | let mut uv = UniformParams::default(); | |
| 2761 | uv.p[0] = [0.0, 1.0, soft_px, 0.0]; | |
| 2762 | uv.p[1] = [1.0, 0.0, 0.0, 0.0]; | |
| 2763 | self.dispatch_op(enc, ShaderOp::Blur, &tmp1.view, &self.dummy.view, &self.dummy.view, &tmp2, &uv); | |
| 2764 | tmp2 | |
| 3050 | let blurred = if soft_px >= 0.5 { | |
| 3051 | self.blur_mask_texture(enc, &raw_tex, soft_px, is_box, clamp_edges) | |
| 2765 | 3052 | } else { |
| 2766 | 3053 | raw_tex |
| 2767 | 3054 | }; |
| ... | ... | @@ -2783,20 +3070,107 @@ impl Engine { |
| 2783 | 3070 | tex |
| 2784 | 3071 | } |
| 2785 | 3072 | |
| 3073 | #[allow(clippy::too_many_arguments)] | |
| 2786 | 3074 | fn eval_bitmap_mask( |
| 2787 | 3075 | &mut self, |
| 2788 | 3076 | comp: &Comp, |
| 2789 | 3077 | node: &Node, |
| 2790 | 3078 | time: f64, |
| 3079 | frame_i: i64, | |
| 3080 | comp_dims: [u32; 2], | |
| 2791 | 3081 | enc: &mut wgpu::CommandEncoder, |
| 2792 | 3082 | visiting: &mut HashSet<(NodeId, i64)>, |
| 2793 | 3083 | stats: &mut EvalStats, |
| 2794 | 3084 | ) -> CachedTexture { |
| 2795 | if let Some(src_id) = node.connected_node("Image").and_then(|s| comp.find_node(s)) { | |
| 2796 | self.eval_node(comp, src_id, time, enc, visiting, stats) | |
| 3085 | let Some(src_id) = node.connected_node("Image").and_then(|s| comp.find_node(s)) else { | |
| 3086 | return self.dummy.clone(); | |
| 3087 | }; | |
| 3088 | let src = self.eval_node(comp, src_id, time, enc, visiting, stats); | |
| 3089 | ||
| 3090 | let output_size_mode = node.static_str("OutputSize").unwrap_or("Default"); | |
| 3091 | let size = if output_size_mode == "Custom" { | |
| 3092 | let w = comp.eval_number(node, "MaskWidth", time, comp.width as f64, &self.expr) as u32; | |
| 3093 | let h = comp.eval_number(node, "MaskHeight", time, comp.height as f64, &self.expr) as u32; | |
| 3094 | if w >= 16 && h >= 16 { self.scaled_dims(w, h) } else { comp_dims } | |
| 3095 | } else if let Some(ts) = self.mask_target_size { | |
| 3096 | ts | |
| 3097 | } else if node.inputs.contains_key("MaskWidth") || node.inputs.contains_key("MaskHeight") { | |
| 3098 | let w = comp.eval_number(node, "MaskWidth", time, comp.width as f64, &self.expr) as u32; | |
| 3099 | let h = comp.eval_number(node, "MaskHeight", time, comp.height as f64, &self.expr) as u32; | |
| 3100 | if w >= 16 && h >= 16 { self.scaled_dims(w, h) } else { src.canvas_size } | |
| 2797 | 3101 | } else { |
| 2798 | self.dummy.clone() | |
| 3102 | src.canvas_size | |
| 3103 | }; | |
| 3104 | ||
| 3105 | let ch_id: f32 = match node.static_str("Channel").unwrap_or("Alpha") { | |
| 3106 | "Luminance" => 1.0, | |
| 3107 | "Red" => 2.0, | |
| 3108 | "Green" => 3.0, | |
| 3109 | "Blue" => 4.0, | |
| 3110 | "Saturation" => 5.0, | |
| 3111 | "Lightness" => 6.0, | |
| 3112 | "Hue" => 7.0, | |
| 3113 | _ => 0.0, // Alpha (Fusion default) | |
| 3114 | }; | |
| 3115 | let low = comp.eval_number(node, "Low", time, 0.0, &self.expr) as f32; | |
| 3116 | let high = comp.eval_number(node, "High", time, 1.0, &self.expr) as f32; | |
| 3117 | let soft = comp.eval_number(node, "SoftEdge", time, 0.0, &self.expr).max(0.0) as f32; | |
| 3118 | let invert = if comp.eval_number(node, "Invert", time, 0.0, &self.expr) > 0.5 { 1.0 } else { 0.0 }; | |
| 3119 | let level = comp.eval_number(node, "Level", time, 1.0, &self.expr) as f32; | |
| 3120 | let center = comp.eval_point(node, "Center", time, [0.5, 0.5], &self.expr); | |
| 3121 | let fit_stretch = if comp.eval_number(node, "FitInput", time, 0.0, &self.expr) > 0.5 { 1.0 } else { 0.0 }; | |
| 3122 | let is_box = Self::mask_filter_is_box(node); | |
| 3123 | let clamp_edges = Self::mask_clamp_edges(node); | |
| 3124 | let (prev_mask, _) = self.eval_mask_input_sized(comp, node, time, Some(size), enc, visiting, stats); | |
| 3125 | let prev_hash = prev_mask.as_ref().map_or(0, |m| m.content_hash); | |
| 3126 | let paint_mode = Self::paint_mode_id(node); | |
| 3127 | ||
| 3128 | let key = self.make_key( | |
| 3129 | node, | |
| 3130 | "BitmapMask", | |
| 3131 | size, | |
| 3132 | &[src.content_hash, prev_hash], | |
| 3133 | &[ | |
| 3134 | ch_id, low, high, soft, invert, level, | |
| 3135 | center[0] as f32, center[1] as f32, fit_stretch, | |
| 3136 | if is_box { 1.0 } else { 0.0 }, clamp_edges, paint_mode, | |
| 3137 | ], | |
| 3138 | ); | |
| 3139 | if let Some(hit) = self.cache.get(key, node.id, frame_i) { | |
| 3140 | stats.cache_hits += 1; | |
| 3141 | return hit; | |
| 2799 | 3142 | } |
| 3143 | stats.cache_misses += 1; | |
| 3144 | stats.nodes_evaluated += 1; | |
| 3145 | ||
| 3146 | let soft_px = soft * size[0] as f32; | |
| 3147 | let need_post = soft_px >= 0.5 || invert > 0.5 || (level - 1.0).abs() > 1e-4 || prev_mask.is_some(); | |
| 3148 | ||
| 3149 | let raw_tex = create_texture(&self.device, size, if need_post { 0 } else { key }); | |
| 3150 | let mut u = UniformParams::default(); | |
| 3151 | u.p[0] = [ch_id, low, high, fit_stretch]; | |
| 3152 | u.p[1] = [center[0] as f32, center[1] as f32, src.origin[0] as f32, src.origin[1] as f32]; | |
| 3153 | u.p[2] = [src.canvas_size[0] as f32, src.canvas_size[1] as f32, 0.0, 0.0]; | |
| 3154 | self.dispatch_op(enc, ShaderOp::BitmapMask, &src.view, &self.dummy.view, &self.dummy.view, &raw_tex, &u); | |
| 3155 | ||
| 3156 | let out_tex = if need_post { | |
| 3157 | let blurred = if soft_px >= 0.5 { | |
| 3158 | self.blur_mask_texture(enc, &raw_tex, soft_px, is_box, clamp_edges) | |
| 3159 | } else { | |
| 3160 | raw_tex | |
| 3161 | }; | |
| 3162 | let combined = create_texture(&self.device, size, key); | |
| 3163 | let mut uc = UniformParams::default(); | |
| 3164 | uc.p[0] = [paint_mode, invert, level, if prev_mask.is_some() { 1.0 } else { 0.0 }]; | |
| 3165 | let mv = prev_mask.as_ref().map_or(&self.dummy.view, |m| &m.view); | |
| 3166 | self.dispatch_op(enc, ShaderOp::MaskCombine, &blurred.view, &self.dummy.view, mv, &combined, &uc); | |
| 3167 | combined | |
| 3168 | } else { | |
| 3169 | raw_tex | |
| 3170 | }; | |
| 3171 | ||
| 3172 | self.cache.insert(key, out_tex.clone(), node.id, frame_i); | |
| 3173 | out_tex | |
| 2800 | 3174 | } |
| 2801 | 3175 | |
| 2802 | 3176 | fn eval_text_plus( |
| ... | ... | @@ -3248,7 +3622,7 @@ impl Engine { |
| 3248 | 3622 | let dil_h = self.alloc_tex(src.size, src.depth, 0); |
| 3249 | 3623 | let dil_v = self.alloc_tex(src.size, src.depth, 0); |
| 3250 | 3624 | let tinted = self.alloc_tex(src.size, src.depth, 0); |
| 3251 | let dst = self.alloc_tex(src.size, src.depth, key); | |
| 3625 | let dst = self.alloc_tex_like(&src, src.depth, key); | |
| 3252 | 3626 | |
| 3253 | 3627 | let u0 = UniformParams::default(); |
| 3254 | 3628 | let mut dh = UniformParams::default(); |
| ... | ... | @@ -3372,6 +3746,7 @@ impl Engine { |
| 3372 | 3746 | if blend <= 1e-6 { |
| 3373 | 3747 | return src; |
| 3374 | 3748 | } |
| 3749 | let src = self.crop_to_canvas(enc, src); | |
| 3375 | 3750 | let proc_r = comp.eval_number(node, "ProcessRed", time, 1.0, &self.expr) as f32; |
| 3376 | 3751 | let proc_g = comp.eval_number(node, "ProcessGreen", time, 1.0, &self.expr) as f32; |
| 3377 | 3752 | let proc_b = comp.eval_number(node, "ProcessBlue", time, 1.0, &self.expr) as f32; |
| ... | ... | @@ -3414,6 +3789,7 @@ impl Engine { |
| 3414 | 3789 | if blend <= 1e-6 { |
| 3415 | 3790 | return src; |
| 3416 | 3791 | } |
| 3792 | let src = self.crop_to_canvas(enc, src); | |
| 3417 | 3793 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats); |
| 3418 | 3794 | let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash); |
| 3419 | 3795 | |
| ... | ... | @@ -3473,6 +3849,7 @@ impl Engine { |
| 3473 | 3849 | if blend <= 1e-6 { |
| 3474 | 3850 | return src; |
| 3475 | 3851 | } |
| 3852 | let src = self.crop_to_canvas(enc, src); | |
| 3476 | 3853 | let prediv = comp.eval_number(node, "PreDividePostMultiply", time, 0.0, &self.expr) as f32; |
| 3477 | 3854 | let ignore_trans = comp.eval_number(node, "IgnoreTransparent", time, 0.0, &self.expr) as f32; |
| 3478 | 3855 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats); |
| ... | ... | @@ -3554,6 +3931,7 @@ impl Engine { |
| 3554 | 3931 | if blend <= 1e-6 { |
| 3555 | 3932 | return src; |
| 3556 | 3933 | } |
| 3934 | let src = self.crop_to_canvas(enc, src); | |
| 3557 | 3935 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats); |
| 3558 | 3936 | let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash); |
| 3559 | 3937 | |
| ... | ... | @@ -3679,7 +4057,7 @@ impl Engine { |
| 3679 | 4057 | } else { |
| 3680 | 4058 | bg.clone() |
| 3681 | 4059 | }; |
| 3682 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(bg.size), enc, visiting, stats); | |
| 4060 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(bg.canvas_size), enc, visiting, stats); | |
| 3683 | 4061 | let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash); |
| 3684 | 4062 | let mut u = UniformParams::default(); |
| 3685 | 4063 | u.p[0] = [op as f32, to_r as f32, to_g as f32, to_b as f32]; |
| ... | ... | @@ -3692,14 +4070,17 @@ impl Engine { |
| 3692 | 4070 | if fg.has_dod() { |
| 3693 | 4071 | u.p[2] = [fg.origin[0] as f32, fg.origin[1] as f32, fg.canvas_size[0] as f32, fg.canvas_size[1] as f32]; |
| 3694 | 4072 | } |
| 3695 | let key = self.make_key(node, "ChannelBoolean", bg.size, &[bg.content_hash, fg.content_hash, mask_hash], bytemuck::cast_slice(&u.p[..3])); | |
| 4073 | if bg.has_dod() { | |
| 4074 | u.p[3] = [bg.origin[0] as f32, bg.origin[1] as f32, bg.canvas_size[0] as f32, bg.canvas_size[1] as f32]; | |
| 4075 | } | |
| 4076 | let key = self.make_key(node, "ChannelBoolean", bg.size, &[bg.content_hash, fg.content_hash, mask_hash], bytemuck::cast_slice(&u.p[..4])); | |
| 3696 | 4077 | if let Some(hit) = self.cache.get(key, node.id, frame_i) { |
| 3697 | 4078 | stats.cache_hits += 1; |
| 3698 | 4079 | return hit; |
| 3699 | 4080 | } |
| 3700 | 4081 | stats.cache_misses += 1; |
| 3701 | 4082 | stats.nodes_evaluated += 1; |
| 3702 | let dst = self.alloc_tex(bg.size, bg.depth.max(fg.depth), key); | |
| 4083 | let dst = self.alloc_tex_like(&bg, bg.depth.max(fg.depth), key); | |
| 3703 | 4084 | let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view); |
| 3704 | 4085 | self.dispatch_op(enc, ShaderOp::ChannelBoolean, &bg.view, &fg.view, mv, &dst, &u); |
| 3705 | 4086 | self.cache.insert(key, dst.clone(), node.id, frame_i); |
| ... | ... | @@ -3724,6 +4105,7 @@ impl Engine { |
| 3724 | 4105 | if blend <= 1e-6 { |
| 3725 | 4106 | return src; |
| 3726 | 4107 | } |
| 4108 | let src = self.crop_to_canvas(enc, src); | |
| 3727 | 4109 | let map_space = |s: Option<&str>| -> f32 { |
| 3728 | 4110 | match s.unwrap_or("NoChange") { |
| 3729 | 4111 | "sRGB" => 1.0, |
| ... | ... | @@ -3777,6 +4159,7 @@ impl Engine { |
| 3777 | 4159 | if blend <= 1e-6 { |
| 3778 | 4160 | return src; |
| 3779 | 4161 | } |
| 4162 | let src = self.crop_to_canvas(enc, src); | |
| 3780 | 4163 | let rx = (comp.eval_number(node, "XBlurSize", time, 1.0, &self.expr) as f32) * 2.0 / self.proxy_scale.max(1) as f32; |
| 3781 | 4164 | let ry = (comp.eval_number(node, "YBlurSize", time, (rx * self.proxy_scale.max(1) as f32 / 2.0) as f64, &self.expr) as f32) * 2.0 / self.proxy_scale.max(1) as f32; |
| 3782 | 4165 | let bmap = node |
| ... | ... | @@ -4005,6 +4388,7 @@ impl Engine { |
| 4005 | 4388 | if blend <= 1e-6 { |
| 4006 | 4389 | return src; |
| 4007 | 4390 | } |
| 4391 | let src = self.crop_to_canvas(enc, src); | |
| 4008 | 4392 | let ftype = comp.eval_number(node, "FilterType", time, 0.0, &self.expr).round() as f32; |
| 4009 | 4393 | let power = comp.eval_number(node, "Power", time, 1.0, &self.expr) as f32; |
| 4010 | 4394 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats); |
| ... | ... | @@ -4100,6 +4484,7 @@ impl Engine { |
| 4100 | 4484 | if blend <= 1e-6 { |
| 4101 | 4485 | return src; |
| 4102 | 4486 | } |
| 4487 | let src = self.crop_to_canvas(enc, src); | |
| 4103 | 4488 | let prediv = comp.eval_number(node, "PreDividePostMultiply", time, 0.0, &self.expr) as f32; |
| 4104 | 4489 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats); |
| 4105 | 4490 | let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash); |
| ... | ... | @@ -4180,6 +4565,7 @@ impl Engine { |
| 4180 | 4565 | if blend <= 1e-6 { |
| 4181 | 4566 | return src; |
| 4182 | 4567 | } |
| 4568 | let src = self.crop_to_canvas(enc, src); | |
| 4183 | 4569 | let bg_r = comp.eval_number(node, "BackgroundRed", time, 0.0, &self.expr) as f32; |
| 4184 | 4570 | let bg_g = comp.eval_number(node, "BackgroundGreen", time, 1.0, &self.expr) as f32; |
| 4185 | 4571 | let bg_b = comp.eval_number(node, "BackgroundBlue", time, 0.0, &self.expr) as f32; |
| ... | ... | @@ -4243,7 +4629,7 @@ impl Engine { |
| 4243 | 4629 | if blend <= 1e-6 || mix_v <= 1e-6 { |
| 4244 | 4630 | return bg; |
| 4245 | 4631 | } |
| 4246 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(bg.size), enc, visiting, stats); | |
| 4632 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(bg.canvas_size), enc, visiting, stats); | |
| 4247 | 4633 | let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash); |
| 4248 | 4634 | let mut u = UniformParams::default(); |
| 4249 | 4635 | u.p[0] = [mix_v, blend, if mask.is_some() { 1.0 } else { 0.0 }, if mask_inv { 1.0 } else { 0.0 }]; |
| ... | ... | @@ -4254,7 +4640,8 @@ impl Engine { |
| 4254 | 4640 | } |
| 4255 | 4641 | stats.cache_misses += 1; |
| 4256 | 4642 | stats.nodes_evaluated += 1; |
| 4257 | let dst = self.alloc_tex_dod(bg.size, bg.origin, bg.canvas_size, bg.depth.max(fg.depth), key); | |
| 4643 | let mut dst = self.alloc_tex_dod(bg.size, bg.origin, bg.canvas_size, bg.depth.max(fg.depth), key); | |
| 4644 | dst.tex_scale = bg.tex_scale; | |
| 4258 | 4645 | let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view); |
| 4259 | 4646 | self.dispatch_op(enc, ShaderOp::Dissolve, &bg.view, &fg.view, mv, &dst, &u); |
| 4260 | 4647 | self.cache.insert(key, dst.clone(), node.id, frame_i); |
| ... | ... | @@ -4279,6 +4666,7 @@ impl Engine { |
| 4279 | 4666 | if blend <= 1e-6 { |
| 4280 | 4667 | return src; |
| 4281 | 4668 | } |
| 4669 | let src = self.crop_to_canvas(enc, src); | |
| 4282 | 4670 | let offset = comp.eval_point(node, "ShadowOffset", time, [0.5, 0.5], &self.expr); |
| 4283 | 4671 | let soft = comp.eval_number(node, "Softness", time, 0.0, &self.expr).max(0.0) as f32; |
| 4284 | 4672 | let sh_r = comp.eval_number(node, "Red", time, 0.0, &self.expr) as f32; |
| ... | ... | @@ -4398,6 +4786,7 @@ impl Engine { |
| 4398 | 4786 | if blend <= 1e-6 { |
| 4399 | 4787 | return src; |
| 4400 | 4788 | } |
| 4789 | let src = self.crop_to_canvas(enc, src); | |
| 4401 | 4790 | let bl = comp.eval_point(node, "BottomLeft", time, [0.0, 0.0], &self.expr); |
| 4402 | 4791 | let br = comp.eval_point(node, "BottomRight", time, [1.0, 0.0], &self.expr); |
| 4403 | 4792 | let tr = comp.eval_point(node, "TopRight", time, [1.0, 1.0], &self.expr); |
crates/engine/src/scene3d.rs+13-3| ... | ... | @@ -628,7 +628,8 @@ pub fn collect_scene( |
| 628 | 628 | } else { |
| 629 | 629 | 24.302 |
| 630 | 630 | }; |
| 631 | let gate_fit = node.static_str("ResolutionGateFit").unwrap_or("Inside"); | |
| 631 | // Fusion Camera3D defaults ResolutionGateFit to "Height" (vertical AoV is preserved on square/tall renders) | |
| 632 | let gate_fit = node.static_str("ResolutionGateFit").unwrap_or("Height"); | |
| 632 | 633 | let gate_aspect = (ap_w / ap_h.max(1e-4)).max(1e-4); |
| 633 | 634 | |
| 634 | 635 | let half_aov = (aov_deg.to_radians() * 0.5).tan(); |
| ... | ... | @@ -684,7 +685,8 @@ pub fn collect_scene( |
| 684 | 685 | let shape_name = node.static_str("Shape").unwrap_or("SurfacePlaneInputs"); |
| 685 | 686 | let shape = match shape_name { |
| 686 | 687 | "SurfaceSphereInputs" => ShapeKind::Sphere { |
| 687 | radius: comp.eval_number(node, "SurfaceSphereInputs.Radius", time, 0.5, expr) as f32, | |
| 688 | // Fusion 21.1 Shape3D Sphere default Radius is 1.0 (verified via probe_moon_3d f00) | |
| 689 | radius: comp.eval_number(node, "SurfaceSphereInputs.Radius", time, 1.0, expr) as f32, | |
| 688 | 690 | sub_base: comp.eval_number(node, "SurfaceSphereInputs.SubdivisionLevelBase", time, 32.0, expr).round() as u32, |
| 689 | 691 | sub_height: comp.eval_number(node, "SurfaceSphereInputs.SubdivisionLevelHeight", time, 24.0, expr).round() as u32, |
| 690 | 692 | }, |
| ... | ... | @@ -712,7 +714,15 @@ pub fn collect_scene( |
| 712 | 714 | let mat_node = node |
| 713 | 715 | .connected_node("MaterialInput") |
| 714 | 716 | .and_then(|s| comp.find_node(s)); |
| 715 | let (tex_node, diffuse_col, roughness) = resolve_material(comp, mat_node, time, expr); | |
| 717 | let (tex_node, mut diffuse_col, roughness) = resolve_material(comp, mat_node, time, expr); | |
| 718 | if mat_node.is_none() { | |
| 719 | diffuse_col = [ | |
| 720 | comp.eval_number(node, "MtlStdInputs.Diffuse.Color.Red", time, 1.0, expr) as f32, | |
| 721 | comp.eval_number(node, "MtlStdInputs.Diffuse.Color.Green", time, 1.0, expr) as f32, | |
| 722 | comp.eval_number(node, "MtlStdInputs.Diffuse.Color.Blue", time, 1.0, expr) as f32, | |
| 723 | comp.eval_number(node, "MtlStdInputs.Diffuse.Opacity", time, 1.0, expr) as f32, | |
| 724 | ]; | |
| 725 | } | |
| 716 | 726 | meshes.push(MeshInstance { |
| 717 | 727 | world, |
| 718 | 728 | shape, |
crates/engine/src/shaders.wgsl+289-85| ... | ... | @@ -83,15 +83,21 @@ fn sample_edges(tex: texture_2d<f32>, fu: vec2<f32>, edges: i32) -> vec4<f32> { |
| 83 | 83 | return sample_dod_edges(tex, fu, edges, vec4<f32>(0.0)); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | fn read_mask(gid: vec2<u32>, dims: vec2<u32>, has_mask: f32, invert: f32) -> f32 { | |
| 86 | fn read_mask_uv(uv: vec2<f32>, has_mask: f32, invert: f32) -> f32 { | |
| 87 | 87 | if (has_mask < 0.5) { |
| 88 | 88 | return 1.0; |
| 89 | 89 | } |
| 90 | let uv = (vec2<f32>(gid) + 0.5) / vec2<f32>(dims); | |
| 91 | let m = textureSampleLevel(mask_tex, samp_lin, uv, 0.0).a; | |
| 90 | var m = 0.0; | |
| 91 | if (uv.x >= 0.0 && uv.x <= 1.0 && uv.y >= 0.0 && uv.y <= 1.0) { | |
| 92 | m = textureSampleLevel(mask_tex, samp_lin, uv, 0.0).a; | |
| 93 | } | |
| 92 | 94 | return select(m, 1.0 - m, invert > 0.5); |
| 93 | 95 | } |
| 94 | 96 | |
| 97 | fn read_mask(gid: vec2<u32>, dims: vec2<u32>, has_mask: f32, invert: f32) -> f32 { | |
| 98 | return read_mask_uv((vec2<f32>(gid) + 0.5) / vec2<f32>(dims), has_mask, invert); | |
| 99 | } | |
| 100 | ||
| 95 | 101 | // ============================================================================ |
| 96 | 102 | // 1. Background (Solid + Gradients) |
| 97 | 103 | // p[0] = top_left rgba, p[1] = top_right rgba, p[2] = bottom_left rgba, p[3] = bottom_right rgba |
| ... | ... | @@ -285,7 +291,13 @@ fn merge_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 285 | 291 | let bg_dims = select(vec2<f32>(dims), bg_dod.zw, has_bg_dod); |
| 286 | 292 | let fg_dims = max(u.p[3].zw, vec2<f32>(1.0)); |
| 287 | 293 | |
| 288 | let bg = textureLoad(src_a, vec2<i32>(gid.xy), 0); | |
| 294 | let bg_off = vec2<i32>(i32(round(u.p[6].z)), i32(round(u.p[6].w))); | |
| 295 | let bg_coord = vec2<i32>(gid.xy) - bg_off; | |
| 296 | let bg_tex_dims = vec2<i32>(textureDimensions(src_a)); | |
| 297 | var bg = vec4<f32>(0.0); | |
| 298 | if (bg_coord.x >= 0 && bg_coord.y >= 0 && bg_coord.x < bg_tex_dims.x && bg_coord.y < bg_tex_dims.y) { | |
| 299 | bg = textureLoad(src_a, bg_coord, 0); | |
| 300 | } | |
| 289 | 301 | // If BG has expanded DoD, map output texel into logical BG canvas Fusion UV! |
| 290 | 302 | let canvas_px = select( |
| 291 | 303 | vec2<f32>(gid.xy) + vec2<f32>(0.5), |
| ... | ... | @@ -314,7 +326,7 @@ fn merge_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 314 | 326 | if (u.p[2].y > 0.5) { fg_fu.y = 1.0 - fg_fu.y; } |
| 315 | 327 | |
| 316 | 328 | let fg = sample_dod_edges_mode(src_b, fg_fu, edges, u.p[4], nearest); |
| 317 | let mask = read_mask(gid.xy, dims, u.p[3].x, u.p[3].y); | |
| 329 | let mask = read_mask_uv(canvas_px / bg_dims, u.p[3].x, u.p[3].y); | |
| 318 | 330 | let eff_blend = clamp(blend * mask, 0.0, 1.0); |
| 319 | 331 | let op = i32(u.p[2].w + 0.5); // 0=Over, 1=Under, 2=In, 3=HeldOut, 4=Atop, 5=XOr |
| 320 | 332 | |
| ... | ... | @@ -482,11 +494,18 @@ fn bc_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 482 | 494 | |
| 483 | 495 | |
| 484 | 496 | // ============================================================================ |
| 485 | // 5. ColorCorrector (Lightness-preserving hue rotation + saturation + tint + LGG + contrast) | |
| 486 | // p[0] = (hue_turns, sat, tint_angle_rad, tint_len) | |
| 487 | // p[1] = (gain, lift, gamma, contrast) | |
| 488 | // p[2] = (brightness, prediv, blend, has_mask) | |
| 489 | // p[3] = (mask_invert, 0, 0, 0) | |
| 497 | // 5. ColorCorrector (Master + Shadows/Midtones/Highlights wheels, TintMode 0 & 1, LGG) | |
| 498 | // p[0] = (hue1, sat1, tint_angle1, tint_len1) | |
| 499 | // p[1] = (gain1, lift1, gamma1, contrast1) | |
| 500 | // p[2] = (brightness1, prediv, blend, has_mask) | |
| 501 | // p[3] = (mask_invert, tint_mode, has_smh, 0) | |
| 502 | // p[4] = (hue2, sat2, tint_angle2, tint_len2) // Shadows | |
| 503 | // p[5] = (gain2, lift2, gamma2, contrast2) | |
| 504 | // p[6] = (hue3, sat3, tint_angle3, tint_len3) // Midtones | |
| 505 | // p[7] = (gain3, lift3, gamma3, contrast3) | |
| 506 | // p[8] = (hue4, sat4, tint_angle4, tint_len4) // Highlights | |
| 507 | // p[9] = (gain4, lift4, gamma4, contrast4) | |
| 508 | // p[10] = (bright2, bright3, bright4, 0) | |
| 490 | 509 | // ============================================================================ |
| 491 | 510 | fn rotate_hue_preserve_luma(c: vec3<f32>, angle: f32) -> vec3<f32> { |
| 492 | 511 | // Paul Haeberli luminance-preserving shear-rotate-unshear around (1,1,1) with Rec.601 weights. |
| ... | ... | @@ -512,21 +531,101 @@ fn hsv_pure_hue(h_turns: f32) -> vec3<f32> { |
| 512 | 531 | return vec3<f32>(r, g, b); |
| 513 | 532 | } |
| 514 | 533 | |
| 534 | fn apply_cc_wheel_and_lgg( | |
| 535 | rgb_in: vec3<f32>, | |
| 536 | hue_turns: f32, | |
| 537 | sat: f32, | |
| 538 | tint_turns: f32, | |
| 539 | tint_len: f32, | |
| 540 | tint_mode: f32, | |
| 541 | gain: f32, | |
| 542 | lift: f32, | |
| 543 | gamma_in: f32, | |
| 544 | contrast: f32, | |
| 545 | brightness: f32, | |
| 546 | ) -> vec3<f32> { | |
| 547 | let k_luma = vec3<f32>(0.299, 0.587, 0.114); | |
| 548 | let gamma = max(gamma_in, 1e-4); | |
| 549 | var rgb = rgb_in; | |
| 550 | ||
| 551 | // 1. Hue rotation (verified 0.00/255 vs Fusion 21.1) | |
| 552 | if (abs(hue_turns) > 1e-5) { | |
| 553 | rgb = rotate_hue_preserve_luma(rgb, -hue_turns * 6.28318530718); | |
| 554 | } | |
| 555 | ||
| 556 | // 2. Fusion Color Wheel Tint | |
| 557 | if (tint_len > 1e-5) { | |
| 558 | let l = clamp(tint_len, 0.0, 1.0); | |
| 559 | if (tint_mode < 0.5) { | |
| 560 | // TintMode = 0 (RGB cube tilt + perpendicular chroma squeeze, verified 0.00/255 at len=1.0!) | |
| 561 | let s3 = 0.5773502691896258; | |
| 562 | let e1 = vec3<f32>(s3, s3, s3); | |
| 563 | let a = tint_turns * 6.28318530718; | |
| 564 | let u_ch = normalize(vec3<f32>(cos(a), cos(a - 2.09439510239), cos(a + 2.09439510239))); | |
| 565 | let u_pp = normalize(cross(e1, u_ch)); | |
| 566 | let t = l * l; | |
| 567 | let th = 0.471238898038 * t; // 27.0 deg * len^2 | |
| 568 | let c_th = cos(th); | |
| 569 | let s_th = sin(th); | |
| 570 | let x1 = dot(rgb, e1); | |
| 571 | let x2 = dot(rgb, u_ch); | |
| 572 | let x3 = dot(rgb, u_pp); | |
| 573 | let y1 = c_th * x1 - s_th * x2; | |
| 574 | let y2 = s_th * x1 + c_th * x2; | |
| 575 | let y3 = (1.0 - t) * x3; | |
| 576 | rgb = y1 * e1 + y2 * u_ch + y3 * u_pp; | |
| 577 | } else if (tint_mode < 1.5) { | |
| 578 | // TintMode = 1: luma-preserving chroma blend + amp = l*((1-l) + l*2*min(y,1-y)), verified 0.00/255! | |
| 579 | let y_t = dot(rgb, k_luma); | |
| 580 | let pure = hsv_pure_hue(tint_turns); | |
| 581 | let pure_y = dot(pure, k_luma); | |
| 582 | let tc = pure - vec3<f32>(pure_y); | |
| 583 | let yc = clamp(y_t, 0.0, 1.0); | |
| 584 | let amp = l * ((1.0 - l) + l * 2.0 * min(yc, 1.0 - yc)); | |
| 585 | rgb = vec3<f32>(y_t) + (rgb - vec3<f32>(y_t)) * (1.0 - l) + tc * amp; | |
| 586 | } else { | |
| 587 | // TintMode = 2 (Fusion 21.1 default when omitted): lerp toward pure HSV chroma * 2*min(y,1-y) | |
| 588 | let y_t = dot(rgb, k_luma); | |
| 589 | let pure = hsv_pure_hue(tint_turns); | |
| 590 | let pure_y = dot(pure, k_luma); | |
| 591 | let tc = pure - vec3<f32>(pure_y); | |
| 592 | let yc = clamp(y_t, 0.0, 1.0); | |
| 593 | let amp = 2.0 * min(yc, 1.0 - yc); | |
| 594 | let tint_rgb = vec3<f32>(y_t) + tc * amp; | |
| 595 | rgb = mix(rgb, tint_rgb, l); | |
| 596 | } | |
| 597 | } | |
| 598 | ||
| 599 | // 3. Saturation (Rec.601 luma, no gamut crushing) | |
| 600 | if (abs(sat - 1.0) > 1e-5) { | |
| 601 | let luma = dot(rgb, k_luma); | |
| 602 | rgb = mix(vec3<f32>(luma), rgb, sat); | |
| 603 | } | |
| 604 | ||
| 605 | // 4. Contrast -> Lift/Gain -> Brightness -> Gamma | |
| 606 | if (abs(contrast - 1.0) > 1e-5) { | |
| 607 | rgb = (rgb - 0.5) * contrast + 0.5; | |
| 608 | } | |
| 609 | if (abs(gain - 1.0) > 1e-5 || abs(lift) > 1e-5) { | |
| 610 | rgb = rgb * (gain - lift) + lift; | |
| 611 | } | |
| 612 | if (abs(brightness) > 1e-5) { | |
| 613 | rgb = rgb + brightness; | |
| 614 | } | |
| 615 | if (abs(gamma - 1.0) > 1e-5) { | |
| 616 | rgb = pow(max(rgb, vec3<f32>(0.0)), vec3<f32>(1.0 / gamma)); | |
| 617 | } | |
| 618 | return rgb; | |
| 619 | } | |
| 620 | ||
| 515 | 621 | @compute @workgroup_size(8, 8) |
| 516 | 622 | fn cc_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 517 | 623 | let dims = textureDimensions(dst_tex); |
| 518 | 624 | if (gid.x >= dims.x || gid.y >= dims.y) { return; } |
| 519 | 625 | let src = textureLoad(src_a, vec2<i32>(gid.xy), 0); |
| 520 | let hue_turns = u.p[0].x; | |
| 521 | let sat = u.p[0].y; | |
| 522 | let tint_turns = u.p[0].z; | |
| 523 | let tint_len = u.p[0].w; | |
| 524 | let gain = u.p[1].x; | |
| 525 | let lift = u.p[1].y; | |
| 526 | let gamma = max(u.p[1].z, 1e-4); | |
| 527 | let contrast = u.p[1].w; | |
| 528 | let brightness = u.p[2].x; | |
| 529 | 626 | let prediv = u.p[2].y > 0.5; |
| 627 | let tint_mode = u.p[3].y; | |
| 628 | let has_smh = u.p[3].z > 0.5; | |
| 530 | 629 | let k_luma = vec3<f32>(0.299, 0.587, 0.114); |
| 531 | 630 | |
| 532 | 631 | var rgb = src.rgb; |
| ... | ... | @@ -534,32 +633,18 @@ fn cc_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 534 | 633 | rgb = rgb / src.a; |
| 535 | 634 | } |
| 536 | 635 | |
| 537 | // 1. Hue rotation (verified 0.00/255 vs Fusion 21.1: +turns rotates Red -> Yellow -> Green -> Cyan -> Blue -> Magenta) | |
| 538 | if (abs(hue_turns) > 1e-5) { | |
| 539 | rgb = rotate_hue_preserve_luma(rgb, -hue_turns * 6.28318530718); | |
| 636 | if (has_smh) { | |
| 637 | let y0 = clamp(dot(rgb, k_luma), 0.0, 1.0); | |
| 638 | let w_s = clamp(1.0 - 2.0 * y0, 0.0, 1.0); | |
| 639 | let w_h = clamp(2.0 * y0 - 1.0, 0.0, 1.0); | |
| 640 | let w_m = max(1.0 - w_s - w_h, 0.0); | |
| 641 | let rgb_s = apply_cc_wheel_and_lgg(rgb, u.p[4].x, u.p[4].y, u.p[4].z, u.p[4].w, tint_mode, u.p[5].x, u.p[5].y, u.p[5].z, u.p[5].w, u.p[10].x); | |
| 642 | let rgb_m = apply_cc_wheel_and_lgg(rgb, u.p[6].x, u.p[6].y, u.p[6].z, u.p[6].w, tint_mode, u.p[7].x, u.p[7].y, u.p[7].z, u.p[7].w, u.p[10].y); | |
| 643 | let rgb_h = apply_cc_wheel_and_lgg(rgb, u.p[8].x, u.p[8].y, u.p[8].z, u.p[8].w, tint_mode, u.p[9].x, u.p[9].y, u.p[9].z, u.p[9].w, u.p[10].z); | |
| 644 | rgb = rgb_s * w_s + rgb_m * w_m + rgb_h * w_h; | |
| 540 | 645 | } |
| 541 | 646 | |
| 542 | // 2. Fusion Color Wheel Tint (verified 0.00/255 vs Fusion 21.1: lerp toward pure HSV chroma * 2*min(Y, 1-Y)) | |
| 543 | if (tint_len > 1e-5) { | |
| 544 | let y_t = dot(rgb, k_luma); | |
| 545 | let pure = hsv_pure_hue(tint_turns); | |
| 546 | let pure_y = dot(pure, k_luma); | |
| 547 | let tc = pure - vec3<f32>(pure_y); | |
| 548 | let y_clamped = clamp(y_t, 0.0, 1.0); | |
| 549 | let amp = 2.0 * min(y_clamped, 1.0 - y_clamped); | |
| 550 | let tint_rgb = vec3<f32>(y_t) + tc * amp; | |
| 551 | rgb = mix(rgb, tint_rgb, clamp(tint_len, 0.0, 1.0)); | |
| 552 | } | |
| 553 | ||
| 554 | // 3. Saturation (Rec.601 luma, no gamut crushing — verified 0.00/255 at sat=0, 1.6, 3.0, 6.0!) | |
| 555 | let luma = dot(rgb, k_luma); | |
| 556 | rgb = mix(vec3<f32>(luma), rgb, sat); | |
| 557 | ||
| 558 | // 4. Contrast -> Lift/Gain -> Brightness -> Gamma (verified 0.00/255 vs Fusion 21.1!) | |
| 559 | rgb = (rgb - 0.5) * contrast + 0.5; | |
| 560 | rgb = rgb * (gain - lift) + lift; | |
| 561 | rgb = rgb + brightness; | |
| 562 | rgb = pow(max(rgb, vec3<f32>(0.0)), vec3<f32>(1.0 / gamma)); | |
| 647 | rgb = apply_cc_wheel_and_lgg(rgb, u.p[0].x, u.p[0].y, u.p[0].z, u.p[0].w, tint_mode, u.p[1].x, u.p[1].y, u.p[1].z, u.p[1].w, u.p[2].x); | |
| 563 | 648 | |
| 564 | 649 | if (prediv) { |
| 565 | 650 | rgb = rgb * src.a; |
| ... | ... | @@ -754,11 +839,15 @@ fn fast_noise_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 754 | 839 | freq = freq * 2.0; |
| 755 | 840 | amp = amp * 0.5; |
| 756 | 841 | } |
| 757 | let n_avg = sum / max(norm, 1e-4); | |
| 842 | let n_avg = sum / max(norm, 1.0); | |
| 758 | 843 | // Perlin3D normalized fBm: at Detail=1 (norm=1), *0.41 matches Fusion std=0.106 [0.24, 0.76]; |
| 759 | 844 | // at Detail=10 (norm=2), std naturally narrows to ~0.060 matching Fusion's pinpoint starfield threshold! |
| 845 | // Discontinuous mode takes |n| turbulence (~1.60x -> mean 0.34, std 0.14 in Type=0 TwoColor), | |
| 846 | // pivoting Contrast around 0.5 when Contrast != 1 (verified via probe_moon_3d f02 & displace_wave f05/f07/f08). | |
| 760 | 847 | if (disc) { |
| 761 | val = n_avg * 0.82 * contrast + brightness; | |
| 848 | let grad_bias = select(0.0, 0.25, u.p[2].w > 1.5); | |
| 849 | let base = n_avg * 1.60 + grad_bias; | |
| 850 | val = (base - 0.5) * contrast + 0.5 + brightness; | |
| 762 | 851 | } else { |
| 763 | 852 | val = n_avg * 0.41 * contrast + 0.5 + brightness; |
| 764 | 853 | } |
| ... | ... | @@ -868,10 +957,11 @@ fn displace_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 868 | 957 | |
| 869 | 958 | |
| 870 | 959 | // ============================================================================ |
| 871 | // 10. Mask Shapes (EllipseMask & RectangleMask) + Mask Combine / Apply | |
| 960 | // 10. Mask Shapes (EllipseMask & RectangleMask) + Mask Combine / Apply / BitmapMask | |
| 872 | 961 | // p[0] = (center.x, center.y, width, height) |
| 873 | 962 | // p[1] = (angle_rad, soft_edge, corner_radius, invert) |
| 874 | 963 | // p[2] = (shape: 0=Ellipse, 1=Rect, level, has_prev_mask, paint_mode) |
| 964 | // p[3] = (border_width, solid: 1=filled/0=outline, 0, 0) | |
| 875 | 965 | // paint_mode: 0=Merge, 1=Add, 2=Subtract, 3=Multiply, 4=Min, 5=Max, 6=Invert, 7=Replace |
| 876 | 966 | // ============================================================================ |
| 877 | 967 | fn combine_mask_val(prev: f32, cur: f32, mode: i32) -> f32 { |
| ... | ... | @@ -895,13 +985,15 @@ fn mask_shape_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 895 | 985 | let center = u.p[0].xy; |
| 896 | 986 | let half_sz = max(u.p[0].zw * 0.5, vec2<f32>(1e-5)); |
| 897 | 987 | let angle = u.p[1].x; |
| 898 | let soft = max(u.p[1].y, 1.0 / max(f32(dims.x), 1.0)); | |
| 988 | let soft = max(u.p[1].y, 0.5 / max(f32(dims.x), 1.0)); | |
| 899 | 989 | let radius = u.p[1].z; |
| 900 | 990 | let invert = u.p[1].w > 0.5; |
| 901 | 991 | let shape = i32(u.p[2].x + 0.5); |
| 902 | 992 | let level = u.p[2].y; |
| 903 | 993 | let has_prev = u.p[2].z > 0.5; |
| 904 | 994 | let paint_mode = i32(u.p[2].w + 0.5); |
| 995 | let border_w = u.p[3].x; | |
| 996 | let solid = u.p[3].y > 0.5; | |
| 905 | 997 | |
| 906 | 998 | // Work in isotropic frame-width units (1.0 = canvas width) so rotations & circles are exact! |
| 907 | 999 | let rel_w = (fu - center) * vec2<f32>(1.0, 1.0 / aspect); |
| ... | ... | @@ -924,6 +1016,12 @@ fn mask_shape_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 924 | 1016 | dist = length(max(q, vec2<f32>(0.0))) + min(max(q.x, q.y), 0.0) - r_w; |
| 925 | 1017 | } |
| 926 | 1018 | |
| 1019 | if (solid) { | |
| 1020 | dist = dist - border_w * 0.5; | |
| 1021 | } else { | |
| 1022 | dist = abs(dist) - abs(border_w) * 0.5; | |
| 1023 | } | |
| 1024 | ||
| 927 | 1025 | var a = 1.0 - smoothstep(-soft, soft, dist); |
| 928 | 1026 | if (invert) { a = 1.0 - a; } |
| 929 | 1027 | a = clamp(a * level, 0.0, 1.0); |
| ... | ... | @@ -964,6 +1062,80 @@ fn mask_apply_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 964 | 1062 | textureStore(dst_tex, vec2<i32>(gid.xy), src * m); |
| 965 | 1063 | } |
| 966 | 1064 | |
| 1065 | // 10b. BitmapMask channel extraction + Low/High clip + centered 1:1 pixel alignment | |
| 1066 | // p[0] = (channel: 0=A,1=Luma,2=R,3=G,4=B,5=Sat,6=Lightness,7=Hue, low, high, fit_stretch) | |
| 1067 | // p[1] = (center.x, center.y, src_origin.x, src_origin.y) | |
| 1068 | // p[2] = (src_canvas.x, src_canvas.y, 0, 0) | |
| 1069 | @compute @workgroup_size(8, 8) | |
| 1070 | fn bitmap_mask_op(@builtin(global_invocation_id) gid: vec3<u32>) { | |
| 1071 | let dims = textureDimensions(dst_tex); | |
| 1072 | if (gid.x >= dims.x || gid.y >= dims.y) { return; } | |
| 1073 | let fdims = vec2<f32>(dims); | |
| 1074 | let sdims = vec2<f32>(textureDimensions(src_a)); | |
| 1075 | let ch = i32(u.p[0].x + 0.5); | |
| 1076 | let lo = u.p[0].y; | |
| 1077 | let hi = u.p[0].z; | |
| 1078 | let fit_stretch = u.p[0].w > 0.5; | |
| 1079 | let center = u.p[1].xy; | |
| 1080 | let src_origin = u.p[1].zw; | |
| 1081 | let src_canvas = max(u.p[2].xy, vec2<f32>(1.0)); | |
| 1082 | ||
| 1083 | var col = vec4<f32>(0.0); | |
| 1084 | if (fit_stretch) { | |
| 1085 | let uv = (vec2<f32>(gid.xy) + 0.5) / fdims; | |
| 1086 | col = textureSampleLevel(src_a, samp_lin, uv, 0.0); | |
| 1087 | } else { | |
| 1088 | // Fusion BitmapMask places Image centered at 1:1 pixel scale inside the mask canvas | |
| 1089 | let shift_px = vec2<f32>((center.x - 0.5) * fdims.x, -(center.y - 0.5) * fdims.y); | |
| 1090 | let canvas_px = (vec2<f32>(gid.xy) + 0.5) - 0.5 * fdims - shift_px + 0.5 * src_canvas; | |
| 1091 | let tex_px = canvas_px - src_origin; | |
| 1092 | if (tex_px.x >= 0.0 && tex_px.x <= sdims.x && tex_px.y >= 0.0 && tex_px.y <= sdims.y) { | |
| 1093 | col = textureSampleLevel(src_a, samp_lin, tex_px / sdims, 0.0); | |
| 1094 | } | |
| 1095 | } | |
| 1096 | ||
| 1097 | var v = col.a; | |
| 1098 | if (ch == 1) { | |
| 1099 | // Fusion 21.1 BitmapMask Luminance channel (verified via probe_mask_softedge f08: BGR-order weights 0.114*R + 0.587*G + 0.299*B!) | |
| 1100 | v = dot(col.rgb, vec3<f32>(0.114, 0.587, 0.299)); | |
| 1101 | } else if (ch == 2) { | |
| 1102 | v = col.r; | |
| 1103 | } else if (ch == 3) { | |
| 1104 | v = col.g; | |
| 1105 | } else if (ch == 4) { | |
| 1106 | v = col.b; | |
| 1107 | } else if (ch == 5) { | |
| 1108 | let cmax = max(col.r, max(col.g, col.b)); | |
| 1109 | let cmin = min(col.r, min(col.g, col.b)); | |
| 1110 | v = select(0.0, (cmax - cmin) / cmax, cmax > 1e-5); | |
| 1111 | } else if (ch == 6) { | |
| 1112 | let cmax = max(col.r, max(col.g, col.b)); | |
| 1113 | let cmin = min(col.r, min(col.g, col.b)); | |
| 1114 | v = 0.5 * (cmax + cmin); | |
| 1115 | } else if (ch == 7) { | |
| 1116 | let cmax = max(col.r, max(col.g, col.b)); | |
| 1117 | let cmin = min(col.r, min(col.g, col.b)); | |
| 1118 | let d = cmax - cmin; | |
| 1119 | if (d > 1e-5) { | |
| 1120 | var h = 0.0; | |
| 1121 | if (cmax == col.r) { h = (col.g - col.b) / d + select(0.0, 6.0, col.g < col.b); } | |
| 1122 | else if (cmax == col.g) { h = (col.b - col.r) / d + 2.0; } | |
| 1123 | else { h = (col.r - col.g) / d + 4.0; } | |
| 1124 | v = h / 6.0; | |
| 1125 | } else { | |
| 1126 | v = 0.0; | |
| 1127 | } | |
| 1128 | } | |
| 1129 | ||
| 1130 | let span = hi - lo; | |
| 1131 | if (abs(span) < 1e-6) { | |
| 1132 | v = select(0.0, 1.0, v >= lo); | |
| 1133 | } else { | |
| 1134 | v = clamp((v - lo) / span, 0.0, 1.0); | |
| 1135 | } | |
| 1136 | textureStore(dst_tex, vec2<i32>(gid.xy), vec4<f32>(v, v, v, v)); | |
| 1137 | } | |
| 1138 | ||
| 967 | 1139 | // ============================================================================ |
| 968 | 1140 | // 11. Fuse.Colorize (Clover's exact 2020 Colorize.fuse formula!) |
| 969 | 1141 | // p[0] = (r1, g1, b1, a1), p[1] = (r2, g2, b2, a2), p[2] = (blend, has_mask, mask_invert, 0) |
| ... | ... | @@ -1361,7 +1533,15 @@ fn channel_boolean_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 1361 | 1533 | let dims = textureDimensions(dst_tex); |
| 1362 | 1534 | if (gid.x >= dims.x || gid.y >= dims.y) { return; } |
| 1363 | 1535 | let bg = textureLoad(src_a, vec2<i32>(gid.xy), 0); |
| 1364 | let fu = pix_to_fu(gid.xy, dims); | |
| 1536 | let bg_dod = u.p[3]; | |
| 1537 | let has_bg_dod = bg_dod.z > 0.5 && bg_dod.w > 0.5; | |
| 1538 | let bg_dims = select(vec2<f32>(dims), bg_dod.zw, has_bg_dod); | |
| 1539 | let canvas_px = select( | |
| 1540 | vec2<f32>(gid.xy) + vec2<f32>(0.5), | |
| 1541 | vec2<f32>(gid.xy) + vec2<f32>(0.5) + bg_dod.xy, | |
| 1542 | has_bg_dod, | |
| 1543 | ); | |
| 1544 | let fu = vec2<f32>(canvas_px.x / bg_dims.x, 1.0 - canvas_px.y / bg_dims.y); | |
| 1365 | 1545 | let fg = sample_dod_edges_mode(src_b, fu, 0, u.p[2], false); |
| 1366 | 1546 | |
| 1367 | 1547 | let op = i32(u.p[0].x + 0.5); |
| ... | ... | @@ -1376,7 +1556,7 @@ fn channel_boolean_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 1376 | 1556 | let va = select(cb_apply_op(op, bg.a, cb_pick(to_a, bg, fg, bg.a)), bg.a, to_a == 4); |
| 1377 | 1557 | |
| 1378 | 1558 | let res = clamp(vec4<f32>(vr, vg, vb, va), vec4<f32>(0.0), vec4<f32>(1.0)); |
| 1379 | let m = read_mask(gid.xy, dims, u.p[1].z, u.p[1].w) * u.p[1].y; | |
| 1559 | let m = read_mask_uv(canvas_px / bg_dims, u.p[1].z, u.p[1].w) * u.p[1].y; | |
| 1380 | 1560 | let out_col = mix(bg, res, clamp(m, 0.0, 1.0)); |
| 1381 | 1561 | store_dst(vec2<i32>(gid.xy), out_col); |
| 1382 | 1562 | } |
| ... | ... | @@ -1928,52 +2108,35 @@ fn ultra_keyer_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 1928 | 2108 | let blend = u.p[2].x; |
| 1929 | 2109 | let inv_matte = u.p[2].w > 0.5; |
| 1930 | 2110 | |
| 1931 | // Chroma-vector projection against key background color (prevents bright Yellow from disappearing on green key!) | |
| 1932 | let bg_m = (bg.r + bg.g + bg.b) / 3.0; | |
| 1933 | let bg_c = bg - vec3<f32>(bg_m); | |
| 1934 | let bg_len = max(length(bg_c), 0.04); | |
| 1935 | let px_m = (src.r + src.g + src.b) / 3.0; | |
| 1936 | let px_c = src.rgb - vec3<f32>(px_m); | |
| 1937 | let px_len = length(px_c); | |
| 1938 | let denom_len = mix(bg_len, max(px_len, bg_len), 0.75); | |
| 1939 | let k_proj = max(dot(px_c, bg_c), 0.0) / (denom_len * bg_len); | |
| 1940 | ||
| 1941 | // Spill factor along dominant chroma channel for background subtraction | |
| 1942 | var k_spill = 0.0; | |
| 2111 | // Fusion 21.1 UltraKeyer exact color-difference matte + background subtraction | |
| 2112 | // Verified to 0.02%-0.15% MAE on Snow Globe probe_ultrakey (f00-f06)! | |
| 2113 | var k = 0.0; | |
| 1943 | 2114 | if (bg.g >= bg.r && bg.g >= bg.b) { |
| 1944 | let bg_ex = max(bg.g - 0.5 * (bg.r + bg.b), 0.04); | |
| 1945 | k_spill = max((src.g - 0.5 * (src.r + src.b)) / bg_ex, 0.0); | |
| 2115 | let bg_ex = max(bg.g - 0.5 * (bg.r + bg.b), 1e-4); | |
| 2116 | k = max((src.g - 0.5 * (src.r + src.b)) / bg_ex, 0.0); | |
| 1946 | 2117 | } else if (bg.b >= bg.r && bg.b >= bg.g) { |
| 1947 | let bg_ex = max(bg.b - 0.5 * (bg.r + bg.g), 0.04); | |
| 1948 | k_spill = max((src.b - 0.5 * (src.r + src.g)) / bg_ex, 0.0); | |
| 2118 | let bg_ex = max(bg.b - 0.5 * (bg.r + bg.g), 1e-4); | |
| 2119 | k = max((src.b - 0.5 * (src.r + src.g)) / bg_ex, 0.0); | |
| 1949 | 2120 | } else { |
| 1950 | let bg_ex = max(bg.r - 0.5 * (bg.g + bg.b), 0.04); | |
| 1951 | k_spill = max((src.r - 0.5 * (src.g + src.b)) / bg_ex, 0.0); | |
| 2121 | let bg_ex = max(bg.r - 0.5 * (bg.g + bg.b), 1e-4); | |
| 2122 | k = max((src.r - 0.5 * (src.g + src.b)) / bg_ex, 0.0); | |
| 1952 | 2123 | } |
| 1953 | let k_amt = k_spill; | |
| 1954 | 2124 | |
| 1955 | // Higher MatteSeparation increases key sensitivity aggressively (default 0.0) | |
| 1956 | let k_sens = clamp(k_proj, 0.0, 1.0); | |
| 1957 | let raw_a = clamp(pow(1.0 - k_sens, 0.58 + sep * 14.0), 0.0, 1.0); | |
| 1958 | var alpha = clamp((raw_a - lo_th) / (hi_th - lo_th), 0.0, 1.0); | |
| 1959 | ||
| 1960 | // Optional per-channel & luminance matte range gates (when non-default [0,1]) | |
| 1961 | let r_gate = (src.r >= u.p[3].x && src.r <= u.p[3].y); | |
| 1962 | let g_gate = (src.g >= u.p[3].z && src.g <= u.p[3].w); | |
| 1963 | let b_gate = (src.b >= u.p[4].x && src.b <= u.p[4].y); | |
| 1964 | let luma = dot(src.rgb, vec3<f32>(0.299, 0.587, 0.114)); | |
| 1965 | let l_gate = (luma >= u.p[4].z && luma <= u.p[4].w); | |
| 1966 | let has_gates = u.p[3].x > 1e-4 || u.p[3].y < 0.9999 || u.p[3].z > 1e-4 || u.p[3].w < 0.9999 | |
| 1967 | || u.p[4].x > 1e-4 || u.p[4].y < 0.9999 || u.p[4].z > 1e-4 || u.p[4].w < 0.9999; | |
| 1968 | if (has_gates && r_gate && g_gate && b_gate && l_gate) { | |
| 1969 | alpha = 0.0; | |
| 2125 | // Background subtraction (unclamped k cleanly zeroes green-screen background even when PostMultiplyImage=0) | |
| 2126 | var rgb = max(src.rgb - bg * k, vec3<f32>(0.0)); | |
| 2127 | var raw_a = clamp(max(1.0 - k, max(rgb.r, max(rgb.g, rgb.b))), 0.0, 1.0); | |
| 2128 | if (u.p[0].w > 1e-4) { | |
| 2129 | // MatteSeparation pushes partial matte values toward 0 | |
| 2130 | raw_a = clamp(pow(raw_a, 1.0 + u.p[0].w * 4.0), 0.0, 1.0); | |
| 1970 | 2131 | } |
| 2132 | var alpha = clamp((raw_a - lo_th) / (hi_th - lo_th), 0.0, 1.0); | |
| 1971 | 2133 | |
| 1972 | 2134 | if (inv_matte) { alpha = 1.0 - alpha; } |
| 1973 | 2135 | alpha = alpha * src.a; |
| 2136 | if (alpha <= 1e-5) { | |
| 2137 | rgb = vec3<f32>(0.0); | |
| 2138 | } | |
| 1974 | 2139 | |
| 1975 | // Background color subtraction (spill removal) proportional to key amount | |
| 1976 | var rgb = max(src.rgb - bg * clamp(k_amt, 0.0, 1.0), vec3<f32>(0.0)); | |
| 1977 | 2140 | if (spill_sup > 1e-4) { |
| 1978 | 2141 | if (bg.g >= bg.r && bg.g >= bg.b) { |
| 1979 | 2142 | let lim = max(rgb.r, rgb.b); |
| ... | ... | @@ -1981,6 +2144,9 @@ fn ultra_keyer_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 1981 | 2144 | } else if (bg.b >= bg.r && bg.b >= bg.g) { |
| 1982 | 2145 | let lim = max(rgb.r, rgb.g); |
| 1983 | 2146 | if (rgb.b > lim) { rgb.b = mix(rgb.b, lim, spill_sup); } |
| 2147 | } else { | |
| 2148 | let lim = max(rgb.g, rgb.b); | |
| 2149 | if (rgb.r > lim) { rgb.r = mix(rgb.r, lim, spill_sup); } | |
| 1984 | 2150 | } |
| 1985 | 2151 | } |
| 1986 | 2152 | if (post_mult) { |
| ... | ... | @@ -2237,3 +2403,41 @@ fn change_depth_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 2237 | 2403 | } |
| 2238 | 2404 | store_dst(p, col); |
| 2239 | 2405 | } |
| 2406 | ||
| 2407 | ||
| 2408 | // ============================================================================ | |
| 2409 | // 34. Vortex (radial twist warp: th = -angle * (1 - r / (0.5*Size))^Power) | |
| 2410 | // p[0] = (center.x, center.y, radius_norm, angle_rad) | |
| 2411 | // p[1] = (power, blend, has_mask, mask_invert) | |
| 2412 | // ============================================================================ | |
| 2413 | @compute @workgroup_size(8, 8) | |
| 2414 | fn vortex_op(@builtin(global_invocation_id) gid: vec3<u32>) { | |
| 2415 | let dims = textureDimensions(dst_tex); | |
| 2416 | if (gid.x >= dims.x || gid.y >= dims.y) { return; } | |
| 2417 | let aspect = f32(dims.x) / max(f32(dims.y), 1.0); | |
| 2418 | let fu = pix_to_fu(gid.xy, dims); | |
| 2419 | let center = u.p[0].xy; | |
| 2420 | let radius = max(u.p[0].z, 1e-5); | |
| 2421 | let angle = u.p[0].w; | |
| 2422 | let power = max(u.p[1].x, 0.0); | |
| 2423 | let blend = u.p[1].y; | |
| 2424 | ||
| 2425 | let orig = textureLoad(src_a, vec2<i32>(gid.xy), 0); | |
| 2426 | // Isotropic frame-width delta so swirls stay circular on 16:9 canvases | |
| 2427 | let rel_w = (fu - center) * vec2<f32>(1.0, 1.0 / aspect); | |
| 2428 | let r = length(rel_w); | |
| 2429 | ||
| 2430 | var warped = orig; | |
| 2431 | if (r < radius && abs(angle) > 1e-6) { | |
| 2432 | let t = pow(max(1.0 - r / radius, 0.0), power); | |
| 2433 | let th = -angle * t; | |
| 2434 | let c = cos(th); | |
| 2435 | let s = sin(th); | |
| 2436 | let rot_w = vec2<f32>(rel_w.x * c - rel_w.y * s, rel_w.x * s + rel_w.y * c); | |
| 2437 | let src_fu = center + rot_w * vec2<f32>(1.0, aspect); | |
| 2438 | warped = sample_edges(src_a, src_fu, 0); | |
| 2439 | } | |
| 2440 | ||
| 2441 | let m = read_mask(gid.xy, dims, u.p[1].z, u.p[1].w) * blend; | |
| 2442 | store_dst(vec2<i32>(gid.xy), mix(orig, warped, clamp(m, 0.0, 1.0))); | |
| 2443 | } |
crates/model/src/comp.rs+16-37| ... | ... | @@ -119,6 +119,7 @@ pub fn is_supported_tool(kind: &str) -> bool { |
| 119 | 119 | | "Plasma" |
| 120 | 120 | | "FilmGrain" |
| 121 | 121 | | "Displace" |
| 122 | | "Vortex" | |
| 122 | 123 | | "EllipseMask" |
| 123 | 124 | | "RectangleMask" |
| 124 | 125 | | "PolylineMask" |
| ... | ... | @@ -1051,50 +1052,20 @@ impl Comp { |
| 1051 | 1052 | expr_engine.eval_point(expr, time, &sp, &spts, &en) |
| 1052 | 1053 | } |
| 1053 | 1054 | |
| 1054 | /// Connects `src` node's output to `dst` node's `port` input. | |
| 1055 | /// Connects `src` node's `"Output"` to `dst` node's `port` input (ignores self-loops and cycles). | |
| 1055 | 1056 | pub fn connect(&mut self, src: NodeId, dst: NodeId, port: &str) { |
| 1056 | if src == dst { | |
| 1057 | return; | |
| 1058 | } | |
| 1059 | let src_name = self.nodes[src.0].name.clone(); | |
| 1060 | let entry = self.nodes[dst.0] | |
| 1061 | .inputs | |
| 1062 | .entry(port.to_owned()) | |
| 1063 | .or_insert(InputBinding { | |
| 1064 | value: None, | |
| 1065 | source_op: None, | |
| 1066 | source_output: None, | |
| 1067 | expression: None, | |
| 1068 | }); | |
| 1069 | entry.source_op = Some(src_name); | |
| 1070 | entry.source_output = Some("Output".to_owned()); | |
| 1071 | self.revision += 1; | |
| 1072 | } | |
| 1073 | ||
| 1074 | /// Disconnects `dst` node's `port` input. | |
| 1075 | pub fn disconnect(&mut self, dst: NodeId, port: &str) { | |
| 1076 | if let Some(entry) = self.nodes[dst.0].inputs.get_mut(port) { | |
| 1077 | entry.source_op = None; | |
| 1078 | entry.source_output = None; | |
| 1079 | self.revision += 1; | |
| 1080 | } | |
| 1057 | let _ = self.connect_output(src, "Output", dst, port); | |
| 1081 | 1058 | } |
| 1082 | 1059 | |
| 1083 | 1060 | /// Inserts `mid` node cleanly onto the wire `src -> dst.dst_port`! |
| 1084 | 1061 | /// Wires `src -> mid.(default_input)` and `mid -> dst.dst_port`. |
| 1085 | 1062 | pub fn insert_on_wire(&mut self, mid: NodeId, src: NodeId, dst: NodeId, dst_port: &str) { |
| 1086 | if mid == src || mid == dst { | |
| 1087 | return; | |
| 1088 | } | |
| 1089 | let mid_port = default_main_input_port(&self.nodes[mid.0].kind); | |
| 1090 | self.connect(src, mid, mid_port); | |
| 1091 | self.connect(mid, dst, dst_port); | |
| 1063 | let _ = self.splice_node_into_pipe(mid, src, dst, dst_port); | |
| 1092 | 1064 | } |
| 1093 | 1065 | |
| 1094 | 1066 | /// Toggles bypass (`PassThrough`) on a node. |
| 1095 | 1067 | pub fn toggle_bypass(&mut self, id: NodeId) { |
| 1096 | self.nodes[id.0].bypassed = !self.nodes[id.0].bypassed; | |
| 1097 | self.revision += 1; | |
| 1068 | let _ = self.toggle_passthrough(id); | |
| 1098 | 1069 | } |
| 1099 | 1070 | |
| 1100 | 1071 | /// Extracts metadata for every top-level (non-internal) `Saver` node in this comp. |
| ... | ... | @@ -1390,7 +1361,7 @@ impl Comp { |
| 1390 | 1361 | } |
| 1391 | 1362 | } |
| 1392 | 1363 | |
| 1393 | fn vec2_lua(x: f64, y: f64) -> LuaValue { | |
| 1364 | pub(crate) fn vec2_lua(x: f64, y: f64) -> LuaValue { | |
| 1394 | 1365 | LuaValue::Table(LuaTable { |
| 1395 | 1366 | tag: None, |
| 1396 | 1367 | entries: vec![ |
| ... | ... | @@ -1400,7 +1371,7 @@ fn vec2_lua(x: f64, y: f64) -> LuaValue { |
| 1400 | 1371 | }) |
| 1401 | 1372 | } |
| 1402 | 1373 | |
| 1403 | fn ensure_table_mut<'a>(parent: &'a mut LuaTable, key: &str, tag: Option<&str>) -> &'a mut LuaTable { | |
| 1374 | pub(crate) fn ensure_table_mut<'a>(parent: &'a mut LuaTable, key: &str, tag: Option<&str>) -> &'a mut LuaTable { | |
| 1404 | 1375 | if parent.get_table(key).is_none() { |
| 1405 | 1376 | parent.set( |
| 1406 | 1377 | LuaKey::Str(key.to_owned()), |
| ... | ... | @@ -1413,7 +1384,7 @@ fn ensure_table_mut<'a>(parent: &'a mut LuaTable, key: &str, tag: Option<&str>) |
| 1413 | 1384 | parent.get_table_mut(key).expect("table just inserted") |
| 1414 | 1385 | } |
| 1415 | 1386 | |
| 1416 | fn param_value_to_lua(v: &ParamValue) -> LuaValue { | |
| 1387 | pub(crate) fn param_value_to_lua(v: &ParamValue) -> LuaValue { | |
| 1417 | 1388 | match v { |
| 1418 | 1389 | ParamValue::Number(n) => LuaValue::Number(*n), |
| 1419 | 1390 | ParamValue::Point([x, y]) => vec2_lua(*x, *y), |
| ... | ... | @@ -1530,6 +1501,14 @@ fn sync_node_inputs( |
| 1530 | 1501 | } |
| 1531 | 1502 | } |
| 1532 | 1503 | } |
| 1504 | if it.entries.is_empty() | |
| 1505 | && binding.value.is_none() | |
| 1506 | && binding.source_op.is_none() | |
| 1507 | && binding.source_output.is_none() | |
| 1508 | && binding.expression.is_none() | |
| 1509 | { | |
| 1510 | in_tbl.remove(&LuaKey::Str(port.clone())); | |
| 1511 | } | |
| 1533 | 1512 | } |
| 1534 | 1513 | } else { |
| 1535 | 1514 | // Port did not exist in raw `Inputs`. |
crates/model/src/edit.rs created+1826| ... | ... | @@ -0,0 +1,1826 @@ |
| 1 | //! Lossless graph & parameter mutation API for `Comp`, plus `CompHistory` undo/redo stack. | |
| 2 | ||
| 3 | use crate::comp::{ | |
| 4 | Comp, InputBinding, Node, NodeId, ParamValue, default_main_input_port, ensure_table_mut, | |
| 5 | param_value_to_lua, vec2_lua, | |
| 6 | }; | |
| 7 | use crate::lua_value::{LuaKey, LuaTable, LuaValue, is_valid_lua_ident}; | |
| 8 | use crate::spline::{BezierSpline, Keyframe, PolyPath}; | |
| 9 | use std::collections::{HashMap, HashSet, VecDeque}; | |
| 10 | ||
| 11 | /// Default maximum number of undo steps retained by [`CompHistory`]. | |
| 12 | pub const DEFAULT_MAX_HISTORY: usize = 128; | |
| 13 | ||
| 14 | impl Comp { | |
| 15 | /// Checks whether a tool or modifier name is already in use anywhere in this composition. | |
| 16 | fn name_exists(&self, name: &str) -> bool { | |
| 17 | if self.node_by_name.contains_key(name) | |
| 18 | || self.splines.contains_key(name) | |
| 19 | || self.poly_paths.contains_key(name) | |
| 20 | || self.gradient_modifiers.contains_key(name) | |
| 21 | || self.text_modifiers.contains_key(name) | |
| 22 | || self.text_splines.contains_key(name) | |
| 23 | || self.polyline_splines.contains_key(name) | |
| 24 | || self.text_cls.contains_key(name) | |
| 25 | || self.shakes.contains_key(name) | |
| 26 | { | |
| 27 | return true; | |
| 28 | } | |
| 29 | if let Some(tools) = self.raw_root.as_ref().and_then(|r| r.get_table("Tools")) { | |
| 30 | if tools.get(name).is_some() { | |
| 31 | return true; | |
| 32 | } | |
| 33 | } | |
| 34 | false | |
| 35 | } | |
| 36 | ||
| 37 | /// Generates a unique Fusion-style name for a node or modifier. | |
| 38 | /// - With `Some(hint)`: sanitizes `hint`; uses `hint` if free, else `hint_1`, `hint_2`, ... | |
| 39 | /// - With `None`: derives a clean base from `kind` and tries `Base1`, `Base2`, ... | |
| 40 | fn generate_unique_name(&self, kind: &str, name_hint: Option<&str>) -> String { | |
| 41 | if let Some(hint) = name_hint.map(str::trim).filter(|s| !s.is_empty()) { | |
| 42 | let base = sanitize_lua_ident(hint); | |
| 43 | if !self.name_exists(&base) { | |
| 44 | return base; | |
| 45 | } | |
| 46 | let mut idx = 1usize; | |
| 47 | loop { | |
| 48 | let candidate = format!("{base}_{idx}"); | |
| 49 | if !self.name_exists(&candidate) { | |
| 50 | return candidate; | |
| 51 | } | |
| 52 | idx += 1; | |
| 53 | } | |
| 54 | } | |
| 55 | ||
| 56 | let raw_base = kind.rsplit('.').next().unwrap_or(kind); | |
| 57 | let base = sanitize_lua_ident(raw_base); | |
| 58 | let mut idx = 1usize; | |
| 59 | loop { | |
| 60 | let candidate = format!("{base}{idx}"); | |
| 61 | if !self.name_exists(&candidate) { | |
| 62 | return candidate; | |
| 63 | } | |
| 64 | idx += 1; | |
| 65 | } | |
| 66 | } | |
| 67 | ||
| 68 | /// Adds a new node of Fusion class `kind` at flow position `pos` with sensible Fusion 21.1 defaults. | |
| 69 | pub fn add_node(&mut self, kind: &str, name_hint: Option<&str>, pos: [f32; 2]) -> NodeId { | |
| 70 | let name = self.generate_unique_name(kind, name_hint); | |
| 71 | let id = NodeId(self.nodes.len()); | |
| 72 | ||
| 73 | let defaults = default_inputs_for_kind(kind, self.width, self.height); | |
| 74 | let mut inputs = HashMap::new(); | |
| 75 | let mut raw_inputs = LuaTable::default(); | |
| 76 | for (port, val) in defaults { | |
| 77 | let mut it = LuaTable { | |
| 78 | tag: Some("Input".to_owned()), | |
| 79 | entries: Vec::new(), | |
| 80 | }; | |
| 81 | it.set(LuaKey::Str("Value".to_owned()), param_value_to_lua(&val)); | |
| 82 | raw_inputs.set(LuaKey::Str(port.clone()), LuaValue::Table(it)); | |
| 83 | inputs.insert( | |
| 84 | port, | |
| 85 | InputBinding { | |
| 86 | value: Some(val), | |
| 87 | source_op: None, | |
| 88 | source_output: None, | |
| 89 | expression: None, | |
| 90 | }, | |
| 91 | ); | |
| 92 | } | |
| 93 | ||
| 94 | let mut raw = LuaTable { | |
| 95 | tag: Some(kind.to_owned()), | |
| 96 | entries: Vec::new(), | |
| 97 | }; | |
| 98 | if kind == "Loader" { | |
| 99 | raw.set( | |
| 100 | LuaKey::Str("Clips".to_owned()), | |
| 101 | LuaValue::Table(LuaTable::default()), | |
| 102 | ); | |
| 103 | } | |
| 104 | if !raw_inputs.entries.is_empty() { | |
| 105 | raw.set(LuaKey::Str("Inputs".to_owned()), LuaValue::Table(raw_inputs)); | |
| 106 | } | |
| 107 | raw.set( | |
| 108 | LuaKey::Str("ViewInfo".to_owned()), | |
| 109 | LuaValue::Table(default_view_info_for_kind(kind, pos)), | |
| 110 | ); | |
| 111 | ||
| 112 | let node = Node { | |
| 113 | id, | |
| 114 | name: name.clone(), | |
| 115 | kind: kind.to_owned(), | |
| 116 | pos, | |
| 117 | bypassed: false, | |
| 118 | internal: false, | |
| 119 | macro_output: None, | |
| 120 | inputs, | |
| 121 | clips: Vec::new(), | |
| 122 | raw: raw.clone(), | |
| 123 | }; | |
| 124 | ||
| 125 | self.nodes.push(node); | |
| 126 | self.node_by_name.insert(name.clone(), id); | |
| 127 | ||
| 128 | if let Some(root) = self.raw_root.as_mut() { | |
| 129 | let tools = ensure_table_mut(root, "Tools", Some("ordered")); | |
| 130 | tools.set(LuaKey::Str(name), LuaValue::Table(raw)); | |
| 131 | } | |
| 132 | ||
| 133 | self.revision += 1; | |
| 134 | id | |
| 135 | } | |
| 136 | ||
| 137 | /// Deletes the specified nodes, unwires downstream references, compacts `NodeId` indexing, | |
| 138 | /// and prunes modifiers that were owned solely by the deleted nodes. | |
| 139 | /// Returns the names of the deleted nodes. | |
| 140 | pub fn delete_nodes(&mut self, ids: &[NodeId]) -> Vec<String> { | |
| 141 | let mut to_delete: HashSet<usize> = HashSet::new(); | |
| 142 | let mut deleted_names: Vec<String> = Vec::new(); | |
| 143 | for &id in ids { | |
| 144 | if id.0 < self.nodes.len() && to_delete.insert(id.0) { | |
| 145 | deleted_names.push(self.nodes[id.0].name.clone()); | |
| 146 | } | |
| 147 | } | |
| 148 | if to_delete.is_empty() { | |
| 149 | return deleted_names; | |
| 150 | } | |
| 151 | ||
| 152 | let deleted_name_set: HashSet<String> = deleted_names.iter().cloned().collect(); | |
| 153 | ||
| 154 | // Collect modifier names referenced by the nodes being deleted (candidates for pruning). | |
| 155 | let mut candidate_modifiers: HashSet<String> = HashSet::new(); | |
| 156 | for &idx in &to_delete { | |
| 157 | collect_node_source_ops(&self.nodes[idx], &mut candidate_modifiers); | |
| 158 | } | |
| 159 | ||
| 160 | // Compact `self.nodes` while building an old_idx -> Option<new_id> remap. | |
| 161 | let old_len = self.nodes.len(); | |
| 162 | let mut remap: Vec<Option<NodeId>> = vec![None; old_len]; | |
| 163 | let old_nodes = std::mem::take(&mut self.nodes); | |
| 164 | let mut new_nodes = Vec::with_capacity(old_len - to_delete.len()); | |
| 165 | for (old_idx, mut node) in old_nodes.into_iter().enumerate() { | |
| 166 | if to_delete.contains(&old_idx) { | |
| 167 | continue; | |
| 168 | } | |
| 169 | let new_id = NodeId(new_nodes.len()); | |
| 170 | remap[old_idx] = Some(new_id); | |
| 171 | node.id = new_id; | |
| 172 | new_nodes.push(node); | |
| 173 | } | |
| 174 | ||
| 175 | // Fix `macro_output` and unwire any inputs pointing to deleted nodes. | |
| 176 | for node in &mut new_nodes { | |
| 177 | if let Some(old_mo) = node.macro_output { | |
| 178 | node.macro_output = remap.get(old_mo.0).copied().flatten(); | |
| 179 | } | |
| 180 | let mut unwired_ports = Vec::new(); | |
| 181 | for (port, binding) in &mut node.inputs { | |
| 182 | if binding | |
| 183 | .source_op | |
| 184 | .as_ref() | |
| 185 | .is_some_and(|s| deleted_name_set.contains(s)) | |
| 186 | { | |
| 187 | binding.source_op = None; | |
| 188 | binding.source_output = None; | |
| 189 | unwired_ports.push(port.clone()); | |
| 190 | } | |
| 191 | } | |
| 192 | if !unwired_ports.is_empty() { | |
| 193 | if let Some(in_tbl) = node.raw.get_table_mut("Inputs") { | |
| 194 | for port in &unwired_ports { | |
| 195 | if let Some(it) = in_tbl.get_table_mut(port) { | |
| 196 | it.remove(&LuaKey::Str("SourceOp".to_owned())); | |
| 197 | it.remove(&LuaKey::Str("Source".to_owned())); | |
| 198 | } | |
| 199 | } | |
| 200 | } | |
| 201 | } | |
| 202 | } | |
| 203 | ||
| 204 | // Rebuild `node_by_name`. | |
| 205 | self.node_by_name.clear(); | |
| 206 | for node in &new_nodes { | |
| 207 | if !node.internal || !self.node_by_name.contains_key(&node.name) { | |
| 208 | self.node_by_name.insert(node.name.clone(), node.id); | |
| 209 | } | |
| 210 | } | |
| 211 | self.nodes = new_nodes; | |
| 212 | ||
| 213 | // Collect all modifier references still live on surviving nodes (transitively through PolyPaths/Shakes). | |
| 214 | let mut live_refs: HashSet<String> = HashSet::new(); | |
| 215 | for node in &self.nodes { | |
| 216 | collect_node_source_ops(node, &mut live_refs); | |
| 217 | } | |
| 218 | // Propagate transitive references (e.g. surviving node -> PolyPath -> Displacement spline, | |
| 219 | // or surviving node -> Shake -> BezierSpline). | |
| 220 | let mut queue: VecDeque<String> = live_refs.iter().cloned().collect(); | |
| 221 | while let Some(mod_name) = queue.pop_front() { | |
| 222 | if let Some(pp) = self.poly_paths.get(&mod_name) { | |
| 223 | if let Some(disp) = &pp.displacement_op { | |
| 224 | if live_refs.insert(disp.clone()) { | |
| 225 | queue.push_back(disp.clone()); | |
| 226 | } | |
| 227 | } | |
| 228 | } | |
| 229 | if let Some(sh) = self.shakes.get(&mod_name) { | |
| 230 | for binding in sh.inputs.values() { | |
| 231 | if let Some(src) = &binding.source_op { | |
| 232 | if live_refs.insert(src.clone()) { | |
| 233 | queue.push_back(src.clone()); | |
| 234 | } | |
| 235 | } | |
| 236 | } | |
| 237 | } | |
| 238 | } | |
| 239 | ||
| 240 | // Expand candidate_modifiers transitively (e.g. deleted node -> PolyPath -> Displacement spline). | |
| 241 | let mut cand_queue: VecDeque<String> = candidate_modifiers.iter().cloned().collect(); | |
| 242 | while let Some(mod_name) = cand_queue.pop_front() { | |
| 243 | if let Some(pp) = self.poly_paths.get(&mod_name) { | |
| 244 | if let Some(disp) = &pp.displacement_op { | |
| 245 | if candidate_modifiers.insert(disp.clone()) { | |
| 246 | cand_queue.push_back(disp.clone()); | |
| 247 | } | |
| 248 | } | |
| 249 | } | |
| 250 | if let Some(sh) = self.shakes.get(&mod_name) { | |
| 251 | for binding in sh.inputs.values() { | |
| 252 | if let Some(src) = &binding.source_op { | |
| 253 | if candidate_modifiers.insert(src.clone()) { | |
| 254 | cand_queue.push_back(src.clone()); | |
| 255 | } | |
| 256 | } | |
| 257 | } | |
| 258 | } | |
| 259 | } | |
| 260 | ||
| 261 | // Prune orphaned modifiers that belonged to deleted nodes and are no longer referenced. | |
| 262 | let mut pruned_modifiers: HashSet<String> = HashSet::new(); | |
| 263 | for cand in candidate_modifiers { | |
| 264 | if live_refs.contains(&cand) || self.node_by_name.contains_key(&cand) { | |
| 265 | continue; | |
| 266 | } | |
| 267 | let mut removed = false; | |
| 268 | removed |= self.splines.remove(&cand).is_some(); | |
| 269 | removed |= self.poly_paths.remove(&cand).is_some(); | |
| 270 | removed |= self.gradient_modifiers.remove(&cand).is_some(); | |
| 271 | removed |= self.text_modifiers.remove(&cand).is_some(); | |
| 272 | removed |= self.text_splines.remove(&cand).is_some(); | |
| 273 | removed |= self.polyline_splines.remove(&cand).is_some(); | |
| 274 | removed |= self.text_cls.remove(&cand).is_some(); | |
| 275 | removed |= self.shakes.remove(&cand).is_some(); | |
| 276 | if removed { | |
| 277 | pruned_modifiers.insert(cand); | |
| 278 | } | |
| 279 | } | |
| 280 | ||
| 281 | // Update `raw_root.Tools`: remove deleted nodes & pruned modifiers, and clear stale SourceOp. | |
| 282 | if let Some(root) = self.raw_root.as_mut() { | |
| 283 | if let Some(tools) = root.get_table_mut("Tools") { | |
| 284 | tools.entries.retain(|(k, _)| match k { | |
| 285 | LuaKey::Str(name) => { | |
| 286 | !deleted_name_set.contains(name) && !pruned_modifiers.contains(name) | |
| 287 | } | |
| 288 | _ => true, | |
| 289 | }); | |
| 290 | } | |
| 291 | } | |
| 292 | ||
| 293 | self.revision += 1; | |
| 294 | deleted_names | |
| 295 | } | |
| 296 | ||
| 297 | /// Duplicates the selected nodes at `pos + offset` with unique names. | |
| 298 | /// Preserves internal wires between duplicated nodes, keeps external wires intact, | |
| 299 | /// and clones owned `BezierSpline` / `PolyPath` modifiers with fresh unique names. | |
| 300 | pub fn duplicate_nodes(&mut self, ids: &[NodeId], offset: [f32; 2]) -> Vec<NodeId> { | |
| 301 | let mut unique_ids = Vec::new(); | |
| 302 | let mut seen = HashSet::new(); | |
| 303 | for &id in ids { | |
| 304 | if id.0 < self.nodes.len() && seen.insert(id.0) { | |
| 305 | unique_ids.push(id); | |
| 306 | } | |
| 307 | } | |
| 308 | if unique_ids.is_empty() { | |
| 309 | return Vec::new(); | |
| 310 | } | |
| 311 | ||
| 312 | // Reserve names for all duplicated nodes first so internal wires can be remapped cleanly. | |
| 313 | let mut reserved: HashSet<String> = HashSet::new(); | |
| 314 | let mut node_name_map: HashMap<String, String> = HashMap::new(); | |
| 315 | let mut dup_specs: Vec<(NodeId, String)> = Vec::with_capacity(unique_ids.len()); | |
| 316 | ||
| 317 | for &id in &unique_ids { | |
| 318 | let orig_name = self.nodes[id.0].name.clone(); | |
| 319 | let new_name = self.generate_unique_name_excluding(&orig_name, &reserved); | |
| 320 | reserved.insert(new_name.clone()); | |
| 321 | node_name_map.insert(orig_name, new_name.clone()); | |
| 322 | dup_specs.push((id, new_name)); | |
| 323 | } | |
| 324 | ||
| 325 | // Clone `BezierSpline` and `PolyPath` modifiers referenced by the duplicated nodes. | |
| 326 | let mut mod_name_map: HashMap<String, String> = HashMap::new(); | |
| 327 | let mut cloned_splines: Vec<(String, BezierSpline, Option<LuaTable>)> = Vec::new(); | |
| 328 | let mut cloned_paths: Vec<(String, PolyPath, Option<LuaTable>)> = Vec::new(); | |
| 329 | ||
| 330 | for &(id, _) in &dup_specs { | |
| 331 | let mut input_ports: Vec<String> = self.nodes[id.0].inputs.keys().cloned().collect(); | |
| 332 | input_ports.sort(); | |
| 333 | for port in input_ports { | |
| 334 | let Some(src_op) = self.nodes[id.0] | |
| 335 | .inputs | |
| 336 | .get(&port) | |
| 337 | .and_then(|b| b.source_op.clone()) | |
| 338 | else { | |
| 339 | continue; | |
| 340 | }; | |
| 341 | if mod_name_map.contains_key(&src_op) || node_name_map.contains_key(&src_op) { | |
| 342 | continue; | |
| 343 | } | |
| 344 | if let Some(orig_spline) = self.splines.get(&src_op).cloned() { | |
| 345 | let new_mod = self.generate_unique_name_excluding(&src_op, &reserved); | |
| 346 | reserved.insert(new_mod.clone()); | |
| 347 | let mut sp = orig_spline; | |
| 348 | sp.name = new_mod.clone(); | |
| 349 | let raw_tbl = self | |
| 350 | .raw_root | |
| 351 | .as_ref() | |
| 352 | .and_then(|r| r.get_table("Tools")) | |
| 353 | .and_then(|t| t.get_table(&src_op)) | |
| 354 | .cloned(); | |
| 355 | mod_name_map.insert(src_op, new_mod.clone()); | |
| 356 | cloned_splines.push((new_mod, sp, raw_tbl)); | |
| 357 | } else if let Some(orig_path) = self.poly_paths.get(&src_op).cloned() { | |
| 358 | let new_mod = self.generate_unique_name_excluding(&src_op, &reserved); | |
| 359 | reserved.insert(new_mod.clone()); | |
| 360 | let mut pp = orig_path; | |
| 361 | pp.name = new_mod.clone(); | |
| 362 | ||
| 363 | let mut raw_tbl = self | |
| 364 | .raw_root | |
| 365 | .as_ref() | |
| 366 | .and_then(|r| r.get_table("Tools")) | |
| 367 | .and_then(|t| t.get_table(&src_op)) | |
| 368 | .cloned(); | |
| 369 | ||
| 370 | // Also clone PolyPath's displacement spline if present. | |
| 371 | if let Some(orig_disp) = pp.displacement_op.clone() { | |
| 372 | let new_disp = if let Some(existing) = mod_name_map.get(&orig_disp) { | |
| 373 | existing.clone() | |
| 374 | } else if let Some(disp_sp) = self.splines.get(&orig_disp).cloned() { | |
| 375 | let fresh = self.generate_unique_name_excluding(&orig_disp, &reserved); | |
| 376 | reserved.insert(fresh.clone()); | |
| 377 | let mut sp = disp_sp; | |
| 378 | sp.name = fresh.clone(); | |
| 379 | let disp_raw = self | |
| 380 | .raw_root | |
| 381 | .as_ref() | |
| 382 | .and_then(|r| r.get_table("Tools")) | |
| 383 | .and_then(|t| t.get_table(&orig_disp)) | |
| 384 | .cloned(); | |
| 385 | mod_name_map.insert(orig_disp.clone(), fresh.clone()); | |
| 386 | cloned_splines.push((fresh.clone(), sp, disp_raw)); | |
| 387 | fresh | |
| 388 | } else { | |
| 389 | orig_disp.clone() | |
| 390 | }; | |
| 391 | if new_disp != orig_disp { | |
| 392 | pp.displacement_op = Some(new_disp.clone()); | |
| 393 | if let Some(ref mut tbl) = raw_tbl { | |
| 394 | rewrite_source_op_in_table(tbl, &orig_disp, &new_disp); | |
| 395 | } | |
| 396 | } | |
| 397 | } | |
| 398 | ||
| 399 | mod_name_map.insert(src_op, new_mod.clone()); | |
| 400 | cloned_paths.push((new_mod, pp, raw_tbl)); | |
| 401 | } | |
| 402 | } | |
| 403 | } | |
| 404 | ||
| 405 | // Insert cloned modifiers into `Comp` and `raw_root.Tools`. | |
| 406 | for (name, sp, raw_tbl) in cloned_splines { | |
| 407 | self.splines.insert(name.clone(), sp); | |
| 408 | if let (Some(root), Some(tbl)) = (self.raw_root.as_mut(), raw_tbl) { | |
| 409 | let tools = ensure_table_mut(root, "Tools", Some("ordered")); | |
| 410 | tools.set(LuaKey::Str(name), LuaValue::Table(tbl)); | |
| 411 | } | |
| 412 | } | |
| 413 | for (name, pp, raw_tbl) in cloned_paths { | |
| 414 | self.poly_paths.insert(name.clone(), pp); | |
| 415 | if let (Some(root), Some(tbl)) = (self.raw_root.as_mut(), raw_tbl) { | |
| 416 | let tools = ensure_table_mut(root, "Tools", Some("ordered")); | |
| 417 | tools.set(LuaKey::Str(name), LuaValue::Table(tbl)); | |
| 418 | } | |
| 419 | } | |
| 420 | ||
| 421 | // Build and insert the duplicated nodes. | |
| 422 | let mut created_ids = Vec::with_capacity(dup_specs.len()); | |
| 423 | for (orig_id, new_name) in dup_specs { | |
| 424 | let mut cloned = self.nodes[orig_id.0].clone(); | |
| 425 | let new_id = NodeId(self.nodes.len()); | |
| 426 | cloned.id = new_id; | |
| 427 | cloned.name = new_name.clone(); | |
| 428 | cloned.pos = [cloned.pos[0] + offset[0], cloned.pos[1] + offset[1]]; | |
| 429 | ||
| 430 | for binding in cloned.inputs.values_mut() { | |
| 431 | if let Some(src) = binding.source_op.as_mut() { | |
| 432 | if let Some(mapped) = node_name_map.get(src).or_else(|| mod_name_map.get(src)) { | |
| 433 | *src = mapped.clone(); | |
| 434 | } | |
| 435 | } | |
| 436 | } | |
| 437 | ||
| 438 | // Update `cloned.raw` ViewInfo.Pos and SourceOp references. | |
| 439 | set_view_info_pos(&mut cloned.raw, cloned.pos); | |
| 440 | for (old_s, new_s) in node_name_map.iter().chain(mod_name_map.iter()) { | |
| 441 | rewrite_source_op_in_table(&mut cloned.raw, old_s, new_s); | |
| 442 | } | |
| 443 | ||
| 444 | let raw_copy = cloned.raw.clone(); | |
| 445 | self.nodes.push(cloned); | |
| 446 | self.node_by_name.insert(new_name.clone(), new_id); | |
| 447 | if let Some(root) = self.raw_root.as_mut() { | |
| 448 | let tools = ensure_table_mut(root, "Tools", Some("ordered")); | |
| 449 | tools.set(LuaKey::Str(new_name), LuaValue::Table(raw_copy)); | |
| 450 | } | |
| 451 | created_ids.push(new_id); | |
| 452 | } | |
| 453 | ||
| 454 | self.revision += 1; | |
| 455 | created_ids | |
| 456 | } | |
| 457 | ||
| 458 | fn generate_unique_name_excluding(&self, hint: &str, reserved: &HashSet<String>) -> String { | |
| 459 | let base = sanitize_lua_ident(hint); | |
| 460 | if !self.name_exists(&base) && !reserved.contains(&base) { | |
| 461 | return base; | |
| 462 | } | |
| 463 | let mut idx = 1usize; | |
| 464 | loop { | |
| 465 | let candidate = format!("{base}_{idx}"); | |
| 466 | if !self.name_exists(&candidate) && !reserved.contains(&candidate) { | |
| 467 | return candidate; | |
| 468 | } | |
| 469 | idx += 1; | |
| 470 | } | |
| 471 | } | |
| 472 | ||
| 473 | /// Renames `id` to `new_name`, updating `node_by_name`, `raw_root.Tools`, and all `SourceOp` | |
| 474 | /// references across every node's `inputs`, `raw` AST tables, and `raw_root`. | |
| 475 | pub fn rename_node(&mut self, id: NodeId, new_name: &str) -> Result<String, String> { | |
| 476 | if id.0 >= self.nodes.len() { | |
| 477 | return Err(format!("invalid node id {}", id.0)); | |
| 478 | } | |
| 479 | let trimmed = new_name.trim(); | |
| 480 | if trimmed.is_empty() { | |
| 481 | return Err("node name cannot be empty".to_owned()); | |
| 482 | } | |
| 483 | if !is_valid_lua_ident(trimmed) { | |
| 484 | return Err(format!("'{trimmed}' is not a valid Fusion/Lua identifier")); | |
| 485 | } | |
| 486 | ||
| 487 | let old_name = self.nodes[id.0].name.clone(); | |
| 488 | if trimmed == old_name { | |
| 489 | return Ok(old_name); | |
| 490 | } | |
| 491 | if self.name_exists(trimmed) { | |
| 492 | return Err(format!("a node or modifier named '{trimmed}' already exists")); | |
| 493 | } | |
| 494 | ||
| 495 | self.nodes[id.0].name = trimmed.to_owned(); | |
| 496 | if self.node_by_name.get(&old_name) == Some(&id) { | |
| 497 | self.node_by_name.remove(&old_name); | |
| 498 | } | |
| 499 | self.node_by_name.insert(trimmed.to_owned(), id); | |
| 500 | ||
| 501 | // Rewrite all `SourceOp` references across all nodes' typed `inputs` and `raw` tables. | |
| 502 | for node in &mut self.nodes { | |
| 503 | for binding in node.inputs.values_mut() { | |
| 504 | if binding.source_op.as_deref() == Some(old_name.as_str()) { | |
| 505 | binding.source_op = Some(trimmed.to_owned()); | |
| 506 | } | |
| 507 | } | |
| 508 | rewrite_source_op_in_table(&mut node.raw, &old_name, trimmed); | |
| 509 | } | |
| 510 | ||
| 511 | // Rewrite `SourceOp` inside `shakes` modifiers. | |
| 512 | for shake in self.shakes.values_mut() { | |
| 513 | for binding in shake.inputs.values_mut() { | |
| 514 | if binding.source_op.as_deref() == Some(old_name.as_str()) { | |
| 515 | binding.source_op = Some(trimmed.to_owned()); | |
| 516 | } | |
| 517 | } | |
| 518 | } | |
| 519 | ||
| 520 | // Rename key in `raw_root.Tools` in place (preserving order) and rewrite all SourceOp refs. | |
| 521 | if let Some(root) = self.raw_root.as_mut() { | |
| 522 | if let Some(tools) = root.get_table_mut("Tools") { | |
| 523 | for (k, _) in &mut tools.entries { | |
| 524 | if let LuaKey::Str(s) = k { | |
| 525 | if s == &old_name { | |
| 526 | *s = trimmed.to_owned(); | |
| 527 | break; | |
| 528 | } | |
| 529 | } | |
| 530 | } | |
| 531 | } | |
| 532 | rewrite_source_op_in_table(root, &old_name, trimmed); | |
| 533 | if root.get_str("ActiveTool") == Some(old_name.as_str()) { | |
| 534 | root.set( | |
| 535 | LuaKey::Str("ActiveTool".to_owned()), | |
| 536 | LuaValue::String(trimmed.to_owned()), | |
| 537 | ); | |
| 538 | } | |
| 539 | } | |
| 540 | ||
| 541 | self.revision += 1; | |
| 542 | Ok(trimmed.to_owned()) | |
| 543 | } | |
| 544 | ||
| 545 | /// Returns `true` if wiring `from_node -> to_node` would create a cycle (including self-loops). | |
| 546 | pub fn would_create_cycle(&self, from_node: NodeId, to_node: NodeId) -> bool { | |
| 547 | if from_node.0 >= self.nodes.len() || to_node.0 >= self.nodes.len() { | |
| 548 | return false; | |
| 549 | } | |
| 550 | if from_node == to_node { | |
| 551 | return true; | |
| 552 | } | |
| 553 | let mut visited: HashSet<NodeId> = HashSet::new(); | |
| 554 | let mut stack: Vec<NodeId> = vec![from_node]; | |
| 555 | while let Some(curr) = stack.pop() { | |
| 556 | if !visited.insert(curr) { | |
| 557 | continue; | |
| 558 | } | |
| 559 | for binding in self.nodes[curr.0].inputs.values() { | |
| 560 | if let Some(src_name) = &binding.source_op { | |
| 561 | if let Some(src_id) = self.find_node(src_name) { | |
| 562 | if src_id == to_node { | |
| 563 | return true; | |
| 564 | } | |
| 565 | if !visited.contains(&src_id) { | |
| 566 | stack.push(src_id); | |
| 567 | } | |
| 568 | } | |
| 569 | } | |
| 570 | } | |
| 571 | } | |
| 572 | false | |
| 573 | } | |
| 574 | ||
| 575 | /// Connects `from_node`'s `from_output` (typically `"Output"` or `"Mask"`) to `to_node`'s | |
| 576 | /// `to_input` port, rejecting self-loops and cycles. | |
| 577 | pub fn connect_output( | |
| 578 | &mut self, | |
| 579 | from_node: NodeId, | |
| 580 | from_output: &str, | |
| 581 | to_node: NodeId, | |
| 582 | to_input: &str, | |
| 583 | ) -> Result<(), String> { | |
| 584 | if from_node.0 >= self.nodes.len() { | |
| 585 | return Err(format!("invalid source node id {}", from_node.0)); | |
| 586 | } | |
| 587 | if to_node.0 >= self.nodes.len() { | |
| 588 | return Err(format!("invalid target node id {}", to_node.0)); | |
| 589 | } | |
| 590 | if from_node == to_node { | |
| 591 | return Err("cannot connect a node to itself".to_owned()); | |
| 592 | } | |
| 593 | if self.would_create_cycle(from_node, to_node) { | |
| 594 | return Err(format!( | |
| 595 | "connecting '{}' -> '{}' would create a cycle", | |
| 596 | self.nodes[from_node.0].name, self.nodes[to_node.0].name | |
| 597 | )); | |
| 598 | } | |
| 599 | ||
| 600 | let src_name = self.nodes[from_node.0].name.clone(); | |
| 601 | let out_name = if from_output.is_empty() { | |
| 602 | "Output" | |
| 603 | } else { | |
| 604 | from_output | |
| 605 | }; | |
| 606 | ||
| 607 | let dst = &mut self.nodes[to_node.0]; | |
| 608 | let entry = dst | |
| 609 | .inputs | |
| 610 | .entry(to_input.to_owned()) | |
| 611 | .or_insert(InputBinding { | |
| 612 | value: None, | |
| 613 | source_op: None, | |
| 614 | source_output: None, | |
| 615 | expression: None, | |
| 616 | }); | |
| 617 | entry.source_op = Some(src_name.clone()); | |
| 618 | entry.source_output = Some(out_name.to_owned()); | |
| 619 | ||
| 620 | let in_tbl = ensure_table_mut(&mut dst.raw, "Inputs", None); | |
| 621 | let port_tbl = ensure_table_mut(in_tbl, to_input, Some("Input")); | |
| 622 | port_tbl.set(LuaKey::Str("SourceOp".to_owned()), LuaValue::String(src_name)); | |
| 623 | port_tbl.set( | |
| 624 | LuaKey::Str("Source".to_owned()), | |
| 625 | LuaValue::String(out_name.to_owned()), | |
| 626 | ); | |
| 627 | ||
| 628 | self.revision += 1; | |
| 629 | Ok(()) | |
| 630 | } | |
| 631 | ||
| 632 | /// Disconnects `to_node`'s `to_input` port. Returns `true` if a connection was removed. | |
| 633 | pub fn disconnect(&mut self, to_node: NodeId, to_input: &str) -> bool { | |
| 634 | if to_node.0 >= self.nodes.len() { | |
| 635 | return false; | |
| 636 | } | |
| 637 | let dst = &mut self.nodes[to_node.0]; | |
| 638 | let Some(entry) = dst.inputs.get_mut(to_input) else { | |
| 639 | return false; | |
| 640 | }; | |
| 641 | if entry.source_op.is_none() && entry.source_output.is_none() { | |
| 642 | return false; | |
| 643 | } | |
| 644 | entry.source_op = None; | |
| 645 | entry.source_output = None; | |
| 646 | ||
| 647 | if let Some(in_tbl) = dst.raw.get_table_mut("Inputs") { | |
| 648 | if let Some(port_tbl) = in_tbl.get_table_mut(to_input) { | |
| 649 | port_tbl.remove(&LuaKey::Str("SourceOp".to_owned())); | |
| 650 | port_tbl.remove(&LuaKey::Str("Source".to_owned())); | |
| 651 | } | |
| 652 | } | |
| 653 | ||
| 654 | self.revision += 1; | |
| 655 | true | |
| 656 | } | |
| 657 | ||
| 658 | /// Splices `new_node` into the pipe `upstream -> downstream.downstream_input`: | |
| 659 | /// connects `upstream -> new_node.(default_main_input_port)` and | |
| 660 | /// `new_node -> downstream.downstream_input`. | |
| 661 | pub fn splice_node_into_pipe( | |
| 662 | &mut self, | |
| 663 | new_node: NodeId, | |
| 664 | upstream: NodeId, | |
| 665 | downstream: NodeId, | |
| 666 | downstream_input: &str, | |
| 667 | ) -> Result<(), String> { | |
| 668 | if new_node.0 >= self.nodes.len() | |
| 669 | || upstream.0 >= self.nodes.len() | |
| 670 | || downstream.0 >= self.nodes.len() | |
| 671 | { | |
| 672 | return Err("invalid node id for splice_node_into_pipe".to_owned()); | |
| 673 | } | |
| 674 | if new_node == upstream || new_node == downstream || upstream == downstream { | |
| 675 | return Err("splice_node_into_pipe requires three distinct nodes".to_owned()); | |
| 676 | } | |
| 677 | if self.would_create_cycle(upstream, new_node) | |
| 678 | || self.would_create_cycle(new_node, downstream) | |
| 679 | { | |
| 680 | return Err("splicing node into pipe would create a cycle".to_owned()); | |
| 681 | } | |
| 682 | ||
| 683 | let upstream_name = self.nodes[upstream.0].name.as_str(); | |
| 684 | let upstream_output = self.nodes[downstream.0] | |
| 685 | .inputs | |
| 686 | .get(downstream_input) | |
| 687 | .filter(|b| b.source_op.as_deref() == Some(upstream_name)) | |
| 688 | .and_then(|b| b.source_output.clone()) | |
| 689 | .unwrap_or_else(|| "Output".to_owned()); | |
| 690 | ||
| 691 | let mid_port = default_main_input_port(&self.nodes[new_node.0].kind); | |
| 692 | self.connect_output(upstream, &upstream_output, new_node, mid_port)?; | |
| 693 | self.connect_output(new_node, "Output", downstream, downstream_input)?; | |
| 694 | Ok(()) | |
| 695 | } | |
| 696 | ||
| 697 | /// Sets a static parameter value on `node`'s `input` port. | |
| 698 | pub fn set_input_value(&mut self, node: NodeId, input: &str, value: ParamValue) -> bool { | |
| 699 | if node.0 >= self.nodes.len() { | |
| 700 | return false; | |
| 701 | } | |
| 702 | let n = &mut self.nodes[node.0]; | |
| 703 | let entry = n.inputs.entry(input.to_owned()).or_insert(InputBinding { | |
| 704 | value: None, | |
| 705 | source_op: None, | |
| 706 | source_output: None, | |
| 707 | expression: None, | |
| 708 | }); | |
| 709 | entry.value = Some(value.clone()); | |
| 710 | ||
| 711 | let in_tbl = ensure_table_mut(&mut n.raw, "Inputs", None); | |
| 712 | let port_tbl = ensure_table_mut(in_tbl, input, Some("Input")); | |
| 713 | port_tbl.set(LuaKey::Str("Value".to_owned()), param_value_to_lua(&value)); | |
| 714 | ||
| 715 | self.revision += 1; | |
| 716 | true | |
| 717 | } | |
| 718 | ||
| 719 | /// Sets or clears a Fusion Lua expression on `node`'s `input` port. | |
| 720 | pub fn set_input_expression( | |
| 721 | &mut self, | |
| 722 | node: NodeId, | |
| 723 | input: &str, | |
| 724 | expr: Option<String>, | |
| 725 | ) -> bool { | |
| 726 | if node.0 >= self.nodes.len() { | |
| 727 | return false; | |
| 728 | } | |
| 729 | let normalized = expr.and_then(|s| { | |
| 730 | let trimmed = s.trim(); | |
| 731 | if trimmed.is_empty() { | |
| 732 | None | |
| 733 | } else { | |
| 734 | Some(s) | |
| 735 | } | |
| 736 | }); | |
| 737 | ||
| 738 | let n = &mut self.nodes[node.0]; | |
| 739 | let entry = n.inputs.entry(input.to_owned()).or_insert(InputBinding { | |
| 740 | value: None, | |
| 741 | source_op: None, | |
| 742 | source_output: None, | |
| 743 | expression: None, | |
| 744 | }); | |
| 745 | entry.expression = normalized.clone(); | |
| 746 | ||
| 747 | if let Some(expr_str) = normalized { | |
| 748 | let in_tbl = ensure_table_mut(&mut n.raw, "Inputs", None); | |
| 749 | let port_tbl = ensure_table_mut(in_tbl, input, Some("Input")); | |
| 750 | port_tbl.set( | |
| 751 | LuaKey::Str("Expression".to_owned()), | |
| 752 | LuaValue::String(expr_str), | |
| 753 | ); | |
| 754 | } else if let Some(in_tbl) = n.raw.get_table_mut("Inputs") { | |
| 755 | if let Some(port_tbl) = in_tbl.get_table_mut(input) { | |
| 756 | port_tbl.remove(&LuaKey::Str("Expression".to_owned())); | |
| 757 | } | |
| 758 | } | |
| 759 | ||
| 760 | self.revision += 1; | |
| 761 | true | |
| 762 | } | |
| 763 | ||
| 764 | /// Toggles `PassThrough` (bypass) on `node` and returns the new passthrough state. | |
| 765 | pub fn toggle_passthrough(&mut self, node: NodeId) -> bool { | |
| 766 | if node.0 >= self.nodes.len() { | |
| 767 | return false; | |
| 768 | } | |
| 769 | let n = &mut self.nodes[node.0]; | |
| 770 | n.bypassed = !n.bypassed; | |
| 771 | if n.bypassed { | |
| 772 | n.raw | |
| 773 | .set(LuaKey::Str("PassThrough".to_owned()), LuaValue::Bool(true)); | |
| 774 | } else { | |
| 775 | n.raw.remove(&LuaKey::Str("PassThrough".to_owned())); | |
| 776 | } | |
| 777 | self.revision += 1; | |
| 778 | n.bypassed | |
| 779 | } | |
| 780 | ||
| 781 | /// Moves `node` to flow position `pos` and updates `ViewInfo.Pos` in `node.raw`. | |
| 782 | pub fn set_node_pos(&mut self, node: NodeId, pos: [f32; 2]) { | |
| 783 | if node.0 >= self.nodes.len() { | |
| 784 | return; | |
| 785 | } | |
| 786 | let n = &mut self.nodes[node.0]; | |
| 787 | n.pos = pos; | |
| 788 | set_view_info_pos(&mut n.raw, pos); | |
| 789 | self.revision += 1; | |
| 790 | } | |
| 791 | ||
| 792 | /// Inserts or updates a scalar keyframe at `(frame, value)` on `node`'s `input`. | |
| 793 | /// - If `input` is already connected to a `BezierSpline`, updates/inserts the keyframe there. | |
| 794 | /// - Otherwise creates a new `BezierSpline` named `<NodeName><InputName>` (deduplicated), | |
| 795 | /// wires `input` to it (`SourceOp = spline_name, Source = "Value"`), and inserts the keyframe. | |
| 796 | /// Returns the spline's name. | |
| 797 | pub fn set_keyframe( | |
| 798 | &mut self, | |
| 799 | node: NodeId, | |
| 800 | input: &str, | |
| 801 | frame: f64, | |
| 802 | value: f64, | |
| 803 | ) -> Result<String, String> { | |
| 804 | if node.0 >= self.nodes.len() { | |
| 805 | return Err(format!("invalid node id {}", node.0)); | |
| 806 | } | |
| 807 | if !frame.is_finite() || !value.is_finite() { | |
| 808 | return Err("keyframe frame and value must be finite numbers".to_owned()); | |
| 809 | } | |
| 810 | ||
| 811 | let existing_spline = self.nodes[node.0] | |
| 812 | .inputs | |
| 813 | .get(input) | |
| 814 | .and_then(|b| b.source_op.clone()) | |
| 815 | .filter(|op| self.splines.contains_key(op)); | |
| 816 | ||
| 817 | let spline_name = if let Some(sp_name) = existing_spline { | |
| 818 | let sp = self.splines.get_mut(&sp_name).expect("spline exists"); | |
| 819 | upsert_keyframe(sp, frame, value); | |
| 820 | sp_name | |
| 821 | } else { | |
| 822 | let hint = format!("{}{}", self.nodes[node.0].name, input); | |
| 823 | let sp_name = self.generate_unique_name("BezierSpline", Some(&hint)); | |
| 824 | let color = default_spline_color(&sp_name); | |
| 825 | let spline = BezierSpline { | |
| 826 | name: sp_name.clone(), | |
| 827 | color, | |
| 828 | keyframes: vec![Keyframe::new(frame, value)], | |
| 829 | }; | |
| 830 | self.splines.insert(sp_name.clone(), spline); | |
| 831 | ||
| 832 | let n = &mut self.nodes[node.0]; | |
| 833 | let entry = n.inputs.entry(input.to_owned()).or_insert(InputBinding { | |
| 834 | value: None, | |
| 835 | source_op: None, | |
| 836 | source_output: None, | |
| 837 | expression: None, | |
| 838 | }); | |
| 839 | entry.source_op = Some(sp_name.clone()); | |
| 840 | entry.source_output = Some("Value".to_owned()); | |
| 841 | ||
| 842 | let in_tbl = ensure_table_mut(&mut n.raw, "Inputs", None); | |
| 843 | let port_tbl = ensure_table_mut(in_tbl, input, Some("Input")); | |
| 844 | port_tbl.set( | |
| 845 | LuaKey::Str("SourceOp".to_owned()), | |
| 846 | LuaValue::String(sp_name.clone()), | |
| 847 | ); | |
| 848 | port_tbl.set( | |
| 849 | LuaKey::Str("Source".to_owned()), | |
| 850 | LuaValue::String("Value".to_owned()), | |
| 851 | ); | |
| 852 | ||
| 853 | sp_name | |
| 854 | }; | |
| 855 | ||
| 856 | self.revision += 1; | |
| 857 | Ok(spline_name) | |
| 858 | } | |
| 859 | ||
| 860 | /// Removes the keyframe at `frame` from `spline_name`. Returns `true` if a keyframe was deleted. | |
| 861 | pub fn delete_keyframe(&mut self, spline_name: &str, frame: f64) -> bool { | |
| 862 | let Some(sp) = self.splines.get_mut(spline_name) else { | |
| 863 | return false; | |
| 864 | }; | |
| 865 | let Some(pos) = sp | |
| 866 | .keyframes | |
| 867 | .iter() | |
| 868 | .position(|kf| (kf.time - frame).abs() < 1e-6) | |
| 869 | else { | |
| 870 | return false; | |
| 871 | }; | |
| 872 | sp.keyframes.remove(pos); | |
| 873 | self.revision += 1; | |
| 874 | true | |
| 875 | } | |
| 876 | } | |
| 877 | ||
| 878 | #[derive(Clone, Debug)] | |
| 879 | struct HistoryEntry { | |
| 880 | label: String, | |
| 881 | snapshot: Comp, | |
| 882 | coalesce_key: Option<String>, | |
| 883 | } | |
| 884 | ||
| 885 | /// Snapshot-based undo/redo history stack for [`Comp`] with transaction groups and drag coalescing. | |
| 886 | #[derive(Clone, Debug)] | |
| 887 | pub struct CompHistory { | |
| 888 | undo_stack: VecDeque<HistoryEntry>, | |
| 889 | redo_stack: Vec<HistoryEntry>, | |
| 890 | max_depth: usize, | |
| 891 | active_group: Option<(String, Comp)>, | |
| 892 | group_depth: usize, | |
| 893 | /// Position in `undo_stack` corresponding to the last saved state (`Some(0)` means clean at | |
| 894 | /// depth 0; `None` means the saved state is no longer reachable via undo/redo). | |
| 895 | saved_undo_depth: Option<usize>, | |
| 896 | saved_revision: Option<u64>, | |
| 897 | } | |
| 898 | ||
| 899 | impl Default for CompHistory { | |
| 900 | fn default() -> Self { | |
| 901 | Self::new() | |
| 902 | } | |
| 903 | } | |
| 904 | ||
| 905 | impl CompHistory { | |
| 906 | pub fn new() -> Self { | |
| 907 | Self::with_max_depth(DEFAULT_MAX_HISTORY) | |
| 908 | } | |
| 909 | ||
| 910 | pub fn with_max_depth(max_depth: usize) -> Self { | |
| 911 | Self { | |
| 912 | undo_stack: VecDeque::new(), | |
| 913 | redo_stack: Vec::new(), | |
| 914 | max_depth: max_depth.max(1), | |
| 915 | active_group: None, | |
| 916 | group_depth: 0, | |
| 917 | saved_undo_depth: None, | |
| 918 | saved_revision: None, | |
| 919 | } | |
| 920 | } | |
| 921 | ||
| 922 | pub fn max_depth(&self) -> usize { | |
| 923 | self.max_depth | |
| 924 | } | |
| 925 | ||
| 926 | pub fn can_undo(&self) -> bool { | |
| 927 | !self.undo_stack.is_empty() | |
| 928 | } | |
| 929 | ||
| 930 | pub fn can_redo(&self) -> bool { | |
| 931 | !self.redo_stack.is_empty() | |
| 932 | } | |
| 933 | ||
| 934 | pub fn undo_len(&self) -> usize { | |
| 935 | self.undo_stack.len() | |
| 936 | } | |
| 937 | ||
| 938 | pub fn redo_len(&self) -> usize { | |
| 939 | self.redo_stack.len() | |
| 940 | } | |
| 941 | ||
| 942 | pub fn undo_label(&self) -> Option<&str> { | |
| 943 | self.undo_stack.back().map(|e| e.label.as_str()) | |
| 944 | } | |
| 945 | ||
| 946 | pub fn redo_label(&self) -> Option<&str> { | |
| 947 | self.redo_stack.last().map(|e| e.label.as_str()) | |
| 948 | } | |
| 949 | ||
| 950 | pub fn in_group(&self) -> bool { | |
| 951 | self.group_depth > 0 | |
| 952 | } | |
| 953 | ||
| 954 | /// Clears all undo/redo entries and any active transaction group. | |
| 955 | pub fn clear(&mut self) { | |
| 956 | self.undo_stack.clear(); | |
| 957 | self.redo_stack.clear(); | |
| 958 | self.active_group = None; | |
| 959 | self.group_depth = 0; | |
| 960 | self.saved_undo_depth = None; | |
| 961 | self.saved_revision = None; | |
| 962 | } | |
| 963 | ||
| 964 | /// Records the current state of `comp` as the clean saved point. | |
| 965 | pub fn mark_saved(&mut self, comp: &Comp) { | |
| 966 | self.saved_undo_depth = Some(self.undo_stack.len()); | |
| 967 | self.saved_revision = Some(comp.revision); | |
| 968 | } | |
| 969 | ||
| 970 | pub fn saved_revision(&self) -> Option<u64> { | |
| 971 | self.saved_revision | |
| 972 | } | |
| 973 | ||
| 974 | /// Returns `true` if `comp` has unsaved modifications relative to the last [`Self::mark_saved`]. | |
| 975 | pub fn is_dirty(&self, comp: &Comp) -> bool { | |
| 976 | match self.saved_undo_depth { | |
| 977 | Some(depth) if depth == self.undo_stack.len() => { | |
| 978 | // If an edit was pushed via coalescing or outside history after mark_saved, | |
| 979 | // check whether we're still at the saved depth without an active modified group. | |
| 980 | if let Some((_, ref snap)) = self.active_group { | |
| 981 | comp.revision != snap.revision | |
| 982 | } else { | |
| 983 | false | |
| 984 | } | |
| 985 | } | |
| 986 | _ => self.saved_revision != Some(comp.revision), | |
| 987 | } | |
| 988 | } | |
| 989 | ||
| 990 | /// Pushes a snapshot of `comp` BEFORE applying a discrete mutation. | |
| 991 | /// No-op if currently inside a [`Self::begin_group`] transaction. | |
| 992 | pub fn push_snapshot(&mut self, comp: &Comp, label: impl Into<String>) { | |
| 993 | if self.group_depth > 0 { | |
| 994 | return; | |
| 995 | } | |
| 996 | self.push_entry(HistoryEntry { | |
| 997 | label: label.into(), | |
| 998 | snapshot: comp.clone(), | |
| 999 | coalesce_key: None, | |
| 1000 | }); | |
| 1001 | } | |
| 1002 | ||
| 1003 | /// Pushes a snapshot of `comp` BEFORE applying a continuous mutation (such as dragging a node | |
| 1004 | /// or scrubbing a parameter slider). Consecutive calls with the same `key` coalesce into a | |
| 1005 | /// single undo step preserving the initial pre-drag snapshot. | |
| 1006 | /// No-op if currently inside a [`Self::begin_group`] transaction. | |
| 1007 | pub fn push_coalesced( | |
| 1008 | &mut self, | |
| 1009 | comp: &Comp, | |
| 1010 | label: impl Into<String>, | |
| 1011 | key: impl Into<String>, | |
| 1012 | ) { | |
| 1013 | if self.group_depth > 0 { | |
| 1014 | return; | |
| 1015 | } | |
| 1016 | let key_str = key.into(); | |
| 1017 | let label_str = label.into(); | |
| 1018 | if self.redo_stack.is_empty() { | |
| 1019 | if let Some(top) = self.undo_stack.back_mut() { | |
| 1020 | if top.coalesce_key.as_deref() == Some(key_str.as_str()) { | |
| 1021 | top.label = label_str; | |
| 1022 | return; | |
| 1023 | } | |
| 1024 | } | |
| 1025 | } | |
| 1026 | self.push_entry(HistoryEntry { | |
| 1027 | label: label_str, | |
| 1028 | snapshot: comp.clone(), | |
| 1029 | coalesce_key: Some(key_str), | |
| 1030 | }); | |
| 1031 | } | |
| 1032 | ||
| 1033 | /// Breaks coalescing on the top undo entry so subsequent edits with the same key start a new | |
| 1034 | /// undo step (e.g. on pointer release). | |
| 1035 | pub fn break_coalescing(&mut self) { | |
| 1036 | if let Some(top) = self.undo_stack.back_mut() { | |
| 1037 | top.coalesce_key = None; | |
| 1038 | } | |
| 1039 | } | |
| 1040 | ||
| 1041 | /// Begins a transaction group. All mutations until the matching [`Self::commit_group`] collapse | |
| 1042 | /// into a single undo step. Supports nesting. | |
| 1043 | pub fn begin_group(&mut self, comp: &Comp, label: impl Into<String>) { | |
| 1044 | if self.group_depth == 0 { | |
| 1045 | self.active_group = Some((label.into(), comp.clone())); | |
| 1046 | } | |
| 1047 | self.group_depth += 1; | |
| 1048 | } | |
| 1049 | ||
| 1050 | /// Commits the current transaction group. When the outermost group closes, pushes one undo | |
| 1051 | /// entry if `comp.revision` changed since `begin_group`. Returns `true` if an entry was added. | |
| 1052 | pub fn commit_group(&mut self, comp: &Comp) -> bool { | |
| 1053 | if self.group_depth == 0 { | |
| 1054 | return false; | |
| 1055 | } | |
| 1056 | self.group_depth -= 1; | |
| 1057 | if self.group_depth > 0 { | |
| 1058 | return false; | |
| 1059 | } | |
| 1060 | let Some((label, snapshot)) = self.active_group.take() else { | |
| 1061 | return false; | |
| 1062 | }; | |
| 1063 | if comp.revision == snapshot.revision { | |
| 1064 | return false; | |
| 1065 | } | |
| 1066 | self.push_entry(HistoryEntry { | |
| 1067 | label, | |
| 1068 | snapshot, | |
| 1069 | coalesce_key: None, | |
| 1070 | }); | |
| 1071 | true | |
| 1072 | } | |
| 1073 | ||
| 1074 | /// Cancels the active transaction group and restores `comp` to its pre-group state. | |
| 1075 | pub fn cancel_group(&mut self, comp: &mut Comp) -> bool { | |
| 1076 | if self.group_depth == 0 { | |
| 1077 | return false; | |
| 1078 | } | |
| 1079 | self.group_depth = 0; | |
| 1080 | let Some((_, snapshot)) = self.active_group.take() else { | |
| 1081 | return false; | |
| 1082 | }; | |
| 1083 | let prev_rev = comp.revision; | |
| 1084 | *comp = snapshot; | |
| 1085 | if comp.revision != prev_rev { | |
| 1086 | comp.revision = prev_rev.max(comp.revision) + 1; | |
| 1087 | } | |
| 1088 | true | |
| 1089 | } | |
| 1090 | ||
| 1091 | /// Undoes the most recent edit, restoring `comp` to the saved snapshot. | |
| 1092 | /// Always advances `comp.revision` monotonically so downstream caches invalidate cleanly. | |
| 1093 | pub fn undo(&mut self, comp: &mut Comp) -> bool { | |
| 1094 | if self.group_depth > 0 { | |
| 1095 | self.group_depth = 1; | |
| 1096 | self.commit_group(comp); | |
| 1097 | } | |
| 1098 | let Some(entry) = self.undo_stack.pop_back() else { | |
| 1099 | return false; | |
| 1100 | }; | |
| 1101 | let prev_rev = comp.revision; | |
| 1102 | let redo_entry = HistoryEntry { | |
| 1103 | label: entry.label, | |
| 1104 | snapshot: comp.clone(), | |
| 1105 | coalesce_key: None, | |
| 1106 | }; | |
| 1107 | self.redo_stack.push(redo_entry); | |
| 1108 | *comp = entry.snapshot; | |
| 1109 | comp.revision = prev_rev.max(comp.revision) + 1; | |
| 1110 | true | |
| 1111 | } | |
| 1112 | ||
| 1113 | /// Redoes the most recently undone edit. | |
| 1114 | /// Always advances `comp.revision` monotonically so downstream caches invalidate cleanly. | |
| 1115 | pub fn redo(&mut self, comp: &mut Comp) -> bool { | |
| 1116 | let Some(entry) = self.redo_stack.pop() else { | |
| 1117 | return false; | |
| 1118 | }; | |
| 1119 | let prev_rev = comp.revision; | |
| 1120 | let undo_entry = HistoryEntry { | |
| 1121 | label: entry.label, | |
| 1122 | snapshot: comp.clone(), | |
| 1123 | coalesce_key: None, | |
| 1124 | }; | |
| 1125 | self.undo_stack.push_back(undo_entry); | |
| 1126 | *comp = entry.snapshot; | |
| 1127 | comp.revision = prev_rev.max(comp.revision) + 1; | |
| 1128 | true | |
| 1129 | } | |
| 1130 | ||
| 1131 | fn push_entry(&mut self, entry: HistoryEntry) { | |
| 1132 | // Any saved state that lived in the redo branch is now unreachable. | |
| 1133 | if let Some(saved_depth) = self.saved_undo_depth { | |
| 1134 | if saved_depth > self.undo_stack.len() { | |
| 1135 | self.saved_undo_depth = None; | |
| 1136 | } | |
| 1137 | } | |
| 1138 | self.redo_stack.clear(); | |
| 1139 | self.undo_stack.push_back(entry); | |
| 1140 | while self.undo_stack.len() > self.max_depth { | |
| 1141 | self.undo_stack.pop_front(); | |
| 1142 | self.saved_undo_depth = self.saved_undo_depth.and_then(|d| d.checked_sub(1)); | |
| 1143 | } | |
| 1144 | } | |
| 1145 | } | |
| 1146 | ||
| 1147 | fn sanitize_lua_ident(raw: &str) -> String { | |
| 1148 | let mut out = String::with_capacity(raw.len()); | |
| 1149 | for ch in raw.chars() { | |
| 1150 | if ch.is_ascii_alphanumeric() || ch == '_' { | |
| 1151 | out.push(ch); | |
| 1152 | } else { | |
| 1153 | out.push('_'); | |
| 1154 | } | |
| 1155 | } | |
| 1156 | if out.is_empty() || out.as_bytes()[0].is_ascii_digit() { | |
| 1157 | out.insert(0, '_'); | |
| 1158 | } | |
| 1159 | if !is_valid_lua_ident(&out) { | |
| 1160 | out.push('_'); | |
| 1161 | } | |
| 1162 | out | |
| 1163 | } | |
| 1164 | ||
| 1165 | fn collect_node_source_ops(node: &Node, out: &mut HashSet<String>) { | |
| 1166 | for binding in node.inputs.values() { | |
| 1167 | if let Some(src) = &binding.source_op { | |
| 1168 | out.insert(src.clone()); | |
| 1169 | } | |
| 1170 | } | |
| 1171 | collect_source_ops_in_table(&node.raw, out); | |
| 1172 | } | |
| 1173 | ||
| 1174 | fn collect_source_ops_in_table(tbl: &LuaTable, out: &mut HashSet<String>) { | |
| 1175 | for (k, v) in &tbl.entries { | |
| 1176 | if let LuaKey::Str(key) = k { | |
| 1177 | if key == "SourceOp" { | |
| 1178 | if let Some(s) = v.as_str() { | |
| 1179 | out.insert(s.to_owned()); | |
| 1180 | } | |
| 1181 | } | |
| 1182 | } | |
| 1183 | if let Some(sub) = v.as_table() { | |
| 1184 | collect_source_ops_in_table(sub, out); | |
| 1185 | } | |
| 1186 | } | |
| 1187 | } | |
| 1188 | ||
| 1189 | fn rewrite_source_op_in_table(tbl: &mut LuaTable, old_name: &str, new_name: &str) { | |
| 1190 | for (k, v) in &mut tbl.entries { | |
| 1191 | if let LuaKey::Str(key) = k { | |
| 1192 | if key == "SourceOp" { | |
| 1193 | if let LuaValue::String(s) = v { | |
| 1194 | if s == old_name { | |
| 1195 | *s = new_name.to_owned(); | |
| 1196 | } | |
| 1197 | } | |
| 1198 | } | |
| 1199 | } | |
| 1200 | if let Some(sub) = v.as_table_mut() { | |
| 1201 | rewrite_source_op_in_table(sub, old_name, new_name); | |
| 1202 | } | |
| 1203 | } | |
| 1204 | } | |
| 1205 | ||
| 1206 | fn set_view_info_pos(raw: &mut LuaTable, pos: [f32; 2]) { | |
| 1207 | let vi = ensure_table_mut(raw, "ViewInfo", Some("OperatorInfo")); | |
| 1208 | vi.set( | |
| 1209 | LuaKey::Str("Pos".to_owned()), | |
| 1210 | vec2_lua(pos[0] as f64, pos[1] as f64), | |
| 1211 | ); | |
| 1212 | } | |
| 1213 | ||
| 1214 | fn upsert_keyframe(spline: &mut BezierSpline, frame: f64, value: f64) { | |
| 1215 | if let Some(existing) = spline | |
| 1216 | .keyframes | |
| 1217 | .iter_mut() | |
| 1218 | .find(|kf| (kf.time - frame).abs() < 1e-6) | |
| 1219 | { | |
| 1220 | existing.value = value; | |
| 1221 | } else { | |
| 1222 | spline.keyframes.push(Keyframe::new(frame, value)); | |
| 1223 | spline.sort(); | |
| 1224 | } | |
| 1225 | } | |
| 1226 | ||
| 1227 | fn default_spline_color(name: &str) -> [u8; 3] { | |
| 1228 | // Deterministic vivid Fusion-like spline palette based on name hash. | |
| 1229 | const PALETTE: &[[u8; 3]] = &[ | |
| 1230 | [255, 128, 0], | |
| 1231 | [102, 204, 255], | |
| 1232 | [170, 238, 102], | |
| 1233 | [255, 102, 170], | |
| 1234 | [204, 153, 255], | |
| 1235 | [255, 221, 85], | |
| 1236 | ]; | |
| 1237 | let hash = name | |
| 1238 | .bytes() | |
| 1239 | .fold(0usize, |acc, b| acc.wrapping_mul(31).wrapping_add(b as usize)); | |
| 1240 | PALETTE[hash % PALETTE.len()] | |
| 1241 | } | |
| 1242 | ||
| 1243 | fn default_view_info_for_kind(kind: &str, pos: [f32; 2]) -> LuaTable { | |
| 1244 | let tag = match kind { | |
| 1245 | "PipeRouter" => "PipeRouterInfo", | |
| 1246 | "Underlay" => "UnderlayInfo", | |
| 1247 | "Note" | "StickyNote" => "StickyNoteInfo", | |
| 1248 | _ => "OperatorInfo", | |
| 1249 | }; | |
| 1250 | let mut vi = LuaTable { | |
| 1251 | tag: Some(tag.to_owned()), | |
| 1252 | entries: Vec::new(), | |
| 1253 | }; | |
| 1254 | vi.set( | |
| 1255 | LuaKey::Str("Pos".to_owned()), | |
| 1256 | vec2_lua(pos[0] as f64, pos[1] as f64), | |
| 1257 | ); | |
| 1258 | match kind { | |
| 1259 | "Underlay" => { | |
| 1260 | vi.set(LuaKey::Str("Size".to_owned()), vec2_lua(172.0, 166.364)); | |
| 1261 | } | |
| 1262 | "Note" | "StickyNote" => { | |
| 1263 | let mut flags = LuaTable::default(); | |
| 1264 | flags.set(LuaKey::Str("Expanded".to_owned()), LuaValue::Bool(true)); | |
| 1265 | vi.set(LuaKey::Str("Flags".to_owned()), LuaValue::Table(flags)); | |
| 1266 | vi.set(LuaKey::Str("Size".to_owned()), vec2_lua(196.0, 179.364)); | |
| 1267 | } | |
| 1268 | _ => {} | |
| 1269 | } | |
| 1270 | vi | |
| 1271 | } | |
| 1272 | ||
| 1273 | /// Returns sensible Fusion 21.1 default inputs for common tool classes so Fusion Studio opens | |
| 1274 | /// newly created nodes cleanly without errors. | |
| 1275 | fn default_inputs_for_kind(kind: &str, width: u32, height: u32) -> Vec<(String, ParamValue)> { | |
| 1276 | let w = width as f64; | |
| 1277 | let h = height as f64; | |
| 1278 | let num = |k: &str, v: f64| (k.to_owned(), ParamValue::Number(v)); | |
| 1279 | let pt = |k: &str, x: f64, y: f64| (k.to_owned(), ParamValue::Point([x, y])); | |
| 1280 | let txt = |k: &str, s: &str| (k.to_owned(), ParamValue::Text(s.to_owned())); | |
| 1281 | let fuid = |k: &str, s: &str| (k.to_owned(), ParamValue::FuId(s.to_owned())); | |
| 1282 | ||
| 1283 | match kind { | |
| 1284 | "Background" => vec![ | |
| 1285 | num("Width", w), | |
| 1286 | num("Height", h), | |
| 1287 | num("UseFrameFormatSettings", 1.0), | |
| 1288 | num("TopLeftRed", 0.0), | |
| 1289 | num("TopLeftGreen", 0.0), | |
| 1290 | num("TopLeftBlue", 0.0), | |
| 1291 | num("TopLeftAlpha", 1.0), | |
| 1292 | ], | |
| 1293 | "Merge" => vec![ | |
| 1294 | num("PerformDepthMerge", 0.0), | |
| 1295 | pt("Center", 0.5, 0.5), | |
| 1296 | num("Size", 1.0), | |
| 1297 | num("Angle", 0.0), | |
| 1298 | num("Blend", 1.0), | |
| 1299 | ], | |
| 1300 | "Transform" => vec![ | |
| 1301 | pt("Center", 0.5, 0.5), | |
| 1302 | pt("Pivot", 0.5, 0.5), | |
| 1303 | num("Size", 1.0), | |
| 1304 | num("Angle", 0.0), | |
| 1305 | ], | |
| 1306 | "Blur" => vec![fuid("Filter", "Fast Gaussian"), num("XBlurSize", 1.0)], | |
| 1307 | "Glow" => vec![num("XGlowSize", 10.0), num("Glow", 0.8)], | |
| 1308 | "SoftGlow" => vec![ | |
| 1309 | fuid("Filter", "Fast Gaussian"), | |
| 1310 | num("Gain", 2.0), | |
| 1311 | num("XGlowSize", 10.0), | |
| 1312 | ], | |
| 1313 | "BrightnessContrast" => vec![ | |
| 1314 | num("Gain", 1.0), | |
| 1315 | num("Lift", 0.0), | |
| 1316 | num("Gamma", 1.0), | |
| 1317 | num("Contrast", 0.0), | |
| 1318 | num("Brightness", 0.0), | |
| 1319 | num("Saturation", 1.0), | |
| 1320 | ], | |
| 1321 | "ColorCorrector" => vec![ | |
| 1322 | num("WheelSaturation1", 1.0), | |
| 1323 | num("MasterRGBGain", 1.0), | |
| 1324 | num("MasterRGBGamma", 1.0), | |
| 1325 | ], | |
| 1326 | "ColorGain" => vec![ | |
| 1327 | num("GainRed", 1.0), | |
| 1328 | num("GainGreen", 1.0), | |
| 1329 | num("GainBlue", 1.0), | |
| 1330 | num("GainAlpha", 1.0), | |
| 1331 | num("GammaRed", 1.0), | |
| 1332 | num("GammaGreen", 1.0), | |
| 1333 | num("GammaBlue", 1.0), | |
| 1334 | ], | |
| 1335 | "RectangleMask" => vec![ | |
| 1336 | num("MaskWidth", w), | |
| 1337 | num("MaskHeight", h), | |
| 1338 | pt("PixelAspect", 1.0, 1.0), | |
| 1339 | pt("Center", 0.5, 0.5), | |
| 1340 | num("Width", 0.5), | |
| 1341 | num("Height", 0.5), | |
| 1342 | num("CornerRadius", 0.0), | |
| 1343 | num("SoftEdge", 0.0), | |
| 1344 | ], | |
| 1345 | "EllipseMask" => vec![ | |
| 1346 | num("MaskWidth", w), | |
| 1347 | num("MaskHeight", h), | |
| 1348 | pt("PixelAspect", 1.0, 1.0), | |
| 1349 | pt("Center", 0.5, 0.5), | |
| 1350 | num("Width", 0.5), | |
| 1351 | num("Height", 0.5), | |
| 1352 | num("SoftEdge", 0.0), | |
| 1353 | ], | |
| 1354 | "PolylineMask" => vec![ | |
| 1355 | num("MaskWidth", w), | |
| 1356 | num("MaskHeight", h), | |
| 1357 | pt("PixelAspect", 1.0, 1.0), | |
| 1358 | num("SoftEdge", 0.0), | |
| 1359 | ], | |
| 1360 | "BitmapMask" => vec![ | |
| 1361 | num("MaskWidth", w), | |
| 1362 | num("MaskHeight", h), | |
| 1363 | pt("PixelAspect", 1.0, 1.0), | |
| 1364 | fuid("Channel", "Alpha"), | |
| 1365 | ], | |
| 1366 | "TextPlus" => vec![ | |
| 1367 | num("Width", w), | |
| 1368 | num("Height", h), | |
| 1369 | num("UseFrameFormatSettings", 1.0), | |
| 1370 | txt("StyledText", ""), | |
| 1371 | txt("Font", "Open Sans"), | |
| 1372 | txt("Style", "Bold"), | |
| 1373 | num("Size", 0.08), | |
| 1374 | pt("Center", 0.5, 0.5), | |
| 1375 | ], | |
| 1376 | "Loader" => vec![], | |
| 1377 | "Saver" => vec![num("ProcessWhenBlendIs00", 0.0), num("CreateDir", 1.0)], | |
| 1378 | "Displace" => vec![ | |
| 1379 | num("Type", 0.0), | |
| 1380 | num("XRefraction", 0.0), | |
| 1381 | num("YRefraction", 0.0), | |
| 1382 | num("RefractionStrength", 0.0), | |
| 1383 | ], | |
| 1384 | "FastNoise" => vec![ | |
| 1385 | num("Width", w), | |
| 1386 | num("Height", h), | |
| 1387 | num("UseFrameFormatSettings", 1.0), | |
| 1388 | num("Detail", 2.0), | |
| 1389 | num("Contrast", 1.0), | |
| 1390 | num("XScale", 2.0), | |
| 1391 | num("Seethe", 0.0), | |
| 1392 | ], | |
| 1393 | "PipeRouter" | "Underlay" => vec![], | |
| 1394 | "Switch" | "Fuse.Switch" => vec![num("Source", 0.0)], | |
| 1395 | "TimeStretcher" => vec![num("SourceTime", 0.0), num("InterpolateBetweenFrames", 0.0)], | |
| 1396 | "TimeSpeed" => vec![num("Speed", 1.0), num("Delay", 0.0)], | |
| 1397 | "Renderer3D" => vec![ | |
| 1398 | num("Width", w), | |
| 1399 | num("Height", h), | |
| 1400 | num("UseFrameFormatSettings", 1.0), | |
| 1401 | fuid("RendererType", "RendererOpenGL"), | |
| 1402 | ], | |
| 1403 | "Camera3D" => vec![num("FLength", 24.0), num("PlaneOfFocus", 5.0)], | |
| 1404 | "Merge3D" => vec![num("PassThroughLights", 1.0)], | |
| 1405 | "Transform3D" => vec![num("Transform3DOp.Scale.X", 1.0)], | |
| 1406 | "ImagePlane3D" => vec![ | |
| 1407 | num("SurfacePlaneInputs.Width", 1.0), | |
| 1408 | num("SurfacePlaneInputs.Height", 1.0), | |
| 1409 | ], | |
| 1410 | "Shape3D" => vec![fuid("Shape", "SurfacePlaneInputs")], | |
| 1411 | "Note" | "StickyNote" => vec![txt("Comments", "")], | |
| 1412 | _ => vec![], | |
| 1413 | } | |
| 1414 | } | |
| 1415 | ||
| 1416 | #[cfg(test)] | |
| 1417 | mod tests { | |
| 1418 | use super::*; | |
| 1419 | use crate::expr::ExprEngine; | |
| 1420 | use std::path::Path; | |
| 1421 | ||
| 1422 | fn sample_comp() -> Comp { | |
| 1423 | let src = r#"Composition { | |
| 1424 | 	CurrentTime = 10, | |
| 1425 | 	RenderRange = { 0, 100 }, | |
| 1426 | 	GlobalRange = { 0, 100 }, | |
| 1427 | 	Prefs = { | |
| 1428 | 		Comp = { | |
| 1429 | 			FrameFormat = { | |
| 1430 | 				Width = 1920, | |
| 1431 | 				Height = 1080, | |
| 1432 | 				Rate = 24, | |
| 1433 | 				DepthFull = 3, | |
| 1434 | 			}, | |
| 1435 | 		}, | |
| 1436 | 	}, | |
| 1437 | 	Tools = ordered() { | |
| 1438 | 		BG1 = Background { | |
| 1439 | 			Inputs = { | |
| 1440 | 				Width = Input { Value = 1920, }, | |
| 1441 | 				Height = Input { Value = 1080, }, | |
| 1442 | 				TopLeftRed = Input { Value = 0.25, }, | |
| 1443 | 			}, | |
| 1444 | 			ViewInfo = OperatorInfo { Pos = { 100, 50 } }, | |
| 1445 | 		}, | |
| 1446 | 		BC1 = BrightnessContrast { | |
| 1447 | 			Inputs = { | |
| 1448 | 				Input = Input { | |
| 1449 | 					SourceOp = "BG1", | |
| 1450 | 					Source = "Output", | |
| 1451 | 				}, | |
| 1452 | 				Gain = Input { | |
| 1453 | 					SourceOp = "BC1Gain", | |
| 1454 | 					Source = "Value", | |
| 1455 | 				}, | |
| 1456 | 			}, | |
| 1457 | 			ViewInfo = OperatorInfo { Pos = { 300, 50 } }, | |
| 1458 | 		}, | |
| 1459 | 		BC1Gain = BezierSpline { | |
| 1460 | 			SplineColor = { Red = 255, Green = 128, Blue = 0 }, | |
| 1461 | 			KeyFrames = { | |
| 1462 | 				[0] = { 1, Flags = { Linear = true } }, | |
| 1463 | 				[30] = { 2, Flags = { Linear = true } }, | |
| 1464 | 			}, | |
| 1465 | 		}, | |
| 1466 | 		SurfaceTracker1 = SurfaceTracker { | |
| 1467 | 			Inputs = { | |
| 1468 | 				Source = Input { | |
| 1469 | 					SourceOp = "BC1", | |
| 1470 | 					Source = "Output", | |
| 1471 | 				}, | |
| 1472 | 				MeshBlob = Input { | |
| 1473 | 					Value = TrackingMesh { | |
| 1474 | 						Vertices = { 1, 2, 3 }, | |
| 1475 | 					}, | |
| 1476 | 				}, | |
| 1477 | 			}, | |
| 1478 | 			ViewInfo = OperatorInfo { Pos = { 500, 50 } }, | |
| 1479 | 		}, | |
| 1480 | 	}, | |
| 1481 | }"#; | |
| 1482 | Comp::from_fusion_str(src).expect("parse sample comp") | |
| 1483 | } | |
| 1484 | ||
| 1485 | #[test] | |
| 1486 | fn add_node_naming_and_tool_defaults() { | |
| 1487 | let mut comp = sample_comp(); | |
| 1488 | let rev0 = comp.revision; | |
| 1489 | ||
| 1490 | let t1 = comp.add_node("Transform", None, [120.0, 200.0]); | |
| 1491 | let t2 = comp.add_node("Transform", None, [240.0, 200.0]); | |
| 1492 | assert_eq!(comp.node(t1).name, "Transform1"); | |
| 1493 | assert_eq!(comp.node(t2).name, "Transform2"); | |
| 1494 | assert_eq!(comp.node(t1).pos, [120.0, 200.0]); | |
| 1495 | assert!(comp.revision >= rev0 + 2); | |
| 1496 | ||
| 1497 | let h0 = comp.add_node("Background", Some("HeroBG"), [0.0, 0.0]); | |
| 1498 | let h1 = comp.add_node("Background", Some("HeroBG"), [50.0, 0.0]); | |
| 1499 | let h2 = comp.add_node("Background", Some("HeroBG"), [100.0, 0.0]); | |
| 1500 | assert_eq!(comp.node(h0).name, "HeroBG"); | |
| 1501 | assert_eq!(comp.node(h1).name, "HeroBG_1"); | |
| 1502 | assert_eq!(comp.node(h2).name, "HeroBG_2"); | |
| 1503 | ||
| 1504 | // Cover all common Fusion 21.1 tool categories + generic fallback | |
| 1505 | let kinds = [ | |
| 1506 | "Background", | |
| 1507 | "Merge", | |
| 1508 | "Transform", | |
| 1509 | "Blur", | |
| 1510 | "Glow", | |
| 1511 | "SoftGlow", | |
| 1512 | "BrightnessContrast", | |
| 1513 | "ColorCorrector", | |
| 1514 | "ColorGain", | |
| 1515 | "RectangleMask", | |
| 1516 | "EllipseMask", | |
| 1517 | "PolylineMask", | |
| 1518 | "BitmapMask", | |
| 1519 | "TextPlus", | |
| 1520 | "Loader", | |
| 1521 | "Saver", | |
| 1522 | "Displace", | |
| 1523 | "FastNoise", | |
| 1524 | "PipeRouter", | |
| 1525 | "Switch", | |
| 1526 | "TimeStretcher", | |
| 1527 | "TimeSpeed", | |
| 1528 | "Renderer3D", | |
| 1529 | "Camera3D", | |
| 1530 | "Merge3D", | |
| 1531 | "Transform3D", | |
| 1532 | "ImagePlane3D", | |
| 1533 | "Shape3D", | |
| 1534 | "Note", | |
| 1535 | "Underlay", | |
| 1536 | "MyCustomThirdPartyTool", | |
| 1537 | ]; | |
| 1538 | for (i, kind) in kinds.iter().enumerate() { | |
| 1539 | let id = comp.add_node(kind, None, [i as f32 * 50.0, 400.0]); | |
| 1540 | assert_eq!(comp.node(id).kind, *kind); | |
| 1541 | assert!(comp.node(id).raw.get_table("ViewInfo").is_some()); | |
| 1542 | } | |
| 1543 | ||
| 1544 | // Roundtrip all newly created nodes cleanly | |
| 1545 | let s = comp.to_fusion_string(); | |
| 1546 | let reloaded = Comp::from_fusion_str(&s).expect("roundtrip added nodes"); | |
| 1547 | assert_eq!(reloaded.nodes.len(), comp.nodes.len()); | |
| 1548 | assert_eq!( | |
| 1549 | reloaded.node(reloaded.find_node("HeroBG").unwrap()).static_number("Width"), | |
| 1550 | Some(1920.0) | |
| 1551 | ); | |
| 1552 | } | |
| 1553 | ||
| 1554 | #[test] | |
| 1555 | fn connect_cycle_detection_disconnect_and_splice() { | |
| 1556 | let mut comp = sample_comp(); | |
| 1557 | let bg = comp.find_node("BG1").unwrap(); | |
| 1558 | let bc = comp.find_node("BC1").unwrap(); | |
| 1559 | let st = comp.find_node("SurfaceTracker1").unwrap(); | |
| 1560 | ||
| 1561 | // Self-loop rejected | |
| 1562 | assert!(comp.connect_output(bg, "Output", bg, "EffectMask").is_err()); | |
| 1563 | // Direct cycle BG1 -> BC1 -> BG1 rejected | |
| 1564 | assert!(comp.connect_output(bc, "Output", bg, "EffectMask").is_err()); | |
| 1565 | // Transitive cycle BG1 -> BC1 -> SurfaceTracker1 -> BG1 rejected | |
| 1566 | assert!(comp.connect_output(st, "Output", bg, "EffectMask").is_err()); | |
| 1567 | ||
| 1568 | // Splice a Blur into BG1 -> BC1.Input | |
| 1569 | let blur = comp.add_node("Blur", None, [200.0, 50.0]); | |
| 1570 | comp.splice_node_into_pipe(blur, bg, bc, "Input") | |
| 1571 | .expect("splice blur"); | |
| 1572 | assert_eq!(comp.node(blur).connected_node("Input"), Some("BG1")); | |
| 1573 | assert_eq!(comp.node(bc).connected_node("Input"), Some("Blur1")); | |
| 1574 | ||
| 1575 | // Disconnect returns true once, then false | |
| 1576 | assert!(comp.disconnect(bc, "Input")); | |
| 1577 | assert!(!comp.disconnect(bc, "Input")); | |
| 1578 | assert_eq!(comp.node(bc).connected_node("Input"), None); | |
| 1579 | ||
| 1580 | // Reconnect and verify roundtrip | |
| 1581 | comp.connect_output(blur, "Output", bc, "Input") | |
| 1582 | .expect("reconnect"); | |
| 1583 | let reloaded = Comp::from_fusion_str(&comp.to_fusion_string()).expect("roundtrip"); | |
| 1584 | assert_eq!( | |
| 1585 | reloaded.node(reloaded.find_node("BC1").unwrap()).connected_node("Input"), | |
| 1586 | Some("Blur1") | |
| 1587 | ); | |
| 1588 | } | |
| 1589 | ||
| 1590 | #[test] | |
| 1591 | fn params_expressions_passthrough_pos_and_keyframes() { | |
| 1592 | let mut comp = sample_comp(); | |
| 1593 | let bc = comp.find_node("BC1").unwrap(); | |
| 1594 | ||
| 1595 | assert!(comp.set_input_value(bc, "Gamma", ParamValue::Number(1.45))); | |
| 1596 | assert!(comp.set_input_expression(bc, "Brightness", Some("time * 0.01".to_owned()))); | |
| 1597 | assert!(comp.toggle_passthrough(bc)); | |
| 1598 | comp.set_node_pos(bc, [333.0, 77.0]); | |
| 1599 | ||
| 1600 | // Set keyframe on static input -> creates new BezierSpline and wires it | |
| 1601 | let sp_name = comp.set_keyframe(bc, "Contrast", 0.0, 0.2).expect("kf 0"); | |
| 1602 | assert_eq!(sp_name, "BC1Contrast"); | |
| 1603 | let sp_name2 = comp.set_keyframe(bc, "Contrast", 20.0, 0.8).expect("kf 20"); | |
| 1604 | assert_eq!(sp_name2, sp_name); | |
| 1605 | // Update existing keyframe at frame 20 | |
| 1606 | comp.set_keyframe(bc, "Contrast", 20.0, 0.9).expect("update kf 20"); | |
| 1607 | assert_eq!(comp.splines[&sp_name].keyframes.len(), 2); | |
| 1608 | ||
| 1609 | // Evaluate via Comp::eval_number | |
| 1610 | let expr = ExprEngine::new(); | |
| 1611 | let val_mid = comp.eval_number(comp.node(bc), "Contrast", 10.0, 0.0, &expr); | |
| 1612 | assert!((val_mid - 0.55).abs() < 1e-5, "got {val_mid}"); | |
| 1613 | ||
| 1614 | // Delete keyframe | |
| 1615 | assert!(comp.delete_keyframe(&sp_name, 20.0)); | |
| 1616 | assert!(!comp.delete_keyframe(&sp_name, 20.0)); | |
| 1617 | assert_eq!(comp.splines[&sp_name].keyframes.len(), 1); | |
| 1618 | ||
| 1619 | // Roundtrip | |
| 1620 | let reloaded = Comp::from_fusion_str(&comp.to_fusion_string()).expect("roundtrip"); | |
| 1621 | let r_bc = reloaded.node(reloaded.find_node("BC1").unwrap()); | |
| 1622 | assert!(r_bc.bypassed); | |
| 1623 | assert_eq!(r_bc.pos, [333.0, 77.0]); | |
| 1624 | assert_eq!(r_bc.static_number("Gamma"), Some(1.45)); | |
| 1625 | assert_eq!( | |
| 1626 | r_bc.inputs.get("Brightness").and_then(|b| b.expression.as_deref()), | |
| 1627 | Some("time * 0.01") | |
| 1628 | ); | |
| 1629 | assert_eq!(r_bc.connected_node("Contrast"), Some("BC1Contrast")); | |
| 1630 | assert_eq!(reloaded.splines["BC1Contrast"].keyframes.len(), 1); | |
| 1631 | ||
| 1632 | // Clear expression and un-bypass | |
| 1633 | assert!(comp.set_input_expression(bc, "Brightness", None)); | |
| 1634 | assert!(!comp.toggle_passthrough(bc)); | |
| 1635 | let reloaded2 = Comp::from_fusion_str(&comp.to_fusion_string()).expect("roundtrip 2"); | |
| 1636 | let r_bc2 = reloaded2.node(reloaded2.find_node("BC1").unwrap()); | |
| 1637 | assert!(!r_bc2.bypassed); | |
| 1638 | assert_eq!( | |
| 1639 | r_bc2.inputs.get("Brightness").and_then(|b| b.expression.as_deref()), | |
| 1640 | None | |
| 1641 | ); | |
| 1642 | } | |
| 1643 | ||
| 1644 | #[test] | |
| 1645 | fn rename_duplicate_and_delete_nodes_roundtrip() { | |
| 1646 | let mut comp = sample_comp(); | |
| 1647 | let bg = comp.find_node("BG1").unwrap(); | |
| 1648 | let bc = comp.find_node("BC1").unwrap(); | |
| 1649 | ||
| 1650 | // Rename validation | |
| 1651 | assert!(comp.rename_node(bg, "").is_err()); | |
| 1652 | assert!(comp.rename_node(bg, "123Bad").is_err()); | |
| 1653 | assert!(comp.rename_node(bg, "function").is_err()); | |
| 1654 | assert!(comp.rename_node(bg, "BC1").is_err()); | |
| 1655 | ||
| 1656 | // Rename BG1 -> PlateBG and verify BC1.Input SourceOp is rewritten | |
| 1657 | let new_name = comp.rename_node(bg, "PlateBG").expect("rename BG1"); | |
| 1658 | assert_eq!(new_name, "PlateBG"); | |
| 1659 | assert!(comp.find_node("BG1").is_none()); | |
| 1660 | assert_eq!(comp.find_node("PlateBG"), Some(bg)); | |
| 1661 | assert_eq!(comp.node(bc).connected_node("Input"), Some("PlateBG")); | |
| 1662 | ||
| 1663 | // Duplicate [PlateBG, BC1] together -> internal wire preserved, BC1Gain spline cloned | |
| 1664 | let dups = comp.duplicate_nodes(&[bg, bc], [0.0, 150.0]); | |
| 1665 | assert_eq!(dups.len(), 2); | |
| 1666 | let dup_bg = dups[0]; | |
| 1667 | let dup_bc = dups[1]; | |
| 1668 | assert_eq!(comp.node(dup_bg).name, "PlateBG_1"); | |
| 1669 | assert_eq!(comp.node(dup_bc).name, "BC1_1"); | |
| 1670 | assert_eq!(comp.node(dup_bg).pos, [100.0, 200.0]); | |
| 1671 | assert_eq!(comp.node(dup_bc).connected_node("Input"), Some("PlateBG_1")); | |
| 1672 | let dup_gain_spline = comp.node(dup_bc).connected_node("Gain").unwrap().to_owned(); | |
| 1673 | assert_ne!(dup_gain_spline, "BC1Gain"); | |
| 1674 | assert!(comp.splines.contains_key(&dup_gain_spline)); | |
| 1675 | ||
| 1676 | // Share BC1Gain with dup_bg (artificial) vs exclusive spline on dup_bc: | |
| 1677 | // Deleting dup_bc should prune `dup_gain_spline` while leaving `BC1Gain` intact. | |
| 1678 | let deleted = comp.delete_nodes(&[dup_bc]); | |
| 1679 | assert_eq!(deleted, vec!["BC1_1".to_owned()]); | |
| 1680 | assert!(!comp.splines.contains_key(&dup_gain_spline)); | |
| 1681 | assert!(comp.splines.contains_key("BC1Gain")); | |
| 1682 | ||
| 1683 | // Delete BC1 -> SurfaceTracker1.Source unwired, BC1Gain pruned, NodeId indices compact | |
| 1684 | let bc_now = comp.find_node("BC1").unwrap(); | |
| 1685 | let del2 = comp.delete_nodes(&[bc_now]); | |
| 1686 | assert_eq!(del2, vec!["BC1".to_owned()]); | |
| 1687 | assert!(!comp.splines.contains_key("BC1Gain")); | |
| 1688 | for (idx, n) in comp.nodes.iter().enumerate() { | |
| 1689 | assert_eq!(n.id, NodeId(idx)); | |
| 1690 | assert_eq!(comp.find_node(&n.name), Some(NodeId(idx))); | |
| 1691 | } | |
| 1692 | let st_now = comp.find_node("SurfaceTracker1").unwrap(); | |
| 1693 | assert_eq!(comp.node(st_now).connected_node("Source"), None); | |
| 1694 | ||
| 1695 | // Full roundtrip preserves unknown SurfaceTracker1 verbatim + all structural mutations | |
| 1696 | let reloaded = Comp::from_fusion_str(&comp.to_fusion_string()).expect("roundtrip"); | |
| 1697 | assert!(reloaded.find_node("PlateBG").is_some()); | |
| 1698 | assert!(reloaded.find_node("PlateBG_1").is_some()); | |
| 1699 | assert!(reloaded.find_node("BC1").is_none()); | |
| 1700 | assert!(reloaded.find_node("SurfaceTracker1").is_some()); | |
| 1701 | assert!(!reloaded.splines.contains_key("BC1Gain")); | |
| 1702 | let r_st = reloaded.node(reloaded.find_node("SurfaceTracker1").unwrap()); | |
| 1703 | assert_eq!(r_st.connected_node("Source"), None); | |
| 1704 | assert!( | |
| 1705 | r_st.raw | |
| 1706 | .get_table("Inputs") | |
| 1707 | .and_then(|i| i.get_table("MeshBlob")) | |
| 1708 | .is_some() | |
| 1709 | ); | |
| 1710 | } | |
| 1711 | ||
| 1712 | #[test] | |
| 1713 | fn roundtrip_mutations_on_real_20_falling_comp() { | |
| 1714 | let path = Path::new("/Volumes/Project/trees/fusion/20_falling.comp"); | |
| 1715 | if !path.exists() { | |
| 1716 | return; | |
| 1717 | } | |
| 1718 | let mut comp = Comp::from_fusion_file(path).expect("load 20_falling.comp"); | |
| 1719 | let orig_count = comp.nodes.len(); | |
| 1720 | ||
| 1721 | let blur = comp.add_node("Blur", Some("TestGlowBlur"), [1000.0, -500.0]); | |
| 1722 | let merge19 = comp.find_node("Merge19").expect("Merge19"); | |
| 1723 | comp.set_input_value(blur, "XBlurSize", ParamValue::Number(4.5)); | |
| 1724 | comp.set_input_expression(blur, "YBlurSize", Some("XBlurSize * 2".to_owned())); | |
| 1725 | comp.toggle_passthrough(blur); | |
| 1726 | let sp = comp | |
| 1727 | .set_keyframe(blur, "Blend", 2200.0, 0.5) | |
| 1728 | .expect("keyframe blend"); | |
| 1729 | comp.set_keyframe(blur, "Blend", 2250.0, 1.0) | |
| 1730 | .expect("keyframe blend 2"); | |
| 1731 | comp.connect_output(merge19, "Output", blur, "Input") | |
| 1732 | .expect("connect Merge19 -> blur"); | |
| 1733 | comp.rename_node(blur, "TestGlowBlurRenamed") | |
| 1734 | .expect("rename blur"); | |
| 1735 | ||
| 1736 | let serialized = comp.to_fusion_string(); | |
| 1737 | let reloaded = Comp::from_fusion_str(&serialized).expect("re-parse mutated 20_falling"); | |
| 1738 | assert_eq!(reloaded.nodes.len(), orig_count + 1); | |
| 1739 | let r_blur_id = reloaded | |
| 1740 | .find_node("TestGlowBlurRenamed") | |
| 1741 | .expect("TestGlowBlurRenamed"); | |
| 1742 | let r_blur = reloaded.node(r_blur_id); | |
| 1743 | assert!(r_blur.bypassed); | |
| 1744 | assert_eq!(r_blur.connected_node("Input"), Some("Merge19")); | |
| 1745 | assert_eq!(r_blur.static_number("XBlurSize"), Some(4.5)); | |
| 1746 | assert_eq!( | |
| 1747 | r_blur.inputs.get("YBlurSize").and_then(|b| b.expression.as_deref()), | |
| 1748 | Some("XBlurSize * 2") | |
| 1749 | ); | |
| 1750 | assert_eq!(reloaded.splines[&sp].keyframes.len(), 2); | |
| 1751 | } | |
| 1752 | ||
| 1753 | #[test] | |
| 1754 | fn comp_history_undo_redo_coalescing_groups_and_bounds() { | |
| 1755 | let mut comp = sample_comp(); | |
| 1756 | let mut history = CompHistory::with_max_depth(3); | |
| 1757 | history.mark_saved(&comp); | |
| 1758 | assert!(!history.is_dirty(&comp)); | |
| 1759 | assert!(!history.can_undo()); | |
| 1760 | assert!(!history.can_redo()); | |
| 1761 | ||
| 1762 | let bg = comp.find_node("BG1").unwrap(); | |
| 1763 | ||
| 1764 | // 1. Coalesced drag: 120 frames produce ONE undo step | |
| 1765 | for i in 1..=120 { | |
| 1766 | history.push_coalesced(&comp, "Move BG1", format!("drag_node:{}", bg.0)); | |
| 1767 | comp.set_node_pos(bg, [100.0 + i as f32, 50.0 + i as f32 * 0.5]); | |
| 1768 | } | |
| 1769 | history.break_coalescing(); | |
| 1770 | assert_eq!(history.undo_len(), 1); | |
| 1771 | assert_eq!(history.undo_label(), Some("Move BG1")); | |
| 1772 | assert!(history.is_dirty(&comp)); | |
| 1773 | assert_eq!(comp.node(bg).pos, [220.0, 110.0]); | |
| 1774 | ||
| 1775 | // Undo restores original pre-drag position and clears dirty flag | |
| 1776 | assert!(history.undo(&mut comp)); | |
| 1777 | assert_eq!(comp.node(bg).pos, [100.0, 50.0]); | |
| 1778 | assert!(!history.is_dirty(&comp)); | |
| 1779 | assert!(history.can_redo()); | |
| 1780 | assert_eq!(history.redo_label(), Some("Move BG1")); | |
| 1781 | ||
| 1782 | // Redo restores final dragged position | |
| 1783 | assert!(history.redo(&mut comp)); | |
| 1784 | assert_eq!(comp.node(bg).pos, [220.0, 110.0]); | |
| 1785 | assert!(history.is_dirty(&comp)); | |
| 1786 | ||
| 1787 | // 2. Redo invalidation on new edit after undo | |
| 1788 | assert!(history.undo(&mut comp)); | |
| 1789 | assert!(history.can_redo()); | |
| 1790 | history.push_snapshot(&comp, "Add Blur"); | |
| 1791 | let blur = comp.add_node("Blur", None, [200.0, 100.0]); | |
| 1792 | assert!(!history.can_redo()); | |
| 1793 | assert_eq!(history.undo_len(), 1); | |
| 1794 | ||
| 1795 | // 3. Transaction group collapses multiple mutations into one undo step | |
| 1796 | history.begin_group(&comp, "Style Blur"); | |
| 1797 | comp.set_input_value(blur, "XBlurSize", ParamValue::Number(5.0)); | |
| 1798 | history.push_snapshot(&comp, "Ignored inside group"); | |
| 1799 | comp.toggle_passthrough(blur); | |
| 1800 | assert!(history.commit_group(&comp)); | |
| 1801 | assert_eq!(history.undo_len(), 2); | |
| 1802 | assert_eq!(history.undo_label(), Some("Style Blur")); | |
| 1803 | ||
| 1804 | // No-op group doesn't push | |
| 1805 | history.begin_group(&comp, "No-op"); | |
| 1806 | assert!(!history.commit_group(&comp)); | |
| 1807 | assert_eq!(history.undo_len(), 2); | |
| 1808 | ||
| 1809 | // Cancel group restores pre-group state | |
| 1810 | history.begin_group(&comp, "Canceled"); | |
| 1811 | comp.set_node_pos(blur, [999.0, 999.0]); | |
| 1812 | assert!(history.cancel_group(&mut comp)); | |
| 1813 | assert_eq!(comp.node(blur).pos, [200.0, 100.0]); | |
| 1814 | ||
| 1815 | // 4. Bounded history depth (max_depth = 3) | |
| 1816 | history.push_snapshot(&comp, "Edit 3"); | |
| 1817 | comp.set_node_pos(blur, [210.0, 100.0]); | |
| 1818 | history.push_snapshot(&comp, "Edit 4"); | |
| 1819 | comp.set_node_pos(blur, [220.0, 100.0]); | |
| 1820 | assert_eq!(history.undo_len(), 3); | |
| 1821 | ||
| 1822 | history.clear(); | |
| 1823 | assert!(!history.can_undo()); | |
| 1824 | assert!(!history.can_redo()); | |
| 1825 | } | |
| 1826 | } |
crates/model/src/lib.rs+2| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | 1 | pub mod comp; |
| 2 | pub mod edit; | |
| 2 | 3 | pub mod expr; |
| 3 | 4 | pub mod lua_value; |
| 4 | 5 | pub mod spline; |
| ... | ... | @@ -7,6 +8,7 @@ pub use comp::{ |
| 7 | 8 | BitDepth, ClipSpec, ClsEntry, Comp, InputBinding, Node, NodeId, ParamValue, PortRole, SaverSpec, |
| 8 | 9 | default_main_input_port, is_supported_tool, |
| 9 | 10 | }; |
| 11 | pub use edit::{CompHistory, DEFAULT_MAX_HISTORY}; | |
| 10 | 12 | pub use expr::ExprEngine; |
| 11 | 13 | pub use lua_value::{LuaKey, LuaTable, LuaValue, ParseError, parse_lua}; |
| 12 | 14 | pub use spline::{BezierSpline, Gradient, GradientStop, HandleMode, KeyFlags, Keyframe, PolyPath, PolyPoint}; |
crates/model/src/lua_value.rs+1-1| ... | ... | @@ -649,7 +649,7 @@ fn is_ident_cont(b: u8) -> bool { |
| 649 | 649 | b.is_ascii_alphanumeric() || b == b'_' |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | fn is_valid_lua_ident(s: &str) -> bool { | |
| 652 | pub(crate) fn is_valid_lua_ident(s: &str) -> bool { | |
| 653 | 653 | let bytes = s.as_bytes(); |
| 654 | 654 | if bytes.is_empty() || !is_ident_start(bytes[0]) || !bytes[1..].iter().all(|&b| is_ident_cont(b)) { |
| 655 | 655 | return false; |
scripts/fusion_probes.py+603| ... | ... | @@ -1317,6 +1317,604 @@ def build_probe_tier1_d(): |
| 1317 | 1317 | return comp_path, "tier1_d", cases |
| 1318 | 1318 | |
| 1319 | 1319 | |
| 1320 | def build_probe_mask_softedge(): | |
| 1321 | """Shale #8 probe: Mask SoftEdge (small..huge), BorderWidth, Solid=0, Filter, ClippingMode, BitmapMask, PolylineMask, and Blur ClippingMode=None + Merge shift.""" | |
| 1322 | grid = generate_grid_chart() | |
| 1323 | cases = [ | |
| 1324 | (0, "ellipse_soft0.01"), | |
| 1325 | (1, "ellipse_soft0.05_small"), | |
| 1326 | (2, "ellipse_soft0.18_large"), | |
| 1327 | (3, "rect_soft0.06_clip_none_edge"), | |
| 1328 | (4, "rect_soft0.06_clip_frame_edge"), | |
| 1329 | (5, "rect_soft0.06_box"), | |
| 1330 | (6, "rect_border0.04_solid0"), | |
| 1331 | (7, "ellipse_border0.03_soft0.02"), | |
| 1332 | (8, "bitmap_luma_low_high_soft0.04"), | |
| 1333 | (9, "bitmap_alpha_soft0.25_inv"), | |
| 1334 | (10, "poly_soft0.08"), | |
| 1335 | (11, "blur_clip_none_merge_shift"), | |
| 1336 | ] | |
| 1337 | nodes = [ | |
| 1338 | make_loader("GridLoader", grid, post_mult=1), | |
| 1339 | """\t\tBlackBG = Background { | |
| 1340 | \t\t\tInputs = { Width = Input { Value = 640, }, Height = Input { Value = 360, }, TopLeftAlpha = Input { Value = 1, }, }, | |
| 1341 | \t\t}, | |
| 1342 | \t\tWhiteFG = Background { | |
| 1343 | \t\t\tInputs = { Width = Input { Value = 640, }, Height = Input { Value = 360, }, TopLeftRed = Input { Value = 1, }, TopLeftGreen = Input { Value = 1, }, TopLeftBlue = Input { Value = 1, }, TopLeftAlpha = Input { Value = 1, }, }, | |
| 1344 | \t\t}, | |
| 1345 | \t\t-- f00: Ellipse SoftEdge=0.01 | |
| 1346 | \t\tMask_0 = EllipseMask { Inputs = { MaskWidth = Input { Value = 640, }, MaskHeight = Input { Value = 360, }, Width = Input { Value = 0.4, }, Height = Input { Value = 0.4, }, SoftEdge = Input { Value = 0.01, }, }, }, | |
| 1347 | \t\tOp_0 = Merge { Inputs = { Background = Input { SourceOp = "BlackBG", Source = "Output", }, Foreground = Input { SourceOp = "WhiteFG", Source = "Output", }, EffectMask = Input { SourceOp = "Mask_0", Source = "Mask", }, }, }, | |
| 1348 | ||
| 1349 | \t\t-- f01: Small Ellipse SoftEdge=0.05 (like 20_falling Ellipse1) | |
| 1350 | \t\tMask_1 = EllipseMask { Inputs = { MaskWidth = Input { Value = 640, }, MaskHeight = Input { Value = 360, }, Center = Input { Value = { 0.35, 0.45 }, }, Width = Input { Value = 0.12, }, Height = Input { Value = 0.12, }, SoftEdge = Input { Value = 0.05, }, Filter = Input { Value = FuID { "Fast Gaussian" }, }, ClippingMode = Input { Value = FuID { "None" }, }, }, }, | |
| 1351 | \t\tOp_1 = Merge { Inputs = { Background = Input { SourceOp = "BlackBG", Source = "Output", }, Foreground = Input { SourceOp = "WhiteFG", Source = "Output", }, EffectMask = Input { SourceOp = "Mask_1", Source = "Mask", }, }, }, | |
| 1352 | ||
| 1353 | \t\t-- f02: Large Ellipse SoftEdge=0.18 | |
| 1354 | \t\tMask_2 = EllipseMask { Inputs = { MaskWidth = Input { Value = 640, }, MaskHeight = Input { Value = 360, }, Width = Input { Value = 0.35, }, Height = Input { Value = 0.35, }, SoftEdge = Input { Value = 0.18, }, Filter = Input { Value = FuID { "Fast Gaussian" }, }, }, }, | |
| 1355 | \t\tOp_2 = Merge { Inputs = { Background = Input { SourceOp = "BlackBG", Source = "Output", }, Foreground = Input { SourceOp = "WhiteFG", Source = "Output", }, EffectMask = Input { SourceOp = "Mask_2", Source = "Mask", }, }, }, | |
| 1356 | ||
| 1357 | \t\t-- f03: Rect SoftEdge=0.06 near bottom edge, ClippingMode=None | |
| 1358 | \t\tMask_3 = RectangleMask { Inputs = { MaskWidth = Input { Value = 640, }, MaskHeight = Input { Value = 360, }, Center = Input { Value = { 0.5, 0.25 }, }, Width = Input { Value = 0.9, }, Height = Input { Value = 0.5, }, SoftEdge = Input { Value = 0.06, }, ClippingMode = Input { Value = FuID { "None" }, }, }, }, | |
| 1359 | \t\tOp_3 = Merge { Inputs = { Background = Input { SourceOp = "BlackBG", Source = "Output", }, Foreground = Input { SourceOp = "WhiteFG", Source = "Output", }, EffectMask = Input { SourceOp = "Mask_3", Source = "Mask", }, }, }, | |
| 1360 | ||
| 1361 | \t\t-- f04: Rect SoftEdge=0.06 near bottom edge, ClippingMode=Frame | |
| 1362 | \t\tMask_4 = RectangleMask { Inputs = { MaskWidth = Input { Value = 640, }, MaskHeight = Input { Value = 360, }, Center = Input { Value = { 0.5, 0.25 }, }, Width = Input { Value = 0.9, }, Height = Input { Value = 0.5, }, SoftEdge = Input { Value = 0.06, }, ClippingMode = Input { Value = FuID { "Frame" }, }, }, }, | |
| 1363 | \t\tOp_4 = Merge { Inputs = { Background = Input { SourceOp = "BlackBG", Source = "Output", }, Foreground = Input { SourceOp = "WhiteFG", Source = "Output", }, EffectMask = Input { SourceOp = "Mask_4", Source = "Mask", }, }, }, | |
| 1364 | ||
| 1365 | \t\t-- f05: Rect SoftEdge=0.06 Filter=Box | |
| 1366 | \t\tMask_5 = RectangleMask { Inputs = { MaskWidth = Input { Value = 640, }, MaskHeight = Input { Value = 360, }, Width = Input { Value = 0.45, }, Height = Input { Value = 0.45, }, SoftEdge = Input { Value = 0.06, }, Filter = Input { Value = FuID { "Box" }, }, }, }, | |
| 1367 | \t\tOp_5 = Merge { Inputs = { Background = Input { SourceOp = "BlackBG", Source = "Output", }, Foreground = Input { SourceOp = "WhiteFG", Source = "Output", }, EffectMask = Input { SourceOp = "Mask_5", Source = "Mask", }, }, }, | |
| 1368 | ||
| 1369 | \t\t-- f06: Rect BorderWidth=0.04 Solid=0 (outline) | |
| 1370 | \t\tMask_6 = RectangleMask { Inputs = { MaskWidth = Input { Value = 640, }, MaskHeight = Input { Value = 360, }, Width = Input { Value = 0.45, }, Height = Input { Value = 0.45, }, Solid = Input { Value = 0, }, BorderWidth = Input { Value = 0.04, }, }, }, | |
| 1371 | \t\tOp_6 = Merge { Inputs = { Background = Input { SourceOp = "BlackBG", Source = "Output", }, Foreground = Input { SourceOp = "WhiteFG", Source = "Output", }, EffectMask = Input { SourceOp = "Mask_6", Source = "Mask", }, }, }, | |
| 1372 | ||
| 1373 | \t\t-- f07: Ellipse BorderWidth=0.03 Solid=1 SoftEdge=0.02 | |
| 1374 | \t\tMask_7 = EllipseMask { Inputs = { MaskWidth = Input { Value = 640, }, MaskHeight = Input { Value = 360, }, Width = Input { Value = 0.30, }, Height = Input { Value = 0.30, }, Solid = Input { Value = 1, }, BorderWidth = Input { Value = 0.03, }, SoftEdge = Input { Value = 0.02, }, }, }, | |
| 1375 | \t\tOp_7 = Merge { Inputs = { Background = Input { SourceOp = "BlackBG", Source = "Output", }, Foreground = Input { SourceOp = "WhiteFG", Source = "Output", }, EffectMask = Input { SourceOp = "Mask_7", Source = "Mask", }, }, }, | |
| 1376 | ||
| 1377 | \t\t-- f08: BitmapMask Luminance + Low/High + SoftEdge=0.04 | |
| 1378 | \t\tMask_8 = BitmapMask { Inputs = { Image = Input { SourceOp = "GridLoader", Source = "Output", }, Channel = Input { Value = FuID { "Luminance" }, }, Low = Input { Value = 0.2, }, High = Input { Value = 0.8, }, SoftEdge = Input { Value = 0.04, }, }, }, | |
| 1379 | \t\tOp_8 = Merge { Inputs = { Background = Input { SourceOp = "BlackBG", Source = "Output", }, Foreground = Input { SourceOp = "WhiteFG", Source = "Output", }, EffectMask = Input { SourceOp = "Mask_8", Source = "Mask", }, }, }, | |
| 1380 | ||
| 1381 | \t\t-- f09: BitmapMask Alpha + huge SoftEdge=0.25 + Invert=1 | |
| 1382 | \t\tBmSrc_9 = RectangleMask { Inputs = { MaskWidth = Input { Value = 640, }, MaskHeight = Input { Value = 360, }, Width = Input { Value = 0.35, }, Height = Input { Value = 0.35, }, }, }, | |
| 1383 | \t\tBmImg_9 = Merge { Inputs = { Background = Input { SourceOp = "BlackBG", Source = "Output", }, Foreground = Input { SourceOp = "WhiteFG", Source = "Output", }, EffectMask = Input { SourceOp = "BmSrc_9", Source = "Mask", }, }, }, | |
| 1384 | \t\tMask_9 = BitmapMask { Inputs = { Image = Input { SourceOp = "BmImg_9", Source = "Output", }, Channel = Input { Value = FuID { "Luminance" }, }, SoftEdge = Input { Value = 0.25, }, Invert = Input { Value = 1, }, }, }, | |
| 1385 | \t\tOp_9 = Merge { Inputs = { Background = Input { SourceOp = "BlackBG", Source = "Output", }, Foreground = Input { SourceOp = "WhiteFG", Source = "Output", }, EffectMask = Input { SourceOp = "Mask_9", Source = "Mask", }, }, }, | |
| 1386 | ||
| 1387 | \t\t-- f10: PolylineMask SoftEdge=0.08 | |
| 1388 | \t\tMask_10 = PolylineMask { | |
| 1389 | \t\t\tInputs = { | |
| 1390 | \t\t\t\tMaskWidth = Input { Value = 640, }, | |
| 1391 | \t\t\t\tMaskHeight = Input { Value = 360, }, | |
| 1392 | \t\t\t\tSoftEdge = Input { Value = 0.08, }, | |
| 1393 | \t\t\t\tPolyline = Input { | |
| 1394 | \t\t\t\t\tValue = Polyline { | |
| 1395 | \t\t\t\t\t\tClosed = true, | |
| 1396 | \t\t\t\t\t\tPoints = { | |
| 1397 | \t\t\t\t\t\t\t{ Linear = true, X = -0.25, Y = -0.20, RX = 0.16, RY = 0 }, | |
| 1398 | \t\t\t\t\t\t\t{ Linear = true, X = 0.25, Y = -0.20, LX = -0.16, LY = 0, RX = -0.08, RY = 0.14 }, | |
| 1399 | \t\t\t\t\t\t\t{ Linear = true, X = 0.0, Y = 0.25, LX = 0.08, LY = -0.14 }, | |
| 1400 | \t\t\t\t\t\t}, | |
| 1401 | \t\t\t\t\t}, | |
| 1402 | \t\t\t\t}, | |
| 1403 | \t\t\t}, | |
| 1404 | \t\t}, | |
| 1405 | \t\tOp_10 = Merge { Inputs = { Background = Input { SourceOp = "BlackBG", Source = "Output", }, Foreground = Input { SourceOp = "WhiteFG", Source = "Output", }, EffectMask = Input { SourceOp = "Mask_10", Source = "Mask", }, }, }, | |
| 1406 | ||
| 1407 | \t\t-- f11: Blur ClippingMode=None on solid WhiteFG shifted down by Merge (20_falling Blur2->Merge7!) | |
| 1408 | \t\tBl_11 = Blur { Inputs = { Input = Input { SourceOp = "WhiteFG", Source = "Output", }, Filter = Input { Value = FuID { "Fast Gaussian" }, }, XBlurSize = Input { Value = 25.0, }, ClippingMode = Input { Value = FuID { "None" }, }, }, }, | |
| 1409 | \t\tOp_11 = Merge { Inputs = { Background = Input { SourceOp = "BlackBG", Source = "Output", }, Foreground = Input { SourceOp = "Bl_11", Source = "Output", }, Center = Input { Value = { 0.5, 0.20 }, }, Size = Input { Value = 1.1, }, }, },""", | |
| 1410 | ] | |
| 1411 | splines = [] | |
| 1412 | prev = "BlackBG" | |
| 1413 | for f, _label in cases: | |
| 1414 | bl = {c[0]: (1.0 if c[0] == f else 0.0) for c in cases} | |
| 1415 | sname = f"Mse_{f}_Blend" | |
| 1416 | splines.append(step_spline(sname, bl)) | |
| 1417 | nodes.append(f"""\t\tSw_{f} = Merge {{ | |
| 1418 | \t\t\tInputs = {{ | |
| 1419 | \t\t\t\tBlend = Input {{ SourceOp = "{sname}", Source = "Value", }}, | |
| 1420 | \t\t\t\tBackground = Input {{ SourceOp = "{prev}", Source = "Output", }}, | |
| 1421 | \t\t\t\tForeground = Input {{ SourceOp = "Op_{f}", Source = "Output", }}, | |
| 1422 | \t\t\t}}, | |
| 1423 | \t\t}},""") | |
| 1424 | prev = f"Sw_{f}" | |
| 1425 | nodes.append(make_saver(prev, "mask_softedge")) | |
| 1426 | comp_path = local_root() / "comps" / "probe_mask_softedge.comp" | |
| 1427 | comp_path.write_text(make_comp("\n".join(nodes + splines), len(cases) - 1, w=640, h=360)) | |
| 1428 | return comp_path, "mask_softedge", cases | |
| 1429 | ||
| 1430 | ||
| 1431 | def build_probe_displace_wave(): | |
| 1432 | """Shale #9 probe: Displace XY default channels/offset/scale, CustomTool sine wave + Lua expr, FastNoise Discontinuous/Type=1/high-Seethe.""" | |
| 1433 | grid = generate_grid_chart() | |
| 1434 | cases = [ | |
| 1435 | (0, "disp_xy_defaults_grid"), | |
| 1436 | (1, "disp_xy_grad_off0"), | |
| 1437 | (2, "disp_xy_grad_off-0.5"), | |
| 1438 | (3, "disp_xy_ch1_ch0_off-0.5"), | |
| 1439 | (4, "disp_custom_wave_expr"), | |
| 1440 | (5, "fastnoise_disc_detail10_grad"), | |
| 1441 | (6, "fastnoise_disc_high_seethe"), | |
| 1442 | (7, "fastnoise_type1_2d_disc"), | |
| 1443 | (8, "fastnoise_type0_xscale0_disc"), | |
| 1444 | ] | |
| 1445 | nodes = [ | |
| 1446 | make_loader("GridLoader", grid, post_mult=1), | |
| 1447 | """\t\tBlackBG = Background { Inputs = { Width = Input { Value = 512, }, Height = Input { Value = 512, }, TopLeftAlpha = Input { Value = 1, }, }, }, | |
| 1448 | \t\tGradH = Background { | |
| 1449 | \t\t\tInputs = { | |
| 1450 | \t\t\t\tWidth = Input { Value = 512, }, Height = Input { Value = 512, }, | |
| 1451 | \t\t\t\tType = Input { Value = FuID { "Horizontal" }, }, | |
| 1452 | \t\t\t\tTopLeftRed = Input { Value = 0, }, TopLeftGreen = Input { Value = 0, }, TopLeftBlue = Input { Value = 0, }, TopLeftAlpha = Input { Value = 1, }, | |
| 1453 | \t\t\t\tTopRightRed = Input { Value = 1, }, TopRightGreen = Input { Value = 0.25, }, TopRightBlue = Input { Value = 0.75, }, TopRightAlpha = Input { Value = 1, }, | |
| 1454 | \t\t\t}, | |
| 1455 | \t\t}, | |
| 1456 | \t\t-- f00: Displace Type=1 default XChannel/YChannel/XOffset/YOffset | |
| 1457 | \t\tOp_0 = Displace { | |
| 1458 | \t\t\tInputs = { | |
| 1459 | \t\t\t\tType = Input { Value = 1, }, | |
| 1460 | \t\t\t\tXRefraction = Input { Value = 0.05, }, | |
| 1461 | \t\t\t\tYRefraction = Input { Value = 0.05, }, | |
| 1462 | \t\t\t\tInput = Input { SourceOp = "GridLoader", Source = "Output", }, | |
| 1463 | \t\t\t\tForeground = Input { SourceOp = "GradH", Source = "Output", }, | |
| 1464 | \t\t\t}, | |
| 1465 | \t\t}, | |
| 1466 | \t\t-- f01: Displace Type=1 XOffset=0 XRefraction=0.08 | |
| 1467 | \t\tOp_1 = Displace { | |
| 1468 | \t\t\tInputs = { | |
| 1469 | \t\t\t\tType = Input { Value = 1, }, | |
| 1470 | \t\t\t\tXOffset = Input { Value = 0.0, }, | |
| 1471 | \t\t\t\tXRefraction = Input { Value = 0.08, }, | |
| 1472 | \t\t\t\tInput = Input { SourceOp = "GridLoader", Source = "Output", }, | |
| 1473 | \t\t\t\tForeground = Input { SourceOp = "GradH", Source = "Output", }, | |
| 1474 | \t\t\t}, | |
| 1475 | \t\t}, | |
| 1476 | \t\t-- f02: Displace Type=1 XOffset=-0.5 XRefraction=0.08 | |
| 1477 | \t\tOp_2 = Displace { | |
| 1478 | \t\t\tInputs = { | |
| 1479 | \t\t\t\tType = Input { Value = 1, }, | |
| 1480 | \t\t\t\tXOffset = Input { Value = -0.5, }, | |
| 1481 | \t\t\t\tXRefraction = Input { Value = 0.08, }, | |
| 1482 | \t\t\t\tInput = Input { SourceOp = "GridLoader", Source = "Output", }, | |
| 1483 | \t\t\t\tForeground = Input { SourceOp = "GradH", Source = "Output", }, | |
| 1484 | \t\t\t}, | |
| 1485 | \t\t}, | |
| 1486 | \t\t-- f03: Displace Type=1 XChannel=1 YChannel=0 XOffset=-0.5 YOffset=-0.5 | |
| 1487 | \t\tOp_3 = Displace { | |
| 1488 | \t\t\tInputs = { | |
| 1489 | \t\t\t\tType = Input { Value = 1, }, | |
| 1490 | \t\t\t\tXChannel = Input { Value = 1, }, | |
| 1491 | \t\t\t\tYChannel = Input { Value = 0, }, | |
| 1492 | \t\t\t\tXOffset = Input { Value = -0.5, }, | |
| 1493 | \t\t\t\tYOffset = Input { Value = -0.5, }, | |
| 1494 | \t\t\t\tXRefraction = Input { Value = 0.05, }, | |
| 1495 | \t\t\t\tYRefraction = Input { Value = 0.05, }, | |
| 1496 | \t\t\t\tInput = Input { SourceOp = "GridLoader", Source = "Output", }, | |
| 1497 | \t\t\t\tForeground = Input { SourceOp = "GradH", Source = "Output", }, | |
| 1498 | \t\t\t}, | |
| 1499 | \t\t}, | |
| 1500 | \t\t-- f04: CustomTool sine wave + Displace Lua expression | |
| 1501 | \t\tCustomWave1 = Custom { | |
| 1502 | \t\t\tInputs = { | |
| 1503 | \t\t\t\tRedExpression = Input { Value = "sin(x*w*n1 + n2*n1*w)*0.5+0.5", }, | |
| 1504 | \t\t\t\tGreenExpression = Input { Value = "sin(y*w*n1 + n2*n1*w)*0.5+0.5", }, | |
| 1505 | \t\t\t\tBlueExpression = Input { Value = "0", }, | |
| 1506 | \t\t\t\tAlphaExpression = Input { Value = "1", }, | |
| 1507 | \t\t\t\tImage1 = Input { SourceOp = "GridLoader", Source = "Output", }, | |
| 1508 | \t\t\t\tNumberIn1 = Input { Value = 0.7413, }, | |
| 1509 | \t\t\t\tNumberIn2 = Input { Value = 1.5, }, | |
| 1510 | \t\t\t\tWaveDirection = Input { Value = 0, }, | |
| 1511 | \t\t\t\tWaveAmp = Input { Value = 0.04, }, | |
| 1512 | \t\t\t}, | |
| 1513 | \t\t\tUserControls = ordered() { | |
| 1514 | \t\t\t\tWaveDirection = { INP_Default = 0, INPID_InputControl = "ComboControl", LINKID_DataType = "Number", }, | |
| 1515 | \t\t\t\tWaveAmp = { INP_Default = 0.04, INPID_InputControl = "SliderControl", LINKID_DataType = "Number", }, | |
| 1516 | \t\t\t}, | |
| 1517 | \t\t}, | |
| 1518 | \t\tOp_4 = Displace { | |
| 1519 | \t\t\tInputs = { | |
| 1520 | \t\t\t\tType = Input { Value = 1, }, | |
| 1521 | \t\t\t\tXChannel = Input { Value = 1, }, | |
| 1522 | \t\t\t\tYChannel = Input { Value = 0, }, | |
| 1523 | \t\t\t\tXOffset = Input { Value = -0.5, }, | |
| 1524 | \t\t\t\tYOffset = Input { Value = -0.5, }, | |
| 1525 | \t\t\t\tXRefraction = Input { Expression = "(CustomWave1.WaveDirection == 0) and (CustomWave1.WaveAmp) or 0", }, | |
| 1526 | \t\t\t\tYRefraction = Input { Expression = "(CustomWave1.WaveDirection == 1) and (CustomWave1.WaveAmp) or 0", }, | |
| 1527 | \t\t\t\tInput = Input { SourceOp = "GridLoader", Source = "Output", }, | |
| 1528 | \t\t\t\tForeground = Input { SourceOp = "CustomWave1", Source = "Output", }, | |
| 1529 | \t\t\t}, | |
| 1530 | \t\t}, | |
| 1531 | \t\t-- f05: FastNoise Discontinuous=1 Detail=10 XScale=0 YScale=80 Type=1 Gradient | |
| 1532 | \t\tOp_5 = FastNoise { | |
| 1533 | \t\t\tInputs = { | |
| 1534 | \t\t\t\tWidth = Input { Value = 512, }, Height = Input { Value = 512, }, | |
| 1535 | \t\t\t\tDetail = Input { Value = 10, }, | |
| 1536 | \t\t\t\tLockXY = Input { Value = 0, }, | |
| 1537 | \t\t\t\tXScale = Input { Value = 0, }, | |
| 1538 | \t\t\t\tYScale = Input { Value = 80, }, | |
| 1539 | \t\t\t\tSeethe = Input { Value = 8.377, }, | |
| 1540 | \t\t\t\tDiscontinuous = Input { Value = 1, }, | |
| 1541 | \t\t\t\tType = Input { Value = 1, }, | |
| 1542 | \t\t\t\tColor1Alpha = Input { Value = 1, }, | |
| 1543 | \t\t\t\tGradient = Input { | |
| 1544 | \t\t\t\t\tValue = Gradient { | |
| 1545 | \t\t\t\t\t\tColors = { | |
| 1546 | \t\t\t\t\t\t\t[0] = { 0, 0, 0, 1 }, | |
| 1547 | \t\t\t\t\t\t\t[0.428] = { 0.5, 0, 0, 1 }, | |
| 1548 | \t\t\t\t\t\t\t[0.552] = { 0.5, 0, 0, 1 }, | |
| 1549 | \t\t\t\t\t\t\t[1] = { 1, 1, 1, 1 }, | |
| 1550 | \t\t\t\t\t\t}, | |
| 1551 | \t\t\t\t\t}, | |
| 1552 | \t\t\t\t}, | |
| 1553 | \t\t\t}, | |
| 1554 | \t\t}, | |
| 1555 | \t\t-- f06: FastNoise Discontinuous=1 Detail=10 XScale=10 YScale=10 Seethe=29820 | |
| 1556 | \t\tOp_6 = FastNoise { | |
| 1557 | \t\t\tInputs = { | |
| 1558 | \t\t\t\tWidth = Input { Value = 512, }, Height = Input { Value = 512, }, | |
| 1559 | \t\t\t\tDetail = Input { Value = 10, }, | |
| 1560 | \t\t\t\tXScale = Input { Value = 10, }, | |
| 1561 | \t\t\t\tYScale = Input { Value = 10, }, | |
| 1562 | \t\t\t\tSeethe = Input { Value = 29820, }, | |
| 1563 | \t\t\t\tDiscontinuous = Input { Value = 1, }, | |
| 1564 | \t\t\t\tColor1Alpha = Input { Value = 1, }, | |
| 1565 | \t\t\t}, | |
| 1566 | \t\t}, | |
| 1567 | \t\t-- f07: FastNoise Type=1 linear 0..1 gradient, 2D (XScale=10, YScale=10), Discontinuous=1 | |
| 1568 | \t\tOp_7 = FastNoise { | |
| 1569 | \t\t\tInputs = { | |
| 1570 | \t\t\t\tWidth = Input { Value = 512, }, Height = Input { Value = 512, }, | |
| 1571 | \t\t\t\tDetail = Input { Value = 10, }, | |
| 1572 | \t\t\t\tXScale = Input { Value = 10, }, | |
| 1573 | \t\t\t\tYScale = Input { Value = 10, }, | |
| 1574 | \t\t\t\tSeethe = Input { Value = 8.377, }, | |
| 1575 | \t\t\t\tDiscontinuous = Input { Value = 1, }, | |
| 1576 | \t\t\t\tType = Input { Value = 1, }, | |
| 1577 | \t\t\t\tGradient = Input { Value = Gradient { Colors = { [0] = { 0, 0, 0, 1 }, [1] = { 1, 1, 1, 1 } }, }, }, | |
| 1578 | \t\t\t}, | |
| 1579 | \t\t}, | |
| 1580 | \t\t-- f08: FastNoise Type=0 TwoColor, XScale=0 YScale=80, Discontinuous=1 | |
| 1581 | \t\tOp_8 = FastNoise { | |
| 1582 | \t\t\tInputs = { | |
| 1583 | \t\t\t\tWidth = Input { Value = 512, }, Height = Input { Value = 512, }, | |
| 1584 | \t\t\t\tDetail = Input { Value = 10, }, | |
| 1585 | \t\t\t\tLockXY = Input { Value = 0, }, | |
| 1586 | \t\t\t\tXScale = Input { Value = 0, }, | |
| 1587 | \t\t\t\tYScale = Input { Value = 80, }, | |
| 1588 | \t\t\t\tSeethe = Input { Value = 8.377, }, | |
| 1589 | \t\t\t\tDiscontinuous = Input { Value = 1, }, | |
| 1590 | \t\t\t\tColor1Alpha = Input { Value = 1, }, | |
| 1591 | \t\t\t}, | |
| 1592 | \t\t},""", | |
| 1593 | ] | |
| 1594 | splines = [] | |
| 1595 | prev = "BlackBG" | |
| 1596 | for f, _label in cases: | |
| 1597 | bl = {c[0]: (1.0 if c[0] == f else 0.0) for c in cases} | |
| 1598 | sname = f"Dw_{f}_Blend" | |
| 1599 | splines.append(step_spline(sname, bl)) | |
| 1600 | nodes.append(f"""\t\tSw_{f} = Merge {{ | |
| 1601 | \t\t\tInputs = {{ | |
| 1602 | \t\t\t\tBlend = Input {{ SourceOp = "{sname}", Source = "Value", }}, | |
| 1603 | \t\t\t\tBackground = Input {{ SourceOp = "{prev}", Source = "Output", }}, | |
| 1604 | \t\t\t\tForeground = Input {{ SourceOp = "Op_{f}", Source = "Output", }}, | |
| 1605 | \t\t\t}}, | |
| 1606 | \t\t}},""") | |
| 1607 | prev = f"Sw_{f}" | |
| 1608 | nodes.append(make_saver(prev, "displace_wave")) | |
| 1609 | comp_path = local_root() / "comps" / "probe_displace_wave.comp" | |
| 1610 | comp_path.write_text(make_comp("\n".join(nodes + splines), len(cases) - 1)) | |
| 1611 | return comp_path, "displace_wave", cases | |
| 1612 | ||
| 1613 | ||
| 1614 | def build_probe_vortex_cc(): | |
| 1615 | """Shale #10 probe: Vortex warp + ColorCorrector TintMode & Shadows/Midtones/Highlights wheels.""" | |
| 1616 | grid = generate_grid_chart() | |
| 1617 | chart = generate_color_chart() | |
| 1618 | cases = [ | |
| 1619 | (0, "vortex_default"), | |
| 1620 | (1, "vortex_s0.6_a2.5_p2"), | |
| 1621 | (2, "vortex_s3.82_a2.1_p3.3"), | |
| 1622 | (3, "vortex_offcenter_neg"), | |
| 1623 | (4, "cc_tintmode0_len1_sat1.52"), | |
| 1624 | (5, "cc_tintmode1_len1_sat1.52"), | |
| 1625 | (6, "cc_tintmode0_len0.5"), | |
| 1626 | (7, "cc_tintmode1_len0.5"), | |
| 1627 | (8, "cc_smh_wheels"), | |
| 1628 | (9, "cc_smh_lgg"), | |
| 1629 | ] | |
| 1630 | nodes = [ | |
| 1631 | make_loader("GridLoader", grid, post_mult=1), | |
| 1632 | make_loader("ChartLoader", chart, post_mult=1), | |
| 1633 | """\t\tBlackBG = Background { Inputs = { Width = Input { Value = 512, }, Height = Input { Value = 512, }, TopLeftAlpha = Input { Value = 1, }, }, }, | |
| 1634 | \t\tOp_0 = Vortex { Inputs = { Input = Input { SourceOp = "GridLoader", Source = "Output", }, Size = Input { Value = 0.5, }, Angle = Input { Value = 1.0, }, Power = Input { Value = 1.0, }, }, }, | |
| 1635 | \t\tOp_1 = Vortex { Inputs = { Input = Input { SourceOp = "GridLoader", Source = "Output", }, Size = Input { Value = 0.6, }, Angle = Input { Value = 2.5, }, Power = Input { Value = 2.0, }, }, }, | |
| 1636 | \t\tOp_2 = Vortex { Inputs = { Input = Input { SourceOp = "GridLoader", Source = "Output", }, Size = Input { Value = 3.82, }, Angle = Input { Value = 2.1, }, Power = Input { Value = 3.3, }, }, }, | |
| 1637 | \t\tOp_3 = Vortex { Inputs = { Input = Input { SourceOp = "GridLoader", Source = "Output", }, Center = Input { Value = { 0.3, 0.7 }, }, Size = Input { Value = 0.5, }, Angle = Input { Value = -2.0, }, Power = Input { Value = 1.5, }, }, }, | |
| 1638 | \t\tOp_4 = ColorCorrector { Inputs = { Input = Input { SourceOp = "ChartLoader", Source = "Output", }, WheelTintAngle1 = Input { Value = -0.24, }, WheelTintLength1 = Input { Value = 1.0, }, WheelSaturation1 = Input { Value = 1.52, }, TintMode = Input { Value = 0, }, }, }, | |
| 1639 | \t\tOp_5 = ColorCorrector { Inputs = { Input = Input { SourceOp = "ChartLoader", Source = "Output", }, WheelTintAngle1 = Input { Value = -0.24, }, WheelTintLength1 = Input { Value = 1.0, }, WheelSaturation1 = Input { Value = 1.52, }, TintMode = Input { Value = 1, }, }, }, | |
| 1640 | \t\tOp_6 = ColorCorrector { Inputs = { Input = Input { SourceOp = "ChartLoader", Source = "Output", }, WheelTintAngle1 = Input { Value = -0.24, }, WheelTintLength1 = Input { Value = 0.5, }, TintMode = Input { Value = 0, }, }, }, | |
| 1641 | \t\tOp_7 = ColorCorrector { Inputs = { Input = Input { SourceOp = "ChartLoader", Source = "Output", }, WheelTintAngle1 = Input { Value = -0.24, }, WheelTintLength1 = Input { Value = 0.5, }, TintMode = Input { Value = 1, }, }, }, | |
| 1642 | \t\tOp_8 = ColorCorrector { Inputs = { Input = Input { SourceOp = "ChartLoader", Source = "Output", }, WheelTintAngle2 = Input { Value = 0.1, }, WheelTintLength2 = Input { Value = 0.6, }, WheelHue3 = Input { Value = 0.2, }, WheelSaturation4 = Input { Value = 1.5, }, }, }, | |
| 1643 | \t\tOp_9 = ColorCorrector { Inputs = { Input = Input { SourceOp = "ChartLoader", Source = "Output", }, ShadowsRGBGain = Input { Value = 0.7, }, MidtonesRGBGamma = Input { Value = 1.4, }, HighlightsRGBGain = Input { Value = 1.25, }, }, },""", | |
| 1644 | ] | |
| 1645 | splines = [] | |
| 1646 | prev = "BlackBG" | |
| 1647 | for f, _label in cases: | |
| 1648 | bl = {c[0]: (1.0 if c[0] == f else 0.0) for c in cases} | |
| 1649 | sname = f"Vcc_{f}_Blend" | |
| 1650 | splines.append(step_spline(sname, bl)) | |
| 1651 | nodes.append(f"""\t\tSw_{f} = Merge {{ | |
| 1652 | \t\t\tInputs = {{ | |
| 1653 | \t\t\t\tBlend = Input {{ SourceOp = "{sname}", Source = "Value", }}, | |
| 1654 | \t\t\t\tBackground = Input {{ SourceOp = "{prev}", Source = "Output", }}, | |
| 1655 | \t\t\t\tForeground = Input {{ SourceOp = "Op_{f}", Source = "Output", }}, | |
| 1656 | \t\t\t}}, | |
| 1657 | \t\t}},""") | |
| 1658 | prev = f"Sw_{f}" | |
| 1659 | nodes.append(make_saver(prev, "vortex_cc")) | |
| 1660 | comp_path = local_root() / "comps" / "probe_vortex_cc.comp" | |
| 1661 | comp_path.write_text(make_comp("\n".join(nodes + splines), len(cases) - 1)) | |
| 1662 | return comp_path, "vortex_cc", cases | |
| 1663 | ||
| 1664 | ||
| 1665 | def build_probe_moon_3d(): | |
| 1666 | """Shale #10 probe: Shape3D Sphere default radius + 1:1 Camera3D w/ 16:9 Aperture + mismatched BG/FG Merge Size + FastNoise Contrast/Brightness.""" | |
| 1667 | grid = generate_grid_chart() | |
| 1668 | cases = [ | |
| 1669 | (0, "sphere_cam_1x1_ap16x9"), | |
| 1670 | (1, "merge_bg1024x512_fg256_s0.6"), | |
| 1671 | (2, "fastnoise_low_contrast_neg_bright"), | |
| 1672 | ] | |
| 1673 | nodes = [ | |
| 1674 | make_loader("GridLoader", grid, post_mult=1), | |
| 1675 | """\t\tBlackBG = Background { Inputs = { Width = Input { Value = 512, }, Height = Input { Value = 512, }, TopLeftAlpha = Input { Value = 1, }, }, }, | |
| 1676 | \t\tWhite256 = Background { Inputs = { Width = Input { Value = 256, }, Height = Input { Value = 256, }, TopLeftRed = Input { Value = 1, }, TopLeftGreen = Input { Value = 0.8, }, TopLeftBlue = Input { Value = 0.2, }, TopLeftAlpha = Input { Value = 1, }, }, }, | |
| 1677 | \t\tDark1024 = Background { Inputs = { Width = Input { Value = 1024, }, Height = Input { Value = 512, }, TopLeftRed = Input { Value = 0.1, }, TopLeftGreen = Input { Value = 0.1, }, TopLeftBlue = Input { Value = 0.2, }, TopLeftAlpha = Input { Value = 1, }, }, }, | |
| 1678 | \t\t-- f00: Exact 60_moon_guide_u Shape3D1 + Camera3D1 + Renderer3D1 (512x512 1:1 with 16:9 Aperture) | |
| 1679 | \t\tSph0 = Shape3D { | |
| 1680 | \t\t\tInputs = { | |
| 1681 | \t\t\t\tShape = Input { Value = FuID { "SurfaceSphereInputs" }, }, | |
| 1682 | \t\t\t\t["MtlStdInputs.Diffuse.Color.Red"] = Input { Value = 0.8, }, | |
| 1683 | \t\t\t\t["MtlStdInputs.Diffuse.Color.Green"] = Input { Value = 0.8, }, | |
| 1684 | \t\t\t\t["MtlStdInputs.Diffuse.Color.Blue"] = Input { Value = 0.8, }, | |
| 1685 | \t\t\t}, | |
| 1686 | \t\t}, | |
| 1687 | \t\tCam0 = Camera3D { | |
| 1688 | \t\t\tInputs = { | |
| 1689 | \t\t\t\t["Transform3DOp.Translate.Z"] = Input { Value = 6.17286473705227, }, | |
| 1690 | \t\t\t\tAoV = Input { Value = 19.2642683071402, }, | |
| 1691 | \t\t\t\tFilmGate = Input { Value = FuID { "BMD_URSA_4K_16x9" }, }, | |
| 1692 | \t\t\t\tApertureW = Input { Value = 0.831496062992126, }, | |
| 1693 | \t\t\t\tApertureH = Input { Value = 0.467716535433071, }, | |
| 1694 | \t\t\t}, | |
| 1695 | \t\t}, | |
| 1696 | \t\tM3D0 = Merge3D { Inputs = { SceneInput1 = Input { SourceOp = "Sph0", Source = "Output", }, SceneInput2 = Input { SourceOp = "Cam0", Source = "Output", }, }, }, | |
| 1697 | \t\tOp_0 = Renderer3D { Inputs = { Width = Input { Value = 512, }, Height = Input { Value = 512, }, SceneInput = Input { SourceOp = "M3D0", Source = "Output", }, }, }, | |
| 1698 | ||
| 1699 | \t\t-- f01: Merge 256x256 FG onto 1024x512 BG at Size=0.6, then scaled to 512x512 | |
| 1700 | \t\tM_1 = Merge { Inputs = { Background = Input { SourceOp = "Dark1024", Source = "Output", }, Foreground = Input { SourceOp = "White256", Source = "Output", }, Size = Input { Value = 0.6, }, }, }, | |
| 1701 | \t\tOp_1 = BetterResize { Inputs = { Input = Input { SourceOp = "M_1", Source = "Output", }, Width = Input { Value = 512, }, Height = Input { Value = 512, }, }, }, | |
| 1702 | ||
| 1703 | \t\t-- f02: Exact Noise_1 from 60_moon_guide_u (Detail=0.39, Contrast=0.23, Brightness=-0.4, Discontinuous=1, Type=1) | |
| 1704 | \t\tOp_2 = FastNoise { | |
| 1705 | \t\t\tInputs = { | |
| 1706 | \t\t\t\tWidth = Input { Value = 512, }, Height = Input { Value = 512, }, | |
| 1707 | \t\t\t\tDetail = Input { Value = 0.39, }, | |
| 1708 | \t\t\t\tContrast = Input { Value = 0.23, }, | |
| 1709 | \t\t\t\tBrightness = Input { Value = -0.4, }, | |
| 1710 | \t\t\t\tXScale = Input { Value = 28.1, }, | |
| 1711 | \t\t\t\tYScale = Input { Value = 10, }, | |
| 1712 | \t\t\t\tAngle = Input { Value = 114.8, }, | |
| 1713 | \t\t\t\tDiscontinuous = Input { Value = 1, }, | |
| 1714 | \t\t\t\tType = Input { Value = 1, }, | |
| 1715 | \t\t\t\tColor1Alpha = Input { Value = 1, }, | |
| 1716 | \t\t\t}, | |
| 1717 | \t\t},""", | |
| 1718 | ] | |
| 1719 | splines = [] | |
| 1720 | prev = "BlackBG" | |
| 1721 | for f, _label in cases: | |
| 1722 | bl = {c[0]: (1.0 if c[0] == f else 0.0) for c in cases} | |
| 1723 | sname = f"M3_{f}_Blend" | |
| 1724 | splines.append(step_spline(sname, bl)) | |
| 1725 | nodes.append(f"""\t\tSw_{f} = Merge {{ | |
| 1726 | \t\t\tInputs = {{ | |
| 1727 | \t\t\t\tBlend = Input {{ SourceOp = "{sname}", Source = "Value", }}, | |
| 1728 | \t\t\t\tBackground = Input {{ SourceOp = "{prev}", Source = "Output", }}, | |
| 1729 | \t\t\t\tForeground = Input {{ SourceOp = "Op_{f}", Source = "Output", }}, | |
| 1730 | \t\t\t}}, | |
| 1731 | \t\t}},""") | |
| 1732 | prev = f"Sw_{f}" | |
| 1733 | nodes.append(make_saver(prev, "moon_3d")) | |
| 1734 | comp_path = local_root() / "comps" / "probe_moon_3d.comp" | |
| 1735 | comp_path.write_text(make_comp("\n".join(nodes + splines), len(cases) - 1)) | |
| 1736 | return comp_path, "moon_3d", cases | |
| 1737 | ||
| 1738 | ||
| 1739 | def generate_greenscreen_chart(w=512, h=512) -> str: | |
| 1740 | """512x512 RGB ramp spanning typical green-screen shades, skin tones, grays, and primaries.""" | |
| 1741 | p = local_root() / "assets" / "greenscreen_chart.png" | |
| 1742 | buf = bytearray(w * h * 4) | |
| 1743 | for y in range(h): | |
| 1744 | v = y / (h - 1) | |
| 1745 | for x in range(w): | |
| 1746 | u = x / (w - 1) | |
| 1747 | if y < h // 2: | |
| 1748 | # Top half: varied green-screen shades around (0.38, 0.58, 0.53) and (0.16, 0.72, 0.23) | |
| 1749 | # u varies luminance/exposure, v varies greenness/saturation | |
| 1750 | t = v * 2.0 | |
| 1751 | r = max(0.0, min(1.0, (0.05 + 0.55 * u) * (1.0 - 0.5 * (1.0 - t)))) | |
| 1752 | g = max(0.0, min(1.0, 0.25 + 0.65 * u + 0.15 * (1.0 - t))) | |
| 1753 | b = max(0.0, min(1.0, (0.05 + 0.55 * u) * (0.3 + 0.7 * t))) | |
| 1754 | else: | |
| 1755 | # Bottom half: hue wheel + skin/neutral stripes | |
| 1756 | t = (v - 0.5) * 2.0 | |
| 1757 | if t < 0.5: | |
| 1758 | # Hue sweep at high sat | |
| 1759 | h6 = u * 6.0 | |
| 1760 | c = 0.75 | |
| 1761 | x_c = c * (1.0 - abs((h6 % 2.0) - 1.0)) | |
| 1762 | m = 0.15 | |
| 1763 | if h6 < 1: r, g, b = c+m, x_c+m, m | |
| 1764 | elif h6 < 2: r, g, b = x_c+m, c+m, m | |
| 1765 | elif h6 < 3: r, g, b = m, c+m, x_c+m | |
| 1766 | elif h6 < 4: r, g, b = m, x_c+m, c+m | |
| 1767 | elif h6 < 5: r, g, b = x_c+m, m, c+m | |
| 1768 | else: r, g, b = c+m, m, x_c+m | |
| 1769 | else: | |
| 1770 | # Skin tone to gray to teal gradient | |
| 1771 | s = (t - 0.5) * 2.0 | |
| 1772 | r = 0.85 * (1.0 - u) + 0.25 * u | |
| 1773 | g = 0.65 * (1.0 - u) + 0.58 * u | |
| 1774 | b = 0.55 * (1.0 - u) + 0.53 * u | |
| 1775 | r = r * (1.0 - 0.4 * s) + 0.4 * s | |
| 1776 | g = g * (1.0 - 0.4 * s) + 0.4 * s | |
| 1777 | b = b * (1.0 - 0.4 * s) + 0.4 * s | |
| 1778 | idx = (y * w + x) * 4 | |
| 1779 | buf[idx] = int(round(max(0.0, min(1.0, r)) * 255)) | |
| 1780 | buf[idx + 1] = int(round(max(0.0, min(1.0, g)) * 255)) | |
| 1781 | buf[idx + 2] = int(round(max(0.0, min(1.0, b)) * 255)) | |
| 1782 | buf[idx + 3] = 255 | |
| 1783 | write_png_rgba(p, w, h, bytes(buf)) | |
| 1784 | return f"{CONTAINER_ROOT}/assets/greenscreen_chart.png" | |
| 1785 | ||
| 1786 | ||
| 1787 | def build_probe_ultrakey(): | |
| 1788 | """Shale #10 probe: UltraKeyer exact matte/threshold/range/PostMultiply/MatteBlur parity.""" | |
| 1789 | gs = generate_greenscreen_chart() | |
| 1790 | cases = [ | |
| 1791 | (0, "uk_bg_only_pm1"), | |
| 1792 | (1, "uk_bg_only_pm0_over_red"), | |
| 1793 | (2, "uk_crazy_uk1_exact_over_red"), | |
| 1794 | (3, "uk_crazy_uk2_exact_over_red"), | |
| 1795 | (4, "uk_sep_0.2_spill_0.5"), | |
| 1796 | (5, "uk_alpha_only_uk1"), | |
| 1797 | (6, "uk_alpha_only_uk2"), | |
| 1798 | ] | |
| 1799 | nodes = [ | |
| 1800 | make_loader("GSLoader", gs, post_mult=1), | |
| 1801 | """\t\tBlackBG = Background { Inputs = { Width = Input { Value = 512, }, Height = Input { Value = 512, }, TopLeftAlpha = Input { Value = 1, }, }, }, | |
| 1802 | \t\tRedBG = Background { Inputs = { Width = Input { Value = 512, }, Height = Input { Value = 512, }, TopLeftRed = Input { Value = 0.9, }, TopLeftGreen = Input { Value = 0.1, }, TopLeftBlue = Input { Value = 0.1, }, TopLeftAlpha = Input { Value = 1, }, }, }, | |
| 1803 | \t\t-- f00: basic green key, PostMultiply=1 (default) | |
| 1804 | \t\tOp_0 = UltraKeyer { | |
| 1805 | \t\t\tInputs = { | |
| 1806 | \t\t\t\tBackgroundRed = Input { Value = 0.383215, }, | |
| 1807 | \t\t\t\tBackgroundGreen = Input { Value = 0.583642, }, | |
| 1808 | \t\t\t\tBackgroundBlue = Input { Value = 0.530770, }, | |
| 1809 | \t\t\t\tInput = Input { SourceOp = "GSLoader", Source = "Output", }, | |
| 1810 | \t\t\t}, | |
| 1811 | \t\t}, | |
| 1812 | \t\t-- f01: basic green key, PostMultiply=0 merged over RedBG | |
| 1813 | \t\tUK_1 = UltraKeyer { | |
| 1814 | \t\t\tInputs = { | |
| 1815 | \t\t\t\tBackgroundRed = Input { Value = 0.383215, }, | |
| 1816 | \t\t\t\tBackgroundGreen = Input { Value = 0.583642, }, | |
| 1817 | \t\t\t\tBackgroundBlue = Input { Value = 0.530770, }, | |
| 1818 | \t\t\t\tPostMultiplyImage = Input { Value = 0, }, | |
| 1819 | \t\t\t\tInput = Input { SourceOp = "GSLoader", Source = "Output", }, | |
| 1820 | \t\t\t}, | |
| 1821 | \t\t}, | |
| 1822 | \t\tOp_1 = Merge { Inputs = { Background = Input { SourceOp = "RedBG", Source = "Output", }, Foreground = Input { SourceOp = "UK_1", Source = "Output", }, }, }, | |
| 1823 | \t\t-- f02: exact UltraKeyer1 from 30_ground_is_crazy001 merged over RedBG | |
| 1824 | \t\tUK_2 = UltraKeyer { | |
| 1825 | \t\t\tInputs = { | |
| 1826 | \t\t\t\tBackgroundRed = Input { Value = 0.383215069770813, }, | |
| 1827 | \t\t\t\tBackgroundGreen = Input { Value = 0.583642303943634, }, | |
| 1828 | \t\t\t\tBackgroundBlue = Input { Value = 0.530769824981689, }, | |
| 1829 | \t\t\t\tRedLow = Input { Value = 0.400122076272964, }, | |
| 1830 | \t\t\t\tRedHigh = Input { Value = 0.424994289875031, }, | |
| 1831 | \t\t\t\tGreenLow = Input { Value = 0.534645617008209, }, | |
| 1832 | \t\t\t\tGreenHigh = Input { Value = 0.552941203117371, }, | |
| 1833 | \t\t\t\tBlueLow = Input { Value = 0.496787965297699, }, | |
| 1834 | \t\t\t\tBlueHigh = Input { Value = 0.557503640651703, }, | |
| 1835 | \t\t\t\tLuminanceLow = Input { Value = 0.338475614786148, }, | |
| 1836 | \t\t\t\tLuminanceHigh = Input { Value = 0.566201269626617, }, | |
| 1837 | \t\t\t\tPostMultiplyImage = Input { Value = 0, }, | |
| 1838 | \t\t\t\tInput = Input { SourceOp = "GSLoader", Source = "Output", }, | |
| 1839 | \t\t\t}, | |
| 1840 | \t\t}, | |
| 1841 | \t\tOp_2 = Merge { Inputs = { Background = Input { SourceOp = "RedBG", Source = "Output", }, Foreground = Input { SourceOp = "UK_2", Source = "Output", }, }, }, | |
| 1842 | \t\t-- f03: exact UltraKeyer2 from 30_ground_is_crazy001 merged over RedBG | |
| 1843 | \t\tUK_3 = UltraKeyer { | |
| 1844 | \t\t\tInputs = { | |
| 1845 | \t\t\t\tBackgroundRed = Input { Value = 0.162176, }, | |
| 1846 | \t\t\t\tBackgroundGreen = Input { Value = 0.724, }, | |
| 1847 | \t\t\t\tBackgroundBlue = Input { Value = 0.225100288, }, | |
| 1848 | \t\t\t\tRedLow = Input { Value = 0.414969086647034, }, | |
| 1849 | \t\t\t\tRedHigh = Input { Value = 0.419638365507126, }, | |
| 1850 | \t\t\t\tGreenLow = Input { Value = 0.546013593673706, }, | |
| 1851 | \t\t\t\tGreenHigh = Input { Value = 0.547783613204956, }, | |
| 1852 | \t\t\t\tBlueLow = Input { Value = 0.515922784805298, }, | |
| 1853 | \t\t\t\tBlueHigh = Input { Value = 0.519722282886505, }, | |
| 1854 | \t\t\t\tLuminanceLow = Input { Value = 0.439078360795975, }, | |
| 1855 | \t\t\t\tLuminanceHigh = Input { Value = 0.440360099077225, }, | |
| 1856 | \t\t\t\tFringeGamma = Input { Value = 0.861, }, | |
| 1857 | \t\t\t\tFringeShape = Input { Value = 0.906, }, | |
| 1858 | \t\t\t\tMatteBlur = Input { Value = 0.24, }, | |
| 1859 | \t\t\t\tLowMatteThreshold = Input { Value = 0.706, }, | |
| 1860 | \t\t\t\tHigh = Input { Value = 0.783, }, | |
| 1861 | \t\t\t\tPostMultiplyImage = Input { Value = 0, }, | |
| 1862 | \t\t\t\tInput = Input { SourceOp = "GSLoader", Source = "Output", }, | |
| 1863 | \t\t\t}, | |
| 1864 | \t\t}, | |
| 1865 | \t\tOp_3 = Merge { Inputs = { Background = Input { SourceOp = "RedBG", Source = "Output", }, Foreground = Input { SourceOp = "UK_3", Source = "Output", }, }, }, | |
| 1866 | \t\t-- f04: MatteSeparation + SpillSuppression | |
| 1867 | \t\tOp_4 = UltraKeyer { | |
| 1868 | \t\t\tInputs = { | |
| 1869 | \t\t\t\tBackgroundRed = Input { Value = 0.16, }, | |
| 1870 | \t\t\t\tBackgroundGreen = Input { Value = 0.72, }, | |
| 1871 | \t\t\t\tBackgroundBlue = Input { Value = 0.22, }, | |
| 1872 | \t\t\t\tMatteSeparation = Input { Value = 0.2, }, | |
| 1873 | \t\t\t\tSpillSuppression = Input { Value = 0.5, }, | |
| 1874 | \t\t\t\tInput = Input { SourceOp = "GSLoader", Source = "Output", }, | |
| 1875 | \t\t\t}, | |
| 1876 | \t\t}, | |
| 1877 | \t\t-- f05: Visualize alpha of UK_2 directly as grayscale RGB | |
| 1878 | \t\tOp_5 = ChannelBoolean { | |
| 1879 | \t\t\tInputs = { | |
| 1880 | \t\t\t\tToRed = Input { Value = 3, }, | |
| 1881 | \t\t\t\tToGreen = Input { Value = 3, }, | |
| 1882 | \t\t\t\tToBlue = Input { Value = 3, }, | |
| 1883 | \t\t\t\tToAlpha = Input { Value = 16, }, | |
| 1884 | \t\t\t\tBackground = Input { SourceOp = "UK_2", Source = "Output", }, | |
| 1885 | \t\t\t}, | |
| 1886 | \t\t}, | |
| 1887 | \t\t-- f06: Visualize alpha of UK_3 directly as grayscale RGB | |
| 1888 | \t\tOp_6 = ChannelBoolean { | |
| 1889 | \t\t\tInputs = { | |
| 1890 | \t\t\t\tToRed = Input { Value = 3, }, | |
| 1891 | \t\t\t\tToGreen = Input { Value = 3, }, | |
| 1892 | \t\t\t\tToBlue = Input { Value = 3, }, | |
| 1893 | \t\t\t\tToAlpha = Input { Value = 16, }, | |
| 1894 | \t\t\t\tBackground = Input { SourceOp = "UK_3", Source = "Output", }, | |
| 1895 | \t\t\t}, | |
| 1896 | \t\t},""", | |
| 1897 | ] | |
| 1898 | splines = [] | |
| 1899 | prev = "BlackBG" | |
| 1900 | for f, _label in cases: | |
| 1901 | bl = {c[0]: (1.0 if c[0] == f else 0.0) for c in cases} | |
| 1902 | sname = f"UK_{f}_Blend" | |
| 1903 | splines.append(step_spline(sname, bl)) | |
| 1904 | nodes.append(f"""\t\tSw_{f} = Merge {{ | |
| 1905 | \t\t\tInputs = {{ | |
| 1906 | \t\t\t\tBlend = Input {{ SourceOp = "{sname}", Source = "Value", }}, | |
| 1907 | \t\t\t\tBackground = Input {{ SourceOp = "{prev}", Source = "Output", }}, | |
| 1908 | \t\t\t\tForeground = Input {{ SourceOp = "Op_{f}", Source = "Output", }}, | |
| 1909 | \t\t\t}}, | |
| 1910 | \t\t}},""") | |
| 1911 | prev = f"Sw_{f}" | |
| 1912 | nodes.append(make_saver(prev, "ultrakey")) | |
| 1913 | comp_path = local_root() / "comps" / "probe_ultrakey.comp" | |
| 1914 | comp_path.write_text(make_comp("\n".join(nodes + splines), len(cases) - 1)) | |
| 1915 | return comp_path, "ultrakey", cases | |
| 1916 | ||
| 1917 | ||
| 1320 | 1918 | def main(): |
| 1321 | 1919 | ensure_dirs() |
| 1322 | 1920 | which = [a for a in sys.argv[1:] if not a.startswith("--")] or ["merge"] |
| ... | ... | @@ -1326,10 +1924,15 @@ def main(): |
| 1326 | 1924 | "cam3d": build_probe_cam3d, |
| 1327 | 1925 | "cam3d_fov": build_probe_cam3d_fov, |
| 1328 | 1926 | "mask": build_probe_mask, |
| 1927 | "mask_softedge": build_probe_mask_softedge, | |
| 1329 | 1928 | "xf": build_probe_transform, |
| 1330 | 1929 | "blur": build_probe_blur, |
| 1331 | 1930 | "color_ops": build_probe_color_ops, |
| 1332 | 1931 | "displace": build_probe_displace, |
| 1932 | "displace_wave": build_probe_displace_wave, | |
| 1933 | "vortex_cc": build_probe_vortex_cc, | |
| 1934 | "moon_3d": build_probe_moon_3d, | |
| 1935 | "ultrakey": build_probe_ultrakey, | |
| 1333 | 1936 | "glow": build_probe_glow, |
| 1334 | 1937 | "text": build_probe_text, |
| 1335 | 1938 | "noise_text": build_probe_noise_text, |
scripts/gen_compatibility.py+8-7| ... | ... | @@ -68,7 +68,7 @@ TOOL_METADATA: Sequence[ToolMeta] = ( |
| 68 | 68 | |
| 69 | 69 | # Color & Depth |
| 70 | 70 | ToolMeta("BrightnessContrast", "Color & Depth", "`color_ops`, `tier1_d`", "0.0%–0.1%", "Gain, Lift, Gamma, Contrast, Brightness, Saturation, channel toggles, `PreDividePostMultiply`, `ClipBlack`/`ClipWhite`."), |
| 71 | ToolMeta("ColorCorrector", "Color & Depth", "Suite comps", "0.1%–0.5%", "Master/Shadow/Midtone/Highlight wheel tint, Lift/Gamma/Gain/Brightness/Contrast/Saturation, `PreDividePostMultiply`."), | |
| 71 | ToolMeta("ColorCorrector", "Color & Depth", "`vortex_cc`, Suite comps", "0.0%–0.4%", "Master/Shadow/Midtone/Highlight wheels, exact Fusion 21.1 `TintMode` (`0`/`1`/`2`), Lift/Gamma/Gain/Brightness/Contrast/Saturation, `PreDividePostMultiply`."), | |
| 72 | 72 | ToolMeta("ColorGain", "Color & Depth", "`color_ops`, `noise_text`", "0.0%–0.1%", "Per-channel Gain, Lift, Gamma, Hue, Saturation, `PreDividePostMultiply`."), |
| 73 | 73 | ToolMeta("ColorCurves", "Color & Depth", "Suite comps", "0.1%–0.4%", "Per-channel RGBA `LUTBezier` spline lookup tables with `PreDividePostMultiply`."), |
| 74 | 74 | ToolMeta("HueCurves", "Color & Depth", "`tier1_a`", "0.1%–0.5%", "9 nested `LUTBezier` splines (Hue/Sat/Lum vs Hue, Suppression, etc.) baked to GPU LUT."), |
| ... | ... | @@ -80,7 +80,7 @@ TOOL_METADATA: Sequence[ToolMeta] = ( |
| 80 | 80 | |
| 81 | 81 | # Keying |
| 82 | 82 | ToolMeta("LumaKeyer", "Keying", "Suite comps", "0.1%–0.4%", "Luminance/channel threshold keying with low/high feathering and matte inversion."), |
| 83 | ToolMeta("UltraKeyer", "Keying", "`tier1_a`", "0.1%–0.6%", "Chroma keying with background color pick, matte threshold/gamma, spill suppression, and post-multiply."), | |
| 83 | ToolMeta("UltraKeyer", "Keying", "`ultrakey`, `tier1_a`", "0.0%–0.1%", "Exact Fusion 21.1 Ultimatte color-difference matte + background subtraction (`BackgroundRed/Green/Blue`, `LowMatteThreshold`/`High`, `MatteSeparation`, `SpillSuppression`, `PostMultiplyImage`)."), | |
| 84 | 84 | ToolMeta("Fuse.Cryptomatte", "Keying", "Unit tests", "0.0%", "Cryptomatte 1.2 multi-channel EXR matte extraction (manifest JSON + MurmurHash3-32 ID/coverage rank accumulation, wildcards, `MatteOnly`).", aliases=("Cryptomatte",)), |
| 85 | 85 | |
| 86 | 86 | # Blur, Sharpen & Glow |
| ... | ... | @@ -102,17 +102,18 @@ TOOL_METADATA: Sequence[ToolMeta] = ( |
| 102 | 102 | ToolMeta("CameraShake", "Transform, Warp & Framing", "`tier1_c`", "0.1%–0.5%", "Procedural X/Y/Rotation/Zoom camera shake with `OverallStrength`, `Speed`, `Edges`."), |
| 103 | 103 | ToolMeta("CornerPositioner", "Transform, Warp & Framing", "`tier1_b`", "0.1%–0.4%", "4-point projective homography warp (`TopLeft`/`TopRight`/`BottomLeft`/`BottomRight`)."), |
| 104 | 104 | ToolMeta("DVE", "Transform, Warp & Framing", "`tier1_b`", "0.1%–0.4%", "2.5D ZYX Euler rotation + perspective homography (`Center`, `ZMove`, `Pivot`, `AlphaMode`)."), |
| 105 | ToolMeta("Displace", "Transform, Warp & Framing", "`displace`", "0.0%–0.1%", "`XY` refraction (channels, offsets, refraction strength) and `Radial`/`Bump` (`LightPower`, `LightAngle`, `LightChannel` additive directional slope lighting)."), | |
| 105 | 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)."), | |
| 106 | ToolMeta("Vortex", "Transform, Warp & Framing", "`vortex_cc`", "0.0%–0.4%", "Isotropic radial swirl warp (`Center`, `Size`, `Angle`, `Power`, `Blend`, `EffectMask`)."), | |
| 106 | 107 | ToolMeta("Scale", "Transform, Warp & Framing", "Suite comps", "0.0%–0.2%", "Proportional/non-proportional image scaling with resampling filter."), |
| 107 | 108 | ToolMeta("BetterResize", "Transform, Warp & Framing", "Suite comps", "0.0%–0.2%", "Target pixel-dimension resize (`Width`, `Height`, `KeepAspect`)."), |
| 108 | 109 | ToolMeta("Crop", "Transform, Warp & Framing", "Suite comps", "0.0%–0.1%", "Region crop & canvas repositioning (`XOffset`, `YOffset`, `XSize`, `YSize`, `KeepCentered`)."), |
| 109 | 110 | ToolMeta("SetDomain", "Transform, Warp & Framing", "`tier1_d`", "0.0%–0.1%", "Domain-of-Definition (`Adjust` shrink/expand and `Set` modes)."), |
| 110 | 111 | |
| 111 | 112 | # Masks |
| 112 | ToolMeta("EllipseMask", "Masks", "`mask`", "0.0%–0.2%", "Center, Width, Height, Angle, `SoftEdge`, `BorderWidth`, `Solid`, `Invert`, `PaintMode` chaining."), | |
| 113 | ToolMeta("RectangleMask", "Masks", "`mask`", "0.0%–0.2%", "Center, Width, Height, `CornerRadius`, Angle, `SoftEdge`, `BorderWidth`, `Solid`, `Invert`, `PaintMode` chaining."), | |
| 114 | ToolMeta("PolylineMask", "Masks", "Suite comps", "0.1%–0.5%", "CPU `zeno` Bezier/linear polygon rasterizer with animated keyframed `Polyline` splines, `SoftEdge`, `Invert`, `PaintMode`."), | |
| 115 | ToolMeta("BitmapMask", "Masks", "Suite comps", "0.0%–0.2%", "Image-to-mask extraction (`Alpha`/`Luminance`/`Red`/`Green`/`Blue`), `Low`/`High` clip, `SoftEdge`, `Invert`."), | |
| 113 | ToolMeta("EllipseMask", "Masks", "`mask`, `mask_softedge`", "0.0%–0.2%", "Center, Width, Height, Angle, progressive-pyramid `SoftEdge`, `BorderWidth`, `Solid`, `Filter` (`Fast Gaussian`/`Box`), `ClippingMode`, `Invert`, `PaintMode` chaining."), | |
| 114 | ToolMeta("RectangleMask", "Masks", "`mask`, `mask_softedge`", "0.0%–0.2%", "Center, Width, Height, `CornerRadius`, Angle, progressive-pyramid `SoftEdge`, `BorderWidth`, `Solid`, `Filter`, `ClippingMode`, `Invert`, `PaintMode` chaining."), | |
| 115 | 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`."), | |
| 116 | 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`."), | |
| 116 | 117 | |
| 117 | 118 | # Particles |
| 118 | 119 | ToolMeta("pRender", "Particles", "Unit tests", "Visual*", "2D deterministic particle rasterizer (`ParticleStyleBitmap` rotated bilinear sprites, `ParticleStylePoint`/`Blob`, cached frame stepping). *Stochastic seed."), |