diff --git a/crates/nodes/src/atomic/blend.rs b/crates/nodes/src/atomic/blend.rs index c2445571..1c8458ed 100644 --- a/crates/nodes/src/atomic/blend.rs +++ b/crates/nodes/src/atomic/blend.rs @@ -36,7 +36,7 @@ fn blend(context: &CookContext) -> CookResult { let (x, y) = (x as i64, y as i64); let m = mask.as_ref().map_or(1.0, |m| m.get_gray(x, y, false)); // These modes read the mask through its transparency before applying global opacity. - let m = if ((0..=2).contains(&mode) && color_blending == 0) || matches!(mode, 7 | 8) { 1.0 - (1.0 - m) } else { m }; + let m = if ((0..=2).contains(&mode) && color_blending == 0) || matches!(mode, 3 | 7 | 8) { 1.0 - (1.0 - m) } else { m }; ops::blend_px(mode, background.get(x, y, false), foreground.get(x, y, false), opacity * m, color_blending, blend_alpha, clamp) })]) } @@ -58,6 +58,9 @@ mod tests { (0, 0, 0.07, true, false, [0x3f1e8c37, 0x3f236cdd, 0x3d21ff39, 0x3e892c70]), (0, 0, 0.3, false, false, [0x3f1e4fbd, 0x3f22b8df, 0x3d267f2b, 0x3e888889]), (0, 0, 0.3, true, true, [0x3f514e8e, 0x3f4b8353, 0xbf55520b, 0xbdcc9712]), + (3, 0, 0.6875, true, false, [0x3f1d2bec, 0x3f214e9d, 0x3d1e9201, 0x3e8ed249]), + (3, 1, 0.6875, true, false, [0x3f145cda, 0x3f131eb2, 0x3d120e5e, 0x3e8ed249]), + (3, 3, 0.6875, true, false, [0x3f1d2bec, 0x3f214e9d, 0x3d1e9201, 0x3e8ed249]), (7, 0, 0.6137, true, false, [0x3f1a2797, 0x3f1659c4, 0x3d75aca1, 0x3e81bac6]), (8, 0, 0.6137, true, false, [0x3f21760a, 0x3f319bf2, 0x3d286e88, 0x3e8e257d]), (8, 1, 0.6137, false, false, [0x3f32bf2c, 0x3f834be5, 0x3d57e86e, 0x3e888889]), diff --git a/crates/nodes/src/ops.rs b/crates/nodes/src/ops.rs index 59296935..2c04d3ea 100644 --- a/crates/nodes/src/ops.rs +++ b/crates/nodes/src/ops.rs @@ -314,7 +314,8 @@ pub fn blend_channel(mode: i32, b: f32, f: f32) -> f32 { match mode { 1 => b + f, 2 => b - f, - 3 => b * f, + // Multiply starts at positive zero. Its weighted contribution can still be negative zero. + 3 => b.mul_add(f, 0.0), 4 => b + 2.0 * f - 1.0, 5 => b.max(f), 6 => b.min(f), @@ -373,7 +374,7 @@ pub fn blend_px(mode: i32, bg: [f32; 4], fg: [f32; 4], opacity: f32, color_blend } return out; } - if ((0..=2).contains(&mode) && color_blending == 0) || (mode == 8 && color_blending != 2) { + if ((0..=2).contains(&mode) && color_blending == 0) || (matches!(mode, 3 | 8) && color_blending != 2) { // The color weights use the complement of transparency. Coverage uses the original alpha. let alpha = if color_blending == 1 { 1.0 } else { 1.0 - (1.0 - fg[3]) }; let source_weight = alpha * opacity; @@ -426,6 +427,15 @@ pub fn gray_from(w: u32, h: u32, v: Vec) -> Result { mod tests { use super::*; + #[test] + fn multiply_blend_preserves_the_sign_after_weighting_a_zero_product() { + let background = [-0.0, 1.0, -0.5, 0.0]; + for (alpha, expected) in [(0.0, [0.0, 1.0, -0.5, 0.0]), (-1.0, [-0.0, 3.0, -1.25, -1.0])] { + let result = blend_px(3, background, [0.0, -1.0, -0.5, alpha], 1.0, 0, true, false); + assert_eq!(result.map(f32::to_bits), expected.map(f32::to_bits)); + } + } + #[test] fn divide_blend_handles_zero_and_small_nonzero_divisors() { for numerator in [-8.0, 0.0, 0.5] { diff --git a/docs/parity-fixes.md b/docs/parity-fixes.md index 37abfe1b..d49c7b4d 100644 --- a/docs/parity-fixes.md +++ b/docs/parity-fixes.md @@ -693,6 +693,18 @@ For shape mapper, the five earlier comparison sizes and four-format inputs are l For ten further shape mapper renders use H=(((59x+41y+5xy) mod 1021)/1020+u+2v)/4, where u,v are source texel centers. Use defaults at 16²/83, four formats at 64²/167, F32 at 128²/347, a 32×16 input at 32²/499, signed 32²/631 with 3H−1.375, 64²/787 and 64²/827. Set radius .375, width .71875, rotation .09375, nine patterns and seven segments. Use shape 0 and disable non-square expansion for the rectangular input. Use shape 1 elsewhere. Link segments and pattern count for the signed input. Disable alternate flipping and select nearest filtering at seed 787. Together the ten smooth-field renders match all 43,264 stored pixels. +### Multiply blending and pre/post composition + +The color pre/post composite matches **166,400/166,400 RGBA pixels in 17 renders**, maximum error zero. The two Levels inputs to the final blend matched on all 4,096 pixels in the changed 64² case before the fix. The multiply blend itself previously matched 2,514/4,096 in the additional 64² F32 field. The complete matrix improved from 162,255/166,400. The final counts are 122,880 U8, 8,192 U16, 8,192 F16 and 27,136 F32. + +Use the four archive cases, changed 64²/42 with opacity .37 and mode 3 in all four formats, and the independent 32² case. For eight further cases, take the [composite matte field](#unbound-property-links-and-composite-matte) Hⱼ. Set foreground to (H₁,H₂,H₃,(x mod 5)/4) and background to (H₄,H₅,H₆,(y mod 7)/6). Test 16² opaque/default, 16² with opacity .375 and mode 0, 64² in all four formats with .6875 and mode 3, 32² opaque with 1 and mode 0, then 128² with .3125 and mode 1. Use seeds 103,164,225,286,347 respectively. + +Independent multiply controls match **2,990,080/2,990,080 pixels in 130 renders**, including the three signed-zero fields below. The measured source-alpha, ignore-alpha and premultiplied paths preserve separate rounding of the color and coverage weights. For the original byte foreground (116,38,60,36), background (158,163,10,68), mask 44 and opacity .6875, source-alpha returns F32 bits (3f1d2bec,3f214e9d,3d1e9201,3e8ed249). Ignoring foreground alpha for color gives (3f145cda,3f131eb2,3d120e5e,3e8ed249). A separate straight-alpha control remains at 14,395/40,960 across ten renders, maximum F32 component error 377.020249 on signed HDR input. + +Use the [independent blend inputs](#color-burn-and-color-dodge) with mode 3 and opacities 1, .6875 and .37. At 64² use varied, opaque, white-mask, constant, black-foreground and transparent-background cases with U8 and F32 sources. Capture the varied case in all four formats. For float sources add the signed field 3H−1 to foreground and background. At .6875 vary the color interpretation and toggle coverage. For grayscale use the 256² byte-pair matrix, reversed pair order and the signed 16-value grid at opacities 1 and .6875. Floating-point comparisons include zero’s sign bit. + +For a direct zero test, set V=(+0,−0,1,−1,.5,−.5,2,−2) with indices modulo eight. At 64² set foreground=(V[x],V[x+3],V[x+5],V[y]) and background=(V[floor(x/8)],V[floor(x/8)+1],V[floor(x/8)+4],V[floor(y/8)]). At seeds 137,180,223 use mask 1, V[x+y] and .6875 respectively. The channel product starts at positive zero. Subsequent weighting preserves a negative zero when both terms are negative zero. All 12,288 RGBA32F pixels now match bit for bit, up from 9,779/12,288 with maximum numerical error zero. + ### Unbound property links and composite matte | Comparison | Renders | Exact pixels / compared | Maximum error | diff --git a/docs/sbs-root-nodes.md b/docs/sbs-root-nodes.md index 6230cf93..5c8d8770 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 **311 Parity**, **45 In progress** and **190 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 **312 Parity**, **45 In progress** and **189 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) @@ -145,7 +145,7 @@ The first pass covered all **546 roots**, with **166 Parity** and **380 Too hard | [composite.sbs/composite/background/uniform_color_float3](../assets/sbs/composite.sbs) | 0 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [composite.sbs/composite/blends/blend_content](../assets/sbs/composite.sbs) | 3 | Yes | [Parity · 171,264 exact pixels in 18 renders](parity-fixes.md#segment-mapping-and-normal-graph-rechecks) | | [composite.sbs/composite/blends/blend_content_grayscale](../assets/sbs/composite.sbs) | 3 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [composite.sbs/composite/blends/blend_content_pre_post_composite](../assets/sbs/composite.sbs) | 2 | Yes | [Too hard: pixel differences](parity-fixes.md#remaining-differences) | +| [composite.sbs/composite/blends/blend_content_pre_post_composite](../assets/sbs/composite.sbs) | 2 | Yes | [Parity · 17 renders, all 166,400 RGBA pixels exact](parity-fixes.md#multiply-blending-and-prepost-composition) | | [composite.sbs/composite/blends/blend_content_pre_post_composite_grayscale](../assets/sbs/composite.sbs) | 2 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [composite.sbs/composite/blends/blend_matte](../assets/sbs/composite.sbs) | 2 | Yes | [Parity · 19 renders, all 168,448 grayscale pixels exact](parity-fixes.md#unbound-property-links-and-composite-matte) | | [composite.sbs/composite/blends/blend_matte_bg_passthrough](../assets/sbs/composite.sbs) | 2 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) |