diff --git a/crates/eval/src/graph_instance.rs b/crates/eval/src/graph_instance.rs index 5bde11a9..2579dd63 100644 --- a/crates/eval/src/graph_instance.rs +++ b/crates/eval/src/graph_instance.rs @@ -142,6 +142,7 @@ pub(crate) fn cook_instance( size_underflow: source_base.size_underflow, dynamic_size: source_base.dynamic_size, format: source_base.format, + pixel_size: source_base.pixel_size, ..base }; Ok((output.clone(), port_base)) diff --git a/crates/eval/src/node_result.rs b/crates/eval/src/node_result.rs index c2927b87..5dc215e9 100644 --- a/crates/eval/src/node_result.rs +++ b/crates/eval/src/node_result.rs @@ -10,7 +10,7 @@ pub struct NodeResult { pub parameters: std::collections::BTreeMap, /// One image per output port (empty when the cook failed) pub outputs: Arc>, - /// Instance ports can return different dimensions and storage formats. + /// Instance ports carry the dimensions, format and pixel size of their source. pub output_bases: Option>, pub error: Option, /// Cook time in milliseconds (0 when served from the cache) diff --git a/crates/eval/tests/instance_pixel_size.rs b/crates/eval/tests/instance_pixel_size.rs new file mode 100644 index 00000000..d4934710 --- /dev/null +++ b/crates/eval/tests/instance_pixel_size.rs @@ -0,0 +1,54 @@ +use materialcraft_core::{FunctionGraph, Graph, NodeId, OutputFormat, Package, ParameterInheritance, Value}; +use materialcraft_eval::{Cache, Options, cook}; +use std::sync::Mutex; + +fn field(graph: &mut Graph, pixel_size: [f32; 2]) -> NodeId { + let mut noise = FunctionGraph::default(); + let unit = noise.add_constant(Value::Float(1.0)); + noise.output = Some(noise.add("rand", &[unit], None)); + let id = graph.add_node("pixel_processor", [0.0; 2]); + let node = graph.node_mut(id).unwrap(); + node.params.insert("function".into(), Value::Function(Box::new(noise))); + node.base.pixel_size = pixel_size; + node.base.pixel_size_mode = ParameterInheritance::Absolute; + id +} + +#[test] +fn blur_inherits_the_pixel_size_of_each_graph_output_on_cold_and_cached_cooks() { + let mut child = Graph::new("Fields"); + let mut parent = Graph::new("Filtered fields"); + for graph in [&mut child, &mut parent] { + graph.size = [6; 2]; + graph.format = OutputFormat::U16; + } + let instance = parent.add_node("graph_instance", [0.0; 2]); + parent.node_mut(instance).unwrap().params.insert("graph".into(), Value::Text("Fields".into())); + let mut comparisons = Vec::new(); + for (identifier, size) in [("horizontal", [2.0, 0.5]), ("vertical", [0.5, 2.0])] { + let inside = field(&mut child, size); + let output = child.add_node("output", [0.0; 2]); + child.node_mut(output).unwrap().params.insert("identifier".into(), Value::Text(identifier.into())); + child.connect(inside, "output", output, "input").unwrap(); + let outside = field(&mut parent, size); + let [nested, flat] = [(instance, identifier), (outside, "output")].map(|(upstream, port)| { + let blur = parent.add_node("blur", [0.0; 2]); + parent.node_mut(blur).unwrap().params.insert("intensity".into(), Value::Float(4.0)); + parent.connect(upstream, port, blur, "input").unwrap(); + blur + }); + comparisons.push((nested, flat, size)); + } + let mut package = Package::new("Pixel sizes"); + package.graphs.extend([parent, child]); + let cache = Mutex::new(Cache::default()); + for cached in [false, true] { + let cooked = cook(&package, 0, &Options::new(&|_| None), &cache); + assert_eq!(cooked.nodes[&instance].error, None); + assert_eq!(cooked.nodes[&instance].cached, cached); + for &(nested, flat, size) in &comparisons { + assert_eq!(cooked.nodes[&nested].base.pixel_size, size); + assert_eq!(cooked.image(nested, 0).unwrap().data(), cooked.image(flat, 0).unwrap().data()); + } + } +} diff --git a/docs/parity-fixes.md b/docs/parity-fixes.md index 562ce9be..3efaea62 100644 --- a/docs/parity-fixes.md +++ b/docs/parity-fixes.md @@ -73,6 +73,27 @@ For a separate check at 256² and seed 372421, compile the same original wrapper Maximum U16 error is zero throughout the three-setting desktop column. The desktop original and reopen also agree in 139,264/139,264 pixels per root. At the previously disputed 256² seed, MaterialCraft and the live desktop agree in 65,536/65,536 pixels per root. The same six, two and four discrepancies recur between the two reference rendering paths on all four one-worker runs per root. The eight-worker runs give more than one output for the same settings. The inventory retains the existing cross-worker differences. [Earlier seed and worker measurements](#computed-graph-seeds-on-load-evaluation-and-save) +### Pixel size on graph instance outputs + +At 128² and seed 0, the Gaussian source in Bricks 01 returns a 64² U16 field with pixel size (2,2). The input to Blur matches the reference in all 4,096 pixels. The filter intensity is 1.61. The instance previously returned the caller's unit pixel size to downstream filters. Blur then copied the field and matched just 53/4,096, maximum U16 error 21,379. + +Create an original grayscale Pixel Processor returning Random(1), stored in U16 at half the caller width and height. Connect it to Blur. In the nested version, place only the source in a child and keep Blur outside. Set pixel size on the source. Use 64² and 128² with seed 0, 128 × 64 with seed 17 and 64 × 128 with seed 12071. Reopen ordinary saves in the reference desktop. Each row compares the filtered pixels at all four dimensions. Maximum error is in the actual output storage units. + +| Source pixel size | Intensity | Blur output | Earlier nested exact · max | Corrected nested exact · max | +|---|---:|---|---:|---:| +| (1,1) | 1.61 | U16 | 9,216/9,216 · 0 | 9,216/9,216 · 0 | +| (2,2) | 1.61 | U16 | 5,120/9,216 · 29445 | 9,216/9,216 · 0 | +| (2,.5) | 4 | U8 | 89/9,216 · 123 | 9,216/9,216 · 0 | +| (.5,2) | 4 | F16 | 13/9,216 · 0.473327637 | 9,216/9,216 · 0 | +| (3,1) | 5.125 | F32 | 0/9,216 · 0.365611508 | 9,216/9,216 · 0 | +| (2,2), Blur set to (1,1) | 1.61 | U16 | 9,216/9,216 · 0 | 9,216/9,216 · 0 | + +All six flat and nested reference pairs agree in 55,296/55,296 pixels. MaterialCraft now passes the internal output's resolved pixel size through each instance port. All 48 flat and nested settings match 110,592/110,592 pixels on originals and again on saves, maximum error 0. Every desktop reopen also matches its original. The regression checks two separate output ports with perpendicular pixel sizes on a cold cook and a cache hit. + +Bricks 01 default Base Color at 128² improves from 13,283/16,384 (maximum U8 error 43) to 16,379/16,384 (maximum 1). Height and Roughness each match 16,384/16,384. Normal matches 16,365/16,384 (maximum U16 error 1) and Ambient Occlusion matches 16,367/16,384 (maximum U16 error 4). Default 64² Base Color still matches 4,096/4,096 and the 64² seed 19, luminosity .65 case matches 4,094/4,096 (maximum 1). The U8 color gradient has differences of one byte with matching inputs. + +At 256² and defaults, raw Base Color matches 65,508/65,536, maximum U8 error 1. The earlier reference 1:1 screen crop matches 65,536/65,536 of this desktop raw capture, maximum error 0. Comparing the current cooked RGB bytes directly with that reference crop gives 65,508/65,536, maximum 1. + ### Intermediate noise outputs and the order of overlapping pattern draws Capture all node outputs of BNW Spots 1 and Clouds 1 and 2 directly in the live desktop. Use 256² and seed 372421, then 128 × 64 and seed 372177, with Disorder .96875 wherever exposed. Also capture the 128² defaults with seed 0. Every captured port stores U16. Compare the stored components at each port against the release evaluator. The terminal images at the first two settings also match the corresponding nested caller in the desktop. diff --git a/docs/sbs-root-nodes.md b/docs/sbs-root-nodes.md index 8dcd0ecb..9d5a5300 100644 --- a/docs/sbs-root-nodes.md +++ b/docs/sbs-root-nodes.md @@ -41,7 +41,7 @@ Nested Curvature, Curvature Smooth and Normal Sobel each match 2,304/2,304 origi Ordinary SBS saves preserve graph seed inheritance across 22 nested graphs. The original and reopened random fields each match 22,528/22,528 pixels. BNW Spots 1 and Clouds 1 and 2 each match 9,216/9,216 pixels across four output formats in the two nested settings. [Seed settings, whole graphs and renderer repeats](parity-fixes.md#graph-random-seed-inheritance-on-save-and-in-nested-graphs) -The Bricks 01 material provides a separate 2D display check. The corrected preview matches all 258 tested encoded RGB channels. The headless 2D PNG also matches every pixel of a 16² uniform-color control in both display modes. With the shared pattern fix, default Base Color matches 4,096/4,096 raw pixels at 64² and 13,283/16,384 at 128², maximum byte errors 0 and 43. The actual 256² 2D views match 55,976/65,536 pixels, maximum 53. [Color swatches](parity-fixes.md#stored-graph-color-in-the-2d-view) · [Whole-material measurements](parity-fixes.md#selected-channels-in-pattern-expressions) +The Bricks 01 material provides a separate 2D display check. The corrected preview matches all 258 tested encoded RGB channels. The headless 2D PNG also matches every pixel of a 16² uniform-color control in both display modes. With the shared pattern and instance pixel-size fixes, default Base Color matches 4,096/4,096 raw pixels at 64² and 16,379/16,384 at 128², maximum byte errors 0 and 1. At 256² the raw outputs match 65,508/65,536, maximum 1. [Child output pixel size and whole-material measurements](parity-fixes.md#pixel-size-on-graph-instance-outputs) [Color swatches](parity-fixes.md#stored-graph-color-in-the-2d-view) · [Whole-material measurements](parity-fixes.md#selected-channels-in-pattern-expressions) The grayscale Tile Generator again has measured parity. Its 55 earlier settings match 284,416/284,416 pixels. Both luminance seeds and all 24 new procedural source, grid and format settings match, including ordinary saves. [Reproduction and zero-error counts](parity-fixes.md#selected-channels-in-pattern-expressions)