From 83dabbfbdab496dcee2d99bed46d4103e5bea4ae Mon Sep 17 00:00:00 2001 From: chasse20 Date: Wed, 18 Nov 2026 14:59:23 -0500 Subject: [PATCH] Preserve tap order and storage in three-texel blurs --- crates/nodes/src/atomic/blur.rs | 5 +++++ crates/nodes/src/atomic/box_filter.rs | 13 ++++++++++++ crates/nodes/src/atomic/directional_blur.rs | 3 +++ crates/nodes/tests/atomic_filter_parity.rs | 23 +++++++++++++++++++++ docs/parity-fixes.md | 15 ++++++++++++++ docs/sbs-root-nodes.md | 4 ++-- 6 files changed, 61 insertions(+), 2 deletions(-) diff --git a/crates/nodes/src/atomic/blur.rs b/crates/nodes/src/atomic/blur.rs index 9691914..a6c8c4d 100644 --- a/crates/nodes/src/atomic/blur.rs +++ b/crates/nodes/src/atomic/blur.rs @@ -18,5 +18,10 @@ fn blur(context: &CookContext) -> CookResult { let radius = context.f("intensity").max(0.0) * context.w.min(context.h) as f32 / BASE_RESOLUTION; let tile = context.tiling_axes(); + if radius > 0.5 && radius <= 1.5 { + let horizontal = box_filter::three_taps(&input, radius, [1, 0], tile); + let stored = crate::output_precision::apply(horizontal, context.format); + return Ok(vec![box_filter::three_taps(&stored, radius, [0, -1], tile)]); + } Ok(vec![box_filter::axis(&box_filter::axis(&input, radius, true, tile[0]), radius, false, tile[1])]) } diff --git a/crates/nodes/src/atomic/box_filter.rs b/crates/nodes/src/atomic/box_filter.rs index 07436ae..13338c2 100644 --- a/crates/nodes/src/atomic/box_filter.rs +++ b/crates/nodes/src/atomic/box_filter.rs @@ -1,6 +1,19 @@ use craft_texture::{Image, Limits, MAX_SIDE}; use rayon::prelude::*; +pub(super) fn three_taps(input: &Image, radius: f32, step: [i64; 2], tile: [bool; 2]) -> Image { + let center_weight = 0.5 / radius; + let edge_weight = (radius - 0.5) * center_weight; + Image::generate(input.width(), input.height(), input.kind(), |x, y| { + let (x, y) = (i64::from(x), i64::from(y)); + let first = input.get_axes(x - step[0], y - step[1], tile); + let center = input.get_axes(x, y, tile); + let last = input.get_axes(x + step[0], y + step[1], tile); + // The two passes visit samples in different directions. Cancellation exposes their order. + std::array::from_fn(|c| last[c].mul_add(edge_weight, center[c].mul_add(center_weight, first[c] * edge_weight))) + }) +} + pub(super) fn axis(input: &Image, radius: f32, horizontal: bool, tile: bool) -> Image { if !radius.is_finite() || radius <= 0.5 { return input.clone(); diff --git a/crates/nodes/src/atomic/directional_blur.rs b/crates/nodes/src/atomic/directional_blur.rs index 9a5a9d0..32dc59c 100644 --- a/crates/nodes/src/atomic/directional_blur.rs +++ b/crates/nodes/src/atomic/directional_blur.rs @@ -32,6 +32,9 @@ pub(super) fn blur(context: &CookContext, angle: f32) -> CookResult { let dy = -dy; let tile = context.tiling_axes(); if dy == 0.0 { + if radius <= 1.5 { + return Ok(vec![box_filter::three_taps(&input, radius, [-1, 0], tile)]); + } return Ok(vec![box_filter::axis(&input, radius, true, tile[0])]); } diff --git a/crates/nodes/tests/atomic_filter_parity.rs b/crates/nodes/tests/atomic_filter_parity.rs index 675ffb9..5220750 100644 --- a/crates/nodes/tests/atomic_filter_parity.rs +++ b/crates/nodes/tests/atomic_filter_parity.rs @@ -203,6 +203,29 @@ fn blur_uses_fractional_box_coverage() { } } +#[test] +fn three_texel_blurs_keep_tap_order_and_intermediate_storage() { + let field = Image::gray(64, 64, |x, y| { + let level = (97 * x + 43 * y + 7 * x * y) % 1024; + (3.0 * (f64::from(level) / 1023.0) - 1.25) as f32 + }); + let input = [Some(field)]; + let controls = [("intensity", Value::Float(5.0))]; + for (format, center, off_center) in [ + (OutputFormat::U8, 0x3e48c8c9, 0x3ee4e4e5), + (OutputFormat::U16, 0x3e4a78ca, 0x3ee558e5), + (OutputFormat::F16, 0x3e15c000, 0x3ee54000), + (OutputFormat::F32, 0x3e15e059, 0x3ee55957), + ] { + let image = cook_format("blur", &input, &controls, [64; 2], true, format); + let stored = materialcraft_nodes::output_precision::apply(image, format); + assert_eq!(stored.get_gray(32, 32, true).to_bits(), center); + assert_eq!(stored.get_gray(11, 13, true).to_bits(), off_center); + } + let directional = cook("directional_blur", &input, &controls, [64; 2], true); + assert_eq!(directional.get_gray(32, 32, true).to_bits(), 0xbdfdbf73); +} + #[test] fn blur_preserves_finite_hdr_constant() { let input = Image::filled(16, 16, Kind::Gray, [1.0e38; 4]); diff --git a/docs/parity-fixes.md b/docs/parity-fixes.md index 8bdc1e2..7e98253 100644 --- a/docs/parity-fixes.md +++ b/docs/parity-fixes.md @@ -253,6 +253,21 @@ Literal-only pixel graphs at 16², seed 23, give 512/768 exact pixels for each l The shared-lookup ridged root still matches 5,160/16,384 at changed roughness in F32, maximum 1.78813934e−7. Its one-octave .7 control still matches 1,847/4,096, maximum 2.38418579e−7. For positive normal x on the signed field, the reference's general power agrees with exp(y×ln(x)) on all 32,614 pixels. On .7 with exponent 1 it returns `3f333334`. Further work on general power and natural exponential is tracked with the [octave controls](#ridged-noise-octave-isolation). +### Three-texel blur kernels + +The bevel Gaussian blur subgraph now matches 138,496/154,880 pixels across 17 renders. All 106,496 U8, 8,192 U16 and 8,192 F16 pixels match. Of 32,000 F32 pixels, 15,616 match. The remaining case is the 128² procedural field at intensity 9, with 0/16,384 exact and maximum error .00221335888. The previous run matched 108,965/154,880 and differed by up to 393 U16 levels. The original defaults at 128² and 256², the changed intensity and all four 64² format checks now match. + +| Original three-texel controls | Renders | Exact RGBA pixels / compared | Maximum error | +|---|---:|---:|---:| +| Separable blur, tiled and untiled | 104 | 1,384,448/1,384,448 | 0 | +| Horizontal directional blur | 40 | 409,600/409,600 | 0 | + +When .5 < radius ≤ 1.5, the center weight is .5/radius and each edge weight is (radius−.5) times the center weight. The separable blur starts with the left tap, fuses the center and then the right tap, and stores the horizontal result in the destination format. The vertical pass starts below the pixel and ends above it. The zero-angle directional blur starts at the right tap. For the signed field below, the 64² separable output at (32,32), intensity 5, stores 50 in U8, 12,958 in U16, 3e15c000 in F16 expanded to F32, and 3e15e059 in F32. The previous U16 result was 9,592. The 64² F32 directional result at that pixel is bdfdbf73. + +For a square side N, fill R with an impulse at (N/2,N/2), G with the column x=N/2 and B with the row y=N/2. Let H=((97x+43y+7xy) mod 1024)/1023. The alpha input is H rounded to the closest stored level for U8 and U16, or 3H−1.25 stored at F16 or F32 precision. Use seed 347. Radius is intensity×N/256. At 32² use intensity 9.5. At 64² use 2.25, 3.25 and 5. At 128² use 1.125, 1.5, 2, 2.5 and 3. At 256² use 1. Use F32 output plus all four formats at 64²/intensity 5. Run the separable blur with both axes tiled and both untiled. The directional comparison uses the tiled 64² intensities 2.25 and 5, and the five 128² intensities. The [wider transform and mapping comparisons](#segment-mapping-and-normal-graph-rechecks) define the sizes and seeds for the nine bevel subgraph cases. Its single-channel input is ((19x+47y+5xy) mod 257)/256, with 2.5H−.75 for signed input and a single impulse at (7,13) for sparse input. Use default intensity at 16², 5 at 64², 9 at 128², 3.25 for sparse input and .25 for signed input. + +Wider kernels still differ. For an F32 impulse blurred at 128² and intensity 4, the five horizontal stripe samples centered on the impulse are .12451171875, .25048828125, .25, .25048828125 and .12451171875. Both outer texels differ from a uniformly weighted window with fractional ends. + ### Segment, mapping and normal graph rechecks | Root | Renders | Exact pixels / compared | Maximum error | diff --git a/docs/sbs-root-nodes.md b/docs/sbs-root-nodes.md index aaf04e7..3390056 100644 --- a/docs/sbs-root-nodes.md +++ b/docs/sbs-root-nodes.md @@ -35,7 +35,7 @@ A graph may accept input pins and still be a root under the dependency criterion Statuses: **Not checked**, **In progress**, **Parity** (exact pixels or typed values for the linked measured cases), or **Too hard** (reason recorded). Function calls do not count as regular graph dependencies. -The first pass covered all **546 roots**, with **166 Parity** and **380 Too hard**. The current inventory has **249 Parity**, **26 In progress** and **271 Too hard**. The November 17 and 18 comparisons include raw counts, output formats and remaining differences. [November 17 measurements](parity-fixes.md#2026-11-17-root-comparisons) · [November 18 measurements](parity-fixes.md#2026-11-18-root-comparisons) +The first pass covered all **546 roots**, with **166 Parity** and **380 Too hard**. The current inventory has **249 Parity**, **27 In progress** and **270 Too hard**. The November 17 and 18 comparisons include raw counts, output formats and remaining differences. [November 17 measurements](parity-fixes.md#2026-11-17-root-comparisons) · [November 18 measurements](parity-fixes.md#2026-11-18-root-comparisons) [Grayscale sampler measurements](parity-fixes.md#grayscale-sampling-of-color-inputs) · [Value sampling across 240 typed comparisons](parity-fixes.md#value-processor-texture-filtering) @@ -77,7 +77,7 @@ The first pass covered all **546 roots**, with **166 Parity** and **380 Too hard | [auto_crop.sbs/min_max](../assets/sbs/auto_crop.sbs) | 1 | Yes | [Parity: 3 cases](parity-fixes.md#verified-cases) | | [auto_levels.sbs/auto_levels](../assets/sbs/auto_levels.sbs) | 1 | No | [Parity: 3 cases](parity-fixes.md#verified-cases) | | [auto_levels.sbs/min_max](../assets/sbs/auto_levels.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [bevel_smooth.sbs/blur_gaussian_grayscale](../assets/sbs/bevel_smooth.sbs) | 1 | Yes | [Too hard: nonzero blur](parity-fixes.md#remaining-differences) | +| [bevel_smooth.sbs/blur_gaussian_grayscale](../assets/sbs/bevel_smooth.sbs) | 1 | Yes | [In progress · 138,496/154,880 pixels, wide F32 kernel open](parity-fixes.md#three-texel-blur-kernels) | | [bevel_smooth.sbs/debug/bevel_smooth_debug_position](../assets/sbs/bevel_smooth.sbs) | 1 | Yes | [In progress · 280,307/285,952 exact pixels](parity-fixes.md#segment-mapping-and-normal-graph-rechecks) | | [bevel_smooth.sbs/jump_flood_segment_iteration](../assets/sbs/bevel_smooth.sbs) | 1 | Yes | [Parity · 171,264 exact pixels in 18 renders](parity-fixes.md#segment-mapping-and-normal-graph-rechecks) | | [blackbody.sbs/blackbody](../assets/sbs/blackbody.sbs) | 0 | No | [In progress · 34,048/42,496 pixels, F32 error](parity-fixes.md#surface-irradiance-and-uniform-power) |