From 05ab4e6987bcd880f9a06a0472b060a887f46053 Mon Sep 17 00:00:00 2001 From: chasse20 Date: Fri, 20 Nov 2026 19:24:37 -0500 Subject: [PATCH] Align clipped stamp offsets before product normalization --- .../nodes/src/pattern/coordinates/oblique.rs | 26 +++++++++---- crates/nodes/src/pattern/tests.rs | 15 +++++++ docs/parity-fixes.md | 39 +++++++++++++++++++ docs/sbs-root-nodes.md | 6 +-- 4 files changed, 76 insertions(+), 10 deletions(-) diff --git a/crates/nodes/src/pattern/coordinates/oblique.rs b/crates/nodes/src/pattern/coordinates/oblique.rs index 7ca931b5..0fa700bc 100644 --- a/crates/nodes/src/pattern/coordinates/oblique.rs +++ b/crates/nodes/src/pattern/coordinates/oblique.rs @@ -31,7 +31,9 @@ pub(super) fn planes(triangle: &Triangle, frame: &Footprint, size: [f32; 2], [[l let anchor = triangle.far_axis.map_or(0, |axis| axis + 1); let planes: [Plane; 2] = std::array::from_fn(|component| { let gradient: [f32; 2] = std::array::from_fn(|axis| { - let difference = aligned_sum([f64::from(vertices[axis + 1][component]), -f64::from(vertices[0][component])], 1); + let start = f64::from(vertices[0][component]); + let end = f64::from(vertices[axis + 1][component]); + let difference = aligned_sum([end, -start], leading_power(start.abs().max(end.abs())), 1); let span = truncate_float(difference * 0.5); let basis = triangle.basis[axis]; let exponents = (span.abs().to_bits() >> 23) + (basis.to_bits() >> 23); @@ -46,7 +48,15 @@ pub(super) fn planes(triangle: &Triangle, frame: &Footprint, size: [f32; 2], [[l let magnitude = offset_product(triangle.offset[i], gradient[i].abs(), units[i]); if gradient[i].is_sign_negative() { -magnitude } else { magnitude } }); - let base = truncate_float(aligned_sum([terms[0], terms[1], f64::from(vertices[anchor][component])], 5)); + let anchor_value = f64::from(vertices[anchor][component]); + // Align each offset product using the exponents of its factors, before a + // carry in the product can shift away another bit during cancellation. + let base_scale = triangle + .offset + .into_iter() + .zip(gradient) + .fold(leading_power(anchor_value), |scale, (offset, slope)| scale.max(leading_power(f64::from(offset)) * leading_power(f64::from(slope)))); + let base = truncate_float(aligned_sum([terms[0], terms[1], anchor_value], base_scale, 5)); let step = gradient.map(f64::from); let unit = units[0].max(units[1]); // The two samples of a pair share the value at their midpoint. Its signed @@ -62,13 +72,15 @@ pub(super) fn planes(triangle: &Triangle, frame: &Footprint, size: [f32; 2], [[l planes.iter().all(|p| p.quantum.is_finite()).then_some(planes) } +fn leading_power(value: f64) -> f64 { + f64::from_bits(value.to_bits() & (0x7ff_u64 << 52)) +} + /// Align signed operands at a shared exponent before cancellation in the interpolation setup. -fn aligned_sum(terms: [f64; N], guard_bits: u32) -> f64 { - let largest = terms.iter().map(|v| v.abs()).fold(0.0_f64, f64::max); - if largest == 0.0 { +fn aligned_sum(terms: [f64; N], scale: f64, guard_bits: u32) -> f64 { + if scale == 0.0 { return 0.0; } - let power = f64::from_bits(largest.to_bits() & (0x7ff_u64 << 52)); - let quantum = power / f64::from(1_u32 << (23 + guard_bits)); + let quantum = scale / f64::from(1_u32 << (23 + guard_bits)); terms.into_iter().map(|v| (v / quantum).trunc() * quantum).sum() } diff --git a/crates/nodes/src/pattern/tests.rs b/crates/nodes/src/pattern/tests.rs index d070721f..ae418c77 100644 --- a/crates/nodes/src/pattern/tests.rs +++ b/crates/nodes/src/pattern/tests.rs @@ -405,6 +405,21 @@ fn rotated_stamps_use_the_pixel_center_when_snapping_the_near_vertex() { } } +#[test] +fn clipped_rotated_ramp_aligns_the_plane_origin_before_product_normalization() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(10)), + ("branchoffset".into(), Value::Float2([-0.5; 2])), + ("frameoffset".into(), Value::Float2([0.113407135, 0.3964901])), + ("patternsize".into(), Value::Float2([0.23880348, 0.90636885])), + ("patternrotation".into(), Value::Float(0.94554406)), + ]); + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0))]); + let image = cook_at_dimensions(graph, &variables, 396907, 128, 256).unwrap().remove(0); + assert_eq!(image.get_gray(11, 163, false).to_bits(), 0x3d88_c460); +} + #[test] fn quarter_turn_square_snaps_its_bounds_before_the_residual_phase_affects_sampling() { let variables = BTreeMap::from([("$tiling".into(), Value::Int(0))]); diff --git a/docs/parity-fixes.md b/docs/parity-fixes.md index 5d602ba8..d123c00c 100644 --- a/docs/parity-fixes.md +++ b/docs/parity-fixes.md @@ -534,6 +534,45 @@ For each root’s 25 follow-up renders, the 5,120 U8, 553,728 U16, 78,336 F16 an In a single-worker release run, four interleaved measurements of the 128² default, 256² default and 512² filled cases gave median whole-graph cook times of 46, 259 and 1,138 ms for Alveolus (previously 45, 247 and 1,068 ms). Pattern Alveolus took 45, 253 and 1,083 ms (previously 43, 238 and 1,045 ms). +### Aligning the origin of a clipped stamp in Creased + +Creased matches **10,947,840/10,947,840 final pixels across 100 distinct settings**, through 1024². Maximum error is zero in every format. Both applications reopened the MaterialCraft file in two independently authored matrices. All 2,399,232 pixels in the 40-setting matrix and all 8,730,624 in the 46-setting matrix matched the original and each other. Repeated settings count once in the following totals. + +| Storage | Distinct settings | Exact pixels | Maximum error | +|---|---:|---:|---:| +| U8 | 18 | 2,093,824/2,093,824 | 0 | +| U16 | 32 | 3,403,520/3,403,520 | 0 | +| F16 | 18 | 2,093,824/2,093,824 | 0 | +| F32 | 32 | 3,356,672/3,356,672 | 0 | + +At 256×512, seed 392488, disorder .9921875 and warp intensity 52.875, the 128×256 pattern generator now stores 36,919 at (11,163). Every captured pixel in its generator, blur, two directional warps and final output matches across twelve stage comparisons. All 22 previously differing final pixels in the 40-setting matrix now agree. [Warp settings and intermediate counts before this fix](#horizontal-displacement-at-zero-warp-angle) + +A single horizontal ramp reproduces the discrepancy without blur or warp. At 128×256 use a black F32 grayscale quadrant, no tiling, unit tint and gain, zero roughness, branch offset (−.5,−.5), frame offset (.113407135,.3964901), size (.23880348,.90636885), rotation .94554406 turns and seed 396907. At (11,163) the reference returns bits 0x3d88c460. The previous implementation returned 0x3d88c464. The corresponding stamp triangle starts at screen coordinates (−19,−18) with horizontal span 136 and vertical span 479. Its origin uses integer pixel offsets 19 and 18. The horizontal signed-coordinate gradients are .06163756921887398 and −.010976589284837246. When summing the vertex value and the two offset products, align the terms at the largest of the vertex exponent and the two sums of factor exponents. A carry in a product still uses the exponent sum from before normalization. This gives the measured origin .21940191090106964. Using the exponents of the completed products gave .21940192580223083. + +An independent graphics-device comparison varied the triangle origin and attributes in 2,304 original triangles. Across all visible signed coordinates, exact counts rose from 1,044,686 to 1,047,772/1,047,772. Changing the alignment precision by one bit for every triangle produced 21,038 differences. For the fifteen stamps contributing to the disputed Creased pixel, all 3,932,160 F32 pixels matched across ramp, paraboloid, pyramid and creased-bell profiles at the measured and unit gains. A further 108 translated and rescaled geometries per profile reached 7,471,101/7,471,104, 7,471,071/7,471,104, 7,471,076/7,471,104 and 7,471,071/7,471,104 respectively. Their maximum F32 errors were 1.19209290e−7, 2.98023224e−7, 1.78813934e−7 and 1.30850822e−7. The outstanding isolated differences include slopes on clipped, rotated stamps in BNW Spots 3 and Clouds 1. + +In eight alternating single-worker release runs, median intact cook times were 206 ms and 179 ms for BNW Spots 1 and 3, previously 211 ms and 183 ms. The depth-seven and depth-nine controls measured 34.4 ms and 542 ms, previously 34.9 ms and 559 ms. + +For the 46 independent intact renders use the following dimensions, seeds, warp intensities and disorders. Render U16 and F32 in every row. Add U8 and F16 at the rows marked four. The earlier 17- and 40-render settings are linked above. + +| Dimensions | Seed | Warp intensity | Disorder | Formats | +|---|---:|---:|---:|---| +| 32×16 | 17 | 1 | .5 | Four | +| 16×128 | 6323 | .25 | 1 | Two | +| 128×16 | 3251 | Default | Default | Four | +| 32×512 | 21973 | 2.125 | .875 | Two | +| 512×32 | 29599 | 61.75 | .21875 | Four | +| 128² | 11 | Default | Default | Two | +| 128×256 | 971 | 23 | .3125 | Four | +| 256×128 | 17 | 47.125 | .6875 | Two | +| 256² | 0 | 32 | .33333334 | Four | +| 256×512 | 392488 | 52.875 | .9921875 | Two | +| 512×256 | 0 | Default | Default | Four | +| 512² | 112309 | 64 | .625 | Four | +| 512×1024 | 45719 | 12.75 | .46875 | Two | +| 1024×512 | 10973 | 57.8125 | .90625 | Two | +| 1024² | 29987 | Default | Default | Four | + ### Horizontal displacement at zero warp angle Creased now matches all 145,664 final pixels in the 17-render comparison. Across 40 further settings the count rose from 2,392,277 to 2,399,210/2,399,232. The original and saved graphs agree on all 2,399,232 pixels within each application. Both applications produced the same 22 cross-app differences after reopening. Creased remains in progress. diff --git a/docs/sbs-root-nodes.md b/docs/sbs-root-nodes.md index f2514ce2..a7b95133 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 **389 Parity**, **157 In progress** and **0 Too hard**. The November 17–20 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) +The first pass covered all **546 roots**, with **166 Parity** and **380 Too hard**. The current inventory has **390 Parity**, **156 In progress** and **0 Too hard**. The November 17–20 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) [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) @@ -89,7 +89,7 @@ Crystal 2 now matches all 5,104,128 pixels across 99 distinct settings through 5 BNW Spots 3 matches all 3,159,552 final pixels across 118 distinct settings. Both apps reopened its saved graph and reproduced all 2,399,232 pixels in the 40-setting file check. One U16 difference remains inside its 256² pattern stage. BNW Spots 1 matches 3,177,940/3,177,984 final pixels across 125 settings. [Pixel-center measurements and remaining differences](parity-fixes.md#pixel-center-rounding-at-the-near-stamp-vertex) -Creased matches all 145,664 pixels in its original matrix and 2,399,210/2,399,232 across 40 further settings. Eleven U16 and eleven F32 pixels differ at one rectangular setting. [Warp measurements and the isolated generator sample](parity-fixes.md#horizontal-displacement-at-zero-warp-angle) +Creased matches 10,947,840/10,947,840 pixels across 100 distinct settings through 1024². Both applications reproduced the original pixels after reopening the saved file. [Exact counts, intermediate stages and settings](parity-fixes.md#aligning-the-origin-of-a-clipped-stamp-in-creased) ## Complete inventory @@ -209,7 +209,7 @@ Creased matches all 145,664 pixels in its original matrix and 2,399,210/2,399,23 | [constant_values.sbs/integer/constant_integer4](../assets/sbs/constant_values.sbs) | 0 | No | [Parity · 41 exact typed vectors, authored constants checked on reload](parity-fixes.md#stored-integer-value-outputs) | | [contrast_luminosity.sbs/contrast_luminosity](../assets/sbs/contrast_luminosity.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [contrast_luminosity.sbs/contrast_luminosity_grayscale](../assets/sbs/contrast_luminosity.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [creased.sbs/creased](../assets/sbs/creased.sbs) | 0 | Yes | [In progress · 2,399,210/2,399,232 pixels on 40 new renders, 17 earlier renders exact](parity-fixes.md#horizontal-displacement-at-zero-warp-angle) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) | +| [creased.sbs/creased](../assets/sbs/creased.sbs) | 0 | Yes | [Parity · 100 settings, 10,947,840/10,947,840 pixels](parity-fixes.md#aligning-the-origin-of-a-clipped-stamp-in-creased) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) | | [crop.sbs/crop](../assets/sbs/crop.sbs) | 1 | No | [Parity · 48 renders, all 377,344 pixels across both outputs exact](parity-fixes.md#half-precision-crop-area-and-input-sizes) | | [crop.sbs/crop_grayscale](../assets/sbs/crop.sbs) | 1 | No | [Parity · 48 renders, all 377,344 pixels across both outputs exact](parity-fixes.md#half-precision-crop-area-and-input-sizes) | | [crystal_1.sbs/crystal_1](../assets/sbs/crystal_1.sbs) | 0 | Yes | [Parity · 1,966,336/1,966,336 pixels in 64 distinct renders, 32 reopened settings](parity-fixes.md#stored-stamp-vertices-in-crystal-1) |