From e2c0703df94bbca3a10dfb408a45f9d94cdd1baf Mon Sep 17 00:00:00 2001 From: chasse20 Date: Sat, 21 Nov 2026 18:03:55 -0500 Subject: [PATCH] Match the forward and inverse sampling coordinates in long directional blurs --- crates/nodes/src/atomic/box_filter.rs | 18 ++++--- crates/nodes/src/atomic/directional_blur.rs | 5 +- crates/nodes/tests/atomic_filter_parity.rs | 22 +++++++++ docs/parity-fixes.md | 54 +++++++++++++++++++++ docs/sbs-root-nodes.md | 6 +-- 5 files changed, 94 insertions(+), 11 deletions(-) diff --git a/crates/nodes/src/atomic/box_filter.rs b/crates/nodes/src/atomic/box_filter.rs index 133e0209..ba052984 100644 --- a/crates/nodes/src/atomic/box_filter.rs +++ b/crates/nodes/src/atomic/box_filter.rs @@ -20,18 +20,24 @@ pub(super) fn sheared(input: &Image, reach: f32, horizontal: bool, slope: f32, s let intermediate = if destination == OutputFormat::Inherit { OutputFormat::U16 } else { destination }; // The slope is in texels. A full period along the line spans this many transverse UV periods. let uv_slope = slope * (length as f32 / across as f32); - let shear = |image: &Image, slope: f32, format| { - // Add the two transform columns before translating back to the texture center. - let shifted = |along: f32, across: f32| (across + slope * along) - slope * 0.5; + let shear = |image: &Image, forward: bool, format| { + let slope = if forward { uv_slope } else { -uv_slope }; + let translation = slope * 0.5; Image::generate_uv(width, height, image.kind(), |u, v| { - let uv = if horizontal { [u, shifted(u, v)] } else { [shifted(v, u), v] }; + // The horizontal forward pass measures along the row from its far edge. + // Keep the transform columns in sample order before adding the translation. + let uv = match (horizontal, forward) { + (true, true) => [u, (-slope).mul_add(1.0 - u, v) + translation], + (true, false) => [u, (slope * u + v) - translation], + (false, _) => [slope.mul_add(v, u) - translation, v], + }; crate::texture_sampler::sample(image, uv, [true; 2], format, None) }) }; - let displaced = crate::output_precision::apply(shear(input, uv_slope, source), intermediate); + let displaced = crate::output_precision::apply(shear(input, true, source), intermediate); let filtered = mip_window::filter(&displaced, reach, horizontal, true, intermediate, intermediate, mip_window::Edges::Sheared(uv_slope)); let filtered = crate::output_precision::apply(filtered, intermediate); - Some(shear(&filtered, -uv_slope, intermediate)) + Some(shear(&filtered, false, intermediate)) } pub(super) fn short_line(input: &Image, reach: f32, step: [f32; 2], tile: [bool; 2], source_format: OutputFormat) -> Image { diff --git a/crates/nodes/src/atomic/directional_blur.rs b/crates/nodes/src/atomic/directional_blur.rs index 175f686f..5e50c20e 100644 --- a/crates/nodes/src/atomic/directional_blur.rs +++ b/crates/nodes/src/atomic/directional_blur.rs @@ -95,9 +95,10 @@ pub(super) fn blur(context: &CookContext, angle: f32) -> CookResult { // An authored eighth turn has an exact unit slope even after radian conversion. // On a rectangle the dominant UV direction can have the smaller texel // component. The window spans the projection along the chosen texel axis. - let (across, along, reach) = if horizontal { (sample_y, sample_x, reach_x) } else { (sample_x, sample_y, reach_y) }; + // Each projected extent rounds before the divide that sets the shear slope. + let (across, along) = if horizontal { (reach_y, reach_x) } else { (reach_x, reach_y) }; let slope = if !stretched && (angle * 8.0).fract() == 0.0 { (line_y * line_x).signum() as f32 } else { across / along }; - if let Some(image) = box_filter::sheared(&input, reach.abs(), horizontal, slope, source_format, context.format) { + if let Some(image) = box_filter::sheared(&input, along.abs(), horizontal, slope, source_format, context.format) { return Ok(vec![image]); } } diff --git a/crates/nodes/tests/atomic_filter_parity.rs b/crates/nodes/tests/atomic_filter_parity.rs index e3e5e0e1..b2b0fef3 100644 --- a/crates/nodes/tests/atomic_filter_parity.rs +++ b/crates/nodes/tests/atomic_filter_parity.rs @@ -658,6 +658,28 @@ fn long_oblique_blur_centers_the_shear_at_texel_precision() { assert_eq!([253, 254, 255].map(|y| result.get_gray(10, y, false).to_bits()), [0x3d0c_9a80, 0x3ce7_57e2, 0x3bbc_f1c9]); } +#[test] +fn long_oblique_blur_samples_the_projected_shear_in_column_order() { + for (size, horizontal, angle, strength, point, expected) in [ + ([128, 64], false, 213.0 / 2048.0, 19.5, [19, 30], [0x3b1a_ea75, 0x3d69_d155, 0x3dca_52bf, 0x3f80_0001]), + ([64, 128], true, -273.0 / 2048.0, 19.5, [29, 44], [0x3d6f_1384, 0x3d82_34f0, 0x3c5b_e7a1, 0x3f80_0000]), + ([64, 128], true, -273.0 / 2048.0, 26.875, [49, 40], [0x3c9f_9ffc, 0x3d67_9d73, 0x3cff_b80f, 0x3f7f_fffe]), + ([128, 128], true, 199.0 / 2048.0, 13.4375, [98, 102], [0x3cee_97a4, 0x3d69_7441, 0, 0x3f80_0000]), + ] { + let field = Image::generate(size[0], size[1], Kind::Color, |x, y| { + let (along, across) = if horizontal { (x, y) } else { (y, x) }; + let mut rgba = [0.0, 0.0, 0.0, 1.0]; + if along % 16 == 0 && across % 4 < 3 { + rgba[(across % 4) as usize] = 1.0; + } + rgba + }); + let params = [("intensity", Value::Float(strength)), ("angle", Value::Float(angle))]; + let image = cook("directional_blur", &[Some(field)], ¶ms, size, true); + assert_eq!(image.get(point[0], point[1], false).map(f32::to_bits), expected, "{size:?} at {strength}"); + } +} + fn signed_modular_field(width: u32, height: u32) -> Image { Image::generate(width, height, Kind::Color, |x, y| { std::array::from_fn(|c| { diff --git a/docs/parity-fixes.md b/docs/parity-fixes.md index c21adfc0..273dcf47 100644 --- a/docs/parity-fixes.md +++ b/docs/parity-fixes.md @@ -1879,6 +1879,60 @@ Across the 93 settings, 45 formerly rejected renders now match. All 18,352 compa The full saved package retains its nested graph and input connections. Both applications reproduced their respective originals in ten reopened settings (2,161/2,161 cross-application pixels, maximum 0). Three saved parents add 12 reopened settings (1,664/1,664 pixels, maximum 0). The previously captured finite and skipped loop controls retain 28/28 exact typed values and 10,240/10,240 exact pixel values. Three regressions cover a settled counter, a constant body result with advancing random draws and alternating signed zero. All 421 node and evaluator release tests passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. +### Sampling both passes of a long oblique blur + +The [periodic RGB impulse](#isolated-sample-coordinates-in-the-two-hq-blur-roots) isolates the transverse sample positions on each pass. Keep the angle and dimensions fixed and change only the radius. For a 128 × 256 image at .337890625 turns, moving from radius 6.71875 to 7.375 changes the forward interpolation weight by one unit of 1/256 texel at 344 of 12,800 common sampled positions. The inverse changes at 264 of 11,776. The slope uses the ratio of the two already rounded projected extents. For the two horizontal passes, let u and v be texel-center coordinates and s the signed UV slope on that pass. The forward pass forms the fused product (−s)(1−u) + v, then adds s/2. The inverse pass first rounds s × u, then adds v and subtracts s/2. Both vertical passes form the fused s × v + u before subtracting s/2. These orderings agree with all 820,992 recovered interpolation weights in 29 angle, size and radius combinations. + +For the independently chosen radius series use (width, height, turns) of (128,64,213/2048), (64,128,−273/2048), (128,128,199/2048) and (128,128,−253/2048). Test radii 4.875, 6.71875 and 7.375. In each combination light columns with residue h modulo 16 across the filtering axis, using pure red, green, blue and black in repeating transverse rows. Transpose the field when the filter runs vertically. Include residues 0 through 15 and repeat residue 7 at zero intensity. Use seed 128681 + 73j + 19r + h at orientation j and radius index r. Set intensity to 256 times radius divided by the shorter side. + +| Isolated F32 inputs | Renders | Earlier exact / compared · maximum | Current exact / compared · maximum | +|---|---:|---:|---:| +| Original impulses | 51 | 2,360,903/2,367,488 · 0.00061633531 | 2,367,488/2,367,488 · 0 | +| Independent impulses | 170 | 8,339,478/8,355,840 · 0.000513050705 | 8,355,840/8,355,840 · 0 | +| Two previous radius sweeps | 68 | 3,333,242/3,342,336 · 0.00069058314 | 3,342,336/3,342,336 · 0 | +| Four new orientations and three radii | 204 | 2,480,832/2,506,752 · 0.00115896761 | 2,506,752/2,506,752 · 0 | + +All 16,572,416 impulse pixels match. Saving the four new graphs and reopening ten settings in each gives 491,520/491,520 cross-application pixels, maximum zero. Each application reproduced all its original buffers. + +For a separate dense input, number test geometries j and stored channels c from zero. Use F32 channels ((31x+53y+7xy+43c+5cx+17⌊y/3⌋+29j) mod 509)/508. Use (width,height,angle numerator,radius) of (128,64,81,4.34375), (64,128,−433,7.15625), (256,64,637,5.53125), (64,256,207,6.40625), (128,128,−843,4.90625) and (128,64,−561,7.21875). Divide each numerator by 2048. Render zero radius at F32, the tabulated radius at all four formats, then radius + .9375 at F32. Use seed 131101 + 53j + 7h with h = 0, 1 or 2 in that order. + +| Dense procedural field | Renders | Exact / compared | Maximum error | +|---|---:|---:|---:| +| RGBA8 | 6 | 73,728/73,728 | 0 | +| RGBA16 | 6 | 73,656/73,728 | 1 | +| RGBA16F | 6 | 73,727/73,728 | 0.00048828125 | +| RGBA32F | 18 | 199,687/221,184 | 1.78813934e-07 | + +These dense inputs expose remaining intermediate arithmetic differences in the individual filter. The three independently reopened dense-input graphs reproduced their original results in both applications. They had 226,589/245,760 cross-application matches in 18 settings. + +For the two whole HQ roots, repeat the [previous 78 settings](#directional-blur-weights-across-110-angles-and-two-projection-axes). The earlier color and grayscale captures differed at 646 and 130 pixels respectively. Both now match 3,661,056/3,661,056 at maximum zero. Then use the same dense field formula above with all four channels for the color root and channel zero for grayscale. Quantize integer sources to the nearest unsigned level. Test these eight geometries at each output format with seed 131337 + 97j. + +| j | Output size | Source size and format | Intensity | Quality | +|---:|---|---|---:|---:| +| 0 | 32 × 64 | 32 × 64, U8 | default | default | +| 1 | 128 × 64 | 128 × 64, F32 | 17.9375 | 1 | +| 2 | 64 × 128 | 64 × 128, U16 | 22.6875 | 1 | +| 3 | 256 × 128 | 128 × 64, F16 | 12.65625 | 0 | +| 4 | 128 × 256 | 128 × 256, F32 | 18.15625 | 1 | +| 5 | 256 × 256 | 128 × 256, U16 | 9.96875 | 1 | +| 6 | 512 × 128 | 512 × 128, U8 | 15.3125 | 1 | +| 7 | 128 × 512 | 128 × 512, F32 | 14.53125 | 1 | + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Color HQ blur (55) | 110 | 987,135/987,136 · 1 | 1,449,983/1,449,984 · 257 | 872,447/872,448 · 0.00390625 | 1,473,791/1,473,792 · 0.00392156839 | +| Grayscale HQ blur (56) | 110 | 987,136/987,136 · 0 | 1,449,984/1,449,984 · 0 | 872,448/872,448 · 0 | 1,473,792/1,473,792 · 0 | + +For root 55, the new 32 settings improved from 1,120,884 to 1,122,300 exact pixels out of 1,122,304. Reopening the two earlier packages and the new package gives 3,868,671/3,868,672 across 71 saved settings, with maximum 0.00392156839. Both applications reproduced every pixel of their own originals. + +For root 56, the new 32 settings improved from 1,122,084 to 1,122,304 exact pixels out of 1,122,304. Reopening the two earlier packages and the new package gives 3,868,672/3,868,672 across 71 saved settings, with maximum 0. Both applications reproduced every pixel of their own originals. + +In the color root at j = 5, the source bridge and the first filter in the second branch agree on 65,536/65,536 pixels. The next directional filter uses .4375 turns and intensity 6.579375267028809. In U8 storage, alpha at (161,11) is 116 in the reference and 117 in MaterialCraft. Subsequent filters carry the difference to (161,19), where the final alpha is 157/255 and 158/255 respectively. This one output pixel accounts for all four format differences. All thirteen observed grayscale stages at j = 5 match. The grayscale root reaches parity for the listed settings. The color root remains in progress. + +A separate one-node graph reproduces the original reference filter at all 65,536 pixels when supplied the matching upstream U8 render. Use the same 256² size, angle and intensity. Repeating its alpha in all four channels reproduces the same single-level difference in all four. Keeping only x = 148…174 and y = 0…23 and clearing everything outside this rectangle also preserves the difference. Across the nine reopened settings, 586,420/589,824 cross-application pixels matched. Both applications reproduced their original buffers. + +Thirteen other roots that use the directional filter retain 72,352,768/72,352,768 exact pixels across 662 measured settings. The other fluid root (272) still matches 1,041,220/1,041,664 across 53 settings, maximum six U16 levels. The release regression failed on the previous implementation. All 422 node and evaluator release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + ## 2026-11-20 root comparisons ### Hue, saturation, lightness and Replace Color diff --git a/docs/sbs-root-nodes.md b/docs/sbs-root-nodes.md index 275887d2..5fa23441 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 **444 Parity**, **102 In progress** and **0 Too hard**. The November 17–21 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) · [November 19 measurements](parity-fixes.md#2026-11-19-root-comparisons) · [November 20 measurements](parity-fixes.md#2026-11-20-root-comparisons) · [November 21 measurements](parity-fixes.md#2026-11-21-root-comparisons) +The first pass covered all **546 roots**, with **166 Parity** and **380 Too hard**. The current inventory has **445 Parity**, **101 In progress** and **0 Too hard**. The November 17–21 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) · [November 19 measurements](parity-fixes.md#2026-11-19-root-comparisons) · [November 20 measurements](parity-fixes.md#2026-11-20-root-comparisons) · [November 21 measurements](parity-fixes.md#2026-11-21-root-comparisons) [Pattern tiling axes and copy bounds across 215 renders](parity-fixes.md#tiling-axes-and-pattern-copy-bounds) · [Grayscale sampler measurements](parity-fixes.md#grayscale-sampling-of-color-inputs) · [Value sampling across 240 typed comparisons](parity-fixes.md#value-processor-texture-filtering) · [Five saved graphs reopened in the reference](parity-fixes.md#saved-filter-graphs-and-scalar-levels-controls) @@ -178,8 +178,8 @@ Creased matches 10,947,840/10,947,840 pixels across 100 distinct settings throug | [blend_switch.sbs/multi_switch_grayscale](../assets/sbs/blend_switch.sbs) | 20 | No | [Parity: 5 cases](parity-fixes.md#verified-cases) | | [blend_switch.sbs/switch](../assets/sbs/blend_switch.sbs) | 2 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [blend_switch.sbs/switch_grayscale](../assets/sbs/blend_switch.sbs) | 2 | No | [Parity: 6 cases](parity-fixes.md#verified-cases) | -| [blur_hq.sbs/blur_hq](../assets/sbs/blur_hq.sbs) | 1 | No | [In progress · 3,660,410/3,661,056 pixels across 78 distinct settings](parity-fixes.md#directional-blur-weights-across-110-angles-and-two-projection-axes) · [Earlier whole-root and sample comparisons](parity-fixes.md#direction-and-sample-coordinates-of-long-oblique-blurs) · [Three-tap and eighth-turn probes](parity-fixes.md#projected-weights-and-tap-order-in-short-directional-blurs) · [Independent oblique sampling controls](parity-fixes.md#isolated-sample-coordinates-in-the-two-hq-blur-roots) · [96-angle originals and reopened graphs](parity-fixes.md#independent-rectangular-directional-weights-at-96-angles) · [Tap order and impulse weights over 1,440 branch renders](parity-fixes.md#three-measured-taps-reproduce-the-rectangular-directional-blur-outputs) · [48 angle pairs with identical folded phase](parity-fixes.md#paired-angles-isolate-the-reduced-phase-of-rectangular-blur) · [A differing pair among 24 targeted angle comparisons](parity-fixes.md#equal-reduced-phases-with-distinct-rectangular-blur-coefficients) · [Signed rotations, large angles and reopened roots](parity-fixes.md#directional-blur-weights-at-signed-and-large-rotations) | -| [blur_hq.sbs/blur_hq_grayscale](../assets/sbs/blur_hq.sbs) | 1 | No | [In progress · 3,660,926/3,661,056 pixels across 78 distinct settings](parity-fixes.md#directional-blur-weights-across-110-angles-and-two-projection-axes) · [Earlier whole-root and sample comparisons](parity-fixes.md#direction-and-sample-coordinates-of-long-oblique-blurs) · [Three-tap and eighth-turn probes](parity-fixes.md#projected-weights-and-tap-order-in-short-directional-blurs) · [Independent oblique sampling controls](parity-fixes.md#isolated-sample-coordinates-in-the-two-hq-blur-roots) · [96-angle originals and reopened graphs](parity-fixes.md#independent-rectangular-directional-weights-at-96-angles) · [Tap order and impulse weights over 1,440 branch renders](parity-fixes.md#three-measured-taps-reproduce-the-rectangular-directional-blur-outputs) · [48 angle pairs with identical folded phase](parity-fixes.md#paired-angles-isolate-the-reduced-phase-of-rectangular-blur) · [A differing pair among 24 targeted angle comparisons](parity-fixes.md#equal-reduced-phases-with-distinct-rectangular-blur-coefficients) · [Signed rotations, large angles and reopened roots](parity-fixes.md#directional-blur-weights-at-signed-and-large-rotations) | +| [blur_hq.sbs/blur_hq](../assets/sbs/blur_hq.sbs) | 1 | No | [In progress · 4,783,356/4,783,360 pixels across 110 distinct settings](parity-fixes.md#sampling-both-passes-of-a-long-oblique-blur) · [Earlier 78-setting whole-root measurements](parity-fixes.md#directional-blur-weights-across-110-angles-and-two-projection-axes) · [Earlier whole-root and sample comparisons](parity-fixes.md#direction-and-sample-coordinates-of-long-oblique-blurs) · [Three-tap and eighth-turn probes](parity-fixes.md#projected-weights-and-tap-order-in-short-directional-blurs) · [Independent oblique sampling controls](parity-fixes.md#isolated-sample-coordinates-in-the-two-hq-blur-roots) · [96-angle originals and reopened graphs](parity-fixes.md#independent-rectangular-directional-weights-at-96-angles) · [Tap order and impulse weights over 1,440 branch renders](parity-fixes.md#three-measured-taps-reproduce-the-rectangular-directional-blur-outputs) · [48 angle pairs with identical folded phase](parity-fixes.md#paired-angles-isolate-the-reduced-phase-of-rectangular-blur) · [A differing pair among 24 targeted angle comparisons](parity-fixes.md#equal-reduced-phases-with-distinct-rectangular-blur-coefficients) · [Signed rotations, large angles and reopened roots](parity-fixes.md#directional-blur-weights-at-signed-and-large-rotations) | +| [blur_hq.sbs/blur_hq_grayscale](../assets/sbs/blur_hq.sbs) | 1 | No | [Parity · 4,783,360/4,783,360 pixels across 110 distinct settings](parity-fixes.md#sampling-both-passes-of-a-long-oblique-blur) · [Earlier 78-setting whole-root measurements](parity-fixes.md#directional-blur-weights-across-110-angles-and-two-projection-axes) · [Earlier whole-root and sample comparisons](parity-fixes.md#direction-and-sample-coordinates-of-long-oblique-blurs) · [Three-tap and eighth-turn probes](parity-fixes.md#projected-weights-and-tap-order-in-short-directional-blurs) · [Independent oblique sampling controls](parity-fixes.md#isolated-sample-coordinates-in-the-two-hq-blur-roots) · [96-angle originals and reopened graphs](parity-fixes.md#independent-rectangular-directional-weights-at-96-angles) · [Tap order and impulse weights over 1,440 branch renders](parity-fixes.md#three-measured-taps-reproduce-the-rectangular-directional-blur-outputs) · [48 angle pairs with identical folded phase](parity-fixes.md#paired-angles-isolate-the-reduced-phase-of-rectangular-blur) · [A differing pair among 24 targeted angle comparisons](parity-fixes.md#equal-reduced-phases-with-distinct-rectangular-blur-coefficients) · [Signed rotations, large angles and reopened roots](parity-fixes.md#directional-blur-weights-at-signed-and-large-rotations) | | [bnw_spots_1.sbs/bnw_spots_1](../assets/sbs/bnw_spots_1.sbs) | 0 | Yes | [In progress · 3,177,940/3,177,984 pixels across 125 settings](parity-fixes.md#pixel-center-rounding-at-the-near-stamp-vertex) · [64,000/64,000 downstream pixels](parity-fixes.md#isolating-the-generators-in-spots-bricks-and-cells) · [Circular stamp and opacity controls](parity-fixes.md#circular-stamp-coverage-and-zero-stamp-opacity) · [One U16 texel accounts for nine default output pixels](parity-fixes.md#one-differing-generator-texel-in-the-basic-spots-root) · [27 generator repeats and held-out pixel predictions](parity-fixes.md#variation-in-the-order-of-additions-in-the-basic-spots-generator) | | [bnw_spots_3.sbs/bnw_spots_3](../assets/sbs/bnw_spots_3.sbs) | 0 | Yes | [Parity · 118 settings, 3,159,552/3,159,552 final pixels](parity-fixes.md#pixel-center-rounding-at-the-near-stamp-vertex) · [27,136/27,136 downstream pixels](parity-fixes.md#isolating-the-generators-in-spots-bricks-and-cells) · [Circular stamp and opacity controls](parity-fixes.md#circular-stamp-coverage-and-zero-stamp-opacity) · [Intermediate recheck](parity-fixes.md#interpolated-coordinates-on-clipped-squares-and-quarter-turns) | | [brick_1.sbs/brick_1](../assets/sbs/brick_1.sbs) | 0 | Yes | [Parity · 131 renders, 3,194,368/3,194,368 pixels](parity-fixes.md#fractional-stamp-vertices-and-the-last-covered-pixel) · [64,000/64,000 downstream pixels](parity-fixes.md#isolating-the-generators-in-spots-bricks-and-cells) · [Earlier generator settings](parity-fixes.md#square-and-rectangular-pattern-generators) |