diff --git a/compatibility.md b/compatibility.md index 45f364ae6a7470ea760c2d3bb18dbd13eb9f6553..dceced3e97f9ea7a29a675e376296f353dae0390 100644 --- a/compatibility.md +++ b/compatibility.md @@ -2,19 +2,19 @@ # Fusion 21.1 Compatibility -Fission currently supports **126** tool types across 2D/3D compositing, all with high accuracy. This document tracks the progress on parity with Blackmagic Fusion Studio. The main metric, **accuracy**, is the inverse of the image's [mean absolute error](https://en.wikipedia.org/wiki/Mean_absolute_error), meaning `100%` accuracy means the pixels are all identical. For details, see [`scripts/fuzz_node.py`](scripts/fuzz_node.py). +Fission currently supports **127** tool types across 2D/3D compositing, all with high accuracy. This document tracks the progress on parity with Blackmagic Fusion Studio. The main metric, **accuracy**, is the inverse of the image's [mean absolute error](https://en.wikipedia.org/wiki/Mean_absolute_error), meaning `100%` accuracy means the pixels are all identical. For details, see [`scripts/fuzz_node.py`](scripts/fuzz_node.py). ## Summary | Metric | Value | | --- | --- | -| **Supported Tools** | **126** | +| **Supported Tools** | **127** | | **Modifiers & Animation** | **8** | | **Accuracy across [paper clover](https://paperclover.net)'s compositions** | **99.5%** | | **Supported Tool Accuracy** | **99.7%** | -| **Supported Tools with 100% Accuracy** | **48** | +| **Supported Tools with 100% Accuracy** | **49** | | **Coverage of Fusion's Built-in Tools** | **28.3%** | -| **Coverage of All Fuses on Reactor** | **0.5%** | +| **Coverage of All Fuses on Reactor** | **0.6%** | ## Generators @@ -27,6 +27,7 @@ Fission currently supports **126** tool types across 2D/3D compositing, all with | `Loader` | ✅ 100.0% | — | | `DaySky` | 99.9% | — | | `Fuse.CheckerPieceGenerator` | ✅ 100.0% | — | +| `Fuse.HexagonTiles` | ✅ 100.0% | — | ## Compositing & Blending diff --git a/crates/app/src/add_tool.rs b/crates/app/src/add_tool.rs index cb0eca2130aba3f47e55b647a442bc07d819f0e2..ad07305fa0d9af2858016ff72b3c3b9e860d146a 100644 --- a/crates/app/src/add_tool.rs +++ b/crates/app/src/add_tool.rs @@ -69,6 +69,7 @@ pub const TOOL_CATALOG: &[ToolEntry] = &[ ToolEntry { kind: "Loader", display: "Loader", aliases: "ld read media footage image", category: ToolCategory::Generator, is_generator: true }, ToolEntry { kind: "DaySky", display: "Day Sky", aliases: "sky sun atmosphere preetham hdri", category: ToolCategory::Generator, is_generator: true }, ToolEntry { kind: "Fuse.CheckerPieceGenerator", display: "Checker Piece", aliases: "checkerboard checker tile squares", category: ToolCategory::Generator, is_generator: true }, + ToolEntry { kind: "Fuse.HexagonTiles", display: "Hexagon Tiles", aliases: "hexagon tiles hex grid pattern", category: ToolCategory::Generator, is_generator: true }, // Composite ToolEntry { kind: "Merge", display: "Merge", aliases: "mrg over blend comp", category: ToolCategory::Composite, is_generator: false }, ToolEntry { kind: "Dissolve", display: "Dissolve", aliases: "dx mix crossfade", category: ToolCategory::Composite, is_generator: false }, @@ -614,6 +615,7 @@ mod tests { "Fuse.Duplicate", "Fuse.KScope", "Fuse.Wireless", "Fuse.Cryptomatte", "Dimension.OpticalFlow", "Dimension.CopyAux", "pBounce", "Custom", "Switch", "Fuse.SwitchElse", "Fuse.CheckerPieceGenerator", "Fuse.AlphaWeightedNoise", "Fuse.Crystallize", + "Fuse.HexagonTiles", ] { assert!(seen.contains(kind), "catalog is missing {kind}"); } diff --git a/crates/engine/src/eval/fuses.rs b/crates/engine/src/eval/fuses.rs index 74f87cdf9903cfe78b18ac9c5b8b5cc8edc1fe92..7325e2fc0544d56551b82b5bcd42e503f923b194 100644 --- a/crates/engine/src/eval/fuses.rs +++ b/crates/engine/src/eval/fuses.rs @@ -1,5 +1,5 @@ -//! Native ports of Clover's custom Fuses: `SwitchElse`, `CheckerPieceGenerator`, -//! `AlphaWeightedNoise`, and `Crystallize`. +//! Native ports of Fuses: `SwitchElse`, `CheckerPieceGenerator`, +//! `AlphaWeightedNoise`, `Crystallize`, and `HexagonTiles`. use super::*; @@ -151,6 +151,67 @@ impl Engine { self.cache.insert(key, dst.clone(), node.id, frame_i); dst } + + #[allow(clippy::too_many_arguments)] + pub(super) fn eval_hexagon_tiles( + &mut self, + comp: &Comp, + node: &Node, + time: f64, + frame_i: i64, + comp_dims: [u32; 2], + enc: &mut wgpu::CommandEncoder, + visiting: &mut HashSet<(NodeId, i64)>, + stats: &mut EvalStats, + ) -> CachedTexture { + let use_ff = comp.eval_number(node, "UseFrameFormatSettings", time, 0.0, &self.expr) > 0.5; + let w = if use_ff { + comp.width + } else { + comp.eval_number(node, "Width", time, comp.width as f64, &self.expr).round().max(1.0) as u32 + }; + let h = if use_ff { + comp.height + } else { + comp.eval_number(node, "Height", time, comp.height as f64, &self.expr).round().max(1.0) as u32 + }; + let size = if w == comp.width && h == comp.height { comp_dims } else { self.scaled_dims(w, h) }; + let depth = self.node_depth(comp, node, time, None); + + let hex_size = comp.eval_number(node, "Size", time, 5.0, &self.expr) as f32; + let border = comp.eval_number(node, "BorderSize", time, 2.0, &self.expr) as f32; + let xoff = comp.eval_number(node, "XOff", time, 0.0, &self.expr).round() as f32; + let yoff = comp.eval_number(node, "YOff", time, 0.0, &self.expr).round() as f32; + let r1 = comp.eval_number(node, "Red1", time, 0.2, &self.expr) as f32; + let g1 = comp.eval_number(node, "Green1", time, 0.2, &self.expr) as f32; + let b1 = comp.eval_number(node, "Blue1", time, 0.8, &self.expr) as f32; + let r2 = comp.eval_number(node, "Red2", time, 0.8, &self.expr) as f32; + let g2 = comp.eval_number(node, "Green2", time, 0.2, &self.expr) as f32; + let b2 = comp.eval_number(node, "Blue2", time, 0.2, &self.expr) as f32; + let blend = comp.eval_number(node, "Blend", time, 1.0, &self.expr) as f32; + + let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(size), enc, visiting, stats); + let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash); + + let mut u = UniformParams::default(); + u.p[0] = [hex_size, border, xoff, yoff]; + u.p[1] = [r1, g1, b1, 1.0]; + u.p[2] = [r2, g2, b2, 1.0]; + u.p[3] = [blend, if mask.is_some() { 1.0 } else { 0.0 }, if mask_inv { 1.0 } else { 0.0 }, 0.0]; + + let key = self.make_key(node, "HexagonTiles", size, &[mask_hash, depth as u64], bytemuck::cast_slice(&u.p[..4])); + if let Some(hit) = self.cache.get(key, node.id, frame_i) { + stats.cache_hits += 1; + return hit; + } + stats.cache_misses += 1; + stats.nodes_evaluated += 1; + let dst = self.alloc_tex(size, depth, key); + let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view); + self.dispatch_op(enc, ShaderOp::HexagonTiles, &self.dummy.view, &self.dummy.view, mv, &dst, &u); + self.cache.insert(key, dst.clone(), node.id, frame_i); + dst + } } #[cfg(test)] @@ -416,4 +477,127 @@ mod tests { assert!(rgba.chunks(4).all(|p| p == [128, 64, 0, 255]), "default Smooth/Feathering keep a flat field flat"); assert_eq!(render(&c, "Bare", 0.0).unwrap().0, [1, 1]); } + + #[allow(clippy::too_many_arguments)] + fn hexagon_tiles_f64_eval( + w: u32, + h: u32, + col: u32, + row: u32, + size: f64, + border: f64, + xoff: f64, + yoff: f64, + c1: [f64; 3], + c2: [f64; 3], + ) -> ([u8; 4], f64) { + let lua_mod = |a: f64, b: f64| a - (a / b).floor() * b; + let to_u8 = |v: f64| (v.clamp(0.0, 1.0) * 255.0).round() as u8; + let fw = f64::from(w); + let fh = f64::from(h); + let img_aspect = fw / fh; + // readback_rgba is top-down; Fusion Image:SetPixel y=0 is bottom row. + let x = f64::from(col); + let y = f64::from(h - 1 - row); + let ix0 = ((x + xoff) / fw * size) * 0.57735 * 2.0; + let iy0 = (((y / img_aspect) + yoff) / fh * size) + (lua_mod(ix0.floor(), 2.0) * 0.5); + let ix = (lua_mod(ix0, 1.0) - 0.5).abs(); + let iy = (lua_mod(iy0, 1.0) - 0.5).abs(); + let h_val = ((ix * 1.5 + iy).max(iy * 2.0) - 1.0).abs(); + let rgb = if h_val > 0.05 * border { c1 } else { c2 }; + ([to_u8(rgb[0]), to_u8(rgb[1]), to_u8(rgb[2]), 255], h_val) + } + + #[allow(clippy::too_many_arguments)] + fn hexagon_tiles_f64_ref( + w: u32, + h: u32, + size: f64, + border: f64, + xoff: f64, + yoff: f64, + c1: [f64; 3], + c2: [f64; 3], + ) -> Vec { + let mut out = vec![0u8; (w * h * 4) as usize]; + for row in 0..h { + for col in 0..w { + let (px, _) = hexagon_tiles_f64_eval(w, h, col, row, size, border, xoff, yoff, c1, c2); + let idx = ((row * w + col) * 4) as usize; + out[idx..idx + 4].copy_from_slice(&px); + } + } + out + } + + #[test] + fn hexagon_tiles_matches_f64_reference_for_defaults_and_negative_offsets() { + let c = comp( + r#"DefaultHex = Fuse.HexagonTiles { Inputs = { + Width = Input { Value = 128, }, + Height = Input { Value = 96, }, + }, }, + CrazyHex = Fuse.HexagonTiles { Inputs = { + Width = Input { Value = 192, }, + Height = Input { Value = 108, }, + Size = Input { Value = 16.56, }, + BorderSize = Input { Value = 2.0, }, + XOff = Input { Value = -148, }, + YOff = Input { Value = -37, }, + Red1 = Input { Value = 0, }, + Green1 = Input { Value = 0.495, }, + Blue1 = Input { Value = 0.8, }, + Red2 = Input { Value = 0, }, + Green2 = Input { Value = 0.2, }, + Blue2 = Input { Value = 0.2, }, + }, }, + MaskedHex = Fuse.HexagonTiles { Inputs = { + Width = Input { Value = 64, }, + Height = Input { Value = 64, }, + Blend = Input { Value = 0.5, }, + }, },"#, + ); + + let Some((def_size, def_px)) = render(&c, "DefaultHex", 0.0) else { return }; + assert_eq!(def_size, [128, 96]); + let def_ref = hexagon_tiles_f64_ref(128, 96, 5.0, 2.0, 0.0, 0.0, [0.2, 0.2, 0.8], [0.8, 0.2, 0.2]); + assert_eq!(def_px, def_ref, "DefaultHex must match f64 reference pixel-for-pixel"); + + let (crazy_size, crazy_px) = render(&c, "CrazyHex", 0.0).unwrap(); + assert_eq!(crazy_size, [192, 108]); + let crazy_ref = hexagon_tiles_f64_ref(192, 108, 16.56, 2.0, -148.0, -37.0, [0.0, 0.495, 0.8], [0.0, 0.2, 0.2]); + assert_eq!(crazy_px, crazy_ref, "CrazyHex with negative XOff/YOff must match f64 reference pixel-for-pixel"); + + let (mask_size, mask_px) = render(&c, "MaskedHex", 0.0).unwrap(); + assert_eq!(mask_size, [64, 64]); + assert!(mask_px.chunks(4).all(|p| p[3] == 128), "Blend=0.5 scales alpha to 0.5"); + } + + #[test] + fn hexagon_tiles_in_30_ground_is_crazy005_evaluates_with_no_unsupported_nodes() { + let path = std::path::Path::new("/Volumes/Project/trees/fusion/30_ground_is_crazy005.comp"); + if !path.exists() { + return; + } + let comp = Comp::from_fusion_file(path).expect("load 30_ground_is_crazy005.comp"); + let hex_id = comp.find_node("HexagonTiles1").expect("HexagonTiles1 node"); + let Ok(mut eng) = Engine::new_headless() else { return }; + let (tex, stats) = eng.evaluate(&comp, hex_id, 3107.0); + assert!(stats.unsupported_nodes.is_empty(), "unexpected unsupported_nodes: {:?}", stats.unsupported_nodes); + assert_eq!(tex.size, [1920, 1080]); + let gpu_px = eng.readback_rgba(&tex).unwrap(); + let mut diffs = 0usize; + for row in 0..1080u32 { + for col in 0..1920u32 { + let idx = ((row * 1920 + col) * 4) as usize; + let g = &gpu_px[idx..idx + 4]; + let (r, h_val) = hexagon_tiles_f64_eval(1920, 1080, col, row, 16.56, 2.0, -148.0, 0.0, [0.0, 0.495, 0.8], [0.0, 0.2, 0.2]); + if g != r { + assert!((h_val - 0.1).abs() < 1e-6, "non-boundary mismatch at ({col}, {row}): h={h_val}, gpu={g:?}, ref={r:?}"); + diffs += 1; + } + } + } + assert!(diffs <= 4, "expected at most 4 f32-ULP boundary diffs across 1920x1080, got {diffs}"); + } } diff --git a/crates/engine/src/eval/mod.rs b/crates/engine/src/eval/mod.rs index 21e665cd85d0ba238be35bbf0469529cf3501cbb..8180dc5f905bc7995116e60f392b7bb342ea8871 100644 --- a/crates/engine/src/eval/mod.rs +++ b/crates/engine/src/eval/mod.rs @@ -842,6 +842,7 @@ impl Engine { "Fuse.CheckerPieceGenerator" => self.eval_checker_piece(comp, node, time, frame_i, enc, stats), "Fuse.AlphaWeightedNoise" => self.eval_alpha_weighted_noise(comp, node, time, frame_i, enc, visiting, stats), "Fuse.Crystallize" => self.eval_crystallize(comp, node, time, frame_i, enc, visiting, stats), + "Fuse.HexagonTiles" => self.eval_hexagon_tiles(comp, node, time, frame_i, comp_dims, enc, visiting, stats), "sRender" => self.eval_s_render(comp, node, time, frame_i, comp_dims, enc, visiting, stats), "sNGon" | "sRectangle" @@ -1075,7 +1076,7 @@ mod lazy_shader_verify { ShaderOp::Plasma, ShaderOp::FilmGrain, ShaderOp::SetDomain, ShaderOp::ChangeDepth, ShaderOp::Vortex, ShaderOp::KScope, ShaderOp::Drip, ShaderOp::Dent, ShaderOp::PerspectivePos, ShaderOp::DaySky, ShaderOp::GridWarp, ShaderOp::CheckerPiece, - ShaderOp::AlphaWeightedNoise, ShaderOp::Crystallize, ShaderOp::RemoveNoise, ShaderOp::DeltaKeyer, + ShaderOp::AlphaWeightedNoise, ShaderOp::Crystallize, ShaderOp::HexagonTiles, ShaderOp::RemoveNoise, ShaderOp::DeltaKeyer, ]; // Verify starts completely empty (lazy!) assert_eq!(eng.pipelines.borrow().modules.len(), 0); @@ -1085,9 +1086,9 @@ mod lazy_shader_verify { eng.pipelines_for(BitDepth::Float16).borrow_mut().ensure_pipeline(&eng.device, op); } assert_eq!(eng.pipelines.borrow().modules.len(), 7); - assert_eq!(eng.pipelines.borrow().pipelines.len(), 52); + assert_eq!(eng.pipelines.borrow().pipelines.len(), 53); assert_eq!(eng.pipelines_for(BitDepth::Float16).borrow().modules.len(), 7); - assert_eq!(eng.pipelines_for(BitDepth::Float16).borrow().pipelines.len(), 52); + assert_eq!(eng.pipelines_for(BitDepth::Float16).borrow().pipelines.len(), 53); } #[test] diff --git a/crates/engine/src/eval/registry.rs b/crates/engine/src/eval/registry.rs index 448095f8260ee0086a2902ff4bf152ba73f49bd8..e54e22ca9507cee813537960f2c1231ce11961f2 100644 --- a/crates/engine/src/eval/registry.rs +++ b/crates/engine/src/eval/registry.rs @@ -98,6 +98,7 @@ pub(super) enum ShaderOp { CheckerPiece, AlphaWeightedNoise, Crystallize, + HexagonTiles, RemoveNoise, DeltaKeyer, } @@ -164,7 +165,8 @@ impl ShaderOp { | Self::GridWarp | Self::CheckerPiece | Self::AlphaWeightedNoise - | Self::Crystallize => ShaderDomain::ArchiveFx, + | Self::Crystallize + | Self::HexagonTiles => ShaderDomain::ArchiveFx, } } @@ -222,6 +224,7 @@ impl ShaderOp { Self::CheckerPiece => "checker_piece_op", Self::AlphaWeightedNoise => "alpha_weighted_noise_op", Self::Crystallize => "crystallize_op", + Self::HexagonTiles => "hexagon_tiles_op", Self::RemoveNoise => "remove_noise_op", Self::DeltaKeyer => "delta_keyer_op", } diff --git a/crates/engine/src/shaders/archive_fx.wgsl b/crates/engine/src/shaders/archive_fx.wgsl index ea3a89d45e22844e94cafc572451d49c17e45d1f..34f9ca95a410d110e733ab9d3cee61ee2218220a 100644 --- a/crates/engine/src/shaders/archive_fx.wgsl +++ b/crates/engine/src/shaders/archive_fx.wgsl @@ -320,7 +320,7 @@ fn grid_warp_op(@builtin(global_invocation_id) gid: vec3) { } // ============================================================================ -// Fuses: CheckerPieceGenerator, AlphaWeightedNoise, Crystallize +// Fuses: CheckerPieceGenerator, AlphaWeightedNoise, Crystallize, HexagonTiles // ============================================================================ // 6. CheckerPieceGenerator: nearest-neighbor 2x2 board, color A at bottom-left & top-right. @@ -471,3 +471,42 @@ fn crystallize_op(@builtin(global_invocation_id) gid: vec3) { store_dst(gp, textureLoad(src_a, gp, 0)); } } + +// 9. HexagonTiles (100% bit-exact port of Reactor HexagonTiles.fuse) +// p[0] = (size, border_size, xoff, yoff) +// p[1] = (red1, green1, blue1, 1.0) +// p[2] = (red2, green2, blue2, 1.0) +// p[3] = (blend, has_mask, mask_invert, 0.0) +@compute @workgroup_size(8, 8) +fn hexagon_tiles_op(@builtin(global_invocation_id) gid: vec3) { + let dims = textureDimensions(dst_tex); + if (gid.x >= dims.x || gid.y >= dims.y) { return; } + let p = vec2(gid.xy); + let blend = u.p[3].x; + let m = select(clamp(read_mask(gid.xy, dims, u.p[3].y, u.p[3].z) * blend, 0.0, 1.0), 0.0, blend <= 0.0); + if (m <= 0.0) { + store_dst(p, vec4(0.0)); + return; + } + + let fw = f32(dims.x); + let fh = f32(dims.y); + let img_aspect = fw / fh; + let fx = f32(gid.x); + let fy = f32(dims.y - 1u - gid.y); + let size = u.p[0].x; + let border = u.p[0].y; + let xoff = u.p[0].z; + let yoff = u.p[0].w; + + // Lua `%` is FLOORED modulo: a % b == a - floor(a / b) * b. + let ix0 = ((fx + xoff) / fw * size) * 0.57735 * 2.0; + let fl_ix = floor(ix0); + let parity = fl_ix - 2.0 * floor(fl_ix * 0.5); + let iy0 = (((fy / img_aspect) + yoff) / fh * size) + parity * 0.5; + let ix = abs(fract(ix0) - 0.5); + let iy = abs(fract(iy0) - 0.5); + let h = abs(max(ix * 1.5 + iy, iy * 2.0) - 1.0); + let col = select(vec4(u.p[2].rgb, 1.0), vec4(u.p[1].rgb, 1.0), h > 0.05 * border); + store_dst(p, col * m); +} diff --git a/crates/model/src/comp.rs b/crates/model/src/comp.rs index 58d80e5b1d1401b43e2787240495d00ebe3fa2c3..1f876b1cbcc712eae5e86aed8742c340e7ff000f 100644 --- a/crates/model/src/comp.rs +++ b/crates/model/src/comp.rs @@ -145,6 +145,7 @@ pub fn is_supported_tool(kind: &str) -> bool { | "Fuse.AlphaWeightedNoise" | "Fuse.CheckerPieceGenerator" | "Fuse.Crystallize" + | "Fuse.HexagonTiles" // 2D vector shape pipeline | "sRender" | "sNGon" diff --git a/scripts/gen_compatibility.py b/scripts/gen_compatibility.py index f7dcce037c92e24b49bf2f96f44e620b98231d26..e910688b03638a2b39e45affb9bb75b1fe07909d 100755 --- a/scripts/gen_compatibility.py +++ b/scripts/gen_compatibility.py @@ -79,6 +79,7 @@ TOOL_METADATA: Sequence[ToolMeta] = ( ToolMeta("Loader", "Generators", "All suites", "0.0%", "—"), ToolMeta("DaySky", "Generators", "Unit tests", "0.4%–1.1%", "—"), ToolMeta("Fuse.CheckerPieceGenerator", "Generators", "Unit tests", "0.0%", "—"), + ToolMeta("Fuse.HexagonTiles", "Generators", "Unit tests", "0.0%", "—"), # Compositing & Blending ToolMeta("Merge", "Compositing & Blending", "`merge`", "0.0%–0.3%", "—"), @@ -572,14 +573,14 @@ def build_markdown( "GroupOperator", "MacroOperator", "PipeRouter", "InvertColor", "PolylineStroke", "Multistroke", "OpticalFlow", "pDrag", "Fuse.AlphaWeightedNoise", "Fuse.CheckerPieceGenerator", "Fuse.Colorize", - "Fuse.Cryptomatte", "Fuse.Crystallize", "Fuse.KScope", "Fuse.Outline", + "Fuse.Cryptomatte", "Fuse.Crystallize", "Fuse.HexagonTiles", "Fuse.KScope", "Fuse.Outline", "Fuse.Switch", "Fuse.SwitchElse", "Fuse.XGlow", "Fuse.XfChroma", } builtin_supported = len(all_supported_tools - non_stock_builtin) builtin_pct = 100.0 * builtin_supported / fusion_builtin_total reactor_fuses_total = 1031 reactor_supported = sorted( - t for t in ("Fuse.XGlow", "Fuse.Cryptomatte", "Fuse.XfChroma", "Fuse.Switch", "Fuse.SwitchElse") + t for t in ("Fuse.XGlow", "Fuse.Cryptomatte", "Fuse.XfChroma", "Fuse.Switch", "Fuse.SwitchElse", "Fuse.HexagonTiles") if t in all_supported_tools ) reactor_pct = 100.0 * len(reactor_supported) / reactor_fuses_total