diff --git a/ATTRIBUTION.md b/ATTRIBUTION.md index 401ce6ab..4bcac3a9 100644 --- a/ATTRIBUTION.md +++ b/ATTRIBUTION.md @@ -35,7 +35,8 @@ images, materials, sample graphs, presets, environments) may ever be added. | `docs/images/materialcraft-levels-editor.png` | Docs screenshot: the Levels editor with the input histogram | MaterialCraft contributors | Offscreen render of MaterialCraft's UI (`crates/ui-egui/tests/snapshot.rs`) | MIT OR Apache-2.0 | | `docs/brand/artcraft-*.svg`, `docs/brand/artcraft-*.png` | ArtCraft logo and mark | ArtCraft Team | storytold/craftrules `assets/brand/` | ArtCraft brand terms, not open source ([`docs/brand/LICENSE-brand.txt`](docs/brand/LICENSE-brand.txt)) | | `crates/nodes/src/atomic/text.rs` (`GLYPHS`) | Single-stroke vector font of the Text node (A–Z, a–z, 0–9, punctuation) | MaterialCraft contributors | Original, designed as stroke data in code | MIT OR Apache-2.0 | -| `assets/sbs/` (every `.sbs` package, recursively), `examples/atomic_sample.sbs` | Procedural node, function graph and material library; atomic sample | ArtCraft Team and the MaterialCraft contributors | Original clean-room recreations of the professional node-based material workflow, created for MaterialCraft; authorship confirmed by the project maintainer | MIT OR Apache-2.0 | +| `assets/sbs/` (every `.sbs` package, recursively) | Procedural node, function graph and material library | ArtCraft Team and the MaterialCraft contributors | Original work created for MaterialCraft. The project maintainer confirmed authorship of the collection. | MIT OR Apache-2.0 | +| [examples/atomic_sample.sbs](examples/atomic_sample.sbs) | Atomic sample graph | ArtCraft Team and the MaterialCraft contributors | [Rust graph generator](crates/engine/src/atomic_sample.rs) and [SBS example writer](crates/engine/examples/atomic_sample.rs) | MIT OR Apache-2.0 | | `assets/sbs/resources/bluenoise_256.png` | 256 × 256 grayscale blue noise, contributor-supplied PNG | Christoph Peters | [Moments in Graphics](https://momentsingraphics.de/BlueNoise.html); contributor-supplied provenance | CC0-1.0 ([license](assets/sbs/resources/LICENSE_BLUE_NOISE.txt)) | | `assets/sbs/resources/bluenoise_256_c.exr` | 256 × 256 color blue noise, contributor-supplied EXR conversion | Christoph Peters | [Moments in Graphics](https://momentsingraphics.de/BlueNoise.html); contributor-supplied provenance | CC0-1.0 ([license](assets/sbs/resources/LICENSE_BLUE_NOISE.txt)) | | `assets/sbs/resources/shuf4_64_32.exr` | 64 × 32 sampling lookup, contributor-supplied EXR | Lukas Hosek and Alexander Wilkie | [Skylight Modelling](https://cgg.mff.cuni.cz/projects/SkylightModelling/); contributor-supplied provenance | BSD-3-Clause ([license](assets/sbs/resources/LICENSE_HOSEK_WILKIE.txt)) | diff --git a/Cargo.lock b/Cargo.lock index 73a1c441..9cb124cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3703,6 +3703,7 @@ dependencies = [ "craft-image-codecs", "craft-mcmat", "craft-mesh", + "craft-mime", "craft-sbs", "craft-svg", "craft-texture", @@ -3738,9 +3739,16 @@ dependencies = [ name = "materialcraft-nodes" version = "0.4.1" dependencies = [ + "craft-font-catalog", "craft-texture", + "half", + "harfrust 0.13.3", "materialcraft-core", "rayon", + "read-fonts 0.43.3", + "serde_json", + "unicode-bidi", + "vello_common", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index c4934bae..92921ee8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,7 +66,8 @@ materialcraft-ui-egui = { path = "crates/ui-egui" } # external thiserror = "2" serde = { version = "1", features = ["derive"] } -serde_json = "1" +# Preserve decimal parameter values before converting them to the graph's storage type. +serde_json = { version = "1", features = ["float_roundtrip"] } sha2 = "0.10" # MIT OR Apache-2.0; stable content keys for persistent previews. glam = { version = "0.30", features = ["serde", "bytemuck"] } rayon = "1" @@ -100,6 +101,11 @@ craft-behavior = { git = "https://github.com/storytold/craft-libs", rev = "d7010 craft-host = { git = "https://github.com/storytold/craft-libs", rev = "d7010805175ba1190d521b2565852bdda39e632c" } craft-theme = { git = "https://github.com/storytold/craft-libs", rev = "d7010805175ba1190d521b2565852bdda39e632c" } craft-i18n = { git = "https://github.com/storytold/craft-libs", rev = "d7010805175ba1190d521b2565852bdda39e632c" } +craft-font-catalog = { git = "https://github.com/storytold/craft-libs", rev = "d7010805175ba1190d521b2565852bdda39e632c", default-features = false } +harfrust = "0.13" +read-fonts = { version = "0.43", default-features = false } +unicode-bidi = "0.3.18" +vello_common = { version = "0.2", default-features = false, features = ["std"] } # Keyboard bindings (chords, dispatch and display text): storytold/craft-libs, MIT OR Apache-2.0 craft-keymap = { git = "https://github.com/storytold/craft-libs", rev = "d7010805175ba1190d521b2565852bdda39e632c", features = ["egui"] } # Native dialogs that do not block the event loop: storytold/craft-libs, MIT OR Apache-2.0 diff --git a/ROADMAP.md b/ROADMAP.md index 3fb8c5d6..11f45272 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,6 +1,14 @@ # MaterialCraft roadmap -**Current focus (2026-11-16):** node behavior, regression coverage and interoperable save/load. +**Current focus (2026-11-28):** ship the measured root-graph improvements and validated save/load fixes; carry the remaining parity work into the next release. + +The root inventory records **494 exact cases out of 546 measured roots**, not complete +numerical compatibility. The other 52 remain deferred: [reference variability and remaining +root differences (#336)](https://github.com/storytold/materialcraft/issues/336) and +[two older linked-dependency cases (#337)](https://github.com/storytold/materialcraft/issues/337). +[Review edge cases and older-document rendering compatibility (#338)](https://github.com/storytold/materialcraft/issues/338) +also need investigation. Corrected SBS conventions can change renders of documents authored +against earlier MaterialCraft behavior; keep original files when comparing versions. The old Rust procedural library has been removed. The main catalog has 29 entries: 25 native primitives and four graph input/output items. Functions have 85 operations; pattern graphs have diff --git a/assets/sbs/functions.sbs b/assets/sbs/functions.sbs index 1d70ccd1..94cbc45a 100644 --- a/assets/sbs/functions.sbs +++ b/assets/sbs/functions.sbs @@ -1 +1 @@ - + diff --git a/crates/automation/src/headless.rs b/crates/automation/src/headless.rs index bbf540f2..f30e6a14 100644 --- a/crates/automation/src/headless.rs +++ b/crates/automation/src/headless.rs @@ -303,7 +303,7 @@ impl Headless { let (w, h) = (options.width.unwrap_or(image.width()).clamp(16, maximum_side), options.height.unwrap_or(image.height()).clamp(16, maximum_side)); let image = image.resize(w, h, true); - Ok((w, h, image.to_rgba8_display())) + Ok((w, h, materialcraft_engine::graph_pixels::rgba8(&image, self.session.view2d.srgb))) } fn render_3d(&mut self, o: &RenderOptions, max: u32) -> (u32, u32, Vec) { diff --git a/crates/automation/tests/view_settings.rs b/crates/automation/tests/view_settings.rs index 404e7665..c1202d7e 100644 --- a/crates/automation/tests/view_settings.rs +++ b/crates/automation/tests/view_settings.rs @@ -2,6 +2,22 @@ use materialcraft_automation::headless::{Filesystem, Headless, RenderOptions}; use materialcraft_engine::new_session; use serde_json::json; +#[test] +fn headless_graph_previews_use_the_selected_display_encoding() { + let mut headless = Headless::new(new_session(), Filesystem::Denied); + headless.session.preview_size = Some(16); + let source = headless.command_run("graph.node.add", json!({"def": "uniform", "params": {"color": [0.2, 0.4, 0.8, 1.0]}})).unwrap(); + headless.command_run("view.2d", json!({"node": source["id"]})).unwrap(); + let options = RenderOptions { view: Some("2d".into()), width: Some(16), height: Some(16), ..Default::default() }; + for (srgb, expected) in [(true, [51, 102, 204, 255]), (false, [124, 170, 231, 255])] { + headless.command_run("view.2d", json!({"srgb": srgb})).unwrap(); + let png = headless.render_png(&options).unwrap(); + let image = image::load_from_memory(&png.png).unwrap().to_rgba8(); + assert_eq!(image.dimensions(), (16, 16)); + assert!(image.pixels().all(|pixel| pixel.0 == expected), "{srgb}: {:?}", image.get_pixel(0, 0)); + } +} + #[test] fn rejected_view_command_preserves_the_rendered_scene() { let mut h = Headless::new(new_session(), Filesystem::Denied); diff --git a/crates/core/src/base_parameter.rs b/crates/core/src/base_parameter.rs index cbef563c..129ff01f 100644 --- a/crates/core/src/base_parameter.rs +++ b/crates/core/src/base_parameter.rs @@ -84,8 +84,8 @@ impl BaseParameter { }; } (Self::PixelSize, Value::Float2(size)) => { - if size.iter().any(|component| !component.is_finite() || *component <= 0.0 || *component > 8192.0) { - return Err("Pixel size components must be finite and between 0 and 8192, excluding zero".into()); + if size.iter().any(|component| !component.is_finite() || component.abs() > 8192.0) { + return Err("Pixel size components must be finite and between -8192 and 8192".into()); } base.pixel_size = *size; diff --git a/crates/core/src/curve.rs b/crates/core/src/curve.rs index 73e14e9c..dd4378ba 100644 --- a/crates/core/src/curve.rs +++ b/crates/core/src/curve.rs @@ -71,8 +71,8 @@ impl Curve { } } - let left_handle = left.right.unwrap_or([left.x + span / 3.0, left.y + slopes[0] * span / 3.0]); - let right_handle = right.left.unwrap_or([right.x - span / 3.0, right.y - slopes[1] * span / 3.0]); + let left_handle = if left.right_broken { [left.x, left.y] } else { left.right.unwrap_or([left.x + span / 3.0, left.y + slopes[0] * span / 3.0]) }; + let right_handle = if right.left_broken { [right.x, right.y] } else { right.left.unwrap_or([right.x - span / 3.0, right.y - slopes[1] * span / 3.0]) }; Some([[left.x, left.y], left_handle, right_handle, [right.x, right.y]]) } } diff --git a/crates/core/src/curve_point.rs b/crates/core/src/curve_point.rs index e9d53f9e..caedf10f 100644 --- a/crates/core/src/curve_point.rs +++ b/crates/core/src/curve_point.rs @@ -9,10 +9,17 @@ pub struct CurvePoint { pub left: Option<[f32; 2]>, #[serde(default, skip_serializing_if = "Option::is_none")] pub right: Option<[f32; 2]>, + /// A broken handle retains its authored position and contributes no tangent. + #[serde(default)] + pub left_broken: bool, + #[serde(default)] + pub right_broken: bool, + #[serde(default)] + pub locked: bool, } impl CurvePoint { pub fn new(x: f32, y: f32) -> Self { - Self { x, y, left: None, right: None } + Self { x, y, left: None, right: None, left_broken: false, right_broken: false, locked: false } } } diff --git a/crates/core/src/exposed_parameter.rs b/crates/core/src/exposed_parameter.rs index d8320b4d..08ea49d9 100644 --- a/crates/core/src/exposed_parameter.rs +++ b/crates/core/src/exposed_parameter.rs @@ -12,6 +12,9 @@ pub struct ExposedParameter { #[serde(default, skip_serializing_if = "String::is_empty")] pub group: String, pub default: Value, + /// A standalone SBS function can explicitly declare a wireable argument. + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub connectable: bool, #[serde(default, skip_serializing_if = "String::is_empty")] pub description: String, #[serde(default, skip_serializing_if = "Option::is_none")] diff --git a/crates/core/src/graph.rs b/crates/core/src/graph.rs index 61a6a23a..ea39707f 100644 --- a/crates/core/src/graph.rs +++ b/crates/core/src/graph.rs @@ -28,10 +28,25 @@ pub struct Graph { pub pins: Vec, /// log2 of the graph ("parent") size per axis pub size: [u32; 2], + /// An authored absolute output size, in log2 texels, independent of the default parent size. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub absolute_output_size: Option<[i32; 2]>, + /// The signed graph output size offset from its caller. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub relative_output_size: Option, + /// Authored function supplying the two output size exponents or offsets. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub output_size_function: Option, #[serde(default)] pub format: OutputFormat, #[serde(default)] pub seed: i32, + /// Whether a nested graph starts from its own seed or adds to its instance seed. + #[serde(default)] + pub seed_mode: crate::ParameterInheritance, + /// An authored expression for the graph seed offset. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub seed_function: Option, #[serde(default)] pub pixel_ratio: i32, #[serde(default)] @@ -54,17 +69,25 @@ pub struct Graph { pub input_images: BTreeMap, #[serde(default, skip_serializing_if = "BTreeSet::is_empty")] pub input_images_linear: BTreeSet, + /// SBS image bindings without an explicit preview interpretation use the resource's file transfer. + #[serde(default, skip_serializing_if = "BTreeSet::is_empty")] + pub input_images_from_file: BTreeSet, #[serde(default)] pub attributes: Attributes, /// The id the next node, frame, comment or pin gets pub next_id: u64, } -/// Smallest and largest graph size, as log2 (16 px .. 8192 px) -pub const MIN_SIZE_LOG2: u32 = 4; +/// Bounds for each default parent dimension, as log2 (1 px .. 8192 px) +pub const MIN_SIZE_LOG2: u32 = 0; pub const MAX_SIZE_LOG2: u32 = 13; impl Graph { + /// Round a requested parent dimension up to a supported power of two. + pub fn parent_size_log2(pixels: u64) -> u32 { + pixels.clamp(1 << MIN_SIZE_LOG2, 1 << MAX_SIZE_LOG2).next_power_of_two().ilog2() + } + /// Display text never changes the identifier used by SBS references pub fn display_name(&self) -> &str { if self.attributes.label.is_empty() { &self.name } else { &self.attributes.label } @@ -82,8 +105,13 @@ impl Graph { comments: Vec::new(), pins: Vec::new(), size: [10, 10], + absolute_output_size: None, + relative_output_size: None, + output_size_function: None, format: OutputFormat::U16, seed: 0, + seed_mode: crate::ParameterInheritance::default(), + seed_function: None, pixel_ratio: 0, pixel_ratio_mode: crate::ParameterInheritance::default(), tiling: [true, true], @@ -94,6 +122,7 @@ impl Graph { presets: Vec::new(), input_images: BTreeMap::new(), input_images_linear: BTreeSet::new(), + input_images_from_file: BTreeSet::new(), attributes: Attributes::default(), next_id: 1, } @@ -105,7 +134,7 @@ impl Graph { /// All editable Function canvases, including processor and parameter functions pub fn functions(&self) -> impl Iterator { - self.function.iter().chain( + self.function.iter().chain(self.output_size_function.iter()).chain(self.seed_function.iter()).chain( self.nodes .iter() .flat_map(|node| node.base.functions.values().chain(node.functions.values()).chain(node.params.values().flat_map(value_functions))), @@ -113,7 +142,7 @@ impl Graph { } pub fn functions_mut(&mut self) -> impl Iterator { - self.function.iter_mut().chain( + self.function.iter_mut().chain(self.output_size_function.iter_mut()).chain(self.seed_function.iter_mut()).chain( self.nodes.iter_mut().flat_map(|node| { node.base.functions.values_mut().chain(node.functions.values_mut()).chain(node.params.values_mut().flat_map(value_functions_mut)) }), @@ -128,8 +157,12 @@ impl Graph { } pub fn instances_mut(&mut self) -> impl Iterator { - self.function.iter_mut().flat_map(|function| function.nodes.iter_mut().filter_map(|node| node.instance.as_mut())).chain(self.nodes.iter_mut().flat_map( - |node| { + self.function + .iter_mut() + .chain(self.output_size_function.iter_mut()) + .chain(self.seed_function.iter_mut()) + .flat_map(|function| function.nodes.iter_mut().filter_map(|node| node.instance.as_mut())) + .chain(self.nodes.iter_mut().flat_map(|node| { node.instance.iter_mut().chain( node.base .functions @@ -138,8 +171,7 @@ impl Graph { .chain(node.params.values_mut().flat_map(value_functions_mut)) .flat_map(|function| function.nodes.iter_mut().filter_map(|node| node.instance.as_mut())), ) - }, - )) + })) } pub fn kind(&self) -> GraphKind { @@ -230,9 +262,44 @@ impl Graph { self.inputs.get(id).or_else(|| self.exposed.iter().find(|e| e.id == id).map(|e| &e.default)) } - /// Graph size in pixels + /// Default parent size used when the graph has no caller. + pub fn parent_size_px(&self) -> [u32; 2] { + self.size.map(|axis| 1 << axis.clamp(MIN_SIZE_LOG2, MAX_SIZE_LOG2)) + } + + /// Literal graph size in pixels. Cooking also evaluates the output size function. pub fn size_px(&self) -> [u32; 2] { - [1 << self.size[0].clamp(MIN_SIZE_LOG2, MAX_SIZE_LOG2), 1 << self.size[1].clamp(MIN_SIZE_LOG2, MAX_SIZE_LOG2)] + self.resolved_output_size(None, None).0 + } + + /// Resolve this graph's output for the caller's parent size, including graph instances. + pub fn output_size_px(&self, parent: [u32; 2]) -> [u32; 2] { + self.resolved_output_size(Some((parent, [0; 2])), None).0 + } + + /// The SBS size setting before applying it to a particular caller. + pub fn output_size_setting(&self) -> (crate::SizeMode, [i32; 2]) { + use crate::{GraphSizeOffset, SizeMode}; + match (self.absolute_output_size, self.relative_output_size) { + (Some(size), _) => (SizeMode::Absolute, size), + (_, Some(GraphSizeOffset::Parent(offset))) => (SizeMode::RelativeToParent, offset), + (_, Some(GraphSizeOffset::Input(offset))) => (SizeMode::RelativeToInput, offset), + _ => (SizeMode::RelativeToInput, [0; 2]), + } + } + + /// Resolve both the allocated dimensions and the portion of the requested size below one texel. + pub fn resolved_output_size(&self, parent: Option<([u32; 2], [i32; 2])>, evaluated: Option<[i32; 2]>) -> ([u32; 2], [i32; 2]) { + let (mode, literal) = self.output_size_setting(); + let size = evaluated.unwrap_or(literal); + if mode == crate::SizeMode::Absolute { + return (size.map(|side| 1 << side.clamp(0, MAX_SIZE_LOG2 as i32)), [0; 2]); + } + let (extent, underflow) = parent.unwrap_or_else(|| (self.parent_size_px(), [0; 2])); + if size == [0; 2] { + return (extent, underflow); + } + crate::offset_dimensions(extent, underflow, size) } } diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index f9ac3175..79e56c93 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -79,9 +79,9 @@ pub use pattern_node::PatternNode; pub use pattern_node_kind::PatternNodeKind; pub use pin::Pin; pub use preset::Preset; -pub use resource::Resource; +pub use resource::{PngRasterInfo, Resource, png_raster_info, png_sample_format}; pub use resource_bytes::ResourceBytes; -pub use size_mode::SizeMode; +pub use size_mode::{GraphSizeOffset, SizeMode, offset_dimensions}; pub use value::Value; pub use value_type::ValueType; diff --git a/crates/core/src/package.rs b/crates/core/src/package.rs index 4ff287f5..548be4f0 100644 --- a/crates/core/src/package.rs +++ b/crates/core/src/package.rs @@ -7,7 +7,7 @@ pub const PACKAGE_EXT: &str = "sbs"; #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] pub struct Package { pub name: String, - /// Baseline version read from SBS. Unversioned packages use the current release on first write. + /// Original SBS format header. The writer chooses its schema revision for new packages. #[serde(default, skip_serializing_if = "Option::is_none")] pub format_version: Option, pub graphs: Vec, diff --git a/crates/core/src/pattern_graph.rs b/crates/core/src/pattern_graph.rs index d1c47bce..06575976 100644 --- a/crates/core/src/pattern_graph.rs +++ b/crates/core/src/pattern_graph.rs @@ -46,6 +46,11 @@ impl PatternGraph { } pub fn validate(&self) -> Result<(), String> { + self.validated_depth().map(|_| ()) + } + + /// Validate every node and return the maximum quadrant depth connected to the root. + pub fn validated_depth(&self) -> Result { if self.nodes.len() > 4096 { return Err("pattern graph exceeds the 4096-node limit".into()); } @@ -59,11 +64,11 @@ impl PatternGraph { } let mut active = BTreeSet::new(); - let mut finished = BTreeSet::new(); + let mut depths = BTreeMap::::new(); for root in &self.nodes { let mut pending = vec![(root.id, false)]; while let Some((id, visited)) = pending.pop() { - if finished.contains(&id) { + if depths.contains_key(&id) { continue; } @@ -73,7 +78,10 @@ impl PatternGraph { } if visited { active.remove(&id); - finished.insert(id); + // Children are complete. Only a quadrant subdivides the image on its way to a child. + let step = u32::from(node.kind == PatternNodeKind::Quadrant); + let depth = node.children.iter().flatten().filter_map(|child| depths.get(child)).max().map_or(0, |d| d + step); + depths.insert(id, depth); continue; } if !active.insert(id) { @@ -84,7 +92,7 @@ impl PatternGraph { pending.extend(node.children.iter().rev().flatten().map(|child| (*child, false))); } } - Ok(()) + Ok(self.root.and_then(|id| depths.get(&id).copied()).unwrap_or(0)) } } diff --git a/crates/core/src/resource.rs b/crates/core/src/resource.rs index 2c0a6aa9..1d7875a0 100644 --- a/crates/core/src/resource.rs +++ b/crates/core/src/resource.rs @@ -1,4 +1,4 @@ -use crate::ResourceBytes; +use crate::{OutputFormat, ResourceBytes}; use serde::{Deserialize, Serialize}; /// An asset retained in memory until the package is saved: a bitmap or an SVG. @@ -32,3 +32,28 @@ impl Resource { fn default_folder() -> String { "Resources".into() } + +/// Original normalized channel precision of a grayscale or truecolor PNG resource. +/// The decoded float values alone cannot distinguish a byte from the equivalent repeated-byte word. +pub fn png_sample_format(bytes: &[u8]) -> Option { + png_raster_info(bytes).map(|info| info.format) +} + +/// Raster properties declared in the header of a normalized grayscale or truecolor PNG. +pub struct PngRasterInfo { + pub size: [u32; 2], + pub format: OutputFormat, + pub grayscale: bool, +} + +pub fn png_raster_info(bytes: &[u8]) -> Option { + let header = bytes.strip_prefix(b"\x89PNG\r\n\x1a\n\0\0\0\rIHDR")?; + let format = match header.get(8..10)? { + [8, 0 | 2 | 4 | 6] => OutputFormat::U8, + [16, 0 | 2 | 4 | 6] => OutputFormat::U16, + _ => return None, + }; + let width = u32::from_be_bytes(*header.first_chunk()?); + let height = u32::from_be_bytes(*header.get(4..)?.first_chunk()?); + Some(PngRasterInfo { size: [width, height], format, grayscale: matches!(header.get(9), Some(0 | 4)) }) +} diff --git a/crates/core/src/size_mode.rs b/crates/core/src/size_mode.rs index 792eb56c..408d1470 100644 --- a/crates/core/src/size_mode.rs +++ b/crates/core/src/size_mode.rs @@ -12,3 +12,23 @@ pub enum SizeMode { /// `offset` is the absolute log2 size (e.g. 10 = 1024 px) Absolute, } + +/// The authored base for a relative graph output size and its signed offsets in octaves. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub enum GraphSizeOffset { + Input([i32; 2]), + Parent([i32; 2]), +} + +/// Apply per-axis log2 offsets and carry requested exponents below a single texel to descendants. +pub fn offset_dimensions(parent: [u32; 2], underflow: [i32; 2], offset: [i32; 2]) -> ([u32; 2], [i32; 2]) { + let shift: [i32; 2] = std::array::from_fn(|axis| underflow[axis].saturating_add(offset[axis].clamp(-12, 13))); + + // Internal images may be one texel; the editor minimum would break size functions + let size = std::array::from_fn(|axis| (f64::from(parent[axis]) * 2f64.powi(shift[axis])).round().clamp(1.0, 8192.0) as u32); + let size_underflow = + std::array::from_fn(|axis| if parent[axis].is_power_of_two() { shift[axis].saturating_add(parent[axis].ilog2() as i32).min(0) } else { 0 }); + + (size, size_underflow) +} diff --git a/crates/core/src/value_tests.rs b/crates/core/src/value_tests.rs index 0e655809..2eb5929e 100644 --- a/crates/core/src/value_tests.rs +++ b/crates/core/src/value_tests.rs @@ -28,6 +28,13 @@ fn coerce_from_json() { assert_eq!(Value::Int(0).coerce_json(&serde_json::json!({"t": "text", "v": "x"})), None); } +#[test] +fn decimal_parameter_text_preserves_a_float_midpoint() { + let input = serde_json::from_str("[0.37710319459438324, -0.37710319459438324]").unwrap(); + let rounded = f32::from_bits(0x3ec1_13ac); + assert_eq!(Value::Float2([0.0; 2]).coerce_json(&input), Some(Value::Float2([rounded, -rounded]))); +} + #[test] fn coerce_json_int_vectors_accept_floats() { assert_eq!(Value::Int2([0; 2]).coerce_json(&serde_json::json!([3.0, 4.0])), Some(Value::Int2([3, 4]))); diff --git a/crates/engine/src/decoded_images.rs b/crates/engine/src/decoded_images.rs index c4e6e018..3cb9d65e 100644 --- a/crates/engine/src/decoded_images.rs +++ b/crates/engine/src/decoded_images.rs @@ -1,13 +1,14 @@ use std::collections::{HashMap, HashSet}; use craft_texture::Image; +use materialcraft_nodes::BitmapColorSpace; const DEFAULT_LIMIT_BYTES: usize = 128 << 20; const MAX_ENTRIES: usize = 128; /// Decoded bitmaps are expendable: resources and active cooks own their source and output data. pub(crate) struct DecodedImages { - images: HashMap<(u64, bool), (Image, u64)>, + images: HashMap<(u64, BitmapColorSpace), (Image, u64)>, bytes: usize, limit: usize, tick: u64, @@ -24,7 +25,7 @@ impl DecodedImages { Self { images: HashMap::new(), bytes: 0, limit, tick: 0 } } - pub fn get(&mut self, key: &(u64, bool)) -> Option { + pub fn get(&mut self, key: &(u64, BitmapColorSpace)) -> Option { self.tick = self.tick.saturating_add(1); self.images.get_mut(key).map(|(image, used)| { *used = self.tick; @@ -32,7 +33,7 @@ impl DecodedImages { }) } - pub fn insert(&mut self, key: (u64, bool), image: Image) { + pub fn insert(&mut self, key: (u64, BitmapColorSpace), image: Image) { if let Some((old, _)) = self.images.remove(&key) { self.bytes = self.bytes.saturating_sub(bytes(&old)); } @@ -82,16 +83,17 @@ mod tests { let mut cache = DecodedImages::new(128); let image = Image::filled(4, 4, Kind::Gray, [0.5; 4]); let weak = Arc::downgrade(image.shared_data()); - cache.insert((0, false), image); + cache.insert((0, BitmapColorSpace::Srgb), image); for key in 1..1_000 { - cache.insert((key, key % 2 == 0), Image::filled(4, 4, Kind::Gray, [0.5; 4])); + let space = if key % 2 == 0 { BitmapColorSpace::Linear } else { BitmapColorSpace::Srgb }; + cache.insert((key, space), Image::filled(4, 4, Kind::Gray, [0.5; 4])); assert!(cache.bytes <= 128); assert!(cache.images.len() <= 2); } assert!(weak.upgrade().is_none()); - assert!(cache.get(&(999, false)).is_some()); + assert!(cache.get(&(999, BitmapColorSpace::Srgb)).is_some()); cache.retain_resources(&HashSet::new()); @@ -103,21 +105,21 @@ mod tests { fn large_images_bypass_the_cache_and_recent_reads_survive_eviction() { let mut cache = DecodedImages::new(128); for key in 0..2 { - cache.insert((key, false), Image::filled(4, 4, Kind::Gray, [0.5; 4])); + cache.insert((key, BitmapColorSpace::Srgb), Image::filled(4, 4, Kind::Gray, [0.5; 4])); } - assert!(cache.get(&(0, false)).is_some()); + assert!(cache.get(&(0, BitmapColorSpace::Srgb)).is_some()); - cache.insert((2, false), Image::filled(4, 4, Kind::Gray, [0.5; 4])); + cache.insert((2, BitmapColorSpace::Srgb), Image::filled(4, 4, Kind::Gray, [0.5; 4])); - assert!(cache.get(&(1, false)).is_none()); + assert!(cache.get(&(1, BitmapColorSpace::Srgb)).is_none()); let large = Image::filled(16, 16, Kind::Gray, [0.5; 4]); let weak = Arc::downgrade(large.shared_data()); - cache.insert((3, false), large); + cache.insert((3, BitmapColorSpace::Srgb), large); assert!(weak.upgrade().is_none()); - assert!(cache.get(&(0, false)).is_some()); + assert!(cache.get(&(0, BitmapColorSpace::Srgb)).is_some()); cache.clear(); diff --git a/crates/engine/src/export_size.rs b/crates/engine/src/export_size.rs index 883d473e..5ca04629 100644 --- a/crates/engine/src/export_size.rs +++ b/crates/engine/src/export_size.rs @@ -9,14 +9,14 @@ pub enum ExportSize { } impl ExportSize { - /// The graph's log2 size at this export size: pixels round down to powers of two from 16 to 8192 + /// The graph's log2 size at this export size: pixels round down to powers of two from 1 to 8192 pub fn log2_size(self, graph_size: [u32; 2]) -> [u32; 2] { match self { ExportSize::LargerSide(pixels) => { let target = log2_pixels(pixels); let bounded = graph_size.map(|side| side.clamp(materialcraft_core::MIN_SIZE_LOG2, materialcraft_core::MAX_SIZE_LOG2)); let larger = bounded[0].max(bounded[1]); - bounded.map(|side| (side + target).saturating_sub(larger).max(materialcraft_core::MIN_SIZE_LOG2)) + bounded.map(|side| (side + target).saturating_sub(larger)) } ExportSize::Exact(pixels) => pixels.map(log2_pixels), } diff --git a/crates/engine/src/exposed_input_commands.rs b/crates/engine/src/exposed_input_commands.rs index f9bba423..194a9507 100644 --- a/crates/engine/src/exposed_input_commands.rs +++ b/crates/engine/src/exposed_input_commands.rs @@ -152,6 +152,7 @@ fn prepare_input(session: &Session, parameters: &J) -> Result<(ExposedParameter, }; let input = ExposedParameter { id: identifier.clone(), + connectable: false, label: strp(parameters, "label").unwrap_or_else(|| descriptor.as_ref().map_or(identifier.as_str(), |descriptor| descriptor.label.as_str())).into(), group: strp(parameters, "group").unwrap_or("").into(), description: strp(parameters, "description") diff --git a/crates/engine/src/file_cmds.rs b/crates/engine/src/file_cmds.rs index d1fab72c..5af83b0b 100644 --- a/crates/engine/src/file_cmds.rs +++ b/crates/engine/src/file_cmds.rs @@ -3,7 +3,7 @@ pub use crate::linked_resource::reader as linked_files; use serde_json::{Value as J, json}; -use materialcraft_core::{Package, Resource, ResourceBytes}; +use materialcraft_core::{Graph, Package, Resource, ResourceBytes}; use materialcraft_formats::{Depth, encode, output_name}; use crate::commands::{CommandSpec, always, bad, boolp, has_graph, has_package, strp, u64p}; @@ -70,9 +70,9 @@ fn new_graph(session: &mut Session, parameters: &J) -> Result { } else { TEMPLATES.iter().find(|entry| entry.0 == template_id).map_or("Graph", |entry| entry.1) }; - let width = u64p(parameters, "size").unwrap_or(1024).clamp(16, 8192); - let height = u64p(parameters, "height").unwrap_or(width).clamp(16, 8192); - let [width_log2, height_log2] = [width, height].map(|side| 63 - side.leading_zeros()); + let width = u64p(parameters, "size").unwrap_or(1024); + let height = u64p(parameters, "height").unwrap_or(width); + let [width_log2, height_log2] = [width, height].map(Graph::parent_size_log2); let base = strp(parameters, "name").map(str::to_string).unwrap_or_else(|| label.replace(' ', "_")); let folder = strp(parameters, "folder").unwrap_or(""); let in_new_package = boolp(parameters, "newPackage").unwrap_or(false); @@ -143,6 +143,7 @@ pub fn replace_package(session: &mut Session, package: Package, path: Option) -> } pub fn open_bytes_linked(session: &mut Session, bytes: &[u8], name: Option, linked: &dyn Fn(&str) -> Option>) -> Result<()> { - open_resolved(session, bytes, name, linked, crate::linked_files::load) + open_resolved(session, bytes, name, linked, Session::load_file_links) } /// Resolve every external graph and its assets through the caller's read capability. pub fn open_bytes_scoped(session: &mut Session, bytes: &[u8], path: &str, read: &dyn Fn(&str) -> Option>) -> Result<()> { let assets = |reference: &str| read(&crate::document_path::resolve(path, reference)); - open_resolved(session, bytes, Some(path.into()), &assets, |pkg| crate::linked_files::load_scoped(pkg, read)) + open_resolved(session, bytes, Some(path.into()), &assets, |_, pkg| crate::linked_files::load_scoped(pkg, read)) } fn open_resolved( @@ -192,7 +193,7 @@ fn open_resolved( bytes: &[u8], name: Option, linked: &dyn Fn(&str) -> Option>, - load: impl FnOnce(&mut Package) -> Vec, + load: impl FnOnce(&mut Session, &mut Package) -> Vec, ) -> Result<()> { let name = name.map(|path| crate::document_path::normalize(&path)); if let Some(name) = &name @@ -213,10 +214,11 @@ fn open_resolved( for (path, source) in &session.pkg.dependencies { read.pkg.dependencies.entry(path.clone()).or_insert_with(|| source.clone()); } - let link_warnings = load(&mut read.pkg); - let path = if read.warnings.is_empty() { name } else { None }; + let link_warnings = load(session, &mut read.pkg); + let (path, recovery_origin) = if read.warnings.is_empty() { (name, None) } else { (None, name) }; read.warnings.extend(link_warnings); session.open_package(read.pkg, path)?; + session.recovery_origin = recovery_origin; for warning in &read.warnings { session.warn(warning.clone()); } @@ -249,7 +251,8 @@ pub(crate) fn save_bytes_at(session: &Session, path: Option<&str>) -> Result) -> Package { @@ -261,15 +264,92 @@ fn package_for_save(session: &Session, path: Option<&str>) -> Package { } } + let in_place = session.path.as_deref().is_some_and(|current| current == path || current == crate::document_path::normalize(path)); + let mut packages = std::collections::BTreeMap::new(); for instance in package.graphs.iter_mut().flat_map(|graph| graph.instances_mut()) { - if !instance.package.is_empty() { - instance.package = crate::document_path::relative(path, &instance.package); + // Catalog links follow the selected library even when the caller is saved inside it. + if instance.package.is_empty() || (in_place && instance.package.starts_with("sbs://")) { + continue; } + let source = std::mem::take(&mut instance.package); + let reference = packages + .entry(source) + .or_insert_with_key(|source| if in_place { crate::document_path::relative(path, source) } else { package_reference(session, path, source) }); + instance.package.clone_from(reference); } } package } +fn package_reference(_session: &Session, destination: &str, source: &str) -> String { + #[cfg(not(target_arch = "wasm32"))] + { + use materialcraft_formats::sbs::library; + use std::path::Path; + + if Path::new(source).is_absolute() + && !library::contains_file(Path::new(destination)) + && let Ok(root) = library::root().canonicalize() + && let Some(uri) = verified_library_reference(_session, &root, source) + { + return uri; + } + } + crate::document_path::relative(destination, source) +} + +#[cfg(not(target_arch = "wasm32"))] +fn verified_library_reference(session: &Session, root: &std::path::Path, source: &str) -> Option { + use materialcraft_formats::sbs::library; + use std::{collections::BTreeMap, path::Path}; + + let uri = library::bundled_package_uri(root, Path::new(source))?; + let mut names = BTreeMap::from([(source.to_string(), uri.clone())]); + let mut pending = vec![source.to_string()]; + while let Some(key) = pending.pop() { + let package = session.pkg.dependencies.get(&key)?; + if package.graphs.is_empty() || !package.resources.is_empty() { + return None; + } + let package_uri = names.get(&key)?; + let mut reference = match session.library.packages.get(package_uri) { + Some(known) => (**known).clone(), + None => { + let bytes = library::read(package_uri).ok()?; + let mut read = materialcraft_formats::sbs::read_sbs(&bytes, package_uri, &linked_files(package_uri)).ok()?; + crate::linked_files::normalize_references(&mut read.pkg, package_uri); + read.pkg + } + }; + + let mut normalized = (**package).clone(); + for instance in normalized.graphs.iter_mut().flat_map(|graph| graph.instances_mut()).filter(|instance| !instance.package.is_empty()) { + if let Some(uri) = names.get(&instance.package) { + instance.package.clone_from(uri); + continue; + } + let path = if instance.package.starts_with("sbs://") { + root.join(library::relative_path(&instance.package).ok()?) + } else { + Path::new(&instance.package).to_path_buf() + }; + let child = library::bundled_package_uri(root, &path)?; + let key = std::mem::replace(&mut instance.package, child.clone()); + names.insert(key.clone(), child); + pending.push(key); + } + + // Loaded calls carry resolved argument types and bodies. Compare both copies + // against the same interfaces so that authored edits remain distinguishable. + crate::linked_packages::interfaces(&mut reference, &session.library.packages); + crate::linked_packages::interfaces(&mut normalized, &session.library.packages); + if normalized.graphs != reference.graphs { + return None; + } + } + Some(uri) +} + pub fn save_files_at(session: &Session, path: &str) -> Result { let active_package = session.package(session.document_id)?; let filename = std::path::Path::new(path).file_name().and_then(|name| name.to_str()).unwrap_or("package.sbs"); @@ -353,7 +433,7 @@ pub(crate) fn save_to_path(s: &mut Session, path: &str) -> Result { let bytes = write_package_at(s, &path)?; s.path = Some(path.clone()); - s.refresh_links(); + s.refresh_saved_links(&path); s.modified = false; Ok(json!({"path": path, "bytes": bytes})) } diff --git a/crates/engine/src/function_variables.rs b/crates/engine/src/function_variables.rs index f21989ad..07eba64f 100644 --- a/crates/engine/src/function_variables.rs +++ b/crates/engine/src/function_variables.rs @@ -8,10 +8,12 @@ use crate::{FunctionGraphTarget, FunctionVariable, Result, Session, commands::ba fn variable_scope(target: &FunctionGraphTarget, session: &Session) -> FunctionScope { match target { FunctionGraphTarget::Pattern { .. } => FunctionScope::FxMap, - FunctionGraphTarget::Parameter { node, parameter } - if parameter == "function" && session.graph().ok().and_then(|graph| graph.node(*node).ok()).is_some_and(|node| node.def == "pixel_processor") => - { - FunctionScope::PixelProcessor + FunctionGraphTarget::Parameter { node, parameter } if parameter == "function" => { + match session.graph().ok().and_then(|graph| graph.node(*node).ok()).map(|node| node.def.as_str()) { + Some("pixel_processor") => FunctionScope::PixelProcessor, + Some("value_processor") => FunctionScope::ValueProcessor, + _ => FunctionScope::Node, + } } _ => FunctionScope::Node, } diff --git a/crates/engine/src/graph_cmds.rs b/crates/engine/src/graph_cmds.rs index b6751f3a..8e7592d6 100644 --- a/crates/engine/src/graph_cmds.rs +++ b/crates/engine/src/graph_cmds.rs @@ -2,7 +2,7 @@ use serde_json::{Value as J, json}; -use materialcraft_core::{Graph, MAX_SIZE_LOG2, MIN_SIZE_LOG2, NodeId, OutputFormat, Value}; +use materialcraft_core::{Graph, MAX_SIZE_LOG2, NodeId, OutputFormat, Value}; use crate::commands::{CommandSpec, always, bad, boolp, has_graph, has_selection, i64p, ids_param, strp, u64p}; use crate::{Result, Session, cmd}; @@ -12,15 +12,16 @@ pub(crate) fn specs() -> Vec { cmd!("graph.open", "Open graph", [], None, "{graph: index or name}", always, open), cmd!("graph.delete", "Delete graph", [], None, "{graph?}", has_graph, delete), cmd!("graph.duplicate", "Duplicate graph", [], None, "{graph?}", has_graph, duplicate), - cmd!("graph.size", "Graph size", [], None, "{graph?, document?, width, height} in pixels (powers of two, 16..8192) or {log2: [w, h]}", always, size), - cmd!("graph.seed", "Random seed", [], None, "{seed, graph?, document?}", always, |s, p| { - let seed = i64p(p, "seed").ok_or_else(|| bad("graph.seed", "`seed` is required"))?.clamp(0, i32::MAX as i64) as i32; - let target = crate::GraphTarget::resolve(s, p)?; - target.edit_merged(s, &format!("graph.seed:{}:{}", target.document, target.graph), "Random seed", |package| { - package.graph_mut(target.graph)?.seed = seed; - Ok(J::Null) - }) - }), + cmd!( + "graph.size", + "Graph size", + [], + None, + "{graph?, document?, width, height} in pixels (rounded up to powers of two, 1..8192) or {log2: [w, h]}", + always, + size + ), + cmd!("graph.seed", "Random seed", [], None, "{seed?, inheritance?: absolute|relativeToParent|relativeToInput, graph?, document?}", always, seed), cmd!("graph.format", "Output format", [], None, "{format: u8|u16|f16|f32, graph?, document?}", always, format), cmd!( "graph.cook", @@ -73,6 +74,33 @@ pub(crate) fn graph_index(s: &Session, p: &J) -> Result { } } +fn seed(session: &mut Session, parameters: &J) -> Result { + let command = "graph.seed"; + let seed = parameters + .get("seed") + .map(|_| i64p(parameters, "seed").map(|n| n.clamp(0, i64::from(i32::MAX)) as i32).ok_or_else(|| bad(command, "expected an integer seed"))) + .transpose()?; + let mode = parameters + .get("inheritance") + .map(|v| serde_json::from_value(v.clone()).map_err(|error| bad(command, format!("invalid inheritance: {error}")))) + .transpose()?; + if seed.is_none() && mode.is_none() { + return Err(bad(command, "a seed or inheritance mode is required")); + } + let target = crate::GraphTarget::resolve(session, parameters)?; + target.edit_merged(session, &format!("graph.seed:{}:{}", target.document, target.graph), "Random seed", |package| { + let graph = package.graph_mut(target.graph)?; + if let Some(seed) = seed { + graph.seed = seed; + graph.seed_function = None; + } + if let Some(mode) = mode { + graph.seed_mode = mode; + } + Ok(J::Null) + }) +} + fn open(s: &mut Session, p: &J) -> Result { let i = graph_index(s, p)?; s.graph = i; @@ -120,15 +148,14 @@ fn duplicate(s: &mut Session, p: &J) -> Result { fn size(s: &mut Session, p: &J) -> Result { let target = crate::GraphTarget::resolve(s, p)?; - let log = |px: u64| 63 - px.clamp(1, 1 << 20).leading_zeros(); let (w, h) = if let Some(a) = p.get("log2").and_then(J::as_array) { - (a.first().and_then(J::as_u64).unwrap_or(10) as u32, a.get(1).and_then(J::as_u64).unwrap_or(10) as u32) + let exponent = |axis: usize| a.get(axis).and_then(J::as_u64).unwrap_or(10).min(u64::from(MAX_SIZE_LOG2)) as u32; + (exponent(0), exponent(1)) } else { let w = u64p(p, "width").ok_or_else(|| bad("graph.size", "`width` is required"))?; - (log(w), log(u64p(p, "height").unwrap_or(w))) + (Graph::parent_size_log2(w), Graph::parent_size_log2(u64p(p, "height").unwrap_or(w))) }; - let (w, h) = (w.clamp(MIN_SIZE_LOG2, MAX_SIZE_LOG2), h.clamp(MIN_SIZE_LOG2, MAX_SIZE_LOG2)); target.edit(s, "Graph size", |package| { package.graph_mut(target.graph)?.size = [w, h]; Ok(json!({"width": 1u32 << w, "height": 1u32 << h})) @@ -294,6 +321,7 @@ fn from_selection(s: &mut Session, p: &J) -> Result { let mut sub = materialcraft_core::Graph::new(&name); sub.size = src.size; sub.seed = src.seed; + sub.format = OutputFormat::Inherit; sub.next_id = src.next_id; sub.nodes = src.nodes.iter().filter(|n| ids.contains(&n.id)).cloned().collect(); sub.connections = src.connections.iter().filter(|c| ids.contains(&c.from) && ids.contains(&c.to)).cloned().collect(); @@ -328,7 +356,11 @@ fn from_selection(s: &mut Session, p: &J) -> Result { let g = s.graph_mut()?; g.remove_nodes(&ids); let inst = g.add_node("graph_instance", [rect[0], rect[1]]); - g.node_mut(inst)?.params.insert("graph".into(), Value::Text(name.clone())); + let instance = g.node_mut(inst)?; + // The extracted graph keeps the source seed for a standalone preview. Cancel + // that offset here so later parent seed edits still reach its original nodes. + instance.base.seed = src.seed.wrapping_neg(); + instance.params.insert("graph".into(), Value::Text(name.clone())); for (from, port, ident) in inputs { g.connect(from, &port, inst, &ident)?; } diff --git a/crates/engine/src/graph_pixels.rs b/crates/engine/src/graph_pixels.rs new file mode 100644 index 00000000..a2f54c4b --- /dev/null +++ b/crates/engine/src/graph_pixels.rs @@ -0,0 +1,29 @@ +//! Display levels of cooked graph images and node thumbnails. + +use crate::image::{Image, linear_to_srgb}; + +/// Quantize a stored channel, including alpha, to its displayed byte. +pub fn stored_byte(value: f32) -> u8 { + (value.clamp(0.0, 1.0) * 255.0 + 0.5) as u8 +} + +/// Interpret a graph channel as sRGB or linear light before displaying it. +pub fn display_byte(value: f32, srgb: bool) -> u8 { + stored_byte(if srgb { value } else { linear_to_srgb(value) }) +} + +/// Expand the stored graph pixels into display RGBA, preserving alpha. +pub fn rgba8(image: &Image, srgb: bool) -> Vec { + let mut pixels = Vec::with_capacity(image.data().len() / image.channels() * 4); + if let Some(gray) = image.gray_data() { + for &value in gray { + let level = display_byte(value, srgb); + pixels.extend_from_slice(&[level, level, level, 255]); + } + } else { + for &[r, g, b, a] in image.data().as_chunks::<4>().0 { + pixels.extend_from_slice(&[display_byte(r, srgb), display_byte(g, srgb), display_byte(b, srgb), stored_byte(a)]); + } + } + pixels +} diff --git a/crates/engine/src/inspect.rs b/crates/engine/src/inspect.rs index 12bcf3a7..ba2ae4d4 100644 --- a/crates/engine/src/inspect.rs +++ b/crates/engine/src/inspect.rs @@ -19,12 +19,14 @@ pub fn session(session: &Session, requested_graph: Option) -> J { "size": graph.size_px(), "format": graph.format, "seed": graph.seed, + "seedMode": graph.seed_mode, "attributes": graph.attributes, "exposed": graph.exposed, "presets": graph.presets, "inputs": graph.inputs, "inputImages": graph.input_images, "inputImagesLinear": graph.input_images_linear, + "inputImagesFromFile": graph.input_images_from_file, "nodes": graph.nodes.iter().map(|node| { let entry = cooked.and_then(|cooked| cooked.nodes.get(&node.id)); let (inputs, outputs) = materialcraft_eval::ports(&session.pkg, graph, node); @@ -59,6 +61,21 @@ pub fn session(session: &Session, requested_graph: Option) -> J { "pins": graph.pins, }); result["physicalSize"] = json!(graph.physical_size); + if let Some(function) = &graph.output_size_function { + result["outputSizeFunction"] = json!(function); + match materialcraft_eval::graph_output_size(graph, session.environment) { + Ok(size) => result["size"] = json!(size), + Err(error) => result["sizeError"] = json!(error), + } + } + if graph.absolute_output_size.is_some() || graph.relative_output_size.is_some() || graph.output_size_function.is_some() { + let (mode, value) = graph.output_size_setting(); + result["outputSizeMode"] = json!(mode); + result["outputSizeValue"] = json!(value); + } + if let Some(function) = &graph.seed_function { + result["seedFunction"] = json!(function); + } result["pixelRatio"] = json!(graph.pixel_ratio); result["pixelRatioMode"] = json!(graph.pixel_ratio_mode); result["tiling"] = json!(graph.tiling); diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 5663974b..e9265fc2 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -69,6 +69,7 @@ pub use history_prefs::HistoryPrefs; pub use library_cache_prefs::LibraryCachePrefs; pub mod graph_edit; pub mod graph_grid; +pub mod graph_pixels; pub mod inspect; pub mod material_bake; pub mod material_cmds; diff --git a/crates/engine/src/linked_files.rs b/crates/engine/src/linked_files.rs index 957e927b..61d5a536 100644 --- a/crates/engine/src/linked_files.rs +++ b/crates/engine/src/linked_files.rs @@ -1,5 +1,6 @@ use crate::document_path; use materialcraft_core::Package; +use std::{collections::BTreeSet, sync::Arc}; pub(crate) fn normalize_references(package: &mut Package, path: &str) { for resource in &mut package.resources { @@ -16,6 +17,60 @@ pub(crate) fn normalize_references(package: &mut Package, path: &str) { } impl crate::Session { + pub(crate) fn load_file_links(&mut self, package: &mut Package) -> Vec { + for (path, source) in &self.pkg.dependencies { + package.dependencies.entry(path.clone()).or_insert_with(|| source.clone()); + } + let pending = references(package); + self.load_sources(package, pending) + } + + fn load_sources(&mut self, package: &mut Package, pending: Vec) -> Vec { + read_references(package, pending, |uri, source| { + // Only aliases actually read from the catalog are owned by it. A caller can supply its own snapshot. + self.library_sources.insert(uri.to_owned(), Arc::clone(source)); + }) + } + + #[cfg(not(target_arch = "wasm32"))] + pub(crate) fn refresh_saved_links(&mut self, path: &str) { + use materialcraft_formats::sbs::library; + use std::path::Path; + + let file = Path::new(path); + let mut changed = BTreeSet::new(); + if let Ok(root) = library::root().canonicalize() + && file.starts_with(&root) + { + // The saved path is canonical. The same file may also be reached through a library symlink. + let aliases: Vec<_> = self + .library_sources + .iter() + .filter_map(|(uri, owned)| { + let relative = library::relative_path(uri).ok()?; + (self.linked_sources.get(uri).is_some_and(|source| Arc::ptr_eq(source, owned)) + && root.join(relative).canonicalize().ok()?.as_path() == file) + .then(|| uri.clone()) + }) + .collect(); + if !aliases.is_empty() { + let mut registry = Package { dependencies: self.linked_sources.clone(), ..Default::default() }; + for uri in &aliases { + registry.dependencies.remove(uri); + } + // Read the saved bytes in each alias's own directory so nested links and resources keep their base. + for warning in self.load_sources(&mut registry, aliases.clone()) { + self.warn(warning); + } + changed.extend( + aliases.into_iter().filter(|uri| registry.dependencies.get(uri).is_some_and(|source| self.linked_sources.get(uri) != Some(source))), + ); + self.linked_sources.extend(registry.dependencies); + } + } + self.refresh_links_from(changed); + } + pub(crate) fn discard_source_changes(&mut self, path: &str) { self.linked_sources.remove(path); self.pkg.dependencies.remove(path); @@ -30,21 +85,18 @@ impl crate::Session { // Include inactive dependents so closing a source also refreshes their references package.graphs.extend(self.documents.values().flat_map(|document| document.pkg.graphs.iter().cloned())); package.dependencies = self.linked_sources.clone(); - for warning in load(&mut package) { + let pending = references(&package); + for warning in self.load_sources(&mut package, pending) { self.warn(warning); } self.linked_sources.extend(package.dependencies); } - self.refresh_links_from(std::collections::BTreeSet::from([path.to_string()])); + self.refresh_links_from(BTreeSet::from([path.to_string()])); } } -pub(crate) fn load(package: &mut Package) -> Vec { - load_references(package, references(package)) -} - fn references(package: &Package) -> Vec { package.graphs.iter().flat_map(|graph| graph.instances()).filter(|instance| !instance.package.is_empty()).map(|instance| instance.package.clone()).collect() } @@ -81,9 +133,20 @@ fn load_file(path: &str) -> Result const MAX_DEPENDENCY_READS: usize = 4096; -fn resolve(package: &mut Package, mut pending: Vec, read: &dyn Fn(&str) -> Result) -> Vec { - use std::{collections::BTreeSet, sync::Arc}; +fn resolve(package: &mut Package, pending: Vec, read: &dyn Fn(&str) -> Result) -> Vec { + resolve_with_catalog(package, pending, read, |_, _| {}) +} +fn read_references(package: &mut Package, pending: Vec, catalog_read: impl FnMut(&str, &Arc)) -> Vec { + resolve_with_catalog(package, pending, &load_file, catalog_read) +} + +fn resolve_with_catalog( + package: &mut Package, + mut pending: Vec, + read: &dyn Fn(&str) -> Result, + mut catalog_read: impl FnMut(&str, &Arc), +) -> Vec { let mut visited = BTreeSet::new(); let mut warnings = Vec::new(); let mut read_attempts = 0; @@ -112,7 +175,11 @@ fn resolve(package: &mut Package, mut pending: Vec, read: &dyn Fn(&str) package.dependencies.entry(name.clone()).or_insert_with(|| dependency.clone()); } pending.extend(references(&source)); - package.dependencies.insert(path, Arc::new(source)); + let source = Arc::new(source); + if path.starts_with("sbs://") { + catalog_read(&path, &source); + } + package.dependencies.insert(path, source); } Err(error) => warnings.push(format!("Could not resolve {path}: {error}")), } diff --git a/crates/engine/src/linked_packages.rs b/crates/engine/src/linked_packages.rs index b0212c7b..bf0c4700 100644 --- a/crates/engine/src/linked_packages.rs +++ b/crates/engine/src/linked_packages.rs @@ -29,7 +29,7 @@ fn reaches(package: &Package, changed: &BTreeSet, sources: &BTreeMap>) -> bool { +pub(crate) fn interfaces(package: &mut Package, sources: &BTreeMap>) -> bool { let updates: Vec<_> = package .graphs .iter() diff --git a/crates/engine/src/material_cmds.rs b/crates/engine/src/material_cmds.rs index ec031d66..a28383e3 100644 --- a/crates/engine/src/material_cmds.rs +++ b/crates/engine/src/material_cmds.rs @@ -31,7 +31,7 @@ pub(crate) fn specs() -> Vec { "Set input preview image", [], None, - "{identifier, resource? | path?, linear?} shows a bitmap resource (or an image file, embedded) on the graph's input node `identifier`, e.g. a mesh map baked in TextureCraft", + "{identifier, resource? | path?, linear?} shows a bitmap on the graph's input node using its file color interpretation. Set linear to true for data or false for sRGB", has_graph, bind ), @@ -136,13 +136,18 @@ fn bind(s: &mut Session, p: &J) -> Result { Some((name, bytes)) => crate::file_cmds::push_resource(&mut s.pkg, &name, bytes, Some(&id)), None => strp(p, "resource").unwrap_or_default().to_string(), }; - let linear = p.get("linear").and_then(J::as_bool).unwrap_or(false); let g = s.graph_mut()?; g.input_images.insert(id.clone(), res.clone()); - if linear { - g.input_images_linear.insert(id.clone()); - } else { - g.input_images_linear.remove(&id); + g.input_images_linear.remove(&id); + g.input_images_from_file.remove(&id); + match p.get("linear") { + None => { + g.input_images_from_file.insert(id.clone()); + } + Some(J::Bool(true)) => { + g.input_images_linear.insert(id.clone()); + } + _ => {} } Ok(json!({"identifier": id, "resource": res})) }) @@ -164,8 +169,10 @@ fn read_image_file(cmd: &str, _: &str) -> Result<(String, Vec)> { fn unbind(s: &mut Session, p: &J) -> Result { let id = strp(p, "identifier").ok_or_else(|| bad("graph.input.unbind", "`identifier` is required"))?.to_string(); s.edit("Clear input preview image", |s| { - s.graph_mut()?.input_images_linear.remove(&id); - Ok(J::Bool(s.graph_mut()?.input_images.remove(&id).is_some())) + let graph = s.graph_mut()?; + graph.input_images_linear.remove(&id); + graph.input_images_from_file.remove(&id); + Ok(J::Bool(graph.input_images.remove(&id).is_some())) }) } diff --git a/crates/engine/src/material_cmds.test.rs b/crates/engine/src/material_cmds.test.rs index 5f27fc15..455f4900 100644 --- a/crates/engine/src/material_cmds.test.rs +++ b/crates/engine/src/material_cmds.test.rs @@ -435,6 +435,55 @@ fn published_disabled_and_typed_instance_cooks_match_source() { assert!((restored[0] - 0.2).abs() < 0.01, "disabled levels must preserve its input: {restored:?}"); } +#[test] +fn rebinding_the_same_file_preserves_its_authored_color_interpretation() { + let mut session = fixture(); + let bytes = encode(&Image::filled(16, 16, Kind::Color, [0.5, 0.5, 0.5, 1.0]), "png", Depth::U8, true).unwrap(); + session.pkg.resources.push(Resource::new("bound_input", "input.png", ResourceBytes::new(bytes.clone()))); + let graph = session.graph_mut().unwrap(); + graph.input_images.insert("curvature".into(), "bound_input".into()); + graph.input_images_from_file.insert("curvature".into()); + let output = graph.nodes.iter().find(|node| node.def == "output" && materialcraft_eval::identifier(node) == "mesh").unwrap().id; + let original = MaterialOptions::default().cook(&session, session.graph, None, Some(16)).unwrap(); + let options = MaterialOptions::from_params(session.graph().unwrap(), &json!({"inputs":{"curvature":"replacement.png"}}), |_| Ok(bytes.clone())).unwrap(); + let rebound = options.cook(&session, session.graph, None, Some(16)).unwrap(); + let expected = original.image(output, 0).unwrap(); + assert!(expected.get(0, 0, false)[0] > 0.4, "the authored file is linear"); + assert_eq!(rebound.image(output, 0).unwrap().data(), expected.data()); +} + +#[test] +fn material_resize_uses_overridden_size_expression_without_editing_the_document() { + use materialcraft_core::{ExposedParameter, FunctionGraph, ValueType}; + + let mut session = fixture(); + let graph = session.graph_mut().unwrap(); + graph.exposed.push(ExposedParameter { + id: "axes".into(), + label: "Axes".into(), + default: Value::Int2([4, 5]), + connectable: false, + min: 0.0, + max: 13.0, + clamp: false, + step: None, + editor: None, + description: String::new(), + group: String::new(), + options: Vec::new(), + }); + graph.absolute_output_size = Some([4, 5]); + graph.output_size_function = Some(FunctionGraph::input("axes", ValueType::Integer2)); + let before = session.pkg.clone(); + let options = + MaterialOptions { size: Some(crate::ExportSize::LargerSide(64)), values: [("axes".into(), Value::Int2([6, 4]))].into(), ..Default::default() }; + let cooked = options.cook(&session, session.graph, None, None).unwrap(); + let output = session.graph().unwrap().nodes.iter().find(|node| node.def == "output").unwrap(); + let image = cooked.image(output.id, 0).unwrap(); + assert_eq!((image.width(), image.height()), (64, 16), "resize must preserve the overridden aspect ratio"); + assert_eq!(session.pkg, before); +} + #[test] fn material_options_ignore_stale_presets_but_validate_explicit_values() { let mut session = fixture(); diff --git a/crates/engine/src/material_options.rs b/crates/engine/src/material_options.rs index 1b3d8c4c..896121df 100644 --- a/crates/engine/src/material_options.rs +++ b/crates/engine/src/material_options.rs @@ -1,6 +1,7 @@ use craft_texture::Image; -use materialcraft_core::{BaseParameter, Graph, SizeMode, Value}; +use materialcraft_core::{BaseParameter, Graph, OutputFormat, SizeMode, Value}; use materialcraft_eval::{Cooked, Options}; +use materialcraft_nodes::BitmapColorSpace; use serde_json::Value as J; use std::{borrow::Cow, collections::BTreeMap}; @@ -13,6 +14,8 @@ pub struct MaterialOptions { pub size: Option, pub values: BTreeMap, pub inputs: BTreeMap, + /// Known sample depth of each bound file before decoding to linear floats. + pub input_formats: BTreeMap, } impl MaterialOptions { @@ -46,14 +49,26 @@ impl MaterialOptions { let mut remaining = MAX_DECODED_INPUT_BYTES; for (id, path) in value.as_object().ok_or_else(|| invalid("inputs must map image identifiers to file paths".into()))? { let input = declared.iter().find(|input| input.identifier == *id).ok_or_else(|| invalid(format!("unknown image input `{id}`")))?; - let linear = if graph.input_images.contains_key(id) { - graph.input_images_linear.contains(id) + let space = if graph.input_images.contains_key(id) { + if graph.input_images_from_file.contains(id) { + BitmapColorSpace::FromFile + } else if graph.input_images_linear.contains(id) { + BitmapColorSpace::Linear + } else { + BitmapColorSpace::Srgb + } } else { let usage = if input.usage == "any" { id } else { &input.usage }; - !materialcraft_formats::material::srgb_usage(usage) + if materialcraft_formats::material::srgb_usage(usage) { BitmapColorSpace::Srgb } else { BitmapColorSpace::Linear } }; let path = path.as_str().ok_or_else(|| invalid(format!("inputs.{id} must be an image path")))?; - let image = materialcraft_formats::decode(&read(path)?, linear)?; + let bytes = read(path)?; + let image = materialcraft_formats::decode_with_color_space(&bytes, space)?; + if image.integer_sampling() + && let Some(format) = materialcraft_core::png_sample_format(&bytes) + { + options.input_formats.insert(id.clone(), format); + } remaining = remaining.checked_sub(std::mem::size_of_val(image.data())).ok_or_else(|| invalid("decoded image inputs exceed 1 GiB".into()))?; options.inputs.insert(id.clone(), image); } @@ -74,7 +89,18 @@ impl MaterialOptions { let mut package = Cow::Borrowed(&session.pkg); if let Some(size) = self.size { let graph = package.to_mut().graph_mut(index)?; - graph.size = size.log2_size(graph.size); + let basis = match size { + ExportSize::LargerSide(_) => { + // Size expressions must see the same exposed values as the export cook. + graph.inputs.extend(self.values.clone()); + materialcraft_eval::graph_output_size(graph, session.environment).map_err(|error| bad("material.cook", error))?.map(u32::ilog2) + } + ExportSize::Exact(_) => graph.size, + }; + graph.size = size.log2_size(basis); + graph.output_size_function = None; + graph.absolute_output_size = None; + graph.relative_output_size = None; // Fixed-size generators keep their native detail while final output bridges resample to the requested size for output in graph.nodes.iter_mut().filter(|node| node.def == "output") { @@ -90,6 +116,7 @@ impl MaterialOptions { options.max_size = max_size; options.only = Some(roots); options.inputs.clone_from(&self.inputs); + options.bitmap_formats.clone_from(&self.input_formats); options.overrides.clone_from(&self.values); let cooked = materialcraft_eval::cook(&package, index, &options, &session.cache); diff --git a/crates/engine/src/open_document.rs b/crates/engine/src/open_document.rs index 868ca824..db28fcef 100644 --- a/crates/engine/src/open_document.rs +++ b/crates/engine/src/open_document.rs @@ -6,6 +6,7 @@ pub struct OpenDocument { pub id: u64, pub pkg: Package, pub path: Option, + recovery_origin: Option, pub graph: usize, pub modified: bool, selection: Vec, @@ -90,6 +91,7 @@ impl OpenDocument { material_preview: if show_outputs { MaterialPreview::for_graph(&pkg, 0) } else { MaterialPreview::default() }, pkg, path, + recovery_origin: None, graph: 0, modified: false, selection: Vec::new(), @@ -115,6 +117,7 @@ impl OpenDocument { exchange!( pkg, path, + recovery_origin, graph, modified, selection, diff --git a/crates/engine/src/package_file_commands.rs b/crates/engine/src/package_file_commands.rs index 39e92dd3..e7323288 100644 --- a/crates/engine/src/package_file_commands.rs +++ b/crates/engine/src/package_file_commands.rs @@ -36,11 +36,8 @@ fn reload(session: &mut Session, parameters: &Value) -> Result { let bytes = read_package(&path)?; let linked = crate::file_cmds::linked_files(&path); let mut read = crate::file_cmds::read_package_bytes(&bytes, &path, &linked)?; - for (path, source) in &session.pkg.dependencies { - read.pkg.dependencies.entry(path.clone()).or_insert_with(|| source.clone()); - } let safe_path = read.warnings.is_empty().then_some(path.clone()); - read.warnings.extend(crate::linked_files::load(&mut read.pkg)); + read.warnings.extend(session.load_file_links(&mut read.pkg)); crate::file_cmds::replace_package(session, read.pkg, safe_path); session.load_warnings = read.warnings; diff --git a/crates/engine/src/preview_cook.rs b/crates/engine/src/preview_cook.rs index 1a225f29..101d6e4b 100644 --- a/crates/engine/src/preview_cook.rs +++ b/crates/engine/src/preview_cook.rs @@ -2,7 +2,7 @@ use std::collections::{BTreeMap, BTreeSet}; use std::sync::{Arc, Mutex}; use materialcraft_core::Package; -use materialcraft_eval::{Cache, Cooked, Options}; +use materialcraft_eval::{Cache, Cooked, Options, PreviewSampling}; /// One background result for the editor and the assigned material sources #[derive(Default)] @@ -14,13 +14,34 @@ pub struct PreviewCook { impl PreviewCook { pub fn run(package: &Package, graph: usize, materials: &BTreeSet, options: &Options<'_>, cache: &Arc>) -> Self { - let mut result = Self { graph, cooked: materialcraft_eval::cook(package, graph, options, cache), materials: BTreeMap::new() }; + Self::with_previous(package, graph, materials, options, cache, &BTreeMap::new()) + } + + pub fn with_previous( + package: &Package, + graph: usize, + materials: &BTreeSet, + options: &Options<'_>, + cache: &Arc>, + previous: &BTreeMap>, + ) -> Self { + let empty = PreviewSampling::default(); + let cook = |index| { + let mut options = options.clone(); + options.previous_sampling = Some(previous.get(&index).map_or(&empty, Arc::as_ref)); + let mut cooked = materialcraft_eval::cook(package, index, &options, cache); + if cooked.nodes.values().any(|node| node.error.is_some()) { + cooked.preview_sampling = previous.get(&index).cloned(); + } + cooked + }; + let mut result = Self { graph, cooked: cook(graph), materials: BTreeMap::new() }; for &index in materials { if result.cancelled() { break; } if index != graph && package.graphs.get(index).is_some() { - result.materials.insert(index, materialcraft_eval::cook(package, index, options, cache)); + result.materials.insert(index, cook(index)); } } result diff --git a/crates/engine/src/session.rs b/crates/engine/src/session.rs index 64c8f51d..2dc78fb2 100644 --- a/crates/engine/src/session.rs +++ b/crates/engine/src/session.rs @@ -1,6 +1,7 @@ //! The session: the open package, the graph being edited, selection, views, snapshot undo and //! the cook cache. +use std::collections::BTreeMap; use std::sync::{Arc, Mutex, PoisonError}; use craft_texture::Image; @@ -59,6 +60,8 @@ pub struct Session { pub pkg: Package, /// Where the package was opened from or last saved to. pub path: Option, + /// Original link base when import warnings require a new save destination. + pub(crate) recovery_origin: Option, /// Index of the graph being edited. pub graph: usize, pub selection: Vec, @@ -138,6 +141,7 @@ impl Session { material_cooked: std::collections::BTreeMap::new(), pkg, path: None, + recovery_origin: None, graph: 0, selection: Vec::new(), annotation_selection: None, @@ -251,6 +255,7 @@ impl Session { if let Some((snap, edited)) = self.group.take() && edited { + self.reset_changed_sampling(&snap.pkg); self.history.record(snap, None, self.history_prefs.undo_limit as usize); self.refresh_links(); } @@ -295,6 +300,7 @@ impl Session { if let Some((_, edited)) = self.group.as_mut() { *edited = true; } else { + self.reset_changed_sampling(&snapshot.pkg); self.history.record(snapshot, key, self.history_prefs.undo_limit as usize); } self.changed(); @@ -353,6 +359,7 @@ impl Session { let s = self.history.undo(self.snapshot(""), self.history_prefs.undo_limit as usize)?; let label = s.label.clone(); + self.reset_changed_sampling(&s.pkg); self.restore(s); self.finish_edit(); self.dirty = true; @@ -368,6 +375,7 @@ impl Session { let s = self.history.redo(self.snapshot(""), self.history_prefs.undo_limit as usize)?; let label = s.label.clone(); + self.reset_changed_sampling(&s.pkg); self.restore(s); self.finish_edit(); self.dirty = true; @@ -396,14 +404,14 @@ impl Session { let hashes = resources.iter().map(|(_, bytes)| bytes.content_hash()).collect(); decoded.lock().unwrap_or_else(PoisonError::into_inner).retain_resources(&hashes); move |requested: &str| { - let (name, linear) = craft_texture::split_resource_key(requested); + let (name, space) = materialcraft_nodes::BitmapColorSpace::split_resource_key(requested); let (_, bytes) = resources.iter().find(|(name_candidate, _)| name_candidate == name)?; - let key = (bytes.content_hash(), linear); + let key = (bytes.content_hash(), space); if let Some(image) = decoded.lock().unwrap_or_else(PoisonError::into_inner).get(&key) { return Some(image); } - let image = materialcraft_formats::decode(bytes.as_slice(), linear).ok()?; + let image = materialcraft_formats::decode_with_color_space(bytes.as_slice(), space).ok()?; decoded.lock().unwrap_or_else(PoisonError::into_inner).insert(key, image.clone()); Some(image) } @@ -420,13 +428,40 @@ impl Session { self.decoded = Arc::new(Mutex::new(crate::decoded_images::DecodedImages::new(16 << 20))); } + // An extent or seed edit releases acquired input textures even if another edit restores + // the original value before the next preview. A grouped edit publishes only once. + fn reset_changed_sampling(&mut self, other: &Package) { + let context = |package: &Package, index: usize| package.graphs.get(index).map(|g| (g.size, g.seed, g.seed_mode)); + let reset = |index, cooked: &mut Cooked| { + if cooked.preview_sampling.is_some() && context(&self.pkg, index) != context(other, index) { + cooked.preview_sampling = None; + } + }; + if let Some(index) = self.cooked_graph { + reset(index, &mut self.cooked); + } + for (&index, cooked) in &mut self.material_cooked { + reset(index, cooked); + } + } + + /// Take the sampling history from published graph previews before starting another cook. + pub fn preview_sampling(&self) -> BTreeMap> { + self.cooked_graph + .into_iter() + .map(|graph| (graph, &self.cooked)) + .chain(self.material_cooked.iter().map(|(&graph, cooked)| (graph, cooked))) + .filter_map(|(graph, cooked)| cooked.preview_sampling.clone().map(|sampling| (graph, sampling))) + .collect() + } + /// Cook the open graph now (at the preview size), on this thread. pub fn cook(&mut self) -> &Cooked { let dec = self.resource_decoder(); let mut opts = Options::new(&dec); opts.environment = self.environment; opts.max_size = self.preview_size; - let cooked = crate::PreviewCook::run(&self.pkg, self.graph, &self.material_preview.graphs(), &opts, &self.cache); + let cooked = crate::PreviewCook::with_previous(&self.pkg, self.graph, &self.material_preview.graphs(), &opts, &self.cache, &self.preview_sampling()); self.accept_preview(cooked); self.dirty = false; self.cook_epoch = self.cook_epoch.wrapping_add(1); diff --git a/crates/engine/src/session.test.rs b/crates/engine/src/session.test.rs index e854e088..6f99da45 100644 --- a/crates/engine/src/session.test.rs +++ b/crates/engine/src/session.test.rs @@ -23,6 +23,161 @@ fn the_resource_decoder_reads_data_maps_as_stored() { assert!((data.get(0, 0, false)[2] - 1.0).abs() < 0.01); } +fn stamp_package() -> (Package, materialcraft_core::NodeId, [materialcraft_core::NodeId; 2]) { + use materialcraft_core::{Graph, OutputFormat, PatternGraph, PatternNodeKind, ResourceBytes, SizeMode, Value}; + + let image = Image::gray(128, 128, |x, y| ((13 * x + 7 * y + 3 * x * y) % 253) as f32 / 255.0); + let bytes = ResourceBytes::new(encode(&image, "png", Depth::U8, false).unwrap()); + let mut package = Package::new("Stamp sampling"); + for name in ["Field", "Copy"] { + package.resources.push(Resource::new(name, format!("{name}.png"), bytes.clone())); + } + let mut graph = Graph::new("Shared image"); + graph.size = [5; 2]; + graph.format = OutputFormat::F32; + let input = graph.add_node("input_grayscale", [0.0; 2]); + let base = &mut graph.node_mut(input).unwrap().base; + base.size_mode = SizeMode::Absolute; + base.size = [5; 2]; + base.format = OutputFormat::U8; + graph.input_images.insert("input".into(), "Field".into()); + graph.input_images_linear.insert("input".into()); + let stamps = [0.0, 80.0].map(|y| { + let id = graph.add_node("fx_map", [100.0, y]); + let mut pattern = PatternGraph::with_root(PatternNodeKind::Quadrant); + pattern.nodes[0].parameters.insert("patterntype".into(), Value::Int(1)); + pattern.nodes[0].parameters.insert("patternsize".into(), Value::Float2([0.5; 2])); + let node = graph.node_mut(id).unwrap(); + node.base.format = OutputFormat::F32; + node.params.insert("color_mode".into(), Value::Bool(false)); + node.params.insert("roughness".into(), Value::Float(0.0)); + node.params.insert("pattern".into(), Value::PatternGraph(Box::new(pattern))); + graph.connect(input, "output", id, "pattern0").unwrap(); + id + }); + package.graphs.push(graph); + (package, input, stamps) +} + +#[test] +fn preview_stamps_reuse_sampling_levels_independently() { + let (package, _, stamps) = stamp_package(); + let mut session = Session::new(package); + let base = 0x3f01_4181; + let mip = 0x3f01_8182; + let pixels = |cook: &materialcraft_eval::Cooked| { + stamps.map(|id| { + assert_eq!(cook.nodes[&id].error, None); + cook.image(id, 0).unwrap().get_gray(9, 8, false).to_bits() + }) + }; + assert_eq!(pixels(session.cook()), [base; 2]); + let change_precision = |session: &mut Session| { + for format in ["u16", "f32"] { + crate::execute(session, "graph.node.base", &serde_json::json!({"id":stamps[0].0,"format":format})).unwrap(); + session.cook(); + } + }; + change_precision(&mut session); + assert_eq!(pixels(session.cook()), [mip, base], "only the edited stamp reacquires its input levels"); + crate::execute(&mut session, "graph.size", &serde_json::json!({"width":32})).unwrap(); + assert_eq!(pixels(session.cook()), [mip, base]); + assert_eq!(pixels(&session.cook_full(0)), [base; 2]); + for extent in [64, 32] { + crate::execute(&mut session, "graph.size", &serde_json::json!({"width":extent})).unwrap(); + } + assert_eq!(pixels(session.cook()), [base; 2]); + change_precision(&mut session); + assert_eq!(pixels(session.cook()), [mip, base]); + crate::execute(&mut session, "graph.input.bind", &serde_json::json!({"identifier":"input","resource":"Copy","linear":true})).unwrap(); + assert_eq!(pixels(session.cook()), [base; 2]); +} + +#[test] +fn changing_one_instances_precision_updates_its_fixed_precision_stamp() { + use materialcraft_core::{Graph, OutputFormat, Value}; + + let (mut package, source, stamps) = stamp_package(); + let child = &mut package.graphs[0]; + let out = child.add_node("output", [200.0, 0.0]); + child.connect(stamps[0], "output", out, "input").unwrap(); + let mut parent = Graph::new("Paired instances"); + parent.size = [5; 2]; + parent.format = OutputFormat::F32; + parent.input_images = std::mem::take(&mut child.input_images); + parent.input_images_linear = std::mem::take(&mut child.input_images_linear); + let input = parent.add_node("input_grayscale", [0.0; 2]); + parent.node_mut(input).unwrap().base = child.node(source).unwrap().base.clone(); + let instances = [0.0, 80.0].map(|y| { + let instance = parent.add_node("graph_instance", [100.0, y]); + let node = parent.node_mut(instance).unwrap(); + node.params.insert("graph".into(), Value::Text(child.name.clone())); + node.base.format = OutputFormat::F32; + parent.connect(input, "output", instance, "input").unwrap(); + instance + }); + package.graphs.insert(0, parent); + let mut session = Session::new(package); + let pixels = |cooked: &materialcraft_eval::Cooked| { + instances.map(|id| { + assert_eq!(cooked.nodes[&id].error, None); + cooked.image(id, 0).unwrap().get_gray(9, 8, false).to_bits() + }) + }; + assert_eq!(pixels(session.cook()), [0x3f01_4181; 2]); + for format in ["u16", "f32"] { + crate::execute(&mut session, "graph.node.base", &serde_json::json!({"id":instances[0].0,"format":format})).unwrap(); + assert_eq!(pixels(session.cook()), [0x3f01_8182, 0x3f01_4181]); + } + assert_eq!(pixels(&session.cook_full(0)), [0x3f01_4181; 2]); +} + +#[test] +fn bitmap_nodes_read_default_colors_from_the_file_and_keep_explicit_data_reads() { + use materialcraft_core::{Graph, OutputFormat, ResourceBytes, Value}; + + let field = Image::filled(16, 16, Kind::Color, [64.0, 128.0, 192.0, 97.0].map(|v| v / 255.0)); + let png = encode(&field, "png", Depth::U8, false).unwrap(); + for (gamma_chunk, expected) in [(false, [64, 128, 192, 97]), (true, [136, 186, 224, 97])] { + let mut bytes = png.clone(); + if gamma_chunk { + // Insert a unit gAMA chunk, including its CRC, immediately after IHDR. + bytes.splice(33..33, *b"\0\0\0\x04gAMA\0\x01\x86\xa0\x31\xe8\x96\x5f"); + } + let mut package = Package::new("Bitmap file colors"); + package.resources.push(Resource::new("field", "field.png", ResourceBytes::new(bytes))); + let mut graph = Graph::new("File and data reads"); + graph.size = [4, 4]; + graph.format = OutputFormat::U8; + let bitmap = graph.add_node("bitmap", [0.0; 2]); + let data = graph.add_node("bitmap", [0.0, 80.0]); + let input = graph.add_node("input_color", [0.0, 160.0]); + graph.input_images.insert("input".into(), "field".into()); + graph.input_images_from_file.insert("input".into()); + for id in [bitmap, data] { + graph.node_mut(id).unwrap().params.insert("resource".into(), Value::Text("field".into())); + } + graph.node_mut(data).unwrap().params.insert("colour_space".into(), Value::Enum(1)); + package.graphs.push(graph); + let mut session = Session::new(package); + let cook = session.cook(); + let pixel = |id| cook.image(id, 0).unwrap().get(0, 0, false).map(|v| (v * 255.0).round() as u8); + assert_eq!(pixel(bitmap), expected); + assert_eq!(pixel(data), [64, 128, 192, 97]); + assert_eq!(pixel(input), expected); + for (linear, levels) in [(Some(true), [64, 128, 192, 97]), (None, expected), (Some(false), [13, 55, 134, 97]), (None, expected)] { + let mut params = serde_json::json!({"identifier": "input", "resource": "field"}); + if let Some(value) = linear { + params["linear"] = value.into(); + } + crate::execute(&mut session, "graph.input.bind", ¶ms).unwrap(); + assert_eq!(session.graph().unwrap().input_images_from_file.contains("input"), linear.is_none()); + let rebound = session.cook().image(input, 0).unwrap().get(0, 0, false).map(|v| (v * 255.0).round() as u8); + assert_eq!(rebound, levels); + } + } +} + #[cfg(test)] mod merge_tests { use crate::Session; diff --git a/crates/engine/tests/it/atomics.rs b/crates/engine/tests/it/atomics.rs index fc13c903..12dc1c99 100644 --- a/crates/engine/tests/it/atomics.rs +++ b/crates/engine/tests/it/atomics.rs @@ -132,7 +132,15 @@ fn native_value_types_survive_processors_and_sbs() { let mut session = Session::new(read.pkg); session.preview_size = Some(16); session.cook(); - for (node, expected) in session.graph().unwrap().nodes.iter().zip(values) { + for (node, authored) in session.graph().unwrap().nodes.iter().zip(values) { + let Some(Value::Function(function)) = node.params.get("function") else { panic!("missing value function") }; + let constant = function.node(function.output.unwrap()).unwrap(); + assert_eq!(constant.value.as_ref(), Some(&authored)); + let expected = match authored { + Value::Int(16_777_217) => Value::Int(16_777_216), + Value::Int2([i32::MIN, i32::MAX]) => Value::Int2([i32::MIN, i32::MIN]), + value => value, + }; assert_eq!(session.cooked.value(node.id, 0), Some(&expected), "{:?}", session.cooked.nodes[&node.id].error); } } diff --git a/crates/engine/tests/it/embedded_edit.rs b/crates/engine/tests/it/embedded_edit.rs index 92cd39c3..8a145fc3 100644 --- a/crates/engine/tests/it/embedded_edit.rs +++ b/crates/engine/tests/it/embedded_edit.rs @@ -648,11 +648,11 @@ fn library_samplers_read_image_inputs_in_both_processors() { session.cook(); if definition == "value_processor" { - let expected = if sampler == "samplecol" { Value::Float4(color) } else { Value::Float(color[0]) }; + let expected = if sampler == "samplecol" { Value::Float4(color) } else { Value::Float(0.5) }; assert_eq!(session.cooked.value(owner, 0), Some(&expected)); } else { - let expected = if sampler == "samplecol" { color } else { [color[0], color[0], color[0], 1.0] }; + let expected = if sampler == "samplecol" { color } else { [0.5, 0.5, 0.5, 1.0] }; assert_eq!(session.cooked.image(owner, 0).unwrap().get(0, 0, false), expected); } diff --git a/crates/engine/tests/it/function_graph.rs b/crates/engine/tests/it/function_graph.rs index f1deb9fd..09e502af 100644 --- a/crates/engine/tests/it/function_graph.rs +++ b/crates/engine/tests/it/function_graph.rs @@ -62,6 +62,7 @@ fn standalone_function_creation_wiring_frame_movement_and_native_round_trip() { let function = graph.function.as_ref().unwrap(); assert_eq!(function.nodes[0].pos, [32.0, 64.0]); let variables = Default::default(); - let context = EvaluationContext { scope: Default::default(), position: [0.0; 2], size: [1.0; 2], images: &[], tile: true, variables: &variables }; + let context = + EvaluationContext { image_formats: &[], scope: Default::default(), position: [0.0; 2], size: [1.0; 2], images: &[], tile: true, variables: &variables }; assert_eq!(compile(function, 0).unwrap().evaluate(&context, &mut EvaluationState::default()).unwrap(), Value::Float(6.0)); } diff --git a/crates/engine/tests/it/function_instances.rs b/crates/engine/tests/it/function_instances.rs index 0ac105b5..4c9dd7c8 100644 --- a/crates/engine/tests/it/function_instances.rs +++ b/crates/engine/tests/it/function_instances.rs @@ -11,6 +11,7 @@ fn source() -> Package { let mut package = Package::new("Functions"); let mut graph = Graph::new("Twice"); graph.exposed.push(ExposedParameter { + connectable: false, description: String::new(), editor: None, clamp: false, @@ -47,7 +48,15 @@ fn evaluate(graph: &FunctionGraph) -> Value { function::compile(graph, 0) .unwrap() .evaluate( - &EvaluationContext { scope: Default::default(), position: [0.5; 2], size: [16.0; 2], images: &[], tile: true, variables: &BTreeMap::new() }, + &EvaluationContext { + image_formats: &[], + scope: Default::default(), + position: [0.5; 2], + size: [16.0; 2], + images: &[], + tile: true, + variables: &BTreeMap::new(), + }, &mut EvaluationState::default(), ) .unwrap() @@ -313,6 +322,24 @@ fn calls_evaluate_arguments_once_and_share_the_variables_they_set() { assert_eq!(evaluate(&caller), Value::Float(103.0)); } +#[test] +fn open_connectable_function_arguments_read_zero_and_preserve_the_source_value() { + let mut package = source(); + package.graphs[0].exposed[0].connectable = true; + let mut session = Session::new(package); + execute(&mut session, "file.new", &json!({"name": "Caller", "kind": "function"})).unwrap(); + let target = json!({"kind": "graph"}); + let instance = call(&mut session, 0, "Twice", &target); + edit(&mut session, &target, json!({"action": "output", "id": instance})); + assert_eq!(evaluate(session.graph().unwrap().function.as_ref().unwrap()), Value::Float(0.0)); + let constant = edit(&mut session, &target, json!({"action": "add", "operation": "const_float1", "at": [0,0]}))["id"].as_u64().unwrap(); + edit(&mut session, &target, json!({"action": "value", "id": constant, "value": Value::Float(0.1875)})); + edit(&mut session, &target, json!({"action": "connect", "from": constant, "to": instance, "input": 0})); + assert_eq!(evaluate(session.graph().unwrap().function.as_ref().unwrap()), Value::Float(0.375)); + execute(&mut session, "package.activate", &json!({"document": 0})).unwrap(); + assert_eq!(session.pkg.graphs[0].input_value("amount"), Some(&Value::Float(0.5))); +} + #[test] fn unconnected_instance_inputs_use_the_source_defaults() { let mut session = Session::new(source()); diff --git a/crates/engine/tests/it/function_library.rs b/crates/engine/tests/it/function_library.rs index a9f74b7c..77789e0b 100644 --- a/crates/engine/tests/it/function_library.rs +++ b/crates/engine/tests/it/function_library.rs @@ -18,7 +18,15 @@ fn session() -> Session { } fn value(function: &FunctionGraph) -> Value { - let context = EvaluationContext { scope: Default::default(), position: [0.5; 2], size: [16.0; 2], images: &[], tile: true, variables: &BTreeMap::new() }; + let context = EvaluationContext { + image_formats: &[], + scope: Default::default(), + position: [0.5; 2], + size: [16.0; 2], + images: &[], + tile: true, + variables: &BTreeMap::new(), + }; function::compile(function, 0).unwrap().evaluate(&context, &mut EvaluationState::default()).unwrap() } @@ -233,8 +241,15 @@ fn supplied_functions_evaluate_before_and_after_save() { if graph.name == "compute_total_number" { variables.insert("render_region".into(), Value::Float4([-0.5, 0.5, -0.5, 0.5])); } - let context = - EvaluationContext { scope: Default::default(), position: [0.5; 2], size: [256.0, 128.0], images: &[], tile: true, variables: &variables }; + let context = EvaluationContext { + image_formats: &[], + scope: Default::default(), + position: [0.5; 2], + size: [256.0, 128.0], + images: &[], + tile: true, + variables: &variables, + }; match source.evaluate(&context, &mut EvaluationState::default()) { Ok(expected) => { assert_eq!(saved.evaluate(&context, &mut EvaluationState::default()).unwrap(), expected, "{}", graph.sbs_path()); diff --git a/crates/engine/tests/it/graph_interaction.rs b/crates/engine/tests/it/graph_interaction.rs index 974d030d..920e7904 100644 --- a/crates/engine/tests/it/graph_interaction.rs +++ b/crates/engine/tests/it/graph_interaction.rs @@ -133,6 +133,9 @@ fn fx_map_starts_with_a_quadrant_and_grows_image_inputs_as_connected() { let source = add(&mut session, "uniform"); execute(&mut session, "graph.node.param", &json!({"id": source.0, "param": "color", "value": [0.5, 0.5, 0.5, 1.0]})).unwrap(); execute(&mut session, "graph.node.param", &json!({"id": source.0, "param": "color_mode", "value": false})).unwrap(); + let sixth = add(&mut session, "uniform"); + execute(&mut session, "graph.node.param", &json!({"id": sixth.0, "param": "color", "value": [0.75, 0.75, 0.75, 1.0]})).unwrap(); + execute(&mut session, "graph.node.param", &json!({"id": sixth.0, "param": "color_mode", "value": false})).unwrap(); let owner = add(&mut session, "fx_map"); let Value::PatternGraph(pattern) = &session.graph().unwrap().node(owner).unwrap().params["pattern"] else { panic!("missing default pattern") }; @@ -153,8 +156,10 @@ fn fx_map_starts_with_a_quadrant_and_grows_image_inputs_as_connected() { assert_eq!(loaded_pattern.nodes[0].kind, PatternNodeKind::Quadrant); assert_eq!(loaded_pattern.root, Some(loaded_pattern.nodes[0].id)); + execute(&mut session, "graph.node.param", &json!({"id": owner.0, "param": "color_mode", "value": false})).unwrap(); for index in 0..6 { - execute(&mut session, "graph.connect", &json!({"from": source.0, "to": owner.0, "toPort": format!("pattern{index}")})).unwrap(); + let input = if index == 5 { sixth } else { source }; + execute(&mut session, "graph.connect", &json!({"from": input.0, "to": owner.0, "toPort": format!("pattern{index}")})).unwrap(); assert_eq!(session.input_ports(owner).last(), Some(&format!("pattern{}", index + 1))); } @@ -163,12 +168,12 @@ fn fx_map_starts_with_a_quadrant_and_grows_image_inputs_as_connected() { let mut pattern = (**pattern).clone(); pattern.nodes[0].parameters.insert("patterntype".into(), Value::Int(1)); - pattern.nodes[0].parameters.insert("imageindex".into(), Value::Int(6)); + pattern.nodes[0].parameters.insert("imageindex".into(), Value::Int(5)); execute(&mut session, "graph.pattern.set", &json!({"id": owner.0, "pattern": pattern})).unwrap(); session.cook(); assert!(session.cooked.nodes[&owner].error.is_none(), "{:?}", session.cooked.nodes[&owner].error); - assert!((session.cooked.image(owner, 0).unwrap().mean()[0] - 0.5).abs() < 1e-5); + assert!((session.cooked.image(owner, 0).unwrap().mean()[0] - 0.75).abs() < 1e-5); let bytes = write_sbs(&session.pkg).unwrap(); @@ -186,7 +191,7 @@ fn fx_map_starts_with_a_quadrant_and_grows_image_inputs_as_connected() { loaded.cook(); - assert!((loaded.cooked.image(loaded_owner, 0).unwrap().mean()[0] - 0.5).abs() < 1e-5); + assert!((loaded.cooked.image(loaded_owner, 0).unwrap().mean()[0] - 0.75).abs() < 1e-5); execute(&mut session, "graph.disconnect", &json!({"to": owner.0, "toPort": "pattern5"})).unwrap(); diff --git a/crates/engine/tests/it/graph_properties.rs b/crates/engine/tests/it/graph_properties.rs index fa115ec7..f2f98afb 100644 --- a/crates/engine/tests/it/graph_properties.rs +++ b/crates/engine/tests/it/graph_properties.rs @@ -5,6 +5,20 @@ use materialcraft_engine::{ }; use serde_json::json; +#[test] +fn graph_parent_dimensions_round_up_and_include_a_single_texel() { + let mut session = Session::new(Package::new("Small")); + execute(&mut session, "file.new", &json!({"template": "empty", "size": 3})).unwrap(); + assert_eq!(session.graph().unwrap().size_px(), [4, 4]); + for (requested, expected) in [([1, 1], [1, 1]), ([1, 8], [1, 8]), ([3, 5], [4, 8]), ([6, 9], [8, 16]), ([17, 31], [32, 32]), ([0, u64::MAX], [1, 8192])] { + let result = execute(&mut session, "graph.size", &json!({"width": requested[0], "height": requested[1]})).unwrap(); + assert_eq!(result, json!({"width": expected[0], "height": expected[1]})); + assert_eq!(session.graph().unwrap().size_px(), expected); + } + execute(&mut session, "graph.size", &json!({"log2": [0, 1u64 << 32]})).unwrap(); + assert_eq!(session.graph().unwrap().size_px(), [1, 8192]); +} + #[path = "graph_property/history_preferences.rs"] mod history_preferences; @@ -171,3 +185,14 @@ fn a_function_label_updates_instances_without_renaming_references() { assert_eq!(materialcraft_engine::nodes::function::node_label(node), "Readable label"); assert_eq!(node.instance.as_ref().unwrap().graph, "Stable_identifier"); } + +#[test] +fn graph_seed_inheritance_can_be_edited_without_changing_the_offset() { + let mut session = materialcraft_engine::new_session(); + execute(&mut session, "graph.seed", &json!({"seed": 17, "inheritance": "absolute"})).unwrap(); + execute(&mut session, "graph.seed", &json!({"inheritance": "relativeToParent"})).unwrap(); + let graph = session.graph().unwrap(); + assert_eq!((graph.seed, graph.seed_mode), (17, materialcraft_engine::core::ParameterInheritance::RelativeToParent)); + assert!(execute(&mut session, "graph.seed", &json!({"seed": 3, "inheritance": "unknown"})).is_err()); + assert_eq!(session.graph().unwrap().seed, 17); +} diff --git a/crates/engine/tests/it/linked_resources.rs b/crates/engine/tests/it/linked_resources.rs index 30f1eb9d..f6a354fa 100644 --- a/crates/engine/tests/it/linked_resources.rs +++ b/crates/engine/tests/it/linked_resources.rs @@ -71,14 +71,18 @@ fn resource_package(source: &str) -> Package { #[test] fn library_resources_resolve_next_to_their_package() { + with_library_files("library_resources_resolve_next_to_their_package", verify_library_resources); +} + +fn with_library_files(test: &str, verify: fn(&std::path::Path)) { const CHILD_ROOT: &str = "MC_LINKED_RESOURCES_TEST_ROOT"; if let Ok(root) = std::env::var(CHILD_ROOT) { - verify_library_resources(std::path::Path::new(&root)); + verify(std::path::Path::new(&root)); return; } // A child process isolates the library root without mutating the test runner's environment - let root = std::env::temp_dir().join(format!("materialcraft-linked-resources-{}", std::process::id())); + let root = std::env::temp_dir().join(format!("materialcraft-linked-resources-{}-{test}", std::process::id())); std::fs::create_dir_all(root.join("assets/sbs/resources")).unwrap(); std::fs::create_dir_all(root.join("assets/sbs/nested/resources")).unwrap(); std::fs::write(root.join("assets/sbs/resources/tile.svg"), TILE).unwrap(); @@ -98,7 +102,7 @@ fn library_resources_resolve_next_to_their_package() { .unwrap(); let status = std::process::Command::new(std::env::current_exe().unwrap()) - .args(["--exact", "linked_resources::library_resources_resolve_next_to_their_package", "--nocapture"]) + .args(["--exact", &format!("linked_resources::{test}"), "--nocapture"]) .env(CHILD_ROOT, &root) .env("MATERIALCRAFT_SBS_DIR", root.join("assets/sbs")) .status() @@ -108,6 +112,38 @@ fn library_resources_resolve_next_to_their_package() { assert!(status.success()); } +#[test] +fn saving_a_catalog_source_updates_open_callers() { + with_library_files("saving_a_catalog_source_updates_open_callers", |root| { + use materialcraft_engine::NodeLibrary; + use std::sync::Arc; + + let alias = "sbs://nested/source.sbs"; + let source = root.join("assets/sbs/nested/source.sbs"); + let caller = root.join("caller.sbs"); + let original = std::fs::read_to_string(root.join("assets/sbs/nested/caller.sbs")).unwrap(); + std::fs::write(&caller, original.replace("source.sbs", alias)).unwrap(); + let check = |project, library, edited, expected| { + let mut session = Session::with_library(project, library); + file_cmds::open_file(&mut session, caller.to_str().unwrap()).unwrap(); + let document = session.document_id; + file_cmds::open_file(&mut session, source.to_str().unwrap()).unwrap(); + let body = FunctionGraph::constant(Value::Float(edited)); + execute(&mut session, "graph.function.set", &json!({"function": body})).unwrap(); + execute(&mut session, "file.save", &json!({})).unwrap(); + session.activate_document(document).unwrap(); + let linked = &session.pkg.dependencies[alias].graphs[0]; + assert_eq!(linked.function.as_ref().unwrap().nodes[0].value, Some(Value::Float(expected))); + assert_eq!(session.graph().unwrap().instances().next().unwrap().package, alias); + }; + check(Package::new("Installed"), NodeLibrary::shared(), 0.375, 0.375); + check(Package::new("Loaded by caller"), Arc::default(), 0.625, 0.625); + let mut project = Package::new("Explicit override"); + project.dependencies.insert(alias.into(), Arc::new(resource_package("resources/tile.svg"))); + check(project, NodeLibrary::shared(), 0.75, 0.5); + }); +} + fn verify_library_resources(root: &std::path::Path) { let library = materialcraft_engine::NodeLibrary::load(&["sbs://nested/caller.sbs".into(), "sbs://nested/source.sbs".into(), "sbs://nested/source.sbs".into()]); diff --git a/crates/engine/tests/it/optimization_perf.rs b/crates/engine/tests/it/optimization_perf.rs index 2eb7b8dd..1ed661f6 100644 --- a/crates/engine/tests/it/optimization_perf.rs +++ b/crates/engine/tests/it/optimization_perf.rs @@ -41,8 +41,9 @@ fn optimization_baseline() { parameters.insert("color_mode".into(), Value::Bool(false)); for size in [512, 2048] { for count in [0, 16] { - let variables = (0..count).map(|index| (format!("input_{index}"), Value::Float(index as f32))).collect(); + let variables: BTreeMap<_, _> = (0..count).map(|index| (format!("input_{index}"), Value::Float(index as f32))).collect(); let context = CookContext { + input_formats: &[], format: materialcraft_core::OutputFormat::F32, w: size, h: size, diff --git a/crates/engine/tests/it/parameter_functions.rs b/crates/engine/tests/it/parameter_functions.rs index aab2fab8..e5fe41bb 100644 --- a/crates/engine/tests/it/parameter_functions.rs +++ b/crates/engine/tests/it/parameter_functions.rs @@ -237,6 +237,7 @@ fn instance_parameter_functions_work_without_stored_literals_and_use_instance_si source.node_mut(color).unwrap().params.insert("color_mode".into(), Value::Bool(false)); source.node_mut(color).unwrap().functions.insert("color".into(), FunctionGraph::input("amount", ValueType::Float4)); source.exposed.push(materialcraft_engine::core::ExposedParameter { + connectable: false, description: String::new(), editor: None, clamp: false, @@ -341,7 +342,8 @@ fn native_channel_parameters_accept_scalar_functions_without_changing_their_bodi assert_eq!(result.error, None, "{definition}.{parameter}"); - let expected = if definition == "fx_map" { Value::Color([0.25, 0.25, 0.25, 1.0]) } else { Value::Float4([0.25; 4]) }; + let gray = [0.25, 0.25, 0.25, 1.0]; + let expected = if definition == "fx_map" { Value::Color(gray) } else { Value::Float4(gray) }; assert_eq!(result.parameters[*parameter], expected); diff --git a/crates/engine/tests/it/sbs_functions.rs b/crates/engine/tests/it/sbs_functions.rs index b27eab7c..c1629bd5 100644 --- a/crates/engine/tests/it/sbs_functions.rs +++ b/crates/engine/tests/it/sbs_functions.rs @@ -43,24 +43,28 @@ fn imported_expression_cooks_follows_inputs_and_survives_undo_and_save() { s.cooked.image(levels, 0).unwrap().mean()[0] }; - assert!(mean(&mut s).abs() < 1e-5); + // The default swizzle places the scalar in red. Grayscale Levels averages RGB, + // so the lower endpoints are (0.75 - 0.25) / 3 and (0.5 - 0.25) / 3. + let original_mean = 2.0 / 5.0; + let changed_mean = 5.0 / 11.0; + assert!((mean(&mut s) - original_mean).abs() < 1e-5); execute(&mut s, "graph.exposed.set", &json!({"id": "amount", "value": 0.5})).unwrap(); - assert!((mean(&mut s) - 1.0 / 3.0).abs() < 1e-5); + assert!((mean(&mut s) - changed_mean).abs() < 1e-5); execute(&mut s, "edit.undo", &json!({})).unwrap(); - assert!(mean(&mut s).abs() < 1e-5); + assert!((mean(&mut s) - original_mean).abs() < 1e-5); execute(&mut s, "edit.redo", &json!({})).unwrap(); - assert!((mean(&mut s) - 1.0 / 3.0).abs() < 1e-5); + assert!((mean(&mut s) - changed_mean).abs() < 1e-5); let saved = sbs::write_sbs(&s.pkg).unwrap(); s.pkg = sbs::read_sbs(&saved, "saved.sbs", &|_| None).unwrap().pkg; s.cache.lock().unwrap().clear(); - assert!((mean(&mut s) - 1.0 / 3.0).abs() < 1e-5); + assert!((mean(&mut s) - changed_mean).abs() < 1e-5); assert!(s.graph().unwrap().nodes.iter().find(|node| node.def == "levels").unwrap().functions.contains_key("in_low")); } diff --git a/crates/engine/tests/it/subgraph_seed.rs b/crates/engine/tests/it/subgraph_seed.rs index c125139c..b1342f53 100644 --- a/crates/engine/tests/it/subgraph_seed.rs +++ b/crates/engine/tests/it/subgraph_seed.rs @@ -11,6 +11,7 @@ fn grouping_noise_preserves_pixels_seed_and_undo() { let mut s = new_session(); s.preview_size = None; run(&mut s, "graph.size", json!({"width": 64, "height": 32})); + run(&mut s, "graph.format", json!({"format": "f32"})); run(&mut s, "graph.seed", json!({"seed": seed})); let noise = run(&mut s, "graph.node.add", json!({"def": "pixel_processor"}))["id"].as_u64().unwrap(); let mut function = materialcraft_engine::core::FunctionGraph::default(); @@ -49,5 +50,30 @@ fn grouping_noise_preserves_pixels_seed_and_undo() { let reopened_output = reopened.graph().unwrap().nodes.iter().find(|node| node.def == "output").unwrap().id; assert_eq!(reopened.cook().image(reopened_output, 0).unwrap().data(), before.data()); + run(&mut s, "edit.undo", json!({})); + for changed_seed in [5, 89] { + run(&mut s, "graph.seed", json!({"seed": changed_seed})); + run(&mut reopened, "graph.seed", json!({"seed": changed_seed})); + assert_eq!(reopened.cook().image(reopened_output, 0).unwrap().data(), s.cook().image(output, 0).unwrap().data()); + } } } + +#[test] +fn editing_a_computed_graph_seed_preserves_the_expression_until_a_literal_is_set() { + use materialcraft_engine::core::{FunctionGraph, ParameterInheritance}; + let mut session = new_session(); + let mut function = FunctionGraph::default(); + function.output = Some(function.add_constant(materialcraft_engine::core::Value::Int(5))); + session.pkg.graphs[0].seed_function = Some(function.clone()); + run(&mut session, "graph.seed", json!({"inheritance": "relativeToParent"})); + assert_eq!(session.pkg.graphs[0].seed_mode, ParameterInheritance::RelativeToParent); + assert_eq!(session.pkg.graphs[0].seed_function.as_ref(), Some(&function)); + let inspected = run(&mut session, "session.inspect", json!({})); + assert_eq!(inspected["graph"]["seedFunction"], serde_json::to_value(&function).unwrap()); + run(&mut session, "graph.seed", json!({"seed": 17})); + assert_eq!(session.pkg.graphs[0].seed_function, None); + assert_eq!(session.pkg.graphs[0].seed, 17); + run(&mut session, "edit.undo", json!({})); + assert_eq!(session.pkg.graphs[0].seed_function, Some(function)); +} diff --git a/crates/engine/tests/it/system_variables.rs b/crates/engine/tests/it/system_variables.rs index 1b6c918c..29b390c2 100644 --- a/crates/engine/tests/it/system_variables.rs +++ b/crates/engine/tests/it/system_variables.rs @@ -51,18 +51,18 @@ fn standalone_get_suggestions_match_each_type_and_order() { } #[test] -fn pixel_processor_suggestions_add_position_without_fx_variables() { - let mut graph = Graph::new("Pixels"); - let owner = graph.add_node("pixel_processor", [0.0; 2]); - graph.node_mut(owner).unwrap().params.insert("function".into(), Value::Function(Box::new(getter("get_float2", "")))); - let mut package = Package::new("Pixels"); - package.graphs.push(graph); - let session = Session::new(package); - let target = FunctionGraphTarget::Parameter { node: owner, parameter: "function".into() }; - - let variables = target.variables(&session, 1).unwrap(); - - assert_eq!(variables.iter().map(|variable| variable.name.as_str()).collect::>(), ["$size", "$sizelog2", "$pos"]); +fn pixel_and_value_processor_suggestions_include_position() { + for processor in ["pixel_processor", "value_processor"] { + let mut graph = Graph::new("Position"); + let owner = graph.add_node(processor, [0.0; 2]); + graph.node_mut(owner).unwrap().params.insert("function".into(), Value::Function(Box::new(getter("get_float2", "")))); + let mut package = Package::new("Position"); + package.graphs.push(graph); + let session = Session::new(package); + let target = FunctionGraphTarget::Parameter { node: owner, parameter: "function".into() }; + let variables = target.variables(&session, 1).unwrap(); + assert_eq!(variables.iter().map(|variable| variable.name.as_str()).collect::>(), ["$size", "$sizelog2", "$pos"]); + } } #[test] @@ -78,6 +78,14 @@ fn graph_metadata_and_host_values_cook_and_round_trip_as_native_get_nodes() { ("get_float3", "$physicalsize", Value::Float3([20.0, 10.0, 0.5])), ("get_float2", "$size", Value::Float2([32.0, 16.0])), ("get_float2", "$sizelog2", Value::Float2([5.0, 4.0])), + ("get_float2", "$pos", Value::Float2([0.0; 2])), + ("get_float1", "$depth", Value::Float(0.0)), + ("get_float1", "$depthpow2", Value::Float(0.0)), + ("get_float1", "$number", Value::Float(0.0)), + ("isdefined", "$pos", Value::Bool(true)), + ("isdefined", "$depthpow2", Value::Bool(true)), + ("isdefined", "$absent", Value::Bool(false)), + ("get_integer3", "$absent", Value::Int3([0; 3])), ]; let ids: Vec<_> = cases.iter().map(|(operation, name, _)| processor(&mut graph, operation, name)).collect(); let mut package = Package::new("Context"); @@ -135,7 +143,7 @@ fn pixel_ratio_and_tiling_inherit_and_preserve_native_relative_modes() { let mut session = Session::new(package); session.selection = vec![pixel]; - for (mode, expected) in [("relativeToInput", 2.0), ("relativeToParent", 3.0), ("absolute", 0.0)] { + for (mode, expected) in [("relativeToInput", 2.0), ("relativeToParent", 4.0), ("absolute", 0.0)] { execute(&mut session, "graph.node.base", &json!({"pixelRatio": 0, "tiling": false, "pixelRatioMode": mode, "tilingMode": mode})).unwrap(); let bytes = write_sbs(&session.pkg).unwrap(); let read = read_sbs(&bytes, "inheritance.sbs", &|_| None).unwrap(); @@ -279,7 +287,8 @@ fn nested_function_instances_use_the_processing_callers_variable_scope() { let cooked = session.cook(); assert_eq!(cooked.nodes[&pixel].error, None); - assert!(cooked.nodes[&value].error.as_deref().unwrap().contains("undefined variable `$pos`")); + assert_eq!(cooked.nodes[&value].error, None); + assert_eq!(cooked.nodes[&value].outputs[0].as_value(), Some(&Value::Float2([0.0; 2]))); let image = cooked.image(pixel, 0).unwrap(); diff --git a/crates/engine/tests/package_resources.rs b/crates/engine/tests/package_resources.rs index 3c375309..fa68f5df 100644 --- a/crates/engine/tests/package_resources.rs +++ b/crates/engine/tests/package_resources.rs @@ -3,6 +3,20 @@ use serde_json::json; const SVG: &[u8] = br#""#; +#[test] +fn saving_a_recovered_package_keeps_its_missing_resource_link_relative() { + let bytes = br#""#; + let mut session = Session::new(Package::new("Empty")); + file_cmds::open_bytes_linked(&mut session, bytes, Some("materials/example.sbs".into()), &|_| None).unwrap(); + assert!(session.path.is_none()); + assert!(!session.load_warnings.is_empty()); + let first = session.document_id; + file_cmds::open_bytes_linked(&mut session, bytes, Some("other/example.sbs".into()), &|_| None).unwrap(); + execute(&mut session, "package.activate", &json!({"document": first})).unwrap(); + let saved = String::from_utf8(file_cmds::save_bytes(&session).unwrap()).unwrap(); + assert!(saved.contains(r#""#)); +} + #[test] fn byte_only_sbs_import_resolves_library_resource_substitutes() { let xml = br#" diff --git a/crates/engine/tests/session.rs b/crates/engine/tests/session.rs index c2c0a7ad..6248743d 100644 --- a/crates/engine/tests/session.rs +++ b/crates/engine/tests/session.rs @@ -127,7 +127,31 @@ fn export_size_keeps_proportions_and_clamps() { s.pkg.graphs[0].size = [u32::MAX, u32::MAX]; assert!(dims(&s, json!(32)).iter().all(|d| *d == (32, 32))); - assert!(dims(&s, json!([1, u64::MAX])).iter().all(|d| *d == (16, 8192)), "sides clamp to 16..8192"); + assert!(dims(&s, json!([1, u64::MAX])).iter().all(|d| *d == (1, 8192)), "sides clamp to 1..8192"); + + s.pkg.graphs[0].absolute_output_size = Some([6, 5]); + assert!(dims(&s, json!(0)).iter().all(|d| *d == (64, 32))); + assert!(dims(&s, json!(32)).iter().all(|d| *d == (32, 16))); + assert_eq!(s.pkg.graphs[0].absolute_output_size, Some([6, 5])); + + s.pkg.graphs[0].absolute_output_size = None; + s.pkg.graphs[0].size = [7, 6]; + let shift = materialcraft_engine::core::GraphSizeOffset::Parent([-1, 1]); + s.pkg.graphs[0].relative_output_size = Some(shift); + assert!(dims(&s, json!(0)).iter().all(|d| *d == (64, 128))); + assert!(dims(&s, json!(32)).iter().all(|d| *d == (16, 32))); + assert_eq!(s.pkg.graphs[0].relative_output_size, Some(shift)); + + use materialcraft_engine::core::{FunctionGraph, Value as GraphValue}; + let function = FunctionGraph::constant(GraphValue::Int2([0, 2])); + s.pkg.graphs[0].output_size_function = Some(function.clone()); + assert!(dims(&s, json!(0)).iter().all(|d| *d == (128, 256))); + assert!(dims(&s, json!(64)).iter().all(|d| *d == (32, 64))); + assert!(dims(&s, json!([32, 16])).iter().all(|d| *d == (32, 16))); + assert_eq!(s.pkg.graphs[0].output_size_function.as_ref(), Some(&function)); + let info = execute(&mut s, "session.inspect", &json!({})).unwrap(); + assert_eq!(info["graph"]["size"], json!([128, 256])); + assert_eq!(info["graph"]["outputSizeMode"], "relativeToParent"); } /// A scratch folder for one test, removed when dropped @@ -165,6 +189,149 @@ fn native_sbs_is_the_default_save_format() { assert_eq!(run(&mut session, "file.save", json!({}))["path"], json!(saved)); } +#[test] +fn saving_a_library_graph_opened_from_disk_keeps_its_portable_function_links() { + let directory = TempDir::new("library-function-export"); + let name = "waveform_01_v2.sbs"; + let library = materialcraft_engine::formats::sbs::library::root(); + let mut session = sample_session(); + for (index, source) in [library.join(name).to_str().unwrap().to_string(), format!("sbs://{name}")].into_iter().enumerate() { + run(&mut session, "file.open", json!({ "path": source })); + let saved = directory.file(&format!("caller-{index}.sbs")); + run(&mut session, "file.saveAs", json!({ "path": saved })); + let xml = std::fs::read_to_string(&saved).unwrap(); + for helper in ["functions.sbs", "functions_hash.sbs"] { + assert!(xml.contains(&format!(r#" = + reopened.pkg.graphs.iter().flat_map(|graph| graph.instances()).map(|instance| instance.package.as_str()).collect(); + assert!(links.contains("sbs://blend_switch.sbs")); + let dependent = library::root().join("non_uniform_blur.sbs").canonicalize().unwrap(); + assert!(links.contains("sbs://non_uniform_blur.sbs")); + + // A local edit in a shared grandchild keeps the whole branch linked to its source. + let functions = library::root().join("functions.sbs").canonicalize().unwrap(); + let source = library::root().join("bevel.sbs"); + let mut edited = sample_session(); + run(&mut edited, "file.open", json!({"path": source})); + let dependency = edited.pkg.dependencies.get_mut(functions.to_str().unwrap()).unwrap(); + std::sync::Arc::make_mut(dependency).graphs[0].name.push_str("_edited"); + let saved = directory.file("with_edits.sbs"); + run(&mut edited, "file.saveCopyAs", json!({"path": saved})); + let mut reopened = sample_session(); + run(&mut reopened, "file.open", json!({"path": saved})); + assert!(reopened.pkg.graphs.iter().flat_map(|graph| graph.instances()).any(|instance| instance.package == dependent.to_str().unwrap())); +} + +#[test] +fn saving_in_place_keeps_a_file_reference_to_a_bundled_graph() { + use materialcraft_engine::{ + core::{Graph, GraphInstance, Package}, + formats::sbs::{library, write_sbs}, + }; + + let directory = TempDir::new("live-library-link"); + let caller = directory.file("caller.sbs"); + let source = library::root().join("blend_switch.sbs").canonicalize().unwrap(); + let mut graph = Graph::new("Caller"); + let instance = graph.add_node("graph_instance", [0.0; 2]); + graph.node_mut(instance).unwrap().instance = Some(GraphInstance { + package: source.to_str().unwrap().to_owned(), + graph: "switch_grayscale".into(), + label: String::new(), + inputs: Vec::new(), + outputs: Vec::new(), + defaults: Default::default(), + }); + let mut package = Package::new("Caller"); + package.graphs.push(graph); + std::fs::write(&caller, write_sbs(&package).unwrap()).unwrap(); + + let mut session = sample_session(); + run(&mut session, "file.open", json!({"path": caller})); + run(&mut session, "file.save", json!({})); + let mut reopened = sample_session(); + run(&mut reopened, "file.open", json!({"path": caller})); + let saved = reopened.pkg.graphs[0].instances().next().unwrap(); + assert_eq!(saved.package, source.to_str().unwrap()); + + let copy = directory.file("copy.sbs"); + run(&mut reopened, "file.saveCopyAs", json!({"path": copy})); + let xml = std::fs::read_to_string(copy).unwrap(); + assert!(xml.contains(r#" = parsed.pkg.graphs[0].instances().map(|instance| instance.package.as_str()).collect(); + assert_eq!(links, [catalog, file]); +} + +#[test] +fn a_changed_or_detached_function_file_keeps_its_disk_identity() { + use materialcraft_engine::formats::sbs::library; + use std::path::Path; + + let directory = TempDir::new("local-function-source"); + let name = "functions_hash.sbs"; + let path = directory.file(name); + let mut changed = library::read(&format!("sbs://{name}")).unwrap(); + changed[0] = b' '; + std::fs::write(&path, changed).unwrap(); + assert!(library::bundled_package_uri(&directory.0.canonicalize().unwrap(), Path::new(&path)).is_none()); + std::fs::copy(library::root().join(name), &path).unwrap(); + assert!(library::bundled_package_uri(&library::root().canonicalize().unwrap(), Path::new(&path)).is_none()); +} + /// Saving an SBS file another program wrote must not overwrite it: MaterialCraft can't write back what it couldn't read #[test] fn saving_an_sbs_file_from_another_program_needs_a_new_name() { diff --git a/crates/eval/Cargo.toml b/crates/eval/Cargo.toml index a5ddc9f0..a352b85f 100644 --- a/crates/eval/Cargo.toml +++ b/crates/eval/Cargo.toml @@ -11,7 +11,7 @@ workspace = true [dependencies] materialcraft-core = { workspace = true } craft-texture = { workspace = true } -materialcraft-nodes = { workspace = true } half = { workspace = true } +materialcraft-nodes = { workspace = true } serde_json = { workspace = true } serde = { workspace = true } diff --git a/crates/eval/src/cache.rs b/crates/eval/src/cache.rs index 2621a8ff..f9807538 100644 --- a/crates/eval/src/cache.rs +++ b/crates/eval/src/cache.rs @@ -1,13 +1,19 @@ -use crate::NodeOutput; +use crate::{NodeOutput, ResolvedBaseParameters}; use std::collections::HashMap; use std::sync::Arc; const DEFAULT_LIMIT_BYTES: usize = 256 << 20; const MAX_ENTRIES: usize = 8192; +#[derive(Clone)] +pub(crate) struct CachedOutputs { + pub values: Arc>, + pub bases: Option>, +} + /// LRU cache of node outputs, bounded by bytes pub struct Cache { - entries: HashMap>, usize, u64)>, + entries: HashMap, bytes: usize, cap: usize, tick: u64, @@ -48,7 +54,7 @@ impl Cache { self.bytes = 0; } - pub(crate) fn get(&mut self, key: u64) -> Option>> { + pub(crate) fn get(&mut self, key: u64) -> Option { self.tick = self.tick.saturating_add(1); let tick = self.tick; self.entries.get_mut(&key).map(|entry| { @@ -57,15 +63,16 @@ impl Cache { }) } - pub(crate) fn put(&mut self, key: u64, outputs: Arc>) { - let size = outputs.iter().fold(0_usize, |total, output| total.saturating_add(output.memory_bytes())); + pub(crate) fn put(&mut self, key: u64, outputs: Arc>, bases: Option>) { + let metadata = bases.as_deref().map_or(0, std::mem::size_of_val); + let size = outputs.iter().fold(metadata, |total, output| total.saturating_add(output.memory_bytes())); if let Some(old) = self.entries.remove(&key) { self.bytes = self.bytes.saturating_sub(old.1); } // Oversized results remain owned by their cooks // Empty results would permit unbounded zero-byte cache metadata - if size == 0 || size > self.cap { + if outputs.is_empty() || size == 0 || size > self.cap { return; } @@ -77,7 +84,7 @@ impl Cache { } self.tick = self.tick.saturating_add(1); - self.entries.insert(key, (outputs, size, self.tick)); + self.entries.insert(key, (CachedOutputs { values: outputs, bases }, size, self.tick)); self.bytes += size; } } diff --git a/crates/eval/src/cache.test.rs b/crates/eval/src/cache.test.rs index 0e26792d..0a01f217 100644 --- a/crates/eval/src/cache.test.rs +++ b/crates/eval/src/cache.test.rs @@ -8,10 +8,10 @@ fn output(side: u32) -> Arc> { #[test] fn oversized_results_are_not_retained_or_allowed_to_flush_useful_entries() { let mut cache = Cache::new(64); - cache.put(1, output(4)); + cache.put(1, output(4), None); let large = output(8); let weak = Arc::downgrade(&large); - cache.put(2, large); + cache.put(2, large, None); assert!(weak.upgrade().is_none()); assert!(cache.get(1).is_some()); @@ -22,12 +22,12 @@ fn oversized_results_are_not_retained_or_allowed_to_flush_useful_entries() { #[test] fn disabled_and_empty_caches_do_not_retain_outputs_or_metadata() { let mut cache = Cache::new(0); - cache.put(1, output(4)); + cache.put(1, output(4), None); assert!(cache.is_empty()); for key in 0..10_000 { - cache.put(key, Arc::new(Vec::new())); + cache.put(key, Arc::new(Vec::new()), None); } assert!(cache.is_empty()); @@ -38,18 +38,18 @@ fn repeated_edits_release_evicted_buffers_and_keep_recent_hits() { let mut cache = Cache::new(128); let first = output(4); let first_weak = Arc::downgrade(&first); - cache.put(0, first); - cache.put(1, output(4)); + cache.put(0, first, None); + cache.put(1, output(4), None); assert!(cache.get(0).is_some()); - cache.put(2, output(4)); + cache.put(2, output(4), None); assert!(cache.get(1).is_none()); assert!(first_weak.upgrade().is_some()); for key in 3..1_000 { - cache.put(key, output(4)); + cache.put(key, output(4), None); assert!(cache.bytes() <= 128); assert!(cache.len() <= 2); diff --git a/crates/eval/src/cache_key.rs b/crates/eval/src/cache_key.rs index 40e0b741..c4fb360a 100644 --- a/crates/eval/src/cache_key.rs +++ b/crates/eval/src/cache_key.rs @@ -50,6 +50,10 @@ pub(crate) fn graph_tree_hash(package: &Package, graph_index: usize) -> u64 { graph_tree_hash_with_registry(package, package, graph_index) } +pub(crate) fn resource_parameter(node: &Node) -> &'static str { + if node.def == "text" { "fontdata" } else { "resource" } +} + pub(crate) fn graph_tree_hash_with_registry(registry: &Package, package: &Package, graph_index: usize) -> u64 { let mut hasher = DefaultHasher::new(); let mut pending = vec![(package, graph_index)]; @@ -79,7 +83,14 @@ pub(crate) fn graph_tree_hash_with_registry(registry: &Package, package: &Packag } for node in &graph.nodes { - if let Some(Value::Text(name)) = node.params.get("resource") { + let parameter = resource_parameter(node); + if node.bindings.contains_key(parameter) || node.functions.contains_key(parameter) { + // The caller may select another package resource when this instance runs. + for resource in &package.resources { + resource.name.hash(&mut hasher); + resource.bytes.content_hash().hash(&mut hasher); + } + } else if let Some(Value::Text(name)) = node.params.get(parameter) { package.resource(name).map(|resource| resource.bytes.content_hash()).hash(&mut hasher); } if node.def == "graph_instance" @@ -93,12 +104,14 @@ pub(crate) fn graph_tree_hash_with_registry(registry: &Package, package: &Packag hasher.finish() } -pub(crate) fn variable_key(node: &Node, parameters: &BTreeMap, variables: &BTreeMap) -> u64 { +pub(crate) fn variable_key(node: &Node, parameters: &BTreeMap, variables: &dyn materialcraft_nodes::GraphVariables) -> u64 { let mut hasher = DefaultHasher::new(); let mut names = std::collections::BTreeSet::new(); let mut pending: Vec<&Value> = parameters.values().collect(); while let Some(value) = pending.pop() { match value { + // JSON represents all non-finite numbers as null. Their signs change pattern blending. + Value::Float(v) if !v.is_finite() => v.to_bits().hash(&mut hasher), Value::Function(graph) => { let mut pending = vec![graph.as_ref()]; while let Some(graph) = pending.pop() { @@ -114,10 +127,12 @@ pub(crate) fn variable_key(node: &Node, parameters: &BTreeMap, va Some(Err(error)) => error.hash(&mut hasher), None => {} } - if (function_node.op.starts_with("get_") || function_node.op == "isdefined") - && let Some(Value::Text(name)) = &function_node.value - { - names.insert(name.as_str()); + if let Some(Value::Text(name)) = &function_node.value { + if function_node.op.starts_with("get_") { + names.insert(name.strip_prefix('%').unwrap_or(name)); + } else if function_node.op == "isdefined" { + names.insert(name.as_str()); + } } } } @@ -137,6 +152,10 @@ pub(crate) fn variable_key(node: &Node, parameters: &BTreeMap, va for name in names { name.hash(&mut hasher); variables.get(name).map(|value| serde_json::to_string(value).unwrap_or_default()).hash(&mut hasher); + variables.literal_inputs().iter().any(|input| input == name).hash(&mut hasher); + if node.def == "fx_map" { + variables.assigned_integers().iter().any(|input| input == name).hash(&mut hasher); + } } hasher.finish() diff --git a/crates/eval/src/cooked.rs b/crates/eval/src/cooked.rs index 3c7e0759..0d2fedd2 100644 --- a/crates/eval/src/cooked.rs +++ b/crates/eval/src/cooked.rs @@ -7,6 +7,7 @@ use std::collections::BTreeMap; #[derive(Clone, Debug, Default)] pub struct Cooked { pub nodes: BTreeMap, + pub preview_sampling: Option>, /// Total wall time of the cook in milliseconds pub ms: f32, pub cancelled: bool, diff --git a/crates/eval/src/external_image.rs b/crates/eval/src/external_image.rs new file mode 100644 index 00000000..6bfc7553 --- /dev/null +++ b/crates/eval/src/external_image.rs @@ -0,0 +1,255 @@ +use crate::NodeOutput; +use craft_texture::{Image, Kind, Limits, MAX_SIDE}; +use materialcraft_core::{OutputFormat, Package}; +use materialcraft_nodes::CookContext; + +/// A power-of-two resize after a bitmap's initial conversion leaves only its base texture level. +pub(super) fn base_level_only(image: &Image, size: (u32, u32), kind: Kind, source: OutputFormat, output: OutputFormat) -> bool { + let axes = [(image.width(), size.0), (image.height(), size.1)]; + if image.kind() != kind || !axes.iter().all(|(a, b)| a.is_power_of_two() && b.is_power_of_two()) { + return false; + } + let [horizontal, vertical] = axes.map(|(a, b)| a.trailing_zeros().abs_diff(b.trailing_zeros())); + let depth = |format| if format == OutputFormat::Inherit { OutputFormat::U16 } else { format }; + horizontal.max(vertical) > u32::from(depth(source) != depth(output)) +} + +/// Odd-sized normalized PNG resources use the same stored and sampled levels as bound rasters. +pub(super) fn resize_bitmap(context: &CookContext, package: &Package) -> Option { + let grayscale = !context.b("color_mode"); + if !grayscale && context.bitmap_color_space() == materialcraft_nodes::BitmapColorSpace::Srgb { + return None; + } + let name = context.text("resource"); + let resource = package.resource(name)?; + let info = materialcraft_core::png_raster_info(resource.bytes.as_slice())?; + let [width, height] = info.size; + // Check the header first so ordinary power-of-two bitmaps still request their decoded image only once. + if info.grayscale != grayscale || (width.is_power_of_two() && height.is_power_of_two()) || (width, height) == (context.w, context.h) { + return None; + } + let image = context.bitmap_resource(name)?; + let kind = if grayscale { Kind::Gray } else { Kind::Color }; + resize(&image, (context.w, context.h), kind, info.format, context.format) +} + +/// Non-power-of-two external rasters filter each axis directly, storing the result between passes. +pub(super) fn resize(image: &Image, size: (u32, u32), kind: Kind, source: OutputFormat, output: OutputFormat) -> Option { + let size = craft_texture::clamp_size(size.0, size.1); + let (width, height) = (image.width(), image.height()); + if (width.is_power_of_two() && height.is_power_of_two()) || (width, height) == size || width.max(height) > MAX_SIDE || image.kind() != kind { + return None; + } + let input_levels: Option = match (image.integer_sampling(), source) { + (true, OutputFormat::U8) => Some(255.0), + (true, OutputFormat::U16) => Some(65535.0), + (false, OutputFormat::F32) => None, + _ => return None, + }; + let output_levels = match output { + OutputFormat::U8 => Some(255.0), + OutputFormat::Inherit | OutputFormat::U16 => Some(65535.0), + OutputFormat::F32 | OutputFormat::F16 => None, + }; + // Keep the lower channel depth through both filter passes. A byte raster sent to + // a word or float output still filters at byte precision. + let maximum = match (input_levels, output_levels) { + (Some(source), Some(output)) => Some(source.min(output)), + (source, output) => source.or(output), + }; + let mut filtered = match (input_levels, maximum) { + (Some(source), Some(working)) if source == working => image.map(kind, |pixel| pixel.map(|v| (v * source).round())), + (_, Some(working)) => dither(image, working, input_levels.is_some())?, + _ => image.clone(), + }; + let (w, h) = size; + let passes = if w <= width { [(true, w), (false, h)] } else { [(false, h), (true, w)] }; + for (horizontal, end) in passes { + filtered = filter_axis(filtered, horizontal, end, maximum.is_some()); + } + if output == OutputFormat::F16 { + return match source { + OutputFormat::U8 => { + let texture = filtered.map(kind, |p| p.map(|v| v / 255.0)).with_integer_sampling(true); + let stored = crate::output_precision::apply(texture.clone(), OutputFormat::F16); + Some(NodeOutput::BoundBitmap { stored, texture, texture_format: source }) + } + OutputFormat::U16 => word_to_half(&filtered).map(NodeOutput::Image), + // Float rasters are filtered at full precision before the half writer diffuses its rounding error. + _ => diffuse(&filtered, |original, received| { + let stored = nearest_positive_half(original + received); + (stored, original - stored) + }) + .map(NodeOutput::Image), + }; + } + let Some(maximum) = maximum else { return Some(NodeOutput::Image(filtered)) }; + let stored = filtered.map(kind, |p| p.map(|v| v / maximum)).with_integer_sampling(output_levels.is_some()); + if input_levels.is_some() && output_levels.is_none_or(|levels| levels > maximum) { + // A wider bridge can report the same normalized values as the source, yet interpolation + // still rounds the weighted sum to normalized integer levels. + let texture = stored.clone().with_integer_sampling(true); + Some(NodeOutput::BoundBitmap { stored, texture, texture_format: source }) + } else { + Some(NodeOutput::Image(stored)) + } +} + +fn nearest_positive_half(value: f32) -> f32 { + let value = value.max(0.0); + let nearest = half::f16::from_f32(value); + let lower = nearest.to_f32(); + if lower < value { + let upper = half::f16::from_bits(nearest.to_bits() + 1).to_f32(); + // The bitmap writer rounds a midpoint to the larger half, including at the subnormal boundary. + if value - lower == upper - value { + return upper; + } + } + lower +} + +fn filter_axis(image: Image, horizontal: bool, end: u32, integer: bool) -> Image { + let start = if horizontal { image.width() } else { image.height() }; + if start == end { + return image; + } + let scale = f64::from(end) / f64::from(start); + let filter_scale = scale.min(1.0); + let radius = 1.0 / filter_scale; + let taps: Vec<_> = (0..end) + .map(|index| { + // On enlargement the mapped origin and half-texel offset round independently. + let center = if end > start { f64::from(index) / scale + 0.5 / scale } else { (f64::from(index) + 0.5) / scale }; + let first = (center - 0.5 - radius).ceil().max(0.0) as u32; + let last = ((center - 0.5 + radius).floor() as u32).min(start - 1); + // Keep the downsampling factor through normalization. Cancelling it changes rounding at close texels. + let mut weights: Vec<_> = (first..=last).map(|i| filter_scale * (1.0 - (f64::from(i) + 0.5 - center).abs() * filter_scale).max(0.0)).collect(); + let sum: f64 = weights.iter().sum(); + for w in &mut weights { + *w /= sum; + } + (first, weights) + }) + .collect(); + let (w, h) = if horizontal { (end, image.height()) } else { (image.width(), end) }; + Image::generate(w, h, image.kind(), |x, y| { + let index = if horizontal { x } else { y }; + let (first, weights) = &taps[index as usize]; + let mut sum = [0.0_f64; 4]; + for (offset, &weight) in weights.iter().enumerate() { + if weight == 0.0 { + continue; + } + let pos = i64::from(*first) + offset as i64; + let pixel = if horizontal { image.get(pos, i64::from(y), false) } else { image.get(i64::from(x), pos, false) }; + for (value, channel) in sum.iter_mut().zip(pixel) { + *value += f64::from(channel) * weight; + } + } + sum.map(|v| if integer { v.round() as f32 } else { v as f32 }) + }) +} + +fn next_fraction(state: &mut u64) -> f32 { + *state = (48_271 * *state) % 2_147_483_647; + (*state as f64 / 2_147_483_647.0) as f32 +} + +fn word_to_half(image: &Image) -> Option { + let mut state = 1_u64; + diffuse(image, |original, received| { + let original = f32::from(original as u16); + let word = (original + received + (next_fraction(&mut state) - 0.5) * 16.0) as u16; + let (stored, reconstructed) = match word { + // The low-end conversion has distinct readback and error values at word three. + 0..=2 => (0.0, 0.0), + 3 => (2.0 / 65536.0, 3.0), + _ => { + let stored = crate::output_precision::store_half(f32::from(word) / 65535.0); + (stored, (stored * 65536.0).min(65535.0)) + } + }; + (stored, original - reconstructed) + }) +} + +fn dither(image: &Image, maximum: f32, word_to_byte: bool) -> Option { + let mut state = 1_u64; + let unit = maximum.recip(); + let limit = f32::MAX / (4.0 * maximum); + diffuse(image, |value, received| { + let random = next_fraction(&mut state); + let original = if value.is_finite() { value.clamp(-limit, limit) } else { f32::from(value > 0.0) }; + let stored = if word_to_byte { + // One full byte level expands to 257 word levels. The noise spans one high-byte step. + let word = (original * 65535.0).round(); + ((word + received * 257.0 + (random - 0.5) * 256.0) / 256.0).floor() + } else { + // The byte writer adds noise in units of 1/256. Diffused error stays in 1/255 units. + let offset = if maximum == 255.0 { received * unit + (random - 0.5) / 256.0 } else { (received + (random - 0.5)) * unit }; + ((original + offset) * maximum).round() + } + .clamp(0.0, maximum); + (stored, original * maximum - stored) + }) +} + +fn diffuse(image: &Image, mut quantize: impl FnMut(f32, f32) -> (f32, f32)) -> Option { + let width = usize::try_from(image.width()).ok()?; + let channels = image.channels(); + let mut samples = Vec::new(); + samples.try_reserve_exact(image.data().len()).ok()?; + samples.extend_from_slice(image.data()); + let mut errors: [_; 3] = std::array::from_fn(|_| vec![[0.0_f32; 4]; width + 4]); + for (y, row) in samples.chunks_exact_mut(width * channels).enumerate() { + let current = y % 3; + for (x, pixel) in row.chunks_exact_mut(channels).enumerate() { + let mut error = [0.0; 4]; + for (c, value) in pixel.iter_mut().enumerate() { + (*value, error[c]) = quantize(*value, errors[current][x + 2][c]); + } + // Two extra columns on each end absorb error outside the image. Propagate the + // original quantization error once, with the three-row Sierra filter. + for (dy, column, weight) in [ + (0, x + 3, 5), + (0, x + 4, 3), + (1, x, 2), + (1, x + 1, 4), + (1, x + 2, 5), + (1, x + 3, 4), + (1, x + 4, 2), + (2, x + 1, 2), + (2, x + 2, 3), + (2, x + 3, 2), + ] { + let dst = &mut errors[(current + dy) % 3][column]; + for (v, e) in dst.iter_mut().zip(error).take(channels) { + *v += e * (weight as f32 / 32.0); + } + } + } + errors[current].fill([0.0; 4]); + } + Image::from_data(image.width(), image.height(), image.kind(), samples, &Limits::default()).ok() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn odd_float_rasters_keep_exact_byte_levels_and_dither_fractional_levels() { + let level = 128.0 / 255.0; + let flat = Image::filled(256, 3, Kind::Color, [level; 4]); + let out = resize(&flat, (256, 4), Kind::Color, OutputFormat::F32, OutputFormat::U8).unwrap(); + assert!(out.as_image().unwrap().data().iter().all(|&v| v == level)); + + let ramp = Image::generate(256, 3, Kind::Color, |x, _| [(51.0 + x as f32 / 256.0) / 255.0; 4]); + let out = resize(&ramp, (256, 4), Kind::Color, OutputFormat::F32, OutputFormat::U8).unwrap(); + let image = out.as_image().unwrap(); + for (x, y, channel, expected) in [(16, 1, 1, 51), (219, 1, 2, 52), (18, 3, 1, 52), (105, 3, 3, 51)] { + assert_eq!((image.get(x, y, false)[channel] * 255.0).round() as u8, expected); + } + } +} diff --git a/crates/eval/src/graph_execution.rs b/crates/eval/src/graph_execution.rs index 5ad60d26..82217706 100644 --- a/crates/eval/src/graph_execution.rs +++ b/crates/eval/src/graph_execution.rs @@ -7,14 +7,52 @@ use std::{ sync::{Mutex, atomic::Ordering}, }; +/// Resolve a document graph's output dimensions without allocating or cooking its textures. +pub fn graph_output_size(graph: &materialcraft_core::Graph, environment: materialcraft_core::EvaluationEnvironment) -> Result<[u32; 2], String> { + if graph.output_size_function.is_none() { + return Ok(graph.size_px()); + } + let mut options = Options::new(&|_| None); + options.environment = environment; + let mut base = crate::ResolvedBaseParameters::graph(graph, &options); + base.evaluate_graph_size(graph, &options, &graph_variables(graph, &options))?; + Ok(base.size) +} + pub fn cook(package: &Package, graph_index: usize, options: &Options, cache: &Mutex) -> Cooked { let started_ms = now_ms(); let mut cooked = Cooked::default(); let Some(graph) = package.graphs.get(graph_index) else { return cooked }; let mut previews = BTreeMap::new(); - let prepared = PreparedGraph::new(package, graph, options); + let variables = graph_variables(graph, options); + let prepared = PreparedGraph::new(package, graph, options, &variables); + let mut sampling = crate::PreviewSampling::default(); + sampling.context = (prepared.parent_base.size, prepared.parent_base.seed, options.max_size); + sampling.caller_format = options.parent_base.map(|base| base.format); + let previous = options.previous_sampling.filter(|p| p.context == sampling.context); + for &id in &prepared.order { + if options.cancel.is_some_and(|cancel| cancel.load(Ordering::Relaxed)) { + cooked.cancelled = true; + break; + } + + let Some(node) = prepared.index.node(id) else { continue }; + + let input = input_image(graph, node, options, &mut previews); + let result = cook_node(package, graph_index, &prepared, node, &cooked, &variables, options, input, cache, previous, &mut sampling); + cooked.nodes.insert(id, result); + } + + cooked.ms = (now_ms() - started_ms) as f32; + if !sampling.is_empty() && !cooked.cancelled && cooked.nodes.values().all(|result| result.error.is_none()) { + cooked.preview_sampling = Some(std::sync::Arc::new(sampling)); + } + cooked +} + +fn graph_variables(graph: &materialcraft_core::Graph, options: &Options) -> BTreeMap { // Exposed parameter values: the graph's own, then the caller's overrides let mut variables: BTreeMap = graph.exposed.iter().filter_map(|exposed| graph.input_value(&exposed.id).map(|value| (exposed.id.clone(), value.clone()))).collect(); @@ -25,22 +63,7 @@ pub fn cook(package: &Package, graph_index: usize, options: &Options, cache: &Mu variables.insert("$uvtile".into(), Value::Int2(options.environment.uv_tile)); variables.insert("$normalformat".into(), Value::Int(options.environment.normal_format)); variables.insert("$physicalsize".into(), Value::Float3(graph.physical_size)); - - for &id in &prepared.order { - if options.cancel.is_some_and(|cancel| cancel.load(Ordering::Relaxed)) { - cooked.cancelled = true; - break; - } - - let Some(node) = prepared.index.node(id) else { continue }; - - let input = input_image(graph, node, options, &mut previews); - let result = cook_node(package, graph_index, &prepared, node, &cooked, &variables, options, input, cache); - cooked.nodes.insert(id, result); - } - - cooked.ms = (now_ms() - started_ms) as f32; - cooked + variables } fn input_image<'a>(graph: &Graph, node: &Node, options: &'a Options<'_>, previews: &'a mut BTreeMap>) -> Option<&'a Image> { @@ -54,8 +77,14 @@ fn input_image<'a>(graph: &Graph, node: &Node, options: &'a Options<'_>, preview } let resource = graph.input_images.get(&identifier)?; - let linear = graph.input_images_linear.contains(&identifier); + let space = if graph.input_images_from_file.contains(&identifier) { + materialcraft_nodes::BitmapColorSpace::FromFile + } else if graph.input_images_linear.contains(&identifier) { + materialcraft_nodes::BitmapColorSpace::Linear + } else { + materialcraft_nodes::BitmapColorSpace::Srgb + }; // Nodes sharing an input also share its first lookup, including a missing preview - previews.entry(identifier).or_insert_with(|| (options.resource)(&craft_texture::resource_key(resource, linear))).as_ref() + previews.entry(identifier).or_insert_with(|| (options.resource)(&space.resource_key(resource))).as_ref() } diff --git a/crates/eval/src/graph_instance.rs b/crates/eval/src/graph_instance.rs index d11e671b..f876e3a1 100644 --- a/crates/eval/src/graph_instance.rs +++ b/crates/eval/src/graph_instance.rs @@ -36,19 +36,26 @@ pub(crate) fn instances_reach(pkg: &Package, from: usize, target: usize) -> bool false } +pub(crate) struct CookedInstance { + pub ports: Vec<(NodeOutput, crate::ResolvedBaseParameters)>, + pub sampling: Option<(std::sync::Arc, u64)>, +} + pub(crate) fn cook_instance( package: &Package, graph_index: usize, node: &Node, input_ports: &[Port], output_ports: &[Port], - inputs: &[Option<&NodeOutput>], + inputs: &[Option<(&NodeOutput, crate::ResolvedBaseParameters)>], + input_keys: &[u64], params: &BTreeMap, - size: (u32, u32), + fixed: &[String], base: crate::resolved_base_parameters::ResolvedBaseParameters, options: &Options, cache: &Mutex, -) -> Result, String> { + previous: Option<&crate::PreviewSampling>, +) -> Result { if options.depth >= MAX_DEPTH { return Err("graph instances nest too deep (does a graph use itself?)".into()); } @@ -67,12 +74,14 @@ pub(crate) fn cook_instance( let root_resource = options.resource_root.unwrap_or(options.resource); let resource = |name: &str| match &node.instance { Some(instance) if !instance.package.is_empty() => { - let (name, linear) = craft_texture::split_resource_key(name); - root_resource(&craft_texture::resource_key(&format!("{}\0{name}", instance.package), linear)) + let (name, space) = materialcraft_nodes::BitmapColorSpace::split_resource_key(name); + root_resource(&space.resource_key(&format!("{}\0{name}", instance.package))) } _ => (options.resource)(name), }; let mut source_options = Options::new(&resource); + let empty = crate::PreviewSampling::default(); + source_options.previous_sampling = options.previous_sampling.map(|_| previous.unwrap_or(&empty)); source_options.environment = options.environment; source_options.parent_tiling = Some(base.tiling); source_options.parent_pixel_ratio = Some(base.pixel_ratio); @@ -85,9 +94,42 @@ pub(crate) fn cook_instance( source_options.graph_stack = options.graph_stack.clone(); source_options.graph_stack.push(identity); source_options.only = Some(source_graph.nodes.iter().filter(|node| node.def == "output").map(|node| node.id).collect()); - source_options.inputs = input_ports.iter().zip(inputs).filter_map(|(port, input)| Some((port.id.clone(), input.as_ref()?.as_image()?.clone()))).collect(); source_options.overrides = params.iter().filter(|(k, _)| source_graph.exposed.iter().any(|e| &e.id == *k)).map(|(k, v)| (k.clone(), v.clone())).collect(); - source_options.overrides.extend(input_ports.iter().zip(inputs).filter_map(|(port, input)| Some((port.id.clone(), input.as_ref()?.as_value()?.clone())))); + for exposed in &source_graph.exposed { + let name = &exposed.id; + if fixed.contains(name) || (!params.contains_key(name) && source_graph.input_value(name).is_some_and(crate::parameter::supports_literal_argument)) { + source_options.literal_inputs.push(name.clone()); + } + } + for ((port, input), &key) in input_ports.iter().zip(inputs).zip(input_keys) { + // A stored argument drives its bridge even when the same port has a wire. + if let Some(expected) = port.value_type + && (node.params.contains_key(&port.id) || node.bindings.contains_key(&port.id) || node.functions.contains_key(&port.id)) + && let Some(value) = params.get(&port.id) + { + if materialcraft_core::ValueType::of(value) != Some(expected) { + return Err(format!("input `{}` requires {}", port.id, expected.label())); + } + source_options.overrides.insert(port.id.clone(), value.clone()); + source_options.literal_inputs.retain(|name| name != &port.id); + continue; + } + let Some((output, source_base)) = input else { continue }; + if let Some((image, texture_format)) = output.texture(source_base.format) { + source_options.inputs.insert(port.id.clone(), image.clone()); + source_options.input_formats.insert(port.id.clone(), texture_format); + source_options.input_bases.insert(port.id.clone(), *source_base); + if matches!(output, NodeOutput::BaseLevel(_)) { + source_options.base_level_inputs.insert(port.id.clone()); + if source_options.previous_sampling.is_some() { + source_options.preview_input_keys.insert(port.id.clone(), key); + } + } + } else if let Some(value) = output.as_value() { + source_options.overrides.insert(port.id.clone(), value.clone()); + source_options.literal_inputs.retain(|name| name != &port.id); + } + } let cooked = cook(source, source_graph_index, &source_options, cache); if cooked.cancelled { return Err("cancelled".into()); @@ -97,20 +139,25 @@ pub(crate) fn cook_instance( return Err(format!("{}: {error}", source_graph.name)); } - output_ports + let mut keys = Vec::new(); + let ports = output_ports .iter() .map(|port| { - let output = source_graph + let result = source_graph .nodes .iter() .find(|candidate| candidate.def == "output" && identifier(candidate) == port.id) .and_then(|node| cooked.nodes.get(&node.id)) - .and_then(|result| result.outputs.first()) .ok_or_else(|| format!("the source output `{}` is missing", port.id))?; - Ok(match output { - NodeOutput::Image(image) => NodeOutput::Image(image.resize(size.0, size.1, true)), - NodeOutput::Value(value) => NodeOutput::Value(value.clone()), - }) + let output = result.outputs.first().ok_or_else(|| format!("the source output `{}` is empty", port.id))?; + if cooked.preview_sampling.is_some() { + keys.push(result.key); + } + // Images carry their source properties across the boundary. The caller owns the random seed. + let port_base = crate::ResolvedBaseParameters { seed: base.seed, ..result.base }; + Ok((output.clone(), port_base)) }) - .collect() + .collect::>()?; + let sampling = cooked.preview_sampling.map(|state| (state, crate::cache_key::hash_of(&keys))); + Ok(CookedInstance { ports, sampling }) } diff --git a/crates/eval/src/lib.rs b/crates/eval/src/lib.rs index 780a9d03..9ba280fa 100644 --- a/crates/eval/src/lib.rs +++ b/crates/eval/src/lib.rs @@ -4,6 +4,7 @@ mod cache; mod cache_key; mod cooked; +mod external_image; mod graph_execution; mod graph_instance; mod graph_output; @@ -13,12 +14,13 @@ mod node_output; mod node_result; mod node_size; mod options; -mod output_precision; +use materialcraft_nodes::output_precision; mod parameter; mod parameter_function; mod port; mod ports; mod prepared_graph; +mod preview_sampling; mod resolved_base_parameters; mod resource_decoder; mod time; @@ -27,7 +29,7 @@ mod value_input_label; pub use cache::Cache; pub use cooked::Cooked; -pub use graph_execution::cook; +pub use graph_execution::{cook, graph_output_size}; pub use graph_output::{output_usage, outputs}; pub use node_execution::error_image; pub use node_output::NodeOutput; @@ -36,6 +38,7 @@ pub use node_size::node_size; pub use options::Options; pub use port::Port; pub use ports::{identifier, instance_graph, ports, ports_with_connections}; +pub use preview_sampling::PreviewSampling; pub use resolved_base_parameters::ResolvedBaseParameters; pub use resource_decoder::ResourceDecoder; pub use time::now_ms; diff --git a/crates/eval/src/node_execution.rs b/crates/eval/src/node_execution.rs index 2ffeb294..a7bd0d3a 100644 --- a/crates/eval/src/node_execution.rs +++ b/crates/eval/src/node_execution.rs @@ -2,18 +2,38 @@ use crate::{Cache, Cooked, NodeOutput, NodeResult, Options, identifier, now_ms}; use crate::{ cache_key::{graph_tree_hash_with_registry, hash_of, image_key, variable_key}, graph_instance::cook_instance, - parameter::resolve_parameters, + parameter::{ResolvedParameters, inspection_parameters, resolve_parameters}, prepared_graph::PreparedGraph, value_execution::evaluate_value, }; use craft_texture::{Image, Kind}; -use materialcraft_core::{Node, Package, Value}; -use materialcraft_nodes::{CookContext, find}; +use materialcraft_core::{Node, OutputFormat, Package, Value}; +use materialcraft_nodes::{CookContext, GraphVariables, find}; use std::{ collections::BTreeMap, sync::{Arc, Mutex}, }; +struct BoundVariables<'a> { + values: &'a BTreeMap, + fixed: &'a [String], + assigned_integers: &'a [String], +} + +impl GraphVariables for BoundVariables<'_> { + fn graph_values(&self) -> &BTreeMap { + self.values + } + + fn literal_inputs(&self) -> &[String] { + self.fixed + } + + fn assigned_integers(&self) -> &[String] { + self.assigned_integers + } +} + /// The magenta image a failed node shows pub fn error_image(w: u32, h: u32) -> Image { Image::filled(w, h, Kind::Color, [1.0, 0.0, 1.0, 1.0]) @@ -34,34 +54,33 @@ pub(crate) fn cook_node( options: &Options, input_image: Option<&Image>, cache: &Mutex, + previous: Option<&crate::PreviewSampling>, + sampling: &mut crate::PreviewSampling, ) -> NodeResult { let (input_ports, output_ports) = prepared.ports(node.id); let definition = find(&node.def); // Gather inputs by port order, with their keys let mut inputs = Vec::new(); + let mut input_formats = Vec::new(); let mut incoming = Vec::new(); let mut input_keys = Vec::new(); + let mut base_level_only = [false; materialcraft_nodes::MAX_IMAGE_INPUTS + 1]; + let mut background_source = None; let mut variables = std::borrow::Cow::Borrowed(graph_variables); + let mut fixed = std::borrow::Cow::Borrowed(options.literal_inputs.as_slice()); let mut input_error = None; for port in input_ports { - let source = prepared.index.input_of(node.id, &port.id).and_then(|connection| { + let connection = prepared.index.input_of(node.id, &port.id); + let source = connection.and_then(|connection| { let result = cooked.nodes.get(&connection.from)?; let index = prepared.ports(connection.from).1.iter().position(|output| output.id == connection.from_port)?; - Some((result.outputs.get(index)?, result.key ^ hash_of(&index))) + Some((result.outputs.get(index)?, result.key ^ hash_of(&index), result.output_base(index)?)) }); input_keys.push(source.as_ref().map_or(0, |source| source.1)); let output = source.map(|source| source.0); - let expected = node.input_values.get(&port.id).copied().or_else(|| { - node.instance - .as_ref()? - .inputs - .iter() - .find(|input| input.identifier == port.id) - .and_then(|input| materialcraft_core::ValueType::from_code(input.type_code)) - }); - if let Some(expected) = expected { + if let Some(expected) = port.value_type { let value = match output.as_ref() { Some(NodeOutput::Value(value)) if materialcraft_core::ValueType::of(value) == Some(expected) => value.clone(), Some(_) => { @@ -72,22 +91,65 @@ pub(crate) fn cook_node( }; variables.to_mut().insert(port.id.clone(), value); + if fixed.contains(&port.id) { + fixed.to_mut().retain(|name| name != &port.id); + } } else { if output.as_ref().is_some_and(|output| output.as_value().is_some()) && !matches!(node.def.as_str(), "output" | "dot") { input_error = Some(format!("input `{}` requires an image", port.id)); } - inputs.push(output.and_then(NodeOutput::as_image).cloned()); + let wired = if options.depth != 0 && matches!(node.def.as_str(), "pixel_processor" | "value_processor" | "fx_map" | "blur" | "directional_blur") { + connection.and_then(|edge| prepared.index.node(edge.from)).and_then(|bridge| wired_texture(options, bridge)) + } else { + None + }; + if node.def == "fx_map" + && let Some(level) = base_level_only.get_mut(incoming.len()) + { + *level = wired.map_or(matches!(output, Some(NodeOutput::BaseLevel(_))), |(_, _, base_level)| base_level); + if port.id == "background" { + background_source = if wired.is_some() { + connection.and_then(|edge| prepared.index.node(edge.from)).and_then(|bridge| options.input_bases.get(&identifier(bridge))).copied() + } else { + source.map(|(_, _, base)| base) + }; + } + } + let stored = source.and_then(|(output, _, base)| output.texture(base.format)); + let image = wired.map(|(image, format, _)| (image, format)).or(stored); + inputs.push(image.map(|(image, _)| image.clone())); + input_formats.push(image.map_or(OutputFormat::F32, |(_, format)| format)); } - incoming.push(output); + incoming.push(source.map(|(output, _, base)| (output, base))); } - let input_base = prepared.input_base(node.id, cooked); - let (mut base, base_values, base_error) = match crate::resolved_base_parameters::evaluate(&node.base, input_base, prepared.parent_base, &mut variables) { - Ok((base, values)) => (base, values, None), - Err(error) => (crate::ResolvedBaseParameters::resolve(&node.base, input_base, prepared.parent_base), BTreeMap::new(), Some(error)), - }; + let input_base = prepared.input_base(node.id, cooked).or_else(|| { + if !matches!(node.def.as_str(), "input_color" | "input_grayscale") { + return None; + } + let source = options.input_bases.get(&identifier(node))?; + // Relative-to-input size follows this wire. The bridge still resolves its own storage precision. + Some(crate::ResolvedBaseParameters { + size: source.size, + size_underflow: source.size_underflow, + dynamic_size: source.dynamic_size, + bound_size: source.bound_size, + pixel_size: source.pixel_size, + pixel_ratio: source.pixel_ratio, + tiling: source.tiling, + bound_image: source.bound_image, + ..prepared.parent_base + }) + }); + let mut assigned_integers = Vec::new(); + let mut pattern_writes = (node.def == "fx_map").then_some(&mut assigned_integers); + let (mut base, base_values, base_error) = + match crate::resolved_base_parameters::evaluate(&node.base, input_base, prepared.parent_base, &mut variables, &fixed, pattern_writes.as_deref_mut()) { + Ok((base, values)) => (base, values, None), + Err(error) => (crate::ResolvedBaseParameters::resolve(&node.base, input_base, prepared.parent_base), BTreeMap::new(), Some(error)), + }; if node.disabled && let Some(input) = input_base @@ -101,14 +163,15 @@ pub(crate) fn cook_node( base_values: base_values.clone(), parameters: BTreeMap::new(), outputs: Arc::new(vec![NodeOutput::Image(error_image(w, h)); output_ports.len().max(1)]), + output_bases: None, error: Some(message), ms: 0.0, key, cached: false, }; - if let Some(error) = base_error { - return fail(error, 0); + if let Some(error) = prepared.base_error.as_ref().or(base_error.as_ref()) { + return fail(error.clone(), 0); } if let Some(error) = input_error { @@ -116,21 +179,73 @@ pub(crate) fn cook_node( } if !node.functions.is_empty() - || matches!(node.def.as_str(), "pixel_processor" | "value_processor" | "fx_map" | "transformation" | "blur" | "directional_blur" | "sharpen") + || matches!( + node.def.as_str(), + "pixel_processor" + | "value_processor" + | "fx_map" + | "transformation" + | "blend" + | "levels" + | "blur" + | "directional_blur" + | "directional_warp" + | "warp" + | "sharpen" + | "distance" + | "emboss" + ) { base.variables(variables.to_mut()); } let seed = base.seed; - let mut parameters = match resolve_parameters(package, node, definition, &mut variables, seed, base.size) { - Ok(parameters) => parameters, - Err(error) => return fail(error, 0), + let ResolvedParameters { values: mut parameters, instance_literals, dynamic_blend_opacity, bound_image_property } = + match resolve_parameters(package, node, definition, &mut variables, base, &fixed, pattern_writes) { + Ok(parameters) => parameters, + Err(error) => return fail(error, 0), + }; + let bound_image = if node.disabled { + base.bound_image + } else { + base.bound_size + || bound_image_property + || dynamic_blend_opacity + || (node.def == "fx_map" && base.bound_seed) + || input_base.is_some_and(|source| source.bound_image) + || incoming.iter().flatten().any(|(_, source)| source.bound_image) }; + let base = crate::ResolvedBaseParameters { bound_image, ..base }; + let background_tiling = background_source.filter(|source| source.dynamic_size == base.dynamic_size).map(|source| source.tiling); + if matches!(node.def.as_str(), "blur" | "emboss") { + variables.to_mut().insert("$pixelsize".into(), Value::Float2(base.pixel_size)); + } let variables = &variables; + let bindings = BoundVariables { values: variables, fixed: &fixed, assigned_integers: &assigned_integers }; let tile = base.tiling[0] && base.tiling[1]; - let resource_hash = match parameters.get("resource") { + // Reuse the graph's decoded input while retaining its storage and binding metadata. + let input_image = input_image.map(|image| { + let name = identifier(node); + if options.inputs.contains_key(&name) { + let format = options.input_formats.get(&name).copied(); + return (image.clone(), format, options.bitmap_formats.get(&name).copied(), options.base_level_inputs.contains(&name)); + } + let bitmap = if image.integer_sampling() { + package + .graphs + .get(graph_index) + .and_then(|graph| graph.input_images.get(&name)) + .and_then(|binding| package.resource(binding)) + .and_then(|resource| materialcraft_core::png_sample_format(resource.bytes.as_slice())) + } else { + None + }; + (image.clone(), None, bitmap, false) + }); + let wired = options.depth != 0 && input_image.as_ref().is_some_and(|(_, upstream, _, _)| upstream.is_some()); + let resource_hash = match parameters.get(crate::cache_key::resource_parameter(node)) { Some(Value::Text(name)) => package.resource(name).map_or(0, |r| r.bytes.content_hash()), _ => 0, }; @@ -142,94 +257,242 @@ pub(crate) fn cook_node( 0 }; - let key = hash_of(&( + let mut key = hash_of(&( &node.def, serde_json::to_string(¶meters).unwrap_or_default(), - (w, h, seed, tile, node.disabled, base.size, base.format, base.tiling, base.pixel_ratio, base.pixel_size.map(f32::to_bits)), + (dynamic_blend_opacity, bound_image, background_tiling), + ( + w, + h, + seed, + tile, + node.disabled, + base.size, + base.size_underflow, + (base.dynamic_size, base.bound_size), + base.format, + base.tiling, + base.pixel_ratio, + base.pixel_size.map(f32::to_bits), + ), &input_keys, resource_hash, subgraph_hash, - // A cached graph instance includes results evaluated with its host environment - (node.def == "graph_instance").then(|| serde_json::to_string(&options.environment).unwrap_or_default()), - input_image.map(|image| image_key(image, cache)), - variable_key(node, ¶meters, variables), + // Child outputs can exceed the instance size, so their cap is independent of w/h. + (node.def == "graph_instance").then(|| (options.max_size, serde_json::to_string(&options.environment).unwrap_or_default())), + input_image.as_ref().map(|(image, upstream, bitmap, base_level)| (image_key(image, cache), upstream, bitmap, wired, base_level)), + (variable_key(node, ¶meters, &bindings), &instance_literals), )); + if options.previous_sampling.is_some() && input_image.is_some() { + let name = identifier(node); + if let Some(&upstream) = options.preview_input_keys.get(&name) { + key = hash_of(&(key, upstream)); + } else if let Some(graph) = package.graphs.get(graph_index) + && let Some(binding) = graph.input_images.get(&name) + { + key = hash_of(&(key, binding, graph.input_images_linear.contains(&name), graph.input_images_from_file.contains(&name))); + } + } + let instance_input_key = key; + if options.previous_sampling.is_some() && !node.disabled { + if node.def == "graph_instance" { + key = sampling.reuse_instance(previous, node.id, key); + } else if node.def == "fx_map" && base_level_only.contains(&true) { + key = sampling.stamp(previous, node.id, key, &input_keys, &mut base_level_only); + } + } if let Some(outputs) = lock(cache).get(key) { - parameters.retain(|_, value| materialcraft_core::ValueType::of(value).is_some()); - return NodeResult { base, base_values, parameters, outputs, error: None, ms: 0.0, key, cached: true }; + inspection_parameters(node, &mut parameters); + let base = outputs.bases.as_deref().and_then(|ports| ports.first()).copied().unwrap_or(base); + return NodeResult { base, base_values, parameters, outputs: outputs.values, output_bases: outputs.bases, error: None, ms: 0.0, key, cached: true }; } let started_ms = now_ms(); + let mut output_bases: Option> = None; let result: Result, String> = if node.disabled { - let input = if let Some(primary) = definition.and_then(|definition| definition.primary_input) { + let input = if let Some(primary) = definition.and_then(|definition| definition.bypass_input) { input_ports.iter().position(|port| port.id == primary).and_then(|index| incoming.get(index)).copied().flatten() } else { incoming.iter().find_map(|output| *output) }; - let output = input.cloned().unwrap_or_else(|| NodeOutput::Image(Image::filled(w, h, Kind::Gray, [0.0; 4]))); + let output = input.map(|(output, _)| output.clone()).unwrap_or_else(|| NodeOutput::Image(Image::filled(w, h, Kind::Gray, [0.0; 4]))); Ok(vec![output; output_ports.len().max(1)]) } else if node.def == "input_value" { let value = variables.get(&identifier(node)).or_else(|| parameters.get("default")).cloned().unwrap_or(Value::Float(0.0)); Ok(vec![NodeOutput::Value(value)]) } else if node.def == "value_processor" { - evaluate_value(¶meters, variables, seed, [w, h], &inputs, tile).map(|value| vec![NodeOutput::Value(value)]) - } else if matches!(node.def.as_str(), "output" | "dot") && incoming.first().and_then(Option::as_ref).is_some_and(|output| output.as_value().is_some()) { - incoming.first().copied().flatten().cloned().map(|output| vec![output]).ok_or("missing value input".into()) - } else if let Some(image) = input_image { - let mut image = if node.def == "input_grayscale" && image.kind() == Kind::Color { - // Grayscale bridges use equal RGB weights and preserve fused float order - let weight = 1.0 / 3.0; - image.map(Kind::Gray, |pixel| [pixel[2].mul_add(weight, pixel[1].mul_add(weight, pixel[0] * weight)), 0.0, 0.0, 0.0]) - } else if node.def == "input_color" { - image.to_color() - } else { - image.clone() - }; - - // Bound resources clamp edges through stored factor-two levels - // Preserve resampling and storage conversion for HDR bridges - let resized = image.width() != w || image.height() != h; - while image.width() != w || image.height() != h { - let next = |current: u32, target: u32| { - if current < target { current.saturating_mul(2).min(target) } else { current.div_ceil(2).max(target) } + evaluate_value(¶meters, &bindings, seed, [w, h], &inputs, &input_formats, tile).map(|value| vec![NodeOutput::Value(value)]) + } else if matches!(node.def.as_str(), "output" | "dot") + && let Some(Some((output, _))) = incoming.first() + && (output.as_value().is_some() + || matches!(output, NodeOutput::BaseLevel(stored) | NodeOutput::BoundBitmap { stored, .. } if (stored.width(), stored.height()) == (w, h))) + { + Ok(vec![(*output).clone()]) + } else if let Some((image, upstream, bitmap, inherited_base_level)) = input_image { + let kind = if node.def == "input_grayscale" { Kind::Gray } else { Kind::Color }; + let format = upstream.unwrap_or(OutputFormat::F32); + let source = bitmap.unwrap_or(format); + let external = if wired { None } else { crate::external_image::resize(&image, (w, h), kind, source, base.format) }; + let tiling = if wired { base.tiling } else { [false; 2] }; + let output = external.unwrap_or_else(|| { + let base_level = if wired { + inherited_base_level && image.kind() == kind && (image.width(), image.height()) == (w, h) && format == base.format + } else { + crate::external_image::base_level_only(&image, (w, h), kind, source, base.format) }; - image = crate::output_precision::apply(image.resize(next(image.width(), w), next(image.height(), h), false), base.format); - } - - // Resized inputs already store the final level at the declared precision - let image = if resized { image } else { crate::output_precision::apply(image, base.format) }; - Ok(vec![NodeOutput::Image(image)]) + let resize = if wired { materialcraft_nodes::resize_connected_image } else { materialcraft_nodes::resize_bound_image }; + let image = resize(image, (w, h), kind, format, base.format, tiling); + if base_level { NodeOutput::BaseLevel(image) } else { NodeOutput::Image(image) } + }); + Ok(vec![output]) } else if node.def == materialcraft_core::MISSING_NODE { let name = if node.label.is_empty() { "this node" } else { node.label.as_str() }; Err(format!("unsupported node `{name}`")) } else if node.def == "graph_instance" { - cook_instance(package, graph_index, node, input_ports, output_ports, &incoming, ¶meters, (w, h), base, options, cache) - } else if let Some(definition) = definition { - let context = CookContext { format: base.format, w, h, seed, tile, inputs: &inputs, params: ¶meters, resource: options.resource, vars: variables }; - (definition.cook)(&context).map(|images| { - images - .into_iter() - .map(|image| { - // Bridges retain their source pixels; filters store their declared precision - let image = if matches!(node.def.as_str(), "output" | "dot") { image } else { crate::output_precision::apply(image, base.format) }; - NodeOutput::Image(image) - }) - .collect() + cook_instance( + package, + graph_index, + node, + input_ports, + output_ports, + &incoming, + &input_keys, + ¶meters, + &instance_literals, + base, + options, + cache, + previous.and_then(|p| p.child(node.id)), + ) + .map(|instance| { + if let Some((child, outputs)) = instance.sampling { + key = hash_of(&(instance_input_key, outputs)); + sampling.record_instance(node.id, instance_input_key, key, child); + } + let (values, bases): (Vec<_>, Vec<_>) = instance.ports.into_iter().unzip(); + output_bases = Some(bases.into()); + values }) + } else if let Some(definition) = definition { + if let (Some(tiling), Some(Some(image)), Some(&source)) = (background_tiling, inputs.first_mut(), input_formats.first()) + && let Some(filtered) = materialcraft_nodes::pattern::direct_background_sample(image, (w, h), source, tiling) + { + *image = filtered; + } + let store_inputs = match base.format { + OutputFormat::F16 => matches!(node.def.as_str(), "blend" | "fx_map" | "levels" | "sharpen" | "blur"), + OutputFormat::F32 => node.def == "blur", + _ => false, + }; + if store_inputs { + // When exactly one size is parameter-controlled, these filters store normalized inputs at their working precision. + // Images stamped by a pattern keep their sampling precision. + for ((image, format), port) in inputs.iter_mut().zip(&mut input_formats).zip(input_ports) { + if (node.def != "fx_map" || port.id == "background") + && matches!(format, OutputFormat::U8 | OutputFormat::U16 | OutputFormat::Inherit) + && let Some(image) = image + && (image.width(), image.height()) == (w, h) + && prepared.source_base(node.id, &port.id, cooked).is_some_and(|source| source.dynamic_size != base.dynamic_size) + { + *image = crate::output_precision::apply(image.clone(), base.format); + if node.def == "blur" { + // Fractional blur taps use the working texture's sampler. + *format = base.format; + } + } + } + } + let context = CookContext { + input_formats: &input_formats, + format: base.format, + w, + h, + seed, + tile, + inputs: &inputs, + params: ¶meters, + resource: options.resource, + vars: &bindings, + }; + if node.def == "bitmap" + && let Some(output) = crate::external_image::resize_bitmap(&context, package) + { + Ok(vec![output]) + } else { + let result = if matches!(node.def.as_str(), "fx_map" | "pixel_processor") { + let drawing = if node.def == "fx_map" { + materialcraft_nodes::pattern::cook_with_image_dependencies(&context, &base_level_only, bound_image) + } else { + materialcraft_nodes::function::pixel_processor_with_dependencies(&context) + }; + drawing.map(|(image, reads_input)| { + // A cached image carries dependencies read by its drawing program along with its pixels. + if reads_input && !bound_image { + output_bases = Some(Arc::from([crate::ResolvedBaseParameters { bound_image: true, ..base }])); + } + vec![image] + }) + } else if node.def == "text" + && !context.text("fontdata").is_empty() + && let Some(font) = package.resource(context.text("fontdata")) + { + materialcraft_nodes::atomic::text_with_font(&context, font.bytes.as_slice()) + } else if dynamic_blend_opacity { + materialcraft_nodes::atomic::blend_with_opacity(&context, true) + } else { + (definition.cook)(&context) + }; + let selected = if node.def == "blend" && !dynamic_blend_opacity { + materialcraft_nodes::atomic::blend_selected_input(&context).and_then(|slot| incoming.get(slot).copied().flatten()) + } else { + None + }; + result.map(|images| { + images + .into_iter() + .map(|image| { + // Bridges retain their source pixels; filters store their declared precision + let image = if matches!(node.def.as_str(), "output" | "dot") { image } else { crate::output_precision::apply(image, base.format) }; + // A Blend that selects a compatible texture retains its available sampling levels. + if let Some((NodeOutput::BaseLevel(source), source_base)) = selected + && source_base.format == base.format + && source.kind() == image.kind() + && (source.width(), source.height()) == (w, h) + { + return NodeOutput::BaseLevel(image); + } + NodeOutput::Image(image) + }) + .collect() + }) + } } else { Err(format!("unknown node `{}`", node.def)) }; // Cooked values serve parameter controls; authoring graphs stay in the document - parameters.retain(|_, value| materialcraft_core::ValueType::of(value).is_some()); + inspection_parameters(node, &mut parameters); match result { Ok(outputs) if outputs.len() == output_ports.len().max(1) || output_ports.is_empty() => { let outputs = Arc::new(outputs); - lock(cache).put(key, outputs.clone()); - NodeResult { base, base_values, parameters, outputs, error: None, ms: (now_ms() - started_ms) as f32, key, cached: false } + lock(cache).put(key, outputs.clone(), output_bases.clone()); + let base = output_bases.as_deref().and_then(|ports| ports.first()).copied().unwrap_or(base); + NodeResult { base, base_values, parameters, outputs, output_bases, error: None, ms: (now_ms() - started_ms) as f32, key, cached: false } } Ok(outputs) => fail(format!("`{}` made {} images for {} outputs", node.def, outputs.len(), output_ports.len()), key), Err(error) => fail(error, key), } } + +// Image reads inside an instance retain the caller texture's dimensions, depth and available mip levels. +fn wired_texture<'a>(options: &'a Options<'_>, bridge: &Node) -> Option<(&'a Image, OutputFormat, bool)> { + let kind = match bridge.def.as_str() { + "input_color" => Kind::Color, + "input_grayscale" => Kind::Gray, + _ => return None, + }; + let name = identifier(bridge); + let image = options.inputs.get(&name)?; + (!bridge.disabled && image.kind() == kind).then_some((image, *options.input_formats.get(&name)?, options.base_level_inputs.contains(&name))) +} diff --git a/crates/eval/src/node_output.rs b/crates/eval/src/node_output.rs index 15d6e66b..0c2f924c 100644 --- a/crates/eval/src/node_output.rs +++ b/crates/eval/src/node_output.rs @@ -1,30 +1,50 @@ use craft_texture::Image; -use materialcraft_core::Value; +use materialcraft_core::{OutputFormat, Value}; +use std::sync::Arc; #[derive(Clone, Debug, PartialEq)] pub enum NodeOutput { Image(Image), + /// A resized external texture whose automatic filtering can only sample its base level. + BaseLevel(Image), + /// A bound bitmap can report its bridge precision while filters sample its original integer texture. + BoundBitmap { + stored: Image, + texture: Image, + texture_format: OutputFormat, + }, Value(Value), } impl NodeOutput { pub fn as_image(&self) -> Option<&Image> { match self { - Self::Image(image) => Some(image), + Self::Image(image) | Self::BaseLevel(image) | Self::BoundBitmap { stored: image, .. } => Some(image), Self::Value(_) => None, } } pub fn as_value(&self) -> Option<&Value> { match self { - Self::Image(_) => None, + Self::Image(_) | Self::BaseLevel(_) | Self::BoundBitmap { .. } => None, Self::Value(value) => Some(value), } } - pub(crate) fn memory_bytes(&self) -> usize { + pub(crate) fn texture(&self, declared: OutputFormat) -> Option<(&Image, OutputFormat)> { match self { - Self::Image(image) => image.data().len().saturating_mul(size_of::()), + Self::BoundBitmap { texture, texture_format, .. } => Some((texture, *texture_format)), + Self::Image(image) | Self::BaseLevel(image) => Some((image, declared)), + Self::Value(_) => None, + } + } + + pub(crate) fn memory_bytes(&self) -> usize { + let bytes = |image: &Image| image.data().len().saturating_mul(size_of::()); + match self { + Self::Image(image) | Self::BaseLevel(image) => bytes(image), + Self::BoundBitmap { stored, texture, .. } if Arc::ptr_eq(stored.shared_data(), texture.shared_data()) => bytes(stored), + Self::BoundBitmap { stored, texture, .. } => bytes(stored).saturating_add(bytes(texture)), Self::Value(Value::Text(text)) => size_of::().saturating_add(text.len()), Self::Value(_) => size_of::(), } diff --git a/crates/eval/src/node_result.rs b/crates/eval/src/node_result.rs index 6dff9e3e..f79b465f 100644 --- a/crates/eval/src/node_result.rs +++ b/crates/eval/src/node_result.rs @@ -10,9 +10,18 @@ pub struct NodeResult { pub parameters: std::collections::BTreeMap, /// One image per output port (empty when the cook failed) pub outputs: Arc>, + /// Instance ports carry the dimensions, format and sampling properties of their source. + pub output_bases: Option>, pub error: Option, /// Cook time in milliseconds (0 when served from the cache) pub ms: f32, pub key: u64, pub cached: bool, } + +impl NodeResult { + pub fn output_base(&self, index: usize) -> Option { + self.outputs.get(index)?; + Some(self.output_bases.as_deref().and_then(|ports| ports.get(index)).copied().unwrap_or(self.base)) + } +} diff --git a/crates/eval/src/node_size.rs b/crates/eval/src/node_size.rs index ac6823dc..6d0bd8ea 100644 --- a/crates/eval/src/node_size.rs +++ b/crates/eval/src/node_size.rs @@ -3,7 +3,13 @@ use materialcraft_nodes::NodeDefinition; /// Literal output size; cooking also evaluates any attached parameter function pub fn node_size(graph: &Graph, definition: Option<&NodeDefinition>, node: &Node, input: Option<(u32, u32)>, maximum: Option) -> (u32, u32) { - let parent = crate::ResolvedBaseParameters { size: graph.size_px(), ..Default::default() }; + if node.disabled + && let Some((width, height)) = input + { + return limit([width, height], maximum); + } + let (size, size_underflow) = graph.resolved_output_size(None, None); + let parent = crate::ResolvedBaseParameters { size, size_underflow, ..Default::default() }; let input = input .filter(|_| !definition.is_some_and(|definition| definition.generator)) .map(|(width, height)| crate::ResolvedBaseParameters { size: [width, height], ..parent }); diff --git a/crates/eval/src/options.rs b/crates/eval/src/options.rs index 9beb3f06..ff93046a 100644 --- a/crates/eval/src/options.rs +++ b/crates/eval/src/options.rs @@ -1,9 +1,10 @@ use craft_texture::Image; -use materialcraft_core::{NodeId, Value}; -use std::collections::BTreeMap; +use materialcraft_core::{NodeId, OutputFormat, Value}; +use std::collections::{BTreeMap, BTreeSet}; use std::sync::atomic::AtomicBool; /// What to cook and how +#[derive(Clone)] pub struct Options<'a> { pub environment: materialcraft_core::EvaluationEnvironment, pub parent_tiling: Option<[bool; 2]>, @@ -15,8 +16,21 @@ pub struct Options<'a> { pub only: Option>, /// Images for the graph's input nodes, by identifier (graph instances) pub inputs: BTreeMap, + /// Upstream storage precision for caller-supplied images. Unspecified floating inputs use full precision. + pub input_formats: BTreeMap, + /// Resolved source properties for each image wired to a graph instance. + pub input_bases: BTreeMap, + /// Caller textures which have only their base level when passed through an instance. + pub base_level_inputs: BTreeSet, + /// Previously accepted samples for this editor graph. Full cooks start without editor state. + pub previous_sampling: Option<&'a crate::PreviewSampling>, + pub(crate) preview_input_keys: BTreeMap, + /// Original storage of decoded external files. Wired graph inputs use their upstream format. + pub bitmap_formats: BTreeMap, /// Values for the graph's exposed parameters (graph instances), over the graph's own pub overrides: BTreeMap, + /// Exposed inputs whose fixed instance arguments can be folded during function evaluation. + pub literal_inputs: Vec, /// Decodes a package resource (bitmap) by name pub resource: &'a crate::ResourceDecoder<'a>, /// Set from another thread to stop between nodes @@ -39,7 +53,14 @@ impl<'a> Options<'a> { max_size: None, only: None, inputs: BTreeMap::new(), + input_formats: BTreeMap::new(), + input_bases: BTreeMap::new(), + base_level_inputs: BTreeSet::new(), + previous_sampling: None, + preview_input_keys: BTreeMap::new(), + bitmap_formats: BTreeMap::new(), overrides: BTreeMap::new(), + literal_inputs: Vec::new(), resource, cancel: None, depth: 0, diff --git a/crates/eval/src/output_precision.rs b/crates/eval/src/output_precision.rs deleted file mode 100644 index 9b1a2408..00000000 --- a/crates/eval/src/output_precision.rs +++ /dev/null @@ -1,61 +0,0 @@ -use craft_texture::{Image, Limits}; -use materialcraft_core::OutputFormat; -use std::sync::Arc; - -pub(crate) fn apply(image: Image, format: OutputFormat) -> Image { - const HALF_FLOAT_MAX: f32 = 65504.0; - const U8_FIXED_SCALE: f64 = 4096.0; - const U16_FIXED_SCALE: f64 = 1_048_576.0; - - let integer = integer_sampling(format); - if format == OutputFormat::F16 { - return with_pixels(image, integer, |pixel| { - // Half-float storage saturates finite overflow and truncates toward zero - // Leaving the f32 unconverted changes every downstream read and export - let value = pixel.clamp(-HALF_FLOAT_MAX, HALF_FLOAT_MAX); - let rounded = half::f16::from_f32(value); - *pixel = if rounded.to_f32().abs() > value.abs() { half::f16::from_bits(rounded.to_bits().saturating_sub(1)).to_f32() } else { rounded.to_f32() }; - }); - } - - let (fraction, maximum) = match format { - OutputFormat::U8 => (U8_FIXED_SCALE, f64::from(u8::MAX)), - OutputFormat::Inherit | OutputFormat::U16 => (U16_FIXED_SCALE, f64::from(u16::MAX)), - OutputFormat::F16 | OutputFormat::F32 => return image.with_integer_sampling(integer), - }; - - with_pixels(image, integer, |pixel| { - // Integer outputs retain four fractional guard bits before conversion - // Halfway-down rounding affects constants and downstream blends - let value = if pixel.is_nan() { 0.0 } else { f64::from(*pixel).clamp(0.0, 1.0) }; - let fixed = (value * fraction).floor() / fraction; - let integer = (fixed * maximum - 0.5).ceil() as u32; - *pixel = integer as f32 / maximum as f32; - }) -} - -pub(crate) fn integer_sampling(format: OutputFormat) -> bool { - matches!(format, OutputFormat::Inherit | OutputFormat::U8 | OutputFormat::U16) -} - -/// `image` with `convert` applied to every float and the integer-sampling flag set. The buffer is -/// changed in place when no other image shares it, and copied once otherwise. -fn with_pixels(image: Image, integer_sampling: bool, convert: impl Fn(&mut f32)) -> Image { - let (width, height, kind) = (image.width(), image.height(), image.kind()); - - // Limits that admit any valid image, so one made with raised limits keeps its size - let mut limits = Limits::default(); - limits.max_side = u32::MAX; - limits.max_pixels = u64::MAX; - limits.max_bytes = u64::MAX; - - let mut data = Arc::clone(image.shared_data()); - drop(image); - - Arc::make_mut(&mut data).iter_mut().for_each(convert); - - // `data` keeps the size and kind of a valid image, so `from_data` accepts it - Image::from_data(width, height, kind, data, &limits) - .unwrap_or_else(|_| Image::filled(width, height, kind, [0.0; 4])) - .with_integer_sampling(integer_sampling) -} diff --git a/crates/eval/src/parameter.rs b/crates/eval/src/parameter.rs index f578411d..4d6682e4 100644 --- a/crates/eval/src/parameter.rs +++ b/crates/eval/src/parameter.rs @@ -1,15 +1,38 @@ -use materialcraft_core::{Node, Package, Value, ValueType}; -use materialcraft_nodes::{NodeDefinition, ParameterDescriptor, clamp_params, resolve_params}; +use crate::{ResolvedBaseParameters, parameter_function::ParameterMode}; +use materialcraft_core::{Node, OutputFormat, Package, Value, ValueType}; +use materialcraft_nodes::function::compile_with_literal_inputs; +use materialcraft_nodes::{NodeDefinition, ParameterDescriptor, accepts_scalar_function, clamp_params, resolve_params}; use std::collections::BTreeMap; +pub(crate) struct ResolvedParameters { + pub values: BTreeMap, + pub instance_literals: Vec, + pub dynamic_blend_opacity: bool, + pub bound_image_property: bool, +} + +pub(crate) fn supports_literal_argument(value: &Value) -> bool { + matches!(value, Value::Int(_) | Value::Float(_) | Value::Float2(_) | Value::Float3(_) | Value::Float4(_)) +} + +// The color cook needs the operand's original width and whether its channels were folded. +fn uniform_color_operand(value: &Value, literal: bool) -> Option { + match value { + Value::Float(_) | Value::Float3(_) => Some(value.clone()), + Value::Float4(rgba) | Value::Color(rgba) => Some(if literal { Value::Color(*rgba) } else { Value::Float4(*rgba) }), + _ => None, + } +} + pub(crate) fn resolve_parameters( package: &Package, node: &Node, definition: Option<&NodeDefinition>, variables: &mut std::borrow::Cow<'_, BTreeMap>, - seed: u32, - size: [u32; 2], -) -> Result, String> { + base: ResolvedBaseParameters, + literal_inputs: &[String], + mut assigned_integers: Option<&mut Vec>, +) -> Result { let mut parameters = match definition { Some(definition) if node.def != "graph_instance" => resolve_params(definition, &node.params), _ => { @@ -27,35 +50,293 @@ pub(crate) fn resolve_parameters( } } + let mut dynamic = std::collections::BTreeSet::new(); + let mut dynamic_blend_opacity = false; + let mut bound_image_property = false; + let mut bound_mip_level = false; + let mut record_drawing_input = |name: &str| match (node.def.as_str(), name) { + ("blend", "opacity") => dynamic_blend_opacity = true, + ("transformation", "mip_level") => bound_mip_level = true, + ("transformation", "matte") if base.tiling != [true; 2] => bound_image_property = true, + ("uniform", "color") + | ("blur" | "directional_blur" | "warp", "intensity") + | ("directional_blur", "angle") + | ("transformation", "offset" | "matrix") + | ("grayscale_conversion", "weights" | "matte") + | ("levels", "in_low" | "in_mid" | "in_high" | "out_low" | "out_high") + | ("fx_map", "opacity" | "roughness" | "background" | "render_region" | "tiling_region") => bound_image_property = true, + _ => {} + }; + let mut uniform_color = None; for (parameter, exposed) in &node.bindings { + if node.def == "uniform" && parameter == "color" { + uniform_color = variables.get(exposed).and_then(|value| uniform_color_operand(value, false)); + } + if node.def == "graph_instance" && !literal_inputs.contains(exposed) { + dynamic.insert(parameter); + } if let (Some(value), Some(current)) = (variables.get(exposed), parameters.get(parameter)) && let Some(coerced) = current.coerce_json(&serde_json::to_value(value).unwrap_or_default()) { + if !literal_inputs.contains(exposed) && !node.functions.contains_key(parameter) { + record_drawing_input(parameter); + } parameters.insert(parameter.clone(), coerced); } } + let mut gray_pattern_opacity = None; for (parameter, function) in &node.functions { let current = parameters.get(parameter).ok_or_else(|| format!("unknown function parameter `{parameter}`"))?; let expected = ValueType::of(current).ok_or_else(|| format!("parameter `{parameter}` cannot have a function"))?; - let allow_scalar = materialcraft_nodes::accepts_scalar_function(&node.def, parameter); - let value = crate::parameter_function::evaluate(function, expected, variables.to_mut(), seed, size, allow_scalar) + let mode = match (node.def.as_str(), parameter.as_str(), base.format) { + ("uniform", "color", _) => ParameterMode::UniformColor, + ("levels", name, format) if accepts_scalar_function("levels", name) => { + ParameterMode::Levels { normalized: name != "in_mid" && matches!(format, OutputFormat::U8 | OutputFormat::U16 | OutputFormat::Inherit) } + } + ("fx_map", "background", _) if matches!(current, Value::Float4(_)) => ParameterMode::Broadcast, + ("fx_map", "opacity", _) if parameters.get("color_mode") == Some(&Value::Bool(false)) => ParameterMode::GrayPatternOpacity, + _ => ParameterMode::Opaque, + }; + let (value, literal) = compile_with_literal_inputs(function, base.seed, literal_inputs) + .and_then(|program| { + if program.reads_graph_parameter(variables) { + record_drawing_input(parameter); + } + crate::parameter_function::evaluate(&program, expected, variables.to_mut(), base.size, mode, Some(current), assigned_integers.as_deref_mut()) + }) .map_err(|error| format!("function of `{parameter}`: {error}"))?; - let value = match (current, value) { - (Value::Float4(_), Value::Float(value)) if allow_scalar => Value::Float4([value; 4]), - (Value::Color(_), Value::Float(value)) if allow_scalar => Value::Float4([value, value, value, 1.0]), - (_, value) => value, + if matches!(mode, ParameterMode::UniformColor) { + uniform_color = uniform_color_operand(&value, literal); + continue; + } + if matches!(mode, ParameterMode::GrayPatternOpacity) { + // Keep the result in floating point until blending. JSON and slider limits lose signed infinities. + gray_pattern_opacity = Some(value); + continue; + } + if node.def == "graph_instance" { + if literal { + dynamic.remove(parameter); + } else { + dynamic.insert(parameter); + } + } + let value = if matches!((&mode, &value), (ParameterMode::Levels { .. }, Value::Float(_))) { + value + } else { + current.coerce_json(&serde_json::to_value(value).unwrap_or_default()).ok_or_else(|| format!("invalid function value for `{parameter}`"))? }; - let value = current.coerce_json(&serde_json::to_value(value).unwrap_or_default()).ok_or_else(|| format!("invalid function value for `{parameter}`"))?; parameters.insert(parameter.clone(), value); } + if let Some(color) = uniform_color { + parameters.insert("color".into(), color); + } // Catalog limits keep values from files and functions within safe cook bounds if let Some(definition) = definition && node.def != "graph_instance" { clamp_params(definition, &mut parameters); } + if let Some(opacity) = gray_pattern_opacity { + parameters.insert("opacity".into(), opacity); + } + // A computed mip mode can appear after the level in the property list. + bound_image_property |= bound_mip_level && parameters.get("mip_mode").and_then(Value::as_i32) == Some(1); - Ok(parameters) + let fixed = if node.def == "graph_instance" { + parameters.iter().filter(|(name, value)| supports_literal_argument(value) && !dynamic.contains(*name)).map(|(name, _)| name.clone()).collect() + } else { + Vec::new() + }; + Ok(ResolvedParameters { values: parameters, instance_literals: fixed, dynamic_blend_opacity, bound_image_property }) +} + +pub(crate) fn inspection_parameters(node: &Node, parameters: &mut BTreeMap) { + parameters.retain(|name, value| { + if node.def == "uniform" && name == "color" { + match value { + Value::Float(level) => *value = Value::Color([*level, *level, *level, 1.0]), + Value::Float3([r, g, b]) => *value = Value::Color([*r, *g, *b, 1.0]), + Value::Float4(rgba) => *value = Value::Color(*rgba), + _ => {} + } + } + if let Value::Float(level) = value + && node.def == "levels" + && accepts_scalar_function("levels", name) + { + *value = Value::Float4([*level, *level, *level, 1.0]); + } + ValueType::of(value).is_some() + }); +} + +#[cfg(test)] +mod tests { + use crate::{Cache, Options, cook}; + use materialcraft_core::{FunctionGraph, Graph, Package, Value, ValueType}; + use std::sync::Mutex; + + #[test] + fn uniform_gray_preserves_the_precision_of_its_color_source() { + use materialcraft_core::OutputFormat; + + let mut graph = Graph::new("Uniform precision"); + graph.size = [2; 2]; + graph.format = OutputFormat::F32; + let uniform = graph.add_node("uniform", [0.0; 2]); + graph.node_mut(uniform).unwrap().params.insert("color_mode".into(), Value::Bool(false)); + let mut package = Package::new("Uniform precision"); + package.graphs.push(graph); + let cache = Mutex::new(Cache::default()); + let mut options = Options::new(&|_| None); + let scalar = Value::Float(f32::from_bits(0x3ed5_1632)); + let rgba = Value::Float4([1.0, f32::EPSILON, -1.0, 0.59375]); + for (value, bound, expected) in [ + (rgba.clone(), false, 0x332a_aaab), + (rgba.clone(), true, 0x3300_0000), + (scalar, true, 0x3ed5_1632), + (Value::Float3([0.125, 0.3125, 0.6875]), true, 0), + (Value::Float4([-65536.0, 65536.0, 0.001953125, 0.5]), false, 0x3a2a_aaab), + (rgba, false, 0x332a_aaab), + ] { + let function = if bound { + let get = FunctionGraph::input("ink", ValueType::of(&value).unwrap()); + options.overrides.insert("ink".into(), value); + get + } else { + FunctionGraph::constant(value) + }; + package.graphs[0].node_mut(uniform).unwrap().functions.insert("color".into(), function); + let cooked = cook(&package, 0, &options, &cache); + assert_eq!(cooked.nodes[&uniform].error, None); + assert_eq!(cooked.image(uniform, 0).unwrap().get_gray(0, 0, false).to_bits(), expected); + } + } + + #[test] + fn grayscale_uniform_distinguishes_image_size_from_an_exposed_color_read() { + use materialcraft_core::OutputFormat; + + let mut graph = Graph::new("Uniform sources"); + graph.size = [2; 2]; + graph.format = OutputFormat::F32; + let uniform = graph.add_node("uniform", [0.0; 2]); + graph.node_mut(uniform).unwrap().params.insert("color_mode".into(), Value::Bool(false)); + let mut package = Package::new("Uniform sources"); + package.graphs.push(graph); + let cache = Mutex::new(Cache::default()); + let mut options = Options::new(&|_| None); + options.overrides.insert("ink".into(), Value::Float4([0.25; 4])); + + for (variable, ty, expected) in [ + ("$size", ValueType::Float2, 0x332a_aaab), + ("$pixelratio", ValueType::Integer, 0x332a_aaab), + ("$uvtile", ValueType::Integer2, 0x332a_aaab), + ("$physicalsize", ValueType::Float3, 0x332a_aaab), + ("unbound_color", ValueType::Float, 0x332a_aaab), + ("$time", ValueType::Float, 0x3300_0000), + ("$normalformat", ValueType::Integer, 0x3300_0000), + ("ink", ValueType::Float4, 0x3300_0000), + ] { + let mut function = FunctionGraph::input(variable, ty); + let read = function.output.unwrap(); + let rgba = function.add_constant(Value::Float4([1.0, f32::EPSILON, -1.0, 0.59375])); + function.output = Some(function.add("sequence", &[read, rgba], None)); + package.graphs[0].node_mut(uniform).unwrap().functions.insert("color".into(), function); + let cooked = cook(&package, 0, &options, &cache); + assert_eq!(cooked.nodes[&uniform].error, None); + assert_eq!(cooked.image(uniform, 0).unwrap().get_gray(0, 0, false).to_bits(), expected); + } + } + + #[test] + fn uniform_color_keeps_hdr_channels_and_distinguishes_an_explicit_alpha() { + use materialcraft_core::OutputFormat; + + let mut graph = Graph::new("Uniform channels"); + graph.size = [2; 2]; + graph.format = OutputFormat::F32; + let uniform = graph.add_node("uniform", [0.0; 2]); + let mut package = Package::new("Uniform channels"); + package.graphs.push(graph); + let cache = Mutex::new(Cache::default()); + let mut options = Options::new(&|_| None); + let rgb = [-65536.0, 65536.0, 0.001953125]; + options.overrides.insert("ink".into(), Value::Float3(rgb)); + let direct = FunctionGraph::input("ink", ValueType::Float3); + let mut with_alpha = direct.clone(); + let color = with_alpha.output.unwrap(); + let alpha = with_alpha.add_constant(Value::Float(0.59375)); + with_alpha.output = Some(with_alpha.add("vector4", &[color, alpha], None)); + for (function, expected) in [(direct, [0.0, 0.0, 0.0, 1.0]), (with_alpha, [rgb[0], rgb[1], rgb[2], 0.59375])] { + package.graphs[0].node_mut(uniform).unwrap().functions.insert("color".into(), function); + let cooked = cook(&package, 0, &options, &cache); + assert_eq!(cooked.nodes[&uniform].error, None); + assert_eq!(cooked.image(uniform, 0).unwrap().get(0, 0, false), expected); + } + } + + #[test] + fn gray_levels_keep_scalar_endpoints_distinct_from_equal_rgb_controls() { + use craft_texture::Image; + use materialcraft_core::OutputFormat; + + let mut graph = Graph::new("Endpoint precision"); + graph.size = [2, 2]; + graph.format = OutputFormat::F32; + let source = graph.add_node("input_grayscale", [0.0; 2]); + let levels = graph.add_node("levels", [0.0; 2]); + graph.connect(source, "output", levels, "input").unwrap(); + let mut package = Package::new("Endpoint precision"); + package.graphs.push(graph); + let mut options = Options::new(&|_| None); + options.inputs.insert("input".into(), Image::gray(4, 4, |_, _| 1.0)); + let cache = Mutex::new(Cache::default()); + + let scalar = f32::from_bits(0x3ec0c0c2); + let rgba = [scalar, scalar, scalar, 1.0]; + let vector_result = f32::from_bits(0x3ec0c0c3); + for (value, expected) in [(Value::Float4(rgba), vector_result), (Value::Float(scalar), scalar), (Value::Float4(rgba), vector_result)] { + package.graphs[0].node_mut(levels).unwrap().functions.insert("out_high".into(), FunctionGraph::constant(value)); + let cooked = cook(&package, 0, &options, &cache); + assert_eq!(cooked.nodes[&levels].parameters["out_high"], Value::Float4(rgba)); + assert_eq!(cooked.image(levels, 0).unwrap().get_gray(0, 0, false).to_bits(), expected.to_bits()); + } + } + + #[test] + fn missing_direct_level_link_keeps_the_property_value() { + let mut graph = Graph::new("Matte"); + graph.size = [2; 2]; + let levels = graph.add_node("levels", [0.0; 2]); + let mut package = Package::new("Links"); + package.graphs.push(graph); + let cache = Mutex::new(Cache::default()); + let reader = FunctionGraph::input("%amount", ValueType::Float); + let mut disconnected = reader.clone(); + disconnected.add_constant(Value::Float(0.75)); + let mut computed = reader.clone(); + let value = computed.output.unwrap(); + let offset = computed.add_constant(Value::Float(0.1875)); + computed.output = Some(computed.add("add", &[value, offset], None)); + + for (function, bound, expected) in [ + (reader.clone(), None, [1.0; 4]), + (disconnected, None, [1.0; 4]), + (reader, Some(0.0), [0.0, 0.0, 0.0, 1.0]), + (computed, None, [0.1875, 0.1875, 0.1875, 1.0]), + ] { + package.graphs[0].node_mut(levels).unwrap().functions.insert("out_high".into(), function); + let mut options = Options::new(&|_| None); + if let Some(level) = bound { + options.overrides.insert("amount".into(), Value::Float(level)); + } + let cooked = cook(&package, 0, &options, &cache); + assert_eq!(cooked.nodes[&levels].error, None); + assert_eq!(cooked.nodes[&levels].parameters.get("out_high"), Some(&Value::Float4(expected))); + } + } } diff --git a/crates/eval/src/parameter_function.rs b/crates/eval/src/parameter_function.rs index e09ce2ff..dcba4d55 100644 --- a/crates/eval/src/parameter_function.rs +++ b/crates/eval/src/parameter_function.rs @@ -1,46 +1,80 @@ -use materialcraft_core::{FunctionGraph, Value, ValueType}; -use materialcraft_nodes::function::{EvaluationContext, EvaluationState, compile}; +use materialcraft_core::{BaseParameter, Value, ValueType}; +use materialcraft_nodes::function::{EvaluationContext, EvaluationState, FunctionScope, Program}; use std::collections::BTreeMap; +#[derive(Clone, Copy)] +pub(crate) enum ParameterMode { + Opaque, + RandomSeed, + Broadcast, + UniformColor, + GrayPatternOpacity, + Levels { normalized: bool }, +} + +impl ParameterMode { + pub(crate) fn for_base(parameter: BaseParameter) -> Self { + if parameter == BaseParameter::RandomSeed { Self::RandomSeed } else { Self::Opaque } + } +} + pub(crate) fn evaluate( - function: &FunctionGraph, + program: &Program, expected: ValueType, variables: &mut BTreeMap, - seed: u32, size: [u32; 2], - allow_scalar: bool, -) -> Result { - let program = compile(function, seed)?; - let scalar_channel = allow_scalar && expected == ValueType::Float4 && program.output_type() == ValueType::Float as u32; - - // A color parameter also takes a gray level or an opaque RGB triple + mode: ParameterMode, + fallback: Option<&Value>, + assigned_integers: Option<&mut Vec>, +) -> Result<(Value, bool), String> { let widened = expected == ValueType::Float4 && [ValueType::Float as u32, ValueType::Float3 as u32].contains(&program.output_type()); - if program.output_type() != expected as u32 && !scalar_channel && !widened { + if program.output_type() != expected as u32 && !widened { return Err(format!("output must be {}", expected.label())); } - - let context = EvaluationContext { scope: Default::default(), position: [0.5; 2], size: size.map(|side| side as f32), images: &[], tile: true, variables }; - let mut state = EvaluationState::default(); - let value = program.evaluate(&context, &mut state)?; - let finite = match &value { - Value::Float(value) => value.is_finite(), - Value::Float2(values) => values.iter().all(|value| value.is_finite()), - Value::Float3(values) => values.iter().all(|value| value.is_finite()), - Value::Float4(values) | Value::Color(values) => values.iter().all(|value| value.is_finite()), - _ => true, - }; - - if !finite { - return Err("function returned a non-finite value".into()); + // A direct link with a missing user input leaves the property's stored setting in effect. + if let Some(value) = fallback + && program.input_identifier().is_some_and(|name| !name.starts_with('$') && !variables.contains_key(name)) + { + return Ok((value.clone(), matches!(mode, ParameterMode::UniformColor))); } + let context = EvaluationContext { + image_formats: &[], + scope: if matches!(mode, ParameterMode::RandomSeed) { FunctionScope::RandomSeed } else { FunctionScope::Node }, + position: [0.5; 2], + size: size.map(|side| side as f32), + images: &[], + tile: true, + variables, + }; + let mut state = EvaluationState::default(); + let value = match mode { + ParameterMode::Levels { normalized: true } => program.evaluate_normalized_color(&context, &mut state)?, + ParameterMode::GrayPatternOpacity => Value::Float(program.evaluate_pattern_opacity(&context, &mut state)?), + _ => program.evaluate(&context, &mut state)?, + }; + // A scalar level is already luminance. Its RGB expansion would introduce a second rounding. + let scalar_level = matches!(mode, ParameterMode::Levels { .. }) && program.output_type() == ValueType::Float as u32; let value = match value { - Value::Float(level) if !scalar_channel && widened => Value::Float4([level, level, level, 1.0]), + value if matches!(mode, ParameterMode::UniformColor) => value, + Value::Float(level) | Value::Float4([level, _, _, _]) if scalar_level => Value::Float(level), + Value::Float(level) if widened && matches!(mode, ParameterMode::Broadcast) => Value::Float4([level; 4]), + Value::Float(level) if widened => Value::Float4([level, level, level, 1.0]), Value::Float3([red, green, blue]) if widened => Value::Float4([red, green, blue, 1.0]), value => value, }; + let fixed = match mode { + ParameterMode::UniformColor => program.uses_fixed_uniform_color(variables), + _ => program.output_is_literal(), + }; + if let Some(names) = assigned_integers { + for (name, value) in state.assignments() { + if matches!(value, Value::Int(_)) && !names.contains(name) { + names.push(name.clone()); + } + } + } variables.extend(state.assignments().clone()); - - Ok(value) + Ok((value, fixed)) } diff --git a/crates/eval/src/port.rs b/crates/eval/src/port.rs index 2c35bbda..345da7fb 100644 --- a/crates/eval/src/port.rs +++ b/crates/eval/src/port.rs @@ -1,3 +1,4 @@ +use materialcraft_core::ValueType; use materialcraft_nodes::PortKind; #[derive(Clone, Debug, PartialEq)] @@ -5,4 +6,6 @@ pub struct Port { pub id: String, pub label: String, pub kind: PortKind, + /// Concrete type of a declared value port. + pub value_type: Option, } diff --git a/crates/eval/src/ports.rs b/crates/eval/src/ports.rs index f141c8af..7981f15c 100644 --- a/crates/eval/src/ports.rs +++ b/crates/eval/src/ports.rs @@ -14,53 +14,38 @@ pub fn ports_with_connections<'a>( incoming: impl IntoIterator, ) -> (Vec, Vec) { if node.def == "graph_instance" { + let ports = |source: &[materialcraft_core::GraphPort]| { + source + .iter() + .map(|port| Port { + id: port.identifier.clone(), + label: port.identifier.clone(), + kind: match port.type_code { + 1 => PortKind::Color, + 2 => PortKind::Gray, + _ => PortKind::Value, + }, + value_type: materialcraft_core::ValueType::from_code(port.type_code), + }) + .collect() + }; if let Some(instance) = &node.instance { - let ports = |ports: &[materialcraft_core::GraphPort]| { - ports - .iter() - .map(|port| Port { - id: port.identifier.clone(), - label: port.identifier.clone(), - kind: match port.type_code { - 1 => PortKind::Color, - 2 => PortKind::Gray, - _ => PortKind::Value, - }, - }) - .collect() - }; return (ports(&instance.inputs), ports(&instance.outputs)); } let Some((_, graph)) = instance_graph(package, node) else { return (Vec::new(), Vec::new()); }; - - let graph_ports = |definition: &str| -> Vec { - graph - .nodes - .iter() - .filter(|node| node.def == definition || (definition == "input" && node.def.starts_with("input_"))) - .map(|node| { - let id = identifier(node); - let kind = match node.def.as_str() { - "input_grayscale" => PortKind::Gray, - "input_color" => PortKind::Color, - _ => PortKind::Any, - }; - - Port { label: id.clone(), id, kind } - }) - .collect() - }; - - return (graph_ports("input"), graph_ports("output")); + let (inputs, outputs) = materialcraft_nodes::graph_interface::graph_ports(graph); + return (ports(&inputs), ports(&outputs)); } if node.def == materialcraft_core::MISSING_NODE { let (inputs, outputs) = materialcraft_core::missing_ports(node); - let inputs = inputs.into_iter().map(|id| Port { label: id.clone(), id, kind: PortKind::Any }).collect(); - let outputs = - outputs.into_iter().map(|(id, grayscale)| Port { label: id.clone(), id, kind: if grayscale { PortKind::Gray } else { PortKind::Color } }).collect(); + let inputs = inputs.into_iter().map(|id| Port { label: id.clone(), id, kind: PortKind::Any, value_type: None }).collect(); + let outputs = outputs + .into_iter() + .map(|(id, grayscale)| Port { label: id.clone(), id, kind: if grayscale { PortKind::Gray } else { PortKind::Color }, value_type: None }) + .collect(); return (inputs, outputs); } @@ -69,7 +54,7 @@ pub fn ports_with_connections<'a>( return (Vec::new(), Vec::new()); }; - let catalog_port = |port: &materialcraft_nodes::PortDefinition| Port { id: port.id.into(), label: port.label.into(), kind: port.kind }; + let catalog_port = |port: &materialcraft_nodes::PortDefinition| Port { id: port.id.into(), label: port.label.into(), kind: port.kind, value_type: None }; let mut inputs: Vec = node .input_values .iter() @@ -77,6 +62,7 @@ pub fn ports_with_connections<'a>( id: identifier.clone(), label: format!("{} ({})", crate::value_input_label(identifier), value_type.label()), kind: PortKind::Value, + value_type: Some(*value_type), }) .collect(); inputs.extend(definition.inputs.iter().map(catalog_port)); @@ -89,7 +75,12 @@ pub fn ports_with_connections<'a>( .max() .unwrap_or(1) .min(materialcraft_nodes::MAX_IMAGE_INPUTS); - inputs.extend((1..count).map(|index| Port { id: format!("{prefix}{index}"), label: format!("Input image {index}"), kind: PortKind::Any })); + inputs.extend((1..count).map(|index| Port { + id: format!("{prefix}{index}"), + label: format!("Input image {index}"), + kind: PortKind::Any, + value_type: None, + })); } (inputs, definition.outputs.iter().map(catalog_port).collect()) diff --git a/crates/eval/src/prepared_graph.rs b/crates/eval/src/prepared_graph.rs index 056e41a5..dac64ff3 100644 --- a/crates/eval/src/prepared_graph.rs +++ b/crates/eval/src/prepared_graph.rs @@ -7,11 +7,12 @@ pub(crate) struct PreparedGraph<'a> { pub index: GraphIndex<'a>, pub order: Vec, pub parent_base: crate::resolved_base_parameters::ResolvedBaseParameters, + pub base_error: Option, ports: BTreeMap, Vec)>, } impl<'a> PreparedGraph<'a> { - pub fn new(package: &Package, graph: &'a Graph, options: &crate::Options<'_>) -> Self { + pub fn new(package: &Package, graph: &'a Graph, options: &crate::Options<'_>, variables: &BTreeMap) -> Self { let index = GraphIndex::new(graph); let needed = options.only.as_deref().map(|roots| index.required_nodes(roots)); let order: Vec<_> = index.topo_order().into_iter().filter(|id| needed.as_ref().is_none_or(|needed| needed.contains(id))).collect(); @@ -23,32 +24,40 @@ impl<'a> PreparedGraph<'a> { }) .collect(); - let parent_base = crate::resolved_base_parameters::ResolvedBaseParameters::graph(graph, options); - Self { index, order, ports, parent_base } + let mut parent_base = crate::resolved_base_parameters::ResolvedBaseParameters::graph(graph, options); + let base_error = + parent_base.evaluate_graph_size(graph, options, variables).and_then(|()| parent_base.evaluate_graph_seed(graph, options, variables)).err(); + Self { index, order, ports, parent_base, base_error } } pub fn input_base(&self, id: NodeId, cooked: &crate::Cooked) -> Option { let node = self.index.node(id)?; let definition = materialcraft_nodes::find(&node.def); - let primary = definition.and_then(|definition| definition.primary_input); + let primary = definition.and_then(|definition| if node.disabled { definition.bypass_input } else { definition.primary_input }); let mut base = self .ports(id) .0 .iter() .filter(|port| port.kind != materialcraft_nodes::PortKind::Value && primary.is_none_or(|primary| port.id == primary)) - .find_map(|port| { - let connection = self.index.input_of(id, &port.id)?; - cooked.nodes.get(&connection.from).map(|result| result.base) - })?; + .find_map(|port| self.source_base(id, &port.id, cooked))?; // Only bypassed generators take their image dimensions from the input if !node.disabled && definition.is_some_and(|definition| definition.generator) { base.size = self.parent_base.size; + base.size_underflow = self.parent_base.size_underflow; + base.dynamic_size = self.parent_base.dynamic_size; + base.bound_size = self.parent_base.bound_size; } Some(base) } + pub fn source_base(&self, id: NodeId, port: &str, cooked: &crate::Cooked) -> Option { + let edge = self.index.input_of(id, port)?; + let index = self.ports(edge.from).1.iter().position(|output| output.id == edge.from_port)?; + cooked.nodes.get(&edge.from)?.output_base(index) + } + pub fn ports(&self, id: NodeId) -> (&[Port], &[Port]) { self.ports.get(&id).map_or((&[], &[]), |(inputs, outputs)| (inputs.as_slice(), outputs.as_slice())) } diff --git a/crates/eval/src/preview_sampling.rs b/crates/eval/src/preview_sampling.rs new file mode 100644 index 00000000..310269d3 --- /dev/null +++ b/crates/eval/src/preview_sampling.rs @@ -0,0 +1,72 @@ +use crate::cache_key::hash_of; +use materialcraft_core::NodeId; +use std::{collections::BTreeMap, sync::Arc}; + +/// Sampling state from one accepted preview. A graph instance owns its child state. +#[derive(Clone, Debug, Default)] +pub struct PreviewSampling { + pub(crate) context: ([u32; 2], u32, Option), + pub(crate) caller_format: Option, + stamps: BTreeMap, + instances: BTreeMap, +} + +#[derive(Clone, Debug)] +struct Stamp { + cook_key: u64, + // Each port keeps the acquired texture identity and whether it used the full mip chain. + inputs: BTreeMap, +} + +#[derive(Clone, Debug)] +struct Instance { + input_key: u64, + output_key: u64, + sampling: Arc, +} + +impl PreviewSampling { + pub(crate) fn is_empty(&self) -> bool { + self.stamps.is_empty() && self.instances.is_empty() + } + + pub(crate) fn child(&self, id: NodeId) -> Option<&PreviewSampling> { + self.instances.get(&id).map(|state| state.sampling.as_ref()) + } + + pub(crate) fn reuse_instance(&mut self, previous: Option<&Self>, id: NodeId, input_key: u64) -> u64 { + if let Some(state) = previous.and_then(|p| p.instances.get(&id)).filter(|s| s.input_key == input_key) { + self.instances.insert(id, state.clone()); + state.output_key + } else { + // Only an instance whose previous evaluation found no retained samplers can hit this key. + hash_of(&(input_key, "preview without sampled bridges")) + } + } + + pub(crate) fn record_instance(&mut self, id: NodeId, input_key: u64, output_key: u64, sampling: Arc) { + self.instances.insert(id, Instance { input_key, output_key, sampling }); + } + + pub(crate) fn stamp(&mut self, previous: Option<&Self>, id: NodeId, cook_key: u64, input_keys: &[u64], base_only: &mut [bool]) -> u64 { + // A precision edit on the calling instance resamples retained textures even at a fixed child precision. + let caller_changed = previous.is_some_and(|state| state.caller_format != self.caller_format); + let previous = previous.and_then(|p| p.stamps.get(&id)); + let mut inputs = BTreeMap::new(); + let mut full = Vec::new(); + for (port, (base_only, &texture)) in base_only.iter_mut().zip(input_keys).enumerate() { + if *base_only { + let retained = previous.is_some_and(|stamp| { + stamp.inputs.get(&port).is_some_and(|&(old, full)| old == texture && (full || caller_changed || stamp.cook_key != cook_key)) + }); + inputs.insert(port, (texture, retained)); + if retained { + *base_only = false; + full.push(port); + } + } + } + self.stamps.insert(id, Stamp { cook_key, inputs }); + if full.is_empty() { cook_key } else { hash_of(&(cook_key, full)) } + } +} diff --git a/crates/eval/src/resolved_base_parameters.rs b/crates/eval/src/resolved_base_parameters.rs index a2588469..a2b2111b 100644 --- a/crates/eval/src/resolved_base_parameters.rs +++ b/crates/eval/src/resolved_base_parameters.rs @@ -1,10 +1,26 @@ use materialcraft_core::{BaseParameter, BaseParameters, Graph, OutputFormat, ParameterInheritance, Value}; +use materialcraft_nodes::function::compile_with_literal_inputs; use std::collections::BTreeMap; #[derive(Clone, Copy, Debug, Default, serde::Serialize)] #[serde(rename_all = "camelCase")] pub struct ResolvedBaseParameters { pub size: [u32; 2], + /// This texture inherits or evaluates a size controlled by a runtime parameter. + #[serde(skip)] + pub dynamic_size: bool, + /// The resolved dimensions depend on a live graph input, including through size inheritance. + #[serde(skip)] + pub bound_size: bool, + /// This node's seed expression reads a live graph input. + #[serde(skip)] + pub bound_seed: bool, + /// A drawing property on this image or a connected source reads a live graph input. + #[serde(skip)] + pub bound_image: bool, + /// Negative requested exponents on axes whose allocated texture is one texel. + #[serde(skip)] + pub size_underflow: [i32; 2], pub seed: u32, pub format: OutputFormat, pub tiling: [bool; 2], @@ -12,43 +28,126 @@ pub struct ResolvedBaseParameters { pub pixel_size: [f32; 2], } +// An image carries no random stream. Both relative modes add to the parent seed. +fn resolve_seed(mode: ParameterInheritance, offset: i32, parent: u32) -> u32 { + mode.resolve(0, None, parent).wrapping_add(offset as u32) +} + impl ResolvedBaseParameters { pub(crate) fn graph(graph: &Graph, options: &crate::Options<'_>) -> Self { let parent = options.parent_base; + let parent_ratio = options.parent_pixel_ratio.or_else(|| parent.map(|base| base.pixel_ratio)); + let (size, size_underflow) = graph.resolved_output_size(parent.map(|base| (base.size, base.size_underflow)), None); Self { - size: parent.map_or_else(|| graph.size_px(), |base| base.size), - seed: parent.map_or(graph.seed as u32, |base| base.seed), - format: parent.map_or(graph.format, |base| base.format), + size, + dynamic_size: graph.absolute_output_size.is_none() && parent.is_some_and(|base| base.dynamic_size), + bound_size: graph.output_size_setting().0 != materialcraft_core::SizeMode::Absolute && parent.is_some_and(|base| base.bound_size), + bound_seed: false, + bound_image: false, + size_underflow, + seed: resolve_seed(graph.seed_mode, graph.seed, parent.map_or(0, |base| base.seed)), + format: match graph.format { + OutputFormat::Inherit => parent.map_or(OutputFormat::Inherit, |base| base.format), + explicit => explicit, + }, tiling: graph.tiling_mode.resolve(graph.tiling, options.parent_tiling, options.parent_tiling.unwrap_or(graph.tiling)), - pixel_ratio: graph.pixel_ratio_mode.resolve(graph.pixel_ratio, options.parent_pixel_ratio, options.parent_pixel_ratio.unwrap_or(graph.pixel_ratio)), + pixel_ratio: graph.pixel_ratio_mode.resolve(graph.pixel_ratio, parent_ratio, parent_ratio.unwrap_or(1)), pixel_size: parent.map_or([1.0; 2], |base| base.pixel_size), } } + fn graph_function_value( + self, + parameter: BaseParameter, + function: &materialcraft_core::FunctionGraph, + options: &crate::Options<'_>, + variables: &BTreeMap, + ) -> Result<(Value, bool, bool), String> { + let mut variables = variables.clone(); + self.variables(&mut variables); + compile_with_literal_inputs(function, self.seed, &options.literal_inputs) + .and_then(|program| { + let dynamic = !program.output_is_literal() && !program.depends_only_on_image_size(); + let bound = program.reads_graph_parameter(&variables); + let (value, _) = crate::parameter_function::evaluate( + &program, + parameter.value_type(), + &mut variables, + self.size, + crate::parameter_function::ParameterMode::for_base(parameter), + None, + None, + )?; + Ok((value, dynamic, bound)) + }) + .map_err(|error| format!("graph {}: {error}", parameter.label().to_ascii_lowercase())) + } + + pub(crate) fn evaluate_graph_size(&mut self, graph: &Graph, options: &crate::Options<'_>, variables: &BTreeMap) -> Result<(), String> { + let Some(function) = &graph.output_size_function else { return Ok(()) }; + let parent = options.parent_base.map(|base| (base.size, base.size_underflow)); + let (size, size_underflow) = if graph.output_size_setting().0 == materialcraft_core::SizeMode::Absolute { + ([0; 2], [0; 2]) + } else { + parent.unwrap_or_else(|| (graph.parent_size_px(), [0; 2])) + }; + let context = Self { size, size_underflow, ..*self }; + let (value, dynamic, bound) = context.graph_function_value(BaseParameter::OutputSize, function, options, variables)?; + let Value::Int2(offset) = value else { return Err("graph output size requires an integer pair".into()) }; + (self.size, self.size_underflow) = graph.resolved_output_size(parent, Some(offset)); + self.dynamic_size |= dynamic; + self.bound_size |= bound; + Ok(()) + } + + pub(crate) fn evaluate_graph_seed(&mut self, graph: &Graph, options: &crate::Options<'_>, variables: &BTreeMap) -> Result<(), String> { + let Some(function) = &graph.seed_function else { return Ok(()) }; + let parent_seed = options.parent_base.map_or(0, |base| base.seed); + // Graph seed functions see the allocated dimensions even when descendants retain a negative size exponent. + let context = Self { seed: resolve_seed(graph.seed_mode, 0, parent_seed), size_underflow: [0; 2], ..*self }; + let (value, _, _) = context.graph_function_value(BaseParameter::RandomSeed, function, options, variables)?; + let Value::Int(offset) = value else { return Err("graph random seed requires an integer".into()) }; + self.seed = resolve_seed(graph.seed_mode, offset, parent_seed); + Ok(()) + } + pub(crate) fn resolve(base: &BaseParameters, input: Option, parent: Self) -> Self { - let size_base = BaseParameter::OutputSize.inheritance(base).resolve([1; 2], input.map(|base| base.size), parent.size); + let dimensions = |base: Self| (base.size, base.size_underflow); + let size_mode = BaseParameter::OutputSize.inheritance(base); + let (size_base, underflow) = size_mode.resolve(([1; 2], [0; 2]), input.map(dimensions), dimensions(parent)); + let (size, size_underflow) = materialcraft_core::offset_dimensions(size_base, underflow, base.size); - // Internal images may be one texel; the editor minimum would break size functions - let size = std::array::from_fn(|axis| (f64::from(size_base[axis]) * 2f64.powi(base.size[axis].clamp(-12, 13))).round().clamp(1.0, 8192.0) as u32); - - // Images carry size and format, but do not carry a random stream - // Relative seed modes use the graph seed without accumulating upstream seeds - let inherited_seed = base.seed_mode.resolve(0, None, parent.seed); let inherited_pixel_size = base.pixel_size_mode.resolve([1.0; 2], input.map(|base| base.pixel_size), parent.pixel_size); Self { size, - seed: inherited_seed.wrapping_add(base.seed as u32), + size_underflow, + dynamic_size: size_mode.resolve(false, input.map(|base| base.dynamic_size), parent.dynamic_size), + bound_size: size_mode.resolve(false, input.map(|base| base.bound_size), parent.bound_size), + bound_seed: false, + bound_image: false, + seed: resolve_seed(base.seed_mode, base.seed, parent.seed), format: BaseParameter::Format.inheritance(base).resolve(base.format, input.map(|base| base.format), parent.format), tiling: base.tiling_mode.resolve(base.tiling, input.map(|base| base.tiling), parent.tiling), pixel_ratio: base.pixel_ratio_mode.resolve(base.pixel_ratio, input.map(|base| base.pixel_ratio), parent.pixel_ratio), - pixel_size: std::array::from_fn(|axis| (inherited_pixel_size[axis] * base.pixel_size[axis]).clamp(f32::MIN_POSITIVE, 8192.0)), + pixel_size: std::array::from_fn(|axis| (inherited_pixel_size[axis] * base.pixel_size[axis]).clamp(-8192.0, 8192.0)), } } pub(crate) fn variables(self, variables: &mut BTreeMap) { + self.size_variables(variables); variables.insert("$tiling".into(), Value::Int(i32::from(self.tiling[0]) | (i32::from(self.tiling[1]) << 1))); variables.insert("$pixelratio".into(), Value::Int(self.pixel_ratio)); } + + fn size_variables(self, variables: &mut BTreeMap) { + if self.size_underflow == [0; 2] { + variables.remove("$sizelog2"); + } else { + let exponents = + std::array::from_fn(|axis| if self.size_underflow[axis] < 0 { self.size_underflow[axis] as f32 } else { (self.size[axis] as f32).log2() }); + variables.insert("$sizelog2".into(), Value::Float2(exponents)); + } + } } pub(crate) fn evaluate( @@ -56,6 +155,8 @@ pub(crate) fn evaluate( input: Option, parent: ResolvedBaseParameters, variables: &mut std::borrow::Cow<'_, BTreeMap>, + literal_inputs: &[String], + mut assigned_integers: Option<&mut Vec>, ) -> Result<(ResolvedBaseParameters, BTreeMap), String> { if base.functions.is_empty() { return Ok((ResolvedBaseParameters::resolve(base, input, parent), BTreeMap::new())); @@ -78,6 +179,9 @@ pub(crate) fn evaluate( pixel_ratio_mode: base.pixel_ratio_mode, }; let mut values = BTreeMap::new(); + let mut computed_size = false; + let mut bound_size = false; + let mut bound_seed = false; let mut resolved = ResolvedBaseParameters::resolve(&evaluated, input, parent); // Size and seed establish the context used by the remaining parameter functions @@ -92,12 +196,31 @@ pub(crate) fn evaluate( if let Some(function) = base.functions.get(¶meter) { resolved.variables(variables.to_mut()); let size = if parameter == BaseParameter::OutputSize && parameter.inheritance(base) != ParameterInheritance::Absolute { - parameter.inheritance(base).resolve(parent.size, input.map(|base| base.size), parent.size) + let inherited = parameter.inheritance(base).resolve(parent, input, parent); + inherited.size_variables(variables.to_mut()); + inherited.size } else { resolved.size }; - let value = crate::parameter_function::evaluate(function, parameter.value_type(), variables.to_mut(), resolved.seed, size, false) + let (value, _) = compile_with_literal_inputs(function, resolved.seed, literal_inputs) + .and_then(|program| { + if parameter == BaseParameter::OutputSize { + computed_size = !program.output_is_literal() && !program.depends_only_on_image_size(); + bound_size = program.reads_graph_parameter(variables); + } else if parameter == BaseParameter::RandomSeed { + bound_seed = program.reads_graph_parameter(variables); + } + crate::parameter_function::evaluate( + &program, + parameter.value_type(), + variables.to_mut(), + size, + crate::parameter_function::ParameterMode::for_base(parameter), + None, + assigned_integers.as_deref_mut(), + ) + }) .map_err(|error| format!("function of `{}`: {error}", parameter.identifier()))?; parameter.set_value(&mut evaluated, &value)?; parameter.set_inheritance(&mut evaluated, parameter.inheritance(base)); @@ -107,5 +230,8 @@ pub(crate) fn evaluate( values.insert(parameter, parameter.value(&evaluated)); } + resolved.dynamic_size |= computed_size; + resolved.bound_size |= bound_size; + resolved.bound_seed = bound_seed; Ok((resolved, values)) } diff --git a/crates/eval/src/tests.rs b/crates/eval/src/tests.rs index 79c6483c..68312cf4 100644 --- a/crates/eval/src/tests.rs +++ b/crates/eval/src/tests.rs @@ -1,3 +1,5 @@ +mod font_resource; + use crate::{cache_key::graph_tree_hash, graph_instance::instances_reach}; use craft_texture::{Image, Kind, Limits}; use materialcraft_core::{NodeId, Package, Value}; @@ -47,6 +49,99 @@ fn cooks_and_caches() { assert_eq!(outputs(&p.graphs[0], &c).len(), 1); } +#[test] +fn fixed_filters_preserve_each_tiling_axis_when_resizing_an_input() { + use materialcraft_core::{OutputFormat, ParameterInheritance, SizeMode}; + + for (filter, port) in [("levels", "input"), ("blend", "foreground"), ("warp", "input")] { + let mut graph = Graph::new("Tiling"); + let input = graph.add_node("input_grayscale", [0.0; 2]); + let output = graph.add_node(filter, [100.0, 0.0]); + for (id, exponent) in [(input, 2), (output, 3)] { + let base = &mut graph.node_mut(id).unwrap().base; + base.size_mode = SizeMode::Absolute; + base.size = [exponent; 2]; + base.format = OutputFormat::U16; + } + graph.connect(input, "output", output, port).unwrap(); + let mut package = Package::new("Tiling"); + package.graphs.push(graph); + let mut options = Options::new(&no_res); + options.inputs.insert("input".into(), Image::gray(4, 4, |x, y| ((4 * y + x) * 4096) as f32 / 65535.0)); + let cache = Mutex::new(Cache::default()); + for (tiling, expected) in [([false, false], 0), ([true, false], 3072), ([false, true], 12288), ([true, true], 15360), ([true, false], 3072)] { + let base = &mut package.graphs[0].node_mut(output).unwrap().base; + base.tiling_mode = ParameterInheritance::Absolute; + base.tiling = tiling; + let result = cook(&package, 0, &options, &cache); + assert_eq!(result.nodes[&output].error, None); + let pixel = result.image(output, 0).unwrap().get_gray(0, 0, false); + assert_eq!((pixel * 65535.0).round() as u32, expected, "{filter} {tiling:?}"); + } + } +} + +#[test] +fn subtexel_size_exponents_survive_allocation_and_cache_reuse() { + use materialcraft_core::{FunctionGraph, OutputFormat, SizeMode}; + + let mut function = FunctionGraph::default(); + let size = function.add("get_float2", &[], Some(Value::Text("$size".into()))); + let log = function.add("get_float2", &[], Some(Value::Text("$sizelog2".into()))); + function.output = Some(function.add("vector4", &[size, log], None)); + let mut graph = Graph::new("Reduction"); + graph.size = [7; 2]; + graph.format = OutputFormat::F32; + let processor = graph.add_node("pixel_processor", [0.0; 2]); + let node = graph.node_mut(processor).unwrap(); + node.params.insert("function".into(), Value::Function(Box::new(function))); + node.params.insert("color_mode".into(), Value::Bool(true)); + node.base.size_mode = SizeMode::RelativeToParent; + let transform = graph.add_node("transformation", [120.0, 0.0]); + graph.node_mut(transform).unwrap().base.size = [3, 0]; + graph.connect(processor, "output", transform, "input").unwrap(); + let mut package = Package::new("Reduction"); + package.graphs.push(graph); + let cache = Mutex::new(Cache::default()); + + for (offset, first, log, next_width) in [(-8, -2147483648.0, -1.0, 4), (-9, 1073741824.0, -2.0, 2), (-10, 536870912.0, -3.0, 1)] { + package.graphs[0].node_mut(processor).unwrap().base.size = [offset, -2]; + let cooked = cook(&package, 0, &Options::new(&no_res), &cache); + assert!(cooked.nodes.values().all(|result| result.error.is_none() && !result.cached)); + let image = cooked.image(processor, 0).unwrap(); + assert_eq!((image.width(), image.height()), (1, 32)); + assert_eq!(image.get(0, 0, false), [first, 32.0, log, 5.0]); + assert_eq!(cooked.image(transform, 0).unwrap().width(), next_width); + } +} + +#[test] +fn value_processor_stores_integer_lanes_at_single_precision() { + use materialcraft_core::{FunctionGraph, ValueType}; + let cache = Mutex::new(Cache::default()); + let mut graph = Graph::new("Integer output"); + let processor = graph.add_node("value_processor", [0.0; 2]); + let mut package = Package::new("Integer output"); + package.graphs.push(graph); + for (kind, input, expected) in [ + (ValueType::Integer, Value::Int(i32::MAX), Value::Int(i32::MIN)), + (ValueType::Integer2, Value::Int2([16_777_217, -16_777_219]), Value::Int2([16_777_216, -16_777_220])), + (ValueType::Integer3, Value::Int3([i32::MIN + 1, 2_147_483_583, 2_147_483_584]), Value::Int3([i32::MIN, 2_147_483_520, i32::MIN])), + (ValueType::Integer4, Value::Int4([-31, 0, 1, i32::MAX]), Value::Int4([-31, 0, 1, i32::MIN])), + ] { + for function in [FunctionGraph::input("numbers", kind), FunctionGraph::constant(input.clone())] { + package.graphs[0].node_mut(processor).unwrap().params.insert("function".into(), Value::Function(Box::new(function))); + let mut options = Options::new(&no_res); + options.overrides.insert("numbers".into(), input.clone()); + let cooked = cook(&package, 0, &options, &cache); + assert_eq!(cooked.value(processor, 0), Some(&expected)); + let cached = cook(&package, 0, &options, &cache); + assert!(cached.nodes[&processor].cached); + assert_eq!(cached.value(processor, 0), Some(&expected)); + } + } +} + #[test] fn material_overrides_skip_bound_preview_decodes_and_release_buffers() { let mut graph = Graph::new("Bound inputs"); @@ -245,6 +340,169 @@ fn preview_cap_and_unknown_nodes() { assert!(c.nodes[&bad].error.is_some()); } +#[test] +fn typed_instance_ports_preserve_explicit_arguments_and_wire_fallbacks() { + use materialcraft_core::{FunctionGraph, ValueType}; + + let (mut parent, instance) = instancing("Caller", "Echo"); + let wire = parent.add_node("input_value", [0.0; 2]); + parent.node_mut(wire).unwrap().params.insert("default".into(), Value::Int(9)); + let mut child = Graph::new("Echo"); + let bridge = child.add_node("input_value", [0.0; 2]); + child.node_mut(bridge).unwrap().params.extend([("identifier".into(), Value::Text("count".into())), ("default".into(), Value::Int(5))]); + let output = child.add_node("output", [0.0; 2]); + child.connect(bridge, "output", output, "input").unwrap(); + + let mut package = Package::new("Typed arguments"); + package.graphs.extend([parent, child]); + let cache = Mutex::new(Cache::default()); + let mut options = Options::new(&no_res); + options.overrides.insert("control".into(), Value::Int(-12)); + for wired in [false, true] { + if wired { + package.graphs[0].connect(wire, "output", instance, "count").unwrap(); + } + for (literal, function, expected) in [(None, false, if wired { 9 } else { 5 }), (Some(0), false, 0), (Some(-3), false, -3), (None, true, -12)] { + let node = package.graphs[0].node_mut(instance).unwrap(); + node.params.remove("count"); + node.functions.remove("count"); + if let Some(value) = literal { + node.params.insert("count".into(), Value::Int(value)); + } + if function { + node.functions.insert("count".into(), FunctionGraph::input("control", ValueType::Integer)); + } + let cooked = cook(&package, 0, &options, &cache); + assert_eq!(cooked.nodes[&instance].error, None); + assert_eq!(cooked.nodes[&instance].outputs[0].as_value(), Some(&Value::Int(expected)), "wire {wired}, stored {literal:?}, function {function}"); + } + } +} + +#[test] +fn cached_instances_distinguish_fixed_and_bound_integer_arguments() { + use materialcraft_core::{ExposedParameter, FunctionGraph, ValueType}; + let (parent, instance) = instancing("Parent", "Selector"); + let mut child = Graph::new("Selector"); + child.exposed.push(ExposedParameter { + connectable: false, + id: "index".into(), + label: "Index".into(), + default: Value::Int(0), + description: String::new(), + group: String::new(), + editor: None, + clamp: false, + step: None, + min: -8.0, + max: 8.0, + options: Vec::new(), + }); + let mut function = FunctionGraph::input("%index", ValueType::Integer); + let input = function.output.unwrap(); + function.output = Some(function.add("tofloat", &[input], None)); + let processor = child.add_node("value_processor", [0.0; 2]); + child.node_mut(processor).unwrap().params.insert("function".into(), Value::Function(Box::new(function))); + let output = child.add_node("output", [0.0; 2]); + child.connect(processor, "output", output, "input").unwrap(); + let mut package = Package::new("Integer arguments"); + package.graphs.extend([parent, child]); + let mut options = Options::new(&no_res); + options.overrides.insert("driver".into(), Value::Int(-5)); + let cache = Mutex::new(Cache::default()); + for bound in [false, true, false] { + let node = package.graphs[0].node_mut(instance).unwrap(); + node.params.insert("index".into(), Value::Int(-5)); + if bound { + node.bindings.insert("index".into(), "driver".into()); + } else { + node.bindings.remove("index"); + } + let result = cook(&package, 0, &options, &cache); + assert_eq!(result.nodes[&instance].error, None); + assert_eq!(result.nodes[&instance].outputs[0].as_value(), Some(&Value::Float(if bound { -5.0 } else { 4_294_967_296.0 }))); + } +} + +#[test] +fn instanced_float_angles_keep_their_precision_across_an_unrelated_write() { + assert_instance_angle_precision(Value::Float(1.0)); +} + +#[test] +fn instanced_vector_angles_preserve_fixed_and_parent_bound_precision() { + for turn in [Value::Float2([1.0, 0.25]), Value::Float3([1.0, 0.25, -0.5]), Value::Float4([1.0, 0.25, -0.5, 0.75])] { + assert_instance_angle_precision(turn); + } +} + +fn assert_instance_angle_precision(argument: Value) { + use materialcraft_core::{ExposedParameter, FunctionGraph, GraphInstance, GraphPort, OutputFormat, ValueType}; + let (parent, instance) = instancing("Parent", "Angle"); + let mut child = Graph::new("Angle"); + child.exposed.push(ExposedParameter { + id: "turn".into(), + label: "Turn".into(), + default: argument.clone(), + connectable: false, + clamp: false, + description: String::new(), + group: String::new(), + editor: None, + step: None, + min: -2.0, + max: 2.0, + options: Vec::new(), + }); + let mut body = FunctionGraph::default(); + let one = body.add_constant(Value::Float(1.0)); + body.output = Some(body.add("set", &[one], Some(Value::Text("scratch".into())))); + let mut expression = FunctionGraph::input("turn", ValueType::of(&argument).unwrap()); + let input = expression.output.unwrap(); + let write = expression.add("instance", &[], None); + let call = expression.nodes.last_mut().unwrap(); + call.instance = Some(GraphInstance { + label: String::new(), + graph: "Remember".into(), + package: String::new(), + inputs: Vec::new(), + outputs: vec![GraphPort { identifier: "output".into(), type_code: 256 }], + defaults: Default::default(), + }); + call.source = Some(Ok(std::sync::Arc::new(body))); + let turn = if matches!(argument, Value::Float(_)) { input } else { expression.add("swizzle1", &[input], Some(Value::Int(0))) }; + let tau = expression.add_constant(Value::Float(std::f32::consts::TAU)); + let angle = expression.add("mul", &[turn, tau], None); + let sine = expression.add("sin", &[angle], None); + expression.output = Some(expression.add("sequence", &[write, sine], None)); + let processor = child.add_node("pixel_processor", [0.0; 2]); + let pixel = child.node_mut(processor).unwrap(); + pixel.base.format = OutputFormat::F32; + pixel.params.insert("function".into(), Value::Function(Box::new(expression))); + let output = child.add_node("output", [0.0; 2]); + child.connect(processor, "output", output, "input").unwrap(); + let mut package = Package::new("Fixed and bound turns"); + package.graphs.extend([parent, child]); + let mut options = Options::new(&no_res); + options.overrides.insert("driver".into(), argument.clone()); + let cache = Mutex::new(Cache::default()); + for (explicit, bound) in [(false, false), (true, false), (true, true), (true, false)] { + let node = package.graphs[0].node_mut(instance).unwrap(); + if explicit { + node.params.insert("turn".into(), argument.clone()); + } + if bound { + node.bindings.insert("turn".into(), "driver".into()); + } else { + node.bindings.remove("turn"); + } + let result = cook(&package, 0, &options, &cache); + assert_eq!(result.nodes[&instance].error, None); + let red = result.image(instance, 0).unwrap().get(0, 0, false)[0]; + assert_eq!(red.to_bits(), if bound { (-0.0_f32).to_bits() } else { 0x343b_bd2e }, "{argument:?}, explicit {explicit}, bound {bound}"); + } +} + #[test] fn graph_instances_cook_their_subgraph() { let (mut p, ..) = sample(); @@ -290,6 +548,61 @@ fn instancing(name: &str, target: &str) -> (Graph, NodeId) { (g, inst) } +#[test] +fn an_instanced_graph_uses_its_declared_absolute_output_size() { + let (parent, instance) = instancing("Parent", "Rectangle"); + let mut child = Graph::new("Rectangle"); + child.absolute_output_size = Some([6, 5]); + let generator = child.add_node("uniform", [0.0; 2]); + let output = child.add_node("output", [100.0, 0.0]); + child.connect(generator, "output", output, "input").unwrap(); + let mut package = Package::new("Dimensions"); + package.graphs.extend([parent, child]); + let cache = Mutex::new(Cache::default()); + for (size, expected) in [(Some([6, 5]), [64, 32]), (Some([5, 0]), [32, 1]), (None, [16, 16])] { + package.graphs[1].absolute_output_size = size; + let cooked = cook(&package, 0, &Options::new(&no_res), &cache); + let image = cooked.image(instance, 0).unwrap(); + assert_eq!([image.width(), image.height()], expected); + assert_eq!(cooked.nodes[&instance].base.size, expected); + } +} + +#[test] +fn instance_outputs_keep_each_sources_dimensions_and_precision() { + use materialcraft_core::{OutputFormat, SizeMode}; + let (mut parent, instance) = instancing("Parent", "TwoOutputs"); + let mut source = Graph::new("TwoOutputs"); + let mut consumers = Vec::new(); + for (name, size, format) in [("output", [6, 5], OutputFormat::F32), ("small", [2, 3], OutputFormat::U8)] { + let fill = source.add_node("uniform", [0.0; 2]); + let base = &mut source.node_mut(fill).unwrap().base; + base.size_mode = SizeMode::Absolute; + base.size = size; + base.format = format; + let bridge = source.add_node("output", [100.0, 0.0]); + source.node_mut(bridge).unwrap().params.insert("identifier".into(), Value::Text(name.into())); + source.connect(fill, "output", bridge, "input").unwrap(); + let consumer = parent.add_node("levels", [200.0, 0.0]); + parent.connect(instance, name, consumer, "input").unwrap(); + consumers.push((consumer, size.map(|power| 1u32 << power), format)); + } + let mut package = Package::new("Per-port dimensions"); + package.graphs.extend([parent, source]); + let cache = Mutex::new(Cache::default()); + for cached in [false, true] { + let cooked = cook(&package, 0, &Options::new(&no_res), &cache); + assert_eq!(cooked.nodes[&instance].cached, cached); + for &(id, size, format) in &consumers { + let result = &cooked.nodes[&id]; + assert_eq!(result.base.size, size); + assert_eq!(result.base.format, format); + let image = cooked.image(id, 0).unwrap(); + assert_eq!([image.width(), image.height()], size); + } + } +} + #[test] fn editing_a_nested_graph_recooks_the_top() { let mut c = Graph::new("c"); @@ -389,6 +702,1004 @@ fn same_size_resources_key_differently() { assert!((second.image(bm, 0).unwrap().mean()[0] - mean).abs() > 0.05); } +#[test] +fn box_blur_uses_the_resolved_pixel_size_on_each_axis() { + use materialcraft_core::{BaseParameter, FunctionGraph, OutputFormat, ParameterInheritance}; + + let mut graph = Graph::new("Blur footprint"); + graph.size = [5, 5]; + graph.format = OutputFormat::F32; + let source = graph.add_node("input_grayscale", [0.0; 2]); + let blur = graph.add_node("blur", [0.0; 2]); + let node = graph.node_mut(blur).unwrap(); + node.params.insert("intensity".into(), Value::Float(1.0)); + node.base.pixel_size_mode = ParameterInheritance::Absolute; + graph.connect(source, "output", blur, "input").unwrap(); + let mut package = Package::new("Blur footprint"); + package.graphs.push(graph); + let mut options = Options::new(&no_res); + options.inputs.insert("input".into(), Image::gray(32, 32, |x, y| f32::from(x == 16 && y == 16))); + let cache = Mutex::new(Cache::default()); + for (size, expected) in + [([64.0, 64.0], [1.0 / 256.0, 1.0 / 512.0, 1.0 / 512.0]), ([1.0, 64.0], [1.0 / 16.0, 0.0, 1.0 / 32.0]), ([64.0, 1.0], [1.0 / 16.0, 1.0 / 32.0, 0.0])] + { + let base = &mut package.graphs[0].node_mut(blur).unwrap().base; + base.functions.insert(BaseParameter::PixelSize, FunctionGraph::constant(Value::Float2(size))); + let result = cook(&package, 0, &options, &cache); + let image = result.image(blur, 0).unwrap(); + assert_eq!([(16, 16), (8, 16), (16, 8)].map(|(x, y)| image.get_gray(x, y, false)), expected, "pixel size {size:?}"); + } +} + +#[test] +fn box_blur_multiplies_signed_pixel_sizes_before_limiting_its_radius() { + use materialcraft_core::{BaseParameter, OutputFormat, ParameterInheritance}; + + let mut graph = Graph::new("Inherited footprint"); + graph.size = [5, 5]; + graph.format = OutputFormat::F32; + let input = graph.add_node("input_grayscale", [0.0; 2]); + let blur = graph.add_node("blur", [0.0; 2]); + graph.node_mut(input).unwrap().base.pixel_size_mode = ParameterInheritance::Absolute; + graph.node_mut(blur).unwrap().base.pixel_size_mode = ParameterInheritance::RelativeToInput; + graph.node_mut(blur).unwrap().params.insert("intensity".into(), Value::Float(1.0)); + graph.connect(input, "output", blur, "input").unwrap(); + let mut package = Package::new("Inherited footprint"); + package.graphs.push(graph); + let mut options = Options::new(&no_res); + options.inputs.insert("input".into(), Image::gray(32, 32, |x, y| f32::from(x == 16 && y == 16))); + let cache = Mutex::new(Cache::default()); + for (parent, factor, expected) in [([-2.0, 3.0], [-64.0, 8.0], 1.0 / 192.0), ([-2.0, 3.0], [64.0, -8.0], 1.0), ([0.0, 4.0], [8.0, -4.0], 1.0)] { + for (node, size) in [(input, parent), (blur, factor)] { + BaseParameter::PixelSize.set_value(&mut package.graphs[0].node_mut(node).unwrap().base, &Value::Float2(size)).unwrap(); + } + let result = cook(&package, 0, &options, &cache); + assert_eq!(result.image(blur, 0).unwrap().get_gray(16, 16, false), expected); + } +} + +#[test] +fn emboss_uses_the_resolved_pixel_size_on_each_axis() { + use materialcraft_core::{OutputFormat, ParameterInheritance}; + + let mut graph = Graph::new("Relief"); + graph.size = [5, 5]; + graph.format = OutputFormat::F32; + let [base, height] = ["base", "height"].map(|name| { + let id = graph.add_node("input_grayscale", [0.0; 2]); + graph.node_mut(id).unwrap().params.insert("identifier".into(), Value::Text(name.into())); + id + }); + let emboss = graph.add_node("emboss", [0.0; 2]); + let node = graph.node_mut(emboss).unwrap(); + node.base.pixel_size_mode = ParameterInheritance::Absolute; + node.base.pixel_size = [0.5, 2.0]; + node.params.insert("intensity".into(), Value::Float(1.0)); + graph.connect(base, "output", emboss, "input").unwrap(); + graph.connect(height, "output", emboss, "height").unwrap(); + let mut package = Package::new("Relief"); + package.graphs.push(graph); + let mut options = Options::new(&no_res); + options.inputs.insert("base".into(), Image::filled(32, 32, Kind::Gray, [0.5; 4])); + options.inputs.insert("height".into(), Image::gray(32, 32, |x, y| if x == 16 && y == 16 { 1.0 } else { 0.0 })); + let cache = Mutex::new(Cache::default()); + for (angle, east, south, center) in [(0.0, 0.4375, 0.5, 0.5625), (0.25, 0.5, 0.25, 0.75)] { + package.graphs[0].node_mut(emboss).unwrap().params.insert("light_angle".into(), Value::Float(angle)); + let result = cook(&package, 0, &options, &cache); + let image = result.image(emboss, 0).unwrap(); + assert_eq!([image.get_gray(17, 16, false), image.get_gray(16, 17, false), image.get_gray(16, 16, false)], [east, south, center]); + } +} + +#[test] +fn bitmap_growth_maps_the_origin_and_half_texel_offset_separately() { + let mut graph = Graph::new("Column"); + graph.size = [0, 6]; + graph.format = materialcraft_core::OutputFormat::F32; + let input = graph.add_node("input_grayscale", [0.0; 2]); + let mut package = Package::new("Column"); + package.graphs.push(graph); + let mut options = Options::new(&no_res); + let column = Image::gray(1, 49, |_, y| { + f32::from_bits(match y { + 5 => 0xbeae_712e, + 6 => 0x3f90_4fe4, + _ => 0, + }) + }); + options.inputs.insert("input".into(), column); + let result = cook(&package, 0, &options, &Mutex::new(Cache::default())); + assert_eq!(result.image(input, 0).unwrap().get_gray(0, 7, false).to_bits(), 0x3c73_7400); +} + +#[test] +fn filters_sample_bound_integer_bitmaps_at_the_source_depth() { + use OutputFormat::{F16, F32, U8, U16}; + use materialcraft_core::{OutputFormat, ParameterInheritance}; + + let mut graph = Graph::new("Source precision"); + graph.size = [5, 5]; + graph.format = F32; + let input = graph.add_node("input_grayscale", [0.0; 2]); + let transform = graph.add_node("transformation", [0.0; 2]); + let output = graph.add_node("output", [0.0; 2]); + let node = graph.node_mut(transform).unwrap(); + node.base.format_mode = ParameterInheritance::Absolute; + node.base.format = F32; + node.params.insert("offset".into(), Value::Float2([15.0 / 1024.0, -21.0 / 1024.0])); + graph.connect(input, "output", transform, "input").unwrap(); + graph.connect(input, "output", output, "input").unwrap(); + let mut package = Package::new("Integer input"); + package.graphs.push(graph); + let cache = Mutex::new(Cache::default()); + for (depth, bridge, expected) in [(U8, F16, 0x3eee_4eee), (U8, F32, 0x3eee_4eee), (U16, F32, 0x3eee_92ef), (U16, F16, 0x3eee_8000)] { + let node = package.graphs[0].node_mut(input).unwrap(); + node.base.format_mode = ParameterInheritance::Absolute; + node.base.format = bridge; + let mut options = Options::new(&no_res); + options.bitmap_formats.insert("input".into(), depth); + let image = Image::gray(32, 17, |x, y| { + let level = if x % 2 == 0 { 9 } else { 243 }; + if depth == U8 { level as f32 / 255.0 } else { (level * 257 + (7 * x + 3 * y) % 251) as f32 / 65535.0 } + }); + options.inputs.insert("input".into(), image.with_integer_sampling(true)); + for _ in 0..2 { + let result = cook(&package, 0, &options, &cache); + assert!(result.nodes.values().all(|node| node.error.is_none())); + assert_eq!(result.image(transform, 0).unwrap().get_gray(0, 0, false).to_bits(), expected); + if depth == U8 && bridge == F16 { + for id in [input, output] { + assert_eq!(result.image(id, 0).unwrap().get_gray(0, 0, false).to_bits(), 0x3d10_8000); + } + } + } + } +} + +#[test] +fn bitmap_half_storage_uses_the_original_integer_channel_depth() { + use materialcraft_core::OutputFormat::{F16, U8, U16}; + + let mut graph = Graph::new("Byte and word"); + graph.size = [5, 5]; + graph.format = F16; + let input = graph.add_node("input_grayscale", [0.0; 2]); + let mut package = Package::new("Integer source"); + package.graphs.push(graph); + for (depth, level, expected) in [ + (U8, 9.0 / 255.0, [0x3d10_8000; 3]), + (U16, 2313.0 / 65535.0, [0x3d10_0000, 0x3d10_2000, 0x3d10_c000]), + (U16, 1.0, [0x3f7f_e000, 0x3f7f_e000, 0x3f80_0000]), + ] { + let mut options = Options::new(&no_res); + options.bitmap_formats.insert("input".into(), depth); + options.inputs.insert("input".into(), Image::filled(32, 17, Kind::Gray, [level; 4]).with_integer_sampling(true)); + let result = cook(&package, 0, &options, &Mutex::new(Cache::default())); + let image = result.image(input, 0).unwrap(); + assert_eq!([0, 1, 2].map(|x| image.get_gray(x, 0, false).to_bits()), expected); + } +} + +fn bitmap_impulse_graph() -> (Graph, NodeId, NodeId) { + use materialcraft_core::{OutputFormat, ParameterInheritance, PatternGraph, PatternNodeKind}; + + let mut graph = Graph::new("Bitmap mip levels"); + graph.size = [4, 6]; + graph.format = OutputFormat::U16; + let input = graph.add_node("input_grayscale", [0.0; 2]); + let stamp = graph.add_node("fx_map", [0.0; 2]); + let mut pattern = PatternGraph::with_root(PatternNodeKind::Quadrant); + pattern.nodes[0].parameters.insert("patterntype".into(), Value::Int(1)); + pattern.nodes[0].parameters.insert("patternsize".into(), Value::Float2([0.25; 2])); + let node = graph.node_mut(stamp).unwrap(); + node.base.format_mode = ParameterInheritance::Absolute; + node.base.format = OutputFormat::U16; + node.params.insert("color_mode".into(), Value::Bool(false)); + node.params.insert("roughness".into(), Value::Float(0.0)); + node.params.insert("pattern".into(), Value::PatternGraph(Box::new(pattern))); + graph.connect(input, "output", stamp, "pattern0").unwrap(); + (graph, input, stamp) +} + +#[test] +fn pattern_mips_of_a_resized_bitmap_preserve_the_measured_impulse() { + let (graph, input, stamp) = bitmap_impulse_graph(); + let mut package = Package::new("Impulse"); + package.graphs.push(graph); + let mut options = Options::new(&no_res); + options.inputs.insert("input".into(), Image::gray(32, 16, |x, y| f32::from(x == 10 && y == 8))); + let cache = Mutex::new(Cache::default()); + for expected in [[0, 2048, 12288, 2048, 0], [0, 1280, 5632, 1280, 0]] { + let result = cook(&package, 0, &options, &cache); + assert!(result.nodes.values().all(|node| node.error.is_none())); + let image = result.image(stamp, 0).unwrap(); + let levels = [30, 31, 32, 33, 34].map(|y| (image.get_gray(7, y, false) * 65535.0).round() as u16); + assert_eq!(levels, expected); + // Binding the identical bridge pixels at their final size supplies an ordinary mip chain. + options.inputs.insert("input".into(), result.image(input, 0).unwrap().clone()); + } +} + +#[test] +fn switch_color_storage_depends_on_whether_opacity_reads_a_graph_parameter() { + use materialcraft_core::{FunctionGraph, OutputFormat, ValueType}; + + let mut graph = Graph::new("Endpoint opacity"); + graph.size = [2; 2]; + let blend = graph.add_node("blend", [0.0; 2]); + graph.node_mut(blend).unwrap().params.insert("mode".into(), Value::Enum(7)); + let mut options = Options::new(&no_res); + for (port, level) in [("foreground", 0.5), ("background", 0.25)] { + let input = graph.add_node("input_color", [0.0; 2]); + graph.node_mut(input).unwrap().params.insert("identifier".into(), Value::Text(port.into())); + graph.connect(input, "output", blend, port).unwrap(); + options.inputs.insert( + port.into(), + Image::generate(4, 4, Kind::Color, |x, _| match x { + 0 => [level, -0.0, -0.25, -0.0], + 1 => [-level, -0.0, -0.25, -0.0], + _ => [f32::from_bits(0x8000_0001), level, 0.125, -0.0], + }), + ); + } + let mut package = Package::new("Switch selection"); + package.graphs.push(graph); + let cache = Mutex::new(Cache::default()); + for format in [OutputFormat::F16, OutputFormat::F32] { + package.graphs[0].format = format; + for (opacity, level) in [(0.0, 0.25), (1.0, 0.5)] { + options.overrides.insert("weight".into(), Value::Float(opacity)); + for bound in [false, true, false] { + let node = package.graphs[0].node_mut(blend).unwrap(); + node.params.insert("opacity".into(), Value::Float(opacity)); + if bound { + node.functions.insert("opacity".into(), FunctionGraph::input("weight", ValueType::Float)); + } else { + node.functions.remove("opacity"); + } + let cooked = cook(&package, 0, &options, &cache); + assert_eq!(cooked.nodes[&blend].error, None); + assert_eq!(cooked.nodes[&blend].parameters["mode"], Value::Enum(7)); + let image = cooked.image(blend, 0).unwrap(); + let zero = if bound { 0.0_f32 } else { -0.0 }; + assert_eq!(image.get(0, 0, false).map(f32::to_bits), [level, zero, -0.25, zero].map(f32::to_bits), "{format:?} {opacity} bound {bound}"); + assert_eq!(image.get(1, 0, false).map(f32::to_bits), [-level, -0.0, -0.25, -0.0].map(f32::to_bits)); + let tiny = if !bound && format == OutputFormat::F32 { f32::from_bits(0x8000_0001) } else { zero }; + assert_eq!(image.get(2, 0, false).map(f32::to_bits), [tiny, level, 0.125, zero].map(f32::to_bits)); + } + } + } +} + +#[test] +fn blend_preserves_the_selected_texture_levels_at_matching_precision() { + use materialcraft_core::{FunctionGraph, OutputFormat, ParameterInheritance, ValueType}; + + let (mut graph, input, stamp) = bitmap_impulse_graph(); + let blend = graph.add_node("blend", [0.0; 2]); + graph.connect(input, "output", blend, "foreground").unwrap(); + graph.connect(blend, "output", stamp, "pattern0").unwrap(); + let mut package = Package::new("Selected impulse"); + package.graphs.push(graph); + let mut options = Options::new(&no_res); + options.inputs.insert("input".into(), Image::gray(32, 16, |x, y| f32::from(x == 10 && y == 8))); + options.overrides.insert("coverage".into(), Value::Float(1.0)); + let cache = Mutex::new(Cache::default()); + for (mode, format, bound, expected) in [ + (7, OutputFormat::U16, false, [0, 2048, 12288, 2048, 0]), + (7, OutputFormat::U16, true, [0, 1280, 5632, 1280, 0]), + (0, OutputFormat::U16, false, [0, 2048, 12288, 2048, 0]), + (7, OutputFormat::U8, false, [0, 1285, 5654, 1285, 0]), + (7, OutputFormat::F32, false, [0, 1280, 5632, 1280, 0]), + ] { + let node = package.graphs[0].node_mut(blend).unwrap(); + node.params.insert("mode".into(), Value::Enum(mode)); + node.base.format_mode = ParameterInheritance::Absolute; + node.base.format = format; + if bound { + node.functions.insert("opacity".into(), FunctionGraph::input("coverage", ValueType::Float)); + } else { + node.functions.remove("opacity"); + } + let result = cook(&package, 0, &options, &cache); + assert!(result.nodes.values().all(|node| node.error.is_none())); + let image = result.image(stamp, 0).unwrap(); + let levels = [30, 31, 32, 33, 34].map(|y| (image.get_gray(7, y, false) * 65535.0).round() as u16); + assert_eq!(levels, expected); + } +} + +#[test] +fn bound_float_bitmap_reduces_close_texels_at_the_measured_filter_precision() { + let mut graph = Graph::new("Row reduction"); + graph.size = [4, 0]; + graph.format = materialcraft_core::OutputFormat::F32; + let input = graph.add_node("input_grayscale", [0.0; 2]); + let mut package = Package::new("Row reduction"); + package.graphs.push(graph); + for (width, row, sample, expected) in [(47, 15, 11, 0x3f00_001d), (65, 14, 9, 0x3f00_001d), (67, 14, 4, 0x3f00_001f)] { + let image = Image::gray(width, 1, |x, _| f32::from_bits(0x3f00_0000 + (13 * x + 7 * row + 3 * x * row + row * row) % 64)); + let mut options = Options::new(&no_res); + options.inputs.insert("input".into(), image); + let result = cook(&package, 0, &options, &Mutex::new(Cache::default())); + assert_eq!(result.image(input, 0).unwrap().get_gray(sample, 0, false).to_bits(), expected); + } +} + +#[test] +fn bound_float_bitmap_diffuses_half_rounding_after_resizing() { + let mut graph = Graph::new("Half input"); + graph.size = [5, 5]; + graph.format = materialcraft_core::OutputFormat::F16; + let input = graph.add_node("input_color", [0.0; 2]); + let mut package = Package::new("Half input"); + package.graphs.push(graph); + let mut options = Options::new(&no_res); + options.inputs.insert("input".into(), Image::filled(32, 17, Kind::Color, [1.0 + 1.0 / 2048.0, -1.0, 0.125, 0.12505])); + let result = cook(&package, 0, &options, &Mutex::new(Cache::default())); + let image = result.image(input, 0).unwrap(); + assert_eq!(image.get(0, 0, false), [1.0 + 1.0 / 1024.0, 0.0, 0.125, 0.125]); + assert_eq!(image.get(1, 0, false), [1.0, 0.0, 0.125, 0.125]); + assert_eq!(image.get(2, 0, false), [1.0 + 1.0 / 1024.0, 0.0, 0.125, 0.125 + 1.0 / 8192.0]); +} + +#[test] +fn bitmap_node_filters_odd_rasters_at_their_original_channel_depth() { + use materialcraft_core::{OutputFormat, Resource, ResourceBytes}; + + let mut graph = Graph::new("Odd bitmap"); + graph.size = [5, 5]; + graph.format = OutputFormat::U16; + let bitmap = graph.add_node("bitmap", [0.0; 2]); + let node = graph.node_mut(bitmap).unwrap(); + node.params.insert("resource".into(), Value::Text("field".into())); + node.params.insert("color_mode".into(), Value::Bool(false)); + let mut package = Package::new("Grayscale bitmap"); + package.graphs.push(graph); + for (depth, expected) in [(8_u8, [11308, 30326, 40349, 49087]), (16, [419, 4749, 33094, 35028])] { + let mut header = b"\x89PNG\r\n\x1a\n\0\0\0\rIHDR".to_vec(); + header.extend_from_slice(&37_u32.to_be_bytes()); + header.extend_from_slice(&23_u32.to_be_bytes()); + header.extend([depth, 0, 0, 0, 0]); + package.resources = vec![Resource::new("field", "field.png", ResourceBytes::new(header))]; + let field = Image::gray(37, 23, |x, y| { + if depth == 8 { + ((83 * x + 151 * y + 11 * x * y + 29) % 256) as f32 / 255.0 + } else { + ((573 * x + 149 * y + 97 * x * y + 317) % 65536) as f32 / 65535.0 + } + }) + .with_integer_sampling(true); + let resource = |_: &str| Some(field.clone()); + let result = cook(&package, 0, &Options::new(&resource), &Mutex::new(Cache::default())); + let image = result.image(bitmap, 0).unwrap(); + let levels = [(0, 0), (3, 7), (16, 16), (31, 31)].map(|(x, y)| (image.get_gray(x, y, false) * 65535.0).round() as u16); + assert_eq!(levels, expected); + } +} + +#[test] +fn odd_color_bitmap_resources_keep_their_channel_depth_during_filtering() { + use materialcraft_core::{OutputFormat, Resource, ResourceBytes}; + + let mut graph = Graph::new("Odd color bitmap"); + graph.size = [4, 4]; + graph.format = OutputFormat::U16; + let bitmap = graph.add_node("bitmap", [0.0; 2]); + let node = graph.node_mut(bitmap).unwrap(); + node.params.insert("resource".into(), Value::Text("field".into())); + node.params.insert("colour_space".into(), Value::Enum(1)); + let mut package = Package::new("Color bitmap"); + package.graphs.push(graph); + + for (width, height, depth, expected) in [ + (29_u32, 47_u32, 8, [[26985, 34181, 37522, 33924], [29555, 33667, 31354, 39321]]), + (41, 27, 16, [[4100, 4730, 9310, 10498], [39835, 29231, 35098, 11450]]), + ] { + let mut header = b"\x89PNG\r\n\x1a\n\0\0\0\rIHDR".to_vec(); + header.extend_from_slice(&width.to_be_bytes()); + header.extend_from_slice(&height.to_be_bytes()); + header.extend([depth, 6, 0, 0, 0]); + package.resources = vec![Resource::new("field", "field.png", ResourceBytes::new(header))]; + let levels = 1_u32 << depth; + let field = Image::generate(width, height, Kind::Color, |x, y| { + [(583, 191, 371, 3229), (47, 313, 59, 4511), (31, 693, 41, 8943), (997, 811, 97, 9043)] + .map(|(a, b, c, d)| ((a * x + b * y + c * x * y + d) % levels) as f32 / (levels - 1) as f32) + }) + .with_integer_sampling(true); + let resource = |key: &str| (craft_texture::split_resource_key(key) == ("field", true)).then(|| field.clone()); + let result = cook(&package, 0, &Options::new(&resource), &Mutex::new(Cache::default())); + let image = result.image(bitmap, 0).unwrap(); + assert_eq!([(0, 0), (6, 11)].map(|(x, y)| image.get(x, y, false).map(|v| (v * 65535.0).round() as u16)), expected); + } +} + +#[test] +fn bound_float_image_filters_an_odd_impulse_on_each_axis() { + let mut graph = Graph::new("Impulse"); + graph.size = [4, 4]; + graph.format = materialcraft_core::OutputFormat::F32; + let input = graph.add_node("input_grayscale", [0.0; 2]); + let mut package = Package::new("Float input"); + package.graphs.push(graph); + for (width, height, center) in [(3, 3, 0x3f524000), (35, 21, 0x3dbac261)] { + let mut options = Options::new(&no_res); + options.inputs.insert("input".into(), Image::gray(width, height, |x, y| f32::from(x == width / 2 && y == height / 2))); + let result = cook(&package, 0, &options, &Mutex::new(Cache::default())); + assert_eq!(result.image(input, 0).unwrap().get_gray(8, 8, false).to_bits(), center); + } +} + +#[test] +fn bound_float_image_with_an_odd_height_retains_its_stored_word_levels() { + let mut graph = Graph::new("Odd height"); + graph.size = [5, 5]; + graph.format = materialcraft_core::OutputFormat::U16; + let input = graph.add_node("input_color", [0.0; 2]); + let mut package = Package::new("Word input"); + package.graphs.push(graph); + let mut options = Options::new(&no_res); + options.inputs.insert("input".into(), Image::filled(32, 17, Kind::Color, [0.21875, 0.25, 0.5, 0.75])); + let result = cook(&package, 0, &options, &Mutex::new(Cache::default())); + let image = result.image(input, 0).unwrap(); + let levels = |x, y| image.get(x, y, false).map(|v| (v * 65535.0).round() as u16); + assert_eq!(levels(0, 0), [14335, 16383, 32768, 49152]); + assert_eq!(levels(1, 0), [14336, 16384, 32767, 49151]); + assert_eq!(levels(0, 2), [14336, 16384, 32768, 49151]); +} + +#[test] +fn bound_image_resizing_filters_normalized_levels_before_float_storage() { + let mut graph = Graph::new("levels"); + graph.size = [4, 4]; + graph.format = materialcraft_core::OutputFormat::F32; + let input = graph.add_node("input_color", [0.0; 2]); + let mut package = Package::new("levels"); + package.graphs.push(graph); + let stripe = Image::generate(8, 8, Kind::Color, |x, _| [(x % 2) as f32; 4]); + let cache = Mutex::new(Cache::default()); + for (normalized, expected) in [(true, 16384.0 / 65535.0), (false, 0.25)] { + let mut options = Options::new(&no_res); + options.inputs.insert("input".into(), stripe.clone().with_integer_sampling(normalized)); + let result = cook(&package, 0, &options, &cache); + assert_eq!(result.image(input, 0).unwrap().get(1, 0, false), [expected; 4]); + assert_eq!(result.image(input, 0).unwrap().get(0, 0, false), [0.0; 4]); + } +} + +#[test] +fn bound_image_resizing_filters_rgb_before_grayscale_conversion() { + let mut graph = Graph::new("Grayscale input"); + graph.size = [4, 4]; + graph.format = materialcraft_core::OutputFormat::F32; + let input = graph.add_node("input_grayscale", [0.0; 2]); + let mut package = Package::new("Channel order"); + package.graphs.push(graph); + let level = 1.0 / 65535.0; + let stripe = Image::generate(8, 8, Kind::Color, |x, _| [if x % 2 == 1 { level } else { 0.0 }, 0.0, 0.0, 1.0]); + let mut options = Options::new(&no_res); + options.inputs.insert("input".into(), stripe.with_integer_sampling(true)); + let result = cook(&package, 0, &options, &Mutex::new(Cache::default())); + let image = result.image(input, 0).unwrap(); + assert_eq!(image.get(1, 0, false)[0], 0.0); + assert_eq!(image.get(2, 0, false)[0], level * (1.0 / 3.0)); +} + +fn unchanged_size_after_read(getter: &str, variable: &str) -> materialcraft_core::FunctionGraph { + let mut graph = materialcraft_core::FunctionGraph::default(); + let read = graph.add(getter, &[], Some(Value::Text(variable.into()))); + let zero = graph.add_constant(Value::Int2([0, 0])); + graph.output = Some(graph.add("sequence", &[read, zero], None)); + graph +} + +#[test] +fn filters_store_normalized_inputs_at_their_working_precision_when_one_size_is_parameter_controlled() { + use materialcraft_core::{BaseParameter, OutputFormat, SizeMode}; + + let mut graph = Graph::new("Filter sizing"); + graph.size = [4, 4]; + graph.format = OutputFormat::U8; + let input = graph.add_node("input_grayscale", [0.0; 2]); + let source = graph.node_mut(input).unwrap(); + source.params.insert("identifier".into(), Value::Text("source".into())); + source.base.size_mode = SizeMode::RelativeToParent; + let levels = graph.add_node("levels", [64.0, 0.0]); + let curve = graph.node_mut(levels).unwrap(); + curve.base.size_mode = SizeMode::RelativeToParent; + curve.base.format = OutputFormat::F16; + curve.params.insert("in_low".into(), Value::Float4([0.21875; 4])); + curve.params.insert("in_high".into(), Value::Float4([0.46875; 4])); + graph.connect(input, "output", levels, "input").unwrap(); + let sharpen = graph.add_node("sharpen", [64.0, 64.0]); + let detail = graph.node_mut(sharpen).unwrap(); + detail.base.size_mode = SizeMode::RelativeToParent; + detail.base.format = OutputFormat::F16; + graph.connect(input, "output", sharpen, "input").unwrap(); + let [blur, fractional_half, fractional_float] = + [(24.0, OutputFormat::F16), (32.0, OutputFormat::F16), (32.0, OutputFormat::F32)].map(|(intensity, format)| { + let blur = graph.add_node("blur", [64.0, 128.0]); + let smooth = graph.node_mut(blur).unwrap(); + smooth.base.size_mode = SizeMode::RelativeToParent; + smooth.base.format = format; + smooth.params.insert("intensity".into(), Value::Float(intensity)); + graph.connect(input, "output", blur, "input").unwrap(); + blur + }); + let mut package = Package::new("Input precision"); + package.graphs.push(graph); + let mut options = Options::new(&no_res); + let field = Image::generate(16, 16, Kind::Gray, |x, y| { + let byte: u8 = match (x, y) { + (7, 8) => 5, + (9, 8) => 78, + (8, 7) => 31, + (8, 9) => 42, + _ => 58, + }; + [f32::from(byte) / 255.0; 4] + }); + options.inputs.insert("source".into(), field); + options.overrides.insert("gain".into(), Value::Float(0.375)); + let cache = Mutex::new(Cache::default()); + let runtime = unchanged_size_after_read("get_float1", "gain"); + for (source_dynamic, output_dynamic) in [(false, false), (true, false), (false, true), (true, true)] { + let [expected_levels, expected_sharpen, expected_blur, expected_half, expected_float] = if source_dynamic == output_dynamic { + [0x3d0e8000, 0x3f1e8000, 0x3e3e0000, 0x3e572000, 0x3e673a97] + } else { + [0x3d0e0000, 0x3f1e6000, 0x3e3de000, 0x3e570000, 0x3e673a99] + }; + for (id, dynamic) in [ + (input, source_dynamic), + (levels, output_dynamic), + (sharpen, output_dynamic), + (blur, output_dynamic), + (fractional_half, output_dynamic), + (fractional_float, output_dynamic), + ] { + let functions = &mut package.graphs[0].node_mut(id).unwrap().base.functions; + if dynamic { + functions.insert(BaseParameter::OutputSize, runtime.clone()); + } else { + functions.remove(&BaseParameter::OutputSize); + } + } + let cooked = cook(&package, 0, &options, &cache); + assert_eq!(cooked.nodes[&levels].error, None); + assert_eq!(cooked.image(levels, 0).unwrap().get_gray(0, 0, false).to_bits(), expected_levels); + assert_eq!(cooked.nodes[&sharpen].error, None); + assert_eq!(cooked.image(sharpen, 0).unwrap().get_gray(9, 8, false).to_bits(), expected_sharpen); + assert_eq!(cooked.nodes[&blur].error, None); + assert_eq!(cooked.image(blur, 0).unwrap().get_gray(7, 8, false).to_bits(), expected_blur); + assert_eq!(cooked.nodes[&fractional_half].error, None); + assert_eq!(cooked.image(fractional_half, 0).unwrap().get_gray(6, 7, false).to_bits(), expected_half); + assert_eq!(cooked.nodes[&fractional_float].error, None); + assert_eq!(cooked.image(fractional_float, 0).unwrap().get_gray(6, 5, false).to_bits(), expected_float); + } +} + +#[test] +fn half_blends_store_integer_inputs_on_different_size_paths() { + use materialcraft_core::{BaseParameter, OutputFormat, SizeMode}; + + let mut graph = Graph::new("Blend sizing"); + graph.size = [1, 0]; + graph.format = OutputFormat::U8; + let [foreground, background] = ["foreground", "background"].map(|identifier| { + let id = graph.add_node("input_grayscale", [0.0; 2]); + let node = graph.node_mut(id).unwrap(); + node.params.insert("identifier".into(), Value::Text(identifier.into())); + node.base.size_mode = SizeMode::RelativeToParent; + id + }); + let bridge = graph.add_node("dot", [0.0; 2]); + let blend = graph.add_node("blend", [0.0; 2]); + let node = graph.node_mut(blend).unwrap(); + node.base.format = OutputFormat::F16; + node.params.insert("opacity".into(), Value::Float(0.4)); + graph.connect(foreground, "output", bridge, "input").unwrap(); + graph.connect(bridge, "output", blend, "foreground").unwrap(); + graph.connect(background, "output", blend, "background").unwrap(); + let mut package = Package::new("Blend sizing"); + package.graphs.push(graph); + + let dimensions = unchanged_size_after_read("get_float2", "$size"); + let runtime = unchanged_size_after_read("get_float1", "gain"); + let mut options = Options::new(&no_res); + options.overrides.insert("gain".into(), Value::Float(0.375)); + for (name, levels) in [("foreground", [71.0, 55.0]), ("background", [155.0, 1.0])] { + options.inputs.insert(name.into(), Image::gray(2, 1, |x, _| levels[x as usize] / 255.0)); + } + let cache = Mutex::new(Cache::default()); + for (front, back, inherit, expected) in [ + (false, false, false, [0x3ef3c000, 0x3db58000]), + (true, false, false, [0x3ef3a000, 0x3db56000]), + (false, true, false, [0x3ef38000, 0x3db58000]), + (true, true, false, [0x3ef38000, 0x3db56000]), + (false, true, true, [0x3ef3a000, 0x3db56000]), + (true, true, true, [0x3ef3c000, 0x3db58000]), + ] { + let graph = &mut package.graphs[0]; + for (id, dynamic) in [(foreground, front), (background, back)] { + graph.node_mut(id).unwrap().base.functions.insert(BaseParameter::OutputSize, if dynamic { runtime.clone() } else { dimensions.clone() }); + } + graph.node_mut(blend).unwrap().base.size_mode = if inherit { SizeMode::RelativeToInput } else { SizeMode::RelativeToParent }; + let result = cook(&package, 0, &options, &cache); + assert!(result.nodes.values().all(|node| node.error.is_none())); + let pixels = result.image(blend, 0).unwrap(); + assert_eq!([0, 1].map(|x| pixels.get_gray(x, 0, false).to_bits()), expected); + assert!(cook(&package, 0, &options, &cache).nodes[&blend].cached); + } +} + +#[test] +fn half_pattern_backgrounds_store_integer_inputs_on_different_size_paths() { + use materialcraft_core::{BaseParameter, FunctionGraph, OutputFormat, PatternGraph, PatternNodeKind, SizeMode}; + + let mut graph = Graph::new("Pattern background sizing"); + graph.size = [4, 4]; + graph.format = OutputFormat::U8; + let background = graph.add_node("input_grayscale", [0.0; 2]); + let draw = graph.add_node("fx_map", [0.0; 2]); + let mut pattern = PatternGraph::with_root(PatternNodeKind::Quadrant); + let stamp = &mut pattern.nodes[0].parameters; + stamp.insert("patterntype".into(), Value::Int(2)); + let level = 3.0 / 32768.0; + stamp.insert("opacity".into(), Value::Float4([level, level, level, 1.0])); + let node = graph.node_mut(draw).unwrap(); + node.base.size_mode = SizeMode::RelativeToParent; + node.base.format = OutputFormat::F16; + node.params.insert("color_mode".into(), Value::Bool(false)); + node.params.insert("pattern".into(), Value::PatternGraph(Box::new(pattern))); + graph.connect(background, "output", draw, "background").unwrap(); + + let mut package = Package::new("Pattern sizing"); + package.graphs.push(graph); + let mut options = Options::new(&no_res); + options.inputs.insert("input".into(), Image::gray(16, 16, |_, _| 58.0 / 255.0)); + options.overrides.insert("gain".into(), Value::Float(0.375)); + let cache = Mutex::new(Cache::default()); + let fixed = FunctionGraph::constant(Value::Int2([0, 0])); + let system = unchanged_size_after_read("get_float2", "$sizelog2"); + let exposed = unchanged_size_after_read("get_float1", "gain"); + for (source_size, draw_size, expected) in [(&fixed, &system, 1864.0), (&fixed, &exposed, 1863.0), (&exposed, &fixed, 1863.0), (&exposed, &exposed, 1864.0)] + { + for (id, size) in [(background, source_size), (draw, draw_size)] { + package.graphs[0].node_mut(id).unwrap().base.functions.insert(BaseParameter::OutputSize, size.clone()); + } + let result = cook(&package, 0, &options, &cache); + assert!(result.nodes.values().all(|node| node.error.is_none())); + assert_eq!(result.image(draw, 0).unwrap().get_gray(8, 8, false), expected / 8192.0); + } +} + +#[test] +fn untiled_pattern_backgrounds_sample_directly_on_the_same_size_path() { + use materialcraft_core::{BaseParameter, FunctionGraph, OutputFormat, ParameterInheritance, PatternGraph, PatternNodeKind, SizeMode}; + + let mut graph = Graph::new("Resized pattern background"); + graph.size = [4, 5]; + graph.format = OutputFormat::U8; + let input = graph.add_node("input_grayscale", [0.0; 2]); + let background = graph.add_node("fx_map", [0.0; 2]); + let draw = graph.add_node("fx_map", [0.0; 2]); + let levels = graph.add_node("levels", [0.0; 2]); + for id in [input, background, levels] { + let base = &mut graph.node_mut(id).unwrap().base; + base.size_mode = SizeMode::RelativeToParent; + base.size = [-1, -1]; + } + for id in [background, draw] { + let mut pattern = PatternGraph::with_root(PatternNodeKind::Quadrant); + if id == draw { + let stamp = &mut pattern.nodes[0].parameters; + stamp.insert("patterntype".into(), Value::Int(2)); + stamp.insert("opacity".into(), Value::Float4([0.10067749, 0.10067749, 0.10067749, 1.0])); + } + let node = graph.node_mut(id).unwrap(); + node.params.insert("pattern".into(), Value::PatternGraph(Box::new(pattern))); + node.params.insert("color_mode".into(), Value::Bool(false)); + } + graph.connect(input, "output", background, "background").unwrap(); + graph.connect(background, "output", levels, "input").unwrap(); + let mut package = Package::new("Pattern sample precision"); + package.graphs.push(graph); + let mut options = Options::new(&no_res); + options.inputs.insert("input".into(), Image::gray(8, 16, |x, y| ((47 * x + 83 * y + 11 * x * y + 849807) % 256) as f32 / 255.0)); + options.overrides.insert("gain".into(), Value::Float(0.375)); + let cache = Mutex::new(Cache::default()); + + let fixed = FunctionGraph::constant(Value::Int2([0, 0])); + let exposed = unchanged_size_after_read("get_float1", "gain"); + for (source, tiling, size, byte, half, corner) in [ + (input, [false, false], &fixed, 128.0, 0.5317383, 169.0), + (background, [false, false], &fixed, 128.0, 0.5317383, 169.0), + (background, [true, false], &fixed, 129.0, 0.53125, 171.0), + (levels, [false, false], &fixed, 128.0, 0.5317383, 169.0), + (levels, [true, true], &fixed, 129.0, 0.53125, 171.0), + (background, [false, false], &exposed, 129.0, 0.53125, 171.0), + ] { + let graph = &mut package.graphs[0]; + graph.connect(source, "output", draw, "background").unwrap(); + let base = &mut graph.node_mut(source).unwrap().base; + base.tiling_mode = ParameterInheritance::Absolute; + base.tiling = tiling; + let base = &mut graph.node_mut(draw).unwrap().base; + base.tiling_mode = ParameterInheritance::Absolute; + base.tiling = [true, true]; + base.size_mode = SizeMode::RelativeToParent; + base.functions.insert(BaseParameter::OutputSize, size.clone()); + for (format, x, expected) in [(OutputFormat::U8, 2, byte / 255.0), (OutputFormat::F16, 4, half)] { + package.graphs[0].node_mut(draw).unwrap().base.format = format; + let result = cook(&package, 0, &options, &cache); + assert!(result.nodes.values().all(|node| node.error.is_none())); + let pixels = result.image(draw, 0).unwrap(); + assert_eq!(pixels.get_gray(x, 2, false), expected, "{format:?}"); + if format == OutputFormat::U8 { + assert_eq!(pixels.get_gray(0, 0, false), corner / 255.0); + } + } + } + + // Enlarge only Y. Repeating X still permits a direct sample. + let graph = &mut package.graphs[0]; + graph.connect(input, "output", draw, "background").unwrap(); + graph.node_mut(input).unwrap().base.size = [0, -1]; + let draw_base = &mut graph.node_mut(draw).unwrap().base; + draw_base.tiling = [false, false]; + draw_base.format = OutputFormat::U8; + draw_base.functions.insert(BaseParameter::OutputSize, fixed); + options.inputs.insert("input".into(), Image::gray(16, 16, |x, y| ((47 * x + 83 * y + 11 * x * y + 849807) % 256) as f32 / 255.0)); + for (source_tiling, byte) in [([true, false], 149.0), ([false, true], 150.0)] { + package.graphs[0].node_mut(input).unwrap().base.tiling = source_tiling; + let result = cook(&package, 0, &options, &cache); + assert!(result.nodes.values().all(|node| node.error.is_none())); + assert_eq!(result.image(draw, 0).unwrap().get_gray(2, 2, false), byte / 255.0); + } +} + +#[test] +fn connected_input_sizes_share_the_last_two_dimensional_filter_pass() { + use materialcraft_core::{OutputFormat, SizeMode}; + let (mut parent, instance) = instancing("Parent", "Resize"); + let source = parent.add_node("input_color", [0.0; 2]); + let source_base = &mut parent.node_mut(source).unwrap().base; + source_base.size_mode = SizeMode::Absolute; + source_base.format = OutputFormat::F32; + parent.connect(source, "output", instance, "input").unwrap(); + let mut child = Graph::new("Resize"); + let bridge = child.add_node("input_color", [0.0; 2]); + let inner_base = &mut child.node_mut(bridge).unwrap().base; + inner_base.size_mode = SizeMode::Absolute; + inner_base.size = [4, 3]; + inner_base.format = OutputFormat::F16; + let output = child.add_node("output", [0.0; 2]); + child.connect(bridge, "output", output, "input").unwrap(); + let mut package = Package::new("Rectangular input"); + package.graphs.extend([parent, child]); + let mut options = Options::new(&no_res); + let cache = Mutex::new(Cache::default()); + let high = 1.0 + 1.0 / 1024.0; + for (size, red, green) in [([5, 5], high, 1.0), ([6, 4], 1.0, high), ([5, 4], 1.0, 1.0)] { + package.graphs[0].node_mut(source).unwrap().base.size = size; + let image = Image::generate(1 << size[0], 1 << size[1], Kind::Color, |x, y| { + let r = if x % 2 == 0 { 1.0 } else { high }; + let g = if y % 2 == 0 { 1.0 } else { high }; + [r, g, -r, -g] + }); + options.inputs.insert("input".into(), image); + let result = cook(&package, 0, &options, &cache); + assert_eq!(result.nodes[&instance].error, None); + let image = result.image(instance, 0).unwrap(); + assert_eq!((image.width(), image.height()), (16, 8)); + assert!( + image.data().as_chunks::<4>().0.iter().all(|&pixel| pixel == [red, green, -red, -green]), + "source {size:?}, first {:?}", + image.get(0, 0, false) + ); + } +} + +#[test] +fn an_image_bridge_resolves_its_size_against_its_own_wire() { + use materialcraft_core::SizeMode; + + let (mut parent, connected) = instancing("Parent", "Bridge"); + let unconnected = parent.add_node("graph_instance", [0.0, 80.0]); + parent.node_mut(unconnected).unwrap().params.insert("graph".into(), Value::Text("Bridge".into())); + for id in [connected, unconnected] { + let base = &mut parent.node_mut(id).unwrap().base; + base.size_mode = SizeMode::Absolute; + base.size = [6; 2]; + } + let input = parent.add_node("input_grayscale", [0.0; 2]); + let source = &mut parent.node_mut(input).unwrap().base; + source.size_mode = SizeMode::Absolute; + source.size = [4, 5]; + parent.connect(input, "output", connected, "input").unwrap(); + + let mut child = Graph::new("Bridge"); + let bridge = child.add_node("input_grayscale", [0.0; 2]); + let output = child.add_node("output", [100.0, 0.0]); + child.connect(bridge, "output", output, "input").unwrap(); + let mut package = Package::new("Bridge sizes"); + package.graphs.extend([parent, child]); + let options = Options::new(&no_res); + let cache = Mutex::new(Cache::default()); + for (mode, size, expected) in [ + (SizeMode::RelativeToInput, [0, 0], [(16, 32), (64, 64)]), + (SizeMode::RelativeToInput, [-1, 1], [(8, 64), (32, 128)]), + (SizeMode::RelativeToParent, [0, 0], [(64, 64); 2]), + (SizeMode::Absolute, [5, 4], [(32, 16); 2]), + ] { + let base = &mut package.graphs[1].node_mut(bridge).unwrap().base; + base.size_mode = mode; + base.size = size; + let cooked = cook(&package, 0, &options, &cache); + let dimensions = [connected, unconnected].map(|id| { + assert_eq!(cooked.nodes[&id].error, None); + let image = cooked.image(id, 0).unwrap(); + (image.width(), image.height()) + }); + assert_eq!(dimensions, expected); + } +} + +#[test] +fn bound_image_resizing_reads_the_upstream_float_format_inside_instances() { + use materialcraft_core::{OutputFormat, SizeMode}; + let (mut parent, instance) = instancing("Parent", "Resized"); + let source = parent.add_node("input_grayscale", [0.0; 2]); + let base = &mut parent.node_mut(source).unwrap().base; + base.size_mode = SizeMode::Absolute; + base.size = [3, 3]; + parent.connect(source, "output", instance, "input").unwrap(); + let mut child = Graph::new("Resized"); + child.absolute_output_size = Some([4, 4]); + let bridge = child.add_node("input_grayscale", [0.0; 2]); + child.node_mut(bridge).unwrap().base.size_mode = SizeMode::RelativeToParent; + child.node_mut(bridge).unwrap().base.format = OutputFormat::F32; + let output = child.add_node("output", [100.0, 0.0]); + child.connect(bridge, "output", output, "input").unwrap(); + let mut package = Package::new("Stored levels"); + package.graphs.extend([parent, child]); + let corners = [0x3fd0e000, 0xbfa46000, 0xc02d8000, 0x407f0000]; + let image = Image::gray(8, 8, |x, y| f32::from_bits(corners[((y % 2) * 2 + x % 2) as usize])); + let mut options = Options::new(&no_res); + options.inputs.insert("input".into(), image); + let cache = Mutex::new(Cache::default()); + for (format, expected) in [(OutputFormat::F32, 0x3ed5f000), (OutputFormat::F16, 0x3ed60000), (OutputFormat::F32, 0x3ed5f000)] { + package.graphs[0].node_mut(source).unwrap().base.format = format; + let cooked = cook(&package, 0, &options, &cache); + assert_eq!(cooked.nodes[&instance].error, None); + assert_eq!(cooked.image(instance, 0).unwrap().get(1, 1, false)[0].to_bits(), expected); + } +} + +#[test] +fn wired_input_sampling_keeps_the_source_texture_and_stores_the_direct_output() { + use materialcraft_core::{FunctionGraph, OutputFormat, ParameterInheritance, SizeMode}; + let (mut parent, instance) = instancing("Parent", "TwoReads"); + let source = parent.add_node("input_grayscale", [0.0; 2]); + let base = &mut parent.node_mut(source).unwrap().base; + base.size_mode = SizeMode::Absolute; + base.size = [3, 3]; + base.format = OutputFormat::U8; + parent.connect(source, "output", instance, "input").unwrap(); + let mut child = Graph::new("TwoReads"); + child.absolute_output_size = Some([4, 4]); + let bridge = child.add_node("input_grayscale", [0.0; 2]); + child.node_mut(bridge).unwrap().base.size_mode = SizeMode::RelativeToParent; + child.node_mut(bridge).unwrap().base.format = OutputFormat::F16; + let reader = child.add_node("pixel_processor", [0.0; 2]); + let node = child.node_mut(reader).unwrap(); + node.base.format = OutputFormat::F32; + node.params.insert("color_mode".into(), Value::Bool(false)); + child.connect(bridge, "output", reader, "input0").unwrap(); + for (name, source) in [("output", reader), ("passed", bridge)] { + let output = child.add_node("output", [0.0; 2]); + child.node_mut(output).unwrap().params.insert("identifier".into(), Value::Text(name.into())); + child.connect(source, "output", output, "input").unwrap(); + } + let mut package = Package::new("Wired sampling"); + package.graphs.extend([parent, child]); + let mut options = Options::new(&no_res); + options.inputs.insert("input".into(), Image::gray(8, 8, |x, _| (x % 2) as f32)); + let cache = Mutex::new(Cache::default()); + for (filter, tile, sample, direct_edge) in [(0, true, 0.0, 0.25), (1, true, 16384.0 / 65535.0, 0.25), (1, false, 16384.0 / 65535.0, 0.0)] { + let base = &mut package.graphs[1].node_mut(bridge).unwrap().base; + base.tiling_mode = ParameterInheritance::Absolute; + base.tiling = [tile, false]; + let mut function = FunctionGraph::default(); + let pos = function.add("get_float2", &[], Some(Value::Text("$pos".into()))); + function.output = Some(function.add("samplelum", &[pos], Some(Value::Int2([0, filter])))); + package.graphs[1].node_mut(reader).unwrap().params.insert("function".into(), Value::Function(Box::new(function))); + let cooked = cook(&package, 0, &options, &cache); + assert_eq!(cooked.nodes[&instance].error, None); + assert_eq!(cooked.image(instance, 0).unwrap().get(1, 0, false)[0], sample); + assert_eq!(cooked.image(instance, 1).unwrap().get(0, 0, false)[0], direct_edge); + } +} + +#[test] +fn wired_value_and_pattern_functions_read_the_callers_texture() { + use materialcraft_core::{FunctionGraph, OutputFormat, PatternGraph, PatternNodeKind}; + let (mut parent, instance) = instancing("Parent", "Sample"); + parent.size = [5; 2]; + let source = parent.add_node("input_color", [0.0; 2]); + parent.node_mut(source).unwrap().base.format = OutputFormat::F32; + parent.connect(source, "output", instance, "input").unwrap(); + + let mut child = Graph::new("Sample"); + let bridge = child.add_node("input_color", [0.0; 2]); + child.node_mut(bridge).unwrap().base.format = OutputFormat::U16; + let mut function = FunctionGraph::default(); + let coord = function.add_constant(Value::Float2([0.375, 0.6875])); + function.output = Some(function.add("samplecol", &[coord], Some(Value::Int2([0, 1])))); + let reader = child.add_node("value_processor", [0.0; 2]); + child.node_mut(reader).unwrap().params.insert("function".into(), Value::Function(Box::new(function.clone()))); + child.connect(bridge, "output", reader, "input0").unwrap(); + + let mut pattern = PatternGraph::with_root(PatternNodeKind::Quadrant); + pattern.nodes[0].parameters.insert("patterntype".into(), Value::Int(2)); + pattern.nodes[0].parameters.insert("opacity".into(), Value::Function(Box::new(function))); + let draw = child.add_node("fx_map", [0.0; 2]); + let node = child.node_mut(draw).unwrap(); + node.base.format = OutputFormat::F32; + node.params.insert("color_mode".into(), Value::Bool(true)); + node.params.insert("background".into(), Value::Color([0.0; 4])); + node.params.insert("pattern".into(), Value::PatternGraph(Box::new(pattern))); + child.connect(bridge, "output", draw, "pattern0").unwrap(); + for (name, source) in [("output", draw), ("sample", reader)] { + let output = child.add_node("output", [0.0; 2]); + child.node_mut(output).unwrap().params.insert("identifier".into(), Value::Text(name.into())); + child.connect(source, "output", output, "input").unwrap(); + } + let mut package = Package::new("Wired color sampling"); + package.graphs.extend([parent, child]); + let mut options = Options::new(&no_res); + let field = Image::generate(32, 32, Kind::Color, |x, y| { + std::array::from_fn(|i| ((37 * x + 41 * y + 7 * x * y + 53 * 19 + 61 * i as u32 + 5 * x * i as u32) % 509) as f32 / 508.0) + }); + options.inputs.insert("input".into(), field); + let result = cook(&package, 0, &options, &Mutex::new(Cache::default())); + assert_eq!(result.nodes[&instance].error, None); + let color = [0.44734252, 0.43011808, 0.4128937, 0.64616144]; + assert_eq!(result.value(instance, 1), Some(&Value::Float4(color))); + let drawn = [0.2890555, 0.27792573, 0.266796, 0.64616144]; + assert_eq!(result.image(instance, 0).unwrap().get(0, 0, false), drawn); +} + +#[test] +fn value_processor_reads_the_upstream_channel_format_after_a_cache_hit() { + use materialcraft_core::{FunctionGraph, OutputFormat}; + + let mut function = FunctionGraph::default(); + let uv = function.add_constant(Value::Float2([0.5, 0.5])); + function.output = Some(function.add("samplelum", &[uv], Some(Value::Int2([0, 0])))); + let mut graph = Graph::new("Value sample"); + graph.size = [4; 2]; + let input = graph.add_node("input_grayscale", [0.0; 2]); + let processor = graph.add_node("value_processor", [0.0; 2]); + graph.node_mut(processor).unwrap().params.insert("function".into(), Value::Function(Box::new(function))); + graph.connect(input, "output", processor, "input0").unwrap(); + let mut package = Package::new("Value sample"); + package.graphs.push(graph); + let mut options = Options::new(&no_res); + let channel = 222.0_f32 / 255.0; + options.inputs.insert("input".into(), Image::gray(16, 16, |_, _| channel)); + let cache = Mutex::new(Cache::default()); + for (format, expected) in [(OutputFormat::U8, 222.0 * (1.0 / 255.0)), (OutputFormat::F32, channel)] { + package.graphs[0].node_mut(input).unwrap().base.format = format; + let result = cook(&package, 0, &options, &cache); + assert_eq!(result.nodes[&processor].error, None); + assert_eq!(result.value(processor, 0), Some(&Value::Float(expected))); + let cached = cook(&package, 0, &options, &cache); + assert!(cached.nodes[&processor].cached); + assert_eq!(cached.value(processor, 0), Some(&Value::Float(expected))); + } +} + #[test] fn input_nodes_read_bound_preview_images() { let mut p = Package::new("p"); @@ -587,7 +1898,10 @@ fn linear_input_images_and_bitmap_nodes_request_data_reads() { (c.image(i, 0).unwrap().data()[0], c.image(b, 0).unwrap().data()[0]) }; - assert_eq!(first(&p), (0.2, 0.2), "default is sRGB, as before"); + assert_eq!(first(&p), (0.2, 0.5), "the bitmap defaults to file channels"); + + p.graphs[0].node_mut(b).unwrap().params.insert("colour_space".into(), Value::Enum(0)); + assert_eq!(first(&p), (0.2, 0.2), "an explicit sRGB read still decodes the color"); p.graphs[0].input_images_linear.insert("n".into()); p.graphs[0].node_mut(b).unwrap().params.insert("colour_space".into(), Value::Enum(1)); @@ -713,10 +2027,50 @@ fn cooked_parameters_retain_values_without_processor_graph_copies() { } #[test] -fn enabled_generators_use_parent_size_and_seed_with_input_image_properties() { +fn a_pattern_uses_only_its_background_for_input_relative_size_and_precision() { + use materialcraft_core::{OutputFormat, ParameterInheritance, SizeMode}; + + let mut graph = Graph::new("Pattern inputs"); + graph.size = [5, 4]; + graph.format = OutputFormat::U8; + let stamp = graph.add_node("uniform", [0.0; 2]); + let back = graph.add_node("uniform", [0.0; 2]); + for (id, size, format) in [(stamp, [6; 2], OutputFormat::F32), (back, [4, 5], OutputFormat::U16)] { + let base = &mut graph.node_mut(id).unwrap().base; + base.size_mode = SizeMode::Absolute; + base.size = size; + base.format = format; + } + let draw = graph.add_node("fx_map", [100.0, 0.0]); + graph.node_mut(draw).unwrap().base.format_mode = ParameterInheritance::RelativeToInput; + graph.connect(stamp, "output", draw, "pattern0").unwrap(); + graph.connect(back, "output", draw, "background").unwrap(); + let mut package = Package::new("Pattern input inheritance"); + package.graphs.push(graph); + let cache = Mutex::new(Cache::default()); + let result = |package: &Package| { + let cooked = cook(package, 0, &Options::new(&no_res), &cache); + let item = &cooked.nodes[&draw]; + assert_eq!(item.error, None); + (item.base.size, item.base.format) + }; + assert_eq!(result(&package), ([16, 32], OutputFormat::U16)); + package.graphs[0].node_mut(draw).unwrap().base.size = [-1, 1]; + assert_eq!(result(&package), ([8, 64], OutputFormat::U16)); + assert!(package.graphs[0].disconnect(draw, "background")); + assert_eq!(result(&package), ([16, 32], OutputFormat::U8)); + // Bypassing this draw still passes through the available stamp texture. + package.graphs[0].node_mut(draw).unwrap().disabled = true; + assert_eq!(result(&package), ([64, 64], OutputFormat::F32)); +} + +#[test] +fn enabled_nodes_resolve_size_from_the_graph_or_their_primary_image() { use materialcraft_core::{BaseParameter, FunctionGraph, OutputFormat, ParameterInheritance, SizeMode, ValueType}; - for definition in ["svg", "fx_map"] { + for (definition, port, size, preview) in + [("pixel_processor", "input0", [64_u32, 32], (16, 8)), ("svg", "background", [64, 32], (16, 8)), ("fx_map", "background", [32, 64], (8, 16))] + { for dynamic in [false, true] { let mut graph = Graph::new("Generator sizes"); graph.size = [6, 5]; @@ -733,16 +2087,20 @@ fn enabled_generators_use_parent_size_and_seed_with_input_image_properties() { base.pixel_size = [0.25, 0.5]; base.pixel_size_mode = ParameterInheritance::Absolute; let generator = graph.add_node(definition, [200.0, 0.0]); - graph.node_mut(generator).unwrap().base.format_mode = ParameterInheritance::RelativeToInput; + let node = graph.node_mut(generator).unwrap(); + node.base.format_mode = ParameterInheritance::RelativeToInput; + if definition == "pixel_processor" { + node.params.insert("function".into(), Value::Function(Box::new(FunctionGraph::constant(Value::Float4([0.25; 4]))))); + } if dynamic { let mut function = FunctionGraph::input("$sizelog2", ValueType::Float2); - let size = function.output.unwrap(); - let parent = function.add_constant(Value::Float2([6.0, 5.0])); - let difference = function.add("sub", &[size, parent], None); + let actual = function.output.unwrap(); + let expected = function.add_constant(Value::Float2(size.map(|axis| axis.ilog2() as f32))); + let difference = function.add("sub", &[actual, expected], None); function.output = Some(function.add("toint2", &[difference], None)); graph.node_mut(generator).unwrap().base.functions.insert(BaseParameter::OutputSize, function); } - graph.connect(background, "output", generator, "background").unwrap(); + graph.connect(background, "output", generator, port).unwrap(); let mut package = Package::new("Generator sizes"); package.graphs.push(graph); let cache = Mutex::new(Cache::default()); @@ -753,8 +2111,8 @@ fn enabled_generators_use_parent_size_and_seed_with_input_image_properties() { let result = &cooked.nodes[&generator]; assert_eq!(result.error, None, "{definition}"); - assert_eq!(result.base.size, [64, 32], "{definition}, dynamic: {dynamic}"); - assert_eq!(cooked.image(generator, 0).map(|image| (image.width(), image.height())), Some((16, 8))); + assert_eq!(result.base.size, size, "{definition}, dynamic: {dynamic}"); + assert_eq!(cooked.image(generator, 0).map(|image| (image.width(), image.height())), Some(preview)); assert_eq!(result.base.seed, 0); assert_eq!(result.base.format, OutputFormat::F32); assert_eq!(result.base.tiling, [false, true]); @@ -764,7 +2122,7 @@ fn enabled_generators_use_parent_size_and_seed_with_input_image_properties() { if !dynamic { assert_eq!( node_size(&package.graphs[0], materialcraft_nodes::find(definition), package.graphs[0].node(generator).unwrap(), Some((32, 64)), Some(16)), - (16, 8) + preview ); } @@ -774,6 +2132,10 @@ fn enabled_generators_use_parent_size_and_seed_with_input_image_properties() { assert_eq!(cooked.nodes[&generator].error, None); assert_eq!(cooked.nodes[&generator].base.size, cooked.nodes[&background].base.size); assert_eq!(cooked.image(generator, 0).map(|image| (image.width(), image.height())), Some((8, 16))); + assert_eq!( + node_size(&package.graphs[0], materialcraft_nodes::find(definition), package.graphs[0].node(generator).unwrap(), Some((32, 64)), Some(16)), + (8, 16) + ); } } } @@ -825,3 +2187,347 @@ fn a_color_parameter_function_may_return_a_gray_level_or_an_rgb_triple() { assert_eq!(result.parameters.get("color").and_then(Value::as_vec4), Some(expected)); } } + +#[test] +fn levels_widens_scalar_endpoints_to_opaque_gray_and_normalizes_integer_controls() { + use materialcraft_core::{FunctionGraph, OutputFormat}; + + for (format, numerator, denominator, expected) in [ + (OutputFormat::F32, 1.0, 0.125, [8.0, 8.0, 8.0, 1.0]), + (OutputFormat::U8, 1.0, 0.0, [1.0; 4]), + (OutputFormat::U16, 1.0, -0.0, [0.0, 0.0, 0.0, 1.0]), + (OutputFormat::U16, 0.0, 0.0, [0.0, 0.0, 0.0, 1.0]), + ] { + let mut function = FunctionGraph::default(); + let a = function.add_constant(Value::Float(numerator)); + let b = function.add_constant(Value::Float(denominator)); + function.output = Some(function.add("div", &[a, b], None)); + let mut graph = Graph::new("Channel control"); + let levels = graph.add_node("levels", [0.0; 2]); + let node = graph.node_mut(levels).unwrap(); + node.base.format = format; + node.functions.insert("in_high".into(), function); + let mut package = Package::new("Channel control"); + package.graphs.push(graph); + let cooked = cook(&package, 0, &Options::new(&no_res), &Mutex::new(Cache::default())); + assert_eq!(cooked.nodes[&levels].error, None); + assert_eq!(cooked.nodes[&levels].parameters["in_high"], Value::Float4(expected)); + } +} + +fn instanced_seed_field() -> (Package, NodeId, NodeId) { + let (mut parent, instance) = instancing("Parent", "Field"); + parent.seed = 19; + parent.node_mut(instance).unwrap().base.seed = 3; + let mut child = Graph::new("Field"); + child.size = parent.size; + let noise = child.add_node("pixel_processor", [0.0; 2]); + let mut function = materialcraft_core::FunctionGraph::default(); + let maximum = function.add_constant(Value::Float(1.0)); + function.output = Some(function.add("rand", &[maximum], None)); + child.node_mut(noise).unwrap().params.insert("function".into(), Value::Function(Box::new(function))); + let output = child.add_node("output", [100.0, 0.0]); + child.connect(noise, "output", output, "input").unwrap(); + let mut pkg = Package::new("Seed controls"); + pkg.graphs.extend([parent, child]); + (pkg, instance, output) +} + +#[test] +fn an_instanced_graph_resolves_its_own_seed_after_the_instance() { + use materialcraft_core::ParameterInheritance::{Absolute, RelativeToInput, RelativeToParent}; + let (mut pkg, instance, output) = instanced_seed_field(); + let cache = Mutex::new(Cache::default()); + for (mode, offset, expected) in [(Absolute, 0, 0), (Absolute, 5, 5), (RelativeToParent, 5, 27), (RelativeToInput, -3, 19)] { + pkg.graphs[1].seed = expected; + let direct = cook(&pkg, 1, &Options::new(&no_res), &cache); + pkg.graphs[1].seed = offset; + pkg.graphs[1].seed_mode = mode; + let nested = cook(&pkg, 0, &Options::new(&no_res), &cache); + assert_eq!(nested.nodes[&instance].error, None); + assert_eq!(nested.image(instance, 0).unwrap().data(), direct.image(output, 0).unwrap().data(), "{mode:?} {offset}"); + } +} + +#[test] +fn graph_seed_functions_read_the_resolved_dimensions_of_the_child() { + use materialcraft_core::{FunctionGraph, ParameterInheritance, ValueType}; + let (mut package, instance, output) = instanced_seed_field(); + package.graphs[1].seed_mode = ParameterInheritance::Absolute; + let mut literal = package.clone(); + let options = Options::new(&no_res); + let cache = Mutex::new(Cache::default()); + for (name, axis, threshold, parent, absolute, expected_seed) in [ + ("$size", 0, 20.0, [5, 4], None, 5), + ("$size", 1, 20.0, [5, 4], None, 0), + ("$sizelog2", 1, 4.5, [4, 5], None, 5), + ("$size", 0, 12.0, [5, 4], Some([3, 4]), 0), + ("$sizelog2", 1, 3.5, [4, 5], Some([3, 4]), 5), + ] { + let mut function = FunctionGraph::input(name, ValueType::Float2); + let selected = function.add("swizzle1", &[function.output.unwrap()], Some(Value::Int(axis))); + let limit = function.add_constant(Value::Float(threshold)); + let predicate = function.add("gt", &[selected, limit], None); + let yes = function.add_constant(Value::Int(5)); + let no = function.add_constant(Value::Int(0)); + function.output = Some(function.add("ifelse", &[predicate, yes, no], None)); + package.graphs[0].size = parent; + package.graphs[1].absolute_output_size = absolute; + package.graphs[1].seed_function = Some(function); + literal.graphs[1].size = parent; + literal.graphs[1].absolute_output_size = absolute; + literal.graphs[1].seed = expected_seed; + let actual = cook(&package, 0, &options, &cache); + assert_eq!(actual.nodes[&instance].error, None); + let reference = cook(&literal, 1, &options, &cache); + assert_eq!(actual.image(instance, 0).unwrap().data(), reference.image(output, 0).unwrap().data(), "{name} {axis} {parent:?} {absolute:?}"); + } +} + +#[test] +fn graph_seed_functions_use_the_child_argument_before_cooking_its_nodes() { + use materialcraft_core::{ExposedParameter, FunctionGraph, ParameterInheritance, ValueType}; + let (mut package, instance, output) = instanced_seed_field(); + let input = ExposedParameter { + id: "offset".into(), + label: "Offset".into(), + default: Value::Int(5), + connectable: false, + min: -20.0, + max: 20.0, + clamp: false, + step: None, + editor: None, + description: String::new(), + group: String::new(), + options: Vec::new(), + }; + package.graphs[1].exposed.push(input); + let mut reference = package.clone(); + let cache = Mutex::new(Cache::default()); + let options = Options::new(&no_res); + let function = FunctionGraph::input("offset", ValueType::Integer); + let mut graph = serde_json::to_value(&package.graphs[1]).unwrap(); + graph["seedFunction"] = serde_json::to_value(&function).unwrap(); + package.graphs[1] = serde_json::from_value(graph).unwrap(); + for (mode, input, expected) in [ + (ParameterInheritance::Absolute, None, 5), + (ParameterInheritance::RelativeToParent, None, 27), + (ParameterInheritance::RelativeToInput, Some(-3), 19), + (ParameterInheritance::Absolute, Some(-3), -3), + ] { + package.graphs[1].seed_mode = mode; + if let Some(value) = input { + package.graphs[0].node_mut(instance).unwrap().params.insert("offset".into(), Value::Int(value)); + } + reference.graphs[1].seed = expected; + let direct = cook(&reference, 1, &options, &cache); + let nested = cook(&package, 0, &options, &cache); + assert_eq!(nested.nodes[&instance].error, None); + assert_eq!(nested.image(instance, 0).unwrap().data(), direct.image(output, 0).unwrap().data(), "{mode:?} {input:?}"); + } + + let mut wrong_type = FunctionGraph::default(); + wrong_type.output = Some(wrong_type.add_constant(Value::Text("invalid".into()))); + package.graphs[1].seed_function = Some(wrong_type); + let invalid = cook(&package, 0, &options, &cache); + assert!(invalid.nodes[&instance].error.as_deref().unwrap().contains("graph random seed")); +} + +#[test] +fn nested_generators_keep_the_child_graph_output_format() { + use materialcraft_core::OutputFormat; + let (mut parent, instance) = instancing("Parent", "Field"); + let mut child = Graph::new("Field"); + child.size = parent.size; + let processor = child.add_node("pixel_processor", [0.0; 2]); + let mut function = materialcraft_core::FunctionGraph::default(); + let value = function.add_constant(Value::Float(0.347821)); + function.output = Some(value); + child.node_mut(processor).unwrap().params.insert("function".into(), Value::Function(Box::new(function))); + let output = child.add_node("output", [100.0, 0.0]); + child.connect(processor, "output", output, "input").unwrap(); + parent.format = OutputFormat::F32; + let mut package = Package::new("Output precision"); + package.graphs.extend([parent, child]); + let cache = Mutex::new(Cache::default()); + for caller in [OutputFormat::U8, OutputFormat::F32] { + package.graphs[0].node_mut(instance).unwrap().base.format = caller; + for child in OutputFormat::ALL { + let expected = if child == OutputFormat::Inherit { caller } else { child }; + package.graphs[1].format = expected; + let direct = cook(&package, 1, &Options::new(&no_res), &cache); + package.graphs[1].format = child; + let nested = cook(&package, 0, &Options::new(&no_res), &cache); + assert_eq!(nested.nodes[&instance].error, None); + assert_eq!(nested.nodes[&instance].output_base(0).unwrap().format, expected); + assert_eq!(nested.image(instance, 0).unwrap().data(), direct.image(output, 0).unwrap().data(), "child {child:?} inside {caller:?}"); + } + } +} + +#[test] +fn nested_blurs_filter_the_original_caller_texture() { + use materialcraft_core::OutputFormat; + for filter in ["directional_blur", "blur"] { + let (mut parent, instance) = instancing("Parent", "Filtered"); + let source = parent.add_node("input_grayscale", [0.0; 2]); + parent.node_mut(source).unwrap().base.format = OutputFormat::F32; + parent.connect(source, "output", instance, "input").unwrap(); + + let mut child = Graph::new("Filtered"); + child.size = parent.size; + let bridge = child.add_node("input_grayscale", [0.0; 2]); + child.node_mut(bridge).unwrap().base.format = OutputFormat::U16; + let add_filter = |graph: &mut Graph, input| { + let id = graph.add_node(filter, [0.0; 2]); + let node = graph.node_mut(id).unwrap(); + node.base.format = OutputFormat::U16; + node.params.insert("intensity".into(), Value::Float(16.0)); + graph.connect(input, "output", id, "input").unwrap(); + id + }; + let direct = add_filter(&mut parent, source); + let nested = add_filter(&mut child, bridge); + let output = child.add_node("output", [0.0; 2]); + child.connect(nested, "output", output, "input").unwrap(); + let mut package = Package::new("Caller precision"); + package.graphs.extend([parent, child]); + let mut options = Options::new(&no_res); + options.inputs.insert("input".into(), Image::gray(16, 16, |x, y| ((97 * x + 31 * y + 13 * x * y) % 251) as f32 / 251.0)); + let cooked = cook(&package, 0, &options, &Mutex::new(Cache::default())); + assert_eq!(cooked.nodes[&instance].error, None); + let result = cooked.image(instance, 0).unwrap(); + let expected = cooked.image(direct, 0).unwrap(); + assert!(result.data().iter().zip(expected.data()).all(|(a, b)| a.to_bits() == b.to_bits()), "{filter}"); + } +} + +#[test] +fn relative_graph_size_offsets_resolve_before_the_children_at_each_instance() { + let (mut parent, instance) = instancing("Parent", "Field"); + parent.size = [5, 4]; + let mut child = Graph::new("Field"); + let fill = child.add_node("uniform", [0.0; 2]); + let output = child.add_node("output", [1.0, 0.0]); + child.connect(fill, "output", output, "input").unwrap(); + let mut pkg = Package::new("Graph dimensions"); + pkg.graphs.extend([parent, child]); + let cache = Mutex::new(Cache::default()); + use materialcraft_core::GraphSizeOffset::{Input, Parent}; + for (offset, node_offset, expected) in + [(Parent([-1, 1]), [0, 0], [16, 32]), (Input([1, -1]), [0, 0], [64, 8]), (Parent([-7, 0]), [3, 0], [2, 16]), (Input([0, 0]), [0, 0], [32, 16])] + { + pkg.graphs[1].relative_output_size = Some(offset); + pkg.graphs[1].node_mut(fill).unwrap().base.size = node_offset; + let result = cook(&pkg, 0, &Options::new(&no_res), &cache); + assert_eq!(result.nodes[&instance].error, None); + let image = result.image(instance, 0).unwrap(); + assert_eq!([image.width(), image.height()], expected); + } +} + +#[test] +fn computed_graph_output_sizes_read_instance_arguments_and_parent_axes() { + use materialcraft_core::{ExposedParameter, FunctionGraph, GraphSizeOffset, ValueType}; + let (mut package, instance, _) = instanced_seed_field(); + package.graphs[0].size = [5, 4]; + let child = &mut package.graphs[1]; + let input = ExposedParameter { + id: "axes".into(), + label: "Axes".into(), + default: Value::Int2([-1, 1]), + connectable: false, + min: -20.0, + max: 20.0, + clamp: false, + step: None, + editor: None, + description: String::new(), + group: String::new(), + options: Vec::new(), + }; + child.exposed.push(input); + child.output_size_function = Some(FunctionGraph::input("axes", ValueType::Integer2)); + let options = Options::new(&no_res); + let cache = Mutex::new(Cache::default()); + for (absolute, mode, axes, expected) in [ + (None, Some(GraphSizeOffset::Parent([0, 0])), [-1, 1], [16, 32]), + (None, Some(GraphSizeOffset::Input([0, 0])), [1, -1], [64, 8]), + (Some([0, 0]), None, [3, 4], [8, 16]), + ] { + package.graphs[1].absolute_output_size = absolute; + package.graphs[1].relative_output_size = mode; + package.graphs[0].node_mut(instance).unwrap().params.insert("axes".into(), Value::Int2(axes)); + let result = cook(&package, 0, &options, &cache); + assert_eq!(result.nodes[&instance].error, None); + let image = result.image(instance, 0).unwrap(); + assert_eq!([image.width(), image.height()], expected); + } +} + +#[test] +fn computed_graph_output_sizes_test_both_axes_before_applying_their_offsets() { + use materialcraft_core::{FunctionGraph, GraphSizeOffset, ValueType}; + let (mut package, instance, _) = instanced_seed_field(); + package.graphs[0].size = [5, 4]; + let options = Options::new(&no_res); + let cache = Mutex::new(Cache::default()); + for (name, axis, threshold, absolute, expected) in [ + ("$size", 0, 16.0, false, [64, 8]), + ("$size", 1, 16.0, false, [16, 32]), + ("$sizelog2", 0, 4.0, false, [64, 8]), + ("$sizelog2", 1, 4.0, false, [16, 32]), + ("$size", 0, 0.0, true, [8, 16]), + ("$size", 0, -0.5, true, [16, 8]), + ("$sizelog2", 1, 0.0, true, [8, 16]), + ("$sizelog2", 1, -0.5, true, [16, 8]), + ] { + let mut function = FunctionGraph::input(name, ValueType::Float2); + let channel = function.add("swizzle1", &[function.output.unwrap()], Some(Value::Int(axis))); + let limit = function.add_constant(Value::Float(threshold)); + let pass = function.add("gt", &[channel, limit], None); + let high = function.add_constant(Value::Int2(if absolute { [4, 3] } else { [1, -1] })); + let low = function.add_constant(Value::Int2(if absolute { [3, 4] } else { [-1, 1] })); + function.output = Some(function.add("ifelse", &[pass, high, low], None)); + let child = &mut package.graphs[1]; + child.absolute_output_size = absolute.then_some([0; 2]); + child.relative_output_size = (!absolute).then_some(GraphSizeOffset::Parent([0; 2])); + child.output_size_function = Some(function); + let result = cook(&package, 0, &options, &cache); + assert_eq!(result.nodes[&instance].error, None); + let image = result.image(instance, 0).unwrap(); + assert_eq!([image.width(), image.height()], expected); + } + package.graphs[1].output_size_function = Some(FunctionGraph::constant(Value::Bool(true))); + let invalid = cook(&package, 0, &options, &cache); + assert!(invalid.nodes[&instance].error.as_deref().unwrap().contains("graph output size")); +} + +#[test] +fn graph_seed_functions_use_the_allocated_size_below_one_texel() { + use materialcraft_core::{FunctionGraph, GraphSizeOffset, ParameterInheritance, ValueType}; + let (mut package, instance, _) = instanced_seed_field(); + package.graphs[0].size = [4, 4]; + package.graphs[1].relative_output_size = Some(GraphSizeOffset::Parent([-6, 0])); + package.graphs[1].seed_mode = ParameterInheritance::Absolute; + let mut literal = package.clone(); + let options = Options::new(&no_res); + let cache = Mutex::new(Cache::default()); + for (name, limit, expected) in [("$size", 0.5, 5), ("$size", 1.0, 0), ("$sizelog2", -0.5, 5), ("$sizelog2", 0.0, 0)] { + let mut function = FunctionGraph::input(name, ValueType::Float2); + let axis = function.add("swizzle1", &[function.output.unwrap()], Some(Value::Int(0))); + let threshold = function.add_constant(Value::Float(limit)); + let pass = function.add("gt", &[axis, threshold], None); + let yes = function.add_constant(Value::Int(5)); + let no = function.add_constant(Value::Int(0)); + function.output = Some(function.add("ifelse", &[pass, yes, no], None)); + package.graphs[1].seed_function = Some(function); + literal.graphs[1].seed = expected; + let result = cook(&package, 0, &options, &cache); + let control = cook(&literal, 0, &options, &cache); + let image = result.image(instance, 0).unwrap(); + assert_eq!([image.width(), image.height()], [1, 16]); + assert_eq!(image.data(), control.image(instance, 0).unwrap().data()); + } +} diff --git a/crates/eval/src/tests/font_resource.rs b/crates/eval/src/tests/font_resource.rs new file mode 100644 index 00000000..b8002235 --- /dev/null +++ b/crates/eval/src/tests/font_resource.rs @@ -0,0 +1,267 @@ +use super::*; +use materialcraft_core::{OutputFormat, Resource, ResourceBytes}; + +fn rectangle_font(height: i16, metrics: [i16; 3]) -> Vec { + outline_font(metrics, 640, &[(0, 0, true), (0, height, true), (512, height, true), (512, 0, true)]) +} + +/// A two-glyph TrueType face with one contour for A. A false flag denotes a quadratic control point. +fn outline_font(metrics: [i16; 3], advance: i16, contour: &[(i16, i16, bool)]) -> Vec { + fn words(values: &[i16]) -> Vec { + values.iter().flat_map(|value| value.to_be_bytes()).collect() + } + fn checksum(data: &[u8]) -> u32 { + data.chunks(4).fold(0u32, |sum, chunk| { + let mut word = [0; 4]; + word[..chunk.len()].copy_from_slice(chunk); + sum.wrapping_add(u32::from_be_bytes(word)) + }) + } + + let mut head = vec![0; 54]; + head[..4].copy_from_slice(&0x10000u32.to_be_bytes()); + head[12..16].copy_from_slice(&0x5f0f3cf5u32.to_be_bytes()); + head[18..20].copy_from_slice(&1024i16.to_be_bytes()); + let bounds = [ + contour.iter().map(|p| p.0).min().unwrap(), + contour.iter().map(|p| p.1).min().unwrap(), + contour.iter().map(|p| p.0).max().unwrap(), + contour.iter().map(|p| p.1).max().unwrap(), + ]; + head[36..44].copy_from_slice(&words(&bounds)); + let mut hhea = vec![0; 36]; + hhea[..4].copy_from_slice(&0x10000u32.to_be_bytes()); + hhea[4..12].copy_from_slice(&words(&[metrics[0], metrics[1], metrics[2], advance])); + hhea[34..].copy_from_slice(&2i16.to_be_bytes()); + let mut maxp = vec![0; 32]; + maxp[..4].copy_from_slice(&0x10000u32.to_be_bytes()); + let count = i16::try_from(contour.len()).unwrap(); + maxp[4..10].copy_from_slice(&words(&[2, count, 1])); + let mut cmap = words(&[0, 1, 3, 1, 0, 12]); + cmap.extend(words(&[4, 32, 0, 4, 4, 1, 0, 65, -1, 0, 65, -1, -64, 1, 0, 0])); + let mut glyf = words(&[1, bounds[0], bounds[1], bounds[2], bounds[3], count - 1, 0]); + glyf.extend(contour.iter().map(|p| u8::from(p.2))); + for axis in 0..2 { + let mut previous = 0; + for &(x, y, _) in contour { + let coordinate = [x, y][axis]; + glyf.extend((coordinate - previous).to_be_bytes()); + previous = coordinate; + } + } + glyf.resize(glyf.len().next_multiple_of(2), 0); + let loca = words(&[0, 0, (glyf.len() / 2) as i16]); + let tables = + [(b"cmap", cmap), (b"glyf", glyf), (b"head", head), (b"hhea", hhea), (b"hmtx", words(&[advance, 0, advance, 0])), (b"loca", loca), (b"maxp", maxp)]; + let mut font = words(&[1, 0, 7, 64, 2, 48]); + font.resize(12 + 16 * tables.len(), 0); + let mut head_start = 0; + for (index, (tag, data)) in tables.into_iter().enumerate() { + let offset = font.len(); + if tag == b"head" { + head_start = offset; + } + let entry = &mut font[12 + 16 * index..12 + 16 * (index + 1)]; + entry[..4].copy_from_slice(tag); + entry[4..8].copy_from_slice(&checksum(&data).to_be_bytes()); + entry[8..12].copy_from_slice(&(offset as u32).to_be_bytes()); + entry[12..].copy_from_slice(&(data.len() as u32).to_be_bytes()); + font.extend(data); + font.resize(font.len().next_multiple_of(4), 0); + } + let adjustment = 0xb1b0_afba_u32.wrapping_sub(checksum(&font)); + font[head_start + 8..head_start + 12].copy_from_slice(&adjustment.to_be_bytes()); + font +} + +#[test] +fn package_font_outlines_render_and_invalidate_the_parent_instance() { + let (mut parent, instance) = instancing("Preview", "Letter"); + parent.size = [6, 5]; + parent.format = OutputFormat::F32; + let mut child = Graph::new("Letter"); + child.size = [6, 5]; + let text = child.add_node("text", [0.0; 2]); + child.node_mut(text).unwrap().params.extend([ + ("text".into(), Value::Text("A".into())), + ("fontdata".into(), Value::Text("Ink".into())), + ("fontsize".into(), Value::Float(0.5)), + ]); + let output = child.add_node("output", [100.0, 0.0]); + child.connect(text, "output", output, "input").unwrap(); + let mut package = Package::new("Original lettering"); + package.graphs = vec![parent, child]; + package.resources.push(Resource::new("Ink", "Ink.ttf", ResourceBytes::new(rectangle_font(512, [768, -256, 0])))); + let cache = Mutex::new(Cache::default()); + let options = Options::new(&no_res); + for (height, first_row) in [(512, 8), (256, 12), (1024, 4)] { + package.resources[0].bytes = ResourceBytes::new(rectangle_font(height, [768, -256, 0])); + let direct = cook(&package, 1, &options, &cache); + assert!(direct.nodes[&text].error.is_none(), "{:?}", direct.nodes[&text].error); + let nested = cook(&package, 0, &options, &cache); + assert!(!nested.nodes[&instance].cached); + let image = nested.image(instance, 0).unwrap(); + assert_eq!((image.width(), image.height()), (64, 32)); + for y in 0..32 { + for x in 0..64 { + let ink = (24..40).contains(&x) && (first_row..16).contains(&y); + assert_eq!(image.get_gray(x, y, false), f32::from(ink), "({x}, {y}) at cap height {height}"); + } + } + assert!(cook(&package, 0, &options, &cache).nodes[&instance].cached); + } +} + +fn text_sample(size: [u32; 2], metrics: [i16; 3], params: &[(&str, Value)]) -> (Package, NodeId) { + let mut graph = Graph::new("Print"); + graph.size = size; + graph.format = OutputFormat::F32; + let id = graph.add_node("text", [0.0; 2]); + let node = graph.node_mut(id).unwrap(); + node.params.insert("fontdata".into(), Value::Text("Ink".into())); + node.params.extend(params.iter().map(|(name, value)| (name.to_string(), value.clone()))); + let mut package = Package::new("Original type"); + package.resources.push(Resource::new("Ink", "Ink.ttf", ResourceBytes::new(rectangle_font(512, metrics)))); + package.graphs.push(graph); + (package, id) +} + +#[test] +fn package_font_uses_horizontal_height_and_line_gap() { + let (package, id) = text_sample([6, 6], [1536, -512, 512], &[("text", Value::Text("A\nA".into())), ("fontsize", Value::Float(0.25))]); + let cooked = cook(&package, 0, &Options::new(&no_res), &Mutex::new(Cache::default())); + assert_eq!(cooked.nodes[&id].error, None); + let image = cooked.image(id, 0).unwrap(); + for y in 0..64 { + for x in 0..64 { + let ink = (30..34).contains(&x) && ((28..32).contains(&y) || (48..52).contains(&y)); + assert_eq!(image.get_gray(x, y, false), f32::from(ink), "({x}, {y})"); + } + } +} + +#[test] +fn package_font_clips_overhang_at_the_outside_of_the_text_block() { + let (mut package, id) = text_sample( + [6, 6], + [768, -256, 0], + &[("text", Value::Text("A\nA".into())), ("fontsize", Value::Float(0.25)), ("position", Value::Float2([0.0, -0.25]))], + ); + package.resources[0].bytes = ResourceBytes::new(rectangle_font(1024, [768, -256, 0])); + let cooked = cook(&package, 0, &Options::new(&no_res), &Mutex::new(Cache::default())); + assert_eq!(cooked.nodes[&id].error, None); + let image = cooked.image(id, 0).unwrap(); + for y in 0..64 { + for x in 0..64 { + let ink = (28..36).contains(&x) && (4..32).contains(&y); + assert_eq!(image.get_gray(x, y, false), f32::from(ink), "({x}, {y})"); + } + } +} + +#[test] +fn package_font_quadratic_detail_tracks_the_text_scale() { + let metrics = [768, -256, 0]; + let (mut package, id) = text_sample([5, 5], metrics, &[("text", Value::Text("A".into())), ("position", Value::Float2([-0.0625, 1.0 / 256.0]))]); + let curve = [(0, 0, true), (512, 1024, false), (1024, 0, true)]; + let options = Options::new(&no_res); + let cache = Mutex::new(Cache::default()); + for (size, segments) in [(0.35, 4), (0.35001, 8)] { + package.graphs[0].node_mut(id).unwrap().params.insert("fontsize".into(), Value::Float(size)); + let chords: Vec<_> = (0..=segments).map(|i| ((1024 * i / segments) as i16, (2048 * i * (segments - i) / (segments * segments)) as i16, true)).collect(); + let mut render = |contour: &[(i16, i16, bool)]| { + package.resources[0].bytes = ResourceBytes::new(outline_font(metrics, 640, contour)); + let result = cook(&package, 0, &options, &cache); + assert_eq!(result.nodes[&id].error, None); + result.image(id, 0).unwrap().clone() + }; + let expected = render(&chords); + assert!(expected.data().contains(&1.0)); + let ink = render(&curve); + for (pixel, (a, b)) in ink.data().iter().zip(expected.data()).enumerate() { + assert_eq!(a, b, "pixel {pixel} at size {size}"); + } + } +} + +#[test] +fn adjacent_quadratic_controls_place_their_join_in_whole_design_units() { + let metrics = [768, -256, 0]; + let (mut package, id) = text_sample( + [7, 6], + metrics, + &[ + ("text", Value::Text("A".into())), + ("fontsize", Value::Float(0.5)), + ("alignment", Value::Enum(0)), + ("position", Value::Float2([-0.1875, 1.0 / 256.0])), + ], + ); + let implicit = [(0, 0, true), (55, -385, false), (492, 126, false), (675, 612, false), (1010, 0, true)]; + let explicit = [implicit[0], implicit[1], (273, -130, true), implicit[2], (583, 369, true), implicit[3], implicit[4]]; + let cache = Mutex::new(Cache::default()); + let mut render = |contour: &[(i16, i16, bool)]| { + package.resources[0].bytes = ResourceBytes::new(outline_font(metrics, 640, contour)); + let result = cook(&package, 0, &Options::new(&no_res), &cache); + assert_eq!(result.nodes[&id].error, None); + result.image(id, 0).unwrap().clone() + }; + let expected = render(&explicit); + assert!(expected.data().contains(&1.0)); + let actual = render(&implicit); + for (pixel, (a, b)) in actual.data().iter().zip(expected.data()).enumerate() { + assert_eq!(a, b, "pixel {pixel} at the implicit join"); + } +} + +#[test] +fn overlapping_glyphs_round_each_coverage_composition() { + let metrics = [768, -256, 0]; + let (mut package, id) = text_sample([5, 5], metrics, &[("fontsize", Value::Float(0.5)), ("alignment", Value::Enum(0))]); + let cache = Mutex::new(Cache::default()); + for (width, expected) in [(11, [44u8, 80, 110, 135]), (32, [128, 192, 224, 240])] { + let contour = [(0, 0, true), (0, 512, true), (width, 512, true), (width, 0, true)]; + package.resources[0].bytes = ResourceBytes::new(outline_font(metrics, 0, &contour)); + for (count, code) in (1..=4).zip(expected) { + package.graphs[0].node_mut(id).unwrap().params.insert("text".into(), Value::Text("A".repeat(count))); + let cooked = cook(&package, 0, &Options::new(&no_res), &cache); + assert_eq!(cooked.nodes[&id].error, None); + let ink = cooked.image(id, 0).unwrap(); + for y in 0..32 { + for x in 0..32 { + let coverage = if x == 16 && (8..16).contains(&y) { code } else { 0 }; + assert_eq!(ink.get_gray(x, y, false), f32::from(coverage) / 255.0, "width {width}, {count} glyphs at ({x},{y})"); + } + } + } + } +} + +#[test] +fn package_font_coverage_interpolates_the_background_channels() { + let (mut package, id) = text_sample( + [5, 4], + [768, -256, 0], + &[ + ("text", Value::Text("A".into())), + ("fontsize", Value::Float(0.5)), + ("position", Value::Float2([1.0 / 128.0, 0.0])), + ("background", Value::Color([1.0, 0.0, 0.0, 0.25])), + ], + ); + let cache = Mutex::new(Cache::default()); + for color in [false, true] { + package.graphs[0].node_mut(id).unwrap().params.insert("color_mode".into(), Value::Bool(color)); + let cooked = cook(&package, 0, &Options::new(&no_res), &cache); + assert_eq!(cooked.nodes[&id].error, None); + let image = cooked.image(id, 0).unwrap(); + for (x, code) in [(0, 0), (12, 191), (18, 255), (20, 64)] { + let alpha = f32::from(code as u8) / 255.0; + if color { + assert_eq!(image.get(x, 6, false), [1.0, alpha, alpha, (1.0 - alpha).mul_add(0.25, alpha)]); + } else { + assert_eq!(image.get_gray(x, 6, false), (1.0 - alpha).mul_add(1.0 / 3.0, alpha)); + } + } + } +} diff --git a/crates/eval/src/value_execution.rs b/crates/eval/src/value_execution.rs index 9813f855..f9a1f758 100644 --- a/crates/eval/src/value_execution.rs +++ b/crates/eval/src/value_execution.rs @@ -1,23 +1,44 @@ use craft_texture::Image; -use materialcraft_core::Value; +use materialcraft_core::{OutputFormat, Value}; use std::collections::BTreeMap; pub(crate) fn evaluate_value( parameters: &BTreeMap, - variables: &BTreeMap, + variables: &dyn materialcraft_nodes::GraphVariables, seed: u32, size: [u32; 2], images: &[Option], + image_formats: &[OutputFormat], tile: bool, ) -> Result { - use materialcraft_nodes::function::{EvaluationContext, EvaluationState, compile}; + use materialcraft_nodes::function::{EvaluationContext, EvaluationState, FunctionScope, compile_with_literal_inputs}; let Some(Value::Function(graph)) = parameters.get("function") else { return Err("missing value function".into()); }; - let program = compile(graph, seed)?; - let context = EvaluationContext { scope: Default::default(), position: [0.5; 2], size: size.map(|side| side as f32), images, tile, variables }; + let program = compile_with_literal_inputs(graph, seed, variables.literal_inputs())?; + let context = EvaluationContext { + image_formats, + scope: FunctionScope::ValueProcessor, + position: [0.0; 2], + size: size.map(|side| side as f32), + images, + tile, + variables: variables.graph_values(), + }; - program.evaluate(&context, &mut EvaluationState::default()) + let value = program.evaluate(&context, &mut EvaluationState::default())?; + Ok(match value { + Value::Int(v) => Value::Int(stored_integer(v)), + Value::Int2(v) => Value::Int2(v.map(stored_integer)), + Value::Int3(v) => Value::Int3(v.map(stored_integer)), + Value::Int4(v) => Value::Int4(v.map(stored_integer)), + other => other, + }) +} + +fn stored_integer(value: i32) -> i32 { + // The value port rounds to binary32 first. The positive endpoint can round up to 2^31. + i32::try_from(value as f32 as i64).unwrap_or(i32::MIN) } diff --git a/crates/eval/tests/filter_tiling.rs b/crates/eval/tests/filter_tiling.rs index 4e76a422..d6a784a7 100644 --- a/crates/eval/tests/filter_tiling.rs +++ b/crates/eval/tests/filter_tiling.rs @@ -3,9 +3,72 @@ use materialcraft_core::{Graph, OutputFormat, Package, ParameterInheritance, Val use materialcraft_eval::{Cache, Options, cook}; use std::sync::Mutex; +#[test] +fn rectangular_directional_blur_uses_the_resolved_pixel_ratio() { + let mut graph = Graph::new("Directional filter"); + graph.format = OutputFormat::F32; + let input = graph.add_node("input_grayscale", [0.0; 2]); + graph.node_mut(input).unwrap().params.insert("identifier".into(), Value::Text("stripe".into())); + let blur = graph.add_node("directional_blur", [100.0, 0.0]); + graph.node_mut(blur).unwrap().params.insert("intensity".into(), Value::Float(2.4)); + graph.connect(input, "output", blur, "input").unwrap(); + let mut package = Package::new("Pixel ratio"); + package.graphs.push(graph); + let resource = |_: &str| None; + let mut options = Options::new(&resource); + let cache = Mutex::new(Cache::default()); + + for (size, angle) in [([5, 6], 0.25), ([6, 5], 0.0)] { + let (w, h) = (1 << size[0], 1 << size[1]); + package.graphs[0].size = size; + let vertical = h > w; + let stripe = Image::gray(w, h, |x, y| f32::from(if vertical { y == h / 2 } else { x == w / 2 })); + options.inputs.insert("stripe".into(), stripe); + package.graphs[0].node_mut(blur).unwrap().params.insert("angle".into(), Value::Float(angle)); + for (graph_ratio, node_ratio, expected) in [(None, None, 1), (Some(0), None, 0), (Some(0), Some(1), 1), (Some(1), Some(0), 0)] { + let graph = &mut package.graphs[0]; + graph.pixel_ratio = graph_ratio.unwrap_or_default(); + graph.pixel_ratio_mode = if graph_ratio.is_some() { ParameterInheritance::Absolute } else { ParameterInheritance::RelativeToParent }; + let base = &mut graph.node_mut(blur).unwrap().base; + base.pixel_ratio = node_ratio.unwrap_or_default(); + base.pixel_ratio_mode = if node_ratio.is_some() { ParameterInheritance::Absolute } else { ParameterInheritance::RelativeToInput }; + let cooked = cook(&package, 0, &options, &cache); + assert_eq!(cooked.nodes[&blur].base.pixel_ratio, expected); + let image = cooked.image(blur, 0).unwrap(); + let (x, y) = (i64::from(w / 2), i64::from(h / 2)); + let center = image.get_gray(x, y, false).to_bits(); + let neighbor = image.get_gray(x + i64::from(!vertical), y + i64::from(vertical), false).to_bits(); + let samples = if expected == 1 { + [1.0f32.to_bits(), 0] + } else if vertical { + [0x3f55_5555, 0x3daa_aaac] + } else { + [0x3f55_5555, 0x3daa_aaad] + }; + assert_eq!([center, neighbor], samples, "{size:?} {graph_ratio:?} {node_ratio:?}"); + } + } + + // The vertical extent is zero here. The transverse projection still reaches the adjacent column. + package.graphs[0].node_mut(blur).unwrap().params.insert("angle".into(), Value::Float(0.25)); + let cooked = cook(&package, 0, &options, &cache); + assert_eq!(cooked.image(blur, 0).unwrap().get_gray(33, 16, false).to_bits(), 0x3216_30f4); + + for (size, strength, expected) in [([5, 6], 4.8, 0x3f52_d2b2), ([6, 5], 9.6, 0x3f0b_996e)] { + package.graphs[0].size = size; + let params = &mut package.graphs[0].node_mut(blur).unwrap().params; + params.insert("angle".into(), Value::Float(0.0625)); + params.insert("intensity".into(), Value::Float(strength)); + let field = Image::gray(1 << size[0], 1 << size[1], |x, y| ((47 * x + 73 * y + 13 * x * y + 79) % 509) as f32 / 508.0); + options.inputs.insert("stripe".into(), field); + let cooked = cook(&package, 0, &options, &cache); + assert_eq!(cooked.image(blur, 0).unwrap().get_gray(7, 13, false).to_bits(), expected); + } +} + #[test] fn atomic_filters_wrap_only_the_requested_axes_and_invalidate_cache() { - for operation in ["blur", "directional_blur", "sharpen"] { + for operation in ["blur", "directional_blur", "sharpen", "distance"] { let mut graph = Graph::new("Filter boundaries"); graph.size = [4; 2]; graph.format = OutputFormat::F32; @@ -13,13 +76,19 @@ fn atomic_filters_wrap_only_the_requested_axes_and_invalidate_cache() { let input = graph.add_node("input_grayscale", [0.0; 2]); graph.node_mut(input).unwrap().params.insert("identifier".into(), Value::Text("source".into())); let filter = graph.add_node(operation, [100.0, 0.0]); - graph.node_mut(filter).unwrap().params.insert("intensity".into(), Value::Float(if operation == "sharpen" { 1.0 } else { 16.0 })); - graph.connect(input, "output", filter, "input").unwrap(); + let (parameter, port, center, background) = if operation == "distance" { ("distance", "mask", 1.0, 0.0) } else { ("intensity", "input", 0.5625, 0.5) }; + let strength = match operation { + "distance" => 48.0, + "sharpen" => 1.0, + _ => 16.0, + }; + graph.node_mut(filter).unwrap().params.insert(parameter.into(), Value::Float(strength)); + graph.connect(input, "output", filter, port).unwrap(); let mut package = Package::new("Filter boundaries"); package.graphs.push(graph); let resource = |_: &str| None; let mut options = Options::new(&resource); - options.inputs.insert("source".into(), Image::gray(16, 16, |x, y| if x == 0 && y == 0 { 0.5625 } else { 0.5 })); + options.inputs.insert("source".into(), Image::gray(16, 16, |x, y| if x == 0 && y == 0 { center } else { background })); let cache = Mutex::new(Cache::default()); for tiling in [[false, false], [true, false], [false, true], [true, true]] { @@ -30,8 +99,8 @@ fn atomic_filters_wrap_only_the_requested_axes_and_invalidate_cache() { assert_eq!(cooked.nodes[&filter].error, None); assert!(!cooked.nodes[&filter].cached); - assert_eq!(image.get_gray(15, 0, false) != 0.5, tiling[0], "{operation}, x, {tiling:?}"); - assert_eq!(image.get_gray(0, 15, false) != 0.5, tiling[1] && operation != "directional_blur", "{operation}, y, {tiling:?}"); + assert_eq!(image.get_gray(15, 0, false) != background, tiling[0], "{operation}, x, {tiling:?}"); + assert_eq!(image.get_gray(0, 15, false) != background, tiling[1] && operation != "directional_blur", "{operation}, y, {tiling:?}"); let cached = cook(&package, 0, &options, &cache); @@ -39,3 +108,37 @@ fn atomic_filters_wrap_only_the_requested_axes_and_invalidate_cache() { } } } + +#[test] +fn directional_warp_uses_each_graph_tiling_axis() { + let mut graph = Graph::new("Warp boundaries"); + graph.size = [4; 2]; + graph.format = OutputFormat::F32; + graph.tiling_mode = ParameterInheritance::Absolute; + let input = graph.add_node("input_grayscale", [0.0; 2]); + graph.node_mut(input).unwrap().params.insert("identifier".into(), Value::Text("field".into())); + let mask = graph.add_node("input_grayscale", [0.0, 50.0]); + graph.node_mut(mask).unwrap().params.insert("identifier".into(), Value::Text("mask".into())); + let warp = graph.add_node("directional_warp", [100.0, 0.0]); + graph.node_mut(warp).unwrap().params.insert("intensity".into(), Value::Float(16.0)); + graph.connect(input, "output", warp, "input").unwrap(); + graph.connect(mask, "output", warp, "intensity_input").unwrap(); + let mut package = Package::new("Warp boundaries"); + package.graphs.push(graph); + let resource = |_: &str| None; + let mut options = Options::new(&resource); + options.inputs.insert("field".into(), Image::gray(16, 16, |x, y| f32::from(x == 0 && y == 0))); + options.inputs.insert("mask".into(), Image::gray(16, 16, |_, _| 1.0)); + let cache = Mutex::new(Cache::default()); + + for tiling in [[false, false], [true, false], [false, true], [true, true]] { + package.graphs[0].tiling = tiling; + for (axis, angle, x, y) in [(0, 0.0, 15, 0), (1, 0.25, 0, 15)] { + package.graphs[0].node_mut(warp).unwrap().params.insert("angle".into(), Value::Float(angle)); + let cooked = cook(&package, 0, &options, &cache); + assert_eq!(cooked.nodes[&warp].error, None); + let image = cooked.image(warp, 0).unwrap(); + assert_eq!(image.get_gray(x, y, false), f32::from(tiling[axis]), "tiling {tiling:?}, angle {angle}"); + } + } +} diff --git a/crates/eval/tests/instance_image_properties.rs b/crates/eval/tests/instance_image_properties.rs new file mode 100644 index 00000000..01c76349 --- /dev/null +++ b/crates/eval/tests/instance_image_properties.rs @@ -0,0 +1,98 @@ +use materialcraft_core::{FunctionGraph, Graph, OutputFormat, Package, ParameterInheritance, Value}; +use materialcraft_eval::{Cache, Options, cook}; +use std::sync::Mutex; + +#[test] +fn cached_instances_follow_caps_on_absolute_child_outputs() { + let mut parent = Graph::new("Caller"); + parent.size = [2; 2]; + let mut child = Graph::new("Large output"); + let source = child.add_node("uniform", [0.0; 2]); + let source_node = child.node_mut(source).unwrap(); + source_node.base.size_mode = materialcraft_core::SizeMode::Absolute; + source_node.base.size = [5; 2]; + let output = child.add_node("output", [0.0; 2]); + child.node_mut(output).unwrap().params.insert("identifier".into(), Value::Text("image".into())); + child.connect(source, "output", output, "input").unwrap(); + let instance = parent.add_node("graph_instance", [0.0; 2]); + parent.node_mut(instance).unwrap().params.insert("graph".into(), Value::Text(child.name.clone())); + let mut package = Package::new("Capped instance"); + package.graphs.extend([parent, child]); + + for caps in [[16, 8], [8, 16]] { + let cache = Mutex::new(Cache::default()); + for cap in caps { + let mut options = Options::new(&|_| None); + options.max_size = Some(cap); + let cold = cook(&package, 0, &options, &Mutex::new(Cache::default())); + let expected = cold.image(instance, 0).unwrap(); + assert_eq!((expected.width(), expected.height()), (cap, cap)); + for cached in [false, true] { + let result = cook(&package, 0, &options, &cache); + assert_eq!(result.nodes[&instance].cached, cached); + let actual = result.image(instance, 0).unwrap(); + assert_eq!((actual.width(), actual.height()), (expected.width(), expected.height())); + assert_eq!(actual.data(), expected.data()); + } + } + } +} + +#[test] +fn each_instance_image_pin_preserves_its_own_sampling_properties() { + let mut parent = Graph::new("Caller"); + let mut child = Graph::new("Two fields"); + for graph in [&mut parent, &mut child] { + 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("Two fields".into())); + let mut filters = Vec::new(); + for (name, size, tiling, ratio) in [("first", [2.0, 0.5], [false, true], 0), ("second", [0.5, 2.0], [true, false], 1)] { + let mut noise = FunctionGraph::default(); + let unit = noise.add_constant(Value::Float(1.0)); + noise.output = Some(noise.add("rand", &[unit], None)); + let source = parent.add_node("pixel_processor", [0.0; 2]); + let field = parent.node_mut(source).unwrap(); + field.params.insert("function".into(), Value::Function(Box::new(noise))); + field.params.insert("color_mode".into(), Value::Bool(false)); + field.base.pixel_size_mode = ParameterInheritance::Absolute; + field.base.pixel_size = size; + field.base.tiling_mode = ParameterInheritance::Absolute; + field.base.tiling = tiling; + field.base.pixel_ratio_mode = ParameterInheritance::Absolute; + field.base.pixel_ratio = ratio; + parent.connect(source, "output", instance, name).unwrap(); + + let input = child.add_node("input_grayscale", [0.0; 2]); + child.node_mut(input).unwrap().params.insert("identifier".into(), Value::Text(name.into())); + let inside = child.add_node("blur", [0.0; 2]); + child.node_mut(inside).unwrap().params.insert("intensity".into(), Value::Float(12.0)); + child.connect(input, "output", inside, "input").unwrap(); + let output = child.add_node("output", [0.0; 2]); + child.node_mut(output).unwrap().params.insert("identifier".into(), Value::Text(name.into())); + child.connect(inside, "output", output, "input").unwrap(); + + let flat = parent.add_node("blur", [0.0; 2]); + parent.node_mut(flat).unwrap().params.insert("intensity".into(), Value::Float(12.0)); + parent.connect(source, "output", flat, "input").unwrap(); + let receiver = parent.add_node("blur", [0.0; 2]); + parent.node_mut(receiver).unwrap().params.insert("intensity".into(), Value::Float(0.0)); + parent.connect(instance, name, receiver, "input").unwrap(); + filters.push((receiver, flat, size, tiling, ratio)); + } + let mut package = Package::new("Image pin properties"); + 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 &(receiver, flat, size, tiling, ratio) in &filters { + let base = cooked.nodes[&receiver].base; + assert_eq!((base.pixel_size, base.tiling, base.pixel_ratio), (size, tiling, ratio)); + assert_eq!(cooked.image(receiver, 0).unwrap().data(), cooked.image(flat, 0).unwrap().data()); + } + } +} 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/crates/eval/tests/pattern_opacity.rs b/crates/eval/tests/pattern_opacity.rs new file mode 100644 index 00000000..68589442 --- /dev/null +++ b/crates/eval/tests/pattern_opacity.rs @@ -0,0 +1,285 @@ +use materialcraft_core::{FunctionGraph, Graph, OutputFormat, Package, PatternGraph, PatternNodeKind, Value, ValueType}; +use materialcraft_eval::{Cache, Options, cook}; +use std::sync::Mutex; + +#[test] +fn pattern_seeds_distinguish_published_integers_from_assignments() { + let mut graph = Graph::new("Integer seed storage"); + graph.size = [4; 2]; + graph.format = OutputFormat::F32; + let stamp = graph.add_node("fx_map", [0.0; 2]); + let node = graph.node_mut(stamp).unwrap(); + node.params.insert("color_mode".into(), Value::Bool(false)); + node.params.insert("roughness".into(), Value::Float(0.0)); + node.params.insert("background".into(), Value::Color([0.0, 0.0, 0.0, 1.0])); + let mut pattern = PatternGraph::with_root(PatternNodeKind::Iterate); + let inner = pattern.add(PatternNodeKind::Iterate).unwrap(); + let leaf = pattern.add(PatternNodeKind::Quadrant).unwrap(); + pattern.nodes[0].children[1] = Some(inner); + pattern.nodes[1].children[1] = Some(leaf); + let fields = &mut pattern.nodes[1].parameters; + fields.insert("numberadded".into(), Value::Int(1)); + fields.insert("randominherited".into(), Value::Bool(false)); + fields.insert("randomseed".into(), Value::Function(Box::new(FunctionGraph::input("seed_value", ValueType::Integer)))); + let mut opacity = FunctionGraph::default(); + let one = opacity.add_constant(Value::Float(1.0)); + opacity.output = Some(opacity.add("rand", &[one], None)); + let fields = &mut pattern.nodes[2].parameters; + fields.insert("patterntype".into(), Value::Int(2)); + fields.insert("blendingmode".into(), Value::Int(0)); + fields.insert("opacity".into(), Value::Function(Box::new(opacity))); + let mut package = Package::new("Integer seed storage"); + package.graphs.push(graph); + let cache = Mutex::new(Cache::default()); + + let write_seed = |result| { + let mut f = FunctionGraph::default(); + let value = f.add_constant(Value::Int(17)); + let store = f.add("set", &[value], Some(Value::Text("seed_value".into()))); + let result = f.add_constant(result); + f.output = Some(f.add("sequence", &[store, result], None)); + f + }; + for (scope, expected) in [("input", 0.50918543), ("opacity", 0.26489496), ("iterate", 0.26489496), ("input", 0.50918543)] { + let mut options = Options::new(&|_| None); + let node = package.graphs[0].node_mut(stamp).unwrap(); + node.functions.remove("opacity"); + let count = match scope { + "input" => { + options.overrides.insert("seed_value".into(), Value::Int(17)); + Value::Int(1) + } + "opacity" => { + node.functions.insert("opacity".into(), write_seed(Value::Float(1.0))); + Value::Int(1) + } + _ => Value::Function(Box::new(write_seed(Value::Int(1)))), + }; + pattern.nodes[0].parameters.insert("numberadded".into(), count); + node.params.insert("pattern".into(), Value::PatternGraph(Box::new(pattern.clone()))); + let result = cook(&package, 0, &options, &cache); + assert_eq!(result.nodes[&stamp].error, None); + assert_eq!(result.image(stamp, 0).unwrap().get_gray(8, 8, false), expected, "{scope}"); + } +} + +fn first_local_probe() -> (Package, materialcraft_core::NodeId) { + let mut graph = Graph::new("First quadrant read"); + graph.size = [4; 2]; + graph.format = OutputFormat::F32; + let stamp = graph.add_node("fx_map", [0.0; 2]); + let node = graph.node_mut(stamp).unwrap(); + node.params.insert("color_mode".into(), Value::Bool(false)); + node.params.insert("roughness".into(), Value::Float(0.0)); + let mut pattern = PatternGraph::with_root(PatternNodeKind::Quadrant); + let fields = &mut pattern.nodes[0].parameters; + fields.insert("patterntype".into(), Value::Int(2)); + let mut tint = FunctionGraph::input("local", ValueType::Float); + let read = tint.output.unwrap(); + let equal = tint.add("eq", &[read, read], None); + let yes = tint.add_constant(Value::Float(0.375)); + let no = tint.add_constant(Value::Float(0.625)); + let choose = tint.add("ifelse", &[equal, yes, no], None); + tint.output = Some(tint.add("set", &[choose], Some(Value::Text("local".into())))); + fields.insert("opacity".into(), Value::Function(Box::new(tint))); + node.params.insert("pattern".into(), Value::PatternGraph(Box::new(pattern))); + + let mut package = Package::new("Quadrant parameter origin"); + package.graphs.push(graph); + (package, stamp) +} + +#[test] +fn bound_pattern_property_changes_the_first_local_read_at_equal_opacity() { + let (mut package, stamp) = first_local_probe(); + let mut options = Options::new(&|_| None); + options.overrides.insert("gain".into(), Value::Float(1.0)); + let cache = Mutex::new(Cache::default()); + for direct in [true, false] { + let node = package.graphs[0].node_mut(stamp).unwrap(); + if direct { + node.bindings.insert("opacity".into(), "gain".into()); + } else { + node.bindings.clear(); + node.functions.insert("opacity".into(), FunctionGraph::input("gain", ValueType::Float)); + } + for fixed in [true, false, true] { + options.literal_inputs = if fixed { vec!["gain".into()] } else { Vec::new() }; + let result = cook(&package, 0, &options, &cache); + assert_eq!(result.nodes[&stamp].error, None); + let expected = if fixed { 0.375 } else { 0.625 }; + assert_eq!(result.image(stamp, 0).unwrap().get_gray(8, 8, false), expected, "direct {direct}, fixed {fixed}"); + } + } + + let graph = &mut package.graphs[0]; + graph.node_mut(stamp).unwrap().functions.clear(); + graph.output_size_function = Some(FunctionGraph::input("offset", ValueType::Integer2)); + options.overrides.insert("offset".into(), Value::Int2([0; 2])); + for (mode, expected) in [(materialcraft_core::SizeMode::RelativeToParent, 0.625), (materialcraft_core::SizeMode::Absolute, 0.375)] { + let base = &mut package.graphs[0].node_mut(stamp).unwrap().base; + base.size_mode = mode; + base.size = if mode == materialcraft_core::SizeMode::Absolute { [4; 2] } else { [0; 2] }; + let result = cook(&package, 0, &options, &cache); + assert_eq!(result.nodes[&stamp].error, None); + assert_eq!(result.image(stamp, 0).unwrap().get_gray(0, 0, false), expected, "{mode:?}"); + } +} + +#[test] +fn connected_image_properties_reach_writable_quadrants() { + let (mut package, stamp) = first_local_probe(); + let graph = &mut package.graphs[0]; + let uniform = graph.add_node("uniform", [0.0; 2]); + let source = graph.node_mut(uniform).unwrap(); + source.params.insert("color_mode".into(), Value::Bool(false)); + source.functions.insert("color".into(), FunctionGraph::input("swatch", ValueType::Float4)); + let blur = graph.add_node("blur", [0.0; 2]); + graph.node_mut(blur).unwrap().params.insert("intensity".into(), Value::Float(0.0)); + graph.connect(uniform, "output", blur, "input").unwrap(); + let drawing = graph.add_node("fx_map", [0.0; 2]); + let mut square = PatternGraph::with_root(PatternNodeKind::Quadrant); + square.nodes[0].parameters.insert("patterntype".into(), Value::Int(2)); + square.nodes[0].parameters.insert("opacity".into(), Value::Function(Box::new(FunctionGraph::input("swatch", ValueType::Float4)))); + let stage = graph.node_mut(drawing).unwrap(); + stage.params.insert("color_mode".into(), Value::Bool(false)); + stage.params.insert("pattern".into(), Value::PatternGraph(Box::new(square))); + let mut options = Options::new(&|_| None); + options.overrides.insert("swatch".into(), Value::Float4([1.0; 4])); + let cache = Mutex::new(Cache::default()); + for port in ["pattern0", "background"] { + for source in [uniform, blur, drawing] { + for (connected, fixed) in [(false, false), (true, true), (true, false), (true, true)] { + let graph = &mut package.graphs[0]; + graph.disconnect(stamp, port); + if connected { + graph.connect(source, "output", stamp, port).unwrap(); + } + options.literal_inputs = if fixed { vec!["swatch".into()] } else { Vec::new() }; + let result = cook(&package, 0, &options, &cache); + assert_eq!(result.nodes[&stamp].error, None); + let background = if connected && port == "background" { 1.0 } else { 0.0 }; + let first = if connected && !fixed { 0.625 } else { 0.375 }; + assert_eq!(result.image(stamp, 0).unwrap().get_gray(8, 8, false), background + first, "{port}, {source:?}, {connected}, {fixed}"); + } + } + package.graphs[0].disconnect(stamp, port); + } +} + +#[test] +fn filter_controls_and_pixel_programs_reach_a_writable_pattern() { + let (mut package, stamp) = first_local_probe(); + let mut options = Options::new(&|_| None); + options.only = Some(vec![stamp]); + let cache = Mutex::new(Cache::default()); + for (filter, property, input) in [ + ("transformation", "offset", Value::Float2([0.0; 2])), + ("grayscale_conversion", "weights", Value::Float4([1.0, 0.0, 0.0, 0.0])), + ("directional_blur", "angle", Value::Float(0.25)), + ("levels", "in_low", Value::Float4([0.0; 4])), + ("warp", "intensity", Value::Float(0.0)), + ("pixel_processor", "function", Value::Float(0.5)), + ] { + let graph = &mut package.graphs[0]; + let source = graph.add_node(filter, [0.0; 2]); + let node = graph.node_mut(source).unwrap(); + let program = FunctionGraph::input("driver", ValueType::of(&input).unwrap()); + if filter == "pixel_processor" { + node.params.insert("color_mode".into(), Value::Bool(false)); + node.params.insert(property.into(), Value::Function(Box::new(program))); + } else { + node.functions.insert(property.into(), program); + } + graph.disconnect(stamp, "pattern0"); + graph.connect(source, "output", stamp, "pattern0").unwrap(); + options.overrides.insert("driver".into(), input); + for (fixed, expected) in [(true, 0.375), (false, 0.625), (true, 0.375)] { + options.literal_inputs = if fixed { vec!["driver".into()] } else { Vec::new() }; + let result = cook(&package, 0, &options, &cache); + assert_eq!(result.nodes[&source].error, None, "{filter}"); + assert_eq!(result.image(stamp, 0).unwrap().get_gray(8, 8, false), expected, "{filter}, fixed {fixed}"); + } + } +} + +#[test] +fn transform_matte_and_mip_level_follow_the_resolved_sampling_modes() { + let (mut package, stamp) = first_local_probe(); + let graph = &mut package.graphs[0]; + let transform = graph.add_node("transformation", [0.0; 2]); + graph.connect(transform, "output", stamp, "pattern0").unwrap(); + let mut options = Options::new(&|_| None); + options.overrides.insert("ink".into(), Value::Float4([0.0; 4])); + options.overrides.insert("level".into(), Value::Int(0)); + let cache = Mutex::new(Cache::default()); + for (property, driver) in [("matte", "ink"), ("mip_level", "level")] { + let node = package.graphs[0].node_mut(transform).unwrap(); + node.bindings.clear(); + node.bindings.insert(property.into(), driver.into()); + node.functions.insert("mip_mode".into(), FunctionGraph::input("mode", ValueType::Integer)); + for axes in [[true, true], [false, true], [true, false], [false, false]] { + let base = &mut package.graphs[0].node_mut(transform).unwrap().base; + base.tiling_mode = materialcraft_core::ParameterInheritance::Absolute; + base.tiling = axes; + for mode in [0, 1, 0] { + options.overrides.insert("mode".into(), Value::Int(mode)); + let active = if property == "matte" { axes != [true; 2] } else { mode == 1 }; + let cooked = cook(&package, 0, &options, &cache); + assert_eq!(cooked.nodes[&transform].error, None); + assert_eq!(cooked.image(stamp, 0).unwrap().get_gray(8, 8, false), if active { 0.625 } else { 0.375 }, "{property}, {axes:?}, {mode}"); + } + } + } +} + +#[test] +fn gray_pattern_opacity_keeps_signed_and_undefined_contributions_until_blending() { + let mut graph = Graph::new("Signed stamp opacity"); + graph.size = [4; 2]; + graph.format = OutputFormat::F32; + let stamp = graph.add_node("fx_map", [0.0; 2]); + let node = graph.node_mut(stamp).unwrap(); + node.params.insert("color_mode".into(), Value::Bool(false)); + node.params.insert("roughness".into(), Value::Float(0.0)); + let mut opacity = FunctionGraph::input("%gain", ValueType::Float); + let numerator = opacity.output.unwrap(); + let denominator = opacity.add_constant(Value::Float(0.0)); + opacity.output = Some(opacity.add("div", &[numerator, denominator], None)); + node.functions.insert("opacity".into(), opacity); + + let mut package = Package::new("Stamp storage"); + package.graphs.push(graph); + let cache = Mutex::new(Cache::default()); + let mut options = Options::new(&|_| None); + let mut pattern = PatternGraph::with_root(PatternNodeKind::Quadrant); + let fields = &mut pattern.nodes[0].parameters; + fields.insert("patterntype".into(), Value::Int(2)); + fields.insert("patternsize".into(), Value::Float2([0.5; 2])); + fields.insert("opacity".into(), Value::Float4([0.25, 0.25, 0.25, 1.0])); + for (mode, expected) in [(0, [f32::MAX.to_bits(), f32::MIN.to_bits(), 0x7fff_ffff]), (1, [f32::MAX.to_bits(), 0, 0])] { + pattern.nodes[0].parameters.insert("blendingmode".into(), Value::Int(mode)); + package.graphs[0].node_mut(stamp).unwrap().params.insert("pattern".into(), Value::PatternGraph(Box::new(pattern.clone()))); + for (gain, bits) in [1.0, -1.0, 0.0].into_iter().zip(expected) { + options.overrides.insert("gain".into(), Value::Float(gain)); + let result = cook(&package, 0, &options, &cache); + assert_eq!(result.nodes[&stamp].error, None); + let image = result.image(stamp, 0).unwrap(); + assert_eq!(image.get_gray(8, 8, false).to_bits(), bits); + assert_eq!(image.get_gray(0, 0, false).to_bits(), 0); + } + } + + let child = pattern.add(PatternNodeKind::Quadrant).unwrap(); + pattern.nodes[0].children[0] = Some(child); + pattern.nodes[0].parameters.insert("blendingmode".into(), Value::Int(0)); + pattern.nodes[0].parameters.insert("patternsize".into(), Value::Float2([1.0; 2])); + pattern.nodes[1].parameters = pattern.nodes[0].parameters.clone(); + pattern.nodes[1].parameters.insert("opacity".into(), Value::Float4([-0.25, -0.25, -0.25, 1.0])); + package.graphs[0].node_mut(stamp).unwrap().params.insert("pattern".into(), Value::PatternGraph(Box::new(pattern))); + options.overrides.insert("gain".into(), Value::Float(1.0)); + let result = cook(&package, 0, &options, &cache); + let image = result.image(stamp, 0).unwrap(); + assert_eq!(image.get_gray(4, 4, false), f32::MIN); + assert_eq!(image.get_gray(12, 12, false), f32::MAX); +} diff --git a/crates/eval/tests/seed_arithmetic.rs b/crates/eval/tests/seed_arithmetic.rs new file mode 100644 index 00000000..355ac00a --- /dev/null +++ b/crates/eval/tests/seed_arithmetic.rs @@ -0,0 +1,58 @@ +use materialcraft_core::{BaseParameter, FunctionGraph, Graph, OutputFormat, Package, ParameterInheritance, Value, ValueType}; +use materialcraft_eval::{Cache, Options, cook}; +use std::sync::Mutex; + +#[test] +fn graph_and_node_seeds_preserve_dynamic_scalar_words() { + let mut graph = Graph::new("Field"); + graph.size = [4; 2]; + graph.format = OutputFormat::F32; + graph.seed_mode = ParameterInheritance::Absolute; + let processor = graph.add_node("pixel_processor", [0.0; 2]); + let mut draw = FunctionGraph::default(); + let one = draw.add_constant(Value::Float(1.0)); + draw.output = Some(draw.add("rand", &[one], None)); + graph.node_mut(processor).unwrap().params.insert("function".into(), Value::Function(Box::new(draw))); + let mut package = Package::new("Seed arithmetic"); + package.graphs.push(graph); + + let mut function = FunctionGraph::input("$size", ValueType::Float2); + let width = function.add("swizzle1", &[function.output.unwrap()], Some(Value::Int(0))); + let scalar_one = function.add_constant(Value::Float(1.0)); + let sum = function.add("add", &[width, scalar_one], None); + let product = function.add("mul", &[width, scalar_one], None); + let word = function.add("toint1", &[width], None); + let sum_word = function.add("toint1", &[sum], None); + let product_word = function.add("toint1", &[product], None); + let next_word = function.add("add", &[word, word], None); + let negative = function.add_constant(Value::Float(-1.5)); + let fixed = function.add("toint1", &[negative], None); + let width_word = 16.0_f32.to_bits(); + let cache = Mutex::new(Cache::default()); + for (result, expected) in + [(word, width_word), (sum_word, (-1.0_f32).to_bits()), (product_word, width_word), (next_word, width_word.wrapping_mul(2)), (fixed, (-2_i32) as u32)] + { + function.output = Some(result); + for on_node in [false, true] { + let mut driven = package.clone(); + let mut literal = package.clone(); + if on_node { + let base = &mut driven.graphs[0].node_mut(processor).unwrap().base; + base.seed_mode = ParameterInheritance::Absolute; + base.functions.insert(BaseParameter::RandomSeed, function.clone()); + let base = &mut literal.graphs[0].node_mut(processor).unwrap().base; + base.seed_mode = ParameterInheritance::Absolute; + base.seed = expected as i32; + } else { + driven.graphs[0].seed_function = Some(function.clone()); + literal.graphs[0].seed = expected as i32; + } + let options = Options::new(&|_| None); + let actual = cook(&driven, 0, &options, &cache); + let control = cook(&literal, 0, &options, &cache); + assert_eq!(actual.nodes[&processor].error, None); + assert_eq!(actual.nodes[&processor].base.seed, expected, "output {result}, on node {on_node}"); + assert_eq!(actual.image(processor, 0).unwrap().data(), control.image(processor, 0).unwrap().data()); + } + } +} diff --git a/crates/formats/Cargo.toml b/crates/formats/Cargo.toml index 6f99b1de..215c2b30 100644 --- a/crates/formats/Cargo.toml +++ b/crates/formats/Cargo.toml @@ -9,6 +9,7 @@ license.workspace = true workspace = true [dependencies] +craft-mime = { workspace = true } craft-xml = { workspace = true } craft-sbs = { workspace = true } craft-zip = { workspace = true } diff --git a/crates/formats/examples/sbs_library_build/convert.rs b/crates/formats/examples/sbs_library_build/convert.rs index ed02479c..5e91ecc3 100644 --- a/crates/formats/examples/sbs_library_build/convert.rs +++ b/crates/formats/examples/sbs_library_build/convert.rs @@ -98,10 +98,11 @@ pub fn package(text: &str, name: &str, identities: &BTreeMap) -> let before = semantics(&document); let mut edits = Vec::new(); - for tag in ["formatVersion", "updaterVersion"] { + let format_version = materialcraft_formats::sbs::output_format_version(xml::value(root, "formatVersion")); + for (tag, version) in [("formatVersion", format_version), ("updaterVersion", env!("CARGO_PKG_VERSION"))] { if xml::child(root, tag).is_none() { let offset = root.first_element_child().ok_or("package has no content")?.range().start; - edits.push(XmlEdit { range: offset..offset, replacement: xml::leaf(tag, env!("CARGO_PKG_VERSION")) }); + edits.push(XmlEdit { range: offset..offset, replacement: xml::leaf(tag, version) }); } } @@ -137,7 +138,10 @@ pub fn package(text: &str, name: &str, identities: &BTreeMap) -> "fileUID" if node.parent().is_some_and(|p| p.has_tag_name("package")) => { xml::set(&mut edits, node, identities.get(name).ok_or("missing package identity")?); } - "formatVersion" | "updaterVersion" if node.parent().is_some_and(|p| p.has_tag_name("package")) => { + "formatVersion" if node.parent().is_some_and(|p| p.has_tag_name("package")) => { + xml::set(&mut edits, node, format_version); + } + "updaterVersion" if node.parent().is_some_and(|p| p.has_tag_name("package")) => { xml::set(&mut edits, node, env!("CARGO_PKG_VERSION")); } "dependency" => { diff --git a/crates/formats/examples/sbs_library_build/tests.rs b/crates/formats/examples/sbs_library_build/tests.rs index 592af389..6413fe0e 100644 --- a/crates/formats/examples/sbs_library_build/tests.rs +++ b/crates/formats/examples/sbs_library_build/tests.rs @@ -39,16 +39,19 @@ fn flat_package_inventory_enforces_the_total_file_limit() { } #[test] -fn conversion_starts_both_versions_at_the_workspace_release() { - let saved = materialcraft_formats::sbs::write_sbs(&materialcraft_core::Package::new("Version check")).unwrap(); - let saved = xml::parse(std::str::from_utf8(&saved).unwrap()).unwrap(); - let expected = xml::value(saved.root_element(), "updaterVersion").unwrap(); - for source in [PACKAGE.to_string(), PACKAGE.replacen("", "", 1)] { +fn conversion_preserves_the_schema_and_records_the_saving_release() { + for (source, schema) in [ + (PACKAGE.to_string(), "1.1.0.202502"), + (PACKAGE.replacen("", "", 1), "1.1.0.202502"), + (PACKAGE.replace("", ""), "1.1.0.202401"), + (PACKAGE.replace("1.1.0.202502", "0.1.3"), "1.1.0.202401"), + ] { let converted = convert::package(&source, "example.sbs", &identities("example.sbs")).unwrap(); let converted = xml::parse(&converted.xml).unwrap(); - assert_eq!(xml::value(converted.root_element(), "updaterVersion"), Some(expected)); - assert_eq!(xml::value(converted.root_element(), "formatVersion"), Some(expected)); + assert_eq!(xml::value(converted.root_element(), "updaterVersion"), Some(env!("CARGO_PKG_VERSION"))); + assert_eq!(xml::value(converted.root_element(), "formatVersion"), Some(schema)); + assert_eq!(converted.root_element().children().filter(|n| n.has_tag_name("formatVersion")).count(), 1); assert_eq!(converted.root_element().children().filter(|n| n.has_tag_name("updaterVersion")).count(), 1); } } diff --git a/crates/formats/src/image.rs b/crates/formats/src/image.rs index fa2a3994..66212d2b 100644 --- a/crates/formats/src/image.rs +++ b/crates/formats/src/image.rs @@ -1,16 +1,22 @@ use crate::{Depth, FormatError, Result, guard}; use craft_image_codecs::{ChannelLayout, CodecError, DecodeOptions, EncodeOptions, Format, Limits as CodecLimits, SampleType}; use craft_texture::{Image, Kind, Limits, MAX_SIDE, linear_to_srgb, srgb_to_linear}; +use materialcraft_nodes::BitmapColorSpace; + +const MAX_DECODE_BYTES: u64 = 1 << 30; /// Decode image file bytes into a linear float image (8-bit color is sRGB-decoded; grayscale files stay grayscale) pub fn decode(bytes: &[u8], linear: bool) -> Result { + decode_with_color_space(bytes, if linear { BitmapColorSpace::Linear } else { BitmapColorSpace::Srgb }) +} + +/// Decode a bitmap using its file transfer or an explicit interpretation of its stored channels. +pub fn decode_with_color_space(bytes: &[u8], space: BitmapColorSpace) -> Result { if bytes.starts_with(b"DDS ") { - return guard(|| crate::dds_image::decode(bytes, linear), || FormatError::Image("DDS decoder failed".into())); + return guard(|| crate::dds_image::decode(bytes, space == BitmapColorSpace::Linear), || FormatError::Image("DDS decoder failed".into())); } const SVG_SNIFF_BYTES: usize = 4096; - const MAX_DECODE_BYTES: u64 = 1 << 30; - if std::str::from_utf8(bytes.get(..bytes.len().min(SVG_SNIFF_BYTES)).unwrap_or_default()).is_ok_and(|text| text.contains(" Result { let opts = DecodeOptions { limits, keep_orientation: true }; let format = craft_image_codecs::detect(bytes).unwrap_or(Format::Tga); let failed = || FormatError::Image("the decoder failed on this file".into()); - let codec_error = |e: CodecError| match e { - CodecError::LimitExceeded(msg) => FormatError::Image(msg), - e => FormatError::Image(e.to_string()), + let codec_error = |error: CodecError| match error { + CodecError::LimitExceeded(message) => FormatError::Image(message), + error => FormatError::Image(error.to_string()), }; - let decoded = guard(|| craft_image_codecs::decode_as_with(format, bytes, &opts).map_err(codec_error), failed)?; let (w, h) = decoded.dimensions(); if w == 0 || h == 0 || w > MAX_SIDE || h > MAX_SIDE { return Err(FormatError::Image(format!("{w}x{h} is outside 1..={MAX_SIDE} pixels"))); } - + let png = if space == BitmapColorSpace::FromFile && format == Format::Png { materialcraft_core::png_raster_info(bytes) } else { None }; + let stored = match space { + BitmapColorSpace::Linear => true, + BitmapColorSpace::Srgb => false, + BitmapColorSpace::FromFile => png.is_some() || matches!(format, Format::Jpeg | Format::Bmp | Format::Tiff | Format::Tga), + }; + let table = png.and_then(|info| { + let maximum = if info.format == materialcraft_core::OutputFormat::U8 { 255 } else { 65535 }; + png_channel_table(bytes, maximum) + }); + let float = decoded.sample_type().is_float(); if decoded.layout().is_gray() { let gray = decoded.converted(ChannelLayout::Gray, SampleType::F32); - let data = gray.to_f32_samples().ok_or_else(|| FormatError::Image("bad buffer".into()))?; - return Image::from_data(w, h, Kind::Gray, data, &Limits::default()).map_err(|e| FormatError::Image(e.to_string())); + let mut data = gray.to_f32_samples().ok_or_else(|| FormatError::Image("bad buffer".into()))?; + if let Some(table) = &table { + for value in &mut data { + *value = mapped_channel(table, *value); + } + } + return Image::from_data(w, h, Kind::Gray, data, &Limits::default()) + .map(|image| image.with_integer_sampling(!float)) + .map_err(|error| FormatError::Image(error.to_string())); } - - let float = decoded.sample_type().is_float(); let mut data = decoded.to_rgba_f32(&limits).map_err(codec_error)?; - if !(float || linear) { - for px in data.as_chunks_mut::<4>().0 { - for c in px.iter_mut().take(3) { - *c = srgb_to_linear(*c); + if let Some(table) = table { + for pixel in data.as_chunks_mut::<4>().0 { + for channel in &mut pixel[..3] { + *channel = mapped_channel(&table, *channel); + } + } + } else if !(float || stored) { + for pixel in data.as_chunks_mut::<4>().0 { + for channel in &mut pixel[..3] { + *channel = srgb_to_linear(*channel); } } } + Image::from_data(w, h, Kind::Color, data, &Limits::default()) + .map(|image| image.with_integer_sampling(stored && !float)) + .map_err(|error| FormatError::Image(error.to_string())) +} - Image::from_data(w, h, Kind::Color, data, &Limits::default()).map_err(|e| FormatError::Image(e.to_string())) +fn png_channel_table(bytes: &[u8], maximum: u32) -> Option> { + let metadata = craft_image_codecs::png_probe::color_chunks(bytes)?; + if metadata.srgb { + return None; + } + // Recover the five-place file gamma before rounding the correction exponent. + let gamma = (f64::from(metadata.gamma?) * 100_000.0).round() / 100_000.0; + let ratio = gamma * 2.2; + let exponent = (100_000.0 / ratio).round() / 100_000.0; + if (ratio * 100_000.0).round() >= 95_000.0 && exponent >= 0.95 { + return None; + } + let levels = f64::from(maximum); + Some((0..=maximum).map(|v| ((f64::from(v) / levels).powf(exponent) * levels).round() as f32 / maximum as f32).collect()) +} + +fn mapped_channel(table: &[f32], value: f32) -> f32 { + let last = table.len().saturating_sub(1) as f32; + table.get((value * last).round() as usize).copied().unwrap_or(value) } /// Encode `image` as `ext` (see [`EXPORT_FORMATS`]). `srgb`: color values are written through the sRGB curve (base color); data maps (normal, roughness…) are written linear diff --git a/crates/formats/src/lib.rs b/crates/formats/src/lib.rs index cc8153a8..b92afb15 100644 --- a/crates/formats/src/lib.rs +++ b/crates/formats/src/lib.rs @@ -20,7 +20,7 @@ pub use file::write_atomic; pub use file::{output_name, safe_file_name}; pub use format_error::FormatError; pub(crate) use guard::guard; -pub use image::{decode, encode}; +pub use image::{decode, decode_with_color_space, encode}; pub type Result = std::result::Result; pub(crate) const MAX_RESOURCE: u64 = 256 << 20; diff --git a/crates/formats/src/sbs/constant.rs b/crates/formats/src/sbs/constant.rs index ec19fca0..8f3b1573 100644 --- a/crates/formats/src/sbs/constant.rs +++ b/crates/formats/src/sbs/constant.rs @@ -1,8 +1,6 @@ pub use craft_sbs::SBS_EXT; pub(super) use craft_sbs::{MAX_XML_NODES, SELF_DEPENDENCY}; -pub(super) const SELF_DEPENDENCY_UID: u64 = craft_sbs::FIRST_UID + 1; - pub(crate) const MAX_GRAPHS: usize = 4096; pub(crate) const MAX_NODES: usize = 100_000; @@ -13,4 +11,5 @@ pub(super) const MAX_WARNINGS: usize = 600; /// Most wires one SBS may carry, across all graphs (audit: MaterialCraft #2). pub(super) const MAX_WIRES: usize = 1_000_000; +pub(super) const SELF_DEPENDENCY_UID: u64 = craft_sbs::FIRST_UID + 1; pub(super) const NODE_HALF_SIZE: [f32; 2] = [50.0, 40.0]; diff --git a/crates/formats/src/sbs/filter_map.rs b/crates/formats/src/sbs/filter_map.rs index add01aae..59757207 100644 --- a/crates/formats/src/sbs/filter_map.rs +++ b/crates/formats/src/sbs/filter_map.rs @@ -32,7 +32,7 @@ pub(super) const FILTERS: &[FilterMap] = &[ sbs: "distance", def: "distance", inputs: &[("mask", "mask"), ("source", "source")], - params: &[("distance", "distance"), ("combinedistance", "combine")], + params: &[("distance", "distance"), ("combinedistance", "combine"), ("distancemode", "metric"), ("colorswitch", "color_mode")], }, FilterMap { sbs: "emboss", @@ -46,12 +46,17 @@ pub(super) const FILTERS: &[FilterMap] = &[ inputs: &[("input1", "input"), ("input2", "gradient"), ("inputgradient", "gradient")], params: &[("coordinate", "position"), ("uvselector", "orientation")], }, - FilterMap { sbs: "gradient", def: "gradient_map", inputs: &[("input1", "input")], params: &[("colorswitch", "color_mode")] }, + FilterMap { + sbs: "gradient", + def: "gradient_map", + inputs: &[("input1", "input")], + params: &[("colorswitch", "color_mode"), ("interpmode", "interpolation")], + }, FilterMap { sbs: "grayscaleconversion", def: "grayscale_conversion", inputs: &[("input1", "input")], - params: &[("alphamult", "flatten_alpha"), ("mattelevel", "matte")], + params: &[("alphamult", "flatten_alpha"), ("mattelevel", "matte"), ("channelsweights", "weights")], }, FilterMap { sbs: "hsl", def: "hsl", inputs: &[("input1", "input")], params: &[("hue", "hue"), ("saturation", "saturation"), ("luminosity", "lightness")] }, FilterMap { sbs: "bitmap", def: "bitmap", inputs: &[], params: &[("colorswitch", "color_mode"), ("colorspace", "colour_space")] }, @@ -59,7 +64,14 @@ pub(super) const FILTERS: &[FilterMap] = &[ sbs: "levels", def: "levels", inputs: &[("input1", "input")], - params: &[("levelinlow", "in_low"), ("levelinmid", "in_mid"), ("levelinhigh", "in_high"), ("leveloutlow", "out_low"), ("levelouthigh", "out_high")], + params: &[ + ("levelinlow", "in_low"), + ("levelinmid", "in_mid"), + ("levelinhigh", "in_high"), + ("leveloutlow", "out_low"), + ("levelouthigh", "out_high"), + ("clampinterm", "clamp_intermediate"), + ], }, FilterMap { sbs: "normal", @@ -79,9 +91,21 @@ pub(super) const FILTERS: &[FilterMap] = &[ sbs: "transformation", def: "transformation", inputs: &[("input1", "input")], - params: &[("offset", "offset"), ("mattecolor", "matte"), ("matrix22", "matrix"), ("filtering", "filtering")], + params: &[ + ("offset", "offset"), + ("mattecolor", "matte"), + ("matrix22", "matrix"), + ("filtering", "filtering"), + ("mipmapmode", "mip_mode"), + ("manualmiplevel", "mip_level"), + ], + }, + FilterMap { + sbs: "warp", + def: "warp", + inputs: &[("input1", "input"), ("inputgradient", "gradient")], + params: &[("intensity", "intensity"), ("warpfilter", "nearest")], }, - FilterMap { sbs: "warp", def: "warp", inputs: &[("input1", "input"), ("inputgradient", "gradient")], params: &[("intensity", "intensity")] }, FilterMap { sbs: "passthrough", def: "dot", inputs: &[("input", "input"), ("input1", "input")], params: &[] }, FilterMap { sbs: "text", @@ -110,12 +134,12 @@ pub(super) const FILTERS: &[FilterMap] = &[ ("opacitymult", "opacity"), ("renderroi", "render_region"), ("tilingroi", "tiling_region"), + ("culling", "cull_outside"), ], }, ]; pub(super) const BASE_PARAMS: &[&str] = &["outputsize", "format", "randomseed", "tiling", "pixelsize", "pixelratio", "quality"]; -pub(super) const HANDLED_PARAMS: &[(&str, &str)] = - &[("bitmap", "bitmapresourcepath"), ("grayscaleconversion", "channelsweights"), ("transformation", "matrix22"), ("curve", "exposecurve")]; +pub(super) const HANDLED_PARAMS: &[(&str, &str)] = &[("bitmap", "bitmapresourcepath"), ("transformation", "matrix22"), ("curve", "exposecurve")]; pub(super) fn filter_by_sbs_name(name: &str) -> Option<&'static FilterMap> { FILTERS.iter().find(|f| f.sbs == name) diff --git a/crates/formats/src/sbs/library.rs b/crates/formats/src/sbs/library.rs index d588eb74..49dba710 100644 --- a/crates/formats/src/sbs/library.rs +++ b/crates/formats/src/sbs/library.rs @@ -47,6 +47,37 @@ pub fn contains_file(path: &std::path::Path) -> bool { path.parent().and_then(|parent| parent.canonicalize().ok()).is_some_and(|parent| parent.starts_with(root)) } +/// Return a portable package link for an unchanged bundled file beneath the canonical library root. +#[cfg(not(target_arch = "wasm32"))] +pub fn bundled_package_uri(canonical_root: &std::path::Path, path: &std::path::Path) -> Option { + use std::io::Read; + + if !path.is_absolute() { + return None; + } + let file = path.canonicalize().ok()?; + let relative = file.strip_prefix(canonical_root).ok()?.to_str()?.replace('\\', "/"); + let uri = format!("sbs://{relative}"); + relative_path(&uri).ok()?; + BUNDLED.binary_search(&uri.as_str()).ok()?; + + // A locally edited package at a shipped path must keep pointing to those edits. + let mut file = std::fs::File::open(file).ok()?; + let expected = read_embedded(&relative).ok()?; + if file.metadata().ok()?.len() != expected.len() as u64 { + return None; + } + let mut buffer = [0; 8192]; + for chunk in expected.chunks(buffer.len()) { + let actual = buffer.get_mut(..chunk.len())?; + file.read_exact(actual).ok()?; + if actual != chunk { + return None; + } + } + (file.read(&mut buffer).ok()? == 0).then_some(uri) +} + /// Read a validated library alias from the configured directory or the embedded fallback. pub fn read(uri: &str) -> Result, String> { let relative = relative_path(uri)?; diff --git a/crates/formats/src/sbs/library_layout.rs b/crates/formats/src/sbs/library_layout.rs index 21259615..8d970381 100644 --- a/crates/formats/src/sbs/library_layout.rs +++ b/crates/formats/src/sbs/library_layout.rs @@ -6,7 +6,7 @@ use super::{ LayoutFrame, LayoutItem, filter_map::FILTERS, - xml::{child_element, child_value, children_named, parse_floats}, + xml::{child_element, child_value, children_named, parse_floats, string_parameter}, }; use crate::{FormatError, Result}; use roxmltree::Node as XmlNode; @@ -189,16 +189,6 @@ fn function_item(node: XmlNode, dependencies: &HashMap<&str, String>) -> Option< Some(LayoutItem::FunctionInstance { package, graph }) } -/// Read a named static string parameter from an atomic filter. -fn string_parameter<'a>(filter: XmlNode<'a, '_>, name: &str) -> Option<&'a str> { - child_element(filter, "parameters") - .into_iter() - .flat_map(|parameters| children_named(parameters, "parameter")) - .find(|parameter| child_value(*parameter, "name") == Some(name)) - .and_then(|parameter| child_element(parameter, "paramValue")) - .and_then(|value| child_value(value, "constantValueString")) -} - #[cfg(test)] #[allow(clippy::unwrap_used, clippy::expect_used)] mod tests { diff --git a/crates/formats/src/sbs/mod.rs b/crates/formats/src/sbs/mod.rs index d9ea0b64..5784de63 100644 --- a/crates/formats/src/sbs/mod.rs +++ b/crates/formats/src/sbs/mod.rs @@ -44,7 +44,7 @@ pub use library_layout::read_layout; pub use read::{is_sbs, read_sbs}; pub use sbs_document::SbsDocument; pub use sbs_read::SbsRead; -pub use write::write_sbs; +pub use write::{output_format_version, write_sbs}; #[cfg(test)] mod tests; diff --git a/crates/formats/src/sbs/node_parameter.rs b/crates/formats/src/sbs/node_parameter.rs index 0702c027..1df2b583 100644 --- a/crates/formats/src/sbs/node_parameter.rs +++ b/crates/formats/src/sbs/node_parameter.rs @@ -11,6 +11,11 @@ pub(super) fn text_param(node: &Node, key: &str, default: &str) -> String { pub(super) fn param_xml(name: &str, value: &Value) -> Option { Some(format!("{}", xml_escape(name), constant_xml(value)?)) } + +pub(super) fn resource_parameter_xml(parameter: &str, name: &str, self_uid: u64, package: &materialcraft_core::Package) -> String { + let path = package.resource(name).map_or_else(|| format!("Resources/{name}"), |resource| resource.sbs_path()); + param_xml(parameter, &Value::Text(format!("pkg:///{path}?dependency={self_uid}"))).unwrap_or_default() +} pub(super) fn special_filter_params_xml<'a>( filter: &str, value_of: &dyn Fn(&str) -> Option<&'a Value>, @@ -19,20 +24,11 @@ pub(super) fn special_filter_params_xml<'a>( ) -> String { match filter { "bitmap" | "svg" => match value_of("resource") { - Some(Value::Text(name)) if !name.is_empty() => param_xml( - if filter == "svg" { "vectorresourcepath" } else { "bitmapresourcepath" }, - &Value::Text(format!( - "pkg:///{}?dependency={self_uid}", - package.resource(name).map_or_else(|| format!("Resources/{name}"), |resource| resource.sbs_path()) - )), - ) - .unwrap_or_default(), + Some(Value::Text(name)) if !name.is_empty() => { + resource_parameter_xml(if filter == "svg" { "vectorresourcepath" } else { "bitmapresourcepath" }, name, self_uid, package) + } _ => String::new(), }, - "grayscaleconversion" => { - let weight = |channel: &str| value_of(channel).and_then(Value::as_f32).unwrap_or(0.0); - param_xml("channelsweights", &Value::Float4([weight("red"), weight("green"), weight("blue"), weight("alpha")])).unwrap_or_default() - } _ => String::new(), } } diff --git a/crates/formats/src/sbs/parameter_array.rs b/crates/formats/src/sbs/parameter_array.rs index e38f2f54..a68ed4fd 100644 --- a/crates/formats/src/sbs/parameter_array.rs +++ b/crates/formats/src/sbs/parameter_array.rs @@ -22,7 +22,16 @@ pub(super) fn read(node: &mut Node, implementation: XmlNode<'_, '_>) { match child_value(array, "name") { Some("curveluminance") => { let position = vector("position").unwrap_or([0.0; 2]); - curve.points.push(CurvePoint { x: position[0], y: position[1], left: vector("left"), right: vector("right") }); + let flag = |name| parameters.get(name).and_then(Value::as_bool).unwrap_or(false); + curve.points.push(CurvePoint { + x: position[0], + y: position[1], + left: vector("left"), + right: vector("right"), + left_broken: flag("isLeftBroken"), + right_broken: flag("isRightBroken"), + locked: flag("isLocked"), + }); } Some("gradientrgba" | "gradientluminance") => { let position = parameters.get("position").and_then(Value::as_f32).unwrap_or(0.0); @@ -31,11 +40,9 @@ pub(super) fn read(node: &mut Node, implementation: XmlNode<'_, '_>) { Some(value) => value.as_vec4().unwrap_or([0.0; 4]), None => [0.0; 4], }; - let midpoint = parameters.get("midpoint").and_then(Value::as_f32).unwrap_or(0.5); - - // Legacy gradient arrays use zero for their default linear segments - // Treating it as a near-zero interpolation fraction clips successive ramps to white - let midpoint = if midpoint == 0.0 { 0.5 } else { midpoint }; + // SBS stores a signed bias. The document uses a centered 0..1 control. + let bias = parameters.get("midpoint").and_then(Value::as_f32).unwrap_or(0.0); + let midpoint = 0.5 + 0.5 * bias.clamp(-1.0, 1.0); gradient.keys.push(GradientKey { pos: position, color, midpoint }); } _ => {} @@ -53,16 +60,10 @@ pub(super) fn read(node: &mut Node, implementation: XmlNode<'_, '_>) { } } -pub(super) fn write(value: &Value, color_mode: bool, writer: &mut SbsWriter) -> String { +pub(super) fn write(value: &Value, writer: &mut SbsWriter) -> String { let name = match value { Value::Curve(_) => "curveluminance", - Value::Gradient(_) => { - if color_mode { - "gradientrgba" - } else { - "gradientluminance" - } - } + Value::Gradient(_) => "gradientrgba", _ => return String::new(), }; @@ -79,22 +80,21 @@ pub(super) fn write(value: &Value, color_mode: bool, writer: &mut SbsWriter) -> Value::Curve(curve) => { for (index, point) in curve.points.iter().enumerate() { let position = [point.x, point.y]; - let left = index.checked_sub(1).and_then(|index| curve.segment(index)).map_or(position, |segment| segment[2]); - let right = curve.segment(index).map_or(position, |segment| segment[1]); + let left = point.left.or_else(|| index.checked_sub(1).and_then(|index| curve.segment(index)).map(|s| s[2])).unwrap_or(position); + let right = point.right.or_else(|| curve.segment(index).map(|s| s[1])).unwrap_or(position); cell(vec![ ("position", Value::Float2(position)), ("left", Value::Float2(left)), ("right", Value::Float2(right)), - ("isLeftBroken", Value::Bool(true)), - ("isRightBroken", Value::Bool(true)), - ("isLocked", Value::Bool(false)), + ("isLeftBroken", Value::Bool(point.left_broken)), + ("isRightBroken", Value::Bool(point.right_broken)), + ("isLocked", Value::Bool(point.locked)), ]); } } Value::Gradient(gradient) => { for key in &gradient.keys { - let color = if color_mode { Value::Color(key.color) } else { Value::Float(craft_texture::luminance(key.color)) }; - cell(vec![("position", Value::Float(key.pos)), ("midpoint", Value::Float(key.midpoint)), ("value", color)]); + cell(vec![("position", Value::Float(key.pos)), ("midpoint", Value::Float(2.0 * key.midpoint - 1.0)), ("value", Value::Float4(key.color))]); } } _ => {} diff --git a/crates/formats/src/sbs/parameter_widget.rs b/crates/formats/src/sbs/parameter_widget.rs index fea17e5d..9ca3b89f 100644 --- a/crates/formats/src/sbs/parameter_widget.rs +++ b/crates/formats/src/sbs/parameter_widget.rs @@ -40,7 +40,8 @@ pub(super) fn read(element: Node<'_, '_>, input: &mut ExposedParameter) { } if color && matches!(input.default, Value::Float4(_)) { // Color defaults use the same displayed-to-linear conversion as node colors - if let Some(value) = child_element(element, "defaultValue") + if let Some(value) = child_element(element, "materialcraftDefault") + .or_else(|| child_element(element, "defaultValue")) .and_then(super::sbs_value::sbs_constant) .and_then(|value| super::sbs_value::to_param_value(&Value::Color([0.0; 4]), &value, 0)) { diff --git a/crates/formats/src/sbs/pattern_graph.rs b/crates/formats/src/sbs/pattern_graph.rs index 6fa72c8c..f3762c23 100644 --- a/crates/formats/src/sbs/pattern_graph.rs +++ b/crates/formats/src/sbs/pattern_graph.rs @@ -1,4 +1,4 @@ -use materialcraft_core::{PatternGraph, PatternNode, PatternNodeKind, Value}; +use materialcraft_core::{FunctionGraph, PatternGraph, PatternNode, PatternNodeKind, Value}; use roxmltree::Node as XmlNode; use std::collections::BTreeMap; use std::fmt::Write; @@ -87,6 +87,13 @@ pub(super) fn write(graph: &PatternGraph, writer: &mut SbsWriter) -> Result = definition.params.iter().map(|parameter| (parameter.id.to_string(), parameter.default.clone())).collect(); parameters.extend(node.parameters.clone()); + if node.kind == PatternNodeKind::Quadrant + && let Some(luminosity @ Value::Float(_)) = parameters.get_mut("opacity") + { + // The literal swatch has four components. A scalar expression preserves the + // luminosity in both grayscale and color patterns when the package is reopened. + *luminosity = Value::Function(Box::new(FunctionGraph::constant(luminosity.clone()))); + } for (name, value) in ¶meters { if let Value::Function(function) = value { let function = function_graph::write(function, writer)?; @@ -122,3 +129,32 @@ pub(super) fn write(graph: &PatternGraph, writer: &mut SbsWriter) -> Result"); Ok(output) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn quadrant_scalar_luminosity_uses_a_scalar_function_on_save() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let original_swatch = Value::Float4([0.25, 0.5, 0.75, 0.875]); + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children[1] = Some(child); + graph.nodes[0].parameters.insert("opacity".into(), Value::Float(-0.3125)); + graph.nodes[1].parameters.insert("opacity".into(), original_swatch.clone()); + let mut writer = SbsWriter { last_uid: 10, external_packages: BTreeMap::new() }; + let xml = write(&graph, &mut writer).unwrap(); + let document = roxmltree::Document::parse(&xml).unwrap(); + let stored = read(document.root_element().first_element_child().unwrap()).unwrap(); + + // A literal swatch accepts four components. A one-component function keeps scalar + // luminosity semantics in both color modes, including values outside the unit range. + let Value::Function(function) = &stored.nodes[0].parameters["opacity"] else { panic!("expected a scalar function") }; + let scalar = function.node(function.output.unwrap()).unwrap(); + assert_eq!(scalar.op, "const_float1"); + assert_eq!(scalar.type_code, 256); + assert_eq!(scalar.value, Some(Value::Float(-0.3125))); + assert_eq!(function.nodes.len(), 1); + assert_eq!(stored.nodes[1].parameters["opacity"], original_swatch); + } +} diff --git a/crates/formats/src/sbs/preview_binding.rs b/crates/formats/src/sbs/preview_binding.rs index 34e39615..7433e5a7 100644 --- a/crates/formats/src/sbs/preview_binding.rs +++ b/crates/formats/src/sbs/preview_binding.rs @@ -8,6 +8,9 @@ const LINEAR_PREFIX: &str = "materialcraft.previewLinear."; pub(super) fn write(out: &mut String, graph: &Graph) { for (identifier, resource) in &graph.input_images { + if graph.input_images_from_file.contains(identifier) { + continue; + } let _ = write!(out, "", xml_escape(identifier), xml_escape(resource)); if graph.input_images_linear.contains(identifier) { let _ = write!(out, "", xml_escape(identifier)); @@ -15,6 +18,21 @@ pub(super) fn write(out: &mut String, graph: &Graph) { } } +pub(super) fn read_resource(graph: &mut Graph, identifier: &str, resource: Option) { + // A matching preview option retains the interpretation explicitly chosen for this resource. + if resource.is_some() && graph.input_images.get(identifier) == resource.as_ref() { + return; + } + graph.input_images_linear.remove(identifier); + if let Some(name) = resource { + graph.input_images.insert(identifier.to_string(), name); + graph.input_images_from_file.insert(identifier.to_string()); + } else { + graph.input_images.remove(identifier); + graph.input_images_from_file.remove(identifier); + } +} + pub(super) fn read(option: XmlNode, graph: &mut Graph) { let Some(name) = child_value(option, "name") else { return }; let Some(value) = child_value(option, "value") else { return }; @@ -27,3 +45,79 @@ pub(super) fn read(option: XmlNode, graph: &mut Graph) { graph.input_images_linear.insert(identifier.to_string()); } } + +#[cfg(test)] +mod tests { + use crate::sbs::{read_sbs, write_sbs}; + use materialcraft_core::{Graph, Package, Resource, ResourceBytes, Value}; + + #[test] + fn image_bridges_write_the_bound_package_resource() { + let mut package = Package::new("Input images"); + let mut resource = Resource::new("grain", "grain.png", ResourceBytes::default()); + resource.folder = "Inputs/Maps".into(); + resource.source = "grain.png".into(); + package.resources.push(resource); + let mut graph = Graph::new("Paint"); + for (definition, identifier) in [("input_grayscale", "height"), ("input_color", "paint"), ("input_color", "open")] { + let id = graph.add_node(definition, [0.0; 2]); + graph.node_mut(id).unwrap().params.insert("identifier".into(), Value::Text(identifier.into())); + } + for identifier in ["height", "paint"] { + graph.input_images.insert(identifier.into(), "grain".into()); + } + package.graphs.push(graph); + + let bytes = write_sbs(&package).unwrap(); + let doc = roxmltree::Document::parse(std::str::from_utf8(&bytes).unwrap()).unwrap(); + let own = doc.descendants().find(|node| node.has_tag_name("dependency") && super::child_value(*node, "filename") == Some("?himself")).unwrap(); + let url = format!("pkg:///Inputs/Maps/grain?dependency={}", super::child_value(own, "uid").unwrap()); + let bindings: Vec<_> = doc + .descendants() + .filter(|node| node.has_tag_name("compInputBridge")) + .map(|bridge| { + bridge + .descendants() + .find(|p| p.has_tag_name("parameter") && super::child_value(*p, "name") == Some("bitmapresourcepath")) + .and_then(|p| p.descendants().find(|v| v.has_tag_name("constantValueString"))) + .and_then(|v| v.attribute("v")) + }) + .collect(); + assert_eq!(bindings, [Some(url.as_str()), Some(url.as_str()), None]); + let reopened = read_sbs(&bytes, "input.sbs", &|_| None).unwrap().pkg; + assert_eq!(reopened.graphs[0].input_images, package.graphs[0].input_images); + assert!(reopened.graphs[0].input_images_from_file.is_empty()); + } + + #[test] + fn image_bridge_binding_takes_precedence_over_a_legacy_preview_name() { + let xml = br#" + + + + + + + "#; + let package = read_sbs(xml, "paint.sbs", &|_| None).unwrap().pkg; + assert_eq!(package.graphs[0].input_images.get("height").map(String::as_str), Some("grain")); + assert!(package.graphs[0].input_images_from_file.contains("height")); + let reopened = read_sbs(&write_sbs(&package).unwrap(), "again.sbs", &|_| None).unwrap().pkg; + assert_eq!(package.graphs[0].input_images_from_file, reopened.graphs[0].input_images_from_file); + } + + #[test] + fn clearing_the_bridge_resource_clears_its_preview_interpretation() { + let mut graph = Graph::new("Paint"); + graph.input_images.insert("height".into(), "grain".into()); + graph.input_images_linear.insert("height".into()); + super::read_resource(&mut graph, "height", Some("grain".into())); + assert!(graph.input_images_linear.contains("height")); + super::read_resource(&mut graph, "height", Some("different".into())); + assert!(graph.input_images_linear.is_empty()); + assert!(graph.input_images_from_file.contains("height")); + super::read_resource(&mut graph, "height", None); + assert!(graph.input_images.is_empty()); + assert!(graph.input_images_from_file.is_empty()); + } +} diff --git a/crates/formats/src/sbs/sbs_reader.rs b/crates/formats/src/sbs/sbs_reader.rs index 5a0083e2..3220e1e2 100644 --- a/crates/formats/src/sbs/sbs_reader.rs +++ b/crates/formats/src/sbs/sbs_reader.rs @@ -14,7 +14,7 @@ use super::read_node::ReadNode; use super::sbs_value::{SbsValue, exposed_default, sbs_constant, to_natural_value, to_param_value}; use super::type_code; use super::warnings::Warnings; -use super::xml::{child_element, child_value, children_named, parse_floats}; +use super::xml::{child_element, child_value, children_named, parse_floats, string_parameter}; use materialcraft_core::{ BaseParameter, ComponentUsage, Connection, ExposedParameter, Graph, MAX_SIZE_LOG2, MIN_SIZE_LOG2, MISSING_NODE, Node, NodeId, OutputFormat, Package, ParameterInheritance, Resource, ResourceBytes, Value, @@ -207,9 +207,19 @@ impl<'text> SbsReader<'text, '_> { pub(super) fn read_graph(&mut self, element: XmlNode<'_, 'text>, name: String) -> Graph { let mut graph = Graph::new(&name); - let base = read_base_params(child_element(element, "baseParameters"), self.warnings); + let mut base = read_base_params(child_element(element, "baseParameters"), self.warnings); + use materialcraft_core::{GraphSizeOffset, SizeMode}; + graph.output_size_function = base.functions.remove(&BaseParameter::OutputSize); + match base.size_mode { + SizeMode::Absolute => graph.absolute_output_size = Some(base.size), + SizeMode::RelativeToParent => graph.relative_output_size = Some(GraphSizeOffset::Parent(base.size)), + SizeMode::RelativeToInput if base.size != [0; 2] => graph.relative_output_size = Some(GraphSizeOffset::Input(base.size)), + SizeMode::RelativeToInput => {} + } graph.format = if BaseParameter::Format.inheritance(&base) == ParameterInheritance::Absolute { base.format } else { OutputFormat::Inherit }; graph.seed = base.seed; + graph.seed_mode = base.seed_mode; + graph.seed_function = base.functions.remove(&BaseParameter::RandomSeed); graph.pixel_ratio = base.pixel_ratio; graph.pixel_ratio_mode = base.pixel_ratio_mode; graph.tiling = base.tiling; @@ -325,8 +335,12 @@ impl<'text> SbsReader<'text, '_> { continue; } - let default = exposed_default(code, child_element(input, "defaultValue").and_then(sbs_constant).as_ref()); - if child_value(input, "isConnectable") == Some("1") { + let default = exposed_default( + code, + child_element(input, "materialcraftDefault").or_else(|| child_element(input, "defaultValue")).and_then(sbs_constant).as_ref(), + ); + let connectable = child_value(input, "isConnectable") == Some("1"); + if connectable && !element.has_tag_name("function") { image_inputs.insert( child_value(input, "uid").unwrap_or("").to_string(), InputBridge { identifier: id, type_code: code as u32, usage: component_usage::read(input), default }, @@ -353,6 +367,7 @@ impl<'text> SbsReader<'text, '_> { label, group, default, + connectable, min, max, options: Vec::new(), @@ -470,6 +485,7 @@ impl<'text> SbsReader<'text, '_> { "compInputBridge" => { let entry = child_value(implementation, "entry").unwrap_or(""); let input = image_inputs.get(entry); + let identifier = input.map_or("input", |input| input.identifier.as_str()); let code = input.map_or(1, |input| input.type_code); let definition = match code { 1 => "input_color", @@ -477,9 +493,14 @@ impl<'text> SbsReader<'text, '_> { _ => "input_value", }; + if matches!(code, 1 | 2) + && let Some(url) = string_parameter(implementation, "bitmapresourcepath") + { + let resource = if url.is_empty() { None } else { self.resource_binding(url, &graph.name) }; + super::preview_binding::read_resource(graph, identifier, resource); + } let (id, index, node) = push_node(graph, definition, pos); if let Some(node) = node { - let identifier = input.map_or("input", |input| input.identifier.as_str()); node.params.insert("identifier".into(), Value::Text(identifier.to_string())); node.params.insert("usage".into(), Value::Enum(input.map_or(ComponentUsage::ANY_INDEX, |input| input.usage))); if let Some(input) = input { @@ -721,6 +742,16 @@ impl<'text> SbsReader<'text, '_> { } if let Some(&(_, mc_name)) = filter.params.iter().find(|(sbs, _)| *sbs == param_name) { + if filter.sbs == "grayscaleconversion" && mc_name == "weights" { + if let Some(weights) = value { + for (i, channel) in ["red", "green", "blue", "alpha"].into_iter().enumerate() { + node.params.insert(channel.into(), Value::Float(weights.float(i))); + } + } else { + self.set_param(node, mc_name, &Value::Float4([0.0; 4]), 0, *param, graph_name); + } + continue; + } let Some(param_def) = def.param(mc_name) else { continue }; self.set_param(node, mc_name, ¶m_def.default, param_def.options.len(), *param, graph_name); @@ -733,11 +764,6 @@ impl<'text> SbsReader<'text, '_> { node.params.insert("resource".into(), Value::Text(name)); } } - ("grayscaleconversion", "channelsweights", Some(weights)) => { - for (i, channel) in ["red", "green", "blue", "alpha"].into_iter().enumerate() { - node.params.insert(channel.into(), Value::Float(weights.float(i))); - } - } _ if HANDLED_PARAMS.contains(&(filter.sbs, param_name)) => {} _ => self.warnings.add(format!("`{}`: SBS parameter `{param_name}` is not supported yet and was ignored", filter.def)), } diff --git a/crates/formats/src/sbs/sbs_value.rs b/crates/formats/src/sbs/sbs_value.rs index 7d595dc4..e6be21d1 100644 --- a/crates/formats/src/sbs/sbs_value.rs +++ b/crates/formats/src/sbs/sbs_value.rs @@ -85,7 +85,16 @@ pub(super) fn exposed_type_code(value: &Value) -> i64 { materialcraft_core::ValueType::of(value).map_or(type_code::FLOAT1, |kind| i64::from(kind as u32)) } +pub(super) fn input_default_xml(value: &Value) -> Option { + // Graph input declarations use the one-lane tag to expose a scalar integer default. + constant_with_integer_tag(value, "constantValueInt1") +} + pub(super) fn constant_xml(value: &Value) -> Option { + constant_with_integer_tag(value, "constantValueInt32") +} + +fn constant_with_integer_tag(value: &Value, integer_tag: &str) -> Option { let join = |xs: &[f32]| xs.iter().map(|x| format_float(*x)).collect::>().join(" "); let (tag, text) = match value { Value::Float(x) => ("constantValueFloat1", format_float(*x)), @@ -93,11 +102,11 @@ pub(super) fn constant_xml(value: &Value) -> Option { Value::Float3(x) => ("constantValueFloat3", join(x)), Value::Float4(x) => ("constantValueFloat4", join(x)), Value::Color(c) => ("constantValueFloat4", join(c)), - Value::Int(i) => ("constantValueInt32", i.to_string()), + Value::Int(i) => (integer_tag, i.to_string()), Value::Int2(i) => ("constantValueInt2", format!("{} {}", i[0], i[1])), Value::Int3(i) => ("constantValueInt3", format!("{} {} {}", i[0], i[1], i[2])), Value::Int4(i) => ("constantValueInt4", format!("{} {} {} {}", i[0], i[1], i[2], i[3])), - Value::Enum(e) => ("constantValueInt32", e.to_string()), + Value::Enum(e) => (integer_tag, e.to_string()), Value::Bool(b) => ("constantValueBool", u8::from(*b).to_string()), Value::Text(s) => ("constantValueString", s.clone()), Value::Curve(_) | Value::Gradient(_) | Value::Function(_) | Value::PatternGraph(_) => return None, diff --git a/crates/formats/src/sbs/sbs_writer.rs b/crates/formats/src/sbs/sbs_writer.rs index 4cfad995..8985a613 100644 --- a/crates/formats/src/sbs/sbs_writer.rs +++ b/crates/formats/src/sbs/sbs_writer.rs @@ -5,13 +5,15 @@ use super::constant::NODE_HALF_SIZE; use super::filter_map::filter_by_def; use super::function_graph; use super::node_identifiers::NodeIdentifiers; -use super::node_parameter::{param_xml, special_filter_params_xml, text_param}; +use super::node_parameter::{param_xml, resource_parameter_xml, special_filter_params_xml, text_param}; use super::output::output_type; -use super::sbs_value::{constant_xml, exposed_type_code}; +use super::sbs_value::{constant_xml, exposed_type_code, input_default_xml}; use super::type_code; use super::xml::{format_float, is_parameters_element, xml_escape}; use crate::{FormatError, Result}; -use materialcraft_core::{ComponentUsage, Connection, Graph, MAX_SIZE_LOG2, MIN_SIZE_LOG2, MISSING_NODE, Node, NodeId, Package, Value, missing_ports}; +use materialcraft_core::{ + BaseParameter, ComponentUsage, Connection, Graph, MAX_SIZE_LOG2, MIN_SIZE_LOG2, MISSING_NODE, Node, NodeId, Package, Value, missing_ports, +}; use materialcraft_nodes::find; use std::collections::{BTreeMap, HashMap}; use std::fmt::Write as _; @@ -145,13 +147,21 @@ impl SbsWriter { out.push_str(""); let ids = NodeIdentifiers { input_entry: input_entries.get(&node.id).copied(), graph_output: output_uids.get(&node.id).copied(), self_uid }; - self.write_implementation(out, node, outputs, ids, pkg)?; + self.write_implementation(out, node, outputs, ids, graph, pkg)?; out.push_str(""); } out.push_str(""); - out.push_str(¶m_xml("randomseed", &Value::Int(graph.seed)).unwrap_or_default()); + let (size_mode, size) = graph.output_size_setting(); let base = materialcraft_core::BaseParameters { + size_mode, + size, + seed: graph.seed, + seed_mode: graph.seed_mode, + functions: [(BaseParameter::OutputSize, &graph.output_size_function), (BaseParameter::RandomSeed, &graph.seed_function)] + .into_iter() + .filter_map(|(parameter, function)| function.clone().map(|function| (parameter, function))) + .collect(), format: graph.format, format_mode: materialcraft_core::ParameterInheritance::Absolute, pixel_ratio: graph.pixel_ratio, @@ -195,7 +205,7 @@ impl SbsWriter { } else { value }; - let default = constant_xml(value).unwrap_or_default(); + let default = input_default_xml(value).unwrap_or_default(); let code = match node.def.as_str() { "input_value" => exposed_type_code(value), "input_grayscale" => type_code::GRAY_IMAGE, @@ -215,12 +225,14 @@ impl SbsWriter { for exposed in &graph.exposed { let uid = self.next_uid(); exposed_uids.insert(exposed.id.clone(), uid); - let default = constant_xml(&exposed.default).unwrap_or_else(|| "".into()); + let default = + input_default_xml(graph.inputs.get(&exposed.id).unwrap_or(&exposed.default)).unwrap_or_else(|| "".into()); let group = if exposed.group.is_empty() { String::new() } else { format!("", xml_escape(&exposed.group)) }; + let connection = if graph.function.is_some() && exposed.connectable { "" } else { "" }; let _ = write!( out, - "{default}", + "{connection}{default}", xml_escape(&exposed.id), uid, xml_escape(&exposed.label), @@ -229,6 +241,11 @@ impl SbsWriter { ); if let Some(current) = graph.inputs.get(&exposed.id).and_then(constant_xml) { let _ = write!(out, "{current}"); + // SBS consumers use the current value as the declared default. Retain the + // authored reset value separately for our project and portable-material round trip. + if let Some(authored) = input_default_xml(&exposed.default) { + let _ = write!(out, "{authored}"); + } } super::parameter_widget::write(out, exposed); let _ = write!(out, "{group}"); @@ -271,6 +288,7 @@ impl SbsWriter { node: &Node, outputs: &[(String, u32, u64)], ids: NodeIdentifiers, + graph: &Graph, package: &Package, ) -> Result<()> { // The reader assigns a native default when a processor omits format @@ -281,7 +299,14 @@ impl SbsWriter { let _ = write!(out, "", ids.graph_output.unwrap_or(0)); } "input_color" | "input_grayscale" | "input_value" => { - let _ = write!(out, "{base}", ids.input_entry.unwrap_or(0)); + let _ = write!(out, "{base}", ids.input_entry.unwrap_or(0)); + if node.def != "input_value" + && let Some(name) = graph.input_images.get(&text_param(node, "identifier", "input")) + && !name.is_empty() + { + out.push_str(&resource_parameter_xml("bitmapresourcepath", name, ids.self_uid, package)); + } + out.push_str(""); } "graph_instance" => { let sub_graph = node.instance.as_ref().map(|instance| instance.graph.clone()).unwrap_or_else(|| text_param(node, "graph", "")); @@ -339,7 +364,10 @@ impl SbsWriter { def => match (filter_by_def(def), find(def)) { (Some(filter), Some(catalog_def)) => { let _ = write!(out, "{base}", filter.sbs); - let value_of = |id: &str| node.params.get(id).or_else(|| catalog_def.param(id).map(|p| &p.default)); + let stored = |id: &str| node.params.get(id).or_else(|| catalog_def.param(id).map(|p| &p.default)); + let weights = (filter.sbs == "grayscaleconversion") + .then(|| Value::Float4(["red", "green", "blue", "alpha"].map(|id| stored(id).and_then(Value::as_f32).unwrap_or(0.0)))); + let value_of = |id: &str| stored(id).or_else(|| if id == "weights" { weights.as_ref() } else { None }); for (sbs_name, mc_name) in filter.params { let Some(value) = value_of(mc_name) else { continue }; @@ -379,7 +407,7 @@ impl SbsWriter { out.push_str(""); for parameter in ["curve", "gradient"] { if let Some(value) = value_of(parameter) { - out.push_str(&super::parameter_array::write(value, value_of("color_mode").and_then(Value::as_bool).unwrap_or(true), self)); + out.push_str(&super::parameter_array::write(value, self)); } } if let Some(Value::PatternGraph(graph)) = value_of("pattern") { diff --git a/crates/formats/src/sbs/tests.rs b/crates/formats/src/sbs/tests.rs index c1a66bb7..1e04ff27 100644 --- a/crates/formats/src/sbs/tests.rs +++ b/crates/formats/src/sbs/tests.rs @@ -8,6 +8,58 @@ fn no_linked_files(_: &str) -> Option> { None } +#[test] +fn connectable_function_argument_survives_save_and_reopen() { + let xml = br#" + + + + + "#; + let package = read_sbs(xml, "argument.sbs", &no_linked_files).unwrap().pkg; + let graph = &package.graphs[0]; + assert_eq!(graph.input_value("amount"), Some(&Value::Float(0.1875))); + let saved = write_sbs(&package).unwrap(); + let document = roxmltree::Document::parse(std::str::from_utf8(&saved).unwrap()).unwrap(); + let argument = document.descendants().find(|node| node.has_tag_name("paraminput")).unwrap(); + assert_eq!(super::xml::child_value(argument, "isConnectable"), Some("1")); + let reopened = read_sbs(&saved, "argument.sbs", &no_linked_files).unwrap().pkg; + assert_eq!(reopened.graphs[0].exposed, graph.exposed); +} + +#[test] +fn absolute_graph_output_size_survives_parent_size_changes_and_save() { + let xml = br#" + + + + "#; + let mut package = read_sbs(xml, "fixed.sbs", &no_linked_files).unwrap().pkg; + assert_eq!(package.graphs[0].size, [7, 8]); + assert_eq!(package.graphs[0].size_px(), [64, 32]); + package.graphs[0].size = [8, 7]; + let saved = write_sbs(&package).unwrap(); + let loaded = read_sbs(&saved, "fixed.sbs", &no_linked_files).unwrap().pkg; + assert_eq!(loaded.graphs[0].size, [8, 7]); + assert_eq!(loaded.graphs[0].size_px(), [64, 32]); +} + +#[test] +fn small_default_parent_sizes_round_trip_per_axis() { + for (width, height) in [(0, 0), (0, 3), (2, 0), (1, 1), (2, 3), (3, 3), (4, 2), (5, 4)] { + let xml = format!( + r#" + + "# + ); + let package = read_sbs(xml.as_bytes(), "small.sbs", &no_linked_files).unwrap().pkg; + assert_eq!(package.graphs[0].size, [width, height]); + let saved = write_sbs(&package).unwrap(); + let loaded = read_sbs(&saved, "small.sbs", &no_linked_files).unwrap().pkg; + assert_eq!(loaded.graphs[0].size_px(), [1 << width, 1 << height]); + } +} + #[test] fn shuffle_roundtrip_preserves_signed_channel_selectors() { for selector in [-2_i32, -1, 8, 9, 16, 255] { @@ -100,40 +152,66 @@ fn sniffs_sbs() { } #[test] -fn first_sbs_save_assigns_the_workspace_version_to_both_fields() { +fn first_sbs_save_declares_the_graph_schema_and_current_updater() { let unversioned = read_sbs(b"", "unversioned.sbs", &no_linked_files).unwrap().pkg; for package in [Package::new("New file"), unversioned] { assert!(package.format_version.is_none()); let text = String::from_utf8(write_sbs(&package).unwrap()).unwrap(); let document = roxmltree::Document::parse(&text).unwrap(); - for field in ["formatVersion", "updaterVersion"] { - assert_eq!(super::xml::child_value(document.root_element(), field), Some(env!("CARGO_PKG_VERSION"))); - } + assert_eq!(super::xml::child_value(document.root_element(), "formatVersion"), Some("1.1.0.202401")); + assert_eq!(super::xml::child_value(document.root_element(), "updaterVersion"), Some(env!("CARGO_PKG_VERSION"))); } } #[test] -fn later_sbs_saves_keep_the_original_format_version_and_refresh_the_updater() { - for baseline in ["0.0.7", "1.1.0.202401"] { +fn later_sbs_saves_upgrade_release_headers_and_keep_existing_schema_revisions() { + for (baseline, saved) in [("0.0.7", "1.1.0.202401"), ("0.1.3", "1.1.0.202401"), ("1.1.0.202401", "1.1.0.202401"), ("1.1.0.202502", "1.1.0.202502")] { let old = format!(r#""#); let mut package = read_sbs(old.as_bytes(), "older.sbs", &no_linked_files).unwrap().pkg; + assert_eq!(package.format_version.as_deref(), Some(baseline)); for _ in 0..3 { - assert_eq!(package.format_version.as_deref(), Some(baseline)); - // Snapshot/restore and subsequent saves must retain the baseline too package = serde_json::from_slice(&serde_json::to_vec(&package).unwrap()).unwrap(); let bytes = write_sbs(&package).unwrap(); let document = roxmltree::Document::parse(std::str::from_utf8(&bytes).unwrap()).unwrap(); - assert_eq!(super::xml::child_value(document.root_element(), "formatVersion"), Some(baseline)); + assert_eq!(super::xml::child_value(document.root_element(), "formatVersion"), Some(saved)); assert_eq!(super::xml::child_value(document.root_element(), "updaterVersion"), Some(env!("CARGO_PKG_VERSION"))); package = read_sbs(&bytes, "saved.sbs", &no_linked_files).unwrap().pkg; + assert_eq!(package.format_version.as_deref(), Some(saved)); } } } +#[test] +fn graph_inputs_write_one_lane_integer_defaults() { + let source = br#" + + + "#; + let mut pkg = read_sbs(source, "settings.sbs", &no_linked_files).unwrap().pkg; + let graph = &mut pkg.graphs[0]; + let mode = graph.exposed.iter_mut().find(|parameter| parameter.id == "mode").unwrap(); + mode.default = Value::Enum(37); + let input = graph.add_node("input_value", [0.0, 0.0]); + let node = graph.node_mut(input).unwrap(); + node.params.insert("identifier".into(), Value::Text("wire".into())); + node.params.insert("default".into(), Value::Int(16_777_217)); + let bytes = write_sbs(&pkg).unwrap(); + let doc = roxmltree::Document::parse(std::str::from_utf8(&bytes).unwrap()).unwrap(); + let defaults: Vec<_> = doc + .descendants() + .filter(|node| node.has_tag_name("paraminput")) + .map(|input| { + let default = super::xml::child_element(input, "defaultValue").unwrap().children().find(roxmltree::Node::is_element).unwrap(); + (super::xml::child_value(input, "identifier").unwrap(), default.tag_name().name(), default.attribute("v").unwrap()) + }) + .collect(); + assert_eq!(defaults, [("wire", "constantValueInt1", "16777217"), ("count", "constantValueInt1", "-3"), ("mode", "constantValueInt1", "37")]); +} + #[test] fn structural_round_trip() { let pkg = sample_package(); @@ -347,6 +425,40 @@ fn native_function_fixture_retains_operation_types_and_ports() { assert_eq!(function.nodes[2].inputs, vec![Some(function.nodes[0].id), Some(function.nodes[1].id)]); } +#[test] +fn distance_metric_survives_a_package_round_trip() { + let mut package = Package::new("Distances"); + let mut graph = Graph::new("Distances"); + for metric in [1, 2] { + let node = graph.add_node("distance", [0.0; 2]); + graph.node_mut(node).unwrap().params.insert("metric".into(), Value::Enum(metric)); + } + package.graphs.push(graph); + let bytes = write_sbs(&package).unwrap(); + let document = roxmltree::Document::parse(std::str::from_utf8(&bytes).unwrap()).unwrap(); + assert_eq!(document.descendants().filter(|n| n.has_tag_name("name") && n.attribute("v") == Some("distancemode")).count(), 2); + let read = read_sbs(&bytes, "distances.sbs", &no_linked_files).unwrap(); + let metrics: Vec<_> = read.pkg.graphs[0].nodes.iter().filter_map(|n| n.params.get("metric").and_then(Value::as_i32)).collect(); + assert_eq!(metrics, [1, 2]); +} + +#[test] +fn distance_preserves_declared_grayscale_and_color_outputs_when_the_switch_is_omitted() { + let xml = br#" + + + + + "#; + let loaded = read_sbs(xml, "distances.sbs", &no_linked_files).unwrap().pkg; + let saved = write_sbs(&loaded).unwrap(); + let again = read_sbs(&saved, "distances.sbs", &no_linked_files).unwrap().pkg; + for package in [&loaded, &again] { + let colors: Vec<_> = package.graphs[0].nodes.iter().filter_map(|node| node.params.get("color_mode").and_then(Value::as_bool)).collect(); + assert_eq!(colors, [true, false]); + } +} + #[test] fn image_output_types_follow_color_mode_and_blended_inputs() { let mut package = Package::new("Channels"); @@ -459,6 +571,94 @@ fn input_usage_defaults_and_unknown_metadata_stay_unclassified() { } } +#[test] +fn graph_seed_inheritance_survives_sbs_saving() { + for mode in [None, Some(0), Some(1), Some(2)] { + for seed in [0, 5, -3] { + if mode.is_none() && seed != 0 { + continue; + } + let parameter = mode.map_or_else(String::new, |mode| { + format!(r#""#) + }); + let xml = format!(r#"{parameter}"#); + let package = read_sbs(xml.as_bytes(), "field.sbs", &no_linked_files).unwrap().pkg; + let bytes = write_sbs(&package).unwrap(); + let text = std::str::from_utf8(&bytes).unwrap(); + let document = roxmltree::Document::parse(text).unwrap(); + let base = document.descendants().find(|n| n.has_tag_name("baseParameters")).unwrap(); + let saved = super::base_parameters::read_base_params(Some(base), &mut Default::default()); + use materialcraft_core::ParameterInheritance::{Absolute, RelativeToInput, RelativeToParent}; + let expected = match mode { + Some(0) => Absolute, + Some(1) => RelativeToParent, + _ => RelativeToInput, + }; + assert_eq!((saved.seed_mode, saved.seed), (expected, seed), "source {mode:?} {seed}"); + } + } +} + +#[test] +fn graph_seed_functions_round_trip_with_their_inheritance() { + use materialcraft_core::BaseParameter; + let xml = r#" + + + + "#; + let package = read_sbs(xml.as_bytes(), "seed.sbs", &no_linked_files).unwrap().pkg; + let saved = write_sbs(&package).unwrap(); + let document = roxmltree::Document::parse(std::str::from_utf8(&saved).unwrap()).unwrap(); + let element = document.descendants().find(|n| n.has_tag_name("baseParameters")).unwrap(); + let base = super::base_parameters::read_base_params(Some(element), &mut Default::default()); + assert_eq!(base.seed_mode, materialcraft_core::ParameterInheritance::RelativeToParent); + let function = base.functions.get(&BaseParameter::RandomSeed).expect("the saved seed has its authored function"); + assert_eq!(function.node(function.output.unwrap()).unwrap().value, Some(materialcraft_core::Value::Int(5))); + assert_eq!(read_sbs(&saved, "copy.sbs", &no_linked_files).unwrap().pkg.graphs[0].functions().count(), 1); +} + +#[test] +fn relative_graph_size_offsets_keep_their_axes_and_inheritance_on_save() { + for (mode, axes) in [(1, [-1, 1]), (2, [1, -1]), (1, [0, 0]), (2, [-6, 0])] { + let [x, y] = axes; + let xml = format!( + r#""# + ); + let pkg = read_sbs(xml.as_bytes(), "field.sbs", &no_linked_files).unwrap().pkg; + let saved = write_sbs(&pkg).unwrap(); + let doc = roxmltree::Document::parse(std::str::from_utf8(&saved).unwrap()).unwrap(); + let element = doc.descendants().find(|n| n.has_tag_name("baseParameters")).unwrap(); + let base = super::base_parameters::read_base_params(Some(element), &mut Default::default()); + let expected = if mode == 1 { materialcraft_core::SizeMode::RelativeToParent } else { materialcraft_core::SizeMode::RelativeToInput }; + assert_eq!((base.size_mode, base.size), (expected, axes)); + assert_eq!(read_sbs(&saved, "copy.sbs", &no_linked_files).unwrap().pkg.graphs[0].size_px(), pkg.graphs[0].size_px()); + } +} + +#[test] +fn computed_graph_output_sizes_round_trip_with_their_inheritance() { + use materialcraft_core::{BaseParameter, SizeMode, Value}; + for (raw, expected) in [(0, SizeMode::Absolute), (1, SizeMode::RelativeToParent), (2, SizeMode::RelativeToInput)] { + let xml = format!( + r#" + + + + "# + ); + let package = read_sbs(xml.as_bytes(), "dimensions.sbs", &no_linked_files).unwrap().pkg; + let saved = write_sbs(&package).unwrap(); + let document = roxmltree::Document::parse(std::str::from_utf8(&saved).unwrap()).unwrap(); + let element = document.descendants().find(|n| n.has_tag_name("baseParameters")).unwrap(); + let base = super::base_parameters::read_base_params(Some(element), &mut Default::default()); + let function = base.functions.get(&BaseParameter::OutputSize).expect("the saved size has its authored function"); + assert_eq!(base.size_mode, expected); + assert_eq!(function.node(function.output.unwrap()).unwrap().value, Some(Value::Int2([-1, 1]))); + assert_eq!(read_sbs(&saved, "copy.sbs", &no_linked_files).unwrap().pkg.graphs[0].functions().count(), 1); + } +} + #[test] fn published_material_preserves_disabled_nodes_and_localized_typed_interfaces() { use crate::material::{read_material, write_material}; diff --git a/crates/formats/src/sbs/write.rs b/crates/formats/src/sbs/write.rs index 12fc9d3a..90660230 100644 --- a/crates/formats/src/sbs/write.rs +++ b/crates/formats/src/sbs/write.rs @@ -6,15 +6,24 @@ use crate::Result; use materialcraft_core::Package; use std::collections::BTreeMap; +/// Schema revision to declare when writing a package, including packages with older app-release headers. +pub fn output_format_version(imported: Option<&str>) -> &str { + const SCHEMA: &str = "1.1.0.202401"; + let Some(version) = imported.filter(|v| !v.trim().is_empty()) else { return SCHEMA }; + // Earlier saves put the three-part app release in this field. Readers use it to select the XML grammar. + let mut parts = version.split('.'); + let is_release = (0..3).all(|_| parts.next().is_some_and(|p| !p.is_empty() && p.bytes().all(|c| c.is_ascii_digit()))) && parts.next().is_none(); + if is_release { SCHEMA } else { version } +} + pub fn write_sbs(pkg: &Package) -> Result> { - let format_version = pkg.format_version.as_deref().filter(|version| !version.trim().is_empty()).unwrap_or(UPDATER_VERSION); + let format_version = output_format_version(pkg.format_version.as_deref()); let mut writer = SbsWriter { last_uid: SELF_DEPENDENCY_UID, external_packages: BTreeMap::new() }; - let self_uid = SELF_DEPENDENCY_UID; let mut content = String::from(""); - super::group_layout::write(&mut content, pkg, &mut writer, self_uid)?; + super::group_layout::write(&mut content, pkg, &mut writer, SELF_DEPENDENCY_UID)?; content.push_str(""); - let dependencies = std::iter::once((SELF_DEPENDENCY, self_uid)).chain(writer.external_packages.iter().map(|(file, uid)| (file.as_str(), *uid))); + let dependencies = std::iter::once((SELF_DEPENDENCY, SELF_DEPENDENCY_UID)).chain(writer.external_packages.iter().map(|(file, uid)| (file.as_str(), *uid))); Ok(craft_sbs::write_package(&pkg.name, format_version, UPDATER_VERSION, dependencies, &content)) } diff --git a/crates/formats/src/sbs/xml.rs b/crates/formats/src/sbs/xml.rs index 0f18761b..37d91648 100644 --- a/crates/formats/src/sbs/xml.rs +++ b/crates/formats/src/sbs/xml.rs @@ -1,5 +1,13 @@ pub(super) use craft_sbs::xml::{child_element, child_value, children_named, format_float, is_parameters_element, parse_floats, xml_escape}; +use roxmltree::Node as XmlNode; + +pub(super) fn string_parameter<'a>(implementation: XmlNode<'a, '_>, name: &str) -> Option<&'a str> { + let parameters = child_element(implementation, "parameters")?; + let parameter = children_named(parameters, "parameter").find(|p| child_value(*p, "name") == Some(name))?; + child_value(child_element(parameter, "paramValue")?, "constantValueString") +} + #[cfg(test)] mod shared_escape_tests { use super::xml_escape; diff --git a/crates/formats/src/tests.rs b/crates/formats/src/tests.rs index ea4173fc..3914c2a4 100644 --- a/crates/formats/src/tests.rs +++ b/crates/formats/src/tests.rs @@ -2,6 +2,17 @@ use super::*; use craft_texture::{Image, Kind, srgb_to_linear}; use std::io::Cursor; +#[test] +fn bound_image_decoding_marks_normalized_linear_channels() { + let mut gray = Cursor::new(Vec::new()); + ::image::GrayImage::from_pixel(2, 2, ::image::Luma([128])).write_to(&mut gray, ::image::ImageFormat::Png).unwrap(); + assert!(decode(gray.get_ref(), false).unwrap().integer_sampling()); + let mut color = Cursor::new(Vec::new()); + ::image::RgbImage::from_pixel(2, 2, ::image::Rgb([128, 64, 32])).write_to(&mut color, ::image::ImageFormat::Png).unwrap(); + assert!(decode(color.get_ref(), true).unwrap().integer_sampling()); + assert!(!decode(color.get_ref(), false).unwrap().integer_sampling()); +} + #[test] fn export_every_format() { let img = Image::generate(8, 8, Kind::Color, |x, y| [x as f32 / 7.0, y as f32 / 7.0, 0.5, 1.0]); diff --git a/crates/formats/tests/bitmap_imports.rs b/crates/formats/tests/bitmap_imports.rs index bc8e86d0..4db14c20 100644 --- a/crates/formats/tests/bitmap_imports.rs +++ b/crates/formats/tests/bitmap_imports.rs @@ -2,6 +2,23 @@ use craft_texture::{Image, Kind}; use materialcraft_formats::{BITMAP_EXTENSIONS, BITMAP_FORMATS, Depth, decode, encode}; use std::io::Cursor; +#[test] +fn grayscale_png_file_gamma_uses_the_measured_word_boundaries() { + let words = [1136, 3683, 4236]; + let field = Image::gray(3, 1, |x, _| words[x as usize] as f32 / 65535.0); + let plain = encode(&field, "png", Depth::U16, false).unwrap(); + for (gamma, crc, expected) in + [(43_181u32, 0x459c_89f9u32, [918, 3165, 3667]), (43_182, 0xdc95_d843, words), (47_847, 0xab61_51a4, words), (47_848, 0x3bde_4c35, [1391, 4253, 4858])] + { + let mut bytes = plain.clone(); + let chunk = [4u32.to_be_bytes(), *b"gAMA", gamma.to_be_bytes(), crc.to_be_bytes()].concat(); + bytes.splice(33..33, chunk); + let image = materialcraft_formats::decode_with_color_space(&bytes, materialcraft_nodes::BitmapColorSpace::FromFile).unwrap(); + let stored: Vec<_> = image.data().iter().map(|v| (v * 65535.0).round() as u16).collect(); + assert_eq!(stored, expected, "file gamma {gamma}"); + } +} + #[test] fn bitmap_filters_are_specific_and_match_supported_extensions() { let extensions: std::collections::BTreeSet<_> = BITMAP_FORMATS.iter().flat_map(|(_, extensions)| extensions.iter().copied()).collect(); @@ -16,6 +33,25 @@ fn bitmap_filters_are_specific_and_match_supported_extensions() { assert_eq!(materialcraft_formats::VECTOR_FORMATS[0], ("All formats", materialcraft_formats::VECTOR_EXTENSIONS)); } +#[test] +fn luminance_exr_preserves_linear_signed_and_hdr_samples() { + use craft_image_codecs::{ChannelLayout, EncodeOptions, Format, SampleType}; + for sample in [SampleType::F16, SampleType::F32] { + for layout in [ChannelLayout::Gray, ChannelLayout::GrayA] { + let values = [-0.25, 0.0, 0.5, 3.0]; + let input: Vec<_> = if layout == ChannelLayout::GrayA { values.into_iter().flat_map(|y| [y, 0.375]).collect() } else { values.to_vec() }; + let source = craft_image_codecs::Image::from_normalized(4, 1, layout, sample, &input).unwrap(); + let encoded = craft_image_codecs::encode(&source, Format::OpenExr, &EncodeOptions::default()).unwrap(); + for linear in [false, true] { + let image = decode(&encoded, linear).unwrap(); + assert!(image.is_gray()); + assert_eq!(image.data(), values); + assert!(!image.integer_sampling()); + } + } + } +} + #[test] fn common_bitmap_formats_decode() { let pixels = Image::filled(4, 4, Kind::Color, [0.25, 0.5, 0.75, 1.0]); diff --git a/crates/formats/tests/curve_tables.rs b/crates/formats/tests/curve_tables.rs new file mode 100644 index 00000000..5e8ecbaa --- /dev/null +++ b/crates/formats/tests/curve_tables.rs @@ -0,0 +1,77 @@ +use craft_texture::Image; +use materialcraft_core::{OutputFormat, Value}; +use materialcraft_formats::sbs::{read_sbs, write_sbs}; +use materialcraft_nodes::{CookContext, find, resolve_params}; +use std::collections::BTreeMap; + +fn curve_package(cells: impl IntoIterator) -> String { + let cells: String = cells.into_iter().collect(); + format!( + r#" + {cells} + "# + ) +} + +fn cell(position: [f32; 2], left: [f32; 2], right: [f32; 2], flags: [bool; 3]) -> String { + let mut parameters = String::new(); + for (name, [x, y]) in [("position", position), ("left", left), ("right", right)] { + parameters.push_str(&format!(r#""#)); + } + for (name, flag) in ["isLeftBroken", "isRightBroken", "isLocked"].into_iter().zip(flags) { + parameters.push_str(&format!(r#""#, u8::from(flag))); + } + format!("{parameters}") +} + +#[test] +fn curve_tables_preserve_dormant_handles_and_their_flags_on_save() { + let xml = curve_package([ + cell([0.0, 0.0625], [0.0, 0.0625], [0.1875, -0.25], [false, true, true]), + cell([1.0, 0.8125], [0.578125, 0.9375], [1.0, 0.8125], [false; 3]), + ]); + let mut bytes = xml.into_bytes(); + for _ in 0..2 { + let package = read_sbs(&bytes, "curve.sbs", &|_| None).unwrap().pkg; + let Value::Curve(curve) = &package.graphs[0].nodes[0].params["curve"] else { panic!("missing curve") }; + assert_eq!(curve.points[0].right, Some([0.1875, -0.25])); + assert_eq!(curve.segment(0).unwrap(), [[0.0, 0.0625], [0.0, 0.0625], [0.578125, 0.9375], [1.0, 0.8125]]); + bytes = write_sbs(&package).unwrap(); + let doc = roxmltree::Document::parse(std::str::from_utf8(&bytes).unwrap()).unwrap(); + let flags: Vec<_> = doc + .descendants() + .filter(|n| n.has_tag_name("constantValueBool")) + .filter_map(|n| { + let name = n.parent()?.parent()?.children().find(|c| c.has_tag_name("name"))?.attribute("v")?; + matches!(name, "isLeftBroken" | "isRightBroken" | "isLocked").then_some((name, n.attribute("v")?)) + }) + .collect(); + assert_eq!(flags, [("isLeftBroken", "0"), ("isRightBroken", "1"), ("isLocked", "1"), ("isLeftBroken", "0"), ("isRightBroken", "0"), ("isLocked", "0")]); + } +} + +#[test] +fn curve_tables_sample_each_segment_even_when_anchors_share_a_texel() { + let points = [[0.0, 0.75], [0.41031, 0.25], [0.41036, 1.125], [0.4104, -0.0625], [1.0, 0.875]]; + let xml = curve_package(points.map(|[x, y]| cell([x, y], [x - 0.03125, y], [x + 0.046875, y], [true, true, false]))); + let package = read_sbs(xml.as_bytes(), "curve.sbs", &|_| None).unwrap().pkg; + let definition = find("curve").unwrap(); + let params = resolve_params(definition, &package.graphs[0].nodes[0].params); + let values = [0x3ed2348d, 0x3ed2b4ad, 0x3ed334cd, 0x3e1779c3, 0x3e931d48]; + let inputs = [Some(Image::gray(5, 1, |x, _| f32::from_bits(values[x as usize])))]; + let vars = BTreeMap::new(); + let context = CookContext { + w: 5, + h: 1, + seed: 0, + format: OutputFormat::F32, + input_formats: &[OutputFormat::F32], + tile: true, + inputs: &inputs, + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + let image = (definition.cook)(&context).unwrap().remove(0); + assert_eq!(image.data().iter().map(|x| x.to_bits()).collect::>(), [0x3e800000, 0x41ad6dd8, 0xc27b1ba9, 0x3f11da69, 0x3eccba50]); +} diff --git a/crates/formats/tests/function_library.rs b/crates/formats/tests/function_library.rs index 22abca8a..e695c78b 100644 --- a/crates/formats/tests/function_library.rs +++ b/crates/formats/tests/function_library.rs @@ -181,6 +181,43 @@ fn assert_same_body(source: &materialcraft_core::Graph, converted: &materialcraf } } +#[test] +fn bundled_vector_equality_compares_each_lane() { + use materialcraft_core::Value; + use materialcraft_nodes::function::{EvaluationContext, EvaluationState, FunctionScope, compile, resolve_instances}; + use std::collections::BTreeMap; + + let bytes = materialcraft_formats::sbs::library::read("sbs://functions.sbs").unwrap(); + let package = read_sbs(&bytes, "functions.sbs", &|_| None).unwrap().pkg; + for width in [3, 4] { + let name = format!("Equality_Float{width}"); + let mut graph = package.graph_by_name(&name).unwrap().1.function.clone().unwrap(); + resolve_instances(&mut graph, &package, &package.dependencies); + let program = compile(&graph, 0).unwrap(); + let vector = |[r, g, b, a]: [f32; 4]| if width == 3 { Value::Float3([r, g, b]) } else { Value::Float4([r, g, b, a]) }; + let original = [0.25, -0.375, 1.0, 2.0]; + for mask in 0..1 << width { + let mut changed = original; + for (lane, value) in changed.iter_mut().take(width).enumerate() { + if mask & (1 << lane) != 0 { + *value += 0.125; + } + } + let variables = BTreeMap::from([("A".into(), vector(original)), ("B".into(), vector(changed))]); + let context = EvaluationContext { + scope: FunctionScope::PixelProcessor, + variables: &variables, + position: [0.5; 2], + size: [1.0; 2], + images: &[], + image_formats: &[], + tile: true, + }; + assert_eq!(program.evaluate(&context, &mut EvaluationState::default()).unwrap(), Value::Bool(mask == 0), "{name} mask {mask}"); + } + } +} + #[test] fn bundled_library_has_complete_bodies_and_current_export_metadata() { let bytes = include_bytes!("../../../assets/sbs/functions.sbs"); diff --git a/crates/formats/tests/gradient_values.rs b/crates/formats/tests/gradient_values.rs index 14186adc..8b68c134 100644 --- a/crates/formats/tests/gradient_values.rs +++ b/crates/formats/tests/gradient_values.rs @@ -51,7 +51,31 @@ fn native_gradient_default_midpoints_are_linear_and_components_are_preserved() { assert!((gradient.eval(0.5)[3] - if color { 0.4 } else { 1.0 }).abs() < 1e-6); let saved = write_sbs(&read.pkg).unwrap(); + let xml = std::str::from_utf8(&saved).unwrap(); + assert!(xml.contains(r#""#)); + assert_eq!(xml.matches(" + + + + + + + "#; + let mut read = read_sbs(xml, "ramp.sbs", &|_| None).unwrap(); + for _ in 0..2 { + let params = &read.pkg.graphs[0].nodes[0].params; + assert_eq!(params["interpolation"].as_i32(), Some(1)); + let Value::Gradient(gradient) = ¶ms["gradient"] else { panic!("missing gradient") }; + assert_eq!(gradient.keys[0].midpoint, 0.3125); + let saved = write_sbs(&read.pkg).unwrap(); + read = read_sbs(&saved, "ramp.sbs", &|_| None).unwrap(); + } +} diff --git a/crates/formats/tests/library_native_ports.rs b/crates/formats/tests/library_native_ports.rs index 18055845..14146b2a 100644 --- a/crates/formats/tests/library_native_ports.rs +++ b/crates/formats/tests/library_native_ports.rs @@ -1,5 +1,42 @@ use materialcraft_formats::sbs::{read_sbs, write_sbs}; +#[test] +fn grayscale_channel_weights_round_trip_as_one_function() { + use materialcraft_core::Value; + let xml = br#" + + + + + + "#; + let mut read = read_sbs(xml, "weights.sbs", &|_| None).unwrap(); + for _ in 0..2 { + assert!(read.warnings.is_empty(), "{:?}", read.warnings); + let node = &read.pkg.graphs[0].nodes[0]; + assert_eq!(node.functions.len(), 1); + assert_eq!(node.functions["weights"].nodes[0].value, Some(Value::Float4([0.125, 0.25, 0.5, 0.125]))); + let saved = write_sbs(&read.pkg).unwrap(); + assert_eq!(std::str::from_utf8(&saved).unwrap().matches(r#""#).count(), 1); + read = read_sbs(&saved, "saved.sbs", &|_| None).unwrap(); + } +} + +#[test] +fn levels_preserves_the_unclamped_input_range_on_save() { + let xml = br#" + + + "#; + let mut read = read_sbs(xml, "range.sbs", &|_| None).unwrap(); + for _ in 0..2 { + assert!(read.warnings.is_empty(), "{:?}", read.warnings); + assert_eq!(read.pkg.graphs[0].nodes[0].params["clamp_intermediate"].as_bool(), Some(false)); + let saved = write_sbs(&read.pkg).unwrap(); + read = read_sbs(&saved, "saved.sbs", &|_| None).unwrap(); + } +} + #[test] fn fx_map_render_and_tiling_regions_keep_native_names_and_functions() { use materialcraft_core::Value; @@ -9,6 +46,7 @@ fn fx_map_render_and_tiling_regions_keep_native_names_and_functions() { + "#; let mut read = read_sbs(xml, "regions.sbs", &|_| None).unwrap(); for _ in 0..2 { @@ -16,12 +54,14 @@ fn fx_map_render_and_tiling_regions_keep_native_names_and_functions() { let node = &read.pkg.graphs[0].nodes[0]; + assert_eq!(node.params["cull_outside"], Value::Bool(true)); assert_eq!(node.params["tiling_region"], Value::Float4([0.0, 2.0, 0.0, 1.0])); assert_eq!(node.functions["render_region"].nodes[0].value, Some(Value::Float4([0.0, 0.5, 0.0, 1.0]))); let bytes = write_sbs(&read.pkg).unwrap(); let saved = std::str::from_utf8(&bytes).unwrap(); + assert!(saved.contains("")); assert!(saved.contains("") && saved.contains("")); read = read_sbs(&bytes, "saved.sbs", &|_| None).unwrap(); @@ -122,3 +162,36 @@ fn native_pattern_inputs_and_hsl_luminosity_round_trip() { assert_eq!(legacy.pkg.graphs[0].connections.len(), 1); assert_eq!(legacy.pkg.graphs[0].nodes.iter().find(|node| node.def == "hsl").unwrap().params["lightness"], materialcraft_core::Value::Float(0.75)); } +#[test] +fn warp_filtering_round_trips_as_a_boolean() { + let xml = br#" + + + "#; + let mut read = read_sbs(xml, "warp.sbs", &|_| None).unwrap(); + for _ in 0..2 { + assert!(read.warnings.is_empty(), "{:?}", read.warnings); + assert_eq!(read.pkg.graphs[0].nodes[0].params.get("nearest"), Some(&materialcraft_core::Value::Bool(true))); + let bytes = write_sbs(&read.pkg).unwrap(); + assert!(std::str::from_utf8(&bytes).unwrap().contains("")); + read = read_sbs(&bytes, "saved.sbs", &|_| None).unwrap(); + } +} + +#[test] +fn transform_mip_settings_survive_sbs_round_trip() { + let xml = br#" + + + + "#; + let mut read = read_sbs(xml, "mip.sbs", &|_| None).unwrap(); + for _ in 0..2 { + assert!(read.warnings.is_empty(), "{:?}", read.warnings); + let params = &read.pkg.graphs[0].nodes[0].params; + assert_eq!(params.get("mip_mode"), Some(&materialcraft_core::Value::Enum(1))); + assert_eq!(params.get("mip_level"), Some(&materialcraft_core::Value::Int(3))); + let bytes = write_sbs(&read.pkg).unwrap(); + read = read_sbs(&bytes, "saved.sbs", &|_| None).unwrap(); + } +} diff --git a/crates/nodes/Cargo.toml b/crates/nodes/Cargo.toml index daf743ef..809ef653 100644 --- a/crates/nodes/Cargo.toml +++ b/crates/nodes/Cargo.toml @@ -10,5 +10,12 @@ workspace = true [dependencies] materialcraft-core = { workspace = true } +craft-font-catalog = { workspace = true } craft-texture = { workspace = true } +harfrust = { workspace = true } +read-fonts = { workspace = true } +unicode-bidi = { workspace = true } +vello_common = { workspace = true } +half = { workspace = true } rayon = { workspace = true } +serde_json = { workspace = true } diff --git a/crates/nodes/examples/filter_timing.rs b/crates/nodes/examples/filter_timing.rs index 6d5a7ad5..3a50b80c 100644 --- a/crates/nodes/examples/filter_timing.rs +++ b/crates/nodes/examples/filter_timing.rs @@ -19,6 +19,7 @@ fn main() -> Result<(), String> { let resource = |_: &str| None; let vars = BTreeMap::new(); let context = CookContext { + input_formats: &[], w: side, h: side, seed: 0, diff --git a/crates/nodes/src/atomic/bitmap.rs b/crates/nodes/src/atomic/bitmap.rs index ab07409f..268231a9 100644 --- a/crates/nodes/src/atomic/bitmap.rs +++ b/crates/nodes/src/atomic/bitmap.rs @@ -1,5 +1,7 @@ use super::ATOMIC; use crate::{CookContext, CookResult, NodeDefinition, node}; +use craft_texture::Kind; +use materialcraft_core::OutputFormat; pub(super) fn definition() -> NodeDefinition { node("bitmap", "Bitmap", ATOMIC) @@ -7,7 +9,7 @@ pub(super) fn definition() -> NodeDefinition { .atomic() .generator() .resource("resource", "Bitmap resource") - .choice("colour_space", "Color space", &["sRGB", "Linear"], 0) + .choice("colour_space", "Color space", &["sRGB", "Linear", "From file"], 2) .boolean("color_mode", "Color output", true) .any_out() .cook(bitmap) @@ -15,7 +17,17 @@ pub(super) fn definition() -> NodeDefinition { fn bitmap(context: &CookContext) -> CookResult { let name = context.text("resource"); - let image = match (context.resource)(&craft_texture::resource_key(name, context.i("colour_space") == 1)) { + let color = context.b("color_mode"); + let image = match context.bitmap_resource(name) { + Some(image) + if image.integer_sampling() + && ((image.width(), image.height()) != (context.w, context.h) || (!color && image.kind() == Kind::Color)) + && [image.width(), image.height(), context.w, context.h].into_iter().all(u32::is_power_of_two) => + { + // The first filtered level converts RGB to its channel mean before storing it. + let kind = if color { image.kind() } else { Kind::Gray }; + crate::resize_bound_image(image, (context.w, context.h), kind, OutputFormat::U16, context.format, [false; 2]) + } Some(image) => image.resize(context.w, context.h, context.tile), None if name.is_empty() => context.gen_color(|u, v| { let c = if ((u * 8.0) as i32 + (v * 8.0) as i32) % 2 == 0 { 0.8 } else { 0.2 }; @@ -24,5 +36,5 @@ fn bitmap(context: &CookContext) -> CookResult { None => return Err(format!("no bitmap resource `{name}`")), }; - Ok(vec![if context.b("color_mode") { image.to_color() } else { image.to_gray() }]) + Ok(vec![if color { image.to_color() } else { image.to_gray() }]) } diff --git a/crates/nodes/src/atomic/blend.rs b/crates/nodes/src/atomic/blend.rs index 3437fdb2..2c82d605 100644 --- a/crates/nodes/src/atomic/blend.rs +++ b/crates/nodes/src/atomic/blend.rs @@ -1,8 +1,10 @@ use super::ATOMIC; +use super::input_resize::{InputResize, converted_color, resized_input}; use crate::ops; use crate::ops::BLEND_MODES; use crate::{CookContext, CookResult, NodeDefinition, node}; use craft_texture::{Image, Kind}; +use materialcraft_core::OutputFormat; pub(super) fn definition() -> NodeDefinition { node("blend", "Blend", ATOMIC) @@ -20,13 +22,62 @@ pub(super) fn definition() -> NodeDefinition { .cook(blend) } +/// The texture a fully weighted, unmasked Blend selects before size or depth conversion. +pub fn blend_selected_input(context: &CookContext) -> Option { + let mode = context.i("mode"); + let opacity = context.f("opacity"); + if context.input(2).is_some() || !(0..=8).contains(&mode) { + return None; + } + if opacity <= 0.0 { + Some(1) + } else if opacity >= 1.0 && (mode == 7 || (mode == 0 && context.input(0).is_some_and(Image::is_gray))) { + Some(0) + } else { + None + } +} + +fn selected_float_color(context: &CookContext, port: usize, dynamic_opacity: bool) -> Option { + let image = context.input(port)?; + let source = context.input_formats.get(port).copied().unwrap_or(if image.integer_sampling() { OutputFormat::U16 } else { OutputFormat::F32 }); + if image.is_gray() + || (image.width(), image.height()) != (context.w, context.h) + || !matches!(source, OutputFormat::F16 | OutputFormat::F32) + || !matches!(context.format, OutputFormat::F16 | OutputFormat::F32) + { + return None; + } + // Fixed opacity can forward the selected texture. A bound opacity still runs the color conversion at either endpoint. + Some(if source == context.format && !dynamic_opacity { + image.clone() + } else { + image.map(Kind::Color, |pixel| converted_color(pixel.map(crate::function::flush_subnormal))) + }) +} + fn blend(context: &CookContext) -> CookResult { - let (foreground, background) = (context.sized(0), context.sized(1)); + blend_with_opacity(context, false) +} + +/// Cook with the resolved opacity and whether its expression reads an exposed graph parameter. +pub fn blend_with_opacity(context: &CookContext, dynamic_opacity: bool) -> CookResult { + let (mode, opacity) = (context.i("mode"), context.f("opacity")); + // Stored graphs can compute an opacity outside the slider range. Bound it before applying the mask. + let opacity = if (0..=8).contains(&mode) { opacity.clamp(0.0, 1.0) } else { opacity }; + let selected = blend_selected_input(context); + if mode == 7 + && let Some(image) = selected.and_then(|port| selected_float_color(context, port, dynamic_opacity)) + { + return Ok(vec![image]); + } + let copies_foreground = selected == Some(0); + let foreground = resized_input(context, 0, if copies_foreground { InputResize::Copy } else { InputResize::Filter }); + let background = resized_input(context, 1, if opacity == 0.0 { InputResize::Copy } else { InputResize::Filter }); let kind = if [&foreground, &background].iter().any(|i| i.as_ref().is_some_and(|i| !i.is_gray())) { Kind::Color } else { Kind::Gray }; let foreground = foreground.unwrap_or_else(|| Image::filled(context.w, context.h, kind, [0.0, 0.0, 0.0, 0.0])); let background = background.unwrap_or_else(|| Image::filled(context.w, context.h, kind, [0.0, 0.0, 0.0, 1.0])); - let mask = context.sized(2).map(|m| m.to_gray()); - let (mode, opacity) = (context.i("mode"), context.f("opacity")); + let mask = resized_input(context, 2, InputResize::Filter).map(|m| m.to_gray()); let color_blending = context.i("color_blending"); let blend_alpha = context.b("alpha") && !foreground.is_gray(); let clamp = @@ -34,6 +85,201 @@ fn blend(context: &CookContext) -> CookResult { Ok(vec![Image::generate(context.w, context.h, kind, |x, y| { 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, 3 | 7 | 8) || (matches!(mode, 4..=6) && color_blending != 2) { + 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) })]) } + +#[cfg(test)] +mod tests { + use super::*; + use crate::resolve_params; + use materialcraft_core::{OutputFormat, Value}; + use std::collections::BTreeMap; + + #[test] + fn switch_endpoints_copy_signed_zero_at_the_selected_color_precision() { + use OutputFormat::{F16, F32}; + let small = -2.0_f32.powi(-27); + let pixels = [[0.5, -0.0, -0.25, -0.0], [-0.0, -0.5, -0.25, 0.5], [small, 0.5, 0.25, -0.0]]; + let field = Image::generate(3, 1, Kind::Color, |x, _| pixels[x as usize]); + let other = Image::filled(3, 1, Kind::Color, [-0.5, -1.0, 1.0, 0.5]); + for (source, target) in [(F32, F32), (F16, F32), (F32, F16), (F16, F16)] { + let selected = crate::output_precision::apply(field.clone(), source); + for (slot, opacity) in [(0, 1.0), (1, 0.0)] { + let mut inputs = [Some(other.clone()), Some(other.clone()), None]; + inputs[slot] = Some(selected.clone()); + let mut formats = [F32; 3]; + formats[slot] = source; + let params = resolve_params(&definition(), &BTreeMap::from([("mode".into(), Value::Enum(7)), ("opacity".into(), Value::Float(opacity))])); + let vars = BTreeMap::new(); + let context = CookContext { + w: 3, + h: 1, + seed: 0, + tile: true, + input_formats: &formats, + format: target, + inputs: &inputs, + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + let result = crate::output_precision::apply(blend(&context).unwrap().remove(0), target); + let same = source == target; + let zero = if same { -0.0_f32 } else { 0.0 }; + let tiny = match (source, target) { + (F32, F32) => small, + (F16, F32) => 0.0, + _ => -0.0, + }; + for (i, expected) in [[0.5, zero, -0.25, zero], pixels[1], [tiny, 0.5, 0.25, zero]].into_iter().enumerate() { + assert_eq!( + result.get(i as i64, 0, false).map(f32::to_bits), + expected.map(f32::to_bits), + "{source:?} to {target:?}, input {slot}, pixel {i}" + ); + } + } + } + } + + #[test] + fn switch_converts_subnormal_inputs_at_the_color_operation() { + let background = [0x0000_0000, 0xbfd3_82af, 0xbf69_87c4, 0x3f80_0000].map(f32::from_bits); + for (opacity, target, bits, expected) in [ + (1.0, OutputFormat::F16, [0xb180_0000, 0x3f80_0000, 0x8000_0001, 0x3b03_86a1], [0x8000_0000, 0x3f80_0000, 0, 0x3b03_8000]), + (0.6137, OutputFormat::F32, [0x8000_0001, 0x3b03_86a1, 0xbf69_87c4, 0x8000_0000], [0, 0xbf23_1903, 0xbf69_87c4, 0x3ec5_c91e]), + ] { + let inputs = [Some(Image::filled(1, 1, Kind::Color, bits.map(f32::from_bits))), Some(Image::filled(1, 1, Kind::Color, background)), None]; + let params = resolve_params(&definition(), &BTreeMap::from([("mode".into(), Value::Enum(7)), ("opacity".into(), Value::Float(opacity))])); + let vars = BTreeMap::new(); + let context = CookContext { + w: 1, + h: 1, + seed: 0, + tile: true, + input_formats: &[OutputFormat::F32; 3], + format: target, + inputs: &inputs, + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + let result = crate::output_precision::apply(blend(&context).unwrap().remove(0), target); + assert_eq!(result.get(0, 0, false).map(f32::to_bits), expected, "opacity {opacity}, {target:?}"); + } + } + + #[test] + fn add_sub_limits_global_opacity_before_blending() { + let mut inputs = [ + Some(Image::gray(2, 1, |x, _| if x == 0 { 35_122.0 / 65_535.0 } else { 32_767.0 / 65_535.0 })), + Some(Image::gray(2, 1, |_, _| 32_767.0 / 65_535.0)), + None, + ]; + let vars = BTreeMap::new(); + for (opacity, masked, expected) in [(6.000_000_5, false, [37_476, 32_766]), (-0.5, false, [32_767, 32_767]), (6.000_000_5, true, [34_115, 32_767])] { + inputs[2] = masked.then(|| Image::gray(2, 1, |x, _| if x == 0 { 73.0 / 255.0 } else { 126.0 / 255.0 })); + let params = resolve_params(&definition(), &BTreeMap::from([("mode".into(), Value::Enum(4)), ("opacity".into(), Value::Float(opacity))])); + let context = CookContext { + w: 2, + h: 1, + seed: 0, + tile: true, + input_formats: &[OutputFormat::U16, OutputFormat::U16, OutputFormat::F32], + format: OutputFormat::U16, + inputs: &inputs, + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + let image = crate::output_precision::apply(blend(&context).unwrap().remove(0), OutputFormat::U16); + assert_eq!([0, 1].map(|x| (image.get_gray(x, 0, false) * 65_535.0).round() as u16), expected); + } + } + + #[test] + fn blend_resizes_connected_images_through_stored_levels() { + for (port, source, format, expected) in [ + (0, OutputFormat::U16, OutputFormat::U16, [26_112.0 / 65_535.0, 42_495.0 / 65_535.0]), + (1, OutputFormat::U16, OutputFormat::F16, [0.3984375, f32::from_bits(0x3f25e000)]), + (2, OutputFormat::F32, OutputFormat::U8, [102.0 / 255.0, 165.0 / 255.0]), + ] { + let mut inputs = [Some(Image::filled(16, 16, Kind::Gray, [1.0; 4])), Some(Image::filled(16, 16, Kind::Gray, [0.0; 4])), None]; + let field = Image::gray(2, 2, |x, y| [0.0, 0.25, 0.75, 1.0][(2 * y + x) as usize]); + inputs[port] = Some(crate::output_precision::apply(field, source)); + let params = resolve_params(&definition(), &BTreeMap::from([("opacity".into(), Value::Float(if port == 1 { 0.0 } else { 1.0 }))])); + let vars = BTreeMap::new(); + let context = CookContext { + w: 16, + h: 16, + seed: 317, + tile: true, + input_formats: &[source; 3], + format, + inputs: &inputs, + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + let result = crate::output_precision::apply(blend(&context).unwrap().remove(0), format); + assert_eq!([result.get(2, 7, false)[0], result.get(6, 12, false)[0]], expected, "input {port}"); + } + } + + #[test] + fn blend_rounds_mask_color_and_coverage_independently() { + let foreground = [116.0, 38.0, 60.0, 36.0].map(|v| v / 255.0); + let background = [158.0, 163.0, 10.0, 68.0].map(|v| v / 255.0); + let mask = 44.0 / 255.0; + for (mode, interpretation, opacity, alpha, hdr, expected) in [ + (0, 0, 1.0, true, false, [0x3f1d97ad, 0x3f209511, 0x3d343117, 0x3e91adfe]), + (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]), + ] { + let level = |v: f32| if hdr { v * 3.0 - 1.0 } else { v }; + let inputs = [ + Some(Image::filled(1, 1, Kind::Color, foreground.map(level))), + Some(Image::filled(1, 1, Kind::Color, background.map(level))), + Some(Image::gray(1, 1, |_, _| level(mask))), + ]; + let vars = BTreeMap::new(); + let params = resolve_params( + &definition(), + &BTreeMap::from([ + ("mode".into(), Value::Enum(mode)), + ("color_blending".into(), Value::Enum(interpretation)), + ("opacity".into(), Value::Float(opacity)), + ("alpha".into(), Value::Bool(alpha)), + ]), + ); + let context = CookContext { + input_formats: &[], + format: OutputFormat::F32, + w: 1, + h: 1, + seed: 0, + tile: true, + inputs: &inputs, + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + let result = blend(&context).unwrap(); + assert_eq!(result[0].get(0, 0, false).map(f32::to_bits), expected, "mode {mode}, interpretation {interpretation}, opacity {opacity}"); + } + } +} diff --git a/crates/nodes/src/atomic/blur.rs b/crates/nodes/src/atomic/blur.rs index 9691914d..db02330e 100644 --- a/crates/nodes/src/atomic/blur.rs +++ b/crates/nodes/src/atomic/blur.rs @@ -1,6 +1,7 @@ -use super::{ATOMIC, box_filter}; +use super::{ATOMIC, box_filter, input_resize}; use crate::{CookContext, CookResult, NodeDefinition, node}; -use craft_texture::Kind; +use craft_texture::Image; +use materialcraft_core::Value; pub(super) fn definition() -> NodeDefinition { node("blur", "Blur", ATOMIC) @@ -13,10 +14,33 @@ pub(super) fn definition() -> NodeDefinition { } fn blur(context: &CookContext) -> CookResult { - let input = context.any_or(0, Kind::Gray, [0.0; 4]); + let intensity = context.f("intensity"); + let (input, source_format) = input_resize::blur_input(context, intensity); const BASE_RESOLUTION: f32 = 256.0; - let radius = context.f("intensity").max(0.0) * context.w.min(context.h) as f32 / BASE_RESOLUTION; + let radius = intensity.max(0.0) * context.w.min(context.h) as f32 / BASE_RESOLUTION; + let pixel_size = match context.vars.get("$pixelsize") { + Some(Value::Float2(size)) => *size, + _ => [1.0; 2], + }; + let [reach_x, reach_y] = pixel_size.map(|scale| { + let reach = radius * scale - 0.5; + if reach.is_finite() { reach.max(0.0) } else { 0.0 } + }); let tile = context.tiling_axes(); - - Ok(vec![box_filter::axis(&box_filter::axis(&input, radius, true, tile[0]), radius, false, tile[1])]) + let filter = |image: Image, reach, horizontal, source| { + if reach <= 0.0 { + image + } else if reach <= 2.0 { + let step = if horizontal { [1.0, 0.0] } else { [0.0, -1.0] }; + box_filter::short_line(&image, reach, step, tile, source) + } else { + box_filter::axis(&image, reach, horizontal, if horizontal { tile[0] } else { tile[1] }, source, context.format) + } + }; + let horizontal = filter(input, reach_x, true, source_format); + if reach_y == 0.0 { + return Ok(vec![horizontal]); + } + let stored = crate::output_precision::apply(horizontal, context.format); + Ok(vec![filter(stored, reach_y, false, context.format)]) } diff --git a/crates/nodes/src/atomic/box_filter.rs b/crates/nodes/src/atomic/box_filter.rs index 07436aed..ba052984 100644 --- a/crates/nodes/src/atomic/box_filter.rs +++ b/crates/nodes/src/atomic/box_filter.rs @@ -1,13 +1,91 @@ use craft_texture::{Image, Limits, MAX_SIDE}; +use materialcraft_core::OutputFormat; use rayon::prelude::*; -pub(super) fn axis(input: &Image, radius: f32, horizontal: bool, tile: bool) -> Image { - if !radius.is_finite() || radius <= 0.5 { +mod mip_window; + +/// Filter on a periodic sheared grid, accounting for the transverse shift at a seam. +pub(super) fn sheared(input: &Image, reach: f32, horizontal: bool, slope: f32, source: OutputFormat, destination: OutputFormat) -> Option { + let (width, height) = (input.width(), input.height()); + let (length, across) = if horizontal { (width, height) } else { (height, width) }; + let radius = reach + 0.5; + if !length.is_power_of_two() || !across.is_power_of_two() || !radius.is_finite() || radius > length as f32 { + return None; + } + // Shearing and reduction accumulate before normalization. Use the bounded fallback for HDR overflow. + let limit = f32::MAX / (2.0 * radius + 2.0); + if !input.data().iter().all(|v| v.abs() <= limit) { + return None; + } + 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, 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| { + // 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, 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, false, intermediate)) +} + +pub(super) fn short_line(input: &Image, reach: f32, step: [f32; 2], tile: [bool; 2], source_format: OutputFormat) -> Image { + let center_weight = 0.5 / (0.5 + reach); + let edge_weight = reach * center_weight; + // The two passes visit samples in different directions. Cancellation exposes their order. + let combine = |first: [f32; 4], center: [f32; 4], last: [f32; 4]| { + std::array::from_fn(|c| last[c].mul_add(edge_weight, center[c].mul_add(center_weight, first[c] * edge_weight))) + }; + if reach > 1.0 || step.iter().any(|v| v.fract() != 0.0) { + // A fractional side tap filters at the source storage precision. + let offset = if reach > 1.0 { 2.0 - 1.0 / reach } else { 1.0 }; + let du = step[0] * offset / input.width() as f32; + let dv = step[1] * offset / input.height() as f32; + return Image::generate(input.width(), input.height(), input.kind(), |x, y| { + let u = (x as f32 + 0.5) / input.width() as f32; + let v = (y as f32 + 0.5) / input.height() as f32; + let first = crate::texture_sampler::sample(input, [u - du, v - dv], tile, source_format, None); + let center = input.get(i64::from(x), i64::from(y), false); + let last = crate::texture_sampler::sample(input, [u + du, v + dv], tile, source_format, None); + combine(first, center, last) + }); + } + let step = step.map(|v| v as i64); + 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); + combine(first, center, last) + }) +} + +pub(super) fn axis(input: &Image, reach: f32, horizontal: bool, tile: bool, source: OutputFormat, destination: OutputFormat) -> Image { + if !reach.is_finite() || reach <= 0.0 { return input.clone(); } // Bound work for hostile strengths to the largest supported image dimension - let radius = radius.min(MAX_SIDE as f32); + let reach = reach.min(MAX_SIDE as f32 - 0.5); + let radius = 0.5 + reach; + let length = if horizontal { input.width() } else { input.height() }; + // Wide windows sum before normalization. Keep the finite HDR and non-finite + // behavior of the extended-precision path when those intermediate sums can overflow. + let limit = f32::MAX / (2.0 * radius + 2.0); + if length.is_power_of_two() && radius <= length as f32 && input.data().iter().all(|v| v.abs() <= limit) { + return mip_window::filter(input, reach, horizontal, tile, source, destination, mip_window::Edges::Paired); + } let extent = (radius + 0.5).floor() as i64; let weight = 1.0 / (2.0 * f64::from(radius)); let edge_weight = (0.5 - (extent as f64 - 0.5) * weight).max(0.0); diff --git a/crates/nodes/src/atomic/box_filter/mip_window.rs b/crates/nodes/src/atomic/box_filter/mip_window.rs new file mode 100644 index 00000000..8a5b88b9 --- /dev/null +++ b/crates/nodes/src/atomic/box_filter/mip_window.rs @@ -0,0 +1,162 @@ +use crate::{output_precision, texture_sampler}; +use craft_texture::Image; +use materialcraft_core::OutputFormat; + +enum Read { + Texel { level: usize, position: i64 }, + Filtered(f32), + AcrossSeam { level: usize, along: f32, shift: f32 }, +} + +struct Tap { + read: Read, + weight: f32, +} + +#[derive(Clone, Copy)] +pub(super) enum Edges { + Paired, + Sheared(f32), +} + +impl Tap { + fn texel(position: i64, width: u32, weight: f32) -> Self { + Self { read: Read::Texel { level: width.ilog2() as usize, position: position.div_euclid(i64::from(width)) }, weight } + } + + fn wrap_sheared(&mut self, length: u32, slope: f32) { + let Read::Texel { level, position } = self.read else { return }; + let count = i64::from(length >> level); + let turns = position.div_euclid(count); + if turns != 0 { + // Crossing a period on the sheared grid shifts the other coordinate. + // Interpolate the already stored mip at that shift, including for endpoint taps. + let along = (position.rem_euclid(count) as f32 + 0.5) / count as f32; + self.read = Read::AcrossSeam { level, along, shift: turns as f32 * slope }; + } + } +} + +fn window(position: u32, length: u32, reach: f32, tile: bool, edges: Edges) -> Vec { + let extent = reach.ceil() as i64; + let fraction = reach - (extent - 1) as f32; + let pair_weight = 1.0 + fraction; + let center = (position as f32 + 0.5) / length as f32; + let filtered = |offset| Tap { read: Read::Filtered(center + offset / length as f32), weight: pair_weight }; + let mut left = i64::from(position) - extent; + let mut right = i64::from(position) + extent; + let mut taps = Vec::new(); + if !tile && left < 0 { + // Clamped coverage contributes one weighted read of the original border texel. + taps.push(Tap::texel(0, 1, fraction + (-left - 1) as f32)); + left = 0; + } else if matches!(edges, Edges::Paired) && left % 2 == 0 { + taps.push(filtered(-extent as f32 + 1.0 / pair_weight)); + left += 2; + } else { + taps.push(Tap::texel(left, 1, fraction)); + left += 1; + } + let last = if !tile && right >= i64::from(length) { + let weight = fraction + (right - i64::from(length)) as f32; + right = i64::from(length) - 1; + Tap::texel(right, 1, weight) + } else if matches!(edges, Edges::Paired) && right % 2 != 0 { + right -= 2; + filtered((extent - 1) as f32 + fraction / pair_weight) + } else { + right -= 1; + Tap::texel(right + 1, 1, fraction) + }; + while left <= right { + // An aligned run of 2^k texels is a single stored texel at level k. + let available = (right - left + 1).min(i64::from(length)) as u32; + let width = 1 << available.ilog2().min(left.trailing_zeros()); + taps.push(Tap::texel(left, width, width as f32)); + left += i64::from(width); + } + taps.push(last); + taps +} + +pub(super) fn filter(input: &Image, reach: f32, horizontal: bool, tile: bool, source: OutputFormat, destination: OutputFormat, edges: Edges) -> Image { + let radius = 0.5 + reach; + let length = if horizontal { input.width() } else { input.height() }; + let mut levels = vec![input.clone()]; + let mut format = source; + let mut size = length; + let max_width = ((radius * 2.0).ceil() as u32).min(length); + for _ in 0..max_width.ilog2() { + let Some(previous) = levels.last() else { break }; + size /= 2; + let (w, h) = if horizontal { (size, input.height()) } else { (input.width(), size) }; + let reduced = texture_sampler::resize_input_level(previous, w, h, format, [true; 2]); + levels.push(output_precision::apply(reduced, destination)); + format = destination; + } + let windows: Vec<_> = (0..length) + .map(|position| { + let mut taps = window(position, length, reach, tile, edges); + if horizontal { + taps.reverse(); + } + if let Edges::Sheared(slope) = edges { + // In the first aligned pair the full texel starts the sum. Its fractional + // neighbor then contributes one fused multiply-add before the larger mip reads. + if let [first, second, ..] = taps.as_mut_slice() + && let (Read::Texel { level: 0, position: a }, Read::Texel { level: 0, position: b }) = (&first.read, &second.read) + && a.div_euclid(2) == b.div_euclid(2) + { + std::mem::swap(first, second); + } + if slope.fract() != 0.0 { + for tap in &mut taps { + tap.wrap_sheared(length, slope); + } + } + } + taps + }) + .collect(); + let scale = 0.5 / radius; + // On a sheared grid the normalized integer window includes a positive storage offset. + // A one-level pulse exposes it before the inverse shear averages neighboring texels. + let storage_offset = match (edges, destination) { + (Edges::Sheared(_), OutputFormat::U8) => Some(0.5 / 256.0), + (Edges::Sheared(_), OutputFormat::U16 | OutputFormat::Inherit) => Some(0.4 / 65535.0), + _ => None, + }; + Image::generate(input.width(), input.height(), input.kind(), |x, y| { + let (position, across, other_size) = if horizontal { (x, y, input.height()) } else { (y, x, input.width()) }; + let other_uv = (across as f32 + 0.5) / other_size as f32; + let read = |tap: &Tap| match tap.read { + Read::Texel { level, position } => { + let (x, y) = if horizontal { (position, i64::from(across)) } else { (i64::from(across), position) }; + levels.get(level).unwrap_or(input).get(x, y, true) + } + Read::Filtered(uv) => { + let xy = if horizontal { [uv, other_uv] } else { [other_uv, uv] }; + texture_sampler::sample(input, xy, [tile; 2], source, None) + } + Read::AcrossSeam { level, along, shift } => { + let across = other_uv + shift; + let xy = if horizontal { [along, across] } else { [across, along] }; + let format = if level == 0 { source } else { destination }; + texture_sampler::sample(levels.get(level).unwrap_or(input), xy, [true; 2], format, None) + } + }; + let Some((first, rest)) = windows.get(position as usize).and_then(|taps| taps.split_first()) else { + return input.get(i64::from(x), i64::from(y), false); + }; + let mut sum = read(first).map(|v| v * first.weight); + for tap in rest { + for (total, v) in sum.iter_mut().zip(read(tap)) { + *total = v.mul_add(tap.weight, *total); + } + } + match storage_offset { + Some(offset) => sum.map(|v| v.mul_add(scale, offset)), + None => sum.map(|v| v * scale), + } + }) +} diff --git a/crates/nodes/src/atomic/curve.rs b/crates/nodes/src/atomic/curve.rs index c3167f49..e10a7e9a 100644 --- a/crates/nodes/src/atomic/curve.rs +++ b/crates/nodes/src/atomic/curve.rs @@ -1,6 +1,9 @@ use super::ATOMIC; -use crate::{CookContext, CookResult, NodeDefinition, node}; -use craft_texture::Kind; +use crate::{CookContext, CookResult, NodeDefinition, node, texture_sampler}; +use craft_texture::{Image, Kind, Limits}; +use materialcraft_core::{Curve, OutputFormat}; + +const TABLE_WIDTH: usize = 1024; pub(super) fn definition() -> NodeDefinition { node("curve", "Curve", ATOMIC).desc("Remaps values through a tone curve.").atomic().any_in("input", "Input").curve("curve", "Curve").any_out().cook(curve) @@ -8,17 +11,50 @@ pub(super) fn definition() -> NodeDefinition { fn curve(context: &CookContext) -> CookResult { let image = context.any_or(0, Kind::Gray, [0.0; 4]); - let curve = context.curve("curve"); - - // Linear interpolation over 1024 intervals approximates the smooth curve - const TABLE_INTERVALS: usize = 1024; - let table: Vec = (0..=TABLE_INTERVALS).map(|i| curve.eval(i as f32 / TABLE_INTERVALS as f32)).collect(); + let table = lookup_table(&context.curve("curve"))?; let lookup = |value: f32| { - let position = value.clamp(0.0, 1.0) * TABLE_INTERVALS as f32; - let i = position as usize; - let a = table.get(i).copied().unwrap_or(0.0); - let b = table.get(i + 1).copied().unwrap_or(a); - a + (b - a) * (position - i as f32) + let u = (value.clamp(0.0, 1.0) * (TABLE_WIDTH - 1) as f32 + 0.5) / TABLE_WIDTH as f32; + texture_sampler::sample(&table, [u, 0.5], [false; 2], OutputFormat::F32, None)[0] }; - Ok(vec![image.map(image.kind(), |p| [lookup(p[0]), lookup(p[1]), lookup(p[2]), p[3]])]) + Ok(vec![image.map(image.kind(), |p| if image.is_gray() { [lookup(p[0]); 4] } else { [lookup(p[0]), lookup(p[1]), lookup(p[2]), p[3]] })]) +} + +fn lookup_table(curve: &Curve) -> Result { + let step = 1.0 / (TABLE_WIDTH - 1) as f32; + let position = |i: usize| i as f32 * step; + let mut entries = Vec::with_capacity(TABLE_WIDTH); + let fill_anchor = |entries: &mut Vec, x, y| { + while entries.len() < TABLE_WIDTH && position(entries.len()) <= x + 0.5 * step { + entries.push(y); + } + }; + if let Some(first) = curve.points.first() { + fill_anchor(&mut entries, first.x, first.y); + let mut last_y = first.y; + for pair in curve.points.windows(2) { + let [left, right] = pair else { continue }; + if entries.len() == TABLE_WIDTH { + break; + } + if right.x <= left.x { + continue; + } + let slope = (right.y - left.y) / (right.x - left.x); + // Even anchors closer than one table texel leave one sample of their segment. + loop { + let x = position(entries.len()); + let y = if left.right_broken && right.left_broken { (x - left.x) * slope + left.y } else { curve.eval(x) }; + entries.push(y); + if entries.len() == TABLE_WIDTH || position(entries.len()) >= right.x - 0.5 * step { + break; + } + } + fill_anchor(&mut entries, right.x, right.y); + last_y = right.y; + } + entries.resize(TABLE_WIDTH, last_y); + } else { + entries.extend((0..TABLE_WIDTH).map(position)); + } + Image::from_data(TABLE_WIDTH as u32, 1, Kind::Gray, entries, &Limits::default()).map_err(|error| error.to_string()) } diff --git a/crates/nodes/src/atomic/directional_blur.rs b/crates/nodes/src/atomic/directional_blur.rs index 9a5a9d07..5e50c20e 100644 --- a/crates/nodes/src/atomic/directional_blur.rs +++ b/crates/nodes/src/atomic/directional_blur.rs @@ -1,6 +1,7 @@ -use super::{ATOMIC, box_filter, direction}; +use super::{ATOMIC, box_filter, direction, input_resize}; use crate::{CookContext, CookResult, NodeDefinition, node}; -use craft_texture::{Image, Kind}; +use craft_texture::Image; +use materialcraft_core::Value; pub(super) fn definition() -> NodeDefinition { node("directional_blur", "Directional blur", ATOMIC) @@ -18,25 +19,95 @@ fn directional_blur(context: &CookContext) -> CookResult { } pub(super) fn blur(context: &CookContext, angle: f32) -> CookResult { - let input = context.any_or(0, Kind::Gray, [0.0; 4]); + let intensity = context.f("intensity"); + let (input, source_format) = input_resize::blur_input(context, intensity); const BASE_RESOLUTION: f32 = 256.0; const MAX_HALF_SAMPLES: i32 = 512; - let radius = context.f("intensity").max(0.0) * context.w.min(context.h) as f32 / BASE_RESOLUTION; - if radius <= 0.5 { + let stretched = context.w != context.h && context.vars.get("$pixelratio").and_then(Value::as_i32) == Some(0); + let extent = |side: u32| (intensity.max(0.0) * side as f32 / BASE_RESOLUTION - 0.5).max(0.0); + let [extent_x, extent_y] = if stretched { [context.w, context.h].map(extent) } else { [extent(context.w.min(context.h)); 2] }; + if extent_x == 0.0 && extent_y == 0.0 { return Ok(vec![input]); } - let (dx, dy) = direction(angle); - - // Image-space rotation follows increasing rows - let dy = -dy; let tile = context.tiling_axes(); - if dy == 0.0 { - return Ok(vec![box_filter::axis(&input, radius, true, tile[0])]); + let radians = angle * std::f32::consts::TAU; + if !radians.is_finite() { + return Err("directional blur angle exceeds the finite radian range".into()); + } + let sine = projected_sine(radians.abs()) * radians.signum(); + let cosine = projected_sine(radians.abs() + std::f32::consts::FRAC_PI_2); + let quarters = angle * 4.0; + let cardinal = (quarters.fract() == 0.0).then_some(quarters % 2.0 == 0.0); + // On a rectangle one pixel extent can vanish before projection. Its surviving axis sets the tap layout. + let axis = if extent_x == 0.0 { + Some(false) + } else if extent_y == 0.0 { + Some(true) + } else { + cardinal + }; + if let Some(horizontal) = axis { + let projection = if cardinal == axis { + // Rotated axial footprints project their reach one float below unity before normalization. + if angle == 0.0 { 1.0 } else { f32::from_bits(0x3f7f_ffff) } + } else if horizontal { + cosine.abs() + } else { + sine.abs() + }; + let reach = (if horizontal { extent_x } else { extent_y }) * projection; + if reach == 0.0 { + return Ok(vec![input]); + } + if reach > 2.0 { + return Ok(vec![box_filter::axis(&input, reach, horizontal, tile[usize::from(!horizontal)], source_format, context.format)]); + } + let step = if !horizontal { + [0.0, -1.0] + } else if reach <= 1.0 { + [-1.0, 0.0] + } else { + [1.0, 0.0] + }; + return Ok(vec![box_filter::short_line(&input, reach, step, tile, source_format)]); } + let (reach_x, reach_y) = (extent_x * cosine, extent_y * sine); + let short_reach = reach_x.abs().max(reach_y.abs()); + let (sample_x, sample_y) = if stretched { (reach_x, reach_y) } else { (cosine, sine) }; + if short_reach <= 1.0 { + // Normalize the offsets in texture coordinates so the longer side keeps its texel scale. + let u = sample_x / context.w as f32; + let v = sample_y / context.h as f32; + // Tap order affects the fused sum. A rectangular image can change which UV axis dominates. + let dominant = if u.abs() > v.abs() { u } else { v }; + if dominant == 0.0 { + return Ok(vec![input]); + } + let span = -dominant; + return Ok(vec![box_filter::short_line(&input, short_reach, [u / span, v / span], tile, source_format)]); + } + if tile == [true; 2] && context.w == input.width() && context.h == input.height() { + // Compare the components before rounding the direction to the sample grid. + let (line_y, line_x) = f64::from(radians).sin_cos(); + let horizontal = line_x.abs() * f64::from(extent_x) / f64::from(context.w) > line_y.abs() * f64::from(extent_y) / f64::from(context.h); + // 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. + // 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, along.abs(), horizontal, slope, source_format, context.format) { + return Ok(vec![image]); + } + } + let (dx, dy) = direction(angle); + // Image-space rotation follows increasing rows. + let (dx, dy) = if stretched { (extent_x * dx, -extent_y * dy) } else { (dx, -dy) }; let major = dx.abs().max(dy.abs()); - let projected_radius = 0.5 + (radius - 0.5) * major; + let reach = if stretched { major } else { extent_x * major }; + let projected_radius = 0.5 + reach; let half_samples = (projected_radius + 0.5).floor().clamp(1.0, MAX_HALF_SAMPLES as f32) as i32; // Bound oblique sampling cost while preserving the extent of large kernels @@ -62,3 +133,32 @@ pub(super) fn blur(context: &CookContext, angle: f32) -> CookResult { pixel })]) } + +/// The filter stores both direction components before deriving sample weights and coordinates. +fn projected_sine(radians: f32) -> f32 { + use std::f64::consts::PI; + + const PI_HIGH: f32 = 3.140625; + const PI_MIDDLE: f32 = (PI - PI_HIGH as f64) as f32; + const PI_LOW: f32 = (PI - PI_HIGH as f64 - PI_MIDDLE as f64) as f32; + + // Large angles use a wide reduction before storing the direction component. + if radians >= 10_000.0 { + return f64::from(radians).sin() as f32; + } + let half_turns = (f64::from(radians) / PI).round_ties_even() as u32; + // Each subtraction rounds separately. The last correction can distinguish angles + // that would have the same single-precision remainder after one subtraction. + let factor = -(half_turns as f32); + let high = factor.mul_add(PI_HIGH, radians); + let middle = factor.mul_add(PI_MIDDLE, high); + let reduced = factor.mul_add(PI_LOW, middle); + let x = if half_turns.is_multiple_of(2) { reduced } else { -reduced }; + let square = x * x; + // Evaluate the odd sine series on the central half turn. Each product rounds before the next sum. + let mut tail = -1.0 / 39_916_800.0; + for coefficient in [1.0 / 362_880.0, -1.0 / 5_040.0, 1.0 / 120.0, -1.0 / 6.0] { + tail = tail * square + coefficient; + } + x + (tail * square) * x +} diff --git a/crates/nodes/src/atomic/directional_warp.rs b/crates/nodes/src/atomic/directional_warp.rs index a7be3e0e..b3da0437 100644 --- a/crates/nodes/src/atomic/directional_warp.rs +++ b/crates/nodes/src/atomic/directional_warp.rs @@ -1,6 +1,7 @@ -use super::{ATOMIC, direction}; +use super::ATOMIC; +use super::input_resize::sampled_input; use crate::{CookContext, CookResult, NodeDefinition, node}; -use craft_texture::{Image, Kind}; +use craft_texture::Image; pub(super) fn definition() -> NodeDefinition { node("directional_warp", "Directional warp", ATOMIC) @@ -15,13 +16,27 @@ pub(super) fn definition() -> NodeDefinition { } fn directional_warp(context: &CookContext) -> CookResult { - let image = context.any_or(0, Kind::Gray, [0.0; 4]); - let map = context.gray_or(1, 0.0); - let (dx, dy) = direction(context.f("angle")); + let target = [context.w, context.h].map(|side| side.clamp(1, craft_texture::MAX_SIDE)); + let tiling = context.tiling_axes(); + let (image, format) = sampled_input(context, 0); + let (map, map_format) = sampled_input(context, 1); + let map = map.to_gray(); + let same_size = [map.width(), map.height()] == target; + let radians = context.f("angle") * std::f32::consts::TAU; + // The horizontal phase includes a quarter turn rounded in radians before evaluating the sine. + let component = |phase: f32| crate::function::truncate_float(f64::from(phase).sin()); + // At zero turns the full horizontal displacement reaches half-texel filter ties. + let direction = if radians == 0.0 { [1.0, 0.0] } else { [component(radians + std::f32::consts::FRAC_PI_2), component(radians)] }; const BASE_RESOLUTION: f32 = 256.0; - let intensity_scale = context.f("intensity") / BASE_RESOLUTION; - Ok(vec![Image::generate_uv(context.w, context.h, image.kind(), |u, v| { - let offset = map.sample_gray(u, v, context.tile) * intensity_scale; - image.sample(u + dx * offset, v + dy * offset, context.tile) + let [width, height] = target.map(|side| side as f32); + let strength = context.f("intensity") / BASE_RESOLUTION; + let shorter = width.min(height); + let step = [direction[0] * strength * (shorter / width), direction[1] * strength * (shorter / height)]; + Ok(vec![Image::generate(context.w, context.h, image.kind(), |x, y| { + let (u, v) = ((x as f32 + 0.5) / width, (y as f32 + 0.5) / height); + let amount = + if same_size { map.get_gray(i64::from(x), i64::from(y), false) } else { crate::texture_sampler::sample(&map, [u, v], tiling, map_format, None)[0] }; + let uv = [step[0].mul_add(amount, u), step[1].mul_add(amount, v)]; + crate::texture_sampler::sample(&image, uv, tiling, format, None) })]) } diff --git a/crates/nodes/src/atomic/distance.rs b/crates/nodes/src/atomic/distance.rs index 92cacb99..8e0da3be 100644 --- a/crates/nodes/src/atomic/distance.rs +++ b/crates/nodes/src/atomic/distance.rs @@ -1,7 +1,9 @@ use super::ATOMIC; -use crate::ops; use crate::{CookContext, CookResult, NodeDefinition, node}; -use craft_texture::Image; +use craft_texture::{Image, Kind}; +use materialcraft_core::Value; + +mod mask_field; pub(super) fn definition() -> NodeDefinition { node("distance", "Distance", ATOMIC) @@ -9,7 +11,9 @@ pub(super) fn definition() -> NodeDefinition { .atomic() .gray_in("mask", "Mask input") .any_in("source", "Source input") + .boolean("color_mode", "Color output", false) .float("distance", "Maximum distance", 10.0, 0.0, 256.0) + .choice("metric", "Distance metric", &["Euclidean", "Manhattan", "Chebyshev"], 0) .boolean("combine", "Combine distance with source", true) .any_out() .cook(distance) @@ -17,38 +21,14 @@ pub(super) fn definition() -> NodeDefinition { fn distance(context: &CookContext) -> CookResult { let mask = context.gray_or(0, 0.0); - const BASE_RESOLUTION: f32 = 256.0; - const MIN_DISTANCE_PIXELS: f32 = 1e-3; - let maximum_distance = (context.f("distance").max(0.0) * context.w as f32 / BASE_RESOLUTION).max(MIN_DISTANCE_PIXELS); - let data = mask.shared_data().clone(); - let inside = |i| data.get(i).copied().unwrap_or(0.0) > 0.5; - let Some(source) = context.sized(1) else { - let squared_distances = ops::distance_sq(context.w, context.h, inside, context.tile); - return Ok(vec![ops::gray_from( - context.w, - context.h, - squared_distances.iter().map(|d| (1.0 - d.sqrt() / maximum_distance).clamp(0.0, 1.0)).collect(), - )?]); - }; - - // Propagate the exact nearest site without gaps from gradient-walk stalls - let (squared_distances, sites) = ops::distance_sq_with_sites(context.w, context.h, inside, context.tile); - let combine = context.b("combine"); - Ok(vec![Image::generate(context.w, context.h, source.kind(), |x, y| { - let i = y as usize * context.w as usize + x as usize; - let site = sites.get(i).copied().unwrap_or(usize::MAX); - let mut pixel = if site == usize::MAX { - [0.0, 0.0, 0.0, if source.is_gray() { 1.0 } else { 0.0 }] - } else { - source.get((site % context.w as usize) as i64, (site / context.w as usize) as i64, false) - }; - let d = squared_distances.get(i).copied().unwrap_or(f32::INFINITY).sqrt(); - if d > maximum_distance { - pixel = [0.0, 0.0, 0.0, if source.is_gray() { 1.0 } else { 0.0 }]; - } else if combine { - let falloff = (1.0 - d / maximum_distance).clamp(0.0, 1.0); - pixel = [pixel[0] * falloff, pixel[1] * falloff, pixel[2] * falloff, pixel[3]]; - } - pixel - })]) + let source = context.sized(1); + let kind = if context.b("color_mode") { Kind::Color } else { Kind::Gray }; + // An incompatible source produces zero channels. Only a disconnected source produces a mask ramp. + if source.as_ref().is_some_and(|image| image.kind() != kind) { + return Ok(vec![Image::filled(mask.width(), mask.height(), kind, [0.0; 4])]); + } + let radius = (context.f("distance").max(0.0) * (mask.width().min(mask.height()) as f32 / 256.0)).min(f32::MAX); + let stretched = context.vars.get("$pixelratio").and_then(Value::as_i32) == Some(0); + let image = mask_field::render(&mask, source.as_ref(), radius, context.tiling_axes(), context.i("metric"), context.b("combine"), stretched)?; + Ok(vec![if kind == Kind::Color && image.is_gray() { image.to_color() } else { image }]) } diff --git a/crates/nodes/src/atomic/distance/mask_field.rs b/crates/nodes/src/atomic/distance/mask_field.rs new file mode 100644 index 00000000..ca0d58e8 --- /dev/null +++ b/crates/nodes/src/atomic/distance/mask_field.rs @@ -0,0 +1,188 @@ +use crate::function::pixel_sqrt; +use craft_texture::{Image, Kind}; +use rayon::prelude::*; + +type Site = [u16; 2]; +const EMPTY: Site = [u16::MAX; 2]; + +struct Axis { + positions: Vec, + origin: f32, + tiled: bool, + units_per_texel: f32, +} + +impl Axis { + fn new(size: u32, tiled: bool, units_per_texel: f32) -> Self { + let extent = size as f32; + // Wrapped coordinates are relative to the midpoint before subtraction. + let origin = if tiled { 0.5 } else { 0.0 }; + let positions = (0..size) + .map(|i| { + // Rounding the scaled center to F32 first can move a site across the half-word boundary. + let word = ((f64::from(i) + 0.5) * f64::from(u16::MAX) / f64::from(size)).round_ties_even(); + (word as f32 / f32::from(u16::MAX) - origin) * extent + }) + .collect(); + Self { positions, origin: origin * extent, tiled, units_per_texel } + } + + fn delta(&self, pixel: usize, site: u16) -> f32 { + let distance = ((pixel as f32 + 0.5 - self.origin) - self.positions[usize::from(site)]).abs(); + let distance = if self.tiled { distance.min(self.positions.len() as f32 - distance) } else { distance }; + distance * self.units_per_texel + } + + fn neighbors(&self, step: f64) -> Vec<[Option; 3]> { + let extent = self.positions.len() as i32; + // Sample at texel centers. A half-texel jump can address different offsets in each direction. + let offsets = [(0.5 - step).floor() as i32, 0, (0.5 + step).floor() as i32]; + (0..extent) + .map(|i| { + offsets.map(|offset| { + let n = i + offset; + if self.tiled { Some(n.rem_euclid(extent) as usize) } else { (0..extent).contains(&n).then_some(n as usize) } + }) + }) + .collect() + } +} + +struct Geometry { + columns: Axis, + rows: Axis, + metric: i32, +} + +impl Geometry { + fn squared_distance(&self, x: usize, y: usize, site: Site) -> f32 { + let dx = self.columns.delta(x, site[0]); + let dy = self.rows.delta(y, site[1]); + match self.metric { + 1 => (dx + dy) * (dx + dy), + 2 => dx.max(dy) * dx.max(dy), + _ => dy.mul_add(dy, dx * dx), + } + } + + fn propagate(&self, mut sites: Vec, first_jump: u32) -> Vec { + let width = self.columns.positions.len(); + let height = self.rows.positions.len(); + let longest = width.max(height) as f64; + let mut next = vec![EMPTY; sites.len()]; + let jumps = (0..=first_jump.ilog2()).rev().map(|power| { + let fraction = f64::from(1u32 << power) / longest; + [fraction * width as f64, fraction * height as f64] + }); + // A final unit step fills missed sites on open fields. It changes measured winners on tiled fields. + let refine = (!self.columns.tiled && !self.rows.tiled).then_some([1.0; 2]); + for [step_x, step_y] in jumps.chain(refine) { + let xs = self.columns.neighbors(step_x); + let ys = self.rows.neighbors(step_y); + next.par_chunks_mut(width).enumerate().for_each(|(y, output)| { + let [above, row, below] = ys[y]; + for (x, dest) in output.iter_mut().enumerate() { + let mut best = sites[y * width + x]; + if best != [x as u16, y as u16] { + let mut nearest = if best == EMPTY { f32::INFINITY } else { self.squared_distance(x, y, best) }; + let [left, column, right] = xs[x]; + // Equal distances keep the current winner. Visit opposing axial pairs before diagonal pairs. + let neighbors = + [(right, row), (left, row), (column, below), (column, above), (right, below), (left, above), (right, above), (left, below)]; + for (sx, sy) in neighbors { + let Some((sx, sy)) = sx.zip(sy) else { continue }; + let candidate = sites[sy * width + sx]; + if candidate != EMPTY && candidate != best { + let d = self.squared_distance(x, y, candidate); + if d < nearest { + nearest = d; + best = candidate; + } + } + } + } + *dest = best; + } + }); + std::mem::swap(&mut sites, &mut next); + } + sites + } +} + +fn attenuate(mut pixel: [f32; 4], gray: bool, weight: f32) -> [f32; 4] { + pixel[if gray { 0 } else { 3 }] *= weight; + pixel +} + +pub(super) fn render(mask: &Image, source: Option<&Image>, radius: f32, tile: [bool; 2], metric: i32, combine: bool, stretched: bool) -> Result { + let (width, height) = (mask.width(), mask.height()); + // Reserve the final coordinate pair as the missing-site marker. + if width == 0 || height == 0 || width > u32::from(u16::MAX) || height > u32::from(u16::MAX) { + return Err("distance mask dimensions exceed the supported coordinate range".into()); + } + let empty = !mask.data().iter().any(|v| *v >= 0.5); + let tiled = tile[0] || tile[1]; + if empty || radius == 0.0 { + let result = match source { + None => Image::filled(width, height, Kind::Gray, [0.0; 4]), + Some(src) if empty && !tiled => Image::filled(width, height, src.kind(), src.get(0, 0, false)), + Some(src) if combine => Image::generate(width, height, src.kind(), |x, y| attenuate(src.get(x.into(), y.into(), false), src.is_gray(), 0.0)), + Some(src) => src.clone(), + }; + return Ok(result); + } + if mask.data().iter().all(|v| *v >= 0.5) { + return Ok(source.cloned().unwrap_or_else(|| Image::filled(width, height, Kind::Gray, [1.0; 4]))); + } + // In stretched space the same UV displacement spans different texel counts on the two axes. + let short_side = width.min(height) as f32; + let units = if stretched { [short_side / width as f32, short_side / height as f32] } else { [1.0; 2] }; + let reach = radius / units[0].min(units[1]); + // With a subpixel reach on both axes no site can reach a neighboring texel. This also keeps a + // tiny positive radius from overflowing its reciprocal at a site of distance zero. + if reach < 0.5 { + let weight = |x: u32, y: u32| if mask.get_gray(x.into(), y.into(), false) >= 0.5 { 1.0 } else { 0.0 }; + return Ok(match source { + None => Image::gray(width, height, weight), + Some(src) if combine => { + Image::generate(width, height, src.kind(), |x, y| attenuate(src.get(x.into(), y.into(), false), src.is_gray(), weight(x, y))) + } + Some(src) => src.clone(), + }); + } + + let w = width as usize; + let initial = mask.data().iter().enumerate().map(|(i, &v)| if v >= 0.5 { [(i % w) as u16, (i / w) as u16] } else { EMPTY }).collect(); + let geometry = Geometry { columns: Axis::new(width, tile[0], units[0]), rows: Axis::new(height, tile[1], units[1]), metric }; + let long_side = width.max(height); + let search_span = radius * (long_side as f32 / short_side); + let first_jump = (search_span.ceil() as u32).clamp(1, long_side).next_power_of_two(); + let sites = geometry.propagate(initial, first_jump); + let inverse_radius = radius.recip(); + let site_distance = |x: u32, y: u32| { + let site = sites[y as usize * w + x as usize]; + let distance = if site == [x as u16, y as u16] { + 0.0 + } else if site == EMPTY { + f32::INFINITY + } else { + pixel_sqrt(geometry.squared_distance(x as usize, y as usize, site)) + }; + (site, distance) + }; + let mask_weight = |distance: f32| (-distance).mul_add(inverse_radius, 1.0).clamp(0.0, 1.0); + let Some(source) = source else { + return Ok(Image::gray(width, height, |x, y| mask_weight(site_distance(x, y).1))); + }; + Ok(Image::generate(width, height, source.kind(), |x, y| { + let (site, distance) = site_distance(x, y); + let pixel = if distance < radius { source.get(site[0].into(), site[1].into(), false) } else { source.get(x.into(), y.into(), false) }; + if !combine { + return pixel; + } + // The tiled path stores the complement after rounding the mask gradient. + let weight = if tiled { 1.0 - (1.0 - mask_weight(distance)) } else { (1.0 - distance * inverse_radius).clamp(0.0, 1.0) }; + attenuate(pixel, source.is_gray(), weight) + })) +} diff --git a/crates/nodes/src/atomic/emboss.rs b/crates/nodes/src/atomic/emboss.rs index a765f2f8..a9ecc012 100644 --- a/crates/nodes/src/atomic/emboss.rs +++ b/crates/nodes/src/atomic/emboss.rs @@ -1,7 +1,7 @@ -use super::{ATOMIC, direction}; -use crate::ops; +use super::ATOMIC; use crate::{CookContext, CookResult, NodeDefinition, node}; use craft_texture::{Image, Kind}; +use materialcraft_core::Value; pub(super) fn definition() -> NodeDefinition { node("emboss", "Emboss", ATOMIC) @@ -18,19 +18,35 @@ pub(super) fn definition() -> NodeDefinition { } fn emboss(context: &CookContext) -> CookResult { - const INTENSITY_REFERENCE_WIDTH: f32 = 64.0; let input = context.any_or(0, Kind::Gray, [0.0; 4]); let height_map = context.gray_or(1, 0.0); - let (light_x, light_y) = direction(context.f("light_angle")); - let intensity = context.f("intensity") * context.w as f32 / INTENSITY_REFERENCE_WIDTH; - let (highlight, shadow) = (context.v4("highlight"), context.v4("shadow")); + let pixel_size = match context.vars.get("$pixelsize") { + Some(Value::Float2(size)) => *size, + _ => [1.0; 2], + }; + let (sin, cos) = (context.f("light_angle") * std::f32::consts::TAU).sin_cos(); + let intensity = context.f("intensity") * (input.width().min(input.height()) as f32 / 256.0); + let light_x = cos * pixel_size[0] * intensity; + let light_y = sin * pixel_size[1] * intensity; + let tint = |id: &str| { + let [r, g, b, _] = context.v4(id); + if input.is_gray() { [(r + g + b) / 3.0; 3] } else { [r, g, b] } + }; + let highlight = tint("highlight"); + let shadow = tint("shadow").map(|v| 1.0 - v); + let tiling = context.tiling_axes(); Ok(vec![Image::generate(context.w, context.h, input.kind(), |x, y| { - let (gx, gy) = ops::slope(&height_map, x as i64, y as i64, context.tile); - let lighting = (-(gx * light_x + gy * light_y) * intensity).clamp(-1.0, 1.0); - let pixel = input.get(x as i64, y as i64, false); - let tint = if lighting >= 0.0 { highlight } else { shadow }; - let blend = lighting.abs(); - [pixel[0] + (tint[0] - pixel[0]) * blend, pixel[1] + (tint[1] - pixel[1]) * blend, pixel[2] + (tint[2] - pixel[2]) * blend, pixel[3]] + let (x, y) = (i64::from(x), i64::from(y)); + let center = height_map.get_gray(x, y, false); + let dx = center - height_map.get_axes(x - 1, y, tiling)[0]; + let dy = center - height_map.get_axes(x, y - 1, tiling)[0]; + let light = light_y.mul_add(dy, light_x * dx); + let mut pixel = input.get(x, y, false); + let weights = if light >= 0.0 { highlight } else { shadow }; + for (value, weight) in pixel.iter_mut().zip(weights) { + *value = light.mul_add(weight, *value); + } + pixel })]) } diff --git a/crates/nodes/src/atomic/font.rs b/crates/nodes/src/atomic/font.rs new file mode 100644 index 00000000..53b21d83 --- /dev/null +++ b/crates/nodes/src/atomic/font.rs @@ -0,0 +1,302 @@ +//! Render package font outlines in normalized text coordinates. +use std::collections::BTreeMap; + +use craft_font_catalog::{FontOutline, RunGlyph, RunInput, ShapePlanCache, shape_run}; +use harfrust::{Direction, Shaper}; +use read_fonts::{TableProvider, tables::glyf::Glyph as StoredGlyph, types::GlyphId}; +use vello_common::{ + fearless_simd::Level, + geometry::RectU16, + kurbo::{Affine, BezPath, ParamCurve, PathEl, Point, QuadBez, Rect, Shape, Vec2}, + peniko::Fill, + strip::{StripFillSegment, visit_strip_fill_segments}, + strip_generator::{StripGenerator, StripStorage}, + tile::Tile, +}; + +use crate::{CookContext, CookResult, raster::composite_text}; + +// A short string can repeat a complex glyph across many wrapping tiles. Bound the +// outline storage and submitted path elements independently of the character count. +const MAX_ELEMENTS: usize = 1_000_000; + +struct Glyph { + path: BezPath, + bounds: Rect, +} + +impl Glyph { + fn new(mut path: BezPath, simple_contour: bool, pixels_per_unit: f64, remaining: &mut usize) -> Result { + let budget_error = "font exceeds the outline storage budget"; + *remaining = remaining.checked_sub(path.elements().len()).ok_or(budget_error)?; + if simple_contour { + // Stored TrueType points have integer design coordinates. The join between + // adjacent controls, including a contour's starting join, uses the lower unit. + for element in path.elements_mut() { + if let PathEl::MoveTo(join) | PathEl::QuadTo(_, join) = element { + *join = join.floor(); + } + } + } + let bounds = path.bounding_box(); + if !path.elements().iter().any(|element| matches!(element, PathEl::QuadTo(..))) { + return Ok(Self { path, bounds }); + } + + let mut raster = BezPath::new(); + let mut current = Point::ORIGIN; + let mut start = Point::ORIGIN; + for &element in path.elements() { + match element { + PathEl::MoveTo(point) => { + start = point; + current = point; + } + PathEl::LineTo(point) | PathEl::CurveTo(_, _, point) => current = point, + PathEl::ClosePath => current = start, + PathEl::QuadTo(control, end) => { + // Each bisection quarters the distance between the curve midpoint and the chord. + let mut deviation = control.distance(current.midpoint(end)) * 0.5 * pixels_per_unit; + let mut segments = 1; + while deviation > 0.35 { + *remaining = remaining.checked_sub(segments).ok_or(budget_error)?; + segments *= 2; + deviation *= 0.25; + } + let curve = QuadBez { p0: current, p1: control, p2: end }; + for step in 1..=segments { + raster.line_to(curve.eval(step as f64 / segments as f64)); + } + current = end; + continue; + } + } + raster.push(element); + } + Ok(Self { path: raster, bounds }) + } +} + +fn shape_line(line: &str, shaper: &Shaper<'_>, plans: &ShapePlanCache) -> Result, String> { + let bidi = unicode_bidi::BidiInfo::new(line, None); + let mut glyphs = Vec::new(); + for paragraph in &bidi.paragraphs { + let (levels, runs) = bidi.visual_runs(paragraph, paragraph.range.clone()); + for range in runs { + let (Some(text), Some(before), Some(after)) = (line.get(range.clone()), line.get(..range.start), line.get(range.end..)) else { + return Err("invalid text shaping range".into()); + }; + let direction = if levels.get(range.start).is_some_and(|level| level.is_rtl()) { Direction::RightToLeft } else { Direction::LeftToRight }; + let input = RunInput { + text, + source_start: range.start, + pre_context: before, + post_context: after, + direction, + language: None, + features: &[], + character_clusters: false, + uppercase: false, + }; + let run = shape_run(shaper, &input, |ch| ch, |face, dir, script, lang, features| plans.get_or_create(face, None, dir, script, lang, features)) + .map_err(|e| e.to_string())?; + glyphs.extend(run); + } + } + Ok(glyphs) +} + +fn copies(low: f64, high: f64, period: f64, tiled: bool) -> Result, String> { + if !tiled { + return Ok(0..=0); + } + let first = (-high / period).ceil(); + let last = ((period - low) / period).floor(); + if first < f64::from(i32::MIN) || last > f64::from(i32::MAX) { + return Err("text transform exceeds the tile coordinate range".into()); + } + Ok(first as i32..=last as i32) +} + +struct Drawing { + coverage: Vec, + generator: StripGenerator, + strips: StripStorage, + width: u16, + height: u16, + tiled: [bool; 2], + remaining: usize, +} + +/// A solid span is opaque. An edge span stores one column of byte coverage at a time. +fn paint_strip(image: &mut [u8], stride: usize, clip: RectU16, span: StripFillSegment, alphas: Option<&[u8]>) { + let rect = span.pixel_rect().intersect(clip); + for y in rect.y0..rect.y1 { + let offset = usize::from(y) * stride; + let Some(row) = image.get_mut(offset + usize::from(rect.x0)..offset + usize::from(rect.x1)) else { continue }; + if let Some(alphas) = alphas { + let first = usize::from(rect.x0 - span.x0()) * usize::from(Tile::HEIGHT) + usize::from(y - span.y()); + for (dst, &src) in row.iter_mut().zip(alphas.iter().skip(first).step_by(usize::from(Tile::HEIGHT))) { + let alpha = u16::from(src); + *dst = (alpha + (u16::from(*dst) * (255 - alpha) + 127) / 255) as u8; + } + } else { + row.fill(255); + } + } +} + +impl Drawing { + fn composite_glyph(&mut self, path: &BezPath, transform: Affine, window: Rect) { + let clip = RectU16::new(window.x0 as u16, window.y0 as u16, window.x1 as u16, window.y1 as u16); + if clip.is_empty() { + return; + } + // Generate coverage in canvas coordinates. Moving an edge into a temporary + // bitmap can change the last coverage bit at a fractional transform. + self.generator.generate_filled_path(path.iter(), Fill::NonZero, transform, None, &mut self.strips, None); + let tiles = RectU16::new(clip.x0 / Tile::WIDTH, clip.y0 / Tile::HEIGHT, clip.x1.div_ceil(Tile::WIDTH), clip.y1.div_ceil(Tile::HEIGHT)); + let stride = usize::from(self.width); + let alphas = &self.strips.alphas; + visit_strip_fill_segments( + &self.strips.strips, + tiles, + &mut self.coverage, + |image, span| { + let bytes = alphas.get(span.alpha_idx as usize..).unwrap_or_default(); + paint_strip(image, stride, clip, span.fill, Some(bytes)); + }, + |image, span| paint_strip(image, stride, clip, span, None), + ); + } + + fn glyph(&mut self, ink: &Glyph, transform: Affine, text_bounds: Rect) -> Result<(), String> { + if ink.path.elements().is_empty() { + return Ok(()); + } + let (width, height) = (f64::from(self.width), f64::from(self.height)); + let bounds = transform.transform_rect_bbox(ink.bounds); + if !bounds.is_finite() { + return Err("non-finite text outline transform".into()); + } + let bounds = bounds.intersect(text_bounds); + if bounds.is_zero_area() { + return Ok(()); + } + let elements = ink.path.elements().len(); + let columns = copies(bounds.x0, bounds.x1, width, self.tiled[0])?; + let rows = copies(bounds.y0, bounds.y1, height, self.tiled[1])?; + if (!self.tiled[0] && (bounds.x1 <= 0.0 || bounds.x0 >= width)) || (!self.tiled[1] && (bounds.y1 <= 0.0 || bounds.y0 >= height)) { + return Ok(()); + } + let canvas = Rect::new(0.0, 0.0, width, height); + for row in rows { + for column in columns.clone() { + self.remaining = self.remaining.checked_sub(elements).ok_or("text outlines exceed the drawing budget")?; + let offset = Vec2::new(f64::from(column) * width, f64::from(row) * height); + let window = (bounds + offset).expand().intersect(canvas); + self.composite_glyph(&ink.path, Affine::translate(offset) * transform, window); + } + } + Ok(()) + } +} + +/// Draw a Text node with the bytes of its resolved package font. +pub fn text_with_font(context: &CookContext<'_>, bytes: &[u8]) -> CookResult { + let face = FontOutline::from_bytes(bytes, 0, &[]).map_err(|e| e.to_string())?; + if face.metrics().units_per_em == 0 { + return Err("font has no design units per em".into()); + } + let font = harfrust::FontRef::from_index(bytes, 0).map_err(|e| e.to_string())?; + let contours = font.glyf().ok().zip(font.loca(None).ok()); + let header = font.hhea().map_err(|e| e.to_string())?; + let ascent = f64::from(header.ascender().to_i16()); + let descent = f64::from(header.descender().to_i16()); + let height_units = ascent - descent; + if height_units <= 0.0 { + return Err("font has no positive horizontal line height".into()); + } + let pitch = height_units + f64::from(header.line_gap().to_i16()); + let data = harfrust::ShaperData::new(&font); + let shaper = data.shaper(&font).build(); + let plans = ShapePlanCache::default(); + let (w, h) = craft_texture::clamp_size(context.w, context.h); + let width = u16::try_from(w).map_err(|_| "text width exceeds the raster size")?; + let height = u16::try_from(h).map_err(|_| "text height exceeds the raster size")?; + let mut drawing = Drawing { + coverage: vec![0; usize::from(width) * usize::from(height)], + generator: StripGenerator::new(width, height, Level::try_detect().unwrap_or(Level::baseline())), + strips: StripStorage::default(), + width, + height, + tiled: context.tiling_axes(), + remaining: MAX_ELEMENTS, + }; + + let [a, b, c, d] = context.v4("matrix").map(f64::from); + let inverse = if a * d == b * c { Affine::IDENTITY } else { Affine::new([a, b, c, d, 0.0, 0.0]).inverse() }; + let [x, y] = context.v2("position").map(f64::from); + let scale = f64::from(context.f("fontsize").max(0.0)) / height_units; + let frame = Affine::scale_non_uniform(f64::from(width), f64::from(height)) + * Affine::translate((0.5 + x, 0.5 + y)) + * inverse + * Affine::scale_non_uniform(scale, -scale); + if !frame.as_coeffs().into_iter().all(f64::is_finite) { + return Err("non-finite text transform".into()); + } + let [xx, yx, xy, yy, _, _] = frame.as_coeffs(); + let pixels_per_unit = xx.hypot(xy).min(yx.hypot(yy)); + let text = context.text("text").chars().take(super::text::MAX_CHARS).collect::().replace("\\n", "\n"); + let mut cache = BTreeMap::new(); + let mut outline_budget = MAX_ELEMENTS; + let mut positioned = Vec::new(); + let mut text_bounds: Option = None; + for (line_index, line) in text.split('\n').enumerate() { + let glyphs = shape_line(line, &shaper, &plans)?; + let mut cursor = 0.0; + let mut positions = Vec::with_capacity(glyphs.len()); + let baseline = -(line_index as f64) * pitch; + let mut left = 0.0; + let mut right = 0.0; + for glyph in glyphs { + if let std::collections::btree_map::Entry::Vacant(entry) = cache.entry(glyph.glyph_id) { + let path = face.outline(glyph.glyph_id).map_err(|e| e.to_string())?; + let simple_contour = + contours.as_ref().is_some_and(|(glyf, loca)| matches!(loca.get_glyf(GlyphId::new(glyph.glyph_id), glyf), Ok(Some(StoredGlyph::Simple(_))))); + entry.insert(Glyph::new(path, simple_contour, pixels_per_unit, &mut outline_budget)?); + } + let ink = cache.get(&glyph.glyph_id).ok_or("missing glyph outline")?; + let x = cursor + f64::from(glyph.x_offset); + if positions.is_empty() { + left = x + ink.bounds.x0; + } + right = x + ink.bounds.x1; + positions.push((glyph.glyph_id, x, baseline + f64::from(glyph.y_offset))); + cursor += f64::from(glyph.x_advance); + } + let shift = match context.i("alignment") { + 0 => 0.0, + 2 => left - right, + _ => (left - right) * 0.5, + }; + let line_bounds = Rect::new(left + shift, baseline + descent, right + shift, baseline + ascent).abs(); + text_bounds = Some(text_bounds.map_or(line_bounds, |bounds| bounds.union(line_bounds))); + positioned.extend(positions.into_iter().map(|(id, x, y)| (id, x + shift, y))); + } + // The transformed text block occupies whole pixels. Ink may extend into another + // line within the block, including when a tiled copy crosses the image edge. + let text_bounds = frame.transform_rect_bbox(text_bounds.unwrap_or_default()).expand(); + if !text_bounds.is_finite() { + return Err("non-finite text bounds".into()); + } + for (id, x, y) in positioned { + if let Some(ink) = cache.get(&id) { + drawing.glyph(ink, frame * Affine::translate((x, y)), text_bounds)?; + } + } + Ok(vec![composite_text(context, |x, y| { + let index = y as usize * usize::from(width) + x as usize; + drawing.coverage.get(index).map_or(0.0, |&alpha| f32::from(alpha) / 255.0) + })]) +} diff --git a/crates/nodes/src/atomic/gradient_map.rs b/crates/nodes/src/atomic/gradient_map.rs index 413047e3..f0a83f16 100644 --- a/crates/nodes/src/atomic/gradient_map.rs +++ b/crates/nodes/src/atomic/gradient_map.rs @@ -1,6 +1,6 @@ use super::ATOMIC; -use crate::{CookContext, CookResult, NodeDefinition, node}; -use craft_texture::{Kind, luminance}; +use crate::{CookContext, CookResult, NodeDefinition, node, texture_sampler}; +use craft_texture::{Image, Kind, Limits}; use materialcraft_core::{Gradient, OutputFormat}; pub(super) fn definition() -> NodeDefinition { @@ -9,6 +9,7 @@ pub(super) fn definition() -> NodeDefinition { .atomic() .gray_in("input", "Input") .gradient("gradient", "Gradient", Gradient::default()) + .choice("interpolation", "Interpolation", &["Linear", "Smooth"], 0) .boolean("color_mode", "Color output", true) .any_out() .cook(gradient_map) @@ -16,39 +17,88 @@ pub(super) fn definition() -> NodeDefinition { fn gradient_map(context: &CookContext) -> CookResult { let input = context.gray_or(0, 0.0); - let gradient = context.gradient("gradient"); - if matches!(context.format, OutputFormat::Inherit | OutputFormat::U16) { - return Ok(vec![integer_map(&input, gradient, !context.b("color_mode"))]); - } - - const LOOKUP_INTERVALS: usize = 512; - let lookup_table: Vec<[f32; 4]> = (0..=LOOKUP_INTERVALS).map(|index| gradient.eval(index as f32 / LOOKUP_INTERVALS as f32)).collect(); let gray = !context.b("color_mode"); - let look = |v: f32| lookup_table.get((v.clamp(0.0, 1.0) * LOOKUP_INTERVALS as f32).round() as usize).copied().unwrap_or([0.0, 0.0, 0.0, 1.0]); - Ok(vec![if gray { input.map(Kind::Gray, |p| [luminance(look(p[0])), 0.0, 0.0, 0.0]) } else { input.map(Kind::Color, |p| look(p[0])) }]) + let kind = if gray { Kind::Gray } else { Kind::Color }; + let table = lookup_table(context.gradient("gradient"), context.i("interpolation") == 1, context.format, gray)?; + let width = table.width() as f32; + Ok(vec![input.map(kind, |p| { + let u = (p[0].clamp(0.0, 1.0) * (width - 1.0) + 0.5) / width; + texture_sampler::sample(&table, [u, 0.5], [false; 2], OutputFormat::F32, None) + })]) } -fn integer_map(input: &craft_texture::Image, mut gradient: Gradient, gray: bool) -> craft_texture::Image { - // The 16-bit path evaluates a 256-entry table in integer position space - // Coarse nearest sampling shifts transitions and downstream noise octaves +fn lookup_table(mut gradient: Gradient, smooth: bool, format: OutputFormat, gray: bool) -> Result { + let levels = match format { + OutputFormat::U8 => Some(255.0), + OutputFormat::Inherit | OutputFormat::U16 => Some(65535.0), + OutputFormat::F16 | OutputFormat::F32 => None, + }; + let width = if levels.is_some() { 256 } else { 1024 }; + let last_index = (width - 1) as f32; + gradient.keys.retain(|key| key.pos.is_finite()); + if gradient.keys.is_empty() { + gradient = Gradient::default(); + } + gradient.sort(); + let gray_words = gray && !smooth && matches!(format, OutputFormat::U16 | OutputFormat::Inherit); + // The first authored stop owns both sides of a shared position. + gradient.keys.dedup_by(|later, earlier| later.pos == earlier.pos); for key in &mut gradient.keys { - key.pos = (key.pos.clamp(0.0, 1.0) * 65535.0).round(); + let position = key.pos.clamp(0.0, 1.0); + key.pos = if levels.is_some() { (position * 65535.0).round() / 257.0 } else { position * last_index }; + if gray { + let [r, g, b, _] = key.color; + let level = (r + g + b) / 3.0; + key.color = [if gray_words { (level.clamp(0.0, 1.0) * 65535.0).round() / 65535.0 } else { level }; 4]; + } else if levels.is_some() { + // Integer ramp stops store byte colors even when the output uses 16 bits. + key.color = key.color.map(|v| (v.clamp(0.0, 1.0) * 255.0).round() / 255.0); + } + } + if gray_words { + // The first stop also owns a position shared after storage at word precision. + gradient.keys.dedup_by(|later, earlier| later.pos == earlier.pos); } - let table: Vec<[u32; 4]> = - (0..256).map(|index| gradient.eval(index as f32 * 257.0).map(|value| (value.clamp(0.0, 1.0) * 65535.0).round() as u32)).collect(); - let lookup = |value: f32| { - let value = if value.is_finite() { value.clamp(0.0, 1.0) } else { 0.0 }; - - // Half-texel conversion before eight-bit weights preserves ramp rounding - let position = (value * 255.0 + 0.5) - 0.5; - let fixed = (position * 256.0).round() as usize; - let index = fixed / 256; - let weight = (fixed % 256) as u32; - let left = table.get(index).copied().unwrap_or([0; 4]); - let right = table.get(index.saturating_add(1)).copied().unwrap_or(left); - std::array::from_fn(|channel| ((left[channel] * (256 - weight) + right[channel] * weight + 128) >> 8) as f32 / 65535.0) - }; - - if gray { input.map(Kind::Gray, |pixel| [luminance(lookup(pixel[0])), 0.0, 0.0, 0.0]) } else { input.map(Kind::Color, |pixel| lookup(pixel[0])) } + let mut entries = vec![gradient.keys.last().map_or([0.0; 4], |key| key.color); width]; + if let Some(first) = gradient.keys.first() { + entries.iter_mut().take(first.pos.ceil() as usize).for_each(|v| *v = first.color); + } + for pair in gradient.keys.windows(2) { + let [left, right] = pair else { continue }; + // Different authored stops can collapse to one position in an integer table. + if right.pos <= left.pos { + continue; + } + let first = left.pos.ceil() as usize; + let end = if gray { right.pos.floor() as usize + 1 } else { right.pos.ceil() as usize }; + let Some(segment) = entries.get_mut(first..end).filter(|s| !s.is_empty()) else { continue }; + let step = (right.pos - left.pos).recip(); + let mut t = (first as f32 - left.pos) * step; + let delta: [f32; 4] = std::array::from_fn(|c| right.color[c] - left.color[c]); + if smooth { + let bias = 2.0 * left.midpoint - 1.0; + for entry in segment { + let u = t * (1.0 - bias * (1.0 - t)); + *entry = if gray { + [left.color[0] + (delta[0] * u) * (u * (3.0 - 2.0 * u)); 4] + } else { + let weight = u * u * (3.0 - 2.0 * u); + std::array::from_fn(|c| left.color[c] + delta[c] * weight) + }; + // Each addition rounds at the table's working precision. + t += step; + } + } else { + let base: [f32; 4] = std::array::from_fn(|c| left.color[c] + delta[c] * t); + let slope = delta.map(|d| d * step); + for (i, entry) in segment.iter_mut().enumerate() { + *entry = std::array::from_fn(|c| base[c] + slope[c] * i as f32); + } + } + } + let data: Vec = entries.into_iter().flatten().map(|v| levels.map_or(v, |max| (v * max).round() / max)).collect(); + Image::from_data(width as u32, 1, Kind::Color, data, &Limits::default()) + .map(|image| image.with_integer_sampling(levels.is_some())) + .map_err(|err| err.to_string()) } diff --git a/crates/nodes/src/atomic/grayscale_conversion.rs b/crates/nodes/src/atomic/grayscale_conversion.rs index adec69dd..7e2625b4 100644 --- a/crates/nodes/src/atomic/grayscale_conversion.rs +++ b/crates/nodes/src/atomic/grayscale_conversion.rs @@ -19,14 +19,17 @@ pub(super) fn definition() -> NodeDefinition { fn grayscale_conversion(context: &CookContext) -> CookResult { let image = context.any_or(0, Kind::Color, [0.0, 0.0, 0.0, 1.0]).to_color(); - let weights = [context.f("red"), context.f("green"), context.f("blue"), context.f("alpha")]; + let weights = context + .value("weights") + .and_then(materialcraft_core::Value::as_vec4) + .unwrap_or_else(|| [context.f("red"), context.f("green"), context.f("blue"), context.f("alpha")]); let flatten = context.b("flatten_alpha"); let matte = context.f("matte"); Ok(vec![image.map(Kind::Gray, |pixel| { // Preserve the fused, ordered dot product through float image storage - let mut value = pixel[3].mul_add(weights[3], pixel[2].mul_add(weights[2], pixel[1].mul_add(weights[1], pixel[0] * weights[0]))); + let mut value = pixel.into_iter().zip(weights).fold(0.0, |sum, (channel, weight)| channel.mul_add(weight, sum)); if flatten { - value = value * pixel[3] + matte * (1.0 - pixel[3]); + value = (matte - value).mul_add(1.0 - pixel[3], value); } [value, 0.0, 0.0, 0.0] })]) diff --git a/crates/nodes/src/atomic/hsl.rs b/crates/nodes/src/atomic/hsl.rs index c9184a35..336d1446 100644 --- a/crates/nodes/src/atomic/hsl.rs +++ b/crates/nodes/src/atomic/hsl.rs @@ -1,11 +1,11 @@ use super::ATOMIC; -use crate::ops; +use crate::function::pixel_divide; use crate::{CookContext, CookResult, NodeDefinition, node}; use craft_texture::Kind; pub(super) fn definition() -> NodeDefinition { node("hsl", "HSL", ATOMIC) - .desc("Hue, saturation and lightness adjustments (0.5 = unchanged).") + .desc("Adjust hue, saturation and lightness around the midpoint of each slider.") .atomic() .color_in("input", "Input") .float("hue", "Hue", 0.5, 0.0, 1.0) @@ -17,15 +17,45 @@ pub(super) fn definition() -> NodeDefinition { fn hsl(context: &CookContext) -> CookResult { let image = context.any_or(0, Kind::Color, [0.0; 4]).to_color(); + let hue_shift = context.f("hue") * 12.0 - 6.0; + let [saturation_shift, lightness_shift] = ["saturation", "lightness"].map(|name| (context.f(name) - 0.5) * 2.0); - // The normalized slider spans one full turn in either direction from its midpoint - let (hue_shift, saturation, lightness) = ((context.f("hue") - 0.5) * 2.0, context.f("saturation"), context.f("lightness")); + Ok(vec![image.map(Kind::Color, |[red, green, blue, alpha]| { + let gain = red.max(green).max(blue).max(1.0); + let scale = pixel_divide(1.0, gain); + let [r, g, b] = [red * scale, green * scale, blue * scale]; + let low = r.min(g).min(b); + let high = r.max(g).max(b); + let chroma = high - low; + let lightness = (low + high) * 0.5; - Ok(vec![image.map(Kind::Color, |pixel| { - let [h, s, l] = ops::rgb_to_hsl(pixel); - let s = if saturation <= 0.5 { s * saturation * 2.0 } else { s + (1.0 - s) * (saturation - 0.5) * 2.0 }; - let l = if lightness <= 0.5 { l * lightness * 2.0 } else { l + (1.0 - l) * (lightness - 0.5) * 2.0 }; - let color = ops::hsl_to_rgb(h + hue_shift, s.clamp(0.0, 1.0), l.clamp(0.0, 1.0)); - [color[0], color[1], color[2], pixel[3]] + // The nonzero divisors also affect ordinary colors at the slider midpoints. + const EPSILON: f32 = 1.0 / 4096.0; + let chroma_range = |lightness: f32| 1.0 - (2.0 * lightness - 1.0).abs(); + let s = if chroma == 0.0 { saturation_shift } else { chroma.mul_add(pixel_divide(1.0, chroma_range(lightness) + EPSILON), saturation_shift) }; + let s = s.clamp(0.0, 1.0); + let l = (lightness + lightness_shift).clamp(0.0, 1.0); + + let (left, right, sector) = if low == r { + (b, g, 3.0) + } else if low == g { + (r, b, 5.0) + } else { + (g, r, 1.0) + }; + // Round the bias with the subtracted channel. Raising saturation makes + // this rounding visible even when all three input channels are equal. + let difference = left - (right + 3.0 * EPSILON); + let sextants = difference.mul_add(pixel_divide(1.0, chroma + EPSILON), sector) + hue_shift; + // Remove whole turns in the multiply-add. Rounding the product first loses the residual at the wrap. + const SIXTH: f32 = 1.0 / 6.0; + let hue = sextants.mul_add(SIXTH, -(sextants * SIXTH).floor()); + let upper = s.mul_add(0.5 * chroma_range(l), l); + let lower = 2.0 * l - upper; + let channel = |weight: f32| (upper - lower).mul_add(weight.clamp(0.0, 1.0), lower) * gain; + let red = (hue - 0.5).abs().mul_add(6.0, -1.0); + let green = (hue - 1.0 / 3.0).abs().mul_add(-6.0, 2.0); + let blue = (hue - 2.0 / 3.0).abs().mul_add(-6.0, 2.0); + [channel(red), channel(green), channel(blue), alpha] })]) } diff --git a/crates/nodes/src/atomic/input_resize.rs b/crates/nodes/src/atomic/input_resize.rs new file mode 100644 index 00000000..0d4206ac --- /dev/null +++ b/crates/nodes/src/atomic/input_resize.rs @@ -0,0 +1,116 @@ +use crate::CookContext; +use craft_texture::{Image, Kind}; +use materialcraft_core::OutputFormat; + +#[derive(Clone, Copy, PartialEq, Eq)] +pub(crate) enum InputResize { + Copy, + Filter, + Levels, + PatternBackground, + Sampled, +} + +pub(crate) fn resized_input(context: &CookContext, port: usize, mode: InputResize) -> Option { + resized_texture(context, port, mode).map(|(image, _)| image) +} + +/// A single filter pass can draw from clamped samples unless an enlarged axis repeats. +/// A longer resize stores its intermediate textures before drawing. +pub fn direct_background_sample(image: &Image, target: (u32, u32), source: OutputFormat, tiling: [bool; 2]) -> Option { + let size = (image.width(), image.height()); + let enlarged_tiled_axis = (target.0 > size.0 && tiling[0]) || (target.1 > size.1 && tiling[1]); + if size == target || enlarged_tiled_axis || crate::texture_sampler::next_filter_size(size, target) != target { + return None; + } + let image = prepare_pattern_background(image.clone(), InputResize::PatternBackground, source, false); + let filtered = crate::texture_sampler::resize_input_level(&image, target.0, target.1, source, [false; 2]); + let enlarged = target.0 > size.0 || target.1 > size.1; + Some(prepare_pattern_background(filtered, InputResize::PatternBackground, source, enlarged)) +} + +pub(super) fn blur_input(context: &CookContext, intensity: f32) -> (Image, OutputFormat) { + // A zero intensity copies through the destination format. Even a subpixel blur uses the working precision. + let mode = if intensity == 0.0 { InputResize::Copy } else { InputResize::Filter }; + resized_texture(context, 0, mode).unwrap_or_else(|| (Image::filled(context.w, context.h, Kind::Gray, [0.0; 4]), OutputFormat::F32)) +} + +pub(super) fn sampled_input(context: &CookContext, port: usize) -> (Image, OutputFormat) { + resized_texture(context, port, InputResize::Sampled).unwrap_or_else(|| (Image::filled(context.w, context.h, Kind::Gray, [0.0; 4]), context.format)) +} + +fn clear_zero_signs(pixel: [f32; 4]) -> [f32; 4] { + pixel.map(|v| if v == 0.0 { 0.0 } else { v }) +} + +/// Color conversion preserves negative zero in every channel when all three RGB signs are negative. +pub(super) fn converted_color(pixel: [f32; 4]) -> [f32; 4] { + if pixel[..3].iter().any(|v| v.is_sign_positive()) { clear_zero_signs(pixel) } else { pixel } +} + +fn prepare_pattern_background(image: Image, mode: InputResize, source: OutputFormat, enlarged: bool) -> Image { + if mode != InputResize::PatternBackground { + return image; + } + let gray = image.kind() == Kind::Gray; + let flush = source == OutputFormat::F32; + let enlarged_color = enlarged && !gray && matches!(source, OutputFormat::F16 | OutputFormat::F32); + if !flush && !enlarged_color { + return image; + } + let needs_change = |&v: &f32| (flush && v.is_subnormal()) || ((gray || enlarged_color) && v.to_bits() == (-0.0_f32).to_bits()); + if !image.data().iter().any(needs_change) { + return image; + } + image.map(image.kind(), |pixel| { + let pixel = if flush { pixel.map(crate::function::flush_subnormal) } else { pixel }; + if gray { + clear_zero_signs(pixel) + } else if enlarged_color { + converted_color(pixel) + } else { + pixel + } + }) +} + +fn resized_texture(context: &CookContext, port: usize, mode: InputResize) -> Option<(Image, OutputFormat)> { + let mut image = context.input(port)?.clone(); + let mut source = context.input_formats.get(port).copied().unwrap_or(if image.integer_sampling() { OutputFormat::U16 } else { OutputFormat::F32 }); + image = prepare_pattern_background(image, mode, source, false); + let target = craft_texture::clamp_size(context.w, context.h); + let size = (image.width(), image.height()); + // A sampled filter can take its final taps directly from an input up to one level larger on either axis. + let direct = + mode == InputResize::Sampled && (target.0..=target.0.saturating_mul(2)).contains(&size.0) && (target.1..=target.1.saturating_mul(2)).contains(&size.1); + if size == target || direct { + return Some((image, source)); + } + let storage = if mode == InputResize::Copy { + context.format + } else { + use OutputFormat::*; + match (source, context.format) { + (F32, _) | (_, F32) => F32, + (F16, _) | (_, F16) => F16, + (U8, U8) => U8, + _ => U16, + } + }; + loop { + let current = (image.width(), image.height()); + let (w, h) = crate::texture_sampler::next_filter_size(current, target); + image = crate::texture_sampler::resize_input_level(&image, w, h, source, context.tiling_axes()); + image = prepare_pattern_background(image, mode, source, (w, h) == target && (w > size.0 || h > size.1)); + // A final reduction can feed the Levels curve directly. An enlargement stores the + // filtered texels first, which matters when the working image uses half precision. + if mode == InputResize::Levels && (w, h) == target && w <= current.0 && h <= current.1 { + return Some((image, source)); + } + image = crate::output_precision::apply(image, storage); + if (w, h) == target { + return Some((image, storage)); + } + source = storage; + } +} diff --git a/crates/nodes/src/atomic/levels.rs b/crates/nodes/src/atomic/levels.rs index f23a118b..c0252ffa 100644 --- a/crates/nodes/src/atomic/levels.rs +++ b/crates/nodes/src/atomic/levels.rs @@ -1,6 +1,8 @@ use super::ATOMIC; +use super::input_resize::{InputResize, resized_input}; use crate::{CookContext, CookResult, NodeDefinition, node}; -use craft_texture::Kind; +use craft_texture::{Image, Kind}; +use materialcraft_core::{OutputFormat, Value}; pub(super) fn definition() -> NodeDefinition { node("levels", "Levels", ATOMIC) @@ -12,41 +14,84 @@ pub(super) fn definition() -> NodeDefinition { .float4("in_high", "Level in high", [1.0; 4], 0.0, 1.0) .float4("out_low", "Level out low", [0.0; 4], 0.0, 1.0) .float4("out_high", "Level out high", [1.0; 4], 0.0, 1.0) + .boolean("clamp_intermediate", "Clamp intermediate values", true) .any_out() .cook(levels) } fn levels(context: &CookContext) -> CookResult { - let image = context.any_or(0, Kind::Gray, [0.0; 4]); - let low = context.v4("in_low"); - let mid = context.v4("in_mid"); - let high = context.v4("in_high"); - let output_low = context.v4("out_low"); - let output_high = context.v4("out_high"); + let image = resized_input(context, 0, InputResize::Levels).unwrap_or_else(|| Image::filled(context.w, context.h, Kind::Gray, [0.0; 4])); + let control = |name| { + if image.is_gray() + && let Some(Value::Float(level)) = context.value(name) + { + return [*level; 4]; + } + let rgba = context.v4(name); + if image.is_gray() { [(rgba[0] + rgba[1] + rgba[2]) / 3.0; 4] } else { rgba } + }; + let endpoint = |name| { + let values = control(name); + match context.format { + OutputFormat::U8 | OutputFormat::U16 | OutputFormat::Inherit => values.map(|v| v.clamp(0.0, 1.0)), + OutputFormat::F16 | OutputFormat::F32 => values, + } + }; + let low = endpoint("in_low"); + let mid = control("in_mid"); + let high = endpoint("in_high"); + let output_low = endpoint("out_low"); + let output_high = endpoint("out_high"); + let clamp = context.b("clamp_intermediate"); - Ok(vec![image.map(image.kind(), |pixel| { - std::array::from_fn(|channel| levels_fn(pixel[channel], low[channel], mid[channel], high[channel], output_low[channel], output_high[channel])) - })]) + let ranges: [_; 4] = std::array::from_fn(|c| ChannelRange::new(low[c], mid[c], high[c], output_low[c], output_high[c])); + Ok(vec![image.map(image.kind(), |pixel| std::array::from_fn(|c| ranges[c].map(pixel[c], clamp)))]) } pub fn levels_fn(v: f32, in_low: f32, in_mid: f32, in_high: f32, out_low: f32, out_high: f32) -> f32 { - let span = in_high - in_low; - let t = if span.abs() < 1e-6 { if v >= in_high { 1.0 } else { 0.0 } } else { ((v - in_low) / span).clamp(0.0, 1.0) }; + ChannelRange::new(in_low, in_mid, in_high, out_low, out_high).map(v, true) +} - // NaN (from an input or a hostile parameter) would otherwise spread through the graph - let t = if t.is_finite() { t } else { 0.0 }; - let mid = if in_mid.is_finite() { in_mid.clamp(0.0, 1.0) } else { 0.5 }; +struct ChannelRange { + in_low: f32, + scale: f32, + gamma: f32, + out_low: f32, + out_span: f32, +} - // The midpoint slider controls reciprocal gamma below neutral and gamma above it - // Treating it as an input value that maps to 0.5 changes authored levels curves - let g = if mid <= 0.5 { 1.0 / (9.0 - 16.0 * mid) } else { 16.0 * mid - 7.0 }; - out_low + t.powf(g) * (out_high - out_low) +impl ChannelRange { + fn new(in_low: f32, in_mid: f32, in_high: f32, out_low: f32, out_high: f32) -> Self { + let span = in_high - in_low; + // Coincident endpoints use the slope of a 0.0001-wide interval. Narrow nonzero spans retain their own slope. + let scale = if span == 0.0 { 10_000.0 } else { span.recip() }; + // The texture evaluator flushes a subnormal slope before it multiplies the input. + let scale = if scale.is_subnormal() { 0.0_f32.copysign(scale) } else { scale }; + let mid = if in_mid.is_finite() { in_mid.clamp(0.0, 1.0) } else { 0.5 }; + let gamma = if mid <= 0.5 { (9.0 - 16.0 * mid).recip() } else { 16.0 * mid - 7.0 }; + Self { in_low, scale, gamma, out_low, out_span: out_high - out_low } + } + + fn map(&self, value: f32, clamp: bool) -> f32 { + let t = (value - self.in_low) * self.scale; + // A nonfinite input or range must not spread NaN through the graph. + let t = if t.is_finite() { t } else { 0.0 }; + let t = if clamp { t.clamp(0.0, 1.0) } else { t }; + let curved = if t == 0.0 || t == 1.0 { t } else { crate::function::signed_pixel_power(t, self.gamma) }; + curved.mul_add(self.out_span, self.out_low) + } } #[cfg(test)] mod levels_tests { use super::levels_fn; + #[test] + fn enormous_ranges_flush_the_reciprocal_before_scaling_the_pixel() { + assert!(levels_fn(3.0, 0.0, 0.5, 2.0_f32.powi(125), 0.0, 1.0) > f32::MIN_POSITIVE); + assert_eq!(levels_fn(3.0, 0.0, 0.5, 2.0_f32.powi(127), 0.0, 1.0).to_bits(), 0); + } + #[test] fn levels_remaps_the_input_range_midtones_and_output_range() { let close = |a: f32, b: f32| (a - b).abs() < 1e-5; @@ -69,9 +114,10 @@ mod levels_tests { assert!(close(levels_fn(0.5, 0.0, 0.5, 1.0, 0.2, 0.6), 0.4)); assert!(close(levels_fn(0.0, 0.0, 0.5, 1.0, 1.0, 0.0), 1.0)); - // A collapsed input range is a threshold; NaN never escapes + // At coincident endpoints the low output begins a steep finite ramp. assert_eq!(levels_fn(0.49, 0.5, 0.5, 0.5, 0.0, 1.0), 0.0); - assert_eq!(levels_fn(0.5, 0.5, 0.5, 0.5, 0.0, 1.0), 1.0); + assert_eq!(levels_fn(0.5, 0.5, 0.5, 0.5, 0.0, 1.0), 0.0); + assert_eq!(levels_fn(0.51, 0.5, 0.5, 0.5, 0.0, 1.0), 1.0); assert!(levels_fn(f32::NAN, 0.0, 0.5, 1.0, 0.0, 1.0).is_finite()); assert!(levels_fn(0.5, f32::NAN, 0.5, f32::NAN, 0.0, 1.0).is_finite()); } diff --git a/crates/nodes/src/atomic/mod.rs b/crates/nodes/src/atomic/mod.rs index 07cb0968..901e0158 100644 --- a/crates/nodes/src/atomic/mod.rs +++ b/crates/nodes/src/atomic/mod.rs @@ -9,12 +9,14 @@ mod directional_warp; mod distance; mod dot; mod emboss; +mod font; mod gradient_dynamic; mod gradient_map; mod grayscale_conversion; mod hsl; mod input_color; mod input_grayscale; +pub(crate) mod input_resize; mod input_value; mod levels; mod normal; @@ -38,6 +40,8 @@ use direction::direction; pub const ATOMIC: &str = "Atomic nodes"; pub const GRAPH_ITEMS: &str = "Graph items"; +pub use blend::{blend_selected_input, blend_with_opacity}; +pub use font::text_with_font; pub use levels::levels_fn; pub use normal::height_to_normal; pub use output::output_kind; diff --git a/crates/nodes/src/atomic/pattern_map.rs b/crates/nodes/src/atomic/pattern_map.rs index 555af1f7..0ce91660 100644 --- a/crates/nodes/src/atomic/pattern_map.rs +++ b/crates/nodes/src/atomic/pattern_map.rs @@ -6,7 +6,7 @@ pub(super) fn definition() -> NodeDefinition { node("fx_map", "FX-Map", ATOMIC) .desc("Places patterns using Quadrant, Switch and Iterate nodes.") .atomic() - .generator() + .inherit_from("background") .any_in("background", "Background") .any_in("pattern0", "Input image 0") .pattern_graph("pattern", "FX-Map graph", PatternGraph::with_root(PatternNodeKind::Quadrant)) @@ -16,6 +16,7 @@ pub(super) fn definition() -> NodeDefinition { .color("background", "Background color", [0.0; 4]) .float4("render_region", "Render region", [0.0, 1.0, 0.0, 1.0], -65536.0, 65536.0) .float4("tiling_region", "Tiling region", [0.0, 1.0, 0.0, 1.0], 0.0, 1.0) + .boolean("cull_outside", "Cull outside", false) .any_out() .cook(crate::pattern::cook) } diff --git a/crates/nodes/src/atomic/pixel_processor.rs b/crates/nodes/src/atomic/pixel_processor.rs index a0a34d43..21995e73 100644 --- a/crates/nodes/src/atomic/pixel_processor.rs +++ b/crates/nodes/src/atomic/pixel_processor.rs @@ -5,6 +5,7 @@ pub(super) fn definition() -> NodeDefinition { node("pixel_processor", "Pixel processor", ATOMIC) .desc("Computes every pixel with a function graph ($pos, $size; sample the inputs).") .atomic() + .generator() .any_in("input0", "Input image 0") .function("function", "Per pixel function", materialcraft_core::FunctionGraph::default()) .boolean("color_mode", "Color output", true) diff --git a/crates/nodes/src/atomic/sharpen.rs b/crates/nodes/src/atomic/sharpen.rs index 52b4e98b..e69c55b4 100644 --- a/crates/nodes/src/atomic/sharpen.rs +++ b/crates/nodes/src/atomic/sharpen.rs @@ -1,6 +1,7 @@ use super::ATOMIC; +use super::input_resize::sampled_input; use crate::{CookContext, CookResult, NodeDefinition, node}; -use craft_texture::{Image, Kind}; +use craft_texture::Image; pub(super) fn definition() -> NodeDefinition { node("sharpen", "Sharpen", ATOMIC) @@ -13,38 +14,42 @@ pub(super) fn definition() -> NodeDefinition { } fn sharpen(context: &CookContext) -> CookResult { - let input = context.any_or(0, Kind::Gray, [0.0; 4]); + let (input, format) = sampled_input(context, 0); + let (width, height) = craft_texture::clamp_size(context.w, context.h); + let same_size = (width, height) == (input.width(), input.height()); let intensity = context.f("intensity"); let tile = context.tiling_axes(); let short_side = context.w.min(context.h) as f32; let horizontal = intensity * short_side / context.w.max(1) as f32; let vertical = intensity * short_side / context.h.max(1) as f32; + let center_weight = 1.0 + 2.0 * (horizontal + vertical); Ok(vec![Image::generate(context.w, context.h, input.kind(), |x, y| { - let (x, y) = (i64::from(x), i64::from(y)); - let center = input.get(x, y, false); - let left = input.get_axes(x - 1, y, tile); - let right = input.get_axes(x + 1, y, tile); - let top = input.get_axes(x, y - 1, tile); - let bottom = input.get_axes(x, y + 1, tile); + let offsets = [(0, 0), (-1, 0), (1, 0), (0, -1), (0, 1)]; + let [center, left, right, top, bottom] = if same_size { + offsets.map(|(dx, dy)| input.get_axes(i64::from(x) + dx, i64::from(y) + dy, tile)) + } else { + let u = (x as f32 + 0.5) / width as f32; + let v = (y as f32 + 0.5) / height as f32; + offsets.map(|(dx, dy)| { + let uv = [u + dx as f32 / input.width() as f32, v + dy as f32 / input.height() as f32]; + crate::texture_sampler::sample(&input, uv, tile, format, None) + }) + }; std::array::from_fn(|channel| { - // Keep the axial differences separate to preserve Float32 cancellation order - let twice_center = 2.0 * center[channel]; - let across = axial_difference(center[channel], twice_center, left[channel], right[channel]); - let down = axial_difference(center[channel], twice_center, top[channel], bottom[channel]); - - // Float outputs retain HDR values but discard negative sharpening lobes - (center[channel] + (across * horizontal + down * vertical)).max(0.0) + let [center, left, right, top, bottom] = [center[channel], left[channel], right[channel], top[channel], bottom[channel]]; + let sum = center.mul_add(center_weight, -horizontal * left); + let sum = right.mul_add(-horizontal, sum); + let sum = top.mul_add(-vertical, sum); + let result = bottom.mul_add(-vertical, sum); + if result.is_finite() || ![center, left, right, top, bottom].iter().all(|v| v.is_finite()) { + return result; + } + // A finite HDR plateau can overflow the weighted center before its neighbors cancel. + let center = f64::from(center); + let across = 2.0 * center - (f64::from(left) + f64::from(right)); + let down = 2.0 * center - (f64::from(top) + f64::from(bottom)); + (center + across * f64::from(horizontal) + down * f64::from(vertical)) as f32 }) })]) } - -fn axial_difference(center: f32, twice_center: f32, first: f32, second: f32) -> f32 { - let difference = twice_center - (first + second); - if difference.is_finite() || ![center, first, second].iter().all(|value| value.is_finite()) { - return difference; - } - - // Finite HDR inputs can overflow both Float32 sums and turn their difference into NaN - (2.0 * f64::from(center) - (f64::from(first) + f64::from(second))) as f32 -} diff --git a/crates/nodes/src/atomic/text.rs b/crates/nodes/src/atomic/text.rs index 3d073890..3ea580d4 100644 --- a/crates/nodes/src/atomic/text.rs +++ b/crates/nodes/src/atomic/text.rs @@ -1,7 +1,7 @@ //! Original single-stroke font rendered as anti-aliased capsules use crate::atomic::ATOMIC; -use crate::raster::{CapsuleRaster, CapsuleSegment, composite}; +use crate::raster::{CapsuleRaster, CapsuleSegment, composite_text}; use crate::{CookContext, CookResult, NodeDefinition, node}; /// The font: each glyph is strokes separated by spaces, each stroke a polyline of `xy` digit pairs on a grid 4 wide where y = 0 is the cap height, 2 the x-height, 6 the baseline and 8 the descender @@ -108,11 +108,11 @@ fn strokes(s: &str) -> impl Iterator> + '_ { } /// Longest text drawn (an allocation cap) -const MAX_CHARS: usize = 10_000; +pub(super) const MAX_CHARS: usize = 10_000; pub(super) fn definition() -> NodeDefinition { node("text", "Text", ATOMIC) - .desc("Draws text with a built-in single-stroke font (A–Z, a–z, 0–9, punctuation). \\n starts a new line.") + .desc("Draws text with the selected package font or the built-in single-stroke font. \\n starts a new line.") .atomic() .generator() .any_in("background", "Background") @@ -173,13 +173,13 @@ fn layout(context: &CookContext, text: &str) -> Vec { fn text(context: &CookContext) -> CookResult { if !context.text("fontdata").is_empty() { - return Err("external fonts are not supported yet; clear Font reference to use the built-in stroke font".into()); + return Err(format!("font resource `{}` is unavailable", context.text("fontdata"))); } let text: String = context.text("text").replace("\\n", "\n").chars().take(MAX_CHARS).collect(); let radius = 0.7 * context.f("fontsize").max(0.0) * context.h as f32 / 16.0; let raster = CapsuleRaster::new(layout(context, &text), radius, context.w, context.h, context.tile); - Ok(vec![composite(context, |x, y| [1.0, 1.0, 1.0, raster.coverage(x as f32 + 0.5, y as f32 + 0.5)])]) + Ok(vec![composite_text(context, |x, y| raster.coverage(x as f32 + 0.5, y as f32 + 0.5))]) } #[cfg(test)] @@ -209,6 +209,7 @@ mod tests { let no_res = |_: &str| None; let vars = BTreeMap::new(); let context = CookContext { + input_formats: &[], format: materialcraft_core::OutputFormat::F32, w: 256, h: 256, diff --git a/crates/nodes/src/atomic/transformation.rs b/crates/nodes/src/atomic/transformation.rs index 3d4eabd9..3710aa10 100644 --- a/crates/nodes/src/atomic/transformation.rs +++ b/crates/nodes/src/atomic/transformation.rs @@ -11,6 +11,8 @@ pub(super) fn definition() -> NodeDefinition { .float2("offset", "Offset", [0.0; 2], -1.0, 1.0) .float4("matrix", "Transform matrix", [1.0, 0.0, 0.0, 1.0], -10.0, 10.0) .choice("filtering", "Filtering", &["Bilinear", "Nearest"], 0) + .choice("mip_mode", "Mipmap mode", &["Automatic", "Manual"], 0) + .int("mip_level", "Mipmap level", 0, 0, 13) .color("matte", "Matte color", [0.0; 4]) .any_out() .cook(transformation) @@ -28,63 +30,336 @@ fn transformation(context: &CookContext) -> CookResult { } let nearest = context.i("filtering") == 1; - let input = if nearest { nearest_mip(input, matrix, context) } else { input }; - let matte = context.v4("matte"); - - // Keep independent wrap axes for panoramic images - let tiling = context.vars.get("$tiling").and_then(materialcraft_core::Value::as_i32).map_or([context.tile; 2], |mask| [mask & 1 != 0, mask & 2 != 0]); + let source_format = context.input_formats.first().copied().unwrap_or(if input.integer_sampling() { OutputFormat::U16 } else { OutputFormat::F32 }); + let tiling = context.tiling_axes(); + let centered = offset == [0.0; 2] && matches!(matrix, [1.0 | -1.0, 0.0, 0.0, 1.0 | -1.0] | [0.0, 1.0 | -1.0, 1.0 | -1.0, 0.0]); + let (input, sample_format) = if centered && !nearest && context.i("mip_mode") == 0 { + let target = if matrix[0] == 0.0 { [context.h, context.w] } else { [context.w, context.h] }; + resize_intermediate_levels(input, target, source_format, context.format, tiling) + } else { + let levels = mip_level(&input, matrix, context); + let sample_format = if levels > 0 && (input.width() > 1 || input.height() > 1) { context.format } else { source_format }; + (reduce_mip(input, levels, source_format, context.format), sample_format) + }; + let matte = crate::output_precision::store_pixel(context.v4("matte"), sample_format); + // A centered resize extends an untiled edge texel, including after a manually selected mip. + let border = (!centered).then_some(matte); + // Fold the pivot into the translation once. SBS stores matrix columns consecutively. + let translation = [0.5 - (0.5 * matrix[0] + 0.5 * matrix[2]) + offset[0], 0.5 - (0.5 * matrix[1] + 0.5 * matrix[3]) + offset[1]]; Ok(vec![Image::generate_uv(context.w, context.h, input.kind(), |u, v| { - let x = u - 0.5; - let y = v - 0.5; - - // SBS stores matrix columns consecutively; interpreting rows reverses rotations - let source_u = matrix[0] * x + matrix[2] * y + 0.5 + offset[0]; - let source_v = matrix[1] * x + matrix[3] * y + 0.5 + offset[1]; - if (!tiling[0] && !(0.0..1.0).contains(&source_u)) || (!tiling[1] && !(0.0..1.0).contains(&source_v)) { - matte - } else if nearest { - input.sample_nearest_axes(source_u, source_v, tiling) + let source_u = matrix[2].mul_add(v, matrix[0] * u) + translation[0]; + let source_v = matrix[3].mul_add(v, matrix[1] * u) + translation[1]; + if nearest { + if (!tiling[0] && !(0.0..1.0).contains(&source_u)) || (!tiling[1] && !(0.0..1.0).contains(&source_v)) { + matte + } else { + input.sample_nearest_axes(source_u, source_v, tiling) + } } else { - input.sample_axes(source_u, source_v, tiling) + crate::texture_sampler::sample(&input, [source_u, source_v], tiling, sample_format, border) } })]) } -fn nearest_mip(mut input: Image, matrix: [f32; 4], context: &CookContext) -> Image { +fn resize_intermediate_levels( + mut input: Image, + target: [u32; 2], + mut source_format: OutputFormat, + destination_format: OutputFormat, + tiling: [bool; 2], +) -> (Image, OutputFormat) { + let source = [input.width(), input.height()]; + let mut next = target.map(|n| n.clamp(1, craft_texture::MAX_SIDE)); + let mut levels = Vec::new(); + // Work back from the output so axes with unequal ratios reach their final step together. + // For example, 16×16 to 64×32 passes through 32×16. + while next != source { + next = std::array::from_fn(|i| if next[i] > source[i] { next[i].div_ceil(2).max(source[i]) } else { next[i].saturating_mul(2).min(source[i]) }); + if next != source { + levels.push(next); + } + } + for [width, height] in levels.into_iter().rev() { + input = crate::texture_sampler::resize_input_level(&input, width, height, source_format, tiling); + input = crate::output_precision::apply(input, destination_format); + source_format = destination_format; + } + (input, source_format) +} + +fn mip_level(input: &Image, matrix: [f32; 4], context: &CookContext) -> u32 { + // Thirteen reductions cover the maximum supported side of 8192 texels. + if context.i("mip_mode") == 1 { + return context.i("mip_level").clamp(0, 13) as u32; + } let width = context.w.max(1) as f32; let height = context.h.max(1) as f32; - let dx = (matrix[0] * input.width() as f32 / width).hypot(matrix[1] * input.height() as f32 / width); - let dy = (matrix[2] * input.width() as f32 / height).hypot(matrix[3] * input.height() as f32 / height); - - // Thirteen reductions cover the maximum supported side of 8192 texels - let levels = dx.max(dy).max(1.0).log2().round().clamp(0.0, 13.0) as u32; - let maximum = match context.format { - OutputFormat::U8 => Some(255.0), - OutputFormat::Inherit | OutputFormat::U16 => Some(65535.0), - OutputFormat::F16 | OutputFormat::F32 => None, + // Measure each source coordinate's gradient over both output axes, in source texels. + let gradient_squared = |dx: f32, dy: f32, size: u32| { + let x = dx * (size as f32 / width); + let y = dy * (size as f32 / height); + x * x + y * y }; + let u = gradient_squared(matrix[0], matrix[2], input.width()); + let v = gradient_squared(matrix[1], matrix[3], input.height()); + // Round the natural log of the squared footprint before converting it to a mip level. + let log_footprint = f64::from(u.max(v).max(1.0)).ln() as f32; + let level = 0.5 * (log_footprint / std::f32::consts::LN_2); + // The fractional level is rounded to ten bits before selecting the nearest image. + const LEVEL_STEPS: f32 = 1024.0; + let stored_level = (level * LEVEL_STEPS).round() / LEVEL_STEPS; + stored_level.round().clamp(0.0, 13.0) as u32 +} +fn reduce_mip(mut input: Image, levels: u32, mut source_format: OutputFormat, format: OutputFormat) -> Image { for _ in 0..levels { if input.width() <= 1 && input.height() <= 1 { break; } - // Integer mip levels round four-texel averages halfway up - input = Image::generate(input.width().div_ceil(2), input.height().div_ceil(2), input.kind(), |x, y| { - let (x, y) = (i64::from(x) * 2, i64::from(y) * 2); - let pixels = [input.get(x, y, false), input.get(x + 1, y, false), input.get(x, y + 1, false), input.get(x + 1, y + 1, false)]; - std::array::from_fn(|channel| { - if let Some(maximum) = maximum { - let sum: u32 = pixels.iter().map(|pixel| (pixel[channel].clamp(0.0, 1.0) * maximum).round() as u32).sum(); - ((sum + 2) / 4) as f32 / maximum - } else { - // Average in f64 so finite HDR texels cannot overflow the sum - (pixels.iter().map(|pixel| f64::from(pixel[channel])).sum::() * 0.25) as f32 - } - }) - }); + // Both final filters read the same mip chain. Each reduction samples at the preceding level's precision. + input = crate::texture_sampler::reduce_level(&input, source_format, format); + source_format = format; } input } + +#[cfg(test)] +mod tests { + use super::*; + use crate::resolve_params; + use materialcraft_core::Value; + use std::collections::BTreeMap; + + #[test] + fn automatic_mip_samples_near_half_level_boundaries() { + let vars = BTreeMap::new(); + for (source, output, matrix, corner, interior) in [ + ([64; 2], [64; 2], [1.0, -1.0, 1.0, 1.0], 0x3f1bdc1c, 0x3ee969e9), + ([64; 2], [64; 2], [0.995, -0.995, 0.995, 0.995], 0x3f45eac6, 0x3eee42ee), + ([64; 2], [64; 2], [0.9998, -0.9998, 0.9998, 0.9998], 0x3f1c4282, 0x3ee9c847), + ([64; 2], [64; 2], [1.4139308, 0.0, 0.0, 0.875], 0x3f18f838, 0x3f061050), + ([64; 2], [64; 2], [1.9993231, -1.9993231, 1.9993231, 1.9993231], 0x3f351f60, 0x3eee62e2), + ([64; 2], [64; 2], [0.625, 2.7598505, -0.34375, 0.61466354], 0x3f033f7f, 0x3f0292d2), + ([64; 2], [64; 2], [0.625, 4.667103, -0.34375, 10.302016], 0x3f02df1f, 0x3ef555d5), + ([64; 2], [64; 2], [1.9996, -1.9996, 1.9996, 1.9996], 0x3f353172, 0x3eee62e2), + ([64; 2], [64; 2], [3.9992, -3.9992, 3.9992, 3.9992], 0x3f163273, 0x3ef48504), + ([64; 2], [64; 2], [1.2, 0.9, 0.19, 0.13], 0x3f2c8cad, 0x3e7988fa), + ([64; 2], [64; 2], [1.2, 0.19, 0.9, 0.13], 0x3f00abeb, 0x3f265292), + ([128, 32], [64; 2], [1.0, -1.0, 1.0, 1.0], 0x3f054585, 0x3ef272f2), + ([128, 32], [32, 128], [1.2, 0.9, 0.19, 0.13], 0x3ef1be3d, 0x3f0bd212), + ] { + let input = Image::gray(source[0], source[1], |x, y| ((13 * x + 19 * y + 7 * x * y) % 256) as f32 / 255.0).with_integer_sampling(true); + let params = resolve_params(&definition(), &BTreeMap::from([("matrix".into(), Value::Float4(matrix))])); + let context = CookContext { + w: output[0], + h: output[1], + seed: 0, + format: OutputFormat::F32, + tile: true, + inputs: &[Some(input)], + input_formats: &[OutputFormat::U8], + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + let image = transformation(&context).unwrap(); + assert_eq!(image[0].get_gray(0, 0, false).to_bits(), corner, "{matrix:?}"); + assert_eq!(image[0].get_gray(19, 43, false).to_bits(), interior, "{matrix:?}"); + } + } + + #[test] + fn affine_texture_coordinates_keep_the_fraction_at_rotated_texel_boundaries() { + let image = Image::generate(128, 128, Kind::Color, |x, y| [(x & 1) as f32, (y & 1) as f32, ((x / 2) & 1) as f32, ((y / 2) & 1) as f32]); + let params = resolve_params( + &definition(), + &BTreeMap::from([ + ("matrix".into(), Value::Float4([2.494_419_6, -1.666_711_1, 1.111_140_7, 1.662_946_3])), + ("offset".into(), Value::Float2([0.1875, -0.3125])), + ("mip_mode".into(), Value::Enum(1)), + ]), + ); + let context = CookContext { + w: 64, + h: 64, + seed: 773, + format: OutputFormat::F32, + tile: true, + inputs: &[Some(image.with_integer_sampling(true))], + input_formats: &[OutputFormat::U8], + params: ¶ms, + resource: &|_| None, + vars: &BTreeMap::new(), + }; + let result = transformation(&context).unwrap(); + for (x, y, bits) in [(62, 9, [0x3eae00ae, 0x3f800000, 0x3f28ffa9, 0x3f800000]), (15, 33, [0x3f04ff85, 0x3f01ff82, 0, 0x3f01ff82])] { + assert_eq!(result[0].get(x, y, false).map(f32::to_bits), bits); + } + } + + #[test] + fn centered_resizes_filter_rectangular_levels_in_source_coordinates() { + let vars = BTreeMap::from([("$tiling".into(), Value::Int(1))]); + for (source_format, height, matrix, mip_mode, mip_level, corner, interior) in [ + (OutputFormat::F32, 8, [1.0, 0.0, 0.0, 1.0], 0, 0, 0xbf27bdf0, 0x3e92acaa), + (OutputFormat::U16, 32, [0.0, 1.0, -1.0, 0.0], 0, 0, 0x3ea1c922, 0x3f410291), + (OutputFormat::F32, 64, [1.0, 0.0, 0.0, 1.0], 1, 1, 0xbf0c5715, 0xbc9d4750), + ] { + let integer = source_format == OutputFormat::U16; + let input = Image::gray(16, 16, |x, y| { + let ramp = f64::from((97 * x + 43 * y + 7 * x * y) % 1024) / 1023.0; + if integer { (ramp * 65535.0).round() as f32 / 65535.0 } else { (3.0 * ramp - 1.25) as f32 } + }) + .with_integer_sampling(integer); + let params = resolve_params( + &definition(), + &BTreeMap::from([ + ("matrix".into(), Value::Float4(matrix)), + ("mip_mode".into(), Value::Enum(mip_mode)), + ("mip_level".into(), Value::Int(mip_level)), + ("matte".into(), Value::Color([0.125, 0.375, -0.5, 1.25])), + ]), + ); + let context = CookContext { + w: 64, + h: height, + seed: 631, + format: OutputFormat::F32, + tile: false, + inputs: &[Some(input)], + input_formats: &[source_format], + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + let result = transformation(&context).unwrap(); + assert_eq!(result[0].get_gray(0, 0, false).to_bits(), corner); + assert_eq!(result[0].get_gray(17, 4, false).to_bits(), interior); + } + } + + #[test] + fn mip_reductions_use_the_precision_of_each_source_level() { + for (format, bits, expected) in [ + (OutputFormat::F16, [0x3fa2e000, 0x3cd0c000, 0x404e0000, 0xc0180000], 0x3f092000), + (OutputFormat::F32, [0x4012ab5d, 0xbf9f3b55, 0x4075821b, 0xc02f817b], 0x3f090e53), + (OutputFormat::U8, [0x3f62e2e3, 0x3ec8c8c9, 0x3f46c6c7, 0x3f068687], 0x3f2525a5), + ] { + let input = Image::gray(2, 2, |x, y| f32::from_bits(bits[(2 * y + x) as usize])).with_integer_sampling(format == OutputFormat::U8); + let output = reduce_mip(input, 1, format, OutputFormat::F32); + assert_eq!(output.get_gray(0, 0, false).to_bits(), expected); + } + } + + #[test] + fn large_affine_offsets_preserve_the_last_visible_mip_texels() { + let color = [23.0, 139.0, 211.0, 255.0].map(|v| v / 255.0); + let inputs = [Some(Image::filled(128, 128, Kind::Color, color).with_integer_sampling(true))]; + for (scale, offset, wrap, target) in [(256.0, [127.5, -127.5], 1, (0, 127)), (1024.0, [-492.5, 511.5], 2, (125, 0))] { + let vars = BTreeMap::from([("$tiling".into(), Value::Int(wrap))]); + let params = resolve_params( + &definition(), + &BTreeMap::from([ + ("matrix".into(), Value::Float4([scale, 0.0, 0.0, scale])), + ("offset".into(), Value::Float2(offset)), + ("matte".into(), Value::Color([0.0, 0.0, 0.0, 1.0])), + ]), + ); + let context = CookContext { + input_formats: &[OutputFormat::U8], + w: 128, + h: 128, + seed: 0, + format: OutputFormat::U8, + tile: false, + inputs: &inputs, + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + let image = crate::output_precision::apply(transformation(&context).unwrap().remove(0), OutputFormat::U8); + assert_eq!(image.get(target.0, target.1, false).map(|v| (v * 255.0).round() as u8), [11, 69, 105, 255]); + assert_eq!(image.get(80, 80, false), [0.0, 0.0, 0.0, 1.0]); + } + } + + #[test] + fn bilinear_transform_filters_the_matte_at_each_untiled_edge() { + let params = resolve_params(&definition(), &BTreeMap::from([("offset".into(), Value::Float2([0.25 / 4.0, 0.375 / 4.0]))])); + let inputs = [Some(Image::filled(4, 4, Kind::Color, [1.0; 4]).with_integer_sampling(true))]; + let vars = BTreeMap::new(); + let context = CookContext { + input_formats: &[], + w: 4, + h: 4, + seed: 0, + format: OutputFormat::F32, + tile: false, + inputs: &inputs, + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + let result = transformation(&context).unwrap(); + for (x, y, level) in [(0, 0, 65535.0), (3, 0, 49151.0), (0, 3, 40959.0), (3, 3, 30720.0)] { + assert_eq!(result[0].get(x, y, false), [level / 65535.0; 4], "texel ({x}, {y})"); + } + } + + #[test] + fn filtered_float_texels_round_at_the_source_precision() { + let params = resolve_params(&definition(), &BTreeMap::from([("offset".into(), Value::Float2([0.25 / 2.0, 0.375 / 2.0]))])); + let vars = BTreeMap::new(); + for (format, bits, expected) in [ + (OutputFormat::F16, [0x3fd0e000, 0xbfa46000, 0xc02d8000, 0x407f0000], 0x3e33a000), + (OutputFormat::F32, [0x3fc50790, 0xc0781fc9, 0x3f8389d2, 0xc029c3cd], 0x3e1fdd4b), + ] { + let inputs = [Some(Image::gray(2, 2, |x, y| f32::from_bits(bits[(2 * y + x) as usize])))]; + let context = CookContext { + w: 2, + h: 2, + seed: 0, + format: OutputFormat::F32, + tile: true, + inputs: &inputs, + input_formats: &[format], + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + assert_eq!(transformation(&context).unwrap()[0].get_gray(0, 0, false).to_bits(), expected, "{format:?}"); + } + } + + #[test] + fn matte_uses_the_inputs_storage_even_with_a_float_output() { + let matte = [0.5, 0.1, -0.312345, 1.144444]; + let params = resolve_params(&definition(), &BTreeMap::from([("offset".into(), Value::Float2([1.0, 1.0])), ("matte".into(), Value::Color(matte))])); + let vars = BTreeMap::new(); + for (format, expected) in [ + (OutputFormat::U8, [127.0 / 255.0, 25.0 / 255.0, 0.0, 1.0]), + (OutputFormat::U16, [32767.0 / 65535.0, 6553.0 / 65535.0, 0.0, 1.0]), + (OutputFormat::F16, [0.5, 0.099975586, -0.31225586, 1.1435547]), + (OutputFormat::F32, matte), + ] { + let integer = matches!(format, OutputFormat::U8 | OutputFormat::U16); + let inputs = [Some(Image::filled(4, 4, Kind::Color, [1.0; 4]).with_integer_sampling(integer))]; + let context = CookContext { + w: 4, + h: 4, + seed: 0, + format: OutputFormat::F32, + tile: false, + inputs: &inputs, + input_formats: &[format], + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + assert_eq!(transformation(&context).unwrap()[0].get(2, 2, false), expected, "{format:?}"); + } + } +} diff --git a/crates/nodes/src/atomic/uniform.rs b/crates/nodes/src/atomic/uniform.rs index 97cf2984..ec1e5b6e 100644 --- a/crates/nodes/src/atomic/uniform.rs +++ b/crates/nodes/src/atomic/uniform.rs @@ -1,6 +1,7 @@ use super::ATOMIC; use crate::{CookContext, CookResult, NodeDefinition, node}; -use craft_texture::{Image, Kind, luminance}; +use craft_texture::{Image, Kind}; +use materialcraft_core::Value; pub(super) fn definition() -> NodeDefinition { node("uniform", "Uniform color", ATOMIC) @@ -14,11 +15,47 @@ pub(super) fn definition() -> NodeDefinition { } fn uniform(context: &CookContext) -> CookResult { - let color = context.v4("color"); + let source = context.value("color"); + // A three-component function needs an explicit alpha to supply this property. + let color = if matches!(source, Some(Value::Float3(_))) { [0.0, 0.0, 0.0, 1.0] } else { context.v4("color") }; Ok(vec![if !context.b("color_mode") { - Image::filled(context.w, context.h, Kind::Gray, [luminance(color); 4]) + let gray = match source { + Some(Value::Float(level)) => *level, + // Runtime RGBA rounds each channel's contribution before accumulating the three. + Some(Value::Float4([r, g, b, _])) => r * (1.0 / 3.0) + g * (1.0 / 3.0) + b * (1.0 / 3.0), + _ => (color[0] + color[1] + color[2]) / 3.0, + }; + Image::filled(context.w, context.h, Kind::Gray, [gray; 4]) } else { Image::filled(context.w, context.h, Kind::Color, color) }]) } + +#[cfg(test)] +mod tests { + use super::*; + use materialcraft_core::{OutputFormat, Value}; + use std::collections::BTreeMap; + + #[test] + fn grayscale_uniform_averages_the_three_color_channels() { + for (color, expected) in [([0.125, 0.3125, 0.6875, 0.40625], 0.375_f32), ([1.75, -0.875, -0.25, 0.5], 0.20833333)] { + let params = BTreeMap::from([("color".into(), Value::Color(color)), ("color_mode".into(), Value::Bool(false))]); + let context = CookContext { + w: 1, + h: 1, + seed: 0, + tile: true, + format: OutputFormat::F32, + inputs: &[], + input_formats: &[], + params: ¶ms, + resource: &|_| None, + vars: &BTreeMap::new(), + }; + let image = uniform(&context).unwrap().remove(0); + assert_eq!(image.get_gray(0, 0, false).to_bits(), expected.to_bits()); + } + } +} diff --git a/crates/nodes/src/atomic/warp.rs b/crates/nodes/src/atomic/warp.rs index ba9ae42a..cbc76e42 100644 --- a/crates/nodes/src/atomic/warp.rs +++ b/crates/nodes/src/atomic/warp.rs @@ -1,7 +1,8 @@ use super::ATOMIC; -use crate::ops; -use crate::{CookContext, CookResult, NodeDefinition, node}; -use craft_texture::{Image, Kind}; +use super::input_resize::sampled_input; +use crate::{CookContext, CookResult, NodeDefinition, node, texture_sampler}; +use craft_texture::Image; +use materialcraft_core::Value; pub(super) fn definition() -> NodeDefinition { node("warp", "Warp", ATOMIC) @@ -10,17 +11,37 @@ pub(super) fn definition() -> NodeDefinition { .any_in("input", "Input") .gray_in("gradient", "Gradient input") .float("intensity", "Intensity", 1.0, 0.0, 32.0) + .boolean("nearest", "Nearest filtering", false) .any_out() .cook(warp) } fn warp(context: &CookContext) -> CookResult { - let image = context.any_or(0, Kind::Gray, [0.0; 4]); - let gradient = context.gray_or(1, 0.0); + let (width, height) = craft_texture::clamp_size(context.w, context.h); + let (image, format) = sampled_input(context, 0); + let (map, map_format) = sampled_input(context, 1); + let map = map.to_gray(); + let same_size = (map.width(), map.height()) == (width, height); + let (w, h) = (width as f32, height as f32); + let (mw, mh) = (map.width() as f32, map.height() as f32); + let stretched = context.vars.get("$pixelratio").and_then(Value::as_i32) == Some(0); + let [extent_x, extent_y] = if stretched { [w, h] } else { [w.min(h); 2] }; let intensity = context.f("intensity"); - Ok(vec![Image::generate_uv(context.w, context.h, image.kind(), |u, v| { - let (x, y) = ((u * context.w as f32) as i64, (v * context.h as f32) as i64); - let (dx, dy) = ops::slope(&gradient, x, y, context.tile); - image.sample(u + dx * intensity, v + dy * intensity, context.tile) + // A slope spans one stored gradient texel. Stretched pixels measure displacement separately along each output axis. + let axis_scale = |extent: f32, output: f32, gradient: f32| (intensity * (extent / 256.0)) * (extent / output) * (gradient / output); + let scale = [axis_scale(extent_x, w, mw), axis_scale(extent_y, h, mh)]; + let tile = context.tiling_axes(); + let nearest = context.b("nearest"); + Ok(vec![Image::generate(width, height, image.kind(), |x, y| { + let (u, v) = ((x as f32 + 0.5) / w, (y as f32 + 0.5) / h); + let (center, left, above) = if same_size { + let (x, y) = (i64::from(x), i64::from(y)); + (map.get_gray(x, y, false), map.get_axes(x - 1, y, tile)[0], map.get_axes(x, y - 1, tile)[0]) + } else { + let read = |u, v| texture_sampler::sample(&map, [u, v], tile, map_format, None)[0]; + (read(u, v), read(u - mw.recip(), v), read(u, v - mh.recip())) + }; + let uv = [scale[0].mul_add(center - left, u), scale[1].mul_add(center - above, v)]; + if nearest { image.sample_nearest_axes(uv[0], uv[1], tile) } else { texture_sampler::sample(&image, uv, tile, format, None) } })]) } diff --git a/crates/nodes/src/bitmap_color_space.rs b/crates/nodes/src/bitmap_color_space.rs new file mode 100644 index 00000000..f8d15293 --- /dev/null +++ b/crates/nodes/src/bitmap_color_space.rs @@ -0,0 +1,49 @@ +/// How a bitmap node interprets the channels stored in a package resource. +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] +pub enum BitmapColorSpace { + Srgb, + Linear, + FromFile, +} + +impl BitmapColorSpace { + pub fn from_index(index: i32) -> Self { + match index { + 1 => Self::Linear, + 2 => Self::FromFile, + _ => Self::Srgb, + } + } + + /// File-based reads have their own cache entry. Existing data and color requests use the shared texture format. + pub fn resource_key(self, name: &str) -> String { + match self { + Self::FromFile => format!("\u{1}F{name}"), + _ => craft_texture::resource_key(name, self == Self::Linear), + } + } + + pub fn split_resource_key(key: &str) -> (&str, Self) { + if let Some(name) = key.strip_prefix("\u{1}F") { + (name, Self::FromFile) + } else { + let (name, linear) = craft_texture::split_resource_key(key); + (name, if linear { Self::Linear } else { Self::Srgb }) + } + } +} + +#[cfg(test)] +mod tests { + use super::BitmapColorSpace; + + #[test] + fn bitmap_resource_keys_preserve_package_paths_and_literal_prefixes() { + for name in ["field", "\u{1}Ffield", "\u{1}Lfield", "child.sbs\0field"] { + for space in [BitmapColorSpace::FromFile, BitmapColorSpace::Srgb, BitmapColorSpace::Linear] { + let key = space.resource_key(name); + assert_eq!(BitmapColorSpace::split_resource_key(&key), (name, space)); + } + } + } +} diff --git a/crates/nodes/src/cook_context.rs b/crates/nodes/src/cook_context.rs index 889cdf0f..f1ed616f 100644 --- a/crates/nodes/src/cook_context.rs +++ b/crates/nodes/src/cook_context.rs @@ -2,12 +2,40 @@ use craft_texture::{Image, Kind}; use materialcraft_core::{Curve, FunctionGraph, Gradient, Value}; use std::collections::BTreeMap; +/// Graph inputs available to a cook, including any fixed by its enclosing instance. +pub trait GraphVariables: Sync { + fn graph_values(&self) -> &BTreeMap; + fn literal_inputs(&self) -> &[String] { + &[] + } + /// Integer variables written by an image-node property before the pattern runs. + fn assigned_integers(&self) -> &[String] { + &[] + } +} + +impl GraphVariables for BTreeMap { + fn graph_values(&self) -> &BTreeMap { + self + } +} + +impl std::ops::Deref for dyn GraphVariables + '_ { + type Target = BTreeMap; + + fn deref(&self) -> &Self::Target { + self.graph_values() + } +} + /// Where a cook runs: output size, seed, tiling, inputs and resolved parameters pub struct CookContext<'a> { pub w: u32, pub h: u32, pub seed: u32, pub format: materialcraft_core::OutputFormat, + /// Storage precision of each image input, in the same order as inputs. + pub input_formats: &'a [materialcraft_core::OutputFormat], pub tile: bool, /// By input port order; `None` = not connected pub inputs: &'a [Option], @@ -15,10 +43,21 @@ pub struct CookContext<'a> { /// The package's bitmap resources, decoded on demand pub resource: &'a (dyn Fn(&str) -> Option + Sync), /// Exposed graph inputs (for `get_*` nodes in function graphs) - pub vars: &'a BTreeMap, + pub vars: &'a dyn GraphVariables, } impl CookContext<'_> { + pub fn bitmap_color_space(&self) -> crate::BitmapColorSpace { + crate::BitmapColorSpace::from_index(self.i("colour_space")) + } + + /// A decoder that only accepts the two original request types can still supply the stored channels. + pub fn bitmap_resource(&self, name: &str) -> Option { + let space = self.bitmap_color_space(); + let image = (self.resource)(&space.resource_key(name)); + if image.is_none() && space == crate::BitmapColorSpace::FromFile { (self.resource)(&craft_texture::resource_key(name, true)) } else { image } + } + pub fn tiling_axes(&self) -> [bool; 2] { self.vars.get("$tiling").and_then(Value::as_i32).map_or([self.tile; 2], |mask| [mask & 1 != 0, mask & 2 != 0]) } diff --git a/crates/nodes/src/function/arithmetic.rs b/crates/nodes/src/function/arithmetic.rs index 5b0fff33..d56c1928 100644 --- a/crates/nodes/src/function/arithmetic.rs +++ b/crates/nodes/src/function/arithmetic.rs @@ -1,7 +1,23 @@ use super::value_type::{dimensions, floats, integer_value, integers, intermediate_float_value as float_value}; use materialcraft_core::Value; -pub(crate) fn evaluate(op: &str, args: &[Value], random: &mut u32, scope: super::FunctionScope) -> Result { +/// Runtime arithmetic treats subnormals as signed zero at its inputs and rounded results. +pub(crate) fn flush_subnormal(value: f32) -> f32 { + if value.is_subnormal() { 0.0_f32.copysign(value) } else { value } +} + +pub(crate) fn evaluate( + instruction: &super::instruction::Instruction, + args: &[Value], + random: &mut crate::random::FunctionRandom, + scope: super::FunctionScope, +) -> Result { + let op = instruction.definition.id; + if op == "rand" && args.is_empty() { + return Ok(Value::Float(random.draw())); + } + let pixel_math = scope == super::FunctionScope::PixelProcessor && !instruction.literal; + let angle_component = |angle, cosine| super::trigonometry::component(angle, cosine, scope, instruction.literal); let first = args.first().ok_or("missing arithmetic operand")?; let count = dimensions(first); let integer = matches!(first, Value::Int(_) | Value::Int2(_) | Value::Int3(_) | Value::Int4(_)); @@ -44,6 +60,14 @@ pub(crate) fn evaluate(op: &str, args: &[Value], random: &mut u32, scope: super: } if op == "dot" { + if pixel_math && count >= 2 { + // The second product rounds first. Each remaining channel contributes one fused operation. + let left = left.map(flush_subnormal); + let right = right.map(flush_subnormal); + let xy = flush_subnormal(left[0].mul_add(right[0], flush_subnormal(left[1] * right[1]))); + let sum = left.iter().zip(right).take(count).skip(2).fold(xy, |sum, (a, b)| flush_subnormal(a.mul_add(b, sum))); + return float_value(&[sum]); + } return float_value(&[left.iter().zip(right).take(count).map(|(a, b)| a * b).sum()]); } @@ -52,7 +76,7 @@ pub(crate) fn evaluate(op: &str, args: &[Value], random: &mut u32, scope: super: return Err("arc tangent requires a float2".into()); } - return float_value(&[left[1].atan2(left[0])]); + return float_value(&[if instruction.literal { left[1].atan2(left[0]) } else { runtime_atan2(left[0], left[1], pixel_math) }]); } if op == "cartesian" { @@ -60,43 +84,101 @@ pub(crate) fn evaluate(op: &str, args: &[Value], random: &mut u32, scope: super: return Err("Cartesian requires scalar radius and angle".into()); } - return float_value(&[left[0] * right[0].cos(), left[0] * right[0].sin()]); + let angle = right[0]; + return float_value(&[left[0] * angle_component(angle, true), left[0] * angle_component(angle, false)]); } + let flush_arithmetic = !instruction.literal && matches!(op, "add" | "sub" | "mul" | "mulscalar" | "div"); let mut result = [0.0; 4]; for (((result, left), right), factor) in result.iter_mut().zip(left).zip(right).zip(factor).take(count) { - *result = match op { + let (left, right) = if flush_arithmetic { (flush_subnormal(left), flush_subnormal(right)) } else { (left, right) }; + let value = match op { "add" => left + right, "sub" => left - right, "mul" | "mulscalar" => left * right, + "div" if pixel_math => super::reciprocal::divide_by(left, right, instruction.literal_divisor), "div" => left / right, - // Floored modulo wraps negative coordinates; remainder keeps their sign - "mod" => left - right * (left / right).floor(), + "mod" => { + let wrapped = left - right * (left / right).floor(); + // Rounding a tiny offset can reach the period itself. Only a literal expression keeps that endpoint. + if !instruction.literal && wrapped == right { 0.0 } else { wrapped } + } "neg" => -left, "abs" => left.abs(), "min" => left.min(right), "max" => left.max(right), "floor" => left.floor(), "ceil" => left.ceil(), - "sqrt" => left.sqrt(), - "exp" => left.exp(), - "log" => left.ln(), - "log2" => left.log2(), - "pow" => left.powf(right), - "pow2" => left.exp2(), - "sin" => left.sin(), - "cos" => left.cos(), - "tan" => left.tan(), - "lerp" => left + (right - left) * factor, - "rand" if scope == super::FunctionScope::Node => crate::random::node_function(random) * left, - "rand" if scope == super::FunctionScope::FxMap => crate::random::pattern_function(random) * left, - "rand" => { - *random = crate::random::hash(random.wrapping_add(1)); - (*random >> 8) as f32 / 16777216.0 * left + "sqrt" if pixel_math => super::square_root::evaluate(left), + "sqrt" => { + // Literal roots preserve negative zero and positive subnormals. Runtime roots flush both to positive zero. + let minimum = if instruction.literal { 0.0 } else { f32::MIN_POSITIVE }; + if left >= minimum { left.sqrt() } else { 0.0 } } + "exp" => super::binary_exponential::exp(left, pixel_math), + "log" if pixel_math => super::binary_exponential::ln(left), + "log" => super::binary_exponential::uniform_ln(left), + "log2" if pixel_math => super::binary_exponential::log2(left), + "log2" => super::binary_exponential::uniform_ln(left) / std::f32::consts::LN_2, + "pow" => super::binary_exponential::power(left, right, pixel_math), + "pow2" if pixel_math => super::binary_exponential::exp2(left), + "pow2" => super::binary_exponential::uniform_exp2(left), + "sin" => angle_component(left, false), + "cos" => angle_component(left, true), + "tan" if instruction.literal => left.tan(), + "tan" => { + let sine = angle_component(left, false); + let cosine = angle_component(left, true); + if pixel_math { super::reciprocal::divide(sine, cosine) } else { sine / cosine } + } + "lerp" if pixel_math => (right - left).mul_add(factor, left), + "lerp" => left + (right - left) * factor, + "rand" if args.len() == 2 => right * left, + "rand" => random.draw() * left, _ => return Err(format!("unknown arithmetic operation `{op}`")), }; + *result = if flush_arithmetic { flush_subnormal(value) } else { value }; } float_value(result.get(..count).ok_or("invalid float dimensions")?) } + +fn runtime_atan2(x: f32, y: f32, pixel_math: bool) -> f32 { + use std::f32::consts::{FRAC_PI_2, PI}; + const LINEAR: f32 = 1.00249; + const QUADRATIC: f32 = -0.0123825; + const CUBIC: f32 = -0.347313; + const QUARTIC: f32 = 0.142604; + let flush = |v: f32| if v.is_subnormal() { 0.0 } else { v }; + let (x, y) = (flush(x), flush(y)); + if x == 0.0 { + return if y > 0.0 { + FRAC_PI_2 + } else if y < 0.0 { + -FRAC_PI_2 + } else { + 0.0 + }; + } + let (ax, ay) = (x.abs(), y.abs()); + let horizontal = ax >= ay; + let (small, large) = if horizontal { (ay, ax) } else { (ax, ay) }; + let ratio = flush(if pixel_math { small * flush(super::reciprocal::divide(1.0, large)) } else { small / large }); + let square = ratio * ratio; + let cube = ratio * square; + let fourth = square * square; + // Both scopes fit the same measured octant. Only the pixel dot product fuses the additions. + let octant = if pixel_math { + let linear = ratio.mul_add(LINEAR, square * QUADRATIC); + fourth.mul_add(QUARTIC, cube.mul_add(CUBIC, linear)) + } else { + ratio * LINEAR + square * QUADRATIC + cube * CUBIC + fourth * QUARTIC + }; + let angle = match (horizontal, x < 0.0) { + (true, false) => octant, + (true, true) => PI - octant, + (false, false) => FRAC_PI_2 - octant, + (false, true) => FRAC_PI_2 + octant, + }; + if y < 0.0 && angle > 0.0 { -angle } else { angle } +} diff --git a/crates/nodes/src/function/assigned_product.rs b/crates/nodes/src/function/assigned_product.rs new file mode 100644 index 00000000..107a5a91 --- /dev/null +++ b/crates/nodes/src/function/assigned_product.rs @@ -0,0 +1,305 @@ +use super::{EvaluationState, Program, instruction::Instruction, product_sum::ProductSum, returned_product::float_width}; +use materialcraft_core::Value; +use std::collections::BTreeMap; + +#[derive(Clone, Copy)] +enum Registers { + Local { left: usize, right: usize, assignment: Option }, + Argument(usize), +} + +/// Factors from this frame or its caller, and the components also read as a rounded product. +#[derive(Clone, Copy)] +pub(super) struct Binding { + registers: Registers, + pub(super) rounded_components: u8, +} + +impl Binding { + pub(super) fn read(self, state: &EvaluationState) -> Option<[Value; 2]> { + match self.registers { + Registers::Argument(slot) => state.assigned_arguments.get(slot)?.clone(), + Registers::Local { left, right, assignment } => { + if let Some(index) = assignment { + state.registers.get(index)?.as_ref()?; + } + Some([state.registers.get(left)?.as_ref()?.clone(), state.registers.get(right)?.as_ref()?.clone()]) + } + } + } + + fn import(self, arguments: &mut Vec) -> Self { + let slot = arguments.len(); + arguments.push(self); + Self { registers: Registers::Argument(slot), ..self } + } +} + +fn variable(op: &Instruction) -> Option<&str> { + match &op.value { + Some(Value::Text(name)) if !name.starts_with('$') => Some(name), + _ => None, + } +} + +fn float_getter(op: &Instruction) -> bool { + matches!(op.definition.id, "get_float1" | "get_float2" | "get_float3" | "get_float4") +} + +fn product(op: &Instruction) -> Option<(usize, usize)> { + let &[a, b] = op.inputs.as_slice() else { return None }; + (!op.literal && float_width(op.type_code) > 0 && matches!(op.definition.id, "mul" | "mulscalar")).then_some((a, b)) +} + +fn unit(op: &Instruction, instructions: &[Instruction]) -> Option { + let &[input, scalar] = op.inputs.as_slice() else { return None }; + (op.definition.id == "mulscalar" && instructions.get(scalar).is_some_and(|i| i.definition.id == "const_float1" && i.value == Some(Value::Float(1.0)))) + .then_some(input) +} + +type ReadMasks = BTreeMap; + +#[derive(Default)] +struct Uses { + reads: ReadMasks, + writes: BTreeMap, + rounded: Vec, + live: Vec, + ordered: bool, + loops: bool, + calls: BTreeMap, +} + +impl Uses { + fn analyze(program: &Program, caller_reads: &dyn Fn(&str) -> u8) -> Self { + let len = program.instructions.len(); + let mut uses = Self { rounded: vec![0; len], live: vec![false; len], ordered: true, ..Self::default() }; + if let (Some(mask), Some(live)) = (uses.rounded.get_mut(program.output), uses.live.get_mut(program.output)) { + *mask = 15; + *live = true; + } + for (index, op) in program.instructions.iter().enumerate().rev() { + if !uses.live[index] { + continue; + } + let observed = uses.rounded[index]; + let mut mark = |input: usize, mask: u8| { + if let (Some(bits), Some(live)) = (uses.rounded.get_mut(input), uses.live.get_mut(input)) { + *bits |= mask; + *live = true; + } + }; + if let Some(call) = &op.call { + let child = Self::analyze(&call.program, &|name| { + if call.defaults.contains_key(name) { 0 } else { caller_reads(name) | uses.reads.get(name).copied().unwrap_or(0) } + }); + for (name, register) in call.inputs.iter().zip(&op.inputs) { + mark(*register, child.reads.get(name).copied().unwrap_or(0)); + } + for (name, &mask) in &child.reads { + if !call.defaults.contains_key(name) { + *uses.reads.entry(name.clone()).or_default() |= mask; + } + } + for (name, count) in &child.writes { + if !call.defaults.contains_key(name) { + *uses.writes.entry(name.clone()).or_default() += count; + } + } + uses.calls.insert(index, child); + } else if let Some(input) = unit(op, &program.instructions) { + mark(input, observed); + } else if let [input] = op.inputs.as_slice() + && let Some(mask) = super::product_sum::selected_components(op) + { + mark(*input, mask); + } else { + match (op.definition.id, op.inputs.as_slice()) { + ("add" | "sub", &[left, right]) => { + mark(left, 0); + mark(right, 0); + } + ("sequence", &[first, last]) => { + mark(first, 0); + mark(last, observed); + } + ("passthrough", &[last]) => mark(last, observed), + ("ifelse", &[condition, yes, no]) => { + mark(condition, 15); + for &shared in &op.control_registers { + mark(shared, 0); + } + let test = program.instructions.get(condition); + if let Some(Instruction { value: Some(Value::Bool(value)), .. }) = test.filter(|op| op.definition.id == "const_bool") { + mark(if *value { yes } else { no }, observed); + } else { + uses.ordered = false; + mark(yes, observed); + mark(no, observed); + } + } + ("set", &[input]) => { + let source = program.instructions.get(input); + // Assigning a getter copies its value. Its rounded lanes are the ones read from either name. + let mask = if source.is_some_and(float_getter) + && let Some(name) = variable(op) + { + observed | caller_reads(name) | uses.reads.get(name).copied().unwrap_or(0) + } else if source.and_then(product).is_some() { + observed + } else { + 15 + }; + mark(input, mask); + if let Some(name) = variable(op) { + *uses.writes.entry(name.to_owned()).or_default() += 1; + } + } + ("get_float1" | "get_float2" | "get_float3" | "get_float4", []) => { + if let Some(name) = variable(op) { + *uses.reads.entry(name.to_owned()).or_default() |= observed; + } + } + _ => { + if op.definition.id == "while" { + uses.ordered = false; + uses.loops = true; + } + for &input in &op.inputs { + mark(input, 15); + } + } + } + } + } + uses + } +} + +fn has_assignment(program: &Program) -> bool { + program.instructions.iter().any(|op| { + (op.definition.id == "set" && op.inputs.first().and_then(|&i| program.instructions.get(i)).and_then(product).is_some()) + || op.call.as_ref().is_some_and(|call| has_assignment(&call.program)) + }) +} + +pub(super) fn identify(program: &mut Program) { + if program.instructions.iter().any(|op| op.call.is_some()) && has_assignment(program) { + let uses = Uses::analyze(program, &|_| 0); + install(program, &uses, &uses.reads, BTreeMap::new()); + } +} + +fn install(program: &mut Program, uses: &Uses, observed: &ReadMasks, mut names: BTreeMap) -> BTreeMap { + let instructions = &program.instructions; + // A dynamic branch can skip a write. Only a unique, executed assignment is eligible in that case. + if !uses.ordered { + names.retain(|name, _| !uses.writes.contains_key(name)); + } + let mut sources = vec![None; instructions.len()]; + let mut setters = BTreeMap::new(); + let mut products_written = BTreeMap::::new(); + if !uses.loops { + for (op, &live) in instructions.iter().zip(&uses.live) { + if live && let ("set", &[input]) = (op.definition.id, op.inputs.as_slice()) { + *products_written.entry(input).or_default() += 1; + } + } + for (index, setter) in instructions.iter().enumerate() { + if uses.live[index] + && let ("set", &[input], Some(name)) = (setter.definition.id, setter.inputs.as_slice(), variable(setter)) + && (uses.ordered || uses.writes.get(name) == Some(&1)) + && products_written.get(&input) == Some(&1) + && let Some(product_op) = instructions.get(input) + && let Some((left, right)) = product(product_op) + { + let mask = (1_u8 << float_width(product_op.type_code)) - 1; + let rounded_components = observed.get(name).copied().unwrap_or(0) | uses.reads.get(name).copied().unwrap_or(0) | uses.rounded[input]; + if mask & !rounded_components == 0 { + continue; + } + let binding = Binding { registers: Registers::Local { left, right, assignment: Some(index) }, rounded_components }; + setters.insert(index, binding); + if !uses.ordered { + names.insert(name.to_owned(), binding); + } + sources[input] = Some(Binding { registers: Registers::Local { left, right, assignment: None }, ..binding }); + } + } + } + for index in 0..program.instructions.len() { + if !uses.live[index] { + continue; + } + let (previous, current) = program.instructions.split_at_mut(index); + let Some(op) = current.first_mut() else { continue }; + let source = |input: usize| sources.get(input).copied().flatten(); + if let Some(call) = &mut op.call { + let Some(child) = uses.calls.get(&index) else { continue }; + let mut imported = BTreeMap::new(); + for (name, binding) in &names { + if !call.defaults.contains_key(name) && child.reads.contains_key(name) && (child.ordered || !child.writes.contains_key(name)) { + imported.insert(name.clone(), binding.import(&mut call.assigned_products)); + } + } + for (name, register) in call.inputs.iter().zip(&op.inputs) { + if child.reads.contains_key(name) + && let Some(binding) = source(*register) + { + imported.insert(name.clone(), binding.import(&mut call.assigned_products)); + } + } + let returned = install(&mut call.program, child, observed, imported); + if uses.ordered { + names.retain(|name, _| !child.writes.contains_key(name) || call.defaults.contains_key(name)); + // A free name assigned a caller's step can carry the same factors into a later call. + if child.ordered { + for (name, binding) in returned { + if child.writes.contains_key(&name) + && !call.defaults.contains_key(&name) + && let Registers::Argument(slot) = binding.registers + && let Some(&argument) = call.assigned_products.get(slot) + { + names.insert(name, argument); + } + } + } + } + continue; + } + if uses.ordered + && op.definition.id == "set" + && let Some(name) = variable(op) + { + let copied = op.inputs.first().and_then(|&i| previous.get(i).filter(|op| float_getter(op)).and_then(|_| source(i))); + if let Some(binding) = setters.get(&index).copied().or(copied) { + names.insert(name.to_owned(), binding); + } else { + names.remove(name); + } + } + let forwarded = match (op.definition.id, op.inputs.as_slice()) { + ("get_float1" | "get_float2" | "get_float3" | "get_float4", []) => { + variable(op).and_then(|name| names.get(name)).copied().filter(|binding| uses.ordered || matches!(binding.registers, Registers::Argument(_))) + } + ("passthrough", &[i]) => source(i), + _ => unit(op, previous).and_then(source), + }; + if let Some(binding) = forwarded { + sources[index] = Some(binding); + } + if let ("add" | "sub", &[left, right]) = (op.definition.id, op.inputs.as_slice()) { + let a = sources.get(left).copied().flatten(); + let b = sources.get(right).copied().flatten(); + let Some(binding) = a.xor(b) else { continue }; + let operand = if a.is_some() { left } else { right }; + let other = if a.is_some() { right } else { left }; + if op.pixel_product_sum.is_none() + || previous.get(operand).and_then(|op| unit(op, previous)).is_some() && previous.get(other).and_then(product).is_none() + { + op.pixel_product_sum = Some(ProductSum::assigned(&op.inputs, b.is_some(), binding)); + } + } + } + names +} diff --git a/crates/nodes/src/function/binary_exponential.rs b/crates/nodes/src/function/binary_exponential.rs new file mode 100644 index 00000000..f71222b2 --- /dev/null +++ b/crates/nodes/src/function/binary_exponential.rs @@ -0,0 +1,153 @@ +//! Logarithm and exponential for runtime function expressions. + +use super::fixed_point::{Quadratic, square_fraction, truncate_float}; +use std::{f64::consts::LN_2, sync::LazyLock}; + +const WIDTH: f64 = 1.0 / 64.0; +const MANTISSA: u32 = 0x7f_ffff; + +// Scale each fitted coefficient to integer units of 2^-38 for evaluation. +static LOGARITHMS: LazyLock<[Quadratic; 64]> = LazyLock::new(|| { + std::array::from_fn(|index| { + let start = 1.0 + index as f64 * WIDTH; + let reciprocal = WIDTH / (start + 0.5 * WIDTH); + let derivatives = [reciprocal / LN_2, -reciprocal.powi(2) / LN_2, 2.0 * reciprocal.powi(3) / LN_2]; + let mut bin = Quadratic::fit(|t| (start + t * WIDTH).log2(), derivatives, [26, 21, 22]); + bin.constant = (bin.constant + 3) << 12; + bin.curvature *= 2; + bin + }) +}); + +static EXPONENTIALS: LazyLock<[Quadratic; 64]> = LazyLock::new(|| { + std::array::from_fn(|index| { + let start = index as f64 * WIDTH; + let mid = (start + 0.5 * WIDTH).exp2(); + let rate = WIDTH * LN_2; + let derivatives = [mid * rate, mid * rate.powi(2), mid * rate.powi(3)]; + let mut bin = Quadratic::fit(|t| (start + t * WIDTH).exp2(), derivatives, [25, 21, 23]); + bin.constant = (bin.constant + 2) << 13; + bin + }) +}); + +fn interpolate(bins: &[Quadratic; 64], bits: u32) -> i64 { + let bin = &bins[((bits & MANTISSA) >> 17) as usize]; + let fraction = bits & 0x1_ffff; + bin.constant + bin.slope * i64::from(fraction) + bin.curvature * i64::from(square_fraction(fraction >> 1)) +} + +pub(super) fn log2(value: f32) -> f32 { + if value.abs() < f32::MIN_POSITIVE { + return f32::NEG_INFINITY; + } + if value <= 0.0 || !value.is_finite() || value == 1.0 { + return value.log2(); + } + let bits = value.to_bits(); + let exponent = i64::from(bits >> 23) - 127; + let fixed = (exponent << 38) + interpolate(&LOGARITHMS, bits); + // A two-bit truncation precedes float normalization. Negative results round one such unit higher. + let rounded = (fixed + 837 + if fixed < 0 { 4 } else { 0 }) & !3; + truncate_float(rounded as f64 / 274_877_906_944.0) +} + +pub(super) fn ln(value: f32) -> f32 { + log2(value) * std::f32::consts::LN_2 +} + +pub(super) fn uniform_ln(value: f32) -> f32 { + if value.is_nan() || value < f32::MIN_POSITIVE { + return 0.0; + } + let bits = value.to_bits(); + let exponent = (bits >> 23) as i32 - 126; + let mantissa = f32::from_bits((126 << 23) | (bits & MANTISSA)); + let u = 1.0 - mantissa; + // Fit the remainder of -ln(1-u) = u(1+uP(u)) over [0, 0.5]. Uniform products and sums round separately. + let coefficients = [-2.507_298, 1.991_688_4, -0.599_022_4, 0.341_097_44, 0.175_831_17, 0.251_863_93, 0.333_263_6, 0.500_000_9]; + let remainder = coefficients.into_iter().fold(1.761_320_2, |p, c| p * u + c); + -u * (1.0 + u * remainder) + exponent as f32 * std::f32::consts::LN_2 +} + +pub(crate) fn signed_pixel_power(value: f32, exponent: f32) -> f32 { + exp2(log2(value.abs()) * exponent).copysign(value) +} + +pub(super) fn exp(value: f32, pixel: bool) -> f32 { + if value.is_nan() { + return if pixel { 0.0 } else { value }; + } + if value < -88.0 { + return 0.0; + } + if value > 89.0 { + return f32::INFINITY; + } + const LOG_HIGH: f32 = std::f32::consts::LN_2; + const LOG_LOW: f32 = (LN_2 - LOG_HIGH as f64) as f32; + let exponent = (value * std::f32::consts::LOG2_E).floor(); + let remainder = (-exponent).mul_add(LOG_LOW, (-exponent).mul_add(LOG_HIGH, value)); + // On [0, ln(2)] the same fitted polynomial uses fused pixel operations and separate uniform operations. + let coefficients = [0.001_304_379_3, 0.008_378_831, 0.041_653_905, 0.166_668_42, 0.499_999_9, 1.0, 1.0]; + let initial = 0.000_275_553_82_f32; + let significand = if pixel { + coefficients.into_iter().fold(initial, |p, c| p.mul_add(remainder, c)) + } else { + coefficients.into_iter().fold(initial, |p, c| p * remainder + c) + }; + // The scale itself can be 2^128 while the product still fits in float32. + let scale = f64::from_bits(((exponent as i32 + 1023) as u64) << 52); + let result = (f64::from(significand) * scale) as f32; + if result.is_subnormal() { 0.0 } else { result } +} + +pub(super) fn power(base: f32, exponent: f32, pixel: bool) -> f32 { + if !pixel && (!base.is_finite() || !exponent.is_finite()) { + return base.powf(exponent); + } + if base.abs() < f32::MIN_POSITIVE { + return 0.0; + } + let magnitude = |x| exp(exponent * if pixel { ln(x) } else { uniform_ln(x) }, pixel); + if base > 0.0 { + return magnitude(base); + } + if exponent.fract() != 0.0 { + return 0.0; + } + let result = magnitude(base.abs()); + if exponent.abs() % 2.0 == 1.0 { -result } else { result } +} + +pub(super) fn uniform_exp2(value: f32) -> f32 { + if value.is_nan() || value <= -126.0 { + return f32::MIN_POSITIVE; + } + let value = super::arithmetic::flush_subnormal(value.min(126.0)); + let exponent = value.floor(); + let remainder = (value - exponent) * std::f32::consts::LN_2; + // The seventh-degree Taylor series for exp(remainder) rounds each product before the addition. + let coefficients = [1.0 / 720.0, 1.0 / 120.0, 1.0 / 24.0, 1.0 / 6.0, 0.5, 1.0, 1.0]; + let significand = coefficients.into_iter().fold(1.0 / 5040.0, |p, c| p * remainder + c); + let scale = f32::from_bits(((exponent as i32 + 127) as u32) << 23); + significand * scale +} + +pub(crate) fn exp2(value: f32) -> f32 { + if value < -126.0 { + return 0.0; + } + if value >= 128.0 || value.is_nan() { + return value.exp2(); + } + let mut fixed = (value * 8_388_608.0) as i32; + // Negative fractional arguments use the one's complement of the fractional magnitude. + if value < 0.0 && fixed as u32 & MANTISSA != 0 { + fixed -= 1; + } + let exponent = (fixed >> 23) + 126; + let polynomial = interpolate(&EXPONENTIALS, fixed as u32); + let significand = ((polynomial + 16_384 - 2_078) >> 15) as u32; + f32::from_bits(((exponent as u32) << 23) + significand) +} diff --git a/crates/nodes/src/function/branch_assignments.rs b/crates/nodes/src/function/branch_assignments.rs new file mode 100644 index 00000000..904f8829 --- /dev/null +++ b/crates/nodes/src/function/branch_assignments.rs @@ -0,0 +1,53 @@ +use super::Program; + +/// A pixel branch evaluates a shared assignment in the enclosing scope. An assignment +/// private to one arm stays there, including when two alternatives inside that arm use it. +pub(super) fn identify(program: &mut Program) { + let instructions = &program.instructions; + if !instructions.iter().any(|op| op.definition.id == "ifelse") + || !instructions.iter().any(|op| op.definition.id == "set" || op.call.as_ref().is_some_and(|call| call.exports)) + { + return; + } + + let mut writes = Vec::with_capacity(instructions.len()); + for op in instructions { + // The loop owns its assignments and refreshes their registers on each iteration. + let assigns = op.definition.id != "while" + && (op.definition.id == "set" || op.call.as_ref().is_some_and(|call| call.exports) || op.inputs.iter().any(|&input| writes[input])); + writes.push(assigns); + } + + let mut paths = vec![0_u8; instructions.len()]; + for branch in 0..instructions.len() { + let op = &program.instructions[branch]; + let [_, yes, no] = op.inputs.as_slice() else { continue }; + if op.definition.id != "ifelse" || !(writes[*yes] || writes[*no]) { + continue; + } + paths.fill(0); + paths[program.output] = 4; + paths[*yes] |= 1; + paths[*no] |= 2; + let mut shared = Vec::new(); + // Instructions follow their inputs. Reach a register from each arm and from + // other consumers before deciding whether it belongs at this branch. + for index in (0..=program.output).rev() { + let path = paths[index]; + if path == 0 || index == branch || !writes[index] { + continue; + } + if path.count_ones() > 1 { + // Evaluate the whole shared expression in order. Pulling individual Sets + // out of a shared sequence or conditional could execute a skipped write. + shared.push(index); + } else { + for &input in &program.instructions[index].inputs { + paths[input] |= path; + } + } + } + shared.reverse(); + program.instructions[branch].control_registers = shared; + } +} diff --git a/crates/nodes/src/function/branch_inputs.rs b/crates/nodes/src/function/branch_inputs.rs new file mode 100644 index 00000000..153dc818 --- /dev/null +++ b/crates/nodes/src/function/branch_inputs.rs @@ -0,0 +1,170 @@ +use super::{Program, function_call::PatternAccess, instruction::Instruction, vector::PatternComponent}; +use materialcraft_core::Value; +use std::collections::{BTreeMap, BTreeSet}; +use std::ops::Range; + +pub(super) struct BranchInputs { + shared: Vec, + true_count: usize, +} + +impl BranchInputs { + // The true arm occurs first. A skipped arm still evaluates effects shared with another consumer. + pub(super) fn skipped(&self, take_true: bool) -> &[usize] { + let (through_true, through_false_only) = self.shared.split_at(self.true_count); + if take_true { through_false_only } else { through_true } + } +} + +/// Schedule shared writes and draws from a skipped arm. Private expressions stay lazy. +pub(super) fn identify(program: &mut Program, pattern_tail: Range) { + let instructions = &program.instructions; + if !instructions.iter().any(|op| op.definition.id == "ifelse") + || !instructions.iter().any(|op| matches!(op.definition.id, "rand" | "set")) + || instructions.iter().any(|op| op.definition.id == "while" || op.call.as_ref().is_some_and(|call| call.exports)) + { + return; + } + + let written: BTreeSet<_> = instructions + .iter() + .filter_map(|op| match (&op.value, op.definition.id) { + (Some(Value::Text(name)), "set") => Some(name.as_str()), + _ => None, + }) + .collect(); + // A range depending on an assignment or image sample must stay at its original read. + let mut independent_range = Vec::with_capacity(instructions.len()); + for op in instructions { + let fixed_input = op.definition.id == "get_float1" && matches!(&op.value, Some(Value::Text(name)) if !written.contains(name.as_str())); + independent_range + .push(op.type_code == 256 && (op.literal || fixed_input || (op.definition.id == "rand" && op.inputs.iter().all(|&i| independent_range[i])))); + } + // A called graph can observe the caller's assignments without listing them among its inputs. + let has_calls_and_writes = !written.is_empty() && instructions.iter().any(|op| op.call.is_some()); + if !has_calls_and_writes { + program.processor_branches = shared_inputs(program, &independent_range, None, &[], 0..0); + } + if pattern_tail.start > 0 { + let draws = pattern_draws(instructions, &written, &independent_range); + program.pattern_branches = shared_inputs(program, &independent_range, Some(&program.pattern_components), &draws, pattern_tail); + } +} + +struct PatternDraw { + direct: bool, + in_expression: bool, +} + +fn pattern_draws(instructions: &[Instruction], written: &BTreeSet<&str>, ranges: &[bool]) -> Vec { + let mut fixed = Vec::with_capacity(instructions.len()); + let mut draws: Vec = Vec::with_capacity(instructions.len()); + for (i, op) in instructions.iter().enumerate() { + let id = op.definition.id; + let read = id.starts_with("get_") && matches!(&op.value, Some(Value::Text(name)) if !written.contains(name.as_str())); + let access = op.call.as_ref().map(|call| call.pattern_access); + let pure = op.depends_only_on_operands() || access == Some(PatternAccess::Arguments); + fixed.push(op.literal || read || (pure && op.inputs.iter().all(|&input| fixed[input]))); + // Bounds and call arguments can be computed from immutable parameters. A read + // taken from a Set or an image must still occur at its original position. + let direct = (id == "rand" && op.inputs.first().is_some_and(|&range| ranges[i] || fixed[range])) + || (access == Some(PatternAccess::Random) && op.inputs.iter().all(|&arg| ranges[arg] || fixed[arg])); + let in_expression = direct || op.inputs.iter().any(|&input| draws[input].in_expression); + draws.push(PatternDraw { direct, in_expression }); + } + draws +} + +fn operands<'a>(instructions: &'a [Instruction], index: usize, components: Option<&'a BTreeMap>) -> &'a [usize] { + let node = &instructions[index]; + match components.and_then(|channels| channels.get(&index)) { + Some(PatternComponent::Register(source)) => std::slice::from_ref(source), + Some(PatternComponent::Zero) => &[], + None => node + .call + .as_ref() + .and_then(|call| call.pattern_arguments.as_ref()) + .filter(|plan| components.is_some() && !matches!(plan.target, super::function_call::PatternTarget::Arguments(_))) + .map_or(&node.inputs, |plan| &plan.registers), + } +} + +fn shared_inputs( + program: &Program, + ranges: &[bool], + components: Option<&BTreeMap>, + draws: &[PatternDraw], + excluded: Range, +) -> BTreeMap { + let instructions = &program.instructions; + let mut paths = vec![0_u8; instructions.len()]; + let mut stack = Vec::new(); + let mut effects = Vec::new(); + let mut plans = BTreeMap::new(); + for (branch, op) in instructions.iter().enumerate().filter(|(i, op)| op.definition.id == "ifelse" && !excluded.contains(i)) { + let &[condition, yes, no] = op.inputs.as_slice() else { continue }; + // A branch folded before a stamp runs cannot schedule draws from its discarded arm. + if components.is_some() && instructions[condition].pattern_literal { + continue; + } + paths.fill(0); + effects.clear(); + // Record the order of first use through each arm. + for (root, path) in [(yes, 1), (no, 2), (program.output, 4)] { + if path == 4 && effects.is_empty() { + break; + } + stack.push(root); + while let Some(index) = stack.pop() { + if index == branch || paths[index] & path != 0 { + continue; + } + let node = &instructions[index]; + let shared_write = op.control_registers.binary_search(&index).is_ok(); + let draw = draws.get(index).map_or_else(|| node.definition.id == "rand" && ranges[index] && !node.inputs.is_empty(), |draw| draw.direct); + if paths[index] == 0 && path != 4 && (shared_write || draw) { + effects.push(index); + } + paths[index] |= path; + // Evaluating a shared expression performs any conditional writes within it in their own scope. + if shared_write { + continue; + } + stack.extend(operands(instructions, index, components).iter().rev().copied()); + } + } + let shared: Vec<_> = if draws.is_empty() { + effects.iter().copied().filter(|&i| paths[i].count_ones() > 1).collect() + } else { + // Evaluate the outermost shared conditional once. Pulling its individual + // draws into the parent branch would consume a draw from its inactive arm. + const ORDERED: u8 = 8; + let mut shared = Vec::new(); + stack.extend([no, yes]); + while let Some(i) = stack.pop() { + if i == branch || paths[i] & ORDERED != 0 { + continue; + } + let common = paths[i].count_ones() > 1; + paths[i] |= ORDERED; + let write = op.control_registers.binary_search(&i).is_ok(); + let conditional = instructions[i].definition.id == "ifelse" && draws[i].in_expression; + if common && (write || draws[i].direct || conditional) { + shared.push(i); + } else if !write { + stack.extend(operands(instructions, i, components).iter().rev().copied()); + } + } + shared + }; + if !shared.is_empty() { + let true_count = shared.iter().take_while(|&&i| paths[i] & 1 != 0).count(); + plans.insert(branch, BranchInputs { shared, true_count }); + } + } + plans +} + +#[cfg(test)] +#[path = "branch_inputs.test.rs"] +mod tests; diff --git a/crates/nodes/src/function/branch_inputs.test.rs b/crates/nodes/src/function/branch_inputs.test.rs new file mode 100644 index 00000000..60a26305 --- /dev/null +++ b/crates/nodes/src/function/branch_inputs.test.rs @@ -0,0 +1,429 @@ +use crate::function::{EvaluationContext, EvaluationState, FunctionScope, compile}; +use materialcraft_core::{FunctionGraph, Value}; +use std::collections::BTreeMap; + +fn constant_call(graph: &mut FunctionGraph, value: f32) -> u32 { + let id = graph.add("instance", &[], None); + let node = graph.nodes.last_mut().unwrap(); + node.instance = Some(materialcraft_core::GraphInstance { + graph: "constant".into(), + label: String::new(), + package: String::new(), + inputs: Vec::new(), + outputs: Vec::new(), + defaults: BTreeMap::new(), + }); + node.source = Some(Ok(std::sync::Arc::new(FunctionGraph::constant(Value::Float(value))))); + id +} + +#[test] +fn a_closed_function_call_preserves_shared_draw_order_in_a_pattern_assignment() { + let mut graph = FunctionGraph::default(); + let first = graph.add("get_bool", &[], Some(Value::Text("first".into()))); + let unit = graph.add_constant(Value::Float(1.0)); + let shared = graph.add("rand", &[unit], None); + let other = graph.add("rand", &[unit], None); + let chosen = graph.add("ifelse", &[first, shared, other], None); + let published = graph.add("set", &[chosen], Some(Value::Text("published".into()))); + let quarter = graph.add_constant(Value::Float(0.25)); + let weighted = graph.add("mul", &[shared, quarter], None); + let total = graph.add("add", &[published, weighted], None); + let angle = constant_call(&mut graph, std::f32::consts::PI); + let eighth = graph.add_constant(Value::Float(0.125)); + let offset = graph.add("mul", &[angle, eighth], None); + graph.output = Some(graph.add("add", &[total, offset], None)); + + // Raw F32 tint words for the two choices on three independently measured stamp seeds. + for (seed, expected) in [(11_038_009, [0x3f00baf2, 0x3f1faf8a]), (9_766_418, [0x3fa910f3, 0x3f3da6cd]), (22_858_730, [0x3f878418, 0x3fcc33e4])] { + let program = compile(&graph, seed).unwrap(); + for (first, word) in [false, true].into_iter().zip(expected) { + let variables = BTreeMap::from([("first".into(), Value::Bool(first))]); + let context = EvaluationContext { + scope: FunctionScope::FxMap, + position: [0.5; 2], + size: [16.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + assert_eq!(program.evaluate(&context, &mut EvaluationState::default()).unwrap(), Value::Float(f32::from_bits(word)), "{seed}, {first}"); + } + } +} + +#[test] +fn reading_one_packed_channel_before_a_pure_call_consumes_only_its_draw() { + for lane in [0, 1] { + let mut graph = FunctionGraph::default(); + let unit = graph.add_constant(Value::Float(1.0)); + let [a, b, next] = std::array::from_fn(|_| graph.add("rand", &[unit], None)); + let pair = graph.add("vector2", &[a, b], None); + let selected = graph.add("swizzle1", &[pair], Some(Value::Int(lane))); + let saved = graph.add("set", &[selected], Some(Value::Text("published".into()))); + let quarter = graph.add_constant(Value::Float(0.25)); + let weighted = graph.add("mul", &[next, quarter], None); + let sum = graph.add("add", &[saved, weighted], None); + let offset = constant_call(&mut graph, 0.125); + graph.output = Some(graph.add("add", &[sum, offset], None)); + let variables = BTreeMap::new(); + let context = EvaluationContext { + scope: FunctionScope::FxMap, + position: [0.5; 2], + size: [16.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + for (seed, word) in [(11_038_009, 0x3ea6d4ee), (9_766_418, 0x3f1e3da6), (22_858_730, 0x3f98c3fa)] { + let value = compile(&graph, seed).unwrap().evaluate(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(value, Value::Float(f32::from_bits(word)), "{seed}, lane {lane}"); + } + } +} + +#[test] +fn shared_conditional_draws_follow_their_arm_and_keep_their_original_position() { + let mut graph = FunctionGraph::default(); + let choice = graph.add("get_bool", &[], Some(Value::Text("first".into()))); + let one = graph.add_constant(Value::Float(1.0)); + let quarter = graph.add_constant(Value::Float(0.25)); + let [a, b, c, next] = std::array::from_fn(|_| graph.add("rand", &[one], None)); + let left = graph.add("add", &[b, a], None); + let right = graph.add("add", &[c, a], None); + let either = graph.add("ifelse", &[choice, left, right], None); + let false_only = graph.add("ifelse", &[choice, b, a], None); + let sum = graph.add("add", &[next, a], None); + let weighted = graph.add("mul", &[sum, quarter], None); + let both_result = graph.add("add", &[either, weighted], None); + let right_result = graph.add("add", &[false_only, weighted], None); + let pair = graph.add("vector2", &[a, b], None); + let control = graph.add("vector3", &[pair, c], None); + + for scope in [FunctionScope::Node, FunctionScope::PixelProcessor, FunctionScope::ValueProcessor, FunctionScope::FxMap] { + for first in [true, false] { + let values = BTreeMap::from([("first".into(), Value::Bool(first))]); + let ctx = EvaluationContext { scope, size: [16.0; 2], position: [0.03125; 2], images: &[], image_formats: &[], tile: true, variables: &values }; + for seed in [3, 20] { + graph.output = Some(control); + let Value::Float3([r1, r2, r3]) = compile(&graph, seed).unwrap().evaluate(&ctx, &mut EvaluationState::default()).unwrap() else { + panic!("three draws") + }; + let expected_both = r1 + r2 + (r3 + if first { r2 } else { r1 }) * 0.25; + let expected_right = if first { r1 + (r3 + r2) * 0.25 } else { r1 + (r2 + r1) * 0.25 }; + for (output, expected) in [(both_result, expected_both), (right_result, expected_right)] { + graph.output = Some(output); + assert_eq!( + compile(&graph, seed).unwrap().evaluate(&ctx, &mut EvaluationState::default()).unwrap(), + Value::Float(expected), + "{scope:?}, {first}, {output}" + ); + } + } + } + } +} + +#[test] +fn an_assignment_shared_only_with_the_later_arm_keeps_the_earlier_arms_read() { + let mut graph = FunctionGraph::default(); + let name = Some(Value::Text("tone".into())); + let choice = graph.add("get_bool", &[], Some(Value::Text("first".into()))); + let start = graph.add_constant(Value::Float(0.125)); + let changed = graph.add_constant(Value::Float(0.625)); + let quarter = graph.add_constant(Value::Float(0.25)); + let init = graph.add("set", &[start], name.clone()); + let set = graph.add("set", &[changed], name.clone()); + let read = graph.add("get_float1", &[], name); + let left = graph.add("ifelse", &[choice, set, read], None); + let right = graph.add("ifelse", &[choice, read, set], None); + let weighted = graph.add("mul", &[set, quarter], None); + let left_sum = graph.add("add", &[left, weighted], None); + let right_sum = graph.add("add", &[right, weighted], None); + let left_result = graph.add("sequence", &[init, left_sum], None); + let right_result = graph.add("sequence", &[init, right_sum], None); + for scope in [FunctionScope::Node, FunctionScope::PixelProcessor, FunctionScope::ValueProcessor, FunctionScope::FxMap] { + for first in [false, true] { + let values = BTreeMap::from([("first".into(), Value::Bool(first))]); + let ctx = EvaluationContext { scope, size: [16.0; 2], position: [0.03125; 2], images: &[], image_formats: &[], tile: true, variables: &values }; + for (root, expected) in [(left_result, 0.78125), (right_result, if first { 0.28125 } else { 0.78125 })] { + graph.output = Some(root); + assert_eq!( + compile(&graph, 0).unwrap().evaluate(&ctx, &mut EvaluationState::default()).unwrap(), + Value::Float(expected), + "{scope:?}, {first}, {root}" + ); + } + } + } +} + +#[test] +fn a_later_random_call_preserves_the_draws_in_a_sequence_assignment() { + // The second sequence input calls a separate graph that draws from the same stamp stream. + for (vector, expected) in [ + (true, [[0x3e5c760a, 0x3ee8063f], [0x3f1b5b11, 0x3f297df4], [0x3f4c65e0, 0x3edef0a6]]), + (false, [[0x3e1fa354, 0x3e74cd9a], [0x3f846c61, 0x3ee92f7e], [0x3f377cfc, 0x3fa0bebe]]), + ] { + let mut graph = FunctionGraph::default(); + let first = graph.add("get_bool", &[], Some(Value::Text("first".into()))); + let unit = graph.add_constant(Value::Float(1.0)); + let [a, b, c, d] = std::array::from_fn(|_| graph.add("rand", &[unit], None)); + let name = Some(Value::Text("firstValue".into())); + let (saved, read) = if vector { + let left = graph.add("vector2", &[a, b], None); + let right = graph.add("vector2", &[c, d], None); + let factor = graph.add_constant(Value::Float(0.375)); + let value = graph.add("lerp", &[left, right, factor], None); + let saved = graph.add("set", &[value], name.clone()); + let read = graph.add("get_float2", &[], name.clone()); + let x = graph.add("swizzle1", &[read], Some(Value::Int(0))); + let y = graph.add("swizzle1", &[read], Some(Value::Int(1))); + (saved, graph.add("ifelse", &[first, y, x], None)) + } else { + let value = graph.add("ifelse", &[first, a, b], None); + let saved = graph.add("set", &[value], name.clone()); + let read = graph.add("get_float1", &[], name); + let quarter = graph.add_constant(Value::Float(0.25)); + let shared = graph.add("mul", &[a, quarter], None); + (saved, graph.add("add", &[read, shared], None)) + }; + let mut sampler = FunctionGraph::default(); + let range = sampler.add_constant(Value::Float(1.0)); + sampler.output = Some(sampler.add("rand", &[range], None)); + let sampled = graph.add("instance", &[], None); + let node = graph.nodes.last_mut().unwrap(); + node.instance = Some(materialcraft_core::GraphInstance { + graph: "next_sample".into(), + label: String::new(), + package: String::new(), + inputs: Vec::new(), + outputs: Vec::new(), + defaults: BTreeMap::new(), + }); + node.source = Some(Ok(std::sync::Arc::new(sampler))); + let eighth = graph.add_constant(Value::Float(0.125)); + let offset = graph.add("mul", &[sampled, eighth], None); + let result = graph.add("add", &[read, offset], None); + graph.output = Some(graph.add("sequence", &[saved, result], None)); + for (seed, words) in [11_038_009, 9_766_418, 22_858_730].into_iter().zip(expected) { + let program = compile(&graph, seed).unwrap(); + for (first, word) in [false, true].into_iter().zip(words) { + let variables = BTreeMap::from([("first".into(), Value::Bool(first))]); + let context = EvaluationContext { + scope: FunctionScope::FxMap, + position: [0.5; 2], + size: [16.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + assert_eq!( + program.evaluate(&context, &mut EvaluationState::default()).unwrap(), + Value::Float(f32::from_bits(word)), + "{seed}, {first}, {vector}" + ); + } + } + } +} + +#[test] +fn a_pattern_conditional_with_a_literal_test_leaves_unused_draws_for_later() { + // A stored choice shares an expression with a later use. Only the inner switch is exposed. + for (reversed, unwired) in [(false, false), (true, false), (false, true)] { + let mut graph = FunctionGraph::default(); + let name = Some(Value::Text("chosen".into())); + let inner = graph.add("get_bool", &[], Some(Value::Text("inner".into()))); + let one = graph.add_constant(Value::Float(1.0)); + let [a, t, e] = std::array::from_fn(|_| graph.add("rand", &[one], None)); + let fallback = graph.add_constant(Value::Float(0.3125)); + let theta = graph.add("ifelse", &[inner, t, fallback], None); + let shared = graph.add("add", &[a, theta], None); + let fixed = graph.add_constant(Value::Float(0.1875)); + let choice = if reversed { + let yes = graph.add_constant(Value::Bool(true)); + graph.add("ifelse", &[yes, fixed, shared], None) + } else { + let low = if unwired { graph.add("get_float1", &[], Some(Value::Text("outer".into()))) } else { graph.add_constant(Value::Float(0.25)) }; + let high = graph.add_constant(Value::Float(0.5)); + let no = graph.add("gt", &[low, high], None); + graph.add("ifelse", &[no, shared, fixed], None) + }; + let saved = graph.add("set", &[choice], name.clone()); + let read = graph.add("get_float1", &[], name); + let half = graph.add_constant(Value::Float(0.5)); + let quarter = graph.add_constant(Value::Float(0.25)); + let eighth = graph.add_constant(Value::Float(0.125)); + let next = graph.add("mul", &[e, half], None); + let later = graph.add("mul", &[shared, quarter], None); + let value = graph.add("mul", &[read, eighth], None); + let sum = graph.add("add", &[next, later], None); + let result = graph.add("add", &[sum, value], None); + graph.output = Some(graph.add("sequence", &[saved, result], None)); + if unwired { + let callee = std::mem::take(&mut graph); + let inner = graph.add("get_bool", &[], Some(Value::Text("inner".into()))); + graph.output = Some(graph.add("instance", &[inner], None)); + let call = graph.nodes.last_mut().unwrap(); + call.inputs.insert(0, None); + call.instance = Some(materialcraft_core::GraphInstance { + graph: "nested_choice".into(), + label: String::new(), + package: String::new(), + inputs: vec![ + materialcraft_core::GraphPort { identifier: "outer".into(), type_code: 256 }, + materialcraft_core::GraphPort { identifier: "inner".into(), type_code: 4 }, + ], + outputs: Vec::new(), + defaults: BTreeMap::from([("outer".into(), Value::Float(0.0)), ("inner".into(), Value::Bool(false))]), + }); + call.source = Some(Ok(std::sync::Arc::new(callee))); + } + for (seed, words) in [(11_038_009, [0x3e570414, 0x3e64b294]), (9_766_418, [0x3ee92f65, 0x3f171545]), (22_858_730, [0x3f30619c, 0x3f365b11])] { + let program = compile(&graph, seed).unwrap(); + for (flag, word) in [false, true].into_iter().zip(words) { + let variables = BTreeMap::from([("inner".into(), Value::Bool(flag))]); + let context = EvaluationContext { + scope: FunctionScope::FxMap, + position: [0.5; 2], + size: [16.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + assert_eq!( + program.evaluate(&context, &mut EvaluationState::default()).unwrap(), + Value::Float(f32::from_bits(word)), + "{seed}, {flag}, {reversed}, {unwired}" + ); + } + } + } +} + +fn pattern_sample(graph: &FunctionGraph, seed: u32, variables: &BTreeMap) -> Value { + let context = + EvaluationContext { scope: FunctionScope::FxMap, position: [0.5; 2], size: [16.0; 2], images: &[], image_formats: &[], tile: true, variables }; + compile(graph, seed).unwrap().evaluate(&context, &mut EvaluationState::default()).unwrap() +} + +fn sample_function(graph: &mut FunctionGraph, body: FunctionGraph, argument: Option<(&str, u32)>) -> u32 { + let wires: Vec<_> = argument.iter().map(|(_, id)| *id).collect(); + let result = graph.add("instance", &wires, None); + let node = graph.nodes.last_mut().unwrap(); + node.instance = Some(materialcraft_core::GraphInstance { + graph: "sample".into(), + package: String::new(), + label: String::new(), + outputs: Vec::new(), + inputs: argument.iter().map(|(s, _)| materialcraft_core::GraphPort { identifier: (*s).into(), type_code: 256 }).collect(), + defaults: argument.iter().map(|(s, _)| ((*s).into(), Value::Float(0.0))).collect(), + }); + node.source = Some(Ok(std::sync::Arc::new(body))); + result +} + +#[test] +fn pattern_draws_in_a_shared_inner_choice_stay_conditional() { + for called in [false, true] { + let mut graph = FunctionGraph::default(); + let first = graph.add("get_bool", &[], Some(Value::Text("outer".into()))); + let second = graph.add("get_bool", &[], Some(Value::Text("inner".into()))); + let one = graph.add_constant(Value::Float(1.0)); + let a = graph.add("rand", &[one], None); + let t = if called { + let mut body = FunctionGraph::default(); + let unit = body.add_constant(Value::Float(1.0)); + body.output = Some(body.add("rand", &[unit], None)); + sample_function(&mut graph, body, None) + } else { + graph.add("rand", &[one], None) + }; + let fallback = graph.add_constant(Value::Float(0.3125)); + let inner = graph.add("ifelse", &[second, t, fallback], None); + let shared = graph.add("add", &[a, inner], None); + let constant = graph.add_constant(Value::Float(0.1875)); + let choice = graph.add("ifelse", &[first, shared, constant], None); + let name = Some(Value::Text("chosen".into())); + let saved = graph.add("set", &[choice], name.clone()); + let read = graph.add("get_float1", &[], name); + let next = graph.add("rand", &[one], None); + let half = graph.add_constant(Value::Float(0.5)); + let quarter = graph.add_constant(Value::Float(0.25)); + let eighth = graph.add_constant(Value::Float(0.125)); + let offset = graph.add("mul", &[next, half], None); + let later = graph.add("mul", &[shared, quarter], None); + let stored = graph.add("mul", &[read, eighth], None); + let sum = graph.add("add", &[offset, later], None); + let result = graph.add("add", &[sum, stored], None); + graph.output = Some(graph.add("sequence", &[saved, result], None)); + for (seed, words) in [ + (11038009, [0x3e380f7c, 0x3e898718, 0x3e5fb8ee, 0x3e8d7364]), + (9766418, [0x3f19b678, 0x3f3bbfde, 0x3f269ff5, 0x3f5a223a]), + (22858730, [0x3f0e09b6, 0x3f12c15a, 0x3f30d34c, 0x3f392892]), + ] { + for ((outer, inner), word) in [(false, false), (false, true), (true, false), (true, true)].into_iter().zip(words) { + let variables = BTreeMap::from([("outer".into(), Value::Bool(outer)), ("inner".into(), Value::Bool(inner))]); + assert_eq!(pattern_sample(&graph, seed, &variables), Value::Float(f32::from_bits(word)), "{seed}, {outer}, {inner}, {called}"); + } + } + } +} + +#[test] +fn pattern_draws_with_computed_arguments_keep_their_place_across_a_choice() { + for (called, expected) in [ + (false, [(11038009, [0x3f0468bc, 0x3ec2006a]), (9766418, [0x3f94855e, 0x3f70a852]), (22858730, [0x402f3ff5, 0x3ff5be5e])]), + (true, [(11038009, [0xbeafa1b4, 0xbe474368]), (9766418, [0x3f4de37f, 0x3f33e37f]), (22858730, [0x3f16768b, 0x3ef8ed16])]), + ] { + let mut graph = FunctionGraph::default(); + let flag = graph.add("get_bool", &[], Some(Value::Text("switch".into()))); + let unit = graph.add_constant(Value::Float(1.0)); + let half = graph.add_constant(Value::Float(0.5)); + let sample = if called { + let weight = graph.add("get_float1", &[], Some(Value::Text("weight".into()))); + let chance = graph.add("mul", &[weight, half], None); + let mut body = FunctionGraph::default(); + let one = body.add_constant(Value::Float(1.0)); + let u = body.add("rand", &[one], None); + let p = body.add("get_float1", &[], Some(Value::Text("chance".into()))); + let test = body.add("lr", &[u, p], None); + let minus_one = body.add_constant(Value::Float(-1.0)); + body.output = Some(body.add("ifelse", &[test, minus_one, one], None)); + sample_function(&mut graph, body, Some(("chance", chance))) + } else { + let count = graph.add("get_integer1", &[], Some(Value::Text("count".into()))); + let pair = graph.add("ivector2", &[count, count], None); + let floats = graph.add("tofloat2", &[pair], None); + let scale = graph.add("swizzle1", &[floats], Some(Value::Int(0))); + let zero = graph.add_constant(Value::Float(0.0)); + let bound = graph.add("max", &[zero, scale], None); + graph.add("rand", &[bound], None) + }; + let fixed = graph.add_constant(Value::Float(0.1875)); + let choice = graph.add("ifelse", &[flag, fixed, sample], None); + let name = Some(Value::Text("picked".into())); + let saved = graph.add("set", &[choice], name.clone()); + let read = graph.add("get_float1", &[], name); + let next = graph.add("rand", &[unit], None); + let quarter = graph.add_constant(Value::Float(0.25)); + let eighth = graph.add_constant(Value::Float(0.125)); + let offset = graph.add("mul", &[next, half], None); + let weighted = graph.add("mul", &[sample, quarter], None); + let old = graph.add("mul", &[read, eighth], None); + let sum = graph.add("add", &[offset, weighted], None); + let result = graph.add("add", &[sum, old], None); + graph.output = Some(graph.add("sequence", &[saved, result], None)); + for (seed, words) in expected { + for (flag, word) in [false, true].into_iter().zip(words) { + let variables = BTreeMap::from([("switch".into(), Value::Bool(flag)), ("weight".into(), Value::Float(0.5)), ("count".into(), Value::Int(7))]); + assert_eq!(pattern_sample(&graph, seed, &variables), Value::Float(f32::from_bits(word)), "{seed}, {flag}, {called}"); + } + } + } +} diff --git a/crates/nodes/src/function/compile.rs b/crates/nodes/src/function/compile.rs index 133510f0..4d6539c0 100644 --- a/crates/nodes/src/function/compile.rs +++ b/crates/nodes/src/function/compile.rs @@ -1,10 +1,29 @@ use super::{Program, catalog, instruction::Instruction}; -use materialcraft_core::FunctionGraph; +use materialcraft_core::{FunctionGraph, ValueType}; use std::collections::{BTreeMap, BTreeSet}; pub fn compile(graph: &FunctionGraph, seed: u32) -> Result { + compile_with_literal_inputs(graph, seed, &[]) +} + +/// Compile with the named inputs fixed by an enclosing graph instance. +pub fn compile_with_literal_inputs(graph: &FunctionGraph, seed: u32, literal_inputs: &[String]) -> Result { + compile_program(graph, seed, literal_inputs, None) +} + +pub(super) fn compile_program( + graph: &FunctionGraph, + seed: u32, + literal_inputs: &[String], + pixel: Option<&super::EvaluationContext<'_>>, +) -> Result { let mut remaining = super::MAX_EXPANDED_NODES; - compile_nested(graph, seed, 0, &mut remaining) + let mut program = compile_nested(graph, seed, 0, &mut remaining)?; + mark_literals(&mut program, literal_inputs.iter().map(|name| (name.as_str(), Constant::Literal)).collect()); + super::reciprocal::identify_products(&mut program, BTreeMap::new()); + plan_pixel_operations(&mut program, pixel, true); + super::assigned_product::identify(&mut program); + Ok(program) } fn compile_nested(graph: &FunctionGraph, seed: u32, depth: usize, remaining: &mut usize) -> Result { @@ -107,7 +126,13 @@ fn compile_nested(graph: &FunctionGraph, seed: u32, depth: usize, remaining: &mu inputs: Vec::new(), value: Some(value), type_code, - repeated: Vec::new(), + literal: true, + pattern_literal: true, + literal_divisor: false, + reciprocal_factor: None, + pixel_product_sum: None, + pixel_interval: None, + control_registers: Vec::new(), call: None, }); instructions.len() - 1 @@ -116,6 +141,12 @@ fn compile_nested(graph: &FunctionGraph, seed: u32, depth: usize, remaining: &mu inputs.push(index); } + if matches!(node.op.as_str(), "vector2" | "vector3" | "vector4" | "ivector2" | "ivector3" | "ivector4") + && ports.first().is_some_and(|(_, input)| input.is_none()) + { + // Connected components occupy the leading lanes. The inferred zero operand pads the end. + inputs.reverse(); + } inputs }; @@ -134,20 +165,63 @@ fn compile_nested(graph: &FunctionGraph, seed: u32, depth: usize, remaining: &mu return Err(format!("{}: input `{}` has the wrong type", instance.graph, port.identifier)); } } - let inputs = ports.iter().filter(|(_, input)| input.is_some()).map(|(name, _)| (*name).to_string()).collect(); + let names: Vec<_> = ports.iter().filter(|(_, input)| input.is_some()).map(|(name, _)| (*name).to_string()).collect(); + let mut defaults = instance.defaults.clone(); + if !names.is_empty() { + // Once a call supplies arguments, an omitted numeric argument reads its typed zero. + for (name, input) in &ports { + if input.is_none() + && let Some(value) = defaults.get_mut(*name) + && let Some(kind) = ValueType::of(value) + && kind != ValueType::String + { + *value = kind.default_value(); + } + } + } let exports = program.instructions.iter().any(|instruction| instruction.definition.id == "set" || instruction.call.as_ref().is_some_and(|call| call.exports)); - Some(super::function_call::FunctionCall { program, inputs, defaults: instance.defaults.clone(), exports }) + let pattern_arguments = super::function_call::PatternArguments::identify(&program, &names, &defaults, &inputs); + Some(super::function_call::FunctionCall { + pattern_access: super::function_call::PatternAccess::identify(&program, &defaults), + program, + inputs: names, + defaults, + argument_factors: None, + reciprocals: None, + assigned_products: Vec::new(), + pattern_arguments, + exports, + }) } else { None }; - let value = node.value.clone().or_else(|| catalog::default_value(&node.op)); + let mut value = node.value.clone().or_else(|| catalog::default_value(&node.op)); + // Getters consume one reference marker. Set and Is Defined address the literal name. + if definition.id.starts_with("get_") + && let Some(materialcraft_core::Value::Text(name)) = &mut value + && let Some(identifier) = name.strip_prefix('%') + { + *name = identifier.to_owned(); + } let input_type = |index: usize| inputs.get(index).and_then(|index| instructions.get(*index)).map_or(256, |instruction| instruction.type_code); let inferred = super::inferred_type::inferred_type(&node.op, value.as_ref(), input_type); let type_code = call.as_ref().map_or_else(|| if node.type_code == 0 { inferred } else { node.type_code }, |call| call.program.output_type()); + let operation = |inputs, value, call| Instruction { call, ..Instruction::new(id, definition, inputs, value, type_code) }; + let mut inputs = inputs; + if definition.id == "rand" + && type_code == 256 + && let [range] = inputs.as_slice() + && instructions.get(*range).is_some_and(|r| r.type_code == 256 && r.value != Some(materialcraft_core::Value::Float(1.0))) + { + // Keep the unit sample in a register. A packed or shared range can then reuse its + // unrounded factors without drawing again, including on each loop iteration. + inputs.push(instructions.len()); + instructions.push(operation(Vec::new(), None, None)); + } indices.insert(id, instructions.len()); - instructions.push(Instruction { id, definition, inputs, value, type_code, repeated: Vec::new(), call }); + instructions.push(operation(inputs, value, call)); } // Instructions come after their inputs, so walking back from a loop reaches its whole condition and body @@ -155,14 +229,132 @@ fn compile_nested(graph: &FunctionGraph, seed: u32, depth: usize, remaining: &mu if instructions.get(index).is_some_and(|instruction| instruction.definition.id == "while") { let repeated = loop_members(&instructions, index); if let Some(instruction) = instructions.get_mut(index) { - instruction.repeated = repeated; + instruction.control_registers = repeated; } } } let output = indices.get(&output).copied().ok_or("missing result instruction")?; - Ok(Program { instructions, output, seed }) + let sequence_prefixes = super::sequence_prefix::identify(&instructions, output); + Ok(Program { + instructions, + output, + seed, + sequence_prefixes, + processor_branches: BTreeMap::new(), + pattern_branches: BTreeMap::new(), + pattern_components: BTreeMap::new(), + loop_sums: BTreeMap::new(), + }) +} + +/// A write can replace an argument before its next read. +pub(super) fn remove_written_arguments(program: &Program, arguments: &mut BTreeMap<&str, T>) { + for op in &program.instructions { + if arguments.is_empty() { + break; + } + if let Some(call) = &op.call + && call.exports + { + // A callee's unrelated assignments leave the caller's known operands available. + remove_written_arguments(&call.program, arguments); + } + if op.definition.id == "set" + && let Some(materialcraft_core::Value::Text(name)) = &op.value + { + arguments.remove(name.as_str()); + } + } +} + +// A pure expression is fixed only as far as its least constant operand. +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +enum Constant { + Varying, + PatternDefault, + Literal, +} + +fn mark_literals(program: &mut Program, mut arguments: BTreeMap<&str, Constant>) -> Constant { + remove_written_arguments(program, &mut arguments); + let mut literals = Vec::with_capacity(program.instructions.len()); + for op in &mut program.instructions { + let source = |index: &usize| literals.get(*index).copied().unwrap_or(Constant::Varying); + let id = op.definition.id; + op.literal_divisor = id == "div" && op.inputs.get(1).is_some_and(|i| source(i) == Constant::Literal); + let constant = if let Some(call) = &mut op.call { + let mut bound: BTreeMap<_, _> = call.defaults.keys().map(|name| (name.as_str(), Constant::PatternDefault)).collect(); + for (name, input) in call.inputs.iter().zip(&op.inputs) { + bound.insert(name.as_str(), source(input)); + } + mark_literals(&mut call.program, bound) + } else if id.starts_with("const_") { + Constant::Literal + } else if id.starts_with("get_") + && let Some(materialcraft_core::Value::Text(name)) = &op.value + { + arguments.get(name.as_str()).copied().unwrap_or(Constant::Varying) + } else if op.depends_only_on_operands() { + op.inputs.iter().map(source).min().unwrap_or(Constant::Varying) + } else { + Constant::Varying + }; + op.literal = constant == Constant::Literal; + op.pattern_literal = constant != Constant::Varying; + literals.push(constant); + } + literals.get(program.output).copied().unwrap_or(Constant::Varying) +} + +fn plan_pixel_operations(program: &mut Program, pixel: Option<&super::EvaluationContext<'_>>, root: bool) -> super::returned_product::Lanes { + let mut returned = BTreeMap::new(); + for index in 0..program.instructions.len() { + let (previous, current) = program.instructions.split_at_mut(index); + if let Some(op) = current.first_mut() { + if let Some(call) = &mut op.call { + let lanes = plan_pixel_operations(&mut call.program, None, false); + if lanes.iter().any(Option::is_some) { + returned.insert(index, lanes); + } + } + op.pixel_interval = pixel_interval(op, previous).map(Box::new); + } + } + let readers = pixel.and_then(|context| super::pixel_condition::live_readers(program, context)); + super::product_sum::identify(&mut program.instructions, readers.as_deref()); + super::branch_assignments::identify(program); + // Only pixel consumers can force a product to round before a later sum. The pattern + // channel pass appends its own reads, which the pixel evaluator never visits. + let exported = super::returned_product::identify(program, returned, root); + let original_len = program.instructions.len(); + let pattern_end = super::sequence_prefix::pattern_planning_end(program); + super::vector::identify_pattern_components(program, pattern_end, root); + super::branch_inputs::identify(program, pattern_end..original_len); + program.loop_sums = + program.instructions.iter().enumerate().filter_map(|(index, op)| super::loop_sum::LoopSum::identify(program, op).map(|sum| (index, sum))).collect(); + exported +} + +fn pixel_interval(op: &Instruction, previous: &[Instruction]) -> Option { + if op.definition.id != "max" || op.type_code != 256 { + return None; + } + let &[a, b] = op.inputs.as_slice() else { return None }; + for (lower, inner) in [(a, b), (b, a)] { + let minimum = previous.get(inner)?; + if !previous.get(lower)?.literal || minimum.definition.id != "min" { + continue; + } + let &[x, y] = minimum.inputs.as_slice() else { continue }; + for (input, upper) in [(x, y), (y, x)] { + if previous.get(upper)?.literal { + return Some(super::instruction::PixelInterval { input, lower, upper, input_is_literal: previous.get(input)?.literal }); + } + } + } + None } /// The instructions the condition and the body of loop `index` evaluate again on every iteration diff --git a/crates/nodes/src/function/evaluation_context.rs b/crates/nodes/src/function/evaluation_context.rs index 1a5eba0f..3048ca91 100644 --- a/crates/nodes/src/function/evaluation_context.rs +++ b/crates/nodes/src/function/evaluation_context.rs @@ -8,6 +8,8 @@ pub struct EvaluationContext<'a> { pub position: [f32; 2], pub size: [f32; 2], pub images: &'a [Option], + /// Stored formats of image slots supplied by the caller. + pub image_formats: &'a [materialcraft_core::OutputFormat], pub tile: bool, pub variables: &'a BTreeMap, } diff --git a/crates/nodes/src/function/evaluation_state.rs b/crates/nodes/src/function/evaluation_state.rs index 9b0c9a50..b62a8943 100644 --- a/crates/nodes/src/function/evaluation_state.rs +++ b/crates/nodes/src/function/evaluation_state.rs @@ -7,14 +7,26 @@ use std::collections::BTreeMap; pub struct EvaluationState { pub(crate) steps: Vec, pub(crate) values: Vec, + pub(super) visited_prefixes: Vec, pub(crate) registers: Vec>, pub(crate) variables: BTreeMap, pub(crate) assignments: BTreeMap, - pub(crate) random: u32, + pub(crate) random: crate::random::FunctionRandom, + pub(super) argument_factors: Option<[f32; 2]>, + pub(super) assigned_arguments: Vec>, + pub(super) reciprocal_arguments: Vec>, + pub(super) returned_reciprocals: [Option; 4], pub(crate) calls: BTreeMap, } impl EvaluationState { + pub(super) fn scalar_register(&self, index: usize) -> Option { + match self.registers.get(index)? { + Some(Value::Float(value)) => Some(*value), + _ => None, + } + } + pub fn variables(&self) -> &BTreeMap { &self.variables } @@ -24,3 +36,65 @@ impl EvaluationState { &self.assignments } } + +/// A loop can change the random stream, the variables it writes and the assignments its caller sees. +pub(crate) struct LoopCheckpoint { + random: crate::random::FunctionRandom, + writes: Vec<(String, Value, Option)>, + sum: Option, +} + +impl LoopCheckpoint { + pub(super) fn capture(state: &EvaluationState, accumulator: Option<&super::loop_sum::LoopSum>) -> Option> { + let sum = accumulator.and_then(|plan| plan.start(state)); + let mut writes = Vec::with_capacity(state.assignments.len()); + for (name, value) in &state.assignments { + if sum.as_ref().is_some_and(|cycle| cycle.name == *name) { + continue; + } + let visible = state.variables.get(name); + materialcraft_core::ValueType::of(value)?; + if let Some(visible) = visible { + materialcraft_core::ValueType::of(visible)?; + } + writes.push((name.clone(), value.clone(), visible.cloned())); + } + Some(Box::new(Self { random: state.random, writes, sum })) + } + + pub(super) fn tracks_sum(&self) -> bool { + self.sum.is_some() + } + + pub(super) fn record_body(&mut self, state: &EvaluationState, last: &Value) -> bool { + self.sum.as_mut().is_none_or(|cycle| cycle.record(state, last)) + } + + pub(super) fn advance(&self, state: &mut EvaluationState, last: &mut Value, remaining: u32, budget: &mut usize) -> u32 { + if self.random != state.random || self.writes.len() + usize::from(self.sum.is_some()) != state.assignments.len() { + return 0; + } + let writes = state.assignments.iter().filter(|(name, _)| self.sum.as_ref().is_none_or(|cycle| &cycle.name != *name)); + if !self.writes.iter().zip(writes).all(|((name, written, visible), (current, value))| { + name == current && same_loop_value(Some(written), Some(value)) && same_loop_value(visible.as_ref(), state.variables.get(name)) + }) { + return 0; + } + self.sum.as_ref().map_or(remaining, |cycle| cycle.replay(state, last, remaining, budget)) + } +} + +fn same_loop_value(left: Option<&Value>, right: Option<&Value>) -> bool { + match (left, right) { + (None, None) => true, + (Some(a), Some(b)) if std::mem::discriminant(a) == std::mem::discriminant(b) => match a { + // A later operation can distinguish signed zero or inspect a float's bits. + Value::Float(_) | Value::Float2(_) | Value::Float3(_) | Value::Float4(_) | Value::Color(_) => { + a.as_vec4().map(|v| v.map(f32::to_bits)) == b.as_vec4().map(|v| v.map(f32::to_bits)) + } + Value::Bool(_) | Value::Int(_) | Value::Int2(_) | Value::Int3(_) | Value::Int4(_) | Value::Text(_) | Value::Enum(_) => a == b, + _ => false, + }, + _ => false, + } +} diff --git a/crates/nodes/src/function/evaluation_step.rs b/crates/nodes/src/function/evaluation_step.rs index ce11a7fd..4c1092ad 100644 --- a/crates/nodes/src/function/evaluation_step.rs +++ b/crates/nodes/src/function/evaluation_step.rs @@ -1,12 +1,16 @@ use materialcraft_core::Value; +use super::evaluation_state::LoopCheckpoint; + pub(crate) enum EvaluationStep { Enter(usize), Store(usize), Apply { instruction: usize, base: usize }, - Branch(usize), + Branch { instruction: usize, prefix: bool }, + Prefix(usize), + Discard, Sequence(usize), LoopStart(usize), - LoopCondition { instruction: usize, iteration: u32, last: Value }, - LoopBody { instruction: usize, iteration: u32 }, + LoopCondition { instruction: usize, iteration: u32, last: Value, checkpoint: Option> }, + LoopBody { instruction: usize, iteration: u32, checkpoint: Option> }, } diff --git a/crates/nodes/src/function/fixed_point.rs b/crates/nodes/src/function/fixed_point.rs new file mode 100644 index 00000000..fafa087f --- /dev/null +++ b/crates/nodes/src/function/fixed_point.rs @@ -0,0 +1,47 @@ +pub(super) struct Quadratic { + pub constant: i64, + pub slope: i64, + pub curvature: i64, +} + +impl Quadratic { + // Fit one interval in local coordinates t=0..1. The derivatives are taken at t=1/2. + pub fn fit(value: impl Fn(f64) -> f64, [first, second, third]: [f64; 3], [a, b, c]: [i32; 3]) -> Self { + let curvature_scale = 2_f64.powi(c); + let ratio = 1_i64 << (c - b); + // On [-1/2,1/2] the linear minimax approximation of the centered cubic is 3t/16. + let center_slope = curvature_scale * (first + third / 32.0); + let slope = ((center_slope - curvature_scale * second * 0.5) / ratio as f64).round() as i64; + let curvature = center_slope.round() as i64 - ratio * slope; + let constant_scale = 2_f64.powi(a); + let linear = 2_f64.powi(a - b) * slope as f64; + let square = 2_f64.powi(a - c) * curvature as f64; + let mut low = f64::INFINITY; + let mut high = f64::NEG_INFINITY; + for step in 0..=64 { + let t = f64::from(step) / 64.0; + let residual = constant_scale * value(t) - linear * t - square * t * t; + low = low.min(residual); + high = high.max(residual); + } + Self { constant: ((low + high) * 0.5).round() as i64, slope, curvature } + } +} + +pub(crate) fn truncate_float(value: f64) -> f32 { + let nearest = value as f32; + if f64::from(nearest).abs() > value.abs() { f32::from_bits(nearest.to_bits().saturating_sub(1)) } else { nearest } +} + +// Square a 16-bit fraction, retaining partial products in the top 15 fractional columns. +// A pair of distinct bits contributes twice. A diagonal bit contributes once. +pub(super) fn square_fraction(fraction: u32) -> u32 { + let mut square = 0; + for bit in 1..=7 { + if fraction & (1 << (16 - bit)) != 0 { + let width = 16 - 2 * bit; + square += (1 << (width - 1)) + ((fraction >> bit) & ((1 << width) - 1)); + } + } + square +} diff --git a/crates/nodes/src/function/function_call.rs b/crates/nodes/src/function/function_call.rs index 0096b8d9..5613b8a0 100644 --- a/crates/nodes/src/function/function_call.rs +++ b/crates/nodes/src/function/function_call.rs @@ -1,11 +1,265 @@ use super::{FunctionDefinition, Program}; +use materialcraft_core::Value; +use std::collections::BTreeMap; pub(crate) const DEFINITION: FunctionDefinition = FunctionDefinition { id: "instance", label: "Function instance", inputs: &[], category: "Graph" }; pub(crate) struct FunctionCall { pub program: Program, pub inputs: Vec, - pub defaults: std::collections::BTreeMap, + pub defaults: BTreeMap, + /// Parent registers for an argument used only in scalar sums within the call. + pub(super) argument_factors: Option<[super::reciprocal::Factor; 2]>, + pub(super) assigned_products: Vec, + pub(super) reciprocals: Option>, + pub(super) pattern_arguments: Option, + pub(super) pattern_access: PatternAccess, /// The called graph sets variables, directly or in a graph it calls; the caller reads them after the call pub exports: bool, } + +/// Which state an inlined pattern function needs in addition to its arguments. +#[derive(Clone, Copy, PartialEq, Eq)] +pub(super) enum PatternAccess { + Arguments, + Random, + Context, +} + +impl PatternAccess { + pub(super) fn identify(program: &Program, defaults: &BTreeMap) -> Self { + let mut access = Self::Arguments; + for op in &program.instructions { + let id = op.definition.id; + let reads = if let Some(call) = &op.call { + call.pattern_access + } else if id == "rand" { + Self::Random + } else if id.starts_with("get_") || id == "isdefined" { + if matches!(&op.value, Some(Value::Text(name)) if defaults.contains_key(name)) { Self::Arguments } else { Self::Context } + } else if id.starts_with("const_") || op.depends_only_on_operands() { + Self::Arguments + } else { + Self::Context + }; + match reads { + Self::Context => return Self::Context, + Self::Random => access = Self::Random, + Self::Arguments => {} + } + } + access + } +} + +/// First uses of scalar arguments in a straight-line pattern function, including directly returned channels. +pub(super) struct PatternArguments { + pub registers: Vec, + pub target: PatternTarget, + pub channels: [Option; 4], +} + +pub(super) enum PatternTarget { + Arguments(Vec), + ReturnedChannels, + PackedArgument { width: usize, lanes: [Option; 4] }, +} + +impl PatternArguments { + pub(super) fn identify(program: &Program, names: &[String], defaults: &BTreeMap, registers: &[usize]) -> Option { + if names.is_empty() || !defaults.values().all(|v| matches!(v, Value::Float(_))) { + return None; + } + let slots_by_name: BTreeMap<_, _> = names.iter().enumerate().map(|(slot, name)| (name.as_str(), slot)).collect(); + let mut seen = vec![false; names.len()]; + let mut slots = Vec::new(); + let mut origins = Vec::with_capacity(program.instructions.len()); + for op in &program.instructions { + let mut lanes = [None; 4]; + if let ("get_float1", Some(Value::Text(name))) = (op.definition.id, &op.value) { + if name.starts_with('$') { + return None; + } + defaults.get(name)?; + if let Some(&slot) = slots_by_name.get(name.as_str()) { + lanes[0] = Some(slot); + if !std::mem::replace(seen.get_mut(slot)?, true) { + slots.push(slot); + } + } + } else if let Some(forwarded) = super::returned_product::forwarded(op, &program.instructions, &origins, None) { + lanes = forwarded; + } else if !op.definition.id.starts_with("const_") && (!op.depends_only_on_operands() || matches!(op.definition.id, "ifelse" | "sequence")) { + // Random draws, assignments and control flow can interleave with the caller's inputs. + return None; + } + origins.push(lanes); + } + let selected = origins.get(program.output)?; + let width = super::returned_product::float_width(program.output_type()); + if width > 0 && selected[..width].iter().all(Option::is_some) { + slots.clear(); + seen.fill(false); + for &slot in selected[..width].iter().flatten() { + if !std::mem::replace(seen.get_mut(slot)?, true) { + slots.push(slot); + } + } + } + Some(Self { + registers: slots.iter().map(|slot| registers.get(*slot).copied()).collect::>()?, + target: PatternTarget::Arguments(slots), + channels: selected.map(|slot| slot.and_then(|i| registers.get(i)).copied()), + }) + } +} + +impl FunctionCall { + /// A straight-line function can read the components of a packed argument in a + /// different order from the pack. Repeated reads use the first draw for that lane. + pub(super) fn packed_arithmetic(&self, registers: &[usize], sources: &[[Option; 4]]) -> Option { + use super::returned_product::{float_width, forwarded}; + use super::vector::PatternComponent; + + let ([name], &[input]) = (self.inputs.as_slice(), registers) else { return None }; + let width = float_width(super::value_type::type_code(self.defaults.get(name)?)); + if width < 2 || name.starts_with('$') || self.pattern_access != PatternAccess::Arguments { + return None; + } + let supplied = sources.get(input)?; + if supplied[..width].iter().all(Option::is_none) { + return None; + } + let instructions = self.program.instructions.get(..=self.program.output)?; + let mut origins = Vec::with_capacity(instructions.len()); + for op in instructions { + let lanes = match (op.definition.id, &op.value) { + ("get_float2" | "get_float3" | "get_float4", Some(Value::Text(read))) if read == name && float_width(op.type_code) == width => { + std::array::from_fn(|i| (i < width).then_some(PatternComponent::Register(i))) + } + ("ifelse" | "sequence", _) => return None, + (id, _) if id.starts_with("const_") || op.depends_only_on_operands() => { + forwarded(op, instructions, &origins, Some(PatternComponent::Zero)).unwrap_or([None; 4]) + } + _ => return None, + }; + origins.push(lanes); + } + + let mut pending = vec![self.program.output]; + let mut visited = vec![false; instructions.len()]; + let mut lanes = [None; 4]; + let mut reads = Vec::new(); + while let Some(index) = pending.pop() { + if std::mem::replace(visited.get_mut(index)?, true) { + continue; + } + let op = instructions.get(index)?; + let selected = origins.get(index)?.get(..float_width(op.type_code))?; + if selected.is_empty() || selected.iter().any(Option::is_none) { + pending.extend(op.inputs.iter().rev().copied()); + continue; + } + for &origin in selected.iter().flatten() { + let PatternComponent::Register(lane) = origin else { continue }; + let entry = lanes.get_mut(lane)?; + if entry.is_none() { + match supplied.get(lane)? { + Some(PatternComponent::Register(source)) => { + *entry = Some(reads.len()); + reads.push(*source); + } + Some(PatternComponent::Zero) => {} + None => return None, + } + } + } + } + if lanes[..width].iter().copied().eq((0..width).map(Some)) { + return None; + } + Some(PatternArguments { registers: reads, target: PatternTarget::PackedArgument { width, lanes }, channels: [None; 4] }) + } + + /// A function made entirely of argument reads, vector packs and swizzles can return + /// caller components directly. Sampling one of its return channels then stays lazy. + pub(super) fn packed_projection(&self, registers: &[usize], sources: &[[Option; 4]]) -> Option { + if !self.defaults.values().any(|value| super::returned_product::float_width(super::value_type::type_code(value)) > 1) { + return None; + } + let mut origins = Vec::with_capacity(self.program.instructions.len()); + for op in &self.program.instructions { + let lanes = match (op.definition.id, &op.value) { + ("get_float1" | "get_float2" | "get_float3" | "get_float4", Some(Value::Text(name))) => { + if name.starts_with('$') || super::value_type::type_code(self.defaults.get(name)?) != op.type_code { + return None; + } + let slot = self.inputs.iter().position(|input| input == name)?; + sources.get(*registers.get(slot)?)?.map(|component| match component { + Some(super::vector::PatternComponent::Register(register)) => Some(register), + _ => None, + }) + } + _ => super::returned_product::forwarded(op, &self.program.instructions, &origins, None)?, + }; + origins.push(lanes); + } + let channels = *origins.get(self.program.output)?; + let width = super::returned_product::float_width(self.program.output_type()); + if width == 0 { + return None; + } + Some(PatternArguments { registers: channels.get(..width)?.iter().copied().collect::>()?, target: PatternTarget::ReturnedChannels, channels }) + } +} + +pub(super) fn pack_scalars(values: &[Value]) -> Result { + let mut channels = [0.0; 4]; + let channels = channels.get_mut(..values.len()).ok_or("too many color components")?; + for (channel, value) in channels.iter_mut().zip(values) { + let Value::Float(component) = value else { return Err("expected a scalar color component".into()) }; + *channel = *component; + } + super::value_type::intermediate_float_value(channels) +} + +impl PatternTarget { + pub(super) fn packed_argument(&self, values: &[Value]) -> Result, String> { + let Self::PackedArgument { width, lanes } = self else { return Ok(None) }; + let mut channels = [0.0; 4]; + let channels = channels.get_mut(..*width).ok_or("invalid packed argument width")?; + for (channel, source) in channels.iter_mut().zip(lanes) { + if let Some(index) = source { + let Some(Value::Float(value)) = values.get(*index) else { return Err("expected a scalar argument component".into()) }; + *channel = *value; + } + } + super::value_type::intermediate_float_value(channels).map(Some) + } +} + +/// Wire presence is local to a call. Free variables can be defined by an executed Set in a caller. +pub(super) struct CallBindings<'a> { + pub call: &'a FunctionCall, + pub caller_assignments: &'a BTreeMap, + pub parent: Option<&'a CallBindings<'a>>, +} + +impl CallBindings<'_> { + pub(super) fn is_defined(&self, name: &str, assignments: &BTreeMap) -> bool { + if self.call.defaults.contains_key(name) { + return self.call.inputs.iter().any(|input| input == name); + } + if assignments.contains_key(name) { + return true; + } + let mut frame = Some(self); + while let Some(current) = frame { + if current.caller_assignments.contains_key(name) { + return true; + } + frame = current.parent; + } + false + } +} diff --git a/crates/nodes/src/function/function_scope.rs b/crates/nodes/src/function/function_scope.rs index f0210861..93708716 100644 --- a/crates/nodes/src/function/function_scope.rs +++ b/crates/nodes/src/function/function_scope.rs @@ -3,6 +3,21 @@ pub enum FunctionScope { #[default] Node, + /// A graph or node's base random seed, evaluated as a 32-bit word. + RandomSeed, + ValueProcessor, PixelProcessor, FxMap, + /// A pattern node's seed can read traversal variables and uses seed arithmetic. + FxMapRandomSeed, +} + +impl FunctionScope { + pub(super) fn is_pattern(self) -> bool { + matches!(self, Self::FxMap | Self::FxMapRandomSeed) + } + + pub(super) fn uses_seed_words(self) -> bool { + matches!(self, Self::RandomSeed | Self::FxMapRandomSeed) + } } diff --git a/crates/nodes/src/function/instruction.rs b/crates/nodes/src/function/instruction.rs index e4d40d90..17159c07 100644 --- a/crates/nodes/src/function/instruction.rs +++ b/crates/nodes/src/function/instruction.rs @@ -7,7 +7,82 @@ pub(crate) struct Instruction { pub inputs: Vec, pub value: Option, pub type_code: u32, - /// For a loop: the instructions of its condition and body, evaluated again on every iteration - pub repeated: Vec, + /// Pure expression with only literal inputs. Its arithmetic rounds before pixel evaluation. + pub literal: bool, + /// A pattern condition also folds when its inputs come from unwired function arguments. + pub(super) pattern_literal: bool, + /// A constant denominator folds to its rounded reciprocal even with a varying numerator. + pub(super) literal_divisor: bool, + /// Original scalar divisor retained when a pixel expression divides by its reciprocal. + pub(super) reciprocal_factor: Option, + pub(super) pixel_product_sum: Option, + /// Registers for max(lower, min(value, upper)) with literal scalar bounds. + pub(super) pixel_interval: Option>, + /// A loop refreshes its condition and body. A pixel branch first evaluates its shared effects. + pub control_registers: Vec, pub call: Option, } + +impl Instruction { + pub(super) fn new(id: u32, definition: &'static FunctionDefinition, inputs: Vec, value: Option, type_code: u32) -> Self { + Self { + id, + definition, + inputs, + value, + type_code, + literal: false, + pattern_literal: false, + literal_divisor: false, + reciprocal_factor: None, + pixel_product_sum: None, + pixel_interval: None, + control_registers: Vec::new(), + call: None, + } + } + + pub(super) fn depends_only_on_operands(&self) -> bool { + self.call.is_none() && !self.inputs.is_empty() && !matches!(self.definition.id, "rand" | "samplelum" | "samplecol" | "set" | "while") + } + + pub(super) fn product_operation(&self) -> Option<&'static str> { + // A cancelled reciprocal keeps the original operands live for their other readers. + // The retained-product pass can use its factor after both operands have run. + if self.reciprocal_factor.is_some() { + return None; + } + let [_, _] = self.inputs.as_slice() else { return None }; + match self.definition.id { + "rand" => Some("mul"), + op @ ("mul" | "mulscalar" | "div") => Some(op), + _ => None, + } + } +} + +pub(super) struct PixelInterval { + pub input: usize, + pub lower: usize, + pub upper: usize, + pub input_is_literal: bool, +} + +impl PixelInterval { + pub fn saturate(&self, state: &super::EvaluationState) -> Option { + if state.scalar_register(self.lower)? != 0.0 { + return None; + } + let input = state.scalar_register(self.input)?; + let upper = state.scalar_register(self.upper)?; + let value = if upper == 1.0 { + input + } else if self.input_is_literal && input == 1.0 { + upper + } else { + return None; + }; + // Saturation maps NaN and both signed zeros to positive zero. + Some(Value::Float(if value > 0.0 { value.min(1.0) } else { 0.0 })) + } +} diff --git a/crates/nodes/src/function/loop_sum.rs b/crates/nodes/src/function/loop_sum.rs new file mode 100644 index 00000000..dbb10295 --- /dev/null +++ b/crates/nodes/src/function/loop_sum.rs @@ -0,0 +1,127 @@ +use super::{EvaluationState, Program, flush_subnormal, instruction::Instruction}; +use materialcraft_core::Value; + +/// A scalar sum returned by the loop body. Only its final addition may read the accumulated value. +pub(super) struct LoopSum { + name: String, + term: usize, +} + +impl LoopSum { + pub(super) fn identify(program: &Program, instruction: &Instruction) -> Option { + if instruction.definition.id != "while" { + return None; + } + let &[_, condition, body] = instruction.inputs.as_slice() else { return None }; + let ops = &program.instructions; + let result = ops.get(body)?; + let write = if result.definition.id == "sequence" { *result.inputs.get(1)? } else { body }; + let assignment = ops.get(write)?; + let Some(Value::Text(name)) = &assignment.value else { return None }; + if assignment.definition.id != "set" || name.starts_with('$') || name.is_empty() { + return None; + } + let &[add] = assignment.inputs.as_slice() else { return None }; + let addition = ops.get(add)?; + if addition.definition.id != "add" || addition.type_code != 256 || addition.literal || addition.pixel_product_sum.is_some() { + return None; + } + let &[a, b] = addition.inputs.as_slice() else { return None }; + let reads_sum = |index| ops.get(index).is_some_and(|op: &Instruction| op.definition.id == "get_float1" && op.value == assignment.value); + let (read, term) = match (reads_sum(a), reads_sum(b)) { + (true, false) => (a, b), + (false, true) => (b, a), + _ => return None, + }; + if [read, add, write, body].contains(&condition) || ops.get(term)?.type_code != 256 { + return None; + } + for &index in &instruction.control_registers { + let op = ops.get(index)?; + // A shared read, a second write or a callee that sees the sum can change a later term or the exit. + if (index != read && index != write && refers_to(op, name)) + || op.call.as_ref().is_some_and(|call| call_uses(&call.program, name)) + || op + .inputs + .iter() + .any(|&input| (input == read && index != add) || (input == add && index != write) || (input == write && index != body) || input == body) + { + return None; + } + } + Some(Self { name: name.clone(), term }) + } + + pub(super) fn start(&self, state: &EvaluationState) -> Option { + let Value::Float(value) = state.variables.get(&self.name)? else { return None }; + let Value::Float(written) = state.assignments.get(&self.name)? else { return None }; + (value.is_finite() && value.to_bits() == written.to_bits()).then(|| SumCycle { + name: self.name.clone(), + term: self.term, + previous: *value, + increments: Vec::new(), + }) + } +} + +fn refers_to(op: &Instruction, name: &str) -> bool { + (op.definition.id.starts_with("get_") || matches!(op.definition.id, "set" | "isdefined")) + && matches!(&op.value, Some(Value::Text(variable)) if variable == name) +} + +fn call_uses(program: &Program, name: &str) -> bool { + // Calls have already passed the compiler's depth and expanded instruction limits. + program.instructions.iter().any(|op| refers_to(op, name) || op.call.as_ref().is_some_and(|call| call_uses(&call.program, name))) +} + +pub(super) struct SumCycle { + pub(super) name: String, + term: usize, + previous: f32, + increments: Vec, +} + +impl SumCycle { + pub(super) fn record(&mut self, state: &EvaluationState, last: &Value) -> bool { + let (Value::Float(last), Some(term)) = (last, state.scalar_register(self.term)) else { return false }; + // Limit the speculative history. Longer cycles can continue through the ordinary evaluator. + if self.increments.len() >= 64 || !term.is_finite() || !last.is_finite() { + return false; + } + let term = flush_subnormal(term); + if flush_subnormal(flush_subnormal(self.previous) + term).to_bits() != last.to_bits() { + return false; + } + self.increments.push(term); + self.previous = *last; + true + } + + pub(super) fn replay(&self, state: &mut EvaluationState, last: &mut Value, remaining: u32, budget: &mut usize) -> u32 { + let Value::Float(value) = last else { return 0 }; + let (Some(Value::Float(visible)), Some(Value::Float(written))) = (state.variables.get_mut(&self.name), state.assignments.get_mut(&self.name)) else { + return 0; + }; + let period = self.increments.len(); + if period == 0 || [*value, *visible, *written].iter().any(|v| v.to_bits() != self.previous.to_bits()) { + return 0; + } + let cycles = remaining as usize / period; + let mut completed = 0; + for _ in 0..cycles.min(*budget / period) { + let before = value.to_bits(); + for &increment in &self.increments { + *value = flush_subnormal(flush_subnormal(*value) + increment); + } + *budget -= period; + completed += 1; + if value.to_bits() == before { + completed = cycles; + break; + } + } + *visible = *value; + *written = *value; + (completed * period) as u32 + } +} diff --git a/crates/nodes/src/function/mod.rs b/crates/nodes/src/function/mod.rs index 6d163b82..30cbec65 100644 --- a/crates/nodes/src/function/mod.rs +++ b/crates/nodes/src/function/mod.rs @@ -9,24 +9,39 @@ const MAX_CALL_DEPTH: usize = 16; const DEFAULT_LOOP_LIMIT: i32 = 32; mod arithmetic; +mod assigned_product; +mod binary_exponential; +mod branch_assignments; +mod branch_inputs; mod catalog; mod compile; mod evaluation_context; mod evaluation_state; mod evaluation_step; +mod fixed_point; mod function_call; mod function_definition; mod function_scope; mod inferred_type; mod instruction; +mod loop_sum; mod node_interface; mod node_types; mod operation; mod output; +mod pattern_channel_operations; +mod pattern_expression; +mod pixel_condition; mod processor; +mod product_sum; mod program; +mod reciprocal; mod resolve_instances; +mod returned_product; +mod sequence_prefix; +mod square_root; mod system_variable; +mod trigonometry; mod unconnected_input; #[cfg(test)] #[path = "unconnected.test.rs"] @@ -35,19 +50,27 @@ pub mod value_type; mod vector; mod warnings; +pub(crate) use arithmetic::flush_subnormal; +pub(crate) use binary_exponential::{exp2 as pixel_exp2, signed_pixel_power}; pub use catalog::{FUNCTIONS, default_value, definition}; -pub use compile::compile; +pub use compile::{compile, compile_with_literal_inputs}; pub use evaluation_context::EvaluationContext; pub use evaluation_state::EvaluationState; +pub(crate) use fixed_point::truncate_float; pub use function_definition::FunctionDefinition; pub use function_scope::FunctionScope; pub use node_interface::{graph_ports, input_identifiers, node_label}; pub use node_types::node_types; pub use output::{can_be_output, output_node}; +pub(crate) use pattern_expression::PatternExpression; pub(crate) use processor::pixel_processor; +pub use processor::pixel_processor_with_dependencies; pub use program::Program; +pub(crate) use reciprocal::divide as pixel_divide; pub use resolve_instances::resolve_instances; +pub(crate) use square_root::evaluate as pixel_sqrt; pub use system_variable::SystemVariable; +pub(crate) use trigonometry::{pixel_sin_cos, uniform_sin_cos_turns}; pub use warnings::warnings; #[cfg(test)] diff --git a/crates/nodes/src/function/operation.rs b/crates/nodes/src/function/operation.rs index f4f14ad8..c1661042 100644 --- a/crates/nodes/src/function/operation.rs +++ b/crates/nodes/src/function/operation.rs @@ -1,17 +1,19 @@ use super::{ EvaluationContext, + function_call::CallBindings, instruction::Instruction, value_type::{self, boolean, dimensions, floats, integers}, }; use materialcraft_core::Value; use std::collections::BTreeMap; -pub(crate) fn evaluate( +pub(super) fn evaluate( instruction: &Instruction, arguments: &[Value], variables: &mut BTreeMap, - random: &mut u32, + random: &mut crate::random::FunctionRandom, context: &EvaluationContext<'_>, + bindings: Option<(&CallBindings<'_>, &BTreeMap)>, ) -> Result { let op = instruction.definition.id; let first = || arguments.first().ok_or("missing first operand"); @@ -35,11 +37,23 @@ pub(crate) fn evaluate( let missing = || format!("undefined variable `{name}` in this context"); let value = match context.variable(name, variables)? { Some(value) => value, - // User counters start at typed zero; unavailable system variables still error - None if !name.starts_with('$') => materialcraft_core::ValueType::from_code(instruction.type_code) - .filter(|kind| *kind != materialcraft_core::ValueType::String) - .map(materialcraft_core::ValueType::default_value) - .ok_or_else(missing)?, + // A pattern's traversal seed selects its stream. The integer getter has no binding for it. + None if context.scope.is_pattern() && name == "$randomseed" && op == "get_integer1" => Value::Int(0), + // Unbound integer names in node properties read as zero, including reserved spellings. + // Known system variables still enforce their own scope and type. + None if matches!(context.scope, super::FunctionScope::Node | super::FunctionScope::RandomSeed) + && op == "get_integer1" + && super::SystemVariable::named(name).is_none() => + { + Value::Int(0) + } + // Unset numeric variables start at typed zero in a value processor. + None if !name.starts_with('$') || context.scope == super::FunctionScope::ValueProcessor => { + materialcraft_core::ValueType::from_code(instruction.type_code) + .filter(|kind| *kind != materialcraft_core::ValueType::String) + .map(materialcraft_core::ValueType::default_value) + .ok_or_else(missing)? + } None => return Err(missing()), }; @@ -60,6 +74,30 @@ pub(crate) fn evaluate( return value_type::canonical(value); } + if context.scope.uses_seed_words() && !instruction.literal { + // Runtime scalar seed sums add the storage words. A float-to-integer cast retains the floored float's bits. + match (op, arguments) { + ("add", [Value::Int(left), Value::Int(right)]) => return Ok(Value::Int(left.wrapping_add(*right))), + ("add", [Value::Float(left), Value::Float(right)]) => { + let sum = f32::from_bits(left.to_bits().wrapping_add(right.to_bits())); + return Ok(Value::Float(super::arithmetic::flush_subnormal(sum))); + } + ("toint1", [Value::Float(value)]) => { + // Rounding a signaling NaN quiets it and preserves the seed payload. + let word = if value.is_nan() { value.to_bits() | 0x0040_0000 } else { value.floor().to_bits() }; + return Ok(Value::Int(word as i32)); + } + _ => {} + } + } + + // A folded scalar cast interprets the 32-bit word as unsigned. Vector casts use signed lanes. + if op == "tofloat" + && instruction.literal + && let Value::Int(value) = first()? + { + return Ok(Value::Float(*value as u32 as f32)); + } if op.starts_with("to") || op.contains("vector") || op.contains("swizzle") { return super::vector::evaluate(op, arguments, instruction.value.as_ref()); } @@ -78,7 +116,11 @@ pub(crate) fn evaluate( } "isdefined" => { let name = name()?; - Value::Bool(context.variable(name, variables)?.is_some()) + let defined = match bindings { + Some((call, assignments)) if super::SystemVariable::named(name).is_none() => call.is_defined(name, assignments), + _ => context.variable(name, variables)?.is_some(), + }; + Value::Bool(defined) } "and" => Value::Bool(boolean(first()?)? && boolean(second()?)?), "or" => Value::Bool(boolean(first()?)? || boolean(second()?)?), @@ -98,6 +140,7 @@ pub(crate) fn evaluate( } let ordering = match (left, right) { + (Value::Int(a), Value::Int(b)) if instruction.literal => Some((*a as u32).cmp(&(*b as u32))), (Value::Int(a), Value::Int(b)) => a.partial_cmp(b), (Value::Float(a), Value::Float(b)) => a.partial_cmp(b), (Value::Bool(a), Value::Bool(b)) => a.partial_cmp(b), @@ -121,16 +164,40 @@ pub(crate) fn evaluate( let setting = instruction.value.as_ref().map(integers).transpose()?.unwrap_or([0, 0, 0, 0]); let index = usize::try_from(setting[0]).map_err(|_| "negative image index")?; - let pixel = match context.images.get(index).and_then(Option::as_ref) { - Some(image) if setting[1] == 0 => { - image.get((position[0] * image.width() as f32).floor() as i64, (position[1] * image.height() as f32).floor() as i64, context.tile) + let (bilinear, repeat) = match (context.scope, setting[1]) { + (super::FunctionScope::Node | super::FunctionScope::RandomSeed, mode) => (mode != 0, context.tile), + (_, 2) => (false, false), + (_, 3) => (true, false), + (_, mode) => (mode != 0, true), + }; + let image = context.images.get(index).and_then(Option::as_ref); + let uniform_sampler = context.scope == super::FunctionScope::ValueProcessor || context.scope.is_pattern(); + let pixel = match image { + Some(image) if uniform_sampler => { + let format = context.image_formats.get(index).copied().unwrap_or(materialcraft_core::OutputFormat::F32); + crate::texture_sampler::sample_uniform(image, [position[0], position[1]], format, bilinear, repeat) + } + Some(image) if context.scope == super::FunctionScope::PixelProcessor => { + let format = context.image_formats.get(index).copied().unwrap_or(materialcraft_core::OutputFormat::F32); + crate::texture_sampler::sample_pixel(image, [position[0], position[1]], format, bilinear, repeat) + } + Some(image) if !bilinear => { + image.get((position[0] * image.width() as f32).floor() as i64, (position[1] * image.height() as f32).floor() as i64, repeat) } Some(image) => image.sample_stored(position[0], position[1], context.tile), None => [0.0; 4], }; - if op == "samplelum" { Value::Float(pixel[0]) } else { Value::Float4(pixel) } + if op == "samplecol" { + Value::Float4(pixel) + } else if (uniform_sampler || context.scope == super::FunctionScope::PixelProcessor) + && image.is_some_and(|texture| texture.kind() == craft_texture::Kind::Color) + { + Value::Float(((pixel[1] + pixel[2]) + pixel[0]) * (1.0 / 3.0)) + } else { + Value::Float(pixel[0]) + } } - _ => return super::arithmetic::evaluate(op, arguments, random, context.scope), + _ => return super::arithmetic::evaluate(instruction, arguments, random, context.scope), }) } diff --git a/crates/nodes/src/function/pattern_channel_operations.rs b/crates/nodes/src/function/pattern_channel_operations.rs new file mode 100644 index 00000000..e65c2352 --- /dev/null +++ b/crates/nodes/src/function/pattern_channel_operations.rs @@ -0,0 +1,76 @@ +use super::{catalog, instruction::Instruction, returned_product::float_width, vector::PatternComponent}; +use materialcraft_core::Value; + +/// A pattern swizzle evaluates a component-wise expression for just the requested channel. +/// Use ordinary scalar instructions so that shared operands, branches and random draws keep +/// the same evaluation order as a scalar expression authored directly. +pub(super) fn project( + op: &Instruction, + original: &[Instruction], + sources: &[[Option; 4]], + generated: &mut Vec, +) -> Option<[Option; 4]> { + let width = float_width(op.type_code); + if width < 2 { + return None; + } + let kind = |i: usize| original.get(i).map(|input| input.type_code); + let valid = match (op.definition.id, op.inputs.as_slice()) { + ("ifelse", &[c, a, b]) => kind(c) == Some(4) && kind(a) == Some(op.type_code) && kind(b) == Some(op.type_code), + ("add" | "mul", &[a, b]) => kind(a) == Some(op.type_code) && kind(b) == Some(op.type_code), + ("mulscalar", &[a, b]) => kind(a) == Some(op.type_code) && kind(b) == Some(256), + ("lerp", &[a, b, x]) => kind(a) == Some(op.type_code) && kind(b) == Some(op.type_code) && kind(x) == Some(256), + _ => false, + }; + if !valid { + return None; + } + + let mut channels = [None; 4]; + for (lane, channel) in channels.iter_mut().take(width).enumerate() { + let mut inputs = Vec::with_capacity(op.inputs.len()); + for &index in &op.inputs { + let source = original.get(index)?; + let input = if source.type_code != op.type_code { + index + } else { + match sources.get(index)?[lane] { + Some(PatternComponent::Register(register)) => register, + Some(PatternComponent::Zero) => { + let register = original.len() + generated.len(); + generated.push(Instruction::new(source.id, catalog::definition("const_float1")?, vec![], Some(Value::Float(0.0)), 256)); + register + } + None => { + let register = original.len() + generated.len(); + generated.push(Instruction::new(source.id, catalog::definition("swizzle1")?, vec![index], Some(Value::Int(lane as i32)), 256)); + register + } + } + }; + inputs.push(input); + } + *channel = Some(PatternComponent::Register(original.len() + generated.len())); + let mut instruction = Instruction::new(op.id, op.definition, inputs, None, 256); + instruction.literal = op.literal; + generated.push(instruction); + } + Some(channels) +} + +/// Pack the scalar results with the ordinary vector instructions, preserving shared registers. +pub(super) fn pack(op: &Instruction, original_len: usize, channels: &[Option; 4], generated: &mut Vec) -> Option { + let (first, rest) = channels.get(..float_width(op.type_code))?.split_first()?; + let Some(PatternComponent::Register(mut packed)) = *first else { return None }; + for (channel, (kind, width)) in rest.iter().zip([("vector2", 512), ("vector3", 1024), ("vector4", 2048)]) { + let Some(PatternComponent::Register(next)) = *channel else { return None }; + let instruction = Instruction::new(op.id, catalog::definition(kind)?, vec![packed, next], None, width); + packed = original_len + generated.len(); + generated.push(instruction); + } + Some(packed) +} + +#[cfg(test)] +#[path = "pattern_channels.test.rs"] +mod tests; diff --git a/crates/nodes/src/function/pattern_channels.test.rs b/crates/nodes/src/function/pattern_channels.test.rs new file mode 100644 index 00000000..a81c2d16 --- /dev/null +++ b/crates/nodes/src/function/pattern_channels.test.rs @@ -0,0 +1,218 @@ +use crate::function::{EvaluationContext, EvaluationState, FunctionScope, compile}; +use materialcraft_core::{FunctionGraph, Value}; +use std::collections::BTreeMap; + +fn random_color(graph: &mut FunctionGraph, one: u32) -> u32 { + let channels = [(); 4].map(|()| graph.add("rand", &[one], None)); + let lower = graph.add("vector2", &channels[..2], None); + let upper = graph.add("vector2", &channels[2..], None); + graph.add("vector4", &[lower, upper], None) +} + +#[test] +fn selecting_a_computed_pattern_channel_preserves_the_next_random_draw() { + for operation in ["ifelse", "mul", "lerp"] { + for lane in [0, 3] { + let mut graph = FunctionGraph::default(); + let one = graph.add_constant(Value::Float(1.0)); + let zero = graph.add_constant(Value::Float(0.0)); + let left = random_color(&mut graph, one); + let right = random_color(&mut graph, one); + let condition = graph.add("get_bool", &[], Some(Value::Text("choice".into()))); + let selected = match operation { + "ifelse" => graph.add(operation, &[condition, left, right], None), + "lerp" => { + let factor = graph.add_constant(Value::Float(0.375)); + graph.add(operation, &[left, right, factor], None) + } + _ => graph.add(operation, &[left, right], None), + }; + let channel = graph.add("swizzle1", &[selected], Some(Value::Int(lane))); + let observed = graph.add("mul", &[channel, zero], None); + let next = graph.add("rand", &[one], None); + graph.output = Some(graph.add("add", &[observed, next], None)); + + for choice in [true, false] { + let variables = BTreeMap::from([("choice".into(), Value::Bool(choice))]); + let context = EvaluationContext { + scope: FunctionScope::FxMap, + position: [0.5; 2], + size: [16.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + for (seed, after_one, after_two) in [(0, 0x3f08_683c, 0x3f41_3194), (17, 0x3f4e_0964, 0x3ec2_8a10)] { + let graph = compile(&graph, seed).unwrap(); + let expected = f32::from_bits(if operation == "ifelse" { after_one } else { after_two }); + assert_eq!(graph.evaluate(&context, &mut EvaluationState::default()).unwrap(), Value::Float(expected), "{operation} channel {lane}"); + } + } + } + } +} + +#[test] +fn assigning_a_computed_pattern_vector_draws_the_operands_of_each_channel_together() { + let variables = BTreeMap::new(); + let context = EvaluationContext { + scope: FunctionScope::FxMap, + position: [0.5; 2], + size: [16.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + // Read each channel back from the assigned vector at three measured stamp seeds. + for (operation, expected) in [ + ("product", [[0x3c41a72f, 0x3e1491a6], [0x3e74d565, 0x3d31859f], [0x3ed198e7, 0x3e1fd4d9]]), + ("sum", [[0x3e7ec4c0, 0x3f432dc0], [0x3f918972, 0x3f66fe54], [0x3fb19ce2, 0x3f4a5a34]]), + ("lerp", [[0x3e0edcac, 0x3ec13990], [0x3efdf41e, 0x3f0d1cf2], [0x3f42c8d5, 0x3ecbb690]]), + ("scalar", [[0x3c41a72f, 0x3cbfad3c], [0x3e74d565, 0x3f3b1f1e], [0x3ed198e7, 0x3e30d4b5]]), + ("multiply_shared", [[0x3c41a72f, 0x3d8a8af7], [0x3e74d565, 0x3e72cfb6], [0x3ed198e7, 0x3ec7ebed]]), + ] { + let mut graph = FunctionGraph::default(); + let unit = graph.add_constant(Value::Float(1.0)); + let [a, b, c, d] = std::array::from_fn(|_| graph.add("rand", &[unit], None)); + let left = graph.add("vector2", &[a, b], None); + let right = graph.add("vector2", &[c, if operation == "multiply_shared" { a } else { d }], None); + let result = match operation { + "lerp" => { + let factor = graph.add_constant(Value::Float(0.375)); + graph.add("lerp", &[left, right, factor], None) + } + "scalar" => graph.add("mulscalar", &[left, c], None), + "sum" => graph.add("add", &[left, right], None), + _ => graph.add("mul", &[left, right], None), + }; + let name = Some(Value::Text("recorded".into())); + let assigned = graph.add("set", &[result], name.clone()); + let read = graph.add("get_float2", &[], name); + for lane in [0, 1] { + let selected = graph.add("swizzle1", &[read], Some(Value::Int(lane as i32))); + graph.output = Some(graph.add("sequence", &[assigned, selected], None)); + for (seed, words) in [11_038_009, 9_766_418, 22_858_730].into_iter().zip(expected) { + let result = compile(&graph, seed).unwrap().evaluate(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(result, Value::Float(f32::from_bits(words[lane])), "{operation}, {seed}, channel {lane}"); + } + } + } +} + +fn weighted_pattern_argument(width: usize, order: Option<[i32; 3]>, repeat_swizzle: bool) -> FunctionGraph { + let (getter, default) = match width { + 2 => ("get_float2", Value::Float2([0.0; 2])), + 3 => ("get_float3", Value::Float3([0.0; 3])), + 4 => ("get_float4", Value::Float4([0.0; 4])), + _ => panic!("unsupported fixture width"), + }; + let mut body = FunctionGraph::default(); + let point = body.add(getter, &[], Some(Value::Text("point".into()))); + body.output = Some(if let Some(order) = order { + let mut terms = Vec::new(); + for (lane, weight) in order.into_iter().zip([0.5, 0.25, 0.125]) { + let channel = if repeat_swizzle { + let repeated = body.add("swizzle3", &[point], Some(Value::Int3([lane; 3]))); + body.add("swizzle1", &[repeated], Some(Value::Int(0))) + } else { + body.add("swizzle1", &[point], Some(Value::Int(lane))) + }; + let weight = body.add_constant(Value::Float(weight)); + terms.push(body.add("mul", &[channel, weight], None)); + } + let pair = body.add("add", &terms[..2], None); + body.add("add", &[pair, terms[2]], None) + } else { + body.add_constant(Value::Float(0.375)) + }); + + let mut graph = FunctionGraph::default(); + let unit = graph.add_constant(Value::Float(1.0)); + let draws: Vec<_> = (0..width).map(|_| graph.add("rand", &[unit], None)).collect(); + let next = graph.add("rand", &[unit], None); + let mut packed = graph.add("vector2", &draws[..2], None); + for (&draw, operation) in draws[2..].iter().zip(["vector3", "vector4"]) { + packed = graph.add(operation, &[packed, draw], None); + } + let sample = graph.add("instance", &[packed], None); + let node = graph.nodes.last_mut().unwrap(); + node.instance = Some(materialcraft_core::GraphInstance { + graph: "weighted_components".into(), + label: String::new(), + package: String::new(), + inputs: vec![materialcraft_core::GraphPort { identifier: "point".into(), type_code: crate::function::value_type::type_code(&default) }], + outputs: vec![], + defaults: BTreeMap::from([("point".into(), default)]), + }); + node.source = Some(Ok(std::sync::Arc::new(body))); + let weight = graph.add_constant(Value::Float(0.0625)); + let tail = graph.add("mul", &[next, weight], None); + graph.output = Some(graph.add("add", &[sample, tail], None)); + graph +} + +fn measured_pattern_argument(graph: &FunctionGraph, seed: u32) -> Value { + let variables = BTreeMap::new(); + let context = EvaluationContext { + scope: FunctionScope::FxMap, + position: [0.5; 2], + size: [16.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + compile(graph, seed).unwrap().evaluate(&context, &mut EvaluationState::default()).unwrap() +} + +#[test] +fn a_returned_pattern_offset_finishes_each_component_in_read_order() { + let mut graph = FunctionGraph::default(); + let one = graph.add_constant(Value::Float(1.0)); + let [x, y, scale] = std::array::from_fn(|_| graph.add("rand", &[one], None)); + let direction = graph.add("vector2", &[x, y], None); + let scaled = graph.add("mulscalar", &[direction, scale], None); + let origin = graph.add_constant(Value::Float2([0.0, 0.0])); + graph.output = Some(graph.add("add", &[origin, scaled], None)); + + for (seed, words) in [(11_038_009, [0x3c41_a72f, 0x3cbf_ad3c]), (9_766_418, [0x3e74_d565, 0x3f3b_1f1e]), (22_858_730, [0x3ed1_98e7, 0x3e30_d4b5])] { + let expected = Value::Float2(words.map(f32::from_bits)); + assert_eq!(measured_pattern_argument(&graph, seed), expected, "returned offset at seed {seed}"); + } +} + +#[test] +fn arithmetic_in_a_called_pattern_function_reads_packed_components_on_first_use() { + let all = [0x3e37_3b24, 0x3eed_4df9, 0x3f29_859c]; + for (order, repeat_swizzle, words) in [ + ([0, 1, 2], false, all), + ([2, 1, 0], false, all), + ([1, 2, 0], false, all), + ([2, 0, 0], false, [0x3e0e_9eda, 0x3f03_aff7, 0x3f2a_7d9c]), + ([1, 1, 2], false, [0x3e2d_9372, 0x3ebd_2261, 0x3f4c_d582]), + ([2, 1, 0], true, all), + ] { + let graph = weighted_pattern_argument(3, Some(order), repeat_swizzle); + for (seed, word) in [11_038_009, 9_766_418, 22_858_730].into_iter().zip(words) { + assert_eq!(measured_pattern_argument(&graph, seed), Value::Float(f32::from_bits(word)), "{order:?}, {repeat_swizzle}, {seed}"); + } + } +} + +#[test] +fn padded_and_unused_components_of_pattern_arguments_consume_no_draw() { + for (width, order, word) in [ + (2, Some([1, 0, 1]), 0x3e1e_1926), + (2, Some([3, 1, 3]), 0x3d4d_a9dc), + (2, Some([3, 2, 3]), 0x3c3d_4b90), + (3, Some([3, 0, 2]), 0x3d9d_db54), + (3, None, 0x3ec5_ea5c), + (4, Some([3, 1, 0]), 0x3e37_3b24), + (4, Some([2, 3, 2]), 0x3e1e_1926), + ] { + let graph = weighted_pattern_argument(width, order, false); + assert_eq!(measured_pattern_argument(&graph, 11_038_009), Value::Float(f32::from_bits(word)), "{width}, {order:?}"); + } +} diff --git a/crates/nodes/src/function/pattern_expression.rs b/crates/nodes/src/function/pattern_expression.rs new file mode 100644 index 00000000..8a6679f9 --- /dev/null +++ b/crates/nodes/src/function/pattern_expression.rs @@ -0,0 +1,235 @@ +use super::{FunctionScope, Program, arithmetic, function_call::PatternTarget, instruction::Instruction, sequence_prefix::Visit, value_type, vector}; +use crate::random::FunctionRandom; +use materialcraft_core::Value; +use std::collections::{BTreeMap, BTreeSet}; + +struct Step<'a> { + instruction: &'a Instruction, + inputs: Vec, + output: usize, +} + +/// Arithmetic in a drawing property whose operands are fixed for this node and +/// depth or come from its random stream. Shared registers draw only once. +pub(crate) struct PatternExpression<'a> { + steps: Vec>, + slots: Vec, + result: usize, + assignment: Option, + ordinary_steps: usize, +} + +struct Builder<'a, 'v> { + variables: &'v BTreeMap, + assigned: &'v BTreeSet<&'v str>, + steps: Vec>, + slots: Vec, + fixed: Vec, + visits: usize, + ordinary_steps: usize, +} + +fn apply(instruction: &Instruction, inputs: &[Value], random: &mut FunctionRandom) -> Result { + if instruction.definition.id == "vector2" { + vector::evaluate(instruction.definition.id, inputs, instruction.value.as_ref()) + } else { + arithmetic::evaluate(instruction, inputs, random, FunctionScope::FxMap) + } +} + +impl<'a> PatternExpression<'a> { + /// The optional tint is the common scalar register and the selected branch. + /// Its Sequence publishes a vector before evaluating that scalar. + pub(crate) fn bind(program: &'a Program, variables: &BTreeMap, assigned: &BTreeSet<&str>, tint: Option<(usize, bool)>) -> Option { + // Large and control-dependent expressions stay with the bounded stack evaluator. + if program.instructions.len() > 96 { + return None; + } + let mut builder = Builder { variables, assigned, steps: Vec::new(), slots: Vec::new(), fixed: Vec::new(), visits: 0, ordinary_steps: 0 }; + let mut registers = vec![None; program.instructions.len()]; + let arguments = BTreeMap::new(); + let (result, assignment) = if let Some((base, scaled)) = tint { + let &[prefix, branch] = program.instructions.get(program.output)?.inputs.as_slice() else { return None }; + let set = program.instructions.get(prefix)?; + let &[written] = set.inputs.as_slice() else { return None }; + if !matches!(&set.value, Some(Value::Text(name)) if !name.is_empty() && !name.starts_with('$')) + || !matches!(program.sequence_prefixes.get(prefix), None | Some(Visit::Value)) + { + return None; + } + let offset = builder.bind(program, written, &mut registers, &arguments, 0)?; + let shared = program.pattern_branches.get(&branch).map_or(&[][..], |plan| plan.skipped(scaled)); + // The VM visits shared inputs of the unselected branch before a false + // result and after a true result. They can advance the random stream. + if !scaled { + for &input in shared { + builder.bind(program, input, &mut registers, &arguments, 0)?; + } + } + let value = builder.bind(program, base, &mut registers, &arguments, 0)?; + if scaled { + for &input in shared { + builder.bind(program, input, &mut registers, &arguments, 0)?; + } + } + if !matches!(builder.slots.get(offset), Some(Value::Float2(_))) || !matches!(builder.slots.get(value), Some(Value::Float(_))) { + return None; + } + (value, Some(offset)) + } else { + (builder.bind(program, program.output, &mut registers, &arguments, 0)?, None) + }; + (value_type::type_code(builder.slots.get(result)?) == program.output_type()).then_some(Self { + steps: builder.steps, + slots: builder.slots, + result, + assignment, + ordinary_steps: builder.ordinary_steps, + }) + } + + /// Each ordinary register visit enters the VM. A new operation also + /// applies and stores its result. The bound program runs just its steps. + pub(crate) fn work(&self) -> (usize, usize) { + (self.steps.len() + 1, self.ordinary_steps) + } + + pub(crate) fn evaluate(&mut self, random: &mut FunctionRandom) -> Result<(Value, Option), String> { + let missing = "invalid bound pattern register"; + let mut arguments = [Value::Float(0.0), Value::Float(0.0), Value::Float(0.0)]; + for step in &self.steps { + let inputs = arguments.get_mut(..step.inputs.len()).ok_or(missing)?; + for (argument, &slot) in inputs.iter_mut().zip(&step.inputs) { + *argument = self.slots.get(slot).ok_or(missing)?.clone(); + } + let value = apply(step.instruction, inputs, random)?; + *self.slots.get_mut(step.output).ok_or(missing)? = value; + } + let assignment = self.assignment.map(|slot| self.slots.get(slot).cloned().ok_or(missing)).transpose()?; + Ok((self.slots.get(self.result).ok_or(missing)?.clone(), assignment)) + } +} + +impl<'a> Builder<'a, '_> { + fn fixed(&mut self, value: &Value) -> Option { + match value { + Value::Float(v) => self.push(Value::Float(*v), true), + Value::Float2(v) => self.push(Value::Float2(*v), true), + _ => None, + } + } + + fn push(&mut self, value: Value, fixed: bool) -> Option { + if self.slots.len() >= 256 || !matches!(value, Value::Float(_) | Value::Float2(_)) { + return None; + } + let slot = self.slots.len(); + self.slots.push(value); + self.fixed.push(fixed); + Some(slot) + } + + fn bind( + &mut self, + program: &'a Program, + index: usize, + registers: &mut [Option], + arguments: &BTreeMap<&'a str, usize>, + depth: usize, + ) -> Option { + if self.visits >= 512 || depth > 64 { + return None; + } + self.visits += 1; + self.ordinary_steps += 1; + if let Some(slot) = *registers.get(index)? { + return Some(slot); + } + let op = program.instructions.get(index)?; + self.ordinary_steps += 1; // Store the result of a newly entered register. + let slot = if let Some(component) = program.pattern_components.get(&index) { + match component { + vector::PatternComponent::Register(input) => self.bind(program, *input, registers, arguments, depth + 1)?, + vector::PatternComponent::Zero => self.push(Value::Float(0.0), true)?, + } + } else if let Some(call) = &op.call { + if call.exports || call.program.instructions.len() > 64 || call.defaults.len() > 64 { + return None; + } + self.ordinary_steps += 1; + // Nested calls inherit outer formals, then shadow them with their own defaults and wires. + let mut bindings = arguments.clone(); + for (name, value) in &call.defaults { + bindings.insert(name, self.fixed(value)?); + } + if let Some(plan) = &call.pattern_arguments { + let PatternTarget::Arguments(positions) = &plan.target else { return None }; + if positions.len() != plan.registers.len() { + return None; + } + for (&position, &input) in positions.iter().zip(&plan.registers) { + let value = self.bind(program, input, registers, arguments, depth + 1)?; + bindings.insert(call.inputs.get(position)?, value); + } + } else { + if call.inputs.len() != op.inputs.len() { + return None; + } + for (name, &input) in call.inputs.iter().zip(&op.inputs) { + let value = self.bind(program, input, registers, arguments, depth + 1)?; + bindings.insert(name, value); + } + } + let mut child = vec![None; call.program.instructions.len()]; + self.bind(&call.program, call.program.output, &mut child, &bindings, depth + 1)? + } else { + self.ordinary_steps += 1; + match op.definition.id { + "const_float1" | "const_float2" => self.fixed(op.value.as_ref()?)?, + "get_float1" | "get_float2" => { + let Value::Text(name) = op.value.as_ref()? else { return None }; + if name.starts_with('$') { + if !matches!(name.as_str(), "$depth" | "$depthpow2") { + return None; + } + self.fixed(self.variables.get(name)?)? + } else if let Some(&argument) = arguments.get(name.as_str()) { + argument + } else { + if self.assigned.contains(name.as_str()) { + return None; + } + self.fixed(self.variables.get(name)?)? + } + } + "add" | "sub" | "mul" | "mulscalar" | "div" | "mod" | "dot" | "rand" | "neg" | "sqrt" | "sin" | "cos" | "vector2" | "cartesian" | "min" + | "max" | "lerp" => { + if op.inputs.len() > 3 { + return None; + } + let mut inputs = Vec::with_capacity(op.inputs.len()); + let mut values = Vec::with_capacity(op.inputs.len()); + let mut fixed = op.definition.id != "rand" || op.inputs.len() == 2; + for &child in &op.inputs { + let slot = self.bind(program, child, registers, arguments, depth + 1)?; + inputs.push(slot); + fixed &= *self.fixed.get(slot)?; + values.push(self.slots.get(slot)?.clone()); + } + // A private stream checks the shape of a varying result without consuming a draw. + let output = self.push(apply(op, &values, &mut FunctionRandom::default()).ok()?, fixed)?; + if !fixed { + self.steps.push(Step { instruction: op, inputs, output }); + } + output + } + _ => return None, + } + }; + if value_type::type_code(self.slots.get(slot)?) != op.type_code { + return None; + } + *registers.get_mut(index)? = Some(slot); + Some(slot) + } +} diff --git a/crates/nodes/src/function/pixel_condition.rs b/crates/nodes/src/function/pixel_condition.rs new file mode 100644 index 00000000..9f9d39e2 --- /dev/null +++ b/crates/nodes/src/function/pixel_condition.rs @@ -0,0 +1,59 @@ +use super::{EvaluationContext, Program, SystemVariable, operation}; +use crate::random::FunctionRandom; +use materialcraft_core::Value; +use std::collections::BTreeMap; + +/// Count reads for arithmetic contraction without changing the evaluation of the condition. +pub(super) fn live_readers(program: &Program, context: &EvaluationContext<'_>) -> Option> { + let instructions = &program.instructions; + if !instructions.iter().any(|op| matches!(op.definition.id, "and" | "or")) + || instructions.iter().any(|op| op.call.is_some() || matches!(op.definition.id, "set" | "rand" | "while" | "sequence")) + { + return None; + } + + let mut known: Vec> = Vec::with_capacity(instructions.len()); + let mut fixed = vec![false; instructions.len()]; + let mut variables = BTreeMap::new(); + let mut random = FunctionRandom::uniform(0); + for (index, op) in instructions.iter().enumerate() { + let id = op.definition.id; + let decisive = match id { + "and" => Some(false), + "or" => Some(true), + _ => None, + }; + let constant = if let Some(value) = decisive + && op.inputs.iter().any(|&input| known.get(input) == Some(&Some(Value::Bool(value)))) + { + fixed[index] = true; + Some(Value::Bool(value)) + } else if matches!(id, "const_bool" | "const_int1") { + op.value.clone() + } else if id == "get_integer1" && matches!(&op.value, Some(Value::Text(name)) if name == "$tiling") { + SystemVariable::Tiling.resolve(context).ok().flatten() + } else if matches!(op.type_code, 4 | 16) && op.depends_only_on_operands() { + let inputs: Option> = op.inputs.iter().map(|&input| known.get(input)?.clone()).collect(); + inputs.and_then(|args| operation::evaluate(op, &args, &mut variables, &mut random, context, None).ok()) + } else { + None + }; + known.push(constant); + } + if !fixed.contains(&true) { + return None; + } + + // A product shared with a live comparison still rounds before an addition. + // A condition fixed by either operand cannot observe that product's precision. + let mut live = vec![false; instructions.len()]; + *live.get_mut(program.output)? = true; + for (index, op) in instructions.iter().enumerate().rev() { + if live[index] && !fixed[index] { + for &input in &op.inputs { + *live.get_mut(input)? = true; + } + } + } + Some(live) +} diff --git a/crates/nodes/src/function/processor.rs b/crates/nodes/src/function/processor.rs index ac7ce22f..566edbb6 100644 --- a/crates/nodes/src/function/processor.rs +++ b/crates/nodes/src/function/processor.rs @@ -1,20 +1,13 @@ -use super::{EvaluationContext, EvaluationState, compile}; +use super::{EvaluationContext, EvaluationState}; use crate::{CookContext, CookResult}; use craft_texture::{Image, Kind, Limits}; use materialcraft_core::Value; use rayon::prelude::*; -fn pixel(value: Value, gray: bool, format: materialcraft_core::OutputFormat) -> Result<[f32; 4], String> { +fn pixel(value: Value, gray: bool) -> Result<[f32; 4], String> { let values = super::value_type::floats(&value)?; - let integer = matches!(format, materialcraft_core::OutputFormat::U8 | materialcraft_core::OutputFormat::U16 | materialcraft_core::OutputFormat::Inherit); - // Integer texture storage converts NaN to black and saturates infinities - // Rejecting those values before storage breaks zero-softness masks - if !integer && values.iter().take(super::value_type::dimensions(&value)).any(|value| !value.is_finite()) { - return Err("pixel function produced a non-finite output".into()); - } - - Ok(if gray { + let color = if gray { let intensity = if super::value_type::dimensions(&value) == 4 { // RGBA results on a grayscale processor use equal RGB weights // Preserve the fused accumulation order at floating-point outputs @@ -31,34 +24,44 @@ fn pixel(value: Value, gray: bool, format: materialcraft_core::OutputFormat) -> 3 => [values[0], values[1], values[2], 1.0], _ => values, } - }) + }; + // Texture storage has a defined NaN bit pattern even when the host operation's payload varies. + Ok(color.map(|v| if v.is_nan() { f32::from_bits(0x7fff_ffff) } else { v })) } pub(crate) fn pixel_processor(context: &CookContext) -> CookResult { + pixel_processor_with_dependencies(context).map(|(image, _)| vec![image]) +} + +/// Cook the image and report published inputs read by the compiled pixel function. +pub fn pixel_processor_with_dependencies(context: &CookContext) -> Result<(Image, bool), String> { let graph = context.function("function").ok_or("missing pixel function")?; - let program = compile(graph, context.seed)?; let gray = !context.b("color_mode"); let kind = if gray { Kind::Gray } else { Kind::Color }; let (width, height) = craft_texture::clamp_size(context.w, context.h); + let frame = EvaluationContext { + image_formats: context.input_formats, + scope: super::FunctionScope::PixelProcessor, + position: [0.0; 2], + size: [width as f32, height as f32], + images: context.inputs, + tile: context.tile, + variables: context.vars.graph_values(), + }; + let program = super::compile::compile_program(graph, context.seed, context.vars.literal_inputs(), Some(&frame))?; let channels = kind.channels(); let mut data = vec![0.0; width as usize * height as usize * channels]; data.par_chunks_mut(width as usize * channels).enumerate().try_for_each_init(EvaluationState::default, |state, (y, row)| -> Result<(), String> { for (x, target) in row.chunks_exact_mut(channels).enumerate() { - let evaluation = EvaluationContext { - scope: super::FunctionScope::PixelProcessor, - position: [(x as f32 + 0.5) / width as f32, (y as f32 + 0.5) / height as f32], - size: [width as f32, height as f32], - images: context.inputs, - tile: context.tile, - variables: context.vars, - }; + let evaluation = EvaluationContext { position: [(x as f32 + 0.5) / width as f32, (y as f32 + 0.5) / height as f32], ..frame }; - let result = pixel(program.evaluate_pixel(&evaluation, state)?, gray, context.format)?; + let result = pixel(program.evaluate_pixel(&evaluation, state)?, gray)?; target.copy_from_slice(result.get(..channels).ok_or("invalid output channels")?); } Ok(()) })?; - Ok(vec![Image::from_data(width, height, kind, data, &Limits::default()).map_err(|e| e.to_string())?]) + let image = Image::from_data(width, height, kind, data, &Limits::default()).map_err(|e| e.to_string())?; + Ok((image, program.reads_graph_parameter(frame.variables))) } diff --git a/crates/nodes/src/function/product_sum.rs b/crates/nodes/src/function/product_sum.rs new file mode 100644 index 00000000..0491424f --- /dev/null +++ b/crates/nodes/src/function/product_sum.rs @@ -0,0 +1,384 @@ +use super::{EvaluationState, arithmetic::flush_subnormal, instruction::Instruction, reciprocal::Factor, returned_product::Source, value_type}; +use materialcraft_core::Value; +use std::collections::BTreeMap; + +#[derive(Clone)] +enum Addend { + Argument(usize), + Literal(Value), +} + +enum Retained { + Argument { source: Source, addend: Addend, subtract: bool }, + PassedArgument, + Assigned(super::assigned_product::Binding), + Lanes(super::returned_product::Sum), +} + +pub(super) struct ProductSum { + // Visit operands in their original order, including reads with side effects. + pub(super) inputs: Vec, + product_on_right: bool, + negated: bool, + operation: &'static str, + literal_divisor: bool, + rounded_components: u8, + retained: Option>, +} + +impl ProductSum { + /// Evaluate the original call and vector arguments before reading the factors they used. + pub(super) fn returned(inputs: &[usize], terms: super::returned_product::Sum) -> Self { + Self { + inputs: inputs.to_vec(), + product_on_right: false, + negated: false, + operation: "mul", + literal_divisor: false, + rounded_components: 0, + retained: Some(Box::new(Retained::Lanes(terms))), + } + } + + pub(super) fn assigned(inputs: &[usize], on_right: bool, source: super::assigned_product::Binding) -> Self { + Self { + inputs: inputs.to_vec(), + product_on_right: on_right, + negated: false, + operation: "mulscalar", + literal_divisor: false, + rounded_components: source.rounded_components, + retained: Some(Box::new(Retained::Assigned(source))), + } + } + + pub(super) fn evaluate(&self, arguments: &[Value], subtract: bool, state: &EvaluationState) -> Result { + if let Some(Retained::Lanes(terms)) = self.retained.as_deref() { + return super::returned_product::evaluate_sum(terms, arguments, subtract, state); + } + let passed; + let (a, b, c, blend, subtract) = if let Some(Retained::Argument { source, addend, subtract }) = self.retained.as_deref() { + passed = source.factors(state)?.map(Value::Float); + let c = match addend { + Addend::Argument(i) => arguments.get(*i).ok_or("missing product addend")?, + Addend::Literal(value) => value, + }; + (&passed[0], &passed[1], c, None, *subtract) + } else if let Some(Retained::Assigned(source)) = self.retained.as_deref() { + let [left, right] = arguments else { return Err("missing product sum operands".into()) }; + let (product, addend) = if self.product_on_right { (right, left) } else { (left, right) }; + // An untaken assignment leaves the getter's ordinary value in effect. + passed = source.read(state).unwrap_or_else(|| [product.clone(), Value::Float(1.0)]); + (&passed[0], &passed[1], addend, None, subtract) + } else if matches!(self.retained.as_deref(), Some(Retained::PassedArgument)) { + let [left, right] = arguments else { return Err("missing scalar sum operands".into()) }; + passed = state.argument_factors.ok_or("missing scalar argument factors")?.map(Value::Float); + (&passed[0], &passed[1], if self.product_on_right { left } else { right }, None, subtract) + } else { + let [first, second, third, rest @ ..] = arguments else { return Err("missing product-sum operands".into()) }; + let (a, b, c) = if self.product_on_right { (second, third, first) } else { (first, second, third) }; + (a, b, c, rest.first(), subtract) + }; + let width = value_type::dimensions(a); + if width != value_type::dimensions(c) || (width != value_type::dimensions(b) && !(self.operation == "mulscalar" && value_type::dimensions(b) == 1)) { + return Err("float operands must have the same dimensions".into()); + } + if blend.is_some_and(|v| value_type::dimensions(v) != width && value_type::dimensions(v) != 1) { + return Err("interpolation factor must be a scalar or match its operands".into()); + } + let blend = blend.map(value_type::floats).transpose()?; + let a = value_type::floats(a)?.map(flush_subnormal); + let b = value_type::floats(b)?.map(flush_subnormal); + let c = value_type::floats(c)?.map(flush_subnormal); + let negate_product = self.negated ^ (subtract && self.product_on_right); + let negate_addend = (subtract && !self.product_on_right) || blend.is_some(); + let result: [f32; 4] = std::array::from_fn(|i| { + let factor = if negate_product { -a[i] } else { a[i] }; + let addend = if negate_addend { -c[i] } else { c[i] }; + let sum = if self.rounded_components & (1 << i) != 0 { + let product = if self.operation == "div" { super::reciprocal::divide_by(factor, b[i], self.literal_divisor) } else { factor * b[i] }; + flush_subnormal(product) + addend + } else if self.operation == "div" { + super::reciprocal::divide_add(factor, b[i], addend, self.literal_divisor) + } else { + factor.mul_add(b[i], addend) + }; + blend.map_or(sum, |t| flush_subnormal(sum).mul_add(t[i], c[i])) + }) + .map(flush_subnormal); + value_type::intermediate_float_value(result.get(..width).ok_or("invalid product-sum dimensions")?) + } +} + +#[derive(Clone, Copy)] +struct ProductOperand { + index: usize, + negated: bool, +} + +#[derive(Clone, Copy, Default)] +struct ProductUsage { + count: usize, + rounded: bool, + swizzles: usize, + selected_components: u8, + repeated: bool, +} + +pub(super) fn selected_components(op: &Instruction) -> Option { + let count = match op.definition.id { + "swizzle1" => 1, + "swizzle2" => 2, + "swizzle3" => 3, + "swizzle4" => 4, + _ => return None, + }; + let components = value_type::integers(op.value.as_ref()?).ok()?; + components.iter().take(count).try_fold(0, |mask, &i| (0..4).contains(&i).then(|| mask | 1 << i)) +} + +fn scalar_product(op: &Instruction) -> Option<(&'static str, [Factor; 2])> { + let &[a, b] = op.inputs.as_slice() else { return None }; + if op.literal || op.type_code != 256 { + return None; + } + match (op.definition.id, op.reciprocal_factor) { + ("div", Some(factor)) => Some(("mul", [Factor::Register(a), factor])), + (operation @ ("mul" | "div"), _) => Some((operation, [a, b].map(Factor::Register))), + _ => None, + } +} + +/// A scalar argument can contract with a callee's addition when that addition is its only use. +fn called_sum(op: &Instruction, instructions: &[Instruction], usage: &[ProductUsage]) -> Option { + let call = op.call.as_ref()?; + let body = &call.program; + let sum = body.instructions.get(body.output)?; + if sum.type_code != 256 || !matches!(sum.definition.id, "add" | "sub") { + return None; + } + let leaf = |index: usize| { + let node = body.instructions.get(index)?; + match (node.definition.id, node.value.as_ref()?) { + ("get_float1", Value::Text(name)) if !name.starts_with('$') => call.inputs.iter().position(|p| p == name).map(Addend::Argument), + ("const_float1", value @ Value::Float(_)) => Some(Addend::Literal(value.clone())), + _ => None, + } + }; + let &[left, right] = sum.inputs.as_slice() else { return None }; + if left == right { + return None; + } + let (left, right) = (leaf(left)?, leaf(right)?); + if matches!((&left, &right), (Addend::Argument(a), Addend::Argument(b)) if a == b) { + return None; + } + let mut terms = [(&left, &right, false), (&right, &left, true)].into_iter().filter_map(|(operand, addend, product_on_right)| { + let Addend::Argument(slot) = operand else { return None }; + let index = *op.inputs.get(*slot)?; + let product = instructions.get(index)?; + if usage.get(index)?.count != 1 { + return None; + } + let (operation, factors) = scalar_product(product)?; + let retained = Retained::Argument { source: Source::local(factors), addend: addend.clone(), subtract: sum.definition.id == "sub" }; + Some(ProductSum { + inputs: op.inputs.clone(), + product_on_right, + negated: false, + operation, + literal_divisor: product.literal_divisor, + rounded_components: 0, + retained: Some(Box::new(retained)), + }) + }); + let term = terms.next()?; + terms.next().is_none().then_some(term) +} + +fn pass_into_sums(call: &mut super::function_call::FunctionCall, inputs: &[usize], previous: &[Instruction], usage: &[ProductUsage]) { + let mut candidates = call.inputs.iter().zip(inputs).filter_map(|(name, &index)| { + let product = previous.get(index)?; + let (operation, factors) = scalar_product(product)?; + (usage.get(index)?.count == 1).then_some((name, product.literal_divisor, operation, factors)) + }); + let Some((name, literal_divisor, operation, factors)) = candidates.next() else { return }; + let body = &mut call.program.instructions; + if candidates.next().is_some() || call.exports || body.iter().any(|op| op.call.is_some() || matches!(op.definition.id, "ifelse" | "sequence" | "while")) { + return; + } + + let reads: Vec<_> = body.iter().map(|op| op.definition.id == "get_float1" && matches!(&op.value, Some(Value::Text(id)) if id == name)).collect(); + let mut sums = Vec::new(); + for (index, op) in body.iter().enumerate() { + let mut uses = op.inputs.iter().enumerate().filter(|(_, input)| reads.get(**input) == Some(&true)); + let Some((slot, _)) = uses.next() else { continue }; + // Any other reader observes the rounded argument and makes it common to these sums. + if uses.next().is_some() || op.type_code != 256 || !matches!(op.definition.id, "add" | "sub") || op.pixel_product_sum.is_some() { + return; + } + sums.push((index, slot == 1)); + } + if sums.is_empty() { + return; + } + call.argument_factors = Some(factors); + for (index, product_on_right) in sums { + if let Some(sum) = body.get_mut(index) { + sum.pixel_product_sum = Some(ProductSum { + inputs: sum.inputs.clone(), + product_on_right, + negated: false, + operation, + literal_divisor, + rounded_components: 0, + retained: Some(Box::new(Retained::PassedArgument)), + }); + } + } +} + +pub(super) fn identify(instructions: &mut [Instruction], live_readers: Option<&[bool]>) { + // A sign change can be applied to a factor inside the fused operation. Follow inputs in + // compilation order so even a long chain of negations takes a single bounded pass. + let mut operands: Vec> = Vec::with_capacity(instructions.len()); + for (index, op) in instructions.iter().enumerate() { + let product = if op.product_operation().is_some() && !op.literal && matches!(op.type_code, 256 | 512 | 1024 | 2048) { + Some(ProductOperand { index, negated: false }) + } else if op.definition.id == "neg" + && let [input] = op.inputs.as_slice() + { + operands.get(*input).copied().flatten().map(|p| ProductOperand { negated: !p.negated, ..p }) + } else { + None + }; + operands.push(product); + } + let operand = |index: usize| operands.get(index).copied().flatten(); + let mut usage = vec![ProductUsage::default(); instructions.len()]; + let has_loop = instructions.iter().any(|op| op.definition.id == "while"); + for (index, op) in instructions.iter().enumerate() { + if op.definition.id == "while" { + for &member in &op.control_registers { + if let Some(reader) = usage.get_mut(member) { + reader.repeated = true; + } + } + } + if op.definition.id == "neg" || live_readers.is_some_and(|readers| readers.get(index) == Some(&false)) { + continue; + } + let sum = match (op.definition.id, op.inputs.as_slice()) { + ("add" | "sub", [a, b]) => operand(*a).zip(operand(*b)).is_none_or(|(p, q)| p.index != q.index), + _ => false, + }; + for (slot, &input) in op.inputs.iter().enumerate() { + if let Some(p) = operand(input) { + usage[p.index].count += 1; + if let Some(components) = selected_components(op) { + usage[p.index].swizzles += 1; + usage[p.index].selected_components |= components; + } + // In lerp(a,b,t), b can contract into b-a. Both uses of a need its rounded value. + usage[p.index].rounded |= !(sum || (op.definition.id == "lerp" && slot == 1)); + } + } + } + + // If a sum consumes a single-use product, the shared product on its other side is a + // rounded addend. Its other readers must see the same value. + for op in instructions.iter().filter(|op| matches!(op.definition.id, "add" | "sub")) { + if let [left, right] = op.inputs.as_slice() + && let (Some(left), Some(right)) = (operand(*left), operand(*right)) + { + for (single, shared) in [(left.index, right.index), (right.index, left.index)] { + if usage[single].count == 1 && !usage[single].rounded && usage[shared].count > 1 { + usage[shared].rounded = true; + } + } + } + } + + let mut shared_pairs = BTreeMap::new(); + for index in 0..instructions.len() { + let Some(op) = instructions.get(index) else { continue }; + if !matches!(op.type_code, 256 | 512 | 1024 | 2048) { + continue; + } + if op.call.is_some() { + if !has_loop { + let (previous, current) = instructions.split_at_mut(index); + if let Some(op) = current.first_mut() { + op.pixel_product_sum = called_sum(op, previous, &usage); + if op.pixel_product_sum.is_none() + && let Some(call) = &mut op.call + { + pass_into_sums(call, &op.inputs, previous, &usage); + } + } + } + continue; + } + let (left, right, blend) = match (op.definition.id, op.inputs.as_slice()) { + ("add" | "sub", &[left, right]) => (left, right, None), + ("lerp", &[left, right, factor]) => (left, right, Some(factor)), + _ => continue, + }; + let mut sides = [(left, right, false), (right, left, true)]; + if op.type_code == 256 + && blend.is_none() + && let (Some(p), Some(q)) = (operand(left), operand(right)) + && p.index != q.index + && [p.index, q.index].iter().all(|&i| usage[i].count > 1 && instructions[i].product_operation() == Some("mul")) + { + // Sums sharing both products reuse the rounded addend chosen by the first sum. + let pair = (p.index.min(q.index), p.index.max(q.index)); + if *shared_pairs.entry(pair).or_insert(p.index) == q.index { + sides.swap(0, 1); + } + } + let product = sides + .into_iter() + .filter(|(_, _, on_right)| blend.is_none() || *on_right) + .filter_map(|(source, other, product_on_right)| { + let source = operand(source)?; + let product = instructions.get(source.index)?; + let used = usage[source.index]; + let &[a, b] = product.inputs.as_slice() else { return None }; + // A swizzle observes only its selected components. The other components may still contract with their sole sum. + let vector_mask = match product.type_code { + 512 => 0b0011, + 1024 => 0b0111, + 2048 => 0b1111, + _ => 0, + }; + let partial = used.swizzles > 0 && used.count == used.swizzles + 1 && vector_mask & !used.selected_components != 0 && blend.is_none(); + if (used.rounded && !partial) || product.type_code != op.type_code { + return None; + } + // Loop iterations can invalidate an operand independently of a shared product. + if has_loop && used.count > 1 && (!partial || used.repeated || usage.get(a)?.repeated || usage.get(b)?.repeated) { + return None; + } + let mut inputs = if product_on_right { vec![other, a, b] } else { vec![a, b, other] }; + inputs.extend(blend); + Some(( + used.count, + ProductSum { + inputs, + product_on_right, + negated: source.negated, + operation: product.product_operation()?, + literal_divisor: product.literal_divisor, + rounded_components: used.selected_components, + retained: None, + }, + )) + }) + .min_by_key(|(count, _)| *count) + .map(|(_, sum)| sum); + if let Some(op) = instructions.get_mut(index) { + op.pixel_product_sum = product; + } + } +} diff --git a/crates/nodes/src/function/program.rs b/crates/nodes/src/function/program.rs index 96003c4a..ee7a4775 100644 --- a/crates/nodes/src/function/program.rs +++ b/crates/nodes/src/function/program.rs @@ -1,4 +1,7 @@ -use super::{EvaluationContext, EvaluationState, evaluation_step::EvaluationStep, instruction::Instruction, operation, value_type}; +use super::{ + EvaluationContext, EvaluationState, evaluation_step::EvaluationStep, function_call::CallBindings, instruction::Instruction, operation, value_type, +}; +use crate::random::FunctionRandom; use materialcraft_core::Value; /// Validated graph with input ids resolved to instruction indices @@ -6,6 +9,11 @@ pub struct Program { pub(crate) instructions: Vec, pub(crate) output: usize, pub(crate) seed: u32, + pub(super) processor_branches: std::collections::BTreeMap, + pub(super) pattern_branches: std::collections::BTreeMap, + pub(super) pattern_components: std::collections::BTreeMap, + pub(super) sequence_prefixes: Vec, + pub(super) loop_sums: std::collections::BTreeMap, } const MAX_EVALUATION_STEPS: usize = 100_000; @@ -15,6 +23,70 @@ impl Program { self.instructions.get(self.output).map_or(0, |instruction| instruction.type_code) } + /// The variable read by a direct link. Disconnected editor nodes have no instructions. + pub fn input_identifier(&self) -> Option<&str> { + let [op] = self.instructions.as_slice() else { return None }; + match &op.value { + Some(Value::Text(name)) if op.definition.id.starts_with("get_") => Some(name), + _ => None, + } + } + + /// Whether the result depends only on literals and pure operations. + pub fn output_is_literal(&self) -> bool { + self.instructions.get(self.output).is_some_and(|instruction| instruction.literal) + } + + /// A grayscale Uniform folds its channel mean when its property has only fixed operands. + pub fn uses_fixed_uniform_color(&self, variables: &std::collections::BTreeMap) -> bool { + self.instructions.iter().all(|op| { + op.literal + || op.depends_only_on_operands() + || op.definition.id == "isdefined" + || match (&op.value, op.definition.id) { + (Some(Value::Text(name)), getter) if getter.starts_with("get_") && !name.starts_with('$') => !variables.contains_key(name), + (Some(Value::Text(name)), "get_float2") => matches!(name.as_str(), "$size" | "$sizelog2"), + (Some(Value::Text(name)), "get_integer1") => { + matches!(name.as_str(), "$tiling" | "$pixelratio") || super::SystemVariable::named(name).is_none() + } + (Some(Value::Text(name)), "get_integer2") => name == "$uvtile", + (Some(Value::Text(name)), "get_float3") => name == "$physicalsize", + _ => false, + } + }) + } + + /// Whether the property reads a bound graph parameter, even if its final value is constant. + pub fn reads_graph_parameter(&self, variables: &std::collections::BTreeMap) -> bool { + self.reads_bound_input(|name| variables.contains_key(name)) + } + + pub(crate) fn reads_bound_input(&self, bound: impl Fn(&str) -> bool) -> bool { + self.instructions.iter().any(|op| { + !op.literal && op.definition.id.starts_with("get_") && matches!(&op.value, Some(Value::Text(name)) if !name.starts_with('$') && bound(name)) + }) + } + + /// Unbound user inputs in a fixed pattern image selector contribute their typed zero. + pub(crate) fn uses_fixed_image_slot(&self, variables: &std::collections::BTreeMap) -> bool { + self.output_is_literal() + || self.instructions.iter().all(|op| { + op.literal + || op.depends_only_on_operands() + || (op.definition.id.starts_with("get_") + && matches!(&op.value, Some(Value::Text(name)) if !name.starts_with('$') && !variables.contains_key(name))) + }) + } + + /// Whether constants and the current image dimensions determine the entire computation. + pub fn depends_only_on_image_size(&self) -> bool { + self.instructions.iter().all(|op| { + op.definition.id.starts_with("const_") + || op.depends_only_on_operands() + || (op.definition.id == "get_float2" && matches!(&op.value, Some(Value::Text(name)) if matches!(name.as_str(), "$size" | "$sizelog2"))) + }) + } + pub fn node_type(&self, id: u32) -> Option { self.instructions.iter().find(|instruction| instruction.id == id).map(|instruction| instruction.type_code) } @@ -28,48 +100,112 @@ impl Program { } pub fn evaluate(&self, context: &EvaluationContext<'_>, state: &mut EvaluationState) -> Result { - let mut random = self.random_seed(context); - self.evaluate_with_random(context, state, &mut random) + state.variables.clone_from(context.variables); + let mut random = self.random_stream(context); + self.evaluate_finite(context, state, &mut random) } - /// Pattern parameters share a random stream within each traversal visit. - pub(crate) fn evaluate_with_random(&self, context: &EvaluationContext<'_>, state: &mut EvaluationState, random: &mut u32) -> Result { - state.variables.clone_from(context.variables); - state.random = *random; - let mut remaining = MAX_EVALUATION_STEPS; - let result = self.run(context, state, &mut remaining); - *random = state.random; - let value = result?; + /// Pattern expressions borrow inherited variables and export only their explicit assignments. + pub(crate) fn evaluate_with_random( + &self, + context: &EvaluationContext<'_>, + state: &mut EvaluationState, + random: &mut FunctionRandom, + ) -> Result { + state.variables.clear(); + self.evaluate_finite(context, state, random) + } + pub(crate) fn evaluate_pattern_seed<'a>( + &self, + context: &EvaluationContext<'_>, + state: &mut EvaluationState, + random: &mut FunctionRandom, + assigned: impl Iterator, + ) -> Result { + state.variables.clear(); + // An integer written by an earlier property occupies a float slot. Published inputs + // and values assigned within this seed expression use their ordinary integer words. + state.variables.extend(assigned.map(|(name, value)| (name.to_owned(), Value::Int((value as f32).to_bits() as i32)))); + self.evaluate_finite(context, state, random) + } + + /// A quadrant blends its tint components individually, including an undefined channel. + pub(crate) fn evaluate_pattern_tint( + &self, + context: &EvaluationContext<'_>, + state: &mut EvaluationState, + random: &mut FunctionRandom, + ) -> Result { + state.variables.clear(); + self.run_with_random(context, state, random) + } + + fn evaluate_finite(&self, context: &EvaluationContext<'_>, state: &mut EvaluationState, random: &mut FunctionRandom) -> Result { + let value = self.run_with_random(context, state, random)?; // Callers may clamp undefined intermediates; completed functions must be finite if value.as_vec4().is_some_and(|components| components.iter().any(|value| !value.is_finite())) { return Err("function produced a non-finite output".into()); } - Ok(value) } - fn random_seed(&self, context: &EvaluationContext<'_>) -> u32 { + /// A grayscale pattern can blend an infinite or undefined scalar into a finite background. + pub fn evaluate_pattern_opacity(&self, context: &EvaluationContext<'_>, state: &mut EvaluationState) -> Result { + state.variables.clone_from(context.variables); + let mut random = self.random_stream(context); + match self.run_with_random(context, state, &mut random)? { + Value::Float(opacity) => Ok(opacity), + _ => Err("pattern opacity requires a scalar".into()), + } + } + + /// Evaluate an integer texture's channel control at its normalized storage boundary. + pub fn evaluate_normalized_color(&self, context: &EvaluationContext<'_>, state: &mut EvaluationState) -> Result { + state.variables.clone_from(context.variables); + let mut random = self.random_stream(context); + let channels = match self.run_with_random(context, state, &mut random)? { + Value::Float(v) => [v, v, v, 1.0], + Value::Float3([r, g, b]) => [r, g, b, 1.0], + Value::Float4(rgba) | Value::Color(rgba) => rgba, + _ => return Err("channel control requires a gray level, RGB or RGBA".into()), + }; + Ok(Value::Float4(channels.map(|v| if v.is_nan() { 0.0 } else { v.clamp(0.0, 1.0) }))) + } + + fn run_with_random(&self, context: &EvaluationContext<'_>, state: &mut EvaluationState, random: &mut FunctionRandom) -> Result { + state.random = *random; + let mut remaining = MAX_EVALUATION_STEPS; + let result = self.run(context, state, &mut remaining, None); + *random = state.random; + result + } + + fn random_stream(&self, context: &EvaluationContext<'_>) -> FunctionRandom { let seed = context.variables.get("$randomseed").and_then(Value::as_i32).map_or(self.seed, |seed| seed as u32); - if context.scope == super::FunctionScope::PixelProcessor { - // Each pixel owns a deterministic stream, independent of worker scheduling - let x = (context.position[0] * context.size[0]).floor() as u32; - let y = (context.position[1] * context.size[1]).floor() as u32; - crate::random::hash(seed ^ crate::random::hash(x.wrapping_add(0x9e37_79b9)) ^ crate::random::hash(y.wrapping_add(0x85eb_ca6b))) - } else { - seed + match context.scope { + super::FunctionScope::PixelProcessor => FunctionRandom::pixel(seed, context.position), + super::FunctionScope::ValueProcessor => FunctionRandom::pixel(seed, [0.0; 2]), + super::FunctionScope::FxMap => FunctionRandom::image(seed), + super::FunctionScope::Node | super::FunctionScope::RandomSeed | super::FunctionScope::FxMapRandomSeed => FunctionRandom::uniform(seed), } } // Pixel assignments are local; only the general evaluator exports the complete environment pub(super) fn evaluate_pixel(&self, context: &EvaluationContext<'_>, state: &mut EvaluationState) -> Result { state.variables.clear(); - state.random = self.random_seed(context); + state.random = self.random_stream(context); let mut remaining = MAX_EVALUATION_STEPS; - self.run(context, state, &mut remaining) + self.run(context, state, &mut remaining, None) } - fn run(&self, context: &EvaluationContext<'_>, state: &mut EvaluationState, remaining_steps: &mut usize) -> Result { + fn run( + &self, + context: &EvaluationContext<'_>, + state: &mut EvaluationState, + remaining_steps: &mut usize, + bindings: Option<&CallBindings<'_>>, + ) -> Result { use EvaluationStep::*; state.steps.clear(); @@ -77,6 +213,8 @@ impl Program { state.assignments.clear(); state.registers.clear(); state.registers.resize(self.instructions.len(), None); + state.visited_prefixes.clear(); + state.visited_prefixes.resize(self.sequence_prefixes.len(), false); state.steps.push(Enter(self.output)); while let Some(step) = state.steps.pop() { @@ -90,12 +228,31 @@ impl Program { } state.steps.push(Store(index)); + if context.scope.is_pattern() + && let Some(source) = self.pattern_components.get(&index) + { + match source { + super::vector::PatternComponent::Register(source) => state.steps.push(Enter(*source)), + super::vector::PatternComponent::Zero => state.values.push(Value::Float(0.0)), + } + continue; + } match instruction.definition.id { + "set" if matches!(&instruction.value, Some(Value::Text(name)) if bindings.is_some_and(|scope| scope.call.defaults.contains_key(name))) => + { + // A formal is read-only. Even side effects in the unused operand are skipped. + let kind = materialcraft_core::ValueType::from_code(instruction.type_code).ok_or("unknown function assignment type")?; + state.values.push(kind.default_value()); + } "ifelse" => { - state.steps.push(Branch(index)); + state.steps.push(Branch { instruction: index, prefix: false }); state.steps.push(Enter(self.input(index, 0)?)); } + "sequence" if !self.sequence_prefixes.is_empty() => { + state.steps.push(Enter(self.input(index, 1)?)); + state.steps.push(Prefix(self.input(index, 0)?)); + } "sequence" => { state.steps.push(Sequence(index)); state.steps.push(Enter(self.input(index, 0)?)); @@ -106,34 +263,102 @@ impl Program { } _ => { state.steps.push(Apply { instruction: index, base: state.values.len() }); - state.steps.extend(instruction.inputs.iter().rev().map(|index| Enter(*index))); + let inputs = match &instruction.pixel_product_sum { + Some(product) if context.scope == super::FunctionScope::PixelProcessor => product.inputs.as_slice(), + _ if context.scope.is_pattern() => instruction + .call + .as_ref() + .and_then(|call| call.pattern_arguments.as_ref()) + .map_or(instruction.inputs.as_slice(), |arguments| arguments.registers.as_slice()), + _ => instruction.inputs.as_slice(), + }; + state.steps.extend(inputs.iter().rev().map(|&index| Enter(index))); } } } Apply { instruction: index, base } => { let instruction = self.instruction(index)?; let arguments = state.values.get(base..).ok_or("invalid function operands")?; - let result = if let Some(call) = &instruction.call { + let pattern = instruction.call.as_ref().and_then(|call| call.pattern_arguments.as_ref()).filter(|_| context.scope.is_pattern()); + let result = if context.scope == super::FunctionScope::PixelProcessor + && let Some(factor) = instruction.reciprocal_factor + && let Some(product) = super::reciprocal::multiply_original(arguments.first(), factor.read(state)) + { + Ok(product) + } else if context.scope == super::FunctionScope::PixelProcessor + && let Some(value) = instruction.pixel_interval.as_deref().and_then(|interval| interval.saturate(state)) + { + Ok(value) + } else if let Some(product) = &instruction.pixel_product_sum + && context.scope == super::FunctionScope::PixelProcessor + { + product.evaluate(arguments, instruction.definition.id == "sub", state) + } else if pattern.is_some_and(|plan| matches!(plan.target, super::function_call::PatternTarget::ReturnedChannels)) { + super::function_call::pack_scalars(arguments) + } else if let Some(call) = &instruction.call { + let factors = if let Some([a, b]) = call.argument_factors.filter(|_| context.scope == super::FunctionScope::PixelProcessor) { + Some([a.read(state).ok_or("missing scalar argument factor")?, b.read(state).ok_or("missing scalar argument factor")?]) + } else { + None + }; + let reciprocals = call.reciprocals.as_deref().filter(|_| context.scope == super::FunctionScope::PixelProcessor); + if let Some(plan) = reciprocals + && !plan.arguments.is_empty() + { + let mut values = state.calls.get_mut(&index).map(|child| std::mem::take(&mut child.reciprocal_arguments)).unwrap_or_default(); + values.clear(); + values.extend(plan.arguments.iter().map(|factor| factor.read(state))); + state.calls.entry(index).or_default().reciprocal_arguments = values; + } + if !call.assigned_products.is_empty() && context.scope == super::FunctionScope::PixelProcessor { + let mut values = state.calls.get_mut(&index).map(|child| std::mem::take(&mut child.assigned_arguments)).unwrap_or_default(); + values.clear(); + values.extend(call.assigned_products.iter().map(|binding| binding.read(state))); + state.calls.entry(index).or_default().assigned_arguments = values; + } let storage = state.calls.entry(index).or_default(); + storage.argument_factors = factors; storage.variables.clone_from(&state.variables); storage.variables.extend(call.defaults.clone()); - for (name, value) in call.inputs.iter().zip(arguments) { + let packed = pattern.map(|plan| plan.target.packed_argument(arguments)).transpose()?.flatten(); + let arguments = packed.as_ref().map_or(arguments, std::slice::from_ref); + for (i, value) in arguments.iter().enumerate() { + let slot = match pattern.map(|plan| &plan.target) { + Some(super::function_call::PatternTarget::Arguments(slots)) => *slots.get(i).ok_or("missing function argument slot")?, + _ => i, + }; + let name = call.inputs.get(slot).ok_or("missing function argument name")?; storage.variables.insert(name.clone(), value.clone()); } // A function call consumes its caller's stream instead of restarting it storage.random = state.random; - let result = call.program.run(context, storage, remaining_steps); + let child = CallBindings { call, caller_assignments: &state.assignments, parent: bindings }; + let result = call.program.run(context, storage, remaining_steps, Some(&child)); + if let Some(plan) = reciprocals { + storage.returned_reciprocals = plan.results.map(|factor| factor.and_then(|f| f.read(storage))); + } state.random = storage.random; if call.exports && result.is_ok() { - // Set publishes into the caller's scope; arguments and defaults stay local - state.variables.extend(storage.assignments.clone()); - state.assignments.extend(storage.assignments.clone()); + // A free assignment can pass through a caller with a formal of the same name. + for (name, value) in &storage.assignments { + if bindings.is_none_or(|scope| !scope.call.defaults.contains_key(name)) { + state.variables.insert(name.clone(), value.clone()); + } + state.assignments.insert(name.clone(), value.clone()); + } } result } else { - operation::evaluate(instruction, arguments, &mut state.variables, &mut state.random, context) + operation::evaluate( + instruction, + arguments, + &mut state.variables, + &mut state.random, + context, + bindings.map(|call| (call, &state.assignments)), + ) } .map_err(|error| format!("{} ({}): {error}", instruction.definition.label, instruction.id))?; @@ -151,37 +376,103 @@ impl Program { let register = state.registers.get_mut(index).ok_or("invalid function register")?; *register = Some(value.clone()); } - Branch(index) => { + Prefix(index) => { + use super::sequence_prefix::Visit; + if state.registers.get(index).is_some_and(Option::is_some) + || state.visited_prefixes.get_mut(index).is_some_and(|seen| std::mem::replace(seen, true)) + { + continue; + } + match self.sequence_prefixes.get(index).copied().unwrap_or(Visit::Value) { + Visit::Skip => {} + Visit::Value => { + state.steps.push(Discard); + state.steps.push(Enter(index)); + } + Visit::Inputs => state.steps.extend(self.instruction(index)?.inputs.iter().rev().copied().map(Prefix)), + Visit::Branch => { + state.steps.push(Branch { instruction: index, prefix: true }); + state.steps.push(Enter(self.input(index, 0)?)); + } + } + } + Branch { instruction: index, prefix } => { let condition = state.values.pop().ok_or("missing branch condition")?; - let slot = if value_type::boolean(&condition)? { 1 } else { 2 }; - - state.steps.push(Enter(self.input(index, slot)?)); + let take_true = value_type::boolean(&condition)?; + let selected = self.input(index, if take_true { 1 } else { 2 })?; + let branches = if context.scope.is_pattern() { &self.pattern_branches } else { &self.processor_branches }; + let (shared, after_selected) = if let Some(inputs) = branches.get(&index) { + (inputs.skipped(take_true), take_true) + } else if context.scope == super::FunctionScope::PixelProcessor { + (self.instruction(index)?.control_registers.as_slice(), false) + } else { + (&[][..], false) + }; + let selected = || if prefix { Prefix(selected) } else { Enter(selected) }; + if !after_selected { + state.steps.push(selected()); + } + for &index in shared.iter().rev() { + if prefix { + state.steps.push(Prefix(index)); + } else if state.registers.get(index).is_some_and(Option::is_none) { + state.steps.push(Discard); + state.steps.push(Enter(index)); + } + } + if after_selected { + state.steps.push(selected()); + } + } + Discard => { + state.values.pop().ok_or("missing discarded function value")?; } Sequence(index) => { state.values.pop().ok_or("missing sequence result")?; state.steps.push(Enter(self.input(index, 1)?)); } LoopStart(index) => { - let last = state.values.pop().ok_or("missing loop initialization")?; + let initializer = state.values.pop().ok_or("missing loop initialization")?; + // The initializer may assign a different type. A skipped body has its own typed zero. + let last = materialcraft_core::ValueType::from_code(self.instruction(index)?.type_code) + .map_or(initializer, materialcraft_core::ValueType::default_value); self.clear_loop_results(index, state)?; - state.steps.push(LoopCondition { instruction: index, iteration: 0, last }); + state.steps.push(LoopCondition { instruction: index, iteration: 0, last, checkpoint: None }); state.steps.push(Enter(self.input(index, 1)?)); } - LoopCondition { instruction: index, iteration, last } => { + LoopCondition { instruction: index, mut iteration, mut last, mut checkpoint } => { let exit = value_type::boolean(&state.values.pop().ok_or("missing loop condition")?)?; let maximum = self.instruction(index)?.value.as_ref().and_then(Value::as_i32).unwrap_or(super::DEFAULT_LOOP_LIMIT); + if !exit + && maximum > 0 + && let Some(previous) = checkpoint.as_ref() + { + let advance = previous.advance(state, &mut last, (maximum as u32).saturating_sub(iteration), remaining_steps); + iteration += advance; + if advance > 0 || !previous.tracks_sum() { + checkpoint = None; + } + } if exit || (maximum >= 0 && iteration >= maximum as u32) { state.values.push(last); } else { + // Check consecutive visits for fixed points. A sum can retain a short sequence + // of increments until the rest of the loop state repeats. + if maximum > 0 && (maximum as u32).saturating_sub(iteration) > 1 && iteration.is_power_of_two() { + checkpoint = super::evaluation_state::LoopCheckpoint::capture(state, self.loop_sums.get(&index)); + } self.clear_loop_results(index, state)?; - state.steps.push(LoopBody { instruction: index, iteration: iteration.saturating_add(1) }); + state.steps.push(LoopBody { instruction: index, iteration: iteration.saturating_add(1), checkpoint }); state.steps.push(Enter(self.input(index, 2)?)); } } - LoopBody { instruction: index, iteration } => { + LoopBody { instruction: index, iteration, mut checkpoint } => { let last = state.values.pop().ok_or("missing loop body result")?; + if checkpoint.as_mut().is_some_and(|previous| !previous.record_body(state, &last)) { + checkpoint = None; + } self.clear_loop_results(index, state)?; - state.steps.push(LoopCondition { instruction: index, iteration, last }); + state.steps.push(LoopCondition { instruction: index, iteration, last, checkpoint }); state.steps.push(Enter(self.input(index, 1)?)); } } @@ -199,7 +490,7 @@ impl Program { fn clear_loop_results(&self, index: usize, state: &mut EvaluationState) -> Result<(), String> { // Outgoing wires share a node value across reads, branches and effects // Only the active loop condition and body run again - for repeated in &self.instruction(index)?.repeated { + for repeated in &self.instruction(index)?.control_registers { if let Some(register) = state.registers.get_mut(*repeated) { *register = None; } diff --git a/crates/nodes/src/function/reciprocal.rs b/crates/nodes/src/function/reciprocal.rs new file mode 100644 index 00000000..3f2cede4 --- /dev/null +++ b/crates/nodes/src/function/reciprocal.rs @@ -0,0 +1,223 @@ +//! Fixed-point reciprocal used by runtime pixel division. + +use super::{EvaluationState, Program, fixed_point::square_fraction, function_call::FunctionCall, returned_product::forwarded, value_type}; +use materialcraft_core::Value; +use std::collections::BTreeMap; + +/// A scalar before its reciprocal rounded, in the frame which evaluated it. +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +pub(super) enum Factor { + Register(usize), + Argument(usize), + Returned { call: usize, lane: u8 }, +} + +impl Factor { + pub(super) fn read(self, state: &EvaluationState) -> Option { + match self { + Self::Register(i) => state.scalar_register(i), + Self::Argument(i) => state.reciprocal_arguments.get(i).copied().flatten(), + Self::Returned { call, lane } => state.calls.get(&call)?.returned_reciprocals.get(usize::from(lane)).copied().flatten(), + } + } +} + +#[derive(Clone, Copy)] +pub(super) enum Origin { + One, + Reciprocal(Factor), +} + +type Lanes = [Option; 4]; + +pub(super) struct CallFactors { + pub arguments: Vec, + pub results: [Option; 4], +} + +fn call_origins(call: &mut FunctionCall, index: usize, inputs: &[usize], origins: &[Lanes]) -> Lanes { + let mut factors = CallFactors { arguments: Vec::new(), results: [None; 4] }; + let mut bound = BTreeMap::new(); + for (name, register) in call.inputs.iter().zip(inputs) { + if let Some(lanes) = origins.get(*register) + && lanes.iter().any(Option::is_some) + { + bound.insert( + name.as_str(), + lanes.map(|lane| match lane { + Some(Origin::Reciprocal(factor)) => { + let slot = factors.arguments.len(); + factors.arguments.push(factor); + Some(Origin::Reciprocal(Factor::Argument(slot))) + } + other => other, + }), + ); + } + } + let mut result = identify_products(&mut call.program, bound); + for (lane, origin) in result.iter_mut().enumerate() { + if let Some(Origin::Reciprocal(factor)) = origin { + factors.results[lane] = Some(*factor); + *factor = Factor::Returned { call: index, lane: lane as u8 }; + } + } + if !factors.arguments.is_empty() || factors.results.iter().any(Option::is_some) { + call.reciprocals = Some(Box::new(factors)); + } + result +} + +/// Track the literal unit numerator and the original divisor through vector lanes and calls. +/// The caller still evaluates both operands, including assignments and random draws. +pub(super) fn identify_products(program: &mut Program, mut arguments: BTreeMap<&str, Lanes>) -> Lanes { + super::compile::remove_written_arguments(program, &mut arguments); + let instructions = &mut program.instructions; + if instructions.iter().any(|op| op.definition.id == "while") { + // A loop can clear the original divisor while another register still holds its reciprocal. + for call in instructions.iter_mut().filter_map(|op| op.call.as_mut()) { + identify_products(&mut call.program, BTreeMap::new()); + } + return [None; 4]; + } + let mut origins: Vec = Vec::with_capacity(instructions.len()); + for index in 0..instructions.len() { + let (previous, current) = instructions.split_at_mut(index); + let op = &mut current[0]; + if let Some(call) = &mut op.call { + let result = call_origins(call, index, &op.inputs, &origins); + origins.push(result); + continue; + } + let lane = |register: usize, component: usize| origins.get(register).and_then(|v| v.get(component)).copied().flatten(); + let mut result = [None; 4]; + match (op.definition.id, op.inputs.as_slice()) { + ("get_float1" | "get_float2" | "get_float3" | "get_float4", []) => { + if let Some(Value::Text(name)) = &op.value + && !name.starts_with('$') + && let Some(lanes) = arguments.get(name.as_str()) + { + result = *lanes; + } + } + ("const_float1" | "const_float2" | "const_float3" | "const_float4", []) => { + if let Some(value) = op.value.as_ref() + && let Ok(components) = value_type::floats(value) + { + for (slot, component) in result.iter_mut().zip(components).take(value_type::dimensions(value)) { + *slot = (component == 1.0).then_some(Origin::One); + } + } + } + ("div", &[a, b]) if op.type_code == 256 && !op.literal => { + if let Some(Origin::Reciprocal(factor)) = lane(b, 0) { + op.reciprocal_factor = Some(factor); + } + if matches!(lane(a, 0), Some(Origin::One)) { + result[0] = Some(Origin::Reciprocal(Factor::Register(b))); + } + } + ("mul" | "mulscalar", &[a, b]) => { + for (i, slot) in result.iter_mut().enumerate().take(super::returned_product::float_width(op.type_code)) { + let left = lane(a, i); + let right = lane(b, if op.definition.id == "mulscalar" { 0 } else { i }); + *slot = match (left, right) { + (Some(Origin::One), other) | (other, Some(Origin::One)) => other, + _ => None, + }; + } + } + ("passthrough", &[input]) => result = origins.get(input).copied().unwrap_or(result), + _ => result = forwarded(op, previous, &origins, None).unwrap_or(result), + } + origins.push(result); + } + origins.get(program.output).copied().unwrap_or([None; 4]) +} + +pub(super) fn multiply_original(numerator: Option<&Value>, factor: Option) -> Option { + let Value::Float(numerator) = numerator? else { return None }; + let flush = super::arithmetic::flush_subnormal; + Some(Value::Float(flush(flush(*numerator) * flush(factor?)))) +} + +#[derive(Clone, Copy)] +struct Polynomial { + quarter_constant: i32, + half_slope: i32, + curvature: i32, +} + +const fn nearest(value: f64) -> i32 { + (value + if value < 0.0 { -0.5 } else { 0.5 }) as i32 +} + +// Derive the coefficients from 1/x. The normalized mantissa spans 128 equal intervals. +// In units of the output significand, the function on interval i is 2^31 / (128+i+t). +const fn polynomials() -> [Polynomial; 128] { + const SCALE: f64 = 2_147_483_648.0; + let mut result = [Polynomial { quarter_constant: 0, half_slope: 0, curvature: 0 }; 128]; + let mut i = 0; + while i < result.len() { + let start = 128.0 + i as f64; + let mid = start + 0.5; + let mid_squared = mid * mid; + // On [-1/2,1/2], the linear minimax approximation of t³ is 3t/16. + let center_slope = -SCALE / mid_squared - (3.0 / 16.0) * SCALE / (mid_squared * mid_squared); + let half_slope = nearest((center_slope - SCALE / (mid_squared * mid)) * 0.5); + let slope = 2 * half_slope; + let curvature = nearest(center_slope) - slope; + + // Center the quarter-unit constant between the extrema of the residual. + let mut low = SCALE; + let mut high = 0.0; + let mut step = 0; + while step <= 64 { + let t = step as f64 / 64.0; + let residual = SCALE / (start + t) - slope as f64 * t - curvature as f64 * t * t; + if residual < low { + low = residual; + } + if residual > high { + high = residual; + } + step += 1; + } + result[i] = Polynomial { quarter_constant: nearest(2.0 * (low + high)), half_slope, curvature }; + i += 1; + } + result +} + +const POLYNOMIALS: [Polynomial; 128] = polynomials(); + +fn factor(denominator: f32, literal_divisor: bool) -> Option { + let bits = denominator.to_bits(); + let exponent = (bits >> 23) & 255; + if literal_divisor || !(1..=252).contains(&exponent) { + // At the limits, an intermediate reciprocal can overflow or underflow a finite quotient. + let reciprocal = denominator.recip(); + return reciprocal.is_normal().then_some(reciprocal); + } + let bin = POLYNOMIALS.get(((bits >> 16) & 127) as usize)?; + let fraction = bits & 0xffff; + let polynomial = (i64::from(bin.quarter_constant) << 13) + + i64::from(bin.half_slope) * i64::from(fraction) + + i64::from(bin.curvature) * i64::from(square_fraction(fraction)); + // The observed rounding threshold includes a bias of 2023/32768 of an output unit. + let significand = ((polynomial + 16_384 + 2_023) >> 15) as u32; + let magnitude = ((252 - exponent) << 23) + significand; + Some(f32::from_bits((bits & 0x8000_0000) | magnitude)) +} + +pub(crate) fn divide(numerator: f32, denominator: f32) -> f32 { + divide_by(numerator, denominator, false) +} + +pub(super) fn divide_by(numerator: f32, denominator: f32, literal_divisor: bool) -> f32 { + factor(denominator, literal_divisor).map_or_else(|| numerator / denominator, |reciprocal| numerator * reciprocal) +} + +pub(super) fn divide_add(numerator: f32, denominator: f32, addend: f32, literal_divisor: bool) -> f32 { + factor(denominator, literal_divisor).map_or_else(|| numerator / denominator + addend, |reciprocal| numerator.mul_add(reciprocal, addend)) +} diff --git a/crates/nodes/src/function/resolve_instances.rs b/crates/nodes/src/function/resolve_instances.rs index 22a75d46..8b5861a8 100644 --- a/crates/nodes/src/function/resolve_instances.rs +++ b/crates/nodes/src/function/resolve_instances.rs @@ -41,8 +41,18 @@ fn resolve(function: &mut FunctionGraph, local: &Package, sources: &BTreeMap = instance.inputs.iter().zip(&node.inputs).map(|(port, value)| (port.identifier.clone(), *value)).collect(); - instance.defaults = - graph.exposed.iter().map(|parameter| (parameter.id.clone(), graph.input_value(¶meter.id).unwrap_or(¶meter.default).clone())).collect(); + instance.defaults = graph + .exposed + .iter() + .map(|parameter| { + // An open socket reads its typed zero. Keep the authored value on the source for editing and saving. + let value = match materialcraft_core::ValueType::of(¶meter.default) { + Some(kind) if parameter.connectable => kind.default_value(), + _ => graph.input_value(¶meter.id).unwrap_or(¶meter.default).clone(), + }; + (parameter.id.clone(), value) + }) + .collect(); instance.inputs = graph .exposed .iter() diff --git a/crates/nodes/src/function/returned_product.rs b/crates/nodes/src/function/returned_product.rs new file mode 100644 index 00000000..1b4e4c09 --- /dev/null +++ b/crates/nodes/src/function/returned_product.rs @@ -0,0 +1,323 @@ +use super::{EvaluationState, Program, arithmetic::flush_subnormal, instruction::Instruction, product_sum::ProductSum, reciprocal::Factor, value_type}; +use materialcraft_core::Value; +use std::collections::{BTreeMap, BTreeSet}; + +/// Registers and components of the factors in the call that evaluated a product. +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)] +pub(super) struct Source { + calls: Vec, + factors: [Factor; 2], + components: [u8; 2], + operation: Operation, +} + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +enum Operation { + Multiply, + Divide { literal_divisor: bool }, +} + +impl Source { + pub(super) fn local(factors: [Factor; 2]) -> Self { + Self { calls: Vec::new(), factors, components: [0, 0], operation: Operation::Multiply } + } + + fn live_for_sum(&self, program: &Program, loops: &[usize], sum: usize) -> bool { + if loops.is_empty() { + return true; + } + if !self.calls.is_empty() { + return false; + } + let mut inside = false; + for &index in loops { + let members = &program.instructions[index].control_registers; + if members.binary_search(&sum).is_ok() { + inside = true; + } else if self.factors.iter().any(|factor| match factor { + Factor::Register(i) => members.binary_search(i).is_ok(), + _ => true, + }) { + // A separate loop can clear a factor while the packed vector still holds its old value. + return false; + } + } + inside + } + + pub(super) fn factors(&self, mut state: &EvaluationState) -> Result<[f32; 2], String> { + for call in &self.calls { + state = state.calls.get(call).ok_or("missing evaluated product call")?; + } + let read = |factor: Factor, component| match factor { + Factor::Register(i) => { + let value = state.registers.get(i).and_then(Option::as_ref).ok_or("missing evaluated product factor")?; + value_type::floats(value)?.get(usize::from(component)).copied().ok_or_else(|| "invalid product component".to_owned()) + } + factor => factor.read(state).ok_or_else(|| "missing reciprocal factor".to_owned()), + }; + Ok([read(self.factors[0], self.components[0])?, read(self.factors[1], self.components[1])?]) + } +} + +pub(super) struct Term { + source: Source, + on_right: bool, +} + +pub(super) type Sum = [Option; 4]; + +pub(super) fn evaluate_sum(terms: &Sum, arguments: &[Value], subtract: bool, state: &EvaluationState) -> Result { + let (left, right, subtract, weight) = match arguments { + [left, right] => (left, right, subtract, None), + // Interpolation first forms the difference between its second and first endpoints. + [first, second, Value::Float(weight)] => (second, first, true, Some(*weight)), + _ => return Err("invalid product sum operands".into()), + }; + let width = value_type::dimensions(left); + if width != value_type::dimensions(right) { + return Err("float operands must have the same dimensions".into()); + } + let left = value_type::floats(left)?; + let right = value_type::floats(right)?; + let mut result = [0.0; 4]; + for (((output, term), left), right) in result.iter_mut().zip(terms).zip(left).zip(right).take(width) { + if let Some(weight) = weight + && term.is_none() + { + *output = (left - right).mul_add(weight, right); + continue; + } + let (left, right) = (flush_subnormal(left), flush_subnormal(right)); + let sum = if let Some(term) = term { + let [a, b] = term.source.factors(state)?.map(flush_subnormal); + let a = if subtract && term.on_right { -a } else { a }; + let addend = if term.on_right { + left + } else if subtract { + -right + } else { + right + }; + match term.source.operation { + Operation::Multiply => a.mul_add(b, addend), + Operation::Divide { literal_divisor } => super::reciprocal::divide_add(a, b, addend, literal_divisor), + } + } else if subtract { + left - right + } else { + left + right + }; + let sum = flush_subnormal(sum); + *output = weight.map_or(sum, |weight| flush_subnormal(sum.mul_add(weight, right))); + } + value_type::intermediate_float_value(result.get(..width).ok_or("invalid sum dimensions")?) +} + +pub(super) type Lanes = [Option; 4]; +type Origins = [Option; 4]; + +#[derive(Default)] +struct Reads { + total: usize, + sole_product_in_sum: usize, +} + +pub(super) fn float_width(code: u32) -> usize { + match code { + 256 => 1, + 512 => 2, + 1024 => 3, + 2048 => 4, + _ => 0, + } +} + +/// Packing and component selection forward a lane without observing its rounded value. +pub(super) fn forwarded(op: &Instruction, instructions: &[Instruction], origins: &[[Option; 4]], padding: Option) -> Option<[Option; 4]> { + let mut out = [None; 4]; + match (op.definition.id, op.inputs.as_slice()) { + ("vector2" | "vector3" | "vector4", [left, right]) => { + let left_width = float_width(instructions.get(*left)?.type_code); + let right_width = float_width(instructions.get(*right)?.type_code); + if left_width == 0 || right_width == 0 || left_width + right_width != float_width(op.type_code) { + return None; + } + let lanes = op.inputs.iter().flat_map(|i| { + let width = instructions.get(*i).map_or(0, |v| float_width(v.type_code)); + origins.get(*i).into_iter().flatten().take(width) + }); + for (dst, src) in out.iter_mut().zip(lanes) { + *dst = *src; + } + } + ("swizzle1" | "swizzle2" | "swizzle3" | "swizzle4", [input]) => { + let indices = value_type::integers(op.value.as_ref()?).ok()?; + let width = float_width(instructions.get(*input)?.type_code); + if width == 0 { + return None; + } + let input = origins.get(*input)?; + for (dst, i) in out.iter_mut().take(float_width(op.type_code)).zip(indices) { + let i = usize::try_from(i).ok()?; + let source = *input.get(i)?; + *dst = if i < width { source } else { padding }; + } + } + _ => return None, + } + Some(out) +} + +pub(super) fn identify(program: &mut Program, mut returned: BTreeMap, root: bool) -> Lanes { + let empty = || std::array::from_fn(|_| None); + if returned.is_empty() + && !program + .instructions + .iter() + .any(|op| op.reciprocal_factor.is_some() || op.product_operation().is_some() && float_width(op.type_code) > 0 && !op.literal) + { + return empty(); + } + + let loops: Vec<_> = program.instructions.iter().enumerate().filter_map(|(i, op)| (op.definition.id == "while").then_some(i)).collect(); + let mut origins: Vec = Vec::with_capacity(program.instructions.len()); + let mut products: Vec<(Source, Reads)> = Vec::new(); + let mut sums = Vec::new(); + // With straight-line evaluation the instructions visit each assignment before its subsequent reads. + // A nested call can also expose the rounded assignment to its caller. + let mut assigned = (root + && program.instructions.iter().any(|op| op.definition.id == "set") + && program.instructions.iter().all(|op| op.call.is_none() && !matches!(op.definition.id, "ifelse" | "while"))) + .then(BTreeMap::new); + let mut unit_products = BTreeSet::new(); + for (index, op) in program.instructions.iter().enumerate() { + if let Some(lanes) = forwarded(op, &program.instructions, &origins, None) { + origins.push(lanes); + continue; + } + if let Some(assigned) = &mut assigned { + let source = |input: usize| origins.get(input).copied().unwrap_or([None; 4]); + let lanes = match (op.definition.id, op.inputs.as_slice(), &op.value) { + ("set", &[input], Some(Value::Text(name))) => { + let lanes = source(input); + if lanes.iter().flatten().all(|&id| products.get(id).is_some_and(|(p, _)| p.operation == Operation::Multiply)) { + assigned.insert(name.as_str(), lanes); + Some(lanes) + } else { + assigned.remove(name.as_str()); + None + } + } + ("get_float1" | "get_float2" | "get_float3" | "get_float4", [], Some(Value::Text(name))) => assigned.get(name.as_str()).copied(), + ("sequence", &[_, last], _) | ("passthrough", &[last], _) => Some(source(last)), + ("mulscalar", &[input, scale], _) + if program.instructions.get(scale).is_some_and(|op| op.definition.id == "const_float1" && op.value == Some(Value::Float(1.0))) => + { + let lanes = source(input); + if lanes.iter().any(Option::is_some) { + unit_products.insert(index); + Some(lanes) + } else { + None + } + } + _ => None, + }; + if let Some(lanes) = lanes { + origins.push(lanes); + continue; + } + } + + for source in op.inputs.iter().filter_map(|i| origins.get(*i)).flatten().flatten() { + if let Some((_, uses)) = products.get_mut(*source) { + uses.total += 1; + } + } + let width = float_width(op.type_code); + let lanes_of = |i: usize| origins.get(i).copied().unwrap_or([None; 4]); + let sides = match (op.definition.id, op.inputs.as_slice()) { + ("add" | "sub", &[left, right]) => Some([lanes_of(left), lanes_of(right)]), + ("lerp", &[_, second, weight]) if program.instructions.get(weight).is_some_and(|w| w.type_code == 256) => Some([lanes_of(second), [None; 4]]), + _ => None, + }; + if width > 0 + && let Some(sides) = sides + && sides.iter().flatten().any(Option::is_some) + && (op.pixel_product_sum.is_none() + || op.inputs.iter().take(2).any(|input| unit_products.contains(input)) && sides.iter().any(|side| side.iter().all(Option::is_none))) + { + for (left, right) in sides[0].iter().zip(sides[1]) { + if let Some(id) = left.xor(right) + && let Some((_, reads)) = products.get_mut(id) + { + reads.sole_product_in_sum += 1; + } + } + sums.push((index, sides)); + } + + let mut lanes = [None; 4]; + if let Some(factor) = op.reciprocal_factor + && let &[a, _] = op.inputs.as_slice() + { + lanes[0] = Some(products.len()); + products.push((Source::local([Factor::Register(a), factor]), Reads::default())); + } else if let Some(operation) = op.product_operation() + && !op.literal + && let &[a, b] = op.inputs.as_slice() + { + let operation = if operation == "div" { Operation::Divide { literal_divisor: op.literal_divisor } } else { Operation::Multiply }; + for (i, lane) in lanes.iter_mut().take(width).enumerate() { + *lane = Some(products.len()); + let j = if op.definition.id == "mulscalar" { 0 } else { i }; + products.push((Source { components: [i as u8, j as u8], operation, ..Source::local([a, b].map(Factor::Register)) }, Reads::default())); + } + } else if let Some(exports) = returned.remove(&index) { + // Two returned lanes can reference the same product. Count their downstream reads together. + let mut distinct = BTreeMap::new(); + for (lane, source) in lanes.iter_mut().zip(exports) { + if let Some(mut source) = source { + source.calls.insert(0, index); + *lane = Some(*distinct.entry(source.clone()).or_insert_with(|| { + let id = products.len(); + products.push((source, Reads::default())); + id + })); + } + } + } + origins.push(lanes); + } + + let output = origins.get(program.output).copied().unwrap_or([None; 4]); + let exported = output.map(|id| { + let (source, uses) = products.get(id?)?; + (uses.total == 0).then(|| source.clone()) + }); + // A caller cannot retain registers that the callee's last loop iteration may have cleared. + let exported = if loops.is_empty() { exported } else { empty() }; + for id in output.into_iter().flatten() { + if let Some((_, uses)) = products.get_mut(id) { + uses.total += 1; + } + } + for (index, sides) in sums { + let terms: Sum = std::array::from_fn(|i| { + // Each sum can contract its only product until a separate reader observes the rounded lane. + sides.iter().enumerate().find_map(|(side, lanes)| { + let id = lanes.get(i).copied().flatten()?; + let (source, uses) = products.get(id)?; + let available = uses.total == 1 || (loops.is_empty() && uses.total == uses.sole_product_in_sum); + (available && source.live_for_sum(program, &loops, index)).then(|| Term { source: source.clone(), on_right: side == 1 }) + }) + }); + if terms.iter().any(Option::is_some) + && let Some(op) = program.instructions.get_mut(index) + { + op.pixel_product_sum = Some(ProductSum::returned(&op.inputs, terms)); + } + } + exported +} diff --git a/crates/nodes/src/function/sequence_prefix.rs b/crates/nodes/src/function/sequence_prefix.rs new file mode 100644 index 00000000..ef7e5bc6 --- /dev/null +++ b/crates/nodes/src/function/sequence_prefix.rs @@ -0,0 +1,119 @@ +use super::instruction::Instruction; + +/// The part of a pattern expression whose branches and packed channels can be planned +/// without moving a draw or assignment across an opaque call. +pub(super) fn pattern_planning_end(program: &super::Program) -> usize { + use super::function_call::PatternAccess; + let instructions = &program.instructions; + // A closed sampler advances the same stamp stream as a direct draw. Its call site + // participates in branch planning even when the surrounding expression assigns variables. + if !instructions.iter().any(|op| op.definition.id == "set") + || instructions.iter().filter_map(|op| op.call.as_ref()).all(|call| call.pattern_access != PatternAccess::Context) + { + return instructions.len(); + } + let Some(first_call) = instructions.iter().position(|op| op.call.as_ref().is_some_and(|call| call.pattern_access != PatternAccess::Arguments)) else { + return instructions.len(); + }; + let Some(root) = instructions.get(program.output) else { return 0 }; + let ("sequence", &[first, _]) = (root.definition.id, root.inputs.as_slice()) else { return 0 }; + // The compiler visits a Sequence's first input and its dependencies before its + // second input. A call in the result cannot observe an intermediate prefix value. + let end = first.saturating_add(1); + if end <= first_call && instructions[end..].iter().all(|op| op.definition.id != "set" && op.call.as_ref().is_none_or(|call| !call.exports)) { + end + } else { + 0 + } +} + +/// How to evaluate a Sequence's first input when its return value is discarded. +#[derive(Clone, Copy)] +pub(super) enum Visit { + Skip, + Value, + Inputs, + Branch, +} + +pub(super) fn identify(instructions: &[Instruction], output: usize) -> Vec { + if !instructions.iter().any(|op| op.definition.id == "sequence") || !instructions.iter().any(|op| op.definition.id == "rand") { + return Vec::new(); + } + // A loop can read the same register at several points with different assignments and draws. + // Keep its existing evaluation and invalidation until each iteration's reads are accounted for. + if instructions.iter().any(|op| op.definition.id == "while") { + return Vec::new(); + } + + let mut readers = vec![Vec::new(); instructions.len()]; + let mut needed = vec![false; instructions.len()]; + let mut effects = vec![false; instructions.len()]; + enum Mark { + Value(usize), + Effect(usize), + } + use Mark::*; + let mut pending = vec![Value(output)]; + for (index, op) in instructions.iter().enumerate() { + for &input in &op.inputs { + readers[input].push(index); + } + // A call may read or export a variable without a wire to the caller. + if op.definition.id == "set" || op.call.is_some() { + pending.push(Value(index)); + pending.push(Effect(index)); + } + } + while let Some(mark) = pending.pop() { + match mark { + Value(i) if !needed[i] => { + needed[i] = true; + let op = &instructions[i]; + if op.definition.id == "rand" || op.definition.id.starts_with("get_") { + pending.push(Effect(i)); + } + if let ("sequence", &[_, last]) = (op.definition.id, op.inputs.as_slice()) { + pending.push(Value(last)); + } else { + pending.extend(op.inputs.iter().copied().map(Value)); + } + } + Effect(i) if !effects[i] => { + effects[i] = true; + for &reader in &readers[i] { + pending.push(Effect(reader)); + let op = &instructions[reader]; + if let ("ifelse", &[condition, yes, no]) = (op.definition.id, op.inputs.as_slice()) + && (i == yes || i == no) + { + pending.push(Value(condition)); + } + } + } + _ => {} + } + } + + instructions + .iter() + .enumerate() + .map(|(i, op)| { + if !effects[i] { + Visit::Skip + } else if needed[i] { + Visit::Value + } else if let ("ifelse", &[_, yes, no]) = (op.definition.id, op.inputs.as_slice()) + && (effects[yes] || effects[no]) + { + Visit::Branch + } else { + Visit::Inputs + } + }) + .collect() +} + +#[cfg(test)] +#[path = "sequence_prefix.test.rs"] +mod tests; diff --git a/crates/nodes/src/function/sequence_prefix.test.rs b/crates/nodes/src/function/sequence_prefix.test.rs new file mode 100644 index 00000000..827ecfc9 --- /dev/null +++ b/crates/nodes/src/function/sequence_prefix.test.rs @@ -0,0 +1,75 @@ +use crate::function::{EvaluationContext, EvaluationState, FunctionScope, compile}; +use materialcraft_core::{FunctionGraph, Value}; +use std::collections::BTreeMap; + +#[test] +fn value_processor_random_draws_use_the_scalar_evaluation_position() { + let mut graph = FunctionGraph::default(); + let one = graph.add_constant(Value::Float(1.0)); + let first = graph.add("rand", &[one], None); + let second = graph.add("rand", &[one], None); + graph.output = Some(graph.add("vector2", &[first, second], None)); + let variables = BTreeMap::new(); + for size in [[16.0; 2], [128.0, 32.0]] { + let context = EvaluationContext { + scope: FunctionScope::ValueProcessor, + position: [0.0; 2], + size, + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + for (seed, pair) in [(3, [280133, 3213511]), (20, [233407, 5314947])] { + let expected = Value::Float2(pair.map(|level| level as f32 / 8388608.0)); + assert_eq!(compile(&graph, seed).unwrap().evaluate(&context, &mut EvaluationState::default()).unwrap(), expected, "seed {seed}"); + } + } +} + +#[test] +fn discarded_sequence_values_preserve_assignments_and_shared_random_draws() { + let mut graph = FunctionGraph::default(); + let one = graph.add_constant(Value::Float(1.0)); + let zero = graph.add_constant(Value::Float(0.0)); + let choice = graph.add("get_bool", &[], Some(Value::Text("choice".into()))); + let first = graph.add("rand", &[one], None); + let unused = graph.add("rand", &[one], None); + let last = graph.add("rand", &[one], None); + let write = graph.add("set", &[first], Some(Value::Text("tone".into()))); + let read = graph.add("get_float1", &[], Some(Value::Text("tone".into()))); + let observe = graph.add("mul", &[read, zero], None); + let following = graph.add("add", &[observe, last], None); + let sum = graph.add("add", &[write, unused], None); + let branch = graph.add("ifelse", &[choice, write, unused], None); + let shared_zero = graph.add("mul", &[first, zero], None); + let shared = graph.add("add", &[last, shared_zero], None); + let pure = graph.add("sequence", &[unused, last], None); + let assigned = graph.add("sequence", &[sum, following], None); + let conditional = graph.add("sequence", &[branch, following], None); + let reused = graph.add("sequence", &[first, shared], None); + let vertices = [pure, assigned, conditional, reused]; + let control = graph.add("vector2", &[first, last], None); + + for scope in [FunctionScope::Node, FunctionScope::FxMap, FunctionScope::PixelProcessor, FunctionScope::ValueProcessor] { + for choice in [true, false] { + let variables = BTreeMap::from([("choice".into(), Value::Bool(choice)), ("tone".into(), Value::Float(0.25))]); + let context = EvaluationContext { scope, position: [0.0; 2], size: [16.0; 2], images: &[], image_formats: &[], tile: true, variables: &variables }; + for seed in [0, 17] { + // An ordinary vector observes the first two draws from this particular scope. + graph.output = Some(control); + let reference = compile(&graph, seed).unwrap().evaluate(&context, &mut EvaluationState::default()).unwrap(); + let Value::Float2([a, b]) = reference else { panic!("two draws") }; + for (root, value) in vertices.into_iter().zip([a, b, if choice { b } else { a }, b]) { + graph.output = Some(root); + let mut state = EvaluationState::default(); + let result = compile(&graph, seed).unwrap().evaluate(&context, &mut state).unwrap(); + assert_eq!(result, Value::Float(value), "scope {scope:?}, root {root}, choice {choice}"); + if root == assigned || (root == conditional && choice) { + assert_eq!(state.assignments().get("tone"), Some(&Value::Float(a))); + } + } + } + } + } +} diff --git a/crates/nodes/src/function/square_root.rs b/crates/nodes/src/function/square_root.rs new file mode 100644 index 00000000..618f2814 --- /dev/null +++ b/crates/nodes/src/function/square_root.rs @@ -0,0 +1,66 @@ +//! Fixed-point square root for runtime pixel expressions. +use super::fixed_point::square_fraction; + +// Quadratics fitted to original procedural float fields. Each row spans 1/64 of the +// normalized mantissa. The constant uses 25 fraction bits, the slope uses 23 (even +// exponent) or 22 (odd), and the curvature uses 24. +#[rustfmt::skip] +const INTERVALS: [[[i32; 3]; 64]; 2] = [ + [ + [33_554_431, 65_535, -506], [33_815_559, 65_029, -494], [34_074_686, 64_534, -482], [34_331_857, 64_051, -472], + [34_587_116, 63_578, -461], [34_840_505, 63_116, -452], [35_092_064, 62_664, -443], [35_341_833, 62_221, -434], + [35_589_849, 61_787, -424], [35_836_148, 61_363, -417], [36_080_766, 60_947, -408], [36_323_737, 60_539, -399], + [36_565_094, 60_139, -391], [36_804_867, 59_748, -385], [37_043_089, 59_363, -376], [37_279_788, 58_987, -370], + [37_514_994, 58_617, -363], [37_748_735, 58_254, -357], [37_981_037, 57_898, -351], [38_211_927, 57_548, -344], + [38_441_430, 57_204, -337], [38_669_571, 56_867, -332], [38_896_374, 56_535, -325], [39_121_862, 56_209, -319], + [39_346_058, 55_889, -315], [39_568_984, 55_574, -309], [39_790_661, 55_264, -304], [40_011_109, 54_960, -299], + [40_230_350, 54_660, -294], [40_448_402, 54_366, -290], [40_665_285, 54_076, -285], [40_881_018, 53_790, -280], + [41_095_617, 53_510, -277], [41_309_103, 53_233, -272], [41_521_490, 52_961, -268], [41_732_797, 52_693, -265], + [41_943_039, 52_429, -261], [42_152_233, 52_168, -255], [42_360_393, 51_912, -252], [42_567_535, 51_660, -249], + [42_773_675, 51_410, -244], [42_978_826, 51_165, -242], [43_183_002, 50_923, -238], [43_386_217, 50_685, -236], + [43_588_485, 50_449, -231], [43_789_818, 50_218, -229], [43_990_230, 49_989, -226], [44_189_734, 49_763, -222], + [44_388_340, 49_541, -221], [44_586_062, 49_321, -217], [44_782_911, 49_104, -214], [44_978_898, 48_890, -211], + [45_174_036, 48_678, -207], [45_368_333, 48_471, -207], [45_561_803, 48_264, -202], [45_754_454, 48_061, -200], + [45_946_297, 47_861, -199], [46_137_343, 47_662, -194], [46_327_601, 47_467, -194], [46_517_081, 47_273, -190], + [46_705_792, 47_082, -188], [46_893_743, 46_894, -187], [47_080_945, 46_707, -184], [47_267_405, 46_523, -182], + ], + [ + [47_453_132, 46_340, -714], [47_822_423, 45_982, -697], [48_188_883, 45_633, -684], [48_552_578, 45_291, -668], + [48_913_569, 44_957, -655], [49_271_915, 44_630, -641], [49_627_673, 44_310, -626], [49_980_899, 43_997, -613], + [50_331_647, 43_690, -599], [50_679_967, 43_390, -588], [51_025_909, 43_096, -577], [51_369_522, 42_808, -567], + [51_710_852, 42_525, -554], [52_049_943, 42_248, -544], [52_386_839, 41_976, -531], [52_721_583, 41_710, -524], + [53_054_215, 41_448, -512], [53_384_773, 41_192, -505], [53_713_298, 40_940, -496], [54_039_826, 40_692, -484], + [54_364_393, 40_449, -476], [54_687_032, 40_211, -470], [55_007_781, 39_976, -459], [55_326_669, 39_746, -453], + [55_643_730, 39_519, -443], [55_958_994, 39_297, -439], [56_272_492, 39_078, -431], [56_584_253, 38_863, -425], + [56_894_306, 38_651, -417], [57_202_679, 38_442, -408], [57_509_398, 38_237, -401], [57_814_490, 38_036, -399], + [58_117_980, 37_837, -391], [58_419_894, 37_641, -383], [58_720_255, 37_449, -379], [59_019_088, 37_259, -372], + [59_316_415, 37_073, -370], [59_612_259, 36_889, -364], [59_906_643, 36_707, -356], [60_199_586, 36_529, -353], + [60_491_111, 36_353, -348], [60_781_239, 36_179, -341], [61_069_987, 36_008, -336], [61_357_377, 35_839, -330], + [61_643_427, 35_673, -327], [61_928_156, 35_509, -323], [62_211_581, 35_347, -317], [62_493_721, 35_188, -316], + [62_774_593, 35_030, -309], [63_054_214, 34_875, -306], [63_332_600, 34_722, -303], [63_609_769, 34_570, -297], + [63_885_734, 34_421, -294], [64_160_513, 34_274, -293], [64_434_120, 34_128, -287], [64_706_570, 33_984, -282], + [64_977_877, 33_843, -282], [65_248_057, 33_702, -275], [65_517_122, 33_564, -273], [65_785_087, 33_427, -269], + [66_051_965, 33_292, -266], [66_317_768, 33_159, -264], [66_582_511, 33_027, -261], [66_846_205, 32_897, -259], + ], +]; + +pub(crate) fn evaluate(value: f32) -> f32 { + if value < f32::MIN_POSITIVE || value.is_nan() { + return 0.0; + } + if value.is_infinite() { + return value; + } + let bits = value.to_bits(); + let exponent = (bits >> 23) as i32 - 127; + let parity = (exponent & 1) as usize; + let interval = ((bits >> 17) & 63) as usize; + let [constant, slope, curvature] = INTERVALS[parity][interval].map(i64::from); + let fraction = bits & 0x1_ffff; + let square = i64::from(square_fraction(fraction >> 1)); + let fixed = (constant << 15) + ((slope * i64::from(fraction)) << parity) + 2 * curvature * square; + // Round to the nearest significand, with exact halfway cases rounded down. + let significand = ((fixed + 65_535) >> 17) as u32; + let scale = (exponent.div_euclid(2) + 126) as u32; + f32::from_bits((scale << 23) + significand) +} diff --git a/crates/nodes/src/function/system_variable.rs b/crates/nodes/src/function/system_variable.rs index 5a956471..e27265f3 100644 --- a/crates/nodes/src/function/system_variable.rs +++ b/crates/nodes/src/function/system_variable.rs @@ -68,8 +68,8 @@ impl SystemVariable { pub fn available_in(self, scope: FunctionScope) -> bool { match self { - Self::Position => matches!(scope, FunctionScope::PixelProcessor | FunctionScope::FxMap), - Self::Depth | Self::DepthPow2 | Self::Number => scope == FunctionScope::FxMap, + Self::Position => !matches!(scope, FunctionScope::Node | FunctionScope::RandomSeed), + Self::Depth | Self::DepthPow2 | Self::Number => scope == FunctionScope::ValueProcessor || scope.is_pattern(), _ => true, } } @@ -81,8 +81,26 @@ impl SystemVariable { let value = match self { Self::Position => Value::Float2(context.position), - Self::Size => Value::Float2(context.size), - Self::SizeLog2 => Value::Float2(context.size.map(f32::log2)), + Self::Depth | Self::DepthPow2 | Self::Number if context.scope == FunctionScope::ValueProcessor => Value::Float(0.0), + Self::Size | Self::SizeLog2 => { + let requested = match context.variables.get("$sizelog2") { + Some(Value::Float2(exponents)) => *exponents, + _ => [0.0; 2], + }; + Value::Float2(std::array::from_fn(|axis| { + if context.size[axis] == 0.0 { + // An absolute graph size function has no inherited dimensions. + 0.0 + } else if requested[axis] < 0.0 && context.size[axis] == 1.0 { + // The raster has one texel, but functions retain the signed size exponent. + if self == Self::SizeLog2 { requested[axis] } else { 1_i32.wrapping_shl(requested[axis] as i32 as u32) as f32 } + } else if self == Self::SizeLog2 { + context.size[axis].log2() + } else { + context.size[axis] + } + })) + } _ => context.variables.get(self.name()).cloned().unwrap_or_else(|| match self { Self::Tiling => Value::Int(if context.tile { 3 } else { 0 }), Self::DepthPow2 => Value::Float(1.0), diff --git a/crates/nodes/src/function/system_variable.test.rs b/crates/nodes/src/function/system_variable.test.rs index 3b64d7b8..9a5d0e39 100644 --- a/crates/nodes/src/function/system_variable.test.rs +++ b/crates/nodes/src/function/system_variable.test.rs @@ -18,8 +18,15 @@ fn system_variables_use_caller_scope_even_when_a_local_name_exists() { ("$depthpow2".into(), Value::Float(0.125)), ("$number".into(), Value::Float(7.0)), ]); - let mut context = - EvaluationContext { scope: FunctionScope::Node, position: [0.25, 0.75], size: [256.0, 128.0], images: &[], tile: true, variables: &variables }; + let mut context = EvaluationContext { + image_formats: &[], + scope: FunctionScope::Node, + position: [0.25, 0.75], + size: [256.0, 128.0], + images: &[], + tile: true, + variables: &variables, + }; for scope in [FunctionScope::Node, FunctionScope::PixelProcessor, FunctionScope::FxMap] { context.scope = scope; @@ -42,6 +49,26 @@ fn system_variables_use_caller_scope_even_when_a_local_name_exists() { } } +#[test] +fn a_property_integer_getter_reads_zero_for_an_unbound_reserved_name() { + let variables = BTreeMap::new(); + let context = EvaluationContext { + scope: FunctionScope::Node, + position: [0.5; 2], + size: [8.0, 4.0], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + for name in ["$randomseed", "$missing_count"] { + assert_eq!(evaluate("get_integer1", name, &context).unwrap(), Value::Int(0)); + assert_eq!(evaluate("isdefined", name, &context).unwrap(), Value::Bool(false)); + } + assert_eq!(evaluate("get_integer1", "$tiling", &context).unwrap(), Value::Int(3)); + assert!(evaluate("get_integer1", "$depth", &context).is_err()); +} + #[test] fn system_values_are_typed_finite_and_read_only() { for (name, operation, value) in [ @@ -52,13 +79,29 @@ fn system_values_are_typed_finite_and_read_only() { ("$tiling", "get_integer1", Value::Int(4)), ] { let variables = BTreeMap::from([(name.into(), value)]); - let context = EvaluationContext { scope: FunctionScope::Node, position: [0.0; 2], size: [16.0; 2], images: &[], tile: true, variables: &variables }; + let context = EvaluationContext { + image_formats: &[], + scope: FunctionScope::Node, + position: [0.0; 2], + size: [16.0; 2], + images: &[], + tile: true, + variables: &variables, + }; assert!(evaluate(operation, name, &context).is_err(), "{name}"); } let variables = BTreeMap::new(); - let context = EvaluationContext { scope: FunctionScope::Node, position: [0.0; 2], size: [16.0; 2], images: &[], tile: true, variables: &variables }; + let context = EvaluationContext { + image_formats: &[], + scope: FunctionScope::Node, + position: [0.0; 2], + size: [16.0; 2], + images: &[], + tile: true, + variables: &variables, + }; let mut graph = FunctionGraph::default(); let value = graph.add_constant(Value::Float(9.0)); graph.output = Some(graph.add("set", &[value], Some(Value::Text("$time".into())))); diff --git a/crates/nodes/src/function/tests.rs b/crates/nodes/src/function/tests.rs index bfea4f84..bd79033d 100644 --- a/crates/nodes/src/function/tests.rs +++ b/crates/nodes/src/function/tests.rs @@ -6,7 +6,15 @@ use super::{EvaluationContext, EvaluationState, FUNCTIONS, compile, default_valu fn evaluate(graph: &FunctionGraph, variables: &BTreeMap) -> Result { let image = Image::filled(3, 5, Kind::Color, [0.25, 0.5, 0.75, 1.0]); - let context = EvaluationContext { scope: Default::default(), position: [0.5; 2], size: [3.0, 5.0], images: &[Some(image)], tile: true, variables }; + let context = EvaluationContext { + image_formats: &[], + scope: Default::default(), + position: [0.5; 2], + size: [3.0, 5.0], + images: &[Some(image)], + tile: true, + variables, + }; compile(graph, 7)?.evaluate(&context, &mut EvaluationState::default()) } @@ -17,6 +25,1746 @@ fn operation(name: &str, arguments: &[Value], setting: Option) -> Result< evaluate(&graph, &BTreeMap::new()) } +#[test] +fn bound_pattern_arithmetic_preserves_nested_arguments_and_shared_random_draws() { + use super::{FunctionScope, PatternExpression}; + use crate::random::FunctionRandom; + use materialcraft_core::{GraphInstance, GraphPort, ValueType}; + + fn call(graph: &mut FunctionGraph, body: FunctionGraph, wires: &[(&str, u32)]) -> u32 { + let inputs: Vec<_> = wires.iter().map(|&(_, id)| id).collect(); + let id = graph.add("instance", &inputs, None); + let node = graph.nodes.last_mut().unwrap(); + let port = |name: &str| GraphPort { identifier: name.into(), type_code: ValueType::Float as u32 }; + node.instance = Some(GraphInstance { + graph: "sample".into(), + label: String::new(), + package: String::new(), + inputs: wires.iter().map(|&(name, _)| port(name)).collect(), + outputs: vec![port("output")], + defaults: wires.iter().map(|&(name, _)| (name.into(), Value::Float(0.0))).collect(), + }); + node.source = Some(Ok(std::sync::Arc::new(body))); + id + } + + let mut leaf = FunctionGraph::input("gain", ValueType::Float); + let gain = leaf.output.unwrap(); + leaf.output = Some(leaf.add("rand", &[gain], None)); + let mut wrapper = FunctionGraph::default(); + let draw = call(&mut wrapper, leaf, &[]); + wrapper.output = Some(wrapper.add("add", &[draw, draw], None)); + let mut graph = FunctionGraph::default(); + let range = graph.add_constant(Value::Float(0.75)); + let gain = graph.add("rand", &[range], None); + let twice = call(&mut graph, wrapper, &[("gain", gain)]); + graph.output = Some(graph.add("vector2", &[twice, gain], None)); + + let program = compile(&graph, 0).unwrap(); + let variables = BTreeMap::from([("gain".into(), Value::Float(0.125))]); + let assigned = BTreeSet::from(["gain"]); + let context = EvaluationContext { + scope: FunctionScope::FxMap, + variables: &variables, + position: [0.5; 2], + size: [16.0; 2], + tile: true, + images: &[], + image_formats: &[], + }; + let mut bound = PatternExpression::bind(&program, &variables, &assigned, None).unwrap(); + for seed in [0, 19, 105_532] { + let mut original = FunctionRandom::image(seed); + let mut compact = original; + let expected = program.evaluate_with_random(&context, &mut EvaluationState::default(), &mut original).unwrap(); + assert_eq!(bound.evaluate(&mut compact).unwrap(), (expected, None)); + assert_eq!(compact.draw().to_bits(), original.draw().to_bits()); + } + + // A free read of the same mutable name and a per-visit position both need live bindings. + for (name, kind) in [("gain", ValueType::Float), ("$pos", ValueType::Float2), ("$number", ValueType::Float)] { + let program = compile(&FunctionGraph::input(name, kind), 0).unwrap(); + assert!(PatternExpression::bind(&program, &variables, &assigned, None).is_none()); + } +} + +#[test] +fn seeded_vector_modulo_preserves_the_period_and_random_stream() { + use super::{FunctionScope, PatternExpression}; + use crate::random::FunctionRandom; + + let mut graph = FunctionGraph::default(); + let range = graph.add_constant(Value::Float(1.0)); + let draw = graph.add("rand", &[range], None); + let pair = graph.add("vector2", &[draw, draw], None); + let offset = graph.add_constant(Value::Float2([0.8125, 0.21875])); + let shifted = graph.add("sub", &[pair, offset], None); + let period = graph.add_constant(Value::Float2([0.375, -0.1875])); + graph.output = Some(graph.add("mod", &[shifted, period], None)); + let program = compile(&graph, 0).unwrap(); + let variables = BTreeMap::new(); + let context = EvaluationContext { + scope: FunctionScope::FxMap, + variables: &variables, + position: [0.5; 2], + size: [16.0; 2], + tile: true, + images: &[], + image_formats: &[], + }; + let mut bound = PatternExpression::bind(&program, &variables, &BTreeSet::new(), None).expect("seeded vector modulo should bind"); + for seed in [0, 19, 42, 329_779] { + let mut normal = FunctionRandom::image(seed); + let mut prepared = normal; + let value = program.evaluate_with_random(&context, &mut EvaluationState::default(), &mut normal).unwrap(); + let Value::Float2([x, y]) = value else { panic!("expected a two-component offset") }; + assert!((0.0..0.375).contains(&x) && y > -0.1875 && y <= 0.0); + assert_eq!(bound.evaluate(&mut prepared).unwrap(), (value, None)); + assert_eq!(prepared.draw().to_bits(), normal.draw().to_bits()); + } +} + +#[test] +fn folded_integers_use_word_order_and_convert_unsigned_magnitudes() { + let variables = BTreeMap::from([("lhs".into(), Value::Int(-5)), ("rhs".into(), Value::Int(2))]); + for (left_literal, right_literal) in [(true, true), (true, false), (false, true), (false, false)] { + let mut graph = FunctionGraph::default(); + let mut operand = |name: &str, value, literal| { + if literal { graph.add_constant(Value::Int(value)) } else { graph.add("get_integer1", &[], Some(Value::Text(name.into()))) } + }; + let left = operand("lhs", -5, left_literal); + let right = operand("rhs", 2, right_literal); + let unsigned = left_literal && right_literal; + for (op, expected) in [("lr", !unsigned), ("lreq", !unsigned), ("gt", unsigned), ("gteq", unsigned)] { + graph.output = Some(graph.add(op, &[left, right], None)); + assert_eq!(evaluate(&graph, &variables).unwrap(), Value::Bool(expected), "{op} with literal operands {left_literal}/{right_literal}"); + } + graph.output = Some(graph.add("tofloat", &[left], None)); + assert_eq!(evaluate(&graph, &variables).unwrap(), Value::Float(if left_literal { 4_294_967_296.0 } else { -5.0 })); + } +} + +#[test] +fn variable_reads_consume_one_reference_marker() { + let variables = BTreeMap::from([("level".into(), Value::Float(0.1875))]); + for (assigned, getter, expected) in + [("level", "%level", 0.6875), ("%level", "level", 0.1875), ("%level", "%level", 0.1875), ("%level", "%%level", 0.6875), ("level", "%%level", 0.0)] + { + let mut graph = FunctionGraph::default(); + let value = graph.add_constant(Value::Float(0.6875)); + let set = graph.add("set", &[value], Some(Value::Text(assigned.into()))); + let get = graph.add("get_float1", &[], Some(Value::Text(getter.into()))); + graph.output = Some(graph.add("sequence", &[set, get], None)); + assert_eq!(evaluate(&graph, &variables), Ok(Value::Float(expected)), "{assigned} then {getter}"); + } + + let mut graph = FunctionGraph::default(); + graph.output = Some(graph.add("isdefined", &[], Some(Value::Text("%level".into())))); + assert_eq!(evaluate(&graph, &variables), Ok(Value::Bool(false))); + graph.output = Some(graph.add("get_float2", &[], Some(Value::Text("%$size".into())))); + assert_eq!(evaluate(&graph, &variables), Ok(Value::Float2([3.0, 5.0]))); +} + +fn pixel_operation(op: &str, operands: &[Value], literal: bool) -> Value { + scoped_operation(super::FunctionScope::PixelProcessor, op, operands, literal) +} + +fn scoped_operation(scope: super::FunctionScope, op: &str, operands: &[Value], literal: bool) -> Value { + let mut graph = FunctionGraph::default(); + let mut variables = BTreeMap::new(); + let mut inputs = Vec::new(); + for (i, operand) in operands.iter().enumerate() { + let input = if literal { + graph.add_constant(operand.clone()) + } else { + let name = format!("input{i}"); + variables.insert(name.clone(), operand.clone()); + graph.add(&format!("get_float{}", super::value_type::dimensions(operand)), &[], Some(Value::Text(name))) + }; + inputs.push(input); + } + graph.output = Some(graph.add(op, &inputs, None)); + let context = EvaluationContext { image_formats: &[], scope, position: [0.5; 2], size: [1.0; 2], images: &[], tile: true, variables: &variables }; + compile(&graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap() +} + +#[test] +fn floating_modulo_wraps_a_rounded_period_to_zero() { + let gap = 1.0 - 1.0_f32.next_down(); + let inputs = [Value::Float4([-gap * 0.5, gap * 0.25, -gap * 0.75, gap]), Value::Float4([1.0, -1.0, 1.0, -1.0])]; + for scope in [super::FunctionScope::FxMap, super::FunctionScope::Node, super::FunctionScope::PixelProcessor] { + assert_eq!(scoped_operation(scope, "mod", &inputs, false), Value::Float4([0.0, 0.0, 1.0 - gap, -1.0 + gap])); + assert_eq!(scoped_operation(scope, "mod", &inputs, true), Value::Float4([1.0, -1.0, 1.0 - gap, -1.0 + gap])); + } +} + +#[test] +fn runtime_arithmetic_flushes_subnormal_operands_and_results_with_their_signs() { + for scope in [super::FunctionScope::Node, super::FunctionScope::ValueProcessor, super::FunctionScope::PixelProcessor, super::FunctionScope::FxMap] { + for (op, a, b, expected) in [ + ("add", 0x00800001, 0x80800000, 0), + ("sub", 0x00800001, 0x00800000, 0), + ("mul", 0x807fffff, 0x40000000, 0x80000000), + ("mul", 0x00800000, 0x3f000000, 0), + ("div", 0x00800000, 0x40000000, 0), + ("div", 0x00800000, 0x807fffff, f32::NEG_INFINITY.to_bits()), + ] { + let args = [Value::Float(f32::from_bits(a)), Value::Float(f32::from_bits(b))]; + let actual = scoped_operation(scope, op, &args, false); + assert!(matches!(actual, Value::Float(value) if value.to_bits() == expected), "{scope:?} {op}: {actual:?}"); + } + } + let a = Value::Float2([f32::from_bits(0x00400000), f32::MIN_POSITIVE]); + let b = Value::Float2([f32::from_bits(0x00400000), 0.5]); + assert_eq!(pixel_operation("dot", &[a, b], false), Value::Float(0.0)); +} + +#[test] +fn uniform_logarithms_and_powers_use_their_measured_domains() { + for (op, input, exponent, bits) in [ + ("log", -1.0, None, 0), + ("log", f32::from_bits(1), None, 0), + ("log", 0.5625, None, 0xbf134b11), + ("log", 0.75, None, 0xbe934b11), + ("log2", -2.0, None, 0), + ("log2", f32::from_bits(1), None, 0), + ("log2", f32::MIN_POSITIVE, None, 0xc2fbffff), + ("log2", 0.625, None, 0xbf2d961e), + ("pow", 0.0, Some(-2.0), 0), + ("pow", -2.0, Some(0.5), 0), + ("pow", -2.0, Some(-3.0), 0xbe000000), + ("pow", 0.3, Some(2.4), 0x3d63befe), + ("pow", 0.563_981_1, Some(2.4), 0x3e8182ad), + ("pow", 0.95, Some(-4.125), 0x3f9e2948), + ] { + let mut inputs = vec![Value::Float(input)]; + inputs.extend(exponent.map(Value::Float)); + for scope in [super::FunctionScope::Node, super::FunctionScope::ValueProcessor] { + let Value::Float(value) = scoped_operation(scope, op, &inputs, false) else { panic!("expected a scalar") }; + assert_eq!(value.to_bits(), bits, "{op}({input}, {exponent:?})"); + } + } +} + +#[test] +fn uniform_square_root_clears_negative_and_subnormal_lanes() { + for scope in [super::FunctionScope::Node, super::FunctionScope::ValueProcessor, super::FunctionScope::FxMap] { + let input = Value::Float4([-0.25, -0.0, f32::from_bits(1), 1.375]); + let Value::Float4(result) = scoped_operation(scope, "sqrt", &[input], false) else { panic!("expected four components") }; + assert_eq!(result.map(f32::to_bits), [0, 0, 0, 1.375_f32.sqrt().to_bits()], "{scope:?}"); + assert_eq!(scoped_operation(scope, "sqrt", &[Value::Float(f32::MIN_POSITIVE)], false), Value::Float(f32::from_bits(0x20000000))); + let special = Value::Float4([f32::NAN, f32::NEG_INFINITY, f32::INFINITY, f32::from_bits(0x3f801000)]); + let Value::Float4(result) = scoped_operation(scope, "sqrt", &[special], false) else { panic!("expected four components") }; + assert_eq!(result.map(f32::to_bits), [0, 0, f32::INFINITY.to_bits(), 0x3f800800]); + let literal = Value::Float4([-1.0, -0.0, f32::from_bits(1), f32::from_bits(0x007fffff)]); + let Value::Float4(result) = scoped_operation(scope, "sqrt", &[literal], true) else { panic!("expected four components") }; + assert_eq!(result.map(f32::to_bits), [0, 0x80000000, 0x1a3504f3, 0x1fffffff]); + } +} + +#[test] +fn runtime_pixel_square_root_normalizes_exponents_and_rounds_halfway_down() { + for (input, expected) in [ + (0x3f801000, 0x3f8007ff), + (0x40300000, 0x3fd44394), + (0x3fe20000, 0x3faa1513), + (0x00800000, 0x20000000), + (0x007fffff, 0), + (0x80000000, 0), + (0xbf800000, 0), + (0x7fc00000, 0), + (0x7f800000, 0x7f800000), + ] { + let Value::Float(value) = pixel_operation("sqrt", &[Value::Float(f32::from_bits(input))], false) else { panic!("expected a scalar") }; + assert_eq!(value.to_bits(), expected, "sqrt({input:08x})"); + } + let x = f32::from_bits(0x3f801000); + assert_eq!(pixel_operation("sqrt", &[Value::Float(x)], true), Value::Float(x.sqrt())); +} + +#[test] +fn runtime_pixel_natural_exponential_reduces_to_a_positive_interval() { + for (input, expected) in [ + (2.0, 0x40ec7325), + (f32::from_bits(0xbf317219), 0x3effffff), + (f32::from_bits(0xc2aeac4f), 0x00800026), + (f32::from_bits(0xc2aeac50), 0), + (f32::from_bits(0x42b17217), 0x7f7fff84), + (f32::from_bits(0x42b17218), 0x7f800000), + ] { + let Value::Float(value) = pixel_operation("exp", &[Value::Float(input)], false) else { panic!("expected a scalar") }; + assert_eq!(value.to_bits(), expected, "exp({input})"); + } + assert_eq!(pixel_operation("pow", &[Value::Float(0.7), Value::Float(4.0)], false), Value::Float(f32::from_bits(0x3e75dccb))); +} + +#[test] +fn uniform_exponential_rounds_each_product_before_adding() { + use super::FunctionScope::{FxMap, Node, ValueProcessor}; + for scope in [Node, ValueProcessor, FxMap] { + for (input, expected) in [(0x3d07db5a, 0x3f845114), (0x3eb3866e, 0x3fb5c18a), (0x3f25a984, 0x3ff47bcc), (0xc2b00000, 0)] { + let Value::Float(value) = scoped_operation(scope, "exp", &[Value::Float(f32::from_bits(input))], false) else { panic!("expected a scalar") }; + assert_eq!(value.to_bits(), expected, "{scope:?} exp({input:08x})"); + } + } + let input = Value::Float(f32::from_bits(0x3d07db5a)); + assert_eq!(pixel_operation("exp", std::slice::from_ref(&input), false), Value::Float(f32::from_bits(0x3f845115))); + for scope in [Node, ValueProcessor, FxMap, super::FunctionScope::PixelProcessor] { + assert_eq!(scoped_operation(scope, "exp", std::slice::from_ref(&input), true), Value::Float(f32::from_bits(0x3f845114))); + } +} + +#[test] +fn uniform_powers_of_two_round_the_fraction_and_limit_the_exponent() { + use super::FunctionScope::{FxMap, Node, PixelProcessor, ValueProcessor}; + for (input, expected) in [ + (-127.5, 0x00800000), + (-126.0, 0x00800000), + (-12.015625, 0x397d3e02), + (-0.125, 0x3f6ac0c3), + (-f32::MIN_POSITIVE, 0x3f7ffff4), + (-f32::from_bits(1), 0x3f800000), + (0.9375, 0x3ff52576), + (16.984375, 0x47fd3e02), + (127.5, 0x7e800000), + ] { + for (scope, literal) in [(Node, false), (ValueProcessor, false), (FxMap, false), (PixelProcessor, true)] { + let result = scoped_operation(scope, "pow2", &[Value::Float(input)], literal); + assert_eq!(result, Value::Float(f32::from_bits(expected)), "{scope:?} pow2({input}), literal={literal}"); + } + } + assert_eq!(pixel_operation("pow2", &[Value::Float(0.9375)], false), Value::Float(f32::from_bits(0x3ff5257e))); + for (input, expected) in [(f32::NAN, 0x00800000), (f32::NEG_INFINITY, 0x00800000), (f32::INFINITY, 0x7e800000)] { + assert_eq!(super::binary_exponential::uniform_exp2(input).to_bits(), expected); + } +} + +#[test] +fn uniform_logarithms_accept_exceptional_intermediate_values() { + for (input, expected) in [(f32::NAN, 0), (f32::NEG_INFINITY, 0), (f32::INFINITY, 0x42b17218)] { + assert_eq!(super::binary_exponential::uniform_ln(input).to_bits(), expected); + } +} + +#[test] +fn runtime_pixel_power_uses_the_natural_logarithm_and_the_sign_of_integer_powers() { + for (base, exponent, expected) in [ + (0.7, 1.0, 0x3f333334), + (0.7, 1.375, 0x3f1cc3e8), + (-0.7, 3.0, 0xbeaf9db5), + (-2.0, -1.0, 0xbf000000), + (-2.0, 0.5, 0), + (0.0, -1.0, 0), + (0.0, 0.0, 0), + (f32::MIN_POSITIVE, 1.0, 0x00800026), + ] { + let Value::Float(value) = pixel_operation("pow", &[Value::Float(base), Value::Float(exponent)], false) else { panic!("expected a scalar") }; + assert_eq!(value.to_bits(), expected, "{base}^{exponent}"); + } +} + +#[test] +fn runtime_pixel_logarithms_and_powers_of_two() { + for (op, input, expected) in [ + ("log2", 0.5, 0xbf7ffffe), + ("log2", 0.7, 0xbf03bb10), + ("log2", 1.0, 0), + ("log2", f32::MIN_POSITIVE, 0xc2fbffff), + ("log", 0.5, 0xbf317217), + ("pow2", -0.5, 0x3f3504f2), + ("pow2", 0.5, 0x3fb504f3), + ("pow2", 1.375, 0x4025fed7), + ("pow2", -126.0, 0x00800000), + ("pow2", -127.0, 0), + ("pow2", 128.0, 0x7f800000), + ] { + let Value::Float(value) = pixel_operation(op, &[Value::Float(input)], false) else { panic!("expected a scalar") }; + assert_eq!(value.to_bits(), expected, "{op}({input})"); + } + for scope in [super::FunctionScope::Node, super::FunctionScope::ValueProcessor, super::FunctionScope::FxMap] { + assert_eq!(scoped_operation(scope, "log2", &[Value::Float(0.5)], false), Value::Float(-1.0)); + } + assert_eq!(pixel_operation("log2", &[Value::Float(0.5)], true), Value::Float(-1.0)); +} + +#[test] +fn runtime_pixel_sine_and_cosine_reduce_the_phase_before_interpolation() { + use std::f32::consts::{FRAC_PI_4, TAU}; + + for (angle, sine, cosine) in [ + (-0.0, 0x80000000, 0x3f800000), + (0.625, 0x3f15c8eb, 0x3f4f9b48), + (-FRAC_PI_4, 0xbf3504f3, 0x3f3504f2), + (TAU, 0x80000000, 0x3f800000), + (f32::from_bits(0xc96df2ae), 0x3e98c108, 0x3f74574d), + ] { + for (op, expected) in [("sin", sine), ("cos", cosine)] { + let Value::Float(result) = pixel_operation(op, &[Value::Float(angle)], false) else { panic!("expected a scalar") }; + assert_eq!(result.to_bits(), expected, "{op}({angle})"); + } + } + assert_eq!(pixel_operation("sin", &[Value::Float(0.625)], true), Value::Float(f32::from_bits(0x3f15c8ef))); + assert_eq!(pixel_operation("cos", &[Value::Float(0.625)], true), Value::Float(f32::from_bits(0x3f4f9b47))); +} + +#[test] +fn runtime_pixel_cartesian_multiplies_the_radius_by_each_quarter_wave() { + for (radius, angle, expected) in [ + (-1.25, std::f32::consts::FRAC_PI_4, [0xbf62462e, 0xbf624630]), + (0.375, -0.0, [0x3ec00000, 0x80000000]), + (0.375, std::f32::consts::FRAC_PI_2, [0, 0x3ec00000]), + ] { + let result = pixel_operation("cartesian", &[Value::Float(radius), Value::Float(angle)], false); + let Value::Float2(xy) = result else { panic!("expected a coordinate") }; + assert_eq!(xy.map(f32::to_bits), expected); + } + let result = pixel_operation("cartesian", &[Value::Float(0.875), Value::Float(0.625)], true); + let Value::Float2(xy) = result else { panic!("expected a coordinate") }; + assert_eq!(xy.map(f32::to_bits), [0x3f35a7de, 0x3f030fd1]); +} + +#[test] +fn runtime_pixel_tangent_uses_the_pixel_sine_cosine_and_reciprocal() { + for (angle, expected) in [(0x3db7cb5d, 0x3db84a0d), (0xc094d5bd, 0xc18258bb), (0x412febe1, 0x450051c9), (0x4453660e, 0x3f0de743)] { + let Value::Float(value) = pixel_operation("tan", &[Value::Float(f32::from_bits(angle))], false) else { panic!("expected a scalar") }; + assert_eq!(value.to_bits(), expected); + } + for scope in [super::FunctionScope::Node, super::FunctionScope::ValueProcessor, super::FunctionScope::FxMap] { + assert_eq!(scoped_operation(scope, "tan", &[Value::Float(0.625)], false), Value::Float(f32::from_bits(0x3f38b30b))); + } + let literal = Value::Float(f32::from_bits(0x3d07db5a)); + assert_eq!(pixel_operation("tan", &[literal], true), Value::Float(f32::from_bits(0x3d07e81c))); +} + +#[test] +fn parameter_and_value_angles_fold_the_phase_before_the_polynomial() { + use super::FunctionScope::{Node, ValueProcessor}; + for scope in [Node, ValueProcessor] { + for (angle, sine, cosine) in [ + (0.625, 0x3f15c8f2, 0x3f4f9b7a), + (-std::f32::consts::FRAC_PI_4, 0xbf350503, 0x3f350503), + (1e-7, 0x34490fdb, 0x3f800000), + (1e9, 0xbf800000, 0xbf800000), + ] { + for (op, expected) in [("sin", sine), ("cos", cosine)] { + let Value::Float(v) = scoped_operation(scope, op, &[Value::Float(angle)], false) else { panic!("expected a scalar") }; + assert_eq!(v.to_bits(), expected, "{scope:?} {op}({angle})"); + } + } + assert_eq!(scoped_operation(scope, "sin", &[Value::Float(0.625)], true), Value::Float(f32::from_bits(0x3f15c8ef))); + } +} + +#[test] +fn pattern_angles_and_uniform_cartesian_use_the_same_components() { + use super::FunctionScope::{FxMap, Node, ValueProcessor}; + for scope in [Node, ValueProcessor, FxMap] { + let angle = Value::Float(0.625); + assert_eq!(scoped_operation(scope, "cos", std::slice::from_ref(&angle), false), Value::Float(f32::from_bits(0x3f4f9b7a))); + let Value::Float2(result) = scoped_operation(scope, "cartesian", &[Value::Float(0.875), angle], false) else { panic!("expected a coordinate") }; + assert_eq!(result.map(f32::to_bits), [0x3f35a80b, 0x3f030fd4]); + } +} + +#[test] +fn fixed_pixel_clipping_preserves_the_live_quotient_precision() { + let rounded = 0x3b9a_ff00; + let contracted = 0x3b9a_ff02; + let definition = crate::find("pixel_processor").unwrap(); + for (control, tiling, expected) in [ + ("tiling", 0, rounded), + ("tiling", 1, contracted), + ("tiling", 2, rounded), + ("tiling", 3, contracted), + ("literal", 0, contracted), + ("parameter", 3, rounded), + ] { + let variables = BTreeMap::from([ + ("numerator".into(), Value::Float(f32::from_bits(0xbeb2_0000))), + ("width".into(), Value::Float(f32::from_bits(0x3f33_b333))), + ("clip".into(), Value::Bool(false)), + ("$tiling".into(), Value::Int(tiling)), + ]); + let mut graph = FunctionGraph::default(); + let [n, d] = ["numerator", "width"].map(|name| graph.add("get_float1", &[], Some(Value::Text(name.into())))); + let q = graph.add("div", &[n, d], None); + let half = graph.add_constant(Value::Float(0.5)); + let coordinate = graph.add("add", &[q, half], None); + let magnitude = graph.add("abs", &[q], None); + let outside = graph.add("gt", &[magnitude, half], None); + let clip = match control { + "tiling" => { + let mask = graph.add("get_integer1", &[], Some(Value::Text("$tiling".into()))); + let two = graph.add_constant(Value::Int(2)); + let zero = graph.add_constant(Value::Int(0)); + let horizontal = graph.add("mod", &[mask, two], None); + graph.add("eq", &[horizontal, zero], None) + } + "literal" => graph.add_constant(Value::Bool(false)), + _ => graph.add("get_bool", &[], Some(Value::Text("clip".into()))), + }; + let condition = graph.add("and", &[outside, clip], None); + graph.output = Some(graph.add("ifelse", &[condition, half, coordinate], None)); + let params = crate::resolve_params( + definition, + &BTreeMap::from([("function".into(), Value::Function(Box::new(graph))), ("color_mode".into(), Value::Bool(false))]), + ); + let context = crate::CookContext { + w: 1, + h: 1, + seed: 0, + tile: true, + format: materialcraft_core::OutputFormat::F32, + inputs: &[], + input_formats: &[], + resource: &|_| None, + params: ¶ms, + vars: &variables, + }; + let image = (definition.cook)(&context).unwrap().remove(0); + assert_eq!(image.get_gray(0, 0, false).to_bits(), expected, "{control}, tiling {tiling}"); + } +} + +#[test] +fn a_swizzle_of_a_quotient_keeps_the_other_vector_components_available_for_a_sum() { + for (numerator, divisor, offset, expected) in [ + ( + [0x3ef8_f8f9, 0x3f59_d9da, 0x3e58_d8d9], + [0x3ee6_e6e7, 0x3ee8_e8e9, 0x3eec_eced], + [0.0, 0.0, -0.5], + [0x3f8a_0474, 0x3fef_72c2, 0xbd2d_8f2f, 0x3f8a_0474], + ), + ( + [0x3f74_c9cf, 0x3fe6_626a, 0x3f47_c930], + [0x3fe6_626a, 0x3f47_c930, 0x3fcf_e21a], + [-0.375, 0.3125, -0.5], + [0x3e20_02c4, 0x4027_9aa4, 0xbc9f_8b65, 0x3f08_00b1], + ), + ] { + let variables = BTreeMap::from([("a".into(), Value::Float3(numerator.map(f32::from_bits))), ("b".into(), Value::Float3(divisor.map(f32::from_bits)))]); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + image_formats: &[], + position: [0.5; 2], + size: [1.0; 2], + images: &[], + tile: true, + variables: &variables, + }; + let mut graph = FunctionGraph::default(); + let [a, b] = ["a", "b"].map(|name| graph.add("get_float3", &[], Some(Value::Text(name.into())))); + let ratio = graph.add("div", &[a, b], None); + let offset = graph.add_constant(Value::Float3(offset)); + let shifted = graph.add("add", &[ratio, offset], None); + let red = graph.add("swizzle1", &[ratio], Some(Value::Int(0))); + graph.output = Some(graph.add("vector4", &[shifted, red], None)); + let actual = compile(&graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(actual, Value::Float4(expected.map(f32::from_bits))); + } +} + +#[test] +fn pixel_quotient_sums_and_second_interpolation_operands_contract() { + let values = [0x4044_ca77, 0x4077_425b, 0xbf00_bb3e, 0x4029_426b].map(|v| Value::Float(f32::from_bits(v))); + let variables = ["a", "b", "c", "t"].into_iter().map(str::to_owned).zip(values).collect(); + let context = EvaluationContext { + image_formats: &[], + scope: super::FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [1.0; 2], + images: &[], + tile: true, + variables: &variables, + }; + let mut graph = FunctionGraph::default(); + let [a, b, c, t] = ["a", "b", "c", "t"].map(|name| graph.add("get_float1", &[], Some(Value::Text(name.into())))); + let quotient = graph.add("div", &[a, b], None); + let product = graph.add("mul", &[a, b], None); + let pixel = |graph: &FunctionGraph| compile(graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + for (op, inputs, bits) in [ + ("add", &[quotient, c][..], 0x3e96_0845), + ("sub", &[quotient, c], 0x3fa6_3d4f), + ("sub", &[c, quotient], 0xbfa6_3d4f), + ("lerp", &[c, quotient, t], 0x403b_a465), + ("lerp", &[c, product, t], 0x4200_fa51), + ] { + graph.output = Some(graph.add(op, inputs, None)); + assert_eq!(pixel(&graph), Value::Float(f32::from_bits(bits))); + } + let blend = graph.add("lerp", &[c, quotient, t], None); + graph.output = Some(graph.add("vector2", &[quotient, blend], None)); + assert_eq!(pixel(&graph), Value::Float2([0x3f4b_bf61, 0x403b_a467].map(f32::from_bits))); +} + +#[test] +fn pixel_interpolation_contracts_only_unobserved_product_lanes_in_its_second_endpoint() { + let sample = [0xbed0_b7e6, 0x3ee9_4b78, 0xbf01_df0b, 0xbf9a_729d].map(f32::from_bits); + let variables = BTreeMap::from([("sample".into(), Value::Float4(sample))]); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + image_formats: &[], + position: [0.5; 2], + size: [1.0; 2], + images: &[], + tile: true, + variables: &variables, + }; + let pixel = |graph: &FunctionGraph| compile(graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + let mut graph = FunctionGraph::default(); + let sample = graph.add("get_float4", &[], Some(Value::Text("sample".into()))); + let first = graph.add("swizzle4", &[sample], Some(Value::Int4([2, 0, 3, 1]))); + let rgb = graph.add("swizzle3", &[sample], Some(Value::Int3([0, 1, 2]))); + let gain = graph.add("swizzle1", &[sample], Some(Value::Int(3))); + let weight = graph.add("swizzle1", &[sample], Some(Value::Int(1))); + let product = graph.add("mulscalar", &[rgb, gain], None); + let alpha = graph.add_constant(Value::Float(0.625)); + let last = graph.add("vector4", &[product, alpha], None); + let mix = graph.add("lerp", &[first, last, weight], None); + graph.output = Some(mix); + assert_eq!(pixel(&graph), Value::Float4([0xbd55_1682, 0xbef1_e18c, 0xbec1_7c27, 0x3f08_66b4].map(f32::from_bits))); + + let mixed_rgb = graph.add("swizzle3", &[mix], Some(Value::Int3([0, 1, 2]))); + let blue = graph.add("swizzle1", &[product], Some(Value::Int(2))); + graph.output = Some(graph.add("vector4", &[mixed_rgb, blue], None)); + assert_eq!(pixel(&graph), Value::Float4([0xbd55_1682, 0xbef1_e18c, 0xbec1_7c28, 0x3f1c_b4a3].map(f32::from_bits))); + + graph.output = Some(graph.add("add", &[mix, last], None)); + assert_eq!(pixel(&graph), Value::Float4([0x3ee1_3554, 0xbf82_d84f, 0x3e6f_da3f, 0x3f94_335a].map(f32::from_bits))); + + graph.output = Some(graph.add("lerp", &[last, first, weight], None)); + assert_eq!(pixel(&graph), Value::Float4([0x3d15_e6f2, 0xbef8_560b, 0xbe5d_ca0b, 0x3f0c_3f08].map(f32::from_bits))); +} + +#[test] +fn pixel_sums_retain_assigned_factors_until_a_component_is_observed() { + let sample = [0x3ef4_615d, 0xbf0c_f4e5, 0x3f25_886e, 0xbfbe_1bf6].map(f32::from_bits); + let variables = BTreeMap::from([("sample".into(), Value::Float4(sample))]); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + image_formats: &[], + position: [0.5; 2], + size: [1.0; 2], + images: &[], + tile: false, + variables: &variables, + }; + let pixel = |graph: &FunctionGraph| compile(graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + let mut graph = FunctionGraph::default(); + let sample = graph.add("get_float4", &[], Some(Value::Text("sample".into()))); + let direction = graph.add("swizzle4", &[sample], Some(Value::Int4([2, 0, 1, 3]))); + let scale = graph.add("swizzle1", &[sample], Some(Value::Int(3))); + let origin = graph.add("swizzle4", &[sample], Some(Value::Int4([1, 2, 3, 0]))); + let product = graph.add("mulscalar", &[direction, scale], None); + let stride = || Some(Value::Text("stride".into())); + let assign = graph.add("set", &[product], stride()); + let mut position = origin; + for expected in [[0xbfc1_67c9, 0xbd7f_2862, 0xbf2a_dd9e, 0x402b_b9b0], [0xc01e_2a90, 0xbf45_6d7a, 0x3e19_f2c2, 0x409c_739a]] { + let step = graph.add("get_float4", &[], stride()); + position = graph.add("add", &[position, step], None); + graph.output = Some(graph.add("sequence", &[assign, position], None)); + assert_eq!(pixel(&graph), Value::Float4(expected.map(f32::from_bits))); + } + let rgb = graph.add("swizzle3", &[position], Some(Value::Int3([0, 1, 2]))); + let step = graph.add("get_float4", &[], stride()); + let blue = graph.add("swizzle1", &[step], Some(Value::Int(2))); + let observed = graph.add("vector4", &[rgb, blue], None); + graph.output = Some(graph.add("sequence", &[assign, observed], None)); + assert_eq!(pixel(&graph), Value::Float4([0xc01e_2a90, 0xbf45_6d7a, 0x3e19_f2c0, 0x3f51_5a4e].map(f32::from_bits))); +} + +#[derive(Clone, Copy)] +enum StepRead { + Sum, + Blue, + BeforeWrite, + AfterWrite, + Copy, + CopyBlue, +} + +fn called_pixel_step(sample: [f32; 4], wired: bool, guard: Option, read: StepRead) -> Value { + let variables = BTreeMap::from([("field".into(), Value::Float4(sample))]); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + image_formats: &[], + position: [0.5; 2], + size: [1.0; 2], + images: &[], + tile: false, + variables: &variables, + }; + let mut graph = FunctionGraph::default(); + let field = graph.add("get_float4", &[], Some(Value::Text("field".into()))); + let dir = graph.add("swizzle4", &[field], Some(Value::Int4([2, 0, 1, 3]))); + let gain = graph.add("swizzle1", &[field], Some(Value::Int(3))); + let pos = graph.add("swizzle4", &[field], Some(Value::Int4([1, 2, 3, 0]))); + let product = graph.add("mulscalar", &[dir, gain], None); + let set = graph.add("set", &[product], Some(Value::Text("stride".into()))); + let setup = if let Some(run) = guard { + let condition = graph.add_constant(Value::Bool(run)); + let zero = graph.add_constant(Value::Float4([0.0; 4])); + graph.add("ifelse", &[condition, set, zero], None) + } else { + set + }; + let mut args = vec![("origin", pos)]; + if wired { + args.push(("step", graph.add("get_float4", &[], Some(Value::Text("stride".into()))))); + } + let mut body = FunctionGraph::default(); + let origin = body.add("get_float4", &[], Some(Value::Text("origin".into()))); + let step = body.add("get_float4", &[], Some(Value::Text(if wired { "step" } else { "stride" }.into()))); + let sum = body.add("add", &[origin, step], None); + body.output = Some(match read { + StepRead::Sum | StepRead::Blue => sum, + StepRead::Copy | StepRead::CopyBlue => { + let copy = body.add("set", &[step], Some(Value::Text("saved_step".into()))); + let replace = body.add("set", &[origin], Some(Value::Text("stride".into()))); + let effects = body.add("sequence", &[copy, replace], None); + let saved = body.add("get_float4", &[], Some(Value::Text("saved_step".into()))); + let advance = body.add("add", &[origin, saved], None); + body.add("sequence", &[effects, advance], None) + } + StepRead::BeforeWrite => { + let answer = body.add("set", &[sum], Some(Value::Text("answer".into()))); + let write = body.add("set", &[origin], Some(Value::Text("stride".into()))); + let effects = body.add("sequence", &[answer, write], None); + let saved = body.add("get_float4", &[], Some(Value::Text("answer".into()))); + body.add("sequence", &[effects, saved], None) + } + StepRead::AfterWrite => { + let write = body.add("set", &[origin], Some(Value::Text("stride".into()))); + body.add("sequence", &[write, sum], None) + } + }); + let call = graph.add("instance", &[], None); + let node = graph.nodes.last_mut().unwrap(); + node.instance = Some(materialcraft_core::GraphInstance { + label: String::new(), + package: String::new(), + graph: "advance".into(), + inputs: args.iter().map(|(name, _)| materialcraft_core::GraphPort { identifier: (*name).into(), type_code: 2048 }).collect(), + outputs: vec![materialcraft_core::GraphPort { identifier: "output".into(), type_code: 2048 }], + defaults: args.iter().map(|(name, _)| ((*name).into(), Value::Float4([0.0; 4]))).collect(), + }); + node.inputs = args.iter().map(|(_, id)| Some(*id)).collect(); + node.source = Some(Ok(std::sync::Arc::new(body))); + let result = if matches!(read, StepRead::Blue | StepRead::CopyBlue) { + let color = graph.add("swizzle3", &[call], Some(Value::Int3([0, 1, 2]))); + let name = if matches!(read, StepRead::CopyBlue) { "saved_step" } else { "stride" }; + let stored = graph.add("get_float4", &[], Some(Value::Text(name.into()))); + let blue = graph.add("swizzle1", &[stored], Some(Value::Int(2))); + graph.add("vector4", &[color, blue], None) + } else { + call + }; + graph.output = Some(graph.add("sequence", &[setup, result], None)); + compile(&graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap() +} + +#[test] +fn called_pixel_sums_use_the_factors_of_a_free_or_wired_step() { + let sample = [0x3ef4_615d, 0xbf0c_f4e5, 0x3f25_886e, 0xbfbe_1bf6].map(f32::from_bits); + for wired in [false, true] { + assert_eq!( + called_pixel_step(sample, wired, None, StepRead::Sum), + Value::Float4([0xbfc1_67c9, 0xbd7f_2862, 0xbf2a_dd9e, 0x402b_b9b0].map(f32::from_bits)) + ); + assert_eq!(called_pixel_step(sample, wired, Some(false), StepRead::Sum), Value::Float4([sample[1], sample[2], sample[3], sample[0]])); + } +} + +#[test] +fn called_pixel_sums_round_the_observed_components_of_the_stored_step() { + let sample = [0xbed0_b7e6, 0x3ee9_4b78, 0xbf01_df0b, 0xbf9a_729d].map(f32::from_bits); + let expected = Value::Float4([0x3f88_ad30, 0xbc7c_be30, 0xbfe0_d28a, 0xbf0c_bfd9].map(f32::from_bits)); + for wired in [false, true] { + assert_eq!(called_pixel_step(sample, wired, None, StepRead::Blue), expected, "wired {wired}"); + } +} + +#[test] +fn called_pixel_sums_follow_assignments_in_execution_order() { + let sample = [0xbed0_b7e6, 0x3ee9_4b78, 0xbf01_df0b, 0xbf9a_729d].map(f32::from_bits); + let sum = Value::Float4([0x3f88_ad30, 0xbc7c_be30, 0xbfe0_d289, 0x3f86_2e37].map(f32::from_bits)); + for wired in [false, true] { + assert_eq!(called_pixel_step(sample, wired, None, StepRead::BeforeWrite), sum, "before write, wired {wired}"); + assert_eq!(called_pixel_step(sample, wired, Some(true), StepRead::Sum), sum, "executed write, wired {wired}"); + } + let origin = [sample[1], sample[2], sample[3], sample[0]]; + assert_eq!(called_pixel_step(sample, false, None, StepRead::AfterWrite), Value::Float4(origin.map(|v| v + v))); +} + +#[test] +fn called_pixel_sums_keep_factors_through_a_copied_step() { + let sample = [0xbed0_b7e6, 0x3ee9_4b78, 0xbf01_df0b, 0xbf9a_729d].map(f32::from_bits); + for (read, expected) in + [(StepRead::Copy, [0x3f88_ad30, 0xbc7c_be30, 0xbfe0_d289, 0x3f86_2e37]), (StepRead::CopyBlue, [0x3f88_ad30, 0xbc7c_be30, 0xbfe0_d28a, 0xbf0c_bfd9])] + { + assert_eq!(called_pixel_step(sample, false, None, read), Value::Float4(expected.map(f32::from_bits))); + } +} + +#[test] +fn pixel_product_sums_round_once_unless_the_product_is_also_read() { + let values = [0x3fe34b19, 0x400d3c6f, 0xc0732711, 0x3f9665e4].map(|bits| Value::Float(f32::from_bits(bits))); + let variables: BTreeMap<_, _> = ["a", "b", "c", "d"].into_iter().map(str::to_owned).zip(values).collect(); + let context = EvaluationContext { + image_formats: &[], + scope: super::FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [1.0; 2], + images: &[], + tile: true, + variables: &variables, + }; + let mut graph = FunctionGraph::default(); + let [a, b, c, d] = ["a", "b", "c", "d"].map(|name| graph.add("get_float1", &[], Some(Value::Text(name.into())))); + let product = graph.add("mul", &[a, b], None); + let other = graph.add("mul", &[c, d], None); + let pixel = |graph: &FunctionGraph| compile(graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + + for (op, inputs, bits) in [ + ("add", [product, c], 0x3df49f1b), + ("add", [c, product], 0x3df49f1b), + ("sub", [product, c], 0x40f6f98d), + ("sub", [c, product], 0xc0f6f98d), + ("add", [product, other], 0xbf0b9d31), + ] { + graph.output = Some(graph.add(op, &inputs, None)); + assert_eq!(pixel(&graph), Value::Float(f32::from_bits(bits)), "{op} {inputs:?}"); + } + + let sum = graph.add("add", &[product, c], None); + graph.output = Some(graph.add("vector2", &[product, sum], None)); + assert_eq!(pixel(&graph), Value::Float2([0x407acc0a, 0x3df49f20].map(f32::from_bits))); + let context = EvaluationContext { image_formats: &[], scope: super::FunctionScope::Node, ..context }; + graph.output = Some(sum); + assert_eq!(compile(&graph, 0).unwrap().evaluate(&context, &mut EvaluationState::default()).unwrap(), Value::Float(f32::from_bits(0x3df49f20))); +} + +#[test] +fn adding_selected_quotient_lanes_contracts_the_left_unshared_lane() { + let variables = BTreeMap::new(); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + position: [0.15625, 0.03125], + size: [16.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + let mut graph = FunctionGraph::default(); + let position = graph.add("get_float2", &[], Some(Value::Text("$pos".into()))); + let divisor = graph.add_constant(Value::Float2([3.625, -0.71875])); + let quotient = graph.add("div", &[position, divisor], None); + let x = graph.add("swizzle1", &[quotient], Some(Value::Int(0))); + let y = graph.add("swizzle1", &[quotient], Some(Value::Int(1))); + let pixel = |graph: &FunctionGraph| compile(graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + for (terms, expected) in [([x, y], 0xb9c4_82a0), ([y, x], 0xb9c4_8280)] { + graph.output = Some(graph.add("add", &terms, None)); + assert_eq!(pixel(&graph), Value::Float(f32::from_bits(expected))); + } + let sum = graph.add("add", &[x, y], None); + for (shared, expected, rounded) in [(x, 0xb9c4_8280, 0.15625f32 / 3.625), (y, 0xb9c4_82a0, 0.03125f32 / -0.71875)] { + graph.output = Some(graph.add("vector2", &[sum, shared], None)); + assert_eq!(pixel(&graph), Value::Float2([f32::from_bits(expected), rounded])); + } +} + +#[test] +fn subtracting_selected_products_keeps_the_operand_signs() { + let variables = BTreeMap::new(); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + position: [0.15625, 0.03125], + size: [16.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + let mut graph = FunctionGraph::default(); + let position = graph.add("get_float2", &[], Some(Value::Text("$pos".into()))); + let factors = graph.add_constant(Value::Float2([3.6123412, -0.7187911])); + let product = graph.add("mul", &[position, factors], None); + let x = graph.add("swizzle1", &[product], Some(Value::Int(0))); + let y = graph.add("swizzle1", &[product], Some(Value::Int(1))); + for (terms, expected) in [([x, y], 0x3f16_3e75), ([y, x], 0xbf16_3e76), ([x, x], 0)] { + graph.output = Some(graph.add("sub", &terms, None)); + let pixel = compile(&graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(pixel, Value::Float(f32::from_bits(expected))); + } +} + +#[test] +fn pixel_product_sum_through_packed_lanes_and_calls_keeps_other_reads() { + let [a, b, c] = [0xbfd8_e681, 0xc03e_5cec, 0xc05f_9255].map(f32::from_bits); + let variables = ["a", "b", "c"].into_iter().map(str::to_owned).zip([a, b, c].map(Value::Float)).collect(); + let context = EvaluationContext { + image_formats: &[], + scope: super::FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [1.0; 2], + images: &[], + tile: true, + variables: &variables, + }; + let pixel = |graph: &FunctionGraph| compile(graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + let mut draws = FunctionGraph::default(); + let one = draws.add_constant(Value::Float(1.0)); + let first = draws.add("rand", &[one], None); + let second = draws.add("rand", &[one], None); + draws.output = Some(draws.add("vector2", &[first, second], None)); + let Value::Float2([first_draw, second_draw]) = pixel(&draws) else { panic!("expected two random draws") }; + assert_ne!(first_draw, second_draw); + + for called in [false, true] { + let mut graph = FunctionGraph::default(); + let [left, right] = ["a", "b"].map(|name| graph.add("get_float1", &[], Some(Value::Text(name.into())))); + let product = graph.add("mul", &[left, right], None); + let one = graph.add_constant(Value::Float(1.0)); + let draw = graph.add("rand", &[one], None); + let mut pair = graph.add("vector2", &[product, draw], None); + if called { + graph.output = Some(pair); + let body = std::mem::take(&mut graph); + pair = graph.add("instance", &[], None); + let node = graph.nodes.last_mut().unwrap(); + node.instance = Some(materialcraft_core::GraphInstance { + label: String::new(), + package: String::new(), + graph: "pair".into(), + inputs: Vec::new(), + outputs: Vec::new(), + defaults: BTreeMap::new(), + }); + node.source = Some(Ok(std::sync::Arc::new(body))); + } + let x = graph.add("swizzle1", &[pair], Some(Value::Int(0))); + let y = graph.add("swizzle1", &[pair], Some(Value::Int(1))); + let addend = graph.add("get_float1", &[], Some(Value::Text("c".into()))); + for args in [[x, addend], [addend, x]] { + let sum = graph.add("add", &args, None); + graph.output = Some(graph.add("vector2", &[sum, y], None)); + assert_eq!(pixel(&graph), Value::Float2([f32::from_bits(0x3fc6_0290), first_draw])); + graph.output = Some(graph.add("vector2", &[sum, x], None)); + assert_eq!(pixel(&graph), Value::Float2([f32::from_bits(0x3fc6_0292), a * b])); + let one = graph.add_constant(Value::Float(1.0)); + let next = graph.add("rand", &[one], None); + graph.output = Some(graph.add("vector2", &[sum, next], None)); + assert_eq!(pixel(&graph), Value::Float2([f32::from_bits(0x3fc6_0290), second_draw])); + } + } +} + +#[test] +fn a_quotient_can_round_with_an_intermediate_sum_in_a_called_function() { + let variables = BTreeMap::from([("dot".into(), Value::Float(f32::from_bits(0x3f01187e))), ("width".into(), Value::Float(0.6875))]); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [1.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + + let mut inner = FunctionGraph::default(); + let q = inner.add("get_float1", &[], Some(Value::Text("q".into()))); + let one = inner.add_constant(Value::Float(1.0)); + let sum = inner.add("add", &[q, one], None); + let two = inner.add_constant(Value::Float(2.0)); + inner.output = Some(inner.add("div", &[sum, two], None)); + + let mut graph = FunctionGraph::default(); + let [dot, width] = ["dot", "width"].map(|name| graph.add("get_float1", &[], Some(Value::Text(name.into())))); + let quotient = graph.add("div", &[dot, width], None); + let result = graph.add("instance", &[quotient], None); + let call = graph.nodes.last_mut().unwrap(); + call.instance = Some(materialcraft_core::GraphInstance { + label: String::new(), + package: String::new(), + graph: "half_range".into(), + inputs: vec![materialcraft_core::GraphPort { identifier: "q".into(), type_code: 256 }], + outputs: Vec::new(), + defaults: BTreeMap::from([("q".into(), Value::Float(0.0))]), + }); + call.source = Some(Ok(std::sync::Arc::new(inner))); + let pixel = |g: &FunctionGraph| compile(g, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + graph.output = Some(result); + assert_eq!(pixel(&graph), Value::Float(f32::from_bits(0x3f5de345))); + graph.output = Some(graph.add("vector2", &[result, quotient], None)); + assert_eq!(pixel(&graph), Value::Float2([0x3f5de344, 0x3f3bc689].map(f32::from_bits))); +} + +#[test] +fn a_pixel_quotient_rounds_with_the_subtraction_in_a_called_function() { + let names = ["offset", "amount"]; + let mut inner = FunctionGraph::default(); + let [offset, amount] = names.map(|name| inner.add("get_float1", &[], Some(Value::Text(name.into())))); + inner.output = Some(inner.add("sub", &[offset, amount], None)); + + let mut graph = FunctionGraph::default(); + let [x, y, z] = ["x", "y", "z"].map(|name| graph.add("get_float1", &[], Some(Value::Text(name.into())))); + let quotient = graph.add("div", &[x, y], None); + let result = graph.add("instance", &[z, quotient], None); + let call = graph.nodes.last_mut().unwrap(); + call.instance = Some(materialcraft_core::GraphInstance { + label: String::new(), + package: String::new(), + graph: "difference".into(), + inputs: names.map(|name| materialcraft_core::GraphPort { identifier: name.into(), type_code: 256 }).into(), + outputs: Vec::new(), + defaults: names.into_iter().map(|name| (name.into(), Value::Float(0.0))).collect(), + }); + call.source = Some(Ok(std::sync::Arc::new(inner))); + let variables = ["x", "y", "z"].map(str::to_owned).into_iter().zip([0xc022f465, 0xbfb54d77, 0x3f4cdf41].map(|b| Value::Float(f32::from_bits(b)))).collect(); + let context = EvaluationContext { + image_formats: &[], + scope: super::FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [1.0; 2], + images: &[], + tile: true, + variables: &variables, + }; + let pixel = |g: &FunctionGraph| compile(g, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + graph.output = Some(result); + assert_eq!(pixel(&graph), Value::Float(f32::from_bits(0xbf7f5030))); + graph.output = Some(graph.add("vector2", &[result, quotient], None)); + assert_eq!(pixel(&graph), Value::Float2([0xbf7f502f, 0x3fe617b8].map(f32::from_bits))); +} + +#[test] +fn vector_sums_use_the_unrounded_product_of_each_independently_returned_lane() { + use materialcraft_core::{GraphInstance, GraphPort}; + let mut body = FunctionGraph::default(); + let [left, right] = ["left", "right"].map(|name| body.add("get_float2", &[], Some(Value::Text(name.into())))); + let product = body.add("mul", &[left, right], None); + let side = body.add("get_float1", &[], Some(Value::Text("side".into()))); + let side = body.add("set", &[side], Some(Value::Text("last".into()))); + body.output = Some(body.add("vector3", &[product, side], None)); + let source = std::sync::Arc::new(body); + let interface = GraphInstance { + label: String::new(), + package: String::new(), + graph: "pair".into(), + inputs: [("left", 512), ("right", 512), ("side", 256)].map(|(name, type_code)| GraphPort { identifier: name.into(), type_code }).into(), + outputs: Vec::new(), + defaults: [("left", Value::Float2([0.0; 2])), ("right", Value::Float2([0.0; 2])), ("side", Value::Float(0.0))].map(|(k, v)| (k.into(), v)).into(), + }; + let mut graph = FunctionGraph::default(); + let [r, g, b, a] = ["r", "g", "b", "a"].map(|name| graph.add("get_float1", &[], Some(Value::Text(name.into())))); + let [rg, ba, gr] = [[r, g], [b, a], [g, r]].map(|xy| graph.add("vector2", &xy, None)); + let [first, second] = [[rg, ba, a], [ba, gr, r]].map(|arguments| { + let call = graph.add("instance", &arguments, None); + let node = graph.nodes.last_mut().unwrap(); + node.instance = Some(interface.clone()); + node.source = Some(Ok(source.clone())); + call + }); + let sum = graph.add("add", &[first, second], None); + let variables = ["r", "g", "b", "a"] + .map(str::to_owned) + .into_iter() + .zip([0xc05f3333, 0x40680000, 0x3f600000, 0xbf200000].map(|v| Value::Float(f32::from_bits(v)))) + .collect(); + let context = EvaluationContext { + image_formats: &[], + scope: super::FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [1.0; 2], + images: &[], + tile: true, + variables: &variables, + }; + for (read, lane, expected) in [ + (first, 0, [0x3df66660, 0xbdb00000, 0xc083999a, 0xc0434ccd]), + (second, 0, [0x3df6666c, 0xbdb00000, 0xc083999a, 0x404b0000]), + (first, 2, [0x3df6666c, 0xbdb00000, 0xc083999a, 0xbf200000]), + ] { + let exposed = graph.add("swizzle1", &[read], Some(Value::Int(lane))); + graph.output = Some(graph.add("vector4", &[sum, exposed], None)); + let value = compile(&graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(value, Value::Float4(expected.map(f32::from_bits))); + } +} + +#[test] +fn pixel_sums_contract_negated_products_and_preserve_shared_rounded_addends() { + let values = [0xc0742acf, 0xbf116093, 0x405370ba, 0x3f3eb229].map(|bits| Value::Float(f32::from_bits(bits))); + let variables = ["a", "b", "c", "d"].into_iter().map(str::to_owned).zip(values).collect(); + let context = EvaluationContext { + image_formats: &[], + scope: super::FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [1.0; 2], + images: &[], + tile: true, + variables: &variables, + }; + let mut graph = FunctionGraph::default(); + let [a, b, c, d] = ["a", "b", "c", "d"].map(|name| graph.add("get_float1", &[], Some(Value::Text(name.into())))); + let product = graph.add("mul", &[a, b], None); + let negative = graph.add("neg", &[product], None); + let other = graph.add("mul", &[c, d], None); + let evaluate = |graph: &FunctionGraph| compile(graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + for (op, operands, expected) in [ + ("add", [negative, c], 0x3f9190bd), + ("sub", [negative, c], 0xc0af0c8b), + ("sub", [c, negative], 0x40af0c8b), + ("add", [negative, other], 0x3e96c3a4), + ("sub", [negative, other], 0xc0941496), + ] { + graph.output = Some(graph.add(op, &operands, None)); + assert_eq!(evaluate(&graph), Value::Float(f32::from_bits(expected))); + } + let sum = graph.add("add", &[negative, c], None); + let both = graph.add("add", &[negative, other], None); + graph.output = Some(graph.add("vector2", &[sum, both], None)); + assert_eq!(evaluate(&graph), Value::Float2([0x3f9190bc, 0x3e96c3a2].map(f32::from_bits))); + graph.output = Some(graph.add("vector2", &[negative, sum], None)); + assert_eq!(evaluate(&graph), Value::Float2([0xc00aa85c, 0x3f9190bc].map(f32::from_bits))); +} + +#[test] +fn paired_sums_keep_the_same_product_unrounded() { + let values = [0xbfd8e681, 0xc00ec5b1, 0xc05f9255, 0xc020d2bc].map(|bits| Value::Float(f32::from_bits(bits))); + let variables = ["r", "g", "b", "a"].into_iter().map(str::to_owned).zip(values).collect(); + let context = EvaluationContext { + image_formats: &[], + scope: super::FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [1.0; 2], + images: &[], + tile: true, + variables: &variables, + }; + let mut graph = FunctionGraph::default(); + let [r, g, b, a] = ["r", "g", "b", "a"].map(|name| graph.add("get_float1", &[], Some(Value::Text(name.into())))); + let p = graph.add("mul", &[r, b], None); + let q = graph.add("mul", &[g, a], None); + let sum = graph.add("add", &[p, q], None); + let difference = graph.add("sub", &[q, p], None); + for (order, expected) in [([sum, difference], [0x41386778, 0xbea0a9ae]), ([difference, sum], [0xbea0a9ab, 0x41386779])] { + graph.output = Some(graph.add("vector2", &order, None)); + let actual = compile(&graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(actual, Value::Float2(expected.map(f32::from_bits))); + } +} + +#[test] +fn clamped_and_repeating_uniform_texture_reads_keep_fractional_weights() { + let image = Image::generate(32, 32, Kind::Color, |x, y| { + let channel = |c: u32| ((47 * x + 31 * y + 7 * x * y + 13 + c * (29 + 3 * x)) % 251) as f32 / 255.0; + [channel(0), channel(1), channel(2), 1.0] + }) + .with_integer_sampling(true); + let mut context = EvaluationContext { + scope: super::FunctionScope::FxMap, + position: [0.5; 2], + size: [32.0; 2], + images: &[Some(image)], + image_formats: &[materialcraft_core::OutputFormat::U8], + tile: false, + variables: &BTreeMap::new(), + }; + for (uv, mode, color, gray) in [ + ([-0.125, -0.25], 0, [0x3e868687, 0x3f31b1b2, 0x3e109091, 0x3f800000], 0x3ebb6612), + ([0.71897, 0.39151], 1, [0x3e90e1aa, 0x3f25d28e, 0x3f06f4bc, 0x3f800000], 0x3ef8d016), + ([-0.12, 0.016], 2, [0x3d50d0d2, 0x3e28a8a9, 0x3e8e8e8f, 0x3f800000], 0x3e28a8aa), + ([-0.12, 0.016], 3, [0x3d56ca82, 0x3e2a2716, 0x3e8f4dc4, 0x3f800000], 0x3e2a2715), + ([1.0311, -0.65315], 3, [0x3f57d7d9, 0x3eacacad, 0x3f50d0d2, 0x3f800000], 0x3f2a5500), + ] { + let mut graph = FunctionGraph::default(); + let position = graph.add_constant(Value::Float2(uv)); + for (sampler, expected) in [("samplecol", Value::Float4(color.map(f32::from_bits))), ("samplelum", Value::Float(f32::from_bits(gray)))] { + graph.output = Some(graph.add(sampler, &[position], Some(Value::Int2([0, mode])))); + let program = compile(&graph, 0).unwrap(); + for scope in [super::FunctionScope::FxMap, super::FunctionScope::ValueProcessor] { + context.scope = scope; + let value = program.evaluate(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(value, expected, "{scope:?} {sampler} mode {mode} at {uv:?}"); + } + } + } +} + +#[test] +fn clamped_uniform_filter_keeps_its_fractions_when_all_four_taps_reach_one_corner() { + let edge = [0x406bfbec, 0xbed93e37, 0x405db487, 0x3f800000].map(f32::from_bits); + let image = Image::generate(32, 32, Kind::Color, |x, y| if (x, y) == (31, 0) { edge } else { [0.0; 4] }); + let mut graph = FunctionGraph::default(); + let position = graph.add_constant(Value::Float2([1.0311, -0.65315])); + graph.output = Some(graph.add("samplecol", &[position], Some(Value::Int2([0, 3])))); + let program = compile(&graph, 0).unwrap(); + let images = [Some(image)]; + for scope in [super::FunctionScope::FxMap, super::FunctionScope::ValueProcessor] { + let context = EvaluationContext { + scope, + position: [0.5; 2], + size: [32.0; 2], + images: &images, + image_formats: &[materialcraft_core::OutputFormat::F32], + tile: true, + variables: &BTreeMap::new(), + }; + let value = program.evaluate(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(value.as_vec4().unwrap().map(f32::to_bits), [0x406bfbec, 0xbed93e38, 0x405db488, 0x3f800000]); + } +} + +#[test] +fn pixel_gray_sampler_combines_stored_color_channels_after_reading() { + let mut graph = FunctionGraph::default(); + let position = graph.add_constant(Value::Float2([0.5; 2])); + graph.output = Some(graph.add("samplelum", &[position], Some(Value::Int2([0, 0])))); + let program = compile(&graph, 0).unwrap(); + let rgba = [0x40521096, 0xbfccf206, 0xbfa48635, 0x3f800000].map(f32::from_bits); + for (kind, expected) in [(Kind::Color, 0x3e0717d6), (Kind::Gray, rgba[0].to_bits())] { + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [1.0; 2], + images: &[Some(Image::filled(1, 1, kind, rgba))], + image_formats: &[], + tile: true, + variables: &BTreeMap::new(), + }; + assert_eq!(program.evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(), Value::Float(f32::from_bits(expected))); + } +} + +#[test] +fn clamped_pixel_samplers_select_the_edge_texel_and_filter_along_it() { + let image = Image::generate(8, 4, Kind::Color, |x, y| { + std::array::from_fn(|c| { + let c = c as u32; + let level = (79 * x + 53 * y + 29 * x * y + 17 * c + 11 * x * c + 3) % 251; + (level as f32 - 91.75) / 71.375 + }) + }); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [16.0, 32.0], + images: &[Some(image)], + image_formats: &[materialcraft_core::OutputFormat::F32], + tile: true, + variables: &BTreeMap::new(), + }; + for (mode, uv, color, gray) in [ + (2, [-0.125, 0.25], [0xbf003963, 0xbe868039, 0xbcc8daca, 0x3e5ac9c0], 0xbe86803a), + (3, [-0.125, 0.25], [0xbf5f457e, 0xbf224c37, 0xbecaa5e2, 0xbe2166ac], 0xbf224c38), + (2, [0.3359375, 0.40625], [0xbf7dc221, 0xbee3c13c, 0x3dd0072c, 0x3f25e269], 0xbee3c13c), + (3, [0.3359375, 0.40625], [0xbf160647, 0xbc2fbf85, 0x3f10884b, 0x3f101cb2], 0xbc2fbf80), + (3, [1.3125, -0.375], [0xbf0765c6, 0x3f49c056, 0x4006b99c, 0xbdc1ae67], 0x3f49c056), + ] { + let mut graph = FunctionGraph::default(); + let position = graph.add_constant(Value::Float2(uv)); + for (op, expected) in [("samplecol", Value::Float4(color.map(f32::from_bits))), ("samplelum", Value::Float(f32::from_bits(gray)))] { + graph.output = Some(graph.add(op, &[position], Some(Value::Int2([0, mode])))); + let actual = compile(&graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(actual, expected, "{op} mode {mode} at {uv:?}"); + } + } +} + +#[test] +fn filtered_pixel_reads_flush_single_precision_subnormals_before_and_after_filtering() { + let normal = f32::MIN_POSITIVE; + let subnormal = f32::from_bits(normal.to_bits() - 1); + let left = [subnormal, -subnormal, -normal, normal * 2.0]; + let image = Image::generate(2, 1, Kind::Color, |x, _| if x == 0 { left } else { [normal, -normal, 0.0, subnormal] }); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + position: [0.0; 2], + size: [2.0, 1.0], + images: &[Some(image)], + image_formats: &[materialcraft_core::OutputFormat::F32], + tile: true, + variables: &BTreeMap::new(), + }; + for (filter, u, expected) in [(0, 0.25, left), (1, 0.25, [0.0, -0.0, -normal, normal * 2.0]), (1, 0.5, [0.0, -0.0, -0.0, normal])] { + let mut graph = FunctionGraph::default(); + let uv = graph.add_constant(Value::Float2([u, 0.5])); + graph.output = Some(graph.add("samplecol", &[uv], Some(Value::Int2([0, filter])))); + let value = compile(&graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(value.as_vec4().unwrap().map(f32::to_bits), expected.map(f32::to_bits)); + } +} + +#[test] +fn pixel_dot_rounds_in_channel_order() { + // One sampled texel distinguishes the accumulation orders in all three widths. + let [x, y, z, w] = [0xc07089a0, 0x3fa2fba9, 0xbe30266f, 0xbcf10944].map(f32::from_bits); + for (left, right, dynamic_bits, literal_bits) in [ + (Value::Float2([x, y]), Value::Float2([0.2126, 0.7152]), 0x3de49f4e, 0x3de49f50), + (Value::Float3([x, y, z]), Value::Float3([0.2126, 0.7152, 0.0722]), 0x3dcb2fab, 0x3dcb2fad), + (Value::Float4([x, y, z, w]), Value::Float4([0.2126, 0.7152, 0.0722, -0.39]), 0x3de2afee, 0x3de2aff0), + ] { + let operands = [left, right]; + assert_eq!(pixel_operation("dot", &operands, false), Value::Float(f32::from_bits(dynamic_bits))); + assert_eq!(pixel_operation("dot", &operands, true), Value::Float(f32::from_bits(literal_bits))); + } +} + +#[test] +fn uniform_atan2_rounds_each_term_and_preserves_literal_angles() { + for scope in [super::FunctionScope::Node, super::FunctionScope::ValueProcessor, super::FunctionScope::FxMap] { + for (coordinate, bits) in [ + ([1.0, 0.1316152], 0x3e061f75), + ([1.0, -0.1316152], 0xbe061f75), + ([1.875, 0.057_220_46], 0x3cfa72bc), + ([-0.1316152, 1.0], 0x3fd9d3ca), + ([1.0, 1.0], 0x3f490fe1), + ([-1.0, -0.0], 0x40490fdb), + ([f32::from_bits(0x00400000), f32::MIN_POSITIVE], 0x3fc90fdb), + ([f32::from_bits(0x7f000000), f32::from_bits(0x7e800000)], 0x3eed6346), + ] { + let Value::Float(angle) = scoped_operation(scope, "atan2", &[Value::Float2(coordinate)], false) else { panic!("expected an angle") }; + assert_eq!(angle.to_bits(), bits, "{scope:?} {coordinate:?}"); + } + assert_eq!(scoped_operation(scope, "atan2", &[Value::Float2([1.0, 1.0])], true), Value::Float(std::f32::consts::FRAC_PI_4)); + } + assert_eq!(pixel_operation("atan2", &[Value::Float2([1.0, 0.1316152])], false), Value::Float(f32::from_bits(0x3e061f76))); +} + +#[test] +fn pixel_atan2_reconstructs_the_quadrant_from_the_runtime_ratio() { + for (coordinate, bits) in [ + ([1.0, 1.0], 0x3f490fe1), + ([-1.0, 1.0], 0x4016cbe3), + ([-1.0, -1.0], 0xc016cbe3), + ([1.0, -1.0], 0xbf490fe1), + ([f32::from_bits(0xc07089a0), f32::from_bits(0x3fa2fba9)], 0x40342917), + ([-1.0, -0.0], 0x40490fdb), + ([-0.0, 0.0], 0), + ] { + let Value::Float(angle) = pixel_operation("atan2", &[Value::Float2(coordinate)], false) else { panic!("expected an angle") }; + assert_eq!(angle.to_bits(), bits, "{coordinate:?}"); + } + assert_eq!(pixel_operation("atan2", &[Value::Float2([1.0, 1.0])], true), Value::Float(std::f32::consts::FRAC_PI_4)); +} + +#[test] +fn a_literal_unit_interval_saturates_an_undefined_pixel_quotient() { + let mut graph = FunctionGraph::default(); + let variable = graph.add("get_float1", &[], Some(Value::Text("zero".into()))); + let undefined = graph.add("div", &[variable, variable], None); + let zero = graph.add_constant(Value::Float(0.0)); + let one = graph.add_constant(Value::Float(1.0)); + let upper = graph.add("min", &[undefined, one], None); + let clamp = graph.add("max", &[zero, upper], None); + graph.output = Some(clamp); + let variables = BTreeMap::from([("zero".into(), Value::Float(0.0))]); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [1.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + let pixel = |g: &FunctionGraph| compile(g, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(pixel(&graph), Value::Float(0.0)); + graph.output = Some(graph.add("vector2", &[clamp, upper], None)); + assert_eq!(pixel(&graph), Value::Float2([0.0, 1.0])); + + let literal_undefined = graph.add("div", &[zero, zero], None); + let upper = graph.add("min", &[one, literal_undefined], None); + let negative_zero = graph.add_constant(Value::Float(-0.0)); + graph.output = Some(graph.add("max", &[upper, negative_zero], None)); + assert!(matches!(pixel(&graph), Value::Float(value) if value.to_bits() == 0)); + + let fractional = graph.add_constant(Value::Float(0.75)); + let upper = graph.add("min", &[undefined, fractional], None); + graph.output = Some(graph.add("max", &[zero, upper], None)); + assert_eq!(pixel(&graph), Value::Float(0.75)); + let upper = graph.add("min", &[undefined, one], None); + graph.output = Some(graph.add("max", &[variable, upper], None)); + assert_eq!(pixel(&graph), Value::Float(1.0)); +} + +#[test] +fn pixel_division_multiplies_by_the_reciprocal() { + let operands = [Value::Float(-2.7353475), Value::Float(1.7320508)]; + assert_eq!(pixel_operation("div", &operands, false), Value::Float(f32::from_bits(0xbfca24fb))); + assert_eq!(pixel_operation("div", &operands, true), Value::Float(f32::from_bits(0xbfca24fc))); + // The runtime flushes both operands of this quotient, giving zero divided by zero. + let tiny = Value::Float(f32::from_bits(1)); + let Value::Float(quotient) = pixel_operation("div", &[tiny.clone(), tiny], false) else { panic!("expected float") }; + assert!(quotient.is_nan()); +} + +#[test] +fn a_literal_pixel_divisor_folds_before_varying_products_and_sums() { + let values = [0xc349_28a6, 0x437f_0000, 0xbeff_f6a8].map(|v| Value::Float(f32::from_bits(v))); + let variables = ["numerator", "divisor", "offset"].into_iter().map(str::to_owned).zip(values).collect(); + let context = EvaluationContext { + image_formats: &[], + scope: super::FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [1.0; 2], + images: &[], + tile: true, + variables: &variables, + }; + let mut graph = FunctionGraph::default(); + let [numerator, runtime, offset] = ["numerator", "divisor", "offset"].map(|name| graph.add("get_float1", &[], Some(Value::Text(name.into())))); + let literal = graph.add_constant(Value::Float(255.0)); + let twice = graph.add_constant(Value::Float(510.0)); + let two = graph.add_constant(Value::Float(2.0)); + let folded = graph.add("div", &[twice, two], None); + let pixel = |graph: &FunctionGraph| compile(graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + for (divisor, quotient_bits, sum_bits) in [(literal, 0xbf49_f299, 0xbfa4_f6f7), (folded, 0xbf49_f299, 0xbfa4_f6f7), (runtime, 0xbf49_f298, 0xbfa4_f6f6)] { + let quotient = graph.add("div", &[numerator, divisor], None); + graph.output = Some(quotient); + assert_eq!(pixel(&graph), Value::Float(f32::from_bits(quotient_bits))); + graph.output = Some(graph.add("add", &[quotient, offset], None)); + assert_eq!(pixel(&graph), Value::Float(f32::from_bits(sum_bits))); + } +} + +#[test] +fn measured_pixel_reciprocals_preserve_runtime_rounding() { + for (input, expected) in [(0x3ecccccc, 0x40200000), (0x3ecc4ccd, 0x4020643f), (0xc2ff6f11, 0xbc0048a0), (0x038537b1, 0x7b75f93f)] { + let x = f32::from_bits(input); + let operands = [Value::Float(1.0), Value::Float(x)]; + assert_eq!(pixel_operation("div", &operands, false), Value::Float(f32::from_bits(expected))); + assert_eq!(pixel_operation("div", &operands, true), Value::Float(1.0 / x)); + } +} + +#[test] +fn pixel_branch_shared_draws_precede_the_selected_arm() { + let mut graph = FunctionGraph::default(); + let test = graph.add("get_bool", &[], Some(Value::Text("first".into()))); + let one = graph.add_constant(Value::Float(1.0)); + let [a, b, next] = std::array::from_fn(|_| graph.add("rand", &[one], None)); + let left = graph.add("vector2", &[a, a], None); + let right = graph.add("vector2", &[b, a], None); + let branch = graph.add("ifelse", &[test, left, right], None); + let tail = graph.add("vector2", &[next, next], None); + graph.output = Some(graph.add("vector4", &[branch, tail], None)); + let values = BTreeMap::from([("first".into(), Value::Bool(false))]); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + position: [24.5 / 32.0, 0.5 / 32.0], + size: [32.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &values, + }; + let program = compile(&graph, 137).unwrap(); + let result = program.evaluate(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(result, Value::Float4([0x3e87_bb00, 0x3f59_6540, 0x3f22_ab7c, 0x3f22_ab7c].map(f32::from_bits))); +} + +#[test] +fn pattern_branch_draws_shared_with_a_later_channel_keep_their_order() { + let mut graph = FunctionGraph::default(); + let condition = graph.add("get_bool", &[], Some(Value::Text("take".into()))); + let one = graph.add_constant(Value::Float(1.0)); + let [a, b, c, alternate, green] = std::array::from_fn(|_| graph.add("rand", &[one], None)); + let mixed = graph.add("lerp", &[a, b, c], None); + let red = graph.add("ifelse", &[condition, mixed, alternate], None); + let rg = graph.add("vector2", &[red, green], None); + graph.output = Some(graph.add("vector3", &[rg, a], None)); + for (take, seed, bits) in [ + (true, 31, [0x3f51_c505, 0x3e9a_198c, 0x3f34_57e6]), + (false, 31, [0x3f5a_33c2, 0x3f46_fab2, 0x3f34_57e6]), + (true, 12071, [0x3f12_cb20, 0x3f48_974e, 0x3ee5_cd7c]), + (false, 68047, [0x3c33_7c80, 0x3f58_d3c2, 0x3d46_3760]), + ] { + let values = BTreeMap::from([("take".into(), Value::Bool(take))]); + let context = EvaluationContext { + scope: super::FunctionScope::FxMap, + position: [0.5; 2], + size: [16.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &values, + }; + let program = compile(&graph, seed).unwrap(); + assert_eq!(program.evaluate(&context, &mut EvaluationState::default()).unwrap(), Value::Float3(bits.map(f32::from_bits))); + } +} + +#[test] +fn shared_pattern_draws_follow_the_order_of_the_conditional_arms() { + let mut graph = FunctionGraph::default(); + let take = graph.add("get_bool", &[], Some(Value::Text("take".into()))); + let one = graph.add_constant(Value::Float(1.0)); + let [a, b, c, d, next] = std::array::from_fn(|_| graph.add("rand", &[one], None)); + let yes = graph.add("lerp", &[a, b, c], None); + let no = graph.add("lerp", &[c, b, d], None); + let branch = graph.add("ifelse", &[take, yes, no], None); + let rg = graph.add("vector2", &[branch, next], None); + graph.output = Some(graph.add("vector3", &[rg, d], None)); + let program = compile(&graph, 31).unwrap(); + for (take, bits) in [(true, [0x3f51_c505, 0x3f5b_5a9e, 0x3e9a_198c]), (false, [0x3f3c_c6a3, 0x3e9a_198c, 0x3f46_fab2])] { + let variables = BTreeMap::from([("take".into(), Value::Bool(take))]); + let context = EvaluationContext { + scope: super::FunctionScope::FxMap, + position: [0.5; 2], + size: [16.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + assert_eq!(program.evaluate(&context, &mut EvaluationState::default()).unwrap(), Value::Float3(bits.map(f32::from_bits))); + } +} + +#[test] +fn selecting_a_packed_pattern_channel_consumes_only_its_draw() { + let mut graph = FunctionGraph::default(); + let one = graph.add_constant(Value::Float(1.0)); + let [a, b, c, d] = std::array::from_fn(|_| graph.add("rand", &[one], None)); + let left = graph.add("vector2", &[a, b], None); + let right = graph.add("vector2", &[c, d], None); + let packed = graph.add("vector4", &[left, right], None); + let [last, third, first] = [3, 2, 0].map(|i| graph.add("swizzle1", &[packed], Some(Value::Int(i)))); + let pair = graph.add("vector2", &[last, third], None); + graph.output = Some(graph.add("vector3", &[pair, first], None)); + let variables = BTreeMap::new(); + let context = EvaluationContext { + scope: super::FunctionScope::FxMap, + position: [0.5; 2], + size: [16.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + let value = compile(&graph, 31).unwrap().evaluate(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(value, Value::Float3([0x3f34_57e6, 0x3f5a_33c2, 0x3f46_fab2].map(f32::from_bits))); +} + +#[test] +fn pattern_call_reads_the_selected_components_of_a_packed_argument() { + let mut body = FunctionGraph::default(); + let channels = body.add("get_float4", &[], Some(Value::Text("channels".into()))); + let [alpha, blue, red] = [3, 2, 0].map(|i| body.add("swizzle1", &[channels], Some(Value::Int(i)))); + let first = body.add("vector2", &[alpha, blue], None); + body.output = Some(body.add("vector3", &[first, red], None)); + + let mut graph = FunctionGraph::default(); + let one = graph.add_constant(Value::Float(1.0)); + let [r, g, b, a, next] = std::array::from_fn(|_| graph.add("rand", &[one], None)); + let rg = graph.add("vector2", &[r, g], None); + let ba = graph.add("vector2", &[b, a], None); + let rgba = graph.add("vector4", &[rg, ba], None); + let result = graph.add("instance", &[rgba], None); + let call = graph.nodes.last_mut().unwrap(); + call.type_code = 1024; + call.instance = Some(materialcraft_core::GraphInstance { + package: String::new(), + graph: "pick_channels".into(), + label: String::new(), + inputs: vec![materialcraft_core::GraphPort { identifier: "channels".into(), type_code: 2048 }], + outputs: Vec::new(), + defaults: BTreeMap::from([("channels".into(), Value::Color([0.0, 0.0, 0.0, 1.0]))]), + }); + call.source = Some(Ok(std::sync::Arc::new(body))); + let variables = BTreeMap::new(); + let context = EvaluationContext { + scope: super::FunctionScope::FxMap, + position: [0.5; 2], + size: [16.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + let run = |graph: &FunctionGraph| compile(graph, 31).unwrap().evaluate(&context, &mut EvaluationState::default()).unwrap(); + let draws = [0x3f34_57e6, 0x3f5a_33c2, 0x3f46_fab2].map(f32::from_bits); + graph.output = Some(result); + assert_eq!(run(&graph), Value::Float3(draws)); + + let outside = graph.add("swizzle1", &[rgba], Some(Value::Int(3))); + let inside = graph.add("swizzle1", &[result], Some(Value::Int(0))); + let pair = graph.add("vector2", &[outside, inside], None); + graph.output = Some(graph.add("vector3", &[pair, next], None)); + assert_eq!(run(&graph), Value::Float3([draws[0], draws[0], draws[1]])); +} + +#[test] +fn pattern_call_arguments_follow_the_returned_channels() { + let names = ["red", "green", "blue"]; + let mut body = FunctionGraph::default(); + let [red, green, blue] = names.map(|n| body.add("get_float1", &[], Some(Value::Text(n.into())))); + let bg = body.add("vector2", &[blue, green], None); + body.output = Some(body.add("vector3", &[bg, red], None)); + + let mut graph = FunctionGraph::default(); + let one = graph.add_constant(Value::Float(1.0)); + let args: [_; 3] = std::array::from_fn(|_| graph.add("rand", &[one], None)); + let result = graph.add("instance", &args, None); + let call = graph.nodes.last_mut().unwrap(); + call.type_code = 1024; + call.instance = Some(materialcraft_core::GraphInstance { + package: String::new(), + graph: "reverse_channels".into(), + label: String::new(), + inputs: names.map(|n| materialcraft_core::GraphPort { identifier: n.into(), type_code: 256 }).into(), + outputs: Vec::new(), + defaults: names.map(|n| (n.into(), Value::Float(0.0))).into(), + }); + call.source = Some(Ok(std::sync::Arc::new(body))); + let variables = BTreeMap::new(); + let context = EvaluationContext { + scope: super::FunctionScope::FxMap, + position: [0.5; 2], + size: [16.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + graph.output = Some(result); + let run = |graph: &FunctionGraph| compile(graph, 31).unwrap().evaluate(&context, &mut EvaluationState::default()).unwrap(); + let draws = [0x3f34_57e6, 0x3f5a_33c2, 0x3f46_fab2].map(f32::from_bits); + assert_eq!(run(&graph), Value::Float3(draws)); + + let selected = graph.add("swizzle1", &[result], Some(Value::Int(0))); + let next = graph.add("rand", &[one], None); + let pair = graph.add("vector2", &[selected, next], None); + graph.output = Some(graph.add("vector3", &[pair, args[2]], None)); + assert_eq!(run(&graph), Value::Float3([draws[0], draws[1], draws[0]])); +} + +#[test] +fn packed_random_ranges_preserve_the_unrounded_draw_in_each_lane() { + let mut graph = FunctionGraph::default(); + let [a, b, c, d] = [0.999, -1.731053, 0.001, 0.352111].map(|x| graph.add_constant(Value::Float(x))); + let left = graph.add("rand", &[a], None); + let right = graph.add("rand", &[b], None); + let pair = graph.add("vector2", &[left, right], None); + let offsets = graph.add("vector2", &[c, d], None); + let sum = graph.add("add", &[pair, offsets], None); + let shared = graph.add("vector4", &[sum, pair], None); + let plus = graph.add("add", &[left, c], None); + let minus = graph.add("sub", &[d, left], None); + let twice = graph.add("vector2", &[plus, minus], None); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + position: [1.5 / 16.0, 0.5 / 16.0], + size: [16.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &BTreeMap::new(), + }; + for (output, expected) in [ + (sum, Value::Float2([0x3ea1_2485, 0xbf63_be1d].map(f32::from_bits))), + (shared, Value::Float4([0x3ea1_2485, 0xbf63_be1e, 0x3ea0_a173, 0xbf9e_f108].map(f32::from_bits))), + (twice, Value::Float2([0x3ea1_2485, 0x3d1d_3394].map(f32::from_bits))), + ] { + graph.output = Some(output); + assert_eq!(compile(&graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(), expected); + } +} + +#[test] +fn a_single_use_pixel_random_range_contracts_with_its_offset() { + let mut graph = FunctionGraph::default(); + let range = graph.add_constant(Value::Float(0.999)); + let offset = graph.add_constant(Value::Float(0.001)); + let draw = graph.add("rand", &[range], None); + let sum = graph.add("add", &[draw, offset], None); + let reverse = graph.add("sub", &[offset, draw], None); + let shared = graph.add("vector2", &[sum, draw], None); + for (output, x, expected) in [ + (sum, 2, Value::Float(f32::from_bits(0x3f35_63cb))), + (reverse, 4, Value::Float(f32::from_bits(0xbeb1_9951))), + (shared, 2, Value::Float2([0x3f35_63ca, 0x3f35_2241].map(f32::from_bits))), + ] { + graph.output = Some(output); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + position: [(x as f32 + 0.5) / 16.0, 0.5 / 16.0], + size: [16.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &BTreeMap::new(), + }; + let value = compile(&graph, 17).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(value, expected); + } +} + +#[test] +fn pixel_random_starts_at_the_normalized_texel_center_and_graph_seed() { + let mut graph = FunctionGraph::default(); + let one = graph.add_constant(Value::Float(1.0)); + graph.output = Some(graph.add("rand", &[one], None)); + for (seed, width, height, x, y, first_draw) in + [(0, 32, 32, 0, 0, 6_046_590), (0, 32, 32, 16, 1, 1_903_037), (1, 32, 32, 31, 31, 6_085_635), (42, 32, 16, 16, 1, 3_941_566)] + { + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + position: [(x as f32 + 0.5) / width as f32, (y as f32 + 0.5) / height as f32], + size: [width as f32, height as f32], + images: &[], + image_formats: &[], + tile: true, + variables: &BTreeMap::new(), + }; + let program = compile(&graph, seed).unwrap(); + let value = program.evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(value, Value::Float(first_draw as f32 / 8_388_608.0)); + } +} + +#[test] +fn measured_pixel_random_draws_share_one_stream() { + let mut graph = FunctionGraph::default(); + let one = graph.add_constant(Value::Float(1.0)); + let negative = graph.add_constant(Value::Float(-2.0)); + let factor = graph.add_constant(Value::Float(0.375)); + let first = graph.add("rand", &[one], None); + let second = graph.add("rand", &[one], None); + let third = graph.add("rand", &[negative], None); + let fourth = graph.add("rand", &[factor], None); + let pair1 = graph.add("vector2", &[first, second], None); + let pair2 = graph.add("vector2", &[third, fourth], None); + graph.output = Some(graph.add("vector4", &[pair1, pair2], None)); + let variables = BTreeMap::new(); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [32.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + let program = compile(&graph, 0).unwrap(); + for (seed, bits) in [(9_091_073, [1060669180, 1057720276, 1034667712, 1054479120]), (3_342_178, [1058664790, 1044635448, 1061348922, 1062659162])] { + let mut state = crate::random::FunctionRandom::image(seed); + let [a, b, c, d] = bits.map(f32::from_bits); + assert_eq!(program.evaluate_with_random(&context, &mut EvaluationState::default(), &mut state).unwrap(), Value::Float4([a, b, -2.0 * c, 0.375 * d])); + } +} + +#[test] +fn pixel_lerp_fuses_the_scaled_difference() { + let operands = [0xc04928a6, 0xbfc9a1db, 0xbefff6a8].map(|bits| Value::Float(f32::from_bits(bits))); + assert_eq!(pixel_operation("lerp", &operands, false), Value::Float(f32::from_bits(0xc07b52ad))); + assert_eq!(pixel_operation("lerp", &operands, true), Value::Float(f32::from_bits(0xc07b52ae))); +} + #[test] fn system_variables_resolve_with_their_declared_types() { for (operation, name, expected) in [ @@ -143,6 +1891,52 @@ fn branches_are_lazy_and_sequence_orders_side_effects() { assert_eq!(evaluate(&graph, &BTreeMap::new()).unwrap(), Value::Int(17)); } +#[test] +fn pixel_branches_share_an_assignment_across_nested_alternatives() { + let mut graph = FunctionGraph::default(); + let name = Some(Value::Text("stored".into())); + let initial = graph.add_constant(Value::Float(0.40625)); + let init = graph.add("set", &[initial], name.clone()); + let uv = graph.add("get_float2", &[], Some(Value::Text("$pos".into()))); + let x = graph.add("swizzle1", &[uv], Some(Value::Int(0))); + let write = graph.add("set", &[x], name.clone()); + let after_write = graph.add("get_float1", &[], name.clone()); + let shared = graph.add("sequence", &[write, after_write], None); + let one = graph.add_constant(Value::Float(1.0)); + let half = graph.add_constant(Value::Float(0.5)); + let upper = graph.add_constant(Value::Float(1.5)); + let first = graph.add("add", &[shared, one], None); + let second = graph.add("mul", &[shared, half], None); + let last = graph.add("get_float1", &[], name); + let selector = graph.add("get_float1", &[], Some(Value::Text("selector".into()))); + let low = graph.add("lr", &[selector, half], None); + let middle = graph.add("lr", &[selector, upper], None); + let inner = graph.add("ifelse", &[middle, second, last], None); + let across_arms = graph.add("ifelse", &[low, first, inner], None); + let siblings = graph.add("ifelse", &[low, first, second], None); + let within_arm = graph.add("ifelse", &[middle, siblings, last], None); + let chosen = graph.add("ifelse", &[low, shared, last], None); + let across_operands = graph.add("add", &[chosen, second], None); + + for (root, expected) in [(across_arms, [1.03125, 0.015625, 0.03125]), (within_arm, [1.03125, 0.015625, 0.40625]), (across_operands, [0.046875; 3])] { + graph.output = Some(graph.add("sequence", &[init, root], None)); + let program = compile(&graph, 0).unwrap(); + for (selector, expected) in [0.0, 1.0, 2.0].into_iter().zip(expected) { + let variables = BTreeMap::from([("selector".into(), Value::Float(selector))]); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + position: [0.03125; 2], + size: [16.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + assert_eq!(program.evaluate_pixel(&context, &mut EvaluationState::default()), Ok(Value::Float(expected)), "root {root}, selector {selector}"); + } + } +} + #[test] fn time_and_tiling_variables_have_typed_defaults_and_host_overrides() { for (name, operation, default, supplied) in @@ -155,7 +1949,15 @@ fn time_and_tiling_variables_have_typed_defaults_and_host_overrides() { for variables in [BTreeMap::new(), BTreeMap::from([(name.into(), supplied.clone())])] { let expected = variables.get(name).unwrap_or(&default); - let context = EvaluationContext { scope: Default::default(), position: [0.5; 2], size: [1.0; 2], images: &[], tile: true, variables: &variables }; + let context = EvaluationContext { + image_formats: &[], + scope: Default::default(), + position: [0.5; 2], + size: [1.0; 2], + images: &[], + tile: true, + variables: &variables, + }; let program = compile(&graph, 0).unwrap(); assert_eq!(program.evaluate(&context, &mut EvaluationState::default()).unwrap(), *expected); @@ -171,11 +1973,38 @@ fn time_and_tiling_variables_have_typed_defaults_and_host_overrides() { let mut graph = FunctionGraph::default(); graph.output = Some(graph.add("get_integer1", &[], Some(Value::Text("$tiling".into())))); - let context = EvaluationContext { scope: Default::default(), position: [0.5; 2], size: [1.0; 2], images: &[], tile: false, variables: &BTreeMap::new() }; + let context = EvaluationContext { + image_formats: &[], + scope: Default::default(), + position: [0.5; 2], + size: [1.0; 2], + images: &[], + tile: false, + variables: &BTreeMap::new(), + }; assert_eq!(compile(&graph, 0).unwrap().evaluate(&context, &mut EvaluationState::default()).unwrap(), Value::Int(0)); } +#[test] +fn skipped_processor_loop_runs_its_initializer_and_returns_a_typed_zero() { + let mut graph = FunctionGraph::default(); + let yes = graph.add_constant(Value::Bool(true)); + let initialize = graph.add("set", &[yes], Some(Value::Text("started".into()))); + let body = graph.add_constant(Value::Float2([4.0, 5.0])); + let result = graph.add("while", &[initialize, yes, body], Some(Value::Int(2))); + let started = graph.add("get_bool", &[], Some(Value::Text("started".into()))); + let after = graph.add("sequence", &[result, started], None); + for scope in [super::FunctionScope::Node, super::FunctionScope::PixelProcessor, super::FunctionScope::ValueProcessor, super::FunctionScope::FxMap] { + let context = + EvaluationContext { scope, position: [0.0; 2], size: [16.0; 2], images: &[], image_formats: &[], tile: true, variables: &BTreeMap::new() }; + for (output, expected) in [(result, Value::Float2([0.0; 2])), (after, Value::Bool(true))] { + graph.output = Some(output); + assert_eq!(compile(&graph, 0).unwrap().evaluate(&context, &mut EvaluationState::default()).unwrap(), expected); + } + } +} + #[test] fn loops_recompute_state_and_have_a_budget() { let mut graph = FunctionGraph::default(); @@ -197,6 +2026,110 @@ fn loops_recompute_state_and_have_a_budget() { assert!(evaluate(&graph, &BTreeMap::new()).unwrap_err().contains("budget")); } +#[test] +fn finite_loop_returns_the_settled_value_and_preserves_its_assignments() { + let mut graph = FunctionGraph::default(); + let zero = graph.add_constant(Value::Int(0)); + let one = graph.add_constant(Value::Int(1)); + let limit = graph.add_constant(Value::Int(5)); + let never = graph.add_constant(Value::Bool(false)); + let counter = Some(Value::Text("counter".into())); + let init = graph.add("set", &[zero], counter.clone()); + let read = graph.add("get_integer1", &[], counter.clone()); + let increment = graph.add("add", &[read, one], None); + let bounded = graph.add("min", &[increment, limit], None); + let write = graph.add("set", &[bounded], counter.clone()); + let result = graph.add("while", &[init, never, write], Some(Value::Int(65_536))); + graph.output = Some(result); + assert_eq!(evaluate(&graph, &BTreeMap::new()).unwrap(), Value::Int(5)); + + let after = graph.add("get_integer1", &[], counter); + graph.output = Some(graph.add("sequence", &[result, after], None)); + assert_eq!(evaluate(&graph, &BTreeMap::new()).unwrap(), Value::Int(5)); +} + +#[test] +fn finite_loop_distinguishes_the_sign_of_zero_in_its_state() { + let mut graph = FunctionGraph::default(); + let zero = graph.add_constant(Value::Float(0.0)); + let never = graph.add_constant(Value::Bool(false)); + let sign = Some(Value::Text("sign".into())); + let init = graph.add("set", &[zero], sign.clone()); + let value = graph.add("get_float1", &[], sign.clone()); + let negate = graph.add("neg", &[value], None); + let write = graph.add("set", &[negate], sign); + graph.output = Some(graph.add("while", &[init, never, write], Some(Value::Int(65)))); + let result = evaluate(&graph, &BTreeMap::new()).unwrap().as_f32().unwrap(); + assert_eq!(result.to_bits(), (-0.0_f32).to_bits()); +} + +#[test] +fn finite_loop_accumulates_a_repeating_sequence_at_float_precision() { + let mut graph = FunctionGraph::default(); + let phase = Some(Value::Text("phase".into())); + let sum = Some(Value::Text("sum".into())); + let never = graph.add_constant(Value::Bool(false)); + let zero = graph.add_constant(Value::Float(0.0)); + let first = graph.add_constant(Value::Float(0.1)); + let second = graph.add_constant(Value::Float(0.3)); + let start_phase = graph.add("set", &[never], phase.clone()); + let start_sum = graph.add("set", &[zero], sum.clone()); + let init = graph.add("sequence", &[start_phase, start_sum], None); + let previous_phase = graph.add("get_bool", &[], phase.clone()); + let flip = graph.add("not", &[previous_phase], None); + let change_phase = graph.add("set", &[flip], phase.clone()); + let current_phase = graph.add("get_bool", &[], phase); + let increment = graph.add("ifelse", &[current_phase, first, second], None); + let current_sum = graph.add("get_float1", &[], sum.clone()); + let add = graph.add("add", &[increment, current_sum], None); + let update = graph.add("set", &[add], sum.clone()); + let body = graph.add("sequence", &[change_phase, update], None); + let result = graph.add("while", &[init, never, body], Some(Value::Int(65_537))); + let expected = (0..65_537).fold(0.0_f32, |total, i| total + if i % 2 == 0 { 0.1 } else { 0.3 }); + graph.output = Some(result); + assert_eq!(evaluate(&graph, &BTreeMap::new()).unwrap(), Value::Float(expected)); + let after = graph.add("get_float1", &[], sum); + graph.output = Some(graph.add("sequence", &[result, after], None)); + assert_eq!(evaluate(&graph, &BTreeMap::new()).unwrap(), Value::Float(expected)); +} + +#[test] +fn finite_sum_checks_exit_and_increments_that_read_the_accumulator() { + let mut graph = FunctionGraph::default(); + let sum = Some(Value::Text("sum".into())); + let zero = graph.add_constant(Value::Float(0.0)); + let one = graph.add_constant(Value::Float(1.0)); + let four = graph.add_constant(Value::Float(4.0)); + let ten = graph.add_constant(Value::Float(10.0)); + let init = graph.add("set", &[zero], sum.clone()); + let total = graph.add("get_float1", &[], sum.clone()); + let small = graph.add("lr", &[total, four], None); + let increment = graph.add("ifelse", &[small, one, four], None); + let add = graph.add("add", &[total, increment], None); + let body = graph.add("set", &[add], sum.clone()); + let read = graph.add("get_float1", &[], sum); + let done = graph.add("gt", &[read, ten], None); + graph.output = Some(graph.add("while", &[init, done, body], Some(Value::Int(65_537)))); + assert_eq!(evaluate(&graph, &BTreeMap::new()).unwrap(), Value::Float(12.0)); +} + +#[test] +fn finite_loop_preserves_each_random_draw_with_a_constant_body_result() { + let mut graph = FunctionGraph::default(); + let one = graph.add_constant(Value::Float(1.0)); + let never = graph.add_constant(Value::Bool(false)); + let draw = graph.add("rand", &[one], None); + let body = graph.add("sequence", &[draw, one], None); + let result = graph.add("while", &[one, never, body], Some(Value::Int(65))); + let next_draw = graph.add("rand", &[one], None); + graph.output = Some(graph.add("sequence", &[result, next_draw], None)); + let mut expected = crate::random::FunctionRandom::uniform(7); + for _ in 0..65 { + expected.draw(); + } + assert_eq!(evaluate(&graph, &BTreeMap::new()).unwrap(), Value::Float(expected.draw())); +} + #[test] fn deep_graphs_shared_inputs_and_cycles_do_not_recurse() { let mut graph = FunctionGraph::constant(Value::Float(1.0)); @@ -223,6 +2156,38 @@ fn deep_graphs_shared_inputs_and_cycles_do_not_recurse() { assert_eq!(evaluate(&graph, &BTreeMap::new()).unwrap(), Value::Float(1_073_741_824.0)); } +#[test] +fn pattern_expressions_read_inherited_values_and_keep_only_local_writes() { + let mut expression = FunctionGraph::default(); + let counter = expression.add("get_float1", &[], Some(Value::Text("counter".into()))); + let one = expression.add_constant(Value::Float(1.0)); + let next = expression.add("add", &[counter, one], None); + expression.output = Some(expression.add("set", &[next], Some(Value::Text("counter".into())))); + let increment = compile(&expression, 17).unwrap(); + let inherited = compile(&FunctionGraph::input("counter", materialcraft_core::ValueType::Float), 17).unwrap(); + let mut state = EvaluationState::default(); + let mut random = crate::random::FunctionRandom::image(17); + for initial in [0.5, -3.0] { + let variables = BTreeMap::from([("counter".into(), Value::Float(initial)), ("label".into(), Value::Text("pattern".into()))]); + let context = EvaluationContext { + scope: super::FunctionScope::FxMap, + position: [0.5; 2], + size: [16.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + let expected = Value::Float(initial + 1.0); + assert_eq!(increment.evaluate_with_random(&context, &mut state, &mut random).unwrap(), expected); + assert_eq!(state.assignments().get("counter"), Some(&expected)); + assert!(!state.variables().contains_key("label")); + assert_eq!(inherited.evaluate_with_random(&context, &mut state, &mut random).unwrap(), Value::Float(initial)); + assert!(state.assignments().is_empty()); + assert!(state.variables().is_empty()); + } +} + #[test] fn pixel_assignments_are_local_and_match_exported_evaluation() { let mut graph = FunctionGraph::default(); @@ -236,7 +2201,15 @@ fn pixel_assignments_are_local_and_match_exported_evaluation() { let mut pixel_state = EvaluationState::default(); for initial in [3.0, 10.0, -2.0] { let variables = BTreeMap::from([("counter".into(), Value::Float(initial)), ("untouched".into(), Value::Text("keep".into()))]); - let context = EvaluationContext { scope: Default::default(), position: [0.5; 2], size: [1.0; 2], images: &[], tile: true, variables: &variables }; + let context = EvaluationContext { + image_formats: &[], + scope: Default::default(), + position: [0.5; 2], + size: [1.0; 2], + images: &[], + tile: true, + variables: &variables, + }; let mut exported = EvaluationState::default(); let expected = program.evaluate(&context, &mut exported).unwrap(); for _ in 0..2 { @@ -249,7 +2222,15 @@ fn pixel_assignments_are_local_and_match_exported_evaluation() { } let read_only = compile(&FunctionGraph::constant(Value::Float(0.5)), 7).unwrap(); - let context = EvaluationContext { scope: Default::default(), position: [0.5; 2], size: [1.0; 2], images: &[], tile: true, variables: &BTreeMap::new() }; + let context = EvaluationContext { + image_formats: &[], + scope: Default::default(), + position: [0.5; 2], + size: [1.0; 2], + images: &[], + tile: true, + variables: &BTreeMap::new(), + }; assert_eq!(read_only.evaluate_pixel(&context, &mut pixel_state).unwrap(), Value::Float(0.5)); assert!(pixel_state.variables().is_empty()); @@ -266,7 +2247,15 @@ fn pixel_random_seed_and_defined_variables_match_general_evaluation() { let program = compile(&graph, 7).unwrap(); let mut state = EvaluationState::default(); for variables in [BTreeMap::from([("$randomseed".into(), Value::Int(42)), ("known".into(), Value::Bool(true))]), BTreeMap::new()] { - let context = EvaluationContext { scope: Default::default(), position: [0.5; 2], size: [1.0; 2], images: &[], tile: true, variables: &variables }; + let context = EvaluationContext { + image_formats: &[], + scope: Default::default(), + position: [0.5; 2], + size: [1.0; 2], + images: &[], + tile: true, + variables: &variables, + }; let expected = program.evaluate(&context, &mut EvaluationState::default()).unwrap(); assert_eq!(program.evaluate_pixel(&context, &mut state).unwrap(), expected); @@ -343,6 +2332,7 @@ fn pixel_random_samples_vary_spatially_and_repeat_for_the_same_seed() { (0..16) .map(|x| { let context = EvaluationContext { + image_formats: &[], scope: super::FunctionScope::PixelProcessor, position: [(x as f32 + 0.5) / 16.0, 0.5], size: [16.0; 2], @@ -381,6 +2371,84 @@ fn exposed_choices_are_integers_inside_functions() { assert!(evaluate(&graph, &BTreeMap::from([("choice".into(), Value::Enum(u32::MAX))])).is_err()); } +#[test] +fn a_constant_return_keeps_literal_precision_in_the_caller() { + let variables = BTreeMap::from([("angle".into(), Value::Float(std::f32::consts::PI))]); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [1.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + for (literal, expected) in [(true, 0x3c8efa35), (false, 0x3c8efa36)] { + let mut inner = FunctionGraph::default(); + inner.output = Some(if literal { + inner.add_constant(Value::Float(std::f32::consts::PI)) + } else { + inner.add("get_float1", &[], Some(Value::Text("angle".into()))) + }); + let mut graph = FunctionGraph::default(); + let result = graph.add("instance", &[], None); + let call = graph.nodes.last_mut().unwrap(); + call.instance = Some(materialcraft_core::GraphInstance { + label: String::new(), + package: String::new(), + graph: "angle_value".into(), + inputs: Vec::new(), + outputs: Vec::new(), + defaults: BTreeMap::new(), + }); + call.source = Some(Ok(std::sync::Arc::new(inner))); + let divisor = graph.add_constant(Value::Float(180.0)); + graph.output = Some(graph.add("div", &[result, divisor], None)); + let value = compile(&graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(value, Value::Float(f32::from_bits(expected))); + } +} + +#[test] +fn nested_pixel_products_keep_the_callers_literal_arguments() { + let mut inner = FunctionGraph::default(); + let names = ["a", "b", "c", "d"]; + let [a, b, c, d] = names.map(|name| inner.add("get_float1", &[], Some(Value::Text(name.into())))); + let left = inner.add("mul", &[a, b], None); + let right = inner.add("mul", &[c, d], None); + inner.output = Some(inner.add("add", &[left, right], None)); + + let mut graph = FunctionGraph::default(); + let a = graph.add_constant(Value::Float(0.1875)); + let b = graph.add_constant(Value::Float(1.25)); + let [c, d] = ["x", "y"].map(|name| graph.add("get_float1", &[], Some(Value::Text(name.into())))); + graph.output = Some(graph.add("instance", &[a, b, c, d], None)); + let call = graph.nodes.last_mut().unwrap(); + call.instance = Some(materialcraft_core::GraphInstance { + label: String::new(), + package: String::new(), + graph: "sum_products".into(), + inputs: names.map(|name| materialcraft_core::GraphPort { identifier: name.into(), type_code: 256 }).into(), + outputs: Vec::new(), + defaults: names.into_iter().map(|name| (name.into(), Value::Float(0.0))).collect(), + }); + call.source = Some(Ok(std::sync::Arc::new(inner))); + let program = compile(&graph, 0).unwrap(); + for (x, y, expected) in [(0xbe7ff6a8, 0xbf68ddb9, 0x3eec6a9d), (0x3eccdf41, 0xbfaa12de, 0xbe9836b5)] { + let variables = BTreeMap::from([("x".into(), Value::Float(f32::from_bits(x))), ("y".into(), Value::Float(f32::from_bits(y)))]); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [1.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + assert_eq!(program.evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(), Value::Float(f32::from_bits(expected))); + } +} + #[test] fn nested_function_assignments_escape_but_arguments_stay_local() { let mut inner = FunctionGraph::default(); @@ -489,6 +2557,135 @@ fn a_loop_evaluates_its_condition_and_body_again_on_every_iteration() { assert_eq!(evaluate(&graph, &BTreeMap::new()).unwrap(), Value::Int(3)); } +#[test] +fn writing_a_function_argument_keeps_its_wire_and_a_nested_free_assignment() { + fn call(body: FunctionGraph, argument: &str, wire: Option) -> FunctionGraph { + let mut graph = FunctionGraph::default(); + let input = wire.map(|value| graph.add_constant(Value::Float(value))); + let result = graph.add("instance", &[], None); + let node = graph.nodes.last_mut().unwrap(); + node.instance = Some(materialcraft_core::GraphInstance { + label: String::new(), + package: String::new(), + graph: "assign_scalar".into(), + inputs: vec![materialcraft_core::GraphPort { identifier: argument.into(), type_code: 256 }], + outputs: vec![materialcraft_core::GraphPort { identifier: "output".into(), type_code: 256 }], + defaults: BTreeMap::from([(argument.into(), Value::Float(0.0))]), + }); + node.inputs = vec![input]; + node.source = Some(Ok(std::sync::Arc::new(body))); + graph.output = Some(result); + graph + } + + let mut write = FunctionGraph::default(); + let value = write.add_constant(Value::Float(0.4375)); + write.output = Some(write.add("set", &[value], Some(Value::Text("amount".into())))); + let direct = call(write.clone(), "amount", Some(0.625)); + assert_eq!(evaluate(&direct, &BTreeMap::new()), Ok(Value::Float(0.0))); + + let mut effect = FunctionGraph::default(); + let value = effect.add_constant(Value::Float(0.4375)); + let operand = effect.add("set", &[value], Some(Value::Text("effect".into()))); + effect.output = Some(effect.add("set", &[operand], Some(Value::Text("amount".into())))); + let mut direct = call(effect, "amount", Some(0.625)); + let entered = direct.output.unwrap(); + let read = direct.add("get_float1", &[], Some(Value::Text("effect".into()))); + direct.output = Some(direct.add("sequence", &[entered, read], None)); + assert_eq!(evaluate(&direct, &BTreeMap::new()), Ok(Value::Float(0.0))); + + let mut parent = call(write, "unused", None); + let write = parent.output.unwrap(); + let argument = parent.add("get_float1", &[], Some(Value::Text("amount".into()))); + parent.output = Some(parent.add("sequence", &[write, argument], None)); + let mut outer = call(parent, "amount", Some(0.625)); + let returned = outer.output.unwrap(); + let shared = outer.add("get_float1", &[], Some(Value::Text("amount".into()))); + outer.output = Some(outer.add("vector2", &[returned, shared], None)); + assert_eq!(evaluate(&outer, &BTreeMap::new()), Ok(Value::Float2([0.625, 0.4375]))); +} + +#[test] +fn a_partially_wired_call_reads_typed_zero_from_its_other_numeric_argument() { + let mut body = FunctionGraph::default(); + body.output = Some(body.add("get_float3", &[], Some(Value::Text("position".into())))); + let mut graph = FunctionGraph::default(); + let size = graph.add_constant(Value::Float(0.0)); + let position = graph.add_constant(Value::Float3([-0.25, 0.5, 0.75])); + let call = graph.add("instance", &[], None); + graph.output = Some(call); + let node = graph.nodes.last_mut().unwrap(); + node.instance = Some(materialcraft_core::GraphInstance { + label: String::new(), + package: String::new(), + graph: "read_position".into(), + inputs: vec![ + materialcraft_core::GraphPort { identifier: "size".into(), type_code: 256 }, + materialcraft_core::GraphPort { identifier: "position".into(), type_code: 1024 }, + ], + outputs: vec![materialcraft_core::GraphPort { identifier: "output".into(), type_code: 1024 }], + defaults: BTreeMap::from([("size".into(), Value::Float(0.5)), ("position".into(), Value::Float3([1.0; 3]))]), + }); + node.source = Some(Ok(std::sync::Arc::new(body))); + node.inputs = vec![Some(size), None]; + let variables = BTreeMap::from([("position".into(), Value::Float3([0.875; 3]))]); + assert_eq!(evaluate(&graph, &variables), Ok(Value::Float3([0.0; 3]))); + graph.nodes.last_mut().unwrap().inputs[1] = Some(position); + assert_eq!(evaluate(&graph, &variables), Ok(Value::Float3([-0.25, 0.5, 0.75]))); + graph.nodes.last_mut().unwrap().inputs = vec![None, None]; + assert_eq!(evaluate(&graph, &variables), Ok(Value::Float3([1.0; 3]))); +} + +#[test] +fn defined_arguments_follow_wires_through_nested_calls() { + fn caller(body: FunctionGraph, wired: bool) -> FunctionGraph { + let mut graph = FunctionGraph::default(); + let zero = graph.add_constant(Value::Float(0.0)); + let result = graph.add("instance", &[], None); + let call = graph.nodes.last_mut().unwrap(); + call.instance = Some(materialcraft_core::GraphInstance { + label: String::new(), + package: String::new(), + graph: "probe".into(), + inputs: vec![materialcraft_core::GraphPort { identifier: "amount".into(), type_code: 256 }], + outputs: vec![materialcraft_core::GraphPort { identifier: "output".into(), type_code: 4 }], + defaults: BTreeMap::from([("amount".into(), Value::Float(0.1875))]), + }); + call.inputs = vec![wired.then_some(zero)]; + call.source = Some(Ok(std::sync::Arc::new(body))); + graph.output = Some(result); + graph + } + + let mut body = FunctionGraph::default(); + let value = body.add_constant(Value::Float(0.4375)); + let set = body.add("set", &[value], Some(Value::Text("amount".into()))); + let defined = body.add("isdefined", &[], Some(Value::Text("amount".into()))); + body.output = Some(body.add("sequence", &[set, defined], None)); + let variables = BTreeMap::from([("amount".into(), Value::Float(0.625))]); + for (outer, inner) in [(false, false), (true, false), (false, true), (true, true)] { + let graph = caller(caller(body.clone(), inner), outer); + assert_eq!(evaluate(&graph, &variables), Ok(Value::Bool(inner))); + } + + let mut free = FunctionGraph::default(); + free.output = Some(free.add("isdefined", &[], Some(Value::Text("mark".into())))); + let mut graph = caller(free, false); + let call = graph.output.unwrap(); + let external = BTreeMap::from([("mark".into(), Value::Float(0.625))]); + assert_eq!(evaluate(&graph, &external), Ok(Value::Bool(false))); + let value = graph.add_constant(Value::Float(0.4375)); + let set = graph.add("set", &[value], Some(Value::Text("mark".into()))); + graph.output = Some(graph.add("sequence", &[set, call], None)); + assert_eq!(evaluate(&graph, &BTreeMap::new()), Ok(Value::Bool(true))); + + let mut graph = caller(body, false); + let call = graph.output.unwrap(); + let assigned = graph.add("isdefined", &[], Some(Value::Text("amount".into()))); + graph.output = Some(graph.add("sequence", &[call, assigned], None)); + assert_eq!(evaluate(&graph, &BTreeMap::new()), Ok(Value::Bool(false))); +} + #[test] fn variables_a_called_graph_sets_reach_its_caller_but_its_inputs_do_not() { let mut called = FunctionGraph::default(); @@ -567,6 +2764,7 @@ fn every_pixel_of_a_processor_draws_its_own_random_numbers() { let parameters = crate::resolve_params(definition, &BTreeMap::from([("function".into(), Value::Function(Box::new(function)))])); let variables = BTreeMap::new(); let context = crate::CookContext { + input_formats: &[], format: materialcraft_core::OutputFormat::F32, w: 8, h: 8, @@ -634,3 +2832,134 @@ fn unconnected_ifelse_condition_stays_boolean_and_empty_branches_keep_declared_t assert_eq!(evaluate(&graph, &BTreeMap::new()).unwrap(), Value::Float2([0.0; 2])); } } + +#[test] +fn packed_loop_products_keep_the_factors_from_the_current_iteration() { + let [r, g, b, weight] = [21.0_f32, 89.0, 149.0, 99.0].map(|code| code / 255.0); + let variables = BTreeMap::from([("color".into(), Value::Float3([r, g, b])), ("weight".into(), Value::Float(weight))]); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [1.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + for nested_read in [false, true] { + let mut graph = FunctionGraph::default(); + let name = Some(Value::Text("total".into())); + let zero = graph.add_constant(Value::Float(0.0)); + let never = graph.add_constant(Value::Bool(false)); + let start = graph.add_constant(Value::Float4([0.0; 4])); + let initialize = graph.add("set", &[start], name.clone()); + let color = graph.add("get_float3", &[], Some(Value::Text("color".into()))); + let scale = graph.add("get_float1", &[], Some(Value::Text("weight".into()))); + let weighted = graph.add("mulscalar", &[color, scale], None); + let term = graph.add("vector4", &[weighted, scale], None); + let mut previous = graph.add("get_float4", &[], name.clone()); + if nested_read { + // This inner loop clears the scale register after the vector has been packed. + let inner = graph.add("while", &[zero, never, scale], Some(Value::Int(1))); + previous = graph.add("sequence", &[inner, previous], None); + } + let sum = graph.add("add", &[term, previous], None); + let store = graph.add("set", &[sum], name.clone()); + let body = graph.add("sequence", &[store, zero], None); + let repeat = graph.add("while", &[initialize, never, body], Some(Value::Int(256))); + let total = graph.add("get_float4", &[], name); + graph.output = Some(graph.add("sequence", &[repeat, total], None)); + let Value::Float4(actual) = compile(&graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap() else { + panic!("expected a four-component sum"); + }; + let [x, y, z] = + [r, g, b].map(|component| (0..256).fold(0.0_f32, |sum, _| if nested_read { component * weight + sum } else { component.mul_add(weight, sum) })); + let alpha = (0..256).fold(0.0_f32, |sum, _| sum + weight); + assert_eq!(actual.map(f32::to_bits), [x, y, z, alpha].map(f32::to_bits), "nested read {nested_read}"); + } +} + +#[test] +fn pixel_division_by_a_literal_unit_reciprocal_uses_the_original_factor() { + let variables = BTreeMap::from([ + ("a".into(), Value::Float(f32::from_bits(0x4076_3400))), + ("b".into(), Value::Float(f32::from_bits(0x3f68_c2ba))), + ("unit".into(), Value::Float(1.0)), + ]); + let context = EvaluationContext { + image_formats: &[], + scope: super::FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [1.0; 2], + images: &[], + tile: true, + variables: &variables, + }; + for (literal, expected) in [(true, 0x405f_da66), (false, 0x405f_da65)] { + let mut graph = FunctionGraph::default(); + let [a, b, unit] = ["a", "b", "unit"].map(|name| graph.add("get_float1", &[], Some(Value::Text(name.into())))); + let one = if literal { graph.add_constant(Value::Float(1.0)) } else { unit }; + let reciprocal = graph.add("div", &[one, b], None); + let quotient = graph.add("div", &[a, reciprocal], None); + graph.output = Some(graph.add("vector2", &[quotient, reciprocal], None)); + let value = compile(&graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(value, Value::Float2([expected, 0x3f8c_c7a2].map(f32::from_bits)), "literal unit {literal}"); + } +} + +#[test] +fn pixel_division_keeps_the_original_length_across_vector_and_scalar_calls() { + fn call(graph: &mut FunctionGraph, body: FunctionGraph, input: u32, kind: u32, default: Value) -> u32 { + let id = graph.add("instance", &[input], None); + let node = graph.nodes.last_mut().unwrap(); + node.instance = Some(materialcraft_core::GraphInstance { + graph: "operation".into(), + label: String::new(), + package: String::new(), + inputs: vec![materialcraft_core::GraphPort { identifier: "v".into(), type_code: kind }], + outputs: Vec::new(), + defaults: BTreeMap::from([("v".into(), default)]), + }); + node.source = Some(Ok(std::sync::Arc::new(body))); + id + } + + let variables = ["a", "b", "c", "z"] + .map(str::to_owned) + .into_iter() + .zip([0x3f80_d400, 0x3fb2_a18e, 0x3e74_0000, 0x3f80_0000].map(|bits| Value::Float(f32::from_bits(bits)))) + .collect(); + let context = EvaluationContext { + scope: super::FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [1.0; 2], + images: &[], + image_formats: &[], + tile: true, + variables: &variables, + }; + let mut normalize = FunctionGraph::default(); + let vector = normalize.add("get_float3", &[], Some(Value::Text("v".into()))); + let squared = normalize.add("dot", &[vector, vector], None); + let length = normalize.add("sqrt", &[squared], None); + let one = normalize.add_constant(Value::Float(1.0)); + let reciprocal = normalize.add("div", &[one, length], None); + normalize.output = Some(normalize.add("mulscalar", &[vector, reciprocal], None)); + + let mut quotient = FunctionGraph::default(); + let [a, v] = ["a", "v"].map(|name| quotient.add("get_float1", &[], Some(Value::Text(name.into())))); + quotient.output = Some(quotient.add("div", &[a, v], None)); + for (constant_z, expected) in [(true, 0x3fdf_4c75), (false, 0x3fdf_4c76)] { + let mut graph = FunctionGraph::default(); + let [c, b, z] = ["c", "b", "z"].map(|name| graph.add("get_float1", &[], Some(Value::Text(name.into())))); + let xy = graph.add("vector2", &[c, b], None); + let z = if constant_z { graph.add_constant(Value::Float(1.0)) } else { z }; + let xyz = graph.add("vector3", &[xy, z], None); + let direction = call(&mut graph, normalize.clone(), xyz, 1024, Value::Float3([0.0; 3])); + let den = graph.add("swizzle1", &[direction], Some(Value::Int(2))); + let result = call(&mut graph, quotient.clone(), den, 256, Value::Float(0.0)); + graph.output = Some(graph.add("vector2", &[result, den], None)); + let value = compile(&graph, 0).unwrap().evaluate_pixel(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(value, Value::Float2([expected, 0x3f13_b1cf].map(f32::from_bits)), "constant Z {constant_z}"); + } +} diff --git a/crates/nodes/src/function/trigonometry.rs b/crates/nodes/src/function/trigonometry.rs new file mode 100644 index 00000000..bcf76f7a --- /dev/null +++ b/crates/nodes/src/function/trigonometry.rs @@ -0,0 +1,85 @@ +//! Runtime sine and cosine for pixel and uniform function scopes. + +use super::fixed_point::{Quadratic, square_fraction, truncate_float}; +use std::sync::LazyLock; + +const QUARTER: u32 = 1 << 23; + +// Derive each quadratic from the sine function over one 64th of the quadrant. +static QUARTER_WAVE: LazyLock<[Quadratic; 64]> = LazyLock::new(|| std::array::from_fn(quarter_polynomial)); + +fn quarter_polynomial(index: usize) -> Quadratic { + let width = std::f64::consts::PI / 128.0; + let (sine, cosine) = ((index as f64 + 0.5) * width).sin_cos(); + let derivatives = [width * cosine, -width.powi(2) * sine, -width.powi(3) * cosine]; + let mut polynomial = Quadratic::fit(|t| ((index as f64 + t) * width).sin(), derivatives, [25, 20, 22]); + polynomial.constant = match index { + 0 => 0, + // These three measured intervals start one constant unit below the rounded midpoint. + 2 | 18 | 46 => polynomial.constant - 1, + _ => polynomial.constant, + }; + polynomial +} + +// One turn spans 25 bits. Retaining the product word before the exponent shift +// reproduces the loss of phase resolution at large angles. +fn phase(bits: u32) -> u32 { + let exponent = ((bits >> 23) & 255) as i32 - 127; + let mantissa = (bits & 0x7f_ffff) | (1 << 23); + let word = ((u64::from(mantissa) * 10_680_707) >> 16) as u32; + let shift = exponent - 8; + let shifted = if shift >= 0 { word.checked_shl(shift as u32) } else { word.checked_shr((-shift) as u32) }; + shifted.unwrap_or(0) & (4 * QUARTER - 1) +} + +pub(super) fn component(angle: f32, cosine: bool, scope: super::FunctionScope, literal: bool) -> f32 { + if literal { + return if cosine { angle.cos() } else { angle.sin() }; + } + if scope == super::FunctionScope::PixelProcessor { pixel_component(angle, cosine) } else { uniform_component(angle, cosine) } +} + +pub(crate) fn pixel_sin_cos(angle: f32) -> (f32, f32) { + (pixel_component(angle, false), pixel_component(angle, true)) +} + +fn pixel_component(angle: f32, cosine: bool) -> f32 { + if !angle.is_finite() { + return f32::NAN; + } + let phase = phase(angle.to_bits()) + if cosine { QUARTER } else { 0 }; + let half = phase & (2 * QUARTER - 1); + let quarter = if half < QUARTER { half } else { 2 * QUARTER - 1 - half }; + let bin = &QUARTER_WAVE[(quarter >> 17) as usize]; + let fraction = quarter & 0x1_ffff; + let fixed = (bin.constant << 12) + bin.slope * i64::from(fraction) + bin.curvature * i64::from(square_fraction(fraction >> 1)); + // The quarter-wave magnitude truncates to the next representable float below the polynomial. + let exact = fixed as f64 / 137_438_953_472.0; + let magnitude = truncate_float(exact); + if (phase & (2 * QUARTER) != 0) ^ (!cosine && angle.is_sign_negative()) { -magnitude } else { magnitude } +} + +fn uniform_component(angle: f32, cosine: bool) -> f32 { + uniform_turn_component(angle * (std::f32::consts::FRAC_1_PI * 0.5), cosine) +} + +pub(crate) fn uniform_sin_cos_turns(turns: f32) -> (f32, f32) { + (uniform_turn_component(turns, false), uniform_turn_component(turns, true)) +} + +fn uniform_turn_component(turns: f32, cosine: bool) -> f32 { + const QUADRANT: f64 = std::f64::consts::FRAC_PI_2; + const CUBIC: f64 = -QUADRANT * QUADRANT * QUADRANT / 6.0; + const FIFTH: f64 = -CUBIC * QUADRANT * QUADRANT / 20.0; + // The measured seventh-order term targets one minus a float epsilon at the quadrant endpoint. + const SEVENTH: f32 = (1.0 - f32::EPSILON as f64 - QUADRANT - CUBIC - FIFTH) as f32; + let turns = turns + if cosine { 0.5 } else { 0.25 }; + let x = 4.0 * (turns - turns.round_ties_even()).abs() - 1.0; + let square = x * x; + let cube = x * square; + let fifth = cube * square; + let seventh = fifth * square; + // Each odd power and each sum rounds separately. + x * std::f32::consts::FRAC_PI_2 + cube * CUBIC as f32 + fifth * FIFTH as f32 + seventh * SEVENTH +} diff --git a/crates/nodes/src/function/unconnected.test.rs b/crates/nodes/src/function/unconnected.test.rs index f30ef160..5c528863 100644 --- a/crates/nodes/src/function/unconnected.test.rs +++ b/crates/nodes/src/function/unconnected.test.rs @@ -30,7 +30,15 @@ fn unconnected_typed_operations_use_their_operand_types() { graph.nodes.first_mut().unwrap().inputs.resize(definition(operation).unwrap().inputs.len(), None); graph.output = Some(id); let variables = Default::default(); - let context = EvaluationContext { scope: Default::default(), position: [0.5; 2], size: [16.0; 2], images: &[], tile: true, variables: &variables }; + let context = EvaluationContext { + image_formats: &[], + scope: Default::default(), + position: [0.5; 2], + size: [16.0; 2], + images: &[], + tile: true, + variables: &variables, + }; let value = compile(&graph, 0).unwrap().evaluate(&context, &mut EvaluationState::default()); @@ -39,21 +47,36 @@ fn unconnected_typed_operations_use_their_operand_types() { } #[test] -fn partially_connected_vectors_fill_only_the_missing_components() { - for (operation, first, last, expected) in [ - ("vector3", Some(Value::Float2([0.25, 0.75])), None, Value::Float3([0.25, 0.75, 0.0])), - ("vector4", None, Some(Value::Float2([0.25, 0.75])), Value::Float4([0.0, 0.0, 0.25, 0.75])), - ("ivector4", Some(Value::Int(7)), None, Value::Int4([7, 0, 0, 0])), +fn vector_constructors_place_a_single_connected_operand_in_the_leading_lanes() { + for (operation, input, expected) in [ + ("vector2", Value::Float(-0.375), Value::Float2([-0.375, 0.0])), + ("vector3", Value::Float2([0.25, 0.75]), Value::Float3([0.25, 0.75, 0.0])), + ("vector4", Value::Float2([0.25, 0.75]), Value::Float4([0.25, 0.75, 0.0, 0.0])), + ("vector4", Value::Float3([0.375, -0.6875, 0.25]), Value::Float4([0.375, -0.6875, 0.25, 0.0])), + ("ivector2", Value::Int(-23), Value::Int2([-23, 0])), + ("ivector3", Value::Int(17), Value::Int3([17, 0, 0])), + ("ivector4", Value::Int(7), Value::Int4([7, 0, 0, 0])), + ("ivector4", Value::Int2([17, -23]), Value::Int4([17, -23, 0, 0])), ] { let mut graph = FunctionGraph::default(); - let inputs = [first.map(|value| graph.add_constant(value)), last.map(|value| graph.add_constant(value))]; - let id = graph.add(operation, &[], None); - graph.nodes.last_mut().unwrap().inputs = inputs.to_vec(); - graph.output = Some(id); + let source = graph.add_constant(input); + graph.output = Some(graph.add(operation, &[], None)); let variables = Default::default(); - let context = EvaluationContext { scope: Default::default(), position: [0.5; 2], size: [16.0; 2], images: &[], tile: true, variables: &variables }; + let context = EvaluationContext { + image_formats: &[], + scope: Default::default(), + position: [0.5; 2], + size: [16.0; 2], + images: &[], + tile: true, + variables: &variables, + }; - assert_eq!(compile(&graph, 0).unwrap().evaluate(&context, &mut EvaluationState::default()), Ok(expected), "{operation}"); + for inputs in [[None, Some(source)], [Some(source), None]] { + graph.nodes.last_mut().unwrap().inputs = inputs.to_vec(); + let value = compile(&graph, 0).unwrap().evaluate(&context, &mut EvaluationState::default()).unwrap(); + assert_eq!(value, expected, "{operation} {inputs:?}"); + } } } @@ -67,7 +90,15 @@ fn partially_connected_dot_uses_the_connected_vector_width() { graph.nodes.last_mut().unwrap().inputs = if connected_slot == 0 { vec![Some(source), None] } else { vec![None, Some(source)] }; graph.output = Some(dot); let variables = Default::default(); - let context = EvaluationContext { scope: Default::default(), position: [0.5; 2], size: [16.0; 2], images: &[], tile: true, variables: &variables }; + let context = EvaluationContext { + image_formats: &[], + scope: Default::default(), + position: [0.5; 2], + size: [16.0; 2], + images: &[], + tile: true, + variables: &variables, + }; assert_eq!(compile(&graph, 0).unwrap().evaluate(&context, &mut EvaluationState::default()), Ok(Value::Float(0.0))); } diff --git a/crates/nodes/src/function/vector.rs b/crates/nodes/src/function/vector.rs index f25f29f6..f1109d03 100644 --- a/crates/nodes/src/function/vector.rs +++ b/crates/nodes/src/function/vector.rs @@ -1,6 +1,85 @@ use super::value_type::{dimensions, floats, integer_value, integers, intermediate_float_value as float_value}; use materialcraft_core::Value; +#[derive(Clone, Copy)] +pub(super) enum PatternComponent { + Register(usize), + Zero, +} + +/// Evaluate packed pattern components in the order their consumers read them. +pub(super) fn identify_pattern_components(program: &mut super::Program, end: usize, root: bool) { + let instructions = &program.instructions; + let prefix = &instructions[..end]; + let mut packed_results: std::collections::BTreeSet<_> = prefix + .iter() + .filter_map(|op| match (op.definition.id, op.inputs.as_slice()) { + ("set", &[source]) if super::returned_product::float_width(op.type_code) > 1 => Some(source), + _ => None, + }) + .collect(); + // Writing the final vector to a pattern property consumes its components in the same order as a Set. + if root && prefix.get(program.output).is_some_and(|op| super::returned_product::float_width(op.type_code) > 1) { + packed_results.insert(program.output); + } + if (packed_results.is_empty() && !prefix.iter().any(|op| op.definition.id == "swizzle1" || op.call.is_some())) + || !prefix.iter().any(|op| matches!(op.definition.id, "rand" | "set") || op.call.is_some()) + { + return; + } + let mut sources = Vec::with_capacity(prefix.len()); + let mut projections = Vec::new(); + let mut generated = Vec::new(); + let mut ranges = Vec::with_capacity(prefix.len()); + for (index, op) in prefix.iter().enumerate() { + let start = instructions.len() + generated.len(); + let mut lanes = [None; 4]; + if let Some(forwarded) = super::returned_product::forwarded(op, instructions, &sources, Some(PatternComponent::Zero)) { + lanes = forwarded; + if op.definition.id == "swizzle1" + && let Some(source) = lanes[0] + { + program.pattern_components.insert(index, source); + } + } else if let Some(projected) = super::pattern_channel_operations::project(op, instructions, &sources, &mut generated) { + lanes = projected; + // A complete conditional still owns its branch effects. For arithmetic, finish the + // operands of the first stored component before drawing those of the next component. + if packed_results.contains(&index) + && op.definition.id != "ifelse" + && let Some(packed) = super::pattern_channel_operations::pack(op, instructions.len(), &lanes, &mut generated) + { + program.pattern_components.insert(index, PatternComponent::Register(packed)); + } + } else if let Some(call) = &op.call { + if let Some(arguments) = &call.pattern_arguments { + lanes = arguments.channels.map(|register| register.map(PatternComponent::Register)); + } else if let Some(projection) = call.packed_projection(&op.inputs, &sources).or_else(|| call.packed_arithmetic(&op.inputs, &sources)) { + lanes = projection.channels.map(|register| register.map(PatternComponent::Register)); + projections.push((index, projection)); + } + } + if op.type_code == 256 && lanes[0].is_none() { + lanes[0] = Some(PatternComponent::Register(index)); + } + sources.push(lanes); + ranges.push(start..instructions.len() + generated.len()); + } + for (index, projection) in projections { + if let Some(call) = program.instructions.get_mut(index).and_then(|op| op.call.as_mut()) { + call.pattern_arguments = Some(projection); + } + } + if !generated.is_empty() { + for op in program.instructions.iter_mut().filter(|op| op.definition.id == "while") { + // Each repetition also invalidates the scalar channels derived from its condition or body. + let repeated: Vec<_> = op.control_registers.iter().filter_map(|&i| ranges.get(i)).flat_map(|r| r.clone()).collect(); + op.control_registers.extend(repeated); + } + program.instructions.extend(generated); + } +} + pub(crate) fn evaluate(op: &str, args: &[Value], setting: Option<&Value>) -> Result { let first = args.first().ok_or("missing vector input")?; let count = op.chars().last().and_then(|c| c.to_digit(10)).unwrap_or(1) as usize; diff --git a/crates/nodes/src/lib.rs b/crates/nodes/src/lib.rs index caca06fb..d4766811 100644 --- a/crates/nodes/src/lib.rs +++ b/crates/nodes/src/lib.rs @@ -5,9 +5,11 @@ pub mod atomic; pub mod catalog; pub mod function; pub mod ops; +pub mod output_precision; pub mod pattern; mod raster; +mod bitmap_color_space; mod cook_context; pub mod graph_interface; mod image_input; @@ -20,9 +22,11 @@ mod parameter_descriptor; mod port_definition; mod port_kind; mod random; +mod texture_sampler; +pub use bitmap_color_space::BitmapColorSpace; pub use catalog::{catalog, categories, find}; -pub use cook_context::CookContext; +pub use cook_context::{CookContext, GraphVariables}; pub use image_input::{MAX_IMAGE_INPUTS, image_input_prefix}; pub use node_definition::NodeDefinition; pub(crate) use node_definition_builder::node; @@ -32,6 +36,7 @@ pub use parameter_definition::ParameterDefinition; pub use parameter_descriptor::ParameterDescriptor; pub use port_definition::PortDefinition; pub use port_kind::PortKind; +pub use texture_sampler::{resize_bound_image, resize_connected_image, resize_input_level}; pub type CookResult = Result, String>; pub type Cook = fn(&CookContext<'_>) -> CookResult; diff --git a/crates/nodes/src/node_definition.rs b/crates/nodes/src/node_definition.rs index 2ffeedc1..f3629e85 100644 --- a/crates/nodes/src/node_definition.rs +++ b/crates/nodes/src/node_definition.rs @@ -11,6 +11,8 @@ pub struct NodeDefinition { pub inputs: Vec, /// The input supplying inherited base parameters, when it differs from port order pub primary_input: Option<&'static str>, + /// The image passed through when bypassed. Without a designated port, use the first wired image. + pub bypass_input: Option<&'static str>, pub outputs: Vec, pub params: Vec, /// A generator takes its size from the graph, not from an input diff --git a/crates/nodes/src/node_definition_builder.rs b/crates/nodes/src/node_definition_builder.rs index b8574d44..0f5ac240 100644 --- a/crates/nodes/src/node_definition_builder.rs +++ b/crates/nodes/src/node_definition_builder.rs @@ -16,6 +16,7 @@ pub(crate) fn node(id: &'static str, label: &'static str, category: &'static str description: "", inputs: Vec::new(), primary_input: None, + bypass_input: None, outputs: Vec::new(), params: Vec::new(), generator: false, @@ -46,6 +47,11 @@ impl NodeDefinitionBuilder { } pub fn primary_input(mut self, identifier: &'static str) -> Self { + self.0.bypass_input = Some(identifier); + self.inherit_from(identifier) + } + + pub fn inherit_from(mut self, identifier: &'static str) -> Self { self.0.primary_input = Some(identifier); self } diff --git a/crates/nodes/src/ops.rs b/crates/nodes/src/ops.rs index 7fbc4f1f..85e0c596 100644 --- a/crates/nodes/src/ops.rs +++ b/crates/nodes/src/ops.rs @@ -314,16 +314,14 @@ 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), 8 => { - if f.abs() < 1e-6 { - if b > 0.0 { 1.0 } else { 0.0 } - } else { - b / f - } + // A zero divisor produces this finite HDR value even when the numerator is zero. + if f == 0.0 { 16_777_216.0 } else { crate::function::pixel_divide(b, f) } } 9 => { if b < 0.5 { @@ -366,8 +364,42 @@ pub fn blend_channel(mode: i32, b: f32, f: f32) -> f32 { /// `blend_alpha`: composite coverage; false preserves background alpha. #[inline] pub fn blend_px(mode: i32, bg: [f32; 4], fg: [f32; 4], opacity: f32, color_blending: i32, blend_alpha: bool, clamp: bool) -> [f32; 4] { - // Switch already interpolates RGBA; another alpha weight composites twice - let t = opacity * if mode != 7 { fg[3] } else { 1.0 }; + if mode == 7 { + // Switch interpolates each channel directly, including alpha. + let mut out = if opacity > 0.0 && opacity < 1.0 { + // Fractional weights flush subnormals before multiplication, after the first product and after the final add. + use crate::function::flush_subnormal; + std::array::from_fn(|k| { + let foreground = flush_subnormal(flush_subnormal(fg[k]) * opacity); + flush_subnormal(flush_subnormal(bg[k]).mul_add(1.0 - opacity, foreground)) + }) + } else { + std::array::from_fn(|k| bg[k].mul_add(1.0 - opacity, fg[k] * opacity)) + }; + if clamp { + for c in &mut out[..3] { + *c = c.clamp(0.0, 1.0); + } + } + return out; + } + if ((0..=2).contains(&mode) && color_blending == 0) || (matches!(mode, 3..=6 | 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; + let background_weight = (-alpha).mul_add(opacity, 1.0); + let mut out = bg; + for k in 0..3 { + let color = bg[k].mul_add(background_weight, blend_channel(mode, bg[k], fg[k]) * source_weight); + out[k] = if clamp { color.clamp(0.0, 1.0) } else { color }; + } + if blend_alpha { + out[3] = (1.0 - bg[3]).mul_add(fg[3] * opacity, bg[3]); + } + return out; + } + + let t = opacity * fg[3]; let coverage = bg[3] * (1.0 - t) + t; let mut o = [0.0; 4]; for k in 0..3 { @@ -375,12 +407,12 @@ pub fn blend_px(mode: i32, bg: [f32; 4], fg: [f32; 4], opacity: f32, color_blend // Weight before adding to preserve integer-boundary rounding o[k] = match color_blending { - 1 if mode != 7 => bg[k] * (1.0 - opacity) + v * opacity, - 2 if mode != 7 && coverage > 0.0 => { + 1 => bg[k] * (1.0 - opacity) + v * opacity, + 2 if coverage > 0.0 => { let v = if clamp { v.clamp(0.0, 1.0) } else { v }; (bg[k] * bg[3] * (1.0 - t) + fg[k] * t * (1.0 - bg[3]) + v * bg[3] * t) / coverage } - 2 if mode != 7 => bg[k], + 2 => bg[k], 3 if mode == 0 => bg[k] * (1.0 - t) + fg[k] * opacity, _ => bg[k] * (1.0 - t) + v * t, }; @@ -389,13 +421,7 @@ pub fn blend_px(mode: i32, bg: [f32; 4], fg: [f32; 4], opacity: f32, color_blend } } - o[3] = if mode == 7 { - bg[3] * (1.0 - opacity) + fg[3] * opacity - } else if blend_alpha || color_blending == 2 || (color_blending == 3 && mode == 0) { - coverage - } else { - bg[3] - }; + o[3] = if blend_alpha || color_blending == 2 || (color_blending == 3 && mode == 0) { coverage } else { bg[3] }; o } @@ -410,6 +436,32 @@ pub fn gray_from(w: u32, h: u32, v: Vec) -> Result { mod tests { use super::*; + #[test] + fn add_sub_blend_weights_source_color_and_coverage_separately() { + let background = [24.0, 5.0, 8.0, 8.0].map(|byte| byte / 255.0); + let foreground = [231.0, 250.0, 247.0, 8.0].map(|byte| byte / 255.0); + let result = blend_px(4, background, foreground, 0.5, 0, true, false); + assert_eq!(result.map(f32::to_bits), [0x3dda_d4cf, 0x3d0e_0b89, 0x3d3c_b8b5, 0x3d3e_bcbb]); + } + + #[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] { + assert_eq!(blend_channel(8, numerator, 0.0), 16_777_216.0); + assert_eq!(blend_channel(8, numerator, -0.0), 16_777_216.0); + } + assert_eq!(blend_channel(8, -8.0, 1e-10), -80_000_000_000.0); + } + #[test] fn color_dodge_and_burn_keep_black_and_white_backgrounds() { const DODGE: i32 = 13; diff --git a/crates/nodes/src/output_precision.rs b/crates/nodes/src/output_precision.rs new file mode 100644 index 00000000..7495c908 --- /dev/null +++ b/crates/nodes/src/output_precision.rs @@ -0,0 +1,81 @@ +use craft_texture::{Image, Limits}; +use materialcraft_core::OutputFormat; +use std::sync::Arc; + +/// Round to the half value used when storing a cooked channel. +pub fn store_half(pixel: f32) -> f32 { + if !pixel.is_finite() { + return if pixel.is_nan() { half::f16::from_bits(0x7fff).to_f32() } else { pixel }; + } + let value = pixel.clamp(-65504.0, 65504.0); + let rounded = half::f16::from_f32(value); + if rounded.to_f32().abs() > value.abs() { half::f16::from_bits(rounded.to_bits().saturating_sub(1)).to_f32() } else { rounded.to_f32() } +} + +fn store_normalized(pixel: f32, fraction: f64, maximum: f64) -> f32 { + let value = if pixel.is_nan() { 0.0 } else { f64::from(pixel).clamp(0.0, 1.0) }; + let fixed = (value * fraction).floor() / fraction; + let integer = (fixed * maximum - 0.5).ceil() as u32; + integer as f32 / maximum as f32 +} + +fn normalized_scale(format: OutputFormat) -> Option<(f64, f64)> { + match format { + OutputFormat::U8 => Some((4096.0, f64::from(u8::MAX))), + OutputFormat::Inherit | OutputFormat::U16 => Some((1_048_576.0, f64::from(u16::MAX))), + OutputFormat::F16 | OutputFormat::F32 => None, + } +} + +/// Store a single border texel at the precision of the image being sampled. +pub(crate) fn store_pixel(pixel: [f32; 4], format: OutputFormat) -> [f32; 4] { + if let Some((fraction, maximum)) = normalized_scale(format) { + pixel.map(|v| store_normalized(v, fraction, maximum)) + } else if format == OutputFormat::F16 { + pixel.map(store_half) + } else { + pixel + } +} + +/// Store a cooked image at its destination precision, including intermediate mip levels. +pub fn apply(image: Image, format: OutputFormat) -> Image { + let integer = integer_sampling(format); + if format == OutputFormat::F16 { + // Half-float storage saturates finite overflow and truncates toward zero. + return with_pixels(image, integer, |pixel| *pixel = store_half(*pixel)); + } + + let Some((fraction, maximum)) = normalized_scale(format) else { + return image.with_integer_sampling(integer); + }; + + // Integer outputs retain four fractional guard bits before halfway-down rounding. + with_pixels(image, integer, |pixel| *pixel = store_normalized(*pixel, fraction, maximum)) +} + +fn integer_sampling(format: OutputFormat) -> bool { + matches!(format, OutputFormat::Inherit | OutputFormat::U8 | OutputFormat::U16) +} + +/// `image` with `convert` applied to every float and the integer-sampling flag set. The buffer is +/// changed in place when no other image shares it, and copied once otherwise. +fn with_pixels(image: Image, integer_sampling: bool, convert: impl Fn(&mut f32)) -> Image { + let (width, height, kind) = (image.width(), image.height(), image.kind()); + + // Limits that admit any valid image, so one made with raised limits keeps its size + let mut limits = Limits::default(); + limits.max_side = u32::MAX; + limits.max_pixels = u64::MAX; + limits.max_bytes = u64::MAX; + + let mut data = Arc::clone(image.shared_data()); + drop(image); + + Arc::make_mut(&mut data).iter_mut().for_each(convert); + + // `data` keeps the size and kind of a valid image, so `from_data` accepts it + Image::from_data(width, height, kind, data, &limits) + .unwrap_or_else(|_| Image::filled(width, height, kind, [0.0; 4])) + .with_integer_sampling(integer_sampling) +} diff --git a/crates/nodes/src/parameter.rs b/crates/nodes/src/parameter.rs index d3ca0554..719efe2b 100644 --- a/crates/nodes/src/parameter.rs +++ b/crates/nodes/src/parameter.rs @@ -5,7 +5,7 @@ use std::collections::BTreeMap; /// How many slider spans the hard limit extends past each end of a parameter's range const HARD_SPAN: f32 = 16.0; -/// Native channel controls also accept a single grayscale value, broadcast by the evaluator. +/// Native channel controls also accept a single grayscale function result. /// Other vector parameters keep their exact function output type. pub fn accepts_scalar_function(definition: &str, parameter: &str) -> bool { matches!((definition, parameter), ("levels", "in_low" | "in_mid" | "in_high" | "out_low" | "out_high") | ("fx_map", "background")) @@ -17,6 +17,13 @@ fn clamp_finite(v: f32, lo: f32, hi: f32, fallback: f32) -> f32 { } pub fn clamp_params(definition: &NodeDefinition, params: &mut BTreeMap) { + if definition.id == "grayscale_conversion" + && let Some(Value::Float4(weights)) = params.get_mut("weights") + { + for (weight, fallback) in weights.iter_mut().zip([1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0, 0.0]) { + *weight = clamp_finite(*weight, -HARD_SPAN, 1.0 + HARD_SPAN, fallback); + } + } for parameter in &definition.params { let Some(value) = params.get_mut(parameter.id) else { continue }; if let Value::Enum(index) = value { @@ -34,15 +41,27 @@ pub fn clamp_params(definition: &NodeDefinition, params: &mut BTreeMap) m.insert(k.clone(), v.clone()); } } + if def.id == "grayscale_conversion" + && let Some(Value::Float4(weights)) = overrides.get("weights") + { + m.insert("weights".into(), Value::Float4(*weights)); + } clamp_params(def, &mut m); m } diff --git a/crates/nodes/src/parameter.test.rs b/crates/nodes/src/parameter.test.rs index 5ecacfd1..afcb044f 100644 --- a/crates/nodes/src/parameter.test.rs +++ b/crates/nodes/src/parameter.test.rs @@ -19,9 +19,13 @@ fn resolve_params_clamps_to_hard_limits() { assert_eq!(p["opacity"], Value::Float(-16.0)); let p = resolve_params(def, &over("opacity", Value::Float(f32::NAN))); assert_eq!(p["opacity"], def.param("opacity").unwrap().default); +} + +#[test] +fn levels_preserves_finite_float_endpoints_beyond_the_slider() { let levels = find("levels").unwrap(); - let p = resolve_params(levels, &over("in_low", Value::Float4([1e9, -1e9, 0.0, 1.0]))); - assert_eq!(p["in_low"], Value::Float4([17.0, -16.0, 0.0, 1.0])); + let p = resolve_params(levels, &over("in_low", Value::Float4([1024.0, -1e12, 0.0, f32::NAN]))); + assert_eq!(p["in_low"], Value::Float4([1024.0, -1e12, 0.0, 0.0])); } #[test] diff --git a/crates/nodes/src/parameter_descriptor.rs b/crates/nodes/src/parameter_descriptor.rs index 1aba2be6..ad29209c 100644 --- a/crates/nodes/src/parameter_descriptor.rs +++ b/crates/nodes/src/parameter_descriptor.rs @@ -35,6 +35,18 @@ impl ParameterDescriptor { } pub fn for_node(package: &Package, node: &Node, parameter: &str) -> Option { + if node.def == "grayscale_conversion" && parameter == "weights" { + // A single function can drive the four channel controls together. + return Some(Self { + id: parameter.into(), + label: "RGBA weights".into(), + default: Value::Float4([1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0, 0.0]), + min: 0.0, + max: 1.0, + options: Vec::new(), + supports_function: true, + }); + } if node.def == "graph_instance" { let source = node .instance @@ -45,7 +57,8 @@ impl ParameterDescriptor { Some(Value::Text(name)) => Some(name.as_str()), _ => None, }); - if let Some((_, graph)) = source.zip(name).and_then(|(source, name)| source.graph_by_name(name)) + let graph = source.zip(name).and_then(|(source, name)| source.graph_by_name(name)).map(|(_, graph)| graph); + if let Some(graph) = graph && let Some(input) = graph.exposed.iter().find(|input| input.id == parameter) { return Some(Self { @@ -59,7 +72,24 @@ impl ParameterDescriptor { }); } - let default = node.instance.as_ref()?.defaults.get(parameter)?.clone(); + let bridge = graph.and_then(|graph| { + graph.nodes.iter().find(|bridge| { + bridge.def == "input_value" + && match bridge.params.get("identifier") { + Some(Value::Text(name)) if !name.is_empty() => name == parameter, + _ => parameter == "input", + } + }) + }); + let default = if let Some(bridge) = bridge { + bridge.params.get("default").cloned().unwrap_or(Value::Float(0.0)) + } else { + let interface = node.instance.as_ref()?; + interface.defaults.get(parameter).cloned().or_else(|| { + let port = interface.inputs.iter().find(|port| port.identifier == parameter)?; + Some(ValueType::from_code(port.type_code)?.default_value()) + })? + }; return Some(Self { id: parameter.into(), label: parameter.into(), diff --git a/crates/nodes/src/pattern/bitmap.rs b/crates/nodes/src/pattern/bitmap.rs new file mode 100644 index 00000000..c9639d15 --- /dev/null +++ b/crates/nodes/src/pattern/bitmap.rs @@ -0,0 +1,144 @@ +use craft_texture::{Image, Limits}; +use materialcraft_core::OutputFormat; +use std::collections::BTreeMap; + +use super::coordinates::PixelPlanes; +use crate::texture_sampler; + +pub(super) struct Mipmaps { + levels: BTreeMap>, + remaining_bytes: u64, +} + +impl Mipmaps { + pub fn new() -> Self { + Self { levels: BTreeMap::new(), remaining_bytes: Limits::default().max_bytes } + } + + pub fn image(&mut self, slot: usize, source: &Image, format: OutputFormat, level: usize) -> Result { + if level == 0 { + return Ok(source.clone()); + } + let levels = self.levels.entry(slot).or_default(); + while levels.len() < level { + let previous = levels.last().unwrap_or(source); + if previous.width() == 1 && previous.height() == 1 { + return Ok(previous.clone()); + } + let texels = u64::from(previous.width().div_ceil(2)) * u64::from(previous.height().div_ceil(2)); + let bytes = texels * previous.channels() as u64 * size_of::() as u64; + // Stamps share cached levels. Bound their combined storage across distinct image slots. + self.remaining_bytes = self.remaining_bytes.checked_sub(bytes).ok_or("pattern mipmaps exceeded their memory budget")?; + levels.push(texture_sampler::reduce_level(previous, format, format)); + } + levels.get(level - 1).cloned().ok_or_else(|| "missing pattern mipmap".into()) + } +} + +pub(super) struct Sampler<'a> { + source: &'a Image, + slot: usize, + format: OutputFormat, + filtering: i32, + fallback_level: usize, + level: usize, + image: Image, + last_quad: Option<[u32; 2]>, +} + +impl<'a> Sampler<'a> { + pub fn new(source: &'a Image, slot: usize, format: OutputFormat, filtering: i32, fallback: [[f32; 2]; 2]) -> Self { + let fallback_level = if filtering == 0 { mip_level(source, fallback) } else { 0 }; + Self { source, slot, format, filtering, fallback_level, level: 0, image: source.clone(), last_quad: None } + } + + pub fn start_copy(&mut self) { + self.last_quad = None; + } + + pub fn sample(&mut self, local: [f32; 2], pixel: [u32; 2], planes: Option<&PixelPlanes>, mipmaps: &mut Mipmaps) -> Result<[f32; 4], String> { + let quad = pixel.map(|v| v & !1); + if self.filtering == 0 && self.last_quad != Some(quad) { + self.last_quad = Some(quad); + let level = planes.map_or(self.fallback_level, |p| mip_level(self.source, p.quad_gradients(quad))); + if level != self.level { + self.image = mipmaps.image(self.slot, self.source, self.format, level)?; + self.level = level; + } + } + Ok(sample(&self.image, local, self.format, self.filtering == 2)) + } +} + +fn mip_level(image: &Image, gradients: [[f32; 2]; 2]) -> usize { + let [dx, dy] = gradients.map(|[u, v]| [u * image.width() as f32, v * image.height() as f32].map(truncate_derivative)); + let footprint = |[x, y]: [f32; 2]| { + let (mantissa, unit) = derivative_parts(x.abs().min(y.abs())); + x.abs().max(y.abs()) + ((11 * mantissa + 4) >> 5) as f32 * unit + }; + let [u_sum, u_diff] = diagonal_components(dx[0], dy[0]); + let [v_sum, v_diff] = diagonal_components(dx[1], dy[1]); + let diagonal = diagonal_footprint(u_sum, v_sum).max(diagonal_footprint(u_diff, v_diff)); + let bits = footprint(dx).max(footprint(dy)).max(diagonal).max(1.0).to_bits(); + // The first measured half-level boundary is 1 + 53/128 and repeats at each power of two. + let exponent = (bits >> 23).saturating_sub(127); + (exponent + u32::from(bits & 0x7f_ffff >= 53 << 16)).min(13) as usize +} + +fn truncate_derivative(value: f32) -> f32 { + f32::from_bits(value.to_bits() & !0x3fff) +} + +// The stored derivative has nine fraction bits. The unit belongs to the input exponent. +fn derivative_parts(magnitude: f32) -> (u32, f32) { + let bits = magnitude.to_bits(); + (512 + ((bits >> 14) & 511), f32::from_bits(bits & 0x7f80_0000) / 512.0) +} + +fn diagonal_components(a: f32, b: f32) -> [f32; 2] { + let exponent = |v: f32| (v.to_bits() >> 23) & 255; + let common = exponent(a).max(exponent(b)); + // Keep one guard bit below the larger component's nine fraction bits before + // adding or subtracting. Cancellation can expose that bit in the diagonal. + let align = |v| match common - exponent(v) { + 0 | 1 => v, + gap @ 2..=10 => f32::from_bits(v.to_bits() & (u32::MAX << (13 + gap))), + _ => 0.0, + }; + let (a, b) = (align(a), align(b)); + [a + b, a - b] +} + +fn diagonal_footprint(u: f32, v: f32) -> f32 { + let major = u.abs().max(v.abs()); + let (_, major_unit) = derivative_parts(major); + let (minor_mantissa, minor_unit) = derivative_parts(u.abs().min(v.abs())); + // Scale each component before summing. The major rounds down at the weighted + // exponent after a quarter input unit of bias. The minor also includes the 11/32 axis weight. + let major = truncate_derivative(truncate_derivative(major) * (11.0 / 16.0) + major_unit * 0.25); + let minor = ((121 * minor_mantissa + 32) >> 9) as f32 * minor_unit; + major + minor +} + +fn sample(image: &Image, local: [f32; 2], format: OutputFormat, nearest: bool) -> [f32; 4] { + let uv = local.map(|axis| axis * 0.5 + 0.5); + if nearest { + if uv.iter().all(|v| (0.0..1.0).contains(v)) { image.sample_nearest_axes(uv[0], uv[1], [false; 2]) } else { [0.0; 4] } + } else { + texture_sampler::sample(image, uv, [false; 2], format, Some([0.0; 4])) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn bitmap_diagonal_gradients_cross_half_levels_in_both_directions() { + let image = Image::gray(32, 32, |_, _| 0.0); + for (texel_steps, expected) in [([[1864, -2248], [1874, 861]], 1), ([[1884, 649], [1884, 649]], 0), ([[1814, -841], [-2192, -1450]], 0)] { + let gradients = texel_steps.map(|pair| pair.map(|v| v as f32 / (2048.0 * 32.0))); + assert_eq!(mip_level(&image, gradients), expected, "{texel_steps:?}"); + } + } +} diff --git a/crates/nodes/src/pattern/blend.rs b/crates/nodes/src/pattern/blend.rs new file mode 100644 index 00000000..9c242b70 --- /dev/null +++ b/crates/nodes/src/pattern/blend.rs @@ -0,0 +1,62 @@ +pub(super) fn color(background: f32, source: f32, alpha: f32, mode: i32, channel: usize) -> f32 { + if mode == 0 { + // A zero contribution retains the background, including its zero sign. + if source == 0.0 { + return background; + } + return if channel == 3 { weighted_sum(source, 1.0 - background, background) } else { background + source }; + } + let remaining = 1.0 - alpha; + if remaining == 0.0 && source == 0.0 { 0.0 } else { weighted_sum(background, remaining, source) } +} + +/// Blend a weighted component and an addend at the precision of the stamp accumulator. +fn weighted_sum(value: f32, weight: f32, addend: f32) -> f32 { + if !value.is_finite() || !weight.is_finite() || !addend.is_finite() { + return value.mul_add(weight, addend); + } + if addend == 0.0 { + return value * weight; + } + if value == 0.0 || weight == 0.0 { + return addend; + } + + let (value_mantissa, value_exponent) = components(value); + let (weight_mantissa, weight_exponent) = components(weight); + let (addend_mantissa, addend_exponent) = components(addend); + let product_exponent = value_exponent + weight_exponent; + let aligned = product_exponent.max(addend_exponent - 1); + // Both integers have 46 fraction bits, before normalizing the product. + // Keep 26 at the common exponent. Any discarded nonzero tail sets the low bit. + let align = |mantissa: u64, exponent: i32| { + let shift = (46 - 26 + aligned - exponent).min(63) as u32; + let high = mantissa >> shift; + (high | u64::from((high << shift) != mantissa)) as i32 + }; + let product = align(value_mantissa * weight_mantissa, product_exponent); + let add = align(addend_mantissa << 23, addend_exponent); + let signed_product = if value.is_sign_negative() == weight.is_sign_negative() { product } else { -product }; + let sum = if addend.is_sign_negative() { signed_product - add } else { signed_product + add }; + + // After cancellation removes two or more leading bits, discard the low + // guard bits at the original operand precision before storing the result. + let shift = (product_exponent.max(addend_exponent) - aligned) as u32; + let magnitude = sum.unsigned_abs(); + let stored = if magnitude < (1 << (25 + shift)) { magnitude & !((2 << shift) - 1) } else { magnitude }; + let unit = f64::from_bits(((1023 + aligned - 26) as u64) << 52); + (f64::from(stored).copysign(f64::from(sum)) * unit) as f32 +} + +/// Exact 24-bit significand and unbiased exponent of a nonzero finite component. +fn components(value: f32) -> (u64, i32) { + let bits = value.to_bits(); + let biased = (bits >> 23) & 255; + if biased == 0 { + // Widening normalizes every single-precision subnormal exactly. + let wide = f64::from(value.abs()).to_bits(); + (0x80_0000 | ((wide >> 29) & 0x7f_ffff), (wide >> 52) as i32 - 1023) + } else { + (u64::from(0x80_0000 | (bits & 0x7f_ffff)), biased as i32 - 127) + } +} diff --git a/crates/nodes/src/pattern/catalog.rs b/crates/nodes/src/pattern/catalog.rs index 45f96a84..a74ce1ad 100644 --- a/crates/nodes/src/pattern/catalog.rs +++ b/crates/nodes/src/pattern/catalog.rs @@ -17,9 +17,9 @@ pub fn definitions() -> &'static [NodeDefinition] { .angle("patternrotation", "Pattern rotation", 0.0) .float("patternsuppl", "Pattern variation", 0.0, 0.0, 1.0) .int("blendingmode", "Blending", 0, 0, 2) - .int("imagefiltering", "Image filtering", 1, 0, 1) + .int("imagefiltering", "Image filtering", 0, 0, 2) .boolean("imagepremul", "Premultiplied image", false) - .int("imageindex", "Image input", 1, 1, crate::MAX_IMAGE_INPUTS as i32) + .int("imageindex", "Image input", 0, 0, crate::MAX_IMAGE_INPUTS as i32 - 1) .int("randomseed", "Random seed", 0, 0, 10000) .boolean("randominherited", "Inherit random seed", true) .cook(crate::node_definition_builder::no_cook), diff --git a/crates/nodes/src/pattern/conditional_tint.rs b/crates/nodes/src/pattern/conditional_tint.rs new file mode 100644 index 00000000..4be70d30 --- /dev/null +++ b/crates/nodes/src/pattern/conditional_tint.rs @@ -0,0 +1,196 @@ +use super::pattern_stamp::PatternStamp; +use super::stamp_cache::{self, Key, Properties}; +use crate::function::{EvaluationState, PatternExpression, Program, flush_subnormal}; +use materialcraft_core::{Value, ValueType}; +use std::collections::{BTreeMap, BTreeSet, HashMap}; + +/// A scalar tint whose two branches use the same seeded value. One branch +/// multiplies it by a live variable. Its prefix also publishes the frame offset. +pub(super) struct ConditionalTint<'a> { + pub offset: &'a str, + condition: &'a str, + threshold: f32, + multiplier: &'a str, + base: usize, +} + +impl<'a> ConditionalTint<'a> { + pub fn identify(program: &'a Program, assigned: &BTreeSet<&str>) -> Option { + let inputs = |index: usize, name: &str| { + let op = program.instructions.get(index)?; + (op.definition.id == name).then_some(op.inputs.as_slice()) + }; + let variable = |index: usize, kind: &str| { + let op = program.instructions.get(index)?; + match &op.value { + Some(Value::Text(name)) if op.definition.id == kind => Some(name.as_str()), + _ => None, + } + }; + let &[prefix, result] = inputs(program.output, "sequence")? else { return None }; + let &[written] = inputs(prefix, "set")? else { return None }; + let offset = variable(prefix, "set")?; + let &[test, scaled, base] = inputs(result, "ifelse")? else { return None }; + let &[a, b] = inputs(scaled, "mul")? else { return None }; + if program.instructions.get(scaled)?.type_code != ValueType::Float as u32 { + return None; + } + let multiplier = variable( + if a == base { + b + } else if b == base { + a + } else { + return None; + }, + "get_float1", + )?; + let &[variable_index, literal] = inputs(test, "gt")? else { return None }; + let condition = variable(variable_index, "get_float1")?; + inputs(literal, "const_float1")?; + let Some(Value::Float(threshold)) = program.instructions.get(literal)?.value.as_ref() else { return None }; + if !threshold.is_finite() + || offset == condition + || offset == multiplier + || multiplier.starts_with('$') + || (condition.starts_with('$') && condition != "$number") + { + return None; + } + // These two results can share operations and random draws. Capture the + // ordinary evaluator's registers after it has followed the chosen branch. + if !stamp_cache::reusable_inputs(program, &[written, base], assigned) { + return None; + } + Some(Self { offset, condition, threshold: *threshold, multiplier, base }) + } + + pub fn scale(&self, variables: &BTreeMap) -> Option { + let Value::Float(condition) = variables.get(self.condition)? else { return None }; + if !condition.is_finite() { + return None; + } + if *condition > self.threshold { + let Value::Float(scale) = variables.get(self.multiplier)? else { return None }; + scale.is_finite().then_some(TintScale::Multiply(*scale)) + } else { + Some(TintScale::Identity) + } + } + + pub fn base(&self, state: &EvaluationState) -> Option { + match state.registers.get(self.base)?.as_ref()? { + Value::Float(value) if value.is_finite() => Some(*value), + _ => None, + } + } +} + +#[derive(Clone, Copy)] +pub(super) enum TintScale { + Identity, + Multiply(f32), +} + +impl TintScale { + pub(super) fn apply(self, value: f32) -> f32 { + match self { + Self::Identity => value, + Self::Multiply(scale) => flush_subnormal(flush_subnormal(value) * flush_subnormal(scale)), + } + } +} + +pub(super) struct DrawingFields<'a> { + pub fields: BTreeMap<&'static str, PatternExpression<'a>>, + pub cost: usize, +} + +#[derive(Default)] +pub(super) struct DrawingExpressions<'a>(BTreeMap<(u32, u32, bool), Option>>); + +impl<'a> DrawingExpressions<'a> { + // Charge compact arithmetic in fractions of an ordinary property pass. + // Even a completely folded draw still pays for property dispatch and placement. + pub(super) const FULL_COST: usize = 128; + + pub(super) fn for_draw( + &mut self, + visit: &super::pattern_visit::PatternVisit, + tint: Option<(&ConditionalTint<'_>, TintScale)>, + placement: bool, + programs: &'a super::evaluation::PropertyPrograms<'_>, + variables: &BTreeMap, + assigned: &BTreeSet<&str>, + ) -> Option<&mut DrawingFields<'a>> { + let scaled = matches!(tint, Some((_, TintScale::Multiply(_)))); + let key = (visit.node, visit.depth, scaled); + // A graph can share a quadrant at many depths. Cap retained programs and failed bindings together. + if self.0.len() >= 64 && !self.0.contains_key(&key) { + return None; + } + self.0 + .entry(key) + .or_insert_with(|| { + let mut fields = BTreeMap::new(); + let (mut compact, mut ordinary) = (16, 16); + let active: &[&str] = if tint.is_some() { + &["opacity", "branchoffset", "patternsize", "patternrotation"] + } else if placement { + // The stamp cache verified that only these seeded fields vary for this quadrant. + &["opacity", "frameoffset", "patternrotation"] + } else { + &["branchoffset"] + }; + for &field in active { + if let Some((program, _)) = programs.get(&(visit.node, field)) { + let tint = tint.filter(|_| field == "opacity").map(|(tint, _)| (tint.base, scaled)); + let expression = PatternExpression::bind(program, variables, assigned, tint)?; + let (steps, visits) = expression.work(); + compact += steps; + ordinary += visits; + fields.insert(field, expression); + } + } + let cost = (compact * Self::FULL_COST).div_ceil(ordinary).clamp(Self::FULL_COST / 4, Self::FULL_COST); + Some(DrawingFields { fields, cost }) + }) + .as_mut() + } +} + +#[derive(Default)] +pub(super) struct ConditionalStamps { + fields: HashMap<(Key, bool), [f32; 8]>, + templates: HashMap<(u32, u32), PatternStamp>, +} + +impl ConditionalStamps { + // The number of seeds can exceed the number of drawn pixels by several orders of magnitude. + // Limit retained property sets for the whole traversal, including distinct branch outcomes. + const MAX_ENTRIES: usize = 1_700_000; + + pub fn get(&self, key: Key, scale: TintScale) -> Option { + let &[bx, by, x, y, width, height, rotation, base] = self.fields.get(&(key, matches!(scale, TintScale::Multiply(_))))?; + let alpha = scale.apply(base); + if !alpha.is_finite() { + return None; + } + let mut stamp = self.templates.get(&(key.node, key.depth))?.clone(); + stamp.center = [x, y]; + stamp.size = [width, height]; + stamp.rotation = rotation; + stamp.color[3] = alpha; + Some(Properties { branch_offset: [bx, by], stamp }) + } + + pub fn insert(&mut self, key: Key, scale: TintScale, base: f32, [bx, by]: [f32; 2], stamp: &PatternStamp) { + if self.fields.len() >= Self::MAX_ENTRIES || scale.apply(base).to_bits() != stamp.color[3].to_bits() { + return; + } + let [x, y] = stamp.center; + let [width, height] = stamp.size; + self.templates.entry((key.node, key.depth)).or_insert_with(|| stamp.clone()); + self.fields.insert((key, matches!(scale, TintScale::Multiply(_))), [bx, by, x, y, width, height, stamp.rotation, base]); + } +} diff --git a/crates/nodes/src/pattern/coordinates.rs b/crates/nodes/src/pattern/coordinates.rs new file mode 100644 index 00000000..a7fcb17c --- /dev/null +++ b/crates/nodes/src/pattern/coordinates.rs @@ -0,0 +1,276 @@ +use super::{footprint::Footprint, region::Region}; +use crate::function::{pixel_divide, truncate_float}; + +mod oblique; + +/// Interpolated signed coordinates of a stamp's padded triangle. +pub(super) struct PixelPlanes { + first_pixel: [u32; 2], + mapping: Mapping, +} + +enum Mapping { + Aligned { axes: [Axis; 2], swap: bool }, + Oblique { planes: [oblique::Plane; 2], origin: [f64; 2] }, +} + +struct Axis { + base: f64, + step: f64, + negative_bias: f64, +} + +struct Triangle { + near: [f64; 2], + far: [f64; 2], + origin: [f64; 2], + basis: [f32; 2], + offset: [i32; 2], + far_axis: Option, +} + +impl PixelPlanes { + pub fn new(frame: &Footprint, region: &Region, center: [f32; 2], size: [f32; 2], dimensions: [u32; 2]) -> Option { + // Snapping displacements use the inverse of the stored projection scale. + // A direct window-to-pixel division changes edge texels in scaled regions. + let pixel_size: [f32; 2] = std::array::from_fn(|i| (dimensions[i] as f32 / region.period()[i]).recip()); + let projected: [_; 2] = std::array::from_fn(|i| region.stamp_sample_vertices(i, center[i], frame.radius[i], dimensions[i])); + // Even a subpixel stamp interpolates its signed coordinates. Extents too large + // to resolve half pixels use the ordinary footprint. + if (0..2).any(|i| { + !(0.0..8_388_608.0).contains(&(2.0 * f64::from(frame.radius[i]) / f64::from(pixel_size[i]))) || projected[i].iter().any(|v| !v.is_finite()) + }) { + return None; + } + let triangle = Triangle::new(projected); + // Move each stored vertex by its snapping displacement in pattern space. + let displacements: [[f32; 2]; 2] = std::array::from_fn(|axis| { + // The interval from the projected half-pixel to the first sample rounds + // before its one-pixel offset is removed, including at a clipped edge. + let first_sample = triangle.near[axis] + 0.5; + let interval = (first_sample - f64::from(projected[axis][0])) as f32; + let low_delta = (interval - 1.0) * pixel_size[axis]; + let high_delta = (triangle.far[axis] - 0.5 - f64::from(projected[axis][1])) as f32 * pixel_size[axis]; + [low_delta - frame.radius[axis], high_delta + 3.0 * frame.radius[axis]] + }); + let first_pixel = triangle.near.map(|n| n as u32); + let swap = frame.cosine == 0.0; + let signs = if swap && frame.sine.abs() == 1.0 { + [-frame.sine * size[1].signum(), frame.sine * size[0].signum()] + } else if frame.sine == 0.0 && frame.cosine.abs() == 1.0 { + [frame.cosine * size[0].signum(), frame.cosine * size[1].signum()] + } else { + let planes = oblique::planes(&triangle, frame, size, displacements)?; + return Some(Self { first_pixel, mapping: Mapping::Oblique { planes, origin: triangle.origin } }); + }; + let [Some(horizontal), Some(vertical)] = std::array::from_fn(|axis| { + let scale = pixel_divide(2.0, size[if swap { 1 - axis } else { axis }].abs()); + let [low, high] = displacements[axis].map(|v| v * scale); + let span = truncate_float(f64::from(high) - f64::from(low)) * 0.5; + let basis = triangle.basis[axis]; + let exponents = (basis.to_bits() >> 23) + (span.to_bits() >> 23); + // Extremely small stamps in large render windows can overflow the vertex span. + if !span.is_normal() || span <= 0.0 || !basis.is_normal() || !(128..=380).contains(&exponents) { + return None; + } + let gradient = gradient_product(basis, span); + let unit = f64::from(gradient.next_up() - gradient); + let vertex = if triangle.far_axis == Some(axis) { high } else { low }; + let base = plane_origin(vertex, [triangle.offset[axis]], [gradient], [unit]); + let sign = f64::from(signs[axis]); + let step = f64::from(gradient); + Some(Axis { base: ((0.5 - triangle.origin[axis]) * step + f64::from(base)) * sign, step: step * sign, negative_bias: unit / 64.0 }) + }) else { + return None; + }; + Some(Self { first_pixel, mapping: Mapping::Aligned { axes: [horizontal, vertical], swap } }) + } + + pub fn clip(&self, bounds: [[u32; 2]; 2]) -> [[u32; 2]; 2] { + std::array::from_fn(|axis| { + let [mut start, mut end] = bounds[axis]; + // The triangle starts at the snapped vertex. Its interpolated coordinates include both stamp edges. + start = start.max(self.first_pixel[axis]).min(end); + let Mapping::Aligned { axes, .. } = &self.mapping else { return [start, end] }; + let contains = |pixel| axes[axis].sample(pixel).abs() <= 1.0; + while start < end && !contains(start) { + start += 1; + } + while start < end && !contains(end - 1) { + end -= 1; + } + [start, end] + }) + } + + pub fn covers_any(&self, bounds: [[u32; 2]; 2], circular: bool) -> bool { + let [[left, right], [top, bottom]] = self.clip(bounds); + if left >= right || top >= bottom { + return false; + } + if !circular && matches!(self.mapping, Mapping::Aligned { .. }) { + return true; + } + (top..bottom).any(|y| { + let row = self.row(y); + (left..right).any(|x| row(x).is_some_and(|uv| !(circular && super::shape::radius_squared(uv) > 1.0))) + }) + } + + pub fn row(&self, y: u32) -> impl Fn(u32) -> Option<[f32; 2]> + '_ { + let sample = self.unclipped_row(y); + let aligned = matches!(self.mapping, Mapping::Aligned { .. }); + move |x| { + let uv = sample(x); + (aligned || uv.iter().all(|v| v.abs() <= 1.0)).then_some(uv) + } + } + + /// Texture gradients include the neighboring lanes even when they fall outside the stamp. + pub fn quad_gradients(&self, [x, y]: [u32; 2]) -> [[f32; 2]; 2] { + let top = self.unclipped_row(y); + let uv = |point: [f32; 2]| point.map(|v| v * 0.5 + 0.5); + let origin = uv(top(x)); + [uv(top(x + 1)), uv(self.unclipped_row(y + 1)(x))].map(|neighbor| [neighbor[0] - origin[0], neighbor[1] - origin[1]]) + } + + fn unclipped_row(&self, y: u32) -> impl Fn(u32) -> [f32; 2] + '_ { + let vertical = match &self.mapping { + Mapping::Aligned { axes, .. } => [f64::from(axes[1].sample(y)), 0.0], + Mapping::Oblique { planes, origin } => planes.each_ref().map(|plane| plane.y_term(y, f64::from(y) + 0.5 - origin[1])), + }; + move |x| match &self.mapping { + Mapping::Aligned { axes, swap } => { + let u = axes[0].sample(x); + let v = vertical[0] as f32; + if *swap { [v, u] } else { [u, v] } + } + Mapping::Oblique { planes, origin } => { + let dx = f64::from(x) + 0.5 - origin[0]; + std::array::from_fn(|i| planes[i].sample(x, dx, vertical[i])) + } + } + } +} + +impl Triangle { + fn new(projected: [[f32; 2]; 2]) -> Self { + let near = projected.map(|[v, _]| f64::from(v).floor() + 1.0); + let far = projected.map(|[_, v]| f64::from(v).floor() + 2.0); + let padded: [f32; 2] = std::array::from_fn(|i| ((far[i] - near[i]) * 0.5) as f32); + let reciprocal = area_reciprocal(truncate_float(f64::from(padded[0]) * f64::from(padded[1]))); + let basis = std::array::from_fn(|i| truncate_float(f64::from(padded[1 - i]) * f64::from(reciprocal))); + let origin = near.map(|n| (n.max(0.0) * 0.25).floor() * 4.0); + let near_offset: [i32; 2] = std::array::from_fn(|i| (origin[i] - near[i]) as i32); + let far_offset: [i32; 2] = std::array::from_fn(|i| (origin[i] - far[i]) as i32); + // The horizontal and vertical far corners are distinct. Prefer the vertical corner on a tie. + let far_axis = (0..2).rev().find(|&i| far_offset[i].unsigned_abs().leading_zeros() >= near_offset[i].unsigned_abs().leading_zeros()); + let offset = std::array::from_fn(|i| if far_axis == Some(i) { far_offset[i] } else { near_offset[i] }); + Self { near, far, origin, basis, offset, far_axis } + } +} + +impl Axis { + fn sample(&self, pixel: u32) -> f32 { + let value = f64::from(pixel) * self.step + self.base; + truncate_float(if value < 0.0 { value + self.negative_bias } else { value }) + } +} + +fn plane_origin(vertex: f32, offsets: [i32; N], slopes: [f32; N], units: [f64; N]) -> f32 { + // Align the offset products by their factor exponents. A carry in a product + // must not shift away another bit when it cancels against the vertex. + let vertex = f64::from(vertex); + let scale = offsets + .into_iter() + .zip(slopes) + .fold(leading_power(vertex), |scale, (offset, slope)| scale.max(leading_power(f64::from(offset)) * leading_power(f64::from(slope)))); + let products = offsets.into_iter().zip(slopes).zip(units).map(|((offset, slope), unit)| { + let value = offset_product(offset, slope.abs(), unit); + if slope.is_sign_negative() { -value } else { value } + }); + truncate_float(aligned_sum(products.chain([vertex]), scale, 5)) +} + +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: impl IntoIterator, scale: f64, guard_bits: u32) -> f64 { + if scale == 0.0 { + return 0.0; + } + let quantum = scale / f64::from(1_u32 << (23 + guard_bits)); + terms.into_iter().map(|v| (v / quantum).trunc() * quantum).sum() +} + +fn offset_product(offset: i32, gradient: f32, unit: f64) -> f64 { + if !gradient.is_normal() { + return f64::from(offset) * f64::from(gradient); + } + let magnitude = offset.unsigned_abs(); + // The integer offset times the 24-bit gradient retains 29 product columns. Each + // partial row loses its low columns before the remaining rows are added. + let low_columns = (u32::BITS - magnitude.leading_zeros()).saturating_sub(5); + let significand = (gradient.to_bits() & 0x7f_ffff) | 0x80_0000; + let mask = (1_u32 << low_columns) - 1; + let mut discarded = 0_u64; + for bit in 0..low_columns { + if magnitude & (1 << bit) != 0 { + discarded += u64::from(significand & (mask >> bit)) << bit; + } + } + let product = f64::from(magnitude) * f64::from(gradient) - discarded as f64 * unit; + if offset < 0 { -product } else { product } +} + +// Interpolate 1/x from its two endpoints and midpoint in each normalized mantissa interval. +// The three samples use quarter units. The squared interpolation fraction retains sixteen bits. +fn area_reciprocal(area: f32) -> f32 { + let bits = area.to_bits(); + let start = 2 * (128 + i64::from((bits >> 16) & 127)); + let [a, b, c] = [start, start + 1, start + 2].map(|denominator| (1_i64 << 34) / denominator); + let t = i64::from(bits & 0xffff); + let square = (t * t) >> 16; + let value = (a << 16) + (4 * b - 3 * a - c) * t + (2 * a - 4 * b + 2 * c) * square; + let significand = ((value + (1 << 17)) >> 18) as u32; + f32::from_bits(((252 - (bits >> 23)) << 23) + significand) +} + +const FRACTION_MASK: u32 = (1 << 23) - 1; + +fn gradient_product(basis: f32, span: f32) -> f32 { + // A power of two only shifts the significand. Every discarded column is zero. + if basis.to_bits() & FRACTION_MASK == 0 || span.to_bits() & FRACTION_MASK == 0 { + return basis * span; + } + let product = gradient_significand_product(basis, span); + let overflow = u32::from(product >= 1 << 47); + let exponent = (span.to_bits() >> 23) + (basis.to_bits() >> 23) - 127 + overflow; + f32::from_bits((exponent << 23) | ((product >> (23 + overflow)) as u32 & FRACTION_MASK)) +} + +fn gradient_significand_product(basis: f32, span: f32) -> u64 { + // Both inputs are positive normal values. Round the magnitude of each signed radix-four + // partial product before accumulating it. The low bit of the span is a separate row. + let significand = |value: f32| i64::from((value.to_bits() & FRACTION_MASK) | (1 << 23)); + let a = significand(span); + let b = significand(basis); + let rounding_error = |row: i64| { + let magnitude = row.abs(); + let rounded = (magnitude + (1 << 16)) & !((1 << 17) - 1); + row.signum() * (rounded - magnitude) + }; + let mut product = a * b + rounding_error((a & 1) * b); + let mut carry = 0; + // Higher rows are already multiples of 2^17 and contribute no rounding error. + for bit in (1..17).step_by(2) { + let pair = (a >> bit) & 3; + let high = pair >> 1; + let digit = (pair & 1) - 2 * high + carry; + product += rounding_error((digit * b) << bit); + carry = high; + } + (product + (1 << 20)) as u64 +} diff --git a/crates/nodes/src/pattern/coordinates/oblique.rs b/crates/nodes/src/pattern/coordinates/oblique.rs new file mode 100644 index 00000000..1a6ee3fb --- /dev/null +++ b/crates/nodes/src/pattern/coordinates/oblique.rs @@ -0,0 +1,88 @@ +use super::{Footprint, Triangle, aligned_sum, gradient_product, gradient_significand_product, leading_power, plane_origin}; +use crate::function::{pixel_divide, truncate_float}; + +pub(super) struct Plane { + base: f64, + step: [f64; 2], + pair_offset: [[f64; 2]; 2], + quantum: f64, + inverse_quantum: f64, +} + +impl Plane { + pub(super) fn y_term(&self, y: u32, dy: f64) -> f64 { + dy * self.step[1] + self.pair_offset[1][(y & 1) as usize] + } + + pub(super) fn sample(&self, x: u32, dx: f64, y_term: f64) -> f32 { + let value = self.base + dx * self.step[0] + self.pair_offset[0][(x & 1) as usize] + y_term; + let fixed = (value * self.inverse_quantum).floor(); + truncate_float((if fixed < 0.0 { fixed + 1.0 } else { fixed }) * self.quantum) + } +} + +pub(super) fn planes(triangle: &Triangle, frame: &Footprint, size: [f32; 2], [[left, right], [top, bottom]]: [[f32; 2]; 2]) -> Option<[Plane; 2]> { + let scale = size.map(|s| pixel_divide(2.0, s)); + let vertices = [[left, top], [right, top], [left, bottom]] + .map(|[x, y]| [y.mul_add(frame.sine, x * frame.cosine) * scale[0], y.mul_add(frame.cosine, -x * frame.sine) * scale[1]]); + if vertices.iter().flatten().any(|v| !v.is_finite()) { + return None; + } + let anchor = triangle.far_axis.map_or(0, |axis| axis + 1); + let square = triangle.far[0] - triangle.near[0] == triangle.far[1] - triangle.near[1]; + let planes: [Plane; 2] = std::array::from_fn(|component| { + let gradient: [f32; 2] = std::array::from_fn(|axis| { + let start = vertices[0][component]; + let end = vertices[axis + 1][component]; + let basis = triangle.basis[axis]; + if square && anchor != 0 && anchor != axis + 1 { + // Across the far edge of a square, the two slope terms share the + // opposite vertex. Align their wide products before subtracting. + let vertex = vertices[anchor][component]; + let (first, first_scale) = wide_slope(basis, half_span(end, vertex)); + let (second, second_scale) = wide_slope(basis, half_span(start, vertex)); + return truncate_float(aligned_sum([first, -second], first_scale.max(second_scale), 2)); + } + let span = half_span(end, start); + let exponents = (span.abs().to_bits() >> 23) + (basis.to_bits() >> 23); + // The partial-product path assumes a normal, finite result at the stored exponent. + if !span.is_normal() || !(128..=380).contains(&exponents) { + return truncate_float(f64::from(basis) * f64::from(span)); + } + gradient_product(basis, span.abs()).copysign(span) + }); + let units = gradient.map(|v| f64::from(v.abs().next_up()) - f64::from(v.abs())); + let base = plane_origin(vertices[anchor][component], triangle.offset, gradient, units); + 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 + // half-step discards gradient bits below a quarter of the larger gradient's ULP. + let quarter = unit * 0.25; + let pair_offset = step.map(|v| { + let half_remainder = (v - (v / quarter).trunc() * quarter) * 0.5; + [half_remainder, -half_remainder] + }); + let quantum = unit / 64.0; + let inverse_quantum = quantum.recip(); + // A narrow stamp can have a tiny origin between steep steps. Discard its + // sub-quantum bits before adding either step, including for negative origins. + let base = (f64::from(base) * inverse_quantum).trunc() * quantum; + Plane { base, step, pair_offset, quantum, inverse_quantum } + }); + planes.iter().all(|p| p.quantum.is_finite()).then_some(planes) +} + +fn half_span(end: f32, start: f32) -> f32 { + let (end, start) = (f64::from(end), f64::from(start)); + truncate_float(aligned_sum([end, -start], leading_power(start.abs().max(end.abs())), 1) * 0.5) +} + +fn wide_slope(basis: f32, span: f32) -> (f64, f64) { + let scale = leading_power(f64::from(basis)) * leading_power(f64::from(span)); + if !span.is_normal() || !basis.is_normal() { + return (f64::from(span) * f64::from(basis), scale); + } + let product = gradient_significand_product(basis, span.abs()) as f64; + let slope = product * (scale / (1_u64 << 46) as f64); + (slope.copysign(f64::from(span)), scale) +} diff --git a/crates/nodes/src/pattern/evaluation.rs b/crates/nodes/src/pattern/evaluation.rs index 48116bf1..6b82ad56 100644 --- a/crates/nodes/src/pattern/evaluation.rs +++ b/crates/nodes/src/pattern/evaluation.rs @@ -1,180 +1,974 @@ -use materialcraft_core::{PatternNodeKind, Value}; -use std::collections::BTreeMap; +use materialcraft_core::{PatternNode, PatternNodeKind, Value, ValueType}; +use std::collections::{BTreeMap, BTreeSet}; -use super::{catalog, pattern_stamp::PatternStamp, pattern_visit::PatternVisit, raster}; -use crate::function::{EvaluationContext, EvaluationState, compile}; +use super::conditional_tint::{ConditionalStamps, ConditionalTint, DrawingExpressions}; +use super::mixed_depth_runs::MixedDepthRuns; +use super::stamp_cache::{self, StampCache, Storage}; +use super::{catalog, footprint::SampleGrid, pattern_stamp::PatternStamp, pattern_visit::PatternVisit, raster, variables::PatternVariables}; +use crate::function::{EvaluationContext, EvaluationState, Program, compile_with_literal_inputs}; +use crate::random::FunctionRandom; use crate::{CookContext, CookResult}; -// A 512-by-512 quadtree needs 349,525 visits including internal quadrants -// Cap deeper trees; the rasterizer separately bounds pixel work +// A 512-by-512 quadtree takes 349,525 visits. Retained, discarded and streamed +// draws have bounded allowances. At most four terminal draws share a parent's +// visit. Five ordinary property evaluations per visit bound the drawing work. const MAX_VISITS: usize = 1_048_576; +// Overlapping squares establish the order of the sixteen grandchildren in a regular seven-level tree. +const SEVEN_LEVEL_RUN_ORDER: [usize; 16] = [12, 13, 8, 9, 14, 0, 1, 15, 2, 11, 6, 7, 10, 3, 4, 5]; + +#[derive(Clone, Copy, PartialEq, Eq)] +enum QuadrantChildren { + None, + AllTerminal, + Other, +} + +type PatternNodes<'a> = BTreeMap; +pub(super) type PropertyPrograms<'a> = BTreeMap<(u32, &'a str), (Program, BTreeMap)>; + +fn reusable_properties( + node: &PatternNode, + children: QuadrantChildren, + programs: &PropertyPrograms, + assigned: &BTreeSet<&str>, + grayscale: bool, + groups: &mut stamp_cache::BranchGroups, +) -> Option { + if node.kind != PatternNodeKind::Quadrant { + return None; + } + let shape = node.parameters.get("patterntype")?.as_i32()?; + let image = image_pattern(shape); + if !(2..=18).contains(&shape) && !(grayscale && image) { + return None; + } + let mut computed = false; + let mut placement = grayscale && (2..=16).contains(&shape); + let mut geometry = placement; + let mut branch_tint = placement && programs.contains_key(&(node.id, "branchoffset")); + let definition = catalog::definition(node.kind)?; + for name in definition.params.iter().map(|p| p.id).filter(|name| uses_property(node.kind, name, shape)) { + if let Some((program, _)) = programs.get(&(node.id, name)) { + // A fixed-image entry stores the branch offset, size and grayscale tint. + // Every other field, including the selected slot, must be constant for this leaf. + if image && !matches!(name, "branchoffset" | "patternsize" | "opacity") { + return None; + } + if matches!(name, "patterntype" | "randomseed" | "randominherited") || !stamp_cache::reusable(program, assigned) { + return None; + } + placement &= matches!(name, "frameoffset" | "patternrotation" | "opacity"); + geometry &= matches!(name, "branchoffset" | "frameoffset" | "patternsize" | "patternrotation" | "opacity"); + branch_tint = branch_tint && matches!(name, "branchoffset" | "opacity") && stamp_cache::independent_of_depth(program); + computed = true; + } + } + if branch_tint && let Some(storage) = groups.storage(node) { + return Some(storage); + } + if !computed || children == QuadrantChildren::Other || (children == QuadrantChildren::AllTerminal && !placement && !geometry) { + return None; + } + Some(if image { + Storage::FixedImage + } else if placement { + Storage::Placement + } else if geometry { + Storage::Geometry { terminal: children == QuadrantChildren::None } + } else { + Storage::Full + }) +} + +fn conditional_tint<'a>(node: &PatternNode, programs: &'a PropertyPrograms, assigned: &BTreeSet<&str>) -> Option> { + if node.kind != PatternNodeKind::Quadrant { + return None; + } + let shape @ 2..=16 = node.parameters.get("patterntype")?.as_i32()? else { return None }; + let (program, names) = programs.get(&(node.id, "opacity"))?; + let tint = ConditionalTint::identify(program, assigned)?; + let (frame, _) = programs.get(&(node.id, "frameoffset"))?; + if names.len() != 1 || names.get(tint.offset) != Some(&ValueType::Float2) || frame.input_identifier() != Some(tint.offset) { + return None; + } + let fields = &catalog::definition(node.kind)?.params; + let fixed = fields.iter().filter(|field| uses_property(node.kind, field.id, shape)).all(|field| { + matches!(field.id, "opacity" | "frameoffset") + || programs + .get(&(node.id, field.id)) + .is_none_or(|(program, _)| matches!(field.id, "branchoffset" | "patternrotation" | "patternsize") && stamp_cache::reusable(program, assigned)) + }); + fixed.then_some(tint) +} + +struct TerminalSiblings { + stack: usize, + discarded: bool, +} + +fn uniform_deep_draws(root: Option, nodes: &PatternNodes) -> bool { + let mut pending: Vec<_> = root.into_iter().map(|id| (id, 0_u8)).collect(); + let mut seen = BTreeSet::new(); + let mut order = None; + while let Some((id, depth)) = pending.pop() { + if !seen.insert((id, depth)) { + continue; + } + let Some(&(node, _, _)) = nodes.get(&id) else { return false }; + let quadrant = node.kind == PatternNodeKind::Quadrant; + if quadrant { + let literal = |name: &str| node.parameters.get(name).map_or(Some(0), Value::as_i32); + let Some(shape) = literal("patterntype") else { return false }; + if shape != 0 { + // A drawing first-level quadrant can require reordering across outer iterations. + let Some(blend @ 0..=2) = literal("blendingmode") else { return false }; + let (pattern, filter) = if image_pattern(shape) { + let Some(slot) = literal("imageindex").and_then(|index| fixed_image_slot(shape, index)) else { return false }; + let Some(filter @ 0..=2) = literal("imagefiltering") else { return false }; + if slot >= crate::MAX_IMAGE_INPUTS as i32 { + return false; + } + (256 + slot, filter) + } else if (2..=16).contains(&shape) { + (shape, 0) + } else { + return false; + }; + let rank = (pattern, filter, blend != 0); + if depth < 2 || *order.get_or_insert(rank) != rank { + return false; + } + } + } + let child_depth = (depth + u8::from(quadrant)).min(2); + pending.extend(node.children.iter().flatten().map(|&child| (child, child_depth))); + } + order.is_some() +} + +fn quadrant_mode(kind: PatternNodeKind, name: &str) -> bool { + kind == PatternNodeKind::Quadrant && matches!(name, "patterntype" | "blendingmode" | "imagefiltering" | "imagepremul" | "randominherited") +} + +fn image_pattern(pattern: i32) -> bool { + pattern == 1 || (256..256 + crate::MAX_IMAGE_INPUTS as i32).contains(&pattern) +} + +fn fixed_image_slot(pattern: i32, requested: i32) -> Option { + // A fixed zero preserves the packed slot. The generic image pattern starts at slot zero. + (requested >= 0).then_some(if requested == 0 { pattern.max(256) - 256 } else { requested }) +} + +fn uses_property(kind: PatternNodeKind, name: &str, pattern: i32) -> bool { + match name { + "randomseed" | "randominherited" | "patterntype" | "branchoffset" => true, + "imageindex" | "imagefiltering" | "imagepremul" => image_pattern(pattern), + _ => kind != PatternNodeKind::Quadrant || pattern != 0, + } +} + +fn has_bound_draw(root: Option, nodes: &PatternNodes, programs: &PropertyPrograms, context: &CookContext, modes: &BTreeMap) -> bool { + // Both connected alternatives contribute, even when a switch or zero iteration skips one during traversal. + let mut pending: Vec<_> = root.into_iter().collect(); + let mut seen = BTreeSet::new(); + let mut state = EvaluationState::default(); + while let Some(id) = pending.pop() { + if !seen.insert(id) { + continue; + } + let Some(&(node, _, _)) = nodes.get(&id) else { continue }; + pending.extend(node.children.iter().flatten().copied()); + let Some(definition) = catalog::definition(node.kind) else { continue }; + let mut pattern = None; + for field in &definition.params { + if field.id == "randominherited" + || quadrant_mode(node.kind, field.id) + || !programs + .get(&(id, field.id)) + .is_some_and(|(program, locals)| program.reads_bound_input(|name| !locals.contains_key(name) && context.vars.contains_key(name))) + { + continue; + } + if uses_property(node.kind, field.id, 0) { + return true; + } + let shape = pattern.get_or_insert_with(|| { + if let Some((program, _)) = programs.get(&(id, "patterntype")) { + let evaluation = EvaluationContext { + image_formats: context.input_formats.get(1..).unwrap_or(&[]), + scope: crate::function::FunctionScope::FxMap, + position: [0.0; 2], + size: [context.w as f32, context.h as f32], + images: context.inputs.get(1..).unwrap_or(&[]), + tile: context.tile, + variables: modes, + }; + program.evaluate_with_random(&evaluation, &mut state, &mut FunctionRandom::image(context.seed)).ok().and_then(|v| v.as_i32()).unwrap_or(0) + } else { + node.parameters.get("patterntype").and_then(Value::as_i32).unwrap_or(0) + } + }); + if uses_property(node.kind, field.id, *shape) { + return true; + } + } + } + false +} + +fn has_uniform_quadrant_leaves(root: u32, depth: u32, nodes: &PatternNodes) -> bool { + let mut level = BTreeSet::from([root]); + for current in 0..=depth { + let mut next = BTreeSet::new(); + for id in level { + let Some(&(node, _, children)) = nodes.get(&id) else { return false }; + if node.kind != PatternNodeKind::Quadrant || (children == QuadrantChildren::None) != (current == depth) { + return false; + } + next.extend(node.children.iter().flatten().copied()); + } + level = next; + } + true +} + +#[derive(Default)] +struct SevenLevelRuns { + seen_root: bool, + starts: [usize; 17], + grandchildren: usize, + child_counts: [Option; 2], + parents_drawn: usize, + leaves_drawn: usize, +} + +impl SevenLevelRuns { + fn visit(&mut self, node: &PatternNode, depth: u32, retained: usize) -> bool { + if node.kind != PatternNodeKind::Quadrant { + return true; + } + if depth == 0 { + // A second quadrant tree interleaves its draws with the first tree's grandchildren. + if self.seen_root { + return false; + } + self.seen_root = true; + } + if depth == 2 { + let Some(start) = self.starts.get_mut(self.grandchildren) else { return false }; + *start = retained; + self.grandchildren += 1; + } + match depth { + 0..=4 => !node.children.contains(&None), + 5 | 6 => { + let count = node.children.iter().flatten().count(); + count > 0 && *self.child_counts[(depth - 5) as usize].get_or_insert(count) == count + } + _ => true, + } + } + + fn draw(&mut self, stamp: &PatternStamp) -> bool { + if stamp.blend != 0 || !(2..=18).contains(&stamp.pattern) { + return false; + } + match stamp.depth { + 6 => self.parents_drawn += 1, + 7 => self.leaves_drawn += 1, + _ => return false, + } + true + } + + fn finish(mut self, retained: usize) -> Option<[usize; 17]> { + let [Some(penultimate), Some(terminal)] = self.child_counts else { return None }; + // The first five full subdivisions give 1,024 parents of the penultimate level. + let leaves = 1024 * penultimate * terminal; + let measured = + (self.parents_drawn == 0 && (penultimate == 4 || (penultimate == 3 && terminal == 4))) || (self.parents_drawn == 4096 && leaves == 16384); + if self.grandchildren != SEVEN_LEVEL_RUN_ORDER.len() || self.leaves_drawn != leaves || !measured { + return None; + } + self.starts[SEVEN_LEVEL_RUN_ORDER.len()] = retained; + Some(self.starts) + } +} + pub(crate) fn cook(context: &CookContext) -> CookResult { + cook_with_base_level_inputs(context, &[]) +} + +/// Cook a pattern with the supplied base-level-only flags in image port order. +pub fn cook_with_base_level_inputs(context: &CookContext, base_level_only: &[bool]) -> CookResult { + cook_with_bound_properties(context, base_level_only, false) +} + +/// A live input to a drawing property affects reads of a local preceding its first assignment. +pub fn cook_with_bound_properties(context: &CookContext, base_level_only: &[bool], bound_property: bool) -> CookResult { + cook_with_visit_limit(context, base_level_only, MAX_VISITS, bound_property) +} + +/// Cook the image and report live drawing inputs for a downstream pattern. +pub fn cook_with_image_dependencies(context: &CookContext, base_level_only: &[bool], bound_property: bool) -> Result<(craft_texture::Image, bool), String> { + evaluate(context, base_level_only, MAX_VISITS, bound_property) +} + +pub(super) fn cook_with_visit_limit(context: &CookContext, base_level_only: &[bool], visit_limit: usize, bound_property: bool) -> CookResult { + evaluate(context, base_level_only, visit_limit, bound_property).map(|(image, _)| vec![image]) +} + +fn evaluate(context: &CookContext, base_level_only: &[bool], visit_limit: usize, bound_property: bool) -> Result<(craft_texture::Image, bool), String> { let Some(Value::PatternGraph(graph)) = context.params.get("pattern") else { return Err("missing pattern graph".into()); }; - graph.validate()?; - let nodes: BTreeMap<_, _> = graph.nodes.iter().map(|node| (node.id, node)).collect(); + let opacity_depth = graph.validated_depth()?; + let terminal_nodes: BTreeSet<_> = + graph.nodes.iter().filter(|node| node.kind == PatternNodeKind::Quadrant && node.children.iter().all(Option::is_none)).map(|node| node.id).collect(); + let mut nodes = BTreeMap::new(); let mut functions = BTreeMap::new(); + let mut fixed_switches = BTreeSet::new(); for node in &graph.nodes { + let mut fixed = node.kind == PatternNodeKind::Switch && node.children.contains(&None); + let mut literal_geometry = true; for (name, value) in &node.parameters { if let Value::Function(function) = value { - functions.insert((node.id, name.as_str()), compile(function, context.seed)?); + let program = compile_with_literal_inputs(function, context.seed, context.vars.literal_inputs())?; + if matches!(name.as_str(), "patternsize" | "patternrotation") { + literal_geometry &= program.output_is_literal(); + } + fixed = fixed && name == "switch" && program.depends_only_on_image_size(); + let mut names = BTreeMap::new(); + super::variables::declarations(&program, &mut names); + functions.insert((node.id, name.as_str()), (program, names)); } } + if fixed { + fixed_switches.insert(node.id); + } + let quadrant_children = if terminal_nodes.contains(&node.id) { + QuadrantChildren::None + } else if node.kind == PatternNodeKind::Quadrant && node.children.iter().flatten().all(|id| terminal_nodes.contains(id)) { + QuadrantChildren::AllTerminal + } else { + QuadrantChildren::Other + }; + nodes.insert(node.id, (node, literal_geometry, quadrant_children)); } + let grayscale = !context.b("color_mode"); + let assigned = functions.values().flat_map(|(_, names)| names.keys().map(String::as_str)).collect(); + let mut branch_groups = stamp_cache::BranchGroups::default(); + let reusable: BTreeMap<_, _> = nodes + .values() + .filter_map(|&(node, _, children)| { + reusable_properties(node, children, &functions, &assigned, grayscale, &mut branch_groups).map(|storage| (node.id, storage)) + }) + .collect(); + drop(branch_groups); + let mut stamp_cache = StampCache::default(); + let tint_plans: BTreeMap<_, _> = if grayscale { + graph.nodes.iter().filter_map(|node| conditional_tint(node, &functions, &assigned).map(|plan| (node.id, plan))).collect() + } else { + BTreeMap::new() + }; + // A literal empty quadrant can move its children. Its unused drawing fields cannot execute. + let branch_offsets: BTreeSet<_> = graph + .nodes + .iter() + .filter(|node| { + node.kind == PatternNodeKind::Quadrant + && node.parameters.get("patterntype").is_none_or(|v| v.as_i32() == Some(0)) + && functions.contains_key(&(node.id, "branchoffset")) + && !functions.contains_key(&(node.id, "randomseed")) + && !functions.contains_key(&(node.id, "randominherited")) + }) + .map(|node| node.id) + .collect(); + let mut conditional_stamps = ConditionalStamps::default(); + let mut expressions = DrawingExpressions::default(); + let image_slots: Vec<_> = + context.inputs.iter().skip(1).take(crate::MAX_IMAGE_INPUTS).enumerate().filter_map(|(i, image)| image.as_ref().map(|_| i as i32)).collect(); let mut pending = Vec::new(); if let Some(root) = graph.root { - pending.push(PatternVisit { node: root, center: [0.5; 2], extent: 1.0, depth: 0, number: 0, seed: context.seed }); + pending.push((PatternVisit { node: root, center: [0.5; 2], extent: 1.0, depth: 0, number: 0, seed: context.seed }, 0_u32)); } let mut stamps = Vec::new(); + let mut runtime_image_selector = false; + let mut root_siblings = None; + let mut root_children_pending = 0; + let mut branch_starts = [None; 4]; - // Keep Set assignments across iterations within this FX-Map cook - let mut variables = context.vars.clone(); + let mut variables = PatternVariables::new(context.vars.graph_values()); + let has_locals = functions.values().any(|(_, names)| !names.is_empty()); + variables.bound_draw = + bound_property || (context.vars.keys().any(|name| !name.starts_with('$')) && has_bound_draw(graph.root, &nodes, &functions, context, &variables.modes)); + let separate_child_variables = opacity_depth == 6 && has_locals && graph.root.is_some_and(|root| has_uniform_quadrant_leaves(root, opacity_depth, &nodes)); let mut max_depth = 0; let mut state = EvaluationState::default(); - let mut remaining = MAX_VISITS; - while let Some(mut visit) = pending.pop() { - remaining = remaining.checked_sub(1).ok_or("pattern graph exceeded its execution budget")?; - let node = nodes.get(&visit.node).ok_or("missing pattern node")?; + let mut terminal_siblings: Option = None; + let mut covered_terminal_misses = 0_usize; + let mut remaining = visit_limit; + let mut discard_allowance = visit_limit; + // Only work already saved by completed bound evaluations can cover additional cache hits. + let mut saved_property_work = 0_usize; + let mut property_work = visit_limit.saturating_mul(5).saturating_mul(DrawingExpressions::FULL_COST); + let mut cached_stream_allowance = visit_limit; + let mut accounted_stamps = 0; + let stream_chunk = (visit_limit / 4).clamp(1, 4_096); + let mut uniform_order = None; + let mut raster_work = raster::RasterWork::new(); + let mut repeated_roots = None; + let mut quadrant_fork = (grayscale && opacity_depth > 6 && !context.b("cull_outside")).then(|| super::quadrant_fork::QuadrantFork::new(opacity_depth - 6)); + let mut repeated_six_level: Option = None; + let mut terminal_quadrants = (grayscale && opacity_depth == 8 && !context.b("cull_outside")).then(super::terminal_quadrants::TerminalQuadrants::default); + let mut seven_level_runs = (grayscale && opacity_depth == 7).then(SevenLevelRuns::default); + let mut underfilled = + (grayscale && opacity_depth >= 8 && !context.b("cull_outside")).then(|| super::underfilled_quadrants::UnderfilledQuadrants::new(opacity_depth)); + let mut sparse_runs = if grayscale && opacity_depth == 8 { super::tile_runs::SparseQuadrantRuns::new(context) } else { None }; + let mut mixed_depth_runs = if grayscale && matches!(opacity_depth, 8..=10) { + // A single tiling axis can order fixed-image draws differently from analytic draws. + let [tile_x, tile_y] = context.tiling_axes(); + let fixed_image = + opacity_depth <= 9 && tile_x == tile_y && !image_slots.is_empty() && *uniform_order.get_or_insert_with(|| uniform_deep_draws(graph.root, &nodes)); + MixedDepthRuns::new(context, opacity_depth, fixed_image) + } else { + None + }; + // A grayscale opacity expression can produce an infinity or NaN which participates in the blend. + let opacity = context.value("opacity").and_then(Value::as_f32).unwrap_or(0.0); + let nonfinite_gray_opacity = grayscale && !opacity.is_finite(); + let opacities = raster::depth_opacities(context.f("roughness"), opacity_depth, opacity); + let grid = opacities.as_deref().ok().and_then(|weights| SampleGrid::new(context, weights)); + let mut parameter_values = Vec::new(); + let mut children = Vec::new(); + let mut empty_switches = BTreeSet::new(); + let mut immediate = None; + while let Some((mut visit, repeats_left)) = immediate.take().or_else(|| pending.pop()) { + // Returning below the previous stack size starts the next child of the root. + if pending.len() < root_children_pending { + root_children_pending = pending.len(); + if let Some(slot) = root_siblings.and_then(|siblings| pending.len().checked_sub(siblings)).and_then(|slot| branch_starts.get_mut(slot)) { + *slot = Some(stamps.len()); + } + } + variables.resume(pending.len()); + if separate_child_variables && visit.depth == 1 { + variables.start_root_child(); + } max_depth = max_depth.max(visit.depth); + if empty_switches.contains(&visit.node) { + continue; + } + remaining = remaining.checked_sub(1).ok_or("pattern graph exceeded its execution budget")?; + if repeats_left != 0 { + // Resume the previous draw's scope before scheduling its sibling. Descendants of + // this draw run first and inherit its own number and seed. + let next = PatternVisit { number: visit.number + 1, seed: crate::random::iteration_child(visit.seed), ..visit.clone() }; + pending.push((next, repeats_left - 1)); + } + let &(node, literal_geometry, quadrant_children) = nodes.get(&visit.node).ok_or("missing pattern node")?; + if quadrant_fork.as_mut().is_some_and(|fork| !fork.visit(node, visit.depth, stamps.len())) { + quadrant_fork = None; + } + if underfilled.as_mut().is_some_and(|runs| !runs.visit(node, visit.depth, stamps.len())) { + underfilled = None; + } + if seven_level_runs.as_mut().is_some_and(|runs| !runs.visit(node, visit.depth, stamps.len())) { + seven_level_runs = None; + } + if terminal_quadrants.as_mut().is_some_and(|runs| !runs.visit(node, visit.depth, stamps.len())) { + terminal_quadrants = None; + } + if sparse_runs.as_ref().is_some_and(|runs| !runs.visit(node, visit.depth)) { + sparse_runs = None; + } + if mixed_depth_runs.as_mut().is_some_and(|runs| !runs.visit(node, visit.depth, stamps.len())) { + mixed_depth_runs = None; + } if node.kind == PatternNodeKind::Dot { if let Some(Some(child)) = node.children.first() { visit.node = *child; - pending.push(visit); + pending.push((visit, 0)); } continue; } let definition = catalog::definition(node.kind).ok_or("missing pattern definition")?; - if node.parameters.get("randominherited").and_then(Value::as_bool) == Some(false) { - visit.seed = node.parameters.get("randomseed").and_then(Value::as_i32).unwrap_or(0) as u32; + for (name, value) in [("$depth", visit.depth as f32), ("$depthpow2", visit.extent), ("$number", visit.number as f32)] { + if let Some(bound) = variables.drawing.get_mut(name) { + *bound = Value::Float(value); + } else { + variables.drawing.insert(name.into(), Value::Float(value)); + } } - variables.insert("$randomseed".into(), Value::Int(visit.seed as i32)); - variables.insert("$depth".into(), Value::Float(visit.depth as f32)); - variables.insert("$depthpow2".into(), Value::Float(visit.extent)); - variables.insert("$number".into(), Value::Float(visit.number as f32)); + let mut declared = Vec::new(); + let tint_plan = tint_plans.get(&node.id); + let scale = tint_plan.and_then(|plan| plan.scale(&variables.drawing)); + let mut base_tint = None; + let tint = tint_plan.zip(scale); + let placement = matches!(reusable.get(&node.id), Some(Storage::Placement)); + let mut bound = if tint.is_some() || placement || branch_offsets.contains(&node.id) { + expressions.for_draw(&visit, tint, placement, &functions, &variables.drawing, &assigned) + } else { + None + }; + let property_cost = bound.as_ref().map_or(DrawingExpressions::FULL_COST, |plan| plan.cost); - let mut parameters = BTreeMap::new(); - let mut random = visit.seed; - for parameter in &definition.params { - let value = match functions.get(&(node.id, parameter.id)) { - Some(program) => { - let evaluation = EvaluationContext { - scope: crate::function::FunctionScope::FxMap, - position: visit.center, - size: [context.w as f32, context.h as f32], - images: context.inputs.get(1..).unwrap_or(&[]), - tile: context.tile, - variables: &variables, - }; - - let value = program.evaluate_with_random(&evaluation, &mut state, &mut random)?; - variables.extend(state.assignments().clone()); - value + let mut evaluate = |id: &str, random: &mut FunctionRandom| -> Result, String> { + let Some((program, names)) = functions.get(&(node.id, id)) else { return Ok(node.parameters.get(id).cloned()) }; + let mode = quadrant_mode(node.kind, id); + if !mode { + variables.enter(names, visit.depth, &mut declared); + } + let inputs = if mode { &variables.modes } else { &variables.drawing }; + // An unbound direct link leaves the field at its default. A getter inside an expression still evaluates to its typed zero. + if program.input_identifier().is_some_and(|name| !name.starts_with('$') && !inputs.contains_key(name)) { + return Ok(None); + } + if let Some(expression) = bound.as_deref_mut().and_then(|plan| plan.fields.get_mut(id)) { + let (value, assignment) = expression.evaluate(random)?; + if let Some(offset) = assignment { + let (Some(tint), Some(scale), Value::Float(base)) = (tint_plan, scale, value) else { return Err("invalid bound pattern tint".into()) }; + if let Some(slot) = variables.drawing.get_mut(tint.offset) { + *slot = offset; + } + base_tint = base.is_finite().then_some(base); + return Ok(Some(Value::Float(scale.apply(base)))); } - None => node.parameters.get(parameter.id).unwrap_or(¶meter.default).clone(), + if id != "opacity" && value.as_vec4().is_some_and(|channels| channels.iter().any(|v| !v.is_finite())) { + return Err("function produced a non-finite output".into()); + } + return Ok(Some(value)); + } + let evaluation = EvaluationContext { + image_formats: context.input_formats.get(1..).unwrap_or(&[]), + scope: if id == "randomseed" { crate::function::FunctionScope::FxMapRandomSeed } else { crate::function::FunctionScope::FxMap }, + position: if mode { [0.0; 2] } else { visit.center }, + size: [context.w as f32, context.h as f32], + images: context.inputs.get(1..).unwrap_or(&[]), + tile: context.tile, + variables: inputs, }; - - parameters.insert(parameter.id, value); + let value = if id == "randomseed" { + program.evaluate_pattern_seed(&evaluation, &mut state, random, variables.seed_integers(context.vars.assigned_integers()))? + } else if node.kind == PatternNodeKind::Quadrant && id == "opacity" { + program.evaluate_pattern_tint(&evaluation, &mut state, random)? + } else { + program.evaluate_with_random(&evaluation, &mut state, random)? + }; + if id == "opacity" + && let Some(plan) = tint_plan + { + base_tint = plan.base(&state); + } + // A quadrant's mode expressions keep their own writes. A later stamp property can read writes from the draw expressions. + if !mode { + for (name, value) in state.assignments() { + if let Some(bound) = variables.drawing.get_mut(name) { + *bound = value.clone(); + } + } + } + Ok(Some(value)) + }; + // The seed expression reads the incoming stream before its offset applies to this stamp and its descendants. + let incoming_seed = visit.seed; + let offset = evaluate("randomseed", &mut FunctionRandom::uniform(incoming_seed))?.and_then(|v| v.as_i32()).unwrap_or(0) as u32; + let inherits = evaluate("randominherited", &mut FunctionRandom::image(incoming_seed))?.and_then(|v| v.as_bool()).unwrap_or(true); + visit.seed = if inherits { incoming_seed.wrapping_add(offset) } else { offset }; + parameter_values.clear(); + let mut random = FunctionRandom::image(visit.seed); + let mut pattern = if node.kind == PatternNodeKind::Quadrant { evaluate("patterntype", &mut random)?.and_then(|v| v.as_i32()).unwrap_or(0) } else { 0 }; + let image_pattern = image_pattern(pattern); + // A streamed parent still visits each connected child in its original position and order. + let cache = reusable + .get(&node.id) + .filter(|storage| { + quadrant_children == QuadrantChildren::None || raster_work.streaming || matches!(storage, Storage::BranchTint { .. } | Storage::Geometry { .. }) + }) + .map(|&storage| { + let (node, depth) = match storage { + Storage::BranchTint { group, .. } => (group, u32::MAX), + _ => (node.id, visit.depth), + }; + (stamp_cache::Key { node, depth, seed: visit.seed }, storage) + }); + let tint_key = stamp_cache::Key { node: node.id, depth: visit.depth, seed: visit.seed }; + let conditional = scale.and_then(|scale| conditional_stamps.get(tint_key, scale)); + let written_offset = conditional.as_ref().map(|properties| properties.stamp.center); + let cached = conditional.or_else(|| { + cache.and_then(|(key, storage)| { + let mut properties = stamp_cache.get(key, storage)?; + if let Storage::BranchTint { size, .. } = storage { + properties.stamp.depth = visit.depth; + properties.stamp.size = size.map(|v| v * visit.extent); + } + Some(properties) + }) + }); + let reused = cached.is_some(); + // An unused stamp property cannot publish a Set to a child. The branch offset still positions that child. + let active = |id: &str| !matches!(id, "patterntype" | "randomseed" | "randominherited") && uses_property(node.kind, id, pattern); + if !reused { + property_work = property_work.checked_sub(property_cost).ok_or("pattern graph exceeded its execution budget")?; + saved_property_work = saved_property_work.saturating_add(DrawingExpressions::FULL_COST - property_cost); + for parameter in definition.params.iter().filter(|p| active(p.id)) { + let mut stream = FunctionRandom::pattern(visit.seed, parameter.id); + let value = evaluate(parameter.id, stream.as_mut().unwrap_or(&mut random))?.unwrap_or_else(|| parameter.default.clone()); + parameter_values.push((parameter.id, value)); + } } - let scalar = |name: &str| parameters.get(name).and_then(Value::as_f32).unwrap_or(0.0); - let integer = |name: &str| parameters.get(name).and_then(Value::as_i32).unwrap_or(0); - let vector = |name: &str| parameters.get(name).and_then(Value::as_vec4).map(|value| [value[0], value[1]]).unwrap_or([0.0; 2]); - if parameters.get("randominherited").and_then(Value::as_bool) == Some(false) { - visit.seed = integer("randomseed") as u32; + // A cache hit must publish the same offset in the declaring depth's scope. + if let (Some(offset), Some(plan), Some((_, names))) = (written_offset, tint_plan, functions.get(&(node.id, "opacity"))) { + variables.enter(names, visit.depth, &mut declared); + if let Some(bound) = variables.drawing.get_mut(plan.offset) { + *bound = Value::Float2(offset); + } } - - let mut children = Vec::new(); + let field = |name: &str| parameter_values.iter().find_map(|(id, value)| (*id == name).then_some(value)); + let scalar = |name: &str| field(name).and_then(Value::as_f32).unwrap_or(0.0); + let integer = |name: &str| field(name).and_then(Value::as_i32).unwrap_or(0); + let vector = |name: &str| field(name).and_then(Value::as_vec4).map(|value| [value[0], value[1]]).unwrap_or([0.0; 2]); + children.clear(); + let mut repeated = None; + let mut discarded_draw = false; + let track_root_children = + grayscale && node.kind == PatternNodeKind::Quadrant && visit.depth == 0 && (Some(node.id) == graph.root || opacity_depth == 6); match node.kind { PatternNodeKind::Dot => {} PatternNodeKind::Quadrant => { - let offset = vector("branchoffset"); - visit.center = [visit.center[0] + offset[0] * visit.extent, visit.center[1] + offset[1] * visit.extent]; - let pattern = integer("patterntype"); - let pattern = if pattern == 1 { integer("imageindex").max(1).saturating_add(255) } else { pattern }; - if pattern != 0 { - let offset = vector("frameoffset"); - let color = match parameters.get("opacity") { - Some(Value::Float(value)) => [*value, *value, *value, 1.0], - Some(value) => value.as_vec4().ok_or("pattern color must be a float or float4")?, - None => [1.0; 4], + if visit.depth == 0 + && let Some(active) = &mut repeated_roots + { + // A switch on the repeated branch may omit an entire quadrant tree. + *active += 1; + } + let offset = cached.as_ref().map_or_else(|| vector("branchoffset"), |properties| properties.branch_offset); + visit.center = [visit.center[0] + offset[0], visit.center[1] + offset[1]]; + if let Some(properties) = &cached { + pattern = properties.stamp.pattern; + } else if image_pattern { + let requested = integer("imageindex"); + let slot = if functions.get(&(node.id, "imageindex")).is_some_and(|(program, _)| !program.uses_fixed_image_slot(&variables.drawing)) { + // Even a stamp with empty coverage establishes the wired order for the other image draws. + runtime_image_selector = true; + // A runtime selector advances across disconnected slots and stops at the last wired image. + let pos = image_slots.partition_point(|&i| i < requested); + image_slots.get(pos).or_else(|| image_slots.last()).copied() + } else { + fixed_image_slot(pattern, requested) }; + pattern = slot.map_or(0, |i| i.saturating_add(256)); + } + if pattern != 0 { + let mut stamp = if let Some(properties) = cached { + properties.stamp + } else { + let tint = field("opacity").unwrap_or(&Value::Float4([1.0; 4])); + let rgba = tint.as_vec4().ok_or("pattern color must be a float or float4")?; + let computed_tint = functions.contains_key(&(node.id, "opacity")); + if rgba.iter().any(|v| v.is_infinite() || (v.is_nan() && !computed_tint)) { + return Err("pattern color must be finite".into()); + } + let color = match tint { + Value::Float(luminosity) => [1.0, 1.0, 1.0, *luminosity], + _ if grayscale => { + // A color expression supplies its alpha. A literal swatch supplies its mean RGB. + let luminosity = if computed_tint { rgba[3] } else { (rgba[0] + rgba[1] + rgba[2]) / 3.0 }; + [1.0, 1.0, 1.0, luminosity] + } + _ => rgba, + }; - stamps.push(PatternStamp { - center: [visit.center[0] + offset[0] * visit.extent, visit.center[1] + offset[1] * visit.extent], - size: vector("patternsize").map(|size| size * visit.extent), - rotation: scalar("patternrotation"), - color, - scalar_color: matches!(parameters.get("opacity"), Some(Value::Float(_))), - depth: visit.depth, - pattern, - variation: scalar("patternsuppl"), - blend: integer("blendingmode"), - filtering: integer("imagefiltering"), - premultiplied: parameters.get("imagepremul").and_then(Value::as_bool).unwrap_or(false), - }); + let stamp = PatternStamp { + center: vector("frameoffset"), + size: vector("patternsize").map(|size| size * visit.extent), + rotation: scalar("patternrotation"), + literal_geometry, + color, + depth: visit.depth, + pattern, + variation: scalar("patternsuppl"), + blend: integer("blendingmode"), + filtering: integer("imagefiltering"), + premultiplied: field("imagepremul").and_then(Value::as_bool).unwrap_or(false), + }; + if let (Some(scale), Some(base)) = (scale, base_tint) { + conditional_stamps.insert(tint_key, scale, base, offset, &stamp); + } + if let Some((key, storage)) = cache { + stamp_cache.insert(key, stamp_cache::Properties { branch_offset: offset, stamp: stamp.clone() }, storage, raster_work.streaming); + } + stamp + }; + stamp.center = [visit.center[0] + stamp.center[0], visit.center[1] + stamp.center[1]]; + if quadrant_fork.as_mut().is_some_and(|fork| !fork.draw(&stamp, opacities.as_deref().unwrap_or_default(), grid.as_ref())) { + quadrant_fork = None; + } + // A draw that misses the sample grid still belongs to its grandchild's run. + if seven_level_runs.as_mut().is_some_and(|runs| !runs.draw(&stamp)) { + seven_level_runs = None; + } + // Evaluate every property before discarding a stamp. Its assignments can reach + // later visits. Keep the first stamp so raster setup still validates depth weights. + let missed = (!stamps.is_empty() || raster_work.background.is_some()) && grid.as_ref().is_some_and(|grid| grid.misses(&stamp)); + if underfilled + .as_mut() + .is_some_and(|runs| !runs.draw(&stamp, opacities.as_deref().unwrap_or_default(), grid.as_ref(), stamps.len(), !missed)) + { + underfilled = None; + } + if sparse_runs.as_mut().is_some_and(|runs| runs.draw(&stamp, opacities.as_deref().unwrap_or_default(), !missed).is_none()) { + sparse_runs = None; + } + if mixed_depth_runs.as_mut().is_some_and(|runs| !runs.draw(&stamp, opacities.as_deref().unwrap_or_default(), !missed)) { + mixed_depth_runs = None; + } + if repeated_six_level + .as_mut() + .is_some_and(|runs| runs.record(&stamp, opacities.as_deref().unwrap_or_default(), grid.as_ref(), !missed).is_none()) + { + repeated_six_level = None; + } + if terminal_quadrants.as_mut().is_some_and(|runs| !runs.draw(&stamp, opacities.as_deref().unwrap_or_default(), grid.as_ref(), !missed)) { + terminal_quadrants = None; + } + if missed { + let reusable_parent = scale.is_some() || matches!(cache, Some((_, Storage::BranchTint { .. } | Storage::Geometry { .. }))); + // These siblings have no children. Each has already evaluated its own + // properties and failed the sample-grid test in the original draw order. + let compact = property_cost < DrawingExpressions::FULL_COST; + if let Some(siblings) = &mut terminal_siblings { + siblings.discarded = true; + covered_terminal_misses = covered_terminal_misses.saturating_add(usize::from(reused || compact)); + remaining += 1; + } else if quadrant_children == QuadrantChildren::AllTerminal + && ((reused && cached_stream_allowance > 0) || (!reused && covered_terminal_misses > 0 && reusable_parent)) + { + // A full evaluation already paid for this parent. One covered leaf + // covers its missed draw. A cached parent uses a streaming credit. + if reused { + cached_stream_allowance -= 1; + } else { + covered_terminal_misses -= 1; + } + remaining += 1; + } else if compact && !reused { + // The bound properties and their writes ran before the footprint test. + remaining += 1; + } else if compact && discard_allowance == 0 && saved_property_work >= property_cost && property_work >= property_cost { + // A reused off-grid stamp can spend work saved by earlier bound arithmetic. + // Charge the same cost as recomputing its properties and retain both ceilings. + saved_property_work -= property_cost; + property_work -= property_cost; + remaining += 1; + } else { + discarded_draw = true; + } + } else { + // A parent visit schedules at most four terminal children. A cached parent + // still pays for its own visit or uses a bounded streaming credit below. + accounted_stamps += usize::from(!reused || terminal_siblings.is_some()); + stamps.push(stamp); + } } - let mut child_random = visit.seed; - for (slot, child) in node.children.iter().enumerate() { - let child_seed = crate::random::quadrant_child(&mut child_random, visit.depth.saturating_add(1)); - if let Some(child) = child { - let mut child_visit = visit.clone(); - child_visit.node = *child; - child_visit.depth = visit.depth.saturating_add(1); - child_visit.extent *= 0.5; - child_visit.seed = child_seed; - child_visit.center = [ - visit.center[0] + (if slot & 1 == 0 { -0.25 } else { 0.25 }) * visit.extent, - visit.center[1] + (if slot & 2 == 0 { -0.25 } else { 0.25 }) * visit.extent, - ]; - children.push(child_visit); + if quadrant_children == QuadrantChildren::AllTerminal { + terminal_siblings = Some(TerminalSiblings { stack: pending.len(), discarded: false }); + } + if quadrant_children != QuadrantChildren::None { + let mut child_random = visit.seed; + for (child, center) in node.children.iter().zip(visit.quadrant_centers()) { + let child_seed = crate::random::quadrant_child(&mut child_random, visit.depth.saturating_add(1)); + if let Some(child) = child { + let mut child_visit = visit.clone(); + child_visit.node = *child; + child_visit.depth = visit.depth.saturating_add(1); + child_visit.extent *= 0.5; + child_visit.seed = child_seed; + child_visit.center = center; + children.push(child_visit); + } } } } PatternNodeKind::Switch => { - let slot = usize::from(parameters.get("switch").and_then(Value::as_bool).unwrap_or(false)); + let slot = usize::from(field("switch").and_then(Value::as_bool).unwrap_or(false)); if let Some(Some(child)) = node.children.get(slot) { visit.node = *child; children.push(visit); + } else if fixed_switches.contains(&node.id) { + empty_switches.insert(node.id); } } PatternNodeKind::Iterate => { - let count = usize::try_from(integer("numberadded")).map_err(|_| "iteration count cannot be negative")?; - if count > remaining || count > 10_000 { - return Err("pattern iteration count exceeds the execution budget".into()); - } + let count = u32::try_from(integer("numberadded")).map_err(|_| "iteration count cannot be negative")?; - if let Some(Some(child)) = node.children.first() { - let mut first = visit.clone(); - first.node = *child; - first.number = 0; - first.seed = crate::random::hash(visit.seed.wrapping_add(1)); - children.push(first); - } - if let Some(Some(child)) = node.children.get(1) { - for number in 0..count { - let mut repeated = visit.clone(); - repeated.node = *child; - repeated.number = number as u32; - repeated.seed = crate::random::hash(visit.seed.wrapping_add(number as u32 + 2)); - children.push(repeated); + if grayscale + && Some(node.id) == graph.root + && node.children.first() == Some(&None) + && !graph.nodes.iter().any(|other| other.id != node.id && other.kind == PatternNodeKind::Iterate) + { + repeated_roots = Some(0_usize); + if opacity_depth == 6 && count > 1 && !context.b("cull_outside") { + repeated_six_level = Some(super::repeated_six_level::RepeatedSixLevelRuns::default()); } } + if let Some(Some(child)) = node.children.first() { + // The initial branch keeps the enclosing iteration's number and seed. + children.push(PatternVisit { node: *child, seed: incoming_seed, ..visit.clone() }); + } + if let Some(repeats_left) = count.checked_sub(1) + && let Some(Some(child)) = node.children.get(1) + && !empty_switches.contains(child) + { + if visit.depth > 0 && (repeats_left != 0 || !children.is_empty()) { + seven_level_runs = None; + if !children.is_empty() || mixed_depth_runs.as_mut().is_some_and(|runs| !runs.repeat_parent(visit.depth, repeats_left)) { + mixed_depth_runs = None; + } + } + // Each connected visit costs at least one unit, even if its stamp is discarded. + // A fixed switch can discover an empty branch on its first visit and skip the rest. + if count as usize > remaining + discard_allowance && !fixed_switches.contains(child) { + return Err("pattern iteration count exceeds the execution budget".into()); + } + let first = PatternVisit { node: *child, number: 0, seed: crate::random::iteration_child(visit.seed), ..visit }; + repeated = Some((first, repeats_left)); + } } } - if children.len().saturating_add(pending.len()) > remaining { + if !empty_switches.is_empty() { + children.retain(|child| { + if empty_switches.contains(&child.node) { + // A cached empty branch still contributes its visited depth to draw ordering. + max_depth = max_depth.max(child.depth); + false + } else { + true + } + }); + } + // A quadrant with no shape and no live children has finished evaluating its + // properties. Charge it to the same bounded allowance as a discarded draw. + let empty_quadrant = node.kind == PatternNodeKind::Quadrant && pattern == 0 && children.is_empty(); + if quadrant_children == QuadrantChildren::None + && terminal_siblings.as_ref().is_some_and(|siblings| pending.len() == siblings.stack) + && let Some(siblings) = terminal_siblings.take() + && siblings.discarded + { + // One reused or compact property pass covers the group's first discarded draw. + // Sibling groups can reuse different numbers of stamps. Parents and visible + // stamps still pay for their own visits, and full evaluations stay bounded. + if covered_terminal_misses > 0 { + covered_terminal_misses -= 1; + } else if discard_allowance > 0 { + discard_allowance -= 1; + } else { + remaining = remaining.checked_sub(1).ok_or("pattern graph exceeded its execution budget")?; + } + } + if node.kind == PatternNodeKind::Quadrant && pattern == 0 && !children.is_empty() && property_cost < DrawingExpressions::FULL_COST { + // This routing quadrant paid for its bound branch expression. The stack + // and every scheduled child retain their own visit and draw limits. + remaining += 1; + } + if discard_allowance > 0 && (discarded_draw || empty_quadrant) { + discard_allowance -= 1; + remaining += 1; + } + // Once every subtree ordering has been ruled out, equal-ranked stamps can be composited + // immediately in traversal order. Reuse their storage and preserve all F32 adds. + if stamps.len() >= stream_chunk + && max_depth > 6 + && mixed_depth_runs.is_none() + && terminal_quadrants.is_none() + && sparse_runs.is_none() + && underfilled.is_none() + && seven_level_runs.is_none() + && repeated_six_level.is_none() + && *uniform_order.get_or_insert_with(|| uniform_deep_draws(graph.root, &nodes)) + { + // Other cached draws, including direct repetitions, have a separate bounded allowance. + let cached_credit = (stamps.len() - accounted_stamps).min(cached_stream_allowance); + // These stamps have already been composited when the next chunk starts. + quadrant_fork = None; + raster_work.streaming = true; + let group = [super::pattern_stamp::DrawRun::whole(&stamps)]; + let image = raster::render(context, &group, &opacities, nonfinite_gray_opacity, base_level_only, runtime_image_selector, &mut raster_work)?; + raster_work.background = Some(image); + cached_stream_allowance -= cached_credit; + remaining = remaining.saturating_add(accounted_stamps + cached_credit); + accounted_stamps = 0; + stamps.clear(); + } + // The count and its assignments have run. A single repetition with no initial + // child can enter that child directly without allocating a traversal-stack entry. + if children.is_empty() && matches!(repeated, Some((_, 0))) { + immediate = repeated.take(); + remaining += 1; + } + if children.len() + pending.len() + usize::from(repeated.is_some() || immediate.is_some()) > remaining { return Err("pattern graph exceeded its execution budget".into()); } - pending.extend(children.into_iter().rev()); + variables.keep_for_children(pending.len(), declared); + if track_root_children { + if root_siblings.is_some() { + // Multiple emitted trees can interleave. A single tree's four child ranges no longer describe the draw. + branch_starts.fill(None); + root_children_pending = 0; + } else { + // Outer repetitions can remain on the stack while the only emitted tree visits its four children. + root_siblings = Some(pending.len()); + root_children_pending = pending.len() + children.len(); + } + } + pending.extend(repeated); + pending.extend(children.drain(..).rev().map(|visit| (visit, 0))); } - Ok(vec![raster::render(context, &stamps, max_depth)?]) + let mut groups = [&[][..]; SEVEN_LEVEL_RUN_ORDER.len()]; + if let Some(run_starts) = seven_level_runs.and_then(|runs| runs.finish(stamps.len())) { + for (group, run) in groups.iter_mut().zip(SEVEN_LEVEL_RUN_ORDER) { + *group = stamps.get(run_starts[run]..run_starts[run + 1]).ok_or("invalid pattern draw range")?; + } + } else { + let mut prefix = stamps.as_slice(); + if max_depth == 6 { + // At six subdivisions the root draws first, then its child streams composite + // in reverse slot order. Within a stream the original draw order is retained. + for (group, start) in groups[1..].iter_mut().zip(branch_starts.into_iter().flatten()) { + let (earlier, branch) = prefix.split_at(start); + *group = branch; + prefix = earlier; + } + } + groups[0] = prefix; + } + let groups = groups.map(super::pattern_stamp::DrawRun::whole); + let mixed_groups = mixed_depth_runs + .and_then(|runs| runs.finish(&stamps)) + .or_else(|| terminal_quadrants.and_then(|runs| runs.finish(&stamps))) + .or_else(|| sparse_runs.and_then(|runs| runs.finish(&stamps))) + .or_else(|| underfilled.and_then(|runs| runs.finish(&stamps))) + .or_else(|| repeated_six_level.and_then(|runs| runs.finish(&stamps, repeated_roots.unwrap_or_default()))) + .or_else(|| repeated_roots.and_then(|repeats| super::repeated_quadrants::runs(context, &stamps, repeats, max_depth))) + .or_else(|| quadrant_fork.and_then(|fork| fork.runs(&stamps))); + let image = raster::render( + context, + mixed_groups.as_deref().unwrap_or(&groups), + &opacities, + nonfinite_gray_opacity, + base_level_only, + runtime_image_selector, + &mut raster_work, + )?; + Ok((image, variables.bound_draw)) } diff --git a/crates/nodes/src/pattern/footprint.rs b/crates/nodes/src/pattern/footprint.rs new file mode 100644 index 00000000..8ae93572 --- /dev/null +++ b/crates/nodes/src/pattern/footprint.rs @@ -0,0 +1,172 @@ +use super::{ + coordinates::PixelPlanes, + pattern_stamp::PatternStamp, + region::{Copies, Region}, +}; +use crate::CookContext; + +pub(super) struct Footprint { + pub sine: f32, + pub cosine: f32, + pub radius: [f32; 2], +} + +impl Footprint { + pub fn new(stamp: &PatternStamp) -> Result { + if stamp.rotation == 0.0 { + return Ok(Self { sine: stamp.rotation, cosine: 1.0, radius: stamp.size.map(|s| s.abs() * 0.5) }); + } + let angle = stamp.rotation * std::f32::consts::TAU; + if !angle.is_finite() { + return Err("pattern rotation exceeds the finite angle range".into()); + } + // Sampling uses the pixel phase even when the draw bounds are folded from literals. + let (sine, cosine) = crate::function::pixel_sin_cos(angle); + let (bounds_sine, bounds_cosine) = if stamp.literal_geometry && (stamp.rotation * 4.0).fract() != 0.0 { + let (s, c) = f64::from(angle).sin_cos(); + (s as f32, c as f32) + } else { + crate::function::uniform_sin_cos_turns(stamp.rotation) + }; + let radius = [ + (stamp.size[0] * bounds_cosine).abs() * 0.5 + (stamp.size[1] * bounds_sine).abs() * 0.5, + (stamp.size[0] * bounds_sine).abs() * 0.5 + (stamp.size[1] * bounds_cosine).abs() * 0.5, + ]; + Ok(Self { sine, cosine, radius }) + } + + pub fn local(&self, point: [f32; 2], center: [f32; 2], size: [f32; 2]) -> Option<[f32; 2]> { + let delta = [point[0] - center[0], point[1] - center[1]]; + let local = [(delta[0] * self.cosine + delta[1] * self.sine) * 2.0 / size[0], (-delta[0] * self.sine + delta[1] * self.cosine) * 2.0 / size[1]]; + // For axis-aligned stamps the preceding interval owns a sample on the shared edge. + let outside = if self.sine == 0.0 || self.cosine == 0.0 { + // Subtract the radius from the center before testing the open edge at pixel precision. + (0..2).any(|axis| !self.contains_axis(axis, point[axis], center[axis])) + } else { + local.iter().any(|v| *v <= -1.0 || *v > 1.0) + }; + (!outside).then_some(local) + } + + pub(super) fn contains_axis(&self, axis: usize, point: f32, center: f32) -> bool { + point > center - self.radius[axis] && point - center <= self.radius[axis] + } + + pub(super) fn is_axis_aligned(&self) -> bool { + (self.sine == 0.0 && self.cosine.abs() == 1.0) || (self.cosine == 0.0 && self.sine.abs() == 1.0) + } +} + +pub(super) struct SampleGrid { + render: Region, + tiling: Region, + dimensions: [u32; 2], + axes: [bool; 2], + cull_outside: bool, +} + +impl SampleGrid { + pub fn new(context: &CookContext, opacities: &[f32]) -> Option { + // Keep stamps for raster validation if a depth weight overflowed. + if opacities.iter().any(|weight| !weight.is_finite()) { + return None; + } + let (width, height) = craft_texture::clamp_size(context.w, context.h); + let axes = context.tiling_axes(); + let cull_outside = context.b("cull_outside"); + let render = Region::new(context.v4("render_region")).ok()?; + let tiling = Region::tiling(context.v4("tiling_region"), axes, cull_outside).ok()?; + Some(Self { render, tiling, dimensions: [width, height], axes, cull_outside }) + } + + fn repeats(&self, stamp: &PatternStamp, frame: &Footprint) -> Result<[Copies; 2], String> { + let center = self.tiling.copy_origin(stamp.center, self.axes); + self.tiling.repeats(&self.render, center, frame.radius, self.axes) + } + + pub fn copies_per_axis(&self, stamp: &PatternStamp) -> Option<[u64; 2]> { + if self.axes == [false; 2] { + return Some([1; 2]); + } + let frame = Footprint::new(stamp).ok()?; + Some(self.repeats(stamp, &frame).ok()?.map(|axis| axis.count)) + } + + pub fn copy_count(&self, stamp: &PatternStamp) -> Option { + let [x, y] = self.copies_per_axis(stamp)?; + // The measured terminal runs allow an original and one adjacent copy along each axis. + ((1..=2).contains(&x) && (1..=2).contains(&y)).then(|| (x * y) as u32) + } + + pub fn misses(&self, stamp: &PatternStamp) -> bool { + if !(2..=18).contains(&stamp.pattern) + || !(0..=2).contains(&stamp.blend) + || !stamp.center.iter().chain(&stamp.size).chain(&stamp.color).chain([&stamp.rotation, &stamp.variation]).all(|v| v.is_finite()) + { + return false; + } + if self.cull_outside && !self.tiling.contains(stamp.center) { + return true; + } + let Ok(frame) = Footprint::new(stamp) else { return false }; + // A footprint wider than two sample spacings in both directions usually covers a pixel. + if (0..2).all(|i| frame.radius[i] * self.dimensions[i] as f32 > self.render.period()[i]) { + return false; + } + let Ok(repeats) = self.repeats(stamp, &frame) else { return false }; + let copies = repeats[0].count.saturating_mul(repeats[1].count); + if copies == 0 { + return true; + } + // A small tiling period can place many copies in a single pixel. Leave those to the raster budget. + if copies > 4 { + return false; + } + let circular = super::shape::circular(stamp.pattern); + let columns = repeats[0].centers(); + for y_center in repeats[1].centers() { + for x_center in columns.clone() { + let center = [x_center, y_center]; + let bounds = self.render.bounds(center, frame.radius, self.dimensions); + let [[left, right], [top, bottom]] = bounds; + if left == right || top == bottom { + continue; + } + // Bound the search for long, thin stamps that cross the render window. + if u64::from(right - left) * u64::from(bottom - top) > 16 { + return false; + } + // Skip the copy when even the final sample precedes the snapped triangle + // and lies outside the ordinary footprint used for extreme vertex spans. + if frame.is_axis_aligned() + && (0..2).any(|axis| { + let low = center[axis] - frame.radius[axis]; + let end = bounds[axis][1]; + let pixels = self.dimensions[axis]; + let near = self.render.stamp_sample_vertices(axis, center[axis], frame.radius[axis], pixels)[0]; + f64::from(near) + 1.0 >= f64::from(end) && self.render.pixel_center(axis, end - 1, pixels) <= low + }) + { + continue; + } + if let Some(planes) = PixelPlanes::new(&frame, &self.render, center, stamp.size, self.dimensions) { + if planes.covers_any(bounds, circular) { + return false; + } + continue; + } + for y in top..bottom { + for x in left..right { + if frame + .local(self.render.point([x, y], self.dimensions), center, stamp.size) + .is_some_and(|uv| !(circular && super::shape::radius_squared(uv) > 1.0)) + { + return false; + } + } + } + } + } + true + } +} diff --git a/crates/nodes/src/pattern/mixed_depth_runs.rs b/crates/nodes/src/pattern/mixed_depth_runs.rs new file mode 100644 index 00000000..ac3289ec --- /dev/null +++ b/crates/nodes/src/pattern/mixed_depth_runs.rs @@ -0,0 +1,439 @@ +use std::{borrow::Cow, sync::LazyLock}; + +use materialcraft_core::{PatternNode, PatternNodeKind}; + +use super::{ + pattern_stamp::{DrawPosition, DrawRun, PatternStamp}, + raster::MIN_STAMP_SIZE, + tile_runs::{FOUR_CHILDREN, TileCopies, UNIT_WINDOW}, +}; +use crate::CookContext; + +const DEPTH_SEVEN_PARENTS: usize = 4_usize.pow(7); + +// Each pair is the exclusive end in depth-seven parent visits and its compositing position. +// The boundaries come from overlapping original squares. A prefix can end inside a grandchild. +const TWO_CHILDREN: &[(usize, usize)] = &[ + (1308, 8), + (1536, 15), + (1792, 14), + (2048, 16), + (3868, 2), + (4096, 25), + (5404, 4), + (5632, 9), + (5888, 18), + (6144, 10), + (7964, 0), + (8192, 23), + (9500, 6), + (9728, 12), + (9984, 11), + (10240, 13), + (12060, 1), + (12288, 21), + (12800, 20), + (13312, 3), + (13824, 24), + (14336, 5), + (14848, 22), + (15360, 7), + (15872, 17), + (16384, 19), +]; + +// With four children and four grandchildren, the independent subtree boundaries +// are 64 parents apart. Runs ending between them fill one or more physical batches. +const FOUR_CHILDREN_AND_GRANDCHILDREN: &[(usize, usize)] = &[ + (64, 15), + (192, 32), + (1956, 16), + (2048, 33), + (3868, 6), + (4096, 17), + (4160, 9), + (4288, 38), + (6052, 10), + (6144, 28), + (7964, 2), + (8192, 19), + (8256, 12), + (8384, 29), + (10148, 13), + (10240, 31), + (12060, 4), + (12288, 25), + (12352, 23), + (12416, 30), + (12480, 43), + (12684, 24), + (12800, 39), + (13060, 1), + (13312, 8), + (13376, 20), + (13440, 34), + (13504, 45), + (13732, 21), + (13824, 42), + (14084, 3), + (14336, 11), + (14400, 26), + (14464, 35), + (14528, 40), + (14756, 27), + (14848, 41), + (15108, 5), + (15360, 14), + (15620, 7), + (15680, 36), + (15712, 18), + (15808, 44), + (15872, 37), + (16132, 0), + (16384, 22), +]; + +// With two trees, each drawing parent and its descendants submit 21 draws before tiling. +// At the end of the first 30 runs a physical batch holds 92 + 128 parents. +// The next 40 finish that batch inside the run starting at parent 12,352. +const CONTINUED_PARENT: usize = 12_352 + 40; +fn continued_layout(prefix: &[(usize, usize)], common: usize, tail: &[usize]) -> Vec<(usize, usize)> { + let mut layout: Vec<_> = prefix.iter().filter(|(_, rank)| *rank < common).copied().collect(); + layout.extend(tail.iter().enumerate().map(|(rank, &end)| (end, common + rank))); + layout.sort_unstable(); + layout +} + +static PAIRED_GRANDCHILDREN: LazyLock> = LazyLock::new(|| { + const COMMON_RUNS: usize = 30; + // Exclusive parent counts in submission order. Counts above 16,384 belong + // to the second tree. Signed overlaps measure where its batches take the + // unfinished draws from the first tree, even when a parent misses the image. + let tail = [ + CONTINUED_PARENT, + 12800, + 14528, + 32596, + 12416, + 29680, + 13824, + 12480, + 24452, + 10240, + 192, + 30508, + 14848, + 28612, + 2048, + 13440, + 14464, + 31532, + 15808, + 13504, + 20352, + 15680, + 15872, + 4288, + 31808, + 32140, + 29696, + 20736, + 22276, + 30720, + 24640, + 26572, + 31744, + 16448, + 18380, + 24576, + 29832, + 22528, + 24648, + 32768, + 28760, + 28672, + 30920, + 32256, + 20880, + 18432, + 30080, + 31056, + 28800, + 28928, + 29184, + 31132, + 29952, + 30208, + 29004, + 24768, + 28864, + 21068, + 20480, + 31936, + 30084, + 21120, + 26624, + 16576, + 31104, + 20992, + 21248, + 31168, + 30976, + 31232, + 21184, + 29056, + 30144, + ]; + continued_layout(FOUR_CHILDREN_AND_GRANDCHILDREN, COMMON_RUNS, &tail) +}); + +// When five physical batches fit before parent 22,528, the rest of that +// subtree joins the two pending subtrees beginning at parent 24,640. +// Integral subtree ends are fixed. Interior markers select a subtree and +// the physical copy count locates the actual split inside it. +fn tiled_pair_continuation(five_batches: bool) -> Vec<(usize, usize)> { + let cut = if five_batches { 22465 } else { 22273 }; + let mut tail = vec![cut, 30720, 24640, 26497, 31744, 16448, 18369, 20480, 31873, 24576, 29761]; + if !five_batches { + // After four complete batches the remaining draws fill a fifth with + // the first copies from the two pending subtrees. + tail.extend([22528, 24641]); + } + tail.extend([32768, 28737, 28672, 30913, 32256, 20865, 28800, 28928, 29184, 31105, 29824, 29952, 30208, 28929]); + if five_batches { + tail.push(22528); + } + tail.extend([24768, 28864, 21120, 26624, 16576, 18432, 29888, 31104, 20992, 21248, 31168, 30976, 31232, 21184, 29056, 31936, 30080]); + let mut layout = continued_layout(&PAIRED_GRANDCHILDREN, 58, &tail); + for (end, rank) in &mut layout { + // Two eight-batch cuts now fall in the preceding 64-parent subtree. + match rank { + 38 => *end = 24385, + 43 => *end = 28545, + _ => {} + } + } + layout.sort_unstable(); + layout +} + +static FIVE_BATCH_CONTINUATION: LazyLock> = LazyLock::new(|| tiled_pair_continuation(true)); +static FOUR_BATCH_CONTINUATION: LazyLock> = LazyLock::new(|| tiled_pair_continuation(false)); + +enum ReceivingBatch { + FirstHalf, + SecondHalf, + DeferredPair, +} + +// Three pending subtrees start before the later quadrant when the cut +// before 18,432 falls before 18,368. If the pair ending at 31,936 cannot +// fill the receiving batch, it resumes in the run that returns to 21,120. +fn receiving_pair_continuation(receiver: ReceivingBatch) -> Vec<(usize, usize)> { + let first_half = matches!(receiver, ReceivingBatch::FirstHalf); + let deferred = matches!(receiver, ReceivingBatch::DeferredPair); + let mut ordered = PAIRED_GRANDCHILDREN.to_vec(); + ordered.sort_unstable_by_key(|&(_, rank)| rank); + let mut ends = Vec::with_capacity(ordered.len()); + for (end, _) in ordered { + match end { + // Physical batch ends can move into another 64-parent subtree. + 24452 if !first_half => ends.push(24449), + 28612 => ends.push(28545), + 22276 => ends.push(22465), + 18380 => ends.push(18305), + 29832 if first_half => ends.push(29823), + 30920 => ends.push(30849), + 31056 => ends.push(if first_half { 31041 } else { 30977 }), + 24576 if !deferred => ends.extend([20480, 31873, end]), + 30080 if first_half => ends.push(29888), + 29952 if first_half => ends.extend([29824, end]), + 24768 => ends.extend([22528, end]), + // The pending pair can finish exactly at the end of its second subtree. + 21120 if deferred => ends.extend([20993, 20480, 31936, 30081, end]), + 30144 if !deferred => ends.extend([31936, if first_half { 30080 } else { end }]), + // These parts moved above or joined the preceding full batch. + 22528 | 24648 | 21068 | 20480 | 31936 | 30084 => {} + _ => ends.push(end), + } + } + continued_layout(&[], 0, &ends) +} + +static FIRST_HALF_RECEIVER: LazyLock> = LazyLock::new(|| receiving_pair_continuation(ReceivingBatch::FirstHalf)); +static SECOND_HALF_RECEIVER: LazyLock> = LazyLock::new(|| receiving_pair_continuation(ReceivingBatch::SecondHalf)); +static DEFERRED_PAIR: LazyLock> = LazyLock::new(|| receiving_pair_continuation(ReceivingBatch::DeferredPair)); + +#[derive(Default)] +pub(super) struct MixedDepthRuns { + layout: &'static [(usize, usize)], + starts: Vec, + next_boundary: usize, + parents: usize, + extra_parents: usize, + trees: usize, + children_per_parent: usize, + draws_per_parent: usize, + deepest: u32, + draws: usize, + shape: Option, + fixed_image: bool, + single_tree_window: bool, + copies: Option, +} + +impl MixedDepthRuns { + pub(super) fn new(context: &CookContext, deepest: u32, fixed_image: bool) -> Option { + if context.b("cull_outside") { + return None; + } + let axes = context.tiling_axes(); + // A common render and tiling window determines the repeated copies along its edges. + let window = if axes == [true; 2] { context.v4("render_region") } else { UNIT_WINDOW }; + let copies = if axes != [false; 2] || deepest == 10 { Some(TileCopies::new(context, deepest, window)?) } else { None }; + Some(Self { copies, deepest, fixed_image, single_tree_window: deepest != 9 || window == UNIT_WINDOW, ..Self::default() }) + } + + pub(super) fn visit(&mut self, node: &PatternNode, depth: u32, retained: usize) -> bool { + if node.kind != PatternNodeKind::Quadrant { + return true; + } + // Count only repetitions that reach a quadrant. Two complete trees can + // share a physical batch across the outer iteration. + if depth == 0 { + if self.trees != 0 { + let continuation = match self.deepest { + 9 => self.children_per_parent == 4 && self.copies.as_ref().is_none_or(TileCopies::tiles_both_axes), + 10 => self.copies.as_ref().is_some_and(TileCopies::complete_inactive_tree), + _ => false, + }; + if !continuation + || self.trees != 1 + || self.extra_parents != 0 + || self.parents != DEPTH_SEVEN_PARENTS + || self.draws != self.parents * self.draws_per_parent + { + return false; + } + } + self.trees += 1; + } + if depth != 7 { + return match depth { + 5 if self.deepest == 10 => { + node.children.iter().all(Option::is_some) && self.copies.as_mut().is_some_and(|c| c.begin_inactive_subtree(self.trees)) + } + 0..=6 => node.children.iter().flatten().count() == 4, + 8 if self.deepest == 9 => node.children.iter().all(Option::is_some), + // Connected child routes can terminate without visiting another quadrant. + 8 if self.deepest == 10 => true, + 9.. if self.deepest == 10 => false, + depth if depth == self.deepest => node.children.iter().all(Option::is_none), + _ => false, + }; + } + let children = node.children.iter().flatten().count(); + if self.children_per_parent == 0 { + (self.layout, self.draws_per_parent) = match (self.deepest, children) { + (8, 2) => (TWO_CHILDREN, 3), + (8, 4) => (FOUR_CHILDREN, 5), + (9, 4) => (PAIRED_GRANDCHILDREN.as_slice(), 21), + (10, 4) => (&[][..], 5), + _ => return false, + }; + self.children_per_parent = children; + self.starts.reserve_exact(self.layout.len() + 1); + } + if children != self.children_per_parent { + return false; + } + if !self.layout.is_empty() && self.parents == self.next_boundary { + let Some(&(end, _)) = self.layout.get(self.starts.len()) else { return false }; + self.starts.push(DrawPosition { stamp: retained, copy: 0 }); + self.next_boundary = end; + } + self.parents += 1; + true + } + + // A second visit to a drawing parent belongs to the same depth-five subtree. + // An iteration at another level changes which subtrees can submit together. + pub(super) fn repeat_parent(&mut self, depth: u32, repeats_left: u32) -> bool { + if self.deepest != 10 || self.trees != 1 || depth != 7 || repeats_left != 1 || self.extra_parents == DEPTH_SEVEN_PARENTS { + return false; + } + self.extra_parents += 1; + true + } + + pub(super) fn draw(&mut self, stamp: &PatternStamp, opacities: &[f32], retained: bool) -> bool { + let Some(weight) = opacities.get(stamp.depth as usize) else { return false }; + let measured_shape = (2..=16).contains(&stamp.pattern) || (self.fixed_image && stamp.pattern >= 256); + // Turning off unrelated draws changes the order even where those draws never overlap the readout. + if !(7..=self.deepest).contains(&stamp.depth) + || stamp.blend != 0 + || !measured_shape + || *self.shape.get_or_insert(stamp.pattern) != stamp.pattern + || !(stamp.color[3] * weight).is_normal() + || stamp.size.iter().any(|axis| axis.abs() < MIN_STAMP_SIZE) + { + return false; + } + self.draws += 1; + self.copies.as_mut().is_none_or(|copies| copies.record(stamp, retained, self.draws, self.draws_per_parent).is_some()) + } + + pub(super) fn finish(mut self, stamps: &[PatternStamp]) -> Option>> { + if self.trees == 0 || self.parents != self.trees * DEPTH_SEVEN_PARENTS + self.extra_parents || self.draws != self.parents * self.draws_per_parent { + return None; + } + if self.deepest == 9 && self.trees == 1 { + // Every recorded draw has at least one copy. A wider window keeps the same + // batch boundaries when none of those draws crosses a tiling edge. + if !self.single_tree_window && self.copies.as_ref().is_none_or(|copies| copies.copy_count() != self.draws) { + return None; + } + // Only a continuation splits this run. Rejoin the two retained + // ranges before flushing the unfinished batches of a single tree. + let split = self.layout.partition_point(|&(end, _)| end <= CONTINUED_PARENT); + self.starts.get(split)?; + self.starts.remove(split); + self.layout = FOUR_CHILDREN_AND_GRANDCHILDREN; + } + if self.starts.len() != self.layout.len() { + return None; + } + if self.deepest == 10 { + return self.copies?.inactive_child_runs(stamps); + } + self.starts.push(DrawPosition { stamp: stamps.len(), copy: 0 }); + let mut layout = Cow::Borrowed(self.layout); + if let Some(copies) = self.copies { + if self.children_per_parent == 2 { + return copies.two_child_runs(stamps); + } + if self.trees == 1 { + layout = copies.layout(self.layout)?; + self.starts = copies.boundaries(&layout, self.draws_per_parent)?; + } else { + let candidates = [ + FIVE_BATCH_CONTINUATION.as_slice(), + FOUR_BATCH_CONTINUATION.as_slice(), + FIRST_HALF_RECEIVER.as_slice(), + SECOND_HALF_RECEIVER.as_slice(), + DEFERRED_PAIR.as_slice(), + self.layout, + ]; + let (selected, bounds) = + candidates.into_iter().find_map(|candidate| copies.boundaries(candidate, self.draws_per_parent).map(|bounds| (candidate, bounds)))?; + layout = Cow::Borrowed(selected); + self.starts = bounds; + } + } + let mut groups = vec![DrawRun::whole(&[]); layout.len()]; + for ((_, rank), bounds) in layout.iter().zip(self.starts.windows(2)) { + *groups.get_mut(*rank)? = DrawRun::between(stamps, bounds[0], bounds[1])?; + } + Some(groups) + } +} diff --git a/crates/nodes/src/pattern/mod.rs b/crates/nodes/src/pattern/mod.rs index c44a54f1..93a2e5d3 100644 --- a/crates/nodes/src/pattern/mod.rs +++ b/crates/nodes/src/pattern/mod.rs @@ -1,13 +1,29 @@ +mod bitmap; +mod blend; mod catalog; +mod conditional_tint; +mod coordinates; mod evaluation; +mod footprint; +mod mixed_depth_runs; mod pattern_stamp; mod pattern_visit; +mod quadrant_fork; mod raster; mod region; +mod repeated_quadrants; +mod repeated_six_level; mod shape; +mod stamp_cache; +mod terminal_quadrants; +mod tile_runs; +mod underfilled_quadrants; +mod variables; +pub use crate::atomic::input_resize::direct_background_sample; pub use catalog::{definition, definitions}; pub(crate) use evaluation::cook; +pub use evaluation::{cook_with_base_level_inputs, cook_with_bound_properties, cook_with_image_dependencies}; #[cfg(test)] mod tests; diff --git a/crates/nodes/src/pattern/pattern_stamp.rs b/crates/nodes/src/pattern/pattern_stamp.rs index 9a854adf..7dcb11f1 100644 --- a/crates/nodes/src/pattern/pattern_stamp.rs +++ b/crates/nodes/src/pattern/pattern_stamp.rs @@ -1,9 +1,10 @@ +#[derive(Clone)] pub(super) struct PatternStamp { pub center: [f32; 2], pub size: [f32; 2], pub rotation: f32, + pub literal_geometry: bool, pub color: [f32; 4], - pub scalar_color: bool, pub depth: u32, pub pattern: i32, pub variation: f32, @@ -11,3 +12,72 @@ pub(super) struct PatternStamp { pub filtering: i32, pub premultiplied: bool, } + +/// A position between tile copies in traversal order. +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +pub(super) struct DrawPosition { + pub stamp: usize, + pub copy: u32, +} + +/// Boundaries in the complete tile stream, including draws discarded before rasterization. +#[derive(Default)] +pub(super) struct CopyPositions { + pub total: u32, + retained: Vec>, +} + +impl CopyPositions { + pub fn record(&mut self, count: u32, retained: bool) -> Option> { + let start = self.total; + self.total = start.checked_add(count)?; + let range = start..self.total; + if retained { + self.retained.push(range.clone()); + } + Some(range) + } + + pub fn at(&self, cut: u32) -> DrawPosition { + let stamp = self.retained.partition_point(|range| range.end <= cut); + // Across discarded draws the next retained stamp starts at its first copy. + let copy = self.retained.get(stamp).map_or(0, |range| cut.saturating_sub(range.start)); + DrawPosition { stamp, copy } + } +} + +#[derive(Clone, Copy)] +pub(super) struct DrawRun<'a> { + stamps: &'a [PatternStamp], + first_copy: u32, + end_copy: u32, +} + +impl<'a> DrawRun<'a> { + pub fn whole(stamps: &'a [PatternStamp]) -> Self { + Self { stamps, first_copy: 0, end_copy: 0 } + } + + pub fn between(stamps: &'a [PatternStamp], start: DrawPosition, end: DrawPosition) -> Option { + if start > end { + return None; + } + if start == end { + return Some(Self::whole(&[])); + } + let stop = end.stamp.checked_add(usize::from(end.copy != 0))?; + Some(Self { stamps: stamps.get(start.stamp..stop)?, first_copy: start.copy, end_copy: end.copy }) + } + + pub fn is_empty(&self) -> bool { + self.stamps.is_empty() + } + + pub fn draws(&self) -> impl Iterator)> + Clone + '_ { + self.stamps.iter().enumerate().map(|(i, stamp)| { + let first = if i == 0 { u64::from(self.first_copy) } else { 0 }; + let end = if i + 1 == self.stamps.len() && self.end_copy != 0 { u64::from(self.end_copy) } else { u64::MAX }; + (stamp, first..end) + }) + } +} diff --git a/crates/nodes/src/pattern/pattern_visit.rs b/crates/nodes/src/pattern/pattern_visit.rs index f4a95e37..d6f3278f 100644 --- a/crates/nodes/src/pattern/pattern_visit.rs +++ b/crates/nodes/src/pattern/pattern_visit.rs @@ -7,3 +7,16 @@ pub(super) struct PatternVisit { pub number: u32, pub seed: u32, } + +impl PatternVisit { + pub fn quadrant_centers(&self) -> [[f32; 2]; 4] { + let half = self.extent * 0.5; + let [left, top] = self.center.map(|v| v - self.extent * 0.25); + // Moving between siblings rounds each step, including the return to the + // left column when the preceding slot has no connected node. + let right = left + half; + let lower_left = right - half; + let bottom = top + half; + [[left, top], [right, top], [lower_left, bottom], [lower_left + half, bottom]] + } +} diff --git a/crates/nodes/src/pattern/quadrant_fork.rs b/crates/nodes/src/pattern/quadrant_fork.rs new file mode 100644 index 00000000..3d88797f --- /dev/null +++ b/crates/nodes/src/pattern/quadrant_fork.rs @@ -0,0 +1,120 @@ +use std::ops::Range; + +use materialcraft_core::{PatternNode, PatternNodeKind}; + +use super::{ + footprint::SampleGrid, + pattern_stamp::{DrawRun, PatternStamp}, + raster::MIN_STAMP_SIZE, + tile_runs::COPIES_PER_BATCH, +}; + +/// A path splits six subdivisions above the leaves. Its last connected child +/// continues the parent draw stream, including when that child draws nothing. +#[derive(Default)] +pub(super) struct QuadrantFork { + depth: u32, + children_left: Option, + first_child: Option, + last_child: Option, + pair: bool, + repeated: bool, + earlier_children: Vec>, + pattern: Option, + continuation_copies: u64, +} + +impl QuadrantFork { + pub(super) fn new(depth: u32) -> Self { + Self { depth, ..Self::default() } + } + + pub(super) fn visit(&mut self, node: &PatternNode, depth: u32, retained: usize) -> bool { + if node.kind != PatternNodeKind::Quadrant { + // An outer gate can emit several trees. Repetitions inside a child have additional draw streams. + return depth == 0 || node.kind == PatternNodeKind::Dot; + } + if depth == 0 && self.children_left.is_some() { + if !self.pair || self.finish_tree().is_none() { + return false; + } + self.children_left = None; + self.repeated = true; + } + if depth <= self.depth { + if self.children_left.is_some() { + return false; + } + let count = node.children.iter().flatten().count(); + if depth < self.depth { + return count == 1; + } + self.pair = count == 2; + self.children_left = Some(count); + return count >= 2 && (!self.repeated || self.pair); + } + if depth == self.depth + 1 { + let Some(left) = self.children_left.and_then(|count| count.checked_sub(1)) else { return false }; + self.children_left = Some(left); + self.first_child.get_or_insert(retained); + if left == 0 { + self.last_child = Some(retained); + } + } + true + } + + pub(super) fn draw(&mut self, stamp: &PatternStamp, weights: &[f32], grid: Option<&SampleGrid>) -> bool { + if stamp.blend != 0 || !(2..=16).contains(&stamp.pattern) || *self.pattern.get_or_insert(stamp.pattern) != stamp.pattern { + return false; + } + if self.first_child.is_some() && self.last_child.is_none() { + return true; + } + let Some(weight) = weights.get(stamp.depth as usize) else { return false }; + let gain = weight * stamp.color[3]; + if gain == 0.0 || stamp.size.iter().any(|side| side.abs() < MIN_STAMP_SIZE) { + return true; + } + let Some(copies) = grid.and_then(|g| g.copies_per_axis(stamp)).and_then(|[x, y]| x.checked_mul(y)) else { return false }; + // Once the continuation submits a full batch, it can interleave with its sibling. + // Count wrapped copies before discarding draws that miss the current sample grid. + self.continuation_copies = self.continuation_copies.saturating_add(copies); + gain.is_normal() && self.continuation_copies < u64::from(COPIES_PER_BATCH) + } + + fn finish_tree(&mut self) -> Option<()> { + let earlier = self.first_child.take()?..self.last_child.take()?; + if !earlier.is_empty() { + if let Some(last) = self.earlier_children.last_mut() + && last.end == earlier.start + { + last.end = earlier.end; + } else { + self.earlier_children.push(earlier); + } + } + Some(()) + } + + pub(super) fn runs(mut self, stamps: &[PatternStamp]) -> Option>> { + self.finish_tree()?; + if self.earlier_children.is_empty() { + return None; + } + let mut runs = Vec::new(); + for range in &self.earlier_children { + runs.push(DrawRun::whole(stamps.get(range.clone())?)); + } + // Prefixes and last children share one stream across the emitted pairs. + let mut cursor = 0; + for range in self.earlier_children { + if cursor < range.start { + runs.push(DrawRun::whole(stamps.get(cursor..range.start)?)); + } + cursor = range.end; + } + runs.push(DrawRun::whole(stamps.get(cursor..)?)); + Some(runs) + } +} diff --git a/crates/nodes/src/pattern/raster.rs b/crates/nodes/src/pattern/raster.rs index 7827c60f..eb23608f 100644 --- a/crates/nodes/src/pattern/raster.rs +++ b/crates/nodes/src/pattern/raster.rs @@ -1,42 +1,115 @@ use craft_texture::{Image, Kind, Limits}; +use materialcraft_core::OutputFormat; use std::sync::Arc; -use super::{pattern_stamp::PatternStamp, region::Region, shape}; +use super::{ + bitmap, blend, + coordinates::PixelPlanes, + footprint::Footprint, + pattern_stamp::{DrawRun, PatternStamp}, + region::Region, + shape, +}; use crate::CookContext; +use crate::atomic::input_resize::{InputResize, resized_input}; +use crate::function::flush_subnormal; const MAX_SAMPLES: u64 = 256_000_000; const MAX_STAMP_COPIES: u64 = 1_048_576; -const MIN_STAMP_SIZE: f32 = 1e-8; +pub(super) const MIN_STAMP_SIZE: f32 = 1e-8; -pub(super) fn render(context: &CookContext, stamps: &[PatternStamp], max_depth: u32) -> Result { +pub(super) struct RasterWork { + pub background: Option, + pub streaming: bool, + samples_left: u64, + copies_left: u64, + mipmaps: bitmap::Mipmaps, +} + +impl RasterWork { + pub fn new() -> Self { + Self { background: None, streaming: false, samples_left: MAX_SAMPLES, copies_left: MAX_STAMP_COPIES, mipmaps: bitmap::Mipmaps::new() } + } +} + +pub(super) fn render( + context: &CookContext, + groups: &[DrawRun<'_>], + opacities: &Result, String>, + nonfinite_gray_opacity: bool, + base_level_only: &[bool], + runtime_image_selector: bool, + work: &mut RasterWork, +) -> Result { let (width, height) = craft_texture::clamp_size(context.w, context.h); let kind = if context.b("color_mode") { Kind::Color } else { Kind::Gray }; - let mut background = - context.input(0).map(|image| image.resize(width, height, context.tile)).unwrap_or_else(|| Image::filled(width, height, kind, context.v4("background"))); - background = if kind == Kind::Gray { background.to_gray() } else { background.to_color() }; - if stamps.is_empty() { + let background = if let Some(previous) = work.background.take() { + previous + } else if context.input(0).is_some_and(|image| image.kind() != kind) { + Image::filled(width, height, kind, [0.0; 4]) + } else { + resized_input(context, 0, InputResize::PatternBackground).unwrap_or_else(|| { + let mut color = context.v4("background"); + if kind == Kind::Gray { + color[0] = (color[0] + color[1] + color[2]) / 3.0; + } + Image::filled(width, height, kind, color.map(flush_subnormal)) + }) + }; + if groups.iter().all(DrawRun::is_empty) { return Ok(background); } let channels = kind.channels(); - let opacity = context.f("opacity").max(0.0); - let weights = depth_weights(context.f("roughness"), max_depth)?; + let opacities = opacities.as_ref().map_err(Clone::clone)?; let integer_sampling = background.integer_sampling(); let mut data = Arc::clone(background.shared_data()); drop(background); let pixels = Arc::make_mut(&mut data); - let mut budget = MAX_SAMPLES; - let mut copies_left = MAX_STAMP_COPIES; let render_region = Region::new(context.v4("render_region"))?; - let period = if context.tile { Region::new(context.v4("tiling_region"))?.period() } else { [1.0; 2] }; + let span = render_region.period(); + let pixel_size = [span[0] / width as f32, span[1] / height as f32]; + let axes = context.tiling_axes(); + let cull_outside = context.b("cull_outside"); + let tile_region = Region::tiling(context.v4("tiling_region"), axes, cull_outside)?; - for stamp in stamps { - if !stamp.center.iter().chain(&stamp.size).chain(&stamp.color).chain([&stamp.rotation, &stamp.variation]).all(|value| value.is_finite()) { + let mut traversal = groups.iter().flat_map(DrawRun::draws); + let mut ordered = Vec::new(); + // A runtime image selector reserves the wired slots in port order. Fixed slots acquire their ranks on first use. + let mut bitmap_ranks = if runtime_image_selector { std::array::from_fn(|index| 256 + index as i32) } else { [0; crate::MAX_IMAGE_INPUTS] }; + let mut next_rank = 256; + let mut draw_order = |stamp: &PatternStamp| { + let mut rank = stamp.pattern; + let mut filtering = 0; + if rank >= 256 + && let Some(slot) = bitmap_ranks.get_mut((rank - 256) as usize) + { + if *slot == 0 { + *slot = next_rank; + next_rank += 1; + } + rank = *slot; + filtering = stamp.filtering; + } + (rank, filtering, stamp.blend != 0) + }; + if !traversal.clone().map(|(stamp, _)| draw_order(stamp)).is_sorted() { + // Assign the remaining ranks in traversal order before the sort compares stamps. + for draw in traversal.by_ref() { + draw_order(draw.0); + ordered.push(draw); + } + // Each shape or bitmap slot draws by filter, then additive before the other blend modes. + ordered.sort_by_key(|(stamp, _)| draw_order(stamp)); + } + for (stamp, selection) in traversal.chain(ordered) { + if !stamp.center.iter().chain(&stamp.size).chain([&stamp.rotation, &stamp.variation]).all(|value| value.is_finite()) { return Err("pattern parameters must be finite".into()); } - if stamp.size.iter().any(|size| size.abs() < MIN_STAMP_SIZE) { + // Check the original center before wrapping can move it back inside the tiling region. + if (cull_outside && !tile_region.contains(stamp.center)) || stamp.size.iter().any(|size| size.abs() < MIN_STAMP_SIZE) { continue; } @@ -48,76 +121,128 @@ pub(super) fn render(context: &CookContext, stamps: &[PatternStamp], max_depth: return Err(format!("unsupported pattern {}", stamp.pattern)); } - let opacity = opacity * weights.get(stamp.depth as usize).copied().ok_or("invalid pattern depth")?; - if !opacity.is_finite() { + let opacity = opacities.get(stamp.depth as usize).copied().ok_or("invalid pattern depth")?; + if !opacity.is_finite() && !nonfinite_gray_opacity { return Err("pattern roughness overflowed its depth opacity".into()); } - // Scalar luminosity weights both RGB and alpha, unlike straight RGBA tint - let source_alpha = if stamp.scalar_color { stamp.color[0] } else { stamp.color[3] }; + let [red, green, blue, authored_alpha] = stamp.color.map(flush_subnormal); + // Flush the stored alpha before a large tint could amplify a subnormal product. + let alpha = flush_subnormal(authored_alpha * flush_subnormal(opacity)); + let channel_tint = [red * alpha, green * alpha, blue * alpha, alpha].map(flush_subnormal); + let tinted_offset = matches!(stamp.pattern, 17 | 18); + let sample_shape = shape::prepare(stamp.pattern, stamp.variation); - let (sine, cosine) = (stamp.rotation * std::f32::consts::TAU).sin_cos(); - let radius = [ - (stamp.size[0] * cosine).abs() * 0.5 + (stamp.size[1] * sine).abs() * 0.5, - (stamp.size[0] * sine).abs() * 0.5 + (stamp.size[1] * cosine).abs() * 0.5, - ]; - let center = if context.tile { std::array::from_fn(|axis| stamp.center[axis].rem_euclid(period[axis])) } else { stamp.center }; - let repeats = if context.tile { render_region.repeats(center, radius, period)? } else { [[0, 0]; 2] }; - let count = |axis: usize| (i64::from(repeats[axis][1]) - i64::from(repeats[axis][0]) + 1).max(0) as u64; - let copies = count(0).checked_mul(count(1)).ok_or("pattern repetition exceeds its budget")?; - copies_left = copies_left.checked_sub(copies).ok_or("pattern repetition exceeds its budget")?; - for repeat_y in repeats[1][0]..=repeats[1][1] { - for repeat_x in repeats[0][0]..=repeats[0][1] { - let center = [center[0] + repeat_x as f32 * period[0], center[1] + repeat_y as f32 * period[1]]; - let [[left, right], [top, bottom]] = render_region.bounds(center, radius, [width, height]); + let frame = Footprint::new(stamp)?; + // The horizontal offset ramp still blends its variation at zero or undefined opacity. + // Image stamps can affect the blend at zero opacity, and skip it at undefined opacity. + if stamp.pattern != 17 && (authored_alpha.is_nan() || (authored_alpha == 0.0 && stamp.pattern < 256)) { + continue; + } + let mut texture = if stamp.pattern >= 256 { + let index = (stamp.pattern - 256) as usize + 1; + let Some(input) = context.input(index).filter(|image| image.kind() == kind) else { continue }; + let format = context.input_formats.get(index).copied().unwrap_or(if input.integer_sampling() { OutputFormat::U16 } else { OutputFormat::F32 }); + let gradients = [ + [frame.cosine * pixel_size[0] / stamp.size[0], -frame.sine * pixel_size[0] / stamp.size[1]], + [frame.sine * pixel_size[1] / stamp.size[0], frame.cosine * pixel_size[1] / stamp.size[1]], + ]; + // An automatic read on a texture with only its base level uses bilinear filtering. + // The original filter selection still determines the order in which the stamps draw. + let filtering = if stamp.filtering == 0 && base_level_only.get(index) == Some(&true) { 1 } else { stamp.filtering }; + Some(bitmap::Sampler::new(input, index, format, filtering, gradients)) + } else { + None + }; + let radius = frame.radius; + let center = tile_region.copy_origin(stamp.center, axes); + let repeats = tile_region.repeats(&render_region, center, radius, axes)?; + let copies = repeats[0].count.checked_mul(repeats[1].count).ok_or("pattern repetition exceeds its budget")?; + let end = selection.end.min(copies); + let selected = end.saturating_sub(selection.start); + if selected == 0 { + continue; + } + // A streamed draw has already paid for its visit and is submitted exactly once. + // Additional tile copies debit the same allowance across every chunk. + let charged = if work.streaming { selected - 1 } else { selected }; + work.copies_left = work.copies_left.checked_sub(charged).ok_or("pattern repetition exceeds its budget")?; + let columns = repeats[0].centers(); + let mut copy = 0_u64; + 'rows: for y_center in repeats[1].centers() { + for x_center in columns.clone() { + if copy == end { + break 'rows; + } + copy += 1; + if copy <= selection.start { + continue; + } + let center = [x_center, y_center]; + let bounds = render_region.bounds(center, radius, [width, height]); + let [[left, right], [top, bottom]] = bounds; let samples = u64::from(right.saturating_sub(left)) * u64::from(bottom.saturating_sub(top)); - budget = budget.checked_sub(samples).ok_or("pattern rendering exceeded its pixel budget")?; + if samples == 0 { + continue; + } + work.samples_left = work.samples_left.checked_sub(samples).ok_or("pattern rendering exceeded its pixel budget")?; + let planes = PixelPlanes::new(&frame, &render_region, center, stamp.size, [width, height]); + if let Some(sampler) = &mut texture { + sampler.start_copy(); + } + let [[left, right], [top, bottom]] = planes.as_ref().map_or(bounds, |p| p.clip(bounds)); for y in top..bottom { + let row = planes.as_ref().map(|planes| planes.row(y)); for x in left..right { - let point = render_region.point([x, y], [width, height]); - let delta = [point[0] - center[0], point[1] - center[1]]; - let local = [(delta[0] * cosine + delta[1] * sine) * 2.0 / stamp.size[0], (-delta[0] * sine + delta[1] * cosine) * 2.0 / stamp.size[1]]; + let local = if let Some(row) = &row { + row(x) + } else { + let point = render_region.point([x, y], [width, height]); + frame.local(point, center, stamp.size) + }; + let Some(local) = local else { continue }; - // The preceding quadrant owns shared edges, including subpixel ones - // Counting both sides can stamp a pixel four extra times - if local.iter().any(|coordinate| *coordinate <= -1.0 || *coordinate > 1.0) { - continue; - } - - let pattern = if stamp.pattern >= 256 { - let index = (stamp.pattern - 256) as usize + 1; - match context.input(index) { - Some(input) => { - let uv = local.map(|coordinate| coordinate * 0.5 + 0.5); - if stamp.filtering == 0 { - input.get((uv[0] * input.width() as f32) as i64, (uv[1] * input.height() as f32) as i64, false) - } else { - input.sample(uv[0], uv[1], false) - } - } - None => [0.0; 4], + let (foreground, stamp_alpha) = if let Some(sampler) = &mut texture { + let sample = sampler.sample(local, [x, y], planes.as_ref(), &mut work.mipmaps)?.map(flush_subnormal); + if kind == Kind::Gray { + // Store coverage before tinting. Its zero then takes the sign of the opacity. + let coverage = (sample[0] - 1.0) + 1.0; + ([coverage * alpha; 4], 1.0) + } else { + let coverage = sample[3] * alpha; + let image_alpha = if stamp.premultiplied { 1.0 } else { 1.0 - (1.0 - sample[3]) }; + let mut color = std::array::from_fn(|i| flush_subnormal(sample[i] * image_alpha) * channel_tint[i]); + color[3] = coverage; + (color, coverage) } } else { - let coverage = shape::coverage(stamp.pattern, local[0], local[1], stamp.variation)?; - [coverage, coverage, coverage, coverage] + let Some((coverage, offset)) = sample_shape(local[0], local[1])? else { continue }; + let coverage = flush_subnormal(coverage); + let offset = flush_subnormal(offset); + let color = channel_tint.map(|tint| if tinted_offset { coverage.mul_add(tint, offset) } else { coverage * tint }); + (color, color[3]) }; let pixel = (y as usize * width as usize + x as usize) * channels; let target = pixels.get_mut(pixel..pixel + channels).ok_or("invalid pattern pixel")?; + let stamp_alpha = flush_subnormal(stamp_alpha); for (channel, target) in target.iter_mut().enumerate() { - let image_alpha = if stamp.pattern >= 256 && !stamp.premultiplied && channel < 3 { pattern[3] } else { 1.0 }; - let alpha = image_alpha * if kind == Kind::Color && channel < 3 { stamp.color[3] } else { 1.0 }; - let tint = if channel == 3 { source_alpha } else { stamp.color[channel] }; - let value = pattern[channel] * tint * alpha * opacity; - *target = match stamp.blend { - // Grayscale legacy maximum blends have no alpha channel to composite - 1 if kind == Kind::Gray => target.max(value), - 1 => value + *target * (1.0 - (pattern[3] * source_alpha * opacity).clamp(0.0, 1.0)), - 2 => target.max(value), - _ => *target + value, - }; + let value = flush_subnormal(foreground[channel]); + let background = flush_subnormal(*target); + *target = flush_subnormal(match (kind, stamp.blend) { + (Kind::Color, _) => blend::color(background, value, stamp_alpha, stamp.blend, channel), + (Kind::Gray, 1 | 2) => background.max(value), + (Kind::Gray, _) if value == 0.0 => background, + (Kind::Gray, _) => background + value, + }); if !target.is_finite() { - return Err("pattern accumulation overflowed".into()); + let undefined_channel = target.is_nan() + && (authored_alpha.is_nan() || background.is_nan() || (kind == Kind::Color && stamp.color[channel].is_nan())); + if !nonfinite_gray_opacity && !undefined_channel { + return Err("pattern accumulation overflowed".into()); + } + // Each stamp reads the preceding stored result. Only the completed blend saturates. + *target = if target.is_nan() { f32::from_bits(0x7fff_ffff) } else { target.clamp(f32::MIN, f32::MAX) }; } } } @@ -129,35 +254,26 @@ pub(super) fn render(context: &CookContext, stamps: &[PatternStamp], max_depth: Image::from_data(width, height, kind, data, &Limits::default()).map(|image| image.with_integer_sampling(integer_sampling)).map_err(|e| e.to_string()) } -fn depth_weights(roughness: f32, max_depth: u32) -> Result, String> { +pub(super) fn depth_opacities(roughness: f32, max_depth: u32, opacity: f32) -> Result, String> { // Match the depth allocation cap to the 4096-node acyclic traversal limit if max_depth >= 4096 || !roughness.is_finite() || roughness < 0.0 { return Err("pattern roughness must be finite and nonnegative, with depth below 4096".into()); } - let mut weights = vec![1.0_f64; max_depth as usize + 1]; - - // Zero is the native no-attenuation mode, not the limit of the normalized geometric weights + let count = max_depth + 1; + // A zero roughness gives every visited depth the full opacity. if roughness == 0.0 { - return Ok(weights.into_iter().map(|value| value as f32).collect()); + return Ok(vec![opacity; count as usize]); } - // Normalize depth weights across drawing and non-drawing ancestors - // Start at the largest weight to avoid overflow - let mut weight = 1.0; - let ratio = f64::from(roughness); - if roughness <= 1.0 { - for value in &mut weights { - *value = weight; - weight *= ratio; - } + // Round the geometric endpoint before subtracting it, particularly near unit roughness. + let first_weight = if roughness == 1.0 { + 1.0 / count as f32 } else { - for value in weights.iter_mut().rev() { - *value = weight; - weight /= ratio; - } - } + let endpoint = roughness.powf(count as f32); + (1.0 - roughness) / (1.0 - endpoint) + }; - let sum: f64 = weights.iter().sum(); - Ok(weights.into_iter().map(|value| (value / sum) as f32).collect()) + // Each child inherits its parent's stored opacity, including the global multiplier. + Ok(std::iter::successors(Some(first_weight * opacity), |parent| Some(parent * roughness)).take(count as usize).collect()) } diff --git a/crates/nodes/src/pattern/region.rs b/crates/nodes/src/pattern/region.rs index 981b0986..8484bf9f 100644 --- a/crates/nodes/src/pattern/region.rs +++ b/crates/nodes/src/pattern/region.rs @@ -1,22 +1,73 @@ /// FX-Map regions use left, right, top, bottom coordinates in pattern space. pub(super) struct Region { start: [f32; 2], + end: [f32; 2], span: [f32; 2], } +#[derive(Clone, Copy)] +pub(super) struct Copies { + pub count: u64, + outermost: f32, + period: f32, +} + +impl Copies { + pub fn centers(self) -> impl Iterator + Clone { + (0..self.count).scan(self.outermost, move |next, _| { + let current = *next; + *next -= self.period; + Some(current) + }) + } +} + impl Region { + pub fn tiling(mut value: [f32; 4], axes: [bool; 2], cull_outside: bool) -> Result { + for (interval, enabled) in value.as_chunks_mut::<2>().0.iter_mut().zip(axes) { + if !enabled && !cull_outside { + *interval = [0.0, 1.0]; + } + } + Self::new(value) + } + pub fn new(value: [f32; 4]) -> Result { - let start = [value[0], value[2]]; - let span = [value[1] - value[0], value[3] - value[2]]; + let mut start = [value[0], value[2]]; + let mut end = [value[1], value[3]]; + let mut span = [end[0] - start[0], end[1] - start[1]]; if value.iter().any(|value| !value.is_finite()) || span.iter().any(|value| !value.is_finite() || value.abs() < f32::EPSILON) { return Err("pattern regions must be finite with nonzero width and height".into()); } - Ok(Self { start, span }) + for axis in 0..2 { + if span[axis] < 0.0 { + // A reversed interval selects the full axis in pattern space. + start[axis] = 0.0; + end[axis] = 1.0; + span[axis] = 1.0; + } + } + Ok(Self { start, end, span }) + } + + pub fn contains(&self, point: [f32; 2]) -> bool { + point.into_iter().enumerate().all(|(axis, value)| (self.start[axis]..self.end[axis]).contains(&value)) } pub fn point(&self, pixel: [u32; 2], size: [u32; 2]) -> [f32; 2] { - std::array::from_fn(|axis| self.start[axis] + (pixel[axis] as f32 + 0.5) / size[axis] as f32 * self.span[axis]) + std::array::from_fn(|axis| self.pixel_center(axis, pixel[axis], size[axis])) + } + + pub fn pixel_center(&self, axis: usize, pixel: u32, size: u32) -> f32 { + self.start[axis] + (pixel as f32 + 0.5) / size as f32 * self.span[axis] + } + + pub fn stamp_sample_vertices(&self, axis: usize, center: f32, radius: f32, pixels: u32) -> [f32; 2] { + let scale = pixels as f32 / self.span[axis]; + // Sample zero is the first pixel center. Rounding before its half-pixel offset + // changes the snapped edge and the interpolation slope in scaled windows. + [center - radius, center + 3.0 * radius].map(|v| (v - self.start[axis]).mul_add(scale, -0.5)) } pub fn bounds(&self, center: [f32; 2], radius: [f32; 2], size: [u32; 2]) -> [[u32; 2]; 2] { @@ -31,24 +82,97 @@ impl Region { } pub fn period(&self) -> [f32; 2] { - self.span.map(f32::abs) + self.span } - pub fn repeats(&self, center: [f32; 2], radius: [f32; 2], period: [f32; 2]) -> Result<[[i32; 2]; 2], String> { - let mut result = [[0; 2]; 2]; + pub fn copy_origin(&self, center: [f32; 2], axes: [bool; 2]) -> [f32; 2] { + std::array::from_fn(|i| { + let start = f64::from(self.start[i]); + let offset = f64::from(center[i]) - start; + let period = f64::from(self.span[i]); + // Adjacent copy indices cease to be distinct F32 translations at 2^24. + if axes[i] && offset.abs() >= 16_777_216.0 * period { (start + offset.rem_euclid(period)) as f32 } else { center[i] } + }) + } + + pub fn repeats(&self, render: &Self, center: [f32; 2], radius: [f32; 2], axes: [bool; 2]) -> Result<[Copies; 2], String> { + let mut result = center.map(|value| Copies { count: 1, outermost: value, period: 0.0 }); for axis in 0..2 { - let end = self.start[axis] + self.span[axis]; - let first = ((self.start[axis].min(end) - center[axis] - radius[axis]) / period[axis]).ceil(); - let last = ((self.start[axis].max(end) - center[axis] + radius[axis]) / period[axis]).floor(); + if !axes[axis] { + continue; + } + let period = f64::from(self.span[axis]); + let start = f64::from(self.start[axis]); + let visible = f64::from(render.start[axis]); + let center = f64::from(center[axis]); + let radius = f64::from(radius[axis]); + // A copy must overlap both windows. Touching an edge alone does not draw it. + let first = ((start.max(visible) - center - radius) / period).floor() + 1.0; + let last_at = |end| ((f64::from(end) - center + radius) / period).ceil() - 1.0; + let last = last_at(self.end[axis].min(render.end[axis])); // A tiny period or huge pattern cannot create unbounded work, even outside the image - if !first.is_finite() || !last.is_finite() || first < i32::MIN as f32 || last >= i32::MAX as f32 { + let coordinates = f64::from(i32::MIN)..=f64::from(i32::MAX); + if !coordinates.contains(&first) || !coordinates.contains(&last) { return Err("pattern repetition exceeds its coordinate budget".into()); } - result[axis] = [first as i32, last as i32]; + let count = (last - first + 1.0).max(0.0) as u64; + // The first translation belongs to the full tiling window, even if that copy is offscreen. + let outer = if count > 0 && self.end[axis] > render.end[axis] { last_at(self.end[axis]) } else { last }; + let period = self.span[axis]; + let position = center as f32 + outer as f32 * period; + let outermost = subtract_periods(position, period, (outer - last) as u64); + result[axis] = Copies { count, outermost, period }; } Ok(result) } } + +/// Advance a run of offscreen copies with the same rounding as individual F32 subtractions. +fn subtract_periods(mut position: f32, period: f32, mut steps: u64) -> f32 { + const FRACTION: u32 = (1 << 23) - 1; + while steps > 0 { + let next = position - period; + if steps == 1 || next == position || !next.is_finite() { + return next; + } + let [a, b, c] = [position, next, next - period].map(f32::to_bits); + let stride = a.abs_diff(b); + // Within one signed exponent the floats are equally spaced. Two equal strides also + // resolve a possible ties-to-even step from an odd significand. Stop at the boundary. + if a >> 23 == b >> 23 && b >> 23 == c >> 23 && stride != 0 && stride == b.abs_diff(c) { + let fraction = a & FRACTION; + // At a positive power of two the next lower float is closer. Cross that boundary one step at a time. + let room = if position.is_sign_negative() { FRACTION - fraction } else { fraction.saturating_sub(1) }; + let jump = steps.min(u64::from(room / stride)); + if jump > 1 { + let delta = jump as u32 * stride; + position = f32::from_bits(if position.is_sign_negative() { a + delta } else { a - delta }); + steps -= jump; + continue; + } + } + position = next; + steps -= 1; + } + position +} + +#[cfg(test)] +mod tests { + use super::subtract_periods; + + #[test] + fn skipping_copies_keeps_rounding_across_exponents_and_ties() { + for (start, period, count) in [(16.5, 0.612, 1157), (0.5, 0.125, 451), (-123456.0, 1.5, 8193), (16_777_212.0, 1.5, 530)] { + let expected = (0..count).fold(start, |position, _| position - period); + assert_eq!(subtract_periods(start, period, count).to_bits(), expected.to_bits()); + } + // The float immediately below a positive power of two is only half an ulp away. + let start = 1.0 + 20.0 * f32::EPSILON; + assert_eq!(subtract_periods(start, 1.3125 * f32::EPSILON, 20), 1.0_f32.next_down()); + assert_eq!(subtract_periods(0.0, f32::EPSILON, 1 << 31), -2.0); + } +} diff --git a/crates/nodes/src/pattern/repeated_quadrants.rs b/crates/nodes/src/pattern/repeated_quadrants.rs new file mode 100644 index 00000000..fea545cb --- /dev/null +++ b/crates/nodes/src/pattern/repeated_quadrants.rs @@ -0,0 +1,73 @@ +use super::{ + footprint::Footprint, + pattern_stamp::{DrawRun, PatternStamp}, + region::Region, + tile_runs::COPIES_PER_BATCH, +}; +use crate::CookContext; + +pub(super) fn runs<'a>(context: &CookContext, stamps: &'a [PatternStamp], repeats: usize, depth: u32) -> Option>> { + if !(6..=10).contains(&depth) || repeats == 0 { + return None; + } + let first_level = repeats.checked_mul(4)?; + if first_level > COPIES_PER_BATCH as usize || first_level > stamps.len() { + return None; + } + let first = stamps.iter().find(|stamp| stamp.depth == 1)?; + if !(2..=16).contains(&first.pattern) { + return None; + } + + let axes = context.tiling_axes(); + let render = Region::new(context.v4("render_region")).ok()?; + let tiling = Region::tiling(context.v4("tiling_region"), axes, context.b("cull_outside")).ok()?; + let mut submitted = 0_u64; + let mut indices = Vec::with_capacity(first_level); + for (index, stamp) in stamps.iter().enumerate() { + if stamp.depth == 0 { + return None; + } + if stamp.depth == 1 { + if stamp.pattern != first.pattern || stamp.blend != 0 || indices.len() == first_level { + return None; + } + let frame = Footprint::new(stamp).ok()?; + let center = tiling.copy_origin(stamp.center, axes); + let [x, y] = tiling.repeats(&render, center, frame.radius, axes).ok()?; + submitted = submitted.checked_add(x.count.checked_mul(y.count)?)?; + if submitted > u64::from(COPIES_PER_BATCH) { + return None; + } + indices.push(index); + } else if stamp.pattern == first.pattern { + // A shared shape also needs the submission order of its deeper draws. + return None; + } + } + // Without a nested Iterate, four retained first-level stamps per repetition + // account for every child, including the two slots belonging to the lower row. + if indices.len() != first_level { + return None; + } + + // Other shapes keep their relative order. The raster sorts each shape separately. + let mut runs = Vec::new(); + let mut start = 0; + for &index in &indices { + if start < index { + runs.push(DrawRun::whole(stamps.get(start..index)?)); + } + start = index + 1; + } + if let Some(rest) = stamps.get(start..).filter(|rest| !rest.is_empty()) { + runs.push(DrawRun::whole(rest)); + } + for slot in (0..4).rev() { + for iteration in indices.as_chunks::<4>().0 { + let index = *iteration.get(slot)?; + runs.push(DrawRun::whole(stamps.get(index..=index)?)); + } + } + Some(runs) +} diff --git a/crates/nodes/src/pattern/repeated_six_level.rs b/crates/nodes/src/pattern/repeated_six_level.rs new file mode 100644 index 00000000..28999247 --- /dev/null +++ b/crates/nodes/src/pattern/repeated_six_level.rs @@ -0,0 +1,78 @@ +use super::{ + footprint::SampleGrid, + pattern_stamp::{CopyPositions, DrawRun, PatternStamp}, + raster::MIN_STAMP_SIZE, + tile_runs::COPIES_PER_BATCH, +}; + +// Each first-level quadrant contains 256 depth-five parents with four terminal children each. +const DRAWS_PER_QUADRANT: usize = 256 * 5; + +#[derive(Default)] +pub(super) struct RepeatedSixLevelRuns { + shape: Option, + draws: usize, + positions: CopyPositions, + quadrant_ends: Vec, +} + +impl RepeatedSixLevelRuns { + pub fn record(&mut self, stamp: &PatternStamp, weights: &[f32], grid: Option<&SampleGrid>, retained: bool) -> Option<()> { + let depth = if self.draws.is_multiple_of(5) { 5 } else { 6 }; + let weight = *weights.get(depth)?; + if stamp.depth != depth as u32 + || stamp.blend != 0 + || !matches!(stamp.pattern, 2 | 8) + || *self.shape.get_or_insert(stamp.pattern) != stamp.pattern + || !stamp.color[3].is_normal() + || !weight.is_normal() + || !(stamp.color[3] * weight).is_normal() + || !stamp.center.iter().chain(&stamp.size).chain([&stamp.rotation, &stamp.variation]).all(|v| v.is_finite()) + || stamp.size.iter().any(|axis| axis.abs() < MIN_STAMP_SIZE) + { + return None; + } + let copies = grid?.copy_count(stamp)?; + let end = self.positions.record(copies, retained)?.end; + self.draws += 1; + if self.draws.is_multiple_of(DRAWS_PER_QUADRANT) { + self.quadrant_ends.push(end); + } + Some(()) + } + + pub fn finish<'a>(self, stamps: &'a [PatternStamp], trees: usize) -> Option>> { + // Without nested iterations this count is possible only when every parent and all four leaves draw. + if trees < 2 || trees.checked_mul(4 * DRAWS_PER_QUADRANT)? != self.draws { + return None; + } + let mut ordered = Vec::new(); + let mut pending: [Vec>; 4] = std::array::from_fn(|_| Vec::new()); + let mut space = [COPIES_PER_BATCH; 4]; + let mut tree_start = 0; + let run = |start, end| DrawRun::between(stamps, self.positions.at(start), self.positions.at(end)); + for &[a, b, c, d] in self.quadrant_ends.as_chunks::<4>().0 { + let quadrants = [tree_start..a, a..b, b..c, c..d]; + tree_start = d; + // Each quadrant can add at most 1,280 draws with four copies apiece, filling at most one batch. + for slot in [3, 0, 1, 2] { + let mut start = quadrants[slot].start; + let end = quadrants[slot].end; + if end - start >= space[slot] { + let cut = start + space[slot]; + pending[slot].push(run(start, cut)?); + ordered.append(&mut pending[slot]); + start = cut; + space[slot] = COPIES_PER_BATCH; + } + if start < end { + pending[slot].push(run(start, end)?); + space[slot] -= end - start; + } + } + } + // Partly filled batches are drawn in reverse quadrant order, retaining tree order inside each one. + ordered.extend(pending.into_iter().rev().flatten()); + Some(ordered) + } +} diff --git a/crates/nodes/src/pattern/shape.rs b/crates/nodes/src/pattern/shape.rs index 7776360f..27bc7bbd 100644 --- a/crates/nodes/src/pattern/shape.rs +++ b/crates/nodes/src/pattern/shape.rs @@ -1,47 +1,94 @@ -pub(super) fn coverage(pattern: i32, x: f32, y: f32, variation: f32) -> Result { - let radius_squared = x * x + y * y; +pub(super) fn circular(pattern: i32) -> bool { + matches!(pattern, 3..=7 | 11..=14 | 16 | 18) +} + +pub(super) fn radius_squared([x, y]: [f32; 2]) -> f32 { + y.mul_add(y, x * x) +} + +/// Prepare the per-stamp constants once, then sample coverage and the signed channel offset. +pub(super) fn prepare(pattern: i32, variation: f32) -> impl Fn(f32, f32) -> Result, String> { + let width = match pattern { + 9 if variation > 0.0 => variation.max(f32::MIN_POSITIVE), + 12 | 14 => 1.0 - variation.max(0.0), + _ => 0.0, + }; + let inverse_width = if width == 0.0 { 0.0 } else { crate::function::pixel_divide(1.0, width) }; + let circular = circular(pattern); + move |x: f32, y: f32| { + let radius_squared = radius_squared([x, y]); + // An uncovered pixel preserves the background even when the blend selects the maximum. + if circular && radius_squared > 1.0 { + return Ok(None); + } + profile(pattern, x, y, radius_squared, variation, inverse_width).map(Some) + } +} + +fn profile(pattern: i32, x: f32, y: f32, radius_squared: f32, variation: f32, inverse_width: f32) -> Result<(f32, f32), String> { let radial = (1.0 - radius_squared).max(0.0); - let value = match pattern - 1 { - 1 => 1.0, - 2 => { - if radius_squared <= 1.0 { - 1.0 - } else { - 0.0 - } + let value = match pattern { + 2 | 3 => 1.0, + 4 => radial, + 5 => quartic_bell(radius_squared), + 6 => { + const FALLOFF: f32 = 11.1 * std::f32::consts::LOG2_E; + (crate::function::pixel_exp2(-FALLOFF * radius_squared) - 0.000_015_1).max(0.0) } - 3 => radial, - 4 => radial * radial, - 5 => (-4.0 * radius_squared).exp(), - 6 => (1.0 - radius_squared.sqrt()).max(0.0).powi(4), - 7 => (1.0 - x.abs().max(y.abs())).max(0.0), - 8 => { - let bevel = variation.clamp(0.0, 1.0); - if bevel <= f32::EPSILON { 1.0 } else { ((1.0 - x.abs().max(y.abs())) / bevel).clamp(0.0, 1.0) } + 7 => (1.0 - crate::function::pixel_sqrt(radius_squared)).max(0.0).powi(4), + 8 => (1.0 - x.abs().max(y.abs())).max(0.0), + 9 if variation <= 0.0 => 1.0, + 9 => { + // Each edge fades independently, including at a corner. + let fade = |coordinate: f32| { + let t = ((1.0 - coordinate.abs()) * inverse_width).clamp(0.0, 1.0); + let square = t * t; + (-2.0_f32).mul_add(square * t, 3.0 * square) + }; + fade(x) * fade(y) } - 9 => (x + 1.0) * 0.5, - 10 => (x * std::f32::consts::PI).cos() * 0.5 + 0.5, - 11 => radial * radial * if x >= 0.0 { 1.0 } else { 0.0 }, - 12 => (1.0 - x.abs()).max(0.0).powi(2), - 13 => { - if radius_squared <= 1.0 && (x - variation.max(0.05)).powi(2) + y * y > 1.0 { - 1.0 - } else { - 0.0 - } + 10 => (x + 1.0) * 0.5 * (1.0 - variation.max(0.0)), + 11 => { + // A finite frequency keeps the phase at x = 0 defined even for very large variations. + let cycles = 6.0_f32.mul_add(variation.max(0.0), 1.5).min(f32::MAX); + let phase = f64::from(x) * f64::from(cycles); + let fraction = (phase - phase.round()).abs() as f32; + let triangle = 1.0 - 4.0 * fraction; + let parabola = (-triangle.abs()).mul_add(triangle, 2.0 * triangle); + // The measured wave uses a quadratic correction before the radial fade. + const CORRECTION: f32 = 0.223_936_68; + let wave = parabola * CORRECTION.mul_add(parabola.abs(), 1.0 - CORRECTION); + radial * (0.5 * wave + 0.5) } + 12 => quartic_bell(radius_squared) * descending_fade(x, inverse_width), + 13 => quartic_bell(radius_squared) * (1.0 - x.abs()).powi(2), 14 => { - if (x.abs() - 0.5).max(0.0).powi(2) + y * y <= 0.25 { - 1.0 - } else { - 0.0 - } + let t = radius_squared.min(1.0); + // Normalize t(1-t)² to one at t=1/3. + let ring = 6.75_f32.mul_add(t, -13.5).mul_add(t, 6.75) * t; + ring * descending_fade((x + 1.0) * 0.5, inverse_width) } - 15 => (1.0 - radius_squared.sqrt()).max(0.0), - 16 => radial.sqrt(), - 17 => ((x + 1.0) * 0.5 + variation).fract(), + 15 => { + let tip = (x.abs() - 0.77 * variation.max(0.0)).max(0.0); + let distance_squared = y.mul_add(y, tip * tip); + (-20.0_f32).mul_add(distance_squared, 1.0).max(0.0) + } + 16 => (1.0 - crate::function::pixel_sqrt(radius_squared)).max(0.0), + 17 => return Ok(((x + 1.0) * 0.5, variation)), + 18 => return Ok((crate::function::pixel_sqrt(radial), variation)), _ => return Err(format!("unknown built-in pattern {pattern}")), }; - Ok(value) + Ok((value, 0.0)) +} + +fn quartic_bell(radius_squared: f32) -> f32 { + // The expanded quartic retains the signed rounding of the low-coverage skirt. + let t = radius_squared.min(1.0); + (t - 4.0).mul_add(t, 6.0).mul_add(t, -4.0).mul_add(t, 1.0) +} + +fn descending_fade(position: f32, inverse_width: f32) -> f32 { + let t = if inverse_width == 0.0 { f32::from(position > 0.0) } else { (position * inverse_width).clamp(0.0, 1.0) }; + (t * t).mul_add(2.0_f32.mul_add(t, -3.0), 1.0) } diff --git a/crates/nodes/src/pattern/stamp_cache.rs b/crates/nodes/src/pattern/stamp_cache.rs new file mode 100644 index 00000000..8e8684e0 --- /dev/null +++ b/crates/nodes/src/pattern/stamp_cache.rs @@ -0,0 +1,367 @@ +use super::pattern_stamp::PatternStamp; +use crate::function::Program; +use materialcraft_core::{PatternNode, Value}; +use std::collections::{BTreeMap, BTreeSet, HashMap}; + +/// A terminal draw can reuse its properties across positions when its programs +/// only depend on the traversal seed, depth and inputs fixed for this cook. +pub(super) fn reusable(program: &Program, assigned: &BTreeSet<&str>) -> bool { + (0..program.instructions.len()).all(|index| reusable_at(program, index, assigned)) +} + +fn reusable_at(program: &Program, index: usize, assigned: &BTreeSet<&str>) -> bool { + let Some(op) = program.instructions.get(index) else { return false }; + let id = op.definition.id; + if matches!(id, "set" | "while" | "samplecol" | "samplelum") { + return false; + } + if (id.starts_with("get_") || id == "isdefined") + && let Some(Value::Text(name)) = &op.value + && (matches!(name.as_str(), "$pos" | "$number") || assigned.contains(name.as_str())) + { + return false; + } + op.call.as_ref().is_none_or(|call| reusable(&call.program, assigned)) +} + +pub(super) fn reusable_inputs(program: &Program, outputs: &[usize], assigned: &BTreeSet<&str>) -> bool { + let mut pending = outputs.to_vec(); + let mut seen = vec![false; program.instructions.len()]; + while let Some(index) = pending.pop() { + let Some(visited) = seen.get_mut(index) else { return false }; + if *visited { + continue; + } + *visited = true; + if !reusable_at(program, index, assigned) { + return false; + } + pending.extend(program.instructions[index].inputs.iter().copied()); + } + true +} + +pub(super) fn independent_of_depth(program: &Program) -> bool { + program.instructions.iter().all(|op| { + !matches!(&op.value, Some(Value::Text(name)) if matches!(name.as_str(), "$depth" | "$depthpow2")) + && op.call.as_ref().is_none_or(|call| independent_of_depth(&call.program)) + }) +} + +/// Identical authoring data can supply a branch offset and tint at several drawing depths. +#[derive(Default)] +pub(super) struct BranchGroups(HashMap, (u32, BTreeMap)>); + +impl BranchGroups { + pub fn storage(&mut self, node: &PatternNode) -> Option { + let size = match node.parameters.get("patternsize") { + Some(Value::Float2(size)) => *size, + None => [1.0; 2], + _ => return None, + }; + let mut parameters = node.parameters.clone(); + // An ordinary save assigns fresh IDs to each expression. Only its result and wiring use them. + for value in parameters.values_mut() { + let Value::Function(graph) = value else { continue }; + let ids: BTreeMap<_, _> = graph.nodes.iter().map(|n| n.id).zip(0_u32..).collect(); + let output = graph.output.as_mut()?; + *output = *ids.get(output)?; + for (id, n) in (0_u32..).zip(&mut graph.nodes) { + n.id = id; + for input in n.inputs.iter_mut().flatten() { + *input = *ids.get(input)?; + } + } + } + let key = serde_json::to_vec(¶meters).ok()?; + // Serialization distinguishes signed zeros. Compare resolved calls and nonfinite values as well. + let group = match self.0.entry(key) { + std::collections::hash_map::Entry::Occupied(entry) if entry.get().1 == parameters => entry.get().0, + entry => { + entry.or_insert((node.id, parameters)); + node.id + } + }; + Some(Storage::BranchTint { group, size }) + } +} + +#[derive(Clone, Copy, PartialEq, Eq, Hash)] +pub(super) struct Key { + pub node: u32, + pub depth: u32, + pub seed: u32, +} + +#[derive(Clone)] +pub(super) struct Properties { + pub branch_offset: [f32; 2], + /// The center holds the frame offset until the two translations have rounded separately. + pub stamp: PatternStamp, +} + +#[derive(Clone, Copy)] +pub(super) enum Storage { + Full, + FixedImage, + Placement, + Geometry { terminal: bool }, + BranchTint { group: u32, size: [f32; 2] }, +} + +// Each node and depth has immutable properties. A sparse seed page points +// to its changing fields, which occupy contiguous blocks across all depths. +#[derive(Default)] +struct PackedStamps { + templates: HashMap<(u32, u32), Properties>, + pages: HashMap<(u32, u32, u16), Box<[u32]>>, + values: Vec>, + bytes: usize, +} + +impl PackedStamps { + const PAGE_SIZE: usize = 256; + const BLOCK_SIZE: usize = 4_096; + + fn address(key: Key) -> ((u32, u32, u16), usize) { + ((key.node, key.depth, key.seed as u16), (key.seed >> 16) as usize) + } + + fn get(&self, key: Key) -> Option<(Properties, [f32; FIELDS])> { + let (page, index) = Self::address(key); + let at = self.pages.get(&page)?.get(index)?.checked_sub(1)? as usize; + let fields = *self.values.get(at / Self::BLOCK_SIZE)?.get(at % Self::BLOCK_SIZE)?; + Some((self.templates.get(&(key.node, key.depth))?.clone(), fields)) + } + + fn insert(&mut self, key: Key, properties: &Properties, fields: [f32; FIELDS], limit: usize) -> bool { + // Child streams have 24-bit seeds. Wider explicit seeds use the small cache. + if key.seed >> 24 != 0 { + return false; + } + let (page, index) = Self::address(key); + let new_block = self.values.last().is_none_or(|block| block.len() == Self::BLOCK_SIZE); + let growth = usize::from(new_block) * Self::BLOCK_SIZE * size_of::<[f32; FIELDS]>() + + usize::from(!self.pages.contains_key(&page)) * Self::PAGE_SIZE * size_of::(); + // Bound both indices and floating-point storage independently of the traversal length. + if self.bytes.saturating_add(growth) > limit { + return false; + } + let entries = self.pages.entry(page).or_insert_with(|| vec![0; Self::PAGE_SIZE].into_boxed_slice()); + let Some(entry) = entries.get_mut(index) else { return false }; + if *entry != 0 { + return true; + } + self.bytes += growth; + if new_block { + self.values.push(Vec::with_capacity(Self::BLOCK_SIZE)); + } + let base = self.values.len().saturating_sub(1) * Self::BLOCK_SIZE; + let Some(block) = self.values.last_mut() else { return false }; + let Ok(at) = u32::try_from(base + block.len() + 1) else { return false }; + block.push(fields); + *entry = at; + self.templates.entry((key.node, key.depth)).or_insert_with(|| properties.clone()); + true + } +} + +#[derive(Default)] +pub(super) struct StampCache { + slots: Vec>, + lookups: usize, + images: PackedStamps<5>, + placements: PackedStamps<4>, + geometry: PackedStamps<8>, +} + +impl StampCache { + // Bound memory independently of the number of nodes, seeds and iterations in a package. + const MAX_SLOTS: usize = 65_536; + + fn index(&self, key: Key) -> usize { + let hash = (key.seed ^ key.node.rotate_left(7) ^ key.depth.rotate_left(19)).wrapping_mul(2_654_435_769); + (hash >> 16) as usize & self.slots.len().saturating_sub(1) + } + + pub fn get(&mut self, key: Key, storage: Storage) -> Option { + self.lookups = self.lookups.saturating_add(1); + if self.slots.len() < Self::MAX_SLOTS && self.lookups > self.slots.len() * 2 { + // A shallow or sparsely connected graph only needs a small table. + self.slots.resize_with((self.slots.len() * 2).max(16), || None); + } + if let Some(Some((stored, value))) = self.slots.get(self.index(key)) + && *stored == key + { + return Some(value.clone()); + } + match storage { + Storage::Full | Storage::Geometry { terminal: false } => None, + Storage::Geometry { terminal: true } => { + let (mut properties, [bx, by, x, y, width, height, rotation, alpha]) = self.geometry.get(key)?; + properties.branch_offset = [bx, by]; + properties.stamp.center = [x, y]; + properties.stamp.size = [width, height]; + properties.stamp.rotation = rotation; + properties.stamp.color[3] = alpha; + Some(properties) + } + Storage::FixedImage => { + let (mut properties, [x, y, width, height, alpha]) = self.images.get(key)?; + properties.branch_offset = [x, y]; + properties.stamp.size = [width, height]; + properties.stamp.color[3] = alpha; + Some(properties) + } + Storage::Placement | Storage::BranchTint { .. } => { + let (mut properties, [x, y, rotation, alpha]) = self.placements.get(key)?; + if matches!(storage, Storage::BranchTint { .. }) { + properties.branch_offset = [x, y]; + } else { + properties.stamp.center = [x, y]; + } + properties.stamp.rotation = rotation; + properties.stamp.color[3] = alpha; + Some(properties) + } + } + } + + pub fn insert(&mut self, key: Key, properties: Properties, storage: Storage, streaming: bool) { + if streaming || matches!(storage, Storage::BranchTint { .. } | Storage::Geometry { terminal: true }) { + let stamp = &properties.stamp; + // Both representations of analytic stamps share one byte limit. Keep sparse + // parents in the small table so their seed pages cannot displace dense leaves. + const ANALYTIC_BYTES: usize = 96 << 20; + let stored = match storage { + Storage::Geometry { terminal: true } if self.lookups > Self::MAX_SLOTS * 2 => { + let [bx, by] = properties.branch_offset; + let [x, y] = stamp.center; + let [width, height] = stamp.size; + let fields = [bx, by, x, y, width, height, stamp.rotation, stamp.color[3]]; + self.geometry.insert(key, &properties, fields, ANALYTIC_BYTES.saturating_sub(self.placements.bytes)) + } + Storage::FixedImage if self.lookups > Self::MAX_SLOTS * 2 => { + let [x, y] = properties.branch_offset; + let [width, height] = stamp.size; + self.images.insert(key, &properties, [x, y, width, height, stamp.color[3]], 64 << 20) + } + Storage::Placement | Storage::BranchTint { .. } => { + let [x, y] = if matches!(storage, Storage::BranchTint { .. }) { properties.branch_offset } else { stamp.center }; + self.placements.insert(key, &properties, [x, y, stamp.rotation, stamp.color[3]], ANALYTIC_BYTES.saturating_sub(self.geometry.bytes)) + } + _ => false, + }; + if stored { + return; + } + } + let index = self.index(key); + if let Some(slot) = self.slots.get_mut(index) { + *slot = Some((key, properties)); + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn branch_programs_share_renumbered_connections_and_distinguish_rewired_operands() { + use materialcraft_core::{FunctionGraph, PatternGraph, PatternNodeKind}; + + let cases = [(1, [5, 9, 4], false, 1), (2, [32, 31, 33], false, 1), (3, [32, 31, 33], true, 3)].map(|(id, ids, reverse, expected)| { + let mut offset = FunctionGraph::default(); + let a = offset.add_constant(Value::Float2([0.125, 0.25])); + let b = offset.add_constant(Value::Float2([0.5, 0.75])); + offset.add("sub", &[a, b], None); + for (node, id) in offset.nodes.iter_mut().zip(ids) { + node.id = id; + } + let [a, b, result] = ids; + offset.nodes[2].inputs = if reverse { vec![Some(b), Some(a)] } else { vec![Some(a), Some(b)] }; + offset.output = Some(result); + let mut node = PatternGraph::with_root(PatternNodeKind::Quadrant).nodes.remove(0); + node.id = id; + node.parameters.insert("branchoffset".into(), Value::Function(Box::new(offset))); + (node, expected) + }); + let mut groups = BranchGroups::default(); + for (node, expected) in &cases { + assert!(matches!(groups.storage(node), Some(Storage::BranchTint { group, .. }) if group == *expected)); + } + } + + #[test] + fn streamed_geometry_keeps_each_translation_and_seed_dependent_field() { + let mut cache = StampCache { lookups: StampCache::MAX_SLOTS * 2 + 1, ..Default::default() }; + let first = Key { node: 17, depth: 9, seed: 0x5611 }; + let second = Key { seed: first.seed | (7 << 16), ..first }; + let make = |v: f32| Properties { + branch_offset: [v, -v], + stamp: PatternStamp { + center: [-2.0 * v, 2.0 * v], + size: [v + 0.5, v + 0.75], + rotation: -0.25 * v, + literal_geometry: false, + color: [1.0, 1.0, 1.0, v + 0.125], + depth: 9, + pattern: 3, + variation: 0.25, + blend: 0, + filtering: 0, + premultiplied: false, + }, + }; + let storage = Storage::Geometry { terminal: true }; + for (key, v) in [(first, 0.125), (second, 0.375)] { + cache.insert(key, make(v), storage, true); + } + for (key, v) in [(second, 0.375), (first, 0.125)] { + let a = cache.get(key, storage).unwrap(); + let b = make(v); + assert_eq!(a.branch_offset, b.branch_offset); + assert_eq!((a.stamp.center, a.stamp.size, a.stamp.rotation, a.stamp.color), (b.stamp.center, b.stamp.size, b.stamp.rotation, b.stamp.color)); + assert_eq!((a.stamp.depth, a.stamp.pattern, a.stamp.variation), (9, 3, 0.25)); + } + assert!(cache.get(Key { depth: 8, ..first }, storage).is_none()); + assert!(cache.get(Key { seed: first.seed | (1 << 24), ..first }, storage).is_none()); + } + + #[test] + fn streamed_image_cache_distinguishes_seed_bits_and_drawing_depth() { + let mut cache = StampCache { lookups: StampCache::MAX_SLOTS * 2 + 1, ..Default::default() }; + let first = Key { node: 17, depth: 9, seed: 0x5611 }; + let second = Key { seed: 0x815611, ..first }; + let mut properties = Properties { + branch_offset: [0.125, -0.25], + stamp: PatternStamp { + center: [0.25, 0.125], + size: [0.75, 0.25], + rotation: -0.125, + literal_geometry: false, + color: [1.0, 1.0, 1.0, 0.375], + depth: 9, + pattern: 257, + variation: 0.0, + blend: 0, + filtering: 1, + premultiplied: false, + }, + }; + cache.insert(first, properties.clone(), Storage::FixedImage, true); + properties.branch_offset = [-0.375, 0.25]; + properties.stamp.size = [0.125, 0.875]; + properties.stamp.color[3] = 0.625; + cache.insert(second, properties, Storage::FixedImage, true); + let a = cache.get(first, Storage::FixedImage).unwrap(); + let b = cache.get(second, Storage::FixedImage).unwrap(); + assert_eq!((a.branch_offset, a.stamp.size, a.stamp.color[3]), ([0.125, -0.25], [0.75, 0.25], 0.375)); + assert_eq!((b.branch_offset, b.stamp.size, b.stamp.color[3]), ([-0.375, 0.25], [0.125, 0.875], 0.625)); + assert_eq!((b.stamp.center, b.stamp.rotation, b.stamp.pattern), ([0.25, 0.125], -0.125, 257)); + assert!(cache.get(Key { depth: 8, ..second }, Storage::FixedImage).is_none()); + assert!(cache.get(Key { node: 18, ..second }, Storage::FixedImage).is_none()); + assert!(cache.get(Key { seed: second.seed | (1 << 24), ..second }, Storage::FixedImage).is_none()); + } +} diff --git a/crates/nodes/src/pattern/terminal_quadrants.rs b/crates/nodes/src/pattern/terminal_quadrants.rs new file mode 100644 index 00000000..d0080112 --- /dev/null +++ b/crates/nodes/src/pattern/terminal_quadrants.rs @@ -0,0 +1,297 @@ +use super::{ + footprint::SampleGrid, + pattern_stamp::{CopyPositions, DrawRun, PatternStamp}, + raster::MIN_STAMP_SIZE, + tile_runs::COPIES_PER_BATCH, +}; +use materialcraft_core::{PatternNode, PatternNodeKind}; + +// With draws on the last three levels, 21 consecutive stamps belong to each +// depth-six parent. Paired squares identify the order of these parent ranges +// for complete trees. Successive trees share the first submissions. +type ParentRange = (usize, usize); +const FIRST: &[ParentRange] = &[ + (1536, 1796), + (2560, 2820), + (512, 772), + (3200, 3328), + (1024, 1156), + (3712, 3840), + (0, 132), + (3456, 3584), + (2048, 2180), + (772, 1024), + (1408, 1416), + (1796, 2048), + (3328, 3336), + (1156, 1280), + (1472, 1536), + (256, 328), + (3968, 4096), + (3072, 3200), + (1344, 1348), + (132, 256), + (384, 512), + (2304, 2312), + (2820, 3072), + (3584, 3592), +]; +const SINGLE_TAIL: &[ParentRange] = + &[(328, 384), (2180, 2304), (2496, 2560), (2312, 2432), (3840, 3968), (1280, 1344), (2432, 2496), (1348, 1408), (3592, 3712), (3336, 3456), (1416, 1472)]; +const REPEATED: &[ParentRange] = &[ + (3336, 3456), + (5632, 6032), + (2180, 2304), + (2496, 2560), + (7552, 7624), + (3592, 3712), + (6656, 7056), + (1416, 1472), + (4608, 5072), + (3840, 3968), + (1280, 1344), + (2432, 2496), + (7936, 7940), + (1348, 1408), + (8064, 8192), + (7168, 7240), + (328, 384), + (7296, 7424), + (5120, 5196), + (2312, 2432), + (7808, 7936), + (4096, 4160), + (4288, 4496), + (7624, 7680), + (6144, 6348), + (5196, 5248), + (5312, 5376), + (5568, 5632), +]; +const DOUBLE_TAIL: &[ParentRange] = &[ + (4160, 4288), + (6348, 6400), + (6592, 6656), + (4496, 4608), + (6400, 6528), + (7940, 8064), + (5248, 5312), + (6528, 6592), + (7240, 7296), + (5376, 5504), + (7056, 7168), + (7680, 7808), + (6032, 6144), + (7424, 7552), + (5072, 5120), + (5504, 5568), +]; +const FOUR_TAIL: &[ParentRange] = &[ + (4160, 4240), + (7240, 7296), + (5376, 5504), + (12160, 12236), + (6032, 6144), + (7424, 7552), + (9728, 10008), + (7056, 7168), + (7680, 7808), + (10752, 11032), + (4496, 4608), + (6400, 6528), + (11904, 11924), + (5072, 5120), + (5504, 5568), + (8704, 9112), + (7940, 8064), + (5248, 5312), + (6528, 6592), + (12032, 12040), + (4240, 4288), + (11392, 11520), + (9216, 9300), + (11924, 12032), + (8192, 8344), + (6348, 6400), + (6592, 6656), + (11648, 11776), + (10240, 10304), + (10432, 10644), + (10008, 10240), + (11520, 11548), + (9300, 9344), + (9408, 9472), + (9664, 9728), + (8448, 8536), + (12236, 12288), + (11264, 11392), + (9472, 9552), + (8344, 8448), + (8576, 8704), + (10304, 10332), + (11032, 11264), + (11776, 11804), + (11548, 11648), + (13824, 14244), + (11804, 11904), + (14848, 15268), + (9112, 9216), + (9600, 9664), + (12800, 13152), + (12040, 12160), + (9344, 9408), + (10368, 10432), + (16128, 16140), + (9552, 9600), + (16256, 16384), + (15360, 15444), + (8536, 8576), + (15488, 15616), + (13312, 13404), + (10332, 10368), + (16000, 16128), + (12288, 12416), + (12480, 12708), + (10644, 10752), + (15744, 15872), + (14336, 14400), + (14528, 14748), + (13404, 13440), + (13504, 13568), + (13760, 13824), + (12416, 12480), + (14748, 14848), + (12708, 12800), + (14400, 14464), + (16140, 16256), + (13440, 13504), + (14464, 14528), + (15444, 15488), + (13568, 13696), + (15268, 15360), + (15872, 16000), + (14244, 14336), + (15616, 15744), + (13152, 13312), + (13696, 13760), +]; + +#[derive(Default)] +pub(super) struct TerminalQuadrants { + // The retained stamp index and physical copy offset at each depth-six parent. + starts: Vec<(usize, u32)>, + positions: CopyPositions, + quarter_start: u32, + trees: usize, + saw_iteration: bool, + wrapped: bool, + draws: usize, + shape: Option, +} + +impl TerminalQuadrants { + pub(super) fn visit(&mut self, node: &PatternNode, depth: u32, retained: usize) -> bool { + match node.kind { + PatternNodeKind::Iterate => { + // A route can precede the outer iteration. A second iteration can interleave different trees. + let outer = depth == 0 && !self.saw_iteration && self.trees == 0; + self.saw_iteration = true; + outer && node.children.first() == Some(&None) + } + // Routed quadrants are counted when visited, including children selected by an interior switch. + PatternNodeKind::Dot | PatternNodeKind::Switch => true, + PatternNodeKind::Quadrant if depth == 8 => node.children.iter().all(Option::is_none), + PatternNodeKind::Quadrant if depth < 8 && node.children.iter().flatten().count() == 4 => { + if depth == 0 { + // An iteration switch can suppress a whole tree before its first quadrant. + self.trees += 1; + } + if depth == 6 { + if self.starts.len() == 4 * 4096 { + return false; + } + // Invisible draws still occupy a place in their parent's run. + self.starts.push((retained, self.positions.total)); + } + true + } + _ => false, + } + } + + pub(super) fn draw(&mut self, stamp: &PatternStamp, weights: &[f32], grid: Option<&SampleGrid>, retained: bool) -> bool { + let Some(weight) = weights.get(stamp.depth as usize) else { return false }; + if !(6..=8).contains(&stamp.depth) + || stamp.blend != 0 + || !(2..=16).contains(&stamp.pattern) + || *self.shape.get_or_insert(stamp.pattern) != stamp.pattern + || !(weight * stamp.color[3]).is_normal() + || stamp.size.iter().any(|axis| axis.abs() < MIN_STAMP_SIZE) + { + return false; + } + let Some(count) = grid.and_then(|grid| grid.copy_count(stamp)) else { return false }; + if self.positions.record(count, retained).is_none() { + return false; + } + self.draws += 1; + self.wrapped |= count > 1; + if self.draws.is_multiple_of(64 * 21) { + // Filling a quarter batch can change which subtree submits the next draw. + let count = self.positions.total - self.quarter_start; + self.quarter_start = self.positions.total; + return count < COPIES_PER_BATCH / 4; + } + true + } + + pub(super) fn finish(mut self, stamps: &[PatternStamp]) -> Option>> { + let (middle, tail) = match self.trees { + 1 => (&[][..], SINGLE_TAIL), + 2 => (REPEATED, DOUBLE_TAIL), + 4 => (REPEATED, FOUR_TAIL), + _ => return None, + }; + if self.starts.len() != self.trees * 4096 || self.draws != self.starts.len() * 21 { + return None; + } + self.starts.push((stamps.len(), self.positions.total)); + let ranges = FIRST.iter().chain(middle).chain(tail); + if !self.wrapped { + return ranges.map(|&(start, end)| Some(DrawRun::whole(stamps.get(self.starts.get(start)?.0..self.starts.get(end)?.0)?))).collect(); + } + + // Complete 64-parent subtrees have fixed boundaries. Interior spans finish + // at a batch boundary and can end between two copies of the same stamp. + let mut cuts = vec![None; self.starts.len()]; + cuts[0] = Some(0); + for &(_, end) in ranges.clone().filter(|(_, end)| end.is_multiple_of(64)) { + *cuts.get_mut(end)? = Some(self.starts.get(end)?.1); + } + let mut submitted = 0_u32; + let mut groups = Vec::with_capacity(FIRST.len() + middle.len() + tail.len()); + for &(start, end) in ranges { + let first = (*cuts.get(start)?)?; + let stop = match *cuts.get(end)? { + Some(cut) => cut, + None => { + let phase = submitted % COPIES_PER_BATCH; + let span = self.starts.get(end)?.1.checked_sub(first)?; + let batches = span.checked_add(phase)?.checked_add(COPIES_PER_BATCH / 2)? / COPIES_PER_BATCH; + let cut = first.checked_add(batches.checked_mul(COPIES_PER_BATCH)?.checked_sub(phase)?)?; + // Outside the neighboring quarter the measured submission order no longer applies. + let low = self.starts.get(end.saturating_sub(64))?.1; + let high = self.starts.get(end.saturating_add(64)).map_or(self.positions.total, |entry| entry.1); + if !(low..=high).contains(&cut) { + return None; + } + *cuts.get_mut(end)? = Some(cut); + cut + } + }; + submitted = submitted.checked_add(stop.checked_sub(first)?)?; + groups.push(DrawRun::between(stamps, self.positions.at(first), self.positions.at(stop))?); + } + (submitted == self.positions.total).then_some(groups) + } +} diff --git a/crates/nodes/src/pattern/tests.rs b/crates/nodes/src/pattern/tests.rs index e2741747..9cdb3335 100644 --- a/crates/nodes/src/pattern/tests.rs +++ b/crates/nodes/src/pattern/tests.rs @@ -2,11 +2,1283 @@ use crate::{CookContext, find, resolve_params}; use materialcraft_core::{FunctionGraph, PatternGraph, PatternNodeKind, Value}; use std::collections::BTreeMap; -fn cook(graph: PatternGraph) -> crate::CookResult { - cook_with_variables(graph, &BTreeMap::new()) +mod paired_batches; +mod repeated_quadrants; +mod sparse_quadrants; +mod terminal_quadrants; +mod underfilled_quadrants; + +fn coverage(shape: i32, x: f32, y: f32, variation: f32) -> f32 { + let sample = super::shape::prepare(shape, variation); + sample(x, y).unwrap().map_or(0.0, |(base, offset)| base + offset) } -fn cook_with_variables(graph: PatternGraph, variables: &BTreeMap) -> crate::CookResult { +#[test] +fn gaussian_stamps_stop_at_the_disc_boundary() { + let x = 0.6; + let inside = 0.79999; + let outside = 0.80001; + assert_eq!(coverage(3, x, inside, 0.0), 1.0); + assert!(coverage(6, x, inside, 0.0) > 0.0); + assert_eq!(coverage(3, x, outside, 0.0), 0.0); + assert_eq!(coverage(6, x, outside, 0.0), 0.0); +} + +#[test] +fn radial_stamps_keep_the_measured_center_and_skirt() { + for (x, y, expected) in [ + (0xbf7c0000, 0x3c7fffbf, [0x3cfc0000, 0x35762800, 0x36cecb1c]), + (0xbeb80001, 0xbef80001, [0x3f22e000, 0x3e27c967, 0x3c90589e]), + (0x3c7fffbf, 0x3c7fffbf, [0x3f7fe000, 0x3f7f8018, 0x3f7e9cc6]), + ] { + for (shape, bits) in (4..=6).zip(expected) { + let value = coverage(shape, f32::from_bits(x), f32::from_bits(y), 0.0); + assert_eq!(value.to_bits(), bits, "shape {shape} at ({x:08x}, {y:08x})"); + } + } +} + +#[test] +fn bell_stamps_keep_signed_samples_until_blending() { + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0))]); + for (mode, expected) in [(0, [0xb2f2_8000, 0xb363_46e0]), (1, [0; 2])] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = + BTreeMap::from([("patterntype".into(), Value::Int(5)), ("blendingmode".into(), Value::Int(mode)), ("patternsize".into(), Value::Float2([1.0; 2]))]); + let image = cook_at_size(graph, &variables, 316163, 64).unwrap().remove(0); + let samples = [(10, 8), (54, 9)].map(|(x, y)| image.get_gray(x, y, false).to_bits()); + assert_eq!(samples, expected, "blend mode {mode}"); + } +} + +#[test] +fn radial_stamp_draws_its_boundary_and_leaves_the_corners_of_its_quad_clear() { + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0))]); + for (shape, variation, corner, edge) in + [(3, 0.25, -0.25, 1.0), (4, 0.25, -0.25, 0.0), (5, 0.25, -0.25, 0.0), (10, 1.0, 0.0, 0.0), (15, 1.0, 0.0, 0.0), (18, 0.25, -0.25, 0.25)] + { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(shape)), + ("patternsuppl".into(), Value::Float(variation)), + ("blendingmode".into(), Value::Int(1)), + ("frameoffset".into(), Value::Float2([1.0 / 128.0; 2])), + ("patternsize".into(), Value::Float2([0.5; 2])), + ]); + let image = cook_in_regions(graph, &variables, 322224, [64; 2], [[0.0, 1.0, 0.0, 1.0]; 2], -0.25).unwrap().remove(0); + assert_eq!([image.get_gray(20, 20, false), image.get_gray(48, 32, false)], [corner, edge], "shape {shape}"); + } +} + +#[test] +fn beveled_square_multiplies_the_two_edge_profiles() { + for (x, y, variation, expected) in [ + (-0.984375, 0.0, 0.0625, 0x3e200000), + (-0.984375, -0.984375, 0.0625, 0x3cc80000), + (-0.984375, -0.984375, 0.125, 0x3af20000), + (-0.984375, -0.984375, -0.25, 0x3f800000), + ] { + assert_eq!(coverage(9, x, y, variation).to_bits(), expected); + } +} + +#[test] +fn beveled_square_uses_the_pixel_reciprocal_for_its_edge_width() { + // Pixel (1, 31) in a centered 64 by 64 stamp lies 3/64 inside the left edge. + for (width, expected) in [(0.072_187_5, 0x3f37_a51f), (0.718_97, 0x3c47_d97b)] { + assert_eq!(coverage(9, -0.953125, -0.015625, width).to_bits(), expected); + } +} + +#[test] +fn horizontal_stamp_fades_use_the_pixel_reciprocal_for_the_remaining_width() { + let coordinate = f32::from_bits(0x3f03_fffe); + let variation = 86.0 / 1021.0; + assert_eq!(coverage(12, coordinate, coordinate, variation).to_bits(), 0x3c9f_e0f0); + assert_eq!(coverage(14, -0.265625, 0.109375, variation).to_bits(), 0x3e9b_3a66); +} + +#[test] +fn gradient_variation_attenuates_the_horizontal_ramp() { + for (variation, expected) in [(-0.25, 0.2578125), (0.0625, 0.241_699_22), (0.5, 0.12890625), (1.0, 0.0), (1.25, -0.064453125)] { + assert_eq!(coverage(10, -0.484375, 0.75, variation), expected); + } +} + +#[test] +fn wave_frequency_and_radial_falloff_follow_stamp_coordinates() { + let x = f32::from_bits(0x3d5fffef); + let y = f32::from_bits(0xbe080003); + for (variation, expected) in [(-0.25, 0x3f6a8659), (0.0, 0x3f6a8659), (0.1875, 0x3f4b2e24), (0.25, 0x3f3dd911), (1.0, 0x3d9ac833)] { + assert_eq!(coverage(11, x, y, variation).to_bits(), expected); + } + assert_eq!(coverage(11, 0.0, 0.5, 0.25), 0.75); +} + +#[test] +fn wave_profile_rounds_the_folded_phase_before_shaping_it() { + for (x, y, variation, expected) in [ + (0xbecc_0001, 0x3bff_ff7f, 0.0, 0x3d9c_60ac), + (0x3e17_fffb, 0x3bff_ff7f, 0.1875, 0x3de6_497a), + (0xbebc_0001, 0x3bff_ff7f, 0.5, 0x3e3b_a2a0), + (0x3ee3_fffd, 0xbc00_003f, 1.0, 0x3e3e_af6e), + ] { + assert_eq!(coverage(11, f32::from_bits(x), f32::from_bits(y), variation).to_bits(), expected); + } +} + +#[test] +fn wave_frequency_rounds_once_before_multiplying_the_coordinate() { + let y = f32::from_bits(0x3bff_ff7f); + for (x, variation, expected) in [(0x3d8f_fff7, 0.45037964, 0x3eb7_1c16), (0x3d1f_ffef, 0.44281647, 0x3f42_b347)] { + assert_eq!(coverage(11, f32::from_bits(x), y, variation).to_bits(), expected); + } + assert_eq!(coverage(11, 0.0, 0.5, f32::MAX), 0.75); +} + +#[test] +fn stamp_profiles_follow_the_radial_and_horizontal_falloffs() { + // Two samples on the low-coverage skirt distinguish the signed quartic from a clamped falloff. + for (shape, x, y, variation, bits) in [ + (7, 0xbf0c0000, 0xbd40000f, 0.0, 0x3d29a3c2), + (12, 0xbeb80001, 0xbef80001, 0.25, 0x3e27c967), + (12, 0x3ec7fffd, 0xbec80001, 0.25, 0x3ddfc34c), + (12, 0x3f3bfffe, 0x3f2bfffe, 0.25, 0xadf38c4f), + (13, 0xbf3c0000, 0x3f2bfffe, 0.25, 0xb1cb84a4), + (13, 0x3ec7fffd, 0xbec80001, 0.25, 0x3db1415d), + (14, 0xbeb80001, 0xbef80001, 0.0, 0x3f40da6b), + (14, 0x3ec7fffd, 0xbec80001, 0.25, 0x3c774318), + (15, 0x3e4ffffb, 0x3c7fffbf, 0.0, 0x3e2e002d), + (15, 0x3e4ffffb, 0x3c7fffbf, 0.25, 0x3f7e2c09), + (16, 0xbe880001, 0xbf740000, 0.0, 0x3c2ce9c0), + (17, 0x3ec7fffd, 0xbec80001, 0.5, 0x3f990000), + (18, 0x3ec7fffd, 0xbec80001, 0.25, 0x3f8ab222), + (18, 0xbf7c0000, 0xbf7c0000, 0.25, 0x00000000), + ] { + let value = coverage(shape, f32::from_bits(x), f32::from_bits(y), variation); + assert_eq!(value.to_bits(), bits, "shape {shape} at ({x:08x}, {y:08x})"); + } +} + +fn cook(graph: PatternGraph) -> crate::CookResult { + cook_with_variables(graph, &BTreeMap::new(), 7) +} + +#[test] +fn stamp_tint_preserves_the_authored_type_and_scales_before_coverage() { + let rgba = Value::Float4([0.9, 0.11, 0.57, 0.732]); + let constant = |value| Value::Function(Box::new(FunctionGraph::constant(value))); + for (shape, color, tint, gain, expected) in [ + (2, false, rgba.clone(), 1.0, [0x3f06_d3a0; 4]), + (2, false, constant(rgba.clone()), 1.0, [0x3f3b_645a; 4]), + (5, true, constant(Value::Float(0.732)), 0.6137, [0x3ee4_3699; 4]), + (5, true, rgba.clone(), 0.6137, [0x3ecd_6456, 0x3d48_d3e4, 0x3e82_14e2, 0x3ee4_3699]), + (17, true, constant(rgba), 327.125, [0x42de_3ea0, 0x4159_4e4d, 0x428c_c144, 0x42f6_f041]), + ] { + assert_stamp_pixel(shape, color, tint, gain, 0.0, expected); + } +} + +#[test] +fn pattern_opacity_flushes_subnormals_at_their_arithmetic_boundaries() { + let normal = f32::MIN_POSITIVE; + let tiny = f32::from_bits(0x0037_1245); + let large = f32::from_bits(0x5d80_0000); + for (tint, gain, background, expected) in [ + ([large, large, large, 0.25], normal, 0.0, [0; 4]), + ([1.0, 1.0, 1.0, tiny], large, 0.0, [0; 4]), + ([tiny, tiny, tiny, 1.0], large, 0.0, [0, 0, 0, large.to_bits()]), + ([1.0, 1.0, 1.0, -1.0], f32::from_bits(0x0080_0001), normal, [0x8000_0000; 4]), + ([1.0; 4], normal, 0.0, [normal.to_bits(); 4]), + ] { + assert_stamp_pixel(2, true, Value::Float4(tint), gain, background, expected); + } + for color in [false, true] { + for shape in [0, 2] { + assert_stamp_pixel(shape, color, Value::Float4([1.0; 4]), 0.0, -tiny, [0x8000_0000; 4]); + } + } +} + +#[test] +fn solid_stamps_round_the_alpha_blend_at_accumulator_precision() { + for (background, expected) in + [(0x393f_a080, [0x3e81_77f4, 0x3e0f_efe8, 0x3eba_f7f4, 0x3ee6_0d32]), (0xbb89_bb22, [0x3e7e_7227, 0x3e0b_7227, 0x3eb8_b913, 0x3ee4_d090])] + { + assert_stamp_pixel(2, true, Value::Float4([0.5625, 0.3125, 0.8125, 0.71875]), 0.625, f32::from_bits(background), expected); + } +} + +fn stamp_on_background(graph: PatternGraph, color: bool, gain: f32, background: [f32; 4], seed: u32) -> craft_texture::Image { + let definition = find("fx_map").unwrap(); + let params = resolve_params( + definition, + &BTreeMap::from([ + ("pattern".into(), Value::PatternGraph(Box::new(graph))), + ("roughness".into(), Value::Float(0.0)), + ("color_mode".into(), Value::Bool(color)), + ("opacity".into(), Value::Float(gain)), + ("background".into(), Value::Color(background)), + ]), + ); + let context = CookContext { + input_formats: &[], + format: materialcraft_core::OutputFormat::F32, + w: 32, + h: 32, + seed, + tile: true, + inputs: &[], + params: ¶ms, + resource: &|_| None, + vars: &BTreeMap::new(), + }; + (definition.cook)(&context).unwrap().remove(0) +} + +fn assert_stamp_pixel(shape: i32, color: bool, tint: Value, gain: f32, background: f32, expected: [u32; 4]) { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([("patterntype".into(), Value::Int(shape)), ("opacity".into(), tint), ("blendingmode".into(), Value::Int(0))]); + let image = stamp_on_background(graph, color, gain, [background; 4], 7); + let pixel = image.get(16, 16, false).map(f32::to_bits); + assert_eq!(&pixel[..image.channels()], &expected[..image.channels()], "shape {shape}, color {color}, opacity {gain}"); +} + +#[test] +fn quadrant_tint_blends_undefined_components_individually() { + let mut tint = FunctionGraph::default(); + let depth = tint.add("get_float1", &[], Some(Value::Text("$depth".into()))); + let zero = tint.add("sub", &[depth, depth], None); + let undefined = tint.add("div", &[zero, zero], None); + let eighth = tint.add("const_float1", &[], Some(Value::Float(0.125))); + let quarter = tint.add("const_float1", &[], Some(Value::Float(0.25))); + let half = tint.add("const_float1", &[], Some(Value::Float(0.5))); + let red_nan = tint.add("vector2", &[undefined, quarter], None); + let blue_alpha = tint.add("vector2", &[eighth, half], None); + let red_tint = tint.add("vector4", &[red_nan, blue_alpha], None); + let red_green = tint.add("vector2", &[eighth, quarter], None); + let alpha_nan = tint.add("vector2", &[eighth, undefined], None); + let alpha_tint = tint.add("vector4", &[red_green, alpha_nan], None); + + let background = [0.25_f32, 0.375, 0.5, 0.75]; + for (shape, color, output, expected) in [ + (2, true, red_tint, [0x7fff_ffff, 0.5_f32.to_bits(), 0.5625_f32.to_bits(), 0.875_f32.to_bits()]), + (2, true, alpha_tint, background.map(f32::to_bits)), + (2, true, undefined, background.map(f32::to_bits)), + (2, false, red_tint, [0.875_f32.to_bits(); 4]), + (2, false, alpha_tint, [0.375_f32.to_bits(); 4]), + (2, false, undefined, [0.375_f32.to_bits(); 4]), + (17, true, alpha_tint, [0x7fff_ffff; 4]), + (17, false, undefined, [0x7fff_ffff; 4]), + (18, true, alpha_tint, background.map(f32::to_bits)), + ] { + tint.output = Some(output); + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(shape)), + ("patternsuppl".into(), Value::Float(0.375)), + ("opacity".into(), Value::Function(Box::new(tint.clone()))), + ]); + let image = stamp_on_background(graph, color, 1.0, background, 40991); + let pixel = image.get(16, 16, false).map(f32::to_bits); + assert_eq!(&pixel[..image.channels()], &expected[..image.channels()]); + } +} + +#[test] +fn quadrant_fields_reject_nonfinite_geometry_and_infinite_tints() { + for (field, value) in [("frameoffset", Value::Float2([f32::NAN, 0.0])), ("opacity", Value::Float(f32::INFINITY))] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = + BTreeMap::from([("patterntype".into(), Value::Int(2)), (field.into(), Value::Function(Box::new(FunctionGraph::constant(value))))]); + assert!(cook_with_variables(graph, &BTreeMap::new(), 40991).is_err()); + } +} + +#[test] +fn zero_authored_stamp_opacity_is_distinct_from_zero_graph_opacity() { + let linked = |value| Value::Function(Box::new(FunctionGraph::constant(Value::Float(value)))); + let tiny = f32::from_bits(1 << 19); + for (shape, tint, gain, gray, red) in [ + (2, Value::Float4([0.0; 4]), 1.0, -0.25, -0.25), + (2, Value::Float4([1.0; 4]), 0.0, 0.0, -0.25), + (17, Value::Float4([0.0; 4]), 1.0, 0.25, 0.0625), + (18, Value::Float4([0.0; 4]), 1.0, -0.25, -0.25), + (18, Value::Float4([1.0; 4]), 0.0, 0.25, 0.0625), + (18, linked(tiny), 1.0, -0.25, -0.25), + (18, linked(-tiny), 1.0, -0.25, -0.25), + (18, linked(f32::MIN_POSITIVE), 1.0, 0.25, 0.0625), + ] { + for (color, expected) in [(false, gray), (true, red)] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(shape)), + ("opacity".into(), tint.clone()), + ("blendingmode".into(), Value::Int(1)), + ("patternsuppl".into(), Value::Float(0.25)), + ]); + let image = stamp_on_background(graph, color, gain, [-0.25; 4], 328019); + assert_eq!(image.get(16, 16, false)[0], expected, "shape {shape}, color {color}, gain {gain}"); + } + } +} + +#[test] +fn gradient_stamp_offsets_apply_to_the_tinted_channels() { + let background = [0.5, 0.375, 0.75, 0.875]; + for (shape, variation, blend, background, position, expected) in [ + (17, 0.25, 0, [0.0; 4], 16, [0x3ebde000, 0x3e9ef000, 0x3ed28000, 0x3ed28000]), + (17, -0.125, 0, [0.0; 4], 16, [0xbb880000, 0xbd844000, 0x3d140000, 0x3d140000]), + (2, 0.0, 0, background, 16, [0x3f3c0000, 0x3efc0000, 0x3f880000, 0x3f6a0000]), + (2, 0.0, 2, background, 16, [0x3f140000, 0x3ec00000, 0x3f540000, 0x3f6a0000]), + (18, -0.125, 1, background, 0, background.map(f32::to_bits)), + ] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(shape)), + ("patternsuppl".into(), Value::Float(variation)), + ("opacity".into(), Value::Float4([0.75, 0.375, 1.0, 0.625])), + ("blendingmode".into(), Value::Int(blend)), + ]); + let image = stamp_on_background(graph, true, 0.5, background, 468); + assert_eq!(image.get(position, position, false).map(f32::to_bits), expected); + } +} + +fn cook_with_variables(graph: PatternGraph, variables: &BTreeMap, seed: u32) -> crate::CookResult { + cook_at_size(graph, variables, seed, 16) +} + +fn cook_at_size(graph: PatternGraph, variables: &BTreeMap, seed: u32, side: u32) -> crate::CookResult { + cook_at_dimensions(graph, variables, seed, side, side) +} + +fn stamp_turn_input() -> Value { + Value::Function(Box::new(FunctionGraph::input("turn", materialcraft_core::ValueType::Float))) +} + +fn cook_at_dimensions(graph: PatternGraph, variables: &BTreeMap, seed: u32, width: u32, height: u32) -> crate::CookResult { + cook_in_regions(graph, variables, seed, [width, height], [[0.0, 1.0, 0.0, 1.0]; 2], 0.0) +} + +#[test] +fn grayscale_stamps_draw_in_shape_then_blend_order() { + let tiny = 2.0_f32.powi(-27); + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0))]); + for (shapes, modes, tints, siblings, background, expected) in [ + ([2, 2, 2], [1, 0, 0], [0.75, 0.25, 0.5], true, 0.1875, [0.9375, 0.75]), + ([2, 3, 2], [1, 0, 0], [0.875, -0.375, 0.5], false, 0.1875, [0.5, 0.875]), + ([2, 3, 2], [0, 0, 0], [0.75, tiny, -0.75], false, 0.0, [tiny, 0.75]), + ] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let first = graph.add(PatternNodeKind::Quadrant).unwrap(); + let second = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children[0] = Some(first); + let parent = if siblings { 0 } else { 1 }; + graph.nodes[parent].children[1] = Some(second); + for (i, (node, size)) in graph.nodes.iter_mut().zip([1.0, 2.0, 4.0]).enumerate() { + let tint = tints[i]; + node.parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(shapes[i])), + ("blendingmode".into(), Value::Int(modes[i])), + ("opacity".into(), Value::Float4([tint, tint, tint, 1.0])), + ("patternsize".into(), Value::Float2([size; 2])), + ]); + } + let image = cook_in_regions(graph, &variables, 0, [32, 16], [[0.0, 1.0, 0.0, 1.0]; 2], background).unwrap().remove(0); + assert_eq!([image.get_gray(0, 0, false), image.get_gray(31, 15, false)], expected, "shapes {shapes:?}, modes {modes:?}"); + } +} + +fn three_bitmap_stamps(slots: [i32; 3], filters: [i32; 3], modes: [i32; 3], colors: [[f32; 4]; 3]) -> PatternGraph { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let first = graph.add(PatternNodeKind::Quadrant).unwrap(); + let second = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children[0] = Some(first); + graph.nodes[1].children[1] = Some(second); + for (i, (node, size)) in graph.nodes.iter_mut().zip([1.0, 2.0, 4.0]).enumerate() { + node.parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(1)), + ("imageindex".into(), Value::Int(slots[i])), + ("imagefiltering".into(), Value::Int(filters[i])), + ("blendingmode".into(), Value::Int(modes[i])), + ("opacity".into(), Value::Float4(colors[i])), + ("patternsize".into(), Value::Float2([size; 2])), + ]); + } + graph +} + +#[test] +fn grayscale_bitmap_stamps_group_repeated_slots_in_first_draw_order() { + use craft_texture::{Image, Kind}; + use materialcraft_core::OutputFormat; + + let definition = find("fx_map").unwrap(); + let level = 128.0 / 255.0; + let tiny = 2.0_f32.powi(-27); + // The input bridges have already resized both constant fields to the graph dimensions. + let inputs = [None, Some(Image::filled(32, 16, Kind::Gray, [level; 4])), Some(Image::filled(32, 16, Kind::Gray, [1.0; 4]))]; + for (slots, filters, modes, tints, expected) in [ + ([1, 0, 1], [2; 3], [0, 0, 0], [0.75, tiny, -0.75], [tiny * level, 0.75]), + ([1, 0, 1], [2; 3], [1, 0, 1], [0.125, 0.25, 0.875], [0.875 + 0.25 * level, 0.125]), + ([1, 1, 1], [2; 3], [1, 0, 1], [0.875, 0.25, 0.75], [0.875, 0.875]), + ([1; 3], [0, 1, 0], [1, 0, 1], [0.75, 0.3125, 0.1875], [1.0625, 0.75]), + ([1; 3], [1, 2, 1], [0; 3], [0.75, tiny, -0.75], [tiny, 0.75]), + ([1; 3], [2, 1, 2], [0; 3], [0.75, tiny, -0.75], [0.0, 0.75]), + ] { + let graph = three_bitmap_stamps(slots, filters, modes, tints.map(|tint| [tint, tint, tint, 1.0])); + let params = resolve_params( + definition, + &BTreeMap::from([ + ("pattern".into(), Value::PatternGraph(Box::new(graph))), + ("roughness".into(), Value::Float(0.0)), + ("color_mode".into(), Value::Bool(false)), + ]), + ); + let context = CookContext { + w: 32, + h: 16, + seed: 471817, + format: OutputFormat::F32, + tile: false, + input_formats: &[OutputFormat::U8; 3], + inputs: &inputs, + params: ¶ms, + resource: &|_| None, + vars: &BTreeMap::from([("$tiling".into(), Value::Int(0))]), + }; + let image = (definition.cook)(&context).unwrap().remove(0); + assert_eq!([image.get_gray(0, 0, false), image.get_gray(31, 15, false)], expected); + } +} + +#[test] +fn bitmap_draw_order_uses_the_wired_slots_for_a_runtime_selector() { + use craft_texture::{Image, Kind}; + use materialcraft_core::{OutputFormat, ValueType}; + + let definition = find("fx_map").unwrap(); + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0)), ("chosen".into(), Value::Int(0))]); + for (kind, gray, alpha, fixed, runtime) in [ + (Kind::Gray, [0.125, 0.25, 0.875], [1.0; 3], 1.0004902_f32, 0.875_f32), + (Kind::Color, [0.75, 0.25, 0.5], [0.375, 0.59375, 0.71875], 0.51298636, 0.451574), + ] { + let colors = std::array::from_fn(|i| [gray[i], gray[i], gray[i], alpha[i]]); + let inputs = [ + None, + Some(Image::filled(32, 16, kind, [128.0 / 255.0, 181.0 / 255.0, 79.0 / 255.0, 1.0])), + Some(Image::filled(32, 16, kind, [1.0, 205.0 / 255.0, 111.0 / 255.0, 1.0])), + ]; + for (selector, expected) in [(FunctionGraph::constant(Value::Int(0)), fixed), (FunctionGraph::input("chosen", ValueType::Integer), runtime)] { + let mut graph = three_bitmap_stamps([1, 0, 1], [2; 3], [1, 0, 1], colors); + graph.nodes[1].parameters.insert("imageindex".into(), Value::Function(Box::new(selector))); + let params = resolve_params( + definition, + &BTreeMap::from([ + ("pattern".into(), Value::PatternGraph(Box::new(graph))), + ("roughness".into(), Value::Float(0.0)), + ("color_mode".into(), Value::Bool(kind == Kind::Color)), + ]), + ); + let context = CookContext { + w: 32, + h: 16, + seed: 471817, + format: OutputFormat::F32, + tile: false, + input_formats: &[OutputFormat::U8; 3], + inputs: &inputs, + params: ¶ms, + resource: &|_| None, + vars: &variables, + }; + let image = (definition.cook)(&context).unwrap().remove(0); + assert_eq!(image.get(0, 0, false)[0].to_bits(), expected.to_bits()); + } + } +} + +fn draw_on_fourth_repetition(graph: &mut PatternGraph) { + // Only the fourth outer repetition submits a quadrant tree. + let select = graph.add(PatternNodeKind::Switch).unwrap(); + let mut condition = FunctionGraph::default(); + let number = condition.add("get_float1", &[], Some(Value::Text("$number".into()))); + let three = condition.add_constant(Value::Float(3.0)); + condition.output = Some(condition.add("eq", &[number, three], None)); + graph.nodes[(select - 1) as usize].children[1] = graph.root; + graph.nodes[(select - 1) as usize].parameters.insert("switch".into(), Value::Function(Box::new(condition))); + let outer = graph.add(PatternNodeKind::Iterate).unwrap(); + graph.nodes[(outer - 1) as usize].children[1] = Some(select); + graph.nodes[(outer - 1) as usize].parameters.insert("numberadded".into(), Value::Int(9)); + graph.root = Some(outer); +} + +#[test] +fn a_single_quadrant_tree_retains_its_compositing_order_through_a_gated_repetition() { + let small = f32::EPSILON * 0.5; + for (depth, expected) in [(5, 0.0_f32), (6, small), (7, small)] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + for (slot, weight) in [1.0, small, -1.0, 0.0].into_iter().enumerate() { + let mut leaf = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children[slot] = Some(leaf); + for _ in 1..depth { + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(leaf - 1) as usize].children.fill(Some(child)); + leaf = child; + } + // Center the first leaf of each subtree on the same pixel. All other leaves miss it. + let first = [slot & 1, slot >> 1].map(|half| half as f32 * 0.5 + 0.5 / (1 << depth) as f32); + graph.nodes[(leaf - 1) as usize].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(4)), + ("patternsize".into(), Value::Float2([0.75; 2])), + ("frameoffset".into(), Value::Float2(first.map(|v| 15.5 / 32.0 - v))), + ("opacity".into(), Value::Float(weight)), + ("blendingmode".into(), Value::Int(0)), + ]); + } + let image = cook_at_size(graph.clone(), &BTreeMap::new(), 377014, 32).unwrap().remove(0); + assert_eq!(image.get_gray(15, 15, false).to_bits(), expected.to_bits(), "{depth} levels"); + + draw_on_fourth_repetition(&mut graph); + let image = cook_at_size(graph, &BTreeMap::new(), 306344, 32).unwrap().remove(0); + assert_eq!(image.get_gray(15, 15, false).to_bits(), expected.to_bits(), "{depth} levels through a gated repetition"); + } +} + +struct QuadrantProbeGroup { + last_three: [usize; 3], + offset: [f32; 2], +} + +fn seven_level_tree() -> (PatternGraph, Vec) { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let mut groups = Vec::new(); + for slot in 0..4 { + let parent = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children[slot] = Some(parent); + for child_slot in 0..4 { + let mut ancestor = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(parent - 1) as usize].children[child_slot] = Some(ancestor); + for _ in 2..5 { + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(ancestor - 1) as usize].children.fill(Some(child)); + ancestor = child; + } + let terminal = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(ancestor - 1) as usize].children.fill(Some(terminal)); + let leaf = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(terminal - 1) as usize].children.fill(Some(leaf)); + let offset = [(slot & 1) * 2 + (child_slot & 1), (slot >> 1) * 2 + (child_slot >> 1)].map(|quarter| -0.25 * quarter as f32); + groups.push(QuadrantProbeGroup { last_three: [ancestor, terminal, leaf].map(|id| (id - 1) as usize), offset }); + } + } + (graph, groups) +} + +fn additive_square(weight: f32, offset: [f32; 2], frame: [f32; 2]) -> BTreeMap { + BTreeMap::from([ + ("patterntype".into(), Value::Int(2)), + ("patternsize".into(), Value::Float2([0.875; 2])), + ("branchoffset".into(), Value::Float2(offset)), + ("frameoffset".into(), Value::Float2(frame)), + ("opacity".into(), Value::Float(weight)), + ("blendingmode".into(), Value::Int(0)), + ]) +} + +fn square_fork(parent_gain: f32) -> PatternGraph { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let mut parent = graph.root.unwrap(); + for depth in 1..=9 { + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + let slots = &mut graph.nodes[(parent - 1) as usize].children; + if let Some(&slot) = [0, 3, 1, 0].get(depth - 1) { + slots[slot] = Some(child); + } else { + slots.fill(Some(child)); + } + if depth == 1 || depth == 9 { + let (gain, size) = if depth == 1 { (parent_gain, 2.0) } else { (f32::EPSILON * 0.25, 1.375) }; + let mut parameters = additive_square(gain, [0.0; 2], [0.0; 2]); + parameters.insert("patternsize".into(), Value::Float2([size; 2])); + graph.nodes[(child - 1) as usize].parameters = parameters; + } + parent = child; + } + graph +} + +#[test] +fn an_empty_later_quadrant_changes_when_its_sibling_draws() { + let mut graph = square_fork(-1.0); + let empty = graph.add(PatternNodeKind::Quadrant).unwrap(); + let active = graph.nodes[3].children[0]; + for (children, surviving_pixel) in [ + ([active, None, None, None], Some((6, 4))), + ([active, Some(empty), None, None], None), + ([active, active, None, None], Some((7, 4))), + ([active, active, active, None], Some((6, 5))), + ([active; 4], Some((7, 5))), + ] { + graph.nodes[3].children.copy_from_slice(&children); + let image = cook_in_regions(graph.clone(), &BTreeMap::new(), 0, [16; 2], [[0.0, 1.0, 0.0, 1.0]; 2], 1.0).unwrap().remove(0); + for y in 0..16 { + for x in 0..16 { + let value = if Some((x, y)) == surviving_pixel { f32::EPSILON } else { 0.0 }; + assert_eq!(image.get_gray(x, y, false).to_bits(), value.to_bits(), "pixel ({x}, {y}), children {children:?}"); + } + } + } +} + +#[test] +fn two_repetitions_share_the_parent_and_last_child_draws() { + let mut graph = square_fork(-0.5); + let empty = graph.add(PatternNodeKind::Quadrant).unwrap(); + let iterate = graph.add(PatternNodeKind::Iterate).unwrap(); + graph.nodes[(iterate - 1) as usize].children[1] = graph.root; + graph.nodes[(iterate - 1) as usize].parameters.insert("numberadded".into(), Value::Int(2)); + graph.root = Some(iterate); + let active = graph.nodes[3].children[0]; + for (sibling, expected) in [(None, [f32::EPSILON, 0.0]), (Some(empty), [0.0; 2]), (active, [0.0, f32::EPSILON])] { + graph.nodes[3].children[1] = sibling; + let image = cook_in_regions(graph.clone(), &BTreeMap::new(), 0, [16; 2], [[0.0, 1.0, 0.0, 1.0]; 2], 1.0).unwrap().remove(0); + assert_eq!([6, 7].map(|x| image.get_gray(x, 4, false).to_bits()), expected.map(f32::to_bits), "sibling {sibling:?}"); + } +} + +#[test] +fn seven_quadrant_levels_order_leaf_runs_before_discarding_missed_stamps() { + let tiny = f32::EPSILON * 0.25; + for (negative, positive, miss_other_stamps, missing_slot, expected) in + [(12, 0, false, None, tiny), (12, 0, true, None, tiny), (0, 14, true, None, 0.0), (12, 0, false, Some(2), tiny), (0, 14, true, Some(2), 0.0)] + { + let (mut graph, groups) = seven_level_tree(); + for (group, QuadrantProbeGroup { last_three: [_, terminal, leaf], offset }) in groups.into_iter().enumerate() { + if let Some(slot) = missing_slot { + graph.nodes[terminal].children[slot] = None; + } + let weight = if group == negative { + -1.0 + } else if group == positive { + tiny + } else { + 0.0 + }; + // Move neutral leaves halfway between samples to exercise geometric culling. + let shift = if miss_other_stamps && weight == 0.0 { 0.5 / 128.0 } else { 0.0 }; + graph.nodes[leaf].parameters = additive_square(weight, offset, [shift; 2]); + } + for detached_dot in [false, true] { + if detached_dot { + graph.add(PatternNodeKind::Dot).unwrap(); + } + let image = cook_in_regions(graph.clone(), &BTreeMap::new(), 136404, [128; 2], [[0.0, 1.0, 0.0, 1.0]; 2], 1.0).unwrap().remove(0); + for y in 0..128 { + for x in 0..128 { + let slot = ((x & 1) + 2 * (y & 1)) as usize; + let value = if x < 32 && y < 32 && missing_slot != Some(slot) { expected } else { 1.0 }; + assert_eq!( + image.get_gray(x, y, false).to_bits(), + value.to_bits(), + "groups {negative} and {positive} at ({x},{y}), missing {missing_slot:?}, detached {detached_dot}" + ); + } + } + } + } +} + +#[test] +fn depth_six_stamps_and_their_four_leaves_draw_in_the_same_grandchild_run() { + let tiny = f32::EPSILON * 0.25; + let (mut graph, groups) = seven_level_tree(); + for (group, QuadrantProbeGroup { last_three: [_, terminal, leaf], offset }) in groups.into_iter().enumerate() { + let weight = match group { + 12 => -1.0, + 0 => tiny, + _ => 0.0, + }; + graph.nodes[terminal].parameters = additive_square(weight, offset, [0.0; 2]); + graph.nodes[leaf].parameters = additive_square(0.25, [0.0; 2], [0.0, 0.5]); + } + let image = cook_in_regions(graph, &BTreeMap::new(), 137143, [128; 2], [[0.0, 1.0, 0.0, 1.0]; 2], 1.0).unwrap().remove(0); + for y in 0..32 { + for x in 0..32 { + assert_eq!(image.get_gray(x, y, false).to_bits(), tiny.to_bits(), "overlapping parents at ({x},{y})"); + assert_eq!(image.get_gray(x, y + 64, false), 5.0, "overlapping leaves at ({x},{y})"); + } + } +} + +fn gated_mixed_depth_tree(grandchildren: bool) -> PatternGraph { + let (mut graph, groups) = seven_level_tree(); + let middle = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(middle - 1) as usize].parameters = additive_square(0.25, [0.0; 2], [0.0, 0.5]); + if grandchildren { + let leaf = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(leaf - 1) as usize].parameters = additive_square(0.25, [0.0; 2], [0.0, 0.5]); + graph.nodes[(middle - 1) as usize].children.fill(Some(leaf)); + } + let tiny = f32::EPSILON * 0.25; + for (group, QuadrantProbeGroup { last_three: [_, prior, parent], offset }) in groups.into_iter().enumerate() { + let (weight, frame) = match group { + 12 if grandchildren => (-1.0, [0.0; 2]), + 5 if !grandchildren => (-1.0, [0.0; 2]), + 0 => (tiny, [0.0; 2]), + _ => (0.25, [0.5, 0.0]), + }; + graph.nodes[parent].parameters = additive_square(weight, offset, frame); + graph.nodes[parent].children.fill(Some(middle)); + let pass = graph.add(PatternNodeKind::Iterate).unwrap(); + graph.nodes[(pass - 1) as usize].children[1] = Some(graph.nodes[parent].id); + graph.nodes[(pass - 1) as usize].parameters.insert("numberadded".into(), Value::Int(1)); + graph.nodes[prior].children.fill(Some(pass)); + } + + draw_on_fourth_repetition(&mut graph); + graph +} + +#[test] +fn single_branch_controls_keep_the_order_of_a_complete_nine_level_tree() { + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0))]); + let image = cook_in_regions(gated_mixed_depth_tree(true), &variables, 188119, [128; 2], [[0.0, 1.0, 0.0, 1.0]; 2], 1.0).unwrap().remove(0); + let samples = [(0, 0), (8, 0), (0, 16), (16, 0)].map(|(x, y)| image.get_gray(x, y, false)); + let tiny = f32::EPSILON * 0.25; + assert_eq!(samples, [0.0, tiny, tiny, 0.0], "one active tree through both iterators"); +} + +#[test] +fn a_larger_tiled_window_keeps_the_draw_order_when_each_stamp_has_one_copy() { + let variables = BTreeMap::from([("$tiling".into(), Value::Int(3))]); + let window = [-0.5, 1.5, -0.5, 1.5]; + let image = cook_in_regions(gated_mixed_depth_tree(true), &variables, 188119, [256; 2], [window; 2], 1.0).unwrap().remove(0); + let samples = [(64, 64), (72, 64), (64, 80), (80, 64)].map(|(x, y)| image.get_gray(x, y, false)); + let tiny = f32::EPSILON * 0.25; + assert_eq!(samples, [0.0, tiny, tiny, 0.0]); +} + +fn draw_white_image(mut graph: PatternGraph, filter: i32, axes: i32) -> craft_texture::Image { + use craft_texture::Image; + + for node in &mut graph.nodes { + if node.parameters.get("patterntype").and_then(Value::as_i32) == Some(2) { + node.parameters.insert("patterntype".into(), Value::Int(1)); + node.parameters.insert("imagefiltering".into(), Value::Int(filter)); + } + } + cook_probe_on_white(graph, axes, &[None, Some(Image::gray(8, 8, |_, _| 1.0))]) +} + +fn cook_probe_on_white(graph: PatternGraph, axes: i32, inputs: &[Option]) -> craft_texture::Image { + use materialcraft_core::OutputFormat; + + let definition = find("fx_map").unwrap(); + let params = resolve_params( + definition, + &BTreeMap::from([ + ("pattern".into(), Value::PatternGraph(Box::new(graph))), + ("roughness".into(), Value::Float(0.0)), + ("color_mode".into(), Value::Bool(false)), + ("background".into(), Value::Color([1.0; 4])), + ]), + ); + let context = CookContext { + w: 128, + h: 128, + seed: 188119, + format: OutputFormat::F32, + tile: axes != 0, + input_formats: &[OutputFormat::F32; 2], + inputs, + params: ¶ms, + resource: &|_| None, + vars: &BTreeMap::from([("$tiling".into(), Value::Int(axes))]), + }; + (definition.cook)(&context).unwrap().remove(0) +} + +#[test] +fn fixed_image_stamps_keep_the_subtree_order_of_an_untiled_quadrant_tree() { + let tiny = f32::EPSILON * 0.25; + for filter in [2, 1, 0] { + let image = draw_white_image(gated_mixed_depth_tree(true), filter, 0); + let samples = [(0, 0), (8, 0), (0, 16), (16, 0)].map(|(x, y)| image.get_gray(x, y, false)); + assert_eq!(samples, [0.0, tiny, tiny, 0.0], "filter {filter}"); + } +} + +fn two_tree_parent_probe(negative: (i32, [i32; 2]), small: (i32, [i32; 2]), wrap_leaves: bool) -> PatternGraph { + fn at_parent(f: &mut FunctionGraph, (iteration, pixel): (i32, [i32; 2])) -> u32 { + let number = f.add("get_float1", &[], Some(Value::Text("$number".into()))); + let phase = f.add_constant(Value::Float(iteration as f32)); + let active = f.add("eq", &[number, phase], None); + let pos = f.add("get_float2", &[], Some(Value::Text("$pos".into()))); + let center = f.add_constant(Value::Float2(pixel.map(|axis| (axis as f32 + 0.5) / 128.0))); + let delta = f.add("sub", &[pos, center], None); + let squared = f.add("dot", &[delta, delta], None); + let zero = f.add_constant(Value::Float(0.0)); + let selected = f.add("eq", &[squared, zero], None); + f.add("and", &[active, selected], None) + } + + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(2)); + let mut parent = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children[1] = Some(parent); + let tiny = f32::EPSILON * 0.25; + for depth in 1..=9 { + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(parent - 1) as usize].children.fill(Some(child)); + parent = child; + if depth < 7 { + continue; + } + let mut params = additive_square(0.25, [0.0; 2], [0.0; 2]); + let mut frame = FunctionGraph::default(); + let pos = frame.add("get_float2", &[], Some(Value::Text("$pos".into()))); + let far = frame.add_constant(Value::Float2([0.875; 2])); + let center = if depth == 7 { + let a = at_parent(&mut frame, negative); + let b = at_parent(&mut frame, small); + let hit = frame.add("or", &[a, b], None); + let readout = frame.add_constant(Value::Float2([32.5 / 128.0, 16.5 / 128.0])); + let mut tint = FunctionGraph::default(); + let selected = at_parent(&mut tint, negative); + let minus_one = tint.add_constant(Value::Float(-1.0)); + let increment = tint.add_constant(Value::Float(tiny)); + tint.output = Some(tint.add("ifelse", &[selected, minus_one, increment], None)); + params.insert("opacity".into(), Value::Function(Box::new(tint))); + frame.add("ifelse", &[hit, readout, far], None) + } else if wrap_leaves && depth == 9 { + // Eight by eight leaves in the first tree produce one extra tile copy each. + let number = frame.add("get_float1", &[], Some(Value::Text("$number".into()))); + let zero = frame.add_constant(Value::Float(0.0)); + let mut inside = frame.add("eq", &[number, zero], None); + let limit = frame.add_constant(Value::Float(8.0 / 512.0)); + for axis in 0..2 { + let component = frame.add("swizzle1", &[pos], Some(Value::Int(axis))); + let below = frame.add("lr", &[component, limit], None); + inside = frame.add("and", &[inside, below], None); + } + let edge = frame.add_constant(Value::Float2([0.0, 0.875])); + frame.add("ifelse", &[inside, edge, far], None) + } else { + far + }; + frame.output = Some(frame.add("sub", &[center, pos], None)); + params.insert("frameoffset".into(), Value::Function(Box::new(frame))); + graph.nodes[(child - 1) as usize].parameters = params; + } + graph +} + +#[test] +fn unfinished_quadrant_draws_can_follow_a_draw_from_the_next_tree() { + let graph = two_tree_parent_probe((1, [118, 112]), (0, [79, 69]), false); + let vars = BTreeMap::from([("$tiling".into(), Value::Int(0))]); + let square = cook_in_regions(graph.clone(), &vars, 188119, [128; 2], [[0.0, 1.0, 0.0, 1.0]; 2], 1.0).unwrap().remove(0); + let image = draw_white_image(graph, 2, 0); + assert_eq!([square.get_gray(32, 16, false), image.get_gray(32, 16, false)], [f32::EPSILON * 0.25; 2], "order of overlapping parents"); +} + +#[test] +fn extra_copies_of_leaves_can_move_a_parent_past_another_subtree() { + for (wrap_leaves, expected) in [(false, f32::EPSILON * 0.25), (true, 0.0)] { + let graph = two_tree_parent_probe((0, [49, 29]), (0, [54, 50]), wrap_leaves); + let image = draw_white_image(graph, 2, 3); + assert_eq!(image.get_gray(32, 16, false), expected, "parent order with wrapping leaves {wrap_leaves}"); + } +} + +fn two_tree_copy_field_readout(negative: [i32; 2], small: [i32; 2], copies_in_group: impl Fn(u32) -> u32 + Sync) -> f32 { + use craft_texture::Image; + + // The two banks hold one texel per terminal quadrant. Move the selected + // leaves to the tile boundary. All remaining leaves stay in the interior. + let mut frame = FunctionGraph::default(); + let pos = frame.add("get_float2", &[], Some(Value::Text("$pos".into()))); + let number = frame.add("get_float1", &[], Some(Value::Text("$number".into()))); + let half = frame.add_constant(Value::Float(0.5)); + let bank = frame.add("mul", &[number, half], None); + let zero = frame.add_constant(Value::Float(0.0)); + let origin = frame.add("vector2", &[bank, zero], None); + let scale = frame.add_constant(Value::Float2([0.5, 1.0])); + let scaled = frame.add("mul", &[pos, scale], None); + let uv = frame.add("add", &[scaled, origin], None); + let x = frame.add("samplelum", &[uv], Some(Value::Int2([0, 0]))); + let y = frame.add_constant(Value::Float(0.875)); + let center = frame.add("vector2", &[x, y], None); + frame.output = Some(frame.add("sub", &[center, pos], None)); + + let mut graph = two_tree_parent_probe((1, negative), (1, small), false); + graph.nodes.last_mut().unwrap().parameters.insert("frameoffset".into(), Value::Function(Box::new(frame))); + let field = Image::gray(1024, 512, |x, y| { + let parent_x = x % 512 / 4; + let parent_y = y / 4; + let mut ordinal = (x / 512) * 16384; + for bit in 0..7 { + ordinal |= ((parent_x >> bit) & 1) << (2 * bit); + ordinal |= ((parent_y >> bit) & 1) << (2 * bit + 1); + } + let copies = copies_in_group(ordinal / 64); + let leaves = copies / 64 + u32::from(ordinal % 64 < copies % 64); + if (y % 4) * 4 + x % 4 < leaves { 0.0 } else { 0.875 } + }); + let image = cook_probe_on_white(graph.clone(), 3, &[None, Some(field)]); + image.get_gray(32, 16, false) +} + +#[test] +fn the_last_tile_copy_in_a_batch_moves_the_following_two_tree_draws() { + // Parent 29,819 and parent 22,269 both belong to the second iteration. + for (extra, expected) in [(167, f32::EPSILON * 0.25), (168, 0.0), (169, 0.0)] { + let value = two_tree_copy_field_readout([109, 71], [111, 30], |group| match group { + 213 => 46, + 217 => 67, + 312 | 419 => 85, + 332 => extra, + 372 => 171, + 384 => 154, + 464 => 36, + 472 => 32, + _ => 0, + }); + assert_eq!(value, expected, "two-tree order with {extra} extra copies in subtree 332"); + } +} + +#[test] +fn a_receiving_tile_batch_can_cross_the_middle_of_its_quadrant() { + // Parents 28,996 and 24,640 exchange order when the next copy fills + // the first half of the receiving 256-parent quadrant. + // Parents 29,824 and 32,596 check the order once that half is full. + for (extra, negative, small, expected) in [(167, [90, 64], [8, 64], f32::EPSILON * 0.25), (168, [90, 64], [8, 64], 0.0), (169, [96, 72], [126, 112], 0.0)] { + let value = two_tree_copy_field_readout(negative, small, |group| match group { + 256 => 189, + 309 => 85, + 320 | 428 => 169, + 464 => extra, + 488 => 148, + _ => 0, + }); + assert_eq!(value, expected, "receiving quadrant with {extra} copies on its first subtree"); + } +} + +#[test] +fn tiled_receiving_order_survives_an_earlier_cut_in_the_preceding_quadrant() { + // Parents 32,139 and 29,680 overlap after the eight-batch cut moves + // into the 64-parent subtree preceding parent 24,448. + let value = two_tree_copy_field_readout([113, 107], [92, 92], |group| match group { + 236 => 76, + 256 => 156, + 308 | 352 => 85, + 320 => 169, + 439 => 132, + 480 => 37, + 488 => 105, + _ => 0, + }); + assert_eq!(value, f32::EPSILON * 0.25); +} + +#[test] +fn tiled_receiving_order_defers_two_subtrees_until_the_batch_fits() { + // At 83 the pending pair returns after parent 21,055. At 84 the + // batch fits exactly, putting parent 31,935 before parent 24,452. + for (extra, negative, small) in [(83, [71, 23], [48, 56]), (84, [103, 111], [114, 56]), (85, [103, 111], [114, 56])] { + let value = two_tree_copy_field_readout(negative, small, |group| match group { + 234 => 70, + 260 => 141, + 320 => 191, + 440 => 145, + 450 => 62, + 480 => 24, + 488 => 126, + 497 => extra, + _ => 0, + }); + assert_eq!(value, f32::EPSILON * 0.25, "receiving batch with {extra} extra copies in subtree 497"); + } +} + +#[test] +fn fixed_image_draws_follow_the_quadrant_runs_when_both_axes_tile() { + for (grandchildren, axes) in [(false, 0), (false, 3), (true, 3)] { + let mut graph = gated_mixed_depth_tree(grandchildren); + // Place one row of child draws over the tile edge. + for node in &mut graph.nodes { + if node.parameters.get("frameoffset") == Some(&Value::Float2([0.0, 0.5])) { + node.parameters.insert("frameoffset".into(), Value::Float2([-0.5 / 256.0, 0.5])); + } + } + let vars = BTreeMap::from([("$tiling".into(), Value::Int(axes))]); + let squares = cook_in_regions(graph.clone(), &vars, 188119, [128; 2], [[0.0, 1.0, 0.0, 1.0]; 2], 1.0).unwrap().remove(0); + let image = draw_white_image(graph, 2, axes); + assert!(squares.data().contains(&(f32::EPSILON * 0.25))); + let exact = squares.data().iter().zip(image.data()).filter(|(a, b)| a.to_bits() == b.to_bits()).count(); + assert_eq!(exact, squares.data().len(), "matching fixed-image pixels, grandchildren {grandchildren}, tiling {axes}"); + } +} + +#[test] +fn depth_eight_parent_order_counts_children_that_cross_the_tile_edge() { + let tiny = f32::EPSILON * 0.25; + let unit = [0.0, 1.0, 0.0, 1.0]; + for (child_count, tiling, child_x, width, early, extent, window, origin) in [ + (2, 0, 0.0, 0.875, 0..284, [128; 2], unit, [0; 2]), + (2, 3, -1.0 / 512.0, 0.875, 0..274, [128; 2], unit, [0; 2]), + (2, 3, 0.4995, 0.875, 0..252, [128; 2], unit, [0; 2]), + (2, 3, -0.125, 4.75, 0..271, [128; 2], unit, [0; 2]), + (2, 3, 0.4995, 4.75, 0..220, [128; 2], unit, [0; 2]), + (2, 3, -1.0 / 512.0, 8.875, 0..252, [128; 2], unit, [0; 2]), + (2, 3, 0.4995, 8.875, 0..188, [128; 2], unit, [0; 2]), + (4, 0, 0.0, 0.875, 580..648, [128; 2], unit, [0; 2]), + (4, 3, -1.0 / 512.0, 0.875, 571..644, [128; 2], unit, [0; 2]), + (4, 3, 0.4995, 0.875, 574..623, [128; 2], unit, [0; 2]), + (2, 3, 0.0, 0.875, 0..284, [256; 2], [-0.5, 1.5, -0.5, 1.5], [64; 2]), + (2, 3, -1.0 / 512.0, 0.875, 0..274, [128, 256], [0.0, 1.0, -0.5, 1.5], [0, 64]), + (2, 3, 0.4995, 0.875, 0..252, [128, 256], [0.0, 1.0, -0.5, 1.5], [0, 64]), + (4, 3, 0.0, 0.875, 580..648, [256; 2], [-0.5, 1.5, -0.5, 1.5], [64; 2]), + (4, 3, -1.0 / 512.0, 0.875, 571..644, [128, 256], [0.0, 1.0, -0.5, 1.5], [0, 64]), + (4, 3, 0.4995, 0.875, 574..623, [128, 256], [0.0, 1.0, -0.5, 1.5], [0, 64]), + ] { + let variables = BTreeMap::from([("$tiling".into(), Value::Int(tiling))]); + let (mut graph, groups) = seven_level_tree(); + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(child - 1) as usize].parameters = additive_square(0.25, [0.0; 2], [child_x, 0.5]); + graph.nodes[(child - 1) as usize].parameters.insert("patternsize".into(), Value::Float2([width, 0.875])); + for (group, QuadrantProbeGroup { last_three: [_, _, parent], mut offset }) in groups.into_iter().enumerate() { + let weight = match group { + 0 => tiny, + 5 => -1.0, + _ => { + // Keep the other parent draws active, outside the readout. + offset[0] += 0.5; + 0.25 + } + }; + graph.nodes[parent].parameters = additive_square(weight, offset, [0.0; 2]); + for (slot, link) in graph.nodes[parent].children.iter_mut().enumerate() { + *link = (child_count == 4 || slot % 2 == 0).then_some(child); + } + } + let image = cook_in_regions(graph, &variables, 158729, extent, [window; 2], 1.0).unwrap().remove(0); + for y in 0..32 { + for x in 0..32 { + let mut parent = 0; + for bit in 0..5 { + parent |= (((x >> bit) & 1) | (((y >> bit) & 1) << 1)) << (2 * bit); + } + let negative_first = early.contains(&parent) || (child_count == 4 && parent >= 768); + let expected = if negative_first { tiny } else { 0.0 }; + assert_eq!( + image.get_gray(origin[0] + x, origin[1] + y, false).to_bits(), + expected.to_bits(), + "{child_count} children, X offset {child_x}, window {window:?} at ({x},{y})" + ); + } + } + } +} + +#[test] +fn three_active_quadrant_levels_split_on_physical_tile_copies() { + fn top_pair_frame(subdivisions: f32) -> Value { + let mut frame = FunctionGraph::default(); + let pos = frame.add("get_float2", &[], Some(Value::Text("$pos".into()))); + let x = frame.add("swizzle1", &[pos], Some(Value::Int(0))); + let y = frame.add("swizzle1", &[pos], Some(Value::Int(1))); + let eighth = frame.add_constant(Value::Float(0.125)); + let left = frame.add("lr", &[x, eighth], None); + let top = frame.add("lr", &[y, eighth], None); + let edge = -0.5 / subdivisions; + let first = frame.add_constant(Value::Float2([edge, 0.5])); + let second = frame.add_constant(Value::Float2([edge - 0.125, 0.5])); + let interior = frame.add_constant(Value::Float2([0.25, 0.5])); + let seam = frame.add("ifelse", &[left, first, second], None); + frame.output = Some(frame.add("ifelse", &[top, seam, interior], None)); + Value::Function(Box::new(frame)) + } + + let tiny = f32::EPSILON * 0.25; + let interior = [0.25, 0.5]; + let horizontal_seam = [[-0.5 / 256.0, 0.5], [-0.5 / 512.0, 0.5]]; + for (tiling, negative, positive, frames, group_frames, first, second) in [ + (0, 12, 0, [[0.0, 0.5]; 2], None, 64..128, 512..1024), + (0, 9, 11, [[0.0, 0.5], horizontal_seam[1]], None, 796..932, 0..0), + (1, 9, 11, [[0.0, 0.5], horizontal_seam[1]], None, 784..919, 0..0), + (2, 9, 11, [[0.0, 0.5], [0.5, -0.5 / 512.0]], None, 784..922, 0..0), + // Two levels cross the seam in the first grandchild, filling a batch in an early subtree. + (1, 12, 0, [interior; 2], Some((0, horizontal_seam.map(Value::Float2))), 64..128, 512..1024), + // The first two subtrees of the final quadrant together submit 10,944 tile copies. + (1, 12, 0, [interior; 2], Some((12, [256.0, 512.0].map(top_pair_frame))), 64..128, 512..1024), + ] { + let (mut graph, groups) = seven_level_tree(); + let mut add_descendants = |frames: [Value; 2]| { + let middle = graph.add(PatternNodeKind::Quadrant).unwrap(); + let leaf = graph.add(PatternNodeKind::Quadrant).unwrap(); + for (id, frame) in [middle, leaf].into_iter().zip(frames) { + let parameters = &mut graph.nodes[(id - 1) as usize].parameters; + *parameters = additive_square(0.25, [0.0; 2], [0.0; 2]); + parameters.insert("frameoffset".into(), frame); + } + graph.nodes[(middle - 1) as usize].children.fill(Some(leaf)); + middle + }; + let middle = add_descendants(frames.map(Value::Float2)); + let selected = group_frames.map(|(group, frames)| (group, add_descendants(frames))); + for (group, QuadrantProbeGroup { last_three: [_, _, parent], offset }) in groups.into_iter().enumerate() { + let (gain, frame) = if group == negative { + (-1.0, [0.0; 2]) + } else if group == positive { + (tiny, [0.0; 2]) + } else { + (0.25, [0.5, 0.0]) + }; + graph.nodes[parent].parameters = additive_square(gain, offset, frame); + let child = selected.filter(|(index, _)| *index == group).map_or(middle, |(_, child)| child); + graph.nodes[parent].children.fill(Some(child)); + } + let variables = BTreeMap::from([("$tiling".into(), Value::Int(tiling))]); + let image = cook_in_regions(graph, &variables, 188119, [128; 2], [[0.0, 1.0, 0.0, 1.0]; 2], 1.0).unwrap().remove(0); + for y in 0..32 { + for x in 0..32 { + let mut parent = 0; + for bit in 0..5 { + parent |= (((x >> bit) & 1) | (((y >> bit) & 1) << 1)) << (2 * bit); + } + let expected = if first.contains(&parent) || second.contains(&parent) { tiny } else { 0.0 }; + assert_eq!(image.get_gray(x, y, false), expected, "tiling {tiling}, groups {negative} and {positive}, parent {parent}"); + } + } + } +} + +#[test] +fn wrapped_copies_of_one_stamp_can_draw_on_opposite_sides_of_another_stamp() { + fn square(gain: f32, center: [f32; 2], size: f32) -> BTreeMap { + let mut frame = FunctionGraph::default(); + let target = frame.add_constant(Value::Float2(center)); + let position = frame.add("get_float2", &[], Some(Value::Text("$pos".into()))); + frame.output = Some(frame.add("sub", &[target, position], None)); + let mut parameters = additive_square(gain, [0.0; 2], [0.0; 2]); + parameters.insert("frameoffset".into(), Value::Function(Box::new(frame))); + parameters.insert("patternsize".into(), Value::Float2([size; 2])); + parameters + } + + let mut tree = PatternGraph::with_root(PatternNodeKind::Quadrant); + let mut parent = tree.root.unwrap(); + for depth in 1..=8 { + let child = tree.add(PatternNodeKind::Quadrant).unwrap(); + tree.nodes[(parent - 1) as usize].children.fill(Some(child)); + if depth >= 7 { + tree.nodes[(child - 1) as usize].parameters = square(0.25, [0.5, 0.75], 0.875); + } + parent = child; + } + + let tiny = f32::EPSILON * 0.25; + let variables = BTreeMap::from([("$tiling".into(), Value::Int(3))]); + // Each parent draws once, followed by four children. Only the two selected squares cross the corner. + for (negative, positive, early_copies) in [(15_699, 65_280, 1), (23_378, 75_520, 2), (2_897, 70_400, 3)] { + let mut graph = tree.clone(); + for (draw, gain) in [(negative, -1.0), (positive, tiny)] { + let parent_visit = draw / 5; + let mut path: Vec<_> = (0..7).rev().map(|level| (parent_visit >> (level * 2)) & 3).collect(); + if draw % 5 != 0 { + path.push(draw % 5 - 1); + } + let size = (1 << path.len()) as f32 / 16.0; + let mut parent = graph.root.unwrap(); + for slot in path { + let original = graph.nodes[(parent - 1) as usize].children[slot].unwrap(); + let node = graph.nodes[(original - 1) as usize].clone(); + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(child - 1) as usize] = materialcraft_core::PatternNode { id: child, ..node }; + graph.nodes[(parent - 1) as usize].children[slot] = Some(child); + parent = child; + } + graph.nodes[(parent - 1) as usize].parameters = square(gain, [0.0; 2], size); + } + let image = cook_in_regions(graph, &variables, 173_519, [128, 64], [[0.0, 1.0, 0.0, 1.0]; 2], 1.0).unwrap().remove(0); + let corners = [(127, 63), (0, 63), (127, 0), (0, 0)]; + for (copy, (x, y)) in corners.into_iter().enumerate() { + assert_eq!(image.get_gray(x, y, false), if copy < early_copies { tiny } else { 0.0 }, "draw {negative}, copy {copy}"); + } + } +} + +#[test] +fn missing_slots_at_the_last_two_subdivisions_keep_the_grandchild_boundaries() { + let tiny = f32::EPSILON * 0.25; + for (subdivision, mask) in [(5, 0b1011), (6, 0b1000), (6, 0b1010)] { + let (mut graph, groups) = seven_level_tree(); + for (group, QuadrantProbeGroup { last_three, offset }) in groups.into_iter().enumerate() { + for (slot, child) in graph.nodes[last_three[subdivision - 5]].children.iter_mut().enumerate() { + if mask & (1 << slot) == 0 { + *child = None; + } + } + let weight = match group { + 12 => -1.0, + 0 => tiny, + _ => 0.0, + }; + graph.nodes[last_three[2]].parameters = additive_square(weight, offset, [0.0; 2]); + } + let image = cook_in_regions(graph, &BTreeMap::new(), 136404, [128; 2], [[0.0, 1.0, 0.0, 1.0]; 2], 1.0).unwrap().remove(0); + for y in 0..128 { + for x in 0..128 { + let place = 6 - subdivision; + let slot = ((x >> place) & 1) + 2 * ((y >> place) & 1); + let expected = if x < 32 && y < 32 && mask & (1 << slot) != 0 { tiny } else { 1.0 }; + assert_eq!(image.get_gray(x, y, false).to_bits(), expected.to_bits(), "subdivision {subdivision}, mask {mask} at ({x},{y})"); + } + } + } +} + +#[test] +fn sparse_quadrant_streams_preserve_the_order_of_their_own_draws() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let weights = [-1.409_263_6, 0.452_831_5, f32::EPSILON * 0.5, 0.124_022_64_f32]; + for (group, slot) in [0, 2].into_iter().enumerate() { + let parent = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children[slot] = Some(parent); + for subslot in 0..2 { + let mut leaf = parent; + for child_slot in [subslot, 0, 0, 0, 0] { + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(leaf - 1) as usize].children[child_slot] = Some(child); + leaf = child; + } + let center = [subslot as f32 * 0.25 + 0.5 / 64.0, group as f32 * 0.5 + 0.5 / 64.0]; + graph.nodes[(leaf - 1) as usize].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(4)), + ("patternsize".into(), Value::Float2([0.75; 2])), + ("frameoffset".into(), Value::Float2(center.map(|v| 15.5 / 32.0 - v))), + ("opacity".into(), Value::Float(weights[group * 2 + subslot])), + ("blendingmode".into(), Value::Int(0)), + ]); + } + } + let image = cook_in_regions(graph, &BTreeMap::new(), 379595, [32; 2], [[0.0, 1.0, 0.0, 1.0]; 2], 1.0).unwrap().remove(0); + assert_eq!(image.get_gray(15, 15, false).to_bits(), 0x3e2b_9cd8); +} + +fn cook_in_regions( + graph: PatternGraph, + variables: &BTreeMap, + seed: u32, + [width, height]: [u32; 2], + [render, tiling]: [[f32; 4]; 2], + background: f32, +) -> crate::CookResult { let definition = find("fx_map").unwrap(); // These traversal fixtures measure unattenuated grayscale stamps @@ -16,13 +1288,17 @@ fn cook_with_variables(graph: PatternGraph, variables: &BTreeMap) ("pattern".into(), Value::PatternGraph(Box::new(graph))), ("roughness".into(), Value::Float(0.0)), ("color_mode".into(), Value::Bool(false)), + ("background".into(), Value::Color([background; 4])), + ("render_region".into(), Value::Float4(render)), + ("tiling_region".into(), Value::Float4(tiling)), ]), ); let context = CookContext { + input_formats: &[], format: materialcraft_core::OutputFormat::F32, - w: 16, - h: 16, - seed: 7, + w: width, + h: height, + seed, tile: true, inputs: &[], params: ¶meters, @@ -33,6 +1309,684 @@ fn cook_with_variables(graph: PatternGraph, variables: &BTreeMap) (definition.cook)(&context) } +#[test] +fn stamp_gradients_keep_the_phase_of_extended_turns() { + for (turns, x, y, bits) in [(1.5, 30, 6, 0x3f05_ffff), (1.75, 6, 30, 0x3f05_ffff), (-3.0, 19, 26, 0x3e9b_fffe)] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([("patterntype".into(), Value::Int(10)), ("patternrotation".into(), Value::Float(turns))]); + let image = cook_at_size(graph, &BTreeMap::new(), 43, 64).unwrap().remove(0); + assert_eq!(image.get_gray(x, y, false).to_bits(), bits, "{turns} turns at ({x},{y})"); + } +} + +#[test] +fn rotated_stamps_use_the_pixel_center_when_snapping_the_near_vertex() { + for (dimensions, center, size, turns, shape, pixel, expected) in [ + ([64, 32], [0.5009855, 0.012967646], [0.024458896, 0.015625], 136.94586, 10, [31, 0], 0x3dff_4c1c), + ([32, 32], [0.06045103, 0.2529377], [0.055972442, 0.03125], 152.8708, 4, [1, 8], 0x3f0e_3e7c), + ([64, 64], [-0.0138504505, 0.07075971], [0.0723335, 0.0625], 189.57106, 4, [0, 5], 0x3eeb_a3c2), + ([256, 256], [-0.010898113, 0.7042948], [0.02902194, 0.03125], 325.4251, 10, [0, 179], 0x3d67_8fd8), + ] { + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0)), ("turn".into(), Value::Float(turns))]); + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(shape)), + ("branchoffset".into(), Value::Float2([-0.5; 2])), + ("frameoffset".into(), Value::Float2(center)), + ("patternsize".into(), Value::Float2(size)), + ("patternrotation".into(), stamp_turn_input()), + ]); + let image = cook_at_dimensions(graph, &variables, 389119, dimensions[0], dimensions[1]).unwrap().remove(0); + assert_eq!(image.get_gray(pixel[0], pixel[1], false).to_bits(), expected, "{center:?} at {dimensions:?}"); + } +} + +#[test] +fn narrow_rotated_stamps_align_the_plane_origin_before_interpolation() { + for (canvas, center, size, turns, shape, pixel, expected) in [ + ([32, 64], [0.59865606, 0.84110206], [0.004831543, 0.28550416], -0.13097546, 10, [18, 52], 0x3f43_ca7a), + ([64, 64], [0.28058177, 0.822639], [0.006552735, 0.31079665], 1.4040037, 6, [18, 53], 0x3f25_4208), + ([128, 64], [0.2890158, 0.7890536], [0.0022128907, 0.43932068], 0.8263619, 8, [29, 48], 0x3ec1_6c44), + ([128, 128], [0.8203125, 0.8671875], [0.00625, 0.23773901], 1.489372, 10, [105, 116], 0x3eab_9835), + ] { + let variables = BTreeMap::from([("turn".into(), Value::Float(turns))]); + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(shape)), + ("branchoffset".into(), Value::Float2([-0.5; 2])), + ("frameoffset".into(), Value::Float2(center)), + ("patternsize".into(), Value::Float2(size)), + ("patternrotation".into(), stamp_turn_input()), + ]); + let image = cook_at_dimensions(graph, &variables, 0, canvas[0], canvas[1]).unwrap().remove(0); + assert_eq!(image.get_gray(pixel[0], pixel[1], false).to_bits(), expected, "{canvas:?} at {pixel:?}"); + } +} + +#[test] +fn stamp_projection_rounds_at_the_pixel_center_in_scaled_regions() { + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0))]); + for (span, center, size, dimensions, samples) in [ + ([7.0; 2], [3.5; 2], [7.0; 2], [64, 64], [(12, 0xbf1c_0001), (19, 0xbec8_0004)]), + ([7.0; 2], [3.5; 2], [7.0; 2], [64, 32], [(0, 0xbf7c_0000), (63, 0x3f7b_fffc)]), + ([7.0; 2], [3.5; 2], [7.0; 2], [32, 64], [(0, 0xbf78_0000), (31, 0x3f77_fffc)]), + ([3.0; 2], [1.5 + 3.0 / 4096.0, 1.5], [3.0; 2], [32, 32], [(12, 0xbe60_8008), (19, 0x3e5f_7ff8)]), + ([13.0; 2], [6.5; 2], [13.0; 2], [32, 64], [(12, 0xbe60_0008), (19, 0x3e5f_fff8)]), + ([13.0, 1.0], [0.5; 2], [1.0; 2], [16, 32], [(0, 0xbe40_0004), (1, 0x0000_0000)]), + ([15.0, 1.0], [0.5; 2], [1.0; 2], [16, 32], [(0, 0xbd80_0008), (1, 0x0000_0000)]), + ([13.0, 1.0], [0.5; 2], [1.0; 2], [32, 64], [(0, 0xbf18_0001), (1, 0x3e5f_fff0)]), + ([7.0, 1.0], [0.109_375_f32.next_down(), 0.5], [0.4375, 1.0], [32, 32], [(0, 0xb380_0000), (1, 0x3f7f_fffc)]), + ] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(17)), + ("patternsuppl".into(), Value::Float(-1.0)), + ("blendingmode".into(), Value::Int(0)), + ("opacity".into(), Value::Float(2.0)), + ("branchoffset".into(), Value::Float2([-0.5; 2])), + ("frameoffset".into(), Value::Float2(center)), + ("patternsize".into(), Value::Float2(size)), + ]); + let region = [0.0, span[0], 0.0, span[1]]; + let image = cook_in_regions(graph, &variables, 170235, dimensions, [region; 2], 0.0).unwrap().remove(0); + for (x, bits) in samples { + assert_eq!(image.get_gray(x, 0, false).to_bits(), bits, "span {span:?}, column {x}"); + } + } +} + +#[test] +fn fading_stamp_uses_the_pixel_center_in_an_offset_rectangular_window() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(12)), + ("patternsuppl".into(), Value::Float(0.78)), + ("blendingmode".into(), Value::Int(1)), + ("branchoffset".into(), Value::Float2([-0.5; 2])), + ("frameoffset".into(), Value::Float2([0.6015625, 0.4375])), + ("patternsize".into(), Value::Float2([1.8125, 0.96875])), + ("patternrotation".into(), stamp_turn_input()), + ]); + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0)), ("turn".into(), Value::Float(0.25))]); + let region = [-1.0, 2.0, -2.5, 3.5]; + let image = cook_in_regions(graph, &variables, 290178, [16, 32], [region; 2], 0.0).unwrap().remove(0); + assert_eq!(image.get_gray(9, 15, false).to_bits(), 0x3f0c_d037); +} + +#[test] +fn clipped_square_stamp_triangles_use_the_far_vertex_for_both_slope_terms() { + for (dimensions, center, size, turns, shape, pixel, expected) in [ + ([256, 256], [-0.08850241, 2.9797058], [0.06013941, 0.0625], 161.3187, 4, [236, 1], 0x3dec_9e10), + ([128, 256], [-0.01251943, 0.8291415], [0.0390625, 0.0078125], 0.94446576, 8, [0, 211], 0x3e21_7c84), + ] { + let variables = BTreeMap::from([("turn".into(), Value::Float(turns))]); + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(shape)), + ("branchoffset".into(), Value::Float2([-0.5; 2])), + ("frameoffset".into(), Value::Float2(center)), + ("patternsize".into(), Value::Float2(size)), + ("patternrotation".into(), stamp_turn_input()), + ]); + let image = cook_at_dimensions(graph, &variables, 395323, dimensions[0], dimensions[1]).unwrap().remove(0); + assert_eq!(image.get_gray(pixel[0], pixel[1], false).to_bits(), expected, "{dimensions:?} at {pixel:?}"); + } +} + +#[test] +fn clipped_quarter_turn_aligns_the_axis_offset_before_adding_the_vertex() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(4)), + ("branchoffset".into(), Value::Float2([-0.5; 2])), + ("frameoffset".into(), Value::Float2([-0.8652914, -0.36846057])), + ("patternsize".into(), Value::Float2([0.09375, 0.27446696])), + ("patternrotation".into(), Value::Float(0.25)), + ]); + let image = cook_at_dimensions(graph, &BTreeMap::new(), 399341, 256, 512).unwrap().remove(0); + assert_eq!(image.get_gray(18, 341, false).to_bits(), 0x3e62_3d20); +} + +#[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))]); + for (turn, size, x) in [(1.5, [0.5175781, 0.27148438], 37), (-17.75, [0.27148438, 0.5175781], 27), (4096.25, [0.27148438, 0.5175781], 42)] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(2)), + ("branchoffset".into(), Value::Float2([-0.5; 2])), + ("frameoffset".into(), Value::Float2([0.5332031, 0.3779297])), + ("patternsize".into(), Value::Float2(size)), + ("patternrotation".into(), Value::Float(turn)), + ]); + let image = cook_at_size(graph, &variables, 323355, 64).unwrap().remove(0); + assert_eq!(image.get_gray(x, 15, false), 0.0, "{turn} turns"); + assert_eq!(image.get_gray(x, 16, false), 1.0, "{turn} turns"); + } +} + +#[test] +fn subpixel_axis_aligned_ramps_and_paraboloids_use_interpolated_coordinates() { + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0))]); + let unit = [0.0, 1.0, 0.0, 1.0]; + for (canvas, [x, y], center, size, seed, expected) in [ + ([64, 32], [37, 18], [0.586_013_8, 0.577_758_8], [1.0 / 2048.0, 1.0 / 512.0], 332208, [0x3eb0_0002, 0x3f43_0001]), + ([16, 32], [6, 19], [0.405_578_6, 0.609_878_54], [-1.0 / 512.0, 1.0 / 512.0], 332239, [0x3e20_0004, 0x3e85_e008]), + ] { + for (shape, bits) in [10, 4].into_iter().zip(expected) { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(shape)), + ("branchoffset".into(), Value::Float2([-0.5; 2])), + ("frameoffset".into(), Value::Float2(center)), + ("patternsize".into(), Value::Float2(size)), + ]); + let image = cook_in_regions(graph, &variables, seed, canvas, [unit; 2], 0.0).unwrap().remove(0); + assert_eq!(image.get_gray(x, y, false).to_bits(), bits, "shape {shape} at {center:?}"); + } + } +} + +#[test] +fn subpixel_square_keeps_its_interpolated_edge_on_repeated_draws() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children[1] = Some(child); + graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(2)); + graph.nodes[1].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(2)), + ("blendingmode".into(), Value::Int(0)), + ("branchoffset".into(), Value::Float2([-0.5; 2])), + ("frameoffset".into(), Value::Float2([0.003_742_665_5, 0.523_437_5])), + ("patternsize".into(), Value::Float2([0.008_139_668, 0.011_718_75])), + ]); + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0))]); + let image = cook_at_size(graph, &variables, 307023, 64).unwrap().remove(0); + assert_eq!(image.get_gray(0, 33, false), 2.0); +} + +#[test] +fn oblique_stamp_interpolates_both_coordinates_of_a_paraboloid() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(4)), + ("patternsize".into(), Value::Float2([0.25; 2])), + ("patternrotation".into(), Value::Float(0.0625)), + ]); + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0))]); + let image = cook_at_size(graph, &variables, 301067, 64).unwrap().remove(0); + assert_eq!(image.get_gray(31, 24, false).to_bits(), 0x3df0_0010); +} + +#[test] +fn rotated_stamp_uses_its_stored_bounds_in_a_displaced_render_window() { + let unit = [0.0, 1.0, 0.0, 1.0]; + for (region, center, turn, shape, [x, y], bits) in [ + ([128.0, 129.0, 0.0, 1.0], [128.4375, 0.4375], 0.125, 10, [17, 27], 0x3c62_f8c0), + ([1024.0, 1025.0, 1024.0, 1025.0], [1024.4375; 2], 0.0625, 4, [23, 21], 0x3cc0_e9a0), + ] { + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0)), ("turn".into(), Value::Float(turn))]); + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(shape)), + ("branchoffset".into(), Value::Float2([-0.5; 2])), + ("frameoffset".into(), Value::Float2(center)), + ("patternsize".into(), Value::Float2([0.25; 2])), + ("patternrotation".into(), stamp_turn_input()), + ]); + let rendered = cook_in_regions(graph, &variables, 337435, [64, 64], [region, unit], 0.0).unwrap().remove(0); + assert_eq!(rendered.get_gray(x, y, false).to_bits(), bits); + } +} + +#[test] +fn subpixel_rotated_stamp_interpolates_its_ramp_and_paraboloid() { + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0)), ("turn".into(), Value::Float(0.125))]); + let unit = [0.0, 1.0, 0.0, 1.0]; + for (shape, bits) in [(10, 0x3f6b_7e10), (4, 0x3e44_b5b0)] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(shape)), + ("branchoffset".into(), Value::Float2([-0.5; 2])), + ("frameoffset".into(), Value::Float2([0.586_013_8, 0.577_758_8])), + ("patternsize".into(), Value::Float2([1.0 / 2048.0, 1.0 / 512.0])), + ("patternrotation".into(), stamp_turn_input()), + ]); + let rendered = cook_in_regions(graph, &variables, 332332, [64, 32], [unit; 2], 0.0).unwrap().remove(0); + assert_eq!(rendered.get_gray(37, 18, false).to_bits(), bits); + } +} + +#[test] +fn sparse_quadrants_report_their_accumulated_child_positions() { + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0))]); + for (slot, center, axis, bits) in [ + (1, [-0.953_548_5, -0.769_640_9], 0, 0xbf54_1bc0), + (2, [0.400_343_98, 0.941_799_6], 0, 0x3e8c_f9e4), + (2, [0.111_769_885, -0.181_289_99], 1, 0xbd66_9050), + ] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let parent = graph.add(PatternNodeKind::Quadrant).unwrap(); + let leaf = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].parameters.insert("branchoffset".into(), Value::Float2([-0.25; 2])); + graph.nodes[0].children[0] = Some(parent); + graph.nodes[1].parameters.insert("branchoffset".into(), Value::Float2(center)); + graph.nodes[1].children[slot] = Some(leaf); + + let mut color = FunctionGraph::default(); + let position = color.add("get_float2", &[], Some(Value::Text("$pos".into()))); + color.output = Some(color.add("swizzle1", &[position], Some(Value::Int(axis)))); + graph.nodes[2].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(2)), + ("patternsize".into(), Value::Float2([4.0; 2])), + ("frameoffset".into(), Value::Float2(center.map(|v| 0.5 - v))), + ("opacity".into(), Value::Function(Box::new(color))), + ]); + let image = cook_at_dimensions(graph, &variables, 365809, 16, 16).unwrap().remove(0); + assert_eq!(image.get_gray(7, 7, false).to_bits(), bits); + } +} + +#[test] +fn rotated_paraboloid_interpolates_across_neighboring_pixel_pairs() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(4)), + ("branchoffset".into(), Value::Float2([-0.5; 2])), + ("frameoffset".into(), Value::Float2([0.046_721_816, 0.413_024_96])), + ("patternsize".into(), Value::Float2([0.106_382_97; 2])), + ("patternrotation".into(), stamp_turn_input()), + ]); + let variables = BTreeMap::from([("$tiling".into(), Value::Int(3)), ("turn".into(), Value::Float(0.430_651_3))]); + let image = cook_at_dimensions(graph, &variables, 350314, 64, 128).unwrap().remove(0); + for (x, y, bits) in [(1, 48, 0x3ecb_3c42), (1, 52, 0x3f4e_334f), (5, 52, 0x3ee8_375a)] { + assert_eq!(image.get_gray(x, y, false).to_bits(), bits); + } +} + +#[test] +fn shallow_rotated_ramp_stores_the_interpolated_coordinate_before_shading() { + 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.415_625, 0.480_468_75])), + ("patternsize".into(), Value::Float2([0.386_718_75, 0.25])), + ("patternrotation".into(), Value::Float(0.000_273_437_5)), + ]); + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0))]); + let image = cook_at_dimensions(graph, &variables, 360680, 32, 64).unwrap().remove(0); + assert_eq!(image.get_gray(8, 31, false).to_bits(), 0x3de5_bb68); +} + +#[test] +fn oblique_stamp_retains_the_small_cross_axis_step_on_a_thin_ramp() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([("patterntype".into(), Value::Int(10)), ("patternrotation".into(), Value::Float(1.5))]); + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0))]); + let image = cook_at_dimensions(graph, &variables, 189775, 256, 16).unwrap().remove(0); + assert_eq!(image.get_gray(128, 6, false).to_bits(), 0x3eff_0000); +} + +#[test] +fn fractional_stamp_edges_set_both_coordinate_gradients() { + for (size, shift, turn, x, y, expected) in [ + ([0.375, 0.23046875], [0.0, 0.0], 0.0, 21, 32, 0x3d80_0004), + ([0.375, 0.23828125], [0.0, 0.00390625], 0.0, 35, 32, 0x3f25_5554), + ([0.625, 0.234375], [0.0078125, 0.0], 0.0, 37, 32, 0x3f1f_ffff), + ([0.23828125, 0.375], [0.0, 0.001953125], 0.25, 20, 34, 0x3f27_de6c), + ([0.2578125, 0.375], [0.0, 0.001953125], 0.25, 20, 33, 0x3f15_5554), + ] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(10)), + ("patternsize".into(), Value::Float2(size)), + ("frameoffset".into(), Value::Float2(shift)), + ("patternrotation".into(), Value::Float(turn)), + ]); + let image = cook_at_size(graph, &BTreeMap::new(), 428, 64).unwrap().remove(0); + assert_eq!(image.get_gray(x, y, false).to_bits(), expected, "size {size:?}, turn {turn}, pixel ({x},{y})"); + } +} + +#[test] +fn wrapped_beveled_stamp_retains_its_coordinate_at_the_crop() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(9)), + ("patternsuppl".into(), Value::Float(0.7265625)), + ("patternsize".into(), Value::Float2([0.984375, 0.484375])), + ("frameoffset".into(), Value::Float2([0.5, 0.25])), + ]); + let image = cook_at_size(graph, &BTreeMap::new(), 261312, 128).unwrap().remove(0); + assert_eq!(image.get_gray(48, 88, false).to_bits(), 0x3e73_2b04); +} + +#[test] +fn clipped_stamp_gradients_use_one_triangle_vertex_for_both_axes() { + let region = super::region::Region::new([0.0, 1.0, 0.0, 1.0]).unwrap(); + for (canvas, center, size, expected) in [ + ([128, 64], [-0.2734375, 0.3125], [0.734375_f32, 0.734375], 0x3f60_ae4e), + ([128, 64], [-0.2734375, 0.3125], [-0.734375, 0.734375], 0x3dfa_8d8c), + ([128, 128], [-0.3046875, -0.265625], [0.7578125, 0.6953125], 0x3f68_3f56), + ] { + let frame = super::footprint::Footprint { sine: 0.0, cosine: 1.0, radius: size.map(|s| s.abs() * 0.5) }; + let planes = super::coordinates::PixelPlanes::new(&frame, ®ion, center, size, canvas).unwrap(); + let [x, _] = planes.row(0)(0).unwrap(); + assert_eq!(((x + 1.0) * 0.5).to_bits(), expected, "center {center:?}, size {size:?}"); + } +} + +#[test] +fn snapped_stamp_vertices_preserve_fractional_positions() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(10)), + ("patternsize".into(), Value::Float2([28.625 / 64.0, 12.625 / 64.0])), + ("frameoffset".into(), Value::Float2([-0.075, -0.125])), + ]); + let image = cook_at_size(graph, &BTreeMap::new(), 265259, 64).unwrap().remove(0); + for (x, bits) in [(16, 0x3e01_3ace), (33, 0x3f38_57a4)] { + assert_eq!(image.get_gray(x, 18, false).to_bits(), bits, "column {x}"); + } +} + +#[test] +fn oblique_stamp_bounds_depend_on_whether_size_and_rotation_are_literal() { + let size = Value::Float2([0.75, 1.5]); + let turn = Value::Float(0.125); + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0)), ("size".into(), size.clone()), ("turn".into(), turn.clone())]); + let link = |name, ty| Value::Function(Box::new(FunctionGraph::input(name, ty))); + for (size, rotation, expected) in [ + (size.clone(), turn.clone(), 0x3f59_911e), + (size.clone(), Value::Function(Box::new(FunctionGraph::constant(turn.clone()))), 0x3f59_911e), + (link("size", materialcraft_core::ValueType::Float2), turn, 0x3f59_9122), + (size, link("turn", materialcraft_core::ValueType::Float), 0x3f59_9122), + ] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(17)), + ("patternsize".into(), size), + ("patternrotation".into(), rotation), + ("frameoffset".into(), Value::Float2([0.0, -1.0])), + ]); + let image = cook_at_dimensions(graph, &variables, 422233, 128, 64).unwrap().remove(0); + assert_eq!(image.get_gray(46, 0, false).to_bits(), expected); + } +} + +#[test] +fn stamp_precision_at_the_far_vertex_precedes_the_coordinate_scale() { + let region = super::region::Region::new([0.0, 1.0, 0.0, 1.0]).unwrap(); + let size = [0.166_012_8_f32, 0.652_076_1]; + let center = [0.029_354_721, 0.792_399_17]; + for (cosine, expected) in [(1.0, 0x3ed5_a7fc), (-1.0, 0x3f15_2c02)] { + let frame = super::footprint::Footprint { sine: 0.0, cosine, radius: size.map(|s| s * 0.5) }; + let planes = super::coordinates::PixelPlanes::new(&frame, ®ion, center, size, [32, 64]).unwrap(); + let [x, _] = planes.row(30)(0).unwrap(); + assert_eq!(((x + 1.0) * 0.5).to_bits(), expected, "cosine {cosine}"); + } +} + +#[test] +fn stamp_vertices_snap_after_storage_at_pixel_precision() { + let region = super::region::Region::new([0.0, 1.0, 0.0, 1.0]).unwrap(); + let size = [0.1875; 2]; + let frame = super::footprint::Footprint { sine: 0.0, cosine: 1.0, radius: [0.09375; 2] }; + let planes = super::coordinates::PixelPlanes::new(&frame, ®ion, [0.295_898_4, -0.031_547_427], size, [512, 128]).unwrap(); + let [x, y] = planes.row(0)(138).unwrap(); + assert_eq!((coverage(4, x, y, 0.0) * 0.91).to_bits(), 0x3f36_8e3f); +} + +#[test] +fn shifted_region_preserves_the_vertices_before_projection() { + let region = super::region::Region::new([0.0, 1.0, -0.5, 1.5]).unwrap(); + let size = [0.270_833_34, 0.162_500_01]; + let frame = super::footprint::Footprint { sine: 0.0, cosine: 1.0, radius: size.map(|s| s * 0.5) }; + let planes = super::coordinates::PixelPlanes::new(&frame, ®ion, [0.541_666_7, 0.437_499_97], size, [16, 32]).unwrap(); + let [u, v] = planes.row(14)(7).unwrap(); + assert_eq!(coverage(4, u, v, 0.0).to_bits(), 0x3f0f_e7d1); +} + +#[test] +fn shifted_region_keeps_the_original_center_for_tiled_copies() { + let shifted = [-0.5, 1.5, 0.0, 1.0]; + let fractional = [[0.0, 1.0, 0.0, 1.0], [-0.173, 0.369, 0.096, 0.869]]; + for (regions, canvas, center, size, [x, y], expected) in [ + ([shifted; 2], [32, 16], [-0.333_333_3, 0.637_500_05], [0.270_833_34, 0.162_5], [1, 9], 0x3e6c_4ec4), + (fractional, [32, 64], [-3.631_460_7, -3.076_536_2], [0.416_212_65, 0.932_240_3], [0, 32], 0x3e16_8cbc), + ] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(10)), + ("blendingmode".into(), Value::Int(0)), + ("branchoffset".into(), Value::Float2([-0.5; 2])), + ("frameoffset".into(), Value::Float2(center)), + ("patternsize".into(), Value::Float2(size)), + ]); + let image = cook_in_regions(graph, &BTreeMap::new(), 319091, canvas, regions, 0.0).unwrap().remove(0); + assert_eq!(image.get_gray(x, y, false).to_bits(), expected, "center {center:?}"); + } +} + +#[test] +fn shifted_region_stores_the_snap_offset_in_pattern_space() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(10)), + ("blendingmode".into(), Value::Int(0)), + ("branchoffset".into(), Value::Float2([-0.5; 2])), + ("frameoffset".into(), Value::Float2([0.005_702_4, 0.984_657_3])), + ("patternsize".into(), Value::Float2([0.203_478_44, 0.709_372_1])), + ("patternrotation".into(), Value::Float(0.25)), + ]); + let regions = [[-0.173, 0.369, 0.096, 0.869], [0.019, 0.631, -0.073, 0.689]]; + let image = cook_in_regions(graph, &BTreeMap::new(), 319613, [32, 64], regions, 0.0).unwrap().remove(0); + assert_eq!(image.get_gray(0, 2, false).to_bits(), 0x3cd4_7660); +} + +#[test] +fn stamp_vertices_keep_the_last_sample_of_a_wrapped_square() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(2)), + ("branchoffset".into(), Value::Float2([-0.5; 2])), + ("frameoffset".into(), Value::Float2([0.958_333_3, 0.4375])), + ("patternsize".into(), Value::Float2([0.270_833_34, 0.8125])), + ]); + let image = cook_at_dimensions(graph, &BTreeMap::new(), 311024, 16, 32).unwrap().remove(0); + assert_eq!(image.get_gray(1, 1, false), 1.0); +} + +#[test] +fn wrapped_centers_store_each_step_across_fractional_periods() { + let region = super::region::Region::new([-0.173, 0.369, 0.096, 0.869]).unwrap(); + let copies = region.repeats(®ion, [0.307_120_5, 0.5], [2.0, 0.0], [true, false]).unwrap(); + let leftmost = copies[0].centers().min_by(f32::total_cmp); + assert_eq!(leftmost.map(f32::to_bits), Some(0xbfee_314e)); +} + +#[test] +fn tiled_ramp_retains_the_phase_of_copies_above_the_visible_window() { + let tiling = [0.019, 0.631, -0.073, 0.689]; + for (axes, canvas, center, size, render, [x, y], expected) in [ + (3, [32, 64], [0.064_685_315, 0.205_253_44], [0.579_976_9, 0.400_788_1], [-0.173, 0.369, 0.096, 0.869], [29, 0], 0x3f73_a212), + (1, [128, 32], [-0.935_683_2, 0.335_352_5], [33.782_4, 0.866_160_7], [-9.979, -9.558, 0.096, 0.869], [6, 0], 0x4160_7c0c), + ] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(10)), + ("blendingmode".into(), Value::Int(0)), + ("branchoffset".into(), Value::Float2([-0.5; 2])), + ("frameoffset".into(), Value::Float2(center)), + ("patternsize".into(), Value::Float2(size)), + ]); + let variables = BTreeMap::from([("$tiling".into(), Value::Int(axes))]); + let image = cook_in_regions(graph, &variables, 329457, canvas, [render, tiling], 0.0).unwrap().remove(0); + assert_eq!(image.get_gray(x, y, false).to_bits(), expected, "render window {render:?}"); + } +} + +#[test] +fn wrapped_additive_stamps_visit_the_outer_row_and_column_first() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(10)), + ("blendingmode".into(), Value::Int(0)), + ("branchoffset".into(), Value::Float2([-0.5; 2])), + ("frameoffset".into(), Value::Float2([0.1875, 0.34375])), + ("patternsize".into(), Value::Float2([2.75, 2.5])), + ]); + let image = cook_at_size(graph, &BTreeMap::new(), 311197, 32).unwrap().remove(0); + assert_eq!(image.get_gray(3, 0, false).to_bits(), 0x4035_1747); +} + +#[test] +fn a_wrapped_stamp_keeps_the_center_precision_of_its_outer_copy() { + 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.063_709_915, 0.906_030_9])), + ("patternsize".into(), Value::Float2([0.128_019_7, 0.062_836_37])), + ]); + let image = cook_at_size(graph, &BTreeMap::new(), 303021, 64).unwrap().remove(0); + assert_eq!(image.get_gray(0, 56, false).to_bits(), 0x3d81_c730); +} + +#[test] +fn snapped_stamp_vertices_clip_the_last_solid_sample() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(2)), + ("patternsize".into(), Value::Float2([0.703125, 0.765625])), + ("frameoffset".into(), Value::Float2([-0.796875, -0.8125])), + ]); + let image = cook_at_size(graph, &BTreeMap::new(), 270681, 64).unwrap().remove(0); + assert_eq!(image.get_gray(0, 3, false), 1.0); + assert_eq!(image.get_gray(0, 4, false), 0.0); +} + +#[test] +fn gaussian_stamp_coordinates_follow_the_pixel_footprint() { + let definition = find("fx_map").unwrap(); + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(6)), + ("blendingmode".into(), Value::Int(1)), + ("patternsize".into(), Value::Float2([3.0, 1.5])), + ("frameoffset".into(), Value::Float2([-0.25; 2])), + ]); + let params = resolve_params( + definition, + &BTreeMap::from([ + ("pattern".into(), Value::PatternGraph(Box::new(graph))), + ("color_mode".into(), Value::Bool(false)), + ("roughness".into(), Value::Float(0.0)), + ("opacity".into(), Value::Float(0.995)), + ]), + ); + for (w, h, x, y, expected) in [ + (16, 16, 7, 1, 0x3ef8_8006), + (16, 32, 0, 14, 0x3eb2_37e3), + (32, 32, 0, 14, 0x3eac_19c4), + (8, 64, 0, 30, 0x3e9b_8a3c), + (64, 128, 2, 62, 0x3e85_65a0), + (128, 256, 0, 126, 0x3e69_16dd), + ] { + let context = CookContext { + w, + h, + seed: 223, + format: materialcraft_core::OutputFormat::F32, + input_formats: &[], + tile: false, + inputs: &[], + params: ¶ms, + resource: &|_| None, + vars: &BTreeMap::new(), + }; + let image = (definition.cook)(&context).unwrap().remove(0); + assert_eq!(image.get_gray(x, y, false).to_bits(), expected, "{w}x{h} at ({x},{y})"); + } +} + +#[test] +fn oblique_square_keeps_the_last_sample_inside_its_edge() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(2)), + ("patternsize".into(), Value::Float2([0.755, 0.391])), + ("patternrotation".into(), Value::Float(0.13125)), + ("frameoffset".into(), Value::Float2([-0.1113, 0.1437])), + ]); + let image = cook_at_size(graph, &BTreeMap::new(), 1108, 512).unwrap().remove(0); + assert_eq!(image.get_gray(307, 492, false), 1.0); + assert_eq!(image.get_gray(308, 492, false), 0.0); + assert_eq!(image.get_gray(307, 493, false), 0.0); +} + +#[test] +fn quarter_turns_keep_stamp_edge_ownership_in_image_space() { + // The sample centers on all four rectangle edges distinguish image-space ownership after rotation. + let size = [0.625, 0.25]; + for (angle, size, first, last) in [ + (0.0, size, [13, 25], [52, 40]), + (0.25, size, [25, 13], [40, 52]), + (0.5, size, [13, 25], [52, 40]), + (0.75, size, [25, 13], [40, 52]), + (-0.25, size, [25, 13], [40, 52]), + (1.25, size, [25, 13], [40, 52]), + (0.0, [-0.625, 0.25], [13, 25], [52, 40]), + (0.25, [-0.625, -0.25], [25, 13], [40, 52]), + ] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(2)), + ("patternsize".into(), Value::Float2(size)), + ("patternrotation".into(), Value::Float(angle)), + ("frameoffset".into(), Value::Float2([1.0 / 128.0; 2])), + ]); + let image = cook_at_size(graph, &BTreeMap::new(), 943, 64).unwrap().remove(0); + for y in 0..64 { + for x in 0..64 { + let covered = (first[0]..=last[0]).contains(&x) && (first[1]..=last[1]).contains(&y); + assert_eq!(image.get_gray(x, y, false), f32::from(covered), "turn {angle} at ({x},{y})"); + } + } + } +} + +#[test] +fn a_sample_on_the_stored_lower_stamp_edge_is_excluded() { + let size = [0.4, 0.3]; + let frame = super::footprint::Footprint { sine: 0.0, cosine: 1.0, radius: size.map(|v| v * 0.5) }; + let sample = [14.5 / 32.0, 9.5 / 16.0]; + for axis in 0..2 { + let mut center = sample; + center[axis] += frame.radius[axis]; + assert!(frame.local(sample, center, size).is_none()); + let mut inside = sample; + inside[axis] += 1.0 / [32.0, 16.0][axis]; + assert!(frame.local(inside, center, size).is_some()); + } +} + #[test] fn pattern_functions_keep_host_time_and_quadrant_depth() { for (name, expected) in [("$time", 0.75), ("$depth", 1.0), ("$depthpow2", 0.5)] { @@ -46,7 +2000,7 @@ fn pattern_functions_keep_host_time_and_quadrant_depth() { function.output = Some(function.add("get_float1", &[], Some(Value::Text(name.into())))); graph.nodes[1].parameters.insert("opacity".into(), Value::Function(Box::new(function))); - let image = cook_with_variables(graph, &BTreeMap::from([("$time".into(), Value::Float(0.75))])).unwrap().remove(0); + let image = cook_with_variables(graph, &BTreeMap::from([("$time".into(), Value::Float(0.75))]), 7).unwrap().remove(0); assert!((image.mean()[0] - expected).abs() < 1e-6, "{name}: {}", image.mean()[0]); } @@ -81,6 +2035,1074 @@ fn iterate_sets_number_and_switch_selects_one_child() { assert_eq!(cook(graph).unwrap()[0].mean()[0], 0.0); } +#[test] +fn an_iterators_seed_settings_apply_to_its_repeated_branch() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let initial = graph.add(PatternNodeKind::Quadrant).unwrap(); + let repeated = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children = vec![Some(initial), Some(repeated)]; + graph.nodes[0].parameters.insert("randomseed".into(), Value::Int(17)); + let mut tint = FunctionGraph::default(); + let half = tint.add_constant(Value::Float(0.5)); + tint.output = Some(tint.add("rand", &[half], None)); + for (square, x) in graph.nodes[1..].iter_mut().zip([-0.25, 0.25]) { + square.parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(2)), + ("patternsize".into(), Value::Float2([0.5, 1.0])), + ("frameoffset".into(), Value::Float2([x, 0.0])), + ("opacity".into(), Value::Function(Box::new(tint.clone()))), + ]); + } + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0))]); + for (inherit, seed, left, right) in [(true, 42, 0x3e2a_2edc, 0x3e37_d570), (false, 42, 0x3e2a_2edc, 0x3ec2_59fa), (false, 329779, 0x3f14_0041, 0x3ec2_59fa)] + { + graph.nodes[0].parameters.insert("randominherited".into(), Value::Bool(inherit)); + let image = cook_in_regions(graph.clone(), &variables, seed, [16; 2], [[0.0, 1.0, 0.0, 1.0]; 2], 0.125).unwrap().remove(0); + for y in 0..16 { + for x in 0..16 { + assert_eq!(image.get_gray(x, y, false).to_bits(), if x < 8 { left } else { right }); + } + } + } +} + +#[test] +fn a_nested_iterators_initial_branch_inherits_the_callers_number() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let inner = graph.add(PatternNodeKind::Iterate).unwrap(); + let initial = graph.add(PatternNodeKind::Quadrant).unwrap(); + let repeated = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children[1] = Some(inner); + graph.nodes[1].children = vec![Some(initial), Some(repeated)]; + + let mut gain = FunctionGraph::default(); + let number = gain.add("get_float1", &[], Some(Value::Text("$number".into()))); + let weight = gain.add_constant(Value::Float(1.0 / 32.0)); + gain.output = Some(gain.add("mul", &[number, weight], None)); + for (square, offset) in graph.nodes[2..].iter_mut().zip([-0.25, 0.25]) { + square.parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(2)), + ("blendingmode".into(), Value::Int(0)), + ("patternsize".into(), Value::Float2([0.5, 1.0])), + ("frameoffset".into(), Value::Float2([offset, 0.0])), + ("opacity".into(), Value::Function(Box::new(gain.clone()))), + ]); + } + + // The left half records the initial branch. The right half records the inner repetitions. + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0))]); + for (outer, inner, seed, width, height, left, right) in [ + (3, 1, 283271, 16, 16, 0.09375, 0.0), + (4, 3, 283328, 8, 8, 0.1875, 0.375), + (2, 0, 283347, 16, 8, 0.03125, 0.0), + (5, 2, 283404, 32, 64, 0.3125, 0.15625), + ] { + graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(outer)); + graph.nodes[1].parameters.insert("numberadded".into(), Value::Int(inner)); + let image = cook_at_dimensions(graph.clone(), &variables, seed, width, height).unwrap().remove(0); + for row in image.data().chunks_exact(width as usize) { + let (a, b) = row.split_at(width as usize / 2); + assert!(a.iter().all(|&pixel| pixel == left), "outer {outer}, inner {inner}, initial branch"); + assert!(b.iter().all(|&pixel| pixel == right), "outer {outer}, inner {inner}, repeated branch"); + } + } +} + +#[test] +fn long_pattern_iterations_charge_only_connected_visits() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let square = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[1].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(2)), + ("blendingmode".into(), Value::Int(0)), + ("patternsize".into(), Value::Float2([1.0; 2])), + ("opacity".into(), Value::Float(1.0 / 32_768.0)), + ]); + for (initial, repeated, count, expected) in [ + (None, Some(square), 12_003, 12_003.0 / 32_768.0), + (Some(square), None, 16_384, 1.0 / 32_768.0), + (None, None, 16_384, 0.0), + (Some(square), None, i32::MAX, 1.0 / 32_768.0), + ] { + graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(count)); + graph.nodes[0].children = vec![initial, repeated]; + let image = cook_at_size(graph.clone(), &BTreeMap::new(), 452933, 4).unwrap().remove(0); + assert!(image.data().iter().all(|&v| v == expected)); + } +} + +#[test] +fn repeated_empty_size_switches_leave_the_visit_budget_for_drawing() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let mark = graph.add(PatternNodeKind::Quadrant).unwrap(); + let repeat = graph.add(PatternNodeKind::Iterate).unwrap(); + let gate = graph.add(PatternNodeKind::Switch).unwrap(); + let bright = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children = vec![Some(mark), Some(repeat)]; + graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(1024)); + graph.nodes[1].parameters.insert("patterntype".into(), Value::Int(2)); + graph.nodes[1].parameters.insert("opacity".into(), Value::Float(0.5)); + graph.nodes[2].children[1] = Some(gate); + graph.nodes[2].parameters.insert("numberadded".into(), Value::Int(1024)); + graph.nodes[3].children[1] = Some(bright); + let mut condition = FunctionGraph::default(); + let log_size = condition.add("get_float2", &[], Some(Value::Text("$sizelog2".into()))); + let width = condition.add("swizzle1", &[log_size], Some(Value::Int(0))); + let threshold = condition.add_constant(Value::Float(6.0)); + condition.output = Some(condition.add("gteq", &[width, threshold], None)); + graph.nodes[3].parameters.insert("switch".into(), Value::Function(Box::new(condition))); + graph.nodes[4].parameters.insert("patterntype".into(), Value::Int(2)); + assert_eq!(cook(graph).unwrap()[0].get_gray(4, 4, false), 0.5); +} + +fn center_at_roughness(graph: PatternGraph, roughness: f32) -> f32 { + let definition = find("fx_map").unwrap(); + let parameters = resolve_params( + definition, + &BTreeMap::from([ + ("pattern".into(), Value::PatternGraph(Box::new(graph))), + ("roughness".into(), Value::Float(roughness)), + ("color_mode".into(), Value::Bool(false)), + ]), + ); + let context = CookContext { + input_formats: &[], + format: materialcraft_core::OutputFormat::F32, + w: 16, + h: 16, + seed: 0, + tile: true, + inputs: &[], + params: ¶meters, + resource: &|_| None, + vars: &BTreeMap::new(), + }; + (definition.cook)(&context).unwrap()[0].get_gray(8, 8, false) +} + +fn render_with_visit_limit(graph: &PatternGraph, limit: usize) -> crate::CookResult { + render_with_inputs_and_visit_limit(graph, &[], false, limit) +} + +fn render_with_inputs_and_visit_limit(graph: &PatternGraph, inputs: &[Option], tile: bool, limit: usize) -> crate::CookResult { + let params = resolve_params( + find("fx_map").unwrap(), + &BTreeMap::from([ + ("pattern".into(), Value::PatternGraph(Box::new(graph.clone()))), + ("roughness".into(), Value::Float(0.0)), + ("color_mode".into(), Value::Bool(false)), + ]), + ); + let context = CookContext { + w: 4, + h: 4, + seed: 19, + tile, + inputs, + input_formats: &[], + format: materialcraft_core::OutputFormat::F32, + params: ¶ms, + resource: &|_| None, + vars: &BTreeMap::new(), + }; + super::evaluation::cook_with_visit_limit(&context, &[], limit, false) +} + +#[test] +fn narrow_quadrants_only_consume_a_draw_when_their_shape_covers_a_sample() { + // At 4 by 4 the nearest sample to the lower left of center is (.375, .375). + // The thin rectangle lies between columns. Only the corner of the disc's box reaches that sample. + for (shape, size, offset) in [(2, [0.0625, 0.75], [0.0; 2]), (3, [0.25; 2], [-0.03125; 2])] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let marker = graph.add(PatternNodeKind::Quadrant).unwrap(); + let repeated = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children = vec![Some(marker), Some(repeated)]; + graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(80)); + square(&mut graph, 1); + graph.nodes[1].parameters.insert("opacity".into(), Value::Float(0.375)); + graph.nodes[2].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(shape)), + ("patternsize".into(), Value::Float2(size)), + ("frameoffset".into(), Value::Float2(offset)), + ("opacity".into(), Value::Float(0.25)), + ]); + assert_eq!(render_with_visit_limit(&graph, 64).unwrap()[0].data(), &[0.375; 16]); + + graph.nodes[2].parameters.insert("frameoffset".into(), Value::Float2([-0.125; 2])); + assert!(render_with_visit_limit(&graph, 64).unwrap_err().contains("execution budget")); + assert_eq!(render_with_visit_limit(&graph, 128).unwrap()[0].get_gray(1, 1, false), 20.375); + } +} + +#[test] +fn terminal_quadrants_charge_the_first_discard_of_each_sibling_group() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let marker = graph.add(PatternNodeKind::Quadrant).unwrap(); + let branch = graph.add(PatternNodeKind::Quadrant).unwrap(); + let leaf = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children = vec![Some(marker), Some(branch)]; + graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(48)); + square(&mut graph, 1); + graph.nodes[1].parameters.insert("opacity".into(), Value::Float(0.375)); + graph.nodes[2].children.fill(Some(leaf)); + square(&mut graph, 3); + graph.nodes[3].parameters.insert("patternsize".into(), Value::Float2([1.0 / 64.0; 2])); + + let image = render_with_visit_limit(&graph, 64).unwrap().remove(0); + for y in 0..4 { + for x in 0..4 { + assert_eq!(image.get_gray(x, y, false), 0.375); + } + } + + // Visible siblings each consume a visit, even if their pixels coincide. + let mut visible = graph.clone(); + visible.nodes[3].parameters.insert("patternsize".into(), Value::Float2([2.0; 2])); + assert!(render_with_visit_limit(&visible, 64).unwrap_err().contains("execution budget")); + + // With only one child per branch, extending the iteration still exhausts the ordinary allowances. + graph.nodes[2].children[1..].fill(None); + graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(80)); + assert!(render_with_visit_limit(&graph, 64).unwrap_err().contains("execution budget")); +} + +fn nested_square_draws(inner_count: i32) -> PatternGraph { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + for _ in 0..6 { + let parent = graph.nodes.len() - 1; + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[parent].children[0] = Some(child); + } + let outer = graph.add(PatternNodeKind::Iterate).unwrap(); + let inner = graph.add(PatternNodeKind::Iterate).unwrap(); + let square = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[6].children[0] = Some(outer); + graph.nodes[7].children[1] = Some(inner); + graph.nodes[8].children[1] = Some(square); + graph.nodes[7].parameters.insert("numberadded".into(), Value::Int(4)); + graph.nodes[8].parameters.insert("numberadded".into(), Value::Int(inner_count)); + let leaf = &mut graph.nodes[9].parameters; + leaf.insert("patterntype".into(), Value::Int(2)); + leaf.insert("patternsize".into(), Value::Float2([512.0; 2])); + leaf.insert("opacity".into(), Value::Float(0.01)); + graph +} + +#[test] +fn a_single_repeat_passes_its_written_value_and_seed_directly_to_the_child() { + let mut graph = nested_square_draws(1); + graph.nodes[7].parameters.insert("numberadded".into(), Value::Int(64)); + + let mut count = FunctionGraph::default(); + let number = count.add("get_float1", &[], Some(Value::Text("$number".into()))); + let scale = count.add_constant(Value::Float(1.0 / 128.0)); + let weight = count.add("mul", &[number, scale], None); + let write = count.add("set", &[weight], Some(Value::Text("weight".into()))); + let one = count.add_constant(Value::Int(1)); + count.output = Some(count.add("sequence", &[write, one], None)); + graph.nodes[8].parameters.insert("numberadded".into(), Value::Function(Box::new(count))); + + let mut tint = FunctionGraph::input("weight", materialcraft_core::ValueType::Float); + let gain = tint.output.unwrap(); + let span = tint.add_constant(Value::Float(0.125)); + let draw = tint.add("rand", &[span], None); + tint.output = Some(tint.add("add", &[gain, draw], None)); + graph.nodes[9].parameters.insert("opacity".into(), Value::Function(Box::new(tint))); + + let expected = render_with_visit_limit(&graph, 8192).unwrap().remove(0); + assert_eq!(expected.data(), &[f32::from_bits(1_100_931_893); 16]); + assert_eq!(render_with_visit_limit(&graph, 64).unwrap()[0].data(), expected.data()); + assert!(render_with_visit_limit(&graph, 32).unwrap_err().contains("budget")); +} + +#[test] +fn streamed_analytic_draws_keep_the_accumulated_pixels_and_bounded_work() { + let mut graph = nested_square_draws(24); + let expected = (0..96).fold(0.0_f32, |background, _| background + 0.01_f32); + assert_eq!(render_with_visit_limit(&graph, 256).unwrap()[0].data(), &[expected; 16]); + assert_eq!(render_with_visit_limit(&graph, 64).unwrap()[0].data(), &[expected; 16]); + + graph.nodes[7].parameters.insert("numberadded".into(), Value::Int(12)); + let expected = (0..288).fold(0.0_f32, |background, _| background + 0.01_f32); + assert_eq!(render_with_visit_limit(&graph, 64).unwrap()[0].data(), &[expected; 16]); + + graph.nodes[7].parameters.insert("numberadded".into(), Value::Int(20)); + assert!(render_with_visit_limit(&graph, 64).unwrap_err().contains("execution budget")); +} + +#[test] +fn streamed_squares_charge_the_tile_copies_after_the_first() { + let mut graph = nested_square_draws(21); + // Each of the 84 draws covers 12,484 horizontal copies and a single row of tiles. + // The first copy was visited with its draw, leaving 1,048,572 extra copies to rasterize. + let leaf = &mut graph.nodes[9].parameters; + leaf.insert("frameoffset".into(), Value::Float2([0.0, 0.25])); + leaf.insert("patternsize".into(), Value::Float2([12_483.0 * 128.0, 32.0])); + let image = render_with_inputs_and_visit_limit(&graph, &[], true, 64).unwrap().remove(0); + assert!(image.get_gray(1, 1, false) > 1.0); + + graph.nodes[9].parameters.insert("patternsize".into(), Value::Float2([12_485.0 * 128.0, 32.0])); + assert!(render_with_inputs_and_visit_limit(&graph, &[], true, 64).unwrap_err().contains("pattern repetition exceeds its budget")); +} + +#[test] +fn streamed_image_draws_share_their_filter_and_source_levels() { + let mut graph = nested_square_draws(35); + let source = craft_texture::Image::gray(32, 32, |x, y| ((13 * x + 29 * y + 7 * x * y + 17) % 256) as f32 / 255.0); + let inputs = [None, Some(source)]; + graph.nodes[9].parameters.insert("patterntype".into(), Value::Int(1)); + graph.nodes[9].parameters.insert("patternsize".into(), Value::Float2([96.0, 80.0])); + for filter in [0, 1, 2] { + graph.nodes[9].parameters.insert("imagefiltering".into(), Value::Int(filter)); + let expected = render_with_inputs_and_visit_limit(&graph, &inputs, false, 512).unwrap().remove(0); + let streamed = render_with_inputs_and_visit_limit(&graph, &inputs, false, 64).unwrap().remove(0); + assert_eq!(streamed.data(), expected.data()); + assert!(streamed.data().iter().any(|value| *value > 0.0)); + } + + // A different filter has a different raster rank even when both quadrants use the same slot. + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[9].children[0] = Some(child); + graph.nodes[10].parameters = graph.nodes[9].parameters.clone(); + graph.nodes[10].parameters.insert("imagefiltering".into(), Value::Int(0)); + assert!(render_with_inputs_and_visit_limit(&graph, &inputs, false, 64).unwrap_err().contains("execution budget")); +} + +#[test] +fn streamed_quadrant_children_reuse_fixed_image_properties() { + let mut graph = nested_square_draws(16); + graph.nodes[7].parameters.insert("numberadded".into(), Value::Int(8)); + graph.nodes[9].parameters.insert("patterntype".into(), Value::Int(1)); + graph.nodes[9].parameters.insert("imageindex".into(), Value::Int(1)); + graph.nodes[9].parameters.insert("randominherited".into(), Value::Bool(false)); + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[9].children.fill(Some(child)); + let mut tint = FunctionGraph::default(); + let one = tint.add_constant(Value::Float(1.0)); + tint.output = Some(tint.add("rand", &[one], None)); + graph.nodes[10].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(257)), + ("patternsize".into(), Value::Float2([512.0; 2])), + ("opacity".into(), Value::Function(Box::new(tint))), + ]); + let field = craft_texture::Image::gray(8, 8, |x, y| (1 + x + 2 * y) as f32 / 32.0); + let inputs = [None, None, Some(field)]; + let expected = render_with_inputs_and_visit_limit(&graph, &inputs, false, 2_048).unwrap().remove(0); + let streamed = render_with_inputs_and_visit_limit(&graph, &inputs, false, 64).unwrap().remove(0); + assert_eq!(streamed.data(), expected.data()); + assert!(streamed.data().iter().any(|value| *value > 1.0)); +} + +#[test] +fn seeded_placement_fields_keep_sparse_draws_within_the_work_budget() { + let mut graph = nested_square_draws(24); + let mut offset = FunctionGraph::default(); + let range = offset.add_constant(Value::Float(0.75)); + let x = offset.add("rand", &[range], None); + let y = offset.add("rand", &[range], None); + let right = offset.add_constant(Value::Float(0.0625)); + let down = offset.add_constant(Value::Float(-0.0625)); + let x = offset.add("add", &[x, right], None); + let y = offset.add("add", &[y, down], None); + let point = offset.add("vector2", &[x, y], None); + offset.output = Some(point); + + let mut rotation = FunctionGraph::default(); + let quarter = rotation.add_constant(Value::Float(0.25)); + let turn = rotation.add("rand", &[quarter], None); + let base = rotation.add_constant(Value::Float(0.125)); + rotation.output = Some(rotation.add("add", &[base, turn], None)); + let mut tint = FunctionGraph::default(); + let one = tint.add_constant(Value::Float(1.0)); + tint.output = Some(tint.add("rand", &[one], None)); + + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[9].children.fill(Some(child)); + graph.nodes[9].parameters.extend([ + ("frameoffset".into(), Value::Function(Box::new(offset.clone()))), + ("patternrotation".into(), Value::Function(Box::new(rotation))), + ("opacity".into(), Value::Function(Box::new(tint))), + ("patternsize".into(), Value::Float2([2.0, 8.0])), + ]); + graph.nodes[10].parameters = graph.nodes[9].parameters.clone(); + let mut ordinary = graph.clone(); + // The Sequence preserves both random coordinates and evaluates the offset through the full VM. + let zero = offset.add_constant(Value::Float(0.0)); + offset.output = Some(offset.add("sequence", &[zero, point], None)); + for node in &mut ordinary.nodes[9..] { + node.parameters.insert("frameoffset".into(), Value::Function(Box::new(offset.clone()))); + } + let expected = render_with_visit_limit(&ordinary, 4096).unwrap().remove(0); + assert!(expected.data().windows(2).any(|v| v[0] != v[1])); + assert!(render_with_visit_limit(&ordinary, 80).unwrap_err().contains("execution budget")); + assert_eq!(render_with_visit_limit(&graph, 80).unwrap()[0].data(), expected.data()); + assert!(render_with_visit_limit(&graph, 32).unwrap_err().contains("execution budget")); +} + +#[test] +fn repeated_image_space_offsets_and_rotations_reuse_the_parent_draw() { + let mut graph = nested_square_draws(55); + graph.nodes[7].parameters.insert("numberadded".into(), Value::Int(2)); + graph.nodes[8].parameters.insert("randominherited".into(), Value::Bool(false)); + let leaf = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[9].children.fill(Some(leaf)); + graph.nodes[10].parameters = graph.nodes[9].parameters.clone(); + for node in &mut graph.nodes[9..=10] { + let mut tint = FunctionGraph::default(); + let one = tint.add_constant(Value::Float(1.0)); + tint.output = Some(tint.add("rand", &[one], None)); + node.parameters.insert("opacity".into(), Value::Function(Box::new(tint))); + node.parameters.insert("frameoffset".into(), Value::Function(Box::new(FunctionGraph::constant(Value::Float2([0.125, -0.25]))))); + let mut angle = FunctionGraph::default(); + let quarter = angle.add_constant(Value::Float(0.25)); + angle.output = Some(angle.add("rand", &[quarter], None)); + node.parameters.insert("patternrotation".into(), Value::Function(Box::new(angle))); + } + let expected = render_with_visit_limit(&graph, 1_024).unwrap().remove(0); + let limited = render_with_visit_limit(&graph, 64).unwrap().remove(0); + assert_eq!(limited.data(), expected.data()); + assert!(limited.data().iter().any(|value| *value > 1.0)); +} + +fn quadrants_with_a_live_tint() -> (PatternGraph, PatternGraph) { + let mut graph = nested_square_draws(40); + graph.nodes[7].parameters.insert("numberadded".into(), Value::Int(6)); + graph.nodes[8].parameters.insert("randominherited".into(), Value::Bool(false)); + let mut count = FunctionGraph::default(); + let number = count.add("get_float1", &[], Some(Value::Text("$number".into()))); + let row = count.add("set", &[number], Some(Value::Text("row".into()))); + let eighth = count.add_constant(Value::Float(0.125)); + let weight = count.add("mul", &[number, eighth], None); + let gain = count.add("set", &[weight], Some(Value::Text("gain".into()))); + let forty = count.add_constant(Value::Int(40)); + let finish = count.add("sequence", &[gain, forty], None); + count.output = Some(count.add("sequence", &[row, finish], None)); + graph.nodes[8].parameters.insert("numberadded".into(), Value::Function(Box::new(count))); + + let leaf = graph.add(PatternNodeKind::Quadrant).unwrap(); + let marker = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[9].children = vec![Some(leaf), Some(leaf), Some(leaf), Some(marker)]; + let mut tint = FunctionGraph::default(); + let width = tint.add_constant(Value::Float(1.0 / 128.0)); + let shift = tint.add("rand", &[width], None); + let corner = tint.add_constant(Value::Float(0.118)); + let shift = tint.add("add", &[corner, shift], None); + let position = tint.add("vector2", &[shift, shift], None); + let publish = tint.add("set", &[position], Some(Value::Text("placed".into()))); + let one = tint.add_constant(Value::Float(1.0)); + let base = tint.add("rand", &[one], None); + let gain = tint.add("get_float1", &[], Some(Value::Text("gain".into()))); + let scaled = tint.add("mul", &[base, gain], None); + let row = tint.add("get_float1", &[], Some(Value::Text("row".into()))); + let threshold = tint.add_constant(Value::Float(1.5)); + let test = tint.add("gt", &[row, threshold], None); + let alpha = tint.add("ifelse", &[test, scaled, base], None); + tint.output = Some(tint.add("sequence", &[publish, alpha], None)); + let offset = FunctionGraph::input("placed", materialcraft_core::ValueType::Float2); + for node in &mut graph.nodes[9..] { + node.parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(2)), + ("frameoffset".into(), Value::Function(Box::new(offset.clone()))), + ("patternsize".into(), Value::Float2([1.0; 2])), + ]); + } + for node in &mut graph.nodes[9..11] { + node.parameters.insert("opacity".into(), Value::Function(Box::new(tint.clone()))); + } + graph.nodes[11].parameters.insert("opacity".into(), Value::Float(0.25)); + + // This equivalent computed offset reads the published value through the full evaluator. + let mut ordinary = graph.clone(); + let mut computed = offset; + let link = computed.output.unwrap(); + let zero = computed.add_constant(Value::Float2([0.0; 2])); + computed.output = Some(computed.add("add", &[link, zero], None)); + for node in &mut ordinary.nodes[9..11] { + node.parameters.insert("frameoffset".into(), Value::Function(Box::new(computed.clone()))); + } + (graph, ordinary) +} + +#[test] +fn repeated_quadrants_reapply_the_live_tint_scale_and_publish_the_frame_offset() { + let (mut graph, mut ordinary) = quadrants_with_a_live_tint(); + let expected = render_with_visit_limit(&ordinary, 4096).unwrap().remove(0); + assert!(expected.data().iter().any(|&v| v > 1.0)); + assert!(render_with_visit_limit(&ordinary, 192).unwrap_err().contains("execution budget")); + let cached = render_with_visit_limit(&graph, 192).unwrap().remove(0); + assert_eq!(cached.data(), expected.data()); + + // Inheriting the outer seed gives different random offsets and tints on later + // iterations. A bound arithmetic pass keeps the offset, gain and every draw. + for drawing in [&mut graph, &mut ordinary] { + drawing.nodes[8].parameters.insert("randominherited".into(), Value::Bool(true)); + } + let expected = render_with_visit_limit(&ordinary, 4096).unwrap().remove(0); + assert!(expected.data().iter().any(|&v| v > 1.0)); + assert_eq!(render_with_visit_limit(&graph, 96).unwrap()[0].data(), expected.data()); + graph.nodes[7].parameters.insert("numberadded".into(), Value::Int(10)); + assert!(render_with_visit_limit(&graph, 96).unwrap_err().contains("execution budget")); +} + +#[test] +fn reused_terminal_offsets_and_compact_parent_draws_share_bounded_work() { + let (mut graph, mut ordinary) = quadrants_with_a_live_tint(); + for drawing in [&mut graph, &mut ordinary] { + drawing.nodes[8].parameters.insert("randominherited".into(), Value::Bool(true)); + // Three additional branches inherit distinct seeds. Their terminal children + // reset theirs, so the same offset is published again in a different parent. + let branch = drawing.add(PatternNodeKind::Quadrant).unwrap(); + drawing.nodes[12].parameters = drawing.nodes[10].parameters.clone(); + drawing.nodes[12].children = drawing.nodes[9].children.clone(); + drawing.nodes[9].children[..3].fill(Some(branch)); + drawing.nodes[10].parameters.insert("randominherited".into(), Value::Bool(false)); + } + let expected = render_with_visit_limit(&ordinary, 65_536).unwrap().remove(0); + assert!(expected.data().iter().any(|value| *value > 1.0)); + assert_eq!(render_with_visit_limit(&graph, 256).unwrap()[0].data(), expected.data()); + assert!(render_with_visit_limit(&graph, 160).unwrap_err().contains("execution budget")); +} + +#[test] +fn a_seeded_branch_offset_keeps_every_scheduled_child() { + let mut graph = nested_square_draws(32); + let leaf = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[9].children[0] = Some(leaf); + graph.nodes[9].parameters.clear(); + let mut offset = FunctionGraph::default(); + let span = offset.add_constant(Value::Float(0.875)); + let x = offset.add("rand", &[span], None); + let y = offset.add("rand", &[span], None); + offset.output = Some(offset.add("vector2", &[x, y], None)); + graph.nodes[9].parameters.insert("branchoffset".into(), Value::Function(Box::new(offset.clone()))); + graph.nodes[10].parameters = + BTreeMap::from([("patterntype".into(), Value::Int(2)), ("patternsize".into(), Value::Float2([96.0, 48.0])), ("opacity".into(), Value::Float(0.125))]); + let mut ordinary = graph.clone(); + // An equivalent Sequence uses the general evaluator and leaves the random stream intact. + let value = offset.output.unwrap(); + let zero = offset.add_constant(Value::Float(0.0)); + offset.output = Some(offset.add("sequence", &[zero, value], None)); + ordinary.nodes[9].parameters.insert("branchoffset".into(), Value::Function(Box::new(offset))); + let expected = render_with_visit_limit(&ordinary, 8192).unwrap().remove(0); + assert!(expected.data().windows(2).any(|v| v[0] != v[1])); + assert!(render_with_visit_limit(&ordinary, 64).unwrap_err().contains("execution budget")); + assert_eq!(render_with_visit_limit(&graph, 64).unwrap()[0].data(), expected.data()); + assert!(render_with_visit_limit(&graph, 32).unwrap_err().contains("execution budget")); +} + +#[test] +fn sparse_branch_offsets_and_tints_reuse_properties_across_drawing_depths() { + let mut graph = nested_square_draws(40); + graph.nodes[8].parameters.insert("randominherited".into(), Value::Bool(false)); + for parent in [9, 10] { + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[parent].children.fill(Some(child)); + } + let mut tint = FunctionGraph::default(); + let one = tint.add_constant(Value::Float(1.0)); + tint.output = Some(tint.add("rand", &[one], None)); + let offset = FunctionGraph::constant(Value::Float2([1.0 / 4096.0, -1.0 / 4096.0])); + for node in &mut graph.nodes[9..=11] { + node.parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(3)), + ("branchoffset".into(), Value::Function(Box::new(offset.clone()))), + ("opacity".into(), Value::Function(Box::new(tint.clone()))), + ("frameoffset".into(), Value::Float2([0.125 - 1.0 / 256.0; 2])), + ("patternsize".into(), Value::Float2([1.0; 2])), + ]); + } + let expected = render_with_visit_limit(&graph, 8_192).unwrap().remove(0); + let limited = render_with_visit_limit(&graph, 384).unwrap().remove(0); + assert_eq!(limited.data(), expected.data()); + assert!(limited.data().iter().any(|v| *v > 0.0)); + assert!(limited.data().contains(&0.0)); +} + +#[test] +fn cached_branch_tints_keep_their_drawing_depth_and_stamp_size() { + let fixed = FunctionGraph::constant(Value::Float(0.75)); + let depth = FunctionGraph::input("$depth", materialcraft_core::ValueType::Float); + for (expression, luminosities) in [(fixed, [0.75, 0.75]), (depth, [0.0, 1.0])] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children[0] = Some(child); + for node in &mut graph.nodes { + node.parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(2)), + ("randominherited".into(), Value::Bool(false)), + ("patternsize".into(), Value::Float2([1.0; 2])), + ("branchoffset".into(), Value::Function(Box::new(FunctionGraph::constant(Value::Float2([0.0; 2]))))), + ("opacity".into(), Value::Function(Box::new(expression.clone()))), + ]); + } + let mut literal = graph.clone(); + for (node, value) in literal.nodes.iter_mut().zip(luminosities) { + node.parameters.insert("branchoffset".into(), Value::Float2([0.0; 2])); + node.parameters.insert("opacity".into(), Value::Float(value)); + } + let expected = render_with_visit_limit(&literal, 64).unwrap().remove(0); + let actual = render_with_visit_limit(&graph, 64).unwrap().remove(0); + assert!(expected.data().iter().any(|v| *v > 0.0)); + assert_eq!(actual.data(), expected.data()); + } +} + +#[test] +fn cached_parents_that_miss_still_draw_their_terminal_children() { + let mut graph = nested_square_draws(41); + graph.nodes[8].parameters.insert("randominherited".into(), Value::Bool(false)); + let leaf = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[9].children.fill(Some(leaf)); + graph.nodes[10].parameters = graph.nodes[9].parameters.clone(); + // At this depth the parent falls between pixel centers. Its four children cover the image. + graph.nodes[9].parameters.insert("patternsize".into(), Value::Float2([0.015625; 2])); + for node in &mut graph.nodes[9..=10] { + let mut tint = FunctionGraph::default(); + let one = tint.add_constant(Value::Float(1.0)); + tint.output = Some(tint.add("rand", &[one], None)); + node.parameters.insert("opacity".into(), Value::Function(Box::new(tint))); + } + let expected = render_with_visit_limit(&graph, 1_024).unwrap().remove(0); + assert!(expected.data().iter().all(|value| *value > 1.0)); + assert_eq!(render_with_visit_limit(&graph, 64).unwrap()[0].data(), expected.data()); + + graph.nodes[7].parameters.insert("numberadded".into(), Value::Int(10)); + assert!(render_with_visit_limit(&graph, 64).unwrap_err().contains("execution budget")); +} + +#[test] +fn repeated_quadrants_keep_both_translations_when_reusing_a_draw() { + let mut graph = nested_square_draws(41); + graph.nodes[8].parameters.insert("randominherited".into(), Value::Bool(false)); + let leaf = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[9].children.fill(Some(leaf)); + graph.nodes[10].parameters = graph.nodes[9].parameters.clone(); + graph.nodes[9].parameters.insert("patternsize".into(), Value::Float2([0.015625; 2])); + for node in &mut graph.nodes[9..] { + let mut angle = FunctionGraph::default(); + let eighth = angle.add_constant(Value::Float(0.125)); + angle.output = Some(angle.add("rand", &[eighth], None)); + node.parameters.insert("patternrotation".into(), Value::Function(Box::new(angle))); + for (field, offset) in [("branchoffset", [0.03125, -0.015625]), ("frameoffset", [-0.015625, 0.03125])] { + node.parameters.insert(field.into(), Value::Function(Box::new(FunctionGraph::constant(Value::Float2(offset))))); + } + } + let expected = render_with_visit_limit(&graph, 1_024).unwrap().remove(0); + assert!(expected.data().iter().any(|value| *value > 0.0)); + // A smaller budget still stops the four repetitions of 41 parent draws. + assert!(render_with_visit_limit(&graph, 64).unwrap_err().contains("execution budget")); + assert_eq!(render_with_visit_limit(&graph, 128).unwrap()[0].data(), expected.data()); +} + +#[test] +fn repeated_terminal_misses_cover_uncached_misses_in_the_next_branch() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let marker = graph.add(PatternNodeKind::Quadrant).unwrap(); + let pair = graph.add(PatternNodeKind::Quadrant).unwrap(); + let first = graph.add(PatternNodeKind::Quadrant).unwrap(); + let second = graph.add(PatternNodeKind::Quadrant).unwrap(); + let cached = graph.add(PatternNodeKind::Quadrant).unwrap(); + let uncached = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children = vec![Some(marker), Some(pair)]; + graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(34)); + square(&mut graph, 1); + graph.nodes[1].parameters.insert("opacity".into(), Value::Float(0.375)); + graph.nodes[2].children = vec![Some(first), Some(second), None, None]; + graph.nodes[3].children.fill(Some(cached)); + graph.nodes[4].children.fill(Some(uncached)); + for node in &mut graph.nodes[3..] { + node.parameters.insert("patterntype".into(), Value::Int(2)); + node.parameters.insert("patternsize".into(), Value::Float2([0.015625; 2])); + } + // Both sets of leaves fall between sample centers. Only the first set can reuse its properties. + for node in &mut graph.nodes[5..] { + node.parameters.insert("frameoffset".into(), Value::Float2([0.0625; 2])); + } + let mut tint = FunctionGraph::default(); + let gain = tint.add_constant(Value::Float(0.5)); + tint.output = Some(tint.add("rand", &[gain], None)); + graph.nodes[5].parameters.insert("randominherited".into(), Value::Bool(false)); + graph.nodes[5].parameters.insert("opacity".into(), Value::Function(Box::new(tint))); + assert_eq!(render_with_visit_limit(&graph, 64).unwrap()[0].data(), &[0.375; 16]); + + // The cached leaf still pays for every retained draw when moved onto the samples. + graph.nodes[5].parameters.insert("frameoffset".into(), Value::Float2([0.0; 2])); + assert!(render_with_visit_limit(&graph, 64).unwrap_err().contains("execution budget")); +} + +#[test] +fn repeated_terminal_properties_leave_room_for_their_visible_siblings() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let marker = graph.add(PatternNodeKind::Quadrant).unwrap(); + let parent = graph.add(PatternNodeKind::Quadrant).unwrap(); + let leaf = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children = vec![Some(marker), Some(parent)]; + graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(100)); + square(&mut graph, 1); + graph.nodes[1].parameters.insert("opacity".into(), Value::Float(0.375)); + graph.nodes[2].children.fill(Some(leaf)); + for i in [2, 3] { + square(&mut graph, i); + graph.nodes[i].parameters.insert("patternsize".into(), Value::Float2([1.0 / 64.0; 2])); + } + let mut tint = FunctionGraph::default(); + let scale = tint.add("const_float1", &[], Some(Value::Float(0.5))); + tint.output = Some(tint.add("rand", &[scale], None)); + graph.nodes[3].parameters.insert("opacity".into(), Value::Function(Box::new(tint))); + graph.nodes[3].parameters.insert("randominherited".into(), Value::Bool(false)); + + let image = render_with_visit_limit(&graph, 64).unwrap().remove(0); + assert_eq!(image.data(), &[0.375; 16]); + + let mut positioned = graph.clone(); + let mut position = FunctionGraph::default(); + position.output = Some(position.add("get_float2", &[], Some(Value::Text("$pos".into())))); + positioned.nodes[3].parameters.insert("frameoffset".into(), Value::Function(Box::new(position))); + assert!(render_with_visit_limit(&positioned, 64).unwrap_err().contains("execution budget")); + + let mut writable = graph.clone(); + let mut write = FunctionGraph::default(); + let gain = write.add("const_float1", &[], Some(Value::Float(0.5))); + write.output = Some(write.add("set", &[gain], Some(Value::Text("gain".into())))); + writable.nodes[2].parameters.insert("opacity".into(), Value::Function(Box::new(write))); + let mut read = FunctionGraph::default(); + read.output = Some(read.add("get_float1", &[], Some(Value::Text("gain".into())))); + writable.nodes[3].parameters.insert("opacity".into(), Value::Function(Box::new(read))); + assert!(render_with_visit_limit(&writable, 64).unwrap_err().contains("execution budget")); + + // Reusing a tint does not make a visible stamp free. + graph.nodes[3].parameters.insert("patternsize".into(), Value::Float2([2.0; 2])); + assert!(render_with_visit_limit(&graph, 64).unwrap_err().contains("execution budget")); +} + +#[test] +fn empty_terminal_quadrants_share_the_discard_allowance() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let marker = graph.add(PatternNodeKind::Quadrant).unwrap(); + let parent = graph.add(PatternNodeKind::Quadrant).unwrap(); + let empty = graph.add(PatternNodeKind::Quadrant).unwrap(); + let gate = graph.add(PatternNodeKind::Switch).unwrap(); + let live = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children = vec![Some(marker), Some(parent)]; + graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(24)); + square(&mut graph, 1); + graph.nodes[1].parameters.insert("opacity".into(), Value::Float(0.375)); + graph.nodes[2].children.fill(Some(empty)); + graph.nodes[3].children[0] = Some(gate); + graph.nodes[4].children[1] = Some(live); + square(&mut graph, 5); + + let image = render_with_visit_limit(&graph, 64).unwrap().remove(0); + for y in 0..4 { + for x in 0..4 { + assert_eq!(image.get_gray(x, y, false), 0.375); + } + } + + graph.nodes[4].parameters.insert("switch".into(), Value::Bool(true)); + assert!(render_with_visit_limit(&graph, 64).unwrap_err().contains("execution budget")); + graph.nodes[4].parameters.insert("switch".into(), Value::Bool(false)); + graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(80)); + assert!(render_with_visit_limit(&graph, 64).unwrap_err().contains("execution budget")); +} + +#[test] +fn empty_switches_at_later_depths_still_affect_roughness() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let empty = graph.add(PatternNodeKind::Switch).unwrap(); + let deeper = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].parameters.insert("patterntype".into(), Value::Int(2)); + graph.nodes[0].children = vec![Some(empty), None, None, Some(deeper)]; + graph.nodes[2].children[3] = Some(empty); + assert_eq!(center_at_roughness(graph, 1.0), 1.0 / 3.0); +} + +#[test] +fn connected_quadrants_set_roughness_even_when_their_branch_is_idle() { + for kind in [PatternNodeKind::Switch, PatternNodeKind::Iterate] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let gate = graph.add(kind).unwrap(); + let middle = graph.add(PatternNodeKind::Quadrant).unwrap(); + let leaf = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].parameters.insert("patterntype".into(), Value::Int(2)); + graph.nodes[0].children[0] = Some(gate); + graph.nodes[1].children[1] = Some(middle); + graph.nodes[2].children[3] = Some(leaf); + for enabled in [false, true] { + if kind == PatternNodeKind::Switch { + graph.nodes[1].parameters.insert("switch".into(), Value::Bool(enabled)); + } else { + graph.nodes[1].parameters.insert("numberadded".into(), Value::Int(i32::from(enabled))); + } + assert_eq!(center_at_roughness(graph.clone(), 1.0), 1.0 / 3.0); + assert_eq!(center_at_roughness(graph.clone(), 0.6), 0.510_204_1); + } + graph.nodes[0].children[0] = None; + assert_eq!(center_at_roughness(graph, 0.6), 1.0); + } +} + +#[test] +fn missing_direct_pattern_inputs_use_the_field_default() { + use materialcraft_core::ValueType; + + let direct = FunctionGraph::input("strength", ValueType::Float); + let mut derived = direct.clone(); + let read = derived.output.unwrap(); + let offset = derived.add_constant(Value::Float(0.375)); + derived.output = Some(derived.add("add", &[read, offset], None)); + for (expression, binding, expected) in [ + (direct.clone(), None, 1.0), + (direct.clone(), Some(0.0), 0.0), + (direct, Some(0.375), 0.375), + (derived, None, 0.375), + (FunctionGraph::input("tint", ValueType::Float4), None, 1.0), + ] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters = BTreeMap::from([("patterntype".into(), Value::Int(2)), ("opacity".into(), Value::Function(Box::new(expression)))]); + let vars = binding.map(|v| ("strength".into(), Value::Float(v))).into_iter().collect(); + let image = cook_with_variables(graph, &vars, 7).unwrap().remove(0); + assert_eq!(image.get_gray(8, 8, false), expected); + } + + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let square = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children[1] = Some(square); + graph.nodes[0].parameters.insert("numberadded".into(), Value::Function(Box::new(FunctionGraph::input("count", ValueType::Integer)))); + graph.nodes[1].parameters.insert("patterntype".into(), Value::Int(2)); + graph.nodes[1].parameters.insert("patternsize".into(), Value::Function(Box::new(FunctionGraph::input("extent", ValueType::Float2)))); + assert!(cook(graph).unwrap()[0].data().iter().all(|&value| value == 1.0)); +} + +#[test] +fn a_sibling_can_update_a_binding_declared_by_the_parent() { + use materialcraft_core::ValueType; + + for (published, initialized, writer_first, expected) in + [(None, false, true, 1.0), (Some(0.25), false, true, 0.25), (Some(0.25), true, true, 0.75), (None, true, true, 0.75), (Some(0.25), true, false, 0.5625)] + { + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let writer = graph.add(PatternNodeKind::Quadrant).unwrap(); + let reader = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children = if writer_first { vec![Some(writer), Some(reader)] } else { vec![Some(reader), Some(writer)] }; + if initialized { + graph.nodes[0].parameters.insert("numberadded".into(), set_then_return("tint", Value::Float(0.5625), Value::Int(1))); + } + graph.nodes[1].parameters.insert("patterntype".into(), Value::Int(2)); + graph.nodes[1].parameters.insert("opacity".into(), set_then_return("tint", Value::Float(0.75), Value::Float(0.0))); + graph.nodes[2].parameters.insert("patterntype".into(), Value::Int(2)); + graph.nodes[2].parameters.insert("opacity".into(), Value::Function(Box::new(FunctionGraph::input("tint", ValueType::Float)))); + let variables = published.map(|v| ("tint".into(), Value::Float(v))).into_iter().collect(); + let image = cook_with_variables(graph, &variables, 17).unwrap().remove(0); + assert_eq!(image.get_gray(8, 8, false), expected, "published {published:?}, initialized {initialized}, writer first {writer_first}"); + } +} + +fn advance_tree_offset() -> Value { + let mut advance = FunctionGraph::default(); + let index = advance.add("get_float1", &[], Some(Value::Text("tree_index".into()))); + let one = advance.add_constant(Value::Float(1.0)); + let next = advance.add("add", &[index, one], None); + let stored = advance.add("set", &[next], Some(Value::Text("tree_index".into()))); + let origin = advance.add_constant(Value::Float2([0.0; 2])); + advance.output = Some(advance.add("sequence", &[stored, origin], None)); + Value::Function(Box::new(advance)) +} + +fn set_then_return(name: &str, value: Value, result: Value) -> Value { + let mut function = FunctionGraph::default(); + let value = function.add_constant(value); + let set = function.add("set", &[value], Some(Value::Text(name.into()))); + let result = function.add_constant(result); + function.output = Some(function.add("sequence", &[set, result], None)); + Value::Function(Box::new(function)) +} + +#[test] +fn first_writable_float_depends_on_connected_draw_properties() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let writer = graph.add(PatternNodeKind::Quadrant).unwrap(); + let switch = graph.add(PatternNodeKind::Switch).unwrap(); + let other = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children = vec![Some(writer), Some(writer), Some(writer), Some(switch)]; + graph.nodes[2].children[0] = Some(writer); + square(&mut graph, 1); + + let mut field = FunctionGraph::input("local", materialcraft_core::ValueType::Float); + let current = field.output.unwrap(); + let defined = field.add("eq", &[current, current], None); + let yes = field.add_constant(Value::Float(0.375)); + let no = field.add_constant(Value::Float(0.625)); + let next = field.add("ifelse", &[defined, yes, no], None); + field.output = Some(field.add("set", &[next], Some(Value::Text("local".into())))); + graph.nodes[1].parameters.insert("opacity".into(), Value::Function(Box::new(field))); + let published = FunctionGraph::input("gain", materialcraft_core::ValueType::Float); + graph.nodes[3].parameters.insert("opacity".into(), Value::Function(Box::new(published))); + let bindings = BTreeMap::from([("gain".into(), Value::Float(0.8125))]); + for (connected, shape, first) in [(false, 2, 0.375), (true, 0, 0.375), (true, 2, 0.625)] { + graph.nodes[2].children[1] = connected.then_some(other); + graph.nodes[3].parameters.insert("patterntype".into(), Value::Int(shape)); + let image = cook_with_variables(graph.clone(), &bindings, 41301).unwrap().remove(0); + for (x, y, expected) in [(4, 4, first), (12, 4, 0.375), (4, 12, 0.375), (12, 12, 0.375)] { + assert_eq!(image.get_gray(x, y, false), expected, "connected {connected}, shape {shape}, pixel ({x}, {y})"); + } + } +} + +#[test] +fn quadrant_children_accumulate_in_their_own_depth() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let writer = graph.add(PatternNodeKind::Quadrant).unwrap(); + let reader = graph.add(PatternNodeKind::Quadrant).unwrap(); + let increment = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children = vec![Some(writer), Some(reader), Some(increment), Some(increment)]; + graph.nodes[0].parameters.insert("branchoffset".into(), set_then_return("count", Value::Float(0.25), Value::Float2([0.0; 2]))); + for node in 1..=3 { + square(&mut graph, node); + } + graph.nodes[1].parameters.insert("opacity".into(), set_then_return("count", Value::Float(0.8125), Value::Float(0.8125))); + let read = FunctionGraph::input("count", materialcraft_core::ValueType::Float); + graph.nodes[2].parameters.insert("opacity".into(), Value::Function(Box::new(read.clone()))); + + let mut counter = read; + let current = counter.output.unwrap(); + let step = counter.add_constant(Value::Float(0.0625)); + let next = counter.add("add", &[current, step], None); + counter.output = Some(counter.add("set", &[next], Some(Value::Text("count".into())))); + graph.nodes[3].parameters.insert("opacity".into(), Value::Function(Box::new(counter))); + + let image = cook(graph).unwrap().remove(0); + for (x, y, expected) in [(4, 4, 0.8125), (12, 4, 0.25), (4, 12, 0.875), (12, 12, 0.9375)] { + assert_eq!(image.get_gray(x, y, false), expected); + } +} + +#[test] +fn six_level_quadrant_children_start_independent_counters() { + for depth in [5, 6] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + for level in 0..depth { + let next = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[level].children.fill(Some(next)); + } + square(&mut graph, depth); + let mut counter = FunctionGraph::input("count", materialcraft_core::ValueType::Float); + let previous = counter.output.unwrap(); + let step = counter.add_constant(Value::Float(1.0 / 4096.0)); + let next = counter.add("add", &[previous, step], None); + counter.output = Some(counter.add("set", &[next], Some(Value::Text("count".into())))); + graph.nodes[depth].parameters.insert("opacity".into(), Value::Function(Box::new(counter))); + + let side = 1 << depth; + let image = cook_at_size(graph, &BTreeMap::new(), 598241, side).unwrap().remove(0); + let half = i64::from(side / 2); + for slot in 0..4 { + let x = slot % 2 * half; + let y = slot / 2 * half; + let first = if depth == 5 { 256 * slot + 1 } else { 1 }; + assert_eq!(image.get_gray(x, y, false), first as f32 / 4096.0, "depth {depth}, child {slot}"); + assert_eq!(image.get_gray(x + 1, y, false), (first + 1) as f32 / 4096.0); + } + } +} + +#[test] +fn quadrant_modes_read_published_inputs_and_shadow_outer_pattern_bindings() { + use materialcraft_core::ValueType; + + let direct = FunctionGraph::input("form", ValueType::Integer); + let mut add_two = direct.clone(); + let read = add_two.output.unwrap(); + let two = add_two.add_constant(Value::Int(2)); + add_two.output = Some(add_two.add("add", &[read, two], None)); + for (shadowed, expression, expected_corner) in [(false, direct.clone(), 1.0), (true, direct, 0.0), (true, add_two, 1.0)] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children[0] = Some(child); + if shadowed { + graph.nodes[0].parameters.insert("numberadded".into(), set_then_return("form", Value::Int(3), Value::Int(0))); + } + graph.nodes[1].parameters.insert("patterntype".into(), Value::Function(Box::new(expression))); + let image = cook_with_variables(graph, &BTreeMap::from([("form".into(), Value::Int(2))]), 17).unwrap().remove(0); + assert_eq!(image.get_gray(0, 0, false), expected_corner, "shadowed {shadowed}"); + if expected_corner == 0.0 { + assert_eq!(image.get_gray(8, 8, false), 0.0); + } + } +} + +#[test] +fn a_quadrant_mode_evaluates_before_it_has_a_traversal_depth() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children[0] = Some(child); + let mut shape = FunctionGraph::default(); + let extent = shape.add("get_float1", &[], Some(Value::Text("$depthpow2".into()))); + let threshold = shape.add_constant(Value::Float(0.25)); + let test = shape.add("gt", &[extent, threshold], None); + let disc = shape.add_constant(Value::Int(3)); + let square = shape.add_constant(Value::Int(2)); + shape.output = Some(shape.add("ifelse", &[test, disc, square], None)); + graph.nodes[1].parameters.insert("patterntype".into(), Value::Function(Box::new(shape))); + + let image = cook(graph).unwrap().remove(0); + assert_eq!(image.get_gray(0, 0, false), 1.0); +} + +#[test] +fn a_quadrant_only_publishes_writes_from_active_stamp_properties() { + for (pattern, property, result, expected) in [ + (0, "opacity", Value::Float(0.0), 0.125), + (0, "branchoffset", Value::Float2([0.0; 2]), 0.75), + (2, "opacity", Value::Float(0.0), 0.75), + (2, "imageindex", Value::Int(0), 0.125), + (2, "patterntype", Value::Int(2), 0.125), + (2, "blendingmode", Value::Int(0), 0.125), + (1, "imagefiltering", Value::Int(1), 0.125), + (1, "imagepremul", Value::Bool(true), 0.125), + (2, "randominherited", Value::Bool(true), 0.125), + ] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children[0] = Some(child); + let parent = &mut graph.nodes[0].parameters; + parent.insert("patterntype".into(), Value::Int(pattern)); + parent.insert("opacity".into(), Value::Float(0.0)); + let mut expression = FunctionGraph::default(); + let value = expression.add_constant(Value::Float(0.75)); + let write = expression.add("set", &[value], Some(Value::Text("marker".into()))); + let result = expression.add_constant(result); + expression.output = Some(expression.add("sequence", &[write, result], None)); + parent.insert(property.into(), Value::Function(Box::new(expression))); + graph.nodes[1].parameters.insert("patterntype".into(), Value::Int(2)); + graph.nodes[1].parameters.insert("opacity".into(), Value::Function(Box::new(FunctionGraph::input("marker", materialcraft_core::ValueType::Float)))); + let image = cook_with_variables(graph, &BTreeMap::from([("marker".into(), Value::Float(0.125))]), 19).unwrap().remove(0); + assert_eq!(image.get_gray(3, 3, false), expected, "pattern {pattern}, property {property}"); + } +} + +#[test] +fn an_empty_switch_still_runs_its_seed_assignment() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let repeat = graph.add(PatternNodeKind::Iterate).unwrap(); + let empty = graph.add(PatternNodeKind::Switch).unwrap(); + let mark = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children = vec![Some(repeat), Some(repeat), Some(mark), None]; + graph.nodes[1].parameters.insert("numberadded".into(), Value::Int(2)); + graph.nodes[1].children[1] = Some(empty); + let mut advance = FunctionGraph::default(); + let count = advance.add("get_float1", &[], Some(Value::Text("count".into()))); + let quarter = advance.add_constant(Value::Float(0.25)); + let next = advance.add("add", &[count, quarter], None); + let set = advance.add("set", &[next], Some(Value::Text("count".into()))); + let zero = advance.add_constant(Value::Int(0)); + advance.output = Some(advance.add("sequence", &[set, zero], None)); + graph.nodes[2].parameters.insert("randomseed".into(), Value::Function(Box::new(advance))); + graph.nodes[3].parameters.insert("patterntype".into(), Value::Int(2)); + graph.nodes[3].parameters.insert("opacity".into(), Value::Function(Box::new(FunctionGraph::input("count", materialcraft_core::ValueType::Float)))); + assert_eq!(cook(graph).unwrap()[0].get_gray(3, 11, false), 1.0); +} + #[test] fn iterate_preserves_assignments_from_previous_iterations() { let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); @@ -104,6 +3126,152 @@ fn iterate_preserves_assignments_from_previous_iterations() { assert!(image.data().iter().all(|value| *value == 6.0), "expected 1 + 2 + 3, got {:?}", image.mean()); } +#[test] +fn an_iterate_keeps_the_initial_seed_and_advances_each_repetition() { + for (slot, count, expected) in [(0, 1, 0x3f042a5e), (1, 1, 0x3f1abd9c), (1, 2, 0x3f2b7424)] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children[slot] = Some(child); + graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(count)); + let params = &mut graph.nodes[1].parameters; + params.insert("patterntype".into(), Value::Int(2)); + params.insert("blendingmode".into(), Value::Int(2)); + let mut draw = FunctionGraph::default(); + let one = draw.add_constant(Value::Float(1.0)); + draw.output = Some(draw.add("rand", &[one], None)); + params.insert("opacity".into(), Value::Function(Box::new(draw))); + let image = cook(graph).unwrap().remove(0); + assert_eq!(image.get(8, 8, false)[0].to_bits(), expected); + } +} + +#[test] +fn driven_scalar_arithmetic_in_an_iterate_seed_uses_storage_words() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let square = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children[1] = Some(square); + graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(1)); + let mut tint = FunctionGraph::default(); + let unit = tint.add_constant(Value::Float(1.0)); + tint.output = Some(tint.add("rand", &[unit], None)); + graph.nodes[1].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(2)), + ("blendingmode".into(), Value::Int(0)), + ("patternsize".into(), Value::Float2([1.0; 2])), + ("opacity".into(), Value::Function(Box::new(tint))), + ]); + + let cases = [ + (0.0, 1.0, 0, [16, 16]), + (1.0, 0.5, 845872, [16, 32]), + (3.0, 0.75, 113, [32, 16]), + (5.25, 0.5, 845872, [16, 16]), + (17.0, 1.0, 42, [16, 32]), + (-1.25, -0.5, 37, [32, 16]), + ]; + for (expression, expected) in [ + ("cast", [0x3f4bd028, 0x3f2676b8, 0x3ef06e34, 0x3f833b5c, 0x3f7d60e6, 0x3ee3256c]), + ("float sum", [0x3e97a050, 0x3f2676b8, 0x3e60dc68, 0x3f5e76b8, 0x3f6560e6, 0x3ea3256c]), + ("integer sum", [0x3e97a050, 0x3f2676b8, 0x3ef06e34, 0x3f833b5c, 0x3efac1cc, 0x3f7192b6]), + ] { + let mut seed = FunctionGraph::default(); + let first = seed.add("get_float1", &[], Some(Value::Text("first".into()))); + let second = seed.add("get_float1", &[], Some(Value::Text("second".into()))); + seed.output = Some(match expression { + "float sum" => { + let sum = seed.add("add", &[first, second], None); + seed.add("toint1", &[sum], None) + } + "integer sum" => { + let left = seed.add("toint1", &[first], None); + let right = seed.add("toint1", &[second], None); + seed.add("add", &[left, right], None) + } + _ => seed.add("toint1", &[first], None), + }); + graph.nodes[0].parameters.insert("randomseed".into(), Value::Function(Box::new(seed))); + for ((first, second, parent_seed, size), bits) in cases.into_iter().zip(expected) { + let vars = BTreeMap::from([("first".into(), Value::Float(first)), ("second".into(), Value::Float(second))]); + let image = cook_in_regions(graph.clone(), &vars, parent_seed, size, [[0.0, 1.0, 0.0, 1.0]; 2], 0.125).unwrap().remove(0); + assert_eq!(image.get_gray(8, 8, false).to_bits(), bits, "{expression}, {first}, {second}"); + } + } +} + +#[test] +fn a_pattern_seed_expression_runs_before_the_stamp_properties() { + let mut seed = FunctionGraph::default(); + let one = seed.add_constant(Value::Float(1.0)); + let draw = seed.add("rand", &[one], None); + let save = seed.add("set", &[draw], Some(Value::Text("seed_draw".into()))); + let local = seed.add_constant(Value::Int(43)); + seed.output = Some(seed.add("sequence", &[save, local], None)); + for (inherits, scope_value, expected) in [(true, false, 0x3f4fd146), (false, false, 0x3e98dd54), (true, true, 0x3ed93158), (false, true, 0x3ed93158)] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let params = &mut graph.nodes[0].parameters; + params.insert("randominherited".into(), Value::Bool(inherits)); + params.insert("randomseed".into(), Value::Function(Box::new(seed.clone()))); + params.insert("patterntype".into(), Value::Int(2)); + let mut opacity = FunctionGraph::default(); + let one = opacity.add_constant(Value::Float(1.0)); + opacity.output = + Some(if scope_value { opacity.add("get_float1", &[], Some(Value::Text("seed_draw".into()))) } else { opacity.add("rand", &[one], None) }); + params.insert("opacity".into(), Value::Function(Box::new(opacity))); + let image = cook_with_variables(graph, &BTreeMap::new(), 7).unwrap().remove(0); + assert_eq!(image.get(8, 8, false)[0].to_bits(), expected); + } +} + +#[test] +fn a_pattern_uses_the_seed_without_exposing_a_variable_for_it() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let params = &mut graph.nodes[0].parameters; + params.insert("patterntype".into(), Value::Int(2)); + params.insert("randomseed".into(), Value::Int(43)); + let mut opacity = FunctionGraph::default(); + let variable = Value::Text("$randomseed".into()); + let exists = opacity.add("isdefined", &[], Some(variable.clone())); + let value = opacity.add("get_integer1", &[], Some(variable)); + let numeric = opacity.add("tofloat", &[value], None); + let fallback = opacity.add_constant(Value::Float(0.25)); + opacity.output = Some(opacity.add("ifelse", &[exists, numeric, fallback], None)); + params.insert("opacity".into(), Value::Function(Box::new(opacity))); + let image = cook_with_variables(graph, &BTreeMap::new(), 7).unwrap().remove(0); + assert_eq!(image.get(8, 8, false)[0], 0.25); +} + +#[test] +fn quadrant_properties_draw_from_independent_streams() { + for (property, setting, expected) in [ + ("branchoffset", Value::Float2([0.0; 2]), 0x3ee082ec), + ("frameoffset", Value::Float2([0.0; 2]), 0x3f11adbc), + ("patternsize", Value::Float2([0.25; 2]), 0x3f0db18c), + ("patternrotation", Value::Float(0.0), 0x3f30ca04), + ("patternsuppl", Value::Float(0.5), 0x3ad62400), + ] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children[0] = Some(child); + let parent = &mut graph.nodes[0].parameters; + parent.insert("patterntype".into(), Value::Int(2)); + parent.insert("opacity".into(), Value::Float(0.0)); + let mut write = FunctionGraph::default(); + let one = write.add_constant(Value::Float(1.0)); + let draw = write.add("rand", &[one], None); + let store = write.add("set", &[draw], Some(Value::Text("measured".into()))); + let setting = write.add_constant(setting); + write.output = Some(write.add("sequence", &[store, setting], None)); + parent.insert(property.into(), Value::Function(Box::new(write))); + let mut read = FunctionGraph::default(); + read.output = Some(read.add("get_float1", &[], Some(Value::Text("measured".into())))); + let leaf = &mut graph.nodes[1].parameters; + leaf.insert("patterntype".into(), Value::Int(2)); + leaf.insert("opacity".into(), Value::Function(Box::new(read))); + let image = cook_with_variables(graph, &BTreeMap::new(), 42).unwrap().remove(0); + assert_eq!(image.get(4, 4, false)[0].to_bits(), expected, "{property}"); + } +} + #[test] fn patterns_reject_cycles_and_bound_exponential_traversal() { let mut graph = PatternGraph::default(); @@ -121,6 +3289,77 @@ fn patterns_reject_cycles_and_bound_exponential_traversal() { assert!(cook(graph).unwrap_err().contains("budget")); } +#[test] +fn deep_quadrants_draw_only_the_leaves_covering_output_samples() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + for depth in 0..10 { + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[depth].children.fill(Some(child)); + } + let increment = 1.0 / 1_048_576.0; + graph.nodes[10].parameters = BTreeMap::from([("patterntype".into(), Value::Int(2)), ("opacity".into(), Value::Float(increment))]); + let image = cook_at_size(graph.clone(), &BTreeMap::new(), 107185, 4).unwrap().remove(0); + assert_eq!(image.data(), &[increment; 16]); + let expanded = [-0.5, 1.5, -0.5, 1.5]; + let image = cook_in_regions(graph, &BTreeMap::new(), 417341, [4; 2], [expanded; 2], 0.0).unwrap().remove(0); + assert_eq!(image.data(), &[0.0, 0.0, 0.0, 0.0, 0.0, increment, increment, 0.0, 0.0, increment, increment, 0.0, 0.0, 0.0, 0.0, 0.0]); +} + +#[test] +fn image_selectors_use_zero_based_slots_and_override_packed_patterns() { + use craft_texture::{Image, Kind}; + + let gray = |v| Some(Image::filled(4, 4, Kind::Gray, [v; 4])); + let inputs = [None, gray(0.25), gray(0.75), None, gray(0.5)]; + let definition = find("fx_map").unwrap(); + for (pattern, slot, computed, expected) in [ + (1, None, false, 0.25), + (1, Some(0), false, 0.25), + (1, Some(1), false, 0.75), + (1, Some(2), false, 0.0), + (256, Some(1), false, 0.75), + (257, None, false, 0.75), + (258, Some(1), false, 0.75), + (257, Some(-1), false, 0.0), + (1, Some(2), true, 0.5), + (1, Some(12), true, 0.5), + (257, Some(-1), true, 0.25), + (257, Some(0), true, 0.25), + ] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let node = &mut graph.nodes[0]; + node.parameters.insert("patterntype".into(), Value::Int(pattern)); + let mut vars = BTreeMap::new(); + if let Some(slot) = slot { + let selector = if computed { + vars.insert("requested".into(), Value::Int(slot)); + let mut function = FunctionGraph::default(); + function.output = Some(function.add("get_integer1", &[], Some(Value::Text("requested".into())))); + Value::Function(Box::new(function)) + } else { + Value::Int(slot) + }; + node.parameters.insert("imageindex".into(), selector); + } + let parameters = + resolve_params(definition, &BTreeMap::from([("pattern".into(), Value::PatternGraph(Box::new(graph))), ("color_mode".into(), Value::Bool(false))])); + let context = CookContext { + input_formats: &[], + format: materialcraft_core::OutputFormat::F32, + w: 4, + h: 4, + seed: 0, + tile: false, + inputs: &inputs, + params: ¶meters, + resource: &|_| None, + vars: &vars, + }; + let image = (definition.cook)(&context).unwrap().remove(0); + assert_eq!(image.get(2, 2, false)[0], expected, "pattern {pattern}, slot {slot:?}"); + } +} + #[test] fn image_indices_outside_the_supported_range_return_an_error() { let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); @@ -129,6 +3368,274 @@ fn image_indices_outside_the_supported_range_return_an_error() { assert!(cook(graph).unwrap_err().contains("unsupported pattern")); } +fn render_bitmap( + input: craft_texture::Image, + format: materialcraft_core::OutputFormat, + [width, height]: [u32; 2], + stamp: &[(&str, Value)], + controls: &[(&str, Value)], +) -> craft_texture::Image { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters.insert("patterntype".into(), Value::Int(1)); + graph.nodes[0].parameters.extend(stamp.iter().map(|(k, v)| ((*k).into(), v.clone()))); + let definition = find("fx_map").unwrap(); + let mut params = BTreeMap::from([("pattern".into(), Value::PatternGraph(Box::new(graph)))]); + params.extend(controls.iter().map(|(k, v)| ((*k).into(), v.clone()))); + let context = CookContext { + w: width, + h: height, + seed: 0, + format: materialcraft_core::OutputFormat::F32, + tile: false, + input_formats: &[materialcraft_core::OutputFormat::F32, format], + inputs: &[None, Some(input)], + params: &resolve_params(definition, ¶ms), + resource: &|_| None, + vars: &BTreeMap::new(), + }; + (definition.cook)(&context).unwrap().remove(0) +} + +#[test] +fn an_unbound_image_selector_keeps_the_fixed_slot() { + use materialcraft_core::{OutputFormat, ValueType}; + + let source = craft_texture::Image::gray(4, 4, |_, _| 0.75); + for (pattern, offset, expected) in [(259, None, 0.0), (259, Some(0), 0.0), (1, Some(0), 0.75), (1, Some(2), 0.0)] { + let mut selector = FunctionGraph::input("missing", ValueType::Integer); + if let Some(offset) = offset { + let index = selector.output.unwrap(); + let step = selector.add_constant(Value::Int(offset)); + selector.output = Some(selector.add("add", &[index, step], None)); + } + let stamp = [("patterntype", Value::Int(pattern)), ("imageindex", Value::Function(Box::new(selector)))]; + let image = render_bitmap(source.clone(), OutputFormat::F32, [4; 2], &stamp, &[("color_mode", Value::Bool(false))]); + assert_eq!(image.get_gray(2, 2, false), expected, "pattern {pattern}, offset {offset:?}"); + } +} + +#[test] +fn grayscale_bitmap_stores_coverage_before_applying_opacity() { + use craft_texture::Image; + use materialcraft_core::OutputFormat; + + let values = [-0.0, 0.0, 2.0_f32.powi(-30), -2.0_f32.powi(-30), 2.0_f32.powi(-24), -2.0_f32.powi(-24), 0.125, -0.125]; + let source = Image::gray(16, 16, |x, _| values[(x % 8) as usize]); + let stamp = [("opacity", Value::Float4([0.75, 0.75, 0.75, 1.0])), ("blendingmode", Value::Int(1)), ("imagefiltering", Value::Int(2))]; + for (gain, expected) in + [(-1.0, [-0.0, -0.0, -0.0, -0.0, -0.75 * 2.0_f32.powi(-24), -0.0, -0.09375, 0.09375]), (0.0, [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.0])] + { + let controls = [("color_mode", Value::Bool(false)), ("background", Value::Color([-4.0; 4])), ("opacity", Value::Float(gain))]; + let image = render_bitmap(source.clone(), OutputFormat::F32, [16; 2], &stamp, &controls); + let bits: [u32; 8] = std::array::from_fn(|x| image.get_gray(x as i64, 0, false).to_bits()); + assert_eq!(bits, expected.map(f32::to_bits)); + } + + let source = Image::gray(16, 16, |x, _| if x % 2 == 0 { 16_777_218.0 } else { -16_777_218.0 }); + for (gain, x, expected) in [(0.6137, 0, 0x4aeb_a92a), (-1.1875, 1, 0x4b64_0004)] { + let controls = [("color_mode", Value::Bool(false)), ("background", Value::Color([-4.0; 4])), ("opacity", Value::Float(gain))]; + let image = render_bitmap(source.clone(), OutputFormat::F32, [16; 2], &stamp, &controls); + assert_eq!(image.get_gray(x, 0, false).to_bits(), expected); + } +} + +#[test] +fn bitmap_stamp_filters_use_the_selected_source_level() { + use materialcraft_core::OutputFormat; + + let input = craft_texture::Image::gray(64, 64, |x, y| ((47 * x + 31 * y + 7 * x * y + 13) % 256) as f32 / 255.0).with_integer_sampling(true); + for (mode, expected) in + [(None, [0x3f4ea0cf, 0x3ecc32cc]), (Some(0), [0x3f4ea0cf, 0x3ecc32cc]), (Some(1), [0x3f5e5ade, 0x3e2cf0ac]), (Some(2), [0x3f62e2e3, 0x3e109090])] + { + let mut stamp = vec![("patternsize", Value::Float2([0.375; 2]))]; + if let Some(mode) = mode { + stamp.push(("imagefiltering", Value::Int(mode))); + } + let image = render_bitmap(input.clone(), OutputFormat::U8, [64; 2], &stamp, &[("color_mode", Value::Bool(false))]); + for (x, bits) in [32, 33].into_iter().zip(expected) { + assert_eq!(image.get_gray(x, 32, false).to_bits(), bits, "filter {mode:?}, x {x}"); + } + } + for (angle, expected) in [(0.0625, 0x3f2f57af), (0.125, 0x3f0b1f8b)] { + let stamp = + [("patternsize", Value::Float2([0.17, 1.0])), ("frameoffset", Value::Float2([0.07125, -0.0390625])), ("patternrotation", Value::Float(angle))]; + let image = render_bitmap(input.clone(), OutputFormat::U8, [64; 2], &stamp, &[("color_mode", Value::Bool(false))]); + assert_eq!(image.get_gray(36, 29, false).to_bits(), expected, "angle {angle}"); + } +} + +#[test] +fn automatic_bitmap_mips_use_texel_gradients_from_neighboring_pixels() { + use materialcraft_core::OutputFormat; + + for (canvas, size, turn, points) in [ + ([128, 32], [0.1767934, 0.38444963], 0.00014097655, &[(64, 16, 0x3ee1_d8e2)][..]), + ([64, 64], [0.17683654, 0.3839], 0.0005, &[(32, 32, 0x3ed0_40d0)][..]), + ([128, 32], [0.10727861, 0.12664622], 0.48012114, &[(64, 16, 0x3ef4_f4f4)][..]), + ([256, 128], [0.17679575, 0.24720412], 0.00014, &[(128, 64, 0x3e8b_bc8c), (128, 63, 0x3f09_4d89)][..]), + ] { + let input = craft_texture::Image::gray(canvas[0], canvas[1], |x, y| { + let band = |dx, dy| (x / dx + y / dy) & 1_u32; + let byte = 6 + 64 * band(1, 1) + 48 * band(2, 2) + 36 * band(4, 4) + 32 * band(8, 8) + 28 * band(16, 8) + 24 * band(32, 8); + byte as f32 / 255.0 + }) + .with_integer_sampling(true); + let stamp = [("patternsize", Value::Float2(size)), ("patternrotation", Value::Float(turn))]; + let image = render_bitmap(input, OutputFormat::U8, canvas, &stamp, &[("color_mode", Value::Bool(false))]); + for &(x, y, expected) in points { + assert_eq!(image.get_gray(x, y, false).to_bits(), expected, "{canvas:?} at ({x},{y})"); + } + } +} + +#[test] +fn rectangular_bitmap_rotation_crosses_the_first_mip_boundary() { + use materialcraft_core::OutputFormat; + + let input = craft_texture::Image::gray(64, 32, |x, y| { + let byte = (17 * x + 59 * y + 9 * x * y + 7) % 251 + 4 * u32::from((x + 3 * y) % 7 < 3); + byte as f32 / 255.0 + }) + .with_integer_sampling(true); + for (numerator, expected) in [(40, 0x3f1a_eb9b), (41, 0x3f1c_699c), (42, 0x3f0e_ca8f), (-41, 0x3eff_d300)] { + let stamp = [("patternsize", Value::Float2([1.0; 2])), ("patternrotation", Value::Float(numerator as f32 / 512.0))]; + let image = render_bitmap(input.clone(), OutputFormat::U8, [64, 32], &stamp, &[("color_mode", Value::Bool(false))]); + assert_eq!(image.get_gray(32, 16, false).to_bits(), expected, "rotation {numerator}/512"); + } +} + +#[test] +fn bitmap_stamp_filters_include_the_last_interpolated_texel() { + use materialcraft_core::OutputFormat; + + let input = craft_texture::Image::gray(32, 32, |_, _| 1.0).with_integer_sampling(true); + let controls = [("color_mode", Value::Bool(false)), ("opacity", Value::Float(0.6875))]; + for (mode, expected) in [(1, 0x3eb0_00b0), (2, 0x3f30_0000)] { + let stamp = [ + ("branchoffset", Value::Float2([-0.5; 2])), + ("frameoffset", Value::Float2([-0.020_833_343, 0.4375])), + ("patternsize", Value::Float2([0.135_416_67, 0.8125])), + ("imagefiltering", Value::Int(mode)), + ]; + let image = render_bitmap(input.clone(), OutputFormat::U8, [32; 2], &stamp, &controls); + assert_eq!(image.get_gray(1, 1, false).to_bits(), expected, "filter {mode}"); + } +} + +#[test] +fn bitmap_stamp_requires_an_input_matching_the_output_kind() { + use craft_texture::{Image, Kind}; + use materialcraft_core::OutputFormat; + + let background = [0.125, 0.5, 0.875, 0.75]; + for (kind, color_output) in [(Kind::Color, false), (Kind::Gray, true)] { + let controls = [("color_mode", Value::Bool(color_output)), ("background", Value::Color(background))]; + let image = render_bitmap(Image::filled(4, 4, kind, [1.0; 4]), OutputFormat::F32, [4; 2], &[], &controls); + let expected = if color_output { background } else { [0.5, 0.5, 0.5, 1.0] }; + assert_eq!(image.get(2, 2, false), expected); + } +} + +#[test] +fn connected_pattern_backgrounds_prepare_small_samples_before_filtering() { + use craft_texture::{Image, Kind}; + use materialcraft_core::OutputFormat; + + let smallest = f32::MIN_POSITIVE; + let largest_subnormal = f32::from_bits(0x007f_ffff); + let gray = Image::gray(2, 2, |x, _| if x == 0 { largest_subnormal } else { 2.0 * smallest }); + let underflow = Image::gray(2, 2, |x, _| if x == 0 { smallest } else { 0.0 }); + let mixed = [-0.0_f32, -0.375, 0.5, -0.0]; + let negative = [-0.0_f32, -0.375, -0.5, -0.0]; + for (input, size, source, expected) in [ + (gray, 1, OutputFormat::F32, [smallest.to_bits(); 4]), + (underflow, 1, OutputFormat::F32, [0; 4]), + (Image::filled(2, 2, Kind::Gray, [-largest_subnormal; 4]), 2, OutputFormat::F32, [0; 4]), + ( + Image::filled(2, 2, Kind::Color, [-largest_subnormal, -0.0, largest_subnormal, -smallest]), + 2, + OutputFormat::F32, + [0x8000_0000, 0x8000_0000, 0, 0x8080_0000], + ), + (Image::filled(2, 2, Kind::Color, mixed), 2, OutputFormat::F32, mixed.map(f32::to_bits)), + (Image::filled(2, 2, Kind::Color, mixed), 4, OutputFormat::F32, [0, mixed[1].to_bits(), mixed[2].to_bits(), 0]), + (Image::filled(2, 2, Kind::Color, mixed), 4, OutputFormat::F16, [0, mixed[1].to_bits(), mixed[2].to_bits(), 0]), + (Image::filled(2, 2, Kind::Color, negative), 4, OutputFormat::F32, negative.map(f32::to_bits)), + ] { + let kind = input.kind(); + let graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let definition = find("fx_map").unwrap(); + let params = resolve_params( + definition, + &BTreeMap::from([("pattern".into(), Value::PatternGraph(Box::new(graph))), ("color_mode".into(), Value::Bool(kind == Kind::Color))]), + ); + let context = CookContext { + w: size, + h: size, + seed: 100237, + format: OutputFormat::F32, + tile: true, + input_formats: &[source], + inputs: &[Some(input)], + params: ¶ms, + resource: &|_| None, + vars: &BTreeMap::new(), + }; + let image = (definition.cook)(&context).unwrap().remove(0); + let pixel = image.get(0, 0, false).map(f32::to_bits); + assert_eq!(&pixel[..image.channels()], &expected[..image.channels()]); + } +} + +#[test] +fn bitmap_stamp_tint_and_coverage_compose_straight_and_premultiplied_colors() { + use craft_texture::{Image, Kind}; + use materialcraft_core::OutputFormat; + + let source = [0x3f12d2d3, 0xbe67e7e8, 0x3ef57575, 0x3f97b7b8].map(f32::from_bits); + let controls = [("color_mode", Value::Bool(true)), ("background", Value::Color([0.25, 0.375, 0.625, 0.8125])), ("opacity", Value::Float(0.375))]; + for (blend, premultiplied, expected) in [ + (0, false, [0x3ebd2e9e, 0x3eb3eba3, 0x3f42183a, 0x3f5d55a6]), + (1, false, [0x3e999f8f, 0x3e7d2a19, 0x3f15a567, 0x3f5d55a6]), + (2, false, [0x3e999f8f, 0x3e7d2a19, 0x3f15a567, 0x3f5d55a6]), + (0, true, [0x3eb39e1e, 0x3eb5cf0f, 0x3f3cc3c4, 0x3f5d55a6]), + ] { + let stamp = [ + ("opacity", Value::Float4([0.75, 0.375, 1.0, 0.625])), + ("blendingmode", Value::Int(blend)), + ("imagepremul", Value::Bool(premultiplied)), + ("imagefiltering", Value::Int(2)), + ]; + let image = render_bitmap(Image::filled(1, 1, Kind::Color, source), OutputFormat::F32, [1; 2], &stamp, &controls); + assert_eq!(image.get(0, 0, false).map(f32::to_bits), expected, "blend {blend}, premultiplied {premultiplied}"); + } +} + +#[test] +fn bitmap_stamp_blend_preserves_guard_bits_during_cancellation() { + use craft_texture::{Image, Kind}; + use materialcraft_core::OutputFormat; + + let source = [0xbaf97631, 0xc061d2bc, 0xbc4a2f47, 0xbe8c58b1].map(f32::from_bits); + let background = [0x3ac3d70f, 0x4031485b, 0x3c1eb9a8, 0x3e5c5bb0].map(f32::from_bits); + let controls = [("color_mode", Value::Bool(true)), ("background", Value::Color(background))]; + for (mode, expected) in [ + (0, [0xb9d67c88, 0xbf422984, 0xbb2dd67c, 0x388c6000]), + (1, [0x34f98400, 0x3a61d400, 0x364a3400, 0x388c5c00]), + (2, [0x34f98400, 0x3a61d400, 0x364a3400, 0x388c5c00]), + ] { + let stamp = [("imagefiltering", Value::Int(2)), ("imagepremul", Value::Bool(true)), ("blendingmode", Value::Int(mode))]; + let image = render_bitmap(Image::filled(1, 1, Kind::Color, source), OutputFormat::F32, [1; 2], &stamp, &controls); + assert_eq!(image.get(0, 0, false).map(f32::to_bits), expected, "blend {mode}"); + } + let controls = [("color_mode", Value::Bool(true)), ("background", Value::Color([-0.0; 4]))]; + for mode in 0..=2 { + let stamp = [("imagefiltering", Value::Int(2)), ("blendingmode", Value::Int(mode))]; + let image = render_bitmap(Image::filled(1, 1, Kind::Color, [0.0; 4]), OutputFormat::F32, [1; 2], &stamp, &controls); + assert_eq!(image.get(0, 0, false).map(f32::to_bits), [(-0.0_f32).to_bits(); 4]); + } +} + fn roughness_sample(roughness: f32, depth: usize, blend: i32, color: bool, repeat: bool) -> crate::CookResult { let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); for index in 0..depth { @@ -138,7 +3645,8 @@ fn roughness_sample(roughness: f32, depth: usize, blend: i32, color: bool, repea let leaf = depth; let leaf_id = graph.nodes[leaf].id; graph.nodes[leaf].parameters.insert("patterntype".into(), Value::Int(2)); - graph.nodes[leaf].parameters.insert("opacity".into(), Value::Float4([0.8, 0.4, 0.2, 1.0])); + let tint = if color { [0.8, 0.4, 0.2, 1.0] } else { [0.8, 0.8, 0.8, 1.0] }; + graph.nodes[leaf].parameters.insert("opacity".into(), Value::Float4(tint)); graph.nodes[leaf].parameters.insert("blendingmode".into(), Value::Int(blend)); if repeat { let dot = graph.add(PatternNodeKind::Dot).unwrap(); @@ -166,6 +3674,7 @@ fn roughness_sample(roughness: f32, depth: usize, blend: i32, color: bool, repea ]), ); let context = CookContext { + input_formats: &[], format: materialcraft_core::OutputFormat::F32, w: 16, h: 16, @@ -180,6 +3689,57 @@ fn roughness_sample(roughness: f32, depth: usize, blend: i32, color: bool, repea (definition.cook)(&context) } +#[test] +fn single_square_preserves_the_stored_opacity_at_each_depth() { + let definition = find("fx_map").unwrap(); + let gain = f32::from_bits(0x4020_0150); + for (last, draw, roughness, opacity, blend, bits) in [ + (5, 5, 0.95, gain, 1, 0x3eba_f23c), + (1, 0, 0.99, 1.0, 1, 0x3f00_a4b1), + (2, 2, 0.99, 1.0, 1, 0x3ea8_f445), + (2, 2, 1.5, 0.6137, 1, 0x3e94_d6a2), + (2, 1, 1.0, gain, 1, 0x3f55_5716), + (5, 5, 4_194_304.0, 1.0, 1, 0), + (0, 0, 0.0, -1.0, 0, 0xbf80_0000), + (0, 0, 0.95, 327.125, 0, 0x43a3_9000), + ] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + for depth in 0..last { + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[depth].children[0] = Some(child); + } + graph.nodes[draw].parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(2)), + ("patternsize".into(), Value::Float2([(1_u32 << draw) as f32; 2])), + ("blendingmode".into(), Value::Int(blend)), + ]); + let params = resolve_params( + definition, + &BTreeMap::from([ + ("pattern".into(), Value::PatternGraph(Box::new(graph))), + ("color_mode".into(), Value::Bool(false)), + ("roughness".into(), Value::Float(roughness)), + ("opacity".into(), Value::Float(opacity)), + ]), + ); + let vars = BTreeMap::new(); + let context = CookContext { + input_formats: &[], + format: materialcraft_core::OutputFormat::F32, + w: 16, + h: 16, + seed: 7, + tile: false, + inputs: &[], + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + let image = (definition.cook)(&context).unwrap().remove(0); + assert_eq!(image.get_gray(0, 0, false).to_bits(), bits, "drawing depth {draw} of {last}, roughness {roughness}, opacity {opacity}"); + } +} + #[test] fn roughness_attenuates_quadrants_by_depth_and_keeps_background() { for color in [false, true] { @@ -189,10 +3749,10 @@ fn roughness_attenuates_quadrants_by_depth_and_keeps_background() { let pixel = image.get(0, 0, false); for (channel, foreground) in [0.8_f32, 0.4, 0.2, 1.0].into_iter().take(image.channels()).enumerate() { let value = foreground * 0.5 * weight; - let expected = match blend { - 1 if !color => value.max(0.1), - 1 => value + 0.1 * (1.0 - 0.5 * weight), - 2 => value.max(0.1), + let expected = match (color, blend) { + (false, 1 | 2) => value.max(0.1), + (true, 1 | 2) => value + 0.1 * (1.0 - 0.5 * weight), + (true, 0) if channel == 3 => value + 0.1 * (1.0 - value), _ => value + 0.1, }; @@ -237,6 +3797,7 @@ fn a_full_nine_level_quadtree_renders_one_pattern_per_pixel() { ]), ); let context = CookContext { + input_formats: &[], format: materialcraft_core::OutputFormat::F32, w: 256, h: 256, @@ -274,10 +3835,11 @@ fn an_iteration_reads_the_variables_the_previous_iteration_set() { function.output = Some(function.add("set", &[next], Some(Value::Text("total".into())))); graph.nodes[1].parameters.insert("opacity".into(), Value::Function(Box::new(function))); - let image = cook_with_variables(graph, &BTreeMap::from([("total".into(), Value::Float(0.0))])).unwrap().remove(0); - - // 0.25, 0.5 and 0.75 add up; three separate copies of the variable would add 0.25 three times - assert!((image.mean()[0] - 1.5).abs() < 1e-5, "{}", image.mean()[0]); + for published in [0.0, 0.125] { + let image = cook_with_variables(graph.clone(), &BTreeMap::from([("total".into(), Value::Float(published))]), 7).unwrap().remove(0); + // The pattern declares a local accumulator. Its three visits add 0.25, 0.5 and 0.75. + assert_eq!(image.mean()[0], 1.5, "published {published}"); + } } #[test] @@ -290,6 +3852,7 @@ fn the_render_region_is_the_part_of_pattern_space_the_image_shows() { &BTreeMap::from([("pattern".into(), Value::PatternGraph(Box::new(graph))), ("render_region".into(), Value::Float4([0.0, 2.0, 0.0, 2.0]))]), ); let context = CookContext { + input_formats: &[], format: materialcraft_core::OutputFormat::F32, w: 16, h: 16, @@ -309,6 +3872,18 @@ fn the_render_region_is_the_part_of_pattern_space_the_image_shows() { assert_eq!(image.get(12, 12, false)[0], 0.0); } +#[test] +fn reversing_a_render_interval_selects_the_full_extent_of_that_axis() { + for (bounds, first_center) in [ + ([0.8125, 0.1875, 0.25, 0.75], [0.0078125, 0.25390625]), + ([0.1875, 0.8125, 0.75, 0.25], [0.19238281, 0.0078125]), + ([0.8125, 0.1875, 0.75, 0.25], [0.0078125; 2]), + ] { + let region = super::region::Region::new(bounds).unwrap(); + assert_eq!(region.point([0, 0], [64, 64]), first_center); + } +} + #[test] fn every_visit_draws_its_own_random_numbers() { let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); @@ -355,6 +3930,7 @@ fn a_pixel_on_the_seam_of_two_patterns_is_drawn_once() { // Two pixels a side put every pixel center on the corner of four of the sixteen squares let context = CookContext { + input_formats: &[], format: materialcraft_core::OutputFormat::F32, w: 2, h: 2, diff --git a/crates/nodes/src/pattern/tests/paired_batches.rs b/crates/nodes/src/pattern/tests/paired_batches.rs new file mode 100644 index 00000000..6e508417 --- /dev/null +++ b/crates/nodes/src/pattern/tests/paired_batches.rs @@ -0,0 +1,677 @@ +use super::*; +use craft_texture::{Image, Kind}; +use materialcraft_core::OutputFormat; + +// Three disjoint portions of a procedural input address the active quadrant levels. +pub(super) fn field_property(depth: u32, offset: [f32; 2], frame: bool, repeated: bool) -> Value { + let mut graph = FunctionGraph::default(); + let pos = graph.add("get_float2", &[], Some(Value::Text("$pos".into()))); + let scale = graph.add_constant(Value::Float2([(1 << depth) as f32 / 1024.0; 2])); + let scaled = graph.add("mul", &[pos, scale], None); + let origin = graph.add_constant(Value::Float2(offset)); + let uv = graph.add("add", &[scaled, origin], None); + let uv = if repeated { + let number = graph.add("get_float1", &[], Some(Value::Text("tree_index".into()))); + let quarter = graph.add_constant(Value::Float(0.25)); + let row = graph.add("mul", &[number, quarter], None); + let zero = graph.add_constant(Value::Float(0.0)); + let bank = graph.add("vector2", &[zero, row], None); + graph.add("add", &[uv, bank], None) + } else { + uv + }; + let sample = graph.add("samplecol", &[uv], Some(Value::Int2([0, 0]))); + let result = if frame { + let center = graph.add("swizzle2", &[sample], Some(Value::Int2([0, 1]))); + graph.add("sub", &[center, pos], None) + } else { + graph.add("swizzle1", &[sample], Some(Value::Int(2))) + }; + graph.output = Some(result); + Value::Function(Box::new(graph)) +} + +fn pair_copy_counts(pair: u32) -> [u32; 64] { + std::array::from_fn(|index| { + let group = index as u32; + match (pair, group) { + (60, 60) => 81, + (60, 61) => 100, + (60, 0..48) => 40 + (26 * group + 63) % 83, + (60, _) => 45 + (9 * group + 8) % 37, + (_, g) if g == pair => 75, + (_, g) if g == pair + 1 => 106, + (_, 0..48) => 27 + (30 * group + 64) % 67, + _ => 45 + (15 * group + 11) % 37, + } + }) +} + +fn stamp_field(group_counts: &[u32; 64], markers: &[(u32, u32, bool)]) -> Image { + let tiny = f32::EPSILON * 0.25; + let mut selected = BTreeMap::new(); + for (j, &(negative, positive, _)) in markers.iter().enumerate() { + let x = (16.5 + 2.0 * j as f32) / 128.0; + selected.insert(negative, [x, 24.5 / 128.0, -1.0, 1.0]); + selected.insert(positive, [x, 24.5 / 128.0, tiny, 1.0]); + } + Image::generate(1024, 1024, Kind::Color, |x, y| { + let (depth, x, y) = match (x, y) { + (0..512, 0..512) => (9, x, y), + (512..768, 0..256) => (8, x - 512, y), + (0..128, 512..640) => (7, x, y - 512), + _ => return [0.0; 4], + }; + let mut visit = 0; + for bit in 0..depth { + visit |= (((x >> bit) & 1) | (((y >> bit) & 1) << 1)) << (2 * bit); + } + // A parent is followed by four children, each with four grandchildren. + let draw = match depth { + 7 => visit * 21, + 8 => (visit / 4) * 21 + 1 + (visit % 4) * 5, + _ => (visit / 16) * 21 + 2 + ((visit / 4) % 4) * 5 + visit % 4, + }; + if let Some(marker) = selected.get(&draw) { + return *marker; + } + let subtree = draw / 1344; + let group = subtree / 4; + let extras = group_counts[group as usize]; + let quota = extras / 4 + u32::from((subtree % 4 + group) % 4 < extras % 4); + let x = if draw % 1344 < quota { 0.0 } else { 64.5 / 128.0 }; + [x, 112.5 / 128.0, 0.25, 1.0] + }) +} + +fn check_batch_markers(group_counts: &[u32; 64], seed: u32, axes: i32, markers: &[(u32, u32, bool)]) { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let mut parent = graph.root.unwrap(); + for depth in 1..=9 { + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(parent - 1) as usize].children.fill(Some(child)); + if depth >= 7 { + let offset = match depth { + 7 => [0.0, 0.5], + 8 => [0.5, 0.0], + _ => [0.0; 2], + }; + let mut params = additive_square(0.25, [0.0; 2], [0.0; 2]); + params.insert("frameoffset".into(), field_property(depth, offset, true, false)); + params.insert("opacity".into(), field_property(depth, offset, false, false)); + graph.nodes[(child - 1) as usize].parameters = params; + } + parent = child; + } + + let definition = find("fx_map").unwrap(); + let params = resolve_params( + definition, + &BTreeMap::from([ + ("pattern".into(), Value::PatternGraph(Box::new(graph))), + ("roughness".into(), Value::Float(0.0)), + ("color_mode".into(), Value::Bool(false)), + ("background".into(), Value::Color([1.0; 4])), + ]), + ); + let variables = BTreeMap::from([("$tiling".into(), Value::Int(axes))]); + let inputs = [None, Some(stamp_field(group_counts, markers))]; + let context = CookContext { + w: 128, + h: 128, + seed, + format: OutputFormat::F32, + tile: true, + inputs: &inputs, + input_formats: &[OutputFormat::F32; 2], + params: ¶ms, + resource: &|_| None, + vars: &variables, + }; + let image = (definition.cook)(&context).unwrap().remove(0); + for (j, &(_, _, negative_first)) in markers.iter().enumerate() { + let expected = if negative_first { f32::EPSILON * 0.25 } else { 0.0 }; + assert_eq!(image.get_gray(16 + 2 * j as i64, 24, false), expected, "seed {seed}, marker {j}"); + } +} + +#[test] +fn full_pairs_defer_individual_copies_after_two_batches() { + // Each pair of numbered stamps overlaps at one pixel. The final bit is set when the negative stamp draws first. + let pair58 = [(322546, 46225, true), (322547, 1168, true), (322548, 2154, true), (322559, 818, true), (5359, 322551, false), (10731, 11628, false)]; + let pair60 = [ + (90032, 332682, false), + (90033, 281378, false), + (90034, 302451, false), + (90047, 303240, false), + (90046, 303080, false), + (90045, 303435, false), + (90044, 302501, false), + (333311, 212967, true), + (333298, 89032, true), + ]; + let pair62 = [ + (344050, 272241, true), + (344051, 258965, true), + (344052, 262618, true), + (344063, 262962, true), + (263423, 332391, false), + (263418, 253025, true), + (263407, 257852, true), + (268779, 333188, false), + ]; + // With 96 extra copies in every group, the last twelve copies of group 60 draw later. + let all_pairs = [ + (327923, 88021, true), + (327924, 91851, true), + (327925, 91651, true), + (327935, 93255, true), + (344042, 259673, true), + (279529, 324712, false), + (85920, 267859, false), + (42912, 267222, false), + (10643, 214976, false), + (10644, 91692, false), + ]; + let preceding_subtrees = [ + (274168, 129135, true), + (274169, 326233, false), + (274170, 323621, false), + (274175, 327236, false), + (295667, 219008, true), + (295668, 172042, true), + (295669, 172046, true), + (295679, 172049, true), + (317174, 47924, true), + (317175, 24, true), + (317176, 9, true), + (317183, 34, true), + (338676, 269607, true), + (338677, 258061, true), + (338678, 258081, true), + (338687, 258057, true), + ]; + let mut crossing = [32; 64]; + for (group, count) in [(50, 91), (54, 96), (58, 93), (62, 95)] { + crossing[group] = count; + } + let second_pair_markers = [ + (279537, 138231, true), + (279583, 94160, true), + (87397, 15706, true), + (90047, 978, true), + (92773, 303597, false), + (95423, 213678, false), + (95461, 94418, true), + ]; + let mut second_pair = [32; 64]; + second_pair[50] = 75; + second_pair[51] = 107; + let penultimate_prefix_markers = [ + (327930, 327964, false), + (327931, 328139, false), + (327934, 327958, false), + (327935, 328054, false), + (327967, 263018, true), + (327973, 280124, true), + (329279, 332822, false), + (329317, 331280, false), + (330623, 331042, false), + (330661, 311138, true), + ]; + let mut penultimate_prefix = [32; 64]; + penultimate_prefix[60] = 90; + let combined_prefixes_markers = [ + (279537, 144436, true), + (279583, 328198, false), + (327930, 92890, true), + (327931, 93598, true), + (327934, 92755, true), + (327935, 93864, true), + (327967, 262553, true), + (87397, 7121, true), + (90047, 33270, true), + (92773, 173881, false), + ]; + let mut combined_prefixes = [32; 64]; + combined_prefixes[50] = 75; + combined_prefixes[51] = 107; + combined_prefixes[60] = 90; + let fourth_pair_markers = [ + (301041, 217929, true), + (301087, 180528, true), + (173413, 18515, true), + (176063, 11958, true), + (178789, 262684, false), + (181439, 265280, false), + (181477, 179464, true), + ]; + let mut fourth_pair = [32; 64]; + fourth_pair[54] = 75; + fourth_pair[55] = 107; + for (group_counts, seed, axes, markers) in [ + (pair_copy_counts(58), 653180, 1, pair58.as_slice()), + (pair_copy_counts(60), 1763066, 1, pair60.as_slice()), + (pair_copy_counts(62), 653180, 1, pair62.as_slice()), + ([96; 64], 206407, 3, all_pairs.as_slice()), + (crossing, 214261, 1, preceding_subtrees.as_slice()), + (fourth_pair, 222453, 1, fourth_pair_markers.as_slice()), + (second_pair, 220419, 1, second_pair_markers.as_slice()), + (penultimate_prefix, 220472, 1, penultimate_prefix_markers.as_slice()), + (combined_prefixes, 220525, 1, combined_prefixes_markers.as_slice()), + ] { + check_batch_markers(&group_counts, seed, axes, markers); + } +} + +#[test] +fn seven_batches_can_end_in_the_preceding_quadrant() { + for (first, seed, markers) in [ + (8, 225641, [(80617, 251488, false), (80618, 313557, false), (80619, 2103, true), (80620, 208828, false), (80639, 321776, false), (80761, 2703, true)]), + ( + 24, + 225664, + [(166633, 271610, false), (166634, 336460, false), (166635, 127058, true), (166636, 321100, false), (166655, 3532, true), (166777, 3002, true)], + ), + ( + 40, + 225687, + [(252649, 290337, false), (252650, 74284, true), (252651, 214430, true), (252652, 2247, true), (252671, 87708, true), (252793, 343869, false)], + ), + ] { + let mut group_counts = [32; 64]; + group_counts[first..first + 7].fill(87); + check_batch_markers(&group_counts, seed, 1, &markers); + } +} + +#[test] +fn deferred_copies_can_fill_the_receiving_quadrant() { + let mut group_counts = [32; 64]; + group_counts[32] = 116; + group_counts[54] = 90; + group_counts[55] = 80; + let markers = [ + (301065, 265134, true), + (301220, 181946, true), + (177441, 189607, false), + (182783, 207671, false), + (182817, 319146, false), + (185471, 208185, false), + (209663, 185762, true), + (306431, 308842, false), + (306465, 185374, true), + ]; + check_batch_markers(&group_counts, 225301, 1, &markers); +} + +#[test] +fn full_middle_pairs_continue_their_separate_subtrees() { + for (pairs, seed, markers) in [ + ( + [[32, 32], [101, 90], [32, 32]], + 226537, + [(279551, 102866, true), (280895, 256149, true), (283583, 288357, false), (284961, 255831, true), (288993, 302446, false), (290337, 222622, true)], + ), + ( + [[32, 32], [32, 32], [78, 101]], + 226568, + [(301055, 181298, true), (302399, 342071, false), (305087, 328846, false), (306465, 341076, false), (310497, 332538, false), (311841, 54464, true)], + ), + ( + [[88, 90], [101, 90], [78, 101]], + 226599, + [(279551, 97145, true), (280895, 256381, true), (283583, 332807, false), (284961, 258500, true), (288993, 310660, false), (290337, 222196, true)], + ), + ] { + let mut group_counts = [32; 64]; + for (first, pair) in [48, 52, 56].into_iter().zip(pairs) { + group_counts[first..first + 2].copy_from_slice(&pair); + } + check_batch_markers(&group_counts, seed, 1, &markers); + } +} + +#[test] +fn penultimate_pair_splits_when_the_partial_subtrees_fill_a_batch() { + for (pair, seed, markers) in [ + ( + [79, 91], + 227173, + [(322559, 6703, true), (323903, 86579, true), (326591, 276861, true), (327969, 267935, true), (332001, 288482, true), (333345, 270405, true)], + ), + ( + [85, 97], + 227204, + [(322559, 16047, true), (323903, 277749, true), (326591, 94356, true), (327969, 258216, true), (332001, 267414, true), (333345, 272173, true)], + ), + ( + [101, 128], + 227235, + [(322559, 14801, true), (323903, 98883, true), (326591, 279431, true), (327969, 167744, true), (332001, 214799, true), (333345, 129478, true)], + ), + ( + [79, 150], + 227266, + [(322559, 22151, true), (323903, 91701, true), (326591, 91253, true), (331967, 283167, true), (333345, 129341, true), (87397, 309051, false)], + ), + ] { + let mut group_counts = [32; 64]; + group_counts[60..62].copy_from_slice(&pair); + check_batch_markers(&group_counts, seed, 1, &markers); + } +} + +#[test] +fn final_pair_continues_into_the_next_subtree_when_the_receiver_is_short() { + for (prefix, preceding, pair, seed, markers) in [ + ( + 80, + 32, + [100, 71], + 228901, + [(344060, 300640, true), (344061, 214437, true), (344062, 264313, true), (258046, 126810, true), (258072, 253595, true), (260735, 127893, true)], + ), + ( + 81, + 32, + [75, 96], + 228932, + [(344060, 113385, true), (344061, 40986, true), (344062, 310665, true), (258046, 259178, false), (258072, 255856, true), (260735, 319019, false)], + ), + ( + 82, + 32, + [71, 100], + 228963, + [(344060, 182379, true), (344061, 328265, true), (344062, 41546, true), (258046, 41088, true), (258072, 334314, false), (260735, 255892, true)], + ), + ( + 50, + 91, + [110, 67], + 228994, + [(344054, 283285, true), (344055, 259617, true), (344056, 330090, true), (344058, 126934, true), (344060, 288415, true), (344063, 42392, true)], + ), + ] { + let mut group_counts = [32; 64]; + group_counts[48] = prefix; + group_counts[60] = preceding; + group_counts[62..64].copy_from_slice(&pair); + check_batch_markers(&group_counts, seed, 1, &markers); + } +} + +#[test] +fn second_quadrant_fills_a_batch_with_the_first_overflowing_pair() { + for (head, pair, last_prefix, seed, markers) in [ + ( + 80, + [91, 81], + 66, + 239183, + [(279544, 219111, true), (279545, 177140, true), (279547, 264248, true), (279550, 18082, true), (86047, 293310, false), (91385, 268863, false)], + ), + ( + 84, + [82, 87], + 84, + 239214, + [(279547, 337858, false), (279548, 238689, true), (279550, 188473, true), (86047, 33592, true), (88046, 272116, false), (91561, 332595, false)], + ), + ( + 72, + [92, 89], + 97, + 239245, + [(279535, 198075, true), (279536, 12379, true), (279538, 73395, true), (279541, 37478, true), (279544, 204365, true), (279549, 29131, true)], + ), + ( + 67, + [94, 90], + 73, + 239276, + [(279532, 122270, true), (279533, 151260, true), (279535, 65152, true), (279538, 35090, true), (279541, 198163, true), (279546, 258888, true)], + ), + ] { + let mut group_counts = [32; 64]; + group_counts[16] = head; + group_counts[50..52].copy_from_slice(&pair); + group_counts[62] = last_prefix; + check_batch_markers(&group_counts, seed, 1, &markers); + } +} + +#[test] +fn three_final_pairs_share_the_penultimate_batch_with_middle_subtrees() { + for (head, middle, last_head, pairs, seed, markers) in [ + ( + 83, + 79, + 49, + [[85, 84], [84, 86], [84, 87]], + 246191, + [(13460, 191490, false), (13480, 253590, false), (14803, 320991, false), (212523, 37343, true), (215059, 7974, true), (266111, 10751, true)], + ), + ( + 83, + 74, + 61, + [[90, 81], [88, 87], [87, 85]], + 246220, + [(13460, 321900, false), (13480, 290313, false), (14803, 60605, false), (212523, 221710, false), (215059, 67593, true), (266111, 268976, false)], + ), + ( + 86, + 67, + 60, + [[94, 79], [94, 83], [93, 81]], + 246249, + [(13460, 145396, false), (13480, 136182, false), (14803, 58999, false), (212523, 29195, true), (215059, 113808, true), (266111, 339580, false)], + ), + ( + 81, + 75, + 46, + [[99, 83], [102, 80], [96, 87]], + 246278, + [(13460, 150313, false), (13480, 84657, false), (14803, 24014, false), (212523, 7900, true), (215059, 60885, true), (266111, 317978, false)], + ), + ] { + let mut group_counts = [32; 64]; + group_counts[0] = head; + group_counts[16] = middle; + group_counts[48] = last_head; + for (group, pair) in [58, 60, 62].into_iter().zip(pairs) { + group_counts[group..group + 2].copy_from_slice(&pair); + } + check_batch_markers(&group_counts, seed, 1, &markers); + } +} + +#[test] +fn eight_middle_group_batches_carry_into_the_first_subtrees() { + for (head, eighth, receiver, middle, next, pair, last, seed, markers) in [ + ( + 107, + 84, + 83, + 82, + 83, + [79, 89], + 84, + 249179, + [(4031, 302217, false), (4010, 192880, false), (40445, 66669, false), (259454, 316884, false), (260735, 298594, false), (212350, 87587, true)], + ), + ( + 111, + 89, + 79, + 82, + 77, + [84, 87], + 86, + 249210, + [(4031, 284859, false), (4010, 245490, false), (40445, 243861, false), (259454, 312946, false), (260735, 321439, false), (212350, 30837, true)], + ), + ( + 111, + 98, + 64, + 83, + 63, + [91, 90], + 92, + 249241, + [(4031, 159042, false), (4010, 208901, false), (40445, 199211, false), (259454, 343227, false), (260735, 315060, false), (212350, 335049, false)], + ), + ( + 107, + 118, + 52, + 85, + 39, + [99, 90], + 101, + 249272, + [(4031, 169499, false), (4010, 175761, false), (40445, 226717, false), (259454, 312824, false), (260735, 340420, false), (212350, 24792, true)], + ), + ] { + let mut group_counts = [32; 64]; + group_counts[0] = head; + group_counts[24..31].fill(84); + group_counts[31] = eighth; + group_counts[32] = receiver; + group_counts[33..40].fill(middle); + group_counts[52] = next; + group_counts[54..56].copy_from_slice(&pair); + group_counts[60..62].copy_from_slice(&[84, 57]); + group_counts[62] = last; + check_batch_markers(&group_counts, seed, 1, &markers); + } +} + +#[test] +fn ten_batches_split_the_later_horizontal_subtrees() { + for (head, following, middle, pair_start, later, end, last, seed, markers) in [ + ( + 120, + 86, + 55, + 84, + 54, + 72, + 78, + 261084, + [(303743, 213233, true), (303763, 342691, false), (303726, 212560, true), (303705, 3691, true), (259584, 327565, false), (260714, 281791, false)], + ), + ( + 109, + 86, + 62, + 89, + 73, + 79, + 62, + 261115, + [(303743, 261223, true), (303763, 326473, false), (303726, 213819, true), (303705, 2845, true), (259584, 286937, false), (260714, 281276, false)], + ), + ( + 121, + 86, + 76, + 82, + 62, + 82, + 81, + 261146, + [(303743, 268210, true), (303763, 319251, false), (303726, 260297, true), (303705, 1829, true), (259584, 1908, true), (260714, 302967, false)], + ), + ( + 121, + 89, + 58, + 93, + 77, + 77, + 64, + 261177, + [(303743, 288302, true), (303763, 339410, false), (303726, 305649, false), (303705, 1704, true), (259584, 335480, false), (260714, 281475, false)], + ), + ] { + let mut groups = [61; 64]; + groups[0] = head; + groups[1..8].fill(following); + groups[52] = middle; + groups[54] = pair_start; + groups[56] = later; + groups[58..60].copy_from_slice(&[80, 70]); + groups[60] = end; + groups[62] = last; + check_batch_markers(&groups, seed, 1, &markers); + } +} + +#[test] +fn middle_batches_share_the_tail_of_the_final_horizontal_pair() { + for (receiver, middle_tail, first, first_end, following, penultimate, last, last_end, seed, markers) in [ + ( + 134, + 0, + 84, + 85, + 83, + 70, + 58, + 110, + 269119, + [(172031, 56696, true), (284927, 174951, true), (344046, 315870, true), (90047, 2990, true), (40339, 171460, false), (263570, 282032, false)], + ), + ( + 114, + 1, + 86, + 83, + 80, + 81, + 83, + 86, + 269156, + [(172031, 188653, false), (284927, 342769, false), (344046, 6790, true), (90047, 282513, false), (40339, 170078, false), (263570, 281121, false)], + ), + ( + 118, + 3, + 79, + 90, + 75, + 82, + 84, + 96, + 269193, + [(172031, 202722, false), (284927, 262240, true), (344046, 28604, true), (90047, 282568, false), (40339, 171613, false), (263570, 281461, false)], + ), + ( + 131, + 16, + 70, + 99, + 58, + 83, + 101, + 93, + 269230, + [(172031, 320872, false), (284927, 333904, false), (344046, 285274, true), (90047, 283471, false), (40339, 170463, false), (258067, 283047, false)], + ), + ] { + let mut groups = [61; 64]; + groups[16] = receiver; + groups[24..32].fill(84); + groups[31] += middle_tail; + groups[48..50].copy_from_slice(&[first, first_end]); + groups[52] = following; + groups[60] = penultimate; + groups[62..64].copy_from_slice(&[last, last_end]); + check_batch_markers(&groups, seed, 1, &markers); + } +} diff --git a/crates/nodes/src/pattern/tests/repeated_quadrants.rs b/crates/nodes/src/pattern/tests/repeated_quadrants.rs new file mode 100644 index 00000000..4055046e --- /dev/null +++ b/crates/nodes/src/pattern/tests/repeated_quadrants.rs @@ -0,0 +1,160 @@ +use super::*; +use materialcraft_core::OutputFormat; + +fn select_iteration(graph: &mut FunctionGraph, number: u32, iteration: i32, gain: f32, otherwise: u32) -> u32 { + let expected = graph.add_constant(Value::Float(iteration as f32)); + let selected = graph.add("eq", &[number, expected], None); + let value = graph.add_constant(Value::Float(gain)); + graph.add("ifelse", &[selected, value, otherwise], None) +} + +fn field(slot: usize, markers: [i32; 3], negative: f32, positive: f32) -> Value { + let mut graph = FunctionGraph::default(); + let number = graph.add("get_float1", &[], Some(Value::Text("$number".into()))); + let zero = graph.add_constant(Value::Float(0.0)); + let result = match slot { + 0 => select_iteration(&mut graph, number, markers[0], negative, zero), + 1 => { + let later = select_iteration(&mut graph, number, markers[1], positive, zero); + select_iteration(&mut graph, number, markers[0], negative, later) + } + 3 => select_iteration(&mut graph, number, markers[2], positive, zero), + _ => zero, + }; + graph.output = Some(result); + Value::Function(Box::new(graph)) +} + +fn active_iterations(iterations: &[i32]) -> Value { + let mut graph = FunctionGraph::default(); + let number = graph.add("get_float1", &[], Some(Value::Text("$number".into()))); + let mut selected = graph.add_constant(Value::Bool(false)); + for &iteration in iterations { + let value = graph.add_constant(Value::Float(iteration as f32)); + let matches = graph.add("eq", &[number, value], None); + selected = graph.add("or", &[selected, matches], None); + } + graph.output = Some(selected); + Value::Function(Box::new(graph)) +} + +#[test] +fn deep_repeated_quadrants_submit_first_level_shapes_by_slot_then_iteration() { + let definition = find("fx_map").unwrap(); + let tiny = f32::EPSILON * 0.25; + let sparse = [2, 6]; + let four = [0, 3, 5, 8]; + for (depth, repeats, active) in [(5, 2, &[][..]), (6, 2, &[][..]), (10, 4, &[][..]), (5, 9, &sparse), (6, 9, &sparse), (9, 9, &[0, 1]), (10, 9, &four)] { + let markers = if active.is_empty() { [0, 1, repeats - 1] } else { [active[0], active[1], active[active.len() - 1]] }; + for reversed in [false, true] { + let (negative, positive) = if reversed { (tiny, -1.0) } else { (-1.0, tiny) }; + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let first = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(repeats)); + let branch = if active.is_empty() { + first + } else { + let switch = graph.add(PatternNodeKind::Switch).unwrap(); + let node = &mut graph.nodes[(switch - 1) as usize]; + node.children[1] = Some(first); + node.parameters.insert("switch".into(), active_iterations(active)); + switch + }; + graph.nodes[0].children[1] = Some(branch); + let mut next = None; + for _ in 2..=depth { + let id = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(id - 1) as usize].children[0] = next; + next = Some(id); + } + for (slot, offset) in [[0.0, 0.0], [0.0, 0.0], [0.5, -0.5], [-0.5, -0.5]].into_iter().enumerate() { + let id = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(first - 1) as usize].children[slot] = Some(id); + let node = &mut graph.nodes[(id - 1) as usize]; + node.children[0] = next; + node.parameters = additive_square(0.0, [0.0; 2], offset); + node.parameters.insert("patternsize".into(), Value::Float2([0.125; 2])); + node.parameters.insert("opacity".into(), field(slot, markers, negative, positive)); + } + let params = resolve_params( + definition, + &BTreeMap::from([ + ("pattern".into(), Value::PatternGraph(Box::new(graph))), + ("roughness".into(), Value::Float(0.0)), + ("color_mode".into(), Value::Bool(false)), + ("background".into(), Value::Color([1.0; 4])), + ]), + ); + let vars = BTreeMap::from([("$tiling".into(), Value::Int(0))]); + let context = CookContext { + w: 32, + h: 32, + seed: 200153, + format: OutputFormat::F32, + tile: false, + inputs: &[], + input_formats: &[], + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + let output = (definition.cook)(&context).unwrap().remove(0); + let left = if (depth < 6) != reversed { tiny } else { 0.0 }; + let right = if reversed { 0.0 } else { tiny }; + assert_eq!([output.get_gray(8, 8, false), output.get_gray(24, 8, false)], [left, right], "depth {depth}, repeats {repeats}, reversed {reversed}"); + } + } +} + +#[test] +fn repeated_six_level_trees_share_quadrant_batches() { + let tiny = f32::EPSILON * 0.25; + for (repetitions, negative, positive, first_leaves) in [(2, (0, 0), (3, 1), 0), (5, (0, 4), (1, 0), 272)] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let root = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children[1] = Some(root); + graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(repetitions)); + for slot in 0..4 { + let mut node = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(root - 1) as usize].children[slot] = Some(node); + for _ in 1..5 { + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(node - 1) as usize].children.fill(Some(child)); + node = child; + } + let leaf = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(node - 1) as usize].children.fill(Some(leaf)); + let left = -0.5 * (slot & 1) as f32; + let top = -0.5 * (slot >> 1) as f32; + let neutral = [left, top + 0.5]; + graph.nodes[(node - 1) as usize].parameters = additive_square(0.25, [0.0; 2], neutral); + let mut params = additive_square(0.25, [0.0; 2], neutral); + let marker = [(negative, -1.0), (positive, tiny)].into_iter().find(|((quadrant, _), _)| *quadrant == slot); + if let Some(((_, repetition), gain)) = marker { + // Only these two leaves overlap in the upper-left quarter. Other draws still fill the batches. + for (name, yes, no) in + [("frameoffset", Value::Float2([left, top]), Value::Float2(neutral)), ("opacity", Value::Float(gain), Value::Float(0.25))] + { + let mut field = FunctionGraph::default(); + let number = field.add("get_float1", &[], Some(Value::Text("$number".into()))); + let which = field.add_constant(Value::Float(repetition as f32)); + let active = field.add("eq", &[number, which], None); + let yes = field.add_constant(yes); + let no = field.add_constant(no); + field.output = Some(field.add("ifelse", &[active, yes, no], None)); + params.insert(name.into(), Value::Function(Box::new(field))); + } + } + graph.nodes[(leaf - 1) as usize].parameters = params; + } + let variables = BTreeMap::from([("$tiling".into(), Value::Int(0))]); + let image = cook_in_regions(graph, &variables, 310373, [64; 2], [[0.0, 1.0, 0.0, 1.0]; 2], 1.0).unwrap().remove(0); + for y in 0..32 { + for x in 0..32 { + let leaf = (0..5).fold(0, |index, bit| index | ((x >> bit) & 1) << (2 * bit) | ((y >> bit) & 1) << (2 * bit + 1)); + let expected = if leaf < first_leaves { tiny } else { 0.0 }; + assert_eq!(image.get_gray(x, y, false).to_bits(), expected.to_bits(), "{repetitions} trees at ({x},{y})"); + } + } + } +} diff --git a/crates/nodes/src/pattern/tests/sparse_quadrants.rs b/crates/nodes/src/pattern/tests/sparse_quadrants.rs new file mode 100644 index 00000000..e854c3f8 --- /dev/null +++ b/crates/nodes/src/pattern/tests/sparse_quadrants.rs @@ -0,0 +1,125 @@ +use super::*; +use materialcraft_core::OutputFormat; + +fn at_center(weight: f32, center: [f32; 2]) -> BTreeMap { + let mut frame = FunctionGraph::default(); + let target = frame.add_constant(Value::Float2(center)); + let position = frame.add("get_float2", &[], Some(Value::Text("$pos".into()))); + frame.output = Some(frame.add("sub", &[target, position], None)); + let mut params = additive_square(weight, [0.0; 2], [0.0; 2]); + params.insert("frameoffset".into(), Value::Function(Box::new(frame))); + params +} + +fn leaf_luminosity(quotas: [f32; 3]) -> Value { + let mut graph = FunctionGraph::default(); + let pos = graph.add("get_float2", &[], Some(Value::Text("$pos".into()))); + let scale = graph.add_constant(Value::Float(16.0)); + let xy = [0, 1].map(|axis| graph.add("swizzle1", &[pos], Some(Value::Int(axis)))); + let cell = xy.map(|component| { + let wide = graph.add("mul", &[component, scale], None); + let floor = graph.add("floor", &[wide], None); + let fraction = graph.add("sub", &[wide, floor], None); + let local = graph.add("mul", &[fraction, scale], None); + graph.add("floor", &[local], None) + }); + let row = graph.add("mul", &[cell[1], scale], None); + let pixel = graph.add("add", &[row, cell[0]], None); + let [ordinary, top, middle] = quotas.map(|value| graph.add_constant(Value::Float(value))); + let half = graph.add_constant(Value::Float(0.5)); + let quarter = graph.add_constant(Value::Float(0.25)); + let left = graph.add("lr", &[xy[0], half], None); + let upper_half = graph.add("lr", &[xy[1], half], None); + let upper_quarter = graph.add("lr", &[xy[1], quarter], None); + let middle_or_lower = graph.add("ifelse", &[upper_half, middle, ordinary], None); + let left_quota = graph.add("ifelse", &[upper_quarter, top, middle_or_lower], None); + let quota = graph.add("ifelse", &[left, left_quota, ordinary], None); + let active = graph.add("lr", &[pixel, quota], None); + let on = graph.add_constant(Value::Float(0.25)); + let off = graph.add_constant(Value::Float(0.0)); + graph.output = Some(graph.add("ifelse", &[active, on, off], None)); + Value::Function(Box::new(graph)) +} + +fn quadrant(graph: &mut PatternGraph, parameters: BTreeMap, children: [Option; 4]) -> u32 { + let id = graph.add(PatternNodeKind::Quadrant).unwrap(); + let node = &mut graph.nodes[(id - 1) as usize]; + node.parameters = parameters; + node.children = children.to_vec(); + id +} + +#[test] +fn sparse_quadrants_count_only_nonzero_copies_when_ordering_parent_and_leaf_draws() { + let tiny = f32::EPSILON * 0.25; + // Groups 11 and 27 have the same position within their root quadrant. + for (quotas, group, parent_first) in + [([86.0; 3], 27, false), ([96.0, 66.0, 96.0], 11, false), ([96.0, 96.0, 85.0], 11, true), ([96.0, 96.0, 85.0], 27, false)] + { + for (parent_gain, leaf_gain, reversed) in [(-1.0, tiny, false), (tiny, -1.0, true)] { + let expected = if parent_first != reversed { tiny } else { 0.0 }; + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let neutral = at_center(0.25, [0.5, 0.75]); + let mut leaves = neutral.clone(); + leaves.insert("opacity".into(), leaf_luminosity(quotas)); + let leaf = quadrant(&mut graph, leaves, [None; 4]); + let mut ordinary = quadrant(&mut graph, neutral.clone(), [Some(leaf); 4]); + let column = if group == 11 { 1.0 } else { 5.0 }; + let marker = additive_square(leaf_gain, [0.0; 2], [-column / 8.0, -3.0 / 8.0]); + let mut marked = quadrant(&mut graph, marker, [Some(leaf); 4]); + for _ in 3..7 { + ordinary = quadrant(&mut graph, neutral.clone(), [Some(ordinary); 4]); + marked = quadrant(&mut graph, neutral.clone(), [Some(marked); 4]); + } + let parent_children = [Some(ordinary); 4]; + let parent = quadrant(&mut graph, neutral.clone(), parent_children); + let mut marker = at_center(parent_gain, [1.0 / 16.0; 2]); + marker.insert("patternsize".into(), Value::Float2([0.5; 2])); + let first_parent = quadrant(&mut graph, marker, parent_children); + let mut children = parent_children; + children[3] = Some(marked); + let marked_parent = quadrant(&mut graph, neutral, children); + + let common = quadrant(&mut graph, BTreeMap::new(), [Some(parent); 4]); + let mut first_children = [Some(first_parent), Some(parent), Some(parent), Some(parent)]; + let mut second_children = [Some(parent); 4]; + if group == 11 { + first_children[2] = Some(marked_parent); + } else { + second_children[2] = Some(marked_parent); + } + let first = quadrant(&mut graph, BTreeMap::new(), first_children); + let second = quadrant(&mut graph, BTreeMap::new(), second_children); + graph.nodes[0].children = vec![Some(first), Some(second), Some(common), Some(common)]; + let definition = find("fx_map").unwrap(); + let params = resolve_params( + definition, + &BTreeMap::from([ + ("pattern".into(), Value::PatternGraph(Box::new(graph))), + ("roughness".into(), Value::Float(0.0)), + ("color_mode".into(), Value::Bool(false)), + ("background".into(), Value::Color([1.0; 4])), + ]), + ); + let vars = BTreeMap::from([("$tiling".into(), Value::Int(0))]); + let context = CookContext { + w: 128, + h: 128, + seed: 189319, + format: OutputFormat::F32, + tile: false, + inputs: &[], + input_formats: &[], + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + let output = (definition.cook)(&context).unwrap().remove(0); + for y in 0..16 { + for x in 0..16 { + assert_eq!(output.get_gray(x, y, false), expected, "at ({x}, {y}), group {group}, quotas {quotas:?}, parent gain {parent_gain}"); + } + } + } + } +} diff --git a/crates/nodes/src/pattern/tests/terminal_quadrants.rs b/crates/nodes/src/pattern/tests/terminal_quadrants.rs new file mode 100644 index 00000000..9112aca3 --- /dev/null +++ b/crates/nodes/src/pattern/tests/terminal_quadrants.rs @@ -0,0 +1,359 @@ +use super::paired_batches::field_property; +use super::*; +use craft_texture::{Image, Kind}; +use materialcraft_core::OutputFormat; + +// Each depth-six parent draws before four children, each followed by four leaves. +// Address the three levels in separate columns and successive iterations in separate rows. +fn location(draw: u32) -> (u32, u32) { + let iteration = draw / 86_016; + let parent = draw % 86_016 / 21; + let within = draw % 21; + let (depth, visit, column) = match within { + 0 => (6, parent, 384), + n if (n - 1) % 5 == 0 => (7, parent * 4 + (n - 1) / 5, 256), + n => (8, parent * 16 + (n - 1) / 5 * 4 + (n - 2) % 5, 0), + }; + let mut x = 0; + let mut y = 0; + for bit in 0..depth { + x |= ((visit >> (2 * bit)) & 1) << bit; + y |= ((visit >> (2 * bit + 1)) & 1) << bit; + } + (column + x, iteration * 256 + y) +} + +fn check_terminal_levels(expanded: bool) { + for (count, markers) in [ + (1, [(28193, 32245, false), (52923, 80165, false), (13176, 44146, true), (9090, 37313, false), (17308, 46423, true), (6792, 15213, false)]), + (2, [(148776, 167500, false), (108044, 154830, false), (2356, 50934, true), (80910, 98000, false), (24344, 108669, true), (29011, 120962, false)]), + (4, [(81374, 106292, false), (261307, 262710, false), (43010, 163056, true), (224189, 266224, false), (176006, 303409, true), (52157, 146973, false)]), + ] { + check_terminal_case(count, expanded, 0, 257831 + 19 * count as u32, &markers, None); + } +} + +fn check_terminal_case(count: i32, expanded: bool, extra_limit: u32, seed: u32, markers: &[(u32, u32, bool)], route: Option<(u32, PatternNodeKind)>) { + // In a white pixel a tiny positive value survives only when the negative square draws first. + let tiny = f32::EPSILON * 0.25; + let root = if count == 1 { PatternNodeKind::Quadrant } else { PatternNodeKind::Iterate }; + let mut graph = PatternGraph::with_root(root); + let mut parent = graph.root.unwrap(); + if count > 1 { + parent = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].parameters.insert("numberadded".into(), set_then_return("tree_index", Value::Float(-1.0), Value::Int(count))); + graph.nodes[(parent - 1) as usize].parameters.insert("branchoffset".into(), advance_tree_offset()); + graph.nodes[0].children[1] = Some(parent); + } + if let Some((0, kind)) = route { + let child = graph.root; + let relay = graph.add(kind).unwrap(); + graph.nodes[(relay - 1) as usize].children[0] = child; + graph.root = Some(relay); + } + for depth in 1..=8 { + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(parent - 1) as usize].children.fill(Some(child)); + if let Some((level, kind)) = route + && depth == level + { + let relay = graph.add(kind).unwrap(); + graph.nodes[(relay - 1) as usize].children[0] = Some(child); + graph.nodes[(parent - 1) as usize].children[0] = Some(relay); + } + if depth >= 6 { + let column = match depth { + 6 => 384, + 7 => 256, + _ => 0, + }; + let offset = [column as f32 / 1024.0, 0.0]; + let mut properties = additive_square(0.25, [0.0; 2], [0.0; 2]); + properties.insert("frameoffset".into(), field_property(depth, offset, true, count > 1)); + properties.insert("opacity".into(), field_property(depth, offset, false, count > 1)); + graph.nodes[(child - 1) as usize].parameters = properties; + } + parent = child; + } + let definition = find("fx_map").unwrap(); + let params = resolve_params( + definition, + &BTreeMap::from([ + ("pattern".into(), Value::PatternGraph(Box::new(graph))), + ("roughness".into(), Value::Float(0.0)), + ("color_mode".into(), Value::Bool(false)), + ("background".into(), Value::Color([1.0; 4])), + ("tiling_region".into(), Value::Float4(if expanded { [-0.5, 1.5, -0.5, 1.5] } else { [0.0, 1.0, 0.0, 1.0] })), + ]), + ); + let axes = if expanded { count - 1 } else { i32::from(extra_limit > 0) }; + let variables = BTreeMap::from([("$tiling".into(), Value::Int(axes))]); + let mut field = BTreeMap::new(); + if extra_limit > 0 { + for group in 0..count as u32 * 64 { + let extras = 1 + (7 * group + 3) % extra_limit; + for draw in 1344 * group..1344 * group + extras { + field.insert(location(draw), [0.0, 0.90625, 0.25, 1.0]); + } + } + } + for (j, &(negative, positive, _)) in markers.iter().enumerate() { + let x = (8.5 + j as f32) / 128.0; + field.insert(location(negative), [x, 12.5 / 128.0, -1.0, 1.0]); + field.insert(location(positive), [x, 12.5 / 128.0, tiny, 1.0]); + } + let input = Image::generate(1024, 1024, Kind::Color, |x, y| field.get(&(x, y)).copied().unwrap_or([0.875, 0.90625, 0.25, 1.0])); + let inputs = [None, Some(input)]; + let context = CookContext { + w: 128, + h: 128, + seed, + format: OutputFormat::F32, + tile: true, + inputs: &inputs, + input_formats: &[OutputFormat::F32; 2], + params: ¶ms, + resource: &|_| None, + vars: &variables, + }; + let image = (definition.cook)(&context).unwrap().remove(0); + for (j, &(_, _, negative_first)) in markers.iter().enumerate() { + assert_eq!(image.get_gray(8 + j as i64, 12, false), if negative_first { tiny } else { 0.0 }, "{count} trees, marker {j}"); + } +} + +#[test] +fn terminal_quadrants_preserve_draw_order_through_an_outer_route() { + let markers = [(148776, 167500, false), (2356, 50934, true), (29011, 120962, false)]; + for route in [PatternNodeKind::Dot, PatternNodeKind::Switch] { + check_terminal_case(2, false, 0, 255151, &markers, Some((0, route))); + } +} + +#[test] +fn an_interior_route_preserves_terminal_draw_order() { + let markers = [(148776, 167500, false), (2356, 50934, true), (29011, 120962, false)]; + for (level, kind) in [(1, PatternNodeKind::Dot), (3, PatternNodeKind::Switch), (8, PatternNodeKind::Dot)] { + check_terminal_case(2, false, 0, 255151, &markers, Some((level, kind))); + } +} + +#[test] +fn three_terminal_levels_interleave_repeated_quadrant_trees() { + check_terminal_levels(false); +} + +#[test] +fn single_copy_terminal_trees_use_the_same_order_in_wide_tiling_regions() { + check_terminal_levels(true); +} + +#[test] +fn partly_wrapped_terminal_quadrants_fill_each_physical_batch() { + for (count, limit, seed, markers) in [ + (1, 5, 275418, [(29710, 61959, false), (69391, 59206, true), (70042, 81747, false), (85417, 29721, true), (48532, 62040, false), (83643, 70043, true)]), + ( + 2, + 14, + 275459, + [(109064, 165953, false), (164259, 152021, true), (37714, 69543, false), (109902, 106389, true), (148173, 169808, false), (112642, 94347, true)], + ), + ( + 4, + 19, + 275541, + [(179109, 248770, false), (207897, 148080, true), (6866, 144342, false), (327758, 324304, true), (109032, 131846, false), (180497, 179055, true)], + ), + ] { + check_terminal_case(count, false, limit, seed, &markers, None); + } +} + +// A depth-seven parent followed by its four depth-eight children. Both coordinates address the procedural input in Morton order. +fn final_pair_location(draw: u32) -> (u32, u32) { + let parent = draw / 5; + let child = draw % 5; + let axis = |shift: u32| (0..7).fold(0, |coordinate, bit| coordinate | (((parent >> (2 * bit + shift)) & 1) << bit)); + let (x, y) = (axis(0), axis(1)); + if child == 0 { (512 + x, y) } else { (2 * x + (child - 1) % 2, 2 * y + (child - 1) / 2) } +} + +enum FinalPairTree { + Plain, + InactiveChildren, + RepeatedChildren, +} + +fn first_quadrant_repeat_offset() -> Value { + let mut graph = FunctionGraph::default(); + let pos = graph.add("get_float2", &[], Some(Value::Text("$pos".into()))); + let x = graph.add("swizzle1", &[pos], Some(Value::Int(0))); + let y = graph.add("swizzle1", &[pos], Some(Value::Int(1))); + let furthest = graph.add("max", &[x, y], None); + let boundary = graph.add_constant(Value::Float(1.0 / 64.0)); + let first = graph.add("lr", &[furthest, boundary], None); + let two = graph.add_constant(Value::Int(2)); + let one = graph.add_constant(Value::Int(1)); + let count = graph.add("ifelse", &[first, two, one], None); + let set = graph.add("set", &[count], Some(Value::Text("child_repeat".into()))); + let offset = graph.add_constant(Value::Float2([0.0; 2])); + graph.output = Some(graph.add("sequence", &[set, offset], None)); + Value::Function(Box::new(graph)) +} + +fn check_final_pair_markers(tree: FinalPairTree, wrapped: bool, origin: [f32; 2], markers: &[(u32, u32, bool)]) { + let inactive_children = !matches!(tree, FinalPairTree::Plain); + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let mut parent = graph.root.unwrap(); + for depth in 1..=8 { + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(parent - 1) as usize].children.fill(Some(child)); + if depth == 7 && matches!(tree, FinalPairTree::RepeatedChildren) { + // Only the first depth-six quadrant submits each of its children twice. + let relay = graph.add(PatternNodeKind::Iterate).unwrap(); + let mut count = FunctionGraph::default(); + count.output = Some(count.add("get_integer1", &[], Some(Value::Text("child_repeat".into())))); + graph.nodes[(relay - 1) as usize].parameters.insert("numberadded".into(), Value::Function(Box::new(count))); + graph.nodes[(relay - 1) as usize].children[1] = Some(child); + graph.nodes[(parent - 1) as usize].parameters.insert("branchoffset".into(), first_quadrant_repeat_offset()); + graph.nodes[(parent - 1) as usize].children.fill(Some(relay)); + } + if depth >= 7 { + let offset = [if depth == 7 { 0.5 } else { 0.0 }, 0.0]; + let mut parameters = additive_square(0.25, [0.0; 2], [0.0; 2]); + parameters.insert("patternsize".into(), Value::Float2([0.875 * (1 << depth) as f32 / 128.0; 2])); + parameters.insert("frameoffset".into(), field_property(depth, offset, true, false)); + parameters.insert("opacity".into(), field_property(depth, offset, false, false)); + graph.nodes[(child - 1) as usize].parameters = parameters; + } + parent = child; + } + if inactive_children { + let gate = graph.add(PatternNodeKind::Switch).unwrap(); + let branch = graph.add(PatternNodeKind::Quadrant).unwrap(); + let leaf = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(parent - 1) as usize].children.fill(Some(gate)); + graph.nodes[(gate - 1) as usize].children[1] = Some(branch); + graph.nodes[(branch - 1) as usize].children[0] = Some(leaf); + assert_eq!(graph.validated_depth().unwrap(), 10); + } + let mut field = BTreeMap::new(); + if wrapped { + // The second child of every 64th parent crosses the left edge. + for draw in (2..81_920).step_by(320) { + field.insert(final_pair_location(draw), [0.0, 0.90625, 0.25, 1.0]); + } + } + let tiny = f32::EPSILON * 0.25; + for (j, &(negative, positive, _)) in markers.iter().enumerate() { + let x = (8.5 + j as f32) / 128.0; + field.insert(final_pair_location(negative), [x, 12.5 / 128.0, -1.0, 1.0]); + field.insert(final_pair_location(positive), [x, 12.5 / 128.0, tiny, 1.0]); + } + let input = Image::generate(1024, 1024, Kind::Color, |x, y| { + let [cx, cy, gain, alpha] = field.get(&(x, y)).copied().unwrap_or([0.875, 0.90625, 0.25, 1.0]); + [cx + origin[0], cy + origin[1], gain, alpha] + }); + let inputs = [None, Some(input)]; + let window = Value::Float4([origin[0], origin[0] + 1.0, origin[1], origin[1] + 1.0]); + let variables = BTreeMap::from([("$tiling".into(), Value::Int(if inactive_children { 3 } else { 1 }))]); + let definition = find("fx_map").unwrap(); + let params = resolve_params( + definition, + &BTreeMap::from([ + ("pattern".into(), Value::PatternGraph(Box::new(graph))), + ("roughness".into(), Value::Float(0.0)), + ("color_mode".into(), Value::Bool(false)), + ("background".into(), Value::Color([1.0; 4])), + ("render_region".into(), window.clone()), + ("tiling_region".into(), window), + ]), + ); + let context = CookContext { + w: 128, + h: 128, + seed: 560071, + format: OutputFormat::F32, + tile: true, + inputs: &inputs, + input_formats: &[OutputFormat::F32; 2], + params: ¶ms, + resource: &|_| None, + vars: &variables, + }; + let image = (definition.cook)(&context).unwrap().remove(0); + for (j, &(_, _, first)) in markers.iter().enumerate() { + assert_eq!(image.get_gray(8 + j as i64, 12, false), if first { tiny } else { 0.0 }, "marker {j}"); + } +} + +#[test] +fn final_pair_batches_precede_the_next_subtree_above_inactive_children() { + check_final_pair_markers( + FinalPairTree::InactiveChildren, + false, + [0.0; 2], + &[ + (36179, 51200, true), + (36180, 51209, false), + (30717, 30722, false), + (56659, 10240, true), + (56660, 10249, false), + (51197, 51203, false), + (15699, 64000, true), + (15700, 64009, false), + (10237, 10243, false), + (23599, 24029, false), + (74240, 79, true), + (3119, 69149, false), + (69120, 41039, true), + (40959, 44109, false), + ], + ); + check_final_pair_markers( + FinalPairTree::InactiveChildren, + true, + [0.0; 2], + &[(64000, 20559, true), (23599, 24029, false), (76101, 7902, true), (69817, 48750, true)], + ); + check_final_pair_markers(FinalPairTree::InactiveChildren, false, [0.125, -0.25], &[(36180, 51209, false), (30717, 30722, false), (56659, 10240, true)]); +} + +#[test] +fn inactive_quadrants_count_repeated_draws_in_their_own_subtree() { + check_final_pair_markers( + FinalPairTree::RepeatedChildren, + false, + [0.0; 2], + &[(30719, 2880, true), (49479, 36180, true), (63999, 23520, true), (67359, 8980, true)], + ); +} + +#[test] +fn final_pair_batches_keep_the_four_child_order_with_one_tiling_axis() { + check_final_pair_markers( + FinalPairTree::Plain, + true, + [0.0; 2], + &[(43841, 15684, true), (2893, 41170, false), (7078, 57951, false), (27212, 9738, false), (28838, 38806, false), (46736, 72040, false)], + ); + check_final_pair_markers( + FinalPairTree::Plain, + false, + [0.0; 2], + &[ + (44397, 27843, true), + (27885, 71936, false), + (4416, 39465, false), + (36850, 15761, false), + (30513, 57392, true), + (47200, 36364, false), + (73365, 18745, false), + (1690, 24737, true), + (28478, 43002, false), + (70020, 5532, true), + (29835, 4097, true), + (7465, 38479, false), + ], + ); +} diff --git a/crates/nodes/src/pattern/tests/underfilled_quadrants.rs b/crates/nodes/src/pattern/tests/underfilled_quadrants.rs new file mode 100644 index 00000000..ab0a2685 --- /dev/null +++ b/crates/nodes/src/pattern/tests/underfilled_quadrants.rs @@ -0,0 +1,471 @@ +use super::*; + +fn overlapping_subtree_pixel(repetitions: i32, negative_gain: f32, wide_first_level: bool) -> f32 { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + let root = graph.root.unwrap(); + if repetitions > 1 { + let iterate = graph.add(PatternNodeKind::Iterate).unwrap(); + graph.root = Some(iterate); + let node = &mut graph.nodes[(iterate - 1) as usize]; + node.children[1] = Some(root); + node.parameters.insert("numberadded".into(), Value::Int(repetitions)); + } + let mut tail = graph.add(PatternNodeKind::Quadrant).unwrap(); + for _ in 4..8 { + let parent = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(parent - 1) as usize].children.fill(Some(tail)); + tail = parent; + } + + let mut parents = vec![(root, [0_usize; 2])]; + for depth in 1..=3 { + let mut children = Vec::new(); + for (parent, [x, y]) in parents { + for slot in 0..4 { + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(parent - 1) as usize].children[slot] = Some(child); + let cell = [2 * x + slot % 2, 2 * y + slot / 2]; + if depth == 1 && wide_first_level { + let node = &mut graph.nodes[(child - 1) as usize]; + node.parameters = BTreeMap::from([ + ("patterntype".into(), Value::Int(6)), + ("blendingmode".into(), Value::Int(0)), + ("patternsize".into(), Value::Float2([5.5 + slot as f32, 7.75 - 0.5 * slot as f32])), + ("patternrotation".into(), Value::Float([0.0, 0.125, 0.21875, 0.34375][slot])), + ("opacity".into(), Value::Float(2.0_f32.powi(-80))), + ]); + } + if depth == 3 { + let index = children.len(); + let (target, gain) = match index { + 50 => (0.25, negative_gain), + 0 => (0.25, 2.0_f32.powi(-25)), + _ => (0.75, 0.125), + }; + let shift = cell.map(|coordinate| target - (coordinate as f32 + 0.5) / 8.0); + let node = &mut graph.nodes[(child - 1) as usize]; + node.parameters = additive_square(gain, [0.0; 2], shift); + node.children.fill(Some(tail)); + } + children.push((child, cell)); + } + } + parents = children; + } + let image = cook_in_regions(graph, &BTreeMap::new(), 41381, [32; 2], [[0.0, 1.0, 0.0, 1.0]; 2], 1.0).unwrap().remove(0); + image.get_gray(8, 8, false) +} + +#[test] +fn overlapping_subtrees_in_an_underfilled_eight_level_tree() { + let small = 2.0_f32.powi(-25); + assert_eq!(overlapping_subtree_pixel(1, -1.0, false).to_bits(), small.to_bits()); + // The three negative draws reach 0.25 before the three small additions. + assert_eq!(overlapping_subtree_pixel(3, -0.25, false).to_bits(), (0.25 + 3.0 * small).to_bits()); +} + +#[test] +fn wide_first_level_stamps_keep_the_order_of_deeper_draws() { + assert_eq!(overlapping_subtree_pixel(1, -1.0, true).to_bits(), 2.0_f32.powi(-25).to_bits()); +} + +enum Continuation { + None, + EmptySwitch, + InactiveBranch(u32), + ActiveTrees(i32), + RoutedIteration(PatternNodeKind), +} + +fn on_tree_pass(graph: &mut FunctionGraph, pass: i32) -> u32 { + let index = graph.add("get_float1", &[], Some(Value::Text("tree_index".into()))); + let pass = graph.add_constant(Value::Float(pass as f32)); + graph.add("eq", &[index, pass], None) +} + +fn corner_offset(pass: Option) -> FunctionGraph { + let mut offset = FunctionGraph::default(); + let origin = offset.add_constant(Value::Float2([0.0; 2])); + let center = offset.add("get_float2", &[], Some(Value::Text("$pos".into()))); + let shift = offset.add("sub", &[origin, center], None); + offset.output = Some(if let Some(pass) = pass { + let active = on_tree_pass(&mut offset, pass); + offset.add("ifelse", &[active, shift, origin], None) + } else { + shift + }); + offset +} + +fn quadrant_tail(graph: &mut PatternGraph, first_depth: usize, mut next: Option, mut leaf_offset: Option) -> Option { + for depth in (first_depth..=8).rev() { + let id = graph.add(PatternNodeKind::Quadrant).unwrap(); + let node = &mut graph.nodes[(id - 1) as usize]; + node.parameters = additive_square(2.0_f32.powi(-76), [0.0; 2], [0.0; 2]); + if depth == 8 + && let Some(offset) = leaf_offset.take() + { + node.parameters.insert("frameoffset".into(), Value::Function(Box::new(offset))); + } + node.children.fill(next); + next = Some(id); + } + next +} + +fn filled_tree_pixel(negative: (usize, usize), positive: (usize, usize), continuation: Continuation, wrapped_subtrees: &[usize]) -> f32 { + marked_tree_pixel(negative, positive, continuation, wrapped_subtrees, None, None) +} + +fn marked_tree_pixel( + negative: (usize, usize), + positive: (usize, usize), + continuation: Continuation, + wrapped_subtrees: &[usize], + marker_iterations: Option<[i32; 2]>, + wrap_iteration: Option, +) -> f32 { + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let iterate = graph.root.unwrap(); + let root = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(iterate - 1) as usize].children[1] = Some(root); + if marker_iterations.is_some() || wrap_iteration.is_some() { + let count = match continuation { + Continuation::ActiveTrees(count) => count, + _ => 2, + }; + graph.nodes[(iterate - 1) as usize].parameters.insert("numberadded".into(), set_then_return("tree_index", Value::Float(0.0), Value::Int(count))); + graph.nodes[(root - 1) as usize].parameters.insert("branchoffset".into(), advance_tree_offset()); + } + let end = matches!(continuation, Continuation::EmptySwitch).then(|| graph.add(PatternNodeKind::Switch).unwrap()); + let marked_depth = negative.0.max(positive.0).max(3); + let plain = quadrant_tail(&mut graph, marked_depth + 1, end, None); + let wrapped = if wrapped_subtrees.is_empty() { plain } else { quadrant_tail(&mut graph, marked_depth + 1, end, Some(corner_offset(wrap_iteration))) }; + // Share the unmarked subtrees so a sixth-level marker fits in an ordinary pattern graph. + let unmarked = quadrant_tail(&mut graph, marked_depth, end, None); + let unmarked_wrapped = + if wrapped_subtrees.is_empty() { unmarked } else { quadrant_tail(&mut graph, marked_depth, end, Some(corner_offset(wrap_iteration))) }; + let mut parents = vec![(root, [0_usize; 2])]; + for depth in 1..=marked_depth { + let mut children = Vec::new(); + for (parent_index, (parent, [x, y])) in parents.into_iter().enumerate() { + for slot in 0..4 { + let ordinal = parent_index * 4 + slot; + if depth == marked_depth && (depth, ordinal) != negative && (depth, ordinal) != positive { + graph.nodes[(parent - 1) as usize].children[slot] = if wrapped_subtrees.contains(&ordinal) { unmarked_wrapped } else { unmarked }; + continue; + } + let id = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(parent - 1) as usize].children[slot] = Some(id); + let cell = [2 * x + slot % 2, 2 * y + slot / 2]; + let node = &mut graph.nodes[(id - 1) as usize]; + if depth >= 2 { + let marker = (depth, ordinal); + let (gain, shift) = if marker == negative || marker == positive { + let shift = cell.map(|i| 0.265625 - (i as f32 + 0.5) / (1 << depth) as f32); + (if marker == negative { -1.0 } else { 2.0_f32.powi(-25) }, shift) + } else { + (2.0_f32.powi(-76), [0.0; 2]) + }; + node.parameters = additive_square(gain, [0.0; 2], shift); + if let Some(passes) = marker_iterations + && (marker == negative || marker == positive) + { + let mut select = FunctionGraph::default(); + let active = on_tree_pass(&mut select, passes[usize::from(marker == positive)]); + let mark = select.add_constant(Value::Float(gain)); + let ordinary = select.add_constant(Value::Float(2.0_f32.powi(-76))); + select.output = Some(select.add("ifelse", &[active, mark, ordinary], None)); + node.parameters.insert("opacity".into(), Value::Function(Box::new(select))); + } + } + if depth == marked_depth { + node.children.fill(if wrapped_subtrees.contains(&ordinal) { wrapped } else { plain }); + } + children.push((id, cell)); + } + } + parents = children; + } + let inactive_depth = match continuation { + Continuation::InactiveBranch(depth) => Some(depth), + Continuation::ActiveTrees(_) | Continuation::RoutedIteration(_) => Some(10), + _ => None, + }; + if let Some(depth) = inactive_depth { + let mut child = graph.add(PatternNodeKind::Quadrant).unwrap(); + for _ in 0..depth { + let parent = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[(parent - 1) as usize].children[0] = Some(child); + child = parent; + } + let switch = graph.add(PatternNodeKind::Switch).unwrap(); + graph.nodes[(switch - 1) as usize].children = vec![Some(root), Some(child)]; + graph.nodes[(iterate - 1) as usize].children[1] = Some(switch); + } + if let Continuation::RoutedIteration(kind) = continuation { + let relay = graph.add(kind).unwrap(); + graph.nodes[(relay - 1) as usize].children[0] = Some(iterate); + graph.root = Some(relay); + } + let image = cook_in_regions(graph, &BTreeMap::new(), 41381, [32; 2], [[0.0, 1.0, 0.0, 1.0]; 2], 1.0).unwrap().remove(0); + image.get_gray(8, 8, false) +} + +fn filled_quadrant_pixel(negative: usize, positive: usize, continuation: Continuation) -> f32 { + filled_tree_pixel((2, negative), (2, positive), continuation, &[]) +} + +#[test] +fn successive_quadrant_batches_preserve_their_child_ranges() { + for (negative, positive) in [((2, 14), (2, 8)), ((2, 1), (3, 2)), ((2, 13), (2, 8)), ((2, 9), (3, 34))] { + assert_eq!(filled_tree_pixel(negative, positive, Continuation::EmptySwitch, &[]).to_bits(), 2.0_f32.powi(-25).to_bits()); + } + assert_eq!(filled_quadrant_pixel(14, 8, Continuation::None).to_bits(), 2.0_f32.powi(-25).to_bits()); +} + +#[test] +fn wrapped_leaves_can_fill_a_quadrant_batch_before_a_leading_pair() { + assert_eq!(filled_tree_pixel((2, 14), (2, 2), Continuation::EmptySwitch, &[]).to_bits(), 0); + assert_eq!(filled_tree_pixel((2, 14), (2, 2), Continuation::EmptySwitch, &[58]).to_bits(), 2.0_f32.powi(-25).to_bits()); +} + +#[test] +fn a_repeated_quadrant_pair_submits_draws_from_both_trees() { + for (negative, positive, passes) in [((3, 52), (3, 2), [1, 1]), ((2, 6), (3, 56), [2, 1]), ((2, 10), (3, 2), [2, 1])] { + let sample = marked_tree_pixel(negative, positive, Continuation::EmptySwitch, &[], Some(passes), None); + assert_eq!(sample.to_bits(), 2.0_f32.powi(-25).to_bits()); + } +} + +#[test] +fn wrapped_copies_can_fill_a_third_batch_in_the_next_tree() { + let pixel = |subtrees: &[usize]| marked_tree_pixel((3, 30), (2, 10), Continuation::EmptySwitch, subtrees, Some([2, 2]), Some(2)); + assert_eq!(pixel(&[25]).to_bits(), 2.0_f32.powi(-25).to_bits()); + assert_eq!(pixel(&[]).to_bits(), 0); +} + +#[test] +fn a_second_tree_quadrant_precedes_the_last_first_tree_pair_at_depth_ten() { + let pixel = marked_tree_pixel((2, 2), (3, 60), Continuation::InactiveBranch(10), &[], Some([2, 1]), None); + assert_eq!(pixel.to_bits(), 2.0_f32.powi(-25).to_bits()); +} + +#[test] +fn outer_iteration_retains_its_batches_through_a_routing_node() { + for kind in [PatternNodeKind::Switch, PatternNodeKind::Dot] { + let pixel = marked_tree_pixel((2, 2), (3, 60), Continuation::RoutedIteration(kind), &[], Some([2, 1]), None); + assert_eq!(pixel.to_bits(), 2.0_f32.powi(-25).to_bits()); + } +} + +#[test] +fn a_carried_middle_pair_precedes_the_remaining_first_tree_quadrant() { + let pixel = marked_tree_pixel((3, 60), (3, 2), Continuation::InactiveBranch(10), &[], Some([2, 1]), None); + assert_eq!(pixel.to_bits(), 2.0_f32.powi(-25).to_bits()); +} + +#[test] +fn a_first_tree_batch_keeps_its_place_before_carried_quadrants() { + let pixel = |negative, positive, passes| marked_tree_pixel(negative, positive, Continuation::InactiveBranch(10), &[34], Some(passes), Some(1)); + assert_eq!(pixel((3, 60), (2, 6), [1, 2]).to_bits(), 2.0_f32.powi(-25).to_bits()); + assert_eq!(pixel((2, 6), (3, 2), [2, 1]).to_bits(), 2.0_f32.powi(-25).to_bits()); +} + +#[test] +fn the_next_collecting_quadrant_reaches_the_second_tree() { + let pixel = marked_tree_pixel((3, 50), (3, 7), Continuation::InactiveBranch(10), &[], Some([2, 1]), None); + assert_eq!(pixel.to_bits(), 2.0_f32.powi(-25).to_bits()); +} + +#[test] +fn a_full_copy_batch_defers_siblings_at_the_current_quadrant() { + let pixel = |wrapped: &[usize]| marked_tree_pixel((5, 270), (5, 268), Continuation::InactiveBranch(10), wrapped, Some([2, 2]), Some(1)); + assert_eq!(pixel(&[]).to_bits(), 2.0_f32.powi(-25).to_bits()); + // Moving 64 leaves to a tile corner adds 192 copies before the same two markers. + assert_eq!(pixel(&[32]).to_bits(), 0); +} + +#[test] +fn later_full_batches_reach_subsequent_collecting_quadrants() { + for (negative, positive, passes) in [((3, 17), (3, 7), [2, 1]), ((3, 35), (3, 33), [2, 2]), ((3, 58), (3, 1), [2, 2])] { + let pixel = marked_tree_pixel(negative, positive, Continuation::InactiveBranch(10), &[], Some(passes), None); + assert_eq!(pixel.to_bits(), 2.0_f32.powi(-25).to_bits()); + } +} + +#[test] +fn a_collecting_batch_can_fill_before_the_next_quadrant_pair_starts() { + let sample = |wrapped: &[usize]| marked_tree_pixel((5, 32), (5, 384), Continuation::InactiveBranch(10), wrapped, Some([1, 2]), Some(1)); + let small = 2.0_f32.powi(-25); + assert!(sample(&[32, 33, 34, 35]) < small * 0.5); + assert_eq!(sample(&[32, 33, 34, 35, 36]).to_bits(), small.to_bits()); +} + +#[test] +fn receiving_groups_submit_before_their_own_carried_pair() { + let small = 2.0_f32.powi(-25); + for (negative, positive, first, count) in [(880, 671, 864, 7), (943, 169, 928, 4)] { + let wrapped: Vec<_> = (first..first + count).collect(); + let sample = |wrapped: &[usize]| marked_tree_pixel((5, negative), (5, positive), Continuation::ActiveTrees(2), wrapped, Some([2, 2]), Some(2)); + assert!(sample(&wrapped[..count - 1]) < small * 0.5); + assert_eq!(sample(&wrapped).to_bits(), small.to_bits()); + } +} + +#[test] +fn a_transferred_sibling_can_fill_the_receiving_group() { + let sample = marked_tree_pixel((5, 939), (5, 169), Continuation::ActiveTrees(2), &[928], Some([2, 2]), Some(1)); + assert_eq!(sample.to_bits(), 2.0_f32.powi(-25).to_bits()); +} + +#[test] +fn carried_pairs_can_fill_before_the_following_tree_starts() { + let small = 2.0_f32.powi(-25); + for trees in [2, 3, 4] { + let sample = marked_tree_pixel((3, 56), (3, 48), Continuation::ActiveTrees(trees), &[], Some([2, 2]), None); + assert_eq!(sample.to_bits(), small.to_bits(), "{trees} trees"); + } +} + +#[test] +fn a_receiving_batch_precedes_the_upper_pair_after_a_sibling_transfer() { + let sample = |first, second, wrapped: &[usize]| marked_tree_pixel((5, first), (5, second), Continuation::ActiveTrees(2), wrapped, Some([2, 2]), Some(2)); + let small = 2.0_f32.powi(-25); + assert_eq!(sample(896, 336, &[]).to_bits(), small.to_bits()); + // The 64 corner squares add 192 copies. The lower pair hands off two + // siblings, and the receiving batch and upper pair both precede the last pair. + assert_eq!(sample(336, 896, &[832]).to_bits(), small.to_bits()); + assert_eq!(sample(896, 768, &[832]).to_bits(), small.to_bits()); +} + +#[test] +fn subsequent_trees_keep_completed_quadrant_batches_ahead_of_unfinished_groups() { + let small = 2.0_f32.powi(-25).to_bits(); + for trees in [3, 4] { + let sample = + |first, second| marked_tree_pixel((5, first), (5, second), Continuation::ActiveTrees(trees), &[832, 896, 897], Some([2, 2]), Some(2)).to_bits(); + assert_eq!(sample(896, 768), small, "{trees} trees"); + assert_eq!(sample(336, 80), small, "{trees} trees"); + } +} + +#[test] +fn third_tree_pairs_fill_with_copies_carried_from_the_second_tree() { + let small = 2.0_f32.powi(-25).to_bits(); + for (negative, positive) in [(384, 80), (640, 80)] { + let sample = marked_tree_pixel((5, negative), (5, positive), Continuation::ActiveTrees(3), &[832, 896, 897], Some([3, 2]), Some(2)); + assert_eq!(sample.to_bits(), small); + } +} + +#[test] +fn third_tree_pairs_keep_single_sibling_transfers_ahead_of_waiting_draws() { + let mut wrapped: Vec<_> = (3328..3331).chain(3584..3587).collect(); + let small = 2.0_f32.powi(-25).to_bits(); + for negative in [1536, 2560] { + let sample = marked_tree_pixel((6, negative), (6, 320), Continuation::ActiveTrees(4), &wrapped, Some([3, 2]), Some(2)); + assert_eq!(sample.to_bits(), small); + } + let incoming = |wrapped: &[usize]| marked_tree_pixel((6, 2200), (6, 2560), Continuation::ActiveTrees(4), wrapped, Some([2, 3]), Some(2)); + assert_eq!(incoming(&wrapped).to_bits(), small); + // Extra copies move the cut across one more depth-five child. + wrapped.extend(2112..2115); + assert!(incoming(&wrapped) < f32::from_bits(small) * 0.5); +} + +#[test] +fn third_tree_receivers_take_children_when_neither_pair_has_a_pending_sibling() { + let small = 2.0_f32.powi(-25).to_bits(); + for (negative, positive, passes) in [(551, 544, [2, 2]), (384, 80, [3, 2]), (640, 80, [3, 2])] { + let sample = marked_tree_pixel((5, negative), (5, positive), Continuation::ActiveTrees(3), &[], Some(passes), None); + assert_eq!(sample.to_bits(), small); + } +} + +#[test] +fn third_tree_receivers_continue_a_collecting_group_before_the_final_pair() { + let wrapped: Vec<_> = (3328..3331).chain(3584..3587).collect(); + let small = 2.0_f32.powi(-25).to_bits(); + for (negative, positive) in [(3712, 1008), (512, 2494)] { + let sample = marked_tree_pixel((6, negative), (6, positive), Continuation::ActiveTrees(4), &wrapped, Some([3, 2]), Some(2)); + assert_eq!(sample.to_bits(), small); + } +} + +#[test] +fn unfinished_quadrant_groups_receive_children_after_the_full_batches() { + let sample = |first, second| marked_tree_pixel((5, first), (5, second), Continuation::ActiveTrees(2), &[832, 896, 897], Some([2, 2]), Some(2)).to_bits(); + let small = 2.0_f32.powi(-25).to_bits(); + // The upper pair gives a child to the first group. A sibling from that + // group's own cut is drawn only after the middle quadrant has finished. + assert_eq!(sample(924, 624), small); + assert_eq!(sample(624, 924), 0); + assert_eq!(sample(972, 541), small); + assert_eq!(sample(541, 972), 0); +} + +#[test] +fn earlier_sibling_transfers_keep_their_order_across_repeated_trees() { + let small = 2.0_f32.powi(-25); + for trees in [2, 3, 4] { + let sample = marked_tree_pixel((5, 32), (5, 30), Continuation::ActiveTrees(trees), &[928], Some([1, 1]), Some(1)); + assert_eq!(sample.to_bits(), small.to_bits(), "{trees} trees"); + } +} + +#[test] +fn a_full_quadrant_pair_transfers_its_pending_sibling() { + let sample = + |negative, positive, wrapped: &[usize]| marked_tree_pixel((5, negative), (5, positive), Continuation::ActiveTrees(1), wrapped, Some([1, 1]), Some(1)); + let small = 2.0_f32.powi(-25); + assert!(sample(32, 30, &[]) < small * 0.5); + assert_eq!(sample(32, 30, &[928]).to_bits(), small.to_bits()); + assert!(sample(30, 32, &[928]) < small * 0.5); +} + +#[test] +fn a_single_tree_drains_the_middle_quadrant_before_the_carried_pair() { + let sample = |negative, positive| marked_tree_pixel((3, negative), (3, positive), Continuation::ActiveTrees(1), &[], Some([1, 1]), None); + assert_eq!(sample(60, 52).to_bits(), 2.0_f32.powi(-25).to_bits()); + assert_eq!(sample(52, 60).to_bits(), 0); +} + +#[test] +fn pending_quadrants_finish_after_the_last_full_batches() { + for ordinal in [336, 592] { + let sample = marked_tree_pixel((5, ordinal), (5, 80), Continuation::InactiveBranch(10), &[624], Some([2, 2]), Some(1)); + assert_eq!(sample.to_bits(), 2.0_f32.powi(-25).to_bits()); + } + let upper = marked_tree_pixel((5, 896), (5, 768), Continuation::InactiveBranch(10), &[624], Some([2, 2]), Some(1)); + assert_eq!(upper.to_bits(), 2.0_f32.powi(-25).to_bits()); +} + +#[test] +fn filled_quadrant_batches_submit_the_middle_pair_before_the_upper_pair() { + assert_eq!(filled_quadrant_pixel(10, 2, Continuation::None).to_bits(), 2.0_f32.powi(-25).to_bits()); +} + +#[test] +fn a_full_batch_collects_separate_ranges_of_the_last_quadrant() { + assert_eq!(filled_quadrant_pixel(15, 4, Continuation::None).to_bits(), 2.0_f32.powi(-25).to_bits()); +} + +#[test] +fn a_filled_batch_can_start_in_the_first_branch_of_the_last_quadrant() { + assert_eq!(filled_quadrant_pixel(12, 0, Continuation::None).to_bits(), 2.0_f32.powi(-25).to_bits()); +} + +#[test] +fn a_closed_switch_below_the_final_quadrants_changes_the_next_full_batch() { + let small = 2.0_f32.powi(-25).to_bits(); + assert_eq!(filled_quadrant_pixel(5, 0, Continuation::None).to_bits(), 0); + assert_eq!(filled_quadrant_pixel(5, 0, Continuation::EmptySwitch).to_bits(), small); + assert_eq!(filled_quadrant_pixel(0, 5, Continuation::EmptySwitch).to_bits(), 0); +} + +#[test] +fn an_inactive_branch_contributes_its_connected_quadrant_depth() { + assert_eq!(filled_quadrant_pixel(5, 0, Continuation::InactiveBranch(8)).to_bits(), 0); + assert_eq!(filled_quadrant_pixel(5, 0, Continuation::InactiveBranch(9)).to_bits(), 2.0_f32.powi(-25).to_bits()); +} diff --git a/crates/nodes/src/pattern/tile_runs.rs b/crates/nodes/src/pattern/tile_runs.rs new file mode 100644 index 00000000..7813279b --- /dev/null +++ b/crates/nodes/src/pattern/tile_runs.rs @@ -0,0 +1,562 @@ +use super::{ + footprint::Footprint, + pattern_stamp::{CopyPositions, DrawPosition, DrawRun, PatternStamp}, + region::Region, +}; +use crate::CookContext; +use std::{borrow::Cow, ops::Range}; + +mod four_children; +mod inactive_children; +mod paired_batches; +mod sparse_quadrants; +mod two_children; + +pub(super) use four_children::FOUR_CHILDREN; +pub(super) use sparse_quadrants::SparseQuadrantRuns; + +use paired_batches::PairedBatches; + +pub(super) const UNIT_WINDOW: [f32; 4] = [0.0, 1.0, 0.0, 1.0]; +const DEPTH_THREE_PARENTS: usize = 256; +const DEPTH_FOUR_PARENTS: usize = 64; +const DEPTH_FIVE_PARENTS: usize = 16; +const TWO_DEEP_TREES: usize = 2 * 4_usize.pow(4); +const PAIRED_SUBTREE_PARENTS: usize = 2 * DEPTH_THREE_PARENTS; +const FIRST_PAIR_END: usize = 48 * DEPTH_THREE_PARENTS + PAIRED_SUBTREE_PARENTS; +// Paired interior squares change order when the preceding draws fill 5,460 tile copies. +pub(super) const COPIES_PER_BATCH: u32 = 5460; +// The lower half of each of these root children submits complete copy batches first. +// Indices count the depth-three quadrants in the traversal. +pub(super) const LEADING_SUBTREES: [usize; 3] = [24, 40, 8]; + +pub(super) struct TileCopies { + window: Region, + axes: [bool; 2], + parents_per_subtree: usize, + positions: CopyPositions, + subtree_ends: Vec, + full_pairs: u8, +} + +impl TileCopies { + pub(super) fn new(context: &CookContext, deepest: u32, window: [f32; 4]) -> Option { + if context.v4("render_region") != window || context.v4("tiling_region") != window { + return None; + } + let parents_per_subtree = match deepest { + 10 => DEPTH_FIVE_PARENTS, + 9 => DEPTH_FOUR_PARENTS, + _ => DEPTH_THREE_PARENTS, + }; + Some(Self { + window: Region::new(window).ok()?, + axes: context.tiling_axes(), + parents_per_subtree, + positions: CopyPositions::default(), + subtree_ends: Vec::new(), + full_pairs: 0, + }) + } + + fn count_stamp(&mut self, stamp: Option<&PatternStamp>, retained: bool) -> Option> { + let count = if let Some(stamp) = stamp { + let footprint = Footprint::new(stamp).ok()?; + let center = self.window.copy_origin(stamp.center, self.axes); + let [x, y] = self.window.repeats(&self.window, center, footprint.radius, self.axes).ok()?; + if !(1..=2).contains(&x.count) || !(1..=2).contains(&y.count) { + return None; + } + (x.count * y.count) as u32 + } else { + 0 + }; + self.positions.record(count, retained) + } + + pub(super) fn complete_inactive_tree(&self) -> bool { + self.subtree_ends.len() == inactive_children::SUBTREES_PER_TREE + } + + pub(super) fn tiles_both_axes(&self) -> bool { + self.axes == [true; 2] + } + + pub(super) fn copy_count(&self) -> usize { + self.positions.total as usize + } + + pub(super) fn begin_inactive_subtree(&mut self, trees: usize) -> bool { + if self.subtree_ends.len() >= trees * inactive_children::SUBTREES_PER_TREE { + return false; + } + self.subtree_ends.push(self.positions.total); + true + } + + pub(super) fn record(&mut self, stamp: &PatternStamp, retained: bool, draws: usize, draws_per_parent: usize) -> Option<()> { + let end = self.count_stamp(Some(stamp), retained)?.end; + if self.parents_per_subtree == DEPTH_FIVE_PARENTS { + *self.subtree_ends.last_mut()? = end; + return Some(()); + } + if draws.is_multiple_of(draws_per_parent * self.parents_per_subtree) { + let parents = draws / draws_per_parent; + // Count the eight pairs in the final quadrant. Their combined occupancy determines + // whether to continue a single overflowing pair or all eight in submission order. + if self.parents_per_subtree == DEPTH_FOUR_PARENTS + && (FIRST_PAIR_END..=64 * DEPTH_THREE_PARENTS).contains(&parents) + && parents.is_multiple_of(PAIRED_SUBTREE_PARENTS) + { + let subtrees = PAIRED_SUBTREE_PARENTS / DEPTH_FOUR_PARENTS; + let start = self.subtree_ends.iter().rev().nth(subtrees - 1)?; + if end - start >= 2 * COPIES_PER_BATCH { + let pair = (parents - FIRST_PAIR_END) / PAIRED_SUBTREE_PARENTS; + self.full_pairs |= 1_u8.checked_shl(u32::try_from(pair).ok()?)?; + } + } + self.subtree_ends.push(end); + } + Some(()) + } + + pub(super) fn two_child_runs<'a>(&self, stamps: &'a [PatternStamp]) -> Option>> { + let ranges = two_children::ranges(&self.subtree_ends)?; + ranges.into_iter().map(|r| DrawRun::between(stamps, self.positions.at(r.start), self.positions.at(r.end))).collect() + } + + pub(super) fn inactive_child_runs<'a>(&self, stamps: &'a [PatternStamp]) -> Option>> { + let ranges = inactive_children::ranges(&self.subtree_ends)?; + ranges.into_iter().map(|r| DrawRun::between(stamps, self.positions.at(r.start), self.positions.at(r.end))).collect() + } + + fn subtree_copies(&self, subtrees: Range) -> Option { + let start = if subtrees.start == 0 { 0 } else { *self.subtree_ends.get(subtrees.start - 1)? }; + self.subtree_ends.get(subtrees.end.checked_sub(1)?)?.checked_sub(start) + } + + fn group_copies(&self, groups: Range) -> Option { + let subtrees = DEPTH_THREE_PARENTS / self.parents_per_subtree; + self.subtree_copies(groups.start * subtrees..groups.end * subtrees) + } + + fn horizontal_layout(&self, ordinary: &'static [(usize, usize)], pair: Option<(usize, usize)>) -> Option> { + let prefix = self.group_copies(60..61)?; + let full_prefix = prefix >= COPIES_PER_BATCH; + let fallback = || pair.is_none().then_some(Cow::Borrowed(ordinary)); + if !full_prefix && pair.is_none() { + if self.full_pairs == 0 + && let Some(layout) = self.first_quadrant_tail(ordinary, prefix) + { + return Some(Cow::Owned(layout)); + } + return fallback(); + } + if let Some((group, head)) = pair { + // The paired prefix defers everything after its second batch. Filling another + // batch in the receiving subtree changes the order of the remaining draws. + let deferred = self.group_copies(group..group + 2)?.checked_sub(2 * COPIES_PER_BATCH)?; + if self.group_copies(head..head + 1)?.checked_add(deferred)? >= COPIES_PER_BATCH { + if group == 50 && !full_prefix { + return self.full_second_quadrant(); + } + if group == 54 && !full_prefix { + return Some(Cow::Borrowed(paired_batches::FULL_RECEIVING_QUADRANT)); + } + return fallback(); + } + } + if full_prefix && self.group_copies(16..17)?.checked_add(prefix - COPIES_PER_BATCH)? >= COPIES_PER_BATCH { + // The later copy from group 60 can then move across another partially filled batch. + return fallback(); + } + + if self.full_pairs == 0b1000 + && prefix == COPIES_PER_BATCH + && let Some(layout) = self.eight_middle_groups() + { + return Some(Cow::Owned(layout)); + } + Some(Self::shift_horizontal_boundaries(ordinary, pair, full_prefix)) + } + + // Interior cuts use a marker in the containing subtree. The batch supplies the exact copy. + fn parent_at_cut(&self, cut: u32) -> Option { + let subtree = self.subtree_ends.partition_point(|&end| end < cut); + let end = *self.subtree_ends.get(subtree)?; + let first = subtree * self.parents_per_subtree; + Some(first + if end == cut { self.parents_per_subtree } else { 1 }) + } + + fn first_quadrant_copies(&self) -> Option { + // The two middle subtrees of group 0 are pending when groups 58 and 59 join the first stream. + self.subtree_copies(0..1)?.checked_add(self.subtree_copies(3..30)?)?.checked_add(self.group_copies(58..60)?) + } + + fn first_quadrant_cut(&self, first: u32) -> Option { + let cut = self.subtree_ends.get(29)?.checked_add(9 * COPIES_PER_BATCH)?.checked_sub(first)?; + if cut <= *self.subtree_ends.get(28)? || cut > *self.subtree_ends.get(30)? { + return None; + } + self.parent_at_cut(cut) + } + + fn first_quadrant_tail(&self, ordinary: &[(usize, usize)], prefix: u32) -> Option> { + if self.group_copies(24..32)? >= 8 * COPIES_PER_BATCH || self.penultimate_copies(prefix)? >= 2 * COPIES_PER_BATCH { + return None; + } + let first = self.first_quadrant_copies()?; + let head = self.first_quadrant_cut(first)?; + // The end of the first eight groups and one subtree each from groups + // 52 and 56 now fill a tenth batch. Split the latter at the physical copy. + let combined = + first.checked_add(self.subtree_copies(30..32)?)?.checked_add(self.subtree_copies(209..210)?)?.checked_add(self.subtree_copies(225..226)?)?; + let extra = combined.checked_sub(10 * COPIES_PER_BATCH)?; + if extra >= self.subtree_copies(225..226)? { + return None; + } + let split = self.parent_at_cut(self.subtree_ends.get(225)?.checked_sub(extra)?)?; + let pair = self.parent_at_cut(self.subtree_ends.get(215)?.checked_add(COPIES_PER_BATCH)?)?; + let mut layout: Vec<_> = ordinary + .iter() + .filter(|(_, rank)| *rank < 30) + .map(|&(end, rank)| { + ( + match rank { + 3 => pair, + 16 => head, + _ => end, + }, + rank, + ) + }) + .collect(); + let tail = [12361, 2048, 13440, split, 12416, 10240, 192, 14464, 15680, 15872, 4288, 12800, 14528, 14848, 13824, 12480, 15808, 13504]; + layout.extend(tail.into_iter().enumerate().map(|(rank, end)| (end, rank + 30))); + layout.sort_unstable(); + Some(layout) + } + + fn eight_middle_groups(&self) -> Option> { + let middle_tail = self.group_copies(24..32)?.checked_sub(8 * COPIES_PER_BATCH)?; + if self.group_copies(52..53)?.checked_add(middle_tail)? >= COPIES_PER_BATCH + || self.group_copies(62..63)? < COPIES_PER_BATCH + || self.group_copies(50..51)? >= COPIES_PER_BATCH + || self.group_copies(58..59)? >= COPIES_PER_BATCH + { + return None; + } + let subtrees = DEPTH_THREE_PARENTS / self.parents_per_subtree; + let first = 32 * subtrees; + let end = 40 * subtrees; + // The deferred copies of the full pair lead the first five subtrees. + // The two skipped subtrees are submitted later, after the next split. + let deferred = self.group_copies(54..56)?.checked_sub(2 * COPIES_PER_BATCH)?; + let copies = deferred.checked_add(self.subtree_copies(first..first + 5)?)?.checked_add(self.subtree_copies(first + 7..end)?)?; + let remainder = copies % COPIES_PER_BATCH; + let middle_cut = self.parent_at_cut(self.subtree_ends.get(end - 1)?.checked_sub(remainder)?)?; + let last_cut = self.parent_at_cut(self.subtree_ends.get(62 * subtrees - 1)?.checked_add(COPIES_PER_BATCH)?)?; + let filled = remainder.checked_add(self.subtree_copies(1..3)?)? >= COPIES_PER_BATCH; + Some(paired_batches::eight_middle_groups(last_cut, middle_cut, filled)) + } + + fn shift_horizontal_boundaries(ordinary: &'static [(usize, usize)], pair: Option<(usize, usize)>, full_prefix: bool) -> Cow<'static, [(usize, usize)]> { + if pair.is_none() && !full_prefix { + return Cow::Borrowed(ordinary); + } + let mut layout = ordinary.to_vec(); + for (end, _) in &mut layout { + if let Some((group, head)) = pair { + let start = head * DEPTH_THREE_PARENTS; + if *end == start + DEPTH_FOUR_PARENTS || *end == start + 3 * DEPTH_FOUR_PARENTS { + *end += DEPTH_THREE_PARENTS; + } else if ((group + 1) * DEPTH_THREE_PARENTS..(group + 2) * DEPTH_THREE_PARENTS).contains(end) { + // Repeated endpoints split the final subtree at the physical copy count. + *end = (group + 2) * DEPTH_THREE_PARENTS; + } + } + let last = 61 * DEPTH_THREE_PARENTS; + if full_prefix && last < *end && *end <= last + 3 * DEPTH_FOUR_PARENTS { + *end = (*end - DEPTH_FOUR_PARENTS).max(last); + } + } + Cow::Owned(layout) + } + + fn full_second_quadrant(&self) -> Option> { + let mut layout = Cow::Borrowed(paired_batches::FULL_SECOND_QUADRANT); + let prefix = self.group_copies(62..63)?; + if prefix != COPIES_PER_BATCH { + // The first submission ends after one batch. It can fall on either side + // of group 63, which supplies the remaining draws later in the sequence. + let (end, _) = layout.to_mut().iter_mut().find(|(_, rank)| *rank == 0)?; + let boundary = 63 * DEPTH_THREE_PARENTS; + *end = if prefix < COPIES_PER_BATCH { boundary + 1 } else { boundary - 1 }; + } + Some(layout) + } + + fn penultimate_copies(&self, prefix: u32) -> Option { + let subtrees = DEPTH_THREE_PARENTS / DEPTH_FOUR_PARENTS; + let receiver = 16 * subtrees; + let following = 61 * subtrees; + let first = if prefix >= COPIES_PER_BATCH { following + 2 } else { following }; + // After the first batch, the first remaining part of group 61 and its + // final subtree join the two middle subtrees of group 16. Only a full + // batch at that point separates the later runs. + let mut copies = prefix; + for range in [first..first + 1, following + 3..following + 4, receiver + 1..receiver + 3] { + copies = copies.checked_add(self.subtree_copies(range)?)?; + } + Some(copies) + } + + fn penultimate_layout(&self, ordinary: &'static [(usize, usize)]) -> Option> { + let prefix = self.group_copies(60..61)?; + let full_prefix = prefix >= COPIES_PER_BATCH; + let layout = if self.penultimate_copies(prefix)? >= 2 * COPIES_PER_BATCH { PairedBatches::Penultimate.layout() } else { ordinary }; + Some(Self::shift_horizontal_boundaries(layout, None, full_prefix)) + } + + fn three_final_pairs_layout(&self) -> Option> { + let penultimate = self.group_copies(60..61)?; + if self.group_copies(58..59)? < COPIES_PER_BATCH || penultimate < COPIES_PER_BATCH || self.group_copies(62..63)? < COPIES_PER_BATCH { + return None; + } + // The first overflowing pair's tail fills group 0. The final pair's + // tail leaves space in group 48, where its remaining draws continue. + let first_tail = self.group_copies(58..60)?.checked_sub(2 * COPIES_PER_BATCH)?; + let last_tail = self.group_copies(62..64)?.checked_sub(2 * COPIES_PER_BATCH)?; + if self.group_copies(0..1)?.checked_add(first_tail)? < COPIES_PER_BATCH || self.group_copies(48..49)?.checked_add(last_tail)? >= COPIES_PER_BATCH { + return None; + } + Some(Cow::Owned(paired_batches::three_final_pairs(self.penultimate_copies(penultimate)? >= 2 * COPIES_PER_BATCH))) + } + + fn middle_and_final_pair(&self, ordinary: &[(usize, usize)], final_tail: u32) -> Option> { + let prefix = self.group_copies(60..61)?; + let middle_tail = self.group_copies(24..32)?.checked_sub(8 * COPIES_PER_BATCH)?; + if prefix >= COPIES_PER_BATCH || self.group_copies(52..53)?.checked_add(middle_tail)? >= COPIES_PER_BATCH { + return None; + } + let penultimate_tail = self.penultimate_copies(prefix)?.checked_sub(2 * COPIES_PER_BATCH)?; + let cut_after = |subtrees: usize, copies| self.parent_at_cut(self.subtree_ends.get(subtrees.checked_sub(1)?)?.checked_add(copies)?); + let first = self.first_quadrant_cut(self.first_quadrant_copies()?)?; + let last_pair = cut_after(248, 2 * COPIES_PER_BATCH)?; + let middle = cut_after(96, 8 * COPIES_PER_BATCH)?; + let pair = cut_after(216, COPIES_PER_BATCH)?; + let after_eight = cut_after(245, (8 * COPIES_PER_BATCH).checked_sub(self.group_copies(8..16)?)?)?; + let mut layout: Vec<_> = ordinary + .iter() + .filter(|(_, rank)| *rank < 19) + .map(|&(end, rank)| { + ( + match rank { + 0 => last_pair, + 2 => middle, + 3 => pair, + 16 => first, + 18 => after_eight, + _ => end, + }, + rank, + ) + }) + .collect(); + // Any remainder after eight middle batches leads group 52. The final pair's remainder leads group 48. + if middle_tail > 0 { + layout.push((32 * DEPTH_THREE_PARENTS, layout.len())); + } + let next = cut_after(208, COPIES_PER_BATCH.checked_sub(middle_tail)?)?; + let receiver = cut_after(192, COPIES_PER_BATCH.checked_sub(final_tail)?)?; + // The middle two subtrees of group 16 draw later. The middle two of group 32 + // and both groups 50 and 51 have already contributed to the ten-batch stream. + let preceding = self + .subtree_copies(64..65)? + .checked_add(self.subtree_copies(67..96)?)? + .checked_add(self.subtree_copies(129..131)?)? + .checked_add(self.group_copies(50..52)?)?; + let later = cut_after(196, (10 * COPIES_PER_BATCH).checked_sub(preceding)?)?; + let penultimate = self.parent_at_cut(self.subtree_ends.get(66)?.checked_sub(penultimate_tail)?)?; + let tail = [ + next, + 16384, + receiver, + 12288, + 14400, + 14727, + 6144, + 8384, + later, + 15680, + 15872, + penultimate, + 12672, + 10240, + 192, + 2048, + 13696, + 14464, + 4288, + 12544, + 12800, + 14528, + 14848, + 13632, + 13824, + 12736, + 15808, + 13760, + ]; + let first_rank = layout.len(); + layout.extend(tail.into_iter().enumerate().map(|(rank, end)| (end, first_rank + rank))); + layout.sort_unstable(); + Some(layout) + } + + fn final_pair_layout(&self) -> Option> { + let ordinary = PairedBatches::Final.layout(); + let deferred = self.group_copies(62..64)?.checked_sub(2 * COPIES_PER_BATCH)?; + if self.group_copies(48..49)?.checked_add(deferred)? >= COPIES_PER_BATCH { + if let Some(layout) = self.middle_and_final_pair(ordinary, deferred) { + return Some(Cow::Owned(layout)); + } + return Some(Cow::Borrowed(ordinary)); + } + let full_prefix = self.group_copies(60..61)? >= COPIES_PER_BATCH; + let mut layout = Self::shift_horizontal_boundaries(ordinary, None, full_prefix); + // The last pair's deferred copies leave room after group 48. Its first run + // fills the batch inside the next subtree and its second run finishes that subtree. + let group_end = 49 * DEPTH_THREE_PARENTS; + let mut ends = layout.to_mut().iter_mut().filter(|(parents, _)| *parents == group_end); + ends.next()?.0 += 1; + ends.next()?.0 += DEPTH_FOUR_PARENTS; + Some(layout) + } + + pub(super) fn layout(&self, ordinary: &'static [(usize, usize)]) -> Option> { + if self.parents_per_subtree == DEPTH_THREE_PARENTS { + let partner = self.group_copies(58..60)?; + if partner.checked_add(self.group_copies(0..2)?)? >= COPIES_PER_BATCH { + // A cut before the second group has a different, unmeasured continuation. + return (partner.checked_add(self.group_copies(0..1)?)? < COPIES_PER_BATCH).then_some(Cow::Borrowed(four_children::FILLED_FIRST_PAIR)); + } + } + if self.full_pairs == u8::MAX && self.axes[0] { + return Some(Cow::Borrowed(paired_batches::ALL_FULL_PAIRS)); + } + // The first pair also submits its parts separately in the ordinary layout. + let later = self.full_pairs & !1; + if self.parents_per_subtree == DEPTH_FOUR_PARENTS && self.axes == [true, false] { + match later { + // Groups 52–53 and 56–57 submit their subtrees separately, + // including when both pairs contain two full batches. + 0 | 0b100 | 0b10000 | 0b10100 => return self.horizontal_layout(ordinary, None), + 0b1110_0000 if later == self.full_pairs => return self.three_final_pairs_layout(), + 0b1000000 => return self.penultimate_layout(ordinary), + 0b10000000 => return self.final_pair_layout(), + 0b10 => return self.horizontal_layout(ordinary, Some((50, 16))), + 0b1000 => return self.horizontal_layout(ordinary, Some((54, 32))), + _ => {} + } + } + if later == 0 { + return Some(Cow::Borrowed(ordinary)); + } + if self.axes != [true, false] || !later.is_power_of_two() { + return None; + } + let end = FIRST_PAIR_END + later.trailing_zeros() as usize * PAIRED_SUBTREE_PARENTS; + Some(Cow::Borrowed(PairedBatches::ending_at(end)?.layout())) + } + + fn split_fits_subtree(&self, parents: usize, cut: u32) -> bool { + let subtree = parents / self.parents_per_subtree; + if parents.is_multiple_of(self.parents_per_subtree) { + // The first part of a repeated endpoint may fill its final subtree exactly. + return self.subtree_ends.partition_point(|&end| end < cut) + 1 == subtree; + } + let group = parents / DEPTH_THREE_PARENTS; + if self.parents_per_subtree == DEPTH_THREE_PARENTS && group == 44 { + // The prefix beginning at group 40 keeps its place when its batch fills one subtree earlier. + return self.subtree_ends.get(42).zip(self.subtree_ends.get(44)).is_some_and(|(&before, &after)| before < cut && cut < after); + } + if self.subtree_ends.len() == TWO_DEEP_TREES { + // A full batch can land on the end of group 87, the middle of + // group 116, or the end of the pending pair at parent 31,936. + if parents == 351 * DEPTH_FOUR_PARENTS + 1 || parents == 466 * DEPTH_FOUR_PARENTS - 1 || parents == 498 * DEPTH_FOUR_PARENTS + 1 { + return self.subtree_ends.get(subtree - 1).zip(self.subtree_ends.get(subtree)).is_some_and(|(&lower, &upper)| lower < cut && cut <= upper); + } + // The earlier cuts and the later cut in group 120 can each + // fall on either side of an interior subtree boundary. + if parents == 348 * DEPTH_FOUR_PARENTS + 1 || parents == 382 * DEPTH_FOUR_PARENTS + 1 || parents == 483 * DEPTH_FOUR_PARENTS + 1 { + return self.subtree_ends.get(subtree - 2).zip(self.subtree_ends.get(subtree)).is_some_and(|(&lower, &upper)| lower < cut && cut < upper); + } + } + if self.parents_per_subtree == DEPTH_FOUR_PARENTS && self.axes == [true, false] && parents % DEPTH_THREE_PARENTS < DEPTH_FOUR_PARENTS { + let previous = match group { + // When the seventh batch ends early, the remaining copies join the + // following quadrant. Filling that batch changes the later draw order. + 15 | 31 | 47 => { + let group_end = subtree + DEPTH_THREE_PARENTS / DEPTH_FOUR_PARENTS - 1; + self.subtree_ends.get(group_end).and_then(|end| end.checked_sub(cut)).is_some_and(|remaining| remaining < COPIES_PER_BATCH) + } + // These four short pairs can also end one subtree early. + 51 | 55 | 59 | 63 => self.full_pairs & (1 << ((group - 49) / 2)) == 0, + _ => false, + }; + if previous { + return self.subtree_ends.get(subtree - 2).zip(self.subtree_ends.get(subtree)).is_some_and(|(&lower, &upper)| lower < cut && cut < upper); + } + } + self.subtree_ends.partition_point(|&end| end <= cut) == subtree + && (self.parents_per_subtree != DEPTH_FOUR_PARENTS + || subtree.checked_sub(1).and_then(|i| self.subtree_ends.get(i)).is_some_and(|&lower| cut > lower)) + } + + pub(super) fn boundaries(&self, layout: &[(usize, usize)], draws_per_parent: usize) -> Option> { + let mut cuts = vec![None; layout.len() + 1]; + let mut order = vec![0; layout.len()]; + cuts[0] = Some(0_u32); + for (run, &(parents, rank)) in layout.iter().enumerate() { + *order.get_mut(rank)? = run; + // A repeated endpoint leaves the first part for the active batch to size. + let split = layout.get(run + 1).is_some_and(|&(next, _)| next == parents); + // After two complete trees, submission 50 ends on a full batch. + // With one copy per draw this coincides with the end of subtree + // 318. Extra copies move the cut earlier inside that subtree. + let physical = self.subtree_ends.len() == TWO_DEEP_TREES && parents == 318 * DEPTH_FOUR_PARENTS; + if !split && !physical && parents.is_multiple_of(self.parents_per_subtree) { + cuts[run + 1] = self.subtree_ends.get((parents / self.parents_per_subtree).checked_sub(1)?).copied(); + } + } + + let mut drawn = 0_u32; + for run in order { + let start = cuts[run]?; + let end = match cuts[run + 1] { + Some(end) => end, + None => { + let (parents, _) = layout[run]; + let first = run.checked_sub(1).map_or(0, |previous| layout[previous].0); + // Consecutive batches can form one run. The first can already + // contain copies from the previous run. + let length = u32::try_from((parents - first) * draws_per_parent).ok()?; + let capacity = length.div_ceil(COPIES_PER_BATCH).checked_mul(COPIES_PER_BATCH)?; + let end = start.checked_add(capacity - drawn % COPIES_PER_BATCH)?; + // Crossing the measured subtree interval can change the order of the later runs. + if !self.split_fits_subtree(parents, end) { + return None; + } + cuts[run + 1] = Some(end); + end + } + }; + drawn = drawn.checked_add(end.checked_sub(start)?)?; + } + if self.positions.total != drawn { + return None; + } + cuts.into_iter().map(|cut| cut.map(|cut| self.positions.at(cut))).collect() + } +} diff --git a/crates/nodes/src/pattern/tile_runs/four_children.rs b/crates/nodes/src/pattern/tile_runs/four_children.rs new file mode 100644 index 00000000..5ae557c5 --- /dev/null +++ b/crates/nodes/src/pattern/tile_runs/four_children.rs @@ -0,0 +1,136 @@ +// Exclusive endpoints in depth-seven parent visits and their submission ranks. +pub(in crate::pattern) const FOUR_CHILDREN: &[(usize, usize)] = &[ + (580, 6), + (1024, 19), + (1416, 15), + (1536, 24), + (2048, 20), + (3140, 2), + (4096, 9), + (4676, 4), + (5120, 13), + (5376, 29), + (5444, 18), + (5632, 31), + (5768, 10), + (5888, 34), + (6144, 14), + (7236, 0), + (8192, 11), + (8772, 8), + (9216, 25), + (9352, 21), + (9728, 27), + (9984, 30), + (10240, 26), + (11332, 1), + (12288, 22), + (12800, 17), + (13312, 3), + (13448, 12), + (13824, 33), + (14336, 7), + (14472, 23), + (14848, 32), + (15360, 5), + (15872, 28), + (16384, 16), +]; + +// When groups 58–59 and 0–1 fill their batch, group 2 is deferred. The next prefix +// starts in group 3, and groups 36–37 finish together. Interior cuts count tile copies. +pub(super) const FILLED_FIRST_PAIR: &[(usize, usize)] = &[ + (512, 6), + (768, 21), + (1860, 7), + (2048, 24), + (3140, 2), + (4096, 10), + (4676, 4), + (5120, 19), + (5376, 27), + (5444, 16), + (5632, 29), + (5768, 11), + (5888, 32), + (6144, 20), + (7236, 0), + (8192, 12), + (8772, 9), + (9216, 22), + (9728, 25), + (9984, 28), + (10240, 23), + (11332, 1), + (12288, 17), + (12800, 15), + (13312, 3), + (13448, 13), + (13824, 31), + (14336, 8), + (14472, 18), + (14848, 30), + (15360, 5), + (15872, 26), + (16384, 14), +]; + +#[cfg(test)] +mod tests { + use super::super::{CopyPositions, DEPTH_THREE_PARENTS, DrawPosition, Region, TileCopies, UNIT_WINDOW}; + use super::FOUR_CHILDREN; + + #[test] + fn a_tile_copy_filling_the_paired_subtrees_changes_the_following_four_child_runs() { + for full in [false, true] { + let mut copies = TileCopies { + window: Region::new(UNIT_WINDOW).unwrap(), + axes: [true; 2], + parents_per_subtree: DEPTH_THREE_PARENTS, + positions: CopyPositions::default(), + subtree_ends: Vec::new(), + full_pairs: 0, + }; + for group in 0..64 { + let extra = match group { + 0 | 1 | 3 | 41..=43 | 59 => 85, + 2 | 40 => 84, + 58 => 84 + usize::from(full), + _ => 0, + }; + // Move the marked leaves to the X seam, preserving the parent and first leaf for signed probes. + let mut moved = (0..extra) + .map(|j| { + let leaf = j * 768 / extra; + leaf / 3 * 5 + leaf % 3 + 2 + }) + .peekable(); + for stamp in 0..1280 { + let count = 1 + u32::from(moved.next_if_eq(&stamp).is_some()); + copies.positions.record(count, true).unwrap(); + } + copies.subtree_ends.push(copies.positions.total); + } + let layout = copies.layout(FOUR_CHILDREN).unwrap(); + let bounds = copies.boundaries(&layout, 5).unwrap(); + let rank = |stamp| { + let mark = DrawPosition { stamp, copy: 0 }; + layout.iter().zip(bounds.windows(2)).find_map(|(&(_, rank), pair)| (pair[0] <= mark && mark < pair[1]).then_some((rank, stamp))).unwrap() + }; + // Each pair shared one pixel in two independent fields with its gains exchanged. + for (first, second, short_order, full_order) in [ + (2560, 3840, true, false), + (2900, 7675, true, false), + (5120, 25000, false, true), + (5125, 40960, false, true), + (8800, 79360, false, true), + (9500, 71680, true, false), + (2561, 3841, true, false), + (5121, 6401, true, true), + (9001, 10281, false, false), + ] { + assert_eq!(rank(first) < rank(second), if full { full_order } else { short_order }, "full {full}, markers {first} and {second}"); + } + } + } +} diff --git a/crates/nodes/src/pattern/tile_runs/inactive_children.rs b/crates/nodes/src/pattern/tile_runs/inactive_children.rs new file mode 100644 index 00000000..917cb26a --- /dev/null +++ b/crates/nodes/src/pattern/tile_runs/inactive_children.rs @@ -0,0 +1,258 @@ +use super::{COPIES_PER_BATCH, LEADING_SUBTREES}; +use std::ops::Range; + +mod completion; +mod outer_transfer; +mod repeated; +#[cfg(test)] +mod tests; +mod wide_transfer; + +// A depth-three quadrant contains sixteen depth-five subtrees. A boundary can +// split a tiled stamp, so convert subtree boundaries to physical copies before filling a batch. +const SUBTREES: usize = 16; +pub(super) const SUBTREES_PER_TREE: usize = 64 * SUBTREES; + +fn boundary(ends: &[u32], subtree: usize) -> Option { + if subtree == 0 { Some(0) } else { ends.get(subtree - 1).copied() } +} + +fn copies(ends: &[u32], subtrees: Range) -> Option> { + Some(boundary(ends, subtrees.start)?..boundary(ends, subtrees.end)?) +} + +fn remainder(ends: &[u32], group: usize, submitted: &Range, batches: u32) -> Option> { + let half = copies(ends, group * SUBTREES..(group + 8) * SUBTREES)?; + (submitted.start == half.start && submitted.end.checked_sub(submitted.start)? == batches * COPIES_PER_BATCH && submitted.end <= half.end) + .then_some(submitted.end..half.end) +} + +fn finish_partial_streams(mut submitted: Vec>, streams: impl IntoIterator>>) -> Option>> { + for stream in streams { + // A stream that fills submits earlier than the partial streams still waiting for siblings. + let length = stream.iter().try_fold(0_u32, |sum, range| sum.checked_add(range.end.checked_sub(range.start)?))?; + if length >= COPIES_PER_BATCH { + return None; + } + submitted.extend(stream.into_iter().filter(|range| !range.is_empty())); + } + Some(submitted) +} + +// At a full batch, half the pending siblings can pass to a later run. When the +// final sibling of a larger subtree is pending, its first two children can pass together. +fn pending_siblings(subtree: usize) -> Option<(Range, usize)> { + for width in [1, 4, SUBTREES] { + let group = subtree / width; + let pending = 3 - group % 4; + let next = (group + 1) * width; + if pending >= 2 { + return Some((next..next + pending.div_ceil(2) * width, width)); + } + if pending == 1 && width > 1 { + return Some((next..next + width / 2, width / 4)); + } + } + None +} + +struct ReceivingPair { + runs: Vec>, + tail: Range, + pending: Range, + handoff: Option>, + split_width: usize, +} + +fn receiving_pair(ends: &[u32], partner: usize, main: usize, first: bool) -> Option { + let partner = copies(ends, partner * SUBTREES..(partner + 2) * SUBTREES)?; + let extent = main * SUBTREES..(main + 8) * SUBTREES; + let start = boundary(ends, extent.start)?; + let room = COPIES_PER_BATCH.checked_sub(partner.end - partner.start)?; + let cut = start.checked_add(room)?; + let subtree = ends.partition_point(|&end| end < cut); + if room == 0 || !extent.contains(&subtree) { + return None; + } + let (deferred, width) = pending_siblings(subtree)?; + let mut skips = vec![deferred.clone()]; + let mut handoff = None; + if first { + // The first receiving pair hands off a second block before continuing. + let extra = match width { + 1 => { + let parent = subtree / 4; + let pending = 3 - parent % 4; + if pending < 2 { + return None; + } + let sibling = (parent + 1) * 4; + sibling..sibling + pending.div_ceil(2) * 4 + } + 4 => deferred.end..deferred.end + 2, + // After a whole depth-three sibling, the following half and quarter + // of a sibling also transfer before this receiver resumes. + SUBTREES if deferred.len() == SUBTREES => deferred.end..deferred.end + SUBTREES / 2 + SUBTREES / 4, + _ => return None, + }; + handoff = Some(copies(ends, extra.clone())?); + skips.push(extra); + } + let mut runs = vec![partner]; + let mut remaining = room + COPIES_PER_BATCH; + let mut next = extent.start; + for skip in skips.into_iter().chain(std::iter::once(extent.end..extent.end)) { + if skip.start < next || skip.end > extent.end { + return None; + } + let available = copies(ends, next..skip.start)?; + let take = remaining.min(available.end - available.start); + if take > 0 { + runs.push(available.start..available.start + take); + remaining -= take; + } + next = skip.end; + } + if remaining != 0 { + return None; + } + let tail = runs.last()?.end..boundary(ends, extent.end)?; + Some(ReceivingPair { runs, tail, pending: deferred, handoff, split_width: width }) +} + +fn completed_half(ends: &[u32], group: usize, partner: usize) -> Option<[Range; 2]> { + let half = copies(ends, group * SUBTREES..(group + 8) * SUBTREES)?; + let remainder = half.start.checked_add(COPIES_PER_BATCH)?..half.end; + let room = COPIES_PER_BATCH.checked_sub(remainder.end.checked_sub(remainder.start)?)?; + let incoming = copies(ends, partner * SUBTREES..(partner + 2) * SUBTREES)?; + if room == 0 || room >= incoming.end - incoming.start { + return None; + } + Some([remainder, incoming.start..incoming.start + room]) +} + +fn full_outer_pair(ends: &[u32]) -> Option<[Range; 2]> { + let preceding = copies(ends, 60 * SUBTREES..62 * SUBTREES)?; + let own = copies(ends, 62 * SUBTREES..64 * SUBTREES)?; + let incoming = copies(ends, 48 * SUBTREES..50 * SUBTREES)?; + let room = COPIES_PER_BATCH.checked_sub(own.end - own.start)?; + // An independently full outer pair has a different submission boundary. + if preceding.end - preceding.start >= COPIES_PER_BATCH || room == 0 || !(room..COPIES_PER_BATCH).contains(&(incoming.end - incoming.start)) { + return None; + } + Some([own, incoming.start..incoming.start + room]) +} + +struct CompletedHalves { + pairs: [[Range; 2]; 2], + third: Range, +} + +fn fill_halves(ends: &[u32], first: &ReceivingPair, full: &mut Vec>) -> Option { + let handoff = first.handoff.as_ref()?; + let third = copies(ends, 8 * SUBTREES..16 * SUBTREES)?; + let remaining = (third.end - third.start).checked_sub(COPIES_PER_BATCH)?; + // Filling the third half with the transferred siblings changes the continuation. + if remaining.checked_add(handoff.end - handoff.start)? >= COPIES_PER_BATCH { + return None; + } + let halves = [completed_half(ends, 24, 52)?, completed_half(ends, 40, 56)?]; + // Passing a depth-four sibling from the first receiver puts the other half first. + let [lower, upper] = &halves; + let order = if first.split_width == 4 { [upper, lower] } else { [lower, upper] }; + full.extend(order.into_iter().flatten().cloned()); + Some(CompletedHalves { pairs: halves, third: third.start + COPIES_PER_BATCH..third.end }) +} + +fn following_batches(ends: &[u32], receivers: &[ReceivingPair], leading: &[Range], outer_tail: Option<&Range>) -> Option>> { + let [first, middle, last] = receivers else { return None }; + if first.split_width == SUBTREES { + return wide_transfer::ranges(ends, receivers, leading, outer_tail?); + } + let middle_siblings = copies(ends, middle.pending.clone())?; + let last_siblings = copies(ends, last.pending.clone())?; + if first.tail.start < first.handoff.as_ref()?.end || middle.tail.start < middle_siblings.end || last.tail.start < last_siblings.end { + return None; + } + let mut full = leading.to_vec(); + let halves = fill_halves(ends, first, &mut full)?; + let tails = [first.tail.clone(), middle_siblings, last.tail.clone()]; + if outer_tail.is_none() + && let Some(completed) = completion::ranges(ends, receivers, &halves.pairs, halves.third, &full, &tails) + { + return Some(completed); + } + full.extend(tails); + Some(full) +} + +fn receive_pairs(ends: &[u32], runs: &mut Vec>) -> Vec { + // The final root quadrant sends one pair to each receiving half. + let mut receivers = Vec::with_capacity(3); + for (partner, main) in [(50, 16), (58, 0), (54, 32)] { + let Some(pair) = receiving_pair(ends, partner, main, main == 16) else { break }; + runs.extend_from_slice(&pair.runs); + receivers.push(pair); + } + receivers +} + +pub(super) fn ranges(ends: &[u32]) -> Option>> { + let first = ends.get(..SUBTREES_PER_TREE)?; + let repeated = ends.len() == 2 * SUBTREES_PER_TREE; + if !repeated && ends.len() != SUBTREES_PER_TREE { + return None; + } + let mut runs = Vec::new(); + for group in LEADING_SUBTREES { + let half = copies(first, group * SUBTREES..(group + 8) * SUBTREES)?; + let batches = (half.end - half.start) / COPIES_PER_BATCH; + if !(1..=2).contains(&batches) { + return None; + } + runs.push(half.start..half.start + batches * COPIES_PER_BATCH); + } + if repeated { + repeated::submit(ends, first, &mut runs)?; + return with_remaining(ends, runs); + } + // The last two depth-three subtrees continue into the first two of the same + // root quadrant. A complete batch submits before work reaches the receivers. + let outer_tail = if let Some([own, incoming]) = full_outer_pair(ends) { + let tail = incoming.end..boundary(ends, 50 * SUBTREES)?; + runs.extend([own, incoming]); + Some(tail) + } else { + None + }; + if let Some(following) = outer_tail.as_ref().and_then(|tail| outer_transfer::ranges(ends, &runs, tail)) { + runs = following; + } else { + let receivers = receive_pairs(ends, &mut runs); + if let Some(following) = following_batches(ends, &receivers, &runs, outer_tail.as_ref()) { + runs = following; + } + } + with_remaining(ends, runs) +} + +fn with_remaining(ends: &[u32], mut runs: Vec>) -> Option>> { + // Preserve every remaining physical copy in traversal order. + let mut submitted = runs.clone(); + submitted.sort_unstable_by_key(|range| range.start); + let mut next = 0; + for range in submitted { + if range.start < next { + return None; + } + if next < range.start { + runs.push(next..range.start); + } + next = range.end; + } + let end = *ends.last()?; + if next < end { + runs.push(next..end); + } + Some(runs) +} diff --git a/crates/nodes/src/pattern/tile_runs/inactive_children/completion.rs b/crates/nodes/src/pattern/tile_runs/inactive_children/completion.rs new file mode 100644 index 00000000..c20efd40 --- /dev/null +++ b/crates/nodes/src/pattern/tile_runs/inactive_children/completion.rs @@ -0,0 +1,205 @@ +use super::{COPIES_PER_BATCH, ReceivingPair, SUBTREES, boundary, copies, pending_siblings}; +use std::ops::Range; + +struct IncomingPair { + cut: u32, + end: u32, + deferred: Range, + width: usize, +} + +impl IncomingPair { + fn after(ends: &[u32], used: &Range, last_group: usize) -> Option { + let subtree = ends.partition_point(|&end| end < used.end); + let (deferred, width) = pending_siblings(subtree)?; + let end = boundary(ends, last_group * SUBTREES)?; + let span = copies(ends, deferred.clone())?; + if used.end > span.start || span.end > end { + return None; + } + Some(Self { cut: used.end, end, deferred, width }) + } + + fn kept(&self, ends: &[u32]) -> Option<[Range; 2]> { + let deferred = copies(ends, self.deferred.clone())?; + Some([self.cut..deferred.start, deferred.end..self.end]) + } + + fn children(&self, ends: &[u32], offsets: Range) -> Option> { + let part = copies(ends, self.deferred.start + offsets.start..self.deferred.start + offsets.end)?; + (part.end <= self.end).then_some(part) + } +} + +// When two depth-four siblings transfer together, each releases its first two +// children before the next root-quadrant pair. Their remaining children return +// to the streams that received the final pairs. +fn depth_four( + ends: &[u32], + first: &ReceivingPair, + last: &ReceivingPair, + incoming: &[IncomingPair; 2], + middle_tail: Range, + third: Range, +) -> Option>>> { + if first.pending.len() != 8 { + return None; + } + let child = |offset: Range| copies(ends, first.pending.start + offset.start..first.pending.start + offset.end); + let [lower, upper] = incoming; + let [upper_head, upper_tail] = upper.kept(ends)?; + let [lower_head, lower_tail] = lower.kept(ends)?; + Some(vec![ + vec![copies(ends, upper.deferred.clone())?], + vec![middle_tail, child(0..2)?, child(4..6)?], + vec![copies(ends, 60 * SUBTREES..62 * SUBTREES)?, child(2..4)?, copies(ends, last.pending.clone())?], + vec![copies(ends, 62 * SUBTREES..64 * SUBTREES)?, copies(ends, 48 * SUBTREES..50 * SUBTREES)?, child(7..8)?], + vec![upper_head, upper_tail, copies(ends, lower.deferred.clone())?], + vec![lower_head, lower_tail, child(6..7)?], + vec![third, first.handoff.clone()?], + ]) +} + +struct TransferredChildren { + first: Vec>, + middle: Vec>, + last: Range, + kept: Vec>, + before_middle_tail: Vec>, +} + +impl IncomingPair { + fn transfer(&self, ends: &[u32], upper: bool) -> Option { + let mut first = Vec::new(); + let mut middle = Vec::new(); + let mut before_middle_tail = Vec::new(); + let mut kept = Vec::new(); + let last = match (self.width, self.deferred.len()) { + (1, 2) => { + first.push(self.children(ends, 0..1)?); + kept.extend(self.kept(ends)?); + self.children(ends, 1..2)? + } + (4, 4) => { + // A whole depth-four sibling releases children of its own and + // takes the first half of the next sibling before returning. + let leading = self.children(ends, 0..2)?; + if upper { + before_middle_tail.push(self.children(ends, 0..1)?); + first.push(self.children(ends, 3..4)?); + middle.push(self.children(ends, 1..2)?); + kept.push(self.children(ends, 2..3)?); + } else { + first.push(self.children(ends, 2..4)?); + kept.push(leading.clone()); + } + let last = self.children(ends, 4..6)?; + kept.extend([self.cut..leading.start, last.end..self.end]); + last + } + _ => return None, + }; + Some(TransferredChildren { first, middle, last, kept, before_middle_tail }) + } +} + +fn depth_five( + ends: &[u32], + first: &ReceivingPair, + last: &ReceivingPair, + incoming: &[IncomingPair; 2], + middle_tail: Range, + third: Range, +) -> Option>>> { + let siblings = |r: &Range| { + (r.len() == 2).then_some(())?; + Some([copies(ends, r.start..r.start + 1)?, copies(ends, r.start + 1..r.end)?]) + }; + let [first_left, first_right] = siblings(&first.pending)?; + let [last_left, last_right] = siblings(&last.pending)?; + let lower = incoming[0].transfer(ends, false)?; + let upper = incoming[1].transfer(ends, true)?; + let mut leading = lower.first; + leading.extend(upper.before_middle_tail); + let mut middle = vec![middle_tail, last_left]; + middle.extend(upper.first); + let mut outer = vec![copies(ends, 60 * SUBTREES..62 * SUBTREES)?, first_left, last_right]; + outer.extend(upper.middle); + let mut kept = upper.kept; + kept.extend(lower.kept); + kept.push(upper.last); + Some(vec![ + leading, + middle, + outer, + vec![copies(ends, 62 * SUBTREES..64 * SUBTREES)?, copies(ends, 48 * SUBTREES..50 * SUBTREES)?, first_right], + kept, + vec![third, first.handoff.clone()?, lower.last], + ]) +} + +pub(super) fn split_at_copies(ranges: &[Range], mut count: u32) -> Option<[Vec>; 2]> { + let mut head = Vec::new(); + let mut tail = Vec::new(); + for range in ranges { + let used = count.min(range.end.checked_sub(range.start)?); + let split = range.start + used; + if range.start < split { + head.push(range.start..split); + } + if split < range.end { + tail.push(split..range.end); + } + count -= used; + } + (count == 0).then_some([head, tail]) +} + +pub(super) fn ranges( + ends: &[u32], + receivers: &[ReceivingPair], + halves: &[[Range; 2]; 2], + third: Range, + leading: &[Range], + tails: &[Range], +) -> Option>> { + let [first, middle, last] = receivers else { return None }; + let incoming = [IncomingPair::after(ends, &halves[0][1], 54)?, IncomingPair::after(ends, &halves[1][1], 58)?]; + let groups = match first.split_width { + 4 => depth_four(ends, first, last, &incoming, middle.tail.clone(), third)?, + 1 => depth_five(ends, first, last, &incoming, middle.tail.clone(), third)?, + _ => return None, + }; + let mut submitted = leading.to_vec(); + let mut remaining = tails.to_vec(); + for (index, group) in groups.into_iter().enumerate() { + let length = group.iter().try_fold(0_u32, |n, r| n.checked_add(r.end.checked_sub(r.start)?))?; + if length < COPIES_PER_BATCH { + remaining.extend(group.into_iter().filter(|r| !r.is_empty())); + continue; + } + // The outer pair can fill on its own, after receiving the first + // receiver's siblings, or after receiving the last receiver's siblings. + // Those transfers happen after three, seven and eleven full batches. + if index != 2 || length >= 2 * COPIES_PER_BATCH { + return None; + } + let own = group.first()?; + let incoming = group.get(1)?; + let batches = if own.end - own.start >= COPIES_PER_BATCH { + 3 + } else if (own.end - own.start).checked_add(incoming.end - incoming.start)? >= COPIES_PER_BATCH { + 7 + } else { + 11 + }; + let [full, rest] = split_at_copies(&group, COPIES_PER_BATCH)?; + let [mut before, after] = split_at_copies(&submitted, batches * COPIES_PER_BATCH)?; + before.extend(full); + before.extend(after); + submitted = before; + remaining.extend(rest); + } + submitted.extend(remaining); + Some(submitted) +} diff --git a/crates/nodes/src/pattern/tile_runs/inactive_children/outer_transfer.rs b/crates/nodes/src/pattern/tile_runs/inactive_children/outer_transfer.rs new file mode 100644 index 00000000..20b5d489 --- /dev/null +++ b/crates/nodes/src/pattern/tile_runs/inactive_children/outer_transfer.rs @@ -0,0 +1,46 @@ +use super::{SUBTREES, boundary, copies, finish_partial_streams, pending_siblings, receiving_pair, remainder}; +use std::ops::Range; + +pub(super) fn ranges(ends: &[u32], leading: &[Range], outer_tail: &Range) -> Option>> { + let [lower, upper, third, _, _] = leading else { return None }; + let lower = remainder(ends, 24, lower, 2)?; + let upper = remainder(ends, 40, upper, 2)?; + let third = remainder(ends, 8, third, 2)?; + + // When the cut leaves two children of the last outer quadrant, the next + // child passes to another stream. The cut child stays with the last child. + let cut_child = ends.partition_point(|&end| end < outer_tail.start); + let (passed, width) = pending_siblings(cut_child)?; + if width != 1 || passed != (cut_child + 1..cut_child + 2) || boundary(ends, passed.end + 1)? != outer_tail.end { + return None; + } + let passed = copies(ends, passed)?; + let kept = outer_tail.start..passed.start; + let last_child = passed.end..outer_tail.end; + + // This handoff puts the pair sent to the third root quadrant first. + // It passes a whole sibling, a half and a quarter to the unfinished streams. + let first = receiving_pair(ends, 54, 32, true)?; + let middle = receiving_pair(ends, 50, 16, false)?; + let last = receiving_pair(ends, 58, 0, false)?; + if first.split_width != SUBTREES || first.pending.len() != SUBTREES || [&middle, &last].iter().any(|pair| pair.split_width != 1 || pair.pending.len() != 1) + { + return None; + } + let child = |offset: Range| copies(ends, first.pending.start + offset.start..first.pending.start + offset.end); + let mut submitted = leading.to_vec(); + submitted.extend(first.runs); + submitted.extend(middle.runs); + submitted.extend(last.runs); + let streams = [ + vec![middle.tail, child(0..2)?, child(4..5)?], + vec![first.tail, child(2..4)?], + vec![copies(ends, last.pending)?, last.tail, child(16..18)?], + vec![copies(ends, 60 * SUBTREES..62 * SUBTREES)?, passed, child(7..8)?], + vec![kept, last_child, child(12..16)?, copies(ends, middle.pending)?, child(5..6)?], + vec![upper, copies(ends, 56 * SUBTREES..58 * SUBTREES)?, child(8..12)?, child(6..7)?], + vec![lower, copies(ends, 52 * SUBTREES..54 * SUBTREES)?, child(18..24)?], + vec![third, child(24..28)?], + ]; + finish_partial_streams(submitted, streams) +} diff --git a/crates/nodes/src/pattern/tile_runs/inactive_children/repeated.rs b/crates/nodes/src/pattern/tile_runs/inactive_children/repeated.rs new file mode 100644 index 00000000..6fc404e6 --- /dev/null +++ b/crates/nodes/src/pattern/tile_runs/inactive_children/repeated.rs @@ -0,0 +1,42 @@ +use super::{COPIES_PER_BATCH, SUBTREES, completion, copies, fill_halves, pending_siblings, receive_pairs}; +use std::ops::Range; + +pub(super) fn submit(ends: &[u32], first_tree: &[u32], submitted: &mut Vec>) -> Option<()> { + if submitted.iter().any(|half| half.end - half.start != COPIES_PER_BATCH) { + return None; + } + let group = |start, end| copies(ends, start * SUBTREES..end * SUBTREES); + let outer = group(62, 64)?; + let incoming = group(48, 50)?; + if (outer.end - outer.start).checked_add(incoming.end - incoming.start)? >= COPIES_PER_BATCH { + return None; + } + + let receivers = receive_pairs(first_tree, submitted); + let [first, middle, last] = receivers.as_slice() else { return None }; + if receivers.iter().any(|p| !matches!((p.split_width, p.pending.len()), (1, 2) | (4, 8))) { + return None; + } + let halves = fill_halves(first_tree, first, submitted)?; + let upper_cut = halves.pairs[1][1].end; + let (upper_siblings, _) = pending_siblings(first_tree.partition_point(|&end| end < upper_cut))?; + // The other outer pair can submit earlier if its incoming siblings fill it. + let other_outer = group(60, 62)?; + let possible = [copies(ends, first.pending.clone())?, copies(ends, last.pending.clone())?, copies(ends, upper_siblings)?]; + let outer_limit = possible.iter().try_fold(other_outer.end - other_outer.start, |sum, range| sum.checked_add(range.end - range.start))?; + if outer_limit >= COPIES_PER_BATCH + || first.tail.start < first.handoff.as_ref()?.end + || middle.tail.start < copies(ends, middle.pending.clone())?.end + || last.tail.start < copies(ends, last.pending.clone())?.end + { + return None; + } + + // The last child of the transferred sibling stays with this outer pair. + // Its unfinished batch continues in the same pair of the following tree. + let last_child = copies(ends, first.pending.end.checked_sub(1)?..first.pending.end)?; + let next_outer = group(64 + 62, 64 + 64)?; + let [full, _] = completion::split_at_copies(&[outer, incoming, last_child, next_outer], COPIES_PER_BATCH)?; + submitted.extend(full); + Some(()) +} diff --git a/crates/nodes/src/pattern/tile_runs/inactive_children/tests.rs b/crates/nodes/src/pattern/tile_runs/inactive_children/tests.rs new file mode 100644 index 00000000..6bf09870 --- /dev/null +++ b/crates/nodes/src/pattern/tile_runs/inactive_children/tests.rs @@ -0,0 +1,256 @@ +use super::ranges; + +// Each of the 16,384 parents draws before its four children. Move the first +// selected draws in one incoming pair to the tile edge, adding one copy each. +fn draw_ranks(edge_draws: usize) -> Vec { + ranks_with_edges(50 * 1280 + 2, 23, edge_draws) +} + +fn ranks_with_edges(first: usize, stride: usize, edge_draws: usize) -> Vec { + ranks_for_copies(|draw| { + let offset = draw.checked_sub(first); + 1 + u32::from(offset.is_some_and(|n| n.is_multiple_of(stride) && n / stride < edge_draws)) + }) +} + +fn ranks_for_copies(count: impl Fn(usize) -> u32) -> Vec { + ranks_for_draws(81_920, count) +} + +fn ranks_for_draws(draws: usize, count: impl Fn(usize) -> u32) -> Vec { + let mut starts = Vec::new(); + let mut ends = Vec::new(); + let mut copies = 0_u32; + for draw in 0..draws { + starts.push(copies); + copies += count(draw); + if (draw + 1).is_multiple_of(80) { + ends.push(copies); + } + } + let mut ranks = vec![usize::MAX; copies as usize]; + for (rank, copy) in ranges(&ends).unwrap().into_iter().flatten().enumerate() { + assert_eq!(ranks[copy as usize], usize::MAX); + ranks[copy as usize] = rank; + } + assert!(!ranks.contains(&usize::MAX)); + starts.into_iter().map(|copy| ranks[copy as usize]).collect() +} + +#[test] +fn a_full_receiving_pair_reorders_the_following_two_batches() { + // Each pair shared a pixel in two signed F32 renders. One extra edge copy + // changes which half-quadrant submits its remaining draws first. + for (edges, before) in [(19, true), (20, false)] { + let rank = draw_ranks(edges); + for (left, right) in [(66560, 59050), (36589, 57785), (39011, 58236), (67164, 57437), (40323, 57678)] { + assert_eq!(rank[left] < rank[right], before, "{edges} edge copies, draws {left}, {right}"); + } + } +} + +#[test] +fn inactive_quadrants_submit_a_second_full_batch_from_the_same_half() { + // Place 679 or 680 independent squares across the same tile edge. The last + // extra copy fills the second batch before the next half starts drawing. + for (extra, before) in [(679, false), (680, true)] { + let mut copies = vec![1; 81_920]; + for i in 0..extra { + copies[24 * 1280 + (1777 * i + 31) % 10240] = 2; + } + let ranks = ranks_for_copies(|draw| copies[draw]); + for (left, right) in [(36173, 15446), (37269, 12312), (36456, 11047)] { + assert_eq!(ranks[left] < ranks[right], before, "{extra} extra copies, draws {left}, {right}"); + } + } +} + +#[test] +fn inactive_quadrants_submit_a_full_outer_pair_before_the_receivers() { + for (extra, before) in [(339, false), (340, true)] { + let mut copies = vec![1; 81_920]; + for i in 0..extra { + copies[62 * 1280 + (233 * i + 71) % 2560] = 2; + } + let ranks = ranks_for_copies(|draw| copies[draw]); + for (left, right) in [(80736, 65485), (80128, 65100), (63952, 66509)] { + assert_eq!(ranks[left] < ranks[right], before, "{extra} extra copies, draws {left}, {right}"); + } + } +} + +#[test] +fn receiving_tails_and_deferred_siblings_follow_the_full_batches() { + let rank = draw_ranks(0); + for (left, right, before) in [(29320, 59050, false), (2960, 72020, false), (50750, 18422, true), (3019, 29753, false)] { + assert_eq!(rank[left] < rank[right], before, "draws {left}, {right}"); + } +} + +#[test] +fn partial_streams_finish_in_the_order_their_remaining_siblings_arrive() { + let ranks = ranks_with_edges(50 * 1280 + 2, 23, 0); + for (left, right, before) in [(67293, 23561, true), (23911, 72552, false), (18729, 43941, false), (16934, 72444, false)] { + assert_eq!(ranks[left] < ranks[right], before, "draws {left}, {right}"); + } + let ranks = ranks_with_edges(50 * 1280 + 2, 23, 20); + for (left, right, before) in [(24093, 77770, false), (79055, 73362, true), (18729, 44010, false), (80854, 23953, true)] { + assert_eq!(ranks[left] < ranks[right], before, "draws {left}, {right}"); + } +} + +#[test] +fn an_incoming_depth_four_sibling_can_pass_its_children_to_other_runs() { + let ranks = ranks_with_edges(24 * 1280 + 1, 9, 40); + for (left, right, before) in [(68062, 73183, false), (67972, 72940, false), (67359, 67445, false), (18729, 72736, false)] { + assert_eq!(ranks[left] < ranks[right], before, "draws {left}, {right}"); + } + let ranks = ranks_with_edges(40 * 1280 + 1, 9, 40); + for (left, right, before) in [(67986, 72413, false), (77734, 23491, true), (79054, 67732, true), (67742, 72985, false)] { + assert_eq!(ranks[left] < ranks[right], before, "draws {left}, {right}"); + } +} + +#[test] +fn a_full_outer_pair_submits_when_its_last_required_copy_arrives() { + // Move squares in the outer pair to the corner (three extra copies) or a + // single edge (one extra copy). Twenty edge squares enter the first receiver. + for (extra, pairs) in [ + (2580_usize, [(77040, 24132, true), (23563, 8764, true)]), + (2739_usize, [(78431, 50530, true), (23572, 8764, true)]), + (2899_usize, [(77666, 70663, true), (77953, 47021, true)]), + (2900_usize, [(77683, 66417, true), (78114, 25244, true)]), + ] { + let mut copies = vec![1; 81_920]; + for i in 0..20 { + copies[50 * 1280 + 2 + 23 * i] = 2; + } + for i in 0..extra / 3 + extra % 3 { + let draw = 60 * 1280 + (211 * i + 17) % 2560; + copies[draw] = if i < extra / 3 { 4 } else { 2 }; + } + let ranks = ranks_for_copies(|draw| copies[draw]); + for (left, right, before) in pairs { + assert_eq!(ranks[left] < ranks[right], before, "{extra} copies, draws {left}, {right}"); + } + } +} + +#[test] +fn a_receiver_can_transfer_a_whole_sibling_and_parts_of_the_next() { + let mut copies = vec![1; 81_920]; + for i in 0..360 { + copies[50 * 1280 + (103 * i + 31) % 2560] = 2; + } + let ranks = ranks_for_copies(|draw| copies[draw]); + for (left, right) in [(66559, 20480), (76799, 0), (71679, 40960)] { + assert!(ranks[left] < ranks[right], "draws {left}, {right}"); + } +} + +#[test] +fn the_third_half_fills_from_the_first_child_of_the_transferred_quarter() { + // Change how many copies of that child fit, from all eighty down to one. + for (extra, next) in [(600, 25200), (620, 25020), (679, 24961)] { + let ranks = ranks_with_transfers(extra, 400); + for (left, right) in [(30719, 2560), (51199, 25040), (25119, 9240), (69119, next)] { + assert!(ranks[left] < ranks[right], "{extra} extra copies, draws {left}, {right}"); + } + } +} + +fn ranks_with_transfers(third_half: usize, last_partner: usize) -> Vec { + let mut copies = vec![1; 81_920]; + for (group, width, amount) in [(24, 8, 680), (40, 8, 680), (8, 8, third_half), (50, 2, 400), (58, 2, 400), (54, 2, last_partner), (62, 2, 340)] { + for i in 0..amount { + copies[group * 1280 + (211 * i + 17) % (width * 1280)] = 2; + } + } + ranks_for_copies(|draw| copies[draw]) +} + +#[test] +fn a_copy_from_the_second_child_changes_which_siblings_return_together() { + // Reducing the third half by one copy makes the batch use both donor children. + for (extra, before) in [(600, false), (599, true)] { + let ranks = ranks_with_transfers(extra, 400); + for (left, right, same_direction) in [(25152, 23943, true), (24708, 74015, false), (67104, 24733, true)] { + assert_eq!(ranks[left] < ranks[right], before == same_direction, "{extra} extra copies, draws {left}, {right}"); + } + } + // The second child can also supply its last copy to the full batch. + let ranks = ranks_with_transfers(520, 400); + for (left, right) in [(51199, 25120), (25199, 9240), (25279, 24640)] { + assert!(ranks[left] < ranks[right], "draws {left}, {right}"); + } +} + +#[test] +fn the_last_receiver_can_return_one_or_two_smaller_subtrees() { + for (third_half, partner, pairs) in + [(620, 200, [(43759, 24560), (78049, 43726)]), (620, 260, [(78147, 43698), (43603, 24797)]), (551, 300, [(43755, 24508), (49378, 43635)])] + { + let ranks = ranks_with_transfers(third_half, partner); + for (left, right) in pairs { + assert!(ranks[left] < ranks[right], "third half {third_half}, partner {partner}, draws {left}, {right}"); + } + } +} + +fn ranks_with_outer_cut(field: usize, outer: usize) -> Vec { + let mut copies = vec![1; 81_920]; + let regions = [ + (24, 8, 700 + 17 * field), + (40, 8, 730 + 21 * field), + (8, 8, 702 + 25 * field), + (50, 2, 500 + 9 * field), + (58, 2, 530 + 6 * field), + (54, 2, 341 + 7 * field), + (62, 2, outer), + ]; + for (group, width, amount) in regions { + for i in 0..amount { + copies[group * 1280 + (1777 * i + 32 + field) % (width * 1280)] = 2; + } + } + ranks_for_copies(|draw| copies[draw]) +} + +#[test] +fn a_deferred_outer_child_changes_which_pair_submits_first() { + // The extra edge copy moves the cut across the boundary between two depth-five siblings. + for (outer, before) in [(499, false), (500, true), (501, true)] { + let ranks = ranks_with_outer_cut(3, outer); + assert_eq!(ranks[69208] < ranks[64124], before, "{outer} extra copies"); + } +} + +#[test] +fn the_cut_outer_child_resumes_between_two_transferred_siblings() { + for (field, pairs) in + [(3, [(63874, 63822), (44118, 63836), (63820, 63951), (63826, 44577)]), (7, [(63906, 63818), (44109, 63806), (63838, 63962), (63791, 44740)])] + { + let ranks = ranks_with_outer_cut(field, 501 + 8 * field); + for (left, right) in pairs { + assert!(ranks[left] < ranks[right], "field {field}, draws {left}, {right}"); + } + } +} + +#[test] +fn a_repeated_tree_fills_the_batch_left_by_the_outer_pair() { + for extra in [0, 100, 259] { + let mut copies = vec![1; 163_840]; + for i in 0..extra { + copies[62 * 1280 + (173 * i + 37) % 2560] = 2; + } + let ranks = ranks_for_draws(copies.len(), |draw| copies[draw]); + // The first tree supplies its outer pair and the last transferred child. + // The next tree supplies exactly the copies still missing from the batch. + let next_outer = 81_920 + 62 * 1280; + let cut = next_outer + 260 - extra; + assert!(ranks[23_599] < ranks[next_outer]); + assert!(ranks[cut - 1] < ranks[67_250]); + assert!(ranks[cut] > ranks[67_261]); + } +} diff --git a/crates/nodes/src/pattern/tile_runs/inactive_children/wide_transfer.rs b/crates/nodes/src/pattern/tile_runs/inactive_children/wide_transfer.rs new file mode 100644 index 00000000..71ea8f59 --- /dev/null +++ b/crates/nodes/src/pattern/tile_runs/inactive_children/wide_transfer.rs @@ -0,0 +1,55 @@ +use super::{COPIES_PER_BATCH, ReceivingPair, SUBTREES, copies, finish_partial_streams, remainder}; +use std::ops::Range; + +pub(super) fn ranges(ends: &[u32], receivers: &[ReceivingPair], leading: &[Range], outer_tail: &Range) -> Option>> { + let [first, middle, last] = receivers else { return None }; + let whole_sibling = |pair: &ReceivingPair| pair.split_width == SUBTREES && pair.pending.len() == SUBTREES; + // The last receiver can also return one or two depth-five subtrees to the + // same unfinished stream. Larger partial siblings can change its order. + let last_returns_to_pair = whole_sibling(last) || last.split_width == 1 && last.pending.len() <= 2; + if !whole_sibling(first) || !whole_sibling(middle) || !last_returns_to_pair { + return None; + } + let [lower, upper, third, ..] = leading else { return None }; + let lower = remainder(ends, 24, lower, 2)?; + let upper = remainder(ends, 40, upper, 2)?; + let third = remainder(ends, 8, third, 1)?; + + // The first receiver transfers a whole sibling, then a half and a quarter + // of the following sibling. Their descendants can finish different streams. + let whole = first.pending.start; + let half = first.pending.end; + let quarter = half + SUBTREES / 2; + let children = |start: usize, offsets: Range| copies(ends, start + offsets.start..start + offsets.end); + let room = COPIES_PER_BATCH.checked_sub(third.end - third.start)?; + let first_child = children(quarter, 0..1)?; + // When the batch enters the second child, the middle receiver takes the + // first child of the half. The upper receiver then takes its third child. + let (donor_children, outer_children, returned_half, upper_child) = + if room <= first_child.end - first_child.start { (1, 3..3, 2..3, children(quarter, 2..3)?) } else { (2, 3..4, 4..6, children(half, 2..3)?) }; + let donor = children(quarter, 0..donor_children)?; + if room == 0 || room > donor.end - donor.start { + return None; + } + let cut = donor.start + room; + let mut runs = leading.to_vec(); + runs.extend([third, donor.start..cut, first.tail.clone(), copies(ends, middle.pending.clone())?]); + let middle_start = donor_children - 1; + if middle_start > 0 { + runs.push(children(half, 0..middle_start)?); + } + runs.push(last.tail.clone()); + + // After the third half fills, each unfinished stream receives its remaining + // siblings. A stream that fills at this stage has a different submission time. + let streams = [ + vec![children(quarter, donor_children..donor_children + 1)?], + vec![middle.tail.clone(), children(whole, 0..8)?, children(half, middle_start..2)?], + vec![copies(ends, 60 * SUBTREES..62 * SUBTREES)?, children(whole, 8..16)?, copies(ends, last.pending.clone())?], + vec![outer_tail.clone(), children(half, outer_children)?, children(half, returned_half.end..8)?], + vec![upper, copies(ends, 56 * SUBTREES..58 * SUBTREES)?, upper_child], + vec![lower, copies(ends, 52 * SUBTREES..54 * SUBTREES)?], + vec![cut..donor.end, children(quarter, 3..4)?, children(half, returned_half)?], + ]; + finish_partial_streams(runs, streams) +} diff --git a/crates/nodes/src/pattern/tile_runs/paired_batches.rs b/crates/nodes/src/pattern/tile_runs/paired_batches.rs new file mode 100644 index 00000000..43069aef --- /dev/null +++ b/crates/nodes/src/pattern/tile_runs/paired_batches.rs @@ -0,0 +1,401 @@ +use super::DEPTH_THREE_PARENTS; + +#[derive(Clone, Copy)] +pub(super) enum PairedBatches { + ThirdFromEnd, + Penultimate, + Final, +} + +impl PairedBatches { + pub(super) fn ending_at(parents: usize) -> Option { + match parents / DEPTH_THREE_PARENTS { + 60 => Some(Self::ThirdFromEnd), + 62 => Some(Self::Penultimate), + 64 => Some(Self::Final), + _ => None, + } + } + + pub(super) fn layout(self) -> &'static [(usize, usize)] { + match self { + Self::ThirdFromEnd => THIRD_PAIR_FROM_END, + Self::Penultimate => PENULTIMATE_PAIR, + Self::Final => FINAL_PAIR, + } + } +} + +// Three full final pairs have the same first 32 submissions. If the partial +// subtrees from groups 61 and 16 fill a batch, their remainder moves to a later run. +pub(super) fn three_final_pairs(filled: bool) -> Vec<(usize, usize)> { + let prefix = [ + 16384, 13057, 7940, 14081, 12034, 15360, 3845, 15616, 13312, 4160, 6027, 14336, 8256, 10120, 15360, 256, 1795, 4096, 15622, 8192, 13376, 13701, 16384, + 12545, 2048, 13381, 12288, 14400, 14722, 6144, 8384, 12620, + ]; + let middle = if filled { + [15616, 15872, 4288, 10240, 393, 12672, 576, 512, 768, 13440, 14464, 640, 4288] + } else { + [10240, 392, 15616, 15872, 4288, 641, 12672, 576, 512, 768, 13440, 14464, 640] + }; + let suffix = [704, 12608, 12800, 14528, 14848, 13824, 12736, 15744, 13504]; + ranked_ends(prefix.into_iter().chain(middle).chain(suffix)) +} + +// With eight batches in groups 24–31, the tail of groups 32–39 can +// fill a later batch with the two middle subtrees of group 0. +pub(super) fn eight_middle_groups(last_cut: usize, middle_cut: usize, filled: bool) -> Vec<(usize, usize)> { + let prefix = [ + last_cut, 13057, 8192, 14336, 12039, 15105, 3844, 15616, 13312, 4160, 6027, 14336, 8512, middle_cut, 15360, 64, 1926, 4096, 15620, 8192, 13569, 16384, + 12352, 12674, 12288, 14400, 14727, 6144, 8640, + ]; + let middle: &[usize] = if filled { &[12364, 10240, 192, 12416, 192] } else { &[12416, 10240, 192] }; + let suffix = [2048, 13696, 14464, 15872, 4288, 12800, 14528, 14848, 13632, 13824, 12480, 15744, 13760]; + ranked_ends(prefix.into_iter().chain(middle.iter().copied()).chain(suffix)) +} + +fn ranked_ends(ends: impl Iterator) -> Vec<(usize, usize)> { + let mut layout: Vec<_> = ends.enumerate().map(|(rank, end)| (end, rank)).collect(); + // Natural parent order locates each span. Equal endpoints split at a physical batch boundary. + layout.sort_unstable(); + layout +} + +// Depth-seven parent endpoints and compositing ranks measured with original square overlaps. +// Inside a depth-four subtree the physical batch count determines the exact copy at the split. +// The tail of groups 54 and 55 fills another batch with group 32. Two runs then +// end at the same parent count because only the physical copy count separates them. +pub(super) const FULL_RECEIVING_QUADRANT: &[(usize, usize)] = &[ + (64, 15), + (65, 25), + (192, 43), + (1926, 16), + (2048, 34), + (3847, 6), + (4096, 17), + (4160, 9), + (4288, 39), + (6022, 10), + (6144, 22), + (7942, 2), + (8192, 19), + (8448, 12), + (8581, 23), + (8704, 28), + (8832, 53), + (8960, 29), + (9985, 13), + (10240, 24), + (12035, 4), + (12288, 26), + (12352, 32), + (12416, 42), + (12480, 51), + (12675, 33), + (12800, 47), + (13058, 1), + (13312, 8), + (13376, 20), + (13440, 35), + (13504, 55), + (13703, 21), + (13824, 52), + (14336, 3), + (14336, 11), + (14341, 27), + (14400, 48), + (14406, 30), + (14464, 41), + (14528, 44), + (14592, 49), + (14663, 36), + (14720, 45), + (14723, 40), + (14784, 46), + (14848, 50), + (15106, 5), + (15360, 14), + (15618, 7), + (15680, 37), + (15688, 18), + (15808, 54), + (15872, 38), + (16130, 0), + (16384, 31), +]; + +// After groups 50–51, the first group in the second quadrant fills another batch. +pub(super) const FULL_SECOND_QUADRANT: &[(usize, usize)] = &[ + (64, 15), + (192, 37), + (1925, 16), + (2048, 38), + (3841, 6), + (4096, 17), + (4352, 9), + (4481, 32), + (4608, 41), + (4736, 35), + (4800, 46), + (4864, 42), + (5889, 10), + (6144, 22), + (7942, 2), + (8192, 19), + (8256, 12), + (8259, 23), + (8384, 33), + (10118, 13), + (10240, 36), + (12035, 4), + (12288, 27), + (12352, 25), + (12416, 34), + (12480, 48), + (12673, 26), + (12800, 43), + (13312, 1), + (13312, 8), + (13376, 20), + (13440, 39), + (13504, 50), + (13703, 21), + (13824, 47), + (14081, 3), + (14336, 11), + (14400, 28), + (14464, 40), + (14528, 44), + (14725, 29), + (14848, 45), + (15105, 5), + (15360, 14), + (15617, 7), + (15680, 30), + (15682, 18), + (15808, 49), + (15872, 31), + (16128, 0), + (16384, 24), +]; + +const THIRD_PAIR_FROM_END: &[(usize, usize)] = &[ + (256, 15), + (394, 34), + (512, 41), + (576, 40), + (640, 45), + (641, 38), + (704, 46), + (768, 42), + (1794, 16), + (2048, 25), + (3846, 6), + (4096, 17), + (4160, 9), + (4288, 37), + (6023, 10), + (6144, 30), + (7941, 2), + (8192, 19), + (8256, 12), + (8384, 31), + (10121, 13), + (10240, 33), + (12033, 4), + (12288, 27), + (12352, 23), + (12360, 32), + (12416, 39), + (12480, 51), + (12674, 24), + (12800, 47), + (13058, 1), + (13312, 8), + (13376, 20), + (13379, 26), + (13440, 43), + (13504, 53), + (13702, 21), + (13824, 50), + (14082, 3), + (14336, 11), + (14400, 28), + (14464, 44), + (14528, 48), + (14722, 29), + (14848, 49), + (15360, 5), + (15360, 14), + (15617, 7), + (15680, 35), + (15687, 18), + (15808, 52), + (15872, 36), + (16129, 0), + (16384, 22), +]; + +const PENULTIMATE_PAIR: &[(usize, usize)] = &[ + (64, 15), + (192, 36), + (1927, 16), + (2048, 37), + (3844, 6), + (4096, 17), + (4160, 9), + (4288, 33), + (4288, 40), + (6022, 10), + (6144, 28), + (7942, 2), + (8192, 19), + (8256, 12), + (8384, 29), + (10118, 13), + (10240, 35), + (12034, 4), + (12288, 25), + (12352, 23), + (12359, 30), + (12416, 34), + (12480, 45), + (12673, 24), + (12800, 41), + (13058, 1), + (13312, 8), + (13376, 20), + (13440, 38), + (13504, 47), + (13703, 21), + (13824, 44), + (14081, 3), + (14336, 11), + (14400, 26), + (14464, 39), + (14528, 42), + (14724, 27), + (14848, 43), + (15105, 5), + (15360, 14), + (15617, 7), + (15680, 31), + (15684, 18), + (15808, 46), + (15872, 32), + (16129, 0), + (16384, 22), +]; + +const FINAL_PAIR: &[(usize, usize)] = &[ + (64, 15), + (192, 31), + (1929, 16), + (2048, 32), + (3849, 6), + (4096, 17), + (4160, 9), + (4288, 37), + (6023, 10), + (6144, 27), + (7942, 2), + (8192, 19), + (8256, 12), + (8384, 28), + (10114, 13), + (10240, 30), + (12037, 4), + (12288, 24), + (12544, 23), + (12544, 38), + (12672, 29), + (12736, 43), + (12800, 39), + (13058, 1), + (13312, 8), + (13376, 20), + (13440, 33), + (13504, 45), + (13703, 21), + (13824, 42), + (14081, 3), + (14336, 11), + (14400, 25), + (14464, 34), + (14528, 40), + (14725, 26), + (14848, 41), + (15105, 5), + (15360, 14), + (15618, 7), + (15680, 35), + (15690, 18), + (15808, 44), + (15872, 36), + (16384, 0), + (16384, 22), +]; + +// The repeated endpoint at group 61 splits the last part of group 60 from its current batch. +pub(super) const ALL_FULL_PAIRS: &[(usize, usize)] = &[ + (256, 15), + (507, 22), + (512, 28), + (635, 39), + (640, 44), + (768, 29), + (2044, 16), + (2048, 47), + (4092, 6), + (4096, 57), + (4352, 9), + (4479, 27), + (4480, 40), + (4544, 55), + (4608, 41), + (4667, 36), + (4736, 56), + (4864, 42), + (6140, 10), + (6144, 19), + (8188, 2), + (8192, 17), + (8448, 12), + (8699, 20), + (8704, 37), + (8832, 35), + (8960, 38), + (10236, 13), + (10240, 21), + (12284, 4), + (12288, 23), + (12543, 32), + (12544, 51), + (12672, 46), + (12735, 43), + (12736, 50), + (12800, 52), + (13311, 1), + (13312, 8), + (13563, 18), + (13568, 33), + (13696, 48), + (13760, 59), + (13824, 34), + (14335, 3), + (14336, 11), + (14587, 24), + (14592, 53), + (14715, 30), + (14720, 45), + (14784, 49), + (14848, 54), + (15359, 5), + (15360, 14), + (15616, 7), + (15616, 25), + (15744, 58), + (15872, 26), + (16383, 0), + (16384, 31), +]; diff --git a/crates/nodes/src/pattern/tile_runs/sparse_quadrants.rs b/crates/nodes/src/pattern/tile_runs/sparse_quadrants.rs new file mode 100644 index 00000000..aa668508 --- /dev/null +++ b/crates/nodes/src/pattern/tile_runs/sparse_quadrants.rs @@ -0,0 +1,112 @@ +use std::ops::Range; + +use super::{Footprint, TileCopies, two_children}; +use crate::CookContext; +use crate::pattern::{ + pattern_stamp::{DrawRun, PatternStamp}, + raster::MIN_STAMP_SIZE, +}; +use materialcraft_core::{PatternNode, PatternNodeKind}; + +pub(in crate::pattern) struct SparseQuadrantRuns { + copies: TileCopies, + parents: Vec>, + groups: Vec>, + draws: usize, + shape: Option, + saw_zero: bool, +} + +impl SparseQuadrantRuns { + pub(in crate::pattern) fn new(context: &CookContext) -> Option { + if context.b("cull_outside") || !matches!(context.tiling_axes(), [false, false] | [true, true]) { + return None; + } + Some(Self { copies: TileCopies::new(context, 8, super::UNIT_WINDOW)?, parents: Vec::new(), groups: Vec::new(), draws: 0, shape: None, saw_zero: false }) + } + + pub(in crate::pattern) fn visit(&self, node: &PatternNode, depth: u32) -> bool { + node.kind == PatternNodeKind::Quadrant + && match depth { + 3 if self.parents.is_empty() => false, + 0..=7 => node.children.iter().flatten().count() == 4, + 8 => node.children.iter().all(Option::is_none), + _ => false, + } + } + + pub(in crate::pattern) fn draw(&mut self, stamp: &PatternStamp, opacities: &[f32], retained: bool) -> Option<()> { + let weight = *opacities.get(stamp.depth as usize)?; + let empty = stamp.color[3] == 0.0; + if !(2..=8).contains(&stamp.depth) + || !(2..=16).contains(&stamp.pattern) + || stamp.blend != 0 + || *self.shape.get_or_insert(stamp.pattern) != stamp.pattern + || !weight.is_finite() + || stamp.center.iter().chain(&stamp.size).chain([&stamp.rotation, &stamp.variation]).any(|value| !value.is_finite()) + || !(empty || (stamp.color[3].is_normal() && weight.is_normal() && (stamp.color[3] * weight).is_normal())) + || stamp.size.iter().any(|axis| axis.abs() < MIN_STAMP_SIZE) + { + return None; + } + if empty { + // Raster validation precedes its zero-luminosity skip. + Footprint::new(stamp).ok()?; + self.saw_zero = true; + } + self.draws += 1; + let range = self.copies.count_stamp((!empty).then_some(stamp), retained)?; + match stamp.depth { + 2 => self.parents.push(range), + 3 => self.groups.push(range), + _ => self.groups.last_mut()?.end = range.end, + } + Some(()) + } + + pub(in crate::pattern) fn finish<'a>(self, stamps: &'a [PatternStamp]) -> Option>> { + // A complete tree has 4^2 + ... + 4^8 authored draws. The measured sparse case + // has at least one zero-luminosity draw, which consumes no batch capacity. + if self.draws != 87_376 || self.parents.len() != 16 || self.groups.len() != 64 || !self.saw_zero { + return None; + } + let mut ends = [0; 64]; + let mut pieces: Vec<(u32, Range)> = Vec::new(); + let mut submitted = 0_u32; + for (group, children) in self.groups.into_iter().enumerate() { + // In the final quadrant each depth-two parent precedes the second pair of + // depth-three groups. Earlier parents precede the first pair. + let slot = if group < 48 { 0 } else { 2 }; + let parent = (group % 4 == slot).then(|| self.parents[group / 4].clone()); + for range in parent.into_iter().chain([children]).filter(|r| !r.is_empty()) { + let start = submitted; + submitted = submitted.checked_add(range.end - range.start)?; + if let Some((_, previous)) = pieces.last_mut() + && previous.end == range.start + { + previous.end = range.end; + } else { + pieces.push((start, range)); + } + } + ends[group] = submitted; + } + if submitted != self.copies.positions.total { + return None; + } + + let mut runs = Vec::new(); + for batch in two_children::ranges(&ends)? { + for (offset, source) in &pieces { + let first = batch.start.saturating_sub(*offset); + let end = batch.end.saturating_sub(*offset).min(source.end - source.start); + if first < end { + let start = self.copies.positions.at(source.start + first); + let stop = self.copies.positions.at(source.start + end); + runs.push(DrawRun::between(stamps, start, stop)?); + } + } + } + Some(runs) + } +} diff --git a/crates/nodes/src/pattern/tile_runs/two_children.rs b/crates/nodes/src/pattern/tile_runs/two_children.rs new file mode 100644 index 00000000..40be9720 --- /dev/null +++ b/crates/nodes/src/pattern/tile_runs/two_children.rs @@ -0,0 +1,269 @@ +use super::COPIES_PER_BATCH; +use std::ops::Range; + +// A batch counts individual tile copies, including copies outside the readout. Overlapping +// squares distinguish both the split inside a subtree and the order of the following subtrees. +struct Split { + partner: Range, + prefix: Range, + remainder: Range, + next: Range, + extra: Range, + last: Range, + // Whole groups after the split and before the separately submitted last group. + whole_groups: usize, +} + +fn leading(bounds: &[u32; 65], group: usize) -> Option<[Range; 2]> { + let cut = bounds[group].checked_add(COPIES_PER_BATCH)?; + if cut > bounds[group + 8] { + return Some([0..0, bounds[group]..bounds[group + 8]]); + } + (bounds[group + 6]..=bounds[group + 8]).contains(&cut).then_some([bounds[group]..cut, cut..bounds[group + 8]]) +} + +struct LeadingPair { + prefix: Range, + tail: Range, + partner: Range, + completion: Option<[Range; 2]>, +} + +fn leading_pair(bounds: &[u32; 65], group: usize, partner_group: usize) -> Option { + let [prefix, mut tail] = leading(bounds, group)?; + let mut partner = bounds[partner_group]..bounds[partner_group + 2]; + let completion = if prefix.is_empty() { + let missing = COPIES_PER_BATCH.checked_sub(tail.end - tail.start)?; + let cut = partner.start.checked_add(missing)?; + // Crossing the first partner group can change the subsequent submission order. + if cut >= bounds[partner_group + 1] { + return None; + } + let borrowed = partner.start..cut; + partner.start = cut; + Some([std::mem::take(&mut tail), borrowed]) + } else { + None + }; + Some(LeadingPair { prefix, tail, partner, completion }) +} + +fn paired(bounds: &[u32; 65], group: usize, partner: usize) -> Option { + let partner = bounds[partner]..bounds[partner + 2]; + let remaining = COPIES_PER_BATCH.checked_sub(partner.end - partner.start)?; + let cut = bounds[group].checked_add(remaining)?; + // Beyond these three observed split positions the continuation order is unknown. + if !(bounds[group + 4]..bounds[group + 7]).contains(&cut) { + return None; + } + let whole_groups = if cut < bounds[group + 5] { + 2 + } else if cut < bounds[group + 6] { + 1 + } else { + 0 + }; + let at = group + 6 - whole_groups; + // The last group is submitted separately even when the preceding group contains the cut. + let next_end = (at + 2).min(group + 7); + Some(Split { + partner, + prefix: bounds[group]..cut, + remainder: cut..bounds[at + 1], + next: bounds[at + 1]..bounds[next_end], + extra: bounds[next_end]..bounds[group + 7], + last: bounds[group + 7]..bounds[group + 8], + whole_groups, + }) +} + +pub(super) fn ranges(subtree_ends: &[u32]) -> Option>> { + let ends: &[u32; 64] = subtree_ends.try_into().ok()?; + let mut bounds = [0; 65]; + bounds[1..].copy_from_slice(ends); + let [first, second, third] = super::LEADING_SUBTREES; + let mut lead24 = leading_pair(&bounds, first, 52)?; + let mut lead40 = leading_pair(&bounds, second, 56)?; + let [lead8, mut tail8] = leading(&bounds, third)?; + let pair0 = paired(&bounds, 0, 58)?; + let pair16 = paired(&bounds, 16, 50)?; + let mut pair32 = paired(&bounds, 32, 54)?; + + let mut runs = Vec::with_capacity(32); + if (lead24.completion.is_some() || lead40.completion.is_some()) && [&pair0, &pair16, &pair32].iter().any(|pair| pair.whole_groups == 2) { + // A fifth-group split leaves a further whole group whose position is unknown here. + return None; + } + runs.extend([lead24.prefix, lead40.prefix, lead8]); + let mut no_completion = None; + let mut prefixes = [(&pair16, &mut lead24.completion), (&pair32, &mut lead40.completion), (&pair0, &mut no_completion)]; + if pair16.whole_groups == 2 { + prefixes.swap(1, 2); + } + for (pair, completion) in prefixes { + runs.extend([pair.partner.clone(), pair.prefix.clone()]); + if pair.whole_groups == 0 + && let Some(batch) = completion.take() + { + runs.extend(batch); + } + } + // When both short blocks are still pending, the split at group 0 orders their finishes. + let pending = if pair0.whole_groups == 0 { [lead24.completion, lead40.completion] } else { [lead40.completion, lead24.completion] }; + for batch in pending.into_iter().flatten() { + runs.extend(batch); + } + let missing = COPIES_PER_BATCH.saturating_sub(bounds[16] - bounds[8]); + if missing != 0 && pair16.whole_groups == 2 && pair0.whole_groups == 2 && !pair32.extra.is_empty() { + // This extra group normally follows the last leading block. Its first copies + // can fill that block after the three paired prefixes have been submitted. + let cut = pair32.extra.start.checked_add(missing)?; + if cut > pair32.extra.end { + return None; + } + runs.extend([tail8, pair32.extra.start..cut]); + tail8 = 0..0; + pair32.extra.start = cut; + } + runs.extend([pair16.remainder, pair16.last]); + // An early split leaves one extra whole subtree. Its position depends on which other + // batches also split early, even when their stamps never overlap that subtree. + let (after_next, after48, after56, after8) = if pair16.whole_groups == 2 { + if pair0.whole_groups == 0 { + runs.extend([pair32.next, pair32.remainder, pair32.last, pair0.remainder, pair0.last]); + } else { + runs.extend([pair0.next, pair32.remainder, pair32.last, pair0.remainder, pair0.last, pair32.next]); + } + let (near, far) = if pair0.whole_groups == 2 { (0..0, pair32.extra) } else { (pair32.extra, 0..0) }; + (near, pair16.extra, pair0.extra, far) + } else if pair32.whole_groups != 1 { + runs.extend([pair32.next, pair0.next, pair32.remainder, pair32.last, pair0.extra, pair0.remainder, pair0.last]); + (0..0, pair32.extra, 0..0, 0..0) + } else { + runs.extend([pair32.next, pair32.remainder, pair32.last, pair0.next, pair0.remainder, pair0.last]); + (0..0, pair0.extra, 0..0, 0..0) + }; + runs.extend([ + bounds[60]..bounds[62], + pair16.next, + after_next, + bounds[62]..bounds[64], + bounds[48]..bounds[50], + after48, + lead40.tail, + lead40.partner, + after56, + lead24.tail, + lead24.partner, + tail8, + after8, + ]); + runs.retain(|r| !r.is_empty()); + Some(runs) +} + +#[cfg(test)] +mod tests { + use super::ranges; + + #[test] + fn sparse_quadrants_submit_whole_groups_around_late_splits() { + // Each square pair shares one pixel in an independent signed F32 readout. + for ([left, center, right, short, first_lead, second_lead], markers) in [ + ( + [145, 95, 66, 96, 96, 96], + &[(4611, 28380, false), (5522, 28416, false), (4616, 28985, true), (5532, 28385, false), (5553, 3920, false), (6446, 6489, true)][..], + ), + ( + [66, 145, 95, 85, 96, 96], + &[(27796, 3636, false), (28507, 3672, false), (27801, 27075, false), (27806, 28517, true), (4256, 27260, false), (4231, 28559, false)][..], + ), + ( + [145, 145, 145, 85, 96, 96], + &[ + (31524, 16510, false), + (31539, 16740, false), + (32435, 16546, false), + (31529, 19273, true), + (31749, 20189, false), + (31994, 43209, false), + (8046, 16552, false), + (12483, 43935, false), + (31754, 7369, false), + ][..], + ), + ( + [95, 66, 95, 96, 84, 83], + &[ + (16419, 21837, true), + (16424, 5, true), + (16429, 11577, false), + (27612, 21842, false), + (27617, 16450, false), + (35893, 15, true), + (38794, 20, false), + (38799, 35898, false), + (5775, 35903, true), + ][..], + ), + ( + [95, 95, 66, 84, 83, 82], + &[ + (16963, 22349, false), + (16968, 5, false), + (27191, 10, true), + (27196, 22354, false), + (27201, 16994, true), + (35445, 15, false), + (38346, 20, true), + (38351, 35450, true), + (5775, 35455, false), + ][..], + ), + ( + [66, 95, 95, 85, 82, 84], + &[ + (16067, 21421, false), + (16072, 5, false), + (27191, 10, false), + (27201, 16098, false), + (27217, 16103, false), + (35509, 15, false), + (38410, 20, false), + (38415, 35514, false), + (38420, 16109, false), + ][..], + ), + ] { + let mut copies = 0_u32; + let ends: [u32; 64] = std::array::from_fn(|group| { + let quota = match group { + 0..8 => left, + 8..16 => short, + 16..24 => center, + 24..32 => first_lead, + 32..40 => right, + 40..48 => second_lead, + _ => 96, + }; + let parent_slot = if group < 48 { 0 } else { 2 }; + copies += 4 * (85 + quota) + 1 + u32::from(group % 4 == parent_slot); + copies + }); + let order: Vec<_> = ranges(&ends).unwrap().into_iter().flatten().collect(); + let mut ranks = vec![usize::MAX; copies as usize]; + for (rank, copy) in order.into_iter().enumerate() { + assert_eq!(ranks[copy as usize], usize::MAX); + ranks[copy as usize] = rank; + } + assert!(!ranks.contains(&usize::MAX)); + for &(first, second, before) in markers { + assert_eq!( + ranks[first] < ranks[second], + before, + "copies {first} and {second}, quotas {left}, {center}, {right}, {short}, {first_lead}, {second_lead}" + ); + } + } + } +} diff --git a/crates/nodes/src/pattern/underfilled_quadrants.rs b/crates/nodes/src/pattern/underfilled_quadrants.rs new file mode 100644 index 00000000..3fb00d31 --- /dev/null +++ b/crates/nodes/src/pattern/underfilled_quadrants.rs @@ -0,0 +1,669 @@ +mod carried; +mod remaining; + +use remaining::{RemainingCopies, SiblingOffsets}; +use std::ops::Range; + +use materialcraft_core::{PatternNode, PatternNodeKind}; + +use super::{ + footprint::SampleGrid, + pattern_stamp::{CopyPositions, DrawPosition, DrawRun, PatternStamp}, + raster::MIN_STAMP_SIZE, + tile_runs::{COPIES_PER_BATCH, LEADING_SUBTREES}, +}; + +// Each of the sixteen depth-two quadrants contributes five consecutive ranges: +// its own draw, then the four child subtrees. Overlapping squares expose these +// eight submission groups before any group fills a physical copy batch. +const GROUPS: [&[(usize, usize)]; 8] = [ + &[(60, 61), (63, 65), (20, 30)], + &[(65, 66), (68, 70), (40, 50)], + &[(70, 71), (73, 75), (0, 10)], + &[(76, 78)], + &[(75, 76), (78, 80), (61, 63)], + &[(50, 60), (71, 73)], + &[(30, 40), (66, 68)], + &[(10, 20)], +]; +// After the leading pairs fill their batches, the last root child collects a +// batch from these three ranges in submission order. They are separate in traversal. +const LAST_CHILD_GROUP: usize = 4; +// Indexed by child slot within the last root quadrant. Each group can fill a +// batch with its depth-two draw and its last two child subtrees alone. +const COLLECTING_GROUPS: [usize; 4] = [0, 1, 2, LAST_CHILD_GROUP]; +// The three leading pairs carry unfinished copy batches into the following tree. +const REPEATED_GROUPS: [usize; 3] = [6, 5, 7]; +// The first two children of the last depth-two quadrant share a separate batch. +const LAST_QUADRANT_PAIR: usize = 3; +const RANGES_PER_CHILD: usize = 1 + 4 * 5; +const RANGES_PER_TREE: usize = 4 * RANGES_PER_CHILD; + +#[derive(Default)] +struct QuadrantPair { + start: usize, + copies: u32, + cut: Option, +} + +impl QuadrantPair { + fn record(&mut self, copies: u32, index: usize, retained: bool) { + let needed = (2 * COPIES_PER_BATCH).saturating_sub(self.copies); + if needed > 0 && needed <= copies { + self.cut = Some(if retained && needed < copies { + DrawPosition { stamp: index, copy: needed } + } else { + DrawPosition { stamp: index + usize::from(retained), copy: 0 } + }); + } + self.copies = self.copies.saturating_add(copies); + } +} + +#[derive(Default)] +struct FollowingPair { + children: usize, + second_child_tail: [u32; 3], + third_child: u32, + third_child_branches: [u32; 4], + fourth_child: u32, + fourth_child_branches: [u32; 4], + fourth_child_grandchildren: [u32; 8], +} + +impl FollowingPair { + fn visit(&mut self, depth: u32, visits_at_depth: usize, copies: u32) { + match depth { + 3 => { + self.children += 1; + match self.children { + 3 => self.third_child = copies, + 4 => self.fourth_child = copies, + _ => {} + } + } + 4 if self.children == 3 => self.third_child_branches[(visits_at_depth - 1) % 4] = copies, + 4 if self.children == 4 => self.fourth_child_branches[(visits_at_depth - 1) % 4] = copies, + 5 if self.children == 2 => self.second_child_tail = [self.second_child_tail[1], self.second_child_tail[2], copies], + 5 if self.children == 4 => { + let child = (visits_at_depth - 1) % 16; + if let Some(offset) = self.fourth_child_grandchildren.get_mut(child) { + *offset = copies; + } + } + _ => {} + } + } +} + +#[derive(Default)] +struct LaterCollectingGroup { + last_child_start: u32, + spans: [CopyPositions; 3], + branches: SiblingOffsets, +} + +#[derive(Default)] +struct RepeatedPair { + middle: CopyPositions, + next: CopyPositions, + later: CopyPositions, + third_tree: CopyPositions, + branches: SiblingOffsets, +} + +#[derive(Clone, Copy)] +enum TrackedSpan { + Collecting(usize, usize), + Middle(usize), + Next(usize), + Later(usize), + ThirdTree(usize), + ThirdCollecting(usize), + LastQuadrantPair(usize), + NextCollecting(usize, usize), +} + +#[derive(Default)] +struct CollectingGroup { + spans: [CopyPositions; 3], + pair: FollowingPair, +} + +impl CollectingGroup { + fn initial_copies(&self) -> u64 { + u64::from(self.spans[0].total) + u64::from(self.spans[1].total) + } + + fn fills_early(&self) -> bool { + self.initial_copies() >= u64::from(COPIES_PER_BATCH) + } + + fn reaches_final_subtrees(&self) -> bool { + self.initial_copies() + u64::from(self.pair.second_child_tail[1]) < u64::from(COPIES_PER_BATCH) + } +} + +#[derive(Default)] +pub(super) struct UnderfilledQuadrants { + // Indices into the retained stamps at each shallow quadrant, including empty ranges. + starts: Vec, + visits: [usize; 9], + saw_iteration: bool, + occupied: Vec, + copies: [u32; GROUPS.len()], + group: usize, + deeper_shape: Option, + first_shape: Option, + first_copies: u64, + pairs: Vec, + collecting: [CollectingGroup; COLLECTING_GROUPS.len()], + repeated: [RepeatedPair; REPEATED_GROUPS.len()], + last_quadrant_pair: [CopyPositions; 2], + next_pair_gap: Range, + next_collecting: [LaterCollectingGroup; 4], + // The third collecting group can fill with its own draw and its first incoming child. + third_collecting: [CopyPositions; 2], + tracked_span: Option, + graph_depth: u32, + active_deep_draws: usize, +} + +impl UnderfilledQuadrants { + pub(super) fn new(graph_depth: u32) -> Self { + Self { graph_depth, ..Self::default() } + } + + fn tracked_span(&self, group: usize, span: usize, first_segment: bool) -> Option { + if self.graph_depth == 10 && group == LAST_QUADRANT_PAIR && (1..=2).contains(&self.visits[0]) { + return Some(TrackedSpan::LastQuadrantPair(self.visits[0] - 1)); + } + if self.graph_depth == 10 + && self.visits[0] == 2 + && let Some(slot) = COLLECTING_GROUPS.iter().position(|&candidate| candidate == group) + { + return Some(TrackedSpan::NextCollecting(slot, span)); + } + if self.visits[0] == 1 + && let Some(slot) = COLLECTING_GROUPS.iter().position(|&g| g == group) + { + return Some(TrackedSpan::Collecting(slot, span)); + } + if self.graph_depth == 10 && self.visits[0] == 3 && group == COLLECTING_GROUPS[2] && span < 2 && first_segment { + return Some(TrackedSpan::ThirdCollecting(span)); + } + let pair = REPEATED_GROUPS.iter().position(|&g| g == group)?; + match (self.visits[0], span) { + (1, 1) => Some(TrackedSpan::Middle(pair)), + (2, 0) => Some(TrackedSpan::Next(pair)), + (2, 1) if self.graph_depth == 10 && pair < 2 => Some(TrackedSpan::Later(pair)), + (3, 0) if self.graph_depth == 10 => Some(TrackedSpan::ThirdTree(pair)), + _ => None, + } + } + + pub(super) fn visit(&mut self, node: &PatternNode, depth: u32, retained: usize) -> bool { + match node.kind { + PatternNodeKind::Iterate => { + // A switch or dot can route to the outer iteration before any quadrant runs. + let outer = !self.saw_iteration && self.visits[0] == 0 && depth == 0; + self.saw_iteration = true; + return outer && node.children.first() == Some(&None); + } + PatternNodeKind::Switch | PatternNodeKind::Dot => return true, + PatternNodeKind::Quadrant => {} + } + let Some(visits) = self.visits.get_mut(depth as usize) else { return false }; + *visits += 1; + if depth == 0 { + return self.starts.len() == (*visits - 1) * RANGES_PER_TREE; + } + if depth > 3 { + if depth == 4 && matches!(self.tracked_span, Some(TrackedSpan::LastQuadrantPair(1))) { + // The next tree defers the third branch of the first quadrant in this pair. + match (*visits - 1) % 8 { + 2 => self.next_pair_gap.start = self.last_quadrant_pair[1].total, + 3 => self.next_pair_gap.end = self.last_quadrant_pair[1].total, + _ => {} + } + } + if depth <= 5 { + self.visit_collecting_branch(depth); + } + return true; + } + let child = self.starts.len() % RANGES_PER_TREE / RANGES_PER_CHILD; + let offset = self.starts.len() % RANGES_PER_CHILD; + self.starts.push(retained); + if offset == 0 { + return depth == 1; + } + let segment = child * 20 + offset - 1; + let parent = (offset - 1).is_multiple_of(5); + if (parent && depth != 2) || (!parent && depth != 3) { + return false; + } + if parent && segment.is_multiple_of(10) { + self.pairs.push(QuadrantPair { start: retained, ..Default::default() }); + } + if !parent { + self.occupied.push(false); + } + let Some((group, span)) = + GROUPS.iter().enumerate().find_map(|(group, spans)| spans.iter().position(|&(lo, hi)| (lo..hi).contains(&segment)).map(|span| (group, span))) + else { + return false; + }; + self.group = group; + self.tracked_span = self.tracked_span(group, span, GROUPS[group][span].0 == segment); + if depth == 3 { + self.visit_collecting_branch(depth); + } + true + } + + fn visit_collecting_branch(&mut self, depth: u32) { + match self.tracked_span { + Some(TrackedSpan::Collecting(slot, 2)) => { + let group = &mut self.collecting[slot]; + group.pair.visit(depth, self.visits[depth as usize], group.spans[2].total); + } + Some(TrackedSpan::NextCollecting(slot, 1)) if depth == 3 => { + let group = &mut self.next_collecting[slot]; + group.last_child_start = group.spans[1].total; + } + Some(TrackedSpan::NextCollecting(slot, 2)) => { + let group = &mut self.next_collecting[slot]; + group.branches.visit(depth, group.spans[2].total); + } + Some(TrackedSpan::Later(slot)) => { + let pair = &mut self.repeated[slot]; + pair.branches.visit(depth, pair.later.total); + } + _ => {} + } + } + + pub(super) fn draw(&mut self, stamp: &PatternStamp, weights: &[f32], grid: Option<&SampleGrid>, index: usize, retained: bool) -> bool { + let Some(weight) = weights.get(stamp.depth as usize) else { return false }; + let gain = weight * stamp.color[3]; + if stamp.blend != 0 || !(2..=16).contains(&stamp.pattern) || stamp.depth == 0 { + return false; + } + if gain == 0.0 || stamp.size.iter().any(|side| side.abs() < MIN_STAMP_SIZE) { + return true; + } + if !gain.is_normal() { + return false; + } + let Some(grid) = grid else { return false }; + if stamp.depth == 1 { + // The first-level shape owns a separate copy batch, including all its wrapped copies. + let Some(count) = grid.copies_per_axis(stamp).and_then(|[x, y]| x.checked_mul(y)) else { return false }; + self.first_copies = self.first_copies.saturating_add(count); + return self.first_copies <= u64::from(COPIES_PER_BATCH) + && *self.first_shape.get_or_insert(stamp.pattern) == stamp.pattern + && self.deeper_shape != Some(stamp.pattern); + } + let Some(count) = grid.copy_count(stamp) else { return false }; + if *self.deeper_shape.get_or_insert(stamp.pattern) != stamp.pattern || self.first_shape == Some(stamp.pattern) { + return false; + } + if stamp.depth >= 3 { + let Some(occupied) = self.occupied.last_mut() else { return false }; + *occupied = true; + } + let Some(pair) = self.pairs.last_mut() else { return false }; + pair.record(count, index, retained); + if let Some(tracked) = self.tracked_span { + let positions = match tracked { + TrackedSpan::Collecting(slot, index) => &mut self.collecting[slot].spans[index], + TrackedSpan::Middle(slot) => &mut self.repeated[slot].middle, + TrackedSpan::Next(slot) => &mut self.repeated[slot].next, + TrackedSpan::Later(slot) => &mut self.repeated[slot].later, + TrackedSpan::ThirdTree(slot) => &mut self.repeated[slot].third_tree, + TrackedSpan::ThirdCollecting(slot) => &mut self.third_collecting[slot], + TrackedSpan::LastQuadrantPair(tree) => &mut self.last_quadrant_pair[tree], + TrackedSpan::NextCollecting(slot, index) => &mut self.next_collecting[slot].spans[index], + }; + if positions.record(count, retained).is_none() { + return false; + } + } + self.active_deep_draws += 1; + self.copies[self.group] = self.copies[self.group].saturating_add(count); + true + } + + fn span_start(&self, tree: usize, group: usize, span: usize) -> Option { + let &(first, _) = GROUPS[group].get(span)?; + self.starts.get(tree * RANGES_PER_TREE + first + 1 + first / 20).copied() + } + + fn copy_range(start: usize, span: &CopyPositions, range: Range) -> Option<(DrawPosition, DrawPosition)> { + let position = |offset| { + let cut = span.at(offset); + Some(DrawPosition { stamp: start.checked_add(cut.stamp)?, copy: cut.copy }) + }; + Some((position(range.start)?, position(range.end)?)) + } + + fn append_copies( + &self, + slot: usize, + pieces: impl IntoIterator)>, + mut remaining: u32, + leading: &mut Vec<(DrawPosition, DrawPosition)>, + ) -> Option<()> { + for (index, range) in pieces { + let span = self.collecting[slot].spans.get(index)?; + let start = self.span_start(0, COLLECTING_GROUPS[slot], index)?; + let count = remaining.min(range.end.checked_sub(range.start)?); + if count != 0 { + leading.push(Self::copy_range(start, span, range.start..range.start + count)?); + } + remaining -= count; + if remaining == 0 { + return Some(()); + } + } + None + } + + fn append_batch(&self, slot: usize, leading: &mut Vec<(DrawPosition, DrawPosition)>) -> Option<()> { + let spans = &self.collecting[slot].spans; + self.append_copies(slot, spans.iter().enumerate().map(|(i, span)| (i, 0..span.total)), COPIES_PER_BATCH, leading) + } + + fn preceding_sibling(&self, slot: usize) -> Option> { + if slot != 2 || self.graph_depth != 10 { + return None; + } + let group = &self.collecting[slot]; + let used = u64::from(COPIES_PER_BATCH).checked_sub(group.initial_copies())?; + let [start, next, last] = group.pair.second_child_tail; + // A cut in this depth-five subtree leaves two siblings in its parent. + // The first moves to the receiving batch and the second stays in the pair. + (u64::from(start) < used && used <= u64::from(next)).then_some(next..last) + } + + fn collecting_handoff(&self, slot: usize) -> Range { + let pair = &self.collecting[slot].pair; + self.preceding_sibling(slot).unwrap_or(pair.third_child..pair.fourth_child) + } + + fn append_following(&self, leading: &mut Vec<(DrawPosition, DrawPosition)>) -> Option<()> { + // A cut before the last two depth-five subtrees can interleave the next stream. + for slot in [0, 2, 1] { + let group = &self.collecting[slot]; + if group.fills_early() { + return Some(()); + } + let late = group.reaches_final_subtrees() || self.preceding_sibling(slot).is_some(); + // At connected depth eight only the third slot submits two consecutive batches in this prefix. + if late && (self.graph_depth > 8 || slot == 2) { + self.append_paired_batches(slot, leading)?; + } else { + self.append_batch(slot, leading)?; + } + if !late { + return Some(()); + } + } + if self.graph_depth == 10 && self.visits[0] == 1 { self.append_single_tree_tail(leading) } else { self.append_repeated_pairs(leading) } + } + + fn append_paired_batches(&self, slot: usize, leading: &mut Vec<(DrawPosition, DrawPosition)>) -> Option<()> { + let group = &self.collecting[slot]; + let [first, middle, tail] = &group.spans; + let pair = &group.pair; + // Each stream skips the sibling handed to another group. The first also skips + // three branches of its fourth child after submitting that child's own draw. + let handoff = self.collecting_handoff(slot); + let gap = if slot == 0 { pair.fourth_child_branches[0]..pair.fourth_child_branches[3] } else { handoff.end..handoff.end }; + let pieces = [(0, 0..first.total), (1, 0..middle.total), (2, 0..handoff.start), (2, handoff.end..gap.start), (2, gap.end..tail.total)]; + self.append_copies(slot, pieces, 2 * COPIES_PER_BATCH, leading) + } + + fn append_repeated_pairs(&self, leading: &mut Vec<(DrawPosition, DrawPosition)>) -> Option<()> { + if self.graph_depth <= 8 || self.visits[0] < 2 { + return Some(()); + } + let mut runs = Vec::with_capacity(REPEATED_GROUPS.len()); + let mut pair_offsets = [0; 3]; + for (slot, &group) in REPEATED_GROUPS.iter().enumerate() { + // At other connected depths, the third pair can submit its depth-five draw after the next tree. + if slot == 2 && self.graph_depth != 10 { + break; + } + let (carried, [tail, middle, branch]) = self.leading_pair_tail(slot)?; + let repeated = &self.repeated[slot]; + if carried >= COPIES_PER_BATCH { + // Either stream filling before the next tree can change their relative order. + return Some(()); + } + // The new tree can fill a third batch with copies carried from the first. + let available = carried.checked_add(repeated.next.total)?; + let next_copies = repeated.next.total.checked_sub(available % COPIES_PER_BATCH)?; + pair_offsets[slot] = next_copies; + runs.push([tail, middle, branch, Self::copy_range(self.span_start(1, group, 0)?, &repeated.next, 0..next_copies)?]); + } + if self.graph_depth == 10 { + return self.append_last_quadrant_pair(leading, runs, pair_offsets); + } + leading.extend(runs.into_iter().flatten()); + Some(()) + } + + fn append_copy_window( + pieces: &[(usize, &CopyPositions, Range)], + mut skip: u32, + mut count: u32, + leading: &mut Vec<(DrawPosition, DrawPosition)>, + ) -> Option<()> { + for (start, span, range) in pieces { + if count == 0 { + return Some(()); + } + let length = range.end.checked_sub(range.start)?; + let offset = skip.min(length); + skip -= offset; + let take = count.min(length - offset); + if take != 0 { + let begin = range.start + offset; + leading.push(Self::copy_range(*start, span, begin..begin + take)?); + count -= take; + } + } + (count == 0).then_some(()) + } + + fn append_last_quadrant_pair( + &self, + leading: &mut Vec<(DrawPosition, DrawPosition)>, + repeated: Vec<[(DrawPosition, DrawPosition); 4]>, + pair_offsets: [u32; 3], + ) -> Option<()> { + let [first, own, children, neighbor] = self.middle_tail()?; + let next = &self.last_quadrant_pair[1]; + let next_start = self.span_start(1, LAST_QUADRANT_PAIR, 0)?; + let last = &self.collecting[1].pair; + let gap = &self.next_pair_gap; + let pieces = [first, own, children, neighbor, (next_start, next, 0..gap.start), (next_start, next, gap.end..next.total)]; + let before_last = pieces[..3].iter().try_fold(0u32, |sum, (_, _, range)| sum.checked_add(range.end.checked_sub(range.start)?))?; + if before_last >= COPIES_PER_BATCH { + // An earlier cut in the first pair can move ahead of the previous submissions. + return Some(()); + } + let carried = before_last.checked_add(last.fourth_child.checked_sub(last.third_child)?)?; + let early_batches = carried / COPIES_PER_BATCH; + if early_batches > 1 { + return Some(()); + } + let total = carried.checked_add(next.total.checked_sub(gap.end.checked_sub(gap.start)?)?)?; + let batches = total / COPIES_PER_BATCH; + let early_receivers = if early_batches == 0 && batches == 1 { [0, 1, 2].map(|slot| self.early_collecting_pieces(slot)) } else { [None, None, None] }; + if self.preceding_sibling(2).is_some() && early_receivers[2].is_none() { + // Without a full receiver the earlier sibling transfer can change the subsequent pairs. + return Some(()); + } + let early = early_batches * COPIES_PER_BATCH; + Self::append_copy_window(&pieces, 0, early, leading)?; + if early != 0 && before_last.checked_add(last.third_child_branches[3].checked_sub(last.third_child)?)? >= COPIES_PER_BATCH { + // Before the last branch, the second and third carried pairs can interleave. + leading.extend(repeated.into_iter().take(1).flatten()); + return Some(()); + } + for (pair, receiver) in repeated.into_iter().zip(early_receivers) { + if let Some(pieces) = receiver { + Self::append_copy_window(&pieces, 0, COPIES_PER_BATCH, leading)?; + } + leading.extend(pair); + } + if !(1..=2).contains(&batches) { + return Some(()); + } + Self::append_copy_window(&pieces, early, batches * COPIES_PER_BATCH - early, leading)?; + if early == 0 && batches == 1 { + self.append_next_collecting_batches(leading, pair_offsets, COPIES_PER_BATCH - carried)?; + } + Some(()) + } + + fn next_collecting_pieces(&self, slot: usize) -> Option<[remaining::Piece<'_>; 6]> { + let [tail, extra, branch] = self.collecting_tail(slot)?; + let [own, children, pair] = &self.next_collecting[slot].spans; + let id = COLLECTING_GROUPS[slot]; + Some([ + tail, + extra, + branch, + (self.span_start(1, id, 0)?, own, 0..own.total), + (self.span_start(1, id, 1)?, children, 0..children.total), + (self.span_start(1, id, 2)?, pair, 0..pair.total), + ]) + } + + fn early_collecting_pieces(&self, slot: usize) -> Option<[remaining::Piece<'_>; 6]> { + let pieces = self.next_collecting_pieces(slot)?; + let before_last_child = Self::piece_count(&pieces[..4])?.checked_add(self.next_collecting[slot].last_child_start)?; + let incoming = Self::piece_count(&pieces[..5])?; + // A batch filled in the last incoming child submits immediately before its own carried pair. + (before_last_child < COPIES_PER_BATCH && (COPIES_PER_BATCH..2 * COPIES_PER_BATCH).contains(&incoming)).then_some(pieces) + } + + fn append_next_collecting_batches(&self, leading: &mut Vec<(DrawPosition, DrawPosition)>, pair_offsets: [u32; 3], middle_used: u32) -> Option<()> { + let mut remainders = Vec::with_capacity(3); + for (slot, next) in self.next_collecting[..3].iter().enumerate() { + let Some(pieces) = self.next_collecting_pieces(slot) else { return Some(()) }; + let (pair_start, pair, _) = pieces[5]; + let carried = Self::piece_count(&pieces[..5])?; + if carried >= COPIES_PER_BATCH { + // Filling before the second tree's pair can change the order of the competing groups. + return Some(()); + } + Self::append_copy_window(&pieces, 0, COPIES_PER_BATCH, leading)?; + let used = COPIES_PER_BATCH - carried; + let Some(mut remainder) = RemainingCopies::new(pair_start, pair, &next.branches, used) else { return Some(()) }; + if !remainder.submit_second(leading)? { + return Some(()); + } + remainders.push(remainder); + } + self.append_remaining_pairs(&remainders, pair_offsets, middle_used, leading) + } + + fn full_batches<'a>(&self, stamps: &'a [PatternStamp], trees: usize) -> Option>> { + // Every quadrant from depth two through eight emits a draw. When a pair + // fills a third batch the competing streams can interleave before this cut. + if self.active_deep_draws != self.visits[2..].iter().sum::() + || self.pairs.len() != trees * 8 + || self.pairs.iter().any(|pair| pair.copies / COPIES_PER_BATCH != 2) + { + return None; + } + let position = |stamp| DrawPosition { stamp, copy: 0 }; + let mut leading = Vec::new(); + let last = &self.collecting[3]; + // Full batches from the last quadrant can precede the three leading pairs. + // Its last child submits first, then each preceding child precedes its own pair. + if last.fills_early() { + self.append_batch(3, &mut leading)?; + } + for (slot, subtree) in LEADING_SUBTREES.into_iter().enumerate() { + if self.collecting[slot].fills_early() { + self.append_batch(slot, &mut leading)?; + } + let pair = self.pairs.get(subtree / 8)?; + leading.push((position(pair.start), pair.cut?)); + } + let copies = last.initial_copies() + u64::from(last.spans[2].total); + if copies / u64::from(COPIES_PER_BATCH) == 1 && !last.fills_early() { + self.append_batch(3, &mut leading)?; + if last.reaches_final_subtrees() { + self.append_following(&mut leading)?; + } + } + leading.retain(|(start, end)| start < end); + let mut runs: Vec<_> = leading.iter().map(|&(start, end)| DrawRun::between(stamps, start, end)).collect::>()?; + // Remove the submitted pieces in traversal order. A wrapped stamp may contribute to both sides of a cut. + leading.sort_unstable(); + let mut submitted = leading.into_iter().peekable(); + for tree in 0..trees { + for child in 0..4 { + let base = tree * RANGES_PER_TREE + child * RANGES_PER_CHILD; + let mut start = position(*self.starts.get(base + 1)?); + let end = position(*self.starts.get(base + RANGES_PER_CHILD)?); + while submitted.peek().is_some_and(|(first, _)| *first < end) { + let (first, next) = submitted.next()?; + runs.push(DrawRun::between(stamps, start, first)?); + start = next; + } + runs.push(DrawRun::between(stamps, start, end)?); + } + } + Some(runs) + } + + pub(super) fn finish(mut self, stamps: &[PatternStamp]) -> Option>> { + let trees = self.visits[0]; + if trees == 0 + || self.visits.iter().enumerate().any(|(depth, &count)| count != trees << (2 * depth)) + || self.starts.len() != trees * RANGES_PER_TREE + || self.occupied.len() != trees * 64 + || self.occupied.contains(&false) + { + return None; + } + self.starts.push(stamps.len()); + let filled = self.copies.iter().any(|&copies| copies >= COPIES_PER_BATCH); + let mut runs = if filled { self.full_batches(stamps, trees)? } else { Vec::new() }; + let mut range = |tree: usize, first: usize, end: usize| { + let start = *self.starts.get(tree * RANGES_PER_TREE + first)?; + let stop = *self.starts.get(tree * RANGES_PER_TREE + end)?; + let slice = stamps.get(start..stop)?; + if !slice.is_empty() { + runs.push(DrawRun::whole(slice)); + } + Some(()) + }; + if !filled { + for spans in GROUPS { + for tree in 0..trees { + for &(first, end) in spans { + // Insert the first-level marker at the start of each twenty-range child. + let child_marker = 1 + first / 20; + range(tree, child_marker + first, child_marker + end)?; + } + } + } + } + // The first-level shape has its own submissions, in reverse child order across trees. + for child in (0..4).rev() { + for tree in 0..trees { + range(tree, child * RANGES_PER_CHILD, child * RANGES_PER_CHILD + 1)?; + } + } + Some(runs) + } +} diff --git a/crates/nodes/src/pattern/underfilled_quadrants/carried.rs b/crates/nodes/src/pattern/underfilled_quadrants/carried.rs new file mode 100644 index 00000000..7f34081a --- /dev/null +++ b/crates/nodes/src/pattern/underfilled_quadrants/carried.rs @@ -0,0 +1,126 @@ +use super::remaining::{Piece, Submission}; +use super::{COLLECTING_GROUPS, COPIES_PER_BATCH, DrawPosition, LAST_QUADRANT_PAIR, LEADING_SUBTREES, RANGES_PER_CHILD, REPEATED_GROUPS, UnderfilledQuadrants}; + +impl UnderfilledQuadrants { + pub(super) fn collecting_tail(&self, slot: usize) -> Option<[Piece<'_>; 3]> { + let first = &self.collecting[0]; + let first_start = self.span_start(0, COLLECTING_GROUPS[0], 2)?; + let branches = &first.pair.fourth_child_grandchildren; + let group = &self.collecting[slot]; + let id = COLLECTING_GROUPS[slot]; + let start = self.span_start(0, id, 2)?; + let tail = &group.spans[2]; + let pair = &group.pair; + let fourth = &pair.fourth_child_branches; + let handoff = self.collecting_handoff(slot); + let mut skipped = handoff.end.checked_sub(handoff.start)?; + let mut last = handoff.end; + if slot == 0 { + skipped = skipped.checked_add(fourth[3].checked_sub(fourth[0])?)?; + last = fourth[3]; + } + let size = u32::try_from(group.initial_copies()).ok()?.checked_add(tail.total.checked_sub(skipped)?)?; + let remaining = size.checked_sub(2 * COPIES_PER_BATCH)?; + if remaining > tail.total.checked_sub(last)? { + return None; + } + + let extra = match slot { + 0 => { + let other = &self.collecting[2]; + (self.span_start(0, COLLECTING_GROUPS[2], 2)?, &other.spans[2], self.collecting_handoff(2)) + } + 2 => { + let children = &first.pair.third_child_branches; + (first_start, &first.spans[2], children[0]..children[2]) + } + _ => (first_start, &first.spans[2], 0..0), + }; + Some([(start, tail, tail.total - remaining..tail.total), extra, (first_start, &first.spans[2], branches[slot]..branches[slot + 1])]) + } + + pub(super) fn middle_tail(&self) -> Option<[Piece<'_>; 4]> { + let first_start = self.span_start(0, LAST_QUADRANT_PAIR, 0)?; + let first_group = &self.collecting[0]; + let second_group = &self.collecting[1]; + let first_branch = self.span_start(0, COLLECTING_GROUPS[0], 2)?; + let second_branch = self.span_start(0, COLLECTING_GROUPS[1], 2)?; + let children = &first_group.pair.third_child_branches; + let last = &second_group.pair; + let first = &self.last_quadrant_pair[0]; + Some([ + (first_start, first, 0..first.total), + (first_branch, &first_group.spans[2], first_group.pair.third_child..children[0]), + (first_branch, &first_group.spans[2], children[2]..first_group.pair.fourth_child), + (second_branch, &second_group.spans[2], last.third_child..last.fourth_child), + ]) + } + + pub(super) fn last_child_tail(&self) -> Option<[Piece<'_>; 4]> { + let first = &self.collecting[0]; + let first_start = self.span_start(0, COLLECTING_GROUPS[0], 2)?; + let branch = &first.pair; + let grandchildren = &branch.fourth_child_grandchildren; + let last = &self.collecting[3]; + let carried = u32::try_from(last.initial_copies()).ok()?.checked_add(last.spans[2].total)?.checked_sub(COPIES_PER_BATCH)?; + let group = COLLECTING_GROUPS[3]; + Some([ + (self.span_start(0, group, 2)?, &last.spans[2], last.spans[2].total.checked_sub(carried)?..last.spans[2].total), + (first_start, &first.spans[2], branch.fourth_child_branches[0]..grandchildren[0]), + (first_start, &first.spans[2], grandchildren[3]..grandchildren[4]), + (first_start, &first.spans[2], grandchildren[7]..branch.fourth_child_branches[2]), + ]) + } + + pub(super) fn leading_pair_tail(&self, slot: usize) -> Option<(u32, [Submission; 3])> { + let group = REPEATED_GROUPS[slot]; + let first_group = &self.collecting[0]; + let deferred = &first_group.pair.fourth_child_grandchildren[4..]; + let branch_start = self.span_start(0, COLLECTING_GROUPS[0], 2)?; + let subtree = LEADING_SUBTREES[slot]; + let pair = self.pairs.get(subtree / 8)?; + let repeated = &self.repeated[slot]; + let (middle_start, middle, range, branch) = if slot == 2 { + let fourth = &first_group.pair.fourth_child_branches; + (branch_start, &first_group.spans[2], fourth[2]..fourth[3], deferred[2]..deferred[3]) + } else { + (self.span_start(0, group, 1)?, &repeated.middle, 0..repeated.middle.total, deferred[1 - slot]..deferred[2 - slot]) + }; + let tail = pair.copies.checked_sub(2 * COPIES_PER_BATCH)?; + let carried = tail.checked_add(range.end.checked_sub(range.start)?)?.checked_add(branch.end.checked_sub(branch.start)?)?; + let end = *self.starts.get((subtree / 16 + 1) * RANGES_PER_CHILD)?; + Some(( + carried, + [ + (pair.cut?, DrawPosition { stamp: end, copy: 0 }), + Self::copy_range(middle_start, middle, range)?, + Self::copy_range(branch_start, &first_group.spans[2], branch)?, + ], + )) + } + + pub(super) fn append_single_tree_tail(&self, leading: &mut Vec) -> Option<()> { + // Without a following tree these unfinished batches drain in producer order. + // A full transfer can submit earlier and change the order of the other producers. + let mut pending = Vec::new(); + let (Some(first), Some(second), Some(third)) = (self.collecting_tail(0), self.collecting_tail(1), self.collecting_tail(2)) else { return Some(()) }; + let middle = self.middle_tail()?; + let last_child = self.last_child_tail()?; + for pieces in [&first[..], &second, &third, &middle, &last_child] { + let count = Self::piece_count(pieces)?; + if count >= COPIES_PER_BATCH { + return Some(()); + } + Self::append_copy_window(pieces, 0, count, &mut pending)?; + } + for slot in [1, 0, 2] { + let (count, ranges) = self.leading_pair_tail(slot)?; + if count >= COPIES_PER_BATCH { + return Some(()); + } + pending.extend(ranges); + } + leading.extend(pending); + Some(()) + } +} diff --git a/crates/nodes/src/pattern/underfilled_quadrants/remaining.rs b/crates/nodes/src/pattern/underfilled_quadrants/remaining.rs new file mode 100644 index 00000000..fbc94cb2 --- /dev/null +++ b/crates/nodes/src/pattern/underfilled_quadrants/remaining.rs @@ -0,0 +1,303 @@ +use super::{COLLECTING_GROUPS, COPIES_PER_BATCH, CopyPositions, DrawPosition, Range, UnderfilledQuadrants}; + +mod next_tree; +mod transfers; + +pub(super) type Submission = (DrawPosition, DrawPosition); +pub(super) type Piece<'a> = (usize, &'a CopyPositions, Range); + +#[derive(Default)] +pub(super) struct SiblingOffsets { + // Copy offsets at depths three, four and five, in quadrant traversal order. + starts: [Vec; 3], +} + +struct SiblingCut { + bounds: [u32; 3], + next_child: Option, +} + +impl SiblingOffsets { + pub(super) fn visit(&mut self, depth: u32, copies: u32) { + if let Some(starts) = depth.checked_sub(3).and_then(|level| self.starts.get_mut(level as usize)) { + starts.push(copies); + } + } + + fn unvisited_subtrees(&self, used: u32) -> usize { + let subtrees = &self.starts[2]; + subtrees.len() - subtrees.partition_point(|&start| start < used) + } + + fn children(&self, level: usize, first: usize, count: usize, sole_parent: bool, total: u32) -> Option { + let starts = self.starts.get(level)?; + let end = first + count; + // The pending sibling can belong to the next pair. Its intersection with this span is empty. + let offset = |index: usize| starts.get(index).copied().unwrap_or(total); + Some(SiblingCut { bounds: [offset(first), offset(first + 1), offset(end)], next_child: sole_parent.then(|| offset(end + 1)) }) + } + + fn split(&self, used: u32, total: u32) -> Option { + // A cut on the depth-two draw has no pending depth-three siblings yet. + let mut branch = self.starts[0].partition_point(|&start| start < used).checked_sub(1)?; + for (level, starts) in self.starts.iter().enumerate().skip(1) { + let first = branch * 4; + let children = starts.get(first..first + 4)?; + let visited = children.partition_point(|&start| start < used); + if visited == 0 { + return self.children(level, first, 2, true, total); + } + branch = first + visited - 1; + } + for level in (0..self.starts.len()).rev() { + let pending = 3 - branch % 4; + if pending >= 2 { + return self.children(level, branch + 1, pending.div_ceil(2), false, total); + } + if pending == 1 && level + 1 < self.starts.len() { + // Keep the sole remaining parent's draw and defer its first two children. + return self.children(level + 1, (branch + 1) * 4, 2, true, total); + } + // A depth-five subtree finishes as a unit. Continue up its pending sibling stack. + branch /= 4; + } + None + } +} + +pub(super) struct RemainingCopies<'a> { + start: usize, + span: &'a CopyPositions, + before: Range, + deferred: [Range; 2], + after: Range, + next_child: Option, +} + +impl<'a> RemainingCopies<'a> { + pub(super) fn new(start: usize, span: &'a CopyPositions, branches: &SiblingOffsets, used: u32) -> Option { + let cut = branches.split(used, span.total)?; + let [first, middle, end] = cut.bounds; + if !(used..=span.total).contains(&first) || end > span.total { + return None; + } + Some(Self { start, span, before: used..first, deferred: [first..middle, middle..end], after: end..span.total, next_child: cut.next_child }) + } + + fn piece(&self, range: Range) -> Piece<'a> { + (self.start, self.span, range) + } + + fn kept(&self) -> [Piece<'a>; 2] { + [self.piece(self.before.clone()), self.piece(self.after.clone())] + } + + fn deferred(&self) -> [Piece<'a>; 2] { + self.deferred.clone().map(|range| self.piece(range)) + } + + pub(super) fn submit_second(&mut self, leading: &mut Vec) -> Option { + let before = self.before.end.checked_sub(self.before.start)?; + let after = self.after.end.checked_sub(self.after.start)?; + if before.checked_add(after)? / COPIES_PER_BATCH != 1 { + // A third full batch or a partially filled second submission can interleave with the next group. + return Some(false); + } + UnderfilledQuadrants::append_copy_window(&self.kept(), 0, COPIES_PER_BATCH, leading)?; + let from_before = before.min(COPIES_PER_BATCH); + self.before.start += from_before; + self.after.start += COPIES_PER_BATCH - from_before; + Some(true) + } +} + +impl UnderfilledQuadrants { + fn following_pair(&self, slot: usize, used: u32, leading: &mut Vec) -> Option> { + let group = *super::REPEATED_GROUPS.get(slot)?; + let pair = self.repeated.get(slot)?; + let start = self.span_start(1, group, 0)?; + let tail = pair.next.total.checked_sub(used)?; + let needed = COPIES_PER_BATCH.checked_sub(tail)?; + let later = &pair.later; + let later_start = self.span_start(1, group, 1)?; + let remainder = RemainingCopies::new(later_start, later, &pair.branches, needed)?; + let pieces = [(start, &pair.next, used..pair.next.total), (later_start, later, 0..later.total)]; + Self::append_copy_window(&pieces, 0, COPIES_PER_BATCH, leading)?; + Some(remainder) + } + + fn following_last_child(&self, leading: &mut Vec) -> Option> { + let [tail, own, middle, last] = self.last_child_tail()?; + let [own_next, children, pair] = &self.next_collecting[3].spans; + let group = COLLECTING_GROUPS[3]; + let pair_start = self.span_start(1, group, 2)?; + let pieces = [ + tail, + own, + middle, + last, + (self.span_start(1, group, 0)?, own_next, 0..own_next.total), + (self.span_start(1, group, 1)?, children, 0..children.total), + (pair_start, pair, 0..pair.total), + ]; + let before = Self::piece_count(&pieces[..6])?; + let used = COPIES_PER_BATCH.checked_sub(before)?; + let remainder = RemainingCopies::new(pair_start, pair, &self.next_collecting[3].branches, used)?; + Self::append_copy_window(&pieces, 0, COPIES_PER_BATCH, leading)?; + Some(remainder) + } + + pub(super) fn piece_count(pieces: &[Piece<'_>]) -> Option { + pieces.iter().try_fold(0u32, |sum, (_, _, range)| sum.checked_add(range.end.checked_sub(range.start)?)) + } + + fn append_receiver_and_last(first: &[Piece<'_>; 5], full_receiver: bool, mut last: Vec, next: &mut Vec) -> Option<()> { + if full_receiver { + // A receiver that needs the last group's handoff submits after that group's own batch. + if Self::piece_count(&first[..4])? < COPIES_PER_BATCH { + next.append(&mut last); + } + Self::append_copy_window(first, 0, COPIES_PER_BATCH, next)?; + } + next.extend(last); + Some(()) + } + + pub(super) fn append_remaining_pairs( + &self, + collecting: &[RemainingCopies<'_>], + pair_offsets: [u32; 3], + middle_used: u32, + leading: &mut Vec, + ) -> Option<()> { + let [first_group, second_group, third_group] = collecting else { return Some(()) }; + let mut next = Vec::new(); + let Some(lower) = self.following_pair(0, pair_offsets[0], &mut next) else { return Some(()) }; + let mut last_batch = Vec::new(); + let Some(last) = self.following_last_child(&mut last_batch) else { return Some(()) }; + let mut upper_batch = Vec::new(); + let Some(upper) = self.following_pair(1, pair_offsets[1], &mut upper_batch) else { return Some(()) }; + let [second_left, second_right] = second_group.deferred(); + let [third_left, third_right] = third_group.deferred(); + let [first_left, first_right] = first_group.deferred(); + let [last_left, last_right] = last.deferred(); + let [lower_left, lower_right] = lower.deferred(); + let [upper_left, upper_right] = upper.deferred(); + let [first_head, first_tail] = first_group.kept(); + let [second_head, second_tail] = second_group.kept(); + let [third_head, third_tail] = third_group.kept(); + + let first = [first_head, first_tail, second_left, second_right, last_left]; + let second = [second_head, second_tail, third_left, third_right]; + let third = [third_head, third_tail, lower_left, upper_left, upper_right]; + let received = Self::piece_count(&first)?; + if received >= 2 * COPIES_PER_BATCH || Self::piece_count(&second)? >= COPIES_PER_BATCH || Self::piece_count(&third)? >= COPIES_PER_BATCH { + return Some(()); + } + + let more_trees = self.visits[0] > 2; + let full_receiver = received >= COPIES_PER_BATCH; + if lower.deferred.iter().chain(&upper.deferred).all(Range::is_empty) { + // With no pending sibling in either pair, both paired batches precede the last child. + next.extend(upper_batch); + Self::append_receiver_and_last(&first, full_receiver, last_batch, &mut next)?; + if more_trees + && full_receiver + && let Some(batches) = self.carry_without_siblings(collecting, [&lower, &upper, &last]) + { + next.extend(batches); + } + } else if full_receiver && Self::piece_count(&first[..2])? < COPIES_PER_BATCH && Self::piece_count(&first[..3])? >= COPIES_PER_BATCH { + // The first child handed over by the second group completes the receiver. + // How many siblings the lower pair gives up determines when that batch submits. + match self.repeated[0].branches.unvisited_subtrees(lower.before.start) { + 2 if !lower.deferred[0].is_empty() && lower.deferred[1].is_empty() => { + next.extend(upper_batch); + // When both pairs transfer one of their final two subtrees, + // the last child finishes before the receiver. + let single_upper = self.repeated[1].branches.unvisited_subtrees(upper.before.start) == 2; + if single_upper { + next.append(&mut last_batch); + } + Self::append_receiver_and_last(&first, true, last_batch, &mut next)?; + if more_trees + && single_upper + && let Some(batches) = self.carry_single_transfers(collecting, [&lower, &upper, &last], pair_offsets[2]) + { + next.extend(batches); + } + } + 3 | 4 if lower.deferred.iter().all(|sibling| !sibling.is_empty()) => { + Self::append_copy_window(&first, 0, COPIES_PER_BATCH, &mut next)?; + next.extend(upper_batch); + next.extend(last_batch); + if let Some(tail) = self.unfinished_receivers(collecting, [&lower, &upper, &last], pair_offsets[2], middle_used) { + next.extend(tail); + } + } + _ => {} + } + } else if !more_trees && !full_receiver { + next.extend(last_batch); + next.extend(upper_batch); + } + if more_trees || full_receiver { + // Another tree or an additional full receiver can interleave the unfinished groups. + leading.extend(next); + return Some(()); + } + let pair = &self.last_quadrant_pair[1]; + let gap = &self.next_pair_gap; + let start = self.span_start(1, super::LAST_QUADRANT_PAIR, 0)?; + if middle_used > gap.start { + return Some(()); + } + let [last_head, last_tail] = last.kept(); + let [low_head, low_tail] = lower.kept(); + let middle = [(start, pair, middle_used..gap.start), (start, pair, gap.end..pair.total), first_left, first_right]; + let split = upper.next_child.unwrap_or(upper.after.start); + if !(upper.after.start..=upper.after.end).contains(&split) { + return Some(()); + } + let upper_ranges = [upper.piece(upper.after.start..split), upper.piece(upper.before.clone()), upper.piece(split..upper.after.end)]; + let third_pair = &self.repeated[2].next; + let final_ranges = [ + low_head, + low_tail, + last_right, + (self.span_start(1, super::REPEATED_GROUPS[2], 0)?, third_pair, pair_offsets[2]..third_pair.total), + (start, pair, gap.clone()), + lower_right, + ]; + for pieces in [&first[..], &second[..], &third[..], &middle[..], &[last_head, last_tail], &upper_ranges[..], &final_ranges[..]] { + let count = Self::piece_count(pieces)?; + Self::append_copy_window(pieces, 0, count, &mut next)?; + } + leading.extend(next); + Some(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn the_last_handoff_can_complete_a_receiving_batch() { + let mut span = CopyPositions::default(); + for _ in 0..=COPIES_PER_BATCH { + span.record(1, true).unwrap(); + } + let position = |stamp| DrawPosition { stamp, copy: 0 }; + let last = (position(20_000), position(20_001)); + // The last group hands off 85 copies. Its own batch precedes a receiver that still needs them. + for incoming in [COPIES_PER_BATCH - 1, COPIES_PER_BATCH, COPIES_PER_BATCH + 1] { + let empty = (0, &span, 0..0); + let first = [(0, &span, 0..incoming), empty.clone(), empty.clone(), empty, (10_000, &span, 0..85)]; + let mut runs = Vec::new(); + UnderfilledQuadrants::append_receiver_and_last(&first, true, vec![last], &mut runs).unwrap(); + assert_eq!(runs.first() == Some(&last), incoming < COPIES_PER_BATCH); + assert_eq!(runs.last() == Some(&last), incoming >= COPIES_PER_BATCH); + } + } +} diff --git a/crates/nodes/src/pattern/underfilled_quadrants/remaining/next_tree.rs b/crates/nodes/src/pattern/underfilled_quadrants/remaining/next_tree.rs new file mode 100644 index 00000000..dc4500c2 --- /dev/null +++ b/crates/nodes/src/pattern/underfilled_quadrants/remaining/next_tree.rs @@ -0,0 +1,174 @@ +use super::{COPIES_PER_BATCH, CopyPositions, Piece, Range, RemainingCopies, SiblingOffsets, Submission, UnderfilledQuadrants}; +use crate::pattern::underfilled_quadrants::{COLLECTING_GROUPS, LAST_QUADRANT_PAIR, REPEATED_GROUPS}; + +struct IncomingChildren<'a> { + start: usize, + span: &'a CopyPositions, + pending: &'a [u32], + parents: &'a [u32; 4], + children: &'a [u32; 16], +} + +impl<'a> IncomingChildren<'a> { + fn piece(&self, range: Range) -> Piece<'a> { + (self.start, self.span, range) + } +} + +impl SiblingOffsets { + fn starts_in(starts: &[u32], range: Range) -> &[u32] { + let remaining = &starts[starts.partition_point(|&n| n < range.start)..]; + &remaining[..remaining.partition_point(|&n| n < range.end)] + } + + fn incoming_children<'a>(&'a self, first: &RemainingCopies<'_>, second: &RemainingCopies<'a>) -> Option> { + let [(start, span, left), (_, _, right)] = second.deferred(); + // The receiving group filled in the first of two adjacent depth-three children. + let siblings = &self.starts[0]; + let index = siblings.binary_search(&left.start).ok()?; + if left.end != right.start || siblings.get(index + 1) != Some(&right.start) || siblings.get(index + 2).copied().unwrap_or(span.total) != right.end { + return None; + } + let cut = left.start.checked_add(COPIES_PER_BATCH.checked_sub(UnderfilledQuadrants::piece_count(&first.kept())?)?)?; + if cut > left.end { + return None; + } + Some(IncomingChildren { + start, + span, + pending: Self::starts_in(&self.starts[2], cut..left.end), + parents: Self::starts_in(&self.starts[1], right.clone()).try_into().ok()?, + children: Self::starts_in(&self.starts[2], right).try_into().ok()?, + }) + } +} + +impl UnderfilledQuadrants { + fn append_third_tree_pair(&self, slot: usize, carried: &[Piece<'_>], submissions: &mut Vec) -> Option<()> { + let span = &self.repeated.get(slot)?.third_tree; + let count = Self::piece_count(carried)?; + if count >= COPIES_PER_BATCH || count.checked_add(span.total)? / COPIES_PER_BATCH != 2 { + // Another full submission changes when the other pair can receive work. + return None; + } + let mut pieces = carried.to_vec(); + pieces.push((self.span_start(2, REPEATED_GROUPS[slot], 0)?, span, 0..span.total)); + Self::append_copy_window(&pieces, 0, 2 * COPIES_PER_BATCH, submissions) + } + + pub(super) fn carry_into_third_tree(&self, lower: &[Piece<'_>], upper: &[Piece<'_>]) -> Option> { + let mut submissions = Vec::new(); + self.append_third_tree_pair(0, lower, &mut submissions)?; + self.append_third_tree_pair(1, upper, &mut submissions)?; + Some(submissions) + } + + pub(super) fn carry_without_siblings( + &self, + collecting: &[RemainingCopies<'_>], + [lower, upper, last]: [&RemainingCopies<'_>; 3], + ) -> Option> { + let [first, second, _] = collecting else { return None }; + if self.repeated[0].branches.unvisited_subtrees(lower.before.start) != 1 + || self.repeated[1].branches.unvisited_subtrees(upper.before.start) != 1 + || self.next_collecting[3].branches.unvisited_subtrees(last.before.start) != 2 + || last.deferred[0].is_empty() + || !last.deferred[1].is_empty() + { + return None; + } + let incoming = self.next_collecting[1].branches.incoming_children(first, second)?; + if incoming.pending.len() != 3 { + return None; + } + let parents = incoming.parents; + let children = incoming.children; + let [lower_head, lower_tail] = lower.kept(); + let [upper_head, upper_tail] = upper.kept(); + // The lower pair visits the second parent and its final child before it receives + // the first two children of the first parent. The upper pair keeps that parent's draw. + let lower_pieces = [ + lower_head, + lower_tail, + incoming.piece(parents[1]..children[4]), + incoming.piece(children[7]..parents[2]), + incoming.piece(children[0]..children[2]), + ]; + let upper_pieces = [upper_head, upper_tail, incoming.piece(parents[0]..children[0]), incoming.piece(children[2]..parents[1])]; + self.carry_into_third_tree(&lower_pieces, &upper_pieces) + } + + pub(super) fn carry_single_transfers( + &self, + collecting: &[RemainingCopies<'_>], + [lower, upper, last]: [&RemainingCopies<'_>; 3], + final_used: u32, + ) -> Option> { + let [first, second, third] = collecting else { return None }; + if self.next_collecting[3].branches.unvisited_subtrees(last.before.start) != 2 + || [upper, last].iter().any(|pair| pair.deferred[0].is_empty() || !pair.deferred[1].is_empty()) + { + return None; + } + let incoming = self.next_collecting[1].branches.incoming_children(first, second)?; + let [lower_head, lower_tail] = lower.kept(); + let [upper_head, upper_tail] = upper.kept(); + let lower_pieces = [lower_head, lower_tail, upper.piece(upper.deferred[0].clone())]; + let mut upper_pieces = vec![upper_head, upper_tail, last.piece(last.deferred[0].clone())]; + match incoming.pending.len() { + 3 => { + // The upper pair also receives the third child of the second depth-four quadrant. + upper_pieces.push(incoming.piece(incoming.children[6]..incoming.children[7])); + } + 4 => {} + _ => return None, + } + let mut submissions = self.carry_into_third_tree(&lower_pieces, &upper_pieces)?; + if let Some(batches) = self.collecting_and_final_pair(third, lower, &incoming, final_used) { + submissions.extend(batches); + } + Some(submissions) + } + + fn collecting_and_final_pair( + &self, + third: &RemainingCopies<'_>, + lower: &RemainingCopies<'_>, + incoming: &IncomingChildren<'_>, + final_used: u32, + ) -> Option> { + let children = incoming.children; + let [first_pending, next_pending, ..] = incoming.pending else { return None }; + let mut pieces = third.kept().to_vec(); + pieces.push(lower.piece(lower.deferred[0].clone())); + pieces.push(incoming.piece(*first_pending..*next_pending)); + let parents = incoming.parents; + let final_child = if incoming.pending.len() == 3 { + pieces.push(incoming.piece(children[2]..children[3])); + parents[2]..parents[3] + } else { + // The depth-three parent's draw stays with the receiver. + parents[0]..parents[2] + }; + let group = COLLECTING_GROUPS[2]; + let [own, child] = &self.third_collecting; + pieces.push((self.span_start(2, group, 0)?, own, 0..own.total)); + let needed = COPIES_PER_BATCH.checked_sub(Self::piece_count(&pieces)?)?; + if needed == 0 || needed >= child.total { + // This order was measured with the batch ending inside its first incoming child. + return None; + } + pieces.push((self.span_start(2, group, 1)?, child, 0..child.total)); + let mut submissions = Vec::new(); + Self::append_copy_window(&pieces, 0, COPIES_PER_BATCH, &mut submissions)?; + let previous = &self.repeated[2].next; + let middle = &self.last_quadrant_pair[1]; + let final_pieces = [ + (self.span_start(1, REPEATED_GROUPS[2], 0)?, previous, final_used..previous.total), + (self.span_start(1, LAST_QUADRANT_PAIR, 0)?, middle, self.next_pair_gap.clone()), + incoming.piece(final_child), + ]; + self.append_third_tree_pair(2, &final_pieces, &mut submissions)?; + Some(submissions) + } +} diff --git a/crates/nodes/src/pattern/underfilled_quadrants/remaining/transfers.rs b/crates/nodes/src/pattern/underfilled_quadrants/remaining/transfers.rs new file mode 100644 index 00000000..1a27efb4 --- /dev/null +++ b/crates/nodes/src/pattern/underfilled_quadrants/remaining/transfers.rs @@ -0,0 +1,141 @@ +use super::{COPIES_PER_BATCH, Piece, Range, RemainingCopies, SiblingOffsets, Submission, UnderfilledQuadrants}; +use crate::pattern::underfilled_quadrants::{LAST_QUADRANT_PAIR, REPEATED_GROUPS}; + +#[derive(Clone, Copy, PartialEq, Eq)] +enum Group { + First, + Second, + Third, + Middle, + Last, + Upper, + Lower, + Final, +} + +impl SiblingOffsets { + fn pending_children(&self, used: u32, total: u32) -> Vec> { + let children = &self.starts[2]; + children[children.partition_point(|&start| start < used)..] + .iter() + .map(|&start| { + // A shallower draw can separate adjacent depth-five subtrees. It stays with the parent. + let end = self.starts.iter().filter_map(|level| level.get(level.partition_point(|&offset| offset <= start))).copied().min().unwrap_or(total); + start..end + }) + .collect() + } +} + +impl<'a> RemainingCopies<'a> { + fn distribute_children(&self, children: &[Range], owner: Group, destinations: &[Group], groups: &mut [Vec>; 8]) { + let mut kept = self.before.start; + for (child, &destination) in children.iter().zip(destinations) { + if destination != owner { + groups[owner as usize].push(self.piece(kept..child.start)); + groups[destination as usize].push(self.piece(child.clone())); + kept = child.end; + } + } + groups[owner as usize].push(self.piece(kept..self.span.total)); + } +} + +impl UnderfilledQuadrants { + pub(super) fn unfinished_receivers( + &self, + collecting: &[RemainingCopies<'_>], + pairs: [&RemainingCopies<'_>; 3], + third_used: u32, + middle_used: u32, + ) -> Option> { + use Group::{Final, First, Last, Lower, Middle, Second, Third, Upper}; + let [first, second, third] = collecting else { return None }; + let [lower, upper, last] = pairs; + let children = |offsets: &SiblingOffsets, pair: &RemainingCopies<'_>| offsets.pending_children(pair.before.start, pair.span.total); + let low_children = children(&self.repeated[0].branches, lower); + let upper_children = children(&self.repeated[1].branches, upper); + let last_children = children(&self.next_collecting[3].branches, last); + + // The lower pair supplies the third group and the final group. The upper pair + // first supplies the three receivers, then the middle group if another child is ready. + let low_routes: &[_] = match low_children.len() { + 3 => &[Third, Final, Lower], + 4 => &[Third, Third, Final, Lower], + _ => return None, + }; + let upper_routes: &[_] = match upper_children.len() { + 5 if upper.deferred[0] == upper_children[1] && upper.deferred[1] == upper_children[2] => &[Upper, First, Second, Third, Upper], + 6 if upper.deferred[0] == upper_children[0] && upper.deferred[1].is_empty() => &[First, Upper, Second, Third, Middle, Upper], + _ => return None, + }; + if lower.deferred.as_slice() != &low_children[..2] || !(2..=5).contains(&last_children.len()) { + return None; + } + let mut last_routes = vec![Last; last_children.len()]; + let left = last_children.iter().position(|child| child == &last.deferred[0])?; + last_routes[left] = First; + let penultimate = last_routes.len() - 2; + if penultimate != left { + let middle_available = !upper_routes.contains(&Middle); + last_routes[penultimate] = if middle_available { Middle } else { Upper }; + if !last.deferred[1].is_empty() && last.deferred[1] != last_children[penultimate] { + let right = last_children.iter().position(|child| child == &last.deferred[1])?; + last_routes[right] = if middle_available { Middle } else { First }; + last_routes[penultimate] = Upper; + } + } + + // The first receiver filled partway through the second group's transferred child. + // Split the pending siblings at that copy and keep the rest of this child in the receiver. + let [(start, span, left), second_right] = second.deferred(); + let used = left.start.checked_add(COPIES_PER_BATCH.checked_sub(Self::piece_count(&first.kept())?)?)?; + if !left.contains(&used) { + return None; + } + let mut incoming = RemainingCopies::new(start, span, &self.next_collecting[1].branches, used)?; + if incoming.after.start > left.end { + return None; + } + incoming.after.end = left.end; + + let middle_pair = &self.last_quadrant_pair[1]; + let middle_start = self.span_start(1, LAST_QUADRANT_PAIR, 0)?; + let gap = &self.next_pair_gap; + if middle_used > gap.start { + return None; + } + let final_pair = &self.repeated[2].next; + let final_start = self.span_start(1, REPEATED_GROUPS[2], 0)?; + let mut groups: [Vec>; 8] = Default::default(); + groups[First as usize].extend(incoming.kept()); + groups[First as usize].push(second_right); + groups[Second as usize].extend(second.kept()); + groups[Second as usize].extend(third.deferred()); + groups[Third as usize].extend(third.kept()); + groups[Middle as usize].extend([(middle_start, middle_pair, middle_used..gap.start), (middle_start, middle_pair, gap.end..middle_pair.total)]); + groups[Middle as usize].extend(first.deferred()); + groups[Final as usize].extend([(final_start, final_pair, third_used..final_pair.total), (middle_start, middle_pair, gap.clone())]); + + lower.distribute_children(&low_children, Lower, low_routes, &mut groups); + upper.distribute_children(&upper_children, Upper, upper_routes, &mut groups); + last.distribute_children(&last_children, Last, &last_routes, &mut groups); + groups[Lower as usize].extend(incoming.deferred()); + let mut counts = [0; 8]; + for (group, count) in groups.iter().zip(&mut counts) { + *count = Self::piece_count(group)?; + if *count >= COPIES_PER_BATCH { + // A group that fills again can transfer more work before the remaining groups finish. + return None; + } + } + if self.visits[0] > 2 { + return self.carry_into_third_tree(&groups[Lower as usize], &groups[Upper as usize]); + } + let mut submissions = Vec::new(); + for (group, count) in groups.iter().zip(counts) { + Self::append_copy_window(group, 0, count, &mut submissions)?; + } + Some(submissions) + } +} diff --git a/crates/nodes/src/pattern/variables.rs b/crates/nodes/src/pattern/variables.rs new file mode 100644 index 00000000..0f667d3d --- /dev/null +++ b/crates/nodes/src/pattern/variables.rs @@ -0,0 +1,117 @@ +use crate::function::Program; +use materialcraft_core::{Value, ValueType}; +use std::collections::BTreeMap; + +pub(super) fn declarations(program: &Program, names: &mut BTreeMap) { + for op in &program.instructions { + if op.definition.id == "set" + && let Some(Value::Text(name)) = &op.value + && let Some(kind) = ValueType::from_code(op.type_code) + { + names.insert(name.clone(), kind); + } + if let Some(call) = &op.call + && call.exports + { + declarations(&call.program, names); + } + } +} + +#[derive(Default)] +struct LocalValues { + depth: Option, + saved: BTreeMap, +} + +pub(super) struct Declaration { + name: String, + outer: Option<(u32, Value)>, +} + +pub(super) struct PatternVariables<'a> { + published: &'a BTreeMap, + pub(super) drawing: BTreeMap, + pub(super) modes: BTreeMap, + pub(super) bound_draw: bool, + locals: BTreeMap, + scopes: Vec<(usize, Vec)>, +} + +impl<'a> PatternVariables<'a> { + pub(super) fn new(published: &'a BTreeMap) -> Self { + let mut drawing = published.clone(); + drawing.remove("$randomseed"); + let mut modes = drawing.clone(); + // Quadrant modes resolve before the traversal provides its position, depth and iteration. + for name in ["$depth", "$depthpow2", "$number"] { + modes.insert(name.into(), Value::Float(0.0)); + } + Self { modes, drawing, published, bound_draw: false, locals: BTreeMap::new(), scopes: Vec::new() } + } + + pub(super) fn seed_integers<'b>(&'b self, assigned: &'b [String]) -> impl Iterator { + let locals = self.locals.iter().filter_map(|(name, local)| local.depth.map(|_| name)); + assigned.iter().chain(locals).filter_map(|name| match self.drawing.get(name) { + Some(Value::Int(value)) => Some((name.as_str(), *value)), + _ => None, + }) + } + + pub(super) fn enter(&mut self, names: &BTreeMap, depth: u32, declared: &mut Vec) { + for (name, kind) in names { + let local = self.locals.entry(name.clone()).or_default(); + if local.depth == Some(depth) || (local.depth.is_none() && !self.modes.contains_key(name) && self.drawing.contains_key(name)) { + continue; + } + // A child may read its parent's value. Declaring the name opens the + // last value written at this quadrant depth, including across siblings. + self.modes.remove(name); + let value = local.saved.remove(&depth).unwrap_or_else(|| match (self.bound_draw, kind) { + // A draw driven by a graph input starts these components undefined until the first write. + (true, ValueType::Float) => Value::Float(f32::NAN), + (true, ValueType::Float2) => Value::Float2([f32::NAN; 2]), + (true, ValueType::Float3) => Value::Float3([f32::NAN; 3]), + _ => kind.default_value(), + }); + let previous = self.drawing.insert(name.clone(), value); + let outer = local.depth.replace(depth).zip(previous); + declared.push(Declaration { name: name.clone(), outer }); + } + } + + pub(super) fn keep_for_children(&mut self, pending: usize, declared: Vec) { + if !declared.is_empty() { + self.scopes.push((pending, declared)); + } + } + + pub(super) fn start_root_child(&mut self) { + // A six-level quadrant tree starts a separate evaluation task per root child. + // Active declarations on the root still supply values to read-only descendants. + for local in self.locals.values_mut() { + local.saved.clear(); + } + } + + pub(super) fn resume(&mut self, pending_after_pop: usize) { + // Once a waiting sibling is popped, the declaring node and all its descendants have finished. + while self.scopes.last().is_some_and(|(pending, _)| pending_after_pop < *pending) { + if let Some((_, declared)) = self.scopes.pop() { + for Declaration { name, outer } in declared { + let Some(local) = self.locals.get_mut(&name) else { continue }; + if let (Some(depth), Some(value)) = (local.depth.take(), self.drawing.remove(&name)) { + local.saved.insert(depth, value); + } + if let Some((depth, value)) = outer { + local.depth = Some(depth); + self.drawing.insert(name, value); + } else if let Some(value) = self.published.get(&name) { + self.drawing.insert(name.clone(), value.clone()); + self.modes.insert(name, value.clone()); + } + } + } + } + } +} diff --git a/crates/nodes/src/random.rs b/crates/nodes/src/random.rs index cb0520ce..970aea7b 100644 --- a/crates/nodes/src/random.rs +++ b/crates/nodes/src/random.rs @@ -1,24 +1,61 @@ -// Lowbias32 integer hash by Chris Wellons, public domain -#[inline] -pub fn hash(mut x: u32) -> u32 { - x ^= x >> 16; - x = x.wrapping_mul(0x7feb_352d); - x ^= x >> 15; - x = x.wrapping_mul(0x846c_a68b); - x ^= x >> 16; - x +#[derive(Clone, Copy, PartialEq, Eq)] +pub(crate) struct FunctionRandom { + state: u32, + multiplier: u32, + increment: u32, + uniform: bool, } -/// The 24-bit sequence used by scalar node-parameter functions. -pub(crate) fn node_function(state: &mut u32) -> f32 { - *state = state.wrapping_mul(16_294_893).wrapping_add(10_493_233) & 0x00ff_ffff; - *state as f32 / 16_777_216.0 +impl FunctionRandom { + pub(crate) fn uniform(state: u32) -> Self { + Self { state, multiplier: 16_294_893, increment: 10_493_233, uniform: true } + } + + pub(crate) fn image(state: u32) -> Self { + Self { state, multiplier: 3_626_811, increment: 51_137, uniform: false } + } + + /// Jenkins one-at-a-time mixing over the graph seed and the two normalized F32 coordinate words. + pub(crate) fn pixel(seed: u32, position: [f32; 2]) -> Self { + let mut hash = 0_u32; + for word in [seed, position[0].to_bits(), position[1].to_bits()] { + let mixed = hash.wrapping_add(word).wrapping_mul(1025); + hash = mixed ^ (mixed >> 6); + } + let mixed = hash.wrapping_mul(9); + Self::image((mixed ^ (mixed >> 11)).wrapping_mul(32769)) + } + + /// Each of these pattern properties starts its own sequence at the traversal seed. + pub(crate) fn pattern(state: u32, property: &str) -> Option { + let (multiplier, increment) = match property { + "opacity" => return Some(Self::image(state)), + "branchoffset" => (14_154_961, 50_989), + "frameoffset" => (1_823_937, 50_707), + "patternsize" => (5_812_301, 50_411), + "patternrotation" => (3_470_325, 50_131), + "patternsuppl" => (12_382_630, 50_647), + "numberadded" => (9_501_597, 50_591), + "switch" => (14_464_988, 50_111), + _ => return None, + }; + Some(Self { state, multiplier, increment, uniform: false }) + } + + pub(crate) fn draw(&mut self) -> f32 { + self.state = self.state.wrapping_mul(self.multiplier).wrapping_add(self.increment) & 0x00ff_ffff; + if self.uniform { self.state as f32 / 16_777_216.0 } else { (self.state >> 1) as f32 / 8_388_608.0 } + } } -/// The measured scalar sequence for functions evaluated inside a pattern graph. -pub(crate) fn pattern_function(state: &mut u32) -> f32 { - *state = state.wrapping_mul(3_626_811).wrapping_add(51_137) & 0x00ff_ffff; - (*state >> 1) as f32 / 8_388_608.0 +impl Default for FunctionRandom { + fn default() -> Self { + Self::image(0) + } +} + +pub(crate) fn iteration_child(state: u32) -> u32 { + state.wrapping_mul(8_532_665).wrapping_add(14_533) & 0x00ff_ffff } /// Quadrant child streams are independent of parameter-function draws. diff --git a/crates/nodes/src/raster/composite.rs b/crates/nodes/src/raster/composite.rs index 0e1f0ee1..4e829b5f 100644 --- a/crates/nodes/src/raster/composite.rs +++ b/crates/nodes/src/raster/composite.rs @@ -1,17 +1,37 @@ -use craft_texture::{Image, Kind, luminance}; +use craft_texture::{Image, Kind}; use crate::CookContext; -pub(crate) fn composite(context: &CookContext, foreground: impl Fn(u32, u32) -> [f32; 4] + Sync) -> Image { +fn mean_rgb([r, g, b, _]: [f32; 4]) -> f32 { + (r + g + b) / 3.0 +} + +fn background(context: &CookContext) -> Image { let kind = if context.b("color_mode") { Kind::Color } else { Kind::Gray }; - let background = match context.input(0) { + match context.input(0) { Some(image) if image.kind() == kind => image.resize(context.w, context.h, context.tile), // An incompatible connection replaces the constant background with empty pixels Some(_) => Image::filled(1, 1, kind, [0.0; 4]), - None => Image::filled(1, 1, Kind::Color, context.v4("background")), - }; - let gray_background = background.is_gray(); + None => { + let color = context.v4("background"); + Image::filled(1, 1, kind, if kind == Kind::Gray { [mean_rgb(color); 4] } else { color }) + } + } +} + +pub(crate) fn composite_text(context: &CookContext, coverage: impl Fn(u32, u32) -> f32 + Sync) -> Image { + let background = background(context); + Image::generate(context.w, context.h, background.kind(), |x, y| { + let ink = coverage(x, y).clamp(0.0, 1.0); + let pixel = background.get(i64::from(x), i64::from(y), false); + pixel.map(|channel| (1.0 - ink).mul_add(channel, ink)) + }) +} + +pub(crate) fn composite(context: &CookContext, foreground: impl Fn(u32, u32) -> [f32; 4] + Sync) -> Image { + let background = background(context); + let kind = background.kind(); // Clamped sampling broadcasts constant backgrounds from one pixel Image::generate(context.w, context.h, kind, |x, y| { @@ -20,7 +40,7 @@ pub(crate) fn composite(context: &CookContext, foreground: impl Fn(u32, u32) -> let foreground_alpha = foreground[3].clamp(0.0, 1.0); if foreground_alpha == 0.0 { // Empty content must preserve hidden RGB in a transparent background - return if kind == Kind::Gray && !gray_background { [luminance(background), 0.0, 0.0, 0.0] } else { background }; + return background; } let background_alpha = background[3].clamp(0.0, 1.0) * (1.0 - foreground_alpha); @@ -31,6 +51,6 @@ pub(crate) fn composite(context: &CookContext, foreground: impl Fn(u32, u32) -> let channel = |index: usize| (foreground[index] * foreground_alpha + background[index] * background_alpha) / alpha; let pixel = [channel(0), channel(1), channel(2), alpha]; - if kind == Kind::Gray { [luminance(pixel), 0.0, 0.0, 0.0] } else { pixel } + if kind == Kind::Gray { [mean_rgb(pixel), 0.0, 0.0, 0.0] } else { pixel } }) } diff --git a/crates/nodes/src/raster/mod.rs b/crates/nodes/src/raster/mod.rs index f33956be..e13b80e4 100644 --- a/crates/nodes/src/raster/mod.rs +++ b/crates/nodes/src/raster/mod.rs @@ -4,4 +4,4 @@ mod composite; pub(crate) use capsule_raster::CapsuleRaster; pub(crate) use capsule_segment::CapsuleSegment; -pub(crate) use composite::composite; +pub(crate) use composite::{composite, composite_text}; diff --git a/crates/nodes/src/tests.rs b/crates/nodes/src/tests.rs index 7cca9019..f7187258 100644 --- a/crates/nodes/src/tests.rs +++ b/crates/nodes/src/tests.rs @@ -10,6 +10,7 @@ fn cook(def: &NodeDefinition, inputs: &[Option], size: u32) -> CookResult let no_res = |_: &str| None; let vars = BTreeMap::new(); let ctx = CookContext { + input_formats: &[], format: materialcraft_core::OutputFormat::F32, w: size, h: size, @@ -24,6 +25,161 @@ fn cook(def: &NodeDefinition, inputs: &[Option], size: u32) -> CookResult (def.cook)(&ctx) } +#[test] +fn pixel_processor_stores_undefined_channels_at_output_precision() { + use materialcraft_core::{FunctionGraph, OutputFormat}; + + let definition = find("pixel_processor").unwrap(); + let mut graph = FunctionGraph::default(); + let pos = graph.add("get_float2", &[], Some(Value::Text("$pos".into()))); + let input = graph.add("samplecol", &[pos], Some(Value::Int2([0, 0]))); + let divisor = graph.add_constant(Value::Float4([0.0, 0.0, 0.0, 2.0])); + graph.output = Some(graph.add("div", &[input, divisor], None)); + let params = resolve_params(definition, &BTreeMap::from([("function".into(), Value::Function(Box::new(graph)))])); + let inputs = [Some(Image::filled(2, 2, Kind::Color, [0.0, 1.0, -1.0, 0.5]))]; + let vars = BTreeMap::new(); + for (format, expected) in [ + (OutputFormat::F32, [0x7fff_ffff, 0x7f80_0000, 0xff80_0000, 0x3e80_0000]), + (OutputFormat::F16, [half::f16::from_bits(0x7fff).to_f32().to_bits(), 0x7f80_0000, 0xff80_0000, 0x3e80_0000]), + (OutputFormat::U16, [0, 1.0_f32.to_bits(), 0, (16384.0_f32 / 65535.0).to_bits()]), + (OutputFormat::U8, [0, 1.0_f32.to_bits(), 0, (64.0_f32 / 255.0).to_bits()]), + ] { + let context = CookContext { + w: 2, + h: 2, + inputs: &inputs, + input_formats: &[OutputFormat::F32], + seed: 0, + tile: true, + params: ¶ms, + vars: &vars, + resource: &|_| None, + format, + }; + let image = (definition.cook)(&context).unwrap().remove(0); + let stored = output_precision::apply(image, format); + assert_eq!(stored.get(0, 0, false).map(f32::to_bits), expected, "{format:?}"); + } +} + +#[test] +fn bilinear_transform_selects_and_stores_the_requested_mip_level() { + let definition = find("transformation").unwrap(); + let inputs = [Some(Image::gray(16, 16, |x, y| if x % 4 == 0 && y % 4 == 0 { 1.0 } else { 0.0 }).with_integer_sampling(true))]; + let variables = BTreeMap::new(); + let filtered = 4096.0 / 65535.0; + + for (size, mode, level, first, second) in [(4, 0, 0, filtered, filtered), (4, 1, 0, 0.0, 0.0), (16, 0, 0, 1.0, 0.0), (16, 1, 2, filtered, filtered)] { + let params = resolve_params(definition, &BTreeMap::from([("mip_mode".into(), Value::Enum(mode)), ("mip_level".into(), Value::Int(level))])); + let context = CookContext { + input_formats: &[], + format: materialcraft_core::OutputFormat::U16, + w: size, + h: size, + seed: 0, + tile: true, + inputs: &inputs, + params: ¶ms, + resource: &|_| None, + vars: &variables, + }; + let result = (definition.cook)(&context).unwrap(); + assert_eq!([result[0].get_gray(0, 0, false), result[0].get_gray(1, 0, false)], [first, second], "size {size}, mode {mode}, level {level}"); + } +} + +#[test] +fn grayscale_bitmap_halving_stores_each_level_before_the_next_filter() { + use materialcraft_core::OutputFormat; + + let definition = find("bitmap").unwrap(); + let params = resolve_params(definition, &BTreeMap::from([("color_mode".into(), Value::Bool(false)), ("resource".into(), Value::Text("field".into()))])); + let source = Image::gray(2, 4, |x, y| { + let level = 1000 * x + u32::from(y == 3); + level as f32 / 65535.0 + }) + .with_integer_sampling(true); + let vars = BTreeMap::new(); + let context = CookContext { + input_formats: &[], + format: OutputFormat::U16, + w: 2, + h: 1, + seed: 0, + tile: false, + inputs: &[], + params: ¶ms, + resource: &|_| Some(source.clone()), + vars: &vars, + }; + let result = (definition.cook)(&context).unwrap(); + let stored = crate::output_precision::apply(result[0].clone(), context.format); + assert_eq!(stored.gray_data().unwrap(), [1.0 / 65535.0, 1001.0 / 65535.0]); +} + +#[test] +fn linear_color_bitmap_filters_each_channel_at_stored_precision() { + use materialcraft_core::OutputFormat; + + let definition = find("bitmap").unwrap(); + let params = resolve_params(definition, &BTreeMap::from([("colour_space".into(), Value::Enum(1)), ("resource".into(), Value::Text("field".into()))])); + let level = |x, y| ((31 * x + 13 * y + 97 * x * y + 19) % 256) as f32 / 255.0; + let source = Image::generate(64, 32, Kind::Color, |x, y| [level(x, y), level(x, (y + 27) % 32), level((x + 55) % 64, y), level((x + 47) % 64, y)]) + .with_integer_sampling(true); + let context = CookContext { + input_formats: &[], + format: OutputFormat::U16, + w: 64, + h: 16, + seed: 497109, + tile: true, + inputs: &[], + params: ¶ms, + resource: &|_| Some(source.clone()), + vars: &BTreeMap::new(), + }; + let result = (definition.cook)(&context).unwrap(); + let stored = crate::output_precision::apply(result[0].clone(), context.format); + let levels = [(0, 0), (7, 3), (63, 15)].map(|(x, y)| stored.get(x, y, false).map(|v| (v * 65535.0).round() as u16)); + assert_eq!(levels, [[6554, 30969, 44718, 45746], [32382, 31354, 40221, 28913], [21074, 46774, 47417, 19661]]); +} + +#[test] +fn bitmap_converts_normalized_rgb_to_gray_on_the_first_filter_pass() { + use materialcraft_core::OutputFormat; + + let definition = find("bitmap").unwrap(); + let params = resolve_params( + definition, + &BTreeMap::from([("colour_space".into(), Value::Enum(1)), ("color_mode".into(), Value::Bool(false)), ("resource".into(), Value::Text("field".into()))]), + ); + let source = Image::generate(32, 64, Kind::Color, |x, y| { + [(583, 191, 371, 3229), (47, 313, 59, 4511), (31, 693, 41, 8943), (997, 811, 97, 9043)] + .map(|(a, b, c, d)| ((a * x + b * y + c * x * y + d) % 65536) as f32 / 65535.0) + }) + .with_integer_sampling(true); + for (format, size, positions, expected) in [ + (OutputFormat::U16, [16, 16], [(0, 0), (3, 7), (15, 15)], [6388, 27024, 28209].map(|v| v as f32 / 65535.0)), + (OutputFormat::F32, [32, 64], [(0, 0), (3, 7), (31, 63)], [0x3dadc8af, 0x3e4060c0, 0x3e80ab2c].map(f32::from_bits)), + ] { + let context = CookContext { + input_formats: &[], + format, + w: size[0], + h: size[1], + seed: 520885, + tile: true, + inputs: &[], + params: ¶ms, + resource: &|_| Some(source.clone()), + vars: &BTreeMap::new(), + }; + let result = (definition.cook)(&context).unwrap(); + let stored = crate::output_precision::apply(result[0].clone(), format); + assert_eq!(positions.map(|(x, y)| stored.get_gray(x, y, false)), expected); + } +} + #[test] fn nearest_transform_mip_keeps_the_last_column_of_an_odd_width_input() { let definition = find("transformation").unwrap(); @@ -33,6 +189,7 @@ fn nearest_transform_mip_keeps_the_last_column_of_an_odd_width_input() { let vars = BTreeMap::new(); let resource = |_: &str| None; let context = CookContext { + input_formats: &[], format: materialcraft_core::OutputFormat::F32, w: 2, h: 2, @@ -115,6 +272,7 @@ fn every_node_survives_hostile_params() { let no_res = |_: &str| None; let vars = BTreeMap::new(); let ctx = CookContext { + input_formats: &[], format: materialcraft_core::OutputFormat::F32, w: 16, h: 16, @@ -158,6 +316,7 @@ fn blend_and_levels_math() { let vars = BTreeMap::new(); let inputs = [Some(fg), Some(bg), None]; let ctx = CookContext { + input_formats: &[], format: materialcraft_core::OutputFormat::F32, w: 4, h: 4, @@ -193,7 +352,18 @@ fn dynamic_gradient_preserves_the_gradient_image_type() { fn cook_sized(def: &NodeDefinition, inputs: &[Option], w: u32, h: u32, resource: &(dyn Fn(&str) -> Option + Sync)) -> CookResult { let params = resolve_params(def, &BTreeMap::new()); let vars = BTreeMap::new(); - let ctx = CookContext { format: materialcraft_core::OutputFormat::F32, w, h, seed: 7, tile: false, inputs, params: ¶ms, resource, vars: &vars }; + let ctx = CookContext { + input_formats: &[], + format: materialcraft_core::OutputFormat::F32, + w, + h, + seed: 7, + tile: false, + inputs, + params: ¶ms, + resource, + vars: &vars, + }; (def.cook)(&ctx) } @@ -230,6 +400,7 @@ fn nearest_transformation_mips_preserve_finite_hdr_constants() { for kind in [Kind::Gray, Kind::Color] { let inputs = [Some(Image::filled(16, 16, kind, [value; 4]))]; let context = CookContext { + input_formats: &[], format: materialcraft_core::OutputFormat::F32, w: 4, h: 4, @@ -263,6 +434,212 @@ fn directional_warp_repeats_a_far_offset_with_its_phase() { } } +fn warp_byte_inputs(source: [u32; 2], map: [u32; 2]) -> [Option; 2] { + let level = |n: i32, denominator: f32| (n as f32 * 255.0 / denominator).round_ties_even() / 255.0; + let field = Image::gray(source[0], source[1], |x, y| level(((41 * x + 53 * y + 7 * x * y + 29) % 1021) as i32, 1020.0)).with_integer_sampling(true); + let mask = Image::gray(map[0], map[1], |x, y| { + let (x, y) = (x as i32, y as i32); + level((11 * x - 17 * y + 3 * x * y + 401).rem_euclid(509), 508.0) + }) + .with_integer_sampling(true); + [Some(field), Some(mask)] +} + +#[test] +fn directional_warp_samples_stored_texels_along_positive_image_angles() { + use materialcraft_core::OutputFormat; + + let inputs = warp_byte_inputs([64; 2], [64; 2]); + let definition = find("directional_warp").unwrap(); + for (angle, intensity, tiling, interior, corner) in [ + (0.0, 7.0, 3, 0x3f1e109e, 0x3e741cf4), + (0.25, 11.0, 3, 0x3f1eaa9f, 0x3ee6a8e7), + (0.125, 17.0, 3, 0x3f2346a3, 0x3d6d90ee), + (0.1875, 25.0, 0, 0x3f258da6, 0x3d20a0a1), + (-0.3125, 21.5, 1, 0x3f134293, 0x3efbecfc), + ] { + let params = resolve_params(definition, &BTreeMap::from([("intensity".into(), Value::Float(intensity)), ("angle".into(), Value::Float(angle))])); + let vars = BTreeMap::from([("$tiling".into(), Value::Int(tiling))]); + let context = CookContext { + w: 64, + h: 64, + seed: 751, + tile: tiling != 0, + format: OutputFormat::F32, + input_formats: &[OutputFormat::U8; 2], + inputs: &inputs, + params: ¶ms, + vars: &vars, + resource: &|_| None, + }; + let image = (definition.cook)(&context).unwrap().remove(0); + assert_eq!(image.get_gray(7, 13, false).to_bits(), interior, "angle {angle}"); + assert_eq!(image.get_gray(63, 63, false).to_bits(), corner, "tiling {tiling}"); + } +} + +#[test] +fn horizontal_warp_at_zero_turns_keeps_the_full_displacement() { + use materialcraft_core::OutputFormat; + + let definition = find("directional_warp").unwrap(); + let inputs = [Some(Image::gray(16, 16, |x, _| x as f32)), Some(Image::filled(16, 16, Kind::Gray, [1025.0 / 2048.0; 4]))]; + for (angle, expected) in [(0.0, 2.0 + 1.0 / 256.0), (1.0, 2.0)] { + let params = resolve_params(definition, &BTreeMap::from([("intensity".into(), Value::Float(64.0)), ("angle".into(), Value::Float(angle))])); + let context = CookContext { + w: 16, + h: 16, + seed: 395191, + tile: true, + format: OutputFormat::F32, + input_formats: &[OutputFormat::F32; 2], + inputs: &inputs, + params: ¶ms, + vars: &BTreeMap::new(), + resource: &|_| None, + }; + let image = (definition.cook)(&context).unwrap().remove(0); + assert_eq!(image.get_gray(0, 0, false), expected, "angle {angle}"); + } +} + +#[test] +fn directional_warp_filters_unequal_image_and_mask_sizes() { + use materialcraft_core::OutputFormat; + + let definition = find("directional_warp").unwrap(); + let params = resolve_params(definition, &BTreeMap::from([("intensity".into(), Value::Float(17.0)), ("angle".into(), Value::Float(0.125))])); + for (source, map, side, center, edge) in [ + ([64; 2], Some([16, 32]), 64, 0x3deaa0eb, 0x3e5bb8dc), + ([64; 2], Some([16, 32]), 32, 0x3ed030d0, 0x3e91a092), + ([16; 2], Some([128; 2]), 32, 0x3f2f3cd9, 0x3d754e55), + ([8, 32], None, 128, 0x3e92e2d9, 0x3e18104b), + ([128, 16], None, 16, 0x3ef47d4d, 0x3efe4e5f), + ] { + let mut inputs = warp_byte_inputs(source, map.unwrap_or([1, 1])); + if map.is_none() { + inputs[1] = Some(Image::filled(side, side, Kind::Gray, [1.0; 4]).with_integer_sampling(true)); + } + let context = CookContext { + w: side, + h: side, + seed: 863, + tile: true, + format: OutputFormat::F32, + input_formats: &[OutputFormat::U8; 2], + inputs: &inputs, + params: ¶ms, + vars: &BTreeMap::new(), + resource: &|_| None, + }; + let image = (definition.cook)(&context).unwrap().remove(0); + assert_eq!(image.get_gray(7, 13, false).to_bits(), center, "source {source:?}, map {map:?}, output {side}"); + assert_eq!(image.get_gray(0, 0, false).to_bits(), edge); + } +} + +#[test] +fn directional_warp_preserves_the_wider_format_while_resizing_each_input() { + use materialcraft_core::OutputFormat::{F16, F32, U8, U16}; + + let definition = find("directional_warp").unwrap(); + let params = resolve_params(definition, &BTreeMap::from([("intensity".into(), Value::Float(17.0)), ("angle".into(), Value::Float(0.125))])); + for (source_format, mask_format, output, expected) in [ + (F32, F32, U8, [0, 172, 114, 0, 1]), + (F16, U16, U16, [0, 44159, 29248, 0, 250]), + (U16, U8, F16, [12326, 14539, 14209, 12653, 13043]), + (U8, F32, U16, [8408, 39305, 30722, 11126, 14133]), + ] { + let input_value = |v: f64, format| match format { + U8 => (v * 255.0).round_ties_even() as f32 / 255.0, + U16 => (v * 65535.0).round_ties_even() as f32 / 65535.0, + F16 => half::f16::from_f64(v).to_f32(), + _ => v as f32, + }; + let image = Image::gray(16, 32, |x, y| { + let value = f64::from((41 * x + 53 * y + 7 * x * y + 29) % 1021) / 1020.0; + input_value(if matches!(source_format, F16 | F32) { value * 1.75 - 0.375 } else { value }, source_format) + }) + .with_integer_sampling(matches!(source_format, U8 | U16)); + let mask = Image::gray(32, 16, |x, y| { + let (x, y) = (x as i32, y as i32); + input_value(f64::from((11 * x - 17 * y + 3 * x * y + 401).rem_euclid(509)) / 508.0, mask_format) + }) + .with_integer_sampling(matches!(mask_format, U8 | U16)); + let context = CookContext { + w: 64, + h: 64, + seed: 1, + tile: true, + format: output, + input_formats: &[source_format, mask_format], + inputs: &[Some(image), Some(mask)], + params: ¶ms, + vars: &BTreeMap::new(), + resource: &|_| None, + }; + let result = crate::output_precision::apply((definition.cook)(&context).unwrap().remove(0), output); + let stored = [(0, 0), (7, 13), (14, 5), (32, 32), (63, 63)].map(|(x, y)| { + let v = result.get_gray(x, y, false); + if output == F16 { half::f16::from_f32(v).to_bits() } else { (v * if output == U8 { 255.0 } else { 65535.0 }).round() as u16 } + }); + assert_eq!(stored, expected, "{source_format:?}/{mask_format:?} into {output:?}"); + } +} + +#[test] +fn directional_warp_keeps_large_authored_displacements_and_their_direction() { + use materialcraft_core::OutputFormat; + + let definition = find("directional_warp").unwrap(); + let inputs = [Some(Image::generate(64, 64, Kind::Color, |x, y| [x as f32, y as f32, 0.0, 1.0])), Some(Image::filled(64, 64, Kind::Gray, [1.0; 4]))]; + for (angle, expected) in [(0.125, [7.59375, 7.59375]), (0.5, [32.03125, 31.953125]), (0.625, [56.53125, 56.34375])] { + let params = resolve_params(definition, &BTreeMap::from([("intensity".into(), Value::Float(2_097_152.0)), ("angle".into(), Value::Float(angle))])); + assert_eq!(params["intensity"], Value::Float(2_097_152.0)); + let context = CookContext { + w: 64, + h: 64, + seed: 887, + tile: true, + format: OutputFormat::F32, + input_formats: &[OutputFormat::F32; 2], + inputs: &inputs, + params: ¶ms, + vars: &BTreeMap::new(), + resource: &|_| None, + }; + let pixel = (definition.cook)(&context).unwrap().remove(0).get(32, 32, false); + assert_eq!(pixel[..2], expected, "angle {angle}"); + } +} + +#[test] +fn rectangular_directional_warps_scale_both_offsets_by_the_shorter_side() { + let definition = find("directional_warp").unwrap(); + let params = resolve_params(definition, &BTreeMap::from([("intensity".into(), Value::Float(16.0)), ("angle".into(), Value::Float(0.125))])); + for (width, height, shift) in [(32, 16, 0.70703125), (16, 32, 0.70703125), (128, 32, 1.4140625), (32, 128, 1.4140625)] { + let inputs = [ + Some(Image::generate(width, height, Kind::Color, |x, y| [x as f32, y as f32, 0.0, 1.0])), + Some(Image::filled(width, height, Kind::Gray, [1.0; 4])), + ]; + let context = CookContext { + w: width, + h: height, + seed: 887, + tile: true, + format: materialcraft_core::OutputFormat::F32, + input_formats: &[], + inputs: &inputs, + params: ¶ms, + vars: &BTreeMap::new(), + resource: &|_| None, + }; + let image = (definition.cook)(&context).unwrap().remove(0); + let (x, y) = (width / 2, height / 2); + assert_eq!(image.get(i64::from(x), i64::from(y), false), [x as f32 + shift, y as f32 + shift, 0.0, 1.0]); + } +} + /// Shrinking a bitmap of large HDR values averages them without overflowing. #[test] fn bitmap_shrinks_large_hdr_values_without_overflow() { diff --git a/crates/nodes/src/texture_sampler.rs b/crates/nodes/src/texture_sampler.rs new file mode 100644 index 00000000..d7a31a1e --- /dev/null +++ b/crates/nodes/src/texture_sampler.rs @@ -0,0 +1,408 @@ +use craft_texture::{Image, Kind}; +use materialcraft_core::OutputFormat; + +/// Resample one stored input level at destination pixel centers. +pub fn resize_input_level(image: &Image, width: u32, height: u32, format: OutputFormat, tiling: [bool; 2]) -> Image { + Image::generate_uv(width, height, image.kind(), |u, v| sample(image, [u, v], tiling, format, None)) +} + +/// Leave each axis within one doubling or halving for the final two-dimensional filter. +pub(crate) fn next_filter_size(current: (u32, u32), target: (u32, u32)) -> (u32, u32) { + let advance = |now: u32, end: u32| { + if now.saturating_mul(2) < end { + now.saturating_mul(2) + } else if end.saturating_mul(2) < now { + now.div_ceil(2) + } else { + now + } + }; + let intermediate = (advance(current.0, target.0), advance(current.1, target.1)); + if intermediate == current { target } else { intermediate } +} + +/// Resize a raster bound directly to an input, converting its channels after the first sampling pass. +pub fn resize_bound_image(image: Image, size: (u32, u32), kind: Kind, source: OutputFormat, output: OutputFormat, tiling: [bool; 2]) -> Image { + resize_stored_levels(image, size, kind, source, output, tiling, |current, target| { + let next = |from: u32, to: u32| if from < to { from.saturating_mul(2).min(to) } else { from.div_ceil(2).max(to) }; + (next(current.0, target.0), next(current.1, target.1)) + }) +} + +/// A graph connection uses the same final two-axis filter as an atomic node input. +pub fn resize_connected_image(image: Image, size: (u32, u32), kind: Kind, source: OutputFormat, output: OutputFormat, tiling: [bool; 2]) -> Image { + resize_stored_levels(image, size, kind, source, output, tiling, next_filter_size) +} + +fn resize_stored_levels( + mut image: Image, + size: (u32, u32), + kind: Kind, + mut source: OutputFormat, + output: OutputFormat, + tiling: [bool; 2], + next_size: impl Fn((u32, u32), (u32, u32)) -> (u32, u32), +) -> Image { + let size = craft_texture::clamp_size(size.0, size.1); + loop { + let current = (image.width(), image.height()); + if current != size { + let (w, h) = next_size(current, size); + image = resize_input_level(&image, w, h, source, tiling); + } + // Later levels read the stored channels, including any RGB-to-gray conversion. + if image.kind() != kind { + image = match kind { + Kind::Gray => { + let weight = 1.0 / 3.0; + image.map(Kind::Gray, |p| [p[2].mul_add(weight, p[1].mul_add(weight, p[0] * weight)), 0.0, 0.0, 0.0]) + } + Kind::Color => image.to_color(), + }; + } + image = crate::output_precision::apply(image, output); + if (image.width(), image.height()) == size { + return image; + } + source = output; + } +} + +/// Value and pattern functions filter stored channel levels using full-precision texel fractions. +pub(crate) fn sample_uniform(image: &Image, uv: [f32; 2], format: OutputFormat, bilinear: bool, repeat: bool) -> [f32; 4] { + if !uv.iter().all(|v| v.is_finite()) { + return [0.0, 0.0, 0.0, 1.0]; + } + let offset = if bilinear { 0.5 } else { 0.0 }; + let axis = |v: f32, size: u32| { + let extent = size as f32; + let scaled = v * extent; + if !repeat { + // Clamp the tap indices. Even four reads of one corner retain their original filter weights. + let texel = if scaled.is_finite() { scaled - offset } else { scaled.signum() * extent }; + let first = texel.floor(); + return (first.clamp(-1.0, extent) as i64, texel - first); + } + // At extreme magnitudes the UV is a whole number of repeats. Keep neighboring indices bounded. + let texel = if scaled.is_finite() { scaled - offset } else { -offset }; + let first = texel.floor(); + // A nearest read exactly on a negative texel boundary belongs to the preceding texel. + let previous = !bilinear && texel < 0.0 && texel == first; + ((first % extent) as i64 - i64::from(previous), texel - first) + }; + let (x, dx) = axis(uv[0], image.width()); + let (y, dy) = axis(uv[1], image.height()); + let levels = match format { + OutputFormat::U8 => Some(255.0_f32), + OutputFormat::U16 => Some(65535.0_f32), + _ => None, + }; + let fetch = |x, y| { + let pixel = image.get(x, y, repeat); + levels.map_or(pixel, |maximum| pixel.map(|v| (v * maximum).round())) + }; + let a = fetch(x, y); + let filtered = if bilinear { + let b = fetch(x + 1, y); + let c = fetch(x, y + 1); + let d = fetch(x + 1, y + 1); + std::array::from_fn(|i| { + let top = a[i] * (1.0 - dx) + b[i] * dx; + let bottom = c[i] * (1.0 - dx) + d[i] * dx; + top * (1.0 - dy) + bottom * dy + }) + } else { + a + }; + levels.map_or(filtered, |maximum| filtered.map(|v| v * maximum.recip())) +} + +/// Bilinear texture filtering. Untiled axes clamp unless the caller supplies a border color. +pub(crate) fn sample(image: &Image, uv: [f32; 2], tiling: [bool; 2], format: OutputFormat, matte: Option<[f32; 4]>) -> [f32; 4] { + if !uv.iter().all(|v| v.is_finite()) { + return matte.unwrap_or([0.0, 0.0, 0.0, 1.0]); + } + filter_taps(image, taps(image, uv, tiling), tiling, format, matte, std::convert::identity) +} + +/// Pixel functions address each coordinate before selecting or filtering texels. +pub(crate) fn sample_pixel(image: &Image, uv: [f32; 2], format: OutputFormat, bilinear: bool, repeat: bool) -> [f32; 4] { + // A singular projection can invalidate just one axis. Repeats sample the seam, + // while a clamped positive infinity reaches the far edge. + let uv = uv.map(|v| { + if v.is_finite() { + v + } else if !repeat && v == f32::INFINITY { + 1.0 + } else { + 0.0 + } + }); + if !bilinear { + return image.get((uv[0] * image.width() as f32).floor() as i64, (uv[1] * image.height() as f32).floor() as i64, repeat); + } + let tiling = [repeat; 2]; + if format != OutputFormat::F32 { + return sample(image, uv, tiling, format, None); + } + // Filtered F32 reads flush subnormals at the texels and again at the result. + filter_taps(image, taps(image, uv, tiling), tiling, format, None, |pixel| pixel.map(crate::function::flush_subnormal)) +} + +/// Average each clamped 2×2 footprint at source precision, then store the reduced level. +pub(crate) fn reduce_level(image: &Image, source: OutputFormat, destination: OutputFormat) -> Image { + let level = Image::generate(image.width().div_ceil(2), image.height().div_ceil(2), image.kind(), |x, y| { + let (x, y) = (i64::from(x) * 2, i64::from(y) * 2); + let taps = [(x, y, 64), (x + 1, y, 64), (x, y + 1, 64), (x + 1, y + 1, 64)]; + filter_taps(image, taps, [false; 2], source, None, std::convert::identity) + }); + crate::output_precision::apply(level, destination) +} + +fn filter_taps( + image: &Image, + taps: [(i64, i64, u32); 4], + tiling: [bool; 2], + format: OutputFormat, + matte: Option<[f32; 4]>, + prepare: impl Fn([f32; 4]) -> [f32; 4], +) -> [f32; 4] { + if image.integer_sampling() { + return sample_normalized(image, taps, tiling, matte); + } + let read = |x, y| prepare(texel(image, x, y, tiling, matte)); + if let Some((x, y, _)) = taps.iter().find(|(_, _, weight)| *weight == 256) { + return read(*x, *y); + } + let pixels = taps.map(|(x, y, weight)| (read(x, y), weight)); + prepare(std::array::from_fn(|channel| filter_float(&pixels, channel, format))) +} + +fn taps(image: &Image, [u, v]: [f32; 2], tiling: [bool; 2]) -> [(i64, i64, u32); 4] { + let (x, dx) = axis(u, image.width(), tiling[0]); + let (y, dy) = axis(v, image.height(), tiling[1]); + // Round the diagonal coefficient first. The four tap weights must still sum to 256. + let diagonal = (dx * dy + 128) / 256; + let bottom = dy - diagonal; + [(x, y, 256 - dx - bottom), (x + 1, y, dx - diagonal), (x, y + 1, bottom), (x + 1, y + 1, diagonal)] +} + +fn texel(image: &Image, x: i64, y: i64, tiling: [bool; 2], matte: Option<[f32; 4]>) -> [f32; 4] { + if let Some(matte) = matte + && ((!tiling[0] && !(0..i64::from(image.width())).contains(&x)) || (!tiling[1] && !(0..i64::from(image.height())).contains(&y))) + { + return matte; + } + image.get_axes(x, y, tiling) +} + +fn sample_normalized(image: &Image, taps: [(i64, i64, u32); 4], tiling: [bool; 2], matte: Option<[f32; 4]>) -> [f32; 4] { + let mut sum = [0.0; 4]; + for (x, y, weight) in taps { + if weight != 0 { + for (total, channel) in sum.iter_mut().zip(texel(image, x, y, tiling, matte)) { + // Stored 16-bit levels times the eight-bit weights sum exactly in f32. + *total += (channel.clamp(0.0, 1.0) * 65535.0).round() * weight as f32; + } + } + } + sum.map(|value| (value / 256.0).round() / 65535.0) +} + +fn filter_float(taps: &[([f32; 4], u32); 4], channel: usize, format: OutputFormat) -> f32 { + let mut maximum = 0.0_f32; + for (pixel, weight) in taps { + if *weight != 0 { + let value = pixel[channel]; + if !value.is_finite() { + return taps.iter().filter(|(_, w)| *w != 0).map(|(p, w)| p[channel] * (*w as f32 / 256.0)).sum(); + } + maximum = maximum.max(value.abs()); + } + } + if maximum == 0.0 { + // A footprint of negative zeros retains its sign. A zero-weight texel cannot change it. + return if taps.iter().all(|(pixel, weight)| *weight == 0 || pixel[channel].is_sign_negative()) { -0.0 } else { 0.0 }; + } + + // Align participating texels to their largest exponent, retaining four extra significand bits. + // The fixed-point products fit in 36 bits even for the largest finite float32 inputs. + let (fraction_bits, smallest_exponent) = if format == OutputFormat::F16 { (10, -24) } else { (23, -149) }; + let exponent = (f64::from(maximum).to_bits() >> 52) as i32 - 1023; + let unit_exponent = exponent - fraction_bits - 4; + let scale = f64::from_bits(((1023 - unit_exponent) as u64) << 52); + let sum: i64 = taps.iter().filter(|(_, w)| *w != 0).map(|(p, w)| (f64::from(p[channel]) * scale) as i64 * i64::from(*w)).sum(); + let magnitude = sum.unsigned_abs(); + if magnitude == 0 { + return 0.0; + } + // Round the weighted sum once at the input storage precision, including ties away from zero. + let shift = (63 - magnitude.leading_zeros() as i32 - fraction_bits).max(smallest_exponent - (unit_exponent - 8)).max(0); + if shift >= 63 { + return 0.0; + } + let rounded = if shift == 0 { magnitude } else { ((magnitude + (1 << (shift - 1))) >> shift) << shift }; + let value = (rounded as f64 / (256.0 * scale)) as f32; + if sum < 0 { -value } else { value } +} + +fn axis(uv: f32, size: u32, tile: bool) -> (i64, u32) { + // Keep the signed fraction until the integer texel is addressed. Adding a repeat in f32 can + // round a negative coordinate across an eight-bit weight boundary. Reduce before scaling to + // keep even extreme coordinates bounded, and retain the half-texel offset exactly. + let uv = if tile { uv.fract() } else { uv.clamp(-1.0, 2.0) }; + let texel = f64::from(uv) * f64::from(size) - 0.5; + let first = texel.floor(); + (first as i64, ((texel - first) * 256.0).round() as u32) +} + +#[cfg(test)] +mod tests { + use crate::function::{EvaluationContext, EvaluationState, FunctionScope, compile}; + use craft_texture::{Image, Kind}; + use materialcraft_core::{FunctionGraph, Value}; + use std::collections::BTreeMap; + + #[test] + fn pixel_texture_reads_address_each_nonfinite_coordinate_independently() { + let field = Image::generate(16, 16, Kind::Color, |x, y| [(x + 1) as f32 / 64.0, (y + 1) as f32 / 64.0, 0.5, 1.0]); + let images = [Some(field)]; + let filtered_row = 11.3125 / 64.0; + for (mode, edge, row) in [(0, 0.015625, 0.171875), (1, 0.1328125, filtered_row), (2, 0.015625, 0.171875), (3, 0.015625, filtered_row)] { + let mut graph = FunctionGraph::default(); + let uv = graph.add("get_float2", &[], Some(Value::Text("uv".into()))); + graph.output = Some(graph.add("samplecol", &[uv], Some(Value::Int2([0, mode])))); + let program = compile(&graph, 0).unwrap(); + for value in [f32::NEG_INFINITY, f32::NAN, f32::INFINITY] { + let vars = BTreeMap::from([("uv".into(), Value::Float2([value, 0.67578125]))]); + let context = EvaluationContext { + scope: FunctionScope::PixelProcessor, + position: [0.5; 2], + size: [16.0; 2], + images: &images, + image_formats: &[materialcraft_core::OutputFormat::F32], + tile: true, + variables: &vars, + }; + let sampled = program.evaluate(&context, &mut EvaluationState::default()).unwrap(); + let edge = if mode >= 2 && value == f32::INFINITY { 0.25 } else { edge }; + assert_eq!(sampled, Value::Float4([edge, row, 0.5, 1.0]), "{value} in mode {mode}"); + } + } + } + + #[test] + fn floating_texture_filter_preserves_negative_zero_when_every_active_tap_has_its_sign() { + use materialcraft_core::OutputFormat; + + let image = Image::generate(2, 2, Kind::Color, |x, y| [-0.0, if x == 1 { 0.0 } else { -0.0 }, if y == 1 { 0.0 } else { -0.0 }, 0.0]); + for format in [OutputFormat::F16, OutputFormat::F32] { + for (position, expected) in [([0.5, 0.5], [-0.0_f32, 0.0, 0.0, 0.0]), ([0.25, 0.5], [-0.0, -0.0, 0.0, 0.0])] { + let result = super::sample(&image, position, [true; 2], format, None); + assert_eq!(result.map(f32::to_bits), expected.map(f32::to_bits)); + } + } + } + + #[test] + fn filtered_coordinates_keep_fraction_bits_through_wrap_and_texel_centering() { + use materialcraft_core::OutputFormat; + + let image = Image::gray(128, 1, |x, _| (x % 2) as f32); + for (bits, value) in [(0xbdfff801, 0.5), (0xbdffe801, 0.49609375), (0x3b7effff, 0.00390625), (0xbb808001, 0.99609375)] { + let sample = super::sample(&image, [f32::from_bits(bits), 0.5], [true; 2], OutputFormat::F32, None); + assert_eq!(sample[0], value, "{bits:08x}"); + } + } + + #[test] + fn value_sampler_repeats_and_filters_at_full_coordinate_precision() { + use materialcraft_core::OutputFormat; + + let colors = [[19., 67., 129., 251.], [85., 222., 17., 9.], [255., 128., 74., 66.], [3., 102., 39., 109.]]; + let bytes = Image::generate(2, 2, Kind::Color, |x, y| colors[(2 * y + x) as usize].map(|n| n / 255.0)).with_integer_sampling(true); + let floats = Image::generate(2, 2, Kind::Color, |x, y| colors[(2 * y + x) as usize].map(|n| (n - 97.125) / 13.375)); + let images = [Some(bytes), Some(floats)]; + let context = EvaluationContext { + scope: FunctionScope::ValueProcessor, + position: [0.0; 2], + size: [16.0; 2], + images: &images, + image_formats: &[OutputFormat::U8, OutputFormat::F32], + tile: false, + variables: &BTreeMap::new(), + }; + for (slot, filtering, expected) in [ + (0, 0, [0x3eaaaaab, 0x3f5edee0, 0x3d888889, 0x3d109091]), + (0, 1, [0x3e8013a0, 0x3f2bd646, 0x3e0f43a5, 0x3e744cb7]), + (1, 1, [0xc01f84ad, 0x40b124ef, 0xc093048e, 0xc02da496]), + ] { + let mut graph = FunctionGraph::default(); + let uv = graph.add_constant(Value::Float2([-0.317, 1.093])); + graph.output = Some(graph.add("samplecol", &[uv], Some(Value::Int2([slot, filtering])))); + let program = compile(&graph, 0).unwrap(); + assert_eq!(program.evaluate(&context, &mut EvaluationState::default()).unwrap(), Value::Float4(expected.map(f32::from_bits))); + } + } + + #[test] + fn pixel_sampler_rounds_the_four_integer_texel_weights_together() { + // RGBA identifies the four corners independently. At (1,128)/256 the diagonal weight is halfway to one. + let image = Image::generate(2, 2, Kind::Color, |x, y| { + let mut pixel = [0.0; 4]; + pixel[(2 * y + x) as usize] = 1.0; + pixel + }) + .with_integer_sampling(true); + let variables = BTreeMap::new(); + let mut context = EvaluationContext { + image_formats: &[], + scope: FunctionScope::PixelProcessor, + position: [0.25 + 1.0 / 512.0, 0.5], + size: [2.0; 2], + images: &[Some(image)], + tile: true, + variables: &variables, + }; + let mut graph = FunctionGraph::default(); + let pos = graph.add("get_float2", &[], Some(Value::Text("$pos".into()))); + graph.output = Some(graph.add("samplecol", &[pos], Some(Value::Int2([0, 1])))); + let program = compile(&graph, 0).unwrap(); + let pixel = |context: &EvaluationContext<'_>| program.evaluate(context, &mut EvaluationState::default()).unwrap(); + let expected = Value::Float4([32768.0, 0.0, 32512.0, 256.0].map(|n| n / 65535.0)); + assert_eq!(pixel(&context), expected); + context.position[0] -= 1.0; + assert_eq!(pixel(&context), expected); + context.tile = false; + assert_eq!(pixel(&context), expected); + graph.nodes.last_mut().unwrap().value = Some(Value::Int2([0, 0])); + let nearest = compile(&graph, 0).unwrap(); + assert_eq!(nearest.evaluate(&context, &mut EvaluationState::default()).unwrap(), Value::Float4([0.0, 0.0, 1.0, 0.0])); + } + + #[test] + fn pixel_sampler_uses_the_storage_precision_of_the_selected_slot() { + use materialcraft_core::OutputFormat; + + let bits = [0x3fd0e000, 0xbfa46000, 0xc02d8000, 0x407f0000]; + let image = Image::gray(2, 2, |x, y| f32::from_bits(bits[(2 * y + x) as usize])); + let inputs = [Some(image.clone()), Some(image)]; + let variables = BTreeMap::new(); + let context = EvaluationContext { + scope: FunctionScope::PixelProcessor, + position: [0.375, 0.4375], + size: [2.0; 2], + images: &inputs, + image_formats: &[OutputFormat::F32, OutputFormat::F16], + tile: true, + variables: &variables, + }; + for (index, expected) in [(0, 0x3e339000), (1, 0x3e33a000)] { + let mut graph = FunctionGraph::default(); + let pos = graph.add("get_float2", &[], Some(Value::Text("$pos".into()))); + graph.output = Some(graph.add("samplelum", &[pos], Some(Value::Int2([index, 1])))); + let program = compile(&graph, 0).unwrap(); + assert_eq!(program.evaluate(&context, &mut EvaluationState::default()).unwrap(), Value::Float(f32::from_bits(expected))); + } + } +} diff --git a/crates/nodes/tests/atomic_filter_parity.rs b/crates/nodes/tests/atomic_filter_parity.rs index 20e23045..68ad20fd 100644 --- a/crates/nodes/tests/atomic_filter_parity.rs +++ b/crates/nodes/tests/atomic_filter_parity.rs @@ -1,18 +1,361 @@ use craft_texture::{Image, Kind}; -use materialcraft_core::{OutputFormat, Value}; +use materialcraft_core::{Gradient, GradientKey, OutputFormat, PatternGraph, PatternNodeKind, Value}; use materialcraft_nodes::{CookContext, find, resolve_params}; use std::collections::BTreeMap; fn cook(id: &str, inputs: &[Option], values: &[(&str, Value)], size: [u32; 2], tile: bool) -> Image { + cook_format(id, inputs, values, size, tile, OutputFormat::F32) +} + +fn cook_format(id: &str, inputs: &[Option], values: &[(&str, Value)], size: [u32; 2], tile: bool, format: OutputFormat) -> Image { let definition = find(id).unwrap(); let values = values.iter().map(|(key, value)| ((*key).into(), value.clone())).collect(); let params = resolve_params(definition, &values); let resource = |_: &str| None; let vars = BTreeMap::new(); - let context = CookContext { w: size[0], h: size[1], seed: 0, format: OutputFormat::F32, tile, inputs, params: ¶ms, resource: &resource, vars: &vars }; + let context = CookContext { input_formats: &[], w: size[0], h: size[1], seed: 0, format, tile, inputs, params: ¶ms, resource: &resource, vars: &vars }; (definition.cook)(&context).unwrap().remove(0) } +#[test] +fn empty_pattern_uses_the_finite_background_before_grayscale_conversion() { + let mut pattern = PatternGraph::with_root(PatternNodeKind::Quadrant); + pattern.nodes[0].parameters.insert("patterntype".into(), Value::Int(0)); + let render = |background, color| { + let values = + [("background", Value::Color(background)), ("color_mode", Value::Bool(color)), ("pattern", Value::PatternGraph(Box::new(pattern.clone())))]; + cook("fx_map", &[], &values, [8, 8], true) + }; + + let background = [-64.0, 192.0, -32.0, 40.0]; + assert_eq!(render(background, true).get(0, 0, false), background); + assert_eq!(render(background, false).get_gray(0, 0, false), 32.0); + let large = f32::from_bits(0x7f00_0000); + assert_eq!(render([large, large, large, 1.0], false).get_gray(0, 0, false), f32::INFINITY); +} + +#[test] +fn oblique_blur_uses_axial_taps_when_one_pixel_extent_is_zero() { + let definition = find("directional_blur").unwrap(); + let vars = BTreeMap::from([("$pixelratio".into(), Value::Int(0))]); + for (w, h, angle, intensity, phase, expected) in [(16, 64, -0.15625, 7.0, 606401, 0x3ea8_9223), (128, 32, 0.125, 4.0, 606448, 0x3f01_0625)] { + let params = resolve_params(definition, &BTreeMap::from([("angle".into(), Value::Float(angle)), ("intensity".into(), Value::Float(intensity))])); + let field = Image::gray(w, h, |x, y| ((59 * x + 23 * y + 7 * x * y + phase) % 251) as f32 / 250.0); + let inputs = [Some(field)]; + let context = CookContext { + w, + h, + seed: 0, + format: OutputFormat::F32, + tile: true, + input_formats: &[OutputFormat::F32], + inputs: &inputs, + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + let image = (definition.cook)(&context).unwrap().remove(0); + assert_eq!(image.get_gray(7, 13, false).to_bits(), expected, "{w} x {h}"); + } +} + +#[test] +fn min_blend_accumulates_the_background_weight_on_the_foreground_product() { + let foreground = Image::gray(1, 1, |_, _| 46.0 / 255.0); + let background = Image::gray(1, 1, |_, _| 79.0 / 255.0); + let out = cook("blend", &[Some(foreground), Some(background)], &[("mode", Value::Enum(6)), ("opacity", Value::Float(0.56))], [1, 1], true); + assert_eq!(out.get_gray(0, 0, false).to_bits(), 0x3e730783); +} + +#[test] +fn warp_uses_the_current_gradient_texel_and_its_predecessors() { + let source = Image::gray(32, 32, |x, _| (x as f32 + 0.5) / 32.0); + let gradient = Image::gray(32, 32, |x, y| f32::from(x == 16 && y == 16)); + let image = cook("warp", &[Some(source), Some(gradient)], &[], [32, 32], true); + for (x, y, expected) in [(15, 16, 15.5), (16, 16, 20.5), (17, 16, 13.5), (16, 17, 16.5)] { + assert_eq!(image.get_gray(x, y, false), expected / 32.0); + } +} + +#[test] +fn warp_differences_span_one_stored_gradient_texel_when_inputs_are_larger() { + let field = |width, height, seed| { + Image::gray(width, height, |x, y| { + let code = (131 * x + 367 * y + 29 * x * y + seed) % 2053; + 1.5 * (code as f32 / 2052.0) - 0.25 + }) + }; + let inputs = [Some(field(64, 32, 17473)), Some(field(32, 64, 17486))]; + let image = cook("warp", &inputs, &[("intensity", Value::Float(0.8375))], [32, 32], true); + for (x, y, bits) in [(5, 0, 0x3ef4626f), (6, 0, 0x3e969df1), (13, 17, 0x3e9b9a34), (31, 31, 0x3eec51f7)] { + assert_eq!(image.get_gray(x, y, false).to_bits(), bits); + } +} + +#[test] +fn rectangular_warp_scales_displacement_by_the_shorter_side_and_preserves_nearest_filtering() { + let source = Image::generate(32, 16, Kind::Color, |x, y| [(x as f32 + 0.5) / 32.0, (y as f32 + 0.5) / 16.0, 0.0, 1.0]); + let gradient = Image::gray(32, 16, |x, y| 0.5 * f32::from(x >= 16) + 0.25 * f32::from(y >= 8)); + let inputs = [Some(source), Some(gradient)]; + for (nearest, expected) in [(false, [0.53125, 0.546875]), (true, [0.546875, 0.53125])] { + let image = cook("warp", &inputs, &[("nearest", Value::Bool(nearest))], [32, 16], true); + let [x, y, _, _] = image.get(16, 8, false); + assert_eq!([x, y], expected); + } +} + +#[test] +fn warp_uses_the_extent_of_each_axis_for_stretched_pixels() { + let definition = find("warp").unwrap(); + let params = resolve_params(definition, &BTreeMap::new()); + for (w, h, ratio, expected) in [ + (32, 16, 0, [0.578125, 0.546875]), + (16, 32, 0, [0.5625, 0.546875]), + (64, 32, 0, [0.6328125, 0.546875]), + (32, 16, 1, [0.53125, 0.546875]), + (16, 32, 1, [0.5625, 0.5234375]), + ] { + let source = Image::generate(w, h, Kind::Color, |x, y| [(x as f32 + 0.5) / w as f32, (y as f32 + 0.5) / h as f32, 0.0, 1.0]); + let gradient = Image::gray(w, h, |x, y| 0.5 * f32::from(x >= w / 2) + 0.25 * f32::from(y >= h / 2)); + let inputs = [Some(source), Some(gradient)]; + let vars = BTreeMap::from([("$pixelratio".into(), Value::Int(ratio))]); + let context = CookContext { + w, + h, + seed: 0, + format: OutputFormat::F32, + tile: true, + input_formats: &[OutputFormat::F32; 2], + inputs: &inputs, + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + let pixel = (definition.cook)(&context).unwrap().remove(0).get(i64::from(w / 2), i64::from(h / 2), false); + assert_eq!([pixel[0], pixel[1]], expected, "pixel ratio {ratio} at {w} by {h}"); + } +} + +#[test] +fn emboss_applies_each_tint_to_a_one_sided_height_difference() { + let color = Image::filled(32, 32, Kind::Color, [0.25, 0.5, 0.75, 0.375]); + let height = Image::gray(32, 32, |x, y| if x == 16 && y == 16 { 1.0 } else { 0.0 }); + let image = cook( + "emboss", + &[Some(color), Some(height)], + &[("intensity", Value::Float(2.0)), ("highlight", Value::Color([0.75, 0.25, 0.125, 0.5])), ("shadow", Value::Color([0.125, 0.875, 0.375, 0.25]))], + [32, 32], + true, + ); + assert_eq!(image.get(16, 16, false), [0.4375, 0.5625, 0.78125, 0.375]); + assert_eq!(image.get(17, 16, false), [0.03125, 0.46875, 0.59375, 0.375]); + assert_eq!(image.get(15, 16, false), [0.25, 0.5, 0.75, 0.375]); +} + +#[test] +fn emboss_averages_the_tints_for_a_grayscale_input() { + let base = Image::gray(32, 32, |_, _| 0.5); + let height = Image::gray(32, 32, |x, y| f32::from(x == 16 && y == 16)); + let image = cook( + "emboss", + &[Some(base), Some(height)], + &[("intensity", Value::Float(1.0)), ("highlight", Value::Color([0.75, 0.25, 0.125, 0.5])), ("shadow", Value::Color([0.125, 0.875, 0.375, 0.25]))], + [32, 32], + true, + ); + assert_eq!(image.get_gray(16, 16, false), 0.546875); + assert_eq!(image.get_gray(17, 16, false), 0.4322917); +} + +#[test] +fn grayscale_uses_all_driven_weights_and_flattens_signed_alpha() { + let px = [0xbfd95555, 0xbf9aaaab, 0xbf380000, 0xbe6aaaab].map(f32::from_bits); + let inp = Image::generate(2, 1, Kind::Color, |x, _| if x == 0 { [-0.0; 4] } else { px }); + let weights = ("weights", Value::Float4([0.125, 0.25, 0.5, 0.125])); + let gray = cook("grayscale_conversion", &[Some(inp.clone())], std::slice::from_ref(&weights), [2, 1], false); + assert_eq!(gray.get_gray(0, 0, false).to_bits(), 0); + let params = [weights, ("flatten_alpha", Value::Bool(true)), ("matte", Value::Float(0.3125))]; + let flattened = cook("grayscale_conversion", &[Some(inp)], ¶ms, [2, 1], false); + assert_eq!(flattened.get_gray(1, 0, false).to_bits(), 0x3f174555); +} + +#[test] +fn levels_applies_signed_gamma_before_mapping_the_output_range() { + let input = Image::generate(2, 1, Kind::Color, |x, _| if x == 0 { [-0.5; 4] } else { [3.0; 4] }); + let params = [("clamp_intermediate", Value::Bool(false)), ("in_mid", Value::Float4([0.25, 0.375, 0.625, 0.75]))]; + let output = cook("levels", &[Some(input)], ¶ms, [2, 1], false); + assert_eq!(output.get(0, 0, false).map(f32::to_bits), [0xbf5edc67, 0xbf4b2ff5, 0xbe000003, 0xbd000003]); + assert_eq!(output.get(1, 0, false).map(f32::to_bits), [0x3f9f741c, 0x3fb89ba3, 0x41d80001, 0x4372fffe]); +} + +#[test] +fn levels_filters_stored_integer_texels_before_remapping_the_range() { + let field = Image::gray(4, 8, |x, y| ((7 * x + 11 * y + 19 * x * y + 9) % 2000) as f32 / 65535.0); + let input = materialcraft_nodes::output_precision::apply(field, OutputFormat::U16); + let image = cook("levels", &[Some(input)], &[], [8, 8], true); + let row = std::array::from_fn(|x| image.get_gray(x as i64, 0, false).to_bits()); + assert_eq!(row, [0x396000e9, 0x393000b7, 0x396000e9, 0x39900094, 0x39a800a9, 0x39c800ce, 0x39e000e9, 0x39c800ce]); +} + +#[test] +fn levels_stores_an_enlarged_input_at_half_precision_before_applying_the_curve() { + let params = [ + ("in_low", Value::Float4([0.0625; 4])), + ("in_mid", Value::Float4([0.625; 4])), + ("out_low", Value::Float4([0.125; 4])), + ("out_high", Value::Float4([0.875; 4])), + ]; + for (width, expected) in [(4, 0x3e620000), (16, 0x3e1f4000)] { + let field = Image::gray(width, 8, |x, y| ((341 + 3279 * x + 9759 * y + 1737 * x * y) % 65536) as f32 / 65535.0); + let input = materialcraft_nodes::output_precision::apply(field, OutputFormat::U16); + let image = cook_format("levels", &[Some(input)], ¶ms, [8, 8], true, OutputFormat::F16); + let stored = materialcraft_nodes::output_precision::apply(image, OutputFormat::F16); + assert_eq!(stored.get_gray(5, 2, false).to_bits(), expected, "source width {width}"); + } +} + +#[test] +fn grayscale_levels_averages_rgb_controls_before_bounding_integer_endpoints() { + let input = [Some(Image::gray(1, 1, |_, _| 45308.0 / 65535.0))]; + let params = [ + ("in_low", Value::Float4([-0.5, 0.25, 1.625, -2.0])), + ("in_mid", Value::Float4([-0.3, 0.53, 1.25, 0.1])), + ("in_high", Value::Float4([0.601, -0.375, 1.875, 2.5])), + ("out_low", Value::Float4([-0.125, -0.875, 1.625, -0.5])), + ("out_high", Value::Float4([1.875, 1.125, -0.375, 2.125])), + ("clamp_intermediate", Value::Bool(false)), + ]; + let floating = cook("levels", &input, ¶ms, [1, 1], true); + assert_eq!(floating.get_gray(0, 0, false).to_bits(), 0x3f5a44c2); + let integer = cook_format("levels", &input, ¶ms, [1, 1], true, OutputFormat::U16); + let stored = materialcraft_nodes::output_precision::apply(integer, OutputFormat::U16); + assert_eq!((stored.get_gray(0, 0, false) * 65535.0).round(), 55876.0); + + let flat = [("out_low", Value::Float4([0.01341; 4])), ("out_high", Value::Float4([0.01341; 4]))]; + let image = cook("levels", &input, &flat, [1, 1], true); + assert_eq!(image.get_gray(0, 0, false).to_bits(), 0x3c5bb59d); +} + +#[test] +fn integer_levels_bounds_the_four_endpoints_before_applying_gamma() { + let params = [ + ("in_low", Value::Float4([-1.75, -0.625, -0.125, -0.5])), + ("in_mid", Value::Float4([0.469, 0.44, 0.51, 0.25])), + ("in_high", Value::Float4([2.375, 2.75, 1.5, 2.875])), + ("out_low", Value::Float4([-0.5, -1.0, 0.25, 0.125])), + ("out_high", Value::Float4([1.875, 2.25, 1.375, 0.875])), + ("clamp_intermediate", Value::Bool(false)), + ]; + let input = [Some(Image::filled(1, 1, Kind::Color, [0.125; 4]))]; + for (format, max, expected) in [(OutputFormat::U8, 255.0, [64, 88, 81, 158]), (OutputFormat::U16, 65535.0, [16323, 22684, 20789, 40620])] { + let image = cook_format("levels", &input, ¶ms, [1, 1], false, format); + let stored = materialcraft_nodes::output_precision::apply(image, format); + assert_eq!(stored.get(0, 0, false).map(|v| (v * max).round() as u16), expected); + } +} + +#[test] +fn additive_blend_bounds_global_opacity_and_fuses_the_background_weight() { + let inputs = [Some(Image::gray(1, 1, |_, _| 9830.0 / 65535.0)), Some(Image::gray(1, 1, |_, _| 2753.0 / 65535.0))]; + for (opacity, bits) in [(0.55, 0x3dfefcff), (1.3, 0x3e449cc5)] { + let params = [("mode", Value::Enum(1)), ("opacity", Value::Float(opacity))]; + let image = cook("blend", &inputs, ¶ms, [1, 1], false); + assert_eq!(image.get_gray(0, 0, false).to_bits(), bits); + } +} + +#[test] +fn levels_scales_narrow_and_coincident_ranges_independently() { + let pixel = [0xbfd95555, 0xbf9aaaab, 0xbf380000, 0xbe6aaaab].map(f32::from_bits); + let input = Image::filled(1, 1, Kind::Color, pixel); + let params = [ + ("in_low", Value::Float4([0.5; 4])), + ("in_high", Value::Float4([0.5, 0.50000036, 0.49999964, 0.50000477])), + ("out_low", Value::Float4([0.0, 0.125, 0.875, 0.25])), + ("out_high", Value::Float4([1.0, 0.875, 0.125, 0.75])), + ("clamp_intermediate", Value::Bool(false)), + ]; + let output = cook("levels", &[Some(input)], ¶ms, [1, 1], false); + assert_eq!(output.get(0, 0, false).map(f32::to_bits), [0xc6abb656, 0xca5aaaa0, 0xca1bfffb, 0xc795552d]); +} + +#[test] +fn gradient_keeps_the_first_stop_at_a_shared_position() { + let input = Image::gray(1, 1, |_, _| 640.0 / 1023.0); + let keys = vec![ + GradientKey::new(0.125, [0.375, 0.75, 0.875, 0.6875]), + GradientKey::new(0.5, [0.875, 0.0625, 0.3125, 0.25]), + GradientKey::new(0.5, [0.1875, 0.75, 0.25, 0.8125]), + GradientKey::new(0.75, [0.25, 0.5625, 0.75, 0.375]), + ]; + let output = cook("gradient_map", &[Some(input)], &[("gradient", Value::Gradient(Gradient { keys }))], [1, 1], false); + assert_eq!(output.get(0, 0, false).map(f32::to_bits), [0x3f0f9be7, 0x3ea0a028, 0x3f084612, 0x3ea0280a]); +} + +#[test] +fn grayscale_gradient_averages_stops_before_interpolating() { + let input = Image::gray(1, 1, |_, _| 640.0 / 1023.0); + let keys = vec![ + GradientKey::new(0.0625, [0.1875, 0.25, 0.4375, 0.8125]), + GradientKey::new(0.34375, [0.59375, 0.9375, 0.3125, 0.5625]), + GradientKey::new(0.890625, [0.8125, 0.125, 0.75, 0.375]), + ]; + for (mode, bits) in [(0, 0x3f167617), (1, 0x3f165bd5)] { + let params = [("gradient", Value::Gradient(Gradient { keys: keys.clone() })), ("interpolation", Value::Enum(mode)), ("color_mode", Value::Bool(false))]; + let output = cook("gradient_map", &[Some(input.clone())], ¶ms, [1, 1], false); + assert_eq!(output.kind(), Kind::Gray); + assert_eq!(output.get_gray(0, 0, false).to_bits(), bits); + } +} + +#[test] +fn linear_gray_word_gradient_stores_stops_before_interpolation() { + let input = Image::gray(256, 1, |x, _| x as f32 / 255.0); + for (count, columns, expected) in [ + (3, [68, 77, 86, 143, 214, 234], [23502, 25044, 26586, 29657, 11152, 5939]), + (64, [2, 62, 102, 144, 181, 211], [22648, 10313, 21474, 34965, 12604, 63000]), + ] { + let keys = (0..count) + .map(|i| { + let value = ((71 * i + 23 * i * i + 51) % 283) as f32 / 282.0; + GradientKey::new(i as f32 / (count - 1) as f32, [value, value, value, 1.0]) + }) + .collect(); + let params = [("gradient", Value::Gradient(Gradient { keys })), ("color_mode", Value::Bool(false))]; + let output = cook_format("gradient_map", &[Some(input.clone())], ¶ms, [256, 1], false, OutputFormat::U16); + assert_eq!(columns.map(|x| (output.get_gray(x, 0, false) * 65535.0).round() as u32), expected); + } +} + +#[test] +fn gray_word_gradient_interpolates_nearby_stops_in_table_space() { + let input = Image::gray(1, 1, |_, _| 128.0 / 255.0); + let keys = [(0.0, 0.0), (0.5, 1.0), (0.504219, 0.0), (1.0, 1.0)].map(|(position, level)| GradientKey::new(position, [level, level, level, 1.0])).to_vec(); + let params = [("gradient", Value::Gradient(Gradient { keys })), ("color_mode", Value::Bool(false))]; + let output = cook_format("gradient_map", &[Some(input)], ¶ms, [1, 1], false, OutputFormat::U16); + assert_eq!((output.get_gray(0, 0, false) * 65535.0).round() as u32, 35142); +} + +#[test] +fn gradient_filter_preserves_linear_and_biased_smooth_segments() { + let input = Image::gray(1, 1, |_, _| f32::from_bits(0x3e414c15)); + let keys = vec![ + GradientKey::new(0.0625, [0.1875, 0.25, 0.4375, 0.8125]), + GradientKey::new(0.34375, [0.59375, 0.9375, 0.3125, 0.5625]), + GradientKey::new(0.890625, [0.8125, 0.125, 0.75, 0.375]), + ]; + let params = [("gradient", Value::Gradient(Gradient { keys }))]; + let output = cook("gradient_map", &[Some(input)], ¶ms, [1, 1], false); + assert_eq!(output.get(0, 0, false).map(f32::to_bits), [0x3ebd61ca, 0x3f0f03fb, 0x3ec34460, 0x3f334460]); + + let mut gradient = Gradient::default(); + gradient.keys[0].midpoint = 0.625; + let step = Image::gray(1, 1, |_, _| 64.0 / 255.0); + let params = [("gradient", Value::Gradient(gradient)), ("interpolation", Value::Enum(1))]; + let output = cook("gradient_map", &[Some(step)], ¶ms, [1, 1], false); + assert_eq!(output.get(0, 0, false).map(f32::to_bits), [0x3ddce217, 0x3ddce217, 0x3ddce217, 0x3f800000]); +} + #[test] fn shuffle_reads_grayscale_from_every_selected_channel() { let inputs = [Some(Image::filled(3, 5, Kind::Gray, [0.25; 4])), Some(Image::filled(3, 5, Kind::Gray, [0.75; 4]))]; @@ -58,12 +401,27 @@ fn sharpen_preserves_float_order_on_ramps() { let output = cook("sharpen", &[Some(input)], &[("intensity", Value::Float(1.0))], [16, 16], true); - // Float32 ramps distinguish the Laplacian's arithmetic order - for (x, bits) in [(1, 0x3d88_8889), (3, 0x3e4c_cccb), (7, 0x3eee_eeed), (13, 0x3f5d_ddde)] { + for (x, bits) in [(1, 0x3d88_8887), (3, 0x3e4c_cccf), (7, 0x3eee_eef1), (13, 0x3f5d_dddc)] { assert_eq!(output.get_gray(x, 7, false).to_bits(), bits, "column {x}"); } } +#[test] +fn sharpen_accumulates_all_four_weighted_neighbors_in_order() { + let input = Image::gray(16, 16, |x, y| { + f32::from_bits(match (x, y) { + (9, 8) => 0x3d9a_e7d9, + (8, 8) => 0xbf0b_3f1e, + (10, 8) => 0x3f49_f914, + (9, 7) => 0xbfe3_2f70, + (9, 9) => 0x3ff6_8c6b, + _ => 0, + }) + }); + let output = cook("sharpen", &[Some(input)], &[("intensity", Value::Float(0.8125))], [16, 16], true); + assert_eq!(output.get_gray(9, 8, false).to_bits(), 0xba0c_0f80); +} + #[test] fn sharpen_preserves_finite_hdr_constant() { let constant = 2.0e38; @@ -74,6 +432,20 @@ fn sharpen_preserves_finite_hdr_constant() { assert!(output.data().iter().all(|value| value.to_bits() == constant.to_bits())); } +#[test] +fn zero_blur_copies_through_the_output_precision_when_resizing() { + let field = Image::gray(32, 32, |x, y| (((17 * x + 113 * y + 59 * x * y + 19) * 7919) % 65536) as f32 / 65535.0); + let input = [Some(materialcraft_nodes::output_precision::apply(field, OutputFormat::U16))]; + for (intensity, expected) in [(0.0, [145, 139]), (0.0009765625, [146, 140]), (3.2, [146, 140]), (-3.2, [146, 140])] { + let params = [("intensity", Value::Float(intensity))]; + for id in ["blur", "directional_blur"] { + let result = cook_format(id, &input, ¶ms, [8, 8], true, OutputFormat::U8); + let stored = materialcraft_nodes::output_precision::apply(result, OutputFormat::U8); + assert_eq!([2, 5].map(|x| (stored.get_gray(x, 0, false) * 255.0).round() as u8), expected, "{id} intensity {intensity}"); + } + } +} + #[test] fn blur_uses_fractional_box_coverage() { let input = Image::gray(16, 16, |x, y| f32::from(x == 8 && y == 8)); @@ -86,6 +458,375 @@ fn blur_uses_fractional_box_coverage() { } } +#[test] +fn box_blur_stores_the_horizontal_pass_with_unequal_pixel_sizes() { + let input = Image::gray(32, 32, |x, y| { + let code = (131 * x + 367 * y + 29 * x * y + 19375) % 2053; + 1.5 * (code as f32 / 2052.0) - 0.25 + }); + let inputs = [Some(input)]; + let blur = find("blur").unwrap(); + let params = resolve_params(blur, &BTreeMap::from([("intensity".into(), Value::Float(1.0))])); + for (size, expected) in [([1.0, 64.0], [154, 126, 141, 120]), ([64.0, 1.0], [124, 122, 135, 129])] { + let vars = BTreeMap::from([("$pixelsize".into(), Value::Float2(size))]); + let context = CookContext { + w: 32, + h: 32, + seed: 0, + tile: true, + format: OutputFormat::U8, + input_formats: &[OutputFormat::F32], + inputs: &inputs, + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + let image = (blur.cook)(&context).unwrap().remove(0); + let stored = materialcraft_nodes::output_precision::apply(image, OutputFormat::U8); + let codes = [(0, 0), (5, 0), (13, 17), (31, 31)].map(|(x, y)| (stored.get_gray(x, y, false) * 255.0).round() as u32); + assert_eq!(codes, expected, "pixel size {size:?}"); + } +} + +#[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); +} + +fn impulse_and_stripes() -> Image { + Image::generate(128, 128, Kind::Color, |x, y| { + let value = f64::from((97 * x + 43 * y + 7 * x * y) % 1024) / 1023.0; + [f32::from(x == 64 && y == 64), f32::from(x == 64), f32::from(y == 64), (3.0 * value - 1.25) as f32] + }) +} + +#[test] +fn five_texel_blurs_filter_the_outer_pairs_before_accumulating() { + let input = [Some(impulse_and_stripes())]; + let params = [("intensity", Value::Float(4.0))]; + let directional = cook("directional_blur", &input, ¶ms, [128; 2], true); + assert_eq!(directional.get(62, 64, false).map(f32::to_bits), [0x3dff0000, 0x3dff0000, 0x3f800000, 0x3d6739cc]); + let separable = cook("blur", &input, ¶ms, [128; 2], true); + assert_eq!(separable.get(63, 64, false).map(f32::to_bits), [0x3d804000, 0x3e804000, 0x3e800000, 0x3e1e66da]); +} + +#[test] +fn rotated_axial_blurs_project_the_outer_texel_coverage() { + let input = [Some(impulse_and_stripes())]; + for (angle, strength, x, y, expected) in [ + (0.0, 2.0, 63, 64, [0x3e800000, 0x3e800000, 0x3f800000, 0x3e1e6799]), + (0.25, 2.0, 64, 63, [0x3e7fffff, 0x3f800000, 0x3e7fffff, 0x3ea04810]), + (-0.25, 4.0, 64, 64, [0x3e800001, 0x3f800000, 0x3e800001, 0x3e800001]), + (0.75, 10.0, 64, 64, [0x3dccccce, 0x3f800001, 0x3dccccce, 0x3e80e835]), + (0.5, 2.0, 63, 64, [0x3e7fffff, 0x3e7fffff, 0x3f800000, 0x3e1e6796]), + (1.0, 10.0, 64, 64, [0x3dccccce, 0x3dccccce, 0x3f800001, 0x3e80e427]), + ] { + let params = [("intensity", Value::Float(strength)), ("angle", Value::Float(angle))]; + let image = cook("directional_blur", &input, ¶ms, [128; 2], true); + assert_eq!(image.get(x, y, false).map(f32::to_bits), expected, "angle {angle}, strength {strength}"); + } +} + +fn modular_blur_field(size: [u32; 2]) -> Image { + Image::gray(size[0], size[1], |x, y| { + let level = (17 * x + 113 * y + 59 * x * y + 19) % 65536; + ((level * 7919) % 65536) as f32 / 65535.0 + }) + .with_integer_sampling(true) +} + +#[test] +fn short_diagonal_blur_orders_the_taps_in_texture_coordinates() { + let params = [("intensity", Value::Float(2.64)), ("angle", Value::Float(-0.125))]; + for (size, corner, interior) in [([64, 128], 0x3ec0b937, 0x3ebf5a70), ([128, 64], 0x3ed1f3e7, 0x3ebf5a71), ([64, 64], 0x3ee9db4a, 0x3ea1a134)] { + let input = modular_blur_field(size); + let image = cook("directional_blur", &[Some(input)], ¶ms, size, true); + assert_eq!(image.get_gray(1, 0, false).to_bits(), corner, "{size:?}"); + assert_eq!(image.get_gray(6, 4, false).to_bits(), interior, "{size:?}"); + } +} + +#[test] +fn short_oblique_blur_rounds_the_projected_center_and_edge_weights() { + for (size, angle, intensity, point, expected) in [ + ([128, 64], 0.4375, 3.625, [1, 1], 0x3f12_3b30), + ([128, 64], 0.4375, 6.3125, [2, 0], 0x3e8d_258d), + ([128, 64], 0.08203125, 3.625, [1, 1], 0x3f15_f9ba), + ([64, 128], -139.0 / 512.0, 3.625, [1, 0], 0x3e25_ead0), + ] { + let source = Image::gray(size[0], size[1], |x, y| if (x, y) == (1, 1) { 1.0 } else { 0.0 }).with_integer_sampling(true); + let params = [("angle", Value::Float(angle)), ("intensity", Value::Float(intensity))]; + let output = cook("directional_blur", &[Some(source)], ¶ms, size, true); + assert_eq!(output.get_gray(point[0], point[1], false).to_bits(), expected, "{angle}, {intensity}"); + } + + let square = [64; 2]; + let params = [("angle", Value::Float(0.375)), ("intensity", Value::Float(2.64))]; + let output = cook("directional_blur", &[Some(modular_blur_field(square))], ¶ms, square, true); + assert_eq!(output.get_gray(2, 0, false).to_bits(), 0x3eb3_e6a6); +} + +fn rectangular_blur_impulse_weights([width, height]: [u32; 2], angle_bits: u32) -> [u32; 2] { + let definition = find("directional_blur").unwrap(); + let vars = BTreeMap::from([("$pixelratio".into(), Value::Int(0))]); + let values = BTreeMap::from([("angle".into(), Value::Float(f32::from_bits(angle_bits))), ("intensity".into(), Value::Float(4.0))]); + let params = resolve_params(definition, &values); + let inputs = [Some(Image::gray(width, height, |x, y| if (x, y) == (width / 2, height / 2) { 1.0 } else { 0.0 }))]; + let context = CookContext { + w: width, + h: height, + seed: 0, + format: OutputFormat::F32, + tile: true, + input_formats: &[OutputFormat::F32], + inputs: &inputs, + params: ¶ms, + resource: &|_| None, + vars: &vars, + }; + let image = (definition.cook)(&context).unwrap().remove(0); + let (x, y) = (i64::from(width / 2), i64::from(height / 2)); + let neighbor = (x + i64::from(width > height), y + i64::from(height > width)); + [(x, y), neighbor].map(|(x, y)| image.get_gray(x, y, false).to_bits()) +} + +#[test] +fn rectangular_blur_retains_the_small_remainder_of_a_half_turn() { + for (size, angle, expected) in [ + ([16, 64], 0xbf80_1b79, [0x3f7e_a895, 0x3b2b_b5b5]), + ([16, 64], 0x40d0_04e0, [0x3f7f_0bd4, 0x3af4_2d29]), + ([64, 16], 0xc0f8_4350, [0x3f73_6fe3, 0x3cc9_01dc]), + ([64, 16], 0x3e7f_8283, [0x3f7f_3b7d, 0x3ac4_8328]), + ] { + assert_eq!(rectangular_blur_impulse_weights(size, angle), expected, "{size:?} at angle {angle:08x}"); + } +} + +#[test] +fn rectangular_blur_uses_the_authored_angle_beyond_the_slider_range() { + for (size, angle, expected) in [ + ([64, 16], 0xc5f5_64d9, [0x3f0f_4d94, 0x3e61_64db]), + ([16, 64], 0xc892_653f, [0x3f59_9847, 0x3d99_9ee3]), + ([16, 64], 0x46f0_483d, [0x3f17_a518, 0x3e50_b5d1]), + ([64, 16], 0x44c6_eb64, [0x3f1e_4e66, 0x3e43_6334]), + ] { + assert_eq!(rectangular_blur_impulse_weights(size, angle), expected, "{size:?} at angle {angle:08x}"); + } +} + +#[test] +fn diagonal_blur_on_rectangles_carries_the_shear_across_tile_edges() { + let intensity = Value::Float(f32::from_bits(0x416b_a592)); + for (size, angle, expected) in [ + ([128, 64], -0.125, [0x3f0d_c0a6, 0x3ec8_c627, 0x3f04_266e]), + ([64, 128], -0.125, [0x3f09_c0a1, 0x3efd_dda2, 0x3f09_9ad0]), + ([128, 64], 0.125, [0x3eac_69f3, 0x3eab_237d, 0x3ef0_cd20]), + ] { + let controls = [("intensity", intensity.clone()), ("angle", Value::Float(angle))]; + let image = cook("directional_blur", &[Some(modular_blur_field(size))], &controls, size, true); + let [w, h] = size.map(i64::from); + let pixels = [(0, 0), (w - 1, h - 1), (w / 2, h / 2)].map(|(x, y)| image.get_gray(x, y, false).to_bits()); + assert_eq!(pixels, expected, "{size:?}, {angle}"); + } +} + +#[test] +fn oblique_rectangular_blur_projects_the_window_onto_its_filtering_axis() { + for (size, angle, intensity, corners) in [ + ([256, 64], 0.0625, 8.375, [0x3ec6_b8fa, 0x3eda_222a]), + ([64, 128], 0.3125, 14.625, [0x3eec_5a9c, 0x3f09_991f]), + ([64, 128], -139.0 / 512.0, 27.25, [0x3f02_9411, 0x3f11_9cf3]), + ] { + let params = [("intensity", Value::Float(intensity)), ("angle", Value::Float(angle))]; + let image = cook("directional_blur", &[Some(modular_blur_field(size))], ¶ms, size, true); + let [width, height] = size.map(i64::from); + let values = [(0, 0), (width - 1, height - 1)].map(|(x, y)| image.get_gray(x, y, false).to_bits()); + assert_eq!(values, corners, "{size:?}, {angle}"); + } +} + +#[test] +fn long_oblique_blur_keeps_the_projected_stripe_weight() { + for (size, angle, strength, vertical_stripe, expected) in [ + ([16, 128], 0.1, 41.96875, true, 0x3e66_e1d7), + ([16, 128], 0.375, 41.96875, true, 0x3e7f_d802), + ([128, 16], 0.265625, 46.6875, false, 0x3e30_2ae0), + ([128, 16], -139.0 / 512.0, 34.89026, false, 0x3e6c_7382), + ] { + let [width, height] = size; + let stripe = Image::gray(width, height, |x, y| { + let on_line = if vertical_stripe { x == width / 2 } else { y == height / 2 }; + if on_line { 1.0 } else { 0.0 } + }); + let params = [("intensity", Value::Float(strength)), ("angle", Value::Float(angle))]; + let image = cook("directional_blur", &[Some(stripe)], ¶ms, size, true); + assert_eq!(image.get_gray(i64::from(width / 2), i64::from(height / 2), false).to_bits(), expected, "{angle}"); + } +} + +#[test] +fn long_oblique_blur_centers_the_shear_at_texel_precision() { + let impulse = Image::gray(512, 256, |x, y| if (x, y) == (11, 254) { 1.0 } else { 0.0 }).with_integer_sampling(true); + let params = [("intensity", Value::Float(7.8787503)), ("angle", Value::Float(0.0625))]; + let result = cook("directional_blur", &[Some(impulse)], ¶ms, [512, 256], true); + assert_eq!([253, 254, 255].map(|y| result.get_gray(10, y, false).to_bits()), [0x3d0c_9a80, 0x3ce7_57e2, 0x3bbc_f1c9]); +} + +#[test] +fn oblique_blur_combines_the_first_aligned_endpoint_with_its_neighbor() { + for (horizontal, angle, offset, coordinate, expected) in [ + (true, 0.4375, 0, 23, [0x3e1d_9977, 0x3ec0_5e22, 0x3f28_eb7d, 0xbdbf_8da3]), + (false, 0.1875, 11, 32, [0x3e08_bc44, 0x3eb8_9fb2, 0x3f06_7ce4, 0x3dd1_7889]), + ] { + let field = Image::generate(64, 64, Kind::Color, |x, y| { + let i = if horizontal { x } else { y }; + std::array::from_fn(|channel| { + let c = channel as u32; + let level = (37 * i + 19 * i * i + 71 * c + 3 * i * c + offset) % 509; + (level as f32 - 170.0) / 256.0 + }) + }); + let params = [("intensity", Value::Float(6.5793753 * 4.0)), ("angle", Value::Float(angle))]; + let output = cook("directional_blur", &[Some(field)], ¶ms, [64; 2], true); + assert_eq!(output.get(coordinate, coordinate, false).map(f32::to_bits), expected); + } + + let levels = [122_u8, 108, 102, 106, 107, 117, 120, 123, 126, 125, 122, 121, 119]; + let field = Image::gray(256, 256, |x, _| x.checked_sub(155).and_then(|i| levels.get(i as usize)).copied().map_or(0.0, |v| f32::from(v) / 255.0)) + .with_integer_sampling(true); + let params = [("intensity", Value::Float(6.5793753)), ("angle", Value::Float(0.4375))]; + let output = cook_format("directional_blur", &[Some(field)], ¶ms, [256; 2], true, OutputFormat::U8); + assert_eq!(materialcraft_nodes::output_precision::apply(output, OutputFormat::U8).get_gray(161, 11, false), 116.0 / 255.0); +} + +#[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| { + let c = c as u32; + let level = (37 * x + 71 * y + 11 * x * y + 47 * c + 3 * x * c) % 1021; + (3.0 * (f64::from(level) / 1020.0) - 1.125) as f32 + }) + }) +} + +#[test] +fn wide_diagonal_blur_filters_between_two_sheared_grids() { + let input = [Some(impulse_and_stripes())]; + for (strength, angle, x, y, expected) in [ + (4.0, 0.125, 64, 64, [0x3e24087d, 0x3ea4087d, 0x3ea4087d, 0x3e891e8a]), + (4.0, 0.125, 64, 65, [0x3da4087d, 0x3ea4087d, 0x3ea4087d, 0x3e532d50]), + (10.0, 0.125, 63, 65, [0x00000000, 0x3e0b0e3c, 0x3e0b0e3c, 0x3e2adf33]), + (4.75, -0.125, 64, 64, [0x3e0c35e8, 0x3e8c35e8, 0x3e8c35e8, 0x3e66fbdc]), + ] { + let params = [("intensity", Value::Float(strength)), ("angle", Value::Float(angle))]; + let image = cook("directional_blur", &input, ¶ms, [128; 2], true); + assert_eq!(image.get(x, y, false).map(f32::to_bits), expected, "strength {strength}, angle {angle}, ({x},{y})"); + } +} + +#[test] +fn diagonal_blur_stores_the_integer_window_before_resampling() { + let input = [Some(Image::gray(32, 32, |_, y| if y % 8 == 0 { 1.0 / 255.0 } else { 0.0 }))]; + for (format, strength, maximum, expected) in + [(OutputFormat::U8, 19.0, 255.0, [0, 0, 1, 0, 0, 0, 1, 1]), (OutputFormat::U16, 48.0, 65535.0, [30, 30, 30, 30, 52, 30, 30, 30])] + { + let settings = [("intensity", Value::Float(strength)), ("angle", Value::Float(0.125))]; + let image = cook_format("directional_blur", &input, &settings, [32; 2], true, format); + let levels: [u32; 8] = std::array::from_fn(|y| (image.get_gray(0, y as i64, false) * maximum).round() as u32); + assert_eq!(levels, expected, "{format:?}"); + } +} + +#[test] +fn oblique_blur_samples_stored_levels_across_the_tile_seam() { + let input = [Some(impulse_and_stripes())]; + let params = [("intensity", Value::Float(10.75)), ("angle", Value::Float(0.0625))]; + let blurred = cook_format("directional_blur", &input, ¶ms, [128; 2], true, OutputFormat::U8); + let stored = materialcraft_nodes::output_precision::apply(blurred, OutputFormat::U8); + for (x, y, expected) in [(0, 65, [0, 0, 57, 116]), (127, 52, [0, 0, 0, 88]), (64, 64, [17, 26, 61, 99])] { + assert_eq!(stored.get(x, y, false).map(|v| (v * 255.0).round() as u8), expected, "({x}, {y})"); + } +} + +#[test] +fn short_oblique_blur_filters_fractional_taps_and_preserves_the_image_aspect() { + let input = [Some(impulse_and_stripes())]; + for (angle, strength, x, y, expected) in + [(0.125, 2.0, 63, 63, [0x3e5413cc, 0x3e5413cc, 0x3e5413cc, 0x3f7efc72]), (0.0625, 2.5, 65, 64, [0x3e2e41cd, 0x3e94b308, 0x3f426ddf, 0x3de85ee0])] + { + let settings = [("intensity", Value::Float(strength)), ("angle", Value::Float(angle))]; + let image = cook("directional_blur", &input, &settings, [128; 2], true); + assert_eq!(image.get(x, y, false).map(f32::to_bits), expected); + } + + for (size, angle, tile, x, y, expected) in [ + ([128, 64], -0.0625, false, 0, 0, [0xbf87572f, 0xbf6ac022, 0xbf46d1e6, 0xbf22e3aa]), + ([64, 128], 0.03125, true, 63, 0, [0xbeeb11b8, 0x3cb90b12, 0x3f13afa5, 0x3f90cb7a]), + ] { + let input = [Some(signed_modular_field(size[0], size[1]))]; + let settings = [("intensity", Value::Float(4.0)), ("angle", Value::Float(angle))]; + let image = cook("directional_blur", &input, &settings, size, tile); + assert_eq!(image.get(x, y, false).map(f32::to_bits), expected); + } +} + +#[test] +fn wide_blur_reduces_aligned_runs_at_the_destination_precision() { + let input = [Some(signed_modular_field(64, 128))]; + let params = [("intensity", Value::Float(17.5))]; + for (format, expected) in [ + (OutputFormat::U8, [0x3ec0c0c1, 0x3edadadb, 0x3ec8c8c9, 0x3ec2c2c3]), + (OutputFormat::U16, [0x3ec2e0c3, 0x3edb88dc, 0x3ec9f4ca, 0x3ec3f0c4]), + (OutputFormat::F16, [0x3ebbc000, 0x3ed24000, 0x3ec30000, 0x3eb66000]), + (OutputFormat::F32, [0x3ebbdad5, 0x3ed25b4e, 0x3ec322fc, 0x3eb6834f]), + ] { + let output = cook_format("blur", &input, ¶ms, [64, 128], true, format); + assert_eq!(materialcraft_nodes::output_precision::apply(output, format).get(11, 37, false).map(f32::to_bits), expected); + } + let clamped = cook("blur", &input, ¶ms, [64, 128], false); + assert_eq!(clamped.get(0, 1, false).map(f32::to_bits), [0xbf1b2df1, 0xbeeaad75, 0xbe9eff07, 0xbe26a135]); +} + #[test] fn blur_preserves_finite_hdr_constant() { let input = Image::filled(16, 16, Kind::Gray, [1.0e38; 4]); @@ -101,27 +842,54 @@ fn directional_blur_uses_full_radius_and_fractional_endpoints() { let output = cook("directional_blur", &[Some(input)], &[("intensity", Value::Float(4.0))], [256, 256], true); - for offset in -4..=4 { - let expected = if offset == -4 || offset == 4 { 0.0625 } else { 0.125 }; - + for (offset, expected) in (-4..=4).zip([0.0625, 513.0 / 4096.0, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 255.0 / 4096.0]) { assert_eq!(output.get_gray(128 + offset, 128, false), expected, "offset {offset}"); } assert_eq!(output.get_gray(128, 129, false), 0.0); } #[test] -fn sharpen_has_center_gain_and_clamps_negative_lobes() { +fn sharpen_preserves_the_signed_lobes_of_an_impulse_in_float_outputs() { let input = Image::gray(16, 16, |x, y| f32::from(x == 8 && y == 8)); + let inputs = [Some(input)]; + for format in [OutputFormat::F16, OutputFormat::F32] { + let output = cook_format("sharpen", &inputs, &[("intensity", Value::Float(1.0))], [16, 16], true, format); + assert_eq!(output.get_gray(8, 8, false), 5.0); + for (x, y) in [(7, 8), (9, 8), (8, 7), (8, 9)] { + assert_eq!(output.get_gray(x, y, false), -1.0); + } + assert_eq!(output.get_gray(7, 7, false), 0.0); + } +} - let output = cook("sharpen", &[Some(input)], &[("intensity", Value::Float(1.0))], [16, 16], true); +#[test] +fn sharpen_resizes_stored_levels_before_computing_contrast() { + let levels = [58997, 1380, 14934, 23956]; + let input = Image::gray(2, 2, |x, y| levels[(2 * y + x) as usize] as f32 / 65535.0).with_integer_sampling(true); + let output = cook("sharpen", &[Some(input)], &[("intensity", Value::Float(0.0))], [4, 4], true); + for (x, y, bits) in [(0, 0, 0x3f136e93), (3, 0, 0x3e86de87), (0, 3, 0x3ebbd0bc), (3, 3, 0x3e9dfa9e)] { + assert_eq!(output.get_gray(x, y, false).to_bits(), bits); + } +} - assert_eq!(output.get_gray(8, 8, false), 5.0); - assert!(output.data().iter().all(|value| *value >= 0.0)); +#[test] +fn reduced_sharpen_reads_neighbors_one_source_texel_apart() { + let input = [Some(Image::gray(16, 16, |x, y| f32::from(x == 8 && y == 8)))]; + for (size, center, above, left) in [([8, 8], 0.75, -0.25, -0.25), ([8, 16], 1.5, -0.25, -0.5), ([16, 8], 1.5, -0.5, -0.25)] { + let image = cook("sharpen", &input, &[("intensity", Value::Float(1.0))], size, true); + let x = i64::from(size[0] / 2); + let y = i64::from(size[1] / 2); + assert_eq!([image.get_gray(x, y, false), image.get_gray(x, y - 1, false), image.get_gray(x - 1, y, false)], [center, above, left]); + } } #[test] fn empty_raster_preserves_transparent_rgb_and_rejects_mismatched_background_kind() { for id in ["text", "svg"] { + let constant = [("color_mode", Value::Bool(false)), ("background", Value::Color([0.0, 1.0, 0.0, 0.25]))]; + let output = cook(id, &[], &constant, [16, 16], false); + assert_eq!(output.get_gray(0, 0, false), 1.0 / 3.0, "{id} grayscale background"); + let pixel = [0.25, 0.5, 0.75, 0.0]; let color = Some(Image::filled(16, 16, Kind::Color, pixel)); let gray = Some(Image::filled(16, 16, Kind::Gray, [0.25; 4])); diff --git a/crates/nodes/tests/brick_primitives.rs b/crates/nodes/tests/brick_primitives.rs index faa5baf8..d5f0a41b 100644 --- a/crates/nodes/tests/brick_primitives.rs +++ b/crates/nodes/tests/brick_primitives.rs @@ -14,6 +14,7 @@ fn cook(def: &str, mut values: BTreeMap, inputs: &[Option] let params = resolve_params(definition, &values); let context = CookContext { + input_formats: &[], format: materialcraft_core::OutputFormat::F32, w: 64, h: 64, @@ -29,19 +30,95 @@ fn cook(def: &str, mut values: BTreeMap, inputs: &[Option] } #[test] -fn hsl_hue_endpoints_complete_a_full_turn() { +fn hsl_hue_endpoints_and_half_turn_preserve_alpha() { let color = [0.7, 0.3, 0.1, 0.6]; let inputs = [Some(Image::filled(64, 64, Kind::Color, color))]; - for hue in [0.0, 0.5, 1.0] { + for (hue, expected) in [ + (0.0, [0.69990844, 0.29946107, 0.10009158]), + (0.5, [0.69990844, 0.29946128, 0.10009158]), + (1.0, [0.69990844, 0.29946128, 0.10009158]), + (0.75, [0.10009158, 0.5005387, 0.69990844]), + ] { let image = cook("hsl", BTreeMap::from([("hue".into(), Value::Float(hue))]), &inputs); - for (actual, expected) in image.get(0, 0, false).into_iter().zip(color) { - assert!((actual - expected).abs() < 1e-5, "hue {hue}: {actual} != {expected}"); + let pixel = image.get(0, 0, false); + for (actual, expected) in pixel.into_iter().zip(expected) { + assert!((actual - expected).abs() < 1e-6, "hue {hue}: {actual} != {expected}"); } + assert_eq!(pixel[3], color[3]); } +} - let image = cook("hsl", BTreeMap::from([("hue".into(), Value::Float(0.75))]), &inputs); +#[test] +fn hsl_offsets_clamp_in_normalized_lightness_and_restore_hdr_gain() { + let gray = [0.125, 0.125, 0.125, 0.5]; + for (source, slider, value, expected) in [ + (gray, "saturation", 0.75, [0.1875, 0.0625, 0.0625, 0.5]), + (gray, "lightness", 0.75, [0.625, 0.625, 0.625, 0.5]), + ([0.25, 0.5, 0.75, 0.5], "saturation", 0.25, [0.5; 4]), + ([1.7890625, -0.046875, 0.734375, 1.515625], "lightness", 1.0, [1.7890625, 1.7890625, 1.7890625, 1.515625]), + ] { + let inputs = [Some(Image::filled(64, 64, Kind::Color, source))]; + let image = cook("hsl", BTreeMap::from([(slider.into(), Value::Float(value))]), &inputs); + assert_eq!(image.get(0, 0, false), expected); + } +} - assert!((image.get(0, 0, false)[2] - 0.7).abs() < 1e-5); +#[test] +fn hsl_wraps_the_hue_before_reconstructing_rgb() { + let low = 1.0 / 8192.0; + let high = 1.0 - low; + let bias = 3.0 / 4096.0; + for (color, hue, rgb) in [ + ([0.5; 3], 1.0, [1.0, f32::EPSILON, 0.0]), + ([low, high - 0.5 - bias, high], 1.0 / 3.0, [0.5, 1.0, 0.0]), + ([low, high - bias, high], 0.375_f32.next_up(), [0.49999946, 1.0, 0.0]), + ] { + let [r, g, b] = color; + let source = Image::filled(64, 64, Kind::Color, [r, g, b, 0.75]); + let values = BTreeMap::from([("hue".into(), Value::Float(hue)), ("saturation".into(), Value::Float(1.0))]); + let pixel = cook("hsl", values, &[Some(source)]).get(0, 0, false); + assert_eq!(pixel, [rgb[0], rgb[1], rgb[2], 0.75], "hue {hue}"); + } +} + +#[test] +fn hsl_rounds_saturation_after_adding_the_slider_shift() { + let source = Image::filled(16, 16, Kind::Color, [0.6109035, 0.6431967, 0.35680333, 0.75]); + let values = BTreeMap::from([("hue".into(), Value::Float(0.359375)), ("saturation".into(), Value::Float(0.8125))]); + let pixel = cook("hsl", values, &[Some(source)]).get(0, 0, false); + assert_eq!(pixel.map(f32::to_bits), [0x3f74_a640, 0x3d35_9c00, 0x3f12_0e45, 0x3f40_0000]); +} + +#[test] +fn hsl_rounds_the_channel_bias_before_computing_hue() { + for (source, rgb) in [ + ([0x3eff_a001, 0x3eff_a001, 0x3eff_a001, 0x3f80_0000], [0x3f7f_a001, 0x38ff_a001, 0]), + ([0x3ee0_32ed, 0x3f10_f4b6, 0x3ede_1694, 0x3e8a_0000], [0x3d1d_60a0, 0x3f80_0000, 0]), + ([0x3eff_ffff, 0x3eff_ffff, 0x3eff_ffff, 0x3f80_0000], [0x3f7f_ffff, 0, 0x38ff_ffff]), + ([0x3eff_fffd, 0x3eff_fffd, 0x3eff_fffd, 0x3f80_0000], [0x3f7f_fffd, 0x38ff_fffd, 0]), + ([0x3eff_fffc, 0x3eff_ffff, 0x3f00_0001, 0x3ea8_0000], [0x3f7f_ffff, 0x3b1f_dfff, 0]), + ([0x3eff_fff9, 0x3eff_fff6, 0x3eff_fffb, 0x3ebc_0000], [0, 0x3f7f_fff8, 0x3abf_dffa]), + ([0x3eff_ffff, 0x3f00_0001, 0x3eff_fffc, 0x3f31_0000], [0x3b1f_dfff, 0, 0x3f7f_ffff]), + ] { + let inputs = [Some(Image::filled(64, 64, Kind::Color, source.map(f32::from_bits)))]; + let image = cook("hsl", BTreeMap::from([("saturation".into(), Value::Float(1.0))]), &inputs); + assert_eq!(image.get(0, 0, false).map(f32::to_bits), [rgb[0], rgb[1], rgb[2], source[3]]); + } +} + +#[test] +fn hsl_expands_chroma_about_the_adjusted_lightness() { + for (source, [hue, saturation, lightness], rgb) in [ + ([0x3dff_7fff, 0x3dff_7fff, 0x3dff_7fff, 0x3f80_0000], [0.5, 1.0, 0.5], [0x3e7f_8000, 0xb280_0000, 0x36ff_0001]), + ([0x3cff_53d5, 0x3cff_53d5, 0x3cff_53d5, 0x3e44_0000], [0.5625, 0.75, 0.5625], [0x3e6f_dfb9, 0x3e47_e56a, 0x3d9f_ea7a]), + ([0x3e3f_ea73, 0x3e3f_ea76, 0x3e3f_ea6c, 0x3f3f_0000], [0.390625, 0.6875, 0.46875], [0x3d9f_e508, 0x3e2f_e25e, 0x3e12_18d9]), + ] { + let inputs = [Some(Image::filled(64, 64, Kind::Color, source.map(f32::from_bits)))]; + let values = + BTreeMap::from([("hue".into(), Value::Float(hue)), ("saturation".into(), Value::Float(saturation)), ("lightness".into(), Value::Float(lightness))]); + let image = cook("hsl", values, &inputs); + assert_eq!(image.get(0, 0, false).map(f32::to_bits), [rgb[0], rgb[1], rgb[2], source[3]]); + } } #[test] @@ -92,6 +169,43 @@ fn subpixel_quadrants_do_not_accumulate_at_shared_edges() { assert!(image.data().iter().all(|value| (*value - 0.25).abs() < 1e-6), "mean {}", image.mean()[0]); } +#[test] +fn quadrant_offsets_use_canvas_units_at_each_depth() { + for (depth, origin, side) in [(1, [16_i64, 48], 8), (2, [8, 56], 4), (3, [4, 60], 2)] { + for property in ["branchoffset", "frameoffset"] { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + for index in 0..depth { + let child = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[index].children[2] = Some(child); + } + let leaf = &mut graph.nodes[depth].parameters; + leaf.insert("patterntype".into(), Value::Int(2)); + leaf.insert("patternsize".into(), Value::Float2([0.25; 2])); + leaf.insert(property.into(), Value::Float2([0.25, 0.125])); + let image = cook("fx_map", BTreeMap::from([("pattern".into(), Value::PatternGraph(Box::new(graph)))]), &[]); + let [cx, cy] = [origin[0] + 16, (origin[1] + 8) % 64]; + for y in 0..64 { + for x in 0..64 { + let inside = (x - cx + side / 2).rem_euclid(64_i64) < side && (y - cy + side / 2).rem_euclid(64_i64) < side; + assert_eq!(image.get_gray(x, y, false), if inside { 1.0 } else { 0.0 }, "{property} at depth {depth}, ({x},{y})"); + } + } + } + } +} + +#[test] +fn gaussian_stamp_reaches_zero_at_the_edge_of_the_unit_disk() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + graph.nodes[0].parameters.insert("patterntype".into(), Value::Int(6)); + let image = cook("fx_map", BTreeMap::from([("pattern".into(), Value::PatternGraph(Box::new(graph)))]), &[]); + assert_eq!(image.get_gray(0, 0, false), 0.0); + for (x, expected) in [(0, 0.000006), (8, 0.002491), (16, 0.073742), (24, 0.542005), (31, 0.994580)] { + let value = image.get_gray(x, 31, false); + assert!((value - expected).abs() < 1.0e-6, "x={x}, {value} vs {expected}"); + } +} + #[test] fn grayscale_max_patterns_do_not_accumulate_opacity() { let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); diff --git a/crates/nodes/tests/distance.rs b/crates/nodes/tests/distance.rs index 642d6f21..e7f2cfcf 100644 --- a/crates/nodes/tests/distance.rs +++ b/crates/nodes/tests/distance.rs @@ -5,17 +5,62 @@ use materialcraft_core::Value; use materialcraft_nodes::{CookContext, find, resolve_params}; fn cook(mask: Image, source: Option, tile: bool, combine: bool, distance: f32) -> Image { + cook_metric(mask, source, tile, combine, distance, 0) +} + +fn cook_metric(mask: Image, source: Option, tile: bool, combine: bool, distance: f32, metric: u32) -> Image { + let color = source.as_ref().is_some_and(|image| !image.is_gray()); + cook_mode(mask, source, tile, combine, distance, metric, color) +} + +fn cook_mode(mask: Image, source: Option, tile: bool, combine: bool, distance: f32, metric: u32, color: bool) -> Image { + let values = BTreeMap::from([ + ("distance".into(), Value::Float(distance)), + ("combine".into(), Value::Bool(combine)), + ("metric".into(), Value::Enum(metric)), + ("color_mode".into(), Value::Bool(color)), + ]); + cook_with_vars(mask, source, tile, values, BTreeMap::new()) +} + +fn cook_with_vars(mask: Image, source: Option, tile: bool, values: BTreeMap, vars: BTreeMap) -> Image { let def = find("distance").unwrap(); - let params = resolve_params(def, &BTreeMap::from([("distance".into(), Value::Float(distance)), ("combine".into(), Value::Bool(combine))])); + let params = resolve_params(def, &values); let (w, h) = (mask.width(), mask.height()); let inputs = [Some(mask), source]; - let vars = BTreeMap::new(); let resource = |_: &str| None; - let ctx = - CookContext { format: materialcraft_core::OutputFormat::F32, w, h, seed: 0, tile, inputs: &inputs, params: ¶ms, resource: &resource, vars: &vars }; + let ctx = CookContext { + input_formats: &[], + format: materialcraft_core::OutputFormat::F32, + w, + h, + seed: 0, + tile, + inputs: &inputs, + params: ¶ms, + resource: &resource, + vars: &vars, + }; (def.cook)(&ctx).unwrap().remove(0) } +#[test] +fn distance_color_selection_controls_empty_sources_and_channel_mismatches() { + let mask = Image::gray(32, 32, |x, y| if (x, y) == (16, 16) { 1.0 } else { 0.0 }); + let gray = cook(mask.clone(), None, true, true, 31.0); + for combine in [true, false] { + let color = cook_mode(mask.clone(), None, true, combine, 31.0, 0, true); + assert_eq!(color.kind(), Kind::Color); + assert_eq!(color.data(), gray.to_color().data()); + } + for (source_kind, color) in [(Kind::Color, false), (Kind::Gray, true)] { + let source = Image::filled(32, 32, source_kind, [0.75; 4]); + let output = cook_mode(mask.clone(), Some(source), true, true, 31.0, 0, color); + assert_eq!(output.kind(), if color { Kind::Color } else { Kind::Gray }); + assert!(output.data().iter().all(|v| v.to_bits() == 0)); + } +} + #[test] fn tiled_distance_spreads_source_across_stationary_gradient() { let mask = Image::gray(32, 32, |x, y| if x == 0 && y == 0 { 1.0 } else { 0.0 }); @@ -28,27 +73,56 @@ fn tiled_distance_spreads_source_across_stationary_gradient() { #[test] fn distance_spreads_source_beyond_the_old_walk_limit() { - let mask = Image::gray(1024, 1, |x, _| if x == 0 { 1.0 } else { 0.0 }); + let mask = Image::gray(512, 512, |x, y| if x == 0 && y == 0 { 1.0 } else { 0.0 }); let output = cook(mask.clone(), Some(mask), false, false, 256.0); - assert_eq!(output.get_gray(1023, 0, false), 1.0); + assert_eq!(output.get_gray(511, 0, false), 1.0); } #[test] -fn distance_preserves_source_alpha_range_and_combine() { +fn distance_spreads_rgb_and_attenuates_the_alpha_channel() { + let mask = Image::gray(32, 32, |x, y| if x == 16 && y == 16 { 0.5 } else { 0.0 }); + let source = + Image::generate(32, 32, Kind::Color, |x, y| std::array::from_fn(|c| ((13 * x + 7 * y + 5 * x * y + 19 * c as u32) % 127) as f32 / 64.0 - 0.375)); + let output = cook(mask.clone(), Some(source.clone()), true, true, 31.0); + assert_eq!(output.get(17, 16, false).map(f32::to_bits), [0x3f50_0000, 0x3f8e_0000, 0x3fb4_0000, 0xbe55_a8ec]); + assert_eq!(output.get(0, 0, false), [-0.375, -0.078125, 0.21875, 0.0]); + let copy = cook(mask, Some(source.clone()), true, false, 31.0); + assert_eq!(copy.get(17, 16, false), source.get(16, 16, false)); + assert_eq!(copy.get(0, 0, false), source.get(0, 0, false)); +} + +#[test] +fn alternative_distance_metrics_use_the_quantized_site_center() { + let mask = Image::gray(64, 128, |x, y| if (x, y) == (1, 2) { 1.0 } else { 0.0 }); + for (metric, bits) in [(1, 0x3f29_5041u32), (2, 0x3f54_a816)] { + let image = cook_metric(mask.clone(), None, false, true, 47.25, metric); + assert_eq!(image.get_gray(3, 4, false).to_bits(), bits); + } +} + +#[test] +fn distance_keeps_the_current_source_texel_at_the_radius() { + let mask = Image::gray(32, 32, |x, y| if (x, y) == (16, 16) { 1.0 } else { 0.0 }); + let source = Image::gray(32, 32, |x, y| if (x, y) == (16, 16) { 0.8125 } else { -0.109375 }); for tile in [false, true] { - let mask = Image::gray(9, 3, |x, y| if x == 0 && y == 1 { 1.0 } else { 0.0 }); - let source = Image::generate(9, 3, Kind::Color, |x, y| if x == 0 && y == 1 { [0.8, 0.4, 0.2, 0.6] } else { [0.1, 0.1, 0.1, 1.0] }); - for combine in [false, true] { - let output = cook(mask.clone(), Some(source.clone()), tile, combine, 512.0 / 9.0); // two pixels - assert_eq!(output.get(0, 1, false), [0.8, 0.4, 0.2, 0.6]); - let expected = if combine { [0.4, 0.2, 0.1, 0.6] } else { [0.8, 0.4, 0.2, 0.6] }; - assert_eq!(output.get(1, 1, false), expected); - assert_eq!(output.get(4, 1, false), [0.0; 4]); - assert_eq!(output.get(8, 1, false), if tile { expected } else { [0.0; 4] }); + for (combine, expected) in [(false, -0.109375f32), (true, -0.0f32)] { + let image = cook_metric(mask.clone(), Some(source.clone()), tile, combine, 16.0, 1); + assert_eq!(image.get_gray(14, 16, false).to_bits(), expected.to_bits()); + assert_eq!(image.get_gray(16, 16, false), 0.8125); } } } +#[test] +fn zero_distance_and_a_positive_subpixel_distance_have_distinct_site_values() { + let mask = Image::gray(32, 32, |x, y| if (x, y) == (1, 2) { 1.0 } else { 0.0 }); + for (strength, expected) in [(0.0, 0.0), (0.125, 1.0), (f32::MIN_POSITIVE, 1.0)] { + let image = cook(mask.clone(), None, true, true, strength); + assert_eq!(image.get_gray(1, 2, false), expected); + assert_eq!(image.get_gray(2, 2, false), 0.0); + } +} + #[test] fn distance_handles_empty_full_masks_and_no_source() { for tile in [false, true] { @@ -56,15 +130,111 @@ fn distance_handles_empty_full_masks_and_no_source() { let full = Image::filled(7, 5, Kind::Gray, [1.0; 4]); let source = Image::generate(7, 5, Kind::Color, |x, y| [x as f32 / 7.0, y as f32 / 5.0, 0.4, 0.7]); - assert!(cook(empty.clone(), Some(source.clone()), tile, false, 256.0).data().iter().all(|&v| v == 0.0)); + let background = cook(empty.clone(), Some(source.clone()), tile, false, 256.0); + assert_eq!(background.get(3, 2, false), if tile { source.get(3, 2, false) } else { source.get(0, 0, false) }); assert_eq!(cook(full, Some(source), tile, true, 256.0).get(3, 2, false), [3.0 / 7.0, 2.0 / 5.0, 0.4, 0.7]); assert!(cook(empty, None, tile, true, 256.0).data().iter().all(|&v| v == 0.0)); - let mask = Image::gray(7, 5, |x, y| if x == 0 && y == 0 { 1.0 } else { 0.0 }); - let ramp = cook(mask, None, tile, false, 512.0 / 7.0); + let mask = Image::gray(32, 32, |x, y| if (x, y) == (16, 16) { 0.5 } else { 0.499 }); + let ramp = cook(mask, None, tile, false, 16.0); + assert_eq!(ramp.get_gray(16, 16, false), 1.0); + assert_eq!(ramp.get_gray(17, 16, false).to_bits(), 0x3eff_f080); + assert_eq!(ramp.get_gray(19, 16, false), 0.0); + } +} - assert_eq!(ramp.get_gray(0, 0, false), 1.0); - assert_eq!(ramp.get_gray(1, 0, false), 0.5); - assert_eq!(ramp.get_gray(3, 0, false), 0.0); +#[test] +fn mask_distance_uses_stored_site_centers_and_the_shorter_dimension() { + let mask = Image::gray(128, 64, |x, y| if (x, y) == (64, 32) { 1.0 } else { 0.0 }); + let ramp = cook(mask, None, true, true, 256.0 * std::f32::consts::SQRT_2); + for (x, y, bits) in [(65, 32, 0x3f7d_2b39), (64, 33, 0x3f7d_2b93), (65, 33, 0x3f7b_ff42), (63, 32, 0x3f7d_2ca0)] { + assert_eq!(ramp.get_gray(x, y, false).to_bits(), bits); + } +} + +#[test] +fn sparse_mask_distance_preserves_the_sites_selected_during_propagation() { + let mask = Image::gray(128, 128, |x, y| if (13 * x + 23 * y + 11 * x * y) % 109 == 0 { 1.0 } else { 0.0 }); + let ramp = cook(mask, None, true, true, 17.375); + for (x, y, bits) in [(99, 0, 0x3e86_a510), (64, 30, 0x3e26_0066), (39, 55, 0x3e25_ccdc)] { + assert_eq!(ramp.get_gray(x, y, false).to_bits(), bits); + } +} + +fn gray_field(mask: Image, source: Option, tiling: i32, ratio: i32, combine: bool, strength: f32) -> Image { + let values = BTreeMap::from([("distance".into(), Value::Float(strength)), ("combine".into(), Value::Bool(combine))]); + let vars = BTreeMap::from([("$pixelratio".into(), Value::Int(ratio)), ("$tiling".into(), Value::Int(tiling))]); + cook_with_vars(mask, source, true, values, vars) +} + +fn distance_neighbors(w: u32, h: u32, site: [u32; 2], tiling: i32, ratio: i32, strength: f32) -> [u32; 2] { + let mask = Image::gray(w, h, |x, y| if [x, y] == site { 1.0 } else { 0.0 }); + let result = gray_field(mask, None, tiling, ratio, true, strength); + let [x, y] = site.map(i64::from); + [result.get_gray(x + 1, y, false), result.get_gray(x, y + 1, false)].map(f32::to_bits) +} + +#[test] +fn rectangular_distance_uses_the_resolved_pixel_ratio_on_both_axes() { + for (w, h, ratio, strength, expected) in [ + (32, 16, 0, 64.0, [0x3f5f_fe10, 0x3f3f_fe20]), + (32, 16, 1, 64.0, [0x3f3f_fc20, 0x3f3f_fe20]), + (16, 64, 0, 64.0, [0x3f3f_fe20, 0x3f6f_fe08]), + (16, 64, 1, 64.0, [0x3f3f_fe20, 0x3f3f_f820]), + (16, 64, 0, 7.25, [0, 0x3ee5_61a6]), + ] { + assert_eq!(distance_neighbors(w, h, [w / 2, h / 2], 3, ratio, strength), expected, "{w} x {h}, ratio {ratio}, strength {strength}"); + } +} + +#[test] +fn distance_rounds_site_coordinates_once_at_word_precision() { + assert_eq!(distance_neighbors(256, 16, [128, 8], 3, 1, 87.625), [0x3f51_29ff, 0x3f51_3ffa]); + assert_eq!(distance_neighbors(16, 256, [8, 128], 3, 1, 87.625), [0x3f51_3ffa, 0x3f51_29ff]); +} + +#[test] +fn distance_measures_off_center_sites_from_the_image_midpoint() { + for tiling in 0..4 { + let x = if tiling & 1 == 0 { 0x3f68_a0d2 } else { 0x3f68_a0de }; + let y = if tiling & 2 == 0 { 0x3f72_fc9f } else { 0x3f72_fca5 }; + assert_eq!(distance_neighbors(512, 32, [1, 30], tiling, 1, 87.625), [x, 0x3f68_a08c]); + assert_eq!(distance_neighbors(32, 512, [30, 1], tiling, 1, 157.375), [0x3f72_fc78, y]); + } +} + +fn spread_sites(w: u32, h: u32, ratio: i32, sites: &[[u32; 2]]) -> Image { + let mask = Image::gray(w, h, |x, y| if sites.contains(&[x, y]) { 1.0 } else { 0.0 }); + let source = Image::gray(w, h, |x, y| sites.iter().position(|s| *s == [x, y]).map_or(0.0625, |i| (i + 1) as f32 / 8.0)); + gray_field(mask, Some(source), 3, ratio, false, 256.0) +} + +#[test] +fn distance_projects_each_jump_onto_both_image_axes() { + for (w, h, ratio, sites, sample, expected) in [ + (64, 16, 0, &[[60, 2], [14, 13]][..], [28, 5], 0.125), + (32, 16, 1, &[[9, 13], [21, 5], [7, 1]][..], [31, 10], 0.125), + (32, 64, 0, &[[7, 59], [8, 31], [12, 37]][..], [18, 12], 0.375), + ] { + let result = spread_sites(w, h, ratio, sites); + assert_eq!(result.get_gray(sample[0], sample[1], false), expected); + } +} + +#[test] +fn distance_preserves_the_first_neighbor_at_equal_distances() { + let output = spread_sites(32, 32, 0, &[[19, 20], [20, 19], [1, 10]]); + assert_eq!(output.get_gray(12, 12, false), 0.125); + let output = spread_sites(128, 128, 0, &[[56, 64], [63, 71]]); + assert_eq!(output.get_gray(119, 8, false), 0.125); +} + +#[test] +fn distance_resolves_tied_sources_in_axis_pairs_before_diagonals() { + let mask = Image::gray(32, 32, |x, y| if (x % 3 == 0 && y % 3 == 0) || (x + 2 * y) % 7 == 3 { 1.0 } else { 0.0 }); + let source = Image::gray(32, 32, |x, y| (1 + x + 32 * y) as f32 / 1024.0); + for (metric, target, site) in [(1, [30, 8], [29, 8]), (2, [14, 0], [15, 0]), (2, [19, 0], [18, 0])] { + let result = cook_metric(mask.clone(), Some(source.clone()), true, false, 256.0, metric); + assert_eq!(result.get_gray(target[0], target[1], false), source.get_gray(site[0], site[1], false)); } } diff --git a/crates/nodes/tests/fx_map_opacity.rs b/crates/nodes/tests/fx_map_opacity.rs index 75992c71..e84afd09 100644 --- a/crates/nodes/tests/fx_map_opacity.rs +++ b/crates/nodes/tests/fx_map_opacity.rs @@ -12,18 +12,23 @@ fn render(depth: usize, roughness: f32, stack: bool, color: Option<[f32; 4]>) -> node.parameters.insert("patterntype".into(), Value::Int(if stack || index == depth { 2 } else { 0 })); node.parameters.insert("opacity".into(), Value::Float4(color.unwrap_or([1.0; 4]))); } + render_graph(graph, roughness, 0.125, color.is_some()).unwrap().remove(0) +} + +fn render_graph(graph: PatternGraph, roughness: f32, opacity: f32, color: bool) -> materialcraft_nodes::CookResult { let definition = find("fx_map").unwrap(); let params = resolve_params( definition, &BTreeMap::from([ ("pattern".into(), Value::PatternGraph(Box::new(graph))), ("roughness".into(), Value::Float(roughness)), - ("opacity".into(), Value::Float(0.125)), - ("color_mode".into(), Value::Bool(color.is_some())), + ("opacity".into(), Value::Float(opacity)), + ("color_mode".into(), Value::Bool(color)), ("background".into(), Value::Color([0.0; 4])), ]), ); let context = CookContext { + input_formats: &[], format: materialcraft_core::OutputFormat::F32, w: 64, h: 64, @@ -35,7 +40,28 @@ fn render(depth: usize, roughness: f32, stack: bool, color: Option<[f32; 4]>) -> vars: &BTreeMap::new(), }; - (definition.cook)(&context).unwrap().remove(0) + (definition.cook)(&context) +} + +#[test] +fn finite_amplified_stamps_between_samples_do_not_exhaust_the_visit_budget() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate); + let background = graph.add(PatternNodeKind::Quadrant).unwrap(); + let tiny = graph.add(PatternNodeKind::Quadrant).unwrap(); + graph.nodes[0].children = vec![Some(background), Some(tiny)]; + graph.nodes[0].parameters.insert("numberadded".into(), Value::Int(1_048_580)); + graph.nodes[1].parameters = BTreeMap::from([("patterntype".into(), Value::Int(2)), ("opacity".into(), Value::Float(0.25))]); + graph.nodes[2].parameters = BTreeMap::from([("patterntype".into(), Value::Int(2)), ("patternsize".into(), Value::Float2([1.0 / 256.0; 2]))]); + let image = render_graph(graph, 0.6, 2.0, false).unwrap().remove(0); + assert!(image.data().iter().all(|&pixel| pixel == 0.5)); +} + +#[test] +fn a_missed_stamp_still_validates_its_depth_weight() { + let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); + assert!(render_graph(graph.clone(), -1.0, 1.0, false).is_ok()); + graph.nodes[0].parameters = BTreeMap::from([("patterntype".into(), Value::Int(2)), ("patternsize".into(), Value::Float2([1.0 / 256.0; 2]))]); + assert!(render_graph(graph, -1.0, 1.0, false).unwrap_err().contains("roughness must be finite")); } #[test] diff --git a/crates/nodes/tests/fx_map_regions.rs b/crates/nodes/tests/fx_map_regions.rs index 6f2e8dc8..e3e3371a 100644 --- a/crates/nodes/tests/fx_map_regions.rs +++ b/crates/nodes/tests/fx_map_regions.rs @@ -3,28 +3,39 @@ use materialcraft_nodes::{CookContext, find, resolve_params}; use std::collections::BTreeMap; fn render(region: [f32; 4], tiling: [f32; 4], tile: bool) -> materialcraft_nodes::CookResult { + render_stamp(region, tiling, if tile { 3 } else { 0 }, [0.0; 2], [0.5; 2]) +} + +fn render_stamp(region: [f32; 4], tiling: [f32; 4], axes: i32, offset: [f32; 2], size: [f32; 2]) -> materialcraft_nodes::CookResult { + render_culled_stamp(region, tiling, axes, offset, size, false) +} + +fn render_culled_stamp(region: [f32; 4], tiling: [f32; 4], axes: i32, offset: [f32; 2], size: [f32; 2], cull: bool) -> materialcraft_nodes::CookResult { let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant); graph.nodes[0].parameters.insert("patterntype".into(), Value::Int(2)); - graph.nodes[0].parameters.insert("patternsize".into(), Value::Float2([0.5; 2])); + graph.nodes[0].parameters.insert("patternsize".into(), Value::Float2(size)); + graph.nodes[0].parameters.insert("frameoffset".into(), Value::Float2(offset)); let definition = find("fx_map").unwrap(); let params = resolve_params( definition, &BTreeMap::from([ ("pattern".into(), Value::PatternGraph(Box::new(graph))), + ("cull_outside".into(), Value::Bool(cull)), ("render_region".into(), Value::Float4(region)), ("tiling_region".into(), Value::Float4(tiling)), ]), ); (definition.cook)(&CookContext { + input_formats: &[], format: materialcraft_core::OutputFormat::F32, w: 64, h: 64, seed: 0, - tile, + tile: axes == 3, inputs: &[], params: ¶ms, resource: &|_| None, - vars: &BTreeMap::new(), + vars: &BTreeMap::from([("$tiling".into(), Value::Int(axes))]), }) } @@ -39,19 +50,62 @@ fn render_region_samples_a_cropped_area() { } #[test] -fn tiling_region_sets_repeat_distance_independently_of_render_region() { +fn expanding_the_render_window_preserves_the_tiling_region() { let region = [0.0, 2.0, 0.0, 1.0]; let repeated = render(region, [0.0, 1.0, 0.0, 1.0], true).unwrap().remove(0); let wider = render(region, region, true).unwrap().remove(0); let untiled = render(region, [0.0, 1.0, 0.0, 1.0], false).unwrap().remove(0); - assert_eq!(repeated.get(48, 32, false)[0], 1.0); + assert_eq!(repeated.get(48, 32, false)[0], 0.0); assert_eq!(wider.get(48, 32, false)[0], 0.0); assert_eq!(wider.data(), untiled.data()); - assert_eq!(repeated.mean()[0], 0.25); + assert_eq!(repeated.mean()[0], 0.125); assert_eq!(wider.mean()[0], 0.125); } +#[test] +fn wide_tiling_regions_place_and_wrap_stamps_at_the_authored_period() { + for vertical in [false, true] { + let region = if vertical { [-15.5, 16.5, -31.5, 32.5] } else { [-31.5, 32.5, -15.5, 16.5] }; + for (center, size, columns, rows) in + [([26.0, 2.0], [3.0, 4.0], 56..=58, 31..=38), ([-24.0, -3.0], [3.0, 5.0], 6..=8, 20..=29), ([35.0, 4.0], [4.0, 3.0], 1..=4, 36..=41)] + { + let orient = |[x, y]: [f32; 2]| if vertical { [y, x] } else { [x, y] }; + let offset = orient(center).map(|v| v - 0.5); + let image = render_stamp(region, region, 3, offset, orient(size)).unwrap().remove(0); + for y in 0..64 { + for x in 0..64 { + let (column, row) = if vertical { (y, x) } else { (x, y) }; + let expected = if columns.contains(&column) && rows.contains(&row) { 1.0 } else { 0.0 }; + assert_eq!(image.get(x, y, false)[0], expected, "center {center:?}, pixel ({x},{y}), vertical {vertical}"); + } + } + } + } +} + +#[test] +fn a_stamp_repeats_on_each_enabled_axis_inside_the_tiling_region() { + let unit = [0.0, 1.0, 0.0, 1.0]; + for (region, tiling, counts) in [(unit, unit, [27, 324, 72, 864]), ([-0.25, 1.25, 0.0, 1.0], [0.125, 0.875, 0.25, 0.75], [117, 216, 312, 576])] { + for (mask, count) in counts.into_iter().enumerate() { + let image = render_stamp(region, tiling, mask as i32, [-0.734375, -0.546875], [0.5625, 0.375]).unwrap().remove(0); + assert_eq!(image.mean()[0] * 4096.0, count as f32, "tiling mask {mask}"); + } + } +} + +#[test] +fn a_stamp_that_only_touches_the_tiling_interval_contributes_no_copy() { + let render = [0.0, 1.0, 0.0, 1.0]; + let tile = [0.25, 0.75, 0.125, 0.875]; + for (offset, excluded, included) in [([-0.375, 0.375], [8, 56], [40, 56]), ([0.375, -0.375], [56, 8], [24, 8])] { + let image = render_stamp(render, tile, 1, offset, [0.25, 0.5]).unwrap().remove(0); + assert_eq!(image.get(excluded[0], excluded[1], false)[0], 0.0); + assert_eq!(image.get(included[0], included[1], false)[0], 1.0); + } +} + #[test] fn degenerate_regions_and_excessive_repetition_return_errors() { let identity = [0.0, 1.0, 0.0, 1.0]; @@ -60,3 +114,58 @@ fn degenerate_regions_and_excessive_repetition_return_errors() { assert!(render(identity, [0.0; 4], true).is_err()); assert!(render(identity, [0.0, 1e-9, 0.0, 1e-9], true).is_err()); } + +#[test] +fn center_culling_uses_both_original_coordinates_before_repetition() { + let unit = [0.0, 1.0, 0.0, 1.0]; + let region = [0.25, 0.75, 0.125, 0.875]; + for mask in 0..=3 { + for (center, visible) in [ + ([0.25, 0.625], true), + ([0.24902344, 0.625], false), + ([0.75, 0.625], false), + ([0.625, 0.125], true), + ([0.625, 0.875], false), + ([1.0625, 0.4375], false), + ] { + let image = render_culled_stamp(unit, region, mask, center.map(|v| v - 0.5), [0.484375, 0.40625], true).unwrap().remove(0); + assert_eq!(image.mean()[0] > 0.0, visible, "mask {mask}, center {center:?}"); + } + } +} + +#[test] +fn a_pattern_background_filters_stored_levels_and_requires_matching_channels() { + use craft_texture::{Image, Kind}; + use materialcraft_core::OutputFormat; + use materialcraft_nodes::output_precision; + + let definition = find("fx_map").unwrap(); + let field = Image::gray(32, 32, |x, y| (((17 * x + 113 * y + 59 * x * y + 19) * 7919) % 65536) as f32 / 65535.0); + let images = [Some(output_precision::apply(field, OutputFormat::U16))]; + for color in [false, true] { + let params = resolve_params( + definition, + &BTreeMap::from([("color_mode".into(), Value::Bool(color)), ("background".into(), Value::Float4([0.125, 0.375, 0.8125, 0.25]))]), + ); + let ctx = CookContext { + w: 8, + h: 8, + seed: 15709, + format: OutputFormat::U8, + tile: true, + vars: &BTreeMap::new(), + resource: &|_| None, + input_formats: &[OutputFormat::U16], + inputs: &images, + params: ¶ms, + }; + let image = output_precision::apply((definition.cook)(&ctx).unwrap().remove(0), OutputFormat::U8); + if color { + assert_eq!(image.kind(), Kind::Color); + assert!(image.data().iter().all(|&v| v == 0.0)); + } else { + assert_eq!([2, 5].map(|x| (255.0 * image.get_gray(x, 0, false)).round() as u8), [146, 140]); + } + } +} diff --git a/crates/nodes/tests/parity_unconnected.rs b/crates/nodes/tests/parity_unconnected.rs index bb24cb86..444d941f 100644 --- a/crates/nodes/tests/parity_unconnected.rs +++ b/crates/nodes/tests/parity_unconnected.rs @@ -16,7 +16,18 @@ fn absent_textures_have_zero_pixels_and_expected_kinds() { let resource = |_: &str| None; let vars = BTreeMap::new(); for (w, h) in [(16, 16), (32, 16), (3, 5)] { - let context = CookContext { w, h, seed: 0, format: OutputFormat::F32, tile: true, inputs: &[], params: ¶ms, resource: &resource, vars: &vars }; + let context = CookContext { + input_formats: &[], + w, + h, + seed: 0, + format: OutputFormat::F32, + tile: true, + inputs: &[], + params: ¶ms, + resource: &resource, + vars: &vars, + }; let outputs = (definition.cook)(&context).unwrap(); let image = outputs.first().unwrap(); diff --git a/crates/ui-egui/src/cook.rs b/crates/ui-egui/src/cook.rs index edea4311..94b3f43c 100644 --- a/crates/ui-egui/src/cook.rs +++ b/crates/ui-egui/src/cook.rs @@ -40,6 +40,7 @@ fn report_failure(app: &mut MaterialCraftApp, msg: String) { base_values: Default::default(), parameters: Default::default(), outputs: Default::default(), + output_bases: None, error: Some(msg.clone()), ms: 0.0, key: 0, @@ -180,6 +181,7 @@ fn start(app: &mut MaterialCraftApp, now: f64) { let (gi, max) = (s.graph, s.preview_size); let environment = s.environment; let materials = s.material_preview.graphs(); + let sampling = s.preview_sampling(); let cache = s.cache.clone(); let epoch = s.cook_epoch; let dec = s.resource_decoder(); @@ -192,7 +194,7 @@ fn start(app: &mut MaterialCraftApp, now: f64) { opts.environment = environment; opts.max_size = max; opts.cancel = Some(&thread_flag); - let cooked = guard("cook", || Ok(PreviewCook::run(&pkg, gi, &materials, &opts, &cache))); + let cooked = guard("cook", || Ok(PreviewCook::with_previous(&pkg, gi, &materials, &opts, &cache, &sampling))); let _ = tx.send(cooked); }); match spawned { diff --git a/crates/ui-egui/src/graph/toolbar.rs b/crates/ui-egui/src/graph/toolbar.rs index 9e12c7bb..8dede632 100644 --- a/crates/ui-egui/src/graph/toolbar.rs +++ b/crates/ui-egui/src/graph/toolbar.rs @@ -2,6 +2,7 @@ use super::navigation::{add_node_near_selection, view_center}; use crate::{MaterialCraftApp, i18n::tr, theme::Tokens}; use egui::Ui; use egui_phosphor::regular as icon; +use materialcraft_engine::core::{MAX_SIZE_LOG2, MIN_SIZE_LOG2}; use serde_json::json; pub(super) fn show(app: &mut MaterialCraftApp, ui: &mut Ui) { @@ -195,8 +196,8 @@ fn parent_size(app: &mut MaterialCraftApp, ui: &mut Ui) { let mut nw = w; let mut nh = h; let combo = |ui: &mut Ui, id: &str, v: &mut u32| { - let r = egui::ComboBox::from_id_salt(id).width(64.0).selected_text(format!("{}", 1u32 << *v)).show_ui(ui, |ui| { - for l in 4..=13u32 { + let r = egui::ComboBox::from_id_salt(id).width(64.0).selected_text(format!("{}", 1u32 << (*v).min(MAX_SIZE_LOG2))).show_ui(ui, |ui| { + for l in MIN_SIZE_LOG2..=MAX_SIZE_LOG2 { ui.selectable_value(v, l, format!("{}", 1u32 << l)); } }); diff --git a/crates/ui-egui/src/graph_previews.rs b/crates/ui-egui/src/graph_previews.rs index 1be71bb7..1450cbaf 100644 --- a/crates/ui-egui/src/graph_previews.rs +++ b/crates/ui-egui/src/graph_previews.rs @@ -142,7 +142,7 @@ impl GraphPreviews { GraphPreviewKey::Native(id) => super::render_native(id), GraphPreviewKey::Graph(package, graph) => { NodeLibrary::preview_cancellable(&thread_library, package, graph, LIBRARY_PREVIEW_SIZE, &thread_cancel) - .map(|image| image.resize(LIBRARY_PREVIEW_SIZE, LIBRARY_PREVIEW_SIZE, true).to_rgba8_display()) + .map(|image| crate::graph_pixels::rgba8(&image.resize(LIBRARY_PREVIEW_SIZE, LIBRARY_PREVIEW_SIZE, true), true)) } } }; diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 12a7d296..9cc1721f 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -13,6 +13,7 @@ pub mod framework; pub mod function; pub mod graph; mod graph_drag_payload; +use materialcraft_engine::graph_pixels; mod help_links; mod history; mod home_screen; diff --git a/crates/ui-egui/src/pattern/parameter_value.rs b/crates/ui-egui/src/pattern/parameter_value.rs index a9355590..bf295fa1 100644 --- a/crates/ui-egui/src/pattern/parameter_value.rs +++ b/crates/ui-egui/src/pattern/parameter_value.rs @@ -25,7 +25,7 @@ pub(super) fn show(ui: &mut Ui, name: &str, value: &mut Value) -> bool { (18, "Offset gradation"), ], "blendingmode" => &[(0, "Add"), (1, "Blend"), (2, "Max")], - "imagefiltering" => &[(0, "Nearest"), (1, "Bilinear")], + "imagefiltering" => &[(0, "Bilinear with mipmaps"), (1, "Bilinear"), (2, "Nearest")], _ => return crate::value_editor::show(ui, value), }; diff --git a/crates/ui-egui/src/preview_disk_cache.test.rs b/crates/ui-egui/src/preview_disk_cache.test.rs index fbfbc5ef..d7b206f7 100644 --- a/crates/ui-egui/src/preview_disk_cache.test.rs +++ b/crates/ui-egui/src/preview_disk_cache.test.rs @@ -65,7 +65,7 @@ fn real_library_previews_survive_relaunch() { assert_eq!(phase, "cold", "warm launch must load {graph} without cooking"); materialcraft_engine::NodeLibrary::preview_cancellable(&library, package, graph, 72, &cancel) - .map(|image| image.resize(72, 72, true).to_rgba8_display()) + .map(|image| crate::graph_pixels::rgba8(&image.resize(72, 72, true), true)) }); assert_eq!(image.unwrap().len(), 72 * 72 * 4); diff --git a/crates/ui-egui/src/property/graph.rs b/crates/ui-egui/src/property/graph.rs index a417baf8..1859fe33 100644 --- a/crates/ui-egui/src/property/graph.rs +++ b/crates/ui-egui/src/property/graph.rs @@ -2,7 +2,7 @@ use super::{input::input_editor, section}; use crate::{MaterialCraftApp, i18n::tr, theme::Tokens}; use egui::{RichText, Ui}; use egui_phosphor::regular as icon; -use materialcraft_engine::core::{Graph, OutputFormat, Resource, Value}; +use materialcraft_engine::core::{Graph, MAX_SIZE_LOG2, MIN_SIZE_LOG2, OutputFormat, Resource, Value}; use serde_json::{Value as JsonValue, json}; pub(super) fn show(app: &mut MaterialCraftApp, ui: &mut Ui, target: materialcraft_engine::GraphTarget) { @@ -29,8 +29,10 @@ fn show_target(app: &mut MaterialCraftApp, ui: &mut Ui, target: materialcraft_en section(ui, "graph-base", tr("Base parameters"), |ui| { for (axis, label) in [(0usize, "Width"), (1, "Height")] { - let mut value = graph.size[axis] as f32; - if crate::widgets::slider(ui, &format!("{} {} px", tr(label), 1u32 << graph.size[axis]), &mut value, 4.0..=13.0, 0).changed() { + let exponent = graph.size[axis].min(MAX_SIZE_LOG2); + let mut value = exponent as f32; + let range = MIN_SIZE_LOG2 as f32..=MAX_SIZE_LOG2 as f32; + if crate::widgets::slider(ui, &format!("{} {} px", tr(label), 1u32 << exponent), &mut value, range, 0).changed() { let mut edited = graph.size; edited[axis] = value.round() as u32; emit("graph.size", json!({"log2": edited})); @@ -43,10 +45,17 @@ fn show_target(app: &mut MaterialCraftApp, ui: &mut Ui, target: materialcraft_en } } }); - let mut seed = graph.seed as f32; - if crate::widgets::slider(ui, tr("Random seed"), &mut seed, 0.0..=1000.0, 0).changed() { - emit("graph.seed", json!({"seed": seed.round() as i64})); - } + ui.horizontal(|ui| { + if let Some(mode) = super::parameter_control::inheritance_menu(ui, tr("Random seed"), graph.seed_mode) { + emit("graph.seed", json!({"inheritance": mode})); + } + ui.vertical(|ui| { + let mut seed = graph.seed as f32; + if crate::widgets::slider(ui, tr("Random seed"), &mut seed, 0.0..=1000.0, 0).changed() { + emit("graph.seed", json!({"seed": seed.round() as i64})); + } + }); + }); }); if target != materialcraft_engine::GraphTarget::active(&app.session) { for (id, parameters) in commands { diff --git a/crates/ui-egui/src/property/node.rs b/crates/ui-egui/src/property/node.rs index 0e37eccb..1a346402 100644 --- a/crates/ui-egui/src/property/node.rs +++ b/crates/ui-egui/src/property/node.rs @@ -99,6 +99,7 @@ fn base_params(app: &mut MaterialCraftApp, ui: &mut Ui, node: &materialcraft_eng let value = if descriptor.options.is_empty() { value } else { Value::Enum(value.as_i32().unwrap_or(0).max(0) as u32) }; let input = ExposedParameter { + connectable: false, description: String::new(), editor: None, clamp: false, diff --git a/crates/ui-egui/src/property/parameter.rs b/crates/ui-egui/src/property/parameter.rs index b1d12457..82c1a547 100644 --- a/crates/ui-egui/src/property/parameter.rs +++ b/crates/ui-egui/src/property/parameter.rs @@ -125,7 +125,7 @@ pub(super) fn param_row(app: &mut MaterialCraftApp, ui: &mut Ui, node: NodeId, p Value::Curve(curve) => { ui.label(RichText::new(tr(parameter.label)).color(tokens.text)); if let Some(edited_curve) = curve_editor(ui, &format!("curve-{}-{}", node.0, parameter.id), &curve) { - set(app, node, parameter.id, json!(edited_curve.points.iter().map(|point| [point.x, point.y]).collect::>())); + set(app, node, parameter.id, typed(&Value::Curve(edited_curve))); } } Value::Gradient(gradient) => { diff --git a/crates/ui-egui/src/property/parameter_control.rs b/crates/ui-egui/src/property/parameter_control.rs index 2efbb658..36e6492a 100644 --- a/crates/ui-egui/src/property/parameter_control.rs +++ b/crates/ui-egui/src/property/parameter_control.rs @@ -133,7 +133,12 @@ fn edit(app: &mut MaterialCraftApp, node: &Node, descriptor: &ParameterDescripto } fn inheritance(app: &mut MaterialCraftApp, ui: &mut Ui, node: &Node, parameter: BaseParameter) { - let current = parameter.inheritance(&node.base); + if let Some(mode) = inheritance_menu(ui, parameter.label(), parameter.inheritance(&node.base)) { + app.run("graph.node.base", json!({"id": node.id, "param": parameter.identifier(), "inheritance": mode})); + } +} + +pub(super) fn inheritance_menu(ui: &mut Ui, parameter_label: &str, current: ParameterInheritance) -> Option { let modes = [ (ParameterInheritance::RelativeToInput, "Relative to input"), (ParameterInheritance::RelativeToParent, "Relative to parent"), @@ -145,14 +150,16 @@ fn inheritance(app: &mut MaterialCraftApp, ui: &mut Ui, node: &Node, parameter: ParameterInheritance::RelativeToParent => icon::TREE_STRUCTURE, ParameterInheritance::Absolute => icon::EQUALS, }; + let mut selected = None; let menu = ui.menu_button(symbol, |ui| { for (mode, label) in modes { if ui.selectable_label(mode == current, tr(label)).clicked() { - app.run("graph.node.base", json!({"id": node.id, "param": parameter.identifier(), "inheritance": mode})); + selected = Some(mode); ui.close(); } } }); - crate::widgets::name(&menu.response, egui::Role::Button, &format!("{} inheritance: {label}", parameter.label())); + crate::widgets::name(&menu.response, egui::Role::Button, &format!("{parameter_label} inheritance: {label}")); menu.response.on_hover_text(tr(label)); + selected } diff --git a/crates/ui-egui/src/thumbs.rs b/crates/ui-egui/src/thumbs.rs index c14900ab..c66cb291 100644 --- a/crates/ui-egui/src/thumbs.rs +++ b/crates/ui-egui/src/thumbs.rs @@ -24,10 +24,10 @@ pub struct Thumbs { frame: u64, } -/// An image as an egui texture image (sRGB display, `side` px) +/// A cooked graph image as an egui thumbnail, in its stored display space. pub fn color_image(img: &Image, side: u32) -> ColorImage { let small = img.resize(side, side, true); - ColorImage::from_rgba_unmultiplied([side as usize, side as usize], &small.to_rgba8_display()) + ColorImage::from_rgba_unmultiplied([side as usize, side as usize], &crate::graph_pixels::rgba8(&small, true)) } #[path = "graph_previews.rs"] @@ -157,6 +157,7 @@ fn render_native(id: &str) -> Option> { let params = resolve_params(def, &BTreeMap::new()); let ctx = CookContext { + input_formats: &[], format: materialcraft_engine::core::OutputFormat::U16, w: LIBRARY_PREVIEW_SIZE, h: LIBRARY_PREVIEW_SIZE, @@ -169,5 +170,5 @@ fn render_native(id: &str) -> Option> { }; let images = (def.cook)(&ctx).ok()?; - Some(images.first()?.resize(LIBRARY_PREVIEW_SIZE, LIBRARY_PREVIEW_SIZE, true).to_rgba8_display()) + Some(crate::graph_pixels::rgba8(&images.first()?.resize(LIBRARY_PREVIEW_SIZE, LIBRARY_PREVIEW_SIZE, true), true)) } diff --git a/crates/ui-egui/src/view2d/display.rs b/crates/ui-egui/src/view2d/display.rs index e813a942..e988906b 100644 --- a/crates/ui-egui/src/view2d/display.rs +++ b/crates/ui-egui/src/view2d/display.rs @@ -1,21 +1,12 @@ //! The 8-bit pixels the 2D view draws for an image use materialcraft_engine::View2d; -use materialcraft_engine::image::{Image, Kind, linear_to_srgb}; +use materialcraft_engine::image::{Image, Kind}; /// 8-bit RGBA of `image` as the view's settings show it: the chosen channel, and brighter when /// the values are read as linear light pub(super) fn display_pixels(image: &Image, view: &View2d) -> Vec { - let mut pixels = image.to_rgba8_display(); - - if !view.srgb { - let encoded = encoded_levels(); - for pixel in pixels.as_chunks_mut::<4>().0 { - for value in pixel.iter_mut().take(3) { - *value = encoded[usize::from(*value)]; - } - } - } + let mut pixels = crate::graph_pixels::rgba8(image, view.srgb); let Some(channel) = isolated_channel(&view.channel).filter(|_| image.kind() == Kind::Color) else { return pixels }; @@ -37,15 +28,6 @@ pub(super) fn isolated_channel(channel: &str) -> Option { } } -/// Every 8-bit level read as linear light and encoded for the screen -fn encoded_levels() -> [u8; 256] { - let mut levels = [0; 256]; - for (level, encoded) in levels.iter_mut().enumerate() { - *encoded = (linear_to_srgb(level as f32 / 255.0).clamp(0.0, 1.0) * 255.0 + 0.5) as u8; - } - levels -} - #[cfg(test)] mod tests { use super::*; @@ -54,6 +36,12 @@ mod tests { Image::filled(2, 1, Kind::Color, [0.2, 0.4, 0.6, 0.5]) } + #[test] + fn encoded_graph_colors_keep_their_stored_levels_in_the_preview() { + let image = Image::filled(1, 1, Kind::Color, [0.2, 0.4, 0.8, 1.0]); + assert_eq!(display_pixels(&image, &View2d::default()), [51, 102, 204, 255]); + } + #[test] fn a_single_channel_is_shown_as_opaque_gray() { let all = display_pixels(&color(), &View2d::default()); diff --git a/crates/ui-egui/src/view2d/pixel_readout.rs b/crates/ui-egui/src/view2d/pixel_readout.rs index 6c2b191a..f85ec501 100644 --- a/crates/ui-egui/src/view2d/pixel_readout.rs +++ b/crates/ui-egui/src/view2d/pixel_readout.rs @@ -1,6 +1,8 @@ use egui::Color32; use materialcraft_engine::View2d; -use materialcraft_engine::image::{Image, linear_to_srgb}; +use materialcraft_engine::image::Image; + +use crate::graph_pixels::{display_byte, stored_byte}; /// The hue is listed in degrees around the color wheel const HUE_DEGREES: f32 = 360.0; @@ -39,14 +41,10 @@ impl PixelReadout { /// The opaque sample with the view's display encoding and channel choice pub(super) fn swatch(&self, view: &View2d) -> Color32 { - let level = |value: f32| (value.clamp(0.0, 1.0) * 255.0 + 0.5) as u8; - let shown = |value: f32| if self.gray { level(value) } else { level(linear_to_srgb(value)) }; - let mut rgb = [shown(self.color[0]), shown(self.color[1]), shown(self.color[2])]; - if !view.srgb { - rgb = rgb.map(|value| level(linear_to_srgb(f32::from(value) / 255.0))); - } + let [r, g, b, a] = self.color; + let mut rgb = [r, g, b].map(|value| display_byte(value, view.srgb)); if let Some(channel) = super::display::isolated_channel(&view.channel).filter(|_| !self.gray) { - let value = if channel == 3 { level(self.color[3]) } else { rgb[channel] }; + let value = if channel == 3 { stored_byte(a) } else { rgb[channel] }; rgb = [value; 3]; } Color32::from_rgb(rgb[0], rgb[1], rgb[2]) @@ -135,7 +133,7 @@ mod tests { assert_eq!(PixelReadout::at(&gray, [0, 0]).swatch(&View2d::default()), Color32::from_rgb(128, 128, 128)); let color = Image::filled(1, 1, Kind::Color, [0.5, 0.0, 1.0, 1.0]); - assert_eq!(PixelReadout::at(&color, [0, 0]).swatch(&View2d::default()), Color32::from_rgb(188, 0, 255)); + assert_eq!(PixelReadout::at(&color, [0, 0]).swatch(&View2d::default()), Color32::from_rgb(128, 0, 255)); } #[test] diff --git a/crates/ui-egui/tests/snapshot/graph_items.rs b/crates/ui-egui/tests/snapshot/graph_items.rs index a4005524..06048276 100644 --- a/crates/ui-egui/tests/snapshot/graph_items.rs +++ b/crates/ui-egui/tests/snapshot/graph_items.rs @@ -2,6 +2,45 @@ use super::{By, MaterialCraftApp, Queryable, UiState, harness, save, settle}; use egui::{Event, Key, Modifiers, PointerButton, accesskit::Role, vec2}; use serde_json::json; +#[test] +#[ignore = "requires an offscreen GPU; run explicitly with --ignored"] +fn toolbar_can_select_small_rectangular_parents() { + let app = MaterialCraftApp::headless(materialcraft_engine::new_session(), UiState::default()); + let mut harness = harness(app, 1600.0, 960.0); + settle(&mut harness, 4); + for (axis, pixels) in [("Parent width", "1"), ("Parent height", "8")] { + harness.get(By::new().role(Role::ComboBox).label(axis)).click(); + settle(&mut harness, 2); + harness.get_by_label(pixels).click(); + settle(&mut harness, 3); + } + assert_eq!(harness.state().session.graph().unwrap().size_px(), [1, 8]); + if let Some(directory) = std::env::var_os("MC_SNAPSHOT_DIR").map(std::path::PathBuf::from) { + std::fs::create_dir_all(&directory).unwrap(); + save(&mut harness, &directory, "small-rectangular-parent"); + } +} + +#[test] +#[ignore = "requires an offscreen GPU; run explicitly with --ignored"] +fn graph_properties_can_change_seed_inheritance() { + let app = MaterialCraftApp::headless(materialcraft_engine::new_session(), UiState::default()); + let mut harness = harness(app, 1600.0, 960.0); + settle(&mut harness, 4); + harness.get(By::new().role(Role::Button).label("Random seed inheritance: Relative to input")).click(); + settle(&mut harness, 2); + harness.get(By::new().role(Role::Button).label("Absolute")).click(); + settle(&mut harness, 3); + assert_eq!(harness.state().session.graph().unwrap().seed_mode, materialcraft_engine::core::ParameterInheritance::Absolute); + harness.get(By::new().role(Role::Slider).label("Random seed")).click(); + settle(&mut harness, 3); + assert!((450..=550).contains(&harness.state().session.graph().unwrap().seed)); + if let Some(directory) = std::env::var_os("MC_SNAPSHOT_DIR").map(std::path::PathBuf::from) { + std::fs::create_dir_all(&directory).unwrap(); + save(&mut harness, &directory, "graph-seed-inheritance"); + } +} + /// A Library pin can be dropped, renamed, reselected and deleted on every canvas. #[test] #[ignore = "requires an offscreen GPU; run explicitly with --ignored"] diff --git a/crates/ui-egui/tests/snapshot/view2d.rs b/crates/ui-egui/tests/snapshot/view2d.rs index f72e2e8d..7a8238a3 100644 --- a/crates/ui-egui/tests/snapshot/view2d.rs +++ b/crates/ui-egui/tests/snapshot/view2d.rs @@ -23,6 +23,21 @@ fn save(harness: &mut Harness<'static, MaterialCraftApp>, name: &str) { harness.render().unwrap().save(directory.join(format!("{name}.png"))).unwrap(); } +#[test] +#[ignore = "requires an offscreen GPU; run explicitly with --ignored"] +fn the_2d_view_displays_stored_graph_colors() { + let mut app = MaterialCraftApp::headless(materialcraft_engine::sample_session(), UiState::default()); + app.session.preview_size = Some(64); + let color = app.run("graph.node.add", json!({"def": "uniform", "params": {"color": [0.2, 0.4, 0.8, 1.0]}})).unwrap()["id"].as_u64().unwrap(); + app.run("view.2d", json!({"node": color})).unwrap(); + app.session.cook(); + let mut harness = view(app); + harness.run_steps(4); + let image = harness.render().unwrap(); + assert_eq!(image.get_pixel(image.width() / 2, image.height() / 2).0, [51, 102, 204, 255]); + save(&mut harness, "view2d-encoded-color"); +} + #[test] #[ignore = "requires an offscreen GPU; run explicitly with --ignored"] fn the_2d_view_shows_its_settings() { diff --git a/docs/architecture.md b/docs/architecture.md index 3678a59c..9fb81493 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -128,8 +128,9 @@ face for native and web builds. Font binaries stay in craft-fonts. Set `CRAFT_FO for releases to fail on an unavailable fallback. Without the optional input, builds still work; a missing font produces a repairable resource and a load warning. A checkout with the Latin catalog is required (for example craft-fonts revision `c1db6d1a8ed772191241c3d185e2104be84d8691`). -All bundled `.sbs` packages, including nested materials, are original clean-room recreations -covered together in [ATTRIBUTION.md](../ATTRIBUTION.md); their other resources retain separate credits. +The [asset attribution](../ATTRIBUTION.md) credits the bundled `.sbs` packages, including nested +materials, to the ArtCraft Team and the MaterialCraft contributors. It records the maintainer's +authorship confirmation for the collection and credits the accompanying resources separately. Bitmap/SVG references into another package import only the requested resource declarations, resolving asset paths beside that owner. These become local resource snapshots with distinct names on collisions; saving retains shared asset links inside the library or carries their bytes @@ -229,9 +230,10 @@ cannot compile instead of substituting empty graphs. The source graph bodies are rewritten metadata does not establish redistribution rights. Local tests compare every converted body and evaluate all 171 functions against the supplied package with valid inputs and caller context. External runtime import and numerical compatibility -still require validation. The first SBS save writes the workspace's Cargo version to both -`formatVersion` and `updaterVersion`. The package model retains the baseline `formatVersion` -when reopening a document; later saves refresh only `updaterVersion`. +still require validation. New SBS files use schema revision `1.1.0.202401`. Saving a package +with a three-part numeric app release in `formatVersion` writes that schema revision too. +Other imported format headers carry through subsequent saves. `updaterVersion` records the +workspace release that wrote the file. Every user-visible action is a `CommandSpec` (`engine/src/*_cmds.rs`): id, label, menu, shortcut, params doc, `enabled`, `run`. The UI calls them through `MaterialCraftApp::run`; the CLI, the JSON diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 7145ad12..b91b9fe6 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -23,9 +23,10 @@ Agents drive MaterialCraft three ways, all dispatching the same engine commands: engine-command authority, including host file access. Set `MATERIALCRAFT_NO_PREFS=1` for scripted runs so the user's layout is left alone. -The first SBS save sets `formatVersion` and `updaterVersion` to MaterialCraft's workspace release -version. Later saves preserve the document's original `formatVersion` and refresh `updaterVersion` -to the saving application's release version. Save As and archive packaging retain that baseline too. +SBS saves, Save As and archive packaging use `formatVersion` to declare the file schema and +`updaterVersion` to record MaterialCraft's workspace release. New files and earlier files with +a three-part numeric release header use schema `1.1.0.202401`. Other imported format revisions +carry through subsequent saves. ## Methods @@ -89,7 +90,7 @@ Types: `move`, `down`, `up`, `click`, `doubleClick`, `drag`, `scroll`, `key` (eg | `graph.function.variables` | `{id, target?: FunctionGraphTarget}` returns ordered suggestions matching a Get node's type and caller scope; typed custom names remain supported | | `session.environment` | `{timeSeconds?, uvTile?: [int, int], normalFormat?: int}` updates host evaluation values without modifying the package; `{}` reads them; defaults are zero and the normal-format code is passed through | | `graph.context` | `{physicalSize?: [x, y, z], pixelRatio?: 0\|1, tiling?: [horizontal, vertical]}` edits material-graph metadata with undo; `{}` reads it; reusable functions receive their caller's context | -| `file.new` | `{template?, name?, folder?, kind?, size?, height?, document?, newPackage?}`. Use `graph.templates` for the supported material templates. `size` is the width in pixels and `height` defaults to it (powers of two, 16 to 8192). `document` selects an open package. `newPackage: true` creates a new untitled package and cannot be combined with `document` or a nonempty `folder` | +| `file.new` | `{template?, name?, folder?, kind?, size?, height?, document?, newPackage?}`. Use `graph.templates` for the supported material templates. `size` is the width in pixels and `height` defaults to it (powers of two, 1 to 8192). `document` selects an open package. `newPackage: true` creates a new untitled package and cannot be combined with `document` or a nonempty `folder` | | `graph.node.edit` | `{}` resolves the selected FX-Map, processor or graph instance to `{kind, node, parameter?, graph?, document?, path?}`; use `ui.menu.invoke` to open its reference in the graph panel | | `graph.node.info` | `{id}` returns `{text}` describing a main-graph node without changing the document or node clipboard | | `graph.instance.add` | `{document, graph, function?: FunctionGraphTarget, at?, snapToGrid?}` adds a linked graph instance from an open package; requires a source output and rejects dependency cycles | @@ -364,7 +365,7 @@ materialcraft-cli export Oak.mcmat build/oak --profile materialx --size 2048 \ The ZIP contains a version marker (`material.json` with `{"version":3}`), a DEFLATE-compressed `source.sbs`, and the source assets its graphs reference under `resources/`. The sole graph at the root of the SBS document is the entry. Reachable helper graphs and functions have local paths under `Dependencies/`. Republish v1 and v2 archives from the original authoring project. -`info` reads the entry's path, dimensions, supported resolutions, typed defaults, saved values, presets, image inputs and output usages. A cook starts from the saved values, applies the named preset, then applies each explicit override. `--set` accepts numbers, booleans, JSON vectors, colors and typed values such as `{"t":"float","v":0.7}`. The size is the longer side in pixels. The graph retains its aspect ratio within the supported powers of two from 16 to 8192. Use `--size 1024x512` to choose both sides. An omitted size uses the authored dimensions. An explicit size also sets the final dimensions of outputs fed by fixed-size nodes. +`info` reads the entry's path, dimensions, supported resolutions, typed defaults, saved values, presets, image inputs and output usages. A cook starts from the saved values, applies the named preset, then applies each explicit override. `--set` accepts numbers, booleans, JSON vectors, colors and typed values such as `{"t":"float","v":0.7}`. The size is the longer side in pixels. The graph retains its aspect ratio within the supported powers of two from 1 to 8192. Use `--size 1024x512` to choose both sides. An omitted size uses the authored dimensions. An explicit size also sets the final dimensions of outputs fed by fixed-size nodes. TextureCraft requests `--profile maps` at its texture set's resolution and supplies mesh maps through repeated `--input identifier=path`. Common identifiers include `ambientOcclusion`, `curvature`, `thickness`, `position`, `worldNormal`, `normal`, `height`, `id`, `bentNormal`, `opacity`, `colorMap` and `worldDirection`. An image override uses the published preview binding’s color space when present. Otherwise the input’s declared usage determines the transfer, with the identifier as a fallback for untagged inputs. The JSON report lists each map's identifier, usage, filename, color space and actual dimensions. @@ -413,10 +414,11 @@ pass `merge: true` to continue one gesture; an ordinary request ends that merge. still coalesce until release. `material_export` uses the headless write-root capability and does not expose unrestricted engine file paths. -Bitmap Color space selects sRGB or Linear. `graph.input.bind` accepts `linear: true` for normal, -height and other data maps. Input preview bindings persist in native SBS graph options with the -`materialcraft.previewImage.` and `materialcraft.previewLinear.` prefixes; these options describe -MaterialCraft editor previews and do not establish external application interoperability. +SBS image inputs store the package resource URL in the input bridge's `bitmapresourcepath`. +Both imported bindings and newly bound images use the resource file's color interpretation by default. +`graph.input.bind` accepts `linear: true` to keep the original levels of normal, height and other +data maps, or `linear: false` for sRGB color. MaterialCraft preserves its explicit preview +interpretations in graph options and reads bindings from older files that use those options. ### Shared graph items and classification metadata diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index 89cedd94..0a79e220 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -10,10 +10,15 @@ The native SBS and primitive-library limitations in [atomic-workflow.md](atomic- > **Last reviewed:** 2026-11-04 · **Last updated:** 2026-11-04 · **Change:** major (SBS is the main project format) · **Target:** the professional node-based material workflow -SBS packages are MaterialCraft's main project format (issue #49), read and written with its own -clean-room code from the format's public documentation and sample files. The older `.mcraft` -package is still read and written. MaterialCraft also reads and writes the open image formats -material artists exchange. +SBS packages are MaterialCraft's main project format (issue #49). Its clean-room Rust codec +reads and writes them. The older `.mcraft` package is still read and written. MaterialCraft +also reads and writes the open image formats material artists exchange. + +The atomic sample builds a height image and a scalar brightness output from a graph defined +in Rust. Its round-trip test saves and reopens the generated graph, checks image errors below +`1e-5` and compares typed values for equality. [Graph generator](../crates/engine/src/atomic_sample.rs) · [Round-trip test](../crates/engine/tests/it/atomics.rs) + +The published sample can be used and modified under either of its project licenses. [Sample file](../examples/atomic_sample.sbs) · [Attribution](../ATTRIBUTION.md) · [MIT](../LICENSE-MIT) · [Apache-2.0](../LICENSE-APACHE) | Format | Read | Write | Fidelity | Tests | |---|---|---|---|---| diff --git a/docs/gaps.md b/docs/gaps.md index 87dfa4f7..e628b034 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -1,5 +1,13 @@ # Gaps +The current root inventory records 494 exact cases out of 546 measured roots. This is limited +to those measurements, not arbitrary settings or complete SBS compatibility. The next release +tracks [remaining root differences](https://github.com/storytold/materialcraft/issues/336), +[older linked dependencies](https://github.com/storytold/materialcraft/issues/337), and +[rendering review cases and migration of older MaterialCraft conventions](https://github.com/storytold/materialcraft/issues/338). +The latter includes possible changes to old warp angles, omitted distance/gradient modes and +pattern image selections. Keep original documents when comparing versions. + The [catalog status](node-catalog-parity.md) records implemented corrections and untested behavior, including all 954 loaded package function bodies. The [atomic corrections](atomic-parity-improvements.md) cover filters, channel selection and diff --git a/docs/parity-fixes.md b/docs/parity-fixes.md index c32f4bf9..62f769ee 100644 --- a/docs/parity-fixes.md +++ b/docs/parity-fixes.md @@ -1,8 +1,16 @@ # MaterialCraft parity fixes -Rolling record of fixes made while working through the [SBS root-node inventory](sbs-root-nodes.md). -Parity means exact pixel or typed-value agreement for recorded cases; pending validation is stated explicitly. -The first pass classifies all 546 roots: 166 Parity and 380 Too hard. These measured cases do not establish complete functional parity. +This record follows the [SBS root-node inventory](sbs-root-nodes.md). The first pass classified 166 of 546 roots as Parity and 380 as Too hard. The inventory gives the current status of each root. + +## Comparison method and provenance + +MaterialCraft's clean-room evaluator is written independently in Rust. The directional-noise comparisons use configured SBS graphs and original procedural test patterns. Each application renders the specified graph, size, seed, parameters and output format. For bitmaps, a pixel counts as exact when its raw channel values match at the reported precision. Maximum error is the largest absolute channel difference, in storage levels for integer formats. Value graphs are compared at their declared type. The tables identify original renders, saved-file reopens and processor counts where those differ. + +An intermediate image is a graph node's output. Some tests expose that node as an additional graph output. An instrumented MaterialCraft build can record individual additions, cache hits and work counts in its own evaluator. The reported reference values come from rendered outputs or the exposed properties named in the test. The draw-order tests compare candidate addition sequences with marker pixels from repeated renders. Several sequences can produce the same stored value. The [paired-square regression](../crates/nodes/src/pattern/tests/paired_batches.rs) constructs the pattern graph and generates its input image in Rust. + +The project records the source and license of bundled graphs and resources in its [asset attribution](../ATTRIBUTION.md). + +## Initial fixes - **2026-11-13 — SBS swizzle defaults (orientation corrected):** Removed the importer's zero-channel overrides for omitted two-, three-, and four-component float/integer swizzle settings. Imports now use the existing identity-channel defaults from the function catalog. The first affected node, `3d_gradient.sbs/3d_linear_gradient`, previously repeated X instead of preserving XYZ, producing a horizontal gradient instead of the reference diagonal gradient. Compared both point-position modes with generated position maps at 256 and 512 pixels. Remaining float differences are recorded below; full node parity is not claimed. - **2026-11-13 — Filtered function sampling (integer probes exact):** Added cooked-image storage precision to function samplers. Bilinear reads use eight fractional bits for filter weights. Normalized integer textures return 16-bit filtered values (including 8-bit sources); floating-point textures retain floating-point values. Input bridges retain the integer/floating-point distinction, and cache keys include it. Direct reference measurements on a generated position ramp showed a 16-bit half-step rounding to the next integer, explaining the remaining UV-gradient offset after the swizzle fix. All six measured integer-source sampler cases match all 65,536 float pixels exactly. Two of three floating-source cases are exact; one differs by 5.96e-8. Full-gradient rounding differences remain below. @@ -19,7 +27,7 @@ The first pass classifies all 546 roots: 166 Parity and 380 Too hard. These meas - **2026-11-13 - Omitted function sampler settings:** Corrected Sample Color/Gray defaults to image zero with nearest filtering. Explicit bilinear settings are retained. Both original omitted-setting probes match all 32,768 float pixels. This removes the shifted edges of the 3D volume mask: default outputs at 128x128 and 256x256 and the changed-scale 128x128 case now match every sixteen-bit pixel. -- **2026-11-13 - Finite results after undefined pixel intermediates:** Pixel Processor arithmetic and vector operations now retain IEEE intermediate values so a later min/max can clamp division by zero to a finite result. Non-finite final pixels still return an actionable error. Parameter and pattern functions are checked at their public evaluation boundary. Four original clamp probes (positive infinity, negative infinity, NaN, and finite division) match all 1,024 float pixels. Box-mask cases previously failed at the exact sampled center; they now cook successfully, with the residual conversion differences recorded below. +- **2026-11-13 - Finite results after undefined pixel intermediates:** Pixel Processor arithmetic and vector operations now retain IEEE intermediate values so a later min/max can clamp division by zero to a finite result. Non-finite final pixels still return an actionable error. Parameter and pattern functions are checked at their public evaluation boundary. Four original clamp probes (positive infinity, negative infinity, NaN, and finite division) match all 1,024 float pixels. Cylinder-mask cases previously failed at the exact sampled center; they now cook successfully, with the residual conversion differences recorded below. - **2026-11-13 - Independent transform wrapping:** Transformation 2D now uses horizontal and vertical tiling flags independently, with matching per-axis image sampling. Previously a horizontal-only panorama lost horizontal wrapping because the two flags collapsed to one boolean. All 131,072 RGBA8 pixels across eight original transform probes match exactly, covering both one-axis modes, positive/negative offsets, matte edges, and varying alpha. The panorama helper improves, but its remaining minification/filtering differences are recorded below. @@ -57,8 +65,17013 @@ The first pass classifies all 546 roots: 166 Parity and 380 Too hard. These meas - **2026-11-13 - Unconnected output images:** Unconnected output bridges now produce transparent RGBA instead of grayscale. The importer separately retains each output's declared image type so saving an unconnected output preserves the graph interface. Both material templates match all 1,179,648 RGBA8 pixels across six recorded cases. All 2,560 direct grayscale/color declaration probe pixels also match, and both declared image types survive save/reload. +## 2026-11-28 root comparisons + +### All Directional Noise 2 v2 settings after the modulo correction + +The release build at `65998c9` rendered all 60 original settings and all 12 archived reopens. Every local archived reopen reproduced its original stored pixels. [Settings, seeds and original file routes](#whole-images-for-sixty-directional-noise-2-v2-settings) · [Independent operator probes and five fresh file reopens](#floating-point-modulo-at-a-rounded-period) + +| Stored pixels | U8 exact · max | U16 exact · max | F16 exact · max | F32 exact · max | +|---|---:|---:|---:|---:| +| Earlier originals, one | 137,470/137,472 · 1 | 251,405/251,648 · 581 | 90,362/90,368 · 0.005859375 | 140,000/254,976 · 0.00887396932 | +| Current originals, one | 137,471/137,472 · 1 | 251,423/251,648 · 1 | 90,365/90,368 · 0.000122070312 | 140,008/254,976 · 2.98023224e-07 | +| Earlier originals, eight | 137,471/137,472 · 1 | 251,458/251,648 · 581 | 90,356/90,368 · 0.005859375 | 153,037/254,976 · 0.00887396932 | +| Current originals, eight | 137,472/137,472 · 0 | 251,477/251,648 · 1 | 90,359/90,368 · 0.000244140625 | 153,050/254,976 · 2.98023224e-07 | +| One reference compared with eight | 137,471/137,472 · 1 | 251,404/251,648 · 1 | 90,356/90,368 · 0.000244140625 | 126,510/254,976 · 3.57627869e-07 | +| Current archived reopens, one | 30,720/30,720 · 0 | 6,395/6,400 · 1 | 1,024/1,024 · 0 | 45,326/84,992 · 2.98023224e-07 | + +A whole image matches when every stored pixel matches. The two reference captures use identical graph parameters. + +| Entire images matched | U8 | U16 | F16 | F32 | +|---|---:|---:|---:|---:| +| Current against one | 11/12 | 1/17 | 8/10 | 0/21 | +| Current against eight | 12/12 | 2/17 | 8/10 | 0/21 | +| One reference against eight | 11/12 | 1/17 | 8/10 | 0/21 | +| Archived reopen against one | 4/4 | 1/3 | 1/1 | 0/4 | + +Across all storage formats, 20/60 complete original images match on one processor and 22/60 on eight. The reference outputs differ from each other in 40/60 settings. Directional Noise 2 v2 remains in progress. + +### Seeded placement in the remaining Directional Noise 3 rectangles + +The shared FX-Map evaluator now binds pure grayscale frame offsets, rotations and luminosities for eligible drawing quadrants. It evaluates each random stream at its original property and charges the arithmetic that runs. A drawing function with unsupported instructions or a mutable input uses the ordinary evaluator. The visit, property-work, raster and cache ceilings still apply. The 64 × 16 and 64 × 32 settings previously exhausted the property budget in F32. Their sixteen and eighteen emitted trees have 6,275,400 and 6,785,426 distinct node, depth and seed combinations. [Earlier eight recoveries and seed-count method](#drawing-parents-and-terminal-children-in-directional-noise-3) + +Open Directional Noise 3 with default tiling and grayscale output. At 64 × 16 use seed 42, scale 2, disorder .03125, angle −.21875 and angle random .03125. At 64 × 32 use seed 195031, scale 3, disorder .34375, angle .09375 and angle random .34375. Enable non-square expansion for both. Keep the other defaults, set each output storage on the Levels node feeding the output, save normally, then open the configured file in both applications. Count whole stored pixels. The integer maxima are storage levels. + +| Size | Storage | Original on one · max | Original on eight · max | Fresh reopen on one · max | Fresh reopen on eight · max | +|---|---|---:|---:|---:|---:| +| 64 × 16 | U8 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| 64 × 16 | U16 | 1,021/1,024 · 2 | 1,022/1,024 · 2 | 1,023/1,024 · 2 | 1,023/1,024 · 2 | +| 64 × 16 | F16 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| 64 × 16 | F32 | 1,023/1,024 · 2.46167183e-05 | 1,022/1,024 · 2.65836716e-05 | 1,022/1,024 · 2.46167183e-05 | 1,022/1,024 · 2.46167183e-05 | +| 64 × 32 | U8 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| 64 × 32 | U16 | 2,041/2,048 · 2 | 2,043/2,048 · 2 | 2,040/2,048 · 2 | 2,040/2,048 · 2 | +| 64 × 32 | F16 | 2,048/2,048 · 0 | 2,047/2,048 · 0.000244140625 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| 64 × 32 | F32 | 2,041/2,048 · 2.90572643e-05 | 2,044/2,048 · 2.48551369e-05 | 2,040/2,048 · 2.65538692e-05 | 2,040/2,048 · 2.65538692e-05 | + +All eight fresh reopens preserve the 12,288 original local pixels. At 64 × 16 the archived F16 reopen matches 1,024/1,024 · 0 on one processor. At 64 × 32 the archived U8 reopen matches 2,048/2,048 · 0. Both local archived buffers also reproduce the original. + +The cumulative table combines the eight current originals with the 52 previously compared originals and the two current archived reopens with the earlier ten. Each of the 60 settings has now rendered. [Full panel and earlier per-format coverage](#rectangular-and-additional-seed-coverage-in-directional-noise-3) + +| Recorded panel | Entire images exact | U8 pixels · max | U16 pixels · max | F16 pixels · max | F32 pixels · max | +|---|---:|---:|---:|---:|---:| +| Original on one | 20/60 | 88,320/88,320 · 0 | 299,978/300,800 · 3 | 90,354/90,368 · 0.00048828125 | 254,265/254,976 · 4.7326088e-05 | +| Original on eight | 21/60 | 88,319/88,320 · 1 | 300,016/300,800 · 3 | 90,353/90,368 · 0.00048828125 | 254,391/254,976 · 4.7326088e-05 | +| Archived reopen on one | 5/12 | 14,336/14,336 · 0 | 22,733/22,784 · 2 | 1,024/1,024 · 0 | 84,783/84,992 · 4.7326088e-05 | + +For an independent control, connect four outer by 24 inner iterations to a wave quadrant. Add four connections to a second wave quadrant in the child variant. Use maximum blending, zero roughness, unit opacity scale and size (.1875,.375). Use a uniform random luminosity up to 1, two independent uniform random offsets up to .75 plus (−.3125,−.40625), and rotation .125 plus a uniform draw up to .25 turns. Compare both graphs at 16² seed 0 and 32 × 16 seed 42, in U8, U16, F16 and F32. All 16 originals and their 16 configured ordinary saves each give **6,144/6,144 · 0** on one and eight processors. The earlier evaluator also matches all 16 originals. + +Two earlier complete F32 outputs retain every local word. Against one and eight processors, the 16² default controls at seed 103852 give 256/256 · 0. At 32², seed 103854, scale 1, disorder .3125, angle .15625, angle random .21875 and non-square expansion off, the counts are 1,020/1,024 and 1,021/1,024 with maximum .0000265836716 on both. The remaining worker-dependent and local pixel differences keep this root in progress. + +The release regression follows seven empty quadrants with four outer by 24 inner iterations. A square parent connects all four slots to a second square with the same seeded properties. With a visit limit of 80 the bound properties reproduce every 4 × 4 output word from an ordinary calculation with limit 4,096. The earlier evaluator exhausts the limit at 80. The bound fixture still exhausts a limit of 32. All 515 release node tests passed, as did formatting, strict workspace Clippy, crate layering and WebAssembly checks. + +For the three remaining comparisons below, capture the original four times on each processor count and one fresh ordinary reopen on each. Count a pixel as stable only when all ten reference words agree. The final column includes pixels where the local word appeared in any of the ten captures. + +| Size | Storage | Stable words matched · total stable | Local word observed · all pixels | +|---|---|---:|---:| +| 64 × 16 | F32 | 1,020/1,021 | 1,023/1,024 | +| 64 × 32 | U16 | 2,032/2,032 | 2,048/2,048 | +| 64 × 32 | F32 | 2,033/2,033 | 2,048/2,048 | + +At (19,14) in the 64 × 16 F32 output, all ten reference captures read .5435265899 and MaterialCraft reads .5435512066. This is the only local word absent from the ten captures for this image. At 64 × 32 every local F32 and U16 word appears at the same coordinate in at least one of the ten returns. + +On a separate copy of the configured 64 × 16 graph, add output bridges to the three FX-Maps and both blends. Keep all existing connections, properties, output formats and the original Levels output. Both reference processor counts returned identical images for all six outputs. The local Levels output reproduced its original F32 buffer. At (19,14) the first difference appears in the third FX-Map. + +| Output in evaluation order | Dimensions and storage | Exact on one or eight · max | Local value | Reference value | +|---|---|---:|---:|---:| +| First FX-Map | 8 × 2 U16 | 16/16 · 0 | 32621 | 32621 | +| Second FX-Map | 16 × 4 U16 | 64/64 · 0 | 11019 | 11019 | +| First Blend | 64 × 16 U16 | 1,024/1,024 · 0 | 28376 | 28376 | +| Third FX-Map | 64 × 16 U16 | 1,023/1,024 · 1 | 20789 | 20788 | +| Second Blend | 64 × 16 U16 | 1,023/1,024 · 1 | 39704 | 39703 | +| Levels | 64 × 16 F32 | 1,023/1,024 · 2.46167183e-05 | 0.5435512066 | 0.5435265899 | + +For the 8 × 2 and 16 × 4 sources, the listed values come from the pixel containing the same normalized position, (2,1) and (4,3) respectively. + +### An additive wave at a 16-bit storage boundary + +Use the 64 × 16 Directional Noise 3 setting with seed 42 and the 64 × 32 setting with seed 195031. For each selected format, collect four original renders on one processor and four on eight, then reopen an ordinary save on each processor count. At 64 × 32 every local U16 and F32 word occurs in at least one of the ten corresponding reference returns. At 64 × 16 in F32, one local value falls outside all ten returns. At (19, 14) MaterialCraft gives .5435512066 and all ten reference returns give .5435265899. [Full settings and file routes](#seeded-placement-in-the-remaining-directional-noise-3-rectangles) + +Add outputs to the three wave patterns and the two blends in the configured 64 × 16 graph. Keep the original normalization and storage. The first two patterns match all 16 and 64 U16 pixels, and the first blend matches all 1,024. The third pattern gives 20,789 at (19, 14) in MaterialCraft and 20,788 in both reference captures. The second blend carries that difference to 39,704 and 39,703. The final Levels output retains the measured F32 difference. + +Set only the third pattern to F32 and read the draws before integer storage. Compare the original additive setting with maximum blending on its wave quadrants. Both processor counts give the following whole-image comparisons. + +| Output at 64 × 16 | Additive exact · max | Maximum blending exact · max | +|---|---:|---:| +| Third pattern | 326/1,024 · 1.78813934e-07 | 1,024/1,024 · 0 | +| Following blend | 627/1,024 · 1.78813934e-07 | 1,024/1,024 · 0 | +| Levels | 637/1,024 · 3.57627869e-07 | 1,024/1,024 · 0 | + +At (19, 14) the additive pattern gives .317213088274 in MaterialCraft and .317212998867 in both reference captures. Flooring these values at 20 fractional bits gives 332,622 and 332,621. Converting each application’s F32 values through the normalized U16 store reproduces its own **1,024/1,024** original U16 words. The difference is already present in the floating-point sum. + +Connect the third pattern directly to the output, keeping its graph settings, and cap only the outer iteration count. Both reference processor counts agree on every pixel of each reduced case. + +| Emitted trees | F32 exact · maximum | +|---:|---:| +| 1 | 959/1,024 · 1.1920929e-07 | +| 2 | 952/1,024 · 1.1920929e-07 | +| 4 | 911/1,024 · 2.68220901e-07 | +| 8 | 764/1,024 · 1.78813934e-07 | + +Keep one emitted tree and follow quadrant slots 1, 0, 1 to the next fork. All four child subtrees measured individually match 1,024/1,024. All sixteen grandchildren also match individually, **16,384/16,384**. With two child slots connected, the six pairs together give **6,137/6,144 · 3.7252903e-09**. With three connected, the four combinations give **4,089/4,096 · 7.4505806e-09**. Both processor counts give these results. + +Replaying each child’s measured contributions as a contiguous group fails to reproduce the reference in four of six pairs and three of four triples, even after trying every child order. Grouping the individual MaterialCraft stamp contributions one level deeper gives six candidate orders that each reproduce all 16 affected positions in every pair. These settings narrow the draw-order discrepancy. Directional Noise 3 remains in progress. + +### All sixty settings in Directional Noise 3 v2 + +The same release at `ffd0927` rendered all 60 original settings and all 12 archived file reopens. The earlier complete sweep produced eleven originals and two archived reopens. Every current local archived reopen reproduces the corresponding original stored pixels. The six additional configured files preserve their sizes, seeds and parameters on ordinary Save. [Six configured reopens](#three-larger-rectangles-in-directional-noise-3-v2) · [Independent half-precision and rectangular controls](#seven-tiled-half-precision-settings-in-directional-noise-3-v2) + +| Comparison | U8 exact · max | U16 exact · max | F16 exact · max | F32 exact · max | Whole images | +|---|---:|---:|---:|---:|---:| +| Original, one | 137,470/137,472 · 2 | 251,645/251,648 · 446 | 90,366/90,368 · 0.0068359375 | 254,975/254,976 · 0.00680267811 | 52/60 | +| Original, eight | 137,470/137,472 · 2 | 251,647/251,648 · 446 | 90,366/90,368 · 0.0068359375 | 254,975/254,976 · 0.00680267811 | 54/60 | +| One reference against eight | 137,472/137,472 · 0 | 251,646/251,648 · 446 | 90,368/90,368 · 0 | 254,976/254,976 · 0 | 58/60 | +| Archived reopen, one | 30,720/30,720 · 0 | 6,400/6,400 · 0 | 1,024/1,024 · 0 | 84,991/84,992 · 0.00652578473 | 11/12 | + +A whole image counts when every stored pixel is exact. Integer errors are storage levels. For F16 and F32 the maximum is the largest absolute difference between stored values. + +| Images exact by precision | U8 | U16 | F16 | F32 | +|---|---:|---:|---:|---:| +| Original, one | 10/12 | 14/17 | 8/10 | 20/21 | +| Original, eight | 10/12 | 16/17 | 8/10 | 20/21 | +| One reference against eight | 12/12 | 15/17 | 10/10 | 21/21 | +| Archived reopen, one | 4/4 | 3/3 | 1/1 | 3/4 | + +
+Original settings and archived file routes + +Use the authored tiling and set the grayscale storage on the final Levels node. The control values are scale, disorder, disorder speed, anisotropy, anisotropy angle, angle, angle randomness, tile offset and non-square expansion. A dash keeps the default. Angles use turns. On the archived route open the saved package and then apply the setting. + +| Size | Seed | Control values | Original storage | Archived reopen | +|---|---:|---|---|---| +| 128² | 0 | Defaults | U8 | U8 | +| 256² | 0 | Defaults | U8, U16, F16, F32 | — | +| 128² | 42 | Defaults | U8 | — | +| 128² | 0 | 2, 0.37, 0.6, 0.3, 0.125, 0.125, 0.2, (0.17, 0.29), — | U8 | — | +| 32² | 113 | 2, 0.37, 0.6, 0.3, 0.125, 0.125, 0.2, (0.17, 0.29), — | F32 | — | +| 64² | 42 | 2, 0.37, 0.6, 0.3, 0.125, 0.125, 0.2, (0.17, 0.29), — | U8, U16, F16, F32 | U8 | +| 16² | 103865 | Defaults | F32 | — | +| 32² | 103866 | 1, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, (0.0, 0.0), on | F32 | F32 | +| 32² | 103867 | 1, 0.3125, 0.6875, 0.25, 0.3125, 0.15625, 0.21875, (0.125, −0.1875), off | U8, U16, F16, F32 | — | +| 64 × 32 | 103871 | 2, 0.6875, 1.4375, 0.625, −0.21875, −0.21875, 0.40625, (−0.3125, 0.4375), on | F32 | F32 | +| 32 × 64 | 103872 | 1, 0.3125, 0.6875, 0.25, 0.3125, 0.15625, 0.21875, (0.125, −0.1875), off | U16 | — | +| 32² | 103873 | 3, 0.125, 0.875, 0.125, 0.15625, 0.375, 0.03125, (−0.0625, 0.125), off | F32 | — | +| 64 × 32 | 103874 | 1, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, (0.0, 0.0), on | F16 | — | +| 16² | 0 | Defaults | U8, U16, F16, F32 | U16 | +| 64 × 16 | 42 | 2, 0.03125, 0.03125, 0.03125, −0.21875, −0.21875, 0.03125, (−0.3125, 0.37890625), on | U8, U16, F16, F32 | F16 | +| 16 × 64 | 411643 | 1, 0.875, 0.875, 0.875, 0.625, 0.625, 0.875, (0.53125, −0.359375), off | U16, F32 | — | +| 64² | 411704 | 3, 0.34375, 0.34375, 0.34375, 0.09375, 0.09375, 0.34375, (0.0, 0.10546875), on | U8, U16, F16, F32 | U16 | +| 128 × 64 | 411765 | 2, 0.96875, 0.96875, 0.96875, 0.71875, 0.71875, 0.96875, (0.625, −0.44140625), off | U16, F32 | — | +| 64 × 128 | 411826 | 1, 0.1875, 0.1875, 0.1875, −0.0625, −0.0625, 0.1875, (−0.15625, 0.2421875), on | U8, U16, F16, F32 | U8 | +| 128² | 411887 | 3, 0.65625, 0.65625, 0.65625, 0.40625, 0.40625, 0.65625, (0.3125, −0.16796875), off | U16, F32 | F32 | +| 128 × 512 | 412009 | 2, 0.53125, 0.53125, 0.53125, 0.28125, 0.28125, 0.53125, (0.1875, −0.05859375), off | U16, F32 | F32 | +| 512 × 128 | 412070 | 1, 0.09375, 0.09375, 0.09375, −0.15625, −0.15625, 0.09375, (−0.25, 0.32421875), on | U16, F32 | — | +| 16 × 32 | 195015 | Defaults | U16, F32 | — | +| 64 × 32 | 195062 | 3, 0.34375, 0.34375, 0.34375, 0.09375, 0.09375, 0.34375, (0.0, 0.10546875), on | U8, U16, F16, F32 | U8 | +| 32 × 64 | 195109 | 1, 0.1875, 0.1875, 0.1875, −0.0625, −0.0625, 0.1875, (−0.15625, 0.2421875), on | U8, U16, F16, F32 | U16 | +| 64² | 195156 | 2, 0.53125, 0.53125, 0.53125, 0.28125, 0.28125, 0.53125, (0.1875, −0.05859375), off | U16, F32 | — | + +
+ +Across all formats MaterialCraft matches 734,456/734,464 original pixels on one processor and 734,458/734,464 on eight. The reference captures disagree with one another in 2 of the 60 original images. At 32² and seed 103867, the original F16 captures both differ at one pixel by .0068359375. The fresh configured reopen is exact on both processor counts. Directional Noise 3 v2 remains in progress. [Repeated values at the source and output](#a-recovered-rectangle-and-repeated-outputs-in-directional-noise-3-v2) + +### Three larger rectangles in Directional Noise 3 v2 + +The 512 × 128, 128 × 512 and 128 × 64 settings that hit the earlier work limit now render in U16 and F32. The 512 × 128 F32 output already matches both reference captures in revision `65998c9`. Each local file reopened after an ordinary save reproduces its original pixels. [Earlier precision settings and file routes](#seven-tiled-half-precision-settings-in-directional-noise-3-v2) + +Keep the original tiling, use the grayscale output and set the output precision on the final Levels node. Leave unlisted controls at their defaults. Save each configured graph and open that file in both applications. + +| Dimensions · seed | Scale | Disorder | Disorder speed | Anisotropy | Anisotropy angle | Angle | Angle random | Tile offset | Non-square expansion | +|---|---:|---:|---:|---:|---:|---:|---:|---|---| +| 512 × 128 · 412070 | 1 | 0.09375 | 0.09375 | 0.09375 | -0.15625 | -0.15625 | 0.09375 | (-0.25, 0.32421875) | On | +| 128 × 512 · 412009 | 2 | 0.53125 | 0.53125 | 0.53125 | 0.28125 | 0.28125 | 0.53125 | (0.1875, -0.05859375) | Off | +| 128 × 64 · 411765 | 2 | 0.96875 | 0.96875 | 0.96875 | 0.71875 | 0.71875 | 0.96875 | (0.625, -0.44140625) | Off | + +| Dimensions | Storage | Original on one · max | Original on eight · max | Fresh reopen on one · max | Fresh reopen on eight · max | +|---|---|---:|---:|---:|---:| +| 512 × 128 | U16 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | +| 512 × 128 | F32 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | +| 128 × 512 | U16 | 65,535/65,536 · 428 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | +| 128 × 512 | F32 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | +| 128 × 64 | U16 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | +| 128 × 64 | F32 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | + +All three original F32 images match both reference captures, **139,264/139,264 · 0** per processor count. At (31,17) in the 128 × 512 U16 original, the one-processor reference reads 32,473. The eight-processor reference, both reference reopens and MaterialCraft read 32,045. Across all six settings, the ordinary reopens match **278,528/278,528** stored pixels on both processor counts. Directional Noise 3 v2 remains in progress. + +### Whole-image comparisons for both Directional Noise 4 roots + +Both roots have whole-buffer measurements for 60 original procedural settings and 12 archived file reopens. The current release at `ffd0927` was checked against seven of those originals and two archived reopens per root. All fourteen original buffers and all four archived buffers reproduce their earlier local float streams byte for byte. The full-panel counts below use the retained measurements. The six new configured reopens are reported separately. Integer errors are storage levels. + +| Root and comparison | U8 exact · max | U16 exact · max | F16 exact · max | F32 exact · max | Whole images | +|---|---:|---:|---:|---:|---:| +| 4 · original, one | 88,319/88,320 · 1 | 300,244/300,800 · 1 | 90,360/90,368 · 0.00048828125 | 138,742/254,976 · 4.76837158e-07 | 18/60 | +| 4 · original, eight | 88,319/88,320 · 1 | 300,265/300,800 · 1 | 90,359/90,368 · 0.00048828125 | 139,439/254,976 · 4.17232513e-07 | 18/60 | +| 4 · one reference against eight | 88,320/88,320 · 0 | 300,239/300,800 · 1 | 90,357/90,368 · 0.00048828125 | 146,367/254,976 · 3.87430191e-07 | 20/60 | +| 4 · archived reopen, one | 14,336/14,336 · 0 | 22,755/22,784 · 1 | 1,024/1,024 · 0 | 47,906/84,992 · 3.57627869e-07 | 5/12 | +| 4 v2 · original, one | 137,471/137,472 · 1 | 250,988/251,648 · 1 | 90,361/90,368 · 0.00048828125 | 116,398/254,976 · 5.96046448e-07 | 21/60 | +| 4 v2 · original, eight | 137,472/137,472 · 0 | 251,007/251,648 · 1 | 90,359/90,368 · 0.00048828125 | 126,458/254,976 · 5.36441803e-07 | 22/60 | +| 4 v2 · one reference against eight | 137,471/137,472 · 1 | 250,987/251,648 · 1 | 90,358/90,368 · 0.00048828125 | 117,429/254,976 · 5.66244125e-07 | 20/60 | +| 4 v2 · archived reopen, one | 30,720/30,720 · 0 | 6,390/6,400 · 1 | 1,024/1,024 · 0 | 35,787/84,992 · 5.66244125e-07 | 6/12 | + +
+Sizes, seeds, exposed parameters and file routes + +Use the authored tiling and set the grayscale storage on the FX-Map feeding the output. The control values are scale, disorder, disorder speed, anisotropy, anisotropy angle, angle, angle randomness, tile offset and non-square expansion, in that order. Directional Noise 4 uses scale, disorder, angle, angle randomness and non-square expansion. The additional fields apply to v2. A dash leaves the control at its default. Angles use turns. Archived reopens open the package first, then apply the listed setting. + +| Size | Seed 4 / v2 | Control values | 4 original | 4 archived | v2 original | v2 archived | +|---|---|---|---|---|---|---| +| 128² | 0 | Defaults | U16 | U16 | U8 | U8 | +| 256² | 0 | Defaults | U8, U16, F16, F32 | — | U8, U16, F16, F32 | — | +| 128² | 42 | Defaults | U16 | — | U8 | — | +| 128² | 0 | 2, 0.37, 0.6, 0.3, 0.125, 0.125, 0.2, (0.17, 0.29), — | U16 | — | U8 | — | +| 32² | 113 | 2, 0.37, 0.6, 0.3, 0.125, 0.125, 0.2, (0.17, 0.29), — | F32 | — | F32 | — | +| 64² | 42 | 2, 0.37, 0.6, 0.3, 0.125, 0.125, 0.2, (0.17, 0.29), — | U8, U16, F16, F32 | U8 | U8, U16, F16, F32 | U8 | +| 16² | 103878 / 103891 | Defaults | F32 | — | F32 | — | +| 32² | 103879 / 103892 | 1, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, (0.0, 0.0), on | F32 | F32 | F32 | F32 | +| 32² | 103880 / 103893 | 1, 0.3125, 0.6875, 0.25, 0.3125, 0.15625, 0.21875, (0.125, −0.1875), off | U8, U16, F16, F32 | — | U8, U16, F16, F32 | — | +| 64 × 32 | 103884 / 103897 | 2, 0.6875, 1.4375, 0.625, −0.21875, −0.21875, 0.40625, (−0.3125, 0.4375), on | F32 | F32 | F32 | F32 | +| 32 × 64 | 103885 / 103898 | 1, 0.3125, 0.6875, 0.25, 0.3125, 0.15625, 0.21875, (0.125, −0.1875), off | U16 | — | U16 | — | +| 32² | 103886 / 103899 | 3, 0.125, 0.875, 0.125, 0.15625, 0.375, 0.03125, (−0.0625, 0.125), off | F32 | — | F32 | — | +| 64 × 32 | 103887 / 103900 | 1, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, (0.0, 0.0), on | F16 | — | F16 | — | +| 16² | 0 | Defaults | U8, U16, F16, F32 | U16 | U8, U16, F16, F32 | U16 | +| 64 × 16 | 42 | 2, 0.03125, 0.03125, 0.03125, −0.21875, −0.21875, 0.03125, (−0.3125, 0.37890625), on | U8, U16, F16, F32 | F16 | U8, U16, F16, F32 | F16 | +| 16 × 64 | 411650 / 411657 | 1, 0.875, 0.875, 0.875, 0.625, 0.625, 0.875, (0.53125, −0.359375), off | U16, F32 | — | U16, F32 | — | +| 64² | 411711 / 411718 | 3, 0.34375, 0.34375, 0.34375, 0.09375, 0.09375, 0.34375, (0.0, 0.10546875), on | U8, U16, F16, F32 | U16 | U8, U16, F16, F32 | U16 | +| 128 × 64 | 411772 / 411779 | 2, 0.96875, 0.96875, 0.96875, 0.71875, 0.71875, 0.96875, (0.625, −0.44140625), off | U16, F32 | — | U16, F32 | — | +| 64 × 128 | 411833 / 411840 | 1, 0.1875, 0.1875, 0.1875, −0.0625, −0.0625, 0.1875, (−0.15625, 0.2421875), on | U8, U16, F16, F32 | U8 | U8, U16, F16, F32 | U8 | +| 128² | 411894 / 411901 | 3, 0.65625, 0.65625, 0.65625, 0.40625, 0.40625, 0.65625, (0.3125, −0.16796875), off | U16, F32 | F32 | U16, F32 | F32 | +| 128 × 512 | 412016 / 412023 | 2, 0.53125, 0.53125, 0.53125, 0.28125, 0.28125, 0.53125, (0.1875, −0.05859375), off | U16, F32 | F32 | U16, F32 | F32 | +| 512 × 128 | 412077 / 412084 | 1, 0.09375, 0.09375, 0.09375, −0.15625, −0.15625, 0.09375, (−0.25, 0.32421875), on | U16, F32 | — | U16, F32 | — | +| 16 × 32 | 195046 / 195077 | Defaults | U16, F32 | — | U16, F32 | — | +| 64 × 32 | 195093 / 195124 | 3, 0.34375, 0.34375, 0.34375, 0.09375, 0.09375, 0.34375, (0.0, 0.10546875), on | U8, U16, F16, F32 | U8 | U8, U16, F16, F32 | U8 | +| 32 × 64 | 195140 / 195171 | 1, 0.1875, 0.1875, 0.1875, −0.0625, −0.0625, 0.1875, (−0.15625, 0.2421875), on | U8, U16, F16, F32 | U16 | U8, U16, F16, F32 | U16 | +| 64² | 195187 / 195218 | 2, 0.53125, 0.53125, 0.53125, 0.28125, 0.28125, 0.53125, (0.1875, −0.05859375), off | U16, F32 | — | U16, F32 | — | + +
+ +For the current binary checks, both roots used the default 16² setting at seed zero in U8, F16 and F32. Directional Noise 4 also used 512 × 128 and 128 × 512 in U16 and F32. Directional Noise 4 v2 used 128 × 64 and 128² in U16 and F32. The archived checks reopened the 16² default U16 file for both, the 128 × 512 F32 file for version 4 and the 128² F32 file for v2. + +| Fresh configured save | Storage | Seed | Original on one · max | Original on eight · max | Reopen on one · max | Reopen on eight · max | +|---|---|---:|---:|---:|---:|---:| +| 4 · 16² | F16 | 0 | 256/256 · 0 | 256/256 · 0 | 256/256 · 0 | 256/256 · 0 | +| 4 · 512 × 128 | U16 | 412077 | 65,419/65,536 · 1 | 65,408/65,536 · 1 | 65,419/65,536 · 1 | 65,419/65,536 · 1 | +| 4 · 512 × 128 | F32 | 412077 | 35,368/65,536 · 4.76837158e-07 | 34,066/65,536 · 3.27825546e-07 | 35,368/65,536 · 4.76837158e-07 | 35,368/65,536 · 4.76837158e-07 | +| 4 v2 · 16² | F16 | 0 | 256/256 · 0 | 256/256 · 0 | 256/256 · 0 | 256/256 · 0 | +| 4 v2 · 128 × 64 | U16 | 411779 | 8,169/8,192 · 1 | 8,160/8,192 · 1 | 8,169/8,192 · 1 | 8,169/8,192 · 1 | +| 4 v2 · 128 × 64 | F32 | 411779 | 3,127/8,192 · 5.96046448e-07 | 3,078/8,192 · 5.06639481e-07 | 3,127/8,192 · 5.96046448e-07 | 3,127/8,192 · 5.96046448e-07 | + +The local configured reopens reproduced all 147,968 original stored pixels. The one- and eight-processor reference originals differ in 40/60 settings for Directional Noise 4 and 40/60 for v2. Both roots remain in progress. + +### Floating-point modulo at a rounded period + +A runtime float modulo can round to the divisor when a very small input has the opposite sign. The reference returns zero at that endpoint. Constant expressions retain the rounded divisor. MaterialCraft now makes that distinction in the shared floating-point operator. The FX-Map drawing evaluator uses the same operator. The original graphs and their live functions supply all parameters. [Quadrant-path measurements](#locating-individual-waves-in-directional-noise-2-v2) + +Use a grayscale square over black with unit opacity and zero roughness. Drive its luminosity with two exposed scalar values passed to modulo. Repeat in a grayscale Uniform and a grayscale Pixel Processor. Read stored F32 at 16². For each divisor 1, −1, .125, 3 and −1.5, let g be the difference between its magnitude and the next smaller positive F32. Multiply g by the divisor sign and each of −1.125, −1, −.75, −.5, −.25, .25, .5, .75 and 1.25. Also test the divisor itself and the values immediately to either side. The last six signed operand pairs are (.3125000298023224, 1), (−.3125000298023224, 1), (.2, .3), (−.2, .3), (−1.25, 3) and (1.25, −3). Use seeds 42, 43 and 44 cyclically. + +| Original independent F32 control | Before · one · max | Current · one · max | Current · eight · max | +|---|---:|---:|---:| +| Drawing property | 14,336/16,896 · 3 | 16,896/16,896 · 0 | 16,896/16,896 · 0 | +| Uniform property | 14,336/16,896 · 3 | 16,896/16,896 · 0 | 16,896/16,896 · 0 | +| Pixel Processor | 14,336/16,896 · 3 | 16,896/16,896 · 0 | 16,896/16,896 · 0 | + +The nine literal controls give 2,304/2,304 · 0 on both processor counts. With divisor 1, literal −2⁻²⁵ gives 1 and a live input of the same value gives zero. A live input of −.75 × 2⁻²⁴ gives the predecessor of 1. Mirror the signs for a negative divisor. In a separate Pixel Processor select the input or its negative using the horizontal pixel coordinate. Thirteen split images improve from 2,304/3,328 · 3 to **3,328/3,328 · 0** on one processor. The same current result holds on eight. + +The 36 earlier seeded offset settings and 36 ordinary reopens each retain 15,360/15,360 pixels on one and eight processors, maximum zero. [Seeded modulo controls and four storage formats](#floored-modulo-in-seeded-drawing-properties) + +For the two isolated waves, keep the graph tiling and source expressions. Make a square with unit opacity scaling and zero roughness. After evaluating the active quadrant’s branch offset, return the negative of its incoming position. Evaluate its original frame offset, size and rotation before returning the center of the render region, (12, 12) and zero respectively. To read an intermediate value, store it at the operation being measured, retain the rest of the original expression and return the stored component as luminosity. The marker covers nine pixels at 64² and 36 pixels at 512 × 128. + +| Size · outer/inner cap | Marker | Before · one · max | Current · one · max | Current · eight · max | +|---|---|---:|---:|---:| +| 64² · 1/2 | Draw count | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| 64² · 1/2 | Vertical offset before modulo | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| 64² · 1/2 | Vertical offset after modulo | 4,087/4,096 · 0.999999978 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| 64² · 1/2 | Luminosity | 4,087/4,096 · 0.0317136049 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| 512 × 128 · 34/1 | Draw count | 65,536/65,536 · 0 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | +| 512 × 128 · 34/1 | Vertical offset before modulo | 65,536/65,536 · 0 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | +| 512 × 128 · 34/1 | Vertical offset after modulo | 65,500/65,536 · 1 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | +| 512 × 128 · 34/1 | Luminosity | 65,500/65,536 · 0.0398881435 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | + +With the original wave shape and position restored, four isolated paths give **139,264/139,264 · 0** on each processor count. At wide pixel (136, 65) the extra .00887397118 disappears. At square pixel (52, 23) the missing .00170036184 is recovered. + +Set the output storage on the second FX-Map. Save the configured graph normally and reopen each file at its stored size, seed and parameters in both applications. Each local reopen reproduces its original buffer. The table compares whole root images. Integer maxima are storage levels. [Exact exposed settings and earlier 60-image sweep](#whole-images-for-sixty-directional-noise-2-v2-settings) + +| Size · seed · storage | Previous original · one · max | Current original · one · max | Current original · eight · max | Current ordinary save · one · max | Current ordinary save · eight · max | +|---|---:|---:|---:|---:|---:| +| 64² · 42 · U16 | 4,091/4,096 · 111 | 4,093/4,096 · 1 | 4,092/4,096 · 1 | 4,093/4,096 · 1 | 4,093/4,096 · 1 | +| 64² · 42 · F16 | 4,094/4,096 · 0.00170898438 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| 64² · 42 · F32 | 2,204/4,096 · 0.00170040131 | 2,205/4,096 · 1.78813934e-07 | 2,366/4,096 · 1.78813934e-07 | 2,186/4,096 · 1.1920929e-07 | 2,186/4,096 · 1.1920929e-07 | +| 512 × 128 · 412056 · U16 | 65,489/65,536 · 581 | 65,498/65,536 · 1 | 65,509/65,536 · 1 | 65,494/65,536 · 1 | 65,494/65,536 · 1 | +| 512 × 128 · 412056 · F32 | 33,830/65,536 · 0.00887396932 | 33,832/65,536 · 2.98023224e-07 | 37,854/65,536 · 1.78813934e-07 | 33,299/65,536 · 2.98023224e-07 | 33,299/65,536 · 2.98023224e-07 | + +Reference runs at identical settings still differ. They agree at 1,904/4,096 · 1.78813934e-07 for the square F32 image and 31,716/65,536 · 2.38418579e-07 for the wide F32 image. These differences keep Directional Noise 2 v2 in progress. + +Other root controls used the same released evaluator. Compare the two local buffers at each setting and score the current raw F32 output against each reference capture. + +| Root | Size · seed | Local buffer compared with previous release | Current · one · max | Current · eight · max | +|---|---|---|---:|---:| +| Spots 1 | 32 × 16 · 456654 | Identical | 451/512 · 1.1920929e-07 | 439/512 · 1.1920929e-07 | +| Spots 3 | 16 × 16 · 0 | Identical | 256/256 · 0 | 256/256 · 0 | +| Clouds 1 | 32 × 32 · 113 | Identical | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| Directional Noise 2 | 32 × 32 · 103827 | Identical | 297/1,024 · 2.98023224e-07 | 298/1,024 · 2.38418579e-07 | +| Directional Noise 3 | 16 × 16 · 103852 | Identical | 256/256 · 0 | 256/256 · 0 | +| Directional Noise 4 | 32 × 32 · 103879 | Identical | 503/1,024 · 2.68220901e-07 | 561/1,024 · 2.98023224e-07 | + +The new floating-point regression failed on the preceding release and passed with the shared operator change. All 514 release node tests, formatting, strict workspace Clippy, the layer check and the WebAssembly check passed. + +### Locating individual waves in Directional Noise 2 v2 + +These measurements use revision `f40f6a5`, before the shared modulo correction. The preceding section reports the same paths after the fix. + +Use the two F32 settings in the [sixty-setting comparison](#whole-images-for-sixty-directional-noise-2-v2-settings). At 64², seed 42, inspect pixel (52, 23). At 512 × 128, seed 412056, inspect (136, 65). Use the second FX-Map over black and retain its live math links. Four reachable drawing quadrants at depths six through nine share their parameters. To measure one depth, give the other three a copy of their property set. In that copy, evaluate the original size expression, including its random draw, then return (0, 0). Read the grayscale F32 words. + +| Drawing depth | 64² · one · max | 64² · eight · max | 512 × 128 · one · max | 512 × 128 · eight · max | +|---:|---:|---:|---:|---:| +| 6 | 2,251/4,096 · 2.98023224e-08 | 2,368/4,096 · 2.98023224e-08 | 45,843/65,536 · 2.98023224e-08 | 45,637/65,536 · 2.98023224e-08 | +| 7 | 3,021/4,096 · 0.0017003566 | 3,032/4,096 · 0.0017003566 | 50,422/65,536 · 2.98023224e-08 | 50,424/65,536 · 2.98023224e-08 | +| 8 | 3,077/4,096 · 2.23517418e-08 | 3,236/4,096 · 2.98023224e-08 | 51,653/65,536 · 0.00887397118 | 55,384/65,536 · 0.00887397083 | +| 9 | 3,068/4,096 · 6.07538968e-05 | 3,251/4,096 · 6.07538968e-05 | 50,930/65,536 · 8.99098814e-06 | 54,643/65,536 · 8.99471343e-06 | + +The depth-eight wide image contains all nine pixels with absolute error over 0.00001. At each subdivision keep each of the four slots in turn. At the target pixel compare the sum of those four returns with the previous image, then follow the child carrying the discrepancy. The wide path uses slots 0, 2, 3, 3, 1, 2, 2, 3. The square path reaches depth seven through slots 3, 2, 1, 3, 2, 0, 3. An outgoing connection below the drawing quadrant has no effect on its wave. + +To select an iteration, evaluate its original count and take the smaller of that count and an integer cap. This retains the count expression's assignments. Use an additive wave with the original tint, size, offsets and rotation. The following captures agreed at every reference pixel between one and eight processors. + +| Size | Outer cap | Inner cap | Exact pixels · max, each processor count | At target, MaterialCraft | At target, reference | +|---|---:|---:|---:|---:|---:| +| 512 × 128 | 33 | 1 | 65,536/65,536 · 0 | 0 | 0 | +| 512 × 128 | 34 | 0 | 65,536/65,536 · 0 | 0 | 0 | +| 512 × 128 | 34 | 1 | 65,533/65,536 · 0.00887397118 | 0.008873971179 | 0 | +| 64² | 1 | 1 | 4,096/4,096 · 0 | 0 | 0 | +| 64² | 1 | 2 | 4,095/4,096 · 0.00170036184 | 0 | 0.001700361841 | + +On the isolated wide path, a single local wave contributes 0.00887397118. Its center is (−1.43517566, .193142891), its effective size is (.005859375, .0227996614), its rotation is .0986371785 turns, and its tint is .584212303. The two applications return the same render and tiling bounds, (−2.5, 1.5, −.32421875, .67578125). In a separate single-quadrant graph put that wave at the recorded center, over black, with unit opacity and zero roughness. With the original render region a computed rotation gives .303792685 at the target in both applications. Repeating with a literal rotation, a square pattern and a unit region gives **524,288/524,288 exact F32 pixels** across eight configurations at each processor count, maximum zero. + +## 2026-11-27 root comparisons + +### All sixty original Directional Noise 2 settings + +Directional Noise 2 has produced whole images for **60/60 established original settings and 12/12 archived saved-package settings** across two measured releases. Revision `e1e3c1e` produced 42 originals and six archived reopens. Revision `fdd01fb` produced all 18 originals and six reopens that had reached the execution limit. All twelve local archived reopens reproduced their corresponding original buffers on the release that rendered them. The first 19 settings now all have whole-image measurements. [Earlier 19-setting comparison](#directional-noise-and-scratch-pattern-sources) + +Compare stored grayscale pixels. Integer maxima are storage levels. Each entry gives exact pixels / total pixels and maximum absolute error. The archived reopens used one reference processor. + +| Measurement | U8 | U16 | F16 | F32 | +|---|---:|---:|---:|---:| +| 42 earlier originals, one | 81,152/81,152 · 0 | 211,311/211,712 · 1 | 83,185/83,200 · 0.00048828125 | 48,322/162,816 · 3.57627869e-07 | +| 42 earlier originals, eight | 81,152/81,152 · 0 | 211,340/211,712 · 1 | 83,192/83,200 · 0.00048828125 | 58,386/162,816 · 3.57627869e-07 | +| 18 recovered originals, one | 7,168/7,168 · 0 | 88,947/89,088 · 1 | 7,168/7,168 · 0 | 32,703/92,160 · 3.57627869e-07 | +| 18 recovered originals, eight | 7,167/7,168 · 1 | 88,956/89,088 · 1 | 7,168/7,168 · 0 | 35,766/92,160 · 2.98023224e-07 | +| Six earlier archived reopens | 12,288/12,288 · 0 | 18,653/18,688 · 1 | — | 297/1,024 · 2.98023224e-07 | +| Six recovered archived reopens | 2,048/2,048 · 0 | 4,092/4,096 · 1 | 1,024/1,024 · 0 | 29,908/83,968 · 2.98023224e-07 | + +
+Sizes, seeds and exposed values for all 60 settings + +Use the package’s own procedural input and keep tiling enabled. Set the storage on the FX-Map feeding the output. Controls are scale, disorder, angle in turns, random angle and non-square expansion, in that order. Leave omitted controls at default. The archived saved package was reopened before applying the listed settings. “All four” means U8, U16, F16 and F32. + +| Size | Seed | Controls | Original formats | Archived reopen | Formerly bounded original | +|---|---:|---|---|---|---| +| 128² | 0 | Defaults | U16 | U16 | — | +| 256² | 0 | Defaults | All four | — | — | +| 128² | 42 | Defaults | U16 | — | — | +| 128² | 0 | 2, 0.37, 0.125, 0.2, default | U16 | — | — | +| 32² | 113 | 2, 0.37, 0.125, 0.2, default | F32 | — | — | +| 64² | 42 | 2, 0.37, 0.125, 0.2, default | All four | U8 | — | +| 16² | 103826 | Defaults | F32 | — | — | +| 32² | 103827 | 1, 0, 0, 0, on | F32 | F32 | — | +| 32² | 103828 | 1, 0.3125, 0.15625, 0.21875, off | All four | — | — | +| 64 × 32 | 103832 | 2, 0.6875, -0.21875, 0.40625, on | F32 | F32 | F32 | +| 32 × 64 | 103833 | 1, 0.3125, 0.15625, 0.21875, off | U16 | — | — | +| 32² | 103834 | 3, 0.125, 0.375, 0.03125, off | F32 | — | F32 | +| 64 × 32 | 103835 | 1, 0, 0, 0, on | F16 | — | — | +| 16² | 0 | Defaults | All four | U16 | — | +| 64 × 16 | 42 | 2, 0.03125, -0.21875, 0.03125, on | All four | F16 | All four | +| 16 × 64 | 411622 | 1, 0.875, 0.625, 0.875, off | U16, F32 | — | — | +| 64² | 411683 | 3, 0.34375, 0.09375, 0.34375, on | All four | U16 | All four | +| 128 × 64 | 411744 | 2, 0.96875, 0.71875, 0.96875, off | U16, F32 | — | — | +| 64 × 128 | 411805 | 1, 0.1875, -0.0625, 0.1875, on | All four | U8 | — | +| 128² | 411866 | 3, 0.65625, 0.40625, 0.65625, off | U16, F32 | F32 | U16, F32 | +| 128 × 512 | 411988 | 2, 0.53125, 0.28125, 0.53125, off | U16, F32 | F32 | U16, F32 | +| 512 × 128 | 412049 | 1, 0.09375, -0.15625, 0.09375, on | U16, F32 | — | — | +| 16 × 32 | 194922 | Defaults | U16, F32 | — | — | +| 64 × 32 | 194969 | 3, 0.34375, 0.09375, 0.34375, on | All four | U8 | All four | +| 32 × 64 | 195016 | 1, 0.1875, -0.0625, 0.1875, on | All four | U16 | — | +| 64² | 195063 | 2, 0.53125, 0.28125, 0.53125, off | U16, F32 | — | — | + +
+ +For six additional comparisons, set the graph size, seed, controls and storage before using ordinary Save. Open each file afresh in both applications and read its stored configuration. All **7,168/7,168** MaterialCraft pixels reproduced their original values. The two fresh reference processor counts agreed at every saved pixel. In the last column, retain only pixels where both original and both saved reference captures gave the same value. + +| Size · seed · storage | Original, one · max | Original, eight · max | Saved, one and eight · max | Matches at fixed reference pixels · max | +|---|---:|---:|---:|---:| +| 64 × 16 · 42 · U8 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| 64 × 16 · 42 · U16 | 1,021/1,024 · 1 | 1,021/1,024 · 1 | 1,021/1,024 · 1 | 1,020/1,021 · 1 | +| 64 × 16 · 42 · F16 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| 64 × 16 · 42 · F32 | 342/1,024 · 1.78813934e-07 | 385/1,024 · 1.78813934e-07 | 351/1,024 · 2.38418579e-07 | 78/163 · 1.1920929e-07 | +| 64 × 32 · 103832 · F32 | 720/2,048 · 1.78813934e-07 | 804/2,048 · 2.38418579e-07 | 738/2,048 · 2.38418579e-07 | 244/438 · 1.78813934e-07 | +| 32² · 103834 · F32 | 411/1,024 · 3.57627869e-07 | 398/1,024 · 2.38418579e-07 | 360/1,024 · 2.98023224e-07 | 115/227 · 1.1920929e-07 | + +At 64 × 16 and seed 42, the original F32 reference runs themselves match 318/1,024 pixels, maximum 2.38418579e-07. One U16 pixel differs by one level at a position where all four reference captures agree. These differences keep the root in progress. [Five repeated captures per worker count](#repeated-f32-captures-of-28-noise-roots) + +### Additive wave overlaps in Directional Noise 2 + +The only processing node is an FX-Map connected directly to the output. Use F32 at 16², seed 103826 and defaults, then 32², seed 103834 with the controls above. Start with the authored wave shapes and additive blending. For the maximum control, change only the blending mode on the two drawing parameter sets. For the additive path controls, successively retain child slots 0, 3, 1, 2, 0 and 3 at the first six four-way quadrant subdivisions. Leave later connections, iterates, seeds and drawing properties as authored. Use the same linked math functions for each control. + +| Drawing control | 16², one · max | 16², eight · max | 32², one · max | 32², eight · max | +|---|---:|---:|---:|---:| +| All additive branches | 75/256 · 1.49011612e-07 | 87/256 · 1.49011612e-07 | 359/1,024 · 2.98023224e-07 | 411/1,024 · 2.38418579e-07 | +| Maximum on both drawing parameter sets | 256/256 · 0 | 256/256 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| Additive, first subdivision restricted | 166/256 · 5.96046448e-08 | 164/256 · 8.94069672e-08 | 644/1,024 · 8.94069672e-08 | 679/1,024 · 8.94069672e-08 | +| Additive, first 2 subdivisions restricted | 214/256 · 2.98023224e-08 | 218/256 · 2.98023224e-08 | 907/1,024 · 2.98023224e-08 | 902/1,024 · 4.47034836e-08 | +| Additive, first 3 subdivisions restricted | 238/256 · 2.98023224e-08 | 238/256 · 2.98023224e-08 | 994/1,024 · 1.49011612e-08 | 973/1,024 · 1.49011612e-08 | +| Additive, first 4 subdivisions restricted | 256/256 · 0 | 256/256 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| Additive, first 5 subdivisions restricted | 256/256 · 0 | 256/256 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| Additive, first 6 subdivisions restricted | 256/256 · 0 | 256/256 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | + +Maximum blending gives 256 and 1,024 distinct values in the two images. The six-subdivision additive path gives 191 and 1,010. Both controls match on each processor count. The full additive sums still vary between reference captures. [Independent overlapping-wave comparison](#addition-and-maximum-blending-in-directional-noise-1-v2) + +Retain slots 0, 3 and 1 at the first three subdivisions. At the fourth, test each of the four child slots by itself and each of the six unordered pairs. An empty fourth subdivision also produces a nonconstant image from the preceding draws. It matches 256/256 and 1,024/1,024 pixels at both processor counts, maximum zero. + +| Fourth subdivision | 16², one · max | 16², eight · max | 32², one · max | 32², eight · max | +|---|---:|---:|---:|---:| +| Four single-child controls | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| Six two-child controls | 1,502/1,536 · 2.98023224e-08 | 1,502/1,536 · 2.98023224e-08 | 6,085/6,144 · 1.49011612e-08 | 6,035/6,144 · 1.49011612e-08 | + +At the fourth subdivision retain only slots 0 and 1. Read the two sizes alternately three more times per worker count. All **eight 16² reference images** have identical words. MaterialCraft matches 253/256, maximum 3.7252903e-09. Each differing MaterialCraft word is one representable value below the reference. At 32² the eight reference images contain three distinct buffers. MaterialCraft matches 997/999 pixels that stayed fixed, maximum 3.7252903e-09. + +| 16² coordinate | MaterialCraft F32 word | Reference F32 word on all eight reads | +|---|---:|---:| +| (7,2) | `3d37495f` | `3d374960` | +| (4,4) | `3d29886d` | `3d29886e` | +| (9,5) | `3b95abfc` | `3b95abfd` | + +### An unfinished draw batch across repeated quadrant pairs + +When an outer Iterate emits multiple two-child quadrant trees, each first child can draw before the shared path and the second child from all repetitions. The continuation contains the shared path and the last connected child of each tree. MaterialCraft counts its physical tile copies, including copies of draws that miss the pixel grid. The measured order applies while this continuation holds fewer than 5,460 copies. [Single-tree draw order and procedural construction](#drawing-a-shared-quadrant-path-with-its-last-child) + +Use the linked nine-subdivision wave graph at 32 × 16, seed 42, F32. Add an outer Iterate with only the repeated port wired. With a drawing slot followed by an empty quadrant, one, two, three, five and nine repetitions now give **2,560/2,560 · 0** on one and eight processors. Keeping just the drawing slot also gives 2,560/2,560. With two drawing slots, one, two and three repetitions give 1,536/1,536. At five and nine repetitions the two drawing slots can fill the continuation and reference outputs vary. + +To locate the boundary, use four repetitions of the two-wave-child graph. Each path contributes 13 wrapped copies per repetition ahead of the fork. The unpruned second branch contributes 1,365. Remove complete leading subtrees from that second child, counting each removed quadrant draw. For a partial subtree, follow its first child recursively. Leave the first drawing child and the parent path intact. Compare F32 words at 32 × 16 and retain the same wave properties. + +| Draws removed per repetition | Continuation copies | Original traversal against one reference · max | Current against one · max | Current against eight · max | +|---:|---:|---:|---:|---:| +| 0 | 5,512 | 503/512 · 1.1920929e-07 | 503/512 · 1.1920929e-07 | 508/512 · 5.96046448e-08 | +| 10 | 5,472 | 503/512 · 1.1920929e-07 | 503/512 · 1.1920929e-07 | 508/512 · 5.96046448e-08 | +| 12 | 5,464 | 503/512 · 1.1920929e-07 | 503/512 · 1.1920929e-07 | 508/512 · 5.96046448e-08 | +| 13 | 5,460 | 503/512 · 1.1920929e-07 | 503/512 · 1.1920929e-07 | 503/512 · 1.1920929e-07 | +| 14 | 5,456 | 508/512 · 5.96046448e-08 | 512/512 · 0 | 512/512 · 0 | +| 18 | 5,440 | 508/512 · 5.96046448e-08 | 512/512 · 0 | 512/512 · 0 | +| 25 | 5,412 | 508/512 · 5.96046448e-08 | 512/512 · 0 | 512/512 · 0 | + +The square regression uses two repetitions and a depth-one gain of −.5 on white. With just the drawing child, pixel (6, 4) retains 2⁻²³. With the later empty child it gives zero. With two drawing children only (7, 4) retains 2⁻²³. The previous release failed at (6, 4). An eight-repetition two-drawing-child control has distinct reference outputs at the same settings. + +Repeat three independent wave controls at 16² seed zero and 32 × 16 seed 42 in U8, U16, F16 and F32. Use nine repetitions with the empty sibling, three with both drawing children, and the four-repetition boundary with 14 draws removed. Across the 24 original settings the exact pixel count rises from 9,192/9,216 · 2.38418579e-07 to **9,216/9,216 · 0** on one reference processor. The current release matches all original pixels at eight processors and all 9,216 reopened pixels independently at each count. Every local reopen reproduces its original buffer. + +On the Directional Noise 2 control with one active branch and a later empty quadrant, 32² seed 103834 improves from 1,000/1,024 · 1.49011612e-08 to **1,024/1,024 · 0**. The 16² seed 103826 graph stays exact. Both configured ordinary saves match every pixel at both processor counts. The connected and disconnected files with identical identifiers also match all their alternating reference reads. The nine-tree two-drawing-child controls and the full root retain differences. [Root controls, sizes and parameters](#a-second-branch-beside-a-wrapped-wave) + +### Drawing a shared quadrant path with its last child + +In a grayscale additive FX-Map, follow a single path to its first fork with six more quadrant subdivisions to the deepest leaf. On a single emitted tree, the earlier connected children draw in slot order, then the shared path draws, then the last connected child draws. A connected empty quadrant can occupy that last slot. MaterialCraft now orders the raster ranges after evaluating the drawing properties. The ordinary package retains its connections. + +Build an FX-Map with nine quadrant subdivisions on a white background with roughness zero and opacity one. Follow child slots 0, 3, 1 to the fork. Draw a square at depth one with size (2, 2) and gain −1. From the fork, fill each active child subtree to depth nine. Draw only the terminal squares, with size (1.375, 1.375) and gain 2⁻²⁵. At 16², seed zero, one active slot leaves 2⁻²³ at (6, 4). Connecting an empty quadrant immediately after it gives zero there. With two, three or four drawing slots, only (7, 4), (6, 5) or (7, 5) retains 2⁻²³, respectively. All other pixels are zero. The regression first failed at (6, 4) with the exact prior F32 word. + +For the depth controls, use unit terminal squares. Move the fork through depths one to four, retaining an earlier drawing slot and a later empty slot. Compare five and six subdivisions below each fork. Test slots (0, 1), (1, 0), (2, 3) and (3, 1) at depth three. The square draws before the parent when its slot comes first and after the parent when its slot comes last. Across 22 connected and disconnected files, at 32² and 256² or 512², the new release matches **3,037,184/3,037,184** pixels on each processor count, maximum zero. Four-way, three-way, two-way and single-path descent controls also distinguish depth from leaf count. + +To distinguish the order among four occupied slots, shift the four children onto the first child with branch offsets of 0 or −1/16 per axis. Draw a unit square at each terminal quadrant. Permute gains of 1, −1, 2⁻²⁵ and zero among the shared path and the four children. Eighteen black-background settings and four white-background settings identify the same order on one and eight reference processors at 64², seed 17. + +An independent wave control uses a black background with roughness and opacity .5. From depth one, cycle through gains .3125, −.71875, .59375, .84375 and −.34375 and rotations .25, −.125 and .0625 turns. Set the frame offset to (.109375, −.09375), the first size to (1.5, 7), then alternate (1.5, 2.75) and (.875, 3.25). Use two or four connected drawing slots. Run both wave controls and the connected square control at 16² seed zero and 32 × 16 seed 42, in U8, U16, F16 and F32. Save each configured graph and reopen it in both applications. The original files and the 24 ordinary saves each give **9,216/9,216 · 0** on one and eight processors. The prior release gave 9,187/9,216 · 1.1920929e-07 on each file route. + +| Directional Noise 2 at 16², seed 103826, F32 | Prior exact pixels · maximum | Current exact pixels · maximum | +|---|---:|---:| +| Each of six possible two-child connections at the fourth subdivision, combined | 1,502/1,536 · 2.98023224e-08 | 1,536/1,536 · 0 | +| Four connected drawing children | 238/256 · 2.98023224e-08 | 256/256 · 0 | +| One drawing child followed by an empty quadrant | 251/256 · 7.4505806e-09 | 256/256 · 0 | +| Ordinary save of the two-child graph with slots 0 and 1 | 253/256 · 3.7252903e-09 | 256/256 · 0 | + +Both reference processor counts give these 16² results. At 32², seed 103834 emits nine trees, and the six two-child controls give 6,085/6,144 · 1.49011612e-08 on one processor and 6,035/6,144 · 1.49011612e-08 on eight. Connecting the empty child still gives 1,000/1,024 · 1.49011612e-08 on both. The full additive root also retains its measured differences. [Whole-root settings](#all-sixty-original-directional-noise-2-settings) · [Original captures and single-wire controls](#a-second-branch-beside-a-wrapped-wave) + +### A second branch beside a wrapped wave + +Save the two-child Directional Noise 2 control with each size, seed, F32 storage and parameter set in its own file. The local reopens reproduce all 1,280 original pixels. Both reference worker counts give 253/256 at 16², maximum 3.7252903e-09, and 1,016/1,024 at 32², maximum 7.4505806e-09. The same three 16² words differ after reopening. [Two-child control and reference words](#additive-wave-overlaps-in-directional-noise-2) + +At 16², record each nonzero contribution to the three differing local pixels. Sampling the wrapped depth-one wave produces the first three values at each position. These copies share center, size, rotation and tint. The remaining draws are at the indicated quadrant depth. Each entry below is an F32 word in accumulation order. The instrumented MaterialCraft evaluator and its release `fdd01fb` gave identical F32 buffers across eleven whole controls. + +| Pixel | Three depth-one contributions | Later depth | Later contributions | +|---|---|---:|---| +| (7,2) | `3c588738`, `3c8d2705`, `3c1a6207` | 8 | `3bb890d6`, `ba45a384` | +| (4,4) | `3cb11a4d`, `3d085ad2`, `3cbaed7d` | 4 | `bd1c5499`, `3aefca02` | +| (9,5) | `3a6ec209`, `3a8de55e`, `39edea7b` | 9 | `3b0af779` | + +Connecting just slot 0 gives exactly the same local contributions, in exactly the same order, at (7,2) and (9,5). Connecting slot 1 as well changes the reference word at each of those positions by one representable value. At (4,4) it adds a fifth local contribution. Enumerating the six orders of the three depth-one copies with the descendants kept last cannot reproduce the reference word at (7,2) or (4,4). Moving all descendants ahead of the three copies reproduces all three reference words, but only 248/256 pixels across the image. + +Replay the recorded contributions across each complete 16² image, accumulating in F32 after every addition. Keep the relative order of descendant draws. The counts below use the one-worker reference. The third column processes all descendant contributions after the first contributing parent copy at each pixel. + +| Fourth subdivision | Existing order · max | After the first contributing copy · max | Before every parent copy · max | +|---|---:|---:|---:| +| Four single-child controls | 1,024/1,024 · 0 | 983/1,024 · 1.49011612e-08 | 982/1,024 · 1.49011612e-08 | +| Six two-child controls | 1,502/1,536 · 2.98023224e-08 | 1,468/1,536 · 2.98023224e-08 | 1,463/1,536 · 2.98023224e-08 | +| All four children | 238/256 · 2.98023224e-08 | 247/256 · 1.49011612e-08 | 243/256 · 1.49011612e-08 | + +Keep the first child fully connected. Give the second child its own quadrant with the same drawing data. Preserve its first zero, one, two, three or four outgoing slots in order. With all four, MaterialCraft reproduces its original two-child buffer at each size. The **same three 16² coordinates** differ by the same one-word amounts for all five variants, including when the second child draws as a leaf. At 32² the counts change with the branches. + +| Outgoing slots on the second child | 16², one and eight · max | 32², one · max | 32², eight · max | +|---:|---:|---:|---:| +| 0 | 253/256 · 3.7252903e-09 | 1,000/1,024 · 1.49011612e-08 | 1,000/1,024 · 1.49011612e-08 | +| 1 | 253/256 · 3.7252903e-09 | 1,000/1,024 · 1.49011612e-08 | 1,000/1,024 · 1.49011612e-08 | +| 2 | 253/256 · 3.7252903e-09 | 1,016/1,024 · 7.4505806e-09 | 1,016/1,024 · 7.4505806e-09 | +| 3 | 253/256 · 3.7252903e-09 | 1,008/1,024 · 7.4505806e-09 | 1,008/1,024 · 7.4505806e-09 | +| 4 | 253/256 · 3.7252903e-09 | 1,016/1,024 · 7.4505806e-09 | 1,016/1,024 · 7.4505806e-09 | + +With the second child disconnected from its descendants, try an empty shape, a wave of size (.125,.125) with zero opacity, and a wave of size (0,0) with unit opacity. Leave the first child and its descendants as authored. Each local frame reproduced its counterpart with only the first child connected. Read the two reference outputs for each control. + +| Second child | 16², one · max | 16², eight · max | 32², one · max | 32², eight · max | +|---|---:|---:|---:|---:| +| Empty shape | 251/256 · 7.4505806e-09 | 251/256 · 7.4505806e-09 | 1,000/1,024 · 1.49011612e-08 | 1,000/1,024 · 1.49011612e-08 | +| Zero opacity | 251/256 · 7.4505806e-09 | 251/256 · 7.4505806e-09 | 1,000/1,024 · 1.49011612e-08 | 1,000/1,024 · 1.49011612e-08 | +| Zero size | 251/256 · 7.4505806e-09 | 251/256 · 7.4505806e-09 | 1,000/1,024 · 1.49011612e-08 | 1,000/1,024 · 1.49011612e-08 | + +Repeat the empty-shape comparison using two files with the same package and graph identifiers and the same live math dependency. Their XML differs by exactly one connection to the empty leaf. Alternate sizes three times per worker count and compare with the first capture at each count. All eight reference reads agree for each size and connection state. With the wire disconnected, MaterialCraft matches 256/256 and 1,024/1,024, maximum zero. Connecting it changes **five reference pixels at 16² and 24 at 32²**, with the maxima above. Both entire MaterialCraft buffers retain their words. This isolates a connection-dependent change in the reference sum even when the additional branch contributes no visible value. + +### Seven tiled half-precision settings in Directional Noise 3 v2 + +All seven previously recorded F16 settings now render in MaterialCraft, including the 64 × 32 output at seed 195062 and the 64² output at seed 411704. The three settings that previously reached the execution limit produce 7,168/7,168 exact pixels on each reference processor count, on the originals and their configured saves. [Earlier precision results and exposed parameter values](#half-precision-inputs-to-levels) + +| Size · seed | F16 original, one or eight · maximum | Configured save, one or eight · maximum | +|---|---:|---:| +| 16² · 0 | 256/256 · 0 | 256/256 · 0 | +| 64 × 16 · 42 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| 32² · 103867 | 1,023/1,024 · 0.0068359375 | 1,024/1,024 · 0 | +| 64 × 32 · 195062 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| 32 × 64 · 195109 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| 64² · 411704 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| 64² · 42 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | + +The seven originals match **14,591/14,592** pixels, maximum .0068359375. Reopening each saved file in the reference app and MaterialCraft gives **14,592/14,592**, maximum zero. The local original and saved words agree in all seven settings. The remaining original pixel at (18,16) is documented with its stage-to-output captures. [F32 and U16 reads at the same coordinate](#a-recovered-rectangle-and-repeated-outputs-in-directional-noise-3-v2) + +At 64 × 32, seed 195062, set scale 3, disorder, speed, anisotropy and angle randomness .34375, both angles .09375 and tile offset (0,.10546875). Enable non-square expansion and leave tiling at its default. Choose U8, U16, F16 and F32 on the Levels node feeding the output. Save each configuration and reopen it with the stored controls. **8,192/8,192** original pixels and **8,192/8,192** saved pixels match each reference processor count, maximum zero. The graph generates its own input. + +### Whole images for sixty Directional Noise 2 v2 settings + +Directional Noise 2 v2 now has whole-buffer comparisons for **60/60 established original settings** and **12/12 archived reopened settings** across the measured releases. The earlier sweep rendered 30 originals and five archived reopens. Subsequent measurements covered the remaining settings. Every archived local reopen reproduced its corresponding original buffer. Only successful grayscale cooks count. Integer maxima are storage levels. + +| Cases | U8 exact · max | U16 exact · max | F16 exact · max | F32 exact · max | +|---|---:|---:|---:|---:| +| All 60 originals, one | 137,470/137,472 · 1 | 251,405/251,648 · 581 | 90,362/90,368 · 0.005859375 | 140,000/254,976 · 0.00887396932 | +| All 60 originals, eight | 137,471/137,472 · 1 | 251,458/251,648 · 581 | 90,356/90,368 · 0.005859375 | 153,037/254,976 · 0.00887396932 | +| Earlier 30 originals, one | 109,822/109,824 · 1 | 80,557/80,640 · 389 | 79,100/79,104 · 0.005859375 | 47,084/79,872 · 0.00593535602 | +| Additional 30 originals, one | 27,648/27,648 · 0 | 170,848/171,008 · 581 | 11,262/11,264 · 0.00170898438 | 92,916/175,104 · 0.00887396932 | +| All 12 archived reopens, one | 30,720/30,720 · 0 | 6,394/6,400 · 389 | 1,024/1,024 · 0 | 45,322/84,992 · 0.00393900275 | + +
+Original settings and archived reopens + +Use the graph’s procedural input and its authored tiling. Set the storage on the second FX-Map, which receives the first as its background. In the controls column the values are scale, disorder, disorder speed, anisotropy, anisotropy angle, angle, angle randomness, tile offset and non-square expansion. Angles use turns. A dash leaves the exposed value at default. Each archived reopen opens the saved package before applying the listed setting. + +| Size | Seed | Controls | Original formats | Archived reopen | +|---|---:|---|---|---| +| 128² | 0 | Defaults | U8 | U8 | +| 256² | 0 | Defaults | U8, U16, F16, F32 | — | +| 128² | 42 | Defaults | U8 | — | +| 128² | 0 | 2, 0.37, 0.6, 0.3, 0.125, 0.125, 0.2, (0.17, 0.29), — | U8 | — | +| 32² | 113 | 2, 0.37, 0.6, 0.3, 0.125, 0.125, 0.2, (0.17, 0.29), — | F32 | — | +| 64² | 42 | 2, 0.37, 0.6, 0.3, 0.125, 0.125, 0.2, (0.17, 0.29), — | U8, U16, F16, F32 | U8 | +| 16² | 103839 | Defaults | F32 | — | +| 32² | 103840 | 1, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, (0.0, 0.0), on | F32 | — | +| 32² | 103841 | 1, 0.3125, 0.6875, 0.25, 0.3125, 0.15625, 0.21875, (0.125, −0.1875), off | U8, U16, F16, F32 | — | +| 64 × 32 | 103845 | 2, 0.6875, 1.4375, 0.625, −0.21875, −0.21875, 0.40625, (−0.3125, 0.4375), on | F32 | — | +| 32 × 64 | 103846 | 1, 0.3125, 0.6875, 0.25, 0.3125, 0.15625, 0.21875, (0.125, −0.1875), off | U16 | — | +| 32² | 103847 | 3, 0.125, 0.875, 0.125, 0.15625, 0.375, 0.03125, (−0.0625, 0.125), off | F32 | — | +| 64 × 32 | 103848 | 1, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, (0.0, 0.0), on | F16 | — | +| 16² | 0 | Defaults | U8, U16, F16, F32 | — | +| 64 × 16 | 42 | 2, 0.03125, 0.03125, 0.03125, −0.21875, −0.21875, 0.03125, (−0.3125, 0.37890625), on | U8, U16, F16, F32 | — | +| 16 × 64 | 411629 | 1, 0.875, 0.875, 0.875, 0.625, 0.625, 0.875, (0.53125, −0.359375), off | U16, F32 | — | +| 64² | 411690 | 3, 0.34375, 0.34375, 0.34375, 0.09375, 0.09375, 0.34375, (0.0, 0.10546875), on | U8, U16, F16, F32 | — | +| 128 × 64 | 411751 | 2, 0.96875, 0.96875, 0.96875, 0.71875, 0.71875, 0.96875, (0.625, −0.44140625), off | U16, F32 | — | +| 64 × 128 | 411812 | 1, 0.1875, 0.1875, 0.1875, −0.0625, −0.0625, 0.1875, (−0.15625, 0.2421875), on | U8, U16, F16, F32 | U8 | +| 128² | 411873 | 3, 0.65625, 0.65625, 0.65625, 0.40625, 0.40625, 0.65625, (0.3125, −0.16796875), off | U16, F32 | — | +| 128 × 512 | 411995 | 2, 0.53125, 0.53125, 0.53125, 0.28125, 0.28125, 0.53125, (0.1875, −0.05859375), off | U16, F32 | — | +| 512 × 128 | 412056 | 1, 0.09375, 0.09375, 0.09375, −0.15625, −0.15625, 0.09375, (−0.25, 0.32421875), on | U16, F32 | — | +| 16 × 32 | 194953 | Defaults | U16, F32 | — | +| 64 × 32 | 195000 | 3, 0.34375, 0.34375, 0.34375, 0.09375, 0.09375, 0.34375, (0.0, 0.10546875), on | U8, U16, F16, F32 | U8 | +| 32 × 64 | 195047 | 1, 0.1875, 0.1875, 0.1875, −0.0625, −0.0625, 0.1875, (−0.15625, 0.2421875), on | U8, U16, F16, F32 | — | +| 64² | 195094 | 2, 0.53125, 0.53125, 0.53125, 0.28125, 0.28125, 0.53125, (0.1875, −0.05859375), off | U16, F32 | — | + +
+ +At 64 × 16 and seed 42, set the listed nine controls and store each of the four formats in its own ordinary save. Reopen each in both applications with the stored configuration. All 4,096/4,096 local saved pixels reproduce their originals. The two fresh reference worker counts agree on every saved pixel. + +| Storage | Original, one · max | Original, eight · max | Ordinary save, one and eight · max | +|---|---:|---:|---:| +| U8 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| U16 | 1,022/1,024 · 1 | 1,023/1,024 · 1 | 1,023/1,024 · 1 | +| F16 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| F32 | 690/1,024 · 8.94069672e-08 | 751/1,024 · 5.96046448e-08 | 709/1,024 · 7.4505806e-08 | + +At 512 × 128 and seed 412056, fresh captures isolate nine F32 pixels with absolute errors above 0.00001. The largest occurs at (136, 65). MaterialCraft gives 0.183100328 and both reference counts give 0.174226359. The reference captures themselves give 32,745/65,536 · 2.98023224e-07. + +Both processing nodes are FX-Maps. The first supplies the background for the second. Make a procedural comparison copy for each control. Disable the second map’s drawing shapes to read its background. Separately disconnect the background and keep the second map’s additive waves. For the final control change those four wave parameter sets to maximum blending. Use F32 at 64² seed 42 and 512 × 128 seed 412056 with the respective exposed values in the settings table. Compare the raw output after each change. + +| Stage | 64², one · max | 64², eight · max | 512 × 128, one · max | 512 × 128, eight · max | +|---|---:|---:|---:|---:| +| Whole original | 2,032/4,096 · 0.0017003715 | 2,162/4,096 · 0.00170040131 | 33,830/65,536 · 0.00887396932 | 37,581/65,536 · 0.00887396932 | +| First map as background | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | +| Second map on black, additive | 2,017/4,096 · 0.00170036405 | 1,798/4,096 · 0.00170037895 | 28,160/65,536 · 0.00887396559 | 28,565/65,536 · 0.00887396932 | +| Second map on black, maximum | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | + +The isolated additive map retains two differences above 0.00001 at 64² and nine at 512 × 128. At the latter size its largest remains at (136, 65). The maximum-blend controls match all 69,632 pixels on each processor count. + +[64² configured saves](#a-tiled-square-in-directional-noise-2-v2) · [64 × 32 configured saves](#floored-modulo-in-seeded-drawing-properties) + +### A tiled square in Directional Noise 2 v2 + +At 64², seed 195094, use scale 2, disorder, speed, anisotropy and angle randomness .53125, both angles .28125 and tile offset (.1875,−.05859375). Disable non-square expansion, keep the authored tiling and leave the other parameters at default. Choose each storage format on the node feeding the output, save the configuration and reopen the file with the stored controls. All four MaterialCraft saved buffers reproduce their originals, **16,384/16,384** pixels. [Related 64 × 32 setting and seeded drawing expression](#floored-modulo-in-seeded-drawing-properties) + +| Storage | Original, one · maximum | Original, eight · maximum | Saved, one · maximum | Saved, eight · maximum | +|---|---:|---:|---:|---:| +| U8 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| U16 | 4,093/4,096 · 1 | 4,093/4,096 · 1 | 4,093/4,096 · 1 | 4,093/4,096 · 1 | +| F16 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,095/4,096 · 0.000122070312 | 4,095/4,096 · 0.000122070312 | +| F32 | 2,170/4,096 · 1.78813934e-07 | 2,422/4,096 · 1.78813934e-07 | 2,218/4,096 · 2.38418579e-07 | 2,218/4,096 · 2.38418579e-07 | + +The earlier original F32 reference pair agreed at 1,899/4,096 · 1.78813934e-07. The exact counts above compare whole buffers. Both roots remain in progress. + +### Floored modulo in seeded drawing properties + +Directional Noise 2 v2 at 64 × 32 and seed 195000 now returns a whole image in each of four storage formats and on their four ordinary saves. The previous evaluator reached its property budget on this setting. It had completed 5,242,880 full property evaluations and still had pending drawing work. The drawing function wraps a two-component offset using floored modulo. The general evaluator already implements that operation. The bounded drawing evaluator now uses the same implementation for its fixed and seeded operands. It preserves the random register and the offset published to subsequent properties. + +Use scale 3, disorder, speed, anisotropy and angle randomness .34375, both angles .09375, tile offset (0,.10546875) and non-square expansion on. Keep tiling and all other defaults. The graph generates its own input. Set the node feeding the output to each storage format, save to its own file, close and reopen with the stored parameters. The four saved MaterialCraft buffers reproduce their originals, **8,192/8,192** pixels. Integer errors below are stored levels. [Earlier tiled settings](#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) + +| Storage | Original · one · max | Original · eight · max | Saved · one · max | Saved · eight · max | +|---|---:|---:|---:|---:| +| U8 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| U16 | 2,047/2,048 · 1 | 2,046/2,048 · 1 | 2,046/2,048 · 1 | 2,046/2,048 · 1 | +| F16 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| F32 | 1,253/2,048 · 1.1920929e-07 | 1,348/2,048 · 1.78813934e-07 | 1,300/2,048 · 1.1920929e-07 | 1,300/2,048 · 1.1920929e-07 | + +The original F32 reference captures themselves agree at 1,096/2,048 pixels, maximum 1.34110451e-07. The remaining differences keep the root in progress. + +For the procedural controls, start with a two-component seeded offset. Subtract (.1875,.21875), then apply floored modulo to each component. With one shared random draw use a period of (.09375,.09375). With two independent draws use (.09375,−.125). For the third case use the signed periods in an offset that the tint assigns to a local variable used by the child. Compare 16² at seed 0, 32 × 16 at seed 42 and 16 × 32 at seed 329779 in U8, U16, F16 and F32. The 36 originals and 36 ordinary reopens each match **15,360/15,360** pixels against both reference processor counts, maximum zero. The regression compares positive and negative periods with the full evaluator and checks the next random draw at four seeds. [Seeded offsets and routing controls](#rectangular-clouds-and-directional-noise-graphs-with-seeded-quadrant-offsets) + +### Rectangular Clouds and Directional Noise graphs with seeded quadrant offsets + +Clouds 1 v2 and Clouds 2 v2 each produce whole images for all **60/60 established originals and 15/15 archived saves** across the recorded passes. Each previously produced 58 originals and 14 saves. The 64 × 16 Directional Noise 3 v2 at seed 42 now matches **4,096/4,096** original pixels across four formats and another **4,096/4,096** after opening its four ordinary saves, at both reference processor counts. Earlier same-setting reference differences still leave the three roots in progress. [Earlier Cloud rectangles](#two-more-whole-outputs-in-noise-clouds-1-v2) · [Earlier Directional Noise results](#a-recovered-rectangle-and-repeated-outputs-in-directional-noise-3-v2) + +An empty quadrant can still move its children. When the shape and seed mode are literal and its only active expression is a pure branch offset, the evaluator binds the fixed operands and evaluates its seeded arithmetic for each visit. It schedules all children in their original order. A terminal group can also reuse a discarded stamp’s already-evaluated properties. After the allowance for discarded draws is spent, another cached miss must pay its arithmetic cost out of both the remaining property allowance and work saved on earlier evaluations. Drawing, repetition, stack and cache limits still apply. No package edits are needed. + +Use the grayscale output and retain tiling on both axes. For the Clouds settings use scale 5, disorder .8125, speed 1.4375, anisotropy .625, anisotropy angle −.21875, tile offset (−.3125,.4375) and non-square expansion on. Use seed 103034 for Clouds 1 v2 at 64 × 32. For Directional Noise 3 v2 at 64 × 16 use scale 2, disorder, speed, anisotropy and angle randomness .03125, both angles −.21875, tile offset (−.3125,.37890625) and non-square expansion on. Leave every other exposed property at its default. Set the precision on the node feeding the output. Save each configuration separately and reopen it at its stored size and seed. Both roots generate their inputs procedurally. + +| Root | Storage | Original · one · max | Original · eight · max | Saved · one · max | Saved · eight · max | +|---|---|---:|---:|---:|---:| +| Clouds 1 v2 | U8 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| Clouds 1 v2 | U16 | 2,047/2,048 · 1 | 2,046/2,048 · 1 | 2,047/2,048 · 1 | 2,047/2,048 · 1 | +| Clouds 1 v2 | F16 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| Clouds 1 v2 | F32 | 1,822/2,048 · 2.08616257e-07 | 1,821/2,048 · 2.68220901e-07 | 1,821/2,048 · 1.78813934e-07 | 1,821/2,048 · 1.78813934e-07 | +| Directional Noise 3 v2 | U8 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| Directional Noise 3 v2 | U16 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| Directional Noise 3 v2 | F16 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| Directional Noise 3 v2 | F32 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | + +All eight saved MaterialCraft outputs reproduce their source words, **12,288/12,288**. For the other panel rectangles use the same Clouds parameters, changing only the dimensions, seed and storage. The two tall comparisons include the last archived saved setting of each root. A dash marks an unmeasured file route. + +| Root | Size · seed · storage | Original · one · max | Original · eight · max | Archived save · one · max | Archived save · eight · max | +|---|---|---:|---:|---:|---:| +| Clouds 1 v2 | 32 × 64 · 103035 · U16 | 2,047/2,048 · 1 | 2,048/2,048 · 0 | 2,046/2,048 · 1 | 2,047/2,048 · 1 | +| Clouds 2 v2 | 64 × 32 · 103056 · F32 | 2,031/2,048 · 5.96046448e-08 | 2,029/2,048 · 5.96046448e-08 | — | — | +| Clouds 2 v2 | 32 × 64 · 103057 · U16 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | + +For an independent control, route a square through a quadrant with no shape. Connect its top-left and bottom-right children to the same square. Use four versions of the branch offset. Give the two components one shared random draw, two separate draws, a polar offset with seeded angle and radius, or an offset assigned to a local that the child's frame reads. Use three repeats for the shared draw and five otherwise. Set the square size to (.5,.25) and its grayscale swatch to .1875. Use 16² at seed 0, 32 × 16 at seed 42 and 16 × 32 at seed 329779 in each format. All 48 originals and 48 saved settings match **20,480/20,480** on each route, maximum zero on one and eight processors. The earlier 24 controls with seeded drawing tints reproduce **10,240/10,240** on each route. [Drawing tint controls](#bound-arithmetic-in-seeded-quadrant-properties) + +Two 4 × 4 regressions compare all sixteen values with the full expression evaluator. A four-by-32 iterate with a seeded branch translation previously exhausted a 64-visit budget and now completes. A six-by-40 iterate with shared terminal offsets and a live tint previously exhausted a 256-visit budget and now completes. The two graphs still reach their budgets at 32 and 160 respectively. + +### Bound arithmetic in seeded quadrant properties + +BNW Spots 3 v2 now produces images for all **62/62 established settings and 14/14 archived saves**. Dirt 4 v2 at 32 × 16, seed 105532, now renders all four output formats with **2,048/2,048** whole pixels exact on both processor counts. These rectangles previously returned a work-budget error. + +A grayscale quadrant can publish a frame offset and use a seeded tint with a live multiplier. For short arithmetic expressions in its offset, tint, branch translation, size and rotation, the evaluator binds fixed operands at the current drawing depth. Each visit executes the remaining operations in dependency order. A shared random register draws once, including across function arguments and the two tint branches. The frame assignment reaches the children and the current multiplier still applies. The evaluator charges at least a quarter of an ordinary property pass to a prepared draw. It tests coverage after the properties run. + +Both roots have no image inputs. For BNW Spots 3 v2 use 64 × 32, seed 194535, scale 3 and .34375 for disorder, speed and anisotropy. Set anisotropy angle .09375 and tile offset (0,.10546875). For Dirt 4 v2 use 32 × 16, seed 105532, scale 2, disorder .8125, speed 1.4375, anisotropy .625, angle −.21875 and tile offset (−.3125,.4375). Enable non-square expansion and leave the remaining properties at their defaults. Set the precision on the node feeding the output. Compare raw words after a fresh reference capture at each processor count. Integer errors are storage levels. + +| Root | Storage | Original · one · maximum | Original · eight · maximum | +|---|---|---:|---:| +| BNW Spots 3 v2 | U8 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| BNW Spots 3 v2 | U16 | 2,048/2,048 · 0 | 2,047/2,048 · 1 | +| BNW Spots 3 v2 | F16 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| BNW Spots 3 v2 | F32 | 1,756/2,048 · 1.1920929e-07 | 1,758/2,048 · 2.08616257e-07 | +| Dirt 4 v2 | U8 | 512/512 · 0 | 512/512 · 0 | +| Dirt 4 v2 | U16 | 512/512 · 0 | 512/512 · 0 | +| Dirt 4 v2 | F16 | 512/512 · 0 | 512/512 · 0 | +| Dirt 4 v2 | F32 | 512/512 · 0 | 512/512 · 0 | + +The earlier one- and eight-processor F32 captures of the BNW original gave 1,777/2,048 and 1,746/2,048 respectively, maximum 1.78813934e−7. The remaining archived U8 save at the same setting now matches all 2,048 pixels on both processor counts. An ordinary F32 save opened directly with its stored settings reproduces the original MaterialCraft F32 words. Its comparison with the two saved-file reference captures is 1,771/2,048 · 2.38418579e-07 on one and 1,771/2,048 · 2.38418579e-07 on eight. [Earlier original and archived settings](#seeded-quadrant-properties-with-a-live-tint-multiplier) + +Repeat the independent square-and-four-children control with the inner Iterate inheriting the outer seed. Use four outer iterations with gain (1 + number) × .25 and seven with gain (1 + number) × .125, two inner repeats and the existing three size/seed pairs in U8, U16, F16 and F32. The 24 originals and 24 ordinary reopens each match **10,240/10,240** pixels on one and eight processors, maximum zero. Resetting the inner seed also preserves the 24 original and 24 archived saved comparisons. In the 4 × 4 regression, six outer and forty inner iterations complete with a visit limit of 96. Before the change the same case exhausted its budget. The sixteen output values match the equivalent graph with a computed frame offset and a larger budget. [Procedural controls and size settings](#seeded-quadrant-properties-with-a-live-tint-multiplier) + +This revision still stopped at the two Clouds rectangles and the 64 × 16 Directional Noise 3 v2 graph. The subsequent traversal change produces complete images for those settings. [Raw comparisons](#rectangular-clouds-and-directional-noise-graphs-with-seeded-quadrant-offsets) BNW Spots 3 v2 has repeat-dependent F32 differences, and Dirt 4 v2 retains the previously measured differences at other settings. [Repeated BNW measurements](#repeated-f32-captures-of-28-noise-roots) [Clouds rectangular settings](#two-more-whole-outputs-in-noise-clouds-1-v2) + +#### Ordinary saves and release cook times for the two rectangles + +Save each of the four configured output formats separately, close the package, and reopen it directly at its saved path. Use the BNW Spots 3 v2 and Dirt 4 v2 dimensions, seeds and parameters above. All eight saved MaterialCraft outputs reproduce their source words, **10,240/10,240 pixels** in total. The reference columns compare the positional raw values at the stored precision. The final two columns compare the reference’s own original and saved captures. + +| Root | Storage | MaterialCraft save · one · max | MaterialCraft save · eight · max | Reference original vs. save · one · max | Reference original vs. save · eight · max | +|---|---|---:|---:|---:|---:| +| BNW Spots 3 v2 | U8 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| BNW Spots 3 v2 | U16 | 2,047/2,048 · 1 | 2,047/2,048 · 1 | 2,047/2,048 · 1 | 2,046/2,048 · 1 | +| BNW Spots 3 v2 | F16 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| BNW Spots 3 v2 | F32 | 1,771/2,048 · 2.38418579e-07 | 1,771/2,048 · 2.38418579e-07 | 1,752/2,048 · 2.38418579e-07 | 1,745/2,048 · 2.38418579e-07 | +| Dirt 4 v2 | U8 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| Dirt 4 v2 | U16 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| Dirt 4 v2 | F16 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| Dirt 4 v2 | F32 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | + +At 16² F32, run three paired timings of the previous and current releases with a single cook thread. Use both orders within the three pairs. Use seed 0 and defaults for BNW Spots 3 v2 and seed 105526 and defaults for Dirt 4 v2. Time the engine cook with the package already loaded. Every run reproduced its original pixel hash. Median time on the measurement machine went from 9.62 to 4.39 seconds for BNW Spots 3 v2 and from 31.85 to 13.68 seconds for Dirt 4 v2. + +The 64 × 32 Directional Noise 2 v2 case at seed 195000 and the 128 × 32 Dirt 4 v2 case at seed 433595 still reach the execution limit in this release. On the latter, the one- and eight-processor reference captures agree at 4,064/4,096 pixels with a maximum difference of .00407773256. [Dimensions and changed Dirt 4 v2 parameters](#repeated-f32-captures-of-28-noise-roots) + +### Addition and maximum blending in Directional Noise 1 v2 + +At 16² F32, seed 103813 and defaults, the first two FX-Maps match all 16 and 64 U8 pixels on all six reads. With the final draws disabled, the background alone matches all 256 F32 pixels. The complete final draw with its original background gives 158/256 on each of three one-processor reads. Disconnecting the background leaves differences in the additive result. Changing the final wave stamps to maximum blending gives all 256 pixels exact on every read, with 256 distinct values in the image. + +To reproduce, alternate the 16² setting with 32² at seed 113. At 32² set scale 2, disorder .37, speed .6, anisotropy .3, anisotropy angle and angle .125, angle randomness .2 and tile offset (.17,.29). Keep the other defaults and use the grayscale F32 output. Read each setting three times on one reference processor and three times on eight. The two initial FX-Maps at 32² also match all 64 and 256 U8 pixels on every read. For the background-only control, give the drawing quadrants of the last FX-Map the empty shape. In the disconnected cases preserve the drawing data and original seeds. For the one-path control retain only child slots 0, 3, 1, 2, 0 and 3 in the first six quadrant subdivisions. Keep both Iterate nodes and all lower connections. + +| Final FX-Map | 16² · one · max | 16² · eight · max | 32² · one · max | 32² · eight · max | +|---|---:|---:|---:|---:| +| Original graph | 158/256 · 1.78813934e-07 | 149–169/256 · 1.1920929e-07 | 604/1,024 · 2.38418579e-07 | 615/1,024 · 2.38418579e-07 | +| Background only | 256/256 · 0 | 256/256 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| Disconnected background, additive waves | 125/256 · 8.94069672e-08 | 146–161/256 · 1.1920929e-07 | 491/1,024 · 8.94069672e-08 | 537/1,024 · 1.1920929e-07 | +| Disconnected background, maximum of waves | 256/256 · 0 | 256/256 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| Disconnected background, maximum of squares | 256/256 · 0 | 256/256 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| Disconnected background, one path through six subdivisions | 256/256 · 0 | 256/256 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | + +The 16² columns give the range of exact pixels and the largest absolute error over three returns. The 32² columns use the first return on each processor count. Combining the six new 16² full outputs with the earlier ten gives 55 positions with the same word in every capture. MaterialCraft matches 54. At (6,9) the difference is 2.98023224e−8. Each application produced full images at both sizes. [Earlier ten captures](#repeated-f32-captures-of-28-noise-roots) + +Configure the disconnected wave controls at each size and use ordinary Save. Open all four files without changing their stored parameters. All 2,560 MaterialCraft pixels reproduce their respective pre-save words. + +| Reopened wave control | Size | One processor · max | Eight processors · max | +|---|---|---:|---:| +| Additive | 16² | 125/256 · 8.94069672e-08 | 125/256 · 8.94069672e-08 | +| Additive | 32² | 537/1,024 · 8.94069672e-08 | 537/1,024 · 8.94069672e-08 | +| Maximum | 16² | 256/256 · 0 | 256/256 · 0 | +| Maximum | 32² | 1,024/1,024 · 0 | 1,024/1,024 · 0 | + +The maximum-blend and isolated-path comparisons provide controls for the stamp arithmetic. A repeatable overlap order that reproduces the additive images remains unresolved. + +### Repeated F32 captures of 28 noise roots + +At one fixed setting per root, compare one MaterialCraft render with five reference returns at one processor and five at eight. Between returns, render a second setting at a different size to invalidate the previous image. Read the raw F32 output after every return. The same processor count produced multiple buffers on 8 of the 28 roots at one processor and on 25 at eight. + +Of the 27 whole images MaterialCraft produced, 19 matched every pixel that had the same F32 word across all ten captures. In total, **11,403/11,445** such pixels matched. In 18 of the 27 images, every position matched a value seen at that position in at least one capture. Those matches can belong to different frames. The 128 × 32 Dirt 4 v2 graph reached the execution budget. + +Each five-count column gives the number of exact pixels in each successive whole frame. The maximum is the largest absolute error across those ten frames. The last column counts exact pixels among those constant across all ten and gives their maximum absolute error. A dash indicates that MaterialCraft returned an error. + +| Root package | Size · seed | Five at one processor | Five at eight processors | Whole maximum | Constant pixels · maximum | +|---|---|---|---|---:|---| +| `noise_bnw_spots_1` | 16² · 0 | 256, 256, 256, 256, 256 | 155, 166, 169, 165, 161 | 1.1920929e-07 | 90/90 · 0 | +| `noise_bnw_spots_1_v2` | 16² · 0 | 256, 256, 256, 256, 256 | 229, 231, 235, 225, 226 | 1.1920929e-07 | 211/211 · 0 | +| `noise_bnw_spots_3` | 64² · 42 | 4094, 4093, 4094, 4091, 4093 | 4095, 4094, 4092, 4093, 4094 | 1.0728836e-05 | 4,089/4,089 · 0 | +| `noise_bnw_spots_3_v2` | 16² · 0 | 232, 232, 233, 232, 232 | 238, 236, 234, 236, 233 | 5.9604645e-08 | 207/211 · 5.9604645e-08 | +| `noise_clouds_1` | 32² · 103019 | 1023, 1023, 1023, 1023, 1023 | 1024, 1023, 1023, 1024, 1024 | 1.5258789e-05 | 1,022/1,022 · 0 | +| `noise_clouds_1_v2` | 16² · 0 | 256, 256, 256, 256, 256 | 215, 223, 220, 220, 214 | 1.1920929e-07 | 198/198 · 0 | +| `noise_clouds_2_v2` | 16² · 103050 | 256, 256, 256, 256, 256 | 252, 249, 250, 252, 252 | 5.9604645e-08 | 247/247 · 0 | +| `noise_directional_noise_1` | 16² · 103800 | 256, 256, 256, 256, 256 | 255, 255, 255, 255, 256 | 1.1444092e-05 | 255/255 · 0 | +| `noise_directional_noise_1_v2` | 16² · 103813 | 158, 158, 158, 158, 158 | 158, 156, 165, 166, 159 | 1.7881393e-07 | 63/67 · 2.9802322e-08 | +| `noise_directional_noise_2` | 16² · 103826 | 75, 75, 75, 74, 75 | 74, 83, 82, 85, 71 | 1.4901161e-07 | 3/5 · 5.9604645e-08 | +| `noise_directional_noise_2_v2` | 16² · 103839 | 148, 148, 157, 151, 150 | 167, 162, 167, 153, 161 | 8.9406967e-08 | 48/49 · 5.9604645e-08 | +| `noise_directional_noise_3` | 32² · 113 | 1010, 1014, 1013, 1015, 1014 | 1022, 1013, 1020, 1022, 1020 | 2.5361776e-05 | 1,007/1,007 · 0 | +| `noise_directional_noise_4` | 16² · 103878 | 127, 127, 127, 127, 127 | 148, 174, 135, 122, 128 | 2.682209e-07 | 48/51 · 5.9604645e-08 | +| `noise_directional_noise_4_v2` | 16² · 0 | 110, 110, 110, 110, 110 | 142, 133, 123, 174, 136 | 2.3841858e-07 | 47/58 · 2.3841858e-07 | +| `noise_dirt_1` | 16² · 105424 | 256, 256, 256, 256, 256 | 250, 246, 248, 246, 247 | 5.9604645e-08 | 242/242 · 0 | +| `noise_dirt_1_v2` | 16² · 105441 | 256, 256, 256, 256, 255 | 251, 251, 253, 253, 253 | 5.9604645e-08 | 248/248 · 0 | +| `noise_dirt_3` | 16² · 105475 | 254, 254, 254, 254, 254 | 254, 254, 255, 254, 255 | 2.9802322e-08 | 253/253 · 0 | +| `noise_dirt_3_v2` | 16² · 105492 | 256, 256, 256, 256, 256 | 255, 256, 255, 256, 255 | 7.4505806e-09 | 255/255 · 0 | +| `noise_dirt_4` | 16² · 105509 | 238, 238, 238, 238, 238 | 256, 256, 256, 256, 256 | 6.1035156e-05 | 238/238 · 0 | +| `noise_dirt_4_v2` | 128 × 32 · 433595 | — | — | — | —/4,064 · — | +| `noise_dirt_5` | 32² · 105545 | 1023, 1023, 1023, 1023, 1023 | 1024, 1024, 1024, 1024, 1024 | 5.081296e-05 | 1,023/1,023 · 0 | +| `noise_dirt_5_v2` | 16² · 105560 | 237, 237, 237, 237, 237 | 230, 232, 231, 232, 233 | 5.9604645e-08 | 208/209 · 7.4505806e-09 | +| `noise_dirt_gradient` | 16 × 32 · 281741 | 512, 512, 512, 512, 512 | 511, 511, 511, 511, 511 | 1.5258789e-05 | 511/511 · 0 | +| `noise_dirt_gradient_v2` | 16² · 105594 | 185, 177, 177, 177, 172 | 180, 188, 184, 188, 193 | 2.3841858e-07 | 124/124 · 0 | +| `noise_fur_2` | 16² · 75892 | 256, 256, 256, 256, 256 | 223, 231, 213, 199, 202 | 5.9604645e-08 | 183/183 · 0 | +| `noise_fur_3` | 16² · 75899 | 174, 174, 174, 174, 174 | 201, 198, 187, 177, 201 | 5.9604645e-08 | 134/150 · 2.9802322e-08 | +| `noise_gaussian_spots_2` | 16² · 87914 | 256, 256, 256, 256, 256 | 241, 237, 237, 238, 239 | 5.9604645e-08 | 225/225 · 0 | +| `noise_gaussian_spots_2_v2` | 16² · 87921 | 256, 256, 256, 256, 256 | 236, 236, 243, 231, 236 | 2.9802322e-08 | 224/224 · 0 | + +The procedural generators have no image inputs. Use defaults except for these settings. BNW Spots 3 uses scale 2 and disorder .37. Clouds 1 uses scale 3, disorder .3125 and non-square expansion off. Directional Noise 3 uses scale 2, disorder .37, angle .125 and angle random .2. Dirt 5 uses scale 1, disorder .3125 and non-square expansion off. For Dirt 4 v2 at 128 × 32, set scale 3, disorder, speed and anisotropy .046875, anisotropy angle −.203125, tile offset (−.296875,.365234375) and non-square expansion on. + +For the intervening setting, use 32² at seed 113. Set scale 2 and disorder .37 when present. For the v2 roots set speed .6, anisotropy .3, anisotropy angle .125 and tile offset (.17,.29) where exposed. Use roughness .6 for both BNW Spots 1 versions and angle .125 with angle random .2 for the directional roots. Dirt Gradient and Dirt Gradient v2 use the disorder fields only. Fur 2 uses scale 2, waves scale .25 and waves rotation .2. Fur 3 uses scale 2, disorder .37 and waves amount 3. The exceptions use 16² and defaults at seeds 103017 for Clouds 1, 103852 for Directional Noise 3 and 105543 for Dirt 5. + +#### The final drawing stage of BNW Spots 3 v2 + +At 16², seed 0 and defaults, read all three FX-Map outputs on twelve more returns per processor count. All 24 renders matched the first two stages at **16/16 and 64/64 U8 pixels**, maximum zero. Combining the 24 final F32 reads with the preceding ten produced 33 distinct whole images. They matched MaterialCraft at 223 to 241 of 256 pixels, with a maximum whole-image error of 1.1920929e−7. Of 185 pixels constant across all 34, 184 matched. At (8,10), all 34 returned `0x3eb84742` and MaterialCraft returned `0x3eb84743`, a difference of 2.9802322e−8. Each of the other 255 pixels matched at least one full capture. + +Keep the outer Iterate’s count expression connected to the first input of a Sequence and return a fixed count from its second input. Leave the three FX-Map connections and six four-way quadrant subdivisions intact. Use the functions library for the reusable math calls. For the last three rows, use a count of one and retain all four children in the first three, four or five subdivisions. At each remaining subdivision keep only the original slot from (0,3,1,2,0,3), indexed by depth. Alternate the same 32² and 16² cases and collect five returns per processor count. + +| Outer repeats · paths per repeat | Exact whole pixels of 256, range over ten returns | Whole maximum | Constant pixels · maximum | Distinct whole buffers | +|---|---:|---:|---|---:| +| 0 · 4,096 | 256 | 0 | 256/256 · 0 | 1 | +| 1 · 4,096 | 230–243 | 5.9604645e-08 | 202/202 · 0 | 10 | +| 2 · 4,096 | 227–240 | 5.9604645e-08 | 191/191 · 0 | 10 | +| 4 · 4,096 | 228–246 | 1.1920929e-07 | 201/201 · 0 | 10 | +| 8 · 4,096 | 228–238 | 1.1920929e-07 | 201/203 · 2.9802322e-08 | 10 | +| 1 · 64 | 256 | 0 | 256/256 · 0 | 1 | +| 1 · 256 | 255–256 | 5.9604645e-08 | 255/255 · 0 | 2 | +| 1 · 1,024 | 254–255 | 5.9604645e-08 | 249/249 · 0 | 5 | + +At one, two and four outer repeats the reference returned both neighboring F32 words at (8,10). At eight repeats it returned the lower word on all ten captures. The reduced one-repeat graphs with 64, 256 or 1,024 active paths each match every constant pixel. The full root remains in progress. + +### Working precision of Blur inputs + +When an equal-sized normalized input feeds Blur and exactly one size depends on a graph parameter, the filter reads the texture at its floating-point destination precision. U8 and U16 inputs to F16 Blur are stored at half precision before the first pass. F32 Blur retains the normalized values and samples them as floats. The second pass reads the stored horizontal result. For fractional taps, the sampler precision affects the result even with identical source texels. + +Use the 16² U8 field of 58 with four changed neighbors from the Sharpen comparison. Have the input, Blur, both or neither read an exposed .375 and return (0,0) as the relative size offset. The fixed and both-reader settings agree. The two single-reader settings also agree. Each cell gives the value read from the reference output on one and eight processors. [Procedural field and size functions](#half-precision-inputs-to-sharpen) + +| Intensity · destination | Pixel | Fixed or both sizes | One size reads the parameter | +|---|---|---:|---:| +| 24 · F16 | (7,8) | .185546875 | .1854248046875 | +| 32 · F16 | (6,7) | .2100830078125 | .2099609375 | +| 32 · F32 | (6,5) | `0x3e673a97` | `0x3e673a99` | + +At intensity 32 with one size reading the parameter, filtering the already stored half pixels with F32 weights gives 251/256, maximum .0001220703125. Sampling them at F16 gives 256/256. For the F32 destination, the previous normalized sampler gave 213/256, maximum 9.9837779999e−7. Sampling the same normalized values at F32 gives 256/256. + +The first 55 Blur settings reuse the procedural grayscale and RGBA fields, sizes and seeds of the Sharpen series, with intensity 24. They improved from **26,321/30,976** to **30,976/30,976**, maximum .00048828125 to zero. The 55 Transformation 2D controls use matrix (.875,.125,−.125,.875) with centered translation and reproduce another 30,976/30,976 unchanged. For a separate intensity sweep use 0, 3.2, 10, 24 and 32 at each of the following settings. The fixed gray U8 control is 16² at seed 0. The variable-size gray U16 source uses 16² at seed 512. The gray U8 source with variable-size Blur uses 16 × 32 at seed 5034. The RGBA U16 source with its size driven uses 64 × 32 at seed 6211. Drive both sizes at 64², seed 4242, in the RGBA U16 control. Store all four output formats and compare every channel. + +| Intensity sweep · 25 settings per format | Before · maximum | After · maximum | +|---|---:|---:| +| U8 | 35,840/35,840 · 0 | 35,840/35,840 · 0 | +| U16 | 35,840/35,840 · 0 | 35,840/35,840 · 0 | +| F16 | 30,839/35,840 · 0.00048828125 | 35,840/35,840 · 0 | +| F32 | 31,004/35,840 · 6.169080734e-06 | 35,840/35,840 · 0 | + +All 100 sweep settings now match **143,360/143,360** on both processor counts. Four F32 fractional or wider filters previously matched 28/4,864. Binding an F32 field with the exact normalized values from the corresponding input bridge independently reproduced 4,864/4,864 with zero error. + +In Dirt 1 use the 16² default at seed 0, 32 × 16 at seed 42 with Disorder .375, and 32² at seed 93 with Disorder .8125. Store U8, U16, F16 and F32 on the final Blend. With the original U8 quarter-size Blur at intensity 3.2, all 7,168 output pixels match. For the other cases, bring Blur to the full U16 FX-Map extent. Use intensity 24 and F16 on Blur, then intensity 32 and F32. Try fixed sizes, have only Blur read Disorder before returning (0,0) for the size, then have both nodes read it. The following rows cover the single-reader path. All three FX-Map inputs agree in each comparison. + +| Blur precision · final output | Before · maximum | After · maximum | +|---|---:|---:| +| F16 · U8 | 1,789/1,792 · 1 | 1,792/1,792 · 0 | +| F16 · U16 | 1,533/1,792 · 8 | 1,792/1,792 · 0 | +| F16 · F16 | 1,631/1,792 · 0.00048828125 | 1,792/1,792 · 0 | +| F16 · F32 | 1,530/1,792 · 0.0001186728477 | 1,792/1,792 · 0 | +| F32 · U8 | 1,791/1,792 · 1 | 1,792/1,792 · 0 | +| F32 · U16 | 1,662/1,792 · 1 | 1,792/1,792 · 0 | +| F32 · F16 | 1,763/1,792 · 0.0001220703125 | 1,792/1,792 · 0 | +| F32 · F32 | 233/1,792 · 7.525086403e-06 | 1,792/1,792 · 0 | + +At Blur itself the three F16 cases improved from 1,334/1,792 · 0.0001220703125 to 1,792/1,792 · 0. The three F32 cases improved from 1/1,792 · 4.023313522e-06 to 1,792/1,792 · 0. The fixed and both-reader controls match every final output on both processors. Across the original and six changed Blur configurations all 84 final renders now match **50,176/50,176 pixels**, maximum zero. + +Use ordinary Save on configured cases and reopen without edits. The 16 direct filter files reproduce 15,360/15,360 pixels. The 10 whole Dirt 1 files reproduce 6,656/6,656 pixels. Each also matches the corresponding pre-save reference on one and eight processors, maximum zero. Dirt 1 remains in progress for its earlier processor-dependent results. [Original Dirt 1 comparison](#four-child-pattern-order-as-a-tile-copy-batch-fills) + +### Keeping an explicit file link when the configured library changes + +Ordinary Save keeps an explicit file reference tied to the file it resolved when the caller was opened. Previously, a caller outside the configured library could acquire a catalog alias when its explicitly linked package matched bundled bytes. Changing the configured library then redirected that saved caller to a different file. + +Use the four configured Waveform v2 callers with U8, U16, F16 and F32 outputs. Put two copies of the hash package in separate library directories. Keep the first original. In the second, set the result of the two-component hash function to .375. Keep the general math dependency equal in both. Open the callers outside either library with the first library configured and use ordinary Save. For each size try the relative filename pointing into the first directory and an explicitly authored catalog alias. Verify both linked file hashes before and after each caller save. Then save the first hash package at its own path so the reference compiler can read its version. Keep the saved callers fixed and reopen them with each directory configured. [Caller dimensions, settings and original function edit](#editing-the-linked-function-with-a-waveform-caller-open) + +With the second library configured, the previous relative-file saves matched **8,410/8,448** pixels of the original-function captures. All 38 differences were in the 16² U16 case at seed 725048, with a maximum of 65,535 levels. The corrected relative-file saves match **8,448/8,448** under either library, maximum zero. The four explicit catalog callers follow the configured library, matching all 8,448 original-function pixels with the first library and all 8,448 edited-function pixels with the second. Each comparison uses the raw words from both one and eight reference processors. A fresh open of the four corrected relative-file saves in the reference app also reproduced **8,448/8,448** original pixels at each processor count. + +The regression starts with an explicit disk reference to a bundled grayscale switch. It checks the resolved file after saving and reopening the caller and the catalog alias in a separate portable copy. Its in-place assertion failed on the previous engine. The older detached-package compiler behavior is recorded separately. [Reference app’s ordinary Save](#ordinary-save-in-the-reference-app-with-the-same-live-dependencies) + +#### Keeping catalog links when saving a caller inside its library + +An ordinary Save previously converted an explicit catalog link to a relative filename when the caller was inside the selected library. A later change of library still picked the old function. The in-place writer now preserves the authored choice for both graph instances and function calls. + +Create two library directories with the same general math package. Put the original hash function in the first and set its two-component hash result to .375 in the second. Under the first directory, create a child folder for callers. Use the four configured Waveform v2 inputs from the preceding comparison. In each configuration create one caller pointing to the hash package by its parent-relative filename and one using its catalog URI. Both use the catalog URI for the general math functions. With the first library selected, save each caller at its existing path. Keep all four external package files fixed and verify their hashes. Reopen all eight saved callers with each library selected. [Sizes, seeds and output formats](#saving-older-linked-packages-at-their-existing-paths) + +| Authored hash link | Selected library on reopen | Expected hash function | Previous exact · maximum | Current exact · maximum | +|---|---|---|---:|---:| +| Relative file | First or second | Original file in first | 8,448/8,448 · 0 | 8,448/8,448 · 0 | +| Catalog | First | Original in selected library | 8,448/8,448 · 0 | 8,448/8,448 · 0 | +| Catalog | Second | Edited in selected library | 8,410/8,448 · 65,535 U16 levels | 8,448/8,448 · 0 | + +Each count holds separately against the one- and eight-processor reference buffers. At 16², seed 725048, the corrected catalog caller reproduced all 256 edited U16 pixels. The earlier file choice reproduced 218. The U8, F16 and F32 cases reproduced all 8,192 pixels with either hash function. The regression saves two graph instances pointing to the same bundled switch through different link forms. Previously both serialized as the same filename. + +Ordinary Save in the reference app preserved both catalog URIs in all four catalog callers. Opening those files afresh there reproduced the original **8,448/8,448** pixels on each processor count, maximum zero. The same fresh-open comparison of the four MaterialCraft-saved catalog callers also reproduced **8,448/8,448**. The older external-file compiler limitation remains recorded for Waveform v2. [Older linked packages](#ordinary-save-in-the-reference-app-with-the-same-live-dependencies) + +### Points Preview graph links after switching the configured library + +Place four configured callers inside the first of two library directories. Use compatible spline dependencies and the generated point strip. Place the same licensed monospace font at the external filename declared by each spline package. In the second spline package connect a .375 grayscale U8 Uniform to the Points Preview output. Save two versions of each caller in the first directory. Give one a relative filename pointing to the first spline package and the other the catalog URI for that package. Close and reopen each caller with each library selected. The four U8 views are the four-point points-only and zero-point combined views at 16² and seed 0, eight-point labels at 32² and seed 42, and twelve points with labels at 32 × 16 and seed 507031. [Procedural inputs, font and external packages](#saving-older-linked-packages-at-their-existing-paths) + +| In-place link | First library selected | Second library selected | Maximum error against the selected source | +|---|---:|---:|---:| +| Relative filename | Original 2,048/2,048 | Original 2,048/2,048 | 0 U8 levels | +| Catalog URI | Original 2,048/2,048 | Edited 2,048/2,048 | 0 U8 levels | + +Both reference processor counts give the same expected values. The previous writer turned the catalog URI into a relative filename. With the second library selected, it reproduced **0/2,048** edited pixels, maximum error 159 levels. Both dependency trees kept their package hashes through all eight caller saves. As a separate reference check, open the same four file-linked caller bytes beside each independent library, preserving the relative location of the generated image. Fresh reference opens at one and eight processors give **2,048/2,048** for each library, maximum zero. An initial copy supplied the first font under its friendly filename, while the saved package declared a content-addressed filename. This gave 1,992/2,048 in the reference, maximum 135 U8 levels. Providing the same font bytes at the declared path restored the 56 label pixels with the caller and spline package bytes unchanged. The newer writer’s root measurements use compatible linked packages. The older detached-package result remains open. [Reference saves with older links](#ordinary-save-in-the-reference-app-with-the-same-live-dependencies) + +### Saving a catalog dependency while its callers stay open + +A caller could keep an old graph or function after another tab saved the physical file selected by its catalog link. The open session refreshed the disk filename and retained an earlier snapshot under the catalog URI. Ordinary Save now refreshes the catalog entries for that file. It reads nested references relative to each catalog entry. An explicit dependency supplied by a project retains its own value. + +Keep one caller open and export its original output. Open the linked package by its physical filename in a second tab. For Points Preview, add a U8 grayscale Uniform at .375 to the linked graph, connect it to the output and save. For Waveform v2, set the linked two-component hash function’s result to .375 and save. Return to the caller tab and export. Undo the connection or function edit, save the dependency a second time and export from the still-open caller. Verify the caller’s file hash through the three exports. Repeat with a relative filename and a catalog URI in each configured caller. [Four Points Preview views and font placement](#points-preview-graph-links-after-switching-the-configured-library) · [Four Waveform sizes, seeds and storage formats](#saving-older-linked-packages-at-their-existing-paths) + +Each cell gives exact pixels against fresh reference buffers for the same saved source state, followed by maximum absolute error. The counts hold separately at one and eight reference processors. Points Preview uses U8. Waveform uses U8, U16, F16 and F32. The previous Waveform differences are all in U16. + +| Caller and link | Original | Saved edit before fix | Saved edit after fix | Undo and save | +|---|---:|---:|---:|---:| +| Points Preview · relative filename | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| Points Preview · catalog URI | 2,048/2,048 · 0 | 0/2,048 · 159 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| Waveform v2 · relative filename | 8,448/8,448 · 0 | 8,448/8,448 · 0 | 8,448/8,448 · 0 | 8,448/8,448 · 0 | +| Waveform v2 · catalog URI | 8,448/8,448 · 0 | 8,410/8,448 · 65,535 | 8,448/8,448 · 0 | 8,448/8,448 · 0 | + +All 16 caller files kept their original bytes. Fresh reference opens of the relative-file callers against the newly saved graph and function packages also match **10,496/10,496** pixels after the edit and **10,496/10,496** after undo, at each processor count. For this check, keep the caller bytes, the locations of the generated image and font, and the saved dependency bytes fixed. The function regression also checks an installed catalog source, one first loaded by the caller, and a project-supplied override. Saving .375 or .625 refreshes the corresponding file-backed entry. The override stays at .5 after a physical save of .75. The previously measured compiler behavior with older external package headers remains open. [Ordinary saves of callers with older linked files](#ordinary-save-in-the-reference-app-with-the-same-live-dependencies) + +### Editing the linked function with a waveform caller open + +Use the four configured Waveform v2 files and the relative function package. In a single MaterialCraft session, open a caller and export its Waveform output as raw linear F32. Open `curve_lookup.sbs` in another tab, set the result of `hash21` to a scalar constant .375 and save the linked file. Return to the caller tab and export again. Undo the function edit in its tab, save there, return to the caller and export a third time. Leave the caller open throughout and verify its file hash before and after. [Configured callers and dependency](#saving-older-linked-packages-at-their-existing-paths) + +Compare each export at the caller’s stored precision with reference captures at one and eight processors. Original, edited and restored states each match **8,448/8,448 pixels**, maximum zero. At 16², seed 725048, 38 of the 256 U16 pixels changed, with a maximum change of 65,535 levels. Undo restored all 256 original values. The U8, F16 and F32 settings retained all 8,192 of their original pixels after the edit. All four caller files kept the same bytes and relative function path. Opening the same callers afresh in MaterialCraft also reproduced both the edited and restored images. + +### Saving older linked packages at their existing paths + +An ordinary Save in MaterialCraft can update an older linked SBS at the same relative path. Both callers below then reopen in the reference app with their original connections. Saving just the caller leaves the older linked files at version `0.1.3`. The reference compiler rejected both configured callers in that state. After saving the linked files, it accepted the same caller bytes. All counts below compare whole pixels at native storage precision on both one and eight reference processors. + +| Root | Settings applied after opening the caller | Configured files opened directly | Maximum channel error | +|---|---:|---:|---:| +| Points Preview | 17,920/17,920 across 30 settings | 2,048/2,048 across 4 saves | 0 U8 levels | +| Waveform v2 | 179,968/179,968 across 43 settings | 8,448/8,448 across 4 saves | 0 in U8, U16, F16 and F32 | + +For Points Preview, bind the generated two-row ellipse field and place the same licensed monospace face at `resources/LiberationMono-Regular.ttf` relative to the spline package. Use counts 4, 8 and 12 with points only, labels only and both, plus count 0 with both. Use 16² at seed 0, 32² at seed 42 and 32 × 16 at seed 507031. Open and save `blend_switch.sbs`, `quad_transform.sbs`, `spline_tools.sbs`, `uv_mapper.sbs` and `value_get_size.sbs` in place. Leave the already compatible `functions.sbs` as supplied. For the four-point, labels-only compiler control, all 31 proper subsets of the five saves failed to compile. Saving all five succeeded. The new package versions read `1.1.0.202401`. The spline package retains 51 graphs, 39 functions and the relative font resource. All 30 renders also match the earlier compatible-library buffers. [Settings, inputs and matched fonts](#overlapping-glyphs-and-points-preview-file-handoff) + +To check that the link stays live, use the four-point points-only, eight-point labels-only, twelve-point combined and zero-point combined callers. In the linked graph, connect a grayscale Uniform set to .375 and U8 to the output, then save. The four callers kept their original bytes. Across the three sizes every one of their 7,168 pixels changed, and both applications returned 96 at each pixel. Reconnect the original Pixel Processor and save again. The reference session's already-loaded callers still returned 96, with 0/7,168 matching the restored computation and a maximum difference of 159 U8 levels. Loading the same four caller paths afresh reproduced the original **7,168/7,168** in both applications, maximum zero. + +For Waveform v2, keep the existing relative `curve_lookup.sbs` filename and the `sbs://functions.sbs` library link. Open the older relative file in MaterialCraft and save it at its own path. All seven function identifiers survive. The three caller files retained their bytes. Reuse the seven sizes, seeds, changed parameters and fixed fields of the earlier waveform series. The three groups respectively reproduce 109,056/109,056, 44,288/44,288 and 26,624/26,624 pixels of their earlier compatible-file captures. [Full waveform settings](#reopened-starburst-symmetry-tile-and-waveform-graphs) + +For the direct-open column, configure and save the callers **before** saving their dependencies. For points, use counts 4, 8, 12 and 0 with the four views above at 16², 32², 32 × 16 and 16² respectively. For waveform, use U8 at 64 × 32, seed 725259, U16 at 16², seed 725048, F16 at 32 × 64, seed 769164, and F32 at 32 × 128, seed 725470. Save the linked files in place, verify the eight caller hashes still match, and open the callers directly with their stored inputs, sizes, seeds and parameters. Both applications reproduced the previous same-setting buffers. The two roots remain in progress for caller-only saves where the external packages keep their older encoding. + +#### Ordinary Save in the reference app with the same live dependencies + +Open the four configured Points Preview callers and the 16² U16 Waveform v2 caller from the preceding comparison. Supply the generated point-list image at the caller’s declared path and the same licensed font at the spline package’s declared path. Keep the linked packages at version `0.1.3`. Use the reference app’s own ordinary Save on each caller. The saved callers retain their relative SBS dependency names and the linked package bytes keep their original hashes. The point-list images move to the sidecar directories named by the saved callers. Each copied image has the same file hash as its procedural input. + +The reference compiler rejected all five reference-saved callers while the external packages still carried their three-part headers. It reported the version of the linked file as unreadable. The previous caller-only saves from MaterialCraft gave the same compiler result. In a separate directory keep the reference-saved callers and all their image sidecars byte-for-byte identical. Open and save the five linked point packages or the single waveform hash package at their respective paths in MaterialCraft. The compiler then accepted every caller. + +| Reference-saved caller opened directly | Stored pixels exact at one processor | At eight | Against earlier compatible caller | Maximum | +|---|---:|---:|---:|---:| +| Four Points Preview views, U8 | 2,048/2,048 | 2,048/2,048 | 2,048/2,048 | 0 | +| Waveform v2, U16, seed 725048 | 256/256 | 256/256 | 256/256 | 0 | + +As an independent control, use the 16² F32 caller returning (called value + .21875, 0, .53125, .75) at seed 596087. Set the file-based function result to .34375. Ordinary Save in the reference app retained the relative function name with either dependency header. The four-part input compiled directly. The three-part input compiled after saving the function file at its original path. Both gave **256/256 RGBA pixels** at each processor count, maximum error zero. Points Preview and Waveform v2 remain in progress for the older detached files. [Original scalar control and tested headers](#reopening-a-portable-copy-with-detached-function-packages) + +### Half-precision inputs to Sharpen + +Sharpen reads equal-sized normalized integer inputs at half precision when it writes F16 and exactly one of the two sizes depends on a graph parameter. The shared evaluator now applies that conversion before the four-neighbor filter. The 55 grayscale and RGBA probes improved from **23,181/30,976** to **30,976/30,976** pixels on both reference processor counts. The maximum component error fell from .001953125 to zero. + +For a minimal case, fill a 16² U8 input with 58. Store 5 at (7,8), 78 at (9,8), 31 at (8,7) and 42 at (8,9). Use intensity 1 and an F16 destination. Have the source, the filter, both or neither read an exposed .375 and return (0,0) as the relative size offset. At (9,8) the two single-reader cases give .61865234375. The other two give .619140625. The four images now match all 1,024 pixels. For the larger series use the same procedural fields, sizes and seeds as the Levels comparison, intensity 1 for gray and .4375 for color. Include U8, U16, F16 and F32 sources, and check the F32 output control. Six configured ordinary saves reproduce all 3,584 pixels. The 130 repeated Levels controls retain 56,320/56,320. [Procedural inputs and size functions](#half-precision-inputs-to-levels) + +In Dirt 4 and Dirt 4 v2, edit the final Sharpen size property so it has the same extent as its FX-Map input. Set it first to half the parent on both axes, then to the input size with zero offset. Use a 16² parent, seed 0 and defaults. Repeat at 32 × 16, seed 93, scale 1, disorder .3125 and non-square expansion disabled. Store U8, U16, F16 and F32 on each route. Both processor counts agree at the FX-Map, Sharpen and output. The first root feeds U16 into the filter and the second feeds U8. + +| Root and size mode | F16 before · maximum | F16 after · maximum | All four formats after | +|---|---:|---:|---:| +| Dirt 4, half the parent | 79/192 · .001953125 | 192/192 · 0 | 768/768 · 0 | +| Dirt 4, relative to input | 192/192 · 0 | 192/192 · 0 | 768/768 · 0 | +| Dirt 4 v2, half the parent | 68/192 · .001953125 | 192/192 · 0 | 768/768 · 0 | +| Dirt 4 v2, relative to input | 192/192 · 0 | 192/192 · 0 | 768/768 · 0 | + +Across these 32 whole-graph settings, exact pixels rose from 2,835/3,072 to **3,072/3,072**. Opening eight configured F16 files without further edits gives another 768/768, maximum zero. + +With the original Sharpen size property, Dirt 4 enlarges the FX-Map. Use scale 1, disorder 0 and non-square expansion enabled at 64 × 32, seed 299618. For the 32 × 64 settings use seed 299697, scale 2, disorder 0.8125 and non-square expansion enabled. Each cell gives exact output pixels and maximum absolute error. + +| Original size · storage | Earlier capture, either processor count | Fresh one-processor capture | Fresh eight-processor capture | Ordinary save, either processor count | +|---|---:|---:|---:|---:| +| 64 × 32 · F16 | 2,045/2,048 · 0.0001220703125 | 2,045/2,048 · 0.0001220703125 | 2,048/2,048 · 0 | 2,044/2,048 · 0.00048828125 | +| 64 × 32 · F32 | 2,035/2,048 · 5.340576172e-05 | 2,007/2,048 · 6.103515625e-05 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| 32 × 64 · F16 | 2,040/2,048 · 0.001953125 | 2,040/2,048 · 0.001953125 | 2,040/2,048 · 0.001953125 | 2,048/2,048 · 0 | +| 32 × 64 · F32 | 2,026/2,048 · 4.583597183e-05 | 2,026/2,048 · 4.583597183e-05 | 2,048/2,048 · 0 | 2,037/2,048 · 6.103515625e-05 | + +The two fresh reference reads of the U16 FX-Map differ by one level at three of 512 input texels on the wide case and one of 512 on the tall case. MaterialCraft matches all 512 on the eight-processor read of each. In the tall F16 case the eight-processor Sharpen result matches MaterialCraft on all 2,048 pixels while the separately read reference output differs at eight. In Dirt 4 v2, both original-size 16 × 32 controls at seed 0 agree in F16 and F32 across both reference counts and their ordinary saves, 1,024/1,024 on each file route. Larger pattern executions and reference variation remain open. [Dense Dirt comparisons and work limits](#dense-seeded-quadrants-in-moisture-noise-and-dirt-4) + +### Half-precision inputs to Levels + +Levels now converts a normalized integer image to half precision before applying the curve when the input and output have equal pixel dimensions and only one size is parameter-controlled. The curve runs in F32 and the output uses its declared storage precision. The untiled 16 × 32 Directional Noise 3 v2 graph at seed 731257 now matches **512/512 F16 pixels**, up from 99/512. The ordinary F16 save also improves from 99/512 to 512/512. Maximum error falls from .0009765625 to zero on one and eight reference processors. All four storage formats match **2,048/2,048** on the original and another **2,048/2,048** after opening the four normally saved files. [Graph parameters and intermediate sizes](#a-recovered-rectangle-and-repeated-outputs-in-directional-noise-3-v2) + +To reproduce the precision change in isolation, fill a 16² U8 input with 58/255. Set input low to 7/32, mid to .5 and high to 15/32. On the input or on Levels, read an exposed float of .375 in the relative size function, then return the original exponent offset (0,0). The stored F16 output is .03466796875 when exactly one node reads the parameter and .0347900390625 when both or neither read it. The regression checks all four combinations using a shared cook cache. + +The raw grayscale and RGBA comparisons cover U8, U16, F16 and F32 input storage, the original root curve, a linear curve, the default Levels curve and a clamped curve with different endpoints per channel. For the nonuniform inputs use channel c at (x,y) equal to (((73 + 4c)x + 29y + 13xy + 37j + 47c) mod 997)/996. Use j = 1 at 32 × 16, j = 2 at 16 × 32, and j = 3 for the 16 × 32 source at a 32² parent. Use seed 843173 + 19j. The 154 settings improved from **54,099/66,560** to **66,560/66,560** on each reference processor count. The largest channel error fell from .001953125 to zero. Eight ordinary saves across all four output formats match another **4,096/4,096** per processor count. + +The original tiling gives the following seven F16 comparisons. The two reference processor counts agree on each file. Each table cell gives whole pixels exact and maximum absolute error. The four completed originals improved from **1,407/7,424** to **7,423/7,424**. All four ordinary saves match **7,424/7,424**, maximum zero. + +| Size · seed | Original before | Original after | Ordinary save after | +|---|---:|---:|---:| +| 16² · 0 | 56/256 · .0009765625 | 256/256 · 0 | 256/256 · 0 | +| 64 × 16 · 42 | Work limit | Work limit | Work limit | +| 32² · 103867 | 204/1,024 · .007080078125 | 1,023/1,024 · .0068359375 | 1,024/1,024 · 0 | +| 64 × 32 · 195062 | Work limit | Work limit | Work limit | +| 32 × 64 · 195109 | 354/2,048 · .0009765625 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| 64² · 411704 | Work limit | Work limit | Work limit | +| 64² · 42 | 793/4,096 · .0009765625 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | + +Use defaults at 16² and the [recorded directional parameters](#reference-repeatability-across-31-open-noise-roots) at 32². The original reference returns .428466796875 at (18,16) there. Both reference reopens and both MaterialCraft file routes return .435302734375. For the other non-square settings and the 64² seed 411704 case, enable non-square expansion and set disorder, disorder speed, anisotropy and angle randomness to the same value. At 64 × 16 use scale 2, common value .03125, angle and anisotropy angle −.21875 and tile offset (−.3125,.37890625). At 64 × 32 and 64² seed 411704 use scale 3, common value .34375, both angles .09375 and tile offset (0,.10546875). At 32 × 64 use scale 1, common value .1875, both angles −.0625 and tile offset (−.15625,.2421875). At 64² seed 42 leave non-square expansion at default and use scale 2, disorder .37, speed .6, anisotropy .3, both angles .125, angle randomness .2 and tile offset (.17,.29). + +Six F16 controls in Noise Clouds 2, Directional Noise 3, Dirt 2 and Dirt 5 match another 3,072/3,072 pixels against each processor count. + +Histogram Select matches **5,120/5,120** across three input fields and all four output formats at both processor counts. Use the constant gray field at 16² with defaults. At 32 × 16 use position .71875, range .3125 and contrast .6875. At 16 × 32 use .375, .625 and .125. The ten recorded F16 Perlin Noise originals match **100,352/100,352** at both processor counts. Its previously configured 64 × 32 F16 save matches **2,048/2,048** on the recorded saved-file comparison. [Perlin Noise settings](#perlin-noise-and-plasma-across-rectangular-projections) + +### A recovered rectangle and repeated outputs in Directional Noise 3 v2 + +Disable tiling on both axes and leave the exposed parameters at their defaults. At 16 × 32 and seed 731257 the previous evaluator stopped at its work limit. With seeded quadrant geometry reuse, the original and four individually configured ordinary saves render under the same limit. U8, U16 and F32 each match **512/512** against both reference processor counts on both file routes, maximum zero. Before the [Levels input precision fix](#half-precision-inputs-to-levels), F16 gave **99/512** on each comparison, maximum .0009765625. For each format, the two reference originals and both reference file reopens agree on all 512 pixels. [Dense quadrant regression](#dense-seeded-quadrants-in-moisture-noise-and-dirt-4) + +The three pattern stages feeding Levels have U8 storage at 2 × 4, 4 × 8 and 16 × 32. Set the Levels input low, mid and high to .350414991, .479999989 and .92156899 respectively and disable intermediate clamping. Rounding only the matching F32 output toward zero to F16 reproduces 99/512 stored reference values. Rounding the normalized U8 input toward zero to half before evaluating the curve in F32 and storing the result in half reproduces 512/512. This comparison measures that rectangle and curve. + +At 32², enable the original tiling, use seed 103867 and the [recorded directional parameters](#reference-repeatability-across-31-open-noise-roots). For U16 the original one- and eight-processor captures differ at (18,16). MaterialCraft gives 28,554, matching 1,023/1,024 on one processor and 1,024/1,024 on eight, maximum 446 and zero. Its F32 output matches 1,024/1,024 on both. + +To repeat the stage comparison, switch to 16², seed 103865 and default exposed parameters before returning to the 32² U16 and F32 pair. Make two returns on each processor count. All four U16 reads match MaterialCraft at the 4², 8² and 32² patterns and at the 32² Levels output. One eight-processor graph output instead returns 28,108 at (18,16). On a one-processor F32 return the last U8 pattern differs by one level there, and the Levels stage reads .428904921 while the graph output reads .435707599. The remaining three F32 stage-to-output reads match at every pixel. The root remains in progress. + +### Input-relative size and precision on a pattern background + +The FX-Map uses its connected background for input-relative size and precision. The 20 outputs in the paired-instance comparison now match **32,256/32,256 pixels**. Eight previously had the wrong dimensions. Together with the child image bridges, all 140 outputs match **235,520/235,520** on one and eight reference processors. The separate 26-output instance comparison now matches 25,856/25,856. [Paired instances and original input fields](#input-relative-dimensions-on-a-child-image-bridge) + +Give a standalone FX-Map a 16 × 32 background and a 32² stamp. With the parent at 32 × 16, omitted or explicit input-relative dimensions produce 16 × 32. A (−1,+1) input-relative exponent offset produces 8 × 64. Parent-relative dimensions give 32 × 16. A disconnected background leaves the parent as the size source even with the stamp wired. Repeat inside a child fixed at 64² with a wired and an unwired background, then fix the background bridge on the child and on the caller. Across 60 output reads at three parent extents, **93,952/93,952** pixels match, maximum error zero. + +Set the background bridge to U16, the stamp bridge to F32 and the parent to U8. Keep the draw's format input-relative. At parent sizes 16², 32 × 16 and 16 × 32, test both inputs, background only, stamp only and both disconnected. The first two configurations inherit U16 and the last two inherit U8. Both the actual storage type and dimensions match in **12/12 cases**, up from 5/12. Raw PNG exports and direct reads of configured files agree with the reference originals on **5,632/5,632 pixels**. Selecting an explicit format in the editor switches that property to absolute inheritance. Preserve the authored mode for this comparison. + +For each of U8, U16, F16 and F32, set the connected background bridge to that precision and leave the FX-Map's precision input-relative. Read the bridge directly and through the draw with the stamp disconnected. Use original grayscale byte fields at 8², 16 × 32 and 128², with the bridge fixed to 16 × 32. For the two smaller fields set byte (x,y) to (17x + 43y + 23(xy mod 7)) mod 251. The 128² field is the linked background used above. All **12,288/12,288** pixels match. Opening the four normally saved draw configurations with the 128² source in the reference app reproduces **2,048/2,048** pixels at each processor count. Maximum error is zero. + +The seven measured roots with an input-relative pattern and a connected background retain their recorded results. Bevel Smooth's position helper retains 354,560/354,560 pixels on both original and saved paths. Paths Trace retains 73,984/73,984 original and 28,928/28,928 saved pixels, and the irradiance UV helper retains 16,384/16,384 on each route. The two newer Tile Random roots retain 180,224/180,224 and the two older roots retain 484,864/484,864 on the originals and again on ordinary saves. + +### One repeated branch in Dirt 4 v2 + +At 128 × 32 with scale 2 and seed 433595, the previous evaluator stopped at its visit limit. With an empty initial branch and exactly one repetition, the Iterate node can enter its child directly after evaluating the count and its assignments. The child receives its usual iteration number, seed and local variables. The pending stack, property work and raster work retain their bounds. This change applies to the shared evaluator. + +Start from the procedural root, set disorder, disorder speed and anisotropy to .046875, anisotropy angle to −.203125 and tile offset to (−.296875,.365234375). Enable non-square expansion, keep the other defaults and choose each output format on the node feeding the output. Save each configuration separately and reopen without edits. All **16,384/16,384** stored MaterialCraft pixels agreed between original and saved files. Each entry compares stored pixel words with the reference and reports maximum absolute error. Integer errors are in storage levels. + +| Storage | Original · one processor | Original · eight | Ordinary reopen · one | Ordinary reopen · eight | +|---|---:|---:|---:|---:| +| U8 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| U16 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| F16 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| F32 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | + +For separate procedural controls, compare an inner Iterate with and without an initial child and with reset or inherited seed. Test shared and independent random draws in a count expression that writes a float read by the drawing child. Use 16² at seed 0, 32 × 16 at seed 42 and 16 × 32 at seed 329779 in all four formats. The 48 one-repeat settings match **20,480/20,480** original and **20,480/20,480** reopened pixels at each reference processor count. The 24 settings with conditional counts match **10,240/10,240** per route. Maximum error is zero. In the 4² regression, one child under each of 64 outer repetitions reproduces all 16 full-budget values at a limit of 64. The previous traversal stopped there. The new traversal still reaches the limit at 32. + +At 32², the previous and current evaluators also produced the same stored pixels for all eight Dirt 5 and Dirt 5 v2 controls. Use scale 1, disorder .3125 and non-square expansion off. For Dirt 5 use seed 105545. For v2 use seed 105562, anisotropy .25, anisotropy angle .3125, disorder speed .6875 and tile offset (.125,−.1875). Keep the other defaults. + +| Root | U8 · one / eight processors | U16 · one / eight | F16 · one / eight | F32 · one / eight | +|---|---:|---:|---:|---:| +| Dirt 5 · exact pixels of 1,024 | 1,024 / 1,024 | 1,023 / 1,024 | 1,023 / 1,024 | 1,023 / 1,024 | +| Maximum error | 0 / 0 | 3 / 0 | .0001220703125 / 0 | .0000508129597 / 0 | +| Dirt 5 v2 · exact pixels of 1,024 | 1,024 / 1,024 | 1,024 / 1,024 | 1,024 / 1,024 | 887 / 922 | +| Maximum error | 0 / 0 | 0 / 0 | 0 / 0 | 5.96046448e−8 / 5.96046448e−8 | + +With scale 3 and the same remaining Dirt 4 v2 settings, the release still stops during the pattern draw. A bounded diagnostic run completed 55,245,436 visits and retained 49,761 draws. Its U8 intermediate agrees at all **1,023/1,023** texels that stayed fixed across six reference reads. Its F32 output matches **4,096/4,096** on five reads and **4,064/4,096** on the sixth, maximum .00407773256. The diagnostic used a larger allowance. The complete scale 2 measurements above used the release limits. [The one changing input texel at scale 3](#a-one-level-pattern-change-before-sharpen-in-dirt-4-v2) + +### A one-level pattern change before Sharpen in Dirt 4 v2 + +At 128 × 32, seed 433595, the graph renders a U8 pattern at 64 × 16 before Sharpen produces the full-size output. Alternate the changed rectangular setting with 32² at seed 113 and read each node directly on three returns at one processor and three at eight. The six pattern buffers have two distinct images. They agree at 1,023/1,024 texels, with 142 or 143 at (52,6). The six F32 graph outputs also have two distinct images. They agree at 4,064/4,096 pixels, with a maximum difference of .00407773256. The word returned by a separate node read can vary between evaluations. [Whole-root seeds and parameters](#repeated-f32-captures-of-28-noise-roots) + +To isolate the filter, retain its original properties and the drawing input’s size function. Use a 64 × 16 U8 field with value ((17x + 37y + 3xy + 29) mod 211) + 12. Compare center values 142 and 143 at (52,6). In a second pair place the following five-by-five neighborhood around that texel, varying only the center. Coordinates start at the first row and column in the raw buffer. + +```text +51 140 62 142 31 +173 136 96 0 0 +78 185 142 93 0 +104 47 86 18 0 +0 105 136 66 110 +``` + +All sixteen procedural outputs match **65,536/65,536** pixels in each reference processor configuration, maximum zero. Their U8 input reads match the supplied fields at **16,384/16,384** texels. Configure and save the two neighborhood inputs separately in each storage format. Both applications reopen the eight saved callers at their stored settings with **32,768/32,768** exact output pixels and maximum zero. + +| Output storage | Pixels unchanged when 142 becomes 143 | Maximum change | +|---|---:|---:| +| U8 | 4,086/4,096 | 3 | +| U16 | 4,067/4,096 | 267 | +| F16 | 4,065/4,096 | 0.0048828125 | +| F32 | 4,064/4,096 | 0.00407773256 | + +The F32 difference covers 32 pixels from (102,10) to (107,15). At (104,12) the values are .678542137 and .682619870. Each isolated input reproduces **32/32** affected whole-root values for its respective observed output. Subtracting the two complete isolated buffers reproduces the whole-root difference at **4,096/4,096** pixels, maximum error zero. MaterialCraft’s measured release still reaches its execution budget drawing the intact 128 × 32 root. The isolated filter comparisons use complete renders. + +### Dense seeded quadrants in Moisture Noise and Dirt 4 + +Moisture Noise at 128 × 32, seed 433959, now renders under the existing execution limits. The intact root matches **16,384/16,384 stored pixels** across U8, U16, F16 and F32 on both one and eight reference processors. Saving each configured format and reopening it before any edit gives another **16,384/16,384** on each processor count. Maximum error is zero. Each of the two U16 pattern stages independently matches 4,096/4,096 pixels in the same graph. Both stages previously stopped before producing an image. + +Set scale to 3, disorder to .046875, pattern size to (.47265625,1.4677734375), angle to −.203125, angle randomness to .046875, global opacity to .462890625 and non-square expansion on. Each branch emits 36 trees from 169 iterations. A tree visits 349,525 quadrants. On the 64² control at seed 433922, the F32 root matches 4,092/4,096 against each processor count in the latest pair, maximum 1.52587891e−5. The reference pair agrees at 4,094/4,096. [Iteration counts, smaller depth controls and repeated captures](#repeated-noise-pixels-and-the-moisture-noise-iteration-count) + +A grayscale procedural quadrant can reuse its branch offset, frame offset, size, rotation and tint for the same node, depth and seed when its expressions read only fixed graph inputs and traversal state represented in that key. The two translations retain their separate F32 additions. The expanded terminal records share the existing 96 MiB budget with the other analytic records. A fully evaluated parent that misses every sample can use one previously skipped terminal evaluation to account for that miss. Cached parents still spend a streaming credit. The traversal still evaluates every connected child in order, and the full-property, retained-draw and raster limits still apply. + +For a reduced regression at 4², put four outer repetitions around 41 inner draws with reset seed inheritance. Give each narrow parent four square children. Use a seeded random rotation up to .125 turns, a branch offset of (.03125,−.015625) and a frame offset of (−.015625,.03125). At an allowance of 128 the previous evaluator stops. The corrected cook agrees with the complete 1,024-allowance image. The independent 64-allowance negative control still stops. + +For Dirt 4 at 32 × 16, seed 105515, set scale to 2, disorder to .8125 and non-square expansion on. The previous build stopped before producing F32 pixels. The current evaluator finishes in all four formats. Each entry gives exact pixels and maximum error. Integer errors are storage levels. + +| Format | Original, one processor | Original, eight processors | Ordinary save, one processor | Ordinary save, eight processors | +|---|---:|---:|---:|---:| +| U8 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| U16 | 501/512 · 3 | 512/512 · 0 | 501/512 · 3 | 501/512 · 3 | +| F16 | 512/512 · 0 | 509/512 · 0.00048828125 | 512/512 · 0 | 512/512 · 0 | +| F32 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | + +Read the Dirt 4 pattern, sharpen and graph output after the same cook. Run U8, U16, F16, F32, U16 and F16 in sequence, once per reference processor count. Across these 12 captures the MaterialCraft pattern matches all 1,536/1,536 U16 pixels and its output matches all 6,144/6,144 sharpen pixels, maximum error zero. On the first eight-processor U16 capture the reference output matches its own sharpen at 501/512, maximum three levels. On the one-processor F32 capture it matches at 500/512, maximum 5.34057617e−5. The other ten output reads match their sharpen exactly. The repeated U16 capture also matches on both processor counts. + +Dirt 4 and Moisture Noise remain in progress. The second Dirt 4 also still reaches its full-property limit at 32 × 16, seed 105532. Use the same scale and disorder, speed 1.4375, anisotropy .625, anisotropy angle −.21875 and tile offset (−.3125,.4375). The original F32 reference and the ordinary save agree at all 512 pixels on the recorded one- and eight-processor reads. + +In that second graph, take the minimum of the original Iterate count and a fixed integer so its expression still publishes its variables. Cap only the outer count at one or four, only the inner count at zero, then the outer at two and the inner at one. All four full outputs match MaterialCraft at **2,048/2,048 F32 pixels** on both processor counts. The 16 × 8 U8 pattern stage also agrees between reference processors in all four controls. The uncapped reference control reproduces all 512 original pixels. + +### Input-relative dimensions on a child image bridge + +An image bridge inside a graph instance now resolves its input-relative dimensions against the image wired to that port on the caller. Across 120 bridge outputs, 36 previously had the wrong dimensions. All **203,264/203,264 pixels** now match on both one and eight reference processors. The previous 84 comparable outputs matched 179,200/179,200. Maximum error is zero wherever dimensions agree. + +Use two instances of the same child. Give the caller a 32² absolute stamp input and a background input that follows the parent. Wire both inputs to the first instance and only the stamp to the second. Read either bridge directly at the child output. Use the [two original 128² byte fields](#sampling-a-retained-input-after-an-editor-change). Exercise 32², 16², 32 × 16 and 16 × 32 parent sizes with inherited and fixed 64² instances. Repeat with the background field bound on the caller. Check omitted and explicit input-relative sizes, a (−1,+1) exponent offset, parent-relative and absolute sizes, a fixed 16² child and F32 bridge storage. + +At a 16 × 32 parent with both instances fixed at 64², the offset background bridge produces 8 × 64 on the wired instance and 32 × 128 on its unwired sibling. Store these two outputs in U8, U16, F16 and F32. Opening the four configured ordinary saves and reading before any edit gives **18,432/18,432** pixels, identical to the four originals and to both reference processor counts. The existing 82 parent-relative sampling controls retain **4,661,248/4,661,248** pixels with zero maximum error. + +Reading the downstream FX-Map exposes a separate size difference. Eight of 20 outputs in the same two-instance comparison still have the wrong dimensions. The other 12 match 27,648/27,648 pixels. On a standalone FX-Map with a 16 × 32 background and a 32 × 16 parent, the reference gives 16 × 32 for omitted or input-relative size and 32 × 16 for parent-relative size. With (−1,+1) relative to input it gives 8 × 64. Disconnecting the background gives the parent dimensions. Both reference processor counts agree in each comparison. + +### Overlapping glyphs and Points Preview file handoff + +Points Preview now matches **26,880/26,880 pixels across 45 settings** with the same font on both sides. The licensed monospace face gives 17,920/17,920 in 30 settings. The original overlapping digit face improves from 8,952 to 8,960/8,960 in 15 settings. At 16², 32² and 32 × 16, use point counts 4, 8 and 12 with labels alone, count 4 with points alone and count 12 with both. For digit `i`, use 1,024 units per em, an advance of 640, ascent 768 and descent −256. Draw three rectangles with opposite corners (0,0) and (64 + 32(i mod 4),512), (224,640) and (416,1088 + 64(i mod 3)), and (128,−576 − 64(i mod 3)) and (416,−128). Both reference processor counts give zero maximum error. [Point fields, label sizes and offsets](#stored-and-wired-values-at-graph-instance-inputs) + +For the independent Text probe, use a zero-advance A consisting of a rectangle from (0,0) to (width,512). Draw one through four copies at 32², size .5, left alignment and zero offset. Widths 6, 8, 11, 32 and 41 give **20,480/20,480 pixels**, up from 20,392. At pixel (16,12), width 11 yields the successive byte values 44, 80, 110 and 135. Width 32 yields 128, 192, 224 and 240. MaterialCraft now composes the new glyph's coverage with the existing byte and rounds after each glyph. It reads edge coverage in canvas coordinates. The 32 quadratic controls retain 81,132/81,152, the 96 straight-sided controls retain 261,700/262,144 and all 83,328 licensed glyph and sheet pixels remain exact. + +| Original and normally reopened Text | Size · seed · format | Previous exact · maximum | Current exact · maximum | +|---|---|---:|---:| +| Width 11, two glyphs | 32² · 0 · U8 | 1,016/1,024 · 1 level | 1,024/1,024 · 0 | +| Width 32, three glyphs | 32² · 42 · U16 | 1,016/1,024 · 257 levels | 1,024/1,024 · 0 | +| Width 11, three glyphs | 32 × 64 · 261017 · F16 | 2,032/2,048 · .00390625 | 2,048/2,048 · 0 | +| Width 41, four glyphs | 64 × 32 · 903331 · F32 | 2,040/2,048 · .0039215684 | 2,048/2,048 · 0 | + +Save configured whole-root callers with their bound procedural point fields and open the files directly in both applications. Eight monospace cases give 5,632/5,632. All 15 overlapping-digit cases give 8,960/8,960. These counts are identical at one and eight processors, maximum zero. The caller requests U8, U16, F16 and F32 across the files. The root's observed output on these direct opens is U8 throughout. + +One ordinary handoff still fails. From a caller pointing directly to the loose spline package with its three-part format version, save four views at three sizes. MaterialCraft reproduces the expected 7,168/7,168 grayscale pixels. The reference app returns a transparent RGBA F32 image in all 12 files on both processor counts. The standalone compiler rejects the linked package before rendering. + +To isolate the dependency, take private copies of the six linked package files with the same licensed font. Use format revision `1.1.0.202401` for the five three-part package headers and zero for the braced file identifiers in dependency records. The reference compiler accepts the package when the spline package's top-level file identifier is still braced and its dependency file identifiers are numeric. Restoring the braced identifier in its self dependency makes the compiler reject it. With the compatible metadata, the original Points Preview graph body compares identically with the inventory graph. Rendering the 30 settings and comparing against MaterialCraft opening the original graph gives 17,920/17,920 on one and eight processors. The installed catalog path selects a different face and gives 17,548/17,920, maximum .380392157. The root remains in progress for the loose-file handoff. + +### Whole design coordinates at implicit glyph joins + +With the same linked, licensed monospace font, all **30 Points Preview settings match 17,920/17,920 pixels** on both one and eight reference processors, maximum zero. The seven previously differing pixels all had count 12. The independent 42 Text renders now match 83,328/83,328, up from 82,571. They cover individual glyphs, digits and the four-line label sheet from 8² through 128 × 64. The catalog-path comparison selects different faces and gives 17,548/17,920, maximum .380392157. [Whole-root inputs and sizes](#stored-and-wired-values-at-graph-instance-inputs) + +Draw an original TrueType A with a quadratic from (0,0) through consecutive off-curve controls (55,−385), (492,126) and (675,612), ending at (1010,0). Close along the baseline. Use 1,024 units per em, ascent 768, descent −256, size .5, left alignment and offset (−.1875,1/256). Insert explicit on-curve points (273,−130) and (583,369) between the controls in a second face. The reference renders both faces identically at 64², 128 × 64 and 64 × 128, or 20,480/20,480 pixels. Rounding each midpoint upwards instead gives 20,288/20,480, maximum .047058821. MaterialCraft now uses the lower whole design coordinate for these implied joins in simple TrueType contours. The original negative-coordinate face improves from 20,330 to 20,480 exact. A positive-coordinate variant with controls (51,789), (492,286) and (671,−125) reaches 20,462/20,480, maximum one grayscale level. Composite glyph transforms remain a separate measurement. + +For four ordinary file saves, compare original and reopened Text output in each application at one and eight processors. The positive-coordinate face at 64² U8, seed 0 gives 4,096/4,096. The negative-coordinate face at 128 × 64 U16, seed 42 gives 8,192/8,192. A licensed zero at 64 × 32 F16, seed 261017 gives 2,048/2,048. The licensed label sheet at 32 × 64 F32, seed 903331 gives 2,048/2,048. Maximum error is zero in all four cases. + +An additional original font uses rectangular digits that extend above the ascent and below the descent. In 15 whole-root settings with that face, Points Preview matches 8,952/8,960, maximum .0039215684. The same results recur after an ordinary save. Isolating individual digits reproduces their coverage in both applications. Where the combined glyphs overlap, the two partial coverages 34 and 94 produce 115 in MaterialCraft and 116 in the reference. Coverages 183 and 48 produce 197 and 196 respectively. The root stays in progress for these same-input differences. + +### Quadratic glyph outlines in Points Preview + +In the same 30 whole-root settings, Points Preview with the same licensed font now matches **17,913/17,920 pixels** on both one and eight reference processors. The previous result was 17,869/17,920. The largest difference fell from 42 grayscale levels to one (.0039215684 on F32 readback). Point-only output matches 5,376/5,376. Labels alone match 5,371/5,376, and points plus labels including the empty input match 7,166/7,168. All seven remaining differences occur at count 12. The catalog-path comparison, where the reference resolves a different font, gives 17,548/17,920 and a maximum of .380392157. The root remains in progress. [Whole-root inputs, offsets and label sizes](#stored-and-wired-values-at-graph-instance-inputs) + +To isolate the contributing stage, render the original licensed four-line label sheet separately at 8², 16² and 16 × 8. Use the resulting byte field in place of Text in a private comparison graph. At root sizes 16², 32² and 32 × 16, use counts 4, 8 and 12 with labels alone, then count 12 with points and labels. MaterialCraft fed the reference sheet reproduces all 7,168/7,168 original reference pixels. Feeding its own sheet reproduces all 7,168/7,168 of its previous pixels. Reimporting the sheet as a linked bitmap in the reference also changes some final samples. The totals above compare the original Text graphs. + +For an independent TrueType face, give A one quadratic from (0,0) through control (512,1024) to (1024,0) and close the contour along the baseline. Use 1,024 units per em, ascent 768, descent −256, centered alignment, offset (−.0625,1/256), and grayscale on black. A second face replaces the curve by straight segments at equal parameter intervals. At 32² the reference gives exactly the four-segment raster at size .35 and the eight-segment raster at .35001. Both comparisons cover 1,024/1,024 F32 pixels, maximum zero. At size .5, use four segments at 16², eight at 32², 64², 128 × 64 and 64 × 128, and sixteen at 128². All six reference curves agree with their corresponding reference polygons. + +MaterialCraft now subdivides a quadratic while its midpoint is more than .35 pixels from the chord at the smaller axis scale. The existing outline storage budget also covers the new segments. Across 32 renders of the curved A, including fractional scales, shear, rotation, reflection and rectangular outputs, agreement improved from 79,823/81,152 to **81,132/81,152**, maximum .431372568 to .003921599. The 42 licensed-face sizes and strings improved from 81,267/83,328 to 82,571/83,328, maximum .631372556 to .533333357. The 96 straight-sided controls retain 261,700/262,144. [Original outline and font measurements](#text-block-bounds-for-linked-font-outlines) + +For each handoff below, save the configured graph normally and reopen it in both applications. Original and reopened counts agree on both reference processor settings. The reference before and after these saves matches all 5,120/5,120 pixels, maximum zero. The zero glyph uses the linked licensed monospace face, centered at size .5 with zero offset. + +| Text configuration | Size · seed · format | Previous exact pixels · maximum | Current exact pixels · maximum | +|---|---|---:|---:| +| Quadratic at .35 | 32² · 0 · U8 | 1,006/1,024 · 36 levels | 1,024/1,024 · 0 | +| Quadratic at .35001 | 32² · 42 · U16 | 1,002/1,024 · 8,224 levels | 1,024/1,024 · 0 | +| Quadratic at .5, matrix (.70710677,−.70710677,.70710677,.70710677) | 64 × 16 · 261017 · F16 | 988/1,024 · .431030273 | 1,024/1,024 · 0 | +| Single zero | 64 × 32 · 903331 · F32 | 1,973/2,048 · .450980395 | 2,021/2,048 · .415686272 | + +### Text block bounds for linked font outlines + +The shared Text renderer now clips glyph ink to the outward-rounded bounds of the transformed text block. It uses the horizontal header ascent and descent, line spacing and aligned line widths. An overhang may extend between two lines of the same block. A wrapped copy carries the same clip to its new position. + +For an original TrueType reproduction, use 1,024 units per em, ascent 768, descent −256 and advance 640. Give A a stem from (0,0) to (96,512). Add rectangles from (128,640) to (256,1024) and (320,832) to (512,960) above the stem, and from (128,−512) to (256,−128) and (320,−512) to (512,−384) below it. At 64² with size .5, left alignment, identity transform and zero offset, both overhangs must stay within rows 8 through 39. The old output matched 3,984/4,096 pixels, maximum 1. The corrected output matches all 4,096. Moving down half a pixel extends coverage into row 40. A quarter-turn moves the clip onto the horizontal axis. Fifteen original F32 cases cover upper and lower ink, translation, rotation, shear, changed header metrics, real line breaks and overlapping glyph advances. They improved from 60,482/61,440 pixels to **61,440/61,440**, maximum 1 to zero. + +The following four separately configured graphs reopened in both applications after an ordinary SBS save. Each current count applies independently to the original and reopened graph on one and eight reference processors. The input is the face above. The two-line case uses A followed by a newline and B, with B drawn from (64,64) to (256,704). All reference original/reopen comparisons are exact. + +| Changed Text setting | Size · seed · format | Previous exact pixels · maximum | Current exact pixels · maximum | +|---|---|---:|---:| +| Wrapped, offset (.4375,.4375) | 32 × 64 · 0 · U8 | 1,992/2,048 · 255 levels | 2,048/2,048 · 0 | +| Two lines, size .25, offset (−.25,−.25) | 64 × 32 · 42 · U16 | 2,038/2,048 · 65,535 levels | 2,048/2,048 · 0 | +| Wrapped, quarter-turn, offset (.4375,−.40625) | 32 × 64 · 261017 · F16 | 1,992/2,048 · 1 | 2,048/2,048 · 0 | +| Ascent 640, descent −384, offset (−.125,0) | 64² · 903331 · F32 | 3,984/4,096 · 1 | 4,096/4,096 · 0 | + +The 96 existing rectangle and diagonal controls retain 261,700/262,144 pixels, maximum .584313743. An overhanging triangle with vertices (128,−512), (384,1024) and (640,−512) at a half-pixel vertical offset gives 4,010/4,096, maximum .168627471. Replaying the 30 Points Preview settings with the same licensed font in both applications gives **17,869/17,920**, maximum .164705887. The saved-library label-only group remains 5,338/5,376. The catalog-path comparison gives 17,545/17,920, maximum .380392157. The root remains in progress for the visible label edges. [Root cases and font selection](#font-line-height-and-coverage-over-a-constant-background) + +### Reference repeatability across 31 open noise roots + +Compare the archived original outputs directly between one and eight allowed reference processors. Pair the same graph, output, parameter values, dimensions, seed, input bindings and storage format. Both captures restored the graph settings and recorded the requested processor count. The 31 roots are inventory indices 236–239, 244–247, 251–258, 261–271, 279–280 and 285–286. All 31 have at least one measured difference. The first eleven unresolved roots precede this group and also have differing reference captures. [Whole noise series](#whole-and-saved-outputs-for-the-two-gaussian-spots-2-noise-generators) · [Directional series](#directional-noise-and-scratch-pattern-sources) · [Earlier reference processor comparisons](#patterns-with-an-explicit-reference-worker-count) + +| Stored output | Paired renders | Renders with differing pixels | Equal reference pixels / compared | Maximum difference | +|---|---:|---:|---:|---:| +| U8 | 324 | 15 | 3,902,947/3,902,976 | 4 levels | +| U16 | 591 | 336 | 8,984,706/8,991,744 | 446 levels | +| F16 | 306 | 54 | 3,007,771/3,008,000 | .00439453125 | +| F32 | 656 | 524 | 6,759,290/7,924,480 | .00408181176 | + +At 16² F32 with default exposed parameters, compare the two reference buffers for `noise_bnw_spots_1.sbs` at seed 0, `noise_dirt_4.sbs` at seed 105509 and `noise_fur_2.sbs` at seed 75892. The counts are 171/256, 238/256 and 203/256, with maxima 1.19209290e−7, 6.103515625e−5 and 1.19209290e−7, respectively. For a U16 example, open `noise_directional_noise_3_v2.sbs` at 32², seed 103867. Set scale 1, disorder .3125, disorder speed .6875, anisotropy .25, anisotropy angle .3125, angle .15625, random angle .21875 and tile offset (.125,−.1875). Disable non-square expansion. The two reference images agree at 1,023/1,024 pixels, with a 446-level difference at the remaining pixel. + +These are reference-to-reference counts. On the 32 × 16 F32 Spots 1 setting at seed 456654, MaterialCraft still differs at seven of 370 pixels that stayed constant across repeated one-processor reads. The inventory retains the measured cross-processor and implementation differences. [Whole-root and invariant-pixel measurements](#receiving-quadrant-subtrees-after-the-second-pair-fills) + +### Reference variation in eight further roots + +Each row compares a reference image against the same setting on eight allowed processors, starting from one. The first and seventh rows use the first of three paired captures. Integer differences are storage levels. All inputs and unspecified parameters use the linked settings or their defaults. + +| Root | Size · seed · format | Equal reference pixels | Maximum difference | +|---|---|---:|---:| +| Noise Moisture Noise (295) | 64² · 433922 · F32 | 4,094/4,096 | 1.52587891e−5 | +| Noise Moisture Noise 1 v2 (296) | 16 × 32 · 732011 · U16 | 511/512 | 1 | +| Noise Moisture Noise 2 (297) | 16 × 32 · 732011 · F32 | 280/512 | 1.78813934e−7 | +| RT Caustics Base (451) | 64² · 4127 · U16 | 4,095/4,096 | 1 | +| Scratches 2 (464) | 16² · 115727 · F32 | 248/256 | 5.96046448e−8 | +| Vertical Noise (534) | 32 × 16 · 739049 · U16 | 501/512 | 1 | +| Wood Fibers 1 (544) | 64² · 703748 · F32 | 4,084/4,096 | 1.81198120e−5 | +| Wood Fibers 2 (545) | 256² · 0 · U16 | 65,336/65,536 | 2 | + +For root 295 use scale 1, disorder .9375, pattern size (1.140625,.85546875), angle .6875, random angle .9375 and global opacity 2.1328125. Disable non-square expansion. For root 451 use the procedural height, normal and noise fields, photon grid size 1, surface height scale .3125, surface height position .75, surface IOR 1.375, photon size 5.5, jitter .3125 and light position (.3125,.6875). Set Disorder to .3 for Vertical Noise and .375 for Wood Fibers 1. [Moisture comparisons](#recovered-dirt-4-and-moisture-renders-at-seed-113) · [Caustic procedural inputs](#paths-caustics-and-cell-fields-after-pattern-sampling) · [Fiber comparison settings](#repeated-wood-fiber-renders-and-isolated-drawing-depths) + +Return to each 64² F32 setting in rows one and seven three times, rendering the other sizes in between. On one processor all 4,096 pixels repeated on both returns in both graphs. On eight, Noise Moisture Noise gave 4,093/4,096 exact on both returns, maximum 1.52587891e−5. Wood Fibers 1 gave 4,089/4,096 and 4,095/4,096, maximum 1.81198120e−5 in each comparison. Across all six captures per graph, MaterialCraft at `fc5ad59` matched 4,090/4,091 invariant pixels in Noise Moisture Noise and 4,080/4,082 in Wood Fibers 1, with maxima 1.52587891e−5 and 1.75237656e−5. Noise Moisture Noise at 128 × 32, seed 433959, still reached the local pattern execution budget. + +### Repeated noise pixels and the Moisture Noise iteration count + +Keep twelve returns to the same F32 setting on one processor and twelve on eight. Before every return, change to 16 × 32. Use seed 0 for Spots 1 and Moisture Noise at that intervening size and 703211 for Wood Fibers 1. For Spots 1 use scale 1, roughness 1 and disorder 0 there. Use defaults on the other two. On return, use scale 2, roughness .375 and disorder .28125 for Spots 1 and the [earlier moisture and fiber parameters](#reference-variation-in-eight-further-roots). Count a pixel as invariant only if its F32 value repeats in all 24 captures. + +| Graph · returned size · seed | Exact invariant pixels | Exact whole-image pixels per return, one processor | Eight processors | Greatest absolute error over all returns | +|---|---:|---:|---:|---:| +| Noise BNW Spots 1 · 32 × 16 · 456654 | 259/259 | 430–454/512 | 410–441/512 | 1.19209290e−7 | +| Noise Moisture Noise · 64² · 433922 | 4,088/4,088 | 4,092/4,096 | 4,091–4,094/4,096 | 1.52587891e−5 | +| Wood Fibers 1 · 64² · 703748 | 4,070/4,070 | 4,084–4,088/4,096 | 4,087–4,091/4,096 | 1.86562538e−5 | + +At every location, at least one reference capture gave the MaterialCraft value. Each individual frame still differed. The counts also depend on the processor setting. Across the twelve one-processor returns, Spots 1 matched 310/311 invariant pixels and Wood Fibers 1 matched 4,076/4,079. The largest differences on those invariant pixels were 2.98023224e−8 and 1.80006027e−5. Across the twelve eight-processor returns the corresponding counts were 286/287 and 4,073/4,073, maxima 2.98023224e−8 and zero. The moisture and fiber counts update the earlier six-read comparisons. + +Read the two U16 pattern outputs feeding the Moisture Noise blend at each return. For each of the two outputs, 4,092/4,092 invariant pixels match, and all 4,096 locations have at least one matching observation. At destination (33,40) the reference alternates between 43,348 and 43,349, and MaterialCraft gives 43,349. At source (60,17) the observations include 14,962 and 14,963, and MaterialCraft gives 14,962. Both values at both locations occur even at one processor. + +At 128 × 32 and seed 433959 use scale 3, disorder .046875, size (.47265625,1.4677734375), angle −.203125, random angle .046875, opacity .462890625 and non-square expansion enabled. Each original pattern output separately reaches the local execution budget. The one- and eight-processor reference buffers agree on all 4,096 U16 pixels in each output, maximum zero. + +To count the work, retain the original Iterate and Switch. Replace their receiving quadrant with a centered unit square, additive blend, an RGB swatch of 1/64 and alpha 1. Use a zero background, zero roughness, unit global opacity and F32 storage. Remove the quadrant’s original offset and children. Each branch now matches all 4,096 pixels on both processor settings at each extent, 16,384/16,384 in total. At 64² the entire image is 1/64. At 128 × 32 exactly 100 pixels are 36/64 and the other 3,996 are zero. Force the switch open and compare one iteration, two and its authored iteration count at both sizes. All 24,576 additional pixels match on one and eight, maximum zero. On the rectangle the same 100 pixels read 1/64, 2/64 and 169/64. The original switch therefore accepts 36 of 169 iterations there. Each accepted iteration expands ten full quadrant levels, or 349,525 visits. Both original branches independently require 12,582,900 quadrant visits before rasterization. + +Cut the four child connections below depth six, seven or eight in each original pattern graph, counting the first quadrant as depth zero. Keep its original seed, Switch, drawing properties and all upstream function links. At 128 × 32 both branches now finish all six reduced graphs. For the blend destination the one/eight comparisons at depths six, seven and eight give 4,096/4,096, 4,096/4,096, 4,096/4,096. For the blend source they give 4,096/4,096, 4,095/4,094, 4,096/4,096. Every count is out of 4,096 raw U16 pixels. The largest storage error is 1.0. Both branches match all 4,096 pixels on both processor settings when cut below depth eight at this rectangle. Restoring the final depth causes the local execution error. + +### Saved image inputs and automatic filtering in Tile Random + +Bind generated gray and color images to graph inputs and use an ordinary **Save As**. The two tile roots previously stored the resource names only in editor options. Opening the saved 32² F32 files in the reference app gave 0/4,096 exact pixels across the four files. For a 1 × 1 grid with both images connected, the maximum errors were .501960814 grayscale and .937254906 color. With only the pattern connected to a regular 2 × 2 grid, they were .694605947 and .854413688. An independently authored one-input package shows the resource URL on the image bridge's `bitmapresourcepath` parameter. Adding that field to the four test files recovered 4,096/4,096 on one and eight processors, maximum zero. + +MaterialCraft now reads and writes this bridge parameter with the package resource path and dependency UID. To test a file-authored binding, connect an image input directly to an output at 16² U8. Use `u(x,y) = x + 16y` for gray and `(u(x,y), u(y,x), 255−u(x,y), u((x−3) mod 16,y))` for RGBA. Write PNGs with no transfer tag, an sRGB tag and gAMA values 100000, 45455 and 220000. Open the ten SBS files directly, save them normally and reopen them in both applications. The previous reader matched 5/2,560 pixels with a maximum error of 255 byte levels. The corrected reader matches 2,560/2,560 on one processor, eight and on ordinary reopen, maximum zero. At gray level 128 the three gamma-tagged files read back as 186, 128 and 221 respectively. Alpha retains its original levels. The 549 tracked SBS files contain 2,495 input bridges and zero authored `bitmapresourcepath` bindings on those bridges. + +For the editor binding path, use the same 16² gray and RGBA fields, each with no transfer tag and with gAMA 100000. Bind the image through `graph.input.bind` with the color setting omitted, save and reopen. The previous default matched 262/1,024 U8 pixels in the four reopened files. The largest error was 135 byte levels in the gamma-tagged RGBA image. The editor now uses the file's color interpretation by default. Open the four saved files directly and read the output before editing any property. All **1,024/1,024 pixels** match on one and eight reference processors, maximum zero. Repeating the four bindings with each explicit color setting preserved the previous MaterialCraft output across 2,048 pixels. The regression also switches modes on the same input and checks its alpha. + +Run the [145 grayscale and 76 color settings](#integer-assignments-read-by-pattern-seeds) with a separate path to the same original procedural bitmap for each connected input in each setting. Read the whole output on one reference processor, on eight and after opening an ordinary MaterialCraft save and reapplying those inputs. Every setting matches on all three routes. Each cell gives exact pixels per route. Maximum error is zero throughout. + +| Root | U8 | U16 | F16 | F32 | Total | +|---|---:|---:|---:|---:|---:| +| Tile Random | 9,728/9,728 | 124,928/124,928 | 11,776/11,776 | 131,328/131,328 | 277,760/277,760 | +| Tile Random Color | 9,728/9,728 | 124,928/124,928 | 11,776/11,776 | 60,672/60,672 | 207,104/207,104 | + +For a file handoff, configure each root in MaterialCraft before saving. Use the defaults at 128² with seeds 0 and 42 and both procedural inputs. At 32² F32 and seed zero, use a 1 × 1 grid with both inputs and the regular 2 × 2 grid with only the pattern. Include the four formats at 32 × 64/530371, 64 × 32/89027 and 16 × 32/2747 from the [rectangular parameter matrix](#integer-assignments-read-by-pattern-seeds). Open each of the 32 files directly. Read the reference output without setting any property, verify its stored seed and compare it with the original configured image and the MaterialCraft reopen. On one and eight processors, all three images match **106,496/106,496 pixels** each. Per root this is 4,608 U8, 37,376 U16, 4,608 F16 and 6,656 F32, maximum zero in every format. + +For the outstanding live edit, keep the 128² pattern connected while removing the background and selecting the regular 2 × 2 grid at 32², seed zero. The sequential result matches 4/1,024 grayscale pixels (maximum .267032921) and 0/1,024 color pixels (.416119799). Giving the same pattern a fresh binding restores 1,024/1,024 each. Insert identity Levels at U8 between the pattern input and its first consumer. Automatic filtering then reproduces the sequential reference result, while explicit bilinear reproduces the fresh result. All six independent comparisons with the Levels graph, including nearest filtering, match 6,144/6,144 F32 pixels in total. These results distinguish the two filtering outcomes even when the input bridge has identical pixel values. + +For a standalone reproduction, generate 128² byte fields `(13x + 7y + 3xy) mod 253` and `(31x + 19y + 5xy) mod 251`. Connect the first to a centered half-size image stamp, with unit opacity and a black background. At 32² F32, adding the second field as background while retaining the pattern gives 833/1,024 exact pixels with automatic filtering, maximum .001968503. Removing it gives 833/1,024, maximum .001968443. Rebinding the pattern or changing to 16² and back restores all 1,024. Explicit bilinear matches 12,544/12,544 across the 13 settings on one processor, eight and after ordinary reopen. Both tile roots retain their open live-edit comparison. + +### Sampling a retained input after an editor change + +Use the two 128² procedural byte fields and half-size image stamp above. Give the image input an absolute 32² or 32 × 64 output. Compare the direct connection with an identity Levels node that inherits the input dimensions and stores U8. For each bridge, set the stamp output to 32², 32 × 64, 64 × 32 and 64² in turn. At each size render F32, change only the stamp precision to U16, then return to F32. Keep the graph extent and binding in place during both precision changes. + +The direct reference result agrees with the base-level sample on the first render at each new extent and with the full mip chain after each precision change. Across 24 comparisons, these two paths account for **36,864/36,864 F32 pixels** and **18,432/18,432 U16 pixels**, maximum zero on one and eight processors. With the 32 × 64 bridge and 64 × 32 output, continuing to sample the base level on the second render gives 1,538/2,048 U16 pixels, maximum 23,644 levels. Temporarily setting a rectangular output to a square and back during a precision change starts a new extent and changes the result. Reapplying the same precision at the same extent before any other edit retained the initial 32² F32 output in the square control. + +Selecting between the two sampling paths offline also reproduces all 484,864 pixels of the earlier 221 sequential root settings. The editor at the time used the fresh-render path for both live background edits. The [live preview measurements](#live-preview-sampling-in-tile-random) record the correction. + +### Live preview sampling in Tile Random + +Open each root once and keep the same editing session for every render. Reuse the same imported resource whenever a procedural input path recurs. Apply the exposed values, seed, extent and storage format from the [221 whole-root settings](#integer-assignments-read-by-pattern-seeds) in sequence. For rectangular cases set the parent to the square width first, then to the requested height. Repeat the sequence after opening an ordinary MaterialCraft save. Compare whole stored pixels to independent reference captures at one and eight processors. The reference captures at those processor counts also agree with each other. + +| Root | Settings | Previous exact pixels | Exact pixels after live edits | Maximum F32 error before → after | +|---|---:|---:|---:|---:| +| Tile Random | 145 | 276,740/277,760 | 277,760/277,760 | .267032921 → 0 | +| Tile Random Color | 76 | 206,080/207,104 | 207,104/207,104 | .416119799 → 0 | + +The original and reopened editing sessions give the same counts. U8, U16, F16 and F32 each match every stored pixel. Repeating the sequence with a fresh resource path per setting also matches 484,864/484,864. The 32 configured files opened and read before any edit give 106,496/106,496 exact pixels. The two other qualified random-tile roots retain 180,224/180,224 across 52 independent controls. [Pixel counts by format, procedural inputs and configured-file settings](#saved-image-inputs-and-automatic-filtering-in-tile-random) + +The editor records which texture each image stamp sampled in the last published preview. When an edit changes a stamp while retaining that texture, its next draw can sample the mip chain. A new binding, seed or parent extent starts a fresh acquisition. The isolated consumer gives 17,664/17,664 exact pixels, two stamps sharing a texture give 25,088/25,088 across both outputs, and fixed seed and size controls give 33,792/33,792. Maximum error is zero in all three comparisons. The regression reads F32 pixel (9,8) in two half-size stamps. Editing one stamp from F32 to U16 and back changes its word from `0x3f014181` to `0x3f018182` while the other remains at its first word. A full cook and an edit from 32² to 64² and back before preview both give the first word for both stamps. [Probe settings](#filtering-after-independent-edits-to-stamps-sharing-an-image) · [Editor regression](../crates/engine/src/session.test.rs) + +A separate non-root control puts the same fixed 32² F32 child stamp inside two graph instances, wires the same 32² U8 bridge to both, and wires the background only to the first. Change the first instance’s precision while leaving its child at F32. The first per-stamp change gave 25,860/26,624 across 13 paired renders, up from 25,478. Four precision edits on the first instance still gave 833/1,024 each, maximum .00196844339. The editor now carries the resolved precision of each calling instance into the sampling state of its child. The same 26 outputs match **26,624/26,624 F32 pixels** on one and eight processors, maximum zero. At pixel (9,8) both instances start at `0x3f014181`. Set only the first instance to U16, then back to F32. Its child returns `0x3f018182` after each edit, while its sibling retains `0x3f014181`. A fresh full cook returns the initial word for both. The 221 original and ordinary-saved Tile Random settings retain 484,864/484,864 on each route. With inherited child size and precision, 25 comparable outputs match all 25,600 U8 pixels. With a 16² parent and a 32² stamp input, the reference returns 16² for the instance with both wires and 32² for its sibling. MaterialCraft returns 32² for both. + +### Filtering after independent edits to stamps sharing an image + +Use the [two 128² byte fields and half-size image stamp](#sampling-a-retained-input-after-an-editor-change). Give the pattern bridge an absolute 32² U8 output. Start the graph at 32², seed 99173, with the pattern connected, no background, and F32 output. Keep the parent extent in place on same-size edits. Compare each result on one and eight processors with the direct, base-level MaterialCraft cook and with a separate identity Levels control that supplies the full mip chain. + +Recomputing identical settings retains the first image. Changing the graph seed, selecting a different file with the same image bytes, and moving to 16² and back each recover the base-level result. Adding or removing the background while keeping the pattern and graph seed selects the full mip chain. Changing the stamp precision from F32 to U16 at the same extent also selects the full chain. Repeating that U16 cook retains its result. Returning to F32 continues to use the full chain. Across 18 sequential renders the fresh path alone gives 16,518/17,664 pixels. The observed sampling modes account for 17,664/17,664 on both processor counts, maximum zero. At 32² a precision change gives 833/1,024 against the base level, maximum 129 U16 levels. + +Add a second stamp and output to the same graph. Both stamps sample the same pattern bridge. Connect the background only to the first stamp. Change only the first stamp's output precision to U16 and back. The first stamp now matches the full chain. The second still matches the base level on all 1,024 pixels. Adding the background to the first stamp also leaves the second at the base level. The two outputs together give 23,942/25,088 for the fresh path alone. The sampling modes account for 25,088/25,088 at one and eight processors, maximum zero, across 13 paired renders. + +Finally run the seed, size and precision changes in four graphs. Independently give the stamp a fixed seed of 71 and absolute size 32², and give the pattern bridge a fixed seed of 71. Use graph seeds 6621, 6622 and 6623, with parent extents 32² and 16². Changing the parent seed or extent restores base-level sampling even in the graph with both overrides, where the pattern, stamp dimensions and their own seeds stay fixed. Across 36 renders the two measured paths account for 33,792/33,792, maximum zero, compared with 30,992/33,792 from the fresh path alone. The [subsequent editor replay](#live-preview-sampling-in-tile-random) covers both whole roots. + +### Integer assignments read by pattern seeds + +The two roots in `tile_random.sbs` each match **142,592/142,592 pixels in all 19 established settings** on one reference processor, on eight and after reopening an ordinary MaterialCraft save. The previous grayscale and color totals were 111,207 and 111,194. The same 1,702,705-byte save was reproduced with the tested build. Both roots also match at 32² with a freshly connected image in the edit-order control described below. [Previous comparison](#returned-vectors-in-pattern-properties) + +In a pattern seed expression, an integer assigned by an earlier property supplies the bits of its F32 storage word. A published integer supplies its integer bits. Both yield the same numeric value to an ordinary integer getter. For an independent F32 probe, put a square with additive Random(1) luminosity over black below two single-iteration Iterate nodes. Disable seed inheritance on the inner Iterate. At graph seed zero, a published seed of 17 gives .5091854334. Assign 17 to a new integer in the global opacity multiplier or the outer iteration count, then use it for the inner seed. Both give .2648949623. Adding 3 inside the seed expression changes that result to .2363138199. + +Use graph seeds 0, 113 and 42 with integer inputs 17, 41 and 16,777,217 respectively. Compare direct literal and published seeds, and assign each of six sources in the global multiplier and again in the outer Iterate. The sources are literal 17, the published integer, that integer plus 3, a cast of 17.5, a cast of the float input plus .5, and a cast of Random(200000000). Set the float input to the published integer plus .125. Render each at 16², reading either the random luminosity or the numeric integer divided by 268435456. All **84 settings and 21,504/21,504 F32 pixels** match on each route, maximum zero. In 24 additional single-processor settings, integer addition, conditional selection and assignment within the same seed expression match 6,144/6,144 pixels. Assigning to the name of an exposed integer remains a separate difference in six controls, 0/1,536 with maximum .447026968. + +The wider whole-root comparison renders each setting in order. Each cell below counts whole pixels with all stored channels exact. The maximum error is the largest stored component difference on any of the three routes. + +| Output | Grayscale settings | Grayscale exact pixels | Maximum error | Color settings | Color exact pixels | Maximum error | +|---|---:|---:|---:|---:|---:|---:| +| U8 | 5/5 | 9,728/9,728 | 0 | 5/5 | 9,728/9,728 | 0 | +| U16 | 10/10 | 124,928/124,928 | 0 | 10/10 | 124,928/124,928 | 0 | +| F16 | 6/6 | 11,776/11,776 | 0 | 6/6 | 11,776/11,776 | 0 | +| F32 | 123/124 | 130,308/131,328 | 0.267032921 | 54/55 | 59,648/60,672 | 0.416119799 | + +Across 145 grayscale settings the previous build matched 61 whole images and 228,741/277,760 pixels, maximum 59,881 in U16. The new result is 144 and 276,740/277,760. Across 76 color settings the previous build matched 33 images and 160,393/207,104, maximum 65,535 in U16. The new result is 75 and 206,080/207,104. + +For the additional open-pin controls, set 32² F32 and seed 0. Use grids (1,1), (2,1), (1,2), (2,2) and (4,4). At each grid compare defaults, zero X/Y size randomness and zero split threshold in mode 0, the latter with pattern 1, pattern 1 with threshold 1 in mode 1, and pattern 1 with zero split and .5 size randomness on both axes. At seeds 1, 42 and 113 repeat the default (1,1) and (4,4) grids. In grayscale also cross (2,1), (1,2) and (2,2) with both split modes, thresholds 0/.5/1 and X/Y randomness (0,0), (.5,0), (0,.5) and (.5,.5). + +Test both image pins open, each alone and both connected for the (1,1) grid, the (2,2) regular grid with pattern 1, defaults and a (7,3) grid with pattern 3 and pattern rotation randomness .3. Use the original grayscale or RGBA pattern and background fields from the [whole-root input comparison](#whole-caustic-scratch-splatter-tile-and-vertical-noise-comparisons). Add three rectangles in U8, U16, F16 and F32. For 32 × 64 use seed 530371, both inputs, a (3,2) grid, pattern 1, split mode 0, threshold .375 and size randomness (.4375,.21875). For 64 × 32 use seed 89027, both inputs, a (7,3) grid, pattern 3, split mode 1, threshold .625, size randomness (.3125,.5) and shape rotation randomness .125. For 16 × 32 use seed 2747, open inputs, a (2,5) grid, pattern 1, split mode 0, threshold 0 and size randomness (.375,.25). Count duplicate settings once. + +One F32 setting has two reproducible reference results. At seed 0 use the 32² (2,2) regular grid with pattern 1 and just the pattern input connected. Opening this setting directly gives 1,024/1,024 exact pixels in each root. Starting from a (1,1) grid with both inputs connected, then removing only the background while keeping the pattern connected, gives 4/1,024 grayscale and 0/1,024 color, with maxima .267032921 and .416119799. Both input bridge images have the same bytes in the two terminal states. Rebinding the identical pattern file by a second path restores all 1,024 pixels, including upon switching back to the original path. Each sequence reproduced on one processor, on eight and after opening the ordinary save. The three other roots with a driven pattern seed retained 2,449,920/2,449,920 pixels in 383 regression settings. Both older tile roots remain open on the sequential edit comparison. + +### Hue rotation and saturation in Replace Color + +Replace Color matches **170,240/170,240 pixels in 39 settings** on one reference processor, eight processors and after reopening a normal MaterialCraft save. All channels match exactly on each route. The earlier build matched 18 whole images and 158,780 pixels. The same 35,695-byte save reopened for the reference comparison was reproduced byte for byte with the corrected build. + +| Output | Settings | Exact pixels before | Maximum error before | Exact pixels after | Maximum error after | +|---|---:|---:|---:|---:|---:| +| U8 | 10 | 125,439/125,440 | 1 | 125,440/125,440 | 0 | +| U16 | 9 | 13,734/13,824 | 1 | 13,824/13,824 | 0 | +| F16 | 7 | 12,794/12,800 | .00048828125 | 12,800/12,800 | 0 | +| F32 | 13 | 6,813/18,176 | .0000009983778 | 18,176/18,176 | 0 | + +Repeat the [31 established settings](#hue-and-chroma-rounding-near-equal-rgb-channels). Add two linear F32 inputs and render each in all four output formats. With zero-based coordinates and color channel c from 0 to 2, set RGB to ((7x + 11y + 3xy + 41c + 5cx + 13cy + 19j) modulo 259)/256 and alpha to ((31x + 13y + 5) modulo 129)/128. For j = 0 use 32 × 64, seed 5309719, source color (.25,.5,.75) and target (.6875,.125,.5625). For j = 1 use 64 × 16, seed 9072209, source (.75,.25,.375) and target (.375,.71875,.09375). + +The shared HSL adjustment adds the minimum-channel sector in the same multiply-add as the biased channel difference times the reciprocal chroma. It adds the slider displacement in sixths of a turn. Removing whole turns in a multiply-add preserves the small residuals seen at wrap boundaries. A second multiply-add applies the saturation shift before rounding. At saturation 1 and lightness .5, a .5 gray rotated with hue 1 gives RGB (1, 2⁻²³, 0). At hue .359375, saturation .8125 and lightness .5, the F32 input (.6109035,.6431967,.35680333) has output words 3f74a640, 3d359c00, 3f120e45. + +For a separate 32 × 8 linear field, use two grays, .5 and .25, followed by seven colors for each minimum channel in R, G, B order. The minimum is 1/8192 and the maximum is 1 − 1/8192. Set the channel pairs (B,G), (R,B) and (G,R), respectively, to give first − (second + 3/4096) equal to −.75, −.5, −.25, 0, .25, .5 and .75 while retaining that maximum. Repeat the 23 colors across x. Set alpha to ((23x + 29y) modulo 129)/128. At saturation 1 and lightness .5, render hue 0, .03125, .125, .21875, 1/3, .421875, .5, .5625, .625, .765625, .9375, 1 and the two adjacent F32 values on either side of .375. Use seed 9314041 + 13j, starting at j = 0. The 14 settings improved from 1,136/3,584 to **3,584/3,584** on each route, maximum error zero. + +The [five gray ramps, six-sector RGB fields, near-grays and shifted lightness controls](#hue-and-chroma-rounding-near-equal-rgb-channels) match 327,680/327,680, 24,576/24,576, 16,384/16,384 and 14,336/14,336 pixels respectively. A standalone HDR channel-offset comparison still matches 20,462/20,480, maximum .000001013279. On the 32 × 8 field, hold the seed at 9314041 and set hue to .5 + t/2 + q for t = −2048, −128, −16, −4, −2, −1, 0, 1, 2, 4, 16, 128 and 2048 and q = 0 or .125. This out-of-range sweep matches 4,672/6,656, maximum 1. The eight differing settings exceed the scalar parameter's current hard range of −16 to 17. + +### Gradient warp on stretched pixels + +Liquid matches **820,480/820,480 pixels in 91 distinct settings** on one reference processor, eight processors and after reopening an ordinary MaterialCraft SBS save. The maximum stored error is zero in every format on each route. + +| Output | Settings | Exact pixels on each route | +|---|---:|---:| +| U8 | 11 | 102,912/102,912 | +| U16 | 22 | 342,016/342,016 | +| F16 | 12 | 104,960/104,960 | +| F32 | 46 | 270,592/270,592 | + +The previous build matched 53/60 established settings and 702,029/785,664 pixels. The seven failures used rectangular outputs with non-square expansion disabled. At seed 106898, compare a 64 × 32 F32 output at scale 5 with disorder and warp intensity both .3125. The previous build matched 2/2,048 pixels, maximum .451499209. Holding the generator settings fixed and setting warp intensity to zero matched all 2,048. At seed 106898, cross 64 × 32, 32 × 16, 16 × 32 and 32² with both expansion settings and warp intensities 0, .03125 and .3125. Keep scale 5 and disorder .3125. This gives 24 F32 settings including the original. For two additional disabled-expansion cases in all four formats use 32 × 64, seed 7001129, scale 9, disorder .3125 and warp .5625, then 64 × 16, seed 8008137, scale 4, disorder .71875 and warp .1875. + +To reproduce the 60 established settings, combine the original 19 Liquid comparisons with the table below and count identical settings once. A single value in the disorder/warp column sets both controls. “All” means U8, U16, F16 and F32. [Original 19 settings](#liquid-fiber-and-related-noise-sources) + +| Size | Seed | Scale | Disorder/warp | Non-square expansion | Output | +|---|---:|---:|---|---|---| +| 16 × 32 | 0 | defaults | defaults | defaults | All | +| 32 × 16 | 42 | 16 | .21875 | on | U16, F32 | +| 64² | 433818 | 5 | .9375 | off | All | +| 128 × 32 | 433855 | 11 | .046875 | on | U16, F32 | +| 32 × 128 | 433892 | 27 | .5625 | off | All | +| 128² | 0 | defaults | defaults | defaults | All | +| 256 × 128 | 433966 | 19 | .328125 | off | U16, F32 | +| 128 × 256 | 434003 | 32 | .8125 | on | U16, F32 | +| 256² | 42 | defaults | defaults | defaults | All | +| 512 × 128 | 434077 | 12 | .671875 | on | U16, F32 | +| 16 × 32 | 300442 | defaults | defaults | defaults | U16, F32 | +| 64 × 32 | 300521 | 1 | 0 | on | All | +| 32 × 64 | 300600 | 13 | .8125 | on | All | +| 64² | 300679 | 16 | .21875 | on | U16, F32 | + +Warp now uses the resolved pixel ratio when measuring displacement. With a gradient the same size as the output, its slope is the current texel minus the adjacent texel on that axis. At intensity one, multiply the slope by the squared axis length divided by 256 to get the displacement in stretched output pixels. The square-pixel setting uses the shorter axis as its length for both directions. For example, with a step of .5 horizontally and .25 vertically at the center of a 32 × 16 image, the center samples the source 2 pixels right and .25 pixels down in stretched mode. With square pixels it samples .5 pixels right and .25 down. + +For independent controls, use X and Y coordinate ramps with a single-pixel impulse or a two-axis step gradient. Cross both ramps and gradients with nearest and bilinear sampling at 16², 32 × 16, 16 × 32 and 64 × 32. Explicitly set the Warp pixel ratio to 0 (stretched) or 1 (square). These 64 settings match 53,248/53,248 F32 pixels on each route. The earlier build matched ten of 16 stretched settings per sampler, with 13,178/13,312 pixels in each. [Procedural fields, intensities and seeds](#gradient-warp-displacement-and-sampling) + +With stretched pixels, repeat the eight mixed-size settings in each of configurations 1 through 8 in the linked table. Across 64 settings, 64 whole images and 194,432/194,432 pixels match on each route. Maximum error is zero. The 14 other inventory roots with a reachable Warp retain 1,938,176/1,938,176 exact pixels across 185 regression settings. The 45,472-byte Liquid save produced by the tested build is byte-identical to the ordinary save used for the reference readback. + +### Returned vectors in pattern properties + +The two roots in `pattern_tile_random.sbs` now match all **1,154,048 pixels across 283 distinct settings** on one processor, eight processors and after reopening an ordinary MaterialCraft save. Maximum error is zero in each format. The [preceding seed correction](#driven-seeds-in-pattern-nodes) had left 20 settings with differences in each of the two main comparison sets. + +| Output | Grayscale settings | Grayscale exact pixels on each route | Color settings | Color exact pixels on each route | +|---|---:|---:|---:|---:| +| U8 | 10 | 33,792/33,792 | 11 | 37,888/37,888 | +| U16 | 19 | 184,832/184,832 | 20 | 188,928/188,928 | +| F16 | 10 | 30,720/30,720 | 11 | 34,816/34,816 | +| F32 | 65 | 175,872/175,872 | 137 | 467,200/467,200 | +| All | **104** | **425,216/425,216** | **179** | **728,832/728,832** | + +Start with the 79 grayscale and 154 color settings in the linked seed comparison. Repeat the connected 64² F32 position case from that section. Open its input pins, then independently disable position randomness, shape rotation and its randomness, pattern rotation randomness, both sets of rotations, and both sets of rotations together with position randomness. Also try zero X/Y size randomness, zero interstice, disabled shape rotation constraint, grids (1,1), (2,1) and (4,4), disabled non-square expansion, pattern 2, defaults with open pins and the original settings at seeds 0 and 113. Count the original once. + +For eight further settings per root, use all four formats on each of two original connected cases. In the 64² position case change the extent to 32 × 64, seed to 4047289, position randomness to .3125, split mode to 0 and shape rotation randomness to .21875. Disable the position randomness constraint. In the connected 5 × 3 case use 64 × 32, seed 1741031, position randomness .625, a 3 × 4 grid and pattern 2. Enable the position randomness constraint and disable the shape rotation constraint. The ordinary save from the verified build matched the 1,741,759-byte file reopened for the reference measurements. + +In the square isolation, assigning the computed frame offset to a new vector variable preserved the reference image. MaterialCraft's two expressions had differed at 49 pixels. The same assignment recovered all 358 differing pixels in a connected 3 × 5 rectangle. Returning a vector from a pattern property now evaluates the operands of its first component before drawing values for the next component, just as an explicit vector assignment does. Reused operands consume one draw. + +Independent checks use one additive square over black. Pack independent Random(.5) draws into two vectors. Return their sum as the frame offset. Repeat with a product sharing a component, scaling by one draw, or a conditional choice. Return an interpolation by .375 as the branch offset, a product as the size, and four-component sums or products as the color. Use 32², 64 × 32, 32 × 64 and 64² F32 at seeds 0, 113, 137 and 845872. All **32/32 settings and 73,728/73,728 pixels** match on each route, up from 12/32 and 54,544/73,728. Adding (.3125, .265625) to the product size gives visible footprints of 100, 280, 216 and 360 pixels. These four settings improved from 9,116/9,216 to 9,216/9,216, maximum error zero. + +The structural scan identified 17 already-qualified roots with potentially affected arithmetic results in a pattern property. All 103 rechecked settings match 1,063,936/1,063,936 pixels. The overlapping 36-root regression set retained 1,350,656/1,350,656 across 396 distinct settings. The older roots in `tile_random.sbs` remain open on one processor, eight processors and ordinary reopen. Grayscale went from 111,274 to 111,207 of 142,592 pixels, and color from 111,101 to 111,194 of 142,592, each over 19 settings. Their maximum U16 errors remain 59,881 and 65,535 respectively. + +### Driven seeds in pattern nodes + +A pattern node's Random Seed expression now uses the same scalar storage arithmetic as a graph or filter seed. It still reads the incoming pattern stream and the variables available to the node. A driven float-to-integer conversion returns the F32 word of the floored value. A driven scalar sum adds the two 32-bit words. Rounding an intermediate signaling NaN sets its quiet bit and retains its sign and payload. + +Use a single additive square with Random(1) luminosity over .125 gray. Drive its parent Iterate's seed with a float converted to an integer, a sum of two floats converted afterward, the sum of two individually converted floats, a product converted afterward, and a converted literal −1.5. Repeat the single-float cast on a Switch and a Quadrant. On a Quadrant also convert ten times the Y component of `$pos`. Use (first, second, graph seed) of (0, 1, 0), (1, .5, 845872), (3, .75, 113), (5.25, .5, 845872), (17, 1, 42) and (−1.25, −.5, 37). Cycle through 16², 16 × 32 and 32 × 16 F32. All **48/48 settings and 20,480/20,480 pixels** matched on one processor, eight processors and after reopening an ordinary MaterialCraft save. Maximum error was zero on each route. + +A separate parent-to-child graph passes two floats to a graph or filter seed. Compare the raw output of a 16² random Pixel Processor. For (3, .75), (5.25, .5), (5.75, .625), (−3, .75), (−5.25, .5) and (−5.75, .625), the recovered seed words are `7f800000`, `7fe80000`, `7fd80000`, `ff800000`, `ffe80000` and `ffd80000`. The finite controls (.75, .25) and (0, 1) give `7dc00000` and `3f800000`. Both seed locations match all 4,096 pixels in aggregate on each of the three routes. Direct integer offsets in 180 single-processor settings at three Iterate depths, including disabled inheritance, retain all 46,080 F32 pixels. + +Both random tile roots now match **20/20 settings and 10,752/10,752 F32 pixels** in the [rectangular expansion controls](#rectangular-expansion-in-the-two-random-tile-roots), up from 10/20 and 10,414. The tall and wide defaults match all 512 pixels each. In each of the layout and drawing passes, read the first, second and fourth visits to the center and outer tall segments and the outer wide segment. Compare the original seed expression and float-driven seed overrides 0, 1, 3, 5 and 17. Each pass matches all **54 settings and 27,648/27,648 F32 pixels**, maximum zero. + +Repeat all established settings on each processor count and reopen an ordinary save. Include the preceding 20 F32 settings and two further rectangular settings in each output format. For the first additional case use the connected 3 × 5 setting, a 32 × 64 output, seed 7011107, pattern 1, split threshold .3125, X/Y size randomness .25/.6875, interstice .15625, pattern rotation option 1 and non-square expansion. For the second start at defaults with open pins, 64 × 16, seed 1024053, a 5 × 2 grid, pattern 3, split mode 1, split threshold .8125, X/Y size randomness .5625/.375, shape scale randomness .25 and non-square expansion. Count identical settings once. All three reference routes agree with each other. The table compares the production evaluator with each route. + +| Output | Grayscale complete | Grayscale exact pixels | Maximum error | Color complete | Color exact pixels | Maximum error | +|---|---:|---:|---:|---:|---:|---:| +| U8 | 4/8 | 28,395/29,696 | 251 | 5/9 | 32,485/33,792 | 254 | +| U16 | 11/17 | 178,576/180,736 | 64507 | 12/18 | 182,750/184,832 | 65278 | +| F16 | 4/8 | 24,883/26,624 | 1 | 5/9 | 29,235/30,720 | 1 | +| F32 | 40/46 | 99,548/102,144 | 1.00000006 | 112/118 | 391,330/393,472 | 1.00000006 | + +Grayscale reaches **59/79 settings and 331,402/339,200 pixels**. Color reaches **134/154 and 635,800/642,816**. On the established settings alone, grayscale improved from 32/52 and 300,698/316,672 to 36/52 and 310,112/316,672. Color improved from 106/126 and 602,588/619,776 to 110/126 and 614,180/619,776. The 100 previously qualified Brick 3 settings still match all 1,295,872 pixels. The two older random tile roots retain 111,274/142,592 and 111,101/142,592 pixels across 19 settings each. + +Random positioning remains open. Use the connected 64² F32 setting with a 2 × 7 grid, pattern 3, filtering 1, pattern rotation randomness .2578125, split threshold .421875, shape scale .837890625, position randomness .0859375, shape rotation −.0078125 and shape rotation randomness .171875. At seed 846324 grayscale differs at 49 pixels. At seed 846361 color differs at 36. Changing position randomness alone to zero gives 4,096/4,096 on both. Passing the original frame offset through an otherwise unused vector assignment reproduces the untouched grayscale reference in this square and in the connected 3 × 5 rectangle. The reference output is identical with either expression. + +### Component reads in color tile function arguments + +The color graph in `pattern_tile_generator.sbs` matches all **777,472 RGBA pixels in 339 distinct settings** on one processor, on eight processors, and after opening a regular MaterialCraft save in the reference app. A pixel counts only when all four stored channels match. The earlier evaluator matched 206 complete settings. The fresh single-processor renders also reproduced the 765,184 archived pixels in the [331 established settings](#three-related-tile-roots-with-the-current-evaluator). + +| Storage | Settings | Earlier exact pixels · maximum error | Current exact pixels on each of the three routes · maximum error | +|---|---:|---:|---:| +| U8 | 9 | 20,575/24,064 · 88 | 24,064/24,064 · 0 | +| U16 | 23 | 146,922/158,208 · 22,635 | 158,208/158,208 · 0 | +| F16 | 21 | 33,806/37,376 · 0.345214844 | 37,376/37,376 · 0 | +| F32 | 286 | 436,635/557,824 · 0.345388740 | 557,824/557,824 · 0 | + +For the eight new settings, use image filter 0, global opacity .75, rotation −.09375 turns, pattern rotation randomness .125, position randomness (.1875, .3125) and non-square expansion. Keep other controls at defaults. Render each of the following at all four precisions. + +| Size · seed | Pattern · grid · input count · blend mode | Color · component randomness | Input pins | +|---|---|---|---| +| 16 × 64 · 504108 | 1 · 4 × 3 · 4 · 1 | (.25, .625, .875, .6875) · (.4375, .25, .3125, .125) | Connect all seven generated 32 × 16 U8 fields | +| 64 × 32 · 504131 | 3 · 2 × 5 · 6 · 0 | (.875, .375, .125, .9375) · (.25, .4375, .125, .375) | Leave the pins open | + +For the connected fields, index the background and the six pattern inputs by m = 0 through 6 and channels by c = 0 through 3. At texel (x,y), take h = ((67x + 43y + 13xy + 11cx + 29m + 59c + 112713) mod 383)/382. Use .75h plus .25 wherever (5x + 7y + 3m + c) mod 17 exceeds 9. Set channel c to one at ((3c + 8) mod 32, (m + 4) mod 16). Round to the nearest U8 level. The complete 560,378-byte SBS written by the corrected build matched the file used for the reference reopens byte for byte. + +The randomized tint passes three components to a straight-line arithmetic function. Reversing the pack and reversing the selection inside that function preserved the reference output and reproduced the correct draw order in the earlier evaluator. The shared pattern evaluator now evaluates packed scalar inputs when the called arithmetic first reads their components. A repeated component reuses its value. An unused component and a swizzle into zero padding consume no draws. The change applies to function calls in FX-Maps. + +To reproduce this independently, pack separate Random(1) draws into a vector and call a function that reads three channels a, b, c in the indicated order. Return .5a + .25b + .125c. Add .0625 times a separate Random(1) after the call and use the result as the opacity of a full-coverage additive square over black. Render F32 at 16², seed 0, at 32 × 16, seed 113, and at 16 × 32, seed 137. + +| Independent functions | Earlier exact pixels · maximum error | Current exact pixels on each route · maximum error | +|---|---:|---:| +| Float3 in XYZ, ZYX, YZX, ZXX and YYZ order, plus ZYX through replicated swizzles | 1,280/7,680 · 0.406245291 | 7,680/7,680 · 0 | +| Float2 YXY, WYW and WZW, Float4 WYX and ZWZ, Float3 WXZ, and a function returning .375 with its argument unused | 0/8,960 · 0.364476055 | 8,960/8,960 · 0 | + +At seed 0 the F32 word for XYZ and ZYX is `3e373b24`. The two-component WYW and WZW functions give `3d4da9dc` and `3c3d4b90`. Returning .375 gives `3ec5ea5c` after the outer draw. The two Rust regressions reproduced the first-use and zero-padding errors separately. + +The single-channel color series matches **128,000/128,000 F32 pixels** in 320 additional archived settings. The earlier evaluator matched 71,680/128,000, with maximum error .625. Use one tile, pattern 1, a 32² opaque white U8 image in the first pattern input and the other pins open. Select one input, filter 2, blend mode 0, full size and opacity, zero rotation and position randomness, and disable non-square expansion. Use the five base colors (.6875,.375,.8125,.78125), (.25,.5,.125,.25), (.9375,.3125,.5625,1), (.5,.625,.4375,.5) and (1,1,1,.375). Vary just one of the four randomness channels. Use seeds 0, 1, 17, 31, 97, 213, 3019, 12071, 42191, 68047, 133107 and 631883, cycling through 16², 32 × 16 and 16 × 32 in that order. Set the varying channel to .25 and .75 at seed indices 0, 3, 7 and 9, and to .5 at every other seed. [Earlier single-tile configuration and stock comparisons](#selected-blend-inputs-and-odd-sized-float-backgrounds-in-tile-generators) + +The 221 grayscale tile settings and 175 settings from 35 other qualified roots retained all 1,350,656 pixels. Both modern circular roots retained 70 exact settings each and the older pair retained 62 each. The 141 vector settings, 90 pure-call settings and raw outputs of 56 Pixel Processor programs retained their earlier values. All 590 node and evaluator release tests passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Rectangular expansion in the two random tile roots + +The shared function change also corrected two whole RGBA settings in `pattern_tile_random.sbs`. Repeating the [established random tile settings](#three-related-tile-roots-with-the-current-evaluator) gives 106/126 complete settings and 602,588/619,776 exact pixels in color, up from 104/126 and 601,273. Grayscale retains 32/52 settings and 300,698/316,672 pixels. Maximum errors in U8, U16, F16 and F32 are 255, 65,535, 1 and 1.00000006 for color and 254, 65,535, 1 and 1.00000006 for grayscale. Both roots remain open. + +At F32 with open pins and seed 845872, the two roots have the same pattern of differing pixels. Run 20 single-processor settings per root. Start at defaults at 16 × 32, then separately set the grid to (1,1), set both size randomness values to zero, and apply both changes together. Set the split threshold to zero and one with the default grid and with the single-tile grid. Try split mode zero with each grid. At (1,1), combine split threshold one, zero interstice and zero size randomness. With the default grid, set interstice to zero, then separately set interstice mode to zero. Try (2,1), (1,2), and disabling non-square expansion. Repeat defaults at seeds 0 and 113. Finally compare 32² and 32 × 16 at seed 845872. Each root gives 10 complete settings and **10,414/10,752** exact pixels, maximum error 1. At the tall default the count is 472/512. Turning expansion off or disabling both size variations gives 512/512. The square default gives 1,024/1,024. + +For the grayscale default, keep the outer Switch and its assignments and add a filter on the segment number it publishes. Allow all visits, then numbers zero through eight separately. The tall output has 245 nonzero center-segment pixels on both sides and matches 512/512 when only that segment runs. Selecting segment five preserves all 40 discrepancies. At 32 × 16, the center also matches 512/512 and selecting segment three preserves all 54 discrepancies. The other seven segment selections on either rectangle return black in both applications. + +### Circular pattern angles and random draws with computed bounds + +Both roots in `pattern_splatter_circular.sbs` now match **216,064/216,064 pixels across 70 distinct settings per root**. The earlier evaluator at `02f2e7d` matched 14/70 complete images per root, including 13/54 in the established series. The original on one processor, the original on eight and the one-processor reopen of the ordinary MaterialCraft SBS save all gave the same result. A color pixel counts as exact only when all four stored channels agree. [Established settings and input formulas](#circular-splatter-geometry-and-the-order-of-random-draws) + +| Storage | Settings per root | Earlier grayscale exact · maximum | Earlier color exact · maximum | Current exact per root on each route | Current maximum | +|---|---:|---:|---:|---:|---:| +| U8 | 4 | 7,978/9,216 · 243 | 6,831/9,216 · 254 | 9,216/9,216 | 0 | +| U16 | 8 | 122,131/123,904 · 62,451 | 121,002/123,904 · 65,535 | 123,904/123,904 | 0 | +| F16 | 4 | 7,967/9,216 · 0.952941895 | 6,831/9,216 · 0.996078491 | 9,216/9,216 | 0 | +| F32 | 54 | 69,451/73,728 · 1 | 68,484/73,728 · 1 | 73,728/73,728 | 0 | + +Start with the 54 linked settings for each root. For the additional F32 geometry comparisons, use the connected 64 × 32 setting at seed 70031 and its seven original input fields. Compare separate changes to unconnected patterns, pivot zero, rotation zero, and symmetry mode zero. Set all three of pivot, rotation and symmetry mode to zero together. Try one ring and one pattern, one ring alone, and one ring with three patterns. Disable the five varying terms together. Repeat the original at 32², at seed 113, and at 32² seed 113 with pivot, rotation and symmetry mode zero. The original occurs in both series and counts once. + +For four more F32 settings on each root, use that same connected control with the following symmetry probabilities. Keep the other exposed values and the original grayscale or RGBA input fields. + +| Size | Seed | Connected patterns | Symmetry mode | Symmetry probability | +|---|---:|---|---:|---:| +| 64 × 32 | 70031 | On | 0 | .375 | +| 32 × 64 | 113 | On | 1 | .625 | +| 32² | 42 | Off | 2 | .8125 | +| 64 × 32 | 0 | Off | 2 | .375 | + +In the connected setting, the angle already differed before drawing the first stamp. Both engines used the third unit draw for the later angle increments. Replacing the computed random range with the same literal, the same exposed scalar, or a unit draw multiplied by the range preserved the reference image. The separate rotation difference followed a function that makes a random choice using a computed symmetry probability. In the shared pattern evaluator, a draw can take its range or a called sampler’s arguments from expressions over immutable inputs. A shared inner conditional now consumes its draws when that conditional runs. Assignments and sampled image reads retain their order. + +For an independent full-coverage additive square at 16² F32, use three seeds (0, 113 and 137) and both values of an exposed switch. Store S = switch ? .1875 : A, then return (E × .5 + A × .25) + S × .125, with E a separate Random(1). For A, compare Random(7), Random(exposed 7), Random(max(0, X of the converted integer pair (7,7))) and Random(1) × 7. The second family calls a function returning −1 when its own Random(1) is below its argument and +1 otherwise. Supply .25, a public .25, or half a public .5. At seed 113 the range outputs are `3f94855e` and `3f70a852` in switch order off/on. The probability outputs are `3f4de37f` and `3f33e37f`. + +| Independent F32 controls | Settings | Earlier exact · maximum | Current exact on each route · maximum | +|---|---:|---:|---:| +| Four random bounds | 24 | 5,376/6,144 · 0.725004077 | 6,144/6,144 · 0 | +| Three probability arguments | 18 | 2,304/4,608 · 0.290001631 | 4,608/4,608 · 0 | +| Exposed and nested choices | 72 | 10,752/18,432 · 0.151002526 | 18,432/18,432 · 0 | +| Circular graph scalar field reads | 48 | 48,978/49,152 · 0.423094749 | 49,152/49,152 · 0 | + +The 48 field outputs read the stamp index, angles, radii, positions, offsets, sizes, rotation and tint on the connected, disconnected and one-stamp controls. Each of the two older circular roots retained all 190,720 pixels across 62 settings. The 221 grayscale Tile Generator settings and 175 settings across 35 other qualified roots retained all 1,350,656 pixels. The 141 vector settings, 90 pure-call settings and raw output words of 56 Pixel Processor programs stayed unchanged. Two new Rust regressions failed on the earlier evaluator. All 588 node and evaluator release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. [Nested choice and field reproduction](#compile-time-conditions-before-a-shared-pattern-draw) · [Older circular roots](#splatter-circular-color-and-assignments-before-a-later-function-call) + +### Three related tile roots with the current evaluator + +The same evaluator also rendered the established whole settings for the color Tile Generator and the two Tile Random roots. These counts compare the unmodified roots with the archived raw buffers. The earlier column comes from the [original tile series](#selected-blend-inputs-and-odd-sized-float-backgrounds-in-tile-generators) and includes changes across intervening revisions. All three roots were open at that revision. + +| Root | Exact settings | Earlier exact pixels | Current exact pixels | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---:|---| +| Tile Generator Color | 206/331 | 621,344/765,184 | 634,737/765,184 | 27 / 12,307 / 0.104003906 / 0.341796875 | +| Tile Random | 32/52 | 291,084/316,672 | 300,698/316,672 | 254 / 65,535 / 1 / 1.00000006 | +| Tile Random Color | 104/126 | 498,989/619,776 | 601,273/619,776 | 255 / 65,535 / 1 / 1.00000006 | + +At that revision, the 32² one-tile color generator test with pattern 2, the input pins open, seed 31 and hue randomness .5 still differs. In a private control, sending the randomized three-component value directly to the tint bypassed its color conversion and matched 14,336/14,336 F32 pixels across 14 settings at seeds 31 and 12071. Leaving the conversion in place and fixing all four draws to half their bounds also matched 14,336/14,336. The subsequent [component-read comparison](#component-reads-in-color-tile-function-arguments) records the fix. [Single-tile settings and procedural fields](#selected-blend-inputs-and-odd-sized-float-backgrounds-in-tile-generators) + +### Compile-time conditions before a shared pattern draw + +A quadrant can use the same random value in an optional assignment and in a later calculation. With a compile-time condition, the discarded arm consumes no draws. In the test below, a condition that reads an exposed variable yields different pixels even when it selects the same arm as a constant condition. An unwired argument of a called function behaves as a constant in this comparison. MaterialCraft now keeps this distinction when compiling pattern branches. + +Use a full-coverage additive square over black at 16² F32. Give its opacity function three separate Random(1) nodes A, T and E. Form L = A + (inner ? T : .3125). In the first input of a Sequence, store S = outer ? L : .1875. In the second, return (E × .5 + L × .25) + S × .125. Render both inner switch values at seeds 0, 113 and 137. Keep the pattern seed offset at its default. For the direct and called forms of T use Random(1) and a zero-argument function returning that draw. For the packed form, pack A and the inner result as Float2, then sum X and Y. + +| F32 cases | Settings | Earlier exact pixels | Earlier max error | Current exact pixels on each route | Current max error | +|---|---:|---:|---:|---:|---:| +| Folded condition on a direct or called draw | 12 | 1,536/3,072 | 0.143974781 | 3,072/3,072 | 0 | +| Reversed literal, negation and constant comparison | 18 | 0/4,608 | 0.143974781 | 4,608/4,608 | 0 | +| Literal wire, open argument and constant-returning call | 18 | 0/4,608 | 0.143974781 | 4,608/4,608 | 0 | +| Exposed or partly exposed condition | 24 | 3,072/6,144 | 0.151002526 | 3,072/6,144 | 0.151002526 | +| Nested exposed conditions | 48 | 7,680/12,288 | 0.151002526 | 7,680/12,288 | 0.151002526 | + +For the fixed conditions, use literal false, swap arms with literal true, negate literal true, or compare .25 > .5. In a called function test its scalar outer argument with > .5 and pass literal zero, leave it open at its zero default, or wire a function returning literal zero. For exposed controls use a public outer value, or AND it with false in each operand order. Exercise both exposed switches in the direct, called and packed forms. The originals on one processor, on eight and the one-processor reopens of ordinary MaterialCraft saves gave identical reference words. + +At seed 113, with the inner switch off, a fixed outer condition yields F32 word `3ee92f65`. An outer condition reading a public value yields `3f19b678` when it takes the same arm. With the inner switch on, the words are `3f171545` and `3f3bbfde`. The 48 fixed settings rose from 1,536 to **12,288/12,288** pixels. Both exposed series still have differences in the order of draws across nested choices. + +The two older circular roots retained 190,720/190,720 pixels apiece in 62 settings per root. The two roots in `pattern_splatter_circular.sbs` retained 13/54 exact settings each. The 221 grayscale Tile Generator settings and 175 archived settings on 35 other qualified roots retained 1,350,656/1,350,656 pixels. The 141 stored-vector cases, 90 pure-call controls and raw output words of 56 Pixel Processor programs also held. [Whole circular comparisons](#circular-splatter-geometry-and-the-order-of-random-draws) · [Older circular color settings](#splatter-circular-color-and-assignments-before-a-later-function-call) + +### Splatter Circular Color and assignments before a later function call + +Splatter Circular Color in `splatter_circular.sbs` matches all **190,720/190,720** pixels in **62 distinct whole settings**, up from 185,121 pixels and 31 complete settings at `4080c38`. Both reference processor counts and the one-processor reopen of the ordinary MaterialCraft SBS save gave the counts below. The 19 established reference captures reproduced their archives in 142,592/142,592 pixels. The grayscale root retained 190,720/190,720 across its own 62 settings on all three routes. + +| Storage | Settings | Earlier exact pixels | Earlier maximum | Current exact pixels on each route | Current maximum | +|---|---:|---:|---:|---:|---:| +| U8 | 5 | 8,587/9,216 | 247 | 9,216/9,216 | 0 | +| U16 | 10 | 123,129/124,416 | 65,535 | 124,416/124,416 | 0 | +| F16 | 6 | 10,635/11,264 | 0.96862793 | 11,264/11,264 | 0 | +| F32 | 41 | 42,770/45,824 | 1 | 45,824/45,824 | 0 | + +Use the [19 established settings](#tile-weave-splatter-and-fiber-stage-comparisons) and the [35 color settings](#grayscale-splatter-circular-across-four-output-formats) with their original RGBA inputs. For the eight additional renders, apply the exposed defaults at 64 × 16 and seed 724903 with the original 16² input pair. At 32 × 64 and seed 724934, use the 32² inputs of the first changed color setting with two patterns, radius .25, size (.25,.25), pattern 2, filtering 2, zero rotation and zero radius, size and mask randomness. Keep center orientation off. Render each rectangle in U8, U16, F16 and F32. + +In the quadrant opacity expression, the first input of a Sequence assigns the rotation, position and size. Its second input computes the tint and calls a function that can use the random stream. The evaluator had let that call change how it planned the earlier assignments. It now follows the boundary between the two inputs when the assignments finish in the first and the second exports no writes. + +Use one full-coverage additive square at 16² F32 and seeds 0, 113 and 137. Make the last operation in the opacity expression a Sequence. Let E be a call to a zero-argument function returning Random(1). The second input adds E/8 to the value described below. Repeat with a direct Random(1) in place of that call. A, B, C and D denote separate Random(1) nodes. Render both values of an exposed switch. + +| First input and value read by the second | Settings including direct controls | Earlier exact pixels | Earlier maximum F32 error | Current exact pixels on each route | Current maximum | +|---|---:|---:|---:|---:|---:| +| Assign the interpolation of (A,B) and (C,D) by .375, then select X or Y | 12 | 1,536/3,072 | 0.188753158 | 3,072/3,072 | 0 | +| Assign A when true and B when false, then read the assignment plus A/4 | 12 | 2,304/3,072 | 0.435002506 | 3,072/3,072 | 0 | +| Assign Y of (A,B), then return the assigned scalar | 12 | 1,536/3,072 | 0.579116881 | 3,072/3,072 | 0 | + +At seed 113 the interpolated-vector outputs with the additional E/8 were `3f1b5b11` and `3f297df4`. The conditional outputs were `3f846c61` and `3ee92f7e`. These words matched with either form of E, on one processor, on eight and after an ordinary save. The Rust regression exercises both sequences and failed on the previous evaluator. + +The 221 grayscale Tile Generator settings and the 175 archived controls on 35 other qualified roots retained **1,350,656/1,350,656** pixels, maximum zero. The 141 stored-vector and 90 pure-call controls retained their original words, as did 56 independent Pixel Processor graphs. The two modern circular roots in `pattern_splatter_circular.sbs` still have 13/54 exact settings each. [Vector controls](#storing-computed-vectors-in-a-quadrant-function) · [Modern circular cases](#circular-splatter-geometry-and-the-order-of-random-draws) + +## 2026-11-26 root comparisons + +### Grayscale Splatter Circular across four output formats + +The grayscale root in `splatter_circular.sbs` now matches all **62 distinct whole settings**, including the ordinary SBS saves. Its 19 established settings improved from 6 to 19 exact images and from 139,334 to 142,592/142,592 pixels. The one-processor reference reproduced all 142,592 archived pixels. The graph stores a randomized vector size and position. The shared quadrant evaluator now preserves the random draws that feed each stored component. [Stored-vector controls](#storing-computed-vectors-in-a-quadrant-function) · [Established inputs and settings](#tile-weave-splatter-and-fiber-stage-comparisons) + +| Storage | Distinct settings | Exact pixels on one processor | Exact pixels on eight processors | Exact pixels after ordinary save | Maximum error on each route | +|---|---:|---:|---:|---:|---:| +| U8 | 5 | 9,216/9,216 | 9,216/9,216 | 9,216/9,216 | 0 | +| U16 | 10 | 124,416/124,416 | 124,416/124,416 | 124,416/124,416 | 0 | +| F16 | 6 | 11,264/11,264 | 11,264/11,264 | 11,264/11,264 | 0 | +| F32 | 41 | 45,824/45,824 | 45,824/45,824 | 45,824/45,824 | 0 | + +For the additional rectangles, keep the 16² source and background of the established default. Render 64 × 16 at seed 724381. At 32 × 64 and seed 724412 use the two 32² fields from the first changed setting. Set Number to 2, Radius to .25, Pattern to 2, PatternSize to (.25,.25) and image input filtering to 2. Set radius, size and mask randomness to zero, with rotation zero and center orientation off. Render each rectangle in all four storage formats. + +For the separate 35-setting series, start at 32² F32 and seed 113 with the two 32² procedural F32 fields from the established changed setting. Use Number 5, Radius .375, Radius_Random .21875, Pattern 1, PatternSize (.1875,.3125), PatternSize_Random .15625, Rotation 22.5, image input filtering 1, center orientation on and RandomMask .1875. Compare the exposed defaults, the changed values, all three random amounts zero and each random amount alone. With the pins open, use Pattern 2, rotation zero and center orientation off. Repeat with 1, 2, 5 and 7 patterns, all three random amounts zero and each alone. With both pins supplied, use Pattern 1 and repeat the zero-randomness and changed settings at 1, 2 and 5 patterns. Also disconnect each pin separately and both together, try U8, U16 and F16, and render 16 × 64 at seed 0 and 64 × 16 at seed 137. The repeated five-pattern setting counts once. + +At `4080c38`, Splatter Circular Color was still open. The same 35-setting series used its rotation .21875 and its original color input fields. All three routes gave 17/35 exact settings and 32,615/35,840 exact pixels. Maximum errors were 165 U8 levels, 42,524 U16 levels, .648803711 in F16 and 1 in F32. With one analytic stamp and only radius randomness enabled, 1,004/1,024 pixels matched, maximum 1. + +### Whole caustic, scratch, splatter, tile and vertical noise comparisons + +At `67ee598`, MaterialCraft rendered the 19 established whole outputs for each of seven roots using their original inputs, seeds, parent sizes and storage formats. The first comparison uses archived raw buffers. The caustic graph uses the height, normal and noise fields from its original comparison. The two splatter roots and two tile roots in this table are from `splatter_circular.sbs` and `tile_random.sbs`. [Caustic settings and input formulas](#paths-caustics-and-cell-fields-after-pattern-sampling) · [Scratch, splatter, tile and vertical noise settings](#tile-weave-splatter-and-fiber-stage-comparisons) · [Four-format inventory comparison](#four-format-inventory-comparison) + +| Root | Previous exact pixels | Current exact pixels | Complete settings | Current maxima in U8 / U16 / F16 / F32 | +|---|---:|---:|---:|---| +| RT Caustics Base | 152,777/172,288 | 167,462/172,288 | 9/19 | 0 / 1 / 0 / 3.33786011e-06 | +| Scratches 2 | 118,291/142,592 | 141,575/142,592 | 6/19 | 0 / 1 / 0 / 1.78813934e-07 | +| Splatter Circular | 139,297/142,592 | 139,334/142,592 | 6/19 | 231 / 59,438 / 1 / 1.00000006 | +| Splatter Circular Color | 140,218/142,592 | 140,218/142,592 | 6/19 | 247 / 65,535 / 0.96862793 / 0.996078431 | +| Tile Random | 111,364/142,592 | 111,364/142,592 | 0/19 | 223 / 57,311 / 1 / 1.00000006 | +| Tile Random Color | 111,228/142,592 | 111,228/142,592 | 0/19 | 250 / 65,535 / 1 / 2.00000003 | +| Vertical Noise | 142,088/142,592 | 142,295/142,592 | 9/19 | 0 / 2 / 0 / 1.75237656e-05 | + +Take one case per storage format from first-pass controls, the precision matrix and the additional settings above. Choose the lowest exact fraction in that format, breaking ties by smaller pixel count. Save each graph as an ordinary SBS file from MaterialCraft. Capture each original with one and eight reference processors and reopen the save with one. Integer maxima are storage levels. Float maxima are absolute errors. + +| Root | U8 dimensions / seed | U16 dimensions / seed | F16 dimensions / seed | F32 dimensions / seed | +|---|---|---|---|---| +| RT Caustics Base | 64 × 64 / 42 | 64 × 64 / 4127 | 64 × 64 / 42 | 128 × 128 / 4159 | +| Scratches 2 | 32 × 32 / 115729 | 32 × 32 / 115729 | 32 × 32 / 115729 | 64 × 32 / 115735 | +| Splatter Circular | 32 × 32 / 116154 | 32 × 32 / 116154 | 32 × 32 / 116154 | 64 × 32 / 116160 | +| Splatter Circular Color | 32 × 32 / 116171 | 32 × 32 / 116171 | 32 × 32 / 116171 | 32 × 32 / 116171 | +| Tile Random | 32 × 32 / 116715 | 32 × 32 / 116715 | 32 × 32 / 116715 | 32 × 32 / 116715 | +| Tile Random Color | 32 × 32 / 116732 | 32 × 32 / 116732 | 32 × 32 / 116732 | 32 × 16 / 116736 | +| Vertical Noise | 32 × 32 / 116919 | 32 × 32 / 116919 | 32 × 32 / 116919 | 32 × 32 / 116918 | + +| Root | One processor · maxima U8 / U16 / F16 / F32 | Eight processors · maxima | Ordinary save · maxima | +|---|---|---|---| +| RT Caustics Base | 25,402/28,672 · 0 / 0 / 0 / 7.74860382e-07 | 25,295/28,672 · 0 / 1 / 0 / 8.34465027e-07 | 25,092/28,672 · 0 / 0 / 0 / 8.34465027e-07 | +| Scratches 2 | 5,120/5,120 · 0 / 0 / 0 / 0 | 4,960/5,120 · 0 / 1 / 0 / 1.1920929e-07 | 5,120/5,120 · 0 / 0 / 0 / 0 | +| Splatter Circular | 3,814/5,120 · 231 / 59,438 / 0.906524658 / 0.929198086 | 3,814/5,120 · 231 / 59,438 / 0.906524658 / 0.929198086 | 3,814/5,120 · 231 / 59,438 / 0.906524658 / 0.929198086 | +| Splatter Circular Color | 3,388/4,096 · 174 / 44,618 / 0.680664062 / 0.680815682 | 3,388/4,096 · 174 / 44,618 / 0.680664062 / 0.680815682 | 3,388/4,096 · 174 / 44,618 / 0.680664062 / 0.680815682 | +| Tile Random | 1,921/4,096 · 223 / 57,222 / 0.947509766 / 0.947844714 | 1,921/4,096 · 223 / 57,222 / 0.947509766 / 0.947844714 | 1,921/4,096 · 223 / 57,222 / 0.947509766 / 0.947844714 | +| Tile Random Color | 1,619/3,584 · 187 / 48,014 / 0.732543945 / 2.00000003 | 1,619/3,584 · 187 / 48,014 / 0.732543945 / 2.00000003 | 1,619/3,584 · 187 / 48,014 / 0.732543945 / 2.00000003 | +| Vertical Noise | 4,080/4,096 · 0 / 1 / 0 / 1.75237656e-05 | 4,085/4,096 · 0 / 1 / 0 / 1.75237656e-05 | 4,080/4,096 · 0 / 1 / 0 / 1.75237656e-05 | + +MaterialCraft reproduced every original pixel on its own reopens. At `67ee598` all seven roots were in progress. + +| Root | Fresh one vs archive · maxima U8 / U16 / F16 / F32 | One vs eight · maxima | One vs reopened · maxima | +|---|---:|---:|---:| +| RT Caustics Base | 24,931/28,672 · 0 / 1 / 0 / 1.07288361e-06 | 25,294/28,672 · 0 / 1 / 0 / 7.15255737e-07 | 26,889/28,672 · 0 / 0 / 0 / 4.17232513e-07 | +| Scratches 2 | 4,835/5,120 · 0 / 1 / 0 / 1.1920929e-07 | 4,960/5,120 · 0 / 1 / 0 / 1.1920929e-07 | 5,120/5,120 · 0 / 0 / 0 / 0 | +| Splatter Circular | 5,120/5,120 · 0 / 0 / 0 / 0 | 5,120/5,120 · 0 / 0 / 0 / 0 | 5,120/5,120 · 0 / 0 / 0 / 0 | +| Splatter Circular Color | 4,096/4,096 · 0 / 0 / 0 / 0 | 4,096/4,096 · 0 / 0 / 0 / 0 | 4,096/4,096 · 0 / 0 / 0 / 0 | +| Tile Random | 4,096/4,096 · 0 / 0 / 0 / 0 | 4,096/4,096 · 0 / 0 / 0 / 0 | 4,096/4,096 · 0 / 0 / 0 / 0 | +| Tile Random Color | 3,584/3,584 · 0 / 0 / 0 / 0 | 3,584/3,584 · 0 / 0 / 0 / 0 | 3,584/3,584 · 0 / 0 / 0 / 0 | +| Vertical Noise | 4,080/4,096 · 0 / 1 / 0 / 1.69277191e-05 | 4,081/4,096 · 0 / 1 / 0 / 1.69277191e-05 | 4,096/4,096 · 0 / 0 / 0 / 0 | + +#### Scratches 2 across all established settings and two new rectangles + +Repeat the full 19-setting series at both processor counts and on ordinary reopen. Add the exposed defaults at 64 × 16 at seed 727889 and the first changed scratch setting at 32 × 64 at seed 727920, each in U8, U16, F16 and F32. The changed values are `Pattern_size_width` 100.0, `Pattern_size_height` 100.0, `Disorder` 0.0. + +| Settings | One processor · exact images · exact pixels · maxima U8 / U16 / F16 / F32 | Eight processors | Ordinary save | +|---|---|---|---| +| Established | 19/19 · 142,592/142,592 · 0 / 0 / 0 / 0 | 7/19 · 141,518/142,592 · 0 / 1 / 0 / 2.38418579e-07 | 19/19 · 142,592/142,592 · 0 / 0 / 0 / 0 | +| Additional rectangles | 8/8 · 12,288/12,288 · 0 / 0 / 0 / 0 | 6/8 · 12,016/12,288 · 0 / 0 / 0 / 1.78813934e-07 | 8/8 · 12,288/12,288 · 0 / 0 / 0 / 0 | + +A second eight-processor render of 64 × 64 at seed 42 matched 3,696/4,096 pixels of the first, maximum 2.38418579e-07. Repeating the new F32 rectangle at 32 × 64 at seed 727920 matched 1,887/2,048, maximum 1.78813934e-07. The original and reopened local buffers agreed for all 27 settings. + +### Storing computed vectors in a quadrant function + +A quadrant that stores a computed vector evaluates the operands for its first component before it draws the operands for the second. MaterialCraft now uses that order for stored sums, products, scalar multiples and interpolations. A scalar shared by two components consumes one draw. + +Use one full-coverage additive square over black at 16 × 16 F32 and graph seeds 0, 113 and 137. In its opacity function, pack independent Random(1) draws into vectors A and B. Store the result, then return one component of the stored value per render. For widths two, three and four, add A and B, multiply them component by component, scale A by another random draw and interpolate from A to B by .375. Repeat the product after connecting the first component of A to the last component of B. For width two also choose between the two vectors with a condition, then read the selected component. Compare the original on one and eight reference processors and the one-processor reopen of an ordinary MaterialCraft save. + +| Vector width | Settings | Previous exact pixels | Previous maximum F32 error | Current exact pixels | Current maximum F32 error | +|---:|---:|---:|---:|---:|---:| +| 2 | 36 | 2,304/9,216 | 0.302005053 | 9,216/9,216 | 0 | +| 3 | 45 | 0/11,520 | 0.843028545 | 11,520/11,520 | 0 | +| 4 | 60 | 0/15,360 | 0.71621437 | 15,360/15,360 | 0 | + +Each of the three routes matched **36,096/36,096** raw F32 pixels, up from 2,304. Both local renders also agreed in every setting. The three- and four-component interpolation results uniquely fit successive draws for (A₁,B₁), then (A₂,B₂), continuing through the final component. For example, at seed 113 the first two stored components were .496003091 and .551222920. A regression reads both components of five assignments at each of the three stamp seeds. + +Pixel Processor product rounding uses the consumers in the original expression. Six size and storage settings for each of 16 independent returned-vector expressions matched **282,624/282,624** pixels, maximum zero, with this fix and at `67ee598`. Use 16² F32 at seed 47, 64² U8, U16, F16 and F32 at seed 223, and 32² F32 at seed 449. The regression for independently returned product components also passed. + +The 221 grayscale Tile Generator settings and 175 settings from 35 other qualified roots matched **1,350,656/1,350,656** archived pixels, maximum zero. All 90 earlier pure-function settings stayed exact. Each root in `pattern_splatter_circular.sbs` still matched 13/54 whole settings on one processor, on eight and after saving. [Pure-function expressions](#shared-draws-and-channel-selection-across-pure-pattern-calls) · [Circular geometry and per-format errors](#circular-splatter-geometry-and-the-order-of-random-draws) + +### Shared draws and channel selection across pure pattern calls + +A quadrant expression can assign a value, call a function and later reuse a draw from a conditional arm. When each called function computes only from its declared arguments and constants, MaterialCraft now preserves the shared draw's position and evaluates only the selected channel of a packed value. The check follows nested calls. A call that draws a random value, samples an image, writes a variable or reads an undeclared name can observe evaluation order. + +Start with one ring and one stamp from the [circular geometry control](#circular-splatter-geometry-and-the-order-of-random-draws). Use a full-coverage additive square over black at 16 × 16 F32, offsets (0,0), size (1,1), and seeds 0, 113 and 137. In the opacity graph let A and B be independent Random(1) nodes. Choose A or B by comparing an exposed float of 0 or 1 with .5, assign the result to a named float and return that result plus A/4 plus π/8. Supply π through a constant-returning function. At seed 113 the F32 words for false and true are `3fa910f3` and `3f3da6cd`. Repeat with a literal in place of the call, with and without the assignment, and with another read of the assigned value added to the result. + +| F32 controls | Settings | Exact pixels before | Maximum error before | Exact pixels after | Maximum error after | +|---|---:|---:|---:|---:|---:| +| Shared draw, assignment, constant call and controls | 30 | 6,144/7,680 | 1.015005827 | 7,680/7,680 | 0 | +| One or two calls computing from a declared argument | 12 | 1,536/3,072 | .435002476 | 3,072/3,072 | 0 | +| Selecting channels of packed draws or their product | 12 | 0/3,072 | .578230530 | 3,072/3,072 | 0 | +| Direct draws shared across two conditions and independent controls | 36 | 6,912/9,216 | .578230530 | 9,216/9,216 | 0 | + +For the argument cases, replace π/8 with a function that returns one eighth of its scalar input. Supply the switch as 0 or 1, directly or through an enclosing function. For the channel cases pack (A,B), select X or Y and store it, then add one quarter of a fresh draw and a function returning .125. Repeat with the X component of (A,B) × (C,D), and with its Y component also added at the end. For the two-condition cases store the first choice between A and B, then add one quarter of a second choice between A and C. Exercise all four switch combinations. Repeat with the first arms reversed and with the second condition using only independent draws. Supply the first switch divided by eight through a function. + +Both reference processor counts and the reference reopen of ordinary MaterialCraft saves matched **23,040/23,040** pixels in these 90 settings. The original and reopened MaterialCraft buffers also agreed. In the separate two-condition control where the shared draw happens inside a called function, only 1,536/3,072 pixels matched. When assigning an entire pairwise vector product, sum or interpolation before reading the result, each operation matched 0/1,536 pixels. At seed 113, interpolating (A,B) toward (C,D) by .375 gave (.496003091, .551222920) in the reference. Across all three seeds this matches drawing A, C, B, D. + +Grayscale Tile Generator retained **757,504/757,504** pixels in its 221 established settings. One or more archived renders of each of the 15 other qualified roots whose quadrant expressions combine assignments, calls and conditional or channel selection matched **227,840/227,840** pixels in 71 settings, maximum zero. The two circular splatter roots retained the same per-format counts and maxima in all 54 settings each on one processor, on eight and after saving. Both remain in progress. [Whole circular results](#circular-splatter-geometry-and-the-order-of-random-draws) · [Grayscale tile inputs and output formats](#selected-channels-in-pattern-expressions) + +### Circular splatter geometry and the order of random draws + +The two roots in `pattern_splatter_circular.sbs` at `bd12ea4` matched every pixel in 13 of 54 distinct settings each. Both original reference processor counts and the one-processor reopen of an ordinary MaterialCraft SBS save gave identical raw buffers in all 54. Each application also reproduced its own originals after saving. The fresh reference buffers for all nine established settings agree with the archives in 132,096/132,096 pixels per root, maximum zero. [Earlier nine whole outputs](#other-roots-using-uniform-arc-tangents) + +| Root | U8 exact pixels · max levels | U16 exact pixels · max levels | F16 exact pixels · max error | F32 exact pixels · max error | +|---|---:|---:|---:|---:| +| Grayscale | 7,978/9,216 · 243 | 122,131/123,904 · 62,451 | 7,967/9,216 · 0.952941895 | 41,608/44,032 · 1 | +| Color | 6,831/9,216 · 254 | 121,002/123,904 · 65,535 | 6,831/9,216 · 0.996078491 | 40,425/44,032 · 1 | + +Start the 32 × 32 F32 control at seed 113 with pattern 3, two rings, seven patterns, radius .35, pattern size (.7,1.2) and scale .8. Set amount random, radius random, angle random, spiral factor and rotation random to (.2,.15,.2,.1,.3). Use the 32² procedural fields numbered one for the background and two through seven for the six pattern image pins. Render with all fields, just the background, just the pattern inputs, or all pins open. Also render exposed defaults, seed 42, 64 × 16, 16 × 64, and the original 32² setting at U8, U16 and F16. [Procedural field formulas](#four-format-inventory-comparison) + +At 32² vary the ring count to one or three and the pattern count to one, three or five, including one of each. Toggle each of the five varying terms off separately. At both one ring and one pattern and the original two rings and seven patterns, enable each varying term alone, the first three together, the last two together, all five or none. Add the nine earlier cases. At 64 × 32 seed 70031 enable connected patterns, set the pivot to 2, rotation to .125 and symmetry random mode to 1. At 32 × 64 seed 74571 use pattern 1, three image inputs, distribution 0, rotation −.1875, five patterns and three rings. Render these two rectangles in all four formats. Duplicate settings count once. + +In the independent seed-113 setting both roots differ at the same 21 of 1,024 pixels. Maximum F32 errors are .921568625 in grayscale and .996078431 in color. With one ring and one pattern, the two roots each match 882/1,024. Radius variation alone gives 1,020/1,024, rotation variation alone gives 872/1,024, and disabling all five varying terms gives 1,024/1,024. + +To read the geometry, retain the Iterate and Switch graph, the original count expressions and every assignment of the quadrant opacity function. Reset a scalar draw counter before the outer count. After evaluating opacity, increment the counter and use the requested published scalar as the opacity of an additive square of size (.025,.025). Place successive squares at distinct pixel centers starting at (0,0) in a black, untiled 32² F32 field. The independent control has 12 draws and the one-ring, one-pattern control has one. In the latter, the initial angle 3.103569269 and initial radius .331919193 match. MaterialCraft then publishes radius .277020574 and rotation .457172245, where the reference gives .281947523 and .538937986. Pattern size and tint match. + +For a separate stream control, replace the quadrant expression with 24 consecutive assignments of Random(1) and read each assigned value. The two seeds 113 and 137 match 49,152/49,152 F32 pixels on both processor counts and on reopen, maximum zero. At seed 113 the second, sixth and seventh samples are .858505130, .288028121 and .560580373. With only radius variation enabled, MaterialCraft uses sample seven. Sample two reproduces the recorded radius. With only rotation variation enabled, MaterialCraft uses sample six. Sample seven reproduces the recorded rotation. These indices reproduce every observed scalar word at seeds 0, 113, 137, 12071 and 68119. For radius use `r + (r * (r * u) − r) * .15` with r = .35 and unit draw u. For rotation use the starting angle of three quarters of a turn, interpolate in radians toward `2πu − π` by .3, then divide by 2π. Round each operation to F32. Both roots remain in progress. + +### Pattern Fibers 1 at default and changed tiling + +Pattern Fibers 1 now matches **438,528/438,528 pixels across 36 whole settings** on one processor, on eight and when reopened from an ordinary MaterialCraft SBS save. All 24 earlier whole settings now match their original archived buffers, including the 7,393 pixels that differed in the previous comparison. This version of the graph takes no image inputs and exposes tiling and non-square expansion. [Established 24 settings, dimensions and seeds](#fibers-and-fluid-pattern-stages) · [Earlier differences by storage format](#pattern-rotation-phase) + +For the additional three rectangles use 16 × 32 at seed 628801 with exposed defaults, 64 × 16 at seed 628833 with tiling 5 and non-square expansion on, and 32 × 64 at seed 628865 with tiling 3 and expansion off. Set the node feeding the output to each of U8, U16, F16 and F32. The original and saved local buffers have the same raw words in every case. + +| Settings | U8 exact | U16 exact | F16 exact | F32 exact | Maximum error on all routes | +|---|---:|---:|---:|---:|---:| +| Established | 5,120/5,120 | 285,696/285,696 | 5,120/5,120 | 128,256/128,256 | 0 | +| Additional rectangles | 3,584/3,584 | 3,584/3,584 | 3,584/3,584 | 3,584/3,584 | 0 | + +All 36 fresh original readbacks agree across the two processor counts and with their one-processor saved-file readbacks. Pattern Fibers 1 qualifies for parity in the measured cases. + +### Full Pattern Weave 2 comparisons at both processor counts + +On release `bd12ea4`, Pattern Weave 2 matches **3,139,840/3,139,840 pixels across all 95 established whole settings** on one processor, on eight, and in fresh ordinary saves opened in both applications. The earlier whole comparison differed at 351 pixels. Each fresh one-processor readback agrees with the corresponding archived original. This graph takes no image input. The measurements cover the original defaults and changed square and rectangular outputs, including different seeds, scales, disorder, 45-degree rotation and non-square expansion. [Seven sizes, fixed fields and reopen settings](#saved-splatter-and-weave-graphs-across-independent-fields) · [Earlier shape and oblique bounds controls](#fixed-and-input-driven-rotation-bounds-for-oblique-stamps) + +| Compared in each of the three routes | U8 exact | U16 exact | F16 exact | F32 exact | Maximum error | +|---|---:|---:|---:|---:|---:| +| Whole outputs | 400,896/400,896 | 1,174,016/1,174,016 | 402,944/402,944 | 1,161,984/1,161,984 | 0 | + +Separately reopen the previously saved packages and compare with the archived reference readbacks of those same files. The first 20 settings match 179,200/179,200 pixels, the second ten match 64,000/64,000, and the thirteen fixed-field settings match 26,624/26,624. All 43 saved renders match **269,824/269,824 pixels**, maximum zero. Pattern Weave 2 qualifies for parity in the measured cases. + +### Full Arc Pavement comparisons across shape selections and ordinary saves + +Arc Pavement matches **791,296/791,296 pixels across 93 distinct whole-graph settings** on release `bd12ea4`. Each setting matched on one processor, on eight and after an ordinary MaterialCraft SBS save opened in both applications. All maximum stored errors are zero. The original desktop buffers from the earlier comparisons also reproduce the fresh one-processor readbacks, including the 64² and 128² image-input cases. + +The first 47 settings repeat the original archive, precision controls, analytic profiles, image filters and seven output sizes with the procedural grayscale input. At 64² and 128² also select each shape 0 through 9, once with the established counts and once with scale and all three counts set to one, amount randomness, color randomness and height decrease zero. At each size separately set pattern variation, color randomness, height decrease and amount randomness to zero from the original changed setting. Two of these 48 comparisons coincide with established settings. [Exact input field, seeds, dimensions and parameter table](#isolated-arc-pavement-draws-in-a-nonunit-render-region) + +| Whole output series | Distinct settings | U8 exact | U16 exact | F16 exact | F32 exact | +|---|---:|---:|---:|---:|---:| +| Established whole settings | 47 | 30,720/30,720 | 155,904/155,904 | 30,720/30,720 | 102,912/102,912 | +| Additional selector and parameter settings | 46 | — | — | — | 471,040/471,040 | + +The same counts apply separately to both original processor counts and the fresh saved-file comparison. The two earlier ordinary saves, covering 30 renders, match all 153,344/153,344 pixels against their archived reference buffers, maximum zero. The earlier scaled-window ramp at (32, 62) also matches. Across five isolated 64 × 64 ramp settings the result is 20,480/20,480 on both processor counts and on ordinary reopen. Arc Pavement qualifies for parity in the measured cases. + +### Two more whole outputs in Noise Clouds 1 v2 + +Noise Clouds 1 v2 now renders **58/60 established originals** and **14/15 archived ordinary saves** across the recorded passes. The earlier measurements covered 56 originals and 13 saves. The two additional originals are 128 × 128 at seed 411810. Set scale to 3, disorder, disorder speed and disorder anisotropy to .65625, anisotropy angle to .40625, tile offset to (.3125, −.16796875) and non-square expansion off. Keep normal tiling and the other exposed defaults. Set U16 or F32 storage on the node connected to the output. [Earlier full series](#whole-and-saved-outputs-for-noise-clouds-1-v2-at-the-four-child-batch-boundary) + +| Storage | Original · one processor | Original · eight | Fresh ordinary save · one | +|---|---:|---:|---:| +| U16 | 16,377/16,384 · 1 | 16,377/16,384 · 1 | 16,377/16,384 · 1 | +| F32 | 14,494/16,384 · 2.68220901e−7 | 14,618/16,384 · 2.38418579e−7 | 14,498/16,384 · 2.68220901e−7 | + +Both new saves reproduce their local original exactly. The earlier archived F32 save also produces the same local value at every pixel and matches 14,471/16,384 · 2.98023224e−7 against its original saved-file capture. Repeating the whole F32 case on the preceding release `ea1543c` gives the same full buffer as `bd12ea4`. The two recovered cases still have the raw differences shown above. + +The two rectangular settings in each of Noise Clouds 1 v2 and Noise Clouds 2 v2 still reach the execution limit on `bd12ea4`. Use 64 × 32 F32 and 32 × 64 U16, at seeds 103034 and 103035 for the first graph and 103056 and 103057 for the second. Set scale 5, disorder .8125, disorder speed 1.4375, disorder anisotropy .625, its angle −.21875, tile offset (−.3125, .4375) and non-square expansion on. All other exposed controls are at default. These four cases produced no local pixel comparison. [Depth-seven and terminal visit counts](#counting-terminal-draws-in-the-two-remaining-clouds-variants) + +### Individual paraboloids and additive order in Noise BNW Spots 3 v2 + +At 64 × 64 F32 and seed 411585, fifteen desktop readbacks agreed with one another and differed from MaterialCraft at three pixels. Record the background and nonzero additive draws there in MaterialCraft traversal order. Each pixel receives eleven paraboloids at depths six through nine. The diagnostic cook reproduces the complete checked release buffer. [Root parameters and full-image comparisons](#seeded-quadrant-properties-with-a-live-tint-multiplier) + +To isolate a draw, use a zero background, the same render and tiling intervals and a single additive paraboloid. Set its branch offset to (−.5, −.5). Supply its absolute center, two dimensions and rotation as exposed floats. Set roughness to zero and global opacity to one. Supply its observed scalar tint multiplied in F32 by its depth opacity. On one processor, on eight and after an ordinary SBS save, all 33 individual images match **135,168/135,168 F32 pixels**, maximum zero. At the three selected pixels every individual contribution also equals its corresponding value in the full MaterialCraft render. + +For the sum controls, restore the two upstream maps as the background. Connect one drawing Quadrant to the repeated branch of an eleven-count Iterate. Use the repetition number to select each recorded center, dimensions, rotation and tint. Run each group in traversal order, reversed and in the third order shown below. Number the draws 0 through 10 in traversal order. All nine complete images match **36,864/36,864 F32 pixels**, maximum zero on each processor count and ordinary reopen. The forward sum gives the full MaterialCraft value at each selected pixel. Both other orders give the observed full reference word. + +| Pixel | Background word | Forward sum | Reversed and third sum | Third order | +|---|---|---|---|---| +| (9, 9) | `0x3eecaced` | `0x3efb6504` | `0x3efb6505` | 1, 0, 6, 10, 2, 4, 8, 9, 3, 5, 7 | +| (33, 41) | `0x3f13a394` | `0x3f0d59a0` | `0x3f0d59a1` | 1, 6, 8, 3, 5, 10, 7, 4, 2, 9, 0 | +| (46, 33) | `0x3f117191` | `0x3f1d2b80` | `0x3f1d2b7f` | 7, 6, 8, 3, 2, 5, 9, 10, 0, 4, 1 | + +For a direct arithmetic replay, interpret each word below as an IEEE binary32 addend. Start at the background word above and round after each addition. + +| Pixel | Addends 0 through 10, hexadecimal | +|---|---| +| (9, 9) | `bb099c21 bb265fee 3c85b53d bc50a193 3ac2eb52 bb17681c 3bf2fcfe 3d04b40d b954f349 bb57489b bbbae64f` | +| (33, 41) | `b8f3de8b b9254daf 39801678 bc578327 bbf6df9d bb108f40 babee2ea bb91c340 bbbb5b83 3c02e67b 3b026ca1` | +| (46, 33) | `bc24af84 bb2e0f62 bc92ce6d bb977f92 3d185f5f 3cc996f0 3a2f311a 3b930c49 3c9319d8 ba1fdcfe bb553cf7` | + +In a local arithmetic replay with the stored background and eleven addends held fixed, 30,987,036 of 39,916,800 permutations give the reference word at (9, 9). At each of the other two pixels, 19,958,400 permutations give each of the two possible words. These results establish that addition order suffices to reproduce the three differences. The execution order of the full reference tree remains unresolved. + +Keep the complete source graph and change just the outer Iterate count on its final FX-Map. Evaluate its original count first in a Sequence, then return zero, one or two. Use the [four established sizes, settings and seeds](#seeded-quadrant-properties-with-a-live-tint-multiplier) in F32. At zero repeats all **23,552/23,552** background pixels match on both processor counts and after saving, maximum zero. The local ordinary save reproduces the original at every count and size. + +| Outer repeats · size | Original · one processor | Original · eight | Ordinary save · one | +|---|---:|---:|---:| +| 1 · 64 × 16 | 1,015/1,024 · 1.1920929e−7 | 1,016/1,024 · 5.96046448e−8 | 1,018/1,024 · 1.1920929e−7 | +| 1 · 64 × 64 | 4,036/4,096 · 1.1920929e−7 | 4,029/4,096 · 1.49011612e−7 | 4,039/4,096 · 1.78813934e−7 | +| 1 · 128 × 128 | 16,123/16,384 · 2.38418579e−7 | 16,196/16,384 · 1.78813934e−7 | 16,121/16,384 · 1.78813934e−7 | +| 1 · 64 × 32 | 2,031/2,048 · 1.49011612e−7 | 2,033/2,048 · 1.1920929e−7 | 2,028/2,048 · 1.1920929e−7 | +| 2 · 64 × 16 | 1,019/1,024 · 1.1920929e−7 | 1,017/1,024 · 5.96046448e−8 | 1,017/1,024 · 1.1920929e−7 | +| 2 · 64 × 64 | 3,981/4,096 · 1.1920929e−7 | 3,975/4,096 · 1.1920929e−7 | 3,981/4,096 · 1.1920929e−7 | +| 2 · 128 × 128 | 15,888/16,384 · 1.78813934e−7 | 15,920/16,384 · 1.78813934e−7 | 15,883/16,384 · 2.38418579e−7 | +| 2 · 64 × 32 | 2,017/2,048 · 1.1920929e−7 | 2,007/2,048 · 1.1920929e−7 | 2,015/2,048 · 1.49011612e−7 | + +To narrow the 64 × 16 and 64 × 64 differences, keep one outer repetition. Vary how many of the first six empty Quadrants retain all four connections. Below the last full subdivision, keep just the slot at that depth from the zero-based sequence 0, 3, 1, 2, 0, 3. Preserve the original slot identifiers and all downstream programs. With one, four, sixteen or sixty-four connected paths, the four controls match **20,480/20,480** pixels on each route, maximum zero. With sixty-four paths the draw changes eight pixels at 64 × 16 and sixty-four at 64 × 64 relative to the background. + +| Connected paths · size | Original · one | Original · eight | Ordinary save · one | +|---|---:|---:|---:| +| 256 · 64 × 16 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| 256 · 64 × 64 | 4,094/4,096 · 2.98023224e−8 | 4,095/4,096 · 2.98023224e−8 | 4,095/4,096 · 2.98023224e−8 | +| 1,024 · 64 × 16 | 1,022/1,024 · 2.98023224e−8 | 1,024/1,024 · 0 | 1,023/1,024 · 2.98023224e−8 | +| 1,024 · 64 × 64 | 4,083/4,096 · 5.96046448e−8 | 4,089/4,096 · 5.96046448e−8 | 4,088/4,096 · 5.96046448e−8 | + +For each 64 × 64 reduced tree, switch from seed 411585 to each of 411586, 411587 and 411588, returning to 411585 after every change on both processor counts. Include the original one-processor, eight-processor and saved readbacks. At 256 paths MaterialCraft matches all 4,093/4,093 invariant pixels and gives an observed word at all 4,096 positions. At 1,024 paths it matches 4,074/4,076 invariant pixels, maximum 2.98023224e−8. At (30, 33) its F32 word is `0x3efe38ce` and all nine reference readbacks give `0x3efe38cd`. At (27, 44) the words are `0x3efd0339` and `0x3efd033a`. The full root stays in progress. + +### Seeded quadrant properties with a live tint multiplier + +A grayscale quadrant can set a two-component frame offset and then choose between a seeded scalar and that same scalar multiplied by a live gain. MaterialCraft now reuses the seed-dependent draw properties for a repeated seed, node, depth and selected branch. It reapplies the current gain and publishes the offset in its original drawing scope before visiting children. The other computed fields must depend only on the seed, depth and fixed inputs. A direct read must connect the assigned offset to the frame. Each draw retains its original position in the traversal. + +For an independent control, connect four or seven outer iterations to an inner Iterate with seed inheritance disabled. In the count expression publish the outer number and a gain of (1 + number) × .25 or × .125, then return two. Connect a .625 × .375 additive square to the repeated branch. Set an offset from two Rand(.25) draws, then return .0625 + Rand(.125), scaled by the gain when the outer number exceeds 1.5. Use that offset for the square and its negative for four .375 × .25 children at .125 luminosity. Use the [three sizes, seeds and four formats from the initial-branch controls](#the-incoming-seed-on-the-initial-branch-of-an-iterate). All 24 originals match 10,240/10,240 pixels on both processor counts. The 24 ordinary saves also match 10,240/10,240. Maximum error is zero. A bounded regression compares the direct offset with an equivalent computed offset and checks a descendant reading the published value. + +Open `noise_bnw_spots_3_v2.sbs/bnw_spots_3` with its normal tiling. Set disorder, disorder speed and disorder anisotropy to the same value in the table. Keep other exposed parameters at default. Set storage precision on the node feeding the output. Compare the stored pixel words against the original desktop outputs on one and eight processors. For the saved column use an ordinary MaterialCraft SBS reopened directly in each application and a one-processor desktop capture. Integer errors are storage levels. + +| Size · seed | Scale | Disorder | Anisotropy angle | Tile offset | Non-square expansion | +|---|---:|---:|---:|---|---| +| 64 × 16 · 42 | 2 | 0.03125 | -0.21875 | (-0.3125, 0.37890625) | true | +| 64 × 64 · 411585 | 3 | 0.34375 | 0.09375 | (0, 0.10546875) | true | +| 128 × 128 · 411768 | 3 | 0.65625 | 0.40625 | (0.3125, -0.16796875) | false | +| 64 × 32 · 194535 | 3 | 0.34375 | 0.09375 | (0, 0.10546875) | true | + +| Size · storage | Original · one | Original · eight | Ordinary save · one | +|---|---:|---:|---:| +| 64 × 16 · U8 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| 64 × 16 · U16 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| 64 × 16 · F16 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| 64 × 16 · F32 | 950/1,024 · 1.1920929e-07 | 945/1,024 · 8.94069672e-08 | 930/1,024 · 1.1920929e-07 | +| 64 × 64 · U8 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| 64 × 64 · U16 | 4,093/4,096 · 1 | 4,095/4,096 · 1 | 4,095/4,096 · 1 | +| 64 × 64 · F16 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| 64 × 64 · F32 | 3,695/4,096 · 1.78813934e-07 | 3,562/4,096 · 2.38418579e-07 | 3,578/4,096 · 1.78813934e-07 | +| 128 × 128 · U16 | 16,377/16,384 · 1 | 16,379/16,384 · 1 | 16,380/16,384 · 1 | +| 128 × 128 · F32 | 14,631/16,384 · 2.38418579e-07 | 14,275/16,384 · 2.38418579e-07 | 14,185/16,384 · 2.08616257e-07 | + +All ten previously blocked originals and their new ordinary saves render. Each local save reproduces its original F32 output word for word before the raw-format comparison. Of the 62 established originals, 58 have now rendered. Of the 14 archived ordinary saves, 13 have now rendered. The three recovered archived saves below are separate files from the freshly written saves. + +| Archived ordinary save | Exact pixels · maximum error | +|---|---:| +| 64 × 16 · F16 | 1,024/1,024 · 0 | +| 64 × 64 · U16 | 4,094/4,096 · 1 | +| 128 × 128 · F32 | 14,395/16,384 · 2.38418579e-07 | + +At 64 × 64, repeat the original desktop capture at each processor count, holding the settings fixed. The final column compares MaterialCraft at the positions where four original desktop captures and the ordinary save all have the same stored word. + +| Format | Fresh original · one | Fresh original · eight | Desktop repeat · one | Desktop repeat · eight | Same word in all five · local exact / compared · max | +|---|---:|---:|---:|---:|---:| +| U8 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| U16 | 4,095/4,096 · 1 | 4,093/4,096 · 1 | 4,092/4,096 · 1 | 4,092/4,096 · 1 | 4,090/4,090 · 0 | +| F16 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| F32 | 3,550/4,096 · 2.08616257e-07 | 3,580/4,096 · 1.49011612e-07 | 3,477/4,096 · 2.38418579e-07 | 3,587/4,096 · 1.78813934e-07 | 2,992/3,024 · 8.94069672e-08 | + +A separate capture allowed seven host processors. Its F32 comparison was 3,555/4,096 · 2.38418579e-07. The processor counts in the table were verified from the capture receipts. + +Read the first two FX-Map outputs directly on one and eight processors at each of the four sizes and seeds above. In a disposable copy, route the output to the unmodified middle FX-Map, expose the first as a second output and remove the final stage. Keep the original U8 precision of the upstream maps. Both processor counts match all 1,472/1,472 first-stage pixels and 5,888/5,888 middle-stage pixels across the four geometries. Maximum error is zero. The discrepancy first appears downstream of those two stored outputs. + +At 64 × 64, switch seed 411585 to 411586, 411587 and 411588 in turn, returning to 411585 after each switch. Make three returns on one processor and three on eight. Across the initial five F32 readbacks and these six returns, 2,801 positions keep the same reference value. MaterialCraft matches 2,791/2,801, maximum 5.96046448e−8. Adding the final FX-Map and output-bridge reads at both processor counts leaves 2,728 invariant positions in fifteen readbacks. MaterialCraft matches 2,725/2,728, maximum 5.96046448e−8, and matches an observed reference value at 4,085/4,096 positions. The three residuals within that invariant set differ by one F32 word step. + +| Pixel (x, y) | MaterialCraft F32 word | Reference word across fifteen readbacks | +|---|---|---| +| (9, 9) | `0x3efb6504` | `0x3efb6505` | +| (46, 33) | `0x3f1d2b80` | `0x3f1d2b7f` | +| (33, 41) | `0x3f0d59a0` | `0x3f0d59a1` | + +The 64 × 32 F32 setting still stops at the execution limit. To count the workload, replace the depth-six drawing node of the last FX-Map with a constant marker of a distinct shape and disconnect its children in a disposable probe. The four-way subtree it replaces draws at depths six through nine, giving 85 draws per marker. Counts for 64 × 16, 64 × 64 and 128 × 128 are 100,370, 101,738 and 110,592 markers. The blocked 64 × 32 setting has 203,374 markers, or 17,286,790 draws. The four 64 × 32 storage settings remain open. + +Two earlier untiled F32 controls at 16 × 32 and 32 × 16 reproduced their previous local hashes for both the original and the saved file. [Earlier untiled scores and seeds](#untiled-spots-clouds-directional-noise-and-dirt-at-two-rectangular-sizes) + +| Related untiled F32 control | Original · one | Original · eight | Ordinary save · one | +|---|---:|---:|---:| +| Directional Noise 1 v2 · 16 × 32 | 346/512 · 1.1920929e-07 | 361/512 · 1.1920929e-07 | 339/512 · 1.1920929e-07 | +| Directional Noise 2 v2 · 16 × 32 | 393/512 · 1.1920929e-07 | 410/512 · 5.96046448e-08 | 371/512 · 8.94069672e-08 | + +Both untiled F32 Directional Noise 3 v2 originals still reach the execution limit. The tiled 64 × 32 F32 Directional Noise 2 v2 original at seed 195000 also reaches the limit at the [earlier changed settings](#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series). The Spots root retains the reported U16 and F32 differences. + +### The incoming seed on the initial branch of an Iterate + +An Iterate passes its incoming random seed to its initial branch. Its seed offset and inheritance setting determine the random stream for its repeated branch. MaterialCraft previously passed the adjusted seed on both connections. The correction is in the shared pattern traversal. + +For the single-branch controls, use a 16 × 16 grayscale F32 buffer, a .125 background and an additive square at unit size with luminosity Rand(.5). Render at seeds 0, 42 and 329779. On the node under test use defaults, inherited seed with offset 17, and inheritance disabled with offsets 0 and 17. For the ordinary save, reopen the disabled, offset-17 case in both applications. Connect the square directly, through either output of an Iterate with count 1, through the first output of a Switch, or to the first subdivision of an empty Quadrant. In the direct case apply the seed settings to the square. + +| Node and connection | Earlier original · one processor | Corrected original · one | Earlier ordinary save · one | Corrected ordinary save · one | +|---|---:|---:|---:|---:| +| Drawing Quadrant | 3,072/3,072 · 0 | 3,072/3,072 · 0 | 768/768 · 0 | 768/768 · 0 | +| Initial branch of Iterate | 1,024/3,072 · 0.451604903 | 3,072/3,072 · 0 | 0/768 · 0.337485671 | 768/768 · 0 | +| Repeated branch of Iterate | 3,072/3,072 · 0 | 3,072/3,072 · 0 | 768/768 · 0 | 768/768 · 0 | +| Switch | 3,072/3,072 · 0 | 3,072/3,072 · 0 | 768/768 · 0 | 768/768 · 0 | +| Subdivision of Quadrant | 3,072/3,072 · 0 | 3,072/3,072 · 0 | 768/768 · 0 | 768/768 · 0 | + +Each entry gives exact pixels / total and maximum absolute error. With parent seed 42 and offset 17, the initial square reads 0.166194379, including the .125 background, for either inheritance setting. The repeated square reads 0.179525137 with inheritance enabled and 0.379592717 with inheritance disabled. + +In the two-branch control, place half-width squares at horizontal offsets −.25 and .25 on the initial and repeated connections. Give both squares the same Rand(.5) luminosity. First use one repeat, seed inheritance and a literal offset 17. Then use two repeats, disable inheritance and compute the offset by adding integers 8 and 9. For each construction compare 16 × 16 at seed 0, 32 × 16 at seed 42 and 16 × 32 at seed 329779 in all four storage formats. Reopen an ordinary save. + +A second control uses four outer iterations and then seven. An inner Iterate records the enclosing repetition number as a float and publishes a gain of (1 + number) × .25 in the four-iteration case and × .125 in the seven-iteration case. Disable seed inheritance on this inner Iterate. Connect a .625 × .375 additive square to its initial branch. In its luminosity expression set a two-component offset from two successive Rand(.25) draws. Then take .0625 + Rand(.125), multiplying by the gain when the published number exceeds 1.5. Read the assigned offset for the square. Connect four .375 × .25 child squares with .125 luminosity and the negative of the published offset. Use the same background, three dimensions, seeds and four formats. + +| Construction · format | Earlier original · one | Corrected original · one | Corrected original · eight | Ordinary save · one | +|---|---:|---:|---:|---:| +| Two-branch squares · U8 | 1,280/2,560 · 86 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | +| Two-branch squares · U16 | 1,280/2,560 · 22117 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | +| Two-branch squares · F16 | 1,280/2,560 · 0.337402344 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | +| Two-branch squares · F32 | 1,280/2,560 · 0.337485671 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | +| Nested squares with a published offset · U8 | 878/2,560 · 223 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | +| Nested squares with a published offset · U16 | 878/2,560 · 57343 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | +| Nested squares with a published offset · F16 | 871/2,560 · 1.61206055 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | +| Nested squares with a published offset · F32 | 871/2,560 · 1.61208928 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | + +Both corrected constructions match all 10,240 pixels on each of the three comparison routes. The ordinary saves reproduce the original local words. Integer errors are stored levels. + +Of the inventory graphs, the two Tile Random roots have a reachable Iterate with an initial connection and a nonzero seed property. Both set its offset to 2. Their initial connection enters another Iterate that disables seed inheritance and sets its own seed from a drawing variable. Repeat the [19 established whole settings and procedural inputs](#tile-weave-splatter-and-fiber-stage-comparisons) for each root on one and eight processors, then reopen an ordinary save. The initial-branch change leaves all 38 local originals and all 38 saves byte-identical to the prior evaluator. + +| Whole graph · comparison | Exact pixels / total | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:| +| Tile Random · One processor | 111,364/142,592 | 223 / 57311 / 1 / 1.00000006 | +| Tile Random · Eight processors | 111,364/142,592 | 223 / 57311 / 1 / 1.00000006 | +| Tile Random · Ordinary save · one | 111,364/142,592 | 223 / 57311 / 1 / 1.00000006 | +| Tile Random Color · One processor | 111,228/142,592 | 250 / 65535 / 1 / 2.00000003 | +| Tile Random Color · Eight processors | 111,228/142,592 | 250 / 65535 / 1 / 2.00000003 | +| Tile Random Color · Ordinary save · one | 111,228/142,592 | 250 / 65535 / 1 / 2.00000003 | + +Both roots retain the whole-output differences shown above. + +### Untiled Spots, Clouds, Directional Noise and Dirt at two rectangular sizes + +Release `0f01b25` includes the [per-axis background sampling change](#filtering-a-resized-pattern-background-on-each-axis). Open each Noise graph with tiling disabled. Use 16 × 32, seed 731257 and exposed defaults. At 32 × 16 use seed 731279, scale 1, disorder .4375 and non-square expansion enabled. Keep the other parameters at their defaults. Set output storage on the node connected to the graph output. Read the whole grayscale buffer, then save the package normally and reopen it in both applications. The [earlier Spots table](#untiled-spots-outputs-and-the-second-dirt-gradient-iteration) covers the 16 × 32 Spots 3 v2 setting. + +Each cell gives exact pixels / total pixels and maximum absolute error. Integer errors are storage levels. The original reference captures used one and eight processors. The saved comparison used one. + +| Graph · size | Route | U8 | U16 | F16 | F32 | +|---|---|---:|---:|---:|---:| +| BNW Spots 3 v2 · 32 × 16 | Original · one processor | 512/512 · 0 | 511/512 · 1 | 512/512 · 0 | 472/512 · 1.1920929e-07 | +| BNW Spots 3 v2 · 32 × 16 | Original · eight | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 464/512 · 1.1920929e-07 | +| BNW Spots 3 v2 · 32 × 16 | Ordinary save · one | 512/512 · 0 | 511/512 · 1 | 512/512 · 0 | 470/512 · 1.1920929e-07 | +| Clouds 1 v2 · 16 × 32 | Original · one processor | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 467/512 · 1.1920929e-07 | +| Clouds 1 v2 · 16 × 32 | Original · eight | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 459/512 · 8.94069672e-08 | +| Clouds 1 v2 · 16 × 32 | Ordinary save · one | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 467/512 · 1.1920929e-07 | +| Clouds 1 v2 · 32 × 16 | Original · one processor | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 475/512 · 8.94069672e-08 | +| Clouds 1 v2 · 32 × 16 | Original · eight | 512/512 · 0 | 511/512 · 1 | 512/512 · 0 | 474/512 · 1.1920929e-07 | +| Clouds 1 v2 · 32 × 16 | Ordinary save · one | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 468/512 · 1.1920929e-07 | +| Clouds 2 v2 · 16 × 32 | Original · one processor | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 507/512 · 5.96046448e-08 | +| Clouds 2 v2 · 16 × 32 | Original · eight | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 508/512 · 5.96046448e-08 | +| Clouds 2 v2 · 16 × 32 | Ordinary save · one | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 507/512 · 5.96046448e-08 | +| Clouds 2 v2 · 32 × 16 | Original · one processor | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 507/512 · 5.96046448e-08 | +| Clouds 2 v2 · 32 × 16 | Original · eight | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 507/512 · 5.96046448e-08 | +| Clouds 2 v2 · 32 × 16 | Ordinary save · one | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 507/512 · 5.96046448e-08 | +| Directional Noise 1 v2 · 16 × 32 | Original · one processor | 512/512 · 0 | 510/512 · 1 | 512/512 · 0 | 346/512 · 1.1920929e-07 | +| Directional Noise 1 v2 · 16 × 32 | Original · eight | 512/512 · 0 | 511/512 · 1 | 512/512 · 0 | 361/512 · 1.1920929e-07 | +| Directional Noise 1 v2 · 16 × 32 | Ordinary save · one | 512/512 · 0 | 510/512 · 1 | 512/512 · 0 | 339/512 · 1.1920929e-07 | +| Directional Noise 1 v2 · 32 × 16 | Original · one processor | 512/512 · 0 | 511/512 · 1 | 512/512 · 0 | 351/512 · 1.1920929e-07 | +| Directional Noise 1 v2 · 32 × 16 | Original · eight | 512/512 · 0 | 511/512 · 1 | 512/512 · 0 | 357/512 · 1.78813934e-07 | +| Directional Noise 1 v2 · 32 × 16 | Ordinary save · one | 512/512 · 0 | 511/512 · 1 | 512/512 · 0 | 346/512 · 1.1920929e-07 | +| Directional Noise 2 v2 · 16 × 32 | Original · one processor | 512/512 · 0 | 512/512 · 0 | 511/512 · 0.000122070312 | 393/512 · 1.1920929e-07 | +| Directional Noise 2 v2 · 16 × 32 | Original · eight | 512/512 · 0 | 512/512 · 0 | 511/512 · 0.000122070312 | 410/512 · 5.96046448e-08 | +| Directional Noise 2 v2 · 16 × 32 | Ordinary save · one | 512/512 · 0 | 512/512 · 0 | 511/512 · 0.000122070312 | 371/512 · 8.94069672e-08 | +| Directional Noise 2 v2 · 32 × 16 | Original · one processor | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 360/512 · 8.94069672e-08 | +| Directional Noise 2 v2 · 32 × 16 | Original · eight | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 372/512 · 5.96046448e-08 | +| Directional Noise 2 v2 · 32 × 16 | Ordinary save · one | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 374/512 · 8.94069672e-08 | +| Directional Noise 3 v2 · 16 × 32 | Original and saved | Visit limit | Visit limit | Visit limit | Visit limit | +| Directional Noise 3 v2 · 32 × 16 | Original and saved | Visit limit | Visit limit | Visit limit | Visit limit | +| Dirt 3 · 16 × 32 | Original · one processor | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 510/512 · 5.96046448e-08 | +| Dirt 3 · 16 × 32 | Original · eight | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 511/512 · 5.96046448e-08 | +| Dirt 3 · 16 × 32 | Ordinary save · one | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 510/512 · 5.96046448e-08 | +| Dirt 3 · 32 × 16 | Original · one processor | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 509/512 · 2.98023224e-08 | +| Dirt 3 · 32 × 16 | Original · eight | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| Dirt 3 · 32 × 16 | Ordinary save · one | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 509/512 · 2.98023224e-08 | +| Dirt 3 v2 · 16 × 32 | Original · one processor | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 509/512 · 2.98023224e-08 | +| Dirt 3 v2 · 16 × 32 | Original · eight | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 508/512 · 2.98023224e-08 | +| Dirt 3 v2 · 16 × 32 | Ordinary save · one | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 509/512 · 2.98023224e-08 | +| Dirt 3 v2 · 32 × 16 | Original · one processor | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 508/512 · 2.98023224e-08 | +| Dirt 3 v2 · 32 × 16 | Original · eight | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 509/512 · 2.98023224e-08 | +| Dirt 3 v2 · 32 × 16 | Ordinary save · one | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 507/512 · 2.98023224e-08 | + +52/60 original settings and their ordinary saves produced buffers. Every completed local save repeats its original pixel words. Whole-buffer agreement is 35/52 on one processor, 36/52 on eight and 35/52 after reopening. The baseline for the same completed U8 settings was 5,155/6,656 · 2 on one processor. It is now 6,656/6,656 · 0. The F16 baseline was 3,767/6,656 · 0.00439453125 and is now 6,655/6,656 · 0.000122070312. + +### A complete quadrant tree with one physical copy per draw + +A single nine-level tree keeps the same submission order when a larger tiled window contains each draw once. The earlier evaluator used the window coordinates to select this order. It now also checks how many physical copies the draws produced in the common render and tiling region. A retained or discarded drawing stamp contributes at least one copy to this count. + +In the [two square Noise Dirt 5 comparisons](#shared-branch-expressions-and-all-sixty-noise-dirt-5-renders), expose the FX-Map alongside Levels and set the FX-Map output to F32. At 32 × 32 use seed 113. At 64 × 64 use seed 42. Use scale 2, disorder .37 and the default expansion setting. Put an integer Minimum after the outer iteration count and keep its original calculation and connections. A cap of one emits one complete tree. Four emits two trees and eight reproduces the complete original local FX-Map buffer at both sizes. The render and tiling regions both run from −.5 to 1.5 on each axis. + +| Cap · size | Earlier on one processor | Corrected on one | Corrected on eight | Ordinary save on one | +|---|---:|---:|---:|---:| +| 1 · 32 × 32 | 1,009/1,024 · 1.1920929e-07 | 1,024/1,024 · 0 | 1,004/1,024 · 1.1920929e-07 | 1,024/1,024 · 0 | +| 1 · 64 × 64 | 4,031/4,096 · 1.1920929e-07 | 4,096/4,096 · 0 | 3,990/4,096 · 1.1920929e-07 | 4,096/4,096 · 0 | +| 4 · 32 × 32 | 996/1,024 · 1.1920929e-07 | 996/1,024 · 1.1920929e-07 | 982/1,024 · 5.96046448e-08 | 996/1,024 · 1.1920929e-07 | +| 4 · 64 × 64 | 3,976/4,096 · 1.1920929e-07 | 3,976/4,096 · 1.1920929e-07 | 3,937/4,096 · 1.1920929e-07 | 3,976/4,096 · 1.1920929e-07 | + +Each entry gives exact pixels / pixels compared and maximum absolute F32 error. The one-tree controls each have 344,064 draws and 344,064 physical copies before removing stamps that miss every sample. Their one-processor totals improve from 5,040/5,120 to 5,120/5,120. The ordinary saves also match all 5,120. Both two-tree local buffers retain their previous hashes. They contain 889 and 868 additional copies, respectively. Each reopened local FX-Map and Levels output matches its original. Both builds write byte-identical ordinary saves for these controls. + +For an independent comparison, use the [nine-level additive square construction](#single-branch-controls-in-complete-quadrant-trees) on white with only outer repetition 3 active. Use the same render and tiling window, with both tiling axes enabled except in the last row. At 256 × 256 use the first and second F32 gain settings, seeds 188119 and 188156. At 128 × 64 use the first gain setting with seed 292177 in F32 and U16. Reopen an ordinary save in both applications. At (72,64) and (64,80) in the centered 256 × 256 first setting, the earlier evaluator returned zero. The corrected release and the one-processor reference return 2⁻²⁵. At (64,64) and (80,64) both return zero. + +Each cell gives exact pixels / total, then the maximum F32 and U16 errors for its four settings. + +| X window · Y window | Earlier on one processor | Corrected on one | Earlier on eight | Corrected on eight | Ordinary save on one | +|---|---:|---:|---:|---:|---:| +| −.5 to 1.5 · −.5 to 1.5 | 146,368/147,456 · 2.98023224e-08 / 0 | 147,456/147,456 · 0 / 0 | 147,336/147,456 · 2.98023224e-08 / 0 | 146,248/147,456 · 2.98023224e-08 / 0 | 147,456/147,456 · 0 / 0 | +| −.25 to 1.75 · −.25 to 1.75 | 146,368/147,456 · 2.98023224e-08 / 0 | 147,456/147,456 · 0 / 0 | 147,392/147,456 · 2.98023224e-08 / 0 | 146,432/147,456 · 2.98023224e-08 / 0 | 147,456/147,456 · 0 / 0 | +| −.5 to 1.5 · −1.5 to 2.5 | 147,456/147,456 · 0 / 0 | 147,456/147,456 · 0 / 0 | 147,456/147,456 · 0 / 0 | 147,456/147,456 · 0 / 0 | 147,456/147,456 · 0 / 0 | +| −.25 to .75 · −.5 to 1.5 | 145,280/147,456 · 2.98023224e-08 / 0 | 147,456/147,456 · 0 / 0 | 147,456/147,456 · 0 / 0 | 145,280/147,456 · 2.98023224e-08 / 0 | 147,456/147,456 · 0 / 0 | +| −.5 to 1.5 · −.5 to 1.5, tiling off | 147,456/147,456 · 0 / 0 | 147,456/147,456 · 0 / 0 | 146,624/147,456 · 2.98023224e-08 / 0 | 146,624/147,456 · 2.98023224e-08 / 0 | 147,456/147,456 · 0 / 0 | + +All 20 corrected one-processor originals and all 20 ordinary saves match, 737,280/737,280 on each route, up from 732,928 on the original. Against the eight-processor captures the earlier total is 736,264/737,280 and the corrected total is 732,040/737,280. The centered, shifted and narrower-X rows lose exact pixels on this comparison. + +Repeat both large F32 settings in those three windows twice more on eight processors and once more on one, reversing the case order. Across the six settings the three eight-processor reads agree at 390,788 pixels. The earlier release matches 390,788 of these and the corrected release 388,044. In the narrower-X window all three eight-processor buffers reproduce the earlier release. They differ from the one-processor output at 1,152 pixels with seed 188119 and 1,024 with seed 188156. Across the original, reopened and repeated reads on both processor counts, 388,044 pixels keep the same word and the corrected release matches every one. + +An independent signed comparison assigns two original square draws to each readout over a white background, with gains −1 and 2⁻²⁵. Use a common window from −.5 to 1.5 on both axes and four children at each level. For one tree, all 16,383 adjacent depth-seven parent pairs follow the previously measured order with either assignment of the gains, giving 32,766/32,766 signed comparisons, maximum error zero. In the two-tree control all 65,534 signed comparisons reproduce the measured two-tree order. Four active trees still change the result. + +For a six-pixel four-tree control, number the depth-seven parents from 0 through 65,535 in tree order, visiting child ports 0 through 3. Use seed 188119, 256 × 256 F32, square size (.875,.875), zero roughness and unit opacity. Give each pair one pixel in the first row, starting at (0,0). The pairs are (38876,46939), (37383,45424), (53619,57876), (58083,61876), (61523,49776) and (57968,53899). Send other depth-seven draws to (252,248) with gain −1. Center all depth-eight and depth-nine draws at (.875,.875) in pattern space with gain .25. On one processor, unchanged reference recooks agree with the first capture at 2/6, 3/6 and 6/6 readouts, maximum 2⁻²⁵, 2⁻²⁵ and 0. Exchanging the gains gives 6/6, 5/6 and 6/6. A one-pair control using only (38876,46939) agrees on all four reads in each direction. A single fixed four-tree order cannot reproduce all the six-pixel captures. + +Repeat the [32 original and 32 reopened Dirt 3, Dirt 5, Dirt Gradient and Vertical Noise controls](#shared-branch-expressions-and-all-sixty-noise-dirt-5-renders) in all four formats. All 64 local buffers retain their prior hashes and all earlier raw scores apply. The complete Noise Dirt 5 root remains in progress. + +### Shared branch expressions and all sixty Noise Dirt 5 renders + +The normal evaluator renders all 60 tiled Noise Dirt 5 originals and all 12 archived ordinary saves on the same release. Earlier runs finished 58 originals and 11 saves. The two remaining originals use 128 × 32, seed 433608, scale 3, disorder .046875 and non-square expansion enabled. Leave the other inputs at their defaults and set the final output to the requested storage. [Original series and parameter combinations](#sixty-whole-settings-for-three-directional-and-dirt-noise-packages) · [Ten earlier recovered settings](#ten-recovered-whole-noise-dirt-5-settings) + +| Storage at 128 × 32 | Original on one processor | Original on eight | Fresh ordinary save on one | Earlier ordinary save on one | +|---|---:|---:|---:|---:| +| U16 | 4,095/4,096 · 3 | 4,095/4,096 · 3 | 4,095/4,096 · 3 | 4,094/4,096 · 3 | +| F32 | 4,094/4,096 · 5.08353114e-05 | 4,095/4,096 · 5.07831573e-05 | 4,095/4,096 · 5.0842762e-05 | 4,096/4,096 · 0 | + +Each entry gives exact pixels / pixels compared and maximum absolute error. The separate archived F32 save matches 4,093/4,096 · 5.0842762e-05. The earlier and corrected builds write byte-identical ordinary SBS files. The corrected original and both saved buffers reproduce the same local words in each measured format. + +The original one- and eight-processor U16 captures agree with one another on 4,094 pixels and MaterialCraft matches all 4,094. Across the 4 U16 reads, 4,093 of 4,093 invariant pixels match, and 0 local words fall outside all captured values. The 5 F32 reads give 4,093/4,093 invariant pixels and 0 outside every capture. The maximum distance to the nearest captured F32 value is 0. + +For the complete series, compare stored words in the original one- and eight-processor captures and the archived one-processor saves. Each cell gives exact images / images rendered followed by exact pixels / pixels compared and the maximum error in that storage format. + +| Storage | Original · one processor | Original · eight processors | Archived ordinary saves · one processor | +|---|---:|---:|---:| +| U8 | 9/9 · 99,840/99,840 · 0 | 9/9 · 99,840/99,840 · 0 | 4/4 · 26,624/26,624 · 0 | +| U16 | 7/20 · 338,863/338,944 · 4 | 6/20 · 338,870/338,944 · 4 | 2/4 · 51,709/51,712 · 4 | +| F16 | 6/10 · 101,876/101,888 · 0.000244140625 | 7/10 · 101,879/101,888 · 0.000122070312 | — | +| F32 | 9/21 · 244,938/244,992 · 5.08576632e-05 | 8/21 · 244,936/244,992 · 5.08725643e-05 | 2/4 · 71,148/71,168 · 5.0842762e-05 | + +Measured across all formats, 31/60 originals match in full on one processor, 30/60 on eight, and 8/12 archived saves on one. Each of the 12 local archived saves matches its original raw buffer. The inventory remains open for the pixel differences above. + +Three settings had pixels that differed from both original reference captures. Repeat each on one and eight processors, reverse their cook order, and reopen an ordinary save. At 64 × 32, seed 281734, scale 1, zero disorder and expansion on, three of seven F32 captures match all 2,048 pixels. The other four give 2,047/2,048 · 5.08278608e-05. All 2,047 pixels that stay constant across the seven reads match MaterialCraft. + +At the two square settings below, all seven reference cooks agree at the listed coordinate. Add a second output to the FX-Map feeding Levels and keep the original output connected. Both processor counts and the ordinary save reproduce the listed values on this two-output graph. At both coordinates the first difference is one U16 level at the FX-Map output. + +| Size · seed · final storage | Pixel | FX-Map U16, local / reference | Final output, local / reference | Final exact pixels · maximum error on one processor | +|---|---:|---:|---:|---:| +| 32 × 32 · 113 · F32 | (2,11) | 36,770 / 36,769 | .2100976706 / .2100468427 | 1,023/1,024 · 5.08278608e-05 | +| 64 × 64 · 42 · U16 | (0,41) | 36,197 / 36,198 | 11,860 / 11,863 | 4,094/4,096 · 3 | + +Use scale 2 and disorder .37 for both square settings. For the FX-Map output alone the single-processor counts are 1,023/1,024 and 4,094/4,096, maximum one U16 level in each. The saved two-output graph reproduces both local buffers exactly. + +Set the FX-Map itself to F32 to read the sum before U16 conversion. At 32 × 32 the raw sums match 956/1,024 pixels on one processor and 954/1,024 on eight. At 64 × 64 they match 3,833/4,096 and 3,814/4,096. All four maxima are 1.19209290e-07. Record the initial background and every nonzero additive contribution at each differing pixel. Replaying the original sequence reproduces the entire local buffer at both sizes. Enumerating the orders of those same contributions reaches every differing reference word, including all 68 and 70 differences at 32 × 32 and all 263 and 282 at 64 × 64. The two tabulated coordinates receive six and three contributions. These per-pixel results leave the shared submission order unresolved. + +Three drawing quadrants use the same branch offset and tint at successive depths. For grayscale analytic shapes whose only computed drawing properties are a branch offset and an optional tint, the evaluator can reuse their values by seed when both expressions are independent of position, depth, iteration and writable variables. The stamp uses the current depth and extent on every visit. An invisible parent of terminal draws can consume one previous skipped evaluation and one unit from the bounded cache allowance. Its children still run in their original order. + +The 128 × 32 U16 control visits 12,583,070 nodes. In a diagnostic MaterialCraft build with room to finish, using separate node and depth keys required 9,038,245 full property evaluations. Starting reuse before the first filled batch and sharing equivalent branch expressions gave 8,122,984 hits and 4,460,086 full evaluations. Both complete buffers have the same raw hash. The latter fits within the existing 5,242,880 full-evaluation limit. A version that kept separate keys for each node and depth still reached that limit. + +A normal save gives the three expressions fresh function-node IDs. In a control made from that save, point the three quadrants to the same parameter data record. Keep every expression and connection. The intermediate renderer that keyed on the original IDs now produces the original U16 hash and matches 4,095/4,096 · 3 on one processor. The corrected renderer compares function wiring with relative node IDs for its cache key. Its regression also distinguishes a subtraction whose operands are exchanged. + +At 16 × 32 use seed 739013 and the published defaults. At 32 × 16 use seed 739049 and the changed values below. Cook in U8, U16, F16 and F32. All 32 original and 32 saved local buffers match the preceding release. Each cell gives raw exact pixels / total, followed by maximum errors in U8, U16, F16 and F32 order. + +| Related graph · changed values | Original · one processor | Original · eight processors | Ordinary save · one processor | +|---|---:|---:|---:| +| Dirt 3 · Disorder 0.4 | 4,096/4,096 · 0 / 0 / 0 / 0 | 4,096/4,096 · 0 / 0 / 0 / 0 | 4,096/4,096 · 0 / 0 / 0 / 0 | +| Dirt 5 · defaults | 4,096/4,096 · 0 / 0 / 0 / 0 | 4,095/4,096 · 0 / 3 / 0 / 0 | 4,096/4,096 · 0 / 0 / 0 / 0 | +| Dirt Gradient · defaults | 4,096/4,096 · 0 / 0 / 0 / 0 | 4,095/4,096 · 0 / 0 / 0 / 1.85370445e-05 | 4,096/4,096 · 0 / 0 / 0 / 0 | +| Vertical Noise · Disorder 0.3 | 4,088/4,096 · 0 / 1 / 0 / 1.65998936e-05 | 4,085/4,096 · 0 / 1 / 0 / 1.65998936e-05 | 4,088/4,096 · 0 / 1 / 0 / 1.65998936e-05 | + +Four alternating cold release cooks of Noise Dirt 5 at 32 × 16, seed 42, scale 2, disorder 0.21875 and expansion on produced identical U16 buffers. With one local rendering thread, median cook time was 46.19 seconds before and 30.39 after the change. Median peak working set was 185.0 and 257.0 MiB. Other comparisons were active. + +### Tiled outputs of ten noise roots and the full Wood Fibers 2 series + +Release `0f01b25` renders the previously blocked 256 × 256 default in Wood Fibers 2. Open the ordinary tiled package, leave all parameters at their defaults and use 256 × 256, seed 0. Read the final U16 grayscale output. The archived setting matches 65,381/65,536 · 2. Across all 18 settings, the recorded comparisons now cover 121,030/126,208 exact pixels. [Previous sizes, formats and changed parameters](#discarding-pattern-stamps-that-miss-every-output-sample) + +A fresh one-processor capture matches 65,333/65,536 · 2, eight processors match 65,315/65,536 · 2, and the ordinary save reopened on one matches 65,340/65,536 · 2. Each value after the pixel counts is the maximum absolute error in U16 levels. The saved and original local buffers have the same raw hash. + +For the ten Noise packages below, keep tiling enabled. At 16 × 32 use the first seed, the published defaults, and U16 and F32 storage. Use all four formats at the second size and seed. Set the storage on the node supplying the final output and reopen an ordinary save in both applications. Each cell gives exact complete images / rendered images, then exact pixels / total and maximum error in U8, U16, F16 and F32 order. A dash indicates that the format did not produce an image. Integer maxima are storage levels. + +| Noise graph · first seed · second size and seed | Original · one processor | Original · eight processors | Ordinary save · one processor | +|---|---:|---:|---:| +| BNW Spots 1 v2 · 194426 · 64 × 32, 194473 | 4/6 · 9,189/9,216 · 0 / 0 / 0 / 1.1920929e-07 | 4/6 · 9,174/9,216 · 0 / 0 / 0 / 1.1920929e-07 | 4/6 · 9,192/9,216 · 0 / 0 / 0 / 5.96046448e-08 | +| BNW Spots 3 v2 · 194488 · 64 × 32, 194535 | 0/2 · 978/1,024 · — / 1 / — / 5.96046448e-08 | 1/2 · 986/1,024 · — / 0 / — / 1.1920929e-07 | 1/2 · 981/1,024 · — / 0 / — / 8.94069672e-08 | +| Clouds 1 v2 · 0 · 16 × 16, 0 | 5/6 · 1,986/2,048 · 0 / 0 / 0 / 1.49011612e-07 | 4/6 · 1,945/2,048 · 0 / 0 / 0 / 1.78813934e-07 | 5/6 · 1,986/2,048 · 0 / 0 / 0 / 1.49011612e-07 | +| Clouds 2 v2 · 0 · 16 × 16, 0 | 5/6 · 2,044/2,048 · 0 / 0 / 0 / 5.96046448e-08 | 4/6 · 2,043/2,048 · 0 / 0 / 0 / 5.96046448e-08 | 5/6 · 2,044/2,048 · 0 / 0 / 0 / 5.96046448e-08 | +| Directional Noise 1 v2 · 194891 · 64 × 32, 194938 | 3/6 · 8,198/9,216 · 0 / 1 / 0 / 2.38418579e-07 | 3/6 · 8,253/9,216 · 0 / 1 / 0 / 1.78813934e-07 | 3/6 · 8,132/9,216 · 0 / 1 / 0 / 2.38418579e-07 | +| Directional Noise 2 v2 · 194953 · 64 × 32, 195000 | 0/2 · 850/1,024 · — / 1 / — / 8.94069672e-08 | 1/2 · 890/1,024 · — / 0 / — / 5.96046448e-08 | 0/2 · 830/1,024 · — / 1 / — / 5.96046448e-08 | +| Directional Noise 3 v2 · 195015 · 64 × 32, 195062 | 2/2 · 1,024/1,024 · — / 0 / — / 0 | 2/2 · 1,024/1,024 · — / 0 / — / 0 | 2/2 · 1,024/1,024 · — / 0 / — / 0 | +| Dirt 3 · 299453 · 64 × 32, 299532 | 4/6 · 9,197/9,216 · 0 / 0 / 0 / 2.98023224e-08 | 4/6 · 9,193/9,216 · 0 / 0 / 0 / 5.96046448e-08 | 4/6 · 9,197/9,216 · 0 / 0 / 0 / 2.98023224e-08 | +| Dirt 3 v2 · 299496 · 64 × 32, 299575 | 4/6 · 9,200/9,216 · 0 / 0 / 0 / 5.96046448e-08 | 4/6 · 9,192/9,216 · 0 / 0 / 0 / 5.96046448e-08 | 4/6 · 9,200/9,216 · 0 / 0 / 0 / 5.96046448e-08 | +| Dirt Gradient v2 · 281778 · 64 × 32, 281845 | 3/6 · 8,398/9,216 · 0 / 1 / 0 / 2.38418579e-07 | 3/6 · 8,518/9,216 · 0 / 1 / 0 / 2.38418579e-07 | 3/6 · 8,431/9,216 · 0 / 1 / 0 / 2.38418579e-07 | + +Use the published defaults at both Clouds sizes. For the second Spots and Directional sizes, set scale 3, disorder, disorder speed and disorder anisotropy .34375, anisotropy angle .09375, tile offset (0,.10546875) and non-square expansion on. Set Spots 1 roughness to .34375. For the Directional graphs use angle .09375 and random angle .34375. For Dirt 3 use scale 1, zero disorder and expansion on. For Dirt 3 v2 also set disorder anisotropy and angle to zero, tile offset (0,0) and disorder speed 1. Dirt Gradient v2 uses zero disorder, anisotropy and anisotropy angle, speed 1 and expansion on. + +The 48 completed originals and their 48 ordinary saves cover 53,248 pixels per comparison route. Every saved local buffer reproduces its original. The 64 × 32 settings of BNW Spots 3 v2, Directional Noise 2 v2 and Directional Noise 3 v2 still reach the execution limit in all four formats, including on reopening. The 16 × 32 Directional Noise 3 v2 default matches both original captures and the save in U16 and F32. + +### Recovered Dirt 4 and Moisture renders at seed 113 + +Repeat the earlier 32 × 32 F32 comparison at seed 113. The earlier evaluator reached its execution guard on Noise Dirt 4, Noise Moisture Noise 1 v2 and Noise Moisture Noise 2. The current release produces all three outputs. Against the archived captures, Dirt 4 matches 1,013/1,024 · 7.62939453e-05, Moisture 1 v2 matches 684/1,024 · 2.98023224e-07 and Moisture 2 matches 809/1,024 · 1.49011612e-07. Each entry gives exact pixels / pixels compared and maximum absolute error. + +For Dirt 4 use scale 2 and disorder .37. For both Moisture graphs also set disorder speed .6, anisotropy .3, anisotropy angle .125, pattern size (.8,1.2), tile offset (.17,.29), pattern angle .125, random angle .2 and global opacity .8. For the default comparison use 16 × 32 and seed 732011 with all exposed values at their defaults. Keep normal tiling. Assign U8, U16, F16 or F32 to the node supplying the output. Save outside the library and open the saved package in both applications. The table compares fresh reference captures. Each cell gives exact pixels / total and maximum error in its format. + +| Graph · size | Reference capture | U8 | U16 | F16 | F32 | +|---|---|---:|---:|---:|---:| +| Noise Dirt 4 · 16 × 32 | Original · one processor | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| Noise Dirt 4 · 16 × 32 | Original · eight processors | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| Noise Dirt 4 · 16 × 32 | Ordinary save · one processor | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| Noise Dirt 4 · 32 × 32 | Original · one processor | 1,023/1,024 · 1 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,013/1,024 · 7.62939453e-05 | +| Noise Dirt 4 · 32 × 32 | Original · eight processors | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| Noise Dirt 4 · 32 × 32 | Ordinary save · one processor | 1,023/1,024 · 1 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| Noise Moisture Noise 1 v2 · 16 × 32 | Original · one processor | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 313/512 · 1.78813934e-07 | +| Noise Moisture Noise 1 v2 · 16 × 32 | Original · eight processors | 512/512 · 0 | 511/512 · 1 | 512/512 · 0 | 324/512 · 2.08616257e-07 | +| Noise Moisture Noise 1 v2 · 16 × 32 | Ordinary save · one processor | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 323/512 · 1.78813934e-07 | +| Noise Moisture Noise 1 v2 · 32 × 32 | Original · one processor | 1,024/1,024 · 0 | 1,023/1,024 · 1 | 1,024/1,024 · 0 | 661/1,024 · 2.98023224e-07 | +| Noise Moisture Noise 1 v2 · 32 × 32 | Original · eight processors | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 662/1,024 · 2.38418579e-07 | +| Noise Moisture Noise 1 v2 · 32 × 32 | Ordinary save · one processor | 1,024/1,024 · 0 | 1,022/1,024 · 1 | 1,024/1,024 · 0 | 656/1,024 · 2.38418579e-07 | +| Noise Moisture Noise 2 · 16 × 32 | Original · one processor | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 253/512 · 1.78813934e-07 | +| Noise Moisture Noise 2 · 16 × 32 | Original · eight processors | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 254/512 · 2.38418579e-07 | +| Noise Moisture Noise 2 · 16 × 32 | Ordinary save · one processor | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 253/512 · 1.78813934e-07 | +| Noise Moisture Noise 2 · 32 × 32 | Original · one processor | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 806/1,024 · 2.08616257e-07 | +| Noise Moisture Noise 2 · 32 × 32 | Original · eight processors | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 817/1,024 · 1.78813934e-07 | +| Noise Moisture Noise 2 · 32 × 32 | Ordinary save · one processor | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 792/1,024 · 2.08616257e-07 | + +All 24 local buffers reproduce their original words after the normal save. Each default and seed-113 setting rendered in all four requested storage formats. The roots remain open for the differences in this table and the earlier size and parameter comparisons. [Dirt settings](#dirt-noise-sources-and-downstream-stages) · [Moisture settings](#liquid-fiber-and-related-noise-sources) + +### Untiled Spots outputs and the second Dirt Gradient iteration + +Open each Noise BNW Spots graph shown below. Turn off graph tiling. At 16 × 32 and seed 731257 keep the exposed defaults. For Spots 1 also use 32 × 16 and seed 731279, with scale 1, disorder .4375 and non-square expansion enabled. Set the format on the last FX-Map. Compare the complete grayscale output, then save the package normally outside the library and reopen it directly in both applications. Integer errors are storage levels. The earlier build was measured in U8 and F16. + +| Graph · size · format | Earlier on one processor | Corrected on one | Corrected on eight | Ordinary save on one | +|---|---:|---:|---:|---:| +| BNW Spots 1 v2 · 16 × 32 · U8 | 404/512 · 1 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| BNW Spots 1 v2 · 16 × 32 · U16 | — | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| BNW Spots 1 v2 · 16 × 32 · F16 | 353/512 · 0.00048828125 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| BNW Spots 1 v2 · 16 × 32 · F32 | — | 472/512 · 1.1920929e-07 | 475/512 · 5.96046448e-08 | 474/512 · 5.96046448e-08 | +| BNW Spots 1 v2 · 32 × 16 · U8 | 396/512 · 1 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| BNW Spots 1 v2 · 32 × 16 · U16 | — | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| BNW Spots 1 v2 · 32 × 16 · F16 | 338/512 · 0.00048828125 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| BNW Spots 1 v2 · 32 × 16 · F32 | — | 467/512 · 1.1920929e-07 | 476/512 · 1.1920929e-07 | 473/512 · 1.1920929e-07 | +| BNW Spots 3 v2 · 16 × 32 · U8 | 329/512 · 2 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| BNW Spots 3 v2 · 16 × 32 · U16 | — | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| BNW Spots 3 v2 · 16 × 32 · F16 | 96/512 · 0.00366210938 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| BNW Spots 3 v2 · 16 × 32 · F32 | — | 478/512 · 1.1920929e-07 | 476/512 · 5.96046448e-08 | 477/512 · 1.1920929e-07 | + +Both Spots 1 geometries and the Spots 3 default now match in U8, U16 and F16 on one processor and on ordinary saves. All 12 reopened local buffers repeat their original words. The F32 outputs still differ. + +For the two untiled Noise Dirt Gradient v2 graphs, retain the background connection and limit only the final FX-Map's iterators. Append an integer minimum after the existing count expression so it still initializes the drawing variables. Keep the smaller and larger geometries at seeds 649211 and 649229. Each entry compares the complete F32 output with the original on one processor. [Full graph settings](#filtering-a-resized-pattern-background-on-each-axis) + +| Maximum outer count | Maximum inner count | 16 × 32 · maximum | 32 × 64 · maximum | +|---:|---|---:|---:| +| 1 | 1 | 512/512 · 0 | 2,048/2,048 · 0 | +| 1 | Graph value | 512/512 · 0 | 2,048/2,048 · 0 | +| 2 | 1 | 503/512 · 5.96046448e-08 | 1,782/2,048 · 1.78813934e-07 | +| 2 | Graph value | 512/512 · 0 | 2,047/2,048 · 5.96046448e-08 | +| 4 | Graph value | 410/512 · 1.78813934e-07 | 1,588/2,048 · 2.38418579e-07 | + +One outer iteration changes 451 and 1,784 pixels from the background-only control and still matches every reference word. With two outer iterations, the two inner-count choices give identical local buffers at both sizes. Repeat each on one processor with the sizes reversed, on eight processors, and after an ordinary save. Across the resulting four reference reads for each graph, MaterialCraft matches every invariant word. With the inner count capped at one there are 398 and 1,503 invariant locations at the two sizes. With the graph's own inner count there are 410 and 1,583. Only the smaller capped case has a local value outside these four reads, at one pixel by 5.96046448e−08. Four outer iterations still differ on both original captures. + +In four alternating cold release runs of the full untiled 16 × 32 Gradient F16 case with one local render thread, median cook time was 70.43 seconds before the background correction and 60.00 seconds after it. Median peak working set was 182.8 and 197.8 MiB. Other comparisons were running during these timings. + +### Filtering a resized pattern background on each axis + +An FX-Map can draw over a clamped, filtered background sample before that sample is rounded to the working texture format. This occurs for a single resize step when the source and receiver sizes are both fixed or both parameter-controlled. Check the connected source's tiling on each axis that grows. If any growing axis repeats, the background is first filtered and stored using the receiver's tiling. A reduction can take the direct path even if its axis repeats. A longer resize or a change between fixed and parameter-controlled sizing keeps the intermediate storage. + +Open Noise Dirt Gradient v2, turn off graph tiling and enable non-square expansion. Use 16 × 32, seed 649211 and disorder .3125, then 32 × 64, seed 649229 and disorder .78125. Keep the other exposed values at their defaults. Set the final FX-Map's stored format as shown. Save normally outside the library, reopen in both applications, and compare the raw grayscale outputs. Each cell gives exact pixels / pixels compared and maximum absolute error. Integer errors are in storage levels. + +| Size · storage | Earlier on one processor | Corrected on one | Corrected on eight | Ordinary save on one | +|---|---:|---:|---:|---:| +| 16 × 32 · U8 | 425/512 · 1 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| 16 × 32 · U16 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| 16 × 32 · F16 | 366/512 · 0.00048828125 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| 16 × 32 · F32 | 400/512 · 1.78813934e-07 | 400/512 · 1.78813934e-07 | 423/512 · 1.1920929e-07 | 399/512 · 1.78813934e-07 | +| 32 × 64 · U8 | 1,613/2,048 · 1 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| 32 × 64 · U16 | 2,047/2,048 · 1 | 2,047/2,048 · 1 | 2,048/2,048 · 0 | 2,047/2,048 · 1 | +| 32 × 64 · F16 | 1,506/2,048 · 0.00048828125 | 2,048/2,048 · 0 | 2,047/2,048 · 0.00048828125 | 2,048/2,048 · 0 | +| 32 × 64 · F32 | 1,560/2,048 · 2.38418579e-07 | 1,560/2,048 · 2.38418579e-07 | 1,680/2,048 · 2.38418579e-07 | 1,556/2,048 · 2.98023224e-07 | + +The U8 and F16 originals each match 2,560/2,560 pixels on one processor, up from 2,038 and 1,872. Both formats also match all 2,560 pixels after saving. The previous run matched one of eight complete originals on one processor. The corrected scores are 5/8 · 9,639/10,240 on one processor, 5/8 · 9,782/10,240 on eight, and 5/8 · 9,634/10,240 for ordinary saves. Every reopened local buffer reproduces its original. On the 32 × 64 original, one U16 pixel differs by one level on one processor and one F16 pixel differs by 0.00048828125 on eight. Both F32 sizes still differ. + +Repeat the F32 read twice more on one processor and twice more on eight, reversing the geometry order on eight. Across seven captures per geometry, including the ordinary save, the reference returns the same word at 332 of 512 locations in the smaller rectangle and 1,316 of 2,048 in the larger. MaterialCraft matches 331 and 1,295 of those invariant words. At 21 and 101 locations its word differs from every captured value. The largest distance to the nearest observed value is 5.96046448e−08 and 1.19209290e−07, respectively. + +For a small independent probe, fill a grayscale U8 image with (47x + 83y + 11xy + seed) modulo 256. Connect it as the background of a gray FX-Map. Use one additive square, size (1,1), zero offset and rotation, unit opacity multiplier and a literal gray swatch .100677490234375 with alpha one. Use destinations 16 × 32 and 32 × 16 with seeds 849807 and 849829. Set the source and receiving sizes relative to their parent. A parameter-controlled comparison reads a .375 graph float before returning the same integer size offset. + +- At 16 × 32 with an 8 × 16 background, turn wrapping on for the receiver. An untiled source gives U8 byte 128 at (2,2) and F16 .53173828125 at (4,2). A two-axis repeating source gives 129 and .53125. The upper-left byte is 169 with the untiled source and 171 when both repeat. Direct input bridges, Levels and pattern outputs follow the connected texture's tiling. +- With a 16 × 16 background and wrapping off for the receiver, repeat X alone and then Y alone. The two U8 bytes at (2,2) are 149 and 150. Only Y grows. Repeat for the transposed resize, a reduction on either or both axes, simultaneous enlargement and reduction, and sources four times larger or smaller. For each source/receiver mask pair, compare both the draw and its source read. +- Repeat the grayscale field using seeds 723101 and 723119 and swatch .1005859375. For color, add 29 times the channel index before taking the byte remainder. Also test converted U16, F16 and F32 sources, a non-neutral Levels filter with output high .84375, blur intensity 2, and move either FX-Map into a graph instance. Compare the source and the drawn output independently before and after an ordinary save. + +| Independent comparisons in U8, U16, F16 and F32 | Settings | Drawn pixels · maximum | Connected source pixels · maximum | +|---|---:|---:|---:| +| Size expressions, procedural sources, filters and graph instances | 368 | 188,416/188,416 · 0 | 178,176/178,176 · 0 | +| Source and receiver tiling, formats and resize directions | 352 | 180,224/180,224 · 0 | 168,704/168,704 · 0 | +| Additional one-axis and mixed-axis geometries | 88 | 45,056/45,056 · 0 | 57,344/57,344 · 0 | + +The ordinary saves reproduce each entry in this table in both applications. At 16 × 32, seed 194488 and default parameters in tiled Noise BNW Spots 3 v2, the first FX-Map produces 32/32 exact bytes and the middle FX-Map 128/128. In a stage-only copy, turn off tiling on both nodes. Its U8 output improved from 102 to 128/128, and F16 from 80 to 128/128. The complete tiled U16 graph retains 511/512 on one processor, maximum one level, and 512/512 on eight. + +The previously verified Bevel Smooth debug position graph and its normal saves each match 354,560/354,560 · 0 across all 38 [RGBA settings](#texture-sampling-in-pattern-functions). At 64 × 64 and seed 42, seven previously verified roots also retain all 114,688 pixels across U8, U16, F16 and F32 on originals and ordinary saves. They are Make It Tile Patch and its grayscale version, Paths Trace, the grayscale graph in `pattern_tile_generator.sbs`, the `debug_hit_uv` output in `rt_irradiance.sbs`, and the standalone Tile Generator and Tile Generator Color graphs. Use the [changed-parameter precision settings](sbs-root-nodes.md#complete-inventory) for each. The new normal-cook regression covers a shared cache, input bridges, Levels, connected patterns and changes to just one tiling axis. All 575 node and evaluator release tests passed, along with formatting, strict workspace Clippy, layers and WebAssembly. + +### Ten recovered whole Noise Dirt 5 settings + +The shared pattern evaluator now produces images for 58 of the [60 original Noise Dirt 5 settings](#sixty-whole-settings-for-three-directional-and-dirt-noise-packages). The earlier comparison produced 48. Recook the twelve former execution errors on the normal release. Compare the stored grayscale words or floating-point values against the original one- and eight-processor reference captures. For each recovered setting also save the package normally, reopen it in both applications and compare against a fresh one-processor reference. Every local saved buffer reproduces its original raw hash. + +Open Noise Dirt 5, keep graph tiling enabled and apply the settings below. Set the requested storage on the node supplying the output. Each measurement gives exact pixels / pixels compared and maximum absolute error. Integer maxima are in storage levels. + +| Size · seed · scale · disorder · non-square expansion | Storage | Original on one processor | Original on eight | Ordinary save on one | +|---|---|---:|---:|---:| +| 32 × 16 · 105549 · 2 · 0.8125 · on | F32 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| 16 × 32 · 105550 · 2 · 0.8125 · on | U16 | 512/512 · 0 | 511/512 · 4 | 512/512 · 0 | +| 32 × 16 · 42 · 2 · 0.21875 · on | U16 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| 32 × 16 · 42 · 2 · 0.21875 · on | F32 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| 32 × 64 · 281801 · 2 · 0.8125 · on | U8 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| 32 × 64 · 281801 · 2 · 0.8125 · on | U16 | 2,047/2,048 · 4 | 2,047/2,048 · 4 | 2,047/2,048 · 4 | +| 32 × 64 · 281801 · 2 · 0.8125 · on | F16 | 2,047/2,048 · 0.000122070312 | 2,048/2,048 · 0 | 2,047/2,048 · 0.000122070312 | +| 32 × 64 · 281801 · 2 · 0.8125 · on | F32 | 2,047/2,048 · 5.08278608e-05 | 2,047/2,048 · 5.08129597e-05 | 2,047/2,048 · 5.08278608e-05 | +| 256 × 128 · 433719 · 3 · 0.328125 · off | U16 | 32,761/32,768 · 3 | 32,763/32,768 · 3 | 32,759/32,768 · 3 | +| 256 × 128 · 433719 · 3 · 0.328125 · off | F32 | 32,758/32,768 · 5.08576632e-05 | 32,758/32,768 · 5.08725643e-05 | 32,757/32,768 · 5.08725643e-05 | + +Across these ten settings the one- and eight-processor reads match 75,756 and 75,758 of 75,776 pixels. The ten fresh saves match 75,753. In the separate twelve-setting archive, eleven saved settings now render. At 128 × 32, seed 433608, scale 3, disorder .046875 and expansion enabled, both U16 and F32 still reach the execution guard. The archived save at that geometry also reaches it. + +### Deferring two tiled subtrees until a quadrant batch fills + +When two tiled FX-Map trees share a batch, an earlier split can fall in the preceding 64-parent subtree. A later pair of subtrees resumes at a different position if it cannot fill the receiving batch. This occurs with additive procedural shapes and connected image stamps. The shared evaluator uses the number of physical copies submitted by each subtree. + +Open Noise Dirt 1 with graph tiling enabled, set scale to 1 and use the dimensions, seed and disorder below. Enable non-square expansion except at seed 785357. Request the listed storage on the node supplying the output. Save normally outside the package library, reopen directly in both applications and compare the stored pixels. Counts are exact pixels / pixels compared, followed by maximum error. Integer errors are measured in storage levels. + +| F32 dimensions · seed · disorder | Previous on one processor | Corrected on one | Corrected on eight | Ordinary save on one | +|---|---:|---:|---:|---:| +| 32 × 16 · 649503 · 0.53125 | 501/512 · 1.1920929e-07 | 512/512 · 0 | 496/512 · 1.1920929e-07 | 512/512 · 0 | +| 64 × 32 · 649541 · 0.8125 | 2,044/2,048 · 5.96046448e-08 | 2,044/2,048 · 5.96046448e-08 | 1,989/2,048 · 1.1920929e-07 | 2,045/2,048 · 5.96046448e-08 | +| 128 × 64 · 649603 · 0.21875 | 7,988/8,192 · 1.1920929e-07 | 8,192/8,192 · 0 | 7,958/8,192 · 1.1920929e-07 | 8,184/8,192 · 5.96046448e-08 | +| 32 × 16 · 785317 · 0.71875 | 496/512 · 5.96046448e-08 | 512/512 · 0 | 493/512 · 5.96046448e-08 | 512/512 · 0 | +| 64 × 32 · 785327 · 0.40625 | 2,002/2,048 · 5.96046448e-08 | 2,048/2,048 · 0 | 1,990/2,048 · 5.96046448e-08 | 2,048/2,048 · 0 | +| 128 × 64 · 785339 · 0.625 | 8,006/8,192 · 1.1920929e-07 | 8,192/8,192 · 0 | 7,968/8,192 · 5.96046448e-08 | 8,192/8,192 · 0 | +| 64 × 128 · 785357 · 0.09375 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 7,873/8,192 · 1.1920929e-07 | 8,192/8,192 · 0 | + +At the four new seeds, render U16 and F32 at every size, adding U8 and F16 at 32 × 16 and 64 × 32. The originals now match all 12 settings on one processor. All 12 ordinary saves have the same local raw hashes and match their reopened reference. The eight-processor captures match seven complete settings. + +| Format | Previous on one | Corrected on one | Corrected on eight | Ordinary save on one | +|---|---:|---:|---:|---:| +| U8 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | +| U16 | 18,943/18,944 · 1 | 18,944/18,944 · 0 | 18,942/18,944 · 1 | 18,944/18,944 · 0 | +| F16 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | +| F32 | 18,696/18,944 · 1.1920929e-07 | 18,944/18,944 · 0 | 18,324/18,944 · 1.1920929e-07 | 18,944/18,944 · 0 | + +Including the earlier geometries, this run checked 41 originals and their 41 ordinary saves. Rerun the [five earlier F32 geometries](#the-receiving-half-of-a-quadrant-in-two-tiled-trees) and the [earlier U8, U16 and F16 geometries](#four-full-batches-in-two-tiled-quadrant-trees) with the same settings. Each local original reproduces its saved raw buffer. + +| All 41 settings by format | Previous on one | Corrected on one | Corrected on eight | Ordinary save on one | +|---|---:|---:|---:|---:| +| U8 · 9 settings | 33,792/33,792 · 0 | 33,792/33,792 · 0 | 33,791/33,792 · 1 | 33,792/33,792 · 0 | +| U16 · 11 settings | 50,175/50,176 · 1 | 50,176/50,176 · 0 | 50,172/50,176 · 1 | 50,176/50,176 · 0 | +| F16 · 9 settings | 33,792/33,792 · 0 | 33,792/33,792 · 0 | 33,792/33,792 · 0 | 33,792/33,792 · 0 | +| F32 · 12 settings | 82,476/82,944 · 1.1920929e-07 | 82,939/82,944 · 5.96046448e-08 | 80,373/82,944 · 1.1920929e-07 | 82,933/82,944 · 5.96046448e-08 | + +In the [60-setting Dirt series](#expanded-image-and-save-comparisons-for-dirt-1-and-dirt-2), the earlier visit counts identify 13 settings per graph with two complete outer trees. Recheck all 13, plus seven settings covering one, four, eight, nine and 36 outer trees. Recheck the four archived ordinary saves per graph selected by the same geometries, including three with two trees. Each cell gives exact complete images / images rendered and exact pixels / pixels compared. + +| Graph | Previous originals on one | Corrected originals on one | Corrected originals on eight | Archived saves on one | +|---|---:|---:|---:|---:| +| Noise Dirt 1 | 15/20 · 153,462/154,368 | 16/20 · 153,516/154,368 | 10/20 · 152,459/154,368 | 3/4 · 39,338/39,424 | +| Noise Dirt 2 | 20/20 · 154,368/154,368 | 20/20 · 154,368/154,368 | 18/20 · 154,366/154,368 | 4/4 · 39,424/39,424 | + +For Noise Dirt 1, the U8 / U16 / F16 / F32 maxima are 0 / 1 / 0 / 1.1920929e-07 on one processor, 0 / 1 / 0 / 1.1920929e-07 on eight and 0 / 0 / — / 5.96046448e-08 for the archived saves. +For Noise Dirt 2, the U8 / U16 / F16 / F32 maxima are 0 / 0 / 0 / 0 on one processor, 0 / 0 / 0 / 2.52090394e-05 on eight and 0 / 0 / — / 0 for the archived saves. + +The only changed raw hash in these 48 comparisons was Noise Dirt 1 at 64 × 32, seed 299403, scale 1, zero disorder and expansion enabled. Its one-processor F32 score improved from 1,994/2,048 · 5.96046448e-08 to 2,048/2,048 · 0. A new ordinary save gives 2,048/2,048 · 0. The previous complete 60-setting comparisons for both graphs remain recorded separately. + +Noise Dirt 1 v2 also changes at 64 × 32. Use seed 299446, scale 1, zero disorder and anisotropy, zero angle and tile offset, unit disorder speed and expansion enabled. Compare this setting with the other five [tiled v2 settings](#whole-untiled-dirt-relatives-and-the-depth-seven-iteration). The other five return their previous local hashes. The F32 result moved from 1,981/2,048 · 1.1920929e-07 to 2,048/2,048 · 0 on one processor and from 1,993/2,048 · 5.96046448e-08 to 1,964/2,048 · 1.1920929e-07 on eight. The ordinary save moved from 1,989/2,048 · 1.1920929e-07 to 2,036/2,048 · 5.96046448e-08. + +For Noise Dirt 5, repeat the [two tiled .34375 rectangles](#the-receiving-half-of-a-quadrant-in-two-tiled-trees) across all four formats. The one-processor result improved from 6/8 · 40,958/40,960 to 8/8 · 40,960/40,960. All eight ordinary saves also match every pixel. The corrected U16 word at (92,40) is 24,511. On eight processors 4/8 · 40,949/40,960 match. The U8 / U16 / F16 / F32 maxima on eight processors are 0 / 4 / 6.10351562e-05 / 5.08278608e-05. + +For the isolation, start with the [two-tree additive-square field](#four-full-batches-in-two-tiled-quadrant-trees). Distribute an added copy per parent in local Y then X order within each group of 64, starting another pass when necessary. Number the 32,768 drawing parents from zero. On a white background give the earlier of two marked parents tint −1 and the later tint 2⁻²⁵. Read the common pixel in F32 and repeat with the two tints reversed. + +- Give groups 234, 260, 320, 440, 450, 480 and 488 exactly 70, 141, 191, 145, 62, 24 and 126 extra copies. Give group 497 successively 83, 84 and 85. At 83, parent 21,055 draws before 20,352. At 84 and 85, parent 31,935 draws before 24,452. At the first two thresholds the previous release returned zero on the relevant marker. The corrected release returns 2⁻²⁵ at all three. +- Give groups 236, 256, 308, 320, 439, 480 and 488 exactly 76, 156, 85, 169, 132, 37 and 105 extras. Give group 352 successively 83, 84 and 85. The earlier batch can cross the boundary at parent 24,448. At 85, marking parents 32,139 and 29,680 gives 2⁻²⁵ instead of the previous zero. All 65,534 signed neighboring comparisons matched in the separate sparse field at 85. Three differences in the first read of the opposite polarity also matched in two repeat captures. + +Two root-derived fields, eight independently perturbed fields and six newly generated weighted or sparse fields each match all 65,534 signed comparisons in their original reference reads. For the perturbations, apply 100 random −1, 0 or +1 group updates with PCG64 seed 807143 and distribute each group's nonnegative total uniformly across its 64 parents. For the second seed 391073, the three weighted fields contain 1,703, 1,543 and 1,847 extras. The three sparse fields contain 898, 851 and 935. The separate 16-field release comparison uses two root-derived fields, six new generated fields, six boundary fields and two earlier controls. For every field compare both complete 256² images from the even and odd adjacent pairs. Results are 2,097,152/2,097,152 · 0 for originals and 2,097,152/2,097,152 · 0 for ordinary saves. + +In four alternating single-processor cold release runs at 128 × 64 and seed 649603, median cook time moved from 6.57 to 6.25 seconds and median peak working set from 235.6 to 249.9 MiB. Both new normal-cook regressions failed on the preceding implementation. All 574 node and evaluator release tests, formatting, strict workspace Clippy, layers and WebAssembly passed. + +### Whole untiled Dirt relatives and the depth-seven iteration + +Set graph tiling to absolute with both axes off. At 16 × 32 use seed 649211 and disorder .3125. At 32 × 64 use seed 649229 and disorder .78125. Enable non-square expansion. Use scale 1 on the three graphs exposing it. For each geometry render U8, U16, F16 and F32, then save the graph normally outside the package library and open that file directly in both applications. Compare the builds immediately before and after the [two-tree untiled draw-order change](#unfinished-draws-across-two-untiled-quadrant-trees). Cells give exact settings / settings rendered and exact pixels / pixels compared. + +| Graph | Before on one processor | After on one | Before on eight | After on eight | Ordinary save on one | +|---|---:|---:|---:|---:|---:| +| Noise Dirt 1 v2 | 6/8 · 10,175/10,240 | 6/8 · 10,175/10,240 | 6/8 · 10,193/10,240 | 6/8 · 10,193/10,240 | 6/8 · 10,166/10,240 | +| Noise Dirt 5 | 5/8 · 10,237/10,240 | 8/8 · 10,240/10,240 | 6/8 · 10,238/10,240 | 5/8 · 10,235/10,240 | 8/8 · 10,240/10,240 | +| Noise Dirt 5 v2 | 6/8 · 10,127/10,240 | 6/8 · 10,127/10,240 | 6/8 · 10,110/10,240 | 6/8 · 10,110/10,240 | 6/8 · 10,126/10,240 | +| Noise Dirt Gradient | 8/8 · 10,240/10,240 | 8/8 · 10,240/10,240 | 7/8 · 10,239/10,240 | 7/8 · 10,239/10,240 | 8/8 · 10,240/10,240 | +| Noise Dirt Gradient v2 | 1/8 · 8,429/10,240 | 1/8 · 8,429/10,240 | 2/8 · 8,572/10,240 | 2/8 · 8,572/10,240 | 1/8 · 8,424/10,240 | + +Noise Dirt 5 gained one exact pixel in each of U16, F16 and F32 at 32 × 64 on one processor. Both sizes also match across all four ordinary saves per size. On eight processors the total moved from 10,238 to 10,235 exact pixels. Noise Dirt Gradient matches both single-processor cases in every format. At 16 × 32, its eight-processor U16 image differs at one pixel by one level. The other three graphs retain their previous local hashes. + +| Graph | Maximum on one, U8 / U16 / F16 / F32 | Maximum on eight | Maximum on saved graphs | +|---|---|---|---| +| Noise Dirt 1 v2 | 0 / 0 / 0 / 5.96046448e-08 | 0 / 0 / 0 / 5.96046448e-08 | 0 / 0 / 0 / 1.1920929e-07 | +| Noise Dirt 5 | 0 / 0 / 0 / 0 | 0 / 4 / 6.10351562e-05 / 5.08278608e-05 | 0 / 0 / 0 / 0 | +| Noise Dirt 5 v2 | 0 / 0 / 0 / 1.1920929e-07 | 0 / 0 / 0 / 5.96046448e-08 | 0 / 0 / 0 / 1.1920929e-07 | +| Noise Dirt Gradient | 0 / 0 / 0 / 0 | 0 / 1 / 0 / 0 | 0 / 0 / 0 / 0 | +| Noise Dirt Gradient v2 | 1 / 1 / 0.00048828125 / 2.38418579e-07 | 1 / 0 / 0.00048828125 / 2.38418579e-07 | 1 / 1 / 0.00048828125 / 2.98023224e-07 | + +To count the Noise Dirt 1 v2 iteration, retain its original outer switch, iteration, seeds and depth-seven iterate. Replace the depth-seven drawing quadrant with a childless additive square. The removed drawings write only their frame offset, which the retained control flow never reads. Set its size to (16,16), literal gray tint to 2⁻²¹ and center to (.21875 + .25 times the enclosing iteration number, .484375). Subtract the quadrant position to form the frame offset. Use a black background, zero roughness, unit opacity and a unit render and tiling region. Sample each square's center and multiply the F32 value by 2²¹. + +With both graph and FX-Map tiling off, the default anisotropy and explicit zero each give 147,456 draws at iteration number zero and none at one or two, at both sizes above. At anisotropy .75 the three counts are 147,456 / 121,765 / 121,765 at 16 × 32 and 147,456 / 121,793 / 121,793 at 32 × 64. The six images match 7,680/7,680 pixels on one processor, on eight and after ordinary saves, maximum zero throughout. + +Restore the original graph and FX-Map tiling and repeat the count. Use the original defaults at 16 × 32 with seeds 0 and 299367. At 32 × 64 with seed 105450 and 64 × 32 with seed 299446, use scale 1, zero disorder and anisotropy, zero anisotropy angle and tile offset, disorder speed 1 and non-square expansion enabled. At 128 × 256 with seed 433678, use scale 1, disorder, disorder speed and anisotropy .8125, angle .5625, offset (.46875, −.3046875) and non-square expansion enabled. The first four settings each give 32,768 / 0 / 0. The last gives 32,768 / 29,283 / 29,283. Across these five controls all three comparisons give 37,888/37,888 · 0. The count at iteration zero corresponds to two complete trees with normal tiling and nine in the two earlier untiled settings. + +Render the complete Noise Dirt 1 v2 graph at those same settings. Compare the checked release, including the receiving-quadrant change, against stored raw captures and fresh ordinary saves. Both local releases give the same raw hashes for these six settings. + +| Size · seed · format | Original on one · maximum | Original on eight · maximum | Ordinary save on one · maximum | +|---|---:|---:|---:| +| 16 × 32 · 0 · F32 | 512/512 · 0 | 501/512 · 5.96046448e-08 | 510/512 · 2.98023224e-08 | +| 16 × 32 · 299367 · F32 | 512/512 · 0 | 492/512 · 1.1920929e-07 | 509/512 · 5.96046448e-08 | +| 32 × 64 · 105450 · F16 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| 64 × 32 · 299446 · F32 | 1,981/2,048 · 1.1920929e-07 | 1,993/2,048 · 5.96046448e-08 | 1,989/2,048 · 1.1920929e-07 | +| 128 × 256 · 433678 · U16 | 32,766/32,768 · 1 | 32,762/32,768 · 1 | 32,762/32,768 · 1 | +| 128 × 256 · 433678 · F32 | 28,180/32,768 · 2.38418579e-07 | 28,746/32,768 · 1.1920929e-07 | 27,949/32,768 · 2.38418579e-07 | + +At 16 × 32 and seed 299367, the earlier catalog measurement was 495/512 · 1.1920929e-07. The current release matches 512/512 F32 pixels on one processor. The 128 × 256 F32 image still differs while all three iteration counts agree. At the earlier [32 × 16 blocked setting](#streaming-deep-quadrants-that-draw-the-same-connected-image), the complete release graph still reaches its execution guard. The reduced depth-seven readout gives 131,072 / 90,211 / 90,211. Both reference worker counts and the ordinary save match 512/512 pixels with maximum zero. The 311,494 parents have 21 drawing quadrants each, requiring 6,541,374 draws. The instrumented MaterialCraft evaluator reaches its 5,242,880 full property evaluations at depth seven. At that point it has 909,311 traversal credits, 2,870 retained draws and zero property-cache hits. Both discrepancies remain open. + +For a separate Noise Dirt 1 repeat at 64 × 32, seed 649541 and disorder .8125, the [first two captures](#the-receiving-half-of-a-quadrant-in-two-tiled-trees) agreed at 1,991 locations. Three further one-processor reads match 2,048, 2,047 and 2,044 of 2,048 pixels. Across the one- and eight-processor reads and the save, all 1,965 invariant pixels match. Each local pixel appears in at least one read. At 32 × 16 and 128 × 64, respectively, one and 25 local pixels still differ from every reference read. + +### The receiving half of a quadrant in two tiled trees + +A batch of wrapped FX-Map draws can finish partway through a quadrant containing 256 parents. On either side of its halfway point, three unfinished subtrees return in a different order. The shared evaluator selects that order when the physical copy counts fit every measured subtree boundary. + +Open Noise Dirt 1 with ordinary graph tiling, scale 1 and non-square expansion enabled. Change disorder and seed as shown. Set the node supplying the grayscale output to F32. Save normally outside the package library and open that file directly in both applications. Each comparison gives exact pixels / pixels compared and maximum error. + +| Size · seed · disorder | Earlier on one processor | Corrected on one | Corrected on eight | Ordinary save on one | +|---|---:|---:|---:|---:| +| 64 × 32 · 649261 · 0.34375 | 1,991/2,048 · 5.96046448e-08 | 2,047/2,048 · 2.98023224e-08 | 1,971/2,048 · 5.96046448e-08 | 2,048/2,048 · 0 | +| 128 × 64 · 649277 · 0.34375 | 8,009/8,192 · 1.1920929e-07 | 8,192/8,192 · 0 | 7,917/8,192 · 1.1920929e-07 | 8,192/8,192 · 0 | +| 32 × 16 · 649503 · 0.53125 | 501/512 · 1.1920929e-07 | 501/512 · 1.1920929e-07 | 501/512 · 5.96046448e-08 | 501/512 · 1.1920929e-07 | +| 64 × 32 · 649541 · 0.8125 | 2,017/2,048 · 5.96046448e-08 | 2,044/2,048 · 5.96046448e-08 | 1,989/2,048 · 1.1920929e-07 | 2,045/2,048 · 5.96046448e-08 | +| 128 × 64 · 649603 · 0.21875 | 7,988/8,192 · 1.1920929e-07 | 7,988/8,192 · 1.1920929e-07 | 8,007/8,192 · 1.1920929e-07 | 7,986/8,192 · 1.1920929e-07 | + +The two rectangles at disorder .34375 moved from 10,000/10,240 · 1.1920929e-07 to 10,239/10,240 · 2.98023224e-08 on one processor. All 10,240 saved pixels matched. On three further one-processor reads, the 64 × 32 reference matched all 2,048 pixels each time. At 128 × 64 it matched 8,192, 8,184 and 8,192. Across the original, the save and the repeated one- and eight-processor reads, MaterialCraft matched all 1,940 and 7,792 invariant locations, respectively. The 64 × 32 image at disorder .8125 still differs at three of the 1,991 locations shared by its original one- and eight-processor reads. + +Repeat in U8, U16 and F16 at the [four earlier geometries](#four-full-batches-in-two-tiled-quadrant-trees) and the three extra seeds above. Each row covers seven original settings and seven ordinary saves. Integer errors are stored levels. + +| Format | Earlier on one | Corrected on one | Corrected on eight | Ordinary save on one | +|---|---:|---:|---:|---:| +| U8 | 31,232/31,232 · 0 | 31,232/31,232 · 0 | 31,231/31,232 · 1 | 31,232/31,232 · 0 | +| U16 | 31,231/31,232 · 1 | 31,232/31,232 · 0 | 31,230/31,232 · 1 | 31,232/31,232 · 0 | +| F16 | 31,232/31,232 · 0 | 31,232/31,232 · 0 | 31,232/31,232 · 0 | 31,232/31,232 · 0 | + +Repeat all 60 originals and 12 archived ordinary saves per graph in the [established Dirt series](#expanded-image-and-save-comparisons-for-dirt-1-and-dirt-2). Each cell gives exact whole settings / settings rendered and exact pixels / pixels compared. + +| Graph | Earlier originals on one | Corrected originals on one | Corrected originals on eight | Archived saves on one | +|---|---:|---:|---:|---:| +| Noise Dirt 1 | 41/60 · 780,815/785,664 | 41/60 · 780,815/785,664 | 32/60 · 779,996/785,664 | 8/12 · 147,514/149,504 | +| Noise Dirt 2 | 53/60 · 785,657/785,664 | 53/60 · 785,657/785,664 | 51/60 · 785,650/785,664 | 11/12 · 149,503/149,504 | + +In U8 / U16 / F16 / F32 order, Dirt 1 maxima are 0 / 1 / 0 / 1.1920929e-07 on one processor, 0 / 1 / 0 / 1.1920929e-07 on eight and 0 / 0 / — / 1.1920929e-07 on the archived saves. Dirt 2 maxima are 0 / 2 / 6.10351562e-05 / 2.52053142e-05 on one processor, 0 / 2 / 0.000122070312 / 2.52090394e-05 on eight and 0 / 0 / — / 2.52053142e-05 on the archived saves. + +All 144 local raw buffers in the established series reproduce their earlier hashes. The three earlier tall F32 originals and saves still match 43,008/43,008 on one processor. + +Use the [two-tree field of additive squares](#four-full-batches-in-two-tiled-quadrant-trees). Per group of 64 parents, distribute extra wrapped leaves first by local Y then X. In groups 256, 309, 320, 428 and 488 add 189, 85, 169, 169 and 148 copies. In group 464 add successively 167, 168 and 169. Starting on white, give parent 28,996 a gain of −1 and parent 24,640 a gain of 2⁻²⁵. With 167 and 168 extra copies the reference returns 2⁻²⁵ and zero. The preceding release returned zero at 167. At 169 copies use parents 29,824 and 32,596 for the same two gains. Both applications give zero. Reversing the gains also verifies the draw order. + +Compare neighboring parents in three independent weighted fields, four independent perturbed fields and the three boundary fields. For the weighted fields use the [PCG64 procedure](#tiled-copies-across-two-complete-quadrant-trees) with seed 1388429, total copies drawn uniformly from 1,400 through 3,199, accepting candidates 1,813, 3,499 and 5,173 counted from each previous selection. Their totals are 1,570, 1,612 and 1,437. For the four perturbed fields use PCG64 seed 879131. From the five fixed group counts above, draw 512 integer offsets from −60 through 80, applying only those at nonzero groups. Add a random integer from 150 through 290 to group 464. Draw from 10 through 180 extra group indices uniformly with replacement. Within each group assign its copies to uniform parent indices with replacement. Reject fields with a parent above sixteen copies or a batch outside the measured receiving subtree. The four fields have 1,128, 1,190, 1,143 and 1,229 extra copies. All 262,136 signed adjacent comparisons matched. For the ten fields compare the two full images containing the even and odd neighboring pairs with opposing gains. The release matched 1,310,688/1,310,720 · 2.98023224e-08 on originals and 1,310,720/1,310,720 · 0 on ordinary saves. The 32 differing signed checks in the first weighted field all matched in two further original captures. A field in which the third pending subtree cannot fill the batch still has a different order. + +Noise Dirt 5 uses the same evaluator. Keep ordinary tiling and repeat the two .34375 rectangles above in all four formats. On one processor 6/8 · 40,958/40,960 match, on eight 4/8 · 40,949/40,960, and on ordinary saves 6/8 · 40,958/40,960. U8 matches at both sizes on all three routes. F16 matches both single-processor originals and saves. On eight processors it gives 2,048/2,048 and 8,190/8,192, maximum 2⁻¹⁴ at the larger size. At 128 × 64, the U16 / F32 maxima are 3 / 5.07831573e-05 on one, 4 / 5.08278608e-05 on eight and 3 / 5.07831573e-05 on the save. Add a second output exposing the upstream FX-Map alongside Levels. At (92,40), two one-processor captures give input 39,995 and U16 output 24,511. Two eight-processor captures give 39,994 and 24,508. Over eleven reads including these paired outputs, MaterialCraft matches all 8,187 invariant locations in each format. Each of its 8,192 pixels appears in at least one reference read of that format. In each format the one-processor original still differs at one pixel. + +All 572 node and evaluator release tests passed along with formatting, strict workspace Clippy, layers and WebAssembly checks. + +### Four full batches in two tiled quadrant trees + +In a pair of complete depth-nine quadrant trees, the last wrapped copy can fill the fifth physical batch before parent 22,528. When only four batches fit, two pending subtrees start earlier. The fifth batch can also end exactly at its subtree boundary. Three additional Noise Dirt 1 settings exposed this difference in the shared FX-Map evaluator. + +Use the original graph with ordinary tiling, scale 1 and non-square expansion enabled. Set disorder and the graph seed as shown and set the grayscale output's source to F32. Save each graph normally in MaterialCraft and reopen it in both applications. Each cell gives exact pixels / pixels compared and maximum absolute difference. + +| Size · seed · disorder | Earlier on one processor | Corrected on one | Corrected on eight | Ordinary save on one | +|---|---:|---:|---:|---:| +| 32 × 64 · 531803 · 0.34375 | 1,991/2,048 · 5.96046448e-08 | 2,048/2,048 · 0 | 1,998/2,048 · 5.96046448e-08 | 2,048/2,048 · 0 | +| 64 × 128 · 531841 · 0.6875 | 7,993/8,192 · 1.1920929e-07 | 8,192/8,192 · 0 | 7,966/8,192 · 1.1920929e-07 | 8,192/8,192 · 0 | +| 128 × 256 · 531901 · 0.8125 | 32,040/32,768 · 1.1920929e-07 | 32,768/32,768 · 0 | 31,754/32,768 · 1.1920929e-07 | 32,768/32,768 · 0 | +| 64 × 32 · 649261 · 0.34375 | 1,991/2,048 · 5.96046448e-08 | 1,991/2,048 · 5.96046448e-08 | 1,990/2,048 · 5.96046448e-08 | 1,992/2,048 · 5.96046448e-08 | +| 128 × 64 · 649277 · 0.34375 | 8,009/8,192 · 1.1920929e-07 | 8,009/8,192 · 1.1920929e-07 | 8,026/8,192 · 1.1920929e-07 | 8,009/8,192 · 1.1920929e-07 | + +The three tall originals moved from 42,024/43,008 · 1.1920929e-07 to 43,008/43,008 · 0 on one processor. Every local save has the original raw hash. The two wider F32 images still have differences. Repeat the four smaller geometries above in U8, U16 and F16. Each row covers four original settings and their saves. Integer maxima count stored levels. + +| Format | Earlier on one | Corrected on one | Corrected on eight | Ordinary save on one | +|---|---:|---:|---:|---:| +| U8 | 20,480/20,480 · 0 | 20,480/20,480 · 0 | 20,479/20,480 · 1 | 20,480/20,480 · 0 | +| U16 | 20,479/20,480 · 1 | 20,480/20,480 · 0 | 20,480/20,480 · 0 | 20,480/20,480 · 0 | +| F16 | 20,480/20,480 · 0 | 20,480/20,480 · 0 | 20,480/20,480 · 0 | 20,480/20,480 · 0 | + +Repeat the [established catalog panel](#expanded-image-and-save-comparisons-for-dirt-1-and-dirt-2). Each row gives exact whole settings / settings rendered and exact pixels. The maxima are reported below in U8, U16, F16 and F32 order. + +| Graph | Earlier originals on one | Corrected originals on one | Corrected originals on eight | Archived saves on one | +|---|---:|---:|---:|---:| +| Noise Dirt 1 | 41/60 · 780,815/785,664 | 41/60 · 780,815/785,664 | 32/60 · 779,996/785,664 | 8/12 · 147,514/149,504 | +| Noise Dirt 2 | 53/60 · 785,657/785,664 | 53/60 · 785,657/785,664 | 51/60 · 785,650/785,664 | 11/12 · 149,503/149,504 | + +Noise Dirt 1 maxima are 0 / 1 / 0 / 1.1920929e-07 on one processor, 0 / 1 / 0 / 1.1920929e-07 on eight and 0 / 0 / — / 1.1920929e-07 on the archived saves. Noise Dirt 2 maxima are 0 / 2 / 6.10351562e-05 / 2.52053142e-05 on one processor, 0 / 2 / 0.000122070312 / 2.52090394e-05 on eight and 0 / 0 / — / 2.52053142e-05 on the archived saves. + +Every local raw hash in the established panel matches the preceding build. The additional rectangular settings above exercise the four-batch order. + +For the reduced control, use two complete nine-level quadrant trees and one additive square per node at depths seven through nine. Each of 16,384 parents in each tree accounts for 21 draws. Divide the two trees' parents into groups of 64 in traversal order. Start every terminal square inside the unit tile. For a group with q extra copies, wrap the first floor(q/64) leaves in each parent and one more leaf in the first q mod 64 parents. Order a parent's sixteen leaves by their local Y then X coordinates. Give groups 213, 217, 312, 372, 384, 419, 464 and 472 respectively 46, 67, 85, 171, 154, 85, 36 and 32 extra copies. Give group 332 successively 167, 168 and 169. On white, overlap parent 29,819 at −1 with parent 22,269 at 2⁻²⁵. Their output is 2⁻²⁵, zero and zero. The preceding build returned zero at 167. A second independent pair, parents 24,640 and 32,596, also changes order. The reference agreed with all 65,534 signed adjacent comparisons in each field. + +Use four further original fields generated with [the same weighted parent selection](#tiled-copies-across-two-complete-quadrant-trees), PCG64 seed 913007 and extra-copy totals drawn uniformly from 1,400 through 2,999. Keep candidates 67, then 16, 76 and 59 counted from the previous selection, restarting the candidate count at zero after each. Their totals are 1,546, 1,621, 2,384 and 1,494. All 262,136 signed adjacent comparisons match. For each of the seven fields render the even pairs with the smaller gain first and the odd pairs with the gains reversed. Render again after an ordinary save. The release matches 917,504/917,504 · 0 on the originals and 917,504/917,504 · 0 on the saves. All 571 release node and graph-evaluation tests passed with formatting, strict workspace Clippy, layers and WebAssembly checks. + +### Tiled copies across two complete quadrant trees + +With ordinary graph tiling, two complete drawing trees can share a physical batch. Each of 16,384 parents per tree submits one draw, four child draws and sixteen grandchild draws. The sums depend on which tile copy fills a batch of 5,460. In the order with five full batches before parent 22,528, its remaining draws precede the two pending subtrees starting at parent 24,640. A separate batch ends at parent 20,352 when no stamp wraps. Additional copies move that cut into the preceding subtree. + +Use Noise Dirt 1 with its original graph and tiling. Keep the published defaults at 16 × 32 and use scale 1, disorder .8125 and non-square expansion at 128 × 256. Set F32 on the node feeding the output. All three single-processor images now match. The invariant column counts locations at which the one- and eight-processor captures have identical F32 words. + +| Dimensions · seed | Earlier on one · maximum | Corrected on one · maximum | Corrected on eight · maximum | Invariant pixels matched | +|---|---:|---:|---:|---:| +| 16 × 32 · 0 | 499/512 · 5.96046448e-08 | 512/512 · 0 | 494/512 · 5.96046448e-08 | 494/494 | +| 16 × 32 · 299324 | 491/512 · 5.96046448e-08 | 512/512 · 0 | 489/512 · 5.96046448e-08 | 489/489 | +| 128 × 256 · 433665 | 32,050/32,768 · 1.1920929e-07 | 32,768/32,768 · 0 | 31,732/32,768 · 1.1920929e-07 | 31,732/31,732 | + +The same 128 × 256 geometry in U16 now matches all 32,768 pixels on one processor, up from 32,764. It also matches all 32,764 locations at which the seven archived U16 reads agree, including (59,61) at 40,709 and (42,230) at 29,926. In F32 all 31,145 locations shared by those seven reads agree with the release result. [Individual overlap measurements](#five-individual-image-draws-at-one-dirt-1-pixel) + +Repeat the [60 settings and 12 archived ordinary saves per graph](#expanded-image-and-save-comparisons-for-dirt-1-and-dirt-2) on one release build. Each cell gives exact pixels, total pixels and maximum difference in that storage format. Integer maxima are stored levels. The archive contains its own saved settings. + +| Graph · storage | Earlier original on one | Corrected original on one | Corrected original on eight | Corrected archived save on one | +|---|---:|---:|---:|---:| +| Noise Dirt 1 · U8 | 99,840/99,840 · 0 | 99,840/99,840 · 0 | 99,840/99,840 · 0 | 26,624/26,624 · 0 | +| Noise Dirt 1 · U16 | 338,928/338,944 · 1 | 338,932/338,944 · 1 | 338,931/338,944 · 1 | 51,712/51,712 · 0 | +| Noise Dirt 1 · F16 | 101,888/101,888 · 0 | 101,888/101,888 · 0 | 101,888/101,888 · 0 | — | +| Noise Dirt 1 · F32 | 239,403/244,992 · 1.1920929e-07 | 240,155/244,992 · 1.1920929e-07 | 239,337/244,992 · 1.1920929e-07 | 69,178/71,168 · 1.1920929e-07 | +| Noise Dirt 2 · U8 | 99,840/99,840 · 0 | 99,840/99,840 · 0 | 99,840/99,840 · 0 | 26,624/26,624 · 0 | +| Noise Dirt 2 · U16 | 338,940/338,944 · 2 | 338,940/338,944 · 2 | 338,935/338,944 · 2 | 51,712/51,712 · 0 | +| Noise Dirt 2 · F16 | 101,887/101,888 · 6.10351562e-05 | 101,887/101,888 · 6.10351562e-05 | 101,887/101,888 · 0.000122070312 | — | +| Noise Dirt 2 · F32 | 244,990/244,992 · 2.52053142e-05 | 244,990/244,992 · 2.52053142e-05 | 244,988/244,992 · 2.52090394e-05 | 71,167/71,168 · 2.52053142e-05 | + +Noise Dirt 1 improved from 37/60 to 41/60 exact originals on one processor. On eight processors 32/60 match, and 8/12 archived saves match on one processor. All four changed originals match after fresh ordinary saves in both applications, covering 66,560/66,560 pixels. Noise Dirt 2 matches 53/60 whole originals on one processor, 51/60 on eight and 11/12 archived saves. + +For an independent test, start a grayscale quadrant graph on white. Let outer iterations 0 and 5 each enter the same complete nine-level tree. Draw original white images or squares at depths 7, 8 and 9 with additive blending. Map pairs of depth-seven parents onto a common interior pixel, with gains −1 and 2⁻²⁵. Swap both gains and repeat the comparisons with adjacent parent pairs offset by one. The two possible results distinguish their compositing order. Hold other draws away from the readout. Move a selected terminal draw from (.875,.875) to (0,.875) to add one tile copy without touching the readout. In the regression, moving the first tree's eight-by-eight corner of terminal draws changes the order of parents 1,955 and 3,868. With no extra copies the readout is 2⁻²⁵ and with 64 it is zero. + +To reproduce the panel with more tile copies, distribute a requested number of extra draws among 32,768 depth-seven parents. Store each parent's count in the lower half of an original 256² RGBA field, with one 128-wide bank per tree. At depth nine, move the first requested number of leaves in the parent's four-by-four region across the tile edge, in row-major order. The upper half of the field carries the independent signed readout pairs. Use PCG64 seed 172349. For each candidate draw 64 standard normal values, exponentiate, repeat each weight for 512 consecutive parents in traversal order, and normalize the weights to sum to one. Draw the extra-copy total uniformly from integers 1,100 through 3,599, then select parents with replacement using those weights. Keep candidates 48, 49, 53 and 56. Continue the same random stream with totals 30 through 439 and keep the next four candidates. Each parent in a tree uses the seven interleaved X and Y bits of its traversal index to locate its texel. Across four fields with 37, 253, 240 and 296 extra copies and four with 2,365, 2,135, 2,389 and 2,516, all 524,272 signed comparisons agree with the physical order. Two readout frames on each of four independent fields reproduce 524,288/524,288 F32 pixels on the release build, and 524,288/524,288 after an ordinary save. Maximum error is zero on both routes. More heavily wrapped first-tree controls can cross another subtree boundary and use the existing fallback. + +Two alternating cold runs of the 128 × 256 case averaged 5.61 s before and 6.56 s after. Average peak process working set was 182.6 MiB and 235.8 MiB. The normal-cook regression failed on the earlier build. All 570 release node and evaluator tests passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Unfinished draws across two untiled quadrant trees + +Noise Dirt 1 now matches all 13 original settings with graph tiling disabled on one processor, up from 12. The ordinary save also matches all 61,440 pixels. At 64 × 128 with seed 883903, scale 1, disorder .8125 and non-square expansion enabled, match counts rose from 8,062/8,192 to 8,192/8,192 in F32. Maximum error fell from 1.1920929e−07 to zero. The same file's eight-processor capture went from 8,053/8,192 to 7,999/8,192, maximum 1.1920929e−07. For the complete 13-setting series this gives 60,901/61,440 on eight processors, with seven whole images exact. Applying the tiling property to the drawing node instead gives 61,440/61,440 on one processor and 60,906/61,440 on eight. [Four output formats and original settings](#fixed-image-draw-order-in-untiled-noise-dirt-1) + +For three additional seeds keep the graph tiling off, scale 1 and expansion on. Run U8, U16, F16 and F32 at the first two sizes and F32 at the largest. Use an ordinary save and open the resulting SBS file directly in each application. The previous build matched 5/9 whole images, 73,054/73,728 pixels, on one processor. All nine now match on one processor and after reopening, maximum zero. On eight processors the same captures give 73,017/73,728 before and 72,886/73,728 after the change. + +| Dimensions · seed · disorder | Format | Earlier on one · maximum | Corrected on one · maximum | Corrected on eight · maximum | Ordinary save on one · maximum | +|---|---|---:|---:|---:|---:| +| 32 × 64 · 531803 · 0.34375 | U8 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| 32 × 64 · 531803 · 0.34375 | U16 | 2,047/2,048 · 1 | 2,048/2,048 · 0 | 2,047/2,048 · 1 | 2,048/2,048 · 0 | +| 32 × 64 · 531803 · 0.34375 | F16 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | +| 32 × 64 · 531803 · 0.34375 | F32 | 2,002/2,048 · 5.96046448e−08 | 2,048/2,048 · 0 | 1,998/2,048 · 5.96046448e−08 | 2,048/2,048 · 0 | +| 64 × 128 · 531841 · 0.6875 | U8 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | +| 64 × 128 · 531841 · 0.6875 | U16 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | +| 64 × 128 · 531841 · 0.6875 | F16 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | +| 64 × 128 · 531841 · 0.6875 | F32 | 8,059/8,192 · 1.1920929e−07 | 8,192/8,192 · 0 | 8,043/8,192 · 1.1920929e−07 | 8,192/8,192 · 0 | +| 128 × 256 · 531901 · 0.8125 | F32 | 32,274/32,768 · 1.1920929e−07 | 32,768/32,768 · 0 | 32,126/32,768 · 1.1920929e−07 | 32,768/32,768 · 0 | + +To isolate the 64 × 128 difference, retain the original outer iteration and the assignments in its switch. Gate the drawing branch on iteration 0 and then on iteration 5. Each isolated tree matches all 8,192 F32 pixels. Chain the two gated nodes with an F32 background connection. Each chain matches its corresponding reference chain at all 8,192 pixels. The forward chain matches 8,187 pixels of the original combined reference and the reverse matches 8,173. Three of the five forward-chain differences lie in pixels touched only by the second tree. + +For an independent order measurement, repeat a complete four-way quadrant tree through depth nine twice. Use additive grayscale on a white F32 background with both tiling axes off. Keep depths seven, eight and nine active and use a fixed connected white image for each draw. Assign each depth-seven parent a procedural address from its quadrant position and the outer iterator. At each readout pixel overlap exactly two selected parents with gains −1 and 2⁻²⁵. Other stamps draw away from the readouts. Swap the gains to check the opposite sign. Compare adjacent pairs once from the first parent and once from the second so that each parent is drawn only once per image. One tree retains all 32,766 signed comparisons of its earlier order. Two joined trees differ at 30 adjacent boundaries from the concatenated single-tree orders. + +On two trees, recover the order from independent pairs of fixed-image parents, then use analytic squares for the final check. All 32,767 adjacent pairs match in both sign directions. The measured order has 103 consecutive parent ranges. Its first 30 agree with the single-tree order. A batch of 5,460 draws fits 260 parents with 21 parent and descendant draws apiece. After two runs of 92 and 128 parents the remaining 40 places split the next run. The shared evaluator accounts for missed stamps when locating boundaries and submits the unfinished first-tree draws with the second tree. A single tree flushes its existing order. + +A repeated one-processor read of the same procedural field produced a different stored result during initial order recovery. Eleven later reads of the unchanged input agreed. Rechecking every comparison in both sign directions and testing the complete final order with the second shape gave the counts above. On the original 64 × 128 graph, independently measured contributions at 402 pixels predicted every reference value on one processor, including all 130 previous differences. At 56 pixels more than one address fit the isolated measurements. Every admissible assignment at each pixel predicted the same final value. The complete release read then matched all 8,192 pixels. + +The normal cook regression uses two outer iterations. With a 128² F32 readout on white, move the first tree’s depth-seven parent centered at (79.5,69.5)/128 and the second tree’s parent at (118.5,112.5)/128 to pixel (32,16). Give the first gain 2⁻²⁵ and the second −1. Use a stamp size of .875 relative to its quadrant and move all other draws to (.875,.875). The previous square and fixed white image each produced zero. The native output and corrected cook both give 2⁻²⁵, with 16,384/16,384 pixels exact for both shapes. A six-iteration switch emitting trees 0 and 5 produces the same result. One-tree and three-tree controls also match all 16,384 reference pixels apiece. + +Repeat at seeds 0 and 218819 with discs, paraboloids, bells and cones. The eight originals and eight ordinary saves each match 131,072/131,072 F32 pixels, maximum zero. The four 256² signed square comparison frames match 262,144/262,144 whole-image pixels. The independent untiled Noise Dirt 2 control uses scale 1, expansion on, 32 × 64 with seed 918731 and disorder .1875, and 64 × 128 with seed 918749 and disorder .75. All four output formats on one processor and all ordinary saves match 40,960/40,960, maximum zero. The eight-processor capture matches 40,959/40,960, maximum 6.10351562e−05 in F16. + +Four alternating cold-process release cooks of the 64 × 128 F32 setting averaged 6.01 s before and 6.04 s after. Peak process working sets were 201.2 and 231.0 MiB. All 569 release tests in the node and evaluator crates passed, together with formatting, strict workspace Clippy, layers and WebAssembly checks. Noise Dirt 1 remains open on eight processors and at its [ordinary tiled settings](#fixed-image-draws-in-tiled-dirt-graphs). + +### Fixed image draws in tiled Dirt graphs + +Open Noise Dirt 1 and Noise Dirt 2 with their ordinary graph tiling. Run the established 60 settings for each root and reopen the 12 archived ordinary saves directly. Compare stored pixels against the same one- and eight-processor desktop captures before and after the evaluator change. Each graph renders all 72 local buffers. [Earlier 60-setting comparison](#complete-render-coverage-for-the-two-fixed-image-dirt-graphs) + +| Stock graph and reference capture | Earlier whole images | Current whole images | Earlier exact pixels | Current exact pixels | +|---|---:|---:|---:|---:| +| Dirt 1 · original on one | 30/60 | 37/60 | 779,410/785,664 | 780,059/785,664 | +| Dirt 1 · original on eight | 33/60 | 32/60 | 780,626/785,664 | 780,308/785,664 | +| Dirt 1 · archived save on one | 6/12 | 7/12 | 147,509/149,504 | 147,510/149,504 | +| Dirt 2 · original on one | 50/60 | 53/60 | 785,652/785,664 | 785,657/785,664 | +| Dirt 2 · original on eight | 53/60 | 51/60 | 785,655/785,664 | 785,650/785,664 | +| Dirt 2 · archived save on one | 10/12 | 11/12 | 149,502/149,504 | 149,503/149,504 | + +| Graph and reference capture | U8 exact · maximum | U16 exact · maximum | F16 exact · maximum | F32 exact · maximum | +|---|---:|---:|---:|---:| +| Dirt 1 · one processor | 99,840/99,840 · 0 | 338,928/338,944 · 1 | 101,888/101,888 · 0 | 239,403/244,992 · 1.1920929e−07 | +| Dirt 1 · eight processors | 99,840/99,840 · 0 | 338,927/338,944 · 1 | 101,888/101,888 · 0 | 239,653/244,992 · 1.1920929e−07 | +| Dirt 1 · archived save on one | 26,624/26,624 · 0 | 51,708/51,712 · 1 | — | 69,178/71,168 · 1.1920929e−07 | +| Dirt 2 · one processor | 99,840/99,840 · 0 | 338,940/338,944 · 2 | 101,887/101,888 · 6.10351562e−05 | 244,990/244,992 · 2.52053142e−05 | +| Dirt 2 · eight processors | 99,840/99,840 · 0 | 338,935/338,944 · 2 | 101,887/101,888 · 0.000122070312 | 244,988/244,992 · 2.52090394e−05 | +| Dirt 2 · archived save on one | 26,624/26,624 · 0 | 51,712/51,712 · 0 | — | 71,167/71,168 · 2.52053142e−05 | + +The following settings changed locally. Defaults include scale 1. Leave unlisted controls at their defaults, save each graph normally and open the saved SBS file directly in both applications. Every fresh local save produces its original pixel buffer. + +| Graph · dimensions · seed | Changed controls | Format | Earlier on one · maximum | Current on one · maximum | Current on eight · maximum | Fresh save on one · maximum | +|---|---|---|---:|---:|---:|---:| +| Dirt 1 · 128 × 128 · 0 | defaults | U16 | 16,383/16,384 · 1 | 16,384/16,384 · 0 | 16,383/16,384 · 1 | 16,384/16,384 · 0 | +| Dirt 1 · 256 × 256 · 0 | defaults | U16 | 65,533/65,536 · 1 | 65,536/65,536 · 0 | 65,532/65,536 · 1 | 65,536/65,536 · 0 | +| Dirt 1 · 16 × 16 · 105424 | defaults | F32 | 251/256 · 5.96046448e−08 | 256/256 · 0 | 248/256 · 5.96046448e−08 | 256/256 · 0 | +| Dirt 1 · 32 × 32 · 105426 | disorder 0.3125, expansion off | F32 | 1,000/1,024 · 5.96046448e−08 | 1,024/1,024 · 0 | 1,001/1,024 · 5.96046448e−08 | 1,024/1,024 · 0 | +| Dirt 1 · 64 × 32 · 105432 | disorder 0.3125, expansion off | F32 | 1,992/2,048 · 1.1920929e−07 | 2,048/2,048 · 0 | 1,980/2,048 · 5.96046448e−08 | 2,048/2,048 · 0 | +| Dirt 1 · 64 × 64 · 433480 | disorder 0.9375, expansion off | F32 | 3,979/4,096 · 1.1920929e−07 | 4,096/4,096 · 0 | 3,962/4,096 · 5.96046448e−08 | 4,096/4,096 · 0 | +| Dirt 1 · 128 × 128 · 0 | defaults | F32 | 15,941/16,384 · 1.1920929e−07 | 16,384/16,384 · 0 | 15,813/16,384 · 1.1920929e−07 | 16,384/16,384 · 0 | +| Dirt 2 · 128 × 128 · 0 | defaults | U16 | 16,383/16,384 · 2 | 16,384/16,384 · 0 | 16,383/16,384 · 2 | 16,384/16,384 · 0 | +| Dirt 2 · 256 × 256 · 0 | defaults | U16 | 65,533/65,536 · 2 | 65,536/65,536 · 0 | 65,531/65,536 · 2 | 65,536/65,536 · 0 | +| Dirt 2 · 128 × 128 · 0 | defaults | F32 | 16,383/16,384 · 2.51829624e−05 | 16,384/16,384 · 0 | 16,383/16,384 · 2.51829624e−05 | 16,384/16,384 · 0 | + +Across Dirt 2 all 785,643 pixels common to the one- and eight-processor reference captures still match. In each of its three changed local images every pixel agrees with the one-processor capture. Seven stored pixels across the 60 original settings still differ on one processor. Both roots remain open. + +For an independent control, keep a single full quadrant tree with four children per interior node and draw a fixed connected image at depths seven and eight, then extend it to depth nine. Also test two alternating connected terminal child slots at depth eight with both tiling axes off. Use a white procedural source, the original 64² and 128 × 64 sizes, seeds 881021 and 881153 and F32 output. The no-tiling, four-child control also runs at depth eight. [Original subtree settings](#fixed-image-draw-order-in-untiled-noise-dirt-1) + +| Last depth · children per drawing parent · tiling | Earlier F32 on one · maximum | Current F32 on one · maximum | +|---|---:|---:| +| 8 · four · off | 12,124/12,288 · 2.38418579e−07 | 12,288/12,288 · 0 | +| 8 · two · off | 12,212/12,288 · 1.1920929e−07 | 12,288/12,288 · 0 | +| 8 · four · both | 12,082/12,288 · 2.38418579e−07 | 12,288/12,288 · 0 | +| 9 · four · both | 11,772/12,288 · 1.1920929e−07 | 12,288/12,288 · 0 | +| 9 · four · horizontal | 11,832/12,288 · 1.1920929e−07 | 11,832/12,288 · 1.1920929e−07 | + +For a varying procedural source use a single 32² grayscale paraboloid as the connected image. Set scale 1 and turn off non-square expansion. At 32 × 64 use seed 437019 and disorder .3125. At 128² use seed 437059 and disorder .84375. Compare U8, U16, F16 and F32 and repeat after an ordinary save. + +| Last depth · children · tiling · filter | Original on one · whole images | Original on eight · whole images | Ordinary save on one · whole images | +|---|---:|---:|---:| +| 8 · four · both · nearest | 73,728/73,728 · 8/8 | 73,510/73,728 · 5/8 | 73,728/73,728 · 8/8 | +| 8 · two · off · bilinear | 73,728/73,728 · 8/8 | 73,723/73,728 · 7/8 | 73,728/73,728 · 8/8 | +| 9 · four · both · automatic | 73,728/73,728 · 8/8 | 73,054/73,728 · 5/8 | 73,728/73,728 · 8/8 | + +The one-processor original and reopened controls have maximum error zero in every format. The largest eight-processor differences across the three controls are U8 0, U16 1, F16 0, F32 1.1920929e−07. Integer errors use stored levels and floating-point errors use absolute differences. + +The shared evaluator uses the existing subtree and tile-copy order for a single complete grayscale quadrant tree drawing one fixed image and filter. The normal cook regression moves part of a signed drawing over the tile edge. The earlier depth-eight control matched 16,060/16,384 analytic-square pixels. The corrected tree matches all 16,384 at depth eight with tiling off and with both axes on, and at depth nine with both on. The white-image horizontal-only control still differs. The graph files use their original procedural controls throughout. + +Four alternating cold-process release runs at the Dirt 1 default 128² F32 setting averaged 3.04 s before and 2.93 s after. Peak process working sets were 197.6 and 204.0 MiB. All 568 release tests in the node and evaluator crates passed along with formatting, strict workspace Clippy, layers and WebAssembly checks. + +### Fixed-image draw order in untiled Noise Dirt 1 + +Open Noise Dirt 1 and set the graph tiling mode to absolute with both axes off. Keep scale at 1 and use the settings below. At the first three sizes render U8, U16, F16 and F32. At 64 × 128 render F32. Repeat after an ordinary save outside the package library, opening the saved file directly in both applications. A separate control sets the same tiling mode on the drawing FX-Map with the graph at its default. All 13 local output buffers and all 13 one-processor reference buffers agree between the two ways of setting the property. + +| Size · seed | Disorder · non-square expansion | Trees drawn | Earlier F32 on one · maximum | Corrected F32 on one · maximum | Corrected F32 on eight · maximum | +|---|---|---:|---:|---:|---:| +| 64 × 64 · 881021 | 0.34375 · off | 1 | 4,016/4,096 · 5.96046448e−08 | 4,096/4,096 · 0 | 3,992/4,096 · 5.96046448e−08 | +| 128 × 64 · 881153 | 0.6875 · off | 1 | 8,022/8,192 · 1.1920929e−07 | 8,192/8,192 · 0 | 7,973/8,192 · 5.96046448e−08 | +| 32 × 32 · 0 | 0.0 · off | 1 | 1,000/1,024 · 5.96046448e−08 | 1,024/1,024 · 0 | 1,004/1,024 · 5.96046448e−08 | +| 64 × 128 · 883903 | 0.8125 · on | 2 | 8,062/8,192 · 1.1920929e−07 | 8,062/8,192 · 1.1920929e−07 | 8,053/8,192 · 1.1920929e−07 | + +| Stored format | Earlier original on one · maximum | Corrected original on one · maximum | Corrected original on eight · maximum | Ordinary reopen on one · maximum | +|---|---:|---:|---:|---:| +| U8 | 13,312/13,312 · 0 | 13,312/13,312 · 0 | 13,312/13,312 · 0 | 13,312/13,312 · 0 | +| U16 | 13,311/13,312 · 1 | 13,312/13,312 · 0 | 13,309/13,312 · 1 | 13,312/13,312 · 0 | +| F16 | 13,312/13,312 · 0 | 13,312/13,312 · 0 | 13,312/13,312 · 0 | 13,312/13,312 · 0 | +| F32 | 21,100/21,504 · 1.1920929e−07 | 21,374/21,504 · 1.1920929e−07 | 21,022/21,504 · 1.1920929e−07 | 21,374/21,504 · 1.1920929e−07 | + +Across the 13 settings the original and its ordinary save each improved from 61,035/61,440 to 61,310/61,440 on one processor. Whole-image matches rose from eight to twelve. The 128 × 64 U16 output gained its final pixel. On eight processors the same original captures give 61,031/61,440 before and 60,955/61,440 after the change. Seven corrected images match completely. Setting tiling on the drawing node gives 60,949/61,440 on its separate eight-processor capture. The ordinary saved graph reproduced every local original buffer. + +For the reduced comparison use the two 64 × 64 and 128 × 64 settings above. Retain one complete quadrant tree through depth nine, remove the outer iteration, set its root branch offset to zero and use unit render and tiling regions. Draw at depths seven, eight and nine. First feed a 32² white procedural field to the fixed image slot with nearest filtering. Next use a solid analytic square at every draw. Finally restore the original procedural source and its bilinear filtering. Compare U16 and F32 in each case. The white image and analytic square give identical complete one-processor reference buffers at both sizes. + +| Reduced graph | Earlier F32 on one · maximum | Corrected F32 on one · maximum | Corrected F32 on eight · maximum | +|---|---:|---:|---:| +| White image, nearest | 11,919/12,288 · 1.1920929e−07 | 12,288/12,288 · 0 | 11,821/12,288 · 2.38418579e−07 | +| Analytic square | 12,288/12,288 · 0 | 12,288/12,288 · 0 | 11,813/12,288 · 2.38418579e−07 | +| Procedural image, bilinear | 12,019/12,288 · 1.1920929e−07 | 12,288/12,288 · 0 | 11,931/12,288 · 1.1920929e−07 | + +Each of the three reduced U16 series matches 12,288/12,288 on one processor. With automatic filtering on the procedural source, add the 32² seed-zero setting. F32 improved from 12,933/13,312 · 5.96046448e−08 to 13,312/13,312 · 0 on one processor. The eight-processor capture gives 12,840/13,312 · 5.96046448e−08. Maximum errors for integer formats are stored code values. Floating-point maxima are absolute differences. + +The evaluator now uses the existing subtree submission order when all drawing quadrants share a fixed image slot, filter and additive grayscale blend in one complete untiled depth-nine tree. Before the change the image draws followed traversal order. The normal cook regression uses a connected white image and signed overlapping draws on white. The earlier cook read zero at (8,0) and (0,16). Nearest, bilinear and automatic filtering now read 2⁻²⁵ at both locations. All 567 release node and evaluator tests passed, along with formatting, strict workspace Clippy, layer and WebAssembly checks. + +The later [two-tree comparison](#unfinished-draws-across-two-untiled-quadrant-trees) closes the 64 × 128 one-processor difference. Subsequent comparisons measure the same evaluator on the [60-setting panel with ordinary tiling](#fixed-image-draws-in-tiled-dirt-graphs). + +### Drawing parents and terminal children in Directional Noise 3 + +Directional Noise 3 now renders 52/60 distinct originals, up from 44. On the established [60-setting panel](#rectangular-and-additional-seed-coverage-in-directional-noise-3), the shared evaluator recovered eight originals at four geometries and all eight new ordinary saves. The 12-setting archive now has ten completed saves. At each setting below use the grayscale output, keep unlisted parameters at their defaults and compare the stored pixels. The controls column gives scale, disorder, angle, angle random and non-square expansion. Save normally and open the saved graph directly in both applications. + +| Dimensions · seed | Controls | Storage | One processor · maximum | Eight processors · maximum | Fresh ordinary save on one · maximum | +|---|---|---|---:|---:|---:| +| 64 × 32 · 103858 | 2, 0.6875, -0.21875, 0.40625, on | F32 | 2,044/2,048 · 2.61366367e−05 | 2,044/2,048 · 2.61366367e−05 | 2,044/2,048 · 2.61366367e−05 | +| 32 × 32 · 103860 | 3, 0.125, 0.375, 0.03125, off | F32 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| 64 × 64 · 411697 | 3, 0.34375, 0.09375, 0.34375, on | U8 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| 64 × 64 · 411697 | 3, 0.34375, 0.09375, 0.34375, on | U16 | 4,092/4,096 · 2 | 4,090/4,096 · 2 | 4,090/4,096 · 2 | +| 64 × 64 · 411697 | 3, 0.34375, 0.09375, 0.34375, on | F16 | 4,095/4,096 · 0.00048828125 | 4,094/4,096 · 0.00048828125 | 4,095/4,096 · 0.00048828125 | +| 64 × 64 · 411697 | 3, 0.34375, 0.09375, 0.34375, on | F32 | 4,092/4,096 · 2.66134739e−05 | 4,091/4,096 · 2.71201134e−05 | 4,087/4,096 · 2.66432762e−05 | +| 128 × 128 · 411880 | 3, 0.65625, 0.40625, 0.65625, off | U16 | 16,345/16,384 · 2 | 16,361/16,384 · 2 | 16,349/16,384 · 2 | +| 128 × 128 · 411880 | 3, 0.65625, 0.40625, 0.65625, off | F32 | 16,350/16,384 · 3.05473804e−05 | 16,356/16,384 · 2.87890434e−05 | 16,352/16,384 · 2.87890434e−05 | + +Reopen the four additional eligible archived settings on one processor. Every archived and freshly saved local raw buffer has the original local hash. + +| Archived dimensions · seed | Storage | Exact pixels · maximum | +|---|---|---:| +| 64 × 32 · 103858 | F32 | 2,045/2,048 · 2.61366367e−05 | +| 64 × 64 · 411697 | U16 | 4,089/4,096 · 2 | +| 128 × 128 · 411880 | F32 | 16,350/16,384 · 3.05473804e−05 | +| 128 × 512 · 412002 | F32 | 65,368/65,536 · 4.7326088e−05 | + +| All measured settings | Whole images exact / rendered | U8 exact pixels · maximum | U16 exact pixels · maximum | F16 exact pixels · maximum | F32 exact pixels · maximum | +|---|---:|---:|---:|---:|---:| +| Original on one processor | 16/52 | 85,248/85,248 · 0 | 296,916/297,728 · 3 | 87,282/87,296 · 0.00048828125 | 251,201/251,904 · 4.7326088e−05 | +| Original on eight processors | 18/52 | 85,247/85,248 · 1 | 296,951/297,728 · 3 | 87,282/87,296 · 0.00048828125 | 251,325/251,904 · 4.7326088e−05 | +| Archived ordinary save on one | 3/10 | 12,288/12,288 · 0 | 22,733/22,784 · 2 | — | 84,783/84,992 · 4.7326088e−05 | + +For a reduced work-count probe, keep the outer iteration and switch at the four geometries. Replace each deepest-stage tree by a single marker using separate unit random draws for its tint and rotation. Recover the seed from both values and propagate the authored seed offset of three through its four children at each subdivision. The 64 × 32 setting emits eight complete trees through depth ten. It visits 2,097,152 depth-nine parents with 645,344 distinct seeds, then 8,388,608 terminal children with 2,581,376 distinct seeds. The other three recovered settings emit nine trees each. + +The evaluator stores pure grayscale frame offsets, rotation and tint separately from constant stamp properties. It can reuse a drawing parent's properties while visiting its children in order. At 64 × 32 an intermediate build stopped with 1,838,058 full evaluations and 1,024,923 cached-draw credits still available. A cached parent that misses every pixel now uses the same bounded credit as a visible cached parent. The evaluator retains the 5,242,880 full-evaluation limit. The remaining 64 × 16 seed 42 and 64 × 32 seed 195031 cases emit sixteen and eighteen trees. Across depths their distinct seed counts alone are 6,275,400 and 6,785,426. Their earlier F32 failures and three outstanding companion formats per geometry remain open. + +For an independent original graph, follow seven empty quadrants with 160 outer and 224 inner iterations. Each draws a paraboloid parent and four paraboloid children with maximum blending. Set parent and child sizes to (96,80) and (24,32). Use independent random grayscale tints up to .875, rotations up to .375 turns and two frame-offset components from −.03125 to .03125. Compare seeds 19 at 16² and 113 at 32 × 16 in U8, U16, F16 and F32 and repeat after an ordinary save. All 6,144 pixels match, maximum zero. The earlier fixed-image parent/child controls match a further 6,144/6,144. All 96 earlier connected-image controls also reproduce their prior raw hashes and maximum errors. + +Four alternating cold-process runs on the previously completed 128 × 512 F32 reference setting, seed 412002, produced the same raw output, 65,377/65,536 on one processor, maximum 4.73260880e−05. Two runs per build averaged 62.17 s before and 41.88 s after the change. Maximum process working sets were 182.8 and 243.2 MiB respectively. All 566 node and evaluator release tests passed, along with formatting, workspace Clippy, layers and WebAssembly checks. + +### Five individual image draws at one Dirt 1 pixel + +Use the [128 × 256 Dirt 1 setting](#individual-drawing-depths-at-a-dirt-1-rounding-boundary). Keep the 32² procedural source, the selected image, bilinear sampling, the original sizes, positions and seed. At each drawing depth keep the original computed grayscale tint when it equals the selected F32 tint below. Return zero for the other draws. Match coordinates from the top left. The child slots in each path run from the first quadrant of the first emitted tree and start at zero. + +| Local draw index | Depth | Child slots | Selected F32 tint | Contribution at (59,61) | +|---:|---:|---|---:|---:| +| 0 | 8 | `01031122` | 1.560014009 | 0.06977591664 | +| 1 | 7 | `0110230` | 1.792800069 | 0.2156563848 | +| 2 | 8 | `01132233` | 1.930725455 | 0.09658035636 | +| 3 | 8 | `10000201` | 1.953956962 | 0.1880335808 | +| 4 | 9 | `100002011` | 1.113133669 | 0.05112567171 | + +Each of the five selections has one nonzero pixel. Each matches 32,768/32,768 F32 pixels, maximum zero. Keeping all five gives 32,767/32,768, maximum 5.96046448e−08. Apply the signed multipliers in local draw-index order to the five selected tints. All multipliers are powers of two with sign. The last two settings independently check the order determined by the first three. + +| Setting | Multipliers in local order | MaterialCraft at (59,61) | One-processor reference | Exact F32 pixels | Maximum error | +|---|---|---:|---:|---:|---:| +| Measurement 1 | -0.015625, 0.0625, -0.5, -2, 8 | -0.00296369195 | -0.002963688225 | 32,767/32,768 | 3.7252903e-09 | +| Measurement 2 | -1, -4, -0.03125, -0.03125, 16 | -0.123284936 | -0.1232849285 | 32,767/32,768 | 7.4505806e-09 | +| Measurement 3 | -0.125, 0.5, -0.0625, -0.03125, -0.25 | 0.07441245764 | 0.07441245764 | 32,768/32,768 | 0 | +| Independent check 1 | -0.5, -0.0625, -32, 8, -0.015625 | -1.635468125 | -1.635468006 | 32,767/32,768 | 1.1920929e-07 | +| Independent check 2 | 4, 0.25, -16, -0.25, -2 | -1.361527562 | -1.361527681 | 32,767/32,768 | 1.1920929e-07 | + +Enumerating all 120 permutations with an F32 addition after every draw leaves indices 3 and 4 first, then 0, 1 and 2. The first pair can exchange places on a zero background. Both independent settings give the predicted reference result. The second independent setting also reproduces the reference value on eight processors and after a normal save on both processor counts. + +On the unsigned five-draw selection, compare U8, U16, F16 and F32 on one and eight processors for the original and its ordinary save. U8 and F16 each match 32,768/32,768 on all four comparisons, maximum zero. F32 gives 32,767/32,768 on all four, maximum 5.96046448e−08. U16 gives 32,767/32,768, maximum one, on both originals and the one-processor save. The eight-processor save matches all 32,768, maximum zero. Every local save reproduces the original local raw buffer. + +A trial replay used the existing order for a single analytic tree with depth-seven parents and two full drawing levels below them. That order reproduces all five measured draw positions after allowing the first pair to exchange places. For a separate check on the unmodified image, retain each of the sixteen first-two-slot combinations in turn to identify the origins of sampled contributions. Sample every invariant F32 mismatch from the seven reads and up to 384 locations from each of three other classes using sampling seed 2343. Of 1,204 sampled locations, 883 had a unique order under that replay. At the 361 with invariant reference values, 330/361 match in the current renderer and 359/361 in the trial. Among the remaining 522 the one-processor score rose from 279 to 476 and the eight-processor score fell from 309 to 183. The two remaining invariant differences and the behavior across other trees are open. + +### Individual drawing depths at a Dirt 1 rounding boundary + +Revision `3f984f7` reproduced the [complete Dirt 1 and Dirt 2 comparison](#complete-render-coverage-for-the-two-fixed-image-dirt-graphs) on the same release binary. For each graph the 58 earlier originals and 11 earlier ordinary saves reproduced their local raw hashes. The two remaining originals and the remaining archived save were already measured on this binary. All 144 original and reopened results have the exact counts and maximum errors previously recorded. + +Open Noise Dirt 1 at 128 × 256, seed 433665, scale 1, disorder .8125 and non-square expansion enabled. Leave other parameters at their defaults. Render U16 and F32 twice on one and eight processors, reversing their format order for the second pair. Save normally, open that file in both applications and render both formats on one processor. Include the two earlier originals for seven reference reads of each format. + +In U16, six comparisons give 32,764/32,768 exact pixels and the archived eight-processor comparison gives 32,762/32,768. Each maximum is one code. Of the 32,764 locations with the same reference code in every read, MaterialCraft matches 32,762. The stable differences are at (59,61) and (42,230). All 32,768 local U16 codes agree with conversion from local F32. The original and normal save give identical local buffers in both formats. In F32, 31,145 pixels are invariant across the seven reads and 31,093 of those match. + +To isolate (59,61), keep the procedural 32² source and the outer iteration, switch, branch offsets, sizes and seed streams. Silence excluded drawing levels individually with a literal zero grayscale tint. Use the same F32 format and one processor for each graph. The unmodified control matches all 32,768 pixels of the original reference capture, maximum zero. + +| Active depths | Exact pixels | Maximum error | MaterialCraft at (59,61) | Reference at (59,61) | +|---|---:|---:|---:|---:| +| 7 | 32,726/32,768 | 5.96046448e-08 | 0.2156563848 | 0.2156563848 | +| 8 | 32,717/32,768 | 5.96046448e-08 | 0.3543898463 | 0.3543898463 | +| 9 | 32,726/32,768 | 2.98023224e-08 | 0.05112567171 | 0.05112567171 | +| 7 and 8 | 32,499/32,768 | 1.1920929e-07 | 0.5700462461 | 0.5700461864 | +| 7, 8 and 9 | 32,050/32,768 | 1.1920929e-07 | 0.6211718917 | 0.6211719513 | + +At (59,61), each isolated level agrees exactly. The whole graph yields 40,708 in MaterialCraft and 40,709 on all seven U16 reference reads. Adding the three separate F32 level images in each of the six possible orders gives .6211718917 here. Taking the reference image for levels seven and eight together, then adding level nine, gives .6211718321. The whole reference result is .6211719513. Recovering the order of individual overlapping draws remains open. + +### Complete render coverage for the two fixed-image Dirt graphs + +Noise Dirt 1 and Noise Dirt 2 each now render all 60 originals and all 12 ordinary saves in their established series. Repeat the [two scale-3 rectangles](#expanded-image-and-save-comparisons-for-dirt-1-and-dirt-2) at 128 × 32. Use disorder .046875, non-square expansion on and all other controls at their defaults. Run each in U16 and F32. Save each graph normally and open the saved file directly in both applications. Also repeat the F32 comparison on the earlier ordinary save. + +| Root · seed · storage | One processor · maximum | Eight processors · maximum | Fresh ordinary save, one processor · maximum | Earlier ordinary save, one processor · maximum | +|---|---:|---:|---:|---:| +| Noise Dirt 1 · 433517 · U16 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | — | +| Noise Dirt 1 · 433517 · F32 | 4,009/4,096 · 5.96046448e−08 | 4,009/4,096 · 5.96046448e−08 | 4,010/4,096 · 5.96046448e−08 | 4,010/4,096 · 5.96046448e−08 | +| Noise Dirt 2 · 433543 · U16 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | — | +| Noise Dirt 2 · 433543 · F32 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | + +| Across the recorded passes | Whole images exact / rendered | Exact pixels / compared | +|---|---:|---:| +| Noise Dirt 1 · one processor | 30/60 | 779,410/785,664 | +| Noise Dirt 1 · eight processors | 33/60 | 780,626/785,664 | +| Noise Dirt 1 · archived ordinary saves on one | 6/12 | 147,509/149,504 | +| Noise Dirt 2 · one processor | 50/60 | 785,652/785,664 | +| Noise Dirt 2 · eight processors | 53/60 | 785,655/785,664 | +| Noise Dirt 2 · archived ordinary saves on one | 10/12 | 149,502/149,504 | + +The two final Dirt 2 images are identical across both processor counts and MaterialCraft. Over all 60 settings the one- and eight-processor results differ on 21 pixels. MaterialCraft matches every one of the 785,643 invariant values, and matches one observed value at each of the other 21 pixels. Both roots retain their per-processor differences. + +In the Dirt 2 rectangle replace the first quadrant and its descendants with a marker under the original outer iteration and switch. Independently draw one unit random value for its tint and rotation and trace the 36 emitted pairs. The two [property streams](../crates/nodes/src/random.rs) distinguish the 24-bit incoming seed for each tree. Expanding the unchanged four child slots through depth nine gives 9,437,184 leaf visits but only 1,499,404 distinct leaf seeds. The earlier evaluator recalculated every image leaf. It exceeded the 5,242,880 full-evaluation allowance before producing either rectangle. + +A terminal grayscale image draw can reuse its properties when only its branch offset, size and tint vary with its seed, depth and immutable graph inputs. The shared evaluator retains the fixed slot, filter and other properties. Dense streams retain the five changing floats in lazily allocated pages with a 64 MiB payload ceiling. A parent quadrant schedules at most four terminal children, bounding their cached reads when a streamed group releases their storage. The existing allowances still bound full property evaluations, direct repetitions, extra tile copies and pixel visits. + +For an independent comparison use the [32² procedural image source](#streaming-deep-quadrants-that-draw-the-same-connected-image). After seven empty quadrants use 160 outer and 224 inner iterations. Each draws one fixed image stamp and four child stamps, for 35,840 parents and 143,360 children. Use maximum blending, fixed bilinear filtering and inherited seeds. For both drawing nodes sample independent uniform values for tint in [0,.875), size in [32,96) × [24,72), and branch offset components in [−.03125,.03125). Use seeds 19 at 16² and 113 at 32 × 16, across U8, U16, F16 and F32. All 16 original and ordinarily saved buffers reproduce the earlier release. All 6,144 pixels match the reference, maximum zero. The [96 connected image controls](#streaming-deep-quadrants-that-draw-the-same-connected-image) also reproduced every prior local raw hash and per-format comparison. A separate 4² regression with a nonzero fixed image slot failed on the preceding release. It compares the result of the same parent and four children at two traversal budgets. + +On the separate Dirt 2 32 × 16 F32 setting at seed 42, start four fresh single-worker release processes in old, new, new, old order. All four raw hashes agree. Mean reported cook time was 28.32 seconds before and 16.42 seconds after. Maximum process peak working set was 182.5 MiB before and 217.7 MiB after. All 564 node and evaluator release tests passed, along with formatting, strict workspace Clippy, layer checks and WebAssembly. + +### Expanded image and save comparisons for Dirt 1 and Dirt 2 + +Repeat the [Dirt 1 settings](#whole-renders-and-reopened-settings-for-two-dirt-noise-generators) and the [Dirt 2 settings](#whole-outputs-and-saved-settings-for-noise-dirt-2-and-noise-dirt-3) that previously stopped at an execution guard. Evaluate one F32 image first at each distinct geometry where available. If it returns pixels, run its other requested formats. Reopen the previously saved SBS at each recovered setting in the 12-case handoff series. The table combines unchanged historical measurements with 24 newly rendered originals and three existing ordinary saves per graph on revision `9e0d6fd`. The [additional freshly saved comparisons](#streaming-deep-quadrants-that-draw-the-same-connected-image) are recorded separately. + +| Root · comparison | Whole images exact / rendered | U8 exact / total · maximum | U16 exact / total · maximum | F16 exact / total · maximum | F32 exact / total · maximum | +|---|---:|---:|---:|---:|---:| +| Noise Dirt 1 · one processor | 29/58 | 99,840/99,840 · 0 | 334,828/334,848 · 1 | 101,888/101,888 · 0 | 234,749/240,896 · 1.1920929e−07 | +| Noise Dirt 1 · eight processors | 32/58 | 99,840/99,840 · 0 | 334,833/334,848 · 1 | 101,888/101,888 · 0 | 235,960/240,896 · 1.1920929e−07 | +| Noise Dirt 1 · ordinary save on one | 6/11 | 26,624/26,624 · 0 | 51,707/51,712 · 1 | — | 65,168/67,072 · 1.1920929e−07 | +| Noise Dirt 2 · one processor | 48/58 | 99,840/99,840 · 0 | 334,840/334,848 · 2 | 101,887/101,888 · 6.10351562e−05 | 240,893/240,896 · 2.52053142e−05 | +| Noise Dirt 2 · eight processors | 51/58 | 99,840/99,840 · 0 | 334,843/334,848 · 2 | 101,887/101,888 · 0.000122070312 | 240,893/240,896 · 2.52090394e−05 | +| Noise Dirt 2 · ordinary save on one | 9/11 | 26,624/26,624 · 0 | 51,711/51,712 · 2 | — | 67,071/67,072 · 2.52053142e−05 | + +Both graphs have rendered 58/60 originals and 11/12 archived ordinary saves. At 128 × 32 set scale 3, disorder .046875 and non-square expansion on. Use seeds 433517 for Dirt 1 and 433543 for Dirt 2. F32 exhausts the evaluation allowance. Its U16 sibling is deferred. A disposable marker in place of the first drawing tree, preserving the outer iteration and switch, emits 36 times for each graph. Each original tree has 349,525 quadrants through depth nine, giving 12,582,900 visits, including 9,437,184 terminal image draws. The 256 × 128 and 512 × 128 controls emit nine and four trees, respectively. Both controls now render. + +For Noise Dirt 2, the two reference worker counts disagree at precisely 21 pixels across the 777,472 compared. Twelve MaterialCraft pixels differ from the one-processor captures and nine from eight processors. The sets are disjoint in every frame. This establishes agreement on every pixel where the two captures have an identical stored value. + +For Noise Dirt 1 at 128², seed 42 and default parameters, both archived U16 captures differed from MaterialCraft by one code at (35,89). Repeat the U16 and F32 outputs twice at one and eight processors, reversing the format order once on each processor count. Open the ordinary save and repeat on one processor. At that pixel the one-processor originals and save give .44903564453125 and 29,428. The fresh eight-processor originals and MaterialCraft give .4490356147289276 and 29,427. Each F32 value gives the corresponding U16 code using the existing output conversion. Across the seven U16 captures, 16,382/16,384 pixel locations are invariant, and MaterialCraft matches every invariant value. Each individual comparison is 16,383/16,384, maximum one. Both local original and saved frames have identical raw buffers. + +### Streaming deep quadrants that draw the same connected image + +Noise Dirt 1 and Noise Dirt 2 can now render previously blocked whole graphs that draw an upstream grayscale pattern through a fixed image slot. Each 32 × 16 setting below traverses eight full quadtrees with ten quadrant levels, or 2,796,200 quadrant visits. Only depths seven through nine draw the connected image. All three use slot zero, bilinear filtering and additive blending. The same evaluator checks that the drawing quadrants have equal raster order before it submits successive groups. Each group uses the same F32 output and the same bounded cache of reduced source images. + +| Original setting | One processor · maximum | Eight processors · maximum | Ordinary save on one · maximum | +|---|---:|---:|---:| +| Noise Dirt 1, scale 2, disorder .8125, non-square expansion on, seed 105430, F32 | 500/512 · 1.19209290e−7 | 502/512 · 5.96046448e−8 | 500/512 · 5.96046448e−8 | +| Noise Dirt 2, scale 2, disorder .21875, non-square expansion on, seed 42, U16 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| Same Dirt 2 setting, F32 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | + +Leave other parameters at their defaults. In both applications open each ordinary save directly. Each local saved render reproduced the original raw output. At 32 × 16, seed 105447, the Dirt 1 v2 setting still reached the traversal guard. Use the same exposed settings as Dirt 1 above and set disorder speed to 1.4375, anisotropy amount to .625, anisotropy angle to −.21875 and tile offset to (−.3125,.4375). Its graph adds an iteration at depth seven. + +In the [earlier 34 Dirt 2 renders](#whole-outputs-and-saved-settings-for-noise-dirt-2-and-noise-dirt-3), all 512,256 MaterialCraft pixels matched at least one of the one- and eight-processor reference values. The nine pixels differing from the one-processor reference and the five differing from the eight-processor reference are disjoint. The two reference images differ on exactly 14 pixels across those settings. Each processor count retains its own exact-match score. + +For a separate input test, start with seven empty quadrants, then 80 outer and 70 inner iterations drawing two overlapping image stamps. Select fixed slot zero as a generic image and as packed image 256. Use sizes (96,80) and (24,32), tints 2⁻¹³ and −2⁻¹⁴, gray background .125, unit opacity and disabled tiling. Run seeds 19 at 16² and 113 at 32 × 16, each at U8, U16, F16 and F32. Repeat with automatic, bilinear and nearest filtering and save normally. + +| Source for the two stamps | Filtering | Original and reopened exact pixels | Maximum error | +|---|---|---:|---| +| Independent 32² procedural grayscale pattern | Automatic, bilinear and nearest | 18,432/18,432 | 0 | +| External 32² grayscale U8 field | Bilinear and nearest | 12,288/12,288 | 0 | +| Same external field | Automatic | 5,964/6,144 | 0 U8 · 7,395 U16 · .113037109 F16 · .112834156 F32 | + +For the procedural source, start at gray .125 and draw a paraboloid of size (.921875,.6875), rotation .125 and tint .75. Connect two child squares in slots zero and three, each of size (.125,1), rotation −.0625 and tint .25. Use its ordinary SBS save as the input for the first capture, then save and reopen again. For the external U8 field use (13x + 29y + 7xy + 17) modulo 256. All 96 local buffers matched their earlier local raw hashes, including the six differing automatic-filter captures at 16². A small-budget regression compares three image filters across chunk boundaries and checks the different-filter ordering guard. It exhausted the traversal budget before the change. + +### Accounting for a streamed draw and its tile copies + +Directional Noise 3 now renders both 128 × 512 at seed 412002 and 512 × 128 at seed 412063 in U16 and F32. Set scale, disorder, angle, angle random and non-square expansion to (2, .53125, .28125, .53125, off) and (1, .09375, −.15625, .09375, on) respectively. Keep other exposed parameters at their defaults. Save normally and open each resulting file directly in both applications. Each saved MaterialCraft output is bit-identical to its original. + +| Dimensions · storage | One processor · maximum | Eight processors · maximum | Ordinary save on one · maximum | +|---|---:|---:|---:| +| 128 × 512 · U16 | 65,368/65,536 · 3 | 65,363/65,536 · 3 | 65,371/65,536 · 2 | +| 128 × 512 · F32 | 65,377/65,536 · 4.7326088e−05 | 65,386/65,536 · 4.7326088e−05 | 65,380/65,536 · 4.7326088e−05 | +| 512 × 128 · U16 | 65,307/65,536 · 2 | 65,284/65,536 · 2 | 65,330/65,536 · 2 | +| 512 × 128 · F32 | 65,306/65,536 · 3.0785799e−05 | 65,342/65,536 · 3.0785799e−05 | 65,338/65,536 · 3.0785799e−05 | + +Together with the [40 earlier renders](#rectangular-and-additional-seed-coverage-in-directional-noise-3), this gives measured outputs for 44 of 60 whole settings. Six F32 attempts reached the traversal limit in the earlier panel and ten sibling-format cases are still deferred. + +Both rectangular F32 settings exhausted the tile-copy allowance on revision `7780885`. A streamed stamp has already paid for its visit. Charging only its additional copies moved both failures to the traversal limit. Full stamp-property evaluations already consume a separate cook-wide allowance. Releasing their retained storage after rasterization now returns their traversal credit. Stamps whose evaluations came from the cache draw on a bounded allowance of their own. Pixel work, extra tile copies and full evaluations remain bounded across all chunks. + +For a small tile-count regression, use seven empty quadrants, then four iterations of 21 additive squares. At depth seven use size (12,483 × 128, 32), frame offset (0,.25), overall opacity one, tint .01, full tiling and a 4² image. Each of the 84 draws has 12,484 horizontal copies. The original copy charge rejected it. The shared raster now handles its 1,048,572 extra copies. Increasing the width to 12,485 × 128 still exceeds the 1,048,576 extra-copy allowance. In the separate square accumulation regression, 12 iterations of 24 full-coverage squares now match the 288 successive F32 additions at a traversal allowance of 64. Twenty iterations of 24 exceed the full-evaluation allowance. + +Repeat the [grayscale and RGBA chunk controls](#streaming-equal-ranked-analytic-stamps-through-one-output-image). Add two grayscale variants with first and second square sizes (1,536,64) and (512,96). Use horizontal tiling in unit render and tiling windows for the first. Enable both axes with render window (.125,.75,.25,.875) and tiling window (−.125,.875,−.25,.75) for the second. Across 80 original and ordinarily reopened buffers at two sizes and four stored formats, all 30,720 pixels matched the reference and the previous release, maximum zero. + +### Counting terminal draws in the two remaining clouds variants + +For Noise Clouds 1 v2 and Noise Clouds 2 v2, the 64 × 32 F32 panel setting still exceeds the traversal limit. Use scale 5, disorder .8125, disorder speed 1.4375, disorder anisotropy .625, its angle −.21875, tile offset (−.3125, .4375), non-square expansion on and the seeds below. In a disposable diagnostic keep the original outer switch, quadrant seeds and depth-seven iteration. Each comparison below retains one of the four original first-level child slots, preserving its slot identifier. Replace each depth-seven drawing quadrant after the iterate with a childless marker. Count the emitted markers from the evaluation trace. The removed children only publish a frame offset. The iteration count reads the graph anisotropy input and its own random stream. This diagnostic counts MaterialCraft visits. + +| Graph · seed | Depth-seven marker counts by original slot | Connected terminal children per marker | Combined drawing visits at depths seven and eight | +|---|---|---:|---:| +| Noise Clouds 1 v2 · 103034 | 524,700, 524,330, 524,492, 524,584 | 4 | 10,490,530 | +| Noise Clouds 2 v2 · 103056 | 609,358, 609,398, 609,706, 609,518 | 2 | 7,313,940 | + +The terminal tint writes the frame offset and reads the current iteration and its fade. The measured draw counts already exceed the 5,242,880 full property-evaluation allowance before the ancestor visits. Simply changing how retained stamps are charged cannot recover these settings. + +### Rectangular and additional seed coverage in Directional Noise 3 + +Revision `7780885` produced 40 different original outputs in the 60-setting panel. Eight attempted F32 cases reached a guard. Twelve additional storage choices on six of those geometries were deferred. In the 40 completed cases, 407,151/407,808 pixels matched on one processor and 407,274/407,808 on eight. Fourteen and sixteen whole buffers respectively were exact. The counts include the [first 19 settings](#streaming-equal-ranked-analytic-stamps-through-one-output-image). + +| Original storage | Completed | One processor · maximum | Eight processors · maximum | +|---|---:|---:|---:| +| U8 | 6 | 81,152/81,152 · 0 | 81,151/81,152 · 1 | +| U16 | 14 | 145,804/146,176 · 2 | 145,853/146,176 · 3 | +| F16 | 7 | 83,187/83,200 · 0.00048828125 | 83,188/83,200 · 0.00048828125 | +| F32 | 13 | 97,008/97,280 · 3.2350421e−05 | 97,082/97,280 · 3.2350421e−05 | + +For the remaining 41 comparisons, use the settings below and the grayscale output, with every omitted field at its default. Test F32 first on each geometry. A limit in the table was reached by MaterialCraft before pixel comparison. An integer maximum is a stored level. A dash in the parameter column uses unmodified defaults. Otherwise the tuple gives (scale, disorder, angle, angle random, non-square expansion). + +| Dimensions · seed | Parameters | Completed storage | F32 result on one · maximum | F32 result on eight · maximum | Storage deferred | +|---|---|---|---:|---:|---| +| 16 × 16 · 0 | — | U8, U16, F16, F32 | 256/256 · 0 | 256/256 · 0 | — | +| 64 × 16 · 42 | (2, 0.03125, -0.21875, 0.03125, on) | — | Traversal limit | Traversal limit | U8, U16, F16 | +| 16 × 64 · 411636 | (1, 0.875, 0.625, 0.875, off) | U16, F32 | 1,021/1,024 · 2.66432762e−05 | 1,023/1,024 · 2.48551369e−05 | — | +| 64 × 64 · 411697 | (3, 0.34375, 0.09375, 0.34375, on) | — | Traversal limit | Traversal limit | U8, U16, F16 | +| 128 × 64 · 411758 | (2, 0.96875, 0.71875, 0.96875, off) | U16, F32 | 8,163/8,192 · 2.59876251e−05 | 8,178/8,192 · 2.59876251e−05 | — | +| 64 × 128 · 411819 | (1, 0.1875, -0.0625, 0.1875, on) | U8, U16, F16, F32 | 8,171/8,192 · 2.84612179e−05 | 8,170/8,192 · 2.70605087e−05 | — | +| 128 × 128 · 411880 | (3, 0.65625, 0.40625, 0.65625, off) | — | Traversal limit | Traversal limit | U16 | +| 256 × 256 · 0 | — | U8, F16, F32 | 65,371/65,536 · 3.2350421e−05 | 65,397/65,536 · 3.2350421e−05 | — | +| 128 × 512 · 412002 | (2, 0.53125, 0.28125, 0.53125, off) | — | Tile-copy limit | Tile-copy limit | U16 | +| 512 × 128 · 412063 | (1, 0.09375, -0.15625, 0.09375, on) | — | Tile-copy limit | Tile-copy limit | U16 | +| 16 × 32 · 194984 | — | U16, F32 | 512/512 · 0 | 512/512 · 0 | — | +| 64 × 32 · 195031 | (3, 0.34375, 0.09375, 0.34375, on) | — | Traversal limit | Traversal limit | U8, U16, F16 | +| 32 × 64 · 195078 | (1, 0.1875, -0.0625, 0.1875, on) | U8, U16, F16, F32 | 2,042/2,048 · 2.55703926e−05 | 2,045/2,048 · 2.48551369e−05 | — | +| 64 × 64 · 195125 | (2, 0.53125, 0.28125, 0.53125, off) | U16, F32 | 4,089/4,096 · 2.67624855e−05 | 4,091/4,096 · 2.54511833e−05 | — | + +Six members of the 12-setting ordinary-save panel had completed originals. Open their existing MaterialCraft saves directly in each application and read the one-processor reference. All six saved MaterialCraft buffers reproduced their original raw hashes. + +| Saved dimensions · seed | Storage | Exact pixels · maximum | +|---|---|---:| +| 128 × 128 · 0 | U16 | 16,342/16,384 · 2 | +| 64 × 64 · 42 | U8 | 4,096/4,096 · 0 | +| 32 × 32 · 103853 | F32 | 1,020/1,024 · 2.70307064e−05 | +| 16 × 16 · 0 | U16 | 256/256 · 0 | +| 64 × 128 · 411819 | U8 | 8,192/8,192 · 0 | +| 32 × 64 · 195078 | U16 | 2,046/2,048 · 2 | + +The six saves matched 31,952/32,000 pixels in total. The [two additional U16 saves at seed zero](#streaming-equal-ranked-analytic-stamps-through-one-output-image) cover the 256² default and the changed 128² geometry. + +### Streaming equal-ranked analytic stamps through one output image + +Directional Noise 3 now renders 17 of the first 19 established whole-graph settings. Revision `3d3aec1` rendered 15 of those 19. The two recovered settings both use seed zero and U16. For the changed setting, set scale to 2, disorder to .37, angle to .125 and angle random to .2. Leave every other exposed parameter at its default. Save each setting normally, reopen it directly in both applications and capture the one-processor reference again. Each saved file gave the same raw MaterialCraft output as its source. [Earlier whole-graph comparison](#reused-properties-across-adjacent-groups-of-terminal-quadrants) + +| Recovered setting | Original on one · maximum | Original on eight · maximum | Ordinary save on one · maximum | +|---|---:|---:|---:| +| 256², defaults | 65,371/65,536 · 2 | 65,406/65,536 · 3 | 65,358/65,536 · 3 | +| 128², changed | 16,345/16,384 · 2 | 16,350/16,384 · 2 | 16,339/16,384 · 2 | + +Recook all 19 starting settings. At both processor counts, compare to the raw output at the requested storage precision. All eight settings recovered in the previous evaluator change kept their raw MaterialCraft pixels. The remaining F32 settings that exceed the execution budget are 64 × 32, seed 103858, and 32², seed 103860. For the first, use scale 2, disorder .6875, non-square expansion on, angle −.21875 and angle random .40625. For the second, use scale 3, disorder .125, non-square expansion off, angle .375 and angle random .03125. + +| Storage | Completed settings | One processor · maximum | Eight processors · maximum | +|---|---:|---:|---:| +| U8 | 2 | 5,120/5,120 · 0 | 5,120/5,120 · 0 | +| U16 | 7 | 121,539/121,856 · 2 | 121,590/121,856 · 3 | +| F16 | 3 | 7,167/7,168 · 0.000244140625 | 7,168/7,168 · 0 | +| F32 | 5 | 7,383/7,424 · 2.7358532e−05 | 7,410/7,424 · 2.65836716e−05 | + +Across those 17 completed outputs, 141,209/141,568 pixels matched on one processor and 141,288/141,568 on eight. Five and six whole buffers respectively were exact. + +The shared evaluator can composite deep analytic draws in chunks once it has ruled out every subtree ordering and verified a single draw rank throughout the reachable graph. A chunk retains the F32 output image for the next chunk. Pixel and tile-copy work is counted across the entire render. Released draws receive bounded credit against the traversal and copy limits. The regression uses seven empty quadrants followed by two nested iterations. Four outer iterations of 24 additive full-coverage squares agree bit-for-bit at work allowances of 64 and 256. The earlier evaluator rejected the allowance of 64. Twelve outer iterations still exceed that allowance. + +For the independent depth and storage control, attach 80 × 70 iterations beneath seven empty quadrants. Each iteration emits two successive square quadrants, the second on the first child slot of the first. Disable tiling. Use a .125 background, roughness zero, opacity one, sizes (512,512) for both squares and scalar tint expressions 2⁻¹³ and −2⁻¹⁴. In the second graph use (128,128) for the child. For the RGBA control use that smaller child and swatches (.25,.5,.75,2⁻¹³) and (.75,.25,.5,2⁻¹⁴). In each graph render 16² with seed 19 and 32 × 16 with seed 113 in U8, U16, F16 and F32. Reopen ordinary saves in both applications. The grayscale graphs matched 12,288/12,288 pixels and the RGBA graph matched 6,144/6,144 against the reference and the prior release. Maximum error was zero across all 48 buffers. + +On the 128² default, alternate the earlier and changed single-worker release runners in A/B/B/A order, starting each cook in a new process. All four raw buffers were identical. Median process peak working set was 232.5 MiB before and 184.4 MiB after, a reduction of 20.7%. Median cook durations were 15.13 s and 15.17 s. + +### Two depth-seven draws at a stored rounding boundary + +At (30,57) in Noise BNW Spots 3, the two applications evaluate both contributing stamps to exactly the same F32 values. The order of their additions explains the one-level U16 difference. Use 64², scale 2, disorder .37, seed 42 and the other exposed defaults. Read the deep pattern directly with F32 storage. Its background is .5. Keep the pattern geometry and set the tints to zero on the depths outside the group under test. [Original and repeated whole-graph observations](#reusing-terminal-quadrant-properties-in-dense-rectangular-renders) + +| Active drawing depths | MaterialCraft at (30,57) | One-processor reference at (30,57) | Exact F32 pixels · maximum | +|---|---:|---:|---:| +| 6–9 | .4972076416015625 | .4972076117992401 | 3,586/4,096 · 1.19209290e−7 | +| 6 and 7 | .4972076416015625 | .4972076117992401 | 3,918/4,096 · 1.19209290e−7 | +| 8 and 9 | .5 | .5 | 3,831/4,096 · 1.19209290e−7 | +| 6 alone | .5 | .5 | 4,036/4,096 · 5.96046448e−8 | +| 7 alone | .4972076416015625 | .4972076117992401 | 4,042/4,096 · 5.96046448e−8 | + +On depth seven only, set the background to zero and replace its tint expression T in turn with max(T,0) and min(T,0). At the same pixel both applications produced +.00044396534212864935 and −.0032363433856517076. The positive control matched 4,091/4,096 and the negative control 4,087/4,096 across the full image, maximum 1.49011612e−8 in both. Starting at .5 and rounding each F32 add, positive first gives .4972076416015625, which stores as 32,585. Negative first gives .4972076117992401, which stores as 32,584. Applying the existing U16 storage rule to the F32 reference also reproduced all 4,092 invariant deep-stage U16 pixels in this setting and all 16,380 at the 128² default. + +Alternate seeds 42 and 43 between reads and compare only seed 42. The depth-seven pixel took the lower value in all five one-processor reads. On eight processors three reads gave the higher value and one the lower. There are 184 pixels with exactly two contributions whose order changes the result. On one processor, 123 consistently followed traversal, 11 consistently reversed it and 50 changed between reads. On eight, the counts were 87, 3 and 94. All the results at these pixels equal one of the two measured orders. Reversing the four root-child groups within each tree would improve the first capture by ten pixels but reduce agreement on the 3,996 invariant single-processor pixels from 3,979 to 3,977. The production renderer keeps the existing ordering. + +### Rectangular dirt-family settings recovered by the shared evaluator + +Revision `3d3aec1` renders seven previously blocked F32 settings in the next eleven open Dirt-family roots. Use the dimensions, seeds and parameters below, with all other exposed parameters at their defaults. Read the raw grayscale output. Save the graph normally in MaterialCraft and reopen the saved file directly in both applications for the last comparison. + +| Noise package | Dimensions · seed | Changed parameters | One processor · max | Eight processors · max | Ordinary save on one · max | +|---|---|---|---:|---:|---:| +| Dirt 3 | 128 × 32 · 433556 | scale 3, disorder 0.046875, non square expansion on | 4,067/4,096 · 5.96046448e−08 | 4,060/4,096 · 2.98023224e−08 | 4,065/4,096 · 5.96046448e−08 | +| Dirt 4 | 16 × 32 · 0 | Defaults | 512/512 · 0 | 491/512 · 5.34057617e−05 | 512/512 · 0 | +| Dirt 4 v2 | 16 × 32 · 299582 | Defaults | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| Dirt 5 | 32 × 16 · 42 | scale 2, disorder 0.21875, non square expansion on | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | +| Dirt 5 v2 | 32 × 16 · 42 | scale 2, disorder 0.21875, disorder speed 0.21875, disorder anisotropy 0.21875, disorder anisotropy angle -0.03125, tile offset (-0.125, 0.21484375), non square expansion on | 457/512 · 5.96046448e−08 | 457/512 · 2.98023224e−08 | 459/512 · 5.96046448e−08 | +| Dirt Gradient | 512 × 128 · 433856 | disorder 0.671875, non square expansion on | 65,520/65,536 · 1.52587891e−05 | 65,517/65,536 · 1.52587891e−05 | 65,517/65,536 · 1.52587891e−05 | +| Dirt Gradient v2 | 32 × 16 · 42 | disorder 0.21875, disorder speed 0.21875, disorder anisotropy 0.21875, disorder anisotropy angle -0.03125, non square expansion on | 361/512 · 2.98023224e−07 | 381/512 · 1.78813934e−07 | 357/512 · 2.98023224e−07 | + +Dirt 3 and Dirt Gradient each had two established rectangular settings left without an output. The U16 companion at 128 × 32, seed 433556, matches all 4,096 pixels on both processor counts. At 512 × 128, seed 433856, the U16 Dirt Gradient companion matches 65,520/65,536 on one and 65,510/65,536 on eight, both within one level. Together with the earlier 58 renders for each graph, all 60 established originals in both graphs now have measured outputs. [Earlier Dirt 3 settings](#compositing-a-single-seven-level-tree-through-pattern-controls) · [Earlier Dirt Gradient settings](#sixty-whole-settings-for-three-directional-and-dirt-noise-packages) + +The same release still exceeded its execution budget for the following F32 settings. + +| Noise package | Dimensions · seed | Changed parameters | +|---|---|---| +| Dirt 1 | 32 × 16 · 105430 | non square expansion on, disorder 0.8125, scale 2 | +| Dirt 1 v2 | 32 × 16 · 105447 | disorder 0.8125, disorder anisotropy 0.625, scale 2, non square expansion on, tile offset (-0.3125, 0.4375), disorder anisotropy angle -0.21875, disorder speed 1.4375 | +| Dirt 2 | 32 × 16 · 42 | scale 2, disorder 0.21875, non square expansion on | +| Dirt 3 v2 | 128 × 32 · 433569 | scale 3, disorder 0.046875, disorder speed 0.046875, disorder anisotropy 0.046875, disorder anisotropy angle -0.203125, tile offset (-0.296875, 0.365234375), non square expansion on | + +### Reused properties across adjacent groups of terminal quadrants + +Directional Noise 3 has produced images for 15 of its first 19 whole settings, up from seven. The eight additional settings below include two default seeds, two changed square sizes and one changed rectangle. The preceding release still exhausted the execution limit at 32², seed 113. On the current release the 256² default and the changed 128² graph at seed zero still exceed it. The 64 × 32 scale-two and 32² scale-three settings retain their earlier failures. The corresponding 32², seed 113 setting in Directional Noise 3 v2 was also checked on the current release and still exceeds the limit. [Initial nineteen settings](#discarding-pattern-stamps-that-miss-every-output-sample) + +For the 128² renders, leave all parameters at their defaults. For the 32² and 64² changed renders, set scale 2, disorder .37, angle .125 and angle random .2. For the 64 × 32 F16 case use scale 1, non-square expansion on, disorder zero and both angles zero. Leave every other control at its default. Read the grayscale output at the indicated precision. In the last column save normally in MaterialCraft and reopen in each application. + +| Size and seed | Format | Original, one processor · max | Original, eight processors · max | Ordinary save, one processor · max | +|---|---|---:|---:|---:| +| 128², 0 | U16 | 16,342/16,384 · 2 | 16,339/16,384 · 2 | 16,342/16,384 · 2 | +| 128², 42 | U16 | 16,346/16,384 · 2 | 16,342/16,384 · 2 | — | +| 32², 113 | F32 | 1,014/1,024 · 2.50339508e−05 | 1,023/1,024 · 2.53617764e−05 | 1,014/1,024 · 2.53617764e−05 | +| 64², 42 | U8 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| 64², 42 | U16 | 4,071/4,096 · 2 | 4,087/4,096 · 2 | — | +| 64², 42 | F16 | 4,095/4,096 · 0.000244140625 | 4,096/4,096 · 0 | — | +| 64², 42 | F32 | 4,073/4,096 · 2.7358532e−05 | 4,088/4,096 · 2.62260437e−05 | — | +| 64 × 32, 103861 | F16 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | — | + +The eight recovered originals match 52,085/52,224 pixels on one processor and 52,119/52,224 on eight. The three ordinary saves match 21,452/21,504 on one. Each saved MaterialCraft buffer is bit-identical to its original. At 32², the original and reopened reference captures themselves agree on 1,022/1,024, with maximum error 2.53617764e−05. + +The deepest pattern at 32² traverses four depth-ten trees, totaling 5,592,404 quadrant visits. Each depth-nine parent has four terminal draws. A replay of the four incoming seeds under the property cache found 807,299 hits, concentrated in 342,193 of 1,048,576 terminal sibling groups. The previous accounting credited only the first reused miss in each group. Even if every draw missed, it required at least 2,104,483 charges against 2,097,152 available. The evaluator now counts each cached terminal draw that misses every sample once. It can spend that saving on the first discard of a later sibling group. Parents and visible draws still pay separately. The evaluator allows at most 5,242,880 full property evaluations and 1,048,576 retained stamps. Raster work is capped at 256,000,000 candidate pixels. [Quadrant evaluator](../crates/nodes/src/pattern/evaluation.rs) + +For an independent regression, connect the initial branch of an Iterate to a .375 square. Repeat a second branch 34 times. Give it two children, each with four references to a 1/64-size square. On the first set of leaves, disable seed inheritance and use a random tint scaled by .5. On the second set use a constant .25 tint. The 4² Rust test previously exhausted its 64 visits. All 16 output values now equal .375. Moving the cached leaves onto samples still reaches the limit. [Regression and visible-draw control](../crates/nodes/src/pattern/tests.rs) + +For desktop readback, use a .125 background, roughness zero, opacity one and additive squares. Set both parents and both leaves to 1/64 size. Render with leaf offsets (1/16, 1/16), then (1/32, 1/32). Use 16², seed 19 and 32 × 16, seed 113, and repeat at U8, U16, F16 and F32. All 6,144 original and 6,144 ordinary-save pixels matched the one-processor reference, maximum zero, and reproduced the previous MaterialCraft buffers exactly. Moving the squares produced three distinct F32 levels at 16². All 559 node and evaluator release tests, formatting, strict workspace Clippy, layer checks and WebAssembly checks passed. + +### Complete render coverage in the second version of Directional Noise 1 + +Directional Noise 1 v2 now renders all 60 established originals and all 12 ordinary saves. Four 64 × 32 originals and their U8 save previously reached the execution budget. These buffers were measured on revision `ac8706a`. Set seed 194938, scale 3, disorder, disorder speed, disorder anisotropy and angle random .34375, disorder anisotropy angle and angle .09375, tile offset (0, .10546875) and non-square expansion on. The U8 and F16 originals each match 2,048/2,048 pixels on both processor counts, maximum zero. U16 matches 2,045/2,048 on one processor and 2,044 on eight, maximum one level. F32 matches 1,222/2,048 and 1,229/2,048, maximum errors 2.38418579e−7 and 1.78813934e−7 respectively. The U8 ordinary save matches 2,048/2,048, maximum zero. [Established settings and save procedure](#sixty-whole-settings-for-three-directional-and-dirt-noise-packages) + +| Comparison | Exact frames | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Original, one processor | 20/60 | 137,469/137,472 · 1 | 251,336/251,648 · 1 | 90,360/90,368 · 0.00048828125 | 147,168/254,976 · 4.17232513e−07 | +| Original, eight processors | 24/60 | 137,472/137,472 · 0 | 251,387/251,648 · 1 | 90,357/90,368 · 0.00048828125 | 153,836/254,976 · 4.17232513e−07 | +| Ordinary save, one processor | 4/12 | 30,719/30,720 · 1 | 6,389/6,400 · 1 | 1,024/1,024 · 0 | 45,629/84,992 · 4.17232513e−07 | + +Across all settings, 626,333/734,464 original pixels match on one processor, 633,052/734,464 on eight and 83,761/123,136 after reopening on one. The F32 differences keep this root open. + +### Sample coverage of narrow and circular quadrant stamps + +Noise BNW Spots 3 v2 now renders the 128 × 512 original in U16 and F32 and the ordinary F32 save. On the preceding release and on a trial that reused writable terminal properties, these settings exceeded the execution budget. Set scale 2, disorder, disorder speed and anisotropy .53125, anisotropy angle .28125, tile offset (.1875, −.05859375), non-square expansion off and seed 411890. Leave other controls at their defaults. Compare the grayscale output at its stored precision. Save the graph in MaterialCraft and reopen it in each application for the last column. [Previous dense settings and saved cases](#recovered-settings-in-the-second-version-of-the-third-spots-graph) + +| Format | One processor, exact / total · maximum | Eight processors, exact / total · maximum | Ordinary save, one processor | +|---|---:|---:|---:| +| U16 | 65,509/65,536 · 1 | 65,508/65,536 · 1 | | +| F32 | 58,614/65,536 · 2.38418579e−7 | 57,113/65,536 · 2.98023224e−7 | 58,614/65,536 · 2.38418579e−7 | + +The original and reopened MaterialCraft F32 buffers are bit-identical. Cumulatively, 48 of 62 established originals and 10 of 14 ordinary saves have produced images. Fourteen original settings and four saved settings retain their earlier execution failures. The 64² seed 411585 case alone emits 101,738 depth-six subtrees. Each visits 85 quadrants through depth nine. + +In the 128 × 512 case, the former grid check retained each of the first 112,352 depth-eight draws because one axis spanned more than one pixel. Keep only the first child at depths one, two and three of the deepest pattern graph to run a smaller diagnostic. Of its 12,288 depth-eight draws, only 3,253 contributed to a sample. The evaluator now tests a narrow footprint against the same snapped sample coordinates and disc boundary as the rasterizer. A copy can test at most 16 pixel positions, with at most four copies per draw. The original property evaluations and the limits on traversal, stored stamps and raster work still apply. The production change uses the existing terminal-property cache. + +For an independent control, use an additive square of .375 over a .125 grayscale background, unit render and tiling regions, tiling on, roughness zero and opacity one. Connect four child quadrants in slot order. Use grayscale swatches for the tints. Set the supplementary parameter to .0625 on the children. In the second graph change only the first two frame offsets as shown. + +| Child shape | Authored size | Frame offset in first graph | Frame offset in second graph | Turns | Tint | +|---|---|---|---|---:|---:| +| Square (2) | (.03125, .75) | (0, 0) | (.03125, 0) | 0 | .125 | +| Disc (3) | (.125, .125) | (−.0078125, −.0078125) | (−.03125, −.03125) | 0 | .25 | +| Paraboloid (4) | (.0625, .6875) | (.03125, −.03125) | (.03125, −.03125) | .125 | .5 | +| Shape 18 | (.125, .1875) | (.234375, .234375) | (.234375, .234375) | .28125 | .1875 | + +Render both original graphs and their ordinary saves at 16² with seed 0, 32 × 16 with seed 42 and 16 × 32 with seed 411890. Set the pattern output precision to U8, U16, F16 and F32 independently. The one-worker D3D11 reference renderer matches 10,240/10,240 original and 10,240/10,240 reopened pixels, maximum zero. All 62 original and 14 saved MaterialCraft buffers for the first Spots 3 variant also remained bit-identical to revision `ae86c8a`. The reduced Rust regression exceeded the execution budget before the coverage change. All 558 node and evaluator release tests, formatting, strict workspace Clippy, layer checks and WebAssembly checks passed. + +### Complete rectangular render coverage in the first clouds graph + +Noise Clouds 1 now renders all 60 established original settings and all 15 ordinary saves. The final two settings already render on revision `ae86c8a`. Use scale 5, disorder .8125 and non-square expansion on. Keep other exposed parameters at their defaults. At 64 × 32, seed 103023, the F32 original matches 2,046/2,048 on each processor count, maximum 1.52587891e−5. At 32 × 64, seed 103024, the U16 original matches 2,047/2,048 on each processor count, maximum one level. Its ordinary save also matches 2,047/2,048, maximum one. These three MaterialCraft buffers were bit-identical before and after the narrow-stamp coverage change. [Original settings and save procedure](#four-cloud-noise-generators-and-repeated-saved-file-comparisons) + +| Comparison | Exact frames | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Original, one processor | 43/60 | 85,760/85,760 · 0 | 296,130/296,192 · 1 | 93,952/93,952 · 0 | 253,382/253,440 · 1.52587891e−5 | +| Original, eight processors | 37/60 | 85,760/85,760 · 0 | 296,086/296,192 · 1 | 93,950/93,952 · .00048828125 | 253,330/253,440 · 1.52587891e−5 | +| Ordinary save, one processor | 9/15 | 4,096/4,096 · 0 | 94,954/94,976 · 1 | 1,536/1,536 · 0 | 22,522/22,528 · 1.52587891e−5 | + +The full comparison gives 729,224/729,344 original pixels on one processor, 729,126/729,344 on eight and 123,108/123,136 after reopening. At 64 × 32, the first previously blocked setting in Noise Clouds 1 v2 and Noise Clouds 2 v2 still exceeds the execution budget. + +### Reusing terminal quadrant properties in dense rectangular renders + +Noise BNW Spots 3 renders the eight rectangular settings that previously exhausted the pattern execution budget. Set non-square expansion on and leave the other exposed parameters at their defaults except for the values in the table. Compare the raw grayscale output in U8, U16, F16 and F32. Each row includes all four formats. [Earlier six recovered settings and eight failures](#dense-settings-recovered-in-the-third-spots-graph) + +| Dimensions | Scale | Disorder | Seed | One processor, exact / total | Eight processors, exact / total | Maximum error on eight | +|---|---:|---:|---:|---:|---:|---| +| 64 × 16 | 2 | .03125 | 42 | 4,096/4,096 | 4,095/4,096 | 1 U16 level | +| 64 × 32 | 3 | .34375 | 194504 | 8,192/8,192 | 8,192/8,192 | 0 | + +Both ordinary saves that previously failed now match all 3,072 pixels on one processor, maximum zero. Use F16 at 64 × 16 and U8 at 64 × 32. A fresh 64 × 16 F32 reference capture of the original and a fresh capture of an ordinary MaterialCraft save also match both local renders on all 1,024 pixels. Their common range is .289851993 to .781987548. + +Rechecking the [complete established matrix](#whole-root-precision-and-saved-comparisons-for-the-three-neighboring-spot-graphs) gives 62/62 original settings rendered, up from 54/62, and 14/14 ordinary saves, up from 12/14. On one processor 34/62 originals match completely, on eight 32/62, and on reopening 8/14. The following counts include every setting in each route. + +| Route | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Original, one processor | 88,832/88,832 · 0 | 301,713/301,824 · 1 | 88,831/88,832 · .000244140625 | 253,561/253,696 · .0000153183937 | +| Original, eight processors | 88,832/88,832 · 0 | 301,750/301,824 · 1 | 88,831/88,832 · .000244140625 | 253,598/253,696 · .0000107288361 | +| Ordinary save, one processor | 15,360/15,360 · 0 | 23,797/23,808 · 1 | 1,024/1,024 · 0 | 82,912/82,944 · .0000107288361 | + +At 64² F32, seed 42, scale 2, disorder .37 and the other exposed defaults, the two coarser pattern stages, Levels and their first Blend match all 9,472 stored samples in a single-processor capture. The deep pattern stage differs by one U16 level at two of 4,096 pixels. Alternating this setting with the 128² default for three more captures left 4,092 of its 4,096 deep-stage pixels invariant. MaterialCraft matched 4,091 of those. At (30,57) all four reference reads store 32,584 and MaterialCraft stores 32,585. At the 128² default it matches 16,373 of 16,380 invariant deep-stage pixels. Forcing the deep stage to F32 gives maximum errors of 1.19209290e−7 and 1.78813934e−7 respectively. These differences keep the root in progress. + +The deepest pattern visits 5,592,400 quadrants at 64 × 16 and 6,291,450 at 64 × 32. Siblings can reach the same terminal seed at different positions. The evaluator reuses an analytic stamp's evaluated properties when its node, seed and depth agree and every input it reads is fixed during the cook. It applies the branch and frame translations separately at the new position, then tests actual pixel coverage in draw order. A group of up to four terminal misses can share its parent's visit when it reuses a property evaluation. Visible stamps still consume individual visits. The retained-stamp limit is 1,048,576 and the ceiling on full property evaluations is 5,242,880. [Shared evaluator](../crates/nodes/src/pattern/evaluation.rs) · [Property eligibility and bounded cache](../crates/nodes/src/pattern/stamp_cache.rs) + +For the reduced graph, use a 4 × 4 output and an Iterate with a .375 square on its initial branch. Repeat a square of local size (1/64, 1/64) 100 times on the second branch. Connect its four child slots to another square of the same local size with seed inheritance disabled and a random tint scaled by .5. Under a 64-visit test allowance, the earlier release returned an execution-budget error. All 16 pixels now equal .375. Reading the quadrant position for the frame offset, reading a gain written by the parent, and enlarging the leaves to cover samples each still reaches the allowance. [Reduced graph and controls](../crates/nodes/src/pattern/tests.rs) + +At 512 × 128, seed 411944, scale 1, disorder .09375 and expansion on, four single-worker release runs in previous/current/current/previous order produced identical F32 buffers. The median whole-graph cook fell from 17.53 s to 14.01 s (20.1%). Use a fresh session per run and measure the cook before serializing its output. + +### Receiving quadrant subtrees after the second pair fills + +Across 86 established Noise BNW Spots 1 settings, the shared renderer matches 825,314/841,728 pixels on one processor, up 175, and 776,619/841,728 on eight, down 79. Across 19 ordinary saves, 196,239/196,352 match, up 11. The seven changed original frames are listed below. Use scale 2, the stated disorder and roughness, and the graph defaults for its other parameters. At 64², disable non-square expansion. The arrows compare both releases to the same raw capture. [Preceding measurements](#carrying-unfinished-quadrant-draws-into-a-third-tree) + +| Dimensions, seed and format | Disorder, roughness | One processor | Eight processors | Maximum error, one / eight | +|---|---|---:|---:|---:| +| 32 × 16, 456654, F32 | .28125, .375 | 447 → 451/512 | 435 → 439/512 | 2⁻²³ / 2⁻²³ | +| 32², 113, F32 | .37, .6 | 941 → 946/1,024 | 800 → 803/1,024 | 2⁻²² / 2⁻²³ | +| 32², 162063, F32 | .78125, .73828125 | 919 → 930/1,024 | 767 → 764/1,024 | 2⁻²³ / 2⁻²² | +| 32 × 64, 456747, F32 | .84375, 1 | 1,637 → 1,673/2,048 | 1,528 → 1,504/2,048 | 2⁻²³ / 2⁻²³ | +| 64², 194536, F32 | .53125, .53125 | 3,793 → 3,804/4,096 | 3,257 → 3,258/4,096 | 2⁻²² / 2⁻²³ | +| 128 × 64, 456809, U16 | .953125, .96875 | 8,187 → 8,188/8,192 | 8,188 → 8,189/8,192 | 1 / 1 | +| 128 × 64, 456809, F32 | .953125, .96875 | 6,499 → 6,606/8,192 | 6,166 → 6,105/8,192 | 2⁻²² / 3 × 2⁻²⁴ | + +The 32² save at seed 162063 also rose from 919 to 930/1,024, maximum 2⁻²³. Across all settings, 66/86 original frames match completely on one processor, 38/86 on eight and 16/19 on reopening. On one processor U8 and F16 each match 108,800/108,800. U16 matches 328,401/328,448 with maximum one level. F32 matches 279,313/295,680 with maximum 2⁻²². + +The two reduced graphs exercise different transfers between the second and third trees. Use a white background, additive squares and the [original quadrant fixture](#carrying-unfinished-quadrant-draws-into-a-third-tree). With no pending sibling to give up in either paired group, leave three depth-five children after the cut in the first incoming depth-three quadrant. In the adjacent quadrant, number the four depth-four parents and their sixteen depth-five children from zero. The lower pair takes parent 1's draw, child 7 and then children 0 and 1. The upper pair takes parent 0's draw and children 2 and 3. These pieces precede each pair's draws in the third tree. With eight trees and the copy field of the 32 × 16 setting above, all 42,121 adjacent and cross-boundary comparisons agree in both gain directions. Three trees with one copy per draw give 42,593/42,593. [Shared renderer](../crates/nodes/src/pattern/underfilled_quadrants/remaining/next_tree.rs) + +When each pair transfers one sibling, the next collecting group takes the lower pair's deferred sibling and the first pending depth-five child inside the cut quadrant. If three children remain there, it also takes child 2 in the adjacent quadrant. Its own draw and the start of its first incoming quadrant in the third tree complete batch 35. The final pair takes its unfinished copies, the deferred middle branch and either parent 2's subtree (three pending children) or the first two parent subtrees (four pending children). Its third-tree draws complete batches 36 and 37. In the latter case, the adjacent depth-three parent's own draw stays with the receiver. Including it reversed two observed comparisons on the 64² copy field. Removing it gave 25,557/25,557. The 32² seed-113 field gave 25,689/25,689. [Regression graphs](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +Fresh reference renders used four output formats on each of five settings. Repeat the 32² seed 113 and 64² seed 194536 settings above, the 32 × 16 setting at seeds 456654 and 456655, and unmodified defaults at 128² seed zero. Save each in MaterialCraft and reopen it in the reference app. U8 and F16 each match all 22,528 pixels on every route. U16 gives 22,527/22,528 on one processor, 22,525 on the ordinary saves and 22,505 on eight, maximum one level. F32 gives the following counts against these specific captures. + +| Size and seed | One processor | Ordinary save on one | Eight processors | Maximum error, one / saved / eight | +|---|---:|---:|---:|---:| +| 32², 113 | 911/1,024 | 929/1,024 | 807/1,024 | 2⁻²³ / 2⁻²³ / 2⁻²³ | +| 64², 194536 | 3,717/4,096 | 3,710/4,096 | 3,297/4,096 | 2⁻²³ / 2⁻²² / 2⁻²² | +| 32 × 16, 456654 | 446/512 | 437/512 | 426/512 | 3 × 2⁻²⁵ / 2⁻²⁴ / 2⁻²⁴ | +| 32 × 16, 456655 | 452/512 | 458/512 | 429/512 | 2⁻²³ / 2⁻²³ / 2⁻²³ | +| 128², 0 | 16,384/16,384 | 16,384/16,384 | 10,092/16,384 | 0 / 0 / 2⁻²² | + +The [previous repeated captures](#carrying-unfinished-quadrant-draws-into-a-third-tree) distinguish changing reference pixels from differences that persisted across those reads. At 32² seed 113, 64² seed 194536 and 32 × 16 seed 456654, respectively, MaterialCraft matches 827/847, 3,405/3,471 and 363/370 of the invariant original pixels on one processor. The ordinary saves give 813/829, 3,436/3,508 and 380/391. The eight-processor originals give 591/666, 2,575/2,810 and 357/371. Later batches and the remaining differences at invariant positions are open. + +The four-format procedural controls match 237,568/237,568 pixels in 232 original renders and again in 232 ordinary saves, maximum error zero. Of these, 156 renders per route place signed gains on the incoming parent, its children and the receiving group on opposite sides of the measured cuts. The other 76 repeat the preceding boundary and depth controls. The second version of the stock root retained every measured output bit on its 87 original settings and 19 saves. + +### Carrying unfinished quadrant draws into a third tree + +Noise BNW Spots 1 matches 825,139/841,728 pixels on one processor across its 86 established settings, up from 825,023. The eight-processor capture gives 776,698/841,728, down from 776,739. Ordinary saves give 196,228/196,352, up from 196,200. Whole-frame counts are 66/86, 38/86 and 16/19 respectively. Three original F32 frames changed. At 32² seed 113 and 64² seed 194536, agreement with the established single-processor captures rose from 926 to 941/1,024 and from 3,720 to 3,793/4,096. The maximum in each is 2⁻²². The third changed original and its ordinary save rose from 891 to 919/1,024, maximum 2⁻²³. [Preceding measurements and square settings](#completed-quadrant-batches-before-a-later-tree) + +The lower and upper quadrant pairs each complete two 5,460-copy batches with draws from the third tree. When both hand off a single sibling, the lower pair first takes the upper pair's deferred child and the upper pair takes the last pair's deferred child. If three depth-five children remain in the receiver's first incoming depth-three quadrant, the upper pair also takes the third child of the second depth-four quadrant in the adjacent incoming quadrant. At four remaining children that additional subtree stays with other draws. When the lower pair instead hands off two siblings, both pairs carry forward the unfinished pieces from the earlier [two-tree transfers](#final-transfers-between-unfinished-quadrant-groups). The renderer locates those boundaries in the physical tile-copy stream, including copies discarded before rasterization. [Shared renderer](../crates/nodes/src/pattern/underfilled_quadrants/remaining/next_tree.rs) + +For an independent boundary check, use three complete eight-level quadrant trees with a connected inactive depth-ten branch. In the second tree, add 110 and 130 copies in depth-three quadrants 52 and 56 using the [edge and corner procedure](#quadrant-batch-order-after-a-sibling-transfer). Add 76 copies in quadrant 33, then change that to 77. The cut moves from the first draw of the thirteenth depth-five child to the preceding parent. The upper pair receives 85 additional unit copies in the first setting. Compare adjacent single-copy draws and draws on opposite sides of batches 31 through 34, exchanging gains −1 and 2⁻²⁵ on white. Both directions agree for all 43,429 relations at 76 and all 43,601 at 77. The four-tree fields from the two square settings give 42,391/42,391 and 42,215/42,215. The three- and eight-tree fields with 166 and 400 extra copies in quadrants 52 and 56 each give 43,799/43,799. + +Repeat the four-format whole-image control with three, four, six and eight trees using the wrapping procedure from the preceding comparison. In the second tree, wrap depth-five subtrees 832, 896 and 897 for three and eight trees. For four trees wrap depth-six subtrees 3328–3330 and 3584–3586. For six use 3328–3333 and 3584–3593. Place negative and positive markers in depth-five subtrees (384,80) and (640,80) in trees three and two respectively. Also exchange both the gains and the tree numbers for the first pair. All 48 original and all 48 ordinarily saved frames match 49,152/49,152 pixels on each route, up from 49,140, maximum zero. [Regression graphs](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +For a finer check use the four-tree field above and depth-six marker pairs (1536,320), (2560,320) and (320,1536), with the markers in trees three and two, three and two, and two and three respectively. Those frames and their ordinary saves each rose from 12,285 to 12,288/12,288. Put markers at 2200 in tree two and 2560 in tree three, in both gain directions. Repeat after also wrapping subtrees 2112–2114 in tree two. These originals and ordinary saves each rose from 16,381 to 16,384/16,384. Across all 76 procedural frames per route, 77,824/77,824 pixels match, maximum zero. Both regression tests failed on the preceding commit. + +Against the same reference repeats as the preceding comparison, the single-processor 32² original matches 907/1,024, down from 914. Across five captures, it matches 824/847 positions at which the reference was invariant, up from 821. At 64² the corresponding counts are 3,777/4,096 and 3,404/3,471, up from 3,700 and 3,348. The ordinary saves give 916/1,024 and 3,784/4,096, with 812/829 and 3,436/3,508 invariant positions matched. The eight-processor captures give 768/1,024 and 3,265/4,096, with 593/666 and 2,579/2,810 invariant positions matched. + +Fresh reference renders of five original settings and ordinary saves gave the following F32 counts. The arrows compare two releases against the same capture. The first three rows use the preceding comparison's scale, disorder and roughness. At 128 × 64 use scale 2, disorder and roughness .96875, and disable non-square expansion. At 16 × 32 use scale 1, zero disorder and roughness 1. Keep the remaining parameters at their defaults. + +| Size and seed | One processor | Ordinary save on one | Eight processors | Maximum, one / saved / eight | +|---|---:|---:|---:|---:| +| 32², 113 | 912 → 919/1,024 | 902 → 907/1,024 | 833 → 825/1,024 | 2⁻²² / 2⁻²³ / 3 × 2⁻²⁴ | +| 64², 194536 | 3,694 → 3,722/4,096 | 3,724 → 3,741/4,096 | 3,367 → 3,354/4,096 | 2⁻²³ / 2⁻²² / 2⁻²² | +| 32 × 16, 456654 | 447/512 | 451/512 | 432/512 | 2⁻²⁴ / 3 × 2⁻²⁵ / 2⁻²⁴ | +| 128 × 64, 411625 | 6,629/8,192 | 6,965/8,192 | 5,924/8,192 | 3 × 2⁻²⁴ on each route | +| 16 × 32, 0 | 512/512 | 512/512 | 365/512 | 0 / 0 / 2⁻²³ | + +U8 and F16 each give 14,336/14,336 on every route, maximum zero. U16 gives 14,332/14,336 on one processor, 14,335/14,336 on reopening and 14,324/14,336 on eight, maximum one stored level. The second version of Spots 1 reproduced all 87 established original and 19 saved frame digests from the previous release. All 554 node and evaluator release tests, formatting, strict workspace Clippy, layering and WebAssembly passed. Later batches, other sibling transfers and processor-dependent differences remain open. + +### Completed quadrant batches before a later tree + +Noise BNW Spots 1 matches 825,023/841,728 pixels across its 86 established settings on one processor, up from 824,634. The eight-processor result is 776,739/841,728, down from 776,818. The 19 ordinary saves give 196,200/196,352, up from 196,193. Whole-frame counts are 66/86, 38/86 and 16/19 respectively. In F32 the corresponding maxima are 2⁻²², 3 × 2⁻²³ and 2⁻²³. The eight-processor F16 maximum is 2⁻¹¹. Integer formats differ by at most one stored level. The second version retains all 87 original and 19 saved frame digests. [Previous measurements for both roots](#final-transfers-between-unfinished-quadrant-groups) + +In the measured eight-level trees, when a transferred child completes a receiving batch, the lower and upper pairs and the last child submit their full batches in the same order with later trees present. The first thirty complete batches can therefore be submitted before the evaluator returns to the unfinished groups. Repeat the four-format graph comparison at scale 2 with the following settings. The 64² case disables non-square expansion. All other controls use their defaults. The arrows compare the preceding and current release cooks with the same reference frame. + +| Size, seed, disorder, roughness | One processor, F32 | Ordinary save on one, F32 | Eight processors, F32 | Maximum after, one / saved / eight | +|---|---:|---:|---:|---:| +| 32², 113, .37, .6 | 909 → 914/1,024 | 894 → 901/1,024 | 778/1,024 | 2⁻²³ / 2⁻²³ / 3 × 2⁻²⁴ | +| 64², 194536, .53125, .53125 | 3,685 → 3,700/4,096 | 3,723 → 3,736/4,096 | 3,302 → 3,297/4,096 | 2⁻²³ / 2⁻²² / 2⁻²³ | +| 32 × 16, 456654, .28125, .375 | 440/512 | 438/512 | 439/512 | 2⁻²⁴ / 3 × 2⁻²⁵ / 2⁻²³ | + +U8 and F16 each match 5,632/5,632 on all three routes, maximum zero. U16 gives 5,631/5,632 on one processor, 5,630/5,632 on reopening and 5,629/5,632 on eight, maximum one level. The rectangle has eight active trees and no pending sibling in either paired group. Across five one-processor captures of the 32² and 64² originals, the reference agreed at 847 and 3,471 positions. The renderer matches 821 and 3,348 of those, up from 815 and 3,334. Across four saved captures it matches 803/829 and 3,403/3,508 positions invariant in the reference. The corresponding eight-processor counts are 601/666 and 2,600/2,810 across four captures. Two single-processor captures of the 32² original differed at 101 pixels. The later batches and differences between repeated reference renders remain open. + +Use an outer Iterate with three, four, six or eight complete eight-level quadrant trees and a connected inactive depth-ten branch. Apply the edge and corner copy procedure in second-tree depth-three quadrants 52, 56 and 48. In that order use extra copy counts (165,400,0), (166,400,0) and (95,120,0) for three trees, (165,165,0) and (260,480,0) for four, (250,245,200) for six, and (165,400,0) and (166,400,0) for eight. Also use the two four-tree fields from the square settings above. Compare successive single-copy draws from the end of batch 26 through batch 30, then compare draws in those batches with unsubmitted draws in the first two trees and in later trees. Exchange gains −1 and 2⁻²⁵ at each intersection. Across the ten fields, 425,278/425,278 order measurements agree in both gain directions. The initial three-tree (165,400,0) acquisition had three reversed and 1,971 inconsistent relations. Two independent reacquisitions in opposite request orders agreed on all 42,291 relations in that field. [Copy-count procedure](#quadrant-batch-order-after-a-sibling-transfer) + +For whole-image controls, use the same four sizes, formats, gains and seeds as in the two-tree comparison. In the second tree of a three-, four- or eight-tree graph, wrap the leaves of depth-five subtrees 832, 896 and 897. Repeat with three and four trees wrapping the depth-six ranges 3328–3330 and 3584–3586, and with six trees wrapping 3328–3333 and 3584–3593. For each field put signed markers in second-tree depth-five subtrees (336,896), (896,336), (768,336), (896,768), (768,896) and (336,80). Across 144 frames on each route, originals went from 147,432 to 147,456/147,456 and ordinary saves from 147,432 to 147,456/147,456, maximum zero. The three-tree regression failed on the preceding release. All 552 node and evaluator release tests, formatting, workspace Clippy, layer checks and WebAssembly checks passed. [Four-format control settings](#quadrant-batch-order-after-a-sibling-transfer) · [Shared batch ordering](../crates/nodes/src/pattern/underfilled_quadrants/remaining.rs) · [Regression graph](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +### Final transfers between unfinished quadrant groups + +At 64 × 32, seed 162172, scale 1, disorder .5625 and roughness .6015625, Noise BNW Spots 1 now matches all 2,048 F32 pixels on one processor, up from 2,045. A fresh ordinary SBS save reopened on one processor also matches 2,048/2,048. At 32 × 16, seed 161954, scale 1, disorder .34375 and roughness .46484375, both routes match 512/512. Each of the four requested formats (U8, U16, F16 and F32) matches 2,560/2,560 across the two sizes on each route, maximum zero. The four recent single-processor F32 captures agree at every position on each route. + +The fresh eight-processor F32 captures give 411/512 and 1,589/2,048, maxima 2⁻²³ and 3 × 2⁻²⁴. The preceding build gives 411 and 1,586 against those same captures. U8 and F16 are exact on eight processors, and U16 gives 2,558/2,560, maximum one stored level. Across four eight-processor F32 captures the references agree at 337 and 1,181 positions. MaterialCraft matches 307 and 1,067 of those positions. + +After [the first thirty full batches](#quadrant-batch-order-after-a-sibling-transfer), each group still owns a range of physical copies. If a batch finished inside a transferred child, a further sibling division occurs at that exact copy. The receiver completes its own part of the child and takes a pending child from the upper pair. The next two groups take the following available upper siblings. The third group also takes the lower siblings before the last two. A parent draw between two depth-five subtrees stays with its original group. The final group receives the penultimate lower subtree. The [shared renderer](../crates/nodes/src/pattern/underfilled_quadrants/remaining/transfers.rs) applies this schedule to two complete trees when the lower, upper and last pairs have respectively three or four, five or six, and two through five unvisited depth-five children, the measured transfers line up with subtree boundaries, and each receiving group stays below 5,460 copies. + +For an independent order measurement, use two intersecting squares per selected depth-five subtree in a 256² F32 output. Extend one horizontally and the other vertically to 15/16 of the tile. Place their centers along distinct rows and columns. On white, draw with gains −1 and 2⁻²⁵ and exchange the gains. Every intersection reads zero or 2⁻²⁵. Divide the markers into panels of at most 105 and capture both panels together for cross-panel comparisons. Vary the edge and corner copy counts in second-tree depth-three quadrants 52, 56 and 48 using the [one-copy procedure](#quadrant-batch-order-after-a-sibling-transfer). The 26 fields gave 268,043/268,043 pairwise order comparisons. One original gain-swap capture was inconsistent. Two fresh acquisitions in opposite request orders agreed at every tested position and supplied that field's count. Separate adjacent-draw and cross-batch tests, including shallower draws, agreed on 614,616/614,616 relations in both gain directions. + +For a complete procedural image, use the [same four output sizes, gains and seeds](#quadrant-batch-order-after-a-sibling-transfer). In the second tree wrap the terminal squares under depth-five quadrants 832, 896 and 897. In another field wrap the leaves of depth-six quadrants 3328–3333 and 3584–3593. For the third field add 3072–3073 to the second field. Use a pair of depth-five markers in both gain directions for each row. + +| Signed marker pair, in second-tree traversal order | First field | Second and third fields | +|---|---|---| +| Upper child and second receiving group | (924,624) | (922,624) | +| Middle group and the receiver's deferred child | (972,541) | (972,541) | +| Final group and lower child | (248,862) | (248,862) | + +The 72 original and 72 reopened frames each improved from 73,716 to 73,728/73,728 exact pixels, maximum zero. Each route covers 9,216 U8, 9,216 U16, 36,864 F16 and 18,432 F32 pixels. The preceding 72 controls and their ordinary saves also give 73,728/73,728 on each route. The [full-graph regression](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) failed before the fix. + +In the established Spots 1 panel, 66/86 originals now match completely on one processor, 38/86 on eight and 16/19 in the ordinary saves. Total agreement is 824,634/841,728, 776,818/841,728 and 196,193/196,352 respectively. The changed F32 totals are 278,635/295,680 on one and 230,977/295,680 on eight, maxima 2⁻²² and 3 × 2⁻²³. Remaining settings include larger repeated trees and the eight-processor differences above. All 551 release tests for the node and evaluation crates passed, along with formatting, strict workspace Clippy, dependency layering and WebAssembly. + +### Quadrant batch order after a sibling transfer + +Noise BNW Spots 1 now matches 65 of its 86 established original settings on one processor, up from 64. The shared pattern renderer accounts for a full batch that finishes in a child transferred from another quadrant. The following two settings exercise different submission orders. Both use scale 1. Counts compare raw F32 pixels. [Renderer](../crates/nodes/src/pattern/underfilled_quadrants/remaining.rs) · [Regression graph](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +| Size, seed, disorder, roughness | One processor, before → after | Ordinary save on one, before → after | Fresh eight processors, before → after | Maximum after, one / saved / eight | +|---|---:|---:|---:|---:| +| 32 × 16, 161954, .34375, .46484375 | 501 → 512/512 | 501 → 512/512 | 410 → 408/512 | 0 / 0 / 2⁻²³ | +| 64 × 32, 162172, .5625, .6015625 | 1,994 → 2,045/2,048 | 1,994 → 2,045/2,048 | 1,591 → 1,586/2,048 | 2⁻²⁴ / 2⁻²⁴ / 3 × 2⁻²⁴ | + +U8 and F16 each match all 2,560 pixels on the three routes. U16 matches 2,560/2,560 on one processor and on reopening, and 2,558/2,560 on eight, maximum one stored level. All four recent one-processor captures of each F32 frame agree with each other, including the three earlier original captures. The four recent saves also agree with each other at every position. On eight processors those four captures agree at 344/512 and 1,147/2,048 positions. MaterialCraft matches 317 and 1,043 of those positions respectively. + +Use two iterations of the [additive-square quadrant tree with an inactive depth-ten branch](#pending-quadrant-siblings-and-the-first-full-receiving-batch). Start with one physical copy per draw. After 26 full batches of 5,460 copies, compare the lower pair, upper pair, first receiving group and last child. The lower pair submits first. When its cut leaves two unvisited depth-five subtrees and it transfers one, the upper pair precedes the receiver. The last child also precedes the receiver when the upper pair has two such subtrees left. When the lower pair has three or four left and transfers two, the receiver precedes the upper pair, followed by the last child. This comparison covers a receiver that fills within the first child supplied by the second group. + +For a one-copy boundary, use second-tree depth-three quadrant 52 in zero-based traversal order. Begin twelve draws after its root. For *e* extra copies, move the first ⌊*e*/3⌋ draws to a corner and the next *e* mod 3 draws to an edge. At 165 extra copies the lower pair transfers one sibling. At 166 it transfers two and the upper–receiver order reverses. Repeat with independent counts in quadrants 56 and 48. Across 96 fields, each of the six pairs of batches was compared at nine positions using both gain directions. Of 5,184 relations, 5,155 agreed in both directions on the first capture and all agreed with the renderer. The other 29 came from one field with 95, 330 and 128 extra copies in quadrants 52, 56 and 48. Each of three independent reacquisitions agreed on all 54 relations in that field, including a reversed acquisition order. + +For the whole-image control, number the depth-five subtrees from zero in each tree. In the second tree only, place coincident squares from subtrees (896,336), (336,896) or (896,768) on white with gains −1 and 2⁻²⁵. Give other squares gain 2⁻⁷⁶. Test six copy fields. Use one copy everywhere, wrap the leaves of depth-six subtrees 3328–3330, wrap depth-five subtree 832, wrap 832 and 896, wrap 832 and 768, or wrap the leaves of both depth-six ranges 3328–3330 and 3584–3586. A wrapped leaf sits at a corner and contributes four physical copies. Use 32² F32 seed 41384, 16 × 32 U8 seed 41484 with gains −.5 and 2⁻²⁵, 32 × 16 U16 seed 41588 with −1 and 2⁻²⁴, and 64 × 32 F16 seed 41692 with 2⁻²⁵ and −1. All 72 original frames and all 72 ordinary saves match. Each route improved from 73,719 to 73,728/73,728 pixels, maximum zero. The regression failed on the preceding renderer. + +| Established Spots 1 panel | One processor, exact pixels · maximum | Eight processors, exact pixels · maximum | Ordinary saves, exact pixels · maximum | +|---|---:|---:|---:| +| U8 | 108,800/108,800 · 0 | 108,799/108,800 · 1 | 90,112/90,112 · 0 | +| U16 | 328,399/328,448 · 1 | 328,244/328,448 · 1 | 93,693/93,696 · 1 | +| F16 | 108,800/108,800 · 0 | 108,798/108,800 · 2⁻¹¹ | 6,400/6,400 · 0 | +| F32 | 278,632/295,680 · 2⁻²² | 230,980/295,680 · 3 × 2⁻²³ | 5,988/6,144 · 2⁻²³ | + +Across the established settings, 824,631/841,728 pixels match on one processor, 776,821/841,728 on eight and 196,193/196,352 in 19 ordinary saves. There are 38/86 exact eight-processor frames and 16/19 exact saves. The two fresh rectangular saves extend this coverage. Remaining differences include three repeatable F32 pixels in the larger rectangle and different eight-processor results between captures. All 550 release tests in the node and evaluation crates, formatting, strict workspace Clippy, dependency layering and WebAssembly passed. + +### Finishing a quadrant copy batch in the next tree + +Noise BNW Spots 1 v2 gained 58 exact F32 pixels across three 16 × 32 original settings on one processor. The same three ordinary SBS saves reopened on one processor gained the same 58. U8 and F16 matched all 1,536 pixels on all three routes. U16 matched 1,536/1,536 on one processor and on reopening, and 1,535/1,536 on eight, maximum one stored level. For the changed setting use scale 1, roughness 1, disorder, speed and anisotropy zero, angle −.375 and tile offset (0,0). The other two settings use the graph defaults. + +| Seed and settings | Original F32 on one processor | Reopened F32 on one processor | Fresh original F32 on eight processors | Current maximum, one / eight | +|---|---:|---:|---:|---:| +| 0, changed | 473 → 491/512 | 473 → 491/512 | 470 → 464/512 | 2⁻²⁴ / 2⁻²³ | +| 194426, defaults | 463 → 487/512 | 463 → 487/512 | 472 → 461/512 | 2⁻²³ / 2⁻²³ | +| 0, defaults | 484 → 500/512 | 484 → 500/512 | 475 → 472/512 | 2⁻²⁴ / 2⁻²³ | + +The shared renderer now continues a partially filled tile-copy batch across two complete iterations of a quadrant tree. Give the [original additive-square graph](#tile-copies-in-the-last-two-active-quadrant-levels) two outer iterations, with independent square positions in each. Keep the inactive descendant levels connected. Index the 81,920 visible draws in each tree in traversal order, with the second tree starting at 81,920. A depth-three quadrant contains 1,280 draws. In the first tree, groups 62–63, then 48–49, then the last depth-five child of a transferred sibling supply the outer pair. Its outstanding copies come from group 62 of the next tree. The renderer counts physical copies at each subtree boundary. [Shared renderer](../crates/nodes/src/pattern/tile_runs/inactive_children/repeated.rs) · [Boundary regression](../crates/nodes/src/pattern/tile_runs/inactive_children/tests.rs) + +Start with one copy per draw. Move e draws of group 62 in the first tree to the horizontal edge at indices 79,360 + (173j + 37) mod 2,560, for j from 0 to e − 1. At e = 0, 100 or 259 the first tree leaves 260, 160 or one of 5,460 copies outstanding. Draw 23,599 precedes 161,280 in both gain directions. At 259, draw 161,280 precedes 67,250 and draw 161,281 follows 67,261. At 260 the batch finishes entirely in the first tree. Both 260 and 261 reverse the comparison between 161,280 and 67,240. These are raw F32 samples of overlapping −1 and 2⁻²⁵ squares on white. All 711,708 adjacent and cross-boundary comparisons of the first eleven batches agreed in both gain directions across eight fields. The twelfth batch agreed on 124,952/124,952 independently selected relations across twelve fields, including the one-copy boundary. + +For the full-image control, mark each row's disjoint pairs at consecutive texels beginning at (6,5). Keep unmarked draws active. Render both gain directions. In the edge field move squares at 1,280g + (211j + 17) mod 2,560 to the edge in groups g = 24, 40, 50 and 62. Use (330, 520, 80, 17) extra copies in the first tree and (430, 630, 170, 93) in the second. The last two fields use the copy counts of the first two 16 × 32 settings above. The group and marker indices are independent of the graph identifier. + +| Field | First two pairs | Additional pairs | +|---|---|---| +| One copy per draw | (161539,67250), (161540,67261) | (23599,161280), (79360,61440) | +| 100 extra | (161439,67250), (161440,67261) | (23599,161280), (79360,61440) | +| 259 extra | (161280,67250), (161281,67261) | (79360,61440) | +| 260 extra | (23599,67250), (161280,67261) | (79360,61440) | +| 261 extra | (23598,67250), (161280,67261) | (79360,61440) | +| Edge field | (161513,67250), (161514,67261) | (23999,161280), (79360,61440) | +| Changed setting | (161518,67250), (161519,67261) | (23599,161280), (79360,61440) | +| Default seed 194426 | (161485,67250), (161486,67261) | (23599,161280), (79360,61440) | + +| Storage, dimensions and seed | Exact original pixels | Exact reopened pixels | Maximum, original / reopened | +|---|---:|---:|---:| +| U8, 64 × 128, 620741 | 131,072/131,072 | 131,072/131,072 | 0 / 0 | +| U16, 128 × 64, 620759 | 131,072/131,072 | 131,072/131,072 | 0 / 0 | +| F16, 256 × 128, 620771 | 524,288/524,288 | 524,288/524,288 | 0 / 0 | +| F32, 128², 620729 | 262,140/262,144 | 262,144/262,144 | 2⁻²⁵ / 0 | + +The 64 original frames give 1,048,572/1,048,576, up from 1,048,552. All 1,048,576 reopened pixels match. The four differing original pixels are in the two fields derived from the 16 × 32 settings. Switch the seed, restore 620729 and reacquire those four F32 frames three times on each route. All 65,536 pixels match on each repeat. The established 87-setting v2 panel now gives 839,460/842,752 on one processor and 830,536/842,752 on eight. The 19 established ordinary saves give 137,715/139,008. Exact whole-frame counts remain 62/87, 58/87 and 13/19 respectively. The three fresh ordinary saves in the table extend the saved coverage. Later batches and eight-processor differences remain open. + +For the first Spots 1 graph use scale 1. At 32 × 16 set seed 161954, disorder .34375 and roughness .46484375. At 64 × 32 set seed 162172, disorder .5625 and roughness .6015625. Repeat four times on one and eight processors, including the archived originals, and reopen the ordinary saves three times on one. The same 501/512 and 1,994/2,048 F32 pixels agree on every one-processor original and reopen, maximum 2⁻²⁴. At 32 × 16 the four eight-processor captures agree with each other at 356/512 positions, and MaterialCraft matches 322 of those. At 64 × 32 they agree at 1,255/2,048 positions, and MaterialCraft matches 1,095. Maximum eight-processor errors across the repeats are 2⁻²³ and 3 × 2⁻²⁴ respectively. + +| Established v2 panel | One processor, exact pixels · maximum | Eight processors, exact pixels · maximum | Ordinary saves, exact pixels · maximum | +|---|---:|---:|---:| +| U8 | 141,568/141,568 · 0 | 141,568/141,568 · 0 | 32,768/32,768 · 0 | +| U16 | 295,674/295,680 · 1 | 295,650/295,680 · 1 | 12,031/12,032 · 1 | +| F16 | 108,800/108,800 · 0 | 108,797/108,800 · 2⁻¹¹ | 1,024/1,024 · 0 | +| F32 | 293,418/296,704 · 2⁻²³ | 284,521/296,704 · 2⁻²³ | 91,892/93,184 · 2⁻²³ | + +Of the 211 established original and saved frames across both roots, precisely the three v2 originals in the first table changed their MaterialCraft output bits. All 549 release tests for the node and evaluation crates passed. The new boundary regression failed on the preceding revision. Formatting, strict workspace Clippy, dependency layering and WebAssembly passed. The inventory remains 480/546. + +### Returning the cut child of a completed outer quadrant + +At 16 × 32 and seed 614041, Noise BNW Spots 1 v2 now matches all 512 raw F32 pixels on one processor and after an ordinary SBS save reopened on one. The previous release matched 500/512 on both routes. The eight-processor capture moved from 473 to 469/512, with maximum error 2⁻²⁴ on both revisions. Use scale 1, roughness .875, disorder .1875, speed .5, anisotropy .25, non-square expansion off and tile offset (−.1875, .0625). The three independent sizes at these settings give the following results. [Preceding measurements](#filling-a-quadrant-batch-from-two-transferred-children) + +| Size and seed | Original F32 on one processor | Reopened F32 on one processor | Original F32 on eight processors | Maximum F32 error, one / eight | +|---|---:|---:|---:|---:| +| 32 × 16, 614019 | 512/512 | 512/512 | 483/512 | 0 / 2⁻²⁴ | +| 16 × 32, 614041 | 512/512 | 512/512 | 469/512 | 0 / 2⁻²⁴ | +| 32², 614063 | 1,024/1,024 | 1,024/1,024 | 950/1,024 | 0 / 2⁻²³ | + +U8, U16 and F16 each match 2,048/2,048 pixels on all three routes, maximum zero. The four earlier F32 cases still match 2,304/2,304 on one processor and on reopening and 2,146/2,304 on eight, maximum 2⁻²³. The difference at seed 614041 arises when a 5,460-copy batch cuts inside depth-five subtree 797. Four physical copies of that subtree remain. Its next sibling transfers and its final sibling resumes with the cut child. This changes which pair fills the next batch. The renderer uses the subtree copy boundaries and checks that every final stream fits a partial batch. [Renderer](../crates/nodes/src/pattern/tile_runs/inactive_children/outer_transfer.rs) · [Regression tests](../crates/nodes/src/pattern/tile_runs/inactive_children/tests.rs) + +To reproduce the boundary with original inputs, use the [additive square tree, edge placement and signed marker gains](#drawing-the-children-of-a-transferred-quadrant). Number the 81,920 draws from zero. In groups 24, 40, 8, 50, 58, 54 and 62 use widths (8, 8, 8, 2, 2, 2, 2) and move (700 + 17i, 730 + 21i, 702 + 25i, 500 + 9i, 530 + 6i, 341 + 7i, 501 + 8i) squares to the tile edge. Within each group g of width w place extra copy j at draw 1280g + (1777j + 32 + i) mod (1280w). For i = 0, 1 and 2 use 368, 380 and 394 extra copies respectively in group 54. For the boundary controls start at i = 3 and replace the count in group 62 with 499, 500 or 501. At 499, draw 69208 follows 64124. At 500 and 501 it precedes 64124 in both gain directions. + +For the full images use the three boundary fields, unmodified fields i = 3, 5 and 7, and a field carrying the 1,024 subtree copy counts of the 16 × 32 seed. For the last field, if a subtree has c copies, move c − 80 of its squares to the edge at local draw (23j + 7) mod 80. Starting at texel (6, 5), mark (69208,64124), (69214,74376), (64145,74362), (51199,43680) and (43839,2400) in consecutive texels. Use the first three pairs at 499. If a selected draw has an edge copy, advance its index to the next single-copy draw. Render both gain directions and reopen ordinary SBS saves of the same seven fields. + +| Storage, size and seed | Exact original pixels | Exact reopened pixels | Maximum error, original / reopened | +|---|---:|---:|---:| +| U8, 64 × 128, 619499 | 114,688/114,688 | 114,688/114,688 | 0 / 0 | +| U16, 128 × 64, 619521 | 114,688/114,688 | 114,688/114,688 | 0 / 0 | +| F16, 256 × 128, 619541 | 458,752/458,752 | 458,752/458,752 | 0 / 0 | +| F32, 128², 619477 | 229,374/229,376 | 229,370/229,376 | 2⁻²⁵ / 2⁻²⁵ | + +The 56 original frames improved from 917,466 to 917,502 of 917,504 exact pixels. The 56 reopens improved from 917,466 to 917,498. At 499, the second pair still draws in the opposite order on the reference. Change the seed, restore 619477 and repeat fields 499 and 501 in three separate one-processor acquisitions on each route. The one-pixel difference at 499 persists in both gain directions on every repeat. The additional four differences in the first reopened capture disappear in all three repeat acquisitions. Both preceding 48-setting panels also reproduce their earlier exact counts on originals and reopens. + +At 256² compare adjacent single-copy draws in both gain directions for fields i = 0 through 8 and the seed-derived field. Of 772,860 relations, 772,829 agreed in both directions and 31 changed with the gain exchange. For the copies left in the cut subtree, compare against each of the 24 other measured ranges in fields 2, 3, 4, 5, 6, 7, 8 and the seed-derived field. Of 192 relations, 177 agreed in both directions and 15 changed. At 500, 501, i = 3, 5, 7 and in the seed-derived field, a separate 14-pair check agreed in both directions on all 84 relations. Both new regressions failed on the preceding revision. All 548 release tests for the node and evaluation crates passed, together with formatting, strict workspace Clippy, dependency layering and WebAssembly. + +The established 86 original settings for Spots 1, 87 for Spots 1 v2 and 19 ordinary saves of each reproduce all 211 previous output digests. Spots 1 remains at 64/86 exact original frames on one processor and 38/86 on eight. Spots 1 v2 remains at 62/87 and 58/87. The inventory is 480/546. + +### Filling a quadrant batch from two transferred children + +Two more Noise BNW Spots 1 v2 settings match every raw F32 pixel on one processor and after an ordinary SBS save reopened in the reference app. Use scale 1, roughness .875, disorder .1875, speed .5, anisotropy .25, non-square expansion off and tile offset (−.1875, .0625). Counts compare the shared renderer before and after the change. [Previous measurements](#drawing-the-children-of-a-transferred-quadrant) + +| Size and seed | Original on one processor | Reopened on one processor | Original on eight processors | Maximum after, one / eight | +|---|---:|---:|---:|---:| +| 32 × 16, 614019 | 506 → 512/512 | 506 → 512/512 | 479 → 483/512 | 0 / 2⁻²⁴ | +| 16 × 32, 614041 | 500/512 | 500/512 | 473/512 | 2⁻²⁴ / 2⁻²⁴ | +| 32², 614063 | 1,019 → 1,024/1,024 | 1,019 → 1,024/1,024 | 949 → 950/1,024 | 0 / 2⁻²³ | + +U8, U16 and F16 each match 2,048/2,048 pixels on all three routes. Four earlier F32 settings match 2,304/2,304 on one processor and on reopening, and 2,146/2,304 on eight. At seed 614019 the third half needs 87 copies. The first child supplies 85 and the second supplies the remaining two. This changes which siblings return to each unfinished batch. At seed 614063 the last receiver returns two depth-five subtrees. The renderer applies both rules to the physical copy counts of the quadrant tree. [Renderer](../crates/nodes/src/pattern/tile_runs/inactive_children/wide_transfer.rs) · [Regression tests](../crates/nodes/src/pattern/tile_runs/inactive_children/tests.rs) + +To reproduce the boundary, use the [additive-square graph, numbering, edge placement and gains](#drawing-the-children-of-a-transferred-quadrant). In groups 24, 40, 8, 50, 58, 54 and 62, use extra copy counts (680, 680, e, 400, 400, h, 340). With h = 400 and e = 600 the first child supplies all 80 required copies. At e = 599 one copy comes from the second child. The draw at 25152 now precedes 23943, 24708 follows 74015, and 67104 precedes 24733. All three relations reverse at e = 600. At e = 520 the batch takes both children in full. Repeat with (e, h) = (620, 200), (620, 260) and (551, 300) to exercise the smaller subtrees in the last receiver. Swapping the two marker gains gave the same order for all 88 comparisons of the first boundary and all 3,780 comparisons across seven one- or two-subtree controls. + +For the full images use both gain directions at each of the six settings. Place the paired draws at successive texels starting at (6, 5) on the original 128² grid. + +| e, h | Five pairs of draw numbers | +|---|---| +| 600, 400 and 599, 400 | (25152,23943), (24708,74015), (67104,24733), (24645,73825), (24696,72318) | +| 551, 400 and 520, 400 | (30719,2560), (51199,25120), (25199,9240), (79359,23680), (44799,24560) | +| 620, 200 | (30719,2560), (51199,25040), (25119,9240), (79359,23680), (43759,24560) | +| 551, 300 | (30719,2560), (51199,25120), (25199,9240), (79359,23680), (43759,24560) | + +| Storage, size and seed | Original exact pixels | Reopened exact pixels | Maximum, original / reopened | +|---|---:|---:|---:| +| U8, 64 × 128, 618479 | 98,304/98,304 | 98,304/98,304 | 0 / 0 | +| U16, 128 × 64, 618503 | 98,304/98,304 | 98,304/98,304 | 0 / 0 | +| F16, 256 × 128, 618521 | 393,216/393,216 | 393,216/393,216 | 0 / 0 | +| F32, 128², 618461 | 196,605/196,608 | 196,608/196,608 | 2⁻²⁵ / 0 | + +The 48 original images improved from 786,385 to 786,429 of 786,432 exact pixels. All 48 ordinary reopens match 786,432/786,432, up from 786,382. The three differing original pixels occur together in the reversed-gain e = 520 control. Submit that graph again in three separate one-processor acquisitions, changing the seed before restoring 618461. Both gain directions match 16,384/16,384 in every repeat, on originals and saves. The earlier panel of 48 original and 48 reopened controls still matches 786,432/786,432 per route. + +For the second-child order, compare consecutive unwrapped draws in the two gain directions at 256² F32. Use e = 599 and 520, the 1,024 measured subtree counts at seed 614019, and independent fields i = 0 through 8 and 10. Define group counts and placement as in the [preceding field series](#drawing-the-children-of-a-transferred-quadrant), with counts 680 + 53i mod 281, 680 + 71i mod 271, 360 + 19i mod 125, 369 + 11i mod 118, 370 + 13i mod 120 and 340 + 29i mod 167 in groups 24, 40, 50, 58, 54 and 62. In group 8, place (599, 551, 526, 541, 569, 577, 525, 580, 579, 538) extra copies in field order at (991j + 37 + 4i) mod 10240. Include the additional draws in subtrees 312 through 315 for every tested i ≥ 6. All 1,013,019 comparisons across the thirteen fields agreed in both directions. For the smaller last receiver, use the measured subtree counts at seed 614063 and fields i = 5, 6, 7, 8, 9 and 11. Restore the earlier group 8 placement with extra counts (679, 590, 565, 610, 625, 640) in that order. In group 54 use counts (180, 205, 240, 275, 305, 340) with stride 211 and offset 17. These seven fields gave 543,902/543,908 matching comparisons in both directions. The other six changed order when the gains were exchanged in field 11. The 16 × 32 root setting and multi-processor differences remain open. + +The 86 original settings for Spots 1, 87 for Spots 1 v2 and 19 ordinary saves of each graph reproduce all 211 previous output digests. Both new regression tests failed on the preceding revision. All 546 release tests for the node and evaluation crates passed, along with formatting, strict workspace Clippy, dependency layering and WebAssembly. The root inventory remains 480/546. + +### Drawing the children of a transferred quadrant + +Noise BNW Spots 1 v2 now matches 512/512 raw F32 pixels at 32 × 16 and seed 561067 on one processor, up from 497/512. The ordinary MaterialCraft save reopened in the reference app also matches 512/512. Four independent one-processor reference renders gave the same bits at every position. The archived eight-processor frame gives 460/512, up from 459/512, with a maximum error of 2⁻²³. Use scale 1, roughness .875, disorder .1875, speed .5, anisotropy .25, non-square expansion off and tile offset (−.1875, .0625). + +The difference first appeared where two full batches of tile copies pass through a pair of quadrants. Use the [original additive-square graph and draw numbering](#tile-copies-in-the-last-two-active-quadrant-levels). On one processor, moving 360 squares in group 50 to the tile edge makes the first receiver pass a whole sibling and then a half and a quarter of the following sibling to other streams. Their children can reach different batches. Give overlapping marker squares gains of −1 and 2⁻²⁵ on white, and exchange the gains on a second render. The previously reversed pairs (66559, 20480), (76799, 0) and (71679, 40960) each put the first draw before the second on both renders. The renderer uses the physical copy counts at the subtree boundaries. [Renderer](../crates/nodes/src/pattern/tile_runs/inactive_children/wide_transfer.rs) · [Regression tests](../crates/nodes/src/pattern/tile_runs/inactive_children/tests.rs) + +For the first control, move draw `50 × 1280 + (103j + 31) mod 2560` to an edge for j = 0 through 359. For three further controls, take groups (24, 40, 8, 50, 58, 54, 62) with widths (8, 8, 8, 2, 2, 2, 2) and extra copy counts (680, 680, e, 400, 400, 400, 340). In each group g of width w, move draw `1280g + (211j + 17) mod (1280w)` for j starting at zero. With e = 600, 620 or 679, the third leading half needs 80, 60 or one copy from the first child of the transferred quarter to fill its 5,460-copy batch. That cut changes when the remaining children draw. + +For independent inputs, the table gives the extra copy counts in the same group order. In the three eight-group regions, use stride 991 for an odd field number i or 1777 for an even i, with offset 31 + 4i. In the four two-group regions, use stride 233 for an odd i or 103 for an even i, with offset 71 + 5i. In fields 6, 8, 9 and 11, also place `12 + (7i + k) mod 30` draws at the edge within each depth-five subtree k = 312 through 315, starting at draw `80k + (23j + 7) mod 80`. + +| Field | 24 | 40 | 8 | 50 | 58 | 54 | 62 | Adjacent pairs exact in both directions | +|---|---:|---:|---:|---:|---:|---:|---:|---:| +| 1 | 733 | 751 | 600 | 379 | 380 | 383 | 369 | 78,324/78,324 | +| 2 | 786 | 822 | 601 | 398 | 391 | 396 | 398 | 78,127/78,127 | +| 3 | 839 | 893 | 619 | 417 | 402 | 409 | 427 | 77,913/77,913 | +| 4 | 892 | 693 | 651 | 436 | 413 | 422 | 456 | 77,956/77,956 | +| 5 | 945 | 764 | 679 | 455 | 424 | 435 | 485 | 77,732/77,732 | +| 6 | 717 | 835 | 590 | 474 | 435 | 448 | 347 | 77,923/77,923 | +| 8 | 823 | 706 | 610 | 387 | 457 | 474 | 405 | 77,971/77,971 | +| 9 | 876 | 777 | 625 | 406 | 468 | 487 | 434 | 77,732/77,732 | +| 11 | 701 | 919 | 640 | 444 | 372 | 393 | 492 | 77,878/77,878 | + +At 256² F32 and seed 617333 + 13i, compare each pair of consecutive unwrapped draws in the calculated order. Render alternating pairs together, then shift by one to cover the other adjacencies. A separate field used the recorded copy counts of the [1,024 subtrees at seed 561067](#repeated-drawing-quadrants-and-full-batches-in-the-outer-pair). For each subtree k with c copies, move its first c − 80 selections to the edge using the same stride 23 and offset 7. At seed 617333 this gave another 75,742/75,742 exact comparisons. Across the ten fields all 777,298 comparisons agreed in both gain directions, maximum F32 readout error zero. + +For a full-image and save check, render the first control, the three e values and independent fields 4 and 9. Put each pair of markers at the same texel on a 128² grid, starting at (6,5) and advancing one column after each pair. Use both gain directions. + +| Field | Five marker pairs in traversal order | +|---|---| +| Group 50 only | (66559,20480), (76799,0), (71679,40960), (49479,2960), (48557,38555) | +| e = 600, 620 or 679 | (30719,2560), (51199,25040), (25119,9240), (79359,23680), (44799,24560) | +| 4 | (66559,20480), (76799,0), (71679,40960), (50177,15373), (30719,2560) | +| 9 | (66559,20480), (76799,0), (71679,40960), (50112,15375), (30719,2560) | + +| Storage, size and seed | Original exact pixels | Reopened exact pixels | Maximum error on either | +|---|---:|---:|---:| +| U8, 64 × 128, 617513 | 98,304/98,304 | 98,304/98,304 | 0 | +| U16, 128 × 64, 617521 | 98,304/98,304 | 98,304/98,304 | 0 | +| F16, 256 × 128, 617537 | 393,216/393,216 | 393,216/393,216 | 0 | +| F32, 128², 617491 | 196,608/196,608 | 196,608/196,608 | 0 | + +All 48 original renders and all 48 renders from the ordinary save match in full. Previously F32 matched 196,548/196,608 pixels, maximum error 2⁻²⁵ on each route. + +Use the same exposed Spots 1 v2 parameters at three independent seeds. U8, U16 and F16 each match all 2,048 pixels on one processor, eight processors and an ordinary save reopened on one. The following counts use the raw F32 buffers. + +| Size and seed | One processor, before → after | Reopened, before → after | Eight processors, before → after | Maximum after, one / eight | +|---|---:|---:|---:|---:| +| 32 × 16, 614019 | 497 → 506/512 | 497 → 506/512 | 477 → 479/512 | 2⁻²⁴ / 2⁻²⁴ | +| 16 × 32, 614041 | 500 → 500/512 | 500 → 500/512 | 473 → 473/512 | 2⁻²⁴ / 2⁻²⁴ | +| 32², 614063 | 989 → 1,019/1,024 | 989 → 1,019/1,024 | 945 → 949/1,024 | 2⁻²⁵ / 2⁻²³ | + +At seed 561067, the four separate eight-processor renders agreed at 435 of 512 positions. MaterialCraft matches 425/435 of those positions, previously 428/435. Across the four full captures it matches 464, 454, 475 and 469 pixels respectively, with maxima 2⁻²³, 2⁻²⁴, 2⁻²⁴ and 2⁻²³. Ten stable positions still differ. At seed 614019 the third half needs 87 copies and its first transferred child contains 85. The continuation across that boundary and the other two seeds remain open. + +The 86 original Spots 1 settings, 87 original Spots 1 v2 settings and 19 ordinary saves of each graph reproduced the preceding release's raw output digests on all 211 frames. The first graph gives 824,569/841,728 pixels on one processor, 776,831/841,728 on eight and 196,193/196,352 on reopening. The second gives 839,402/842,752, 830,541/842,752 and 137,715/139,008 respectively. In a separate four-setting F32 check at seeds 560971, 560983, 561019 and 561067, all 2,304/2,304 pixels are now exact on one processor and on reopening. On eight processors 2,146/2,304 match, maximum 2⁻²³. [Whole-root format counts and maximum errors](#completing-partial-copy-batches-above-inactive-quadrants) · [Exposed values for the four F32 settings](#tile-copies-in-the-last-two-active-quadrant-levels) + +### Repeated drawing quadrants and full batches in the outer pair + +Start with the [original additive-square graph and its traversal numbering](#tile-copies-in-the-last-two-active-quadrant-levels). Keep both tiling axes and the connected, inactive descendants through depth ten. Between each depth-six quadrant and its children, insert an Iterate with an empty initial branch. On the depth-six branch offset, read the red channel of a 1024² procedural field at texel (256 + x, 512 + y). Here x and y are the 64² quadrant coordinates. Write an integer child count of two for a marked texel or one otherwise, then return a zero offset. Read that count in the Iterate. Each marked depth-six quadrant adds four depth-seven parents and sixteen depth-eight draws. + +Number depth-six quadrants in traversal order, starting at zero. Use six fields with these marked indices. + +| Field | Marked quadrants | +|---|---| +| Control | None | +| First | 0 | +| Receiver | 50 × 64 + 10 | +| Middle | 24 × 64 + 21 and 40 × 64 + 19 | +| Later | 60 × 64 + 12, 62 × 64 + 31 and 48 × 64 + 9 | +| Spread | (211j + 17) mod 4096 for j from 0 through 11 | + +Place a separate square of gain −0.25 in a marked and an unmarked branch. From white, the marked square leaves 0.5 and the unmarked square leaves 0.75. The signed draw-order markers outside the repeated branches agree in both gain directions on all 686 pairs. Previously an inner repeat selected traversal order for the tree. Recording the physical copies at each actual depth-five boundary lets the renderer retain batch order when a subtree contains more than sixteen drawing parents. + +For each field, render both marker directions at 256² F32 with seed 613117, 64 × 128 U8 with seed 613139, 128 × 64 U16 with seed 613141 and 256 × 128 F16 with seed 613163. Reopen the ordinary MaterialCraft save in the reference app and repeat all 48 frames. + +| Output | Original exact pixels | Reopened exact pixels | Maximum error on either | +|---|---:|---:|---:| +| U8 | 98,304/98,304 | 98,304/98,304 | 0 | +| U16 | 98,304/98,304 | 98,304/98,304 | 0 | +| F16 | 393,216/393,216 | 393,216/393,216 | 0 | +| F32 | 786,432/786,432 | 786,432/786,432 | 0 | + +The previous release missed 142 F32 pixels on each route, maximum 2⁻²⁵. All three other formats retained their previous bits. + +To isolate two submission boundaries separately, leave the Iterate count at one. Number 64 depth-three groups of 1,280 draws each. In a leading half starting at group 24, 40 or 8, move draw `1280g + (1777j + 31) mod 10240` to one tile edge for consecutive j starting at zero. At 679 extra copies the half contains 10,919 copies. At 680 it contains 10,920 and submits its second complete batch before the next half starts. Adding a 681st copy leaves that copy pending. Vary each half independently and then fill two or three halves together. + +For the outer pair, group 62 and its following group continue into groups 48 and 49. In either two-group interval move draw `1280g + (233j + 71) mod 2560` to one tile edge. With 339 extra copies in groups 62–63, the outer pair follows the first receiver. At 340 extras it fills a batch of 5,460 and precedes that receiver. The same threshold holds when the extra copies are in groups 48–49 or alternate between the two intervals. A dense field with 5,537 outer copies matched all 537 signed comparisons against the leading halves, receivers and later draws. The final 77 copies were outside that full batch. Separate, underfilled fields still have differences in the order of their later draws. [Boundary regressions](../crates/nodes/src/pattern/tile_runs/inactive_children/tests.rs) · [Repeated Iterate regression](../crates/nodes/src/pattern/tests/terminal_quadrants.rs) + +For whole-image checks, use five disjoint pairs on row 5 in columns 6 through 10 of the 128² marker field. Render both gain directions at 128² F32, 64 × 128 U8, 128 × 64 U16 and 256 × 128 F16 with seeds 614131, 614159, 614171 and 614189 respectively. In the last two fields put 680 extra copies in each leading half starting at group 24 or 40. Alternate the outer extras between groups 62 and 48, advancing the local index after each pair. + +| Placement and extra copies | Traversal indices for the five marker pairs | +|---|---| +| Leading half, 679 | (38865,51618), (36173,15446), (36836,55838), (37269,12312), (39867,54119) | +| Leading half, 680 | (38865,51618), (36173,15446), (36836,55838), (37269,12312), (39868,54119) | +| Outer group 62, 339 | (63311,64861), (62714,66424), (61880,65431), (81655,64132), (63326,64047) | +| Outer group 62, 340 | (63312,64861), (62715,66424), (61881,65431), (81656,64132), (63327,64047) | +| Alternating, 339 | (63266,65301), (62624,64826), (61727,65835), (81486,64277), (63281,66203) | +| Alternating, 340 | (63267,65301), (62625,64826), (61727,65835), (81486,64277), (63282,66203) | + +The 48 originals and their 48 ordinary saves each match 786,432/786,432 pixels, maximum zero. Each route gives 98,304 exact U8, 98,304 exact U16, 393,216 exact F16 and 196,608 exact F32 pixels. The previous release gave 786,408/786,432 on each route with a maximum F32 error of 2⁻²⁵. + +In the second Spots 1 graph, set scale to 1, roughness to 0.875, disorder to 0.1875, speed to 0.5, anisotropy to 0.25, non-square expansion to false and tile offset to (−0.1875, 0.0625). In a MaterialCraft trace, a diagnostic draw on the initial branch of each depth-seven Iterate distinguished one visit from two. Removing the diagnostic stamps from the trace left every original stamp's geometry unchanged. At 32 × 16 and seed 561067, 15,379 parents drew once and 1,005 drew twice. Their 1,024 depth-five subtrees contained 16 through 22 drawing parents. The first three leading halves, in submission order, contained 10,949, 11,084 and 10,849 physical copies. + +| Size and seed, F32 | One processor, before → after | Fresh eight processors, before → after | Ordinary save, before → after | Maximum error after, one / eight / save | +|---|---:|---:|---:|---:| +| 32 × 16, 561067 | 460 → 497/512 | 472 → 467/512 | 460 → 497/512 | 2⁻²⁴ / 2⁻²⁴ / 2⁻²⁴ | +| 32 × 16, 614019 | 465 → 497/512 | 465 → 477/512 | 465 → 497/512 | 2⁻²⁴ / 2⁻²³ / 2⁻²⁴ | +| 16 × 32, 614041 | 462 → 500/512 | 475 → 473/512 | 462 → 500/512 | 2⁻²⁴ / 2⁻²⁴ / 2⁻²⁴ | +| 32², 614063 | 940 → 989/1,024 | 927 → 945/1,024 | 940 → 989/1,024 | 2⁻²⁴ / 2⁻²³ / 2⁻²⁴ | + +Across the three new seeds U8, U16 and F16 each matched all 2,048/2,048 pixels on one processor, on eight and on reopening, maximum zero. The archived eight-processor F32 capture at seed 561067 gives 459/512, previously 470/512. Its maximum error rose from 2⁻²⁴ to 2⁻²³. The other three [earlier F32 settings](#completing-partial-copy-batches-above-inactive-quadrants) stayed at 256/256, 512/512 and 1,024/1,024 on one processor and on reopening. + +Repeat the 32 × 16 F32 at seed 561067 in four separate reference renders per processor count. All 512 positions were identical across the four one-processor renders. On eight processors, 435/512 positions were identical across the four, and MaterialCraft matched 428 of those 435. It matched at least one of the four values at 505/512 positions. Against individual renders it matched 460, 463, 480 and 471 pixels, maximum 2⁻²⁴ in each. Two eight-processor reference renders differed by as much as 2⁻²³. The seven stable positions that differ from MaterialCraft remain open. + +Across the established 87 Spots 1 v2 settings and 19 ordinary saves, all 106 output digests match the previous release. The counts remain 839,402/842,752 on one processor, 830,541/842,752 on eight and 137,715/139,008 after reopening. Whole-frame counts remain 62/87, 58/87 and 13/19 respectively. [Counts and maximum errors by output format](#completing-partial-copy-batches-above-inactive-quadrants) + +The first Spots 1 graph retained all 86 original and 19 reopened frame digests. It matches 824,569/841,728 on one processor, 776,831/841,728 on eight and 196,193/196,352 after reopening. Both roots remain in progress. The three new regressions failed against the previous implementation. All 542 node and evaluator release tests passed with the changes. Formatting, strict workspace Clippy, dependency layering and WebAssembly passed. + +## 2026-11-25 root comparisons + +### Completing partial copy batches above inactive quadrants + +Use the [two active drawing levels and the original edge-square field](#which-half-quadrant-completes-the-next-copy-batch). The 64 depth-three quadrants each contain 16 depth-five subtrees. After the first eleven batches fill, two receiving streams can transfer different children of the same pending sibling. Finishing those streams in traversal order changed the sum of overlapping F32 draws. MaterialCraft now splits the pending sibling at its depth-five boundaries and counts each physical tile copy when a receiving stream fills. [Shared traversal](../crates/nodes/src/pattern/tile_runs/inactive_children/completion.rs) · [Regression tests](../crates/nodes/src/pattern/tile_runs/inactive_children/tests.rs) + +To vary the incoming work, move draws `50 × 1280 + 2 + 23j` to one tile edge for consecutive j starting at zero. Compare zero, nineteen and twenty additional copies. Independently move forty or seventy draws at `g × 1280 + 1 + 9j` in group g = 24 or 40. At 256² F32 and seed 612671, leave the wrapped squares active. Place consecutive pairs of single-copy draws on separate pixels in two alternating sets so each draw has only one destination per render. Exchange the gains −1 and 2⁻²⁵ to verify the order in both directions. The four fields with 40/0, 0/40, 40/40 and 70/70 extra copies in groups 24/40 matched all **327,376/327,376** adjacent comparisons, maximum readout error zero. The four physical-copy densities taken from the 16² default and seeds 560971, 560983 and 561019 matched all 80,688, 80,690, 80,660 and 80,568 adjacent comparisons respectively. + +The stream starting in groups 60–61 can also fill a 5,460-copy batch. With twenty extra copies in group 50, add e copies to groups 60–61 by visiting draw `60 × 1280 + (211j + 17) mod 2560`. Move the first ⌊e/3⌋ squares to a corner and the next e mod 3 squares to one edge. At e = 2,580 the stream fills after the eleventh earlier batch. At 2,740 it fills after the seventh and at 2,900 after the third. Fifteen fields at and around the boundaries matched **1,214,619/1,214,619** adjacent comparisons in both gain directions. Sixteen further fields independently varied the work arriving from groups 24 and 40. Of their 1,294,534 adjacent comparisons, 1,294,516 agreed in both directions. In the remaining 18 the two gain directions returned different orders. A full stream involving groups 62–63 and 48–49 can redistribute more children and remains open. + +For whole images, place five disjoint marker pairs on row 5, columns 6 through 10 of the 128² field. Render each gain direction at 128² F32 with seed 560071, 64 × 128 U8 with seed 560081, 128 × 64 U16 with seed 560107 and 256 × 128 F16 with seed 560131. Open the ordinary MaterialCraft save in the reference app and repeat all 48 frames. + +| Extra copies | Pairs of traversal indices in column order | +|---|---| +| Zero | (67293,23561), (23911,72552), (18729,43941), (16934,72444), (79054,68386) | +| 40 in group 24 | (68062,73183), (67972,72940), (67359,67445), (18729,72736), (67638,73004) | +| 20 in group 50 | (24093,77770), (79055,73362), (18729,44010), (80854,23953), (80057,62891) | +| 20 in group 50 and e = 2,580 | (77040,24132), (23563,8764), (23767,43954), (43972,10049), (72400,23620) | +| 20 in group 50 and e = 2,899 | (77666,70663), (77953,47021), (76882,58343), (78376,40501), (77690,63909) | +| 20 in group 50 and e = 2,900 | (77683,66417), (78114,25244), (78527,74433), (79257,7611), (77666,70663) | + +| Storage | Original, exact pixels / total | Reopened, exact pixels / total | Maximum error on either | +|---|---:|---:|---:| +| U8 | 98,304/98,304 | 98,304/98,304 | 0 | +| U16 | 98,304/98,304 | 98,304/98,304 | 0 | +| F16 | 393,216/393,216 | 393,216/393,216 | 0 | +| F32 | 196,608/196,608 | 196,608/196,608 | 0 | + +Previously F32 matched 196,550/196,608 on each route with maximum error 2⁻²⁵. The [earlier eight four-format controls](#tile-copies-in-the-last-two-active-quadrant-levels) with inactive descendants also reached 131,072/131,072 on each route, up from 131,070. The eight controls with the plain tree matched 131,072/131,072 on each route. + +For the intact second Spots 1 root, the 16² F32 original at seed 560971 improved from 254/256 to 256/256 on one processor. The 16 × 32 original at seed 560983 improved from 507/512 to 512/512. Each ordinary save also matches every pixel, maximum zero. The explicit eight-processor captures match 227/256 and 456/512 respectively, maximum 2⁻²⁴ in both. The default 16² and independent 32² seed 561019 retain all 1,280 exact pixels on one processor and on reopening. The 32 × 16 seed 561067 has 17,389 active depth-seven draws and 69,556 depth-eight draws. It still matches 460/512 on one processor and on reopening, maximum 2⁻²³, and 470/512 on eight processors, maximum 2⁻²⁴. [Exposed settings and processor controls](#tile-copies-in-the-last-two-active-quadrant-levels) + +The full 87-setting one-processor comparison gained four complete frames. At 128² and seed zero, U16 rose from 16,383 to 16,384 exact pixels and F32 from 16,231 to 16,384. At 256² and seed zero, U16 rose from 65,534 to 65,536 and F32 from 65,007 to 65,536. The eight-processor captures of these same settings give 16,379 and 14,357 exact pixels at 128² and 65,514 and 58,403 at 256², in U16 and F32 respectively. These account for a net gain of 685 exact one-processor pixels and a loss of 157 exact pixels against the archived eight-processor frames. The 19 saved output digests retained their previous values. [Identical-input reference repeats](#which-half-quadrant-completes-the-next-copy-batch) + +| Spots 1 v2 storage | One processor · exact pixels · maximum | Eight processors · exact pixels · maximum | Ordinary save · exact pixels · maximum | +|---|---:|---:|---:| +| U8 | 141,568/141,568 · 0 | 141,568/141,568 · 0 | 32,768/32,768 · 0 | +| U16 | 295,674/295,680 · 1 | 295,650/295,680 · 1 | 12,031/12,032 · 1 | +| F16 | 108,800/108,800 · 0 | 108,797/108,800 · 2⁻¹¹ | 1,024/1,024 · 0 | +| F32 | 293,360/296,704 · 2⁻²³ | 284,526/296,704 · 2⁻²³ | 91,892/93,184 · 2⁻²³ | +| All formats | 839,402/842,752 | 830,541/842,752 | 137,715/139,008 | +| Whole frames | 62/87 | 58/87 | 13/19 | + +In the first Spots 1 graph, all 86 original and 19 reopened output digests agree with the previous build. The counts are 824,569/841,728 on one processor, 776,831/841,728 on eight and 196,193/196,352 on reopening. Both roots remain in progress. All 539 node and evaluator release tests passed. Formatting, strict workspace Clippy, dependency layering and WebAssembly passed. + +### Which half-quadrant completes the next copy batch + +Use the [two active drawing levels above two inactive levels](#tile-copies-in-the-last-two-active-quadrant-levels). At 128² F32 and seed 91771, number the 81,920 active draws in traversal order and divide them into 64 groups of 1,280. The incoming pairs start in groups 50, 58 and 54 and enter groups 16, 0 and 32 respectively. To add one physical copy, move a single square to the horizontal tile edge. Keep the signed markers on interior squares and repeat each comparison with the gains exchanged. + +In the first incoming pair, move draw `50 × 1280 + 2 + 23j` for consecutive j starting at zero. With 19 edge draws, the first receiver transfers a depth-five sibling and the remainder of groups 24–31 submits ahead of the remainder of groups 40–47. With 20 edge draws, the receiver transfers a depth-four sibling and the two remainders exchange places. In both cases each remainder starts after its first 5,460 copies and takes enough copies from groups 52–53 or 56–57 to complete the next batch. Five disjoint marker pairs change order at that single-copy boundary. [Measured pairs and regression tests](../crates/nodes/src/pattern/tile_runs/inactive_children/tests.rs) + +Vary all three incoming pairs independently over zero and twenty additional copies. Then move 19, 20 or 21 draws in just one pair, in the receiving half or after the first cut. The order calculated from the first transfer matched 12,240/12,240 signed comparisons across eighteen fields, maximum F32 readout error zero. Independently moving 39, 40 or 41 draws in the later halves or their partners produced 5,440/5,440 agreements. For a second spacing, move the second child at offset `2 + 5j` in group 50. Eleven fields with 40 through 320 extra copies matched another 7,480/7,480 comparisons. At 360, 400, 450 and 490 extra copies the first transfer was larger. Neither order accounted for all 680 comparisons on any of those four fields. + +After those batches, the first receiving half submits its tail, followed by the siblings deferred in the middle receiver and the last receiver's tail. This continuation also depends on whether the third leading half can fill another batch with its transferred siblings. Seven separate underfilled fields gave 660/660 signed agreements apiece around these boundaries. In a field with twenty edge squares per group, reversing the gains changed 79/660 inferred comparisons. The remaining 581 agreed. The denser fields that can fill this third batch retain the earlier traversal. [Shared copy calculation](../crates/nodes/src/pattern/tile_runs/inactive_children.rs) + +For an independent whole-image check, use the nine marker pairs in the two regression tests above. Split pairs sharing a draw between renders. Use zero, nineteen and twenty edge draws, both gain directions and the [four sizes, seeds and formats](#tile-copies-in-the-last-two-active-quadrant-levels). The 48 original frames match 786,432/786,432 pixels and their 48 ordinary saves also match 786,432/786,432, maximum zero. Each series previously matched 786,396 pixels with maximum error 2⁻²⁵. + +The earlier four-format procedural series with inactive descendants now matches 131,070/131,072 pixels on originals and again on ordinary saves, up from 131,066 on each. Each remaining difference is one F32 pixel of magnitude 2⁻²⁵ in one of the two gain directions. The corresponding series terminating at the last drawing level retained 131,072/131,072 on each pass, maximum zero. + +The following Noise BNW Spots 1 v2 results use the [five F32 settings and parameter values](#tile-copies-in-the-last-two-active-quadrant-levels). The seven-processor and explicitly masked eight-processor columns come from separate desktop captures. + +| Root size and seed | Previous one processor | Current one processor | Seven processors | Eight processors | Ordinary save | Maximum across current captures | +|---|---:|---:|---:|---:|---:|---:| +| 16², seed 0 | 251/256 | 256/256 | 228/256 | 233/256 | 256/256 | 2⁻²³ | +| 16², seed 560971 | 249/256 | 254/256 | 242/256 | 225/256 | 254/256 | 2⁻²⁴ | +| 16 × 32, seed 560983 | 503/512 | 507/512 | 507/512 | 458/512 | 507/512 | 2⁻²³ | +| 32², seed 561019 | 1,021/1,024 | 1,024/1,024 | 1,024/1,024 | 1,003/1,024 | 1,024/1,024 | 2⁻²⁴ | +| 32 × 16, seed 561067 | 460/512 | 460/512 | 460/512 | 470/512 | 460/512 | 2⁻²³ | + +To measure the reference's repeatability, submit the identical 16² seed-zero F32 graph three more times with the same output and intermediate observations and restore the original processor mask after each acquisition. All four one-processor reference frames agree at 256/256 pixels. Across four explicitly verified eight-processor frames, 220/256 pixel positions held the same value in every frame. Pairwise agreement ranged from 231/256 to 239/256, with maximum pairwise error 2⁻²⁴. MaterialCraft matches 213 of those 220 stable positions and 246/256 positions in at least one of the four frames. Ten positions differ from every eight-processor capture. These repeated reads measure separate effects from the reproducible draw-order boundary. + +The original one- and eight-processor reference panels also differ with identical graph inputs. In the first Spots 1 graph, the two reference captures agree at 772,695/841,728 pixels across 86 settings. In the second they agree at 829,601/842,752 across 87. For the second graph, the F32 reference captures agree at 283,592/296,704 pixels, maximum 2⁻²³. U8 agrees at 141,568/141,568, U16 at 295,644/295,680 with maximum 1, and F16 at 108,797/108,800 with maximum 2⁻¹¹. + +Across the [87 original settings and 19 ordinary saves](#copy-batches-from-the-final-quadrant-pair-and-the-following-group), five settings gained exact one-processor pixels, including the default 256² F32 frame, which rose from 64,012 to 65,007 of 65,536. Four settings lost exact pixels against the archived eight-processor captures. In total, 58/87 frames match in full on one processor and 58/87 on eight. All 19 saved output digests retained their previous values, with 13 complete matches. Maximum errors below use each format's stored units. + +| Storage | One processor · exact pixels · maximum | Eight processors · exact pixels · maximum | Ordinary save · exact pixels · maximum | +|---|---:|---:|---:| +| U8 | 141,568/141,568 · 0 | 141,568/141,568 · 0 | 32,768/32,768 · 0 | +| U16 | 295,671/295,680 · 1 | 295,653/295,680 · 1 | 12,031/12,032 · 1 | +| F16 | 108,800/108,800 · 0 | 108,797/108,800 · 2⁻¹¹ | 1,024/1,024 · 0 | +| F32 | 292,678/296,704 · 2⁻²³ | 284,680/296,704 · 2⁻²³ | 91,892/93,184 · 2⁻²³ | +| All formats | 838,717/842,752 | 830,698/842,752 | 137,715/139,008 | + +The one-processor total gained 1,258 exact pixels and the eight-processor total lost 447. In the first Spots 1 graph, all 86 original and 19 reopened output digests retained their previous values. Totals remain 824,569/841,728 pixels on one processor, 776,831/841,728 on eight and 196,193/196,352 in the saves. Both roots remain in progress. All 536 node and evaluator release tests passed, as did formatting, strict workspace Clippy, dependency layering and WebAssembly checks. + +### Tile copies in the last two active quadrant levels + +Use the [independent additive-square graph](#final-pattern-draws-above-inactive-quadrants-in-spots-1-v2). Give every quadrant through depth six four children. Each of the 16,384 depth-seven parents and its four depth-eight children emits one square. Number those 81,920 draws in traversal order starting at zero. Set roughness to zero, use a white background and position each signed pair at one pixel center. With gains −1 and 2⁻²⁵, a result of 2⁻²⁵ means the negative square drew first. Exchange the gains for the second read. Keep all unmarked draws active. + +First terminate the tree at depth eight. Divide the draws into 64 equal depth-three quadrants. In each group, select four or twenty evenly spaced children from slots 2, 3 and 4 of the five-draw sequence. Center those squares at x = 0 for horizontal tiling, or at y = 0 for vertical tiling. Each adds one physical copy. For each density, horizontal, vertical and both-axis tiling gave 300/300 expected comparisons in both gain directions. The untiled single-copy field gave another 300/300. The measured F32 ordering error was zero at every marked pixel. The shared renderer now counts these copies when just one axis tiles. [Traversal and whole-graph regressions](../crates/nodes/src/pattern/tests/terminal_quadrants.rs) + +For the two-child control, keep only the first and third child connections. Use 400 disjoint pairs at 128² F32, seed 91771. In the wrapped settings, move the third draw of every 32nd parent to the selected edge. On the four-child format control, compare both gain directions at 128² F32, 64 × 128 U8, 128 × 64 U16 and 256 × 128 F16, at seeds 560071, 560081, 560107 and 560131 respectively. Save and reopen each graph in both applications. + +| Original procedure | Previous exact pixels | Current exact pixels | Current exact reopened pixels | Maximum current error | +|---|---:|---:|---:|---:| +| Two children, horizontal tiling, interior squares | 32,436/32,768 | 32,768/32,768 | 32,768/32,768 | 0 | +| Two children, vertical tiling, edge squares | 32,438/32,768 | 32,768/32,768 | 32,768/32,768 | 0 | +| Two children, horizontal tiling, edge squares | 32,430/32,768 | 32,768/32,768 | 32,768/32,768 | 0 | +| Two children, both axes, edge squares | 32,768/32,768 | 32,768/32,768 | 32,768/32,768 | 0 | +| Four children, horizontal tiling, four formats | 131,058/131,072 | 131,072/131,072 | 131,072/131,072 | 0 | +| Four children above two inactive levels, same formats | 131,062/131,072 | 131,066/131,072 | 131,066/131,072 | 2⁻²⁵ | + +The previous reopened counts matched the previous original counts. Previous nonzero maxima were 2⁻²⁵. The six remaining differences in each four-format series with inactive descendants are F32 pixels. Its U8, U16 and F16 frames match throughout. + +With both inactive levels connected and one copy per draw, compare consecutive draws in a proposed order on two disjoint sets of pairs. Put pair number i at pixel (2 + i modulo 251, 2 + floor(i/251)) in a 256² F32 image at seed 612671. Four renders cover both sets and both gain directions. A 29-interval reconstruction missed three of 81,919 adjacent pairs. Independently resolving the split intervals and measuring the twelve new adjacencies gives 81,919/81,919 for the revised 38 intervals, maximum signed-readout error zero. To reproduce the measurement, expand each half-open parent interval below in ascending order and emit draws 5p through 5p+4 for each parent p. [Shared physical-copy calculation](../crates/nodes/src/pattern/tile_runs/inactive_children.rs) + +```text +6144..7236 10240..11332 2048..3140 12800..13312 4096..4688 4720..4736 +4800..5864 14848..15360 0..592 624..1704 13824..14336 8192..8784 +8816..9896 7236..8192 13312..13448 11332..12288 14336..14472 5864..6144 +592..624 9896..10240 13456..13472 1704..2048 8784..8800 14480..14496 +15360..15872 4688..4704 8800..8816 15872..16384 12288..12800 4704..4720 +14472..14480 14512..14848 13448..13456 13488..13824 14496..14512 3140..4096 +4736..4800 13472..13488 +``` + +For the first nine full batches, each of three half-quadrants submits 5,460 physical copies. The receiving half-quadrants each combine two incoming subtrees with their own draws. When a batch fills, the next siblings may continue later. A depth-five sibling transfer in the first receiver can also defer one or two depth-four subtrees, depending on how many siblings are pending. On a field with unevenly spaced edge and corner copies, treating both transfers alike missed 24/668 signed comparisons. Accounting for both pending depth-four siblings matched 670/670 fresh comparisons around the revised boundaries. The same 330 signed pairs also agreed with unit-window reference reads when both windows were translated by (.125, −.25), doubled about the center, or enlarged only vertically. The maximum error in those three comparisons was zero. + +For the uneven field, use a PCG64 generator initialized with seed 681779. In each consecutive 1,280-draw group g, take an unordered sample without replacement of 5 + ((23g) modulo 47) draws from slots 2 through 4. Use the generator's sample order. Place selections 0, 7, 14 and so on at (0,0) and the other selected squares at (0,.90625). Use (.875,.90625) for unmarked interior squares. Place signed markers only on single-copy draws. The test uses 128² F32 at seed 91771 and a 1024² procedural lookup field. + +The following whole-root F32 counts use Noise BNW Spots 1 v2. Leave unspecified parameters at their defaults. For the last three settings use scale 1 and disable non-square expansion. The four independent seeds supplement the existing 87-setting series. + +| Root size, seed and changed parameters | Earlier one processor | Current one processor | Seven processors | Verified eight processors | Ordinary save | Maximum across current captures | +|---|---:|---:|---:|---:|---:|---:| +| 16², seed 0, defaults | 232/256 | 251/256 | 233/256 | 236/256 | 251/256 | 2⁻²³ | +| 16², seed 560971, defaults | 230/256 | 249/256 | 239/256 | 226/256 | 249/256 | 2⁻²⁴ | +| 16 × 32, seed 560983, roughness 1, disorder 0, tile offset (.125, .25) | 468/512 | 503/512 | 503/512 | 456/512 | 503/512 | 2⁻²³ | +| 32², seed 561019, roughness .625, disorder .25, speed .375, anisotropy 0 | 999/1,024 | 1,021/1,024 | 1,021/1,024 | 1,002/1,024 | 1,021/1,024 | 2⁻²⁴ | +| 32 × 16, seed 561067, roughness .875, disorder .1875, speed .5, anisotropy .25, tile offset (−.1875, .0625) | 460/512 | 460/512 | 460/512 | 470/512 | 460/512 | 2⁻²³ | + +The capture log records seven eligible logical processors for the intermediate-stage and four independent-seed series previously labeled eight. Repeating those ten settings with an explicit eight-processor mask verified the fourth result column. At seed zero, the previous renderer matched 241/256 on the seven-processor capture and 237/256 on the fresh eight-processor capture. The two reference captures agree on 236/256 pixels, maximum 2⁻²⁴. The final setting draws 86,945 stamps and includes an additional active pass. It retains 52 differing pixels on one processor, seven processors and the ordinary save. + +The reference also varied across identical one-processor renders. On the single-copy field, compare four evenly spaced interior draws from each depth-five subtree in the first eight depth-three quadrants of each receiving half with distinct draws from depth-three quadrants 58, 54 and 62 respectively. This gives 1,536 pairs. Render both gain directions at 128² F32 with seed 91771, then repeat each exact input three times. Against the first frame, the three repeats in the original gain direction matched 15,934/16,384, 15,934/16,384 and 15,673/16,384 pixels, maximum 2⁻²⁵. All three reverse-gain repeats matched 16,384/16,384, maximum zero. Comparing the order inferred from both directions within each acquisition gave 1,086, 1,536, 1,536 and 1,211 agreements out of 1,536. No root status changed on these samples. + +Across the established 87 original settings, six gained exact one-processor pixels and 57 match in full. The default 256² F16 frame gained its last four pixels. At 128² and 256² F32 the default gained 1,167 and 4,757 pixels respectively. The 87-setting reference captures do record eight eligible processors. Three of those settings improved, three declined and 58 match in full. All 19 reopened frame digests retained their previous values, with 13 exact across applications. [Original sizes, seeds and parameters](#copy-batches-from-the-final-quadrant-pair-and-the-following-group) + +| Stored pixels | One processor · exact · maximum | Eight processors · exact · maximum | Ordinary save · exact · maximum | +|---|---:|---:|---:| +| U8 | 141,568/141,568 · 0 | 141,568/141,568 · 0 | 32,768/32,768 · 0 | +| U16 | 295,662/295,680 · 1 | 295,656/295,680 · 1 | 12,031/12,032 · 1 | +| F16 | 108,800/108,800 · 0 | 108,797/108,800 · 2⁻¹¹ | 1,024/1,024 · 0 | +| F32 | 291,429/296,704 · 2⁻²³ | 285,124/296,704 · 2⁻²³ | 91,892/93,184 · 2⁻²³ | +| All formats | 837,459/842,752 | 831,145/842,752 | 137,715/139,008 | + +The one-processor total gained 5,953 exact pixels and the eight-processor total lost 166. The first Spots 1 graph retained all 86 original and 19 reopened counts. Two previously complete graph bodies with depth-eight quadrants retained 8,192/8,192 pixels each at 32 × 64 F32 and 64 × 32 U8, U16 and F16. All 534 release tests for the node and evaluator crates passed, along with formatting, strict workspace Clippy, dependency layering and WebAssembly checks. + +### Full copy batches received across repeated quadrant trees + +Use the [overlapping square fixture](#pending-quadrant-siblings-and-the-first-full-receiving-batch) with an outer iteration of two, three or four trees and an unselected depth-ten branch. Keep the white background, additive gains −1 and 2⁻²⁵, and ordinary square gain 2⁻⁷⁶. Number each level's quadrants from zero in traversal order within its tree. A sibling left by the first tree can fill a receiving group's next batch. When it fills in the last incoming child, the group submits immediately before its own carried pair. The three pairs begin at second-tree depth-two quadrants 6, 10 and 2. Fourteen independently generated copy fields, including 5,459, 5,460 and 5,461 copies and two or three receivers filling together, confirmed 3,832/3,832 ordering comparisons in both gain directions. Six separate fields confirmed 6,450/6,450 comparisons through the first thirteen batches after the earlier sibling transfer. [Shared quadrant traversal](../crates/nodes/src/pattern/underfilled_quadrants.rs) + +For a two-pass F32 check, mark second-tree depth-five quadrants 880 and 671. Move the terminal squares below second-tree quadrants 864 through 869 to the corner, then include 870. The receiver goes from 5,336 to 5,528 copies and the sample at (8,8) changes from zero to 2⁻²⁵. Repeat with markers 943 and 169, moving quadrants 928 through 930 and then including 931. This gives 5,442 and 5,634 copies and the same change. Marking second-tree quadrants 939 and 169 and moving first-tree quadrant 928 also gives 2⁻²⁵. The signed order holds with reversed gains and additional active trees. [Whole-graph regressions](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +Later in the second tree, the lower and upper paired batches can both precede the last child's batch, including with a third or fourth tree active. The ordering of a full receiver depends on when it reaches 5,460 copies. In the signed 32² field, add 192 copies under first-tree depth-three quadrant 39. Starting twelve visits into second-tree depth-three quadrant 20 in traversal order, change consecutive one-copy squares to four copies at the corner, with one extra copy on each remaining square needed to reach the stated increment. Increments of 846, 847 and 848 give 5,459, 5,460 and 5,461 total copies including the last child's handoff. The last child precedes the receiver in all nine sampled pairs per field. Increments of 931, 932 and 933 give 5,459, 5,460 and 5,461 copies *before* that handoff. The last child precedes the receiver in 9/9, 0/9 and 0/9 pairs respectively. On the separate quadrant-19 field with 1,000 extra copies, 132 of 234 first comparisons changed on reversing the gains. All 234 reproduced on a fresh capture, including the nine receiver comparisons. [Receiving ranges and boundary regression](../crates/nodes/src/pattern/underfilled_quadrants/remaining.rs) + +For the four-format controls, use 32² F32 at seed 41384, 16 × 32 U8 at 41484, 32 × 16 U16 at 41588 and 64 × 32 F16 at 41692. In the repeated-pair controls, compare second-tree depth-three quadrants 56 and 48 in both gain directions, compare 52 with quadrant 0 on the following tree when present, shift first-tree depth-five quadrant 624 to the tile corner, and repeat the first-tree 32/30 marker with quadrant 928 wrapped. The receiving-group controls use the three marker pairs above, with neighboring densities, reversed gains, and two to four trees. The earlier control sets keep the settings recorded in the linked fixtures. + +| Procedural controls | Graphs | Exact original pixels | Exact reopened pixels | Maximum in either | +|---|---:|---:|---:|---:| +| Receiving groups and their neighboring thresholds | 11 | 45,056/45,056 | 45,056/45,056 | 0 | +| Carried pairs in the second through fourth trees | 15 | 61,440/61,440 | 61,440/61,440 | 0 | +| Earlier sibling boundaries and reversals | 12 | 49,152/49,152 | 49,151/49,152 | 2.64697796e−23 | +| Lower, upper and last depth-three pairs | 9 | 36,837/36,864 | 36,846/36,864 | 2⁻²⁵ | +| Earlier receiving group, neighboring densities and reversals | 9 | 36,864/36,864 | 36,864/36,864 | 0 | + +Across the 86 Spots 1 settings, one-processor agreement increases from 824,258 to 824,569 of 841,728 pixels. Sixteen settings improve and the 64 previously exact frames stay exact. Eight-processor agreement goes from 776,866 to 776,831, with four settings improving, eleven declining and 38 exact frames. The 19 ordinary saves go from 196,191 to 196,193 of 196,352 pixels, with 16 exact frames. [Earlier whole-root procedure](#final-copy-batches-in-one-and-two-quadrant-trees) + +| Storage | One processor · exact pixels · maximum | Eight processors · exact pixels · maximum | Ordinary save · exact pixels · maximum | +|---|---:|---:|---:| +| U8 | 108,800/108,800 · 0 | 108,799/108,800 · 1 | 90,112/90,112 · 0 | +| U16 | 328,399/328,448 · 1 | 328,244/328,448 · 1 | 93,693/93,696 · 1 | +| F16 | 108,800/108,800 · 0 | 108,798/108,800 · 4.88281250e−4 | 6,400/6,400 · 0 | +| F32 | 278,570/295,680 · 2.38418579e−7 | 230,990/295,680 · 3.57627869e−7 | 5,988/6,144 · 1.19209290e−7 | + +The independent square and rectangular F32 comparisons retain different scores on the one-processor, seven-processor and reopened captures. + +| Earlier whole-root F32 settings | One processor · exact pixels · maximum | Seven processors · exact pixels · maximum | Ordinary save · exact pixels · maximum | +|---|---:|---:|---:| +| Eight settings with changed seeds, sizes and disorder | 25,879/26,624 · 1.19209290e−7 | 19,433/26,624 · 2.38418579e−7 | 26,350/26,624 · 1.19209290e−7 | +| Six additional rectangular settings | 20,989/21,504 · 1.78813934e−7 | 17,063/21,504 · 1.78813934e−7 | 21,187/21,504 · 1.19209290e−7 | +| Eight scale-one settings | 11,520/11,520 · 0 | 8,609/11,520 · 2.38418579e−7 | 11,500/11,520 · 1.19209290e−7 | + +Of the 66 open root graph bodies, 64 contain a quadrant stage and seven have a stage with a connected depth of ten. Only this Spots 1 stage declares potential draws at every depth from two through eight, which this shared traversal path requires. Mixed copy densities, later groups and worker-dependent outputs still differ. The inventory remains 480/546. [Additional F32 settings and seeds](#pending-quadrant-siblings-and-the-first-full-receiving-batch) + +### Final pattern draws above inactive quadrants in Spots 1 v2 + +Render the second Noise BNW Spots 1 package in F32. Read the output of each of its two FX-Maps and the final output bridge in the same capture session. Repeat in the ordinary MaterialCraft save. For a background control, leave the upstream connection in place and set each authored pattern type to zero in the final FX-Map. Save and reopen this control with its function packages available through their usual relative paths. + +The upstream U8 image matches 1,216/1,216 pixels in the one-processor, seven-processor and reopened comparisons, maximum zero on each. After resizing, the background control matches 4,864/4,864 F32 pixels, maximum zero. Comparing separate reference reads of the final FX-Map and its output bridge gives 4,863/4,864 on one processor, 4,747/4,864 on eight and 4,846/4,864 after reopening. Their maximum F32 errors are 5.96046448e−8, 1.19209290e−7 and 5.96046448e−8 respectively. At 16² defaults those comparisons give 256/256, 236/256 and 256/256. + +| Size, seed and exposed settings | Release vs. one processor | Release vs. seven processors | Release vs. ordinary save | Maximum F32 error across the three | +|---|---:|---:|---:|---:| +| 16², 0, defaults | 232/256 | 241/256 | 232/256 | 1.19209290e−7 | +| 16 × 32, 0, scale 1, roughness 1, disorder/speed/anisotropy 0, angle −.375, offset (0,0) | 473/512 | 468/512 | 473/512 | 1.19209290e−7 | +| 16 × 32, 194426, defaults | 463/512 | 476/512 | 463/512 | 1.19209290e−7 | +| 32 × 16, 456654, scale 2, roughness .375, disorder .28125, speed .24609375, anisotropy .140625, angle −.09375, offset (.0703125,−.03515625) | 511/512 | 512/512 | 511/512 | 5.96046448e−8 | +| 32², 113, scale 2, roughness .6, disorder .37, speed .6, anisotropy .3, angle .125, offset (.17,.29) | 1,014/1,024 | 1,015/1,024 | 1,015/1,024 | 5.96046448e−8 | +| 32 × 64, 194520, scale 1, roughness/disorder/speed/anisotropy .1875, angle −.0625, offset (−.15625,.2421875), non-square expansion on | 2,048/2,048 | 2,048/2,048 | 2,048/2,048 | 0 | + +At 16² and seed zero the final tree draws 16,384 parents at depth seven and four children per parent at depth eight. The 80,689 interior, 1,227 edge and four corner draws generate 83,159 physical tile copies. To observe their order, make an independent graph with a single outer iteration and switch, four children per quadrant, a single iteration on the way to depth seven, and unselected branches reaching depth ten. Use additive squares on white. Enable tiling on both axes. Place unmarked squares inside the tile, on the left edge or at the lower-left corner for one, two or four copies. Give two single-copy squares gains −1 and 2⁻²⁵ and place them on the same pixel. Repeat with the gains exchanged. The two reads identify which square drew first. + +In the 16² root, 196 pixels have the same stored sum for every order of their contributors. The other 60 pixels involve 404 distinct single-copy pairs. Measure all 404 pairs on the independent graph in fourteen 128² F32 renders. Applying these comparisons to MaterialCraft's own background and individual draw contributions reproduces 256/256 original and 256/256 reopened pixels on one processor, maximum zero. The same replay matches 228/256 pixels on the seven-processor capture, maximum 1.19209290e−7. Removing the interior and outer routes and stopping the tree at depth eight reverses nine of the 38 relationships required by the original and reopened pixels. Keeping the inactive descendants alone preserves all 38 on this field. + +The first probe used horizontal tiling, giving the four corner draws two copies each. Repeating all fourteen renders with both axes enabled gives the same 404/404 signed comparisons and the same three raw-pixel replay scores. + +The renderer before the shared tile-copy correction differs on the F32 settings above. The inventory remains 480/546. [Whole graph across 87 settings and 19 ordinary saves](#copy-batches-from-the-final-quadrant-pair-and-the-following-group) + +### Pending quadrant siblings and the first full receiving batch + +Use the [overlapping square fixture](#final-copy-batches-in-one-and-two-quadrant-trees) with one active pass and a connected, inactive depth-ten branch. Put the two signed marks at depth-five quadrants 32 and 30, counting from zero in traversal order. Moving the 64 terminal squares under quadrant 928 to the tile corner adds 192 physical copies. The first batch fills with two pending siblings under the same parent. The first sibling moves to the receiving group and the second stays with the submitting pair. At pixel (8,8) the unwrapped F32 control reads zero, the wrapped version reads 2⁻²⁵, and exchanging the gains gives zero again. The independent one-pass ordering replay agrees with 2,036/2,036 signed comparisons for the 32² spot field and 2,043/2,043 at 64 × 32. [Copy ranges](../crates/nodes/src/pattern/underfilled_quadrants/carried.rs) + +For the two-pass boundary, mark depth-five quadrant 32 on the first pass and 384 on the second. Move the final squares under first-pass quadrants 32 through 35 to the tile corner, then also move the squares under quadrant 36. The extra quadrant raises the receiving group's incoming count past 5,460. The reference sample changes from below 2⁻²⁶ to 2⁻²⁵. Independent 32² fields allocate 933 or 934 extra copies to second-pass depth-three quadrant 50, or 935 to quadrant 51. This gives 5,459, 5,460 and 5,461 incoming copies. All 285 signed comparisons per field place the full receiving batch after 20, 13 and 13 preceding batches respectively. Adding copies on the first pass can also change an earlier sibling transfer. The same total alone leaves that order unresolved. Both Rust regressions failed before the corrections. [Shared traversal](../crates/nodes/src/pattern/underfilled_quadrants.rs) · [Procedural regression tests](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +Each graph below was rendered in U8, U16, F16 and F32. The previous and current exact counts apply independently to the originals and to their ordinary saves. The maximum is the largest current absolute error on either side. + +| Procedural comparison | Graphs | Previous exact pixels per side | Current exact pixels per side | Maximum | +|---|---:|---:|---:|---:| +| One-pass sibling transfer, reversed markers and neighboring wrap controls | 8 | 32,764/32,768 | 32,768/32,768 | 0 | +| Same markers with two, three or four passes | 4 | 16,380/16,384 | 16,380/16,384 | 2⁻²⁵ | +| Earlier collecting batch, neighboring densities and reversed gains | 9 | 36,860/36,864 | 36,864/36,864 | 0 | + +Two additional complete Spots 1 originals and their ordinary saves now match on one processor. Set scale 1, disable non-square expansion, and use (width, height, seed, disorder, roughness) of (32,32,395435,.375,.875) and (64,32,395572,.8125,.4375). The exact counts increase from 968/1,024 and 1,991/2,048 to 1,024/1,024 and 2,048/2,048, maximum zero. Against the seven-processor captures the same frames fall from 706 to 697 and from 1,603 to 1,585 exact pixels. Their combined maximum is 1.78813934e−07. + +For eight further F32 settings, keep scale 1 and non-square expansion off. Use seeds 920633 + 163 × i for i = 0 through 7, with (width, height, disorder, roughness) in order (16,16,.8125,.625), (16,32,.375,.9375), (32,16,.9375,.25), (32,32,.625,.375), (32,64,.8125,.125), (64,32,.25,.6875), (64,64,.5,.9375) and (64,16,1,.5). The one-processor originals match 11,520/11,520, maximum zero. The seven-processor originals match 8,609/11,520, maximum 2.38418579e−07. The reopens match 11,500/11,520, maximum 1.19209290e−07, with all 20 differences at seed 921448. The 86 original settings and 19 saves in the established panel retain all their earlier scores and per-format maxima. The inventory remains 480/546. [Full panel by storage format](#final-copy-batches-in-one-and-two-quadrant-trees) + +### Final copy batches in one and two quadrant trees + +Start with the [eight-level overlapping squares](#remaining-siblings-at-a-full-quadrant-copy-batch) and keep the inactive depth-ten branch. Give ordinary squares gain 2⁻⁷⁶ on a white background. Move two selected squares to the center of pixel (8,8) at 32² with gains −1 and 2⁻²⁵. For one pass, use depth-three quadrants 60 and 52 in traversal order. The reference value is 2⁻²⁵. Exchanging the gains gives zero. Once the last full batch submits, each producer with a partially filled batch keeps its remaining draw ranges together. The previous traversal separated the middle producer's ranges from the later pair. [Shared copy ranges](../crates/nodes/src/pattern/underfilled_quadrants/carried.rs) + +For two passes, move the 64 final squares under first-pass depth-five quadrant 624 to the tile corner. Compare second-pass depth-five quadrants 336 and 80, 592 and 80, then 896 and 768. Each reference marker reads 2⁻²⁵. A pending sibling can belong entirely to the next pair, leaving an empty intersection with the current pair. When both carried pairs have no pending sibling, both full batches submit before the final child. A receiving group that fills another 5,460 copies can change this order and remains open. Both the one- and two-pass regressions failed before their respective corrections. [Sibling transfers](../crates/nodes/src/pattern/underfilled_quadrants/remaining.rs) · [Procedural regression graphs](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +The following independently authored graphs use the four output formats of the linked square fixture. Each reopened count compares an ordinary MaterialCraft save with the reference app. The final column gives the largest absolute error across originals and reopens. + +| Controls | Graphs | Previous original | Current original | Reopened | Maximum | +|---|---:|---:|---:|---:|---:| +| One-pass and second-pass controls | 9 | 36,837/36,864 | 36,864/36,864 | 36,864/36,864 | 0 | +| Carried depth-five markers | 6 | 24,570/24,576 | 24,575/24,576 | 24,575/24,576 | 2⁻²⁵ | +| Carried depth-three markers | 9 | 36,783/36,864 | 36,819/36,864 | 36,828/36,864 | 2⁻²⁵ | +| Lower, upper and last pairs at depth five | 6 | 24,570/24,576 | 24,574/24,576 | 24,574/24,576 | 2⁻²⁵ | +| Earlier and later sibling transfers | 11 | 45,008/45,056 | 45,029/45,056 | 45,029/45,056 | 2⁻²⁵ | + +Across 86 complete Spots 1 settings, thirteen additional one-processor frames become exact, including eleven F32 and two U16 frames. All 64 exact frames are included below. The one-processor total gains 3,098 exact pixels. Eight-processor agreement falls by 415 pixels, with three frames improving, nine declining and 38 exact. The 19 ordinary saves retain their previous scores, including 16 exact frames. [Preceding counts](#remaining-siblings-at-a-full-quadrant-copy-batch) + +| Storage | One processor · exact pixels · maximum | Eight processors · exact pixels · maximum | Reopened · exact pixels · maximum | +|---|---:|---:|---:| +| U8 | 108,800/108,800 · 0 | 108,799/108,800 · 1 | 90,112/90,112 · 0 | +| U16 | 328,398/328,448 · 1 | 328,243/328,448 · 1 | 93,693/93,696 · 1 | +| F16 | 108,800/108,800 · 0 | 108,798/108,800 · .00048828125 | 6,400/6,400 · 0 | +| F32 | 278,260/295,680 · 2.38418579e−07 | 231,026/295,680 · 3.57627869e−07 | 5,986/6,144 · 1.1920929e−07 | + +At 16 × 32 and seed zero, all four original and all four reopened F32 captures now match 512/512, up from 490/512, with maximum zero. At 64 × 32 the four original reads still give 1,695/1,832 invariant pixels and the four reopened reads give 1,587/1,679. For independent one-pass F32 settings, disable non-square expansion, set scale 1 and use (width, height, seed, disorder, roughness) of (16,32,395161,0,1), (64,64,395846,.9375,.21875) and (64,128,395983,.5625,.5625). All 12,800/12,800 original and 12,800/12,800 reopened pixels match, maximum zero. The additional (32,32,395435,.375,.875) and (64,32,395572,.8125,.4375) cases remain at 968/1,024 and 1,991/2,048 on both the original and the save. The second version of Spots 1 retains every measured digest across 87 originals and 19 saves, scoring 831,506/842,752 on one processor, 831,311/842,752 on eight and 137,715/139,008 on the saves. [Second-version settings and errors](#full-copy-batches-spanning-successive-quadrant-trees) + +### Interior routes between terminal quadrants + +In the [three-level terminal square graph](#outer-routes-into-the-final-three-active-quadrant-levels), insert a Dot on the first child at depth 1, 3 or 8 of a two-pass tree. Repeat with a Switch at depth 3 or 8, connecting both choices to the original child. Also test a single pass with a Dot at depth 4 and four passes with a Switch at depth 7. The renderer now checks the quadrants reached through each route. The previous depth-zero restriction discarded the terminal draw order at the first interior route. The two-pass F32 regression failed before this change. [Traversal](../crates/nodes/src/pattern/terminal_quadrants.rs) · [Regression graph](../crates/nodes/src/pattern/tests/terminal_quadrants.rs) + +Render the procedural marker field in F32 at 128², U16 at 128 × 64, F16 at 64 × 128 and U8 at 64². The seeds in that order are 255151, 255194, 255237 and 255280. All seven originals match 258,048/258,048 pixels. Their ordinary SBS saves reopen and match another 258,048/258,048. Each of the fourteen graphs previously differed at twelve F32 pixels with maximum 2⁻²⁵. All four formats now have maximum error zero. The earlier first-child capture that varied at ten F32 pixels is recorded with its five original and five reopened repeat reads. [Marker settings and the earlier repeated capture](#outer-routes-into-the-final-three-active-quadrant-levels) + +Directional Noise 1 retains 734,118/734,464 pixels on the one-processor capture, 734,140/734,464 on eight and 123,081/123,136 across 12 saves. All 60 original and 12 reopened frame digests match the preceding build. Its second version retains all ten original and three reopened guard frames, scoring 100,039/103,168 on one processor, 100,434/103,168 on eight and 26,621/26,624 after reopening. Both roots remain in progress. [Whole-root procedure and errors by storage format](#final-three-quadrant-levels-in-directional-noise-1) + +### Remaining siblings at a full quadrant copy batch + +Use the [eight-level additive square graph](#full-copy-batches-spanning-successive-quadrant-trees) with two outer iterations, an inactive branch reaching connected depth ten and a white background. Number children from zero in traversal order at each depth. As a 5,460-copy batch fills inside the second tree, the collecting group finishes its current depth-five subtree. Walking up the pending quadrants, it hands off the first half of two or three remaining siblings, rounded up. If a single larger sibling remains, its own draw stays in the group and its first two children are handed off. When the parent’s own draw fills the batch, its first two children are handed off. The boundary follows the number of physical copies of each stamp, including wrapped copies. The other siblings supply the next batch. [Shared renderer](../crates/nodes/src/pattern/underfilled_quadrants.rs) + +For a minimal order readout, overlap a negative square from second-pass depth-five quadrant 270 with a positive square from quadrant 268 at pixel (8,8) on a 32² F32 output. Their gains are −1 and 2⁻²⁵. The unwrapped field gives 2⁻²⁵. Moving the 64 final squares of first-pass depth-five quadrant 32 to the tile corner adds 192 copies and changes the same pixel to zero. In separate tests mark second-pass depth-three quadrant 17 against first-pass quadrant 7, 35 against 33 in the second pass, and 58 against 1 in the second pass. All three reference values are 2⁻²⁵. Both Rust regressions failed on the preceding renderer. [Regression graphs](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +Varying the number of wrapped copies in first-pass subtree 2 gave 3,618/3,618 signed comparisons across 18 independently generated fields. Nine two-, three- and four-pass graphs match 36,864/36,864 pixels before saving and 36,864/36,864 after reopening, covering U8, U16, F16 and F32 with maximum error zero. Three additional graphs marking later draws match 24,536/24,576 original and reopened pixels combined, maximum 2⁻²⁵. A separate boundary probe placed the first collecting batch after twenty full submissions with 5,459 incoming copies and after thirteen at 5,460 or 5,461. Competing groups that fill before reaching the second-tree pair and the final partial batches remain open. + +Across 86 complete Spots 1 settings, the one-processor total increases by 2,101 pixels. Twenty-six settings improve, one declines and 51 match in full. On eight processors ten improve, sixteen decline and 38 match in full. The aggregate decreases by 250. Two of 19 reopens improve and 16 match in full, an increase of 23 pixels. An original 128² U16 setting at seed zero, scale 2, disorder .37 and roughness .6 drops from 16,377 to 16,375/16,384. The two positions are (105,32), which moves from 30,963 to 30,964, and (6,34), which moves from 16,058 to 16,059. Both values at each position occur across four fresh original reads. Four reopens give 30,964 and 16,058 at those positions. The old and new releases each match 16,371/16,373 invariant original U16 pixels and 16,371/16,375 invariant reopened U16 pixels. [Preceding measurements](#copy-batches-from-the-final-quadrant-pair-and-the-following-group) + +| Storage | One processor · exact pixels · maximum | Eight processors · exact pixels · maximum | Reopened · exact pixels · maximum | +|---|---:|---:|---:| +| U8 | 108,800/108,800 · 0 | 108,799/108,800 · 1 | 90,112/90,112 · 0 | +| U16 | 328,393/328,448 · 1 | 328,248/328,448 · 1 | 93,693/93,696 · 1 | +| F16 | 108,800/108,800 · 0 | 108,798/108,800 · .00048828125 | 6,400/6,400 · 0 | +| F32 | 275,167/295,680 · 2.38418579e−7 | 231,436/295,680 · 3.57627869e−7 | 5,986/6,144 · 1.19209290e−7 | + +Four original and four reopened 16 × 32 seed-zero F32 captures each improve from 469 to 490/512, maximum 1.19209290e−7. At 64 × 32 the renderer matches 1,695/1,832 invariant original pixels and 1,587/1,679 invariant reopened pixels, gains of nine on each side. The two earlier U16 and F32 coordinate checks still match every repeated capture. The second version of Spots 1 retains every measured output bit. It matches 831,506/842,752 on one processor, 831,311/842,752 on eight and 137,715/139,008 after reopening. Across 30 rendered settings of the `moisture_noise`, `noise_directional_noise_2`, `noise_moisture_noise` and `wood_fibers_1` packages, all 66,560 local pixels retain their previous values. Two further Directional Noise 2 settings still exceed the execution budget. [Repeated frame settings](#bounded-work-for-empty-terminal-quadrants) + +### Outer routes into the final three active quadrant levels + +Build the [directional generator’s three-level square fixture](#final-three-quadrant-levels-in-directional-noise-1) with four connected children at every subdivision through depth eight. Keep the draws on depths six through eight. For multiple passes, initialize a writable float to −1 in the outer Iterate count expression and increment it in the first Quadrant’s branch offset. Use the resulting pass index to address the procedural marker field. In the two-pass fixture, place the negative square at draw 148,776 and the positive square at draw 167,500, counting both passes from zero. The marker pixel reads zero. Before the correction, a Dot before the Iterate changed that pixel to 2⁻²⁵. [Normal cook regression](../crates/nodes/src/pattern/tests/terminal_quadrants.rs) + +Compare the direct route, a Dot, each selected Switch arm, a chain of three routes, and an ordinary save and reopen of the right-arm graph. Repeat for one, two and four passes. Also test a two-pass Switch with both arms connected, a route between the Iterate and its first Quadrant, and two further ordinary reopens. Use a white background, zero roughness and additive squares. Capture F32 at 128² with seed 255151, U16 at 128 × 64 with seed 255194, F16 at 64 × 128 with seed 255237, and U8 at 64² with seed 255280. The 24 configurations cover 19 originals and five saves. All raw reference frames match their direct counterpart. The renderer now counts the active trees when traversal reaches the first Quadrant, including routes before and after the outer Iterate. [Shared traversal](../crates/nodes/src/pattern/terminal_quadrants.rs) + +| Storage | Previous exact pixels | Current exact pixels | Previous maximum | Current maximum | +|---|---:|---:|---:|---:| +| U8 | 98,304/98,304 | 98,304/98,304 | 0 | 0 | +| U16 | 196,608/196,608 | 196,608/196,608 | 0 | 0 | +| F16 | 196,608/196,608 | 196,608/196,608 | 0 | 0 | +| F32 | 393,000/393,216 | 393,216/393,216 | 2.98023224e−8 | 0 | + +The 19 original graphs gain 168 exact pixels and the five saves gain 48. Interior routes remain open. A Dot on the first child gave one reference frame with ten differing pixels out of 16,384, maximum 2⁻²⁵, compared with the direct route. Five fresh reads of that same file and five of its ordinary save matched the direct frame in full. The current renderer differs from that repeated frame at twelve pixels. The measured third- and eighth-level routes also differ at twelve F32 pixels each. All U8, U16 and F16 interior-route comparisons match. + +The complete Directional Noise 1 sweep retains all prior output bits across 60 original settings and 12 ordinary saves. The one- and eight-processor references give 734,118/734,464 and 734,140/734,464 respectively. The saves give 123,081/123,136. A separate ten-setting sample of the second version retains 100,039/103,168 on one processor and 100,434/103,168 on eight. Three saves retain 26,621/26,624. Both roots remain in progress. [Whole-graph maximum errors by storage format](#final-three-quadrant-levels-in-directional-noise-1) + +### Copy batches from the final quadrant pair and the following group + +Build the [eight-level additive square tree](#full-copy-batches-spanning-successive-quadrant-trees) with two outer repetitions and an inactive branch extending to connected depth ten. Number quadrants at each depth from zero in child-slot order within each tree. The first tree contributes both depth-three subtrees 60 and 61, subtree 18’s own draw and its last two children, and all of subtree 34. With one copy per square these three pieces contribute 2,730, 683 and 1,365 copies. The second tree supplies the next 682 from subtrees 60 and 61, deferring the third child of 60. The resulting 5,460 copies fill one batch. Sixteen original copy distributions with two, three or four repetitions agree on 9,092/9,092 signed comparisons for this part of the order. [Shared quadrant renderer](../crates/nodes/src/pattern/underfilled_quadrants.rs) + +When the first tree contributes 5,459 copies, all 225 sampled orders agree in each of two settings. At exactly 5,460, the batch submits before the three pairs carried from the first tree. Placing it after those pairs gives 72 wrong orders out of 224. Adding 3,798 extra wrapped copies within second-pass subtree 61 fills two batches. All 360 sampled orders agree in that setting. Wrapping all 1,024 final squares of first-pass subtree 34 adds 3,072 copies. Its first batch precedes the carried pairs, but the second and third carried pairs can interleave. Only the first carried pair has an established position at that cut. + +For a separate pixel test use the white background, .875 squares and the [published gains, seeds, sizes and four storage formats](#full-copy-batches-spanning-successive-quadrant-trees). Put the negative square in second-pass depth-three subtree 60 and the positive square in first-pass subtree 2. At 32² F32 the pixel at (8,8) changes from zero to 2⁻²⁵. Moving the 1,024 final squares of first-pass subtree 34 to the tile corner gives two more tests. First place the negative square in first-pass subtree 60 and the positive square in second-pass depth-two quadrant 6. Then place the negative square in that quadrant and the positive square in first-pass subtree 2. Both reference pixels read 2⁻²⁵. [Renderer regressions](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +If the first tree carries fewer than 5,460 copies and the second tree completes one batch, a further stream starts with the copies left in the first collecting group. It receives first-pass subtree 2, the first depth-five branch under the first child of subtree 19, second-pass depth-two quadrant 12 and its last two child subtrees, then second-pass quadrants 4 and 5. The renderer submits the first 5,460 copies when this stream reaches the second-pass pair before filling. In a separate two-square graph use second-pass subtree 50 and first-pass subtree 7 for the negative and positive squares. At 32² F32 the reference reads 2⁻²⁵, and the previous renderer read zero. Later batches and streams that fill before reaching this pair remain under investigation. + +Across the 86 Spots 1 settings the one-processor comparison gains 1,058 exact pixels. Twenty-three settings improve and 49 match in full. The eight-processor comparison loses 92 pixels. Seven settings improve, thirteen decline and 38 match in full. One of the 19 ordinary saves gains seven pixels, with 15 matching in full. [Preceding comparison and capture settings](#carrying-the-third-quadrant-pair-through-an-outer-iteration) + +| Storage | One processor · exact pixels · maximum | Eight processors · exact pixels · maximum | Reopened · exact pixels · maximum | +|---|---:|---:|---:| +| U8 | 108,800/108,800 · 0 | 108,799/108,800 · 1 | 90,112/90,112 · 0 | +| U16 | 328,391/328,448 · 1 | 328,248/328,448 · 1 | 93,692/93,696 · 1 | +| F16 | 108,800/108,800 · 0 | 108,798/108,800 · .00048828125 | 6,400/6,400 · 0 | +| F32 | 273,068/295,680 · 2.38418579e−7 | 231,686/295,680 · 3.57627869e−7 | 5,964/6,144 · 1.19209290e−7 | + +The reproducible 128 × 512 U16 regression at (106,171) is resolved. Seed 411869, scale 2, roughness and disorder .53125, with non-square expansion disabled, now gives 45,824 and F32 0.6992377638816833. The 128² pixel at (44,98), seed 411747, scale 3, roughness and disorder .65625, retains 23,266 and F32 0.3550243079662323. Each value matches four original and four reopened reference captures. At 16 × 32 F32 and seed zero, four original and four reopened captures improve from 460 to 469/512, maximum 1.19209290e−7 each. At 64 × 32, 1,686 of the 1,832 invariant original pixels match and 1,578 of the 1,679 invariant reopened pixels match, up by three in each case. [Settings for the repeated frames](#bounded-work-for-empty-terminal-quadrants) + +The seven unwrapped two-square configurations match 28,672/28,672 pixels across the four formats, for originals and again for ordinary saves. Six of seven configurations with wrapped squares also match in full. When both first-pass subtrees 34 and 61 wrap, 4,056/4,096 pixels match on each side and the finite error reaches 2⁻⁷⁴. The six configurations marking the following group match all 24,576 original pixels and all 24,576 reopened pixels. Eight graphs that mark later draws give 32,759/32,768 on each side, maximum 2⁻²⁵. The earlier depth-nine and eleven probes still differ on two pixels. All three new Rust regressions failed before their corresponding changes. + +The 397 earlier procedural controls retain 1,294,336/1,294,336 pixels, and 44 controls with changed leaf connections retain 45,056/45,056. Both maxima are zero. The second version of Spots 1 produces identical raw frames to the previous build in all 87 original settings and 19 saves. Exact agreement remains 831,506/842,752 on one processor, 831,311/842,752 on eight and 137,715/139,008 after reopening. All 519 node and evaluator release tests passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. [Second-version maxima by storage format](#full-copy-batches-spanning-successive-quadrant-trees) + +### Carrying the third quadrant pair through an outer iteration + +Use the [eight-level additive square tree](#full-copy-batches-spanning-successive-quadrant-trees) with two repetitions. Extend a connected, inactive branch to depth ten. After the first two pairs continue into the second tree, the third stream takes the remaining copies from first-tree depth-two quadrants 2 and 3, depth-four subtree 78, depth-five subtree 310, then the second tree's depth-two pair 2 and 3. With one copy per draw the carried pieces contain 2, 341 and 85 copies. The second pair contributes 10,492 copies to finish two 5,460-copy batches. [Shared quadrant renderer](../crates/nodes/src/pattern/underfilled_quadrants.rs) + +Varying the copy counts in eleven fields with two, three or four repetitions gives 6,191/6,191 matching signed comparisons for the tested prefix. Separate two- and four-copy edge stamps give 84/84 predicted signs, including both gain directions at the second and third batch boundaries. At 5,459 carried copies all 217 sampled orders agree. Increasing the carried count to exactly 5,460 makes the first-tree pieces precede the other two second-tree pairs. Continuing the previous order would fail 36/270 comparisons. The renderer stops extending this prefix when the first tree already fills a batch. + +Place the negative square in depth-two quadrant 2 on the second pass and the positive square in depth-three quadrant 60 on the first. Use the previously recorded 32² F32, 16 × 32 U8, 32 × 16 U16 and 64 × 32 F16 settings, seeds and published gains. The F32 pixel at (8,8) changes from 5.29395592e−23 to the reference value 2⁻²⁵. Repeat with four passes, the gains reversed, and the pairs at depths four and five. Across nine depth-ten configurations all 36,864 original pixels and all 36,864 reopened pixels match, maximum zero. Placing the negative square in first-pass depth-five quadrant 310 and the positive square in second-pass depth-two quadrant 2 at depths nine and eleven leaves 8,190/8,192 exact on each side, maximum 2⁻²⁵. Both shallower and deeper controls remain open. [Settings and gain sequence](#full-copy-batches-spanning-successive-quadrant-trees) + +The outer Iterate can also be reached through a Dot or the selected arm of a Switch. The renderer used the declared root ID to recognize the Iterate and lost the measured draw order through either connection. Test a Dot, either switch arm, a chain of three routing nodes, a first-pass depth-four/depth-five marker pair, and a four-pass tree. All six reference graphs retain the direct graph's pixels across the four storage formats. MaterialCraft improves from 24,440/24,576 to 24,576/24,576 on both originals and ordinary saves, maximum zero. The two Rust regressions reproduce the incorrect pixels before their corresponding fixes. [Renderer regression tests](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +Across the 86 Noise BNW Spots 1 settings, one-processor agreement improves by 1,273 to 818,001/841,728. Twenty-two settings gain exact pixels, one loses one pixel and 49 match in full. The eight-processor comparison gains 81 to 777,623/841,728. Nine settings improve, twelve decline and 38 match in full. The 19 ordinary saves gain three to 196,161/196,352, with 15 matching in full. [Previous root measurements](#full-copy-batches-spanning-successive-quadrant-trees) + +| Storage | One processor · exact pixels · maximum | Eight processors · exact pixels · maximum | Reopened · exact pixels · maximum | +|---|---:|---:|---:| +| U8 | 108,800/108,800 · 0 | 108,799/108,800 · 1 | 90,112/90,112 · 0 | +| U16 | 328,388/328,448 · 1 | 328,249/328,448 · 1 | 93,692/93,696 · 1 | +| F16 | 108,800/108,800 · 0 | 108,798/108,800 · .00048828125 | 6,400/6,400 · 0 | +| F32 | 272,013/295,680 · 2.38418579e−7 | 231,777/295,680 · 3.57627869e−7 | 5,957/6,144 · 1.19209290e−7 | + +At 16 × 32 F32 and seed zero, four original and four reopened captures each improve from 451 to 460/512, maximum 1.19209290e−7. At 64 × 32 and scale three, the four originals retain 1,683 matches among their 1,832 invariant pixels. The four reopened references retain 1,575 matches among their 1,679 invariant pixels. [Repeat settings](#bounded-work-for-empty-terminal-quadrants) + +Two U16 settings each change one pixel. At 128², seed 411747, scale 3 and disorder and roughness .65625, pixel (44,98) moves from 23,267 to the reference code 23,266. At 128 × 512, seed 411869, scale 2 and disorder and roughness .53125, pixel (106,171) moves from 45,824 to 45,825. Disable non-square expansion for both. Four fresh original and four reopened reference captures retain 45,824 at the second pixel and 23,266 at the first. The second pixel remains a reproducible one-code regression despite variation elsewhere in the repeated frames. Switching the output to F32 isolates the same two pixels before integer storage. At (44,98) the renderer changes from 0.3550243377685547 to 0.3550243079662323. All eight fresh F32 references give the latter. At (106,171) it changes from 0.6992377638816833 to 0.6992378234863281, and all eight references give the former. Applying the existing U16 conversion to these F32 reads reproduces every measured integer code. + +The 397 earlier procedural controls and 44 controls with changed terminal connections still match all 1,294,336 and 45,056 pixels respectively, maximum zero. The second version of Spots 1 produces the same raw frames as the preceding build in all 87 original settings and 19 saves. Agreement remains 831,506/842,752 on one processor, 831,311/842,752 on eight and 137,715/139,008 after reopening. All 516 node and evaluator release tests passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. [Second-version maxima by storage format and processor count](#full-copy-batches-spanning-successive-quadrant-trees) + +### Full copy batches spanning successive quadrant trees + +Repeat the [eight-level additive tree](#physical-copy-batches-across-neighboring-quadrants) twice. Number quadrants at each depth from zero in child-slot order within each tree. When the first thirteen batches take the measured order, two streams continue into the second tree. Each starts with the copies left in a first-tree quadrant pair after its first 10,920 copies. The pieces that follow are listed in submission order. [Shared renderer](../crates/nodes/src/pattern/underfilled_quadrants.rs) + +| First-tree pair | Next first-tree subtrees at depth three | Next first-tree subtree at depth five | Second-tree pair | +|---|---|---|---| +| 6 and 7 | 52 and 53 | 309 | 6 and 7 | +| 10 and 11 | 56 and 57 | 308 | 10 and 11 | + +With one physical copy per draw, each row carries 2 + 2,730 + 85 copies into the second tree. A second-tree pair supplies 10,922 more. With 2,640 extra copies near the start of second-tree subtree 25, the first stream reaches 16,379. One additional copy fills its third 5,460-copy batch. When the pieces from the first tree alone reach 5,460, competing streams can submit earlier. Adding 2,642 copies within first-tree subtree 56 keeps the carried count at 5,459. Adding one more changes 70 of 432 sampled orders in that field. + +Across twenty two-, three- and four-tree copy distributions, the reference agrees with the predicted order on all 9,138 tested pairs in both gain directions. Applying the same order in twelve denser cases where the carried pieces alone can fill a batch gives 361 wrong predictions out of 5,496. Five further fields vary the second-tree copies in subtree 25 or 30, crossing the third-batch boundary. All 2,160 tested pairs agree when the renderer counts the full batches. + +For a separate pixel comparison, use white as the initial pixel value, zero roughness, .875 squares and ordinary gain 2⁻⁷⁶. Set a float to zero in the outer Iterate's count expression, return two, and increment the float in the root quadrant's branch offset on each pass. On the second pass, place depth-three square 30 and depth-two square 10 at (.265625,.265625) with gains −1 and 2⁻²⁵. At 32² F32, seed 41384, the pixel at (8,8) reads zero. Move the 1,024 final squares of subtree 25 to the tile corner on the second pass only. Their 3,072 additional wrapped copies move square 30 ahead of square 10. The same pixel now reads 2⁻²⁵ in both the original reference graph and its ordinary MaterialCraft save. The intermediate renderer still returned zero. [Renderer regressions](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +Five additional distributions fill the second pair, fill both pairs, or change the copy density while repeating the tree three or four times. All ten third-batch distributions now agree on 4,320/4,320 signed draw pairs. The 397 earlier procedural controls retain 1,294,336/1,294,336 exact pixels. The 44 controls with changed terminal connections retain 45,056/45,056. Both sets have maximum error zero. + +For the second stream, mark second-pass depth-three square 46 against first-pass square 60 and wrap subtree 43 on the second pass. Repeat the first pair with the gains exchanged, both subtrees wrapped, and four tree repetitions. For the test with both subtrees wrapped, mark second-pass squares 30 and 46. Use the 32² F32 setting above, 16 × 32 U8 at seed 41484, 32 × 16 U16 at seed 41588 and 64 × 32 F16 at seed 41692, with the [published gain settings](#connected-graph-depth-and-the-ninth-quadrant-batch). The five wrapped configurations match all 20,480 original and all 20,480 reopened pixels. The two unwrapped controls match 8,181/8,192 on each side, maximum 3.97046694e−23. Testing cuts inside a two- or four-copy stamp gives the predicted result at all 112 edges and corners for the second batch and all 56 for the third, including both gain directions. + +An independent series marks first-pass depth-three pairs (52,2), (56,2) and (2,52), then first-pass square 52 against depth-five square 309 and square 56 against depth-five square 308. Mark second-pass depth-two square 6 against first-pass square 56 in two and four repetitions, and second-pass depth-two square 10 against first-pass square 2 in two repetitions. Render each at the four sizes in all four storage formats and reopen each ordinary save. The 128 settings improve from 130,649 to **131,017/131,072** on each side. U8, U16 and F16 each match 32,768/32,768. F32 matches 32,713/32,768, maximum 6.61744490e−23. The previous floating-point maximum was 2⁻²⁴. + +A second series applies both gains on every repetition. Divide the negative gain by the repetition count, including the swapped-gain setting. Use the first-pass pairs above without the pass restriction, add the depth-five pair (309,308) and repeat (52,2) with one, two and four trees. Across 128 settings, 131,028/131,072 original and 131,049/131,072 reopened pixels match. The respective maxima are 2⁻²⁴ and 2⁻²⁵. In the four-tree 64 × 32 F16 setting the first original and reopened reference captures differ on 21/2,048 pixels by 2⁻²⁴. Four further original captures and four further reopened captures agree on all 2,048 pixels with the first reopened capture. + +Across the 86 original Noise BNW Spots 1 settings, 27 gain exact pixels on one processor and 49 match in full. The total increases by 2,562 to 816,728/841,728. On eight processors, two settings gain, 24 lose and 38 match in full. The total falls by 1,366 to 777,542/841,728. The 19 ordinary saves gain 23 pixels to 196,158/196,352, with 15 matching in full. The third-batch correction preserves every MaterialCraft output bit in these 86 settings and 19 saves. [Earlier measurements and root settings](#physical-copy-batches-across-neighboring-quadrants) + +| Storage | One processor · exact pixels · maximum | Eight processors · exact pixels · maximum | Reopened · exact pixels · maximum | +|---|---:|---:|---:| +| U8 | 108,800/108,800 · 0 | 108,799/108,800 · 1 | 90,112/90,112 · 0 | +| U16 | 328,388/328,448 · 1 | 328,251/328,448 · 1 | 93,692/93,696 · 1 | +| F16 | 108,800/108,800 · 0 | 108,798/108,800 · .00048828125 | 6,400/6,400 · 0 | +| F32 | 270,740/295,680 · 2.38418579e−7 | 231,694/295,680 · 3.57627869e−7 | 5,954/6,144 · 2.38418579e−7 | + +All four original and four reopened captures at 16 × 32 F32 and seed zero improve from 428 to 451/512, maximum 1.19209290e−7. At 64 × 32 with scale three, 1,683 of the 1,832 pixels identical across the four original references match, up from 1,675. Across the four reopened references, 1,575 of the 1,679 invariant pixels match, up from 1,567. The maximum is 1.19209290e−7 throughout. Two regressions reproduce the earlier incorrect draws. All 514 node and evaluator release tests passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. [Repeated whole-root settings](#bounded-work-for-empty-terminal-quadrants) + +The second Spots 1 version retains 831,506/842,752 exact pixels on one processor and 831,311/842,752 on eight across 87 settings. The 19 ordinary saves retain 137,715/139,008. Respectively 56, 58 and 13 settings match in full. All U8 pixels agree. The largest U16 error is one code on all three comparisons. F16 maxima are .00048828125, .0001220703125 and zero. The F32 maximum is 1.19209290e−7 throughout. [Parameters, sizes and formats for this version](#whole-root-precision-and-saved-comparisons-for-the-three-neighboring-spot-graphs) + +### Physical copy batches across neighboring quadrants + +Use the [eight-level additive tree](#connected-graph-depth-and-the-ninth-quadrant-batch). Number the sixteen depth-two quadrants and the 64 depth-three subtrees from zero in child-slot order. With one copy per draw, a depth-two quadrant and its last two child subtrees supply 2,731 copies. Adding 2,728 copies inside subtree 58 leaves quadrant 14 waiting. Adding one more fills a batch of 5,460. It now draws before quadrants 2 and 3. The corresponding boundaries in subtrees 50 and 54 move their batches ahead of quadrants 6 and 10 respectively. A full batch from quadrant 15 and subtrees 62 and 63 precedes all three. Two simultaneously filled groups retain their relative order in the measured controls. [Shared copy ordering](../crates/nodes/src/pattern/underfilled_quadrants.rs) + +When the first seven batches take their ordinary order, the next streams begin at quadrants 12, 14 and 13, in that order. Each joins its last two child subtrees to draws from a second quadrant pair. The respective pairs are 4–5, 0–1 and 8–9. A first batch ending before the final two depth-five subtrees of 17, 1 or 33 can interleave with another stream. On the measured later cuts with a deeper connected graph, each stream supplies two consecutive batches. All three skip the third child subtree of the receiving quadrant. The first also skips three branches beneath the fourth child. At connected depth eight the middle stream still supplies two consecutive batches. The other two have a different continuation. Across 83 distributions, all 51,108 tested signed comparisons involving the predicted prefix agreed in both gain directions. Separate two-tree controls put the second batch boundary inside a two- or four-copy stamp. All 112 edge and corner observations agreed across the last two streams. + +For an independent image, use the same white background, .875 squares and ordinary gain 2⁻⁷⁶. Place two squares at (.265625,.265625). Use depth-two quadrants 14 and 8, depth-two quadrant 1 and depth-three subtree 2, depth-two quadrants 13 and 8, or depth-two quadrant 9 and depth-three subtree 34. In each pair the first square takes the negative gain. Render the [four sizes, gain settings, seeds and storage formats](#connected-graph-depth-and-the-ninth-quadrant-batch) with and without the inactive child below the leaves. Compare again after an ordinary MaterialCraft save and reopen. Both applications preserve their respective original pixels in all 128 settings. + +| Storage | Earlier exact at either depth | Deeper connection, original and reopened | Ends at depth eight, original and reopened | Maximum at depth eight | +|---|---:|---:|---:|---:| +| U8 | 16,384/16,384 | 16,384/16,384 | 16,384/16,384 | 0 | +| U16 | 16,384/16,384 | 16,384/16,384 | 16,384/16,384 | 0 | +| F16 | 16,330/16,384 | 16,384/16,384 | 16,378/16,384 | 2⁻²⁴ | +| F32 | 15,976/16,384 | 16,384/16,384 | 16,348/16,384 | 2⁻²⁴ | + +All deeper-connection maxima are zero. The 42 differing pixels in the depth-eight controls belong to the pair at quadrant 9 and subtree 34. To exercise an early batch independently, move all 1,024 final squares of a chosen subtree to the tile corner using a frame offset of zero minus the quadrant position. This adds 3,072 wrapped copies. Use subtrees 50, 58, 54 or 62 separately, 62 with 50 or 54, and an unshifted control. At 32² F32, 16 × 32 U8, 32 × 16 U16 and 64 × 32 F16, all 28,672 original and all 28,672 reopened pixels agree, maximum zero. The earlier result was 28,455/28,672 on each, maximum 2⁻²⁵. The two renderer regressions both returned zero in place of 2⁻²⁵ before the fix. [Renderer regressions](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +The 16 × 32 seed-zero F32 setting of Noise BNW Spots 1 improves from 416 to 428 exact pixels out of 512 in each of four original and four reopened reference captures, maximum 1.19209290e−7. At 64 × 32 with scale three, the four original references agree on 1,832 of 2,048 pixels. Of these, MaterialCraft matches 1,675, up from 1,672. The four reopened references agree on 1,679 pixels, of which 1,567 match, up from 1,564. All eight maximum errors are 1.19209290e−7. The depth-eight continuation and the work carried into the next tree remain open. [Settings for both repeated captures](#bounded-work-for-empty-terminal-quadrants) + +Across 86 original settings, 814,166/841,728 pixels match on one processor, a gain of 7,633. Thirty-two settings improve and none lose exact pixels. Both 128² U16 images with default parameters and seeds 0 and 42 now match completely, bringing the whole-frame count to 49 of 86. On eight processors, 778,908/841,728 match, a loss of 1,381. Four settings improve, 24 lose pixels, and the same 38 frames match completely. The 19 ordinary saves gain ten exact pixels to 196,135/196,352, with 15 completely exact frames. + +| Storage | One processor · exact pixels · maximum | Eight processors · exact pixels · maximum | Reopened · exact pixels · maximum | +|---|---:|---:|---:| +| U8 | 108,800/108,800 · 0 | 108,799/108,800 · 1 | 90,112/90,112 · 0 | +| U16 | 328,381/328,448 · 1 | 328,250/328,448 · 1 | 93,690/93,696 · 1 | +| F16 | 108,800/108,800 · 0 | 108,798/108,800 · .00048828125 | 6,400/6,400 · 0 | +| F32 | 268,185/295,680 · 2.38418579e−7 | 233,061/295,680 · 3.57627869e−7 | 5,933/6,144 · 2.38418579e−7 | + +All 397 earlier procedural settings now match all 1,294,336 pixels, recovering the last 56. All 48 opposite-gain settings also match 49,152/49,152, recovering 98. The 32 mixed-connectivity settings and twelve static-branch settings retain 32,768/32,768 and 12,288/12,288 respectively. Maximum error is zero throughout. The full measurement of the preceding ninth-batch build retained the second version's counts of 831,506/842,752 on one processor, 831,311/842,752 on eight and 137,715/139,008 on 19 saves. On this build, eight original settings and four saves of that version retain the previous local output bits. The node and evaluator release suites passed all 512 tests. Formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Connected graph depth and the ninth quadrant batch + +Start with the [complete eight-level tree and its first eight batches](#the-next-full-batch-in-an-eight-level-quadrant-tree). Draw .875 squares at depths two through eight on white, with roughness zero and gain 2⁻⁷⁶. Place depth-two squares 5 and 0 together at (.265625, .265625) with respective gains −1 and 2⁻²⁵. The center sample at 32² F32 is zero. Connect an empty Switch to one child slot of a final quadrant and the sample becomes 2⁻²⁵. Exchanging the gains reverses both results. Connecting the first leaf, the last leaf, any one of the four root subtrees or all leaves gives the same change. Disconnecting that edge restores the original result. + +The deciding property is the maximum quadrant depth connected to the root. Put the entire eight-level tree on the selected side of a Switch. On the other side, attach a chain reaching depth three, eight, nine or ten. Without executing any node in that chain, depths three and eight give zero and depths nine and ten give 2⁻²⁵. A disconnected ten-level chain gives zero. A separate field marked 714 pairs of draws. All 714 orders agreed with the deeper sequence for both the nine- and ten-level chains. An eight-level chain reversed 88 pairs, including 73 comparisons through the ninth batch. [Graph depth](../crates/core/src/pattern_graph.rs) · [Renderer and regressions](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +When the eighth batch reaches one of the last two depth-five subtrees in subtree 17, a deeper connected graph can submit a second batch from the same stream. Continue up to the start of subtree 18, take subtree 19's own draw and its final depth-four branch, then continue through quadrant 5 until both batches contain 10,920 physical copies. The shared renderer counts wrapped copies and copies that miss the image. Across ten qualifying distributions, all 3,177 signed-pair comparisons agreed. Unconditionally extending the sequence failed 801 of 5,180 comparisons in sixteen other distributions. [Copy submissions](../crates/nodes/src/pattern/underfilled_quadrants.rs) + +Beginning with one copy per draw, put 167 additional copies early in subtree 50. The first of the final two depth-five subtrees now begins at copy offset 5,459 and all 397 checked pairs retain their order. Adding one more copy moves that offset to 5,460 and reverses 16 pairs. Placing the same 168 copies in subtree 16 gives the same result. Adding 360 copies within the final 169 draws of subtree 17 preserves all 396 comparable pairs. A separate two-tree probe put the 10,920-copy cut inside a two- or four-copy stamp. All 56 edge and corner comparisons agreed in both gain directions. + +For an independent image comparison, use depth-two pairs (5,0), (0,5) and (5,1). Connect a Switch below each leaf with an unselected quadrant on its true side. Select that side only when the horizontal size exponent reaches nine. Render at 32² with gains (−1,2⁻²⁵), 16 × 32 with (−.5,2⁻²⁵), 32 × 16 with (−1,2⁻²⁴) and 64 × 32 with (2⁻²⁵,−1). At each size render U8, U16, F16 and F32 using consecutive seeds beginning at 41381, 41484, 41587 and 41690 respectively. Save each graph normally in MaterialCraft and reopen it in both applications. The reference pixels agree between original and reopened packages at all 48 settings. + +| Storage | Previous exact pixels | Previous maximum | Current original | Current reopened | Maximum on both | +|---|---:|---:|---:|---:|---:| +| U8 | 12,288/12,288 | 0 | 12,288/12,288 | 12,288/12,288 | 0 | +| U16 | 12,288/12,288 | 0 | 12,288/12,288 | 12,288/12,288 | 0 | +| F16 | 12,225/12,288 | 2⁻²⁴ | 12,288/12,288 | 12,288/12,288 | 0 | +| F32 | 11,784/12,288 | 2⁻²⁴ | 12,288/12,288 | 12,288/12,288 | 0 | + +On the [eight previously recorded Noise BNW Spots 1 settings](#the-next-full-batch-in-an-eight-level-quadrant-tree), the one-processor count rises from 24,145 to 24,180 of 25,088 exact pixels. The eight-processor count falls from 23,763 to 23,743. On one processor the two 16 × 32 F32 settings improve from 404 to 416 and from 403 to 409 of 512 pixels. The 32 × 64 setting improves from 1,914 to 1,925 of 2,048 and the 64² setting from 3,510 to 3,512 of 4,096. Their maximum absolute errors are 1.19209290e−7, 1.19209290e−7, 5.96046448e−8 and 2.38418579e−7 respectively. Four ordinary saves retain 2,799/2,816, maximum 5.96046448e−8. + +The full 86-setting comparison gives 806,533/841,728 on one processor and 780,289/841,728 on eight. Of the one-processor settings, 27 gained exact pixels, three lost exact pixels and 56 retained their counts. Forty-seven match completely. On eight processors seven gained, 22 lost and 57 retained their counts. Thirty-eight match completely. The 64 × 128 F16 setting at seed 411686, scale one, disorder and roughness .1875 and nonsquare expansion enabled became exact on one processor and lost one exact pixel on eight. Nineteen ordinary saves improved to 196,125/196,352 with 14 completely exact settings. Four original and four reopened captures of the 16 × 32 seed-zero F32 setting each give 416/512. + +| Storage | One processor · exact pixels · maximum | Eight processors · exact pixels · maximum | Reopened · exact pixels · maximum | +|---|---:|---:|---:| +| U8 | 108,800/108,800 · 0 | 108,799/108,800 · 1 | 90,112/90,112 · 0 | +| U16 | 328,361/328,448 · 1 | 328,258/328,448 · 1 | 93,687/93,696 · 1 | +| F16 | 108,800/108,800 · 0 | 108,798/108,800 · .00048828125 | 6,400/6,400 · 0 | +| F32 | 260,572/295,680 · 2.38418579e−7 | 234,434/295,680 · 3.57627869e−7 | 5,926/6,144 · 2.38418579e−7 | + +The 32 single-edge and mixed-connectivity controls improve from 31,298/32,768 to 32,768/32,768. The twelve unselected-branch controls improve from 11,994/12,288 to 12,288/12,288. Both previous maxima were 2⁻²⁵, and both current maxima are zero. The 397 earlier settings retain 1,294,280/1,294,336 exact pixels, maximum 5.29395623e−23. A separate high-density control adds 2,729 copies within subtree 58. Quadrant 14 and subtrees 58 and 59 now fill 5,460 copies before joining any other subtree. Their batch precedes the draws from quadrants 2 and 3 in all sixteen signed comparisons with those two batches. This early submission and the remaining later batches are open. + +The full measurement after the preceding eighth-batch change also covered the second version of Noise BNW Spots 1. All 87 original settings and 19 ordinary saves retained their previous output bits. The one-processor total was 831,506/842,752 and the eight-processor total was 831,311/842,752. Saved files matched 137,715/139,008. The [per-format counts and errors](#dense-settings-recovered-in-the-third-spots-graph) still apply to that comparison. + +The closed-Switch regression returned zero in place of 2⁻²⁵ before the change. The node library and evaluator passed all 510 release tests. Formatting, strict workspace Clippy, dependency layers and WebAssembly also passed. + +### Published filter properties upstream of a quadrant draw + +Connect each of six filters to the unused pattern image socket of the [four-square first-read probe](#connected-image-properties-and-the-first-quadrant-draw). Supply a fixed white Uniform where the filter takes an image. Use a per-pixel function returning .5, a Transform 2D offset of (0,0), grayscale weights (1,0,0,0), a Directional Blur angle of .25, a Levels input low of zero or Warp intensity zero. Make two graphs per filter. In one, compute the value entirely from constants. In the other, add zero times the published scalar to each component. The fixed graph draws .375 in all four quadrants. A published drawing input changes the first quadrant to .625 even when the filter returns identical pixels. The evaluator carries the property read through the image output and its cache entry. The Pixel Processor reports the reads of the same compiled function that produces its pixels. [Parameter evaluation](../crates/eval/src/parameter.rs) · [Pixel function](../crates/nodes/src/function/processor.rs) · [Cache and sampling-mode regressions](../crates/eval/tests/pattern_opacity.rs) + +Render the twelve graphs at 16 × 32 F32, 32 × 16 U8, 32² F16 and 16² U16 with seeds 41671, 41684, 41697 and 41710 respectively. Use the published default .8125 in F32 and F16 and change it to .3125 in U8 and U16. Save each graph normally in MaterialCraft, reopen the SBS in both applications and compare again. The original and reopened reference bits agree across all 48 settings. + +| Storage | Previous exact pixels | Previous max | Current original exact pixels | Current reopened exact pixels | Max on both | +|---|---:|---:|---:|---:|---:| +| F32 | 5,376/6,144 | .25 | 6,144/6,144 | 6,144/6,144 | 0 | +| U8 | 5,376/6,144 | 63 codes | 6,144/6,144 | 6,144/6,144 | 0 | +| F16 | 10,752/12,288 | .25 | 12,288/12,288 | 12,288/12,288 | 0 | +| U16 | 2,688/3,072 | 16,383 codes | 3,072/3,072 | 3,072/3,072 | 0 | + +At 16² and 32 × 16 F32, use seeds 41301 and 41309. Repeat with the Transform matrix, both Directional Blur controls, all five Levels controls and the grayscale matte with alpha flattening disabled and enabled. All these drawing properties produce .625 on the first square when published. Publishing a Transform filtering or mip mode, the grayscale alpha selector, the Levels intermediate clamp or the Warp filter gives .375. A per-pixel program that reads only the pixel position and returns .5 also gives .375. The twelve initial graphs match 9,216/9,216 pixels in these sizes. The ten selector and property comparisons match 7,680/7,680, and eight more numeric and sampling controls match 6,144/6,144, all with maximum error zero. + +For a published Transform matte, cross all four tiling choices with offsets (0,0), (.5,0), (0,.5) and (.5,.5). The first square is .375 with both axes tiled and .625 when either axis is untiled, including the identity transform. With a computed mip mode, use automatic and manual selection and a fixed or published mip level of zero. Only manual mode with the published level gives .625. These twenty graphs improve from 12,864/15,360 to 15,360/15,360 F32 pixels, maximum .25 to zero. + +In a separate instance check, pass the Uniform into a child graph containing the quadrant draw. Then put the Uniform in the child and draw in the parent. In each direction compare a published color, a fixed color and a disconnected image. The six graphs match 4,608/4,608 original and 4,608/4,608 reopened F32 pixels, with maximum error zero. + +Position Debug, Bevel Smooth Debug Position, Radial Blur Grayscale and Debug Hit UV retain 768/768, 4,096/4,096, 16,384/16,384 and 16,384/16,384 exact pixels respectively. Eight selected original settings for each Noise BNW Spots 1 version retain every MaterialCraft output bit. They match 24,856/25,600 and 25,546/25,600 reference pixels. Both have maxima of zero in U8 and F16 and one code in U16. Their F32 maxima are 2.38418579e−7 and 5.96046448e−8 respectively. Both roots remain open. + +Both new evaluator regressions returned .375 in place of .625 before the fix. All 508 release tests for the two changed crates, formatting, strict workspace Clippy, dependency layers and WebAssembly pass. + +### The next full batch in an eight-level quadrant tree + +In a complete additive tree, start with the [six leading batches](#leading-copy-batches-in-complete-quadrant-trees) and the [5,460-copy batch in the last root quadrant](#a-full-copy-batch-in-the-last-root-quadrant). Number depth-two quadrants 0–15 and depth-three subtrees 0–63 in child-slot traversal order. When the seventh batch reaches either of the final two depth-five subtrees in subtree 49, the next full batch begins with quadrant 12, continues through subtrees 50 and 51, and takes the remaining copies from quadrant 4 and its descendants. Physical copies count even when they miss the image. The shared quadrant renderer applies this prefix to trees with a draw at every depth from two through eight and two full batches per depth-two pair. [Submission order and cuts](../crates/nodes/src/pattern/underfilled_quadrants.rs) · [Two-square regression](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +Start with one physical copy per square. Add one wrapped copy to each of the first 168 unmarked draws in subtree 62. All twelve selected pair orders persist. Adding the 169th moves the cut before the final two subtrees and reverses five orders. Repeating the experiment in subtree 48 gives the same 168/169 boundary. Adding 360 copies within the final 169 draws of subtree 49 preserves all twelve orders. Compare each pair by drawing two overlapping squares on white, with gains −1 and 2⁻²⁵, then exchanging the gains. Across 16 distributions that meet the cut condition, all 4,884 pair comparisons agree. These include one, two and four trees and three copy distributions taken from whole-root settings. In ten other distributions the same proposed order fails 548 of 3,186 comparisons. + +For an independent image, draw .875 squares at depths two through eight, with background one, roughness zero and ordinary gain 2⁻⁷⁶. Move the two depth-two squares at (12,0), (0,12) or (12,4) to normalized position (.265625,.265625). Use gains (−1,2⁻²⁵) at 32² F32 with seed 41384, (−.5,2⁻²⁵) at 16 × 32 U8 with seed 41484, (−1,2⁻²⁴) at 32 × 16 U16 with seed 41588, and (2⁻²⁵,−1) at 64 × 32 F16 with seed 41692. The twelve settings improve from 12,141/12,288 pixels to 12,288/12,288 on both originals and ordinary saves. The previous maximum error was 2⁻²⁵ in F32. All corrected maxima are zero. Across 256 earlier signed-square settings, including their reopens, exact counts improve from 261,948 to 262,088 of 262,144. The remaining maximum is 5.29395623e−23. All 1,007,616 pixels in 117 earlier procedural controls still match. + +| Noise BNW Spots 1 · F32 | One processor, previous → current | Current maximum | Eight processors, previous → current | Current maximum | +|---|---:|---:|---:|---:| +| 16 × 32, scale and roughness one, disorder and seed zero | 403 → 404 / 512 | 1.19209290e−7 | 363 → 360 / 512 | 1.19209290e−7 | +| 16 × 32, exposed defaults, seed 194395 | 403 → 403 / 512 | 1.19209290e−7 | 363 → 360 / 512 | 1.19209290e−7 | +| 32 × 64, scale one, disorder and roughness .1875, nonsquare expansion enabled, seed 194489 | 1,898 → 1,914 / 2,048 | 5.96046448e−8 | 1,825 → 1,823 / 2,048 | 5.96046448e−8 | +| 64², scale two, disorder and roughness .53125, nonsquare expansion disabled, seed 194536 | 3,497 → 3,510 / 4,096 | 2.38418579e−7 | 3,312 → 3,316 / 4,096 | 1.19209290e−7 | + +Including 128² U16 at exposed defaults and the 16 × 32 seed-zero U8, U16 and F16 settings gives 24,145/25,088 exact original pixels on one processor, up from 24,115, and 23,763/25,088 on eight, down from 23,767. The maximum integer error is one U16 code. Four original and four reopened repeat captures of the seed-zero F32 setting each give 404/512. Four other saved settings retain 2,799/2,816 exact pixels, maximum 5.96046448e−8. The second version of the root retains every previous bit in the eight original and four saved settings. The order of subsequent batches and processor-dependent differences remain open. + +Repeating the [86 distinct original settings and 19 ordinary saves](#a-full-copy-batch-in-the-last-root-quadrant) gives these whole-root results. Integer errors count storage codes. Floating-point counts compare stored bits and maxima give absolute errors. + +| Noise BNW Spots 1 storage | One processor · exact pixels · max | Eight processors · exact pixels · max | Reopened · exact pixels · max | +|---|---:|---:|---:| +| U8 | 108,800/108,800 · 0 | 108,799/108,800 · 1 | 90,112/90,112 · 0 | +| U16 | 328,353/328,448 · 1 | 328,258/328,448 · 1 | 93,683/93,696 · 1 | +| F16 | 108,799/108,800 · .0001220703125 | 108,799/108,800 · .00048828125 | 6,400/6,400 · 0 | +| F32 | 256,650/295,680 · 2.38418579e−7 | 234,986/295,680 · 3.57627869e−7 | 5,925/6,144 · 2.38418579e−7 | + +On one processor, 25 settings gained exact pixels, 61 retained their counts and 46 match completely. The total rose from 799,592 to 802,602 of 841,728. The newly exact setting is 128 × 64 U16, seed 411625, scale two, disorder and roughness .96875, nonsquare expansion disabled. On eight processors, seven settings gained pixels, fifteen lost pixels and 64 retained their counts. The total rose from 780,781 to 780,842 of 841,728, with 39 completely exact settings. One saved setting gained five exact F32 pixels, bringing the reopened total to 196,120/196,352. Fourteen of the nineteen saved settings match completely. + +The two-square regression first returned zero in place of 2⁻²⁵. All 506 release tests for the node library and evaluator, formatting, strict workspace Clippy, dependency layers and WebAssembly pass. + +### Connected image properties and the first quadrant draw + +Connect a white Uniform to the pattern socket of the [four-square writable-float graph](#first-reads-of-writable-quadrant-floats). Use square mode so the draw does not sample this socket. Give each component of the Uniform the value one plus zero times the published scalar. The first square contributes .625, and the other three contribute .375. Replacing the Uniform with literal white, computing white entirely from constants or disconnecting it gives four .375 contributions. A Uniform with a published output-size offset of zero reproduces the first result. The evaluator carries this dependency through connected image outputs and includes it in the cook cache. [Graph evaluator](../crates/eval/src/node_execution.rs) · [Cache regression](../crates/eval/tests/pattern_opacity.rs) + +Use eight original graphs. Connect the live Uniform to the pattern and background sockets in turn. Use the literal and disconnected controls on the pattern socket. Insert a zero-intensity Blur after the live Uniform, then test a Blend whose opacity evaluates to one from a published input and whose source is fixed. For the last two graphs, connect another FX-Map whose square luminosity or outer opacity evaluates to one from that input. Render all eight with default .8125 at 16 × 32 F32 and 32² F16, and changed .3125 at 32 × 16 U8 and 16² U16. The respective seeds in table order are 41671, 41684, 41697 and 41710. Save each graph normally in MaterialCraft and repeat the measurements on the reopened graph in the reference desktop. + +| Storage | Previous exact pixels | Previous maximum error | Current original exact | Current reopened exact | Current maximum error | +|---|---:|---:|---:|---:|---:| +| F32 | 3,328/4,096 | .25 | 4,096/4,096 | 4,096/4,096 | 0 | +| U8 | 3,456/4,096 | 63 codes | 4,096/4,096 | 4,096/4,096 | 0 | +| F16 | 6,656/8,192 | .25 | 8,192/8,192 | 8,192/8,192 | 0 | +| U16 | 1,728/2,048 | 16,383 codes | 2,048/2,048 | 2,048/2,048 | 0 | + +At 16² and 32 × 16 F32, seeds 41301 and 41309, the direct input and background cases match 4,608/4,608 pixels. The nine literal, constant-expression and disconnected controls match 6,912/6,912. The six Blur and Blend chains match 4,608/4,608. Another 5,376/5,376 pixels distinguish an upstream pattern's drawing properties from the Uniform's seed, format, tiling and color selector. Connecting the live Uniform to the foreground, background or mask of a Blend gives the same first draw at fixed opacity zero and one, including when the selected color is fixed. All 4,608 pixels in those twelve settings match. The maximum error is zero in each group. + +Eight whole Noise BNW Spots 1 v2 settings retain every previous output bit and match 25,546/25,600 reference pixels, maximum one U16 code. The Position Debug and Bevel Smooth Debug Position controls match all 768 and 4,096 RGBA8 pixels respectively. The Tile helper matches 49,152/49,152 U16 pixels across defaults, seed 42 and changed parameters. The original and reopened spline preprocess controls each match 294,912/294,912 image pixels and six of six typed counts. The dense noise roots and the [remaining writable-variable widths](#first-reads-of-writable-quadrant-floats) stay open. + +The new cache regression first failed with .375 in the live square and now passes. All 505 release tests for the evaluator and node library, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### First reads of writable quadrant floats + +The first read of a writable scalar, float2 or float3 at a quadrant depth can produce undefined components when a drawing property reads a live graph input. The next visit at that depth sees the previous assignment. To distinguish these cases, connect four child slots to one square. In the square’s luminosity function, assign .375 if the local equals itself and .625 otherwise. With a live parent branch offset the squares read .625, .375, .375, .375 in traversal order. Substituting a literal for the graph input gives four .375 squares in this comparison. [Pattern evaluator](../crates/nodes/src/pattern/evaluation.rs) · [Variable scope](../crates/nodes/src/pattern/variables.rs) + +Use the eleven [tint and blend configurations](#undefined-components-in-a-computed-quadrant-tint) with the writable assignment of the previous local plus .0625. Use the published default .8125 at 16² F32 with seed 40991 and 32 × 16 U16 with seed 41005. Change the published input to .3125 at 16² F16 with seed 40998 and 32 × 16 U8 with seed 41012. Count a pixel as exact when every stored channel has the same bits, including NaNs. + +| Storage | Previous exact pixels | Corrected exact pixels | Previous maximum finite error | Corrected maximum error | +|---|---:|---:|---:|---:| +| U8 | 1,536/5,632 | 5,632/5,632 | 96 codes | 0 | +| U16 | 1,536/5,632 | 5,632/5,632 | 24,576 codes | 0 | +| F16 | 768/2,816 | 2,816/2,816 | .25 | 0 | +| F32 | 768/2,816 | 2,816/2,816 | .25 | 0 | + +The previous F16 and F32 results each had 768 differing nonfinite channels. All stored floating-point channels now match. Independently save each original in MaterialCraft and reopen it in the reference desktop. The original and reopened reference outputs agree on all 16,896 pixels. The five [nested caller configurations](#writable-first-reads-through-graph-instances) now match all 3,840 original and all 3,840 reopened F32 pixels, maximum zero in both sets. Changing only the origin of an opacity value of one also changes the first square when reusing the cook cache. [Cache regression](../crates/eval/tests/pattern_opacity.rs) + +For the component-width control, store the local plus a zero vector and start luminosity at .125. For each component unequal to itself, add 1/32, 2/32, 4/32 or 8/32 according to its position. Compare fixed opacity one with opacity one plus zero times a published input. The scalar, float2 and float3 cases match all 4,608 F32 pixels, maximum zero. The live float4 case still matches 0/768, maximum .21875. The fourth component can retain a finite value across reference cooks. The two integer controls match 0/1,536 with maximum .75. These initial values remain open. + +Connect a second square to a switch and drive its luminosity from a published input. The first square reads .625 even with the switch fixed to the other branch. Disconnecting the second square or setting its shape to zero gives .375. A published branch offset or seed still affects a shapeless quadrant. A published image index affects an image stamp with no texture connected. Image filtering and seed inheritance each leave the first square at .375. A graph-size function that returns (0,0) from a published scalar affects both relative size modes. With an absolute 16² size on the pattern node the first square reads .375. The six graph size and seed inheritance controls match 4,352/4,352 F32 pixels. [Connected-branch regression](../crates/nodes/src/pattern/tests.rs) + +Across ten scalar first-read expressions with fixed and live parents, 14,976/15,360 F32 pixels match, up from 14,016. The 384 remaining differences occur on the fixed-parent 32 × 16 captures, maximum .25. Thirty other binding and assignment variants improve from 12,288/23,040 to 19,200/23,040, maximum 1.5. A separate reference control with a live upstream Uniform color and literal properties on the pattern node also changes the first square. Disconnecting the Uniform or replacing its color with the same literal restores the four .375 readings. [Connected-image measurements and fix](#connected-image-properties-and-the-first-quadrant-draw) + +Seven original and four reopened settings of each Noise BNW Spots 1 version retain their previous MaterialCraft buffers bit for bit. Version one matches 20,618/20,992 original pixels on one processor and 20,455/20,992 on eight, with maximum one U16 code. Its ordinary saves match 2,799/2,816, maximum 5.96046448e−8. Version two matches 20,904/20,992 on both processor counts and 4,273/4,352 on saves, with respective maxima 1.19209290e−7 and 5.96046448e−8. Both whole roots remain in progress. [Original settings and previous buffers](#undefined-components-in-a-computed-quadrant-tint) + +Both new regressions failed on the preceding implementation. All 504 release tests for the node library and graph evaluator pass with the fix. Formatting, strict workspace Clippy, dependency layers and WebAssembly also pass. + +## 2026-11-24 root comparisons + +### Undefined components in a computed quadrant tint + +A quadrant can blend a computed tint with one undefined component. In a color square, an undefined red with finite alpha affects red alone. Floating outputs store the undefined channel as `0x7fffffff` in F32 and `0x7fff` in F16. Both integer formats store zero. A grayscale quadrant uses the alpha of a computed color. A square with undefined alpha or undefined scalar luminosity leaves its background visible. The horizontal offset ramp blends at undefined opacity and produces undefined components. [Quadrant property evaluation](../crates/nodes/src/pattern/evaluation.rs) · [Per-channel storage](../crates/nodes/src/pattern/raster.rs) · [Regression cases](../crates/nodes/src/pattern/tests.rs) + +To reproduce, connect four child slots of a quadrant to one unit square. Use a color background of (.25, .375, .5, .75), or its grayscale value .375. Subtract a published scalar from itself and divide the resulting zero by itself. In color, place the result in red of (red, .25, .125, .5), replace alpha in (.125, .25, .125, alpha), or use the result as a scalar tint. In gray, use the scalar and both color vectors. Test all six at blend mode 0, then red, alpha and gray scalar at mode 1 and red and gray scalar at mode 2. At mode 0 the color square with undefined red stores (NaN, .5, .5625, .875). Modes 1 and 2 store (NaN, .3125, .3125, .875). + +Use the published default .8125 at 16² F32 with seed 40991 and 32 × 16 U16 with seed 41005. Use .3125 at 16² F16 with seed 40998 and 32 × 16 U8 with seed 41012. Save each of the eleven graphs normally in MaterialCraft, reopen it in the reference desktop, and compare the raw channels. For the shape controls, use mode 0 with red, alpha and gray scalar tints. Test a Gaussian and both offset ramps, variation .375, then a connected uniform image with color (.5, .25, .125, .75) or gray .5. Repeat each with subtraction in place of division to supply finite zero. + +| Raw output | Squares | Reopened squares | Gaussian and ramps | Connected images | +|---|---:|---:|---:|---:| +| U8 | 5,632/5,632 | 5,632/5,632 | 9,216/9,216 | 3,072/3,072 | +| U16 | 5,632/5,632 | 5,632/5,632 | 9,216/9,216 | 3,072/3,072 | +| F16 | 2,816/2,816 | 2,816/2,816 | 4,608/4,608 | 1,536/1,536 | +| F32 | 2,816/2,816 | 2,816/2,816 | 4,608/4,608 | 1,536/1,536 | + +All 70,656 pixels agree in every stored bit. The maximum difference between finite channels is zero. Previously every one of the 88 square renders and the 48 undefined shape and image controls returned a cook error. The 48 finite controls already matched. + +The same eleven fields expose a separate writable-variable discrepancy. Replace zero divided by zero with an assignment of the previous local value plus .0625 to the same name, and read a published value in the parent branch. U8 and U16 each match 1,536/5,632 pixels with maxima of 96 and 24,576 codes. F16 and F32 each match 768/2,816 with maximum finite error .25 and 768 differing nonfinite channels. Checking the local for equality with itself before its first write distinguishes the first child from later siblings in the reference desktop. [Earlier assignment and read-only controls](#independent-writable-variables-in-six-level-quadrant-trees) + +The tint change preserves all measured MaterialCraft buffers in seven original and four reopened settings per root for Noise BNW Spots 1 and its second version. The original checks include exposed defaults, all four formats at 16 × 32, and two changed F32 settings. Against one- and eight-processor desktop captures the first version matches 20,618/20,992 and 20,455/20,992, maximum one U16 code. Its ordinary saves match 2,799/2,816, maximum 5.96046448e−8. The second version matches 20,904/20,992 at both processor counts, maximum 1.19209290e−7, and 4,273/4,352 on saves, maximum 5.96046448e−8. The outstanding dense F32 comparisons keep both roots in progress. [First version settings](#a-full-copy-batch-in-the-last-root-quadrant) · [Second version settings](#whole-root-precision-and-saved-comparisons-for-the-three-neighboring-spot-graphs) + +### The remaining sample in a dense draw-order replay + +Use Noise BNW Spots 1 at 16 × 32 in F32, with scale and roughness one, disorder zero and seed zero. The production renderer matches 403/512 pixels of the repeatable one-processor frame, maximum 1.19209290e−7. An independent replay of the recorded draw contributions orders 1,706 markers and locates 17 physical copy boundaries. It matches 511/512 pixels, maximum 5.96046448e−8. One of 387 additional pair comparisons also reverses. [Root settings and physical-copy measurements](#a-full-copy-batch-in-the-last-root-quadrant) + +At pixel (4,24), there are sixteen contributions. The replay adds .07803279906511307 before .02525315061211586, .03236100822687149 and .01711149513721466. To test their order, use two overlapping signed squares on a white background, with gains −1 and 2⁻²⁵, and swap their gains for a second read. Test thirteen pairs at the implicated positions, first alone and then with 150 unrelated pairs in the frame. Both measurements give the same thirteen answers. The .07803279906511307 contribution follows all three smaller weights. With their measured order, the pixel sum changes from .649192750453949 to the exact desktop value .6491926908493042. The rule that produces this order across seeds and copy distributions remains open. + +### Writable first reads through graph instances + +Inside a child graph, connect all four quadrant child slots to a square. In the parent quadrant's branch offset, assign a published scalar to a local and return (0,0). In the square's luminosity, read the same local and assign .375 if it equals itself, or .625 otherwise. Instantiate the graph five ways. Leaving the child input at its default, setting it to literal .4375 and computing it from literal .3125 + .125 each produce four .375 squares. Wiring the caller's published scalar, or computing .4375 plus zero times that scalar, produces .625 in the first square and .375 in the other three. + +Use 16² F32, seed 41301 and caller default .8125, then 32 × 16 F32, seed 41309 and caller value .3125. Ordinary saves reproduce all five reference results. MaterialCraft matches 2,304/2,304 pixels across the three fixed cases and 1,152/1,536 across the two caller-dependent cases. The same counts hold on originals and saves, with maximum errors zero and .25 respectively. [Direct first-read and tint comparisons](#undefined-components-in-a-computed-quadrant-tint) + +## 2026-11-23 root comparisons + +### Independent writable variables in six-level quadrant trees + +In a plain quadrant tree with six subdivision levels, each connected child of the root starts its own writable variable scope. Successive visits within that child retain the value at the declaring depth. With five full levels a counter spans all four root children. The evaluator checks the reachable nodes and terminal depths before starting separate scopes. An active declaration on the root remains available to descendants that only read it. [Scope handling](../crates/nodes/src/pattern/variables.rs) · [Traversal](../crates/nodes/src/pattern/evaluation.rs) · [Five- and six-level regression](../crates/nodes/src/pattern/tests.rs) + +Use a full six-level tree, a tree with all four root children followed by five single-child levels, and one with only opposite child slots at every level. For a five-level control, use all four slots throughout. At the leaves, draw a unit square and keep the first visited position in a local float. When the value is zero, write .125 + .5 × (1 + x + sy) / s², where s is the number of cells along an axis and (x,y) is the zero-based cell. Otherwise write the existing value. In the 64² complete tree the first positions have linear indices 0, 32, 2,048 and 2,080. There are four counters even when each root child contains only one leaf. + +For two other original fields, add 1/4,096 to a local counter at depth six or depth one in a complete six-level tree. Read the F32 field in a Pixel Processor using nearest sampling. Subtract the first pixel and add .125. For the depth-one field give the leaves a positive gain of 1e−30. Subtracting the first pixel removes an initial offset observed across separate reference renders of uninitialized variables. At 64² the depth-six field records 1,024 increments per root child. For both counter fields and all four first-position fields render s², 2s × s, s × s/2 and s × 2s. Use s = 64 for six levels and 32 for five. Use seed 598241 + 283i + j for size index i and format index j in the table order. Repeat after an ordinary save and reopen. + +| Output | Previous exact / 118,272 · max | Current original | Current ordinary save | Current max | +|---|---:|---:|---:|---:| +| U8 | 84,286 · 192 | 118,272/118,272 | 118,272/118,272 | 0 | +| U16 | 67,390 · 49,151 | 118,272/118,272 | 118,272/118,272 | 0 | +| F16 | 67,390 · .75 | 118,272/118,272 | 118,272/118,272 | 0 | +| F32 | 67,390 · .75 | 118,272/118,272 | 118,272/118,272 | 0 | + +Across the inventory, ten roots contain eleven pure quadrant trees ending at depth six. Their reachable quadrant properties contain no direct Set. Compare the two 256² and 128 × 64 desktop controls for each of BNW Spots 1 and Clouds 1 and 2, then four 64² changed-format captures each for BNW Spots 3, Directional Noise, Dirt Gradient, Fluid, Microscope View, Scratches 4 and Wood Fibers 2. All 34 MaterialCraft buffers retain their earlier bits. The reference comparisons give 28,672/28,672 U8, 249,844/249,856 U16, 28,672/28,672 F16 and 28,659/28,672 F32, with maxima of 0, 2, 0 and 2.59876251e−5 respectively. The thirteen differing F32 pixels are one in Dirt Gradient and twelve in Wood Fibers 2. [Early noise roots and their desktop settings](#live-desktop-and-standalone-rendering-of-three-noise-roots) + +A separate read/write discrepancy already occurs with a single level of four sibling squares. In the root branch offset, assign a published input to a local float and return (0,0). Reading the local in a child gives the published .8125 or .3125. Adding .0625 and assigning the result to a different name gives .875 or .375. Assigning that same sum back to the name just read returns zero in the reference and accumulates across the four squares in MaterialCraft. The 16² default gives 0/256, maximum .25. Replacing that child expression with a literal assignment of .25 restores 256/256 agreement. In the six-level version using an increment of 1/4,096, the 64² default still gives 0/4,096 F32 pixels, maximum .25, on both the original and ordinary save. The read-only version matches 4,096/4,096 on both. Uninitialized first-position fields can also retain a value from an earlier capture. Only the specified measurements are marked exact. + +### A full copy batch in the last root quadrant + +In a complete eight-level additive tree with two full batches per neighboring pair of depth-two quadrants, the next 5,460 physical copies come from three parts of the first tree. In zero-based child-slot traversal order, take the depth-two draw at 15, then the depth-three subtrees 62 and 63, then 48 and 49. Stop after 5,460 copies when these parts together contain one full batch and a smaller remainder. A cut within one wrapped stamp can submit some of its copies now and the others later. The shared evaluator uses the observed batch counts and the ordered spans. [Evaluator and shape conditions](../crates/nodes/src/pattern/underfilled_quadrants.rs) · [Two-square regression](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +Use the earlier signed-square procedure with depth-two (negative, positive) pairs (15,4), (12,15), (15,0) and (14,15). Use a plain quadrant for the first and fourth trees and one outer iteration for the second and third. Add faint first-level Gaussians to the second and fourth. The 32² default with pair (15,4) reads 2⁻²⁵ at (.265625,.265625), previously zero. Repeat at 16 × 32, 32 × 16 and 64 × 32 with the same changed gains, seed series and four output formats as the preceding batch experiment. [Gains, seeds and ordinary-save procedure](#leading-copy-batches-in-complete-quadrant-trees) + +| Output | Previous exact / 16,384 · max | Current original exact / 16,384 · max | Current ordinary save exact / 16,384 · max | +|---|---:|---:|---:| +| U8 | 16,384 · 0 | 16,384 · 0 | 16,384 · 0 | +| U16 | 16,384 · 0 | 16,384 · 0 | 16,384 · 0 | +| F16 | 16,300 · 2⁻²⁴ | 16,384 · 0 | 16,384 · 0 | +| F32 | 15,712 · 2⁻²⁴ | 16,286 · 5.29395623e−23 | 16,286 · 5.29395623e−23 | + +Together the four graphs match 65,438/65,536 original and 65,438/65,536 reopened pixels. Three retain a residual in F32. In five independently authored fields with one, two and four trees, all 1,250 signed order comparisons agree. Doubling the physical copies everywhere except depth-two pairs starting at 2, 6 and 10 in the first tree produces a second full batch in the last root quadrant. In this control 65/269 predicted orders differ. For a separate boundary check, double the footprints in subtrees 62 and 63 to place the cut there, or leave them at unit size to place it in 48 and 49. Place the boundary stamp across the horizontal seam for two copies, or across both seams for four. Test each copy against a depth-two square at 4 with both gain directions. All 56 comparisons agree, including cuts one, two and three copies into a four-copy stamp. All 245 earlier procedural settings still give 1,138,688/1,138,688 exact pixels. + +| Noise BNW Spots 1 | One processor · exact / total · max | Eight processors · exact / total · max | Ordinary saves · exact / total · max | +|---|---:|---:|---:| +| U8 | 108,800/108,800 · 0 | 108,799/108,800 · 1 | 90,112/90,112 · 0 | +| U16 | 328,342/328,448 · 1 | 328,259/328,448 · 1 | 93,683/93,696 · 1 | +| F16 | 108,799/108,800 · .0001220703125 | 108,799/108,800 · .00048828125 | 6,400/6,400 · 0 | +| F32 | 253,651/295,680 · 2.38418579e−7 | 234,924/295,680 · 3.57627869e−7 | 5,920/6,144 · 2.38418579e−7 | + +The 86 one-processor settings gain 4,246 exact pixels, reaching 799,592/841,728. The eight-processor comparisons lose 1,247, reaching 780,781/841,728. The 19 ordinary saves gain 13, reaching 196,115/196,352. At 16 × 32 with scale and roughness one, disorder zero and seed zero, the whole F32 image improves from 393 to 403 of 512, maximum 1.19209290e−7, in four original and four reopened captures. The early levels match 512/512 in each. Under the 256² exposed defaults and seed zero, F32 improves from 51,179 to 53,802 of 65,536 on one processor and changes from 43,327 to 42,389 on the eight-processor capture. The one-processor 256² F16 original is now exact. One 2,048-pixel F32 setting loses two exact pixels on one processor. One U16 setting becomes exact on one processor and loses whole-frame agreement on eight. At 32 × 64, seed 456747, scale two, roughness one and disorder .84375, interleave four fresh renders with changed seeds. The new F32 result loses exactly two matches against each of the five one-processor frames, including two of the 1,709 invariant pixels. At 64 × 32, seed 162172, scale one, disorder .5625 and roughness .6015625, all five one-processor U16 frames match 2,048/2,048. One capture with eight eligible processors and four repeats with seven give three distinct frames. All 2,045 invariant pixels agree, and each of the three varying pixels agrees with at least one capture. Subsequent submissions and processor-dependent differences remain open. [Earlier measurements and repeated captures](#leading-copy-batches-in-complete-quadrant-trees) + +### Leading copy batches in complete quadrant trees + +In a complete eight-level grayscale quadrant tree, each pair of neighboring depth-two quadrants contains eight depth-three subtrees. Number the subtrees 0–63 in child-slot traversal order. When every pair emits two full batches of 5,460 physical copies plus a remainder smaller than a batch, the first tree submits 10,920 copies from each of the spans starting at subtrees 24, 40 and 8, in that order. This was measured with additive draws at every level from two through eight and a separate optional shape at level one. Copies outside the sampled pixels still count. A cut within a wrapped stamp separates individual copies. The renderer applies the measured prefix and keeps its existing traversal for the remaining deeper draws. [Shared evaluator](../crates/nodes/src/pattern/underfilled_quadrants.rs) · [Two-square regression](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +For a minimal whole image, start with white, roughness zero and .875-square additive stamps at depths two through eight. Give ordinary stamps gain 2⁻⁷⁶. At depth two move two squares to (.265625,.265625) and expose their gains. Use the four (negative, positive) quadrant pairs (10,2), (2,0), (6,10) and (0,6). Use an outer one-repeat Iterate on the first and third trees, a plain quadrant on the other two, and faint first-level Gaussians on the last two. At 32², 16 × 32, 32 × 16 and 64 × 32 use (−1,2⁻²⁵), (−.5,2⁻²⁵), (−1,2⁻²⁴) and (2⁻²⁵,−1). The first pair uses the exposed defaults. Use seed 41381 + 103i + j with size index i and format index j in U8, U16, F16, F32 order. At the first 32² F32 readout the previous renderer returned zero and the reference returned 2⁻²⁵. + +| Output | Previous original exact / 16,384 · max | Current original | Current ordinary save | Current max | +|---|---:|---:|---:|---:| +| U8 | 16,384 · 0 | 16,384/16,384 | 16,384/16,384 | 0 | +| U16 | 16,384 · 0 | 16,384/16,384 | 16,384/16,384 | 0 | +| F16 | 16,321 · 2⁻²⁴ | 16,384/16,384 | 16,384/16,384 | 0 | +| F32 | 15,782 · 2⁻²⁴ | 16,384/16,384 | 16,384/16,384 | 0 | + +All 131,072 typed comparisons match. Separately, compare signed marker pairs in five procedural fields spanning one, two and four trees, squares and paraboloids, and both uniform and spatially varying counts of one, two and four copies. Keep a positive subpixel gain on the unmarked draws. Each depth-three subtree contains 1,365 logical draws. All 1,435/1,435 ordering comparisons agree. For a negative control with two trees, double the copies except in depth-two pairs starting at 2, 6 and 10 of the first tree. Some pairs now fill four batches. Five of 287 predictions reverse in two independent runs. The implementation tests the batch counts for every pair. Cuts one copy into a two-copy stamp and one, two or three copies into a four-copy stamp pass all 84 signed boundary comparisons. The earlier repeated-tree, variable-footprint, wide-shape and underfilled controls retain 1,007,616/1,007,616 exact pixels in 117 settings. + +| Noise BNW Spots 1 | One processor · exact / total · max | Eight processors · exact / total · max | Ordinary saves · exact / total · max | +|---|---:|---:|---:| +| U8 | 108,800/108,800 · 0 | 108,799/108,800 · 1 | 90,112/90,112 · 0 | +| U16 | 328,323/328,448 · 1 | 328,278/328,448 · 1 | 93,679/93,696 · 1 | +| F16 | 108,797/108,800 · .00048828125 | 108,799/108,800 · .00048828125 | 6,400/6,400 · 0 | +| F32 | 249,426/295,680 · 2.38418579e−7 | 236,152/295,680 · 3.57627869e−7 | 5,911/6,144 · 2.38418579e−7 | + +Across the 86 settings, exact counts change from 782,741 to 795,346 of 841,728 on one processor and from 788,160 to 782,028 on eight. Nineteen ordinary saves change from 196,084 to 196,102 of 196,352. On one processor two additional U16 settings are exact and all 27 previously differing F32 settings improve. At 16 × 32, scale one, roughness one, zero disorder and seed zero, all four original and four reopened F32 captures give 393/512, previously 370/512, maximum 1.19209290e−7. The early levels still match 512/512. At 256², exposed defaults and seed zero, five single-processor captures agree. F32 improves from 43,491 to 51,179 of 65,536, while F16 changes from 65,535 to 65,534 of 65,536. No previously exact single-processor setting loses whole-frame agreement. + +Four previously exact eight-processor settings have one differing pixel each in the recorded frames. Repeat the 16 × 32 scale-one U16 setting, the 64 × 128 U16 setting at seed 456840, and both 256² default floating-point formats four times with seven eligible processors, interleaving changed seeds. Including the recorded eight-processor result, the latter three settings each give five distinct frames. At the separate 16 × 32 U16 default in the second series, five measurements on each processor count reproduce their own result. MaterialCraft matches 512/512 on one and 511/512 on eight, maximum one. Later batches and processor-dependent ordering remain open. [Whole-root settings and prior counts](#first-level-draw-order-in-repeated-spot-quadrants) · [Independent pixel-order replay](#connected-inactive-descendants-and-dense-quadrant-draw-order) + +### Dense settings recovered in the third spots graph + +Build `f27ef77` renders six of the fourteen Noise BNW Spots 3 settings that previously reached the traversal bound. Compare the raw output to the recorded one- and eight-processor reference frames. At 64² use scale 3, disorder .34375, non-square expansion enabled and seed 411578. At 128² use scale 3, disorder .65625, non-square expansion disabled and seed 411761. In both rows keep the remaining exposed defaults. + +| Size and output | One processor | Eight processors | Maximum error on either | Ordinary save on one processor | +|---|---:|---:|---:|---:| +| 64² U8 | 4,096/4,096 | 4,096/4,096 | 0 | | +| 64² U16 | 4,094/4,096 | 4,095/4,096 | 1 | 4,094/4,096, max 1 | +| 64² F16 | 4,096/4,096 | 4,096/4,096 | 0 | | +| 64² F32 | 4,094/4,096 | 4,094/4,096 | 1.06692314e−5 | | +| 128² U16 | 16,376/16,384 | 16,375/16,384 | 1 | | +| 128² F32 | 16,375/16,384 | 16,376/16,384 | 1.07288361e−5 | 16,375/16,384, max 1.07288361e−5 | + +The six newly rendered settings give 49,131/49,152 exact pixels on one processor and 49,132/49,152 on eight. Four formats at 64 × 16, scale 2, disorder .03125, non-square expansion enabled and seed 42 still reach the execution bound. The same holds at 64 × 32, scale 3, disorder .34375, non-square expansion enabled and seed 194504. These failures also reproduce after an ordinary save in F16 at 64 × 16 and U8 at 64 × 32. The earlier sweep rendered 48 other settings. [Earlier 62-setting comparison and saved-file matrix](#whole-root-precision-and-saved-comparisons-for-the-three-neighboring-spot-graphs) + +Rechecking the complete 87-setting Noise BNW Spots 1 v2 matrix on this build gives 831,506/842,752 exact pixels on one processor, 831,311/842,752 on eight and 137,715/139,008 on the 19 ordinary saves. All 141,568 U8 pixels match on both processor counts. The F32 maximum is 1.19209290e−7 on both and on the saved cases. The U16 maximum is one in all three sets. F16 maxima are .00048828125 and .0001220703125 on one and eight processors, and zero on the saves. + +### Recovered settings in the second version of the third spots graph + +Rechecking the 32 Noise BNW Spots 3 v2 settings that previously exceeded the traversal budget produces 16 images on build `f27ef77`. Compare the original output to the recorded desktop frames using one and eight processors. Three of eight previously blocked ordinary saves now render. The table counts only the settings revisited here. [Earlier 62-setting sweep and save procedure](#whole-root-precision-and-saved-comparisons-for-the-three-neighboring-spot-graphs) · [Shared terminal traversal change](#bounded-work-for-terminal-quadrant-siblings) + +| Format | One processor · exact / total · max | Eight processors · exact / total · max | Reopened on one processor · exact / total · max | +|---|---:|---:|---:| +| U8 | 21,504/21,504 · 0 | 21,504/21,504 · 0 | 5,120/5,120 · 0 | +| U16 | 82,921/82,944 · 1 | 82,922/82,944 · 1 | | +| F16 | 5,120/5,120 · 0 | 5,120/5,120 · 0 | | +| F32 | 75,657/83,968 · 2.08616257e−7 | 75,152/83,968 · 2.38418579e−7 | 879/1,024 · 1.19209290e−7 | + +The 16 recovered originals match 185,202/193,536 pixels on one processor and 184,698/193,536 on eight. The three recovered saves match 5,999/6,144. To reproduce, set the exposed parameters below and leave other values at their defaults. A blank expansion field uses the exposed default. + +| Size | Seed | Scale | Disorder / speed / anisotropy / angle | Tile offset | Non-square expansion | Rendered | Still reaches budget | +|---|---:|---:|---|---|---|---|---| +| 128 × 128 | 0 | 2 | 0.37 / 0.6 / 0.3 / 0.125 | 0.17, 0.29 | | U8 | | +| 32 × 32 | 113 | 2 | 0.37 / 0.6 / 0.3 / 0.125 | 0.17, 0.29 | | F32 | | +| 64 × 64 | 42 | 2 | 0.37 / 0.6 / 0.3 / 0.125 | 0.17, 0.29 | | U8, U16, F16, F32 | | +| 64 × 16 | 42 | 2 | 0.03125 / 0.03125 / 0.03125 / -0.21875 | -0.3125, 0.37890625 | true | | U8, U16, F16, F32 | +| 64 × 64 | 411585 | 3 | 0.34375 / 0.34375 / 0.34375 / 0.09375 | 0, 0.10546875 | true | | U8, U16, F16, F32 | +| 128 × 64 | 411646 | 2 | 0.96875 / 0.96875 / 0.96875 / 0.71875 | 0.625, -0.44140625 | false | U16, F32 | | +| 128 × 128 | 411768 | 3 | 0.65625 / 0.65625 / 0.65625 / 0.40625 | 0.3125, -0.16796875 | false | | U16, F32 | +| 128 × 512 | 411890 | 2 | 0.53125 / 0.53125 / 0.53125 / 0.28125 | 0.1875, -0.05859375 | false | | U16, F32 | +| 512 × 128 | 411951 | 1 | 0.09375 / 0.09375 / 0.09375 / -0.15625 | -0.25, 0.32421875 | true | U16, F32 | | +| 64 × 32 | 194535 | 3 | 0.34375 / 0.34375 / 0.34375 / 0.09375 | 0, 0.10546875 | true | | U8, U16, F16, F32 | +| 64 × 64 | 194629 | 2 | 0.53125 / 0.53125 / 0.53125 / 0.28125 | 0.1875, -0.05859375 | false | U16, F32 | | +| 32 × 32 | 162174 | 2 | 0.78125 / 1.015625 / 0.390625 / 0.40625 | 0.1708984375, -0.29296875 | | U8, U16, F16, F32 | | + +The 64 × 16 F16, 64² U16 at seed 411585, 128² F32, 128 × 512 F32 and 64 × 32 U8 saved cases still reach the same execution bound. The 64² U8 save at seed 42 and the 32² U8 and F32 saves at seed 162174 are the three recovered cases. At 32² the original F32 gives 894/1,024 and the save 879/1,024 on their respective one-processor captures, both with maximum error 1.19209290e−7. + +### Connected inactive descendants and dense quadrant draw order + +An inactive branch beyond the last drawn level can change the order of earlier draws. Use an outer Iterate with two complete quadrant trees. Draw Gaussians at depth one and additive paraboloids at depths two through eight. Mark the eight first-level Gaussians, 32 depth-two draws, 128 depth-three draws, and leaves 0, 511 and 1,023 in each depth-three subtree. Use the quadrant position to address each level and initialize a tree ordinal in the Iterate. At a selected pixel over a background of one, give the two markers gains of −1 and 2⁻²⁵, then exchange their gains in a second render. Other draws have a positive gain too small to change the readout. + +At 128², inserting an active Switch before the tree preserves all 551 previously measured adjacent pairs. Connecting Switch inputs to all four child slots after depth eight, each selecting its unconnected branch while the other branch leads to a drawable quadrant, reverses 26 pairs. Extending the potential branch by one more switched quadrant reverses 27. The same 27 pairs reverse at 16 × 32 and 32 × 64. Adding an extra horizontal copy at each depth-six draw gives 37 reversals, the same at 128² and 16 × 32. Sorting the two fields with inactive descendants independently and checking both gain directions confirms all 551 adjacent pairs in each field. All eight first-level Gaussians still follow the deeper draws. + +For a spatially varying control, give each deeper draw the same number of physical copies as its footprint in a MaterialCraft trace. Encode the count, readout flag and destination pixel in a generated 512² input. Give single-copy markers a footprint .75 pixels wide and high. Place two-copy markers at the horizontal boundary with width 1.5 pixels and four-copy markers at a corner with both dimensions 1.5 pixels. Keep the 16 × 32 scale-one, roughness-one, zero-disorder, seed-zero case and the two inactive depths. Its 174,760 logical draws produce 177,238 copies. At seed 194395 with exposed defaults there are 177,244 copies. At 32 × 64, seed 194489, scale one, disorder and roughness .1875 and non-square expansion enabled, there are 177,526. Independent adjacent comparisons pass for all 525, 528 and 523 unwrapped markers respectively. In the seed-zero field, bringing wrapped markers into the readout gives 708 ordered draws with all 707 adjacent comparisons verified. + +The seed-zero whole output still gives **370/512 F32 pixels** in MaterialCraft, maximum 1.19209290e−7. Interpolating between the measured subtree markers predicts 499/512 at the same maximum error. For each of the 13 remaining pixels and eight controls drawn from the other pixels, independently sort the contributing deeper draws with the two-marker test. Replaying MaterialCraft’s original weights in those measured orders gives **21/21 F32 values exactly**, maximum zero. The 21 pixels contain 283 contributions including first-level shapes and repeated copies. This localizes the residual differences in those pixels to draw order. A common submission rule for an arbitrary tree is still open. [Whole-root setting and repeated ordinary saves](#physical-copy-boundaries-in-dense-quadrant-subtrees) + +### Inherited and writable variables across quadrant depths + +A quadrant child can read a value assigned by its parent. When the child declares the same name with Set, it opens the last value written at its own quadrant depth. Later writes at that depth can continue from that value across sibling nodes. A sibling that only reads the inherited name still sees the parent’s value. Iterate and Switch keep the current quadrant depth. MaterialCraft now saves and restores the two bindings separately. [Variable evaluator](../crates/nodes/src/pattern/variables.rs) [Traversal regression](../crates/nodes/src/pattern/tests.rs) + +Start with an empty root quadrant. Its branch offset assigns .25 to a named variable and returns (0,0). Connect additive squares in all four child slots. In slot order, write .8125 and emit it, read the parent’s value, add .0625 to the child binding and emit it, then perform the same increment again. On black the four F32 quadrant values are (.8125,.25,.875,.9375). Previously the second quadrant also emitted .8125. This reproduces with and without an outer Iterate and with either a direct getter or a getter plus zero. The four independently measured 16² controls improve from 768/1,024 to 1,024/1,024, maximum .5625 to zero. + +Repeat the four-child graph with a float, a float pair that emits its second component, and an integer in units of 1/128. In the pair graph set the first component to half the second. For size index i use 16², 32 × 16, 16 × 32 and 32². The corresponding (parent, first child, increment) triples are (.25,.8125,.0625), (−.125,.375,.125), (.5,.25,−.03125) and (1.25,−.1875,.0625). The first triple uses the exposed defaults. For format index j use U8, U16, F16 and F32, with seed 31873 + 37i + j. Export the raw result from the reference desktop, then repeat after an ordinary MaterialCraft save and reopen. + +| Output | Prior exact / 6,912 · maximum | Current original | Current reopened | Current maximum | +|---|---:|---:|---:|---:| +| U8 | 5,184 · 255 | 6,912/6,912 | 6,912/6,912 | 0 | +| U16 | 5,184 · 65,535 | 6,912/6,912 | 6,912/6,912 | 0 | +| F16 | 5,184 · 1.4375 | 6,912/6,912 | 6,912/6,912 | 0 | +| F32 | 5,184 · 1.4375 | 6,912/6,912 | 6,912/6,912 | 0 | + +In a separate complete tree, write .375 on an empty quadrant’s branch offset and read it at depth three on a square over a .125 background. At depths three and six, a depth-one writer gives 3,840/3,840 exact pixels per package over three seeds in each of the F32, U16 and F16 settings below. At depth seven only 20 of the 64 square cells receive the parent’s value in the reference. At depth eight a depth-one writer reaches 26 cells, and a depth-two writer reaches 56. MaterialCraft carries the value to all 64. At depth eight, with a depth-one writer, exact counts are 312/768 in F32, 624/1,536 in U16 and 624/1,536 in F16, on each package. Maximum errors are .375, 24,575 and .375 respectively. Use 16² F32 at seed 17, 32 × 16 U16 at seed 31, and 16 × 32 F16 at seed 42, adding 109 for each subsequent seed. Initializing the name in the outer Iterate also reproduces the depth-eight differences. A depth-zero writer gives all 3,840 pixels in that control. Work subdivision in deeper trees remains open. + +Across the 86 whole Noise BNW Spots 1 settings, the one- and eight-processor captures still give 782,741/841,728 and 788,160/841,728. The 19 ordinary saves give 196,084/196,352. Twelve mixed settings of the neighboring v2 root retain their earlier output bit for bit, 28,160/28,160 between MaterialCraft builds. Its one-processor reference comparison is 28,082/28,160 for those settings. All 411 release node tests passed, together with formatting, strict workspace Clippy, dependency layers and WebAssembly. [Full whole-root settings and errors by format](#first-level-draw-order-in-repeated-spot-quadrants) + +### Physical copy boundaries in dense quadrant subtrees + +At 16 × 32, scale 1, roughness 1, disorder 0 and seed 0, all four original and four reopened F32 captures of Noise BNW Spots 1 agree bit for bit. MaterialCraft matches **370/512 pixels** on each, maximum 1.19209290e−7. Levels 1–5 alone match all 512. This gives a repeatable whole graph for testing how deeper draws combine. At 64 × 32 and scale 3 the same reference desktop produces different whole frames with the same seed. [Eight-capture results for both spots graphs](#bounded-work-for-empty-terminal-quadrants) + +To isolate the first change in draw order, make a complete eight-subdivision quadrant tree. At depth eight, place pairs of square grids on the same 32² area of an F32 canvas filled with one. Give one grid gain −1 and the other 2⁻²⁵. The overlap records either zero or 2⁻²⁵. Pack 32 pairs per 256² frame. Measure all 2,016 pairs of depth-three subtrees and reverse the gains on 192 pairs. Earlier active levels emit unit-copy squares of gain 2⁻⁷² away from the readout. Activating depths four through eight submits 1,364 copies per depth-three subtree. Starting at depth three adds one copy. + +| Order tested against the reference | Settings | Exact F32 pixels | Maximum error | +|---|---:|---:|---:| +| Previously measured terminal order, 1,364 copies | 69 | 4,521,984/4,521,984 | 0 | +| Same order, 1,365 copies | 69 | 4,063,232/4,521,984 | 2.98023224e−8 | +| Order recovered at 1,365, positive readout reflected in both axes | 69 | 4,521,984/4,521,984 | 0 | +| Positions ranked separately, then reflected after adding a depth-two draw per four subtrees | 69 | 4,521,609/4,521,984 | 2.98023224e−8 | +| Same reflection with 64 extra horizontal copies per subtree | 69 | 4,457,623/4,521,984 | 2.98023224e−8 | +| Same reflection with varying extra copies | 69 | 4,494,769/4,521,984 | 2.98023224e−8 | + +For an independent test, overlap all 64 subtree grids on the same square of side .125 centered at (.5625,.4375). Use unit-size additive squares on depths three through eight with gain multipliers (1, −.75, 1.625, −.03125, .1875, −.375). Reflect the horizontal and vertical axes of each descendant according to the two low bits of its subtree's Morton index. For case j, generate 64 gains uniformly in [−.75,.75) with PCG64 seed 938137 + 49j and round to F32. In cases 2, 3 and 4 multiply every third gain, starting at zero, by 2⁻¹⁸. Use graph seed 35173 + 17j at 256², 512 × 256, 256 × 512, 128 × 256, 256 × 128 and 128² in that order. + +MaterialCraft matches **403,200/409,600**, maximum 4.76837158e−6, against each of the original and reopened packages. Summing in the order measured on the pair probes predicts **409,600/409,600**, maximum zero, on each package, including all 6,400 pixels in the overlap. Filling a quarter of a 5,460-copy batch changes the order even when no shape wraps. Applying the measured sequence directly to a whole spots graph still leaves differences. + +To measure repeated trees, initialize an ordinal in the outer Iterate, advance it at the root quadrant, and use the ordinal and quadrant position to select a marker from a generated input. Compare markers in both gain directions and verify adjacent pairs in independent renders. The depth-three markers pass 63/63 adjacent comparisons in one tree, 127/127 in two, and 255/255 in four. One four-tree comparison gave inconsistent gain reversals in the first capture. Four fresh captures in both directions agreed, and the independent adjacent comparisons passed. + +On two trees, mark all 32 depth-two draws, all 128 depth-three draws, and the first, middle (Morton index 511) and last leaf in each depth-three subtree. Both the single-copy field and a field with an extra horizontal copy at every depth-six draw pass 543/543 adjacent comparisons. The depth-three starts retain the same relative order in both. Some final leaves fall after the next subtree has started. With the two observed orders and the actual spot copy counts, replaying the full 16 × 32 case gives 437/512 and 438/512 pixels respectively, maximum 1.19209290e−7. The remainder still needs a common rule for mixed shapes and copy counts. + +### Bounded work for empty terminal quadrants + +A quadrant can evaluate its properties, produce no shape and finish with every child disconnected or behind a cached empty switch. After evaluating the properties and resolving the children, the evaluator charges the visit to the existing discard allowance while units remain. An empty terminal quadrant uses an ordinary visit once that allowance runs out. A quadrant with no shape and a live child also uses an ordinary visit. [Evaluator](../crates/nodes/src/pattern/evaluation.rs) [Budget regression](../crates/nodes/src/pattern/tests.rs) + +Start an Iterate with a full-frame additive square of gain .375 on a black canvas. On its repeated branch, recursively connect four identical quadrants per level. Each last quadrant connects to a switch whose right branch draws a square of size (1.25,.75) and gain .0625 when log₂(width) ≥ 6. Use zero roughness. For two subdivisions and three repetitions, render 16², 32 × 16, 16 × 32, 64 × 32 and 64² in U8, U16, F16 and F32. For size index i and format index j in that order, use seed 51271 + 31i + j. The original and its ordinary SBS save each match 29,696/29,696 pixels, maximum 0. + +With eight subdivisions and sixteen repetitions, the tree visits 1,048,576 terminal quadrants. At 16² and 32 × 16 the switches select their disconnected branch. At each size use U16 and F32, with j = 0 and 1 respectively. Previously all eight original and reopened renders reached the visit limit. They now match 1,536/1,536 pixels in each package, maximum 0. With a small test allowance, switching to a live child or requesting additional repetitions still returns the execution-budget error. + +In the two spots roots, use 64 × 32, scale 3 and seed 194442. Preserve all branches and disable the other shape levels in the pattern map being inspected. The following ten F32 isolates previously returned a traversal error. The maximum error is the absolute difference in stored float values. [Full parameter settings](#first-level-draw-order-in-repeated-spot-quadrants) + +| Root | Enabled levels | Exact / 2,048 pixels · maximum error | +|---|---|---:| +| Noise BNW Spots 1 | 1–5 | 2,038/2,048 · 5.96046448e−8 | +| Noise BNW Spots 1 | 1 | 2,048/2,048 · 0 | +| Noise BNW Spots 1 | 2 | 2,039/2,048 · 2.98023224e−8 | +| Noise BNW Spots 1 | 3 | 2,044/2,048 · 7.4505806e−9 | +| Noise BNW Spots 1 | 4 | 2,047/2,048 · 3.7252903e−9 | +| Noise BNW Spots 1 | 5 | 2,046/2,048 · 1.86264515e−9 | +| Noise BNW Spots 1 | 6 | 2,015/2,048 · 9.31322575e−10 | +| Noise BNW Spots 1 | 7 | 2,021/2,048 · 2.32830644e−10 | +| Noise BNW Spots 1 v2 | 7 | 2,048/2,048 · 0 | +| Noise BNW Spots 1 v2 | 9–10 | 2,048/2,048 · 0 | + +Capture levels 1–5 again in the first graph and levels 7–8 in v2, then reopen an ordinary MaterialCraft save in the reference desktop. U8, U16 and F16 each match 2,048/2,048 pixels on all four captures. F32 counts follow. + +| Root | Original F32 · maximum | Reopened F32 · maximum | +|---|---:|---:| +| Noise BNW Spots 1 | 2,018/2,048 · 5.96046448e−8 | 1,997/2,048 · 5.96046448e−8 | +| Noise BNW Spots 1 v2 | 2,047/2,048 · 5.96046448e−8 | 2,047/2,048 · 2.98023224e−8 | + +To check repeatability, capture each original and reopened package four times on one processor. Before each capture, render a control with seed 322027 + 37i + j, where i runs from 0 to 3 and j is 0 for the 16 × 32 comparison and 1 for the 64 × 32 comparison. The smaller setting uses scale 1, roughness 1, disorder 0 and seed 0. Compare each stored F32 pixel across the eight native frames, then compare MaterialCraft at the positions where all eight agree. The last column counts pixels for which at least one of the eight native values equals MaterialCraft's value. + +| Root and draws | Size | Distinct native frames | Native invariant / total | Exact at invariant pixels | Maximum native spread | Exact on any capture | +|---|---|---:|---:|---:|---:|---:| +| Noise BNW Spots 1, selected levels | 16 × 32 | 1 | 512/512 | 512/512 | 0 | 512/512 | +| Noise BNW Spots 1, selected levels | 64 × 32 | 8 | 1,890/2,048 | 1,889/1,890 | 1.1920929e-07 | 2,046/2,048 | +| Noise BNW Spots 1 v2, selected levels | 16 × 32 | 1 | 512/512 | 473/512 | 0 | 473/512 | +| Noise BNW Spots 1 v2, selected levels | 64 × 32 | 6 | 2,044/2,048 | 2,044/2,044 | 5.96046448e-08 | 2,048/2,048 | +| Noise BNW Spots 1, whole root | 16 × 32 | 1 | 512/512 | 370/512 | 0 | 370/512 | +| Noise BNW Spots 1, whole root | 64 × 32 | 8 | 1,608/2,048 | 1,511/1,608 | 1.1920929e-07 | 1,940/2,048 | +| Noise BNW Spots 1 v2, whole root | 16 × 32 | 2 | 506/512 | 471/506 | 5.96046448e-08 | 475/512 | +| Noise BNW Spots 1 v2, whole root | 64 × 32 | 6 | 2,044/2,048 | 2,044/2,044 | 5.96046448e-08 | 2,048/2,048 | + +The complete v2 comparison has 831,506/842,752 matching pixels on one processor and 831,311/842,752 on eight over 87 settings. Its 19 saved settings match 137,715/139,008. Both roots remain in progress. + +### Wide first-level shapes in additive quadrant trees + +The first-level shape in a complete eight-level quadrant tree can wrap more than twice on an axis. Counting those copies against the separate first-level batch restores the measured order of draws in the deeper subtrees. The shared renderer uses the stamp's rotated bounds and the graph's render and tiling regions. [Copy counts](../crates/nodes/src/pattern/footprint.rs) [Regression graph](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +Use the paired squares at depth three from the [submission-order comparison](#submission-order-in-underfilled-eight-level-quadrant-trees). Add a Gaussian to each first-level quadrant. For child j numbered 0–3 use size (5.5 + j, 7.75 − .5j), rotations 0, .125, .21875 and .34375 turns, and gain 2⁻⁸⁰. Swap the negative and small gains in the paired squares and run one and three repetitions. Also drive the gains with scalar constant functions and reopen the three-repeat swatch graph. At 32², 64 × 32 and 32 × 64, seeds 41381, 17 and 42, the six series improve from 30,288/30,720 F32 pixels, maximum 8.94069672e−8, to 30,720/30,720, maximum 0. + +At 32² and seed 41381, set all four first-level rotations to zero and all sizes to (68,76). Change the first child's width to 64, 68 and 72. Those settings submit 5,382, 5,460 and 5,538 first-level copies. The first two each match 1,024/1,024, maximum 0. The last matches 1,008/1,024, maximum 2.98023224e−8, and remains open. + +Enable the first five levels together in the [six spots settings](#first-level-draw-order-in-repeated-spot-quadrants). In the first graph, four or five first-level stamps cross the previous per-axis limit in each of the three differing settings. The five completed original cases improve from 7,902/8,192 F32 pixels, maximum 5.96046448e−8, to 8,192/8,192, maximum 0. Five freshly reopened cases give the same improvement. In the v2 graph the corresponding probe selects levels 7–8 of its pattern map. These settings match 8,047/8,192 on the original and 8,048/8,192 after reopening, maximum 1.19209290e−7 on each. The two reference captures for v2 agree on 8,175/8,192, maximum 5.96046448e−8. + +Across all 86 whole-root settings for the first graph, 782,741/841,728 pixels match on one processor and 788,160/841,728 on eight. Nineteen ordinary saves match 196,084/196,352. The maximum F32 errors are 3.57627869e−7, 2.38418579e−7 and 2.38418579e−7 respectively. All six combined-depth isolates finish at 8,618/10,240 F32 pixels, maximum 2.38418579e−7. + +### Submission order in underfilled eight-level quadrant trees + +On a white grayscale F32 canvas, subdivide a quadrant eight times into four children. Put identical additive shapes in all 64 depth-three cells. In depth-first order starting at zero, move cells 50 and 0 to (.25,.25) and the others to (.75,.75). Give cell 50 gain −1, cell 0 gain 2⁻²⁵ and the others .125. Set the authored square size to (.875,.875). The center of the first mark reads 2⁻²⁵. Traversal order gave zero. In three repetitions with gain −.25, the same mark reads .25 plus three units of 2⁻²⁵. The original and its ordinary SBS save give identical readouts at 32², 64 × 32 and 32 × 64 with seeds 41381, 17 and 42. [Executable regression](../crates/nodes/src/pattern/tests/underfilled_quadrants.rs) + +Swapping the gains for each of four pairs (50/0, 54/58, 62/8 and 53/48) gives 24 settings per package. Original and reopened comparisons each improve from 40,672/40,960 pixels, maximum 2⁻²⁵, to 40,960/40,960, maximum 0. The three-repeat check improves from 5,048/5,120, maximum 8.94069672e−8, to 5,120/5,120 on each pass. + +The shared renderer groups the draws below each depth-two quadrant into its own draw and its four child subtrees. In the measured complete trees, eight groups of those ranges composite in a stable order. Each group processes successive repetitions in order. The renderer records the boundaries before discarding stamps that miss every sample. It counts nonzero tile copies, including subpixel draws, to detect the 5,460-copy boundary. The measured path covers additive analytic shapes with all 64 depth-three subtrees occupied in each repetition and every submission group below that boundary. [Group ranges and eligibility](../crates/nodes/src/pattern/underfilled_quadrants.rs) + +For independent F32 fields, draw at depths 2, 3 and 8. Use signed seeded gains, jittered frame offsets and five masks admitting 4, 8, 11, 6 and 9 positions per axis out of 32 in each depth-three subtree. Use 128 × 64, 256 × 128, 64 × 128, 128 × 256 and 128² with seed 41381 + 57j for row j starting at zero. A second series uses width 1 + (19g mod 13) for subtree g and changes the corner from which its mask grows. The repetition sweep includes every count from one through twelve. + +| Generated fields | F32 settings | Traversal order, exact / total · max | Corrected renderer, exact / total · max | +|---|---:|---:|---:| +| Fixed gate widths, two shapes and one, two or four repetitions | 30 | 568,951/589,824 · 3.6239624e−5 | 589,824/589,824 · 0 | +| Uneven gate widths, one, two or four repetitions | 15 | 284,456/294,912 · 1.23977661e−5 | 294,912/294,912 · 0 | +| Three, five, six or eight repetitions | 12 | 283,229/294,912 · 4.95910645e−5 | 294,912/294,912 · 0 | +| Seven, nine, ten, eleven or twelve repetitions | 5 | 38,893/40,960 · 9.15527344e−5 | 40,960/40,960 · 0 | + +In Noise BNW Spots 1, isolate depths by disabling the other shapes while keeping their original branches. Use the six settings from the previous first-level comparison. Five permit each shallow isolate to finish. At 64 × 32, scale 3, seed 194442, the shallow isolates reach the traversal budget. The depth-eight, deep and all-draw settings complete on all six. Counts below compare stored F32 pixels with the one-processor reference. [Parameters for the six settings](#first-level-draw-order-in-repeated-spot-quadrants) + +| Draws enabled in the spots graph | Before, exact / total · max | After, exact / total · max | +|---|---:|---:| +| Depth 3 | 8,094/8,192 · 2.98023224e−8 | 8,192/8,192 · 0 | +| Depth 4 | 8,060/8,192 · 2.98023224e−8 | 8,192/8,192 · 0 | +| Depth 5 | 8,040/8,192 · 2.98023224e−8 | 8,192/8,192 · 0 | +| Depth 6 | 8,023/8,192 · 1.49011612e−8 | 8,192/8,192 · 0 | +| Depths 1–5 | 7,297/8,192 · 1.1920929e−7 | 7,902/8,192 · 5.96046448e−8 | +| Depth 7 | 8,033/8,192 · 1.49011612e−8 | 8,107/8,192 · 3.7252903e−9 | +| Depth 8 | 10,093/10,240 · 2.98023224e−8 | 10,093/10,240 · 2.98023224e−8 | +| Depths 6–10 | 8,948/10,240 · 5.96046448e−8 | 8,948/10,240 · 5.96046448e−8 | +| All authored depths | 8,618/10,240 · 2.38418579e−7 | 8,618/10,240 · 2.38418579e−7 | + +All 86 whole-root settings complete. Exact counts are 782,741/841,728 on one processor, 788,160/841,728 on eight and 196,084/196,352 in 19 ordinary saves. The previous comparison gives the same totals and per-format maxima. An additional original series uses each row below in U8, U16, F16 and F32. Reopen rows 1, 4, 5 and 8 from an ordinary SBS save. + +| Size | Seed | Scale | Disorder | Roughness | +|---|---:|---:|---:|---:| +| 8² | 0 | 1 | 0 | 1 | +| 16 × 8 | 17 | 1 | .21875 | 0 | +| 8 × 16 | 42 | 1 | .375 | .0625 | +| 16² | 371149 | 2 | .6875 | .25 | +| 32 × 16 | 537367 | 1 | .3125 | .5 | +| 16 × 32 | 33753 | 2 | .203125 | 1 | +| 32² | 31717 | 1 | .84375 | 2 | +| 64 × 32 | 87239 | 2 | .25 | .03125 | + +| Whole-root series | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Original, 32 settings | 4,672/4,672 · 0 | 4,670/4,672 · 1 | 4,672/4,672 · 0 | 3,965/4,672 · 1.78813934e−7 | +| Reopened, 16 settings | 2,880/2,880 · 0 | 2,879/2,880 · 1 | 2,880/2,880 · 0 | 2,687/2,880 · 1.19209290e−7 | + +Full groups can split a subtree. For all 2,016 pairs of depth-three groups, plus 192 swapped-gain comparisons, a 23 × 23 gate per group matches the underfilled order on 1,168,032/1,168,032 overlap pixels. A 24 × 24 gate matches only 939,108/1,271,808. The first split occurs after 276 leaves of a subtree in Morton order, the remainder of 5,460 divided by 576. A separate prediction that submits full groups first matches all 69 frames in two uneven-density series and 68/69 in a third. Three one-processor recaptures of the differing setting, each preceded by a different control, match that prediction on all 393,216 pixels. Full-group ordering and the whole spots root remain open. + +Across three interleaved single-processor release runs per build, median process CPU for the 32² scale-2, 16 × 32 default and 64² changed root settings was 13.719 seconds before and 11.766 seconds after. Two settings on the two-repetition generated field took 6.203 and 6.328 seconds respectively. All 408 node release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Runtime scalar arithmetic in graph and node seeds + +A graph or node can compute its random seed from a caller's parameters. Converting a driven float to a seed preserves the 32-bit representation of its floored value. For example, a width of 16 supplies `0x41800000`. Runtime scalar addition in a seed expression adds the operand words modulo 2³². With .75 and .25 the resulting word is `0x7dc00000`. Subtraction and multiplication in the measured expressions use ordinary float arithmetic. A folded conversion of the constant −1.5 returns the integer −2. The shared evaluator now selects these operations when evaluating a base random seed. [Regression covering both seed properties](../crates/eval/tests/seed_arithmetic.rs) + +To reproduce the direct measurement, feed two exposed floats from a parent to a child. Use the first operand, their sum, their difference or their product, followed by a scalar float-to-integer conversion. Apply the result to the graph or to a grayscale F32 Pixel Processor returning Random(1). Compare all 256 stored pixels at 16² for (.75,.25), (1.75,.25), (−.25,.5), (−1.25,−.5), (5.125,1), (16,1), (32,2) and (0,−1). Each seed property matches **8,192/8,192 pixels**, maximum zero. Return the same expressions through a typed Value Processor, an integer instance argument and a float instance argument. Each matches 32/32 typed results, maximum zero. + +Nine further graph-seed expressions cover comparisons against zero and one, multiplication before or after addition, absolute value, subtraction after addition, the sum of two converted integers and the folded negative constant. They match 18,432/18,432 F32 pixels on the originals and another 18,432/18,432 after an ordinary save and desktop reopen, maximum zero. Direct size and argument checks at 16² and 32 × 16 match 15,360/15,360. The three dimension conversions that previously matched 0/3,072 now match 3,072/3,072 on both originals and saves. Moving the sum, product and conversion predicates to graph size, node size and node format gives 3,072/3,072, 3,072/3,072 and 6,144/6,144 pixels respectively, maximum zero. + +For the whole-root test, instance BNW Spots 1, Clouds 1 or Clouds 2 beneath a child with the computed seed. Use the changed caller from the integer-seed comparison. For each root, try the first operand converted to integer, the converted sum, the converted product, an integer 5 or 0 selected by whether the sum exceeds zero, and the sum of the two converted integers. Render at 16² with seed 0 and (1.75,.25), 64 × 32 with seed 17 and (−1.25,−.5), 32 × 64 with seed 372177 and (5.125,1), and 32² with seed 372421 and (.75,.25). Read the actual U16 output in the desktop with one eligible processor. [Caller settings and seed inheritance](#computed-graph-seeds-on-load-evaluation-and-save) + +| Root | Previous exact / total · maximum U16 codes | Corrected original · max | Corrected after ordinary save and reopen · max | +|---|---:|---:|---:| +| BNW Spots 1 | 6,657/26,880 · 43,285 | 26,880/26,880 · 0 | 26,880/26,880 · 0 | +| Clouds 1 | 6,657/26,880 · 45,527 | 26,880/26,880 · 0 | 26,880/26,880 · 0 | +| Clouds 2 | 6,657/26,880 · 50,514 | 26,880/26,880 · 0 | 26,880/26,880 · 0 | + +The desktop originals and saves also match each other in all 26,880 pixels per root. The catalog scan found zero authored graph or top-level atomic seed expressions in the 546 root bodies. These measurements cover caller-supplied scalar seed arithmetic. The earlier differences between repeated noise renders remain open. [Eight-processor captures](#archived-noise-settings-and-repeated-intermediate-reads) + +### Live desktop and standalone rendering of three noise roots + +Create an original parent and child wrapper around each catalog root. Sum the parent seed, instance offset +3 and parent-relative child offset −3. Drive the child offset with an integer input. Set Disorder to .96875 on BNW Spots 1 and Clouds 1. Clouds 2 has no exposed Disorder input. Request F32 at the caller and read the terminal storage type from the live desktop. It returns U16. Compare raw U16 pixels at 256² with seeds 372421 and 0, then at 128 × 64 with seed 372177. Use the same settings after an ordinary MaterialCraft save and desktop reopen. Restrict the desktop process to one logical processor during each capture and restore its affinity afterward. + +For a separate check at 256² and seed 372421, compile the same original wrapper with default optimizations and with optimizations disabled. In each case render twice with one explicit worker and twice with eight using the D3D11 standalone renderer. Export F32 TIFF and compare to the normalized live U16 field. The last column gives the range of exact counts and largest absolute error across its four captures. + +| Root | MaterialCraft vs. desktop U16, original and saved, each | Standalone vs. desktop, one worker · max | Standalone vs. desktop, eight workers · max | +|---|---:|---:|---:| +| BNW Spots 1 | 139,264/139,264 | 65,530/65,536 · 3.0517578125e-05 | 65,530–65,536/65,536 · 3.0517578125e-05 | +| Clouds 1 | 139,264/139,264 | 65,534/65,536 · 6.103515625e-05 | 65,532–65,536/65,536 · 0.000106811523438 | +| Clouds 2 | 139,264/139,264 | 65,532/65,536 · 3.0517578125e-05 | 65,533–65,535/65,536 · 3.0517578125e-05 | + +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) + +### Repeated desktop renders of the three early noise roots + +Use the same original parent and child files and ordinary saves as in the single-processor desktop comparison above. Select eight alternating eligible logical processors, then all sixteen. Each capture records its processor mask and restores the previous mask. Start at 256² with seed 372421, switch to 128 × 64 with seed 372177 and repeat the first request. Render 256² with seed 0, repeat the rectangle and return to the first request a third time. Reopen the ordinary save and repeat the sequence. Read the actual U16 output from the reference desktop. + +| Root | Eligible processors | Exact vs. MaterialCraft across six 256² captures at seed 372421, per capture | Maximum U16 error | Exact between repeats on the same open file, per comparison | Maximum repeat error | Stable desktop pixels matching MaterialCraft / all stable pixels | +|---|---:|---:|---:|---:|---:|---:| +| BNW Spots 1 | 8 | 65,530–65,536/65,536 | 2 | 65,530–65,536/65,536 | 2 | 65,530/65,530 | +| BNW Spots 1 | 16 | 65,530–65,536/65,536 | 2 | 65,530–65,536/65,536 | 2 | 65,530/65,530 | +| Clouds 1 | 8 | 65,532–65,535/65,536 | 7 | 65,534–65,535/65,536 | 7 | 65,532/65,533 | +| Clouds 1 | 16 | 65,532–65,535/65,536 | 7 | 65,533–65,536/65,536 | 7 | 65,532/65,532 | +| Clouds 2 | 8 | 65,531–65,534/65,536 | 2 | 65,531–65,536/65,536 | 2 | 65,530/65,531 | +| Clouds 2 | 16 | 65,531–65,534/65,536 | 2 | 65,530–65,536/65,536 | 2 | 65,529/65,530 | + +Each rectangular capture matches 8,192/8,192 pixels, maximum 0. The seed-0 default-size checks give the following results on the original and its ordinary save. Each range covers those two captures. + +| Root | Eligible processors | Exact vs. MaterialCraft at seed 0, per capture | Maximum U16 error | +|---|---:|---:|---:| +| BNW Spots 1 | 8 | 65,536/65,536 | 0 | +| BNW Spots 1 | 16 | 65,531–65,536/65,536 | 2 | +| Clouds 1 | 8 | 65,529–65,532/65,536 | 4 | +| Clouds 1 | 16 | 65,529–65,530/65,536 | 4 | +| Clouds 2 | 8 | 65,534–65,535/65,536 | 2 | +| Clouds 2 | 16 | 65,533–65,535/65,536 | 2 | + +At seed 372421, some BNW Spots 1 captures match the entire MaterialCraft buffer at each affinity. Clouds 1 has one stable differing pixel among the six eight-processor captures. Clouds 2 has one at each affinity. The six samples at each affinity establish repeatability only for those captures. All three remain in progress. [Single-processor desktop and standalone results](#live-desktop-and-standalone-rendering-of-three-noise-roots) + +### Archived noise settings and repeated intermediate reads + +Match earlier whole-root renders to the one-processor comparison by width, height, seed, exposed input values, wired images and actual output format. Compare MaterialCraft revision `1cc2da0` with those same one-processor frames. For each root, take the eight settings whose earlier and one-processor captures disagreed. Render those eight settings four more times in the desktop with eight eligible processors. Reverse or rotate their order between runs. Use the same raw output and restore the processor mask after each capture. + +| Root | Matched settings | Exact vs. one processor · max | Exact vs. earlier captures | Fully exact eight-processor frames among 32 repeats | Disputed settings with at least one exact repeat | +|---|---:|---:|---:|---:|---:| +| BNW Spots 1 | 125 | 3,177,984/3,177,984 · 0 | 3,177,932/3,177,984 | 11/32 | 6/8 | +| Clouds 1 | 48 | 787,712/787,712 · 0 | 787,692/787,712 | 4/32 | 3/8 | +| Clouds 2 | 47 | 771,328/771,328 · 0 | 771,310/771,328 | 5/32 | 2/8 | + +| Root | Fresh U16 exact / total · max codes | Fresh F16 exact / total · max | Fresh F32 exact / total · max | +|---|---:|---:|---:| +| BNW Spots 1 | 458,686/458,752 · 2 | 262,144/262,144 · 0 | 556,966/557,056 · 0.0000216364861 | +| Clouds 1 | 720,834/720,896 · 7 | — | 540,637/540,672 · 0.000110566616 | +| Clouds 2 | 786,389/786,432 · 2 | — | 655,325/655,360 · 0.0000229179859 | + +All U8 comparisons matched in the earlier captures. No U8 setting qualified for the repeat series. Earlier maximum errors in U8, U16, F16 and F32 were 0, 2, .000244140625 and .0000216364861 for BNW Spots 1, 0, 4, 0 and .000110566616 for Clouds 1, and 0, 2, 0 and .0000229179859 for Clouds 2. The cloud rows cover the overlapping archive settings. [Full single-processor measurements](#compositing-complete-seven-level-additive-quadrant-trees) + +Read each generator, its downstream filters and the root output through the desktop on one processor and in four additional eight-processor captures. These reads can trigger separate evaluations. The following are values from the first eight-processor inspection and its single-processor counterpart. Coordinates start at the top left. All other generator outputs matched in these three inspections. + +| Root and U16 setting | First differing FX-Map, exact / total · max | Example texel (x,y), one → eight | Whole output, exact / total · max | +|---|---:|---|---:| +| BNW Spots 1, 128 × 256, seed 372360, Disorder .203125 | 8,191/8,192 · 1 | (52,66), 11975 → 11974 | 32,761/32,768 · 1 | +| Clouds 1, 128², seed 42, defaults | 16,383/16,384 · 1 | (112,7), 2245 → 2244 | 16,381/16,384 · 3 | +| Clouds 2, 128 × 256, seed 382397, defaults | 32,765/32,768 · 1 | (20,58), 1248 → 1249 | 32,765/32,768 · 2 | + +In BNW Spots 1 the differing field feeds Transformation 2D and Blend, then Levels. The inspected transformation matches 32,764/32,768, maximum 1. A later eight-processor inspection of the same setting matches the entire single-processor output. The three roots retain their in-progress status. [Earlier repeated desktop captures](#repeated-desktop-renders-of-the-three-early-noise-roots) + +#### Replaying the differing generator samples + +At each U16 setting in the table above, cook the corresponding FX-Map in MaterialCraft. Verify that its generated field equals the one-processor field, then supply it to the same downstream graph as an image input at its native dimensions and precision. The unmodified field reproduces every pixel of the one-processor root output. For each eight-processor read, change only the texels that differ in the inspected FX-Map. BNW Spots 1 and Clouds 1 each require the one-code changes shown above when a generator difference is present. For the first Clouds 2 read, add one at (20,58) and subtract one at (35,113) and (79,232). + +| Root | Exact replay / total on the first eight-processor read · maximum U16 codes | Exact replay across four eight-processor reads · maximum U16 codes | +|---|---:|---:| +| BNW Spots 1 | 32,768/32,768 · 0 | 131,072/131,072 · 0 | +| Clouds 1 | 16,384/16,384 · 0 | 65,536/65,536 · 0 | +| Clouds 2 | 32,768/32,768 · 0 | 131,068/131,072 · 2 | + +The first replay reproduces all seven, three and three differing output pixels respectively. For Clouds 2 the other three replays leave two, one and one differing pixels, with maximum errors of 2, 1 and 2 codes. The desktop can reevaluate the generator and terminal output on separate port reads. The measurements isolate the input differences that explain each exact replay. + +### Filtering root outputs through two graph instances + +Wrap each of BNW Spots 1, Clouds 1 and Clouds 2 in an original child and parent. Wire the parent instance output into Blur and keep the catalog graph intact. Set tiling on the nested source to none for U8, horizontal for U16 and vertical for F16. Use Blur intensity 12. For F32 set the nested source pixel ratio to stretch (0) and drive Blur intensity with 12 times the inherited pixel ratio. Use the default caller for U8 and F16, and the changed caller from the seed comparison for U16 and F32. Render 64² with seed zero, 128 × 64 with seed 372177 and 64 × 128 with seed 372421. Reopen a normal MaterialCraft save in the desktop and repeat. [Seed caller construction](#computed-graph-seeds-on-load-evaluation-and-save) + +| Root | Previous F32 exact / total · max | Corrected F32 exact / total · max | All four formats, original exact / total · max | All four formats, reopened exact / total · max | +|---|---:|---:|---:|---:| +| BNW Spots 1 | 0/20,480 · 0.354674250 | 20,480/20,480 · 0 | 81,920/81,920 · 0 | 81,920/81,920 · 0 | +| Clouds 1 | 0/20,480 · 0.425102033 | 20,480/20,480 · 0 | 81,920/81,920 · 0 | 81,920/81,920 · 0 | +| Clouds 2 | 0/20,480 · 0.212616652 | 20,480/20,480 · 0 | 81,920/81,920 · 0 | 81,920/81,920 · 0 | + +U8, U16 and F16 each match 20,480/20,480 per root before and after the sampling-property correction. Every original and reopened desktop output also agrees exactly. [Sampling-property fix and flat controls](#sampling-properties-on-graph-inputs-and-outputs) + +### Conditional inputs shared across function branches + +Build fourteen original functions that select between two arms. Share a Random(1) between an arm and the result, or between both arms. Place a separate draw before the shared draw in each arm. For an assignment, initialize a float to .125, assign .625 in one arm and read it from the other. Add a quarter of the assigned result after the conditional. Swap the arms and include both possible conditions. Additional controls use a stored range, a graph input as the range and an assignment read by the condition. Run each at 16² for graph seeds 0 and 17 and both signs of the control. Repeat on ordinary saves reopened in the reference desktop. + +| Function context | Previous exact samples · maximum error | Corrected original exact samples | Corrected reopened exact samples | +|---|---:|---:|---:| +| FX-Map quadrant opacity, F32 pixels | 11,776/14,336 · 0.5 | 14,336/14,336 | 14,336/14,336 | +| Pixel Processor, F32 pixels | 11,776/14,336 · 1.094946325 | 14,336/14,336 | 14,336/14,336 | +| Uniform Color parameter, RGBA F32 pixels | 9,216/14,336 · 0.5 | 14,336/14,336 | 14,336/14,336 | +| Value Processor, typed floats | 36/56 · 0.5 | 56/56 | 56/56 | + +Maximum error is zero in both corrected columns and between original and reopened desktop results. A shared write in the later arm takes effect after the earlier arm reads its variable. Sharing a draw across the arms preserves a selected arm’s preceding draw. The function evaluator now uses that order for shared writes and eligible random draws. Private arm expressions still evaluate lazily. + +Ten earlier conditional graphs match 94,720/94,720 pixels across 70 renders. White Noise v2 matches 10,240/10,240 intermediate pixels across ten ports and 69,120/69,120 root pixels across 72 captures. The grayscale Tile Generator matches 284,416/284,416 across its 55 distinct settings. All maximum errors are zero. Discarded loops and random graph arguments have separate outstanding measurements. [Loop controls](#sequence-evaluation-and-scalar-random-values) + +### Sequence evaluation and scalar random values + +Build an original function around two distinct Random(1) nodes. In Sequence, use the first draw directly, multiply it by zero in the returned expression, assign it to a variable, or use it in both the discarded input and the returned expression. Include a write with a second unused draw beside it, a conditional write and both signs of its control. Render the eleven variants at 16², with control +1 and −1 and graph seeds 0 and 17. Repeat after an ordinary MaterialCraft save and desktop reopen. + +| Function context | Original exact samples | Reopened exact samples | Maximum absolute error | +|---|---:|---:|---:| +| FX-Map quadrant opacity, F32 pixels | 11,264/11,264 | 11,264/11,264 | 0 | +| Pixel Processor, F32 pixels | 11,264/11,264 | 11,264/11,264 | 0 | +| Uniform Color parameter, RGBA F32 pixels | 11,264/11,264 | 11,264/11,264 | 0 | +| Value Processor, typed floats | 44/44 | 44/44 | 0 | + +A discarded draw leaves the next random value available. A write, a draw used elsewhere or a draw multiplied by zero in the returned expression can still advance the stream. Scalar Value Processor starts its stream at the zero-coordinate pixel hash. A second test uses the first draw, a zero-weighted draw and a shared draw, with twelve caller seeds from 0 through 372421, a relative seed offset of +3 and two sizes (16² and 128 × 32). All 72/72 typed results match on the original and the reopened graphs, maximum 0. Each original desktop result above also matches the reopened desktop result. + +Two further controls put a three-iteration loop on the discarded side of Sequence. Its body either discards Random(1) or assigns the draw. The reference returns the first draw after either loop. These cases still differ in MaterialCraft. Across both loops and four settings, FX-Map matches 0/2,048, maximum 0.386968136, Pixel Processor matches 0/2,048, maximum 0.961201191 and Value Processor matches 0/8, maximum 0.662862062. Seven further controls outside those two loops, including an empty loop, produce 7,168/7,168, maximum 0 in FX-Map, 7,168/7,168, maximum 0 in Pixel Processor and 24/28, maximum 0.45432511 in Value Processor. Those four scalar differences occurred when a false conditional arm shared a draw with another expression. The later conditional comparison measures that case after the correction. [Conditional results](#conditional-inputs-shared-across-function-branches) Random expressions passed as graph arguments are also under separate investigation. + +### Sampling properties on graph inputs and outputs + +Connect an original half-size U16 Random(1) field to Blur. Compare a flat graph with the same connection across an instance output. Set tiling on the field to none, horizontal, vertical or both, then repeat with an absolute override on Blur. Use intensity 12. For the pixel-ratio cases, set the source ratio to stretch (0) or square (1) and drive Blur intensity with the float conversion of the inherited pixel ratio multiplied by 12. + +For an instance input, wire two original fields to separately named grayscale bridges. Give the fields pixel sizes (2,.5) and (.5,2) and use intensity 4 inside the child. In separate controls use unit pixel sizes and opposite one-axis tiling modes, or pixel ratios 0 and 1. Read each pin in turn. Test absolute settings on the input bridge. Render at parent sizes 64² and 128² with seed 0, 128 × 64 with seed 17 and 64 × 128 with seed 12071. Compare the stored output of the matching flat graph, the child inside an instance and an ordinary save reopened in the reference desktop. + +| Nested U16 control | Previous exact pixels · maximum error | Corrected original exact pixels · maximum error | Corrected reopen exact pixels · maximum error | +|---|---:|---:|---:| +| Output tiling 0, 1, 2, 3 and explicit override | 43,568/46,080 · 16278 | 46,080/46,080 · 0 | 46,080/46,080 · 0 | +| Output pixel ratio 0, 1 and explicit override | 18,432/27,648 · 50328 | 27,648/27,648 · 0 | 27,648/27,648 · 0 | +| Input pixel size, each of two pins | 9,216/18,432 · 34253 | 18,432/18,432 · 0 | 18,432/18,432 · 0 | +| Input tiling, both pins and their absolute overrides | 35,632/36,864 · 16278 | 36,864/36,864 · 0 | 36,864/36,864 · 0 | +| Input pixel ratio, both pins and their absolute overrides | 27,648/36,864 · 50328 | 36,864/36,864 · 0 | 36,864/36,864 · 0 | + +Across the 36 flat and nested graphs, the original and the ordinary save each match 331,776/331,776 U16 pixels. The desktop original and reopen agree at every pixel. Both input pins now retain their own sampling settings. A downstream filter reads the settings from the selected child output. The same previous pixel-size matrix still matches 110,592/110,592 on each pass. + +Repeat the no-tiling output, stretch-ratio output, first tiling input and second ratio input with Blur explicitly storing U8, F16 and F32. Each storage format matches 73,728/73,728 pixels on the original and 73,728/73,728 on the ordinary save, maximum error 0. The desktop flat and nested comparisons and all original-versus-reopen comparisons give the same exact counts. Bricks 01 Base Color repeats its 4,096/4,096 at 64², 16,379/16,384 at 128² and 4,094/4,096 with changed luminance and seed at 64². Its last two maximum byte errors are 1. + +### 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. + +| Whole graph including its intermediate ports | Exact pixels across the three settings | Maximum stored error | +|---|---:|---:| +| BNW Spots 1 | 496,640/496,640 | 0 | +| Clouds 1 | 681,472/681,472 | 0 | +| Clouds 2 | 411,136/411,136 | 0 | + +To distinguish the two reference render paths on original geometry, build a full seven-level quadrant tree on a white 128² F32 buffer. Give its sixteen grandchild groups independent additive gains. Offset each group's leaves back to the first quarter on both axes and set their square pattern size to (.875,.875). Set the lower-index group's gain to −1, the higher-index group's gain to 2⁻²⁵ and the other fourteen gains to zero. Repeat for all 120 pairs with seed 136404. Where the squares overlap, addition of the small term before or after subtraction of one gives distinguishable F32 results. + +On one logical processor, MaterialCraft matches the live desktop in 1,966,080/1,966,080 pixels, maximum error 0. Compiling the same graph normally and using the standalone D3D11 renderer with one explicit worker gives 1,891,328/1,966,080 against that desktop, maximum 2⁻²⁵. Exactly 73 of the 120 pairs change the 32² overlap. The standalone order is ascending group index. The observed desktop order is 12, 13, 8, 9, 14, 0, 1, 15, 2, 11, 6, 7, 10, 3, 4, 5. The six-level 120-pair control matches 491,520/491,520 desktop pixels. Seven eight-level controls still give 454,656/458,752 against the desktop, maximum 2⁻²⁵. The eight-level case remains open. [Earlier pair construction and measurements](#compositing-complete-seven-level-additive-quadrant-trees) + +### Selected channels in pattern expressions + +In an original single-square pattern, connect four independent random scalars to a four-component vector. Make a second vector the same way. Choose between the vectors with a boolean, multiply them component by component, or interpolate between them with a scalar factor of .375. Swizzle the first or last component into opacity. To observe how many draws the expression consumes, multiply the swizzled result by zero and add a new random draw. Test both gate values and seeds 0 and 17 at 16² in F32. Across the direct, nested, arithmetic and next-draw controls, 112 renders match 28,672/28,672 pixels, maximum error 0. Supplying a four-component interpolation factor in a further 16 probes still gives 0/4,096 exact pixels, maximum F32 error .59443158. + +The pattern evaluator previously drew every channel before selecting one. It now evaluates the scalar operands of the requested channel, preserving the chosen branch and the order of shared random draws. The isolated grayscale Tile Generator luminance pair (1,0) on a 4 × 14 grid now matches 4,096/4,096 U16 pixels at each of seeds 0 and 17, maximum error 0. This holds for literal grid counts and for a column input, a row input plus ten and a jitter input, including after ordinary saves. + +For a connected-source check, generate a grayscale U8 ramp of .75u + .25v at quarter width and height. Connect it to the Source pin. In the first instance select the source image, set the gap to .06, scale to 1.12 and luminance variation and contrast to (.49,.95). In the second instance select the square and set the luminance pair to (1,0). Set the row offset to .25, pattern-specific pair to (0,0) and blend mode to 2 on both. Render each at 64² with seed 0, a 4 × 14 grid and zero row jitter, then at 64 × 32 with seed 17, a 5 × 7 grid and .375 jitter, and at 32 × 128 with seed 12071, a 3 × 5 grid and .125 jitter. Use neutral grayscale Levels inheriting input dimensions to select the actual terminal U8, U16, F16 and F32 storage. Reopen the ordinary MaterialCraft saves in the reference desktop. + +| Tile Generator comparison | Settings | Exact pixels | Maximum error | +|---|---:|---:|---:| +| Grayscale root, earlier whole-root matrix | 55 | 284,416/284,416 | 0 | +| Grayscale root, archived saves reopened in the desktop | 43 | 179,968/179,968 | 0 | +| Source and square matrix, original vs. desktop | 24 | 81,920/81,920 | 0 | +| Same matrix, saved vs. desktop | 24 | 81,920/81,920 | 0 | +| Desktop original vs. reopened save | 24 | 81,920/81,920 | 0 | +| Related Tile Generator in the separate catalog package | 221 | 757,504/757,504 | 0 | + +With both the graph-color display correction and the pattern fix, Bricks 01 gives the following Base Color results. For the raw rows a pixel matches when all three U8 channel values agree. The last row compares the actual displayed RGB pixels from the two 1:1 2D views. + +| Bricks 01 Base Color | Exact pixels | Maximum byte error | +|---|---:|---:| +| 64², defaults, seed 0 | 4,096/4,096 | 0 | +| 64², luminosity .65, seed 19 | 4,094/4,096 | 1 | +| 128², defaults, seed 0 | 13,283/16,384 | 43 | +| 256² 2D views, defaults, seed 0 | 55,976/65,536 | 53 | + +At 64² and defaults, eight of the nine raw material outputs match every pixel. Normal matches 4,084/4,096 with maximum U16 error 1. At 256², mean displayed RGB is (153.61,115.32,91.40) in MaterialCraft and (153.55,115.21,91.28) in the reference. The whole material still has measured differences at higher resolutions. [Earlier comparison with the display correction alone](#stored-graph-color-in-the-2d-view) + +### Stored graph color in the 2D view + +Display the Base Color output of Bricks 01 at 1:1 with the default sRGB interpretation. With seed 0 and a 64² parent, all 4,096 pixels captured from the reference viewport match its raw U8 RGB output, maximum error 0. The old MaterialCraft viewport applied a linear-light to sRGB conversion to those already encoded numbers. The same conversion brightened graph thumbnails and the color sampler. + +Use a uniform color with stored RGB (.2,.4,.8) and alpha 1. The reference viewport and node thumbnail show (51,102,204). The old MaterialCraft preview showed (124,170,231). The corrected MaterialCraft offscreen viewport shows (51,102,204). For the full byte scale, make 86 original opaque swatches whose three channels cover levels 0–255. Compare the rendered reference colors and the actual MaterialCraft display function. With the default encoded interpretation, 86/86 swatches and 258/258 channels match, maximum error 0. Reading the same numbers as linear light gives 14/86 exact swatches and 132/258 exact channels, maximum error 1. In seven further storage controls across U8, U16, F16 and F32, both interpretations stay within one displayed byte. The display choice leaves stored channel readouts and alpha intact. The headless 2D PNG uses the same session display setting. On a 16 × 16 uniform RGBA buffer, all 256 pixels are (51,102,204,255) with the encoded interpretation and all 256 are (124,170,231,255) with linear-light interpretation. Both PNG comparisons have maximum byte error 0. + +| Bricks 01 Base Color | Reference mean RGB | Old mean RGB | Corrected mean RGB | Old exact pixels / max error | Corrected exact pixels / max error | +|---|---|---|---|---:|---:| +| 64², seed 0, defaults | 152.2, 119.9, 97.6 | 203.6, 182.1, 165.3 | 154.8, 121.5, 98.4 | 0/4,096 · 154 | 628/4,096 · 119 | +| 128², seed 0, defaults | 153.3, 117.0, 93.6 | 204.7, 180.3, 162.0 | 156.7, 119.0, 94.3 | 0/16,384 · 155 | 3,112/16,384 · 125 | +| 64², seed 19, luminosity .65 | 218.8, 201.3, 190.8 | 237.7, 228.4, 222.7 | 217.8, 199.8, 189.2 | 97/4,096 · 121 | 900/4,096 · 118 | + +The comparison uses the same cooked MaterialCraft buffer for each old and corrected pair. A pixel counts when all three displayed bytes match. Maximum error is the largest absolute channel difference in byte levels. On the 64² default, the specular texture already matched at 4,096/4,096 raw pixels and now also matches at 4,096/4,096 displayed pixels, maximum error 0. The remaining base-color differences are present in the raw graph output. [First differing tile and noise stages](#tile-luminance-variation-in-bricks-01) + +### Tile luminance variation in Bricks 01 + +Cook the base-color output of the Bricks 01 PBR material at 64², default inputs and seed 0, with one reference worker. Read the raw ports of its 144 top-level nodes. The base-color branch has 123 nodes. The first differing outputs have matching upstream images, including the 16² U8 Source image connected to both tile instances (256/256, maximum error 0). + +| First differing output | Exact pixels | Maximum U16 error | +|---|---:|---:| +| Vertical Noise at 64 × 32 | 2,044/2,048 | 2 | +| Tile Generator using the Source image, scale 1.12 | 873/4,096 | 31,370 | +| Tile Generator using the square pattern | 0/4,096 | 62,555 | + +To isolate the square-pattern case, instance the grayscale Tile Generator from `tile_generator.sbs` in an original graph. Leave its image pins empty, request U16, set a 4 × 14 grid and set the luminance variation and contrast pair to (1,0). Leave the remaining inputs at their defaults. The grid alone matches 4,096/4,096 at seeds 0 and 17. The luminance pair changes that to 0/4,096 at each seed, maximum errors 62,555 and 58,225 respectively. Individually setting the row offset to .25, the pattern-specific pair to (0,0), or the blending mode to 2 on the control grid still matches 4,096/4,096 per seed. + +Next combine those settings with the luminance pair. Try both literal grid counts and graph inputs for the column count, a row count calculated as 4 + 10, and zero row jitter. The reference square-pattern output at seed 0 matches its corresponding Bricks 01 stage in all 4,096 pixels, maximum error 0. The same 0/4,096 cross-app counts and maximum errors recur on the original and an ordinary MaterialCraft save at both seeds. The reopened reference output matches its original in all 8,192/8,192 pixels for each wiring. This reopens the grayscale tile root's earlier 55-setting result. The Source-image branch needs a connected texture for a meaningful comparison. + +### Computed caller sizes on BNW Spots 1 and Clouds 1 and 2 + +Instance each catalog root through a child whose parent-relative graph size reads an exposed integer pair. Bind it to a parent pair. At 16² and outer seed 0 use (−1,+1), an absolute child seed expression returning 5 and the root's default parameters. At 64 × 32 and outer seed 372177 use (+1,−1), parent-relative child seed −3, and Disorder 0.96875. The caller adds seed offset 3. The two resulting images are 8 × 32 and 128 × 16. Measure one desktop worker and reopen each ordinary MaterialCraft save. + +First set the instance's requested format to U8, U16, F16 and F32. The terminal catalog output is U16 in all eight settings per root. Then insert a neutral grayscale Levels after the root, inherit its input dimensions, and select each of the four storage formats on that final operation. Read the actual pixel format from the desktop. The four output types now differ. Compare dimensions, stored pixel values and the original against the reopened desktop graph. + +| Root | Direct U16 original and save, each | U8 after Levels | U16 after Levels | F16 after Levels | F32 after Levels | +|---|---:|---:|---:|---:|---:| +| BNW Spots 1 | 9,216/9,216 | 2,304/2,304 | 2,304/2,304 | 2,304/2,304 | 2,304/2,304 | +| Clouds 1 | 9,216/9,216 | 2,304/2,304 | 2,304/2,304 | 2,304/2,304 | 2,304/2,304 | +| Clouds 2 | 9,216/9,216 | 2,304/2,304 | 2,304/2,304 | 2,304/2,304 | 2,304/2,304 | + +Every format column has the same exact count for MaterialCraft versus the original, MaterialCraft versus the save and the desktop original versus its reopen. Maximum error is zero throughout. The separate full-size 256² seed comparison differs at six, two and four pixels respectively against the one-worker reference. All three roots remain in progress. [Full-size seed and worker repeats](#computed-graph-seeds-on-load-evaluation-and-save) + +### Graph output size functions and signed offsets + +MaterialCraft now reads, evaluates and saves a graph's output size expression and its absolute, parent-relative or input-relative mode. The evaluator resolves the caller's arguments and axes before cooking the child and evaluating its seed. This applies to instances and to the root graph. The graph inspector reports the effective size. An explicit export size applies once and leaves the authored graph settings intact. + +Build an original child that outputs a grayscale Random(1) field. Call it at 16 × 16, 32 × 16 and 16 × 32 with outer seeds 0, 42 and 19. For the two relative modes, start with offsets (0,0), (−1,+1), (+1,−1) and (−6,0). Also drive the child from a parent integer pair, or choose between (−1,+1) and (+1,−1) by comparing one lane of `$size` or `$sizelog2` with a float threshold. Use (3,4) and (4,3) for the corresponding absolute settings. For the wired controls, feed the instance a procedural image with offsets (+1,−1), and read the child through a blur with zero parent-relative offset. Use one desktop worker. Compare the native dimensions, storage type and pixel values, save through the ordinary SBS writer, reopen in the desktop and repeat. + +| Shared graph behavior | Settings | Original exact / total | Reopened exact / total | +|---|---:|---:|---:| +| Seed predicates on both axes with a relative size | 108 | 46,080/46,080 | 46,080/46,080 | +| Stored offsets and both relative modes | 72 | 23,424/23,424 | 23,424/23,424 | +| Instance with a differently sized image input | 36 | 11,776/11,776 | 11,776/11,776 | +| Offsets across the one-texel boundary | 12 | 448/448 | 448/448 | +| U8, U16, F16 and F32 storage | 12 | 5,120/5,120 | 5,120/5,120 | +| Constant, driven and conditional size expressions | 81 | 26,496/26,496 | 26,496/26,496 | +| Absolute and inherited function input dimensions | 56 | 10,752/10,752 | 10,752/10,752 | +| Seed function below one texel and literal controls | 90 | 1,920/1,920 | 1,920/1,920 | +| Size function below one texel | 48 | 1,200/1,200 | 1,200/1,200 | + +All 515 settings across 54 groups match 127,216/127,216 pixels on each side, with maximum absolute error 0. The two desktop readbacks also match each other at every pixel. An absolute size function reads zero for both size variables. In a relative function, a 16-wide parent followed by a horizontal offset of −6 carries exponent −2 below the one-texel allocation. An additional offset of +3 gives a width of 2. A seed function at the intermediate graph sees an allocated width of 1 and log width of 0. + +For the catalog check, open Hemisphere and Shape Base and set the preview's parent size through the desktop graph API. Leave the graph's output size expression active. Repeat the earlier 18 Hemisphere and 61 Shape Base settings, then the seven square, wide and tall settings below, including the four storage formats and both values of `non_square`. Compare each original with MaterialCraft, reopen the ordinary save in both applications, and compare the two desktop outputs directly. + +| Root | Settings | MaterialCraft vs. original | MaterialCraft vs. reopen | Desktop original vs. reopen | Max error | +|---|---:|---:|---:|---:|---:| +| Hemisphere | 18 earlier + 7 | 173,568/173,568 | 173,568/173,568 | 173,568/173,568 | 0 | +| Shape Base | 61 earlier + 7 | 344,064/344,064 | 344,064/344,064 | 344,064/344,064 | 0 | + +The earlier Shape Base comparison forced the graph's output dimensions when the desktop reported an unspecified preview parent. That overwrote the size expression in memory. For those same 61 settings the earlier procedure read 460,544 pixels. A fresh desktop session with the preview parent set explicitly read 341,760. The seven additional settings read 2,304 pixels, including four enabled rectangular parents that each produce 16 × 16. The earlier forced-size measurements remain reproducible under that procedure. Hemisphere returns to measured parity. The first three FX-Map roots retain their separate 256² differences. [Earlier shape and rectangle settings](#rectangular-hemisphere-and-shape-base-output-sizes) [Seed and worker-count measurements](#computed-graph-seeds-on-load-evaluation-and-save) + +The stored-offset and computed-size regressions failed on the previous implementation. Across the five affected crates, 907 release tests passed and eight were ignored. The engine command panic regression, formatting, strict workspace Clippy, dependency layers and WebAssembly checks passed. The native release desktop also opened the ordinary Hemisphere save and cooked the 32 × 16 parent to a 16 × 16 output. + +### Rectangular Hemisphere and Shape Base output sizes + +Open Hemisphere and Shape Base from the catalog in the reference desktop. For each graph render the default 16² at seed 0 in F32. Set `non_square` to true for 32 × 16 at seed 42 in U8 and F32, then for 16 × 32 at seed 690727 in F16 and U16. Set it to false for 32 × 16 at seed 19 and 16 × 32 at seed 0 in F32. Read the dimensions and native output bits. Repeat by opening an ordinary MaterialCraft SBS save in the desktop. + +| Graph | MaterialCraft vs. catalog original | Desktop original vs. desktop reopen | +|---|---|---| +| Hemisphere | 1,280/1,280 pixels exact in three settings, max 0. Four enabled rectangular settings have different dimensions. | 1,280/1,280 exact in three settings, max 0. In all four enabled settings the original gives 16 × 16 and the save gives the requested rectangle. | +| Shape Base | 3,328/3,328 pixels exact in seven settings, max 0 | 3,328/3,328 exact in seven settings, max 0 | + +MaterialCraft and the desktop agree on all 3,328 pixels of the saved Hemisphere, including the changed rectangles. Comparing each application's output from the same save therefore misses the loss of the catalog behavior. The SBS reader skips the authored graph output-size function and the writer omits it. Hemisphere is in progress. Its earlier 18 settings retain their exact counts. Shape Base retains its measured parity. [Earlier hemisphere results](#normal-maps-panoramas-and-primitive-shapes) [Earlier Shape Base results](#reopened-paper-fiber-gaussian-and-shape-generators) + +### Computed graph seeds on load, evaluation and save + +The SBS reader used to drop a graph's seed expression. The evaluator consequently used the stored integer offset, and an ordinary save lost the expression. MaterialCraft now preserves the function, evaluates it against the child's arguments and resolved dimensions, then applies the authored seed inheritance. Editing inheritance retains the function. Entering a literal seed replaces the function, and undo restores it. + +Create a child with a grayscale F32 Pixel Processor returning Random(1). Connect its output through an instance with a parent-relative seed offset of 3. Give the child an absolute, parent-relative or input-relative seed. In each mode supply 5, −3, −6 + 11, an exposed integer defaulting to 5, that input overridden to −3, and that input bound to a parent integer of −3. Include separate children with literal 5 and −3. Render at 16² with seeds 0 and 19 and at 32 × 16 with seed 42. Compare the F32 bits, then repeat with ordinary SBS saves. + +| One-worker D3D11 comparison | Exact pixels / total | Maximum absolute error | +|---|---:|---:| +| Previous evaluator, 54 renders with seed expressions | 0/18,432 | 0.992987871 | +| Corrected evaluator, original and reopened expressions, each | 18,432/18,432 | 0 | +| Reference expressions vs. their equivalent literal seeds | 18,432/18,432 | 0 | +| Literal controls, original and reopened, each | 6,144/6,144 | 0 | +| Desktop, five expression graphs at all three settings, original and reopened, each | 5,120/5,120 | 0 | + +Replace the child field with an instance of the complete BNW Spots 1, Clouds 1 or Clouds 2 graph. Keep the catalog graph intact. At 16² use defaults, outer seed 0 and an absolute child expression returning 5. At 64 × 32 use outer seed 372177, Disorder .96875 where exposed, and a parent-relative seed function reading the instance's −3 override. Request U8, U16, F16 and F32 on the enclosing instance. These requests retain the child output's own storage. Compare F32 readbacks and repeat with a literal child seed and an ordinary save. Independently open the U8 default and changed F32 settings in the desktop using distinct embedded graph identifiers for each fixture. + +| Computed-seed root | Previous evaluator · exact / total · max | Corrected vs. one-worker original and ordinary reopen, each | Corrected vs. desktop original and ordinary reopen, each | +|---|---:|---:|---:| +| BNW Spots 1 | 4/9,216 · 0.571389347 | 9,216/9,216 · 0 | 2,304/2,304 · 0 | +| Clouds 1 | 0/9,216 · 0.556694895 | 9,216/9,216 · 0 | 2,304/2,304 · 0 | +| Clouds 2 | 0/9,216 · 0.567727149 | 9,216/9,216 · 0 | 2,304/2,304 · 0 | + +At 256² and seed 372421, repeat the changed F32 setting on the original and the saved wrapper with one and eight workers. All three one-worker reference originals and saves reproduce their own 65,536 pixels. The table reports comparisons against the original wrappers. Numeric errors are absolute differences in the normalized F32 readback. + +| Root | Corrected vs. one worker · exact / 65,536 · max | Corrected vs. eight workers, two runs · exact · max | Eight-worker reference repeat · exact · max | +|---|---:|---:|---:| +| BNW Spots 1 | 65,530 · 0.000030517578125 | 65,536 · 0 on both | 65,536 · 0 | +| Clouds 1 | 65,534 · 0.00006103515625 | 65,534 and 65,535 · 0.00006103515625 | 65,533 · 0.00006103515625 | +| Clouds 2 | 65,532 · 0.000030517578125 | 65,533 · 0.000030517578125 on both | 65,532 · 0.000030517578125 | + +To isolate the evaluation dimensions, return seed 5 when one lane of `$size` or `$sizelog2` exceeds an exposed float threshold, otherwise return 0. Test both axes at 16², 32 × 16 and 16 × 32 with outer seeds 0, 42 and 19. Use thresholds 0, .5, 1, 7.5, 8, 15.5, 16, 31.5 and 32 for size and −1, 0, 1, 2.5, 3, 3.5, 4, 4.5 and 5 for log size. The desktop comparisons match 46,080/46,080 pixels when the child inherits its extent and 13,824/13,824 with a fixed 8 × 16 child. Both totals repeat on ordinary saves with zero error. The desktop reads the resolved dimensions. The standalone renderer reads (1,1) and log dimensions (0,0) in the isolated graph-seed controls. + +A child with a relative size offset of (−1,+1) exposed a separate file-format gap. All 108 original output extents disagreed with MaterialCraft, and reopening the saved file in the desktop changed all 108 extents. No pixel score was assigned to those pairs. In this comparison the two size lanes and one log-size lane converted to an integer seed matched 0/3,072 desktop pixels, maximum 0.998188853, both before and after saving. For an exposed parent float of 5, the desktop's graph and atomic seed fields both match a literal seed of 1084227584. An ordinary Value Processor returns the typed integer 5 for the same expression. The later scalar seed correction matches all 3,072 original and reopened pixels. [Runtime scalar arithmetic](#runtime-scalar-arithmetic-in-graph-and-node-seeds) [Graph size measurements](#graph-output-size-functions-and-signed-offsets) [Earlier literal seed and storage-format measurements](#graph-random-seed-inheritance-on-save-and-in-nested-graphs) + +The format and evaluator regressions failed on the previous code. The dimension regression also failed with a one-texel function context. The edit and undo test passes. Across the four touched crates, 499 release tests passed and 8 were ignored. The engine command panic regression, formatting, strict workspace Clippy, dependency layers and WebAssembly checks passed. + +### Float vector arguments in nested functions + +Fixed two-, three- and four-component float arguments now retain literal precision when an instance supplies the child graph's default, a stored vector, or a constant expression. A vector read from an exposed parent parameter retains runtime precision. This uses the graph evaluator's existing distinction between fixed and driven arguments. [Scalar argument measurements](#scalar-float-precision-in-nested-graph-instances) + +Expose a float vector of width 2, 3 or 4 in a child graph. Take the first components of (1, .503799975, .48120001, −.38157) as the default and of (.375, .723561, −.38157, .1875) as the changed value. In a color Pixel Processor, swizzle the last available lane and multiply by the F32 constant 6.2831855 to obtain an angle. Return its sine, its cosine, the angle and Random(1) as RGBA32F. Use the default, a stored override, an expression adding the changed vector to a zero vector, and a binding to the parent's exposed vector. Build three top-level controls using the two literal vectors and an exposed changed vector. Render each graph at 16 × 16 with seed 0 and 32 × 16 with seed 585193. Compare all four channels, including the seeded field. + +| Comparison | Exact whole pixels / total | Maximum absolute component error | +|---|---:|---:| +| Previous evaluator vs. one-worker D3D11, all 21 graphs | 10,752/16,128 | 1.78813934e−7 | +| Corrected evaluator vs. one-worker D3D11, original and ordinary SBS reopen, each | 16,128/16,128 | 0 | +| Reference original vs. ordinary SBS reopen | 16,128/16,128 | 0 | +| Reference nested graphs vs. their corresponding top-level controls | 9,216/9,216 | 0 | +| Desktop vs. standalone reference, original and reopened 2-lane default, 3-lane expression and 4-lane parent binding combined | 4,608/4,608 | 0 | + +To exercise node and FX-Map parameter functions, feed the absolute sine from the same last lane to a grayscale Uniform's color or to the opacity of a single additive square covering the canvas. Use the nested default, parent binding and both corresponding top-level controls at all three vector widths and both sizes. For each operation, the previous evaluator matched 6,912/9,216 · 8.34465027e−7 and the corrected evaluator matches 9,216/9,216 · 0. The nested and top-level reference controls match 9,216/9,216 · 0 across both operations. + +In Panorama Spot, separate the direction calculated per pixel from the fixed light position (.503799975, .48120001). The earlier per-pixel direction matched while the fixed light X and Y differed at every one of 768 pixels. Their maximum errors were 1.62050128e−7 and 2.60770321e−7. Z matched all 768. The corrected light direction and axis-length readout matches 768/768 · 0. Across the three panorama graphs, 15 intermediate or control graphs matched 11,520/11,520 · 0. The six complete-graph settings use the same two sizes, seeds, instance formats and procedural inputs as the earlier comparison. [Nested-filter settings](#output-precision-in-nested-generators-and-blurs) Each cell gives exact whole pixels / total and maximum absolute component error. The corrected original and reopened counts were independently measured against the reference desktop and the standalone renderer. + +| Graph | Previous evaluator, original | Corrected evaluator, original | Corrected evaluator, ordinary SBS reopen | +|---|---:|---:|---:| +| Panorama Shape | 2,268/2,304 · 2.86102295e-06 | 2,304/2,304 · 0 | 2,304/2,304 · 0 | +| Panorama Shape 2 | 2,286/2,304 · 5.03659248e-06 | 2,304/2,304 · 0 | 2,304/2,304 · 0 | +| Panorama Spot | 2,302/2,304 · 0.0012512207 | 2,304/2,304 · 0 | 2,304/2,304 · 0 | + +The earlier 18 settings for each shape matched 171,264/171,264 pixels per graph, and the 36 Spot settings matched 189,696/189,696. The 90 scalar-angle controls matched 215,040/215,040. Normal Sobel, Panorama 3D Position and Panorama Sphere Light each matched 2,304/2,304 original and 2,304/2,304 reopened pixels in the six nested settings. Maximum error in every recheck was zero. + +### Ordinary SBS saves with verified library dependencies + +Opening a library file by its disk path and saving an ordinary SBS outside the library now preserves portable links through nested packages. Before emitting a library alias, the save verifies each reachable package against the bundled bytes and compares its loaded graphs using the same resolved call interfaces. A dependency with a changed file, edited graph, or local resources keeps its disk link. + +Open `panorama_position.sbs` from its library folder and use `file.saveCopyAs` into an empty folder. The saved package now refers to `sbs://panorama_shape.sbs`. Previously the saved file pointed to the disk copy of that dependency and the reference compiler rejected its format version before producing an image. Repeat with private copies of the position, shape and functions packages and append a newline to the functions file. The saved position graph keeps the path to that copy of the shape package. File hashes before and after each save confirm that all three source files retain their contents. The engine regression also edits a loaded grandchild graph in memory and verifies its parent keeps the disk link on reopen. + +Instance the saved Panorama 3D Position graph in a new caller. At the default up vector, select U8 and F32 instance formats. Also use F16 with `up_vector` set to 1. Render each at 16 × 16 with seed 0 and 32 × 16 with seed 585193. The child declares U16. Compare all four channels of each output. Each comparison below covers six renders. + +| Compared outputs | Exact whole pixels / total | Maximum absolute component error | +|---|---:|---:| +| MaterialCraft and the reference desktop opening the ordinary save | 2,304/2,304 | 0 | +| MaterialCraft and the one-worker D3D11 renderer opening the ordinary save | 2,304/2,304 | 0 | +| Reference renderer opening the library original and the ordinary save | 2,304/2,304 | 0 | +| Reference desktop and standalone renderer opening the ordinary save | 2,304/2,304 | 0 | + +Independently repeat the earlier nested-filter measurements in the reference desktop. Use the F32 instance default for the two shapes, F16 with `scale` .375 for Spot, and the sizes, seeds and original procedural inputs from the [nested-filter comparison](#output-precision-in-nested-generators-and-blurs). The desktop and one-worker standalone reference agree on all 3,072/3,072 pixels with zero error. The complete MaterialCraft comparisons are below. + +| Graph | Desktop pixel format | Exact whole pixels / total | Maximum absolute component error | +|---|---|---:|---:| +| Normal Sobel | RGBA16 | 768/768 | 0 | +| Panorama Shape | RGBA32F | 756/768 | 2.86102295e-06 | +| Panorama Shape 2 | RGBA32F | 761/768 | 5.03659248e-06 | +| Panorama Spot | RGBA32F | 766/768 | 0.0012512207 | + +### Output precision in nested generators and blurs + +A child graph with an absolute working format now cooks its generators in that format. A child with inherited precision takes the resolved instance format. Newly grouped nodes keep following the parent format at their new instance. Blur and Directional Blur connected directly to a nested image input now sample the original caller texture, including its storage precision and dimensions. Reading out the bridge itself still exposes the bridge's own stored result. + +For the format probe, connect a grayscale Pixel Processor returning Random(1) to the output of a child graph. In a parent, connect an instance of the child directly to the output. Set the instance to each of U8, U16, F16 and F32. On the child, use an omitted format, each of the four absolute formats, parent-relative U8 or F16, and input-relative U16 or F32. Add four F32-instance cases with a parent-relative format on the processor and each absolute child format. Render all 40 graphs at 16² with seeds 0 and 19 and at 32 × 16 with seed 42. Compare every component as F32 using the one-worker Direct3D 11 reference. A separate caller with the expected working format gives the same reference field. + +| Nested generator | Exact pixels / total · maximum absolute error | +|---|---:| +| Previous evaluator vs. reference | 25,609/40,960 · 0.00217908621 | +| Corrected evaluator vs. reference | 40,960/40,960 · 0 | +| Corrected evaluator vs. reference after an ordinary SBS save | 40,960/40,960 · 0 | +| Original reference vs. expected format, and original vs. saved reference, each | 40,960/40,960 · 0 | + +For the blur probe, feed a seeded grayscale Random(1) field into a child containing one blur filter. Use a matching flat filter as a control, then repeat the flat case with its source stored at the bridge precision. At 16² and 32 × 16 use seeds 0 and 585193. Exercise F32 → U16 at intensities 4 and 16, F32 → U8 at 24, and F16 → U16, U16 → F32 and F32 → F16 at 16. For Directional Blur include directions 0 and .25 turns for F32 → U16 at 16. The nested and flat reference agree on 9,984/9,984 pixels. Explicitly storing the source at the bridge precision gives 5,793/9,984 · 0.0039215982. The previous nested evaluator gives 8,614/9,984 · 0.0039215982. The corrected evaluator matches 28,416/28,416 pixels over the unique nested, flat and stored-source controls, maximum zero. + +Independently vary the generator and bridge sizes for each blur at intensity 16. Use parent-relative generator exponents (0,0), (−1,−1), (1,0) and (−1,0). Set the bridge respectively to parent-relative (−1,−1), parent-relative (0,0), absolute exponents (2,2), and input-relative (1,−1). Keep the filter parent-sized. All 6,144/6,144 reference pixels match the flat filters. The previous nested evaluator matched 1,276/6,144 · 0.469520092. The corrected flat and nested results match 12,288/12,288 · 0. + +For eight complete roots, use U8 and F32 instance settings at the root defaults and F16 with the change in the table. Run each square at 16², seed 0, and rectangular at 32 × 16, seed 585193. Connect the first exposed image input to an original F32 processor returning Random(1) for grayscale or (u,v,Random(1),1) for color. Two independent source readouts match 1,536/1,536 · 0. Curvature, Curvature Smooth, Normal Sobel and Panorama 3D Position declare U16 internally. The four other graphs declare F32. Read the actual output as F32. Each numeric cell gives exact whole pixels / total and the largest absolute component error. + +| Root | Changed parameter | Previous evaluator vs. reference | Corrected evaluator vs. reference | Corrected evaluator vs. reference on ordinary SBS reopen | +|---|---|---:|---:|---:| +| curvature | intensity .375 | 1,412/2,304 · 0.00585949421 | 2,304/2,304 · 0 | 2,304/2,304 · 0 | +| curvature_smooth | normal_format 1 | 20/2,304 · 0.736054242 | 2,304/2,304 · 0 | 2,304/2,304 · 0 | +| normal_sobel | intensity .375 | 0/2,304 · 0.00218203664 | 2,304/2,304 · 0 | 2,304/2,304 · 0 | +| panorama_3d_position | up_vector 1 | 2,304/2,304 · 0 | 2,304/2,304 · 0 | Compiler rejected dependency before rendering | +| panorama_shape | shape_intensity .375 | 2,268/2,304 · 2.86102295e-06 | 2,268/2,304 · 2.86102295e-06 | 2,268/2,304 · 2.86102295e-06 | +| panorama_shape_2 | shape 1 | 2,286/2,304 · 5.03659248e-06 | 2,286/2,304 · 5.03659248e-06 | 2,286/2,304 · 5.03659248e-06 | +| panorama_sphere_light | up_vector 1 | 2,304/2,304 · 0 | 2,304/2,304 · 0 | 2,304/2,304 · 0 | +| panorama_spot | scale .375 | 2,302/2,304 · 0.0012512207 | 2,302/2,304 · 0.0012512207 | 2,302/2,304 · 0.0012512207 | + +In Normal Sobel, correcting child precision alone gave 2,283/2,304 · 1.52885914e-05. Reading the input bridge, horizontal blur, vertical blur and final normal separately gave 768/768, 648/768, 734/768 and 759/768 respectively. The corrected blur input matches all four readouts, 3,072/3,072 · 0. For each of the seven roots that reopened, the reference original and saved images agree on 2,304/2,304 pixels. + +Panorama 3D Position's ordinary loose-file save pointed to a second library package on disk with a three-part format version. The standalone compiler stopped before producing any of the six images. Substituting the verified library alias alone produced 2,304/2,304 · 0. Saving an ordinary SBS from a reopened portable copy also gave 2,304/2,304 · 0. In both controls the reference reopened output matched the original on all 2,304 pixels. [Detached package version controls](#reopening-a-portable-copy-with-detached-function-packages) + +Panorama Shape, Shape 2 and Spot have repeatable differences in these smaller settings. For each, repeat the F32 default or the changed Spot case with the first input disconnected, transparent, black, white, constant (.1875,.4375,.625,.375), a coordinate ramp, and the original source stored in U8 and F16. Each Shape run matched 756/768 · 2.86102295e-06, each Shape 2 run matched 761/768 · 5.03659248e-06, and each Spot run matched 766/768 · 0.0012512207. Both one-worker D3D11 renders of the original field were bit-identical for each of these three roots. + +### Graph random seed inheritance on save and in nested graphs + +Saving a graph that omitted its random seed used to write an absolute zero. When another graph called that file, the reference renderer restarted its random stream at zero. MaterialCraft also ignored a child's authored seed mode when cooking an instance. The SBS reader, writer and evaluator now preserve how the child obtains its seed. An absolute seed starts a new stream. Either relative mode adds the child's signed offset to the resolved instance seed, wrapping at 32 bits. The graph properties panel and the `graph.seed` command expose inheritance. Grouping nodes keeps the original standalone seed and offsets it at the new instance so later parent seed edits still reach the grouped nodes. + +Build a child containing a single grayscale F32 Pixel Processor that returns Random(1). Connect an instance of that child to the parent output. Use child seeds omitted, absolute 0 or 5, parent-relative 0 or 5, and input-relative 5. For each, use an omitted instance seed, absolute 7 and parent-relative 3. Repeat four configurations with the child in a separate SBS file. Render each at 16² with parent seeds 0 and 19 and at 32 × 16 with seed 42. Compare every F32 bit with the one-worker Direct3D 11 reference. As an independent control, render the same random field at the calculated seed with no intervening seed offset. + +| Random-field comparison | Exact pixels / total · maximum absolute error | +|---|---:| +| Original reference field vs. the calculated seed | 22,528/22,528 · 0 | +| Previous MaterialCraft vs. reference | 7,424/22,528 · 0.982471466 | +| Current MaterialCraft vs. reference, 66 original renders | 22,528/22,528 · 0 | +| Current MaterialCraft vs. reference, 66 renders after ordinary SBS saves | 22,528/22,528 · 0 | +| Signed controls, 12 additional renders | 4,096/4,096 · 0 | + +The signed controls use child offsets −3 in each inheritance mode and a +19 child under an instance offset of −19. A separate child with the constant integer 5 supplied by a function still differs in absolute and parent-relative modes. Together these cases give 0/2,048 · 0.992930532. In the 546 inventory graph bodies, 539 omit the graph seed, including all 66 open roots. The other seven have literal parent-relative seeds, six at +2 and one at zero. + +For BNW Spots 1, put the complete saved graph into a fresh one-instance caller. At 128 × 64 use seed 372177 and Disorder 1 with U16 output. At 256² use seed 372421 and Disorder .96875 with U16, F16 and F32 output. Compare the reference caller loading the catalog with the reference caller loading the saved file. In that order the former absolute-zero save matched 1/8,192 · 39918, 3/65,536 · 48234, 40/65,536 · 0.736083984, 3/65,536 · 0.736003667. Removing just that parameter, or changing only its mode to parent-relative, restored 204,800/204,800 pixels in each experiment. Integer errors are stored levels and floating-point errors are absolute component differences. + +For BNW Spots 1 and Clouds 1 and 2, use a 16² default instance at seed 0, then a 64 × 32 instance at seed 372177. Set Disorder to .96875 where exposed. Switching the instance between the four formats alone leaves the stored child output unchanged in this setup. Before the fix, the original and saved child outputs in the reference matched 1,024/9,216 · 0.551033825, 1,024/9,216 · 0.572350621, 1,024/9,216 · 0.749904647 respectively over those eight reads per root. After the fix each pair agrees for 9,216/9,216 pixels with maximum error 0. + +To measure the four actual output formats independently, put an identity Levels filter after each instance and explicitly set its output precision. Read back F32 and compare the underlying U8, U16, F16 or F32 samples. For the remaining rows use a 16² default at seed 0 in F32 and a 32 × 16 instance at seed 569071 in U16 and F32. Set Disorder to .34375 where exposed. Use X Amount 3 and Y Amount 12 for Anisotropic Noise, and Branches 7 and Randomness .375 for Starburst. Each comparison reopens the complete child package through the ordinary SBS writer. + +| Root | MaterialCraft vs. original reference · exact / total · max | MaterialCraft vs. saved reference · exact / total · max | Reference original vs. save · exact / total · max | +|---|---:|---:|---:| +| bnw spots 1 | 9,216/9,216 · 0 | 9,216/9,216 · 0 | 9,216/9,216 · 0 | +| clouds 1 | 9,216/9,216 · 0 | 9,216/9,216 · 0 | 9,216/9,216 · 0 | +| clouds 2 | 9,216/9,216 · 0 | 9,216/9,216 · 0 | 9,216/9,216 · 0 | +| dirt 1 | 1,280/1,280 · 0 | 1,280/1,280 · 0 | 1,280/1,280 · 0 | +| dirt 3 | 1,280/1,280 · 0 | 1,280/1,280 · 0 | 1,280/1,280 · 0 | +| dirt 5 | 1,280/1,280 · 0 | 1,280/1,280 · 0 | 1,280/1,280 · 0 | +| dirt 6 | 1,280/1,280 · 0 | 1,280/1,280 · 0 | 1,280/1,280 · 0 | +| dirt gradient | 1,279/1,280 · 1.52885914e-05 | 1,279/1,280 · 1.52885914e-05 | 1,280/1,280 · 0 | +| fur 2 | 1,280/1,280 · 0 | 1,280/1,280 · 0 | 1,280/1,280 · 0 | +| gaussian spots 2 | 1,280/1,280 · 0 | 1,280/1,280 · 0 | 1,280/1,280 · 0 | +| moisture noise | 1,280/1,280 · 0 | 1,280/1,280 · 0 | 1,280/1,280 · 0 | +| anisotropic noise | 1,280/1,280 · 0 | 1,280/1,280 · 0 | 1,280/1,280 · 0 | +| starburst | 1,280/1,280 · 0 | 1,280/1,280 · 0 | 1,280/1,280 · 0 | + +In Dirt Gradient the 16² default F32 image first differs at (12,11), before the Levels readout. MaterialCraft gives .368169695 and the one-worker reference gives .368154407. Three repeats each at one and four workers give the same 255/256 match. All three two-worker renders and one of three eight-worker renders match all 256 pixels. The other two eight-worker renders match 255/256. Loading the original or saved child at one worker reproduces the same pixel. For the four larger BNW Spots 1 settings above, render the same compiled file four times at each of one, two, four and eight explicit workers. All four one-worker runs agree at every pixel in each setting. Eight workers produced two different buffers per setting. Comparing each of the three later eight-worker renders with the first gives 24,552/24,576 · 2, 196,596/196,608 · 2, 196,605/196,608 · 0.000244140625, 196,602/196,608 · 2.16364861e-05. Two and four workers also produced two buffers at 128 × 64. These repeat measurements and the earlier desktop comparisons leave the affected roots in progress. [Earlier comparisons by worker count](#patterns-with-an-explicit-reference-worker-count) + +### Reopening a portable copy with detached function packages + +Start with an SBS graph calling a private function package by a relative filename. For the waveform series, use the earlier detached hash file with format version `0.1.3` and the same seven sizes, seeds, changed parameters and additional fixed fields. Use **Save Copy As** to write an `.mcraft` file. Open that copy in MaterialCraft and use **Save Copy As** to write `graph.sbs` in a fresh directory. The resulting waveform SBS references two adjacent function packages under `resources/packages/`. Both use version `1.1.0.202401`. The source caller and detached file retained their original bytes. [Earlier waveform cases](#reopened-starburst-symmetry-tile-and-waveform-graphs) + +Open the exported SBS, apply each original setting and store the requested U8, U16, F16 or F32 precision on the node feeding the output. Save the case, compile it in the reference renderer and read its one-worker D3D11 F32 output. Compare all channels to MaterialCraft. Also compare each application with the original raw buffer at the original storage precision. + +| Waveform settings | Renders | Cross-app exact pixels | Each application vs. original | Maximum error | +|---|---:|---:|---:|---:| +| First saved series | 20 | 109,056/109,056 | 109,056/109,056 | 0 | +| Second saved series | 10 | 44,288/44,288 | 44,288/44,288 | 0 | +| Additional fixed fields | 13 | 26,624/26,624 | 26,624/26,624 | 0 | + +An independent 16² F32 caller at seed 596087 returns (.5625, 0, .53125, .75). Keep its relative function link and change only the detached package's format version. The standalone compiler rejected `0.1.3`, `1.0.0` and `1.1.0` before it produced a render. The same fixture compiled with `0.1.3.0`, `0.1.3.202401`, `1.0.0.201701`, `1.1.0.0` and `1.1.0.202401`. All 1,280/1,280 pixels matched, maximum zero. Exporting the three-part fixture through the portable-copy route gave another 256/256 exact pixels. The ordinary loose-file route still preserves the external file's identity. Its earlier desktop result with the untouched three-part dependency remains 167,194/179,968, with maxima of 65,535 U16 levels and 1 in F32. [Loose-file handoff](#version-of-a-detached-function-package-and-waveform-reopening) + +### Font line height and coverage over a constant background + +Give a generated TrueType A a 512 × 512 rectangular outline, an advance of 640 and 1,024 units per em. Render two lines of A at size .25, centered at offset (0,−.125) on a 64² F32 output. Start at horizontal ascent 768, descent −256 and gap 0. Independently change the horizontal header, the typographic and Windows metrics in the OS/2 table, and the typographic-metrics selection bit. Include two version-4 OS/2 tables with the bit enabled. Across the twelve fonts, the vertical scale is `pixel_height / (ascender - descender)`. The baseline interval is `scale * (ascender - descender + line_gap)`. For example, horizontal metrics (896,−256,128) use a scale denominator of 1,152 and a baseline interval of 1,280 design units. The twelve MaterialCraft renders match **49,152/49,152 pixels**, maximum error 0. Three of these graphs saved and reopened in both applications match **12,288/12,288**, maximum error 0. [OpenType horizontal header fields](https://learn.microsoft.com/en-us/typography/opentype/spec/hhea) + +Render the rectangular A at 32 × 16, size .5, offset (1/128,0). Use grayscale and RGBA outputs. Set the background to red with alpha .25, green with .5, blue with 0 or (.1875,.4375,.625,.375). The measured grayscale background is the arithmetic mean of RGB. Coverage interpolates each output channel from its background value to white, including alpha. All counts below require every channel of a pixel to match the one-worker F32 readback. + +| Original graph | Previous exact / total · max | Current exact / total · max | +|---|---:|---:| +| Text, four backgrounds and two output types | 2,128/4,096 · 0.749019593 | 4,096/4,096 · 0 | +| SVG, opaque red and half-opacity white rectangles on the same backgrounds | 1,664/4,096 · 0.498039186 | 3,072/4,096 · 0.498039186 | +| Six settings with the licensed monospace face, seven dimensions each | 73,641/83,328 · 1 | 81,267/83,328 · 0.631372556 | + +For the monospace controls, use 0, 0123, 01 and 23 on successive lines, A, a period, and the Points Preview label sheet. Use the same linked font bytes in each application, with the sizes, transforms and alignments stored in the graph. Render 8², 16², 16 × 8, 8 × 16, 32², 64² and 128 × 64. Across six ordinary package saves (three line-metric graphs, the label sheet at four sizes, tinted RGBA Text and grayscale SVG), the reference output before and after saving agrees for **21,952/21,952 · 0**. MaterialCraft against the reopened reference gives **21,101/21,952 · 0.631372556**. The remaining SVG differences include the authored half-opacity rectangle. Independent diagonal SVG edges at 32 × 16 give **3,664/4,096 · 0.623529404**. The original square and triangular font controls across transforms give **261,700/262,144 · 0.584313743** in 96 renders and **48,994/49,152 · 0.584313743** in 18 renders of prior saves. [Outline shapes and transform settings](#package-font-outlines-and-point-preview) + +Repeat the whole Points Preview comparison using the same two-row procedural field, counts, offsets, settings and seeds. Each saved-library comparison resolves the same licensed font on both sides. The reference catalog chooses a different font file. [Root settings and inputs](#stored-and-wired-values-at-graph-instance-inputs) + +| View | Previous, full save · max | Current, full save · max | Current, original catalog · max | +|---|---:|---:|---:| +| Points only | 5,376/5,376 · 0 | 5,376/5,376 · 0 | 5,376/5,376 · 0 | +| Labels only | 5,087/5,376 · 0.494117673 | 5,338/5,376 · 0.164705887 | 5,103/5,376 · 0.380392157 | +| Both, including empty input | 7,063/7,168 · 0.419607846 | 7,155/7,168 · 0.113725491 | 7,066/7,168 · 0.356862746 | + +Point-only controls remain exact. Visible labels keep this root in progress. + +### Stored and wired values at graph instance inputs + +Connect a typed graph input directly to an output. In the caller place an instance with an open input, an explicit argument, a wire from a Value Processor, or both an argument and a wire. The reference uses the declared default when the port is open. A wire supplies the value when the argument is absent. An explicit constant or parameter function supplies the value even with a wire present. MaterialCraft now resolves the argument using the bridge's declared type. The same-package and linked-package paths use the same port information. + +For an integer bridge with default 5, try an open port, stored 0, stored −3, wired 9, wired 9 with stored −3, and wired 9 with stored 9. The results in that order are 5, 0, −3, 9, −3 and 9. Run all six for same-file and linked instances, then save and reopen each caller in both applications. Agreement improved from 12/24 to **24/24 integer values**, maximum error 0. Repeat the linked cases with integer, Boolean and float2 types, testing both a constant argument and a parameter function on an open or wired port. For Boolean use default and wire true and argument false. For float2 use default (.125,.875), wire (2.5,−4.25) and argument (−.75,.375). These 18 original and 18 reopened outputs improved from 12/36 to **36/36 typed values**, maximum component error 0. + +In Points Preview, keep the same generated two-row ellipse strip, 32² canvas, point size .0625 and labels off. Connect point counts 1, 4 or 8. For each count test an open offset, constants 0 and 1, wires 0, 1 and 2, and a wire of 1 with constant 2. All **21,504/21,504** grayscale pixels match, maximum error 0. Repeat the [28 earlier root settings](#package-font-outlines-and-point-preview), including counts 4, 8 and 12 at offset 0, 1 and 2. All **25,088/25,088** pixels match the desktop captures in their stored formats. + +For a second whole-root comparison, use counts 4, 8 and 12 with the same offsets. Hide the first point for count 8 and the last for count 12. Use point sizes .03125, .0625 and .09375 and label sizes .0625, .09375 and .125 respectively. Test points only, labels only and both. Also test count zero with both enabled. For each view use 16² seed 0, 32² seed 42 and 32 × 16 seed 507031. Compare the one-worker F32 readback of the original instance and the instance referring to the complete saved spline package with its licensed fallback font. Errors below are normalized grayscale differences. + +| Visible elements | Original exact / total · max | Full save exact / total · max | Reference original versus full save · max | +|---|---:|---:|---:| +| Points | 5,376/5,376 · 0 | 5,376/5,376 · 0 | 5,376/5,376 · 0 | +| Labels | 5,088/5,376 · 0.513725515 | 5,087/5,376 · 0.494117673 | 5,105/5,376 · 0.380392157 | +| Both, including the empty input | 7,063/7,168 · 0.411764707 | 7,063/7,168 · 0.419607846 | 7,067/7,168 · 0.356862746 | + +The complete saved library reopens in the reference renderer. The reference catalog and the full save select different font files. Point-only output agrees across both paths. Visible labels also differ when both applications open the same saved font, leaving the root in progress. + +### Package font outlines and point preview + +The Text primitive reads the selected package font. Shaping and outline drawing use the shared font catalog and the CPU rasterizer. Editing the font bytes invalidates both the Text node and its parent graph instance. The release regression constructs a two-glyph TrueType face in memory, halves the cap height and checks the complete 64 × 32 raster on both cooks. + +For the independent reference comparison, generate two faces with 1,024 units per em, ascent 768, descent −256 and letter advance 640. Give A a 512 × 512 rectangle in one face and a triangle with vertices (0, 0), (256, 768), (512, 0) in the other. Give B a rectangle from (64, 64) to (256, 704) and space an advance of 256. Render white text on black at 64², 64 × 32 and 32 × 64. Start with size .5, centered alignment, zero offset and an identity transform. Vary text including empty strings, spaces and newlines, size, alignment, fractional translation, rotation, shear, reflection, singular matrices and tiling. Compare raw F32 readbacks from the one-worker reference renderer. + +| Comparison | Renders | Exact pixels / total | Maximum absolute error | +|---|---:|---:|---:| +| All original Text graphs | 96 | 261,686/262,144 | .584313781 | +| Six ordinary SBS saves reopened in both applications | 18 | 48,980/49,152 | .584313781 | +| Reference output before and after those saves | 18 | 49,152/49,152 | 0 | + +All three resolutions match for 28 of 32 settings. The sheared triangle differs by at most 5.97e−8. The triangle's diagonal coverage accounts for the other three differing settings. For the six reopens, use centered A in both fonts, AB, AB followed by a newline and A, shear, and tiling. A separate 64² triangle crosses U8, U16, F16 and F32 with grayscale or color output. With an opaque black background each matches 4,034/4,096 pixels, maximum normalized error .337281. With a constant background of (.1875, .4375, .625, .375), grayscale matches 154/4,096 per format and color matches 4,034/4,096 per format. The largest respective errors are .323980 and .458824. + +Points Preview now cooks with its linked font present. Use a generated F32 point strip with two rows of offset ellipses. With the point-count bridge open, ten settings at 16², 32² and four rectangular sizes up to 64 × 32 and 32 × 64 give 10,496/10,496 exact pixels. With labels off, connect integers 4, 8 and 12, set the respective offsets to 0, 1 and 2 and point sizes to .03125, .0625 and .09375. Test 16² F32, 32² in four parent formats and 32 × 16 F32. The stored U8 results are 4,864/4,864, 4,760/4,864 and 4,631/4,864. The last two reach 255 codes of error. The root stays open for the differing nonempty cases and visible labels. + +### Spline preprocessing with empty inputs and complete library saves + +Use the [original circle, tangent and striped mask fields](#spline-preprocessing-with-wired-counts). Instantiate the unmodified preprocessing graph and expose either its RGBA image or its integer count. Compare the disconnected default, connected counts (0,1), (1,1) and (2,1), and a spacing-driven (2,1) case. For the first three connected cases choose side 3, amount mode 0 and one spline per spline. For the last choose side 1, amount mode 1 and spacing .09375. The counts were 0, 0, 1, 2 and 21. The images were 2048 × 16 except for the spacing-driven output at 2048 × 32. + +Run each output at 16² seed 0, 16 × 32 seed 466061 and 32 × 16 seed 42. Also run the disconnected default with all three image inputs empty at 16² seed 0. Save the ten original test graphs through MaterialCraft and reopen them in both applications. The earlier four-format check added 32,768/32,768 exact pixels at each of U8, U16, F16 and F32. + +| Comparison | Exact RGBA pixels | Exact integer outputs | Maximum error | +|---|---:|---:|---:| +| Original graphs, explicit one-worker renderer | 622,592/622,592 | 16/16 | 0 | +| Ten reopened test graphs | 622,592/622,592 | 16/16 | 0 | +| Reference originals versus reopened test graphs | 622,592/622,592 | 16/16 | 0 | +| Desktop readback of six original or reopened controls | 131,072/131,072 | 3/3 | 0 | +| Entire library saved from its catalog entry | 131,072/131,072 | 3/3 | 0 | +| Entire library saved from its disk path | 131,072/131,072 | 3/3 | 0 | +| Disk save with a locally edited math dependency | 131,072/131,072 | 3/3 | 0 | + +For each complete library save, open the project’s unmodified spline package with the shared OFL font available and save outside the library. Point a fresh image or integer test graph at this saved file. Repeat the disconnected default, one-spline case and spacing case. The reference also reproduced all three original images and counts for each source path. The desktop supplied the formerly missing zero-count pixels through an instance. Its direct whole-library zero-count render did not return an image during the observation window. + +The disk-open save previously wrote relative paths to four unchanged, self-contained graph packages. The reference compiler rejected all six controls at dependency loading. The shared save command now uses portable library links for byte-identical, resource-free packages whose processing graphs and functions have no external calls. The corrected full-library save carries five catalog links including the existing math library. A separate save with four changed integer lanes in the local math package retained that relative filename and the four portable graph links. A dependency with its own external link retained its filesystem identity in the regression test. All 281 engine release tests, the hostile-command test, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. The preprocessing root reached parity for the measured cases. + +### Unused and unavailable relative functions + +Create eight original caller and function-package pairs with unique graph names, file UIDs and relative filenames. The caller samples red from the [original two rectangular float fields](#packed-products-in-the-second-endpoint-of-a-pixel-interpolation) at texel centers. Its output is (call result + .21875, sampled red, .53125, .75). The function takes one float argument and returns .34375. Use 64 × 32 F32 at seed 463071 and 32 × 64 U16 at seed 463094. Change only the dependency header between the two versions in each pair. + +| Caller and dependency | F32 exact / total · max | U16 exact / total · max | Reference red, F32 / U16 | +|---|---:|---:|---:| +| Called with sampled input, header 1.1.0.202401 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | .5625 / 36,863 | +| Called with sampled input, header 0.1.3 | 0/2,048 · .34375 | 0/2,048 · 22,527 | .21875 / 14,336 | +| Called with disconnected input, header 1.1.0.202401 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | .5625 / 36,863 | +| Called with disconnected input, header 0.1.3 | 0/2,048 · .34375 | 0/2,048 · 22,527 | .21875 / 14,336 | +| Unused call, .75 in its place, both headers | 4,096/4,096 · 0 | 4,096/4,096 · 0 | .96875 / 63,487 | + +A missing function name produced .21875 red with either header in the reference. MaterialCraft reported the missing graph on both calls. Each reference image retained the input-dependent green channel and the constant blue and alpha channels. This isolates the older relative file discrepancy to the called value. The [waveform measurements](#version-of-a-detached-function-package-and-waveform-reopening) retain their original counts. + +### Single connected operands in vector constructors + +In an original Value Processor, construct float and integer vectors of widths two, three and four. For each width try every smaller operand width in the first port alone, the second port alone and both ports. Use (.375, −.6875, .25) or (17, −23, 5), taking the leading values for the first connected operand and the reversed list for the second operand in the two-wire controls. Repeat the 36 graphs at 16² and 32², seeds 79 and 197. With a single connection its components occupy the leading lanes and the remaining lanes are zero. For example, connecting (17, −23) only to the second port of an integer vector of width three returns (17, −23, 0). + +| Comparison | Previous exact / total | Previous maximum error | Current exact / total | Current maximum error | +|---|---:|---:|---:|---:| +| Float vectors, whole typed values | 24/36 | 1.0625 | 36/36 | 0 | +| Integer vectors, whole typed values | 24/36 | 40 | 36/36 | 0 | +| Five saved graphs, whole typed values | 4/10 | 40 | 10/10 | 0 | +| Pixel Processor, first port empty | 0/8,192 | 1.99861372 | 8,192/8,192 | 0 | +| Pixel Processor, second port empty | 8,192/8,192 | 0 | 8,192/8,192 | 0 | +| FX-Map, first port empty, F32 and F16 | 0/384 | .625 | 384/384 | 0 | +| FX-Map, first port empty, U16 | 0/128 | 20,480 | 128/128 | 0 | +| FX-Map, zero input, U8 | 128/128 | 0 | 128/128 | 0 | + +Reopen five ordinary MaterialCraft saves in both applications. Use float widths three and four with the second port wired to a scalar or triple, integer width three with a pair on the second port, and integer width four with a scalar on the first port or both ports wired to pairs. The reference reproduced all ten original typed values. The same change in the function compiler applies to freshly authored graphs and reopened files. + +For the pixel controls use the [signed procedural F32 fields](#packed-products-in-the-second-endpoint-of-a-pixel-interpolation) at 64×32 and 32×64, seeds 435071 and 435090. Pack the sampled red channel alone in a pair and append (.1875,.875), or pack that constant pair alone in a four-vector. Repeat with each input port. For the FX-Map, expose a scalar on the second port of a pair in the root square's opacity expression and select its first or second component. Render at 16×8 with zero background and roughness. In order use F32 (.625, first), F32 (.625, second), F16 (.3125, first), U16 (.3125, second) and U8 (0, first), seeds 458151 + 29j starting at j = 0. + +The range covers physically disconnected ports. A separate pair with two wires still differs when its leading wire reads an undeclared variable and the other carries a nonzero value. Scanning the reachable expressions in all 546 root graph bodies found zero one-wire vector constructors with the leading port disconnected. Called function bodies were outside that scan. The root count stays at 479. The regression failed on the preceding compiler. All 401 node release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Two dense spots packages across storage formats + +Use the whole original BNW Spots 3 and BNW Spots 3 v2 graphs. At 16² and seed zero use all defaults. At 64² and seed 42 use scale 2 and disorder .37. On v2 also use disorder speed .6, anisotropy .3, anisotropy angle .125 and tile offset (.17,.29). Cook both sizes at U8, U16, F16 and F32. Compare each raw raster with its desktop capture and both explicit worker counts. Each column covers 4,352 grayscale pixels. + +| Package and reference | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| BNW Spots 3 · Desktop | 4,352/4,352 · 0 | 4,351/4,352 · 1 | 4,352/4,352 · 0 | 4,349/4,352 · 1.06990337e-05 | +| BNW Spots 3 · One worker | 4,352/4,352 · 0 | 4,352/4,352 · 0 | 2,726/4,352 · 0.00048828125 | 4,352/4,352 · 0 | +| BNW Spots 3 · Eight workers | 4,352/4,352 · 0 | 4,351/4,352 · 1 | 2,726/4,352 · 0.00048828125 | 4,349/4,352 · 1.06692314e-05 | +| BNW Spots 3 v2 · Desktop | 4,352/4,352 · 0 | 4,352/4,352 · 0 | 4,352/4,352 · 0 | 3,905/4,352 · 1.49011612e-07 | +| BNW Spots 3 v2 · One worker | 4,352/4,352 · 0 | 4,352/4,352 · 0 | 4,352/4,352 · 0 | 4,352/4,352 · 0 | +| BNW Spots 3 v2 · Eight workers | 4,352/4,352 · 0 | 4,351/4,352 · 1 | 4,352/4,352 · 0 | 3,803/4,352 · 1.78813934e-07 | + +The F32 readback of the explicit F16 renders contains exact half values at all 4,352 positions in each package. On BNW Spots 3, 1,626 of those stored half values differ from the desktop, including at one worker. The two v2 F16 references match the desktop throughout. The four F32 reopens reproduce the corresponding original counts and errors. Each reopened package matches the explicit one-worker reference at both sizes, 4,352/4,352 F32 pixels per package. + +At 64 × 16, seed 42, non-square expansion enabled, scale 2 and disorder .03125, both whole graphs still exceed the traversal budget. For v2 use disorder speed and anisotropy .03125, angle −.21875 and offset (−.3125,.37890625). Neither rectangular cook contributes to the exact totals. The [32² dense case and execution bound](#bounded-work-for-terminal-quadrant-siblings) remain separately measured. + +### Bounded work for terminal Quadrant siblings + +The shared FX-Map evaluator now charges a group of at most four terminal Quadrant siblings for its first discarded stamp. Each child evaluates its own properties, applies its variable writes and reaches its own sample-grid test before it can share that charge. Each visible stamp still costs a visit. An iteration or a branch with descendants cannot obtain extra visits by repeating a single discarded stamp. Terminal nodes also skip the unused child-center and child-seed calculations. + +The ordinary limit covers 1,048,576 visits plus the same number of individual discards. Every group with an extra discard needs a distinct parent and first discarded child among those ordinary visits. At most three further discards can share their charge, bounding evaluated visits at 5,242,880. Stored stamps, stack occupancy, raster copies and pixel work retain their own bounds. A regression with a 64-visit allowance checks a visible marker and 48 four-child groups that miss all 4×4 samples. Changing those children to visible squares reaches the limit. Repeating a branch with a single missed child 80 times also reaches it. The previous cook failed on the marker case. + +Repeat the [four whole BNW Spots 3 v2 readouts](#four-cloud-noise-generators-and-repeated-saved-file-comparisons) with the normal release cook and compare the final F32 buffers with the desktop. The default 16×32 at seed zero gives 478/512 exact. At scale 1, the 32×16 seed 162065 and 64×32 seed 162283 give 449/512 and 1,860/2,048. Maximum channel errors are 1.1920929e−7, 1.1920929e−7 and 1.49011612e−7 respectively. The 32² scale-two seed 162174 previously exhausted the visit allowance. + +| Scale-two F32 comparison, 4,025,030 visits | Original, exact / total · maximum | MaterialCraft save reopened, exact / total · maximum | +|---|---:|---:| +| Explicit one-worker reference, both repeat runs | 1,024/1,024 · 0 | 1,024/1,024 · 0 | +| Desktop | 894/1,024 · 1.1920929e−7 | 894/1,024 · 1.1920929e−7 | +| Explicit eight-worker reference, first run | 878/1,024 · 1.78813934e−7 | 878/1,024 · 1.78813934e−7 | +| Explicit eight-worker reference, second run | 874/1,024 · 1.1920929e−7 | 874/1,024 · 1.1920929e−7 | + +Use the [same graph settings, reference captures and worker repeats](#dense-quadrant-traversal-and-reference-worker-counts). In the 32 original four-format Quadrant controls, 28 renders complete with 7,159/7,168 desktop pixels exact. Six of eight reopens complete with 766/768 exact. Maximum error in either set is 5.96046448e−8. The regular depth-eleven tree still reaches the limit at all four tested formats and both saved formats. The whole spot root remains in progress. All 402 node release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Dense Quadrant traversal and reference worker counts + +Construct a grayscale FX-Map with a .0625 background, zero roughness, overall opacity 1, both regions (0,1,0,1), center culling enabled and wrapping disabled. Start at (.5,.5). At each subdivision link all four children to the next empty Quadrant. At the last level draw additive squares of size (1.75,2.25), rotation zero and luminosity `rand(.0625) + .0625 * $pos.x`. In the returning-offset version move the root branch by (1.25,0) and the final stamp by (−1.25,0). In the narrow version change only the size to (.375,1.25). Use seeds 441151 + 31j, with j from zero to three in the column order below. + +| Graph and final depth | F32 16×8 | F16 16² | U16 8×16 | U8 32×16 | +|---|---:|---:|---:|---:| +| Regular, 6 | 128/128 · 0 | 256/256 · 0 | 128/128 · 0 | 512/512 · 0 | +| Regular, 8 | 128/128 · 0 | 256/256 · 0 | 128/128 · 0 | 512/512 · 0 | +| Regular, 10 | 121/128 · 2.98023224e-08 | 256/256 · 0 | 128/128 · 0 | 512/512 · 0 | +| Regular, 11 | Visit limit | Visit limit | Visit limit | Visit limit | +| Returning offset, 8 | 128/128 · 0 | 256/256 · 0 | 128/128 · 0 | 512/512 · 0 | +| Returning offset, 10 | 126/128 · 5.96046448e-08 | 256/256 · 0 | 128/128 · 0 | 512/512 · 0 | +| Narrow, 8 | 128/128 · 0 | 256/256 · 0 | 128/128 · 0 | 512/512 · 0 | +| Narrow, 10 | 128/128 · 0 | 256/256 · 0 | 128/128 · 0 | 512/512 · 0 | + +The production cook matched 7,159/7,168 desktop pixels in 28 completed settings. The reference produced a buffer for all 32. Save and reopen the depth-eight regular, depth-eleven regular, depth-ten returning and depth-ten narrow graphs. Repeat the F32 and U16 rectangles. The two applications matched 766/768 pixels in six completed reopens, maximum 5.96046448e−8. Across all eight, the reference reproduced 1,008/1,024 original pixels. Its 16 changed pixels were in the depth-eleven F32 image, maximum 2.98023224e−8. + +For the whole BNW Spots 3 v2 graph use 32² F32, seed 162174, scale 2, disorder .78125, speed 1.015625, anisotropy .390625, angle .40625 and tile offset (.1708984375,−.29296875). Complete this traversal and the two F32 square controls below in a diagnostic MaterialCraft build with a higher visit allowance. On each saved graph select one or eight reference workers explicitly and render twice without changing the seed. The table gives exact pixels / total and maximum channel error. + +| Graph | Completed traversal vs one worker, both runs | vs desktop | vs eight workers, first run | vs eight workers, second run | Eight-worker repeat | +|---|---:|---:|---:|---:|---:| +| Regular, 11 | 128/128 · 0 | 109/128 · 2.98023224e-08 | 113/128 · 2.98023224e-08 | 107/128 · 2.98023224e-08 | 96/128 · 2.98023224e-08 | +| Returning offset, 10 | 128/128 · 0 | 126/128 · 5.96046448e-08 | 105/128 · 5.96046448e-08 | 113/128 · 5.96046448e-08 | 102/128 · 5.96046448e-08 | +| Whole Spots 3 v2 | 1,024/1,024 · 0 | 894/1,024 · 1.1920929e-07 | 878/1,024 · 1.78813934e-07 | 874/1,024 · 1.1920929e-07 | 887/1,024 · 2.38418579e-07 | + +The dense spot traversal takes 4,025,030 visits. At depth eight in its final generator, testing a square with radius four times the current subdivision width around the incoming center plus the inherited frame offset would reject 6,442 of 753,536 subtrees that contained a retained stamp. The returning-offset controls also draw after their ancestors leave the image. The [bounded terminal-sibling cook](#bounded-work-for-terminal-quadrant-siblings) subsequently completed this spot setting in production. The depth-eleven limit and the multi-worker differences remain open. [Original spot traversal and whole-root measurements](#whole-root-precision-and-saved-comparisons-for-the-three-neighboring-spot-graphs) + +### Whole and reopened first-renderer irradiance pass + +Repeat the [17 default-index settings](#first-renderer-eighth-irradiance-pass) and the [nine connected-index settings](#irradiance-with-a-connected-pass-index) after the [instance input and rotation correction](#scalar-float-precision-in-nested-graph-instances). The original seven procedural inputs, graph expressions and output connections are retained. Each of the 26 image outputs and 26 next-index float values matches, including the default at 256² and seed 42 at 128². + +| Comparison | Settings | U8 exact / total | U16 exact / total | F16 exact / total | F32 exact / total | Float indices exact / total | Maximum error | +|---|---:|---:|---:|---:|---:|---:|---:| +| Default index | 17 | 4,352/4,352 | 4,352/4,352 | 102,656/102,656 | 8,960/8,960 | 17/17 | 0 | +| Connected index | 9 | — | — | 4,608/4,608 | — | 9/9 | 0 | +| Reopened standalone graph | 5 | 256/256 | 256/256 | 256/256 | 512/512 | 5/5 | 0 | +| Reopened parent linked to the saved child | 4 | — | — | 2,560/2,560 | — | 4/4 | 0 | + +For the standalone reopen, save the original graph with MaterialCraft and compare its image and typed index outputs in both applications. At 16² repeat the default and changed shadow readouts in F32 and the three small U8, U16 and F16 readouts. For the connected path save a wrapper with a relative dependency on that same saved child. Reopen the emitted files and set the start index to −1, .5, 3 and 7.25 at seeds 11, 43, 61 and 211. The stored images and typed next-index values reproduce their original reference outputs. The original graph reached parity for the measured cases. + +### Whole first-renderer specular pass after the Switch correction + +Repeat the [original, rectangular and saved comparisons](#whole-and-reopened-eighth-specular-passes) for the first renderer's eighth specular pass with the [parameter-driven Switch Blend correction](#switch-blend-with-parameter-driven-endpoint-opacity). Count a pixel as exact when all four stored channel words, including zero signs, agree. The changed 128² and default 256² F16 renders now match 16,384/16,384 and 65,536/65,536 pixels. Seed 42 and the default at 128² each match 16,384/16,384. + +| Comparison | Settings | U8 exact / total | U16 exact / total | F16 exact / total | F32 exact / total | Maximum error | +|---|---:|---:|---:|---:|---:|---:| +| Original graph | 26 | 5,136/5,136 | 5,136/5,136 | 119,888/119,888 | 12,180/12,180 | 0 | +| Independent rectangular inputs | 12 | 160/160 | 160/160 | 320/320 | 320/320 | 0 | +| MaterialCraft SBS reopened in both applications | 5 | 128/128 | 32/32 | 16,416/16,416 | 128/128 | 0 | +| Environment and material controls, full output | 5 | — | — | — | 81,920/81,920 | 0 | +| Same five renders, first Pixel Processor | 5 | — | — | — | 81,920/81,920 | 0 | + +Each saved reference buffer also reproduced its original. The five 128² environment controls use the original eight inputs, a black or coordinate environment, black emissive, or black specular and roughness. The complete outputs resolve the [four earlier F16 zero-sign differences](#whole-specular-outputs-and-wired-irradiance-stages), including the one that recurred after saving. The original root qualifies for parity on these measured cases. + +### Scalar float precision in nested graph instances + +A scalar float supplied by an instance default, an explicit constant or a constant expression retains literal precision inside the child graph. A value driven by an exposed parent parameter retains runtime precision. In an original Pixel Processor, take the sine of one full turn using the F32 constant 6.2831855. The fixed result has F32 bits `343bbd2e`. With the same turn supplied by an exposed parent input it has bits `80000000`. A called function writing a different variable preserves this distinction. MaterialCraft now tracks fixed scalar floats at graph boundaries and invalidates known operands by the names a called function writes. + +Use the signed procedural RGBA fields from the [pixel interpolation comparison](#packed-products-in-the-second-endpoint-of-a-pixel-interpolation). Use field indices 0, 1, 2, 0, 0 and 1 with seeds 435071 + 19j for j from 0 through 5. Read the red channel with nearest sampling. Set the exposed turns to 1, .1875, −.38157, .723561, 0 and .375. Output sine, cosine, the F32 angle in radians and the sampled red channel. Compare top-level reads, literal 1 and .375, nested defaults, explicit values, a .375 + .625 expression, a parent read and a parent-driven selection between 1 and .375. Repeat the phase calculation in a called function and after a call that writes a sampled value to an unrelated variable. + +| Comparison | Renders | Exact pixels / total | Maximum component error | +|---|---:|---:|---:| +| Fifteen F32 graphs, before | 90 | 129,024/215,040 | 1.74845553e−7 | +| Same F32 graphs, corrected | 90 | 215,040/215,040 | 0 | +| Six controls, U8, U16 and F16 at the first three settings | 54 | 49,152/49,152 per format | 0 | +| Eight MaterialCraft saves opened in both applications, F32 | 48 | 114,688/114,688 | 0 | +| Earlier returned-product, shared-product and quotient controls | 307 | 1,288,192/1,288,192 | 0 | + +The six format controls use top-level literal and exposed turns, a child default, an explicit child value, a parent read after an unrelated write, and the constant expression. The saves include two top-level graphs and six parent/child pairs with relative dependencies. Each saved reference image reproduced its original. The regression alternates default, explicit and parent-driven inputs on a shared cache. It failed on the preceding evaluator. All 470 evaluation and node release tests passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +For the first renderer's eighth irradiance pass, repeat the [nine connected-index settings](#irradiance-with-a-connected-pass-index) with its existing SBS graph. All 4,608/4,608 F16 pixels and 9/9 float indices match, maximum zero. With the [four saved intermediate readouts](#whole-specular-outputs-and-wired-irradiance-stages), each processor, the first Switch and the final image match 2,560/2,560 F16 pixels. The four final images and index values reproduce the original reference outputs. At row 14 in the two 32² controls, the three rotation columns, world and rotated hits, sampling coordinates, samples and lighting terms match 896/896 F32 pixels over 14 readouts. The first two reference columns contain −1.74845553e−7 and +1.74845553e−7 off the diagonal. + +Separate probes also assign to the same name as the exposed angle. At turns 1, .1875 and 0, the top-level write, a parent-driven argument shadowed in a call, and an unrelated write through two calls match 18,432/18,432 F32 pixels. Four other read/write combinations in child graphs still differ at all 24,576 pixels. Writing the exposed name before another call reads it has maximum error 18.8408465 across the output channels. Shadowing a fixed input or reusing a getter evaluated before a write has maximum error 1.74845553e−7. These are independent controls for assignment order. + +### Rectangular image inputs on graph instances + +When a connected image crosses a graph boundary, axes more than one doubling or halving from their target move first. The final sampling pass adjusts both axes to the requested dimensions. Each pass stores its result at the input bridge's precision. A 32² F32 image feeding a 16 × 8 F16 bridge therefore goes through 32 × 16. MaterialCraft previously used 16² as the intermediate. The connected bridge now shares the atomic input filters' choice of intermediate dimensions. + +Connect a parent color input to a child color input fixed at 16 × 8. Wire the child input directly to its output. At size index j, use parent dimensions (16,8), (16,16), (32,16), (32,32), (64,64), (128,32), (64,16), (4,4), (8,2), (32,4), (128,2), (8,64), (4,1), (2,2) and (128,128), in that order. Set seed s = 430031 + 37j. For channel c and width w, compute the unsigned 32-bit word q = (x + wy + s + 701c) × 1597334677 + 3812015801, then q = (q XOR (q >> 16)) × 2246822519, wrapping both products. Generate F32 sign bit (q >> 15) & 1, biased exponent 120 + q mod 10, and fraction (q >> 1) & 0x7fffff. Compare all four stored channels at every output pixel. + +| Parent → child storage | Settings | Previous exact / total · max | Corrected exact / total · max | +|---|---:|---:|---:| +| F32 → F16 | 15 | 913/1,920 · .00390625 | 1,920/1,920 · 0 | +| F16 → F16 | 15 | 904/1,920 · .00390625 | 1,920/1,920 · 0 | +| F32 → F32 | 15 | 929/1,920 · 4.76837158e−7 | 1,920/1,920 · 0 | +| U16 → F32 | 15 | 969/1,920 · 1.15036964e−5 | 1,920/1,920 · 0 | +| F16 → U8 | 15 | 1,046/1,920 · 191 levels | 1,920/1,920 · 0 | +| U8 → U16 | 15 | 1,338/1,920 · 1 level | 1,920/1,920 · 0 | +| F32 → U16 | 15 | 1,074/1,920 · 49,151 levels | 1,920/1,920 · 0 | + +Bind the same files directly to F16, F32 and U16 bridges for 45 additional controls. All 5,760/5,760 pixels match. Save the F32 → F16, F32 → F32 and U8 → U16 child packages with MaterialCraft, then save their corresponding parents with relative references to the saved children. Also save the direct F16 graph. All four saved graphs reopened in both applications. Their 7,680/7,680 pixels matched across applications and reproduced the original reference outputs. + +For a smaller regression, alternate R by column and G by row between 1 and 1 + 1/1024. Set B = −R and A = −G. With the same F16 child, the 32² source produces R = 1 + 1/1024 and G = 1. The 64 × 16 source exchanges those results. Compare both and the 32 × 16 and 16 × 8 controls at seeds 431039 + 41j. The four outputs improved from 256/512 to 512/512 pixels, maximum error from .0009765625 to zero. The regression failed before the change. Formatting, the evaluation and node release tests, strict workspace Clippy, dependency layers and WebAssembly checks passed. + +Repeat the [nine connected-index irradiance settings](#eighth-irradiance-pass-with-default-and-connected-indices). They now match **4,603/4,608 F16 pixels** and **9/9 typed indices**, maximum errors .001953125 and zero. The .5 case improved from 991/1,024 to 1,023/1,024. Both 7.25 cases improved from 1,007/1,024 to 1,024/1,024. The four output-format requests at index 3 each retain 255/256. The saved inner graph reproduced every original reference output in the four processor readouts. The first processor and both Switches have identical exact counts at all four settings. + +In the 32² row-14 probe, capture the 16 × 8 environment bridge, the 32² emissive bridge and their F32 sample coordinates at the third light call. Recomputing the two filtered samples from each application's own bridge and coordinates reproduces all 256 measured samples across two pass indices and both applications. The corrected environment bridge matches all 128 pixels on the actual field. A separate rotation difference remains before the emissive lookup. + +### Copied steps in called pixel sums + +The shared pixel evaluator now follows a floating-point product copied to another variable. A later addition can use its original factors after the first variable is overwritten. Reading a component of the copy separately rounds that component. The same behavior applies when the next addition or the component read is in the caller or a subsequent function call. + +Use the four F32 settings from the [component and assignment-order comparison](#component-reads-and-writes-across-pixel-function-calls). From the original signed input field form a position from GBAR and a direction from BRGA. Store direction times A as the step. Inside the call, copy the step to another variable, overwrite the original with the position, and add the captured step to the position. Compare a single unused copy, a second unused copy, an explicit read of the copy, and a read in a later call. In three further graphs, append the saved B component after the first three sum components, reading B inside the call or in the caller. As a control, overwrite the copy with the position before reading it. + +| Comparison | Graphs | Settings | Exact F32 pixels / total | Maximum component error | +|---|---:|---:|---:|---:| +| Original graphs, before | 8 | 32 | 23,916/49,152 | 4.76837158e−7 | +| Same graphs, corrected | 8 | 32 | 49,152/49,152 | 0 | +| Copy, separate B read, caller B read and later call saved by MaterialCraft | 4 | 16 | 24,576/24,576 | 0 | + +All four saves reproduced the original reference pixels when reopened. The earlier unused-copy graph improved from 3,968/8,192 to 8,192/8,192 in F16 and F32 combined. Of the 42 earlier assignment graphs, 41 now match 342,016/342,016 pixels across 197 settings. The sampled-alpha branch still matches 11,173/22,528, including when reopened. Another 49 earlier arithmetic graphs retained 1,288,192/1,288,192 exact pixels across 307 settings. The 64² irradiance first processor retained 4,096/4,096 in both floating formats. The copied-step regression failed before the change. All 401 node release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly checks passed. + +### Switch Blend with parameter-driven endpoint opacity + +An unmasked Switch Blend with opacity 0 or 1 can forward the selected floating-point color texture when opacity is fixed and storage precision matches. When its opacity reads an exposed graph parameter, the color conversion runs even at matching precision. It flushes F32 subnormal components to signed zero, then clears zero signs unless all three RGB signs are negative. A change of floating-point storage precision also runs this conversion. The shared Blend cook now uses the evaluator's existing distinction between fixed and parameter-driven opacity. + +Use the [independent sign fields](#signed-zero-when-switch-blend-selects-a-floating-point-color-input) with both nearest-sampling inputs stored in F16 or both in F32. Set opacity to literal zero, an exposed float at 0 and 1, or the result of testing that float against .5. Repeat with fixed parent-relative dimensions and with an output-size function that reads the parent size and returns the relative offset (0,0). Apply the size function to the background, both sources, the Switch, or both sources and the Switch. Compare the actual F16 and F32 outputs at 16², 32 × 16 and 16 × 32. + +For the smaller-magnitude field, store the F32 words `00000000 00000001 00400000 007fffff 00800000 31800000 33800000 38000000 3ee00000 00000000 3f600000 ba004000`. For channel c, source s (0 foreground, 1 background) and size index j, select word (y + 2c + s + 7j) modulo 12. OR its sign with bit c of (x + 3y + 5j + 3s) modulo 16. Use 16² and 32 × 16 with seeds 421019 and 421042. Repeat the three opacity controls with matching source precision and both floating-point output formats. + +| Comparison | Settings | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:| +| Eighteen opacity and size controls, before | 142 | 20,828/28,928 · 0 | 26,176/28,928 · 0 | +| Same controls, corrected | 142 | 28,928/28,928 · 0 | 28,928/28,928 · 0 | +| Six small-magnitude controls, before | 40 | 5,752/7,680 · 0 | 5,060/7,680 · 1.17549421e−38 | +| Same controls, corrected | 40 | 7,680/7,680 · 0 | 7,680/7,680 · 0 | +| Six MaterialCraft SBS saves opened in both applications | 44 | 8,704/8,704 · 0 | 8,704/8,704 · 0 | + +Each saved reference output reproduced its original. The [20 earlier Switch graphs](#signed-zero-when-switch-blend-selects-a-floating-point-color-input) retained 81,920/81,920 exact pixels across 144 settings. Their seven saves retained 27,136/27,136 across 50 settings. The graph regression changes the opacity source while reusing the cook cache, selects both inputs, and compares F16 and F32 channel bits. It failed before the change. All 67 evaluation and 400 node release tests passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly checks. + +For the [first eighth specular pass](#whole-specular-outputs-and-wired-irradiance-stages), guard the three processor bodies at their original coordinates and expose all three processor outputs and both Switch outputs. At 256², compare x = 0, 1 and 255 at y = 101, 102, 103, 179, 180 and 181, plus (134,88), (25,93) and (255,255). Both Switches improved from 18/21 to 21/21 pixels, including the three negative green zeros. All five outputs matched 21/21 there and 42/42 in the 128² black-specular control, maximum error zero. The reference also reproduced its unguarded pixels at every selected coordinate. The complete unguarded output is tracked separately. + +### Eighth irradiance pass with default and connected indices + +Repeat the [17 default-index and nine connected-index settings](#irradiance-with-a-connected-pass-index) after the called pixel-sum correction. All 17 default-index images now match, including the default at 128² and 256² and seed 42 at 128². The 26 next-index floats are exact. + +| Connections | Settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Default pass index | 17 | 4,352/4,352 · 0 | 4,352/4,352 · 0 | 102,656/102,656 · 0 | 8,960/8,960 · 0 | +| Connected pass index | 9 | — | — | 4,537/4,608 · 0.001953125 | — | + +To isolate the first processor at 32², keep the seven original procedural fields and seed 43 from the start-index .5 case. Repeat with only the index changed to zero. Guard row 14, retain the first three light calls in order, and expose the third call's environment UV, sampled color, gain and weight as F32 in separate runs. All 64 UVs, gains and weights match. The sampled environment color matches 23/32 pixels at .5 and 27/32 at zero, with maximum error .000244140625 in both. Exposing the nested input bridge directly identifies an earlier difference. The 32² parent feeding the 16 × 8 F16 environment bridge matches 105/128 bridge pixels, maximum .00048828125. The corresponding U16 emissive bridge matches 1,024/1,024. The connected-index outputs remain in progress. + +### Component reads and writes across pixel function calls + +In the shared Pixel Processor evaluator, a call can read individual components of a stored product. The observed components round at the multiplication. The other components retain their factors for an addition or subtraction. A getter evaluated before a later assignment keeps its earlier value. A getter evaluated after the assignment reads the replacement. + +Repeat the [called ray-step probes](#assigned-ray-steps-inside-pixel-function-calls) with the same signed procedural fields, including the 13 settings for each repeated call. In six additional graphs, return the leading components of the sum followed by the stored product's R, G, B, A, AR or GB components. Pass the step through a free variable or a connected function argument. In five further graphs, compare the fresh sum, a write before or after the sum, a write visible to the caller, and a free-variable write alongside a connected argument. Use 64 × 32 F32 and F16 at seed 379131, 32 × 64 F32 at 379172, 16 × 64 F32 at 394167 and 32² F32 at 394213. + +| Comparison | Renders | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Sixteen one-addition graphs | 16 | — | — | — | 32,768/32,768 · 0 | +| Nine repeated addition, subtraction, observation and reassignment graphs | 117 | 27,648/27,648 · 0 | 27,648/27,648 · 0 | 27,648/27,648 · 0 | 119,808/119,808 · 0 | +| Assignment guarded by literal true or false, free or connected step | 4 | — | — | — | 8,192/8,192 · 0 | +| Six independent component selections | 30 | — | — | 12,288/12,288 · 0 | 36,864/36,864 · 0 | +| Five read and write orders | 25 | — | — | 10,240/10,240 · 0 | 30,720/30,720 · 0 | +| Assignment guarded by sampled alpha | 13 | 1,547/3,072 · 255 | 1,545/3,072 · 65,535 | 1,505/3,072 · 31.9316406 | 6,576/13,312 · 31.9348962 | +| Getter also assigned to an unread variable before a write | 5 | — | — | 2,048/2,048 · 0 | 1,920/6,144 · 4.76837158e-07 | + +The sixteen one-addition cases previously matched 29,800/32,768 pixels. The six component selections previously matched 33,520/49,152. Seven existing MaterialCraft saves now match 96,256/96,256 pixels. The saved sampled-alpha graph matches 11,173/22,528, with the same per-format counts and maxima as the original. Seven additional saves cover the R, B and AR reads, the two write orders, the second assignment and the literal-true connected step. They match 65,536/65,536 pixels across 39 settings. Together the 15 saves reopened in the reference app and reproduced 184,320/184,320 original pixels. + +Both new regressions failed on the preceding evaluator. All 400 node release tests passed on the correction, along with formatting, strict workspace Clippy, dependency layers and WebAssembly checks. The [wired irradiance pass](#whole-specular-outputs-and-wired-irradiance-stages) remains in progress. + +### Whole specular outputs and wired irradiance stages + +The first eighth specular pass (root 396) was rerun after correcting [floating-point Switch Blend](#signed-zero-when-switch-blend-selects-a-floating-point-color-input). All five [128² environment and material controls](#environment-and-intermediate-precision-in-the-eighth-specular-passes) now match 81,920/81,920 F32 output pixels and 81,920/81,920 F32 first-processor pixels. This includes the 31 zero signs in the black-specular control. The [original matrix and five saved cases](#whole-and-reopened-eighth-specular-passes) have four remaining zero-sign differences in F16. Three occur in the 256² default. The fourth occurs in the 128² changed case and repeats when reopened. All five saved reference images reproduced the originals. + +| Render set | Settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Specular, original matrix | 26 | 5,136/5,136 · 0 | 5,136/5,136 · 0 | 119,884/119,888 · 0 | 12,180/12,180 · 0 | +| Specular, rectangular controls | 12 | 160/160 · 0 | 160/160 · 0 | 320/320 · 0 | 320/320 · 0 | +| Specular, saved SBS opened in both applications | 5 | 128/128 · 0 | 32/32 · 0 | 16,415/16,416 · 0 | 128/128 · 0 | +| Irradiance, default index through 64² | 14 | 4,352/4,352 · 0 | 4,352/4,352 · 0 | 4,352/4,352 · 0 | 8,960/8,960 · 0 | +| Irradiance, wired pass indices | 9 | — | — | 4,537/4,608 · 0.001953125 | — | + +For the 256² specular readout, open a MaterialCraft save with the three processor results and both Switch outputs exposed. Keep their original precision and render settings. The reference reproduced the 65,536 original output pixels. All five outputs are F16. At (0,102), (0,103) and (0,180) the selected first processor stored 8000 on green and the first Switch stored 0000. All its other pixels matched the selected input. The second Switch matched the first on 65,536/65,536 pixels. This same-precision comparison remains open. + +The irradiance rows use [the original 14 unwired settings through 64² and nine wired settings](#irradiance-with-a-connected-pass-index) after the [called ray-step correction](#assigned-ray-steps-inside-pixel-function-calls). The 23 next-pass outputs match 23/23 typed floats, maximum zero. For the wired comparison, save the inner graph with MaterialCraft. Expose each processor and the first Switch as image outputs in a disposable copy. Connect the same original wrapper to this relative SBS dependency and open it in both applications. Each saved reference output matched its original. The next-pass value also matched in all four readouts. Each pair below reports exact F16 pixels and maximum component error. + +| Pass index · size · seed | First processor | Second processor | Third processor | First Switch | Final output | +|---|---:|---:|---:|---:|---:| +| −1 · 16² · 11 | 256/256 · 0 | 254/256 · 0.005859375 | 255/256 · 0.0009765625 | 256/256 · 0 | 256/256 · 0 | +| .5 · 32² · 43 | 991/1,024 · 0.001953125 | 970/1,024 · 0.00390625 | 1,009/1,024 · 0.001953125 | 991/1,024 · 0.001953125 | 991/1,024 · 0.001953125 | +| 3 · 16² · 61 | 255/256 · 0.0009765625 | 255/256 · 0.0009765625 | 256/256 · 0 | 255/256 · 0.0009765625 | 255/256 · 0.0009765625 | +| 7.25 · 32² · 211 | 1,007/1,024 · 0.001953125 | 988/1,024 · 0.001953125 | 1,004/1,024 · 0.001953125 | 1,007/1,024 · 0.001953125 | 1,007/1,024 · 0.001953125 | + +At the three positive indices the selected first processor already contains every difference that reaches the output. Both roots remain in progress. + +### Assigned ray steps inside pixel function calls + +In the first eighth irradiance pass (root 395), the parent pixel function stores direction times step length. The shadow function reads this step and adds it to its current position. The shared evaluator can now retain both factors across calls, including steps passed through a connected argument. It rounds the product and the addition together when the callee reads the assigned step only for the sum. + +Repeat the [64² irradiance comparison and row-20 readouts](#stored-products-in-pixel-expressions-and-irradiance-ray-steps). On the third light, the position after 0, 1, 4, 8 and 15 shadow calls matched 320/320 F32 pixels. The final world hit, emissive coordinates, filtered sample, lighting factor and light contribution each matched 64/64. Maximum error was zero throughout. At (28,20) the hit Y was 0.6489657164 and emissive V was 0.09066748619 in both applications. The full first processor improved from 4,094/4,096 to 4,096/4,096 in F16 and from 3,023/4,096 to 4,096/4,096 in F32. The two output precisions use the same bound fields and settings. + +For the 16 one-addition graphs, use the [original assignment and called-function configurations](#stored-products-in-pixel-expressions-and-irradiance-ray-steps). Fourteen are now exact. In the two remaining cases the callee overwrites the step after the addition. For the extended controls use both sets of signed input fields from that comparison, across all 13 settings per graph. Put the assignment in a function with a connected field argument, then call a second function to advance the stored position. With a free step perform one and eight additions, or eight with the operands exchanged. With a connected step perform two and eight additions. Subtract the step from the position and the position from the step in two separate two-call graphs. + +| Comparison | Renders | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Sixteen one-addition graphs | 16 | — | — | — | 29,800/32,768 · 4.76837158e-07 | +| Seven addition and subtraction graphs | 91 | 21,504/21,504 · 0 | 21,504/21,504 · 0 | 21,504/21,504 · 0 | 93,184/93,184 · 0 | +| Literal true or false around the assignment, free and connected step | 4 | — | — | — | 5,224/8,192 · 4.76837158e-07 | +| Two additions with the stored blue component in alpha | 13 | 3,072/3,072 · 0 | 3,072/3,072 · 0 | 3,069/3,072 · 1.90734863e-06 | 6,105/13,312 · 9.53674316e-07 | +| Reassign the step to the original position before the second addition | 13 | 3,072/3,072 · 0 | 3,071/3,072 · 1 | 3,068/3,072 · 0.0009765625 | 7,291/13,312 · 9.53674316e-07 | +| Eight additions after a condition on input alpha | 13 | 1,547/3,072 · 255 | 1,544/3,072 · 65535 | 1,505/3,072 · 31.9316406 | 1,243/13,312 · 31.9348962 | +| Six exact SBS saves opened in both applications | 42 | 9,216/9,216 · 0 | 9,216/9,216 · 0 | 9,216/9,216 · 0 | 46,080/46,080 · 0 | +| Reopened separately observed blue component | 13 | 3,072/3,072 · 0 | 3,072/3,072 · 0 | 3,069/3,072 · 1.90734863e-06 | 6,105/13,312 · 9.53674316e-07 | +| Reopened condition on input alpha | 13 | 1,547/3,072 · 255 | 1,544/3,072 · 65535 | 1,505/3,072 · 31.9316406 | 1,243/13,312 · 31.9348962 | + +For the conditional graphs, assign direction times A to the step when A > 0 and return zero on the other branch. Discard the returned value and read the step inside eight calls. On the F32 fields the reference matches the unconditional assignment, including pixels with negative A. With a literal false guard, both applications return the original position. A literal true produced the fused result in the reference, with 564/2,048 matching pixels for each MaterialCraft graph. All eight saves reproduced the original reference pixels. The six exact saves span the outer and root assignment, the connected and free steps, eight additions and reverse subtraction. + +The new free- and connected-step regression failed before the correction and passed afterward. All 49 earlier product and quotient graphs retained 1,288,192/1,288,192 exact pixels in 307 renders. Verification ran 398 node release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly checks. The complete root remains in progress. + +### Signed zero when Switch Blend selects a floating-point color input + +In the [first eighth specular pass](#environment-and-intermediate-precision-in-the-eighth-specular-passes), render the black-specular-and-roughness control at 128² with F32 storage on the first pixel processor. Expose all three pixel processors and the two downstream Switch Blend results in a disposable MaterialCraft save. Read all five outputs from one cook in each application. The first processor and the final reference output each reproduced all 16,384 original pixels. Before the correction the three processors each matched 16,384/16,384 between applications. Their formats are F32, F16 and F16. The first Switch matched 16,345/16,384 and the second 16,353/16,384. Maximum numerical error was zero at all five stages. At (1,22) the first Switch returned `80000000` on green in MaterialCraft and `00000000` in the reference. + +An unmasked Switch at opacity zero or one copies the selected input. A same-size floating-point RGBA copy at the same precision preserves every channel bit. When converting F16 to F32 or F32 to F16, an existing zero retains its sign only when all three source RGB signs are negative. This also governs an existing zero in alpha. Converting before rounding to F16 preserves the sign of a negative nonzero component that rounds to zero. Subnormal F32 channels become signed zero before this precision conversion. At fractional weights the foreground and background channels, the rounded foreground product and the resulting multiply-add each flush subnormals to signed zero. + +Feed two nearest-sampling pixel processors into an unmasked Switch. For component c of each F32 RGBA field select words from `00000000 80000000 b1800000 31800000 bf800000 3f800000 3e8b217c bfd382af 80000001 00000001 c0000000 3b0386a1 b8899021 38f061d5 bf6987c4 405ccaac`. Index foreground by (x + 3c + 5j) modulo 16 and background by (y + 7c + 3j) modulo 16. Use 32 × 16, 16 × 32 and 32² for j = 0, 1 and 2 and seed 397091 + 47j. Use F32 for both processors at opacities 0, 1, .25 and .6137. Repeat with an F16 foreground at 0, 1, .5 and .6137. Store the Switch in all four formats at the first size and in F32 at the other two. + +For independent sign tests, use 16², 32 × 16 and 16 × 32. For source s = 0 for foreground or 1 for background, take bit c of (x + 5y + 7j + 3s) modulo 16 as the sign. Select a magnitude from (0,.5,2⁻²⁷,0,2⁻²⁴,.375,2⁻²⁵,1.125) by (y + 3c + s + 5j) modulo 8. Select each source in turn at F16 and F32 storage, leaving the other input at F32. Use seed 399023 + 47j. Store all four formats at the first size and F16 and F32 at the others. The sixteen sign masks distinguish the three RGB signs from all four channel signs, the first two signs and unconditional zero clearing. + +For a separate field around the smallest normal F32 value, use 16 × 32, 32 × 16 and 32² at seeds 404127 + 19j. Use the same eight graphs as the first comparison. Select channel words from `00000000 80000000 00000001 80000001 0071f5ab 80493874 007fffff 807fffff 00800000 80800000 00800001 80800001 00bce209 81d50c43 3f8c3793 c0666bbb`. Use index (7x + y + 5c + 7j) modulo 16 for foreground or (3x + 5y + 3c + 7j + 1) modulo 16 for background. Store all four formats at the first size and both floating formats at the others. With equal F32 inputs, all three flush stages are needed to reproduce every floating-output pixel at .25 and .6137. + +| Comparison | Renders | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Eight endpoint graphs, before correction | 56 | 3,072/3,072 · 0 | 3,072/3,072 · 0 | 4,726/7,168 · 0 | 10,234/13,312 · 0 | +| Eight endpoint graphs, corrected | 56 | 3,072/3,072 · 0 | 3,072/3,072 · 0 | 7,168/7,168 · 0 | 13,312/13,312 · 0 | +| Four endpoint SBS saves, opened in both applications | 28 | 1,536/1,536 · 0 | 1,536/1,536 · 0 | 3,584/3,584 · 0 | 6,656/6,656 · 0 | +| Four partial-opacity controls, before correction | 24 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 1,960/2,048 · 0 | 7,456/8,192 · 1.40129846e-45 | +| Four partial-opacity controls, corrected | 24 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 8,192/8,192 · 0 | +| Independent small magnitudes, four endpoint graphs | 32 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | +| Independent small magnitudes, four partial-opacity graphs | 32 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | +| Two small-magnitude SBS saves reopened in both applications | 16 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | +| Reopened .6137 same-precision control | 6 | 512/512 · 0 | 512/512 · 0 | 512/512 · 0 | 2,048/2,048 · 0 | + +The endpoint saves cover F32 background selection, F16 foreground selection, a foreground stored in F32 and a background stored in F16. Each saved reference buffer matched its original. Both input processors matched at every setting. The two additional saves cover foreground selection and weighting at .6137. On the original three F32 output sizes at each of the four partial opacities, the three-stage flush rule reproduces 8,192/8,192 pixels. Both the selected-input and subnormal regressions failed before their respective corrections and passed afterward. All 398 node release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly checks passed. + +### Stored products in pixel expressions and irradiance ray steps + +A straight-line pixel expression can assign a vector product to a variable and add it to several positions. For each component consumed only by additions, the evaluator now rounds the multiply and add together. Returning the stored blue component alongside the sum preserves the rounded blue product in both places. A subsequent assignment takes effect at the next read. The change applies to the shared expression evaluator. + +Use the original signed RGBA32F fields and seven settings from the [packed interpolation comparison](#packed-products-in-the-second-endpoint-of-a-pixel-interpolation). At each texel use (B,R,G,A) for the direction, A for the scale and (G,B,A,R) for the starting position. Compare the stored step, the starting position, one and eight direct additions, one, two and eight additions of the assigned step, the two-addition result with the stored blue component in alpha, and a reassignment to the starting position before the second addition. Repeat the one- and eight-addition graphs with a multiplication by literal one between the read and the add. At 64 × 32 in F32, the earlier evaluator matched 564, 420 and 367 of 2,048 pixels on the one-, two- and eight-addition assigned graphs. All three now match 2,048/2,048. + +For independent fields use 16 × 64, 64 × 16 and 32 × 32, with index j from zero. Let q = (x + width × y + 394123 + 53j + 713c) × 1597334677 + 3812015801 modulo 2³² for component c. Replace q with ((q XOR (q >> 16)) × 2246822519) modulo 2³². Use bit 13 for the sign, 123 + (q modulo 5) for the biased exponent, and bits 1 through 23 for the fraction. Use seed 394167 + 23j. Run one addition, eight additions, the observed blue and reassignment on all three F32 fields. Repeat the first in U8, U16 and F16. Save and reopen those first four graphs from the original set plus the eight-addition literal-one graph, then the eight-addition and blue readouts from the independent set. Both applications reproduced their originals in every saved comparison. + +| Comparison | Renders | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Eleven original expressions, before correction | 77 | 22,528/22,528 · 0 | 22,519/22,528 · 1 | 22,521/22,528 · 0.00000762939453 | 66,949/112,640 · 0.00000762939453 | +| Eleven original expressions, corrected | 77 | 22,528/22,528 · 0 | 22,528/22,528 · 0 | 22,528/22,528 · 0 | 112,640/112,640 · 0 | +| Four expressions on independent fields | 24 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 12,288/12,288 · 0 | +| Seven SBS saves reopened in both applications | 47 | 12,288/12,288 · 0 | 12,288/12,288 · 0 | 12,288/12,288 · 0 | 57,344/57,344 · 0 | + +To reproduce the remaining difference in [irradiance pass 395](#irradiance-with-a-connected-pass-index), use the changed 64² setting and read its first pixel processor. In a disposable save, route that processor to the graph output. The reference F16 image matched all 4,096 pixels of the original intermediate. The two applications match 4,094/4,096 in F16, maximum 0.00390625, and 3,023/4,096 in F32, maximum 0.000645160675. On row 20, return the eight light contributions separately. Summing the eight from the last back to the first reproduces all 64 summed pixels in each application. At x = 28 the third contribution differs in the emissive term. The environment term, emissive cosine and hit flag match across the row. + +Expose the direction, length, starting position and position after 0, 1, 4, 8 and 15 shadow calls. The direction, length and stored step each match 64/64. Starting with each application's first position, adding the rounded step reproduces all five MaterialCraft readouts. Rounding the direction times length together with each position reproduces all five reference readouts. At (28,20), sixteen advances yield hit Y = 0.648965240 in MaterialCraft and 0.648965716 in the reference. The corresponding emissive V coordinates are 0.0906677246 and 0.0906674862. The change moves one fractional filter weight across a rounding boundary. Independently weighting the same stored U16 texels reproduces all 64 samples in each application. + +For a separate called-function comparison at 64 × 32 F32, place the assignment in the pixel expression or in a function with a connected field argument. In each scope, try reading the step inside an addition helper, renaming the variable, returning an assigned result, reassigning the step after the addition, updating the caller's position with and without an extra argument, passing a wired step into that update, and passing both operands explicitly. Give each function and node a unique identifier in its package. For all 16 controls the reference agrees with a single rounded multiply-add at 32,768/32,768 pixels. MaterialCraft matches 9,024/32,768, maximum 0.000000476837158. Carrying the factors into nested calls remains open. Root 395 retains its previous inventory status. + +The regression failed on the previous build and passed after the evaluator change. The 49 earlier product, quotient and interpolation graphs retained 1,288,192/1,288,192 exact pixels in 307 renders. All 395 release node tests, formatting, strict workspace Clippy, dependency layers and WebAssembly checks passed. + +## 2026-11-22 root comparisons + +### Packed products in the second endpoint of a pixel interpolation + +At 64² in the [world-position plane light](#panoramic-line-light-and-horizon-across-the-seam), separately returning the two endpoints and scalar weight from the final interpolation gave 4,096/4,096 exact F32 pixels at each readout. The interpolated output matched 4,084/4,096. Its second endpoint packs RGB multiplied by exposure alongside a constant alpha. At (21,3), rounding the blue product before subtracting the first endpoint gives output bits `3ebaed06`. Combining that product with the subtraction gives the measured `3ebaed07`. This calculation reproduced all 4,096 pixels. The shared pixel evaluator now carries the factors of each eligible component through packing into the interpolation. A separate read of a product lane preserves its rounded value. If the interpolation and a subsequent add both consume the product, each can fuse it with its own addend. + +For the independent graphs, sample one original RGBA32F field at texel centers. For (width,height) = (64,32), (32,64), (64,64), number the fields j from zero. For channel c from zero let q be ((x + width × y) × (747796405 + 2c) + 2891336453 + 19998479c + 78571j) modulo 2³². Use bit 13 of q for the sign, 125 + ((q >> 25) modulo 3) for the biased F32 exponent, and bits 1 through 23 for the fraction. Use seed 379131 + 41j. Run F32 at all sizes, add U8, U16 and F16 at 64 × 32, then repeat its F32 setting. + +Use first endpoint (B,R,A,G), second endpoint (R×A,G×A,B×A,.625) and weight G. Test this graph, reversed endpoints, and identical packed endpoints. Also test returning the independently rounded blue product alongside the mixed RGB, adding the second endpoint to the mix, selecting lanes YWZX from the second endpoint, dividing RGB by A, using RGBA×A directly, and packing (R×A,G×A,R×B,B×G). At (11,0), the second-endpoint case gives RGB bits `bd551682 bef1e18c bec17c27`. Returning the blue product changes just the mixed blue to `bec17c28`. The separate product reads `3f1cb4a3`. + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Nine original graphs, previous cook | 18,432/18,432 · 0 | 18,428/18,432 · 1 | 18,431/18,432 · 3.81469727e-06 | 64,959/92,160 · 9.53674316e-07 | +| Same nine graphs, corrected cook | 18,432/18,432 · 0 | 18,432/18,432 · 0 | 18,432/18,432 · 0 | 92,160/92,160 · 0 | +| Five MaterialCraft saves, opened in both applications | 10,240/10,240 · 0 | 10,240/10,240 · 0 | 10,240/10,240 · 0 | 51,200/51,200 · 0 | + +The five saves cover the ordinary and reversed endpoints, the independently returned blue lane, the subsequent add and the quotient. Every saved reference buffer reproduced its original. Two additional probes deliberately connected a float4 to the weight port. The desktop reported that port as scalar and the incoming connection as float4. At 64 × 32 in F32 both reference outputs equaled the first endpoint, 4,096/4,096 pixels. MaterialCraft evaluated component weights at those connections. Across the 14 format and size comparisons those two graphs matched 214/32,768 pixels, with maxima of 255 U8 levels, 65,535 U16 levels, 10.1123047 F16 and 10.1180855 F32. These mismatched port types remain a separate difference. + +Repeat the [22 earlier plane-light settings](#nadir-patch-after-reopening-its-linked-shape-package). For four additional geometries use (output width, output height, input width, input height) = (32,16,32,16), (16,32,16,32), (64,32,32,16) and (32,64,64,32). For geometry j use seed 380233 + 47j. Number the three input identifiers m alphabetically and components c from zero. Store each channel as ((41x + 73y + 11xy + 157m + 61c + 3cx + seed) modulo 1021)/1024 in F32. Use channel zero for the pattern image. Keep the first geometry at defaults. For the others use position modes 2, 1, 0 and patterns 4, 1, 3 respectively. Set world position (−.875,.34375,1.125), UV position (.328125,.203125), scale .6875, size (.75,1.25), rotation (.046875,−.09375,.171875), color mode 2 and exposure 1.3125. Enable the background input. Enable ground clipping and the grid on geometry two only. Use F32 on all four geometries and all four formats on geometries zero and two. Reopen a normal MaterialCraft SBS save at these ten settings and the four earlier plane-space settings. + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| 22 earlier whole-root settings | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 175,360/175,360 · 0 | +| 10 independent rectangular settings | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 5,120/5,120 · 0 | +| 14 whole-root reopens in both applications | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | 33,792/33,792 · 0 | + +Panorama Plane Light matched **212,736/212,736** original pixels across 32 settings and **41,472/41,472** reopened pixels. Both applications reproduced their original buffers after reopening. The packed-lane regression failed on the previous build and passed with the fix. All 394 node release tests passed, as did formatting, strict workspace Clippy, dependency layers and WebAssembly. + +The 49 earlier graphs for returned vectors, shared product pairs and scalar quotients retained 1,288,192/1,288,192 exact pixels across 307 renders. [Returned-vector probes](#pixel-products-carried-through-vector-lanes-and-calls) · [Quotient and interpolation probes](#pixel-quotients-and-volume-mask-interpolation) + +### Whole and reopened eighth specular passes + +Use the [26 original specular settings](#eighth-raytraced-specular-passes), including the default at 128² and 256², the changed 128² render and seed 42 at 128². Repeat the [12 independent rectangular fields](#rectangular-inputs-and-remaining-half-float-pixels-in-the-eighth-specular-passes) at 8 × 4 through 8 × 16. Each pixel counts only if all four stored channels match. + +Save the original graph with MaterialCraft, reopen it in both applications and compare the four rectangular handoff cases with their originals. Include a 128² F16 reopen, using the changed settings for pass 396 or defaults for pass 408. Each application reproduced its original pixels at the five settings reported below. + +For the [five environment and material controls](#environment-and-intermediate-precision-in-the-eighth-specular-passes), select F32 storage for the first connected pixel processor and keep the original output wiring. Read both outputs in the same cook. Pass 408 returns F16 at the output. Pass 396 returns F32 at the output, and all 81,920 reference pixels in its five controls contain values exactly representable in F16. Keep the original eight input fields, then change only the environment to black, the environment to the coordinate field, emissive to black, or specular and roughness to black. The general [reciprocal arithmetic correction](#reciprocal-division-through-pixel-function-calls) applies to these graphs. All package edits for intermediate readouts used disposable measurement copies. + +| Pass | Comparison | Settings | U8 exact / total | U16 exact / total | F16 exact / total | F32 exact / total | Maximum error | +|---:|---|---:|---:|---:|---:|---:|---:| +| 408 | Original matrix | 26 | 5,136/5,136 | 5,136/5,136 | 119,888/119,888 | 12,180/12,180 | 0 | +| 408 | Independent rectangular fields | 12 | 160/160 | 160/160 | 320/320 | 320/320 | 0 | +| 408 | Saved SBS, opened in both applications | 5 | 128/128 | 32/32 | 16,416/16,416 | 128/128 | 0 | +| 408 | Environment and material controls, full graph | 5 | — | — | 81,920/81,920 | — | 0 | +| 408 | Same five renders, first pixel processor | 5 | — | — | — | 81,920/81,920 | 0 | + +### Reciprocal division through pixel function calls + +The two eighth specular passes divide a lighting term by the Z component of a normalized direction. Returning the environment lookup alone matched the 128-pixel scanline through (62,57) of the second pass. Returning the scalar lighting quotient exposed a rounding difference. Both operands matched at that pixel. In a separate original graph, the pixel expression `A / (1 / B)` reproduced A × B throughout the signed field. At (1,0) the inputs have F32 words `40763400` and `3f68c2ba`. A separate read of the inner reciprocal returns `3f8cc7a2`. The outer quotient returns `405fda66`. Supplying the one from a sampled channel returns `405fda65`. The latter control matched before the change. + +The pixel evaluator now retains the original factor through scalar calls, vector construction, component selection and multiplication by a literal unit lane. Other readers of the reciprocal receive its rounded value. A sole downstream add or subtract can contract with the resulting product. The original operands still evaluate in graph order. The two measured roots use their existing SBS operations. Loop-carried reciprocal factors remain unmeasured. + +Use a nearest-filtered four-channel F32 procedural input. Number pixels in row-major order from zero and number the fields j = 0, 1, 2. Use sizes 64 × 32, 32 × 64 and 64², with seeds 364801 + 31j. Let m be the low 32 bits of 747796405i + 2891336453 + 997j. Red is ((1103515245i + 53719 + 57j) mod 65521)/8192 − 4. For green, combine the low 23 bits of m with exponent field 126 + ((m >> 22) mod 3). In field two use 1 + (m mod 131071)/16777216 instead. Blue is (((m >> 8) mod 257) − 128)/512. Alpha is one. At the first size, render in F32, U8, U16 and F16. Render the other sizes in F32 and return to the original F32 setting. + +For the direct graphs, pack the quotient, its denominator, the underlying factor and red into RGBA. Compare ordinary division with a unit reciprocal, a connected Dot inside the expression, multiplication by one or two, a sampled numerator of one, a squared or square-root divisor, two equivalent vector-pack controls, normalization with Z equal to one or one plus blue, a reciprocal numerator of .625, and the sum of two quotients. For the call graphs, move the inverse, the division or both into reusable functions. Normalize (blue, green, Z) in a function and pass its Z lane to a scalar division function. Compare literal Z against sampled alpha. Also add two called quotients, add or subtract blue, and expose an additional read of the quotient in the sum graph. At 64 × 32 the sole-read sum matched all 2,048 fused results. The shared sum matched all 2,048 separately rounded results. For the two called quotients, contracting the left product matched all 2,048 pixels. + +| Graphs and comparisons | Renders | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| 14 direct graphs, previous cook | 98 | 28,672/28,672 · 0 | 28,670/28,672 · 1 | 28,671/28,672 · 0.001953125 | 130,734/143,360 · 3.81469726562e-06 | +| 14 direct graphs, corrected cook | 98 | 28,672/28,672 · 0 | 28,672/28,672 · 0 | 28,672/28,672 · 0 | 143,360/143,360 · 0 | +| 9 call and arithmetic controls, previous cook | 63 | 18,432/18,432 · 0 | 18,430/18,432 · 1 | 18,429/18,432 · 0.00390625 | 81,058/92,160 · 1.90734863281e-06 | +| 9 call and arithmetic controls, corrected cook | 63 | 18,432/18,432 · 0 | 18,432/18,432 · 0 | 18,432/18,432 · 0 | 92,160/92,160 · 0 | +| 8 saved graphs reopened in both applications | 56 | 16,384/16,384 · 0 | 16,384/16,384 · 0 | 16,384/16,384 · 0 | 81,920/81,920 · 0 | +| 3 signed boundary controls | 18 | 1,536/1,536 · 0 | 1,536/1,536 · 0 | 1,536/1,536 · 0 | 4,608/4,608 · 0 | + +The saved graphs cover the simple reciprocal, packed lane, sampled one, two reads, both operations in calls, both normalization inputs and the sum of two calls. The reference also reproduced its original 131,072 pixels after reopening. For the boundary controls use the quotient, a direct product and a sampled-unit numerator at 32 × 16 and 16 × 32. Cycle green through both signs of the F32 magnitudes `00000000 00000001 007fffff 00800000 00800001 3f68c2ba 3f800000 3f801001 40000000 7d7fffff 7e800000 7f000000 7f7fffff`. Select the magnitude at index (i + 5j) mod 13 and flip its sign on alternate blocks of 13 pixels. Select red from +0, −0, 1, −1, 1.53247, −.8125, .0003771 and 259.3 at index (floor(i/26) + j) mod 8. Return self-equality, equality to zero, less than zero and the value clamped to [−256,256]. Use seeds 367811 and 367842, all four formats at the first size, F32 at the second, then repeat the first F32 setting. The reference quotient and product also matched one another across all 3,072 boundary pixels. + +For the specular controls, retain the initial assignments and the first n contributions for n = 0 through 8. Preserve the original normalization after the sum. At 128² read every pixel of row 36 in pass 396 with the changed controls, and row 57 in pass 408 with the default controls. Both full eight-contribution reference buffers reproduced the original intermediate, 16,384/16,384 per graph. The corrected scanlines match 1,152/1,152 pixels per graph over the nine prefixes. The previous counts were 1,064/1,152, maximum 5.96046447754e−8, and 1,075/1,152, maximum 1.19209289551e−7, respectively. The changed 128² F16 root 396 scores **16,384/16,384 · 0**. The default 128² F16 root 408 scores **16,384/16,384 · 0**. The earlier full-size matrix includes additional seeds and 256² renders. [Original fields and half-precision differences](#rectangular-inputs-and-remaining-half-float-pixels-in-the-eighth-specular-passes) + +### Branch offsets, center culling and two dense spot graphs + +An empty Quadrant can sit outside the tiling region and still have a visible descendant. In an original grayscale graph, route slots 1 then 2 through two empty Quadrants to one additive square. Give the square luminosity .75 and size (.75,.75) in its local frame. Move the outer branch horizontally by d. At the square either subtract d as a branch offset, subtract d as a pattern offset, or leave its offset zero. Test each graph with center culling off and on and with wrapping off and on along both axes. Keep the unit render and tiling regions. + +Use (width, height, format, d) = (32,16,F32,0), (32,16,F32,1.25), (32,16,F32,−1.5), (16,32,U16,5.25), (32,16,U8,1.25), (64,32,F16,−1.5) and the first setting again. For setting j starting at zero use seed 371092 + 23j and restore the original seed on the last request. Both offsets that bring the square back draw 18 pixels at 32 × 16 and 72 at 64 × 32, including with culling enabled. Without the return offset, culling removes the displaced squares. With culling disabled, wrapping brings them back into view. + +| Comparison | Renders | U8 exact / total | U16 exact / total | F16 exact / total | F32 exact / total | Maximum error | +|---|---:|---:|---:|---:|---:|---:| +| Twelve original graphs | 84 | 6,144/6,144 | 6,144/6,144 | 24,576/24,576 | 24,576/24,576 | 0 | +| Three graphs saved in MaterialCraft and reopened in both applications | 21 | 1,536/1,536 | 1,536/1,536 | 6,144/6,144 | 6,144/6,144 | 0 | + +The reopens use the returning branch offset and pattern offset, both with culling on and wrapping off, and the uncorrected offset with culling and wrapping on. Each saved reference buffer reproduced the original. Skipping a subtree solely because an ancestor lies outside the frame would lose the measured returning squares. [Position, depth and iteration](#position-depth-and-iteration-in-pattern-expressions) + +For the two separately packaged BNW Spots 3 roots, use the [explicit renderer worker procedure](#patterns-with-an-explicit-reference-worker-count) on a normal MaterialCraft save. Compare the desktop original on one eligible processor to the saved graph rendered with one or eight workers. At 16² use defaults and seed zero in all four formats. At 64² use scale 2, disorder .37 and seed 42 in all four formats. For version 2 also use disorder speed .6, anisotropy .3, angle .125 and tile offset (.17,.29). At 64 × 16 use F32, scale 2, disorder .03125, expansion on and seed 42. In version 2 set speed and anisotropy to .03125, angle to −.21875 and tile offset to (−.3125,.37890625). Include the 256² default F16 at seed zero. Repeat the three F32 settings in each worker configuration. + +| Root | Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---:|---|---:|---:|---:|---:| +| 238 | Desktop vs. one worker | 4,352/4,352 · 0 | 4,351/4,352 · 1 | 42,614/69,888 · 0.00048828125 | 5,373/5,376 · 1.06990337372e-05 | +| 238 | Desktop vs. eight workers | 4,352/4,352 · 0 | 4,352/4,352 · 0 | 42,612/69,888 · 0.00048828125 | 5,372/5,376 · 1.06990337372e-05 | +| 238 | One vs. eight workers | 4,352/4,352 · 0 | 4,351/4,352 · 1 | 69,882/69,888 · 0.00048828125 | 5,373/5,376 · 1.06692314148e-05 | +| 238 | One worker, repeated | — | — | — | 5,376/5,376 · 0 | +| 238 | Eight workers, repeated | — | — | — | 5,374/5,376 · 1.06692314148e-05 | +| 239 | Desktop vs. one worker | 4,352/4,352 · 0 | 4,352/4,352 · 0 | 69,887/69,888 · 0.0001220703125 | 4,855/5,376 · 1.49011611938e-07 | +| 239 | Desktop vs. eight workers | 4,352/4,352 · 0 | 4,351/4,352 · 1 | 69,887/69,888 · 0.000244140625 | 4,614/5,376 · 1.78813934326e-07 | +| 239 | One vs. eight workers | 4,352/4,352 · 0 | 4,351/4,352 · 1 | 69,886/69,888 · 0.000244140625 | 4,730/5,376 · 1.78813934326e-07 | +| 239 | One worker, repeated | — | — | — | 5,376/5,376 · 0 | +| 239 | Eight workers, repeated | — | — | — | 4,677/5,376 · 1.78813934326e-07 | + +Opening the original SBS, its MaterialCraft save and the source prepared for publication in the desktop reproduced the same 17,408/17,408 pixels across the two roots, at 16² and 64² in F16 and F32. The maximum error for each pair was zero. For root 238, publishing that source and rendering with one worker gave 140/256 and 2,586/4,096 exact F16 pixels against the desktop. Of the differing desktop values, 1,592 were one half-float step lower and 34 were two steps lower. The maximum error was .00048828125. Truncating the standalone F32 output toward zero to F16 reproduced all 4,352 standalone F16 values. The corresponding 4,352 F16 pixels of root 239 were identical between the two renderers. + +Both the production cook and ordinary Quadrant traversal matched the one-worker reference on all 4,352 F32 pixels of the 16² and 64² square settings for root 238. At 64² they matched 4,093/4,096 desktop pixels with maximum .0000106990337. For root 239, both cooks matched 256/256 at 16² against the one-worker reference and 232/256 against the desktop, maximum 5.96046448e−8. Both reached the execution budget at 64² in root 239 and at 64 × 16 in both roots. All three F32 reference requests completed for both worker counts. [Previous complete-root measurements](#whole-root-precision-and-saved-comparisons-for-the-three-neighboring-spot-graphs) + +### Patterns with an explicit reference worker count + +The desktop process affinity and the worker count chosen by the standalone renderer select different execution conditions. For the latter, use Direct3D 11, publish the normally saved SBS with optimization disabled, expose random seed, and inherit the graph seed from the render request. Set the final filter to the desired storage precision before publishing each of the four variants. Request the graph output as a 32-bit floating-point TIFF and convert back to its declared storage for comparison. Integer maxima are stored levels. For floating-point images compare component bit patterns and report absolute error. [Overlap repeatability and desktop property inspection](#worker-count-and-repeatability-of-overlapping-patterns) + +For the isolated BNW Spots 1 generator, render at a 256² parent size, yielding a 128² generator. Use the default disorder with seed zero, .1875 with seed 1 and .640625 with seed 135071. Replay the 16,384 emitted MaterialCraft stamp contributions for each buffer, using one F32 addition per contribution. Both replays use the same positions and contributions. Only the order of addition changes. [Sixteen grandchild groups and independent markers](#compositing-complete-seven-level-additive-quadrant-trees) + +| Reference, three F32 buffers | Ordinary Quadrant traversal · exact / total · max | Measured desktop group order · exact / total · max | +|---|---:|---:| +| Desktop with one eligible host processor | 47,844/49,152 · 2.98023224e-08 | 49,152/49,152 · 0 | +| Direct3D 11 with one worker | 49,152/49,152 · 0 | 47,844/49,152 · 2.98023224e-08 | +| SSE2 with one worker | 15,227/49,152 · 1.57803297e-05 | 15,224/49,152 · 1.57654285e-05 | +| Vulkan with one worker | 33,042/49,152 · 1.1920929e-07 | 32,763/49,152 · 1.1920929e-07 | + +For the isolated final Noise Clouds 1 pattern stage, repeat its eight-level tree two, three, four or five times. Disconnect the background, use black, and disable tiling. For two and four trees use four F32 requests in order. Start at 64² with defaults and seed zero. Use 128 × 64 with scale 2, disorder .46875, non-square expansion off and seed 337607. Use 64 × 128 with scale 1, disorder .71875, expansion on and seed 337649. Return to the first request. For three and five trees add 344023 to each seed. The current MaterialCraft cook uses ordinary traversal for these repeated trees. [Original tree controls](#worker-count-and-repeatability-of-overlapping-patterns) + +| Trees | MaterialCraft vs. 1 worker | MaterialCraft vs. 2 workers | MaterialCraft vs. 4 workers | MaterialCraft vs. 8 workers | 1 worker, second vs. first | 8 workers, second vs. first | +|---:|---:|---:|---:|---:|---:|---:| +| 2 | 24,576/24,576 · 0 | 21,261/24,576 · 1.1920929e-07 | 20,024/24,576 · 1.78813934e-07 | 17,806/24,576 · 1.78813934e-07 | 24,576/24,576 · 0 | 23,821/24,576 · 8.94069672e-08 | +| 3 | 24,576/24,576 · 0 | 20,772/24,576 · 2.38418579e-07 | 19,484/24,576 · 2.38418579e-07 | 17,258/24,576 · 2.38418579e-07 | 24,576/24,576 · 0 | 24,353/24,576 · 1.1920929e-07 | +| 4 | 24,576/24,576 · 0 | 20,487/24,576 · 2.38418579e-07 | 19,444/24,576 · 2.38418579e-07 | 17,137/24,576 · 2.38418579e-07 | 24,576/24,576 · 0 | 24,576/24,576 · 0 | +| 5 | 24,576/24,576 · 0 | 20,248/24,576 · 3.57627869e-07 | 18,651/24,576 · 4.76837158e-07 | 16,971/24,576 · 2.38418579e-07 | 24,576/24,576 · 0 | 23,342/24,576 · 2.38418579e-07 | + +For the whole graphs, compare the current MaterialCraft release cook and a diagnostic cook that submits grayscale procedural stamps directly in Quadrant traversal order. The diagnostic uses the same traversal for every graph, with the same expressions, seed evolution, stamp samples, compositing and downstream filters. The five comparisons cover 24 settings each. The desktop column uses the original graph with process affinity restricted to one eligible host processor. The standalone columns use the saved graph and an explicit worker count. [Existing spot graph settings](#whole-root-precision-and-saved-comparisons-for-the-three-neighboring-spot-graphs) · [Cloud graph settings](#repeated-cloud-renders-and-two-generator-texels) + +| Whole graph and comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| BNW Spots 1 · MaterialCraft vs. desktop | 82,432/82,432 · 0 | 82,432/82,432 · 0 | 82,432/82,432 · 0 | 81,152/81,152 · 0 | +| BNW Spots 1 · MaterialCraft vs. 1 worker | 82,432/82,432 · 0 | 82,418/82,432 · 2 | 82,431/82,432 · 0.000244140625 | 81,146/81,152 · 2.16364861e-05 | +| BNW Spots 1 · MaterialCraft vs. 8 workers | 82,432/82,432 · 0 | 82,432/82,432 · 0 | 82,432/82,432 · 0 | 81,152/81,152 · 0 | +| BNW Spots 1 · ordinary traversal vs. 1 worker | 82,432/82,432 · 0 | 82,432/82,432 · 0 | 82,432/82,432 · 0 | 81,152/81,152 · 0 | +| BNW Spots 1 · ordinary traversal vs. 8 workers | 82,432/82,432 · 0 | 82,418/82,432 · 2 | 82,431/82,432 · 0.000244140625 | 81,146/81,152 · 2.16364861e-05 | +| BNW Spots 1 · 1 worker repeat | 8,704/8,704 · 0 | 2,048/2,048 · 0 | 8,704/8,704 · 0 | 2,048/2,048 · 0 | +| BNW Spots 1 · 8 worker repeat | 8,704/8,704 · 0 | 2,048/2,048 · 0 | 8,704/8,704 · 0 | 2,048/2,048 · 0 | +| Clouds 1 · MaterialCraft vs. desktop | 92,672/92,672 · 0 | 113,152/113,152 · 0 | 92,672/92,672 · 0 | 113,152/113,152 · 0 | +| Clouds 1 · MaterialCraft vs. 1 worker | 92,672/92,672 · 0 | 113,145/113,152 · 4 | 92,672/92,672 · 0 | 113,145/113,152 · 5.57303429e-05 | +| Clouds 1 · MaterialCraft vs. 8 workers | 92,672/92,672 · 0 | 113,147/113,152 · 7 | 92,672/92,672 · 0 | 113,149/113,152 · 5.55515289e-05 | +| Clouds 1 · ordinary traversal vs. 1 worker | 92,672/92,672 · 0 | 113,152/113,152 · 0 | 92,672/92,672 · 0 | 113,152/113,152 · 0 | +| Clouds 1 · ordinary traversal vs. 8 workers | 92,672/92,672 · 0 | 113,144/113,152 · 7 | 92,672/92,672 · 0 | 113,146/113,152 · 5.57303429e-05 | +| Clouds 1 · 1 worker repeat | 16,896/16,896 · 0 | 4,096/4,096 · 0 | 16,896/16,896 · 0 | 4,096/4,096 · 0 | +| Clouds 1 · 8 worker repeat | 16,896/16,896 · 0 | 4,096/4,096 · 0 | 16,896/16,896 · 0 | 4,096/4,096 · 0 | +| Clouds 2 · MaterialCraft vs. desktop | 92,672/92,672 · 0 | 113,152/113,152 · 0 | 92,672/92,672 · 0 | 113,152/113,152 · 0 | +| Clouds 2 · MaterialCraft vs. 1 worker | 92,672/92,672 · 0 | 113,134/113,152 · 2 | 92,670/92,672 · 0.00048828125 | 113,134/113,152 · 2.29477882e-05 | +| Clouds 2 · MaterialCraft vs. 8 workers | 92,672/92,672 · 0 | 113,146/113,152 · 2 | 92,672/92,672 · 0 | 113,149/113,152 · 2.29179859e-05 | +| Clouds 2 · ordinary traversal vs. 1 worker | 92,672/92,672 · 0 | 113,152/113,152 · 0 | 92,672/92,672 · 0 | 113,152/113,152 · 0 | +| Clouds 2 · ordinary traversal vs. 8 workers | 92,672/92,672 · 0 | 113,136/113,152 · 2 | 92,670/92,672 · 0.00048828125 | 113,137/113,152 · 2.29477882e-05 | +| Clouds 2 · 1 worker repeat | 16,896/16,896 · 0 | 4,096/4,096 · 0 | 16,896/16,896 · 0 | 4,096/4,096 · 0 | +| Clouds 2 · 8 worker repeat | 16,896/16,896 · 0 | 4,096/4,096 · 0 | 16,896/16,896 · 0 | 4,096/4,096 · 0 | +| Noise BNW Spots 1 · MaterialCraft vs. desktop | 75,008/75,008 · 0 | 93,410/93,440 · 1 | 75,007/75,008 · 0.00048828125 | 75,725/81,152 · 2.38418579e-07 | +| Noise BNW Spots 1 · MaterialCraft vs. 1 worker | 75,007/75,008 · 1 | 93,374/93,440 · 1 | 75,006/75,008 · 0.000244140625 | 50,809/81,152 · 1.1920929e-07 | +| Noise BNW Spots 1 · MaterialCraft vs. 8 workers | 75,007/75,008 · 1 | 93,420/93,440 · 1 | 75,005/75,008 · 0.00048828125 | 75,567/81,152 · 1.78813934e-07 | +| Noise BNW Spots 1 · ordinary traversal vs. 1 worker | 75,008/75,008 · 0 | 93,440/93,440 · 0 | 75,008/75,008 · 0 | 81,152/81,152 · 0 | +| Noise BNW Spots 1 · ordinary traversal vs. 8 workers | 75,006/75,008 · 1 | 93,360/93,440 · 1 | 75,005/75,008 · 0.00048828125 | 48,724/81,152 · 2.38418579e-07 | +| Noise BNW Spots 1 · 1 worker repeat | 4,352/4,352 · 0 | 2,048/2,048 · 0 | 4,352/4,352 · 0 | 2,048/2,048 · 0 | +| Noise BNW Spots 1 · 8 worker repeat | 4,351/4,352 · 1 | 2,047/2,048 · 1 | 4,351/4,352 · 0.000244140625 | 1,806/2,048 · 1.1920929e-07 | +| Noise BNW Spots 1 v2 · MaterialCraft vs. desktop | 89,344/89,344 · 0 | 81,151/81,152 · 1 | 75,004/75,008 · 0.00048828125 | 80,898/81,152 · 1.1920929e-07 | +| Noise BNW Spots 1 v2 · MaterialCraft vs. 1 worker | 89,344/89,344 · 0 | 81,152/81,152 · 0 | 75,008/75,008 · 0 | 81,152/81,152 · 0 | +| Noise BNW Spots 1 v2 · MaterialCraft vs. 8 workers | 89,344/89,344 · 0 | 81,152/81,152 · 0 | 75,007/75,008 · 0.00048828125 | 80,892/81,152 · 1.1920929e-07 | +| Noise BNW Spots 1 v2 · ordinary traversal vs. 1 worker | 89,344/89,344 · 0 | 81,152/81,152 · 0 | 75,008/75,008 · 0 | 81,152/81,152 · 0 | +| Noise BNW Spots 1 v2 · ordinary traversal vs. 8 workers | 89,344/89,344 · 0 | 81,152/81,152 · 0 | 75,007/75,008 · 0.00048828125 | 80,892/81,152 · 1.1920929e-07 | +| Noise BNW Spots 1 v2 · 1 worker repeat | 16,640/16,640 · 0 | 2,048/2,048 · 0 | 4,352/4,352 · 0 | 2,048/2,048 · 0 | +| Noise BNW Spots 1 v2 · 8 worker repeat | 16,640/16,640 · 0 | 2,048/2,048 · 0 | 4,352/4,352 · 0 | 1,911/2,048 · 5.96046448e-08 | + +The traversal diagnostic matched **1,803,008/1,803,008** complete output pixels with one reference worker. The current release matched **1,797,291/1,803,008** against the desktop. The repeated standalone settings used format order U8, U16, F16 and F32 and the positions 1, 5, 9, 13, 17 and 21 in the combined 24-request series. Eight-worker repeat differences are present in the table. Renderer-specific matches and diagnostic results leave the five roots in progress. + +The table gives the six requests in order for each format. A setting number refers to the dimensions, seed and exposed values immediately below. Omitted parameters use the graph default. Every graph uses its original procedural inputs. + +| Graph | U8 | U16 | F16 | F32 | +|---|---|---|---|---| +| BNW Spots 1 | 1, 2, 3, 4, 5, 6 | 1, 2, 7, 4, 8, 6 | 1, 2, 3, 9, 5, 6 | 10, 11, 2, 12, 13, 6 | +| Clouds 1 | 1, 14, 15, 16, 17, 18 | 1, 14, 19, 20, 21, 18 | 1, 14, 15, 16, 17, 18 | 1, 14, 19, 20, 21, 18 | +| Clouds 2 | 1, 22, 23, 24, 25, 26 | 1, 22, 27, 28, 29, 26 | 1, 22, 23, 24, 25, 26 | 1, 22, 27, 28, 29, 26 | +| Noise BNW Spots 1 | 30, 31, 32, 33, 34, 35 | 30, 36, 33, 37, 38, 39 | 30, 31, 32, 33, 34, 35 | 30, 31, 40, 34, 41, 39 | +| Noise BNW Spots 1 v2 | 30, 42, 43, 44, 45, 35 | 30, 42, 43, 46, 47, 48 | 30, 42, 49, 50, 46, 35 | 30, 42, 49, 46, 47, 48 | + +| Setting | Width × height | Seed | Changed parameters | +|---:|---:|---:|---| +| 1 | 16 × 32 | 0 | Defaults | +| 2 | 32 × 64 | 9707 | disorder 0.15625 | +| 3 | 64 × 32 | 371994 | disorder 0.5625 | +| 4 | 64 × 64 | 223 | disorder 0.4375 | +| 5 | 64 × 128 | 349184 | disorder 0.21875 | +| 6 | 256 × 256 | 372421 | disorder 0.96875 | +| 7 | 32 × 64 | 372055 | disorder 0.875 | +| 8 | 128 × 64 | 372177 | disorder 1 | +| 9 | 64 × 64 | 349122 | disorder 0.421875 | +| 10 | 16 × 16 | 83 | Defaults | +| 11 | 32 × 32 | 8852 | Defaults | +| 12 | 32 × 128 | 9712 | disorder 0.84375 | +| 13 | 64 × 128 | 372116 | disorder 0 | +| 14 | 32 × 64 | 382191 | disorder 0.53125 | +| 15 | 64 × 64 | 382232 | Defaults | +| 16 | 64 × 64 | 42 | disorder 0.4 | +| 17 | 256 × 64 | 382355 | disorder 0.3984375 | +| 18 | 512 × 128 | 382478 | disorder 0.671875 | +| 19 | 128 × 32 | 382273 | disorder 0.875 | +| 20 | 64 × 128 | 382314 | disorder 1 | +| 21 | 128 × 256 | 382396 | disorder 0.921875 | +| 22 | 32 × 64 | 382192 | Defaults | +| 23 | 64 × 64 | 382233 | Defaults | +| 24 | 64 × 64 | 42 | Defaults | +| 25 | 256 × 64 | 382356 | Defaults | +| 26 | 512 × 128 | 382479 | Defaults | +| 27 | 128 × 32 | 382274 | Defaults | +| 28 | 64 × 128 | 382315 | Defaults | +| 29 | 128 × 256 | 382397 | Defaults | +| 30 | 16 × 16 | 0 | Defaults | +| 31 | 32 × 32 | 113 | disorder 0.37, roughness 0.6, scale 2 | +| 32 | 32 × 64 | 456747 | disorder 0.84375, roughness 1, scale 2 | +| 33 | 32 × 64 | 194489 | disorder 0.1875, non square expansion true, roughness 0.1875, scale 1 | +| 34 | 64 × 64 | 42 | disorder 0.37, roughness 0.6, scale 2 | +| 35 | 256 × 256 | 0 | Defaults | +| 36 | 64 × 16 | 42 | disorder 0.03125, non square expansion true, roughness 0.03125, scale 2 | +| 37 | 128 × 64 | 456809 | disorder 0.953125, roughness 0.96875, scale 2 | +| 38 | 128 × 128 | 42 | Defaults | +| 39 | 512 × 128 | 411930 | disorder 0.09375, non square expansion true, roughness 0.09375, scale 1 | +| 40 | 64 × 32 | 194442 | disorder 0.34375, non square expansion true, roughness 0.34375, scale 3 | +| 41 | 64 × 128 | 411686 | disorder 0.1875, non square expansion true, roughness 0.1875, scale 1 | +| 42 | 32 × 32 | 113 | disorder 0.37, disorder anisotropy 0.185, disorder anisotropy angle -0.005, disorder speed 0.32375, roughness 0.6, scale 2, tile offset (0.0925,-0.04625) | +| 43 | 64 × 32 | 194473 | disorder 0.34375, disorder anisotropy 0.34375, disorder anisotropy angle 0.09375, disorder speed 0.34375, non square expansion true, roughness 0.34375, scale 3, tile offset (0,0.10546875) | +| 44 | 64 × 64 | 411571 | disorder 0.34375, disorder anisotropy 0.34375, disorder anisotropy angle 0.09375, disorder speed 0.34375, non square expansion true, roughness 0.34375, scale 3, tile offset (0,0.10546875) | +| 45 | 128 × 128 | 0 | Defaults | +| 46 | 64 × 64 | 42 | disorder 0.37, disorder anisotropy 0.3, disorder anisotropy angle 0.125, disorder speed 0.6, roughness 0.6, scale 2, tile offset (0.17,0.29) | +| 47 | 64 × 128 | 411693 | disorder 0.1875, disorder anisotropy 0.1875, disorder anisotropy angle -0.0625, disorder speed 0.1875, non square expansion true, roughness 0.1875, scale 1, tile offset (-0.15625,0.2421875) | +| 48 | 512 × 128 | 411937 | disorder 0.09375, disorder anisotropy 0.09375, disorder anisotropy angle -0.15625, disorder speed 0.09375, non square expansion true, roughness 0.09375, scale 1, tile offset (-0.25,0.32421875) | +| 49 | 32 × 64 | 456747 | disorder 0.84375, disorder anisotropy 0.421875, disorder anisotropy angle 0.46875, disorder speed 0.73828125, roughness 1, scale 2, tile offset (0.2109375,-0.10546875) | +| 50 | 32 × 64 | 194520 | disorder 0.1875, disorder anisotropy 0.1875, disorder anisotropy angle -0.0625, disorder speed 0.1875, non square expansion true, roughness 0.1875, scale 1, tile offset (-0.15625,0.2421875) | + +### Scalar Quadrant luminosity in saved packages + +A Quadrant accepts a scalar luminosity in MaterialCraft. Saving that value as a one-component literal swatch produced an SBS that the reference renderer could not compile. The native swatch takes four components. A single constant scalar function is also a valid property representation, and retains the scalar’s meaning in both grayscale and color. The writer now uses that representation for a scalar literal on a Quadrant. Existing four-component swatches and authored functions retain their representations. [Writer and regression](../crates/formats/src/sbs/pattern_graph.rs) + +Use one additive square covering the canvas with pattern size (4,4), zero roughness, opacity multiplier one and tiling off. Use black for the grayscale background and (.125,.25,.5,.375) for the color background. For each color mode and each luminosity in (.375,−.3125,1.5,0,1), compare three graphs. The first holds the scalar directly in MaterialCraft. The second uses a function with that scalar as its only constant. The third uses the literal swatch (.1875,.5,.8125,luminosity). Save each with the ordinary file command and reopen it. The earlier writer’s ten scalar saves were all rejected by the reference compiler. All ten corrected scalar saves, ten constant-function saves and ten swatch saves compiled. + +Render 16 × 8 F32, 8 × 16 U8, 32 × 16 U16 and 16 × 32 F16, then return to the original F32 setting. The seed is 352001 + 37i + 17j for zero-based luminosity and setting indices, with the original seed on return. For RGBA, count a matching pixel only when all four component bit patterns agree. + +| Comparison across both color modes | Renders | U8 exact / total | U16 exact / total | F16 exact / total | F32 exact / total | Maximum error | +|---|---:|---:|---:|---:|---:|---:| +| Original MaterialCraft scalar vs. the reference scalar expression | 50 | 1,280/1,280 | 5,120/5,120 | 5,120/5,120 | 2,560/2,560 | 0 | +| Corrected scalar save reopened in both applications | 50 | 1,280/1,280 | 5,120/5,120 | 5,120/5,120 | 2,560/2,560 | 0 | +| Reference scalar expression vs. the reopened scalar save | 50 | 1,280/1,280 | 5,120/5,120 | 5,120/5,120 | 2,560/2,560 | 0 | +| Authored constant expression, reopened in both applications | 50 | 1,280/1,280 | 5,120/5,120 | 5,120/5,120 | 2,560/2,560 | 0 | +| Authored literal swatch, reopened in both applications | 50 | 1,280/1,280 | 5,120/5,120 | 5,120/5,120 | 2,560/2,560 | 0 | + +The 549 tracked SBS packages contain 396 function-valued and 59 four-component literal Quadrant opacity properties. None contains a one-component literal in that field. This corrects saved user graphs while the measured root count stays at 475/546. The regression failed on the previous writer and passed after the change. All 127 format-crate release tests passed, along with formatting, strict workspace Clippy, dependency layers and the WebAssembly checks. + +### Position, depth and iteration in pattern expressions + +Iterate supplies the zero-based repetition number. Quadrant subdivision supplies the branch position, depth and extent. Expressions on descendants can read those values. A Switch or Iterate at the root read the starting position (.5,.5). After Quadrant slots 1 and 2, each read (.625,.375). An Iterate’s initial branch keeps the enclosing number and its repeated branch starts a new counter. [Nested counter measurements](#initial-branch-of-a-nested-pattern-iterator) + +Build a grayscale pattern with a black background, zero roughness, opacity multiplier one and tiling off. Follow the first d slots of (1,2,3,0,1) through empty Quadrants. At the end, draw one additive square of size (4 × 2ᵈ, 4 × 2ᵈ). For the Quadrant read the value in the square’s luminosity. For the control-node readouts, assign the value inside the Iterate count or Switch condition, return one or true, and read the assigned value in the child square. Set the outer count to two or four where indicated. At 16 × 8 in F32 these single-draw values were constant across the image. + +| Depth d | Horizontal position | Vertical position | Depth readout | Depth scale readout | +|---:|---:|---:|---:|---:| +| 0 | .5 | .5 | 0 | 1 | +| 1 | .75 | .25 | 1 | .5 | +| 2 | .625 | .375 | 2 | .25 | +| 3 | .6875 | .4375 | 3 | .125 | +| 5 | .671875 | .390625 | 5 | .03125 | + +Use 13 graphs. For a Quadrant use d = 0, 1, 2, 3 and 5, then d = 2 with two or four outer repetitions. For an Iterate and a Switch use d = 0 and 2, then d = 3 with two outer repetitions. Select the constant .375, `$depth`, `$depthpow2`, `$number`, X and Y of `$pos`, X and Y of `$size`, X and Y of `$sizelog2`, and `$time` in that order. Use seed 346181 + 13j for selector j starting at zero. Repeat the position-X readout at 8 × 16, then the depth-scale readout in U8, U16, F16 and F32 at 16 × 8. The unanimated time read zero. Image size and its base-two logarithm read (16,8) and (4,3). Outside a repetition the number read zero. + +| Comparison | Renders | U8 exact / total | U16 exact / total | F16 exact / total | F32 exact / total | Maximum error | +|---|---:|---:|---:|---:|---:|---:| +| Original, one eligible host processor | 208 | 1,664/1,664 | 1,664/1,664 | 1,664/1,664 | 21,632/21,632 | 0 | +| Original, eight eligible host processors | 64 | 512/512 | 512/512 | 512/512 | 6,656/6,656 | 0 | +| Reopened in both applications | 24 | 512/512 | — | — | 2,560/2,560 | 0 | +| Ancestor and emitting-node offsets | 35 | — | — | — | 4,480/4,480 | 0 | +| Direct predicates without an assignment | 104 | — | — | — | 13,312/13,312 | 0 | + +The eight-processor controls use the three depth-two node kinds and the four-repeat depth-two Quadrant. Save each in MaterialCraft and reopen every third selector case starting at zero. Each application also reproduced its original raw output in all 24 reopens. + +Apply a branch offset of (1.125,−.8125) at the root of the depth-two path. Quadrant, Iterate and Switch then read (1.75,−.4375). Moving the same offset to the emitting Quadrant itself left its position readout at (.625,.375). These five graphs use the constant, depth, depth scale, number and two position components at 16 × 8, then position X at 8 × 16. + +In the independent predicate graphs, compare the counter with −1, 0, 1, 2, 3 and 4. Set the square’s gain to one on equality and zero otherwise. Four outer repetitions produced (0,1,1,1,1,0). Two produced (0,1,1,0,0,0). For the two nested control nodes, use two outer repetitions at depth three. The Switch opens its drawing arm on equality. The inner Iterate emits three squares on equality and one otherwise. For position tests on both controls, compare each component directly with .125, .25, .375, .5, .625 and .75 at depths zero and two. The root Switch opened for the first three thresholds on either axis. At depth two it opened for the first four thresholds on X and the first two on Y. The Iterate chose three or one repetitions at the same boundaries. Use seed 181503 + 11j at 16 × 8, repeat threshold index two at 8 × 16 with seed 718201, and return to the first setting. The earlier measurements of the five Quadrant mode fields apply to their separate evaluation phase. [Mode-field measurements](#assignments-in-quadrant-mode-expressions) + +### Worker count and repeatability of overlapping patterns + +Desktop captures labeled one or eight processors in this inventory select the eligible host processors using process affinity. The standalone CPU renderer also has an explicit worker-count setting. These two controls produced different F32 buffers for the same original overlap graph. + +Repeat a complete four-child tree to depth eight either twice or four times. Start with white, use zero roughness, unit render and tiling regions and disable wrapping. Draw additive squares at depths seven and eight. In tree N−1 mark depth-seven parents 6 × 1,024 + i and in tree N−2 mark parents 5 × 1,024 + i, with trees and parents numbered from zero in traversal order. Place both marked squares at pixel (x,y) in the upper-left 32² readout, where the interleaved bits of x and y give i. Make each marked square .875 pixels wide at 128² and move unmarked draws clear of the readout. Give the two squares −1 and 2⁻²⁵, then exchange the gains. The two possible stored results are zero and 2⁻²⁵. The inputs encoding the marker positions and assignments were generated for this test. [Single-tree marker construction](#four-child-pattern-order-as-a-tile-copy-batch-fills) + +Publish each original graph, select the SSE2 CPU engine and render at 128² F32 with seed 343877. Run each gain assignment twice at each explicit worker count. Compare the second raw buffer with the first at every pixel, including pixels outside the marker field. + +| Trees | Workers | Exact / total, both repeated assignments | Maximum F32 error | +|---:|---|---:|---:| +| 2 | 1, 2 or 4, each | 32,768/32,768 | 0 | +| 4 | 1, 2 or 4, each | 32,768/32,768 | 0 | +| 2 | 8 | 32,256/32,768 | 2⁻²⁵ | +| 4 | 8 | 31,744/32,768 | 2⁻²⁵ | + +With one, two or four workers, every marker had the same order in both trees tested. With eight workers, duplicate runs differed on 256 pixels per gain assignment for two trees and 512 for four. In the desktop two-tree probe, one positive-gain assignment produced 564 positive markers on the first 128² F32 request and zero when returning to that setting after the other formats, even with affinity limited to one host processor. + +For direct MaterialCraft comparisons, render each gain assignment at 128², 128 × 64 and 64 × 128 F32 with seeds 343877, 343903 and 343907 respectively. Add U8, U16 and F16 at 128² and seed 343939, then return to the first request. Save each graph and reopen requests numbered 0, 3, 6, 9 and 12 in the combined series of 14. + +| Trees | Desktop affinity | U8 exact / total | U16 exact / total | F16 exact / total | F32 exact / total · maximum error | +|---:|---|---:|---:|---:|---:| +| 2 | One | 32,768/32,768 | 32,768/32,768 | 32,768/32,768 | 96,612/98,304 · 2⁻²⁵ | +| 2 | Eight | 32,768/32,768 | 32,768/32,768 | 32,768/32,768 | 98,304/98,304 · 0 | +| 4 | One | 32,768/32,768 | 32,768/32,768 | 32,768/32,768 | 97,280/98,304 · 2⁻²⁵ | +| 4 | Eight | 32,768/32,768 | 32,768/32,768 | 32,768/32,768 | 98,304/98,304 · 0 | +| 2 | One, reopened | 16,384/16,384 | — | 16,384/16,384 | 39,832/40,960 · 2⁻²⁵ | +| 4 | One, reopened | 16,384/16,384 | — | 16,384/16,384 | 40,448/40,960 · 2⁻²⁵ | + +All U8, U16 and F16 maxima were zero. The desktop node exposed its seed, tiling, culling, regions, roughness and opacity. The inspected node had 15 input properties, with no draw-order selector. The repeat differences leave the affected whole roots in progress. + +### Whole and saved outputs for the two Gaussian Spots 2 noise generators + +Compare the whole procedural outputs before and after the seven-level compositing change at `8a52087`. Each saved SBS was reopened in both applications at the listed settings. Integer errors use stored levels. Floating-point counts compare bits and maxima use absolute error. [Seven-level controls and identification of a single emitted tree](#compositing-a-single-seven-level-tree-through-pattern-controls) + +Expose the first pattern generator as F32. For the first four requests use graph sizes 16 × 32, 64 × 32, 32 × 64 and 64² with seed 288101 + 43i + 79j, where i is the inventory index and j = 0…3. Then use 128², defaults and seed zero. Run each stage with its normal controls, with the outer repeat forced to one and switch forced to the tree, and with both outer controls bypassed. + +| Index · package | Controls for the four seeded stage requests, in order | +|---|---| +| 285 · noise_gaussian_spots_2 | Defaults / scale=1, disorder=0, non_square_expansion=on / scale=7, disorder=0.8125, non_square_expansion=on / scale=3, disorder=0.3125, non_square_expansion=off | +| 286 · noise_gaussian_spots_2_v2 | Defaults / scale=1, disorder=0, non_square_expansion=on, disorder_speed=1, disorder_anisotropy=0, disorder_anisotropy_angle=0, tile_offset=(0, 0) / scale=7, disorder=0.8125, non_square_expansion=on, disorder_speed=1.375, disorder_anisotropy=0.625, disorder_anisotropy_angle=-0.3125, tile_offset=(-0.4375, 0.0625) / scale=3, disorder=0.3125, non_square_expansion=off, disorder_speed=0.625, disorder_anisotropy=0.375, disorder_anisotropy_angle=0.1875, tile_offset=(0.1875, -0.3125) | + +| Stage · five requested settings | Rendered | Earlier F32 exact / total · max | Corrected F32 exact / total · max | +|---|---:|---:|---:| +| noise_gaussian_spots_2 · original | 4/5 | 21,037/23,040 · 5.96046448e-08 | 22,526/23,040 · 5.96046448e-08 | +| noise_gaussian_spots_2 · one forced tree | 5/5 | 23,460/25,088 · 5.96046448e-08 | 25,088/25,088 · 0 | +| noise_gaussian_spots_2 · outer controls bypassed | 5/5 | 25,088/25,088 · 0 | 25,088/25,088 · 0 | +| noise_gaussian_spots_2_v2 · original | 4/5 | 20,334/23,040 · 8.94069672e-08 | 22,096/23,040 · 5.96046448e-08 | +| noise_gaussian_spots_2_v2 · one forced tree | 5/5 | 23,122/25,088 · 8.94069672e-08 | 25,022/25,088 · 5.96046448e-08 | +| noise_gaussian_spots_2_v2 · outer controls bypassed | 5/5 | 23,055/25,088 · 8.94069672e-08 | 25,015/25,088 · 8.94069672e-08 | + +The original stage in each graph reached the execution budget at the changed 32 × 64 request. Both forced single-tree stages and both bypassed stages rendered all five settings. + +| Package · comparison | Rendered / requested | Exact settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:|---:| +| noise_gaussian_spots_2 · one processor | 56/62 | 38 | 97,792/97,792 · 0 | 344,572/344,576 · 1 | 97,792/97,792 · 0 | 256,336/269,056 · 1.1920929e-07 | +| noise_gaussian_spots_2 · eight processors | 56/62 | 27 | 97,792/97,792 · 0 | 344,555/344,576 · 1 | 97,791/97,792 · 6.10351562e-05 | 251,734/269,056 · 1.1920929e-07 | +| noise_gaussian_spots_2 · reference one versus eight | 62/62 | 31 | 99,840/99,840 · 0 | 348,651/348,672 · 1 | 99,839/99,840 · 6.10351562e-05 | 254,425/273,152 · 1.1920929e-07 | +| noise_gaussian_spots_2 · one-processor SBS reopen | 12/13 | 11 | 4,096/4,096 · 0 | 119,808/119,808 · 0 | 4,096/4,096 · 0 | 23,390/23,552 · 5.96046448e-08 | +| noise_gaussian_spots_2 · reference original versus reopened | 13/13 | 12 | 4,096/4,096 · 0 | 119,808/119,808 · 0 | 4,096/4,096 · 0 | 25,563/25,600 · 5.96046448e-08 | +| noise_gaussian_spots_2_v2 · one processor | 56/62 | 34 | 196,096/196,096 · 0 | 246,246/246,272 · 1 | 97,792/97,792 · 0 | 232,229/269,056 · 1.78813934e-07 | +| noise_gaussian_spots_2_v2 · eight processors | 56/62 | 27 | 196,096/196,096 · 0 | 246,244/246,272 · 1 | 97,792/97,792 · 0 | 226,045/269,056 · 1.78813934e-07 | +| noise_gaussian_spots_2_v2 · reference one versus eight | 62/62 | 31 | 198,144/198,144 · 0 | 250,334/250,368 · 1 | 99,840/99,840 · 0 | 227,967/273,152 · 1.78813934e-07 | +| noise_gaussian_spots_2_v2 · one-processor SBS reopen | 12/13 | 9 | 20,480/20,480 · 0 | 103,416/103,424 · 1 | 4,096/4,096 · 0 | 22,158/23,552 · 8.94069672e-08 | +| noise_gaussian_spots_2_v2 · reference original versus reopened | 13/13 | 12 | 20,480/20,480 · 0 | 103,424/103,424 · 0 | 4,096/4,096 · 0 | 25,261/25,600 · 5.96046448e-08 | + +| Package | Earlier → corrected one-processor exact pixels | Eight-processor exact pixels | One-processor saved exact pixels | +|---|---:|---:|---:| +| noise_gaussian_spots_2 | 787,083 → 796,492 of 809,216 | 790,563 → 791,872 of 809,216 | 149,414 → 151,390 of 151,552 | +| noise_gaussian_spots_2_v2 | 761,369 → 772,363 of 809,216 | 765,155 → 766,177 of 809,216 | 148,177 → 150,150 of 151,552 | + +The material outputs still differ at the listed settings. Every successful MaterialCraft save reproduced its original output. + +
+noise_gaussian_spots_2 procedural settings + +The control columns use `disorder`, `non_square_expansion`, `scale`, in that order. + +| Size | Seed | Controls | Formats | Reopened | Execution budget reached | +|---|---:|---|---|---|---| +| 128 × 128 | 0 | Defaults | U16, U8, F16, F32 | U16 | — | +| 256 × 256 | 0 | Defaults | U16 | — | — | +| 128 × 128 | 42 | Defaults | U16 | — | — | +| 128 × 128 | 0 | 0.37, default, 2 | U16 | — | — | +| 32 × 32 | 113 | 0.37, default, 2 | F32 | — | — | +| 64 × 64 | 42 | 0.37, default, 2 | U8, U16, F16, F32 | U8 | — | +| 16 × 16 | 87914 | Defaults | F32 | — | — | +| 32 × 32 | 87915 | 0, on, 1 | F32 | F32 | — | +| 32 × 32 | 87916 | 0.3125, off, 3 | U8, U16, F16, F32 | — | — | +| 64 × 32 | 87920 | 0.8125, on, 7 | F32 | F32 | F32 | +| 32 × 64 | 87921 | 0.8125, on, 7 | U16 | — | U16 | +| 64 × 64 | 87922 | 0.3125, off, 3 | F32 | — | — | +| 128 × 64 | 87923 | 0.3125, off, 3 | F32 | — | — | +| 64 × 128 | 87923 | 0.3125, off, 3 | U16 | — | — | +| 128 × 128 | 87925 | Defaults | F32 | F32 | — | +| 16 × 32 | 0 | Defaults | U8, U16, F16, F32 | — | — | +| 32 × 16 | 42 | 0.21875, on, 2 | U16, F32 | U16 | — | +| 64 × 64 | 433792 | 0.9375, off, 1 | U8, U16, F16, F32 | F32 | — | +| 128 × 32 | 433829 | 0.046875, on, 3 | U16, F32 | — | — | +| 32 × 128 | 433866 | 0.5625, off, 2 | U8, U16, F16, F32 | F16 | — | +| 256 × 128 | 433940 | 0.328125, off, 3 | U16, F32 | U16 | — | +| 128 × 256 | 433977 | 0.8125, on, 1 | U16, F32 | — | — | +| 256 × 256 | 42 | Defaults | U8, U16, F16, F32 | U16 | — | +| 512 × 128 | 434051 | 0.671875, on, 1 | U16, F32 | — | — | +| 16 × 32 | 300356 | Defaults | U16, F32 | U16 | — | +| 64 × 32 | 300435 | 0, on, 1 | U8, U16, F16, F32 | F32 | — | +| 32 × 64 | 300514 | 0.8125, on, 7 | U8, U16, F16, F32 | — | U8, U16, F16, F32 | +| 64 × 64 | 300593 | 0.3125, off, 3 | U16, F32 | U16 | — | + +
+ +
+noise_gaussian_spots_2_v2 procedural settings + +The control columns use `disorder`, `disorder_anisotropy`, `disorder_anisotropy_angle`, `disorder_speed`, `non_square_expansion`, `scale`, `tile_offset`, in that order. + +| Size | Seed | Controls | Formats | Reopened | Execution budget reached | +|---|---:|---|---|---|---| +| 128 × 128 | 0 | Defaults | U8, U16, F16, F32 | U8 | — | +| 256 × 256 | 0 | Defaults | U8 | — | — | +| 128 × 128 | 42 | Defaults | U8 | — | — | +| 128 × 128 | 0 | 0.37, 0.3, 0.125, 0.6, default, 2, (0.17, 0.29) | U8 | — | — | +| 32 × 32 | 113 | 0.37, 0.3, 0.125, 0.6, default, 2, (0.17, 0.29) | F32 | — | — | +| 64 × 64 | 42 | 0.37, 0.3, 0.125, 0.6, default, 2, (0.17, 0.29) | U8, U16, F16, F32 | U8 | — | +| 16 × 16 | 87921 | Defaults | F32 | — | — | +| 32 × 32 | 87922 | 0, 0, 0, 1, on, 1, (0, 0) | F32 | F32 | — | +| 32 × 32 | 87923 | 0.3125, 0.375, 0.1875, 0.625, off, 3, (0.1875, -0.3125) | U8, U16, F16, F32 | — | — | +| 64 × 32 | 87927 | 0.8125, 0.625, -0.3125, 1.375, on, 7, (-0.4375, 0.0625) | F32 | F32 | F32 | +| 32 × 64 | 87928 | 0.8125, 0.625, -0.3125, 1.375, on, 7, (-0.4375, 0.0625) | U16 | — | U16 | +| 64 × 64 | 87929 | 0.3125, 0.375, 0.1875, 0.625, off, 3, (0.1875, -0.3125) | F32 | — | — | +| 128 × 64 | 87930 | 0.3125, 0.375, 0.1875, 0.625, off, 3, (0.1875, -0.3125) | F32 | — | — | +| 64 × 128 | 87930 | 0.3125, 0.375, 0.1875, 0.625, off, 3, (0.1875, -0.3125) | U16 | — | — | +| 128 × 128 | 87932 | Defaults | F32 | F32 | — | +| 16 × 32 | 0 | Defaults | U8, U16, F16, F32 | — | — | +| 32 × 16 | 42 | 0.21875, 0.21875, -0.03125, 0.21875, on, 2, (-0.125, 0.214844) | U16, F32 | U16 | — | +| 64 × 64 | 433805 | 0.9375, 0.9375, 0.6875, 0.9375, off, 1, (0.59375, -0.414062) | U8, U16, F16, F32 | F32 | — | +| 128 × 32 | 433842 | 0.046875, 0.046875, -0.203125, 0.046875, on, 3, (-0.296875, 0.365234) | U16, F32 | — | — | +| 32 × 128 | 433879 | 0.5625, 0.5625, 0.3125, 0.5625, off, 2, (0.21875, -0.0859375) | U8, U16, F16, F32 | F16 | — | +| 256 × 128 | 433953 | 0.328125, 0.328125, 0.078125, 0.328125, off, 3, (-0.015625, 0.119141) | U16, F32 | U16 | — | +| 128 × 256 | 433990 | 0.8125, 0.8125, 0.5625, 0.8125, on, 1, (0.46875, -0.304688) | U16, F32 | — | — | +| 256 × 256 | 42 | Defaults | U8, U16, F16, F32 | U16 | — | +| 512 × 128 | 434064 | 0.671875, 0.671875, 0.421875, 0.671875, on, 1, (0.328125, -0.181641) | U16, F32 | — | — | +| 16 × 32 | 300399 | Defaults | U16, F32 | U16 | — | +| 64 × 32 | 300478 | 0, 0, 0, 1, on, 1, (0, 0) | U8, U16, F16, F32 | F32 | — | +| 32 × 64 | 300557 | 0.8125, 0.625, -0.3125, 1.375, on, 7, (-0.4375, 0.0625) | U8, U16, F16, F32 | — | U8, U16, F16, F32 | +| 64 × 64 | 300636 | 0.3125, 0.375, 0.1875, 0.625, off, 3, (0.1875, -0.3125) | U16, F32 | U16 | — | + +
+ +### Whole and saved outputs for Noise Dirt 3 v2 + +Compare the whole procedural outputs before and after the seven-level compositing change at `8a52087`. Each saved SBS was reopened in both applications at the listed settings. Integer errors use stored levels. Floating-point counts compare bits and maxima use absolute error. [Seven-level controls and identification of a single emitted tree](#compositing-a-single-seven-level-tree-through-pattern-controls) + +| Package · comparison | Rendered / requested | Exact settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:|---:| +| noise_dirt_3_v2 · one processor | 58/60 | 34 | 198,144/198,144 · 0 | 236,538/236,544 · 1 | 101,888/101,888 · 0 | 234,828/240,896 · 1.1920929e-07 | +| noise_dirt_3_v2 · eight processors | 58/60 | 33 | 198,144/198,144 · 0 | 236,538/236,544 · 1 | 101,888/101,888 · 0 | 234,978/240,896 · 1.1920929e-07 | +| noise_dirt_3_v2 · reference one versus eight | 60/60 | 35 | 198,144/198,144 · 0 | 240,636/240,640 · 1 | 101,888/101,888 · 0 | 238,158/244,992 · 5.96046448e-08 | +| noise_dirt_3_v2 · one-processor SBS reopen | 11/12 | 8 | 26,624/26,624 · 0 | 51,712/51,712 · 0 | — | 66,532/67,072 · 1.1920929e-07 | +| noise_dirt_3_v2 · reference original versus reopened | 12/12 | 10 | 26,624/26,624 · 0 | 51,712/51,712 · 0 | — | 71,141/71,168 · 5.96046448e-08 | + +| Package | Earlier → corrected one-processor exact pixels | Eight-processor exact pixels | One-processor saved exact pixels | +|---|---:|---:|---:| +| noise_dirt_3_v2 | 771,398 → 771,398 of 777,472 | 771,548 → 771,548 of 777,472 | 144,868 → 144,868 of 145,408 | + +The material outputs still differ at the listed settings. Every successful MaterialCraft save reproduced its original output. + +
+noise_dirt_3_v2 procedural settings + +The control columns use `disorder`, `disorder_anisotropy`, `disorder_anisotropy_angle`, `disorder_speed`, `non_square_expansion`, `scale`, `tile_offset`, in that order. + +| Size | Seed | Controls | Formats | Reopened | Execution budget reached | +|---|---:|---|---|---|---| +| 128 × 128 | 0 | Defaults | U8, U16, F16, F32 | U8, U16 | — | +| 256 × 256 | 0 | Defaults | U8 | — | — | +| 128 × 128 | 42 | Defaults | U8 | — | — | +| 128 × 128 | 0 | 0.37, 0.3, 0.125, 0.6, default, 2, (0.17, 0.29) | U8 | — | — | +| 32 × 32 | 113 | 0.37, 0.3, 0.125, 0.6, default, 2, (0.17, 0.29) | F32 | — | — | +| 64 × 64 | 42 | 0.37, 0.3, 0.125, 0.6, default, 2, (0.17, 0.29) | U8, U16, F16, F32 | U8 | — | +| 16 × 16 | 105492 | Defaults | F32 | — | — | +| 32 × 32 | 105493 | 0, 0, 0, 1, on, 1, (0, 0) | F32 | F32 | — | +| 32 × 32 | 105494 | 0.3125, 0.25, 0.3125, 0.6875, off, 1, (0.125, -0.1875) | U8, U16, F16, F32 | — | — | +| 32 × 16 | 105498 | 0.8125, 0.625, -0.21875, 1.4375, on, 2, (-0.3125, 0.4375) | F32 | F32 | — | +| 16 × 32 | 105499 | 0.8125, 0.625, -0.21875, 1.4375, on, 2, (-0.3125, 0.4375) | U16 | — | — | +| 64 × 32 | 105500 | 0.3125, 0.25, 0.3125, 0.6875, off, 1, (0.125, -0.1875) | F32 | — | — | +| 32 × 64 | 105501 | 0, 0, 0, 1, on, 1, (0, 0) | F16 | — | — | +| 16 × 32 | 0 | Defaults | U8, U16, F16, F32 | U16 | — | +| 32 × 16 | 42 | 0.21875, 0.21875, -0.03125, 0.21875, on, 2, (-0.125, 0.214844) | U16, F32 | — | — | +| 64 × 64 | 433532 | 0.9375, 0.9375, 0.6875, 0.9375, off, 1, (0.59375, -0.414062) | U8, U16, F16, F32 | U8 | — | +| 128 × 32 | 433569 | 0.046875, 0.046875, -0.203125, 0.046875, on, 3, (-0.296875, 0.365234) | U16, F32 | F32 | U16, F32 | +| 32 × 128 | 433606 | 0.5625, 0.5625, 0.3125, 0.5625, off, 2, (0.21875, -0.0859375) | U8, U16, F16, F32 | — | — | +| 256 × 128 | 433680 | 0.328125, 0.328125, 0.078125, 0.328125, off, 3, (-0.015625, 0.119141) | U16, F32 | — | — | +| 128 × 256 | 433717 | 0.8125, 0.8125, 0.5625, 0.8125, on, 1, (0.46875, -0.304688) | U16, F32 | U16 | — | +| 256 × 256 | 42 | Defaults | U8, U16, F16, F32 | F32 | — | +| 512 × 128 | 433791 | 0.671875, 0.671875, 0.421875, 0.671875, on, 1, (0.328125, -0.181641) | U16, F32 | — | — | +| 16 × 32 | 299496 | Defaults | U16, F32 | — | — | +| 64 × 32 | 299575 | 0, 0, 0, 1, on, 1, (0, 0) | U8, U16, F16, F32 | U8 | — | +| 32 × 64 | 299654 | 0.8125, 0.625, -0.21875, 1.4375, on, 2, (-0.3125, 0.4375) | U8, U16, F16, F32 | U16 | — | +| 64 × 64 | 299733 | 0.21875, 0.21875, -0.03125, 0.21875, on, 2, (-0.125, 0.214844) | U16, F32 | — | — | + +
+ +### Whole and saved outputs for Noise Clouds 1 v2 at the four-child batch boundary + +Repeat the 60 whole-root settings and 15 SBS reopens at revision `1852120`. Compare stored integer levels and exact floating-point bits. Error maxima are absolute differences within each format. [Procedural inputs, settings and seeds](#four-cloud-noise-generators-and-repeated-saved-file-comparisons) · [Isolated four-child generator](#four-child-pattern-order-as-a-tile-copy-batch-fills) + +| Comparison | Rendered / requested | Exact settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:|---:| +| One processor | 56/60 | 33 | 134,912/134,912 · 0 | 228,553/228,608 · 1 | 93,952/93,952 · 0 | 216,735/235,008 · 3.27825546e-07 | +| Eight processors | 56/60 | 25 | 134,912/134,912 · 0 | 228,520/228,608 · 1 | 93,951/93,952 · 0.00048828125 | 209,153/235,008 · 2.98023224e-07 | +| Reference one versus eight | 60/60 | 24 | 134,912/134,912 · 0 | 246,944/247,040 · 1 | 93,951/93,952 · 0.00048828125 | 222,210/253,440 · 2.98023224e-07 | +| One-processor SBS reopen | 13/15 | 7 | 20,480/20,480 · 0 | 76,514/76,544 · 1 | 1,536/1,536 · 0 | 5,464/6,144 · 1.78813934e-07 | +| Reference original versus reopened | 15/15 | 12 | 20,480/20,480 · 0 | 78,591/78,592 · 1 | 1,536/1,536 · 0 | 21,412/22,528 · 2.98023224e-07 | + +| Comparison | Earlier exact pixels at `e4675a1` | Exact pixels at `1852120` | Total | +|---|---:|---:|---:| +| Whole, one processor | 664,563 | 674,152 | 692,480 | +| Whole, eight processors | 669,413 | 666,536 | 692,480 | +| Reopened, one processor | 103,994 | 103,994 | 104,704 | + +The following requests reached the pattern execution budget in MaterialCraft. All 13 successful MaterialCraft reopens reproduced their original raw outputs. + +| Run | Size | Seed | Exposed controls | Format | +|---|---|---:|---|---| +| Whole | 64 × 32 | 103034 | scale=5, disorder=0.8125, non_square_expansion=true, disorder_speed=1.4375, disorder_anisotropy=0.625, disorder_anisotropy_angle=-0.21875, tile_offset=[-0.3125, 0.4375] | F32 | +| Whole | 32 × 64 | 103035 | scale=5, disorder=0.8125, non_square_expansion=true, disorder_speed=1.4375, disorder_anisotropy=0.625, disorder_anisotropy_angle=-0.21875, tile_offset=[-0.3125, 0.4375] | U16 | +| Whole | 128 × 128 | 411810 | scale=3, disorder=0.65625, disorder_speed=0.65625, disorder_anisotropy=0.65625, disorder_anisotropy_angle=0.40625, tile_offset=[0.3125, -0.16796875], non_square_expansion=false | U16 | +| Whole | 128 × 128 | 411810 | scale=3, disorder=0.65625, disorder_speed=0.65625, disorder_anisotropy=0.65625, disorder_anisotropy_angle=0.40625, tile_offset=[0.3125, -0.16796875], non_square_expansion=false | F32 | +| Reopened | 32 × 64 | 103035 | scale=5, disorder=0.8125, non_square_expansion=true, disorder_speed=1.4375, disorder_anisotropy=0.625, disorder_anisotropy_angle=-0.21875, tile_offset=[-0.3125, 0.4375] | U16 | +| Reopened | 128 × 128 | 411810 | scale=3, disorder=0.65625, disorder_speed=0.65625, disorder_anisotropy=0.65625, disorder_anisotropy_angle=0.40625, tile_offset=[0.3125, -0.16796875], non_square_expansion=false | F32 | + +### Four-child pattern order as a tile-copy batch fills + +In one eight-level additive quadrant tree, each of the 16,384 depth-seven parents draws itself and four leaves. A depth-three subtree contains 256 of these parents and 1,280 logical draws. A stamp crossing the tiling window can contribute several copies. The render order changes when subtrees 58 and 59 followed by 0 and 1 reach 5,460 physical copies. In the measured continuation, subtree 2 moves later and the next prefix starts in subtree 3. The prefix starting in subtree 40 can also fill one subtree earlier. MaterialCraft counts copies in the common render and tiling window and uses the observed order within its measured range. [Four-child ordering and threshold regression](../crates/nodes/src/pattern/tile_runs/four_children.rs) + +To reproduce the threshold, use a white F32 image and active additive squares. At each parent, reserve the parent and its first leaf for signed markers. Number the other three leaves in recursive slot order. For a subtree with q additional copies, place leaves with ordinal floor(768j/q) on the X seam for j from 0 through q−1. Keep the other leaves inside the unit square. In groups 58, 59, 0, 1 distribute 339 extra copies as (84,85,85,85). Do the same for groups 40 through 43 and use (84,85) for groups 2 and 3. With all other extra counts at zero, groups (58,59,0,1), (40,41,42,43) and (0,1,2,3) each account for 5,459 copies. Move one more leaf of group 58 to the seam to reach 5,460 in the first total. Two signed square markers sharing a pixel with gains −1 and 2⁻²⁵ reveal their order. Swap the gains and repeat. Seven marker pairs in the regression reverse order and two preserve it. Adding one copy to group 40 or group 2 alone preserves the earlier ordering for these pairs. The regression failed before the change. + +For an independent order readout, give selected parents horizontal strips and their first leaves vertical strips. Read their F32 intersections, exchange the two gains and resolve tied ranks with individual point pairs. Refine each interval where adjacent sampled parents separate in rank. The observed order spans 35 runs before the first total fills and 33 afterwards. A separate profile with 5,461 copies in the prefix starting at group 40 locates its first cut in group 43. For the profile with 5,461 in groups 58, 59, 0 and 1, the parent ordering agreed at all 16,384 positions. Eleven of 192 nearby stamp pairs gave different orders between two dense point fields. Each of those eleven pairs was then isolated at a separate pixel, one pair per field. With seeds 335509 and 335527 and both gain assignments, all 44 isolated readouts reproduced the 33-run order. + +In a second regression, use all four terminal leaf slots in the expanded-window square construction. At the 1,024 Morton-ordered readout positions the following half-open parent ranges return 2⁻²⁵. All other positions return zero. [Square construction](#eight-level-two-child-drawing-across-equal-tile-and-render-windows) · [End-to-end regression](../crates/nodes/src/pattern/tests.rs) + +| Common X and Y windows | Output | Readout origin | Leaf X offset | Positive ranges | +|---|---|---|---:|---| +| (−.5,1.5) × (−.5,1.5) | 256² | (64,64) | 0 | [580,648), [768,1024) | +| (0,1) × (−.5,1.5) | 128 × 256 | (0,64) | −1/512 | [571,644), [768,1024) | +| (0,1) × (−.5,1.5) | 128 × 256 | (0,64) | .4995 | [574,623), [768,1024) | + +Repeat the 64-subtree round-robin fields in the linked construction with all four leaf slots and add 613 to each seed. Use both gain assignments at all four sizes and the four stored formats at 128 × 64. Save and reopen every third case, starting with the first. Counts compare raw pixels, integer errors use stored levels and floating errors are absolute. + +| Window and reference | Earlier exact / total · max | Corrected exact / total · max | +|---|---:|---:| +| Expanded square · one processor | 240,504/245,760 · 2.98023224e-08 | 245,760/245,760 · 0 | +| Expanded square · eight processors | 241,800/245,760 · 2.98023224e-08 | 239,344/245,760 · 2.98023224e-08 | +| Expanded square · one-processor reopen | 103,868/106,496 · 2.98023224e-08 | 106,496/106,496 · 0 | +| Expanded X · one processor | 245,760/245,760 · 0 | 245,760/245,760 · 0 | +| Expanded X · eight processors | 245,760/245,760 · 0 | 245,760/245,760 · 0 | +| Expanded X · one-processor reopen | 106,496/106,496 · 0 | 106,496/106,496 · 0 | +| Translated rectangle · one processor | 235,248/245,760 · 2.98023224e-08 | 245,760/245,760 · 0 | +| Translated rectangle · eight processors | 228,016/245,760 · 2.98023224e-08 | 230,672/245,760 · 2.98023224e-08 | +| Translated rectangle · one-processor reopen | 101,240/106,496 · 2.98023224e-08 | 106,496/106,496 · 0 | +| Unit render and larger tiling window · one processor | 221,320/245,760 · 2.98023224e-08 | 221,320/245,760 · 2.98023224e-08 | +| Unit render and larger tiling window · eight processors | 199,776/245,760 · 2.98023224e-08 | 199,776/245,760 · 2.98023224e-08 | +| Unit render and larger tiling window · one-processor reopen | 94,276/106,496 · 2.98023224e-08 | 94,276/106,496 · 2.98023224e-08 | + +All 42 equal-window settings agreed on one processor, 737,280/737,280 pixels, with zero maximum error. All 15 corresponding reopens also agreed, 319,488/319,488 pixels. The unequal-window control retained its earlier raw buffers. + +For Noise Clouds 1 and Noise Clouds 1 v2, expose the final pattern generator directly as F32. Force the outer repeat to one and the switch to its tree. Disconnect the background input on v2 and set both generators’ backgrounds to opaque black. Run the following settings in order. Save and reopen settings 0, 3 and 6 in both applications. + +| Setting | Size | Seed | Exposed controls | +|---:|---|---:|---| +| 0 | 128 × 128 | 0 | Defaults | +| 1 | 128 × 128 | 17 | Defaults | +| 2 | 64 × 64 | 330251 | scale=1, disorder=0.21875, non_square_expansion=true | +| 3 | 128 × 128 | 330277 | scale=1, disorder=0.46875, non_square_expansion=false | +| 4 | 256 × 64 | 330307 | scale=1, disorder=0.71875, non_square_expansion=true | +| 5 | 64 × 256 | 330353 | scale=1, disorder=0.28125, non_square_expansion=true | +| 6 | 128 × 64 | 330371 | scale=2, disorder=0.9375, non_square_expansion=false | +| 7 | 128 × 128 | 0 | Defaults | + +| F32 single-tree field | Earlier exact / total · max | Corrected exact / total · max | +|---|---:|---:| +| Clouds 1 · one processor | 77,763/110,592 · 1.1920929e-07 | 110,592/110,592 · 0 | +| Clouds 1 · eight processors | 80,201/110,592 · 8.94069672e-08 | 77,612/110,592 · 1.1920929e-07 | +| Clouds 1 · one-processor reopen | 26,715/40,960 · 8.94069672e-08 | 40,960/40,960 · 0 | +| Clouds 1 v2 · one processor | 77,175/110,592 · 8.94069672e-08 | 110,592/110,592 · 0 | +| Clouds 1 v2 · eight processors | 81,392/110,592 · 1.1920929e-07 | 75,691/110,592 · 1.1920929e-07 | +| Clouds 1 v2 · one-processor reopen | 26,490/40,960 · 8.94069672e-08 | 40,960/40,960 · 0 | + +Restore each generator’s original background, including the incoming connection on v2. At the seven settings below, compare the original controls with one, two or four forced trees, wrapping off, parents only and leaves only. Each row names the settings used for that comparison. [Earlier cloud sources and seeds](#four-cloud-noise-generators-and-repeated-saved-file-comparisons) + +| Setting | Size | Seed for Clouds 1 / v2 | Exposed controls | +|---|---|---|---| +| a0 | 128 × 128 | 0 / 0 | Defaults | +| a34 | 128 × 64 | 411681 / 411688 | scale=2, disorder=0.96875, non_square_expansion=false / scale=2, disorder=0.96875, disorder_speed=0.96875, disorder_anisotropy=0.96875, disorder_anisotropy_angle=0.71875, tile_offset=[0.625, -0.44140625], non_square_expansion=false | +| a46 | 512 × 128 | 411986 / 411993 | scale=1, disorder=0.09375, non_square_expansion=true / scale=1, disorder=0.09375, disorder_speed=0.09375, disorder_anisotropy=0.09375, disorder_anisotropy_angle=-0.15625, tile_offset=[-0.25, 0.32421875], non_square_expansion=true | +| a9 | 16 × 16 | 103017 / 103028 | Defaults | +| more | 64 × 128 | 326871 / 326872 | scale=2, disorder=0.59375, non_square_expansion=false / scale=2, disorder=0.59375, disorder_speed=0.96875, disorder_anisotropy=0.96875, disorder_anisotropy_angle=0.71875, tile_offset=[0.625, -0.44140625], non_square_expansion=false | +| offset | 128 × 64 | 411698 / 411705 | scale=2, disorder=0.96875, non_square_expansion=false / scale=2, disorder=0.96875, disorder_speed=0.96875, disorder_anisotropy=0.96875, disorder_anisotropy_angle=0.71875, tile_offset=[0.625, -0.44140625], non_square_expansion=false | +| repeat | 128 × 64 | 411681 / 411688 | scale=2, disorder=0.96875, non_square_expansion=false / scale=2, disorder=0.96875, disorder_speed=0.96875, disorder_anisotropy=0.96875, disorder_anisotropy_angle=0.71875, tile_offset=[0.625, -0.44140625], non_square_expansion=false | + +| F32 stage with original background · one processor unless specified | Settings | Rendered | Earlier exact / total · max | Corrected exact / total · max | +|---|---|---:|---:|---:| +| Clouds 1 · original | a0, a34, a46, a9, more, offset, repeat | 7/7 | 70,037/114,944 · 8.94069672e-08 | 76,906/114,944 · 8.94069672e-08 | +| Clouds 1 · original, eight processors | a0, a34, a46, a9, more, offset, repeat | 7/7 | 72,405/114,944 · 8.94069672e-08 | 72,899/114,944 · 8.94069672e-08 | +| Clouds 1 · one tree | a0, a34, a46, more | 4/4 | 82,948/98,304 · 8.94069672e-08 | 98,304/98,304 · 0 | +| Clouds 1 · one tree, wrapping off | a0, a34, a46, more | 4/4 | 98,304/98,304 · 0 | 98,304/98,304 · 0 | +| Clouds 1 · original, wrapping off | a0, a34, a46, more | 4/4 | 69,155/98,304 · 8.94069672e-08 | 69,155/98,304 · 8.94069672e-08 | +| Clouds 1 · two trees | a34, a9 | 2/2 | 7,266/8,448 · 1.1920929e-07 | 7,266/8,448 · 1.1920929e-07 | +| Clouds 1 · four trees | a34, a9 | 2/2 | 7,127/8,448 · 2.38418579e-07 | 7,127/8,448 · 2.38418579e-07 | +| Clouds 1 · parents only | a34, a9 | 2/2 | 6,953/8,448 · 5.96046448e-08 | 6,953/8,448 · 5.96046448e-08 | +| Clouds 1 · leaves only | a34, a9 | 2/2 | 6,709/8,448 · 2.98023224e-08 | 6,709/8,448 · 2.98023224e-08 | +| Clouds 1 · original SBS reopen | a0, a9, repeat | 3/3 | 15,055/24,832 · 8.94069672e-08 | 21,924/24,832 · 8.94069672e-08 | +| Clouds 1 v2 · original | a0, a34, a46, a9, more, offset, repeat | 7/7 | 102,201/114,944 · 3.27825546e-07 | 104,432/114,944 · 3.27825546e-07 | +| Clouds 1 v2 · original, eight processors | a0, a34, a46, a9, more, offset, repeat | 7/7 | 102,663/114,944 · 2.98023224e-07 | 102,514/114,944 · 2.98023224e-07 | +| Clouds 1 v2 · one tree | a0, a34, a46, more | 4/4 | 94,040/98,304 · 2.08616257e-07 | 96,237/98,304 · 2.08616257e-07 | +| Clouds 1 v2 · one tree, wrapping off | a0, a34, a46, more | 4/4 | 97,304/98,304 · 1.78813934e-07 | 97,304/98,304 · 1.78813934e-07 | +| Clouds 1 v2 · original, wrapping off | a0, a34, a46, more | 1/4 | 14,573/16,384 · 1.78813934e-07 | 14,573/16,384 · 1.78813934e-07 | +| Clouds 1 v2 · two trees | a34, a9 | 2/2 | 7,564/8,448 · 3.27825546e-07 | 7,564/8,448 · 3.27825546e-07 | +| Clouds 1 v2 · four trees | a34, a9 | 2/2 | 6,511/8,448 · 3.27825546e-07 | 6,511/8,448 · 3.27825546e-07 | +| Clouds 1 v2 · parents only | a34, a9 | 1/2 | 248/256 · 5.96046448e-08 | 248/256 · 5.96046448e-08 | +| Clouds 1 v2 · leaves only | a34, a9 | 2/2 | 8,147/8,448 · 1.1920929e-07 | 8,147/8,448 · 1.1920929e-07 | +| Clouds 1 v2 · original SBS reopen | a0, a9, repeat | 3/3 | 21,645/24,832 · 3.27825546e-07 | 23,876/24,832 · 3.27825546e-07 | + +For Clouds 1 at 128² defaults the single tree has 81,920 logical draws and 3,141 extra wrapped copies. Replaying its original F32 contributions at their original pixels in physical copy order reproduces all 16,384 reference pixels. The earlier order reproduced 9,619. The original 128 × 64 changed setting emits four trees with 0, 1,577, 3,016 and 1,679 extra copies. Applying the single-tree ordering successively to these trees reproduces 6,611/8,192 pixels. This comparison leaves the repeated-tree order open. + +A separate marker field reproduced the 64 subtree copy totals of each of these four trees. Its 142 observed draw runs interleave adjacent trees. Applying the resulting physical copy order to the original cloud contributions reproduced all 8,192 pixels with zero maximum error. This replay is independent of the single-tree renderer change. + +For the whole Clouds 1 graph repeat all 60 settings and 15 SBS reopens. Cook four settings spanning default and changed controls and U8, U16, F16 and F32 in both fresh and cached sessions. All four raw buffers and error results agreed between execution paths. [Complete cloud settings](#four-cloud-noise-generators-and-repeated-saved-file-comparisons) + +| Root and comparison | Rendered / requested | Exact settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:|---:| +| Clouds 1 · one processor | 58/60 | 43 | 85,760/85,760 · 0 | 294,083/294,144 · 1 | 93,952/93,952 · 0 | 251,336/251,392 · 1.52587891e-05 | +| Clouds 1 · eight processors | 58/60 | 37 | 85,760/85,760 · 0 | 294,039/294,144 · 1 | 93,950/93,952 · 0.00048828125 | 251,284/251,392 · 1.52587891e-05 | +| Clouds 1 · reference one versus eight | 60/60 | 35 | 85,760/85,760 · 0 | 296,060/296,192 · 1 | 93,950/93,952 · 0.00048828125 | 253,328/253,440 · 1.52587891e-05 | +| Clouds 1 · one-processor SBS reopen | 14/15 | 9 | 4,096/4,096 · 0 | 92,907/92,928 · 1 | 1,536/1,536 · 0 | 22,522/22,528 · 1.52587891e-05 | +| Clouds 1 · reference original versus reopened | 15/15 | 15 | 4,096/4,096 · 0 | 94,976/94,976 · 0 | 1,536/1,536 · 0 | 22,528/22,528 · 0 | + +| Whole root | Earlier → corrected exact pixels on one processor | Eight processors | SBS reopen on one processor | +|---|---:|---:|---:| +| Clouds 1 | 725,069 → 725,131 of 725,248 | 725,041 → 725,033 of 725,248 | 121,054 → 121,061 of 121,088 | + +The earlier whole Clouds 1 measurements used revision `f59c45f`. Each successful MaterialCraft reopen reproduced its original buffer. The following settings reached the pattern execution budget. + +| Root | Size | Seed | Exposed controls | Format | Run | +|---|---|---:|---|---|---| +| Clouds 1 | 64 × 32 | 103023 | scale=5, disorder=0.8125, non_square_expansion=true | F32 | Whole | +| Clouds 1 | 32 × 64 | 103024 | scale=5, disorder=0.8125, non_square_expansion=true | U16 | Whole and reopened | + +The following four whole Clouds 1 v2 settings are measured in this revision. A fresh session and a cached session produced identical raw buffers. + +| Size | Seed | Exposed controls | Format | One processor · exact / total · max | Eight processors · exact / total · max | +|---|---:|---|---|---:|---:| +| 16 × 16 | 0 | Defaults | U8 | 256/256 · 0 | 256/256 · 0 | +| 16 × 16 | 0 | Defaults | U16 | 256/256 · 0 | 256/256 · 0 | +| 32 × 16 | 169477 | scale=1, disorder=0.34375, disorder_speed=0.796875, disorder_anisotropy=0.171875, disorder_anisotropy_angle=-0.03125, tile_offset=[0.0751953125, -0.12890625] | F16 | 512/512 · 0 | 512/512 · 0 | +| 32 × 16 | 169477 | scale=1, disorder=0.34375, disorder_speed=0.796875, disorder_anisotropy=0.171875, disorder_anisotropy_angle=-0.03125, tile_offset=[0.0751953125, -0.12890625] | F32 | 458/512 · 1.1920929e-07 | 474/512 · 5.96046448e-08 | + +The same terminal structure occurs in Dirt 1 and Dirt 6. Repeat the 68 earlier Dirt 1 settings, 67 earlier Dirt 6 settings and twelve additional wrapping settings per root. Each graph had 16 SBS reopens. [Dirt 1 and Dirt 6 wrapping evidence](#wrapped-draw-order-for-four-children-below-depth-seven) + +| Root | Whole one processor · exact / total | Whole eight processors · exact / total | Reopened one processor · exact / total | Changed local raw buffers versus the previous cook | +|---|---:|---:|---:|---:| +| Dirt 1 | 2,579,712/2,579,712 | 2,579,658/2,579,712 | 288,512/288,512 | 0/96 | +| Dirt 6 | 2,563,328/2,563,328 | 2,561,906/2,563,328 | 510,720/510,720 | 0/95 | + +The maximum error was zero across every one-processor whole and reopened Dirt setting. The eight-processor whole errors were measured separately for each stored format. + +| Root | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Dirt 1 | 542,976/542,976 · 0 | 770,280/770,304 · 1 | 542,975/542,976 · 0.00048828125 | 723,427/723,456 · 1.53183937e-05 | +| Dirt 6 | 542,975/542,976 · 1 | 753,560/753,920 · 5 | 542,830/542,976 · 0.000244140625 | 722,541/723,456 · 9.27764922e-05 | + +Median one-processor process CPU time over three alternating release runs per version, including load and readback, changed from 5.719 to 5.547 seconds for three forced single-tree fields, 10.656 to 10.859 seconds for three repeated-tree fields, 8.781 to 8.891 seconds for three whole Clouds 1 renders. Both regressions failed on the earlier implementation and passed on the corrected code. All 457 release node and evaluator tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Whole and saved outputs for Noise Clouds 2 v2 with equal-window batching + +Cook all 60 whole procedural settings and the 15 SBS reopens at revision `f59c45f`. Compare raw integer levels and floating-point bit patterns. Maxima are absolute differences in each stored format. The reference ran with one and eight processors. [Settings, output sizes, formats and seeds](#four-cloud-noise-generators-and-repeated-saved-file-comparisons) + +| Comparison | Rendered / requested | Exact settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:|---:| +| One processor | 58/60 | 39 | 134,912/134,912 · 0 | 244,981/244,992 · 1 | 93,952/93,952 · 0 | 249,096/251,392 · 4.76837158e-07 | +| Eight processors | 58/60 | 35 | 134,912/134,912 · 0 | 244,988/244,992 · 1 | 93,952/93,952 · 0 | 248,409/251,392 · 4.76837158e-07 | +| Reference one versus eight | 60/60 | 35 | 134,912/134,912 · 0 | 247,029/247,040 · 1 | 93,952/93,952 · 0 | 249,630/253,440 · 4.76837158e-07 | +| One-processor SBS reopen | 14/15 | 9 | 20,480/20,480 · 0 | 76,540/76,544 · 1 | 1,536/1,536 · 0 | 22,295/22,528 · 1.78813934e-07 | +| Reference original versus reopened | 15/15 | 13 | 20,480/20,480 · 0 | 78,592/78,592 · 0 | 1,536/1,536 · 0 | 22,447/22,528 · 1.78813934e-07 | + +The following MaterialCraft requests reached the pattern execution budget. Each successfully reopened SBS produced the same raw output as its original MaterialCraft graph. + +| Size | Seed | Exposed controls | Format | Run | +|---|---:|---|---|---| +| 64 × 32 | 103056 | scale=5, disorder=0.8125, non_square_expansion=true, disorder_speed=1.4375, disorder_anisotropy=0.625, disorder_anisotropy_angle=-0.21875, tile_offset=[-0.3125, 0.4375] | F32 | Whole | +| 32 × 64 | 103057 | scale=5, disorder=0.8125, non_square_expansion=true, disorder_speed=1.4375, disorder_anisotropy=0.625, disorder_anisotropy_angle=-0.21875, tile_offset=[-0.3125, 0.4375] | U16 | Whole | +| 32 × 64 | 103057 | scale=5, disorder=0.8125, non_square_expansion=true, disorder_speed=1.4375, disorder_anisotropy=0.625, disorder_anisotropy_angle=-0.21875, tile_offset=[-0.3125, 0.4375] | U16 | Reopened | + +Disconnect the background input of the final pattern generator and set its background to opaque black. Expose that generator directly as F32. Keep its original iteration and switch controls. Cook the listed eight settings in order, then save and reopen settings 0, 3 and 6. [Connected-background final stage](#eight-level-two-child-drawing-across-equal-tile-and-render-windows) + +| Setting | Size | Seed | Exposed controls | One processor · F32 exact / total · max | Eight processors · F32 exact / total · max | +|---:|---|---:|---|---:|---:| +| 0 | 128 × 128 | 0 | Defaults | 16,384/16,384 · 0 | 13,245/16,384 · 4.47034836e-08 | +| 1 | 128 × 128 | 17 | Defaults | 16,384/16,384 · 0 | 12,488/16,384 · 2.98023224e-08 | +| 2 | 64 × 64 | 330251 | scale=1, disorder=0.21875, non_square_expansion=true | 4,096/4,096 · 0 | 3,238/4,096 · 4.47034836e-08 | +| 3 | 128 × 128 | 330277 | scale=1, disorder=0.46875, non_square_expansion=false | 16,384/16,384 · 0 | 12,721/16,384 · 2.98023224e-08 | +| 4 | 256 × 64 | 330307 | scale=1, disorder=0.71875, non_square_expansion=true | 13,278/16,384 · 4.47034836e-08 | 13,390/16,384 · 4.47034836e-08 | +| 5 | 64 × 256 | 330353 | scale=1, disorder=0.28125, non_square_expansion=true | 13,351/16,384 · 2.98023224e-08 | 13,719/16,384 · 2.98023224e-08 | +| 6 | 128 × 64 | 330371 | scale=2, disorder=0.9375, non_square_expansion=false | 6,916/8,192 · 2.98023224e-08 | 6,919/8,192 · 2.23517418e-08 | +| 7 | 128 × 128 | 0 | Defaults | 16,384/16,384 · 0 | 13,655/16,384 · 4.47034836e-08 | + +Across the three disconnected-background reopens, 39,684 of 40,960 F32 pixels matched the reference. The maximum error was 2.98023224e-08. The reference reproduced all 40,960 pixels on reopen. For the whole graph, two of its 15 reference reopens differed from their original F32 renders at 81 pixels in total. The whole root remains in progress. + +### Eight-level two-child drawing across equal tile and render windows + +A complete eight-level additive pattern can draw a parent followed by two leaves at each of its 16,384 terminal branches. The measured single-processor pixels agree with MaterialCraft's batch size of 5,460 physical tile copies when the render and tiling windows extend beyond the unit square. MaterialCraft now counts each stamp using the actual common window when both axes wrap. This changes how overlapping F32 contributions accumulate. The measured path requires a single emitted tree and the existing checks on shape, opacity, subdivisions and batch boundaries. [Two-child batch construction](../crates/nodes/src/pattern/tile_runs/two_children.rs) + +For the regression, start with a white grayscale F32 field. Place additive squares on all depth-seven parents and on their two leaves in slots 0 and 2. Superimpose the parent squares from second-level groups 0 and 5, assigning gains 2⁻²⁵ and −1 respectively. Keep all remaining draws active at gain .25. Use seed 158729, leaf width and height .875 in local coordinates, and leaf Y offset .5. Number the parents in a 32² readout in recursive child order. For each texel, interleave its five column and row bits, starting with the low column bit. [Regression geometry and readout](../crates/nodes/src/pattern/tests.rs) + +| Render and tiling windows (X then Y) | Output | Readout origin | Leaf X offset | Parents returning 2⁻²⁵ | Parents returning zero | +|---|---|---|---:|---:|---:| +| (−.5,1.5), (−.5,1.5) | 256² | (64,64) | 0 | 284 | 740 | +| (0,1), (−.5,1.5) | 128 × 256 | (0,64) | −1/512 | 274 | 750 | +| (0,1), (−.5,1.5) | 128 × 256 | (0,64) | .4995 | 252 | 772 | + +Each readout has one transition. The earlier renderer fails the first expanded-window readout at (0,0) relative to its origin. + +For an independent comparison, number the 64 depth-three subtrees in recursive slot order. Pair the first with the last, the second with the penultimate and so on. Hold the first subtree fixed and rotate the other 63 one position to the right each round. Place pair j in cell (j mod 8, floor(j/8)) of an eight-column grid within the unit window. Both parent streams draw at that cell, with gains −1 and 2⁻²⁵. Use leaf gain .25 and frame offset (0,.5). Reverse the two parent gains for the second polarity. For size index j = 0…3 use 256², 128 × 64, 64 × 128 and 128² and rounds 0, 17, 41 and 61. Use seed 322817 + 53j + polarity. Request F32 at all sizes and U8, U16 and F16 at 128 × 64. Save every third setting starting at the first, in size, polarity and U8/U16/F16/F32 order. Open the saved SBS in both applications. + +| Render window · tiling window | Reference | Earlier exact / total · max | Corrected exact / total · max | +|---|---|---:|---:| +| (−.5,1.5) on both axes, same tiling | one processor | 240,184/245,760 · 2.98023224e-08 | 245,760/245,760 · 0 | +| (−.5,1.5) on both axes, same tiling | eight processors | 238,992/245,760 · 2.98023224e-08 | 236,376/245,760 · 2.98023224e-08 | +| (−.5,1.5) on both axes, same tiling | one-processor reopen | 103,708/106,496 · 2.98023224e-08 | 106,496/106,496 · 0 | +| (−1.5,2.5) × (0,1), same tiling | one processor | 245,760/245,760 · 0 | 245,760/245,760 · 0 | +| (−1.5,2.5) × (0,1), same tiling | eight processors | 245,760/245,760 · 0 | 245,760/245,760 · 0 | +| (−1.5,2.5) × (0,1), same tiling | one-processor reopen | 106,496/106,496 · 0 | 106,496/106,496 · 0 | +| (.125,1.125) × (−.375,1.625), same tiling | one processor | 234,608/245,760 · 2.98023224e-08 | 245,760/245,760 · 0 | +| (.125,1.125) × (−.375,1.625), same tiling | eight processors | 230,912/245,760 · 2.98023224e-08 | 227,616/245,760 · 2.98023224e-08 | +| (.125,1.125) × (−.375,1.625), same tiling | one-processor reopen | 100,920/106,496 · 2.98023224e-08 | 106,496/106,496 · 0 | +| unit square, tiling (−.5,1.5) on both axes | one processor | 219,928/245,760 · 2.98023224e-08 | 219,928/245,760 · 2.98023224e-08 | +| unit square, tiling (−.5,1.5) on both axes | eight processors | 201,844/245,760 · 2.98023224e-08 | 201,844/245,760 · 2.98023224e-08 | +| unit square, tiling (−.5,1.5) on both axes | one-processor reopen | 93,580/106,496 · 2.98023224e-08 | 93,580/106,496 · 2.98023224e-08 | + +All 42 equal-window settings and all 15 corresponding reopens match on one processor. The shifted and square windows retain differences on eight processors. The unequal-window control retains its earlier buffers. The differences in this table occur in F32. + +Expose the final pattern generator of Noise Clouds 2 as F32. Keep both wrap axes enabled. Run each setting below at its listed seed, at seed + 17, then back at the listed seed. The parent and leaf counts are 16,384 and 32,768 per render. Replay each original F32 contribution at its measured texel. For the last setting, count the vertical copies before dividing into batches. + +| Size | Seed | Exposed controls | Common X and Y windows | Extra copies at seed / seed + 17 | +|---|---:|---|---|---:| +| 128 × 128 | 0 | scale=2, disorder=0.37 | (-0.5,1.5), (-0.5,1.5) | 0 / 0 | +| 128 × 64 | 411695 | scale=2, disorder=0.96875, non_square_expansion=false | (-0.5,1.5), (-0.5,1.5) | 0 / 0 | +| 512 × 128 | 412000 | scale=1, disorder=0.09375, non_square_expansion=true | (-1.5,2.5), (0,1) | 1,187 / 1,139 | + +The six replays match 180,224/180,224 F32 samples with maximum error zero. The unwrapped final-stage controls match every sample at the three original seeds. Turning off just the parent or just the leaf draws changes the compositing order. Their remaining differences are listed below. + +| Noise Clouds 2 stage or output | Exact / total · max | +|---|---:| +| Final F32 stage, one processor | 270,336/270,336 · 0 | +| Final F32 stage, eight processors | 260,928/270,336 · 2.98023224e-08 | +| Final F32 stage, wrapping off | 90,112/90,112 · 0 | +| Final F32 stage, unit windows and wrapping off | 90,112/90,112 · 0 | +| Parents alone | 88,196/90,112 · 1.49011612e-08 | +| Leaves alone | 89,305/90,112 · 3.7252903e-09 | +| Whole output, one processor | 270,336/270,336 · 0 | +| Whole output, eight processors | 270,334/270,336 · 1 | +| Whole output reopened, one processor | 270,336/270,336 · 0 | +| Whole output reopened, eight processors | 270,333/270,336 · 2 | + +Before the change, 261,034/270,336 isolated F32 samples matched on one processor, with maximum error 2.98023224e-08. When the eight-processor reference returned to the original seed, 86,460/90,112 samples matched its first render, with maximum error 2.23517418e-08. The one-processor reference reproduced all three starting buffers. The two U16 cases use stored levels for error, and the F32 case uses absolute error. + +Repeat the final-stage readout with the v2 graph. Use the following six settings in their listed order. Keep its background connected, then repeat with wrapping off. Save and reopen the first, third and fifth settings. + +| Size | Seed | Exposed controls | +|---|---:|---| +| 128 × 128 | 0 | Defaults | +| 128 × 128 | 0 | scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, tile_offset=[0.17, 0.29] | +| 128 × 64 | 411702 | scale=2, disorder=0.96875, disorder_speed=0.96875, disorder_anisotropy=0.96875, disorder_anisotropy_angle=0.71875, tile_offset=[0.625, -0.44140625], non_square_expansion=false | +| 512 × 128 | 412007 | scale=1, disorder=0.09375, disorder_speed=0.09375, disorder_anisotropy=0.09375, disorder_anisotropy_angle=-0.15625, tile_offset=[-0.25, 0.32421875], non_square_expansion=true | +| 256 × 64 | 325439 | scale=1, disorder=0.34375, disorder_speed=0.96875, disorder_anisotropy=0.96875, disorder_anisotropy_angle=0.71875, tile_offset=[0.625, -0.44140625], non_square_expansion=false | +| 64 × 128 | 325477 | scale=1, disorder=0.71875, disorder_speed=0.09375, disorder_anisotropy=0.09375, disorder_anisotropy_angle=-0.15625, tile_offset=[-0.25, 0.32421875], non_square_expansion=true | + +| v2 F32 final stage | Earlier exact / total · max | Corrected exact / total · max | +|---|---:|---:| +| One processor | 129,319/131,072 · 4.76837158e-07 | 129,319/131,072 · 4.76837158e-07 | +| Eight processors | 129,208/131,072 · 3.57627869e-07 | 129,208/131,072 · 3.57627869e-07 | +| Wrapping off | 16,260/16,384 · 1.1920929e-07 | 16,260/16,384 · 1.1920929e-07 | +| Reopened on one processor | 40,460/40,960 · 2.38418579e-07 | 40,460/40,960 · 2.38418579e-07 | + +The v2 stage retained all its earlier buffers across the six original settings and three reopens. With wrapping off, only the 128² default request rendered. The other five settings reached the execution budget. + +The following whole-graph comparisons read the requested storage format directly. Integer maxima are measured in stored levels and floating maxima in absolute error. All 60 settings and 15 reopens rendered. [Whole-cloud settings and original SBS saves](#four-cloud-noise-generators-and-repeated-saved-file-comparisons) + +| Package · reference | Rendered / requested | Exact settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:|---:| +| noise_clouds_2 · one processor | 60/60 | 60 | 85,760/85,760 · 0 | 296,192/296,192 · 0 | 93,952/93,952 · 0 | 253,440/253,440 · 0 | +| noise_clouds_2 · eight processors | 60/60 | 50 | 85,760/85,760 · 0 | 296,180/296,192 · 2 | 93,952/93,952 · 0 | 253,429/253,440 · 2.29477882e-05 | +| noise_clouds_2 · reference one versus eight | 60/60 | 50 | 85,760/85,760 · 0 | 296,180/296,192 · 2 | 93,952/93,952 · 0 | 253,429/253,440 · 2.29477882e-05 | +| noise_clouds_2 · one-processor SBS reopen | 15/15 | 15 | 4,096/4,096 · 0 | 94,976/94,976 · 0 | 1,536/1,536 · 0 | 22,528/22,528 · 0 | +| noise_clouds_2 · reference original versus reopened | 15/15 | 15 | 4,096/4,096 · 0 | 94,976/94,976 · 0 | 1,536/1,536 · 0 | 22,528/22,528 · 0 | + +Four whole v2 settings were checked both with a fresh session and with the ordinary cook cache. The raw buffers agreed between the two execution paths. + +| Size | Format | Seed | Exposed controls | One processor · exact / total · max | Eight processors · exact / total · max | +|---|---|---:|---|---:|---:| +| 16 × 16 | U8 | 0 | Defaults | 256/256 · 0 | 256/256 · 0 | +| 16 × 16 | U16 | 0 | Defaults | 256/256 · 0 | 256/256 · 0 | +| 32 × 16 | F16 | 169551 | scale=1, disorder=0.34375, disorder_speed=0.796875, disorder_anisotropy=0.171875, disorder_anisotropy_angle=-0.03125, tile_offset=[0.0751953125, -0.12890625] | 512/512 · 0 | 512/512 · 0 | +| 32 × 16 | F32 | 169551 | scale=1, disorder=0.34375, disorder_speed=0.796875, disorder_anisotropy=0.171875, disorder_anisotropy_angle=-0.03125, tile_offset=[0.0751953125, -0.12890625] | 507/512 · 5.96046448e-08 | 505/512 · 5.96046448e-08 | + +Noise Clouds 2 gained its last three differing pixels on one processor. All 15 saved settings also match. On eight processors 23 whole pixels differ across ten settings, compared with 20 across seven before the change. The reference itself varies with processor count and between repeated eight-processor renders at a fixed seed. All successful MaterialCraft reopens reproduce their original raw buffers. Both roots remain in progress. + +Only the two Noise Clouds 2 packages have both the required terminal structure and potentially non-unit windows in the 546-root inventory. Median process CPU time in alternating one-processor release runs, three per version, changed from 5.531 to 5.609 seconds for three final-stage cloud fields, 4.328 to 4.359 seconds for three square probe fields, 5.500 to 5.562 seconds for three whole Clouds 2 renders. All 456 release node and evaluator tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Tile-copy batches across repeated six-level quadrant trees + +Several six-level trees can contribute to the same pixel in a grayscale pattern. With all 1,024 depth-five parents and their four terminal children drawing, each first-level quadrant submits 1,280 stamps per tree. The four quadrants keep separate batches across repetitions. Within each tree, full batches of 5,460 physical tile copies are submitted in slot order 3, 0, 1, 2. At the end, partial batches composite in order 3, 2, 1, 0. A repeated tile can fill a batch before its other copy draws. MaterialCraft now records these boundaries before discarding stamps that miss the sample grid. The measured path covers complete trees of nonzero additive squares or analytic shape 8, with one outer repetition controller and center culling disabled. [Single-tree controls](#six-level-quadrant-draw-order-after-an-iteration-or-switch) · [Repeated-tree regression](../crates/nodes/src/pattern/tests/repeated_quadrants.rs) + +Build an original white F32 graph with roughness zero. Repeat a complete quadtree, with a square on every depth-five parent and depth-six leaf. Place neutral stamps at (.875,.90625) with gain .25. Center two marked squares on the same readout texel, each .875 readout pixels wide and high. Draw −1 first and the texel retains 2⁻²⁵. Draw 2⁻²⁵ first and the addition rounds back to white before the subtraction leaves zero. Repeat each marked pair with the gains exchanged. Keep unrelated stamps active. The Rust regression on the earlier cook returned 2⁻²⁵ at (0,0) for two trees where the measured order gives zero. + +With tiling off, enumerate a tree first by child slot and then recursively in child order, drawing each parent immediately before its four leaves. Pairwise strip crossings identified contiguous runs for one, two, three, four, five, eight and nine trees. With two and four trees, overlapping point markers independently confirmed all 10,239 and 20,479 neighboring stamp pairs in those runs. Each pair was read with both gain assignments. Five trees put 5,460 copies from each quadrant into its first batch. Nine trees fill two batches per quadrant. Thirteen trees gave the predicted result in all 302 additional marker pairs, including boundaries in a third full batch. + +To reproduce the output comparisons, number each leaf within its first-level slot from 0 to 1,023 in recursive child order. Use two, five or nine trees. Mark leaf 0 of slot 0 in the first tree against leaf 0 of slot 3 in the second. Mark leaves 0, 1, 63, 270, 271, 272, 273, 511, 888 and 1,023 in slot 0 of the last tree against the same leaves in slot 1 of the first. Finally compare leaves 0, 275, 300 and 900 of slots 2 and 3 in the last tree. Scan the pairs in that order and take the first set that shares no stamps. For pair j put both marks at normalized position ((8 + j mod 85 + .5)/128, (12 + floor(j/85) + .5)/128), with size .875/128. Exchange the gains for the second field. Request 128², 128 × 64, 64 × 128 and 256², using seed 319463 + 17 × tree count + 31 × size index + polarity (indices start at zero). Request F32 at each size and U8, U16 and F16 at 128 × 64. Reopen every third setting in both applications, starting with the first, in size, polarity and U8/U16/F16/F32 order. + +| Tree count · comparison | Earlier exact / total · max | Corrected exact / total · max | +|---|---:|---:| +| 2 · one processor | 245,720/245,760 · 2.98023224e-08 | 245,760/245,760 · 0 | +| 2 · eight processors | 245,720/245,760 · 2.98023224e-08 | 245,760/245,760 · 0 | +| 2 · one-processor SBS reopen | 106,476/106,496 · 2.98023224e-08 | 106,496/106,496 · 0 | +| 5 · one processor | 245,660/245,760 · 2.98023224e-08 | 245,760/245,760 · 0 | +| 5 · eight processors | 245,705/245,760 · 2.98023224e-08 | 245,715/245,760 · 2.98023224e-08 | +| 5 · one-processor SBS reopen | 106,446/106,496 · 2.98023224e-08 | 106,496/106,496 · 0 | +| 9 · one processor | 245,710/245,760 · 2.98023224e-08 | 245,760/245,760 · 0 | +| 9 · eight processors | 245,710/245,760 · 2.98023224e-08 | 245,760/245,760 · 0 | +| 9 · one-processor SBS reopen | 106,471/106,496 · 2.98023224e-08 | 106,496/106,496 · 0 | + +The five-tree field still differs from the eight-processor reference at 45 pixels, maximum 2⁻²⁵. All 15 one-processor reopens match. + +For a horizontal wrapping check, use four trees and move selected neutral leaves to x = 0, preserving their y coordinate. This adds one copy for each selected leaf. With q extra copies in a tree and slot, select the leaves at indices floor(768j/q), j from 0 to q−1, in the list of the last three children of each of its 256 parents. Counts per slot below include all four trees. In the first two profiles use the same per-tree counts as the corresponding cloud source. The remaining profiles distribute extras e across the four trees as floor((e + t)/4) for t = 0…3. Verify parent order and place signed point markers on either side of batch boundaries. + +| Profile | Aggregate copies in slots 0, 1, 2, 3 | Parent positions matched | Neighboring marker pairs matched | +|---|---|---:|---:| +| Clouds 1 | 5,495, 5,517, 5,525, 5,510 | 4,096/4,096 | 209/209 | +| Clouds 2 | 5,451, 5,518, 5,483, 5,715 | 4,096/4,096 | 198/198 | +| Slot 0 fills | 5,462, 5,457, 5,455, 5,452 | 4,096/4,096 | 172/172 | +| All four exactly full | 5,460, 5,460, 5,460, 5,460 | 4,096/4,096 | 165/165 | +| All four one copy short | 5,459, 5,459, 5,459, 5,459 | 4,096/4,096 | 165/165 | +| Slots 0 and 2 fill | 5,462, 5,455, 5,465, 5,450 | 4,096/4,096 | 177/177 | + +For the first two profiles the extra copies in each tree and slot are listed below. At 5,459 total copies in each slot the final order is 3, 2, 1, 0. At 5,460 in each slot the observed order is 3, 0, 1, 2. + +| Tree index | First cloud profile · extra copies by slot | Second cloud profile · extra copies by slot | +|---:|---|---| +| 0 | 0, 0, 0, 0 | 0, 0, 0, 0 | +| 1 | 134, 91, 103, 83 | 78, 95, 122, 178 | +| 2 | 165, 212, 210, 199 | 203, 196, 129, 246 | +| 3 | 76, 94, 92, 108 | 50, 107, 112, 171 | + +Two asymmetric profiles fill selected slots in the third tree and the others in the fourth. To reproduce their per-tree extras, use (90,616,97,72), (100,622,80,94), (100,630,95,95), (121,160,102,110) for the first and (130,99,623,625), (105,90,641,620), (100,117,634,670), (83,113,43,152) for the second. Point markers confirmed 260/260 comparisons in each profile. Grouping the full batches by round irrespective of the tree that filled each one gave 80/260 in each. One strip comparison in the first profile gave inconsistent rankings across its two gain assignments. The 520 point comparisons use separate captures. + +A square centered on the wrapping seam can itself straddle the 5,460th copy. In the first profile use draw 20,433 (zero-based in traversal order), with controls 0 and 19,138. In the second use draw 19,178 with controls 20,255 and 20,479. Place the marked square at x = 0, y = 23.5/128, width 2.75/128 and height .875/128. Center the control squares on columns 0 and 127 of row 23. Exchange the gains, then transpose centers and sizes and enable vertical wrapping alone. With negative gain on the split square the two readouts are zero and 2⁻²⁵. Swapping gains exchanges the readouts. Across all eight 128² images exact pixels improved from 131,064/131,072 · 2.98023224e-08 to 131,072/131,072 · 0. + +Expose the six-level generator of the two original cloud packages as F32. The stage renders at half the graph dimensions. Use the original controls and windows at the 128 × 64 request, then disable wrapping. For forced two- and four-tree runs use unit windows and wrapping off, hold the switch on its tree arm, and repeat the 16², 128² and 128 × 64 settings, then the 128² setting with seed 312923 + 37i. Here i is 244 or 246. [Graph settings and intermediate readback](#six-level-quadrant-draw-order-after-an-iteration-or-switch) + +| Six-level stage | Earlier F32 exact / total · max | Corrected F32 exact / total · max | +|---|---:|---:| +| Clouds 1 · original wrapping | 1,924/2,048 · 1.49011612e-07 | 2,048/2,048 · 0 | +| Clouds 1 · wrapping off | 1,959/2,048 · 1.1920929e-07 | 2,048/2,048 · 0 | +| Clouds 1 · two trees, unit windows | 8,640/10,304 · 2.68220901e-07 | 10,304/10,304 · 0 | +| Clouds 1 · four trees, unit windows | 5,973/10,304 · 2.98023224e-07 | 10,304/10,304 · 0 | +| Clouds 2 · original wrapping | 1,480/2,048 · 4.47034836e-08 | 2,048/2,048 · 0 | +| Clouds 2 · wrapping off | 1,678/2,048 · 4.47034836e-08 | 2,048/2,048 · 0 | +| Clouds 2 · two trees, unit windows | 7,390/10,304 · 8.94069672e-08 | 10,304/10,304 · 0 | +| Clouds 2 · four trees, unit windows | 6,341/10,304 · 1.49011612e-07 | 10,304/10,304 · 0 | + +The whole-graph comparisons use the original settings and saved SBS packages. Integer maxima use stored levels and floating maxima use absolute error. [Whole-cloud settings and saved files](#four-cloud-noise-generators-and-repeated-saved-file-comparisons) + +| Whole package · comparison | Rendered / requested | Exact settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:|---:| +| noise_clouds_1 · one processor | 58/60 | 39 | 85,760/85,760 · 0 | 294,043/294,144 · 1 | 93,952/93,952 · 0 | 251,314/251,392 · 1.52587891e-05 | +| noise_clouds_1 · eight processors | 58/60 | 37 | 85,760/85,760 · 0 | 294,045/294,144 · 1 | 93,950/93,952 · 0.00048828125 | 251,286/251,392 · 1.52587891e-05 | +| noise_clouds_1 · reference one versus eight | 60/60 | 35 | 85,760/85,760 · 0 | 296,060/296,192 · 1 | 93,950/93,952 · 0.00048828125 | 253,328/253,440 · 1.52587891e-05 | +| noise_clouds_1 · one-processor SBS reopen | 14/15 | 8 | 4,096/4,096 · 0 | 92,900/92,928 · 1 | 1,536/1,536 · 0 | 22,522/22,528 · 1.52587891e-05 | +| noise_clouds_1 · reference original versus reopened | 15/15 | 15 | 4,096/4,096 · 0 | 94,976/94,976 · 0 | 1,536/1,536 · 0 | 22,528/22,528 · 0 | +| noise_clouds_2 · one processor | 60/60 | 57 | 85,760/85,760 · 0 | 296,190/296,192 · 1 | 93,952/93,952 · 0 | 253,439/253,440 · 2.28285789e-05 | +| noise_clouds_2 · eight processors | 60/60 | 53 | 85,760/85,760 · 0 | 296,182/296,192 · 2 | 93,952/93,952 · 0 | 253,430/253,440 · 2.29477882e-05 | +| noise_clouds_2 · reference one versus eight | 60/60 | 50 | 85,760/85,760 · 0 | 296,180/296,192 · 2 | 93,952/93,952 · 0 | 253,429/253,440 · 2.29477882e-05 | +| noise_clouds_2 · one-processor SBS reopen | 15/15 | 15 | 4,096/4,096 · 0 | 94,976/94,976 · 0 | 1,536/1,536 · 0 | 22,528/22,528 · 0 | +| noise_clouds_2 · reference original versus reopened | 15/15 | 15 | 4,096/4,096 · 0 | 94,976/94,976 · 0 | 1,536/1,536 · 0 | 22,528/22,528 · 0 | + +Clouds 1 gained 116 exact whole pixels against the one-processor reference. Two settings still exhaust the execution budget. Clouds 2 gained 22 and matched all 123,136 pixels across its 15 saved settings. Three single-processor whole pixels still differ. At 128², scale 2, disorder .37 and seed zero, one U16 pixel differs by one level. At 512 × 128, scale 1, disorder .09375, nonsquare expansion on and seed 412000, one U16 pixel differs by one level and one F32 pixel differs by 2.28285789e−5. The eight-processor captures also retain differences. All successful local saves reproduce the original MaterialCraft output. + +Only these two inventory roots combine the required outer controller, full six levels and parent/leaf shape in the reachability scan. In alternating release runs on one processor, median process CPU time including loading and raw output readback changed from 3.547 to 3.719 seconds for three single-tree square fields, 5.469 to 5.500 seconds for three four-tree cloud fields, 5.109 to 5.031 seconds for three whole Clouds 2 renders. All 456 release node and evaluator tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Compositing a single seven-level tree through pattern controls + +A switch, routing dot or single repetition between quadrants can pass the same seven-level tree to the renderer. MaterialCraft now recognizes its sixteen grandchildren through these controls. It counts the quadrant trees actually submitted. A second tree or an inner iteration with multiple submitted branches uses the existing traversal. [Measured grandchild order and eligible layouts](#compositing-complete-seven-level-additive-quadrant-trees) + +Construct the [four overlapping analytic leaves](#six-level-quadrant-draw-order-after-an-iteration-or-switch) at depth seven. Use the same eight gain tuples and index j, with seed 309511 + 53j. Repeat the third and fourth tuples at 64 × 32 and 32 × 64 with seeds 309949 and 309971. Compare the F32 bit patterns. The Rust regression at (15,15) previously returned zero through the fourth-of-nine switch for gains (1,2⁻²⁴,−1,0). Both the direct graph and the switch now return the observed 2⁻²⁴. [Regression fixture](../crates/nodes/src/pattern/tests.rs) + +| F32 comparisons | Earlier exact / total · max | Corrected exact / total · max | +|---|---:|---:| +| Direct tree | 12,288/12,288 · 0 | 12,288/12,288 · 0 | +| One active tree through five control configurations | 52,480/61,440 · 1.1920929e-07 | 61,440/61,440 · 0 | +| Two active trees, direct repetition or two of nine | 20,264/24,576 · 2.38418579e-07 | 20,264/24,576 · 2.38418579e-07 | +| Three saved fourth-of-nine settings | 2,496/3,072 · 1.1920929e-07 | 3,072/3,072 · 0 | + +The five configurations use one repeated branch, the initial branch alone, a constant switch, the fourth of nine repetitions, and one inner repetition at each outgoing edge of depth two. All 50 reference buffers equal their direct-tree counterparts. Save the fourth-of-nine graph in MaterialCraft and reopen it in both applications at j = 1, 13 and 48. The multiple-tree controls retained every previous local output bit. + +Expose the first pattern generator in each package directly as F32. Repeat with its outer repeat forced to one and its switch forced to the tree, then with the outer repeat and switch bypassed. Leave the inner nodes and parameters intact. At index i use 16 × 32, 64 × 32, 32 × 64 and 64² with seed 288101 + 43i + 79j (j = 0…3), then 128² with defaults and seed zero. The source extent follows the graph. The four seeded requests use the exposed controls shown below. + +| Index · package | Defaults and changed controls in size order | +|---|---| +| 264 · noise_dirt_3 | defaults / non_square_expansion=on, disorder=0.0, scale=1 / non_square_expansion=on, disorder=0.8125, scale=2 / scale=2, disorder=0.21875, non_square_expansion=on | +| 265 · noise_dirt_3_v2 | defaults / disorder=0.0, disorder_anisotropy=0, scale=1, non_square_expansion=on, tile_offset=[0.0, 0.0], disorder_anisotropy_angle=0, disorder_speed=1 / disorder=0.8125, disorder_anisotropy=0.625, scale=2, non_square_expansion=on, tile_offset=[-0.3125, 0.4375], disorder_anisotropy_angle=-0.21875, disorder_speed=1.4375 / scale=2, disorder=0.21875, disorder_speed=0.21875, disorder_anisotropy=0.21875, disorder_anisotropy_angle=-0.03125, tile_offset=[-0.125, 0.21484375], non_square_expansion=on | +| 279 · noise_fur_2 | defaults / scale=1, waves_scale=0.0, waves_rotation=0.0, non_square_expansion=on / scale=3, waves_scale=0.25, waves_rotation=0.8125, non_square_expansion=on / scale=2, waves_scale=0.5625, waves_rotation=0.125, non_square_expansion=off | + +| Stage · five requests | Earlier F32 exact / total · max | Corrected F32 exact / total · max | +|---|---:|---:| +| noise_dirt_3 · original controls | 6,269/6,272 · 2.98023224e-08 | 6,271/6,272 · 2.98023224e-08 | +| noise_dirt_3 · one tree | 6,270/6,272 · 2.98023224e-08 | 6,272/6,272 · 0 | +| noise_dirt_3 · outer controls bypassed | 6,272/6,272 · 0 | 6,272/6,272 · 0 | +| noise_dirt_3_v2 · original controls | 6,251/6,272 · 5.96046448e-08 | 6,262/6,272 · 2.98023224e-08 | +| noise_dirt_3_v2 · one tree | 6,261/6,272 · 5.96046448e-08 | 6,272/6,272 · 0 | +| noise_dirt_3_v2 · outer controls bypassed | 6,262/6,272 · 2.98023224e-08 | 6,271/6,272 · 1.49011612e-08 | +| noise_fur_2 · original controls | 20,582/25,088 · 1.1920929e-07 | 23,716/25,088 · 1.1920929e-07 | +| noise_fur_2 · one tree | 21,643/25,088 · 1.1920929e-07 | 25,088/25,088 · 0 | +| noise_fur_2 · outer controls bypassed | 25,088/25,088 · 0 | 25,088/25,088 · 0 | + +The inner controls in the v2 dirt source are still present in the bypassed graph. One F32 pixel differs there. The fur source with one forced tree matches all 25,088 samples. At 128² with defaults, the original fur stage stores U16. Rounding the reference F32 probe to U16 reproduces 15,872/16,384 samples in that original stage, maximum one level. Whole comparisons below read the actual requested output format. + +| Whole package · comparison | Rendered / requested | Exact settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:|---:| +| noise_dirt_3 · one processor | 58/60 | 35 | 99,840/99,840 · 0 | 334,838/334,848 · 1 | 101,888/101,888 · 0 | 239,325/240,896 · 1.52587891e-05 | +| noise_dirt_3 · eight processors | 58/60 | 36 | 99,840/99,840 · 0 | 334,843/334,848 · 1 | 101,888/101,888 · 0 | 239,368/240,896 · 1.52587891e-05 | +| noise_dirt_3 · reference one versus eight | 60/60 | 38 | 99,840/99,840 · 0 | 338,935/338,944 · 1 | 101,888/101,888 · 0 | 243,043/244,992 · 1.1920929e-07 | +| noise_dirt_3 · SBS reopen on one processor | 11/12 | 7 | 26,624/26,624 · 0 | 51,705/51,712 · 1 | — | 66,682/67,072 · 5.96046448e-08 | +| noise_dirt_3 · reference original versus reopened | 12/12 | 11 | 26,624/26,624 · 0 | 51,712/51,712 · 0 | — | 71,158/71,168 · 2.98023224e-08 | +| noise_fur_2 · one processor | 62/62 | 37 | 99,840/99,840 · 0 | 348,639/348,672 · 1 | 99,840/99,840 · 0 | 246,085/273,152 · 2.38418579e-07 | +| noise_fur_2 · eight processors | 62/62 | 23 | 99,839/99,840 · 1 | 348,617/348,672 · 1 | 99,839/99,840 · 0.000122070312 | 232,221/273,152 · 2.38418579e-07 | +| noise_fur_2 · reference one versus eight | 62/62 | 23 | 99,839/99,840 · 1 | 348,608/348,672 · 1 | 99,839/99,840 · 0.000122070312 | 223,660/273,152 · 2.38418579e-07 | +| noise_fur_2 · SBS reopen on one processor | 13/13 | 9 | 4,096/4,096 · 0 | 119,799/119,808 · 1 | 4,096/4,096 · 0 | 25,006/25,600 · 8.94069672e-08 | +| noise_fur_2 · reference original versus reopened | 13/13 | 13 | 4,096/4,096 · 0 | 119,808/119,808 · 0 | 4,096/4,096 · 0 | 25,600/25,600 · 0 | + +Noise Fur 2 gained 19,867 exact whole pixels against the one-processor capture and 4,107 across its reopens. Its match against the eight-processor capture declined by 3,892 pixels. The original dirt package retained its whole and saved counts. The two processor settings produce different raw reference buffers in both roots. All successful local reopens reproduced the original MaterialCraft buffer. Execution-budget errors contribute no pixels. [Noise Dirt 3 settings and failed requests](#whole-outputs-and-saved-settings-for-noise-dirt-2-and-noise-dirt-3) + +
+Noise Fur 2 procedural settings + +Controls appear in the order `non_square_expansion`, `scale`, `waves_rotation`, `waves_scale`. + +| Size | Seed | Controls | Formats | Reopened | Execution budget reached | +|---|---:|---|---|---|---| +| 128 × 128 | 0 | Defaults | U16, U8, F16, F32 | U16 | — | +| 256 × 256 | 0 | Defaults | U16 | — | — | +| 128 × 128 | 42 | Defaults | U16 | — | — | +| 128 × 128 | 0 | default, 2, 0.2, 0.25 | U16 | — | — | +| 32 × 32 | 113 | default, 2, 0.2, 0.25 | F32 | — | — | +| 64 × 64 | 42 | default, 2, 0.2, 0.25 | U8, U16, F16, F32 | U8 | — | +| 16 × 16 | 75892 | Defaults | F32 | — | — | +| 32 × 32 | 75893 | on, 1, 0.0, 0.0 | F32 | F32 | — | +| 32 × 32 | 75894 | off, 2, 0.125, 0.5625 | U8, U16, F16, F32 | — | — | +| 64 × 32 | 75898 | on, 3, 0.8125, 0.25 | F32 | F32 | — | +| 32 × 64 | 75899 | on, 3, 0.8125, 0.25 | U16 | — | — | +| 64 × 64 | 75900 | off, 2, 0.125, 0.5625 | F32 | — | — | +| 128 × 64 | 75901 | off, 2, 0.125, 0.5625 | F32 | — | — | +| 64 × 128 | 75901 | off, 2, 0.125, 0.5625 | U16 | — | — | +| 128 × 128 | 75903 | Defaults | F32 | F32 | — | +| 16 × 32 | 0 | Defaults | U8, U16, F16, F32 | — | — | +| 32 × 16 | 42 | on, 2, -0.28125, 0.21875 | U16, F32 | U16 | — | +| 64 × 64 | 433714 | off, 1, 0.4375, 0.9375 | U8, U16, F16, F32 | F32 | — | +| 128 × 32 | 433751 | on, 3, -0.453125, 0.046875 | U16, F32 | — | — | +| 32 × 128 | 433788 | off, 2, 0.0625, 0.5625 | U8, U16, F16, F32 | F16 | — | +| 256 × 128 | 433862 | off, 3, -0.171875, 0.328125 | U16, F32 | U16 | — | +| 128 × 256 | 433899 | on, 1, 0.3125, 0.8125 | U16, F32 | — | — | +| 256 × 256 | 42 | Defaults | U8, U16, F16, F32 | U16 | — | +| 512 × 128 | 433973 | on, 1, 0.171875, 0.671875 | U16, F32 | — | — | +| 16 × 32 | 300098 | Defaults | U16, F32 | U16 | — | +| 64 × 32 | 300177 | on, 1, 0.0, 0.0 | U8, U16, F16, F32 | F32 | — | +| 32 × 64 | 300256 | on, 3, 0.8125, 0.25 | U8, U16, F16, F32 | — | — | +| 64 × 64 | 300335 | off, 2, 0.125, 0.5625 | U16, F32 | U16 | — | + +
+ +Median process CPU time in alternating release runs, three per version, changed from 8.172 to 7.984 seconds for four single-tree renders, 8.688 to 8.953 seconds for four two-tree renders, 17.109 to 17.016 seconds for three Noise Dirt 3 renders. All 455 node and evaluator release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Six-level quadrant draw order after an iteration or switch + +A single grayscale quadrant tree with six levels of subdivision draws the initial quadrant and then composites its four child streams in reverse slot order. Outer iterations can still be waiting on the evaluation stack while the only active tree runs. The renderer now records where the four children start relative to those waiting iterations. A second active tree invalidates these ranges. Parameter evaluation, seed inheritance and the order inside each child stream follow the original traversal. [Direct six-level probes](#draw-order-at-six-quadrant-subdivisions) + +For an independent F32 probe, center one leaf from each first-level subtree on pixel (15,15) of a 32² image. Use the direct six-level construction with analytic pattern 4 on the leaves and include all four children at every subdivision. Start from black. Use the four gains from each row, keep the stamp size at (.75,.75) and use seed 306293 + 17j. Each tuple applies to slots zero through three. Repeat the third and fourth tuples at 64 × 32 and 32 × 64 with seeds 306719 and 306763. At the test pixel the fourth outer iteration passes the tree and the other eight iterations take the empty switch arm. For gains (1,2⁻²⁴,−1,0) the earlier renderer returned zero and the reference returned 2⁻²⁴. [Regression fixture](../crates/nodes/src/pattern/tests.rs) + +| j | Seed | Gains in slot order | +|---:|---:|---| +| 0 | 306293 | 0.25, 0.125, 0.375, 0.0625 | +| 1 | 306310 | 1, −1, 2⁻²⁴, 0 | +| 3 | 306344 | 1, 2⁻²⁴, −1, 0 | +| 8 | 306429 | −1, 1, 0, 2⁻²⁴ | +| 13 | 306514 | 2⁻²⁴, 1, −1, 0 | +| 21 | 306650 | 0, −1, 1, 2⁻²⁴ | +| 32 | 306837 | −1, 1, 2⁻²⁴, 2⁻²⁵ | +| 48 | 307109 | 2⁻²⁴, 2⁻²⁵, −1, 1 | + +One repeated branch, the initial branch alone, a constant switch, the fourth of nine repetitions, and a single inner repetition after depth two each reproduce the direct reference image. Across these 50 renders the earlier cook matched 53,760/61,440 · 5.96046448e-08 and the corrected cook matches 61,440/61,440 · 0. The fourth-of-nine graph was saved and reopened in both applications at the three square settings with j = 1, 13 and 48. Exact pixels improved from 2,560/3,072 · 5.96046448e-08 to 3,072/3,072 · 0. The two-tree and two-of-nine controls retain their earlier raw buffers and match 21,504/24,576 · 1.1920929e-07. Five-level controls remain exact. The seven-level case that passes through the outer switch still differs in this revision. + +Expose the six-level pattern stage as F32. It is the first generator in Clouds 1 and the middle generator in Clouds 2. Request whole graph sizes 16², 128², 128 × 64 and 256² at the following settings. The stage renders at half the requested width and height. Values use the original package identifiers. + +| Requested size | Seed | Exposed controls | +|---|---:|---| +| 16 × 16 | 103017 / 103039 for Clouds 1 / 2 | Defaults | +| 128 × 128 | 0 | Defaults | +| 128 × 64 | 411681 / 411695 for Clouds 1 / 2 | scale=2, disorder=0.96875, non_square_expansion=false | +| 256 × 256 | 0 | Defaults | + +| Six-level stage · four settings | Earlier F32 exact / total · max | Corrected F32 exact / total · max | +|---|---:|---:| +| Clouds 1 · original controls | 20,397/22,592 · 1.49011612e-07 | 22,468/22,592 · 1.49011612e-07 | +| Clouds 1 · wrapping off | 21,369/22,592 · 1.49011612e-07 | 22,503/22,592 · 1.1920929e-07 | +| Clouds 1 · one outer repetition, unit windows, wrapping off | 21,350/22,592 · 1.49011612e-07 | 22,592/22,592 · 0 | +| Clouds 1 · one child at each subdivision | 22,592/22,592 · 0 | 22,592/22,592 · 0 | +| Clouds 2 · original controls | 16,239/22,592 · 5.96046448e-08 | 22,024/22,592 · 4.47034836e-08 | +| Clouds 2 · wrapping off | 19,141/22,592 · 4.47034836e-08 | 22,222/22,592 · 4.47034836e-08 | +| Clouds 2 · one outer repetition, unit windows, wrapping off | 19,017/22,592 · 5.96046448e-08 | 22,592/22,592 · 0 | +| Clouds 2 · one child at each subdivision | 22,592/22,592 · 0 | 22,592/22,592 · 0 | + +With original controls the 128 × 64 request emits four trees in each six-level stage. Its remaining error is visible before final quantization. The other three requests emit one tree and match every F32 stage sample. A separate replay kept every original F32 contribution and its sample position. Reversing the four 1,280-draw streams gave the measured single-tree images. Each stream has 256 depth-five draws and 1,024 depth-six draws. + +Repeat the 60 whole settings and 15 SBS reopens for each root. Maxima use stored integer levels or absolute floating-point differences. [Whole-graph settings](#four-cloud-noise-generators-and-repeated-saved-file-comparisons) + +| Package · comparison | Rendered / requested | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| noise_clouds_1 · one processor | 58/60 | 85,760/85,760 · 0 | 293,987/294,144 · 1 | 93,952/93,952 · 0 | 251,254/251,392 · 1.52587891e-05 | +| noise_clouds_1 · eight processors | 58/60 | 85,760/85,760 · 0 | 294,027/294,144 · 1 | 93,950/93,952 · 0.00048828125 | 251,272/251,392 · 1.52587891e-05 | +| noise_clouds_1 · reference one versus eight | 60/60 | 85,760/85,760 · 0 | 296,060/296,192 · 1 | 93,950/93,952 · 0.00048828125 | 253,328/253,440 · 1.52587891e-05 | +| noise_clouds_1 · after reopening, one processor | 14/15 | 4,096/4,096 · 0 | 92,883/92,928 · 1 | 1,536/1,536 · 0 | 22,512/22,528 · 1.52587891e-05 | +| noise_clouds_1 · reference original versus reopened | 15/15 | 4,096/4,096 · 0 | 94,976/94,976 · 0 | 1,536/1,536 · 0 | 22,528/22,528 · 0 | +| noise_clouds_2 · one processor | 60/60 | 85,760/85,760 · 0 | 296,179/296,192 · 2 | 93,952/93,952 · 0 | 253,428/253,440 · 2.29477882e-05 | +| noise_clouds_2 · eight processors | 60/60 | 85,760/85,760 · 0 | 296,171/296,192 · 2 | 93,952/93,952 · 0 | 253,427/253,440 · 2.29477882e-05 | +| noise_clouds_2 · reference one versus eight | 60/60 | 85,760/85,760 · 0 | 296,180/296,192 · 2 | 93,952/93,952 · 0 | 253,429/253,440 · 2.29477882e-05 | +| noise_clouds_2 · after reopening, one processor | 15/15 | 4,096/4,096 · 0 | 94,971/94,976 · 2 | 1,536/1,536 · 0 | 22,524/22,528 · 2.29477882e-05 | +| noise_clouds_2 · reference original versus reopened | 15/15 | 4,096/4,096 · 0 | 94,976/94,976 · 0 | 1,536/1,536 · 0 | 22,528/22,528 · 0 | + +Against the one-processor captures, Clouds 1 improved from 724,871 to 724,953/725,248 exact pixels and Clouds 2 from 729,305 to 729,319/729,344. At 128 × 64 with seed 411695, the first and third Clouds 2 generators match every U16 sample. The six-level generator matches 2,047/2,048, maximum one stored level. The first blend retains that difference. The second blend differs at two output pixels, and the final F32 maximum is 2.28881836e−5. Every successful MaterialCraft save reproduced its original raw buffer. Settings that returned an execution-budget error contribute no pixels. + +Noise Fluid retained 1,266,944/1,266,944 whole pixels at both processor counts and 271,872/271,872 across 15 reopens. [Noise Fluid settings](#noise-fluid-across-procedural-controls-and-stored-formats) + +The color and grayscale tile-patch roots each retained 21,366,784/21,366,784 whole pixels across 127 settings through 1024². The 122 reopened settings per root matched all 22,283,264 stored pixels. [Tile-patch settings and fields](#diagonal-blur-across-rectangular-tile-edges) + +In six interleaved release runs on one processor, median process CPU time including loading and raw readback changed from 7.875 to 7.781 seconds for four single-tree renders, 8.078 to 7.859 seconds for four two-tree renders, and 10.766 to 10.719 seconds for three whole Clouds 2 renders. All 455 release node and evaluator tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Noise Fluid across procedural controls and stored formats + +Noise Fluid matches all 1,266,944 pixels in 71 distinct settings on both one and eight processors. The first 53 repeat the earlier measurements against both fresh captures and the original archived buffers. They include the 273 U16 and 171 F32 pixels that previously differed. The generator has no image inputs. Every saved case reopened in both applications and reproduced its original raw values. [Earlier whole outputs and controls](#diagonal-blur-across-rectangular-tile-edges) + +| Comparison | Settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| One processor | 71 | 138,752/138,752 · 0 | 565,248/565,248 · 0 | 138,752/138,752 · 0 | 424,192/424,192 · 0 | +| Eight processors | 71 | 138,752/138,752 · 0 | 565,248/565,248 · 0 | 138,752/138,752 · 0 | 424,192/424,192 · 0 | +| Earlier reference buffers | 53 | 95,744/95,744 · 0 | 495,616/495,616 · 0 | 95,744/95,744 · 0 | 354,560/354,560 · 0 | +| Reopened in both applications | 15 | 20,480/20,480 · 0 | 143,872/143,872 · 0 | 2,048/2,048 · 0 | 105,472/105,472 · 0 | +| Reopened versus original reference | 15 | 20,480/20,480 · 0 | 143,872/143,872 · 0 | 2,048/2,048 · 0 | 105,472/105,472 · 0 | + +Expose the initial pattern generator directly at its original U16 precision. The original stage and the isolated output agree in all four cases. The following counts compare MaterialCraft with those captures. Each maximum for the stage is in stored U16 levels. The whole comparison uses the format shown. + +| Size, seed | Whole format | Earlier initial pattern · max | Current initial pattern · max | Earlier whole output · max | Current whole output · max | +|---|---|---:|---:|---:|---:| +| 32 × 64, 33632 | U16 | 502/512 · 1 | 512/512 · 0 | 2,003/2,048 · 1 | 2,048/2,048 · 0 | +| 64 × 32, 33631 | F32 | 499/512 · 1 | 512/512 · 0 | 1,989/2,048 · 1.52587891e-05 | 2,048/2,048 · 0 | +| 128 × 32, 433660 | U16 | 1,010/1,024 · 1 | 1,024/1,024 · 0 | 4,037/4,096 · 1 | 4,096/4,096 · 0 | +| 64 × 32, 286222 | F32 | 512/512 · 0 | 512/512 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | + +The four isolated sources and their downstream outputs first match in the build that projects stamp vertices from the pixel-center origin in scaled windows. The preceding build retains the earlier errors. To measure the projection independently, use one fading bell stamp (type 12, variation .78), maximum blend, black background, no tiling, unit opacity and zero roughness. Use the same window for render and tiling. The four width, height and window combinations are (16,32,−1,2,−2.5,3.5), (32,16,−2.5,3.5,−1,2), (64,16,−5.5,6.5,−1,2) and (32,16,−1.5,2.5,−.5,1.5). The window values are left, right, top and bottom. [Pixel-center projection](#projecting-stamp-vertices-relative-to-pixel-centers-in-scaled-windows) + +At each size use these (center, size, turns) settings in order. The first is ((.52734375,.40625),(2.25,1.25),.25), the second ((.6015625,.4375),(1.8125,.96875),.25), and the third ((.4375,.65625),(1.1875,.6875),0). Render all four formats at the first setting and U16 and F32 at the others. Use seed 290171 + 23j + 7m, where j indexes the window and m the stamp. Reopen the first U8, first F32 and third U16 settings at each size. At pixel (9,15) of the 16 × 32 second stamp, the old F32 bits were `3f0cd03f`. The reference and current cook give `3f0cd037`. The regression checks this pixel through the node’s normal cook. [Fading stamp regression](../crates/nodes/src/pattern/tests.rs) + +| Independent stamp | Settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Earlier, one processor | 32 | 2,560/2,560 · 0 | 7,680/7,680 · 0 | 2,560/2,560 · 0 | 7,661/7,680 · 4.76837158e-07 | +| Corrected, one processor | 32 | 2,560/2,560 · 0 | 7,680/7,680 · 0 | 2,560/2,560 · 0 | 7,680/7,680 · 0 | +| Corrected, eight processors | 32 | 2,560/2,560 · 0 | 7,680/7,680 · 0 | 2,560/2,560 · 0 | 7,680/7,680 · 0 | +| After reopening | 12 | 2,560/2,560 · 0 | 2,560/2,560 · 0 | — | 2,560/2,560 · 0 | + +All 454 node and evaluator release tests, workspace formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +
+Reproduce all 71 whole renders and the 15 reopen checks + +Only changed controls are listed. Use graph defaults for the rest. Reopen the formats listed in the last column. + +| Size | Seed | Controls | Formats | Reopened | +|---|---:|---|---|---| +| 128 × 128 | 0 | Defaults | U16, U8, F16, F32 | U16, U8 | +| 256 × 256 | 0 | Defaults | U16, F32 | — | +| 128 × 128 | 42 | Defaults | U16 | — | +| 128 × 128 | 0 | `scale` 2, `disorder` 0.37, `pattern_size` (0.8, 1.2), `warp_intensity` 0.4 | U16 | — | +| 64 × 64 | 42 | `scale` 2, `disorder` 0.37, `pattern_size` (0.8, 1.2), `warp_intensity` 0.4 | U8, U16, F16, F32 | U16 | +| 32 × 32 | 113 | `scale` 2, `disorder` 0.37, `pattern_size` (0.8, 1.2), `warp_intensity` 0.4 | F32 | — | +| 16 × 16 | 33625 | Defaults | F32 | — | +| 32 × 32 | 33626 | `scale` 1, `disorder` 0.0, `warp_intensity` 0.0, `pattern_size` (0.5, 1.0), `non_square_expansion` on | F32 | F32 | +| 32 × 32 | 33627 | `scale` 2, `disorder` 0.3125, `warp_intensity` 0.1875, `pattern_size` (0.625, 0.25), `non_square_expansion` off | U8, U16, F16, F32 | — | +| 64 × 32 | 33631 | `scale` 3, `disorder` 0.71875, `warp_intensity` 0.4375, `pattern_size` (0.8125, 0.375), `non_square_expansion` on | F32 | F32 | +| 32 × 64 | 33632 | `scale` 3, `disorder` 0.71875, `warp_intensity` 0.4375, `pattern_size` (0.8125, 0.375), `non_square_expansion` on | U16 | — | +| 64 × 64 | 33633 | `scale` 2, `disorder` 0.3125, `warp_intensity` 0.1875, `pattern_size` (0.625, 0.25), `non_square_expansion` off | F32 | — | +| 128 × 128 | 41713 | Defaults | F32 | — | +| 256 × 256 | 41713 | Defaults | U16 | U16 | +| 256 × 128 | 13217 | `scale` 2, `disorder` 0.3125, `warp_intensity` 0.1875, `pattern_size` (0.625, 0.25), `non_square_expansion` off | F32 | — | +| 128 × 256 | 13217 | `scale` 2, `disorder` 0.3125, `warp_intensity` 0.1875, `pattern_size` (0.625, 0.25), `non_square_expansion` off | U16 | — | +| 256 × 256 | 6217 | `scale` 3, `disorder` 0.71875, `warp_intensity` 0.4375, `pattern_size` (0.8125, 0.375), `non_square_expansion` on | U16 | — | +| 16 × 32 | 0 | Defaults | U8, U16, F16, F32 | U16 | +| 32 × 16 | 42 | `scale` 2, `disorder` 0.21875, `warp_intensity` 0.21875, `pattern_size` (0.6015625, 1.349609375), `non_square_expansion` on | U16, F32 | — | +| 64 × 64 | 433623 | `scale` 1, `disorder` 0.9375, `warp_intensity` 0.9375, `pattern_size` (1.140625, 0.85546875), `non_square_expansion` off | U8, U16, F16, F32 | U8 | +| 128 × 32 | 433660 | `scale` 3, `disorder` 0.046875, `warp_intensity` 0.046875, `pattern_size` (0.47265625, 1.4677734375), `non_square_expansion` on | U16, F32 | F32 | +| 32 × 128 | 433697 | `scale` 2, `disorder` 0.5625, `warp_intensity` 0.5625, `pattern_size` (0.859375, 1.11328125), `non_square_expansion` off | U8, U16, F16, F32 | — | +| 256 × 128 | 433771 | `scale` 3, `disorder` 0.328125, `warp_intensity` 0.328125, `pattern_size` (0.68359375, 1.2744140625), `non_square_expansion` off | U16, F32 | — | +| 128 × 256 | 433808 | `scale` 1, `disorder` 0.8125, `warp_intensity` 0.8125, `pattern_size` (1.046875, 0.94140625), `non_square_expansion` on | U16, F32 | U16 | +| 256 × 256 | 42 | Defaults | U8, U16, F16, F32 | F32 | +| 512 × 128 | 433882 | `scale` 1, `disorder` 0.671875, `warp_intensity` 0.671875, `pattern_size` (0.94140625, 1.0380859375), `non_square_expansion` on | U16, F32 | — | +| 32 × 64 | 286151 | Defaults | U8, U16, F16, F32 | F16 | +| 64 × 32 | 286222 | `scale` 2, `disorder` 0.34375, `warp_intensity` 0.2578125, `pattern_size` (0.6953125, 1.263671875), `non_square_expansion` on | U16, F32 | — | +| 64 × 128 | 286293 | `scale` 3, `disorder` 0.78125, `warp_intensity` 0.5859375, `pattern_size` (1.0234375, 0.962890625), `non_square_expansion` off | U8, U16, F16, F32 | U16 | +| 128 × 64 | 286364 | `scale` 1, `disorder` 0.59375, `warp_intensity` 0.4453125, `pattern_size` (0.8828125, 1.091796875), `non_square_expansion` on | U16, F32 | — | +| 128 × 128 | 286435 | `scale` 2, `disorder` 0.125, `warp_intensity` 0.09375, `pattern_size` (0.53125, 1.4140625), `non_square_expansion` off | U16, F32 | U16 | +| 256 × 128 | 286506 | `scale` 3, `disorder` 0.9375, `warp_intensity` 0.703125, `pattern_size` (1.140625, 0.85546875), `non_square_expansion` on | U8, U16, F16, F32 | F32 | + +
+ +### Two independent pattern sources in Moisture Noise + +Repeat the [94 Moisture Noise settings](#moisture-spot-and-cell-fields-across-processors-and-saved-packages) with one and eight reference processors. Add five size and parameter combinations. Use the default controls at 32 × 64. For 64 × 32, 64 × 128, 128 × 64 and 128², set disorder d to .375, .8125, .46875 and .1875 respectively. Set pattern width to 36 + 96d and height to 27 + 64(1 − d). Use seed 187403 + 73j for zero-based row j. Request U16 and F32 for all rows, plus U8 and F16 at the three middle sizes. + +| Reference processors | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| 1 | 110 | 760,062/760,064 · 1 | 1,413,730/1,413,888 · 6 | 760,041/760,064 · 0.00048828125 | 1,338,221/1,338,368 · 7.80820847e-05 | +| 8 | 110 | 760,062/760,064 · 1 | 1,413,686/1,413,888 · 6 | 760,037/760,064 · 0.00048828125 | 1,338,178/1,338,368 · 7.83205032e-05 | +| 1, reopened | 18 | 28,671/28,672 · 1 | 24,571/24,576 · 5 | 8,192/8,192 · 0 | 425,941/425,984 · 7.80522823e-05 | + +Reopen the earlier 12 saved settings and every third new setting starting with the first. Both applications reproduced their original frames on all 18 settings, 487,424/487,424 pixels each. The reopened row compares the applications to each other. + +Route each of the two active pattern sources, the blend and the final levels node to the output of a separate saved graph. Compare the source node in the original graph, the reconnected output in the reference, and the reconnected output in MaterialCraft on one processor. The original and reconnected reference buffers match in all 20 comparisons. Keep the two pattern buffers and the blend at U16, and request F32 from levels. Coordinates below are zero-based. + +| Size, seed | Width, height, disorder | Destination pattern exact / total | Source pattern exact / total | Blend exact / total | Levels exact / total · max | +|---|---|---:|---:|---:|---:| +| 64 × 64, 42 | 60, 140, 0.3 | 4,095/4,096 | 4,096/4,096 | 4,095/4,096 | 4,095/4,096 · 7.802248e-05 | +| 32 × 64, 42 | 61.84375, 161.78125, 0.21875 | 2,048/2,048 | 2,047/2,048 | 2,047/2,048 | 2,047/2,048 · 7.802248e-05 | +| 64 × 32, 405833 | 145.5625, 85.1875, 0.8125 | 2,047/2,048 | 2,048/2,048 | 2,047/2,048 | 2,047/2,048 · 7.80820847e-05 | +| 64 × 32, 187476 | 72, 67, 0.375 | 2,048/2,048 | 2,048/2,048 | 2,048/2,048 | 2,048/2,048 · 0 | +| 128 × 128, 187695 | 54, 79, 0.1875 | 16,384/16,384 | 16,384/16,384 | 16,384/16,384 | 16,384/16,384 · 0 | + +The maximum U16 error is one code wherever a stage differs. At 64² and seed 42 the destination reads 34557 in MaterialCraft and 34556 in the reference at (32,6). The blend retains those codes. Levels returns .6257977485656738 and .6257197260856628. At 32 × 64 and seed 42 the destination matches throughout, while the source reads 4186 and 4187 at (31,21). Each active pattern source therefore accounts for a discrepancy at a different setting. The whole root remains in progress. + +### Three active quadrant levels in Dirt 5 and Dirt Gradient + +Dirt 5 and Dirt Gradient draw a parent at depth 7, its four children and their sixteen children. In a complete tree this gives 344,064 draws before tiling. Changing the addition order changes some F32 pixels even when all three levels draw the same shape. The clean-room renderer now counts physical tile copies when splitting these runs. The order was measured with original square graphs and checked on the two root generators. + +Start with a unit render and tiling region, zero roughness (the stored `hurst` parameter), a white background and a full four-child tree. Leave depths 0–6 empty. At depth 7 draw two squares at the same center with weights −1 and 2⁻²⁵. The two possible F32 results distinguish the draw order. Keep the deeper levels active and move their .25-weight squares away from the readout. Use a square width of .875 in both axes. On one reference processor, pair the 64 depth-three subtrees in 63 rounds so that each pair meets once. Reading the 256 corresponding parent centers in Morton order gives 516,096/516,096 matching comparisons. Shift the compared centers within the subtrees and test both polarities. All 818,406 eligible overlap reads across 684 frames agree with the reconstructed order. Split the 256 parent positions at 0, 4, 28, 64, 96, 128, 140, 164, 192 and 256, then bisect each interval. Comparing the midpoints of the 153 interval pairs in every subtree and both polarities gives another 19,584/19,584 exact reads. All three maxima are zero. These observations place the parents in 46 contiguous runs. + +To reproduce the tile-edge regression, divide the tree into 16 depth-two subtrees, subtract each subtree origin from its depth-seven branch offset and use 128² F32 at seed 188119. Set the frames of groups 9 and 11 to zero and their weights to −1 and 2⁻²⁵ respectively. Offset all other parent frames by (.5, 0) with weight .25. Offset the children by (0, .5) and the grandchildren by (−.5/512, .5). Read the top-left 32² pixels in Morton order. The tiny positive result occurs at parent indices [796, 932) with tiling off and [784, 919) with horizontal tiling. With vertical tiling and grandchild offset (.5, −.5/512), it occurs at [784, 922). All other readout pixels are zero. Moving a grandchild over a seam changes the order of the overlapping interior parents. + +For wider coverage, use shape selectors 2, 3, 4 and 6 with tiling off, horizontal, vertical and both. Keep child and grandchild base frame offsets at (0, .5). Apply the following eight changes, with seed 188119 + 37j for zero-based row j. The deltas are in unit coordinates. + +| Negative, positive group | Size | Width | Child frame delta | Grandchild frame delta | +|---|---|---:|---|---| +| 12, 0 | 128² | .875 | 0 | 0 | +| 0, 14 | 128² | .875 | 0 | (−.5/512, 0) | +| 4, 13 | 128 × 64 | .875 | (.5/256, 0) | 0 | +| 10, 3 | 64 × 128 | .875 | 0 | (0, −.5/512) | +| 9, 15 | 256 × 128 | .75 | 0 | (−.5/512, 0) | +| 5, 11 | 128 × 256 | .9375 | 0 | (−.5/512, 0) | +| 12, 0 | 128² | .875 | 0 | (−.5/512, 0) | +| 12, 0 | 128² | .875 | 0 | (0, −.5/512) | + +The 128 full F32 frames matched 2,359,296/2,359,296 pixels. In the square graph repeat all four tiling modes with group pairs (9,11), (7,9), (5,11) and (5,7), moving the grandchild just over each seam in turn as in the regression. These 32 frames matched 524,288/524,288. Save and reopen rows 0, 3 and 6 for horizontal squares, both-axis shape 3 and untiled shape 6. Repeat with square edge settings 0, 3 and 6 under vertical tiling, visiting X then Y for each pair in the given order. Both applications preserved their originals and agreed on all 172,032/172,032 pixels across these 12 reopens. All maxima are zero. + +Test the copy threshold independently with square size .875, horizontal tiling and 128² F32. Leave the parent pairs overlapped. Each depth-three subtree has 5,376 draws. Move 0, 40, 80 or 83 grandchild squares to cross the left edge, dividing the extra copies equally among the four depth-four children and assigning remainders to the first children in Morton order. Use pairing rounds 0, 5, 17, 28, 41 and 62 in both polarities. All 48 frames match, 786,432/786,432 pixels with maximum zero. At 84 extra copies, a subtree fills a batch of 5,460 in MaterialCraft. At that threshold the marker pixels can indicate a different relative order. The three-level tiled implementation uses the measured order below that threshold when its splits remain in the measured subtree intervals. + +For the real generators, route the pattern node directly to the output. Request F32 at 256² seed 0, 128 × 64 seed 142327 and 256 × 128 seed 142453. Add 32², 32 × 64, 64 × 128, 128 × 64, 128² and 256 × 128 with seed 186377 + i + 71j, where i is the inventory index and j starts at zero. Dirt 5 matched all 175,104 pixels with tiling off and all 175,104 with both axes enabled. Dirt Gradient also matched 175,104/175,104 untiled, all maxima zero. With its original horizontal tiling it matched 60,028/175,104, maximum 1.19209290e−7. With both axes enabled it matched 42,464/175,104, maximum 1.34110451e−7. + +For each whole root, repeat the earlier 67 settings. Add 16 × 32, 128 × 64, 128² and 256 × 128 with seed 185771 + 43i + 73j. Then add 32 × 16, 64 × 128, 128 × 64, 128² and 256 × 128 at seeds 188101 + i, 142452, 142454, 188441 + i and 188711 + i respectively. In each series use U16 and F32 at the first and last sizes, and all four formats for the middle sizes, in U8, U16, F16, F32 order. These roots expose no input pins or adjustable parameters. Reopen the earlier 12 saved settings and every third setting of each new series, starting at the first. The reopened row compares the applications. [Earlier root settings and reopens](#single-processor-comparisons-for-clouds-2-and-five-dirt-fields) + +| Root | Reference processors | Settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---|---:|---:|---:|---:|---:| +| Dirt 5 | 1 | 95 | 567,552/567,552 · 0 | 779,008/779,008 · 0 | 567,552/567,552 · 0 | 748,544/748,544 · 0 | +| Dirt 5 | 8 | 95 | 567,548/567,552 · 1 | 778,585/779,008 · 4 | 567,396/567,552 · 0.000244140625 | 748,143/748,544 · 5.10364771e-05 | +| Dirt 5 | 1, reopened | 22 | 28,672/28,672 · 0 | 70,656/70,656 · 0 | 16,384/16,384 · 0 | 238,848/238,848 · 0 | +| Dirt Gradient | 1 | 95 | 567,552/567,552 · 0 | 778,701/779,008 · 2 | 567,524/567,552 · 0.00048828125 | 748,233/748,544 · 1.93715096e-05 | +| Dirt Gradient | 8 | 95 | 567,552/567,552 · 0 | 778,737/779,008 · 2 | 567,533/567,552 · 0.000244140625 | 748,268/748,544 · 2.03251839e-05 | +| Dirt Gradient | 1, reopened | 22 | 28,672/28,672 · 0 | 70,633/70,656 · 1 | 16,383/16,384 · 6.10351562e-05 | 238,767/238,848 · 1.93715096e-05 | + +Both applications reproduced their own whole-root originals on all 354,560/354,560 reopened pixels per root. Across the 95 whole-root settings, Dirt 5 matched 2,662,656/2,662,656 on one processor and 2,661,672/2,662,656 on eight. Dirt Gradient matched 2,662,010/2,662,656 on one and 2,662,090/2,662,656 on eight. Both roots remain in progress. + +Repeat 256 × 128 F32 at seed 142453, 128² U16 and F16 at seed 185917 + 43i, and 256 × 128 F32 at seed 185990 + 43i. Interleave three reads at each original seed with two reads at seed +3 and +5. All four repeated Dirt 5 settings were exact between single-processor reference reads. With eight processors, two reference reads of the first F32 setting agreed on 32,759/32,768 pixels, maximum 5.08725643e−5. For Dirt Gradient even two single-processor reference reads of the 128² F16 setting differed on 2/16,384 pixels, maximum .000244140625. + +The new square regression failed on the preceding implementation. After the fix, 432 release tests passed in the node and evaluation crates. Formatting, workspace Clippy for all targets, layer checks and the WebAssembly check passed. Seventy existing Clouds 2, Dirt 1 and Dirt 6 settings retained 1,711,872/1,711,872 exact pixels. + +### Paired subtree capacity in horizontally tiled Dirt Gradient + +In the complete three-level generator, one early subtree can fill a batch while nearby interior squares still follow the measured order. The earlier implementation fell back as soon as any depth-three subtree reached 5,460 physical copies. The renderer now checks each pair of depth-three subtrees in the final quadrant against two batches. It also checks that every computed split lies strictly inside its measured depth-four subtree. Independent overlaps show that filling certain pairs changes the order of unrelated draws. [Three-level square setup and earlier root settings](#three-active-quadrant-levels-in-dirt-5-and-dirt-gradient) + +Start with the 16-group square probe, zero roughness, unit opacity and a white background. Re-rendering rows 0, 1 and 6 of the earlier horizontal square graph with only the stored roughness field at zero reproduced all 49,152/49,152 original pixels. With that field set to one, the first frame at (8,0) changed from 2⁻²⁵ to .899999976. Keep child and grandchild frames at (.25, .5). For the selected depth-two groups move the child frame to (−.5/256, .5) and the grandchild frame to (−.5/512, .5). For vertical tiling transpose both components of every child and grandchild frame. With width .875, an affected depth-three subtree crossing the seam adds 32 child copies and 64 grandchild copies to its 5,376 draws. The depth-seven markers stay in the upper-left readout. + +Use four sets of selected groups, {0}, {0,1,2}, {1,3,5,7,9,11} and {0,…,11}. Use square shape 2 with horizontal, vertical and both-axis tiling, shape 4 with horizontal tiling, shape 3 with vertical tiling and shape 6 with both axes. For each, run group pairs (12,0), (9,11), (5,7) and (0,14) at 128² and width .875, then (9,15) at 256 × 128 and width .75, and (5,11) at 128 × 256 and width .9375. Use seed 189557 + 41j for zero-based row j. The 144 F32 frames improved from 3,016,786/3,145,728 to **3,145,728/3,145,728**, maximum error from 2⁻²⁵ to zero. Save and reopen rows 0, 2 and 4 for square/horizontal/{0}, shape 3/vertical/{1,3,5,7,9,11} and shape 6/both/{0,…,11}. All nine reopens matched, 196,608/196,608 pixels, maximum zero, and each application reproduced its own originals. + +Vary the copy count separately with the 64-group square probe. In depth-three group g add 46 + (23g modulo 37) horizontal copies for g < 48, or 63 + (7g modulo 14) otherwise. Set the extra counts of groups g and g+1 in the tested pair to 72 and 95, 96, 97 or 104 respectively. In depth-four child a assign floor(v/4) extras plus one if (a + g) modulo 4 is less than v modulo 4, for group total v. Move that many grandchildren, chosen in local row-major order, from (.5,.75) to the horizontal seam at (0,.75). Compare the low-density order prediction with the one-processor reference in the upper 64 rows of the 128² images. Use rounds 1, 7, 11, 17, 32, 41, 54 and 62, reversing signs in a second capture of rounds 11 and 41. + +| Pair starting group | 10,919 copies | 10,920 copies | 10,921 copies | 10,928 copies | +|---:|---:|---:|---:|---:| +| 50 | 81,920/81,920 | 79,999/81,920 | 80,002/81,920 | 78,080/81,920 | +| 54 | 81,920/81,920 | 81,342/81,920 | 81,342/81,920 | 79,218/81,920 | +| 58 | 81,920/81,920 | 81,083/81,920 | 81,083/81,920 | 81,083/81,920 | +| 62 | 81,920/81,920 | 79,934/81,920 | 79,934/81,920 | 79,934/81,920 | + +The maximum readout error is zero in the first column and 2⁻²⁵ wherever the prediction differs. The implementation retains its previous rendering path outside the measured conditions. + +In Dirt Gradient's nine direct horizontal F32 generator settings, the normal renderer improved from 60,028/175,104 to 99,776/175,104. Four settings now match every pixel, 58,368/58,368 in total. These are 256 × 128 at seed 142453, plus 32², 64 × 128 and 128² at seeds 186509, 186651 and 186793. The other five settings retain differences, maximum 1.19209290e−7. Dirt Gradient untiled and Dirt 5 untiled and tiled on both axes retained 525,312/525,312 exact generator pixels in total. Dirt Gradient with both axes enabled still matches 42,464/175,104, maximum 1.34110451e−7. + +Repeat the 95 earlier Dirt Gradient whole-root settings and add 32 × 64, 64 × 128, 128 × 64, 256 × 64 and 128 × 256 with seeds 195113, 142326, 142328, 195577 and 195689. Use U16 and F32 at both ends and all four formats in U8, U16, F16, F32 order at the three middle sizes. Reopen the previous 22 saved settings and every third new setting starting at the first. + +| Reference processors | Settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| 1 | 111 | 600,320/600,320 · 0 | 846,292/846,592 · 2 | 600,294/600,320 · 0.00048828125 | 815,829/816,128 · 1.96099281e-05 | +| 8 | 111 | 600,320/600,320 · 0 | 846,310/846,592 · 2 | 600,298/600,320 · 0.000244140625 | 815,822/816,128 · 2.03251839e-05 | +| 1, reopened | 28 | 36,864/36,864 · 0 | 80,878/80,896 · 1 | 32,767/32,768 · 6.10351562e-05 | 279,728/279,808 · 1.93715096e-05 | + +In the original 95 settings, the one-processor comparison gained 41 exact pixels, reaching 2,662,051/2,662,656. The eight-processor comparison lost 17 exact pixels against the same stored frames, reaching 2,662,073/2,662,656. Across all 111 settings the counts are 2,862,735/2,863,360 and 2,862,750/2,863,360 respectively. Both applications reproduced their own 430,336/430,336 pixels across the 28 reopens. Dirt Gradient remains in progress. + +With one local processor, use the direct horizontal F32 generator at 256² seed 0, 256 × 128 seed 142453 and 64 × 128 seed 186651. Six interleaved release measurements per version after warmup gave median cook times of 2,242 to 2,275 ms, 2,145 to 2,239 ms, 2,100 to 2,145 ms. The two-level seam regression failed at parent 64 on the previous code and passed with the change. All 432 release tests for the node and evaluation crates passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Zero-luminosity draws and addition order in Moisture Noise + +Expose each pattern source separately, retaining just its generator and output. Repeat the five size, seed and control combinations in the stage table. Capture the stored U16 result, then F32 with the original tiling and with both axes disabled, on one processor. The isolated U16 outputs reproduced every reference pixel from the intact graph. [Five settings and whole-root results](#two-independent-pattern-sources-in-moisture-noise) + +| Generator output | Destination exact / total · max | Source exact / total · max | +|---|---:|---:| +| U16, original tiling | 26,622/26,624 · 1 | 26,623/26,624 · 1 | +| F32, original tiling | 26,227/26,624 · 1.1920929e-07 | 26,076/26,624 · 1.49011612e-08 | +| F32, tiling off | 26,356/26,624 · 1.1920929e-07 | 26,302/26,624 · 7.4505806e-09 | + +In each F32 render, record the background and the F32 contribution of each original stamp at each covered pixel in MaterialCraft. Replaying them in traversal order reproduced all 106,496 MaterialCraft pixels. Of those, 104,961 matched the reference, maximum 1.19209290e−7. For each of the 1,535 others, permute the same contributions and round to F32 after each addition. Verify the resulting order independently with F32 addition. Each differing pixel had at least one order giving the exact reference bits. The diagnostic reconstructs 106,496/106,496 pixels with zero maximum error. Finding a consistent order shared by all pixels and held-out settings remains open. + +For example, use 64², seed 42 and tiling off. At destination (63,21) the F32 background is 0x3efefef8. Adding 0x3ac65b72 then 0x3b0da8f8 yields 0x3f007052. Reversing them yields the reference 0x3f007053. At source (37,10) start from zero. The three contributions 0x3bb14b71, 0x3bee99ee and 0x3c451a3a yield 0x3cca8675 in that order. Moving the third to the front yields the reference 0x3cca8674. + +Build an independent four-child square tree from depth zero through eight. Enable shape 2 at depths two through eight, additive blending, width and height .875, zero roughness, unit global opacity, a white background and no tiling. Use a 128² F32 output. Keep depths two through six and depth eight centered at (.5,.75) with luminosity .25. Number the 64 depth-three groups in child-slot traversal order. Move their depth-seven grids by multiples of 1/8 so each pair lands on the same 16 × 16 tile in the upper half. Assign −1 to one grid and 2⁻²⁵ to the other. The two possible orders give either 2⁻²⁵ or zero at the pixel centers. + +Start with group numbers 0 through 63 in order. Pair the ends inward, keep the first number fixed, move the last number to the second position and repeat for 63 rounds. Lay the 32 pairs left-to-right in eight columns. Use seed 137143 + 17j for zero-based round j and reverse the gains in a second capture every seventh round starting at zero. Every one of the 589,824 readings agreed with one order of the 64 groups across all 256 local coordinates. For an independent parent comparison, give each active depth-two square width and height .5 and move it to the center of a readout tile. In round j place parent p opposite group (4p + j) modulo 64, for j = 0 through 63. Reverse every seventh round. Also compare all parent pairs in a 15-round rotation, reversing every third round. Use seed 189319 for these comparisons. All 344,064 readings agreed with a single ordering of the 16 parents and 64 groups, maximum error zero. + +In each real generator, 87,376 logical draws occur at depths two through eight. Across the five settings, 43,449–43,776 of the destination draws and 43,600–43,927 of the source draws have nonzero luminosity. To isolate the effect of these draws, expose a single scalar controlling the depth-eight luminosity in the square tree. All depth-eight squares still occupy the lower half. Repeat rounds 0, 5, 17, 28, 41 and 62 with both polarities. Compare the upper 64 rows to separate captures with constant depth-eight luminosity zero and .25. + +| Exposed luminosity | Against zero control · exact / total | Against .25 control · exact / total | +|---:|---:|---:| +| 0 | 98,304/98,304 | 29,184/98,304 | +| 2⁻²⁰ | 29,184/98,304 | 98,304/98,304 | +| .125 | 29,184/98,304 | 98,304/98,304 | +| −.125 | 29,184/98,304 | 98,304/98,304 | + +The maximum upper-half error is zero for exact comparisons and 2⁻²⁵ for the others. At round zero with the initial polarity, (0,0) changes from 2⁻²⁵ to zero as soon as the lower squares take any of the three tested nonzero gains. MaterialCraft matches 610,816/786,432 complete pixels across the 48 exposed settings, maximum 2⁻²⁵. At zero gain reopen rounds 0 and 28 with initial polarity, at 2⁻²⁰ the same rounds reversed, at .125 rounds 5 and 41 with initial polarity, and at −.125 those rounds reversed. Both applications reproduced their own 131,072/131,072 saved pixels. The cross-application result was 97,792/131,072, maximum 2⁻²⁵. Moisture Noise remains in progress. + +### The first subtree pair in the final Dirt Gradient quadrant + +The first pair of depth-three subtrees in the final quadrant can submit 10,944 tile copies and still follow the order measured for its separate parts. The previous two-batch check selected traversal order for the entire generator. The renderer now keeps the measured ordering for that pair when the computed splits stay inside their depth-four subtrees. Later pairs still select traversal order when they reach two batches. [Paired subtree capacity and the 16-group probe](#paired-subtree-capacity-in-horizontally-tiled-dirt-gradient) + +Use the earlier 16-group graph with zero roughness. Number depth-two groups from zero in child-slot order. Select group 12, 13, 14 or 15. At depths eight and nine use the position after the selected group's branch offset. In its upper eighth of the unit tile (y < .125), set e = −.5 / 2ᵈ at depth d. For horizontal or both-axis tiling use frame (e,.5) if x < .125 and (e − .125,.5) otherwise. For vertical tiling use (.5,e). The other child and grandchild frames stay at (.25,.5) for horizontal or both axes and (.5,.25) for vertical. With horizontal tiling and width .875, this adds 96 copies in each of the two adjacent depth-three subtrees, on top of 10,752 draws. + +Repeat the six negative/positive group pairs, widths, resolutions and six shape/axis combinations in the preceding setup. Use seed 193637 + 73j for zero-based row j. At 128², horizontal tiling, square shape and groups (12,0), interleave the five low bits of x and y in the upper-left 32² readout, with x in the least significant bit. The reference returns 2⁻²⁵ for parent indices 64–127 and 512–1023 and zero elsewhere. The previous implementation returned zero at parent 64. + +| Selected depth-two group | F32 settings | Earlier exact / total | Current exact / total | Current max | +|---:|---:|---:|---:|---:| +| 12 | 36 | 754,248/786,432 | 786,432/786,432 | 0 | +| 13 | 36 | 754,248/786,432 | 754,248/786,432 | 2⁻²⁵ | +| 14 | 36 | 753,769/786,432 | 753,769/786,432 | 2⁻²⁵ | +| 15 | 36 | 754,288/786,432 | 754,288/786,432 | 2⁻²⁵ | + +Save and reopen rows 0, 2 and 4 of group 12 for shape 2/horizontal, shape 3/vertical and shape 6/both axes. All 196,608/196,608 reopened F32 pixels matched across applications and in each application's comparison to its own originals. All 144 earlier density controls also reproduced 3,145,728/3,145,728 reference pixels, maximum zero. + +The horizontal Dirt Gradient generator at 32 × 64, seed 186580, improved from 599/2,048 to 2,048/2,048 exact F32 pixels, maximum error from 5.96046448e−8 to zero. Five of nine horizontal settings now match throughout. Together the nine improved from 99,776/175,104 to 101,225/175,104, maximum 1.19209290e−7. The untiled generator and the two Dirt 5 generator configurations matched 525,312/525,312 pixels. Dirt Gradient with both axes enabled matched 42,464/175,104, maximum 1.34110451e−7. + +The same 111 whole-root settings again matched 2,862,735/2,863,360 pixels on one reference processor and 2,862,750/2,863,360 on eight. The 28 saved settings matched 430,237/430,336 across applications and 430,336/430,336 against each application's own original. The linked whole-root table gives the counts and maximum errors by output format. Dirt Gradient remains in progress. [Whole-root settings and per-format results](#paired-subtree-capacity-in-horizontally-tiled-dirt-gradient) + +The new regression failed at parent 64 before the change. After the fix, all 432 node and evaluation release tests passed. Formatting, strict workspace Clippy for all targets, dependency layers and WebAssembly passed. Four interleaved one-processor release measurements after warmup gave median cook times of 1,910 to 1,922 ms for the corrected 32 × 64 generator, and 1,934 to 1,954 ms at 128 × 64 and seed 186722. + +### Individual tile copies after two full horizontal batches + +In a complete quadrant tree with four children and four grandchildren below depth seven, the horizontal generator can fill two batches in depth-three groups 58–59 or 62–63. Number groups in child-slot order. Each batch holds 5,460 physical copies. At 256² and seed zero, group pair 58–59 contributes one further copy. At 128 × 64 and seed 142327 it contributes 17. In group pair 62–63 at 128 × 64 and seed 186722, the remaining ten copies enter the batch containing group 48. The last seven copies from group 48 resume after the 15,766th depth-seven parent. Each cut can fall between the two horizontal copies of a single square. + +For the three settings, give each depth-seven parent an individually addressable square and pair squares at distinct readout pixels. Start from white, add −1 and 2⁻²⁵, then repeat with their signs exchanged. All 32,766 adjacent comparisons per setting distinguish one order of the 16,384 parent markers. An additional 1,616, 1,632 and 1,168 reads locate the splits inside the final child or grandchild in each run. Compare the first and last copies in each short continuation to sparse parent markers, then to their immediate neighbors in both polarities. In the 186722 setting the seven-copy continuation falls between parent markers 90,027 and 267,456 when stamps are numbered in depth-first order starting at zero. + +The regression uses seed 653180. For depth-three group g below 48, put 27 + (30g + 64) mod 67 copies over the seam. For the other groups use 45 + (15g + 11) mod 37. Replace the two selected counts by 75 and 106. Divide each count over its four depth-four subtrees. Each subtree receives the quotient, with one extra where (subtree + g) mod 4 is less than the remainder. Use the first stamps in each subtree's traversal order for its extra copies. For each overlapping pair the test checks whether the negative or positive square drew first. The earlier renderer returned zero on its first marker, where the reference reads 2⁻²⁵. All four full 128² reference readouts with the two group selections and both polarities matched 65,536/65,536 pixels. + +For a second input, pack the depth-nine positions into the top-left 512² of an original 1024² field, depth eight at (512,0) and depth seven at (0,512). Assign a pixel-center destination and a signed luminosity to every stamp from the field. Use seeds 193373 + 97j in the four base settings. The 256² and seed-186722 copy distributions each match 36,864/36,864 F32 pixels. With the 142327 distribution the comparison to its first capture is 36,067/36,864, maximum 1.66893005e−6. Repeat the differing 64 × 128 input on three individually selected reference processors. All three reproduce the calculated 8,192/8,192 pixels and differ from the first capture at the same 797 pixels. On eight processors the repeat matches 7,209/8,192 calculated pixels, maximum 2.74181366e−6. Keep the original capture in the reported count. + +Vary the per-subtree copy counts with independent procedural fields at 128² and 128 × 64. The selected pairs receive 168–320 extra copies in 12 distributions for 58–59 and 168–1,344 in 18 distributions for 62–63, on top of 10,752 logical draws. All 60 F32 renders match 737,280/737,280 pixels. The 144 previous lower-density controls match 3,145,728/3,145,728. The 144 group-selection controls match 3,048,737/3,145,728, maximum 2⁻²⁵. Reopen eight signed-field settings from MaterialCraft saves. The applications agree on 86,016/86,016 pixels. MaterialCraft reproduces all original buffers. The reference reproduces 85,219/86,016 original pixels, with the same 797 differences in the 142327 distribution. + +| Dirt Gradient, 111 distinct whole settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| One processor | 600,320/600,320 · 0 | 846,337/846,592 · 2 | 600,300/600,320 · .00048828125 | 815,867/816,128 · 1.96099281e−5 | +| Eight processors | 600,320/600,320 · 0 | 846,301/846,592 · 2 | 600,296/600,320 · .00048828125 | 815,814/816,128 · 2.03251839e−5 | + +The measured whole-root counts are 2,862,824/2,863,360 on one processor and 2,862,731/2,863,360 on eight. Those changes add 89 exact pixels on one processor and remove 19 on eight against the previous captures. Across 28 reopened settings, the applications agree on 430,274/430,336 pixels. Both reproduce all their own original pixels. Eight of nine horizontal generator settings are now exact, totaling 156,061/175,104 F32 pixels. The 256 × 128, seed-186864 generator still differs at 19,043 pixels, maximum 1.19209290e−7. Both-axis tiling still matches 42,464/175,104, maximum 1.34110451e−7. The untiled and neighboring generator controls retain 525,312/525,312 exact pixels. Dirt Gradient remains in progress. [Whole-root settings](#paired-subtree-capacity-in-horizontally-tiled-dirt-gradient) · [Earlier group-selection controls](#the-first-subtree-pair-in-the-final-dirt-gradient-quadrant) + +All 433 node and evaluator release tests passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Sparse quadrant parents and leaves in Moisture Noise + +Number the 64 depth-three groups in child-slot order and count the nonzero tile copies for each group. Each copy contributes to the count even when it misses all output samples. The first twelve depth-two parents precede their four depth-three groups. The last four parents precede their second pair of groups. With those parent positions the same 5,460-copy batch splits used by two-child trees reproduce the source generator at 64² and 32 × 64 with seed 42, and at 64 × 32 with seed 187476. The three tiled F32 fields now agree at 8,192/8,192 pixels, compared with 7,864 before. [Five generator settings](#two-independent-pattern-sources-in-moisture-noise) · [Two-child batch splits](#two-child-draw-order-when-neighboring-subtrees-cross-different-tile-batches) + +In the [original square tree](#zero-luminosity-draws-and-addition-order-in-moisture-noise), divide each depth-four subtree into its 16 × 16 depth-eight grid. Give the first 86, 96 or 128 cells in row-major order luminosity .25 and give the other cells zero. For a fourth field use 70 + (11j mod 35) cells in depth-four subtree j, numbered in child-slot order. At 128² F32, repeat all 63 depth-seven pairing rounds at 86 cells and reverse the gains every seventh round. For each of the other three fields use rounds 0, 5, 17, 28, 41 and 62 in both polarities. Across 108 renders the upper-half readouts match 884,736/884,736 pixels. + +For an independent comparison, give every depth-two square size (.5,.5) and compare parent p to depth-three group (4p + k) mod 64 at all 256 readout pixels. Use k = 0, 1, 2, 13, 27, 41 and 63, seed 189319 and both gain polarities. Repeat for the 86-cell, 96-cell and varying-count fields. All 172,032 readout pixels match. For the regression, use the 86-cell field and retain just parent 0 and group 27 at the upper-left 16² readout. With parent −1 and leaves 2⁻²⁵, the reference returns zero across the tile. The previous renderer returned 2⁻²⁵ at (0,0). Reversing both gains gives 2⁻²⁵ across the tile. Across all 150 full procedural renders the applications agree on 2,457,600/2,457,600 pixels. Reopen round 0 of the 86-cell and varying-count fields and the k = 27 parent comparison of the 86-cell field, each in both polarities. Both applications reproduce their originals and agree on 98,304/98,304 pixels. + +| Isolated output across five settings | Destination exact / total · max | Source exact / total · max | +|---|---:|---:| +| U16, original tiling | 26,622/26,624 · 1 | 26,624/26,624 · 0 | +| F32, original tiling | 26,227/26,624 · 1.19209290e−7 | 26,404/26,624 · 7.45058060e−9 | +| F32, tiling off | 26,356/26,624 · 1.19209290e−7 | 26,302/26,624 · 7.45058060e−9 | + +| Moisture Noise, 110 distinct whole settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| One processor | 760,062/760,064 · 1 | 1,413,761/1,413,888 · 6 | 760,042/760,064 · .00048828125 | 1,338,252/1,338,368 · 7.80820847e−5 | +| Eight processors | 760,062/760,064 · 1 | 1,413,679/1,413,888 · 6 | 760,036/760,064 · .00048828125 | 1,338,179/1,338,368 · 7.83205032e−5 | + +The one-processor comparison gains 63 exact pixels, reaching 4,272,117/4,272,384. The eight-processor comparison loses seven, reaching 4,271,956/4,272,384. Both applications reproduce their own 487,424 pixels across 18 saved settings. The cross-application result is 487,376/487,424. Source settings with a later split or too few copies to fill the leading batch still differ. The isolated destination still differs in all five F32 settings. Moisture Noise remains in progress. + +On one processor, alternate the old and new release builds four times each after warmup for the tiled F32 source at 64² seed 42, 64 × 32 seed 187476 and 128² seed 187695. Median elapsed cook times changed from 2,586 to 3,221 ms, 2,529 to 2,903 ms and 2,187 to 3,055 ms during the concurrent verification run. A second interleaved series measured total process CPU time for all three settings, including package loading and readback. Its median changed from 13.602 to 13.680 seconds. All 434 node and evaluator release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### A late copy in the penultimate horizontal subtree pair + +At 256 × 128 and seed 186864, the horizontal Dirt Gradient generator submits 10,926 copies from depth-three groups 60 and 61. Two batches take 10,920 of them. A subsequent batch fills three copies before the end of the depth-four subtree containing depth-seven parent 4287. Number stamps from zero in depth-first order. Stamps 90,045 through 90,047 resume after the 15,696th parent marker, between logical stamps 303,723 and 266,133. For a run covering N depth-seven parents, round its nominal 21N copies up to a multiple of 5,460 and subtract the occupancy of the active batch. A repeated parent endpoint can therefore leave a later continuation inside the same subtree. Apply the cut only when it falls in the measured subtree interval. + +Pair distinct square markers in an original 128² F32 field, starting from white with gains −1 and 2⁻²⁵. Merging the ordered groups required 32 frames and 38,221 reads, including all 32,766 adjacent checks in both polarities. A further 1,432 reads located individual copy boundaries. Compare the first and last deferred stamps to sparse parent markers and their neighbors in both polarities, 2,066 reads each. The two internal comparisons confirm the order of the three stamps. The original 256 × 128 generator now matches 32,768/32,768 pixels. Four independently weighted square inputs using the same copy counts match 36,864/36,864 pixels. + +For the regression, use the [same square tree and per-subtree distribution](#individual-tile-copies-after-two-full-horizontal-batches) at seed 1763066. In group g below 48 put 40 + (26g + 63) mod 83 squares over the seam. Elsewhere use 45 + (9g + 8) mod 37, replacing the counts for groups 60 and 61 by 81 and 100. This leaves 15 deferred copies. Check nine marker pairs with both gain assignments. The previous renderer returned 2⁻²⁵ on the first readout where the reference returned zero. Both 128² fields now agree on 32,768/32,768 pixels. Vary the selected pair from 168 to 207 extra copies across 13 further distributions, leaving zero through 44 deferred copies. All 26 F32 fields at 128² and 128 × 64 match 319,488/319,488 pixels. The 60 previous weighted controls and four signed fields for the neighboring pairs match 737,280/737,280 and 65,536/65,536 pixels. Reopen seven settings from four MaterialCraft saves spanning the original distribution, two independent distributions and the signed regression. Both applications reproduce their own buffers and agree on 90,112/90,112 pixels. Maximum error is zero in each of these comparisons. + +All nine horizontal generator settings now match 175,104/175,104 pixels, gaining 19,043 exact pixels. The untiled and neighboring generator controls match 525,312/525,312. Both-axis tiling still matches 42,464/175,104, maximum 1.34110451e−7. Across the [111 whole-root settings](#individual-tile-copies-after-two-full-horizontal-batches), one processor matches 2,862,824/2,863,360 pixels and eight match 2,862,731/2,863,360. Maximum error is zero in U8, two codes in U16, .00048828125 in F16 and 1.96099281e−5 or 2.03251839e−5 in F32 on one or eight processors respectively. For 28 reopened whole-root settings, both applications reproduce their original buffers and agree with each other on 430,274/430,336 pixels. Dirt Gradient remains in progress. All 434 node and evaluator release tests passed, together with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### First-level draw order in repeated spot quadrants + +Number the four children of a quadrant from zero in traversal order. In a repeated tree with a unique first-level shape, the shape draws in child order 3, 2, 1, 0 once the visited subdivision depth reaches six. Each child retains ascending iteration order. Depths one through five retain traversal order. A switch can skip a whole tree within the repeated branch. Count the root quadrants that are visited when dividing the first-level draws into groups of four. The measured implementation covers depths six through ten, a single root iterator without an initial branch, four retained first-level additive shapes per active iteration, and at most 5,460 first-level tile copies. A shape also used by deeper draws needs its joint submission order. + +Use an original white F32 canvas with square marks at (.25,.25) and (.75,.25). Give the first mark −1 on child 0 in the first active iteration and 2⁻²⁵ on child 3 in the last. At the second mark use child 1 for both gains in the first and second active iterations. Swap both gains and repeat. Use 32² at seed 200153 and 64 × 32 at seed 200363. Compare depths 5 and 6 with two repetitions and depth 10 with four. Repeat depth 6 with eight reference processors. All 16 images match 24,576/24,576 pixels. For nine requested repetitions, use active iterations 2 and 6 at depths 5 and 6, iterations 0 and 1 at depth 9, and 0, 3, 5 and 8 at depth 10. Repeat the two gain assignments, sizes and eight-processor depth-six controls. All 20 images match 30,720/30,720 pixels. The prior renderer returned 2⁻²⁵ on the first deep readout where the reference returned zero. Using the requested iteration count also failed the nine-repetition regression. + +At 128², give every first-level stamp an individually addressable destination and sign. Compare adjacent pairs in both gain assignments. Sweep depths one through ten and repeat counts from one through eight, then 16, 32, 64 and 128. The widest case distinguishes 512 stamps. Place additional small, nonzero shapes outside the readout, including four-way descendants down to depth seven. Across six such controlled configurations at depths 3, 6 and 10, all 48 F32 images match 786,432/786,432 pixels. In the first Noise BNW Spots 1 graph, isolate the first-level shape while retaining the deeper branch structure. The five completed F32 settings improve from 6,178/8,192 to 8,192/8,192. At 64 × 32 with scale 3, the diagnostic graph exceeds the visit budget after its deeper shapes are disabled. With all shapes enabled, all six diagnostics render and agree on 8,618/10,240 pixels, maximum 2.38418579e−7. Reopen the five completed isolates and six gated-square settings from MaterialCraft saves. Both applications reproduce their own pixels and agree on 17,408/17,408. + +For the whole-root comparison, recapture the 62 distinct settings from the existing default, precision, seed, scale, roughness and disorder sweeps. Add a four-size series at 16 × 32, 64 × 32, 32 × 64 and 64². Start with defaults, then set scale to 3, 1, 2 and both disorder and roughness to .34375, .1875, .53125. Enable non-square expansion on the two middle sizes. Use seed 194395 + 47j for zero-based row j. Render U16 and F32 at every size, adding U8 and F16 at the middle sizes. Include the separate 12-format series at 16 × 32, 32 × 16, 32² and 64 × 32, with defaults then disorder .34375, .78125 and .5625, scale 1, 2 and 1, and roughness .25 + .625 × disorder. Its seeds are zero then 153113 + 37 × 236 + 109j. Compare defaults and changed controls at their declared output dimensions. [Earlier spot-graph sweeps](#connected-quadrant-depth-and-amplified-spot-patterns) + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| One processor | 108,800/108,800 · 0 | 328,291/328,448 · 1 | 108,798/108,800 · 0.00048828125 | 236,852/295,680 · 3.57627869e−7 | +| Eight processors | 108,799/108,800 · 1 | 328,292/328,448 · 1 | 108,800/108,800 · 0 | 242,269/295,680 · 2.38418579e−7 | +| Saved packages, one processor | 90,112/90,112 · 0 | 93,670/93,696 · 1 | 6,400/6,400 · 0 | 5,902/6,144 · 2.38418579e−7 | + +All 86 distinct whole-root settings render. The one-processor result gains 57,860 exact pixels, reaching 782,741/841,728. Eight processors gain 58,793, reaching 788,160/841,728. The maximum single-processor F32 difference increases from 2.38418579e−7 to 3.57627869e−7. MaterialCraft reproduces all 196,352 of its original pixels across 19 reopened settings. The reference reproduces 196,348/196,352, maximum 5.96046448e−8. The two applications agree on 196,084/196,352 reopened pixels. The joint order of the deeper shape draws remains open. + +In eight interleaved single-processor release measurements, render the 32² scale-2 setting at seed 113, the 16 × 32 default and the 64² changed setting. Median total process CPU time for the three cooks, including package loading and readback, changed from 12.203 to 12.469 seconds. All 435 node and evaluator release tests passed together with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Whole-root precision and saved comparisons for the three neighboring spot graphs + +These observations cover the other three Noise BNW Spots graphs before the [first-level draw-order correction](#first-level-draw-order-in-repeated-spot-quadrants). For Spots 1 v2, recapture 63 distinct earlier settings. For both Spots 3 graphs, recapture 38 each. Add the two four-size series described for Spots 1. In the first series, the starting seeds for Spots 1 v2, Spots 3 and Spots 3 v2 are 194426, 194457 and 194488 respectively. Add 47 for each following row. Use scale 3, 1 and 2 after the default row. For the v2 parameters, disorder speed and anisotropy equal disorder d, the anisotropy angle is d − .25 and tile offsets are (0,.10546875), (−.15625,.2421875) and (.1875,−.05859375). Apply roughness only in graphs that expose it. In the second series the changed-row seed is 153113 + 37i + 109j for graph index i = 237, 238 or 239 and size index j = 1, 2 or 3. Set exposed disorder speed to .625 + .5d, anisotropy to .5d, angle to d − .375 and tile offset to (.21875d,−.375d). These generators have no image inputs. [Earlier precision sweeps](#connected-quadrant-depth-and-amplified-spot-patterns) · [Earlier deep-region measurements](#deep-pattern-samples-in-custom-render-and-tiling-regions) + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Spots 1 v2, one processor | 141,568/141,568 · 0 | 295,656/295,680 · 1 | 108,796/108,800 · 0.00048828125 | 285,486/296,704 · 1.1920929e−7 | +| Spots 1 v2, eight processors | 141,568/141,568 · 0 | 295,652/295,680 · 1 | 108,799/108,800 · 0.000122070312 | 285,292/296,704 · 1.1920929e−7 | +| Spots 3, one processor | 81,663/81,664 · 1 | 278,140/278,272 · 1 | 81,660/81,664 · 0.00048828125 | 229,989/230,144 · 1.53183937e−5 | +| Spots 3, eight processors | 81,663/81,664 · 1 | 278,178/278,272 · 1 | 81,660/81,664 · 0.00048828125 | 230,025/230,144 · 1.53183937e−5 | +| Spots 3 v2, one processor | 109,312/109,312 · 0 | 80,610/80,640 · 1 | 76,543/76,544 · 0.000122070312 | 73,521/80,640 · 1.78813934e−7 | +| Spots 3 v2, eight processors | 109,312/109,312 · 0 | 80,621/80,640 · 1 | 76,543/76,544 · 0.000244140625 | 74,617/80,640 · 1.78813934e−7 | + +All 87 Spots 1 v2 settings render, with 831,506/842,752 exact pixels on one processor and 831,311/842,752 on eight. For Spots 3, 48 of 62 settings render and match 671,452/671,744 on one processor or 671,526/671,744 on eight. For Spots 3 v2, 30 of 62 settings render, matching 339,986/347,136 or 341,093/347,136 respectively. The remaining 14 and 32 settings exceed the pattern visit budget in MaterialCraft. Their reference outputs were captured and have no comparable local buffer. In the 32² F32 Spots 3 v2 setting with scale 2 and disorder .78125, a separate diagnostic traversal recorded 4,025,030 visits. Of its 4,003,160 draws, 3,985,551 missed the sample grid. Completing that traversal reproduced 889/1,024 reference pixels, maximum 1.49011612e−7. This diagnostic is outside the production-render totals. + +| Reopened settings | MaterialCraft completed / attempted | Cross-application exact / total | MaterialCraft versus original | Reference versus original · maximum error | +|---|---:|---:|---:|---:| +| Spots 1 v2 | 19/19 | 137,715/139,008 | 139,008/139,008 | 138,824/139,008 · 1.1920929e−7 | +| Spots 3 | 10/14 | 99,552/99,584 | 99,584/99,584 | 123,129/123,136 · 1 | +| Spots 3 v2 | 6/14 | 27,904/27,904 | 27,904/27,904 | 122,085/123,136 · 1 | + +MaterialCraft saves reopen in both applications. For Spots 1 v2, the cross-application saved maxima are zero in U8 and F16, one code in U16 and 1.19209290e−7 in F32. For Spots 3 they are zero in U8, one code in U16 and 1.06990337e−5 in F32. The six completed saved Spots 3 v2 comparisons are exact in U8 and U16. All three roots remain in progress. + +### Late and underfilled draw batches in Moisture Noise + +In the [sparse quadrant tree](#sparse-quadrant-parents-and-leaves-in-moisture-noise), pair groups 58–59 with 0–7, 50–51 with 16–23, and 54–55 with 32–39. Each pair submits a prefix of 5,460 nonzero tile copies. A split inside the seventh group leaves only its remainder and the final group. The other two pairs can then submit their next whole group earlier. A short block of groups 8–15 ordinarily finishes later. When all three paired prefixes split in their fifth group, copies from group 38 fill the short block immediately after the prefixes. The unused part of group 38 follows later. Underfilled leading blocks at groups 24 and 40 remain open. + +For a compact reproduction, draw all 16 depth-two parents and 64 depth-three groups. Within each depth-four subtree give the first q cells of its 16² depth-eight grid luminosity .25 and the rest zero. Set q for groups 0–7, 16–23, 32–39 and 8–15 respectively to (145,95,66,96), (66,145,95,85), or (145,145,145,85). Use q = 96 elsewhere. Pair depth-seven squares on white, one at −1 and one at 2⁻²⁵, and swap the gains. Compare group 5 with 38, 6 with 4, 38 with 6, 7 with 37, and 38 with 20 at the starts and interiors of the groups. All 170 signed readouts and all 98,304 pixels in their six 128² F32 images match. For the parent regression select parent 0 and groups 8, 11, 27 and 38. Set q = 96 everywhere except groups 0–7 at 66, then repeat with only groups 8–15 at 85. The previous renderer gave 2⁻²⁵ at (0,0) in the group 11 late-split probe. The reference and corrected renderer give zero. Both gains across the 16 full images match 262,144/262,144. + +For the broader sweep vary each paired split independently between its fifth, sixth and seventh group. Nineteen occupancy fields exercise every combination containing a seventh-group split. Twelve more fields make groups 8–15 contain 5,460 copies or fall short by 1, 37 or 53. For the 19 fields use PCG64 seed 199511 and enumerate zero-based cut triples from (4,4,4) to (6,6,6) lexicographically, skipping triples without a 6. Draw 256 integer quotas uniformly from 87 through 98. Keep each of 16 parents when a uniform draw exceeds .15, then each of 64 groups when a new draw exceeds .25. For the three eight-group regions in order 0, 16, 32, replace their 32 quotas with base 145, 98 or 67 for a cut of 4, 5 or 6, adding independent integer offsets −6 through 6. Accept draws that land in the requested groups. For the 12 short fields use PCG64 seed 200753 and cut triples 555, 656, 565, 456, 666, 544, 645, 444. Use deficits 1, 37 and 0 for the first two triples and 53 elsewhere. Start with quotas 90 through 105, parent and group thresholds .10 and .13, and regional bases 143, 95 and 66 with offsets −5 through 5. Divide the required active leaf count for groups 8–15 equally among their 32 quotas, giving the remainder to distinct uniformly sampled positions. Select rounds 0, 5, 17, 28, 41 and 62 from the [64-group pair comparison](#sparse-quadrant-parents-and-leaves-in-moisture-noise), using both gains. The 276 full F32 renders match 4,521,984/4,521,984, maximum zero. The earlier 150 fields also match 2,457,600/2,457,600. Four independent marker orderings each passed all 32,766 adjacent signed comparisons. Saving and reopening seven new settings and six existing controls reproduced both applications’ originals and matched 212,992/212,992 across applications. + +Repeat both generators at the [five isolated settings](#two-independent-pattern-sources-in-moisture-noise), with their original U16 precision, original tiling in F32, and tiling disabled in F32. Thirteen of the 20 F32 renders now match every pixel, up from three. + +| Isolated output | Destination exact / total · max | Source exact / total · max | +|---|---:|---:| +| U16, original tiling | 26,624/26,624 · 0 | 26,624/26,624 · 0 | +| F32, original tiling | 26,593/26,624 · 5.96046448e−8 | 26,624/26,624 · 0 | +| F32, tiling off | 26,455/26,624 · 1.1920929e−7 | 26,390/26,624 · 7.4505806e−9 | + +Repeat the 110 whole-root settings and 18 saved selections listed in the [earlier comparison](#sparse-quadrant-parents-and-leaves-in-moisture-noise). The one-processor result gained 143 exact pixels, including all 110,592 pixels in the 16 additional settings. The eight-processor comparison lost 47 exact pixels. Each application reproduced all 487,424 of its own pixels after reopening the saved files. Across applications the reopened comparison matched 487,396/487,424, with a maximum F32 error of 7.80522823e-05. + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Whole root, one processor | 760,064/760,064 · 0 | 1,413,827/1,413,888 · 6 | 760,052/760,064 · 0.00048828125 | 1,338,317/1,338,368 · 7.80820847e−5 | +| Whole root, eight processors | 760,060/760,064 · 1 | 1,413,659/1,413,888 · 6 | 760,034/760,064 · 0.00048828125 | 1,338,156/1,338,368 · 7.83205032e−5 | + +The shared two-child draw path retained 1,792,256/1,792,256 pixels in the 97 one-processor Clouds 2 settings and 1,792,196/1,792,256 on eight. The median process CPU time for the [three release benchmark settings](#sparse-quadrant-parents-and-leaves-in-moisture-noise) was 12.227 seconds before and 12.133 after, with four runs per version on one processor. All 436 node and evaluator release tests passed, together with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Eight full subtree pairs in Dirt Gradient + +In this Dirt Gradient fixture, MaterialCraft counts 10,920 physical tile copies in each of eight adjacent pairs of depth-three subtrees in the final quadrant. The recorded pixels agree with a different ordering of the parent and descendant draws. MaterialCraft groups 5,460 copies per batch and applies that ordering when its cuts stay in the measured subtree intervals. The regression distinguishes a late continuation inside group 60. + +Start with a full four-child tree and additive squares at depths seven, eight and nine. Number stamps in depth-first order from zero. Each depth-seven parent and its descendants contribute 21 stamps. In every depth-four subtree move 24 depth-nine squares to the left seam. Select the first 24 cells in row-major order within its 32² depth-nine grid. This adds 96 copies per depth-three group. Use a 128² F32 white canvas and compare pairs of depth-seven markers at shared centers with gains −1 and 2⁻²⁵. The 73 frames gave 57,275 marker readings for stamp pairs, including all 32,766 adjacent comparisons in both gain assignments. For the 16,384 parents, a sequence of 59 runs fits those readings. Comparisons of individual stamps locate 20 cuts inside parent groups in that sequence. Two further sets of 2,066 comparisons placed stamps 327924 and 327935 after the 14,051st parent, between stamps 306306 and 330624. Eleven adjacent comparisons put the intervening stamps in ascending order. These last 12 stamps of group 60 form a separate run. [Single-pair probes and stamp coordinates](#individual-tile-copies-after-two-full-horizontal-batches) + +For the compact regression, place the extra copies on the first 24 stamps of each 1,344-stamp depth-four subtree in traversal order. Use seed 206407 and the same two gains. Put stamp pairs (327923,88021), (327924,91851), (327925,91651) and (327935,93255) at (16,24), (18,24), (20,24) and (22,24). At x = 24, 26, 28, 30, 32 and 34 on that row, use (344042,259673), (279529,324712), (85920,267859), (42912,267222), (10643,214976) and (10644,91692), respectively. Exchange gains and read the raw F32 image. All 20 marker readings and 32,768/32,768 image pixels match. The regression failed with the previous renderer. [Executable square regression](../crates/nodes/src/pattern/tests/paired_batches.rs) + +For each of the nine both-axis [generator settings](#three-active-quadrant-levels-in-dirt-5-and-dirt-gradient), count the edge copies in each of 256 depth-four subtrees. Apply those counts to an independently generated square tree. Pair depth-three groups in rotation rounds 0, 5, 17, 28, 41 and 62, repeating with the gains swapped. All 108 fields match 1,769,472/1,769,472 pixels. For weighted inputs use the [packed stamp grid](#individual-tile-copies-after-two-full-horizontal-batches) at 128² and 128 × 64. Include the measured copy counts for the 256² seed-zero, 128 × 64 seed-142327 and 128² seed-186793 generators. In seventeen more fields vary the counts per depth-four subtree with PCG64 seed 206379. Sweep the totals for group 60 through 84, 85, 96, 102, 128, 156 and 175. Bring the final quadrant’s depth-three pairs up to at least 10,920 copies. The fields cover both a cut at the group boundary and cuts inside the group. To regenerate the weighted pixel data, label the first three fields onp1, onp0 and onh4 in the order of sizes given above. Label the other fields var0 through var17, omitting var14. For a label’s characters c₀, c₁, …, seed PCG64 with 193887 + Σ(i + 1) × codepoint(cᵢ). Generate a uniform number per stamp and divide it by 4, 1.8 or 1 at depth seven, eight or nine. Within each depth-four subtree, move the stamps with the lowest scores to the seam until its copy quota is met. For field ordinal k and size ordinal j, seed a fresh PCG64 with 206333 + 41k + 97j. Generate three unsigned bytes per stamp, take the first two modulo 32 and the third modulo 128. Add 128 to the third byte for edge stamps. Pack those bytes at the depth-specific coordinates in the linked grid. Across the 40 weighted renders, 491,520/491,520 pixels match. The 28 earlier weighted and signed images match 352,256/352,256, and another 64 earlier pressure and square controls match 802,816/802,816. All maxima are zero. + +Reopen both weighted sizes for variant numbers 0, 2 and 13 and the 128² seed-186793 copy distribution. Reopen the forward 128² signed regression as well. Both applications reproduce their originals. The nine cross-application comparisons match 114,688/114,688 pixels, maximum zero. All nine both-axis Dirt Gradient F32 generator settings now match 175,104/175,104 pixels, up from 42,464/175,104. The 36 horizontal, untiled and Dirt 5 generator controls match 700,416/700,416, maximum zero. + +Repeat the [111 whole-root settings and 28 saved selections](#individual-tile-copies-after-two-full-horizontal-batches). Their exact counts are unchanged. Maximum integer errors are in storage codes. + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Dirt Gradient, one processor | 600,320/600,320 · 0 | 846,337/846,592 · 2 | 600,300/600,320 · 0.00048828125 | 815,867/816,128 · 1.96099281e−5 | +| Dirt Gradient, eight processors | 600,320/600,320 · 0 | 846,301/846,592 · 2 | 600,296/600,320 · 0.00048828125 | 815,814/816,128 · 2.03251839e−5 | +| Reopened, one processor | 36,864/36,864 · 0 | 80,879/80,896 · 1 | 32,767/32,768 · 6.10351562e−5 | 279,764/279,808 · 1.88946724e−5 | + +Each application reproduces all 430,336 pixels of its own whole-root originals. Dirt 5 retains 2,662,656/2,662,656 on one processor, 2,661,672/2,662,656 on eight and 354,560/354,560 across 22 reopened settings. Dirt Gradient remains in progress. The remaining whole-graph difference is visible, for example, at 64² with seed 42 in U16 and F32. + +To locate that difference, read each of the three pattern generators, two blends and three levels nodes in the original graph. Reconnect each stage in a separate saved graph. Use all four formats at 64², seed 42. Add F32 at 128 × 32, seed 398611, 128 × 256, seed 398693, 128 × 512, seed 398816, and 256 × 128, seed 142453. Repeat F32 at 64², seeds 41 and 43, and 32 × 128, seed 398611. All 88 rewired reference comparisons reproduce the original stage buffers, 1,054,720/1,054,720 pixels. The first two generators match 191,488/191,488 stored pixels across applications. In the third generator the 64² seed-42 pixel (36,46) is 8343 in MaterialCraft and 8342 in the reference. The blend gives 28897 and 28896 at the same pixel. Final F32 levels give 0.325307131 and 0.325291693, respectively. + +At the eight distinct sizes and seeds from those settings, expose the third generator in F32 with its original horizontal tiling. It matches 71,865/151,552, maximum 8.94069672e-08. With the 64² seeds 41 and 42, 128 × 32 seed 398611 and 128 × 256 seed 398693, turning tiling off or enabling both axes gives 90,112/90,112 pixels across the eight comparisons, maximum zero. + +In four interleaved single-processor release runs per version, render the 256², 128 × 64 and second 128 × 64 both-axis generator settings at seeds 0, 142327 and 186722. Median process CPU time changed from 9.781 to 9.789 seconds. All 436 release tests for nodes and the evaluator passed, together with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Completing short paired quadrant batches in Moisture Noise + +Start with the [sparse quadrant tree](#sparse-quadrant-parents-and-leaves-in-moisture-noise). A run of fewer than 5,460 submitted copies from groups 24–31 borrows the missing copies from group 52. Groups 40–47 borrow from group 56. When the paired prefix starting at 16 or 32 splits in its seventh group, its short block finishes immediately after that prefix. Other pending blocks finish after the prefix starting at 0. If that prefix splits in its seventh group, block 24 finishes first. Otherwise block 40 finishes first. The measured rule covers sixth- and seventh-group splits and borrowing strictly within the first partner group. + +For the regression, enable all 16 depth-two parents and all 64 depth-three groups. In each depth-four subtree set the first q cells of the 16² depth-eight grid to .25 and the rest to zero. For the six consecutive blocks starting at groups 0, 16, 32, 8, 24 and 40, respectively, use q = (95,66,95,96,84,83), (95,95,66,84,83,82) or (66,95,95,85,82,84), and use 96 elsewhere. Draw two coincident depth-seven squares on white with gains −1 and 2⁻²⁵, then swap the gains. Compare 48 pairs per profile, including groups 24, 40, 52 and 56 against each other and the three paired prefixes. All 288 signed marker values and all 98,304 pixels in the six 128² F32 images match. The previous range calculation declined all three profiles. An independently reconstructed ordering also matches all 32,766 signed adjacent comparisons on the isolated generator's fifth setting with tiling disabled. + +For the broader sweep, use PCG64 seed 205173. Enumerate sixth- and seventh-group splits independently for the three paired prefixes. For each combination test short blocks at (24), (40), (24,40), (24,8), (40,8) and (24,40,8). Keep parents when uniform draws exceed .12 and groups when they exceed .19. Start with integer q in [92,103]. Use 93 or 66 for the paired subtrees plus an independent integer in [−8,8]. Target 5,460 minus 84–176 copies for short blocks, or plus 79–160 for full blocks. Subtract retained parents, groups and the 85 interior cells per subtree. Distribute the remaining leaves across the 32 subtrees with neighboring quotas offset by opposite integers in [−6,6]. Twelve additional fields at seed 208611 include exact fills and deficits of 1, 26, 53, 97 and 511. Across these 60 fields, all 13,440 signed prefix comparisons agree. Their 120 complete marker images match 1,966,080/1,966,080. Compare independent weighted group pairs in rounds 5 and 28, or 17, 41 and 62 when all three blocks are short. The 256 F32 images match 4,194,304/4,194,304. Another 448 earlier renders match 7,340,032/7,340,032. Saving and reopening 12 new controls reproduced both applications’ original pixels and matched 196,608/196,608 across applications. Thirteen earlier saved controls matched 212,992/212,992. + +Both generators now match all five [isolated settings](#two-independent-pattern-sources-in-moisture-noise) in U16, F32 with original tiling and F32 with tiling disabled. All 30 outputs match 159,744/159,744, including all 20 floating-point outputs. Repeat at 128² with width 44.21875, height 177.90625 and disorder .09375, at default 512², and at 256 × 1024 with seed 57669, width 105.90625, height 121.46875 and disorder .53125. Include 128² seed 1, 128 × 64 seed 0 and 256 × 128 seed 0 using the first controls. At seven whole-root settings, the four reconnected stored stages agree with their original outputs and with MaterialCraft on 2,457,600/2,457,600 pixels. The two generators' 12 independent F32 outputs match 1,196,032/1,196,032. + +The [110 whole-root settings](#two-independent-pattern-sources-in-moisture-noise) now match every pixel on one processor, gaining 124. The eight-processor comparison loses 34 exact pixels and differs at 509. All 18 one-processor saved settings reproduce both applications' original outputs and match across applications. + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| One processor | 760,064/760,064 · 0 | 1,413,888/1,413,888 · 0 | 760,064/760,064 · 0 | 1,338,368/1,338,368 · 0 | +| Eight processors | 760,060/760,064 · 1 | 1,413,642/1,413,888 · 6 | 760,028/760,064 · 0.00048828125 | 1,338,145/1,338,368 · 7.83205032e−5 | +| Reopened, one processor | 28,672/28,672 · 0 | 24,576/24,576 · 0 | 8,192/8,192 · 0 | 425,984/425,984 · 0 | + +To check repeatability, use the 128² and default 512² settings above at seed 0 in U16 and F32. Include default 256² at seed 42 in U8 and the 256 × 1024 setting above at seed 57669 in U16, F16 and F32. Alternate offsets 0, 7, 0, 13, 0 from each input seed. On one processor all three original-seed passes reproduce the earlier capture, 4,227,072/4,227,072 pixels. On eight processors, the original graph differed from itself at 540 of 4,227,072 compared pixels across the three pairwise comparisons. The reopened graph differed from itself at 498. Across all five seed passes, original and reopened eight-processor outputs agreed on 7,044,256/7,045,120 pixels. + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| One processor, repeated original seed | 196,608/196,608 · 0 | 1,622,016/1,622,016 · 0 | 786,432/786,432 · 0 | 1,622,016/1,622,016 · 0 | +| Eight processors, repeated original seed | 196,606/196,608 · 1 | 1,621,752/1,622,016 · 6 | 786,384/786,432 · 0.00048828125 | 1,621,790/1,622,016 · 7.83205032e−5 | +| Eight processors, repeated reopened seed | 196,608/196,608 · 0 | 1,621,818/1,622,016 · 6 | 786,384/786,432 · 0.00048828125 | 1,621,764/1,622,016 · 7.83205032e−5 | +| Eight processors, original versus reopened | 327,678/327,680 · 1 | 2,702,936/2,703,360 · 6 | 1,310,643/1,310,720 · 0.00048828125 | 2,702,999/2,703,360 · 7.83205032e−5 | + +The shared draw path retained 1,792,256/1,792,256 exact pixels on one processor and 1,792,196/1,792,256 on eight across 97 Clouds 2 settings. Four interleaved runs per version at the [three release benchmark settings](#sparse-quadrant-parents-and-leaves-in-moisture-noise) gave median process CPU times of 5.820 seconds before and 5.758 after. All 436 node and evaluator release tests passed, together with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Horizontal pattern batches ending in the preceding subtree + +The third Dirt Gradient generator can finish a 5,460-copy batch in the last depth-four subtree of group 50, 54, 58 or 62. The remaining copies in that subtree draw later. The renderer now accepts that cut when horizontal tiling is active, the pair holds fewer than 10,920 physical copies and the cut stays strictly inside the two adjacent depth-four subtrees' outer bounds. The later draw order changes in other groups and full pairs. + +For the regression, use the [horizontal tree of additive squares](#eight-full-subtree-pairs-in-dirt-gradient). Give each depth-three group 32 extra horizontal copies, except groups 50, 54, 58 and 62 at 91, 96, 93 and 95 respectively. In group g with q extra copies, give each of its four depth-four subtrees floor(q/4) extras. Add one at slot s when (s + g) modulo 4 is below q modulo 4. Move the first stamps in depth-first order within each depth-four subtree to the left seam. At seed 214261 pair 16 depth-seven or descendant squares on white with gains −1 and 2⁻²⁵, then swap the gains. Before the fix all 32 signed sample values differed. The two corrected F32 images match 32,768/32,768. + +Use the [packed stamp grid](#individual-tile-copies-after-two-full-horizontal-batches) with weights generated from PCG64. Render at 128² and 128 × 64. In the boundary sweep initialize each depth-four extra count with a random integer from 5 through 13, using seed 211057. For each selected group distribute 83, 84, 85, 96 or 120 extras across its four subtrees with equal multinomial probabilities. Give its following group 32 extras. Advance the paint seed from 211519 by 43 per profile and 67 per size. These are the original single-processor captures. Each row covers ten F32 renders. + +| Group | Previous exact / total · max | Current exact / total · max | +|---|---:|---:| +| 50 | 115,158/122,880 · 3.4570694e−6 | 122,880/122,880 · 0 | +| 54 | 115,151/122,880 · 2.98023224e−6 | 121,919/122,880 · 2.38418579e−6 | +| 58 | 115,167/122,880 · 2.86102295e−6 | 121,934/122,880 · 1.90734863e−6 | +| 60 | 115,175/122,880 · 2.86102295e−6 | 115,175/122,880 · 2.86102295e−6 | +| 62 | 115,189/122,880 · 3.81469727e−6 | 122,880/122,880 · 0 | + +On two of the boundary profiles the reference produced different F32 values on different captures. Repeat both sizes, holding the input pixels fixed and using seed offsets 0, 1, 0. At 85 extras in group 54 and 84 in group 58, all six renders of each profile on each of processor indices 0 and 4 match the current draw order, 294,912/294,912 pixels. At index 6 the comparisons give 70,843/73,728 · 2.38418579e−6 for group 54 and 68,990/73,728 · 3.09944153e−6 for group 58. With eight processors the corresponding results are 67,899/73,728 · 3.33786011e−6 and 67,906/73,728 · 3.33786011e−6. + +In the second sweep, j = 0 uses the fixed regression distribution. For j greater than zero, generate each group's quota with seed 214153 + 37j. Start each at an integer in [28,64]. Select the even group of each of the four pairs from 66, 81, 83, 84, 85, 88, 91, 96, 101, 120, 143 or 163. Choose its neighbor from 2 through 165 minus that count. At j divisible by 3 set groups 48 and 49 to 85 and 89. For j modulo 4 equal to 1, 2 or 3, override groups 62–63, 58–59 or 60–61 with (70,101), (81,102) or (80,96), respectively. Distribute each quota as in the regression. Use paint seeds 214557 + 41j and 214654 + 41j. The twelve weighted images at j = 0, 4, 8, 9, 12 and 16 improved from 135,877/147,456 · 3.57627869e−6 to 147,456/147,456 · 0. Five profiles also cross an earlier subtree boundary. Those ten outputs are unchanged at 113,222/122,880 · 2.86102295e−6. Seven further distributions taken from actual generator settings match 168,145/172,032 · 3.4570694e−6 across fourteen weighted renders. The 150 earlier signed and weighted pair controls match 2,293,760/2,293,760, and another 92 earlier controls match 1,155,072/1,155,072. All 45 earlier generator controls match 875,520/875,520. + +Repeat the [eight horizontal F32 settings and their isolated stored stages](#eight-full-subtree-pairs-in-dirt-gradient). The horizontal generator improved from 71,865/151,552 to 126,056/151,552 · 7.4505806e−8. Six settings match every pixel. At 64² seed 42 the result is 1,661/4,096 · 5.96046448e−8, and at 128 × 256 seed 398693 it is 9,707/32,768 · 7.4505806e−8. The eight untiled and both-axis renders still match 90,112/90,112. All 88 reconnected stages reproduce the original reference buffers. Across applications the first two generators match 191,488/191,488 stored pixels. The third matches 163,824/163,840 with a maximum of 1 storage codes. At (36,46) in the 64² seed-42 case it still gives 8343 and 8342 in U16. + +Reopen both boundary sizes for group 50 at 84 extras, group 54 at 85, profiles 0 and 9 of the second sweep, the forward signed regression and the isolated generator at 64² seed 42, 128 × 32 seed 398611 and 128 × 512 seed 398816. MaterialCraft reproduces all twelve originals. The reference matches 187,455/188,416 · 2.38418579e−6 against its originals. The cross-application result is 185,981/188,416 · 5.96046448e−8. + +Repeat the [111 whole-root settings and 28 saved selections](#individual-tile-copies-after-two-full-horizontal-batches). All twelve changed single-processor settings now match every pixel. This gains 125 exact pixels, with 411 still different. Eight processors lose eleven exact pixels. Both applications reproduce their own original outputs at all 28 reopened settings. + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Dirt Gradient, one processor | 600,320/600,320 · 0 | 846,398/846,592 · 2 | 600,301/600,320 · 0.00048828125 | 815,930/816,128 · 1.96099281e−5 | +| Dirt Gradient, eight processors | 600,320/600,320 · 0 | 846,294/846,592 · 2 | 600,297/600,320 · 0.00048828125 | 815,809/816,128 · 2.03251839e−5 | +| Reopened, one processor | 36,864/36,864 · 0 | 80,879/80,896 · 1 | 32,767/32,768 · 6.10351562e−5 | 279,777/279,808 · 1.87754631e−5 | + +Dirt 5 retains 2,662,656/2,662,656 exact pixels on one processor, 2,661,672/2,662,656 on eight and 354,560/354,560 across the 22 reopened settings. The median process CPU time for the 128 × 32 seed-398611, 64² seed-41 and 128 × 512 seed-398816 F32 generator renders was 9.594 seconds before and 9.633 seconds after the fix, using four interleaved runs per version on one processor. All 436 node and evaluator release tests passed, together with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Deferred copies in horizontal Dirt Gradient batches + +Across 111 distinct whole-root settings, 91 match every pixel on one reference processor, up from 81. Ten changed outputs account for all 83 newly matching pixels. On eight processors 43 settings match every pixel, down from 45, and seven fewer pixels match. All 28 MaterialCraft saves reopened in both applications. Each application reproduced its original 430,336 pixels. The cross-application difference fell from 49 pixels to 16. Maximum errors are in storage codes for integers and in absolute units for floats. + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Whole root, one processor | 600,320/600,320 · 0 | 846,442/846,592 · 2 | 600,302/600,320 · 0.00048828125 | 815,968/816,128 · 1.96099281e−5 | +| Whole root, eight processors | 600,320/600,320 · 0 | 846,290/846,592 · 2 | 600,298/600,320 · 0.00048828125 | 815,805/816,128 · 2.03251839e−5 | +| Reopened, one processor | 36,864/36,864 · 0 | 80,887/80,896 · 1 | 32,767/32,768 · 6.10351562e−5 | 279,802/279,808 · 1.80006027e−5 | + +Repeat the original and changed whole-graph settings with U8, U16, F16 and F32 output. For the ordering probe, use the third generator’s complete depth-nine quadrant tree with original additive square stamps at depths seven through nine and horizontal tiling. Each of its 64 depth-three groups contains 5,376 logical draws before tiling. One physical batch holds 5,460 copies. At 64² and seed 42, group 60 fills one batch and its six remaining copies draw later. At 128 × 256 and seed 398693, groups 50–51 fill two batches and defer 14 copies. The original signed probes verify all 32,766 adjacent depth-seven parent comparisons in each setting. Overlaps in both polarities place the first and last deferred copies and verify the order within each tail. Replaying the observed order matches all 36,864 raw F32 pixels. Groups 54–55 produce the corresponding displacement into group 32 at 128 × 256, seed 142631, and 256 × 128, seed 188843. These two generator images match 65,536/65,536. [Whole-graph settings](#horizontal-pattern-batches-ending-in-the-preceding-subtree) + +To reproduce the four regressions, start with 32 additional horizontal seam copies per group. Set groups 50–51 to 75 and 107, set group 60 to 90, combine both changes, or set groups 54–55 to 75 and 107. Use seeds 220419, 220472, 220525 and 222453 respectively. The pairs of logical draw indices and quota distribution are in the regression. Give one square weight −1 and the other 2⁻²⁵ over a background of one, swap the weights and read the same pixels in F32. Both directions agree on all 76 signed comparisons. The compiled renderer matches 131,072/131,072 · 0 over the eight complete images. [Regression fixture](../crates/nodes/src/pattern/tests/paired_batches.rs) + +For the receiving-subtree boundary, use 128 × 64 weighted square fields. Put 78 extra seam copies in group 50 or 54 and 90 + E in its neighbor, with E in 0, 1, 14, 31 and 63. In the receiving group, 16 or 32 respectively, set the extra count to 84 − E plus an offset of −3, −1, 0, 1 or 4. Split each quota between four depth-four subtrees as in the regression. Keep all other group counts at 32. Name the case with the group, E and offset + 3 as in `p50e14d2`. Seed PCG64 with 193887 plus the sum of the one-based character positions times their ASCII values. Draw a uniform number per logical stamp in depth-first order, divide by 4, 1.8 or 1 at depth seven, eight or nine, and wrap the lowest scores within each subtree. Use the four-weight input construction with paint seed 222419 + 19j. Number j from zero in the order above, starting the group-54 sweep at 35. Below capacity the predicted two-batch order matches all 163,840 F32 pixels. At capacity it matches 73,526/81,920 · 2.38418579e−6. Above capacity it matches 146,845/163,840 · 1.90734863e−6. The renderer uses this continuation only while the receiving group has room. A subsequent full batch can split later subtrees again. [Weighted field construction](#the-first-subtree-pair-in-the-final-dirt-gradient-quadrant) + +The compiled renderer matches all 151,552 pixels in the eight horizontal F32 isolates, up from 126,056. Untiled and both-axis controls each match 45,056/45,056. Across the 86 earlier weighted component settings the compiled result changed from 1,033,611/1,056,768 · 3.4570694e−6 to 1,045,203/1,056,768 · 2.86102295e−6. All twelve previously exact settings from the six boundary distributions match 147,456/147,456. Nine additional saved signed and weighted controls reproduced their original output in both applications and match 104,581/106,496 · 2.38418579e−6 across applications. For the twelve release cooks of the six boundary distributions, the median elapsed time was 9.566 seconds before and 11.242 after. The measurements include contention from concurrent comparisons. + +Thirteen remaining seed-and-size combinations from the preceding build and two independent seeds isolate the discrepancy to the third generator. The first two generators match 261,120/261,120 · 0 in stored U16. The third matches 504,154/504,320 · 1 in stored U16 and 260,217/504,320 · 1.1920929e−7 in direct F32. At 512² and seed 398898, the whole U16, F16 and F32 outputs still differ at 124, 14 and 132 pixels, respectively. Three fresh one-processor captures of eight direct F32 settings, with size and seed 512 × 512 at 398898, 128 × 256 at 142631, 128 × 256 at 398693, 256 × 128 at 188843, 128 × 128 at 42, 64 × 128 at 142326, 64 × 64 at 42 and 32 × 16 at 188233, reproduce 1,166,691/1,168,896 · 2.98023224e−8 relative to their first captures. The middle repeat differs at 2,013 pixels for seed 142631 and 192 at 64² and seed 42. Dirt 5 retains its previous 95-setting result, 2,662,656/2,662,656 on one processor and 2,661,672/2,662,656 on eight. All 436 node and evaluator release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly checks passed. + +### Full receiving quadrants and seven-batch prefixes in Dirt Gradient + +Dirt Gradient matches **96 of 111 settings** on one processor. The five newly exact settings use 512 × 512 at seed 398898 (U16, F16 and F32) and 256 × 64 at seed 195577 (U16 and F32). The other 106 settings retain their previous one-processor counts. The reference at eight processors matches 43 whole settings. Integers below use stored codes and floats use absolute channel error. The matrix includes defaults, changed parameters, independent seeds, rectangular dimensions and the same 28 MaterialCraft save/reopen controls. [Whole-root settings and procedural inputs](#deferred-copies-in-horizontal-dirt-gradient-batches) + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| One processor | 600,320/600,320 · 0 | 846,572/846,592 · 1 | 600,316/600,320 · 0.000244140625 | 816,107/816,128 · 1.80006027e−5 | +| Eight processors | 600,320/600,320 · 0 | 846,268/846,592 · 2 | 600,296/600,320 · 0.00048828125 | 815,790/816,128 · 2.03251839e−5 | +| Reference one versus eight | 600,320/600,320 · 0 | 846,260/846,592 · 2 | 600,296/600,320 · 0.00048828125 | 815,777/816,128 · 2.03251839e−5 | +| Saved files on one processor | 36,864/36,864 · 0 | 80,887/80,896 · 1 | 32,767/32,768 · 6.10351562e−5 | 279,802/279,808 · 1.80006027e−5 | + +At 512 × 512, the third generator submits 10,922 horizontal tile copies from depth-three groups 54 and 55. Their two excess copies precede the draws from group 32. That group fills another 5,460-copy batch and changes the order of later quadrants. Original overlapping squares established 55 contiguous parent ranges, with 32,766 signed adjacent comparisons across 16,384 parents. Splitting the final two copies gives 56 physical ranges. Direct F32 comparison of the compiled generator improves from 79,736/262,144 pixels to 262,144/262,144, maximum zero. Independent weighted fields vary the receiving group and the two donating groups across the capacity threshold. Two spare copies plus 82 extra copies in the receiver fill the batch. With 81 extra copies the earlier continuation still matches all 8,192 pixels. For pairs with 0, 1, 14, 31 and 63 deferred copies, set the receiver to the threshold or 1 or 4 copies above it. The draw-order replay matches 10 of these 15 weighted fields and 118,260/122,880 · 2.62260437e−6 on the first captures. Three fresh captures of each of the five differing fields yield 14 exact renders out of 15 and 121,924/122,880 · 3.33786011e−6. + +At 256 × 64, seven batches finish 23 copies before the next depth-three group. When that group's copies and the remaining prefix fit in one batch, the calculated boundary can fall in the preceding depth-four subtree. Use groups 8–14, 24–30 and 40–46 in turn. At 128², give each of the seven groups 87 extra copies and all other groups 32, using seeds 225641, 225664 and 225687. For the receiving-quadrant test use seed 225301, with 116, 90 and 80 extra copies in groups 32, 54 and 55 respectively. The eight signed F32 renders reproduce all 70 marker comparisons and 131,072/131,072 pixels, maximum zero. The compiled direct F32 generator at seed 195577 improves from 5,603/16,384 pixels to 16,384/16,384, maximum zero. [Square construction and tile-copy counts](#horizontal-pattern-batches-ending-in-the-preceding-subtree) + +The one-processor whole-root difference falls from 328 pixels to 45. The eight-processor difference changes from 647 to 686. The two reference captures differ at 707 pixels. Three additional single-processor captures of each of the previous 20 nonexact settings, with alternating case order, reproduce all 2,927,616/2,927,616 stored pixels. Of the 45 remaining single-processor differences, 33 match the independent eight-processor capture and 12 differ from every retained reference value. All 28 saved packages reproduce each application's original output. Cross-application agreement is 430,320/430,336 · 1. Nine additional saved signed and weighted settings reproduce each original and match 88,164/90,112 · 2.38418579e−6 across applications. + +Remaining single-processor differences occur at six seed-and-size combinations. Further full-pair continuations and the late splits around groups 50, 54, 58, 60 and 62 remain under measurement. Both regression tests failed before the change. All 438 release tests in the node and evaluator crates passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly checks. + +### Middle and penultimate horizontal subtree pairs in Dirt Gradient + +Dirt Gradient matches 102 of 111 whole settings on one processor, up from 96. Six additional U16, F16 and F32 renders are exact at 128², seed 191593, and 128 × 64, seed 142328. The other 105 settings retain their previous counts. Against eight processors 44 settings match in full. On the 28 saved-file controls each application reproduces every one of its own 430,336 pixels. Integers in the table use stored codes and floating-point maxima are absolute channel errors. [Whole-root inputs, settings and preceding measurements](#full-receiving-quadrants-and-seven-batch-prefixes-in-dirt-gradient) + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| One processor | 600,320/600,320 · 0 | 846,577/846,592 · 1 | 600,319/600,320 · 6.10351562e−5 | 816,113/816,128 · 1.75833702e−5 | +| Eight processors | 600,320/600,320 · 0 | 846,265/846,592 · 2 | 600,295/600,320 · 0.00048828125 | 815,784/816,128 · 2.03251839e−5 | +| Reference one versus eight | 600,320/600,320 · 0 | 846,260/846,592 · 2 | 600,296/600,320 · 0.00048828125 | 815,777/816,128 · 2.03251839e−5 | +| Saved files on one processor | 36,864/36,864 · 0 | 80,887/80,896 · 1 | 32,767/32,768 · 6.10351562e−5 | 279,808/279,808 · 0 | + +Use a complete quadrant tree with active levels 7, 8 and 9, horizontal tiling and groups numbered from zero in traversal order. Groups 52–53 and 56–57 submit their subtrees separately even when either pair contains two 5,460-copy batches. This covers the two pairs together and a full first pair in groups 48–49. For the penultimate pair, start with the copies in group 60. Add the two middle depth-four subtrees of group 16 and the last subtree of group 61. When group 60 is short of one batch, add the first subtree of group 61. When group 60 fills a batch, add the third subtree instead. Reaching 10,920 copies separates the later runs. A full group 60 also advances the three affected boundaries by one depth-four subtree. + +For the middle pairs, start at 32 extra copies per group and set groups 52–53 to 101 and 90, or 56–57 to 78 and 101, or both with groups 48–49 set to 88 and 90. Use seeds 226537, 226568 and 226599. For the last four controls set groups 60–61 to (79,91), (85,97), (101,128) and (79,150), starting at seed 227173 and adding 31 each time. Reversing the two marker opacities agrees on all 208 draw-order comparisons. The compiled renderer matches 229,376/229,376 F32 pixels across the 14 signed controls. [Procedural square and copy construction](#horizontal-pattern-batches-ending-in-the-preceding-subtree) + +Fifty-four earlier weighted fields and 70 independent threshold settings give 1,015,808/1,015,808 F32 pixels in the draw-order replay. For the latter, vary group 60's extra copies over 40, 65, 79, 83, 84, 85 and 96. Across two different fields for each value, move the four selected subtree counts to give combined totals of 10,918, 10,919, 10,920, 10,921 and 10,923. The compiled renderer matches all 573,440/573,440 pixels, maximum zero. The two affected direct F32 generator settings improve from 6,661/16,384 and 3,257/8,192 to 24,576/24,576 combined, maximum zero. An additional 84 weighted settings cover mixed group occupancies and four copy-count fields from whole renders. The compiled result is 677,519/688,128 · 3.4570694e−6. + +Seven weighted settings, the forward marker input from one fixture and the reversed input from another give nine additional saves. Each MaterialCraft reopen reproduces its original. All nine source renders match across applications. In the first reference reopen series the saved files differ from the reference originals on 6,771 pixels, giving 83,341/90,112 · 3.33786011e−6 across applications. Two fresh comparisons of each source and each saved file in a new reference session reproduce the originals on 360,448/360,448 pixels with zero error. + +The one-processor whole-root comparison now differs on 31 pixels and the eight-processor comparison on 696. The reference modes differ on 707 pixels for the same 111 settings. Three extra one-processor captures of each of the earlier 20 nonexact settings repeat all 2,927,616 stored pixels. Of the remaining 31 differences, 21 match the eight-processor capture and 10 fall outside all retained reference values. Four seed-and-size combinations remain open, including a final horizontal pair with three deferred copies. Both added regressions failed before the change. All 440 node and evaluator release tests passed, together with formatting, strict workspace Clippy, dependency layers and WebAssembly. Across four interleaved release runs per implementation, the three horizontal generator settings used a median 20.281 seconds of process CPU time before the change and 20.312 seconds after it, including loading and readback. + +### Final horizontal pair with a short receiver in Dirt Gradient + +Dirt Gradient matches 105 of 111 whole settings on one processor. All 16,384 pixels now match at 128 × 128, seed 188573, in U16, F16 and F32. This corrects six, one and six pixels respectively. The other 108 one-processor settings retain their previous counts. On eight processors 45 settings are exact, up from 44, and 703 pixels differ, up from 696. Both applications reproduce all 430,336 of their own pixels in the 28 saved-file controls. The table gives stored integer levels and absolute floating-point errors. [Whole-root inputs and settings](#middle-and-penultimate-horizontal-subtree-pairs-in-dirt-gradient) + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| One processor | 600,320/600,320 · 0 | 846,583/846,592 · 1 | 600,320/600,320 · 0 | 816,119/816,128 · 1.75833702e−5 | +| Eight processors | 600,320/600,320 · 0 | 846,261/846,592 · 2 | 600,296/600,320 · 0.00048828125 | 815,780/816,128 · 2.03251839e−5 | +| Reference one versus eight | 600,320/600,320 · 0 | 846,260/846,592 · 2 | 600,296/600,320 · 0.00048828125 | 815,777/816,128 · 2.03251839e−5 | +| Saved files on one processor | 36,864/36,864 · 0 | 80,887/80,896 · 1 | 32,768/32,768 · 0 | 279,808/279,808 · 0 | + +Use horizontal tile copies of overlapping squares on a complete quadrant tree with active levels 7, 8 and 9. Groups 62 and 63 submit two batches of 5,460 copies. The 128-square field puts 100 and 71 extra copies in these groups, leaving three deferred copies. The signed draw-order probes locate all three after the two-batch prefix. When their count plus group 48 is less than 5,460, the next run fills the batch inside the first depth-four subtree of group 49. A later run finishes that subtree. The direct F32 generator improves from 8,256/16,384 to 16,384/16,384 pixels, maximum zero. [Procedural square, copy and opacity construction](#horizontal-pattern-batches-ending-in-the-preceding-subtree) + +For the signed controls, start with 32 extra copies in each group. Set groups (48, 60, 62, 63) to (80, 32, 100, 71), (81, 32, 75, 96), (82, 32, 71, 100) and (50, 91, 110, 67). Use seeds 228901, 228932, 228963 and 228994 and reverse the two marker opacities. All 128 order comparisons and 131,072/131,072 compiled F32 pixels agree, maximum zero. For the weighted fields use 0, 1, 3, 9, 18 or 61 deferred copies. Set the combined receiving total to 5,456, 5,459, 5,460 or 5,461 copies. Test uniform and independently varied group counts plus the occupancy from seed 188573. All 25 short-receiver fields agree on 204,800/204,800 pixels. Including full receivers gives 41/49 exact fields and 393,661/401,408 pixels, maximum 3.57627869e-06. Five weighted controls and two signed controls reproduce every application's 73,728 original pixels after saving. Across applications they match on 72,759/73,728 pixels, maximum 3.57627869e-06. + +The reference processor modes differ on 707 whole-root pixels. Three additional one-processor captures of 20 settings repeat all 2,927,616 pixels. Of the 18 remaining one-processor differences, 11 agree with the eight-processor reference and seven fall outside all observed reference values. The three open one-processor seed and size combinations are 191520 at 128 × 64, 142326 at 64 × 128 and 188233 at 32 × 16. The new regression failed before the change. All 441 node and evaluator release tests passed along with formatting, strict workspace Clippy, the dependency layer check and WebAssembly. + +### Fur 1 across scaled windows and saved files + +Fur 1 matches all 811,264 pixels across 62 distinct whole-root settings on both one and eight processors. The 15 MaterialCraft saves reproduce the original in each application and match across applications on 154,112/154,112 pixels. Maximum stored error is zero in all four formats. The root has no image inputs. All renders use its procedural generator. + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Whole root, one processor | 98,304/98,304 · 0 | 345,088/345,088 · 0 | 98,304/98,304 · 0 | 269,568/269,568 · 0 | +| Whole root, eight processors | 98,304/98,304 · 0 | 345,088/345,088 · 0 | 98,304/98,304 · 0 | 269,568/269,568 · 0 | +| Saved packages, one processor | 4,608/4,608 · 0 | 117,248/117,248 · 0 | 6,144/6,144 · 0 | 26,112/26,112 · 0 | + +Repeat the 21 original default, seed, parameter and precision settings. The F32 case at 64 × 32, seed 75891, uses scale 3, disorder 0.6875 and non-square expansion. Before the change to stamp projection it matched 1,313/2,048 pixels, maximum 1.67191029e-05. The first release executable with the projection change matches all 2,048 pixels, maximum zero. The complete 21-render set now matches 178,432/178,432 pixels. [Original Fur settings](#fur-pattern-sources-and-downstream-filters) · [Stored-opacity comparison](#stored-opacity-across-pattern-depths) · [Pixel-center projection and its regression](#projecting-stamp-vertices-relative-to-pixel-centers-in-scaled-windows) + +Add the settings below. The 128-square, seed-zero U16 setting also appears in the original series and counts once. All 50 retained reference settings reproduced their original 795,904 pixels in the fresh single-processor capture. For saves, take every fifth distinct original setting starting with the first, then take F32 at seed 236449, U8 at 235389, U16 and F16 at 235435, and F32 at 235457. + +| Size | Seed | Scale | Disorder | Non-square expansion | Formats | +|---|---:|---:|---:|---|---| +| 16 × 32 | 0 | 2 | 0 | On | U8, U16, F16, F32 | +| 32 × 16 | 42 | 2 | 0.21875 | On | U16, F32 | +| 64 × 64 | 433701 | 1 | 0.9375 | Off | U8, U16, F16, F32 | +| 128 × 32 | 433738 | 3 | 0.046875 | On | U16, F32 | +| 32 × 128 | 433775 | 2 | 0.5625 | Off | U8, U16, F16, F32 | +| 128 × 128 | 0 | 2 | 0 | On | U8, U16, F16, F32 | +| 256 × 128 | 433849 | 3 | 0.328125 | Off | U16, F32 | +| 128 × 256 | 433886 | 1 | 0.8125 | On | U16, F32 | +| 256 × 256 | 42 | 2 | 0 | On | U8, U16, F16, F32 | +| 512 × 128 | 433960 | 1 | 0.671875 | On | U16, F32 | +| 16 × 32 | 236449 | 2 | 0 | On | U16, F32 | +| 32 × 16 | 235389 | 0 | 0.3125 | On | U8, U16, F16, F32 | +| 64 × 32 | 235435 | 3 | 0.84375 | Off | U8, U16, F16, F32 | +| 32 × 64 | 235457 | 1 | 0.5625 | On | U16, F32 | + +To isolate the rectangular projection, render one untiled horizontal gradient stamp in a square window of span 3, 7 or 13. Center the stamp at half the span and give it the full window size on both axes. Use a signed gradient with opacity 2, rendering at 64 × 32 and 32 × 64 with seeds 75891 and 75892. All six F32 controls match 12,288/12,288 pixels with zero error. At span 7 the preceding renderer missed all 4,096 pixels, maximum 2.38418579e-07. The regression also checks the first and last pixel in both rectangular orientations. All 375 node release tests passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. The inventory status covers the measured settings. + +### Perlin Noise and Plasma across rectangular projections + +Perlin Noise, Perlin Noise v2 and Plasma each match all 775,424 pixels in 60 distinct whole-root settings on one and eight processors. Each root also matches all 152,576 pixels from 15 MaterialCraft saves reopened in both applications. The maximum stored-channel error is zero in all four formats. These three roots generate their inputs procedurally. + +| Root and comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Perlin Noise, one or eight processors | 98,304/98,304 · 0 | 335,360/335,360 · 0 | 100,352/100,352 · 0 | 241,408/241,408 · 0 | +| Perlin Noise v2, one or eight processors | 196,608/196,608 · 0 | 237,056/237,056 · 0 | 100,352/100,352 · 0 | 241,408/241,408 · 0 | +| Plasma, one or eight processors | 98,304/98,304 · 0 | 335,360/335,360 · 0 | 100,352/100,352 · 0 | 241,408/241,408 · 0 | +| Saved packages, per root | 25,088/25,088 · 0 | 51,712/51,712 · 0 | 2,048/2,048 · 0 | 73,728/73,728 · 0 | + +The original 19 settings accounted for 142,592 pixels per root. A release immediately before the stored projection change still differed in the three cases below. Each uses scale 13, disorder .8125 and non-square expansion. The second package also uses disorder speed 1.4375 and tile offset (−.3125,.4375). The following release matches all three. [Original whole-root settings](#liquid-fiber-and-related-noise-sources) · [Stored projection and earlier regression](#inverting-the-stored-pixel-projection-in-scaled-stamp-regions) + +| Root | Size, format | Seed | Previous exact / total · max | Corrected exact / total · max | +|---|---|---:|---:|---:| +| Perlin Noise | 16 × 32, U16 | 107084 | 507/512 · 2 | 512/512 · 0 | +| Perlin Noise v2 | 32 × 16, F32 | 107100 | 112/512 · 5.36441803e−7 | 512/512 · 0 | +| Plasma | 16 × 32, U16 | 107118 | 509/512 · 1 | 512/512 · 0 | + +Repeat the following ten size and seed combinations. For v2 and Plasma, add 13 and 26 respectively to seeds above 42. The v2 disorder speed equals disorder where specified. The 128² seed-zero U16 setting in the first package and Plasma, and its U8 counterpart in v2, already occur in the original series. All 48 distinct retained settings reproduce the 760,064 pixels in their earlier captures. + +| Size | Seed in first package | Scale | Disorder | Expand | Tile offset in v2 | Formats | +|---|---:|---:|---:|---|---|---| +| 16 × 32 | 0 | Default | Default | Default | Default | U8, U16, F16, F32 | +| 32 × 16 | 42 | 16 | 0.21875 | On | -0.125, 0.21484375 | U16, F32 | +| 64 × 64 | 433961 | 5 | 0.9375 | Off | 0.59375, -0.4140625 | U8, U16, F16, F32 | +| 128 × 32 | 433998 | 11 | 0.046875 | On | -0.296875, 0.365234375 | U16, F32 | +| 32 × 128 | 434035 | 27 | 0.5625 | Off | 0.21875, -0.0859375 | U8, U16, F16, F32 | +| 128 × 128 | 0 | Default | Default | Default | Default | U8, U16, F16, F32 | +| 256 × 128 | 434109 | 19 | 0.328125 | Off | -0.015625, 0.119140625 | U16, F32 | +| 128 × 256 | 434146 | 32 | 0.8125 | On | 0.46875, -0.3046875 | U16, F32 | +| 256 × 256 | 42 | Default | Default | Default | Default | U8, U16, F16, F32 | +| 512 × 128 | 434220 | 12 | 0.671875 | On | 0.328125, -0.181640625 | U16, F32 | + +For the first package, add 16 × 32 at seed 236469 with defaults, then 32 × 16, 64 × 32 and 32 × 64 at seeds 235409, 235455 and 235477. Render U16 and F32 at each size and add U8 and F16 at the two middle sizes. Use scale 5, disorder .3125 and disabled non-square expansion after the default row. For v2 add one to these four seeds, and set disorder speed .6875 and tile offset (.125,−.1875) on the changed rows. For Plasma add two to the four first-package seeds. Save every fifth distinct retained setting starting with the first. Also save F32 on the default row, U8 on the second, U16 and F16 on the third, and F32 on the fourth. + +The reduced regression uses a single signed horizontal gradient, tint 2, size (1,1) and center (.5,.5) with tiling disabled. Use a window from (0,0) to (S,1), for S = 13, 15, 51. For each span use 16 × 32, 64 × 16, 128 × 32 and 32 × 16. Starting at seed 237141, advance by seven within each size series and by 19 for the next span. These 12 F32 images improve from 18,336/18,432, maximum 1.1920929e−7, to 18,432/18,432, maximum zero. Both new 16 × 32 regression rows distinguish the stored projection inverse at the first pixel. All 442 node and evaluator release tests passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Paths Trace with rectangular path and background inputs + +Paths Trace matches 73,984/73,984 RGBA pixels on each processor count across 31 distinct settings. Nine MaterialCraft saves match 28,928/28,928 pixels on reopening in each application and across applications. Maximum error is zero in each format. + +| Root and comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| One or eight processors | 11,776/11,776 · 0 | 13,312/13,312 · 0 | 10,752/10,752 · 0 | 38,144/38,144 · 0 | +| Saved packages, one processor | 4,864/4,864 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 19,968/19,968 · 0 | + +Repeat the 19 earlier settings using the original procedural paths and backgrounds. The fresh single-processor capture reproduces all 58,624 archived pixels. For the independent 32² F32 input at seed 113, the release before the runtime bitmap draw-order correction matched 1,012/1,024 pixels, maximum 1.22619528. The release with that correction matches all 1,024 pixels. Its regression renders three overlapping stamps with fixed and parameter-bound image slots, in gray and RGBA. In the RGBA case the measured red channel at the first pixel is .51298636 for fixed selectors and .451574 for a bound selector. [Path point coordinates and background formulas](#paths-caustics-and-cell-fields-after-pattern-sampling) · [Bitmap ordering controls and regression](#pattern-draw-order-for-fixed-and-runtime-image-slots) + +For the additional settings, start with the five-point path, its 16² background, default controls, 16 × 32 output and seed zero. Use the seven-point path and 64² background with corners and vertices enabled and thickness 1.625 for 32 × 16 at seed 235461 and 64 × 32 at seed 235507. Finish with the five-point path and 32² background, corners and vertices disabled and thickness .25, at 32 × 64 and seed 235529. Render U16 and F32 in every row, adding U8 and F16 on the two middle rows. Save the first, sixth, eleventh and sixteenth retained settings, then F32, U8, U16 and F16, and F32 on the four additional rows respectively. + +### Brick pattern generators across square and rectangular outputs + +The Brick 1 and Brick 2 roots in the pattern packages each match all 1,237,248 pixels across 96 distinct settings at one and eight processors. Each set of 47 MaterialCraft saves reproduces all 920,064 pixels within each application and across applications. The maximum stored error is zero throughout. Both roots generate the bricks procedurally. + +| Root and comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Brick 1, one or eight processors | 52,736/52,736 · 0 | 584,192/584,192 · 0 | 54,784/54,784 · 0 | 545,536/545,536 · 0 | +| Brick 2, one or eight processors | 52,736/52,736 · 0 | 584,192/584,192 · 0 | 54,784/54,784 · 0 | 545,536/545,536 · 0 | +| Brick 1 saves | 20,992/20,992 · 0 | 448,512/448,512 · 0 | 18,432/18,432 · 0 | 432,128/432,128 · 0 | +| Brick 2 saves | 20,992/20,992 · 0 | 448,512/448,512 · 0 | 18,432/18,432 · 0 | 432,128/432,128 · 0 | + +Repeat the 84 archived settings for each pattern package, including the 34-case variation of tiling, smoothness and interstice width, and the 31-case fractional edge sweep. The new single-processor captures reproduce all 1,221,888 original pixels per root. MaterialCraft previously matched 1,121,408 of those pixels in Brick 1 and 1,087,172 in Brick 2. [Original pattern settings](#paper-brick-fiber-mesh-polygon-and-shape-roots) · [Rectangular settings and fractional edges](#fractional-edges-of-axis-aligned-pattern-stamps) + +The same change to pixel-center projection resolves the following F32 controls. For Brick 1 use 32 × 128 at seed 201826, scale 3, smoothness 625/1021 and interstice width .0625. The preceding renderer matched 3,511/4,096 pixels, maximum 2.4959445e−6. For Brick 2 use 32 × 16 at seed 109605, scale 5, smoothness .546875, interstice width .0625 and non-square expansion. The preceding renderer matched 457/512 pixels, maximum 1.22189522e−6. The first release with the pixel-center change matches all 4,096 and 512 pixels respectively. The rectangular gradient regression isolates the displacement at the stamp vertex. [Pixel-center projection](#projecting-stamp-vertices-relative-to-pixel-centers-in-scaled-windows) · [Independent rectangular regression settings](#fur-1-across-scaled-windows-and-saved-files) + +Add the following settings. Render U16 and F32 at each size, and add U8 and F16 on the two middle rows. For saved files take all 31 fractional-edge settings, every fifth distinct archived setting starting with the first, and F32, U8, U16 and F16, and F32 on the four new rows respectively. Count overlapping settings once. All 442 release tests in the node and evaluator crates and the workspace checks passed. + +| Output | Brick 1 seed | Brick 2 seed | Scale | Edge smoothness | Interstice width | +|---|---:|---:|---|---|---| +| 16 × 32 | 237536 | 237537 | Default | Default | Default | +| 32 × 16 | 235466 | 235467 | 3 | .34375 | .078125 | +| 64 × 32 | 235512 | 235513 | 5 | .8125 | .1875 | +| 32 × 64 | 235534 | 235535 | 2 | .15625 | .046875 | + +### Weighted color accumulation in the palette iteration + +The K-means iteration root matches all 135,168 RGBA pixels in 33 distinct whole-root settings on one and eight processors. All ten MaterialCraft saves reopen to their original 40,960 pixels in both applications and agree across applications. The output palette is 256 × 16 at every input size. Maximum channel error is zero for every measured format. + +| Root and comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| One or eight processors | 16,384/16,384 · 0 | 32,768/32,768 · 0 | 20,480/20,480 · 0 | 65,536/65,536 · 0 | +| Saved packages, one processor | 4,096/4,096 · 0 | 12,288/12,288 · 0 | 4,096/4,096 · 0 | 20,480/20,480 · 0 | + +The first difference was in the weighted RGB sum over each 256-sample row. The two input images and the 256² classification map already agreed bit for bit. The function multiplies each RGB component by its weight, packs the three products with a fourth weight component, then adds that vector to the running total. Preserving the product through packing allows a single F32 rounding per RGB addition. The evaluator uses these factors within the current iteration when each factor survives until the sum. A nested loop that clears a factor uses the previously stored vector value. The fourth component follows ordinary F32 addition. + +| Stage | 32² input before | 64² input before | 32² input after | 64² input after | +|---|---:|---:|---:|---:| +| Weighted rows | 65,416/65,536 · 3.81469727e−5 | 65,404/65,536 · 1.52587891e−5 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | +| Final palette | 4,080/4,096 · 5.96046448e−8 | 4,080/4,096 · 8.94069672e−8 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | + +For the two stage comparisons, use the independent 32² input at seed 113 and the changed 64² setting at seed 42, each with four centroids, the alpha control enabled and color space 1. Read the two source images, classification, weighted rows and final palette in their declared formats. The preceding 19 whole-root settings had 77,776/77,824 exact pixels. The new run matches all 77,824 and reproduces the retained captures. [Original palette settings and fields](#tile-weave-splatter-and-fiber-stage-comparisons) + +For a reduction to one centroid, fill the initial 256 × 16 palette with byte RGBA (64,64,64,255). Fill a 16² source with (21,89,149,99), use seed 235133, the alpha control enabled, and color space 0. In the first pixel of each weighted row the reference F32 bit patterns are 4102F577, 420AC0FE, 42684BC8, 42C6C6EC. Rounding the product separately gives 4102F576, 420AC0FF, 42684BCA, 42C6C6EC. A release regression distinguishes the two arithmetic paths and checks the nested-loop case. Across twelve one- and two-color fields, both the independent fused calculation and the corrected evaluator match all 786,432 RGBA pixels in the weighted-row stage. To reproduce the two six-case series, use the following byte colors, splitting two-color fields evenly at the middle column. Cycle through 16², 32 × 16 and 16 × 32. Use seed 235133 + 19j for zero-based row j. + +| j | First series | Second series | Alpha control | +|---:|---|---|---| +| 0 | (109,67,213,185) | (21,89,149,99) | On | +| 1 | (179,191,61,103) | (23,103,145,117) | On | +| 2 | (73,149,211,255) | Same | On | +| 3 | (109,67,213,185) | (21,89,149,99) | Off | +| 4 | (192,83,49,193) and (31,177,247,124) | (29,116,167,193) and (31,177,247,124) | On | +| 5 | (220,127,18,79) and (31,177,247,124) | Same | Off | + +For the 14 additional whole-root renders, generate source bytes at zero-based (x,y) as (7x+13y+11m, 19x+5y+3xy+m, 3x+53y+7m, 17x+29y+m) modulo 256. The seed palette at column x uses (29x+17m,43x+3m,61x+7m) modulo 256 and alpha 255 across all 16 rows. Use U16 and F32 for every row below and add U8 and F16 for the third and fourth. Save the first and every fourth retained setting, then F32, U16, F16, U8 and F32 respectively from the new rows. + +| Source size | Seed | m | Centroids | Alpha control | Color space | +|---|---:|---:|---|---|---| +| 16² | 0 | 3 | Default | Default | Default | +| 32 × 16 | 232039 | 5 | 1 | Default | Default | +| 16 × 32 | 232067 | 7 | 3 | On | 1 | +| 32² | 232091 | 11 | 5 | Off | 0 | +| 64 × 32 | 232123 | 13 | 4 | On | 1 | + +The packed-loop regression failed on the original renderer and passed after the change. All 442 release tests in the node and evaluator crates passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Directional Scratches across scaled projection windows + +Both Directional Scratches packages match 2,571,520/2,571,520 pixels each in 86 distinct settings, on one and eight processors. Each has 64 MaterialCraft saves with 2,442,240/2,442,240 exact pixels on reopening in both applications and comparing across them. Maximum stored error is zero across all four formats. + +| Root and comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Directional Scratches, one or eight processors | 432,896/432,896 · 0 | 874,752/874,752 · 0 | 434,944/434,944 · 0 | 828,928/828,928 · 0 | +| Directional Scratches, saved files | 429,824/429,824 · 0 | 766,208/766,208 · 0 | 427,264/427,264 · 0 | 818,944/818,944 · 0 | +| Directional Scratches v2, one or eight processors | 482,048/482,048 · 0 | 825,600/825,600 · 0 | 434,944/434,944 · 0 | 828,928/828,928 · 0 | +| Directional Scratches v2, saved files | 380,672/380,672 · 0 | 815,360/815,360 · 0 | 427,264/427,264 · 0 | 818,944/818,944 · 0 | + +Render the 74 archived settings, including the two thirty-case series. Their fresh one-processor captures reproduce all 2,556,160 original pixels per root. The following independent release comparisons locate the earlier differences at the change that projects stamp vertices relative to pixel centers in scaled windows. The rectangular stamp regression measures that displacement directly. [Archived scratch and Gaussian settings](#scaled-scratch-and-gaussian-noise-and-spot-generators) · [Pixel-center controls](#projecting-stamp-vertices-relative-to-pixel-centers-in-scaled-windows) · [Rectangular regression](#fur-1-across-scaled-windows-and-saved-files) + +| Root | Size | Seed | Format | Previous exact / total · max | Corrected exact / total · max | +|---|---|---:|---|---:|---:| +| Directional Scratches | 64 × 64 | 411725 | U16 | 4,087/4,096 · 1 | 4,096/4,096 · 0 | +| Directional Scratches v2 | 64 × 64 | 411732 | U16 | 4,081/4,096 · 1 | 4,096/4,096 · 0 | + +Directional Scratches at seed 411725 uses scale 3, angle 0.09375, angle random 0.34375, disorder 0.34375, pattern amount 0.34375, pattern size (0.6328125, 8.96875), pattern size random (0.296875, 0.49609375), non-square expansion on. Directional Scratches v2 at seed 411732 uses scale 3, disorder 0.34375, disorder speed 0.34375, disorder anisotropy 0.34375, disorder anisotropy angle 0.09375, angle 0.09375, angle random 0.34375, pattern amount 0.34375, pattern size (0.6328125, 8.96875), pattern size random (0.296875, 0.49609375), tile offset (0.0, 0.10546875), non-square expansion on. + +Add the following original procedural settings. Render U16 and F32 at each size and add U8 and F16 at 32 × 16 and 64 × 32. Save the settings from both thirty-case series that contributed a distinct entry after the original default, seed and precision sweeps. Also save every fifth distinct archived setting from the first, and the new F32, U8, U16 and F16, and F32 controls in size order. Count each setting once. + +| Root | Output size and seed | Exposed settings | +|---|---|---| +| Directional Scratches | 16 × 32 at 238576 | defaults | +| Directional Scratches | 32 × 16 at 235370, 64 × 32 at 235416 | angle 0.15625, angle random 0.21875, disorder 0.3125, non-square expansion off, pattern amount 0.5625, pattern size (0.6875, 3.25), pattern size random (0.0625, 0.21875), scale 1 | +| Directional Scratches | 32 × 64 at 235438 | angle 0.375, angle random 0.03125, disorder 0.125, non-square expansion off, pattern amount 0.375, pattern size (0.375, 1.75), pattern size random (0.03125, 0.09375), scale 3 | +| Directional Scratches v2 | 16 × 32 at 238577 | defaults | +| Directional Scratches v2 | 32 × 16 at 235371, 64 × 32 at 235417 | angle 0.15625, angle random 0.21875, disorder 0.3125, disorder anisotropy 0.25, disorder anisotropy angle 0.3125, disorder speed 0.6875, non-square expansion off, pattern amount 0.5625, pattern size (0.6875, 3.25), pattern size random (0.0625, 0.21875), scale 1, tile offset (0.125, -0.1875) | +| Directional Scratches v2 | 32 × 64 at 235439 | angle 0.375, angle random 0.03125, disorder 0.125, disorder anisotropy 0.125, disorder anisotropy angle 0.15625, disorder speed 0.875, non-square expansion off, pattern amount 0.375, pattern size (0.375, 1.75), pattern size random (0.03125, 0.09375), scale 3, tile offset (-0.0625, 0.125) | + +All 442 release tests in the node and evaluator crates passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Gaussian Noise across scaled projection windows + +Both Gaussian Noise packages match 2,855,168/2,855,168 pixels each in 91 distinct settings, on one and eight processors. Each has 68 MaterialCraft saves with 2,708,480/2,708,480 exact pixels on reopening in both applications and comparing across them. Maximum stored error is zero across all four formats. + +| Root and comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Gaussian Noise, one or eight processors | 509,952/509,952 · 0 | 922,624/922,624 · 0 | 509,952/509,952 · 0 | 912,640/912,640 · 0 | +| Gaussian Noise, saved files | 506,880/506,880 · 0 | 805,888/805,888 · 0 | 504,320/504,320 · 0 | 891,392/891,392 · 0 | +| Gaussian Noise v2, one or eight processors | 542,720/542,720 · 0 | 889,856/889,856 · 0 | 509,952/509,952 · 0 | 912,640/912,640 · 0 | +| Gaussian Noise v2, saved files | 441,344/441,344 · 0 | 871,424/871,424 · 0 | 504,320/504,320 · 0 | 891,392/891,392 · 0 | + +Render the 79 archived settings, including the two thirty-case series. Their fresh one-processor captures reproduce all 2,839,808 original pixels per root. The following independent release comparisons locate the earlier differences at the change that projects stamp vertices relative to pixel centers in scaled windows. The rectangular stamp regression measures that displacement directly. [Archived scratch and Gaussian settings](#scaled-scratch-and-gaussian-noise-and-spot-generators) · [Pixel-center controls](#projecting-stamp-vertices-relative-to-pixel-centers-in-scaled-windows) · [Rectangular regression](#fur-1-across-scaled-windows-and-saved-files) + +| Root | Size | Seed | Format | Previous exact / total · max | Corrected exact / total · max | +|---|---|---:|---|---:|---:| +| Gaussian Noise | 32 × 64 | 87893 | U16 | 2,046/2,048 · 1 | 2,048/2,048 · 0 | +| Gaussian Noise v2 | 32 × 128 | 433827 | U16 | 4,091/4,096 · 1 | 4,096/4,096 · 0 | + +Gaussian Noise at seed 87893 uses scale 19, disorder 0.8125, non-square expansion on. Gaussian Noise v2 at seed 433827 uses scale 27, disorder 0.5625, disorder speed 0.5625, disorder anisotropy 0.5625, disorder anisotropy angle 0.3125, tile offset (0.21875, -0.0859375), non-square expansion off. + +Add the following original procedural settings. Render U16 and F32 at each size and add U8 and F16 at 32 × 16 and 64 × 32. Save the settings from both thirty-case series that contributed a distinct entry after the original default, seed and precision sweeps. Also save every fifth distinct archived setting from the first, and the new F32, U8, U16 and F16, and F32 controls in size order. Count each setting once. + +| Root | Output size and seed | Exposed settings | +|---|---|---| +| Gaussian Noise | 16 × 32 at 238598 | defaults | +| Gaussian Noise | 32 × 16 at 235392, 64 × 32 at 235438, 32 × 64 at 235460 | disorder 0.3125, non-square expansion off, scale 3 | +| Gaussian Noise v2 | 16 × 32 at 238599 | defaults | +| Gaussian Noise v2 | 32 × 16 at 235393, 64 × 32 at 235439, 32 × 64 at 235461 | disorder 0.3125, disorder anisotropy 0.375, disorder anisotropy angle 0.1875, disorder speed 0.625, non-square expansion off, scale 3, tile offset (0.1875, -0.3125) | + +All 442 release tests in the node and evaluator crates passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Sphere displacement on rectangular height fields + +Sphere Displace matches 157,952/157,952 RGBA pixels in 31 distinct settings on one and eight processors. Nine MaterialCraft saves reproduce 29,184/29,184 pixels when reopened in both applications and compared across applications. The maximum stored-channel error is zero for each output format. + +| Root and comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| One or eight processors | 7,680/7,680 · 0 | 125,440/125,440 · 0 | 9,728/9,728 · 0 | 15,104/15,104 · 0 | +| Saved files | 4,608/4,608 · 0 | 18,432/18,432 · 0 | 2,048/2,048 · 0 | 4,096/4,096 · 0 | + +Repeat the 19 earlier settings with the original procedural height fields. The fresh one-processor capture reproduces all 142,592 archived pixels. At 32², seed 113, use the independent gray field, size .7, displacement .2, UV offset (.125,.25) and eight samples. The release before the pixel-subtraction and singular-coordinate corrections matched 1,022/1,024 F32 pixels, maximum 1.52587891e-05. The following release matched 1,024/1,024. With all other settings held at seed 113, replacing only the 32² input with constant gray bytes 0, 63 or 191 gives 3,072/3,072 exact pixels in both releases. Restoring the varying field reproduces both differences in the earlier release. The eight other constant-field settings below also match 8,704/8,704 pixels in both releases. The separate selected-product and texture-coordinate regressions cover the two changes in this release. [Earlier whole-root and stage comparisons](#tile-weave-splatter-and-fiber-stage-comparisons) · [Arithmetic and sampler controls](#pixel-subtraction-and-texture-coordinates-at-the-panorama-equator) + +For the constant controls keep the 32² independent settings above and use (width, height, gray byte, samples) of (32,32,0,8), (32,32,0,3), (32,16,0,5), (16,32,0,7), (32,32,63,3), (16,32,131,7), (64,32,0,9) and (64,32,191,9). Use seed 240283 plus 17 times the zero-based row number. Render RGBA F32. + +For the additional whole-root settings, generate one grayscale byte per texel as `(13x + 29y + 5xy + 31j) mod 256` at the output dimensions in row j. Render U16 and F32 for every row and add U8 and F16 for rows 1 and 2. + +| Row | Size | Seed | Sphere size | Displacement | UV scale | UV offset | Tilt | Samples | +|---:|---|---:|---:|---:|---|---|---|---:| +| 0 | 16 × 32 | 238011 | Default | Default | Default | Default | Default | Default | +| 1 | 32 × 16 | 235527 | 0.875 | 0.125 | (1.25, 0.75) | (0.125, -0.25) | On | 3 | +| 2 | 64 × 32 | 235573 | 0.6875 | 0.375 | (0.75, 1.625) | (-0.1875, 0.3125) | Off | 7 | +| 3 | 32 × 64 | 235595 | 1.0 | 0.0 | (1.0, 1.0) | (0.0, 0.0) | On | 2 | + +Save the first, sixth, eleventh and sixteenth retained settings and the new F32, U8, U16 and F16, and F32 cases in row order. All 442 release tests in the node and evaluator crates passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Gaussian Spots 1 across scaled projection windows + +Both Gaussian Spots 1 packages match 2,808,832/2,808,832 pixels each in 79 distinct settings, on one and eight processors. Each has 65 MaterialCraft saves with 2,689,024/2,689,024 exact pixels on reopening in both applications and comparing across them. Maximum stored error is zero across all four formats. + +| Root and comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Gaussian Spots 1, one or eight processors | 508,928/508,928 · 0 | 911,360/911,360 · 0 | 508,928/508,928 · 0 | 879,616/879,616 · 0 | +| Gaussian Spots 1, saved files | 506,880/506,880 · 0 | 805,888/805,888 · 0 | 504,320/504,320 · 0 | 871,936/871,936 · 0 | +| Gaussian Spots 1 v2, one or eight processors | 541,696/541,696 · 0 | 878,592/878,592 · 0 | 508,928/508,928 · 0 | 879,616/879,616 · 0 | +| Gaussian Spots 1 v2, saved files | 441,344/441,344 · 0 | 871,424/871,424 · 0 | 504,320/504,320 · 0 | 871,936/871,936 · 0 | + +Render the 67 archived settings, including the two thirty-case series. Their fresh one-processor captures reproduce all 2,793,472 original pixels per root. The following independent release comparisons locate the earlier differences at the change that projects stamp vertices relative to pixel centers in scaled windows. The rectangular stamp regression measures that displacement directly. [Archived scratch and Gaussian settings](#scaled-scratch-and-gaussian-noise-and-spot-generators) · [Pixel-center controls](#projecting-stamp-vertices-relative-to-pixel-centers-in-scaled-windows) · [Rectangular regression](#fur-1-across-scaled-windows-and-saved-files) + +| Root | Size | Seed | Format | Previous exact / total · max | Corrected exact / total · max | +|---|---|---:|---|---:|---:| +| Gaussian Spots 1 | 128 × 32 | 433803 | F32 | 3,138/4,096 · 5.12599945e−6 | 4,096/4,096 · 0 | +| Gaussian Spots 1 v2 | 128 × 32 | 433816 | F32 | 3,091/4,096 · 5.42402267e−6 | 4,096/4,096 · 0 | + +Gaussian Spots 1 at seed 433803 uses scale 3, disorder 0.046875, non-square expansion on. Gaussian Spots 1 v2 at seed 433816 uses scale 3, disorder 0.046875, disorder speed 0.046875, disorder anisotropy 0.046875, disorder anisotropy angle -0.203125, tile offset (-0.296875, 0.365234375), non-square expansion on. + +Add the following original procedural settings. Render U16 and F32 at each size and add U8 and F16 at 32 × 16 and 64 × 32. Save the settings from both thirty-case series that contributed a distinct entry after the original default, seed and precision sweeps. Also save every fifth distinct archived setting from the first, and the new F32, U8, U16 and F16, and F32 controls in size order. Count each setting once. + +| Root | Output size and seed | Exposed settings | +|---|---|---| +| Gaussian Spots 1 | 16 × 32 at 238600 | defaults | +| Gaussian Spots 1 | 32 × 16 at 235394 | disorder 0.21875, non-square expansion on, scale 2 | +| Gaussian Spots 1 | 64 × 32 at 235440 | disorder 0.9375, non-square expansion off, scale 1 | +| Gaussian Spots 1 | 32 × 64 at 235462 | disorder 0.046875, non-square expansion on, scale 3 | +| Gaussian Spots 1 v2 | 16 × 32 at 238601 | defaults | +| Gaussian Spots 1 v2 | 32 × 16 at 235395 | disorder 0.21875, disorder anisotropy 0.21875, disorder anisotropy angle -0.03125, disorder speed 0.21875, non-square expansion on, scale 2, tile offset (-0.125, 0.21484375) | +| Gaussian Spots 1 v2 | 64 × 32 at 235441 | disorder 0.9375, disorder anisotropy 0.9375, disorder anisotropy angle 0.6875, disorder speed 0.9375, non-square expansion off, scale 1, tile offset (0.59375, -0.4140625) | +| Gaussian Spots 1 v2 | 32 × 64 at 235463 | disorder 0.046875, disorder anisotropy 0.046875, disorder anisotropy angle -0.203125, disorder speed 0.046875, non-square expansion on, scale 3, tile offset (-0.296875, 0.365234375) | + +All 442 release tests in the node and evaluator crates passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Dirt Gradient when groups 50 and 51 fill the second quadrant + +Dirt Gradient matches 107/111 complete settings on one processor and 43/111 on eight. At 32 × 16, seed 188233, the remaining U16 and F32 pixels now agree, one newly exact pixel in each format. The other 109 one-processor results retain their previous counts and maxima. The table uses stored integer levels and absolute floating-point errors. All 28 saved files reproduce their original 430,336 pixels within each application. [Whole-root settings, input formulas and previous counts](#final-horizontal-pair-with-a-short-receiver-in-dirt-gradient) + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| One processor | 600,320/600,320 · 0 | 846,584/846,592 · 1 | 600,320/600,320 · 0 | 816,120/816,128 · 1.75833702e−5 | +| Eight processors | 600,320/600,320 · 0 | 846,260/846,592 · 2 | 600,296/600,320 · 0.00048828125 | 815,779/816,128 · 2.03251839e−5 | +| Reference one versus eight | 600,320/600,320 · 0 | 846,260/846,592 · 2 | 600,296/600,320 · 0.00048828125 | 815,777/816,128 · 2.03251839e−5 | +| Saved files on one processor | 36,864/36,864 · 0 | 80,888/80,896 · 1 | 32,768/32,768 · 0 | 279,808/279,808 · 0 | + +The first two pattern generators already agreed at this seed. The third generator improved from 201/512 F32 pixels, maximum 4.47034836e-08, to 512/512 with zero error. The root now also matches after its final levels adjustment. In the original overlapping-square test, groups 50 and 51 have 92 and 77 extra tile copies. They fill two 5,460-copy batches and leave one copy for group 16. That group's 96 extra copies take the next batch past capacity. When group 60 is short, a further split depends on group 62. With 84 extra copies it fills exactly one batch. Fewer or more copies move that boundary into the following or preceding subtree. Measurements of signed overlaps gave 51 ordered ranges. Applying their physical copy counts reproduced all 512 pixels of the isolated third generator. + +Build a complete quadrant tree with horizontal tiling and active levels seven through nine. Give the 64 groups 32 extra copies each, then set the four groups below. Place two signed, overlapping markers at each of 16 positions and repeat with the opacities exchanged. The four settings cover a receiving total one copy short, exactly full, and one copy above capacity. The eight compiled 128² F32 images match 131,072/131,072 pixels, including all 128 marker comparisons. [Square construction and copy placement](#horizontal-pattern-batches-ending-in-the-preceding-subtree) + +| Seed | Group 16 | Group 50 | Group 51 | Group 62 | +|---:|---:|---:|---:|---:| +| 239183 | 80 | 91 | 81 | 66 | +| 239214 | 84 | 82 | 87 | 84 | +| 239245 | 72 | 92 | 89 | 97 | +| 239276 | 67 | 94 | 90 | 73 | + +The 128 × 64 weighted controls use three independent series. Vary group 62 across 83, 84, 85 and 96 extra copies with group 60 below 84, using the original, uniform and PCG64-seeded group counts (seed 239015). All 42 settings match 344,064/344,064 pixels. In a separate series vary the pair's overflow across 1, 13 and 35 extra copies, with receiver totals on both sides of full and independently distributed child counts from PCG64 seed 234023. All 18 settings in this continuation match 147,456/147,456 pixels. Finally preserve the original receiving groups while lowering or redistributing the other groups (PCG64 seed 238531). Of 22 settings, 21 match exactly. The combined result is 179,308/180,224 pixels, maximum 2.50339508e−6. + +The differing weighted setting reduces each group from 8 through 15 to 32 extra copies while retaining the original receiving groups. Its first one-processor capture differs from MaterialCraft at 916/8,192 pixels. Three subsequent one-processor captures in different case orders each match MaterialCraft on all 8,192 pixels. An independent eight-processor capture matches 7,214/8,192, maximum 2.74181366e−6. Two saved signed fields and three saved weighted fields each reproduce their originals in both applications and match 57,344/57,344 pixels across applications. + +Across the whole-root matrix, 16 single-processor differences remain at 128 × 64, seed 191520 and 64 × 128, seed 142326. The eight-processor comparison differs at 705 pixels. The two reference processor settings differ at 707. The new regression failed on the previous renderer. All 443 node and evaluator release tests passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Noise-library Messy Fibers and Microscope View + +All seven roots match 775,424/775,424 pixels apiece in 60 distinct settings on one and eight processors. For each root, 38 MaterialCraft saves reproduce the original in both applications and match 646,656/646,656 pixels across applications. Maximum stored-channel error is zero in each format. Each graph generates its inputs procedurally. + +| Root and comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Messy Fibers 1, Messy Fibers 2, Messy Fibers 3, Microscope View · one or eight processors | 98,304/98,304 · 0 | 335,360/335,360 · 0 | 100,352/100,352 · 0 | 241,408/241,408 · 0 | +| Messy Fibers 1 v2, Messy Fibers 2 v2, Messy Fibers 3 v2 · one or eight processors | 196,608/196,608 · 0 | 237,056/237,056 · 0 | 100,352/100,352 · 0 | 241,408/241,408 · 0 | +| Messy Fibers 1, Messy Fibers 1 v2, Messy Fibers 2, Messy Fibers 2 v2, Messy Fibers 3, Messy Fibers 3 v2, Microscope View · saved files | 95,232/95,232 · 0 | 228,352/228,352 · 0 | 92,672/92,672 · 0 | 230,400/230,400 · 0 | + +The following comparisons replay the same F32 setting in builds immediately before and after the indicated changes. The linked single-stamp measurements and regressions isolate the frequency, interpolation or origin calculation. For the first three roots, the measured frequency is six times the variation plus 1.5 with one F32 rounding. [Original 19 whole-root settings and public controls](#liquid-fiber-and-related-noise-sources) + +| Root | Size | Seed | Earlier exact / total · max | Corrected exact / total · max | Primitive comparison | +|---|---|---:|---:|---:|---| +| Messy Fibers 1 | 16 × 16 | 106907 | 79/256 · 2.98023224e−7 | 256/256 · 0 | [Wave frequency](#wave-frequency-and-phase-in-directional-noise) | +| Messy Fibers 1 v2 | 16 × 16 | 106924 | 97/256 · 2.68220901e−7 | 256/256 · 0 | [Wave frequency](#wave-frequency-and-phase-in-directional-noise) | +| Messy Fibers 2 | 32 × 16 | 106947 | 104/512 · 2.38418579e−7 | 512/512 · 0 | [Wave frequency](#wave-frequency-and-phase-in-directional-noise) | +| Messy Fibers 2 v2 | 32 × 16 | 106964 | 511/512 · 2.98023224e−8 | 512/512 · 0 | [Narrow stamp origin](#starting-coordinates-of-narrow-rotated-stamps) | +| Messy Fibers 3 | 32 × 32 | 113 | 982/1,024 · 3.27825546e−7 | 1,024/1,024 · 0 | [Paired interpolation](#interpolation-across-pairs-of-pixels-in-cells-1) | +| Messy Fibers 3 v2 | 32 × 32 | 113 | 1,023/1,024 · 2.38418579e−7 | 1,024/1,024 · 0 | [Near-vertex origin](#pixel-center-rounding-at-the-near-stamp-vertex) | +| Microscope View | 32 × 32 | 113 | 1,007/1,024 · 4.57838178e−5 | 1,024/1,024 · 0 | [Fractional stamp edges](#fractional-edges-of-axis-aligned-pattern-stamps) | + +Repeat the 19 original settings and the series below. Use the inventory indices 288 through 294 in the table order above. Use seed zero on rows 0 and 5, seed 42 on rows 1 and 8, and 430013 + 13 times the root index + 37 times the row elsewhere. Use U16 and F32 throughout and also U8 and F16 on rows 0, 2, 4, 5 and 8. One 128² default already occurs in the first series. The fresh one-processor renders reproduce 760,064/760,064 archived pixels per root across all 48 distinct settings. + +| Row | Output size | Variation d | Fiber scale | Microscope scale | +|---:|---|---:|---:|---:| +| 0 | 16 × 32 | Defaults | Default | Default | +| 1 | 32 × 16 | .21875 | 2 | 16 | +| 2 | 64 × 64 | .9375 | 1 | 5 | +| 3 | 128 × 32 | .046875 | 3 | 11 | +| 4 | 32 × 128 | .5625 | 2 | 27 | +| 5 | 128 × 128 | Defaults | Default | Default | +| 6 | 256 × 128 | .328125 | 3 | 19 | +| 7 | 128 × 256 | .8125 | 1 | 32 | +| 8 | 256 × 256 | Defaults | Default | Default | +| 9 | 512 × 128 | .671875 | 1 | 12 | + +On changed rows set disorder, angle randomness, color or luminance randomness, disorder speed, anisotropy and warp intensity to d wherever the root exposes that control. Set angle and anisotropy angle to d − .25, lines to 4 + 37d, links to 9 + 22d and tile offset to (d − .34375, .40625 − .875d). Enable non-square expansion on odd rows. + +For each root add the four rows below. Add the root index to the seed column. Use U16 and F32 for each row, adding U8 and F16 on the middle two. For v2 the changed rows also set disorder speed (.625,1.25,.4375), anisotropy (.375,.6875,.1875), anisotropy angle (.1875,−.125,.3125) and offset ((.1875,−.3125),(−.28125,.21875),(.09375,.125)) in row order. Use the root's exposed lines or links control. Color and luminance randomness belong to the third fiber pair. + +| Size | Seed base | Fiber / microscope scale | Disorder | Angle / randomness | Lines / links | Color or luminance randomness | Warp intensity | Non-square expansion | +|---|---:|---|---:|---|---|---:|---:|---| +| 16 × 32 | 242049 | Defaults | Default | Default | Default | Default | Default | Default | +| 32 × 16 | 235111 | 2 / 11 | .3125 | −.09375 / .375 | 9.25 / 12.5 | .25 | .28125 | Off | +| 64 × 32 | 235157 | 3 / 23 | .796875 | .21875 / .6875 | 21.375 / 27.25 | .8125 | .6875 | On | +| 32 × 64 | 235179 | 1 / 9 | .15625 | −.34375 / .15625 | 7.75 / 6.875 | .4375 | .84375 | Off | + +Save every fifth distinct archived setting from the first and each additional setting contributed by the ten-row series. In the four new rows save F32, U8, U16 and F16, and F32 in row order. All 443 node and evaluator release tests passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Hue and chroma rounding near equal RGB channels + +The reference retains a hue difference at equal-channel grays immediately below powers of two when saturation is raised. At hue .5, saturation 1 and lightness .5, render five 256² F32 ramps. For pixel index i from zero to 65,535, subtract i + 1 from the positive F32 bit pattern for .125, .25, .5, .75 or 1, use that value for all RGB channels and set alpha to 1. Use seeds 243109 through 243113. Below .25, .5 and 1 the last visible differences occur 49,151, 24,575 and 12,287 representable values from the center. Each is one representable step inside a distance of 3/4096. The .125 ramp reaches its final odd offset, while the .75 ramp has no visible hue difference. + +At each pixel, choose the first minimum channel in R, G, B order. For a red, green or blue minimum use the channel pair (B,G), (R,B) or (G,R) and a sector of 3, 5 or 1 respectively. Adding 3/4096 to the second channel before subtraction reproduces the measured boundary. Divide that difference by chroma + 1/4096 with the pixel reciprocal, add the sector, convert sixths to turns and apply the slider displacement. For adjusted lightness L the available chroma range is 1 − |2L − 1|. Computing half that range before the multiply-add with saturation preserves the measured endpoints of dark colors. The .125 ramp now matches all 65,536 pixels. + +| Comparison | Settings | Exact before | Exact after | Maximum before U8 / U16 / F16 / F32 | Maximum after U8 / U16 / F16 / F32 | +|---|---:|---:|---:|---|---| +| Palette and coordinate fields | 90 | 35,732/42,240 | 36,841/42,240 | 0 / 1 / 0.000122070312 / 1.54972076e−6 | 0 / 1 / 0.000122070312 / 1.54972076e−6 | +| Independent colors and HDR | 72 | 52,896/79,872 | 55,399/79,872 | 0 / 1 / 0.001953125 / 0.000122368336 | 0 / 1 / 0.001953125 / 1.47819519e−5 | +| 26-step gray hue sweep | 26 | 5,387/13,312 | 5,736/13,312 | — / — / — / 0.000122845173 | — / — / — / 7.15255737e−7 | +| Gray and near-gray slider controls | 8 | 9,370/16,384 | 10,784/16,384 | — / — / — / 0.000122308731 | — / — / — / 4.17232513e−7 | +| Channel offsets near four gray values | 10 | 12,604/20,480 | 16,402/20,480 | 1 / 6 / 0.00048828125 / 0.000122308731 | 0 / 1 / 0.000122070312 / 1.01327896e−6 | +| Five gray ramps | 5 | 227,840/327,680 | 315,380/327,680 | — / — / — / 0.000122070305 | — / — / — / 1.78813934e−7 | +| Three independent six-sector color fields | 3 | 7,270/24,576 | 8,922/24,576 | — / — / — / 1.07288361e−6 | — / — / — / 1.07288361e−6 | +| Four shifted lightness settings | 7 | 10,124/14,336 | 11,645/14,336 | 0 / 3 / 0.000244140625 / 0.000122242374 | 0 / 0 / 0 / 3.57627869e−7 | +| Whole root, one or eight processors | 31 | 148,378/157,952 | 148,752/157,952 | 1 / 1 / 0.000244140625 / 1.07288361e−6 | 1 / 1 / 0.000244140625 / 9.983778e−7 | +| Saved whole root | 9 | 27,297/29,184 | 27,366/29,184 | 0 / 1 / 0 / 6.2584877e−7 | 0 / 1 / 0 / 3.57627869e−7 | + +For the first three rows, repeat the [linear inputs, controller values and seed schedules](#hue-saturation-lightness-and-replace-color). For the gray slider controls use 64 × 32 F32. Each four-row band starts at one of .00390625, .25, .4990234375, .5, .501953125, .75, .875 and 1. Add x − 32 to the input word. Keep RGB equal on the first field. On the second, add one step to channel c when (c+y) modulo 3 is 1 and y modulo 4 is nonzero, or subtract one when (c+y) modulo 3 and y modulo 4 both equal 2. Alpha is 1. Use hue .5, .625, .375 and .75 with saturation 1, lightness .5 and seeds 241183 + 17j. + +For the four-center offset field select .125, .25, .5 or 1 by the 16-pixel column band. Add the cyclic word offsets −8193, −8192, −8191, −4097, −4096, −4095, −2049, −2048, −2047, −11, −7, −5, −3, −2, −1 and 0. Across each 16-row block add the six permutations of (−3,0,2), the three unique permutations of (−1,0,0) and (0,0,1) each in first-appearance order, then (0,0,0), (0,−17,23), (11,−5,−3) and (−19,31,−31). Alpha is ((13x+31y) mod 257)/256. Render (hue,saturation,lightness) at (.5,1,.5), (.59375,.875,.5), (.37109375,.9375,.453125) and (.875,.71875,.625) with seeds 242211 + 37j. Add U8, U16 and F16 on the middle two rows. + +For the six-sector field use 128 × 64 and PCG64 seed 243751. Fill low from [0,.49) and round to F32, set high = 1 − low, then round low + (high − low)u to F32 using the next uniform field u. Permute (low,middle,high) by lexicographic permutation (3x+y) modulo 6. Alpha is ((19x+37y+71) mod 257)/256. Render F32 at (.5,1,.5), (.609375,1,.5) and (.359375,.8125,.5), seeds 243791 through 243793. + +The shifted-lightness field uses 64 × 32 and PCG64 seed 245173. Select a center by (x+3y) modulo 8 from .03125, .0625, .125, .1875, .25, .375, .5 and .75. Subtract a uniform signed 32-bit integer from 1 through 49,152 from its F32 word. When (x+y) modulo 3 is nonzero, add ((x(3+c)+y(7−c)+c) mod 13) − 6 to each channel word. Alpha is ((23x+41y+43) mod 257)/256. Render (.5,1,.5), (.5625,.75,.5625), (.390625,.6875,.46875) and (.78125,.53125,.75) in F32, with seeds 245177 + 19j. Also render the third setting in U8, U16 and F16. Four saved direct graphs reproduce each application's original in all 10 comparisons. Their cross-application score is 17,556/20,480 · 1. + +For the whole root, repeat the original 19 settings, then add 16 × 32, 32 × 16, 64 × 32 and 32 × 64 at seeds 242283, 235553, 235599 and 235621. Render U16 and F32 at each size, adding U8 and F16 on the middle rows. For rows j = 0 and 2 set channel c to ((x(7+2c)+y(19−3c)+5xy+31c+47j) mod 263)/256, using 2.5v − .5 on row 2. For rows 1 and 3 select the F32 word for .125, .25, .5 or 1 by (x+3y) modulo 4 and subtract 1 + ((3x+5y) mod 31). Add or subtract (x+3y) mod 5 where (x+y+c) mod 3 equals zero or one. Alpha is ((11x+17y+3xy+37j) mod 257)/256 throughout. Keep default source and target colors on row 0. On row 1 use the F32 value immediately below .5 in each source channel and target (.125,.75,.5625). Use (.1875,.375,.6875) and (.84375,.21875,.40625) on row 2, then (.375,.5,.625) and (.75,.5625,.25) on row 3. + +All 19 fresh reference captures reproduced the 142,592 archived pixels. The one- and eight-processor reference outputs also matched each other on all 157,952 pixels. Save every fifth archived case starting with the first, then the new F32, U8, U16 and F16, and F32 settings on the four additional rows respectively. All nine saved whole-root cases reproduced their original in each application, totaling 29,184 pixels. Cross-application differences remain. Both new regression tests failed before their respective corrections and passed afterwards. All 445 node and evaluator release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Three consecutive full pairs in the final Dirt Gradient quadrant + +At 128 × 64 and seed 191520 the horizontal Dirt Gradient generator now matches all 8,192 F32 pixels. It previously matched 2,346/8,192 with maximum error 7.4505806e−8. The other 14 isolated F32 settings retain their previous scores. Across the [111 whole-root settings](#individual-tile-copies-after-two-full-horizontal-batches), 109 settings are exact on one processor and 43 on eight. The reference captures for the two processor counts differ at 707 pixels. The 28 saved whole-root settings reproduce their original buffers in both applications. + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| One processor | 600,320/600,320 · 0 | 846,590/846,592 · 1 | 600,320/600,320 · 0 | 816,126/816,128 · 1.74641609e−5 | +| Eight processors | 600,320/600,320 · 0 | 846,262/846,592 · 2 | 600,296/600,320 · 0.00048828125 | 815,779/816,128 · 2.03251839e−5 | +| Reopened, one processor | 36,864/36,864 · 0 | 80,894/80,896 · 1 | 32,768/32,768 · 0 | 279,808/279,808 · 0 | + +The three full pairs start at groups 58, 60 and 62. In each, the first group contains at least 5,460 physical copies. Copies beyond the first two batches of groups 58–59 join group 0 and fill its first batch. Those left by groups 62–63 join group 48 and leave that batch short. In the later submission, add the copies in group 60, the final two depth-four subtrees of group 61 and the middle two of group 16. At 10,920 copies their order changes. The first 32 submitted ranges and final nine ranges are shared across the boundary. The middle ranges differ in where they resume the partially drawn subtree. + +Build the [original square and signed overlap probes](#horizontal-pattern-batches-ending-in-the-preceding-subtree) with horizontal tiling. Start each depth-three group at 32 extra copies, then use the table below. In each group divide the extras evenly among four subtrees, giving the remainder to slots for which (slot + group) modulo 4 is less than the remainder. Within each subtree give the earliest draws the second tile copy. The regression stores measured comparisons between draw indices with reversed gains. The eight signed F32 renders improve from 130,944/131,072 · 2.98023224e−8 to 131,072/131,072 · 0. + +| Group 0 | Group 16 | Group 48 | Groups 58–63 | Later batch relative to capacity | Seed | +|---:|---:|---:|---|---:|---:| +| 83 | 79 | 49 | 85, 84, 84, 86, 84, 87 | -1 | 246191 | +| 83 | 74 | 61 | 90, 81, 88, 87, 87, 85 | +0 | 246220 | +| 86 | 67 | 60 | 94, 79, 94, 83, 93, 81 | +1 | 246249 | +| 81 | 75 | 46 | 99, 83, 102, 80, 96, 87 | +12 | 246278 | + +A separate forward and reverse comparison ordered 208 parent markers on each of four fields. Markers around parent 641 change order when the later batch fills. Two complete scans started with both ends of each 64-parent subtree, then bisected gaps across which the measured rank changed. Auditing single-copy children after the parent scan placed 39 displaced children in the redistributed field and 23 in a second field. Each reconstructed order matched its independent 8,192-pixel weighted output. + +For 56 independent 128 × 64 fields use PCG64 seed 245317. In each row j draw 64 group quotas from integers [24,83). Let E = (0,1,3,9,15,23,35). For first groups 58, 60 and 62 take (84,85,91,103)[j mod 4], (84,85,96,109)[floor(j/2) mod 4] and (84,85,94,101)[floor(j/3) mod 4]. Set the three pair sums to 168 + E at indices j, floor(j/2)+2 and floor(j/5)+1 modulo 7. Set group 0 to 84 minus the first pair's excess plus (0,1,6,15)[j mod 4]. Set group 48 to 84 minus the last pair's excess minus (1,2,7,22)[j mod 4]. Split each quota with four equal multinomial probabilities, then replace the distribution by the even split above where j modulo 4 is 1. From j = 28 onward adjust subtree 65 to make the later batch fall (−2,−1,0,1,2,9,15)[j mod 7] copies from capacity. If the quota would go below zero, take its deficit from subtree 66, then 247. Use seed 245343 + 23j for the [weighted square field](#paired-subtree-capacity-in-horizontally-tiled-dirt-gradient). + +The 22 variations of the original quotas match 180,224/180,224 · 0. Eight independent cases from the earlier split-field series match 65,536/65,536 · 0. The 56 new fields match 457,004/458,752 · 1.90734863e−6 on their first reference capture. At rows 6 and 15 three fresh single-processor captures each match all 8,192 pixels. Together the two eight-processor repeats match 14,444/16,384 · 2.62260437e−6. Six further MaterialCraft saves of signed and weighted fields reproduce all six local originals. Their first cross-application comparison matches 72,783/73,728 · 1.90734863e−6. All six subsequent single-processor readbacks of the original and saved row 29 match the original buffer, 49,152/49,152 pixels, maximum zero. + +Remaining single-processor root differences are n1u16 (2 pixels), n1f32 (2 pixels). At 64 × 128, seed 142326, the isolated horizontal source still matches 2,713/8,192 F32 pixels, maximum 5.96046448e−8. The new signed regression failed before the correction. All 446 node and evaluator release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Final-pair and middle-batch copies in Dirt Gradient + +Dirt Gradient matches all **143 whole-graph settings on one processor**, including the four formats at 64 × 128, seed 254181. All **40 saved settings** reopen with identical pixels in both applications. On eight processors, 50/143 settings and 3,272,132/3,272,960 pixels match. Comparing the reference application's own one- and eight-processor captures gives the same per-setting counts and maxima. [Whole-graph settings, seeds, output formats and save order](#ten-batches-in-the-horizontal-dirt-gradient-source) + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| 143 whole settings, one processor | 657,664/657,664 · 0 | 994,048/994,048 · 0 | 657,664/657,664 · 0 | 963,584/963,584 · 0 | +| 143 whole settings, eight processors | 657,664/657,664 · 0 | 993,657/994,048 · 2 | 657,639/657,664 · 0.00048828125 | 963,172/963,584 · 2.03251839e-05 | +| Reference one versus eight processors | 657,664/657,664 · 0 | 993,657/994,048 · 2 | 657,639/657,664 · 0.00048828125 | 963,172/963,584 · 2.03251839e-05 | +| 40 reopens across applications, one processor | 36,864/36,864 · 0 | 130,048/130,048 · 0 | 73,728/73,728 · 0 | 337,152/337,152 · 0 | + +Isolate the depth-nine horizontal additive pattern at 64 × 128, seed 254181. Number its depth-four subtrees in traversal order, with four subtrees per group. Groups 24–31 fill eight batches of 5,460 copies. Groups 62–63 exceed two batches by 12 copies. Those 12 lead group 48. Whenever the middle groups have a remainder, it leads group 52. Group 60 and the first and last subtrees of group 61 share a two-batch stream with the middle subtrees of group 16. Count even those wrapped copies that miss all pixels. The isolated output improves from 2,495/8,192 (maximum 8.94069672e−8) to **8,192/8,192 F32 pixels** (zero). + +For the [signed square probe](#three-consecutive-full-pairs-in-the-final-dirt-gradient-quadrant), set every group to 61 extra copies and groups 24–31 to 84, then apply the table. Distribute the extras among the four subtrees as in the [normal-cook regression](../crates/nodes/src/pattern/tests/paired_batches.rs). At 128² exchange the negative and positive gains. Across eight buffers the check improves from 130,944/131,072 (maximum 2.98023224e-08) to 131,072/131,072 (zero). + +| Group 16 | 31 | 48 | 49 | 52 | 60 | 62 | 63 | Seed | +|---:|---:|---:|---:|---:|---:|---:|---:|---:| +| 134 | 84 | 84 | 85 | 83 | 70 | 58 | 110 | 269119 | +| 114 | 85 | 86 | 83 | 80 | 81 | 83 | 86 | 269156 | +| 118 | 87 | 79 | 90 | 75 | 82 | 84 | 96 | 269193 | +| 131 | 100 | 70 | 99 | 58 | 83 | 101 | 93 | 269230 | + +At 128 × 64, use the same four rows of quotas with the [weighted square field](#paired-subtree-capacity-in-horizontally-tiled-dirt-gradient). For row j starting at zero, use seeds 273097 + 31j and 273600 + 31j. Save and reopen the first seed in each row. Across eight originals, 65,536/65,536 F32 pixels match, maximum 0. The four cross-application reopens match 32,768/32,768, maximum 0. All four local buffers repeat their whole originals. + +A further 16 weighted fields derived from the stage's copy counts match 131,072/131,072, maximum 0. Ten independently distributed quota fields match 79,251/81,920, maximum 2.50339508e-06. Three fields account for that difference. Recapture those three and two exact controls on the same single processor. The successive five-buffer results are 40,070/40,960 (maximum 1.78813934e-06), 40,960/40,960 (zero), and 40,960/40,960 (zero). The inventory retains the eight-processor whole-graph differences. All 451 node and evaluator release tests, formatting, strict workspace Clippy, crate layers and WebAssembly passed. + +### Ten batches in the horizontal Dirt Gradient source + +On one processor all **127 earlier whole settings match pixel for pixel**, including the six previously differing values at 64 × 128, seed 254179. Their isolated horizontal pattern improves from 3,314/8,192 F32 pixels (maximum 5.96046448e−8) to 8,192/8,192 (zero). All 34 earlier saved settings also match in both applications. A further 16 whole settings extend the comparison to **139/143 settings and 3,272,949/3,272,960 pixels**. The four differing settings share seed 254181. [Earlier settings and saved results](#eight-middle-batches-in-the-horizontal-dirt-gradient-source) + +| Whole-output comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Earlier 127, one processor | 616,704/616,704 · 0 | 895,744/895,744 · 0 | 616,704/616,704 · 0 | 865,280/865,280 · 0 | +| Earlier 127, eight processors | 616,704/616,704 · 0 | 895,391/895,744 · 2 | 616,679/616,704 · 0.00048828125 | 864,910/865,280 · 2.03251839e-05 | +| Earlier 34 reopens, one processor | 36,864/36,864 · 0 | 105,472/105,472 · 0 | 40,960/40,960 · 0 | 296,192/296,192 · 0 | +| New 16, one processor | 40,959/40,960 · 1 | 98,300/98,304 · 1 | 40,959/40,960 · 0.000244140625 | 98,299/98,304 · 1.64806843e-05 | +| New 16, eight processors | 40,959/40,960 · 1 | 98,268/98,304 · 2 | 40,959/40,960 · 0.000244140625 | 98,265/98,304 · 2.02655792e-05 | +| New 16, reference one versus eight | 40,960/40,960 · 0 | 98,266/98,304 · 2 | 40,960/40,960 · 0 | 98,262/98,304 · 2.02655792e-05 | +| New six reopens, one processor | — | 24,572/24,576 · 1 | 32,768/32,768 · 0 | 40,960/40,960 · 0 | +| New six, reference original versus reopened | — | 24,576/24,576 · 0 | 32,768/32,768 · 0 | 40,960/40,960 · 0 | + +For the 16 new settings leave the controls at their defaults. Use 64 × 128 at seeds 254177 and 254181, 128 × 64 at 191523 and 142329, 128 × 256 at 263113 and 256 × 128 at 263147. Use U16 then F32 everywhere, with U8, U16, F16 and F32 in that order for the second and fifth seeds. Save in MaterialCraft and reopen zero-based settings 0, 3, 6, 9, 12 and 15 in each application. All 40 local saved outputs retain their original pixels. + +In a horizontal depth-nine tree, number the 256 depth-four subtrees in traversal order. Each contains 1,344 draws before wrapping. Each group contains four such subtrees. The measured split occurs with short final pairs, a short group 60, a short eight-group stream at groups 24–31, and room left after combining group 60 with the first and last subtrees of group 61 and the two middle subtrees of group 16. Count the copies in subtree 0, subtrees 3–31, the second subtrees of groups 52 and 56, and groups 58–59. At 54,600 copies these portions fill ten batches. Surplus copies split the second subtree of group 56. Its remainder draws later. The first nine-batch cut can fall on either side of the start of subtree 30. Both cuts use physical copies, including copies of a square that misses all sampled pixels. + +Use the [signed overlapping-square procedure](#three-consecutive-full-pairs-in-the-final-dirt-gradient-quadrant) at 128², seed and quotas below. Start every group with 61 extra copies, set groups 58 and 59 to 80 and 70, then apply the table. Split each group evenly among its four subtrees, rotating the remainder by group index. The committed regression contains six independently measured pairs per qualifying field. In the full 16-pair comparison with gains exchanged, the last four fields improve from 130,944/131,072 (maximum 2.98023224e-08) to 131,072/131,072 (zero). The one-copy-short control gives 32,736/32,768 (maximum 2.98023224e−8) before and after. [Regression and field construction](../crates/nodes/src/pattern/tests/paired_batches.rs) + +| Group 0 | Each of 1–7 | Group 52 | Group 54 | Group 56 | Group 60 | Group 62 | Copies above ten batches | Seed | +|---:|---:|---:|---:|---:|---:|---:|---:|---:| +| 113 | 86 | 53 | 78 | 66 | 70 | 75 | -1 | 261053 | +| 120 | 86 | 55 | 84 | 54 | 72 | 78 | 0 | 261084 | +| 109 | 86 | 62 | 89 | 73 | 79 | 62 | 1 | 261115 | +| 121 | 86 | 76 | 82 | 62 | 82 | 81 | 8 | 261146 | +| 121 | 89 | 58 | 93 | 77 | 77 | 64 | 28 | 261177 | + +Independent weighted fields use the [128 × 64 square-field construction](#paired-subtree-capacity-in-horizontally-tiled-dirt-gradient). Start with the 256 per-subtree extra-copy counts from the horizontal stage at seed 254179. Use the original counts for row 0. In rows 1–61, split the 64 group totals with independent four-way equal-probability multinomial draws using PCG64 seed 258137. For rows 2–9 add (−18,−6,−2,−1,0,1,2,4) to group 54. In rows 10–17 adjust group 7 so that groups 0–7 sum to 672+(−32,−8,−2,−1,0,1,2,12). In rows 18–25 adjust group 31 so that groups 24–31 sum to 672+(−20,−6,−2,−1,0,1,2,8). In rows 26–33 set group 60 to (72,80,82,83,84,85,86,95) and cap group 61 at 167 minus group 60. In rows 34–41 use (53,74,82,83,84,85,91,110) for group 0. For the final 20 rows perturb each group by an integer from [−8,8], cap every odd member of the final eight pairs at 167 minus its neighbor, then set group 54 to (81,83,84,85,87)[row mod 5] and cap group 55 again. Paint the field with seed 258047+31 × row. The 38 qualifying fields match **311,296/311,296** F32 pixels (zero). All 62 together give 498,226/507,904 (maximum 5.48362732e-06). + +At seed 254181 the local horizontal stage matches 2,495/8,192 F32 pixels (maximum 8.94069672e−8). Three one-processor captures agree pixel for pixel. Comparing the one- and eight-processor captures gives 2,444/8,192 (maximum 8.94069672e−8). Groups 24–31 fill eight batches and groups 62–63 exceed two batches by 12 copies in this setting. The inventory retains this root in progress. + +### Eight middle batches in the horizontal Dirt Gradient source + +Dirt Gradient matches all **2,863,360 pixels across the earlier 111 settings** on one reference processor, including all 28 saved settings. At 64 × 128, seed 142326, the horizontal pattern source improves from 2,713/8,192 F32 pixels (maximum 5.96046448e−8) to 8,192/8,192 (maximum zero). All 14 other isolated settings retain their scores. All 707 differing pixels in the eight-processor comparison also differ between the two reference captures, with identical counts and maximum error in every setting. [Earlier whole-root settings](#individual-tile-copies-after-two-full-horizontal-batches) + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Earlier 111, one processor | 600,320/600,320 · 0 | 846,592/846,592 · 0 | 600,320/600,320 · 0 | 816,128/816,128 · 0 | +| Earlier 111, eight processors | 600,320/600,320 · 0 | 846,260/846,592 · 2 | 600,296/600,320 · 0.00048828125 | 815,777/816,128 · 2.03251839e−5 | +| Earlier 28 reopens, one processor | 36,864/36,864 · 0 | 80,896/80,896 · 0 | 32,768/32,768 · 0 | 279,808/279,808 · 0 | +| New 16, one processor | 16,384/16,384 · 0 | 49,149/49,152 · 1 | 16,384/16,384 · 0 | 49,149/49,152 · 1.69277191e−5 | +| New 16, eight processors | 16,384/16,384 · 0 | 49,130/49,152 · 2 | 16,383/16,384 · 0.000244140625 | 49,134/49,152 · 1.88946724e−5 | +| New six reopens, one processor | — | 24,576/24,576 · 0 | 8,192/8,192 · 0 | 16,384/16,384 · 0 | + +For the new 16 settings leave the graph controls at their defaults. Use 64 × 128 at seeds 142325 and 142327, 128 × 64 at 191519 and 191521, 64 × 128 at 254179, and 128 × 64 at 254183. Use U16 and F32 everywhere and add U8 and F16 at seeds 142327 and 254179. Save in MaterialCraft and reopen settings 0, 3, 6, 9, 12 and 15 in both applications, numbering from zero in the order given and using U8, U16, F16, F32 within a size. Both applications reproduce their own six original buffers. At seed 254179 three U16 pixels still differ by one code and three F32 pixels differ by up to 1.69277191e−5. The 16 settings have identical MaterialCraft pixels before and after this fix. Across all 127 settings, 125 are exact on one processor. + +The full pair at groups 54–55 passes its extra copies to group 32, leaving that receiving batch short. Group 60 fills exactly one 5,460-copy batch. Groups 24–31 fill at least eight batches. Their excess plus group 52 leaves the next batch short. Group 62 fills a batch while groups 50 and 58 fall short. In the next quadrant, add the pair’s extra copies to depth-four subtrees 128–132 and 135–159 inclusive. The remainder after dividing by 5,460 gives the number of copies from the split to the end of group 39. When that remainder plus subtrees 1 and 2 reaches 5,460, two runs move relative to the next partial subtree. The physical copy counts locate both interior cuts. + +For four independent signed fields set all 64 group quotas to 32 extra copies. Give groups 24–30 a quota of 84, groups 60 and 61 quotas of 84 and 57, and use the other values below. Use the [even split and signed overlap procedure](#three-consecutive-full-pairs-in-the-final-dirt-gradient-quadrant). Sixteen draw pairs per field, each with both gain assignments, give 128 observed order comparisons. Eight F32 buffers improve from 130,944/131,072 · 2.98023224e−8 to 131,072/131,072 · 0. The new regression failed before the correction. + +| Group 0 | Group 31 | Group 32 | Each of 33–39 | Group 52 | Groups 54, 55 | Group 62 | Later batch relative to capacity | Seed | +|---:|---:|---:|---:|---:|---|---:|---:|---:| +| 107 | 84 | 83 | 82 | 83 | 79, 89 | 84 | -1 | 249179 | +| 111 | 89 | 79 | 82 | 77 | 84, 87 | 86 | +0 | 249210 | +| 111 | 98 | 64 | 83 | 63 | 91, 90 | 92 | +1 | 249241 | +| 107 | 118 | 52 | 85 | 39 | 99, 90 | 101 | +8 | 249272 | + +For an independent weighted series, use the [original 128 × 64 weighted square field](#paired-subtree-capacity-in-horizontally-tiled-dirt-gradient). Generate 56 rows j with PCG64 seed 248367. Draw 64 integer group quotas from [24,83). Let E=(0,1,4,12,23,35,53)[j mod 7]. Draw group 54 from [73,105) and set group 55 to 168+E minus group 54. Set group 32 to max(1,84−E−(1,2,7,14)[j mod 4]). Use 84 in group 60, (34,64,80,83)[j mod 4] in group 61 and (84,85,89,106)[floor(j/3) mod 4] in group 62. Limit group 63 to 167 minus group 62. Draw groups 24–30 from [73,98). Set group 31 so that the sum in groups 24–31 is 672+(0,1,5,14,34,67,−1)[floor(j/2) mod 7]. For even j, start groups 33–39 at 71, 85, 95, 72, 98, 92, 85 and add independent integers from [−8,9). Use equal-probability four-way multinomial splits. After those draws, replace every third row starting at row 0 with the even split above. From row 21 onward adjust randomly selected subtrees 136–159 by one copy, keeping quotas in [0,160], until the later batch falls (−8,−2,−1,0,1,2,8)[j mod 7] copies from capacity. Seed the weighted image with 248431+23j. + +The 11 earlier split fields within those conditions match 90,112/90,112 · 0. The 33 qualifying new fields match 269,363/270,336 · 2.02655792e−6. Row 5 differs at 973 pixels in its first reference capture. Three additional one-processor captures each match every pixel in rows 5 and 7, or 49,152/49,152 in total. The same two fields on eight processors match 14,451/16,384 · 2.38418579e−6. Row 8 crosses the group-52 boundary and still differs on each one-processor repeat (7,222/8,192 exact, maximum 2.74181366e−6). After saving three signed fields and weighted rows 5, 30 and 31 in MaterialCraft, both applications agree on 73,728/73,728 · 0. MaterialCraft reproduces each original. The first reference original of row 5 differs from its first saved capture at 973 pixels. Three further reference readbacks of each file all reproduce the first saved buffer, 49,152/49,152 pixels, maximum zero. + +In the six additional whole-root settings rendered separately at F32, four isolated horizontal generators are exact. Seed 191519 matches 2,875/8,192 source pixels, maximum 8.94069672e−8, even though the whole-root output is exact. Seed 254179 matches 3,314/8,192 source pixels, maximum 5.96046448e−8. Two further single-processor captures at seed 254179 reproduce all 8,192 reference pixels each. All 447 node and evaluator release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +## 2026-11-21 root comparisons + +### Connected quadrant depth and amplified spot patterns + +In the two BNW Spots 1 generators, disabling a deep branch changed the brightness of the root square. On the first root at 32², scale 2, roughness .6, disorder .37 and seed 113, the ratio between the original implementation and the reference matched the difference between ten and eleven octave weights. Counting connected quadrant subdivisions through switches and iterators fixed the brightness. The traversal still uses the visited drawing depth to order stamps. + +An original F32 control draws one white square at the root, with empty quadrants below it. Insert a switch before depth 1 in chains of depths 2 and 3, or before depth 1 or 3 in a depth-5 chain. Exercise both branches with an empty arm and with a short arm. Disconnect the depth-5 chain for a separate control. Replace the switch with a zero- or one-count iterator at depths 1 and 3. Use gain 1, roughness .375, .6, 1 or 1.25, at 16². For unit roughness the root reads 1/3, 1/4 and 1/6 at depths 2, 3 and 5 even with the deep arm inactive. Disconnecting that arm gives 1. Across 68 settings **17,408/17,408** raw F32 pixels match, maximum error zero. Before the fix 8,192 matched and the maximum error was .355624951. + +The renderer also checks the computed octave weights when culling tiny stamps. An original square 1/256 of the image width and height exercised gains .5, 1.5, 2, 3.25, −.75 and 1.875, with repeat counts 19, 211, 12003, 3, 1 and 5 respectively. The first three are centered. The next two add frame offset (1/64,1/32), and the last adds (−1/128,−1/64). Use seed `458527 + 31j + width` with one-based series index `j`. Compare 16², 32 × 16, 16 × 32, 64 × 32 and 32 × 64 in U16 and F32, with U8 and F16 at 16² and 64 × 32. Including the separate 16² F32 gain-1.5 single-stamp control, **92,416/92,416** pixels match in 85 renders, maximum error zero. The release regression also draws a visible background before 1,048,580 missed stamps at gain 2. The earlier renderer exhausted its visit budget. + +The root table counts one original per distinct setting and excludes cook errors. The first version includes the depth and culling fixes. The second version records the complete depth-only comparison. The four 64² precision controls and the changed 32² F32 control were also repeated with culling active in v2 and kept the same counts. In the earlier common sets the depth change improved 135,406 to 639,048 exact pixels out of 792,576 in the first version and 306,072 to 752,311 out of 760,832 in v2. + +| Root | Distinct comparable settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| BNW Spots 1 (236) | 60 | 103,167/103,168 · 1 | 311,103/311,552 · 1 | 103,161/103,168 · 0.00048828125 | 125,170/278,784 · 1.90734863e-06 | +| BNW Spots 1 v2 (237) | 55 | 134,912/134,912 · 0 | 261,354/261,376 · 1 | 102,142/102,144 · 0.00048828125 | 253,903/262,400 · 1.1920929e-07 | + +The 26-setting series uses (width, height, scale, disorder, roughness) of (16,32,1,0,1), (32,16,2,.28125,.375), (32,32,2,.37,.6), (64,32,1,.140625,.75), (32,64,2,.84375,1), (64,64,1,.40625,0), (128,64,2,.953125,.96875), (64,128,1,.734375,.5625) and 128² defaults. In v2 set disorder speed to .875 times disorder, anisotropy to half the disorder, its angle to disorder minus .375 and tile offset to (.25d,−.125d) at changed settings. Use seeds zero at indices 0 and 8, 113 at index 2 and `456623 + 31j` elsewhere. Compare U16 and F32 everywhere and U8 and F16 at 0, 2, 4 and 8. At zero roughness the opacity function returned a non-finite value in both U16 and F32. Those two settings per root yielded no local image at this revision. + +The 30-setting series uses sizes 16², 64 × 16, 16 × 64, 64², 128 × 64, 64 × 128, 128², 256², 128 × 512 and 512 × 128. Use defaults and seed zero at indices 0 and 7. At the other eight set scale to 2, 1, 3, 2, 1, 3, 2 and 1 respectively. For disorder and roughness use .03125, .875, .34375, .96875, .1875, .65625, .53125 and .09375 in that order. In both versions enable non-square expansion on odd changed indices. In v2 set speed and anisotropy to the same value, angle to `d − .25`, offset to `(d − .34375,.40625 − .875d)`. Use seed 42 at index 1, otherwise `409729 + 7i + 61j` for inventory index `i`. Compare U16 and F32 throughout, plus U8 and F16 at indices 0, 1, 3, 5 and 7. All 30 first-version cases now cook. Its 64 × 16 F32 case moved from a visit-budget error to 483/1,024 exact, maximum 1.1920929e−7. On the depth-only v2 comparison the four 64 × 16 settings and two 128² scale-3 settings exceeded the visit budget. + +Both applications reopened the saved files for both series. MaterialCraft reproduced its own pixels on every completed local comparison. The reference original and reopen agreed on 115,728/125,952 and 592,313/629,760 pixels in the first version's 26- and 30-setting series, and 123,392/125,952 and 622,661/629,760 in v2. The first version also produced different exact counts on three same-setting reference captures, including 480 versus 478 out of 1,024 F32 pixels at seed 113. The comparisons retain those residuals. All 325 core and node release tests, strict workspace Clippy, formatting, dependency layers and WebAssembly checks passed. + +### Grayscale pattern output at zero roughness + +At scale 1, disorder .40625, roughness zero and seed 456778, both BNW Spots 1 roots returned a scalar infinity from their opacity expression. The generic parameter evaluator rejected it before drawing. The grayscale pattern evaluator now passes the scalar to the blend, including its sign, and preserves the distinction between positive infinity, negative infinity and an undefined result in the cook cache. A stamp stores the observed finite endpoint or NaN bit pattern after blending. Untouched pixels retain the background. + +| 64² root and settings | U16 exact / total | F32 exact / total | Maximum error in both formats | +|---|---:|---:|---:| +| BNW Spots 1 (236) | 4,096/4,096 | 4,096/4,096 | 0 | +| BNW Spots 1 v2 (237) | 4,096/4,096 | 4,096/4,096 | 0 | + +Use the zero-roughness setting in the preceding 26-setting series, including its v2 speed, anisotropy, angle and offset. Before this fix neither format yielded a local image. Each application also reopened the MaterialCraft saves. The four saved outputs matched all 16,384 pixels across applications, maximum zero. The first root's F32 pixels all contain the largest finite F32 value. The second root also contains background-valued pixels. + +The independent one-stamp control divides two scalar graph inputs to drive the global opacity with roughness zero. Use numerators and denominators (1,1), (1,0), (−1,0), (0,0), (.25,1), (−.25,1), (1,4) and (−1,−0). Alternate 32 × 16 and 32². The seven configurations use a half-width square at default, .25 and zero tint, a full-width square at −.25 tint and a full-width linear ramp at .25 tint, in maximum mode, plus a half-width .25 square in modes 0 and 2. Use seed `459223 + 17j + h` for one-based configuration index `j` and zero-based setting `h`. Compare U8, U16, F16 and F32, plus four F32 pilot renders of the default square. All **175,104/175,104** pixels match in 228 renders, maximum zero. An additive positive or negative infinity stores the corresponding signed finite limit. An undefined additive result stores F32 bits `0x7fffffff` and F16 bits `0x7fff`. The maximum blend retains its finite black background against an undefined contribution. + +Separate pairs of overlapping stamps revealed a remaining difference. Draw a negative .25 root square in maximum mode above a positive .25 additive child on black. In the 32 × 16 F32 probe at finite gain −1, MaterialCraft matched 224/512 pixels. The other 288 differed by .25. The same geometry also differs with negative infinite gain. Four RGBA controls with undefined gain still report a local cook error. These results and the finite-roughness differences in the preceding root comparison keep both roots in progress. All 373 evaluation and node release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly checks passed. + +### Direction and sample coordinates of long oblique blurs + +Across the 78 original settings in [the rectangular blur comparison](#oblique-directional-blur-on-rectangular-images), the number of differing color pixels fell from 1,258 to 646 and the number of differing grayscale pixels fell from 438 to 130. Each application reproduced its own original on all 3,489,792 pixels in 60 saved settings per root, maximum error zero. Both roots remain in progress. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Blur HQ (55) | 78 | 706,504/706,560 · 1 | 1,169,141/1,169,408 · 257 | 591,816/591,872 · 0.00439453125 | 1,192,949/1,193,216 · 0.0039215982 | +| Blur HQ Grayscale (56) | 78 | 706,545/706,560 · 1 | 1,169,358/1,169,408 · 257 | 591,857/591,872 · 0.00390625 | 1,193,166/1,193,216 · 0.0039215982 | + +A single white stripe isolates the projected width. Draw a line through the middle column or row of a black 16-bit input, perpendicular to the filtering axis. Use both 128 × 16 and 16 × 128 orientations for turns .03125, .0625, .1, .125, .1875, .2421875, .265625, .3125, .375, .4375, .5625, −.0625, −.125, −.1875, −.271484375, .0791015625, .1201171875, .2099609375, .337890625, .4033203125, −.3583984375 and .53125. Use radii 2.18064117, 2.623046875, 2.91796875, 3.17349243, 3.734375, 4.18359375, 4.97953796, 5.2578125, 5.84778023, 6.8125, 7.14850616, 7.5703125, 8.96439362, 9.298828125, 10.65226746, 12.376953125, 13.50491333 and 14.31640625 texels. Multiply by 256 divided by the shorter side for the intensity. Seed is `455833 + 17j + h` for zero-based orientation and radius indices. Across 792 RGBA F32 images, **1,577,984/1,622,016** pixels match, maximum 2.38418579e−7. The same test with four additional turns (37, −119, 303 and −431 divided by 1024) matches all **294,912/294,912** pixels, maximum zero. + +The center weight distinguishes the stored single-precision direction from an unrounded sine and cosine. The measured approximation folds a positive radian phase into the central half turn, evaluates the odd sine series through degree eleven in single precision and uses a quarter-turn shift for cosine. The ratio of the two stored components gives the shear. An off-center impulse distinguishes adding the two matrix terms before subtracting the center translation. At 512 × 256, intensity 7.8787503, 1/16 turn and white at (11,254), the three red-channel F32 words at (10,253) through (10,255) are `3d0c9a80`, `3ce757e2` and `3bbcf1c9`. + +The single-impulse control uses (width, height, turn, radius in texels) of (512,256,.0625,7.8787503), (256,512,.0625,7.8787503), (512,128,.4375,7.0537505), (128,512,.4375,7.0537505) and (256,256,−.0849609375,6.71875). Each has six white-pixel locations at (⌊w/2⌋+5,⌊h/3⌋−1), (⌊w/5⌋+1,⌊h/2⌋+7), (w−3,7), (11,h−2), (⌊w/3⌋+11,⌊h/5⌋+2) and (1,1). Use seed `462021 + 23j + h` for zero-based series and position indices. All **2,752,512/2,752,512** RGBA F32 pixels match across 30 renders, maximum zero. + +The sparse fields use the same tuples with (256,128,.1875,4.8675003) inserted before the last tuple. In filtering-axis coordinates, start the white columns at 3, 10, 16, 23, 25 or 30 and repeat every 32 texels. In zero-based column `i` place a point every 16 rows starting at `(3i + 5h) mod 16` for zero-based field `h`. Use seed `460039 + 17j + h`. F32 matches **2,948,850/2,949,120** pixels in 36 settings, maximum .000616334379, up from 2,555,364 exact. U8 matches **983,040/983,040** in the 12 settings using fields 1 and 4, maximum zero. + +The independent 312-case primitive series from the preceding comparison has the following raw pixel counts. + +| Storage | Exact pixels before | Exact pixels after | Pixels compared | Maximum after | +|---|---:|---:|---:|---:| +| U8 | 344,024 | 344,030 | 344,064 | 1 | +| U16 | 342,166 | 342,561 | 344,064 | 63 | +| F16 | 319,077 | 343,693 | 344,064 | .0009765625 | +| F32 | 1,545,530 | 1,864,772 | 1,949,696 | .000969707966 | + +Both release regressions failed before the fix and passed afterward. All 320 node release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly checks passed. + +### Package ownership of saved function calls + +A saved same-package function call now includes the UID of the package’s own `?himself` dependency. A bare function path could bind to another open package with the same folder and function name. Older files with either representation still open. + +For an independent reproduction, make two files, each with a grayscale Pixel Processor that calls a local function named `Controls/SharedLevel`. Return .125 in the first file and .875 in the second. Open both files in that order. Compare U8 at 16²/seed 0, U16 at 32 × 16/71, F16 at 16 × 32/903 and F32 at 32²/1911. Both original files gave their own constant. With the earlier writer, the first save matched all 2,304 pixels. The second save reopened with the first file’s value in the reference app. It matched 0/256 U8, 0/512 U16, 0/512 F16 and 0/1,024 F32 pixels. Maximum errors were 191 and 49,151 integer levels and .75 in each floating format. The corrected saves matched **4,608/4,608** pixels across both applications, maximum zero. + +The same test in the 3D Voronoi graph replaced the local distance function’s return value with .375. Use a 16² F32 output at seed 37 with defaults, random-color style and the same style with a constant black position field. The first two use position field 7 below. In the previously unqualified file none of the 768 pixels agreed, maximum .6220703125. Reopening the ordinary MaterialCraft save restored **768/768**, maximum zero. Replacing the entire Pixel Processor output with .625 also agreed on all 768 pixels. + +For the four [Voronoi roots](#voronoi-distortion-and-shared-noise-inputs), supply the same original 1024 × 16 U16 table to each application. In one table, shuffle rows of the integers 0 through 1023 consecutively with the Python Mersenne Twister seeded 104729. In the other, use `((53+2y)x + 137y + 29) mod 1024`. Round each table entry times 65535/1023 to the nearest even integer. Save the linked 3D noise package and the parent through MaterialCraft, keep the resource and dependency paths valid, then save the parent a second time. On all four roots, for each table, the reference app reproduced **81,920/81,920** pixels in 36 settings after each save, maximum zero. The two saves also agreed bit for bit. Changing just the two version fields in the linked source did not restore its distorted output. An additional save with qualified function calls reproduced **28,672/28,672** reference pixels in 12 settings for each root and table, maximum zero. These within-application comparisons test the file handoff. + +The 36 settings use sizes 16², 32 × 16, 16 × 32, 32², 64 × 16, 16 × 64, 64 × 32, 32 × 64, 64², 128 × 32, 32 × 128 and 128 × 64, indexed by `j` starting at zero. For 3D roots after index zero, the U16 position channels are `(⌊65535x/(w−1)⌋ + 1597j) mod 65536`, `(⌊65535y/(h−1)⌋ + 977j) mod 65536`, `(233x + 641y + 47xy + 3079(x mod 5) + 11j) mod 65536` and 65535. At 0 and 8 use defaults and seed zero. Use seed 42 at 1 and `457043 + 19j` elsewhere. Use U16 and F32 throughout, plus U8 and F16 at 0, 2, 4, 7, 8 and 10. + +In index order set scale to (8,3,7,2,5,11,9,4,8,13,6,15) and `d` to (0,.15625,.6875,.96875,.4375,0,.28125,.8125,.5625,.171875,.9375,.3125) at changed settings. Use distance mode `j mod 4`, style `(j−1) mod 7`, edge thickness `.03125+.15625d`, Minkowski number `1.25+1.5d`, random-color seed mode `j mod 2` and seed `211j`. Invert when `j mod 3 = 1`. Set offset to `(.1875d,−.375d,.625d)`, size to `(.75+d,1.25−.25d,1.5−.375d)`, distance scale to `.75+.5d`, distortion multiplier to `1+.5d`, intensity to `.1875d` and rounded curve to `.25d`. The 3D variants use disorder `d` and tiling on odd indices. The 2D variants use `(d,.625d,1−.375d)` and non-square expansion on odd indices. Fractal variants use levels `j mod 2` through `2+j mod 3`, opacity `.5+.625d`, roughness `.25+.5d`, lacunarity `1.5+.75d` and blend mode `j mod 3`. + +For the 3D Voronoi cross-application comparison, also repeat indices 1, 2, 3, 4 and 6 with F32 and zero distortion. Across both tables and 82 original settings, U8 matches **20,028/24,064** (maximum 162), U16 **53,820/57,856** (41,505), F16 **20,028/24,064** (.633056641) and F32 **64,060/68,096** (.633334696). In the shuffled-table random-color case at 32 × 64, 32/2,048 pixels agree in each format. The four roots remain in progress. The writer regression failed on the earlier exporter. All 125 format release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly checks passed. + +### Shared pixel assignments in Voronoi color selection + +In a pixel function, both arms of a conditional can use the same assignment, a sequence containing it, or a called function that exports it. MaterialCraft now evaluates that shared expression after the condition and before the selected arm. Uses in two alternatives inside a single arm stay inside that arm. A loop evaluates its own assignments on each iteration. + +For a minimal reproduction, initialize a scalar to .40625. Define one shared expression that stores the horizontal pixel coordinate in the scalar and reads it back. For selector values below .5 return that expression plus 1. For values below 1.5 return half the same expression. Otherwise read the scalar. At the first pixel center of a 16² image the last alternative previously returned .40625. Both applications now return .03125. When the first two alternatives are siblings inside one arm of an outer conditional, the other arm returns .40625. + +Fourteen original graphs used a single assignment, a sequence or a called function, a shared or independent expression in sibling or nested alternatives, and a final read after the conditional. Use selectors 0, 1, 2 and 7 at 16² F32 with seeds 0, 43, 373 and 1921. For spatial conditions substitute three times the vertical pixel coordinate. Seven additional graphs tested an operand outside the branch on either side of an addition, a following sequence, an inner conditional, two ordered writes, a two-iteration loop and a write in the condition. Use 16², 32 × 16, 16 × 32 and 32² F32 with those four selectors, then 32 × 16 U16 at 2, 16 × 32 F16 at 7 and 16² U8 at 2. Add the case index and 31 times the graph index to seed 463361. + +Across the 105 controls the old evaluator matched 22,424/39,424 pixels. U8 matched 712/1,792 with maximum 143, U16 matched 1,344/3,584 with maximum 37887, F16 matched 1,360/3,584 with maximum 0.578125, F32 matched 19,008/30,464 with maximum 0.578125. The current evaluator matches **39,424/39,424**, maximum zero in every format. + +Use the two original U16 lookup tables, 36 settings and five undistorted F32 cases described in the [saved function measurements](#package-ownership-of-saved-function-calls). For each root the 82 original comparisons include both lookup tables and all four output formats. The 24 saved-package comparisons reopen the file in both applications. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| 3D Voronoi (304) | 82 | 24,064/24,064 · 0 | 57,856/57,856 · 0 | 24,064/24,064 · 0 | 68,096/68,096 · 0 | +| 2D Voronoi (306) | 82 | 24,064/24,064 · 0 | 57,856/57,856 · 0 | 24,064/24,064 · 0 | 68,096/68,096 · 0 | + +Each root also matched **57,344/57,344** pixels after saving, with 12,800 U8, 32,256 U16, 4,096 F16 and 8,192 F32 pixels. Maximum error was zero. In the original shuffled-table, 32 × 64 random-color case, the previous evaluator matched 32/2,048 pixels in 3D and 0/2,048 in 2D in each format. Each now matches all 2,048. The 2D and 3D fractal versions also match in that setting with both tables and all four formats, 16,384/16,384 pixels per root. + +For each nonfractal root, 38 further comparisons matched **32,256/32,256**, maximum zero. These include the [seven shuffled-table settings](#voronoi-distortion-and-shared-noise-inputs) and the 16², 32² and signed 16² F32 cases repeated with the affine table. For the other 28 renders, start at index 7 of the 36-setting matrix. Repeat with zero distortion, graph seeds 0 and 37, graph-derived color seed with the original seed and zero, and explicit color seeds 0, 1, 42 and 257. At 16² repeat all seven styles, all four distance modes, with inversion disabled and with zero distortion. Repeat random color on default controls with seed 37 and graph-derived or explicit color seed 1477. + +An independent 3D control used six 1024 × 16 U16 tables filled with 0, 65535, horizontal ramp, vertical ramp, four times the row-major texel index, and the affine table. At 16² F32/seed 37 use the original position field and defaults, random color, explicit color seed 1477, scale 2 with zero disorder, scale 3 with distortion .2, and style 4 with distortion .15. Also repeat random color with the default seed, explicit seed 1477 and zero disorder at scale 1 on constant U16 RGB positions (0,0,0), (32768,16384,32768), (13107,26214,39321) and (65535,65535,65535). All **27,648/27,648** pixels across 108 renders agreed, maximum zero. + +The 2D and 3D nonfractal roots reach measured parity with the same procedural tables in both applications. The [stock-table measurements](#voronoi-distortion-and-shared-noise-inputs) still apply to the separate bundled resources. Three distorted 32² stock renders per root used different table contents. The two fractal roots remain in progress pending the wider comparisons. The shared-assignment release regression failed before the change and passed afterward. All 321 node release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly checks passed. + +### Draw order for overlapping procedural grayscale stamps + +Grayscale pattern maps now draw procedural shapes in ascending shape order. Within a shape, additive contributions precede maximum contributions. Stamps with the same shape and blend group retain their traversal order. This affects overlapping stamps, including additive-only graphs where changing the order changes a low floating-point bit. + +Build three overlapping quadrants with respective sizes 1, 2 and 4, background .1875, persistence zero and no wrapping. Use three squares with maximum, add and add modes and tints .75, .25 and .5. At 32 × 16 the first and last pixels were 1.5 and 1.25. Both applications now produce .9375 and .75. For a chain use square, disc, square with the same blend modes and .875, −.375 and .5 tints. The two pixels are .5 and .875. With additive tints .75, 2⁻²⁷ and −.75 against zero, they are 2⁻²⁷ and .75. The release regression covers all three arrangements. + +| Original procedural measurements | Renders | Exact before | Exact after | Previous maximum error | +|---|---:|---:|---:|---:| +| Three stamps, siblings and chains | 36 | 16,028/24,576 | 24,576/24,576 | 16384 | +| Trees ending at depth 5, 6 and 7 | 18 | 5,730/9,216 | 9,216/9,216 | 0.60937497 | +| Horizontal, vertical and two-axis wrapping | 18 | 3,274/9,216 | 9,216/9,216 | 1.3125 | +| Cancellation between additive profiles | 16 | 6,894/8,192 | 8,192/8,192 | 7.4505806e-09 | +| Pairs spanning all 17 procedural shapes | 112 | 26,609/28,672 | 28,672/28,672 | 0.31250006 | +| Three squares, including equal keys | 253 | 111,184/129,536 | 129,536/129,536 | 1.125 | +| Two signed stamps and seven gain settings | 168 | 80,256/86,016 | 86,016/86,016 | 6.80564693e+38 | + +In total, 249,975/295,424 previously matched. All **295,424/295,424** now match across 621 renders, maximum zero. The six full-tree variants include 3,072 U8, 3,072 U16, 6,144 F16 and 12,288 F32 pixels. The other groups use F32. Undefined results were compared by their stored bits. + +For the full trees use a background of .1875 and gains 1 at 32 × 16, −1 at 16 × 32 and .625 at 32². Repeat the same sizes and gains in U8, U16 and F16. Use seeds 462427 + 41 × tree index + case index. Add empty quadrant levels to the first, fourth and sixth trees to test the depth boundary. For the pair sweep, use adjacent shapes 2 through 18 and both blend assignments at 16², background .125, additive tint .3125, maximum tint .75, and gains ±1. Equal-shape triplets use background .1875 and gains 1, −1, .375, 1.75 and −1.5. Signed two-stamp cases use tints ±.25 of opposite sign and backgrounds 0 and .5. In addition to finite positive and negative gains, divide 1, −1 and 0 by zero, and ±10³⁰ by 10⁻⁸. + +For the weighted spots comparison, use the first six parameter sets, at 16 × 32, 32 × 16, 32², 64 × 32, 32 × 64 and 64² with seeds 0, 456654, 113, 456716, 456747 and 456778. Render U16 and F32 in every case, plus U8 and F16 in the first, third and fifth. The following totals compare complete root outputs to the corresponding original or reopened reference graph. + +| Root and package | U8 exact · max | U16 exact · max | F16 exact · max | F32 exact · max | +|---|---:|---:|---:|---:| +| bnw_spots_1, original | 3,584/3,584 · 0 | 10,237/10,240 · 1 | 3,584/3,584 · 0 | 8,031/10,240 · 2.38418579e-07 | +| bnw_spots_1, saved | 3,584/3,584 · 0 | 10,235/10,240 · 1 | 3,584/3,584 · 0 | 7,995/10,240 · 2.38418579e-07 | +| bnw_spots_1, original | 3,584/3,584 · 0 | 10,240/10,240 · 0 | 3,584/3,584 · 0 | 9,960/10,240 · 1.1920929e-07 | + +In the first root the original F32 exact count rose from 6,994 to 8,031 of 10,240. The saved graph reached 7,995. The zero-roughness 64² U16 and F32 cases matched completely. The other settings retain differences. The four earlier U16 checks of the separate basic spots root still match 114,671/114,688, maximum two. All 322 node release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly checks passed. + +### One differing generator texel in the basic spots root + +At 256² with default parameters and seed zero, one U16 texel in the third pattern generator explains the differing output pixels in the basic spots root (57). Its two 64² generators each match 4,096/4,096 texels. The 128² generator matches **16,383/16,384**, maximum one level. At zero-based (99,47), MaterialCraft stores 9,942 and the reference stores 9,941. + +Connect the third generator directly to the output of the saved graph, leaving its original half-resolution setting. Default U8 and F16 each match 16,384/16,384. F32 matches 15,999/16,384, maximum 2.98023224e−8. At (99,47) the reference result is .15169809758663177 and the local result is .15169811248779297. Multiplying by 2²⁰ gives 159066.984375 and 159067. The values fall on opposite sides of the fixed-point boundary before U16 conversion. The original transform spreads the difference to (35,111), (163,111), (35,239) and (163,239). The direct branch adds (198,93), (197,94), (198,94), (199,94) and (199,95). + +In the [single-generator input graph](#isolating-the-generators-in-spots-bricks-and-cells), bind the local 128² U16 third-generator output. Keep the first two generators live. Change only (99,47) and render at 256² in each format. Each row compares a controlled graph with the unmodified original reference output. + +| Input level at (99,47) | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:| +| 9,942 | 65,527/65,536 · 2 | 65,535/65,536 · 0.000244140625 | 65,527/65,536 · 2.15768814e-05 | +| 9,941 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | 65,536/65,536 · 0 | +| 9,943 | 65,526/65,536 · 3 | 65,535/65,536 · 0.000244140625 | 65,526/65,536 · 4.31537628e-05 | + +When both applications received the same controlled input they agreed on **589,824/589,824 pixels** across all nine renders, maximum zero. Setting the texel to 9,941 also reproduced all **196,608/196,608** unmodified reference pixels across the three formats. + +Repeated renders distinguish a stable difference from variation in the original [125-setting comparison](#gaussian-generators-and-spots-through-1024-pixels-per-side). Six captures rotated the order of the tested cases. At 128 × 64, seed 372177, disorder 1, repeated U16 outputs included both 8,184/8,192 and 8,192/8,192. At 256 × 128, seed 379055, disorder .53125, they included 32,759/32,768 and 32,768/32,768. The 128² archive case at seed zero and disorder .35 gave both 16,376/16,384 and 16,384/16,384. Each partial match had a maximum error of two levels. Both 128² default checks, with seeds zero and 42, matched all 16,384 pixels. + +Of the 44 original pixel-format differences, 25 matched on at least one subsequent full-root render in the repeat series. The default 256² U16 comparison retained the same nine differences in all 15 captures. F32 retained nine. In three further captures with intermediate outputs observed, one F16 output also matched. The two stable groups account for 18 pixel-format differences across nine coordinates. The published original total stays 3,177,940/3,177,984. The origin of the generator's F32 accumulation difference remains open. + +### Fractal Voronoi roots with shared lookup tables + +The 2D fractal Voronoi root (307) reaches measured parity with the same procedural lookup in both applications. The 3D fractal root (305) had residual differences on the shuffled table in the same evaluator. Both roots use the [shared assignment and style controls](#shared-pixel-assignments-in-voronoi-color-selection) and the [36-setting parameter matrix and five undistorted controls](#package-ownership-of-saved-function-calls), once with the seeded shuffled table and once with the affine table. These cover defaults, distortion, signed position fields, noise and color seeds, distance and color choices, octave settings, square and rectangular outputs and all four storage formats. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| 3D fractal Voronoi (305) | 82 | 23,900/24,064 · 18 | 57,565/57,856 · 28698 | 23,832/24,064 · 0.0678710938 | 67,781/68,096 · 0.437905461 | +| 2D fractal Voronoi (307) | 82 | 24,064/24,064 · 0 | 57,856/57,856 · 0 | 24,064/24,064 · 0 | 68,096/68,096 · 0 | + +After writing the packages with MaterialCraft and reopening them in both applications, the corresponding 24 saved cases measured as follows. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| 3D fractal Voronoi, saved (305) | 24 | 12,669/12,800 · 18 | 32,221/32,256 · 638 | 4,096/4,096 · 0 | 8,187/8,192 · 0.437905461 | +| 2D fractal Voronoi, saved (307) | 24 | 12,800/12,800 · 0 | 32,256/32,256 · 0 | 4,096/4,096 · 0 | 8,192/8,192 · 0 | + +The 2D fractal results also match **32,256/32,256** across 38 supplemental settings and **7,168/7,168** across the ten supplemental saves, maximum zero. The seven shuffled-table and three affine-table cases compare the original and saved pixel buffers inside each application as well. At 16² and 32², the two applications each reproduce every original stored pixel after reopening, for both fractal roots. With the 3D shuffled table the differences were present before saving and persisted after reopening. + +The [stock-table comparison](#voronoi-distortion-and-shared-noise-inputs) used different resources in the two applications. All 27 undistorted renders matched 146,688/146,688 pixels per root. The three distorted 32² stock renders differed throughout, with F32 maxima .175076187 for the 2D fractal and .205578864 for the 3D fractal. Those cases remain distinct from the shared-table results. + +### Projected weights and tap order in short directional blurs + +The short oblique blur measures its reach using the stored horizontal and vertical direction components. It derives the first and last tap from the dominant component in texture coordinates. The same stored component supplies the projected width of a long diagonal window. On 16 × 128, the vertical white stripe at .375 turns and intensity 41.96875 produces center F32 bits 0x3e7fd802. A single U16 impulse at (1,1) on 128 × 64, angle .4375 and intensity 3.625, produces 0x3f123b30 at that pixel. The previous result was 0x3f123b31. + +The 46 three-tap F32 cases in the [rectangular blur matrix](#oblique-directional-blur-on-rectangular-images) improved from **384,404/442,368** to **442,368/442,368**, maximum zero. The 217 original signed and axial field controls from the [short-line comparison](#short-directional-blur-tap-order-on-rectangular-inputs) also match exactly, including square inputs where ordering the positive and negative taps affects the stored result. + +For an independent field use U16 levels (19x² + 313y + 3137xy + 47(j+3) + 26213(x mod 3)) mod 65536. Cycle dimensions 32 × 16, 16 × 32, 32² and 64 × 16 in zero-based angle order. Use turns (37,−119,303,−431)/1024, (183,−377,693,−1043)/2048, (987,−645,1213,−1515)/1024, then .06250012, .43749989, .213798523, .394229889, .125, −.125, .375, −.375, .625, .875, .08203125 and −.271484375. Set intensity to 256 times the radius divided by the shorter side. Use radii .5009765625, .671875, .8984375, 1.0703125, 1.3515625, 1.49 and 1.595703125 with seed 469193+29j+k for radius index k. Render F32 throughout and all four formats at indices 2 and 4. + +| Original primitive series | Renders | Exact pixels / total | Maximum error | +|---|---:|---:|---:| +| Earlier short-field controls · RGBA16 | 31 | 708,608/708,608 | 0 | +| Earlier short-field controls · RGBA16F | 31 | 708,608/708,608 | 0 | +| Earlier short-field controls · RGBA32F | 124 | 2,834,432/2,834,432 | 0 | +| Earlier short-field controls · RGBA8 | 31 | 708,608/708,608 | 0 | +| Earlier oblique matrix · RGBA16 | 36 | 342,561/344,064 | 63 | +| Earlier oblique matrix · RGBA16F | 36 | 343,693/344,064 | 0.0009765625 | +| Earlier oblique matrix · RGBA32F | 204 | 1,922,736/1,949,696 | 0.000969707966 | +| Earlier oblique matrix · RGBA8 | 36 | 344,030/344,064 | 1 | +| Independent field · RGBA16 | 48 | 36,864/36,864 | 0 | +| Independent field · RGBA16F | 48 | 36,864/36,864 | 0 | +| Independent field · RGBA32F | 168 | 128,991/129,024 | 0.00146079063 | +| Independent field · RGBA8 | 48 | 36,864/36,864 | 0 | +| Original stripe angles · RGBA32F | 792 | 1,608,192/1,622,016 | 1.1920929e-07 | +| Additional stripe angles · RGBA32F | 576 | 1,179,648/1,179,648 | 0 | +| Signed eighth-turn stripes · RGBA32F | 240 | 491,520/491,520 | 0 | +| Single impulses · RGBA32F | 30 | 2,752,512/2,752,512 | 0 | +| Sparse periodic impulses · RGBA32F | 36 | 2,948,850/2,949,120 | 0.000616334379 | +| Sparse periodic impulses · RGBA8 | 12 | 983,040/983,040 | 0 | + +For the eighth-turn controls orient the same 16-bit stripes perpendicular to each filter axis at 16 × 128 and 128 × 16. Use the first, second, fourth, sixth, seventh, ninth, thirteenth, fifteenth, seventeenth and eighteenth radii in the [long-stripe series](#direction-and-sample-coordinates-of-long-oblique-blurs). Use turns 0.125, 0.375, 0.625, 0.875, -0.125, -0.375, -0.625, -0.875, 1.125, -1.375, 1.625, -1.875 and seed 471329+71j+17h+i for angle j, orientation h and zero-based original radius index i. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Blur HQ (55) | 78 | 706,504/706,560 · 1 | 1,169,141/1,169,408 · 257 | 591,816/591,872 · 0.00439453125 | 1,192,949/1,193,216 · 0.0039215982 | +| Blur HQ Grayscale (56) | 78 | 706,545/706,560 · 1 | 1,169,358/1,169,408 · 257 | 591,857/591,872 · 0.00390625 | 1,193,166/1,193,216 · 0.0039215982 | + +In the two complete roots, 646 color and 130 grayscale pixels still differ across 78 distinct settings per root. All 3,489,792 original pixels in each application reproduced after reopening 60 saved settings per root, maximum zero. The residuals include longer oblique passes. The new release regression failed before this change and passed afterward. All 323 node release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly checks passed. + +### Stored levels when resizing a grayscale bitmap resource + +The Bitmap node now filters power-of-two normalized grayscale resources at each factor-of-two step. It clamps at the resource edge and stores each intermediate level at the node's destination format. Bitmap and graph-input paths use the same level sampler. The previous Bitmap cook averaged the entire footprint in one pass for integer-ratio reductions and sampled the original image directly for enlargements. + +The 3D fractal Voronoi graph requests its lookup at 1024 × 1. Its original procedural input has 1024 columns and 16 rows. For U16, take successive vertical pairs, compute (a+b+1) div 2, and repeat until one row remains. On the shuffled table, 70/1,024 stored texels previously matched, maximum two levels. On the affine table, 95/1,024 matched, also within two levels. The earlier graph-output tests masked the affine-table differences. + +Use the [two procedural tables](#package-ownership-of-saved-function-calls), a second row shuffle using seed 1299709, and tables filled with zero or 32768. From the first shuffled table, also replace zeros with 64, clamp the maximum to 65471, take the 65535 complement, and replace each of the 16 rows in turn with the matching affine row. All 24 directly captured Bitmap outputs now match **24,576/24,576** U16 texels, maximum zero. For an independent check, generate a 1024 × 1 PNG from the repeated pair calculation and bind it in both applications. The preceding evaluator then reproduces every final pixel across the seven shuffled and three affine settings of each fractal Voronoi root, **7,168/7,168 per root**, maximum zero. + +For a two-column regression use four rows. Fill the columns with 0 and 1000 respectively and add one at the bottom of each column. Resizing to 2 × 1 U16 stores 1 and 1001. The previous evaluator stored 0 and 1000. + +For an independent Bitmap graph, generate U16 levels (573x+149y+97xy+317) mod 65536 at 64 × 32 and 32 × 64, and U8 levels (83x+151y+11xy+29) mod 256 at 64 × 32. A fourth 64 × 32 U16 image uses 514 floor(x/8), plus one where x mod 4 and y mod 4 are both 3. With grayscale output, render each at 64 × 32, 32², 64 × 16, 32 × 16, 16², 16 × 32, 16 × 64, 64², 128 × 16 and 32 × 64. Use all four formats. The seeds are 497107 + 41j + k, with field indices 0 for U16, 1 for U8, 2 for the transposed U16 field and 3 for the tie field, and zero-based resolution index k. + +| Output | Renders | Exact before / total · maximum | Exact after / total · maximum | +|---|---:|---:|---:| +| LUM8 | 40 | 55,322/58,368 · 85 | 58,368/58,368 · 0 | +| LUM16 | 40 | 48,598/58,368 · 21884 | 58,368/58,368 · 0 | +| LUM16F | 40 | 53,644/58,368 · 0.333984375 | 58,368/58,368 · 0 | +| LUM32F | 40 | 23,985/58,368 · 0.33392936 | 58,368/58,368 · 0 | + +All **233,472/233,472** pixels match. The 3D fractal Voronoi root also now matches all **5,632/5,632** pixels on the seven shuffled-table settings, up from 5,475. The affine settings still match 1,536/1,536, and the 28 additional style, color-seed and distance controls match 25,088/25,088. All maxima are zero. Capturing the three displacement calls separately before this fix showed that their nine inputs (position, scale and offset for each call) already matched 46,080/46,080 F32 pixels across six settings. + +Repeat the two modular fields at 37 × 23, with field indices 4 and 5. These non-power-of-two Bitmap outputs have the following remaining differences. A graph input bound to the same PNG matched the complete reference Bitmap output in all 80 settings, 116,736/116,736 pixels across both files, maximum zero. + +| Output | Renders | Exact pixels / total · maximum | +|---|---:|---:| +| LUM8 | 20 | 15,093/29,184 · 85 | +| LUM16 | 20 | 4,548/29,184 · 21878 | +| LUM16F | 20 | 5,057/29,184 · 0.333740234 | +| LUM32F | 20 | 16/29,184 · 0.333839174 | + +The new release regression failed before this change and passed afterward. All 324 node and 55 evaluator release tests passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly checks. + +### Variation in the order of additions in the basic spots generator + +Use the 128 × 128 third generator from the [single-texel comparison](#one-differing-generator-texel-in-the-basic-spots-root). At a 256 × 256 parent size, render it directly to F32 nine times per setting. Rotate the order of the three settings between captures. The table counts bitwise-equal pixels against the unmodified MaterialCraft renderer. A varying coordinate produced at least two different stored values in the nine reference captures. + +| Seed and disorder | Exact / total across nine renders | Maximum error | Varying reference coordinates | +|---|---:|---:|---:| +| 0, default | 144,288/147,456 | 2.98023224e-08 | 524 | +| 42, default | 144,385/147,456 | 2.98023224e-08 | 469 | +| 0, .35 | 144,726/147,456 | 2.98023224e-08 | 447 | + +To test the addition order, capture the position in traversal order and the F32 contribution of every MaterialCraft stamp that covers each pixel. The seven quadrant subdivisions yield 16,384 leaves. Group the leaves by their first two quadrant choices, numbering each group from 0 to 15 in traversal order. Keep the 1,024 leaves inside each group in order. For each pixel, enumerate the orderings of the groups that touch it, and accumulate the original contributions one at a time in F32 starting from zero. Keep the orderings that produce the observed F32 bits. Find a single order of all 16 groups that satisfies these constraints across the image. + +One group order per capture reproduces **442,368/442,368** pixels over all 27 renders, maximum zero. For example, the first default capture fits group order `0 12 9 1 4 5 13 10 14 15 8 11 6 7 2 3`. Fitting on part of each image also predicts withheld pixels. Exclude every coordinate with `(x + 3*y) % 5 == 0` and the coordinate (99,47) before choosing each order. An ascending search for the first compatible group order predicts **88,476/88,479** withheld pixels, maximum 1.49011612e−8. All nine default captures predict the held-out (99,47) value .15169809758663177. + +In the default graph the four MaterialCraft contributions at (99,47), in its traversal order, are .05887965112924576, .031324971467256546, .02835862897336483 and .03313484787940979. Their accumulation order accounts for the U16 boundary at that coordinate. The observed changes between captures prevent a single fixed image from matching every repeat. These reordered images explain the disagreement. The original renderer counts above and the [125-setting root comparison](#gaussian-generators-and-spots-through-1024-pixels-per-side) remain the parity measurements. + +### Original channel precision of odd-sized grayscale bitmap resources + +The grayscale Bitmap node and a graph input bound to the same 37 × 23 PNG produced identical stored pixels in the reference app. MaterialCraft previously resized the embedded resource with a single bilinear lookup. The bitmap now uses the existing two-pass raster filter. It retains the source byte or word depth during resizing, including when a downstream node samples a wider output. + +Generate the U8 and U16 modular fields at 37 × 23 and use the ten output sizes and seed formula in the [stored-level comparison](#stored-levels-when-resizing-a-grayscale-bitmap-resource), with field indices 5 and 4 respectively. All 80 embedded Bitmap outputs and all 80 graph input outputs now match. The following counts are for the embedded Bitmap. + +| Output | Renders | Exact before / total · maximum | Exact after / total · maximum | +|---|---:|---:|---:| +| LUM8 | 20 | 15,093/29,184 · 85 | 29,184/29,184 · 0 | +| LUM16 | 20 | 4,548/29,184 · 21878 | 29,184/29,184 · 0 | +| LUM16F | 20 | 5,057/29,184 · 0.333740234 | 29,184/29,184 · 0 | +| LUM32F | 20 | 16/29,184 · 0.333839174 | 29,184/29,184 · 0 | + +At 32² U16, read (0,0), (3,7), (16,16) and (31,31). The byte field stores 11,308, 30,326, 40,349 and 49,087. The word field stores 419, 4,749, 33,094 and 35,028. The two source precisions are distinguishable even when the output format is identical. The 160 power-of-two controls still reproduce all 233,472 pixels. + +For a downstream check connect each original resource through a Bitmap or a bound image input to a Pixel Processor. Set the upstream format in turn to U8, U16, F16 and F32. Request a bilinear color sample at the pixel center plus (.01318359375, −.02734375). Render to F32 at 32², 16 × 32 and 64 × 16, then to U8, U16 and F16 at 32². Use seed 507011 + 43i + j for zero-based upstream format i and output case j. All 96 renders match **90,112/90,112 RGBA pixels**, maximum zero. This includes 40,960 F32 pixels and 16,384 in each other format. + +MaterialCraft wrote six packages spanning direct and downstream reads. Reopening in both apps reproduced the original 37,888/37,888 pixels across 40 saved settings and matched across applications in all four formats, maximum zero. The regression failed on the previous evaluator and passed with the fix. Eight core and 56 evaluator release tests passed. Formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Repeated cloud renders and two generator texels + +For Clouds 1 and 2 (78 and 79), repeat the differing cases from the [32-setting series](#pixel-center-rounding-at-the-near-stamp-vertex) and one U8 control. Use the original graph, the MaterialCraft save, and six further original-graph captures with rotated case order. Compare the same deterministic MaterialCraft output against each of the eight reference renders. A pixel counts as exact only if its complete stored value matches. + +| Root and format | Targeted cases | First render exact / total | First maximum | Pixels matching on at least one render / total | Largest error across eight renders | +|---|---:|---:|---:|---:|---:| +| Clouds 1, U8 | 1 | 512/512 | 0 | 512/512 | 0 | +| Clouds 1, U16 | 2 | 98,294/98,304 | 4 | 98,303/98,304 | 4 | +| Clouds 1, F32 | 3 | 163,828/163,840 | 0.000110566616 | 163,840/163,840 | 0.000110566616 | +| Clouds 2, U8 | 1 | 512/512 | 0 | 512/512 | 0 | +| Clouds 2, U16 | 5 | 180,728/180,736 | 2 | 180,736/180,736 | 2 | +| Clouds 2, F16 | 1 | 65,535/65,536 | 0.000244140625 | 65,536/65,536 | 0.000244140625 | +| Clouds 2, F32 | 3 | 131,581/131,584 | 2.28881836e-05 | 131,584/131,584 | 2.28881836e-05 | + +Use matrix case indices 7, 8 and 9 for Clouds 1, and 1, 6, 7, 8 and 9 for Clouds 2, with case 0 as the control. In Clouds 2 every one of the 12 initially differing stored values recurred as an exact match at least once. In Clouds 1 this happened at 21 of 22. The remaining coordinate was (126,211) in the 128 × 256 U16 case with seed 382396 and disorder .921875. It differed by four levels even in a reference render that matched all the other 32,767 pixels. + +To isolate that case, observe the three pattern generators in the original graph. The smaller generators match 8,192/8,192 and 2,048/2,048 U16 texels. In the full-size generator feeding the transform and the opacity mask, two texels differ by one level each in the render that records the three generator outputs. Bind its MaterialCraft U16 output as the original graph's input at that node. Leave the two smaller generators running and change only the two listed texels. The following rows compare with the original reference outputs. + +| U16 level at (35,174) | U16 level at (126,211) | U16 exact / total · max | F32 exact / total · max | +|---:|---:|---:|---:| +| 1,760 | 1,913 | 32,763/32,768 · 4 | 32,763/32,768 · 5.57303429e-05 | +| 1,759 | 1,913 | 32,767/32,768 · 4 | 32,767/32,768 · 5.51939011e-05 | +| 1,760 | 1,912 | 32,764/32,768 · 4 | 32,764/32,768 · 5.57303429e-05 | +| 1,759 | 1,912 | 32,768/32,768 · 0 | 32,768/32,768 · 0 | + +With identical generator inputs in both applications, all **524,288/524,288** pixels match on the sixteen U8, U16, F16 and F32 controlled renders. Changing both generator texels reproduced all 65,536 original U16 and F32 pixels. Both roots remain in progress for their unmodified 32-setting series. + +### 3D fractal Voronoi after correcting bitmap lookup reduction + +The 3D fractal Voronoi root (305) now matches every stored pixel on the two independently generated lookup tables. The [lookup strip measurements](#stored-levels-when-resizing-a-grayscale-bitmap-resource) isolate the cause. The 1024 × 16 resource reduces one row pair at a time. Rounding each pair to a stored U16 level changes the distortion at positions that previously selected a different cell. + +Use the [same parameter matrix and the two original table recipes](#fractal-voronoi-roots-with-shared-lookup-tables). Exact counts below include defaults and changed octave, distance, color, seed and distortion settings at square and rectangular resolutions. MaterialCraft wrote the packages for the separate 24-setting reopen comparison. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Original, shared tables (305) | 82 | 24,064/24,064 · 0 | 57,856/57,856 · 0 | 24,064/24,064 · 0 | 68,096/68,096 · 0 | + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Reopened, shared tables (305) | 24 | 12,800/12,800 · 0 | 32,256/32,256 · 0 | 4,096/4,096 · 0 | 8,192/8,192 · 0 | + +The shuffled and affine tables each matched 87,040/87,040 pixels across 41 original renders and 28,672/28,672 across 12 saved renders. Switching between the two tables changes outputs. An additional 38 control renders matched 32,256/32,256, and all 7,168 pixels matched in the ten supplemental saves. All maxima are zero. + +These measurements use the same lookup image in both applications. The separate [bundled lookup observations](#voronoi-distortion-and-shared-noise-inputs) include three distorted 32² cases that differ across all 3,072 F32 pixels with the default resources, maximum .205578864. With distortion disabled those 27 controls matched 146,688/146,688 pixels. + +### Stored levels of linear color bitmap resources + +Power-of-two linear RGBA bitmaps use the same clamped, stored levels as the [grayscale bitmap controls](#stored-levels-when-resizing-a-grayscale-bitmap-resource). Filtering each normalized channel this way fixes one-level differences on a single reduction and larger errors when resizing through several levels. At 64 × 32 to 64 × 16 the old evaluator differed on every U16 pixel of the byte field. At (0,0) the exact result is (6554, 30969, 44718, 45746). + +For the 64 × 32 byte field use A(x,y) = (31x + 13y + 97xy + 19) mod 256. Use A in red and periodic shifts of A by five rows, nine columns and seventeen columns in green, blue and alpha. Render the ten sizes in the [grayscale tests](#stored-levels-when-resizing-a-grayscale-bitmap-resource) at seed 497107 + j, with zero-based size index j. For an independent 32 × 64 word field use (ax + by + cxy + d) mod 65536 for each channel. The RGBA coefficient tuples are (583,191,371,3229), (47,313,59,4511), (31,693,41,8943) and (997,811,97,9043). Render at 32 × 64, 16², 16 × 64, 64 × 16, 64² and 32 × 128 with seed 520884 + j. Select linear color input in MaterialCraft and render all four formats. + +| Output | Renders | Exact before / total · maximum | Exact after / total · maximum | +|---|---:|---:|---:| +| RGBA8 | 16 | 24,168/27,136 · 84 | 27,136/27,136 · 0 | +| RGBA16 | 16 | 15,291/27,136 · 21684 | 27,136/27,136 · 0 | +| RGBA16F | 16 | 22,547/27,136 · 0.330810547 | 27,136/27,136 · 0 | +| RGBA32F | 16 | 4,250/27,136 · 0.330882341 | 27,136/27,136 · 0 | + +The 64 original renders matched **108,544/108,544** pixels. The 24 saved renders matched **37,632/37,632** across applications and reproduced their originals in each application, maximum zero. The normalized-color regression failed on the previous evaluator and passed with the fix. Formatting, the node release suite, strict workspace Clippy, dependency layers and WebAssembly passed. + +The default interpretation of an untagged color source, color-to-grayscale conversion and odd-sized RGBA sources have separate comparisons. For example, the 29 × 47 linear byte field still differed in the six-resolution series. + +### Grayscale conversion on the first bitmap filter pass + +A normalized RGBA bitmap with grayscale output filters RGB at source precision on the first resize pass. It takes the equally weighted mean of the three sampled channels, then stores the gray value at the requested precision. Later passes filter that grayscale image. A same-size render takes the same channel mean directly. Alpha varies independently in these controls. + +Generate the modular RGBA word field at 32 × 64. For the byte field use the same four coefficient tuples modulo 256 at 64 × 32. Choose linear input and grayscale output. Render 32 × 64, 16², 16 × 64, 64 × 16, 64² and 32 × 128 in U8, U16, F16 and F32, with seed 520884 + size index. For the word field at 16², the first pixel stores 6388 in U16. A same-size F32 render starts with the word `3dadc8af`. [Field coefficients](#stored-levels-of-linear-color-bitmap-resources) + +| Output | Renders | Exact before / total · maximum | Exact after / total · maximum | +|---|---:|---:|---:| +| LUM16 | 12 | 2/25,088 · 24283 | 25,088/25,088 · 0 | +| LUM16F | 12 | 46/25,088 · 0.370605469 | 25,088/25,088 · 0 | +| LUM32F | 12 | 0/25,088 · 0.370539784 | 25,088/25,088 · 0 | +| LUM8 | 12 | 453/25,088 · 94 | 25,088/25,088 · 0 | + +Across all 48 renders, **100,352/100,352** pixels match, maximum zero. Converting the source to stored gray before filtering matches 52,263/100,352. Converting at the last level matches 85,196/100,352. The 20 saved renders matched **47,616/47,616** across applications and reproduced the original buffers in both, maximum zero. The node regression reproduces the earlier error. The release node suite, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +These measurements cover power-of-two dimensions and an explicit linear data read. The separate comparisons for odd-sized color resources and file-default color interpretation remain open for this evaluator. + +### Grayscale bitmap stamp ordering across slots and filters + +In a grayscale pattern graph, bitmap slots draw after the procedural shapes. Their first traversal use determines the order of the slots. Within a slot the measured order is automatic mip filtering (0), bilinear (1), then nearest (2). At each filter mode additive stamps draw before maximum stamps. Equal keys keep traversal order. + +Use a three-node quadrant chain with the first child connected at quadrant 0 and the next at quadrant 1. Give the three stamps sizes 1, 2 and 4 and use zero roughness, zero background, tiling off, unit opacity multiplier and F32 grayscale output. Supply constant byte images of 128 and 255 at slots 0 and 1. At 32 × 16 and 16 × 32, seeds 471817 and 471818, the following results distinguish the ordering. + +| Slots | Filters | Blend modes | Signed grayscale tints | Top-left F32 value | +|---|---|---|---|---:| +| 1,0,1 | 2,2,2 | add,add,add | .75, 2⁻²⁷, −.75 | 3.7398995e−9 | +| 1,0,1 | 2,2,2 | max,add,max | .125, .25, .875 | 1.00049019 | +| 1,1,1 | 0,1,0 | max,add,max | .75, .3125, .1875 | 1.0625 | +| 1,1,1 | 1,0,1 | max,add,max | .75, .3125, .1875 | .75 | + +The independent filter sweep uses each ordered pair of distinct filters a,b from 0,1,2 with the stamps set to a,b,a. It repeats the maximum/additive case and the signed three-addition case. For the five-stamp controls, vary the slot sequence across 2,1,2,0,1 and 0,0,0,0,0 as well as mixed shapes and slots. Use filters (i+j) mod 3 for zero-based stamp i and case j, sizes 1,2,4,8,16, and exercise additions, both maximum mode values, positive and negative gains. Reversing the serialized node list in alternating cases preserves the connected traversal order. The tested sizes are 32 × 16, 16 × 32, 32² and 16². + +| F32 comparison | Renders | Exact before / total · maximum | Exact after / total · maximum | +|---|---:|---:|---:| +| Three stamps with two slots | 40 | 20,184/23,040 · 0.212009817 | 23,040/23,040 · 0 | +| Five stamps with up to three slots | 24 | 9,335/13,824 · 0.593627483 | 13,823/13,824 · 0 | +| Constant fields | 8 | 1,984/4,096 · 0.25 | 4,096/4,096 · 0 | +| Procedural shapes with a bitmap | 24 | 11,879/16,384 · 0.375 | 16,384/16,384 · 0 | +| Filter pairs on one slot | 24 | 9,120/12,288 · 0.3125 | 12,288/12,288 · 0 | + +The 120 composite renders matched **69,631/69,632** pixels. Rendering the individual stamps separately matched **187,390/187,392** across 312 renders. Starting with the same independently authored graph serialized by MaterialCraft, saving it again and reopening it in both applications matched **33,791/33,792** across 60 renders. Each application reproduced its own originals. The maximum numerical error is zero. At (0,0) on the 16 × 32 five-stamp, one-slot control with negative gain, the reference stored negative zero and MaterialCraft stored positive zero. The same sign difference occurred in two isolated-stamp renders. + +The four 64² U8, U16, F16 and F32 root controls stayed exact on Arc Pavement, Tile Generator, Tile Random and Weave 2 in the first group of rechecks. Paths Trace and Splatter Circular still differ. The larger root matrices retain their existing status. The ordering regression reproduced the earlier error. The release node suite, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Odd-sized linear color bitmap resources + +The same odd-sized linear RGBA PNG produces identical pixels as a Bitmap resource and as a bound color input. This holds both at the node output and at a downstream filtered read. The evaluator now reuses the bound-raster resize for embedded color images at their original normalized channel depth. + +Generate the byte field at **29 × 47** and the word field at **41 × 27**, using the four RGBA coefficient tuples modulo 256 and 65536 respectively. Select linear input and color output. Render at 32 × 64, 16², 16 × 64, 64 × 16, 64² and 32 × 128, seed 520884 + size index, in all four formats. On the 16² U16 output, pixel (6,11) stores (29555,33667,31354,39321) for the byte source and (39835,29231,35098,11450) for the word source. [Field coefficients](#stored-levels-of-linear-color-bitmap-resources) + +| Output | Renders | Exact before / total · maximum | Exact after / total · maximum | +|---|---:|---:|---:| +| RGBA16 | 12 | 1,563/25,088 · 27611 | 25,088/25,088 · 0 | +| RGBA16F | 12 | 770/25,088 · 0.421264648 | 25,088/25,088 · 0 | +| RGBA32F | 12 | 0/25,088 · 0.421319731 | 25,088/25,088 · 0 | +| RGBA8 | 12 | 5,652/25,088 · 107 | 25,088/25,088 · 0 | + +Each source matched 50,176/50,176 pixels in 24 renders. All 45,056/45,056 pixels also matched in 48 downstream samples of the bitmap and independently in 48 samples of the bound input. For those reads, add (.01318359375, −.02734375) to the pixel-center UV and sample bilinearly. Render each of the four bitmap formats at 32², 16 × 32 and 64 × 16 with F32 output, then at 32² in U8, U16 and F16. The seed is 551317 + 43f + j for format index f and setting index j. + +MaterialCraft saved ten procedural graphs. Both applications reopened them and reproduced their respective originals in all 52 settings. Across applications **70,144/70,144** pixels matched after reopening. All maxima are zero. The evaluation regression failed before this change and passed after it. The 57 release evaluation tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. The measurements cover linear color reads from these two PNG sources. + +### Isolated sample coordinates in the two HQ blur roots + +A periodic RGB impulse separates the two sheared texture reads of the directional blur used in the HQ roots (55 and 56). Use an original F32 input and output. Choose the filtering axis from the larger absolute direction component divided by that axis’s image extent. Along that axis, light every sixteenth column with a chosen residue h from 0 to 15. Across the columns, repeat four rows of pure red, green, blue and black. Alpha is one. Transpose for the vertical axis. Set intensity to the tabulated radius times 256 divided by the shorter image side. + +| Series | Width × height · turns · radius | F32 renders including identity | Exact pixels / total | Maximum error | +|---|---|---:|---:|---:| +| Original | 128 × 64 · 0.08203125 · 6.8125 | 17 | 138,193/139,264 | 0.000504907221 | +| Original | 512 × 128 · 0.4375 · 7.0537505 | 17 | 1,110,577/1,114,112 | 0.00061633531 | +| Original | 256 × 256 · -0.0849609375 · 6.71875 | 17 | 1,112,133/1,114,112 | 0.000332366675 | +| Independent | 256 × 128 · 0.396484375 · 6.71875 | 17 | 557,056/557,056 | 0 | +| Independent | 128 × 256 · 0.146484375 · 6.71875 | 17 | 557,056/557,056 | 0 | +| Independent | 256 × 128 · 0.103515625 · 6.71875 | 17 | 555,427/557,056 | 0.000445365906 | +| Independent | 256 × 256 · 0.142578125 · 6.71875 | 17 | 1,111,296/1,114,112 | 0.000350469723 | +| Independent | 256 × 256 · 0.447265625 · 6.71875 | 17 | 1,113,969/1,114,112 | 0.000278607011 | +| Independent | 256 × 256 · 0.052734375 · 6.71875 | 17 | 1,111,759/1,114,112 | 0.000301325927 | +| Independent | 256 × 256 · 0.302734375 · 6.71875 | 17 | 1,109,731/1,114,112 | 0.000300129876 | +| Independent | 128 × 256 · 0.337890625 · 6.71875 | 17 | 552,016/557,056 | 0.000513050705 | +| Independent | 128 × 512 · 0.4375 · 7.0537505 | 17 | 1,114,112/1,114,112 | 0 | +| Independent | 256 × 128 · 0.1875 · 4.8675003 | 17 | 557,056/557,056 | 0 | + +For series index j and residue h use seed 556013 + 83j + h for the original series and 562811 + 83j + h for the independent series. The seventeenth render of each series repeats residue 7 at zero intensity. All 630,784 identity pixels match the authored RGB values. The original matrix matched 2,360,903/2,367,488 across 51 renders, maximum 0.00061633531. The independent matrix matched 8,339,478/8,355,840 across 170 renders, maximum 0.000513050705. + +Near an isolated column, the two transverse texture reads have only two contributing rows each. At the column center and just inside both ends of the blur kernel, read the three color channels to distinguish adjacent 1/256-texel interpolation weights. Several ways of constructing an affine plane from rounded corners matched the three calibration settings to within 1.5e−8 on those interior reads. Across the ten independent settings, the existing coordinate calculation had 4,578 interior reads differing by more than 4e−7. No calibrated pair improved that count across the complete independent set. Both roots retain their [78-setting original and saved comparisons](#projected-weights-and-tap-order-in-short-directional-blurs). + +### Stored coverage before grayscale bitmap stamp opacity + +Grayscale bitmap stamps store `(sample − 1) + 1` at F32 precision before multiplying by opacity. This changes the sign of a zero coverage value under negative opacity. For a sample of 16,777,218, a tint of .75 and an opacity multiplier of .6137, it also changes a nonzero result. The measured output word is `4aeba92a`. Negate the sample and set the multiplier to −1.1875 to obtain `4b640004`. + +Use the [three- and five-stamp inputs, seeds and resolutions](#grayscale-bitmap-stamp-ordering-across-slots-and-filters). Compare stored words including the sign bit. The 120 composites matched **69,632/69,632** F32 pixels and the 312 individual-stamp renders matched **187,392/187,392**. The 60 reopened renders matched **33,792/33,792**, with identical original and reopened buffers in each application. All maxima are zero. + +For the coverage control, populate each row of an original 16² float field with −0, +0, ±2⁻³⁰, ±2⁻²⁶, ±2⁻²⁵, ±2⁻²⁴, ±.125, ±.25, 1, 1.25, with the positive value first in each ± pair. Use an F32 input bridge, a unit-size maximum stamp, background −4, tint .75, opacity multipliers 1, −1, 0 and −.5, and seeds 560722 through 560725. All 48 renders matched **12,288/12,288** pixels across three filter modes and U8, U16, F16 and F32 outputs, maximum zero. + +For an independent F32 control, fill each row with −1−2⁻²³, 1−2⁻²⁴, 2²⁴, 2²⁴+2, 2²⁴+4, −2²⁴−2, −2²⁴−4, 2¹⁸+.125, .1234, 1.25, 3.14, −3.14159, 0, 2⁻²⁵, 2⁻²⁴, 2⁻²². Use nearest filtering, background −2²⁸ and gains 1, −1, 0, −.5, .6137, −1.1875 and −0. Read both the input bridge and output in the reference app. Rounding the coverage first predicts **1,792/1,792** output words. A fused multiply-add predicts 1,232 and direct sample multiplication predicts 1,392. MaterialCraft's complete graph matched 1,536/1,792, maximum 14,942,196. An independent empty-pattern control reproduced a separate clamp on the literal background. + +For the byte field `29 × ((x + 3y) mod 9)`, keep the same four gains and formats, use nearest filtering, all three blend settings and backgrounds −1, +0, −0 and .25. Set the seed to 560713 + 61 × background index + 9 × blend setting + gain index. The four backgrounds matched 12,288, 12,032, 9,536 and 12,288 of 12,288 pixels respectively. The differences at zero were sign bits, maximum zero. Empty grayscale and color graphs with signed-zero, subnormal and mixed-channel backgrounds matched 37,376/47,104 pixels across 184 renders, maximum zero. Eight additional saved graphs reproduced each application's original in all 83 renders. Their cross-application count was 18,944/21,248, maximum 14,942,196. + +The regression failed on the earlier evaluator and passed with the coverage change. The release node suite passed all 328 tests. Formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Stripes across square and rectangular canvases + +Both Stripes roots now match **215,040/215,040** pixels across the original 18 renders in the [hard-edge, filtering and archived controls](#other-roots-using-uniform-arc-tangents), maximum zero. The pattern package previously differed at (23,59) on a hard edge in four formats. The standalone package differed at 28 archived U16 pixels. + +For the new series render each row below in U8, U16, F16 and F32. Width and softness are normalized. The seed is 571801 + 137 × the zero-based row index. + +| Canvas | Stripes | Width | Softness | Shift | Align | Filtering | +|---|---:|---:|---:|---:|---:|---| +| 32 × 64 | 5 | .375 | .5 | 2 | 0 | On | +| 128 × 32 | 11 | .21875 | .25 | 3 | 2 | Off | +| 64 × 128 | 19 | .796875 | .0625 | 4 | 1 | On | +| 256 × 64 | 7 | .515625 | .6875 | 1 | 0 | Off | +| 16 × 64 | 1 | 1 | 0 | 0 | 2 | Off | +| 256² | 17 | .34375 | .15625 | 5 | 1 | On | + +For a separate F32 sweep use the first row's parameters at 32 × 64, 64 × 32, 32², 64², 32 × 128 and 64 × 128. At 32 × 64 also turn filtering off, set shift to 0, set align to 2, set width to .5 and set softness to .25, changing one parameter per render. Use seeds 582801 + 17 × the zero-based case index. For the pattern package compare both settings of non-square expansion at 32 × 64 and repeat rows two, three and five above in all four formats at both settings, adding 97 to each row's original seed. The counts include its earlier [field controls](#facet-masks-and-stripe-boundaries). + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Pattern Stripes (372) | 83 | 151,296/152,576 · 21 | 265,984/267,264 · 5461 | 151,296/152,576 · 0.0834960938 | 175,488/190,464 · 0.291666687 | +| Standalone Stripes (510) | 53 | 121,856/121,856 · 0 | 236,544/236,544 · 0 | 121,856/121,856 · 0 | 155,648/155,648 · 0 | + +The standalone root matched all **635,904** pixels across 53 distinct settings. Its 21 saved renders matched **277,504/277,504** across applications. The pattern root matched **744,064/762,880** across 83 distinct settings. Its 29 saved renders matched **313,856/316,416**, maximum 21. In both applications, reopening regenerated every original pixel for the saved settings. + +At 32 × 64 in the first row the pattern package matched 768/2,048 pixels in each format. The maximum errors were 21 U8 levels, 5,461 U16 levels, .08349609375 in F16 and .0833333731 in F32. The pattern generator in the F32 setting matched 2,048/2,048 pixels, maximum 0. Both preceding directional blurs and the blend feeding the last blur also matched all 2,048 words. The first difference was in the last vertical directional blur. The standalone package matched all 2,048 at the same setting. + +### Nadir patch after reopening its linked shape package + +Replay the archived seeds and input variations, the four 64² formats, the independent 32² input and the [eight banded Nadir Patch inputs](#sobel-normals-and-nadir-projection). For Plane Light repeat its [nine projection fields and four plane-space controls](#panoramic-line-light-and-horizon-across-the-seam). + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Nadir Patch (329) | 17 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 148,666/148,736 · 1.1920929e-07 | +| Plane Light (334) | 22 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 8,192/8,192 · 0 | 174,579/175,360 · 4.76837158e-07 | + +Nadir Patch matched all 114,688 archived pixels, all 16,384 pixels in the four 64² formats and all 1,024 in the independent 32² field. Its remaining 70 differences occur in the banded F32 comparison, maximum 1.1920929e−7. The earlier 17-render comparison had 532 differing pixels and a maximum F32 error of .000473022461. + +The patch graph calls functions in the shape package. Save the patch graph and the shape package independently with MaterialCraft, retain the shape dependency as a relative path and reopen the patch. Across all eight banded settings the reference reproduced **41,216/41,216** original pixels. MaterialCraft reproduced its original buffers at all eight settings. Saving and reopening this pair again gave the same results in both applications. The cross-application comparison after each save was **41,146/41,216**, maximum 1.1920929e−7. Plane Light's four saved renders reproduced every original pixel within each application and matched 28,459/28,672 across applications, maximum 1.1920929e−7. + +Keeping the shape dependency pointed at the unconverted inventory source gave **36,657/41,216** matching pixels between the original and reopened reference renders, maximum 65,535 U16 levels. The reference could not open that unconverted local patch package directly. In a separate 16² default, changed 64² and seam 128² comparison, resolving only the shape dependency to its available native package restored all **20,736/20,736** reference pixels. Resolving only the math dependency gave 18,013/20,736, maximum 1 in F32. Both image bridges matched their original source fields in all three observed renders. At 16² the first discrepancy was the pixel processor, with 240/256 exact and maximum .739467438. These measurements distinguish dependency resolution on reopen from the small F32 differences in the working graph. + +### Bitmap file transfer and stored channel precision + +A Bitmap with an omitted color interpretation reads the stored RGB levels for the measured PNG, BMP, TGA, TIFF and JPEG files. Floating-point EXR retains its linear levels. A PNG gamma tag can change the stored color or gray levels before resizing. The session caches file-default, explicit linear and explicit sRGB reads independently, including resources from linked packages. Saving an original graph with an omitted interpretation preserves that omission. + +Generate a 64 × 32 RGB image with 8 × 8 blocks. Set X and Y to the integer block coordinates. Compute channels modulo 256 using 71X + 43Y + 19, 99X + 107Y + 13 and 149X + 23Y + 53. Encode each file from those pixels. Use JPEG quality 96 with full chroma resolution and use channel/255 for floating-point EXR. Render each format with the interpretation omitted and with an explicit linear read, at native size in U8, U16, F16 and F32 and at 16² in F32. Use seed 555013 + file index for native size and 555827 + index for the reduction, in PNG, BMP, TGA, TIFF, JPEG, EXR order. File-default reads improved from 8,448/50,688 exact pixels (maximum 18,815 U16 levels) to 50,688/50,688. The explicit reads matched another 50,688/50,688. + +For the PNG profile controls use the [modular RGBA fields](#stored-levels-of-linear-color-bitmap-resources). Take the byte field with no tag, an sRGB tag, gAMA 100000, gAMA 45455, and an embedded standard sRGB profile. Render at 64 × 32, 32² and 16 × 64 in all four formats with seeds 497107, 497108 and 497113. Those 60 renders improved from 0/81,920 (maximum 43,948 U16 levels) to 81,920/81,920. For independent byte and word controls, set gAMA to 30000, 40000, 43000, 44000, 45455, 47000, 48000, 50000, 60000, 80000 and 100000. Render at native size in four formats and at 16² in F32. The eleven matching-depth boundary probes use 43178, 43181, 43182, 43230, 43291, 47725, 47727, 47728, 47784, 47846 and 47848. For the [grayscale fields](#stored-levels-when-resizing-a-grayscale-bitmap-resource) use the 64 × 32 modular byte and word fields described there, at native size in all four formats with no tag and gAMA 30000, 43181, 43182, 45455, 47847, 47848, 60000 and 100000. + +For file gamma g and channel maximum M, the observed transfer rounds 1/(2.2g) to five decimal places. Keep source levels when 2.2g rounded to five places and the rounded exponent are both at least .95. Otherwise store round(M × (channel/M)^exponent) at the original channel depth. Alpha keeps its stored level. At gAMA 43181, 43182, 47847 and 47848 the format regression checks the two edges of the identity interval. A separate session regression exposed the earlier read of (64,128,192,97) as (13,55,134,97). + +| Stored output | Original renders | Exact pixels / total | Reopened renders | Exact pixels / total | Maximum error | +|---|---:|---:|---:|---:|---:| +| LUM16 | 18 | 36,864/36,864 | 6 | 12,288/12,288 | 0 | +| LUM16F | 18 | 36,864/36,864 | 6 | 12,288/12,288 | 0 | +| LUM32F | 18 | 36,864/36,864 | 6 | 12,288/12,288 | 0 | +| LUM8 | 18 | 36,864/36,864 | 6 | 12,288/12,288 | 0 | +| RGBA16 | 61 | 114,688/114,688 | 18 | 36,864/36,864 | 0 | +| RGBA16F | 50 | 92,160/92,160 | 18 | 36,864/36,864 | 0 | +| RGBA32F | 85 | 101,120/101,120 | 33 | 40,704/40,704 | 0 | +| RGBA8 | 61 | 114,688/114,688 | 21 | 39,936/39,936 | 0 | + +Bitmap file-default and explicit data reads matched all 570,112 pixels across 329 renders. Reopening 24 saved packages matched another 203,520/203,520 pixels and reproduced each original buffer in both applications. One of the original packages was saved by the reference editor before the five direct renders. These measurements cover the generated files and the listed metadata. Other ICC profiles, palette transparency and file-default DDS remain unmeasured. All 790 release tests across the engine, evaluator, format and node crates passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Finite HDR backgrounds in empty pattern graphs + +The literal background of an FX-Map supplies image samples. The previous parameter clamp limited all four channels to −16 through 17, before the renderer could store color or take the grayscale mean. With an empty quadrant and background (−64,192,−32,40), both apps now return those four F32 values in color mode and 32 in grayscale. Non-finite parameter components retain the usual parameter fallback. + +Set the quadrant pattern type to zero, omit the background image, and use a 16² output. Test the following backgrounds in both color modes, numbered from zero. For rows with one RGB level, repeat it on all three channels. The rows are (−128,−128,−128,1), (128,128,128,128), (−64,192,−32,40), (32768,−16384,8192,−4096), (−2²⁸,−2²⁸,−2²⁸,1), (2⁸⁰,2⁸⁰,2⁸⁰,1), (2¹²⁶,2¹²⁶,2¹²⁶,1), (2¹²⁷,2¹²⁷,2¹²⁷,1), (−2¹²⁷,2¹²⁷,−2¹²⁷,2¹²⁰) and (17,−16,16.5,−15.5). Use seed 570829 + 13 × row + color switch. Render each at U8, U16 and F32 and include F16 where every channel fits its finite range. For the all-positive 2¹²⁷ row, both applications store F32 word `7f800000` after the grayscale sum overflows, and 255 and 65535 in the two normalized formats. + +| Stored output | Original renders | Exact / total | Reopened renders | Exact / total | Maximum error | +|---|---:|---:|---:|---:|---:| +| LUM16 | 10 | 2,560/2,560 | 10 | 2,560/2,560 | 0 | +| LUM16F | 5 | 1,280/1,280 | 5 | 1,280/1,280 | 0 | +| LUM32F | 10 | 2,560/2,560 | 10 | 2,560/2,560 | 0 | +| LUM8 | 10 | 2,560/2,560 | 10 | 2,560/2,560 | 0 | +| RGBA16 | 10 | 2,560/2,560 | 10 | 2,560/2,560 | 0 | +| RGBA16F | 5 | 1,280/1,280 | 5 | 1,280/1,280 | 0 | +| RGBA32F | 10 | 2,560/2,560 | 10 | 2,560/2,560 | 0 | +| RGBA8 | 10 | 2,560/2,560 | 10 | 2,560/2,560 | 0 | + +Across the 67 entirely finite earlier renders, 10,240/17,152 pixels had matched with a maximum F32 error of 1.70141183e+38. All 70 renders now match **17,920/17,920** pixels, including the infinity word. All 20 saved packages match **17,920/17,920** on reopening and regenerate the originals in both applications. The [wide grayscale bitmap stamp](#stored-coverage-before-grayscale-bitmap-stamp-opacity) improved from 1,536/1,792 to **1,792/1,792** across its seven settings, also exact on reopening. Its maximum is zero. The empty-background regression failed at the old parameter clamp. All 666 release tests in the node, evaluator and engine crates passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. The [signed-zero empty-background comparisons](#stored-coverage-before-grayscale-bitmap-stamp-opacity) remain separate. + +### Pixel ratio in rectangular directional filters + +An inherited top-level pixel ratio evaluates to 1 (square pixels). An absolute ratio of 0 stretches the pixels to the graph dimensions. The last directional blur in Pattern Stripes inherits the graph's explicit zero. With square pixels its extent uses the shorter side. With stretched pixels each axis has extent max(0, intensity × axis length / 256 − .5) before the filter projects the direction. An inactive vertical extent can still leave a nonzero transverse projection at a quarter turn. + +On a value processor return the integer getter for `$pixelratio` directly. With (graph, node) values (inherit, inherit), (0, inherit), (1, inherit), (inherit, 0), (inherit, 1), (0, 1), (1, 0), both applications report 1, 0, 1, 0, 1, 1, 0. Test each at 16², 32 × 64 and 64 × 32 with seed 604211 + 13 × pair index + 31 × size index. The previous evaluator matched 18/21 values, maximum error 1. The updated evaluator and the seven saved graphs match **21/21** each, maximum zero. + +Generate an RGB field with a centered one-column impulse in red, a one-row impulse in green, and ((47x + 73y + 13xy + 79) mod 509)/508 in blue. For the inherited-ratio controls use 32 × 64, 64 × 32, 32², 64², 32 × 128 and 64 × 128. At zero and .25 turns set strength to 0, 1.2, 2.4, 4.8, 9.6 and 14. At .5, −.25 and .75 turns use 2.4, 4.8 and 9.6. Use F32 throughout and also U8, U16 and F16 at .25 turns and strength 2.4. Those 144 renders match **516,096/516,096** pixels, maximum zero. For the explicit graph and node ratio controls use both ratios, the four rectangular sizes, strengths 2.4, 4.8 and 9.6, and turns 0, .25, .125 and .0625. Also test each opposing graph/node override at .25 turns. The 120 cardinal renders improved from 365,337/491,520 (maximum .625) to 491,520/491,520. The 96 oblique renders improved from 202,156/393,216 (maximum .734410703) to 390,194/393,216 (maximum 1.1920929e−7). + +At 32 × 64, intensity 2.4 and .25 turns, the central green row stores F32 word `3f555555` and its neighbor `3daaaaac` with ratio 0. With ratio 1 they store 1 and 0. At 64 × 32, the same zero-ratio setting stores `321630f4` in the column next to the red impulse. The evaluator regression also covers node overrides, two oblique footprints and a shared cook cache. + +An independent field uses sizes 16 × 64, 128 × 32 and 64 × 256. Set S = 606401 + 47 × size index. Red is ((59x + 23y + 7xy + S) mod 251)/250, green is ((83x + 47y + 17xy + S) mod 257)/256 and blue is one where (x + 3y + S) mod 7 = 2. Use strengths 0, 1.5, 2, 2.5, 4, 7 and 12.5. With ratio 0 use turns 0, .25, .5, −.25, .75, .125, −.15625 and .1875. With ratio 1 repeat .25 and −.15625. Render in F32 and add U8, U16 and F16 at strengths 1.5 and 2.5. The 234 cardinal renders improved from 895,239/1,677,312 (maximum 43,690 U16 levels) to **1,677,312/1,677,312**, maximum zero. The 156 oblique renders improved from 385,616/1,118,208 (maximum 44,362 U16 levels) to **1,054,821/1,118,208**. By format they matched 172,032/172,032 U8, 172,020/172,032 U16, 172,032/172,032 F16 and 538,737/602,112 F32, with maxima 0, 1, 0 and .00105390698 respectively. All seven saved graphs reproduced the originals in both apps. Across apps their 70 reopened renders matched 436,716/437,248 pixels, maximum 1.1920929e−7. + +Replay the [Stripes settings](#stripes-across-square-and-rectangular-canvases). For the two mean-of-least-variance iteration roots also replay the [original matrix](#color-conversion-gradient-height-and-histogram-controls). Add 16 × 64, 64 × 16, 32 × 64 and 64 × 32 F32 input fields. Generate each input lane j as ((13x + 17y + 11xy + 53j + 43(j+1)x + 73(j+1)y) mod 251)/250. Use lane zero for grayscale. Render in all four formats with seed 607013 + 5 × inventory index + 29 × size index. Use defaults at the first size and use the four-format matrix's changed settings at the rest, with intensity/smoothness (2.5,.375), (4,.625) and (6.5,.8125). All 24 saved variation renders regenerated their original pixels in both applications and matched 36,864/36,864 across apps. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Pattern Stripes (372) | 83 | 152,576/152,576 · 0 | 267,264/267,264 · 0 | 152,576/152,576 · 0 | 190,464/190,464 · 0 | +| Standalone Stripes (510) | 53 | 121,856/121,856 · 0 | 236,544/236,544 · 0 | 121,856/121,856 · 0 | 155,648/155,648 · 0 | +| Mean of Least Variance color iteration (207) | 34 | 129,024/129,024 · 0 | 14,336/14,336 · 0 | 14,336/14,336 · 0 | 38,144/38,144 · 0 | +| Mean of Least Variance grayscale iteration (208) | 34 | 129,024/129,024 · 0 | 14,336/14,336 · 0 | 14,336/14,336 · 0 | 38,144/38,144 · 0 | + +Pattern Stripes improved from 744,064/762,880 to **762,880/762,880** across all 83 settings. Its 29 saved renders matched **316,416/316,416**, and the standalone root retained **277,504/277,504** on its 21 saved renders. Each application reproduced every original buffer for those saves. The two HQ blur roots retain 646 and 130 differing pixels across their respective 78 settings. The rectangular regression failed on the prior build. All 666 release tests across the engine, evaluator and node crates passed, as did formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Oblique directional filters with one zero pixel extent + +When one pixel extent is zero on a stretched rectangle, the surviving projection determines the sample locations, even at an oblique angle. Six F32 controls with a projected reach between one and two pixels went from 2,218/55,296 to **55,296/55,296** exact pixels, maximum zero. They use the [independent rectangle fields and intensities](#pixel-ratio-in-rectangular-directional-filters). At 16 × 64 with strength 7 and −.15625 turns, the red value at (7,13) has F32 word `3ea89223`. At 128 × 32 with strength 4 and .125 turns it has word `3f010625`. The regression for these two values failed on the previous build. + +Across all 390 renders in that sweep, this change recovers 53,078 pixels. Normalized errors in the tables are stored integer levels. Floating errors are absolute. + +| Output | Renders | Exact before / total · maximum | Exact after / total · maximum | +|---|---:|---:|---:| +| RGBA16 | 60 | 430,068/430,080 · 1 | 430,068/430,080 · 1 | +| RGBA16F | 60 | 430,080/430,080 · 0 | 430,080/430,080 · 0 | +| RGBA32F | 210 | 1,441,905/1,505,280 · 0.00105390698 | 1,494,983/1,505,280 · 0.00105390698 | +| RGBA8 | 60 | 430,080/430,080 · 0 | 430,080/430,080 · 0 | + +For an independent sweep use 16 × 256 and 256 × 16, in that order, with S = 617147 + 31 × size index. Use (((73x + 41y + 19xy + S) mod 509) − 91)/364 in red, ((53x + 101y + 7xy + S) mod 257)/256 in green and 1 in blue when (x + 2y + S) mod 11 equals 2, otherwise 0. Select ratio 0 and turns −.15625, .125, .203125 and .328125. Use strengths 1.125, 1.75, 2.375, 3.5, 4.75, 6.5 and 7.75, with seed S + 13 × angle index + strength index. Render all strengths in F32 and add U8, U16 and F16 at 2.375 and 4.75. + +| Comparison | Format | Renders | Exact pixels / total | Maximum error | +|---|---|---:|---:|---:| +| Independent field | RGBA16 | 16 | 65,483/65,536 | 1 | +| Independent field | RGBA16F | 16 | 61,391/65,536 | 0.00048828125 | +| Independent field | RGBA32F | 56 | 209,045/229,376 | 1.78813934e-07 | +| Independent field | RGBA8 | 16 | 65,504/65,536 | 1 | +| Reopened independent field | RGBA16 | 8 | 32,751/32,768 | 1 | +| Reopened independent field | RGBA16F | 8 | 32,719/32,768 | 0.000244140625 | +| Reopened independent field | RGBA32F | 32 | 118,888/131,072 | 1.78813934e-07 | +| Reopened independent field | RGBA8 | 8 | 32,736/32,768 | 1 | + +Seven of the eight angle and size pairs matched in every format. All differences in the independent sweep occur on the tall field at .203125 turns. Saving the eight graphs and reopening them in each application reproduced every original buffer at the 56 selected settings. Across apps those saves matched 217,094/229,376 pixels. The 70 saves from the earlier sweep matched 436,716/437,248, maximum 1.1920929e-07, with all originals reproduced in each app. + +To isolate the remaining projection error, replace red with a one-column impulse at the horizontal center and green with a one-row impulse at the vertical center. Read the center weight and its axial neighbor at strengths .625, .6875, .7109375, .765625, .828125, .921875, 1, 1.0625, 1.1875, 1.296875, 1.390625 and 1.484375. Across 22 angles and both orientations these weights agree with the current projected component in 42 of 44 comparisons. At .203125 turns the vertical component needs one additional F32 unit in the last place. At .302734375 turns the horizontal component does too. Two-axis oblique filtering remains open. + +Pattern Stripes retained **762,880/762,880** exact pixels across 83 distinct settings. All 331 node release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Adding selected components of a vector quotient + +A pixel function can select two components of a vector quotient, then add them. If both components feed only that sum, the numerator and reciprocal of the left component participate in one fused multiply-add with the rounded right component. An independent reader of the left component makes that lane round first and allows the right component to contract. Independent readers of both require both rounded values. Returning the quotient from a local function preserves these rules in the tested calls. + +Divide normalized pixel-center coordinates by (3.625, −.71875). Select x and y, add in both orders, expose x, y or both beside the sum, and repeat x as both operands. At (0.15625,0.03125), x + y stores F32 word `b9c482a0` and y + x stores `b9c48280`. Repeat at 16² and 64 × 32, seeds 632137 + variant index and 633107 + variant index. The 12 renders match **13,824/13,824** pixels, maximum zero. + +For an independent RGBA input use seeds S = 635791, 636119 and 636889 at 16², 32 × 64 and 64 × 32. Red is (((31x + 13y + 7xy + S) mod 353) − 151)/29. Green is (((13x + 59y + 17xy + S) mod 379) − 209)/37. Blue is (((73x + 31y + 5xy + S) mod 251) + 11)/61. Alpha is −(((37x + 23y + 13xy + S) mod 311) + 5)/73. Divide (red, green) by (blue, alpha) and repeat with the literal divisor. Exercise both addition orders, both single-lane readers, both lanes shared, x used twice, a call returning the quotient, and the call with x shared. Render all three shapes in F32 and add U8, U16 and F16 at 32 × 64. + +| Output | Renders | Exact before / total · maximum | Exact after / total · maximum | +|---|---:|---:|---:| +| LUM16 | 8 | 16,381/16,384 · 1 | 16,384/16,384 · 0 | +| LUM16F | 8 | 16,384/16,384 · 0 | 16,384/16,384 · 0 | +| LUM32F | 24 | 28,997/34,816 · 7.62939453e-06 | 34,816/34,816 · 0 | +| LUM8 | 8 | 16,384/16,384 · 0 | 16,384/16,384 · 0 | +| RGBA16 | 8 | 16,381/16,384 · 1 | 16,384/16,384 · 0 | +| RGBA16F | 8 | 16,384/16,384 · 0 | 16,384/16,384 · 0 | +| RGBA32F | 24 | 28,476/34,816 · 7.62939453e-06 | 34,816/34,816 · 0 | +| RGBA8 | 8 | 16,384/16,384 · 0 | 16,384/16,384 · 0 | + +All 96 renders match **167,936/167,936** pixels. After a MaterialCraft save, 92 renders from the 22 original arithmetic graphs matched **177,664/177,664** across apps and reproduced every original buffer in each. All maxima are zero. + +In Nadir Patch, render the two quotient components of the Gaussian separately, then their sum. Across the [16², 64² and 128² band inputs](#sobel-normals-and-nadir-projection), each component already matched 20,736/20,736. Adding the rounded values matched 16,959/20,736 with maximum .0625. Contracting the left numerator with its reciprocal matched **20,736/20,736**, maximum zero. The twelve probes from numerator to Gaussian output matched **248,832/248,832** pixels in 36 renders. The intact root now matches **173,312/173,312** in its earlier 17 settings. The [two saved companion packages](#nadir-patch-after-reopening-its-linked-shape-package) each reproduce the eight original buffers and match **41,216/41,216** across apps. + +For new root inputs use S = 638141 + 173 × index at 32 × 64, 64 × 16, 16 × 64, 64² and 32². Red is ((17x + 59y + 7xy + S) mod 283)/282. Green is ((89x + 47y + 19xy + S) mod 311)/310. Blue is one when (3x + 5y + S) mod 17 is below 8, otherwise zero. Alpha is ((53x + 73y + S) mod 257)/256. The independent grayscale mask is ((23x + 31y + 7xy + S) mod 157)/156. Use all four output formats for the settings below and repeat defaults in F32 at the first, fourth and fifth sizes. Turns are fractions of one revolution. + +| Size | Enabled / frames / frame thickness | Scale / patch size | Patch turn / source offset | Alpha mode / hardness | Source position / patch position | +|---|---|---|---|---|---| +| 32 × 64 | yes / no / .015625 | .75 / (1.25,.6875) | .15625 / .046875 | 1 / .21875 | (.953125,.75) / (.03125,.90625) | +| 64 × 16 | yes / yes / .125 | .53125 / (.9375,1.125) | −.09375 / −.0625 | 0 / .625 | (.0625,.875) / (.96875,.96875) | +| 16 × 64 | no / no / .0625 | .84375 / (.625,.875) | .25 / .125 | 1 / .5 | (.3125,.625) / (.71875,.953125) | +| 64² | yes / no / .09375 | .375 / (1.0625,.75) | .03515625 / −.03515625 | 1 / .1875 | (.984375,.5) / (.015625,.84375) | +| 32² | yes / yes / .0078125 | .625 / (.8125,1.3125) | −.1875 / .09375 | 0 / .34375 | (.625,.6875) / (.59375,.96875) | + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Nadir Patch (329) | 40 | 17,318/17,408 · 119 | 17,306/17,408 · 30519 | 17,306/17,408 · 0.465576172 | 165,018/165,120 · 0.465690076 | + +The 23 new settings matched **43,636/44,032** pixels. The 396 differences occur at the changed 64² setting. The two companion saves each reproduced every original buffer within each app at the 23 settings and matched 43,636/44,032 across apps. Plane Light retained 781 differing pixels across 22 settings. The arithmetic regression failed on the earlier build. All 332 node release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Original and reopened dirt, moisture and cellular noise fields + +These measurements use MaterialCraft revision `76fd1f7`. Recheck the archived roots and the four 64² precisions. Repeat their independently configured 32² field. For Dirt 3 and Dirt 6 include the [40 size, seed and disorder changes](#wave-frequency-and-phase-in-directional-noise) alongside the earlier field controls. For Moisture Noise repeat its [82 settings](#moisture-noise-across-repeated-original-renders). + +For the other six packages use the [30-setting rectangular series](#connected-quadrant-depth-and-amplified-spot-patterns), including its sizes, output formats, seeds and eight values of disorder d. Use defaults at indices 0 and 7. For a default scale above 8, change scale to 16, 5, 11, 27, 4, 19, 7 and 12 at the other eight indices. For smaller default scales those values are 2, 1, 3, 2, 1, 3, 2 and 1. Change each exposed float to d, with angle and disorder anisotropy angle d − .25 and pattern scale .375 + 1.25d. When exposed, set pattern to 3,4,9,5,7,1,3,10, color source to j mod 3 and pseudo-random seed to 37 + 131j, using the zero-based size index j. Set boolean controls on odd changed indices. Use tile offset (d − .34375, .40625 − .875d). For pattern size use (.4375 + .75d, .8125 + .6875(1 − d)) if its default height is at most 2, otherwise (.375 + .75d, 4.5 + 13d). Other float pairs use (.125 + .5d,.625 − .375d). The independent byte input is 127((floor(x/3) + floor(y/7)) mod 2) + ((5x + 9y + xy) mod 129) at sizes 64², 64 × 32, 32 × 64, 128², 128 × 64 and 64 × 128, indexed by j mod 6. Leave the input empty at the two defaults. Include the [banded cell inputs and previous source controls](#paths-caustics-and-cell-fields-after-pattern-sampling) where applicable. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Dirt 3 (129) | 56 | 469,248/469,248 · 0 | 597,236/597,248 · 1 | 469,248/469,248 · 0 | 550,385/550,400 · 1.52587891e-05 | +| Dirt 6 (131) | 55 | 469,247/469,248 · 1 | 580,619/580,864 · 5 | 469,158/469,248 · 0.000244140625 | 549,705/550,400 · 9.27709043e-05 | +| Moisture Noise (226) | 82 | 717,053/717,056 · 1 | 1,318,957/1,319,168 · 6 | 717,032/717,056 · 0.00048828125 | 1,243,462/1,243,648 · 7.83205032e-05 | +| Cells 1 v2 (241) | 49 | 136,448/136,448 · 0 | 243,960/243,968 · 1 | 87,296/87,296 · 0 | 266,646/269,824 · 8.34465027e-07 | +| Cells 4 (242) | 59 | 91,352/91,392 · 208 | 331,887/362,752 · 64479 | 91,348/91,392 · 0.816040039 | 268,953/299,776 · 0.983886491 | +| Cells 4 v2 (243) | 59 | 206,042/206,080 · 223 | 215,769/248,064 · 63423 | 91,370/91,392 · 0.872467041 | 267,469/299,776 · 0.967772953 | +| Creased (248) | 38 | 83,199/83,200 · 1 | 289,012/289,024 · 1 | 83,200/83,200 · 0 | 240,884/240,896 · 1.52587891e-05 | +| Crystal 1 (249) | 48 | 84,224/84,224 · 0 | 291,956/292,096 · 2 | 92,416/92,416 · 0 | 249,203/249,344 · 1.94627792e-05 | +| Crystal 2 (250) | 48 | 84,224/84,224 · 0 | 292,087/292,096 · 1 | 92,416/92,416 · 0 | 249,328/249,344 · 1.52587891e-05 | + +All listed cases finished. Counts use the first observation of a repeated setting. Dirt 6 had 1 repeated setting with different exact counts. The two LUM16 reads matched 65,503 and 65,516 of 65,536. Moisture Noise had 1 repeated setting with different exact counts. The two LUM16 reads matched 16,382 and 16,384 of 16,384. Cells 1 v2 improved from 640,414 to 734,350 of the same 737,536 pixels. Its largest remaining normalized error is one stored level. + +| Saved graph or series | Renders | Cross-app exact / total | Max U8 / U16 / F16 / F32 | Original vs reopened in reference · differing pixels | +|---|---:|---:|---|---:| +| Dirt 3 | 40 | 2,005,998/2,006,016 | 0 / 1 / 0 / 1.52587891e-05 | 16 | +| Dirt 6 | 40 | 2,005,169/2,006,016 | 1 / 5 / 0.000244140625 / 9.27709043e-05 | 677 | +| Moisture, first series | 30 | 521,148/521,216 | 1 / 6 / 0.000244140625 / 7.83205032e-05 | 76 | +| Moisture, second series | 32 | 3,313,340/3,313,664 | 1 / 6 / 0.00048828125 / 7.80820847e-05 | 353 | +| Cells 1 v2 | 30 | 629,153/629,760 | 0 / 1 / 0 / 8.34465027e-07 | 0 | +| Cells 4 | 30 | 568,040/629,760 | 208 / 64479 / 0.816040039 / 0.983886491 | 0 | +| Cells 4 v2 | 30 | 548,103/629,760 | 255 / 65467 / 0.998535156 / 0.998962402 | 20,475 | +| Creased | 30 | 629,735/629,760 | 1 / 1 / 0 / 1.52587891e-05 | 0 | +| Crystal 1 | 30 | 629,480/629,760 | 0 / 2 / 0 / 1.94627792e-05 | 0 | +| Crystal 2 | 30 | 629,746/629,760 | 0 / 1 / 0 / 1.52587891e-05 | 0 | + +MaterialCraft reproduced its original output buffers for every saved case in that table. The reference also reproduced all saved cases of Cells 1 v2, Cells 4, Creased and Crystal 1 and 2. The repeated [dirt](#repeated-dirt-pattern-stages) and [moisture](#moisture-noise-across-repeated-original-renders) comparisons measure variation in the original renders. + +For Cells 4 v2, repeat the 16² F32 default, the 64 × 16 U8, U16 and F32 settings, the 128 × 64 U16 and F32 settings, the 256² F32 default and the 128 × 512 F32 setting three times each. Every setting repeated bit-for-bit within each original or saved package. The two independent saves gave the same results. At 128 × 64, seed 411674, scale 27 and color source 1, each saved F32 buffer matched 0/8,192 of the reference library root, maximum .996459901. The U16 comparison matched 0/8,192, maximum 65,303 levels. The reference loader rejected the local source in its original 0.1.3 encoding. On the MaterialCraft-saved root, vary only the paths to the two linked helpers. Independently save the hash function package, the general function package, or both in the current SBS format. With pseudo-random seeds 0, 17, 561 and 823 at 128 × 64, color sources 0 and 2 each reproduced all 32,768 reference pixels with every pairing. Color source 1 reproduced 0/32,768 with the original helper paths or with just the general function package saved. With the saved hash package it reproduced **32,768/32,768** with either version of the general function package. With the hash dependency retained as a relative path, the 30 original reference renders matched every pixel after the first root save and again after the second. MaterialCraft reproduced every original buffer for both saves. The two reopened roots matched 1,130,268/1,259,520 across applications. These roots remain in progress. + +### Pixel subtraction and texture coordinates at the panorama equator + +At the equator, the panorama projection can produce an undefined horizontal texture coordinate alongside a finite vertical coordinate. Addressing the two axes independently fixes the sampled row. In the preceding projection stage, subtracting a selected product or quotient also preserves the operand sign when a component is used in a fused multiply-add. + +Use the [five original color and mask fields](#adding-selected-components-of-a-vector-quotient), including the four-format 64² setting with source position (.984375,.5), patch position (.015625,.84375), patch turn .03515625 and source offset −.03515625. The source direction there is approximately (.99518466,−.09801697,−0.0). The reciprocal of its last component is negative infinity. The sampled coordinates include an F32 NaN with word `7fffffff` and vertical coordinate .5. Bilinear repeat samples both sides of the horizontal seam at that row. Rendering the complete image on the earlier build differed at 90 U8 pixels (maximum 119 levels) and 102 pixels each in U16, F16 and F32 (maxima 30,519 levels, .465576172 and .465690076). + +Repeat the F32 setting while changing one control at a time. Set source latitude to .5 ± 1/8192, .46875 or .53125, or longitude to .5 or 0. Set either turn or both to zero. Vary the source offset by ±1/8192. Try alpha mode 0, the frame helper on, the effect disabled, the published defaults, a centered patch, and hardness 1. In the two settings immediately above and below the equator the earlier build already matched every pixel. + +To isolate the arithmetic, record the rotated direction, raw center, reciprocal, scaled center, their two-component difference, projected coordinates, sampled patch, weight and final output at the three band settings and eight changed or default F32 settings. Subtracting two rounded vectors reproduced 24,232/37,120 difference vectors. Multiplying each raw center component by the reciprocal with the negated rotated component as the fused addend reproduced 37,120/37,120. After the change all nine diagnostics match in every selected component, including signed zero, infinities and NaN words, **334,080/334,080** pixels across 99 renders. + +Multiply or divide pixel-center position by (3.6123411655426025,−.718791127204895), subtract the x and y components in both orders, expose x, y or both beside x − y, and repeat x − x. Use 16² and 64 × 32, seed 641933 + 83j + width, numbering the six product variants first, then the six quotient variants. At position (.15625,.03125), x − y in the product graph stores `3f163e75` and y − x stores `bf163e76`. For the signed field use the [independent quotient input formula and graph variants](#adding-selected-components-of-a-vector-quotient) at the same three sizes with seeds 656803, 657889 and 658451. Use subtraction in place of addition, retain the sampled divisors and repeat with literal divisors (−1.06719768,2.41659069). + +For the texture read, divide floor(3p) − 1 by x − x at pixel-center coordinate p, producing negative infinity, NaN and positive infinity in successive thirds. Put this coordinate in x, y or both. On a finite axis use 1.5p − .12109375. Cross these layouts with nearest and bilinear in repeat and clamp. With seed S = 651913 + 109j at 16², 32 × 16 and 16 × 32, use an original RGBA field ((x+1)/64, (y+1)/64, ((3x+7y+S) mod 127)/128, 1−((x+2y+S) mod 8)/16). Render F32 at each size and all four output formats at 32 × 16. At 16² with invalid x and y = .67578125, nearest repeat reads red/green (.015625,.171875) and bilinear repeat reads (.1328125,.1767578125). In clamp the red value is .015625 for NaN and negative infinity and .25 for positive infinity. + +For the second texture field, use the same coordinates and seed S = 657061 + 179j at 16 × 64, 64 × 16 and 32². Use RGBA components (((43x+67y+17xy+S) mod 271)−23)/274, (((17x+31y+7xy+S) mod 211)−15)/261, the indicator of (3x+11y+S) mod 11 = 7, and ((23x+137y+3xy+S) mod 251)/250. For variants k from 0 to 11 cycle x, y and both invalid, cycle nearest repeat, bilinear clamp, bilinear repeat and nearest clamp, and change input storage in groups of four from U8 to U16 to F16. Even variants return color and odd variants return gray. Use F32 at all sizes and all four output formats at 32². + +| Independent comparison | Renders | Earlier exact / total · maximum | Current exact / total · maximum | +|---|---:|---:|---:| +| Position products and quotients | 24 | 25,138/27,648 · 4.76837158e-07 | 27,648/27,648 · 0 | +| Independent signed quotient field | 96 | 154,227/167,936 · 1 | 167,936/167,936 · 0 | +| Coordinate ramps and seams | 72 | 13,516/33,792 · 61759 | 33,792/33,792 · 0 | +| Normalized and half-float input fields | 72 | 29,302/73,728 · 57343 | 73,728/73,728 · 0 | + +The independent comparison maxima above use stored units. The 28 saved arithmetic graphs reproduced **191,488/191,488** pixels across 104 renders. The 24 saved texture-coordinate graphs reproduced **89,088/89,088** across 120 renders. Each original and reopen matched within both applications and across applications, maximum zero. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Nadir Patch (329) | 56 | 17,408/17,408 · 0 | 17,408/17,408 · 0 | 17,408/17,408 · 0 | 230,656/230,656 · 0 | + +Nadir Patch matches **282,880/282,880** pixels across 56 distinct settings. The two saves of the banded root, two saves of the independent fields and the equator series with its saved companion match **244,224/244,224** across 80 reopened renders. Both applications reproduced their original buffers. Plane Light still differs in 781/199,936 pixels across 22 settings, maximum 4.76837158e−7 in F32. Its four reopened renders reproduce their originals and match 28,459/28,672 pixels across applications, maximum 1.19209290e−7. Both new regressions failed before the fixes. All 670 release tests in the node, evaluator and engine crates passed, as did formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Reopened paper, fiber, Gaussian and shape generators + +Recheck the intact roots on revision `02d910f`. The [older paper, fiber and shape comparisons](#paper-brick-fiber-mesh-polygon-and-shape-roots) covered 19 distinct settings per root. The [pattern-package Gaussian](#radial-stamp-profiles-and-pattern-generators) covered 18. Include those settings and all four 64² output precisions. For Shape Base also repeat the authored, square and disc variants selected with its published pattern parameter, retaining a repeated setting once. + +All four graphs generate their pixels procedurally. For an independent series use sizes 32 × 16, 16 × 64, 32², 128 × 64, 64 × 128, 128², 256 × 128 and 128 × 256. Use seed 662047 + 17i + 251j with zero-based inventory index i and size index j. Leave the parameters at their defaults for j = 0 and 5. At the six other sizes use the following controls. Fibers and Gaussian both expose tiling and nonsquare expansion. Shape Base exposes its own nonsquare control. + +| Size | Paper width / height / disorder | Fibers and Gaussian tiling / expand | Shape pattern / variation / scale | Shape XY size / angle in turns / nonsquare | +|---|---|---|---|---| +| 16 × 64 | 62.5 / 113.75 / .078125 | 2 / off | 1 / .125 / .59375 | (1.25,.46875) / .15625 / off | +| 32² | 103.125 / 69.375 / .609375 | 3 / on | 7 / .328125 / 1.15625 | (.71875,1.125) / −.21875 / on | +| 128 × 64 | 187.5 / 53.125 / .921875 | 5 / off | 11 / .71875 / .8125 | (.5625,1.4375) / .046875 / on | +| 64 × 128 | 79.6875 / 147.5 / .3125 | 4 / on | 3 / .09375 / 1.28125 | (1.03125,.59375) / −.40625 / off | +| 256 × 128 | 128.75 / 91.25 / .46875 | 1 / off | 15 / .625 / .9375 | (.84375,.53125) / .34375 / on | +| 128 × 256 | 93.75 / 162.5 / .734375 | 3 / on | 8 / .4375 / .671875 | (.40625,.90625) / −.125 / on | + +Render U16 and F32 at every size. Add U8 and F16 at j = 1, 2, 3, 4 and 7. Each independent series matches 304,128/304,128 pixels across 26 renders. The table includes the earlier whole-root settings and reports maximum stored-channel error. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Paper Path (340) | 45 | 56,320/56,320 · 0 | 221,184/221,184 · 0 | 58,368/58,368 · 0 | 110,848/110,848 · 0 | +| Pattern Fibers 2 (362) | 45 | 56,320/56,320 · 0 | 221,184/221,184 · 0 | 58,368/58,368 · 0 | 110,848/110,848 · 0 | +| Pattern Gaussian 2 (364) | 44 | 59,392/59,392 · 0 | 223,744/223,744 · 0 | 59,392/59,392 · 0 | 132,864/132,864 · 0 | +| Pattern Shape Base (369) | 61 | 58,368/58,368 · 0 | 224,256/224,256 · 0 | 62,464/62,464 · 0 | 115,456/115,456 · 0 | + +Across all four intact roots, **1,829,376/1,829,376** pixels match in 195 root settings. Save each package using MaterialCraft and open it in both applications for all 26 independent settings. Save each again and compare F32 at every size and all four formats at 64 × 128. Each graph matches 429,568/429,568 reopened pixels. All **1,718,272/1,718,272** pixels across 148 reopened renders match across applications and reproduce the respective original buffers. All maxima are zero. + +For the [reduced pattern and downstream controls](#paper-brick-fiber-mesh-polygon-and-shape-roots), the per-output comparisons on the current build are below. These diagnostics use the earlier input recipes and their own output dimensions. + +| Control | Renders | Exact pixels / compared | Maximum stored error | +|---|---:|---:|---:| +| Paper Path, authored shape | 9 | 8,448/8,448 | 0 | +| Paper Path, square and disc | 18 | 16,896/16,896 | 0 | +| Pattern Fibers 2, authored shape | 9 | 1,728/1,728 | 0 | +| Pattern Fibers 2, square and disc | 18 | 3,456/3,456 | 0 | +| Pattern Shape Base, authored shape | 9 | 8,448/8,448 | 0 | +| Pattern Shape Base, square and disc | 18 | 16,896/16,896 | 0 | +| Pattern Fibers 2, substituted grayscale source | 10 | 10,496/10,496 | 0 | + +### Directional blur weights across 110 angles and two projection axes + +Recheck both HQ blur roots in the [78 original settings and rectangular fields](#direction-and-sample-coordinates-of-long-oblique-blurs) on revision `02d910f`. Include U8, U16, F16 and F32 and reopen the two independent rectangular series in each application. A raw pixel counts as exact only when every stored channel agrees. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| HQ blur, color (55) | 78 | 706,504/706,560 · 1 | 1,169,141/1,169,408 · 257 | 591,816/591,872 · 0.00439453125 | 1,192,949/1,193,216 · 0.0039215982 | +| HQ blur, gray (56) | 78 | 706,545/706,560 · 1 | 1,169,358/1,169,408 · 257 | 591,857/591,872 · 0.00390625 | 1,193,166/1,193,216 · 0.0039215982 | + +The color root reproduced all original buffers after saving in both applications. Its 60 reopened renders matched 3,489,146/3,489,792 across applications, maximum 257 stored levels. + +The gray root reproduced all original buffers after saving in both applications. Its 60 reopened renders matched 3,489,662/3,489,792 across applications, maximum 257 stored levels. + +For a separate axial measurement, use a 16 × 64 F32 color input. Set red to one on column 8, green to one on row 32, and blue to ((43x+83y+5xy+631739) mod 257)/256. Use pixel ratio 0 in a directional blur. In order, use angles j/256 for j = 0..64, then (((101j+23) mod 2048)+.25)/8192 for j = 0..39, then −.15625, −.3896484375, .337890625, .4375 and .75 turns. For each angle use extents .3125, .5, .734375, .953125 and 1, with strength 4(extent+.5) and seed 631739 + 7 × angle index + extent index. Read the green weights on rows 32 and 33 at column 8. For projected reach r, the candidate center weight is .5/(.5+r) and the adjacent weight is r times that stored center weight. + +Across the 550 complete renders, 539,308/563,200 RGBA pixels match, maximum 1.1920929e-07. The measured pair of weights admits the current direction component at 102/110 angles for all five extents. For the remaining 8 angles, the nearest component consistent with all five pairs differs by one F32 unit in the last place. + +The two-axis [sample-coordinate measurements](#direction-and-sample-coordinates-of-long-oblique-blurs) also constrain changes in how the slope is calculated. Compare the existing projection components, their ratio after scaling by the extent, and the component inferred from the independent impulse. For the front and reverse passes, count disagreements with the observed one-part-in-256 texel coordinates. The current division of the unit components and two rounded additions leaves 2,284 differing coordinates on the 13 starting geometries and 958 on four held-out radii. Dividing the scaled extents and fusing the first multiply-add leaves 727 and 1,019, respectively. The held-out inputs retain the documented slope differences. Both roots remain in progress. + +### Reopened Gaussian, polygon and weave pattern generators + +Compare the three whole procedural generators on revision `02d910f`. Include the archived defaults and changed settings from the [radial generator](#radial-stamp-profiles-and-pattern-generators), [polygon](#paper-brick-fiber-mesh-polygon-and-shape-roots) and [weave](#tile-weave-splatter-and-fiber-stage-comparisons) measurements, together with the 64² U8, U16, F16 and F32 controls. In the independent series use 16 × 32, 64 × 16, 32 × 64, 64², 128 × 64, 64 × 128 and 256 × 128. Set the graph seed to 686347 + 31i + 179j, with zero-based inventory index i and size index j. Leave the parameters at their defaults for j = 0 and 5. Render every size in U16 and F32. Also render U8 and F16 at j = 1, 3 and 6. Each root has 20 independent renders covering 189,440 pixels. + +At the five other sizes, apply the following controls. Tiling and nonsquare expansion apply to all three graphs, the 45-degree rotation applies to Weave, and the remaining controls apply to Polygon. + +| Size | Tiling / nonsquare | Rotate Weave 45° | Sides / scale / rotation in turns | Curve / gradient | Invert gradient / autoscale | +|---|---|---|---|---|---| +| 64 × 16 | 2 / on | off | 4 / .75 / .09375 | -.1875 / .859375 | off / on | +| 32 × 64 | 5 / off | on | 7 / 1.234375 / -.28125 | .296875 / .49609375 | on / off | +| 64 × 64 | 3 / on | off | 11 / .9375 / .15625 | 0 / .71875 | off / on | +| 128 × 64 | 1 / off | on | 3 / 1.453125 / -.0625 | .515625 / .33203125 | on / on | +| 256 × 128 | 2 / off | on | 5 / 1.09375 / -.203125 | .15625 / .6015625 | on / on | + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Pattern Gaussian 1 (363) | 38 | 46,080/46,080 · 0 | 179,712/179,712 · 0 | 46,080/46,080 · 0 | 88,832/88,832 · 0 | +| Pattern Polygon 2 (367) | 39 | 43,008/43,008 · 0 | 177,152/177,152 · 0 | 45,056/45,056 · 0 | 66,816/66,816 · 0 | +| Pattern Weave 1 (381) | 39 | 43,008/43,008 · 0 | 177,152/177,152 · 0 | 45,056/45,056 · 0 | 66,816/66,816 · 0 | + +Across all three original roots, **1,024,768/1,024,768** pixels match in 116 distinct root settings, maximum zero. Save each package with MaterialCraft and reopen in both applications for all 20 independent renders. Save each a second time, then repeat F32 at every size and U8, U16 and F16 at 64². All **775,680/775,680** reopened pixels match across applications and reproduce each respective original, with maximum zero across 90 renders. + +The earlier stage controls exercise each of the three polygon stamps in isolation and the weave branch with its authored shape or a substituted disc. The grayscale-source row measures the downstream polygon graph with original grayscale inputs. + +| Stage comparison | Renders | Exact pixels / compared | Maximum stored error | +|---|---:|---:|---:| +| Polygon, authored stamps | 27 | 25,344/25,344 | 0 | +| Polygon, square and disc | 54 | 50,688/50,688 | 0 | +| Polygon, substituted grayscale source | 10 | 10,496/10,496 | 0 | +| Weave, authored stamp and disc | 12 | 2,816/2,816 | 0 | + +### Reopened Perlin, scratches, shape and weave generators + +Compare the six whole generators on revision `02d910f`. Include the [earlier ten-case procedural stage matrix](#tile-weave-splatter-and-fiber-stage-comparisons), the [Weave 4 sweep](#plane-light-splatter-symmetry-and-waveform-comparisons), the archived roots and the four 64² output formats. The independent series uses the [seven image sizes, four output formats and seed formula](#reopened-gaussian-polygon-and-weave-pattern-generators) from the pattern-generator comparison. Each graph supplies its own procedural input. Use defaults at 16 × 32 and 64 × 128. At the other five sizes use the controls below. Scratches 4 exposes no graph controls and uses each size and seed with its published defaults. + +| Root | Parameter | 64 × 16 | 32 × 64 | 64² | 128 × 64 | 256 × 128 | +|---|---|---:|---:|---:|---:|---:| +| Perlin Noise Zoom | Distance | 3 | 13 | 7 | 17 | 9 | +| Perlin Noise Zoom | Disorder | 15.9375 | 57.109375 | 31.875 | 75.703125 | 45.15625 | +| Scratches 1 | Pattern_size_width | 89.5 | 120.5 | 101.5 | 134.5 | 111.5 | +| Scratches 1 | Pattern_size_height | 131.3125 | 86.265625 | 113.875 | 65.921875 | 99.34375 | +| Scratches 1 | Rotation_Var | 17.4375 | 39.234375 | 25.875 | 49.078125 | 32.90625 | +| Scratches 1 | Disorder | 0.1875 | 0.671875 | 0.375 | 0.890625 | 0.53125 | +| Scratches 1 | Rotation | 27.0625 | 63.390625 | 41.125 | 79.796875 | 52.84375 | +| Shape Base | pattern | 3 | 11 | 7 | 1 | 8 | +| Shape Base | pattern_specific | 0.1875 | 0.671875 | 0.375 | 0.890625 | 0.53125 | +| Shape Base | scale | 0.7109375 | 1.01367188 | 0.828125 | 1.15039062 | 0.92578125 | +| Shape Base | size_xy | (0.828125, 1.1328125) | (1.19140625, 0.830078125) | (0.96875, 1.015625) | (1.35546875, 0.693359375) | (1.0859375, 0.91796875) | +| Shape Base | angle | 0.09375 | -0.28125 | 0.15625 | -0.0625 | -0.203125 | +| Weave 1 | Tiling | 2 | 5 | 3 | 1 | 2 | +| Weave 1 | Rotate_45_Degrees | off | on | off | on | on | +| Weave 4 | Tiling | 2 | 5 | 3 | 1 | 2 | +| Weave 4 | Rotation | off | on | off | on | on | + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Perlin Noise Zoom (418) | 39 | 43,008/43,008 · 0 | 177,152/177,152 · 0 | 45,056/45,056 · 0 | 66,816/66,816 · 0 | +| Scratches 1 (463) | 39 | 43,008/43,008 · 0 | 177,152/177,152 · 0 | 45,056/45,056 · 0 | 66,816/66,816 · 0 | +| Scratches 4 (465) | 38 | 43,008/43,008 · 0 | 160,768/160,768 · 0 | 45,056/45,056 · 0 | 66,816/66,816 · 0 | +| Shape Base (466) | 39 | 43,008/43,008 · 0 | 177,152/177,152 · 0 | 45,056/45,056 · 0 | 66,816/66,816 · 0 | +| Weave 1 (537) | 39 | 43,008/43,008 · 0 | 177,152/177,152 · 0 | 45,056/45,056 · 0 | 66,816/66,816 · 0 | +| Weave 4 (540) | 38 | 46,080/46,080 · 0 | 179,712/179,712 · 0 | 46,080/46,080 · 0 | 88,832/88,832 · 0 | + +The six whole roots matched **2,004,480/2,004,480** pixels across 232 distinct settings, maximum zero. Save each graph in MaterialCraft, then reopen it in both applications for the 20 independent renders. Save each a second time and compare F32 at all seven sizes plus U8, U16 and F16 at 64². Each root matched 258,560/258,560 reopened pixels. All **1,551,360/1,551,360** pixels across the 180 reopened renders matched across applications and reproduced their respective originals, maximum zero. + +The reduced controls revisit the branch that first differed in the original comparison. Retain the original shape or substitute a disc, using the earlier six settings and graph wiring. For Shape Base, serialize the isolated single-quadrant graph before comparison. Both Shape Base branches also matched 9,728/9,728 pixels across 12 renders after a second save and reopen. + +| Reduced branch | Renders | Exact pixels / compared | Maximum stored error | +|---|---:|---:|---:| +| Perlin Noise Zoom, authored shape and disc | 12 | 9,728/9,728 | 0 | +| Scratches 1, authored shape and disc | 12 | 9,728/9,728 | 0 | +| Scratches 4, authored shape and disc | 12 | 9,728/9,728 | 0 | +| Shape Base, authored shape and disc | 12 | 9,728/9,728 | 0 | +| Weave 1, authored shape and disc | 12 | 2,816/2,816 | 0 | + +### Distance propagation on rectangular and tied cellular fields + +Recheck the [earlier 59 settings and the relative dependency for the second root](#original-and-reopened-dirt-moisture-and-cellular-noise-fields), then add 20 settings per root. Use widths and heights 32 × 16, 16 × 128, 64 × 32, 128 × 256, 128², 256 × 64 and 32². With zero-based inventory index i and size index j, use seed S = 689287 + 19i + 239j. At j = 0 and 4 leave the controls at their defaults and leave the input disconnected. At the other sizes connect the original F32 gray field .75((61x + 103y + 11xy + S) mod 349)/348 + .25[(3x + 5y + S) mod 17 < 6]. Use F32 and U16 at every size, with U8 and F16 also at j = 1, 2 and 5. The speed control belongs to Cells 4 v2. + +| Size | Scale | Disorder | Speed | Color source | Pseudo-random seed | Nonsquare expansion | +|---|---:|---:|---:|---:|---:|---| +| 16 × 128 | 7 | 0.078125 | 0.59375 | 1 | 337 | on | +| 64 × 32 | 11 | 0.734375 | 1.125 | 2 | 271 | off | +| 128 × 256 | 18 | 0.40625 | 0.8125 | 0 | 89 | on | +| 256 × 64 | 5 | 0.90625 | 1.5625 | 1 | 613 | off | +| 32 × 32 | 23 | 0.171875 | 0.4375 | 2 | 719 | on | + +Before the Distance changes, revision `02d910f` matched 934,490/1,028,608 pixels for Cells 4 and 935,072/1,028,608 for v2. The maximum absolute stored-channel errors were 64,479 and 64,522 integer levels. The corrected whole-root results follow. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Cells 4 (242) | 79 | 111,872/111,872 · 0 | 433,920/433,920 · 0 | 111,872/111,872 · 0 | 370,944/370,944 · 0 | +| Cells 4 v2 (243) | 79 | 226,560/226,560 · 0 | 319,232/319,232 · 0 | 111,872/111,872 · 0 | 370,944/370,944 · 0 | + +Save the first root with MaterialCraft and reopen it in both applications. For v2 keep the [compatible hash helper at the measured relative path](#original-and-reopened-dirt-moisture-and-cellular-noise-fields). The first save repeats all 30 earlier settings and all 20 independent settings. On the second save repeat F32 at all seven independent sizes and all formats at 64 × 32. The earlier 30-setting series also includes a second save for v2. + +| Root | Reopened renders | Exact pixels / compared | Maximum error | +|---|---:|---:|---:| +| Cells 4 | 60 | 890,368/890,368 | 0 | +| Cells 4 v2 | 90 | 1,520,128/1,520,128 | 0 | + +Both applications reproduced their respective original buffers in every saved case. Across applications the two intact roots match **2,057,216/2,057,216** pixels across 158 distinct root settings, and **2,410,496/2,410,496** across 150 reopened renders. All maxima are zero. + +Both roots contain two Distance nodes. Pixel ratio 0 scales each texel displacement by min(W,H)/axis length. Pixel ratio 1 uses texel distances directly. A source texel at index i has a stored coordinate given by the nearest even integer to (i + .5)65535/N on an axis of length N. Decode that word before subtracting the pixel center. A wrapped axis uses the image midpoint as its origin during subtraction. At 512 × 32, a site at (1,30) and strength 87.625 gives F32 word `3f68a0de` one texel to the right with horizontal wrapping and `3f68a0d2` with that axis open. Vertical wrapping alone leaves the latter word intact. + +The propagation step covers the same fraction of each axis. For a step of j texels on the longest side L, point sampling on an axis of length N addresses offsets floor(.5 − jN/L) and floor(.5 + jN/L). Equal-distance candidates retain the current site. Among new candidates the observed priority is right, left, down, up, lower right, upper left, upper right and lower left. Rows increase downwards. With both axes open the final one-texel refinement remains in use. + +For a small Euclidean example, tile a 32 × 16 mask with sites (9,13), (21,5) and (7,1). Give them source values .125, .25 and .375 with .0625 elsewhere, set strength 256, choose ratio 1 and disable Combine. The value at (31,10) is .125. For a tie test at 32² set the mask where x and y are both multiples of three or (x + 2y) mod 7 equals 3. Give each source texel value (1 + x + 32y)/1024. At strength 256 the Manhattan result at (30,8) selects (29,8). With Chebyshev distance, (14,0) selects (15,0) and (19,0) selects (18,0). + +For the dense-mask series use the size, metric and tiling combinations (32², Euclidean, both), (64 × 16, Euclidean, both), (16 × 32, Euclidean, both), (32², Euclidean, neither), (32², Manhattan, both), (32², Chebyshev, both), (64 × 32, Euclidean, horizontal) and (32 × 64, Euclidean, vertical). Number them g = 0–7. For setting t = 0–5 use seed S = 711709 + 19g + 109t and strength 256, 206.5, 95.75, 256, 133.25 or 78.5 respectively. Set the mask where (17x + 31y + 5xy + S) mod 251 is below 64, 107, 144 or 193 at t = 0, 1, 2 or 5. At t = 3 use the lattice from the tie test. At t = 4 require x mod 2 = y mod 2 and (x + y) mod 3 different from zero. Use source (1 + x + Wy)/(WH) with Combine disabled. + +| Direct comparison | Renders | Exact pixels / compared | Maximum stored error | +|---|---:|---:|---:| +| Sparse two- to five-site sources, both axes tiled | 48 | 55,296/55,296 | 0 | +| Same sparse sources with one or both axes open | 144 | 165,888/165,888 | 0 | +| Six dense masks on eight combinations of size, tiling and metric | 48 | 58,368/58,368 | 0 | +| Symmetric sparse sites on four tiled squares | 52 | 282,880/282,880 | 0 | +| Symmetric sites with one or both axes open | 78 | 199,636/199,680 | 0.125 | +| Identical isolated sites across all four tiling modes | 36 | 1,966,080/1,966,080 | 0 | +| Center, adjacent and off-center sites in seven image sizes | 49 | 1,777,664/1,777,664 | 0 | + +Both internal Distance outputs also matched 1,135,616/1,135,616 pixels in 60 intermediate renders across the original, independent and earlier differing root settings. The sparse open-axis comparisons retain the differences listed above. Each regression reproduced its original failure. The release node suite ran with the committed resource fixtures. Formatting, strict all-target workspace Clippy, the dependency-layer check and WebAssembly passed. + +### Modifying a 256-entry color palette + +The Modify Color Palette subgraph (439) writes 256 × 1 RGBA entries at every requested parent size. Revision `02d910f` reproduces all 256 entries, including the two formerly differing F32 values, in the [128² modular palette and ID test](#height-distance-texture-mapping-skew-and-weave). Repeat the archived defaults, seed 42, changed controls, signed, thin, repeated and four-format inputs and the two independent series below. Compare complete stored RGBA entries. + +For the seven-size series use 16², 64 × 32, 32 × 128, 64², 128 × 32, 16 × 64 and 128² in that order. For zero-based inventory index i and size index j use seed S = 703113 + 41i + 211j. Render U16 and F32 at every size, plus U8 and F16 at j = 1, 3 and 6. At j = 0 leave inputs disconnected. At j = 5 use 32 × 16 source images and the default graph parameters. At the other sizes match the input dimensions to the parent and apply the settings in the table. At j = 3 wire only the palette. + +For the palette use the following original F32 modular field. Number the image inputs alphabetically from m = 0 and channels from k = 0. Set A = ((29+11k+3m)x + (73+7k+5m)y + (5+2k)xy + S + 37m + 43k) mod 257. Set B to one where (5x + 3y + 7k + S + 17m) mod 19 < 7 and zero elsewhere. Write .6875A/256 + .3125B. Here the palette is input m = 1. The grayscale ID field is ((11x+17y+S) mod 16)/15. + +| Parent size | color_selection_mode | color_position | color_index | color_selection_spread | color_selection_contrast | distance_color_space | mode | opacity | override_color | hsl | +|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:| +| 64 × 32 | 0 | (0.2578125, 0.736328125) | 2 | 0.107421875 | 0.0859375 | 0 | 0 | 0.4609375 | (0.1875, 0.171875, 0.828125) | (-0.08203125, -0.04296875, 0.04296875) | +| 32 × 128 | 1 | (0.46875, 0.47265625) | 6 | 0.37109375 | 0.296875 | 1 | 1 | 0.671875 | (0.1875, 0.59375, 0.40625) | (0.05859375, -0.1484375, 0.1484375) | +| 64 × 64 | 0 | (0.34375, 0.62890625) | 4 | 0.21484375 | 0.171875 | 0 | 2 | 0.546875 | (0.1875, 0.34375, 0.65625) | (0.029296875, -0.0859375, 0.0859375) | +| 128 × 32 | 1 | (0.5859375, 0.326171875) | 8 | 0.517578125 | 0.4140625 | 1 | 0 | 0.7890625 | (0.1875, 0.828125, 0.171875) | (-0.12890625, -0.20703125, 0.20703125) | +| 128 × 128 | 1 | (0.515625, 0.4140625) | 5 | 0.4296875 | 0.34375 | 1 | 2 | 0.71875 | (0.1875, 0.6875, 0.3125) | (0.114257812, -0.171875, 0.171875) | + +For the second series keep both inputs fixed at 64 × 32. Set t = (floor(x/8) + 3floor(y/8) + floor((x+2y)/11)) mod 8. The RGB channels are ((83t+19) mod 251)/250, ((47t+91) mod 241)/240 and ((109t+11) mod 239)/238. Alpha is ((5x+13y+57) mod 127)/126 and ID is ((3x+7y+5) mod 16)/15. Use default parameters for setting 0 and the eight rows below in order. Use seed 733458 + setting index. Render all nine in F32 and add U8, U16 and F16 at settings 2 and 6. + +| Setting | color_selection_mode | color_position | color_index | color_selection_spread | color_selection_contrast | distance_color_space | mode | opacity | override_color | hsl | +|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:| +| 1 | 0 | (0.203125, 0.765625) | 5 | 0.28125 | 0.78125 | 0 | 0 | 1 | (0.09375, 0.734375, 0.90625) | (-0.1875, 0.3125, -0.15625) | +| 2 | 1 | (0.828125, 0.765625) | 9 | 0.625 | 0 | 0 | 0 | 0.765625 | (0.09375, 0.734375, 0.90625) | (-0.1875, 0.3125, -0.15625) | +| 3 | 0 | (0.203125, 0.765625) | 0 | 0 | 0.3125 | 1 | 0 | 0.421875 | (0.09375, 0.734375, 0.90625) | (-0.1875, 0.3125, -0.15625) | +| 4 | 1 | (0.828125, 0.765625) | 3 | 0.28125 | 0.78125 | 1 | 1 | 1 | (0.09375, 0.734375, 0.90625) | (-0.1875, 0.3125, -0.15625) | +| 5 | 0 | (0.203125, 0.765625) | 5 | 0.625 | 0 | 1 | 1 | 0.765625 | (0.09375, 0.734375, 0.90625) | (-0.1875, 0.3125, -0.15625) | +| 6 | 1 | (0.828125, 0.765625) | 9 | 0 | 0.3125 | 0 | 1 | 0.421875 | (0.09375, 0.734375, 0.90625) | (-0.1875, 0.3125, -0.15625) | +| 7 | 0 | (0.203125, 0.765625) | 0 | 0.28125 | 0.78125 | 0 | 2 | 1 | (0.09375, 0.734375, 0.90625) | (-0.1875, 0.3125, -0.15625) | +| 8 | 1 | (0.828125, 0.765625) | 3 | 0.625 | 0 | 0 | 2 | 0.765625 | (0.09375, 0.734375, 0.90625) | (-0.1875, 0.3125, -0.15625) | + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Modify Color Palette (439) | 59 | 2,048/2,048 · 0 | 3,072/3,072 · 0 | 2,048/2,048 · 0 | 7,936/7,936 · 0 | + +Across the 59 distinct whole-root settings all **15,104/15,104** palette entries matched, maximum zero. With the second input pair held fixed, 460 entries across the eight changed F32 settings differed from the default output. Save the package in MaterialCraft and reopen it in both applications for all 20 seven-size renders and all 15 fixed-input renders. Save it a second time and repeat F32 at all seven sizes plus U8, U16 and F16 at 64². All **11,520/11,520** entries matched across the 45 reopened renders, maximum zero. Each application also reproduced its own original buffers. + +### Reopened starburst, symmetry, tile and waveform graphs + +Repeat the original whole-graph measurements for the six roots on revision `02d910f`, including the archived defaults, stage controls and four 64² output formats. Count a pixel when every stored channel matches. The first independent series uses the [seven dimensions, formats, modular field and seed formula](#modifying-a-256-entry-color-palette) from the palette comparison. Use the modular field for every image input with its declared gray or RGBA channels. Use graph defaults at 16² and 16 × 64, with inputs disconnected at 16² and a 32 × 16 source for every input at 16 × 64. At 64² connect only the second alphabetical image pin when there are multiple pins, or the sole pin otherwise. At the remaining sizes connect every pin. Use the controls below in the same order for both tile generators. + +| Root | Control | 64 × 32 | 32 × 128 | 64² | 128 × 32 | 128² | +|---|---|---:|---:|---:|---:|---:| +| Starburst | Branches | 7 | 11 | 9 | 13 | 10 | +| Starburst | BlurAmount | 1.515625 | 2.78125 | 2.03125 | 3.484375 | 3.0625 | +| Starburst | Randomness | 0.171875 | 0.59375 | 0.34375 | 0.828125 | 0.6875 | +| Starburst | SizeMin | 0.10546875 | 0.2109375 | 0.1484375 | 0.26953125 | 0.234375 | +| Starburst | SizeMax | 0.967773438 | 0.888671875 | 0.935546875 | 0.844726562 | 0.87109375 | +| Starburst | SizeVariation | 0.0859375 | 0.296875 | 0.171875 | 0.4140625 | 0.34375 | +| Starburst | Tiling | 1 | 2 | 3 | 1 | 3 | +| Symmetry Slice | Symmetry_Mode | 0 | 1 | 2 | 0 | 2 | +| Symmetry Slice | Transfer_Mode | 0 | 1 | 0 | 1 | 1 | +| Symmetry Slice | Blend | 0.171875 | 0.59375 | 0.34375 | 0.828125 | 0.6875 | +| Symmetry Slice | Flip_Side | on | off | on | off | off | +| Symmetry Slice | Flip_Side2 | off | on | off | off | off | +| Both tile generators | Nb_X | 3 | 7 | 5 | 9 | 6 | +| Both tile generators | Nb_Y | 2 | 3 | 4 | 5 | 3 | +| Both tile generators | Scale | 0.794921875 | 1.05859375 | 0.90234375 | 1.20507812 | 1.1171875 | +| Both tile generators | ScaleVariation | 0.064453125 | 0.22265625 | 0.12890625 | 0.310546875 | 0.2578125 | +| Both tile generators | Offset | -0.21875 | 0.15625 | 0.078125 | -0.34375 | 0.3046875 | +| Both tile generators | Pattern_Type | 1 | 3 | 6 | 1 | 9 | +| Both tile generators | image_input_filtering | 0 | 1 | 2 | 0 | 2 | +| Both tile generators | Free_Rotation | -0.21875 | 0.15625 | 0.078125 | -0.34375 | 0.3046875 | +| Both tile generators | Position_Random | (0.0537109375, 0.0268554688) | (0.185546875, 0.0927734375) | (0.107421875, 0.0537109375) | (0.258789062, 0.129394531) | (0.21484375, 0.107421875) | +| Both tile generators | GlobalOpacity | 0.626953125 | 0.78515625 | 0.69140625 | 0.873046875 | 0.8203125 | +| Waveform v2 | samples | 24 | 56 | 40 | 72 | 48 | +| Waveform v2 | function | 0 | 1 | 2 | 0 | 2 | +| Waveform v2 | roughness | 0.171875 | 0.59375 | 0.34375 | 0.828125 | 0.6875 | +| Waveform v2 | scale | 3 | 7 | 5 | 9 | 6 | +| Waveform v2 | amplitude_min | 0.125976562 | 0.205078125 | 0.158203125 | 0.249023438 | 0.22265625 | +| Waveform v2 | amplitude_max | 0.978515625 | 0.92578125 | 0.95703125 | 0.896484375 | 0.9140625 | +| Waveform v2 | noise | 0.0859375 | 0.296875 | 0.171875 | 0.4140625 | 0.34375 | +| Waveform v2 | pattern | 1 | 3 | 6 | 5 | 4 | +| Waveform v2 | pattern_variation | 0.12890625 | 0.4453125 | 0.2578125 | 0.62109375 | 0.515625 | +| Waveform v2 | disorder | 0.171875 | 0.59375 | 0.34375 | 0.828125 | 0.6875 | +| Waveform v2 | disorder_speed | 0.53515625 | 0.8515625 | 0.6640625 | 1.02734375 | 0.921875 | +| Waveform 1 | Samples | 24 | 56 | 40 | 72 | 48 | +| Waveform 1 | SizeMin | 0.07421875 | 0.1796875 | 0.1171875 | 0.23828125 | 0.203125 | +| Waveform 1 | SizeMax | 0.947265625 | 0.89453125 | 0.92578125 | 0.865234375 | 0.8828125 | +| Waveform 1 | WaveNumber | 3 | 7 | 5 | 9 | 6 | +| Waveform 1 | Noise | 0.171875 | 0.59375 | 0.34375 | 0.828125 | 0.6875 | +| Waveform 1 | Pattern | 1 | 3 | 6 | 5 | 4 | + +For the second series keep the source fields fixed. Use W × H = 64 × 32 for odd inventory indices and 32 × 64 for even indices. Number image pins m alphabetically from zero and channels a from zero. Define S = 744019 + 47i for inventory index i. Set A to ((17+2a)x + (43+6a)y + 5xy + S + 29m + 89a) mod 257. Set B to one where (3x+11y+7a) mod 13 < 4 and zero elsewhere. Write .75A/256 + .25B in F32, setting the pixel at x = (floor(W/2)+3a) mod W and y = floor(H/3) to one in each channel. Connect every declared image input throughout. + +Render defaults at seeds 0 and 42. At seed 42 change one control at a time in the order below. Then swap the output width and height while keeping the original source dimensions. Render defaults at seed 42 and a final combined setting at seed S. For the combined setting use the last tested value of each control. Compare F32 at all ten settings. Add U8, U16 and F16 for the original seed-42 default and the final combined setting. + +| Root | Individual settings in order | +|---|---| +| Starburst | `Branches` = 5, `Branches` = 17, `BlurAmount` = 0.5, `Randomness` = 0.875, `SizeMin` = 0.1875, `Tiling` = 3 | +| Symmetry Slice | `Symmetry_Mode` = 1, `Symmetry_Mode` = 2, `Transfer_Mode` = 1, `Blend` = 0.625, `Flip_Side` = on, `Flip_Side2` = on | +| Both tile generators | `Nb_X` = 5, `Nb_Y` = 3, `Pattern_Type` = 1, `Pattern_Type` = 7, `Free_Rotation` = 0.1875, `image_input_filtering` = 2 | +| Waveform v2 | `samples` = 48, `function` = 2, `roughness` = 0.3125, `pattern` = 7, `disorder` = 0.8125, `disorder_speed` = 0.4375 | +| Waveform 1 | `Samples` = 48, `SizeMin` = 0.21875, `SizeMax` = 0.6875, `WaveNumber` = 5, `Noise` = 0.5625, `Pattern` = 7 | + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Starburst (509) | 55 | 31,744/31,744 · 0 | 156,416/156,416 · 0 | 33,792/33,792 · 0 | 62,464/62,464 · 0 | +| Symmetry Slice (516) | 54 | 149,504/149,504 · 0 | 44,288/44,288 · 0 | 34,816/34,816 · 0 | 84,480/84,480 · 0 | +| Tile Generator (520) | 55 | 31,744/31,744 · 0 | 156,416/156,416 · 0 | 33,792/33,792 · 0 | 62,464/62,464 · 0 | +| Tile Generator Color (521) | 55 | 31,744/31,744 · 0 | 156,416/156,416 · 0 | 33,792/33,792 · 0 | 62,464/62,464 · 0 | +| Waveform v2 (535) | 54 | 149,504/149,504 · 0 | 44,288/44,288 · 0 | 34,816/34,816 · 0 | 84,480/84,480 · 0 | +| Waveform 1 (536) | 54 | 34,816/34,816 · 0 | 158,976/158,976 · 0 | 34,816/34,816 · 0 | 84,480/84,480 · 0 | + +Across 327 distinct settings the six roots matched **1,792,512/1,792,512** pixels, maximum zero. Save each graph in MaterialCraft and reopen it in both applications. Repeat the complete seven-size series, then save a second time and repeat F32 at all seven sizes plus U8, U16 and F16 at 64². For the fixed-field series repeat all ten F32 settings plus U8, U16 and F16 at the final combined setting after a save. Starburst, Symmetry Slice, both tile generators and Waveform 1 each matched 179,968/179,968 reopened pixels. Across their 215 reopened renders, **899,840/899,840** pixels matched across applications and reproduced the respective original buffers, maximum zero. + +Waveform v2 remains in progress. Its original 54 settings matched 313,088/313,088 pixels. Its 43 saved renders matched **167,194/179,968** across applications. In the disconnected 16² default, 158/256 pixels matched after a save in both U16 and F32, with maxima 65,535 and 1 respectively. MaterialCraft reproduced every one of its original buffers. In the reference app the first save changed six of the 20 seven-size renders and seven of the 13 fixed-field renders. Both applications reproduced their own first-save outputs after a second save in the ten repeated settings. + +For the previously isolated pattern branches, repeat the [authored shape and disc comparison](#tile-weave-splatter-and-fiber-stage-comparisons) on the same revision. Starburst matched 2,816/2,816 pixels. Both tile generators matched 9,728/9,728 each. Each pair of branches spans 12 renders, maximum zero. + +### Independent rectangular directional weights at 96 angles + +Extend the [110-angle projection comparison](#directional-blur-weights-across-110-angles-and-two-projection-axes) with an original graph containing 16 parallel directional filters per batch. Use F32 RGB inputs. Red is one on the center column, green is one on the center row, and both are zero elsewhere. Blue is ((43x+83y+5xy+631739) mod 257)/256. Render 16 × 64 and 64 × 16, keeping the input dimensions equal to the output. At each size use projected extents E = .3125, .5, .734375, .953125 and 1, with intensity 4(E+.5). Use seed 723371 + 17b + 5j + k, with batch b, size j and extent k numbered from zero. Each parallel branch has one of the following angles in turns, written as an integer divided by 65536. + +| Batch | Rotation numerators | +|---:|---| +| 0 | 3072, 5888, 13312, 16346, 5184, -25536, 8192, 2048, -80877, 71395, -2101, 90555, -33773, 30203, -19725, -76869 | +| 1 | 69387, -76749, 79499, -57381, -24789, 39659, -87589, -27805, -49485, 59227, 44371, 85075, 23059, -42893, 95227, 55107 | +| 2 | -55373, -8709, 41123, -51389, 45515, -60045, -88645, 7699, -7213, -95869, 5083, -20021, 21763, 69371, 2011, 26227 | +| 3 | 1107, 6819, 43435, -13781, -13413, 14307, 79835, 67699, -71461, -11597, -86909, 37827, 96955, 83763, -15501, -32773 | +| 4 | 62099, -48677, -42773, -5733, 21755, -77061, 79883, -3117, 34819, 87955, 67979, -30597, -24501, 78011, 42163, 42563 | +| 5 | -84757, 53675, -70437, 81203, 15603, -94477, 82307, -39221, 12667, 97387, 51355, 23635, 70707, -76389, -54429, -56853 | + +The earlier center-and-neighbor coefficient test gives a nonempty interval for every axis. The current projected coefficient satisfies the observed F32 rounding bounds on 178/192 axes. The full RGB comparison includes the modular blue field and compares all three components together. + +| Size | Extent | Branch renders | Exact pixels / compared | Maximum F32 error | +|---|---:|---:|---:|---:| +| 16 × 64 | 0.3125 | 96 | 92,617/98,304 | 1.1920929e-07 | +| 16 × 64 | 0.5 | 96 | 92,990/98,304 | 1.1920929e-07 | +| 16 × 64 | 0.734375 | 96 | 94,126/98,304 | 1.78813934e-07 | +| 16 × 64 | 0.953125 | 96 | 94,662/98,304 | 1.1920929e-07 | +| 16 × 64 | 1 | 96 | 91,300/98,304 | 1.1920929e-07 | +| 64 × 16 | 0.3125 | 96 | 95,530/98,304 | 1.1920929e-07 | +| 64 × 16 | 0.5 | 96 | 95,941/98,304 | 1.1920929e-07 | +| 64 × 16 | 0.734375 | 96 | 96,211/98,304 | 1.1920929e-07 | +| 64 × 16 | 0.953125 | 96 | 94,853/98,304 | 1.1920929e-07 | +| 64 × 16 | 1 | 96 | 95,702/98,304 | 1.1920929e-07 | + +The 960 original branch renders matched **943,932/983,040** pixels, maximum 1.78813934e-07. Save each graph in MaterialCraft, reopen it in both applications, and repeat the first and last extent at both sizes. Across the 384 reopened branch renders, **375,149/393,216** pixels matched across applications, maximum 1.1920929e-07. Each application reproduced every pixel of its own original outputs. The color and grayscale HQ blur roots remain in progress with their previous 78-setting whole-root counts. + +### Repeated wood fiber renders and isolated drawing depths + +On revision `02d910f`, compare Wood Fibers 1 on the [original stage settings](#tile-weave-splatter-and-fiber-stage-comparisons) and the [seven dimensions, formats and seeds](#reopened-gaussian-polygon-and-weave-pattern-generators) used for the other procedural generators. The root has no image pins. At 64 × 16, 32 × 64, 64², 128 × 64 and 256 × 128, set Disorder to .1875, .671875, .375, .890625 and .53125 respectively. Use defaults at 16 × 32 and 64 × 128. The table gives one reference render per original setting. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Wood Fibers 1 (544) | 39 | 43,007/43,008 · 1 | 176,702/177,152 · 2 | 45,048/45,056 · 0.00048828125 | 66,664/66,816 · 1.94907188e-05 | + +Across 39 distinct original settings **331,421/332,032** pixels matched. Save the package in MaterialCraft and reopen it in both applications. Compare all 20 seven-size renders after the first save and F32 at all seven sizes plus U8, U16 and F16 at 64² after a second save. Across the 30 reopened renders, **258,128/258,560** pixels matched across applications, maximum two stored integer levels. MaterialCraft reproduced every original buffer. In the reference app 219 pixels changed from the original to the first save across 20 renders and 111 from the first to the second across ten. Repeated renders of the same original package also varied. + +Render each of the following nine original settings five times. Number the settings from zero and rotate their execution order by the run index, reversing that order on odd runs. Compare the five stored outputs from the reference app with one MaterialCraft render. A varying pixel changes between reference renders. A stable difference is a pixel that all five reference renders agree on and that differs from MaterialCraft. The two columns are disjoint. + +| Width × height | Seed | Disorder | Output | Varying / stable differences in first pattern | Varying / stable differences in final output | Final exact pixels across five runs (min–max) | Largest error | +|---|---:|---:|---|---:|---:|---:|---:| +| 256 × 256 | 0 | Default | LUM16 | 256 / 57 | 240 / 57 | 65,361–65,379 / 65,536 | 2 | +| 128 × 128 | 0 | Default | LUM16 | 75 / 15 | 72 / 14 | 16,337–16,341 / 16,384 | 2 | +| 32 × 32 | 117089 | 0.375 | LUM32F | 6 / 2 | 8 / 3 | 1,016–1,021 / 1,024 | 1.94907188e-05 | +| 256 × 128 | 704285 | 0.53125 | LUM16 | 119 / 20 | 116 / 21 | 32,690–32,713 / 32,768 | 2 | +| 256 × 128 | 704285 | 0.53125 | LUM32F | 118 / 26 | 121 / 26 | 32,688–32,709 / 32,768 | 1.85966492e-05 | +| 128 × 64 | 703927 | 0.890625 | LUM16 | 35 / 13 | 41 / 8 | 8,163–8,169 / 8,192 | 2 | +| 128 × 64 | 703927 | 0.890625 | LUM32F | 39 / 11 | 40 / 9 | 8,160–8,170 / 8,192 | 1.94907188e-05 | +| 64 × 128 | 704106 | Default | LUM16 | 34 / 4 | 27 / 8 | 8,171–8,175 / 8,192 | 2 | +| 64 × 128 | 704106 | Default | LUM32F | 30 / 4 | 35 / 4 | 8,169–8,181 / 8,192 | 1.87754631e-05 | + +For the drawing-depth controls, keep traversal, connections and expressions that supply the stamp values. Replace only the shape of each omitted depth with the empty shape. Read the pattern output directly at the requested precision. Use 32²/117089, 32 × 16/117093, 64 × 32/730713 and 64²/730757, where the second number is the seed. Use Disorder .375, .8125, .171875 and .671875 respectively. Render U16 and F32 for each size. + +| Drawing depths | U16 exact / total · maximum | F32 exact / total · maximum | +|---|---:|---:| +| 1–9 | 7,657/7,680 · 1 | 2,510/7,680 · 2.98023224e-07 | +| 1–3 | 7,676/7,680 · 1 | 3,076/7,680 · 1.1920929e-07 | +| 1–5 | 7,668/7,680 · 1 | 2,616/7,680 · 1.78813934e-07 | +| 4 | 7,680/7,680 · 0 | 5,965/7,680 · 2.98023224e-08 | +| 5 | 7,680/7,680 · 0 | 6,050/7,680 · 2.98023224e-08 | +| 6 | 7,680/7,680 · 0 | 5,965/7,680 · 2.98023224e-08 | +| 6–9 | 7,677/7,680 · 1 | 3,661/7,680 · 8.94069672e-08 | +| 5–9 | 7,672/7,680 · 1 | 3,058/7,680 · 1.1920929e-07 | + +The individual depths 4, 5 and 6 each match all 7,680 U16 pixels. F32 distinguishes differences within each of those depths. At the 256² default final output, the five reference renders vary at 240 pixels and agree on 57 additional pixels that differ from MaterialCraft. Both effects remain open. + +### Diagonal mip selection on rotated rectangular bitmaps + +The first different stage of Radial Blur Grayscale was the automatic bitmap filter in its first pattern graph. A 32 × 64 modular-and-impulse input at default parameters gave 345/2,048 exact U16 pattern pixels, maximum 405 levels. The downstream blend gave 527/2,048, maximum 138 U16 levels. At the F32 output 527/2,048 matched, maximum .00210574269. The input and all three transformed fields already matched. + +Retain the graph’s original sample count and per-stamp opacity, limiting only the number of visits. With 64 samples, .125 turns and the center offset (0,0), the first 41 draws matched 2,048/2,048 pixels. Including the 42nd draw, rotated by 41/512 turns, matched 338/2,048 with maximum 404 U16 levels. With the new filter both prefixes and the complete draw match. A separate one-stamp graph reproduces the transition at either orientation of a 2:1 rectangle. At ±41/512 turns the reference automatic filter selects the same level as bilinear sampling. At 42/512 it selects a coarser level. + +For a 64 × 32 original byte image use ((17x+59y+9xy+7) mod 251) + 4[(x+3y) mod 7 < 3]. Use one full-size, centered grayscale bitmap stamp, tiling off, opacity one, and read F32 at (32,16). At rotations 40/512, 41/512, 42/512 and −41/512 the stored bits are `3f1aeb9b`, `3f1c699c`, `3f0eca8f` and `3effd300`. For the wider sweep use 32 × 64, 64 × 32, 64² and 32 × 128. At the first size use the matching byte output of the first transform in the modular-and-impulse graph. At the three other sizes replace 7 in the byte field with 7j, with j = 1, 2, 3. At all four sizes render turns (39,40,41,42,43)/512, 41/512 ± 2⁻¹⁵, 41/512 ± 2⁻¹², −41/512, 0, .125 and .25−41/512. Automatic and bilinear each match **159,744/159,744** F32 pixels across 52 settings. + +The [two-by-two pixel group](#automatic-bitmap-stamp-levels-at-neighboring-pixels) supplies the two screen derivatives in texels. Truncate each signed component to nine fraction bits. For each texture coordinate, align the two screen derivatives with one extra fraction bit at the larger exponent before taking their sum and difference. Evaluate both diagonals. Weight the larger magnitude by 11/16, add a quarter of its input unit and truncate to nine fraction bits at the resulting exponent. For the smaller magnitude with nine-bit integer significand m (including its implicit leading bit, scaled by 512), use floor((121m+32)/512) times its input unit. The maximum of both axial and both diagonal footprints selects the level at the existing half-level thresholds. + +Generate a mip chain with a constant value equal to its level number and read the selected level using explicit gradients. The three fixed regression matrices, written in texels divided by 2048, are ((1864,−2248),(1874,861)), ((1884,649),(1884,649)) and ((1814,−841),(−2192,−1450)). Their measured levels are 1, 0 and 0, respectively. In the independent dense series draw four F32 components uniformly from −1 to 1 with random seed 763451. Use 131,072 matrices in order. For the first 32,768 make the two screen derivatives equal, and for the next 32,768 make them opposites. For the following 16,384 set both second components to zero. For the next 16,384 set the second screen derivative to zero. Scale each matrix by 2ᵉ × 1.4140625 × u divided by its approximate unquantized footprint, with e a uniform integer from 0 through 6 and u uniform from .997 to 1.003. The unquantized footprint uses max + 11/32 min for each axis and 11/16 of that norm for both diagonals. + +| Graphics-device level choices | Exact before / compared | Exact now / compared | Maximum level error now | +|---|---:|---:|---:| +| Four derivative families from the earlier stress test | 64,127/65,536 | 65,536/65,536 | 0 | +| Independent near-threshold perturbations | 16,182/16,384 | 16,384/16,384 | 0 | +| Independent signed and collinear matrices | 124,877/131,072 | 131,072/131,072 | 0 | + +The 139 earlier automatic stamp settings retained 2,105,344/2,105,344 exact pixels and the independent 180-setting boundary series retained 2,457,600/2,457,600. All 506,880/506,880 stored pixels at the ten observed stages across 23 radial graph renders matched, maximum zero. + +For the whole root, repeat the archived defaults and controls, the four 64² formats, and the [seven-size modular input series](#modifying-a-256-entry-color-palette). At the five nondefault sizes in that series, use (samples, angle, center) in this order. Use (7,−.21875,(−.21875,.13671875)), (15,.15625,(.15625,−.09765625)), (11,.078125,(.078125,−.048828125)), (19,−.34375,(−.34375,.21484375)) and (13,.3046875,(.3046875,−.1904296875)). For the 32 × 64 modular-and-impulse field write 1 at (2,43), .625 at (18,2), and .3125 where x mod 13 = 0 and y mod 3 ≠ 0. Elsewhere write ((11x+29y+7xy) mod 241)/960. Use defaults, then (samples,angle) = (1,.375), (2,−.21875), (3,.25), (7,.28125), (11,−.1875), (16,.5625), (29,−.421875), (47,.15625). Use center (−.21875,.15625) for the first four changes and (.3125,−.09375) for the last four. Use seed 733460 plus the setting index and F32 throughout, with U8, U16 and F16 also measured at 2 and 16 samples. + +For the independent ten-size series below, use seed S = 763819 + 61j and a procedural F32 input. For source dimensions W × H write .5[((41x+59y+13xy+S) mod 257)/256] + .3125[(floor(x/5)+floor(y/7)) mod 2] + .1875[(3x+13y+S) mod 17 < 4]. Set the texel at x = (floor(W/3)+2y) mod W to one in every row. Use a 32 × 16 source at j = 4 and 7, and equal source and output dimensions elsewhere. Render U16 and F32 throughout, also U8 and F16 at j = 1, 6 and 9. + +| j | Output dimensions | Samples | Angle in turns | Center offset | +|---:|---|---:|---:|---| +| 0 | 16 × 32 | 64 | 0.125 | (0, 0) | +| 1 | 32 × 64 | 64 | -0.125 | (-0.1875, 0.28125) | +| 2 | 64 × 32 | 64 | 0.125 | (0.34375, -0.125) | +| 3 | 128 × 64 | 128 | -0.125 | (0, 0) | +| 4 | 64 × 128 | 48 | 0.15625 | (-0.1875, 0.28125) | +| 5 | 128 × 128 | 64 | 0.125 | (0, 0) | +| 6 | 128 × 256 | 128 | 0.125 | (0, 0) | +| 7 | 256 × 64 | 63 | 0.304688 | (-0.1875, 0.28125) | +| 8 | 32 × 16 | 65 | 0.125 | (0.34375, -0.125) | +| 9 | 64 × 256 | 97 | -0.421875 | (0, 0) | + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Radial Blur Grayscale (441) | 80 | 82,944/82,944 · 0 | 259,840/259,840 · 0 | 84,992/84,992 · 0 | 163,840/163,840 · 0 | + +All **591,616/591,616** pixels matched across 80 distinct whole-root settings. Save the seven-size graph and repeat all 20 renders. Save it a second time and repeat all seven F32 settings and the other three formats at 64². Reopen the modular-and-impulse graph for all 15 settings. Reopen the independent ten-size graph for all ten F32 outputs plus the other three formats at 128 × 256. All **385,792/385,792** pixels matched across 58 reopened renders, maximum zero. Each application reproduced all its original buffers. Both new regressions failed before the change and passed afterward. All 342 release node tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. Across seven alternating single-core release runs, median cook time for the default 32 × 64 field went from 168.7 to 166.5 ms. The 128 × 256 field at 128 samples went from 5038 to 5070 ms. + +### Waveform v2 with library and file-based hash functions + +Use the same 54 original settings and 43 saved renders as the [Waveform v2 comparison](#reopened-starburst-symmetry-tile-and-waveform-graphs), including seven output sizes, independent parameter edits, seeds and all four precisions. Original outputs matched **313,088/313,088** pixels across applications, maximum zero. The earlier saved-file comparison used relative links to the older local function packages. Repeat the handoff using each of the following dependency routes. In each row, open the saved file directly in both applications. + +| Hash function source used by the saved root | First save, 20 renders | Second save, 10 renders | Fixed-size and transposed series, 13 renders | Maximum error | +|---|---:|---:|---:|---:| +| Portable library reference | 109,056/109,056 | 44,288/44,288 | 26,624/26,624 | 0 | +| Relative reference to the separately saved function package | 109,056/109,056 | 44,288/44,288 | 26,624/26,624 | 0 | + +For the library route, open `sbs://waveform_01_v2.sbs` in MaterialCraft, use `file.saveAs` and reopen. The saved file links to `sbs://functions.sbs` and `sbs://functions_hash.sbs`. For the relative route, open the older local `functions_hash.sbs` in MaterialCraft and save that package separately. Point only the saved waveform’s hash dependency to this file with a relative path. Both routes reproduced every original pixel in each application and matched **179,968/179,968** pixels across applications on reopening. Retaining the original hash file on disk gave **167,194/179,968** across applications, maximum 65,535 U16 levels and 1 in F32. Switching only the general math dependency retained the 16² discrepancy. + +To isolate the hash function, create a one-output pixel processor calling `hash21`. Supply normalized pixel-center XY plus (a, .21875) to its `input`. Use 16² with a = 0, 64 × 16 with a = .3125 and 16 × 64 with a = −.4375. Apply seeds 775641, 775642 and 775643 in order. Render F32 at every size and U8, U16 and F16 at 64 × 16. Save just the caller and repeat all six renders in both applications. + +| Caller’s hash function | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Portable library reference | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 2,304/2,304 · 0 | +| Relative link to the older function file | 2/1,024 · 255 | 0/1,024 · 65495 | 0/1,024 · 0.999023438 | 1/2,304 · 0.999511719 | +| Relative link to the separately saved function file | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 2,304/2,304 · 0 | + +The table applies both before and after saving the caller. Each application reproduced its own six buffers after saving. With the older relative dependency, the reference returned zero throughout, and 3/5,376 pixels matched across applications on each run. The same caller matched 5,376/5,376 on each run with either the library function or the separately saved file. Waveform v2 remains in progress for the older relative dependency. + +### Isolated Arc Pavement draws in a nonunit render region + +Compare Arc Pavement (354) on revision `7ff64fa`. All 211,200 pixels in the earlier 27 whole-root settings now match. Add seven image sizes with defaults at 16² and 16 × 64, and changed settings at 64 × 32, 32 × 128, 64², 128 × 32 and 128². Use seed S = 717627 + 211j, indexing 16², 64 × 32, 32 × 128, 64², 128 × 32, 16 × 64 and 128² from zero. Leave the input disconnected at 16². At the other sizes connect a grayscale F32 field of the output size, except for a 32 × 16 source at 16 × 64. At coordinates x,y use .6875 × ((29x+73y+5xy+S) mod 257)/256 plus .3125 where (5x+3y+S) mod 19 < 7. Compare U16 and F32 at every size, adding U8 and F16 at 64 × 32, 64² and 128². + +| Changed setting | 64 × 32 | 32 × 128 | 64² | 128 × 32 | 128² | +|---|---:|---:|---:|---:|---:| +| `scale` | 1 | 2 | 3 | 1 | 3 | +| `pattern_amount` | 5 | 9 | 7 | 11 | 8 | +| `pattern_amount_random` | 0.171875 | 0.59375 | 0.34375 | 0.828125 | 0.6875 | +| `pattern_min_amount` | 1 | 2 | 3 | 1 | 3 | +| `arcs_amount` | 3 | 7 | 5 | 9 | 6 | +| `pattern` | 1 | 3 | 7 | 1 | 4 | +| `pattern_variation` | 0.171875 | 0.59375 | 0.34375 | 0.828125 | 0.6875 | +| `pattern_scale` | 0.6484375 | 0.859375 | 0.734375 | 0.9765625 | 0.90625 | +| `pattern_width` | 1.0390625 | 0.828125 | 0.953125 | 0.7109375 | 0.78125 | +| `pattern_height` | 0.47265625 | 0.7890625 | 0.6015625 | 0.96484375 | 0.859375 | +| `input_image_filtering` | 0 | 1 | 2 | 0 | 2 | +| `pattern_height_decrease` | 0.04296875 | 0.1484375 | 0.0859375 | 0.20703125 | 0.171875 | +| `color_random` | 0.171875 | 0.59375 | 0.34375 | 0.828125 | 0.6875 | +| `non_square_expansion` | on | off | on | off | off | + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Arc Pavement (354) | 47 | 30,720/30,720 · 0 | 155,891/155,904 · 1 | 30,710/30,720 · 0.00048828125 | 102,396/102,912 · 4.64916229e-06 | + +Across 47 distinct settings **319,717/320,256** pixels matched. Save the root in MaterialCraft and repeat all 20 seven-size renders. Save again and repeat F32 at every size, plus U8, U16 and F16 at 64². Across applications, **152,283/153,344** pixels matched after reopening, maximum one stored integer level. Both applications reproduced their own original buffers. + +At 64² and 128², retain the seven-size controls and seed, and vary just the shape selector from 0 through 9. In the bitmap setting (1), 4,095/4,096 and 16,383/16,384 F32 pixels match, with maximum errors .328675061 and .236963362 respectively. Setting scale, both pattern counts and arc count to 1, and amount randomness, color randomness and height decrease to zero, yields exact F32 buffers for all ten selectors at both sizes. + +Use an initialized draw counter to write each draw into a separate cell of a 256² F32 image. Capture the visit indicator, the two position offsets, the two sizes and the rotation on each of the two settings. The resulting twelve grids matched **786,432/786,432** pixels, maximum zero. + +For the paraboloid selector (4), isolate draws covering three differing pixels at each size. Keep each center, both dimensions and rotation, set the branch offset to (−.5,−.5), and draw one stamp at unit opacity. With render and tiling intervals [−1,2] on both axes, multiplying each reference stamp by its original opacity and taking the maximum reproduces the whole reference graph at (32,62), (32,63) and (32,3) at 64², and at the three 128² positions in the table. Repeat the individual draws with the horizontal ramp (10). For a unit-region control, map each center c to (c+1)/3 and each size s to s/3 in F32 and render on [0,1]². + +| Size | Paraboloid samples in whole root | Region | Paraboloid exact / total · max F32 | Horizontal ramp exact / total · max F32 | +|---|---|---|---:|---:| +| 64² | (32,62), (32,63), (32,3) | [−1,2] | 24,572/24,576 · 3.39746475e-06 | 24,571/24,576 · 1.40070915e-06 | +| 64² | (32,62), (32,63), (32,3) | [0,1] | 24,576/24,576 · 0 | 24,576/24,576 · 0 | +| 128² | (123,93), (123,122), (122,8) | [−1,2] | 131,045/131,072 · 4.88758087e-06 | 131,039/131,072 · 1.37090683e-06 | +| 128² | (123,93), (123,122), (122,8) | [0,1] | 131,072/131,072 · 0 | 131,072/131,072 · 0 | + +Both shapes agree on all 311,296 unit-region pixels. Nonunit-region stamps retain F32 differences. At 64², the horizontal ramp differs at two pixels with center (.5393365, 1.9508762), size (.05541531, .08797855) and zero rotation, even with tiling disabled. At pixel (32,62), MaterialCraft gives .213091522 and the reference gives .213092923. The root stays in progress. + +### Saved splatter and weave graphs across independent fields + +Recheck the [earlier root and single-branch measurements](#tile-weave-splatter-and-fiber-stage-comparisons) with the pattern sampler from `7ff64fa`. Include each archived distinct setting and the four 64² output precisions. The two weave entries use different packages. + +For the new seven-size series use zero-based size index j, inventory index i and seed S = 792713 + 37i + 241j. The sizes in order are 16 × 32, 64 × 16, 64², 16 × 64, 32 × 128, 128 × 64 and 256 × 128. Render U16 and F32 at every size. Add U8 and F16 at indices 1, 2 and 6. Use defaults at j = 0 and 3. Disconnect every pin at j = 0. At j = 3 supply a 32 × 16 field. Otherwise use the output size. For Splatter Color, order the input identifiers alphabetically and supply only the first at j = 4 and only the second at j = 5. + +At texel (x,y), for zero-based pin m and channel a, form v = ((31+11a)x + (47+2m)y + 7xy + S + 89m + 37a) mod 257. Write .625v/256 + .375 when (3x+13y+5a+m) mod 17 < 5, and .625v/256 otherwise. Set the texel at ((⌊width/2⌋+3a) mod width, ⌊height/3⌋) to one in that channel. Use a single channel for the grayscale input. The two weave generators have no image inputs. + +For j = 1,2,4,5,6 the respective disorder fractions r are .15625, .625, .3125, .84375 and .46875. Set weave tiling or scale to 3,7,4,11,5 and enable the 45-degree rotation at odd j. On Pattern Weave 2 enable non-square expansion when j mod 3 differs from 2. On the splatter graphs use rotation 19.25, −37.5, 73.125, −11.75 and 31.5 degrees in order. Set width to 65+85r, height to 147−93r, rotation variation to 18+55r, zoom to 62+65r and gain to .5+.5r. Pan by (−.1875+.5r, .3125−.5r). The five grid counts are 3,5,2,4,6 and the pattern selections are 2,4,8,1,7. Set disorder to r, its angle to one quarter of the rotation, its random switch to even j, size variation to .5r and image filtering to j mod 3. Set output minimum/maximum to (.125r, 1−.09375r), luminosity or color variation to .5625r, and background to .1875r for gray or (.25r,.6875r,.375,.8125) for color. + +The independent fixed-field series uses 64 × 32 for index 491 and 32 × 64 for the other three indices. Start with default settings at seeds 0 and 42. At seed 42 change just one control per F32 render according to the table. Transpose the output dimensions for defaults at seed 42, then use the combined changes at seed 803347 + 47i. A repeated control takes its last listed value. Render the original seed-42 default and the transposed combination at all four precisions. Keep the input dimensions fixed. In channel a of pin m set t = ((17+2a)x + (43+6a)y + 5xy + 803347 + 47i + 29m + 89a) mod 257. Write .75t/256 plus .25 where (3x+11y+7a) mod 13 < 4. Place the same unit impulse as in the seven-size series. + +| Root | Six single-control changes at seed 42 | +|---|---| +| Pattern Weave 2 | Scale 3, scale 13, disorder .5625, rotate 45 degrees on, non-square expansion off, disorder .875 | +| Both splatter roots | Grid count 3, pattern 1, pattern 7, rotation 31.25, disorder .71875, filtering 2 | +| Weave 2 | Tiling 3, tiling 5, disorder .3125, rotate 45 degrees off, disorder .875, tiling 7 | + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Pattern Weave 2 (382) | 95 | 400,896/400,896 · 0 | 1,173,842/1,174,016 · 81 | 402,942/402,944 · 0.000610351562 | 1,161,809/1,161,984 · 0.00169374049 | +| Splatter (488) | 55 | 47,104/47,104 · 0 | 175,104/176,128 · 9366 | 49,152/49,152 · 0 | 81,152/82,176 · 0.142916024 | +| Splatter Color (491) | 55 | 47,104/47,104 · 0 | 176,128/176,128 · 0 | 49,152/49,152 · 0 | 82,176/82,176 · 0 | +| Weave 2 (538) | 95 | 400,896/400,896 · 0 | 1,174,016/1,174,016 · 0 | 402,944/402,944 · 0 | 1,161,984/1,161,984 · 0 | + +Save each graph from MaterialCraft and reopen the result directly in both applications. Repeat all 20 seven-size renders after the first save. Save again and repeat the seven F32 renders plus the three other precisions at 64². Use the saved file for all ten fixed-field F32 renders and the three other precisions at the transposed combined setting. Both applications reproduced every pixel of their own originals across all 43 reopens per root. + +| Root | First save, 20 renders | Second save, 10 renders | Fixed-field reopens, 13 renders | Total exact / compared | Maximum U8 / U16 / F16 / F32 | +|---|---:|---:|---:|---:|---| +| Pattern Weave 2 | 179,194/179,200 | 63,996/64,000 | 26,622/26,624 | 269,812/269,824 | 0 / 43 / 0.000610351562 / 0.000656142831 | +| Splatter | 177,152/179,200 | 62,976/64,000 | 26,624/26,624 | 266,752/269,824 | 0 / 9366 / 0 / 0.142916024 | +| Splatter Color | 179,200/179,200 | 64,000/64,000 | 26,624/26,624 | 269,824/269,824 | 0 / 0 / 0 / 0 | +| Weave 2 | 179,200/179,200 | 64,000/64,000 | 26,624/26,624 | 269,824/269,824 | 0 / 0 / 0 / 0 | + +The six-setting authored-shape and disc controls from the earlier branch comparison now match across applications in every measured branch. Pattern Weave 2 matched 12,160/12,160 across its two branches and both shapes. Splatter and Splatter Color each matched 9,728/9,728. Weave 2 matched 2,816/2,816. All branch maxima are zero. + +Splatter Color and Weave 2 have measured parity across the reported settings. Pattern Weave 2 still differs on 351 whole pixels. Grayscale Splatter differs on the 16 × 64 default fed by the 32 × 16 field at seed 811492. Its input bridge matched all 1,024 U16 words. The following pattern draw differed on all 1,024 words, maximum 9,366. Rebinding the measured bridge levels as a 16 × 64 original-field input gave 1,024/1,024 matching F32 output pixels, maximum zero. + +### Portable function links when opening a library graph from disk + +Open the physical `waveform_01_v2.sbs` beneath the configured package library in MaterialCraft. Save to a directory outside that library with `file.saveAs`. Close and reopen the new file directly in both applications. Repeat the [seven-size and fixed-field waveform comparisons](#waveform-v2-with-library-and-file-based-hash-functions). Include a second save and reopen. + +Before the fix, opening the graph through its physical path wrote relative links to the two local function packages. Opening through the library alias preserved both portable links. At the 16² default and the changed 64 × 32 and 128 × 32 F32 controls, the two saved files produced the following results. + +| How MaterialCraft opened the original | Saved F32 pixels exact / compared | Maximum error | +|---|---:|---:| +| Physical path | 4,712/6,400 | 1 | +| Library alias | 6,400/6,400 | 0 | + +When a graph is saved outside the configured library, unchanged, self-contained function packages from that library use portable URIs. The positive control uses the package files bundled with the tested build. The second library contains the earlier general math file from revision `97f2e06` and the unchanged hash file. The earlier math file differs byte-for-byte from the bundled version and keeps its relative link. + +| Source directory used to open the waveform | Saved general math link | Saved hash link | First save, 20 renders | Second save, 10 renders | Fixed-field reopens, 13 renders | +|---|---|---|---:|---:|---:| +| Bundled files | Library URI | Library URI | 109,056/109,056 | 44,288/44,288 | 26,624/26,624 | +| Earlier file for general math | Relative file path | Library URI | 109,056/109,056 | 44,288/44,288 | 26,624/26,624 | + +All **179,968/179,968** pixels on each route matched across applications and repeated the original render in each application. The U8, U16, F16 and F32 maxima were zero. Saving within the same configured library to a child directory wrote relative links resolving to both original functions. A detached older hash file still has the [separate measured handoff difference](#waveform-v2-with-library-and-file-based-hash-functions). Waveform v2 remains in progress for that case. + +The normal open/save/reopen regression failed before the change and passed after it. Separate controls retain file identity for a same-length edit and a byte-identical copy outside the library. The release engine and format suites passed, along with the hostile-command check, formatting, strict workspace Clippy, dependency layering and WebAssembly. + +### Automatic filtering after resizing a bound bitmap + +Grayscale Splatter’s automatic stamp filter can receive an input with only its base texture level. A targeted impulse distinguishes this state from an image with identical stored pixels and a full set of reduced levels. + +Place a single white texel at (10,8) on a black 32 × 16 F32 grayscale image. Bind it to a U16 input bridge at 16 × 64. In one quadrant draw a centered bitmap stamp at one quarter of the output width and height, with automatic filtering, zero roughness and tiling off. Read U16 at x = 7 on rows 30 through 34. Both applications now give **0, 2048, 12288, 2048, 0**. Export the unmodified bridge pixels as U16 PNG or normalized F32 EXR at 16 × 64 and bind them again. Both applications then give **0, 1280, 5632, 1280, 0**. The release regression failed on the original binding before the fix. The two bindings also exercise the evaluator cache. + +For the measured power-of-two inputs, count the greatest difference in width or height exponents between the external file and the bridge. With matching input and output precision, any resize left the base level alone. With a depth conversion, one step still supplied reduced levels and two or more steps left only the base. Half and full EXR supplied F32 samples at the start of this comparison. The odd-size controls retained reduced levels. A compatible graph-instance input and a same-size reroute preserve the effective filter. Identity Levels supplies reduced levels again. The stamp’s authored filter continues to determine its drawing order. + +Check storage and resizing independently with a single centered quarter-size stamp. For source size index j write the grayscale field ((71x+31y+17xy+3j) mod 257)/256 to byte or word PNG, or half or full EXR. For integers multiply by the largest stored value and round to nearest, ties to even. Vary the bridge across U8, U16, F16 and F32 and compare the stamp’s U16 and F32 output. Use seed 816701 + 73j. The ordered input-to-output sizes are 16×64→16×64, 32²→16×64, 32×16→16×64, 64×16→16×64, 256×4→16×64, 4×128→64×16, 128²→32², 8²→64×32, 7×23→32², 64×16→32², 128×64→32×16, 8×4→32×16, 16×32→16×128, 16×256→16×64 and 64²→16². For all four input depths with a word bridge and for full EXR across every bridge, capture every size in F32 and add U16 at indices 0, 1, 2 and 4. For the other nine depth combinations use indices 0, 1, 2, 4, 6, 8, 9 and 13, adding the same four U16 renders. + +| Isolated comparison | Renders | Exact pixels before / compared | Exact pixels after / compared | Maximum after | +|---|---:|---:|---:|---:| +| Centered gray and color stamps, three filter modes and sizes 1, ½, ¼ and ⅛ | 132 | 133,943/135,168 | 135,168/135,168 | 0 | +| Offset stamps and rotations 0, .109375 and −.078125 turns, automatic and bilinear | 54 | 53,696/55,296 | 55,296/55,296 | 0 | +| Instance, reroute and identity Levels | 18 | 18,174/18,432 | 18,432/18,432 | 0 | +| Impulse and its two same-size rebindings | 3 | 3,069/3,072 | 3,072/3,072 | 0 | +| All 16 source and bridge depth pairs | 241 | 238,992/248,576 | 248,576/248,576 | 0 | + +Repeat the [55 earlier grayscale Splatter settings](#saved-splatter-and-weave-graphs-across-independent-fields) and add thirteen original fields. For index j, start with .625 × ((29x+101y+11xy+37j+19) mod 251)/250 and add .375 where (x+7y+3j) mod 19 < 6. Set the pixel at ((⌊width/3⌋+2j) mod width, (⌊height/2⌋+j) mod height) to one. Store the named source depth. Use seed 822307 + 269j. Render U16 and F32 throughout and add U8 and F16 at j = 0, 2, 4, 6, 10 and 12. + +| j | Source → output | Source storage | Changes from defaults | +|---:|---|---|---| +| 0 | 32×16 → 16×64 | F32 | Defaults | +| 1 | 16×32 → 64×16 | U16 | Defaults | +| 2 | 32² → 16×64 | U16 | Defaults | +| 3 | 32² → 16×64 | U8 | Defaults | +| 4 | 64×16 → 16×64 | F16 | Defaults | +| 5 | 8×128 → 64×32 | F32 | Grid 3, rotation 17.8125°, disorder .53125, pattern 9 | +| 6 | 128×32 → 32×64 | U16 | Grid 5, rotation −32.625°, disorder .21875, pattern 9 | +| 7 | 32×64 → 32×64 | F16 | Defaults | +| 8 | 4×32 → 32² | U8 | Filter 1, pattern 9 | +| 9 | 16×128 → 64×32 | F32 | Filter 2, pattern 9 | +| 10 | 7×23 → 32² | U8 | Defaults | +| 11 | 13×33 → 32×64 | F32 | Grid 3, rotation 17.8125°, disorder .53125, pattern 9 | +| 12 | 64² → 16×32 | F32 | Pattern 1, rotation 63.125° | + +| Output | Renders | Exact before / total · maximum | Exact after / total · maximum | +|---|---:|---:|---:| +| LUM16 | 29 | 184,448/194,048 · 16353 | 194,048/194,048 · 0 | +| LUM16F | 14 | 50,176/55,808 · 0.211425781 | 55,808/55,808 · 0 | +| LUM32F | 37 | 90,496/100,096 · 0.249530882 | 100,096/100,096 · 0 | +| LUM8 | 13 | 48,128/53,760 · 54 | 53,760/53,760 · 0 | + +Grayscale Splatter matched **403,712/403,712** pixels across 93 distinct settings, up from **373,248/403,712** on the same inputs. The 55 earlier settings now match 354,560/354,560. Save the graph from MaterialCraft and reopen it in both applications. Repeat the earlier 43 saved-file settings, the thirteen new F32 cases and the three other precisions at indices 0, 4 and 10. All **296,960/296,960** pixels matched across the 65 reopens, maximum zero, and each application reproduced every original buffer. + +The color Splatter and Weave 2 control roots retained their earlier perfect counts. Pattern Weave 2 retained its 351 differing pixels across 95 settings. Formatting, 401 release tests across the evaluator and node crates, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Three measured taps reproduce the rectangular directional blur outputs + +Extend the [96-angle rectangular experiment](#independent-rectangular-directional-weights-at-96-angles) with 48 new F32 angles. Use the same two sizes (16 × 64 and 64 × 16), original red column and green row impulses, modular blue field, and five extents. Start with 0.046875, 0.0791015625, 0.203125, 0.4608612060546875, 0.7427520751953125, 1.4530487060546875 turns. For each center, change its positive F32 bit pattern by −5, −2, −1, +1, +2 and +5, in order. Then for each center add half a turn in F32 and change that result by −1 and +1 representable values. Use batches of 16 angles and seed 824091 + 17b + 5j + r, where b is the batch, j the size and r the extent, all indexed from zero. + +For each branch and extent, read the center and both adjacent weights from the impulse on the longer axis. Predict the entire raw output from the original input. Multiply the next texel by the weight measured one pixel before the impulse. Fuse the center multiply and addition, then fuse the previous texel multiply and addition using the weight measured one pixel after the impulse. Each operation stores an F32 result. The blue values used for this check are independent of all three measured weights. Count a pixel only when every stored channel agrees. + +| Original angles | Branch renders | MaterialCraft exact / compared | Maximum F32 error | Exact using measured weights | Exact with taps reversed | +|---|---:|---:|---:|---:|---:| +| 96 | 960 | 943,932/983,040 | 1.78813934e-07 | 983,040/983,040 | 696,407/983,040 | +| 48 | 480 | 455,107/491,520 | 1.1920929e-07 | 491,520/491,520 | 346,645/491,520 | + +The three measured weights reproduce all 1,474,560 pixels with maximum error zero. Across the 48 new angles, the current projection satisfies the rounding bounds for 84/96 axes. On every axis, at least one F32 direction component satisfies the observations at all five extents. This isolates the short axial discrepancy to the calculation of the weights. + +Save the three new graphs in MaterialCraft and reopen them in both applications. Repeat both sizes at projected extents .3125 and 1. Each application reproduced all **196,608/196,608** pixels of its original renders. Across applications the 192 reopened branch renders matched **184,755/196,608**, maximum 1.1920929e-07. Both HQ blur roots remain in progress on their [78 whole-root settings](#directional-blur-weights-across-110-angles-and-two-projection-axes). + +### Recheck of 471 bitmap sampling and placement groups + +Repeat the [1,213 bitmap and coordinate controls](#rotated-stamp-coordinates-in-gradient-linear-1-and-bnw-spots) after the [bound-image filtering fix](#automatic-filtering-after-resizing-a-bound-bitmap). These groups cover stamp scale and mip selection (48), its rectangular (24), independently rotated and scaled (128) and boundary (81) variants, rectangular placement (45), rotated mip sampling (48), per-axis UV coordinates (57), tiny stamps (16), channel handling (12), the global filter parameters (5) and seven baseline bitmap graphs. Compare every stored channel of each output pixel. + +| Storage | Render outputs | Exact before / compared | Exact after / compared | Maximum error before | Maximum error after | +|---|---:|---:|---:|---:|---:| +| LUM8 | 20 | 9,728/9,728 | 9,728/9,728 | 0 | 0 | +| LUM16 | 68 | 206,336/206,336 | 206,336/206,336 | 0 | 0 | +| LUM16F | 20 | 9,728/9,728 | 9,728/9,728 | 0 | 0 | +| LUM32F | 744 | 4,250,112/4,250,112 | 4,250,112/4,250,112 | 0 | 0 | +| RGBA8 | 6 | 6,144/6,144 | 6,144/6,144 | 0 | 0 | +| RGBA16 | 51 | 27,614/29,184 | 29,184/29,184 | 34583 | 0 | +| RGBA16F | 6 | 6,144/6,144 | 6,144/6,144 | 0 | 0 | +| RGBA32F | 298 | 285,592/304,384 | 304,384/304,384 | 0.527698517 | 0 | + +All **4,821,760/4,821,760** pixels matched. Before the fix, 20,362 color pixels differed across word and full-float outputs. No group lost exact pixels or increased its maximum error. These are isolated sampling and placement measurements. The whole-root comparisons for grayscale and color Splatter retain their respective settings and reopen counts. + +### Parameter-controlled sizes and half-precision pattern backgrounds + +A normalized integer background can cross a half-precision storage boundary before the first pattern draws, even when its dimensions already match the output. In the measured cases this happens when exactly one of the upstream image and the F16 pattern output uses a size controlled by an exposed parameter. Computing a size solely from the current image dimensions follows the fixed-size path. The same distinction applies to normalized Blend inputs. + +For a minimal grayscale control, connect a U8 input holding 58/255 to the background of a 16² F16 pattern. Draw one centered, full-size square in additive mode with gray tint 3/32768, alpha 1 and unit overall opacity. Give the source and the pattern relative size offsets of (0,0). In a size function, read an exposed float set to .375, then return the original (0,0). With the function on just one side the stored output is **.2274169921875**. With fixed sizes on both sides, only a read of `$size` or `$sizelog2`, or an exposed size function on both sides, it is **.2275390625**. The difference is the initial conversion of the normalized background toward zero at half precision. Supplying the same field as a nearest-filtered bitmap stamp retains its original sampling precision. + +For the gray and RGBA controls, run matching U8 and U16 input bridges, then repeat with F16 and F32 sources. The single-square gray tint is 3/32768 and the RGBA tint is (.4814453125,.187835693359375,.5118408203125,.734375). In color use (.22745098,.49411765,.52931082,.61328125) for the constant input. At size index j = 0, 1, 2, 3, use 16², 32 × 16, 16 × 32 and 32², with seed 843173 + 19j. For j > 0 use (((73+4c)x + 29y + 13xy + 37j + 47c) mod 997)/996, where c is the zero-based channel. The j = 3 source is 16 × 32. At the constant setting compare all four output formats. Add F16 and F32 for j = 1, then F16 for j = 2 and 3. Exercise source only, output only, both, neither, and the nearest-filtered bitmap slot with tint .71875. + +In the separate 64² fading-square test use variation .2, tint 1, and the original 128² input reduced to a U8 background. Repeat on the field ((47x+83y+11xy+5) mod 257)/256, including tint .34375. Change the requested relative size using an exposed integer pair, a converted float, a Boolean choice, or a read followed by a constant result. Include a Boolean whose two branches both return (0,0), and a size-only choice between (0,0) and (1,0) based on the aspect ratio. An exposed setting that genuinely enlarged the result also matched. For the independent graph-property test, individually retain or remove the output size, opacity, background, render region, tiling region and their measured combinations. Changing only the size function moved all 375 differences on the original 64² F16 field. The F32 control remained exact. + +| Independent comparison | Renders | Exact before / compared | Exact after / compared | Maximum before | Maximum after | +|---|---:|---:|---:|---:|---:| +| Blend foreground/background reading the current size or its logarithm | 4 | 13,516/16,384 | 16,384/16,384 | 0.00048828125 | 0 | +| Exposed-parameter size paths, gray and color | 136 | 54,159/60,928 | 60,928/60,928 | 0.0009765625 | 0 | +| Dimensions-only size paths, gray and color | 136 | 60,928/60,928 | 60,928/60,928 | 0 | 0 | +| Exposed size expressions and changed dimensions | 65 | 288,181/299,008 | 299,008/299,008 | 0.0009765625 | 0 | +| Counterfactuals on the single-stamp generator | 48 | 190,808/196,608 | 196,608/196,608 | 0.0009765625 | 0 | + +The earlier 64 Blend controls also matched **262,144/262,144** pixels across the four formats. The two evaluator regressions failed against the preceding implementation and passed after the change. + +For the four whole roots, include prior defaults, parameter sweeps, all archived root outputs, and 20 new renders per root. At index j = 0 through 6 use 16 × 32, 64 × 32, 32 × 64, 16 × 64, 64², 128 × 32 and 64 × 128. Set seed S = 831997 + 37i + 113j, where i is the inventory index below. At j = 0 disconnect all image inputs. Use default controls at j = 0 and 3. At j = 4 connect the even-numbered input pins in identifier order, and at j = 6 the odd-numbered pins, counting from zero. Connect every pin at the other nonzero indices. Use the output dimensions for the source, except at j = 3 and 5 where the sources are 32 × 16 and 32 × 64. + +For input m and channel c, let U = (((31+2c)x + (59+3m)y + 11xy + S + 17c + 43m) mod 257)/256. The field is .625U plus .375 where (7x+3y+5c+m) mod 23 < 9. Set a unit impulse at x = (floor(width/2)+3c) mod width and y = (floor(height/3)+m) mod height. Store j = 1 as U8 PNG, j = 5 as U16 PNG, j = 4 as F16 EXR, and the other connected fields as F32 EXR. Compare U16 and F32 at all seven sizes, and also U8 and F16 at j = 1, 4 and 6. + +| j | x amount | y amount | Pattern | Parameter d | Generator image count | +|---:|---:|---:|---:|---:|---:| +| 1 | 3 | 5 | 1 | .1875 | 6 | +| 2 | 5 | 3 | 7 | .609375 | 2 | +| 4 | 2 | 7 | 3 | .34375 | 3 | +| 5 | 7 | 2 | 1 | .8125 | 6 | +| 6 | 4 | 4 | 5 | .46875 | 4 | + +For these five rows set image filtering to j mod 3 and pattern rotation randomness to .75d. On the generators use pattern size (.625+.5d,1.125−.625d), position randomness (.5d,.25d), rotation −.1875+.5d and opacity 1−.5d. On the random tilers use split threshold .25+.5d, shape scale .6875+.4375d, position randomness .25d, shape rotation −.09375+.25d and shape rotation randomness .5d. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Pattern Tile Generator (373) | 63 | 30,720/30,720 · 0 | 186,624/186,624 · 0 | 30,720/30,720 · 0 | 50,463/50,688 · 2.38418579e-07 | +| Pattern Tile Generator Color (374) | 39 | 19,456/19,456 · 0 | 142,332/142,336 · 1 | 21,504/21,504 · 0 | 31,165/32,000 · 2.38418579e-07 | +| Pattern Tile Random (375) | 52 | 23,208/26,624 · 255 | 169,553/177,664 · 65535 | 19,655/23,552 · 1 | 78,668/88,832 · 1.00000006 | +| Pattern Tile Random Color (376) | 126 | 26,868/30,720 · 255 | 172,566/181,760 · 65535 | 23,591/27,648 · 1 | 275,964/379,648 · 1.00000006 | + +Save each graph in MaterialCraft, open the saved package in both applications, and repeat all 20 new renders. Save a second time and repeat all seven F32 settings plus the other three formats at 64². Both applications reproduced their original buffers on all 120 reopened renders. + +| Whole root | Before / compared | After / compared | Reopened exact / compared | Reopened maximum | +|---|---:|---:|---:|---:| +| Pattern Tile Generator | 296,952/298,752 | 298,527/298,752 | 106,558/107,008 | 2.38418579e-07 | +| Pattern Tile Generator Color | 212,392/215,296 | 214,457/215,296 | 105,732/107,008 | 1 | +| Pattern Tile Random | 291,037/316,672 | 291,084/316,672 | 76,704/107,008 | 65535 | +| Pattern Tile Random Color | 498,869/619,776 | 498,989/619,776 | 75,455/107,008 | 65535 | + +Eleven more focused reopens per generator include the original background, a new modular background, reduced or zero opacity and disconnected pins. In grayscale **45,056/45,056** pixels matched, maximum zero. In color **11,212/11,264** matched, maximum 2.38418579e−7. Both applications reproduced their own originals. The four roots remain in progress. Both generators now match all measured F16 pixels. The whole grayscale generator still differs at 225 F32 pixels, and the color generator at four U16 and 835 F32 pixels. On the two new F32 bitmap settings, supplying any one of the six stamp images on its own, with or without the original background, matched in both generators. The combined images still differ. Both random tilers retain larger placement and pattern differences. + +Formatting, strict workspace Clippy, dependency layering, all ten WebAssembly crate checks and all 402 evaluator and node release tests passed. The release tests used the committed resource set. + +### Version of a detached function package and waveform reopening + +The older detached hash package used in the [Waveform v2 handoff](#waveform-v2-with-library-and-file-based-hash-functions) declares format version `0.1.3`. Keep its relative path and all function definitions and values. In an independent disposable copy change the package’s `formatVersion` to `1.1.0.202401`. In MaterialCraft the original and changed headers give identical pixels. In the reference app the changed header restores the waveform. + +Use the [seven-size, changed-parameter and fixed-field series](#reopened-starburst-symmetry-tile-and-waveform-graphs). Save the caller in MaterialCraft and point its hash dependency at the local copy. The general math dependency remains the portable library reference. Open the saved file directly in each application. The three F32 controls at 16², 64 × 32 and 128 × 32 matched **4,712/6,400** with the older header, maximum 1. Changing the format version alone gave **6,400/6,400**, maximum zero. A second copy also includes a complete self-dependency entry with type `package`, file UID 0 and version UID 0. + +| Relative hash dependency | First save, 20 renders | Second save, 10 renders | Fixed-field reopens, 13 renders | Maximum error | +|---|---:|---:|---:|---:| +| Updated format version, original dependency list | 109,056/109,056 | 44,288/44,288 | 26,624/26,624 | 0 | +| Updated format version, complete self-dependency entry | 109,056/109,056 | 44,288/44,288 | 26,624/26,624 | 0 | + +Each application reproduced all **179,968/179,968** original pixels on each route. A deliberately incomplete self-dependency containing only the filename and UID produced **167,194/179,968** exact pixels at the updated format version. Opening the dependency in MaterialCraft and saving it as a separate package writes the supported header and a complete self-dependency through the regular file commands. + +In a separate one-output pixel processor, call the hash function with normalized pixel-center coordinates offset by (0,.21875) at 16² F32 and (.3125,.21875) at 64 × 16 U16. Use seeds 775641 and 775642. With the older detached file the reference returned zero at every pixel whether the file was adjacent, in a child directory, two directories up or renamed. Replacing its result with the constant .34375 left the reference at zero. With a separately saved file that same replacement returned .34375 and 22,528 U16 at every pixel in both applications. Reducing the package to just the marked function preserved **1,280/1,280** exact pixels. Changing only its format version back to `0.1.3` gave **0/1,280**, maximum .34375 in F32 and 22,528 U16 levels. Altering only the writer version or file UID preserved all 1,280 pixels. + +Waveform v2 remains in progress for directly reopening the unchanged older detached dependency. The original graph, the portable library route and the measured current-format relative routes are exact. + +### Pattern draw order for fixed and runtime image slots + +Overlapping bitmap stamps with constant image selectors draw in the order each image slot is first used. When any visited bitmap quadrant reads a changing image selector, the slots draw in ascending input-port order. This applies to both grayscale and RGBA. The selector can return the same integer in both cases. A visited image with zero size, zero tint or an off-canvas footprint still establishes the order. A disconnected quadrant, an empty pattern, a procedural shape and an unbound getter retained first-use order in the controls. + +Use a black background and three overlapping bitmap quadrants that select slots (1,0,1). At successive depths use sizes (1,1), (2,2) and (4,4), nearest filtering, overall opacity 1 and a constant image per slot. In grayscale use byte levels 128 and 255. With maximum, additive and maximum blending and tints (.125,.25,.875), the F32 value at the upper left is **1.0004901885986328** for fixed selectors and **.875** for a bound selector. With three additive stamps and tints (.75,2⁻²⁷,−.75), the corresponding values are **3.7398995e−9** and **0**. For color use the byte tuples (128,181,79,255) and (255,205,111,255). Use source-over, additive and source-over, RGB tints (.75,.25,.5) and alpha (.375,.59375,.71875). The red channel changes from **.51298636** to **.451574**. + +For each blend family, render at 32 × 16 with seed 471817 and 16 × 32 with seed 471818. Repeat the first setting with the exposed slot values reversed to (0,1,0). Use fixed selectors, each of the seven nonempty subsets of exposed selectors, a literal-valued function, a read of the iteration number followed by the literal result, and an exposed integer plus zero. In separate two-size controls, attach the extra quadrant with its value fixed, bound or unbound, and vary connectivity, shape, size and footprint as described above. + +The mixed-shape controls compare all three layers together and each layer on its own. Group by procedural pattern identifier, then bitmap slot. Within a bitmap slot, filter modes draw in the order automatic, bilinear, nearest. Within each group additive draws first and equal keys keep their traversal order. For three overlapping RGBA quadrants, use a transparent background, RGB tints (.75,.25,.5) and alpha (.375,.5,.75). The twelve configurations below list each quadrant as (pattern, slot, filter, blend). Pattern 1 selects an image, while 2 and 5 select procedural shapes. Use the same images, quadrant sizes and two resolutions as above. Only row 11 reads all three image indices from exposed integers. + +| Configuration | First | Second | Third | +|---:|---|---|---| +| 1 | (1,1,2,0) | (1,1,0,1) | (1,1,2,1) | +| 2 | (1,1,2,1) | (1,1,1,0) | (1,1,2,1) | +| 3 | (1,1,1,1) | (1,1,2,0) | (1,1,1,1) | +| 4 | (1,0,1,1) | (1,0,1,0) | (1,0,1,1) | +| 5 | (1,0,1,1) | (1,0,1,2) | (1,0,1,0) | +| 6 | (1,1,2,1) | (2,0,0,1) | (1,0,2,0) | +| 7 | (2,0,2,1) | (1,0,2,1) | (2,0,2,0) | +| 8 | (5,0,2,1) | (2,0,2,1) | (5,0,2,0) | +| 9 | (2,0,2,1) | (5,0,2,0) | (2,0,2,0) | +| 10 | (1,1,2,1) | (1,0,1,1) | (1,1,0,0) | +| 11 | (1,1,2,0) | (1,0,1,1) | (1,1,0,1) | +| 12 | (5,0,2,0) | (1,0,1,1) | (2,0,2,1) | + +| Independent F32 comparison | Renders | Exact before / compared | Maximum before | Exact after / compared | Maximum after | +|---|---:|---:|---:|---:|---:| +| Grayscale selectors | 66 | 23,472/33,792 | 0.25 | 33,792/33,792 | 0 | +| RGBA selectors | 66 | 22,720/33,792 | 0.185526788 | 33,792/33,792 | 0 | +| Grayscale quadrant reachability | 16 | 6,752/8,192 | 3.7398995e-09 | 8,192/8,192 | 0 | +| RGBA quadrant reachability | 16 | 5,792/8,192 | 5.28845145e-09 | 8,192/8,192 | 0 | +| Shapes, filters and blend order | 96 | 42,390/49,152 | 0.2578125 | 49,152/49,152 | 0 | + +After saving ten of the small graphs in MaterialCraft, both applications reproduced their original buffers. All **13,312/13,312** pixels matched across the 26 reopened renders, maximum zero. The release regression on fixed and bound selectors failed before the change and passed afterward. + +On the [previous whole-root comparison](#parameter-controlled-sizes-and-half-precision-pattern-backgrounds) the grayscale generator advanced from 298,527 to **298,752/298,752** across 63 settings. The color generator advanced from 214,457 to **215,296/215,296** across 39 settings. The maximum error is zero for both. The expanded comparison below also includes the background controls, each of the six slots alone or with background, all fifteen slot pairs at two sizes, and a new six-size field. Settings repeated across series are counted once. + +For the new field use seed S = 105607 + 19i + 157j, where i is the inventory index and j is the zero-based row below. For input m in sorted identifier order and zero-based channel c, form U = ((67x+43y+13xy+11cx+29m+59c+S) mod 383)/382. The channel is .75U plus .25 where (5x+7y+3m+c) mod 17 > 9. Set one texel to 1 at x = (3c+⌊input width/4⌋) mod input width, y = (m+⌊input height/4⌋) mod input height. Round the PNGs to their nearest stored levels, ties to even. Set position randomness to (.1875,.3125), global opacity to .75+j/32, rotation to −.09375+j/64, and rotation randomness to .125+j/32. Enable non-square expansion at even j. Use bitmap pattern 1. The grayscale tint is .875 with luminance randomness .21875. The RGBA tint is (.6875,.375,.8125,.78125) with variation (.21875,.125,.3125,.15625). + +| j | Output | Input | Input storage | Tiles | Images | Blend | Filter | +|---:|---|---|---|---|---:|---:|---:| +| 0 | 32 × 16 | 32 × 16 | U8 | 3 × 4 | 6 | 1 | 0 | +| 1 | 64 × 32 | 64 × 32 | U16 | 5 × 3 | 6 | 0 | 1 | +| 2 | 32 × 64 | 16 × 32 | F32 | 4 × 5 | 3 | 1 | 2 | +| 3 | 32² | 31 × 23 | F32 | 5 × 7 | 2 | 0 | 1 | +| 4 | 128 × 32 | 32 × 64 | U8 | 7 × 3 | 6 | 1 | 0 | +| 5 | 32 × 64 | 32 × 64 | F16 | 3 × 5 | 4 | 0 | 2 | + +Connect every input except indices 2, 4 and 5 at j = 2, and index 0 at j = 5. Read U16 and F32 at all six sizes, with U8 and F16 also at j = 0 and 3. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Pattern Tile Generator (373) | 176 | 32,255/32,256 · 1 | 201,896/202,496 · 18902 | 77,310/77,312 · 0.00390625 | 328,103/328,704 · 0.288434759 | +| Pattern Tile Generator Color (374) | 152 | 19,699/20,992 · 50 | 146,123/155,136 · 16285 | 33,003/34,304 · 0.193847656 | 285,643/294,656 · 0.248491704 | +| Pattern Tile Random (375) | 52 | 23,208/26,624 · 255 | 169,553/177,664 · 65535 | 19,655/23,552 · 1 | 78,668/88,832 · 1.00000006 | +| Pattern Tile Random Color (376) | 126 | 26,868/30,720 · 255 | 172,566/181,760 · 65535 | 23,591/27,648 · 1 | 275,964/379,648 · 1.00000006 | + +| Whole-root save, reopen and repeat | Renders | Exact / compared | Maximum by output format (U8 / U16 / F16 / F32) | +|---|---:|---:|---| +| Pattern Tile Generator | 57 | 177,484/178,688 | 1 / 18902 / 0.00390625 / 0.288434759 | +| Pattern Tile Generator Color | 57 | 124,276/144,896 | 50 / 16285 / 0.193847656 / 0.248491704 | +| Pattern Tile Random | 30 | 76,704/107,008 | 255 / 65535 / 1 / 1.00000006 | +| Pattern Tile Random Color | 30 | 75,455/107,008 | 255 / 65535 / 1 / 1.00000006 | + +The two applications reproduced their own original buffers on all 174 whole-root reopens. These include the first and second saves of the earlier seven-size suite, both new sixteen-render series and the eleven focused background reopens per generator. Grayscale has two differing F32 pixels in the 31 × 23 field and 599 in the resized byte field. Removing every stamp retained the two odd-input differences in the U8 background bridge. For the resized byte field, changing only the automatic image filter to bilinear or nearest made the entire grayscale F32 output exact. With bilinear selected, 4,096/4,096 of the reference pixels also equal its automatic result. At the first size, disabling only the four color-variation controls made 512/512 RGBA F32 pixels exact, maximum zero. The two random tilers still have placement and pattern discrepancies. + +Seven alternating release cooks per version measured the median cook time for the color field at j = 1 (23.17 to 21.88 ms), at j = 4 (68.26 to 60.70 ms), and the earlier 128 × 32 grayscale field (39.77 to 43.13 ms). + +All 93 grayscale Splatter settings (403,712 pixels), 55 color Splatter settings (354,560 pixels), and 80 grayscale Radial Blur settings (591,616 pixels) matched after the change, with maximum zero. Formatting, strict workspace Clippy, dependency layering, all ten WebAssembly checks and all 343 release node tests passed. The release suite used the committed resource set. + +### First and repeated automatic samples of an embedded bitmap + +An embedded bitmap can report identical U16 pixels on every read while the reference app returns different automatically filtered pattern samples. The first render after opening the graph and a later render of exactly the same setting differed in three of five tests. Explicit bilinear sampling reproduced every repeat. + +Create one original grayscale PNG from the field ((71x+31y+17xy+3k) mod 257)/256 at each source size below. Round to the nearest byte or word, ties to even. Place it as a linear Bitmap resource, set the Bitmap to U16 at parent size, and connect it to a centered quarter-size bitmap quadrant. Use input slot 0, additive blending, unit opacity and tint, zero rotation and roughness, and disable tiling. Capture the Bitmap node and the pattern. At row j use seed 107203+17j for every render. Open the graph and set the pattern format successively to F32, U16, F32, U16, F16, U8, F16 and U8. In a fresh copy run the formats in reverse order. Repeat both runs with explicit bilinear filtering. Leave the source, seed and dimensions fixed throughout each run. + +| j | Source and k | Output | First vs second F32 in the forward order | Maximum | First vs second U8 in the reverse order | Maximum | +|---:|---|---|---:|---:|---:|---:| +| 0 | 16 × 64, U8, k = 0 | 64² | 3,858/4,096 | 0.250156403 | 3,900/4,096 | 64 | +| 1 | 16 × 64, U8, k = 0 | 128 × 32 | 4,096/4,096 | 0 | 4,096/4,096 | 0 | +| 2 | 32², U16, k = 1 | 16 × 64 | 1,024/1,024 | 0 | 1,024/1,024 | 0 | +| 3 | 7 × 23, U8, k = 8 | 32² | 965/1,024 | 0.00318908691 | 1,009/1,024 | 1 | +| 4 | 128², U16, k = 6 | 16² | 240/256 | 0.0225528479 | 241/256 | 6 | + +| MaterialCraft against the reference app | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Automatic | 40,680/41,984 · 64 | 40,544/41,984 · 16143 | 40,620/41,984 · 0.246337891 | 40,349/41,984 · 0.250156403 | +| Bilinear | 41,984/41,984 · 0 | 41,984/41,984 · 0 | 41,984/41,984 · 0 | 41,984/41,984 · 0 | + +All 160 observed U16 Bitmap buffers agreed between the two reference runs and the filter variants at their respective size. At 64² from the byte input, the first automatic F32 render agreed with bilinear. After the intervening U16 render, repeating F32 changed 238 pixels. The 128 × 32 control used the same source file and was stable. At 32² from the odd input, the first and later F32 results both differed from bilinear, and they also differed from each other. Automatic sampling of embedded bitmaps remains open. + +### Selected Blend inputs and odd-sized float backgrounds in tile generators + +Pattern Tile Generator now matches **757,504/757,504** raw grayscale pixels in 221 distinct settings, with maximum error zero in U8, U16, F16 and F32. The 176 settings from the [bitmap-slot comparison](#pattern-draw-order-for-fixed-and-runtime-image-slots) had 1,204 differing pixels. Preserving the sampling levels of a resized image selected by Blend removed 1,198 differences. Correcting float-to-byte dithering in an odd-sized background removed the last six. An additional 45 settings matched all 116,736 pixels. + +An unmasked Switch at full opacity can forward the foreground's available sampling levels. A grayscale Copy also does so. At zero opacity the nine bounded blend modes forward the background's levels. This requires matching dimensions, channel kind and storage depth. Connecting a mask, changing depth, or driving opacity from a bound graph input gives the downstream automatic filter a full mip chain. The reference retained the source levels with a literal-valued opacity function, image-size read, unused seed read and unbound opacity input. Binding the blend mode, alpha switch or color interpretation at fixed opacity also retained them. The two paths can produce identical intermediate Blend pixels. + +Bind a 32 × 16 single-channel F32 image with one white pixel at (10,8) to a 16 × 64 U16 bridge. Use an unmasked Switch with fixed opacity 1, U16 output, then a centered quarter-size bitmap quadrant with automatic filtering. In the final U16 stamp the column at x = 7, rows 30–34, reads **0, 2048, 12288, 2048, 0**. Rebind the same bridge pixels directly at 16 × 64 to get **0, 1280, 5632, 1280, 0**. A F32 Blend output followed by the U16 stamp gives the latter values. A U8 Blend output gives **0, 1285, 5654, 1285, 0**. + +For the five field controls, use 32 × 64 to 128 × 32, 32² to 32², 32² to 64 × 32, 64² to 16 × 32 and 32 × 16 to 16 × 64. Use byte, byte, byte, word and F32 sources, respectively. At zero-based size index j, use seed 108131 + 53j. Set channel c to ((23x + 71y + 11xy + 13j + 53c) mod 263)/262, mark the texel at one third of the width and half the height white, and round PNG samples to the nearest stored level. Compare automatic and bilinear filtering after a direct input, Switch, Copy and Add. Use (.125,.3125,.6875,.40625) for the optional background. For the mask and depth controls, bind the field on either side against (.375,.375,.375,.375), move opacity between −.25 and 1.25 and try masks of 0, .5 and 1. For the property controls, drive one property at a time from a literal, folded addition of zero, a sequence reading an exposed value, image size or seed, or a missing getter. + +The float-to-byte writer adds centered noise in units of 1/256 and diffused quantization error in units of 1/255 before rounding. Use a zero F32 16 × 3 image and set the first texel to 50.997/255, 50.998/255, 50.999/255, then 51/255. On conversion to a 16 × 4 U8 input the first texel reads **50, 50, 51, 51**. A 256 × 3 constant F32 image of 128/255 retains byte 128 throughout. Further controls use exact byte and word levels stored in F32, binary fields, one-F32-step offsets around predicted thresholds, and independent gray and four-channel fields. The eight source sizes are 31 × 23, 23 × 31, 7 × 23, 15 × 23, 31 × 32, 32 × 23, 63 × 47 and 33 × 21. At index j and channel c use u = ((71x + 31y + 17xy + 3j + 43c + 109273 + 19j) mod 383)/382, then .75u plus .25 wherever (5x + 7y + 3j + c) mod 17 > 9. + +The asymmetric Blend background also exposed the grayscale Uniform conversion. A fixed RGB value of (.125,.3125,.6875) produces .375, independent of alpha. The fixed signed tuple (1.75,−.875,−.25) gives .20833333. The twelve color controls cover primary, equal-channel, out-of-range and nearly canceling values as literals and exposed four-component inputs. The latter still differ in two F32 settings, including the signed tuple. The four remaining RGBA Copy pixels in the mask and interpretation series occur in color interpretation modes 2 and 3 at full opacity. + +| Independent comparison | Renders | Exact before / compared | Maximum before, U8 / U16 / F16 / F32 | Exact after / compared | Maximum after, U8 / U16 / F16 / F32 | +|---|---:|---:|---|---:|---| +| Field, depth and filter | 252 | 526,630/534,528 | — / 15676 / — / 0.239200413 | 534,528/534,528 | — / 0 / — / 0 | +| Blend side, mask and color interpretation | 168 | 339,359/344,064 | — / — / — / 0.239200413 | 344,060/344,064 | — / — / — / 1.090765e-05 | +| Blend mode, output depth and exposed opacity | 204 | 410,250/417,792 | — / — / — / 0.241184056 | 417,792/417,792 | — / — / — / 0 | +| Property source and image filtering | 112 | 280,856/286,720 | — / — / — / 0.239200413 | 286,720/286,720 | — / — / — / 0 | +| Single impulse through Blend | 12 | 12,282/12,288 | — / 6656 / — / — | 12,288/12,288 | — / 0 / — / — | +| Earlier graph, background and depth controls | 155 | 172,800/172,800 | — / 0 / 0 / 0 | 172,800/172,800 | — / 0 / 0 / 0 | +| Odd-sized procedural image fields | 130 | 149,097/149,504 | 1 / 0 / — / 0 | 149,504/149,504 | 0 / 0 / — / 0 | +| Byte boundaries and sparse ramps | 74 | 71,448/75,776 | 1 / — / — / — | 75,776/75,776 | 0 / — / — / — | +| Single-step threshold controls | 56 | 20,682/26,112 | 1 / 0 / — / 0 | 26,112/26,112 | 0 / 0 / — / 0 | +| Fixed and exposed Uniform colors | 192 | 17,280/27,648 | 164 / 42139 / 0.642578006 / 0.642999947 | 27,456/27,648 | 0 / 0 / 0 / 2.98023224e-08 | + +The property-source row counts completed image comparisons. In 16 additional attempts, the reference evaluated a sequence that read the seed before returning a literal. MaterialCraft reported an undefined seed variable for both grayscale and RGBA. Those attempts have no local pixel result. + +For the 45 additional grayscale settings, start with rows 3 and 4 of the [six-size field](#pattern-draw-order-for-fixed-and-runtime-image-slots). At each size compare empty inputs, background alone, stamps alone, each slot alone and each slot with background. Change one control at a time across all three filters, both blend modes, one image slot, square expansion, full or zero opacity and fixed position and rotation. Repeated settings count once. The expanded color series also includes row 0 and single-tile controls at 32² using a white bitmap or procedural shape 2 or 3. Use seeds 31, 12071 and 68047, fixed tint (.6875,.375,.8125,.78125) or white, then vary hue, saturation, lightness and alpha individually by .5 or in combination. The single-tile series includes exact fixed-color and lightness-only settings. Hue, saturation and alpha differences keep the color generator open. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Pattern Tile Generator (373) | 221 | 32,256/32,256 · 0 | 202,496/202,496 · 0 | 77,312/77,312 · 0 | 445,440/445,440 · 0 | +| Pattern Tile Generator Color (374) | 331 | 19,701/20,992 · 50 | 146,125/155,136 · 15147 | 33,005/34,304 · 0.193847656 | 422,513/554,752 · 0.366030335 | +| Pattern Tile Random (375) | 52 | 23,208/26,624 · 255 | 169,553/177,664 · 65535 | 19,655/23,552 · 1 | 78,668/88,832 · 1.00000006 | +| Pattern Tile Random Color (376) | 126 | 26,868/30,720 · 255 | 172,566/181,760 · 65535 | 23,591/27,648 · 1 | 275,964/379,648 · 1.00000006 | + +| MaterialCraft save reopened by both applications | Renders | Cross-application exact / compared | Maximum, U8 / U16 / F16 / F32 | +|---|---:|---:|---| +| Pattern Tile Generator | 57 | 178,688/178,688 | 0 / 0 / 0 / 0 | +| Pattern Tile Generator Color | 57 | 124,284/144,896 | 50 / 15147 / 0.193847656 / 0.231126025 | +| Pattern Tile Random | 30 | 76,704/107,008 | 255 / 65535 / 1 / 1.00000006 | +| Pattern Tile Random Color | 30 | 75,455/107,008 | 255 / 65535 / 1 / 1.00000006 | +| Selected Blend controls | 35 | 72,704/72,704 | — / 0 / — / 0 | +| Odd-sized inputs | 48 | 33,536/33,536 | 0 / 0 / — / 0 | +| Uniform controls | 44 | 6,336/6,336 | 0 / 0 / 0 / 0 | +| Additional grayscale generator settings | 10 | 25,600/25,600 | — / — / — / 0 | +| Additional color generator settings | 12 | 4,775/9,216 | — / — / — / 0.341796875 | + +Both applications reproduced their own originals on all 323 reopened renders. For the grayscale generator alone this covers 204,288/204,288 exact cross-application pixels across 67 reopens. The two random tilers still differ in pattern placement and composition. Previously exact controls retained 403,712/403,712 pixels across 93 grayscale Splatter settings, 354,560/354,560 across 55 color Splatter settings and 591,616/591,616 across 80 grayscale Radial Blur settings, all with maximum zero. + +All three new release regressions failed before their respective fixes and passed afterward. The 406 release evaluation and node tests passed using the committed resource set. Formatting, strict workspace Clippy, dependency layering and all ten WebAssembly checks passed. + +### Unbound integer variables in node properties + +An integer getter in a node property reads zero for an unbound reserved name. A definedness test on that name returns false. In the same property, the tiling flags and pixel ratio return 3 and 1 with default tiling. The distinction affects a Blend even when the property reads the seed and then returns a fixed opacity or mode. + +Use a Uniform node at 8 × 4 with F32 RGBA output and seeds 0, 31 and 12071. Drive the output property from an integer getter for `$randomseed`, `$tiling`, `$pixelratio`, an invented reserved name (`$missing114`) and an unset user integer. For each name, wire five graphs. Return the integer through the `value` input of a float cast, read the integer before returning .625, add .625 to the cast result, select .625 when the integer equals zero and .25 otherwise, or select .75 when the variable is defined and .25 otherwise. Read each raw RGBA pixel, including alpha. The seed and both missing names returned (0,0,0,1) on the direct read and (.25,.25,.25,1) on the definedness test, for all three seeds. + +| Independent F32 comparison | Renders | Before · exact pixels / compared | Earlier cook errors | After · exact pixels / compared | Maximum after | +|---|---:|---:|---:|---:|---:| +| Integer getter, arithmetic, sequence and definedness | 75 | 1,632/1,632 | 24 | 2,400/2,400 | 0 | +| Grayscale and RGBA Blend property controls | 128 | 286,720/286,720 | 16 | 327,680/327,680 | 0 | + +The Blend controls use the two sizes, fields, filters and independent property drivers from the [selected-input comparison](#selected-blend-inputs-and-odd-sized-float-backgrounds-in-tile-generators). The additional 16 completed renders compare 40,960 pixels. The regression exercises both the seed spelling and an invented name, checks definedness, and retains the scope check for a known system variable. + +Save twelve of the graphs in MaterialCraft. Repeat the direct seed, sequence, addition, conditional and definedness cases, the two defined integers, the two missing-name controls, and one seed-driven Blend per channel kind. Both applications reproduced their original buffers. All **11,200/11,200** pixels across the 34 reopened renders matched, maximum zero. + +The regression failed before the change and passed afterward. The 410 release node and evaluation tests passed with the committed resources. Formatting, strict workspace Clippy, layering and all ten WebAssembly checks passed. + +### Paired angles isolate the reduced phase of rectangular blur + +Use the [three-tap impulse and modular RGB field](#three-measured-taps-reproduce-the-rectangular-directional-blur-outputs). Compare two different angles chosen to have the same absolute folded phase in F32. First round the absolute turn count times F32(2π) to F32. For the horizontal component add F32(π/2) and round again. Subtract the nearest integer multiple of π in binary64, round to F32 and take the magnitude. The paired targets respectively use adjacent angles with identical stored radians, reflection about a half turn, a whole extra turn, and a shift between the vertical and horizontal axes. At each extent compare both the center coefficient and its immediate neighbor on the longer axis. + +Use the angles below as F32 bit patterns in hexadecimal. Each group lists twelve pairs in order. Batch sixteen consecutive angles per graph, alternating the two members of each pair. Render at 16 × 64 and 64 × 16 using projected extents .3125, .5, .734375, .953125 and 1. At batch b, size j and extent k use seed 116159 + 17b + 5j + k, with zero-based indices. The quarter-turn pairs compare the vertical component of the first angle with the horizontal component of the second. All other pairs compare the vertical components. + +| Pair family | First six angle pairs | Last six angle pairs | +|---|---|---| +| Stored radians | 3e5b467b/3e5b467a, 3e691d8a/3e691d8b, 3e59d225/3e59d226, 3e233d08/3e233d09, 3d7c45e2/3d7c45e1, 3dfb2fbb/3dfb2fbc | 3e54b7a4/3e54b7a3, 3e6dfaa1/3e6dfaa2, 3dd48687/3dd48688, 3dccab29/3dccab28, 3e355f14/3e355f13, 3e365ab0/3e365aaf | +| Half-turn reflection | 3e25172f/3ead7468, 3e442a51/3e9dead7, 3e461361/3e9cf64f, 3e3f7c76/3ea041c4, 3dbf4a89/3ed02d5d, 3e214528/3eaf5d6b | 3df69059/3ec25be9, 3e54090d/3e95fb79, 3e1fa1dd/3eb02f11, 3e5063e3/3e97ce0e, 3d8468ac/3edee5d4, 3e2cc1a2/3ea99f2e | +| Additional turn | 3e67ad41/3f9cf5a8, 3e4633b1/3f98c676, 3e25fc67/3f94bf8d, 3e34d233/3f969a46, 3da23131/3f8a2313, 3e672842/3f9ce508 | 3e1f45e9/3f93e8bd, 3e1be392/3f937c72, 3e55bd83/3f9ab7b0, 3e1a89d4/3f93513a, 3e32eceb/3f965d9d, 3e6b9b59/3f9d736b | +| Quarter-turn axis change | 3e513a7c/3d3b1607, 3e63e822/3ce0bee5, 3e51fbc9/3d3810d7, 3e4e9407/3d45afdc, 3e0d7fb6/3de50090, 3e520f6f/3d37c23b | 3e407ed0/3d7e04ba, 3e3bbd67/3d88852d, 3dad0aec/3e297a88, 3e0d2fd6/3de5a050, 3e659e97/3cd30b3c, 3e6b9f4c/3ca30594 | + +All **480/480** paired coefficient words agree, maximum zero. Each of the 48 pairs admits at least one shared F32 direction value consistent with both coefficients at all five extents. The current approximation falls within the rounding bounds on 176/192 independently measured axes. Across the full three-channel field the 960 branch renders matched **942,690/983,040** raw pixels, maximum 1.78813934e-07. + +Save all six authored graphs in MaterialCraft. Reopen each in both applications at the two sizes and at the first and last extent. Match the sixteen outputs by identifier. Each application reproduced every pixel of its own original. Across applications, **377,468/393,216** pixels matched in 384 reopened branch renders, maximum 1.78813934e-07. The color and grayscale HQ blur roots remain open on their [78 whole-root settings](#directional-blur-weights-across-110-angles-and-two-projection-axes). + +### Rectangular inputs and reopened outputs on seven roots + +Compare Hard Light, Clamp Grayscale, Curvature, HDR Range Viewer Grayscale, Material Switch, PBR Dielectric F0 and Spot Emboss with newly generated inputs. Each root has twelve size, parameter and output-format settings. Material Switch has twelve independently read outputs at each setting. Count a pixel as exact only when all its stored channels agree. + +At zero-based row j, use seed 117731 + 13i + 31j with the inventory index i shown below. For each connected image pin in identifier order, with zero-based pin m and channel c, use ((71x + 37y + 11xy + 17m + 29c + 7j + seed) mod 383)/382. At row 3, multiply by 1.5 and subtract .25. For a normal input or the Curvature input, set X = .35 cos(2π(x+.5)/width) and Y = .35 sin(2π(y+.5)/height). Store ((1+X)/2,(1+Y)/2,(1+√(1−X²−Y²))/2,1). Round integer inputs to the nearest stored level, ties to even. + +| j | Output size | Inputs | Properties | Requested outputs | +|---:|---|---|---|---| +| 0 | 16 × 32 | U8 procedural fields | Defaults | U16, F32 | +| 1 | 64 × 32 | U16 procedural fields | First setting below | U8, U16, F16, F32 | +| 2 | 32 × 16 | All image pins disconnected | Defaults | U16, F32 | +| 3 | 32 × 64 | F32 procedural fields | Second setting below | U8, U16, F16, F32 | + +| Root (index) | First setting | Second setting | Original output renders · exact / compared | Reopened output renders · exact / compared | +|---|---|---|---:|---:| +| Hard Light (41) | Opacity .375, alpha blending off | Opacity .8125, alpha blending on | 12 · 18,432/18,432 | 5 · 7,168/7,168 | +| Clamp Grayscale (73) | Limits (.3125,.6875) | Limits (.125,.84375) | 12 · 18,432/18,432 | 5 · 7,168/7,168 | +| Curvature (119) | Intensity .5625, green inversion off, normal format 1 | Intensity 1.75, green inversion on, normal format 0 | 12 · 18,432/18,432 | 5 · 7,168/7,168 | +| HDR Range Viewer Grayscale (180) | Range (.125,1.5) | Range (−.25,.875) | 12 · 18,432/18,432 | 5 · 7,168/7,168 | +| Material Switch (204) | Switch, ambient occlusion and specular level on. Emissive and opacity off | Same with emissive and opacity on | 144 · 221,184/221,184 | 60 · 86,016/86,016 | +| PBR Dielectric F0 (385) | Preset 1, specular range .625, glass range .375, IOR 1.375 | Same with preset 5 | 12 · 18,432/18,432 | 5 · 7,168/7,168 | +| Spot Emboss (508) | Intensity 1.875, light (.3125,.6875), highlight (.75,.25,.5,.875), shadow (.125,.375,.25,.5) | Same with intensity 2.75 | 12 · 18,432/18,432 | 5 · 7,168/7,168 | + +Material Switch outputs were diffuse, normal, specular, height, roughness, metallic, glossiness, ambient occlusion, base color, emissive, specular level and opacity. The 216 original output renders matched **331,776/331,776** pixels, maximum zero. Save each package in MaterialCraft and reopen it in both applications. Read every selected output by identifier at row 0 U16, row 1 U8, row 2 F32 and row 3 F16 and F32. The 90 reopened output renders matched **129,024/129,024** pixels, maximum zero. Each application also reproduced all its own original buffers. These cases extend the seven roots' existing measured parity. + +### Equal reduced phases with distinct rectangular blur coefficients + +The [48 paired-angle controls](#paired-angles-isolate-the-reduced-phase-of-rectangular-blur) agreed at every tested extent. To distinguish the remaining cases, start with 24 angles where the current direction estimate misses the observed interval. For each, choose a different positive angle with the same F32 folded phase. Keep the same red column impulse, green row impulse, blue modular field, two rectangular sizes and five projected extents. Use seed 121587 + 17b + 5j + k with the earlier batch, size and extent numbering. The table lists the F32 turn words. H selects the horizontal impulse coefficient and V the vertical one. + +| Batch | Paired turn words and axes, in order | +|---:|---| +| 0 | 3e7f6800H/3a17ffd0V, 3e67ad41H/3ef3d6a0V, 3e5b467aH/3eeda33dV, 3e59d226H/3eece913V, 3e520f6fH/3d37c23fV, 3fb9fd7fV/3f99fd7fH, 3e9b0000H/3d580003V, 3f98c676H/3fb8c675V | +| 1 | 3e365aafH/3edb2d58V, 3d965000V/3f969b00H, 3e32ecebH/3d9a2629V, 3da20001V/3f144000V, 3db80000V/3eae0000H, 3dc80000V/3f58ffffH, 3e1a89d4H/3dcaec59V, 3dd48688H/3f92b797V | +| 2 | 3dbf4a89H/3e205abbV, 3f574300V/3f174300H, 3fab1280V/3fb4ed80H, 3da20002H/3fea2000V, 3d7e04baH/3e407ecfV, 3fa62980V/402314bfH, 3fb9fd82H/3e4fec0fV, 3d3ffffbH/3d3ffffaH | + +Twenty-three pairs have identical coefficients at all five extents, and one differs. For H at .249420166015625 turns the stored phase is 3.1379494667053223 radians. For V at .0005798311904072762 turns it is .0036431869957596064. Both absolute folded phases round to F32 word `3b6ec289`. All five center weights agree. All five neighboring weights differ by one F32 word. The five observations constrain the horizontal direction magnitude to `3b6ec265` and the vertical one to `3b6ec266`. A calculation that retains only the rounded absolute folded phase cannot reproduce both. This distinguishes the reduction or subsequent precision even with identical stored input to the existing sine polynomial. + +The 480 original branch renders matched **351,169/491,520** whole RGB pixels across applications, maximum 1.78813934e-07. Save the three graphs in MaterialCraft, reopen them in both applications and repeat the first and last extents at both sizes. All sixteen named outputs reproduced their own originals in each application. Across applications, the 192 reopened renders matched **142,599/196,608**, maximum 1.78813934e-07. Both HQ blur roots remain in progress. + +### Uniform channel width and grayscale rounding in node properties + +Grayscale Uniform preserves a scalar input directly. A fixed four-component color sums red, green and blue in that order, then divides by three. A runtime four-component color multiplies each of those channels by F32(1/3) first, then adds the three rounded contributions from left to right. Alpha does not enter the mean. A three-component function result yields zero in grayscale and opaque black in RGBA. Packing the same RGB with an explicit alpha restores its color. Graph inspection keeps the original RGB parameter available. + +Use (1,2⁻²³,−1,.59375) to distinguish the two means. The fixed F32 result has bits `332aaaab` and the exposed result has bits `33000000`. A fixed signed tuple (−65536,65536,2⁻⁹,.5) yields `3a2aaaab`. Feed the scalar with bits `3ed51632` to either channel mode. In grayscale, it retains that word. The controls also cover three primaries, equal-channel levels, signed colors and permutations of nearly canceling channels. + +For the first dependency series, compare a literal, a folded sum with zero, a bound RGBA color, the same color plus a zero vector, and a sequence that reads the bound color before returning the literal. Also read image size before the literal, take alpha from the bound input, select between the bound and fixed colors, return a scalar channel, or return a scalar after reading size. Use the signed tuple above, (1.75,−.875,−.25,.5), (.1,.1,.1,.25), three copies of `3ed51632` with alpha .875, the HDR cancellation tuple, and (−.4,1.875,.1375,−.5). At tuple j use seed 116491 + 17j, width 16 for even j and 8 for odd j, and height 8 when j is divisible by three and 4 otherwise. Compare F32 at all six and all four formats at j = 0, 2 and 4. + +For the last two series, return the signed cancellation tuple after reading the source, or make its green component (1 + source) × 2⁻²³. Render grayscale and RGBA at 8 × 4, 16 × 8, 32 × 16 and 64 × 16. Use seeds 31, 12071, 68047 and 471817 and exposed scalar values .03125, .25, .875 and 1. Size uses the first width divided by 16, and log size uses the first exponent divided by four. Compare fixed arithmetic after size, log size, tiling, pixel ratio, UV tile, physical size, an unbound integer seed, an invented reserved integer and absent user inputs. Definedness tests on time, the exposed input, a missing input and pixel ratio also use the fixed mean. Reading time, normal format or an exposed value, performing a random draw, and writing a named value use the runtime mean. Both the direct and sequence forms are measured. + +| Raw image comparison | Renders | Exact before / compared | Maximum before by storage (U8 / U16 / F16 / F32) | Exact after / compared | Maximum after | +|---|---:|---:|---|---:|---:| +| Fixed and exposed colors | 192 | 27,456/27,648 | 0 / 0 / 0 / 2.98023224e-08 | 27,648/27,648 | 0 | +| Permutations, equal channels and cancellation | 116 | 1,088/7,424 | — / — / — / 0.895311117 | 7,424/7,424 | 0 | +| Scalar, RGB and RGBA endpoints | 246 | 4,992/7,872 | 255 / 65535 / 1.3125 / 1.3125 | 7,872/7,872 | 0 | +| Packing, selecting and binding channels | 329 | 5,984/10,528 | — / 45055 / — / 65520 | 10,528/10,528 | 0 | +| Folded, bound and sequenced colors | 300 | 19,840/23,040 | 85 / 21845 / 65488 / 65520 | 23,040/23,040 | 0 | +| Image size, seed, time, random draws and assignments | 160 | 54,272/67,840 | — / — / — / 1.98682173e-08 | 67,840/67,840 | 0 | +| Other system variables, missing inputs and definedness | 160 | 64,448/67,840 | — / — / — / 9.93410865e-09 | 67,840/67,840 | 0 | + +Across the seven series, **212,192/212,192** raw pixels matched across 1,503 renders. Save twelve of the system-variable and source graphs and reopen them in both applications. All 20,352/20,352 pixels matched in 48 F32 renders. The earlier 16 saved graphs cover widths, direct links, folded and bound parameters and extreme colors. All 5,568/5,568 pixels matched across 78 reopens. Both applications reproduced their own original buffers. The three regressions failed on the earlier evaluation paths and passed after correction. The 413 release node and evaluation tests, strict Clippy, formatting, layering and all ten WebAssembly checks passed using the committed resource set. In a separate control with the pattern random-order changes disabled, the grayscale and color tile generators and both random tiling roots matched the earlier totals of 757,504/757,504, 621,344/765,184, 291,084/316,672, 498,989/619,776, respectively. + +### Directional blur weights at signed and large rotations + +A directional blur accepts signed angles outside its slider range. A parameter check previously clipped every angle beyond ±33 turns to the endpoint. The regression uses a unit impulse in each of two rectangular images and reads the center pixel and its immediate neighbor along the longer axis. At strength 4, the F32 turn word `c5f564d9` on a 64 × 16 image gives center `3f0f4d94` and neighbor `3e6164db`. The turn word `46f0483d` on a 16 × 64 image gives `3f17a518` and `3e50b5d1`. Authored rotations can reach both results through the ordinary parameter resolver. + +For shorter phases, convert the turns to F32 radians. Use the magnitude of the radians for sine and add F32(π/2) to that magnitude for cosine. Subtract the nearest number of half turns using three parts of π. Start with 3.140625, round the remainder of π to F32 for the middle part, then round the residual to F32 for the low part. A fused multiply and subtraction produces each successive remainder. Restore the sign of the sine after odd half turns. Feeding those remainders to the existing sine polynomial predicts all 64 independently selected axes where the previous and revised reductions disagree. Both predictions fit the 16 controls. All 128 near-axis measurements admit the revised coefficient, up from 125. The earlier [equal-remainder pair](#equal-reduced-phases-with-distinct-rectangular-blur-coefficients) illustrates the lost bit. + +At large phases the implementation evaluates the sine in double precision and stores the F32 result. Eight deliberately distinguishable axes just below 10,000 radians select the split reduction. Eight just above select the wide sine. Across the three large-angle and transition series, the wide sine falls within the observed interval on 170/171 selected axes at or above 10,000 radians. The remaining case at 10011.0888671875 radians differs by one F32 word. Finite turns whose conversion to F32 radians overflows produce a cook error. + +Connect an exposed turn and strength to a directional blur with pixel ratio zero. At index i use turns 0, .125, .24952130019664764, 32.875, 33, 33.03125, −33.125, 41.1875, −118.21875, 817.1796875, 1591.34375, 1594.0625, 8076.78125, −125003.34375, 1080535.625 and −1727287.125. Cycle through strengths 3.25, 4, 4.9375 and 5.8125. Render 16 × 64 and 64 × 16 at all four output formats. Use seed 124151 + 19i + b, where b is the zero-based size index. Red lights the center column and green the center row. Blue is ((67x + 19y + 3xy + 11i + 124151) mod 293)/292. Use F32 inputs at even i. At odd i store nearest-even U16 levels. Compare all output channels at each pixel. + +| Exposed rotation output | Renders | Exact before / compared · maximum | Exact after / compared · maximum | +|---|---:|---:|---:| +| RGBA8 | 32 | 21,930/32,768 · 163 | 32,768/32,768 · 0 | +| RGBA16 | 32 | 21,702/32,768 · 41799 | 32,764/32,768 · 1 | +| RGBA16F | 32 | 19,225/32,768 · 0.637451172 | 31,744/32,768 · 0.00048828125 | +| RGBA32F | 32 | 12,945/32,768 · 0.637816101 | 31,330/32,768 · 1.78813934e-07 | + +Save the four packages and reopen them in both applications. Repeat U8 and F32 at 16 × 64 and U16 and F16 at 64 × 16. Each application reproduced its complete original buffers. Across applications the 64 reopens matched 64,510/65,536 · 1. + +For the fixed rotations, use the [column, row and modular blue field](#independent-rectangular-directional-weights-at-96-angles), both rectangular sizes and all five extents. Each batch contains sixteen independently readable F32 outputs. Use seed S + 17b + 5j + k for base S, batch b, size j and extent k, numbered from zero. Save each graph and repeat the first and last extents at both sizes. Both applications reproduced their own original buffers at every named output. The maxima below are in F32 image units. + +| Fixed rotation series | Seed S | Original renders | Exact before / compared · maximum | Exact after / compared · maximum | Reopened renders | Reopened exact after / compared · maximum | +|---|---:|---:|---:|---:|---:|---:| +| Near axes | 122887 | 1,280 | 1,093,947/1,310,720 · 1.78813934e-07 | 1,094,911/1,310,720 · 1.78813934e-07 | 512 | 406,556/524,288 · 1.78813934e-07 | +| Discriminating pairs and controls | 1232077 | 800 | 709,368/819,200 · 1.78813934e-07 | 737,708/819,200 · 1.78813934e-07 | 320 | 293,842/327,680 · 1.78813934e-07 | +| 8 to 2,097,152 turns | 1239913 | 1,120 | 139,626/1,146,880 · 0.666647226 | 1,122,896/1,146,880 · 1.1920929e-07 | 448 | 448,506/458,752 · 1.1920929e-07 | +| Coarse transition series | 1240507 | 1,280 | 104,359/1,310,720 · 0.666636944 | 1,279,081/1,310,720 · 1.1920929e-07 | 512 | 511,275/524,288 · 1.1920929e-07 | +| Fine transition series | 1245681 | 1,280 | 97,887/1,310,720 · 0.666650057 | 1,275,230/1,310,720 · 1.78813934e-07 | 512 | 509,634/524,288 · 1.78813934e-07 | + +For the near-axis turns, offset the positive F32 words for .25, .5, .75, 1, 1.25 and 2 turns by −521, −121, −37, −13, −5, −2, −1, 1, 2, 5, 13, 37, 121, 521, 1261 and 5279, in order. Append 32 turns with zero-based index m, rounding 2^(−26 + m mod 16) × (1 + .3125 floor(m/16) + (m mod 3)/16) / (2π) to F32. + +
+Fixed F32 turn words for the four comparison series + +H marks the horizontal coefficient and V the vertical coefficient used for the interval comparison. Each branch was rendered in both orientations. + +| Series | Batch | Turn words and selected axis | +|---|---:|---| +| Discriminating pairs and controls | 0 | bf801b79V, bfffcb7aV, 40fffe4cV, bf7fc816V, 40d004e0V, c0f84350H, 3e73ecc0H, be7ff2b5H, 3fffd172V, bf402cebH, beffd187V, c01ffa86V, c01ffa8fV, 40ffb7ffV, 405feb06V, bf001a38V | +| Discriminating pairs and controls | 1 | 3f80229dV, bfdfaee0H, c0801f04V, 3f7fd4bdV, 3f9ce8a3H, c0f7b0b3H, 3e7f8283H, 3f7fc3acV, bfe03d97H, 3fcf537aV, c06fbd74H, c0702ab9H, bfe05074H, 4087fc36H, be8029c5H, 3e7f702fH | +| Discriminating pairs and controls | 2 | 4098069bH, bf8017bcV, 3fbfabd5V, 40d00387V, c05e0de4V, c0cfe5a0V, bfdfd2e9H, 40cffc9cV, 40704614H, 3fdfc859H, c0c80348H, c09002eeV, 3f7fd447V, 4097f8adH, 40a00718V, c01ffa93V | +| Discriminating pairs and controls | 3 | 400ff98bH, be7fcd76H, c0f80045H, c0ffc589V, 40d8690eH, bf7fc9ffV, 40801891V, c087fc2bH, 3e7f6dccH, c09ff92dV, bf801905V, c00ff9e8H, 40c7fb11H, 407fb03bV, 3effb27cV, 3e8031faH | +| Discriminating pairs and controls | 4 | 3f3fb891H, c010018cH, 40f7b393H, 3e7fa8d4H, 400ffad9H, c0703341H, bfdfc445H, c0ffce1fV, 3f402c42H, 3effbf59V, be7f88a1H, befbe270V, 3effbeb6V, bf7f92c8V, 401000dfH, 40801876V | +| 8 to 2,097,152 turns | 0 | c5f564d9H, c3829d11H, c892653fV, 46f0483dV, c3c8ccb2V, c6d7aa62H, c48fd3f4H, c5349a41H, c1f82151V, c57d1db2V, c6f1b553V, c6162ac0H, c3d8807dV, 44f3c253V, c55c5240H, 48630193V | +| 8 to 2,097,152 turns | 1 | c7b4c824H, 4955fc3eH, 423bdc4aV, c19b457bH, 47f2b357H, 4441fb55V, c6e7fb6eV, 46d994baV, c8812dd4V, c9d2d9b9H, 45620584H, 45102284V, c6cb0ccaV, 49d1139fV, c39c8a91H, 49c1f417V | +| 8 to 2,097,152 turns | 2 | 443296a5H, 46c93debV, 427f2c7dH, c4f24859H, 44a6ef1aV, 427b1059H, c88718f4V, 483525d5H, 427e9c19V, c9a11d73V, c6958389H, c5232f8bV, c983e6bdH, 4972898bH, c25f6e28V, 490e318dH | +| 8 to 2,097,152 turns | 3 | c9962d73H, c73640caV, c2283f9fH, 49c74c5fV, 49a9874fV, c1f90534V, 424dfb26V, 49dbf3edH, 49b5c4cfV, 45788578V, c6fe6e70H, c9ac2963H, c8c03f7dV, 487469bdV, c8491c0bV, 469b9707V | +| 8 to 2,097,152 turns | 4 | c891a5cbV, 47b1664fV, c2a81bb3V, c33ebdddH, 43f80165V, c3bac0c5V, c20a03d8V, 496090aaV, 45e799cdH, c8ef3926H, c5742094V, 421a2849H, 49234e27H, c202fea2H, 4510abdcH, c71a48acH | +| 8 to 2,097,152 turns | 5 | 499d0ac5V, 49390a35V, c35174d1H, c39df712V, c304c184H, 48d5dd3dH, c6c03fbdH, 49815e1fV, c89e7396H, c810da97V, 419a2191H, c38f477eH, 486c76d9H, c6d8a158H, c21910c2H, 47f28ddaV | +| 8 to 2,097,152 turns | 6 | c9f8e01fH, 441a57d3H, 43d7754eH, 43da7f51V, 43fe62c8H, c7b65a38H, 4687ba9aV, c91f36e3H, c9809e1fH, 47d08363H, c715fa3aH, 43eafe8bV, 49e4fe55H, c8eb4275V, 4257750aV, 473e2515V | +| Coarse transition series | 0 | c4ec1bdaV, 44aa8966H, 441e20e0H, c4ede6d8V, c50568fdH, 4485f58bH, 44fa5729V, 441db091V, 45049d1fV, 44922997H, 45822702V, 44c97fd9H, c4a33adcH, 4490af21V, 44a461d5V, c4f53abbH | +| Coarse transition series | 1 | 449ed8eaV, 44a2f0aaH, 44a4631eV, 44a485d4V, 449ed0eaH, c485fd8bV, c4aff79bV, c4a2a80eV, c4a2e7abH, c49f2c0bH, c4a6eff5H, c4ce18a3H, 44a311fcV, c41e30e0V, 449ee0dbH, c4f571aeH | +| Coarse transition series | 2 | c496e556V, c4923197V, 44a2fb3bH, c4b8a7dbV, 4491c633V, c41da091H, 44a3c992H, 447f4b3eV, c497e5eeH, 4496dd56H, c4a2d9dfH, c4838ce0V, c4a3d192V, c4a330afV, c4a2f8b8H, c5a00607V | +| Coarse transition series | 3 | 44b97f65V, 44b9ef5fH, 44a1466aH, 44a3067dH, c4a2e7ccV, 44a33271V, 459dd32fH, 44783df6V, 44a47dd4H, 44a2f0b2H, 44250419H, 450ad7c1H, 4491be33H, 44251419V, 44a3c1adV, c4edcea2V | +| Coarse transition series | 4 | 44920affH, c497edeeV, c4c8156fH, c5a00407H, c490a721H, c422fd55H, c4c987d9V, 44a30170V, 44a2efabV, 44230d55V, 44e97e25H, 44a14e6aV, c4c81d6fV, c5967d14V, 45822502H, c497c96eH | +| Coarse transition series | 5 | c4a1d92fV, c498e0fcV, c4bc02d4H, 4498d8fcH, 449f340bV, 44a06f51H, 44bc0ad4V, 44a32a71H, c4a23973V, c4ed5006H, c4e65877V, c4ce20a3V, 44a3b9adH, c4a300b8V, 44e95813H, c4a45b1eH | +| Coarse transition series | 6 | c4782df6H, 44ab5fb7V, c4a1d12fH, c4ab57b7H, c4a2a00eH, 44a50aafH, c497d16eV, 449ee8dbV, c4a309fcH, 44cadf56H, 44ada7c6V, 44b97765H, c4a23173H, c5056cfdV, c47f3b3eH, 450adbc1V | +| Coarse transition series | 7 | 44a2f8aaV, 44aee9e2V, 44a2e1dfV, 44a30e7dV, 45af1a15H, 44e6c344H, c4b9f75fV, c4aa461fH, 459dd52fV, c48384e0H, c4a07751V, c4aa89f8H, 449212ffV, c4a6e249V, 44cb0927V, c4b9af3dH | +| Fine transition series | 0 | 44bdbdf4V, c4c731f7H, c4c2eb04V, c4c71ff6V, c4c777caV, 44c6e2b4V, 44c6c7eaH, 44c70297V, 44c6b96cH, 44c54057V, 44c50fe9V, c4c703e2H, 44c70be2V, 44c72a0eV, c4c717dcV, c4c9b79eV | +| Fine transition series | 1 | c4c6f2e0V, 44bd700bV, c4c6d6deH, c4c6ed44V, 44c6c06eH, 44c6b067H, 44c6e52bH, 44c6eb64H, c4c6e839V, 44bdb5f4H, c4c6a430V, c4cd0305H, c4c6d0f5H, c4c70fdcH, 44c6ed2bV, c4c8fd59H | +| Fine transition series | 2 | 44c6e872H, 44c69c30H, c4bd680bH, 44c6da77V, c4c2c1a2H, c4c6c86eV, 44c6e544H, 44cbbbefH, 44c6a20dH, c4c6c91cV, c4d00623H, c4c6f813H, 44c6f364V, 44c6f009H, 44c72a9fH, 44c45c03V | +| Fine transition series | 3 | c4c6f6adV, c4c7147aV, 44be460aV, c4c6b867V, 44c6f02bH, c4c6e925V, 44c9af9eH, 44c6eeadH, c4c6f4c8V, c4c6e32aH, 44c70a1cV, c4c86744V, c4c6f09aH, c4c68724V, c4ca3d43H, c4c6f254V | +| Fine transition series | 4 | 44c53857H, c4c2e304H, c4c3a2c5V, c4c6e079H, c4cea9b6H, 44c6bf24H, c4c83b5fH, c4c51ab2V, c4c3ae6aV, c4cc0eb4V, 44c185feH, c4c74a4fH, c4c6aa0dV, c4c6ffa8V, 44c6f0dbV, c4c6eb3aH | +| Fine transition series | 5 | c4c6efa1V, 44cfe373V, c4c6d277H, 44c6e801H, 44c8eb14V, c4c6e745H, 44cde3b5V, c4ceb1b6V, 44c547a2H, 44c6dedeV, c4c6f4c5H, 44c758f0H, c4c90559V, 44c6f0faV, 44c67f24H, 44c70c7aH | +| Fine transition series | 6 | 44c6f2e0V, 44c6f89aV, 44bede62H, c4c6c16cV, c4c6c724V, c4c6e8dbH, 44caba23V, c4c7329fV, c4c6881dH, 44c8e314H, c4c6e696V, c4c717f6H, c4c6ef45V, 44c42494H, c4c7524fV, c4d00e23V | +| Fine transition series | 7 | c4c18dfeV, 44c70013V, c4c6901dV, c4c2fd10H, c4c82285V, c4c6eae0H, c4c72ce3V, 44c6fdafH, 44c6f7a8H, c4cddbb5H, c4c724e3H, 44c507e9H, c4c76fcaH, 44c6de96H, 44c6eae0H, 44c6f673V | + +
+ +The whole-root comparison uses the [78 settings per HQ blur](#directional-blur-weights-across-110-angles-and-two-projection-axes), including default and changed properties, seeds and all four formats. The two independent saved rectangular series have 60 renders per root. Both applications reproduced their own originals. + +| Whole root | U8 exact / compared · maximum | U16 exact / compared · maximum | F16 exact / compared · maximum | F32 exact / compared · maximum | Reopened exact / compared · maximum across storage formats | +|---|---:|---:|---:|---:|---:| +| Color HQ blur | 706,504/706,560 · 1 | 1,169,141/1,169,408 · 257 | 591,816/591,872 · 0.00439453125 | 1,192,949/1,193,216 · 0.0039215982 | 3,489,146/3,489,792 · 257 | +| Grayscale HQ blur | 706,545/706,560 · 1 | 1,169,358/1,169,408 · 257 | 591,857/591,872 · 0.00390625 | 1,193,166/1,193,216 · 0.0039215982 | 3,489,662/3,489,792 · 257 | + +Both whole roots retain differing pixels. The two impulse regressions failed on the previous renderer and passed after the change. The 416 release node and evaluation tests, formatting, strict Clippy, layering and all ten WebAssembly checks passed using the committed resource set. + +### Shared random draws in pattern branches and returned color channels + +In a pattern tint, a random draw used by a conditional arm and a later channel keeps its place in the order of the arms. The condition runs first. With the false arm selected, the tested draws shared with the skipped true arm run before the false result. With the true arm selected, its result runs before draws needed from the false arm. A scalar selection from a packed vector visits the supplying component. In a straight-line called function with scalar inputs, the first uses of those inputs determine their evaluation order. Repeated reads reuse the same draw. + +Use one full-coverage rectangle, additive color on a black background, with unit alpha and independent unit draws A, B, C, D and E. Set the RGB result to (if take then lerp(A,B,C) else D, E, A). At seed 31 the F32 words for true are `3f51c505 3e9a198c 3f3457e6` and for false are `3f5a33c2 3f46fab2 3f3457e6`. Replace the false arm with lerp(C,B,D) and return D in blue. True gives `3f51c505 3f5b5a9e 3e9a198c` and false gives `3f3cc6a3 3e9a198c 3f46fab2`. Test all four combinations of two Boolean inputs when nesting the arms. Use 16², 32 × 16 and 16 × 32 with seeds 31, 12071 and 68047 respectively, and range inputs .25, .625 and .9375. + +For the channel controls, form RGBA from two pairs of unit draws. Select individual channels, reverse or repeat them, try a padded channel and reuse an original draw in a later output. For the call controls expose red, green and blue as scalar arguments, each wired to a distinct draw. Return (blue,green,red), (blue,blue,red) or selected arithmetic on them. Compare the whole result and a single selected result assembled with the caller's next draw. Repeat with three return channels derived from one packed RGBA argument. The four F32 settings use 16² seed 31 with the switch off and on, 32 × 16 seed 12071 with it off, and 16 × 32 seed 68047 with it on. The saved controls preserve the original connections and argument order. + +| F32 comparison | Renders | Earlier exact pixels / total · maximum | Current exact pixels / total · maximum | +|---|---:|---:|---:| +| Shared draws and branch controls | 84 | 29,184/32,256 · 0.852352262 | 30,720/32,256 · 0.852352262 | +| Two conditional arms, nested branches and assignments | 216 | 58,880/92,160 · 0.836026192 | 89,600/92,160 · 0.836026192 | +| Channel selection through nested vectors | 136 | 4,608/52,224 · 0.836026192 | 49,152/52,224 · 0.836026192 | +| Three scalar function inputs in different return orders | 104 | 6,144/39,936 · 0.836026192 | 23,040/39,936 · 0.836026192 | +| Returned channels with sums, products and interpolation | 96 | 1,536/36,864 · 0.836026192 | 29,184/36,864 · 0.873463869 | +| One vector argument with reordered and repeated channels | 180 | 0/69,120 · 0.836026192 | 11,520/69,120 · 0.836026192 | +| Channel selection with a local assignment or sequence | 80 | 1,536/30,720 · 3.07092288e+16 | 13,824/30,720 · 3.07092288e+16 | + +The first six groups went from **100,352 to 233,216 exact pixels out of 322,560** across 816 renders. Another 338 renders matched every pixel. Each render retained or increased its exact count. The largest error in the arithmetic-call group increased from .836026192 to .873463869. Some last-group graphs read a variable without an executed write. That row reports exact captured pixels and the largest finite component difference. The captures include non-finite values, so the value of an undefined read remains unresolved. + +| Saved graph family | Packages | Reopened renders | Cross-application exact pixels / total · maximum | +|---|---:|---:|---:| +| Packed channel selections | 10 | 40 | 15,360/15,360 · 0 | +| Scalar call arguments | 7 | 28 | 6,144/10,752 · 0.798588514 | +| Shared conditional draws | 8 | 32 | 11,520/12,288 · 0.271984816 | +| Packed call arguments | 10 | 40 | 1,536/15,360 · 0.836026192 | + +Each application reproduced every pixel of its own original renders after reopening these files. Calls with vector inputs, arithmetic-dependent selections, assignments and nested conditionals retain measured differences. + +Across all 958 previously recorded settings for roots 373–376, 441, 488 and 491, the exact counts and maxima are unchanged. Grayscale Tile Generator remains exact in **757,504/757,504** pixels across 221 settings. Color Tile Generator matches **621,344/765,184** across 331. Its per-channel tint draws still differ. A call with unknown dependencies can read a variable assigned in its caller, so those graphs retain their existing evaluation order. Four node regressions reproduced the earlier errors. All 416 release tests in the node and evaluator crates passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Rectangular inputs and remaining half-float pixels in the eighth specular passes + +Repeat the [eighth specular pass comparison](#eighth-raytraced-specular-passes) for both root packages. The complete 26-setting capture at `02d910f` and a repeat of one 128² setting per root at `a45240f` give the counts below. The earlier first-pass report had 279 differing pixels in root 396. Five remain in the complete capture. Every floating-point difference in those two matrices is in F16. + +| Root | Full matrix, exact / total | F16 exact / total · maximum | 128² F16 repeat, exact / total · maximum | +|---|---:|---:|---:| +| 396 | 142,335/142,340 | 119,883/119,888 · 0.0009765625 | changed, 16,383/16,384 · 0.0001220703125 | +| 408 | 142,337/142,340 | 119,885/119,888 · 0.000244140625 | default, 16,383/16,384 · 0.000244140625 | + +For an independent rectangular test at `a45240f`, use output sizes 8 × 4, 4 × 8, 16 × 8 and 8 × 16, with input sizes 8 × 4, 8 × 4, 16 × 8 and 8 × 16 respectively. Number these settings j from zero and use seed 126331 + 31j. Number input identifiers m in alphabetical order and RGBA components c from zero. Store each source channel as F32 using ((29x + 43y + 7xy + 61m + 17c + 3cx + seed) mod 257)/256. Use channel zero for height and blue noise. Decode the first two normal channels to signed values, multiply by .45, reconstruct positive Z and encode back to [0,1], with alpha one. Position uses texel-center UV, .3125 + .375 times channel two and alpha one. + +Keep the first setting at defaults. At j = 1, 2 and 3 set shape to 1, 2 and 0 respectively, scale to .625 + .0625j, plane size to (.75,1.125), rotation to .03125j, rotation direction to −.0625j, displacement to .015625j, UV tiling to 1.125 and UV offset to (.1875,−.3125). Compare F16 and F32 for each setting and add U8 and U16 at j = 0 and 2. Save one package per root, reopen it in both applications, and compare j = 0/U16, 1/F16, 2/U8 and 3/F32 to the original renders. + +| Root | New renders | U8 exact / total · maximum | U16 exact / total · maximum | F16 exact / total · maximum | F32 exact / total · maximum | Reopened exact / total · maximum | +|---|---:|---:|---:|---:|---:|---:| +| 396 | 12 | 160/160 · 0 | 160/160 · 0 | 320/320 · 0 | 320/320 · 0 | 320/320 · 0 | +| 408 | 12 | 160/160 · 0 | 160/160 · 0 | 320/320 · 0 | 320/320 · 0 | 320/320 · 0 | + +Each application reproduced every component of its own saved-file controls. Both roots remain in progress on the full-size F16 settings. + +### Caller texture precision in typed reads and the UV debug marker + +A typed value function, a pattern property function, a bitmap stamp and a pattern background connected directly to a child graph’s image input read the compatible caller texture with its dimensions, storage depth and available mip levels. A square marker connected this way inside a graph instance exposed the difference. In the [earlier 90 settings](#fixed-integer-arguments-and-the-uv-debug-marker), the preceding build matched 284,157/284,160 pixels. At 32² with index 0, count 1, offset 0 and debug position (.375,.6875), red at (9,19), (10,20) and (11,21) was 15,898 instead of 15,899 in U16. Rounding the F32 source to U16 before feeding it to the parent makes both applications produce 15,898. The corrected evaluator reads the supplied texture when the source is an enabled child input of matching image kind. + +For the independent UV fields, render 32² and 64 × 32. At pixel (x,y) set component c of the F32 input to ((37x + 41y + 7xy + 53r + 61c + 5xc) mod 509)/508 for c = 0,1,2,3. Use (index, count, offset, debug position, r) of (0,1,0,(.375,.6875),19), (1,8,0,(.421875,.765625),19), (0,1,0,(.28125,.71875),41) and (0,1,0,(.626953125,.3974609375),73). For each row j and size b from zero use seed 125141 + 17j + 3b. Compare the original float field, the nearest U16 and U8 levels stored in F32, half precision stored in F32, U16 and U8 PNG inputs, and two F32 variants with RGB shifted by ±.375/65535 and clamped to [0,1]. Compare every stored component at all four output depths. + +| Root 454 storage | Earlier 90, exact / pixels · max | Current 90, exact / pixels · max | Additional renders | Additional before, exact / pixels · max | Additional after, exact / pixels · max | +|---|---:|---:|---:|---:|---:| +| RGBA8 | 120,832/120,832 · 0 | 120,832/120,832 · 0 | 64 | 98,297/98,304 · 191 | 98,304/98,304 · 0 | +| RGBA16 | 18,429/18,432 · 1 | 18,432/18,432 · 0 | 64 | 98,294/98,304 · 49188 | 98,304/98,304 · 0 | +| RGBA16F | 18,432/18,432 · 0 | 18,432/18,432 · 0 | 64 | 98,107/98,304 · 0.7504882812 | 98,304/98,304 · 0 | +| RGBA32F | 126,464/126,464 · 0 | 126,464/126,464 · 0 | 64 | 98,304/98,304 · 0 | 98,304/98,304 · 0 | + +To isolate the input read, wire the original field into a child graph. In one graph return a typed four-channel sample. In another assign that sample to a full-coverage square’s tint on black. Keep the parent input F32 and choose U8, U16, F16 or F32 on the child input. Use coordinates (.375,.6875), (.28125,.734375), (.375,.6875), (.421875,.765625), (.626953125,.3974609375), (.2138671875,.8798828125), (.28125,.71875) and (−.03125,1.09375), and seeds 126071 + 17j. The first four outputs are 32², followed by 64 × 32, 16 × 32, 32 × 16 and 16 × 32. Inputs are 32² except cases 4, 6 and 7 which use 64 × 32. Use the U16-rounded F32 source for case 2, the half-rounded source for case 3 and the U16 PNG for case 6. At the first coordinate the typed F32 value is (.447342515, .430118084, .412893713, .646161437). For bitmap stamps, use unit size and nearest filtering, half size and linear filtering, or quarter size and automatic mip selection. Use cases 0, 2, 3, 4, 5 and 6 in each depth. For a background-only control disable the stamp and wire the same input to its background. + +| Isolated operation | Renders or typed reads | Before, exact / compared · max | After, exact / compared · max | +|---|---:|---:|---:| +| Typed F32 vector | 32 | 9/32 · 0.00143660605 | 32/32 · 0 | +| F32 pattern tint | 32 | 8,704/30,720 · 0.001405417919 | 30,720/30,720 · 0 | +| Unit nearest bitmap | 24 | 8,740/24,576 · 0.003619194031 | 24,576/24,576 · 0 | +| Half-size linear bitmap | 24 | 19,975/24,576 · 0.001777678728 | 24,576/24,576 · 0 | +| Quarter-size automatic bitmap | 24 | 23,424/24,576 · 0.1906615794 | 24,576/24,576 · 0 | +| Connected background | 24 | 8,704/24,576 · 0.002080440521 | 24,576/24,576 · 0 | + +Switching the reference child from F32 to the three lower depths preserved 24/24 typed vectors and 23,040/23,040 tint pixels. The three nested mip controls retain 18,432/18,432 exact pixels. Compute Irradiance and Compute Ray Direction each retain 217,088/217,088 exact pixels in their 32 recorded settings. + +| Reopened graph | Packages | Renders or typed reads | Cross-application exact / compared · max | +|---|---:|---:|---:| +| Original UV parents | 6 | 42 | 56,832/56,832 · 0 | +| Independent UV parents | 4 | 64 | 98,304/98,304 · 0 | +| Bitmap stamps | 2 | 12 | 12,288/12,288 · 0 | +| Sampled pattern tint | 2 | 8 | 9,216/9,216 · 0 | +| Typed sample | 2 | 8 | 8/8 · 0 | + +Both applications reproduce their original stored results on reopening every package in the table. Root 454 matches **677,376/677,376 pixels across 346 measured renders**. The typed and pattern regression reproduced the earlier conversion. All 418 release tests across the evaluator and node crates passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Returned channels of a packed argument in pattern functions + +A pattern call that returns channels selected from a packed argument draws the caller’s scalar sources in the order the result needs them. Selecting the same source twice reuses its draw. The evaluator traces an argument through a function containing only typed argument reads, vector packs and channel selections. A scalar selection can then evaluate the supplying register directly. A whole vector result evaluates the supplying registers in return order. Both four-float and color-widget defaults represent a four-channel argument. + +Use the [full-coverage rectangle and seed-31 draw sequence](#shared-random-draws-in-pattern-branches-and-returned-color-channels). Pack four independent unit draws A, B, C and D into RGBA and pass them as one argument. Return (D,C,A), (A,D,B), (B,B,B) or (D,D,C). At seed 31 the whole (D,C,A) return has RGB words `3f3457e6 3f5a33c2 3f46fab2`. Return (D, first channel of the call, next draw E) instead to get `3f3457e6 3f3457e6 3f5a33c2`. Repeat with the caller selecting the third or second returned channel and with a Boolean selecting between D and the call’s first channel. The four F32 settings use 16²/31 with the switch off and on, 32 × 16/12071 with it off and 16 × 32/68047 with it on. + +| Callee at four F32 settings and five caller wirings | Renders | Earlier exact pixels / total · max | Current exact pixels / total · max | +|---|---:|---:|---:| +| Direct or repeated channels | 80 | 3,840/30,720 · 0.8360261917 | 30,720/30,720 · 0 | +| Interpolation | 20 | 2,304/7,680 · 0.7985885143 | 2,304/7,680 · 0.7985885143 | +| Addition | 20 | 1,536/7,680 · 0.8360261917 | 1,536/7,680 · 0.8360261917 | +| Conditional | 20 | 2,304/7,680 · 0.8360261917 | 2,304/7,680 · 0.8360261917 | +| Additional random draw | 20 | 0/7,680 · 0.8360261917 | 0/7,680 · 0.8360261917 | +| Assignment | 20 | 1,536/7,680 · 0.8360261917 | 1,536/7,680 · 0.8360261917 | + +The complete 180-render family improved from 11,520 to 38,400 exact pixels out of 69,120. The direct and repeated channel cases are exact. The arithmetic, conditional and stateful cases retain the listed differences. + +Independently author a function with a two-, three- or four-channel slider argument, or a four-channel color argument. Give each function a distinct name and an explicit same-package reference. Pack independent draws into the argument and return (last, penultimate, first). Compare the whole return, (last original, first returned, E), and (third returned, second original, E). Use 16²/seed 0, 32 × 16/31, 16 × 32/12071 and 32²/68047. Compare each configuration at all four output depths. + +| Output depth | Renders | Earlier exact pixels / total · max | Current exact pixels / total · max | +|---|---:|---:|---:| +| RGBA8 | 48 | 2,304/27,648 · 213 | 27,648/27,648 · 0 | +| RGBA16 | 48 | 2,304/27,648 · 54789 | 27,648/27,648 · 0 | +| RGBA16F | 48 | 2,304/27,648 · 0.8357315063 | 27,648/27,648 · 0 | +| RGBA32F | 48 | 2,304/27,648 · 0.8360261917 | 27,648/27,648 · 0 | + +| Saved graph family | Packages | Reopened renders | Earlier cross-application exact pixels / total · max | Current cross-application exact pixels / total · max | +|---|---:|---:|---:|---:| +| F32 function controls | 10 | 40 | 1,536/15,360 · 0.8360261917 | 10,752/15,360 · 0.8360261917 | +| Independent widths and output depths | 4 | 16 | 0/9,216 · 36135 | 9,216/9,216 · 0 | + +Each application reproduced its own original buffers after reopening all 14 packages. Four earlier families covering scalar calls, channel arithmetic, swizzles and conditionals retain their original per-render counts and maxima. Across the 958 recorded settings for roots 373–376, 441, 488 and 491, all per-render counts and maxima are unchanged. Color Tile Generator still matches 621,344/765,184 pixels across 331 settings. Its per-channel tint order remains open. The packed-argument regression reproduced the wrong sequence with a color-widget default. All 418 node and evaluator release tests and the formatting, workspace Clippy, layer and WebAssembly checks passed. + +### Finite loops that reach a fixed point in path-length graphs + +A finite function loop can reach a state that repeats on every remaining iteration. At a pair of consecutive condition checks the evaluator compares the random stream, the written variable names, the values visible inside the function and the assignments visible to its caller. Identical state gives the same subsequent body and condition. The evaluator returns the last body result. It samples these pairs at powers of two to avoid copying state on every iteration of a changing loop. Float comparisons preserve the component bits, including the sign of zero. + +For a small reproduction of [the path-length cases](#skipped-loops-and-path-buffers), start with a zero RGBA F32 image. At (0,0) store (1,1/W,1/H,1/W) and at (1,0) store (N+1,1,1,1/W), where W and H are the input dimensions. On row 1 use the first N positions of (.21875,.34375), (.75,.390625), (.640625,.796875), (.390625,.84375), (.125,.546875), then duplicate the first position. Set blue to 1 and alpha to −.25 for the first point, −.125 for the duplicate and −1 for interior points. Use (W,H,N) of (4,4,1), (4,4,2), (8,8,3) and (16,16,5). Set scale to (1.25,.8125). Test no passthrough with intermediate lengths off and on at F32, passthrough with intermediate lengths on at F32, then intermediate lengths on with passthrough off at U16, F16 and U8. The seed is 128101 + 11N + the zero-based setting index. + +In the 8² three-vertex test, the reference header at (1,0) stores 3.816796064376831. Starting at iteration 1, the observed cursor and sampled position are both (0,0). The length, sampled texel and exported assignments are identical on consecutive visits. MaterialCraft gives the same F32 word at this pixel with an experimental cap of 1, 2, 3, 4, 8, 16, 32 or 64. The authored loop allows 65,536 iterations. A selected-pixel trace also found continuing sums in the resized-input cases below. + +For an independent field use (W,H,N) of (4,8,2), (8,4,3), (8,16,4), (16,8,5), (16,16,7) and (32,16,8). In geometry j from zero, set vertex h to (((11h²+9h+5j+13) mod 101)/112, ((7h²+19h+13j+7) mod 109)/128). Retain the same header, alpha flags and duplicated closing vertex. Test defaults at F32, intermediate lengths on with passthrough off and scale (.6875+.03125j,1.4375−.0625j) at all four formats, and passthrough on with intermediate lengths on at F32. Use seed 129011 + 61j + 7m, with modes m = 0, 1, 2. Independently wire geometries 0, 2 and 4 through parent graphs at all four output formats. + +| Whole path-length graph | Attempted | Earlier comparable | Earlier exact pixels / compared · max | Current comparable | Current exact pixels / compared · max | +|---|---:|---:|---:|---:|---:| +| Previously published direct inputs | 9 | 9 | 774/774 · 0 | 9 | 774/774 · 0 | +| Transformed vertices with a 16² source | 6 | 1 | 256/256 · 0 | 1 | 256/256 · 0 | +| Path headers at the requested size | 6 | 0 | 0/0 · 0 | 6 | 8,448/8,448 · 0 | +| One, two, three and five distinct vertices | 24 | 15 | 228/228 · 0 | 24 | 1,764/1,764 · 0 | +| Independent square and rectangular path buffers | 36 | 14 | 838/838 · 0 | 36 | 5,446/5,446 · 0 | +| Three independently authored graph parents | 12 | 4 | 128/128 · 0 | 12 | 1,664/1,664 · 0 | + +Across the 93 settings, 45 formerly rejected renders now match. All 18,352 compared pixels match, with maximum zero. Five renders still exceed the execution budget when a 16² seven-vertex input is resized for 32² or 64² output. At (1,0) in the 32² F32 case the reference stores 75,845.5859375. The running sum changes across iterations here. An error image supplies no comparable samples. + +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. + +### Repeating increments in finite path-length loops + +Five [resized path-length settings](#finite-loops-that-reach-a-fixed-point-in-path-length-graphs) previously exhausted the execution budget. In these cases the path cursor revisits the same vertices while its length continues to grow. In the original 16² to 32² F32 case, expose the square-root term of the final scalar addition without changing the cursor or condition. At output (1,0), seven initial increments lead into a period of four. The four measured F32 increments are .23174433410167694, 2.1718389987945557, .9635875225067139 and 1.26210618019104. Replaying the ordered additions to iteration 65,536 gives exactly 75,845.5859375. At (13,1), the period begins after two steps and produces 75,860.09375. The trace predicted all seven reference pixels with observed periods. A separate zero-valued control had no observed period in its first twelve steps. + +The evaluator recognizes a final scalar addition assigning its result back to the same variable. It checks that the rest of the body, the exit condition and called functions do not read or write that sum. When the remaining variables, exported assignments and random stream repeat, it replays the observed increments in their original order and precision. Replayed additions consume the execution budget. Returning to the same accumulated bits after a full period also preserves the result for any remaining complete periods. + +Repeat all 93 prior settings and resize the six [independent vertex fields](#finite-loops-that-reach-a-fixed-point-in-path-length-graphs), in their published order, to 8², 8², 16 × 32, 32 × 16, 32² and 16 × 32. Keep their vertex headers, graph parameters and six output-mode combinations. Set the seed to 132337 + 67j + 7m with geometry j and mode m numbered from zero. The comparison uses the actual output dimensions, including one-texel results. + +| Whole path-length graph | Settings | Exact pixels / compared | Maximum error | +|---|---:|---:|---:| +| Previous whole-graph settings, including the five resized fields | 93 | 26,544/26,544 | 0 | +| Additional resized path fields | 36 | 13,446/13,446 | 0 | + +Across these 129 settings, the measured storage formats gave 6,593/6,593 U8 pixels, 6,593/6,593 U16 pixels, 6,593/6,593 F16 pixels, 20,211/20,211 F32 pixels, all at maximum zero. Ten reopened full-source settings reproduced 2,161/2,161 pixels, twelve reopened parent settings reproduced 1,664/1,664, and eleven reopened resize settings reproduced 4,737/4,737. Cross-application maximum error was zero in each group. Each application also reproduced its original buffers after reopening. + +The regression alternates .1 and .3 for 65,537 steps and checks both the returned sum and the assignment read afterward. The former evaluator exceeded its budget. A second test reads the sum inside both the term and the exit and reaches 12. Existing original loop controls retained 28/28 exact typed values and 10,240/10,240 exact pixels. All 424 node and evaluator release tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Accumulating the first aligned pair in a sheared blur + +The four [color HQ blur differences](#sampling-both-passes-of-a-long-oblique-blur) trace to a horizontal window in the second blur branch. Its inverse shear at (161,11) combines rows 24 and 25 with weights 32/256 and 224/256. Repeating each displaced row down a separate image isolates the window from both shears. Row 24 gives alpha 117 in both applications. On row 25 the reference stores 116 and the previous window stores 117. + +A single directional blur reproduces the issue with thirteen U8 texels. At 256², repeat the levels 122, 108, 102, 106, 107, 117, 120, 123, 126, 125, 122, 121 and 119 in columns 155 through 167 of every row, and use zero elsewhere. Put the same level in each channel. At .4375 turns and intensity 6.579375267028809 the sampling window at column 161 starts with columns 167 and 166. Starting with the full texel before the fractional endpoint makes the endpoint product and addition round together. The normalized result before U8 storage moves from `3eea0000` to `3ee9ffff`. The byte moves from 117 to the measured 116. At strengths 6.578125 and 6.5859375 the target byte is 116 and 117 respectively. Across these three strengths and four formats, all 786,432 standalone pixels match, maximum zero. + +For independent direction and alignment checks, number the geometry j, channel c and field h from zero. Let i be the integer coordinate along the selected filter axis and L = (37i + 19i² + 71c + 3ic + 11j + 53h) mod 509. Supply (L−170)/256 at h = 0 and L/508 at h = 1 and 2 in F32. At h = 2 multiply by 1.125 where (x+y) mod 3 is zero and by .9375 elsewhere. Set intensity to 256r/min(W,H), with radius r as tabulated. For each geometry use all four output formats at h = 0 and 1, then F32 at h = 2 and a separate zero-intensity F32 control. Use seed 133651 + 43j + 7h. + +| Geometry series | Width × height, angle in turns, radius | +|---|---| +| Wider windows | (64 × 64, 0.4375, 6.5793753), (64 × 64, 0.1875, 6.5793753), (128 × 64, -0.078125, 8.1875), (64 × 128, -0.3125, 8.1875), (64 × 32, 0.09375, 4.59375), (32 × 64, 0.34375, 4.59375), (128 × 64, 0.390625, 12.8125), (64 × 128, 0.234375, 12.8125), (32 × 32, 0.125, 5.125), (32 × 32, -0.375, 13.625), (128 × 128, 0.046875, 17.3125), (64 × 128, -0.21875, 3.5625) | +| Narrow projection on an elongated image | (32 × 256, 0.215, 3.375), (256 × 32, 0.035, 3.375), (32 × 256, 0.215, 6.5625), (256 × 32, 0.035, 6.5625), (32 × 256, -0.215, 9.5), (256 × 32, -0.035, 9.5) | + +For the wider windows, an independent reconstruction using the documented mip reduction and a single rounding on the first aligned pair predicts all 1,792/1,792 along-axis samples in the signed and nonnegative F32 stripe fields. Both orientations are included. + +| Direct control series | Settings | Earlier exact pixels / compared | Current exact pixels / compared | Current maximum by storage | +|---|---:|---:|---:|---| +| Twelve wider geometries | 120 | 712,734/716,800 | 716,800/716,800 | U8 0, U16 0, F16 0, F32 0 | +| Six elongated geometries | 60 | 471,329/491,520 | 491,520/491,520 | U8 0, U16 0, F16 0, F32 0 | +| Isolated alpha, repeated rows and thirteen-texel input | 57 | 3,722,565/3,735,552 | 3,735,549/3,735,552 | U8 0, U16 1, F16 0, F32 0 | +| Six previous dense geometries | 36 | 420,798/442,368 | 426,356/442,368 | U8 0, U16 1, F16 0.00048828125, F32 1.78813934e-07 | + +The prior impulse controls retain 16,572,416/16,572,416 raw pixels in 493 renders. In the isolated alpha series the remaining three mismatches are one U16 level. The previous dense series still exposes F32 arithmetic differences on the 128 × 64 field at 81/2048 turns. + +For the complete roots, repeat the previous 110 settings. Then use H = ((61x + 37y + 13xy + 31⌊y/4⌋ + 67c + 11xc + 53j) mod 1021)/1020, with channel zero for grayscale. Round integer sources to the nearest level. At geometries 4 and 5 use 1.75H−.375. At each size compare all four output formats using seed 133771 + 61j. + +| j | Output size | Source size and storage | Intensity | Quality | +|---:|---|---|---:|---:| +| 0 | 64 × 128 | 32 × 64, F16 | default | default | +| 1 | 256 × 128 | 256 × 128, U16 | 17.0625 | 1 | +| 2 | 128 × 256 | 128 × 256, U8 | 20.59375 | 1 | +| 3 | 256 × 256 | 128 × 256, U16 | 9.96875 | 1 | +| 4 | 128 × 128 | 64 × 128, F32 | 14.28125 | 0 | +| 5 | 32 × 256 | 32 × 128, F32 | 26.75 | 1 | +| 6 | 256 × 32 | 128 × 32, U16 | 19.40625 | 1 | +| 7 | 64 × 64 | 64 × 64, F16 | 0.0 | 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) | 142 | 1,163,264/1,163,264 · 0 | 1,626,112/1,626,112 · 0 | 1,048,576/1,048,576 · 0 | 1,649,920/1,649,920 · 0 | +| Grayscale HQ blur (56) | 142 | 1,163,264/1,163,264 · 0 | 1,626,112/1,626,112 · 0 | 1,048,576/1,048,576 · 0 | 1,649,920/1,649,920 · 0 | + +Each root matches 5,487,872/5,487,872 original pixels. At the disputed root output the alpha is 157/255 in both applications. Each root also matches 4,241,408/4,241,408 pixels across 82 reopened settings, and both applications reproduced their respective original buffers. Maximum error is zero. The signed horizontal and vertical stripe checks and the thirteen-texel byte regression exercise the same window through normal node evaluation. The regression failed on the earlier build. All 425 node and evaluator release tests passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Environment and intermediate precision in the eighth specular passes + +Repeat the two [128² F16 settings](#rectangular-inputs-and-remaining-half-float-pixels-in-the-eighth-specular-passes) at seed zero, using the changed shape for root 396 and defaults for root 408. Keep the same eight bound inputs and final output format. Set only the first connected pixel processor to F32 and compare its raw RGBA with the graph output. Pass 396 returns F32, with every stored value exactly representable in F16 across these five controls. Pass 408 returns F16. All eight intermediate input images on this path matched in the preceding capture. + +For three controls replace one input with a generated opaque black 128² F32 texture. For the fourth replace the environment with an F32 texture containing red (x+.5)/128, green (y+.5)/128, blue ((17x+37y+5xy) mod 257)/256 and alpha one. All other inputs and parameters keep their values from the same original setting. Each count below requires all four channel bit patterns of a pixel to match. + +| Root | Input change | First processor F32 exact / 16,384 | Maximum F32 error | Final pixels exact / 16,384 | Maximum output error | +|---|---|---:|---:|---:|---:| +| 396 | Original inputs | 14,265 | 2.384185791015625e-07 | 16,383 | 0.0001220703125 | +| 396 | Black environment | 16,384 | 0 | 16,384 | 0 | +| 396 | Coordinate environment | 14,542 | 2.9802322387695312e-08 | 16,384 | 0 | +| 396 | Black emissive | 14,162 | 2.384185791015625e-07 | 16,383 | 0.0001220703125 | +| 396 | Black specular and roughness | 14,871 | 7.450580596923828e-09 | 16,352 | 2.384185791015625e-07 | +| 408 | Original inputs | 14,809 | 2.384185791015625e-07 | 16,383 | 0.000244140625 | +| 408 | Black environment | 16,384 | 0 | 16,384 | 0 | +| 408 | Coordinate environment | 15,023 | 1.4901161193847656e-08 | 16,384 | 0 | +| 408 | Black emissive | 14,768 | 2.384185791015625e-07 | 16,383 | 0.000244140625 | +| 408 | Black specular and roughness | 15,061 | 1.1920928955078125e-07 | 16,384 | 0 | + +At (54,36) in root 396, the green component reaches F32 bits `be745fff` in the reference app and `be746000` in MaterialCraft. At (62,57) in root 408, blue reaches `3e81bfff` and `3e81c000`, respectively. Each pair straddles a half-precision truncation boundary. The black environment makes both the intermediate and the final image exact. The coordinate environment removes the final discrepancies while retaining F32 differences. The individual arithmetic operation in the environment-dependent calculation remains unresolved in both roots. + +### Compositing complete seven-level additive quadrant trees + +Changing only the addition order of MaterialCraft's F32 contributions reproduced the measured BNW Spots 1 generator images from a single reference processor. Repeated raw captures agreed across two different processor choices, a fresh application launch and reopened packages. With eight processors, repeated native captures of the same three 128² generators varied at 235, 243 and 272 positions. The graph settings were seed 0 at defaults, seed 42 at defaults, and seed 0 with disorder .35. [Earlier generator measurements](#variation-in-the-order-of-additions-in-the-basic-spots-generator) + +To measure the order directly, build an original full quadrant tree on a white F32 background. At depth two label each of the sixteen grandchildren by 4a+b, with child slots a and b in traversal order. Continue every branch to level seven. Draw one additive square of size (.875,.875) at each leaf with zero roughness. Translate each grandchild's leaves into the upper-left 32 × 32 region of a 128² image, subtracting ((2(a mod 2)+(b mod 2))/4, (2 floor(a/2)+floor(b/2))/4) from their positions. For each pair assign one group opacity −1, the other 2⁻²⁵, and all others zero. Each covered pixel reads 2⁻²⁵ if the negative group draws first and zero otherwise. The single-negative, white-background and exactly representable .25 controls verify the readout. + +All 120 pairs yielded a single order. Numbered from zero, the 1,024-leaf groups draw in **12, 13, 8, 9, 14, 0, 1, 15, 2, 11, 6, 7, 10, 3, 4, 5** order. The same order had independently predicted 22,938 held-out pixels of the three original generators. Six further 128² seed/disorder pairs (1/.1875, 135071/.640625, 113/.921875, 9157/0, 735553/1 and 135697/.34375) matched all 98,304 F32 pixels. It also predicted both disputed Clouds 1 generator texels, including U16 levels 1,759 at (35,174) and 1,912 at (126,211). [Earlier cloud captures](#repeated-cloud-renders-and-two-generator-texels) + +MaterialCraft now keeps the position of each group boundary before discarding leaves that miss the sample grid. At 128 × 64, BNW Spots 1 with seed 372177 and disorder 1 discards 11,968 of 16,384 leaves from its 64 × 32 generator. Ordering the surviving contributions by their original group matches all 2,048 F32 texels. The previous whole-root output missed the same eight coordinates in U16 and F32. The implementation applies to a complete, grayscale, seven-level tree that draws only additive procedural leaves. An eight-level control gives different orders across portions of the same grandchild. + +| Original control | Settings | Earlier exact / total | Current exact / total | Earlier maximum F32 error | Current maximum | +|---|---:|---:|---:|---:|---:| +| Six-level pair comparisons at 64² | 120 | 491,520/491,520 | 491,520/491,520 | 0 | 0 | +| Seven-level pair comparisons at 128² | 120 | 1,891,328/1,966,080 | 1,966,080/1,966,080 | 2.9802322387695312e-8 | 0 | +| Seven levels with displaced neutral squares | 10 | 143,360/151,552 | 151,552/151,552 | 2.9802322387695312e-8 | 0 | + +For the displaced controls, use pairs (12,0) and (0,14). Offset all neutral squares by half a 128² texel along both axes. Test both signs at 128², the original signs at 64 × 32 and 256 × 128, and the reversed signs at 128 × 64. The release regression exercises both ordinary and culled neutral leaves through the pattern node. + +Repeat the archived spots and cloud settings on one logical processor with raw U8, U16, F16 and F32 readback. For Clouds 1 the table includes 48 archived settings and 20 new ones. Use (width, height, seed, disorder) of (16,128,139144,.375), (128,16,139817,.921875), (128,256,139711,.4375), (256,128,139547,1), (256,256,139333,.140625), (128,64,139999,default) and (64,256,139181,.578125). Test U16 and F32 at all seven sizes, adding U8 and F16 at the second, fourth and sixth. Clouds 2 uses 32 published settings, 3 archive renders and 4 precision renders. [Archived whole-root settings](#pixel-center-rounding-at-the-near-stamp-vertex) + +| Root and capture set | Renders or distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| BNW Spots 1, distinct | 125 | 649,984/649,984 · 0 | 949,504/949,504 · 0 | 649,984/649,984 · 0 | 928,512/928,512 · 0 | +| Clouds 1, distinct | 68 | 202,240/202,240 · 0 | 417,792/417,792 · 0 | 202,240/202,240 · 0 | 370,944/370,944 · 0 | +| Clouds 2, renders | 39 | 158,208/158,208 · 0 | 302,065/302,080 · 2.0 | 158,207/158,208 · 0.000244140625 | 203,766/203,776 · 2.2917985916137695e-05 | + +BNW Spots 1 matched **3,177,984/3,177,984** (previously 3,177,904 on these same single-processor captures). Clouds 1 matched **1,193,216/1,193,216**, including 405,504 pixels in the 20 new settings. Clouds 2 still differs at 26 of 822,272 pixels across its 39 renders. Save the packages in MaterialCraft and reopen them in both applications. The single-processor cross-application results were 580,608/580,608 from 24 BNW Spots 1 renders, 349,696/349,696 from 21 Clouds 1 renders and 186,879/186,880 from 11 Clouds 2 renders. The last maximum was .000244140625. Both applications reproduced every pixel of their own original outputs. + +On the original eight-processor captures of the 125 BNW Spots 1 settings the new renderer matches 3,177,932/3,177,984 (previously 3,177,940). Maximum errors are 0 U8, 2 U16, .000244140625 F16 and 2.1636486053466797e-5 F32. On the 32 original cloud captures, Clouds 1 matches 707,570/707,584 (previously 707,562), maximum 4 U16 levels. Clouds 2 remains 707,572/707,584, maximum 2 U16 levels. The three roots retain their in-progress inventory status. BNW Spots 3 retains all 3,159,552 original pixels across 118 settings and all 2,399,232 across 40 reopened renders, maximum zero. The regression failed on the previous renderer. All 426 node and evaluator release tests passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Downstream root captures after the aligned blur correction + +At revision `8ec728b`, repeat the archived source-graph settings for fourteen roots that use blur or share its sampling path. Use the original procedural fields, parameters, dimensions, seeds and storage formats from the linked comparisons. Count a pixel only when every channel has the same stored bits. The thirteen previously verified roots match 72,352,768/72,352,768 pixels across 662 distinct settings, maximum zero. [Aligned blur measurements](#accumulating-the-first-aligned-pair-in-a-sheared-blur) + +| Root | Distinct settings | Exact / total pixels | Earlier settings | +|---|---:|---:|---| +| `anisotropic_blur.sbs/anisotropic_blur` | 21 | 180,480/180,480 | [Settings](#integer-and-oblique-directional-blur) | +| `anisotropic_blur.sbs/anisotropic_blur_grayscale` | 19 | 163,072/163,072 | [Settings](#integer-and-oblique-directional-blur) | +| `fluid.sbs/fluid` | 121 | 25,969,920/25,969,920 | [Settings](#short-directional-blur-tap-order-on-rectangular-inputs) | +| `height_to_normal_world_units.sbs/height_to_normal_world_units` | 8 | 131,072/131,072 | [Settings](#height-to-normal-in-world-units) | +| `height_to_normal_world_units.sbs/height_to_normal_world_units_2` | 8 | 131,072/131,072 | [Settings](#height-to-normal-in-world-units) | +| `make_it_tile_patch.sbs/make_it_tile_patch` | 141 | 22,284,288/22,284,288 | [Settings](#diagonal-blur-across-rectangular-tile-edges) | +| `make_it_tile_patch_grayscale.sbs/make_it_tile_patch_grayscale` | 127 | 21,366,784/21,366,784 | [Settings](#diagonal-blur-across-rectangular-tile-edges) | +| `noise_anisotropic_noise.sbs/anisotropic_noise` | 18 | 171,264/171,264 | [Settings](#quarter-turn-directional-blur) | +| `noise_anisotropic_noise_v2.sbs/anisotropic_noise_v2` | 18 | 171,264/171,264 | [Settings](#high-pass-anisotropic-noise-and-triangle-grid-controls) | +| `noise_fluid.sbs/fluid` | 53 | 1,041,220/1,041,664 | [Settings](#diagonal-blur-across-rectangular-tile-edges) | +| `normal_sobel.sbs/normal_sobel` | 27 | 213,504/213,504 | [Settings](#sobel-normals-and-nadir-projection) | +| `normal_sobel.sbs/normal_sobel_2` | 18 | 171,264/171,264 | [Settings](#segment-mapping-and-normal-graph-rechecks) | +| `pattern_stripes.sbs/stripes` | 83 | 762,880/762,880 | [Settings](#pixel-ratio-in-rectangular-directional-filters) | +| `stripes.sbs/stripes` | 53 | 635,904/635,904 | [Settings](#pixel-ratio-in-rectangular-directional-filters) | + +The remaining fluid-noise root has 95,744/95,744 U8 pixels, 495,343/495,616 U16, 95,744/95,744 F16 and 354,389/354,560 F32. Maximum errors in the same order are 0, 6 stored levels, 0 and .0000152587890625. This reproduces the earlier 53-setting result. + +### Single-processor comparisons for Clouds 2 and five dirt fields + +At revision `b10bdb5`, render the archived seed, size and format settings on one logical processor, then compare every output pixel in the declared storage. Use the 47 distinct archived settings for Clouds 2, 56 each for Dirt 1 and Dirt 3, and 55 each for Dirt 5, Dirt 6 and Dirt Gradient. The archived roots include their default settings. [Cloud settings](#compositing-complete-seven-level-additive-quadrant-trees) · [Dirt settings](#wave-frequency-and-phase-in-directional-noise) · [Additional dirt precision settings](#original-and-reopened-dirt-moisture-and-cellular-noise-fields) + +For Clouds 2 add the seven size/seed pairs in the linked Clouds 1 matrix with all parameters at default. For the dirt fields add (width, height, seed, disorder) of (16,32,142171,.625), (128,64,142327,.53125), (256,128,142453,.921875) and (128,256,142631,.1875). Set disorder on Dirt 1 and Dirt 3, which expose that parameter. Use U16 and F32 at all four sizes and add U8 and F16 on the middle two. Integer errors below are storage levels. Float errors are absolute differences. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Clouds 2 (79) | 67 | 202,240/202,240 · 0 | 401,389/401,408 · 2 | 202,238/202,240 · 0.00048828125 | 370,927/370,944 · 2.29179859e-05 | +| Dirt 1 (128) | 68 | 510,208/510,208 · 0 | 671,469/671,488 · 1 | 510,208/510,208 · 0 | 624,622/624,640 · 1.53183937e-05 | +| Dirt 3 (129) | 68 | 510,208/510,208 · 0 | 671,471/671,488 · 1 | 510,208/510,208 · 0 | 624,624/624,640 · 1.52587891e-05 | +| Dirt 5 (130) | 67 | 510,206/510,208 · 1 | 654,711/655,104 · 4 | 510,046/510,208 · 0.00048828125 | 624,269/624,640 · 5.08725643e-05 | +| Dirt 6 (131) | 67 | 510,208/510,208 · 0 | 654,786/655,104 · 5 | 510,078/510,208 · 0.000244140625 | 623,810/624,640 · 9.27764922e-05 | +| Dirt Gradient (132) | 67 | 510,208/510,208 · 0 | 654,844/655,104 · 2 | 510,183/510,208 · 0.00048828125 | 624,380/624,640 · 1.93715096e-05 | + +Save each package in MaterialCraft. Reopen on a different logical processor and compare both applications to their own original output and to one another. The Clouds 2 reopen figures below cover the new ten renders. The [earlier eleven reopens](#compositing-complete-seven-level-additive-quadrant-trees) have their own counts. The dirt reopens take every sixth setting in archive-then-new order, starting with the first. + +| Root | All original settings, exact / total | New settings, exact / total | Reopens | Cross-application pixels after reopening | Maximum after reopening by storage | +|---|---:|---:|---:|---:|---| +| Clouds 2 | 1,176,794/1,176,832 | 405,489/405,504 | 10 | 162,809/162,816 | U8 0, U16 2, F32 0 | +| Dirt 1 | 2,316,507/2,316,544 | 230,396/230,400 | 12 | 238,842/238,848 | U8 0, U16 1, F16 0, F32 1.52587891e-05 | +| Dirt 3 | 2,316,511/2,316,544 | 230,400/230,400 | 12 | 461,041/461,056 | U8 0, U16 1, F16 0, F32 1.52587891e-05 | +| Dirt 5 | 2,299,232/2,300,160 | 230,297/230,400 | 12 | 238,714/238,848 | U8 0, U16 4, F32 5.08725643e-05 | +| Dirt 6 | 2,298,882/2,300,160 | 230,335/230,400 | 12 | 460,719/461,056 | U8 0, U16 5, F32 8.08723271e-05 | +| Dirt Gradient | 2,299,615/2,300,160 | 230,353/230,400 | 12 | 238,770/238,848 | U8 0, U16 1, F32 1.93715096e-05 | + +Each application reproduced every pixel of its own original output on these reopens. The Clouds 2 generator still differs with a fixed processor. An original square-stamp probe isolates an effect at the tile boundary. Start with a white 256² F32 field and a full seven-level branching tree. Each depth-seven quadrant draws a square of size (.875,.875). Add depth-eight children in slots 0 and 2 with gain .25 and shift their frames down by half the image. Set roughness to zero. Number the first 64 subtrees by the first three base-four child slots. Pair them using a rotating list 0 through 63, keeping the first element fixed and moving the last element to position one each round. Pair position j with 63−j, translate both subtrees into upper-half tile (j mod 8, floor(j/8)) on an 8 × 8 grid, and assign the two parent gains −1 and 2⁻²⁵. Repeat with the gains exchanged. + +In rounds 0, 19 and 41, moving the parent frames right and down by half a texel changed 5, 10 and 10 of the 8,192 upper-half odd-coordinate samples. The sampled pixels distinguish which parent draws first. With tiling disabled, all 24,576 samples reproduced the original order. Reducing the shifted squares to size (.375,.375) also reproduced all 24,576. A fixed order derived on the unshifted squares left 1,592 differences among 65,536 F32 texels in the 256-square Clouds 2 generator at seed 0 and defaults. This leaves the mixed-depth accumulation order open. + +### Three terminal children in seven-level quadrant trees + +Dirt 3 draws 12,288 additive leaves at depth seven. Each depth-six quadrant has children in slots 0, 1 and 3. The previous renderer ordered the complete four-child case and visited the three-child case in sequence. On a white F32 background, repeat the [seven-level square experiment](#compositing-complete-seven-level-additive-quadrant-trees), disconnecting slot 2 from every depth-six quadrant. The 120 pair comparisons at 128² improved from 1,910,016/1,966,080 exact pixels to **1,966,080/1,966,080**, maximum F32 error from 2⁻²⁵ to zero. Separately omitting each of slots 0, 1, 2 and 3 produced the same ordering in all 92,160 overlapping samples per omission. An unconnected routing dot on the complete four-child graph also retained that order. Across its 120 renders MaterialCraft improved from 1,891,328/1,966,080 to **1,966,080/1,966,080**, maximum error zero. + +An independent comparison labelled all 64 subtrees reached after the third subdivision. Pair them in 63 round-robin rounds with the same white background, −1 and 2⁻²⁵ square opacities and zero roughness. Translate each pair into one of 32 upper-half tiles of the 8 × 8 grid. Across all 2,016 comparisons the four consecutive subtrees of each grandchild stayed together. The sixteen groups of 768 leaves followed the order measured in the four-child case. MaterialCraft uses the connected terminal child count to find group boundaries before dropping stamps that miss the sample grid. It checks the node kinds that the renderer actually visits. + +For the Dirt 3 generator itself, read F32 at (width, height, seed, disorder) of (128,512,398765,.984375), (128,64,142327,.53125) and (256,128,142453,.921875). Compare the original generator directly, its output from the package saved in MaterialCraft, and a diagnostic output connected directly to that generator. The reference reproduced every generator pixel after reopening. The group order reduced the maximum F32 error from 5.96046448e-8 to zero. The comparison ran against the normal MaterialCraft renderer as well as the independently reordered contributions. + +| Dirt 3 capture | Renders | Earlier exact / total | Current exact / total | Current maximum by storage | +|---|---:|---:|---:|---| +| Generator, single processor | 3 | 105,609/106,496 | 106,496/106,496 | F32 0 | +| Whole root, single processor | 68 | 2,316,511/2,316,544 | 2,316,544/2,316,544 | U8 0, U16 0, F16 0, F32 0 | +| Saved whole root, single processor | 12 | 461,041/461,056 | 461,056/461,056 | U8 0, U16 0, F16 0, F32 0 | +| Whole root, eight processors | 68 | 2,316,521/2,316,544 | 2,316,526/2,316,544 | U8 0, U16 1, F16 0.00048828125, F32 1.52587891e-05 | +| Second capture, eight processors | 12 | 461,048/461,056 | 461,047/461,056 | U8 0, U16 1, F16 0, F32 0 | + +Use the [68 dirt settings and twelve reopens](#single-processor-comparisons-for-clouds-2-and-five-dirt-fields). Both applications preserved every original pixel on their own single-processor reopens. With eight processors the reference reproduced 461,056/461,056 of its own pixels on the twelve repeated settings, with maximum differences of U8 0, U16 0, F16 0, F32 0. Dirt 3 remains in progress for this configuration. The regression exercises three- and four-child trees, culled neutral squares and a disconnected dot. All 426 node and evaluator release tests passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Parent and leaf draws in Fur 2 and Gaussian Spots 2 + +Fur 2 and Gaussian Spots 2 each draw 4,096 procedural stamps at depth six and four children per stamp at depth seven. The group boundary must precede the parent draw, including when its geometry misses the sample grid. MaterialCraft now records the boundary on entry to each of the sixteen grandchildren and preserves the original order of draws inside it. The renderer recognizes regular additive grayscale trees with the measured depth and child counts. + +Build an original 128² white F32 graph with zero roughness and additive squares of size (.875,.875) at depths six and seven. Use the [64-subtree round-robin comparison](#single-processor-comparisons-for-clouds-2-and-five-dirt-fields). For each pair translate both subtrees into one upper-half tile. Give the parents gains −1 and 2⁻²⁵. Set child gain .25 and shift each child frame down by half the image. All 2,016 comparisons gave the same order for every parent sample in a subtree. Groups of four subtrees followed the [measured sixteen-grandchild order](#compositing-complete-seven-level-additive-quadrant-trees). + +For an independent overlap test, remove the half-image shift so both levels draw over one another. Repeat rounds 0, 19 and 41 at 128², 128 × 64, 64 × 128 and 256 × 128, with both assignments of each pair to its tile. Number the 32 tiles from zero. Parent A uses gain −1. Parent B uses .31250003 at tile index 1 mod 3 and 2⁻²⁵ elsewhere. Child A uses 2⁻²⁵ at indices 0 mod 3 and −.18750002 elsewhere. Child B uses .31250003 at indices 2 mod 3 and 2⁻²⁵ elsewhere. Use seed 151371 + 53 times the round number + the zero-based size index. The normal renderer improved from **258,048/393,216 to 393,216/393,216** across all 24 F32 renders. Maximum error fell from 5.96046448e-8 to zero. Save the graph in MaterialCraft and reopen it in both applications. All 131,072 F32 pixels from eight reopens matched. + +The square tests also covered missing slots. Keeping three of the four children at depth five or keeping just slot 3 at depth six gave 1,966,080/1,966,080 F32 pixels in each 120-pair matrix. Keeping slots 1 and 3 at depth six gave 1,965,568/1,966,080 in the first capture, maximum 2⁻²⁵. The single difference in pair (5,14) covered 512 pixels. Repeating the same 120 settings on one processor gave 1,966,080/1,966,080. Twelve further renders with interleaved pair changes matched all 196,608 pixels. Eight independently rebuilt pair controls for each of the six possible two-slot masks and a rotating mask matched all 917,504 pixels. These counts preserve the first reference result. + +For each root repeat its 85 archived settings on one processor. Add (width, height, d) of (32,16,default), (64,128,.28125), (256,64,.6875) and (128,256,.84375), with seed 148603 + 29i + 71j for inventory index i and zero-based size index j. Set disorder to d on the three changed cases. For Fur 2 also set wave scale to .25 + .625d and rotation to d − .5. Render U16 and F32 at every size and add U8 and F16 at the two middle sizes. Save each root in MaterialCraft, reopen it in both applications and repeat every eighth setting on a different logical processor, starting with the first. Repeat all 97 original settings with eight processors. [Archived Fur 2 settings](#fur-across-two-rectangular-render-series) · [Archived Gaussian Spots 2 settings](#gaussian-generators-and-spots-through-1024-pixels-per-side) + +| Root and capture | Settings | Earlier exact / total | Current exact / total | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:|---:|---:| +| Fur 2, one processor | 97 | 8,789,131/9,414,912 | 9,414,912/9,414,912 | 1,592,576/1,592,576 · 0 | 3,119,872/3,119,872 · 0 | 1,592,576/1,592,576 · 0 | 3,109,888/3,109,888 · 0 | +| Fur 2, eight processors | 97 | 8,953,423/9,414,912 | 9,007,353/9,414,912 | 1,592,575/1,592,576 · 1 | 3,119,477/3,119,872 · 1 | 1,592,543/1,592,576 · 0.000244140625 | 2,702,758/3,109,888 · 2.38418579e-07 | +| Gaussian Spots 2, one processor | 97 | 8,679,805/9,414,912 | 9,414,912/9,414,912 | 1,592,576/1,592,576 · 0 | 3,119,872/3,119,872 · 0 | 1,592,576/1,592,576 · 0 | 3,109,888/3,109,888 · 0 | +| Gaussian Spots 2, eight processors | 97 | 8,816,968/9,414,912 | 8,944,516/9,414,912 | 1,592,574/1,592,576 · 1 | 3,119,459/3,119,872 · 1 | 1,592,546/1,592,576 · 0.00048828125 | 2,639,937/3,109,888 · 1.78813934e-07 | + +Each root matched all **1,494,016 pixels across 13 single-processor reopens**. Both applications reproduced their own original pixels. The initial four F32 controls at 64², 64 × 128, 256 × 64 and 256² matched 94,208/94,208 per root, compared with 76,499 for Fur 2 and 72,032 for Gaussian Spots 2. Their eight-processor results keep both roots in progress. The new parent-overlap regression failed at (0,0) on the preceding code. All 428 node and evaluator release tests passed, together with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Tile copies and the draw order in Clouds 2 + +Clouds 2 has a generator with 16,384 depth-seven parents, each drawing a stamp and two depth-eight children in slots 0 and 2. An original square probe separates the parent readout from the child positions. Use the [64-subtree pairing and gains](#single-processor-comparisons-for-clouds-2-and-five-dirt-fields) on a white 256² F32 field. Draw the parents at size (.875,.875) and keep them in the upper half. Draw both children at gain .25 and size (2.25,.875). Add .5 to their frame Y and set their frame X offset to the target X minus their incoming X position. Use the original 63 rounds and seed 137143 + 17 times the zero-based round. Read the upper 128 rows on a single processor. Each of the 2,016 subtree pairs contributes 1,024 samples. The parent gains distinguish the two possible orders by 2⁻²⁵. + +Compare two separate controls. The first draws two unshifted-X children in slots 0 and 2. The second draws all four children. In both controls the children have size (.875,.875), gain .25 and the half-image Y shift. The two controls differ at 480,608 upper-half samples. + +| Two-child probe | Exact against two-child control | Exact against four-child control | Maximum F32 error against the two controls | +|---|---:|---:|---| +| X = .5, tiled | 2,064,384/2,064,384 | 1,583,776/2,064,384 | 0 / 2.98023224e-08 | +| X = 0, tiled | 1,583,776/2,064,384 | 2,064,384/2,064,384 | 2.98023224e-08 / 0 | +| X = 0, tiling disabled | 2,064,384/2,064,384 | 1,583,776/2,064,384 | 0 / 2.98023224e-08 | +| X = 0 for odd-numbered subtrees and .5 for even, tiled | 1,725,200/2,064,384 | 1,670,224/2,064,384 | 2.98023224e-08 / 2.98023224e-08 | + +Changing only the position of the child draws changed the order of parent draws elsewhere in the image. Centering every child on the wrapped edge reproduced the four-child control across the entire readout. Disabling tiling reproduced the two-child control. Save all four original graphs in MaterialCraft, reopen them in the reference on a different processor, and repeat rounds 0, 10, 20, 30, 40, 50 and 60. Each reopened graph reproduced all 458,752 pixels of its own full-frame original, maximum F32 error zero. + +For the root generator, save Clouds 2 in MaterialCraft and wire the middle of its three pattern stages directly to the output. At default graph controls, set its base tiling to neither, X, Y or both. Render F32 at (width, height, seed) of (32,16,42), (256,256,0) and (512,128,382479). With both axes enabled the reconnected stage reproduced the original intermediate at every pixel. The baseline below is MaterialCraft's normal accumulation order for this graph. The replay sums the same original nonzero F32 contributions in the order measured on the two-child control. To determine the order, label the 64 subtrees with their first three base-four slots in traversal order. Within each subtree the control has two observed parent orders, separated after 28 of 256 parents in Morton order. Repeat all 63 rounds after translating the second member of each pair by ±16 texels in both axes and read an 8 × 8 region in the common interior. Those 8,064 pair relations fix the relative order between different subtrees. Number draws in traversal order from zero. The resulting contiguous intervals below use an exclusive end. + +18432–23892, 30720–36180, 6144–11604, 38400–39936, 12288–16212, 41472–43008, 24576–28500, 44544–46080, 0–3924, 16212–16896, 17664–18432, 29184–29952, 28500–29184, 29952–30720, 4608–5376, 3924–4608, 5376–6144, 46080–47616, 16896–17664, 47616–49152, 36864–38400, 36180–36864, 43008–44544, 23892–24576, 39936–41472, 11604–12288. + +| Tiling | Baseline exact / 131,584 | Baseline maximum F32 error | Replay exact at 32 × 16 | Replay exact at 256² | Replay exact at 512 × 128 | Replay maximum F32 error | +|---|---:|---:|---:|---:|---:|---:| +| Neither | 116,310 | 2.98023224e-08 | 512/512 | 65,536/65,536 | 65,536/65,536 | 0 | +| X | 113,411 | 3.7252903e-08 | 510/512 | 64,867/65,536 | 64,919/65,536 | 3.7252903e-08 | +| Y | 112,053 | 4.47034836e-08 | 512/512 | 64,708/65,536 | 64,067/65,536 | 3.7252903e-08 | +| Both | 109,269 | 4.47034836e-08 | 510/512 | 63,944/65,536 | 63,594/65,536 | 3.7252903e-08 | + +The replay matched all 131,584 generator pixels with tiling disabled. With both axes enabled it left 3,536 differences across the same sizes. The mixed placement control also differs from both uniform placements. Clouds 2 remains in progress. Its [67 whole-root comparisons](#single-processor-comparisons-for-clouds-2-and-five-dirt-fields) used the production renderer. + +### Moisture, spot and cell fields across processors and saved packages + +MaterialCraft revision 7cc1893 matched 4,161,468 of 4,161,792 Moisture Noise pixels across 94 single-processor settings. Repeat the [82 archived settings](#original-and-reopened-dirt-moisture-and-cellular-noise-fields). Add (width, height, d) of (32,16,.75), (64,128,.28125), (256,64,.6875) and (128,256,.84375), with seed 148603 + 29 × 226 + 71j for zero-based setting j. Use default controls at j = 0. Otherwise set disorder to d, pattern width to 24 + 180d and height to 32 + 120(1 − d). Request U16 and F32 at all four sizes, plus U8 and F16 at the two middle sizes. The 12 added settings matched 164,859/164,864 pixels. Save in MaterialCraft and reopen every eighth setting starting with the first on another logical processor. + +| Whole root | Settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Moisture Noise (226) | 94 | 741,630/741,632 · 1 | 1,376,869/1,377,024 · 6 | 741,609/741,632 · 0.00048828125 | 1,301,360/1,301,504 · 7.80820847e-05 | +| BNW Spots 1 (236), new settings | 12 of 12 | 1,536/1,536 · 0 | 4,095/4,096 · 1 | 1,536/1,536 · 0 | 2,416/4,096 · 2.38418579e-07 | +| BNW Spots 1 v2 (237), new settings | 12 of 12 | 1,536/1,536 · 0 | 4,095/4,096 · 1 | 1,536/1,536 · 0 | 3,982/4,096 · 1.1920929e-07 | +| BNW Spots 3 (238), new settings | 12 of 12 | 1,536/1,536 · 0 | 4,093/4,096 · 1 | 1,536/1,536 · 0 | 4,093/4,096 · 1.06692314e-05 | +| BNW Spots 3 v2 (239), new settings | 8 of 12 | 512/512 · 0 | 3,071/3,072 · 1 | 512/512 · 0 | 2,764/3,072 · 1.49011612e-07 | +| Cells 1 (240), new settings | 12 of 12 | 1,536/1,536 · 0 | 4,096/4,096 · 0 | 1,536/1,536 · 0 | 4,096/4,096 · 0 | +| Cells 1 v2 (241), new settings | 12 of 12 | 1,536/1,536 · 0 | 4,096/4,096 · 0 | 1,536/1,536 · 0 | 4,096/4,096 · 0 | +| Cells 1 (240), full series, each processor setting | 60 | 85,760/85,760 · 0 | 296,146/296,192 · 1 | 93,952/93,952 · 0 | 241,918/253,440 · 8.34465027e-07 | +| Cells 1 v2 (241), full series, each processor setting | 61 | 137,984/137,984 · 0 | 248,056/248,064 · 1 | 88,832/88,832 · 0 | 270,742/273,920 · 8.34465027e-07 | + +For roots 236–241 use (width, height, scale, disorder d) of (16,32,default,default), (32,16,1,.34375), (32,32,2,.78125) and (64,32,1,.5625). Use seed 0 and all defaults first, then seed 153113 + 37i + 109j for inventory index i and zero-based setting j. On changed settings set roughness to .25 + .625d, disorder speed to .625 + .5d, anisotropy to .5d, its angle to d − .375 and tile offset to (.21875d,−.375d) wherever exposed. For Cells 1 v2 select pattern 3, pattern size (.8,1.2), pattern scale .8, angle .125, angle randomness .2 and luminance randomness .25. Request U16 and F32 at the first and last settings. At the two middle settings request U8, U16, F16 and F32. Save each package in MaterialCraft and reopen the 16 × 32 U16, 32 × 16 U16, 32² U8 and 32² F32 cases. Use one processor and change its logical index for the reopens. + +The full Cells 1 series combines the archived defaults, seed and control changes, the [four-format controls](#four-format-inventory-comparison), the independent 32² setting, the [30 rectangular and square settings](#original-and-reopened-dirt-moisture-and-cellular-noise-fields), plus the 12 new settings. Include the [ten source comparisons](#bnw-spots-3-and-cells-1-pattern-sources) for the first package and the [additional cell controls](#paths-caustics-and-cell-fields-after-pattern-sampling) for the second. Deduplicate settings by seed, controls, dimensions, image inputs and storage. Repeat all settings at one and eight processors. Save and reopen every fourth setting starting with the first on one processor. Both processor counts gave the same exact counts and maxima on each complete series. + +| Reopened package | Comparable renders | Cross-application exact / total | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---| +| Moisture Noise | 12 | 442,322/442,368 | 1 / 5 / — / 7.80522823e-05 | +| BNW Spots 1 | 4 | 2,703/3,072 | 0 / 1 / — / 2.38418579e-07 | +| BNW Spots 1 v2 | 4 | 3,032/3,072 | 0 / 1 / — / 1.1920929e-07 | +| BNW Spots 3 | 4 | 3,069/3,072 | 0 / 1 / — / 1.06692314e-05 | +| BNW Spots 3 v2 | 2 | 1,024/1,024 | — / 0 / — / — | +| Cells 1 | 4 | 3,072/3,072 | 0 / 0 / — / 0 | +| Cells 1 v2 | 4 | 3,072/3,072 | 0 / 0 / — / 0 | +| Cells 1, full series | 15 | 122,881/123,136 | 0 / 1 / 0 / 3.57627869e-07 | +| Cells 1 v2, full series | 16 | 191,792/192,256 | 0 / 0 / 0 / 8.34465027e-07 | + +All completed MaterialCraft reopens reproduced their own original buffers. The 32² BNW Spots 3 v2 setting exceeded the pattern visit budget in all four formats. These missing renders account for 4,096 pixels. The two attempted reopens at this setting returned the same error. The initial reference reopen at 32² F32 matched 939/1,024 pixels against its original, maximum 1.78813934e-7. Alternately reopen the original and the saved package twice on the same logical processor, then once on a second processor. All U8 reads were identical. The original reproduced all F32 pixels on each repeat. One read from the saved package also matched all 1,024 original pixels. The other two matched 919 and 995. Their maximum errors against the original were 1.19209290e-7 and 8.94069672e-8. The other five roots in the new series and Moisture Noise reproduced all their reference pixels after reopening. + +For the two cell generators isolate the stamp supplying the maximum at differing F32 pixels. Use a black grayscale background, maximum blending, zero roughness and unit global gain. Match the selected stamp's size, center, turns, scalar opacity and render and tiling windows. Across seven first-package settings the isolated reference stamp reproduced the complete generator at all 45 selected differing pixels. Across five second-package settings it reproduced all 33. At 32², seed 102975, render and tile both axes over [−1,2]. Draw shape 4, size (3,3), center (.5007324,−.7152839), zero turns, opacity one. Pixel (9,0) in the original and the isolated reference stores F32 bits 0x3f4f364f. MaterialCraft gives 0x3f4f3650. The isolated stamp still differs elsewhere in the image. Both cell roots remain in progress. + +### Untiled draw order for two and four children below depth seven + +Start with the [original paired-square controls](#tile-copies-and-the-draw-order-in-clouds-2). Each of the 64 depth-three subtrees has 256 depth-seven parents in Morton order. With two children per parent, the order can change after parent 28 inside a subtree. With four children it can change after parents 68 and 136. To resolve the four-child order, repeat the 63 pairing rounds on a white 256² F32 image. Offset the second member’s parent frame by (−1,+1)/128 and (0,−1)/128 in separate runs. Shift both members inward by one cell where the offset would leave the image. Compare the paired parent positions inside each 16 × 16 readout, keeping destination coordinates 2 through 13 on both axes. The three parent intervals give 18,144 relative orders between distinct subtrees. The renderer records the corresponding contiguous stretches of parent visits before empty pixel coverage is discarded. It uses their measured order for active, untiled, additive grayscale quadrant trees of this shape. + +Check each of the six ways to connect two child slots and a seventh graph cycling those pairs across the 64 subtrees. Use rounds 0, 7, 19, 31, 41 and 61, then exchange the two gains. Each graph reproduced all 393,216 upper-half F32 pixels of the two-child parent ordering, maximum error zero. An independent 16-grandchild control at 128² holds one grandchild at gain −1 and a second at 2⁻²⁵. With the remaining parents active in a separate part of the image the negative parent draws first on 284/1,024 paired samples with two children and 324/1,024 with four. Setting the other parent gains to zero changes those counts to 796 and zero. Those two-child zero-gain images still differ by up to 2⁻²⁵. + +For the full-image comparison use a white background and roughness zero. Draw depth-seven parents at size (1.125,1.25) and children at (1.875,1.125) with frame offset (.0009765625,−.001953125). Draw either squares at zero rotation or discs with parent rotation .0625 turns and child rotation −.1875 turns. Use slots 0 and 2 or all four. For rounds 3, 11, 31 and 56 use 128², 128 × 64, 64 × 128 and 256 × 128. For pair index h starting at zero set the first parent gain to −1, the second to .31250003 when h mod 3 = 1 and to 2⁻²⁵ otherwise. The first child gain is 2⁻²⁵ when h mod 3 = 0 and −.18750002 otherwise. The second child gain is .31250003 when h mod 3 = 2 and 2⁻²⁵ otherwise. Run both pair orientations with seed 157139 + 73j + 17s, where j is the zero-based round index and s is 0 or 1 for the orientation. Request U16 and F32 at every size, plus U8 and F16 at the second and fourth sizes. Use one logical processor. + +| Children and shape | Previous exact / total | Previous maximum normalized error | Current U8 exact / total | Current U16 exact / total | Current F16 exact / total | Current F32 exact / total | +|---|---:|---:|---:|---:|---:|---:| +| 2, squares | 385,984/425,984 | 6.10351562e-05 | 81,920/81,920 | 131,072/131,072 | 81,920/81,920 | 131,072/131,072 | +| 2, discs | 393,324/425,984 | 6.10351562e-05 | 81,920/81,920 | 131,072/131,072 | 81,920/81,920 | 131,072/131,072 | +| 4, squares | 390,640/425,984 | 0.000122070312 | 81,920/81,920 | 131,072/131,072 | 81,920/81,920 | 131,072/131,072 | +| 4, discs | 390,624/425,984 | 6.10351562e-05 | 81,920/81,920 | 131,072/131,072 | 81,920/81,920 | 131,072/131,072 | + +All 1,703,936 pixels matched in the 96 original settings, maximum error zero in every format. Save each of the four graphs in MaterialCraft and reopen it on a different logical processor. Repeat the first orientation at 128 × 64 in all four formats and the exchanged orientation at 256 × 128 in U16 and F32. Each reopened graph matched 98,304/98,304 pixels across applications. Both applications also reproduced every pixel of their own original. A separate six-setting F32 reopen per graph matched 106,496/106,496 each. + +Wire the generator stage to the graph output and repeat with tiling disabled and both axes enabled. For Clouds 2 use default controls at (width, height, seed) of (32,16,42), (256,256,0) and (512,128,382479). For Dirt 1 and Dirt 6 use (256,256,0), (128,64,142327) and (256,128,142453). Set Dirt 1 disorder to its default, .53125 and .921875, respectively. Dirt 6 has no exposed graph controls. Before changing the tiling, each reconnected reference output reproduced its original intermediate at every pixel. The following counts compare raw F32 pixels across applications. + +| Root generator | Previous untiled exact / total | Current untiled exact / total | Current tiled exact / total | Tiled maximum error | +|---|---:|---:|---:|---:| +| Clouds 2 (79) | 116,310/131,584 | 131,584/131,584 | 109,269/131,584 | 4.47034836e-08 | +| Dirt 1 (128) | 106,495/106,496 | 106,496/106,496 | 105,345/106,496 | 1.1920929e-07 | +| Dirt 6 (131) | 105,750/106,496 | 106,496/106,496 | 100,440/106,496 | 1.1920929e-07 | + +The untiled maximum error fell to zero in all nine settings. The ordinary tiled generators still differ. All three whole roots remain in progress. In six interleaved, single-processor release cooks per binary after warmup, median times at the last two sizes in the table changed from 483.0/488.0 to 490.2/489.3 ms for Clouds 2, 496.6/511.3 to 497.4/513.7 ms for Dirt 1, and 525.4/554.3 to 531.0/549.9 ms for Dirt 6. + +### Wrapped draw order for four children below depth seven + +Use the [untiled parent and child graphs](#untiled-draw-order-for-two-and-four-children-below-depth-seven) with both tile axes enabled and the unit render window. For four-child additive trees, a stamp that touches a tile edge can change the order of two interior parents elsewhere in the image. With white as background, gains −1 and 2⁻²⁵ reveal their relative order in F32. Count each physical copy along each axis before discarding stamps that cover no pixel. Traverse the measured four-child runs in compositing order. An interior split moves to the next cumulative multiple of 5,460 copies. Keep the existing draw order if a cut crosses a depth-three subtree, divides one repeated stamp, or makes the ranges overlap. Two-child wrapped fields have different boundaries. + +In the 128² regression with 16 grandchild groups, move the depth-eight squares by (−1/512,.5) or (.4995,.5). With groups 0 and 5 overlapping, the earlier negative-gain parent moves from positions 580–647 in the untiled Morton sequence to 571–643 or 574–622 respectively. Positions 768–1023 retain their order. The 12 original F32 images, including exchanges of the two gains, match 196,608/196,608 pixels, previously 192,728. The maximum error fell from 2⁻²⁵ to zero. + +At 256², pair all 64 subtrees round-robin, using rounds 0, 7, 19, 31, 41 and 61 and both gain orientations. Use parent squares of size (.875,.875), child squares (2.25,.875) displaced by .5 in Y, and pin the child X center to .5. Move selected child centers to X=0. Five layouts match all 786,432 pixels each. Their moved slots are respectively none, subtree 0 slot 0, subtree 22 slots 0 and 2, one slot each in subtrees 3/16/39/52 (slots 0/1/2/3), and slot i mod 4 in subtrees i=3,11,…,59. Moving slots 1–3 of subtree 17 matches 641,832/786,432. Moving all four slots of subtree 41 matches 625,312. Moving slot 0 in all subtrees matches 611,648. Moving all four in even subtrees matches 609,384. Each remaining maximum is 2⁻²⁵. + +Repeat rounds 2, 5, 11, 19, 33, 47 and 60 with both orientations. Pin Y to .75, add dx to each incoming child X, and use child size (sx,.875) and rotation t turns. In order, (dx,sx,t) is (.001251,1.375,.125), (−.002719,2.25,0), (.000713,4.125,−.0625), (.171371,1.875,.0625), (−.213375,2.75,−.125) or (.000875,.4375,0). Counting copies predicts all 2,752,512 parent-region pixels across these six layouts. The production full-frame matches in the same order are 917,504, 873,944, 917,504, 762,744, 917,504 and 917,504 out of 917,504 each. The two remaining maximum F32 errors are 2⁻²⁵. + +Repeat the 24 [square and rotated-disc cases](#untiled-draw-order-for-two-and-four-children-below-depth-seven) per shape with four children and both axes tiled. Squares improve from 390,462 to 425,984/425,984 exact pixels across four formats, maximum zero. Discs improve from 391,241 to 420,446/425,984. All disc U8 and U16 pixels match. F16 matches 81,918/81,920, maximum .00048828125. F32 matches 125,536/131,072, maximum 1.19209290e−7. Repeat the six saved-file settings per graph. Both applications reproduce every pixel of their own originals. The cross-app results are 98,304/98,304 for squares and 98,302/98,304 for discs, with the same F16 and F32 maxima. + +For the whole roots, repeat the [single-processor settings for Clouds 2 and the dirt fields](#single-processor-comparisons-for-clouds-2-and-five-dirt-fields). Add 32 × 16, 64 × 256, 128² and 512 × 128 with seed 168617 + 47i + 91j, where i is 128 or 131 and size j starts at zero. For Dirt 1 use default disorder, .3125, .65625 and .84375 in that order. Dirt 6 has no exposed numeric control. Render U16 and F32 at all sizes plus U8 and F16 at the middle two. Render the entire series with the reference process on one and eight logical processors. The maxima below use stored levels for integer formats and absolute error for floats. + +| Root | Reference processors | Settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:|---:| +| Dirt 1 (128) | 1 | 80 | 542,976/542,976 · 0 | 770,304/770,304 · 0 | 542,976/542,976 · 0 | 723,456/723,456 · 0 | +| Dirt 1 (128) | 8 | 80 | 542,976/542,976 · 0 | 770,280/770,304 · 1 | 542,975/542,976 · 0.00048828125 | 723,427/723,456 · 1.53183937e-05 | +| Dirt 6 (131) | 1 | 79 | 542,976/542,976 · 0 | 753,919/753,920 · 2 | 542,976/542,976 · 0 | 723,451/723,456 · 2.02059746e-05 | +| Dirt 6 (131) | 8 | 79 | 542,975/542,976 · 1 | 753,559/753,920 · 5 | 542,830/542,976 · 0.000244140625 | 722,536/723,456 · 9.27764922e-05 | + +Dirt 1 matches **2,579,712/2,579,712** whole-root pixels on one processor, previously 2,579,666. Eight processors match **2,579,658**, previously 2,579,678 against the same reference captures. For Dirt 6 the corresponding counts are **2,563,322/2,563,328** on one processor, previously 2,561,870, and **2,561,900** on eight, previously 2,562,094. Both roots remain in progress. Save each root in MaterialCraft and reopen it in both applications. Repeat the 12 historical save settings and every third new setting starting at the first U16 image. Each application reproduces its originals on all 16. The reopened cross-app totals are 288,512/288,512 for Dirt 1 and 510,720/510,720 for Dirt 6, maximum zero. + +The three directly connected F32 pattern-stage settings per root now match 106,496/106,496 for both Dirt 1 and Dirt 6 with ordinary tile wrapping. The six remaining single-processor whole-root differences for Dirt 6 occur at 32 × 128, seed 398553. Expose the pattern generator, first levels, transform, blend, second levels and sharpen in succession. Each native reconnection reproduces the intact node output across both storage requests. The U16 generator first differs at (28,16) by one stored level. The first levels differs by two at one pixel, the transform matches all 4,096, and the blend and second levels each differ by one at one pixel. Sharpen leaves one differing U16 pixel (maximum two levels) and five F32 pixels (maximum 2.02059746e−5). The tiled two-child Clouds 2 generator retains the earlier 109,269/131,584 F32 result. + +In six interleaved single-processor release cooks per binary after warmup, the median tiled generator times at 128 × 64 and 256 × 128 went from 783.9/839.3 to 812.8/866.2 ms for Dirt 1, and from 826.3/898.8 to 833.3/889.8 ms for Dirt 6. + +### Individual tile copies across a pattern draw boundary + +A wrapped square can straddle two draw runs. In six original graphs, a second square draws between two copies of the first. The rightmost translation draws first, then the next translation to its left. At a corner, the row with the largest Y draws first. The raster now carries the copy range through the reordered runs and charges the repetition budget for each selected copy. The split positions include draws discarded for empty pixel coverage. A run whose length would cross a depth-three subtree still uses its earlier ordering. + +Start with a full eight-level quadrant tree on a white F32 field, roughness zero and wrapping enabled on both axes. The first seven subdivisions have all four children. Only depth-seven parents and their four children draw. Use additive squares of size (.875,.875) and gain .25. Set each stamp’s frame offset to (.5,.75) minus its incoming position. Number the 81,920 draws from zero in traversal order, with each parent followed by its four children. Move just the two listed draws to the common center. Give them normalized width and height 1/16, using authored size 8 at depth seven or 16 at depth eight. Give the first draw gain −1 and the second 2⁻²⁵, then exchange them. The table records which corners or edges retained 2⁻²⁵ in the first orientation. The exchanged orientation reversed every readout. + +| First draw | Second draw | Center | Edge positions that retained 2⁻²⁵ | +|---:|---:|---|---| +| 36,179 | 53,930 | (0,.25) | Right | +| 56,659 | 12,970 | (.25,0) | Bottom | +| 15,699 | 65,280 | (0,0) | Bottom right | +| 23,378 | 75,520 | (0,0) | Bottom right and bottom left | +| 2,897 | 70,400 | (0,0) | Both bottom corners and top right | +| 43,859 | 18,090 | (0,.375) | Right | + +Use 128², 64 × 128 and 128 × 64. For graph index h, size index j and gain orientation v, starting at zero, set seed 173519 + 37h + 7j + v. Render U16 and F32 at every size, plus U8 and F16 at the middle size. Across 96 settings all **983,040/983,040** pixels match, maximum zero. Previously 982,272 matched, maximum 2⁻²⁵. Save all six graphs in MaterialCraft. Reopen each on another logical processor and render the middle size at the first gain orientation in four formats, then the last size at the other orientation in U16 and F32. Across these 36 settings every application reproduced its originals, and all **294,912/294,912** cross-app pixels match. + +Across all 84 [dispersed child layouts](#wrapped-draw-order-for-four-children-below-depth-seven), all **5,505,024/5,505,024** full-frame F32 pixels now match, maximum zero. The concentrated three-slot, four-slot, all-subtree and even-subtree layouts retain their previous differences. The four-format rotated discs improve from 420,446 to 420,448/425,984. The 5,534 differing F32 samples have maximum 1.19209290e−7, and the two differing F16 samples have maximum .00048828125. All 425,984 tiled square pixels still match. + +For Dirt 6 repeat the [79 single- and eight-processor whole-root settings](#wrapped-draw-order-for-four-children-below-depth-seven). All **2,563,328/2,563,328** match on one processor. Eight processors match **2,561,906/2,563,328**. The U8, U16, F16 and F32 maxima on eight are respectively one level, five levels, .000244140625 and 9.27764922e−5. At 32 × 128 and seed 398553 the generator’s 15,646th logical draw has two copies. Its first copy ends at cumulative copy 15,787. Neither covers a pixel in that image. Splitting there changes the order of later visible draws. The original U16 value at (28,16), the five F32 sharpen samples, and all six isolated F32 generators at 32 × 128, 128 × 32, 16 × 64 and 64 × 256 now match. The isolated generators improved from 32,302 to 33,792/33,792. + +Add five distinct F32 whole-root settings for Dirt 6. Use seeds 398552 and 398554 at 32 × 128 and seed 398553 at 128 × 32, 16 × 64 and 64 × 256. All 29,696 pixels match on one processor. Eight processors match 29,641/29,696, maximum 6.06477261e-05. Reopening these five MaterialCraft saves on one processor reproduces each application's original and matches all 29,696 pixels across applications. Including them brings the one-processor result to 2,593,024/2,593,024 in 84 settings and the eight-processor result to 2,591,547/2,593,024. Dirt 1 retains 2,579,712/2,579,712 on one processor and 2,579,658/2,579,712 on eight at its 80 settings. The 16 previously specified reopens per root also match every pixel across applications. Both roots remain in progress. + +In six interleaved single-processor release runs per binary after warmup, median times at 128 × 64 and 256 × 128 changed from 578.4/637.5 to 561.4/618.3 ms for Dirt 1 and from 603.3/638.7 to 604.2/669.4 ms for Dirt 6. + +### Four cloud noise generators and repeated saved-file comparisons + +Use each cloud noise root’s own procedural graph. Combine the initial output cases, the [four-format inventory](#four-format-inventory-comparison), the [cloud scale comparisons](#cloud-and-crystal-pattern-sources-across-scales), the follow-up wrapper settings and 12 new settings. Deduplicate by dimensions, seed, exposed values, input and storage format. For the new settings use (width, height, disorder d, scale) of (16,32,default,default), (32,16,.34375,1), (32,32,.78125,2) and (64,32,.5625,1). Use seed zero for the first size and 160303 + 37i + 109j elsewhere, with root index i and zero-based size index j. In both v2 roots set disorder speed to .625 + .5d, anisotropy to .5d, anisotropy angle to d − .375 and tile offset to (.21875d,−.375d) on changed settings. Render U16 and F32 at every size and add U8 and F16 at the middle two. + +The 60-setting comparison used MaterialCraft revision 3e6da95, first against a reference process on one logical processor and then on eight. Counts compare complete stored grayscale pixels. Integer maxima are in stored levels and floating maxima are absolute. A setting that returned an execution-budget error contributes no pixels to the denominator. + +| Root | Reference processors | Completed / requested | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:|---:| +| Clouds 1 (244) | 1 | 58/60 | 85,760/85,760 · 0 | 293,710/294,144 · 2 | 93,947/93,952 · 0.00048828125 | 250,945/251,392 · 3.05175781e-05 | +| Clouds 1 (244) | 8 | 58/60 | 85,760/85,760 · 0 | 293,748/294,144 · 2 | 93,945/93,952 · 0.00048828125 | 250,953/251,392 · 3.05175781e-05 | +| Clouds 1 v2 (245) | 1 | 56/60 | 134,912/134,912 · 0 | 228,500/228,608 · 1 | 93,948/93,952 · 0.00048828125 | 204,756/235,008 · 3.93390656e-06 | +| Clouds 1 v2 (245) | 8 | 56/60 | 134,912/134,912 · 0 | 228,495/228,608 · 1 | 93,949/93,952 · 0.00048828125 | 209,591/235,008 · 3.93390656e-06 | +| Clouds 2 (246) | 1 | 60/60 | 85,759/85,760 · 1 | 296,115/296,192 · 2 | 93,951/93,952 · 0.00048828125 | 253,352/253,440 · 2.29477882e-05 | +| Clouds 2 (246) | 8 | 60/60 | 85,759/85,760 · 1 | 296,115/296,192 · 2 | 93,951/93,952 · 0.00048828125 | 253,353/253,440 · 2.29477882e-05 | +| Clouds 2 v2 (247) | 1 | 58/60 | 134,912/134,912 · 0 | 244,961/244,992 · 1 | 93,952/93,952 · 0 | 245,384/251,392 · 9.53674316e-07 | +| Clouds 2 v2 (247) | 8 | 58/60 | 134,912/134,912 · 0 | 244,970/244,992 · 1 | 93,952/93,952 · 0 | 245,666/251,392 · 9.53674316e-07 | + +The missing scale-five settings are 64 × 32 F32 and 32 × 64 U16. Use seeds 103023/103024 for root 244, 103034/103035 for 245 and 103056/103057 for 247. Root 245 also exceeds the visit budget at 128², seed 411810 and scale three in U16 and F32. All 60 settings completed for root 246. + +MaterialCraft revision 039f310 repeated the 12 new settings per root and reproduced its earlier source-file outputs byte for byte. In inventory order the cross-app exact counts were 11,254, 10,839, 11,264 and 11,216 out of 11,264 each. The maximum errors on these settings were one U16 level and 1.52587891e−5 F32 for 244, 1.49011612e−7 F32 for 245, zero throughout for 246 and 5.96046448e−8 F32 for 247. Saving in MaterialCraft and reopening four of these settings reproduced every application’s own originals. Cross-app, the four saved settings matched 3,072, 2,969, 3,072 and 3,058 of 3,072 pixels respectively, with the same nonzero F32 maxima for 245 and 247. + +For the larger file comparison save each root in MaterialCraft, reopen the package in both applications and repeat every fourth setting in combination order, beginning at the first. The reference rendered 15 settings per saved package. MaterialCraft reproduced the raw digest of every setting it could render. The completed cross-app comparisons on one processor follow. + +| Root | Completed reopens / requested | Exact / total | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---| +| Clouds 1 | 14/15 | 120,793/121,088 | 0 / 1 / 0 / 3.05175781e-05 | +| Clouds 1 v2 | 13/15 | 102,982/104,704 | 0 / 1 / 0 / 3.09944153e-06 | +| Clouds 2 | 15/15 | 123,072/123,136 | 0 / 2 / 0 / 2.29477882e-05 | +| Clouds 2 v2 | 14/15 | 118,757/121,088 | 0 / 1 / 0 / 9.53674316e-07 | + +The reference source and saved images agreed on every pixel in all 15 settings for roots 244 and 246. The first comparison differed in three settings for root 245 and two for 247. Repeat both source and saved files with the reference pinned to each of the same two individual processors. For each tested configuration render seed offsets 0,7,0,19,0 and compare the three visits at the original seed. Use defaults in the initial U8 case. For the U16 scale-five case set disorder .8125, speed 1.4375, anisotropy .625, angle −.21875 and tile offset (−.3125,.4375), with non-square expansion enabled. At 64² and 128² F32 use scale three. Set disorder, speed and anisotropy all to .34375 or .65625 respectively, angle to .09375 or .40625, offset to (0,.10546875) or (.3125,−.16796875), and expansion on or off. Include the earlier single-processor capture, giving seven renders per file at each configuration. The following counts show coordinates that varied within each file. Every coordinate had at least one stored value in common between the two files at all eight configurations. A single pinned processor produced distinct frames on repeated visits to the same file in the listed varying F32 cases. + +| Root | Dimensions · format · seed | Varying pixels in source | Varying pixels in save | Largest difference across the 14 renders | +|---|---|---:|---:|---:| +| Clouds 1 v2 | 128 × 128 · U8 · 0 | 0 | 0 | 0 | +| Clouds 1 v2 | 32 × 64 · U16 · 103035 | 3 | 3 | 1 | +| Clouds 1 v2 | 64 × 64 · F32 · 411627 | 262 | 249 | 2.38418579e-07 | +| Clouds 1 v2 | 128 × 128 · F32 · 411810 | 1,657 | 1,554 | 2.98023224e-07 | +| Clouds 2 v2 | 128 × 128 · U8 · 0 | 0 | 0 | 0 | +| Clouds 2 v2 | 32 × 64 · U16 · 103057 | 0 | 0 | 0 | +| Clouds 2 v2 | 64 × 64 · F32 · 411641 | 12 | 17 | 1.1920929e-07 | +| Clouds 2 v2 | 128 × 128 · F32 · 411824 | 108 | 151 | 1.78813934e-07 | + +In the spot generator’s [32², scale-two case](#moisture-spot-and-cell-fields-across-processors-and-saved-packages), use seed 162174, disorder .78125, speed 1.015625, anisotropy .390625, angle .40625 and tile offset (.1708984375,−.29296875). Its first two U8 stages match 64/64 and 256/256, maximum zero. A bounded diagnostic run allowed 4,194,304 visits in the final stage. It counted 4,025,030 graph visits, 4,003,160 draws and 3,985,551 draws dropped before rasterization, leaving 17,609. The resulting F32 output matched 889/1,024 pixels, maximum 1.49011612e−7. The three-stage release diagnostic took 132,269 ms on one processor. The production visit bound still stops this setting. All five roots remain in progress. + +### Wrapped draw order for two children below depth seven + +Use the [original paired-square tree](#untiled-draw-order-for-two-and-four-children-below-depth-seven), with 64 subtrees, 256 depth-seven parents per subtree and two depth-eight children per parent. Enable both tiling axes in the unit window. Each parent draws an interior square with gain −1 or 2⁻²⁵ on a white F32 background. Align pairs of subtrees in 32 separate areas of the upper half of the image. Draw the children lower down with gain .25. Use a child width of 2.25 and height .875 in its own cell. Place both children on the horizontal seam for parents with index modulo 16 equal to zero, zero or one, or seven in three separate graphs. Center the other children horizontally. Render all 63 pairing rounds at 256² with seed 137143 + 17r for zero-based round r. + +The marker pixels are consistent with a change in parent order at indices 211, 144 and 212 respectively within a divided subtree. Each graph has two parent ranges. Displacing the competing interior squares by opposing one-cell offsets distinguished 8,064 cross-subtree relations per graph. One sequence of 29 contiguous draw ranges fits all three graphs when the splits are expressed in physical tile copies. In this sequence, splits occur every 5,460 copies drawn in composite order. The first three divided prefixes may finish in either of the last two subtrees before their continuations end. Later cuts can change the order of entire subtrees. MaterialCraft checks those boundaries before using either measured sequence. + +Six separately constructed graphs varied which parents put children on the seam. Use every 32nd parent, every 64th, every 16th in even subtrees, every 32nd shifted by three times the subtree index, every 16th except every 64th in subtrees 16–23, or every 16th in the first two of every four subtrees and every 32nd in the other two. Each selected sequence predicted 516,096/516,096 same-parent pair comparisons, maximum zero. The 26-range sequence applied to the every-64th case. A separate set used every 16th parent at the seam. Test each of the six two-slot combinations, then cycle through all six across the 64 subtrees. For rounds 3, 11, 24, 35, 43 and 58 render each gain orientation. In these seven graphs the complete F32 output improved from 4,391,856/5,505,024 to 5,505,024/5,505,024 pixels, maximum zero. + +A smaller original has 16 top-level groups of 1,024 parents. Pair groups zero and five with opposite gains and reverse them. Try child widths .875, 2.625, 4.75 and 8.875 at height .875, and X offsets 0, −1/512, .4995, .5 − 1/256, .375, .4375, −.125 and −.25 at Y offset .5. At 128², width .875 and offset −1/512 the tiny value occupies the first 274 parents in interleaved X/Y bit order. At offset .4995 it occupies the first 220 for width 4.75 and the first 188 for width 8.875, where four boundaries split a repeated stamp. The regression failed on the preceding revision at pixel (0,0). Across all 64 settings the complete F32 counts by width follow. + +| Child width | Previous exact / total | Current exact / total | Maximum absolute error | +|---:|---:|---:|---:| +| 0.875 | 257,684/262,144 | 261,640/262,144 | 2.98023224e-08 | +| 2.625 | 257,900/262,144 | 260,128/262,144 | 2.98023224e-08 | +| 4.75 | 258,200/262,144 | 261,076/262,144 | 2.98023224e-08 | +| 8.875 | 258,650/262,144 | 260,026/262,144 | 2.98023224e-08 | + +For the Clouds 2 root (79), repeat the [67 single-processor settings](#single-processor-comparisons-for-clouds-2-and-five-dirt-fields). Add 32 × 16, 64 × 256, 128² and 512 × 128 with seeds 175129 + 137j, zero-based in this order. Use U16 and F32 throughout and add U8 and F16 at the middle two sizes. This root has no exposed numeric control. Reuse the same MaterialCraft output for the two independently captured reference processor counts. Save the root in MaterialCraft, reopen it in both applications and render every fifth setting starting at the first. + +| Reference processors | Previous exact / total | Current exact / total | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:|---:| +| 1 | 1,439,952/1,440,000 | 1,439,994/1,440,000 | 235,008/235,008 · 0 | 500,220/500,224 · 2 | 235,008/235,008 · 0 | 469,758/469,760 · 2.29179859e-05 | +| 8 | 1,439,981/1,440,000 | 1,439,951/1,440,000 | 235,008/235,008 · 0 | 500,201/500,224 · 2 | 235,006/235,008 · 0.00048828125 | 469,736/469,760 · 2.29477882e-05 | + +The 12 added settings matched 263,168/263,168 pixels on one processor and 263,158/263,168 on eight. The 16 single-processor saved-file comparisons matched 285,184/285,184 across applications and reproduced each application's source outputs. The six single-processor differences come from 128², seed 42, in the original U16 storage and 128 × 256, seed 139711, in U16 and F32. The eight-processor total changed from 19 to 49 unequal pixels. Clouds 2 remains in progress. + +Expose the complete 49,152-draw generator as F32, preserving its two tiling axes. Of the three [earlier sizes](#tile-copies-and-the-draw-order-in-clouds-2), the 256² and 512 × 128 stages now match 65,536/65,536 each. The 32 × 16 stage matches 449/512, maximum 1.49011612e−8. For ten additional stages use 16 × 32, 32 × 64, 128 × 64, 64 × 128, 128², 256 × 128, 128 × 256, 256², 512 × 128 and 128 × 512. Use seed 175219 + 83j in this order. The completed counts improved from 250,310 to 275,369 of 297,472 pixels, maximum 3.72529030e−8. Five stages matched exactly. The other five still take the ordinary draw order because their split points cross an unmeasured subtree boundary. + +Repeat the [independently authored square and rotated-disc controls](#untiled-draw-order-for-two-and-four-children-below-depth-seven) with both tiling axes enabled, two terminal children, each gain orientation and all four storage formats. Each graph has 24 complete settings and six single-processor saved comparisons. Both applications reproduced their respective saved settings. U8 and U16 maxima below are stored levels. Floating maxima are absolute. + +| Original graph | Complete settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Square, source | 24 | 81,920/81,920 · 0 | 131,072/131,072 · 0 | 65,407/81,920 · 0.00048828125 | 106,918/131,072 · 1.1920929e-07 | +| Square, saved | 6 | 8,192/8,192 · 0 | 40,960/40,960 · 0 | 8,190/8,192 · 0.00048828125 | 32,702/40,960 · 1.1920929e-07 | +| Rotated disc, source | 24 | 81,920/81,920 · 0 | 131,072/131,072 · 0 | 73,591/81,920 · 6.10351562e-05 | 106,028/131,072 · 5.96046448e-08 | +| Rotated disc, saved | 6 | 8,192/8,192 · 0 | 40,960/40,960 · 0 | 8,192/8,192 · 0 | 32,631/40,960 · 5.96046448e-08 | + +The earlier four-child Dirt 1 and Dirt 6 F32 controls still matched 246,784/246,784 pixels across 12 settings. After the [individual-copy change](#individual-tile-copies-across-a-pattern-draw-boundary), the prior 17-root verified set also matched all 3,139,328 pixels across its 167 root settings. Six interleaved single-processor release timings per binary after warmup gave medians of 765→780 ms at 256² and 753→770 ms at 512 × 128 for the Clouds 2 generator. The 430 release tests for the node and evaluation crates passed, along with formatting, workspace Clippy, layering and the WebAssembly check. + +### Projecting stamp vertices relative to pixel centers in scaled windows + +Draw one original horizontal offset ramp on a zero F32 background. Use tint 2, offset −1, global gain 1, additive blending, zero rotation and disabled tiling. Set the stamp width and height to the square render-window span S. Put the center at (S/2,S/2). At S = 7 and output 64², columns 12 and 19 return F32 bits BF1C0001 and BEC80004 in every row. Previously they returned BF1C0000 and BEC80000. At S = 3, output 32² and center X = 1.5 + 3/4096, the same columns return BE608008 and 3E5F7FF8. At S = 13 and output 32 × 64 they return BE600008 and 3E5FFFF8. The regression failed at the first S = 7 sample before the change. + +The reference results use a projected coordinate relative to sample zero. MaterialCraft now stores the pattern-space vertex, subtracts the window origin and combines projection and the −.5 pixel offset in one rounded F32 multiply-add. The snapped triangle and its coordinate interpolation both use that stored value. The early coverage check uses the same origin. + +For the 150-render sweep use S = 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,37,41,43,47,51,53,55,59,61,1.125,1.203125,1.3125,1.671875. In each window use (width,height,normalized X offset,width multiplier) of (64,64,0,1), (32,64,0,1), (32,32,1/4096,1), (64,32,.173177,1) and (64,32,.173177,.915781). Set center X to (.5 + offset)S and the stamp width to S times the multiplier. Use seed 170123 + 37j + k for zero-based span and configuration indices. Save the S = 3,7,13,51 graphs in MaterialCraft and reopen all five settings per graph in both applications. + +In a separate 198-render sweep keep the vertical span and stamp height at one. Use horizontal spans S = 3,7,13,15,51,1. For each, set the window width W to S or its immediate F32 neighbor below or above. For the first four cases use stamp width S and center X = (.5 + d)S. The (pixel width, pixel height, d) triples are (64,64,0), (32,64,0), (32,32,1/4096) and (64,32,.173177). For the next six cases at 64², the pairs (stamp width, twice the X center) are (W,W), (S−,S), (S+,S), (S,S−), (S,S+) and (1,S), where − and + denote neighboring F32 values. Finish with (1,1) at 32 × 64. Use seed 181161 + 73j + 11h + k for span index j, window step h in {−1,0,1} and case index k. One output still differs at 128 pixels, maximum 1.19209290e−7. + +For a separate edge test position either the near vertex or the padded far vertex at a half pixel. Try the horizontal spans 3,7,13,51,1.125,1.203125,1,3.375, widths 32,64,128 and height 32. With size S times .0625,.126953125,.25,.4375,.5,.78125,1 or 1.03125, solve for the stamp center that places the vertex at column x + .5. Test that F32 center and its two F32 neighbors. For x running from −1 to width − 2, retain up to four distinct (width,x) pairs per span and vertex where rounding before or after the half-pixel offset changes the snapped column. These give 34 renders. Interpolating from the corrected coordinates while retaining the previous snap matched 52,096/54,272 pixels. Moving both operations to the sample-relative coordinates matched 53,760/54,272 and made 27 whole renders exact. + +| Original controls | Renders | Previous exact / total | Current exact / total | Current maximum absolute error | +|---|---:|---:|---:|---:| +| Horizontal ramps across 30 spans | 150 | 314,688/337,920 | 337,920/337,920 | 0 | +| Independent window, center and size variations | 198 | 561,088/645,120 | 644,992/645,120 | 1.1920929e-07 | +| Edges that change snapped column | 34 | 51,680/54,272 | 53,760/54,272 | 1.1920929e-07 | +| Ramps on both axes in six render windows | 168 | 426,144/442,368 | 441,344/442,368 | 1.1920929e-07 | +| Rectangular windows and independent dimensions | 140 | 257,524/286,720 | 282,100/286,720 | 4.76837158e-07 | +| Individual paraboloids from the two cell roots | 34 | 560,829/579,584 | 565,400/579,584 | 4.41534212e-07 | +| Earlier unit-window ramps, precision neighbors and both brick roots | 544 | 7,065,600/7,065,600 | 7,065,600/7,065,600 | 0 | + +The last row includes the four storage formats for the brick outputs. The 20 saved ramp settings improved from 24,640/45,056 to 45,056/45,056 cross-app, maximum zero. Both applications reproduced their own source outputs. The three tiled Clouds 2 generator settings and six Dirt 6 generator settings retained 165,313/165,376 F32 pixels, maximum 1.49011612e−8. All 79 complete Clouds 2 root digests also reproduced revision f9699eb. + +For each Cells 1 root, repeat the [60 or 61 settings and saved comparisons](#moisture-spot-and-cell-fields-across-processors-and-saved-packages). Add 16 × 64, 64 × 32, 64 × 128 and 128 × 64 with seed 181763 + 31i + 97j for inventory index i and zero-based size j. Use U16 and F32 at all four sizes and add U8 and F16 at the middle two. Use defaults first, then the earlier settings with scale/disorder (1,.34375), (2,.78125) and (1,.5625). In v2 keep angle .125, angle random .2, pattern 3, pattern size (.8,1.2), pattern scale .8 and luminance random .25. For disorder d, use speed .625 + .5d, anisotropy .5d, anisotropy angle d − .375 and tile offset (.21875d,−.375d). Save and reopen every third added setting, beginning with the first. + +Both independent reference processor counts, one and eight, gave the same comparisons for each entire root. The 12 additional settings per root matched 59,392/59,392 pixels across both applications. Integer maxima below are stored levels and the F16 and F32 maxima are absolute. + +| Root | Settings | Previous exact / total | Current exact / total | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:|---:|---:| +| Cells 1 (240) | 72 | 777,168/788,736 | 778,411/788,736 | 96,000/96,000 · 0 | 315,611/315,648 · 1 | 104,192/104,192 · 0 | 262,608/272,896 · 2.38418579e-07 | +| Cells 1 v2 (241) | 73 | 805,006/808,192 | 805,710/808,192 | 148,224/148,224 · 0 | 267,520/267,520 · 0 | 99,072/99,072 · 0 | 290,894/293,376 · 3.27825546e-07 | + +Only two settings per root differ. In Cells 1 these are U16 and F32 at 128 × 512, seed 411897, scale seven and disorder .53125 with non-square expansion disabled. In Cells 1 v2 they are F32 at 128², seed 269, and 32², seed 383. Use scale 13, disorder .6875, speed .625, base angle .0625, random angle .1875, anisotropy .25 at angle .125, pattern 4, size (.875,1.125), pattern scale .8125, luminance random .375 and tile offset (.1875,−.3125). Enable non-square expansion only at 128². + +| Saved root | Settings | Cross-app exact / total | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---| +| Cells 1 | 19 | 142,555/142,592 | 0 / 1 / 0 / 0 | +| Cells 1 v2 | 20 | 211,712/211,712 | 0 / 0 / 0 / 0 | + +All of these saved settings reproduced each application’s own source frame. The isolated one-processor release timings used six interleaved runs per revision after warmup. Median Clouds 2 generator time changed from 792 to 811 ms at 256² and from 779 to 793 ms at 512 × 128. The two timed Cells 1 settings changed from 37.0 to 37.2 ms and from 24.4 to 24.6 ms. Both roots remain in progress. Formatting, all 431 release tests for the node and evaluation crates, workspace Clippy, dependency layers and the WebAssembly check passed. + +### Two-child draw order when neighboring subtrees cross different tile batches + +In the two-child additive square tree, groups of 256 depth-seven parents each contribute 768 logical stamps. Boundary crossings increase the number of physical draws in each group. Three leading batches begin at groups 24, 40 and 8. Three other batches first consume two subtrees from groups 50, 54 or 58 and then continue from groups 16, 32 or 0, respectively. Each batch ends after 5,460 tile copies. The continuation order depends on which of the three paired batches reaches the split one subtree early. MaterialCraft selects the observed 26–29 draw runs from those physical counts. A split can separate two copies of the same stamp. + +Repeat the [two-child square controls](#wrapped-draw-order-for-two-children-below-depth-seven). In each of 64 subtrees, count parent positions p from 0 to 255 in quadrant traversal order. Move the two terminal slots of selected parents to the horizontal tile edge and keep the others in the interior. For the first six distributions select every 32nd parent, every 64th, every 16th in even groups only, every 32nd with phase 3g, every 16th except every 64th in groups 16–23, and every 16th in groups divisible by four with every 32nd elsewhere. Here g is the zero-based subtree index. For a second series, give groups 0–7, 16–23 and 32–39 independently a period of 16 or 64. Keep period 32 elsewhere and select (p + 3g) modulo the period equal to zero. These eight patterns exercise every combination of split positions. + +Compare each pair of the 64 subtrees at all 256 parent positions by adding −1 and 2⁻²⁵ in opposite orders against a unit background. Displaced readouts distinguish segments that otherwise never overlap. All 4,128,768 pair decisions in the eight-pattern series agreed with the resulting draw order. Six other distributions matched 3,096,576/3,096,576 decisions. Five independently authored distributions with the same per-subtree copy totals as individual cloud renders matched 2,580,480/2,580,480. To reproduce the five totals, use the exposed 128² generator at seeds 42 and 43, 128 × 256 at seed 139711, 32 × 64 at seed 175302 and 512 × 128 at seed 175883. For each group distribute half the extra copies in evenly spaced pairs and place an odd remaining copy in the first parent. Eight full F32 frames from each of the eight patterns and five matched distributions gave 6,815,744/6,815,744 pixels, maximum zero. + +Independently vary the widths of the two terminal squares over .875, 2.625, 4.75 and 8.875 with frame X offsets 0, −1/512, .4995, .5 − 1/256, .375, .4375, −.125 and −.25. Keep the frame Y offset .5. Both signs across these 64 renders matched 1,048,576/1,048,576 pixels. The width .875 and X offset .4995 regression failed at (0,0) before the fix. The 84 existing terminal-slot comparisons retained 5,505,024/5,505,024 exact pixels, the 48 original shape controls retained 851,968/851,968 and 12 four-child controls retained 246,784/246,784. + +For Clouds 2 (79), repeat the [79 earlier whole-root settings](#wrapped-draw-order-for-two-children-below-depth-seven) on one and eight processors. Extend with 128² at seeds 41 and 43, 128 × 256 at 139710 and 139712, 128 × 64 and 32 × 128 at 183419, and 256 × 64 at 183531. Use U16 and F32 throughout and add U8 and F16 at seeds 43 and 139710. Save the graph in MaterialCraft and reopen the previous 16 settings and all settings from the new 128² seed 43, 128 × 256 seed 139710 and 32 × 128 seed 183419 cases. Each application reproduced its own source pixels, and the 26 cross-app comparisons matched 489,984/489,984 pixels, maximum zero. + +| Reference processors | Distinct whole settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---:|---:|---:|---:|---:|---:| +| 1 | 97 | 284,160/284,160 · 0 | 627,200/627,200 · 0 | 284,160/284,160 · 0 | 596,736/596,736 · 0 | +| 8 | 97 | 284,160/284,160 · 0 | 627,169/627,200 · 2 | 284,158/284,160 · 0.00048828125 | 596,709/596,736 · 2.29477882e-05 | + +One processor matched 1,792,256/1,792,256 raw whole-root pixels, including the six previously differing pixels at seeds 42 and 139711. The eight-processor comparison matched 1,792,196/1,792,256. Exposing the generator directly in F32 matched 429,056/429,056 pixels across the 13 earlier settings and 180,224/180,224 at seven additional settings. Those seven use 128² at seeds 42, 41 and 43, 128 × 256 at seeds 139711, 139710 and 139712, and 256 × 128 at seed 139711. At the six intermediate or final output taps, eight whole-graph settings matched 758,784/758,784 stored pixels. The reopened output selections also reproduced each source tap. + +For ten representative whole settings, alternate the original seed with offsets +13, +29 and +43, returning to the original after each change. Include the earlier capture for five raw comparisons per setting. Two separately pinned single processors each reproduced every coordinate in all five frames. On eight processors between one and seven coordinates per setting varied across the five frames. Five coordinates across four settings differed from MaterialCraft in all five eight-processor frames. Clouds 2 remains in progress. Six interleaved one-processor release timings per revision after warmup gave median generator times of 574 to 571 ms at 256² and 567 to 562 ms at 512 × 128. All 431 release tests for the node and evaluation crates, formatting, workspace Clippy, dependency layers and the WebAssembly check passed. + +### Inverting the stored pixel projection in scaled stamp regions + +The last two differing settings in each Cells 1 root reproduced with individual original paraboloids. Turn off tiling and place one stamp at each contributing translated center. The maximum of those untiled stamps reproduced each original tiled paraboloid. Two signed offset ramps, one along each local axis, further isolated the coordinate error. In the 128 × 512 case, one horizontal ramp differed at center X −2.5763158798217773, while its copy at X 4.423684120178223 matched. Across 127 isolated, translated and tiled stamp renders, the current comparisons improved from 2,844,826/2,907,136 pixels to 2,907,136/2,907,136, maximum zero. All 34 original isolated cell stamps also match, 579,584/579,584 F32 pixels. + +A smaller reproduction uses one horizontal ramp, additive blend, tint 2, offset −1 and a zero gray F32 background. Disable tiling. Use stamp size (1,1), center (.5,.5), render bounds (0,13,0,1), output 32 × 64 and seed 181317. The first two pixels have bits BF180001 and 3E5FFFF0. The previous build returned BF180000 at column zero. With horizontal span 7, stamp width .4375, center X one F32 step below .109375, 32² output and seed 181746, the first two pixels return B3800000 and 3F7FFFFC. MaterialCraft now computes pattern units per pixel by taking the reciprocal of the rounded F32 pixels-per-unit projection. The integration regression failed on the first reproduction before this change. + +The [150 original scaled windows, 198 one-ULP variations and 34 half-pixel edges](#projecting-stamp-vertices-relative-to-pixel-centers-in-scaled-windows) now match 337,920/337,920, 645,120/645,120 and 54,272/54,272 F32 pixels, all maxima zero. The previous last two counts were 644,992 and 53,760. The 20 reopened ramp settings matched 45,056/45,056. The 544 earlier ramp and brick checks retained 7,065,600/7,065,600 exact pixels. + +For 64 independent signed ramps, use horizontal spans S = 7,13,15,61,109,121,1.125,3.375. The vertical span T is the entry three positions ahead, wrapping at the end. For zero-based span index j, the window origin X is −(S−1)/2 for even j and −S/4 for odd j, while Y is zero for multiples of three and −3T/8 for the others. For zero-based case k use the eight tuples (output, width fraction, rotation in turns) below. Center the stamp at origin + (S(.375 + .01953125k), T(.25 + .041015625k)). Its size is (S times the width fraction, T(.375 + .046875k)). At k = 6 use size (1,T) and center origin + (.5,T/2). Use seed 185109 + 97j + k. + +| k | Output | Width fraction | Rotation | +|---:|---|---:|---:| +| 0 | 32 × 64 | .0625 | 0 | +| 1 | 64 × 32 | .296875 | .25 | +| 2 | 128 × 64 | .4375 | 0 | +| 3 | 64 × 128 | .53125 | .25 | +| 4 | 64² | .3125 | .0576171875 | +| 5 | 32 × 128 | .203125 | −.1015625 | +| 6 | 32 × 64 | 1/S | 0 | +| 7 | 64 × 32 | .3828125 | .125 | + +These 64 frames improved from 261,376/262,144 pixels, maximum 1.43051147e−6, to 262,144/262,144, maximum zero. They include spans where inverting the stored projection rounds the pixel size up, down and exactly. + +Repeat the [whole Cells 1 suites](#projecting-stamp-vertices-relative-to-pixel-centers-in-scaled-windows) with one and eight reference processors. Add the cases below to each root. Use the scale, disorder and expansion settings shown here. For v2 set speed .625, angle .0625, random angle .1875, anisotropy .25 at angle .125, pattern 4, pattern size (.875,1.125), pattern scale .8125, luminance random .375 and tile offset (.1875,−.3125). Use U16 and F32 throughout and add U8 and F16 for both scale-13 settings. + +| Output | Seed | Scale | Disorder | Non-square expansion | +|---|---:|---:|---:|---| +| 128 × 256 | 411896 | 7 | .53125 | Off | +| 64 × 128 | 411898 | 7 | .53125 | On | +| 64² | 185241 | 13 | .6875 | Off | +| 128 × 64 | 185253 | 13 | .6875 | On | +| 32 × 64 | 185293 | 15 | .34375 | On | +| 64 × 32 | 185303 | 9 | .78125 | Off | + +Both processor configurations gave the following exact counts independently. Every maximum error is zero. The source captures also reproduced all 729,344 original archived pixels for Cells 1 and all 748,800 for Cells 1 v2. + +| Root | Distinct settings | U8 exact / total | U16 exact / total | F16 exact / total | F32 exact / total | +|---|---:|---:|---:|---:|---:| +| Cells 1 (240) | 88 | 108,288/108,288 | 372,992/372,992 | 116,480/116,480 | 330,240/330,240 | +| Cells 1 v2 (241) | 89 | 160,512/160,512 | 324,864/324,864 | 111,360/111,360 | 350,720/350,720 | + +Save and reopen the previously differing settings and every third new setting, starting with the first, in addition to the earlier file checks. Across applications Cells 1 matched 265,472/265,472 pixels in 26 distinct reopened settings. Cells 1 v2 matched 286,464/286,464 in 28. Both applications also reproduced their own source frames. A duplicate Cells 1 reopen at 128 × 512 was exact and is counted once. Cells 1 and Cells 1 v2 are marked Parity for these measured cases. The inventory now has 449 roots at Parity and 97 in progress. + +The six interleaved one-processor release timings per revision after warmup gave Cells 1 medians of 39.6 to 39.4 ms and 26.3 to 26.3 ms. The two Clouds 2 medians were 747 to 754 ms and 716 to 759 ms. All 431 release tests for the node and evaluation crates, formatting, strict workspace Clippy, dependency layers and the WebAssembly check passed. + +### Creased and crystal noise sources on one and eight processors + +Repeat the earlier whole-graph comparisons for the three noise-library roots with the reference restricted to one processor and then to eight. The originals have no image pins. Compare raw output codes for U8 and U16 and stored bits for F16 and F32. The source graphs reproduce the archived reference frames on every one of their original 38, 48 and 48 distinct settings. These accounted for 696,320/696,320, 718,080/718,080 and 718,080/718,080 pixels respectively. [Earlier settings and measurements](#original-and-reopened-dirt-moisture-and-cellular-noise-fields) + +Add 16 settings per root using the five rows below. For zero-based row j and inventory index i, use seed 186119 + 97i + 37j. Keep the unlisted parameters at their defaults. For Creased set the warp intensity equal to the disorder at each changed setting. + +| j | Output | Scale for Creased / Crystal 1 / Crystal 2 | Disorder | Non-square expansion | Formats | +|---:|---|---|---:|---|---| +| 0 | 32 × 16 | defaults | default | default | U16, F32 | +| 1 | 64 × 128 | 2 / 27 / 2 | .96875 | off | U8, U16, F16, F32 | +| 2 | 128 × 64 | 3 / 19 / 3 | .65625 | off | U8, U16, F16, F32 | +| 3 | 64² | 1 / 12 / 1 | .09375 | on | U8, U16, F16, F32 | +| 4 | 128 × 32 | 1 / 5 / 1 | .875 | off | U16, F32 | + +The two processor configurations independently gave the counts below. Every maximum error was zero. + +| Root | Distinct settings | U8 exact / total | U16 exact / total | F16 exact / total | F32 exact / total | Reopened settings | Reopened exact / total | +|---|---:|---:|---:|---:|---:|---:|---:| +| Creased (248) | 54 | 103,680/103,680 | 314,112/314,112 | 103,680/103,680 | 265,984/265,984 | 14 | 198,912/198,912 | +| Crystal 1 (249) | 64 | 104,704/104,704 | 317,184/317,184 | 112,896/112,896 | 274,432/274,432 | 16 | 198,400/198,400 | +| Crystal 2 (250) | 64 | 104,704/104,704 | 317,184/317,184 | 112,896/112,896 | 274,432/274,432 | 16 | 198,400/198,400 | + +Save the graphs in MaterialCraft, reopen each in both applications, and render again. The historical reopen settings common to all three use 128² defaults in U16, 64² seed 42 in U8, 32² seed 113 in F32, then rows 0, 1, 3, 4, 5, 7 and 9 of the earlier ten-size series in F32, F32, U16, F32, F32, F16 and U16 respectively. For both crystal roots also reopen the earlier changed 32² U8 and 64 × 32 F32 controls, with seeds 103074 and 103078 for Crystal 1 and 103085 and 103089 for Crystal 2. From the new table reopen rows 1–3 in U8 and row 4 in U16 for Creased, and row 0 in U16 and rows 1–3 in F16 for both crystal roots. Both applications reproduced every pixel of their own source graphs as well. All three roots are marked Parity within these measured settings. + +## 2026-11-20 root comparisons + +### Hue, saturation, lightness and Replace Color + +The HSL primitive adds twice each slider's displacement from .5 to saturation and lightness, then clamps. For an HDR input it divides RGB by the largest of 1 and the three input channels before adjusting color and restores that gain afterwards. With default settings pure red produces (.999877930, .0001220703125, .00109827518) in the reference. Equal-channel .125 gray with saturation .75 produces (.1875,.0625,.0625). Changing lightness to .75 instead gives (.625,.625,.625). + +| Measured outputs | Exact pixels before | Maximum U8 / U16 / F16 / F32 error before | Exact pixels after | Maximum U8 / U16 / F16 / F32 error after | +|---|---:|---|---:|---| +| Palette and two coordinate fields, 90 renders | 13,380/42,240 | 126 / 32256 / 0.492195129 / 1.02734375 | 35,732/42,240 | 0 / 1 / 0.000122070312 / 1.54972076e-06 | +| Independent colors and nearly equal channels, 72 renders | 8,189/79,872 | 255 / 65535 / 1.31054688 / 3.25 | 52,896/79,872 | 0 / 1 / 0.001953125 / 0.000122368336 | +| Replace Color, 19 whole renders | 99,049/142,592 | 64 / 15809 / 0.241210938 / 0.244705796 | 136,480/142,592 | 1 / 1 / 0.000244140625 / 1.07288361e-06 | + +Alpha matched the source in both applications for all 75,520 direct F32 pixels. The color error that remains is largest on nearly gray colors with raised saturation. In a separate 26-hue sweep with saturation 1 and lightness .5, 5,387/13,312 F32 pixels match, maximum error 0.000122845173. Four original HSL graphs saved by MaterialCraft reopened in the reference. Their 24 before/after readbacks across all four formats matched 15,104/15,104 pixels, maximum error zero. + +Build a single HSL node with a linear F32 color input. For the first six cases at each setting use 16² F32, 16×32 F32, 32×16 F32, then repeat the 16×32 source in U8, U16 and F16. Seed case k at setting j with 104887+17j+k, both zero-based. In the 16² palette vary alpha by row y/16 and cycle RGB across black, white, .5 gray, .125 gray, red, green, blue, yellow, magenta, cyan, (.25,.5,.75), (.75,.5,.25), (.625,.375,.125), (.875,.375,.5), (.1875,.375,.25), and (.75,.625,.125). For channel c at coordinates x,y use v=((11x+17y+13xy+7c+5xc+3yc) mod 67)/64. The unit field uses min(1,v). The HDR field uses 2.5v−.75 and replaces the first 16 RGB pixels in row zero with the palette. + +Start with omitted controls, then set (hue,saturation,lightness) to (.5,.5,.5), (.625,.5,.5), (.375,.5,.5), (.5,.25,.5), (.5,.75,.5), (.5,0,.5), (.5,1,.5), (.5,.5,.25), (.5,.5,.75), (.5,.5,0), (.5,.5,1), (.3125,.6875,.15625), (.875,.1875,.8125) and (−.125,1.125,−.25). + +For the independent six-case batch use 64×32 F32, 32² F32, 32×16 F32, then the 32² field in U16, F16 and U8. Use seed 105289+17j+k. In the first image choose low=floor(y/6)/16, high=1−low and middle=low+(x/64)(high−low). Permute the channels using lexicographic permutation index (y+floor(x/32)) mod 6. For the second image draw PCG64 seed 105022 uniformly over [−.8125,2.3125), convert to F32, and replace even rows with F32 uniform draws in [0,1). For the third image choose a base cyclically by (x+3y) from [−.5,−0,0,smallest positive F32,2⁻¹⁸,2⁻¹²,.125,.49999997,.5,.50000006,.875,1,2,4]. Add and subtract a difference from [0,2⁻²⁴,2⁻¹⁸,2⁻¹²,.0625,.25] indexed by (floor(x/3)+2y) mod 6. Permute (base,base+d,base−d) by (x+y) mod 6, and use (.7,.3,.1) in the first pixel. Draw the three alpha fields over [−.375,1.375) with the corresponding PCG64 streams seeded 105021, 105022 and 105023. Set the first pixel's alpha to .6 in each image. + +The 12 settings for the independent fields are (.5,.5,.5), (0,.5,.5), (1,.5,.5), (.75,.5,.5), (.5,1,.5), (.25,1,.5), (.625,1,.5), (.5,.5,.625), (.5,.625,.5), (.1875,.3125,.75), (.8125,.625,.4375) and (.5000031,.499817,.499987). + +The separate hue sweep uses 32×16 linear F32, seed 106871+j and hue [0, 0.03125, 0.08333333, 0.1092233, 0.125, 0.15625, 0.18739991, 0.25, 0.3125, 0.4375, 0.46875, 0.49999997, 0.5, 0.50000006, 0.500371, 0.5772527, 0.5833333, 0.625, 0.6666667, 0.6875, 0.75, 0.81115973, 0.8333333, 0.9101257, 0.96875, 1]. Set alpha to (x+.5)/32. For x<8 take gray from [0,.0625,.1875,.25,.3125,.49999997,.5,.5625,.6875,.75,.9375,1,1.5,2,3.125,4] indexed by row y. For 8≤x<20 use ((31x+79y+3xy) mod 253)/252. For x≥20 take the same positions in a row-major 32×16 PCG64 field drawn uniformly over [−.125,1.5) with seed 106913. Set all RGB channels to that F32 gray. + +For Replace Color repeat the four archived cases, the [five precision and seed cases](#four-format-inventory-comparison), and the ten [linear input and size cases](#shared-lookups-and-environment-shadow-pass) with i=442 and a single RGBA input. Use source/target color settings (.5,.5,.5)/(.5,.5,.5) for A, (.125,.625,.8125)/(.8125,.25,.375) for B, and (.875,.1875,.3125)/(.25,.75,.125) for C. The root still differs in all four output formats. Its standalone regressions for hue endpoints, additive adjustments and HDR gain failed on the previous implementation and passed with the change. All 252 release node tests, formatting, strict workspace Clippy, dependency layers and WebAssembly checks passed. + +### Shared lookups and environment shadow pass + +Three whole roots matched all 721,408 pixels across 103 renders. The tile and noise roots used two original lookup images in both applications. Their earlier comparisons used different lookup data. The parity measurements below apply to the two common inputs. + +| Root | Renders | Exact pixels / compared | Pixels in U8 / U16 / F16 / F32 | Maximum error in U8 / U16 / F16 / F32 | +|---|---:|---:|---|---| +| tile_random_2 | 38 | 285,184/285,184 | 10,240 / 240,640 / 14,336 / 19,968 | 0 / 0 / 0 / 0 | +| blue_noise | 38 | 285,184/285,184 | 10,240 / 11,264 / 14,336 / 249,344 | 0 / 0 / 0 / 0 | +| ibl_shadow_pass | 27 | 151,040/151,040 | 6,144 / 6,656 / 9,728 / 128,512 | 0 / 0 / 0 / 0 | + +Generate two 256² grayscale U16 lookups with zero-based coordinates. The first is `19*(809*x+4079*y+127*x*y+3121) mod 65536`. The second is 53249 where `(5*x+13*y) mod 17 < 4` and 1023 elsewhere. Bind the same image to the active Bitmap in each application. For each lookup repeat the archived 128² and 256² defaults, 128² seed 42, 128² changed settings, and the [five precision and seed cases](#four-format-inventory-comparison). + +For the ten additional cases use zero-based inventory index i=378, 410 or 413. Add [0,1,2,2,2,2,6,7,8,9] to seed 104351+17i. Use [16²,32²,32²,32²,32²,32²,32×16,16×32,64×32,32×64], storage [F32,F32,U8,U16,F16,F32,F32,U16,F32,F16] and settings [defaults,A,B,B,B,B,C,C,B,A]. + +| Published controls | A | B | C | +|---|---|---|---| +| Tile counts X/Y, random size and random position multipliers | 2/2, 0, 0 | 3/5, .5625, .3125 | 5/3, .875, .6875 | +| Corner radius, random size map multiplier, mask start, shape rotation | 0, 0, 0, 0 | .15625, .375, .1875, .15625 | .4375, .6875, .4375, −.21875 | +| Dithering | 0 | .3125 | .8125 | +| Shadow sequence, total samples, horizontal rotation | 1, 2, 0 | 2, 5, .15625 | 5, 9, −.21875 | + +For bound inputs number each component n=4p+c with zero-based input index p and channel c. Use random_size_map, random_slant_map, round_corners_radius_map, bevel_distance_map, mask_map in the tile graph and blue_noise, environment, normal in the shadow graph. The first two cases use U8, taking the floor of the following levels divided by 257. The flat level is 8199+2413n. The impulse field is 59003−391n where `(x+2n) mod 11 = (y+3n) mod 11` and 302+67n elsewhere. For the two C settings use U16 with level 32769+n where `(7x+13y+3n) mod 11 = 0`, and 32767−n elsewhere. The other cases use F32 with level `7919*(11x+31y+7xy+93+47n+(n+1)x) mod 65536` divided by 65535. Import the fields as linear data. Swapping lookup images changes 4,766 tile pixels numerically across these ten cases. The noise root also changes with the input, including 1,024/1,024 pixels in the 32² F32 B case. + +Eight additional shadow renders use curved normals and a bright diagonal band in an HDR environment. At pixel centers u=(x+.5)/width and v=(y+.5)/height, set z=2v−1 and angle=2π(u+m/16). Encode the unit normal (sqrt(1−z²) cos(angle), sqrt(1−z²) sin(angle), z) in [0,1]. The environment RGB is (u+1.5b, v+.75b, .125+.75uv), with b=1 where `abs((x+4y+3m) mod width−width/2) < max(width/9,1)` and zero elsewhere. Both alphas are one. The noise input's channel c is `(37x+59y+13xy+47c+11m) mod 251` divided by 250. + +Use m=[0,1,2,3,3,3,4,5], seed 106399+17m, sizes [16²,32×16,16×32,32²,32²,32²,64×32,32×64] and storage [F32,F32,F16,U8,U16,F32,F32,F16]. For m=0..5 use sequences [1,2,4,3,5,7], sample counts [2,3,5,6,9,11] and rotations [0,.125,−.1875,.375,.5625,−.125]. All 8,448 shadow pixels match. The 16² F32 output contains values as high as 35.6196213. + +### Paper, brick, fiber, mesh, polygon and shape roots + +All eight roots produced 19 whole outputs apiece. Across 152 renders, 915,896/1,140,736 pixels matched. Every root differs in at least one recorded case. Integer error counts storage levels. Floating-point error is the largest absolute difference in a stored channel. + +| Root | Exact whole pixels / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---| +| paper_path | 135,674/142,592 | 0 / 1 / 0.0009765625 / 5.69224358e-06 | +| brick_1 | 139,565/142,592 | 0 / 1 / 0 / 6.94394112e-06 | +| brick_2 | 139,074/142,592 | 0 / 1 / 3.81469727e-06 / 1 | +| fibers_2 | 139,312/142,592 | 0 / 2 / 0.000244140625 / 3.05175781e-05 | +| mesh_1 | 41,087/142,592 | 0 / 5317 / 0.0375976562 / 0.0811322033 | +| mesh_2 | 39,574/142,592 | 0 / 9102 / 0.0595703125 / 0.138887614 | +| polygon_2 | 141,734/142,592 | 0 / 4 / 3.05175781e-05 / 6.10351562e-05 | +| shape_base | 139,876/142,592 | 0 / 1 / 0.00048828125 / 1.37090683e-06 | + +Use the four archived cases, the [four-format sweep and independent seed](#four-format-inventory-comparison), and ten additional renders. Use the zero-based inventory index i and seed 103547+17i plus [0,1,2,2,2,2,6,7,8,9]. The sizes are [16²,32²,32²,32²,32²,32²,32×16,16×32,64×32,32×64]. Use [F32,F32,U8,U16,F16,F32,F32,U16,F32,F16] and settings [defaults,A,B,B,B,B,C,C,B,A]. Apply the controls exposed by the selected root. + +| Controls | A | B | C | +|---|---|---|---| +| Paper width, height, disorder | 100, 100, 0 | 73.5, 119.25, .375 | 137.25, 65.5, .8125 | +| Integer scale, edge smoothness, interstice width | 1, 0, 0 | 3, .15625, .21875 | 5, .546875, .0625 | +| Nonsquare expansion, tiling, rotate 45° | on, 1, off | off, 3, on | on, 2, off | +| Boolean rotation, polygon sides, polygon scale | off, 3, 1 | on, 5, .75 | off, 9, 1.1875 | +| Polygon rotation, curve, gradient, invert gradient | 0, 0, 1, off | .125, .3125, .625, on | −.21875, −.1875, .1875, off | +| Autoscale, pattern, pattern-specific control | on, 2, 0 | off, 5, .1875 | on, 9, .5625 | +| Shape scale, XY size, angle, nonsquare | 1, (1,1), 0, on | .8125, (.625,.8125), .21875, off | 1.1875, (1.1875,.4375), −.3125, on | + +For each connected pattern stage retain the shortest path to an authored stamp, breaking ties by connection identifier, and clear image inputs. For the shape root use its single authored quadrant and choose square or disc through its published pattern control. Use the nine cases excluding 64×32. Each variant covers ten stages in 90 renders. + +| Root | Authored shape numbers | Authored exact / compared | Maximum authored U8 / U16 / F16 / F32 error | Square exact / compared | Disc exact / compared | +|---|---|---:|---|---:|---:| +| paper_path | 15 | 8,446/8,448 | 0 / 0 / 0 / 1.07288361e-06 | 8,448/8,448 | 8,448/8,448 | +| brick_1 | 9 | 8,173/8,448 | 0 / 1 / 0 / 1.7285347e-06 | 8,448/8,448 | 8,448/8,448 | +| brick_2 | 9 | 8,330/8,448 | 0 / 1 / 0 / 3.08454037e-06 | 8,448/8,448 | 8,448/8,448 | +| fibers_2 | 6 | 985/1,728 | 0 / 1 / 0 / 5.96046448e-07 | 1,728/1,728 | 1,728/1,728 | +| mesh_1 | 13 | 2,000/3,264 | 0 / 1 / 3.05175781e-05 / 1.07288361e-06 | 3,264/3,264 | 3,261/3,264 | +| mesh_2 | 15 | 2,380/3,456 | 0 / 1 / 0.00048828125 / 2.83122063e-06 | 3,456/3,456 | 3,456/3,456 | +| polygon_2 | 3, 10, 16 | 21,510/25,344 | 0 / 1 / 0.00048828125 / 4.17232513e-07 | 25,344/25,344 | 25,344/25,344 | +| shape_base | published pattern + 1 | 7,951/8,448 | 0 / 1 / 0 / 1.49011612e-07 | 8,448/8,448 | 8,448/8,448 | + +Authored shapes match 59,775/67,584 pixels, squares 67,584/67,584, and discs 67,581/67,584. The reference produced nonzero pixels in 89, 90 and 89 of the 90 renders respectively. The three unequal disc pixels are all in the first mesh root. Its disc maximum U8 / U16 / F16 / F32 error is 0 / 65535 / 0 / 1.00211096. + +Four roots also have downstream stages. Replace the source patterns with the original fields, sizes and input storage used in the [dirt source substitutions](#dirt-noise-sources-and-downstream-stages). Each row covers ten outputs. The two mesh roots produce identical residual totals with these inputs. Their 32×64 F16 field cases account for their maximum floating error. + +| Root | Exact pixels / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---| +| fibers_2 | 10,496/10,496 | 0 / 0 / 0 / 0 | +| mesh_1 | 8,984/10,496 | 0 / 1 / 0.25 / 1.52587891e-05 | +| mesh_2 | 8,984/10,496 | 0 / 1 / 0.25 / 1.52587891e-05 | +| polygon_2 | 10,496/10,496 | 0 / 0 / 0 / 0 | + +### Deep pattern samples in custom render and tiling regions + +The FX-Map traversal checks tiny procedural stamps against the actual render and tiling rectangles. A discarded stamp must miss every candidate output sample of every visible copy, or have its center culled by the tiling region. The raster and traversal use the same region rules, including reversed intervals and disabled tiling axes. A stamp with more than four candidate copies goes through ordinary raster accounting. The visit, discard, copy and pixel limits stay in effect. + +Generate ten levels of empty quadrants. At each level connect all four slots to the next quadrant. Draw an additive axis-aligned gray square of local size (1,1) at each leaf, opacity 2⁻²⁰, zero roughness, global opacity one, over zero. Repeat with nine levels. For each table row j, render 4² F32, 8×4 U16, 4×8 F32 and 16² F32 with seed 417341+43j+k at format index k=0…3. + +| j | Depth | Render region (left, right, top, bottom) | Tiling region | Tiled axes | Cull outside | Previous result | Exact / total after | Maximum error | +|---:|---:|---|---|---|---|---|---:|---:| +| 0 | 10 | (-0.5, 1.5, -0.5, 1.5) | (-0.5, 1.5, -0.5, 1.5) | both | off | 4 visit errors | 336/336 | 0 | +| 1 | 10 | (0.125, 0.625, -0.25, 0.75) | (0, 1, 0, 1) | both | off | 4 visit errors | 336/336 | 0 | +| 2 | 10 | (-0.25, 0.75, 0.25, 1.25) | (-0.25, 0.75, 0.25, 1.25) | x | off | 4 visit errors | 336/336 | 0 | +| 3 | 9 | (0.125, 0.625, -0.25, 0.75) | (-0.25, 0.75, 0, 0.5) | both | on | 336/336 | 336/336 | 0 | +| 4 | 9 | (0.625, 0.125, 0.875, 0.25) | (0, 1, 0, 1) | y | off | 336/336 | 336/336 | 0 | +| 5 | 9 | (0, 1, 0, 1) | (0.25, 0.75, 0.125, 0.625) | none | on | 336/336 | 336/336 | 0 | + +In the expanded window the four central samples of the 4×4 F32 image equal 2⁻²⁰ and the twelve outer samples are zero. Before the change this regression returned the traversal-budget error. The two unit-window controls matched 32/32. Another 696 original rectangle, tiling, ramp, square and falloff controls match **1,966,080/1,966,080 F32 pixels**, maximum zero, before and after the change. [Original traversal and budget controls](#bounded-traversal-of-deep-patterns) + +At 32² F32, seed 113, scale 2 and disorder .37, the first BnW Spots 3 and first Dirt 5 noise packages (inventory indices 238 and 268) now finish with 1,024/1,024 exact pixels each, maximum zero. Both previously returned the visit error. At 64², seed 42, BnW Spots 3 also finishes in all four output formats with the same scale and disorder. U8 matches 4,096/4,096, U16 4,094/4,096 (maximum 1), F16 4,096/4,096 and F32 4,093/4,096 (maximum 1.06692314e−5). The companion packages at 239 and 269 still reach the visit guard for their independent 32² cases with disorder speed .6, anisotropy .3, anisotropy angle .125 and tile offset (.17,.29). Both Directional Noise 3, Dirt 1 and Dirt 4 variants also reach the guard in their independent 32² cases. + +### Bounded traversal of deep patterns + +Four roots reached the traversal guard even at 4×4. A diagnostic MaterialCraft release build raised its visit ceiling from 1,048,576 to 2,097,152 and the raster copy ceiling from 1,048,576 to 8,388,608 for this experiment. The 256,000,000-pixel-work guard remained active. Use defaults, F32, and seeds 106622, 106635, 106765 and 106778 in table order. Each process cooked one graph on one worker. Peak resident memory includes graph loading. The visit and stamp counts are for the most expensive pattern stage. Times are single observations. + +| Package | Whole pixels exact | Maximum F32 error | Visits / emitted stamps | Cook seconds | Peak MiB | First differing stage | +|---|---:|---:|---:|---:|---:|---| +| noise_directional_noise_3 | 13/16 | 2.50339508e-05 | 1,398,103 / 1,392,640 | 14.65 | 291.0 | Depth-ten pattern, 13/16 U16 pixels, one level | +| noise_directional_noise_3_v2 | 16/16 | 0 | 1,430,879 / 1,392,640 | 42.12 | 291.6 | All observed stages exact | +| noise_dirt_4 | 0/16 | 0.103746146 | 1,398,103 / 1,398,080 | 13.63 | 289.4 | Sharpen, after an exact 2×2 U16 source | +| noise_dirt_4_v2 | 0/16 | 1.63018703e-05 | 1,463,647 / 1,398,080 | 42.36 | 290.2 | Sharpen, after an exact 2×2 U8 source | + +Both dirt graphs already match all four source texels before sharpening. In the first graph a reference F32 edge is −.103746146 and the local edge is zero. The second has only small positive differences. In the first directional graph the two smaller patterns and their blend match exactly. Three values differ by one stored level in the deepest pattern, and those differences reach the final Levels node. + +For a traversal-only control, connect all four slots of each empty quadrant to the next quadrant, down to depth nine or ten. Use absolute 4×4 F32 output, zero roughness, unit global opacity, additive axis-aligned square leaves, gray level 2⁻²⁰, and seed 107011 + 17 × depth + 4. Use leaf size (1,1) for one cell or (2^depth,2^depth) for an image-wide square. The input consists entirely of these original parameters. + +| Depth and footprint | Visit ceiling | Exact pixels | Maximum error | Cook seconds | Peak MiB | +|---|---:|---:|---:|---:|---:| +| 9, cell | 1,048,576 | 16/16 | 0 | 0.94 | 190.6 | +| 9, wide | 1,048,576 | 16/16 | 0 | 0.95 | 190.4 | +| 10, cell | 1,048,576 | Execution budget | — | 2.55 | 239.3 | +| 10, cell | 2,097,152 | 16/16 | 0 | 3.98 | 225.2 | +| 10, wide | 1,048,576 | Execution budget | — | 2.48 | 224.8 | +| 10, wide | 2,097,152 | 16/16 | 0 | 3.80 | 225.4 | + +Depth ten produces 1,398,101 visits and 1,048,576 stamps. Raising only the visit ceiling renders both footprints. The cell case produces exactly one increment per pixel. In the wide case each pixel receives 409,600 to 802,816 increments. Both controls match every stored bit. At depth nine the wide case receives 102,400 to 200,704 increments. Dropping the last subdivision would therefore change the output. + +For a separate partition test, isolate the deepest pattern of each directional graph and the sole pattern of each dirt graph. At the first quadrant whose four outputs point to the same child, keep just one connected slot. Repeat with each of the four slots, retaining its original slot number. Render 4², 8², and 8×4 F32, using seeds 103307 + 13 × the zero-based inventory index + 0, 1 and 2 respectively. Use the first two distinct default/changed settings from the linked family measurements. All 48 partitioned renders complete with the standard guard. They match 160/1,120 pixels, with maximum F32 error .0000105798244. These are separate quadrant images. Full-root parity remains open for all four graphs. + +### Clamped texture reads in spline graphs + +The sampling mode stored with an image slot controls both filtering and edge addressing. Modes 0 and 1 repeat the image, with nearest and bilinear filtering respectively. Modes 2 and 3 clamp to its edges with the same two filters. Previously the two clamped modes both used bilinear repeat. At a spline boundary this mixed the opposite end of the tangent field into the first sample. + +| Whole root | Renders | Previously exact | Exact / compared | Pixels in U8 / U16 / F16 / F32 | Maximum channel error | +|---|---:|---:|---:|---|---:| +| compute_spline_tangents | 27 | 43,296 | 43,776/43,776 | 7,168 / 7,168 / 7,168 / 22,272 | 0 | +| modify_spline_property_sub | 19 | 24,317 | 28,928/28,928 | 5,120 / 5,632 / 7,168 / 11,008 | 0 | +| resample_spline_data | 19 | 29,816 | 29,952/29,952 | 5,120 / 5,632 / 7,168 / 12,032 | 0 | +| select_spline_sub | 19 | 583,680 | 622,592/622,592 | 65,536 / 98,304 / 98,304 / 360,448 | 0 | +| spline_warp_sub | 19 | 28,448 | 28,928/28,928 | 5,120 / 5,632 / 7,168 / 11,008 | 0 | + +All five roots match 754,176/754,176 pixels. The tangent root includes the 18 independently wired line, circle and signed-curve outputs in the [spline helper controls](#wired-spline-helpers-and-shape-mapping). Three other roots use the same sampler modes in their graph definitions. The grayscale grid atlas and the sorting iteration in each of the quantization and shape-splatter packages still match all 344,064 pixels in their 12 archived renders. + +For the four other spline roots, add ten cases to the nine archived and changed-precision controls per root. Use sizes, formats and A/B/C settings from the [shared lookup matrix](#shared-lookups-and-environment-shadow-pass). The base seed is 109121 + 17 × the zero-based inventory index. Add 0, 1, 2, 2, 2, 2, 6, 7, 8 and 9 in case order. + +For field A/B/C let m be 0/1/2. Defaults use m=0. At each of the first two rows j=0,1, use angle 2π((x+.5)/width+m/16+j/8), center (.34375+.28125j,.59375−.1875j) and radii (.1875,.1875), (.25,.09375) or (.15625,.28125). Fill the coordinate map with (cx+rx cos angle, cy+ry sin angle, 1, −1) and the data map with (−sin angle, cos angle, 0, 1). Other rows are zero. At normalized pixel centers u,v, the UV input is (u,v,1−u,1). The vector map is (.5+.25 cos(2π(u+v)), .5+.375 sin(2πu), .5, 1). Use u for the attenuation curve. Other scalar fields have H=((11x+7y+5xy+13m) mod 251)/250. Their color equivalents use (H,1−H,.125+.75H,1). Supply the fields as linear F32. + +| Root and controls in order | A | B | C | +|---|---|---|---| +| Modify property, sampling mode / property / opacity / blending mode | 0 / 0 / 1 / 0 | 1 / 1 / .6875 / 1 | 1 / 2 / .3125 / 2 | +| Select, spline index / output / selection mode / range start and end / normalized start and end | 0 / 0 / 0 / 0…1 / 0…1 | 1 / 1 / 1 / 0…1 / .1875….8125 | 0 / 1 / 0 / 1…2 / .3125….6875 | +| Warp, intensity / center / sampling mode / vector map / attenuation curve / start and end attenuation / intensity map tiling | 0 / .5 / 0 / off / off / 0 and 0 / 1 | .1875 / .375 / 1 / on / on / .15625 and .21875 / 2 | .34375 / .6875 / 0 / on / on / .25 and .09375 / 3 | + +Resample uses its published defaults. In the original pixel probe, fill an 8×4 image with Q=(79x+53y+29xy+17c+11xc+3) mod 251 in channel c. Store Q for U8, 251Q for U16, or (Q−91.75)/71.375 for F16 and F32. In a Pixel Processor read color or luminosity at UV×gain+offset. Broadcast the luminosity to four channels. Test all four sampling modes in each source format. + +| Output and extent | UV gain | UV offset | +|---|---|---| +| 16² F32 | (1,1) | (0,0) | +| 32×16 F32 | (2,2) | (−.5,−.5) | +| 16×32 F32 | (−1.75,2.5) | (1.34375,−.6875) | +| 32×16 U8, U16, F16 | (2,2) | (−.5,−.5) | +| 8×4 F32, five separate reads | (0,0) | (0,0), (1,1), (−.125,.25), (.3359375,.40625), (1.3125,−.375) | +| 32² F32 | (.8125,−.6875) | (.1875,.875) | + +Start at seed 109847 + 17 × the input storage index (U8, U16, F16, F32), adding one per row or repeated read. The 384 pixel-processor renders improved from 76,755 to 128,000/128,000 exact pixels. The maximum became zero in every output format. Repeat modes 2 and 3 in the [uniform texture controls](#texture-sampling-in-pattern-functions). Use the same 13 positions and add controls running mode 0 or 1 at coordinates clamped to [1/64,63/64]. Across 416 pattern renders, 262,144 pixels previously matched and all 425,984 now match. The 104 typed Float4 values improved from 64 to 104 exact, maximum error zero. Uniform bilinear reads clamp each tap index and retain the original fractional weights. At (1.0311,−.65315) on the F32 source, the unclamped fractions produce green bits `bed93e38`, one bit different from clamping the coordinate before interpolation. + +Six original sampler packages saved by MaterialCraft reopened in the reference. Across six reads per package, all 15,040 pixels and all 12 Float4 values matched the respective original packages, maximum error zero. The two pixel graphs used modes 2 and 3 on F32 color and U16 luminosity. Each uniform scope used nearest and filtered clamp on the U8 color source. + +Two further roots with these modes remain open. The shape-splatter normal processor matches 666/142,592 pixels over 19 renders. Maximum finite U8 / U16 / F16 / F32 errors are 255 / 65,462 / .998570919 / .998893440. Some outputs contain nonfinite channels. The point preview returned 27,904/27,904 equal final pixels in 15 comparable cases, but the text stage reports an external-font error. In the three separate count/offset wrappers the counts are 4, 8 and 12 and the offsets are 0, 1 and 2. The error prevents a whole-root comparison in those wrappers. + +### 3D noise with two original permutation tables + +The basic and ridged 3D noise roots matched all 872,960 output pixels across 112 renders with identical procedural lookups. In every render the Bitmap in each application also matched all 16,384 U16 lookup texels. Replacing one lookup with the other changed the result in all 17 basic cases and all 39 ridged cases. It changed 172,483 and 261,463 pixel values respectively. + +| Whole root | Renders | Exact / compared | Pixels in U8 / U16 / F16 / F32 | Maximum error | +|---|---:|---:|---|---:| +| 3D_perlin_noise | 34 | 347,136/347,136 | 231,424 / 34,816 / 38,912 / 41,984 | 0 | +| 3D_ridged_noise_fractal | 78 | 525,824/525,824 | 239,616 / 43,008 / 47,104 / 196,096 | 0 | + +For each table initialize Python 3.12 `random.Random` once, using seed 104729 for the first and 1299709 for the second. In each of 16 rows, shuffle a fresh list of integers 0 through 1023 using that generator. Store each shuffled value k at level `round(k × 65535 / 1023)` in a linear grayscale 1024×16 U16 image. Bind the image to the active Bitmap in both applications. Repeat the [seven basic cases](#basic-and-ridged-3d-perlin) and the [29 ridged cases](#natural-exponential-and-ridged-noise) with each table. + +Add ten position fields per root and table. At integer coordinates x,y let u=(x+.5)/width, v=(y+.5)/height and R=((31x+47y+13xy+17m) mod 251)/250. Store the linear RGBA32F vector (u+.3125v−.25, 1.375v−.1875u−.125, 2R−.875+.0625m, 1). Use seed 134269+17m. Setting A uses defaults. B/C use scale 6/11 for basic noise. For ridged noise use octave levels 1–4 and roughness .6875 for B, and levels 2–6 and roughness .3125 for C. + +| Extent | Storage | m | Setting | +|---|---|---:|---| +| 16² | F32 | 0 | A | +| 32×16 | F32 | 1 | B | +| 16×32 | F32 | 2 | C | +| 32² | U8, U16, F16, F32 | 1 | B | +| 8×32 | F32 | 3 | C | +| 64×32 | F32 | 2 | B | +| 32×64 | F16 | 1 | C | + +After the sampler and Sharpen changes, 24 repeat renders reproduced all 21,504 pixels bit for bit. The inventory status covers the common procedural inputs. The applications' bundled tables give different default output. On the 128² seed-zero ramp, basic noise matched 173/16,384 U8 pixels (maximum 203 levels) and ridged noise matched 176/16,384 (maximum 139 levels). [Bundled table measurements](#natural-exponential-and-ridged-noise) + +### Tile, weave, splatter and fiber stage comparisons + +Across 25 roots, 3,294,234/3,483,648 whole output pixels matched in 474 renders. All 25 had a measured difference. Another 18 renders of wood_fibers_2 reached the traversal limit before producing a whole image. The numbers below use zero-based inventory indices to distinguish graphs with identical names. Error is the largest stored-channel difference, in levels for integers and absolute units for floats. A dash indicates an unavailable comparison. + +| Index and graph | Renders | Exact whole pixels / compared | Maximum U8 / U16 / F16 / F32 error | First differing stage IDs in the ten new renders | +|---|---:|---:|---|---| +| 374 · tile_generator_color | 19 | 137,997/142,592 | 0 / 49 / 0.0009765625 / 0.00121033192 | 1238191865 pattern | +| 381 · weave_1 | 19 | 139,840/142,592 | 0 / 1 / 0 / 1.52587891e-05 | 1064675946 pattern | +| 382 · weave_2 | 19 | 140,765/142,592 | 1 / 59 / 0.0009765625 / 0.00169374049 | 1298573641 pattern, 1298573810 pattern | +| 383 · pavement_1 | 19 | 141,408/142,592 | 0 / 2 / 0 / 2.06083059e-05 | 1047650292 pattern | +| 416 · sphere_displace | 19 | 142,163/142,592 | 0 / 329 / 0.000244140625 / 0.000122070312 | 1335843323 pixel processor | +| 418 · perlin_noise_zoom | 19 | 131,983/142,592 | 0 / 1 / 0.000244140625 / 8.34465027e-07 | 1051010199 pattern | +| 438 · kmeans_iteration | 19 | 77,776/77,824 | 0 / 0 / 0 / 8.94069672e-08 | 1502542656 pixel processor | +| 441 · radial_blur_grayscale | 19 | 121,514/142,592 | 1 / 14 / 0.00048828125 / 0.000137329102 | 1310833960 pattern, 1312489342 pattern | +| 463 · scratches_1 | 19 | 133,530/142,592 | 0 / 3 / 0.00048828125 / 4.06503677e-05 | 1028634246 pattern | +| 464 · scratches_2 | 19 | 118,291/142,592 | 1 / 2 / 0.00048828125 / 4.4465065e-05 | 1028227090 pattern | +| 465 · scratches_4 | 18 | 106,551/126,208 | 1 / 5 / 0.00048828125 / 4.57763672e-05 | 1047058056 pattern | +| 466 · shape_base | 19 | 139,931/142,592 | 0 / 1 / 0.00048828125 / 1.37090683e-06 | 1041346098 pattern | +| 488 · splatter | 19 | 142,577/142,592 | 0 / 91 / 0.00122070312 / 0.00137332082 | 1028307162 pattern | +| 489 · splatter_circular | 19 | 139,297/142,592 | 231 / 59438 / 1 / 1.00000006 | 1048865333 pattern | +| 490 · splatter_circular_color | 19 | 140,218/142,592 | 247 / 65535 / 0.96862793 / 0.996078431 | 1048865333 pattern | +| 491 · splatter_color | 19 | 142,551/142,592 | 1 / 83 / 0.00134277344 / 0.00141908228 | 1028307162 pattern | +| 509 · starburst | 19 | 141,503/142,592 | 0 / 1 / 1.52587891e-05 / 1.52592547e-05 | 1065612277 pattern | +| 520 · tile_generator | 19 | 139,723/142,592 | 0 / 42 / 0.00048828125 / 0.000639975071 | 1238191865 pattern | +| 521 · tile_generator_color | 19 | 137,445/142,592 | 1 / 103 / 0.00146484375 / 0.00199997425 | 1067616990 pattern | +| 522 · tile_random | 19 | 111,364/142,592 | 223 / 57311 / 1 / 1.00000006 | 1126353318 pattern | +| 523 · tile_random_color | 19 | 111,228/142,592 | 250 / 65535 / 1 / 2.00000003 | 1126353318 pattern | +| 534 · vertical_noise | 19 | 142,088/142,592 | 0 / 2 / 0.00048828125 / 1.75237656e-05 | 1094664716 pattern, 1041349787 output | +| 537 · weave_1 | 19 | 139,856/142,592 | 0 / 1 / 6.10351562e-05 / 1.52587891e-05 | 1064675946 pattern | +| 538 · weave_2 | 19 | 138,111/142,592 | 0 / 3 / 0.00048828125 / 4.57763672e-05 | 1035222092 pattern | +| 544 · wood_fibers_1 | 19 | 136,524/142,592 | 1 / 10 / 0.00048828125 / 7.51614571e-05 | 1035311965 pattern | +| 545 · wood_fibers_2 | 18 | 0 comparable outputs | 0 / 0 / 0 / 0 | pattern traversal | + +Repeat the archived default, seed 42, changed controls when available, and the [four-format and independent-seed comparison](#four-format-inventory-comparison). For the ten additional renders use the extents, formats, settings and seed offsets in the [shared lookup matrix](#shared-lookups-and-environment-shadow-pass). The base seed is 104351+17i through index 441 and 107839+17i thereafter. The table gives changes in A / B / C order. Other parameters retain their published defaults. + +| Inventory indices | Controls and their A / B / C values | +|---|---| +| 374 | x_amount 2 / 3 / 5 · y_amount 2 / 5 / 3 · pattern 2 / 1 / 3 · pattern_input_number 1 / 6 / 3 · image_input_filtering 2 / 1 / 0 · pattern_size (1,1) / (0.6875,0.8125) / (1.25,0.5625) · position_random (0,0) / (0.125,0.1875) / (0.3125,0.0625) · pattern_rotation_random 0 / 0.375 / 0.6875 · rotation 0 / 0.15625 / -0.21875 · global_opacity 1 / 0.8125 / 0.375 | +| 381 | Tiling 1 / 2 / 3 · rotate_45_degrees off / on / off · non_square_expansion on / off / on | +| 382 | scale 1 / 3 / 7 · Disorder 0 / 0.3125 / 0.8125 · rotate_45_degrees off / on / off · non_square_expansion on / off / on | +| 383 | Roudness 0 / 0.3125 / 0.8125 | +| 416 | size 1 / 0.8125 / 0.5625 · displacement_intensity 0 / 0.1875 / 0.625 · uv_scale (1,1) / (0.75,1.25) / (1.5,0.625) · uv_offset (0,0) / (0.1875,-0.28125) / (-0.3125,0.4375) · tilt_uvs off / on / off · samples 2 / 5 / 9 | +| 418 | Distance 2 / 5 / 11 · Disorder 0 / 19.375 / 61.25 | +| 438 | k 2 / 3 / 5 · ignore_alpha off / on / off · color_space 1 / 0 / 1 | +| 441 | samples 2 / 5 / 11 · angle 0 / 0.09375 / -0.21875 · center_position (0.5,0.5) / (0.375,0.6875) / (0.1875,0.8125) | +| 463 | Pattern_size_width 100 / 73.5 / 137.25 · Pattern_size_height 100 / 119.25 / 65.5 · Disorder 0 / 0.375 / 0.8125 · Rotation_Var 0 / 31.25 / 63.75 · Rotation 0 / 22.5 / -16.875 | +| 464 | Pattern_size_width 100 / 73.5 / 137.25 · Pattern_size_height 100 / 119.25 / 65.5 · Disorder 0 / 0.375 / 0.8125 | +| 465, 545 | Published defaults | +| 466 | pattern 1 / 5 / 8 · pattern_specific 0 / 0.1875 / 0.5625 · scale 1 / 0.8125 / 1.1875 · size_xy (1,1) / (0.625,0.8125) / (1.1875,0.4375) · angle 0 / 0.21875 / -0.3125 | +| 488, 491 | Pattern_size_width 100 / 73.5 / 137.25 · Pattern_size_height 100 / 119.25 / 65.5 · Disorder 0 / 0.375 / 0.8125 · Rotation_Var 0 / 31.25 / 63.75 · Rotation 0 / 22.5 / -16.875 · Grid_Number 2 / 3 / 5 · Pan_X 0 / 0.125 / -0.1875 · Pan_Y 0 / -0.0625 / 0.21875 · Gain 1 / 0.625 / 0.8125 · image_input_filtering 2 / 1 / 0 · Disorder_Random off / on / on | +| 489 | Number 2 / 5 / 7 · Radius 0.25 / 0.375 / 0.1875 · Radius_Random 0 / 0.21875 / 0.4375 · Pattern 2 / 1 / 3 · PatternSize (0.25,0.25) / (0.1875,0.3125) / (0.375,0.125) · PatternSize_Random 0 / 0.15625 / 0.4375 · Rotation 0 / 22.5 / -16.875 · image_input_filtering 2 / 1 / 0 · CenterOrientation off / on / off · RandomMask 0 / 0.1875 / 0.375 | +| 490 | number 2 / 5 / 7 · radius 0.25 / 0.375 / 0.1875 · radius_random 0 / 0.21875 / 0.4375 · pattern 2 / 1 / 3 · pattern_size (0.25,0.25) / (0.1875,0.3125) / (0.375,0.125) · pattern_size_Random 0 / 0.15625 / 0.4375 · rotation 0 / 0.21875 / -0.3125 · image_input_filtering 2 / 1 / 0 · center_orientation off / on / off · random_mask 0 / 0.1875 / 0.375 | +| 509 | Branches 3 / 7 / 11 · BlurAmount 0 / 1 / 2 · Randomness 0 / 0.375 / 0.8125 · SizeMin 0.125 / 0.21875 / 0.0625 · SizeMax 0.875 / 0.6875 / 1 · SizeVariation 0 / 0.3125 / 0.625 · Tiling 1 / 2 / 3 | +| 520, 521 | Nb_X 2 / 3 / 5 · Nb_Y 2 / 5 / 3 · Scale 1 / 0.8125 / 0.5625 · ScaleVariation 0 / 0.21875 / 0.4375 · Offset 0 / 0.375 / -0.25 · Pattern_Type 2 / 1 / 3 · image_input_filtering 2 / 1 / 0 · Free_Rotation 0 / 0.09375 / 0.21875 · Position_Random (0,0) / (0.125,0.0625) / (0.3125,0.25) · GlobalOpacity 1 / 0.6875 / 0.4375 | +| 522, 523 | x_amount 2 / 3 / 5 · y_amount 2 / 5 / 3 · pattern 2 / 1 / 3 · image_input_filtering 2 / 1 / 0 · pattern_rotation_random 0 / 0.21875 / 0.4375 · split_threshold 0.5 / 0.3125 / 0.8125 · shape_scale 1 / 0.6875 / 1.125 · position_random 0 / 0.1875 / 0.4375 · mask_random 0 / 0.125 / 0.3125 | +| 534, 544 | Disorder 0 / 0.375 / 0.8125 | +| 537 | Tiling 1 / 3 / 2 · Rotate_45_Degrees off / on / off | +| 538 | Tiling 1 / 3 / 2 · Rotate_45_Degrees off / on / off · Disorder 0 / 0.375 / 0.8125 | + +For each bound pin use the flat, impulse, near-threshold and hashed fields in the [shared input recipe](#shared-lookups-and-environment-shadow-pass). Set n=4p+c for indices through 441, or n=4(p+1)+c for later indices, with p the zero-based pin position in the following table and c the channel. Single-channel inputs use c=0. + +| Index | Bound pins in field order | +|---|---| +| 374 | pattern_input_1, pattern_input_2, pattern_input_3, pattern_input_4, pattern_input_5, pattern_input_6, background | +| 416 | input | +| 438 | input, seeds | +| 441 | input | +| 488 | Source | +| 489 | Source, background | +| 490 | Source, background | +| 491 | Source, Source_alpha | +| 520 | Source, background | +| 521 | Source, background | +| 522 | pattern_input, background_input | +| 523 | background_input_1, pattern_input | + +To isolate the pattern stages, connect the identified stage directly to the output, disconnect its input images, and retain the shortest branch from the pattern root to a node with a nonempty or dynamic shape. For ties, visit the output slots in identifier order. Render once with its authored shape and again with a disc (pattern 3). Use the ten-case matrix indices 0, 2, 3, 4, 5 and 7. This retains the branch parameters, seeds and output-format inheritance. Stage dimensions can differ from the whole output. The counts cover every stored channel of each output pixel. + +| Index and stage ID | Retained branch IDs, root to stamp | Authored exact / compared | Authored maximum U8 / U16 / F16 / F32 | Disc exact / compared | Disc maximum U8 / U16 / F16 / F32 | +|---|---|---:|---|---:|---| +| 374 · 1238191865 | 1299185944 → 1299185946 → 1032256671 → 1032256560 | 4,777/4,864 | 0 / 0 / 0 / 2.95042992e-06 | 4,864/4,864 | 0 / 0 / 0 / 0 | +| 381 · 1064675946 | 4087961384 → 4087966788 → 4087966766 → 4087966772 | 1,390/1,408 | 0 / 1 / 0 / 9.53674316e-07 | 1,408/1,408 | 0 / 0 / 0 / 0 | +| 382 · 1298573641 | 1298572907 → 1298572909 → 1298572911 → 1298574249 | 4,864/4,864 | 0 / 0 / 0 / 0 | 4,864/4,864 | 0 / 0 / 0 / 0 | +| 382 · 1298573810 | 1035222495 → 1035222491 | 1,183/1,216 | 0 / 0 / 0 / 5.36441803e-07 | 1,216/1,216 | 0 / 0 / 0 / 0 | +| 383 · 1047650292 | 1027784760 → 1027785067 → 1027785022 | 152/152 | 0 / 0 / 0 / 0 | 152/152 | 0 / 0 / 0 / 0 | +| 418 · 1051010199 | 1051010310 → 1051010203 | 3,649/4,864 | 0 / 1 / 0 / 8.34465027e-07 | 4,864/4,864 | 0 / 0 / 0 / 0 | +| 441 · 1310833960 | 1312497559 → 1312497566 | 4,864/4,864 | 0 / 0 / 0 / 0 | 4,864/4,864 | 0 / 0 / 0 / 0 | +| 441 · 1312489342 | 1312497441 → 1312497447 | 4,864/4,864 | 0 / 0 / 0 / 0 | 4,864/4,864 | 0 / 0 / 0 / 0 | +| 463 · 1028634246 | 4087623626 → 4087677897 → 1028225479 → 1028225487 → 1028634317 → 4087677903 | 4,863/4,864 | 0 / 0 / 0 / 1.14087015e-08 | 4,864/4,864 | 0 / 0 / 0 / 0 | +| 464 · 1028227090 | 4087623626 → 4087677895 → 1025020977 → 1025023617 → 1028227170 → 1028227669 → 1028227391 | 4,864/4,864 | 0 / 0 / 0 / 0 | 4,864/4,864 | 0 / 0 / 0 / 0 | +| 465 · 1047058056 | 4087623626 → 4087677895 → 4087677897 → 1047057855 → 1047057852 → 1027434391 → 4087677903 | 4,861/4,864 | 0 / 0 / 3.05175781e-05 / 2.4959445e-06 | 4,864/4,864 | 0 / 0 / 0 / 0 | +| 466 · 1041346098 | 4094898783 | 4,626/4,864 | 0 / 1 / 0 / 1.49011612e-07 | 4,864/4,864 | 0 / 0 / 0 / 0 | +| 488 · 1028307162 | 1033746299 → 1033745600 | 4,864/4,864 | 0 / 0 / 0 / 0 | 4,864/4,864 | 0 / 0 / 0 / 0 | +| 489 · 1048865333 | 1048865351 → 1181069015 | 4,843/4,864 | 0 / 65535 / 0 / 0 | 4,603/4,864 | 255 / 65535 / 1 / 1 | +| 490 · 1048865333 | 1048865351 → 1181069015 | 4,834/4,864 | 0 / 53713 / 0 / 0 | 4,710/4,864 | 209 / 53713 / 0.819335938 / 0.819607973 | +| 491 · 1028307162 | 1033746299 → 1033745600 | 4,864/4,864 | 0 / 0 / 0 / 0 | 4,864/4,864 | 0 / 0 / 0 / 0 | +| 509 · 1065612277 | 1048629866 → 1048629846 | 1,290/1,408 | 0 / 1 / 9.53674316e-07 / 2.68220901e-06 | 1,408/1,408 | 0 / 0 / 0 / 0 | +| 520 · 1238191865 | 1032256671 → 1032256560 | 4,777/4,864 | 0 / 0 / 0 / 2.95042992e-06 | 4,864/4,864 | 0 / 0 / 0 / 0 | +| 521 · 1067616990 | 1032256671 → 1032256560 | 4,777/4,864 | 0 / 0 / 0 / 2.95042992e-06 | 4,864/4,864 | 0 / 0 / 0 / 0 | +| 522 · 1126353318 | 1127323343 → 1126890304 → 1126797479 → 1126797467 → 1126797473 → 1126891504 → 1126892423 → 1126797483 | 4,864/4,864 | 0 / 0 / 0 / 0 | 4,864/4,864 | 0 / 0 / 0 / 0 | +| 523 · 1126353318 | 1127323343 → 1126890304 → 1126797479 → 1126797467 → 1126797473 → 1126891504 → 1126892423 → 1126797483 | 4,864/4,864 | 0 / 0 / 0 / 0 | 4,864/4,864 | 0 / 0 / 0 / 0 | +| 534 · 1094664716 | 1028056080 → 1028056090 → 1028376477 → 1028376473 → 1028055564 | 2,430/2,432 | 0 / 0 / 0 / 5.96046448e-08 | 2,432/2,432 | 0 / 0 / 0 / 0 | +| 537 · 1064675946 | 4087961384 → 4087966788 → 4087966766 → 4087966772 | 1,390/1,408 | 0 / 1 / 0 / 9.53674316e-07 | 1,408/1,408 | 0 / 0 / 0 / 0 | +| 538 · 1035222092 | 1028306906 → 1028306857 → 4089929701 → 1035222497 → 1035222495 → 1035222491 | 1,405/1,408 | 0 / 0 / 2.38418579e-07 / 4.07162588e-08 | 1,408/1,408 | 0 / 0 / 0 / 0 | +| 544 · 1035311965 | 1029866950 → 1030039276 | 3,938/4,864 | 0 / 1 / 0 / 8.94069672e-07 | 4,864/4,864 | 0 / 0 / 0 / 0 | + +Ten isolated packages at indices 441, 466, 522 and 523 opened in the reference after saving them with MaterialCraft. All 48,640 local pixels in these 60 renders were bit-identical before and after the save. Nine packages matched all 4,864 reference pixels each. The authored shape at index 466 differed at 234 F32 pixels and four U16 pixels. Its disc matched in all four formats. + +Across all 25 stages, 150 authored single-branch renders matched 94,097/96,984 pixels, and 150 disc controls matched 96,569/96,984. A differing disc leaves placement, coverage or evaluation upstream of the original shape open. Sphere displacement and K-means first differ in their pixel processors. The later [bounded whole-graph cook](#discarding-pattern-stamps-that-miss-every-output-sample) completed 17 of 18 Wood Fibers 2 renders. + +### Signed Sharpen stencils and stored inputs + +Sharpen preserves negative lobes in floating-point output and uses the input's working storage when resizing. Its four-neighbor stencil starts with the weighted left texel. It adds the center, right, top and bottom terms in that order, fusing the product and addition at each step. With horizontal weight H and vertical weight V, the center weight is 1+2(H+V). H and V scale intensity by the shorter output side divided by the respective axis length. The two earlier sign and resizing regressions and two further accumulation checks failed on the preceding implementations. All 256 release node tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +| Original probe | Renders | Exact / compared | Maximum error | +|---|---:|---:|---| +| Impulse, signed ramp and constant, U16 and F32 sources | 16 | 5,632/5,632 | 0 in all four output formats | +| Grayscale and RGBA with output size inherited from the input | 108 | 10,512/10,512 | 0 in all four output formats | +| Output size set by parent | 108 | 38,549/38,832 comparable | 0 / 0 / 0 / 1.87000686 in U8 / U16 / F16 / F32 | +| Independent signed field with five nonzero strengths and changed sizes | 80 | 16,417/16,704 | 4.39762998 F32 | +| Dirt 4 and its second version, shared 2² sources | 8 | 136/136 | 0 F32 | + +For the impulse matrix, place a single white texel at (8,8) in a black 16² image. Render at intensity one in all four formats and at 32² F32. At 16² the floating-point output is 5 at the center, −1 at its four axial neighbors and zero at the diagonals. In U8 and U16 the center is white and the neighbors black. Add the 16² signed field (((x+3y) mod 17)−5)/8 at intensities .375 and 0, and a flat .28125 at intensity 1. Use F32 inputs or clip and round to U16, and seeds 138559+11j in the order F32, F16, U8, U16, enlarged F32, two ramps and flat. + +For the input-size and parent-size matrices, use source extents 2², 8×4 and 16². Test grayscale and four-channel inputs in U16 and F32. In channel c use level Q=(7919x+21473y+1103xy+2927c+139m+58997) mod 65536 for m=0 or 2. For m=1 use 59841−223c where (x+y+c) mod 3=0, and 3431+125c elsewhere. Write Q for U16 or Q/19001−.8125 for F32. Use the following cases with seed 134381+19j+i, where i is 1 for U16 and 3 for F32. The parent-size matrix has four additional size discrepancies at a requested 1². The reference returned 8×4. The pixel totals exclude those four outputs. + +| Requested extent relative to source | Strength | Field m | Stored output | +|---|---:|---:|---| +| Same | 1 | 0 | F32 | +| Double both axes | 1, then 0 | 0 | F32 | +| Double both axes | .375 | 1 | F32, U8, U16, F16 | +| Four times width, twice height | 1.25 | 2 | F32 | +| Half both axes | 1 | 2 | F32 | + +For the independent field use Q=(269x+1723y+257xy+9587c+7919((x+3y+5c) mod 13)+7537) mod 65536 at 8×4 or 16². Write Q for U16 or (Q−31007)/15019+.03125(x mod 3) for F32. Use F32 output. At the source extent use strengths 0, 1, .375, .8125, 1.34375 and 2.71875, then double both axes at 0 and .8125, and halve both axes at 0 and 1.34375. Use seed 142867+19j. The 287 differing pixels were in the reduced nonzero-strength cases. At 16² on an independent x/15 F32 ramp, strength one gives bits 3d888887, 3e4ccccf, 3eeeeef1 and 3f5ddddc at columns 1, 3, 7 and 13. Three finite ramp controls match 768/768 pixels. A separate constant 2×10³⁸ input produces positive infinity in all 256 reference pixels. MaterialCraft preserves that finite HDR plateau. + +The two 4×4 reference outputs in the [deep traversal experiment](#bounded-traversal-of-deep-patterns) reproduce exactly when Sharpen alone receives the measured sources. Use U16 levels (30680,17968 / 0,24181) for dirt_4 and U8 levels (89,103 / 90,43) for its second version, in row order. Test 4² at strengths 1 and 0, 2² at 1, and 8×4 at .375. Use seeds 103307+13i at inventory indices i=266 and 267. All 136 F32 pixels match, including both whole-reference 4² outputs. Both 4×4 whole outputs subsequently matched with [bounded pattern traversal](#discarding-pattern-stamps-that-miss-every-output-sample). Dirt 6 improved from 117,826 to 125,252/129,280 exact pixels across 16 whole renders. Its U8 / U16 / F16 / F32 maxima are 0 / 8 / .000244140625 / .0000927746296. + +A MaterialCraft-saved U16 input graph and an independently saved RGBA32F graph reopened in the reference. The first six cases of each reproduced all 1,620 stored pixels byte for byte. + +### Sharpen at reduced output sizes + +When the source is up to twice the output size on either axis and at least as large on both, Sharpen reads the center and four neighbors from the stored source. Neighbor offsets span one source texel. The stencil weights still use the output aspect ratio. A unit-strength white impulse at (8,8) in a black 16² F32 image isolates the spacing. At 8² the center, upper and left values are (.75, −.25, −.25). At 8×16 they are (1.5, −.25, −.5), and at 16×8 they are (1.5, −.5, −.25). The regression failed before the change. The four impulse renders, including 4², match 336/336 F32 pixels. + +| Matrix | Renders | Exact pixels / compared | Maximum error | +|---|---:|---:|---:| +| Parent-size cases from the preceding section | 108 requested | 38,832/38,832 in 104 comparable outputs | 0 | +| Independent signed field from the preceding section | 80 | 16,704/16,704 | 0 | +| Independent 32×16 fields with mixed axis sizes | 180 | 158,688/158,688 | 0 | + +The four requested 1² outputs still differ in extent. For the new fields, use level Q=(131x+6571y+409xy+83(c+3)(x+9y)+9973((x+7y+3c) mod 9)+45821) mod 65536 in channel c. Use gray U16, F16 and F32, and RGBA U8, U16 and F32. Store floor(Q/257) for U8, Q for U16, and (Q−31007)/15019+.03125 for floating point. At strengths 0 and .8125 render F32 at 16×8, 8×4, 4×2, 16², 32×8, 8×16, 16×32, 64×8, 64×4, 4×32, 32×16, 64×32 and 128×64. Seed is 147151+11j+s for zero-based extent j and strength index s. Repeat 16×8 at strength .8125, seed 147269, in U8, U16, F16 and F32. All 108 same-size controls and both independently supplied dirt inputs also remain exact. + +### Discarding pattern stamps that miss every output sample + +The evaluator tests small built-in shapes against the same pixel centers, rotated footprint and edge ownership as the rasterizer. It evaluates the stamp's parameters first so writes and seed changes still reach later visits. It retains the first stamp for raster validation. Each subsequent discarded stamp pays for one additional traversal step, up to 1,048,576 extra steps. The retained-stamp allowance is 1,048,576, with the existing limits of 1,048,576 raster copies and 256,000,000 candidate pixels. The shortcut applies to the full unit render and tiling regions when depth weights are bounded. + +The depth-ten cell-sized quadrant regression originally reached the traversal guard. It now matches 16/16 F32 pixels, each 2⁻²⁰, with a 2.02-second cook. The depth-ten wide-stamp control still reaches the guard. Both depth-nine controls match 16/16 pixels. The 60 repeat-and-assignment controls and 48 additional stage renders reproduce all 47,744 previously stored local pixels. Against the reference, the two groups match 11,904/23,040 and 24,566/24,704 respectively. Formatting, 258 release node tests, strict workspace Clippy, dependency layers and WebAssembly passed in the shared validation run. + +| Root | Whole renders completed | Exact pixels / compared | Maximum U8 / U16 / F16 / F32 | Extra small renders completed | Small F32 exact / compared | Maximum small F32 error | +|---|---:|---:|---|---:|---:|---:| +| noise_directional_noise_3 | 7/19 | 7,168/7,424 | 0 / 2 / 0.00048828125 / 2.85804272e-05 | 2/4 | 73/80 | 2.84314156e-05 | +| noise_directional_noise_3_v2 | 2/19 | 1,280/1,280 | — / — / — / 0 | 2/4 | 80/80 | 0 | +| noise_dirt_4 | 10/19 | 89,052/105,728 | 1 / 12 / 0.00122070312 / 7.62939453e-05 | 2/4 | 49/80 | 7.62939453e-05 | +| noise_dirt_4_v2 | 5/19 | 99,535/99,584 | 5 / — / — / 0 | 2/4 | 80/80 | 0 | +| wood_fibers_2 | 17/18 | 55,649/60,672 | 1 / 4 / 0.0009765625 / 8.55624676e-05 | 4/4 | 123/144 | 2.47359276e-05 | + +The whole renders repeat the recorded [directional](#directional-noise-and-scratch-pattern-sources), [dirt](#dirt-noise-sources-and-downstream-stages) and [wood fiber](#tile-weave-splatter-and-fiber-stage-comparisons) matrices. An em dash denotes a format without a completed output. Omitted renders reached the traversal guard. For each root also request F32 at 4² and 8² with defaults, then 8×4 and 4×8 with settings A from its matrix. At index i use seeds 103307+13i+j for j=0…3. Each directional and dirt root completed both squares. Wood Fibers 2 completed all four small renders. Its 256² default is the only whole render that still reaches the guard. + +Using one worker per fresh process, the 4² defaults for directional 3, its second version, dirt 4 and its second version took 12.64, 39.70, 12.57 and 37.87 cook seconds and peaked at 205.3, 205.2, 205.9 and 205.6 MiB respectively. Whole F32 counts were 13/16, 16/16, 16/16 and 16/16. The three differing directional pixels had maximum error 2.50339508e-05. The earlier [diagnostic run](#bounded-traversal-of-deep-patterns) used 289–292 MiB and took 14–42 seconds across these same inputs. + +The three independent patterns in Wood Fibers 2 already differ before Levels and Blend. Across the ten additional renders, stage 1070386767 matched 4,690/5,248 U16 pixels (maximum three levels), stage 1083954697 matched 40,412/40,960 (one level) and stage 1083954764 matched 162,125/163,840 (one level). The final output matched 9,591/10,496. The 128² default and seed 42 each completed, with 13,485 and 15,779 of 16,384 final U16 pixels exact. + +### Individual Wood Fibers 2 stamps + +Disconnect all inputs to each of the three original Wood Fibers 2 pattern stages. Keep only the indicated quadrant slots from the root to the first stamp and clear its children. Render the original shape, then replace just the shape with a disc and a square. Use the default controls and request 16² F32 at seed 117104, 32² in U8, U16, F16 and F32 at seed 117106, and 16×32 U16 at seed 117111. The stage retains its own output size. Each table cell covers six outputs. + +| Stage | Slots in order | Shape | Authored exact / compared | Maximum U8 / U16 / F16 / F32 | Disc exact / compared | Square exact / compared | +|---|---|---:|---:|---|---:|---:| +| 1070386767 | 0,0,0,3,3,0,0 | 11 | 2,432/2,432 | 0 / 0 / 0 / 0 | 2,432/2,432 | 2,432/2,432 | +| 1083954697 | Root stamp | 6 | 16,469/24,576 | 0 / 1 / .00006103515625 / 2.38418579e-07 | 24,576/24,576 | 24,576/24,576 | +| 1083954764 | 0,0,0,3,3 | 11 | 97,600/98,304 | 0 / 0 / 5.96046448e-08 / 3.35276127e-08 | 98,304/98,304 | 98,304/98,304 | + +All 18 outputs from the first stage were black on this path. To exercise it visibly, take seven successive slots of 0, 1, 2 or 3, then alternate 0,3 starting at 0 and 1,2 starting at 1. Repeat the six cases above and add F32 at 64², 128² and 256² with seeds 160033, 160052 and 160071. The original shape produced visible samples in 30 of its 54 renders and matched 272,289/272,640 pixels. Its 351 differences are all F32, maximum 5.05358912e-07. Discs and squares each matched 272,640/272,640 pixels, maximum zero, with visible samples in 33 and 34 renders respectively. These single-branch comparisons isolate differences in all three sources. The [whole root and its 256² traversal limit](#discarding-pattern-stamps-that-miss-every-output-sample) remain open. + +### Pattern coordinates under a change of render region + +Four original single-stamp probes isolate the remaining Alveolus coordinate differences. The same physical points can be rendered inside the unit square or inside a larger region at twice the width and height. Across 540 renders, MaterialCraft matched 2,237,142/2,654,208 reference pixels. The largest difference was one storage level for U8 and U16, .00048828125 for F16 and 1.13248825e-06 for F32. + +| Shape | All three regions, exact / compared | Maximum U8 / U16 / F16 / F32 | Reference unit vs centered crop | Reference unit vs translated crop | +|---|---:|---|---:|---:| +| 4 | 558,495/663,552 | 1 / 1 / 0.00048828125 / 1.13248825e-06 | 67,812/73,728 | 66,339/73,728 | +| 6 | 537,415/663,552 | 0 / 1 / 3.05175781e-05 / 8.94069672e-07 | 61,230/73,728 | 58,446/73,728 | +| 10 | 570,616/663,552 | 1 / 1 / 0.00048828125 / 2.98023224e-07 | 62,184/73,728 | 58,527/73,728 | +| 17 | 570,616/663,552 | 1 / 1 / 0.00048828125 / 2.98023224e-07 | 62,184/73,728 | 58,527/73,728 | + +Start with a single untextured quadrant, a black background, unit opacity, maximum blending and no tiling. Use shapes 4, 6, 10 and 17. Set both render and tiling regions to [0,1] on both axes, then [−.5,1.5], then [−1,1]. In the latter two cases double the output dimensions and extract the pixels that cover the original region. The first crop starts halfway across the unit image width and height, the second starts one unit width and height into the expanded output. MaterialCraft reproduced every local crop bit across 589,824 such pixel comparisons. + +For the first four geometries center the stamp at (.25,.25), with sizes (3,1.5), (−3,1.5), (3,−1.5) and (−3,−1.5). For the fifth use center (.75,.75) and positive size (3,1.5). Use center (.376953125,.580078125) for the last four geometries. Their (width, height, turns) are (.931640625,.6171875,0), (−.931640625,.6171875,0), (.931640625,.6171875,.25) and (.931640625,.6171875,.21875). The first five use zero turns. Request 32×64 F32, 64×32 F32, 64×32 U16, 32² F16 and 32² U8. Use seed 152591+13g+j for zero-based geometry g and output case j. + +On the 64×32 F32 horizontal gradient at geometry zero, pixel (14,8) has bits 3efbffff in the unit reference and 3efc0000 in both expanded reference crops. MaterialCraft gives 3efc0000 for all three. In the Gaussian F32 cases the centered and translated reference crops respectively reach 1.78813934e-07 and 4.17232513e-07 absolute difference from the unit reference. The linear gradient also changes before any radial falloff is involved. The coordinate rounding rule and both whole Alveolus roots remain open. + +### Wire presence inside a called function + +The normal processor in `shape_splatter_compute_normal` tests whether a ray argument has a wire. MaterialCraft counted an unwired argument's declared default as a connection. A called function now tests its own input wires. A zero-valued wire counts. An identically named wire on an enclosing call does not supply the inner call. An executed Set can define a free variable in the function or a caller. A Set to a formal argument stays inside the call. The nested-call regression failed on the earlier evaluator. Formatting, 259 release node tests, strict workspace Clippy, dependency layers and WebAssembly passed. + +Create a separate package and distinct function identifiers for each control, including each nested function. Return .8125 when Is Defined is true and .3125 when false. Declare the scalar argument with default .1875. At 16² and 32² use seeds 79 and 197 and publish .625 and .3125 respectively. Test a wire, an open port, a same-named outer value, and open ports explicitly marked connectable or non-connectable in a node parameter, Pixel Processor, FX-Map and Value Processor. All 19,200/19,200 F32 pixels and 10/10 typed floats match. Six separate calibration functions returning successive multiples of .046875 matched 3,840/3,840 pixels and 6/6 typed floats. + +In separate pixel and typed graphs, wire zero or .1875, Set .4375 before the call or in its body, forward or omit an inner wire, and read the name after the call. Include a Set in an untaken branch, a free name matching a published input, an unknown name, and the system names for size, position and time. The top-level checks match 10,240/10,240 pixels and 16/16 typed floats. Of the 224 outputs across all six groups, 212 match. Four explicit connectable-wire cases fail to resolve locally. Four plain Get cases return the authored .1875 where the reference returns zero. Four cases reading a formal after assigning .4375 also differ by .4375. The earlier [unconnected argument controls](#unconnected-function-arguments) include separate live-document behavior. + +| Whole root | Cases | Exact pixels / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---| +| shape_splatter_compute_normal, [earlier inputs](#clamped-texture-reads-in-spline-graphs) | 19 | 142,592/142,592, previously 666 | 0 / 0 / 0 / 0 | +| shape_splatter_compute_normal, independent inputs below | 10 | 9,811/11,520 | 0 / 0 / 0 / .593523026 | +| cells_1 in noise_cells_1_v2, [earlier inputs](#tile-random-cell-fields-and-noise-upscaling) | 20 | 158,728/173,312, previously 158,598 | 1 / 0 / 0 / .00000181794167 | +| perlin_noise in noise_perlin_noise_v2, [earlier inputs](#liquid-fiber-and-related-noise-sources) | 19 | 132,970/142,592 | 1 / 39,650 / .00048828125 / .435275048 | + +Counts compare stored bits in every channel. The earlier 32×64 F16 normal render has 26 matching blue NaNs with bits `7fff`. The new 16×32 F32 input set 2 and 64×32 F32 set 4 produce NaNs in all three RGB channels in both applications. All 7,680 payloads and all alpha values in those two outputs match. The table gives the maximum error among finite pairs. + +For independent field set m=0…6 use dimensions 16², 32×16, 16×32, 32², 64×32, 32×64 and 64×32. Supply six RGBA maps and two grayscale maps. At pixel (x,y) in input t, channel c, take q=((71x+157y+33xy+1471t+253c+997m+33(x+11t)(y+7c)) mod 4093)/4092. When m is divisible by three use .8125+.125q if (floor(x/3)+2floor(y/5)+t+c) mod 4 is zero, otherwise .0625+.4375q. In inputs 0 and 4 set alpha to zero where (x+3y+m) mod 7 is zero. Store even sets in U16 rounded to nearest and odd sets in F32. Use seed 157807+29m. Request F32 except set 5 in F16. Repeat set 3 in U8, U16 and F16. + +Set 0 uses defaults. For sets 1…6 choose shape types 11, 1, 4, 7, 11 and 2. Set X and Y counts to 2+(m mod 4) and 4−(m mod 3), amount to 7+m, distribution mode and output normal format to m mod 2, nonsquare expansion to m mod 3 = 1, and extrusion height to .40625+.125m with symmetry on for even sets. Enable displacement when m is divisible by three. Turn around the normal by (m−3)×.109375, set the pivot to (.09375(m−2),−.109375m,.03125), background opacity to .0625m, atlas grid to (2+(m mod 3),2), and pattern input count to 1+(m mod 3). + +The reference reopened a MaterialCraft-saved graph using the same public math calls. Its ten reference outputs reproduce all 11,520 original reference pixels bit for bit. On the seventh field set, changing only the shape type to 2 reproduces the full discrepancy, 339/2,048 F32 pixels exact. In 31 single-setting and shape/displacement controls, 18 shape-2 outputs each match 339/2,048 and the other 13 each match 2,048/2,048. Sampling, the active predicate, ray distance and atlas position each match 6,656/6,656 pixels in four cases that record those intermediate graph outputs. The cube normal and the subsequent stored normal each match 970/6,656. The value before encoding matches 4,947/6,656 and differs only on shape 2. The whole root remains in progress. + +### Connectable numeric arguments in saved function graphs + +An explicitly connectable argument on a standalone function now retains its identifier, numeric type, authored default and connection flag when MaterialCraft reads and saves the package. Its value at a call with the port open is the typed zero. Connecting the port supplies the wire value. The save/reopen regression previously lost the .1875 source default during import. A second regression exercises the open and wired calls through the editing commands. + +Repeat the [wire-presence controls](#wire-presence-inside-a-called-function) with a separate package and function name for each case. Mark an open scalar argument connectable in each of the four calling scopes. In pixel and value processors also wire the scalar on connectable and explicitly non-connectable declarations. At 16²/seed 79 and 32²/seed 197 these eight packages match all 6,400 LUM32F pixels and 6/6 typed values. Maximum error is zero. + +For each of the nine [boolean, signed integer and float argument controls](#unconnected-function-arguments), mark the argument connectable, then wire it or leave it open. Repeat with a second scalar argument wired to .25. The first component of the result matches in all 36/36 typed outputs, maximum error zero. With the connection flag omitted and the second argument wired, 9/18 controls match at this revision, maximum error 9. + +Independently name and save the eight scalar packages and the 18 single-argument typed packages through MaterialCraft. Open each saved file in the reference under its fresh identifiers and repeat the comparisons. All 6,400/6,400 LUM32F pixels and 24/24 typed values across 34 outputs match, maximum error zero. Formatting, the release suites for core, nodes, formats, engine, eval and UI, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Gaussian coverage at the disc boundary + +The Gaussian stamp in both Alveolus roots now writes zero outside its unit disc. In the 54 F32 [render-region pairs](#pattern-coordinates-under-a-change-of-render-region), match the Gaussian to the paraboloid at the same coordinate. For each positive paraboloid sample, find the F32 squared radii that round to its observed value under max(0, 1 − r²). Across 147,664/147,664 samples at least one of those radii reproduces the reference Gaussian exactly. For 67,889 samples the paraboloid identifies a unique radius, maximum Gaussian error zero. At 61 additional pixels MaterialCraft previously produced a positive Gaussian where the paraboloid was zero. The largest such value was 7.75708031e−9. The reference Gaussian was zero at all 61 pixels. + +Draw an unrotated, white, single stamp on black with maximum blending and no tiling. Use the four rows below. For each row move the center so the chosen pixel center samples (x,y) = direction × sqrt(1+d) in signed stamp coordinates. Render the disc, paraboloid and Gaussian separately in F32. Use d = 0 and both signs of .000001, .000005, .00001, .00002, .00005, .0001 and .0003. The seed is 164117 + 43 times the zero-based row + the position in ascending d. In a second sweep use d = k × 2⁻²⁶ for k from −32 through 32 and base seed 165311. + +| Output size | Sample pixel | Signed stamp size | Direction | +|---|---|---|---| +| 16×16 | (8,8) | (.5,.5) | (.6,.8) | +| 32×16 | (17,6) | (.75,.3125) | (−.8,.6) | +| 16×32 | (5,19) | (−.375,.625) | (.6,−.8) | +| 32×32 | (22,17) | (.625,−.4375) | (−.6,−.8) | + +| Gaussian outputs | Renders | Exact pixels before | Exact pixels after | Maximum error after | +|---|---:|---:|---:|---:| +| Three render regions, four formats | 135 | 537,415/663,552 | 537,476/663,552 | U8 0, U16 1, F16 3.05175781e−5, F32 8.94069672e−7 | +| First F32 sweep | 60 | 30,046/34,560 | 30,073/34,560 | 1.25169754e−6 | +| Second F32 sweep | 260 | 130,128/149,760 | 130,223/149,760 | 5.66244125e−7 | + +Every reference Gaussian pixel outside its paired disc was zero in both sweeps, 29,406/29,406 and 127,365/127,365. The probes leave equality at exactly r² = 1 unresolved. The implementation applies the cutoff only above one. Differences in the interior remain. On the earlier whole-root matrices, Alveolus still matches 332,280/334,336 pixels and the pattern variant 201,876/203,264. Their maximum U8/U16/F16/F32 errors are 0/1,000/0/3.05175781e−5 and 0/2/0/1.52587891e−5 respectively. The two brick-generator Tile helpers each retain 114,688/114,688 LUM16 pixels across four renders. The boundary regression failed before the fix. All 262 release node tests, formatting, strict workspace Clippy, layers and WebAssembly passed. + +### Pixel coordinates for whole-pixel pattern stamps + +The two Alveolus roots use the same Gaussian stamp at different resolutions. In the 32×16 unfilled Alveolus case, the 16² generator pixel at (15,9) previously stored 31,807 in U16. The reference stores 31,808. It moves two output pixels, at (7,9) and (23,9). An original 16² Gaussian at center (.25,.25), size (3,1.5), maximum blend, opacity .995 and zero rotation distinguishes the coordinate step before storage. At (7,1) its F32 bits are `3ef88006`. The earlier three-guard-bit product gives `3ef88001`. At physical stamp size 48×24 the measured steps are `3d2aaaa9` horizontally and `3daaaaab` vertically. + +For an axis-aligned analytic stamp whose edges land on whole pixels, form its two pixel extents plus .5. Truncate their product to F32 before taking its reciprocal. The interpolation basis on each axis is the opposite padded extent times that reciprocal, truncated to F32. The coordinate step multiplies this basis by F32(2 + 1/extent). Treat the span’s lowest significand bit as a separate partial product. Recode the remaining bits in signed radix four, round each partial product’s magnitude to a multiple of 2¹⁷, and add 2²⁰ before storing the normalized product. Use the left edge and the preceding four-pixel boundary to set up the affine coordinate. The saved regression exercises six rectangular and square Gaussian samples. Fractional edges and oblique angles still have separate unverified cases. Sampled images retain their point and mip filtering coordinates. + +**Independent interpolation check.** Render a four-vertex triangle strip with a 4×4 viewport and pixel-space corners (0,0), (X,0), (0,Y), (X,Y). Give the corners the respective attributes (0,0), (A,0), (0,A), (A,A), with clip W equal to one. Read the raw F32 pair at pixel (0,0) and double it to obtain the two gradients. The two directions matched at 78,000/78,000 calibration values and 40,000/40,000 held-out values, maximum error zero. The held-out set included quarter-pixel extents up to 1,600 and amplitudes with eleven exponent values. Truncating the area corrected the 1,000 held-out products that differed with a nearest-rounded area. + +For a shorter reproducible sweep, start a 32-bit unsigned state at `0x51c37e29`. Advance by `state = 1664525 × state + 1013904223` modulo 2³². For each of 8,192 rectangles take three successive states a, b and c. Obtain X and Y from a and b with `1 + (s mod 1599) + ((s >> 20) & 3)/4`. Use the F32 amplitude with bits `((121 + c mod 11) << 23) | (c >> 9)`. The unit-amplitude check matches 16,384/16,384 gradients and the variable-amplitude check matches 16,384/16,384, maximum error zero, on the same Direct3D 11 device as the reference. + +| Complete output or independent control | Renders | Exact pixels | Maximum error | +|---|---:|---:|---:| +| Alveolus, earlier root matrices | 41 | 334,336/334,336 | 0 | +| Pattern Alveolus, earlier root matrices | 33 | 203,264/203,264 | 0 | +| Alveolus, follow-up matrix | 25 | 681,728/681,728 | 0 | +| Pattern Alveolus, follow-up matrix | 25 | 681,728/681,728 | 0 | +| Unit horizontal ramp at zero and half turns, F32 | 72 | 2,032,128/2,032,128 | 0 | +| Paraboloid, Gaussian and horizontal ramp in three render regions, F32 | 90 | 552,960/552,960 | 0 | +| Previously verified roots using the pattern primitive | 167 | 3,139,328/3,139,328 | 0 | + +For each root’s 25 follow-up renders, the 5,120 U8, 553,728 U16, 78,336 F16 and 44,544 F32 output pixels also match after reopening its MaterialCraft save in both apps. The 17 previously verified roots were rechecked with their recorded settings, including the matching preview size for Position Debug. Gradient Linear 1 still differs at 224/435,968 pixels across 47 renders. The extended 1.5-turn case remains open. Gradient Linear 3 now matches 277,760/277,760 pixels across its earlier 23 renders. [Root settings and saved-file checks](#reopening-sbs-files-with-release-number-headers) · [Ramp dimensions, seeds and extended turns](#linear-gradient-sampling-on-rectangular-targets) · [Render-region controls](#pattern-coordinates-under-a-change-of-render-region) + +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). + +### Fur across two rectangular render series + +The totals below count distinct combinations of dimensions, seed, public parameter values and final storage. They include the earlier default, changed, precision and independent captures and the new 28 and 38 settings. For settings observed twice, the table retains the first capture in the precision, independent, targeted and archived comparison order. MaterialCraft reproduced every original pixel after saving and reopening each package in both new series (498,688 and 8,654,848 pixels per root). The final column gives the reference’s original-versus-reopened counts for those same series. + +| Root (inventory index) | Distinct settings | U8 exact/total · max | U16 exact/total · max | F16 exact/total · max | F32 exact/total · max | Reference reopen, 28 and 38 settings | +|---|---:|---:|---:|---:|---:|---:| +| Fur 1 (155) | 85 | 1,568,000/1,568,000 · 0 | 3,062,016/3,062,016 · 0 | 1,568,000/1,568,000 · 0 | 3,052,032/3,052,032 · 0 | 498,688 and 8,654,848 | +| Fur 2 (156) | 85 | 1,567,999/1,568,000 · 1 | 3,061,572/3,062,016 · 1 | 1,567,975/1,568,000 · 0.000244140625 | 2,570,924/3,052,032 · 2.38418579e-07 | 485,168 and 8,344,661 | +| Fur 3 (157) | 85 | 1,568,000/1,568,000 · 0 | 3,062,016/3,062,016 · 0 | 1,568,000/1,568,000 · 0 | 3,052,032/3,052,032 · 0 | 498,688 and 8,654,848 | +| Fur 4 (158) | 85 | 1,568,000/1,568,000 · 0 | 3,062,016/3,062,016 · 0 | 1,568,000/1,568,000 · 0 | 3,052,032/3,052,032 · 0 | 498,688 and 8,654,848 | + +Use the dimensions, storage selections, seeds, d values and defaults in the two Fibers 1 matrices. [Full render settings](#fibers-1-and-fluid-through-1024-pixels-per-side) + +Set disorder to d throughout the changed cases. Fur 3 also uses density d. In the smaller series Fur 2 uses wave scale .125+.625d and wave rotation d. In the larger series its wave scale is 1−.75d and rotation d−.5. + +Fur 2 had differing exact counts on 2 duplicate settings. At 256² with defaults and seed 0 the two U16 captures gave 65,528 and 65,526 of 65,536. At 128² with seed 42 they gave 16,379 and 16,383 of 16,384. + +At 256² with defaults and seed 0, repeat the original Fur 2 six times at each of U16 and F32. Each image contains 65,536 pixels. + +| Storage | Distinct reference images | Exact against first · maximum error | Exact against any at that pixel | Outside reference range | Maximum distance outside range | +|---|---:|---:|---:|---:|---:| +| U16 | 5 | 65,523 · 1 | 65,532 | 4 | 1 | +| F32 | 6 | 58,730 · 1.1920929e-07 | 61,980 | 3,494 | 1.1920929e-07 | + +### Gaussian generators and spots through 1024 pixels per side + +The totals below count distinct combinations of dimensions, seed, public parameter values and final storage. They include the earlier default, changed, precision and independent captures and the new 28 and 38 settings. For settings observed twice, the table retains the first capture in the precision, independent, targeted and archived comparison order. MaterialCraft reproduced every original pixel after saving and reopening each package in both new series (498,688 and 8,654,848 pixels per root). The final column gives the reference’s original-versus-reopened counts for those same series. + +| Root (inventory index) | Distinct settings | U8 exact/total · max | U16 exact/total · max | F16 exact/total · max | F32 exact/total · max | Reference reopen, 28 and 38 settings | +|---|---:|---:|---:|---:|---:|---:| +| Gaussian 1 (160) | 82 | 1,571,072/1,571,072 · 0 | 3,054,848/3,054,848 · 0 | 1,571,072/1,571,072 · 0 | 3,045,888/3,045,888 · 0 | 498,688 and 8,654,848 | +| Gaussian 2 (161) | 82 | 1,571,072/1,571,072 · 0 | 3,054,848/3,054,848 · 0 | 1,571,072/1,571,072 · 0 | 3,045,888/3,045,888 · 0 | 498,688 and 8,654,848 | +| Gaussian Spots 1 (162) | 73 | 1,566,976/1,566,976 · 0 | 3,050,752/3,050,752 · 0 | 1,566,976/1,566,976 · 0 | 3,019,008/3,019,008 · 0 | 498,688 and 8,654,848 | +| Gaussian Spots 2 (163) | 85 | 1,568,000/1,568,000 · 0 | 3,061,612/3,062,016 · 1 | 1,567,963/1,568,000 · 0.00048828125 | 2,488,240/3,052,032 · 1.78813934e-07 | 483,541 and 8,258,387 | + +Use the dimensions, storage selections, seeds, d values and defaults in the two Fibers 1 matrices. [Full render settings](#fibers-1-and-fluid-through-1024-pixels-per-side) + +Gaussian 1 and 2 use the listed tiling values. Both spots roots use disorder d for the changed cases. + +Gaussian Spots 2 had differing exact counts on 2 duplicate settings. At 256² with defaults and seed 0 the two U16 captures gave 65,528 and 65,533 of 65,536. At 128² with seed 42 they gave 16,379 and 16,381 of 16,384. + +At 256² with defaults and seed 0, repeat the original Gaussian Spots 2 six times at each of U16 and F32. Each image contains 65,536 pixels. + +| Storage | Distinct reference images | Exact against first · maximum error | Exact against any at that pixel | Outside reference range | Maximum distance outside range | +|---|---:|---:|---:|---:|---:| +| U16 | 6 | 65,532 · 1 | 65,535 | 1 | 1 | +| F32 | 5 | 53,871 · 1.1920929e-07 | 61,912 | 3,565 | 1.1920929e-07 | + +### Tile patch inputs and scratch color precision + +The grayscale tile patch matches all 3,966,976 primary pixels. Its color counterpart differs at 326 pixels in each of two storage formats. Scratches 2 differs at eight F32 pixels. Each pixel counts once and requires every channel to match. Integer errors are in stored levels. Both applications reopened the saved files and reproduced their own originals exactly on 521,216 pixels across the 30 smaller settings and 3,313,664 across the 32 larger settings for each root. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Tile patch, color (202) | 71 | 830,720/830,720 · 0 | 1,209,274/1,209,600 · 13832 | 716,032/716,032 · 0 | 1,210,298/1,210,624 · 0.211062819 | +| Tile patch, grayscale (203) | 71 | 830,720/830,720 · 0 | 1,209,600/1,209,600 · 0 | 716,032/716,032 · 0 | 1,210,624/1,210,624 · 0 | +| Scratches 2 (206) | 82 | 815,360/815,360 · 0 | 1,220,864/1,220,864 · 0 | 717,056/717,056 · 0 | 1,243,640/1,243,648 · 5.96046448e-08 | + +The primary totals include the earlier default, seed, precision and targeted measurements, with duplicate settings counted once. A separate eight-setting series using an original procedural image at the two patch inputs matched 131,072/131,072 pixels for each root, maximum zero. It includes 128² and 256² defaults, seed 42 and changed settings at 64² in all four formats. + +For the two new series, use the root's zero-based inventory index i and the row index j. In the table x means keep the public defaults. Use U16 and F32 for every row. Also render U8 and F16 at smaller indices 0,2,3,6,9 and larger indices 0,2,3,4,7,8. + +| j | Smaller dimensions | Smaller d | Smaller seed | Larger dimensions | Larger d | Larger seed | +|---:|---|---:|---|---|---:|---| +| 0 | 16×16 | x | 0 | 32² | x | 42 | +| 1 | 32×64 | .21875 | 42 | 64×256 | .34375 | 31877+43i | +| 2 | 64×32 | .8125 | 401477+19i+31j | 256×64 | .90625 | 69491+43i | +| 3 | 64² | .375 | 401477+19i+31j | 128² | .09375 | 0 | +| 4 | 128×64 | .03125 | 401477+19i+31j | 256² | x | 42 | +| 5 | 64×128 | .96875 | 401477+19i+31j | 128×512 | .6875 | 13681+43i | +| 6 | 128² | x | 0 | 512×128 | .28125 | 9199+43i | +| 7 | 128×256 | .5625 | 401477+19i+31j | 512² | x | 0 | +| 8 | 256×128 | .15625 | 401477+19i+31j | 256×1024 | .53125 | 47951+43i | +| 9 | 256² | x | 401477+19i+31j | 1024×256 | .796875 | 31607+43i | + +For changed settings use pattern width 31+141d, height 61+129(1−d) and disorder d on all three roots. In the patches, use d for mask size, mask precision, mask warping, size variation, rotation variation and color or luminosity variation. Set rotation to d−.25 and select octave from (1,3,2,1,2,3,2,3,1,2) by j. Use (d/2,1−d,d,.375+.5d) for the color background and .83d for grayscale. + +Leave Source disconnected at j=0. For other smaller rows take h=(j−1) mod 6. For larger rows take h=(j+2) mod 6. Generate a U8 field at the h-th size from (64²,64×32,32×64,128²,128×64,64×128) with integer coordinates starting at zero. The grayscale level is 127((⌊x/3⌋+⌊y/7⌋) mod 2)+(5x+9y+xy) mod 129. For color use R=(13x+17y+31h) mod 256, G=211((⌊x/4⌋ XOR ⌊y/8⌋) mod 2)+(x+y) mod 43, B=(7xy+19x+53h) mod 256 and A=(23x+11y+97h) mod 256. + +At larger j=6 the color patch first differs in the bitmap pattern map. Its input, background and all upstream filters match. The map gives 65,210/65,536 U16 pixels with maximum error 13,832. The downstream transform preserves that count. The final F32 maximum is .211062819 at (157,113), and all 326 unequal pixels lie between x=144–167 and y=109–123. At larger j=5 every observed stage matches. At j=7 the last mask blur differs at 35/262,144 U16 pixels by one level and its downstream warp and final image match. + +Repeated original-only Scratches 2 renders at smaller j=1,3,4,6 were bit-identical in six runs of each setting. MaterialCraft matched 2,047/2,048, 4,095/4,096, 8,190/8,192 and 16,383/16,384 RGBA32F pixels respectively. The respective maximum errors were 5.96046448e−8, 2.98023224e−8, 5.96046448e−8 and 2.98023224e−8. The first setting differs only in green at (18,52). [Earlier stage and parameter controls](#scratches-messy-fibers-microscope-and-moisture) + +### Messy Fibers and Microscope View through 1024 pixels per side + +All five generator outputs match in the primary series, including every stored gray level and floating-point bit through 1024 pixels per side. Both applications reopened the MaterialCraft package and reproduced each original exactly on the 521,216 pixels in the 30 smaller settings and the 3,313,664 pixels in the 32 larger settings per root. The table counts distinct original settings once. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Messy Fibers 1 (220) | 82 | 717,056/717,056 · 0 | 1,319,168/1,319,168 · 0 | 717,056/717,056 · 0 | 1,243,648/1,243,648 · 0 | +| Messy Fibers 2 (221) | 82 | 717,056/717,056 · 0 | 1,319,168/1,319,168 · 0 | 717,056/717,056 · 0 | 1,243,648/1,243,648 · 0 | +| Messy Fibers 3 (222) | 70 | 814,336/814,336 · 0 | 1,209,600/1,209,600 · 0 | 716,032/716,032 · 0 | 1,210,624/1,210,624 · 0 | +| Messy Fibers 4 (223) | 77 | 700,672/700,672 · 0 | 1,286,400/1,286,400 · 0 | 700,672/700,672 · 0 | 1,227,264/1,227,264 · 0 | +| Microscope View (224) | 82 | 717,056/717,056 · 0 | 1,319,168/1,319,168 · 0 | 717,056/717,056 · 0 | 1,243,648/1,243,648 · 0 | + +Use the dimensions, formats, seeds and d for index i in the two tile-patch series. Leave defaults in rows marked x. These five roots generate their own input. [Render matrices](#tile-patch-inputs-and-scratch-color-precision) + +| Root | Changed public controls | +|---|---| +| Messy Fibers 1 | Disorder d, rotation variation 57+237d, links 7+19d, emboss intensity 1.6d and emboss angle −50+218d | +| Messy Fibers 2 | Disorder d and lines 12+37d | +| Messy Fibers 3 | Disorder d, rotation variation 57+237d and rotation d−.25 | +| Messy Fibers 4 | No public parameters | +| Microscope View | Disorder d and warp intensity 4+11d | + +Separate downstream checks replaced each live generator with a different original U16 field in Messy Fibers 1, Messy Fibers 4 and Microscope View. All 46,336/46,336 output pixels per graph matched across the twelve settings, maximum zero. [Field formulas and stage measurements](#scratches-messy-fibers-microscope-and-moisture) + +### Affine mip selection on rectangular and skewed footprints + +Mesh 2 matches **8,912,896/8,912,896 final pixels across 73 distinct settings**. Mesh 1 has 454 unequal pixels. Both applications reopened the saved packages and reproduced their own original results on every pixel of the smaller 36 renders (588,800 pixels) and the larger 34 renders (8,536,064 pixels) for each root. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Mesh 1 (211) | 73 | 1,568,000/1,568,000 · 0 | 2,904,143/2,904,320 · 1 | 1,567,998/1,568,000 · 0.000244140625 | 2,872,301/2,872,576 · 1.52587891e-05 | +| Mesh 2 (212) | 73 | 1,568,000/1,568,000 · 0 | 2,904,320/2,904,320 · 0 | 1,568,000/1,568,000 · 0 | 2,872,576/2,872,576 · 0 | + +The two generators take no image inputs. The table lists (width×height, tiling, rotation switch) for each row. A dash selects all defaults. For the smaller series use seed zero at j=0,6,11 and 401129+13i+31j elsewhere, where i is the root index. Use U16 and F32 on all rows and also U8 and F16 at j=0,2,5,6,8,11. The larger series uses the listed seed and adds U8 and F16 at j=0,2,4,6,7,10. + +| j | Smaller dimensions | Tiling, rotation | Larger dimensions | Tiling, rotation | Larger seed | +|---:|---|---|---|---|---:| +| 0 | 16×16 | — | 32×64 | — | 0 | +| 1 | 32×32 | 1, off | 128×32 | 1, off | 42 | +| 2 | 32×32 | 1, on | 64×256 | 3, on | 7823 | +| 3 | 32×64 | 2, off | 256×128 | 2, off | 55337 | +| 4 | 64×32 | 3, on | 256×256 | — | 0 | +| 5 | 64×64 | 3, off | 512×256 | 1, on | 42 | +| 6 | 128×128 | — | 256×512 | 3, off | 7789 | +| 7 | 128×128 | 1, off | 512×512 | — | 0 | +| 8 | 128×128 | 1, on | 512×1024 | 2, on | 70717 | +| 9 | 128×256 | 2, on | 1024×512 | 1, off | 58073 | +| 10 | 256×128 | 3, off | 1024×1024 | — | 39133 | +| 11 | 256×256 | — | — | — | — | + +The affine transform now measures the source U and V gradients in texels across both output axes. Each squared gradient rounds its two products and their sum to F32. The natural log of the larger squared gradient rounds to F32 before conversion to a mip level. Rounding the fractional level to ten bits selects the nearest stored image. At 64² the matrix (1,−1,1,1) now samples level 1. A diagonal matrix (s,−s,s,s) with s=1.9993231296539307 samples level 2. The former implementation sampled a finer image at both settings. + +Generate a U8 RGBA field with R=(13x+19y+7xy) mod 256, G=255((x XOR y) mod 2), B=255((⌊x/2⌋+⌊y/4⌋) mod 2), A=4+((5x+19y+33) mod 251). Use both tiling axes, zero offset and F32 output. At the second matrix, pixel (0,0) has red bits 0x3f351f60 and (19,43) has 0x3eee62e2. For the skew matrix (.625,2.7598505,−.34375,.61466354), the corresponding values are 0x3f033f7f and 0x3f0292d2. The regression also exercises non-square sources and outputs. + +| Original transform series | Renders | Exact before | Exact after / total | Maximum error before | Maximum error after | +|---|---:|---:|---:|---:|---:| +| Initial auto levels | 84 | 235,810 | 344,064/344,064 | 0.49609375 | 0 | +| Manual levels 0–3 | 336 | 1,376,256 | 1,376,256/1,376,256 | 0 | 0 | +| Coarse thresholds | 78 | 286,849 | 319,488/319,488 | 0.49609375 | 0 | +| Fine thresholds | 66 | 180,224 | 270,336/270,336 | 0.48343116 | 0 | +| Square and rectangular footprints | 138 | 313,345 | 409,600/409,600 | 0.549227991 | 0 | +| Adjacent F32 coefficients | 66 | 118,899 | 270,336/270,336 | 0.5 | 0 | +| Rectangular source, nearest and bilinear | 96 | 357,578 | 393,216/393,216 | 0.541451991 | 0 | +| Repeat, sign and dimension controls | 51 | 114,002 | 365,568/365,568 | 0.5 | 0 | +| Independent near-threshold skew matrices | 155 | 352,259 | 634,880/634,880 | 0.547572951 | 0 | +| High levels on a 2048×32 source | 90 | 6,736 | 92,160/92,160 | 0.423014522 | 0 | + +For the fine sweep use 33 equally spaced values between 1.4130859375 and 1.4140625 on one axis and on the 45-degree diagonal. For the adjacent-coefficient sweep start at F32(2^(.5−.5/1024)), offset its bit pattern by −96,−32,−12,−4,−1,0,1,4,12,32,96 and scale by 1,2 or 4. Compare the axis-aligned matrix (s,0,0,.875) and the diagonal with coefficients ±s/√2. The 155 skew probes distinguish separate squared products from a fused product and from a double-precision norm. In the high-level series render 32² with a 2048×32 source. For levels l=4…9, resolve radii 2^(l+.5−.5/1024) at angles 0,.231,.613,π/4,1.117 radians and the preceding, nearest and following F32 horizontal coefficient. The 90 auto images match the selected manual levels. + +Mesh 1 first differs in its two-stamp pattern source. Six original-only F32 captures agree across every pixel at 128×64 and 256². Against MaterialCraft the source matches 7,994/8,192 (maximum 2.38418579e−7) and 62,825/65,536 (4.17232513e−7). An original two-leaf graph reproduces those counts. With only the positive eighth-turn stamp, all 74,752 F32 pixels match across three sizes when both tiling axes are disabled. Wrapping both axes gives 70,822/74,752 with maximum 3.75672244e−7. Its rectangle is (.75,1.5) centered at (.5,.5). Changing either size or rotation to a graph input makes a separate four-size probe exact. Fixed size and rotation together give 86,299/91,136 at the same values. [Earlier per-stamp measurements](#directional-and-additive-stamp-profiles) + +### Moisture noise across repeated original renders + +Moisture Noise (226) matched **3,996,504/3,996,928 pixels across 82 distinct settings**. The primary table uses the first observation where a setting repeats. At 128², seed zero and default U16, earlier original renders matched either 16,382 or 16,384 of the 16,384 output pixels. Six fresh reads of that setting were identical to each other and matched 16,383 pixels, maximum difference five levels. + +| Stored output | Primary exact / total | Maximum error | +|---|---:|---:| +| U8 | 717,053/717,056 | 1 | +| U16 | 1,318,957/1,319,168 | 6 | +| F16 | 717,032/717,056 | 0.00048828125 | +| F32 | 1,243,462/1,243,648 | 0.0000783205032 | + +Use the two tile-patch render series with i=226. Leave the controls at defaults in the indicated rows. For a changed row set disorder to d, pattern width to 31+141d and height to 61+129(1−d). The graph generates its own inputs. After saving and reopening the package, MaterialCraft reproduced every original pixel on the 521,216 smaller-series pixels and 3,313,664 larger-series pixels. The reference original/reopened comparisons matched 521,140 and 3,313,311 respectively, with maximum error six U16 levels. [Dimensions, seeds, formats and d values](#tile-patch-inputs-and-scratch-color-precision) + +Each series requests six frames from the original graph with identical settings. The varying-pixel count is the union of positions that changed across those frames. The last column counts MaterialCraft pixels outside the minimum and maximum values observed at the corresponding positions. + +| Setting | Format | Exact against first / total · max | Distinct frames | Varying pixels · largest span | Outside the six-frame range · max distance | +|---|---|---:|---:|---:|---:| +| 128², defaults, seed 0 | U16 | 16,383/16,384 · 5 | 1 | 0 · 0 | 1 · 5 | +| 128², defaults, seed 0 | F32 | 16,384/16,384 · 0 | 1 | 0 · 0 | 0 · 0 | +| 512×128, seed 18917, width 70.65625, height 153.71875, disorder .28125 | U16 | 65,524/65,536 · 5 | 6 | 24 · 6 | 2 · 5 | +| Same rectangular setting | F32 | 65,522/65,536 · .0000780820847 | 6 | 22 · .0000780820847 | 0 · 0 | + +In the twelve earlier cases with intermediate graph outputs recorded, the generator feeding the blend source matched 46,336/46,336 pixels. The generator feeding the destination and the blend each matched 46,334/46,336, maximum one U16 level. The independently requested final images matched 46,335/46,336, maximum .0000780224800 F32. The differing positions can change between requests for intermediate and final images. The stable 128² U16 discrepancy remains open. [Twelve stage settings](#scratches-messy-fibers-microscope-and-moisture) + +### Precision of two dense noise generators in custom regions + +At 64² with seed 42, scale 2 and disorder .37, the following roots now complete in all four storage formats. Both take procedural inputs only. + +| Root | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| BnW Spots 3 (238) | 4,096/4,096 · 0 | 4,094/4,096 · 1 | 4,096/4,096 · 0 | 4,093/4,096 · .0000106692314 | +| Dirt 5 (268) | 4,096/4,096 · 0 | 4,095/4,096 · 3 | 4,096/4,096 · 0 | 4,094/4,096 · .0000508129597 | + +For Spots 3, the 16² F32 default at seed 102951 matched 254/256 with maximum .0000106990337. Scale 1, zero disorder and expansion enabled matched all 1,024 F32 pixels at seed 102952 and all 8,192 F16 pixels at 128×64, seed 102960. Seven scale-3 and scale-5 cases still reached the traversal limit. [Original series](#cloud-and-crystal-pattern-sources-across-scales) + +For Dirt 5, the 16² F32 default at seed 105543 matched 256/256. At 32², scale 1, zero disorder and expansion enabled, seed 105544 matched 1,022/1,024 F32 pixels with maximum .0000508204103. Changing disorder to .3125 and disabling expansion matched all 4,096 pixels over the four formats at seed 105545. At 64×32 the same controls matched 2,047/2,048 F32 pixels at seed 105551, maximum .0000508278608. The 32×64 zero-disorder F16 case matched 2,048/2,048 at seed 105552. The 32×16 F32 and 16×32 U16 cases at scale 2 and disorder .8125 still reached the traversal limit. [Original series](#dirt-noise-sources-and-downstream-stages) + +### Fixed and input-driven rotation bounds for oblique stamps + +Mesh 1 (211) now matches all **8,912,896 pixels over 73 distinct settings**, including the 454 pixels that differed after the affine transform correction. The separately packaged Mesh 1 (365), Mesh 2 (366) and Pavement 1 (383) each matched **2,927,872/2,927,872** across 59 settings. All comparisons use the named package's own procedural graph. The two Weave 2 roots still differ. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Mesh 1 (211) | 73 | 1,568,000/1,568,000 · 0 | 2,904,320/2,904,320 · 0 | 1,568,000/1,568,000 · 0 | 2,872,576/2,872,576 · 0 | +| Pattern Mesh 1 (365) | 59 | 358,912/358,912 · 0 | 1,118,208/1,118,208 · 0 | 360,960/360,960 · 0 | 1,089,792/1,089,792 · 0 | +| Pattern Mesh 2 (366) | 59 | 358,912/358,912 · 0 | 1,118,208/1,118,208 · 0 | 360,960/360,960 · 0 | 1,089,792/1,089,792 · 0 | +| Pattern Weave 2 (382) | 59 | 358,912/358,912 · 0 | 1,087,649/1,118,208 · 63506 | 360,960/360,960 · 0 | 1,059,232/1,089,792 · 0.96903944 | +| Pavement 1 (383) | 59 | 358,912/358,912 · 0 | 1,118,208/1,118,208 · 0 | 360,960/360,960 · 0 | 1,089,792/1,089,792 · 0 | +| Weave 2 (538) | 59 | 358,908/358,912 · 1 | 1,115,751/1,118,208 · 3 | 360,898/360,960 · 0.00048828125 | 1,087,631/1,089,792 · 4.58359718e-05 | + +Both applications reopened each MaterialCraft package. For Mesh 1 and Mesh 2 (211 and 212), every pixel of the 588,800 smaller-series and 8,536,064 larger-series pixels reproduced the original within each application. The 42 new settings for each of roots 365, 366, 382, 383 and 538 likewise reproduced all 2,867,200 pixels on reopening within each application. Mesh 2 (212) retained all 8,912,896 cross-application matches. The two image-input roots with the same kind of oblique stamp, Noise Upscale 1 and 2 (301 and 302), retained 697,344/697,344 pixels apiece across their 21 original-input settings. [Mesh series](#affine-mip-selection-on-rectangular-and-skewed-footprints) · [Upscaler input fields](#sampling-integer-bitmap-inputs-through-wider-bridges) + +An oblique pattern stamp with fixed size and rotation computes its bounds from the sine and cosine of its F32 angle in radians. Reading either size or rotation from a graph input uses the uniform rotation in turns for bounds. The profile inside the rectangle uses the pixel rotation in both cases. Literal arithmetic expressions follow the fixed case. Adding zero to an input read preserves the input-driven result. Exact quarter turns retain their measured bounds, including −.5 and 2 turns. + +To reproduce the regression, draw a single grayscale stamp of type 17 at center (.5,−.5), size (.75,1.5), rotation .125 turns. Disable tiling and read 128×64 F32. At (46,0) the fixed stamp gives 0x3f59911e. Expose either size or rotation with the same value and the result is 0x3f599122. Six repeated original frames of the two-stamp source were identical in the earlier investigation. [Source isolation](#affine-mip-selection-on-rectangular-and-skewed-footprints) + +| Original stamp controls | Renders | Exact before | Exact after / total | Maximum after | +|---|---:|---:|---:|---:| +| Initial fixed and input-driven geometry | 144 | 2,518,248 | 2,555,904/2,555,904 | 0 | +| Independent angles, sizes and quarter turns | 264 | 4,670,082 | 4,685,824/4,685,824 | 0 | +| Literal and input-driven expressions | 40 | 847,312 | 901,120/901,120 | 0 | +| Single-stamp wrap, frame and region controls | 39 | 929,017 | 971,776/971,776 | 0 | +| Individual size, rotation, center, gain and tint settings | 44 | 987,985 | 1,002,496/1,002,496 | 0 | +| Two stamps together and each alone | 54 | 2,548,342 | 2,568,192/2,568,192 | 0 | + +The twelve placements use 128×64 at centers (.5,.5), (−.5,.5), (.5,−.5), (1.5,.5) and (.5,1.5), then 256² at (−.5,.5) and (.5,−.5), 64×128 at (.3125,.625) and (−.21875,.78125), 32×128 at (.53125,1.25), 128×32 at (1.25,.34375) and 128² at (0,0). For geometry j and placement k use seed 422231+31j+k. The initial shapes include ±.125, .09375, .3125, −.21875, .373046875, .25 and .5126953125 turns. The independent series includes exact quarter turns, the F32 neighbors of .25, the predecessor of .5, extended turns and narrow rectangular footprints. All 33 additional graphs reproducing the five earlier test fixtures also matched **574,464/574,464 pixels**. Those fixtures' recorded bit patterns came from input-driven rotation. Their fixed-rotation counterparts have independently measured values. + +For roots 365, 366, 382, 383 and 538, the new series uses the following dimensions and controls. A dash leaves all controls at defaults. For each changed row j, roots 365 and 366 use the listed tiling, rotation switch and non-square expansion. Root 382 uses the listed scale with disorder d, rotation and expansion. Root 383 uses d as roundness. Root 538 uses the listed tiling, d and rotation. Use U16 and F32 on every row and add U8 and F16 at j=0,1,3,5,6,9,12. Seeds are zero at j=0,6,9, 42 at j=1,12 and 435337+13i+71j elsewhere for inventory index i. + +| j | Dimensions | Tiling | Scale | d | Rotation | Expansion | +|---:|---|---:|---:|---:|---|---| +| 0 | 16×32 | — | — | — | — | — | +| 1 | 64×16 | 1 | 5 | 0.125 | off | off | +| 2 | 16×64 | 3 | 9 | 0.8125 | on | on | +| 3 | 64×64 | 2 | 3 | 0.46875 | on | on | +| 4 | 128×32 | 3 | 12 | 0.0625 | off | off | +| 5 | 32×128 | 1 | 4 | 0.6875 | on | off | +| 6 | 128×128 | — | — | — | — | — | +| 7 | 256×128 | 2 | 11 | 0.96875 | off | on | +| 8 | 128×256 | 1 | 7 | 0.21875 | on | off | +| 9 | 256×256 | — | — | — | — | — | +| 10 | 512×128 | 3 | 13 | 0.5625 | off | on | +| 11 | 128×512 | 1 | 2 | 0.34375 | on | on | +| 12 | 512×512 | 2 | 6 | 0.90625 | on | off | +| 13 | 1024×512 | 3 | 19 | 0.15625 | off | off | + +In Pattern Weave 2, the largest difference occurs at 512×128, scale 13, disorder .5625, rotation off and expansion on. F32 matched 35,158/65,536 pixels there with maximum .96903944. In Weave 2 the 128² default F32 render matched 16,128/16,384 with maximum .0000152587891. Both original/reopened pairs reproduced their own outputs at these settings. [Earlier stage measurements](#tile-weave-splatter-and-fiber-stage-comparisons) + +### Automatic bitmap stamp levels at neighboring pixels + +The color tile patch now matches all 3,966,976 pixels in its previous 71 settings. That includes the 326 differing U16 pixels and 326 differing F32 pixels at 512×128. Both patch roots match on 99 of 103 distinct settings. Each differs in the four storage formats at a new 1024×512 setting. Count one pixel when all channels match, including F32 bits. Integer maxima are in stored levels. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Tile patch, color (202) | 103 | 1,492,629/1,494,272 · 1 | 2,685,435/2,692,352 · 211 | 1,373,690/1,379,584 · 0.00341796875 | 2,686,459/2,693,376 · 0.0032196641 | +| Tile patch, grayscale (203) | 103 | 1,492,645/1,494,272 · 1 | 2,680,462/2,692,352 · 212 | 1,371,196/1,379,584 · 0.00341796875 | 2,681,149/2,693,376 · 0.00324004889 | + +The 36 additional renders use 64², 128×32, 64×256, 256×64, 128×512, 512×128, 512×256, 256×512, 512², 1024×256, 256×1024 and 1024×512. Use d = (default,.03125,.84375,.21875,.5625,.28125,.46875,.09375,default,.71875,.34375,.90625). Use the public control mappings and original fields from the [previous patch measurements](#tile-patch-inputs-and-scratch-color-precision) with the octave index j modulo 10. Leave Source disconnected at j=0, otherwise take field (j+1) modulo 6. Use seed 0 at j=0 and 8, seed 17884 at j=5, and 451749+31j otherwise. Render U16 and F32 throughout, adding U8 and F16 at j=0,1,4,5,8,11. Both applications reopened each saved graph and reproduced the original on 5,341,184/5,341,184 pixels in these 36 cases. The earlier 30- and 32-setting saves also reproduced every pixel within each application. + +Automatic image stamps choose a stored level from texture-coordinate differences measured across a two-by-two pixel group. Each group uses its top-left, top-right and bottom-left coordinates, including neighbors outside the drawn shape. To distinguish levels, generate a U8 field starting at 6. Add 64,48,36,32,28,24 when the sum of the two integer coordinate quotients for divisors (1,1),(2,2),(4,4),(8,8),(16,8),(32,8) respectively is odd. For manual levels replace each two-by-two block by the integer quotient of its sum plus two divided by four. At 256×128 center the stamp at (.5,.5), use size (.17679575,.24720412) and .00014 turns. Of the 1,466 pixels that distinguish levels two and three, 1,073 choose level two and 393 choose level three. An independently written graphics-device probe matched all 32,768 pixels with the shared group derivatives. Per-pixel derivatives reproduced 32,703. + +Across 139 stamp settings the new path matches 2,105,344/2,105,344 pixels. A second series near level transitions matches 2,457,600/2,457,600 across 180 settings. The 180 independent manual-level renders also match 2,457,600/2,457,600. The native F32 values at (128,64) and (128,63) in the fixed 256×128 graph are \`3e8bbc8c\` and \`3f094d89\`. Four fixed graphs used in the failing regression match 45,056/45,056. The 18 root controls covering repeat renders, changed seeds, zeroed individual controls, and solid, transparent or patterned inputs match 1,179,648/1,179,648. Both packaged Tile helpers retained their existing pixel and file-reopen matches. The 471 archived bitmap graphs retained 4,801,398/4,821,760 exact pixels across 1,213 renders. Each graph retained its previous exact count and maximum in every measured format. + +For a separate device-level stress test, sample a mip chain whose level identifies itself, choosing a derivative magnitude near a half-level threshold. The footprint reproduced 16,384/16,384 level choices for one screen direction and 16,384/16,384 for collinear derivatives in a single texture coordinate. It reproduced 15,483/16,384 when both screen derivatives were the same two-component vector and 15,876/16,384 for two independent vectors. Remaining diagonal threshold differences are open. + +At 1024×512 the first difference in the color root is the last directional blur (1041413498). It matches 18,310/524,288 U16 pixels, maximum 348. Its lower-resolution input matches all 131,072 U8 pixels. The following warp matches 523,419/524,288 U8 pixels, maximum one. The bitmap map then matches 517,371/524,288 U16 pixels, maximum 211. At the earlier 512×128 disagreement both the bitmap map and its final transform now match in full. At the 512² default the last blur still differs at 35 U16 pixels by one level, and the final color image matches. + +All 310 release node tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. Seven alternating single-worker release runs gave median cook times of 326 to 328 ms for color at 512×128, 1,828 to 1,897 ms for color at 512², 1,839 to 1,813 ms for grayscale at 512² and 26.2 to 25.1 ms for the rectangular Tile helper. + +### Streaming repeated pattern visits + +A repeating pattern now advances its number and random seed one draw at a time. The initial child runs once and a disconnected repeat child takes no visits. The evaluator accounts for visited nodes and keeps its existing bounds on retained stamps, discarded stamps and raster work. A repeat count alone previously caused an error above 10,000, even with the repeat child disconnected. + +For an independent reproduction, connect a single unit white square to the repeated child of an Iterate node. Use additive blending on a black grayscale background, zero roughness and an opacity multiplier of 1/32768. Render counts 0, 1, 8192, 9999, 10000, 10001, 12003 and 16384 in F32 at 8×4 with seed 452933, and U16 at 4² with seed 452950. For counts 0, 10001 and 16384 also wire only the initial child or leave both children disconnected. The 28 original renders matched 672/672 pixels, maximum zero. In F32 every repeated square added exactly 1/32768. At 12,003 repeats the stored U16 value is 24,006. At 16,384 repeats F32 stores .5 and U16 stores 32,767. Another 42 renders with independent random colors and positions retained 258,048/258,048 identical RGBA pixels, maximum zero. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Cells 1, second package (241) | 49 | 135,940/136,448 · 255 | 197,357/243,968 · 65441 | 86,784/87,296 · 0.998535156 | 220,333/269,824 · 0.99857223 | + +Both applications reproduced their original Cells 1 outputs after reopening the saved graph across all 629,760 pixels of the new 30-setting series. All 30 now cook. The four 64×16 results formerly refused by MaterialCraft match 516/1,024 U8 pixels, 511/1,024 U16, 512/1,024 F16 and 511/1,024 F32. Their respective maxima are 255, 65,441, .998535156 and .99857223. The other settings include exact 16², 256² and 128×512 outputs. The root remains open. [Earlier field comparisons](#wire-presence-inside-a-called-function) + +To reproduce the new series, use dimensions 16², 64×16, 16×64, 64², 128×64, 64×128, 128², 256², 128×512 and 512×128 in order. Use defaults at j=0 and 7. The other rows use d from (default,.03125,.875,.34375,.96875,.1875,.65625,default,.53125,.09375). Use zero seed at the default rows, 42 at j=1 and 411416+61j otherwise. Render U16 and F32 throughout, adding U8 and F16 at j=0,1,3,5,7. For changed settings select scale and pattern from (8,16,5,11,27,4,19,32,7,12) and (4,3,4,9,5,7,1,4,3,10) respectively. Set disorder, disorder speed, disorder anisotropy, luminance random and angle random to d. Set angle and anisotropy angle to d−.25 and pattern scale to .375+1.25d. Use pattern size (.4375+.75d,.8125+.6875(1−d)), tile offset (d−.34375,.40625−.875d) and enable non-square expansion at odd j. The primary table counts distinct settings once. + +The new regression failed on the preceding evaluator. All 311 release node tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. In seven alternating single-worker release runs, median times for 8,192 and 10,000 small repeats changed from 36.2 to 32.3 ms and 37.3 to 47.5 ms respectively. For Cells 1 the 64² changed case took 23.1 to 23.2 ms and the 256² default took 156.1 to 169.6 ms. + +### Diagonal blur across rectangular tile edges + +Both tile-patch roots match all 21,366,784 final pixels apiece through 1024². The previously failing 1024×512 setting now matches in all four storage formats. For a long, tiled diagonal blur, select the filtering axis in normalized texture coordinates. Shear along that axis in texels. Across a full period the transverse shift in texture coordinates is the texel slope times the filtering length divided by the transverse length. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Blur HQ, color (55) | 48 | 215,043/231,424 · 13 | 225,326/268,288 · 3341 | 100,355/116,736 · 0.0510253906 | 249,134/292,096 · 0.0509803891 | +| Blur HQ, grayscale (56) | 48 | 219,008/231,424 · 7 | 247,794/268,288 · 1799 | 104,320/116,736 · 0.0275878906 | 271,602/292,096 · 0.0274509788 | +| Tile patch, color (202) | 127 | 4,115,712/4,115,712 · 0 | 6,624,512/6,624,512 · 0 | 4,001,024/4,001,024 · 0 | 6,625,536/6,625,536 · 0 | +| Tile patch, grayscale (203) | 127 | 4,115,712/4,115,712 · 0 | 6,624,512/6,624,512 · 0 | 4,001,024/4,001,024 · 0 | 6,625,536/6,625,536 · 0 | +| Noise Fluid (272) | 53 | 95,744/95,744 · 0 | 495,343/495,616 · 6 | 95,744/95,744 · 0 | 354,389/354,560 · 1.52587891e-05 | + +The 24 additional patch settings use dimensions (1024×512, 512×1024, 1024², 512², 1024×256, 256×1024, 512×1024, 1024×512) and d = (.53125,.359375,default,.765625,.140625,.96875,.203125,.6875). Use the same public control mappings and original six fields as the [tile-patch input series](#tile-patch-inputs-and-scratch-color-precision), selecting field (j+4) modulo 6 and seed 454489+61j, with seed zero at defaults. Use U16 and F32 for every setting, also U8 and F16 at j=0,1,2,7. All 13,107,200 pixels per root reproduced independently within each application on reopening the MaterialCraft save. The earlier 30-, 32- and 36-setting saves also reproduced. In the 1024×512 color graph the last U16 blur improved from 18,310 to 524,193 exact samples out of 524,288, reducing its maximum from 348 levels to one. Its downstream warp, shuffle, pattern, transform and final output all match. At the 512² default the same stage differs by one level on 35 pixels. + +For an independent primitive check, generate the 16-bit field (117x+953y+43xy+191j+2051((x+3y) mod 7)) mod 65536. At even j divide by 257 using integer division to obtain an 8-bit source. For j=0…7 use (32×64,64×32,128×32,32×128,256×64,64×256,128×256,256×128) and turns (−.125,.125,.375,−.375,.125,−.125,.125,−.125). Use strengths 256r/min(width,height) for r=(.75,1.875,2.625,3.2,3.75,5.625,9.1875,14.375). Render U16 and F32 throughout and U8 and F16 at r=.75,3.2,5.625,14.375. Across 192 renders, U8 improved from 163,358 to 442,368/442,368, maximum 62 to zero. U16 improved from 222,548 to 884,641/884,736, maximum 17,565 to one. F16 improved from 124,302 to 442,364/442,368, maximum .24230957 to .00048828125. F32 improved from 212,361 to 843,680/884,736, maximum .26803905 to 1.78813934e−7. The regression samples the origin, center and opposite corner of a separate modular field. It failed on the previous filter. + +Both high-quality blur roots retain their 18 earlier exact settings. The additional 30 use (32×64,128×32,64×128,256×64,64×256,128²,256×128,128×256,512×128,128×512), intensities (0,3.25,default,13.625,9.375,2.625,6.5,14.75,4.25,4.25) and qualities (0,1,default,1,0,1,0,1,1,1). Choose original field j modulo 6 with seed 454919+29j, or zero at j=2. Render U16 and F32 throughout and U8 and F16 at j=0,2,3,5,8. Each application reproduced 737,280/737,280 original pixels per root from the save. The two high-intensity rectangular settings still differ. All four axial and diagonal passes matched at both settings and at the 512×128 control. The other branch first differs at .0625 turns. On the 256×64 input that stage matches 0/16,384 color pixels, maximum 52 U8 levels, and 365/16,384 grayscale pixels, maximum 36. On the 512×128 control the entire graph matches in both roots. [Earlier exact blur settings](#integer-and-oblique-directional-blur) + +Fluid retained 25,969,920/25,969,920 across 121 settings. For Noise Fluid the table combines the earlier full outputs with 30 additional renders. Use (16×32,32×16,64²,128×32,32×128,128²,256×128,128×256,256²,512×128), d=(default,.21875,.9375,.046875,.5625,default,.328125,.8125,default,.671875), scale=(default,2,1,3,2,default,3,1,default,1). For changed rows set disorder and warp intensity to d, pattern size to (.4375+.75d,.8125+.6875(1−d)) and enable non-square expansion at odd j. Use seed zero at j=0,5, seed 42 at j=1,8 and 433549+37j otherwise. Render U16 and F32 throughout and U8 and F16 at j=0,2,4,5,8. The two applications each reproduced all 633,856 pixels from the save. Across the 53 distinct full-output settings, 273 U16 and 171 F32 pixels still differ. [Earlier Fluid stage comparisons](#fibers-and-fluid-pattern-stages) + +All 312 release node tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. Over seven alternating single-worker release runs, median time for the 256×64 primitive at r=14.375 fell from 53.1 to 25.7 ms. The 1024×512 color and grayscale patch medians changed from 3315.9 to 3332.8 ms and 3557.5 to 3151.7 ms respectively. The 256×64 color HQ graph took 145.7 to 158.2 ms. + +### Starting coordinates of narrow rotated stamps + +Scratches 2 matches 5,414,144/5,414,144 RGBA pixels across 113 distinct settings, with zero maximum error. All eight previously differing F32 pixels in the earlier 82 settings now match. Each application reopened the MaterialCraft save and reproduced every pixel of its original in series of 30, 32 and 36 settings (521,216, 3,313,664 and 2,531,328 pixels). + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Scratches 2 (206) | 113 | 971,008/971,008 · 0 | 1,741,056/1,741,056 · 0 | 938,240/938,240 · 0 | 1,763,840/1,763,840 · 0 | + +For the 36 additional settings use dimensions (32×128,128×32,64²,256×64,64×256,128²,256²,512×128,128×512,512×256,256×512,512²) and d=(default,.08984375,.796875,.43359375,.99609375,.0625,default,.890625,.3203125,.265625,.6953125,default). Set width to 31+141d, height to 61+129(1−d) and disorder to d. Use seed zero at the three defaults, 42 at j=2 and 455377+47j otherwise. Render U16 and F32 throughout, adding U8 and F16 at j=0,2,5,6,9,11. The table counts identical settings once. [Earlier root and repeat settings](#tile-patch-inputs-and-scratch-color-precision) + +To isolate the cause, replay the 130 contributing Gaussian stamps at five differing pixels, with each stamp over transparent black and then over (127/255,127/255,1,1). Five individual foregrounds differed. Compositing the independently observed foregrounds in draw order reproduced all five original reference pixels exactly. Using the earlier local foregrounds reproduced all five local results. At 32×64, center (.59865606,.84110206), size (.004831543,.28550416), input-driven rotation −.13097546 turns and pixel (18,52), the reference signed horizontal coordinate is .52961653471. The preceding evaluator returned .52961647511. A single white horizontal ramp gives F32 bits 0x3f43ca7a at this pixel. + +The plane origin now truncates toward zero on the interpolation grid before either gradient contributes. The grid spacing is one sixty-fourth of the larger gradient’s F32 spacing. The change handles small negative origins when a thin rotated stamp has steep gradients in opposite directions. Across 260 isolated source/backdrop renders, 130 individual stamps over independently controlled incoming colors and 36 unit-gain profile renders, all 3,317,760 F32 pixels match. The six profiles were the paraboloid, horizontal ramp, pyramid, Gaussian, quartic bell and cone. + +An independent right-triangle graphics probe used 1,800 original triangles, integer edge spans of 8–86 texels, positive and negative vertex attributes, and one attribute pair close to zero. The previous calculation differed on 27 of 1,496,272 active coordinate components. Truncating the starting coordinate first matches every component. Four earlier triangle series retained all 5,623,484 exact components. The 40-setting BNW Spots 1 comparison still matches 2,399,204/2,399,232. The earlier 32-setting Clouds 1 and 2 series still match 707,562 and 707,572 out of 707,584 respectively. Their reference-repeat differences remain open. [Earlier variable-stage comparisons](#pixel-center-rounding-at-the-near-stamp-vertex) + +The new regression failed on the preceding evaluator. All 313 release node tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. Across seven alternating single-worker release runs, the 128² default-seed median changed from 869.1 to 747.0 ms and the 512² default from 7140.4 to 5854.7 ms. + +### Oblique directional blur on rectangular images + +A rectangular image can put the dominant texture-coordinate direction along the shorter texel projection. A line of unit impulses running across that axis isolates the filter window. Long oblique passes now use the sheared grid and project the radius minus half a texel onto the selected filtering axis. The corner regression uses a modular 16-bit field, both aspect orientations and a negative angle. It failed on the previous implementation. + +The two high-quality blur roots were recooked for the earlier 48 settings and 30 new settings each. The earlier set has 70 differing color pixels and 16 differing gray pixels, down from 118,686 and 65,820. The new set uses six original 16-bit sources sized 128 × 64, 64 × 128, 256 × 128, 128 × 256, 256 × 256 and 512 × 128. With zero-based coordinates let `a = (95 + 143x + 233y + 67xy + 1577((floor(x/7) + floor(y/3)) mod 11)) mod 65536`. Grayscale uses `a`. The color channels are `a`, `13a + 249x + 19`, `491y + 811x + 7931(x mod 5)` and `233xy + 397y + 1597(floor(x/3) mod 5)`, each modulo 65536. + +Cycle those sources in order for (width, height, intensity, quality) tuples (64,128,9.875,1), (128,64,15.875,1), (512,128,21.375,1), (128,512,18.125,1), (256,256,default,default), (256,128,7.875,0), (256,512,12.375,1), (512,256,11.9375,1), (512,512,9.3125,1) and (1024,128,19.375,1). Use seed zero for defaults and `455673 + 41j` for zero-based tuple index `j` otherwise. Compare U16 and F32 in every tuple and U8 and F16 in tuples 0, 1, 4, 7 and 8. Both applications reproduced all 3,489,792 original pixels per root when reopening 60 saved cases. The table counts each original setting once. Integer maxima are storage levels, and floating maxima are absolute channel errors. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Blur HQ (55) | 78 | 706,351/706,560 · 1 | 1,168,988/1,169,408 · 257 | 591,663/591,872 · 0.00439453125 | 1,192,796/1,193,216 · 0.0039215982 | +| Blur HQ Grayscale (56) | 78 | 706,483/706,560 · 1 | 1,169,266/1,169,408 · 257 | 591,795/591,872 · 0.00415039062 | 1,193,074/1,193,216 · 0.0039215982 | + +Comparing the original U8 intermediates locates further differences. At 256 × 64 the 1/16-turn pass is exact, and the subsequent 7/16-turn pass first differs in 13 color or six gray pixels, all on row zero. At 128 × 256 the first differences occur in the 3/16-turn pass (36 color, five gray). On the new 512 × 256 and 512 × 512 inputs the first 1/16-turn pass differs by one stored level in 35 and 88 color pixels, or 11 and 15 gray pixels. The two roots remain open. + +An independent 312-case primitive series used 12 signed angle/size pairs, radii 0.90625, 1.578125, 2.09375, 2.921875, 3.65625, 6.8125 and 13.75 texels, a modular 16-bit field, two isolated white pixels and a periodic stripe. + +| Storage | Exact pixels before | Exact pixels after | Pixels compared | Maximum before | Maximum after | +|---|---:|---:|---:|---:|---:| +| U8 | 100,206 | 344,024 | 344,064 | 96 | 1 | +| U16 | 26,036 | 342,166 | 344,064 | 24636 | 63 | +| F16 | 32,373 | 319,077 | 344,064 | 0.375976562 | 0.0009765625 | +| F32 | 757,353 | 1,545,530 | 1,949,696 | 0.375929713 | 0.00128859282 | + +Seven alternating single-worker release cooks had median times of 61.6 → 32.7 ms and 55.2 → 32.1 ms on the two 13.75-texel primitive cases. The complete 256 × 64 color graph measured 162.6 → 224.7 ms, and the 128 × 256 grayscale graph measured 391.7 → 400.2 ms. All 314 node release tests, workspace Clippy, formatting, dependency layers and WebAssembly checks passed. + +### Scaled scratch and Gaussian noise and spot generators + +The six scaled generators were compared at revision `1e254e4`. Their archived defaults and previously measured settings are included once. Each new series pairs 30 original procedural renders with 30 reopens of the file saved by MaterialCraft. Each application also reproduced its own original pixels across its earlier 30-case save series. The pixel table counts original settings only. Integer maxima are stored levels and floating maxima are absolute channel errors. + +Use output sizes (32,64), (64,32), (128,128), (256,64), (64,256), (256,256), (512,128), (128,512), (256,512) and (512,512). At indices 0, 5 and 9 use default parameters, with seeds 0, 0 and 42. For each other index `j` use seed `456089 + 17i + 43j` with inventory index `i`. Use scalar `d` equal to .921875, .453125, .0390625, .69921875, .578125, .98046875 and .19140625 at indices 1, 2, 3, 4, 6, 7 and 8 respectively. Gaussian Noise uses scales 16, 5, 11, 27, 19, 32 and 7 at these indices. The other four roots use 2, 1, 3, 2, 3, 1 and 2. Compare U16 and F32 throughout, plus U8 and F16 at 1, 2, 5, 6 and 9. + +Set disorder, disorder speed, disorder anisotropy, angle random and pattern amount to `d` wherever exposed. Angle and disorder anisotropy angle use `d − .25`. Pattern size uses `(.375 + .75d, 4.5 + 13d)`, pattern size random uses `(.125 + .5d, .625 − .375d)`, and tile offset uses `(d − .34375, .40625 − .875d)`. Enable non-square expansion at odd changed indices. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Directional Scratches (259) | 74 | 430,336/430,336 · 0 | 869,519/869,632 · 1 | 432,367/432,384 · 0.000122070312 | 821,171/823,808 · 1.32219866e-05 | +| Directional Scratches v2 (260) | 74 | 479,487/479,488 · 1 | 820,377/820,480 · 2 | 432,368/432,384 · 0.000244140625 | 820,959/823,808 · 3.32295895e-05 | +| Gaussian Noise (281) | 79 | 506,881/507,392 · 229 | 755,521/917,504 · 63380 | 506,878/507,392 · 0.899414062 | 665,442/907,520 · 1.93185183 | +| Gaussian Noise v2 (282) | 79 | 536,207/540,160 · 228 | 680,103/884,736 · 65535 | 503,306/507,392 · 1.19726562 | 642,173/907,520 · 6.80174084 | +| Gaussian Spots 1 (283) | 67 | 506,368/506,368 · 0 | 906,165/906,240 · 1 | 506,330/506,368 · 0.000244140625 | 863,774/874,496 · 5.12599945e-06 | +| Gaussian Spots 1 v2 (284) | 67 | 539,136/539,136 · 0 | 873,399/873,472 · 1 | 506,359/506,368 · 0.000122070312 | 859,821/874,496 · 7.9870224e-06 | + +Both Gaussian Noise outputs are exact at the default 256² and 512² settings. The 128 × 512 test at scale 32 with non-square expansion differs at all 65,536 F32 pixels in the first version, with maximum error 1.93185183. The 512 × 128 test at scale 19 with expansion disabled differs at 2,432 pixels, with maximum 1.49011612e-7. The earlier stage comparisons locate differences in the pattern generator. The scratch and spots counts also retain nonzero errors. All six roots remain open. + +### Tiling periods on rectangular Gaussian noise graphs + +A single square stamp exposed the displacement at the edge of a wide tiling region. The parameter resolver clipped each tiling coordinate to the catalog slider range extended by 16 units. A 64-unit interval centered on .5 became a 33-unit interval, which moved repeated stamps. The resolver now passes the finite coordinates to the pattern renderer. The renderer bounds visited stamps, copies and sampled pixels. + +Center the render and tiling rectangles on (.5,.5). Use (render width, render height, tile width, tile height) of (32,32,32,32), (38,19,33,19), (19,38,19,33), (64,32,33,32), (32,64,32,33), (44,11,33,11), (32,64,32,64), (64,32,64,32), (33,33,33,33), (34,17,34,17) and (32,64,32,33). Enable both tiling axes except in the last case. Place the root branch at (−.5,−.5) with zero rotation, zero variation and additive blending. Use a single square for zero-based indices 1, 4, 7 and 10, and a horizontal ramp for the others. Render at 128 × 64 F32 when the render width is at least the height, and 64 × 128 otherwise. Set (X offset, Y offset, X size, Y size) to (0,0,5.75,6.25), (9,.5,7,11), (−14.5,−5,3.25,2.25), (17,2,5,3), (26,−14,3,4), (−31,1,3.75,3), (.25,22,8,6), (1,−19,7,9) and (.5,−27,4,2). Use seed `457591 + 11j + h` for interval index `j` and stamp index `h`. + +The independent 64² controls use identical render and tile intervals 64 × 32, repeated with the axes exchanged. Set (center X, center Y, width, height) to (26,2,3,4), (−24,−3,3,5), (14.5,−1,5,3) and (35,4,4,3), with seeds 458293 through 458296. In the first orientation the first stamp covers columns 56–58 and rows 31–38 inclusive. The last wraps into columns 1–4 and rows 36–41. The transposed masks exchange rows and columns. Across the 99 rectangular and eight square cases, **841,920/843,776** F32 pixels previously matched, maximum error 1. The full intervals match **843,776/843,776**, maximum error zero. + +The same 79 [whole-root settings](#scaled-scratch-and-gaussian-noise-and-spot-generators) were compared again for each version, including defaults, varied scale, non-square expansion, seeds, resolutions and four storage formats. Each version also reproduced the raw pixels of both 30-setting series after a save and reopen in each application. The table counts the original settings once. + +| Root (inventory index) | Distinct settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Gaussian Noise (281) | 79 | 507,392/507,392 · 0 | 917,296/917,504 · 1 | 507,390/507,392 · 0.000244140625 | 825,603/907,520 · 3.57627869e-07 | +| Gaussian Noise v2 (282) | 79 | 540,160/540,160 · 0 | 884,582/884,736 · 1 | 507,392/507,392 · 0 | 839,170/907,520 · 2.38418579e-07 | + +Four additional file pairs isolate the region setting. Use scale 19 with disorder .8125, non-square expansion enabled and 64 × 32 F32 or 32 × 64 U16. Use seeds 87892 and 87893 in the first version and 87899 and 87900 in v2. In v2 set disorder speed to 1.375, anisotropy to .625, anisotropy angle to −.3125 and tile offset to (−.4375,.0625). Reopen files with the authored tiling expression and with the full render interval assigned directly. Both reproduce every original reference pixel. Assigning the clipped interval instead changes 797 and 774 pixels in the first version and 2,048 and 1,390 in v2. The maximum F32 errors are .668966413 and 1.01086843 respectively. The corresponding U16 maxima are 43,886 and 51,197 levels. + +Across all inventory settings, both versions now agree on every U8 pixel. The first version retains two F16 differences, and both retain one-level U16 differences and small F32 discrepancies in the pattern generator. The wide-stamp regression failed before the interval change. All 318 node release tests, strict workspace Clippy, formatting, dependency layers and WebAssembly checks passed. + +### Short directional blur tap order on rectangular inputs + +Fluid matches **25,969,920/25,969,920 final pixels across 121 distinct settings** through 2048 pixels per side. Both applications reopened the MaterialCraft package and reproduced every pixel of their originals over 28, 38 and 36 settings (498,688, 8,654,848 and 17,588,224 pixels). The three renders with intermediate graph outputs recorded at 512×1024, 1024×512 and 1024² match 9,961,472/9,961,472 intermediate and final samples. [First differing stage and earlier settings](#fibers-1-and-fluid-through-1024-pixels-per-side) + +| Storage | Distinct settings | Exact pixels | Maximum error | +|---|---:|---:|---:| +| U8 | 19 | 4,848,896/4,848,896 | 0 | +| U16 | 41 | 8,206,592/8,206,592 | 0 | +| F16 | 19 | 4,848,896/4,848,896 | 0 | +| F32 | 42 | 8,065,536/8,065,536 | 0 | + +For the final 36 renders use the following (width×height, seed, d) tuples in order. Render U16 and F32 throughout, adding U8 and F16 at zero-based indices 0,3,4,6,9,11. + +| j | Dimensions | Seed | d | +|---:|---|---:|---:| +| 0 | 32×128 | 0 | .9375 | +| 1 | 128×32 | 42 | .34375 | +| 2 | 256×512 | 412351 | default | +| 3 | 512×256 | 402971 | .09375 | +| 4 | 512×1024 | 43016 | .6875 | +| 5 | 512×1024 | 0 | .90625 | +| 6 | 1024×512 | 42 | default | +| 7 | 256×1024 | 13441 | .40625 | +| 8 | 1024×256 | 67357 | .59375 | +| 9 | 512×2048 | 31121 | .25 | +| 10 | 2048×512 | 60149 | .796875 | +| 11 | 1024×1024 | 31973 | default | + +Use disorder d, warp intensity 53d, flow .34375−d, pattern length .78125−.625d and width .09375+.625d for the changed settings. At j=4 use the earlier 512×1024 settings (warp intensity 41.9375, flow .21875, length .5546875, width .359375). The third directional blur now matches 131,072/131,072 U16 pixels there. + +A three-tap directional blur reads its outer taps in the order set by the dominant **normalized texture coordinate**. At −.125 turns it starts toward increasing x on a tall image and increasing y on a wide image. Reading the taps in reverse changes the last bit of the fused sum. Generate a linear U16 field with level ((17x+113y+59xy+19)×7919) mod 65536, enable both tile axes, and use intensity 2.64 at 64×128. At (1,0) the F32 bits change from 0x3ec0b936 to the measured 0x3ec0b937. With the same strength and 128×64 the measured bits are 0x3ed1f3e7. + +| Original input series | Renders | Exact pixels before | Exact pixels after / total | Maximum error after by storage | +|---|---:|---:|---:|---| +| ±.125 turns | 70 | 3,780,865 | 3,956,736/3,956,736 | 0 / 0 / 0 / 0 | +| Seven other angles | 147 | 865,371 | 871,548/1,003,520 | 0 / 1 / 0.000122070312 / 1.1920929e-07 | +| Earlier rectangle and square controls | 174 | 923,423 | 923,423/1,622,016 | 192 / 49199 / 1.05664062 / 1.06214854 | + +The last column gives U8, U16, F16 and F32 in order. For the new series use radii .515625, .66, .875 and 1.32, with intensity equal to radius×256/min(width,height). Render F32 throughout, adding U8, U16 and F16 at radius .66. At ±.125 use 64×128, 128×64, 64², 256×512 and 512×256. At .375, −.375, .875, −.0625, .3125, −.1875 and .09375 turns use the first three sizes. For native RGBA input, import the grayscale field into the fixed U16 color input. At .375 turns and radius .875 on 64×128, and at .875 turns and radius 1.32 on 128×64, exact F32 counts decrease from 4,055 to 3,517 and 3,130 to 2,941. In both cases maximum error falls from 1.1920929e−7 to 5.96046448e−8. These short oblique angles remain open. [Earlier oblique controls](#short-oblique-directional-blur) + +### Fibers 1 and Fluid through 1024 pixels per side + +Fibers 1 matched 9,430,272/9,430,272 final pixels across 87 distinct combinations of dimensions, seed, parameter values and storage. Fluid matched 9,428,962/9,430,272 on the same matrix. The 655 differing locations in the 512×1024 Fluid render affect both the U16 and F32 outputs. Each application reproduced its original pixels when reopening the MaterialCraft package in the new 28 and 38 settings (498,688 and 8,654,848 pixels per root). + +| Root and inventory index | Storage | Settings | Exact pixels | Maximum error | +|---|---|---:|---:|---:| +| Fibers 1 (137) | U8 | 13 | 1,568,000/1,568,000 | 0 | +| Fibers 1 (137) | U16 | 30 | 3,217,664/3,217,664 | 0 | +| Fibers 1 (137) | F16 | 13 | 1,568,000/1,568,000 | 0 | +| Fibers 1 (137) | F32 | 31 | 3,076,608/3,076,608 | 0 | +| Fluid (153) | U8 | 13 | 1,568,000/1,568,000 | 0 | +| Fluid (153) | U16 | 30 | 3,217,009/3,217,664 | 24 | +| Fluid (153) | F16 | 13 | 1,568,000/1,568,000 | 0 | +| Fluid (153) | F32 | 31 | 3,075,953/3,076,608 | 0.000366210938 | + +For the 28 new renders, take j from zero in the dimension and parameter lists below. Use seed 0 at j=0,8, 42 at j=1 and 399553+31i+17j otherwise, where i is the inventory index. Render U16 and F32 throughout, adding U8 and F16 at j=0,2,5,7,8. Keep defaults at j=0,8. At other indices, Fibers 1 uses the listed tiling. Fluid uses disorder, pattern length and pattern width equal to d, warp intensity 40d and flow .5d−.1875. + +| | Values in dimension order | +|---|---| +| Dimensions | 16², 16×64, 64×16, 32×128, 128×32, 64², 128×256, 256×128, 256² | +| d | default, .96875, .03125, .71875, .21875, .015625, .859375, .46875, default | +| Tiling | default, 2, 1, 3, 2, 1, 1, 2, default | + +For the 38 larger renders, add 31i to the table seed except at j=3,6. Keep the public parameters at defaults where shown. Render U16 and F32 throughout, adding U8 and F16 at j=0,3,5,6,9,12. At changed settings Fluid uses disorder d, warp intensity 61d, flow d−.46875, pattern length .125+.625d and width .875−.75d. The 512×1024 discrepancy occurs at seed 43016 and d=.6875. Its pattern source and next two directional blurs match all 131,072 pixels each. The first differing stage is directional blur 1050407172 (intensity .66, angle −.125 turns). It matches 130,944/131,072 U16 pixels, maximum one level. At (161,17) the reference stores 31,157 and MaterialCraft stores 31,158. + +| | Values in dimension order | +|---|---| +| Dimensions | 32², 256×64, 64×256, 128², 128×512, 512×128, 256², 256×512, 512×256, 512², 512×1024, 1024×512, 1024² | +| Seed | 29, 863, 23173, 42, 5227, 17293, 0, 173, 11173, 21101, 38273, 11867, 11939 | +| d | .25, .625, .0625, default, .84375, .09375, .375, .171875, .984375, default, .6875, .28125, default | +| Tiling | 1, 3, 2, default, 1, 3, 2, 1, 2, default, 3, 2, default | + +In 15 separate stage captures per root, explicitly select U8, U16 and F32 on the pattern generator (Fibers 1 UID 1041346050, Fluid UID 1050407179) and preserve downstream format inheritance. Both roots match all 835,584 final pixels per root. Across all observed stages Fibers 1 matches 2,015,232/2,015,232 and Fluid matches 3,969,024/3,969,024, maximum error zero. [Earlier stage settings](#fibers-and-fluid-pattern-stages) + +### Repeated Dirt pattern stages + +Render each listed pattern source six times in the same native session, alternating its storage between U16 and F32, with fixed graph parameters, dimensions and seed. Each entry below has 65,536 pixels. “First” compares MaterialCraft with the first reference frame. “Any” counts pixels matching at least one of the six at that location. The last two columns count values outside the six-frame minimum and maximum and give the largest distance to that interval. Integer errors are in stored levels. [Root settings and final-output comparisons](#wave-frequency-and-phase-in-directional-noise) + +| Root · pattern UID | Format | Distinct reference frames | First exact · maximum error | Any exact | Outside interval | Maximum distance | +|---|---|---:|---:|---:|---:|---:| +| Dirt 1 · 1050406955 | U16 | 1 | 65,535 · 1 | 65,535 | 1 | 1 | +| Dirt 1 · 1050406955 | F32 | 6 | 64,957 · 1.1920929e-07 | 65,453 | 83 | 5.96046448e-08 | +| Dirt 3 · 1083962542 | U16 | 3 | 65,535 · 1 | 65,536 | 0 | 0 | +| Dirt 3 · 1083962542 | F32 | 6 | 65,179 · 5.96046448e-08 | 65,326 | 209 | 5.96046448e-08 | +| Dirt 5 · 1047055673 | U16 | 6 | 65,517 · 1 | 65,531 | 5 | 1 | +| Dirt 5 · 1047055673 | F32 | 6 | 58,420 · 1.1920929e-07 | 62,328 | 3,179 | 1.1920929e-07 | +| Dirt 6 · 1047121771 | U16 | 6 | 65,522 · 1 | 65,534 | 2 | 1 | +| Dirt 6 · 1047121771 | F32 | 6 | 62,155 · 1.1920929e-07 | 64,867 | 653 | 1.1920929e-07 | +| Dirt Gradient · 1083691739 | U16 | 6 | 65,507 · 1 | 65,529 | 7 | 1 | +| Dirt Gradient · 1083691739 | F32 | 6 | 26,681 · 1.1920929e-07 | 52,850 | 10,609 | 5.96046448e-08 | + +Use 256² with defaults and seed 0 except for Dirt 3, which uses 128×512, disorder .984375 and seed 398765. At (144,242) every Dirt 1 U16 reference stored 38,981 and MaterialCraft stored 38,980. All five roots retain at least one difference outside the observed reference interval in one or both formats. + +### Interpolated coordinates on clipped squares and quarter turns + +Directional Noise matches **40,572,160/40,572,160 final pixels across 136 distinct settings through 2048²**. Both applications reopened the MaterialCraft package and reproduced the original values across 40, 46 and 28 settings (2,006,016, 8,730,624 and 29,753,344 pixels). All fourteen intermediate outputs at 1024², seed 29987, match across 6,225,920 pixels, including the generator sample previously one U16 level high. [Wave-stamp isolation and the first 108 settings](#wave-frequency-and-phase-in-directional-noise) + +| Storage | Distinct settings | Exact pixels | Maximum error | +|---|---:|---:|---:| +| U8 | 23 | 7,600,896/7,600,896 | 0 | +| U16 | 44 | 12,699,392/12,699,392 | 0 | +| F16 | 23 | 7,600,896/7,600,896 | 0 | +| F32 | 46 | 12,670,976/12,670,976 | 0 | + +The last 28 settings use (width×height, seed) pairs (64×1024,0), (1024×64,42), (256×1024,32011), (1024×256,91151), (512²,71123), (1024²,0), (1024²,42), (512×2048,67061), (2048×512,13877), (2048²,25771). Render U16 and F32 throughout, adding U8 and F16 at indices 1,4,6,9 starting from zero. + +Two original quadrant controls isolate the setup of the interpolated coordinates. Use a black grayscale F32 output, zero roughness, unit gain and tint, tiling on both axes, branch offset (−.5,−.5) and the following frame offsets. The additional pyramid row exercises a perpendicular slope on the other side of the image. + +| Profile and dimensions | Frame offset | Pattern size | Rotation in turns | Pixel | Previous bits | Measured bits | +|---|---|---|---:|---|---|---| +| Paraboloid, 256×512 | (−.8652914,−.36846057) | (.09375,.27446696) | .25 | (18,341) | 0x3e623d24 | 0x3e623d20 | +| Paraboloid, 256² | (−.08850241,2.9797058) | (.06013941,.0625) | 161.3187 | (236,1) | 0x3dec9e20 | 0x3dec9e10 | +| Pyramid, 128×256 | (−.01251943,.8291415) | (.0390625,.0078125) | .94446576 | (0,211) | 0x3e217c80 | 0x3e217c84 | + +For the quarter turn the padded triangle starts at (−1,299), with spans 142 and 97. Adding the horizontal offset product to the signed vertex value 1.0100661516189575 gives independent results at single-precision storage boundaries. Align both terms at their shared exponent with five guard bits before adding them. The measured origin is .981601893901825, previously .9816018342971802. In 2,560 independently generated axis-aligned triangles, the exact count increased from 1,173,382 to 1,181,994/1,181,994 signed coordinates. Four or six guard bits gave 16,192 and 6,468 differences. Four stamp profiles at 134 original axis-aligned or quarter-turn geometries each matched all 39,733,248 F32 pixels, maximum error zero. + +The two oblique examples have equal horizontal and vertical screen spans (43 and 11 respectively). When clipping selects a far vertex, the perpendicular gradient uses two half-spans measured from that vertex. Keep both signed slope products at extended precision, align them with two guard bits, then subtract and store the resulting gradient. Rectangular triangles retain their measured gradients. On 1,440 translated square triangles the exact coordinate count rose from 440,248 to 476,000/476,000. A separate 2,560-triangle comparison of squares and rectangles differing by one pixel measured 972,042/972,042 coordinates, including 30,130 previously different square samples. Three independent triangle sets retained or reached exact agreement across 1,047,772, 1,731,210 and 2,368,502 coordinates. Four original profiles (ramp, paraboloid, pyramid and creased bell), each tested on 108 translated and rescaled geometries, matched 29,884,416/29,884,416 F32 pixels. + +All 653,456 values across the eight intermediate-stage captures in BNW Spots 3 now match, including all 524,288 samples of the previously differing branch. The 118 distinct final settings remain 3,159,552/3,159,552. BNW Spots 1 still matches 3,177,940/3,177,984 final samples over 125 settings. Across the additional stage probes Clouds 1 has 1,510,019/1,510,080 exact pixels and Clouds 2 has 911,010/911,040. [Cloud and BNW Spots comparisons, including repeat behaviour](#pixel-center-rounding-at-the-near-stamp-vertex) + +### Wave frequency and phase in Directional Noise + +Directional Noise (`directionnal_noise.sbs`) matched 10,818,793/10,818,816 final pixels across 108 distinct settings. All 23 earlier renders (147,712 pixels) and all 40 new renders through 512² (2,006,016 pixels) match. Before the wave fix the same two comparisons had 59 and 732 differing pixels. All 14 captured intermediate outputs now match in eight earlier and five new renders. The independent 46-render matrix found 23 differences at 1024², seed 29987. + +| Storage | Distinct settings | Exact pixels | Maximum error | +|---|---:|---:|---:| +| U8 | 19 | 2,030,336/2,030,336 | 0 | +| U16 | 34 | 3,393,269/3,393,280 | 2 | +| F16 | 19 | 2,030,335/2,030,336 | 0.000244140625 | +| F32 | 36 | 3,364,853/3,364,864 | 1.68979168e-05 | + +At 128², use one centered grayscale wave stamp of unit size, tint and gain, zero rotation and roughness, and a black background. At pixel (38,64) with zero variation the output bits are `0x3d9c60ac`. The previous value was `0x3d9c60a8`. Accumulate six times the nonnegative variation plus 1.5 with one F32 rounding. Multiply this frequency by the signed horizontal coordinate, subtract the nearest integer phase and round the absolute distance to F32 before forming the triangle. The existing quadratic shaping and radial falloff then give 131,072/131,072 F32 pixels at variations 0, .0625, .1875, .25, .375, .5, .75 and 1. At variation .45037964, pixel (68,64) measures `0x3eb71c16`. Rounding the frequency multiplication and addition separately gives `0x3eb71c10`. + +Twelve variations (−.25, 0, .03125, .1234567, .1875, .3125, .375, .53125, .71875, .95, 1 and 1.25) over twelve geometries from 16² to 512×128 gave 5,286,912/5,286,912 pixels in 288 renders. These include rotations .07317, −.21457, .23137 and 1.07123 turns, nonuniform size, clipped edges and all four output formats. Two additional frequency sweeps compared a full centered 128² stamp and a 128×256 stamp with size (.234375,.421875), at −.21457 turns. All 2,408,448 F32 pixels in 98 renders match. Fourteen variations in one sweep specifically distinguish a single rounding from two. The separate-rounding model loses 156,048/311,296 pixels in the 19 centered controls from that sweep. + +For the directional root, independent draws from its three pattern stages matched 988,160/988,160 F32 pixels across 60 cases in the initial isolation set. + +The 1024² holdout isolates the remaining differences to (18,341) in the 256×512 pattern stage 1067074843. The reference stores 16386 there in U16 and .2500428855419159 in F32, identically in six renders at the same seed. Thirteen of its fourteen contributing stamps agree across their entire F32 outputs. The remaining stamp has frame offset (−.8652914,−.36846057), size (.09375,.27446696), rotation .25 turns, gain .0783345 and tint 1.8601174. At the disputed pixel it returns bits `0x3cdb7e2f` in the reference and `0x3cdb7e32` in MaterialCraft. Adding the independently measured draws in graph order reproduces the reference sum. The one U16 difference spreads to eleven F32 output pixels after resampling and levels. Both applications reopened the saved package and reproduced their own originals in all 40 and all 46 cases, respectively 2,006,016 and 8,730,624 pixels per comparison. + +For the 40-setting matrix, use dimensions (16²,16×64,64×16,32×128,128×32,64²,128×256,256×128,256²,128×512,512×128,512²). With zero-based dimension index j and inventory index i, use seed 0 at j=0 and 8, 42 at j=1 and 396203+17i+41j elsewhere. Render U16 and F32 throughout, adding U8 and F16 at j=0,2,4,6,7,8,10,11. Directional Noise (i=127) has no exposed input parameters. For the independent matrix use the dimensions, seeds and formats in the Creased holdout table. [Independent render settings](#aligning-the-origin-of-a-clipped-stamp-in-creased) + +The five following Dirt roots used the same 40-setting matrix. For Dirt 1 and 3, disorder was (default,1,0,.6875,.03125,.859375,.1875,.65625,default,.984375,.140625,.5). The other three have no exposed parameters. Each format cell gives the exact pixels and maximum error. Every U8 and F16 denominator is 464,128 and every U16 and F32 denominator is 538,880. The final column compares the reference’s original and reopened package over 2,006,016 pixels. MaterialCraft reproduced its own originals on all 2,006,016 for each root. + +| Root (inventory index) | U8 exact · max | U16 exact · max | F16 exact · max | F32 exact · max | Exact on reference reopen | +|---|---:|---:|---:|---:|---:| +| Dirt 1 (128) | 464,128 · 0 | 538,870 · 1 | 464,128 · 0 | 538,861 · 1.53183937e-05 | 2,005,998 | +| Dirt 3 (129) | 464,128 · 0 | 538,869 · 1 | 464,128 · 0 | 538,865 · 1.52587891e-05 | 2,006,000 | +| Dirt 5 (130) | 464,126 · 1 | 538,700 · 4 | 464,048 · 0.00048828125 | 538,702 · 5.10215759e-05 | 2,005,678 | +| Dirt 6 (131) | 464,127 · 1 | 538,646 · 5 | 464,038 · 0.000244140625 | 538,185 · 9.27709043e-05 | 2,005,339 | +| Dirt Gradient (132) | 464,128 · 0 | 538,710 · 2 | 464,116 · 0.00048828125 | 538,686 · 2.00867653e-05 | 2,005,635 | + +### 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. + +| Original graph | Renders | U8 exact · max | U16 exact · max | F16 exact · max | F32 exact · max | +|---|---:|---:|---:|---:|---:| +| Earlier matrix | 17 | 5,120/5,120 · 0 | 123,904/123,904 · 0 | 5,120/5,120 · 0 | 11,520/11,520 · 0 | +| New settings, original or reopened | 40 | 529,664/529,664 · 0 | 669,941/669,952 · 3 | 529,664/529,664 · 0 | 669,941/669,952 · 4.57763672e−5 | + +At 512², disorder .5, warp intensity 64 and seed 392570, the blurred 256² U16 image and 32×64 U16 displacement map match in both apps. The first warp previously matched 259,007/262,144 U16 pixels, maximum six levels. The final warp matched 259,047/262,144 F32 pixels, maximum .000183105469. Both warps now match all 262,144 pixels, maximum zero. + +A 16² F32 horizontal coordinate ramp and constant F32 mask 1025/2048 reproduce the difference on one pixel. Set both axes to repeat and the intensity to 64. At zero turns the measured value at (0,0) is 2+1/256. The previous implementation returned 2 after rounding the direction just below one. An authored full turn gives 2 in both applications. MaterialCraft uses an exact horizontal unit vector at zero turns. + +For independent warp controls, use the grayscale field (1011x+1123y+17xy+577) mod 65536 and mask (307x+587y+617xy+37001) mod 65536 as U16 words. Include a linear horizontal ramp and a full-white map. Compare 64² through 512² outputs with equal and unequal source and mask dimensions, including 512² output with a 256² source and a 32×64 mask. These controls and the two isolated Creased warps match 5,033,984/5,033,984 U16 and 5,033,984/5,033,984 F32 pixels over 82 renders. The previous counts were 5,028,248 and 5,031,514, with maximum errors 256 and .00390630960. + +A separate 24-angle sweep uses a horizontal or vertical coordinate ramp at 16², 64×32 and 128², intensity 64. For t=(x+3y) mod 16, use mask (((181t+512) mod 2048)+.5)/(64×min(width,height)), negating when t mod 5 is 3. The F32-source suite matches 896,615/897,024 output pixels, maximum 1/256. The remaining 409 occur at −1.5, 1.75, .25−2⁻¹⁵ and .5+2⁻¹⁵ turns. U16 inputs on the same settings match all 897,024 F32 output pixels. Other measured angles include zero, positive and negative quarter, half, three-quarter and full turns, .125, −.125 and .37109375. The zero-turn F32 renders alone gained 198 exact pixels and now match 37,376/37,376. + +In the earlier 224-render matrix, the 14 differences previously observed at zero turns are gone. Nine remain at −.3125 turns, giving 1,089,527/1,089,536 pixels. The 64 source/map/output format combinations retain 262,144/262,144 exact pixels. The unequal-input, output-size and resize-path suites retain 412,160/412,160, 340,480/340,480 and 873,600/873,600 respectively. The 72 amplified renders retain 274,432/294,912 exact F32 pixels, maximum 1.96875. [Prior matrices and graph settings](#multi-directional-warp-and-intermediate-storage) + +For the 40 intact renders, use dimensions (16²,16×64,64×16,32×128,128×32,64²,128×256,256×128,256²,256×512,512×256,512²). In this order use warp intensity (default,0,64,17.75,63.5,4.125,59.25,.5,default,52.875,31.125,64) and disorder (default,1,.125,.78125,.0625,.8125,.375,.546875,default,.9921875,.1015625,.5). At zero-based indices 0 and 8 use seed 0, at index 1 use 42, otherwise use 392119+41j. Render U16 and F32 at every dimension, with U8 and F16 at indices 0,2,4,6,7,8,10,11. + +All 22 remaining final differences occur at 256×512 with seed 392488. At (11,163) of the 128×256 generator stage (UID 1083962295), six forced reference renders each returned 36,919 in U16 and .5633411407470703 in F32. MaterialCraft's U16 result is 36,918. Three U16 samples then differ in the blur, twelve in the first warp and eleven in each of the two final formats. Replaying each warp with the measured input and mask at that setting reproduces all 131,072 pixels at both stages. The independent directional-warp change also preserved 175,360/175,360 pixels on each of the two multi-directional warps and two non-uniform blur sample roots. [Earlier warp measurements](#multi-directional-warp-and-intermediate-storage) + +### Pixel-center rounding at the near stamp vertex + +BNW Spots 1 now matches 3,177,940/3,177,984 final pixels across 125 distinct settings. The earlier result was 3,177,789. Its remaining differences include deeper stages whose results change across repeated reference renders. BNW Spots 3 retains 3,159,552/3,159,552 exact final pixels across 118 settings. The same 40-setting save and reopen comparison again matched all 2,399,232 pixels in both applications. [Dimensions, settings and repeated renders](#draw-order-at-six-quadrant-subdivisions) + +| Root on the original file | U8 exact · max | U16 exact · max | F16 exact · max | F32 exact · max | +|---|---:|---:|---:|---:| +| BNW Spots 1, 125 settings | 649,984/649,984 · 0 | 949,470/949,504 · 2 | 649,983/649,984 · .000244140625 | 928,503/928,512 · 2.15768814e−5 | +| BNW Spots 3, 118 settings | 647,936/647,936 · 0 | 943,360/943,360 · 0 | 647,936/647,936 · 0 | 920,320/920,320 · 0 | +| Clouds 1, 32 settings | 154,112/154,112 · 0 | 199,670/199,680 · 4 | 154,112/154,112 · 0 | 199,668/199,680 · .000110566616 | +| Clouds 2, 32 settings | 154,112/154,112 · 0 | 199,672/199,680 · 2 | 154,111/154,112 · .000244140625 | 199,677/199,680 · 2.28881836e−5 | + +A cropped quadrant with one stamp isolates the change. Use black F32 grayscale, additive blending, unit gain and tint, zero roughness, no tiling, branch offset (−.5,−.5) and seed 389119. Apply the center as the frame offset. The table gives the reference F32 bits at zero-based pixel coordinates. MaterialCraft previously returned 0x3dff4c20 for the first sample. + +| Dimensions | Profile | Center | Size | Rotation in turns | Pixel | F32 bits | +|---|---|---|---|---:|---|---| +| 64×32 | Linear ramp | (.5009855,.012967646) | (.024458896,.015625) | 136.94586 | (31,0) | 0x3dff4c1c | +| 32² | Paraboloid | (.06045103,.2529377) | (.055972442,.03125) | 152.8708 | (1,8) | 0x3f0e3e7c | +| 64² | Paraboloid | (−.0138504505,.07075971) | (.0723335,.0625) | 189.57106 | (0,5) | 0x3eeba3c2 | +| 256² | Linear ramp | (−.010898113,.7042948) | (.02902194,.03125) | 325.4251 | (0,179) | 0x3d678fd8 | + +Each axis rounds the projected near edge minus half a pixel to F32, then rounds the interval to the snapped first sample center to F32. Subtracting one pixel gives the displacement of the near vertex. This reproduces the ramp, pyramid and paraboloid measurements on both sides of a clipped edge. The 297 translation and scale controls moved eleven measured stamps by (0,0), (1,0), (0,1), (5,−3) and (−4,4) pixels at the original size, by (0,0) and (2,3) at double size, and by (0,0) at four and eight times the size. Together they match 27,426,816/27,426,816 F32 pixels, up from 27,426,354. A further 112 geometries, each rendered with all three profiles, match 6,669,312/6,669,312 pixels, up from 6,669,285. They include 16×32 through 512×128, rotated, axis-aligned and out-of-bounds vertices. The maximum error is zero in both sets. + +In BNW Spots 3's 256² U16 stage at a requested 16², disorder .15625 and seed 8866, pixel (118,0) now stores 44,702 in both apps. At (236,1) the reference stores 29,396 and MaterialCraft stores 29,397. Across eight renders the intermediate matches 524,287/524,288 pixels, maximum one U16 level. In Clouds 2 all seven pyramid stamps contributing at (19,0) of the 32×16 stage now match individually across all 3,584 F32 pixels. Larger Clouds renders still vary across reference recooks. [Root settings and variability](#draw-order-at-six-quadrant-subdivisions) + +Seventeen of the 152 earlier stamp-control sets gained a combined 2,645 exact pixels. The other 135 retained their exact counts and maxima. All 98,304 pixels in the 36-render cropped-boundary set now match. Across 1,052 isolated BNW Spots 1 draws, 820,301/820,304 F32 pixels match. In the 40-root recheck BNW Spots 1 gained 97 exact pixels in its original 34-render matrix. The other 39 retained their results. Four alternating single-worker release runs had median cook times of 198 ms for BNW Spots 1 and 179 ms for BNW Spots 3, previously 202 ms and 175 ms. + +### Draw order at six quadrant subdivisions + +BNW Spots 3 matched every final output in 118 distinct combinations of dimensions, seed, disorder and format. The preceding 27-render comparison gained 213 exact pixels. BNW Spots 1 gained 71 exact pixels in its 34-render comparison and still has differences at higher resolutions. + +| Root and distinct settings | U8 exact · max | U16 exact · max | F16 exact · max | F32 exact · max | +|---|---:|---:|---:|---:| +| BNW Spots 3, 118 | 647,936/647,936 · 0 | 943,360/943,360 · 0 | 647,936/647,936 · 0 | 920,320/920,320 · 0 | +| BNW Spots 1, 125 | 649,984/649,984 · 0 | 949,396/949,504 · 2 | 649,980/649,984 · 0.00048828125 | 928,429/928,512 · 2.16364861e−5 | + +For the 40 new settings per graph, use dimensions (16²,16×64,64×16,32×128,128×32,64²,128×256,256×128,256²,256×512,512×256,512²) and disorder (default,1,0,.953125,.0625,.71875,.328125,.53125,default,.96875,.1015625,.5). At zero-based indices 0 and 8 use seed 0, at index 1 use 42, and elsewhere use 378211+31j+11i for index j and inventory row i (57 or 58). Render U16 and F32 throughout and add U8 and F16 at indices 0,2,4,6,7,8,10,11. The totals also include the earlier settings, counting duplicates once. Both apps reopened the BNW Spots 3 save and matched the original and each other on all 2,399,232 pixels. On BNW Spots 1, the reference's original and reopened renders agreed on 2,399,216/2,399,232 pixels, with a maximum difference of two U16 levels. [Earlier settings and repeat measurements](#sibling-positions-in-subdivided-pattern-quadrants) + +A black-background F32 probe isolates the order of addition. Connect four branches to a grayscale quadrant, subdivide each to depth five or six, and put a paraboloid of size (.75,.75) on its leaves. Use zero roughness and rotation. Offset each branch's first leaf onto the center of pixel (15,15) at 32². With gains (1,2⁻²⁴,−1,0), the measured value is zero at depth five and 2⁻²⁴ at depth six. The previous implementation returned zero in both cases. Across 49 gain combinations at each depth from one through six, all 301,056 F32 pixels now match. A white-background probe distinguished all 24 branch permutations. It measured slot order 0,1,2,3 through depth five and 3,2,1,0 at six. The same change occurred with only four leaf draws. Two connected branches with two draws each at depth six gave order 2,3,0,1. MaterialCraft preserves evaluation and random-seed order and passes the completed child streams to the rasterizer in their measured order. + +Two individual U16 samples still differ inside BNW Spots 3. At 16², disorder .15625 and seed 8866, its 256² pattern stage (UID 1083436013) gives 44,702 at (118,0) and 29,396 at (236,1) in the reference. MaterialCraft gives 44,703 and 29,397. All 524,286 other pixels of that stage across eight renders match, and both differences disappear before the final output. BNW Spots 1's previously differing 32² generator pixel at (13,25), seed 0 and 128² requested, now stores 4,031. Its deeper stage remains variable. Six forced reference evaluations of the same 128×64 setting, disorder 1 and seed 372177, produced two distinct U16 images and six distinct F32 images. [Original stage and single-stamp tests](#sibling-positions-in-subdivided-pattern-quadrants) + +Giving the root its own square with a grayscale gain of −.625 over white reproduced 90,112/90,112 F32 pixels across 88 full and sparse renders. These include additive and maximum child blends. All 152 earlier stamp-control sets retained their raw results. Six of 40 intact roots gained exact pixels. The other 34 retained their exact counts and maxima. + +| Earlier matrix | Renders | Previous exact | Current exact / compared | Maximum error, U8 / U16 / F16 / F32 | +|---|---:|---:|---:|---| +| BNW Spots 1 | 34 | 204,103 | 204,174/204,288 | 0 / 2 / .00048828125 / 2.16066837e−5 | +| BNW Spots 3 | 27 | 185,643 | 185,856/185,856 | 0 / 0 / 0 / 0 | +| Clouds 1 | 17 | 145,652 | 145,655/145,664 | 0 / 4 / 0 / 5.49852848e−5 | +| Clouds 2 | 16 | 129,258 | 129,277/129,280 | 0 / 1 / 0 / 0 | +| Directional Noise | 23 | 147,600 | 147,653/147,712 | 0 / 2 / 0 / 0 | +| Dirt Gradient | 16 | 129,176 | 129,236/129,280 | 0 / 2 / 0 / 1.83582306e−5 | + +| New Clouds renders | U8 exact · max | U16 exact · max | F16 exact · max | F32 exact · max | +|---|---:|---:|---:|---:| +| Clouds 1 | 154,112/154,112 · 0 | 199,670/199,680 · 4 | 154,112/154,112 · 0 | 199,668/199,680 · .000110566616 | +| Clouds 2 | 154,112/154,112 · 0 | 199,671/199,680 · 2 | 154,111/154,112 · .000244140625 | 199,676/199,680 · 2.28881836e−5 | + +Use dimensions (16×32,32×16,32×64,64²,128×32,64×128,256×64,128×256,256²,512×128). Clouds 1 uses disorder (default,.03125,.53125,default,.875,1,.3984375,.921875,default,.671875). Clouds 2 has no exposed parameter. Use seed 0 at indices 0 and 8, seed 42 at index 1 and 382031+41j+i elsewhere, with i=78 or 79. Render U16 and F32 throughout and add U8 and F16 at indices 0,2,3,6,8,9. In the reference, original and reopened files agreed on 707,558/707,584 pixels for Clouds 1 and 707,569/707,584 for Clouds 2. Repeating the original 256² default six times also produced four distinct U16 pattern images for Clouds 1 (UID 1084449121) and five for Clouds 2 (UID 1067067866). At (23,188) Clouds 1 returned both 1,556 and 1,557. At (146,119) Clouds 2 returned both 1,373 and 1,374. Each stage produced six distinct F32 images. + +Both new regressions failed on the preceding implementation. All 299 release node tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. Four alternating single-worker release measurements gave median cook times of 196.0 to 194.1 ms for BNW Spots 1 at 64² and 174.0 to 176.5 ms for BNW Spots 3. The 16² stress graphs took 33.2 to 33.4 ms at depth seven and 524.6 to 547.3 ms at depth nine. + +### Sibling positions in subdivided pattern quadrants + +Crystal 2 matched all 5,104,128 pixels across 99 distinct combinations of dimensions, seed, warp intensity and output format. The five positions that differed at 256² now agree at every measured stage, including the U16 pattern and levels outputs and the final warp. Six other intact roots gained exact pixels. + +The first differing value in two BNW Spots 1 branches was the child position. Their exposed branch offsets matched. A sparse graph reproduces this with three quadrant nodes. Connect slot 0 of the root to the parent and offset the root by (−.25,−.25). Set the parent's offset to the position in the table. Connect its indicated slot to a square, set the square size to (4,4), the frame offset to (.5,.5) minus the parent position, and its grayscale opacity to the indicated component of `$pos`. With tiling off, seed 365809 and a 16² F32 output, read pixel (7,7). + +| Child slot | Parent position | Component | Previous F32 | Reference and current F32 | +|---:|---|---|---:|---:| +| 1 | (−.95354849, −.76964092) | x | −.828548491 | −.828548431 | +| 2 | (.400343984, .941799581) | x | .275343984 | .275344014 | +| 2 | (.111769885, −.181289986) | y | −.0562899858 | −.0562899709 | + +The upper-left position subtracts a quarter of the parent extent from each coordinate. Take a stored half-extent step right for the upper-right x. Take one half-extent step down for the bottom row and step left from that stored right x for the lower-left child. Step right again for the last child. Each operation rounds to F32. Disconnected slots still contribute their coordinate steps. The regression failed on the preceding build with `bf541bc1` in the first case. The measured result is `bf541bc0`. + +| Original sparse probes | Renders | Previous exact | Current exact / compared | Maximum F32 error before / after | +|---|---:|---:|---:|---:| +| Each child slot and coordinate at the root | 55 | 13,696 | 14,080/14,080 | 5.96046448e−8 / 0 | +| Each slot one subdivision deeper | 59 | 14,592 | 15,104/15,104 | 5.96046448e−8 / 0 | +| Seven successive subdivisions | 120 | 29,696 | 30,720/30,720 | 1.19209290e−7 / 0 | +| Five graphs across U8, U16, F16 and F32 | 60 | 29,504 | 30,720/30,720 | 1.19209290e−7 / 0 | + +For the deep probes connect one child per level. Use slot sequences 2310233, 1100311 and 0123213. At each leaf read x and y separately from `$pos`. Each path used 20 sequences of seven pairs of offsets, including all zeros and independent signed offsets. For the 18 random sequences draw x then y from a PCG64 stream seeded 358469 in path order. Draw each sequence uniformly over ±(1,.2,2,.03,5,.5,.125,8,1,4,1,.01,.01,.25,3,.5,1,2) respectively and store in F32. All 30,720 pixels in the five four-format graphs also survived a MaterialCraft save and reopen in both apps. + +| Intact root and earlier matrix | Renders | Previous exact | Current exact / compared | Maximum error U8 / U16 / F16 / F32 | +|---|---:|---:|---:|---| +| BNW Spots 1 | 34 | 201,559 | 204,103/204,288 | 0 / 2 / 0.00048828125 / 2.16364861e−05 | +| BNW Spots 3 | 27 | 184,346 | 185,643/185,856 | 0 / 1 / 0.00048828125 / 1.53183937e−05 | +| Clouds 1 | 17 | 145,634 | 145,652/145,664 | 0 / 4 / 0 / 5.49852848e−05 | +| Clouds 2 | 16 | 129,223 | 129,258/129,280 | 0 / 2 / 0 / 0 | +| Directional Noise | 23 | 147,080 | 147,600/147,712 | 0 / 2 / 0 / 0 | +| Dirt Gradient | 16 | 129,046 | 129,176/129,280 | 0 / 2 / 0 / 1.83582306e−05 | + +The other 34 intact roots retained their earlier counts and maxima. All 152 existing stamp-control sets retained their raw comparison results. Cells 1 retained all 2,975,232 pixels in its 89-setting matrix. + +| New or expanded root matrix | Renders | U8 exact · max | U16 exact · max | F16 exact · max | F32 exact · max | +|---|---:|---:|---:|---:|---:| +| Crystal 2, union of distinct settings | 99 | 964,096/964,096 · 0 | 1,632,256/1,632,256 · 0 | 964,096/964,096 · 0 | 1,543,680/1,543,680 · 0 | +| BNW Spots 1, larger settings | 32 | 94,720/94,720 · 0 | 169,388/169,472 · 2 | 94,720/94,720 · 0 | 169,396/169,472 · 2.16364861e−05 | +| BNW Spots 3, larger settings | 32 | 94,720/94,720 · 0 | 169,169/169,472 · 1 | 94,712/94,720 · 0.00048828125 | 169,128/169,472 · 1.53183937e−05 | + +For Crystal 2 repeat the [previous 40 settings and earlier root matrices](#interpolation-across-pairs-of-pixels-in-cells-1). The next ten (width×height, intensity, seed) triples are (128²,61.75,365075), (256²,60.5,365075), (256²,61.75,365076), (256²,63.75,42), (128×256,61.75,365075), (256×128,.0625,368003), (256×512,47.25,368131), (512×256,22.5,368173), (512²,61.75,365075) and (64×128,7.125,0). Use U16 and F32 throughout. Add U8 and F16 at zero-based indices 0,2,4,5,7,8. The two saved matrices reproduced 2,214,912/2,214,912 and 2,703,360/2,703,360 pixels within each app. + +For the 32 larger spots renders choose (16×32,32²,64×32,32×64,64×128,128×64,128²,256×128,128×256,256²) with disorder (default,.03125,.5625,.875,0,1,.7421875,.5,.203125,.96875). Use seeds 0 and 42 at indices 0 and 1. At index j≥2 use 366001+103i+61j with root index i=57 or 58. Render U16 and F32 at every size. Add U8 and F16 at indices 0,2,3,4,6,9. In the [earlier eight BNW Spots 1 settings](#isolating-the-generators-in-spots-bricks-and-cells), all nine recorded stages now agree. All 113,664 pixels also match on the separate 24-render BNW Spots 1 matrix. On the larger matrix MaterialCraft reopened both saved roots with 528,384/528,384 identical pixels per file. The reference reproduced the BNW Spots 3 save exactly. For BNW Spots 1 it reproduced 528,375/528,384 on the first comparison. Alternating the 128×64 U16 and 256² F16 settings eight times for each file produced both observed outputs on **each** file. The U16 variants differed at eight pixels by up to two levels and the F16 variants at one by .000244140625. + +A reproducible BNW Spots 1 discrepancy remains with defaults, seed 0 and a 128² output. At (13,25) its 32² pattern generator stores U16 4,031 in the reference and 4,030 in MaterialCraft. Render its four contributing paraboloids individually in F32, at full gain .061428577 and with both tiling axes enabled. Their values agree at that pixel (.0110335825,.00197766931,.00639200816,.0420982391). The complete standalone renders match 4,096/4,096 pixels. Six forced reference re-cooks of the generator each gave .06150150299. Another setting at 128×64, disorder 1 and seed 372177 gave both 12,725 and 12,726 for the U16 stage at (32,22). Both spots roots remain open. + +Four alternating single-worker release measurements at 64² gave medians of 296.9 to 285.5 ms for BNW Spots 1 and 251.1 to 245.4 ms for BNW Spots 3. The depth-seven and depth-nine four-way stress graphs at 16² went from 49.3 to 49.6 ms and from 781.8 to 779.8 ms. All 297 release node tests, formatting, strict workspace Clippy, dependency layers and WebAssembly checks passed. + +### Interpolation across pairs of pixels in Cells 1 + +The last differing Cells 1 sample came from a white paraboloid at (1,52) on a 64×128 image. Given the same three vertices, an independently drawn triangle reproduced the reference’s two signed F32 coordinates, .3740799427 and .2336531430. The previous CPU result was .3740799129 for the first coordinate. The pattern output stored `3f4e334f` in the reference and `3f4e3350` in MaterialCraft. Reuse the [single stamp, resolution and seed](#bounds-and-pixel-coordinates-of-rotated-pattern-stamps). Its pixels (1,48), (1,52) and (5,52) now store `3ecb3c42`, `3f4e334f` and `3ee8375a` in both apps. + +An original right triangle isolates the interpolation step. Give its vertices screen coordinates (0,0), (1024,0) and (0,1024) with clip W=1. Assign a scalar attribute A, A+1024g and A+1024h. Select integer x and y from 0 through 15, set A to F32(−g(x+.5)−h(y+.5)), and store the three attributes as F32 before drawing. This puts the sample near zero and exposes low bits that would disappear on conversion to the output format. In 6,240 signed samples with gradient exponent differences from 0 through 12, the new calculation matched 6,240/6,240, maximum error zero. On three independent sets with other starting values and translated triangles, all 819,200, 819,200 and 652,280 measured coordinate components matched the device. Across a further 77,822 components from stamp triangles, 77,821 matched, maximum 1.90734863e−6. + +The opposite half-steps of a two-pixel pair use a common precision. Taking one ULP of the larger gradient as U, truncate each signed gradient to multiples of U/4 for the half-step from the pair midpoint. Store the accumulated sample on a grid of U/64 before conversion to F32. A second regression checks the shallow horizontal ramp at (8,31) on a 32×64 image. Use center (.415625,.48046875), size (.38671875,.25), rotation .0002734375 turns, tiling off and seed 360680. The reference stores `3de5bb68`. Both regressions failed on the preceding build. + +| F32 stamp comparison | Renders | Previous exact | Current exact / pixels | Maximum error now | +|---|---:|---:|---:|---:| +| Translated ramp | 210 | 860,128 | 860,160/860,160 | 0 | +| Translated paraboloid | 210 | 860,071 | 860,160/860,160 | 0 | +| Extended-turn ramp | 99 | 337,757 | 337,920/337,920 | 0 | +| Extended-turn paraboloid | 99 | 337,743 | 337,920/337,920 | 0 | +| Pyramid at ordinary angles | 30 | 159,717 | 159,744/159,744 | 0 | +| Rotated subpixel ramp | 220 | 309,757 | 309,759/309,760 | 9.53674316e−07 | +| Rotated subpixel paraboloid | 220 | 309,749 | 309,759/309,760 | 2.98023224e−06 | +| Individual draws from BNW Spots 1 | 1,052 | 820,191 | 820,249/820,304 | 1.67638063e−07 | + +The rotated subpixel ramp and paraboloid each have one differing pixel. Both use the 16×32 placement, the first pair of subpixel extents and .3305 turns. In a separate angular sweep, use turns (.0001220703125,.0002734375,−.0007453125,.00128125,.00390625,.01607,.2499,.5003,−1.0001,−.74934,1.50014,.43065130710601807,.1171875). At zero-based angle i and size j, select (32×64,64×32,64²,128×64)[j] and seed 360607+73i+j. Center the stamp at (.415625+.03125j, .53125−.05078125(i mod 3)). Set the width to .375+.01171875(i mod 5), negated at j=2, and the height to .25+.046875j. Across the 52 geometries all 212,992 pixels matched for each of square, horizontal ramp, paraboloid and pyramid. The previous exact counts were 212,992, 212,868, 212,811 and 212,819 respectively. [Translated, extended-turn and subpixel settings](#bounds-and-pixel-coordinates-of-rotated-pattern-stamps) + +| Intact root, distinct settings | Renders | U8 exact · max | U16 exact · max | F16 exact · max | F32 exact · max | +|---|---:|---:|---:|---:|---:| +| Cells 1, union of original settings | 89 | 615,168/615,168 · 0 | 916,736/916,736 · 0 | 615,168/615,168 · 0 | 828,160/828,160 · 0 | +| Crystal 2, new settings | 40 | 414,208/414,208 · 0 | 693,243/693,248 · 1 | 414,208/414,208 · 0 | 693,243/693,248 · 1.52587891e−05 | + +Cells 1 matches all 2,975,232 pixels in 89 distinct combinations of dimensions, seed, exposed values and output format. The 42-render expansion uses (16²,32²,64×128,128×64,128²,256×128,128×256,256²,512×256,256×512,512²,256²). Use (distance, disorder) = (default), (1,0), (23,21.875), (7,51.5625), (16,37.5), (3,2.34375), (11,71.875), (19,93.75), (9,12.5), (29,100), (default), (default). The seeds at j=0,2,10,11 are 0,350314,0,42. Elsewhere use 361003+41j. Render U16/F32 at every size and add U8/F16 at j=0,1,2,5,6,7,9,10,11. MaterialCraft saves of this matrix and the preceding 24-render matrix reopened in both apps and retained all 2,708,480 and 113,664 pixels respectively. [Earlier Cells 1 matrices and parameter controls](#bounds-and-pixel-coordinates-of-rotated-pattern-stamps) + +Crystal 2 improved from 145,662 to 145,664/145,664 on 17 earlier renders and matches 40,192/40,192 on ten additional historical settings. It remains in progress. For the 40 new settings use dimensions (16×32,32×16,64²,128×64,64×128,128²,256×128,128×256,256²,512²,512×256,256×512) and warp intensities (default,0,1.25,3.4375,9.625,13.875,27.75,42.5,61.75,default,31,.125). Defaults use seed 0. Use seed 42 at j=1 and 364651+53j elsewhere. Render all four formats at j=0,2,3,4,6,7,8,9 and U16/F32 elsewhere. At 256², intensity 61.75 and seed 365075, three of the 65,536 U16 pattern samples differ by one level. At (108,73) the pattern stage stores 34,666 against 34,665, then levels stores 28,192 against 28,191. The warp spreads the three differences to five output pixels. All 2,214,912 pixels in the root’s MaterialCraft save reproduce the original within each app. + +The other 39 rechecked intact roots retained their counts and maximum errors on their earlier matrices. Across eight saved graphs, all 5,420,032 pixels matched the corresponding originals after reopening in each app. The extended-angle ramp that previously differed on 19 saved-file samples now matches all 49,152 cross-app samples. The two spots roots retain their outstanding differences in the intact graphs. + +In four alternating single-worker release runs at 64², median cook times for BNW Spots 1 and BNW Spots 3 went from 186.2 to 211.4 ms and from 150.9 to 176.9 ms. On the 16² four-way stress graph, depth seven went from 33.2 to 33.5 ms and depth nine from 527.0 to 548.5 ms. All 296 release node tests, formatting, strict workspace Clippy, layers and WebAssembly passed. + +### Bounds and pixel coordinates of rotated pattern stamps + +A white square, horizontal ramp and paraboloid distinguish the bounding rectangle of a stamp from its coordinate rotation. Translating both the stamp and its render window by an integer preserves their relative positions and exposes rounding when the corners are stored. The measured bounds use the uniform sine and cosine of the original rotation in turns. Each vertex retains its snapping displacement in pattern space. The two signed coordinates use the pixel rotation of the angle in radians and the original stamp dimensions. A rotated stamp narrower than one pixel still interpolates across the padded triangle. MaterialCraft now uses these coordinates for drawing and for culling repeated subpixel stamps. + +Render a white stamp of size (.25,.25) against black at 64² with tiling off, at zero variation and unit opacity. Center the stamp at (128.4375,.4375), use .125 turns and render the window (128,129,0,1). The horizontal ramp at (17,27) stores F32 bits `3c62f8c0`. At (1024.4375,1024.4375), .0625 turns and window (1024,1025,1024,1025), the paraboloid at (23,21) stores `3cc0e9a0`. For a subpixel reproduction, use the unit window at 64×32, center (.5860138,.5777588), size (1/2048,1/512), .125 turns and seed 332332. At (37,18) the ramp stores `3f6b7e10` and the paraboloid `3e44b5b0`. Both regression tests failed on the preceding release build. + +| F32 comparison | Renders | Previous exact | Current exact / pixels | Previous maximum error | Current maximum error | +|---|---:|---:|---:|---:|---:| +| Translated square | 210 | 860,086 | 860,160/860,160 | 1 | 0 | +| Translated horizontal ramp | 210 | 818,202 | 860,128/860,160 | 0.999963701 | 5.96046448e−08 | +| Translated paraboloid | 210 | 824,830 | 860,071/860,160 | 0.0643066764 | 1.1920929e−07 | +| Extended-turn horizontal ramp | 99 | 321,658 | 337,757/337,920 | 0.000248193741 | 5.96046448e−08 | +| Extended-turn paraboloid | 99 | 324,170 | 337,743/337,920 | 0.000876843929 | 1.1920929e−07 | +| Rotated subpixel square | 220 | 309,760 | 309,760/309,760 | 0 | 0 | +| Rotated subpixel ramp | 220 | 309,560 | 309,757/309,760 | 4.76837158e−05 | 9.53674316e−07 | +| Rotated subpixel paraboloid | 220 | 309,628 | 309,749/309,760 | 0.000161468983 | 2.98023224e−06 | +| Individual draws from BNW Spots 1 | 1,052 | 805,230 | 820,191/820,304 | 8.36327672e−07 | 1.67638063e−07 | + +For the translated series, draw in unit-size 64² windows starting at (0,0), (.5,0), (1,0), (0,−1), (−2,2), (4,0), (0,4), (16,16), (128,0), (0,128), (−128,128), (1024,1024), (16384,0), (0,−16384) and (65536,65536). Add either (28,28)/64 or (27.375,23.625)/64 to the window origin. Use corresponding sizes (16,16)/64 and (16.875,13.375)/64. For each angle in (.125,−.125,.0625,.21875,.3305,.04073,278.50824) draw the two geometries in that order. The seed is 337107+41i+j for zero-based window i and draw j. + +The extended series uses 33 angles in each of three unit windows with origins (0,0), (128,0) and (1024,−32). The first eight angles are .125, .04073, 278.50824, 1.5, 4096.25, .3305, 65535.25 and −1024.75 turns. The remaining angles have the following F32 bit patterns, in order. + +`3f33fb3e c038fb77 c0545a49 c04d4960 407fe89a c1438ef8 41c3281c c1c889c9 41d9b04b 41ffdea6 434ace4b c3bb0f0c 43fb49fb c3d59add c3e40003 c57e64bf c5ac2320 c5d84f6c c5c40e47 c5dd2600 474ae86f c76a5182 47eaef36 47a88f06 47c11be1` + +For zero-based angle j, cycle 32×64, 64² and 128×32. Add (.4375+.02075(j mod 4), .453125+.0375(j mod 3)) to the window origin. Use width .19+.014(j mod 5), negated when j mod 5 = 4, and height .315−.027(j mod 4). The seed is 341771+71i+j. The subpixel sweep uses the 11 extents and four placements described below with five nonzero angles per placement. [Subpixel sizes and placements](#drawing-axis-aligned-stamps-smaller-than-one-pixel) + +An independently drawn Direct3D 11 triangle with these vertex coordinates reproduced every reference pixel in a separate 30-render control, 159,744/159,744 for each of square, ramp, paraboloid and pyramid with zero maximum error. With identical vertices, the CPU matched 159,744, 159,724, 159,715 and 159,717 respectively. The largest CPU error was zero for coverage, 5.96046448e−8 for ramp and pyramid, and 1.19209290e−7 for paraboloid. Interpolation of the signed coordinates remains measurable after the change to the bounds. + +| Intact root | Renders | Previous exact | Current exact / pixels | Maximum U8 / U16 / F16 / F32 | +|---|---:|---:|---:|---| +| BNW Spots 1 | 34 | 197,377 | 201,559/204,288 | 0 / 3 / 0.00048828125 / 4.30941582e−05 | +| BNW Spots 3 | 27 | 180,975 | 184,346/185,856 | 0 / 2 / 0.00048828125 / 2.7179718e−05 | +| Cells 1 | 17 | 145,267 | 145,664/145,664 | 0 / 0 / 0 / 0 | +| Clouds 1 | 17 | 144,225 | 145,634/145,664 | 0 / 4 / 0 / 5.49852848e−05 | +| Clouds 2 | 16 | 128,440 | 129,223/129,280 | 0 / 2 / 0.00048828125 / 2.29477882e−05 | +| Creased | 17 | 145,105 | 145,541/145,664 | 0 / 19 / 0 / 0 | +| Crystal 2 | 17 | 145,213 | 145,662/145,664 | 0 / 1 / 0 / 1.52587891e−05 | + +The other 33 rechecked roots retained their exact counts and maxima. The three roots below also ran on new cases. Use sizes (16×32,32×16,32×64,64×32,64²,128×64,64×128,128²) in order. At size index j=0 use the defaults and seed 0. At j=1 use seed 42. Thereafter the seed is 342557+113r+31j, where r is 57, 58 or 67 in inventory order, counting from zero. For the spots roots use disorders (default,0,.1875,.6875,.421875,.984375,.21875,.36). For Cells 1 multiply each changed disorder by 100 and use distances (default,1,5,7,13,19,23,16). Render the even-indexed sizes in all four formats and the odd-indexed sizes in U16 and F32. + +| Intact root, 24 new renders each | U8 exact · max | U16 exact · max | F16 exact · max | F32 exact · max | +|---|---:|---:|---:|---:| +| BNW Spots 1 | 14,848/14,848 · 0 | 41,770/41,984 · 2 | 14,841/14,848 · 0.00048828125 | 41,770/41,984 · 2.16364861e−05 | +| BNW Spots 3 | 14,848/14,848 · 0 | 41,859/41,984 · 1 | 14,847/14,848 · 0.000244140625 | 41,831/41,984 · 1.53779984e−05 | +| Cells 1 | 14,848/14,848 · 0 | 41,983/41,984 · 3 | 14,848/14,848 · 0 | 41,983/41,984 · 3.67164612e−05 | + +Cells 1 remains in progress. At the 64×128 setting with seed 350314, distance 23 and disorder 21.875, the only differing position is (1,52). The pattern map stores 52,787 against 52,786 in the reference. Levels produces 34,868 against 34,865 in U16. A single white paraboloid isolates the maximum at that pixel. Use center (.046721816,.41302496), size (.10638297,.10638297), .4306513 turns, tiling on and unit opacity. The F32 values are .8054704666 and .8054704070 respectively. All other candidate draws at this position were smaller. + +All six MaterialCraft saves reopened in both apps. Within each app all 496,640 pixels matched the corresponding originals, maximum zero. This includes the 72 intact-root renders and 60 independent stamp renders. The three independent inputs were five translated ramps, five subpixel paraboloids and five extended-angle ramps in all four formats. Between apps the first two sets matched all 81,920 and 24,576 pixels respectively. The extended ramps matched 12,288/12,288 U8, 12,287/12,288 U16 (maximum one), 12,288/12,288 F16 and 12,270/12,288 F32 (maximum 5.96046448e−8) on the originals and saves. + +The default 32² BNW Spots 1 root has two exact pattern maps, 64/64 and 4,096/4,096 U16 pixels. The third matches 255/256. At (7,7) it stores 9,686 against 9,685 in the reference. Summing the four contributing independently rendered reference stamps gives .1477923244, while measuring the original reference pattern stage directly in F32 gives .1477918327. All eight separately forced re-cooks reproduce the U16 result at every pixel. In the 16² root the corresponding 8² pattern map differs at (7,5), with 5,870 against 5,869. All permutations of the three individual reference contributions still store 5,870. The source of that discrepancy is open. + +For Dirt 3, a separate 32-render whole-root matrix matched 86,528/86,528 in U8 and F16, 237,055/237,056 in U16 (maximum one), and 237,055/237,056 in F32 (maximum 1.52587891e−5), on the original and its MaterialCraft save. At 128² and seed 42, (85,0), three isolated pyramid contributions agree in both apps at F32 bits `3e6302db`, `3db28155` and `3d6b5fe4`. The local pattern accumulator stores `3ebb8dc0` and ten forced reference re-cooks each store `3ebb8dbf` there. Across the complete 128² F32 stage, 16,266 to 16,309 pixels match across the ten comparisons, maximum 1.19209290e−7. A separate three-branch graph tests all six draw orders at seven tile placements. All 688,128 F32 pixels match. This leaves the order of overlapping draws in the intact graph unresolved. [Original Dirt 3 accumulation case](#drawing-axis-aligned-stamps-smaller-than-one-pixel) + +On four alternating single-worker release runs, median cook times at 64² went from 173.4 to 188.1 ms for BNW Spots 1 and from 146.7 to 149.8 ms for BNW Spots 3. The 16² four-way stress graph took 34.8 ms at depth seven and 555.9 ms at depth nine, previously 32.6 and 520.3 ms. All 294 release node tests, formatting, strict workspace Clippy, layers and WebAssembly passed. + +### Drawing axis-aligned stamps smaller than one pixel + +At zero rotation a narrow ramp still interpolates across the padded triangle. Sampling its continuous shape at the pixel center gave a different F32 result. In a repeated draw, a test against the continuous rectangle could also discard an entire stamp. MaterialCraft now clips these small axis-aligned stamps against the interpolated coordinates during traversal and drawing. + +For a minimal reproduction, use a black 64×32 graph with tiling off. Center a white stamp at (.5860138,.5777588), set the size to (1/2048,1/512), use zero rotation and variation, and set seed 332208. At (37,18), the horizontal ramp stores F32 bits `3eb00002` and the paraboloid stores `3f430001`. On a black 64² graph, draw a white additive square twice at (.0037426655,.5234375), size (.008139668,.01171875), seed 307023. At (0,33) the accumulator stores 2. Both Rust regression tests exercise the normal graph cook and failed before the fix. + +| F32 control | Renders | Previous exact | Current exact / pixels | Previous maximum | Current maximum | +|---|---:|---:|---:|---:|---:| +| Unrotated square | 44 | 61,952 | 61,952/61,952 | 0 | 0 | +| Unrotated horizontal ramp | 44 | 61,915 | 61,952/61,952 | 5.66244125e−7 | 0 | +| Unrotated paraboloid | 44 | 61,916 | 61,952/61,952 | 6.07967377e−6 | 0 | +| Quarter-turn multiples, square | 144 | 417,776 | 417,791/417,792 | 1 | 1 | +| Quarter-turn multiples, horizontal ramp | 144 | 417,602 | 417,782/417,792 | .999998569 | .205678016 | +| Quarter-turn multiples, paraboloid | 144 | 417,698 | 417,780/417,792 | .0000569820404 | .00000107288361 | +| First-column square, tiling off | 48 | 196,597 | 196,601/196,608 | 1 | 1 | +| First-column square, horizontal tiling on | 48 | 196,608 | 196,608/196,608 | 0 | 0 | +| First-column ramps of either sign and paraboloids, both tiling settings | 288 | 1,179,539 | 1,179,549/1,179,648 | 1 | 1 | + +For the 44 unrotated geometries, the sequence of pixel extents is (.03125,.0625), (.125,.09375), (.265625,.4375), (.8125,.375), (.96875,.4375), (1,.6875), (1.03125,.625), (.375,1.25), (1.5,1.25), (.59375,2.375) and (2.375,.40625). For each extent (w,h), use the four rows below. Starting at the center of the indicated pixel, add (dx×w,dy×h) pixels and normalize by the output dimensions. Normalize the stamp size by the same dimensions. For extent index i and row j, both starting at zero, use seed 332177+31(24i+j). + +| Output | Pixel | dx, dy | Width sign | +|---|---|---|---:| +| 32² | (13,15) | 0, 0 | + | +| 64×32 | (37,18) | .15625, −.1875 | + | +| 16×32 | (6,19) | −.34375, .2578125 | − | +| 32×64 | (12,42) | .40625, .09375 | + | + +The quarter-turn series includes signed widths and heights, draws on half-pixel edges, and adjacent F32 center values on six rectangular or square outputs from 16×32 to 128×64. It uses turns 0, .25, .5, −.25, .75, 1, −.5 and −1. All errors in this series occur in the render window (−.173,.369,.096,.869). The unit window and (−.375,1.125,.125,.875) each match all 417,792 sampled pixels. Across 220 oblique geometries, the square still matches 309,760/309,760, the ramp 309,560/309,760 (maximum .0000476837158), and the paraboloid 309,628/309,760 (maximum .000161468983). A separate Direct3D 11 triangle given MaterialCraft’s vertices agrees with its CPU square, ramp and paraboloid for all 3,798,528 pixels across 380 axis-aligned geometries. Differences from the reference remain at the stamp edges. + +A two-draw test covers seven square placements, six ramps and six paraboloids in each of U8, U16, F16 and F32. For each format 47,100/47,104 pixels match. The four differences occur on squares, with maxima of 255, 65,535, 2 and 2 respectively. Four graphs saved by MaterialCraft reopen in both apps. Within each app all 337,920 original and reopened pixels agree over 100 renders, including 84,480 in each format. Between apps, original and reopened files both give 84,476/84,480 exact in U8, U16 and F16, and 84,475/84,480 in F32. [First-column placements](#tiling-axes-and-pattern-copy-bounds) + +| Intact root | Renders | Previous exact | Current exact / pixels | Maximum U8 / U16 / F16 / F32 | +|---|---:|---:|---:|---| +| Directional Noise | 23 | 146,950 | 147,080/147,712 | 1 / 3 / .00048828125 / .0000336766243 | +| Dirt 3 | 17 | 145,627 | 145,663/145,664 | 0 / 1 / 0 / 0 | +| Dirt 6 | 16 | 126,304 | 129,249/129,280 | 0 / 5 / 0 / 0 | +| Dirt Gradient | 16 | 129,026 | 129,046/129,280 | 0 / 2 / 0 / .0000183582306 | + +The other 36 rechecked roots keep their recorded exact counts and maximum errors, including BNW Spots 1 at 197,377/204,288 and BNW Spots 3 at 180,975/185,856. On the 128² seed-42 Dirt 3 graph, the pattern stage stores 24,007 at (85,0) against 24,006 in the reference. The transformation matches 16,384/16,384 pixels. The final U16 blend stores 39,714 against 39,713. [Generator settings and earlier intact-root comparisons](#rotated-stamp-coordinates-in-gradient-linear-1-and-bnw-spots) + +In four alternating single-worker release runs, median 64² cook time for Spots 1 went from 169.7 to 173.8 ms, and Spots 3 from 147.7 to 149.3 ms. An original four-way square graph at 16² took 32.7 ms at depth seven and 516.4 ms at depth nine, previously 32.3 and 530.8 ms. Both versions produced the same 2,560 pixels at 16² and 32². The reference failed to compute the depth-seven stress graph and the depth-nine run was interrupted after ten minutes without a result. These timing fixtures have no cross-app pixel measurement. + +### Tiled draws in cropped windows and quarter-turn bounds + +A tiled stamp starts at the outermost copy in the tiling window, including when that copy is outside the render window. Its position is stored in F32, then each successive copy subtracts the F32 period. In the fractional-window controls, adding ten independently rendered, unwrapped copies at those centers reproduces all 16,384 reference pixels of eight tiled horizontal and vertical ramps. Four settings use trials 24, 28, 48 and 64 in the earlier D/E window. [Window definitions and trial sequence](#projecting-stamp-vertices-through-shifted-render-regions) + +For a single horizontal ramp, use both tiling axes, frame offset (.064685315,.20525344), size (.5799769,.4007881), zero rotation and additive blending. Use a 32×64 render window D and tiling window E. Pixel (29,0) is F32 `3f73a212`. Starting at the outermost visible copy gives `3f73a216`. With horizontal tiling only, use a 128×32 render window (−9.979,−9.558,.096,.869), the same E, center (−.9356832,.3353525) and size (33.7824,.8661607). Pixel (6,0) is `41607c0c`. The implementation can skip invisible copies in a run of equally spaced floats. At an exponent boundary it takes an individual subtraction to retain the rounding of the next center. + +At an exact multiple of a quarter turn the draw rectangle is axis-aligned. The stored sampling angle can still have a residual sine or cosine. Draw an unwrapped white square on a black 64² output with branch offset (−.5,−.5) and frame offset (.533203125,.3779296875). At 1.5 turns use size (.517578125,.271484375). Pixel (37,15) is black and (37,16) is white. Swapping the size components gives the same two rows at x=27 for −17.75 turns and at x=42 for 4096.25 turns. Both the cropped ramp and the quarter-turn regressions fail on the preceding cooker. + +| Grayscale F32 controls | Renders | Exact pixels before | Exact pixels after / compared | Maximum error before | Maximum error after | +|---|---:|---:|---:|---:|---:| +| Original render and tiling windows | 504 | 1,374,592 | 1,374,592/1,376,256 | 2.38418579e-07 | 2.38418579e-07 | +| Fractional centers and windows | 210 | 573,249 | 575,479/577,536 | 2.38418579e-07 | 1.78813934e-07 | +| Displaced render windows | 45 | 85,610 | 101,216/101,376 | 1.43051147e-05 | 2.38418579e-07 | +| Tile stamp placements | 192 | 589,824 | 589,824/589,824 | 0 | 0 | +| Square at exact quarter turns | 108 | 294,452 | 294,912/294,912 | 1 | 0 | +| Ramp at exact quarter turns | 108 | 284,832 | 293,605/294,912 | 1 | 1.78813934e-07 | +| Square across extended turns | 135 | 367,402 | 368,640/368,640 | 1 | 0 | +| Ramp across extended turns | 135 | 321,277 | 364,604/368,640 | 1 | 2.38418579e-07 | +| Square immediately beside 1.5 turns | 18 | 49,150 | 49,150/49,152 | 1 | 1 | +| Ramp immediately beside 1.5 turns | 18 | 49,107 | 49,107/49,152 | 0.609433711 | 0.609433711 | +| Earlier five geometries, square | 45 | 239,604 | 239,616/239,616 | 1 | 0 | +| Earlier five geometries, ramp | 45 | 237,038 | 237,064/239,616 | 0.408296943 | 1.1920929e-07 | +| Earlier five geometries, paraboloid | 45 | 236,980 | 237,006/239,616 | 5.96046448e-07 | 5.96046448e-07 | +| Earlier five geometries, pyramid | 45 | 237,007 | 237,041/239,616 | 3.57627869e-07 | 3.57627869e-07 | + +For the 45 displaced-window cases use E as the tiling window, horizontal tiling only, and zero rotation. With period p=.631−.019, set the render window to (.019+dp−.206,.019+dp+.215,.096,.869). Use d=−.5, −1, −2, −4, −8, −16, .25, 1.75 and 5.25, in that order. At each d use five outputs in order, 32×16, 64×32, 16×32, 64² and 128×32. Starting from PCG64 seed 329457, draw each center x from [−2,1), center y from [.25,.6) and stamp height from [.5,1.25). Stamp width is max(.62,1.15|d|p) × (1+.5j) for size index j from zero. The graph seed is 329457+53i+j for shift index i from zero. The remaining 160 differences all occur in the 64×32 case at d=−16. + +For the quarter-turn controls, set the screen-aligned size in pixels and place the indicated edge at a half-pixel using the table. The center on that axis is the edge plus half the screen-aligned size. Normalize each component by the output dimension, then swap the two normalized stamp sizes at odd quarter turns. For each geometry use its edge-axis center rounded to F32 and the immediately smaller and larger F32 values, in increasing order. Use a white square or horizontal ramp, unit opacity and zero variation, with tiling off. + +| Output | Screen-aligned size | Placed edge | Center on the other axis | +|---|---|---|---:| +| 32×64 | 28.625 × 41.75 | y=8.5 | x=13.875 | +| 64×32 | 41.75 × 28.625 | x=6.5 | y=15.375 | +| 64² | 33.125 × 17.375 | y=15.5 | x=34.125 | + +For the first bank use turns .5, 1.5, −1.5, 2.5, −2.5, 1, −2, .25, .75, 1.25, 1.75, −1.75, 1.5−2⁻²³ and 1.5+2⁻²³. The last two angles account for the two remaining square-mask differences. For the extended bank use .25, 1.5, −1.75, 3.25, −17.75, 17.5, −127.5, 128.25, 511.75, −512, 4096.25, −4096.5, 32768.25, −32768.75 and 65536.5. In each bank use seed 323339+j for zero-based render index j in angle, geometry, center order. [Earlier five-geometry and thin-ramp settings](#rotated-stamp-coordinates-in-gradient-linear-1-and-bnw-spots) + +For the saved-file comparison use the five d=−16 ramps and extended-bank indices 9, 16, 43, 97 and 130 for both the square and ramp. Render each in U8, U16, F16 and F32, then reopen the three MaterialCraft saves in both apps. Each app reproduced all 176,128 of its own original pixels across the 60 reopened settings. The raw comparisons between apps give the same counts before and after saving. + +| Saved settings | Exact U8 | Exact U16 | Exact F16 | Exact F32 | Maximum F32 error | +|---|---:|---:|---:|---:|---:| +| Displaced ramp | 11,264/11,264 | 11,264/11,264 | 11,264/11,264 | 11,104/11,264 | 2.38418579e-07 | +| Quarter-turn square | 16,384/16,384 | 16,384/16,384 | 16,384/16,384 | 16,384/16,384 | 0 | +| Quarter-turn ramp | 16,384/16,384 | 16,384/16,384 | 16,384/16,384 | 16,373/16,384 | 5.96046448e-08 | + +The maximum U8, U16 and F16 errors in the saved settings are zero. The 108 additional noncardinal square controls match 619,520/619,520 pixels. At the same settings the horizontal ramps match 546,778/619,520 (maximum 3.57627869e−7) and the paraboloids match 552,416/619,520 (maximum 1.13248825e−6). The 140 thin ramps retain 161,784/161,792 U16 pixels and 645,506/647,168 F32 pixels, with maxima of one level and 5.96046448e−8. + +BNW Spots 1 still matches 197,377/204,288 pixels in 34 intact renders and BNW Spots 3 matches 180,975/185,856 in 27. Their U16 maxima are 3 and 2 levels, and their F32 maxima are .0000431537628 and .0000305175781. The two Tile helpers and Gradient Linear 1 remain exact in their four-format and saved-file controls. The exact counts and maximum errors agree with the preceding measurements for all 40 intact guard roots. Four alternating single-worker release measurements per version gave median times of 173.3 to 171.4 ms for 64² Spots 1, 147.1 to 147.7 ms for 64² Spots 3, 4.5 to 4.5 ms for the 128×32 d=−16 ramp. The Spots settings used disorder .84375 and seeds 8855 and 8868 respectively. + +### Circular stamp coverage and zero stamp opacity + +A circular stamp preserves its background outside the unit disc. Samples exactly on the circumference still enter the blend, including a zero-valued sample. On a 64² F32 canvas, draw a white stamp centered at (32.5,32.5) pixels with size (32,32) pixels and maximum blending over −.25. At (20,20) a disc, paraboloid and bell each leave −.25. At (48,32) their values are 1, 0 and 0. A fully attenuated horizontal ramp and the capsule both write zero at (20,20). The circular selectors are 3–7, 11–14, 16 and 18. + +Authored opacity is tested after flushing subnormal values and before multiplying by graph opacity. With zero authored opacity all built-in selectors except the horizontal offset ramp preserve the background. The horizontal offset ramp still contributes its variation. At graph opacity zero, a hemisphere with nonzero authored opacity still contributes its variation inside the disc. For variation .25 over gray −.25 and maximum blending the center pixel is .25 at graph opacity zero and −.25 at authored opacity zero. The smallest normal F32 value and two signed subnormal values distinguish the two stages. [Earlier opacity and accumulator controls](#pattern-opacity-near-zero-and-color-accumulation) + +| F32 comparison | Renders | Previously exact | Now exact / compared | Maximum absolute error | +|---|---:|---:|---:|---:| +| Grayscale selectors and blend modes | 312 | 770,731 | 877,555/878,592 | 5.960464477539063e-08 | +| All selectors on signed backgrounds | 84 | 263,102 | 302,307/311,808 | 3.0994415283203125e-06 | +| Gray swatches and global gain | 204 | 655,067 | 833,852/835,584 | 5.960464477539063e-08 | +| RGBA swatches and global gain | 204 | 826,976 | 834,227/835,584 | 1.1920928955078125e-07 | +| Linked scalar and vector, gray | 56 | 35,520 | 57,344/57,344 | 0 | +| Linked scalar and vector, RGBA | 56 | 52,472 | 57,344/57,344 | 0 | + +For the 312 selector and blend controls use a single unwrapped stamp over −.25. In order, use these (output, normalized center, normalized size, turns) settings. + +| Index | Output | Center | Size | Turns | +|---:|---|---|---|---:| +| 0 | 64² | .5, .5 | 1, 1 | 0 | +| 1 | 64² | 32.5/64, 32.5/64 | .5, .5 | 0 | +| 2 | 32×64 | 15.5/32, 28.5/64 | .75, .5 | 0 | +| 3 | 64×32 | 28.5/64, 15.5/32 | .5, .75 | .25 | +| 4 | 64² | .5, .5 | 1, 1 | .125 | +| 5 | 32×16 | .4375, .375 | 1.25, .75 | .5 | + +First use selectors (3,4,5,6,7,11,12,13,14,16,18) with variation .25, white tint and mode 1. Then use (9,10,12,14,15) with variation 1 and the same tint and mode. Finally use (2,5,17,18) with variation .25, grayscale tints (0,−.125,.0001) and blend modes (0,1,2) in that order, with mode varying fastest. Set the seed to 322193 + 31 × geometry index + control index, starting both at zero. The 72 zero-tint renders match 202,752/202,752 pixels. + +For the 84-render selector comparison use the negative-background, maximum-blend bell geometries 0, 1, 4 and 5 (seeds 316166, 316203, 316314 and 316351). Use all 17 selectors with white tint and variation .25, selectors 2, 3 and 5 with black tint and variation .25, and selector 10 with white tint and variation 1. [Bell geometries](#image-inputs-and-bell-stamps-in-brick-generator-tile) + +For the two 204-render swatch matrices, use every selector from 2 through 18, variation .25, mode 1 and geometries 0, 1 and 4. Use black with alpha 1, white with alpha 0, then (.75,.375,1,.625) at graph opacities 0 and 1. The first two swatches have graph opacity 1. Use gray −.25 or RGBA (−.25,.375,−.125,.5) as background. Set the seed to 328019 + 37 × geometry index + selector + swatch index. For the linked controls use a 32² unit stamp on those backgrounds with selectors 2, 5, 17 and 18. Drive opacity with a scalar or a vector (.625,.375,1,alpha). Use −.125, 0, .0001, 2⁻¹²⁶, 2⁻¹³⁰, −2⁻¹³⁰ and .375 as scalar or alpha. The seed is 329691 + value index. + +Gray bell controls at the earlier settings match 57,344/57,344, 57,331/57,344, 57,091/57,344, 124,189/126,976 pixels in U8, U16, F16 and F32 respectively. The maximum errors in the same order are 0, 1, 0.0001220703125, 4.166056442045374e-07. RGBA bell controls at the earlier settings match 57,344/57,344, 57,313/57,344, 57,138/57,344, 124,172/126,976 pixels in U8, U16, F16 and F32 respectively. The maximum errors in the same order are 0, 1, 0.000244140625, 2.8312206268310547e-07. [Bell geometry, formats and seeds](#image-inputs-and-bell-stamps-in-brick-generator-tile) + +The intact BNW Spots 1 and BNW Spots 3 outputs still match 197,377/204,288 and 180,975/185,856 pixels across 34 and 27 renders. The largest errors remain 3 and 2 levels in U16, and .0000431537628 and .0000305175781 in F32. The two Tile helpers and Gradient Linear 1 continue to match in all four formats and on their recorded saved-file settings. [Intact roots and remaining rotation differences](#rotated-stamp-coordinates-in-gradient-linear-1-and-bnw-spots) + +The median single-worker release cook across four alternating measurements per version was 173.8 to 170.6 ms for 64² Spots 1 (seed 8855) and 150.1 to 146.5 ms for 64² Spots 3 (seed 8868). Both used disorder .84375 and F32 output. + +### Rotated stamp coordinates in Gradient Linear 1 and BNW Spots + +Gradient Linear 1 matches 958,208/958,208 pixels across 79 renders, with zero maximum error in U8, U16, F16 and F32. The earlier 47 renders differed on 16 U8, 16 U16, 16 F16 and 176 F32 pixels. Maximum errors were one integer level, .000244140625 F16 and .0000152587890625 F32. All 32 additional settings match after reopening the MaterialCraft save in both apps. The reference also reproduces every original output from the saved file. [Earlier root settings and phase measurements](#pattern-rotation-phase) · [Rectangular gradient controls](#linear-gradient-sampling-on-rectangular-targets) + +| Gradient Linear 1 | U8 exact | U16 exact | F16 exact | F32 exact | Total exact | +|---|---:|---:|---:|---:|---:| +| Earlier 47 renders | 34,816 | 149,504 | 34,816 | 216,832 | 435,968 | +| Additional 32 renders | 57,344 | 203,776 | 57,344 | 203,776 | 522,240 | + +For the additional cases use the following (output, tiling, rotation selector) tuples in order. Use F32 and U16 throughout, and add U8 and F16 at indices 2, 3, 6 and 8. The seed is 317171 + 37j for zero-based index j. + +| j | Output | Tiling | Rotation | j | Output | Tiling | Rotation | +|---:|---|---:|---:|---:|---|---:|---:| +| 0 | 16×64 | 1 | 3 | 6 | 128×128 | 5 | 2 | +| 1 | 32×128 | 3 | 1 | 7 | 256×128 | 7 | 1 | +| 2 | 256×16 | 1 | 3 | 8 | 128×256 | 9 | 3 | +| 3 | 16×256 | 1 | 3 | 9 | 64×32 | 2 | 0 | +| 4 | 512×32 | 1 | 3 | 10 | 128×64 | 4 | 3 | +| 5 | 32×512 | 1 | 3 | 11 | 512×128 | 3 | 3 | + +The pattern rasterizer now computes the signed U and V at each snapped triangle vertex, then interpolates both over the output. For each component, align the vertex differences with one guard bit and the two offset products and anchor value with five. A 256×16 unwrapped unit ramp at 1.5 turns reads F32 `3eff0000` at (128,6), which stores as U16 32,640. It previously read `3efeffff` and stored as 32,639. A 64² paraboloid centered at (.5,.5), sized (.25,.25), rotated .0625 turns, reads `3df00010` at (31,24). The previous value was `3df00018`. Both single-stamp regressions failed before interpolation was applied. + +| Independent F32 stamps | Renders | Previously exact | Now exact / compared | Maximum error | +|---|---:|---:|---:|---:| +| Square | 45 | 239,604 | 239,604/239,616 | 1 | +| Horizontal ramp | 45 | 210,135 | 237,038/239,616 | .4082969427 | +| Paraboloid | 45 | 213,413 | 236,980/239,616 | 5.96046448e−7 | +| Square pyramid | 45 | 208,278 | 237,007/239,616 | 3.57627869e−7 | + +Use an unwrapped white stamp over black with unit opacity. The five (output, center in pixels, size in pixels) tuples are (64²,32/32,16/16), (128×64,37.2/23.15,27.125/16.375), (32×64,−2.125/29.375,28.625/41.75), (64²,−18.15/−3.21,70.25/32.5) and (128×64,41.125/17.375,97.123/38.157). Divide each component by its corresponding output dimension. At each geometry use turns .125, −.125, .0625, .21875, .3305, .04073, 1.5, 1.75 and 0. The seed is 301021 + 23j in geometry-major order. The square’s 12 differences are on row 8 of the third geometry at 1.5 turns. On the independent thin-ramp controls, 645,506/647,168 F32 pixels match with maximum error 5.96046448e−8. U16 matches 161,784/161,792 with maximum error one level. [Thin-ramp dimensions and seeds](#linear-gradient-sampling-on-rectangular-targets) + +| Intact root | Renders | Previously exact | Now exact / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---:|---| +| BNW Spots 1 | 34 | 197,312 | 197,377/204,288 | 1 / 3 / .00048828125 / .0000431537628 | +| BNW Spots 3 | 27 | 180,768 | 180,975/185,856 | 1 / 2 / .00048828125 / .0000305175781 | + +The 84 separate 64² paraboloids of Spots 1 now match 336,968/344,064 F32 pixels at defaults and 336,736/344,064 with changed disorder. The respective maximum errors are 7.03148544e−8 and 7.70669430e−8. Smaller stamps and their accumulation remain open. In 1,213 earlier bitmap and coordinate controls, the exact whole-pixel count rose from 4,791,431 to 4,791,757/4,821,760. Ten of the 471 groups lost exact pixels, including a rotated ramp and mip-filtered placements. The maximum gray errors are zero U8, 149 U16, zero F16 and .00361639261 F32. The corresponding RGBA maxima are zero, 34,583, zero and .527698517. [Isolated Spots 1 settings](#individual-stamps-in-bnw-spots-1) · [Bitmap filtering controls](#bitmap-stamp-filtering-and-compositing) + +The broader root guard covered 40 roots. These additional intact outputs changed their exact pixel counts. All five roots still have differences. + +| Root | Renders | Previously exact | Now exact / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---:|---| +| Cells 1 | 17 | 145,061 | 145,267/145,664 | 1 / 3 / 0.00048828125 / 3.67760658e-05 | +| Clouds 1 | 17 | 144,229 | 144,225/145,664 | 1 / 11 / 0.00048828125 / 0.000111341476 | +| Clouds 2 | 16 | 128,332 | 128,440/129,280 | 1 / 2 / 0.00048828125 / 2.29477882e-05 | +| Creased | 17 | 144,567 | 145,105/145,664 | 0 / 19 / 0.000244140625 / 1.52587891e-05 | +| Crystal 2 | 17 | 144,766 | 145,213/145,664 | 0 / 2 / 0.000244140625 / 3.05473804e-05 | + +Four alternating single-worker release cooks per version gave median times of 169.1 to 175.7 ms for 64² Spots 1 (disorder .84375, seed 8855), 131.4 to 151.0 ms for 64² Spots 3 (disorder .84375, seed 8868), 11.4 to 11.3 ms for the 512×32 F32 gradient (index 4). + +### Projecting stamp vertices through shifted render regions + +Both Brick Generator Tile helpers now match every pixel in 106 renders each, including the rectangular cases and the four output formats. The second helper previously matched 341,035/347,136. Its 32 additional settings also match after reopening the MaterialCraft save in both apps. [Root parameters, input formula and seeds](#image-inputs-and-bell-stamps-in-brick-generator-tile) · [Earlier rectangular settings](#rectangular-fields-in-the-two-brick-generator-tile-helpers) + +| Output per helper | Renders | Exact pixels | Maximum error | +|---|---:|---:|---:| +| U8 | 16 | 33,280/33,280 | 0 levels | +| U16 | 28 | 192,000/192,000 | 0 levels | +| F16 | 16 | 33,280/33,280 | 0 | +| F32 | 46 | 88,576/88,576 | 0 | +| Reopened save, all formats | 32 | 196,608/196,608 | 0 | + +In the second helper the 16×32 render and tiling windows are (0,1,−.5,1.5). On a 32×16 output they are (−.5,1.5,0,1). A white, unrotated paraboloid centered at (.541666687,.437499970), sized (.270833343,.162500009), gives raw F32 `3f0fe7d1` at (7,14) in the first window. The previous result was `3f0fe7c8`. An unrotated horizontal ramp centered at (−.333333313,.637500048) and sized (.270833343,.162499994) gives `3e6c4ec4` at (1,9) in the second window. Reducing its center modulo the window width before placing the copies loses precision. + +The rasterizer stores the triangle vertices in pattern space, projects their offsets from the render origin at F32 precision, and snaps them in pixel space. It converts each snapping displacement back into pattern space before scaling the signed coordinate. The outer visible copy starts from the authored center. In a 32×64 quarter-turn ramp with center (.0057024003,.9846573), size (.20347844,.7093721), render window (−.173,.369,.096,.869) and tiling window (.019,.631,−.073,.689), pixel (0,2) is `3cd47660`. The previous result was `3cd47650`. All three regressions failed against the previous rasterizer. In 192 separate horizontal-ramp, vertical-ramp, paraboloid and square renders from the helper's stamp placements, 589,824/589,824 F32 pixels match with zero maximum error. + +**Independent windows.** Draw one white horizontal ramp over black with additive blending. For the vertical read, swap the two stamp dimensions and turn by .25. Use a root quadrant with branch offset (−.5,−.5) and set its frame offset to the desired center. Render each geometry with both tiling axes off and again with both on. The paired render/tiling windows in order are A/A, B/B, C/C, D/D, D/E, U/D and D/U. Here A=(0,1,−.5,1.5), B=(−.5,1.5,0,1), C=(−.375,1.125,.125,.875), D=(−.173,.369,.096,.869), E=(.019,.631,−.073,.689) and U=(0,1,0,1). + +Use NumPy PCG64 seed 319091. For each of 18 zero-based indices j, draw two independent uniform center coordinates in [−.7,1.4) followed by two sizes in [.147,1.07). Cycle through 32×64, 64×32 and 64². For window index i use render seed 319237 + 31j + i. Across those 504 renders, the number of exact F32 pixels increased from 1,264,469 to 1,374,592/1,376,256. Every render retained or improved its exact count. The 1,664 differences occur in the tiled C/C horizontal ramp at j=11 with a maximum error of 2⁻²². The four independently positioned copies sum to the reference tiled output exactly. Two of those individual horizontal copies still differ. + +A further 210 F32 renders cover centers several periods outside the windows. The exact count increased from 454,474 to 573,249/577,536 pixels, maximum error 2⁻²². Six renders lost exact pixels in this set. Isolated draws reproduce the tiled reference when the windows coincide on row 1. On row 2, four horizontal ramps still differ when the individually positioned copies are added. Start a fresh PCG64 stream at 320021 and continue it across the table. Restart the trial number at one in each row. On odd trials draw both center coordinates in [−4.02,3.2), on even trials in [−.219,.337), then both sizes in [.111,1.07). A trial number modulo three of 0, 1 or 2 selects 32×64, 64×32 or 64². Draw the listed trials with both tiling axes enabled, ending each row after its last listed trial. For the zero-based selected index j and row i use seed 320597 + 43j + i. Stamp sizes, centers and window coordinates are stored as F32. + +| Render / tiling windows | Selected trials | Exact F32 pixels | Maximum error | +|---|---|---:|---:| +| A / A | 6, 20, 24, 42, 44, 48, 50, 58, 72, 96, 100, 102, 106, 107, 108 | 77,824/77,824 | 0 | +| D / D | 7, 11, 13, 21, 23, 24, 29, 31, 35, 46, 47, 48, 49, 53, 57 | 85,840/86,016 | 2⁻²³ | +| D / E | 5, 19, 24, 27, 28, 35, 37, 41, 43, 48, 51, 55, 59, 61, 64 | 74,609/77,824 | 2⁻²² | +| U / D | 3, 5, 15, 17, 21, 23, 24, 27, 35, 43, 48, 49, 55, 59, 63 | 81,920/81,920 | 0 | +| (.37,1.723,−1.136,.197) / (−.391,.533,−.251,.194) | 1, 4, 5, 8, 10, 11, 13, 14, 17, 20, 24, 25, 26, 28, 29 | 94,208/94,208 | 0 | +| (−.851,.95,−.151,.341) / same | 1, 4, 10, 21, 24, 25, 27, 36, 41, 43, 47, 48, 59, 63, 64 | 73,728/73,728 | 0 | +| (.91,1.792,−.46,1.9) / same | 6, 11, 16, 24, 26, 27, 32, 34, 35, 37, 38, 42, 45, 47, 48 | 85,120/86,016 | 2⁻²³ | + +### Image inputs and bell stamps in Brick Generator Tile + +The first Brick Generator Tile helper matches all 347,136 pixels in 106 renders. The 32 settings saved by MaterialCraft also match all 196,608 pixels after reopening in both apps. The second helper still differed on rectangular outputs at this checkpoint. For the 32 additional settings, both saved graphs reproduce their respective original reference outputs exactly. [Subsequent region measurements](#projecting-stamp-vertices-through-shifted-render-regions) + +| Helper and settings | Renders | U8 exact / pixels | U16 exact / pixels | F16 exact / pixels | F32 exact / pixels | +|---|---:|---:|---:|---:|---:| +| Brick Generator, earlier | 74 | 6,144/6,144 | 120,832/120,832 | 6,144/6,144 | 17,408/17,408 | +| Brick Generator, additional | 32 | 27,136/27,136 | 71,168/71,168 | 27,136/27,136 | 71,168/71,168 | +| Pattern Brick Generator, earlier | 74 | 6,138/6,144 | 120,822/120,832 | 6,138/6,144 | 17,100/17,408 | +| Pattern Brick Generator, additional | 32 | 27,133/27,136 | 70,741/71,168 | 27,133/27,136 | 65,830/71,168 | + +Maximum error is zero in all four formats for the first helper. Across all 106 renders of the second helper, the maxima are 175 U8 levels, 45,055 U16 levels, .6875 F16 and .6875 F32. Its independently drawn stamps reproduce the reference helper output at every pixel on the 16×32 paraboloid and 32×16 Gaussian controls. The remaining differences are already present in the individual stamps. [Earlier settings and procedural input](#rectangular-fields-in-the-two-brick-generator-tile-helpers) + +For the additional rows, use seed 314159 + 73j for zero-based row j. Render F32 and U16 every time, adding U8 and F16 on rows 0, 2, 6 and 8. Supply a white U16 input when j mod 4 = 0. Otherwise set its level at (x,y) to 1024 + ((65519 + 39377x + 17713y + 131xy + 1123j) mod 63521). The type column is the integer pattern selector on the helper. + +| j | Output | Input | Type | X/Y count | Scale | Offset | Global offset X/Y | Opacity | +|---:|---|---|---:|---|---:|---:|---|---:| +| 0 | 32×16 | 16×32 | 1 | 3/5 | .8125 | .375 | .125/−.0625 | .6875 | +| 1 | 16×64 | 16×64 | 1 | 1/7 | .739 | .167 | −.207/.137 | .533 | +| 2 | 32×64 | 64×32 | 2 | 5/3 | .917 | .259 | .371/−.291 | .817 | +| 3 | 64×32 | 64×32 | 3 | 7/2 | .631 | .457 | −.329/.539 | .913 | +| 4 | 64×64 | 32×64 | 4 | 9/5 | .833 | .579 | .117/−.217 | .639 | +| 5 | 64×128 | 64×128 | 5 | 3/7 | .517 | .719 | −.373/.171 | .977 | +| 6 | 128×64 | 128×32 | 1 | 5/9 | .993 | .339 | .219/−.317 | .369 | +| 7 | 128×32 | 32×128 | 2 | 3/1 | .867 | .119 | −.413/−.193 | .733 | +| 8 | 128×128 | 128×128 | 1 | 9/7 | .687 | .883 | .083/.241 | .871 | +| 9 | 256×64 | 64×128 | 4 | 11/3 | .931 | .631 | −.189/.327 | .571 | +| 10 | 32×128 | 32×128 | 3 | 1/5 | .439 | .953 | .499/−.493 | .937 | +| 11 | 64×64 | 16×32 | 5 | 4/3 | .377 | .215 | −.311/.413 | .753 | + +A single tiled 16×32 image stamp isolates the edge-sampling error in the first helper. Use a white input of the same size, a black background, center (.958333313,.4375), size (.270833343,.8125), zero rotation and opacity .6875. Pixel (1,1) was zero in all three filter modes. The reference reads .2229037880897522 with mip filtering, .34375524520874023 with linear filtering and .6875 with nearest filtering. The interpolated horizontal coordinate lies just inside the stamp and samples its last texel. The rasterizer now uses the same interpolated coordinates for image and analytic stamps. + +At 12 stamp placements, repeat all three filters with white and patterned U16 inputs. Generate the patterned input as in the table with j=0. Seed each pair with 312883 + 17 times the zero-based placement index. Each mode now matches 12,288/12,288 F32 pixels, maximum error zero. The previous exact counts were 12,214 for each linear filter and 12,206 for nearest. A 32² regression uses a white U8 source, center (−.020833343,.4375), size (.13541667,.8125) and wrapping disabled. It failed on the previous sampler. Across 1,213 earlier bitmap controls, exact whole pixels increased from 4,762,689 to 4,791,431 of 4,821,760. The maximum grayscale errors are zero U8, 343 U16, zero F16 and .005227506160736084 F32. The corresponding RGBA maxima are zero, 34,583, zero and .5276985168457031. [Filter, channel and blend controls](#bitmap-stamp-filtering-and-compositing) + +The 12 (center X/Y, width/height) placements, in seed order, are (.291666687,.4375,.270833343,.8125), (.625,.4375,.270833313,.8125), (.958333313,.4375,.270833343,.8125), (.416666687,.237500012,.270833343,.162499994), (.666666687,.637500048,.270833343,.162499994), (.791666687,.837499976,.270833343,.162500009), (.958333313,.037499994,.270833343,.162500009), (1.20833325,.43749997,.270833343,.162500009), (.958333313,.0625,.270833343,.203125), (1.20833325,.5625,.270833343,.203125), (.291666687,−.5625,.270833343,.8125) and (.625,−.362499952,.270833313,.162499994). Use zero rotation, tiling on both axes, additive blending and opacity .6875. + +The final 25 differences in the wider first-helper matrix were all negative F32 bell samples on rows 5 and 11. Their 33 independently drawn bells now match 221,184/221,184 F32 pixels. Replacing each bell by a ramp or paraboloid also gives 221,184/221,184 pixels per shape. At 64² a white, centered unit bell on black with additive blending reads b2f28000 at (10,8) and b36346e0 at (54,9) in raw F32 bits. The old profile clamped both to zero. Keeping the signed quartic until blending preserves both readings and the maximum blend gives zero at those same pixels. The two-mode regression failed before this change. + +In 136 independent gray and color bell renders, exact whole pixels increased from 579,761 to 580,258/598,016. The centered unit additive gray case improved from 4,082 to 4,096/4,096 F32 pixels, maximum error zero. With maximum blending over a gray background of −.25, that unit case still matches 3,228/4,096 with maximum error .25 at the stamp corners. Some oblique stamps also differ. For these controls use (output, center X/Y, size X/Y, turns) of (64²,.5/.5,1/1,0), (32×16,.417/.533,.813/.693,0), (16×32,.541/.383,.779/.689,0), (64×128,.437/.329,.517/.817,0), (128×64,.675/.419,.433/.557,.25), (32×64,.519/.591,.777/.625,.125), (64²,.291/.773,.519/.627,.071) and (128×32,.717/.177,.881/.437,.5). Use F32 throughout and add F16, U16 and U8 at indices 0, 3 and 5. Run additive and maximum blending on black, then on −.25 gray or RGBA (−.25,.1875,−.09375,.375). Use white for gray and tint (.75,.375,1,.625) for color. Use seed 316163 + 37 times the geometry index + the blend/background index from 0 to 3. + +### Stored stamp vertices in Crystal 1 + +Crystal 1 now matches all 1,966,336 raw pixels across 64 distinct renders. At 512×128, graph seed 311203, warp intensity 5.137 and disorder .923, nine paraboloids cover source pixel (138,0). The maximum comes from a stamp centered at (.2958984076976776,.9684525728225708), size (.1875,.1875), rotation zero and opacity .91. Draw its upper wrapped copy alone at Y −.031547427. The reference reads `3f368e3f` in F32, and MaterialCraft previously read `3f368e41`. In the whole graph that changes the stored U16 source from 46,734 to 46,733. The warp then reproduces the measured output in all four formats. + +The rasterizer now stores both triangle vertices at F32 pixel precision before snapping their positions. Coverage starts at the snapped near vertex and includes samples whose interpolated coordinates reach exactly either edge. A separate 16×32 wrapped white square with center (.9583333,.4375) and size (.27083334,.8125) covers (1,1). Both pixel regressions failed before the change. The 180 square-edge renders gained 50 exact pixels and now match 184,320/184,320. Another 45 horizontal ramps and 45 squares placed near rounding thresholds matched all 1,179,648 F32 pixels. One such 128×64 case uses center (.1703786552,.3904481232), size (.3016948104,.6273717880), no rotation or tiling and seed 312407. + +| Distinct Crystal 1 outputs | U8 pixels | U16 pixels | F16 pixels | F32 pixels | Maximum absolute error | +|---|---:|---:|---:|---:|---:| +| 64 original renders, all exact | 170,496 | 557,568 | 449,024 | 789,248 | 0 in each format | +| 32 of those settings reopened from a MaterialCraft save, all exact | 99,840 | 368,128 | 99,840 | 368,128 | 0 in each format | + +The 64 comprise 17 earlier renders, 32 changed-control renders and 15 further distinct settings. To reproduce the final 16 stage comparisons, start at 512×128, seed 311203, warp 5.137 and disorder .923. Render U8, U16, F16 and F32. Also render F16 and F32 for each of six changes, restoring the base after each one. Use 256×64, warp zero, disorder zero, seed 311204, 256² and 128×512. One base F16 output repeats the earlier 32-render matrix. All nine graph stages matched in every case. The independent paraboloid and horizontal and vertical ramp measurements at the suspect location also match all 3,145,728 F32 pixels. [Earlier control values, seeds and saved-file comparisons](#wrapped-stamp-centers-in-brick-3) + +In the two Brick Generator Tile helpers, independently drawing each of 84 unit-region stamp placements as a square, ramp and paraboloid matched 129,024/129,024 F32 pixels. The first helper now matches 150,508/150,528 pixels over 74 renders. Its five remaining differing pixels per format occur with image input at 16×32. The maximum errors are 58 U8 levels, 14,974 U16 levels, .2283935546875 F16 and .2284952700138092 F32. The second helper matches 150,174/150,528 with maximum errors of 175, 45,055, .6875 and .6875 respectively. Both remain in progress. In the separate unwrapped subpixel-square controls, 196,597/196,608 F32 pixels match and the maximum error is one. [Helper settings and input construction](#rectangular-fields-in-the-two-brick-generator-tile-helpers) + +### Wrapped stamp centers in Brick 3 + +Three stamps accounted for the last 16 differing U16 source pixels in the earlier Brick 3 cases. The downstream outputs repeated those differences in U16 and F32. All three stamps crossed the left edge. A single 64² horizontal ramp, center (.063709915,.9060309), size (.1280197,.06283637), zero rotation and horizontal tiling isolates the error. At (0,56) the F32 bits were `3d81c770`. The reference reads `3d81c730`. A regression for that pixel failed on the previous cooker. + +The starting center is stored in F32 at the outer copy that overlaps the render and tiling windows. The rasterizer and its small-footprint test step back one period at a time from that center. Where the horizontal period is one and the outer copy is the next tile, this makes the center in the original tile `(center + 1) − 1` in F32. The three isolated bevels now match all 20,480 F32 pixels, maximum error zero. The other two centers are (.0630749836564064,.15664711594581604) and (.0630003958940506,.6566050052642822), both with size (.1265193521976471,.06177031993865967) at 128×64. + +| Brick 3 outputs | Renders | Exact U8 | Exact U16 | Exact F16 | Exact F32 | Total exact / compared | +|---|---:|---:|---:|---:|---:|---:| +| Earlier cases, including defaults | 68 | 39,936 | 179,200 | 39,936 | 168,448 | 427,520/427,520 | +| Changed decimal controls | 32 | 78,336 | 355,840 | 78,336 | 355,840 | 868,352/868,352 | + +Maximum error is zero in each format. Before the change, the 32 new cases matched 867,054/868,352 pixels. Maximum errors were zero U8, one U16 level, .00048828125 F16 and .0000152587890625 F32. The ordinary MaterialCraft save reopened in both apps and preserved every one of those 868,352 pixels. [Earlier brick cases and parameter settings](#fractional-stamp-vertices-and-the-last-covered-pixel) + +For the 32 new renders use the following (width×height, tiling, roundness, luminosity variation, luminosity seed, disorder) tuples, in row order. Use F32 and U16 on every row, adding U8 and F16 on rows 0, 2, 5 and 9. The graph seed is 303407 + 59 × row + the zero-based format index in that order. + +| Row | Size | Tiling | Roundness | Luminosity variation | Luminosity seed | Disorder | +|---:|---|---:|---:|---:|---:|---:| +| 0 | 32×16 | 1 | .131 | .219 | 11 | .883 | +| 1 | 16×64 | 2 | .257 | .418 | 27 | .539 | +| 2 | 32×128 | 1 | .319 | .623 | 37 | .173 | +| 3 | 64×32 | 3 | .437 | .716 | 41 | .297 | +| 4 | 64×128 | 3 | .531 | .317 | 53 | .373 | +| 5 | 128×64 | 2 | .647 | .931 | 67 | .477 | +| 6 | 128×256 | 4 | .701 | .293 | 79 | .663 | +| 7 | 256×128 | 1 | .789 | .147 | 93 | .513 | +| 8 | 256² | 2 | .853 | .839 | 103 | .719 | +| 9 | 512×128 | 3 | .947 | .353 | 127 | .993 | +| 10 | 512×256 | 2 | .197 | .751 | 151 | .193 | +| 11 | 128×32 | 1 | .339 | .497 | 173 | .383 | + +An independent single-ramp sweep varied horizontal and vertical orientation, all four tiling masks and stamp sizes spanning up to 3.3 periods. All 3,112,960 F32 pixels across 456 renders agree. For each mask and orientation, begin with the three isolated stamp geometries. With NumPy PCG64 seed 302609, draw two widths uniformly from [.15,.87) and two center fractions from [.16,.48) for each of 45 geometries. For each axis choose width × fraction, 1 − width × fraction, or .5 in that order. Cycle the horizontal choice each row and the vertical choice every three rows. Cycle 64², 128×32, 32×128, 64×128 and 128² outputs. Use nine further 64² cases with both widths drawn from [1.05,3.3) and both centers from [.001,.99). For the vertical ramp transpose the two widths and use a quarter turn. Use seed 302999 + 11 × geometry index. + +As a separate check inside the reference app, combine independently drawn, unwrapped paraboloids with maximum blending and compare them with the tiled drawing. For each of 15 geometries the reconstructed images match in the unit region at .071 turns and in the asymmetric region (−.125,.75,−.25,1.125) at zero and .071 turns, 294,912/294,912 pixels. Measuring each center directly from the original position missed 8,955 and 4,972 pixels on the two rotated sets. In a 64² subpixel solid-stamp check, horizontal tiling matches 196,608/196,608 pixels across 48 renders. With tiling disabled, 196,597/196,608 match, maximum error one. The differing samples lie within a few F32 steps of the stamp boundary. The four nonunit ramp sets retain their previously recorded differences. + +Fractional periods distinguish a sequence of F32 subtractions from a single multiplication by the copy index. Repeat geometries 3, 12, 22, 38, 48, 50, 51, 53, 55 and 56 above at 32². Use bounds (.019,.631,−.073,.689) at zero turns and (−.173,.369,.096,.869) at .071 turns. Stepping one period at a time reconstructs 20,480/20,480 native maximum-blend pixels. A single multiplication misses 371, maximum 1.1920928955078125e−7. With horizontal period .542, center .30712050199508667 and copy indices −4 through 3, the leftmost center has bits `bfee314e`. + +For additive blending, each row runs from the largest to the smallest column, and rows run from the largest to the smallest row. Reassembling the unwrapped native outputs in that order reproduces all 118,784 F32 pixels in 35 renders across the unit region and the two fractional regions. Reversing both axes differs at 8,414 pixels, maximum 2.86102294921875e−6. With a 32² horizontal ramp centered at (.1875,.34375), size (2.75,2.5), opacity one and wrapping on both axes, pixel (3,0) has bits `40351747`. Traversing in ascending order gives `40351746`. Both the fractional-center and accumulation-order regressions failed before the change. + +For a direct comparison between apps, render centered horizontal ramps and paraboloids with the following (width×height, center X/Y, size X/Y) groups at zero turns, additive blending and F32 storage. Use (32²,.1875/.34375,2.75/2.5), (64×32,.29535/.6747,1.8125/3.125), (32×64,.8197/.43265,3.536/.939), (64²,.5729/.1692,2.617/2.329), (32²,.593/.7796,1.801/2.71) and (64×32,.1121/.997,3.145/3.499) with seed 311197 + 19 × group. The ramps improved from 7,953 to 12,288/12,288 and the paraboloids from 8,282 to 12,288/12,288. Maximum errors fell from 1.430511474609375e−6 and 9.5367431640625e−7 to zero. + +BNW Spots 1 now matches 197,312/204,288 pixels, BNW Spots 3 matches 180,768/185,856, the two Brick Generator Tile helpers match 150,301 and 149,872 of 150,528 and Cells 1 matches 145,061/145,664. The maximum errors in U8, U16, F16 and F32 respectively are 1/3/.00048828125/.0000431537628 for Spots 1, 1/2/.00048828125/.0000305175781 for Spots 3, 175/45,055/.6875/1 for each Tile and 0/3/.00048828125/.0000367760658 for Cells 1. [Individual spot measurements](#individual-stamps-in-bnw-spots-1) · [Tile helper controls](#rectangular-fields-in-the-two-brick-generator-tile-helpers) + +Crystal 1 gained its last 311 pixels in the earlier 17-render matrix, 145,664/145,664. Another 32 original renders and their saved-file readbacks each match 935,935/935,936 pixels between apps. The reference app reproduces all 935,936 pixels before versus after the save. One F16 pixel differs by .0001220703125. Use (width×height, warp intensity, disorder) of (16×32,0,.137), (32×64,3.179,.533), (64×16,7.25,.351), (128×32,12.739,.119), (64×128,20.527,.779), (256×64,35.193,.801), (128×256,49.73,.327), (256×128,63.125,1), (256²,32.979,.477), (512×128,5.137,.923), (512×256,47.507,.679) and (128×64,0,0). Use seed 310453 + 83 × row + the format index. Render F32 then U16 throughout, adding U8 then F16 on rows 0, 2, 6 and 9. At (138,0) on the 512×128 F16 case, the first differing stage is the U16 pattern map, 46,733 in the reference and 46,734 in MaterialCraft. Reusing that seed in every format gives one U16 difference, one F16 difference, one F32 difference of .0000152736902 and exact U8. Crystal 1 remains in progress. Crystal 2 lost four matches in its earlier matrix, with 144,766/145,664 exact. Its maximum errors are zero U8, two U16 levels, zero F16 and .0000305175781 F32. + +### Decimal graph parameters on the control channel + +The two remaining differences in the first 200-render unit-region sweep came from parsing the width before cooking. A 128×32 horizontal ramp used width `0.37710319459438324`, height `0.6551689207553864`, frame offset (−.022019073367118835,.3031836450099945) from the canvas center and seed 265655. Its transposed counterpart used a quarter turn and seed 265656. The width lies halfway between two F32 values. The JSON reader previously returned a binary64 value just below that midpoint. The positive width reached the graph as `3ec113ab`. The reference reads `3ec113ac`. Enabling round-trip decimal parsing in the existing JSON dependency preserves the midpoint until conversion to the graph’s type. A regression with both signs failed before the change. + +| Pass-through value | Exact scalar components before | Exact after | Maximum absolute error before | Maximum after | +|---|---:|---:|---:|---:| +| Float | 47/50 | 50/50 | 1.9073486328125e−6 | 0 | +| Float2 | 93/100 | 100/100 | 7.62939453125e−6 | 0 | +| Float4 | 192/200 | 200/200 | 3.814697265625e−6 | 0 | + +For each type, connect a value processor that reads its exposed parameter directly to a typed output. Supply JSON decimals and compare the raw F32 component bits. Start the unsigned 32-bit generator at `443b0781` hexadecimal and update it with `1664525s + 1013904223` modulo 2³². Continue the sequence across all three types. For case j=0…49 and component c, take two successive draws. Use biased exponent 119 + (first draw modulo 15) and the low 23 bits of the second draw for a positive F32. Find its midpoint with the next higher F32 in binary64. According to (j+c) modulo 4, supply the midpoint, its lower binary64 neighbor, its higher binary64 neighbor, or the higher F32. Negate when (j+c) modulo 3 is zero. In case zero, replace the generated values with the width above and alternate signs. Use 32² for even cases, 16² for odd cases and seed 304193 + 31j + component count. + +The original and the ordinary MaterialCraft save for each type produced identical typed readbacks in both apps, 350/350 scalar components per set. The 200 original ramp renders improved from 1,391,416 to 1,392,640/1,392,640 bit-identical F32 pixels. Maximum absolute pixel error fell from 1.1920928955078125e−7 to zero. The 264 independently seeded controls retained all 1,802,240 pixels. [Ramp controls and remaining nonunit-region differences](#fractional-stamp-vertices-and-the-last-covered-pixel) + +### Scaling the far vertex of an analytic stamp + +The two remaining square-edge ramp differences in the 264-render unit-region sweep have the same cause. Use a 32×64 output, center (.029354721,.79239917), normalized size (.1660128,.6520761), unit opacity, and zero or half a turn. At (0,30) the zero-turn F32 bits were 3ed5a7fa instead of 3ed5a7fc. The half-turn bits were 3f152c03 instead of 3f152c02. The signed displacement from the far vertex is stored in F32 before multiplication by the coordinate scale. A two-orientation regression failed on the previous implementation. + +All 1,802,240/1,802,240 raw F32 pixels in those 264 original renders now match, maximum absolute error zero. An independent 16-render replay using explicit F32 widths or their immediate neighbors also matches all 49,152/49,152 pixels. Both brick roots retain every measured output in the two 32-case decimal matrices, 1,910,784/1,910,784 pixels per root in four formats, including their reopened packages. [Input generation, unit-region dimensions and prior root totals](#fractional-stamp-vertices-and-the-last-covered-pixel) + +The wider recheck of the preceding vertex and coverage changes retained all 3,139,328 pixels over 17 previously verified roots. In the earlier root matrices, Crystal 1 gained 386 exact pixels, Directional Noise gained 361, Dirt 3 gained 35 and Dirt 6 gained 1,043. Dirt Gradient lost 20, with 128,939/129,280 exact and maximum errors of zero U8, two U16 levels, .000244140625 F16 and .0000198483467 F32. Brick 3 still had 32 different U16 or F32 pixels at that checkpoint. + +### Fractional stamp vertices and the last covered pixel + +Brick 1 and Brick 2 now match all 255 measured original renders, including defaults, changed graph controls, several seeds, rectangular outputs and four storage formats. An original horizontal F32 ramp localized the first difference in Brick 2. At 64² use center (.425,.375), size (28.625/64,12.625/64), zero rotation and unit opacity. Before the change, pixel (16,18) read `3e013acc` instead of `3e013ace` and (33,18) read `3f3857a2` instead of `3f3857a4`. Translating the same ramp in two-pixel increments changed its step when a far vertex crossed 64, even though its fractional position on the grid stayed the same. + +The interpolator now stores each unsnapped vertex in F32 before adding its displacement to the pixel grid. The two coordinates at the outermost sample must also lie within the closed interval [−1,1]. The physical footprint still assigns a pixel exactly on a shared edge to one neighbor. For a solid stamp centered at (−19/64,−20/64), size (45/64,49/64), (0,3) stays white and (0,4) becomes black. Both this assertion and the ramp regression failed on the previous cooker. The clipping check runs at the ends of the span. + +| Root | Renders | Exact U8 | Exact U16 | Exact F16 | Exact F32 | Total exact / compared | Maximum in each format | +|---|---:|---:|---:|---:|---:|---:|---:| +| 59 · brick_1 | 131 | 128,512 | 1,476,096 | 128,512 | 1,461,248 | 3,194,368/3,194,368 | 0 | +| 60 · brick_2 | 124 | 126,464 | 1,469,952 | 126,464 | 1,453,056 | 3,175,936/3,175,936 | 0 | + +Use the previously recorded root settings, then apply the 12 decimal settings to both graphs. Add 909 to each seed for Brick 2. In the first 31 follow-ups, each original and its ordinary MaterialCraft save now match all 856,064 raw pixels across apps. [Original brick controls and first saved-file checks](#fractional-edges-of-axis-aligned-pattern-stamps) · [Twelve additional settings and output formats](#cropped-origins-of-axis-aligned-stamps) + +| Additional original F32 controls | Renders | Exact pixels | Maximum absolute error | +|---|---:|---:|---:| +| Translated ramps with three width and height pairs | 180 | 1,732,608/1,732,608 | 0 | +| Horizontal and vertical signed ramps crossing a canvas edge | 144 | 1,019,904/1,019,904 | 0 | +| Solid, paraboloid, beveled and offset stamps at the same boundaries | 144 | 1,019,904/1,019,904 | 0 | +| Fractional-width and fractional-height ramps measured earlier | 669 | 5,050,368/5,050,368 | 0 | +| Arbitrary centers and extents in the unit region, first set | 200 | 1,391,416/1,392,640 | .000000119209290 | +| Independently seeded unit-region controls, second set | 264 | 1,801,968/1,802,240 | .0000000894069672 | + +For the signed edge controls choose these (canvas, pixel extent, pixel center) triples. Use (128²,126×62,0/96), (128×64,94×47,−35/20), (64×128,47×94,20/−35), (128²,97×89,−39/−34), (64²,45×49,−19/−20), (32×128,99×123,−40/22), (128×32,105×95,27/−37), (64²,66×64,−27/15), (32×64,92×85,−33/−34), (64×128,27.75×119.125,12/−48), (128×64,99.25×51.75,−41/27), and (32²,73.125×71.875,−28/−29). Offset the center by (0,0), (.125,.25), or (.375,.125) pixels. Use single horizontal and quarter-turned ramps with both signs of the ramp size, then shapes 2, 4, 9 and 17. Use zero roughness, .7265625 bevel smoothness, seed 270557 + 31 × triple index + 3 × offset index + negative-size flag for the ramps and .375 variation for shape 17. Brick 3 still differs at 32/427,520 pixels across 68 renders, maximum one U16 level or .0000152587891 F32. Its U8 and F16 results agree throughout. + +Saving both graphs with the normal package writer and reopening them in the reference app preserved all 1,910,784 pixels per graph across the 32 decimal cases. MaterialCraft reopened the same two files and matched those pixels as well. Four nonunit-region controls still differ. Render the 24 cases for j = 12 through 23 of the generator below with view and tiling bounds (−.175,.837,−.243,1.109), (.071,.663,.169,.728), (−.11328125,.88671875,−.0703125,.9296875) and (.1875,.8125,.09375,.84375), respectively. The four sets match 155,285, 130,877, 159,340 and 138,652 of 163,840 pixels each. Their maximum errors are 1.78813934e−7, 2.38418579e−7, 1.78813934e−7 and 2.38418579e−7. + +For the 264 unit-region controls start the [32-bit generator](#cropped-origins-of-axis-aligned-stamps) at 0x4a9721d3. Each draw shifts the new state right eight and divides by 2²⁴. Cycle the canvas through 16×128, 128×16, 32×64, 64×32, 128² and 256×64. Draw width and height in pixels as 2 + draw × (1.2 × axis dimension − 2), then the two normalized center components as −.2 + 1.4 × draw. Negate the X size for j mod 3 = 1 and the Y size for j mod 5 = 1. At even j render zero and half turns, at odd j render both quarter turns after transposing the canvas and center. The seed is 290449 + 11j + orientation index. The remaining 272 pixels belong to the two j = 68 images. In the first set, entering the same 32-bit width explicitly made both previously different renders exact. All 272 release node tests passed. + +### Cropped origins of axis-aligned stamps + +Brick 1 at 256², tiling 2, edge smoothness .7265625 and interstice width .03125 differed at 64 output positions in each of U16 and F32. Two independently authored bevel stamps reproduce the entire 128² source in each app. For the wrapped stamp use shape 9, size (.984375,.484375), center (0,.75), unit opacity and the same smoothness. At (48,88) its F32 value was `3e732afe` in MaterialCraft and `3e732b04` in the reference. The combined U16 source there was 15,562 versus 15,563. Replacing the bevel by a horizontal ramp isolated the difference to the horizontal coordinate. + +At the four-pixel origin, choose the far vertical triangle vertex when its integer distance fits in as few bits as the vertical distance to the near vertex. Otherwise apply the same comparison horizontally, then use the near vertex if neither qualifies. For each axis, multiply the unsigned offset by the 24-bit gradient significand. Drop the low max(0, bit length of the offset − 5) columns in each partial product before adding the rows. Apply the sign, add the vertex attribute and truncate to F32. For a negative interpolated value add 1/64 of a gradient unit in the last place before the final truncation. The wrapped bevel and signed, doubly clipped gradient assertions exercise the original discrepancy. + +| Original control | Renders | Exact pixels or scalar coordinates | Maximum error | +|---|---:|---:|---:| +| Horizontal and vertical ramps at fractional extents | 669 | 5,050,368/5,050,368 | 0 | +| Seeded independent triangle interpolation, two signed coordinates | 1,024 | 251,364/251,364 | 0 | +| Brick 1, original 68 runs and first 31 follow-ups | 99 | 1,283,584/1,283,584 | 0 in all four formats | +| Brick 1, first 31 follow-ups reopened from a MaterialCraft save | 31 | 856,064/856,064 | 0 in all four formats | +| Brick 1, 12 further parameter settings | 32 | 1,906,474/1,910,784 | 0 U8, 1 U16, 0 F16, .0000153183937 F32 | +| Previously verified roots at their recorded settings | 167 | 3,139,328/3,139,328 | 0 | + +To reproduce the triangle check, start a 32-bit state at `0x31d57b09` and advance with 1,664,525 × state + 1,013,904,223 modulo 2³² before each draw. For j = 0 through 1,023 take W = 19 + draw mod 493, H = 17 + draw mod 389. For K and J use (draw shifted right eight) mod (floor(dimension/2) + 4) − 3. Take two more draws for near attributes u and v, each .5 + ((draw shifted right 16) mod 64)/64. Negate u unless j is divisible by three and v unless j is divisible by five. The far attributes are F32(u × (1 − W/(max(K,3) + t))) and its vertical counterpart, with t = .5 on odd j and zero otherwise. Draw the right triangle with corners (−K,−J), (W−K,−J) and (−K,H−J) onto 16×8. Compare pixel centers with nonnegative barycentric coordinates and normalized horizontal plus vertical distance below .997. + +For the 32 new Brick 1 renders, read each row as width × height, tiling, smoothness and gap. Run F32 and U16 for every row, then U8 and F16 for rows 0, 1, 3 and 7. In that order, seed each format with 286049 + 43 × row + format index. + +| Row | Dimensions, tiling, smoothness, gap | Row | Dimensions, tiling, smoothness, gap | +|---:|---|---:|---| +| 0 | 16×32, 2, .113, .071 | 6 | 256², 5, .917, .287 | +| 1 | 32×64, 1, .199, .183 | 7 | 512×128, 3, .577, .253 | +| 2 | 64×128, 3, .317, .097 | 8 | 512², 1, .431, .107 | +| 3 | 128×32, 4, .489, .139 | 9 | 1024×256, 2, .737, .149 | +| 4 | 128×256, 3, .697, .193 | 10 | 256×512, 3, .349, .039 | +| 5 | 256×128, 2, .811, .063 | 11 | 128², 2, .999, .013 | + +Across the 32, U8 and F16 each match all 72,192 pixels. U16 matches 881,552/883,200 and F32 matches 880,538/883,200. Brick 1 remains in progress. Separately, 200 original F32 ramps with arbitrary fractional centers match 1,346,264/1,392,640 pixels, maximum .000000178813934. For 72 deliberately clipped signed ramps per orientation, 509,590/509,952 pixels match horizontally and vertically, with maxima 1 and 1.00000024. [Earlier sizes, root settings and saved packages](#fractional-edges-of-axis-aligned-pattern-stamps) + +On the recorded set of 17 Crystal 1 renders, 144,967/145,664 pixels match. Directional Noise matches 146,377/147,712 on its 23 renders. Four interleaved single-worker release runs gave median 512² cook times of 1,355 ms for Alveolus and 1,050 ms for Pattern Alveolus, compared with 1,238 and 1,169 ms respectively before this change. All 270 release node tests passed. + +### Fractional edges of axis-aligned pattern stamps + +Changing only the height of a horizontal ramp changes its left-to-right coordinate step. For a 64² grayscale F32 quadrant, use shape 10, center (.5,.5), size (.375,.23046875), zero rotation and zero roughness. At pixel (21,32) the reference returns `3d800004`. The previous calculation returned `3d800000`. A second control uses size (.23828125,.375), center (.5,.501953125) and a quarter turn. Pixel (20,34) reads `3f27de6c`. The five raw sample assertions fail on the previous cooker and pass with the change. + +For each unrotated image axis let C be the center in pixels, S the positive pixel extent and L = C − S/2. Snap the near vertex to N = floor(L + .5) and the far vertex to H = floor(L + 2S + .5) + 1. Use (H − N)/2 for each padded extent in the earlier area calculation. Multiply N − C and H − C by the runtime pixel quotient 2/S and store each result in F32. Truncate their difference to F32 before halving it for the gradient product. Anchor the stored coordinate at the preceding four-pixel boundary of max(N,0). Exact quarter turns exchange the axes. Coverage uses the open lower and closed upper edges in the original coordinate space. This preserves the measured ownership of shared edges. [Gradient product and area reciprocal](#pixel-coordinates-for-whole-pixel-pattern-stamps) · [Earlier horizontal and vertical sweeps](#horizontal-stamp-bounds-at-fractional-heights) + +| Original grayscale F32 control | Renders | Exact pixels | Maximum absolute error | +|---|---:|---:|---:| +| Width, height and horizontal phase at zero rotation | 143 | 2,342,912/2,342,912 | 0 | +| Eighth-pixel shifts at fractional heights | 208 | 851,968/851,968 | 0 | +| Transposed extents at both quarter turns | 168 | 688,128/688,128 | 0 | +| New rectangles and their quarter-turned transposes | 150 | 1,167,360/1,167,360 | 0 | +| Whole-canvas ramps with zero and half turns | 72 | 2,032,128/2,032,128 | 0 | +| Aligned paraboloids, Gaussians and ramps in three render regions | 144 | 884,736/884,736 | 0 | +| Oblique cases from the same render-region matrix | 18 | 95,504/110,592 | 1.01327896e-6 | + +For the 150 new rectangles, use a NumPy PCG64 generator with seed 121967. For j from 0 through 74 cycle dimensions through 64², 128×64, 64×128, 32×64 and 128². Draw two integers in [21,220) and divide by four for pixel extents. Draw two more in [−128,129) and add each sixteenth-pixel offset to the canvas center. For j < 18, after consuming these draws, replace the width by the repeating sequence 15.25, 16.5, 24 and the height by 24. Use center offsets floor(j/3)/8 and .25. From j = 60 onward replace center X by the sequence 0, 1.125, canvas width − 1.75. Render the horizontal ramp, then transpose the canvas and center with the same normalized size and a quarter turn. Use seed 241459 + 43j + orientation index. [Size and slope controls](#horizontal-stamp-slope-and-height) · [Three render regions](#pattern-coordinates-under-a-change-of-render-region) + +| Intact root | Renders | Exact pixels before | Exact pixels after / compared | Maximum U8 / U16 / F16 / F32 error after | +|---|---:|---:|---:|---| +| 59 · brick_1 | 68 | 422,109 | 427,520/427,520 | 0 / 0 / 0 / 0 | +| 60 · brick_2 | 61 | 406,666 | 408,652/409,088 | 0 / 1 / 0 / 1.52587891e-05 | +| 61 · brick_3 | 68 | 424,082 | 424,442/427,520 | 0 / 3 / 0 / 4.57763672e-05 | +| 62 · brick_generator | 74 | 149,415 | 149,508/150,528 | 175 / 45055 / 0.6875 / 1 | +| 117 · crystal_1 | 17 | 144,060 | 144,947/145,664 | 0 / 14 / 0.000244140625 / 0.000106841326 | +| 127 · directionnal_noise | 23 | 145,077 | 146,315/147,712 | 1 / 3 / 0.00048828125 / 3.36766243e-05 | +| 129 · dirt_3 | 17 | 145,359 | 145,559/145,664 | 0 / 1 / 1.52587891e-05 / 1.52736902e-05 | +| 131 · dirt_6 | 16 | 125,252 | 125,236/129,280 | 0 / 8 / 0.000244140625 / 9.27746296e-05 | +| 132 · dirt_gradient | 16 | 128,396 | 128,959/129,280 | 0 / 2 / 0.000244140625 / 1.98483467e-05 | +| 355 · pattern_brick_1 | 53 | — | 355,574/365,824 | 0 / 1 / 0 / 3.40938568e-05 | +| 356 · pattern_brick_2 | 53 | — | 344,464/365,824 | 1 / 1 / 3.81469727e-06 / 1 | +| 357 · pattern_brick_generator | 74 | 149,402 | 149,418/150,528 | 175 / 45055 / 0.6875 / 1 | + +BNW Spots 1 retains 197,288/204,288 exact pixels and BNW Spots 3 retains 180,719/185,856. Cells 1 retains 144,995/145,664. Across U8, U16, F16 and F32 the respective maximum errors are 1 / 3 / .00048828125 / .0000431537628, 1 / 2 / .00048828125 / .0000305175781 and 0 / 3 / .00048828125 / .0000367760658. Dirt 6 has 16 fewer matching U16 pixels in its 16-render matrix. Its maximum U16 error remains eight levels. Both Alveolus roots, Gradient Linear 3 and all 17 earlier verified roots retain every measured pixel. The 17-root check covers 3,139,328 pixels in 167 renders. In four interleaved single-worker release runs, median 512² cook time went from 1,076 to 1,061 ms for Alveolus and from 1,050 to 1,032 ms for Pattern Alveolus. + +For four brick roots, compare 31 additional intact renders and the same 31 after an ordinary MaterialCraft save reopened in each app. The first is an unmodified 64² U16 graph with seed 252103 + inventory index. For each subsequent tuple (width, height, tiling, smoothness, interstice), set the corresponding graph parameters. Use (32,32,1,.25,.125), (16,64,2,.375,.0625), (64,32,3,.6875,.09375), (32,128,4,.15625,.234375), (128,64,2,.53125,.1015625), (256,128,3,.8125,.15625), (128,256,1,.328125,.2109375), (256,256,2,.7265625,.03125), (512,256,3,.4375,.1171875) and (256,512,1,.5859375,.1796875). Render F32, U16, F16 and U8 for the first five tuples and F32 and U16 for the remaining five. Use seed 253309 + 37 × zero-based tuple index + inventory index + zero-based format index. + +| Root | Exact between apps before save | Exact between apps after save | Exact before versus after save in each app | Maximum U8 / U16 / F16 / F32 error between apps | +|---|---:|---:|---:|---| +| brick_1 | 855,936/856,064 | 855,936/856,064 | 856,064/856,064 | 0 / 1 / 0 / 1.52587891e-05 | +| brick_2 | 854,464/856,064 | 854,464/856,064 | 856,064/856,064 | 0 / 1 / 0 / 1.52597204e-05 | +| pattern_brick_1 | 765,834/856,064 | 765,834/856,064 | 856,064/856,064 | 0 / 1 / 0 / 3.39746475e-06 | +| pattern_brick_2 | 742,708/856,064 | 742,708/856,064 | 856,064/856,064 | 0 / 1 / 0.000122070312 / 7.27176666e-06 | + +The 256² Brick 1 case retains 64 different positions in both U16 and F32. At (112,24) the stored U16 word is 15,562 in MaterialCraft and 15,563 in the reference. Brick 2 also retains differences at the generator. With the earlier 128² case at tiling 2, seed 199591, smoothness 195/1021 and interstice 27/128, its 64² generator matches 4,076/4,096 U16 pixels, maximum error one. For each application, summing its six original beveled-square stamps in traversal order reproduces its own generator at 4,096/4,096 pixels. At generator pixel (39,19) the stamp centered at (.425,.375) returns F32 `3f53f660` locally and `3f53f64d` in the reference. Its U16 output reads 54,262 and 54,261 respectively. An independent horizontal coordinate ramp at that geometry differs, while all 32,768 vertical-control pixels over the eight visible copies match. These roots remain in progress. + +### Gradient Linear 3 and its reopened file + +Gradient Linear 3 matches 277,760/277,760 pixels across the earlier 23 renders and 569,856/569,856 across 27 additional renders. The maximum error is zero in U8, U16, F16 and F32. The reference app and MaterialCraft both reopened the ordinary MaterialCraft save. All 569,856 reopened pixels also match between apps and match their respective originals. + +The first additional case uses the authored parameters at 64² with seed 247003. For the others set the graph’s tiling, rotation index and position as follows. Number the rows from zero and use seed `246497 + 29 × row + format index`, indexing the formats in the order shown below. The 32×128 case exercises rotation index 2 on a tall output. Gradient Linear 1 still differs at 224/435,968 pixels across 47 measured renders. [Earlier settings and gradient measurements](#linear-gradient-sampling-on-rectangular-targets) + +| Size | Tiling | Rotation | Position | Formats | +|---|---:|---:|---:|---| +| 16×16 | 1 | 0 | .5 | F32, U16 | +| 32×64 | 3 | 1 | .3 | U8, U16, F16, F32 | +| 128×32 | 4 | 3 | .125 | U8, U16, F16, F32 | +| 32×128 | 1 | 2 | .875 | U8, U16, F16, F32 | +| 128×64 | 5 | 3 | .484375 | U8, U16, F16, F32 | +| 256×128 | 3 | 0 | .0625 | F32, U16 | +| 64×256 | 2 | 2 | .59375 | F32, U16 | +| 256×256 | 4 | 1 | .75 | F32, U16 | +| 512×256 | 3 | 3 | .15625 | F32, U16 | + +### Individual stamps in BNW Spots 1 + +The intact root matches 197,288/204,288 pixels across 34 recorded renders. Maximum absolute errors are 1 in U8, 3 in U16, 0.00048828125 in F16 and 0.000043153762817382813 in F32. The earlier downstream-input replacement still matches all 64,000 pixels. [Generator and downstream settings](#isolating-the-generators-in-spots-bricks-and-cells) + +Render the original graph at 32² with seed 8852 and default parameters, then at 16² with seed 8853 and disorder .15625. For each of its three pattern generators, take the centers, sizes and rotations from MaterialCraft’s procedural traversal. Render each entry separately as an additive grayscale paraboloid with both tiling axes enabled, zero roughness and its original depth-weighted opacity. Use F32 for each render. Sum in traversal order in F32, then store in U16. The 1,052 independent renders give the following counts. Each cell reports exact raw pixels over total pixels with maximum absolute error in parentheses. + +| Root setting | Generator size | Stamps | Isolated F32 stamps between apps | Reference sum against its generator | MaterialCraft sum against its generator | Intact generator between apps | +|---|---|---:|---:|---:|---:|---:| +| Default | 16² | 413 | 105,403/105,728 (8.363277e-07) | 255/256 (1) | 256/256 (0) | 251/256 (1) | +| Default | 64² | 84 | 331,046/344,064 (1.085573e-07) | 4,096/4,096 (0) | 4,096/4,096 (0) | 4,089/4,096 (1) | +| Default | 8² | 306 | 19,383/19,584 (4.470348e-07) | 64/64 (0) | 64/64 (0) | 63/64 (1) | +| Changed | 8² | 88 | 5,567/5,632 (7.115304e-07) | 63/64 (1) | 64/64 (0) | 62/64 (1) | +| Changed | 64² | 84 | 331,176/344,064 (1.260778e-07) | 4,096/4,096 (0) | 4,096/4,096 (0) | 4,082/4,096 (1) | +| Changed | 4² | 77 | 1,172/1,232 (6.146729e-07) | 16/16 (0) | 16/16 (0) | 16/16 (0) | + +On the changed 64² generator, stamp 63 (zero-based) has center (.49878266,1.0614731), size (.6508908,.5), rotation 278.50824 turns and opacity .05875. Substitute its reference contribution into the local sum. Pixel (18,6) moves from 2,127 to 2,128 and pixel (19,11) from 3,394 to 3,395. The reverse substitution restores both local values. Both apps reproduce every pixel of their own intact 64² generator from the separate stamps. The two smaller reference sums with one differing pixel and the oblique stamp coordinates remain open. + +### Reopening SBS files with release-number headers + +Save both Alveolus roots, then open each saved file as a user package in the reference app (16.0.7). With the earlier writer both files declare format version `0.1.3` and updater `0.4.1`. Both opens fail. Changing only the format revision to `1.1.0.202502` makes both files open. Changing only the updater, package identity or graph name leaves both opens failing. + +On the same saved Alveolus graph, revisions `1.1.0.201600`, `1.1.0.202101`, `1.1.0.202401` and `1.1.0.202502` all open. The three-part values `0.0.7`, `0.1.3`, `0.4.1`, `1.0.0` and `1.1.0` all fail. Explicitly enabling or disabling automatic package updates gives the same results for `0.1.3`, `0.4.1` and `1.1.0.202502`. A separate original uniform graph and an original Gaussian stamp both open with the dated revision and fail with `0.1.3`. + +MaterialCraft now writes schema `1.1.0.202401` on a first save or when replacing a three-part numeric app-release header. Files with other declared revisions retain them. The updater field records the saving workspace release. Save the intact graphs through the ordinary writer and open those exact bytes in both applications. In each app compare the reopened output with that app’s original graph output. The MaterialCraft comparison uses the preceding release-mode cooker for both inputs to isolate serialization. + +| Reopened graph | Renders | Reference before and after save | MaterialCraft before and after save | Maximum error | +|---|---:|---:|---:|---:| +| Alveolus | 25 | 681,728/681,728 | 681,728/681,728 | 0 | +| Pattern Alveolus | 25 | 681,728/681,728 | 681,728/681,728 | 0 | + +For the first eight cases use default parameters at 128²/seed 0, 256²/seed 0 and 128²/seed 42 in U16. Then enable filled cells. Use default tiling and interstice width .1 in Alveolus, and tiling 2 and width .15 in Pattern Alveolus. Render at 128²/seed 0 in U16 and at 64²/seed 42 in U8, U16, F16 and F32. The next twelve runs use the following settings. For row `j`, starting at zero, use seed `221359 + 43j + i`, where `i` is 19 for Alveolus and 353 for Pattern Alveolus. + +| Size | Format | Tiling | Filled cells | Interstice width | +|---|---|---:|---|---:| +| 16×16 | U16 | 1 | On | .1 | +| 32×16 | F32 | 1 | Off | .375 | +| 16×32 | U8 | 2 | On | .125 | +| 64×128 | F16 | 2 | Off | .015625 | +| 128×64 | U16 | 1 | On | .1 | +| 128×256 | F32 | 1 | On | .21875 | +| 256×128 | U16 | 1 | Off | .0625 | +| 256×256 | F16 | 2 | On | .1875 | +| 512×512 | U16 | 1 | On | .1 | +| 256×512 | U16 | 2 | On | .125 | +| 64×32 | F32 | 3 | Off | .28125 | +| 32×128 | F32 | 1 | On | .25 | + +The last five repeat the 32×16 row in F32, U8, U16, F16 and F32, advancing its seed by seven for each successive render. + +### Four source pixels in the filled Alveolus cells + +At 128², seed 0, enable filled cells and set the interstice width to .1. The 64×128 U16 generator matches 8,096/8,192 pixels. Each differing pixel is one level away. The final U16 output matches 16,376/16,384, with a maximum error of 1,000 levels. In the saved graph with the generator exposed as an input, edit one source word at a time. Run each of the 96 edits forward from the local field and backward from the reference field. Include the two unedited endpoints, for 194 local renders. + +| Source (x, y) | Affected final pixels (x, y) | +|---|---| +| (2, 62) | (33, 62), (97, 62) | +| (29, 62) | (62, 62), (126, 62) | +| (34, 126) | (1, 126), (65, 126) | +| (61, 126) | (30, 126), (94, 126) | + +In each row, changing 17,074 to 17,075 changes both output pixels from 46,140 to 47,140. Undoing the edit reverses both changes. Individually editing any of the other 92 differing source pixels leaves the final frame intact in both directions. Restoring the four together reproduces all 16,384 original reference pixels. Restoring the other 92 together reproduces all 16,384 original local pixels. At final position (33,62), the second blur reads 216 locally and 215 in the reference. The following Levels maps those values to 46,140 and 47,140. + +Reopen the saved graph in the reference app and run the two endpoints, the four single edits in each direction, and six further single edits in each direction. For the six controls take indices 0, 11, 29, 47, 63 and 79 in row-major order among the 96 differing source pixels. Include the two grouped edits. MaterialCraft and the reference agree on **393,216/393,216 U16 pixels across 24 renders**, maximum error zero. [Saved graph and earlier four-format controls](#alveolus-filters-after-the-first-differing-stage) + +The original generator field can also be rebuilt from two independent white Gaussian stamps on black. Use centers (.25,.25) and (.75,.75), dimensions (3,1.5), zero rotation, maximum blend and opacity .995. For each center render the nine translations (dx,dy) in {−1,0,1}² with tiling off. The pixelwise maximum gives exactly the separately rendered tiled stamp in F32 at 94,720/94,720 pixels across sixteen comparisons. Combine the two stamps and store in U16. The reconstructed field matches the intact native generator at **47,360/47,360** pixels across sizes 16×32, 128×256, 32², 8×32, 64×32, 8×64, 32×64 and 64×128. The first six sizes use seeds 178403+19j+c for zero-based size j and center c. The final two use 83+c and 223+c. On the seven sizes with individual U16 readbacks the F32-to-U16 conversion also matches 815,616/815,616 stored words. + +To isolate coordinate interpolation, draw an independent Direct3D 11 triangle for each translated stamp. In pixel space place its first vertex at the top left of its footprint, its second two footprint widths to the right, and its third two heights down. Assign signed local coordinates (−1,−1), (3,−1), (−1,3). Sample the interpolated coordinates at pixel centers, apply the [Gaussian profile](#gaussian-coverage-at-the-disc-boundary), scale by .995 and take the pixelwise maximum. At 64×128 the U16 field matches all 8,192 original pixels, including the four decisive words. In 36 individual 32×64 and 64×128 F32 renders it matches 177,291/184,320 pixels, maximum 1.08033419e−7. On the eighteen individual 64×128 U16 renders it matches 147,455/147,456, maximum one level. All individual F32 differences in this sweep belong to the first stamp at translations (−1,0) and (−1,1). + +Repeat the eight [size and format controls](#alveolus-filters-after-the-first-differing-stage) and the fifteen [square and rectangular controls](#square-and-rectangular-pattern-generators) for each root. Supply the independently rasterized U16 field to the saved graph in both apps and compare the final result to the intact reference. + +| Root | Local generator / compared | Triangle generator / compared | Final U16 with triangle / compared | Final F32 with triangle / compared | Maximum final U16 / F32 error | +|---|---:|---:|---:|---:|---| +| Alveolus | 73,051/73,760 | 73,176/73,760 | 128,968/130,048 | 18,578/18,688 | 2 / 3.05175781e−5 | +| Pattern Alveolus | 60,852/61,472 | 60,880/61,472 | 128,968/130,048 | 18,540/18,688 | 2 / 1.52587891e−5 | + +U8 and F16 each match 7,168/7,168 final pixels per root. The two apps supplied with identical triangle fields agree on all 326,144 final pixels across the 46 saved-graph renders. At the largest stage, 128×256, the current CPU matches 32,548/32,768 original generator pixels and the triangle matches 32,236/32,768. Both miss by at most one word. The general coordinate calculation and both intact roots remain open. + +### Alveolus filters after the first differing stage + +Replace the single FX-Map in each Alveolus graph with a linear U16 image input. Give the input the same size expression and storage as the FX-Map so both transformations, both blurs, both Levels and both Blends still execute with their original settings. Save the two diagnostic graphs in MaterialCraft and reopen them in the reference app. + +For each graph use the archived 128² default, 256² default, 128² seed 42 and 128² changed case, followed by the 64² changed case in U8, U16, F16 and F32 at seed 42. The changed Alveolus uses filled cells and interstice width .1. Its pattern-package counterpart uses tiling 2, filled cells and width .15. First bind the U16 output measured at the original generator stage for each case. The whole restored output matches the original reference in both applications at 131,072/131,072 pixels per graph, maximum error zero. + +Repeat the eight settings with independent procedural inputs of the same stage dimensions. At zero-based even case j, take the maximum of two periodic Gaussians centered at (z,z) for z=.21875 and .71875. At normalized pixel centers u,v use dx=((u−z+.5) mod 1)−.5 and analogously for dy. Store the nearest U16 level to 65535 exp(−11.1(dx²/.29+dy²/.11)). At odd j store (113x+79y+19xy+31j+7771) mod 65536. These eight additional renders per graph also match 131,072/131,072 pixels each. Across all 32 saved-graph comparisons the four-format counts are 16,384 U8, 475,136 U16, 16,384 F16 and 16,384 F32, all exact. In the intact generators the first differing stage still produces the [measured whole-output differences](#gaussian-coverage-at-the-disc-boundary). + +The generator coordinate also depends on the orthogonal stamp size. Use one unrotated stamp centered at y=.53125. In order, use (center X, signed width) = (.25,3), (.25,−3), (.75,3), (.376953125,.931640625), (.5,1), (.625,.5), (.375,1.5). Vary height through 1, 8 and 128. Use built-in shape IDs 4, 6, 8, 10 and 14 at zero variation, unit opacity, black background, maximum blend and no tiling. In the unit region render 32×16 and 64×16 F32. Double both dimensions for regions [−.5,1.5]² and [−1,1]². For geometry j, height index t and width index n use seed 169307+83j+7t+n. Across 630 whole stamps MaterialCraft matches 868,741/1,451,520 pixels, maximum 1.49011612e−6. + +Compare the reference scanline at physical y=.53125 between heights, holding the X coordinates fixed. For the horizontal gradient the height-1 strip agrees with height 8 at 3,022/3,360 F32 samples and with height 128 at 1,580/3,360, maximum error 1.19209290e−7 in each comparison. For the Gaussian the corresponding counts are 2,988 and 1,383 of 3,360, with maxima 4.17232513e−7 and 5.06639481e−7. In the horizontal gradient, samples at a given X repeat exactly down each drawn column in these controls. A coordinate computed solely from X, center X and width cannot reproduce all three height settings. + +### Numeric arguments in partially wired calls + +The cube intersection in `shape_splatter_compute_normal` declares position (1,1,1). On the shape-2 field that exposed the [wire-presence discrepancy](#wire-presence-inside-a-called-function), leave position open or explicitly wire (0,0,0), (1,1,1) or (.125,−.0625,.25). Keep the other connections and compare both the cube stage and the whole normal output. The reference open and zero cases agree at all 4,608 pixels of each output. Wiring the declared (1,1,1) reproduced the earlier local result. The evaluator now uses the typed zero for omitted numeric arguments when the call has a wire. The 24 comparisons match 36,864/36,864 RGBA32F pixels, maximum error zero. The nine boolean, signed integer and float types covered by the [argument controls](#connectable-numeric-arguments-in-saved-function-graphs) now match in 54/54 typed outputs, maximum error zero. + +A Set targeting the currently called function's own argument returns its typed zero and skips its operand. A Set to a free name in a child can reach an outer caller even when the intervening function has a formal of the same name. Wire .625 to the intervening formal and have the child assign .4375. The intervening function reads .625 and its caller reads .4375. Put another free Set in the operand of a formal assignment and observe it after the call in both a pixel and a value graph. All 5,120/5,120 F32 pixels and 8/8 typed outputs in the operand controls match, maximum error zero. Of the 224 earlier [wire and scope tests](#wire-presence-inside-a-called-function), 220 now match. The four remaining outputs read a wholly open argument with an authored default of .1875. MaterialCraft retains its live source-default behavior for such calls. Separate nested controls also find a free read of an enclosing formal where the reference reads zero. The two new evaluator regressions failed before the changes. All 262 release node tests, strict workspace Clippy, formatting, layers and WebAssembly passed. + +| Whole normal root | Renders | Exact pixels / compared | Maximum finite error | +|---|---:|---:|---:| +| Previous default, changed and precision cases | 19 | 142,592/142,592 | 0 | +| Independent rectangular and stepped fields | 10 | 11,520/11,520, previously 9,811 | 0 | +| Single-setting and displacement controls on the shape-2 field | 31 | 63,488/63,488, previously 32,726 | 0 | +| Twelve shape modes at four output formats | 48 | 48,968/49,152, previously 45,000 | 1.19209290e−7 in F32 | +| Total | 108 | 266,568/266,752 | 1.19209290e−7 | + +The saved graph also matches all 11,520 pixels on the independent fields. The seven saved diagnostic outputs match 34,048/34,048 pixels on the original stage controls. Stored NaN payloads agree on all 26 lanes in the original half-float case, 7,680 lanes on the independent fields, 36,864 in the single-setting controls and 33,792 across the twelve-mode sweep. Each of U8, U16 and F16 matches 12,288/12,288 pixels in the twelve-mode sweep. F32 matches 12,104/12,288. + +To reproduce the twelve-mode sweep, take mode j = 0…11. Cycle output size through 16×32, 32×16, 32×32 and 64×32. For input t = 0…7 and channel c, compute q = ((79x + 173y + 11xy + 109t + 37c + 53j) mod 1021)/1020 and b = (floor(x/3) + 2floor(y/2) + t + c + j) mod 5. Use .8125+.09375q if b=0, .125+.1875q if b=1, otherwise .4375+.125q. In the six RGBA inputs use alpha zero if (x+3y+7t+j) mod 11 is zero, otherwise one if b=2, otherwise .71875+.125q. Store the eight procedural inputs in U8, U16 or F32 according to j mod 3, rounding integer inputs to nearest. For output format index p = 0…3 in U8, U16, F16, F32 order use seed 167057+19j+p. Set the shape to j, normal format to j mod 2, displacement on when j mod 3 = 0, rotation to ((j mod 5)−2)×.0625, extrusion height to .375+j/32, nonsquare expansion on when j mod 4 = 1, pattern count to 1+(j mod 3), and atlas size to (2+(j mod 2),2). + +The one remaining mismatch in this sweep is the 64×32 F32 shape-3 render, with 1,864/2,048 pixels exact. On the same eight inputs, setting only the shape to 3 gives 1,856/2,048 exact. Each of the other eleven modes matches all 2,048 pixels with the same inputs and remaining settings. Across five stage controls the sampled input, active flag, ray distance, atlas index, cube normal and stored object normal each match 10,240/10,240 pixels. The vector before encoding matches 7,372/10,240, maximum error 2.38418579e−7. The root remains in progress. + +### Component rounding in the shape splatter normal + +All 292,864 whole pixels match across 144 renders of `shape_splatter_compute_normal`, including defaults, the twelve shape modes, both normal formats, alternate seeds and the six new fields below. By output storage the totals are 137,472 RGBA8, 23,296 RGBA16, 26,880 RGBA16F and 105,216 RGBA32F. Maximum error is zero in each format. All 78,362 NaN components match in their stored bits, including sign and payload. The independently saved package also matches 11,520/11,520 pixels when reopened on the ten [earlier fields](#numeric-arguments-in-partially-wired-calls). Those repeats are outside the 144 renders. + +The first different intermediate in the curved shape was a three-component quotient plus (0,0,−.5). Another branch selected only the first two components of the quotient. At pixel (3,0) in the 64×32 F32 shape-3 case, the Z numerator and denominator have bits `3e58d8d9` and `3eececed`. The quotient matches at `3eea4e1a`. Rounding it before subtracting .5 gives `bd2d8f30`. The reference gives `bd2d8f2f`. The evaluator now delays rounding of the unselected components through their sum when the additional readers are swizzles. It retains the rounded value of each selected component and guards loop-dependent operands. The twelve-mode test improves from 48,968 to 49,152/49,152 pixels. The 22 separate 64×32 F32 whole renders that omit individual controls or vary the shape match 45,056/45,056. The six intermediate results from the hit position through the encoded normal match 36,864/36,864, and the ten projections of the normal calculation match 61,440/61,440. Each maximum is zero. + +For the 36 new whole renders number the fields h=0…5, with dimensions 16², 32×16, 16×32, 32², 64×16 and 16×64. Use eight linear inputs, six RGBA and two gray. For input t and component c, set q = ((53x+109y+31xy+127t+77c+83h+13tx+7cy) mod 4093)/4092 and p = (floor(x/(1+h mod 3))+floor(y/(2+h mod 2))+3c+t) mod 6. Use .09375+.21875q for p<2, .8125+.125q for p=4 and .375+.28125q otherwise. For alpha use zero when (3x+y+t+h) mod 13 is zero and .25+.703125q elsewhere. In field 4 transform the first two RGB inputs by 2.25v−.4375. Store the six fields in U16, F32, U8, U16, F32 and U8 respectively, rounding integer inputs to nearest. Use seed 174431+29h+shape. Render shapes 2 and 4 in F32 and shape 3 in all four formats. Set rotation about the normal to (h−2)×.09375, extrusion height to .28125+.125h, symmetry on for even h, displacement on for h mod 3 ≠ 1, normal format to h mod 2, nonsquare expansion on for h mod 3 = 1, background opacity to .1875+.09375h, X/Y counts to 2+(h mod 3) and 3+(h mod 4), and amount to 6+h. All 26,112 pixels match. + +An independent Pixel Processor reads a linear RGBA32F field at half the output width and height through a nearest sample. Generate input component c as (((79x+47y+11xy+113c+37xc+53yc) mod 1021)+79)/411. Form Q from RGB multiplied or divided componentwise by GBA. Output Q+(−.375,.3125,−.5) in RGB. For alpha use one, Q.x, Q.y, Q.z, or the dot product of a swizzle of Q with a vector of ones. Test xy, zx, yz, yy and xyz. Use 32×16 and 16×32 F32 followed by 32² U16 and F16, with seed 172363+13j. This improves 47,408 to 50,408/55,296 pixels across 72 renders. All 36,864 integer and half-float pixels match. Multi-component dot products with distinct indices still differ in F32, maximum 9.53674316e−7. The two other inventory roots with this shared vector-operation pattern, Triangle Grid Base and Shape Mapper, retain all 171,264 and 310,784 exact pixels in 18 and 29 renders respectively. + +### Rectangular fields in the two brick-generator Tile helpers + +Both Tile helpers matched their four earlier U16 cases, 114,688 pixels each. New rectangular fields expose differences in each helper. For a 16×32 and 32×16 U16 input set the stored level at (x,y) to (1471x + 317y + 71xy + 17) mod 65536. Test defaults, then input image, square, disc, paraboloid and Gaussian patterns in that order. On the changed cases set the X/Y counts to (3,5), scale to .8125, offset to .375, global offset to (.125,−.0625) and opacity to .6875. Render each case in U8, U16, F16 and F32. Use seed 171443 + 11j + width, with defaults at j=0. + +| Pattern | Exact / 4,096 pixels, brick generator | Exact / 4,096 pixels, pattern brick generator | +|---|---:|---:| +| Defaults | 4,096 | 4,096 | +| Input image | 4,076 | 4,012 | +| Square | 4,076 | 4,012 | +| Disc | 4,096 | 4,096 | +| Paraboloid | 3,635 | 3,638 | +| Gaussian | 3,598 | 3,620 | + +The first helper matches 23,577/24,576 new pixels and the second 23,474/24,576. Each has maximum errors of 175 U8 levels, 45,055 U16 levels, .6875 F16 and .6875 F32. For a square the first 16×32 F32 result differs at five pixels and the 32×16 result matches. The other helper differs at 18 and three respectively. The paraboloid and Gaussian have much smaller F32 differences, at most 1.11758709e−6. In the reference app, independently named files saved by MaterialCraft reproduce all 24,576/24,576 original reference pixels for each helper, zero maximum error across the four formats. The two inventory rows are in progress. + +### The lower edge of an axis-aligned stamp + +For an axis-aligned stamp, subtract the radius from the center before comparing the open edge to the sample. On a 32×16 target, draw a square with extents (.4,.3). Put its left edge through the center of pixel (14,9), keeping Y centered on the pixel. Repeat with its top edge through that center and X centered on the pixel. The reference excludes the pixel in both cases and draws the next interior pixel. Subtracting the stamp center from the sample first rounded these decimal extents differently and included the edge. The regression failed on the original calculation. + +| Original square and Tile comparisons | Renders | Exact pixels before | Exact pixels after | Maximum error after | +|---|---:|---:|---:|---| +| Edge displacements near pixel centers | 180 | 184,234/184,320 | 184,270/184,320 | 1 F32 | +| Independent sizes in the unit and expanded regions | 240 | 639,412/640,000 | 639,544/640,000 | 1 F32 | +| Independent quarter turns and signed dimensions | 192 | 490,782/491,520 | 490,944/491,520 | 1 F32 | +| Square edges at ten positions in each orientation | 280 | 142,892/143,360 | 142,892/143,360 | 1 F32 | +| Square and two horizontal gradients, with and without tiling | 288 | 157,302/196,608 | 157,302/196,608 | 1 F32 | +| Two Tile helpers, rectangular four-format suite | 96 | 47,051/49,152 | 47,147/49,152 | 175 U8 / 45,055 U16 / .6875 F16 / .6875 F32 | +| Same Tile helpers, individual controls at 16×32 | 44 | 22,197/22,528 | 22,294/22,528 | 1 F32 | + +Every raw pixel that changed in these seven groups moved to the reference value. In the [four-format suite](#rectangular-fields-in-the-two-brick-generator-tile-helpers) the pattern-package Tile helper now matches 4,060/4,096 pixels on each of its image and square patterns, up from 4,012. The other helper retains its measured counts. For the 22 F32 controls per helper, start with the 16×32 square settings from that suite. Test all controls together and defaults, then omit each control alone and set each alone. Finally set X/Y counts to (1,1), (1,5), (3,1), (2,2), (4,4) and (3,5) with all other square settings. Including those cases and the four archived renders gives 149,415/150,528 for the first helper and 149,402/150,528 for the pattern-package helper. Both roots remain in progress. A single unrotated square at (.625,.4375), dimensions (.8125,.8125), reproduces the first helper's one-tile mask. The remaining difference covers 26 pixels in the first column of the 16×32 target. + +To reproduce the first row, use an unrotated square, black background, unit opacity, maximum blend and tiling off. Use (width,height,size X,size Y) = (16,32,.3125,.5625), (32,16,.4,.3) or (64,32,−.421875,−.28125). Choose the center of pixel (width/2−2,height/2+1). Center the stamp there on one axis and move its lower or upper edge there on the other. Add each of 0, ±1/64, ±3/1024, ±1/512, ±1/1024, ±1/8192, ±1/65536 and ±1/1048576 pixel to the moved center. Use seed 178667+91j+17e+t, with zero-based geometry j, edges left/right/top/bottom in that order and t indexing the displacements in ascending order. Output is F32. + +For the 240-render sweep use geometries j=0…23 with dimensions cycling through 16×32, 32×16, 64×32, 32×64, 16² and 64×16. Choose pixel x=1+((3+11j) mod (width−2)), y=1+((5+7j) mod (height−2)). Set the absolute extents to .22+((71j+19) mod 113)/171 and .16+((31j+47) mod 89)/131. Negate X when j mod 3 = 1 or Y when j mod 3 = 2. Choose edge j mod 4 in the order above. Use displacements [−1/65536,−1/1048576,0,1/1048576,1/65536] pixel and seed 184237+59j+t. Render the unit region and the same geometry in [−.5,1.5]² at twice both dimensions. The 192 rotation controls repeat both regions with j=0…31, dimensions cycling through 32², 16×32, 32×16 and 32×64, selected pixel ((5+7j) mod (width−1),(7+11j) mod (height−1)) and edge floor(j/2) mod 4. Use physical extents .21+((199j+37) mod 719)/961 and .18+((59j+67) mod 317)/503 rounded to F32. Select turns [0,.25,.5,−.25] by (j+floor(j/4)) mod 4, exchange the authored extents on odd quarter turns, and negate authored X or Y when j mod 3 is zero or one respectively. Use displacements [−1/1048576,0,1/1048576] and seed 186103+23j+t. + +For the 280 position controls, vary the horizontal width over 2, 5, 8, 11, 13, 16 and 21 pixels on a 16×32 target. Keep the vertical extent .8125 and center Y=.4375. Put the left or right edge on pixel centers 0, 1, 2, 3, 5, 7, 8, 11, 14 and 15. Transpose everything for the vertical cases. Use seed 183271+53×extent+pixel. All 140 lower edges exclude the anchored sample. The upper edge excludes 18 of the 140 samples. In either orientation it excludes position 0 at extents 5 and 13, positions 0–2 at extent 11, and positions 0–3 at extent 21. Those clipped upper edges remain an independent discrepancy. + +All 17 previously verified inventory roots with a reachable FX-Map retain 3,139,584/3,139,584 pixels across 168 equal-resolution checks, maximum zero. The previously documented mixed-resolution Position Debug control still differs at 20/256 pixels. The two Alveolus whole matrices also retain their [previous counts](#gaussian-coverage-at-the-disc-boundary). All 264 release node tests, formatting, strict workspace Clippy, dependency layers and WebAssembly passed. + +### Isolating the generators in spots, bricks and cells + +Six roots use one to three pattern fields before their final filters. Replace each source in a copy of the root with a U16 grayscale input bridge. Keep the original size and format expressions, downstream wires and final format. Save each graph with MaterialCraft, reopen it in the reference app and compare every output pixel at its stored precision. Use the square cases in their listed order followed by the seven rectangular cases where present. [Original settings, dimensions and seeds](#square-and-rectangular-pattern-generators) + +| Inventory index and root | Source node UIDs in slot order | Renders with all sources supplied | Exact output pixels | Maximum error | +|---|---|---:|---:|---:| +| 57 · Black and white spots 1 | `1065025864`, `1065025865`, `1065025871` | 30 | 64,000/64,000 | 0 | +| 58 · Black and white spots 3 | `1083436001`, `1083436013`, `1086975888` | 16 | 27,136/27,136 | 0 | +| 59 · Brick 1 | `1041346037` | 30 | 64,000/64,000 | 0 | +| 60 · Brick 2 | `1041346033` | 16 | 27,136/27,136 | 0 | +| 61 · Brick 3 | `1035248938`, `1065200619` | 30 | 64,000/64,000 | 0 | +| 67 · Cells 1 | `1051010199` | 16 | 27,136/27,136 | 0 | + +Each setting has two inputs for each generator slot. First supply its measured native stage from the intact root. On these 69 cases, the reopened reference matches all 136,704 pixels of the intact reference. Then supply an independent field at the same resolution. For zero-based setting j and slot b, use integer pixel coordinates x,y. At j mod 3 = 0 use (709x + 571y + 139xy + 983b + 271j + 91bx) mod 65536. At j mod 3 = 1 use 32769 + 7b where (5x + 3y + b + j) mod 11 = 0 and 32767 − 7b elsewhere. At j mod 3 = 2 use 58913 − 331b where (x + 3b) mod 13 = (y + 2j) mod 13 and 977 + 419b elsewhere. Across the two input families all 273,408 pixels agree in U8, U16, F16 and F32. + +For the three roots with multiple sources, restore one measured source at a time and let the other generators run. All 99 reopened reference renders match their intact originals, 200,704/200,704 pixels. The table gives the raw MaterialCraft comparison against the reopened reference. + +| Root | Restored slot | Renders | Exact output pixels | Maximum U8 / U16 levels | Maximum F16 / F32 error | +|---|---:|---:|---:|---:|---:| +| Black and white spots 1 | 0 | 15 | 31,453/32,000 | 1 / 2 | 0.000244140625 / 4.31537628e-05 | +| Black and white spots 1 | 1 | 15 | 31,138/32,000 | 1 / 3 | 0.00048828125 / 4.31537628e-05 | +| Black and white spots 1 | 2 | 15 | 31,613/32,000 | 0 / 2 | 0.00048828125 / 2.16364861e-05 | +| Black and white spots 3 | 0 | 8 | 13,157/13,568 | 0 / 1 | 0 / 2.7179718e-05 | +| Black and white spots 3 | 1 | 8 | 13,207/13,568 | 0 / 1 | 0 / 2.7179718e-05 | +| Black and white spots 3 | 2 | 8 | 13,452/13,568 | 0 / 1 | 0 / 1.53183937e-05 | +| Brick 3 | 0 | 15 | 32,000/32,000 | 0 / 0 | 0 / 0 | +| Brick 3 | 1 | 15 | 31,914/32,000 | 0 / 1 | 0 / 0 | + +For Brick 3, supplying the first field corrects every tested output. Supplying only the second leaves 86 U16 pixels one level off on the 128×32 case. Both spots graphs still differ when any one of the three fields is supplied. The whole-root inventory continues to report the intact graphs. + +### Root checks after clipping Gaussian stamps + +A scan of the reachable pattern nodes in the 546 inventory graphs found 61 roots with an explicit Gaussian or a variable stamp type. The table reports the previous whole-root captures compared again after the [disc cutoff](#gaussian-coverage-at-the-disc-boundary). It includes the archived authored defaults, changed controls and seeds, the available four-format and independent-field captures, and the earlier square/rectangular sets where present. The inventory links the wider matrices for individual roots. Some dynamic selectors choose other shapes in these cases. The table records measured output agreement across all completed outputs. Dirt Gradient and Wood Fibers 2 also encountered the recorded evaluation budget in the rows marked with an asterisk. The [new rectangular Tile cases](#rectangular-fields-in-the-two-brick-generator-tile-helpers) are additional measurements. + +| Inventory index | Root | Cases | Exact / compared pixels | Maximum U8 / U16 / F16 / F32 error | +|---:|---|---:|---:|---| +| 19 | `alveolus.sbs/alveolus` | 41 | 332,280/334,336 | 0 / 1000 / 0 / 3.05175781e-05 | +| 62 | `brick_generator.sbs/resources/Tile` | 4 | 114,688/114,688 | — / 0 / — / — | +| 127 | `directionnal_noise.sbs/directionnal_noise` | 23 | 145,077/147,712 | 1 / 3 / 0.00048828125 / 3.36766243e-05 | +| 132 | `dirt_gradient.sbs/dirt_gradient` | 16 | 128,396/129,280 | 0 / 2 / 0.000244140625 / 1.98483467e-05 | +| 137 | `fibers_1.sbs/fibers_1` | 9 | 130,217/132,096 | 0 / 1 / 3.05175781e-05 / 1.52587891e-05 | +| 155 | `fur_1.sbs/fur_1` | 9 | 121,609/132,096 | 1 / 2 / 0.00048828125 / 3.05175781e-05 | +| 156 | `fur_2.sbs/fur_2` | 9 | 121,041/132,096 | 1 / 1 / 0.000244140625 / 6.7949295e-06 | +| 160 | `gaussian_1.sbs/gaussian_1` | 9 | 130,730/132,096 | 0 / 2 / 0 / 1.52587891e-05 | +| 161 | `gaussian_2.sbs/gaussian_2` | 9 | 131,076/132,096 | 0 / 1 / 0 / 1.52587891e-05 | +| 163 | `gaussian_spots_2.sbs/gaussian_spots_2` | 9 | 124,083/132,096 | 1 / 1 / 0.000244140625 / 5.15580177e-06 | +| 202 | `make_it_tile_patch.sbs/make_it_tile_patch` | 9 | 132,090/132,096 | 1 / 93 / 0.00146484375 / 0.00212101638 | +| 203 | `make_it_tile_patch_grayscale.sbs/make_it_tile_patch_grayscale` | 9 | 132,092/132,096 | 0 / 47 / 0.000732421875 / 0.00105287135 | +| 206 | `me_water_level.sbs/scratches_2` | 9 | 126,034/132,096 | 1 / 2 / 0.00048828125 / 1.98483467e-05 | +| 223 | `messy_fibers_4.sbs/messy_fibers_4` | 8 | 85,783/115,712 | 1 / 200 / 0.00048828125 / 7.62939453e-05 | +| 224 | `microscope_view.sbs/microscope_view` | 9 | 131,223/132,096 | 0 / 60 / 0.000244140625 / 1.52606517e-05 | +| 236 | `noise_bnw_spots_1.sbs/bnw_spots_1` | 9 | 3,214/132,096 | 1 / 5957 / 0.0029296875 / 0.0030413866 | +| 237 | `noise_bnw_spots_1_v2.sbs/bnw_spots_1` | 9 | 41,776/132,096 | 16 / 10 / 0.00048828125 / 0.000160634518 | +| 241 | `noise_cells_1_v2.sbs/cells_1` | 9 | 132,092/132,096 | 1 / 0 / 0 / 0 | +| 257 | `noise_directional_noise_4.sbs/directional_noise_4` | 9 | 126,388/132,096 | 0 / 1 / 0 / 2.89082527e-06 | +| 258 | `noise_directional_noise_4_v2.sbs/directional_noise_4` | 9 | 127,092/132,096 | 1 / 1 / 0.00048828125 / 2.38418579e-06 | +| 270 | `noise_dirt_gradient.sbs/dirt_gradient` | 9 | 131,270/132,096 | 0 / 1 / 0.000244140625 / 1.52587891e-05 | +| 271 * | `noise_dirt_gradient_v2.sbs/dirt_gradient` | 9 | 110,035/115,712 | 10 / 578 / 0.0087890625 / 0.0088198483 | +| 278 | `noise_fur_1.sbs/fur_1` | 9 | 111,105/132,096 | 1 / 2 / 0.00048828125 / 2.7179718e-05 | +| 279 | `noise_fur_2.sbs/fur_2` | 9 | 119,335/132,096 | 1 / 2 / 0.000244140625 / 1.35600567e-05 | +| 280 | `noise_fur_3.sbs/fur_3` | 9 | 120,953/132,096 | 1 / 1 / 0.000244140625 / 1.26212835e-05 | +| 281 | `noise_gaussian_noise.sbs/gaussian_noise` | 9 | 125,703/132,096 | 0 / 1 / 0.000122070312 / 3.57627869e-07 | +| 282 | `noise_gaussian_noise_v2.sbs/gaussian_noise` | 9 | 127,129/132,096 | 1 / 1 / 0.000244140625 / 5.96046448e-07 | +| 285 | `noise_gaussian_spots_2.sbs/gaussian_spots_2` | 9 | 122,726/132,096 | 1 / 1 / 0.000244140625 / 1.37090683e-05 | +| 286 | `noise_gaussian_spots_2_v2.sbs/gaussian_spots_2` | 9 | 126,481/132,096 | 1 / 1 / 0.000244140625 / 1.42455101e-05 | +| 287 | `noise_liquid.sbs/liquid` | 9 | 127,452/132,096 | 1 / 268 / 0.0009765625 / 0.000885009766 | +| 294 | `noise_microscope_view.sbs/microscope_view` | 9 | 130,081/132,096 | 1 / 48 / 0.000183105469 / 0.000137329102 | +| 300 | `noise_plasma.sbs/plasma` | 9 | 129,346/132,096 | 0 / 2 / 0.000122070312 / 1.52885914e-05 | +| 350 | `paths_tools.sbs/paths_trace` | 9 | 18,297/18,432 | 120 / 30822 / 0.62109375 / 1.22619528 | +| 353 | `pattern_alveolus.sbs/alveolus` | 33 | 201,876/203,264 | 0 / 2 / 0 / 1.52587891e-05 | +| 354 | `pattern_arc_pavement.sbs/arc_pavement` | 9 | 132,096/132,096 | 0 / 0 / 0 / 0 | +| 357 | `pattern_brick_generator.sbs/resources/Tile` | 4 | 114,688/114,688 | — / 0 / — / — | +| 361 | `pattern_fibers_1.sbs/fibers_1` | 9 | 130,217/132,096 | 0 / 1 / 3.05175781e-05 / 1.52587891e-05 | +| 362 | `pattern_fibers_2.sbs/fibers_2` | 9 | 128,900/132,096 | 0 / 2 / 0 / 3.05175781e-05 | +| 363 | `pattern_gaussian_1.sbs/gaussian_1` | 9 | 130,730/132,096 | 0 / 2 / 0 / 1.52587891e-05 | +| 364 | `pattern_gaussian_2.sbs/gaussian_2` | 9 | 131,076/132,096 | 0 / 1 / 0 / 1.52587891e-05 | +| 369 | `pattern_shape.sbs/shape_base` | 9 | 130,383/132,096 | 0 / 1 / 0.00048828125 / 1.37090683e-06 | +| 370 | `pattern_splatter_circular.sbs/splatter_circular` | 9 | 130,916/132,096 | 223 / 57311 / 0.874511719 / 0.921568625 | +| 371 | `pattern_splatter_circular.sbs/splatter_circular_color` | 9 | 130,715/132,096 | 254 / 65535 / 0.996078491 / 0.996078431 | +| 373 | `pattern_tile_generator.sbs/tile_generator` | 9 | 130,546/132,096 | 0 / 1 / 0 / 0 | +| 374 | `pattern_tile_generator.sbs/tile_generator_color` | 9 | 128,338/132,096 | 0 / 1 / 0 / 0 | +| 375 | `pattern_tile_random.sbs/tile_random` | 9 | 132,096/132,096 | 0 / 0 / 0 / 0 | +| 376 | `pattern_tile_random.sbs/tile_random_color` | 9 | 132,096/132,096 | 0 / 0 / 0 / 0 | +| 418 | `perlin_noise_zoom.sbs/perlin_noise_zoom` | 9 | 126,082/132,096 | 0 / 1 / 0.000244140625 / 5.66244125e-07 | +| 463 | `scratches_1.sbs/scratches_1` | 9 | 125,454/132,096 | 0 / 3 / 0.00048828125 / 1.63316727e-05 | +| 464 | `scratches_2.sbs/scratches_2` | 9 | 112,902/132,096 | 1 / 2 / 0.00048828125 / 2.07424164e-05 | +| 466 | `shape.sbs/shape_base` | 9 | 130,383/132,096 | 0 / 1 / 0.00048828125 / 1.37090683e-06 | +| 489 | `splatter_circular.sbs/splatter_circular` | 9 | 130,443/132,096 | 222 / 57311 / 1 / 1.00000006 | +| 490 | `splatter_circular.sbs/splatter_circular_color` | 9 | 130,794/132,096 | 247 / 65535 / 0.96862793 / 0.996078431 | +| 520 | `tile_generator.sbs/tile_generator` | 9 | 129,318/132,096 | 0 / 1 / 0.00048828125 / 4.88758087e-06 | +| 521 | `tile_generator_color.sbs/tile_generator_color` | 9 | 127,043/132,096 | 0 / 1 / 0.0009765625 / 4.88758087e-06 | +| 522 | `tile_random.sbs/tile_random` | 9 | 105,004/132,096 | 223 / 57311 / 1 / 1.00000006 | +| 523 | `tile_random.sbs/tile_random_color` | 9 | 105,004/132,096 | 250 / 65535 / 1 / 1.00000006 | +| 534 | `vertical_noise.sbs/vertical_noise` | 9 | 131,620/132,096 | 0 / 2 / 0.000244140625 / 1.69873238e-05 | +| 535 | `waveform_01_v2.sbs/waveform_01_v2` | 9 | 124,848/132,096 | 255 / 0 / 0 / 0 | +| 536 | `waveform_1.sbs/waveform_1` | 9 | 131,931/132,096 | 0 / 1 / 0 / 0 | +| 545 * | `wood_fibers_2.sbs/wood_fibers_2` | 8 | 46,058/50,176 | 1 / 4 / 0.0009765625 / 8.55624676e-05 | + +## 2026-11-19 root comparisons + +### Texture sampling in pattern functions + +The Bevel Smooth debug position root matches **354,560/354,560 RGBA pixels in 38 renders**, maximum error zero. This includes 12,288 pixels in each of U8, U16 and F16 and 317,696 in F32. Previously the 22 recorded cases matched 285,715/285,952 and the 16 offset controls matched 68,394/68,608. At 64² on the [position field](#segment-mapping-and-normal-graph-rechecks), the incoming image was exact but the last FX-Map drew a 17-pixel diagonal at x=22…38, y=x+9. Its texture read determined the location and angle. The upstream processor, both FX-Maps and the input and output bridges now match 368,640/368,640 pixels across 18 renders comparing those graph outputs. + +A pattern function wraps both axes when sampling an image, including when output tiling is disabled. A nearest read on an exact negative texel boundary takes the preceding texel. For example, (−.125,−.25) in a 32² image selects (27,23). The [value-function filter](#value-processor-texture-filtering) also applies to pattern reads. Its bilinear fractions retain F32 precision. For a gray read from a color source, filter each channel and then evaluate ((G+B)+R) × float32(1/3). + +| Original sampler controls | Renders | Previously exact pixels | Exact / compared | Maximum error | +|---|---:|---:|---:|---:| +| Nearest and bilinear, color and gray, plus a disconnected sampler | 90 | 190,720 | 422,400/422,400 | 0 | +| Four input formats, signed coordinates and both output tiling settings | 208 | 36,864 | 212,992/212,992 | 0 | +| Separate Value Processors, U8 and F32 sources | 52 | — | 52/52 Float4 values | 0 | + +For the first row, fill a square stamp from the sampled color, or broadcast the sampled luminosity with alpha one. Use source (x/N, y/N, ((47x+31y+7xy+13) mod 257)/256, 1). For N=16,32,64,128 read (.5,.5) at 16 and (.3125,.6875) at the other sizes. At 64² place a sample (.25,.5,.75,.999 or .001) texels past (20,44) on both axes. Also sample (−.125,.4375), (1.125,1.625), (0,0), (1,1), (.199,.78125) and (.49999,.50001). Finish with (.1234567,.7654321) at 32², (.4891,.9125) at 128² and (.103,.253) at 16². Seeds start at 3877 and increase by 17. Repeat on an empty second image socket with the nearest color sampler. + +For the second row use a 32² field with RGB level L=((47x+31y+7xy+13+c(29+3x)) mod 251) in channel c and alpha level 255. For U16 multiply all four levels by 251. For F16/F32 take (L−99.3125)/31.375 and alpha one. Test color and gray in both sampling modes with transparent black behind the stamp. In order, use (−.125,−.25), (−4.001,−7.999)/32, (0,0), (1,−1), (2.25,−1.625), (.3125,.6875), (.5,6.5)/32, (.0013121,.998713), (.71897,.39151), (.625,.427), (−.12,.016), (1.0311,−.65315) and (.920211,.090037). Start at seed 3989 plus the storage index in U8/U16/F16/F32 order and add 11 per coordinate. Enable tiling when the storage index plus the bilinear and grayscale flags is odd. At (.71897,.39151) the U8 bilinear red has F32 bits `3e90e1aa` and its luminosity has bits `3ef8d016`. The separate value graphs use the same coordinates and return the color directly. + +For the 16 additional Bevel renders set position offset (1,1) and supply the constant RGBA32F field (p.x+d.x, p.y+d.y, .375, a). Default to p=(.3125,.6875), a=1, debug mode on, 64² F32. Start with p=(.5,.5) at 32² and d=(0,0), then the default p with d=(0,0). Use d=(.1875,−.1875) in all four formats, then (.1875,.1875), (.1875,0) and (0,.1875). Repeat (.1875,−.1875) with a=0, then at 128² and 32² with a=1. For the mode-off cases use p=(.25,.75), d=(.0625,.0625) and then d=(−.125,.375), a=.5 at 32². Finish with p=(.25,.75), d=(−.2,.3) and the default p with (.1875,−.1875), mode on. Seed j is 3659+17j, starting at j=0. + +Standalone signed rectangles and discs still render at both signs of either size component. The 60 color/gray rectangle and gray disc renders match 310,272/310,272 pixels. At 64² a rectangle centered at (.4766544,.6173407), size (.37573713,−.01), rotated −.37499994 turns covers 17 pixels in both applications. A separate directional gradation on the same five geometries and four sign combinations matches 103,316/103,424 pixels. Its maxima are 0 U8, 1 U16, .00006103515625 F16 and .00000011920929 F32. + +### Diffuse and specular outputs of the mesh material graph + +Both material outputs match across **42 renders and 46 output images**, totaling **358,912/358,912 RGBA pixels**. The four archived renders each supply both outputs. The two four-format sweeps, two independent 32² cases and 28 additional renders each select one output. The same inputs before the [Add Sub rounding fix](#source-alpha-rounding-in-highpass) gave 340,909/358,912 exact pixels. Maximum component errors were zero U8 levels, one U16 level, zero F16 and 1.19209290e−7 F32. + +| Output storage | Exact pixels / compared | Maximum error | +|---|---:|---:| +| RGBA8 | 245,760/245,760 | 0 | +| RGBA16 | 16,384/16,384 | 0 | +| RGBA16F | 16,384/16,384 | 0 | +| RGBA32F | 80,384/80,384 | 0 | + +Each new render reads the selected output, all 15 filters and all five input bridges. All 1,576,200 pixels across those 588 images match. To reproduce the inputs set H=((31x+53y+7xy+23v+67c+3cy+19) mod 509)/508 for channel c. In order, assign v=0–4 to diffuse, specular, world-space normal, occlusion and curvature. The last two use channel zero. For the normal set X=.625(H₀−.5), Y=.75(H₁−.5), Z=sqrt(1−X²−Y²), then encode (.5+.5X,.5+.5Y,.5+.5Z,1). Supply original F32 images on all five ports. + +The four controls below are pre-lighting, occlusion, edge sharpness and specular occlusion in that order. For each output start at 16² F32 with defaults. Render 64² in U8, U16, F16 and F32 with (.3125,.6875,.4375,.5625). At 32² F32 set just one control to .625 in each of four renders. At 128² F32 use (.8125,.1875,.75,.375) and opaque diffuse and specular. Next use (.1875,.8125,.25,.875) for a 32×16 source at 32², then a 32² source with diffuse and specular RGB equal to 2.5H−.625. Finish with two 64² F32 renders using the original four controls, first with a flat normal (.5,.5,1,1), then with the original normal. Each series starts at seed 6761 and advances by 17. + +The same change also reaches other unresolved roots. On the independent 32² F32 input, BW Spots 3 matches 629/1,024 pixels (maximum 3.91006470e−5), Normal to Height 270/1,024 (.305256728), Polygon 2 1,012/1,024 (.0000152587891), Slope Blur 0/1,024 (.768627450), and each grayscale Slope Blur 12/1,024 (.329411790). The other BW Spots 3 graph exceeds the pattern execution budget. Symmetry Slice matches its independent 1,024 pixels but only 11,445/16,384 on the changed four-format input. [Independent inputs and controls](#four-format-inventory-comparison) + +### Global blend opacity in Normal to Height + +Normal to Height matches **145,664/145,664 stored pixels across 18 renders**. U8 contributes 5,120 pixels in two renders, U16 121,856 in seven, F16 5,120 in two and F32 13,568 in seven. Each format has zero maximum error. For the 11 renders with stage outputs recorded before and after the fix, the earlier build matched 3,201/18,688 final pixels. At each of 92 reachable stages whose inputs and output fit within 128², the previous result was 2,181,843/2,796,800. The corrected result is 2,796,800/2,796,800, maximum zero across all 1,012 intermediate images. + +The two earliest differences were 16² U16 Add Sub blends fed by transforms. Both inputs matched at both stages in all 11 renders. At a computed global opacity of 6.000000476837158, foreground 35,122 and background 32,767 give 37,476. A second foreground of 32,767 gives 32,766. Applying the authored opacity directly gave 61,021 and 32,761. The blend caps global opacity to [0,1] before applying the mask. With the same two inputs and F32 mask values 73/255 and 126/255 the expected levels are 34,115 and 32,767. The measured bound applies to the nine native blend modes, Copy through Divide. It is applied during rendering. Ordinary saves retain the authored opacity expression. + +Use the four inventory renders at 128² and 256², seeds 0 and 42. The changed controls are normal format 1, relief balance (.2,.6,.8) and global opacity .6. The four 64² formats and the independent 32² field supply five further renders. For the nine additional inputs, start with tangent components R=((17x+23y+3xy) mod 31−15)/32 and G=((11x−7y+5xy) mod 29−14)/32. Store (.5+.5R,.5+.5G,.5+.5sqrt(1−R²−G²),1). Round U8 sources to the nearest byte with even ties. A flat field uses R=G=0. The impulse field is flat except for R=.625 at (16,16) and G=−.375 at (10,8). The following rows give every added run. [Four-format inventory comparison](#four-format-inventory-comparison) + +| Size and seed | Input | Normal format, relief balance, global opacity | Output | +|---|---|---|---| +| 16² / 61253 | Flat U8 | Defaults | F32 | +| 32² / 61300 | Impulse F32 | 0, (.875,.125,.5), .5 | F32 | +| 32² / 61347 | U8 field | 1, (.1875,.6875,.8125), .5625 | U8, U16, F16, F32 | +| 64×32 / 61535 | F32 field | 0, (.25,.875,.375), .8125 | F32 | +| 32×64 / 61582 | U8 field | 0, (.25,.875,.375), .8125 | U16 | +| 64² / 61629 | F32 field | 1, (.1875,.6875,.8125), .5625 | F32 | + +For an independent constant-opacity check use a single native blend with the original foreground, background and mask fields described under [source-alpha rounding](#source-alpha-rounding-in-highpass). Use unsigned 16² and signed 32² F32 inputs with source alpha enabled. For each native mode m from 0 to 8 set the primitive opacity to −.5, 0, .375, 1, 1.25 and the next F32 above 6. Use seed 71711+19m, plus one for the signed input. All 69,120 RGBA32F pixels in 108 renders match, up from 42,258. Comparing the native results for −.5 against 0 and both high settings against 1 gives 34,560/34,560 exact pixels. + +The separate computed-opacity controls use grayscale or color inputs with and without a mask. Set opacity to −.5, 0, .375, 1, 1+2⁻²⁰, 1.25 and the next F32 above 6. For Add Sub test unsigned 16² F32, unsigned 32² U8, U16 and F16, and signed 32² F32. For color also test the three other alpha interpretations on signed 16² F32 inputs. For unmasked grayscale and masked color repeat the unsigned 16² F32 settings for the eight other modes. In all 42 groups the out-of-range native renders agree byte-for-byte with their respective endpoint. MaterialCraft matches 158,392/161,280 pixels across these 294 renders, up from 88,416. All 157,696 pixels in the 280 renders outside straight interpretation match. The signed straight-alpha controls remain open at 696/3,584 exact RGBA32F pixels, maximum component error 772.524188. + +For these controls use L=(53x+17y+7xy+35v+61c+3cy+3) mod 251, with v=0,1,2 for foreground, background and mask, respectively, and c for the channel. Use L/255 for unsigned inputs and (L−83.125)/53.5 for signed images or (L−83.125)/101 for a signed mask. Grayscale image bridges store U16. For their source texels use (round(131071H)+97x+3y²+257v) mod 65536, where H is the unsigned or signed input value above. The first two row-zero foreground levels are 35,122 and 32,767, and both background levels are 32,767. Color and mask bridges store F32. Use seed 64109+37b+k, where b indexes the groups in the order given and k=0,1,2,3 for unmasked gray, masked gray, unmasked color and masked color. + +The release also matches all 2,577,920 pixels across 164 renders of 18 previously measured blend roots. For file fidelity, save the current-header Normal to Height graph with the ordinary save command. Reopen it in the reference app using the nine inputs above, the changed 64² F32 input and the independent 32² input. The saved and original graphs match all 18,688 pixels with zero maximum error. + +### Source-alpha rounding in Highpass + +| Root | Renders | Exact pixels / compared | Maximum error | +|---|---:|---:|---:| +| Highpass, RGBA | 21 | 177,408/177,408 | 0 | +| Highpass, grayscale | 30 | 216,576/216,576 | 0 | +| Add Sub graph | 7 | 311,296/311,296 | 0 | + +The RGBA high-pass uses the source as background and a blurred, inverted image as foreground. The input bridge, blur and levels matched before the fix. The first discrepancy was the final Add Sub blend at half opacity. Across the same 21 renders, 165,429/177,408 pixels matched before the change. Maximum errors were one U16 level and 1.19209290e−7 F32. The corrected RGBA counts are 122,880 U8, 8,192 U16, 8,192 F16 and 38,144 F32, all exact. In each of the 12 new renders of each high-pass graph, all five observed nodes match. The grayscale total also includes the [earlier nine field variations](#high-pass-anisotropic-noise-and-triangle-grid-controls). + +For those 12 renders, channel c of the original F32 source is H=((31x+53y+11xy+67c+5xc+17) mod 509)/508. Use channel zero for grayscale. In order, use 16² F32 with the default radius, 32² F32 with radius zero, and 64² with radius 2.75 in U8, U16, F16 and F32. Repeat the 64² F32 case with alpha one. At 32² use radius .125 and alpha zero. At 128² use radius 6.5 and alpha one. Follow with a 32×16 source at 32² and radius 1.375, then 32² at radius .6875. In the last two cases RGB is 2.375H−.625. Finish by repeating the original 64² F32 radius 2.75 render. Seeds start at 5021 and advance by 19. + +For source alpha, form a=1−(1−foreground alpha) in F32 and w=a×opacity. For each color channel, foreground contribution is ((background+2×foreground)−1)×w. Use a fused multiply-add to compute 1−a×opacity, then another to multiply that weight by background and add the foreground contribution. Coverage is the fused sum background alpha+(1−background alpha)×(foreground alpha×opacity). With background bytes (24,5,8,8), foreground (231,250,247,8) and opacity .5, the F32 result has bits 3ddad4cf, 3d0e0b89, 3d3cb8b5 and 3d3ebcbb. + +The standalone Add Sub filter matches **59,904/59,904 pixels across 36 renders** using source, ignored or premultiplied alpha. These include enabled and disabled alpha blending, an absent or connected opacity mask, grayscale and color, and signed floating-point inputs. The three straight-alpha probes at 32² F32 remain open. Connected-mask and unmasked color match 64/1,024 and 62/1,024 pixels, maximum 2.38418579e−7 for both. Masked grayscale matches 604/1,024, maximum 1.19209290e−7. The Add Sub graph row reports its own seven renders. + +To reproduce the filter controls use one graph per input layout, with foreground, background and optionally mask. In binding order use slot v=0,1,2 for foreground, background and mask. For each channel c use L=(53x+17y+7xy+35v+61c+3cy+3) mod 251. Use L/255 normally. For signed cases use (L−83.125)/53.5 for the images and (L−83.125)/101 for the mask. Masks and grayscale images take channel zero. Set image bridges to F32 for the color graphs and U8 for the grayscale graph. For each graph use 16² F32 at opacity 1, then 32² at opacity .5 in all four formats. At 64² F32 with signed inputs use .6875 with alpha blending disabled, then .3125 with it enabled. At 32² F32 and opacity .6137 run ignored, straight, premultiplied and source alpha. Finish with signed inputs at 16² F32 and opacity zero, followed by 64² F32 with unsigned inputs and opacity 1. Each series starts at seed 5113 and advances by 17. + +### Stored input precision in box and directional blur + +Dirt 1 matches **145,626/145,664 pixels across 17 renders**. Previously 144,472 matched, with maximum U16 error 304 levels. U16 now matches 123,869/123,904 with maximum error one level. All 5,120 U8 and all 5,120 F16 pixels match. F32 matches 11,517/11,520 with maximum 1.52587891e−5. The 64² case that previously had 255/256 exact pixels at the 16² U8 blur now matches 256/256 at that stage and 4,096/4,096 at the output. The repeated 64² case first differs at the U16 FX-Map, with 4,094/4,096 and maximum one level, while the U8 blur still matches 256/256. [Generator inputs, controls and seeds](#square-and-rectangular-pattern-generators) + +A zero blur copies its resized input at the destination precision. With a nonzero intensity, the resize stores each level at the wider input or destination precision, including the final reduction. If the filter has a nonzero radius, it reads the resized texture at that working precision. A matching-size input retains its existing format. This applies to both filters even when the intensity is too small to cover another texel. + +| Direct comparisons | Renders | Exact pixels / compared | Max U8 / U16 levels | Max F16 / F32 error | +|---|---:|---:|---:|---:| +| Box blur, mixed input sizes and storage | 133 | 238,336/238,336 | 0 / 0 | 0 / 0 | +| Box blur, zero through 4.001 | 48 | 49,152/49,152 | 0 / 0 | 0 / 0 | +| Box blur, signed subpixel settings | 18 | 1,152/1,152 | 0 / — | 0 / 0 | +| Both filters, signed and wider kernels | 36 | 2,302/2,304 | 0 / — | 0 / 2.98023224e-08 | +| Directional blur, mixed sizes and angles | 91 | 162,606/163,072 | 0 / 0 | 0 / 1.1920929e-07 | + +For the mixed-size rows, generate the [original four-channel field](#stored-input-resizing-and-grayscale-levels-controls) with component c = ((131x+367y+29xy+41c+17xc+seed) mod 2053)/2052. For gray take the first component. Encode normalized inputs at their specified depth. For floating inputs use 1.5 times the component minus .25 in linear F32, then store at the indicated input depth. Before the blur, feed a neutral Levels at the input dimensions. At each index j below, use base seed 11677+11(250+j). Render 16² F32, 32² U8/U16/F16/F32, 64² F32 and 64² U16. Add 0, 1, 1, 1, 1, 5 and 6 to the base seed. Multiply the output width and height by two to the respective powers shown to obtain the input dimensions. The angle column gives the additional directional renders in turns. + +| j | Input | Size powers (X,Y) | Tiling | Intensity | Directional angles | +|---:|---|---|---|---:|---| +| 0 | U16 gray | (2, 2) | XY | 0 | 0 | +| 1 | U16 gray | (2, 2) | XY | 3.2 | 0.25 | +| 2 | U16 gray | (2, 1) | XY | 0 | — | +| 3 | U16 gray | (1, 0) | XY | 0 | 0.125 | +| 4 | U16 gray | (-1, 0) | XY | 0 | — | +| 5 | U16 gray | (-2, -1) | X | 0 | -0.0625 | +| 6 | U16 gray | (-1, 1) | Y | 0 | — | +| 7 | U8 RGBA | (-2, -1) | XY | 0 | — | +| 8 | U8 RGBA | (-1, -1) | off | 0 | 0.1875 | +| 9 | F16 RGBA | (-2, -1) | XY | 0 | 0.125 | +| 10 | F16 RGBA | (1, 1) | XY | 0 | — | +| 11 | F32 RGBA | (2, 1) | XY | 0 | — | +| 12 | F32 RGBA | (-1, 0) | off | 0 | 0 | +| 13 | U16 gray | (-1, 0) | XY | 8.5 | 0, 0.25 | +| 14 | U16 gray | (1, 1) | XY | 9 | 0.125 | +| 15 | U16 gray | (2, 2) | off | 12 | 0.25 | +| 16 | F32 RGBA | (-1, -1) | X | 12 | — | +| 17 | F16 RGBA | (-1, 0) | Y | 6 | 0 | +| 18 | U8 RGBA | (-1, -1) | XY | 10 | 0.125 | + +For the threshold series, take the 128² U16 field from j=0 at the 32² setting. Keep seed 15701 and store all four formats at intensities 0, 2⁻¹⁸, 2⁻¹⁰, .03125, .125, .5, 1, 1.5, 2, 3.2, 4 and 4.001. With U8 output, using destination precision throughout matches all 1,024 pixels at zero and 889/1,024 at 2⁻¹⁸. Using the wider precision reverses those counts. + +For the two signed series, generate a 32² U16 image with level ((17x+113y+59xy+19)×7919) mod 65536. Reduce to 8² U8, F16 and F32. At seed 15709 test box intensities 0, 2⁻¹⁰, 3.2, 16, −2⁻¹⁰ and −3.2. At U8 the row-zero pixels at columns 2 and 5 are 145 and 139 at zero and 146 and 140 at ±3.2. At seed 15709, repeat both filter types at 0, 2⁻¹⁰, 3.2, −3.2, 64 and −64, with an eighth turn for directional blur. The +64 directional F32 result matches 62/64 pixels, maximum 2.98023224e−8. The independent directional angles retain the F32 differences shown above. + +### Pixel reciprocals for stamp edge widths + +The beveled square (shape 9) scales its edge distance by the pixel reciprocal of the bevel width. The fading bell and ring (12 and 14) scale their horizontal positions by the pixel reciprocal of one minus the nonnegative variation. MaterialCraft now evaluates the reciprocal once per stamp and applies it to the two square edges or the horizontal fade. Two regressions failed on the previous calculations. + +On a centered 64² white stamp with unit dimensions, at pixel (1,31) the independently measured left edge distance is 3/64. At width .0721875 the reference square reads F32 `3f37a51f`, one bit above the previous `3f37a51e`. At width .71897 it reads `3c47d97b`, previously `3c47d977`. On the same canvas, use variation 86/1021 for the other two shapes. The bell gives `3c9fe0f0` at (48,48) and the ring gives `3e9b3a66` at (23,35). + +| Isolated factor, supplied with independently measured coordinates or profile values | F32 exact before | F32 exact after | U8 / U16 / F16 exact after, per format | Maximum error after | +|---|---:|---:|---:|---:| +| Square edge | 143,866/169,496 | 169,496/169,496 | 16,880/16,880 | 0 | +| Bell fade | 44,795/47,800 | 47,800/47,800 | 3,585/3,585 | 0 | +| Ring fade | 256,542/279,720 | 279,720/279,720 | 20,979/20,979 | 0 | + +Use three black backgrounds with tiling on both axes and white stamps at maximum blend. The tuples (canvas, center, extents) are (64², (.5,.5), (1,1)), (32×64, (.375,.625), (.8125,.96875)) and (128×64, (.2831,.7083), (.7313,.5329)). Set the quadrant branch offset to (−.5,−.5) and the frame offset to the stated center. Use shape 8 to measure the distance to the nearer square edge. Two shape 10 ramps with opposite horizontal extents measure the X distance, and two quarter-turned ramps with exchanged extents measure Y. For a positive width select interior pixels before the fade ends where the other edge distance exceeds the width by more than .000004. For nonpositive widths compare the interior plateau. The unattenuated bell comes from shape 5 at the same geometry. The unattenuated ring comes from shape 14 at variation 1.25. Use a base value above .00001. For the bell compare signed X above .5 using the complementary ramp, and for the ring use the positive horizontal ramp directly. + +For the square, take (23+17h)/1021 for h=0…41 followed by 0, −.25, 1, .0721875, .71897 and .375. Use seed 196903+59j+h for geometry index j. For the bell and ring use (17+23h)/1021 for h=0…31 followed by 0, .25, .75, .875, 1, 1.25, −.25 and .71897 and seed 198171+73j+h. Render all in F32. For the square also render U8, U16 and F16 at h=2,9,19,25,41,45. For the bell and ring repeat those formats at h=2,14,37. + +| Complete stamp outputs | Renders | Exact before | Exact after / compared | Maximum U8 / U16 / F16 / F32 after | +|---|---:|---:|---:|---| +| Square widths and rectangular canvases | 198 | 781,861 | 794,489/946,176 | 0 / 1 / 0.000244140625 / 1.97887421e-05 | +| Bell, ring and their unattenuated controls | 297 | 1,080,989 | 1,082,447/1,419,264 | 0 / 1 / 0.00048828125 / 1.7285347e-06 | +| Individual stamps from Brick 3 | 274 | 1,120,884 | 1,121,022/1,122,304 | 0 / 1 / 0 / 1.03116035e-05 | + +The full square width sweep gains 12,628 exact F32 pixels. In 1,207 pixels the earlier coordinate and edge-factor errors had canceled. Those pixels now differ. All 220,136 separately measured square-edge samples match when supplied with the reference coordinates. + +In Brick 3 at 128×32 U16, seed 9787, use Tiling 1, Roundness .34375, Lum_var .6875, Lum_seed 13 and Disorder .3125. Record the two generators’ emitted centers, extents, luminosities and variation at the raster entry. Draw each stamp on its own. Set branch offset to (−.5,−.5), frame offset to the recorded center, variation to .0721875, local roughness to zero and blend to maximum. Use opacity 1.3437529 for the 128 stamps from depth four of node 1035248938, and 3.0873783 for the two depth-one stamps from node 1065200619. For example, stamp 10 at depth four has center (.43812585,.031536788), extents (.12283202,.05915039) and luminosity .62089026. Use seed 194081+37b+j for stamp j with b=1 for the larger group and b=0 for the smaller. Render every stamp in F32 and U16, and also in U8 and F16 for available indices 0,1,4,23,87. + +Taking the per-pixel maximum reconstructs each app’s intact U16 stage exactly, 4,096/4,096 for each stage in each app. The two apps differ at 86 pixels in the first stage and 56 in the second, maximum one U16 level. Forty of the first stage’s stamps and one of the second stage’s stamps carry those differences. Converting the F32 maxima to U16 also reproduces all 8,192 levels per app. [Downstream source substitution](#isolating-the-generators-in-spots-bricks-and-cells) + +For intact Brick 1, Brick 2, Brick 3 and the two pattern brick roots, add 34 renders per root. For setting j=0…18 cycle canvas dimensions through 64², 128×32, 32×128, 128×64, 128² and 64×32. Use seed 199103+7i+17j, where i is the zero-based inventory index. Use defaults at j=0,1. For subsequent settings use scale or Tiling 1+(j mod 3), smoothness or Roundness (23+43j)/1021, and interstice width (7+(5j mod 23))/128 where present. For Brick 3 also use Lum_var (7+(13j mod 63))/71, Lum_seed 13+3j and Disorder (3+(17j mod 47))/53. Render F32 throughout, all four formats at j=0,4,12,18 and also U16 at j=6,8,15. + +| Intact root | New exact before | New exact after / compared | Maximum U8 / U16 / F16 / F32 after | +|---|---:|---:|---| +| 59 · brick_1 | 219,491 | 219,491/223,232 | 0 / 1 / 6.10351562e-05 / 1.52597204e-05 | +| 60 · brick_2 | 221,106 | 221,106/223,232 | 0 / 1 / 0.000244140625 / 1.52885914e-05 | +| 61 · brick_3 | 222,098 | 222,114/223,232 | 0 / 1 / 0 / 4.57763672e-05 | +| 355 · pattern_brick_1 | 171,296 | 171,296/223,232 | 0 / 1 / 3.81469727e-06 / 3.32593918e-05 | +| 356 · pattern_brick_2 | 171,846 | 171,846/223,232 | 0 / 1 / 6.10351562e-05 / 1.32322311e-05 | + +Across these new whole-root renders, 24 pixels become exact and eight previously exact pixels differ. Each change occurs in Brick 3, evenly divided between U16 and F32. The table below includes the new settings for the five brick roots. It also gives the archived defaults and applicable existing four-format, changed-parameter, seed and rectangular cases for every directly reachable stamp with shape 9, 12, 14 or a dynamic selector. A dynamic selector can choose a different shape in a given case. Only completed outputs contribute to the counts. + +| Inventory index and root | Renders | Exact before | Exact after / compared | Maximum U8 / U16 / F16 / F32 after | +|---|---:|---:|---:|---| +| 59 · brick_1 | 68 | 421,981 | 421,981/427,520 | 0 / 1 / 6.10351562e-05 / 1.52597204e-05 | +| 60 · brick_2 | 61 | 406,666 | 406,666/409,088 | 0 / 1 / 0.000244140625 / 1.52885914e-05 | +| 61 · brick_3 | 68 | 424,066 | 424,082/427,520 | 0 / 3 / 0 / 4.57763672e-05 | +| 62 · brick_generator/resources/Tile | 74 | 149,415 | 149,415/150,528 | 175 / 45055 / 0.6875 / 1 | +| 114 · creased | 17 | 143,948 | 143,948/145,664 | 0 / 29 / 0.00048828125 / 1.52587891e-05 | +| 118 · crystal_2 | 17 | 144,770 | 144,770/145,664 | 0 / 2 / 0 / 3.05175781e-05 | +| 153 · fluid | 28 | 538,504 | 538,504/538,880 | 0 / 201 / 0 / 0.00306707621 | +| 157 · fur_3 | 21 | 145,101 | 145,101/178,432 | 1 / 4 / 0.00048828125 / 6.10351562e-05 | +| 158 · fur_4 | 21 | 148,961 | 148,961/178,432 | 0 / 4 / 0.00048828125 / 6.10351562e-05 | +| 222 · messy_fibers_3 | 9 | 127,012 | 127,012/132,096 | 1 / 3 / 0.0009765625 / 5.24520874e-05 | +| 241 · noise_cells_1_v2/cells_1 | 9 | 132,092 | 132,092/132,096 | 1 / 0 / 0 / 0 | +| 248 · noise_creased/creased | 9 | 131,312 | 131,312/132,096 | 0 / 1 / 0.000244140625 / 1.52885914e-05 | +| 250 · noise_crystal_2/crystal_2 | 19 | 152,713 | 152,713/153,856 | 0 / 46 / 0.00048828125 / 1.52597204e-05 | +| 272 · noise_fluid/fluid | 28 | 508,823 | 508,823/538,880 | 1 / 79 / 0.0009765625 / 0.00108343363 | +| 292 · noise_messy_fibers_3/messy_fibers_3 | 19 | 123,834 | 123,834/142,592 | 0 / 2 / 0.00048828125 / 2.47955322e-05 | +| 293 · noise_messy_fibers_3_v2/messy_fibers_3 | 19 | 132,391 | 132,391/142,592 | 1 / 3 / 0.00048828125 / 3.12328339e-05 | +| 350 · paths_tools/paths_trace | 9 | 18,297 | 18,297/18,432 | 120 / 30822 / 0.62109375 / 1.22619528 | +| 354 · pattern_arc_pavement/arc_pavement | 27 | 208,786 | 208,786/211,200 | 0 / 0 / 0 / 9.93907452e-06 | +| 355 · pattern_brick_1/brick_1 | 53 | 310,861 | 310,861/365,824 | 0 / 1 / 3.81469727e-06 / 3.32593918e-05 | +| 356 · pattern_brick_2/brick_2 | 53 | 310,928 | 310,928/365,824 | 0 / 1 / 6.10351562e-05 / 1 | +| 357 · pattern_brick_generator/resources/Tile | 74 | 149,402 | 149,402/150,528 | 175 / 45055 / 0.6875 / 1 | +| 369 · pattern_shape/shape_base | 19 | 139,876 | 139,876/142,592 | 0 / 1 / 0.00048828125 / 1.37090683e-06 | +| 370 · pattern_splatter_circular/splatter_circular | 9 | 130,916 | 130,916/132,096 | 223 / 57311 / 0.874511719 / 0.921568625 | +| 371 · pattern_splatter_circular/splatter_circular_color | 9 | 130,715 | 130,715/132,096 | 254 / 65535 / 0.996078491 / 0.996078431 | +| 373 · pattern_tile_generator/tile_generator | 9 | 130,546 | 130,546/132,096 | 0 / 1 / 0 / 0 | +| 374 · pattern_tile_generator/tile_generator_color | 9 | 128,338 | 128,338/132,096 | 0 / 1 / 0 / 0 | +| 375 · pattern_tile_random/tile_random | 9 | 132,096 | 132,096/132,096 | 0 / 0 / 0 / 0 | +| 376 · pattern_tile_random/tile_random_color | 9 | 132,096 | 132,096/132,096 | 0 / 0 / 0 / 0 | +| 382 · pattern_weave_2/weave_2 | 9 | 130,307 | 130,307/132,096 | 1 / 59 / 0.0009765625 / 0.000900268555 | +| 383 · pavement_1 | 9 | 130,912 | 130,912/132,096 | 0 / 2 / 0 / 2.06083059e-05 | +| 465 · scratches_4 | 18 | 106,551 | 106,551/126,208 | 1 / 5 / 0.00048828125 / 4.57763672e-05 | +| 466 · shape/shape_base | 19 | 139,931 | 139,931/142,592 | 0 / 1 / 0.00048828125 / 1.37090683e-06 | +| 489 · splatter_circular | 19 | 139,297 | 139,297/142,592 | 231 / 59438 / 1 / 1.00000006 | +| 490 · splatter_circular/splatter_circular_color | 19 | 140,218 | 140,218/142,592 | 247 / 65535 / 0.96862793 / 0.996078431 | +| 509 · starburst | 19 | 141,503 | 141,503/142,592 | 0 / 1 / 1.52587891e-05 / 1.52592547e-05 | +| 520 · tile_generator | 19 | 139,723 | 139,723/142,592 | 0 / 42 / 0.00048828125 / 0.000639975071 | +| 521 · tile_generator_color | 19 | 137,445 | 137,445/142,592 | 1 / 103 / 0.00146484375 / 0.00199997425 | +| 522 · tile_random | 19 | 111,364 | 111,364/142,592 | 223 / 57311 / 1 / 1.00000006 | +| 523 · tile_random/tile_random_color | 19 | 111,228 | 111,228/142,592 | 250 / 65535 / 1 / 2.00000003 | +| 535 · waveform_01_v2 | 9 | 124,848 | 124,848/132,096 | 255 / 0 / 0 / 0 | +| 536 · waveform_1 | 9 | 131,931 | 131,931/132,096 | 0 / 1 / 0 / 0 | +| 538 · weave_2 | 19 | 138,111 | 138,111/142,592 | 0 / 3 / 0.00048828125 / 4.57763672e-05 | + +These 42 inventory rows remain in progress. Additional previously measured settings in each linked root’s record retain their own scope. + +Both regressions, the release node suite, formatting, workspace Clippy with warnings denied, dependency layers and the WebAssembly checks passed. + +### Linear gradient sampling on rectangular targets + +Gradient Linear 1 at 64² F32, seed 462, Tiling 4 and rotation 3 draws one centered gradient into a 256×16 U16 intermediate. An independently authored graph reproduces all 4,096 native intermediate pixels. Use a white, unit-size horizontal gradient (shape 10), maximum intensity, zero variation, 1.5 turns, additive blending, black background and tiling in both axes. In MaterialCraft the reproduction matches 4,080/4,096 pixels. On row 6, columns 128–143 are each one level low. At column 128 the reference reads 32,640 and MaterialCraft reads 32,639. Applying U16 storage to the independent native F32 readback reproduces all 4,096 native U16 levels. + +| Independent centered gradient | Cases | Exact MaterialCraft pixels | Maximum error | +|---|---:|---:|---:| +| Extended turns, F32 | 112 | 395,513/647,168 | 1.19209290e−7 | +| Extended turns, U16 | 28 | 160,616/161,792 | 1 level | +| Zero and half turns, F32 | 72 | 1,319,136/2,032,128 | 5.96046448e−8 | + +For the extended turns use dimensions (256,16), (128,16), (64,16), (256,32), (256,64), (512,16) and (32,16), then transpose each. Use turns 0, .5, 1.5, −.5, −1.5, 2.5, 1.5−2⁻²³ and 1.5+2⁻²³. For dimension index h and angle index j the seed is 189773+29h+j. Use F32 for all angles and repeat ±1.5 in U16. For the last row, choose the width and height independently from 16, 32, 64, 128, 256 and 512. For zero-based width and height indices j,h use seed 192403+37j+11h plus one for the half turn. + +An independent Direct3D 11 draw on the same device reproduces all 2,032,128 native F32 pixels of the last row. In pixel space, draw a triangle strip ordered top right, top left, bottom right, bottom left. Use bounds [0,width+.5] × [0,height+.5]. Set the horizontal vertex attribute to (2x/width−1) at zero turns and its negative at half a turn. Write (interpolated attribute+1)/2. Moving the half-pixel extension to the low ends of both axes also reproduces all 2,032,128 pixels. The extended-angle F32 controls retain differences with this construction. The intact root remains in progress. [Whole-root format and save/reopen checks](#pattern-rotation-phase) + +### Pattern rotation phase + +An original horizontal gradient distinguishes .5 from 1.5 turns and .75 from 1.75 turns. The latter rotations leave a small cross-axis component. At 1.5 turns, a stamp four pixels wide and 256 pixels high gives a fitted component of 1.87244e−7. At −3.75 turns the corresponding component is −7.49176e−7. MaterialCraft’s pixel sine and cosine give 1.87261e−7 and −7.49045e−7 from the stored F32 angles (bits 34491200 and b5491200). The pattern renderer now uses that same phase calculation. Edges with an exactly zero axis component keep their image-space boundary rule. + +| Original controls | Renders | Previously exact | Now exact / compared | Maximum absolute error by format | +|---|---:|---:|---:|---| +| Unit gradient, extended turns and neighboring F32 angles | 79 | 225,623 | 241,479/438,272 | 2.38418579e-07 F32 / 1 U16 | +| Thin gradient, extended turns | 57 | 3,560,754 | 3,595,790/3,735,552 | 8.34465027e-07 F32 | +| Unit gradient, cardinal rotations | 96 | 1,309,160 | 1,325,612/1,867,776 | 8.94069672e-08 F32 / 1 U16 | +| Unit gradient, oblique rotations | 16 | 208,057 | 211,579/311,296 | 2.38418579e-07 F32 / 1 U16 | +| Shape and render-region edge controls | 104 | 618,848 | 618,848/647,168 | 1.78813934e-07 F32 | +| Oblique square footprints | 78 | 4,542,719 | 4,542,720/4,542,720 | 0 F32 | + +For the first row draw a centered unit horizontal gradient. On a 64² canvas, visit −4 through 4 turns in quarter turns, then 1.5 plus each of [−2⁻²⁰,−2⁻²³,2⁻²³,2⁻²⁰], .5 plus [−2⁻²⁰,−2⁻²⁴,2⁻²⁴,2⁻²⁰], and finally [.1875,−.1875,.625,.8125]. Use seed 42313+53j with zero-based angle index j. Add 256×32 and 32×256 at −2.5, −.5, .5, 1.5, 1.75, 2, 2.5 and 3.5 turns. Use F32 throughout and also U16 at −2.5, .5, 1.5, 1.75, 2.5 and 3.5. The extended-angle U16 subset goes from 122,078 to 122,042 exact pixels out of 122,880, with maximum error one level. For all 18 paired U16 and F32 settings, applying U16 storage to each app’s own F32 samples reproduces all 122,880 of its U16 levels. The 838 differing U16 samples originate before output storage. + +For the thin-gradient row use a 256² F32 canvas, height 1 and widths 1/8, 1/32 and 1/64. Center the first two widths and offset the last by .25 pixel on both axes. Use turns [−3.75,−3,−2.5,−1.75,−1.5,−.5,0,.5,1.5,1.75,2,2.25,2.5,2.75,3,3.5,4,1.5−2⁻²³,1.5+2⁻²³] and seed 53851+43j+k for angle j and width k. The maximum pixel error drops from 2.39610672e−5 to 8.34465027e−7. The square that previously missed pixel (307,492) uses size (.755,.391), offset (−.1113,.1437), .13125 turns, seed 1108 and a 512² F32 output. Its right and lower neighbors remain outside. [Shape and render-region controls](#quarter-turn-stamps-and-render-bounds) + +| Root | Renders | Previously exact | Now exact / compared | Maximum error in U8, U16, F16 and F32 | +|---|---:|---:|---:|---| +| Gradient Linear 1 | 47 | 435,120 | 435,744/435,968 | 1, 1, .000244140625, .0000152587891 | +| Gradient Linear 3 | 23 | 265,072 | 265,072/277,760 | 0, 2, 0, .0000305175781 | +| Arc Pavement | 27 | 206,904 | 206,911/211,200 | 0, 0, 0, .00000993907452 | +| Fibers | 24 | 416,631 | 416,773/424,192 | 0, 1, .0000305175781, .0000153183937 | +| Pattern Fibers | 24 | 416,669 | 416,799/424,192 | 0, 1, .0000305175781, .0000153183937 | + +Arc Pavement previously had a maximum F32 error of .00000987946987. Gradient Linear 1 still has 16 unequal pixels in each of U8, U16 and F16 and 176 in F32. On the 24 profiles per root, Fluid and Noise Fluid give the same counts and maxima as the earlier [pattern-stage comparison](#fibers-and-fluid-pattern-stages). All 3,211,776 pixels from 159 equal-resolution renders of 19 previously matched pattern roots are exact. For the separate file check, save the original test graph, Gradient Linear 1, Fibers and Fluid through the normal save command with input header `1.1.0.202502`. Reopen each save in the reference app and compare to the original in that same app. Across 14 extended-angle controls and nine settings per root, all 134,144 pixels in 41 renders match, with maximum error zero. + +### Pattern opacity near zero and color accumulation + +| Measured output | Renders | Exact pixels / compared | Maximum component error | +|---|---:|---:|---:| +| Independent depth, roughness and opacity | 288 | 73,728/73,728 | 0 | +| Smallest stored gains, signed values and very large tints | 165 | 42,240/42,240 | 0 | +| Point-sampled original F32 gray and RGBA bitmaps | 32 | 8,192/8,192 | 0 | +| Positive and negative subnormal clear colors | 40 | 10,240/10,240 | 0 | +| Mixed-channel clear colors and transparent or signed squares | 56 | 14,336/14,336 | 0 | +| Three color blend modes on generated F32 backgrounds, four output formats | 63 | 76,032/76,032 | 0 | +| Earlier mixed-size backgrounds with a square or an opposite-type input | 105 | 188,160/188,160 | 0 | + +The first row improves from 73,442 exact pixels and closes both 143-pixel discrepancies in the [depth controls](#stored-opacity-across-pattern-depths). A solid RGBA square with RGB 2⁶⁰, alpha .25, roughness zero and gain 2⁻¹²⁶ has all four components zero. With RGB 1, alpha −1, gain F32 bits `00800001` and a 2⁻¹²⁶ background, each result has bits `80000000`. The renderer flushes subnormal operands and intermediate products to signed zero before later stages can amplify them. For an authored gray clear color the mean uses F32 RGB before flushing. For example the mixed swatch (smallest normal, −next-to-largest subnormal, −next-to-largest subnormal) gives negative zero. A zero additive contribution retains the destination sign. + +For the 165 depth renders use a 16² F32 output, seed 91813 + 7j, one square at depth 0, 7 of 8 or 10 of 10. At depth zero use signed gains with F32 magnitude bits 1, 00100000, 00370011, 007fffff, 00800000, 00800001 and 01000000. Use tints 1, 2⁶⁰, .25 and 2⁻¹⁶ over zero or 2⁻¹²⁶. At the other depths cross roughness 2⁻¹⁸, .0001, .00032 and 2⁻¹² with gains .37, 1, 2¹⁸ and 2⁻¹². For the point-sampled bitmap use a 16² field with white pixels or an eleven-entry repeated sequence [1, t, n, .25, 2⁶⁰, 0, −.3125, −n, −t, 2n, 1.125], where t has bits 00371245 and n is the smallest positive normal. Select element (11y + 3x + 5c) mod 11 for channel c. The clear-color series also draws on ±t, draws on mixed normal and subnormal color components and compares an empty map with a half-width square. + +The 63 blend renders previously matched 66,507/76,032 pixels. F32 matched 38,861/48,384 with maximum .5. U16 matched 9,214/9,216 with maximum one level. F16 and U8 each matched 9,216/9,216. A built-in color stamp now uses the same measured accumulator precision as the bitmap stamp. With alpha .71875 and gain .625 over destination alpha `393fa080`, the stored result is `3ee60d32`. A single F32 multiply-add gives `3ee60d31`. On the 105 previous mixed-size renders this closes the two one-ULP alpha differences. [Background resize controls](#pattern-backgrounds-and-center-culling) + +For each blend mode use one unit square and (R,G,B,A,gain) values (.5625,.3125,.8125,.71875,.625), (.35,−.6971,1.78125,.6337,.7723) and (−.372,.8123,1.326,1.1873,−1.359). Generate F32 RGBA backgrounds using PCG64 with seeds 100049 through 100052, drawing channels uniformly from [−1.25,1.625). Use 16², 32×64, 64×32 and 32² fields in order. Replace the first eight rows of field zero with F32 bits `393fa080 bb89bb22 3ee60000 393fa080`. Multiply field one by powers of two with integer exponents from −22 through 21, drawn from the same generator. Set R to zero in rows 0–7, A to one in rows 8–15 and G to negative zero in rows 16–23 of field two. Store field three in all four formats. + +The remaining F32 gradient measurements separate coverage from the tint arithmetic. Across 204 gray and RGBA renders the actual output matches 48,128/52,224 pixels. A gain of 2⁶⁰ amplifies a coverage difference to 68,719,476,736. Using identical measured unit-tint coverage gives 52,224/52,224 exact pixels. Compare shapes 2 and 17 at 16², on zero or ±2⁻¹²⁶, with seeds 96259 + j. Additional connected F32 backgrounds match 854/2,048 pixels in eight renders, maximum 1.17549421e−38. This difference is visible with an empty pattern. The gray input bridge retains the negative sign for subnormal values and negative zero, while the empty gray output gives positive zero. The color output preserves their sign. + +Six current-header saves reopened in the reference app and matched 34,816/34,816 pixels across 58 renders, maximum error zero. The 19 previously verified pattern roots retained 3,211,776/3,211,776 exact pixels in 159 renders, maximum error zero. + +### Subnormal values in filtered pixel reads + +The F32 bilinear Pixel Processor sampler flushes subnormal input components to signed zero before filtering. It applies the same rule to the filtered result. Nearest sampling and directly wired images preserve their input bit patterns. The 150 original renders below match **41,664/41,664 RGBA32F pixels**, maximum error zero. The first 60 previously matched 14,489/15,360, maximum 1.10202595e−38. + +| Sample mode and field | Renders | Exact pixels / compared | +|---|---:|---:| +| U16, F16 and F32 fields sampled at output pixel centers | 60 | 15,360/15,360 | +| Mixed signed F32 fields at six input sizes, bilinear at output centers | 18 | 4,608/4,608 | +| Same fields, nearest at output centers or at (.390625,.34375) | 36 | 9,216/9,216 | +| Same fields, bilinear at (.390625,.34375) | 18 | 4,608/4,608 | +| Direct wire at the six original input sizes | 18 | 7,872/7,872 | + +Use the [three-storage sampler fields](#signed-zero-in-floating-point-texture-filtering) for the first row. For the other rows use a 16² output and scale the source width and height by (1,1), (2,2), (½,½), (2,1), (1,2) or (½,2). At relative size j generate three fields with seeds 100151+19j+i. Use F32 bit patterns 00000000, 80000000, 00371245, 80371245, 007fffff, 807fffff, 00800000, 80800000, 00800001, 80800001, 009fffff, 80bfffff, 01000000, 81000000, 017fffff, 817fffff, 02000001 and 82000001. The first field samples this list uniformly with a seeded PCG64 generator in row, column and channel order. For the second field take index (5x+9y+3c) mod 18, with index 12+(c mod 2) where (floor(x/2)+3floor(y/2)+c) mod 7 is zero. For the last field take index (x+7y+c) mod 18, with −.25 where (x+y+c) mod 3 is zero. At output centers the native nearest reads preserve all 3,547 subnormal components. The filtered reads return signed zeros there when the result falls below the smallest positive normal. + +Eight small capture graphs also tested the cost of loading the node library. Use the first row at size/storage pairs (0,U16), (1,F16), (2,F32), (3,U16), (4,F16), (3,F32), (0,F32) and (4,U16), including all four field variants for each pair. Running eight independent sessions in separate processes took 26.12 and 24.70 seconds. Running the same sessions in one process with a shared read-only library took 3.34 and 3.29 seconds. Test the two orders on one worker. Each run produced 96 identical images, 30,976/30,976 captured pixels, identical node values and errors, and zero maximum difference. + +### Signs of zero in enlarged color backgrounds + +MaterialCraft now preserves a negative zero in an enlarged connected RGBA pattern background when all three filtered RGB channels have their sign bit set. A positive sign in any RGB channel changes zero components to positive zero, including an alpha of negative zero. The rule applies at the final enlargement before output storage. A 2× enlargement of the constant (−0,−.375,.5,−0) gives (+0,−.375,.5,+0). With blue set to −.5 both negative zeros survive. Same-size controls preserve the original RGBA signs. + +| Original control | Renders | Previous exact | Exact pixels / compared | Maximum numerical error | +|---|---:|---:|---:|---:| +| Vary RGB and alpha signs in independent spatial fields | 80 | 14,027 | 20,480/20,480 | 0 | +| Flat fields with mixed zero signs and ordinary values | 80 | 12,800 | 20,480/20,480 | 0 | +| Both sides of the first nonzero half value, four output formats | 120 | 30,131 | 30,720/30,720 | 0 | +| Earlier signed F32 inputs at six relative sizes | 72 | 17,764 | 18,432/18,432 | 0 | +| Earlier subnormal and normal threshold fields | 60 | 14,575 | 15,360/15,360 | 0 | +| Earlier U8, U16 and F16 sources | 120 | 30,559 | 30,599/30,720 | 0 | + +For the first row render an empty color pattern at 16² F32. Use F32 and F16 RGBA sources at 16², 32², 8², 8×16, 16×8, 8×32, 4² and 32×4. Number those sizes j from zero, and the five fields i from zero. For the first three fields use sign mask (floor(x/2)+3floor(y/2)+5i) mod 16. For the last two use (3x+5y+3xy+i) mod 16. Bit c sets the sign of channel c, starting with red. Use zero magnitude in field 0. In field 1 use .375+.125c where (floor(x/2)+floor(y/2)+c) mod 3 is zero. In field 2 use .1875+.0625c where (5x+3y+c) mod 3 is zero. Elsewhere these two fields use zero. In fields 3 and 4 choose magnitude at index (x+5y+3c+i) mod 4 from (0,2⁻¹²⁶,2⁻¹²⁵,2⁻¹²⁷) for F32 and (0,2⁻²⁴,2⁻²⁰,.75) for F16. Use seed 102389+13j+i. + +For the second row use both source formats, sizes 8², 16², 32², 4² and 8×32, and seed 102991+16j+i. Use the two constant examples above followed by (−0,−0,−0,+0), (+0,−0,−0,−0), (.25,−0,−0,−0), (−.25,−0,−0,.75), (−0,.25,−0,−.75) and (−0,−0,.25,−.75). + +For the half threshold row use source sizes 16², 32², 8², 4² and 8×32. Draw three fields with sign mask (5x+3y+7xy+i) mod 16 and magnitudes (0,2⁻²⁴,2⁻²⁵,2⁻²³,2⁻²⁶,2⁻²¹,2⁻²⁴,.3125). For field 0 index the magnitudes by (floor(x/2)+5floor(y/2)+2c) mod 8. For fields 1 and 2 use (3x+y+3c+i) mod 8. Use seed 103109+7j+i and render both source formats to F32, F16, U16 and U8. + +The 19 previously verified roots match all 3,211,776 pixels in 159 renders after the zero-sign correction. All 15,360 RGBA pixels in the earlier mixed-storage controls now match. The remaining 121 unequal grayscale pixels differ only in their zero sign. The reference input bridge already clears negative zero in the measured half-gray source. [Earlier texture filtering measurements](#signed-zero-in-floating-point-texture-filtering) · [Original background inputs](#connected-floating-point-pattern-backgrounds) + +### Signed zero in floating-point texture filtering + +A bilinear footprint containing only zeros retains a negative sign in a channel when every contributing texel has a negative sign. Texels with zero weight have no effect. On 20 original color Pixel Processor renders, all **20,480/20,480 F16- and F32-source component signs** match this rule. The full 60-render matrix improved from 10,741 to 14,489/15,360 bit-exact RGBA32F pixels. The remaining maximum absolute error is 1.10202595e−38. + +At a 16² output sample the original field at each pixel center using bilinear filtering. Use source sizes 32², 8², 32×16, 16² and 8×32. Test U16, F16 and F32 inputs at each size. First fill all channels with negative zero, then use negative zero except where (7x+3y+c) mod 11 is divisible by five. These two fields on floating sources supply the sign comparisons above. For a mixed field use index (7x+3y+c) mod 11 into [0,−0,0,−0,−0,q,−q,−2q,4q,.125,−.125], with q=2⁻¹²⁶ for F32 and 2⁻²⁴ for F16. For the last field replace each negative zero of the second field with −2×2⁻¹²⁶ and each positive zero with negative zero. Encode the U16 controls as level zero for zero values and 32333 otherwise. Use seeds 100397+11s+j for size index s and field index j. + +The [connected pattern background controls](#connected-floating-point-pattern-backgrounds) now match 2,048/2,048 on the eight 32²-to-16² threshold renders, 17,764/18,432 on the 72 relative-size renders and 14,575/15,360 on the 60 threshold-field renders. The 120 lower-precision source cases remain at 30,559/30,720. Maximum numeric error is zero in all four groups. The 19 previously verified roots still match 3,211,776/3,211,776 pixels across 159 renders. + +### Connected floating-point pattern backgrounds + +| Original inputs, 16² output | Renders | Previously exact | Exact pixels / compared | Maximum absolute error | +|---|---:|---:|---:|---:| +| Same-size F32 inputs with an empty map or one square | 8 | 854 | 2,048/2,048 | 0 | +| Signed F32 fields at six relative input sizes, four output formats | 72 | 12,921 | 17,715/18,432 | 0 | +| Five F32 threshold fields at six relative input sizes | 60 | 1,924 | 11,851/15,360 | 0 | +| U8, U16 or F16 source at four relative input sizes, four output formats | 120 | 30,559 | 30,559/30,720 | 0 | + +Keep the output pattern empty and feed it a floating-point image of the same channel type. In alternating columns, set one sample to F32 bits `007fffff` and its neighbor to twice the smallest positive normal. Reducing the two columns to one gives `00800000`. Averaging the unprepared input gives `00c00000`. Alternating the smallest normal and zero gives positive zero after reduction. A same-size gray input maps both signed subnormals and negative zero to positive zero. A same-size RGBA input retains the sign of each zero. MaterialCraft now prepares connected F32 samples before filtering and at each filter result. [Authored clear colors and stamp blending](#pattern-opacity-near-zero-and-color-accumulation) + +At 32² to 16², test those first two column pairs, then switch the second to negative values and finally fill the source with the negative largest subnormal. For RGBA alternate channel signs. At seeds 100391 through 100394, gray matches all 1,024 pixels. Color matches 768/1,024, with a zero-sign difference on the uniform field. + +For the eight same-size cases repeat F32 bits `00000000 80000000 00371245 80371245 007fffff 807fffff 00800000 80800000 00800001 80800001 3e8914f7 bf102ff3` at index (7x+5y+3c) mod 12 for channel c. Use seed 100109. Compare an empty map and a centered half-size square with gain zero, one or the smallest positive normal. For the 72 renders use input width and height relative to the output by factors (1,1), (2,2), (½,½), (2,1), (1,2), (½,2). Mix both signs of zero, subnormal and normal values around the smallest F32 normal, then replace every third sample of the last field with −.25. Store each field as F32 and the last in all four output formats. All 9,216 grayscale pixels match bit for bit. The only unequal RGBA pixels differ in their sign of zero. + +For the 60 threshold renders use 32², 8², 64², 4², 4×32 and 32×4 inputs. With n the smallest F32 normal and t the largest positive subnormal, alternate t and 2n by column. Use −t everywhere in the second field. Select −2n or −t according to (x+3y+2c) mod 5 in the third, and 2n or −2n on the same mask in the fourth. In the fifth field select −n or t by (floor(x/2)+floor(y/2)+c) mod 3. Use seed 100237+7j+i for size j and field i. All 7,680 gray pixels match bit for bit. RGBA matches 4,171/7,680. Before the fix the maximum error across these fields was 1.80915927e−38. + +For the 120 source-storage controls use 16², 32×16, 8² and 32×8 inputs. Read half words `0000 8000 0001 8001 03ff 83ff 0400 8400 3555 bffe 02ff 01ff 8000` at index (3x+7y+c) mod 13. Add floor(x/2)+5floor(y/3) to the index on a second field. For integer sources use (53i+17) mod 256 or (11677i+77) mod 65536 with index i. At 16² the first half-gray file contains 39 negative zeros. Its reference input bridge has already converted all 39 to positive zero. The corresponding half-color file retains all 156 negative zeros at the bridge. The remaining differences in these controls are signed zeros. Across six files saved by MaterialCraft, the reference app reproduced all 6,144/6,144 source-file pixels in 24 renders. + +The previous 105 mixed-size stamp renders still match 188,160/188,160 pixels. The 159 renders of 19 previously verified roots match 3,211,776/3,211,776, maximum error zero. + +### Trapezoid coordinates under fixed clipping + +| Root | [Original inputs](#quad-swirl-trapezoid-and-vector-morph-comparisons) | Boundary fields | Four tiling settings on the boundary fields | Maximum component error | +|---|---:|---:|---:|---:| +| trapezoid_transform | 171,264/171,264 | 135,424/135,424 | 541,696/541,696 | 0 | +| trapezoid_transform_grayscale | 171,264/171,264 | 135,424/135,424 | 541,696/541,696 | 0 | + +Before the fix, both roots matched 171,262/171,264 pixels on the original 18 renders. On the 10 extra boundary renders the color and grayscale roots matched 135,365/135,424, 135,411/135,424 respectively. The final 40 renders per root repeat those fields with horizontal and vertical tiling disabled, horizontal only, vertical only and both axes. For boundary inputs store (x,y,x mod 2,y mod 2) as F32, using x alone in grayscale. In the binary case use (x mod 2,y mod 2,floor(x/2) mod 2,floor(y/2) mod 2). For signed inputs multiply by .1875 and subtract 2.125. Use square fields at 16, 128, 128, 256 and 64 pixels, then a 64×32 field and a repeated 128² field, with seeds 89,131,233,331,421,509,601. The 64² signed field covers all four output formats. Top/bottom stretch is .3/−.2 for the coordinate, binary and repeated cases, .3125/.75 for signed, and .3125/−.2 for the thin field. The 16² case retains defaults. For the four tiling settings use seed 94423 + 17 × mask + j for case j and masks 0 to 3. + +Let q = (x − .5) / lerp(1 − top, 1 − bottom, y). The sample uses (q + .5,y). Clipping checks abs(q) > .5 only when horizontal tiling is disabled. At (19,0) of the 128² coordinate field with top=.3 and bottom=−.2, the numerator and denominator have F32 bits `beb20000` and `3f33b333`. With clipping fixed off the stored coordinate is `3b9aff02`. A live comparison of abs(q) stores q separately and produces `3b9aff00` at the same pixel. The compiler counts numerical uses of the intermediate after a Boolean condition has been fixed by a literal or the tiling mask. A user parameter that happens to contain false still supplies a runtime condition. + +Expose the position, division factors and quotient independently using the 16² default, the 128² coordinate, 256² large-grid, 64² signed and 64² thin fields, plus the 128² large and 32² signed inputs from the original matrix. Each of the three projections matches 107,776/107,776 F32 pixels. Write the local position to a four-channel F32 texture and read its xy components in a second processor. The reference and local samplers agree in both roots for separate point and linear sampling, the original sampling selector and the two corresponding inline samplers. The ten seven-case groups match 1,077,760/1,077,760 pixels. In the unmodified graph the comparison was the extra reader of q. + +The 105 branch-isolation renders use the live absolute-value check, the original tiling gate, literal gates, exposed gates, a varying per-pixel gate, separately returned absolute values and quotients, and multiplication controls. They match 1,616,640/1,616,640 pixels. The additional 56 renders swap gate operands, use disjunction, test a fixed gate on a multiplication, and retain the quotient as a live output. They match 862,208/862,208 pixels. All maxima are zero. + +The three other inventory roots containing the same direct combination of pure pixel arithmetic and Boolean operations retained their recorded results. Curvature v2, Shape Splatter to Mask and Summed Area Table Iteration match 246,044/246,044 pixels in 14 renders. Both transformed roots also reproduce all 270,848/270,848 source pixels when their current-header MaterialCraft saves are opened in the reference app. The two saves retaining the older `0.1.3` header are refused at package load. Saved-file evidence covers header `1.1.0.202502`. [Format-header comparison](#integer-defaults-in-saved-graph-interfaces) + +### Scratches, Messy Fibers, Microscope and Moisture + +MaterialCraft at `7283a5b` produced the following whole-root counts. Each F32 or F16 error is an absolute component difference. U8 and U16 errors use stored levels. The Scratches output is RGBA. The other five outputs are grayscale. + +| Package root | Renders | Exact pixels / compared | U8 exact / maximum | U16 exact / maximum | F16 exact / maximum | F32 exact / maximum | +|---|---:|---:|---:|---:|---:|---:| +| me_water_level.sbs/scratches_2 | 21 | 138,019/178,432 | 119,761/119,808 · 1 | 12,842/15,360 · 2 | 5,070/5,120 · 0.00048828125 | 346/38,144 · 2.24113464e-05 | +| messy_fibers_1.sbs/messy_fibers_1 | 21 | 122,750/178,432 | 5,117/5,120 · 1 | 94,328/130,048 · 4 | 5,072/5,120 · 0.00048828125 | 18,233/38,144 · 6.13927841e-05 | +| messy_fibers_2.sbs/messy_fibers_2 | 21 | 96,050/178,432 | 5,117/5,120 · 1 | 85,685/130,048 · 5 | 5,000/5,120 · 0.00048828125 | 248/38,144 · 6.47902489e-05 | +| messy_fibers_4.sbs/messy_fibers_4 | 20 | 119,106/162,048 | 5,114/5,120 · 1 | 82,167/113,664 · 200 | 5,043/5,120 · 0.00048828125 | 26,782/38,144 · 0.00244146585 | +| microscope_view.sbs/microscope_view | 21 | 177,304/178,432 | 5,120/5,120 · 0 | 129,145/130,048 · 66 | 5,112/5,120 · 0.000244140625 | 37,927/38,144 · 0.00115966797 | +| moisture_noise.sbs/moisture_noise | 21 | 178,192/178,432 | 5,120/5,120 · 0 | 129,875/130,048 · 6 | 5,117/5,120 · 0.00048828125 | 38,080/38,144 · 7.80820847e-05 | + +Each row includes the previous defaults, seed changes, available parameter changes and stored-format comparisons. The twelve additional stage captures used seed 95383 + 7i + k with zero-based inventory indices i = 206, 220, 221, 223, 224 and 226 respectively. Use 16²/default/k=0, 32²/A/k=1, 32²/B/k=2 in U8, U16, F16 and F32, 64×32/C/k=6 in F32, 32×64/C/k=7 in U16, 64²/B/k=8 and 128×64/B/k=9 in F32, 64×128/B/k=9 in U16 and 128²/default/k=11 in F32. Other single-format cases use F32. + +- For Scratches and Moisture use (width, height, disorder) = (100,100,0), (36,74,12.75), (81,23,57.5). +- For Messy Fibers 1 use (rotation variation, links, disorder, emboss intensity, emboss angle) = (0,1,0,0,0), (132,13,10.75,1.375,37), (283,29,44.25,−.875,163). For Messy Fibers 2 use (lines, disorder) = (1,0), (7,17.125), (27,53.75). Messy Fibers 4 has no exposed controls. +- For Microscope use (warp intensity, disorder) = (0,0), (2.5,15.75), (11.125,46.25). + +The earliest unequal stages in every comparable differing stage capture were pattern generators. Substitute a distinct original U16 image for each live generator in the four graphs with downstream filters. At zero-based case j=0 give source h the constant 8191(h+1). At j=1 use 52111−83h on (x+h) mod width = y mod width and 713+39h elsewhere. For j=6,7,8 use 32776+h where (3x+13y+7h) mod 23 is zero and 32767+h elsewhere. For the other settings use [7919(11x+31y+7xy+93+47h+(h+1)x)] mod 65536. Preserve each source’s original dimensions, including the half-width, quarter-height images in Messy Fibers 4. + +| Matching-input graph | Output exact / compared | All observed stages, including output and input bridges | Maximum error | +|---|---:|---:|---:| +| messy_fibers_1.sbs/messy_fibers_1 | 46,336/46,336 | 139,008/139,008 | 0 | +| messy_fibers_4.sbs/messy_fibers_4 | 46,336/46,336 | 382,272/382,272 | 0 | +| microscope_view.sbs/microscope_view | 46,336/46,336 | 185,344/185,344 | 0 | +| moisture_noise.sbs/moisture_noise | 46,336/46,336 | 231,680/231,680 | 0 | + +The four matching-input roots give 185,344/185,344 exact output pixels across 48 renders. They cover Emboss, two directional warps, transformation, blending, ordinary warp and Levels. The moisture package also contains a disconnected source and filter. The stage counts cover the nodes reachable from its output. + +For each live source in the original graph, route it directly to the output. Keep the shortest connected path to a drawing quadrant, using ascending output slot to break ties. Keep the authored shape, then substitute a square or disc. The last control retains all drawing branches with a square at every authored draw site. Use the 16² default, all four 32²/B formats, 64×32/C F32, 64²/B F32 and 64×128/B U16. The maxima columns use U8 / U16 / F16 / F32 in that order. + +| Root and pattern source UID | Isolated square | Isolated disc | Isolated authored profile | Authored maxima | Full square layout | Layout maxima | +|---|---:|---:|---:|---|---:|---| +| scratches_2 · 1028227090 · shape 6 | 18,688/18,688 | 18,688/18,688 | 18,687/18,688 | 0 / 0 / 0 / 6.55651093e-07 | 18,688/18,688 | 0 / 0 / 0 / 0 | +| messy_fibers_1 · 1028375992 · shape 11 | 18,688/18,688 | 18,688/18,688 | 17,447/18,688 | 0 / 2 / 0.000244140625 / 2.40802765e-05 | 18,688/18,688 | 0 / 0 / 0 / 0 | +| messy_fibers_2 · 1028631746 · shape 11 | 18,688/18,688 | 18,688/18,688 | 18,522/18,688 | 1 / 1 / 0.000122070312 / 5.27501106e-06 | 18,688/18,688 | 0 / 0 / 0 / 0 | +| messy_fibers_4 · 1047483128 · shape 11 | 18,688/18,688 | 18,688/18,688 | 17,878/18,688 | 0 / 1 / 3.05175781e-05 / 3.55839729e-05 | 18,688/18,688 | 0 / 0 / 0 / 0 | +| messy_fibers_4 · 1047551360 · shape 6 | 2,336/2,336 | 2,336/2,336 | 1,845/2,336 | 0 / 0 / 0 / 1.63912773e-07 | 2,336/2,336 | 0 / 0 / 0 / 0 | +| messy_fibers_4 · 1047551723 · shape 6 | 2,336/2,336 | 2,336/2,336 | 1,743/2,336 | 0 / 1 / 1.90734863e-06 / 2.23517418e-07 | 2,336/2,336 | 0 / 0 / 0 / 0 | +| messy_fibers_4 · 1047551778 · shape 11 | 18,688/18,688 | 18,688/18,688 | 17,792/18,688 | 0 / 2 / 3.81469727e-06 / 2.4408102e-05 | 18,688/18,688 | 0 / 0 / 0 / 0 | +| microscope_view · 1028199215 · shape 6 | 18,688/18,688 | 18,688/18,688 | 18,642/18,688 | 0 / 0 / 0 / 3.7252903e-08 | 13,369/18,688 | 0 / 0 / 0 / 3.33786011e-06 | +| moisture_noise · 1152046381 · shape 4 | 18,688/18,688 | 18,688/18,688 | 18,669/18,688 | 0 / 0 / 0 / 5.96046448e-08 | 18,625/18,688 | 0 / 0 / 0 / 5.96046448e-08 | +| moisture_noise · 1152046384 · shape 4 | 18,688/18,688 | 18,688/18,688 | 18,664/18,688 | 0 / 0 / 0 / 2.09547579e-08 | 18,613/18,688 | 0 / 0 / 0 / 1.49011612e-08 | + +All isolated squares and discs here have maximum error zero. In Scratches, Messy Fibers 1, 2 and 4 the complete square controls also agree. The authored soft and wave profiles still differ. Microscope and Moisture also have differences with all original branches drawing squares. All six whole roots remain in progress. + +### BNW Spots 3 and Cells 1 pattern sources + +| Root package | Whole outputs compared / attempted | Exact pixels / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---| +| noise_bnw_spots_3 | 6/19 | 104,343/107,776 | — / 2 / .00048828125 / .0000259578228 | +| noise_bnw_spots_3_v2 | 6/19 | 106,559/107,776 | 1 / — / .00048828125 / .00000336766243 | +| noise_cells_1 | 19/19 | 143,321/153,856 | 0 / 1 / .00048828125 / .000000894069672 | + +Each row includes the original 128² and 256² defaults, 128² seed 42 and changed controls, the four-format and independent inputs, and ten additional stage captures. In each spots root 13 settings hit the pattern execution limit. Counts omit outputs without a comparable image. In the v2 spots root the 128² U8 seed-42 case is exact at 16,384/16,384. Cells 1 matches all 5,120 U8 pixels and 4,397/13,568 F32 pixels. [Original four-format controls](#four-format-inventory-comparison) + +For the ten stage captures use inventory index i = 238, 239 or 240 and seeds 100333+11i plus [0,1,2,2,2,2,6,7,8,9]. Start with 16² F32 at defaults. At 32² F32 set (scale, disorder, non-square expansion) to (1,0,on). Use (3,.3125,off) at 32² in U8, U16, F16 and F32. Use (5,.8125,on) at 64×32 F32 and 32×64 U16, then (3,.3125,off) at 64² F32 and (1,0,on) at 128×64 F16. For v2 use (speed, anisotropy, anisotropy angle, tile offset) of (1,0,0,[0,0]), (.6875,.25,.3125,[.125,−.1875]) and (1.4375,.625,−.21875,[−.3125,.4375]) at scales 1, 3 and 5 respectively. + +In the first spots root the three U16 generators match 63/64, 988/1,024 and 255/256 pixels at the 32² scale-one setting. Replace those generators with original grayscale fields matching each stage's resolution and format. The remaining two blends and Levels then give 21,760/21,760 exact output pixels in ten renders. For field j use level 8199(j+1) at defaults, a diagonal of 59003−49j over 302+69j at scale one, and ((11x+31y+7xy+93+47j+(j+1)x)×7919) mod 65536 for the format sweep. For the two rectangular scale-five cases use levels 32769+j and 32767+j selected by (7x+13y+3j) mod 11. Use the format-sweep field at 64² and 128×64. + +The v2 spots graph has three pattern stages in series. At the same 32² setting its first two images match 64/64 and 256/256 U8 pixels. The terminal F32 pattern stage matches 81/1,024. In separate tests substitute an original input for the first stage, then for the second stage. The comparable whole outputs match 8,200/9,472 and 8,208/9,472 respectively. Seven of ten settings per substitution still hit the execution limit. The original Cells 1 graph consists of a single pattern stage. + +For each of these seven generators isolate a shortest connected path from the pattern root to a drawing quadrant. Retain the original Iterate and Switch expressions on the path, keep one outgoing connection per node, and give the stage an empty background input. Compare its authored paraboloid, then substitute a solid square and a disc. Use the ten-case series above with the 64² case omitted. On those isolated paths the authored profiles match 23,180/23,184, 23,097/23,184 and 14,864/17,664 pixels respectively. The square and disc each match 64,032/64,032 pixels across all seven sources, maximum zero. The authored profiles retain F32 maxima of 4.17232513e−7, 6.25848770e−7 and 8.94069672e−7. These three roots remain in progress. + +### Cloud and crystal pattern sources across scales + +| Root package | Whole outputs compared / attempted | Exact pixels / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---| +| noise_clouds_1 | 17/19 | 143,752/149,760 | 1 / 2 / .00048828125 / .0000305175781 | +| noise_clouds_1_v2 | 12/19 | 135,187/141,568 | 1 / 1 / .00048828125 / .00000429153442 | +| noise_clouds_2 | 19/19 | 152,152/153,856 | 1 / 3 / .00048828125 / .0000230669975 | +| noise_clouds_2_v2 | 12/19 | 136,706/141,568 | 1 / 1 / .00048828125 / .00000119209290 | +| noise_crystal_1 | 19/19 | 151,000/153,856 | 0 / 2 / .0001220703125 / .0000207051635 | +| noise_crystal_2 | 19/19 | 152,713/153,856 | 0 / 46 / .00048828125 / .0000152597204 | + +The two original cloud graphs and both crystal graphs produce bit-exact downstream outputs with original procedural fields substituted for all source generators, **87,040/87,040 pixels in 40 renders**, maximum error zero. The v2 packages draw into the preceding stage. In noise_clouds_1_v2 two independent captures used the same field in place of the first generator and retained the final generator. Those captures matched 8,174/9,472 and 8,163/9,472 whole pixels. Both reached the execution limit at seven settings. The maximum errors were .00048828125 F16 and .00000234693289 F32. See also the [gradient warp measurements for Crystal 2](#gradient-warp-displacement-and-sampling). + +For noise_clouds_2_v2, replace its first or second pattern stage with the original field at that stage’s resolution and precision. The two comparable sets match 8,348/9,472 and 8,352/9,472 pixels, with seven execution-limit settings in each set. F32 maxima are .000000834465027 in both sets. F16 maxima are .0001220703125 and .000244140625. + +Use the archive, four-format and independent cases, then the ten [spots scale, resolution and field controls](#bnw-spots-3-and-cells-1-pattern-sources) with inventory indices 244, 245, 246, 247, 249 and 250 in table order. The reference produced all 114 whole outputs. The two missing local outputs for noise_clouds_1 are the scale-five rectangular cases. For each v2 cloud graph the scale-three and scale-five settings reached the execution limit. + +Isolate the shortest connected path from the pattern root to a drawing quadrant in each of the 13 source stages. Keep the original Iterate and Switch controls, disconnect image inputs, and omit the 64² render from the ten new cases. Each solid square and each disc matched every compared pixel. The authored profile retains the following differences across the same paths. + +| Root package | Authored shape number | Square or disc exact pixels per shape | Authored profile exact / compared | Maximum U8 / U16 / F16 / F32 profile error | +|---|---:|---:|---:|---| +| noise_clouds_1 | 8 | 22,080 | 22,074/22,080 | 0 / 0 / 0 / .000000894069672 | +| noise_clouds_1_v2 | 8 | 22,080 | 22,071/22,080 | 0 / 0 / .00000762939453 / .000000834465027 | +| noise_clouds_2 | 8 | 23,184 | 23,166/23,184 | 0 / 0 / .00000762939453 / .000000298023224 | +| noise_clouds_2_v2 | 8 | 23,184 | 23,153/23,184 | 0 / 0 / 0 / .000000759959221 | +| noise_crystal_1 | 4 | 35,328 | 30,215/35,328 | 0 / 1 / .00048828125 / .00000101327896 | +| noise_crystal_2 | 12 | 17,664 | 17,512/17,664 | 0 / 1 / .000244140625 / .00000238418579 | + +### Pattern variable declarations and fixed image selectors + +A draw expression that declares a variable can update its previous value within the same cook. The declaration is visible to that node's later draw properties and descendants. A sibling that only reads the name sees the published graph input, or the field default for an unbound direct link. If their parent declares that name, both siblings can read and write the shared pattern value. The declaration exists even when its Set is on an untaken conditional branch. In a quadrant's five mode expressions a shadowed graph input is unavailable. Its direct link uses the field default and an arithmetic read contributes zero. + +| Original control | Renders | Previous exact | Exact pixels / compared | Previous maximum F32 / U16 | Maximum F32 / U16 | +|---|---:|---:|---:|---|---| +| Pattern type or tint in a sibling, Iterate child or quadrant child | 120 | 48,560 | 51,200/51,200 | 0.65625 / 32,767 | 0 / 0 | +| Sibling order with and without an ancestor declaration | 144 | 59,040 | 61,440/61,440 | 0.75 / 49,151 | 0 / 0 | +| Five read expressions with an earlier sibling assignment | 120 | 48,800 | 51,200/51,200 | 0.5 / 32,767 | 0 / 0 | +| Conditional ancestor assignment with both branches exercised | 84 | 35,840 | 35,840/35,840 | 0 / 0 | 0 / 0 | +| Five quadrant modes reading traversal and image variables | 150 | 59,204 | 62,440/64,000 | 1.75195312 / 32,768 | 0.84176302 / 27,569 | + +Use an Iterate with one repeat and a square on each branch. In the reader use size (.75,.625), offset (.015625,−.03125), seed offset 43 and RGBA background (.125,.3125,.6875,.5). Use 16² F32 at seed 100673, then 32×16 F32 and U16 at 100691. The small writer square has size (.125,.125) and offset (−.375,−.375). For the type controls publish 2 and assign 3. For tint publish (.25,.375,.5,1) and assign (.75,.625,.5,1). Move the assignment from the preceding to the following sibling, the parent Iterate count or the parent quadrant tint. Compare bare getters and getter plus zero with each literal alternative. An integer getter plus 2 in a shadowed child mode selects square 2. + +For the ancestor test, remove or retain the published tint, interchange the children, and either omit the parent assignment or initialize it to (.5625,.1875,.75,1). The first child can update the parent's value before the second reads it. Repeat with an unrelated assignment, a random red addition in [0,.125], a red addition of .125 times the horizontal stamp position, a copy to another name, and a copy to the same name. Only the same-name copy reopens the preceding sibling's pattern value when the parent has no declaration. For the conditional control let a published Boolean choose between the tint assignment followed by count 1, and a bare count 1. Both choices expose the declaration to the children. + +A further 120 same-node controls matched 51,200/51,200 RGBA pixels with zero maximum error. Assign size (.75,.4375) in the seed, frame offset or pattern variation and read it in size. Assign tint in the seed or branch offset and read it in opacity. Run with the published value present and absent and compare each getter to the published, assigned and default literals. The seed and frame offset precede size. Variation follows size, and branch offset follows opacity. + +For the mode controls use the [five original quadrant settings and input field](#assignments-in-quadrant-mode-expressions). At quadrant depth one test depth > .5, depth scale > .25 and > .75, horizontal position > .125, and image width > 24. Use the iteration number > .5 on three repeats. Choose disc or square for the shape and 1 or 0 for the other four modes. Use 16² F32 at seed 100673+j, then 32×16 F32 and U16 at 100691+j, for zero-based mode index j. All five read the traversal depth, depth scale, position and iteration number as zero, and image width follows the output size. Each of shape, blending, premultiplication and seed inheritance matches 12,800/12,800 pixels. Filtering matches 11,240/12,800, with maximum .841763020 F32 and 27569 U16. The separate direct-link seed-inheritance controls now match 8,960/8,960 pixels, maximum zero. + +| Original image selector | Renders | Previous exact | Exact pixels / compared | Previous maximum F32 / U16 / F16 | Maximum F32 / U16 / F16 | +|---|---:|---:|---:|---|---| +| Generic and packed selectors with four, two or one wired slots | 108 | 28,160 | 46,080/46,080 | 0.776470602 / 50,886 / 0.776428223 | 0 / 0 / 0 | +| Offsets to missing and published integer selectors | 99 | 28,160 | 42,240/42,240 | 0.898039222 / 58,853 / 0.897949219 | 0 / 0 / 0 | + +Use four original 16² gray U8 stamps at levels 31, 79, 151 and 229. Wire slots {0,1,2,3}, {1,3} or {2}. Render at 16² F32, 32×16 U16 and 16×32 F16. Add offsets 0, 1 and 2 to seed 102667, 102682 or 102687 for the three wiring cases. For pattern 1, 257 or 259, omit the index, set it to zero, bind it directly to a missing integer, or add zero to that getter. All four choices preserve the fixed slot. For pattern 259 add 0, 1, 2 or 4 to a missing integer, then add a published integer of 2. Compare against direct literal indices and a direct link to the published 2. An expression containing only constants and missing user getters selects the fixed numbered slot. A live selector advances across unwired slots. + +The reference's renders also varied when a property incremented a variable without first initializing it. With a 0.25 increment per square, three visits in a fresh file produced 1.5, and a subsequent render of the same graph could give 6.0. Run at 16²/103779 and 32×16/103781 singly and in both orders, using one visit, three visits, two sibling nodes, two quadrant children or an explicit initial value .125. Across 60 renders MaterialCraft matches 18,304/23,040 F32 pixels, maximum 9. All 12 explicitly initialized renders match 4,608/4,608 pixels and both sizes give 1.875 for three visits. + +Seven new original packages saved through MaterialCraft at format version 1.1.0.202502 reopened in the reference app. Across 20 source-to-save renders covering ancestor and sibling reads, a conditional declaration, mode arithmetic, two sparse image selectors and the initialized counter, all 8,448 pixels match with maximum zero. The 19 previously verified roots match all 3,211,776 pixels in 159 renders after the changes. + +### Direct pattern links with an unbound variable + +An unbound user variable connected directly to a pattern property leaves that property at its default. Within an arithmetic expression the same getter contributes its typed zero. A bound zero supplies an actual zero. MaterialCraft now distinguishes these cases when evaluating a pattern graph. + +| Original control | Renders | Exact pixels / compared | Maximum F32 / U16 error | +|---|---:|---:|---| +| Grayscale and RGBA square, scalar and Float4 opacity | 84 | 35,840/35,840 | 0 / 0 | +| Square size from a Float2 link | 21 | 8,960/8,960 | 0 / 0 | +| Iterate count from an integer link | 21 | 8,960/8,960 | 0 / 0 | +| Seed inheritance from a Boolean link | 21 | 8,310/8,960 | .694821596 / 40631 | + +For the first row, render a centered square of size (.75,.75). In each output kind and for each opacity type, compare seven settings. Omit opacity, read an unbound user variable directly, bind that variable to zero or a second value in an outer Iterate, add the second value to an unbound read, or author either value directly. Use .375 for the scalar and (.25,.5,.75,1) for the vector. Author the scalar controls as constant-return expressions and the vector controls as literal colors. In grayscale, the vector expression supplies its alpha and the literal vector supplies its mean RGB. Use 16² F32, 32×16 F32 and 32×16 U16 at seeds 100801 through 100803. Before the change 32,960/35,840 pixels matched, with maxima of 1 F32 and 65535 U16 levels. + +For the next three rows start with an outer Iterate's initial child. Use a square of size (.8125,.625) and RGBA (.125,.25,.375,1). Compare omission, an unbound read, explicit constant-return expressions for zero and a second value, matching assignments in the outer Iterate, and a derived expression. Use (.375,.625) for the second size. To measure count, insert a second Iterate and draw (.125,.25,.375,.25) on its repeated branch with a changed count of 2. For seed inheritance, use a seed offset of 43, a random stamp color, true as the second value and logical negation for the derived expression. For property index j in the displayed order use the same sizes and formats at seed 101621+11j+i, with i from 0 through 2. Together these rows improved from 23,650 to 26,230/26,880. The remaining 650 pixels occur when the outer Iterate assigns false to the seed-inheritance variable. The reference uses the field default there. [Quadrant mode reads and writes](#assignments-in-quadrant-mode-expressions) + +Six additional original files at format version 1.1.0.202502 were saved by MaterialCraft, reopened in the reference app and compared against their source-file renders. The four pattern files exercise writes from empty and drawing squares, an image-index expression and an exposed bilinear filter. The two pixel-read files exercise an 8² source and a 32×16 source feeding a 16² output. All 19 stored-image comparisons matched, **6,912/6,912 pixels**, maximum error zero. [Pattern properties](#active-properties-of-empty-and-drawing-quadrants) · [Filtered pixel reads](#subnormal-values-in-filtered-pixel-reads) + +Five further saved-file checks cover an unbound scalar opacity, an outer-bound Float4 opacity, missing size, derived count and a false seed-inheritance binding. All 6,400 pixels in 15 source-to-save renders match, maximum zero. + +The 19 previously verified roots also match all 3,211,776 pixels in 159 renders after the direct-link change, maximum error zero. + +### Assignments in quadrant mode expressions + +Local assignments inside the pattern type, blend mode, image filter, premultiplication and seed-inheritance expressions affect that expression's result. Later properties and children retain their incoming variables. Across the [117 child-color controls](#active-properties-of-empty-and-drawing-quadrants), the count improved from 49,120 to **49,920/49,920 exact RGBA pixels**, maximum error zero. The image-index expression still publishes its assignment on a bound image stamp. + +Use an image, solid or empty parent and an initialized child color as in the linked measurements. Separately, render the parent without the child to verify these five settings. Use seed 43 inside the stamp, global seed 100673+j at 16² F32, and 100691+j at 32×16 F32 and U16 for property index j in the order above. Set its size to (.75,.625), offset to (.015625,−.03125), color to (.5,.625,.875,.75) and background to (.125,.3125,.6875,.5). For the image cases, generate a 16² texture with channels ((13x+7y) mod 17)/16, ((5x+11y+xy) mod 19)/18, ((3x+7y) mod 11)/10 and .125+.75((x+5y) mod 7)/6. Substitute a random color for the seed-inheritance cases. + +The native literal, computed-constant and exposed-input settings agree for all 33,280 pixels in the 78 nonliteral comparisons. The corresponding whole-stamp comparison between applications gives 47,760/49,920 exact pixels in 117 renders. Errors remain in bitmap filtering, up to 21504 U16 levels and .516796827 F32. In another 156 renders an outer Iterate assigns an integer or Boolean immediately before the quadrant. Compare a literal, a read of that outer variable, a read with a published graph default, and a Set followed by a Get inside the same expression. The cross-application result is 55,812/66,560, maximum 41882 U16 levels and .701812745 F32. Outer-variable reads in the reference select the property default in all five tests. Writes subsequently read within the same expression select the authored value. + +### Active properties of empty and drawing quadrants + +In an empty quadrant, branch offset and random seed can change a variable that a child reads. Frame offset, opacity, rotation, size and variation publish their assignments on drawing quadrants. Image index publishes its assignment on a bound image stamp. MaterialCraft now skips the inactive draw and image properties. Across 117 independently authored renders the raw count improved from **48,160 to 49,120/49,920 RGBA pixels**. The F32 result is 29,472/29,952 with maximum .5, and U16 is 19,648/19,968 with maximum 32767 levels. + +Use an Iterate with zero repeats. In its count expression set a Float4 variable to (.125,.25,.375,1) before returning zero. Connect the initial child to an empty quadrant, a solid square or an image stamp bound to an original white 16² image. Make that quadrant transparent, except for the stamp being tested. In each property under test first assign (.625,.75,.875,1) to the variable, then return the authored property value. Let a solid child in quadrant zero read the variable as its color. In order, test branch offset, frame offset, opacity, rotation, size, variation, blend mode, image filter, image index, premultiplication, seed, seed inheritance and pattern type. Use zero offsets and rotation, unit size, zero variation, additive blend, image filter 1, index 0, premultiplication enabled, seed 0 and inheritance enabled. At property index j render 16² F32 with seed 100477+j, then 32×16 F32 and U16 with seed 100519+j. + +The child retained its initial color for property writes in blend mode, image filter, premultiplication, seed inheritance and pattern type on all three kinds of parent. Some local children still see those assignments. Independent single-stamp controls confirm that literal, computed-constant and exposed-variable settings choose the same reference draw in 33,280/33,280 pixels across 78 comparisons against 39 literal renders. The 19 previously verified pattern roots match 3,211,776/3,211,776 pixels in 159 renders. + +### Liquid, fiber and related noise sources + +The fourteen roots produced 242/266 comparable whole outputs and 1,703,324/1,891,840 exact pixels. Each microscope-view root reached the pattern graph execution limit in eight of its 19 cases. A failed cook contributes zero compared pixels. Integer differences are storage levels. + +| Root package | Whole outputs compared / attempted | Exact pixels / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---| +| noise_liquid | 19/19 | 135,824/142,592 | 1 / 268 / 0.0009765625 / 0.451499209 | +| noise_messy_fibers_1 | 19/19 | 96,519/142,592 | 1 / 4 / 0.00048828125 / 4.52399254e-05 | +| noise_messy_fibers_1_v2 | 19/19 | 131,876/142,592 | 1 / 2 / 0.00048828125 / 2.95042992e-05 | +| noise_messy_fibers_2 | 19/19 | 84,588/142,592 | 1 / 7 / 0.00048828125 / 7.802248e-05 | +| noise_messy_fibers_2_v2 | 19/19 | 130,496/142,592 | 1 / 4 / 0.00048828125 / 6.29425049e-05 | +| noise_messy_fibers_3 | 19/19 | 123,834/142,592 | 0 / 2 / 0.00048828125 / 2.47955322e-05 | +| noise_messy_fibers_3_v2 | 19/19 | 132,391/142,592 | 1 / 3 / 0.00048828125 / 3.12328339e-05 | +| noise_microscope_view | 19/19 | 140,486/142,592 | 1 / 48 / 0.000244140625 / 0.000274658203 | +| noise_moisture_noise | 11/19 | 107,093/107,776 | 0 / 1 / 0.00048828125 / 1.52587891e-05 | +| noise_moisture_noise_1_v2 | 11/19 | 104,176/107,776 | 0 / 1 / 0 / 1.43051147e-06 | +| noise_moisture_noise_2 | 11/19 | 104,071/107,776 | 1 / 1 / 0.00048828125 / 1.49011612e-06 | +| noise_perlin_noise | 19/19 | 139,281/142,592 | 0 / 4 / 0.00048828125 / 3.05771828e-05 | +| noise_perlin_noise_v2 | 19/19 | 132,970/142,592 | 1 / 39650 / 0.00048828125 / 0.435275048 | +| noise_plasma | 19/19 | 139,719/142,592 | 0 / 2 / 0.000122070312 / 1.52885914e-05 | + +Use the four archived cases, the [four-format sweep and independent seed](#four-format-inventory-comparison), and ten fresh renders. In inventory order, number these roots i=287 through 300, starting with noise_liquid. Use 102011+17i as the base seed. Add [0,1,2,2,2,2,6,7,8,9] for the ten renders. Use [16²,32²,32²,32²,32²,32²,32×16,16×32,64×32,32×64], storage [F32,F32,U8,U16,F16,F32,F32,U16,F32,F16], and settings [defaults,A,B,B,B,B,C,C,B,A]. Apply each setting to the published controls present in that package. + +| Controls | A | B | C | +|---|---|---|---| +| Scale when the package default is 1 | 1 | 1 | 2 | +| Scale with any other default | 1 | 5 | 13 | +| Disorder, nonsquare expansion, disorder speed | 0, on, 1 | .3125, off, .6875 | .8125, on, 1.4375 | +| Disorder anisotropy, its angle, tile offset | 0, 0, (0,0) | .25, .3125, (.125,−.1875) | .625, −.21875, (−.3125,.4375) | +| Warp intensity, angle, angle randomness | 0, 0, 0 | .3125, .21875, .375 | .8125, −.3125, .6875 | +| Line and link counts, color and luminance randomness | 2, 2, 0, 0 | 5, 5, .3125, .3125 | 9, 9, .625, .625 | +| Pattern size, angle, angle randomness, global opacity | (1,1), 0, 0, 1 | (.75,1.25), .21875, .375, .8125 | (1.375,.625), −.3125, .6875, 1.1875 | + +In each of 17 pattern stages, keep the shortest connected path to a quadrant with an authored shape and clear its image inputs. Break equal-length ties by connection identifier. Use the nine cases that exclude 64×32. Render the authored shape, then a square and a disc with the same parameters and connections. The three groups match 122,941/143,616, 143,301/143,616 and 143,298/143,616 pixels respectively. Of 153 runs per group, 146 authored runs, 148 square runs and 148 disc runs produced at least one nonzero reference pixel. Only the Perlin noise root differs on its hard shapes, with maximum U8 / U16 / F16 / F32 error 0 / 32768 / 0 / 3.96000028 for the square and 0 / 32768 / 0 / 3.52000022 for the disc. + +| Root package | Authored shape numbers | Authored exact / compared | Maximum authored U8 / U16 / F16 / F32 error | Square exact / compared | Disc exact / compared | +|---|---|---:|---|---:|---:| +| noise_liquid | 6 | 5,773/8,448 | 0 / 1 / 0.000244140625 / 9.83476639e-07 | 8,448/8,448 | 8,448/8,448 | +| noise_messy_fibers_1 | 11 | 8,099/8,448 | 0 / 1 / 0.000122070312 / 1.84476376e-05 | 8,448/8,448 | 8,448/8,448 | +| noise_messy_fibers_1_v2 | 11 | 8,045/8,448 | 0 / 1 / 3.05175781e-05 / 1.26063824e-05 | 8,448/8,448 | 8,448/8,448 | +| noise_messy_fibers_2 | 11 | 8,357/8,448 | 0 / 1 / 6.10351562e-05 / 6.99050725e-06 | 8,448/8,448 | 8,448/8,448 | +| noise_messy_fibers_2_v2 | 11 | 8,321/8,448 | 0 / 1 / 3.05175781e-05 / 4.35113907e-06 | 8,448/8,448 | 8,448/8,448 | +| noise_messy_fibers_3 | 14 | 8,437/8,448 | 0 / 1 / 0 / 2.5331974e-06 | 8,448/8,448 | 8,448/8,448 | +| noise_messy_fibers_3_v2 | 14 | 8,434/8,448 | 0 / 1 / 0 / 3.41795385e-06 | 8,448/8,448 | 8,448/8,448 | +| noise_microscope_view | 6 | 5,773/8,448 | 0 / 1 / 0.000122070312 / 1.07288361e-06 | 8,448/8,448 | 8,448/8,448 | +| noise_moisture_noise | 4 | 16,669/16,896 | 0 / 1 / 2.38418579e-07 / 3.57627869e-07 | 16,896/16,896 | 16,896/16,896 | +| noise_moisture_noise_1_v2 | 4 | 8,336/8,448 | 0 / 1 / 0 / 3.87430191e-07 | 8,448/8,448 | 8,448/8,448 | +| noise_moisture_noise_2 | 4 | 8,034/8,448 | 0 / 1 / 0 / 2.38418579e-07 | 8,448/8,448 | 8,448/8,448 | +| noise_perlin_noise | 5 | 11,401/16,896 | 0 / 1 / 0.00048828125 / 1.66893005e-06 | 16,896/16,896 | 16,896/16,896 | +| noise_perlin_noise_v2 | 5 | 5,692/8,448 | 0 / 32768 / 0 / 0.653483272 | 8,133/8,448 | 8,130/8,448 | +| noise_plasma | 6 | 11,570/16,896 | 0 / 1 / 0.000244140625 / 9.53674316e-07 | 16,896/16,896 | 16,896/16,896 | + +Where there are downstream stages, replace the source patterns with the same original fields in both applications. Use each source's output size and storage and the ten field settings from the [dirt noise source comparison](#dirt-noise-sources-and-downstream-stages). All five substitutions produced ten comparable images each. + +| Root package | Exact pixels / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---| +| noise_liquid | 8,448/10,496 | 0 / 0 / 0 / 0.836438522 | +| noise_microscope_view | 10,496/10,496 | 0 / 0 / 0 / 0 | +| noise_moisture_noise | 10,496/10,496 | 0 / 0 / 0 / 0 | +| noise_perlin_noise | 10,496/10,496 | 0 / 0 / 0 / 0 | +| noise_plasma | 10,496/10,496 | 0 / 0 / 0 / 0 | + +### Single-branch controls in complete quadrant trees + +A switch or a one-branch iterator can pass a single complete tree to the pattern renderer. MaterialCraft previously discarded the measured draw order as soon as it visited either control. The renderer now counts the outer trees that actually reach a quadrant. It checks inner iteration branching, the connected quadrants, draw counts and stamp properties before applying the order. The regression’s fourth outer repetition passes a depth-nine tree through one inner repetition. At (8,0) and (0,16) the previous cook returned zero. The corrected cook and the one-processor reference return 2⁻²⁵. [Original square construction](#three-active-quadrant-levels-in-dirt-5-and-dirt-gradient) · [Normal cook regression](../crates/nodes/src/pattern/tests.rs) + +The following comparisons use original square stamps on white with wrapping off. Draw at depths seven, eight and nine, or seven and eight in the shorter tree. For the first four configurations use the first four rows of the linked square construction with the same sizes, offsets, gains and seeds. Repeat the first two gain configurations at 64 × 32 and 32 × 64 with seeds 292177 and 292214. For the nine-repetition and shorter-tree controls use the first two 128² cases and the 64 × 32 case. Counts compare stored F32 bits. Each maximum is an absolute error. + +| Square control | Renders | Earlier exact / total · max | Corrected exact / total · max | +|---|---:|---:|---:| +| Direct depth-nine tree | 6 | 53,248/53,248 · 0 | 53,248/53,248 · 0 | +| One outer repetition | 6 | 52,160/53,248 · 2.98023224e-08 | 53,248/53,248 · 0 | +| One inner repetition at depth seven | 6 | 52,160/53,248 · 2.98023224e-08 | 53,248/53,248 · 0 | +| Both iterators | 6 | 52,096/53,248 · 2.98023224e-08 | 53,184/53,248 · 2.98023224e-08 | +| Both iterators and an outer switch | 6 | 52,160/53,248 · 2.98023224e-08 | 53,248/53,248 · 0 | +| Inner initial branch with zero repetitions | 6 | 52,160/53,248 · 2.98023224e-08 | 53,248/53,248 · 0 | +| Dot control at depth seven | 6 | 53,248/53,248 · 0 | 53,248/53,248 · 0 | +| Reopened graph with both iterators and switch | 3 | 26,048/26,624 · 2.98023224e-08 | 26,624/26,624 · 0 | +| Only outer repetition 3 of 0–8 draws | 3 | 33,728/34,816 · 2.98023224e-08 | 34,816/34,816 · 0 | +| Outer repetitions 3 and 6 both draw | 3 | 34,752/34,816 · 5.96046448e-08 | 34,752/34,816 · 5.96046448e-08 | +| Two inner repetitions | 3 | 34,816/34,816 · 0 | 34,816/34,816 · 0 | +| Connected initial and repeated inner branches | 3 | 34,816/34,816 · 0 | 34,816/34,816 · 0 | +| One outer draw, inner initial branch only | 3 | 33,728/34,816 · 2.98023224e-08 | 34,816/34,816 · 0 | +| Direct depth-eight trees with four or two children | 6 | 69,632/69,632 · 0 | 69,632/69,632 · 0 | +| Same depth-eight trees through both iterators and switch | 6 | 67,584/69,632 · 2.98023224e-08 | 69,632/69,632 · 0 | +| Three independent recaptures of the 128² two-iterator case | 3 | 47,424/49,152 · 2.98023224e-08 | 49,152/49,152 · 0 | +| Controls inserted before depths 3, 4, 5, 6 or 8 | 18 | 203,584/208,896 · 2.98023224e-08 | 208,896/208,896 · 0 | + +The first native render with both iterators differed from the direct tree at 64 of 16,384 pixels, maximum 2⁻²⁵. Three later captures on separate single processors each reproduced all 16,384 direct pixels. The table retains that first capture. Two active outer trees still differ at 64 pixels across the three settings. All three multiple-branch controls reproduced their earlier local raw buffers. + +In the final stage of Noise Dirt Gradient v2, remove the background connection and set both iteration counts to one. Use the [three gradient settings](#initial-branch-of-a-nested-pattern-iterator). For the constant-color rows give every active stamp RGBA (.3125,.3125,.3125,1). The original windows come from the stage. The unit window is (0,1,0,1) on both render and tiling regions. + +| Final-stage controls | Earlier F32 exact / total · max | Corrected F32 exact / total · max | +|---|---:|---:| +| Unit windows, wrapping off | 1,077/2,816 · 7.4505806e-08 | 2,816/2,816 · 0 | +| Original windows, wrapping off | 1,643/2,816 · 4.47034836e-08 | 2,816/2,816 · 0 | +| Unit windows, wrapping off, constant color | 1,041/2,816 · 2.98023224e-08 | 2,816/2,816 · 0 | +| Original windows, wrapping off, constant color | 1,623/2,816 · 2.98023224e-08 | 2,816/2,816 · 0 | +| Unit windows, both axes wrapped | 669/2,816 · 8.94069672e-08 | 669/2,816 · 8.94069672e-08 | + +| Final-stage controls | Eight-processor F32 · max | Reopened in both applications · max | Original versus reopened reference · max | +|---|---:|---:|---:| +| Unit windows, wrapping off | 1,090/2,816 · 7.4505806e-08 | 2,816/2,816 · 0 | 2,816/2,816 · 0 | +| Original windows, wrapping off | 1,671/2,816 · 5.96046448e-08 | 2,816/2,816 · 0 | 2,816/2,816 · 0 | +| Unit windows, both axes wrapped | 664/2,816 · 1.1920929e-07 | 669/2,816 · 8.94069672e-08 | 2,816/2,816 · 0 | + +Each successful local save reproduced its original raw buffer. All 344,064 logical stamps have one physical copy with wrapping disabled. With both axes wrapped, the same three trees submit 353,000, 352,711 and 353,256 copies. Their submission order remains open. With all original controls and the background connected, the first two stages still match 44/44 and 704/704 U8 samples. The final stage matches 1,941/2,816 · 2.38418579e-07 on the three original captures. [Sixty whole gradient settings](#sixty-whole-renders-after-correcting-the-inner-iterator) + +The following whole-graph measurements compare the corrected cook with the same native inputs at each processor count. Reopens use the normal SBS writer. The last column lists stored U8, U16, F16 and F32 maxima in that order. A dash identifies an unmeasured format. + +| Package · reference | Completed / requested | Exact / total | Maximum by format | +|---|---:|---:|---| +| noise_clouds_1 · one | 11/11 | 5,626/5,632 | 0 / 0 / 0 / 1.52587891e-05 | +| noise_clouds_1 · eight | 11/11 | 5,626/5,632 | 0 / 0 / 0 / 1.52587891e-05 | +| noise_clouds_1 · reopened, one | 2/2 | 768/768 | — / 0 / 0 / — | +| noise_clouds_1_v2 · one | 11/11 | 5,373/5,632 | 0 / 0 / 0 / 1.49011612e-07 | +| noise_clouds_1_v2 · eight | 11/11 | 5,411/5,632 | 0 / 0 / 0 / 1.78813934e-07 | +| noise_clouds_1_v2 · reopened, one | 2/2 | 768/768 | — / 0 / 0 / — | +| noise_clouds_2_v2 · one | 11/11 | 5,612/5,632 | 0 / 0 / 0 / 5.96046448e-08 | +| noise_clouds_2_v2 · eight | 11/11 | 5,608/5,632 | 0 / 0 / 0 / 5.96046448e-08 | +| noise_clouds_2_v2 · reopened, one | 2/2 | 768/768 | — / 0 / 0 / — | +| noise_dirt_5 · one | 8/12 | 6,911/6,912 | 0 / — / 0.000122070312 / 0 | +| noise_dirt_5 · eight | 8/12 | 6,911/6,912 | 0 / — / 0 / 5.08278608e-05 | +| noise_dirt_5 · reopened, one | 1/2 | 1,024/1,024 | — / — / — / 0 | + +The default 16² F32 Clouds 2 v2 at seed 103050 improved from 251/256 to 256/256 against the one-processor capture. Against eight processors it changed from 255/256 to 252/256. The eight-processor maximum is 5.96046448e-08. Every other listed whole output and every comparable save reproduced the prior local digest. + +For an independent repeat, open both source and save and render seeds 103050, 103067, 103050, 103093 and 103050 in that order. Repeat on each of two individual processors and then on eight. The twelve single-processor visits to the original seed match 3,072/3,072 · 0. The six eight-processor visits match 1,512/1,536 · 5.96046448e-08. At the two changed seeds the counts are 2,048/2,048 · 0 on the individual processors and 1,014/1,024 · 5.96046448e-08 on eight. Each local reopen reproduces the source at all three seeds. + +
+Whole-graph controls and saved cases + +| Package | Size | Seed | Controls | Formats | Reopened | Execution budget reached | +|---|---|---:|---|---|---|---| +| noise_clouds_1 | 16 × 16 | 103017 | Defaults | F32 | — | — | +| noise_clouds_1 | 32 × 32 | 103019 | disorder=0.3125, non_square_expansion=false, scale=3 | F16 | — | — | +| noise_clouds_1 | 16 × 16 | 0 | Defaults | U8, U16, F16 | U16 | — | +| noise_clouds_1 | 64 × 16 | 42 | disorder=0.03125, non_square_expansion=true, scale=2 | F32 | — | — | +| noise_clouds_1 | 16 × 32 | 0 | Defaults | F32 | — | — | +| noise_clouds_1 | 32 × 16 | 169440 | disorder=0.34375, scale=1 | U8, U16, F16, F32 | F16 | — | +| noise_clouds_1_v2 | 16 × 16 | 103028 | Defaults | F32 | — | — | +| noise_clouds_1_v2 | 32 × 32 | 103030 | disorder=0.3125, disorder_anisotropy=0.25, disorder_anisotropy_angle=0.3125, disorder_speed=0.6875, non_square_expansion=false, scale=3, tile_offset=[0.125, -0.1875] | F16 | — | — | +| noise_clouds_1_v2 | 16 × 16 | 0 | Defaults | U8, U16, F16 | U16 | — | +| noise_clouds_1_v2 | 64 × 16 | 42 | disorder=0.03125, disorder_anisotropy=0.03125, disorder_anisotropy_angle=-0.21875, disorder_speed=0.03125, non_square_expansion=true, scale=2, tile_offset=[-0.3125, 0.37890625] | F32 | — | — | +| noise_clouds_1_v2 | 16 × 32 | 0 | Defaults | F32 | — | — | +| noise_clouds_1_v2 | 32 × 16 | 169477 | disorder=0.34375, disorder_anisotropy=0.171875, disorder_anisotropy_angle=-0.03125, disorder_speed=0.796875, scale=1, tile_offset=[0.0751953125, -0.12890625] | U8, U16, F16, F32 | F16 | — | +| noise_clouds_2_v2 | 16 × 16 | 103050 | Defaults | F32 | — | — | +| noise_clouds_2_v2 | 32 × 32 | 103052 | disorder=0.3125, disorder_anisotropy=0.25, disorder_anisotropy_angle=0.3125, disorder_speed=0.6875, non_square_expansion=false, scale=3, tile_offset=[0.125, -0.1875] | F16 | — | — | +| noise_clouds_2_v2 | 16 × 16 | 0 | Defaults | U8, U16, F16 | U16 | — | +| noise_clouds_2_v2 | 64 × 16 | 42 | disorder=0.03125, disorder_anisotropy=0.03125, disorder_anisotropy_angle=-0.21875, disorder_speed=0.03125, non_square_expansion=true, scale=2, tile_offset=[-0.3125, 0.37890625] | F32 | — | — | +| noise_clouds_2_v2 | 16 × 32 | 0 | Defaults | F32 | — | — | +| noise_clouds_2_v2 | 32 × 16 | 169551 | disorder=0.34375, disorder_anisotropy=0.171875, disorder_anisotropy_angle=-0.03125, disorder_speed=0.796875, scale=1, tile_offset=[0.0751953125, -0.12890625] | U8, U16, F16, F32 | F16 | — | +| noise_dirt_5 | 16 × 16 | 105543 | Defaults | F32 | — | — | +| noise_dirt_5 | 32 × 32 | 105544 | disorder=0.0, non_square_expansion=true, scale=1 | F32 | F32 | — | +| noise_dirt_5 | 32 × 32 | 105545 | disorder=0.3125, non_square_expansion=false, scale=1 | U8, F16 | — | — | +| noise_dirt_5 | 32 × 16 | 105549 | disorder=0.8125, non_square_expansion=true, scale=2 | F32 | F32 | F32 | +| noise_dirt_5 | 16 × 32 | 105550 | disorder=0.8125, non_square_expansion=true, scale=2 | U16 | — | U16 | +| noise_dirt_5 | 64 × 32 | 105551 | disorder=0.3125, non_square_expansion=false, scale=1 | F32 | — | — | +| noise_dirt_5 | 16 × 32 | 0 | Defaults | U8, F16, F32 | — | — | +| noise_dirt_5 | 32 × 16 | 42 | disorder=0.21875, non_square_expansion=true, scale=2 | U16, F32 | — | U16, F32 | + +
+ +On one processor, median release process CPU time over three interleaved runs changed from 11.453 to 11.672 seconds for six fresh one-tree cooks, 14.109 to 14.078 seconds for four two-tree cooks, and 21.312 to 21.281 seconds for one default 16² gradient cook. These times include opening the package and reading the result. All 455 node and evaluator release tests passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. + +### Sixty whole renders after correcting the inner iterator + +The 60 settings for Noise Dirt Gradient v2 include the 12 fresh cases in the [isolated iterator measurements](#initial-branch-of-a-nested-pattern-iterator). The table counts stored pixels from successful cooks. The other settings reached the pattern graph traversal budget. Both whole and saved comparisons use the same material output. Integer maxima are in storage levels. + +| Comparison | Rendered / attempted | Exact settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:|---:| +| Earlier, one processor | 40/60 | 0 | 170,088/173,568 · 40 | 92,735/96,768 · 11437 | 90,188/93,696 · 0.16015625 | 61,278/100,608 · 0.174517393 | +| Corrected, one processor | 40/60 | 15 | 173,567/173,568 · 1 | 96,663/96,768 · 1 | 93,692/93,696 · 0.00048828125 | 64,247/100,608 · 7.15255737e-07 | +| Corrected, eight processors | 40/60 | 18 | 173,568/173,568 · 0 | 96,689/96,768 · 1 | 93,690/93,696 · 0.00048828125 | 71,020/100,608 · 3.57627869e-07 | +| Reference one versus eight | 60/60 | 19 | 198,143/198,144 · 1 | 240,335/240,640 · 1 | 101,878/101,888 · 0.00048828125 | 147,429/244,992 · 1.54972076e-06 | +| Earlier after reopening | 8/12 | 0 | 20,618/22,528 · 40 | 18,041/18,944 · 7324 | — | 43,808/66,560 · 0.0274509788 | +| Corrected after reopening | 8/12 | 3 | 22,528/22,528 · 0 | 18,927/18,944 · 1 | — | 44,076/66,560 · 4.76837158e-07 | +| Reference original versus reopened | 12/12 | 11 | 26,624/26,624 · 0 | 51,712/51,712 · 0 | — | 70,540/71,168 · 2.38418579e-07 | + +Every comparable MaterialCraft save reproduces its original local floating-point buffer. The reference columns include all successful reference renders, including the settings that exceeded the MaterialCraft budget. + +
+Whole and reopened settings + +Use `disorder`, `disorder_speed`, `disorder_anisotropy`, `disorder_anisotropy_angle`, `non_square_expansion` in the listed control order. + +| Size | Seed | Controls | Formats | Reopened | Whole budget reached | Reopen budget reached | +|---|---:|---|---|---|---|---| +| 128 × 128 | 0 | Defaults | U8, U16, F16, F32 | U8, U16 | — | — | +| 256 × 256 | 0 | Defaults | U8 | — | — | — | +| 128 × 128 | 42 | Defaults | U8 | — | — | — | +| 128 × 128 | 0 | 0.37, 0.6, 0.3, 0.125, default | U8 | — | U8 | — | +| 32 × 32 | 113 | 0.37, 0.6, 0.3, 0.125, default | F32 | — | — | — | +| 64 × 64 | 42 | 0.37, 0.6, 0.3, 0.125, default | U8, U16, F16, F32 | U8 | — | — | +| 16 × 16 | 105594 | Defaults | F32 | — | — | — | +| 32 × 32 | 105595 | 0, 1, 0, 0, on | F32 | F32 | — | — | +| 32 × 32 | 105596 | 0.3125, 0.6875, 0.25, 0.3125, off | U8, U16, F16, F32 | — | — | — | +| 32 × 16 | 105600 | 0.8125, 1.4375, 0.625, -0.21875, on | F32 | F32 | F32 | F32 | +| 16 × 32 | 105601 | 0.8125, 1.4375, 0.625, -0.21875, on | U16 | — | — | — | +| 64 × 32 | 105602 | 0.3125, 0.6875, 0.25, 0.3125, off | F32 | — | — | — | +| 32 × 64 | 105603 | 0, 1, 0, 0, on | F16 | — | — | — | +| 16 × 32 | 0 | Defaults | U8, U16, F16, F32 | U16 | — | — | +| 32 × 16 | 42 | 0.21875, 0.21875, 0.21875, -0.03125, on | U16, F32 | — | U16, F32 | — | +| 64 × 64 | 433610 | 0.9375, 0.9375, 0.9375, 0.6875, off | U8, U16, F16, F32 | U8 | U8, U16, F16, F32 | U8 | +| 128 × 32 | 433647 | 0.046875, 0.046875, 0.046875, -0.203125, on | U16, F32 | F32 | U16, F32 | F32 | +| 32 × 128 | 433684 | 0.5625, 0.5625, 0.5625, 0.3125, off | U8, U16, F16, F32 | — | U8, U16, F16, F32 | — | +| 256 × 128 | 433758 | 0.328125, 0.328125, 0.328125, 0.078125, off | U16, F32 | — | U16, F32 | — | +| 128 × 256 | 433795 | 0.8125, 0.8125, 0.8125, 0.5625, on | U16, F32 | U16 | U16, F32 | U16 | +| 256 × 256 | 42 | Defaults | U8, U16, F16, F32 | F32 | — | — | +| 512 × 128 | 433869 | 0.671875, 0.671875, 0.671875, 0.421875, on | U16, F32 | — | U16, F32 | — | +| 16 × 32 | 281778 | Defaults | U16, F32 | — | — | — | +| 64 × 32 | 281845 | 0, 1, 0, 0, on | U8, U16, F16, F32 | U8 | — | — | +| 32 × 64 | 281912 | 0.8125, 1.4375, 0.625, -0.21875, on | U8, U16, F16, F32 | U16 | — | — | +| 64 × 64 | 281979 | 0.21875, 0.21875, 0.21875, -0.03125, on | U16, F32 | — | — | — | + +
+ +### Initial branch of a nested pattern iterator + +In Noise Dirt Gradient v2 the initial branch of an inner iterator reads the caller’s iteration number. MaterialCraft had set it to zero. The repeated branch starts at zero and increments for its own repetitions. This affected opacity in the middle of the graph’s three pattern stages. Passing the existing number to the initial branch corrects all 704 middle-stage U8 samples in the following three settings. The final F32 stage still has rounding differences. + +| Root size, seed | Stage | Earlier exact / total · max | Corrected exact / total · max | Original versus separately exposed reference stage · max | +|---|---|---:|---:|---:| +| 16 × 16, 105594 | First pattern, U8 | 4/4 · 0 | 4/4 · 0 | 4/4 · 0 | +| 16 × 16, 105594 | Middle pattern, U8 | 64/64 · 0 | 64/64 · 0 | 64/64 · 0 | +| 16 × 16, 105594 | Final pattern, F32 | 177/256 · 2.38418579e-07 | 177/256 · 2.38418579e-07 | 256/256 · 0 | +| 16 × 32, 281778 | First pattern, U8 | 8/8 · 0 | 8/8 · 0 | 8/8 · 0 | +| 16 × 32, 281778 | Middle pattern, U8 | 100/128 · 48 | 128/128 · 0 | 128/128 · 0 | +| 16 × 32, 281778 | Final pattern, F32 | 290/512 · 0.174517453 | 386/512 · 2.38418579e-07 | 430/512 · 2.38418579e-07 | +| 64 × 32, 281845 | First pattern, U8 | 32/32 · 0 | 32/32 · 0 | 32/32 · 0 | +| 64 × 32, 281845 | Middle pattern, U8 | 147/512 · 45 | 512/512 · 0 | 512/512 · 0 | +| 64 × 32, 281845 | Final pattern, F32 | 170/2,048 · 0.15857181 | 1,378/2,048 · 2.38418579e-07 | 1,536/2,048 · 1.78813934e-07 | + +The first two settings use defaults. For the third use zero disorder, zero anisotropy and anisotropy angle, speed 1 and nonsquare expansion enabled. Read each original intermediate output before connecting that stage directly to the output in a separate copy. The last column records differences between those two reference captures. Leaving only the background matched 1,216/1,216 U8 pixels across six settings. The outer position, direction, counters and switch readouts matched 11,264/11,264 F32 samples. Selecting one inner initial branch at outer iterations 1 and 3 produced nonzero local pixels where the reference drew zero. The repeated branches matched. Pinning the number to zero or to one in the opacity expression made the isolated branches agree. All 20 isolated branch renders now match, 6,400/6,400 · 0. + +For an independent counter probe, connect the outer iterator’s repeat output to an inner iterator. Draw an additive half-width square on each of the inner iterator’s branches, centered at horizontal coordinates .25 and .75. Set roughness to zero, use black behind the squares and set opacity to the current iteration number divided by 32. For three outer and one inner repetition the two F32 halves read .09375 and 0. With four outer and three inner repetitions they read .1875 and .375. With two outer repetitions and zero inner repetitions the initial half still reads .03125. The new node test failed on the earlier implementation and passed after the correction. [Counter regression](../crates/nodes/src/pattern/tests.rs) + +| Independent square graph | Settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Earlier one processor | 33 | 1,408/2,816 · 80 | 1,408/2,816 · 20480 | 1,408/2,816 · 0.3125 | 11,008/14,016 · 0.3125 | +| One processor | 33 | 2,816/2,816 · 0 | 2,816/2,816 · 0 | 2,816/2,816 · 0 | 14,016/14,016 · 0 | +| Eight processors | 33 | 2,816/2,816 · 0 | 2,816/2,816 · 0 | 2,816/2,816 · 0 | 14,016/14,016 · 0 | +| One processor after reopening | 12 | 256/256 · 0 | 512/512 · 0 | 2,048/2,048 · 0 | 4,032/4,032 · 0 | + +Use (outer, inner, width, height) of (3,1,16,16), (1,1,16,32), (3,2,32,16), (4,3,8,8), (2,0,16,8), (0,3,8,16), (1,4,32,32) and (5,2,32,64), with seed 283271 + 19j for zero-based row j. Render F32 for all three wirings (both, initial only, repeat only). With both branches connected render all four formats at rows 0, 2 and 7. For a reopen take every third setting of each wiring, beginning with the first, in U8, U16, F16, F32 order where all are present. + +| Whole graph across four fresh seeds | Settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:| +| Earlier, one processor | 12 | 2,301/4,096 · 40 | 5,753/8,704 · 11437 | 2,092/4,096 · 0.158691406 | 3,572/8,704 · 0.174517393 | +| Corrected, one processor | 12 | 4,096/4,096 · 0 | 8,696/8,704 · 1 | 4,096/4,096 · 0 | 5,523/8,704 · 5.36441803e-07 | +| Corrected, eight processors | 12 | 4,096/4,096 · 0 | 8,689/8,704 · 1 | 4,096/4,096 · 0 | 6,084/8,704 · 3.57627869e-07 | +| Reference one versus eight | 12 | 4,096/4,096 · 0 | 8,691/8,704 · 1 | 4,096/4,096 · 0 | 5,577/8,704 · 4.76837158e-07 | + +| Size, seed | Exposed controls | Formats | +|---|---|---| +| 16 × 32, 281778 | Defaults | U16, F32 | +| 64 × 32, 281845 | `disorder` 0.0, `disorder_anisotropy` 0, `non_square_expansion` on, `disorder_anisotropy_angle` 0, `disorder_speed` 1 | U8, U16, F16, F32 | +| 32 × 64, 281912 | `disorder` 0.8125, `disorder_anisotropy` 0.625, `non_square_expansion` on, `disorder_anisotropy_angle` -0.21875, `disorder_speed` 1.4375 | U8, U16, F16, F32 | +| 64 × 64, 281979 | `disorder` 0.21875, `disorder_speed` 0.21875, `disorder_anisotropy` 0.21875, `disorder_anisotropy_angle` -0.03125, `non_square_expansion` on | U16, F32 | + +Polygon Paths also has a function call beneath a nested initial branch. The 19 archived RGBA settings retain all 5,120 original pixels. Add 32 × 16 with 9 sides, 16 × 64 with 13 sides and 64 × 32 with 21 sides at seeds 285143, 285180 and 285217. Render all four formats in U8, U16, F16, F32 order. All 31 settings match 9,216/9,216 pixels on each processor count, with all four components exact. Reopen every fourth setting starting with the first. Both applications reproduce all 2,304 pixels across the eight reopens. All maxima are zero. [Archived polygon settings](#color-temperature-range-reductions-sky-parameters-and-polygon-paths) + +### Sixty whole settings for three directional and dirt noise packages + +Each package has 60 distinct settings. The first 48 combine the earlier default, seed, control and format captures with the larger size sweep. Twelve additional settings exercise four fresh seeds and square and rectangular sizes. The table compares the same raw output against one- and eight-processor captures. Each saved package went through MaterialCraft’s SBS writer and reopened in both applications. The 12 settings per package include defaults and changed controls. Counts exclude replacement outputs from failed cooks. [Earlier directional stages](#directional-noise-and-scratch-pattern-sources) · [Earlier dirt stages](#dirt-noise-sources-and-downstream-stages) + +| Package · comparison | Rendered / attempted | Exact settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:|---:| +| noise_directional_noise_1_v2 · one processor | 56/60 | 18 | 135,421/135,424 · 1 | 249,291/249,600 · 1 | 88,312/88,320 · 0.00048828125 | 145,946/252,928 · 4.17232513e-07 | +| noise_directional_noise_1_v2 · eight processors | 56/60 | 22 | 135,424/135,424 · 0 | 249,343/249,600 · 1 | 88,309/88,320 · 0.00048828125 | 152,607/252,928 · 4.17232513e-07 | +| noise_directional_noise_1_v2 · reference one versus eight | 60/60 | 21 | 137,469/137,472 · 1 | 251,327/251,648 · 1 | 90,357/90,368 · 0.00048828125 | 141,410/254,976 · 4.17232513e-07 | +| noise_directional_noise_1_v2 · one processor after reopening | 11/12 | 3 | 28,671/28,672 · 1 | 6,389/6,400 · 1 | 1,024/1,024 · 0 | 45,629/84,992 · 4.17232513e-07 | +| noise_directional_noise_1_v2 · reference original versus reopened | 12/12 | 10 | 30,720/30,720 · 0 | 6,400/6,400 · 0 | 1,024/1,024 · 0 | 83,408/84,992 · 2.38418579e-07 | +| noise_dirt_5 · one processor | 48/60 | 21 | 97,792/97,792 · 0 | 298,925/299,008 · 4 | 99,828/99,840 · 0.000244140625 | 205,006/205,056 · 5.0842762e-05 | +| noise_dirt_5 · eight processors | 48/60 | 26 | 97,792/97,792 · 0 | 298,939/299,008 · 4 | 99,832/99,840 · 0.000122070312 | 205,009/205,056 · 5.08725643e-05 | +| noise_dirt_5 · reference one versus eight | 60/60 | 26 | 99,840/99,840 · 0 | 338,835/338,944 · 4 | 101,869/101,888 · 0.000244140625 | 244,918/244,992 · 5.08725643e-05 | +| noise_dirt_5 · one processor after reopening | 9/12 | 6 | 26,624/26,624 · 0 | 49,653/49,664 · 4 | — | 66,543/66,560 · 5.0842762e-05 | +| noise_dirt_5 · reference original versus reopened | 12/12 | 11 | 26,624/26,624 · 0 | 51,712/51,712 · 0 | — | 71,167/71,168 · 5.0842762e-05 | +| noise_dirt_gradient · one processor | 58/60 | 38 | 99,840/99,840 · 0 | 273,090/273,408 · 1 | 101,885/101,888 · 0.00048828125 | 178,797/179,456 · 1.52587891e-05 | +| noise_dirt_gradient · eight processors | 58/60 | 34 | 99,840/99,840 · 0 | 273,101/273,408 · 1 | 101,885/101,888 · 0.00048828125 | 178,795/179,456 · 1.52587891e-05 | +| noise_dirt_gradient · reference one versus eight | 60/60 | 32 | 99,840/99,840 · 0 | 338,795/338,944 · 1 | 101,884/101,888 · 0.00048828125 | 244,883/244,992 · 1.52587891e-05 | +| noise_dirt_gradient · one processor after reopening | 12/12 | 8 | 26,624/26,624 · 0 | 51,576/51,712 · 1 | — | 71,136/71,168 · 1.52587891e-05 | +| noise_dirt_gradient · reference original versus reopened | 12/12 | 12 | 26,624/26,624 · 0 | 51,712/51,712 · 0 | — | 71,168/71,168 · 0 | + +All comparable MaterialCraft reopens reproduce their original local buffers. The settings marked in the last two columns reached the pattern graph execution budget. The directional measurements used revision `e1e3c1e` and the two dirt measurements used `c7a1a37`. + +
+noise_directional_noise_1_v2 · settings and saved comparisons + +Use `angle`, `angle_random`, `disorder`, `disorder_anisotropy`, `disorder_anisotropy_angle`, `disorder_speed`, `non_square_expansion`, `scale`, `tile_offset` in the listed control order. An omitted control uses the graph default. + +| Size | Seed | Controls | Formats | Reopened | Whole budget reached | Reopen budget reached | +|---|---:|---|---|---|---|---| +| 128 × 128 | 0 | Defaults | U8 | U8 | — | — | +| 256 × 256 | 0 | Defaults | U8, U16, F16, F32 | — | — | — | +| 128 × 128 | 42 | Defaults | U8 | — | — | — | +| 128 × 128 | 0 | 0.125, 0.2, 0.37, 0.3, 0.125, 0.6, default, 2, 0.17, 0.29 | U8 | — | — | — | +| 32 × 32 | 113 | 0.125, 0.2, 0.37, 0.3, 0.125, 0.6, default, 2, 0.17, 0.29 | F32 | — | — | — | +| 64 × 64 | 42 | 0.125, 0.2, 0.37, 0.3, 0.125, 0.6, default, 2, 0.17, 0.29 | U8, U16, F16, F32 | U8 | — | — | +| 16 × 16 | 103813 | Defaults | F32 | — | — | — | +| 32 × 32 | 103814 | 0, 0, 0, 0, 0, 1, on, 1, 0.0, 0.0 | F32 | F32 | — | — | +| 32 × 32 | 103815 | 0.15625, 0.21875, 0.3125, 0.25, 0.3125, 0.6875, off, 1, 0.125, -0.1875 | U8, U16, F16, F32 | — | — | — | +| 64 × 32 | 103819 | -0.21875, 0.40625, 0.6875, 0.625, -0.21875, 1.4375, on, 2, -0.3125, 0.4375 | F32 | F32 | — | — | +| 32 × 64 | 103820 | 0.15625, 0.21875, 0.3125, 0.25, 0.3125, 0.6875, off, 1, 0.125, -0.1875 | U16 | — | — | — | +| 32 × 32 | 103821 | 0.375, 0.03125, 0.125, 0.125, 0.15625, 0.875, off, 3, -0.0625, 0.125 | F32 | — | — | — | +| 64 × 32 | 103822 | 0, 0, 0, 0, 0, 1, on, 1, 0.0, 0.0 | F16 | — | — | — | +| 16 × 16 | 0 | Defaults | U8, U16, F16, F32 | U16 | — | — | +| 64 × 16 | 42 | -0.21875, 0.03125, 0.03125, 0.03125, -0.21875, 0.03125, on, 2, -0.3125, 0.37890625 | U8, U16, F16, F32 | F16 | — | — | +| 16 × 64 | 411615 | 0.625, 0.875, 0.875, 0.875, 0.625, 0.875, off, 1, 0.53125, -0.359375 | U16, F32 | — | — | — | +| 64 × 64 | 411676 | 0.09375, 0.34375, 0.34375, 0.34375, 0.09375, 0.34375, on, 3, 0.0, 0.10546875 | U8, U16, F16, F32 | U16 | — | — | +| 128 × 64 | 411737 | 0.71875, 0.96875, 0.96875, 0.96875, 0.71875, 0.96875, off, 2, 0.625, -0.44140625 | U16, F32 | — | — | — | +| 64 × 128 | 411798 | -0.0625, 0.1875, 0.1875, 0.1875, -0.0625, 0.1875, on, 1, -0.15625, 0.2421875 | U8, U16, F16, F32 | U8 | — | — | +| 128 × 128 | 411859 | 0.40625, 0.65625, 0.65625, 0.65625, 0.40625, 0.65625, off, 3, 0.3125, -0.16796875 | U16, F32 | F32 | — | — | +| 128 × 512 | 411981 | 0.28125, 0.53125, 0.53125, 0.53125, 0.28125, 0.53125, off, 2, 0.1875, -0.05859375 | U16, F32 | F32 | — | — | +| 512 × 128 | 412042 | -0.15625, 0.09375, 0.09375, 0.09375, -0.15625, 0.09375, on, 1, -0.25, 0.32421875 | U16, F32 | — | — | — | +| 16 × 32 | 194891 | Defaults | U16, F32 | — | — | — | +| 64 × 32 | 194938 | 0.09375, 0.34375, 0.34375, 0.34375, 0.09375, 0.34375, on, 3, 0.0, 0.10546875 | U8, U16, F16, F32 | U8 | U8, U16, F16, F32 | U8 | +| 32 × 64 | 194985 | -0.0625, 0.1875, 0.1875, 0.1875, -0.0625, 0.1875, on, 1, -0.15625, 0.2421875 | U8, U16, F16, F32 | U16 | — | — | +| 64 × 64 | 195032 | 0.28125, 0.53125, 0.53125, 0.53125, 0.28125, 0.53125, off, 2, 0.1875, -0.05859375 | U16, F32 | — | — | — | + +
+ +
+noise_dirt_5 · settings and saved comparisons + +Use `scale`, `disorder`, `non_square_expansion` in the listed control order. An omitted control uses the graph default. + +| Size | Seed | Controls | Formats | Reopened | Whole budget reached | Reopen budget reached | +|---|---:|---|---|---|---|---| +| 128 × 128 | 0 | Defaults | U16, U8, F16, F32 | U16, U8 | — | — | +| 256 × 256 | 0 | Defaults | U16 | — | — | — | +| 128 × 128 | 42 | Defaults | U16 | — | — | — | +| 128 × 128 | 0 | 2, 0.37, default | U16 | — | — | — | +| 32 × 32 | 113 | 2, 0.37, default | F32 | — | — | — | +| 64 × 64 | 42 | 2, 0.37, default | U8, U16, F16, F32 | U8 | — | — | +| 16 × 16 | 105543 | Defaults | F32 | — | — | — | +| 32 × 32 | 105544 | 1, 0, on | F32 | F32 | — | — | +| 32 × 32 | 105545 | 1, 0.3125, off | U8, U16, F16, F32 | — | — | — | +| 32 × 16 | 105549 | 2, 0.8125, on | F32 | F32 | F32 | F32 | +| 16 × 32 | 105550 | 2, 0.8125, on | U16 | — | U16 | — | +| 64 × 32 | 105551 | 1, 0.3125, off | F32 | — | — | — | +| 32 × 64 | 105552 | 1, 0, on | F16 | — | — | — | +| 16 × 32 | 0 | Defaults | U8, U16, F16, F32 | U16 | — | — | +| 32 × 16 | 42 | 2, 0.21875, on | U16, F32 | — | U16, F32 | — | +| 64 × 64 | 433571 | 1, 0.9375, off | U8, U16, F16, F32 | U8 | — | — | +| 128 × 32 | 433608 | 3, 0.046875, on | U16, F32 | F32 | U16, F32 | F32 | +| 32 × 128 | 433645 | 2, 0.5625, off | U8, U16, F16, F32 | — | — | — | +| 256 × 128 | 433719 | 3, 0.328125, off | U16, F32 | — | U16, F32 | — | +| 128 × 256 | 433756 | 1, 0.8125, on | U16, F32 | U16 | — | — | +| 256 × 256 | 42 | Defaults | U8, U16, F16, F32 | F32 | — | — | +| 512 × 128 | 433830 | 1, 0.671875, on | U16, F32 | — | — | — | +| 16 × 32 | 281667 | Defaults | U16, F32 | — | — | — | +| 64 × 32 | 281734 | 1, 0, on | U8, U16, F16, F32 | U8 | — | — | +| 32 × 64 | 281801 | 2, 0.8125, on | U8, U16, F16, F32 | U16 | U8, U16, F16, F32 | U16 | +| 64 × 64 | 281868 | 2, 0.21875, on | U16, F32 | — | — | — | + +
+ +
+noise_dirt_gradient · settings and saved comparisons + +Use `disorder`, `non_square_expansion` in the listed control order. An omitted control uses the graph default. + +| Size | Seed | Controls | Formats | Reopened | Whole budget reached | Reopen budget reached | +|---|---:|---|---|---|---|---| +| 128 × 128 | 0 | Defaults | U16, U8, F16, F32 | U16, U8 | — | — | +| 256 × 256 | 0 | Defaults | U16 | — | — | — | +| 128 × 128 | 42 | Defaults | U16 | — | — | — | +| 128 × 128 | 0 | 0.37, default | U16 | — | — | — | +| 32 × 32 | 113 | 0.37, default | F32 | — | — | — | +| 64 × 64 | 42 | 0.37, default | U8, U16, F16, F32 | U8 | — | — | +| 16 × 16 | 105577 | Defaults | F32 | — | — | — | +| 32 × 32 | 105578 | 0, on | F32 | F32 | — | — | +| 32 × 32 | 105579 | 0.3125, off | U8, U16, F16, F32 | — | — | — | +| 32 × 16 | 105583 | 0.8125, on | F32 | F32 | — | — | +| 16 × 32 | 105584 | 0.8125, on | U16 | — | — | — | +| 64 × 32 | 105585 | 0.3125, off | F32 | — | — | — | +| 32 × 64 | 105586 | 0, on | F16 | — | — | — | +| 16 × 32 | 0 | Defaults | U8, U16, F16, F32 | U16 | — | — | +| 32 × 16 | 42 | 0.21875, on | U16, F32 | — | — | — | +| 64 × 64 | 433597 | 0.9375, off | U8, U16, F16, F32 | U8 | — | — | +| 128 × 32 | 433634 | 0.046875, on | U16, F32 | F32 | — | — | +| 32 × 128 | 433671 | 0.5625, off | U8, U16, F16, F32 | — | — | — | +| 256 × 128 | 433745 | 0.328125, off | U16, F32 | — | — | — | +| 128 × 256 | 433782 | 0.8125, on | U16, F32 | U16 | — | — | +| 256 × 256 | 42 | Defaults | U8, U16, F16, F32 | F32 | — | — | +| 512 × 128 | 433856 | 0.671875, on | U16, F32 | — | U16, F32 | — | +| 16 × 32 | 281741 | Defaults | U16, F32 | — | — | — | +| 64 × 32 | 281808 | 0, on | U8, U16, F16, F32 | U8 | — | — | +| 32 × 64 | 281875 | 0.8125, on | U8, U16, F16, F32 | U16 | — | — | +| 64 × 64 | 281942 | 0.21875, on | U16, F32 | — | — | — | + +
+ +### Whole renders and reopened settings for two dirt noise generators + +Each generator runs from its own procedural parameters. Compare one- and eight-processor reference captures with the same MaterialCraft release cook at revision `1b73ea6`. Each saved graph went through the SBS writer and was opened in both applications. The counts include every successful cook. The final column in each settings list identifies requests that reached the pattern execution budget. A saved setting in that column reached the same budget after reopening. [Earlier dirt stage measurements](#dirt-noise-sources-and-downstream-stages) + +| Package · comparison | Rendered / attempted | Exact settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:|---:| +| noise_dirt_1 · one processor | 34/60 | 18 | 89,600/89,600 · 0 | 204,788/204,800 · 1 | 91,648/91,648 · 0 | 122,867/126,208 · 1.1920929e-07 | +| noise_dirt_1 · eight processors | 34/60 | 19 | 89,600/89,600 · 0 | 204,789/204,800 · 1 | 91,648/91,648 · 0 | 123,659/126,208 · 1.1920929e-07 | +| noise_dirt_1 · reference one versus eight | 60/60 | 31 | 99,840/99,840 · 0 | 338,923/338,944 · 1 | 101,888/101,888 · 0 | 237,356/244,992 · 1.1920929e-07 | +| noise_dirt_1 · after reopening on one processor | 8/12 | 4 | 22,528/22,528 · 0 | 49,659/49,664 · 1 | — | 64,670/66,560 · 1.1920929e-07 | +| noise_dirt_1 · reference original versus reopened | 12/12 | 10 | 26,624/26,624 · 0 | 51,712/51,712 · 0 | — | 71,084/71,168 · 5.96046448e-08 | +| noise_dirt_1_v2 · one processor | 28/60 | 16 | 167,424/167,424 · 0 | 86,010/86,016 · 1 | 87,551/87,552 · 0.000244140625 | 86,349/89,344 · 2.38418579e-07 | +| noise_dirt_1_v2 · eight processors | 28/60 | 17 | 167,424/167,424 · 0 | 86,010/86,016 · 1 | 87,552/87,552 · 0 | 87,404/89,344 · 1.1920929e-07 | +| noise_dirt_1_v2 · reference one versus eight | 60/60 | 30 | 198,144/198,144 · 0 | 240,606/240,640 · 1 | 101,887/101,888 · 0.000244140625 | 220,063/244,992 · 2.38418579e-07 | +| noise_dirt_1_v2 · after reopening on one processor | 6/12 | 3 | 18,432/18,432 · 0 | 16,895/16,896 · 1 | — | 64,455/66,560 · 2.38418579e-07 | +| noise_dirt_1_v2 · reference original versus reopened | 12/12 | 9 | 26,624/26,624 · 0 | 51,710/51,712 · 1 | — | 71,069/71,168 · 5.96046448e-08 | + +Every successful MaterialCraft reopen reproduced its original raw buffer. Integer maxima are in stored levels. Each float comparison checks the stored bits and reports the maximum absolute difference. + +
+noise_dirt_1 settings + +Controls appear in the order `disorder`, `non_square_expansion`, `scale`. Omitted controls use graph defaults. + +| Size | Seed | Controls | Formats | Reopened | Execution budget reached | +|---|---:|---|---|---|---| +| 128 × 128 | 0 | Defaults | U16, U8, F16, F32 | U16, U8 | — | +| 256 × 256 | 0 | Defaults | U16 | — | — | +| 128 × 128 | 42 | Defaults | U16 | — | — | +| 128 × 128 | 0 | 0.37, default, 2 | U16 | — | U16 | +| 32 × 32 | 113 | 0.37, default, 2 | F32 | — | F32 | +| 64 × 64 | 42 | 0.37, default, 2 | U8, U16, F16, F32 | U8 | U8, U16, F16, F32 | +| 16 × 16 | 105424 | Defaults | F32 | — | — | +| 32 × 32 | 105425 | 0, on, 1 | F32 | F32 | — | +| 32 × 32 | 105426 | 0.3125, off, 1 | U8, U16, F16, F32 | — | — | +| 32 × 16 | 105430 | 0.8125, on, 2 | F32 | F32 | F32 | +| 16 × 32 | 105431 | 0.8125, on, 2 | U16 | — | U16 | +| 64 × 32 | 105432 | 0.3125, off, 1 | F32 | — | — | +| 32 × 64 | 105433 | 0, on, 1 | F16 | — | — | +| 16 × 32 | 0 | Defaults | U8, U16, F16, F32 | U16 | — | +| 32 × 16 | 42 | 0.21875, on, 2 | U16, F32 | — | U16, F32 | +| 64 × 64 | 433480 | 0.9375, off, 1 | U8, U16, F16, F32 | U8 | — | +| 128 × 32 | 433517 | 0.046875, on, 3 | U16, F32 | F32 | U16, F32 | +| 32 × 128 | 433554 | 0.5625, off, 2 | U8, U16, F16, F32 | — | U8, U16, F16, F32 | +| 256 × 128 | 433628 | 0.328125, off, 3 | U16, F32 | — | U16, F32 | +| 128 × 256 | 433665 | 0.8125, on, 1 | U16, F32 | U16 | — | +| 256 × 256 | 42 | Defaults | U8, U16, F16, F32 | F32 | — | +| 512 × 128 | 433739 | 0.671875, on, 1 | U16, F32 | — | U16, F32 | +| 16 × 32 | 299324 | Defaults | U16, F32 | — | — | +| 64 × 32 | 299403 | 0, on, 1 | U8, U16, F16, F32 | U8 | — | +| 32 × 64 | 299482 | 0.8125, on, 2 | U8, U16, F16, F32 | U16 | U8, U16, F16, F32 | +| 64 × 64 | 299561 | 0.21875, on, 2 | U16, F32 | — | U16, F32 | + +
+ +
+noise_dirt_1_v2 settings + +Controls appear in the order `disorder`, `disorder_anisotropy`, `disorder_anisotropy_angle`, `disorder_speed`, `non_square_expansion`, `scale`, `tile_offset`. Omitted controls use graph defaults. + +| Size | Seed | Controls | Formats | Reopened | Execution budget reached | +|---|---:|---|---|---|---| +| 128 × 128 | 0 | Defaults | U8, U16, F16, F32 | U8, U16 | — | +| 256 × 256 | 0 | Defaults | U8 | — | — | +| 128 × 128 | 42 | Defaults | U8 | — | — | +| 128 × 128 | 0 | 0.37, 0.3, 0.125, 0.6, default, 2, (0.17, 0.29) | U8 | — | U8 | +| 32 × 32 | 113 | 0.37, 0.3, 0.125, 0.6, default, 2, (0.17, 0.29) | F32 | — | F32 | +| 64 × 64 | 42 | 0.37, 0.3, 0.125, 0.6, default, 2, (0.17, 0.29) | U8, U16, F16, F32 | U8 | U8, U16, F16, F32 | +| 16 × 16 | 105441 | Defaults | F32 | — | — | +| 32 × 32 | 105442 | 0, 0, 0, 1, on, 1, (0, 0) | F32 | F32 | — | +| 32 × 32 | 105443 | 0.3125, 0.25, 0.3125, 0.6875, off, 1, (0.125, -0.1875) | U8, U16, F16, F32 | — | — | +| 32 × 16 | 105447 | 0.8125, 0.625, -0.21875, 1.4375, on, 2, (-0.3125, 0.4375) | F32 | F32 | F32 | +| 16 × 32 | 105448 | 0.8125, 0.625, -0.21875, 1.4375, on, 2, (-0.3125, 0.4375) | U16 | — | U16 | +| 64 × 32 | 105449 | 0.3125, 0.25, 0.3125, 0.6875, off, 1, (0.125, -0.1875) | F32 | — | — | +| 32 × 64 | 105450 | 0, 0, 0, 1, on, 1, (0, 0) | F16 | — | — | +| 16 × 32 | 0 | Defaults | U8, U16, F16, F32 | U16 | — | +| 32 × 16 | 42 | 0.21875, 0.21875, -0.03125, 0.21875, on, 2, (-0.125, 0.214844) | U16, F32 | — | U16, F32 | +| 64 × 64 | 433493 | 0.9375, 0.9375, 0.6875, 0.9375, off, 1, (0.59375, -0.414062) | U8, U16, F16, F32 | U8 | U8, U16, F16, F32 | +| 128 × 32 | 433530 | 0.046875, 0.046875, -0.203125, 0.046875, on, 3, (-0.296875, 0.365234) | U16, F32 | F32 | U16, F32 | +| 32 × 128 | 433567 | 0.5625, 0.5625, 0.3125, 0.5625, off, 2, (0.21875, -0.0859375) | U8, U16, F16, F32 | — | U8, U16, F16, F32 | +| 256 × 128 | 433641 | 0.328125, 0.328125, 0.078125, 0.328125, off, 3, (-0.015625, 0.119141) | U16, F32 | — | U16, F32 | +| 128 × 256 | 433678 | 0.8125, 0.8125, 0.5625, 0.8125, on, 1, (0.46875, -0.304688) | U16, F32 | U16 | U16, F32 | +| 256 × 256 | 42 | Defaults | U8, U16, F16, F32 | F32 | — | +| 512 × 128 | 433752 | 0.671875, 0.671875, 0.421875, 0.671875, on, 1, (0.328125, -0.181641) | U16, F32 | — | U16, F32 | +| 16 × 32 | 299367 | Defaults | U16, F32 | — | — | +| 64 × 32 | 299446 | 0, 0, 0, 1, on, 1, (0, 0) | U8, U16, F16, F32 | U8 | — | +| 32 × 64 | 299525 | 0.8125, 0.625, -0.21875, 1.4375, on, 2, (-0.3125, 0.4375) | U8, U16, F16, F32 | U16 | U8, U16, F16, F32 | +| 64 × 64 | 299604 | 0.21875, 0.21875, -0.03125, 0.21875, on, 2, (-0.125, 0.214844) | U16, F32 | — | U16, F32 | + +
+ +### Whole outputs and saved settings for Noise Dirt 2 and Noise Dirt 3 + +Each generator runs from its own procedural parameters. Compare one- and eight-processor reference captures with the same MaterialCraft release cook at revision `1b73ea6`. Each saved graph went through the SBS writer and was opened in both applications. The counts include every successful cook. The final column in each settings list identifies requests that reached the pattern execution budget. A saved setting in that column reached the same budget after reopening. [Earlier dirt stage measurements](#dirt-noise-sources-and-downstream-stages) + +| Package · comparison | Rendered / attempted | Exact settings | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:|---:|---:| +| noise_dirt_2 · one processor | 34/60 | 27 | 89,600/89,600 · 0 | 204,794/204,800 · 2 | 91,647/91,648 · 6.10351562e-05 | 126,206/126,208 · 2.52053142e-05 | +| noise_dirt_2 · eight processors | 34/60 | 30 | 89,600/89,600 · 0 | 204,797/204,800 · 2 | 91,647/91,648 · 0.000122070312 | 126,207/126,208 · 2.51978636e-05 | +| noise_dirt_2 · reference one versus eight | 60/60 | 46 | 99,840/99,840 · 0 | 338,931/338,944 · 2 | 101,886/101,888 · 0.000122070312 | 244,986/244,992 · 2.52090394e-05 | +| noise_dirt_2 · after reopening on one processor | 8/12 | 6 | 22,528/22,528 · 0 | 49,663/49,664 · 2 | — | 66,559/66,560 · 2.52053142e-05 | +| noise_dirt_2 · reference original versus reopened | 12/12 | 12 | 26,624/26,624 · 0 | 51,712/51,712 · 0 | — | 71,168/71,168 · 0 | +| noise_dirt_3 · one processor | 58/60 | 35 | 99,840/99,840 · 0 | 334,838/334,848 · 1 | 101,888/101,888 · 0 | 239,325/240,896 · 1.52587891e-05 | +| noise_dirt_3 · eight processors | 58/60 | 36 | 99,840/99,840 · 0 | 334,843/334,848 · 1 | 101,888/101,888 · 0 | 239,368/240,896 · 1.52587891e-05 | +| noise_dirt_3 · reference one versus eight | 60/60 | 38 | 99,840/99,840 · 0 | 338,935/338,944 · 1 | 101,888/101,888 · 0 | 243,043/244,992 · 1.1920929e-07 | +| noise_dirt_3 · after reopening on one processor | 11/12 | 7 | 26,624/26,624 · 0 | 51,705/51,712 · 1 | — | 66,682/67,072 · 5.96046448e-08 | +| noise_dirt_3 · reference original versus reopened | 12/12 | 11 | 26,624/26,624 · 0 | 51,712/51,712 · 0 | — | 71,158/71,168 · 2.98023224e-08 | + +Every successful MaterialCraft reopen reproduced its original raw buffer. Integer maxima are in stored levels. Each float comparison checks the stored bits and reports the maximum absolute difference. + +
+noise_dirt_2 settings + +Controls appear in the order `disorder`, `non_square_expansion`, `scale`. Omitted controls use graph defaults. + +| Size | Seed | Controls | Formats | Reopened | Execution budget reached | +|---|---:|---|---|---|---| +| 128 × 128 | 0 | Defaults | U16, U8, F16, F32 | U16, U8 | — | +| 256 × 256 | 0 | Defaults | U16 | — | — | +| 128 × 128 | 42 | Defaults | U16 | — | — | +| 128 × 128 | 0 | 0.37, default, 2 | U16 | — | U16 | +| 32 × 32 | 113 | 0.37, default, 2 | F32 | — | F32 | +| 64 × 64 | 42 | 0.37, default, 2 | U8, U16, F16, F32 | U8 | U8, U16, F16, F32 | +| 16 × 16 | 105458 | Defaults | F32 | — | — | +| 32 × 32 | 105459 | 0, on, 1 | F32 | F32 | — | +| 32 × 32 | 105460 | 0.3125, off, 1 | U8, U16, F16, F32 | — | — | +| 32 × 16 | 105464 | 0.8125, on, 2 | F32 | F32 | F32 | +| 16 × 32 | 105465 | 0.8125, on, 2 | U16 | — | U16 | +| 64 × 32 | 105466 | 0.3125, off, 1 | F32 | — | — | +| 32 × 64 | 105467 | 0, on, 1 | F16 | — | — | +| 16 × 32 | 0 | Defaults | U8, U16, F16, F32 | U16 | — | +| 32 × 16 | 42 | 0.21875, on, 2 | U16, F32 | — | U16, F32 | +| 64 × 64 | 433506 | 0.9375, off, 1 | U8, U16, F16, F32 | U8 | — | +| 128 × 32 | 433543 | 0.046875, on, 3 | U16, F32 | F32 | U16, F32 | +| 32 × 128 | 433580 | 0.5625, off, 2 | U8, U16, F16, F32 | — | U8, U16, F16, F32 | +| 256 × 128 | 433654 | 0.328125, off, 3 | U16, F32 | — | U16, F32 | +| 128 × 256 | 433691 | 0.8125, on, 1 | U16, F32 | U16 | — | +| 256 × 256 | 42 | Defaults | U8, U16, F16, F32 | F32 | — | +| 512 × 128 | 433765 | 0.671875, on, 1 | U16, F32 | — | U16, F32 | +| 16 × 32 | 299410 | Defaults | U16, F32 | — | — | +| 64 × 32 | 299489 | 0, on, 1 | U8, U16, F16, F32 | U8 | — | +| 32 × 64 | 299568 | 0.8125, on, 2 | U8, U16, F16, F32 | U16 | U8, U16, F16, F32 | +| 64 × 64 | 299647 | 0.21875, on, 2 | U16, F32 | — | U16, F32 | + +
+ +
+noise_dirt_3 settings + +Controls appear in the order `disorder`, `non_square_expansion`, `scale`. Omitted controls use graph defaults. + +| Size | Seed | Controls | Formats | Reopened | Execution budget reached | +|---|---:|---|---|---|---| +| 128 × 128 | 0 | Defaults | U16, U8, F16, F32 | U16, U8 | — | +| 256 × 256 | 0 | Defaults | U16 | — | — | +| 128 × 128 | 42 | Defaults | U16 | — | — | +| 128 × 128 | 0 | 0.37, default, 2 | U16 | — | — | +| 32 × 32 | 113 | 0.37, default, 2 | F32 | — | — | +| 64 × 64 | 42 | 0.37, default, 2 | U8, U16, F16, F32 | U8 | — | +| 16 × 16 | 105475 | Defaults | F32 | — | — | +| 32 × 32 | 105476 | 0, on, 1 | F32 | F32 | — | +| 32 × 32 | 105477 | 0.3125, off, 1 | U8, U16, F16, F32 | — | — | +| 32 × 16 | 105481 | 0.8125, on, 2 | F32 | F32 | — | +| 16 × 32 | 105482 | 0.8125, on, 2 | U16 | — | — | +| 64 × 32 | 105483 | 0.3125, off, 1 | F32 | — | — | +| 32 × 64 | 105484 | 0, on, 1 | F16 | — | — | +| 16 × 32 | 0 | Defaults | U8, U16, F16, F32 | U16 | — | +| 32 × 16 | 42 | 0.21875, on, 2 | U16, F32 | — | — | +| 64 × 64 | 433519 | 0.9375, off, 1 | U8, U16, F16, F32 | U8 | — | +| 128 × 32 | 433556 | 0.046875, on, 3 | U16, F32 | F32 | U16, F32 | +| 32 × 128 | 433593 | 0.5625, off, 2 | U8, U16, F16, F32 | — | — | +| 256 × 128 | 433667 | 0.328125, off, 3 | U16, F32 | — | — | +| 128 × 256 | 433704 | 0.8125, on, 1 | U16, F32 | U16 | — | +| 256 × 256 | 42 | Defaults | U8, U16, F16, F32 | F32 | — | +| 512 × 128 | 433778 | 0.671875, on, 1 | U16, F32 | — | — | +| 16 × 32 | 299453 | Defaults | U16, F32 | — | — | +| 64 × 32 | 299532 | 0, on, 1 | U8, U16, F16, F32 | U8 | — | +| 32 × 64 | 299611 | 0.8125, on, 2 | U8, U16, F16, F32 | U16 | — | +| 64 × 64 | 299690 | 0.21875, on, 2 | U16, F32 | — | — | + +
+ +### Dirt noise sources and downstream stages + +The eleven dirt-noise roots produced **116/209 comparable whole outputs** and **1,045,373/1,067,264 exact pixels**. MaterialCraft reached its pattern execution limit in 93 cases, including every whole-graph case for both Dirt 4 packages. The counts below exclude replacement images emitted after a cook error. Integer errors are storage levels. + +| Root package | Whole outputs compared / attempted | Exact pixels / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---| +| noise_dirt_1 | 11/19 | 104,064/107,776 | 0 / 538 / 0.00048828125 / 0.000222146511 | +| noise_dirt_1_v2 | 11/19 | 107,082/107,776 | 1 / 14 / 0.00048828125 / 0.000208899379 | +| noise_dirt_2 | 11/19 | 107,184/107,776 | 0 / 21 / 0.00048828125 / 0.000252112746 | +| noise_dirt_3 | 19/19 | 135,236/142,592 | 1 / 3 / 0.000244140625 / 3.39820981e-05 | +| noise_dirt_3_v2 | 17/19 | 136,738/141,568 | 1 / 2 / 0.000244140625 / 2.52574682e-05 | +| noise_dirt_4 | 0/19 | No comparable image | — / — / — / — | +| noise_dirt_4_v2 | 0/19 | No comparable image | — / — / — / — | +| noise_dirt_5 | 11/19 | 107,751/107,776 | 0 / 4 / 0 / 5.08278608e-05 | +| noise_dirt_5_v2 | 11/19 | 107,341/107,776 | 0 / 0 / 0 / 5.96046448e-08 | +| noise_dirt_gradient | 19/19 | 141,554/142,592 | 0 / 1 / 0.000244140625 / 1.52587891e-05 | +| noise_dirt_gradient_v2 | 6/19 | 98,423/101,632 | 10 / — / 0.16015625 / 0.027451098 | + +Use the four archived size, seed and parameter cases and the [four-format sweep and independent seed](#four-format-inventory-comparison). Add ten renders at sizes 16², 32², 32², 32², 32², 32², 32×16, 16×32, 64×32 and 32×64, in F32, F32, U8, U16, F16, F32, F32, U16, F32 and F16 respectively. Use defaults, A, B, B, B, B, C, C, B and A. Seed each graph at 100987+17i plus [0,1,2,2,2,2,6,7,8,9], with i from 261 through 271 in table order. Apply each setting where the root exposes it. + +| Controls | A | B | C | +|---|---|---|---| +| Scale, disorder, nonsquare expansion | 1, 0, on | 1, .3125, off | 2, .8125, on | +| Disorder speed, anisotropy, anisotropy angle, tile offset | 1, 0, 0, (0,0) | .6875, .25, .3125, (.125,−.1875) | 1.4375, .625, −.21875, (−.3125,.4375) | + +For each of 20 pattern stages, retain the shortest connected path to an authored drawing quadrant, breaking ties by connection identifier. Clear the stage inputs. Render its authored shape, then a square and a disc, with all other properties preserved. Use the ten-case sequence above except the 64×32 case. The square and disc each match **115,032/115,032** with zero maximum error in 180 renders. The authored paths match 111,112/115,032. Of those 180 renders per shape, 97 authored renders, 102 square renders and 101 disc renders contained at least one nonzero pixel. + +| Root package | Reached shape numbers | Authored path exact / compared | Maximum U8 / U16 / F16 / F32 error | Exact pixels per hard shape | +|---|---|---:|---|---:| +| noise_dirt_1 | 1,4 | 16,416/17,664 | 0 / 0 / 0 / 3.57627869e-07 | 17,664 | +| noise_dirt_1_v2 | 1,4 | 16,416/17,664 | 0 / 0 / 0 / 3.57627869e-07 | 17,664 | +| noise_dirt_2 | 1,4 | 16,416/17,664 | 0 / 0 / 0 / 3.57627869e-07 | 17,664 | +| noise_dirt_3 | 4,16 | 10,560/10,560 | 0 / 0 / 0 / 0 | 10,560 | +| noise_dirt_3_v2 | 4,16 | 10,560/10,560 | 0 / 0 / 0 / 0 | 10,560 | +| noise_dirt_4 | 8 | 2,071/2,112 | 0 / 0 / 0 / 7.15255737e-07 | 2,112 | +| noise_dirt_4_v2 | 8 | 2,088/2,112 | 0 / 1 / 0 / 7.74860382e-07 | 2,112 | +| noise_dirt_5 | 3 | 8,448/8,448 | 0 / 0 / 0 / 0 | 8,448 | +| noise_dirt_5_v2 | 3 | 8,448/8,448 | 0 / 0 / 0 / 0 | 8,448 | +| noise_dirt_gradient | 6 | 9,059/9,108 | 0 / 0 / 0 / 5.21540642e-08 | 9,108 | +| noise_dirt_gradient_v2 | 6 | 10,630/10,692 | 0 / 0 / 0 / 3.7252903e-08 | 10,692 | + +Supply identical original fields to the downstream graph by replacing its source pattern stages with image inputs. The second substitution retains the final pattern and supplies its immediate source patterns. Use the same ten settings and the native source stage's width, height and storage in each case. For input index a starting at zero, use constant 8199(a+1) in the default case. For A at 32² place 59003−49a on (x+2a) mod width = y mod width and 302+69a elsewhere. For C use 32769+a where (7x+13y+3a) mod 11 is zero and 32767+a elsewhere. For the other cases use ((11x+31y+7xy+93+47a+(a+1)x)×7919) mod 65536. Use the integer field directly for U16, its quotient by 257 rounded down for U8, and its value divided by 65535 for floating storage. + +| Root package | Replaced stages | Outputs compared / attempted | Exact pixels / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---|---:|---:|---| +| noise_dirt_1 | Source stages | 8/10 | 8,735/9,472 | 1 / 48 / 0.000915527344 / 0.000764921308 | +| noise_dirt_1 | Inputs of final pattern | 8/10 | 8,740/9,472 | 1 / 48 / 0.000915527344 / 0.000764921308 | +| noise_dirt_1_v2 | Source stages | 8/10 | 8,207/9,472 | 1 / 47 / 0.00317382812 / 0.000719666481 | +| noise_dirt_1_v2 | Inputs of final pattern | 8/10 | 8,220/9,472 | 1 / 47 / 0.00317382812 / 0.000719666481 | +| noise_dirt_2 | Source stages | 8/10 | 9,420/9,472 | 0 / 38 / 0.00105667114 / 0.000882223248 | +| noise_dirt_2 | Inputs of final pattern | 8/10 | 9,420/9,472 | 0 / 38 / 0.00105667114 / 0.000882223248 | +| noise_dirt_3 | Source stages | 10/10 | 9,438/10,496 | 0 / 3 / 0.00048828125 / 2.8192997e-05 | +| noise_dirt_3 | Inputs of final pattern | 10/10 | 9,444/10,496 | 0 / 3 / 0.00048828125 / 2.8192997e-05 | +| noise_dirt_3_v2 | Source stages | 8/10 | 8,722/9,472 | 0 / 0 / 0.00048828125 / 2.68220901e-07 | +| noise_dirt_3_v2 | Inputs of final pattern | 8/10 | 8,730/9,472 | 0 / 0 / 0.00048828125 / 2.68220901e-07 | +| noise_dirt_4 | Source stages | 10/10 | 3,097/10,496 | 1 / 3 / 0.349609375 / 0.349553674 | +| noise_dirt_4_v2 | Source stages | 10/10 | 1,902/10,496 | 4 / 3 / 0.352294922 / 0.352193475 | +| noise_dirt_5 | Source stages | 10/10 | 10,496/10,496 | 0 / 0 / 0 / 0 | +| noise_dirt_gradient | Source stages | 10/10 | 10,496/10,496 | 0 / 0 / 0 / 0 | +| noise_dirt_gradient_v2 | Source stages | 3/10 | 1,617/3,328 | — / — / 0.122558594 / 0.0274509192 | +| noise_dirt_gradient_v2 | Inputs of final pattern | 3/10 | 2,167/3,328 | — / — / 0 / 9.53674316e-07 | + +### Partly wrapped copies in Directional Noise 1 + +The third pattern stage draws at depths six through eight. Sixty-four consecutive depth-six parents normally emit 1,344 squares or Gaussian stamps. When each such group emits fewer than 1,365 physical copies, complete subtrees keep their measured boundaries. Interior runs finish on a multiple of 5,460 submitted copies, including copies that miss every pixel. A boundary can fall within a stamp. Across six Gaussian windows the F32 results improved from 4,544/6,144 (maximum 1.78813934e-07) to **6,144/6,144 (maximum 0)**. Ten windows with more copies match 10,021/14,336 (maximum 1.78813934e-07). The whole graph remains at 734,118/734,464 pixels on one processor and 734,140/734,464 on eight. All 12 local saved outputs reproduce their originals and match 123,081/123,136 pixels across applications. [Whole-graph settings and maxima by stored format](#final-three-quadrant-levels-in-directional-noise-1) + +Use the connected stage and its original iteration and switch. Compare 16 × 32, seed 194860 at defaults, and 32 × 64, seed 194954 with scale 1, disorder .1875, angle −.0625, angle random .1875 and nonsquare expansion on. Enable horizontal wrapping and set both windows to (−E, 1+E, 0, 1). In order, use E = .2734375, .201171875, .177734375, .150390625, .154296875, .140625, .11328125 and .0546875. Both sizes match at the first and third widths, and the smaller size also matches at the second and fourth. Repeat the first and third widths in all four formats and the fifth in F32. For each width, save every third setting starting at zero, with the smaller image first and formats in table order. Every reference reopen repeats its original buffer. + +| Stage comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| 18 originals, one processor | 5,120/5,120 · 0 | 5,120/5,120 · 0 | 5,120/5,120 · 0 | 6,937/7,680 · 1.78813934e-07 | +| 18 originals, eight processors | 5,120/5,120 · 0 | 5,117/5,120 · 1 | 5,120/5,120 · 0 | 5,638/7,680 · 1.1920929e-07 | +| Reference one versus eight processors | 5,120/5,120 · 0 | 5,117/5,120 · 1 | 5,120/5,120 · 0 | 5,519/7,680 · 1.1920929e-07 | +| Seven reopens, one processor | 1,024/1,024 · 0 | — | 4,096/4,096 · 0 | 1,375/1,536 · 1.78813934e-07 | + +For an independent ordering test, use one, two and four complete trees on a white 128² F32 image. At the start of each 64-parent group g, wrap 1 + ((7g+3) modulo L) consecutive squares horizontally, with L equal to 5, 14 and 19 respectively. Use seed 275377 + 41 times the tree count. Move two squares to each of 16 pixels, assign gains −1 and 2⁻²⁵, and repeat with the gains exchanged. All 96 pair comparisons agree. The six full buffers improved from 98,208/98,304 (maximum 2.98023224e-08) to 98,304/98,304 (maximum 0). The normal-cook regression failed on the previous implementation. [Square positions and expected order](../crates/nodes/src/pattern/tests/terminal_quadrants.rs) + +On a white 128 × 64 field, sample pixel centers and select gains from .125, −.03125, 1, 2⁻²⁵, .078125, .005859375, .00008777529 and .24066773. Use a PCG64 generator to draw all columns, then rows, then gain indices. Use squares .75 pixels on each axis. Move selected centers to the seam of the wrapping axis or axes. For one, two and four trees, choose 1, (3g+1) modulo 4, 6 or 7 such centers per group without replacement, using seed 278179 + 37 times the zero-based choice + 23 times the tree count, with 1 added for two axes. The 21 vertical and two-axis cases within the measured capacity match 172,032/172,032 (maximum 0). Seven four-copy stamps per group exceed that capacity. The three corresponding fields match 20,801/24,576 (maximum 2.86102295e-06). + +For the horizontal field use two and four trees, seed 271153 + 53j + 17 times the tree count, with j equal to 0, 1, 4, 7, 8, 10, 12, 14, 15, 16, 17, 18, 19 and 22. At j = 0, 1 and 4 wrap no stamp, the first stamp and stamp 32,256 respectively. At 7 use draws 337–340, the midpoint, the midpoint + 336, the fourth-last draw and the last draw. At j = 8 through 19 choose 1, 2, 4, 6, 8, 10, 12, 15, 18, 20, 21 or 24 stamps per group without replacement. At 22 draw the quota uniformly from 0 through 79. The 22 fields within capacity match 178,846/180,224 (maximum 1.90734863e-06). The six outside match 40,376/49,152 (maximum 1.90734863e-06). In two qualifying fields the first reference buffer differs from three successive recaptures on the same processor. All 8 qualifying fields selected for recapture match 65,536/65,536 (maximum 0) on each of the three repeats. All 452 node and evaluator release tests, formatting, strict workspace Clippy, crate layers and WebAssembly passed. + +### Terminal quadrant order across sampling windows + +For the last three additive levels in a complete depth-eight tree, the same submission order applies if each visited stamp emits exactly one physical copy. Count copies from the actual render and tiling windows and the rotated stamp footprint before discarding draws outside sampled pixels. Eleven F32 stage renders improve from **19,534/27,136** (maximum 2.98023224e-07) to **27,136/27,136** (zero). Seven renders that generate additional copies give 7,286/14,336 (maximum 2.98023224e-07). Those cases still need different submission boundaries. The 60 whole Directional Noise 1 settings and 12 saved settings retain the counts in the earlier table. [Whole settings, controls and per-format results](#final-three-quadrant-levels-in-directional-noise-1) + +Use the original directional graph's third pattern stage with the iteration count fixed at two and its repeated branch active. Compare 64², seed 42, scale 2, disorder .37, angle .125 and angle random .2, and 16 × 32, seed 194860 at defaults. Measure both in each of nine configurations. Start with the graph's original windows and tiling. Disable wrapping for the second configuration. For the third, also set the tiling window to the unit square. For the fourth, disable wrapping and set only the render window to the unit square. For the fifth, render (.1,.8,.2,.65) with a unit tiling window and wrapping off. For the sixth, render (−.2,.46,.05,.83) in the tiling window (.1,.9,−.3,1.2), wrapping off. Finally use unit windows with horizontal, vertical and two-axis wrapping. Coordinates are left, right, top, bottom. + +As an independent control, use the earlier 16 pairs for one, two and four trees at 128², then change the tiling window to (−.5,1.5,−.5,1.5) with no wrapping, horizontal wrapping and both axes respectively. Both gain assignments in both sets of three windows give 196,608/196,608 F32 pixels (maximum zero). Both new normal-cook regressions failed before the fixes. The node and evaluator release suites passed all 450 tests, together with formatting, strict workspace Clippy, crate layers and the WebAssembly checks. [Signed square regression](../crates/nodes/src/pattern/tests/terminal_quadrants.rs) + +### Final three quadrant levels in Directional Noise 1 + +The third pattern stage is the first differing stage in this directional generator. Its two earlier pattern stages and their first blend match all 16,896 pixels each in eight settings. At the third stage the original window and tiling give 16,884/16,896 U16 pixels (maximum 1) and 10,505/16,896 F32 pixels (maximum 1.78813934e-07). The root remains in progress. [Earlier root measurements](#directional-noise-and-scratch-pattern-sources) + +With unit render and tiling windows, wrapping disabled, and a single additive shape drawn at depths six through eight, each depth-six parent supplies 21 draws. A complete depth-eight tree has 4,096 such parents. One, two and four active trees submit 35, 68 and 139 contiguous parent ranges respectively. The boundaries refer to every visited draw, including squares that miss all pixel centers. For 21 F32 stage renders, using the measured order improves **27,536/46,080 · 4.76837158e-07** to **46,080/46,080 · 0**. This covers a direct tree, a forced one-, two- or four-iteration tree and the graph's own iteration switch. The latter also selects 18 trees in one of the original window settings. + +To measure the order independently, connect all four children at every subdivision through depth eight. Use additive squares at the last three levels, size 0.875, zero roughness, a white F32 background and one processor. Put pale squares at the same distant point with weight 0.25. For each numbered pair move both centers to the same pixel and assign −1 and 2⁻²⁵. A surviving 2⁻²⁵ identifies which square drew first. Repeat with the gains exchanged. Horizontal and vertical strips allow multiple comparisons per image. Bisect parent indices around changes in the observed ordering. Sixteen independent pairs at each tree count, repeated with both gain assignments, agreed in all 96 comparisons. The normal cook regression failed before the correction. [Signed square fixture](../crates/nodes/src/pattern/tests/terminal_quadrants.rs) + +| Comparison | U8 exact / total · max | U16 exact / total · max | F16 exact / total · max | F32 exact / total · max | +|---|---:|---:|---:|---:| +| Whole graph, 60 settings, one processor | 88,319/88,320 · 1 | 300,641/300,800 · 1 | 90,367/90,368 · 0.000244140625 | 254,791/254,976 · 1.14738941e-05 | +| Whole graph, 60 settings, eight processors | 88,319/88,320 · 1 | 300,639/300,800 · 1 | 90,366/90,368 · 0.000244140625 | 254,816/254,976 · 1.14738941e-05 | +| Same reference renders, one versus eight | 88,318/88,320 · 1 | 300,652/300,800 · 1 | 90,367/90,368 · 0.000244140625 | 254,783/254,976 · 1.14440918e-05 | +| Whole graph, 12 saved settings, one processor | 14,336/14,336 · 0 | 22,769/22,784 · 1 | 1,024/1,024 · 0 | 84,952/84,992 · 1.14440918e-05 | +| Reference original versus saved whole graph | 14,336/14,336 · 0 | 22,784/22,784 · 0 | 1,024/1,024 · 0 | 84,992/84,992 · 0 | +| Isolated stage, 24 new settings, one processor | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 20,480/20,480 · 0 | +| Isolated stage, 24 new settings, eight processors | 2,048/2,048 · 0 | 2,044/2,048 · 1 | 2,048/2,048 · 0 | 11,044/20,480 · 3.57627869e-07 | +| Isolated stage, 12 saved settings, one processor | — | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | + +For the 24 new stage settings, use the direct tree, two forced iterations, four forced iterations and the original switch. In each configuration use the following width, height, seed, scale, angle, angle random, disorder and nonsquare expansion. At 16 × 32 use 260153, 2, 0.09375, 0.125, 0.3125, off. At 32 × 16 use 260171, 1, −0.046875, 0.21875, 0.5625, on. At 64 × 64 use 260183, 2, 0.15625, 0.09375, 0.28125, off. Use F32 everywhere and all four formats at 32 × 16. Save in MaterialCraft and reopen in both applications for the first F32 and the middle U16 and F16 cases. + +All 60 original whole-graph buffers and all 12 reopened buffers retain their previous MaterialCraft pixels. Reproduce the whole settings below using the same grayscale output and defaults for omitted controls. Integer errors are stored levels. The full root still differs in its original sampling windows. + +
+Whole-graph controls and stored formats + +| Size | Seed | Scale, disorder, angle, angle random, expand nonsquare | Formats | Reopened | +|---|---:|---|---|---| +| 128 × 128 | 0 | Defaults | U16 | U16 | +| 256 × 256 | 0 | Defaults | U16, U8, F16, F32 | — | +| 128 × 128 | 42 | Defaults | U16 | — | +| 128 × 128 | 0 | 2, 0.37, 0.125, 0.2, default | U16 | — | +| 32 × 32 | 113 | 2, 0.37, 0.125, 0.2, default | F32 | — | +| 64 × 64 | 42 | 2, 0.37, 0.125, 0.2, default | U8, U16, F16, F32 | U8 | +| 16 × 16 | 103800 | Defaults | F32 | — | +| 32 × 32 | 103801 | 1, 0, 0, 0, on | F32 | F32 | +| 32 × 32 | 103802 | 1, 0.3125, 0.15625, 0.21875, off | U8, U16, F16, F32 | — | +| 64 × 32 | 103806 | 2, 0.6875, -0.21875, 0.40625, on | F32 | F32 | +| 32 × 64 | 103807 | 1, 0.3125, 0.15625, 0.21875, off | U16 | — | +| 32 × 32 | 103808 | 3, 0.125, 0.375, 0.03125, off | F32 | — | +| 64 × 32 | 103809 | 1, 0, 0, 0, on | F16 | — | +| 16 × 16 | 0 | Defaults | U8, U16, F16, F32 | U16 | +| 64 × 16 | 42 | 2, 0.03125, -0.21875, 0.03125, on | U8, U16, F16, F32 | F16 | +| 16 × 64 | 411608 | 1, 0.875, 0.625, 0.875, off | U16, F32 | — | +| 64 × 64 | 411669 | 3, 0.34375, 0.09375, 0.34375, on | U8, U16, F16, F32 | U16 | +| 128 × 64 | 411730 | 2, 0.96875, 0.71875, 0.96875, off | U16, F32 | — | +| 64 × 128 | 411791 | 1, 0.1875, -0.0625, 0.1875, on | U8, U16, F16, F32 | U8 | +| 128 × 128 | 411852 | 3, 0.65625, 0.40625, 0.65625, off | U16, F32 | F32 | +| 128 × 512 | 411974 | 2, 0.53125, 0.28125, 0.53125, off | U16, F32 | F32 | +| 512 × 128 | 412035 | 1, 0.09375, -0.15625, 0.09375, on | U16, F32 | — | +| 16 × 32 | 194860 | Defaults | U16, F32 | — | +| 64 × 32 | 194907 | 3, 0.34375, 0.09375, 0.34375, on | U8, U16, F16, F32 | U8 | +| 32 × 64 | 194954 | 1, 0.1875, -0.0625, 0.1875, on | U8, U16, F16, F32 | U16 | +| 64 × 64 | 195001 | 2, 0.53125, 0.28125, 0.53125, off | U16, F32 | — | + +
+ +### Directional noise and scratch pattern sources + +The ten directional generators produced **135 comparable whole outputs across 190 cases**. The reference produced all 190. The other 55 local evaluations reached the pattern execution limit. Integer errors below are stored levels. A missing error value indicates an unavailable image. + +| Root package | Whole outputs compared / attempted | Exact pixels / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---| +| noise_directional_noise_1 | 19/19 | 136,222/144,640 | 1 / 2 / 0.00048828125 / 4.19616699e-05 | +| noise_directional_noise_1_v2 | 18/19 | 133,251/142,592 | 1 / 1 / 0.00048828125 / 4.15444374e-05 | +| noise_directional_noise_2 | 11/19 | 103,497/107,776 | 0 / 4 / 0.00048828125 / 1.06692314e-05 | +| noise_directional_noise_2_v2 | 11/19 | 105,116/107,776 | 1 / 1 / 0.000244140625 / 1.57654285e-05 | +| noise_directional_noise_3 | 0/19 | No comparable image | — / — / — / — | +| noise_directional_noise_3_v2 | 0/19 | No comparable image | — / — / — / — | +| noise_directional_noise_4 | 19/19 | 134,015/144,640 | 0 / 1 / 0.00048828125 / 6.67572021e-06 | +| noise_directional_noise_4_v2 | 19/19 | 134,664/144,640 | 1 / 1 / 0.00048828125 / 4.76837158e-06 | +| noise_directional_scratches | 19/19 | 119,970/144,640 | 1 / 1 / 0.00048828125 / 2.37524509e-05 | +| noise_directional_scratches_v2 | 19/19 | 137,786/144,640 | 1 / 1 / 0.000244140625 / 2.8796494e-05 | + +Use the four archived defaults, seed and changed cases, the [four-format sweep and independent seed](#four-format-inventory-comparison), and ten renders with intermediate graph outputs recorded. For the latter, seed j is 100537+13i plus [0,1,2,2,2,2,6,7,8,9], with i = 251 through 260 in table order. Start at 16² F32 with defaults. Use A at 32² F32, B at 32² in U8/U16/F16/F32, C at 64×32 F32, B at 32×64 U16, D at 32² F32 and A at 64×32 F16. + +| Exposed controls | A | B | C | D | +|---|---|---|---|---| +| Scale, disorder, expand nonsquare, angle, angle random | 1, 0, on, 0, 0 | 1, .3125, off, .15625, .21875 | 2, .6875, on, −.21875, .40625 | 3, .125, off, .375, .03125 | +| v2 speed, anisotropy, anisotropy angle, tile offset | 1, 0, 0, (0,0) | .6875, .25, .3125, (.125,−.1875) | 1.4375, .625, −.21875, (−.3125,.4375) | .875, .125, .15625, (−.0625,.125) | +| Scratch amount, size, size random | 1, (.5,20), (0,0) | .5625, (.6875,3.25), (.0625,.21875) | .8125, (1.25,7.5), (.15625,.3125) | .375, (.375,1.75), (.03125,.09375) | + +For each of the 19 source stages, isolate the shortest connected path to a drawing quadrant, retain its original controls and clear the stage background. Repeat for a square and disc, skipping the 32² D case. All **146,520/146,520 square pixels** and **146,520/146,520 disc pixels** match across 171 renders per shape. The authored wave and directional profiles retain differences on these same paths. + +| Root package | Authored shape number | Exact square or disc pixels per shape | Authored profile exact / compared | Maximum U8 / U16 / F16 / F32 profile error | +|---|---:|---:|---:|---| +| noise_directional_noise_1 | 11 | 34,560 | 30,657/34,560 | 0 / 1 / 3.05175781e-05 / 2.33855098e-06 | +| noise_directional_noise_1_v2 | 11 | 15,120 | 14,847/15,120 | 0 / 1 / 5.96046448e-08 / 4.270114e-07 | +| noise_directional_noise_2 | 11 | 11,520 | 7,926/11,520 | 0 / 1 / 6.10351562e-05 / 1.34110451e-06 | +| noise_directional_noise_2_v2 | 11 | 14,400 | 13,476/14,400 | 0 / 1 / 1.52587891e-05 / 9.83476639e-07 | +| noise_directional_noise_3 | 11 | 12,420 | 12,336/12,420 | 0 / 0 / 1.90734863e-06 / 1.1920929e-07 | +| noise_directional_noise_3_v2 | 11 | 12,420 | 12,345/12,420 | 0 / 0 / 0 / 2.51457095e-07 | +| noise_directional_noise_4 | 6 | 11,520 | 11,485/11,520 | 0 / 0 / 0 / 8.34465027e-07 | +| noise_directional_noise_4_v2 | 6 | 11,520 | 11,462/11,520 | 0 / 0 / 0 / 4.76837158e-07 | +| noise_directional_scratches | 16 | 11,520 | 11,515/11,520 | 0 / 0 / 0 / 1.51991844e-06 | +| noise_directional_scratches_v2 | 16 | 11,520 | 11,479/11,520 | 0 / 0 / 0 / 3.03983688e-06 | + +At 32² and scale one, noise_directional_noise_3 completes its 4² and 8² sources before its 32² source reaches the traversal limit. Replace all three source generators with the [original grayscale fields](#bnw-spots-3-and-cells-1-pattern-sources) at each source's measured size and precision. The remaining two blends and Levels match 12,544/12,544 pixels over the ten new cases, maximum zero. The same substitution in noise_directional_noise_1 also matches 12,544/12,544. In noise_directional_noise_1_v2, retaining the two later generators or just the terminal generator gives 7,067/10,496 and 7,001/10,496 pixels respectively. Each substitution reaches the execution limit at 64×32, scale two. The respective F32 maxima are .0000418424606 and .0000414848328. Both have maxima of zero U8, one U16 level and .00048828125 F16. + +For the final-pattern input substitution in noise_directional_noise_2_v2, 6,832/9,472 pixels match, with maximum U8 / U16 / F16 / F32 errors 0 / 1 / 0.00048828125 / 1.56760216e-05. In noise_directional_noise_3_v2 both substitutions reached the execution limit in all ten runs. + +### Pattern expression variables and cook time + +Pattern expressions now read inherited graph variables from the active context. Each expression stores its local writes and passes explicit assignments to the next expression. A general evaluation still returns the complete variable environment. In two release runs in opposite order, raw outputs matched between builds on all five successful controls, **17,024/17,024 captured pixels per run**, maximum error zero. A sixth control reached the same execution limit and produced the same intermediate data. The independent reference comparisons on 19 previously verified roots matched 3,211,776/3,211,776 pixels in 159 renders. + +| Six-case release batch, one worker | Previous cook time | Revised cook time | Previous process CPU time | Revised process CPU time | +|---|---:|---:|---:|---:| +| Previous build followed by revised build | 133.28 s | 43.59 s | 145.86 s | 62.12 s | +| Revised build followed by previous build | 127.98 s | 42.96 s | 147.44 s | 62.53 s | + +Use the [Dirt 1 disc stage](#overlapping-disc-additions-in-dirt-1) at 64²/seed 42/disorder .4, 32²/100189/.15625 and 64²/43/.4, in F32. Then run the two [BNW Spots 3](#bnw-spots-3-and-cells-1-pattern-sources) scale-one controls at 32² F32, and the first spots root at scale three and 32² U8. Use a fresh session for each case and the same processor affinity for both release binaries. Cook time is the sum reported by the six graph evaluations. Process CPU time also includes loading the node library, configuring the cases and capturing the images. + +### Gaussian pattern sources and repeat limits + +At commit `793e0b7`, each root received 21 reference renders. The first table gives exact pixels / compared pixels / maximum error in each stored format. Integer errors are stored levels. The two Spots packages with a scale control exceeded the local traversal limit in two cases each. Their pixel denominators include the 19 cases that emitted comparable images. The reference app completed all four of the omitted renders. + +| Package root | Whole pixels exact / compared | U8 | U16 | F16 | F32 | +|---|---:|---|---|---|---| +| gaussian_spots_2 | 137,856/178,432 | 5,119/5,120/1 | 126,779/130,048/1 | 5,057/5,120/0.000244140625 | 901/38,144/6.40749931e-06 | +| noise_gaussian_noise | 139,833/178,432 | 5,120/5,120/0 | 127,801/130,048/43886 | 5,116/5,120/0.000122070312 | 1,796/38,144/0.668966413 | +| noise_gaussian_noise_v2 | 140,152/178,432 | 119,802/119,808/1 | 13,718/15,360/51197 | 5,113/5,120/0.000244140625 | 1,519/38,144/1.0108676 | +| noise_gaussian_spots_2 | 132,670/174,336 | 5,118/5,120/1 | 121,908/128,000/3 | 4,907/5,120/0.000244140625 | 737/36,096/3.65674496e-05 | +| noise_gaussian_spots_2_v2 | 136,601/174,336 | 119,790/119,808/1 | 11,396/13,312/3 | 4,951/5,120/0.000244140625 | 464/36,096/3.70144844e-05 | + +Include the previous defaults, seed, parameter and four-format cases, plus the independent 32² input. For the twelve stage-traced renders use seed 85919 + 7i + k with i = 163, 281, 282, 285 or 286 in table order. Use 16²/default/k=0, 32²/A/k=1, 32²/B/k=2 in U8, U16, F16 and F32, 64×32/C/k=6 in F32, 32×64/C/k=7 in U16, 64²/B/k=8 and 128×64/B/k=9 in F32, 64×128/B/k=9 in U16 and 128²/default/k=11 in F32. Other single-format controls use F32. Every unequal case with comparable stage images first differs in the pattern generator. + +For gaussian_spots_2 set Disorder to 0, .3125 and .8125 for A/B/C. For the Noise packages use (scale,disorder,non-square expansion) tuples (1,0,on), (3,.3125,off) and (7,.8125,on). In the two Gaussian Noise packages use 19 for the last scale. For the v2 packages also set (disorder speed, anisotropy, angle, tile offset) to (1,0,0,(0,0)), (.625,.375,.1875,(.1875,−.3125)) and (1.375,.625,−.3125,(−.4375,.0625)). + +Isolate the shortest reachable path to a drawing quadrant. Select sibling connections in ascending identifier order. Start at the first quadrant on that path and retain only the connections leading to the drawing quadrant. Draw the authored soft profile, a unit square or a disc while preserving the other authored properties. Also draw the square with every original branch connected. Compare the 16² default, 32²/A, all four 32²/B formats, 64²/B and 128×64/B. Each cell gives exact pixels / 17,664, followed by maximum error across formats. These 160 renders use the updated [stamp tint](#pattern-tint-coverage-and-grayscale-conversion). + +| Package root | Isolated square | Isolated disc | Isolated soft profile | Complete square layout | +|---|---:|---:|---:|---:| +| gaussian_spots_2 | 17,664 / 0 | 17,664 / 0 | 17,657 / 1.37090683e-06 | 17,664 / 0 | +| noise_gaussian_noise | 17,664 / 0 | 17,664 / 0 | 3,565 / 6.10351562e-05 | 17,664 / 0 | +| noise_gaussian_noise_v2 | 17,664 / 0 | 17,664 / 0 | 3,547 / 1 | 17,664 / 0 | +| noise_gaussian_spots_2 | 17,664 / 0 | 17,664 / 0 | 17,664 / 0 | 17,663 / 0.254905939 | +| noise_gaussian_spots_2_v2 | 17,664 / 0 | 17,664 / 0 | 17,663 / 5.40167093e-08 | 14,329 / 0.161732554 | + +All 176,640 isolated square and disc pixels agree. The complete square layout and the original soft stamp must be considered separately. The isolated soft stamp in noise_gaussian_spots_2 is exact across these eight renders, while the complete square layout has a differing pixel. The large rectangular cases and the full soft generators remain open. + +A separate 24-render scale sweep used 2 through 7, C for the other controls, and seed 93281 + 7i. For noise_gaussian_spots_2 the 16² F32 target completed scales 2–6 and the 64×32 U16 target completed scales 2–4. For the v2 root the corresponding completed scales were 2–4 and 2–3. The remaining eleven local cases reached the traversal budget. The reference app produced all 24 outputs. Across the 13 comparable outputs 8,115/12,288 pixels matched. The maximum was 4 stored U16 levels and 5.22732735e-05 F32. + +### Pattern tint, coverage and grayscale conversion + +| Original stamp control | Renders | Previous exact | Current exact / pixels | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---:|---| +| One solid square, changed source channels and global opacity | 92 | 8,448 | 23,552/23,552 | — / — / — / 0 | +| 64 independently tinted squares | 78 | 16,612 | 26,112/26,112 | 0 / 0 / 0 / 0 | +| White and hashed bitmap inputs | 56 | 10,248 | 14,336/14,336 | 0 / 0 / 0 / 0 | +| Four nonconstant shapes with RGBA tint | 88 | 36,432 | 71,184/90,112 | 0 / 0 / 9.53674316e-07 / 0.000280380249 | +| Four shapes with a scalar expression | 88 | 72,398 | 75,796/90,112 | 0 / 0 / 2.38418579e-07 / 5.76451421e-05 | + +Use additive blending, one full-size square on transparent black, roughness zero and a 16² F32 output. For the swatch (.9,.11,.57,.732), the grayscale square gives bits `3f06d3a0`. Returning the same value from a four-channel expression gives `3f3b645a`. Direct swatches use ((R + G) + B) / 3 in F32. Four-channel expressions supply A and scalar expressions supply their single value. A white point-sampled bitmap gives the same respective values. The alternate 16² input uses U8 intensity (41x + 29y + 13xy + 3) mod 256. Render both inputs with gains 1 and .6137. The solid-square controls also include red, green, blue, transparent black, signed and over-one channels, with gains 1, .6137, −1.1875 and 327.125. + +For the color grid, fully subdivide three times and draw one white square in each leaf. Use the original scalar and four-channel expressions as well as literal swatches. Draw on RGBA (.125,.25,.375,.5) under all three blend modes. The 64 colors use PCG64 seed 90287 with four F32 draws per leaf, drawn uniformly from [−1.25,1.625). Include primary colors, equal RGB, zero and unit alpha, signed cancelling channels and values up to 32 times the original amplitude. Use (roughness,gain) pairs (0,1), (.95,.6137), (0,−1.1875), (1.03125,327.125), (.75,2.500080108642578), (0,.37) and (1,1). Alternate 32×16 and 16², with seeds 90739 + 11j. Cases j=1 and j=3 also cover U8, U16 and F16. + +In color mode, first round A × depth opacity. Multiply each RGB channel by that result before applying shape coverage. Shapes 17 and 18 add their variation as part of the final multiply-add. Using the reference app’s unit-tint coverage as identical input reproduces 53,248/53,248 F32 pixels across shapes 5, 10, 17 and 18, with maximum error zero. MaterialCraft’s own nonconstant coverage still differs on the cases in the table. At (16,16) of a 32² shape 5 with the example swatch and gain .6137, RGBA gives `3ecd6456 3d48d3e4 3e8214e2 3ee43699`. A scalar expression returning .732 gives `3ee43699` in all four channels. Use seeds 91117 + 17j and variations 0, .125 and −.25. + +| Full root on the [previous inputs](#stored-opacity-across-pattern-depths) | Renders | Previous exact | Current exact / pixels | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---:|---| +| brick_3 | 34 | 201,968 | 201,968/204,288 | 0 / 3 / 0 / 1.33514404e-05 | +| clouds_1 | 17 | 144,178 | 144,178/145,664 | 1 / 11 / 0.00048828125 / 0.000111341476 | +| clouds_2 | 16 | 128,263 | 128,263/129,280 | 1 / 3 / 0.00048828125 / 2.29477882e-05 | +| creased | 17 | 143,936 | 143,948/145,664 | 0 / 29 / 0.00048828125 / 1.52587891e-05 | +| crystal_2 | 17 | 144,774 | 144,770/145,664 | 0 / 2 / 0 / 3.05175781e-05 | +| dirt_1 | 17 | 145,661 | 145,661/145,664 | 0 / 1 / 0 / 1.51991844e-05 | +| dirt_3 | 17 | 145,351 | 145,359/145,664 | 0 / 1 / 1.52587891e-05 / 1.52736902e-05 | +| dirt_5 | 16 | 129,226 | 129,226/129,280 | 0 / 4 / 6.10351562e-05 / 5.0842762e-05 | +| dirt_6 | 16 | 117,822 | 117,826/129,280 | 0 / 8 / 0.133789062 / 0.140006408 | +| dirt_gradient | 16 | 128,449 | 128,396/129,280 | 0 / 2 / 0.000244140625 / 1.98483467e-05 | + +Dirt 1 also has 12 new comparisons per setting. Repeat seed S eight times interleaved with S+1, S+2 and S+19 in the sequence 0,0,1,0,2,0,0,19,0,0,1,0 relative to S. At the default 128² U16 output with S=0, three pixels vary by one stored level within the eight reference runs. Every MaterialCraft value appears in at least one reference run, and two entire reference frames match it. At 64² with the recorded changed controls and S=42, one U16 pixel varies by one level and the local frame matches one entire repeat. The corresponding F32 reference output is byte-identical across all eight runs. It differs from MaterialCraft at the same single pixel by .0000151991844. Dirt 1 remains in progress. + +Opening six MaterialCraft saves in the reference app reproduces 37,632/37,632 source-file pixels in 69 renders, maximum error zero. The files exercise a grayscale swatch, constant expression, color grid, gradient with a four-channel getter, radial shape with a scalar getter and a bitmap with an expression. Rerunning 19 previously verified pattern roots gives 3,211,776/3,211,776 exact pixels across 159 renders. + +### Overlapping disc additions in Dirt 1 + +The whole root still matches 145,661/145,664 pixels across 17 renders. Its first differing stage draws grayscale discs at depths seven and eight. Connect that stage directly to the output, retain all four root quadrants or one at a time, and enable both drawing depths or either depth alone. To disable a depth, set its pattern type to zero and leave the descendants, offsets and seed expressions connected. Across the 15 variants, 120 renders match **629,340/629,760** pixels. + +| Output format | Exact pixels / compared | Maximum absolute error | +|---|---:|---:| +| U8 | 61,440/61,440 | 0 | +| U16 | 61,439/61,440 | 1 level | +| F16 | 61,440/61,440 | 0 | +| F32 | 445,021/445,440 | 1.19209290e−7 | + +For each variant render 64² with disorder .4 and seed 42 in F32, U16, F16 and U8. Then render 32² with disorder .15625 and seed 100189, 128² at defaults with seed zero, 64² with disorder .4 and seed 43, and repeat the first F32 case. At the pattern output with all quadrants and both depths enabled, the two seed-42 reference F32 frames differ at 29/4,096 pixels, maximum 5.96046448e−8. [Repeated final-root outputs](#pattern-tint-coverage-and-grayscale-conversion) + +For an independent check take the centers, sizes and luminosities from MaterialCraft's traversal of each quadrant. Each quadrant emits 20,480 axis-aligned discs across both depths. At each pixel center, wrap the disc center to its tile, test the unit-disc radius and accumulate the covered luminosities with their depth opacities in traversal order using F32. This reconstruction matches all 384,000 local F32 pixels for the four distinct settings across the 15 variants. Against the reference it matches 383,644/384,000. At every one of the 356 unequal pixels some ordering of those same individual additions reproduces the observed reference bits exactly. The differing pixels each have three to eight contributions. Reversing the whole traversal matches 383,365 pixels, grouping by ascending depth matches 383,584, and accumulating in F64 before rounding matches 383,470. These results isolate the sensitivity to addition order. The remaining whole-root difference and the repeat variability are recorded separately. + +### Stored opacity across pattern depths + +| Direct pattern control | Renders | Exact pixels / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---| +| One white square at a selected depth | 1080 | 359,424/359,424 | 0 / 0 / 0 / 0 | +| Independent roughness values and large exponents | 288 | 73,442/73,728 | — / — / — / 4.34931234e-39 | +| Power-rounding and overflow controls | 85 | 21,760/21,760 | — / — / — / 0 | +| Signed and extended global opacity | 192 | 49,152/49,152 | — / — / — / 0 | + +On the main single-square matrix the previous cook matched 286,511/359,424 pixels. The updated cook matches 359,424/359,424, maximum error zero. In noise_fur_1 the isolated square at depth five now gives F32 bits `3ebaf23c` in both apps. On the complete pattern layout the flat square improves from 3,072/26,880 and the disc from 3,078/26,880 to 26,880/26,880 each. The isolated square and disc also match all 26,880 pixels each. The original soft profile at the root still differs. [Fur inputs and layout isolation](#fur-pattern-sources-and-downstream-filters) + +Draw one white square with maximum blending at depth `d`. Give it size `(2^d,2^d)`, disable tiling and leave every other quadrant empty. Connect the only child of quadrant `j` at slot `j mod 4`. The following lists specify maximum depth and drawing depths. Use 0/[0], 1/[0,1], 2/[0,1,2], 3/[0..3], 4/[0..4], 5/[0..5], 6/[0,3,6], 8/[0,1,4,7,8], 10/[0,5,9,10] and 12/[0,6,12]. The deepest visited quadrant counts even when it draws nothing. For the main matrix use gain 1 with roughness [0,.125,.1875,.375,.5,.5625,.75,.8125,.9,.9375,.95,.99,.9999998807907104,1,1.03125,1.125,1.5,2,4]. Then use [.375,.95,1,1.5] with each gain in [.6137,2.500080108642578]. Number those settings `j` from zero. Use 32×16 when `j mod 3 = 0` and 16² otherwise, with seed `81799 + 13 × maximum depth + d + j`. Read F32 for every case and also U8, U16 and F16 at roughness .95 with the larger gain. + +For positive roughness `r` and `n` visited depths, the first depth uses the geometric normalization `(1 − r) / (1 − pow(r,n))`. Store the endpoint power in F32 before subtraction. At unit roughness the first weight is `1/n`. Multiply the first weight by the global opacity, then multiply each stored parent opacity by the roughness to obtain the child. Zero roughness gives every depth the full global opacity. A chain with a square at depth 2, roughness .99 and gain 1 returns `3ea8f445`. With roughness 1.5 and gain .6137 it returns `3e94d6a2`. The 37 rounding-boundary cases distinguish the native single-precision power from a power evaluated in double precision and rounded once. For one witness use roughness 1.2230699062347412, depth 5 of 5 and gain 1. The observed output is `3e852977`. The 48 overflow controls use roughness `2^e` with `e` in [6,10,15,22,31,45] at (maximum depth, drawing depth) [(5,5),(1,0),(3,1),(10,10),(2,2),(8,4),(4,3),(12,12)]. A depth-five square with roughness 4,194,304 returns zero. MaterialCraft previously limited the roughness passed to the cook to 34. + +In the 192 additive square controls use (0,0), (1,0), (3,1) and (5,5), the six roughness values [0,.95,1,1.5,34,64] and global opacity [−1,0,.6137,10,170,171,327.125,65536]. Render at 16² F32 with seed `86917 + j`. The unit square at depth zero returns the input opacity, including negative values and values above 170. With a four-component quadrant tint and a colored background the additional 84 renders match 29,448/35,328 pixels. Their maximum F32 error is 8064.03027. Those controls expose a separate tint discrepancy. + +For the independent roughness controls, use (2,0), (3,1), (4,4), (5,5), (6,3), (8,7), (10,10) and (12,12). Use F32 16² with seed `87211 + 23j` and gains [1,.37,1.73,2.500080108642578] cycling by case. The roughness list starts with [.0001,2^-18,.03125,.32,.73,.86,.9823,.99873], the adjacent F32 values below and above one, then [1.000012,1.0043,1.33,2.71,4.125,7,13]. Append 13 values drawn uniformly from [.01,2.25] with one NumPy PCG64 stream seeded 80627 across the eight depth pairs, followed by the six powers of two above. + +At this revision the independent controls had 286 differing pixels. For depth 7 of 8, roughness 2^-18 and gain .37, the local covered pixels have F32 bits `002f5c1d`. For depth 10 of 10, roughness .0001 and gain 1, they have bits `000116bb`. Each capture differs in 143 pixels and the reference output stores zero. The later [opacity and accumulator controls](#pattern-opacity-near-zero-and-color-accumulation) reproduce both cases exactly. The power-rounding measurements use the Windows reference session. + +| Original root | Renders | Exact pixels before | Exact pixels after / compared | Maximum U8 / U16 / F16 / F32 error after | +|---|---:|---:|---:|---| +| brick_3 | 34 | 200,505 | 201,968/204,288 | 0 / 3 / 0 / 1.33514404e-05 | +| clouds_1 | 17 | 144,184 | 144,178/145,664 | 1 / 11 / 0.00048828125 / 0.000111341476 | +| clouds_2 | 16 | 128,259 | 128,263/129,280 | 1 / 3 / 0.00048828125 / 2.29477882e-05 | +| creased | 17 | 143,936 | 143,936/145,664 | 0 / 29 / 0.00048828125 / 1.52587891e-05 | +| crystal_2 | 17 | 144,774 | 144,774/145,664 | 0 / 2 / 0 / 3.05175781e-05 | +| dirt_1 | 17 | 145,626 | 145,661/145,664 | 0 / 1 / 0 / 1.51991844e-05 | +| dirt_3 | 17 | 145,297 | 145,351/145,664 | 0 / 1 / 1.52587891e-05 / 1.52736902e-05 | +| dirt_5 | 16 | 129,218 | 129,226/129,280 | 0 / 4 / 6.10351562e-05 / 5.0842762e-05 | +| dirt_6 | 16 | 117,822 | 117,822/129,280 | 0 / 8 / 0.133789062 / 0.140006408 | +| dirt_gradient | 16 | 128,383 | 128,449/129,280 | 0 / 2 / 0.000244140625 / 1.98483467e-05 | +| fur_1 | 21 | 164,031 | 164,031/178,432 | 1 / 2 / 0.00048828125 / 3.05771828e-05 | +| noise_fur_1 | 21 | 122,553 | 122,549/178,432 | 1 / 3 / 0.00048828125 / 8.31484795e-05 | + +These are full root outputs on the [original generator inputs](#square-and-rectangular-pattern-generators) and the linked Fur settings. Clouds 1 and noise_fur_1 have slightly fewer exact pixels on those inputs after the depth correction. Dirt 1 retains three differing pixels across 17 renders. All 19 previously verified roots in the direct FX-Map guard set still match 3,211,776/3,211,776 pixels in 159 renders, maximum error zero. The independently authored depth-five chain, fur_1 and noise_fur_1 were also saved via MaterialCraft and opened again in the reference app. Against the source-file renders, the 26 reopened cases match 61,184/61,184 pixels, maximum error 0. The root files used the current-format header for this handoff. Open each file at its save destination so package-relative dependencies resolve. A separately moved copy of noise_fur_1 lost its relative link to `functions.sbs` and matched only 24/28,928 pixels. Reopening the identical saved bytes at the original destination matches 28,928/28,928. + +### Fur pattern sources and downstream filters + +Each root has 21 raw comparisons, totaling 178,432 pixels per root. Each format cell gives exact pixels / maximum error. The denominators are 5,120 U8, 130,048 U16, 5,120 F16 and 38,144 F32. Integer errors are stored levels. Every differing stage-traced case first diverges in the FX-Map. + +| Package root | Exact pixels | U8 | U16 | F16 | F32 | +|---|---:|---:|---:|---:|---:| +| fur_1 | 164,031 | 5,119 / 1 | 118,988 / 2 | 5,091 / 0.00048828125 | 34,833 / 3.05771828e-05 | +| fur_2 | 134,013 | 5,119 / 1 | 123,497 / 1 | 5,080 / 0.000244140625 | 317 / 1.06096268e-05 | +| fur_3 | 145,101 | 5,117 / 1 | 106,705 / 4 | 5,067 / 0.00048828125 | 28,212 / 6.10351562e-05 | +| fur_4 | 148,992 | 5,120 / 0 | 107,228 / 4 | 5,066 / 0.00048828125 | 31,578 / 6.10351562e-05 | +| noise_fur_1 | 122,553 | 5,117 / 1 | 112,234 / 3 | 5,027 / 0.00048828125 | 175 / 8.31186771e-05 | +| noise_fur_2 | 130,666 | 5,119 / 1 | 120,328 / 5 | 5,018 / 0.000244140625 | 201 / 7.84248114e-05 | +| noise_fur_3 | 132,982 | 5,119 / 1 | 122,585 / 3 | 5,048 / 0.000244140625 | 230 / 5.67138195e-05 | + +The 12 stage-traced renders add to the four archived renders, four output-precision renders and one independent seed. In case order the new renders use 16², 32² five times, 64×32, 32×64, 64², 128×64, 64×128 and 128². Their output formats are F32, F32, U8, U16, F16, F32, F32, U16, F32, F32, U16 and F32. Number inventory rows from zero. Use seed `73939 + 7 × row` plus offsets 0, 1, 2, 2, 2, 2, 6, 7, 8, 9, 9 and 11. The first and last cases keep defaults. The other cases use the following tuples in the order A, B, B, B, B, C, C, B, B, B. + +| Root | Parameter order | A | B | C | +|---|---|---|---|---| +| fur_1 | disorder | 0 | 0.375 | 7.5 | +| fur_2 | disorder, wave scale, wave rotation | 0, 0, 0 | 0.3125, 0.5625, 0.125 | 0.71875, 0.25, 0.8125 | +| fur_3 | density, disorder | 0.1875, 0.125 | 0.4375, 0.625 | 0.75, 0.25 | +| fur_4 | disorder | 0 | 0.3125 | 0.71875 | +| noise_fur_1 | scale, disorder, expand non-square | 1, 0, on | 2, 0.375, off | 3, 0.6875, on | +| noise_fur_2 | scale, wave scale, wave rotation, expand non-square | 1, 0, 0, on | 2, 0.5625, 0.125, off | 3, 0.25, 0.8125, on | +| noise_fur_3 | scale, disorder, wave amount, expand non-square | 1, 0, 0, on | 2, 0.3125, 2.75, off | 3, 0.6875, 5.125, on | + +For fur_1, fur_3 and fur_4, wire a U16 input to the consumers of the pattern generator. Across the 12 settings, supply 32767 everywhere for case 0, 52111 on the diagonal over 713 for case 1, and 32768 where `(x + 13y) mod 23 = 0` over 32767 for cases 6–8. Otherwise use `((11x + 31y + 7xy + 93) × 7919) mod 65536`. Three additional captures per root pass MaterialCraft's own generated U16 pattern into both renderers at cases 0, 5 and 8. Across all 45 equal-input renders the roots match 155,136/155,136 pixels. All 210 stage images match 723,968/723,968 pixels. The reference app also reproduces the original local root at all 16,128 pixels fed from the local pattern, maximum error zero. + +To isolate the generator, route it directly to the output and render cases 0, 2, 3, 4, 5, 6, 8 and 11 with each layout below. Retain the authored pattern, replace it with a flat square or replace it with a disc. For the single-path layout, follow the shortest path to an explicit drawing quadrant, traversing sibling connection identifiers in ascending order. Start at the first quadrant on that path and retain only its path to the selected drawing quadrant. Each cell gives exact raw pixels out of 26,880. + +| Package root | Full, authored | Full, square | Full, disc | Single path, authored | Single path, square | Single path, disc | +|---|---:|---:|---:|---:|---:|---:| +| fur_1 | 3,542 | 26,880 | 26,880 | 26,691 | 26,880 | 26,880 | +| fur_2 | 3,219 | 26,879 | 26,878 | 26,819 | 26,880 | 26,880 | +| fur_3 | 5,217 | 26,880 | 26,880 | 26,855 | 26,880 | 26,880 | +| fur_4 | 5,403 | 26,880 | 26,880 | 26,819 | 26,880 | 26,880 | +| noise_fur_1 | 3,022 | 3,072 | 3,078 | 26,832 | 26,823 | 26,832 | +| noise_fur_2 | 3,078 | 26,874 | 26,878 | 26,833 | 26,880 | 26,880 | +| noise_fur_3 | 3,119 | 26,879 | 26,875 | 26,776 | 26,880 | 26,880 | + +For noise_fur_1 the single square has the same coverage in both renderers. All 57 covered pixels across the five F32 renders have local bits `3ebaf23a` and reference bits `3ebaf23c`, maximum error 5.96046448e−8. The path has six quadrants, with the white square at depth five, roughness 0.949999988079071 and global opacity 2.500080108642578. Each of the other six single-square probes matches all eight renders. Some complete layouts still differ in coverage, and the authored soft pattern differs on each isolated path. All seven roots remain open. + +### Fibers and Fluid pattern stages + +All four roots first differ in their FX-Map. Each row covers 24 full-root renders and compares 5,120 pixels each in U8 and F16, 285,696 in U16 and 128,256 in F32. Cells show exact pixels and the largest absolute error in that storage format. + +| Package and root | All formats, exact / compared | U8 | U16 | F16 | F32 | +|---|---:|---:|---:|---:|---:| +| `fibers_1.sbs/fibers_1` | 416,631/424,192 | 5,120 · 0 | 280,553 · 1 | 5,116 · 3.05175781e-05 | 125,842 · 1.53183937e-05 | +| `fluid.sbs/fluid` | 423,928/424,192 | 5,120 · 0 | 285,544 · 201 | 5,120 · 0 | 128,144 · 0.00306707621 | +| `noise_fluid.sbs/fluid` | 396,306/424,192 | 5,118 · 1 | 263,238 · 79 | 5,103 · 0.0009765625 | 122,847 · 0.00108343363 | +| `pattern_fibers_1.sbs/fibers_1` | 416,669/424,192 | 5,120 · 0 | 280,422 · 1 | 5,116 · 3.05175781e-05 | 126,011 · 1.53183937e-05 | + +Start with the four archive renders and the five [precision and independent runs](#four-format-inventory-comparison). Use the following settings for the additional 15 runs. The indices are 137 and 361 for Fibers and Pattern Fibers, and 153 and 272 for Fluid and Noise Fluid, respectively. + +| Controls in graph order | A | B | C | +|---|---|---|---| +| Fibers, tiling | 1 | 2 | 3 | +| Pattern Fibers, tiling and non-square expansion | 1, on | 2, off | 3, on | +| Fluid, disorder, warp intensity, flow, pattern length, pattern width | 0, 0, 0, .5, .5 | .3125, 17, .1875, .625, .25 | .71875, 41, −.125, .8125, .375 | +| Noise Fluid, scale, disorder, warp intensity, pattern size, non-square expansion | 1, 0, 0, (.5,1), on | 2, .3125, .1875, (.625,.25), off | 3, .71875, .4375, (.8125,.375), on | + +At 16² use defaults in F32. At 32² use A in F32, then B in U8, U16, F16 and F32. Use C at 64×32 in F32 and 32×64 in U16. At 64² use B in F32. The seeds are 31721+7i plus offsets 0, 1, 2, 2, 2, 2, 6, 7 and 8, where i is the root index. The last six profiles are 128² F32 at defaults/41713, 256² F32 at defaults/0, 256² U16 at defaults/41713, 256×128 F32 and 128×256 U16 at B/13217, and 256² U16 at C/6217. + +In Fluid at 256² and seed 0, three of the 16,384 U8 pattern samples differ by a single level. At (76,1) the local and reference levels are 139 and 140. At (17,104) they are 226 and 225, and at (43,110) they are 210 and 209. At C and seed 6217 only (5,45) differs, at 212 and 213. Reconnect the downstream filters to a 128² grayscale input with the same stored format. Using the locally rendered field reproduces the 112 differing default output pixels in U16 and F32 and the 40 differing pixels in the C U16 output. Adjusting the three default samples or the single C sample in the scratch control makes all 65,536 output pixels exact in each of the three comparisons with the original root. + +The two versions of each input field were measured at 256² U16 and F32. Three independent 128² byte inputs add four output formats each. At texel (x,y) the first field is (11x+31y+7xy+93) mod 256. The second is 237 on the main diagonal and 13 elsewhere. The third is 128 when (x+13y) mod 23 is zero and 127 elsewhere. Use seeds 16319, 16390 and 16461, with defaults for the first two and C for the third. The 20 renders match all **1,310,720 output pixels**, and all 6,225,920 pixels in the 200 observed stage images, maximum zero. + +For each graph, connect its pattern primitive directly to the graph output. Use defaults at 128²/0, 256²/0 and 256²/41713, then C at 256²/6217. Also repeat 256² defaults at seed 0 in a second visit. Each visit covers U8, U16, F16 and F32. The primitive's own size rules apply within the parent. Check the resolved storage in both apps. The isolated native U8, U16 and F32 buffers also match those of the full graph with the same pattern storage in all 60 paired captures. + +| Isolated pattern | Exact / compared in 20 renders | U8 max | U16 max | F16 max | F32 max | +|---|---:|---:|---:|---:|---:| +| fibers_1.sbs/fibers_1 | 347,323/458,752 | 1 | 1 | 0.00048828125 | 1.10268593e-06 | +| fluid.sbs/fluid | 217,580/278,528 | 1 | 1 | 0.00048828125 | 4.17232513e-06 | +| noise_fluid.sbs/fluid | 209,826/278,528 | 1 | 2 | 0.00048828125 | 2.87890434e-05 | +| pattern_fibers_1.sbs/fibers_1 | 347,323/458,752 | 1 | 1 | 0.00048828125 | 1.10268593e-06 | + +The isolated Fibers primitives use Gaussian stamps. Both Fluid primitives use the asymmetric quartic profile at a quarter turn and variation .779999971. Their remaining differences are present in the pattern output before the downstream transform, blur, Levels and warp filters. The [single-stamp measurements](#horizontal-stamp-slope-and-height) constrain the shared coordinate calculation. + +### Stored grayscale stops and scalar Levels controls + +Three fractal sum roots match **436,992/436,992 output pixels across 54 renders**, maximum error zero. Each root contributes 119,808 U16, 5,120 U8, 5,120 F16 and 15,616 F32 pixels. Use the nine inventory renders and the nine seed, size and parameter profiles recorded with the [box blur measurements](#box-blur-and-signed-pixel-sizes). The comparisons include defaults, changed roughness and opacity, restricted octave ranges and both rectangular orientations. All images from reachable graph stages matched in the nine renders per root that recorded intermediate outputs. + +| Package and root | Exact before / compared | Exact after / compared | Node output images compared | Exact stage pixels | +|---|---:|---:|---:|---:| +| `fractal_sum_base.sbs/fractal_sum_base` | 142,777/145,664 | 145,664/145,664 | 1,188 | 1,007,841,792 | +| `noise_fractal_sum_base.sbs/fractal_sum_base` | 143,104/145,664 | 145,664/145,664 | 1,008 | 1,310,976 | +| `noise_fractal_sum_base.sbs/fractal_sum_base_2` | 143,120/145,664 | 145,664/145,664 | 1,008 | 1,310,976 | + +On these roots, a linear grayscale Gradient Map stores the arithmetic mean of its RGB stop channels as a normalized U16 word before interpolation. Clamp the mean to [0,1] and round to the nearest stored level. The first stop at a shared stored position owns that position. Interpolate in the existing 256-entry table's index space and sample the stored table with eight-bit weights. An original four-stop ramp at positions 0, .5, .504218996 and 1 with grayscale values 0, 1, 0 and 1 gives 35,142 at input 128/255. This sample distinguished two calculations that both matched 203,520 pixels in the first fifteen affected root stages. + +For a three-stop linear ramp at 0, .5 and 1, give stop j an RGB level of ((71j+23j²+51) mod 283)/282. For input columns 68, 77, 86, 143, 214 and 234 divided by 255, the U16 outputs are 23,502, 25,044, 26,586, 29,657, 11,152 and 5,939. Use 64 evenly spaced stops with the same levels at j=0…63. Columns 2, 62, 102, 144, 181 and 211 give 22,648, 10,313, 21,474, 34,965, 12,604 and 63,000. + +A grayscale Levels control fed by a scalar function uses the scalar directly. At a white input, a scalar output-high with F32 bits 0x3ec0c0c2 yields exactly those bits. An explicit four-component control with that value in RGB and alpha one yields 0x3ec0c0c3. The mean of three equal components rounds once more. A direct scalar input link has the same behavior as a scalar literal. An explicitly repeated four-channel swizzle has the same grayscale behavior as the vector control. The property inspector retains its four displayed components. Changing the function type with a warm cache reproduces both results. + +The standalone Levels comparison matched **20,480/20,480 pixels in 80 renders**. Use scalar bit patterns 0x3ec0c0c2 and 0x3bc0c0c2. For each, set output-high to a literal RGBA property, a scalar function constant, an RGBA function constant, an explicit four-lane scalar repeat or a direct link to a scalar graph input. Set the alpha of the two RGBA constants to one. Use 16² gray and color F32 inputs, all four output formats and seed 24389 or 24390 respectively. Set H=((83x+131y+521xy+31) mod 389)/388 and replace rows zero and one with 1 and .5. For RGBA shift each row of H right by 0, 3, 5 and 7 columns with wraparound. In four reduced fractal graphs with a white 8² input, all 1,536/1,536 F32 pixels across 24 weight settings match. The prior scalar implementation matched 1,216. The full storage ramps and explicit-swizzle controls also retain 528,384/528,384 exact pixels in 24 renders. + +Ordinary saves of the three current-header root graphs reopened in the reference app. They reproduced **40,704/40,704 pixels in 27 renders**. Twenty standalone Levels files and thirteen standalone gradient files also reproduced all **978,944 pixels in 158 reopened renders**. + +| Standalone Gradient Map series | Renders | Exact pixels / compared | Maximum U8 / U16 levels | Maximum F16 / F32 error | +|---|---:|---:|---:|---:| +| Gray and mixed-color stops | 72 | 851,059/884,736 | 1 / 1 | 0 / 2.22027302e-06 | +| Shared positions, signed stops and endpoints | 42 | 514,547/516,096 | 175 / 1 | 0 / 1.1920929e-07 | +| Steep and shallow segments | 72 | 880,464/884,736 | 1 / 1 | 0.00048828125 / 3.15904617e-06 | +| Byte tables with exhaustive inputs | 24 | 835,309/835,584 | 1 / — | — / — | + +For the first series use 2, 3, 7, 64, 19 and 11 stops, each in both gray and mixed RGB. Channel c at stop j is ((71j+23j²+31c+11jc+51) mod 283)/282. For gray use channel zero for all three RGB components. The positions are j/(N−1), except the 11-stop series uses (j+.175×(j mod 3))/(N−.65). For N=19 use smooth interpolation with the stored midpoint field ((j mod 5)−2)×.15625. Use linear interpolation for the others. Render the F32 input x/255 at 256×16 U16 and (x+256y)/65535 at 256² U16. Use the [signed modular grayscale field](#gradient-warp-displacement-and-sampling) at 32² in all four output formats with seed 23473+17k, where k starts at zero and gray precedes mixed RGB. For the linear cases alone, 703,484/706,560 U16 pixels match, maximum one level. + +For the byte-table controls, repeat the two 256-wide ramps for all twelve stop sets at U8 output. For the seven limit cases use these (position, gray level) pairs. Apply the same six renders and a common 32² field with seed 23473. + +| Case | Stops | +|---:|---| +| 0 | (0,−.25), (.351,1.25), (.697,−.25), (1,.75) | +| 1 | (.125,.3125), (.5,.875), (.5,.1875), (.875,.625) | +| 2 and 3 | As in case 1, with the middle positions a−.0000001 and a+.0000001 for a=.5 or 128/255 | +| 4 | (.3,.15125) | +| 5 | (.25,.67), (.75,.125) | +| 6 | (0,1), (1,0) | + +For the twelve steep and shallow cases use four positions (0,x,x+d,1) with values (0,1,0,1). Use (x,d)=(.5,.004218996), (.5,1/255), (.5,2/255), (.25,.004218996), (1/3,.004218996), then (.5,.004218996) twice with values (.1,.9,.2,.9) and (.2,.85,.3,.85). Finish with (.4675,1.1/255), (.375,1.7/255), (.75,.004218996), (.5,.0001) and (.5,.1). Apply the six renders from the limit cases. Across the 36 U16 outputs, 846,214/847,872 pixels match with maximum error one level. Smooth tables, HDR stops at U8, and some independent linear table entries retain the differences in the table above. + +White Noise retained all 229,376 U16 pixels in five earlier renders. Eight more original-seed renders matched 24,832/24,832 pixels. Use 16² F32 at seed zero, 32² in all four formats at seed 11231, 64×32 U16 at 7159, 32×64 F32 at 9677 and 128² F32 at 17233. The root has no exposed controls. The release replay of 30 previously verified roots with reachable gradient or scalar-control paths retained 5,057,536/5,057,536 exact pixels across 256 renders, maximum zero. + +### Tone curve sampling and saved handles + +The `noise_upscale` root matched **142,592/142,592 output pixels across 17 renders**, maximum error zero. In the eight renders with intermediate graph outputs recorded, all 62,976 pixels across 48 images matched. Before the change the same root matched 2,687 output pixels, with maximum errors of 15 U8 levels, 3,791 U16 levels, .228057861 F16 and .228064887 F32. The curve is the first differing filter on the independent input. + +Use the [nine inventory renders](#four-format-inventory-comparison), then the [eight additional input profiles for the noise blend](#box-blur-and-signed-pixel-sizes) with a single grayscale input, graph defaults and seed 14604 in place of 14578. The 17 renders account for 119,808 U8, 5,120 U16, 5,120 F16 and 12,544 F32 output pixels. On the changed 32² floating case the U8 codes 32 and 128 entering the curve yield .250977516 and −.228034332. The latter measures the narrow descending segment between adjacent anchors. + +A broken outgoing or incoming handle retains its authored position in the file. Its effective control point is the anchor. For two broken handles the sampled segment follows its secant. The table has 1,024 float entries. For index i, evaluate x=i×(1/1023), with the reciprocal rounded to F32. The anchor covers table centers within half a step. Each segment still supplies at least one interior sample, including when several anchors occupy a single texel. Sample the stored table with eight-bit linear weights before converting to the output format. For example, use anchors (0,.75), (.41031,.25), (.41036,1.125), (.4104,−.0625), (1,.875) with both handles broken. Indices 420, 421 and 422 give .25, 21.6786346 and −62.7770119. + +Ordinary saves preserved the active and dormant handles and lock flags. All **78,080/78,080 pixels in 56 reopened renders** matched the original files in the reference. These cover eight original standalone packages and a current-header copy of the complete noise upscale graph. Before the fix, five of those standalone files changed appearance on save. Only 110/42,240 pixels matched across their 30 renders. + +| Standalone curve measurements | Renders | Exact pixels / compared | Max U8 / U16 levels | Max F16 / F32 error | +|---|---:|---:|---:|---:| +| Closely spaced anchors, broken handles | 24 | 393,216/393,216 | 0 / 0 | 0 / 0 | +| Ten curves on scalar ramps through an RGBA bridge | 60 | 74,253/84,480 | 1 / 3 | 0.00048828125 / 5.05000353e-05 | +| Independent incoming and outgoing handle flags | 36 | 30,877/50,688 | 1 / 28 | 0.00048828125 / 0.000418391079 | +| Seven curves at table boundaries and off-grid inputs | 21 | 171,363/344,064 | 0 / 0 | 0 / 0.000418391079 | +| Color fields with varying alpha | 84 | 34,099/101,376 | 1 / 3 | 0.25 / 0.25 | + +For the first series, use these eight ordered sets of (x,y) anchors. Give each a left/right handle at x−.03125 and x+.046875, both at the same y and both broken. + +| Set | Anchors | +|---:|---| +| 0 | (0,.125), (.4122,.875), (.4139,.0625), (1,.6875) | +| 1 | (0,−.125), (.5,.875), (.5012,.0625), (1,.8125) | +| 2 | (.0733,.375), (.3261,.875), (.3262,−.0625), (.8123,.625) | +| 3 | The five anchors in the example above | +| 4 | (0,.1875), (.25,.5625), (.75231,.40625), (1,.875) | +| 5–7 | Repeat set 4 with intermediate x positions (.2501,.7501), (.2504,.7506), (.2508,.7508) respectively | + +Use three 128² F32 input images with seeds 21143+13j+h for set j and image h. For row-major pixel index p, set i=p mod 1024 and use offset a from row group floor(p/1024). The offsets are 0, 1/2, 1/8, 1/4, 3/8, 5/8, 3/4, 7/8, 1/256, 31/256, 63/256, 127/256, 129/256, 191/256, 223/256 and 255/256. The first two inputs are (i+a)/1024 and (i+a−.5)/1023. The third uses PCG64 seed 20219 and uniform samples on [−.0625,1.0625) rounded to F32. Replace its first twelve values with −.1, 0, 1, 1.1, 2⁻²⁰, 1−2⁻²⁰, .25, .25+2⁻²⁰, .5, .5+2⁻²⁰, .75 and .75+2⁻²⁰. + +For the handle comparison, use endpoints (0,.0625) and (1,.8125), outgoing control (.1875,−.25) and incoming control (.578125,.9375). Test both flags true, both false, outgoing only, incoming only and both omitted in grayscale. Repeat both true in RGBA. Use the F32 ramp p/(W×H−1) at 16² F32, 32² in all four formats and 64² F32. The two independent controls, the omitted flags and their saved copies distinguish the file behavior from the remaining rendering differences. With active handles the continuous cubic and the reference's sampled curve can still differ. The RGBA fields also expose independent differences on alpha, including signed input. For a direct alpha control, an input of .996078432 gives .996078491 at F32 with the default alpha mapping. + +### Box blur and signed pixel sizes + +The `noise_blend` root matched **142,592/142,592 pixels across 17 renders**, maximum error zero. With the same inputs it previously matched 2,550 pixels. The eight additional renders include every reachable filter and input bridge. All 73,472 pixels in those 56 intermediate and final images matched. The root totals are 119,808 U8, 5,120 U16, 5,120 F16 and 12,544 F32 pixels. + +Use the [four-format inventory comparison](#four-format-inventory-comparison) for the first nine renders. For the other eight, generate both inputs using the [modular field and storage formats used for Mosaic](#gradient-warp-displacement-and-sampling). Use channel zero, with seed 14578 for `input` and 31 more for `previous`. Add 0, 1, 2, 2, 2, 2, 6 and 7. For the 16² U16 input use graph defaults. At 32² with F32 inputs set roughness, global opacity, minimum level, maximum level, level and contrast to (.375,.5,0,3,0,.625). Next set (.6,.8,1,3,2,.8) at 32² with U16 inputs and all four output formats. Finish with (.25,.875,1,4,3,.375) using 128×64 F32 inputs at 64² and 32×64 U8 inputs at 32². All other outputs are F32. + +Box Blur multiplies the radius intensity×min(W,H)/256 by the resolved pixel size on each axis. An axis whose radius is at most half a pixel copies its samples. The horizontal pass still stores its result at output precision before an active vertical pass. On a 32² unit impulse at intensity one with pixel size (1,64), the center is 1/16, with endpoints of 1/32 eight pixels above and below. With (64,1) the same values run horizontally. With (64,64) the center is 1/256. At a relative pixel size, multiply the two signed components by the corresponding input or parent components before using the filter. For example, (−2,3) followed by (−64,8) resolves to (128,24). A signed or zero component also survives an ordinary save. + +| Comparison | Renders | Exact pixels / compared | Maximum error | +|---|---:|---:|---:| +| Independent X and Y blur radii | 135 | 203,520/203,520 | 0 | +| Signed sizes on connected Blur and Emboss nodes | 93 | 112,384/112,384 | 0 | +| Current-header saves of the four roots, reopened in the reference | 35 | 51,200/51,200 | 0 | +| Six standalone saves with authored or inherited sizes, reopened in the reference | 52 | 69,120/69,120 | 0 | + +For the 135 blur controls, use an F32 center impulse at 16², 32², 32×64 and 64×32, and the signed modular field at 32² in U8/U16/F16/F32 and 64² F32. The seeds in render order are 19373, 19374, four copies of 19375, 19379, 19380 and 19381. Cross these with (pixel width, pixel height, intensity) of (1,1,1), (64,64,1), (1,64,1), (64,1,1), (0,16,4), (16,0,4), (.5,1.5,16), (1.5,.5,16), (−2,3,16), (3,−2,16), (2,4,8), (4,2,8), (16,32,1.25), (1,1,64) and (1,1,32). Tile both axes except for X only, Y only and neither on settings nine through eleven. + +Repeat the same nine images at intensity one for five connected size controls. Use input/filter sizes (−2,3)/(−64,8), (−2,3)/(64,−8) and (0,4)/(8,−4), relative to the input. Repeat the last two with an absolute filter size. For the 48 relief comparisons set intensity one and angle .125 turns. Use input/filter (−2,3)/(1,1) and (0,4)/(1,1) relative, (1,1)/(−2,3) and (1,1)/(0,4) absolute, then (−2,3)/(−1,2) and (−2,3)/(1,−2) relative. Use the [relief fields](#emboss-lighting-and-physical-pixel-size): X ramp at 16² and 32², Y ramp, impulse, step, small field, hash with quarter gray and hash with three-quarter gray at 32², seeds 97, 126, 184, 213, 242, 271, 300 and 329. + +Three fractal sum roots improved on the same 18 renders each. Their [subsequent gradient and scalar-control measurements](#stored-grayscale-stops-and-scalar-levels-controls) reached exact output on all 54. The first differences in the new measurements include five U16 gradient maps with matching inputs. The second and third roots also have isolated one-level errors in Levels. All four current-header root saves reproduced their original outputs when both files were rendered by the reference. + +| Remaining root | Exact pixels before | Exact pixels after / compared | Maximum U8 / U16 levels | Maximum F16 / F32 error | +|---|---:|---:|---:|---:| +| `fractal_sum_base.sbs/fractal_sum_base` | 253 | 142,777/145,664 | 0 / 2 | 0.000244140625 / 3.05175781e-05 | +| `noise_fractal_sum_base.sbs/fractal_sum_base` | 238 | 143,104/145,664 | 0 / 2 | 0 / 1.52587891e-05 | +| `noise_fractal_sum_base.sbs/fractal_sum_base_2` | 311 | 143,120/145,664 | 0 / 2 | 0 / 1.52587891e-05 | + +In addition to the nine inventory renders, use seed 19661+7i for root indices 154, 273 and 274. Add 0, 1, 2, 2, 2, 2, 6, 7 and 8. Use 16² F32 defaults, then 32² F32 with roughness .3125, global opacity .875 and levels 1–3. At 32² use (.6875,.625,2,6) for those controls in all four output formats. Use (.5,.75,1,8) at 64×32 and 32×64 F32, then repeat (.3125,.875,1,3) at 64² F32. These three roots have no image inputs. + +### Gradient warp displacement and sampling + +Both Mosaic roots and all three Slope Blur roots match the reference in **88 renders and 722,176 output pixels**, maximum error zero. The new intermediate comparisons also match all **3,461,888 pixels across 2,369 images**, including the input bridges. Each Mosaic contains 16 gradient warps and each Slope Blur contains 32. Before the fix the color Mosaic matched 1,024/142,592 pixels and the gray Mosaic matched 2,695/142,592 on the same inputs. + +| Root | Renders | Exact pixels / compared | Maximum error | +|---|---:|---:|---:| +| `mosaic.sbs/mosaic` | 17 | 142,592/142,592 | 0 | +| `mosaic.sbs/mosaic_grayscale` | 17 | 142,592/142,592 | 0 | +| `slope_blur.sbs/slope_blur` | 18 | 145,664/145,664 | 0 | +| `slope_blur.sbs/slope_blur_grayscale` | 18 | 145,664/145,664 | 0 | +| `slope_blur.sbs/slope_blur_grayscale_2` | 18 | 145,664/145,664 | 0 | + +All five include the four original renders, the [four-format comparison and independent 32² case](#four-format-inventory-comparison). For each Mosaic, the totals are 119,808 U8, 5,120 U16, 5,120 F16 and 12,544 F32 pixels. For each Slope Blur, the counts are the same except for 15,616 F32 pixels. + +For the eight additional Mosaic renders, use the [modular input field](#stored-input-precision-in-box-and-directional-blur). For source and effect in that order, use channel zero for grayscale and add 31 to the effect's seed. The two root indices i are 227 and 228. Use seed 11003+13i and add 0, 1, 2, 2, 2, 2, 6 and 7. Start with 16² U16 input, F32 output, graph defaults. Use 32² floating input and output with one sample and zero intensity. Next use 32² U16 input with four samples and intensity .25 in U8/U16/F16/F32. Finish with eight samples and intensity .6875, using 128×64 floating inputs at a 64² parent and 32×64 U8 inputs at a 32² parent. Both outputs are F32. Store the floating fields as 1.5 times the normalized value minus .25. + +For Slope Blur, use the same field and channel conventions with seed 18211+17i for root indices 484–486. Add 0, 1, 2, 2, 2, 2, 6, 7 and 8. Use 16² U8 inputs, F32 output and defaults, followed by 32² floating inputs and output with one sample, zero intensity and mode 0. At 32², use U16 inputs with four samples, intensity 1.375 and mode 1 in all four output formats. For the last three F32 outputs use parent 64×32, 32×64 and 64². Use respectively 64×32 floating inputs with eight samples, intensity 2.5 and mode 2, 64² U8 inputs with three samples, intensity .71875 and mode 0, and 64×128 floating inputs with twelve samples, intensity .25 and mode 1. + +The displacement uses the current gradient texel minus its immediate left and upper neighbors. With equal input and output dimensions W×H and S=min(W,H), multiply those differences by intensity×S²/256 to get the source offset in output pixels. On a 32² unit impulse at intensity one, the center moves four pixels in both directions, the texel to its right moves four pixels left, and the texel below moves four pixels up. Each axis respects its own tiling flag. Nearest and bilinear filter the primary image at the displaced coordinates. A gradient up to twice the output size per axis can supply its texels directly. The difference then spans one stored gradient texel, scaled by the gradient-to-output size ratio on that axis. + +| Standalone controls | Renders | Exact pixels / compared | Maximum error | +|---|---:|---:|---:| +| Planar sources, impulses, ramps and signed fields | 180 | 215,040/215,040 | 0 | +| Rectangular and square coordinate controls | 40 | 34,816/34,816 | 0 | +| Color and gray fields, native input sizes | 80 | 219,520/219,520 | 0 | +| Unequal inputs with an explicit output size | 32 | 50,176/50,176 | 0 | + +For the 180 planar renders store the X and Y coordinate ramps (x+.5)/N and (y+.5)/N as separate F32 sources. Use a constant .5 map at 16², then a step map .5[x≥N/2]+.25[y≥N/2] at 16², 32² and 64². At 32² also use a unit center impulse, a ramp (x+2y)/128, and a border map .25[x<2 or y<2]+.5[x=N−1 or y=N−1]. Each bracket is one when true. For the four output formats at 32², use source (((11x+17y+3xy) mod N)+.5)/N and map (((11x+19y+7xy+23) mod 97)−21)/64. Cross these fields with intensities 0, 1, 4, .5, 8, −2.5, 8, 8, 8 and 31. Use nearest for the fifth setting and bilinear for the others. The seventh through ninth use no tiling, X only and Y only. The other settings tile both axes. Start at seed 10009 and add 19 per map/size/output setting. For the 40 coordinate controls, cross both ramps and the step and impulse with nearest and bilinear at 16², 32², 32×16, 16×32 and 64×32. Use intensity one, XY tiling and seed 18121+W+H. + +For the mixed-size fields use the same modular field as the Mosaic roots above. Start at seed 17327+29j, add 13 for the gradient and add 0, 1, 1, 1, 1, 5, 6 and 7 for the eight renders. Use parent 16² F32, 32² in U8/U16/F16/F32, 64×32 F32, 32×64 F32 and 64² F32. The size powers in the table multiply the corresponding parent dimension by two to that power. The first series inherits the source dimensions at the warp. Repeat configurations 5–8 with the output explicitly set to the parent dimensions. + +| j | Source / gradient storage | Source / gradient size powers | Intensity | Filter and wrapping | +|---:|---|---|---:|---| +| 0 | U8 gray / U8 | (0,0) / (0,0) | .0625 | Bilinear XY | +| 1 | U8 RGBA / U8 | (0,0) / (0,0) | .0625 | Bilinear XY | +| 2 | U16 RGBA / U16 | (0,0) / (0,0) | 3.25 | Bilinear XY | +| 3 | F16 gray / F16 | (0,0) / (0,0) | .41875 | Bilinear XY | +| 4 | F32 gray / F32 | (0,0) / (0,0) | .71875 | Nearest XY | +| 5 | F32 gray / F32 | (1,0) / (0,1) | .8375 | Bilinear XY | +| 6 | U16 RGBA / F32 | (−1,0) / (1,−1) | .0625 | Bilinear X | +| 7 | U16 gray / U8 | (2,1) / (1,2) | −1.375 | Bilinear Y | +| 8 | F32 RGBA / U16 | (−1,1) / (−2,−1) | 2.125 | Nearest, clamped | +| 9 | F32 gray / F32 | (0,0) / (0,0) | 1 | Bilinear, clamped | + +Ordinary MaterialCraft saves of the five complete graphs in current-header SBS packages reopened in the reference. Their 43 additional renders reproduced all 61,696 output pixels, maximum error zero. The reference app rejected the two MaterialCraft saves whose inputs retained the older 0.1.3 package header. Three current-header standalone warp saves also matched all 42,496 pixels in 36 additional renders. + +Ten other roots have a reachable gradient warp. Reuse the [square and rectangular generator controls](#square-and-rectangular-pattern-generators) for the first two Crystal roots, the [patch controls](#bitmap-stamp-filtering-and-compositing) for both patch roots and the [four-format inventory controls](#four-format-inventory-comparison) for the others. The color patch differs by one pixel in each of the four 64² formats. Grayscale matches U8 and differs by one pixel in U16, F16 and F32. Both independent 32² F32 patches differ by one pixel. + +| Remaining root | Renders | Exact pixels / compared | Max U8 / U16 levels | Max F16 / F32 error | +|---|---:|---:|---:|---:| +| `crystal_1.sbs/crystal_1` | 17 | 144,060/145,664 | 1 / 55 | 0.000244140625 / 0.000106841326 | +| `crystal_2.sbs/crystal_2` | 17 | 144,468/145,664 | 0 / 19 | 0.000244140625 / 3.05473804e-05 | +| `fluid.sbs/fluid` | 9 | 131,984/132,096 | 0 / 201 | 0 / 0 | +| `make_it_tile_patch.sbs/make_it_tile_patch` | 9 | 132,090/132,096 | 1 / 93 | 0.00146484375 / 0.00212101638 | +| `make_it_tile_patch_grayscale.sbs/make_it_tile_patch_grayscale` | 9 | 132,092/132,096 | 0 / 47 | 0.000732421875 / 0.00105287135 | +| `microscope_view.sbs/microscope_view` | 9 | 131,217/132,096 | 0 / 61 | 0.000244140625 / 1.52606517e-05 | +| `noise_crystal_2.sbs/crystal_2` | 9 | 131,037/132,096 | 0 / 46 | 0.00048828125 / 1.52587891e-05 | +| `noise_fluid.sbs/fluid` | 9 | 129,723/132,096 | 1 / 71 | 0.00048828125 / 0.00016784668 | +| `noise_liquid.sbs/liquid` | 9 | 127,452/132,096 | 1 / 268 | 0.0009765625 / 0.000885009766 | +| `noise_microscope_view.sbs/microscope_view` | 9 | 130,081/132,096 | 1 / 48 | 0.000183105469 / 0.000137329102 | + +### Pattern backgrounds and center culling + +A connected FX-Map background with matching channels is resized at the wider of its input and output storage precisions. The resize proceeds one power-of-two level at a time. A connected input of the opposite bitmap type produces a zero background in the requested type. With the input disconnected, the authored background color applies. A grayscale map uses the mean of its three color components. + +| Comparison with the reference | Renders | Exact pixels / compared | Maximum stored-component error | +|---|---:|---:|---:| +| Background alone, mixed sizes and storage | 84 | 150,528/150,528 | 0 | +| Square over a matching background, plus opposite-type controls | 105 | 188,158/188,160 | 2.98023224e−8 RGBA32F | +| Connected opposite type and disconnected, with and without a square | 60 | 52,224/52,224 | 0 | +| Independent 32² U16 field reduced to 8² | 3 | 192/192 | 0 | +| Center at or across the edges of the unit and custom tiling regions | 84 | 172,032/172,032 | 0 | +| Same custom regions with center culling disabled | 60 | 122,880/122,880 | 0 | +| Reversed, fractional and negative tiling regions | 60 | 61,440/61,440 | 0 | + +For the background rows use configurations 0 and 2 through 12 of the [mixed-size blur matrix](#stored-input-precision-in-box-and-directional-blur), retaining the neutral Levels source, dimensions, formats, seeds and tiling. Connect that source to the pattern background. A single resize of the original texture matched only 90,461/150,528 pixels in the first row. For the second row, draw an additive square of size (.25,.3125) at (.3125,.65625), global opacity .625, with gray .421875 or RGBA (.5625,.3125,.8125,.71875). Also render configurations 2, 8 and 10 with the opposite output type and an empty pattern. All 138,768 pixels outside the square in the twelve matching-type configurations agree. The two differing pixels lie inside the square. For the third row keep those three opposite types, set the constant to (.125,.375,.8125,.25), and cross connected/disconnected with square/empty at 16² F32 and 32² in all four formats. The disconnected gray value is .4375. For the independent reduction use U16 codes ((17x+113y+59xy+19)×7919) mod 65536 at seed 15709. At 8² U8, pixels (2,0) and (5,0) contain 146 and 140. + +When culling is enabled, the original stamp center must lie inside both tiling intervals before any copies are drawn. Each interval includes its lower endpoint and excludes its upper endpoint, including on axes with wrapping disabled. Use a square of size (.484375,.40625). In order, place its center at (.5,.5), (.1875,.1875), (.2490234375,.625), (.25,.625), (.75,.625), (.7509765625,.625), (.625,.125), (.625,.875), (.75,.875), (.125,.0625), (−.0625,.765625) and (1.0625,.4375). Rotate the tenth square .125 turns. With index j starting at zero, render at 64² when j is divisible by three and 32² otherwise, cycle F32/U16/F16/U8, and use seed 8209+17j. Use unit regions with XY wrapping and culling off and on. Then enable culling with tiling (.25,.75,.125,.875) and each of the four wrap masks, followed by XY wrapping with render region (−.5,1.5,−.25,1.25). Repeat those five custom configurations with culling off. + +For the 60 endpoint controls, use render region (−1,1.5,−1,1.5), a .5-square, and tiling regions (.75,.25,.125,.875), (.25,.75,.875,.125), (.75,.25,.875,.125), (.1,.3,.15625,.84375) and (−.8125,−.1875,−.75,.5). Use respective wrap masks XY, none, X, none and XY. Test centers (.5,.5), (0,.625), (.75,.625), (1,.5), (.25,.875), (.5,.125), (.125,.5), (.3125,.5), (.625,.0625), (−.8125,−.75), (−.5,.25) and (−.1875,.25). All are 32² RGBA32F, seed 9833+17j. A reversed interval uses [0,1) on its axis. + +Five ordinary MaterialCraft saves reopened in the reference and reproduced all 53,952 pixels in 39 renders, maximum error zero. They cover X-only culling, two reversed intervals, the 32² to 8² reduction and opposite-type backgrounds in both directions. The Paths Polygon root retained 5,120/5,120 exact buffer pixels across its 19 renders. The position debug root retained all 136,192 pixels in its seven equal-resolution controls and all 256 pixels in its separately matched preview. The Bevel Smooth debug position root matched 246,784/246,784 across 13 renders. [Polygon controls](#color-temperature-range-reductions-sky-parameters-and-polygon-paths) · [Matched position preview](#tinted-stamp-offsets-and-alpha) + +The second Black and White Spots 1 root now matches 41,745/132,096 pixels over its nine controls, compared with 35,010 in the earlier run. U8 matches 36,930/118,784 with maximum error 16 levels, U16 matches 834/4,096 with maximum 147 levels, F16 matches 3,501/4,096 with maximum .002197265625, and F32 matches 480/5,120 with maximum .00223374367. The 64² four-format sweep uses seed 42, scale 2, disorder .37, speed .6, anisotropy .3, angle .125 turns, roughness .6 and tile offset (.17,.29). [Archived and independent controls](#empty-size-dependent-pattern-branches) + +### Tiling axes and pattern copy bounds + +A square stamp now wraps independently on each enabled axis. A repeated copy contributes only when its bounding box overlaps the tiling interval on every wrapped axis. A copy that only touches an endpoint contributes zero. Extending the render window beyond the tiling rectangle exposes the portions of admitted copies that extend into the larger window. A reversed tiling interval uses [0,1] on that axis. The tests exercise all four masks and both edges of a tangency. + +| MaterialCraft compared with the reference | Renders | Exact pixels / compared | Maximum stored-component error | +|---|---:|---:|---:| +| Axis-aligned square, two regions, grayscale and RGBA | 112 | 200,704/200,704 | 0 | +| Default, expanded and reversed regions, RGBA32F | 22 | 90,112/90,112 | 0 | +| Rotated square, paraboloid, Gaussian and tangent squares, F32 | 81 | 160,564/163,328 | 2.14576721e−6 | + +For the first row use maximum blending, an axis-aligned square and a black background. For each of masks 0, X, Y and XY, first use unit render and tiling regions, then render (−.25,1.25,0,1) with tiling (.125,.875,.25,.75). Regions are in left, right, top, bottom order. Render these seven settings, in order, with seed 7949+19j. + +| Output | Center offset from (.5,.5) | Stamp size | +|---|---|---| +| 16² F32 | (−.46875,−.4375) | (.25,.3125) | +| 32² U8, U16, F16, F32 | (.421875,.453125) | (.375,.25) | +| 64² F32 | (−.734375,−.546875) | (.5625,.375) | +| 64² U16 | (.671875,−.59375) | (.3125,.125) | + +At 64² F32 the covered pixel counts for 0, X, Y and XY are 27, 324, 72 and 864 in the unit region and 117, 216, 312 and 576 in the custom region. For the second row, draw the centered half-size square at seed zero and the first row's 16² geometry at seed 1511, both at 64². With render (0,2,0,1) compare the unit and matching tiling regions, tiling disabled and the tiling region omitted. Also render (0,2,0,2) with unit tiling, and (−.5,1.5,0,1) with X tiling. Finally use a unit render window and tiling (.25,.75,.125,.875), reversing X, Y and then both axes. Repeat the last setting with tiling disabled. + +For the final row, render each F32 shape separately at the following settings. Capture X, Y and XY tiling and the individual untiled copies offset by integer multiples of the tiling interval. The pixelwise maximum of the admitted untiled reference copies reproduces all 32,256/32,256 pixels in the 18 tiled reference renders, maximum zero. The cross-application counts above include the separate shape renders. Small radial-profile differences remain. + +| Shape | Output | Center | Size | Turns | Tiling region | Render region | Seed of tiled image | +|---|---:|---|---|---:|---|---|---:| +| Square | 64×64 | (0.0625, 0.21875) | (0.34375, 0.40625) | 0.125 | (0.125, 0.875, 0.25, 0.75) | (-0.25, 1.25, -0.5, 1.5) | 3322 | +| Square | 16×32 | (1.390625, 0.8125) | (0.53125, 0.6875) | -0.1875 | (-0.375, 1.125, -0.125, 0.75) | (-0.75, 1.5, -0.5, 1.25) | 3393 | +| Paraboloid | 32×64 | (-0.234375, 0.109375) | (0.21875, 0.3125) | 0.25 | (0.3125, 0.6875, 0.25, 0.625) | (-0.25, 1.25, -0.375, 1.375) | 3464 | +| Gaussian | 32×64 | (0.21875, -0.15625) | (0.5625, 0.4375) | 0 | (-0.375, 0.125, -0.625, 0.125) | (-0.875, 0.625, -1, 0.625) | 3535 | +| Square | 32×32 | (0.125, 0.875) | (0.25, 0.5) | 0 | (0.25, 0.75, 0.125, 0.875) | (0, 1, 0, 1) | 3606 | +| Square | 32×32 | (0.875, 0.125) | (0.25, 0.5) | 0 | (0.25, 0.75, 0.125, 0.875) | (0, 1, 0, 1) | 3677 | + +### Stored input resizing and grayscale Levels controls + +Directional noise at 16² now matches all 256 F32 pixels after its 8×16 U16 Blend. Before the fix, the Blend matched 128/128 and the following Levels matched 59/256, with a maximum F32 error of 8.49366188e−6. The remaining first difference at the 32² default is in a U16 FX-Map, with 31/32 pixels equal and a one-level maximum error. On the 64² F32 case, 4,037/4,096 final pixels match with maximum error 3.36766243e−5. The maximum across the earlier comparison was 2.94148922e−5. The larger exact count and the higher maximum are both retained below. [Square and rectangular generator inputs and seeds](#square-and-rectangular-pattern-generators) + +| Root | Renders | Previously exact | Current exact pixels / compared | Max U8 / U16 levels | Max F16 / F32 error | +|---|---:|---:|---:|---:|---:| +| Black and white spots 3 | 27 | 139,099 | 139,314/185,856 | 1 / 3 | 0.00048828125 / 5.4359436e-05 | +| Clouds 1 | 17 | 131,293 | 144,125/145,664 | 1 / 11 | 0.00048828125 / 0.000111579895 | +| Crystal 2 | 17 | 104,017 | 104,128/145,664 | 14 / 12040 | 0.052734375 / 0.136126161 | +| Directional noise | 23 | 97,505 | 145,135/147,712 | 1 / 3 | 0.00048828125 / 3.36766243e-05 | + +Across 300 direct comparisons, all 1,421,760 pixels match in their declared storage, with maximum component error zero. A color pixel counts once when all four components agree. The change uses the stored input precision at destination pixel centers. Intermediate resizes proceed in steps of up to a factor of two. A Levels enlargement stores at the wider input or output precision before applying its curve. The final reduction samples the previous level directly. In grayscale, each of the five Levels controls averages red, green and blue as ((R+G)+B)/3 before any integer endpoint clamp. Fixed Levels and Blend controls receive both resolved tiling axes. + +| Direct comparison | Renders | Exact pixels / compared | +|---|---:|---:| +| Original gray and color fields, changed size and precision | 84 | 150,528/150,528 | +| Independent sizes, tiling axes and changed curve | 105 | 188,160/188,160 | +| Isolated scalar endpoints | 12 | 49,152/49,152 | +| Independent RGB controls, grayscale and RGBA | 60 | 245,760/245,760 | +| Complete normalized 16-bit ramp, two curves, four outputs | 8 | 524,288/524,288 | +| Same ramp through a half input, two curves, two float outputs | 4 | 262,144/262,144 | +| Two widths and small integer ramps | 11 | 704/704 | +| Four tiling masks, Levels and Blend, U16 and F32 | 16 | 1,024/1,024 | + +The first two field series previously matched 83,073/150,528 and 73,501/188,160 pixels. To reproduce the resize fields, calculate H=((131x+367y+29xy+41c+17xc+seed) mod 2053)/2052 for component c starting at zero. For byte and word input, round H to the nearest stored level. For a floating input use 1.5H−.25 and apply the stated bridge format. Compare 16² F32, 32² U8/U16/F16/F32 and 64² F32/U16 in that order. The seed for field j is 11677+11j plus offsets 0,1,1,1,1,5,6. The changed curve has input low .0705882013, midpoint .522988021, high 1, output low .0134100001 and high .955938995 on RGB. Alpha uses the neutral curve. Intermediate clamping is off. + +The source size is the output size multiplied by (2ˣ,2ʸ) for the exponents below. The optional neutral Levels stage has the source dimensions and format. Tiling masks 0,1,2,3 enable neither axis, X, Y and both. In the second group every field includes the neutral stage and uses the changed curve. + +| Fields j | Source and dimensions | Controls | +|---|---|---| +| 0–2 | RGBA32F (0,0), RGBA16 (−1,0), LUM16 (−1,0) | Direct, neutral, mask 3 | +| 3–5 | LUM16 (−1,0), (−1,0), (0,0) | Neutral stage, neutral curve for 3 and changed curve for 4–5, mask 3 | +| 6–8 | LUM16 (0,−1), (1,0), (2,1) | Neutral stage and curve, mask 3 | +| 9–11 | RGBA8, RGBA16F and RGBA32F, all (−1,0) | Neutral stage and curve, mask 3 | +| 91–94 | LUM16 (−1,−1) | Masks 3,0,1,2 | +| 95–99 | LUM16 (−2,−1), (−2,−2), (−1,1), (1,1), (2,2) | Mask 3 | +| 100–102 | RGBA16F (−1,−1), RGBA32F (−1,−1), RGBA8 (−2,−1) | Mask 3 | +| 103–105 | RGBA16F, RGBA32F and RGBA8, all (−1,0) | Masks 0,0,3 | + +For the 256² ramp, use U16 code 256y+x or store (256y+x)/65535 through an F16 bridge. Compare neutral and changed curves, using seeds 6347 and 6348 for U16, 6733 and 6734 for F16. The 64² independent-control input uses U16 codes round(65535((41x+17y+13xy) mod 4093)/4092). Set the first eight codes to 0,1,2,3,65532,65533,65534,65535. One unclamped grayscale control uses input low (−.5,.25,1.625,−2), mid (−.3,.53,1.25,.1), high (.601,−.375,1.875,2.5), output low (−.125,−.875,1.625,−.5) and high (1.875,1.125,−.375,2.125). At source level 45,308 the result is U16 level 55,876 or F32 bits 0x3f5a44c2. + +For the tiling control, enlarge a 4² grayscale word field with code (4y+x)×4096 to 8². Use a neutral Levels or a foreground-only Blend at full opacity. In mask order 0,1,2,3, the top-left U16 levels are 0, 3072, 12288 and 15360 in both operations. Four regression tests cover source filtering, half precision before the curve, grayscale control conversion and independent tiling axes through the evaluator and its cache. + +### Saved filter graphs and scalar Levels controls + +A grayscale Levels graph with an exposed scalar expression matches **4,096/4,096 pixels in 16 renders**, maximum zero. Bind a uniform .5 F32 input at 16². Set the lower input control to a float4 swizzle of (amount−.25). With the default swizzle, the expression occupies red and the other RGB components are zero. At amounts .75 and .5, the raw F32 outputs are .40000003576278687 and .4545454680919647. An explicit (0,0,0,0) swizzle instead broadcasts the scalar and produces 0 and .3333333432674408. Repeat both graphs at amounts .9375 and .25. Use seeds 9217 through 9220 in that order and render both U16 and F32. The engine regression also changes the input, undoes it, redoes it and reloads the saved package. + +Five original graphs saved through MaterialCraft's file commands reopened in the reference with **52,224/52,224 pixels identical to the reference renders of the source files**, maximum zero. Both the imported and written packages use schema 1.1.0.202502. Compare the seven gray Y-only and seven RGBA X-only [custom-region square renders](#tiling-axes-and-pattern-copy-bounds), seven box blur renders at index 0 and seven directional renders at index 15 and .25 turns in the [input-resize matrix](#stored-input-precision-in-box-and-directional-blur), and the eight default-swizzle Levels renders above. The original procedural fields, exposed values, output formats and dimensions were the same on both sides of each comparison. + +### Repeated seeds in dirt and pattern generators + +At 16² F32 and seed 9802, Dirt 5 produces two reference values at pixel (12,4) on repeated evaluations of the same graph. The other 255/256 pixels agree in all eight observations. With the intermediate images included, the output was 0.21309643983840942 three times and 0.21314725279808044 five times. With only the output observed, the counts were seven and one. The maximum difference in both series is 0.0000508129597. The U16 FX-Map at that coordinate alternates between levels 36,829 and 36,830. The directly connected F32 Levels image also alternates. In the original 16² MaterialCraft render the pixel is 0.21309643983840942. The recorded overall root counts still include the comparison against the original reference observation. [Square and rectangular pattern generators](#square-and-rectangular-pattern-generators) + +Each series evaluates the seeds S + (0,0,1,0,2,0,0,19,0,0,1,0) in order, keeping the original procedural inputs and reading raw images after each graph evaluation. The table compares the eight visits to S. Each row counts a pixel once if every component has identical stored bits in all eight visits. + +| Root | Side | Seed S | Stable final pixels / compared | Maximum variation in final output | +|---|---:|---:|---:|---:| +| Dirt 5, intermediate images included | 16 | 9802 | 255/256 | 0.0000508129597 | +| Dirt 5, output only | 16 | 9802 | 255/256 | 0.0000508129597 | +| Dirt 5 | 32 | 9803 | 1,024/1,024 | 0 | +| Dirt 1 | 16 | 9776 | 256/256 | 0 | +| Dirt gradient | 16 | 9828 | 256/256 | 0 | +| Crystal 1 | 16 | 9633 | 256/256 | 0 | +| Crystal 2 | 16 | 9646 | 256/256 | 0 | +| Alveolus | 16 | 8359 | 256/256 | 0 | +| Directional noise | 32 | 9764 | 1,024/1,024 | 0 | + +Use settings A at 16² and B at 32² from the linked generator table. All observed intermediate pixels also repeat in the 32² Dirt 5 and Directional noise cases and the Dirt 1, Crystal and Alveolus cases. Dirt gradient has three varying intermediate pixels, each at (14,7) in a separate image. The U16 Blend spans 29,406–29,407, the U16 FX-Map spans 11,843–11,844, and the F32 Levels spans 0.3331910967826843–0.3332066237926483. The Dirt gradient final pixel repeats in all eight visits. Its other measured differences with MaterialCraft remain open. + +### Square and rectangular pattern generators + +Nineteen roots account for 194 new renders and 368,384 output pixels. Capturing the intermediate filters in the same renders places the first difference at an FX-Map in 18 of the 19 roots. Brick 2 matches all eight new outputs and every intermediate image. Its earlier U16, F16 and F32 differences are reproducible. The combined columns include the archived defaults, original changed controls and the earlier four-format and independent cases compared again with the current evaluator. All counts require equality across every stored component. + +| Inventory index | Root | New renders | New exact pixels / compared | Combined renders | Combined exact pixels / compared | Max U8 / U16 levels | Max F16 / F32 error | +|---:|---|---:|---:|---:|---:|---:|---:| +| 19 | Alveolus | 15 | 31,608/32,000 | 41 | 332,280/334,336 | 0 / 1000 | 0 / 3.05175781e-05 | +| 57 | Black and white spots 1 | 15 | 25,692/32,000 | 34 | 157,008/204,288 | 1 / 5 | 0.00048828125 / 6.47306442e-05 | +| 58 | Black and white spots 3 | 8 | 10,283/13,568 | 27 | 139,099/185,856 | 1 / 3 | 0.00048828125 / 5.4359436e-05 | +| 59 | Brick 1 | 15 | 31,858/32,000 | 34 | 202,490/204,288 | 0 / 1 | 1.52587891e-05 / 1.52587891e-05 | +| 60 | Brick 2 | 8 | 13,568/13,568 | 27 | 185,560/185,856 | 0 / 1 | 6.10351562e-05 / 1.52662396e-05 | +| 61 | Brick 3 | 15 | 31,829/32,000 | 34 | 200,505/204,288 | 0 / 3 | 0 / 1.52587891e-05 | +| 67 | Cells 1 | 8 | 13,525/13,568 | 17 | 144,983/145,664 | 0 / 3 | 0.00048828125 / 3.67760658e-05 | +| 78 | Clouds 1 | 8 | 7,054/13,568 | 17 | 131,293/145,664 | 1 / 11 | 0.00048828125 / 0.000111401081 | +| 79 | Clouds 2 | 8 | 13,456/13,568 | 16 | 128,005/129,280 | 1 / 3 | 0.00048828125 / 2.29477882e-05 | +| 114 | Creased | 8 | 13,483/13,568 | 17 | 143,706/145,664 | 0 / 29 | 0.00048828125 / 1.53183937e-05 | +| 117 | Crystal 1 | 8 | 1,403/13,568 | 17 | 99,250/145,664 | 52 / 27622 | 0.206420898 / 0.361802135 | +| 118 | Crystal 2 | 8 | 1,996/13,568 | 17 | 104,017/145,664 | 14 / 12040 | 0.052734375 / 0.136126161 | +| 127 | Directional noise | 15 | 15,078/32,000 | 23 | 97,505/147,712 | 1 / 2 | 0.0009765625 / 2.94148922e-05 | +| 128 | Dirt 1 | 8 | 13,565/13,568 | 17 | 144,472/145,664 | 0 / 304 | 0 / 1.52587891e-05 | +| 129 | Dirt 3 | 8 | 13,535/13,568 | 17 | 145,297/145,664 | 0 / 1 | 1.52587891e-05 / 1.52736902e-05 | +| 130 | Dirt 5 | 8 | 13,558/13,568 | 16 | 129,218/129,280 | 0 / 4 | 0.000122070312 / 5.0842762e-05 | +| 131 | Dirt 6 | 8 | 9,039/13,568 | 16 | 117,822/129,280 | 0 / 8 | 0.133789062 / 0.140006408 | +| 132 | Dirt gradient | 8 | 0/13,568 | 16 | 538/129,280 | 115 / 50249 | 0.453125 / 0.877987966 | +| 353 | Pattern Alveolus | 15 | 31,436/32,000 | 33 | 201,876/203,264 | 0 / 2 | 0 / 1.52587891e-05 | + +All 19 roots generate their own input. For square renders use defaults at 32² F32, setting A at 16² F32, B at 32² in U8/U16/F16/F32, then C at 64² F32 and U16. With the zero-based inventory index i in the table, use seed 8111+13i plus offsets 0, 1, 2, 2, 2, 2, 3 and 4 in that order. + +| Roots | Parameters in tuple order | A | B | C | +|---|---|---|---|---| +| Both Alveolus | Tiling, filled cells, interstice width | (3,off,.0625) | (1,on,.21875) | (2,off,.375) | +| Both spots, Clouds 1, Dirt 1 and Dirt 3 | Disorder | .15625 | .46875 | .84375 | +| Brick 1 and 2 | Tiling, edge smoothness, interstice width | (3,.15625,.21875) | (1,.546875,.0625) | (2,.3125,.375) | +| Brick 3 | Tiling, roundness, luminance variation, luminance seed, disorder | (2,.125,.15625,7,.125) | (1,.34375,.6875,13,.3125) | (3,.03125,.3125,31,.5625) | +| Cells 1 | Distance, disorder | (3,12.5) | (11,37.5) | (17,68.75) | +| Creased and Crystal 1 | Warp intensity, disorder | (0,.15625) | (12.75,.46875) | (27.5,.84375) | +| Crystal 2 | Warp intensity | 0 | 12.75 | 27.5 | +| Clouds 2, directional noise, Dirt 5, Dirt 6 and Dirt gradient | Graph seed and dimensions | Defaults | Defaults | Defaults | + +For Pattern Alveolus enable non-square expansion in A and C and disable it in B. Both Alveolus roots, black and white spots 1, Bricks 1 and 3, and directional noise also have seven rectangular renders. Use 64×32 F32 at defaults, 32×64 in all four formats at A, 128×32 U16 at B and 32×128 F32 at C. Use seed 8623+19i plus offsets 0, 1, 1, 1, 1, 5 and 6. Width precedes height. The output dimensions were checked against both applications. + +The new stage captures compare 2,140,795/2,835,040 pixels across 1,452 images, including output bridges. The first discrepancy in the 16² directional noise Levels output occurs after a matching 8×16 U16 blend. The blend matches all 128 input pixels, while 59/256 Levels samples match with maximum F32 error 8.49366188e−6. In the 64² Dirt 1 render, all 4,096 U16 pattern pixels match, followed by a 16² U8 blur with 255/256 exact pixels and maximum error one level. In the 16² Dirt 5 case, all 256 F32 Levels samples match and the output bridge differs at one pixel by .0000508129597. Dirt gradient first differs in three separate pattern maps. [Previous spot and brick controls](#spot-and-brick-pattern-generators) · [Previous radial stamp controls](#radial-stamp-profiles-and-pattern-generators) + +| Stage storage | Images | Exact pixels / compared | Maximum component error | +|---|---:|---:|---:| +| LUM16 | 1,148 | 1,777,298/2,364,864 | 57516 | +| LUM16F | 50 | 53,124/63,488 | 0.453125 | +| LUM32F | 188 | 250,004/341,504 | 0.877987966 | +| LUM8 | 66 | 60,369/65,184 | 115 | + +### Horizontal stamp bounds at fractional heights + +A 24-pixel-wide horizontal gradient on a 64² canvas gives one of two F32 horizontal slopes as only its height and vertical position vary. For each of 21 heights h from 14.75 to 17.25 in eighth-pixel steps, render at centers (32,c), where c=32+j/8 for j from 0 through 7. In these 168 original renders the two possible slopes separate exactly by the integer distance D=floor(c+1.5h+.5)−floor(c−.5h+.5). Where D is 29, 31, 32 or 35, the slope is the nearest F32 to 2/24. Where D is 30, 33 or 34, the slope is two F32 steps below that value. For h=16.25 the eight offsets give slope differences [0,−2,−2,−2,−2,0,0,0]. The calculation establishes the effect of independently rounding the two vertical endpoints. The general slope calculation for other widths remains unresolved. + +Follow these renders with widths [12,20,24,40], heights [15,16,17,24,33] and vertical offsets [0,.5] in nested order, with horizontal center 32.5. All 208 controls use F32, zero rotation and seed 59771+23i, starting at i=0. The current release matches 798,890/851,968 raw pixels, maximum 2.38418579e−7. The [single-stamp slope measurements](#horizontal-stamp-slope-and-height) describe how to recover the candidate slope from the stored values. + +### Horizontal stamp slope and height + +An original single horizontal gradient stamp changes its F32 slope when only its height changes. For example, use size (24,16) in pixel units, center (64,64), zero rotation, zero roughness, opacity 1 and disabled tiling on a 128² canvas. Repeat with heights 33 and 63.25. Against the nearest F32 to 2/24, the only compatible F32 horizontal slopes are respectively 0, −2 and 0 representable steps away. Each nonempty row within each image has identical stored pixels. Moving a 48.125×32 stamp by .5 pixel horizontally also changes its slope by one representable step. These height and origin controls constrain the coordinate calculation for the [tiled radial stamps](#tiled-radial-stamp-coordinates). + +To recover the slope, use every interior sample of the horizontal ramp. For each candidate F32 slope s near 2/width, bound the intercept b at every pixel center x by requiring the stored ramp to equal F32((trunc32(sx+b)+1)/2). The intersection of those bounds identifies the possible slopes. The 198 F32 renders below give **3,304,944/3,428,352 exact pixels** with the current renderer, maximum 2.38418579e−7. + +For the first 55 renders, use sizes in pixels and offsets from the canvas center. For each width in [12,20,24,40,48], keep height 16 and visit sides 64, 128 and 256 in order. At side 128 render widths [12,24,40,48] for each (horizontal offset, height) in [(7,16),(.375,16),(0,33),(0,63.25),(11.25,48)]. At height 32 place the left edge of widths 24, 48 and 96 at x in [−2,0,1.125,3.5]. Finally, offset a 48.125×32 stamp horizontally by [0,.25,.5,.75,1,1.5,7.5,32]. Use seed 31237+19j in the order given, starting at j=0. + +The next 143 renders use side 128 and seed 41249+17j. Center width 24 and set height to [4,5,6,7,8,9,10,11,12,13,14,15,15.125,15.75,15.984375,16,16.015625,16.25,16.875,17,18,19,20,21,22,23,24,25,31,32,33,34,39,40,47,48,63,64,80,96,121]. For each width/height pair [(24,16),(24,17),(24,16.25),(24,16.875),(24,32),(48.125,32),(32,16)], use offsets [(0,.25),(0,.5),(0,.75),(0,1),(.5,.5),(.125,−3.5)]. Finally center every width in [20,30,32,40,48,64] at each height in [8,16,17,24,31,32,33,40,48,64]. The general slope calculation remains open. + +### Tiled radial stamp coordinates + +An original graph draws a single Gaussian stamp with opacity .995 or a paraboloid with opacity 1. Use maximum blending, size (3,1.5), and center (.25,.25) or (.75,.75). At 32×64 and 64×128 F32, the per-pixel maximum of nine separate untiled renders matches the tiled render. Offset each copy by (dx,dy) with both components in {−1,0,1}. The same result holds for the Gaussian at 64×128 U16. Across the two shapes this gives 40,960/40,960 F32 and 16,384/16,384 U16 pixels, maximum error zero. Seeds are 83 and 84 at the smaller size and 223 and 224 at the larger one. + +The following calculation also predicts those ten tiled images. In each axis of length N, let L=N(center+offset−size/2), D=N×size and B=max(0,L). K is the next F32 toward zero from F32(2/D). At pixel center p inside (L,L+D], evaluate the local coordinate as trunc32((p−B)×K+trunc32(−1+(B−L)×K)), where trunc32 rounds toward zero. Preserve full precision inside the two truncations. Apply the [radial profiles](#radial-stamp-profiles-and-pattern-generators) and take the maximum over the copies. + +In 52 further renders, this coordinate calculation predicts only 104,640/219,136 F32 pixels and 218,428/219,136 U16 pixels. The respective maximum errors are 8.34465027e−7 and one level. Both shapes use width N/2 and height N, with seed 4729+17j for row j starting at zero. Render each row in F32 and U16. These independent cases keep the general coordinate calculation open. + +| N | Center | Size | +|---:|---|---| +| 32 | (.25,.25) | (3,1.5) | +| 256 | (.75,.75) | (3,1.5) | +| 32 | (.3125,.6875) | (3,1.5) | +| 128 | (.1875,.8125) | (3,1.5) | +| 64 | (.5,.5) | (1,1) | +| 128 | (.5,.5) | (.75,.375) | +| 64 | (.375,.625) | (1.5,.75) | +| 64 | (.625,.3125) | (.6875,1.125) | +| 64 | (.5625,.4375) | (1.4,1.4) | +| 128 | (.50013,.49967) | (.71875,1.6875) | +| 128 | (.3125,.6875) | (2,.5) | +| 64 | (.1875,.3125) | (.618034,.953125) | +| 256 | (.5,.5) | (4,2) | + +For all 26 Gaussian renders in this table, acquiring the same package and capturing its outputs took 352.37 seconds in a long-running reference session and 24.01 seconds in a fresh one. Both captures produced byte-identical outputs at all 219,136 pixels. A second check repeated 13 color renders and obtained byte-identical readbacks at 62,976/62,976 pixels across 39 images. Each run restored the prior graph settings. + +### Fixed integer arguments and the UV debug marker + +The UV debug graph now matches all 217,088 pixels in its original 32 renders. The [square-root measurements](#uniform-square-roots-and-the-uv-debug-marker) previously had 194,522 exact. Sixteen additional renders with signed channel offsets match all 10,240 pixels. Six independently wired parents add 56,828/56,832 exact pixels. Compute Irradiance and Compute Ray Direction each retain all 217,088 exact pixels across 32 renders. + +| Debug hit UV storage | Renders | Exact RGBA pixels / compared | Maximum component error | +|---|---:|---:|---:| +| U8 | 13 | 120,832/120,832 | 0 | +| U16 | 9 | 18,429/18,432 | 1 level | +| F16 | 9 | 18,432/18,432 | 0 | +| F32 | 59 | 126,463/126,464 | .750555232 | + +For the 16 direct renders, use field channel c=((37x+41y+7xy+53×19+61c+5xc) mod 509)/508 as F32, with c from 0 through 3. Set the debug position to (.1875,.8125), sample index to 0 and count to 1. Sweep integer offsets −2 through 5 at 16² and 32² F32. Use seed 6481+17j+7t for offset index j and size index t, starting at zero. + +For the wired parents, drive the index and count through value processors. Use the following settings in row order. Within each row render the same field at 16² F32, 32² in U8/U16/F16/F32, 64² F32 with a 64×32 field, and 32² F32 with field values scaled by 2.5 and shifted by −.75. Use seed 4591+17j+13t for row j and render t. + +| Index | Count | Offset | Debug position | +|---:|---:|---:|---| +| 0 | 1 | −1 | (.1875,.8125) | +| 0 | 4 | −1 | (.671875,.328125) | +| 2 | 8 | −1 | (.25,.625) | +| 1 | 8 | 0 | (.421875,.765625) | +| 3 | 4 | 1 | (.71875,.15625) | +| 0 | 1 | 0 | (.375,.6875) | + +At (13,24) in the fourth row's 32² F32 output, the reference stores gray .1476394385. MaterialCraft also covers that pixel with the marker color (.43350938,.89819467,0,1). An isolated rectangle centered at (.42769217,.83190984), size (.13307922,.01), rotated .23604888 turns reproduces the extra pixel. In the final row at 32² U16 the reference stores red 15,899 at (9,19), (10,20) and (11,21). MaterialCraft stores 15,898. Both apps store 15,898 when an independent rectangle receives the literal red value .24259558. Integer storage also agrees on all 14,336 output pixels from 56 solid rectangle and uniform-color controls around half-level thresholds. + +Four independent color and grayscale rectangle series compare coverage at 16², 32², 64² and 128², using the two marker geometries above and offsets of up to a quarter pixel. A forward-transformed quadrilateral reproduces all 197,632 coverage decisions in 88 renders. In 80 additional edge-focused renders it matches 137,175/137,216. Snapping its screen vertices to the nearest 1/256 pixel gives 137,166/137,216. MaterialCraft's inverse-transform test gives 137,185/137,216. The maximum binary coverage error for each method on this second set is one. + +For the second set, position one edge of a rotated rectangle at an interior pixel center. Vary its length in [.1,.57], its signed width among −.03125, .009765625, .09765625 and .25, and its rotation among −.38200337, −1/6, .03125, .09375, .125, .21249999, .23604888, .3125 and .4782 turns. Shift each center axis by up to one F32 spacing. The 80 cases include both agreement and disagreement between the analytical coverage tests. They preserve a distinction that the first two geometries alone would miss. + +A folded scalar integer is ordered and converted to F32 using its unsigned 32-bit value. A runtime scalar integer has signed ordering and conversion. For example a folded −5 becomes 4,294,967,296 in F32. With a runtime input of −5 it becomes −5. Compare −32,768 with 2, −5 with −2 in both orders, −1 with 0 in both orders, equal operands, opposite signs and −2³¹ with 1,024. Test less, less-or-equal, greater and greater-or-equal with two literals, two runtime inputs, either operand fixed, and an equivalent literal subtraction. Both scalar integer encodings and the converted values are covered. All 84/84 returned F32 tuples match. Integer vectors of two, three and four lanes preserve signed conversion in all 12/12 additional typed controls. + +For the scope controls pack the four comparison flags into bits 0 through 3 and use bit 4 for float(left)>1,000,000. Divide by 32. With (−5,2), both fixed yield .875, a fixed left operand and runtime right operand yield .59375, and a runtime left operand with fixed right yields .09375. Use a property function, pixel processor, pattern function and value processor at 16² F32 and 32² in four formats with a positive and a negative argument. All 39,168 image pixels and 15 typed values match. + +An enclosing instance passes the fixed status of its scalar integer arguments through nested graphs and reusable functions. A value wire or exposed runtime control keeps its runtime status. Four original current-format packages with fixed, directly bound, computed and nested fixed inputs were saved by MaterialCraft and reopened in the reference app. All 20/20 typed F32 tuples match before and after saving and across applications, with error zero. + +Self-assignment remains open. Two separate programs assign an integer to the same identifier they read in the assignment, then read it again. With distinct graph identifiers and instruction IDs, 40/60 typed tuples match across those programs and four controls. The maximum F32 error in that capture was 2.65040882e25. Repeating the five identical seeds and inputs in the runtime self-assignment reproduced only one reference tuple. Assigning from a different input and assigning a constant to a local variable reproduced all 20/20 tuples, with error zero. + +### Uniform square roots and the UV debug marker + +The UV debug marker now cooks all **32** previously measured cases. The 27 cases that already cooked still match every pixel. Across all 32 renders **194,522/217,088 RGBA pixels** match. Maximum errors are 253 U8 levels, 0 U16 levels, 0 F16 and 1 F32. The five formerly rejected renders contribute 218/22,784 exact pixels. At 16² with index 0, count 1 and offset −1, the first output pixel has gray level .360237986 in the reference app and zero in MaterialCraft. At index 1, count 4 and offset 0, both store zero there. The input's first RGB and alpha components differ at this position. Both sibling roots, Compute Irradiance and Compute Ray Direction, retain 217,088/217,088 pixels each across 32 renders each, with error zero. [Wired sample inputs and seeds](#environment-rotation-and-wired-irradiance-samples) + +A uniform square root returns positive zero for negative values, either sign of zero, positive subnormals and NaN. Positive normal values use the ordinary F32 square root. For example, sqrt(1.375) has bits `3f9617e3` in a uniform function and `3f9617e2` in a runtime pixel expression. Positive infinity propagates in the comparisons. A literal square root preserves negative zero and accepts a positive subnormal. These distinctions apply before the output is stored. [Runtime pixel square roots](#runtime-pixel-square-roots) + +| Original controls | Renders | Exact stored pixels | Exact typed floats | Maximum absolute error | +|---|---:|---:|---:|---:| +| Runtime roots and equality predicates | 136 | 26,112/26,112 | 34/34 | 0 | +| Quotients by zero, literal predicates and positive controls | 52 | 9,984/9,984 | 13/13 | 0 | +| Raw literal roots | 28 | 5,120/5,376 | 7/7 | 0 | +| Pattern dimensions, offsets, rotation and color | 35 | 43,520/43,520 | — | 0 | + +For the first three rows evaluate the expression independently in a node parameter, pattern, Pixel Processor and Value Processor. The three images are 16² LUM32F. For the first row read the raw square root r and the separate expression [r=0]+2[r=r]. Use −.25, −1, −.00003125, −0, +0, the least positive subnormal, the least positive normal, .0625, .31875, .81234568, 1, 1.375, 2, 3, 7.03125, 1337.125 and 2⁻⁹⁸. Start at seed 4319 and add 11 per entry. + +For the quotient controls compute d=a/0 for a=0,−1,1 and output [sqrt(d)=0]+2[sqrt(d)=sqrt(d)]+4[sqrt(d)=d]. The three uniform results are 3, 3 and 6. For the literal predicate pack four equalities into bits 0 through 3. Compare the roots of F32 bits bf800000, 80000000 and 00000001 to zero, and the root of 3f801000 to 3f800800. The other positive and subnormal controls take F32 bits 3f801000, 40300000, 3fe20000, 007fffff, 00800001, 7f000010, 00800000, 3fb3d23a and 3f8081cd. Each series starts at seed 4457 and advances by 13. For the raw literals use −.25, −0, 00000001, 007fffff, 3f801000, 0/0 and −1/0, selected by a runtime index with seeds 4549+13j. The typed results have bits 00000000, 80000000, 1a3504f3, 1fffffff, 3f800800, 00000000 and 00000000. Only the grayscale maximum-blend square with literal −0 differs in the sign of zero at all 256 pixels. The reference image stores +0. The numeric maximum error is zero and the table counts bitwise matches. + +For the last row draw a parent square with size (.375,.5), color (.75,.25,.5,1), transparent black background and no tiling. Draw a second square on its upper-left child with local size (.25,.25), color (.25,.75,.125,1), maximum blend and zero roughness. Bind sqrt(t) to the parent's width with height .3125, the X pattern offset, the rotation, the X branch offset or the red channel, one graph per property. Keep Y offsets zero. Render t=.0625 and −.25 at 16² F32, then −.25 at 32² in all four formats, then .25 at 64² F32. Use seeds 4271+13j within each series. Before the square-root fix, the 25 negative-input cases reported a nonfinite function result. Both stamps now evaluate without an error. At 16² a negative input to width leaves the four child pixels visible. + +### Paths, caustics and cell fields after pattern sampling + +| Root | Renders | Exact pixels / compared | Maximum U8 / U16 levels | Maximum F16 / F32 error | +|---|---:|---:|---:|---:| +| Cells 4 | 29 | 215,500/215,552 | 0 / 53,506 | 0 / 0.491874591 | +| Cells 4, second package | 29 | 215,516/215,552 | 223 / 20,688 | 0.315917969 / 0.667963699 | +| Paths Trace | 19 | 58,213/58,624 | 120 / 30,822 | 0.756835938 / 1.22619528 | +| RT Caustics Base | 19 | 152,777/172,288 | 0 / 1 | 0.000122070312 / 6.67572021e-06 | + +The ten new path and caustic renders use the following (output side, input height, seed, format, setting). Use (16,16,4069,F32,default), (32,32,4093,F32,A), four at (64,64,4127,B) in U8/U16/F16/F32 order, (128,128,4159,F32,C), (32,16,4177,F32,A), (32,32,4201,F32,D) and (64,64,4229,F32,B). The four archived controls and five inventory cases are also included. An independent input repeated for stage inspection counts once. [Four-format inventory comparison](#four-format-inventory-comparison) + +For Paths Trace use the transformed five-point path for default, A and D and the seven-point path for B and C. The background stores ((37x+41y+7xy+583+61c+5xc) mod 509)/508 in channel c, starting at zero. In settings A/B/C/D enable corner tracing for A and B, vertex tracing for B and C, and set thickness to .75/1.625/2.75/.25. All four recorded stage outputs match at the default settings, in both A renders and in D. The six remaining renders first differ in the FX-Map that draws the path. At 64² in U8 the output differs at 18 pixels, including (0,0), (1,0) and (63,0). [Path buffer coordinates](#marked-variable-reads-in-path-and-mipmap-graphs) + +For RT Caustics Base supply height and noise H=((37x+41y+7xy+53j) mod 509)/508 at j=11 and 13. Store the normal field at j=12, using the normal and alpha construction below. For A/B/C/D use photon grid size 1/1/2/0, height scale .0625/.3125/.625/0, height position .125/.75/.375/.5, index of refraction 1.125/1.375/1.625/1, photon size 2/5.5/7.25/3 and jitter 0/.3125/.75/0. Place the light at (.3125,.6875) for A and B and (.75,.25) for C and D. The first differing stage is the photon FX-Map. At 64² in U16 it differs at (1,7) by one level and the final image matches. Across both matrices all 122,880 U8 output pixels match. U16 matches 8,185/8,192, F16 matches 8,181/8,192 and F32 matches 13,531/33,024. [Procedural normal fields](#normal-maps-panoramas-and-primitive-shapes) + +For the eight extra Cells 4 renders use the gray band value ((floor(x/3)+2floor(y/5)) mod 5)/4. Run defaults at 16²/71, four output formats at 64²/193, 128² F32/317, a 64×32 input at 64² F32/449 and a 64² F32 repeat at seed 503. The three changed settings use (scale, disorder, color source, pseudo-random seed) of (9,.21875,1,17), (17,.75,2,255) and (6,.4375,1,41) for the 64², 128² and rectangular inputs. Set disorder speed to .75/1.625/.3125 where exposed and disable non-square expansion for the rectangular input. The first package matches 41,216/41,216 band pixels. The second matches 41,206/41,216. Their earlier default and modular images still have differences. [Cell-field inputs and differing scatter stages](#tile-random-cell-fields-and-noise-upscaling) + +The debug hit UV root matches **194,304/194,304 RGBA pixels in 27 successful renders**, maximum error zero in each format. Five further renders with index 0, count 1 and index offset −1 produce a local nonfinite function error. The reference renders all five. Their 22,784 pixels are excluded from the successful-render total. [Wired sample inputs and seeds](#environment-rotation-and-wired-irradiance-samples) + +The position debug root's seven archived equal-resolution cases match all 136,192 pixels and the matched 128² preview adds 256/256 pixels at its 16² output. The spline preprocess root retains six exact integer counts and four 2048×16 renders with 131,072/131,072 exact RGBA pixels, maximum error zero. The zero-count reference timeout still has no comparable image. [Position debug preview](#tinted-stamp-offsets-and-alpha) · [Spline preprocessing with wired counts](#spline-preprocessing-with-wired-counts) + +### Integer and oblique directional blur + +| Root | Renders | Previous exact pixels | Exact / compared | Maximum error | +|---|---:|---:|---:|---:| +| `anisotropic_blur.sbs/anisotropic_blur` | 29 | 145,109 | 200,192/200,192 | 0 | +| `anisotropic_blur.sbs/anisotropic_blur_grayscale` | 29 | 165,764 | 200,192/200,192 | 0 | +| `blur_hq.sbs/blur_hq` | 18 | 65,482 | 171,264/171,264 | 0 | +| `blur_hq.sbs/blur_hq_grayscale` | 18 | 128,880 | 171,264/171,264 | 0 | + +On the 128² anisotropic color and grayscale inputs at angle .0625, intensity 17.5, anisotropy .625 and high quality, the first directional pass operates at intensity 10.5. Look at the raw U8 output of that pass. Before the change, 191/16,384 color and 2,125/16,384 grayscale pixels matched. On both inputs all 16,384 now match. A sheared sampling grid crosses the image boundary at a different position on the other axis. Wrap each tap at its own stored mip level and bilinearly sample the transverse shift. Recomputing the padded edge from the original bitmap still misses 675 color and 290 grayscale pixels, with a maximum error of two byte levels. + +An integer diagonal blur stores the first shear and each reduction at the destination depth. In the window normalization, adding half of 1/256 before the U8 store reproduces the measured byte controls. The measured U16 offset is approximately .4 of one stored level. To isolate the rounding, generate a 32² image whose rows divisible by eight contain 1/255, with all other rows zero. Set angle .125 and both axes to repeat. At intensity 19 the U8 output at x=0 for the first eight rows is `0,0,1,0,0,0,1,1`. At intensity 48 the U16 levels are `30,30,30,30,52,30,30,30`. For the edge test use the 128² signed [impulse-and-stripes field](#tiled-diagonal-directional-blur), angle .0625 and intensity 10.75. Pixel (0,65) is RGBA8 (0,0,57,116), (127,52) is (0,0,0,88), and (64,64) is (17,26,61,99). + +All four roots include the [archive and four-format comparisons](#tiled-diagonal-directional-blur), the independent 32² input and nine further fields. For those nine use `H=((37x+41y+7xy+61c+5xc) mod 509)/508` for color channel c. Use c=0 for grayscale RGB with opaque alpha. Render defaults at 16²/43. At 64²/157 render all four formats at intensity 5.25 with high quality. At 128²/293 use intensity 18.5 with high quality off. At 32²/463 use signed input `2.5H−.75` and intensity 10.25 with high quality. Apply the signed transformation to every channel. Repeat the 128² settings at 32²/599 with a 32×16 input and the 64² settings at seed 751. On the anisotropic roots the three changed intensity settings use anisotropy/angle .6875/.0625, .3125/.15625 and 1/−.21875. + +The anisotropic roots include twelve additional fields. Use `H=((73x+37y+11xy+157+43c+3cx) mod 1021)/1020`, with c=0 for the grayscale image. Columns for each case below give square side, seed, intensity, anisotropy, angle in turns, quality and output. Apply `2.5H−.875` to both signed inputs. + +| Side | Seed | Intensity | Anisotropy | Angle | High quality | Output | +|---:|---:|---:|---:|---:|---|---| +| 16 | 2833 | 10 | .5 | 0 | Off | F32 | +| 32 | 2953 | 10 | .5 | 0 | Off | U8 | +| 64 | 3001 | 24 | .8125 | .125 | Off | U8, U16, F16, F32 | +| 128 | 3049 | 17.5 | .625 | .0625 | On | F32, signed | +| 32 | 3119 | 5.375 | .375 | −.1875 | Off | F32, signed | +| 32 | 3203 | 0 | 1 | .03125 | On | F32 | +| 64 | 3251 | 27 | 0 | −.375 | On | F32 | +| 64 | 3271 | 24 | .8125 | .125 | Off | F32 | +| 32 | 3313 | 13 | .75 | .1875 | On | F32 | + +### Direct blur controls and remaining differences + +| Procedural control | Renders | Previous exact pixels | Current exact / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---:|---| +| Tiled eighth turns | 96 | 1,046,248 | 1,158,974/1,351,680 | 0 / 1 / 0.00048828125 / 3.57627869e-07 | +| Tiled .0625 and .21875 turns | 24 | 2,625 | 280,184/337,920 | 1 / 74 / 0.00146484375 / 0.00263102353 | +| Untiled .125 turns | 12 | 5,523 | 5,523/168,960 | 192 / 49,199 / 1.09570312 / 1.09612465 | +| Independent stripes and projected axial controls | 64 | 134,690 | 160,571/163,840 | 0 / 0 / 3.81469727e-06 / 5.96046448e-08 | +| Code patches, low pulses and translated row fields | 80 | 1,200,293 | 1,454,692/1,495,040 | 0 / 1 / — / 1.78813934e-07 | + +The [impulse and stripes controls](#tiled-diagonal-directional-blur) specify the input, strength and seed for the first three rows. In the 96 tiled eighth-turn renders, all 163,840 RGBA8 pixels match. Of 163,840 RGBA16 pixels, 90 still differ by one level. Off-axis filtering has further differences at .21875 turns. Untiled boundaries and non-square processing grids still use the direct sampling path. + +For the independent stripes use U8 inputs at (side, radius) (32,2.375), (64,3.125), (64,6) and (32,5.375). Set R=(53x+29x²+19) mod 256, G=(31y+7y²+17) mod 256, B to 208 or 23 according to the parity of x+y, and A to 127. The second field uses 1 or 2 by x parity, 9 or 2 by y parity, (x+3y) mod 17 and 127+(x(y+1) mod 3). Set intensity to 256×radius/side at .125 turns. For the first field also render horizontal and vertical controls with radius .5+(radius−.5)/√2, across all four formats at seeds 3359 through 3362. + +For the code patches, assign k=16⌊y/16⌋+⌊x/16⌋ on a 256² field and store channels (k,k+1,k+67,k+129) modulo 256. The other inputs are 64² row fields or a 32² one-level pulse across four base levels. One row field uses `((31y+7y²+17) mod 128)+32+c`. The other uses `U=((117y+53y²+17) mod 251)`, with channels U, (U+12) mod 256 and the transposes of both. In the pulse field add one to (0,4,45,184) every eighth row. For the U16 inputs, scale each code by 257 and add 29c below code 255. Use the same four radii at .125 turns and seeds 3433–3436 in field order. Store each U8 source in U8, U16 and F32, and each U16 source in U16 and F32. All 299,008 U8 output pixels in this set match. + +The 38 color and grayscale anisotropic renders compare 304 graph images read at intermediate nodes and at the input and output bridges. 2,560,000/2,560,000 pixels match, maximum stored-component error 0. Six other roots with a reachable directional blur retain all 790,528 exact pixels in 52 renders. + +Four additional large and rectangular-source anisotropic stage captures match 278,528/278,528 pixels in 32 images. Reloading the package for each color or grayscale pair took 506.09 seconds in total. Repeating the same four captures with the open package took 4.14 seconds. All raw readbacks were byte-identical. The graph size, seed, numeric controls, source bindings and output format were restored between captures. + +The high-quality color and grayscale blur graphs each have 65 observed images across their 128² changed input and four archived controls. The final outputs match 131,072/131,072 pixels in each graph. Across all observed images, color matches 1,703,770/1,703,936 and grayscale 1,703,876/1,703,936. At the default 256² input, four directional passes and one intermediate blend differ by at most one U8 level in each graph. + +### Bitmap stamp filtering and compositing + +A quadrant with an image pattern uses automatic bilinear mip filtering when `imagefiltering` is omitted or zero. Mode 1 selects the original level with bilinear filtering. Mode 2 selects the nearest texel. Filter taps outside the bitmap use transparent black. Intermediate reductions store each level at the source precision, which matters even when the final output is F32. A grayscale stamp needs a grayscale image and a color stamp needs a color image. Wiring the opposite kind leaves the background intact. + +For an original 64² image, set the byte at `(x,y)` to `(47x + 31y + 7xy + 13) mod 256`. For the signed F32 input, divide that field by 255, multiply by 1.75 and subtract 0.375. Keep the input at 64² and render the quadrant at 32², 64² and 128². A centered stamp of size (0.375, 0.375) produces F32 bits `3f4ea0cf`, `3f5e5ade` and `3f62e2e3` at pixel (32,32) of the 64² output for modes 0, 1 and 2. To distinguish horizontal and diagonal mip selection, use size (0.17, 1), offset (0.07125, −0.0390625) and rotations of 0.0625 and 0.125 turns. The selected levels are 2 and 3 at 64². Bilinear modes use the measured four-tap weights in [stored texture filtering](#multi-directional-warp-and-intermediate-storage). + +| Original procedural control | Renders | Previous exact pixels | Exact / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---:|---| +| Hash, ramp, checker and flat stamps from 16² to 128² | 150 | 496,615 | 683,609/695,040 | 221 / 56,797 / 0.866622925 / 1 | +| Fixed 64² byte and signed F32 inputs, eight stamp transforms | 192 | 902,752 | 1,221,604/1,228,800 | — / 65,535 / — / 1.66078436 | +| Twelve anisotropic transforms, three modes and the omitted setting | 144 | 752,204 | 1,029,747/1,032,192 | — / — / — / 0.996078432 | +| Tint, opacity, three blend modes and premultiplication | 90 | 49,150 | 92,132/92,160 | 0 / 0 / 0 / 5.96046448e-08 | +| Matching and crossed grayscale and color sockets | 60 | 29,249 | 60,864/61,440 | 0 / 1 / 0 / 5.96046448e-08 | +| Four image pins with fixed selectors | 30 | 5,632 | 7,680/7,680 | — / — / — / 0 | + +The automatic mip estimate selected the observed level in 81 angle and scale combinations, 128 additional independently chosen transforms, and 24 rectangular cases with sides of 32, 64 and 128. The corresponding F32 bit comparisons give 331,582/331,776 (maximum 0.00355535746), 523,951/524,288 (maximum 0.00379943848), 73,702/73,728 (maximum 0.000717163086) respectively. Oblique sample positions still have pixel-level differences. To isolate the nearest-filter error, replace the stamp with a horizontal gradation, then rotate it by a quarter turn and swap its dimensions to measure the other coordinate. Sampling the original bitmap with the two measured coordinates and a zero border reproduces **408,576/408,576 F32 pixels** in 57 renders of 19 geometries, maximum error zero. + +For the tint tests, the 32² input channel `c` is `1.5 × (((47x + 31y + 7xy + 13 + 69c + 3xc) mod 256) / 255) − 0.25`. Use opacity 0.375, tint (0.75, 0.375, 1, 0.625) and background (0.25, 0.375, 0.625, 0.8125). Grayscale applies the mean RGB tint. Color mode 0 adds the premultiplied RGB contribution and accumulates alpha. Modes 1 and 2 composite over the background. Signed alpha and premultiplied input are covered. The 28 F32 alpha differences in this measurement were each 0.0000000596046448. The [signed blend controls](#signed-bitmap-blend-precision) subsequently close all 28. The fixed four-pin renders now match the raw F32 samples as well as the slot selections. + +| Root | Renders | Exact / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---| +| Make It Tile Patch | 9 | 98,161/132,096 | 2 / 318 / 0.00476074219 / 0.00485236943 | +| Make It Tile Patch Grayscale | 9 | 117,553/132,096 | 2 / 150 / 0.00228881836 / 0.00228885561 | +| Arc Pavement | 27 | 206,904/211,200 | 0 / 0 / 0 / 9.87946987e-06 | + +For both patch roots, retain the [four-format parameter matrix](#four-format-inventory-comparison), the independent 32² render and the four original 128²/256² controls. The changed case uses mask size 0.8, precision 0.7, warping 0.1, pattern width/height 120/160, disorder 0.25, size variation 0.15, two octaves and rotation 0.125. Arc Pavement previously matched 202,429/211,200 pixels in the [same cases](#uniform-arc-tangents-and-pavement-rotations). All 123,904 U16 pixels, 8,192 U8 pixels and 8,192 F16 pixels now match. The soft, bell, pyramid and capsule patterns at seed 547 and three image choices at seed 607 account for the 4,296 remaining F32 differences. + +Both patch graphs first differ in a fixed 32² U16 mask. One Gaussian stamp, size (1.4, 1.4) and opacity 1.00343001, matches 1,020/1,024 pixels. The four differences are one level each at (24,7), (11,11), (7,24) and (24,24). The color graph also has an independent U8 directional blur difference upstream. At the default 128² graph size, this blur matches 4,087/4,096 pixels, maximum one level. + +Six independently authored files with format header `1.1.0.202502` passed through ordinary `file.saveAs` and reopened in the reference app. Four files covered omitted and explicit filtering, and two covered tinted color with and without premultiplication. Comparing original and saved output in that app gives **96,256/96,256 exact pixels in 22 renders**, maximum zero. See the [earlier file handoff](#image-selection-in-saved-pattern-graphs) for the older-header restriction. + +The two Alveolus roots use procedural Gaussian stamps. In each root, all eight stage comparisons place the first differing pixel in the FX-Map. On the default 128² and 256² renders its half-width U16 output matches 8,096/8,192 and 32,548/32,768 pixels respectively, maximum one stored level. Isolate the two stamps at (0.25, 0.25) and (0.75, 0.75), local size (3, 1.5), opacity 0.995 and maximum blending. Independently storing the reference F32 result as U16 reproduces the observed U16 values. The coordinate calculation remains open for both roots. + +### Signed bitmap blend precision + +The bitmap stamp accumulator retains three guard bits below the aligned single-precision significands. A weighted component and its addend each keep a low bit when discarded digits are nonzero. When cancellation removes two or more leading bits, the accumulator drops the low guard bits before storing the result. In additive mode a zero source contribution preserves the background's zero sign. In the over modes a transparent source scales the background by its remaining coverage. + +| Procedural inputs | Renders | Previous exact pixels | Exact / compared | Maximum error | +|---|---:|---:|---:|---:| +| Constant tint and background, grayscale and color | 90 | 92,132 | 92,160/92,160 | 0 | +| Signed color over a varying background | 96 | 94,568 | 98,304/98,304 | 0 | +| Independent exponent ramps and near cancellation | 54 | 66,248 | 96,768/96,768 | 0 | +| Positive and negative zero with opposite signs | 6 | 5,532 | 6,144/6,144 | 0 | + +The [90 tint and opacity controls](#bitmap-stamp-filtering-and-compositing) include U8, U16, F16 and F32 output. For the 96 two-image controls use the same 32² signed RGBA stamp. Set background channel c to `3.55 × fract(((53x + 29y + 11xy + 37) mod 257)/256 + .117c + .005xc) − 1.35`. Cross all three blend modes and both premultiplication settings with four output formats. Use opacity/tint pairs .427/(.487,.683,.237,.563), .375/(.75,.375,1,.625), .923/(1.375,.125,−.125,1.1875) and 1.333/(−.375,1.875,.439,.271). For pair j and blend b use seed 1787+13j+b. + +For the 54 independent F32 renders use sides 16, 64 and 32, and seeds 2683+17i+7j+b for size index i, tint index j and blend b. Before cancellation, source channel c is `(((31x+83y+23xy+47c+13) mod 1021)/509−1) × 2^(((3x+7y+11c) mod 19)−9)`. The background is `(((73x+41y+17xy+31c+67) mod 1019)/503−1) × 2^(((5x+7y+3c) mod 23)−11)`. Use opacity/tint pairs .63125/(.4375,−.8125,.733125,.93375), .14875/(1.21325,−.796875,.34375,.713125), and 1/(1,1,1,1). At 32² set source alpha to `1.5 × (((7x+59y+13) mod 509)/508) − .3125`. With F32 arithmetic, place the background at `−V/(1−A+1e−25) × (1+2^−12)` where `V` is the premultiplied, tinted source contribution, `A` is its coverage and `abs(1−A)>1e−5`. At smaller denominators use the original background RGB and alpha .5. The six separate signed-zero renders use a 32² repeating table (+0,−0,1,−1,.5,−.5,2,−2), all three blends, both premultiplication settings and seeds 2729+b. Equality for floating outputs includes the sign bit. + +A single nearest-filtered premultiplied texel at full opacity reproduces the former rounding error. Use F32 source bits `baf97631 c061d2bc bc4a2f47 be8c58b1` and background `3ac3d70f 4031485b 3c1eb9a8 3e5c5bb0`. The four over-mode output words are `34f98400 3a61d400 364a3400 388c5c00`. The additive alpha word is `388c6000`. + +Replaying 206 renders across 18 affected roots gives 2,131,360/2,246,400 exact pixels. The pattern-package [Tile Random Color matrix](#tile-random-image-and-soft-patterns) gains one F32 pixel and now matches **268,904/276,736** in 40 renders. Its maximum component errors are 163 U8, 59,666 U16, .0478515625 F16 and .90265286 F32. The image-rotation and texel-boundary differences remain. `brick_generator.sbs/resources/Tile`, `histogram_tools.sbs/histogram_compute` and `pattern_brick_generator.sbs/resources/Tile` retain 233,984/233,984 exact pixels in 40 renders combined. + +### Tile Random image and soft patterns + +The pattern-package Tile Random and Tile Random Color render the background by itself when the pattern selector is zero. At 64²/827 all 4,096 color output pixels match the original background. Use selector 1 for an image stamp. At 64²/2273, switching from filter 0 to 1 or from 1 to 2 changes 1,187 reference pixels in both roots. Both background and image pins contain procedural fields. + +| Root | Renders | Exact / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---| +| Tile Random | 32 | 238,215/243,968 | 165 / 60,395 / 0.0498046875 / 1 | +| Tile Random Color | 40 | 268,904/276,736 | 163 / 59,666 / 0.0478515625 / 0.90265286 | + +The original 20 grayscale renders still match 176,384/176,384 pixels. The color root matches 209,152/209,152 across the same settings, eight additional selector-zero controls, and its archive and inventory cases together. The twelve additional renders per root expose the outstanding differences. + +For grayscale use H=((73x+37y+11xy+k) mod 1021)/1020, with k=29 on the pattern pin and 72 on the background. For RGBA add 43c+3cx inside the modulus, with c=0,1,2,3, k=29 on the background and 72 on the pattern. Use (4,5) tiles, pattern-specific value .3125, rotation randomness .375, shape rotation .125, interstice .1875 and split threshold .625. Render all three image filters at 64²/2273 F32, plus nearest at 128²/2311 U16, bilinear at 64²/2333 U8, and automatic mips at 32²/2357 F16. Render at 64²/2371 with filter 1 and blend mode 1, and at 32²/2393 with filter 2, blend mode 1 and signed inputs 2.5H−.875. For the two color cases use tint (.75,.375,1,.625), tint randomness (.25,.125,.375,.25) and background (.25,.375,.625,.8125). At 64²/2203 use bell (5), Gaussian (6) and pyramid (8). At 128²/2221 use brick (9). Maximum F32 errors for the three soft patterns are 2.14576721e−6 across the two roots. The U16 brick cases differ by one level at 70 grayscale and 216 color pixels. + +A coordinate-coded color stamp isolates the effect of rotation on image sampling. Store R=x+1, G=y+1, B=128 and A=255 in a 64² U8 image and wire transparent black to the background. At 64²/2273 with the settings above and nearest filtering, both cooks draw the same 1,187 pixels. Of those, 594 sample a different quarter-turn of the image. Removing only the random pattern rotation gives 4,096/4,096 exact F32 pixels, maximum zero. With zero interstice and zero size randomness, all four fixed pattern rotations match for (1,1), (1,2) and (2,1) tiles. With (4,5) tiles and fixed rotation zero, 1,560 pixels differ by one source texel horizontally. Across the 30 rotation controls the result is 108,653/122,880 exact F32 pixels, maximum component error 0.247058838. + +### Connected bitmap pattern roots + +Repeat the four original root settings and the [five inventory cases](#four-format-inventory-comparison) after the [bitmap filtering change](#bitmap-stamp-filtering-and-compositing). The table counts complete pixels across all output channels and gives maximum stored-component errors. A dash marks formats with no completed comparisons. The three dirt roots exceeded the pattern execution budget in all five additional cases. Their counts cover the four completed original renders. Arc Pavement, the two patch roots and the two pattern-package Tile Random roots have their wider results above. + +| Package / graph | Completed renders | Exact / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---| +| `noise_dirt_1.sbs/dirt_1` | 4 | 94,914/98,304 | — / 538 / — / — | +| `noise_dirt_1_v2.sbs/dirt_1` | 4 | 98,263/98,304 | 1 / — / — / — | +| `noise_dirt_2.sbs/dirt_2` | 4 | 97,737/98,304 | — / 21 / — / — | +| `paths_tools.sbs/paths_trace` | 9 | 18,297/18,432 | 120 / 30,822 / 0.62109375 / 1.22619528 | +| `pattern_splatter_circular.sbs/splatter_circular` | 9 | 130,917/132,096 | 223 / 57,311 / 0.874511719 / 0.921568625 | +| `pattern_splatter_circular.sbs/splatter_circular_color` | 9 | 130,678/132,096 | 254 / 65,535 / 0.996078491 / 0.996078431 | +| `pattern_tile_generator.sbs/tile_generator` | 9 | 130,546/132,096 | 0 / 1 / 0 / 0 | +| `pattern_tile_generator.sbs/tile_generator_color` | 9 | 128,338/132,096 | 0 / 1 / 0 / 0 | +| `pattern_weave_2.sbs/weave_2` | 9 | 130,222/132,096 | 1 / 59 / 0.0009765625 / 0.000900268555 | +| `radial_blur.sbs/radial_blur_grayscale` | 9 | 109,921/132,096 | 1 / 14 / 0.00048828125 / 0.000137329102 | +| `splatter.sbs/splatter` | 9 | 132,084/132,096 | 0 / 91 / 0 / 1.52587891e-05 | +| `splatter_circular.sbs/splatter_circular` | 9 | 130,443/132,096 | 222 / 57,311 / 1 / 1.00000006 | +| `splatter_circular.sbs/splatter_circular_color` | 9 | 130,794/132,096 | 247 / 65,535 / 0.96862793 / 0.996078431 | +| `splatter_color.sbs/splatter_color` | 9 | 132,066/132,096 | 0 / 59 / 0.000122070312 / 0.000137329102 | +| `tile_generator.sbs/tile_generator` | 9 | 129,318/132,096 | 0 / 1 / 0.00048828125 / 4.88758087e-06 | +| `tile_generator_color.sbs/tile_generator_color` | 9 | 127,043/132,096 | 0 / 1 / 0.0009765625 / 4.88758087e-06 | +| `tile_random.sbs/tile_random` | 9 | 105,004/132,096 | 223 / 57,311 / 1 / 1.00000006 | +| `tile_random.sbs/tile_random_color` | 9 | 105,004/132,096 | 250 / 65,535 / 1 / 1.00000006 | + +### Multi-directional warp and intermediate storage + +The color and grayscale multi-directional warps each match **175,360/175,360 pixels** across the 19 [root cases](#directional-warp-orientation-and-input-precision), maximum error zero. Each root contributes 122,880 U8, 8,192 U16, 8,192 F16 and 36,096 F32 pixels. The two non-uniform blur sample roots retain the same exact counts. + +For each multi-directional root, inspect the four original renders, the 64² changed F32 render, A in U8 and F32, B in F32 and signed D in F32. Compare the 27 raw graph images per render, including the input and output nodes. Across both roots all **7,796,736/7,796,736 pixels in 486 images** match, maximum zero. This includes 4,620,288 pixels in 288 individual directional warps. Before the change, one grayscale warp at angle .625 and intensity 4 differed by one byte at four 64² pixels. This propagated into all four output formats. + +Compute horizontal direction from the sine of the angle in radians plus a quarter turn. Round the radian sum to single precision before evaluating the sine. The measured root cases agree when narrowing each sine toward zero and fusing the displacement with the pixel center. A constant warp intensity can exceed the previous hard slider limit of 1,088. Its magnitude changes sampling coordinates and leaves the tap count fixed. + +| Direct warp measurements | Renders | Exact pixels / compared | Maximum error | +|---|---:|---:|---| +| All source, map and output format combinations | 64 | 262,144/262,144 | 0 | +| Unequal dimensions with inherited warp size | 70 | 412,160/412,160 | 0 | +| Unequal dimensions with explicit warp size | 70 | 340,480/340,480 | 0 | +| Sixty size controls and thirty X/Y position ramps | 90 | 953,472/953,472 | 0 | +| Eight direction and wrapping configurations | 224 | 1,089,513/1,089,536 | 1 U8, 48 U16, .00241088867 F16, .005859375 F32 | +| Amplified X/Y position ramps | 72 | 274,432/294,912 | 1.96875 F32 | + +For the 64 format combinations, use the [orientation source and mask](#directional-warp-orientation-and-input-precision) at 16×32 and 32×16 respectively. Round integer fields to the nearest stored level. Use 1.75H−.375 for floating source images and M for floating masks, rounding the F16 file to half precision. Render at 64² with intensity 17, angle .125, both axes tiled and seed 961. Independently cross the source, mask and output in U8, U16, F16 and F32. At each resampling step use the wider of that input's format and the output, in the order U8, U16, F16, F32. With F32 source and map, output bytes at (0,0), (7,13), (14,5), (32,32), (63,63) are 0, 172, 114, 0 and 1. + +The [large-displacement inputs](#directional-warp-tiling-and-unequal-input-sizes) now use all three authored intensities. The remaining five amplified Y ramps differ at −.3125, .9375 and 2.073125 turns. The ordinary 224-render matrix retains 14 differing pixels at angle zero and nine at −.3125. These primitive results delimit the root measurements above. + +### Directional warp tiling and unequal input sizes + +A graph with horizontal-only tiling previously clamped both axes when the warp angle and intensity were constants. At (0,0) in the 64² byte-field probe the F32 value was .02745098. Passing both graph tiling flags through the evaluator gives the measured .532509327. All 28 horizontal-only renders now match. The full [single-warp matrix](#directional-warp-orientation-and-input-precision) matches 1,089,472/1,089,536 pixels across 224 renders. The maxima are 1 U8, 288 U16, .00439453125 F16 and .0048828125 F32. + +The warp applies the displacement to the output pixel center with one fused multiply-add per axis. A source whose dimensions each lie between the output dimension and twice that dimension supplies the taps directly. Other sources pass through stored factor-two levels. An axis within one step of its target waits until both axes can take their final step together. For example, an 8×32 source at 128² goes through 16×64, 32×64, 64×64 and 128×128. The mask follows the same size rule and is sampled at output pixel centers. + +| Measurement | Renders | Exact pixels / compared | Maximum U8 / U16 / F16 / F32 | +|---|---:|---:|---| +| Unequal original source and map, warp size inherited from source | 70 | 392,072/412,160 | 13 / 723 / .012451171875 / 0 | +| Same inputs with the warp size relative to the graph | 70 | 319,070/340,480 | 43 / 10,985 / .012451171875 / 0 | +| X and Y position ramps, square and rectangular | 30 | 79,872/79,872 | F32 0 | +| Unequal dimensions with a unit mask and F32 output | 60 | 873,600/873,600 | F32 0 | + +For the 60 unit-mask renders, use the original grayscale byte field from the [orientation probes](#directional-warp-orientation-and-input-precision). Bind a white mask at the source dimensions, set angle to .125 turns and intensity to 17. Set both axes to repeat. In order, test source dimensions 8×16, 8×32, 4×32, 128×16, 128×32, 128×8, 32×256, 256×128, 8² and 256² at output sides 8, 16, 32, 64, 128 and 256. Use seeds 947 through 956 in source order. For the two 70-render matrices, use the five source/map pairs and seeds 863+17j+n, with pair index j from zero and requested side n. Both U8 and F32 sources match in F32 output. Cases combining higher-precision sources with narrower outputs still differ. + +All ten additional root inputs now match for both multi-directional warps. Across the full 19 cases, color matches **175,339/175,360** with a one-level U8 maximum and zero elsewhere. Grayscale matches **175,344/175,360**, with four changed-case pixels differing in each format. Maxima are 1 U8, 257 U16, .00390625 F16 and .00392156839 F32. Both non-uniform blur roots retain **175,360/175,360** exact pixels each. + +To amplify small direction differences, bind separate 64² F32 fields returning x and y with an F32 unit mask and both axes tiled. For angles 0, .25, .5, .75, .125, .375, .625, .9375, .073125, −.3125, 1.1875 and 2.073125 turns, use intensities 4,096, 262,144 and 2,097,152. The 72 renders match 24,576/294,912 pixels, maximum 61.34765625. The resolved MaterialCraft intensity is 1,088 for all three authored values. At .625 turns and intensity 2,097,152 the reference center (32,32) reads x=56.53125 and y=56.34375. The two coordinates distinguish the direction components independently. + +### Directional warp orientation and input precision + +Both non-uniform blur sample roots now match **175,360/175,360 pixels each**, maximum error zero. Previously their nine baseline cases matched 96,971/132,096 grayscale and 50,664/132,096 color pixels. Directional warp now samples positive angles toward increasing image Y, scales distances in pixels by the shorter image side divided by 256, and bilinearly filters the image at its stored precision. + +| Root | Renders | Exact pixels / compared | Maximum error by storage | +|---|---:|---:|---| +| Non-uniform blur grayscale sample | 19 | 175,360/175,360 | 0 in all four formats | +| Non-uniform blur color sample | 19 | 175,360/175,360 | 0 in all four formats | +| Multi-directional warp color | 19 | 175,329/175,360 | 1 U8, 257 U16, .00390625 F16, .00392156839 F32 | +| Multi-directional warp grayscale | 19 | 175,339/175,360 | 1 U8, 257 U16, .00390625 F16, .00392156839 F32 | + +Each row includes the archived renders, the four 64² formats, the independent 32² input and ten additional comparisons. For those ten, use an original source with channel c = ((41x+53y+7xy+29+37c+11cx) mod 1021)/1020 and mask M = ((11x−17y+3xy+401) mod 509)/508. Use c=0 for gray. Round both to the nearest byte except for the signed case, which uses 1.75c′−.375 with c′ the source channel value, and M at F32. All color channels including alpha count toward a matching pixel. + +| Case | Side, format, seed | Blur parameters (intensity, samples, angle, asymmetry, anisotropy, inner rotation) | Multi-directional parameters (intensity, angle, mode, directions) | +|---|---|---|---| +| Default | 16, F32, 137 | Defaults | Defaults | +| A | 64, all four formats, 251 and again F32 at 827 | (2.5, 6, .1875, .375, .5, .28125) | (7.25, .1875, 0, 4) | +| B | 128, F32, 353 | (1.75, 4, −.125, .125, .75, .0625) | (3.5, −.125, 5, 2) | +| C | 32, F32, 479 | (7, 2, .3125, .625, .25, −.125) | (11.75, .3125, 6, 1) | +| D | 32, signed F32, 557 and 64, byte source with F32 output, 733 | (4, 8, −.0625, .5, .375, .15625) | (4.25, −.0625, 10, 4) | + +For a single directional warp, bind the same gray field and mask in U8, U16, F16 and F32. Use signed source values for float storage. For each source format and parameter row j, use a constant .625 mask at 16² F32, then varying masks at 32² F32, 64² U8/U16/F16/F32 and 128² F32. Seeds are 751+11j+d+17i with d the source format (0–3) and i the size/format index (0–6). Test (angle in turns, intensity) of (0,0), (0,7), (.25,11), (.125,17), (−.1875,−5.75) and (.073125,11.25) with both axes tiled, then (.1875,25) with neither tiled and (−.3125,21.5) with only X tiled. The 224 renders match **1,086,456/1,089,536 pixels**. Maximum errors are 255 U8, 65,535 U16, 1.070373535 F16 and 1.415079325 F32. The single-axis graph setting accounts for 3,016 differing pixels. + +With a constant unit mask and separate F32 images returning x and y, all **79,872/79,872** pixels match across 30 renders, maximum error zero. Use intensity 16 and angles 0, .25, .125 at 64², 32×16, 16×32, 128×32 and 32×128. The measured diagonal shifts are .70703125 pixels at the two 16-pixel short sides and 1.4140625 at the 32-pixel short sides. For unequal source/map dimensions use (32×16,64²), (128×64,32×16), (64²,16×32), (128²,32²), (16²,128²), U8 or F32 inputs, angle .125 and intensity 17. The seven output requests above, using the varying mask throughout, match **294,268/412,160 pixels** across 70 renders. The corresponding maxima are 255, 65,535, 1.201248169 and 1.202106290. + +Six other inventory roots contain the same primitive. Replaying their archived outputs, precision sweeps and independent inputs gave the following results. For Messy Fibers 4 the archive has three renders. Each other row has four. Integer maxima below are stored levels. + +| Root | Renders | Exact pixels / compared | Maximum U8 / U16 / F16 / F32 | +|---|---:|---:|---| +| creased.sbs/creased | 9 | 80,098/132,096 | 1 / 637 / 0.00048828125 / 0.0001525878906 | +| fluid.sbs/fluid | 9 | 2,715/132,096 | 7 / 16338 / 0.02526855469 / 0.02534788847 | +| messy_fibers_4.sbs/messy_fibers_4 | 8 | 56,296/115,712 | 1 / 354 / 0.00439453125 / 0.01023879647 | +| noise_creased.sbs/creased | 9 | 91,206/132,096 | 1 / 782 / 0.00048828125 / 1.531839371e-05 | +| noise_fluid.sbs/fluid | 9 | 5,620/132,096 | 5 / 11756 / 0.01708984375 / 0.01704069972 | +| pavement_1.sbs/pavement_1 | 9 | 59,168/132,096 | 255 / 65535 / 1 / 1 | + +## 2026-11-18 root comparisons + +### Pixel Processor products and sums + +Use the signed RGBA32F field and position ramp specified under [3D linear gradient](#3d-linear-gradient). Each arithmetic probe has a nearest-sampled RGBA input, seed zero and a 128×128 float output. Compare the raw output in the 16.0.7 Direct3D 11 reference app with the MaterialCraft CPU cook. A pixel counts when all channels match. Integer errors in this log use stored levels. Floating errors use absolute differences. + +| Pixel expression | Exact pixels / total | Maximum error | +|---|---:|---:| +| `R*G+B`, `B+R*G`, `R*G-B`, `B-R*G` | 16,384/16,384 each | 0 | +| `R*G+B*A`, `R*G-B*A` | 16,384/16,384 each | 0 | +| Runtime product plus .375, runtime channel times .3 minus B, literal product plus R | 16,384/16,384 each | 0 | +| Shared product read directly and in a sum, shared product used only in sums, vector times scalar plus vector | 16,384/16,384 each | 0 | + +Rounding each multiplication separately matched 11,640 additions, 11,721 left subtractions, 12,098 two-product additions and 12,052 two-product subtractions out of 16,384 each. The largest difference was 1.907349e-6. The CPU evaluator now fuses the dynamic product into its immediate sum in pixel scope. A literal product or a product also read as a standalone value retains its rounded value. When both operands are products, the left product fuses. + +Repeat the November 17 **3D linear gradient** cases with that change. At 256² and 512², the default UV, default world and oblique world gradients each match 65,536/65,536 and 262,144/262,144 LUM32F pixels, maximum error zero. Seed 42 at 128² matches all 16,384 default UV pixels and all 16,384 oblique pixels in each of LUM8, LUM16 and LUM16F. Contrast .6 still differs. Exact counts are 24,206/65,536 and 96,824/262,144 with a maximum error of 2.384186e-7. For the signed input above, a direct `1/G` probe matches 14,182/16,384 float pixels. All finite differences in that probe are one unit in the last place. + +With the original shared lookup described under [basic and ridged 3D Perlin](#basic-and-ridged-3d-perlin), **basic 3D Perlin** now matches 65,536/65,536 pixels at 256² and 16,384/16,384 in each of the other six cases, including changed LUM16, LUM16F and LUM32F. All maximum errors are zero. With the applications' respective stock lookups, only 173/16,384 and 663/65,536 LUM8 pixels match. Both maxima are 203 levels. + +### Runtime reciprocal and 3D gradient contrast + +The twelve wired 3D linear gradient cases listed under [3D linear gradient](#3d-linear-gradient) now match **1,376,256/1,376,256 pixels**, maximum error zero. This includes all 65,536 and 262,144 LUM32F pixels at contrast .6 and all four measured output formats. An exposed contrast of .6 gives the float32 denominator `0x3ecccccc`. Its runtime reciprocal is 2.5. With a literal expression, the reciprocal is the next float above 2.5. + +For a standalone Pixel Processor, nearest-sample a linear RGBA32F input and output the reciprocal of one channel at its original dimensions. Five fields match **671,744/671,744 LUM32F pixels**, maximum error zero. Use seed zero. For the 128² case take G from the signed field under [3D linear gradient](#3d-linear-gradient). Construct the remaining four fields from float32 bits at row-major pixel index `i`, repeated in RGB. + +| Dimensions | Input bits | Exact pixels / total | +|---|---|---:| +| 256² | `0x3f800000 + 128*i` | 65,536/65,536 | +| 256² | `(125 << 23) + floor(3*2^23/5) - 32768 + i` | 65,536/65,536 | +| 512² | Use `h=(747796405*i+2891336453) mod 2^32` as below | 262,144/262,144 | +| 512² | Use `h=(1013904223*i+341937) mod 2^32` as below | 262,144/262,144 | + +For the 512² fields, use the low 23 bits of `h` as the fraction, `7 + (37*((h >> 22) XOR i)) mod 241` as the biased exponent, and bit 2 of `i` as the sign. MaterialCraft derives a quadratic for each of 128 mantissa intervals from the mathematical reciprocal. The measured fixed-point square retains partial products through fractional bit 15. The literal division path retains its original rounding. A separate 32² RGBA32F probe emits contrast, denominator, reciprocal and half the reciprocal minus one half. All nine runs match 1,024/1,024 pixels each, including exposed values .3, .35, .51, .6, .625, .875 and .99, an image input and a literal. + +With Position disconnected, both apps return zero in U8 and U16 and quiet NaN in floating storage. At 32² with seed zero, the 1,024 raw samples are respectively `0x00`, `0x0000`, `0x7fff` and `0x7fffffff`. At 64² with seed 42 the F32 result has the same NaN bits at all 4,096 pixels. The five disconnected cases match **8,192/8,192 bit patterns**. Maximum finite error is zero for the two integer runs. The float runs contain only NaNs, for which a numerical maximum error is undefined. Across the 12 wired and five disconnected cases the root matches **1,384,448/1,384,448 pixels**. + +Four independent 32² image functions distinguish output storage from scalar parameter validation. Bind an RGBA32F field with `R=(x mod 7)-3`, `G=1` on every fourth row starting at zero and `G=0` elsewhere, `B=0` and `A=1`. Output, in turn, B/B, A/B, R/B and R/G. In U8, U16, F16 and F32 each run matches 1,024/1,024 stored samples, **16,384/16,384** overall. The mixed R/G float images each contain 256 finite values, 120 quiet NaNs, 288 positive infinities and 360 negative infinities. Every special value matches bit for bit and the maximum finite error is zero. Integer storage maps NaNs and negative infinities to zero and positive infinities to white. + +### Resizing images bound to graph inputs + +Bind a 128² linear image directly to a graph input, set the input bridge to the indicated storage format, and nearest-sample its output at pixel centers into RGBA32F. The CPU cook and the reference app match **4,534,272/4,534,272 pixels across 72 cases**, maximum component error zero. All four channels count toward each pixel. + +| Source | Bridge | Output sides | Cases | Exact pixels / total | +|---|---|---|---:|---:| +| Original RGBA8 atlas field | Color in U8, U16, F16 and F32 | 64, 128, 256 | 12 | 344,064/344,064 | +| Original RGBA16 and signed RGBA32F fields | Color in U8, U16, F16 and F32 | 32, 64, 128, 256, 512 | 40 | 2,793,472/2,793,472 | +| Same RGBA16 and signed RGBA32F fields | Grayscale in U16 and F32 | 32, 64, 128, 256, 512 | 20 | 1,396,736/1,396,736 | + +Use the RGBA8 formula under [atlas crop with wired value inputs](#atlas-crop-with-wired-value-inputs) and the signed RGBA32F field under [3D linear gradient](#3d-linear-gradient). For the RGBA16 field, map each signed input component `v` to the nearest integer to `65535*(v+4)/8`. Use seed 42 below 128² and zero otherwise. The grayscale bridge result was also read directly before expansion to RGBA. + +Each factor-two step filters four clamped texels at the source storage precision, then stores the result in the bridge format. For grayscale, the first step filters the three color channels before computing the equal-weight mean. Further steps read stored grayscale. Before the fix, the 256² RGBA8 source case with an F32 bridge matched 4/65,536 pixels, maximum error 7.629395e-6. Filtering the same RGBA16 field after conversion to gray matched only 53,819/65,536 gray U16 pixels at 256². + +The 256² atlas wrapper now matches 65,281/65,536 at default rotation, maximum .250003815. Its 255 differing pixels lie on the first row and column of the lower-right quadrant. Rotation .125 matches 65,089/65,536, maximum 1. The directly bound controls above and this wrapper exercise different graph connections. + +With the inputs and settings under [panoramic LOD](#panoramic-lod), the four 64² seed-42 format runs now match 4,096/4,096 each, maximum zero. The 128² opaque, alpha and changed-seed outputs each match 16,128/16,384, maximum 125 byte levels. At 256² the opaque image matches 64,768/65,536, maximum 126. Both 128² flat controls match 16,128/16,384, maximum 116. + +The rotated 3D planar projection runs still differ. At 128² the grayscale output matches 16,335/16,384 in LUM16, maximum 226 levels, and color matches 16,378/16,384 in RGBA8, maximum one level. At 64² both roots match 4,094/4,096 in U8 and 4,093/4,096 in each of U16, F16 and F32. The respective maxima are 1, 32, .00048828125 and .000488288701. All three default and changed-seed runs for each root match 98,304/98,304 pixels. With the [shared lookup](#basic-and-ridged-3d-perlin), ridged 3D Perlin matches all four eight-bit cases. Its changed U16, F16 and F32 runs match 16,337, 16,380 and 5,160 of 16,384 pixels, with maxima 1, .00048828125 and 1.78813935e-7. + +### Wired graph textures and pixel sampling + +An original two-graph package returns two outputs from the child. One child output returns its color input directly, the other reads it using a Pixel Processor. The parent supplies the 128² RGBA8 atlas field above at a fixed 128². Give the child input a parent-relative size and set its precision explicitly. Read the stored bridge from the direct output and the sampled value from an RGBA32F output. Each pixel comparison includes all four components and checks the reported dimensions and depth. + +| Controls | Output comparisons | Exact pixels / total | Maximum error | +|---|---:|---:|---:| +| Nearest and bilinear at pixel centers, U8/U16/F16/F32 bridge, sides 64/128/256, seed zero | 48 | 1,376,256/1,376,256 | 0 | +| Bilinear at 32² seed 42 and 512² seed zero, same four bridge formats | 16 | 2,105,344/2,105,344 | 0 | +| At 256² and F32, change the tiling on the parent input, child input or processor to none, horizontal or vertical | 18 | 1,179,648/1,179,648 | 0 | + +The directly returned bridge resizes through stored factor-two levels using its own horizontal and vertical tiling flags. The sampled color input retains the source dimensions and precision inside the graph instance. For example, at 64² the first red value is 48/255 when sampled nearest and 24/255 through the direct U16 bridge. At 256², both axes wrap for the bilinear sampler. The first atlas texel receives a green contribution of 16,384/65,535 from the opposite edge. + +For a separate single-graph control, nearest- or bilinear-sample the same fixed 128² input at `$pos + (−.3125,.1875)`. Set the processor output to RGBA32F, side 256 and seed 42. Repeat with its tiling set to none, horizontal, vertical and both. All **524,288/524,288** pixels match, maximum zero. The explicit image read repeats both axes in all eight cases. + +In the [atlas crop wrapper](#atlas-crop-with-wired-value-inputs), default rotation at 256² now matches **65,536/65,536** RGBA32F pixels, maximum zero. With .125 turns the 256² case matches 65,408/65,536, maximum .994125247. At 128² it matches 16,320/16,384 with seed zero or 42, maximum 1. At 64², 4,064/4,096 match, maximum .996078432 in the authored float output. The remaining rotation differences follow one edge of the sampled shape. + +For the [spline distance controls](#height-distance-texture-mapping-skew-and-weave), both wired counts now match 1,024/1,024 at 32² seed 42 and 4,096/4,096 at 64² seed 137 in LUM32F. At 16² seed zero, count 1 matches 256/256 and count 2 matches 252/256, maximum 5.96046448e-8. + +### Value Processor coordinates + +Both maximum-coordinate roots return the same Float2 as the reference in **12/12 typed comparisons each**. All maximum component errors are zero. Before the fix, reading the position variable stopped both cooks. A Value Processor starts at (0,0) and passes this position to nested function calls. + +| Root | Defaults, changed input and seed | Four requested output formats | Four isolated peaks | +|---|---:|---:|---:| +| `pbr_render.sbs/get_max_coords/get_max_coord` | 4/4 | 4/4 | 4/4 | +| `pbr_render2.sbs/get_max_coords/get_max_coord` | 4/4 | 4/4 | 4/4 | + +Use the byte field (17x+31y) mod 256 at 128² and 256² with seed zero, and at 128² with seed 42. The changed field is 32+((17x+31y) mod 160) at 128² with seed zero. At 64² seed 42, requesting U8, U16, F16 and F32 at the upstream processor yields the Float2 (.1015625,.109375) in all four cases. These roots expose no ordinary parameters. For the original single-peak field use (11x+13y+3xy) mod 79, and set the specified pixel to 255. + +| Size | Seed | Peak pixel | Typed result in both roots | +|---:|---:|---|---| +| 16² | 7 | (1,2) | (.09375,.15625) | +| 32² | 91 | (21,7) | (.6640625,.234375) | +| 64² | 113 | (57,48) | (.890625,.75) | +| 128² | 251 | (122,17) | (.953125,.125) | + +Separate original value graphs read `$pos`, `$size`, `$sizelog2`, `$depth`, `$depthpow2` and `$number`. At 16² and 128² with seed zero and 64² with seed 42, the position and three depth or iteration values are zero. The size values follow the canvas and its base-two logarithm. Is Defined reports true for the position, size and three depth or iteration names and false for an unbound probe name. Unbound numeric and Boolean reads return a typed zero. These scalar and vector controls match **50/50 typed values** with maximum error zero. + +A Value Processor also averages a sampled color’s three channels in the order measured under [grayscale sampling](#grayscale-sampling-of-color-inputs). Using the same four RGBA fields, sample at (39.5+.1875,77.5+.5625)/128. Repeat with a uniform (.25,.5,.75,1). Compare the single Float or Float4 as IEEE float32 components in nearest and bilinear modes. Before correcting normalization and filtering, 23/32 values matched across the two input fields, with maximum component error 5.84125519e-06. + +### Value Processor texture filtering + +The 32 scalar and color comparisons above now match **32/32 typed values**. Two independent 128² coordinate sets add **192/192 Float4 values**. Two more sets at 2² and 32² give **16/16 Float4 values**. Maximum component error is zero across all 240 comparisons. Both maximum-coordinate roots still match all 24 previously measured Float2 results. + +A value function wraps both texture axes even when output tiling is disabled. For bilinear sampling, multiply the UV by the stored dimensions, subtract .5 and keep the full float32 fractional texel position. In each row compute a×(1−t)+b×t with two rounded products and a sum, then do the same vertically. For U8 or U16, interpolate stored integer channel levels as float32 and finally multiply by the float32 reciprocal of 255 or 65,535. A nearest read normalizes the selected stored level with the same reciprocal. Floating textures already carry their sample values. + +Use the four original color fields described under [grayscale sampling](#grayscale-sampling-of-color-inputs), both filtering modes and output tiling disabled. For the first set choose (x,y,a,b) from (7,13,0,0), (83,127,48,144), (42,78,19,61), (17,93,128,128), (0,62,−93,181), (126,7,201,113), (77,0,−171,−35), (128,67,47,23), (−2,132,105,151), (31,40,1,255), (4,1,77,99), (76,30,45,85). The UV is (x+.5+a/256,y+.5+b/256)/128. For the second set use (((227j mod 1447)−153)/1009, ((281j mod 1867)−413)/1031) for j=0…11. In both sets alternate seeds 0 and 42. + +For the small independent field, take row-major RGBA byte tuples (19,67,129,251), (85,222,17,9), (255,128,74,66) and (3,102,39,109). For U16, multiply each level by 251. For F16 and F32, use (level−97.125)/13.375. Sample at (−.317,1.093), seed 17, directly from a 2² bridge and again after the bridge resizes the field to 32². With the 2² byte field, the four bilinear component bit patterns are `3e8013a0 3f2bd646 3e0f43a5 3e744cb7`. + +### Luminosity, axial gradients, color lookup and luminance merge + +The five roots below each match **165,120/165,120 pixels in 15 cases**. Replaying the four first-pass captures gives 114,688 exact pixels per root. Four 64² producer formats at seed 42 give 16,384, and a separate 32² F32 case at seed 113 gives 1,024. Six further original cases give 33,024. Their sizes are 16² F32 at seed 17, 64² U8/U16/F16/F32 at seed 71 and 128² F32 at seed 137. Floating comparisons include the stored bits of every channel. Maximum finite error is zero throughout. + +| Root | Seed 42 settings | Independent controls at seeds 17, 71 and 137 | +|---|---|---| +| `blend.sbs/luminosity` | Opacity .67 with foreground, background and mask | Disable alpha blending, set opacity to .375 at 16² and 64² or .8125 at 128², and use the fields below | +| `gradient_axial.sbs/gradient_axial` and `gradient_axial_reflected` | Endpoints (.15,.3), (.7,.85), expansion disabled | Enable expansion. Use (.8125,.21875) and (.09375,.78125). At 16² set both endpoints to the first point | +| `hald_clut.sbs/hald_clut` | Identity lookup, input alpha control disabled | Use a new nonlinear lookup and vary the input alpha. Enable alpha control at 16² and 64², disable it at 128² | +| `hdr_merge.sbs/average_luminance_merge` | Original HDR field, exposure delta 2 | Use the HDR field below. Set exposure delta to −.75 at 16² and 1.375 otherwise | + +For Luminosity, let t be 1 for background, 2 for foreground or 3 for mask. Generate C=(11x+17y+3xy+31t) mod 256. The mask is C. The color inputs contain (C, (41x−19y+11t) mod 256, (3x+79y+t) mod 256, 42×((13x+7y+31t) mod 7)). For the 512² lookup, use the low, middle and high six bits of the row-major index as R, G and B indices. Map each to the nearest byte using 255/63. The lookup stores (floor((R+2G)/3), 255−B, floor(R/8) XOR floor(G/4) XOR floor(B/2), 255). Feed it RGBA bytes ((11x+7y+3xy) mod 256, (43x+17y+28) mod 256, (5x+11y) mod 256, 23×((7x+3y) mod 11)). The original HDR input stores RGBA32F (((7x+23y+5xy) mod 303)/53, .09375+((19x+2y) mod 187)/51, ((x+8y) mod 103)/31, 1). + +With coincident endpoints both gradients return the same quiet NaN, bit pattern `0x7fffffff`, at every one of the 256 pixels. All other outputs are finite. At 64² the five independent F32 images have respectively 4,092, 2,210, 2,053, 4,096 and 4,096 distinct stored pixels. + +### Skipped loops and path buffers + +A loop runs its initializer before testing its exit condition. If the condition is already true, or the iteration allowance is zero, its result is the zero of its declared result type. A loop that enters the body returns its last body value. MaterialCraft previously returned the initializer on a skipped loop. A Boolean initializer followed by a float body consequently stopped both path roots with a type error. + +Use a standalone loop with a scalar body of 9 and an initializer of 7, true, (3,5,7,9) or an unwired initializer. Set the exit condition to true, false or pixel X ≥ .5, with iteration allowances 0, 1 or 2. Eight pixel functions at 16² seed 7 and 32² seed 91 match **10,240/10,240 LUM32F pixels**. The eight matching value functions give **16/16** exact typed results. Changing the result type to Boolean, integer pair or float pair with a true or false condition gives another **12/12** exact typed results. Three 32² uniform-parameter image probes match **3,072/3,072 pixels**. All maxima are zero. The regression also reads a variable assigned by the initializer after the loop. Direct Boolean or vector outputs from a grayscale Pixel Processor are a separate open conversion case. + +| Path root | Inputs and controls | Exact pixels / total | Maximum error | +|---|---|---:|---:| +| `Impl/sort_by_blue` | Four original 16² RGBA32F cases with seed 0 or 42, including changed settings | 1,024/1,024 | 0 | +| Same | 64² seed 42, passthrough enabled, count 32, U8/U16/F16/F32 | 16,384/16,384 | 0 | +| Same | Passthrough disabled, count 7 at 16² seed 17; count 19 at 32² seed 71 in four formats and 64² seed 137 F32 | 8,448/8,448 | 0 | +| `Impl/compute_paths_lengths` | Four original 16² cases, including the 1×1 passthrough result, plus four 1×1 results at requested 64² seed 42 | 773/773 | 0 | +| Same | Five-point transformed path at 16² seed 17 F32, intermediate lengths disabled | 256/256 | 0 | +| Same | Intermediate lengths enabled and passthrough disabled, five or seven points, seed 17, 71 or 137 | Execution budget reached | Unavailable | + +The sort holdout uses RGBA bytes ((17x+13y+5) mod 256, (29x−13y) mod 256, 23×((3x+7y) mod 11), (7x+5y+11) mod 256). Its outputs contain seven or nineteen distinct RGBA tuples. Across the fourteen sort cases **25,856/25,856 pixels** match. The length holdout starts with the original five- or seven-point closed path buffer and replaces each vertex (x,y) by (.0625+.625x+.1875y, .125+.0625x+.6875y). Set scale to (1.25,.8125). Both the resized 16² path buffer and independently sized buffers with header texel spacing 1/side reach the local execution limit with intermediate lengths enabled. The reference app returns a grayscale image. An error image supplies no comparable samples. + +### Luminance EXR input + +Generate a half- or single-precision EXR with luminance `(((67x+131y+5xy) mod 1024)−256)/128`. Write either Y alone or Y with a separate alpha channel `((11x+13y) mod 64)/64`. Bind each file to a grayscale input and sample at pixel centers with a Pixel Processor. At 32² use seed 113 and store U8, U16, F16 and F32. At 64² use seed 239 and store F32. These twenty original inputs and output-format combinations match **32,768/32,768 pixels**, maximum error zero. The previous decoder rejected the luminance files. MaterialCraft now decodes bounded Y and YA images through the existing shared image codec and retains linear signed and HDR luminance. The in-memory import regression checks both linear flag settings for both input precisions and layouts. + +Repeating the nine independent input cases each for [color burn, color dodge](#color-burn-and-color-dodge) and [color temperature](#color-temperature-range-reductions-sky-parameters-and-polygon-paths) with genuine luminance resources gives **117,504/117,504 exact pixels**. The direct RGBA Divide and Switch probes at full and partial opacity match **163,840/163,840 pixels** with genuine luminance masks. The signed scalar endpoint cases still distinguish positive and negative zero. Full and partial Divide each match 63,488/65,536 for both F16 and F32. Full Switch matches 63,744/65,536 at F16 and 63,232/65,536 at F32. Partial Switch matches 65,280/65,536 at both precisions. Their maximum absolute error is zero. + +### Grayscale sampling of color inputs + +Feed an original 128² image to a Pixel Processor and read input zero with the grayscale sampler at pixel-center UV plus (.1875,.5625) texels. Use seed 42 and a LUM32F output. With nearest and bilinear filtering, RGBA8, RGBA16, RGBA16F and RGBA32F each match 16,384/16,384 pixels per mode. On the signed F32 input, reading only red previously matched zero pixels in both modes. Maximum errors were 4.95148039 and 3.83905315. Adding green and blue first, then red, and multiplying by the float32 reciprocal of three after sampling matches all eight color cases exactly. + +For RGBA8 use ((17x+31y) mod 256, floor(255x/127), 255−floor(255y/127), (7x+13y) mod 256). For the floating formats use the signed four-channel input under [3D linear gradient](#3d-linear-gradient). For RGBA16 encode round((channel+4)×65535/8) from that field. The eight grayscale-bridge controls also match all pixels. Their U8 input is (61x+137y+7xy) mod 256. Their U16 input is q=(2029x+4889y+193xy) mod 65536. For floating storage, supply a linear RGB image with the same float32 value q/8191−3.25 in each channel and alpha one, and select a grayscale bridge. The single stored channel is sampled directly. The sixteen comparisons match **262,144/262,144 pixels**, maximum error zero. A separate luminance-only float EXR was readable in the reference app and the current MaterialCraft decoder returned an error for that file. + +### Half-precision Crop area and input sizes + +| Root | Renders | Exact stored pixels / compared | Maximum error | +|---|---:|---:|---:| +| Color Crop, both outputs | 48 | 377,344/377,344 | 0 | +| Grayscale Crop, both outputs | 48 | 377,344/377,344 | 0 | + +Each root produced 256,000 exact U8 pixels, 26,624 U16, 30,720 F16 and 64,000 F32. The four archived renders each expose two image outputs. The remaining runs change storage at the producing node of Output or Area. The formerly mismatching enabled Area renders at 64² now match all 4,096 pixels each. The [earlier Crop controls](#crop-output-and-area) give the source fields, transforms and first exact counts. + +For the additional twelve renders per port, use original bytes Hⱼ=((37+13j)x+(29−5j)y+(7+2j)xy+53j) mod 256. Use j=0…3 for RGBA and j=0 for gray. Run native defaults at 16²/seed 47 in F32. Enable Show Crop Area for the remaining cases. At 32²/139 use Input Size (32,64), matrix (.75,−.125,.375,1.25), offset (−.1875,.3125) and filter 0. At 64²/277 use (64,64), (.625,.25,−.375,1.125), (.125,−.25) and filter 1. Run both in all four output formats. At 32²/419 use 16×32 input, Input Size (16,32), identity, offset (.09375,.1875), filter 0 in F16 and F32. Repeat the first changed F16 case at seed 619. These inputs contribute 47,616 exact pixels per root. + +With F16 blend output and equal physical extents, normalized integer inputs pass through half storage when the source and blend differ in whether their effective output size depends on a runtime expression. A plain size, a literal Int2 or an expression made solely of constants each use the static path. A getter or assignment sequenced before the same Int2 can change the rounding. A blend inheriting the background size also inherits that dependency. A pass-through node preserves it. The cook cache includes the distinction. + +For a two-pixel reproduction, blend foreground bytes (71,55) over background (155,1) at opacity .4. Use a static (0,0) relative size or a sequence that reads the runtime size then returns (0,0). The half output expanded to F32 has bits 3ef3c000 and 3db58000 with both inputs static. Making just the foreground size dynamic changes them to 3ef3a000 and 3db56000. The regression varies both sources and blend inheritance with a shared cache. + +| Standalone blend controls | Renders | Exact stored pixels / compared | Largest stored error¹ | +|---|---:|---:|---:| +| Output size read or assignment | 64 | 262,144/262,144 | 0 | +| Size inheritance through two image sources | 96 | 391,540/393,216 | 1 | +| Eleven expressions with byte, word or half inputs | 132 | 540,672/540,672 | 0 | +| Independent foreground, background and opacity sizes | 36 | 147,456/147,456 | 0 | +| Eleven expressions with full-float inputs | 44 | 180,224/180,224 | 0 | +| Different physical extents and equal-size controls | 96 | 293,493/393,216 | 5501 | + +¹ Integer errors use stored levels. Floating errors use absolute component differences. For the separate source-depth controls, use a 64² linear field Hⱼ=(((19+16j)x+(13+28j)y+(7+6j)xy+43j) mod 1021)/1019−.03125 for foreground j=0 and background j=1. Change the stored precision, size inheritance and expression independently. Compare all four output formats. The 96 size-inheritance renders match all 98,304 F16 pixels. In that set, 1,674 F32 pixels differ by at most 1.19209290e−7 and two U16 pixels differ by one level. The physical-size controls also exercise 16, 32 and 128 texel inputs to a 64² blend. Those filter results have their own measurements above. + +### Crop output and area + +The color and grayscale Crop roots each match **229,376/229,376** pixels across both outputs in the four original cases. Use the default graph at 128² and 256² with seed zero, repeat 128² with seed 42, then disable Show Crop Area, set Input Size to (128,128), Matrix to (1.2,.25,−.125,.8), Offset to (.1,−.15), and Filtering to 1 at 128². The inputs are the original foreground or grayscale ramp from the first pass. At 64² seed 42, retaining the 128² original input, these altered settings match a further 32,768/32,768 pixels per root across the two outputs and all four storage formats. Every maximum is zero. + +For the independent case, enable Show Crop Area, set Input Size to (64,128), Matrix to (.75,−.125,.375,1.25), Offset to (−.1875,.3125) and Filtering to 0. Use the original color or height field under [height distance, texture mapping and skew](#height-distance-texture-mapping-skew-and-weave) at the output dimensions. At 128² seed 71 F32 and 64² seed 137 in all four storage formats, each root’s Output matches 32,768/32,768 pixels. Area matches in U8, U16 and F32. At 64² F16, color Area matches 4,054/4,096 and grayscale Area matches 4,087/4,096. Both maxima are .00048828125. The last operation on both Area outputs is a blend. + +### Tile edge masks and normalized spline distances + +| Root | First four captures | Four 64² parent formats, seed 42 | Independent 32², seed 113 | Seven new cases | Total exact / compared | +|---|---:|---:|---:|---:|---:| +| `smart_auto_tile.sbs/pattern_find_edges_step` | 3,146,752 | 4,096 | 1,024 | 34,048 | 3,185,920/3,185,920 | +| `spline_tools.sbs/internal_tools/normalize_spline_distance` | 1,024 | 16,384 | 1,024 | 34,048 | 52,480/52,480 | + +All 16 cases per root match at the stored precision, with maximum error zero. In the edge-mask root the default grid exponent is 10, so the first three results are each 1,024² at parent sizes 128² or 256² and seeds zero or 42. Setting the grid exponent to 5 produces a 32² result. The normalized distance root has a single grayscale input and no additional exposed settings. Its first four outputs are 16² LUM32F. The earlier precision and independent input definitions are in the [four-format inventory](#four-format-inventory-comparison). + +The seven new cases per root use 16² F32 at seed 17, 64² U8/U16/F16/F32 at seed 71, 128² F32 at seed 137 and 32² F32 at seed 211. Use integer coordinates starting at zero, with N equal to the requested side. Set the edge-mask grid exponent to log₂(N), blur and smoothness to .25, combined threshold to .375 and per-channel thresholds for base color, normal and height to .1875, .3125 and .125. Enable per-channel thresholds except at 32². Disable height at 16², base color at 32² and normal at 128². Bind linear byte fields using z=(13x+7y+3xy) mod 256. Base color is (z,19x+3y,7x−23y,255−z), normal is (127+2x,91+3y,255−floor(z/5),255) and height is 19x+23y+7xy, reducing all byte channels modulo 256. The mask alpha is 255. Its RGB channels are 255 where (floor(x/4)+2floor(y/5)) mod 3 is nonzero, x < N/2 and y mod 7 ≥ 3, respectively, and zero otherwise. The 64² F32 output contains ten distinct RGBA tuples. + +For normalized distance at 16² and 64² use a grayscale byte field (17x+7y+3xy) mod 256, with the rightmost column replaced by 13y mod 256. At 128² use 16-bit levels (311x+1861y+31xy) mod 65536 and zero the final column on rows y mod 3=0. At 32² store (((13x−31y+2xy) mod 253)−87)/32 in each RGB channel of a linear float image, alpha one, with the final column zero on rows y mod 4=0. The 64² F32 output has 3,330 distinct levels. + +The [wired bridge distance](#height-distance-texture-mapping-skew-and-weave) root was also retested. With count two, 32² and 64² now match 1,024/1,024 and 4,096/4,096. The 16² case matches 252/256 with maximum 5.96046448e−8. All three count-one cases remain exact. + +### Runtime pixel logarithms and powers of two + +An original pixel function returns (log2(1+t), 2ᵗ, 2⁻ᵗ, log2((1+t)/2)). Across eight 1024² RGBA32F images all **8,388,608 pixels and 33,554,432 components** match bit for bit, maximum error zero. For image j=0..7, let t=(j×2²⁰+i)/2²³ with row-major index i, seed 251. Supply the four arguments as a linear RGBA32F input and sample at pixel centers with nearest filtering. This exhausts all float32 mantissas in [1,2) for the logarithm and all 23-bit fixed fractions in [0,1) for the exponential. + +| Additional per-pixel controls | Cases | Exact / compared | Maximum finite error | +|---|---:|---:|---:| +| Logarithm base two and power of two on the 256² fields below | 22 | 1,441,792/1,441,792 | 0 | +| Natural logarithm, log2(x)×float32(ln(2)), and 2^(log2(x)×y) on signed and exceptional pairs | 6 | 393,216/393,216 | 0 | +| Both signs of zero, subnormals, smallest normals and NaN payloads, three operations at 16² | 3 | 768/768 | 0 | +| Exposed scalar passed directly to the pixel function, three operations | 28 | 7,168/7,168 | 0 | + +For the 256² fields use the row-major 32-bit hash h from [the runtime trigonometry controls](#runtime-pixel-sine-cosine-and-atlas-rotation). At seed 239, set (x,y)=(1+t,t) with the 23-bit numerator of t equal to 128i, i, h mod 2²³, or 0x3a0000+i. For the signed field use x=4h/2³²−2 and y=12i/65535−6. The exceptional field cycles x through NaN, −∞, −2, −1, −0, +0, 2⁻¹⁴⁰, 2⁻¹²⁶, .25, .5, 1, 2, 2²⁰, +∞. Repeat each y for 17 pixels in the cycle NaN, −∞, −129, −126, −2, −1, −.5, −0, +0, .5, 1, 2, 3, 127, 128, +∞. Round inputs to float32 before sampling. + +At seed 193, the full-range field combines exponent bits i mod 255 and mantissa h mod 2²³ for x, and uses y=300h/2³²−150. The power-boundary field starts at float bit pattern ((i mod 254)+1)×2²³ for x and at float32((i mod 255)−127) for y, then offsets their bit patterns by (floor(i/254) mod 17)−8 and (floor(i/255) mod 17)−8 respectively. For the near-one field offset the bit pattern of 1 by i−32768 and set y=(i−32768)/2³¹. A fourth field uses x=.5+1.5h/2³² and y=2h/2³²−1. The last cycles x through (.5,.7,.625,.2,.8,1,1.125,2,0,−1,−.7) and repeats each successive y in (0,1,2,3,4,5,6,7,.5,1.375,−1) for 13 pixels. For the 16² exceptional controls, cycle float32 input bits through 00000001, 007fffff, 80000001, 807fffff, 00000000, 80000000, 00800000, 80800000, 7fc12345 and ffc12345 at seed 17. + +Both pixel operations evaluate a quadratic over one of 64 intervals. The coefficients come from the mathematical functions and the sampled rounding thresholds. The runtime logarithm of .5 has bits `bf7ffffe`, the literal result has bits `bf800000`. The pixel natural logarithm multiplies the base-two result by float32(ln(2)). Replaying the 30 existing sine and cosine comparisons after sharing the polynomial fitting routine gives 1,443,840/1,443,840 pixels, maximum zero. + +For the exposed scalar controls use .5, .625, .7, 1, 1.125, 1.25, 2, 4 and 1.375 for either logarithm. For the exponential use −2, −1, −.625, −.5, −.125, 0, .5, 1, 1.375 and 2. Cycle seeds 71, 137 and 313 at 16². In a separate Value Processor, the same arguments match 5/9 typed base-two logarithms, 5/9 natural logarithms and 9/10 powers of two. Maximum errors are 5.96046448e−8, 2.98023224e−8 and 2.38418579e−7 respectively. See the [uniform power and logarithm measurements](#uniform-powers-of-two-and-volume-lighting) for the subsequent fix and the remaining logarithm error. + +Literal-only pixel graphs at 16², seed 23, give 512/768 exact pixels for each logarithm on .5, .7 and 1. At .7 their maximum errors are 5.96046448e−8 for log2 and 2.98023224e−8 for ln. Literal powers of two match 768/768 at −.5, 1.375 and 2, maximum zero. + +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). + +### Marked variable reads in path and mipmap graphs + +| Root | Renders | Exact RGBA pixels / compared | Maximum error | +|---|---:|---:|---:| +| Facet link template | 18 | 57,600/57,600 | 0 | +| Facet stitch template | 18 | 57,600/57,600 | 0 | +| Vertex processor | 18 | 57,600/57,600 | 0 | +| Simple vertex processor | 18 | 57,600/57,600 | 0 | +| Color mipmap N from O | 18 | 287,232/287,232 | 0 | + +A Get variable operation consumes one leading `%`. For an exposed Float named `angle`, Get `angle` and Get `%angle` both return the exposed value. Set `angle` to .6875 before the second read and it returns .6875. Set `%angle` instead and Get `%angle` still returns the exposed value, while Get `%%angle` returns .6875. Is Defined tests the literal name. A Get of `%$size` has the same result as a Get of `$size`. + +Use original Node, Pixel Processor, Value Processor and FX-Map functions. For each function use a 16² default at seed 41 with angle .625, 32² at seed 131 with .1875, and 64² at seed 409 with .875. Test bare, marked, twice-marked and absent names, and the read/write combinations above. For Is Defined choose .875 for true and .1875 for false. For the size probe select X and multiply by 1/128. The Node scope stores the scalar before returning an Int2 size. Before the fix the marked exposed Float matched 0/3 typed values and 0/5,376 Pixel Processor pixels, maximum .875. It now matches all three values and every pixel. + +| Direct scope | Cases | Exact pixels or typed values / compared | Maximum error | +|---|---:|---:|---:| +| Node | 51 | 91,392/91,392 | 0 | +| Pixel Processor | 51 | 91,392/91,392 | 0 | +| Value Processor | 51 | 51/51 | 0 | +| FX-Map opacity | 51 | 80,640/91,392 | 1 | + +At FX-Map opacity, an unresolved direct Get of `%other` or `%%angle` yields opacity 1 in the reference app and 0 in MaterialCraft. All six such renders differ at every pixel. A literal Is Defined check and a read after assigning the marked name match. The table records the unresolved direct-read behavior separately from the five measured root graphs. + +The nine additional renders for each root use the [modular input, resolution, precision and seed matrix](#normal-maps-panoramas-and-primitive-shapes). For both facet templates, set radius to .6875, 1.3125 and 2.125 for A/B/C, enable init only in B, set foreach to .375, .75 and 1.125, and use finally (.1875,.34375,.75,1). Each changed facet output is uniform on these inputs. + +For each vertex root use the original five-point path for defaults and A and the seven-point path for B and C. For every valid position (x,y) in the path's second row use (.0625+.625x+.1875y, .125+.0625x+.6875y). Bind each remaining image pin in identifier order to its modular field. Set the per-vertex pair to (.1875,.8125), (−.25,.625) and (.78125,.3125), with image input counts 1, 2 and 3. On the full processor set previous/next fetch counts to (1,1), (0,2) and (1,0). Both 64² F32 outputs contain 383 distinct tuples. + +For the color mipmap use (N,O)=(2,1),(3,0),(4,1), init .375, .75 and 1.125, blend .8125, finally (.75,.125,.6875,1), and empty (.1875,.3125,.625,.25). The 64² F32 output has 2,558 distinct tuples. The default 16² parent produces 16×32 and the 128² B parent produces 128×256. Counts use the stored output extents and precision for each render. + +### Plane light, splatter, symmetry and waveform comparisons + +| Root | Renders | Exact pixels / compared | Maximum U8 / U16 levels | Maximum F16 / F32 error | +|---|---:|---:|---:|---:| +| Panorama plane light | 18 | 170,458/171,264 | 0 / 0 | 0 / 1.21593475e-05 | +| Splatter blend, grayscale | 18 | 170,610/171,264 | 77 / 19923 | 0.303955078 / 0.780312974 | +| Splatter blend, color | 23 | 203,407/204,032 | 90 / 23114 | 0.352539062 / 0.566889435 | +| Symmetry slice | 18 | 156,022/171,264 | 7 / 1632 | 0.0249023438 / 0.0248995423 | +| Waveform v2 | 18 | 142,662/171,264 | 255 / 65535 | 1 / 1 | +| Waveform 1 | 18 | 142,630/171,264 | 255 / 65535 | 2 / 2 | +| Weave 4 | 18 | 170,018/171,264 | 0 / 1 | 0 / 0.765621424 | + +Each root includes the archived outputs, the four-format sweep, an independent 32² render and nine further original renders. The color splatter count also includes five earlier changed-input controls. Use the [modular image fields, A/B/C settings, sizes and seeds](#normal-maps-panoramas-and-primitive-shapes) for the additional renders except symmetry slice. Number the changed settings k=1,2,3 for A/B/C. + +| Root | Additional changed settings | +|---|---| +| Plane light | World position (−.75,.4375,1.25), UV (.3125,.28125), rotation (.0625k,−.125,.1875), scale .6875, size (.75,1.25). Use distance-from-origin mode in B and alternate up vector in C. Set color mode and pattern to k mod 3, color (.75,.34375,.625), temperature 4375 and exposure 1.25. Disable background input in C and enable ground clipping in B. | +| Splatter blend | Set pattern count to 3, 8 and 5, and color-input opacity to .375, .75 and 1. For grayscale set luminance adjustment −.1875 and luminance random .3125k. For color set random pattern assignment .375, HSL adjustment (.1875,−.125,.25), HSL random (.125,.25,.375). Use normal processing and the alternate input normal format in B. | +| Waveform v2 | Set sample count to 17, 31 and 24, function to k mod 3, scale to 4+k, amplitude limits .1875 and .8125, noise .125k, pattern to 3, 6 and 4, pattern variation .125k and disorder .15625k. | +| Waveform 1 | Use the same sample counts, noise and patterns, size limits .1875 and .8125 and wave number k+2. | +| Weave 4 | Use tiling 3, 5 and 7. Enable rotation in A and C. | + +For symmetry, use the 16² default at seed 17, then the modular RGBA field at 64² in all four formats with seed 73, 128² F32/181, signed 32² F32/293, a 32×16 input at 32² F32/449, and the 64² F32 repeat at seed 661. In this order the changed (symmetry mode, transfer mode, blend, flip side, flip side 2) settings are (1,0,.25,true,false), (2,1,.71875,false,true), (0,1,.5,true,true) and (2,0,1,false,false). Repeat the first setting at seed 661. The first differing pattern buffer at 64² matches 3,840/4,096 U8 texels, maximum one level. At (28,0) MaterialCraft stores 114 and the reference stores 113. + +The plane-light Pixel Processor at 64² F32 matches 4,020/4,096 pixels, maximum 1.21593475e−5. At (14,6) its red channel is 2.48438478 in MaterialCraft and 2.48438454 in the reference. In both splatter graphs the signed case first differs in the same 256² RGBA16 Pixel Processor. Every pixel differs, maximum 65,415 levels. At (0,0) MaterialCraft stores (51546,38154,36337,11593) and the reference stores (3600,46195,62868,47648). + +In the 64² F32 waveform captures, the earliest differing stage is the pattern generator. Waveform v2 matches 3,908/4,096 pixels there, maximum 1. Waveform 1 matches 4,040/4,096, maximum 2. On the signed Weave 4 case, the first 8² U16 pattern differs at (7,0) and (3,4). Both reference texels are 65,535 and both MaterialCraft texels are zero. + +### High-pass, anisotropic noise and triangle-grid controls + +| Root | Renders | Exact pixels / compared | Maximum error | +|---|---:|---:|---:| +| Grayscale high-pass | 18 | 171,264/171,264 | 0 | +| Anisotropic noise v2 | 18 | 171,264/171,264 | 0 | +| Triangle grid base | 18 | 171,264/171,264 | 0 | + +Each root includes four archived renders, the four-format sweep, the independent 32² case and nine additional renders. Use the [modular fields and size/seed matrix](#normal-maps-panoramas-and-primitive-shapes) for the nine. For the high-pass source use the gray field H and set radius to 3, 11.25 and 24 for A, B and C. The 64² F32 output contains 212 distinct gray values. + +For anisotropic noise v2 use X/Y counts (5,13), (7,19) and (3,23). Enable rotation and Y count by resolution only in B, and non-square expansion only in A and C. Set smoothness/interpolation to (.625,.5), (.375,.1875) and (1,.75). Use disorder 0, .34375 and .6875 and disorder speed .8125. The 64² F32 render contains 764 distinct gray values. + +For the triangle grid bind the procedural height, vector map and color inputs. For k=1,2,3 use X count 4+k, Y count 3+k, triangulation k mod 2, vector-map displacement .0625k and rotation .09375k. Set random position multiplier .375, rotation disorder .15625 and random height .3125. The color-output selector is an integer enum. Use 1 in A/B and 0 in C. The 64² F32 render contains 40 distinct RGBA tuples. An earlier probe passed a Boolean to this selector and was rerun with the declared integer type. + +### Environment rotation and wired irradiance samples + +| Root | Successful renders | Exact RGBA pixels / compared | Maximum U8 / U16 levels | Maximum F16 / F32 error | +|---|---:|---:|---:|---:| +| Rotate environment | 18 | 171,264/171,264 | 0 / 0 | 0 / 0 | +| Compute irradiance | 32 | 217,088/217,088 | 0 / 0 | 0 / 0 | +| Compute ray direction | 32 | 217,088/217,088 | 0 / 0 | 0 / 0 | +| Debug hit UV | 27 | 193,960/194,304 | 239 / 57568 | 0.878417969 / 1.6449104 | + +Use the [procedural normal, position and modular fields](#normal-maps-panoramas-and-primitive-shapes), the same nine image sizes, seeds and destination formats, and the same A/B/C labels. For an input named hit_uv use (u,v,H,1). For environment rotation, set amount to .0625k, direction angle to −.1875, around-pole angles before and after to .125 and .3125, and exposure to .5, 1.25 and −.375 for A, B and C. Default and archived controls are included. + +The irradiance graphs expose the sample index and count as scalar value pins. For nine direct cases leave these pins disconnected. In three additional original parent graphs, connect Float Value Processors to i and nb_samples with values (0,1), (1,4) and (5,16). Wire the same procedural images through the parent. For (1,4) use the 16² default, A at 64² in U16, F16 and F32, and the 64² F32 repeat. For the other two pairs use the 16² default, A at 64² U8, B at 128², signed C at 32² and the 32×16 B input. These 15 parent renders per root preserve the child’s declared F16 storage for irradiance and ray direction. Changing the connected pair from (0,1) to (5,16) changes every pixel at 16² and 128² in both graphs. Each standalone 64² F32 irradiance and ray-direction image has 4,096 distinct RGBA tuples. + +For the debug root set debug_pos to (.3125,.6875), and use index offsets 0, 1 and 2 in the direct A, B and C settings. In the three parent graphs use index offsets −1, 0 and 1 respectively. All five cases with index 0, count 1 and offset −1 render in the reference app. MaterialCraft reports a nonfinite pattern-function result on those five and their fallback images are excluded from the pixel counts. The direct 64² F32 case isolates a second difference. The gray conversion, gradient and input match. The pattern output differs at four pixels on rows 46–49. At (20,46) the reference stores (.321308792,.787873089,0,1) and MaterialCraft stores (.811764717,.811764717,.811764717,1). + +### Pixel quotients and volume-mask interpolation + +The volume mask matches **1,029,632/1,029,632 pixels across 116 renders**. The maximum error is zero in each format. This includes all 640,512 F32, 315,392 U16, 36,864 F16 and 36,864 U8 pixels. The [shape and axis sweeps](#volume-mask-shapes-and-axis-sweeps) give the procedural position fields, parameters and seeds. + +The first difference on the zero-rotation cylinder was an interpolation whose second endpoint is a quotient. Moving the pixel function's output to each operand showed that both endpoints matched. MaterialCraft had rounded the quotient before subtracting the first endpoint. The sphere also uses a quotient minus one when its radial extents differ. Reading 17 intermediate scalars on the 64² X sweep at seed 183, the 32² Y sweep at seed 226 and the 128² Z sweep at seed 140 gives 365,568/365,568 exact F32 values in 51 observations after the correction. + +| Direct pixel expressions | Renders | Exact pixels / compared | Maximum error | +|---|---:|---:|---:| +| Quotient, reciprocal, sums, differences and interpolations | 91 | 652,288/652,288 | 0 | + +Write q=R/G and p=R×G. Compare q, 1/G, q+B, B+q, q−B, B−q, lerp(q,B,A), lerp(B,q,A), lerp(R,B,A), lerp(p,B,A), lerp(B,p,A), lerp(B,A,q), and the four-channel output (q,q−B,lerp(B,q,A),q). Run each expression on the [signed 128² field](#3d-linear-gradient) with F32 at seeds 127 and 541. Use its top-left 64² texels in all four formats at seed 239. At 32² use F32 and seed 313 with channel c=((37x+71y+11xy+47c+3xc) mod 1021)/256−1.125. For every input replace G with .125 wherever |G| is less than .1. Sample at texel centers with nearest filtering. + +The previous cook matched 603,372/652,288 pixels with maximum F32 error 0.0000152587890625. The measured sums round once when they consume a runtime quotient. For lerp(a,b,t), a quotient or product in b can combine with the subtraction b−a. The first endpoint, a quotient used as the weight, and a quotient also returned as a separate channel preserve their individual rounding. + +### Volume-mask shapes and axis sweeps + +The counts in this subsection were measured before the [pixel quotient correction](#pixel-quotients-and-volume-mask-interpolation). All 116 renders now match. + +The shape menu assigns 0 to cube, 1 to cylinder and 2 to sphere. Cube is the default. Some earlier case names called shape 1 a box and called the default a sphere. The corrected shape names above and below use the actual control value. + +| Control | Renders | Exact pixels / compared | Maximum float error | +|---|---:|---:|---:| +| Cylinder along X | 9 | 57,111/58,368 | 9.53674316e-07 | +| Cylinder along Y | 9 | 57,165/58,368 | 9.53674316e-07 | +| Cylinder along Z | 9 | 58,368/58,368 | 0 | +| Six settings on X, Y and Z, cube | 18 | 129,024/129,024 | 0 | +| Six settings on X, Y and Z, cylinder | 18 | 128,359/129,024 | 7.15255737e-07 | +| Six settings on X, Y and Z, sphere | 18 | 111,882/129,024 | 9.53674316e-07 | + +Including the earlier 35 cases, **1,008,141/1,029,632 pixels** match in 116 renders. U8, U16 and F16 match every measured pixel. F32 matches 619,021/640,512 with maximum error 3.81469727e−6. The new cylinder cases with equal X/Y radii match in both radial directions. Unequal radial extents expose a float discrepancy with rotation set to zero. The axial Z sweep matches all 58,368 pixels. All 18 cube cases match, including tilted nonuniform cubes. + +Use a linear RGBA32F position input. For side N and integer pixel coordinates (x,y), set one component to (x+Ny+.5)/N². Set the other position components to .5 and alpha to one. Choose world-space positioning and change the center and extent on the swept axis only. The other center components are .5 and the other extents are one. Run the following cylinder cases on each axis with zero rotation. + +| N | Center | Extent | Scale | Feather | Seed | Outputs | +|---:|---:|---:|---:|---:|---:|---| +| 128 | .5 | 1 | .5 | .5 | 41 | F32 | +| 128 | .5 | .625 | .375 | .15625 | 71 | F32 | +| 64 | .3125 | .8125 | .34375 | .375 | 131 | U8, U16, F16, F32 | +| 32 | .6875 | .3125 | .75 | .21875 | 227 | F32 | +| 64 | .5 | .75 | .5 | .25 | 431 | F32, replace the swept component by .6875+(x+64y−2048)×2⁻²¹ | +| 64 | .3125 | .8125 | .34375 | .375 | 577 | F32 | + +For each of the three shapes, repeat the linear sweep on each axis using these six F32 settings. Center the swept component at .5 for N=128, .3125 for N=64 and .6875 for N=32. The rotations are in turns. + +| N | Size | Scale | Feather | Rotation | Seed | +|---:|---|---:|---:|---|---:| +| 128 | (1,1,1) | .375 | .15625 | (0,0,0) | 97 | +| 128 | (.625,.625,1) | .375 | .15625 | (0,0,0) | 140 | +| 64 | (.8125,1,.625) | .34375 | .375 | (0,0,0) | 183 | +| 32 | (1,.3125,.75) | .75 | .21875 | (0,0,0) | 226 | +| 64 | (.8125,1,.625) | .34375 | .375 | (0,0,.25) | 269 | +| 32 | (1,.3125,.75) | .75 | .21875 | (.0625,−.125,.1875) | 312 | + +### Distance output channels, axis wrapping and cutoffs + +| Original controls | Renders | Exact pixels / compared | Maximum U8 / U16 levels | Maximum F16 / F32 error | +|---|---:|---:|---:|---:| +| Unconnected source, both output kinds and both Combine settings | 64 | 294,912/294,912 | 0 / 0 | 0 / 0 | +| Connected source with the opposite output kind | 14 | 21,504/21,504 | 0 / 0 | 0 / 0 | +| Connected source with static axis wrapping | 56 | 86,012/86,016 | 28 / 7,248 | .110534668 / .110588416 | +| Single-center cutoff, both settings of Combine | 168 | 258,048/258,048 | — | — / 0 | + +Without a source, grayscale returns the distance ramp and color returns the same ramp in RGB with alpha one. Connecting a grayscale source to color output, or RGBA to grayscale output, returns zeros in every requested channel. These 46 color or conflicting-source renders previously returned the wrong channel count. For the first row use 32² tiled and 64×128 open masks. Test empty, full and single-corner masks at strength zero, a sparse mask at 79.5, and a center site at 31. Use seed 179+37j, j from zero. Run F32 for each, and also U8, U16 and F16 for the sparse field. Use the [mask and source formulas](#connected-distance-sources-and-cellular-patterns). + +For the next two rows, use 32² gray and 64×32 RGBA sources. Combine is on. Use empty, full, corner and sparse F32 masks, then repeat the sparse mask as F16, U16 and U8. For the conflicting kinds retain the connected controls' strengths 31, 31, 32 and 41.375 for those four mask layouts. For static controls use a matching source, constant strength 47.25 and the four wrapping settings. Use seeds 307+19j in each group. Static tiling previously matched 77,637/86,016 pixels. The four remaining differences are the same sparse gray texel (31,18) with Y wrapping alone. Its F32 values are .113228783 in MaterialCraft and .223817199 in the reference. + +For the cutoff row place a site at the center of each source size and choose radii .25, 1, 2, 3, 4, 8 and 16 pixels at seeds 509+23j. Set strength to radius×256/min(W,H). Test Euclidean, Manhattan and Chebyshev distances with both axes open or both tiled. Exactly at the radius, the source comes from the current texel. For example, at (14,16) in the 32² Manhattan case with radius 2, the gray output with Combine off is −.109375 before gray-input conversion. With Combine on the stored F32 result is negative zero. Including the boundary in the spread previously matched 257,890/258,048 pixels with maximum error 1.1875. + +The [connected-source and cellular measurements](#connected-distance-sources-and-cellular-patterns) retain 184,320/184,320 exact pixels on the matching-source format matrix. The mixed metric matrix now matches 630,768/630,784, maximum F32 error .096614778. The 16 residuals are on sparse wrapped masks. The radius sweep retains 950,270/950,272, maximum .765625. Directional distance still matches 342,528/342,528 across both outputs. The two Cells 4 roots still match 19,151 and 15,949 of 173,312 pixels respectively, with their first difference at the scatter map. + +### Connected distance sources and cellular patterns + +A connected distance source supplies the nearest qualifying site's texel inside the radius and the current texel beyond it. With Combine enabled the gray channel or the alpha channel is attenuated. RGB remains the sampled site's color inside the radius and the current texel's color outside. The 120 gray and RGBA controls below previously matched 64,706/184,320 pixels. Maximum errors were 255 U8 levels, 65,535 U16 levels and 1.859375 in F16 and F32. + +| Original distance controls | Renders | Exact pixels / compared | Maximum error | +|---|---:|---:|---:| +| Matching gray and RGBA source formats | 120 | 184,320/184,320 | 0 | +| Three metrics and four tiling settings | 168 | 630,766/630,784 | 0.096614778 | +| Empty, isolated and full masks at small distances | 54 | 202,752/202,752 | 0 | +| Sparse-site radius sweep and connected-source cutoffs | 120 | 950,270/950,272 | 0.765625 | + +Use both a grayscale source and a matching RGBA source. At pixel (x,y), use channel c=((13x+7y+5xy+19c) mod 127)/64−.375, with c=0 for luminance. Repeat the nine layouts and strengths from the [32² mask controls](#directional-distance-and-mask-propagation) with both axes tiled and Combine on and off. Also run 64×32 with both axes open and Combine on, and 32×64 with both tiled and Combine off. The two centered horizontal sites are at x=W/4 and 3W/4. Run each case in F32 at seed 431+29j from j=0, and repeat the single-center and sparse cases in U8, U16 and F16. + +For the metric row use 64×128 mask-only, 64×32 RGBA and 32² grayscale. Combine is on. Use both open and both tiled with Euclidean, Manhattan and Chebyshev distance, then wrap each axis alone with Euclidean distance. Use F32, seed 197+29j, and strengths 31, 0, 47.25, 159.75, 41.375, 367 and 16. The masks are empty, a site at (1,2) twice, full, sparse, and centered twice. Use (13x+23y+11xy) mod 109=0 for the standalone sparse mask and (13x+11y+7xy) mod 67=0 for the sources. Two grayscale Manhattan cutoff pixels differ only in the sign of zero. The other 16 differences occur on sparse wrapped fields. All 114,688 RGBA pixels in this matrix match. For the small-distance row use both open and both tiled, the same three sizes, Euclidean distance and strengths 0, .125 and 2 at seeds 541, 578 and 615 for each mask. + +For the last row, run the sparse standalone mask at radii 1.25, 2.875, 3.875, 4, 4.25, 5.5, 6.75, 7.875, 8, 8.125, 8.6875, 9.875, 10.34375, 11.5, 12.75, 14.125, 15, 15.875, 16, 16.125, 19.75 and 23.875 pixels at seeds 283+17j. Use 128² tiled Euclidean and 64×128 open fields for all three metrics. All 901,120 mask pixels match. The connected controls use Combine off on 64×32 RGBA and 32² gray, both open and both tiled. At seeds 653+17j use an empty mask at strength 31, a corner, empty and full mask at zero, a corner at 1, a sparse mask at 413 and .25, and a center at 4096. Two RGBA texels differ on the tiled rectangular sparse field at strength 413. + +The open-field results require a final unit propagation step. The measured tiled square cases retain their original winners without it. At zero distance the mask gradient is black. For a positive subpixel radius, qualifying sites are white. When the source is connected and an open field is empty, the result copies its first texel. The 32 directional-distance root renders retain all 342,528 exact pixels. + +| Cellular root | Renders | Exact pixels / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---| +| Cells 4 | 17 | 19,151/173,312 | 231 / 65462 / 0.9066162109 / 1 | +| Cells 4 v2 | 17 | 15,949/173,312 | 253 / 58223 / 0.8881835938 / 1 | + +For the additional cellular controls use the eight [banded-input cases](#panoramic-line-light-and-horizon-across-the-seam). Use defaults at 16². At 64², 128² and with rectangular input, respectively, set scale to 9, 17 and 6, disorder to .21875, .75 and .4375, source selection to 1, 2 and 1 and the additional random seed to 17, 255 and 41. Disable non-square expansion only for the rectangular input. The second version also sets disorder speed to .75, 1.625 and .3125. The totals include the original defaults, changed parameters, four formats and independent 32² fields. + +Read the input bridge and each reachable filter's first output. At 64² in U16 the first version's two grayscale FX-Maps each match 3,935/4,096 before Distance. Their maxima are 63,743 and 65,535 levels. At 128² the maps match 15,914 and 15,823 of 16,384, both with maximum 65,535 levels. The second version's RGBA16 FX-Map is the first difference at both sizes, with 3,941/4,096 and 15,811/16,384 exact and maximum 65,535 levels. The input bridges match. Both cellular roots remain in progress. + +### Directional distance and mask propagation + +Directional distance matches **342,528/342,528 pixels** in 32 renders across the value and UV outputs. The maximum error is zero in all four storage formats. The previous batch matched 342,473 pixels. Its first differing buffer was the distance primitive receiving a mask with its source disconnected. + +| Direct mask controls | Renders | Exact pixels / compared | Maximum error | +|---|---:|---:|---:| +| Square and rectangular fields, sparse through full coverage | 56 | 516,096/516,096 | 0 | +| Single-site threshold | 11 | 11,264/11,264 | 0 | +| Tiled 32² mask, nine layouts and distances | 9 | 9,216/9,216 | 0 | + +For the first row use 64², 128×64 and 128² with both axes tiled, and 64×128 with both axes open. In each size use the following eight F32 masks in order, with seed 167+37j from j=0. A single center site uses strength 256√2. A site at (1,2) uses 37.25. Set sites where (13x+23y+11xy) mod 109=0 and use 17.375. Put sites on column floor(W/3) and row floor(H/2) and use 23.75. Alternate .5 with .50000762939453125 on (x+2y) mod 13=0 and use 9.75. Empty and full masks use 59 and 19. Repeat the sparse mask and strength at the last seed. Also store the center and sparse cases in U8, U16 and F16. Before the correction, 289,400/516,096 pixels matched. Maximum errors were 124 U8 levels, 32,019 U16 levels, .4881744384765625 in F16 and 1 in F32. + +For the threshold row set a single F32 center texel on an otherwise black 32² mask. Use strength 31 and seeds 431+29j for values −.25, 0, 2⁻¹⁶, .0625, .25, .499, .5−.5/65535, .5, .5+.5/65535, .75 and 1. The first accepted value is .5. For the last row of the table use strengths 31, 32, 41.375, 127, 16, 31, 31, 33 and 41.375 at the same seed progression. The masks are a center site, a site at (1,2), (13x+11y+7xy) mod 67=0, sites at (8,16) and (24,16), a center site, empty, full, .4375 on (x+3y) mod 13=0, and the repeated sparse mask. + +The radius in pixels is strength×min(W,H)/256. Seed locations use normalized texel centers rounded to the nearest unsigned 16-bit coordinate. At each power-of-two jump, compare the sites from the eight neighbors and the center. Halve the jump through one pixel. A Euclidean search with an extra refinement disagrees at (99,0), (64,30) and (39,55) on the tiled 128² sparse case. The observed F32 values there have bits 3e86a510, 3e260066 and 3e25ccdc. Attenuation uses the [runtime square root](#runtime-pixel-square-roots) and a fused multiply-add. Connected sources have a separate color and attenuation path and remain under comparison. + +For the full graph, repeat the original four renders, the [four-format and independent comparisons](#four-format-inventory-comparison) for both ports, and the [modular field matrix](#normal-maps-panoramas-and-primitive-shapes) on each port. Number the gray fields in the order angle map, distance map, input. For settings A, B and C the output selector is (1,0,1), maximum distance (.1875,.3125,.0625), angle (.125,.25,.375), distance-map multiplier (.6875,.25,1) and angle-map multiplier (.25,.625,0). Set the angle-map offset to .375. Each port matches 39,168/39,168 pixels in its nine modular-field renders. + +### Panoramic line light and horizon across the seam + +| Root | Renders | Exact RGBA pixels / compared | Maximum error | +|---|---:|---:|---:| +| Panorama line light | 30 | 241,152/241,152 | 0 | +| Panorama plane light | 22 | 199,155/199,936 | 4.76837158e-07 | +| Straighten panorama horizon | 26 | 212,480/212,480 | 0 | + +The [pixel quotient and interpolation change](#pixel-quotients-and-volume-mask-interpolation) also resolves the line-light and horizon differences in the [original panorama matrix](#normal-maps-panoramas-and-primitive-shapes). On the same release binary each root matches all 171,264 pixels in those 18 renders. In the eight banded-input renders below, the preceding binary matched 41,188/41,216 line-light pixels and 41,172/41,216 horizon pixels. The maximum errors were 2.56299973e−6 and 3.05175781e−5 respectively. Both now match all 41,216. + +Number the input pins j in identifier order. At integer texel (x,y) set B=((floor(x/3)+2floor(y/5)+j) mod 5)/4. Gray inputs use B. For color use (u,v,B,A), with normalized texel centers (u,v). Set A=.875 where xW−W/8 and .375 elsewhere. Run 16² F32 at seed 71, all four formats at 64²/193, 128² F32/317, 64×32 input on a 64² F32 canvas/449, and repeat 64² F32/503. + +For the eight line-light renders set the UV endpoints to (.9375,.40625) and (.0625,.71875), camera to (.125,−.0625,.1875), line rotation to −.15625 and thickness to .15625. Use color (.8125,.375,.1875), temperature 3975 and exposure .75. For 16², 64², 128² and the rectangular input, set both pattern and color mode to 0,1,2,0 respectively. Use distance-from-origin mode at 128², ground/ceiling for the other sizes, and up-vector mode 1 only for the rectangular input. For the horizon use defaults at 16² and horizon points (.9375,.34375) and (.0625,.71875) for the other cases. Use rotation .0625 at 128² and −.1875 elsewhere. Disable horizon correction only for the rectangular input. + +For four further line- and plane-light renders use F32. At 64² select world, distance-from-origin and ground/ceiling positioning with seeds 239, 310 and 381 respectively. At 128² use world positioning with seed 452. Set color mode 2 and pattern 4 at 64², pattern 1 at 128². For the line use the 64² and 128² banded inputs above, with world endpoints (−.875,.4375,1.25) and (.5,−.3125,1.125). For the plane use the 64² A and 128² B [plane-light fields](#plane-light-splatter-symmetry-and-waveform-comparisons) with world position (−.75,.4375,1.25). All 28,672 line-light pixels match. On the plane, the four outputs match 4,084/4,096, 4,049/4,096, 4,079/4,096 and 16,247/16,384. Their first three maximum errors are 5.96046448e−8 and the last is 1.19209290e−7. The plane remains in progress. + +### Normal maps, panoramas and primitive shapes + +| Root | Renders | Exact pixels / compared | Maximum U8 / U16 levels | Maximum F16 / F32 error | +|---|---:|---:|---:|---:| +| Normalize normal map | 18 | 171,264/171,264 | 0 / 0 | 0 / 0 | +| Transform normal map | 18 | 171,264/171,264 | 0 / 0 | 0 / 0 | +| Panoramic 3D position | 18 | 171,264/171,264 | 0 / 0 | 0 / 0 | +| Panorama line light | 18 | 171,207/171,264 | 0 / 0 | 2.38418579e-07 / 7.86781311e-06 | +| Panorama shape | 18 | 171,264/171,264 | 0 / 0 | 0 / 0 | +| Panorama shape 2 | 18 | 171,264/171,264 | 0 / 0 | 0 / 0 | +| Straighten panorama horizon | 18 | 171,231/171,264 | 1 / 204 | 0.0029296875 / 0.00311285257 | +| Cube | 18 | 171,264/171,264 | 0 / 0 | 0 / 0 | +| Cube position, normal, depth and UV | 60 | 685,056/685,056 | 0 / 0 | 0 / 0 | +| Hemisphere | 18 | 171,264/171,264 | 0 / 0 | 0 / 0 | + +The totals include the original defaults, original changed settings, four requested output formats, the independent 32² screen and nine additional renders per output. For the new fields let u and v be texel-center coordinates. In each input, number pins j in identifier order and channels c from zero. Use H=((37x+41y+7xy+53j) mod 509)/508. For ordinary color inputs add 61c+5xc to the numerator before the modulus. Gray inputs use H. For normal inputs use (.5+.5a,.5+.5b,.5+.5√(1−a²−b²),.25+.75H), with a=.625(2u−1) and b=.625(2v−1). The transform's normal input uses j=−1. Position inputs use (u,v,.25+.5H,1). + +Use F32 inputs and the following output settings. Use defaults at 16²/seed 43. Use A at 64²/157 in U8, U16, F16 and F32. Use B at 128² F32/293 and with 32×16 inputs at 32² F32/599. Use C at 32² F32/463 with every input value v replaced by 2.5v−.75. Repeat A at 64² F32/751. Generators use the same sizes and seeds. Let k equal 1, 2 and 3 for A, B and C. + +| Control | A, B and C | +|---|---| +| Normalization | No exposed numeric control. | +| Normal transform | Matrix (.8125,.34375,−.1875,1.125) for A/C and (0,−.75,1.25,0) for B. Offset (.1875,−.3125) for A/B and (−.5,.0625) for C. Normal format 1 only in B. Disable scale/skew compensation only in C. | +| Panoramic position and line light | Up vector 1 only in B. For the light, position mode 1 only in B, grid enabled only in C, UV endpoints (.1875,.25) and (.71875,.4375), height .625, distance 1.375, color mode k mod 3, temperature 4375 and exposure 1.25. | +| Panorama shape | Same matrices and offsets as the normal transform. Shape k mod 3, color (.75,.34375,.625), intensity 1.375, soft borders .1875, hotspot size .375 at (.25,.6875). Disable background only in C and texture only in B. | +| Panorama shape 2 | Same matrices, offsets, shape and color. Use color mode k mod 3, temperature 4375, exposure 1.25 and hardness .6875. Use image gamma 1 only in B and disable background only in C. | +| Straighten horizon | Points (.1875,.34375) and (.71875,.59375). Horizontal rotation .0625 in B and −.1875 in A/C. Disable horizon correction only in C. | +| Cube and four cube buffers | Orientation (.0625k,−.1875), size (.625,.875,1.125). Scale .34375 in B and .5 in A/C. Disable non-square expansion only in C. | +| Hemisphere | Scale .625 in B and .875 in A/C, size (.6875,1.125), rotation .09375k. Disable non-square expansion only in C. | + +The four 64² F32 cube buffers contain 3,187 distinct position tuples, four normals, 2,969 depths and 3,187 UV tuples. The transformed normal map contains 4,094 distinct tuples. All four stored components count toward an RGBA pixel match. + +The line-light differences begin in its pixel processor. On the signed field, pixel (6,2) stores 1.98653376 in the three color channels in the reference and 1.98652911 in MaterialCraft. For the horizon, the input matches. Its pixel processor differs at two texels in the 64² A case. Pixel (39,49) has reference red .756740689 and MaterialCraft red .753627837. Both discrepancies were resolved in the [panorama seam comparisons](#panoramic-line-light-and-horizon-across-the-seam). + +### Tiled diagonal directional blur + +A centered shear moves a periodic square image onto an axis-aligned sample grid. The blur reduces full interior texel runs at the mip level for their width, with separate fractional endpoint reads. An inverse shear samples the stored result back on the output grid. Both shears filter at the precision of their input. The integer comparisons use U16 intermediates. + +Across 96 original diagonal renders, exact RGBA pixels improved from 35,337 to 1,046,248 out of 1,351,680. + +| Output | Renders | Previous exact | Current exact / compared | Previous maximum | Current maximum | +|---|---:|---:|---:|---:|---:| +| RGBA8 | 16 | 4,953 | 117,809/163,840 | 200 | 1 | +| RGBA16 | 16 | 239 | 97,055/163,840 | 51479 | 1 | +| RGBA16F | 16 | 12,188 | 163,827/163,840 | 0.811889648 | 0.00048828125 | +| RGBA32F | 48 | 17,957 | 667,557/860,160 | 0.867096573 | 3.57627869e-07 | + +Use a center impulse in R, a vertical stripe through the center in G and a horizontal stripe in B. For U8 and U16 set alpha to H=((97x+43y+7xy) mod 1024)/1023 and round the four channels to the nearest stored integer. Floating inputs use 3H−1.25 for alpha. In order, use turns .125, −.125, .375, .625 and .875 on F32, then .125 on U8, U16 and F16. For each, take (radius, square side) pairs (2,32), (2.375,128), (3.125,64), (5.375,128), (11.25,64), (7.5,256). Set intensity to 256×radius/side and seed to 479+37j+19k for zero-based angle/input index j and radius index k. Use all four output formats at radii 3.125 and 5.375, and F32 elsewhere. + +At .125 and −.125 turns with F32 input and F16 output, all 40,960 pixels match. Differences in the other diagonal renders include fractional channel rounding and the projection of angles beyond the first quadrant. The untiled .125, tiled .0625, and tiled .21875 controls retain larger differences. Across these 36 renders the maxima are 192 U8 levels, 49,199 U16 levels, 1.095703125 in F16 and 1.09612465 in F32. + +| Inventory root | Renders | Exact / compared | Maximum U8 / U16 | Maximum F16 / F32 | +|---|---:|---:|---:|---:| +| `anisotropic_blur.sbs/anisotropic_blur` | 8 | 112,190/115,712 | 1 / 0 | 0 / 0 | +| `anisotropic_blur.sbs/anisotropic_blur_grayscale` | 8 | 112,563/115,712 | 1 / 0 | 0 / 0 | +| `blur_hq.sbs/blur_hq` | 9 | 40,496/132,096 | 8 / 0 | 0 / 0 | +| `blur_hq.sbs/blur_hq_grayscale` | 9 | 96,534/132,096 | 4 / 0 | 0 / 0 | + +The [four-format inventory](#four-format-inventory-comparison) gives the changed inputs and settings. Each of the four roots matches on its independent F32 input and its changed 64² four-format matrix. The differences above are in archived U8 cases. Six previously exact roots with reachable directional filters also matched all 790,528 pixels in 52 renders, maximum zero. + +### Short oblique directional blur + +| Direct footprint | Renders | Exact pixels before | Exact pixels after / compared | Maximum error after | +|---|---:|---:|---:|---:| +| 128² impulse and stripes | 10 | 27,936 | 163,840/163,840 | 0 | +| Rectangle, U8 output | 10 | 3,535 | 81,920/81,920 | 0 | +| Rectangle, U16 output | 10 | 1,113 | 81,906/81,920 | 1 | +| Rectangle, F16 output | 10 | 0 | 81,918/81,920 | 7.62939453e-06 | +| Rectangle, F32 output | 50 | 0 | 292,389/409,600 | 3.57627869e-07 | + +A projected reach of at most one texel uses three taps. Multiply radius−.5 by the larger absolute sine or cosine of the angle. Divide each direction component by its image dimension, then divide both by the larger resulting magnitude to obtain the texel offsets. The first tap points toward positive coordinates on the original dominant axis. Filter the two outer taps at source precision. With reach d and center weight m=.5/(.5+d), weight each side by d×m. Multiply the first tap by its weight, accumulate the center with a fused multiply-add, then accumulate the last tap the same way. + +Use the [128² impulse, stripes, signed alpha and radius sequence](#quarter-turn-directional-blur) at .125 and .0625 turns. The first five radii at both angles now match exactly. The fourteen wider renders match 4,832/229,376 RGBA32F pixels, maximum .750733346. On the 108 straight-angle controls all 1,769,472 pixels still match. + +For rectangles use H=((37x+71y+11xy+47c+3xc) mod 1021)/1020 in channel c. Use 3H−1.125 for F32 inputs and round(255H) for U8. In order, the angles are .03125, .09375, .15625, .21875, −.0625, .3125, .375, .625, −.137 and .913 turns. Use 64×128 for indices 0, 2, 5, 7 and 9 and 128×64 elsewhere. Use U8 source at indices 3 and 6, F32 otherwise. Disable both tile axes at indices 2, 4 and 9. Use radii .5625, 1, 1.32, 1.5, 1.5625, 1.875, 2.25, 5.375 and 12.25, with intensity four times the radius and seeds 187+19j by zero-based radius index. Use F32 output for every radius and add U8, U16 and F16 at radii 1.32 and 5.375. The table covers only the 80 short cases. The other 70 rectangle renders match 61/573,440 pixels, with maximum errors of 192 U8 levels, 49,199 U16 levels, 1.056640625 F16 and 1.06214854 F32. + +| Root | Renders | Exact pixels / compared | Maximum U8 / U16 levels | Maximum F16 / F32 error | +|---|---:|---:|---:|---:| +| Color anisotropic blur | 24 | 226,638/269,568 | 16 / 0 | 0 / 0.0235294104 | +| Grayscale anisotropic blur | 24 | 232,976/269,568 | 16 / 0 | 0 / 0.0196078718 | +| Color high-quality blur | 18 | 63,731/171,264 | 8 / 0 | 0 / 0.00784316659 | +| Grayscale high-quality blur | 18 | 125,647/171,264 | 4 / 0 | 0 / 0.00784316659 | + +For the nine added root renders use the [modular fields and size/seed matrix](#normal-maps-panoramas-and-primitive-shapes). Set intensity to 5.25, 18.5 and 10.25 in A/B/C. Set quality to 1, 0 and 1. For anisotropic blur set anisotropy to .6875, .3125 and 1 and angle to .0625, .15625 and −.21875 turns. The 128² case differs in all four graphs. The direct wider impulse and rectangle probes reproduce the outstanding error in a single directional primitive. + +### Quarter-turn directional blur + +Anisotropic noise matches **171,264/171,264 grayscale pixels in 18 renders**, maximum error zero. The [noise settings and seeds](#color-conversion-gradient-height-and-histogram-controls) include the rotated 128² and 32² cases. At 128² the directional stage improved from 15,226/16,384 to 16,384/16,384. Every sampled stage matches on the 64², 128² and rectangular-input controls. The final outputs comprise 122,880 U16 pixels, 32,000 F32 pixels and 8,192 each U8 and F16. + +A single directional filter on an original 128² linear RGBA32F field matches **1,769,472/1,769,472 pixels in 108 renders**. Use an impulse at (64,64) in R, its column in G and its row in B. Use 3H−1.25 for alpha, where H=((97x+43y+7xy) mod 1024)/1023. Test turns 0, .25, .5, .75, 1, −.75, −.25, −.5 and 1.25. For each angle use radii .5625, .75, 1, 1.25, 1.5, 2, 2.375, 2.5, 3.125, 4.375, 5 and 8.25, with seed 113+17j at zero-based radius index j. At this size set intensity to twice the radius. + +For a nonzero whole-quarter turn, project radius−.5 by the F32 factor immediately below one before calculating weights. With projected reach d, the center weight is .5/(.5+d). The short-window side weight is d times that weight. For a wider window retain d−(ceil(d)−1) for the partial outer texel. At radius 1, the quarter-turn impulse stores F32 bits 3e7fffff one row above center. At radii 2 and 5, its central texel stores 3e800001 and 3dccccce. At zero turns the same three readings along the horizontal axis are 3e800000, 3e800000 and 3dcccccd. + +Forty additional 64×128 quarter-turn renders on the original modular RGBA8 field, with both axes wrapped or both clamped, match **327,680/327,680 pixels**. For channel c round 255 times ((37x+71y+11xy+47c+3xc) mod 1021)/1020 to the nearest byte, with ties to even. Use radii .75, 1.25, 1.5, the next F32 above 1.5, 2, 2.5, the next F32 above 2.5, 3.125, 4.375, 9.5 and 15.5625. Multiply the radius by four for intensity. Use seed 97+23j and F32 output. At radii 1.25, 2 and 4.375 also use U8, U16 and F16. Each of those three formats contributes 49,152 pixels. + +Before the [short oblique filter correction](#short-oblique-directional-blur), the same 128² impulse and stripes also differed at .125 and .0625 turns. At .125 turns, 32,768/196,608 pixels match, maximum .750733346. At .0625 turns, 0/196,608 match, maximum .433206394. That earlier measurement included both short and wide kernels. + +### Alpha maximum and one-texel reductions + +The alpha-maximum helper matches **36/36 RGBA output pixels in 33 renders**, maximum error zero. Its output has one texel for inputs through 256² and four for a 512² input. The 128² position and alpha field previously selected a different tuple with maximum component error .968627451. Reading the whole reduction chain on this input showed that the final processor received an exact 2×2 image. At requested exponent −1 it samples the lower-right texel. The earlier cook treated the one-texel allocation as logical exponent zero. + +For the 128² field at seed 347, take u and v at texel centers and H=((59x+41y+5xy) mod 1021)/1020. Store (u,v,H,.125+.625H) as RGBA32F, replacing alpha at (3,125) by .9375. For fourteen further renders, use original RGBA8 fields with channels x mod 253, y mod 251, (31x+29y) mod 251 and (47x+59y+13xy) mod 191. Set a marked texel in quadrant j to (29+53j,211−47j,37+59j,255). Number quadrants in row-major order. Place the mark one eighth or seven eighths of the way across each axis. Use a 16² field at seed 73, four 128² fields at seeds 137, 173, 277 and 373, and a 64² southwest field in all four formats at seed 433. Also test 256² northeast/577, 512² southeast/661, 128×64 northwest/739 at a 128² parent, 128² with opposing northwest and southeast marks/809, and 128² southwest/953. These cases improved from 11/17 to 17/17 output pixels. The 128² northwest field returns RGBA8 levels (75,69,59,190) expressed as F32. The two-mark field returns (188,70,214,255). + +| Direct controls | Renders | Exact pixels or typed values / compared | Maximum error | +|---|---:|---:|---:| +| Pixel size, logarithm and sample displacement | 72 | 3,333/3,333 | 0 | +| Pixel canvas, absolute, parent and first input | 12 | 86,420/86,420 | 0 | +| Filter size relative to a one-texel input | 16 | 1,088/1,088 | 0 | +| Uniform color function | 8 | 148/148 | 0 | +| Stamp opacity | 24 | 444/444 | 0 | +| Typed value function | 24 | 24/24 | 0 | + +At parent sides 16, 32, 64, 128, 256 and 512, request offsets (−8,−8), (−5,−5), (−8,−2) and (−2,−8), seed 127. Return the two size components and the two pixel-center coordinates in RGBA32F. Repeat with the base-two size logarithm. For the third output, sample a linear F32 image at the pixel center plus (.25,.25) divided by the reported size. Set the source channels to (x/N,y/N,((17x+23y+9xy) mod 251)/250,1). The raster clamps each axis to one texel while the logarithm keeps the requested negative exponent. For exponents −1, −2, −3 and −4 the reported size is −2³¹, 2³⁰, 2²⁹ and 2²⁸. The position still uses physical texel centers. + +The propagation controls use parents of 16, 64, 128 and 256 at seed 131. Follow the (−8,−2) processor with a transform whose width offset relative to input is −1, 0, +1 or +3. For example, at parent 128 and offset +3 the transform is four texels wide. Uniform color encodes the two logarithms as .5 + log₂(size)/16 and the two reported sizes as .5 + size/2³². Test relative (−8,−2) and absolute (−2,3). A separate diagnostic that assigns a variable inside the pixel-ratio function, then reads it in another parameter, matches 64/296 pixels in sixteen renders. The reference returns zero for that read. This side effect remains open. + +### Material bundles and the eighth irradiance pass + +| Root | Recorded renders | Exact output pixels / compared | Maximum stored error | +|---|---:|---:|---:| +| Material transforms, all five outputs | 74 | 856,320/856,320 | 0 | +| Two-material blender, three outputs | 46 | 513,792/513,792 | 0 | +| Four-material blender, three outputs | 46 | 513,792/513,792 | 0 | +| Eight-material blender, three outputs | 46 | 513,792/513,792 | 0 | +| Raytraced irradiance IS pass 8 | 18 | 136,704/136,704 | 0 | + +The material roots use four archived settings, followed by a four-format and independent render of each output. Add nine renders per output using the procedural channels H and input-port ordering from the [color and histogram controls](#color-conversion-gradient-height-and-histogram-controls). Use default controls at 16²/seed 47, A in all formats at 64²/151, B at 128²/307, C on signed 32² input/467, B on 32×16 input at 32²/557, and A at 64²/719. The five transform outputs cover diffuse, specular, height, opacity and emissive. Use scale/rotation/offset (75,137.5)/.125/(.1875,−.3125) for A, (125,50)/.25/(−.125,.4375) for B and (62.5,150)/−.1875/(.5,.0625) for C. + +For the blenders, let m number materials from one and k be 1, 2 or 3 for A, B or C. Set each material transform to (.25+.0625m, .0625(m+k), .25+.03125m, .6875−.03125m). Set the height range to (.0625m,.9375−.03125m) and specular range to (.03125m,.875−.015625m). The mask index is (floor(x/4)+3floor(y/5)) mod 8. The grayscale mask uses byte level (37×index) mod 256. The color mask uses its three low bits as red, green and blue, each either 0 or 255, with alpha 255. Compare all three composited outputs. + +The eighth irradiance pass previously timed out. Finishing the original 128² default, seed 42 and changed settings plus the 256² default gave 114,688/114,688 RGBA16F pixels. These archive measurements used the signed-product implementation. The four 64² storage formats, the independent 32² case and nine additional cases matched 22,016/22,016 pixels both before and after the wide-blur and function-call changes. The combined storage totals are 119,040 RGBA16F, 8,960 RGBA32F and 4,352 each RGBA8 and RGBA16. + +For those nine new cases, use u=(x+.5)/N, v=(y+.5)/N and H=((53x+31y+9xy+43) mod 257)/256. Write original F32 channels for position (u,v,H,1), normal (.5+.3(u−.5),.5+.3(v−.5),1,1), environment (.25+u,2v,H²,1), previous (v,H,u,.125+.75u), emissive (.75u,.375H,.5v,1), sample table (u,v,H,1−H), noise (H,H,H,1) and height (v,v,v,1). Use defaults at 16²/seed 37. For the rest set shape scale .8125, UV tiling 1.5 and displacement .125. Run shape 0/pass 1 at 32²/173 and repeat at seed 439. Repeat seed 173 with previous=(.5H,.25v,1−u,1). This changes every one of the 1,024 output pixels and both images match exactly. At 16² use shape 1/pass 3/seed 359 with black environment and emissive, and shape 2/pass 2/seed 251 in all four output formats. + +### Literal pixel divisors and RGB to Lab + +| Comparison | Renders | Exact stored pixels / compared | Maximum error | +|---|---:|---:|---:| +| RGB to Lab | 29 | 212,480/212,480 | 0 | +| Original quotient and contraction controls | 252 | 741,888/741,888 | 0 | + +The RGB-to-Lab root matches 126,976 RGBA16, 12,288 RGBA8, 14,336 RGBA16F and 58,880 RGBA32F pixels. Before the change the root matched 152,444/212,480. All 58,880 full-float pixels had a differing component, at most 1.19209290e−7. The archived defaults, changed parameters and four-format cases are under [color conversion and related controls](#color-conversion-gradient-height-and-histogram-controls). + +For each of the two Keep Alpha settings, run a 16² grid (u,v,(x XOR y)/15,1) at seed 31 with u=x/15 and v=y/15. In an original linear RGBA32F field, define Hⱼ=(((31+16j)x+(47−4j)y+(7+6j)xy+101j) mod 1021)/1020. Use H at 64²/163 in four output formats and repeat F32 at seed 587. Use 3H−1.125 at 32²/281 in F16 and F32. At 128²/373 use R,G,B=.04045+(((x+7jy) mod 67)−33)/65536 for j=1,2,3, with alpha H₃. Also pass 16×32 pixels at 32²/499 in F32. The input bridge stores RGBA8 in the measured reference cases. + +A runtime numerator divided by a literal denominator uses the float32 reciprocal of that literal. A sampled denominator of the same value uses the [runtime pixel reciprocal](#runtime-reciprocal-and-3d-gradient-contrast). For 255 the two multipliers have bits 3b808081 and 3b808080. For numerator c34928a6, the quotients have bits bf49f299 and bf49f298. Adding offset befff6a8 through a single-use quotient gives bfa4f6f7 and bfa4f6f6. A separately consumed quotient rounds before addition. The regression covers a folded 510/2 denominator as well. + +For direct controls, sample R,G,B,A from a linear RGBA32F field. For each of ten denominators (255,100,200,500,.3999999761581421,−3.625,10,1,7,3), put that value in G. Emit R divided by the literal, R/G, the literal quotient plus B, or (200R+127.5) divided by the literal. For 255 add a folded denominator and a graph returning both a quotient and a sum using it. Use 16²/61 and 32²/367 F32 plus 64²/211 in four formats. Start with the upper-left crop of the original signed 128² [four-channel hash field](#3d-linear-gradient), multiply R by 64, and at 32² replace R with ((37x+53y+5xy) mod 2047)/16−19.875. Set the first two pixels to (127.5,G,0,1) and (.375,G,.5,1). All 225,792 F32 pixels in 126 renders match bit for bit, as do the 172,032 pixels in each of U8, U16 and F16. + +### Vector equality, Lab to RGB and SBS round trips + +| Comparison | Renders | Exact stored pixels / compared | Maximum error | +|---|---:|---:|---:| +| MaterialCraft Lab-to-RGB root | 25 | 180,736/180,736 | 0 | +| Six independent comparisons using the edited functions | 36 per application | 50,688/50,688 per application | 0 | +| Same comparisons using the reference app’s saved and reopened copy | 36 per application | 50,688/50,688 per application | 0 | +| Reference app conversion with the edited file, then with its saved copy | 25 per file | 180,736/180,736 per file | 0 | +| Reference app comparisons after MaterialCraft Save As | 36 | 50,688/50,688 | 0 | +| Reference app conversion after MaterialCraft Save As | 25 | 180,736/180,736 | 0 | + +The RGB and RGBA equality functions compared red twice when reading the first two lanes from each operand. Four selectors in the existing function library now read red and green. The Lab-to-RGB root bypasses conversion only for fully transparent black. A green-only texel with zero alpha previously took that bypass. The old root matched 180,157/180,736 pixels. The largest errors were 255 in U8, 65,535 in U16 and 1 in F16 and F32. The corrected root matches all 123,904 U8, 9,216 U16, 10,240 F16 and 37,376 F32 pixels. + +Use the archive, four-format inputs and independent field under [color conversion and related controls](#color-conversion-gradient-height-and-histogram-controls). For ten new renders, use the modular fields, sizes, formats and seeds in [RGB to Lab](#literal-pixel-divisors-and-rgb-to-lab). At 128² set L to (0,.04,.08,.08000001,.07999999,.5,1) indexed by x mod 7, adding 1/8192 where y mod 4 equals 1. Set the two chroma channels to .5+((x mod 16)−8)/128 and .5+((y mod 16)−8)/128. + +For six green-channel and transparency cases set mask=(x+3y) mod 16 and z=1+((37x+11y+7xy) mod 255). Byte channel j is 1+((z+43j−1) mod 255) when bit j is set, zero otherwise. Run 16²/seed 73 F32, 32²/193 in four formats and 64²/379 F32. For direct function tests compare the first two, three or four lanes against (0,0,0,0) or (.25,−.375,1,2). Add the same byte field divided by 256 to the chosen offset and output one for equal, zero otherwise. The regression enumerates all eight three-lane masks and all sixteen four-lane masks. With the previous file, the three-lane comparisons matched 7,392/8,448 pixels for each offset and the four-lane comparisons matched 7,920/8,448. + +For the file check, open a byte-identical copy of the edited functions package in reference app 16.0.7, save a copy there, then load the saved file. Both RGB first-pair selectors read (0,1) before and after saving. The RGBA function retained both (0,1) selectors and both (2,3) selectors. Run the direct comparisons above using a relative dependency on each file. For the native conversion check, nearest-sample the byte RGBA bridge, compare all four lanes to zero with the selected file, and otherwise combine the public Lab conversion of RGB with the original alpha. Run the same 25 render cases. Substituting the pre-fix file in that graph reproduces the original 180,157/180,736 count. + +For the MaterialCraft-to-reference handoff, open the edited function library in MaterialCraft and use Save As to write a separate SBS file. Open that saved file in reference app 16.0.7. It exposes 201 resources. Both three-lane selectors and the first pair from each four-lane operand read (0,1). The second pairs read (2,3). Set the equality and conversion graphs’ relative dependency to that specific Save As file and repeat all 61 renders above. Both comparisons are pixel-exact. Repeating the same Save As and reopen with the pre-fix library gives 180,157/180,736 conversion pixels, maximum 65,535 U16 levels. + +The separate complete color-quantization package did not open in the reference app with either function library, including when supplied with an original procedural lookup image. It also did not open after saving from MaterialCraft with its existing 0.1.3 format header. A separate original constant graph opens with a current header and fails to open with 0.1.3. Changing only the complete package’s header still left its import unresolved. The round-trip results in the table cover the edited function file and the measured consumers. + +### Color conversion, gradient, height and histogram controls + +| Root or output group | Recorded renders | Exact pixels / compared | Maximum stored error | +|---|---:|---:|---| +| sRGB to ACEScg | 18 | 171,264/171,264 | 0 | +| Linear gradient 3 | 18 | 161,419/171,264 | U16 2, F32 3.05175781e−5 | +| Radial gradient | 18 | 171,264/171,264 | 0 | +| Height blend, both outputs | 32 | 342,528/342,528 | 0 | +| Histogram scan | 18 | 171,264/171,264 | 0 | +| Histogram and cumulative distribution | 32 | 4,608/4,608 | 0 | +| Mean of least variance, color iteration | 18 | 171,264/171,264 | 0 | +| Mean of least variance, grayscale iteration | 18 | 171,264/171,264 | 0 | +| Color median filter | 18 | 171,264/171,264 | 0 | +| Anisotropic noise | 18 | 167,393/171,264 | U16 17, F32 .000274673104 | + +Each single-output root includes four archived renders, four 64² storage formats, an independent 32² render and nine additional settings. For the two-output roots each archive render captures both outputs, then the format and additional cases select one output at a time. The median filter also matched 131,072/131,072 pixels in a separate repeat of the four original settings and the four storage formats. Those repeats are excluded from the table. The [earlier input and format matrix](#four-format-inventory-comparison) identifies the original fields. + +For the nine additional settings, number pins j in identifier order and channels c from zero. Define H=((47x+67y+13xy+29c+11cx+71j+3jy) mod 1021)/1020. Use rounded 16-bit PNG levels, taking c=0 for grayscale. At 16² use default controls, seed 37 and F32 output. At 64² use setting A, seed 173 and U8/U16/F16/F32. At 128² use B/307 and F32. At 32² use C/439 with 2.5H−.75 in F32. Also run B on 32×16 input at 32²/571 and repeat A in F32 at seed 701. Generators render at the stated output size. + +| Root | A | B | C | +|---|---|---|---| +| Linear gradient 3, tiling/position/rotation | 3/.3125/1 | 7/.8125/2 | 2/.4375/3 | +| Radial gradient, shape/non-square expansion | 1/off | 2/on | 3/off | +| Height blend, position/contrast/mode/opacity | .3125/.6875/1/.8125 | .625/1/0/.4375 | .1875/.375/1/.75 | +| Histogram scan, position/contrast/invert | .3125/.6875/off | .625/1/on | .4375/.375/off | +| Histogram resolution exponent | 6 | 5 | 7 | +| Least variance, intensity/smoothness/criterion/Gaussian | 10/.125/1/off | 16/.75/0/on | 24/.5/1/off | +| Median, kernel/filter/affect alpha | 1/1/off | 0/0/on | 1/1/off | +| Anisotropic noise, X/Y counts, smoothness/interpolation | 5/13, .625/.5 | 7/19, .375/.1875 | 3/23, 1/.75 | + +For the radial gradient set points to (.28125,.40625) and (.75,.84375). The color least-variance control affects alpha only in B. For anisotropic noise enable rotation and Y amount by resolution only in B, and disable non-square expansion only in B. The color conversion has no exposed numeric control. At 64² F32 its output has 4,038 distinct RGBA tuples. The two height outputs have 3,210 distinct heights and 2,324 mask values. The 64-bin histogram has counts from 7 to 85 and its cumulative distribution has 64 distinct values. + +For linear gradient 3, the first differing stage is its grayscale 16-bit FX-Map. At 64² A the stamp matches 3,840/4,096 texels, maximum one level. At 128² B it matches 16,249/16,384, also by one level. The root's U8 outputs match 8,192/8,192. F16 matches 7,936/8,192, maximum .00048828125. In anisotropic noise the upstream field matches. At B the first difference is the directional blur, 15,226/16,384 at 128², maximum 18 levels before the final output. The 32² B blur misses one pixel by one level. The root's U8 outputs match 8,164/8,192, maximum one level, and F16 matches 7,796/8,192, maximum .00048828125. + +### Wired spline helpers and shape mapping + +| Root | Renders | Exact pixels / compared | Exact integers / compared | Maximum integer-image / F32 error | +|---|---:|---:|---:|---:| +| Shape mapper | 29 | 310,784/310,784 | — | 0 / 0 | +| 2D spline transform | 64 | 87,552/87,552 | 18/18 | 0 / 0 | +| Bridge distance | 33 | 54,528/54,528 | — | 0 / 0 | +| Initial spline length | 27 | 43,776/43,776 | — | 0 / 0 | +| Spline tangents | 27 | 43,296/43,776 | — | 63578 / 1.95677358 | + +The spline cases add three original coordinate and tangent buffers, with counts 1, 3 and 2 supplied through Integer value processors wherever the graph accepts a count. At 16² (circle) or 32×16 (line and signed curve), populate rows 0 to 2 and leave later rows zero. Let θ=2π(x+.5)/width. The circle and signed coordinates are (.5+(.25−y/32)cos θ, .375+(.1875+y/64)sin θ+y/16, 1, −1), with tangent (−sin θ,cos θ,0,1). For the signed curve, transform its x component to 2.5x−.875 and negate its y component in row 1. For the line use D=(x+.5)/width−.5 and slope S=.5 in the first half, −.25 in the second. Its coordinates are (.5+D,.375+S×D+y/16,1,−1), tangent (1,S,0,1). + +The spline transform uses matrix (1.125,−.25,.375,.75) on the circle, and (0,−1,1,0) on the other buffers. Set offset (.1875,−.3125) and switch on reverse direction for both curved inputs. For distance and length, feed parent size (2,1) with non-square correction enabled on curved buffers, or (.75,1.5) with correction disabled on the line. Use tangent mode 1 on curved inputs and 0 on the line. Render 16² F32/seed 89, 32²/197 with four requested formats and 64² F32/439. For the integer port use one render per size. Its nine wired results are three 1s, three 3s and three 2s. The transformed 32² line contains 97 different stored coordinate tuples. + +The transform's wired image ports and bridge distance retain F32 storage inside their wrapper. Their direct four-format runs verify U8, U16, F16 and F32. The six earlier [wired bridge distance cases](#height-distance-texture-mapping-skew-and-weave) now match all 10,752 pixels. With three splines the tangent helper matches 7,971/8,448 on the line, including 955/1,024 in F32 at 32². Its 64² F32 line reaches error 1.95677358. Both curved inputs match 8,448/8,448 on this helper. + +For shape mapper, the five earlier comparison sizes and four-format inputs are listed in the [inventory comparison](#four-format-inventory-comparison). Add an F32 coordinate grid with R=x and an alternating-column pattern x mod 2 at 128², plus coordinate fields at 16², 256², 64×32 into 64² and a 128² repeat. At 64² store .1875x−2.125 in all four output formats. The seeds for 16², 128² grid, 128² binary, 256², signed 64², rectangular input and the repeat are 89, 131, 233, 331, 421, 509 and 601. Use defaults at 16² and otherwise radius .3125, width .6875, seven patterns, five segments, rotation .1875 and alternate flipping. Use shape 0 for the rectangular case and 1 elsewhere, nearest filtering for the binary case. + +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 | +|---|---:|---:|---:| +| Composite matte | 19 | 168,448/168,448 | 0 | +| Levels property controls | 48 | 141,312/141,312 | 0 | +| Blend opacity controls | 48 | 196,608/196,608 | 0 | + +The matte graph’s grayscale Levels output-high property directly reads an absent user input. The reference app reports a stored property value of (1,1,1,1), which remains in effect. With foreground byte 64 and background byte 191, Levels outputs 64 and the final F32 result is .8120107650756836. Before the fix Levels returned zero and the blend produced .7490196228027344. On the original nine renders, the root improved from 659/132,096 to 132,096/132,096 exact pixels. The ten additional renders match all 36,352 pixels. The combined totals are 122,880 U8, 8,192 U16, 8,192 F16 and 29,184 F32. + +Use the 128² default, reversed-input and seed-42 fields, the 256² default and the 64² four-format and independent 32² cases. For the ten additional cases use F32 values (.25,.75) and (.75,.25) for foreground/background at 16², then (0,1) at 32². At 64² in four formats and 128² in F32, fill each input with Hⱼ=(((37+4j)x+(61−2j)y+(7+2j)xy+37j) mod 1021)/1020 using j=1,2. Use seeds 103,164,225,286 and 347 respectively. Also connect just the .25 foreground or just the .75 background at a 32² parent, seed 419. The root exposes no matte-opacity control. + +For independent Levels controls use (H₁,H₂,H₃,(x mod 5)/4) as linear RGBA input. Compare the default output-high, a scalar literal .375, an absent scalar, an available scalar, adding .1875 to either scalar, and packing either scalar into all four lanes. Use 16², 64² and 32² at seeds 89,168 and 247 with bound values .375,.75 and 0. At 64² capture all four formats, elsewhere F32. Only the direct absent scalar keeps the stored output-high. Before the fix this control matched 0/17,664 pixels. + +On an independently authored blend with scalar inputs H₁ and H₂, compare the default opacity, an absent getter with and without a leading percent sign, that same getter with a disconnected literal, the getter plus .1875, a bound getter, a bound zero and a local write of .3125 followed by a read. Use the same three input sizes and formats, seeds 71,168,265 and bound values .375,.75,.125. The blend’s output is fixed at 64² for these controls. Each direct missing-variable case improved from 24/24,576 to 24,576/24,576 exact pixels. A missing variable used in arithmetic contributes zero, and a zero-valued binding is honored. + +### Stored integer value outputs + +The four-integer root matches **41/41 typed vectors**, maximum absolute component error zero. A stored graph input of (−31,0,1,2147483647) cooks to (−31,0,1,−2147483648). Independent scalar, two-, three- and four-component processors matched **132/132 typed results** across immediate constants and direct input reads. In 32 input cases per width, the reference app’s value constructor and graph property preserved all 320 requested integer lanes. At the processor and graph output ports, all 320 matched rounding to binary32 followed by conversion back to signed 32-bit integer. The positive endpoint rounds to 2³¹ and stores −2³¹. For example, 16777217 stores 16777216, −16777219 stores −16777220, and 2147483583 stores 2147483520. The regression checks uncached and cached outputs at all four widths. A MaterialCraft save and reload also preserves all ten authored constant values across scalar and vector integers, floats, Boolean and text. After reopening, the authored integer 16777217 is intact and its cooked output is 16777216. The authored pair (−2147483648,2147483647) is intact and both cooked lanes are −2147483648. + +For the 32 boundary cases let T=2²⁴ and M=2³¹. In order, take 0, 1, −1, 257, 65537, −65537, 2²³+1, T−1, T, T+1, T+2, T+3, −T−1, −T−3, 2²⁵+1, 2²⁵+3, 2³⁰+1, M−258, M−193, M−192, M−191, M−129, M−128, M−65, M−64, M−63, M−3, M−2, M−1, −M, −M+1 and −M+65. In case j, fill lane c from index (j+7c) mod 32. Cycle parent sides 16/32/64/128 and requested U8/F16/U16/F32 with seed 29+37j. All outputs report their integer type. Also cook defaults at 16² and the first d components of (M−1,T+1,−T−3,−M+1) as a literal at 32², seed 83. The three existing scalar, two- and three-integer root cases per width also still match. + +Arithmetic inside a processor has a separate measured difference. Inserting modulo 257 before the output gives 26/132 exact typed results, maximum component error 257. Across scalar and four-component addition and subtraction controls at offsets −7 through 7 from (T,−T,2²⁹,−2³⁰), 48/94 results match, maximum error 8. A fully literal (T+1)−T returns 1 in both applications. A direct graph input set to T+1, then reduced by T, returns 0 in the reference app and 1 in this cook. + +### Unconnected function arguments + +Create an original function that returns its scalar argument and declares .1875 as the source default. Call it from a node parameter, pixel processor, stamp parameter and value processor. For each scope test five variants with a wired argument, an open argument, an open argument sharing the outer variable name, and an open argument declared connectable or explicitly non-connectable. Supply .625 at 16²/seed 79 and .3125 at 32²/seed 197. Read LUM32F for the three image scopes and a typed float for the value scope. + +Each image scope matches 2,560/6,400 pixels and the value scope matches 4/10 typed floats. Maximum error is .1875 in every scope. Wired arguments match, as does the open connectable declaration. For the remaining open declarations MaterialCraft reads the authored .1875 and the reference returns zero. MaterialCraft also uses published source defaults across open documents, including when the author changes the source value. This difference remains open. + +For a separate typed control at 16²/seed 487, pass true, integer 7, integer vectors (−2,3), (9,−8,7) and (4,3,2,1), float .1875, and float vectors (−.75,.5), (.625,−1.5,2) and (−1.375,3,2,−.25). Read bool as 0 or 1 and convert the first component of each numeric argument to float. With the value wired, 9/9 typed floats match exactly. With the value declared as the source default and the call port open, 0/9 match, with maximum error 9. The [literal-argument comparisons](#literal-arguments-inside-pixel-function-calls) use explicit wires. + +The release engine tests also cover scalar Levels controls before and after saving a package. Their expected alpha is one for an input function returning .25, consistent with the [measured endpoint controls](#integer-levels-endpoints-and-channel-mixing). + +### Literal arguments inside pixel function calls + +The color-temperature root now matches all 42,496 RGBA pixels across its 19 renders. All 29,440 F32 pixels and all 4,352 pixels in each of U8, U16 and F16 are bit-exact. The previous F32 result differed by up to 1.1920929e−7. The root exposes a scalar temperature, with a default of 3,000. The [temperature cases and scalar fit](#volume-density-dithering-and-color-temperature-controls) give the original settings and varying-input controls. + +| Independently constructed F32 controls | Renders | Exact before / compared | Exact after / compared | Maximum error after | +|---|---:|---:|---:|---:| +| Nested sum and difference, signed hash field | 24 | 134,270/141,312 | 141,312/141,312 | 0 | +| Nested arithmetic, logarithm and sine, modular fields | 48 | 247,296/282,624 | 282,624/282,624 | 0 | +| Temperature fit with warm, cool, unit or varying coefficients and full RGB | 25 | 98,576/113,920 | 113,920/113,920 | 0 | + +Create a separate four-input scalar function for each expression a×b+c×d, a×b−c×d, ln(a) or sin(a). Give each function a distinct identifier. Bind the first pair, the second pair, all four or none of the arguments to literal values (.1875, 1.25, −.375, 2.75). For the remaining arguments sample the corresponding channels of an original RGBA32F image at pixel centers. Use 16²/seed 83, 128²/311 and 32²/577. For the first row use 4H/2³²−2 with the [row-major hash](#runtime-pixel-sine-cosine-and-atlas-rotation) at index 4(yN+x)+channel. For the second row use ((73x+93y+7xy+47c+7cy) mod 1024)/256. Double this and subtract four at 32². Inlining the same expressions also matches on all 529,920 control pixels. + +When a and b are literals, their product rounds first and the other product can fuse with the sum. At (2,0) of the 128² hash field, c and d have F32 bits be7ff6a8 and bf68ddb9. The expected sum ends in 3eec6a9d. Rounding c×d first gives 3eec6a9c. A literal read inside a function also uses literal arithmetic for its logarithm and sine. The function compiler carries that information through explicit argument connections and accounts for assignments that can replace their values. + +Omitting a connection is a separate case. With the same declared defaults and both first-pair ports left open, the hash-field sum/difference agrees on 0/35,328 pixels, maximum .234375238. The four modular-field expressions agree on 0/70,656 pixels, maximum 1.67397642. The measured color-temperature root uses explicit connections for its fit. + +### Wide blur windows and bevel blur + +The bevel blur matches 311,552/311,552 grayscale pixels across all 26 renders, maximum error zero. The [bevel intensity controls](#five-texel-blur-kernels) previously matched 160,049 pixels. The current totals are 122,880 U8, 24,576 U16, 24,576 F16 and 139,520 F32. These include all three successive blur stages at the larger intensities. + +| Original controls with radius above 2.5 texels | Renders | Exact RGBA pixels / compared | Maximum error | +|---|---:|---:|---:| +| Separable impulse, stripes and signed channel | 48 | 1,081,344/1,081,344 | 0 | +| Zero-angle directional impulse and stripes | 16 | 262,144/262,144 | 0 | +| Separable modular four-channel fields | 48 | 172,032/172,032 | 0 | +| Zero-angle directional modular fields | 24 | 86,016/86,016 | 0 | +| Four shifted impulses | 42 | 1,204,224/1,204,224 | 0 | +| Rectangular and square RGBA fields, separable | 128 | 3,801,088/3,801,088 | 0 | +| Rectangular and square RGBA fields, directional | 64 | 1,900,544/1,900,544 | 0 | + +Interior runs aligned to a power of two read a single filtered texel from the corresponding one-dimensional mip level. Reduce adjacent pairs at the source precision, storing each level at the destination precision. At the boundary of a footprint with radius r, let e=ceil(r−.5) and f=r−(e−.5). An endpoint aligned with the start of a pair combines the fractional texel with its full neighbor. For example, the left sample lies 1/(1+f) texels from that endpoint and has weight 1+f. A lone endpoint has weight f. Accumulate the weighted runs from right to left horizontally and top to bottom vertically, then multiply by .5/r. On a clamped axis, coverage beyond the image contributes one weighted read of the original border texel. A 256² impulse at column 128 and radius 4 reads .0625 at column 124, 513/4096 at 125 and 255/4096 at 132. + +Use the [three-texel impulse and stripe inputs](#three-texel-blur-kernels) and the [four-channel and shifted-stripe inputs](#five-texel-blur-kernels). At seed 347 run the separable blur at intensity 17.5 on 64², 6.25/10/16.5/24.75 on 128² and 5.25 on 256². Run the zero-angle directional filter on the four 128² cases. For the modular fields use radius 2.875 at 64²/seed 797, 3.0625 at 32²/839 and 3.375 at 64²/877, with all four destination formats at 3.375. For the shifted stripes use radii 2.75, 3, 3.125, 3.5, 4, 5.25 and 8.25, seed 239, at 64², 128² and 256². + +For the final two rows use 64×128, 128×64 and 256×256. Channel c is H=((37x+71y+11xy+47c+3xc) mod 1021)/1020. Supply rounded U8 levels or F32 values 3H−1.125. In order, use intensities 6.25, 9, 13, 17.5, 23.75, 30, 31.5, 48 and 62.75 at seeds 109+58j with j starting at zero. Output F32 except at 17.5, which uses U8, U16, F16 and F32. Run the separable filter with both axes tiled and both clamped, and the horizontal directional filter tiled. The radius scales from the shorter dimension on both axes. The table counts only radii above 2.5. Oblique directional kernels are outside these measurements. + +### Five-texel blur kernels + +| Original controls with 1.5 < radius ≤ 2.5 | Renders | Exact RGBA pixels / compared | Maximum error | +|---|---:|---:|---:| +| Separable impulse, stripes and signed field | 40 | 851,968/851,968 | 0 | +| Zero-angle directional blur on the same fields | 12 | 147,456/147,456 | 0 | +| Separable four-channel field | 80 | 253,952/253,952 | 0 | +| Zero-angle directional four-channel field | 40 | 126,976/126,976 | 0 | +| Shifted stripes, separable and directional | 36 | 1,032,192/1,032,192 | 0 | + +At this radius, sample the center directly and combine the texels on each side with a filtered read at offset 2−1/(radius−.5) texels. The center weight is .5/radius. Each side has weight (radius−.5)×center weight. Filter at the source storage precision, then accumulate in F32 from left to right horizontally or bottom to top vertically. The separable blur stores its horizontal image at the destination precision. On the 128² stripe at radius 2, the outer and inner samples are .12451171875 and .25048828125. The regression also checks the raw F32 channels on the signed field. + +Use the [three-texel inputs](#three-texel-blur-kernels) for the first two rows. For the next two, define H=((33x+87y+5xy+71c+17cx+13cy) mod 1021)/1020 per channel. Use H rounded to the nearest integer level for normalized inputs and 3H−1.375 for floating inputs. Run the separable filter both tiled and untiled. Use radius and seed (1.5009765625,97), (1.71875,137) and (2.375,571) at 32². At 64² use (1.5625,109), (1.9375,211), (2.09375,389) and (2.4990234375,683). Output F32 except at radius 1.9375, which uses all four formats. For the last row, fill the four F32 channels with vertical stripes at x=1, N/8+1, N/2 and N−3. Use 64², 128² and 256², seed 239, and radii 1.50390625, 1.75, 2, 2.0625, 2.25 and 2.5. + +The bevel blur now matches all 154,880 pixels of the original 17 renders, including 128² at intensity 9. Its three blur stages each have radius 2.25 at that setting. Nine further renders extend the range. Define H=((37x+29y+11xy) mod 509)/508. At 32² use intensity 0/seed 53. At 64² use intensity 16/137 with 2.5H−.75. Both match exactly. At 128² run intensity 12.5/307 in all formats and repeat F32 at seed 797. At 256² use intensity 10.75/487. For a 64×32 source at 64² use intensity 24.5/653. + +| Bevel blur with the extended range | Exact pixels / compared | Maximum error | +|---|---:|---:| +| LUM8 | 106,545/122,880 | 3 | +| LUM16 | 8,192/24,576 | 356 | +| LUM16F | 8,192/24,576 | 0.005859375 | +| LUM32F | 37,120/139,520 | 0.00733691454 | + +At radius 3.125, shifting a single vertical impulse by one column exchanges the two measured edge weights .09953125 and .099999994. Those larger footprints still differ. The maximum F32 difference on the extended bevel matrix occurs at 256². + +### Uniform powers of two and volume lighting + +| Graph or operation | Cases | Exact RGBA or grayscale pixels / compared | Maximum error | +|---|---:|---:|---:| +| Uniform power of two, 128 independently evaluated columns per image | 80 | 1,310,720/1,310,720 | 0 | +| Uniform base-two logarithm, 128 columns per image | 9 | 145,536/147,456 | 2.38418579e−7 | +| Direct tests of the two uniform operations in four storage formats | 32 | 51,200/51,200 | 0 | +| Volume environment light | 39 | 7,898/31,488 | U8 4, U16 829, F16 .0126953125, F32 .0560382009 | +| Volume direct light | 46 | 43,038/43,264 | U8 0, U16 0, F16 .0000152587890625, F32 .00000370293856 | + +Use a node function to compute x=o+i×d for each column i=0..127, store each result in a scalar variable, then read the variable for the current column into a 128² F32 output. At seed 257 use (o,d) for the power of two of (0,1/128), (−1,1/128), (−8,1/8), (−.5,1/32768), (.625,1/16384), (−4,1/37), (−3,1/19), (32,1/64) and (−31,1/64). For the logarithm use (1,1/128), (.5,1/256), (1,1/32768), (.125,1/32), (2,1/64), (8,1/16), (1.75,1/16384), (2⁻¹²⁶,2⁻¹²⁹) and (.7,1/4096). The subnormal step flushes to zero. The logarithm differs in 15 of the 1,152 sampled columns. In a second power-of-two series, use (j/64,1/8192) for j=0..63, followed by (0,−1/4096), (−.5,1/4096), (.5,1/4096), (16,1/256), (−16,1/256), (32,1/128) and (−32,1/128). Set the seed to 311+29j. For the four-format controls, run exponents −.984375, −.015625, .9375 and −2 or logarithm arguments .625, 1.375, 1.75 and 2 at sides 16, 32, 64 and 32, seeds 277, 318, 359 and 400. + +The uniform exponential clamps the argument to [−126,126]. For its fractional part f, evaluate the degree-seven Taylor polynomial of exp(f×float32(ln 2)) in Horner order, rounding each operation to float32. Scale by the integer power of two. An exposed −.125 gives bits 3f6ac0c3. Both a literal and a uniform .9375 give 3ff52576, while a runtime pixel argument gives 3ff5257e. The negative smallest normal gives 3f7ffff4, the negative smallest subnormal gives 3f800000, and a NaN intermediate gives 00800000. Uniform log2 computes the uniform natural logarithm divided by float32(ln 2). Direct readbacks of intermediate +∞, −∞ and NaN give natural-log bits 42b17218, 00000000 and 00000000. The [per-pixel comparisons](#runtime-pixel-logarithms-and-powers-of-two) cover the separate pixel evaluations. + +For temperature-to-RGB use 1200, 1733, 2718.5, 3000, 3975, 5555, 6500, 7111.25, 9900.5 and 18000. For the scalar fit use .1875, .3125, .5625, .875, 1, 1.375, 2.25, 4.125, 7.5 and 13.125 with coefficients (.1875,1.25,−.375,2.75) and (2.75,−.25,1.375,−.625). For each series use seed 151+29j, a 32² canvas when j is a multiple of three and 16² otherwise. Each of the three operations gives 5,632/5,632 exact pixels in the node scope, 5,632/5,632 in the pixel scope and 10/10 exact typed values in the Value Processor. All maxima are zero. + +All 7,680 direct-light density pixels in the [density controls](#volume-density-dithering-and-color-temperature-controls) now match. Twelve further direct-light renders match 13,056/13,056. Use the same thin, thick and varying-density inputs. Run (a) thin defaults, (b) thick at 2700 K, (c) thick at 9900.5 K and 64², (d) thin with explicit light RGB (.1875,.5,.8125), (e) thin with ambient intensity 1.75 and RGB (.3125,.75,.1875), and (f) varying density with ambient intensity 1, RGB (.375,.7,.2), explicit light RGB (.4375,.1875,.75), UV (.375,.6875) and light intensity 2.25. Use seeds 47, 118, 189, 260, 331 and 402 respectively. Use four formats for (b) and (f), F32 elsewhere. The complete direct-light matrix is exact at U8 (7,424/7,424) and U16 (7,424/7,424). F16 has 10,751/10,752 exact pixels and F32 has 17,439/17,664. + +Read out named values immediately after initialization and after the first volume step on the 16² thin, 16² dithered, 32² thick and 32² varying-density F32 cases. For environment light the initial ray position, ray direction, noise input, dithering, step size and accumulated depth are each exact at 2,560/2,560. After one step the position and depth each match 1,280/2,560, maximum 1.96305132. Scattered light and transmission match 1,280/2,560, maximum .0574402809. For direct light the initial light color improved from 0/2,560 to 2,560/2,560 exact. Direction, ambient color, noise, step size, first position and first depth are also exact. First-step scattering and transmission match 2,560/2,560, maximum 0. The two light roots remain in progress. + +### Undefined quotients in a unit interval and panorama spot lighting + +| Output | Renders | Exact stored pixels / compared | Maximum error | +|---|---:|---:|---:| +| Panorama spot | 36 | 189,696/189,696 | 0 | +| Eight intermediate spot outputs, F32 | 24 | 24,576/24,576 | 0 | +| Inlined and called scalar intervals | 120 | 168,960/168,960 | 0 | +| Operand order, shared reads, signed zero and computed bounds | 66 | 92,928/92,928 | 0 | +| Single minimum or maximum, called and inline | 24 | 33,792/33,792 | 0 | + +The panorama spot matches 165,120 F32 pixels and 8,192 pixels in each of U8, U16 and F16. The preceding build matched 188,736/189,696, maximum 3.91726637 in F32. With a zero-size hotspot, its numerator matches at every pixel. Dividing it by zero and then evaluating max(0,min(x,1)) produced a weight of one in MaterialCraft and zero in the reference. Those 1,024 intermediate weights now match. For example, at (5,3) in the 32² border case the red output changed from 6.26762629 to 2.35035992. At hotspot size 2⁻¹² and .4375 the same intermediate was already exact. + +In a pixel function, a scalar clamp with literal bounds zero and one saturates NaN to positive zero. Returning the inner min(NaN,1) separately still gives one. Inline operands and explicitly bound function arguments both exhibit this behavior. The .25 to .75 interval returns .75 for NaN in the same operation order. Runtime bounds supplied through the texture also keep their individual minimum and maximum behavior. + +For the 36 spot renders, start with the four archive and five inventory comparisons. Define channel c of the original F32 texture as H=((37x+41y+7xy+61c+5xc) mod 509)/508. Use the defaults at 16²/43. At 64²/157 set the position to (.21875,.3125), scale .8125, color (.84375,.375,.59375), temperature 4,750, intensity 1.875 and border softness .34375. Set hotspot intensity 3.125, size .4375, falloff .65625 and position (.65625,.1875). Enable the input and the background, with color (.0625,.15625,.3125,.875). Render all four formats and repeat F32 at seed 751. The additional F32 settings are as follows. + +| Size / seed | Changes from the 64² case | +|---|---| +| 128² / 293 | Position (.984375,.4375), scale 2.625, hotspot (.03125,.84375) | +| 32² / 347 | Position (.5,0), hotspot (.5,1), softness .9375, background disabled | +| 32² / 431 | 32×16 source, softness, hotspot size and falloff zero, texture disabled | +| 32² / 577 | Background and texture disabled | +| 32² / 661 | Scale .125, hotspot size and falloff 1, temperature 8,800, texture 2.5H−.75 | + +For the final sixteen renders use the 32²/431 case. With a 32×16 source run all eight combinations of softness 0/.34375, size 0/.4375 and falloff 0/.65625. Repeat the all-zero and all-positive combinations with a 32² source. From the all-zero combination, change just one control per render. Set softness, size or falloff to 2⁻¹², disable the background, set hotspot intensity to zero, or set shape intensity to zero. + +For the independent clamp controls, choose a numerator and denominator by (x+3y+seed) mod 12 from (0,0), (1,0), (−1,0), (7,2), (−7,2), (.375,1), (.75,1), (−.25,1), (−0,−0), (1,−0), (−1,−0), (.5,2). Use 16²/83 and 64²/311 F32, and 32²/157 in all four formats. Try max(lower,min(q,upper)) and min(upper,max(q,lower)), unit and .25/.75 literal limits, and swapped operand orders. For varying limits choose (0,1), (.25,.75), (−.25,1.5), (−1,0), (0,1), (0,1), (.25,.5), (−.25,.25) by (5x+7y+seed) mod 8. Include zero and one formed by subtracting a texture component from itself and adding one. Separately expose the minimum or quotient in a second comparison, swap each bound, use negative zero, compute bounds from literals and form 0/0 with literals. For the single-extremum controls replace zero denominators with one wherever the numerator is nonzero. This retains NaNs and gives finite stored results after the selected minimum or maximum. + +### Reverse polar sampling in color and grayscale + +The color and grayscale roots each match **306,688/306,688 pixels in 28 renders**, maximum error zero. Each matrix includes 126,976 U8, 12,288 U16, 12,288 F16 and 155,136 F32 pixels. Both use the same coordinate function and a bilinear image read. The coordinate function packs the radius-times-cosine and radius-times-sine products into two lanes before adding (.5,.5). In 19 color-field controls the build with scalar product forwarding matched 174,522/174,592 pixels, maximum .00390630960. The build with [independent vector product rounding](#vector-products-in-the-direct-light-pass) and the current build each match all 174,592. + +The first 18 renders include the four archive cases, five inventory comparisons and nine [modular, signed and rectangular fields](#segment-mapping-and-normal-graph-rechecks). Add ten original coordinate and stripe inputs. Fill color channels with (x,y,x mod 2,y mod 2) for integer pixel indices, or just x for grayscale. Run F32 at 16²/seed 89, 128²/131 and 601, 256²/331 and 64²/509 with a 64×32 source. At 128²/233 replace the four channels with x mod 2, y mod 2, floor(x/2) mod 2 and floor(y/2) mod 2. At 64²/421 apply .1875v−2.125 to the coordinate field and render all four formats. Both roots expose only their input image. + +### Scalar products used by sums inside a called function + +| Measured output | Renders | Exact pixels / compared | Maximum error | +|---|---:|---:|---:| +| Two-point panorama gradient | 19 | 143,104/143,104 | 0 | +| Linear panorama gradient | 19 | 143,104/143,104 | 0 | +| Intermediate outputs of the two gradients, F32 | 38 | 97,280/97,280 | 0 | +| Independent called and inlined expressions | 156 | 459,264/459,264 | 0 | +| Earlier scalar call controls | 60 | 176,640/176,640 | 0 | + +Each panorama root now matches 127,744 F32 pixels and 5,120 pixels in each of U8, U16 and F16. The two-point gradient previously matched 138,704 of these pixels and the linear gradient matched 138,579. The original direction, color, contrast, seam, pole and coincident-point cases are listed under [panorama gradient weights](#panorama-gradient-weights). + +When a pixel function passes a scalar product or quotient to a second function, additions and subtractions inside that function can use the original factors. At texel (1,0) of the 32² linear gradient, the dot product has F32 bits 3f01187e and the width is .6875. The range helper returns bits 3f5de345. Returning the quotient in a second output channel rounds it to 3f3bc689 and changes the range result to 3f5de344. The regression exercises both graphs. + +For the 156 renders, use the [signed RGBA field, six output settings and seeds](#vector-products-in-the-direct-light-pass). Let Q be R/G or R×G and B be the blue channel. Evaluate (Q+1)/2 and (B−Q)+Q for both terms. For division also evaluate (Q−B)/3, (B+Q)×.375, (Q+B)−Q and (B−Q)−Q. For both terms repeat (Q+1)/2 while returning Q in a separate channel, and subtract max(Q,B) from the half-range within the same function. For division also evaluate (B−Q)+Q². Render each expression as a separate function with explicit arguments, then inline it. The earlier build matched 446,883/459,264. The 120 controls for [two shared products](#two-sums-sharing-the-same-scalar-products) still match all 353,280 pixels. + +### Panorama gradient weights + +| Root | Renders | Exact RGBA pixels / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---| +| Two-point panorama gradient | 19 | 138,704/143,104 | 0 / 1 / 0 / 1.78813934e−7 | +| Linear panorama gradient | 19 | 138,579/143,104 | 0 / 1 / 0 / 5.96046448e−8 | + +Both roots generate their own coordinates. Alongside the four archive renders and five [inventory comparisons](#four-format-inventory-comparison), run the ten settings below. For the two-point gradient set colors to (.8125,.1875,.5625) and (.0625,.6875,.375). The second contrast is half the first. For the linear gradient use the first position, the same two colors as top and bottom, and the first contrast. All 5,120 U8 and 5,120 F16 pixels match for each root. The two-point root has 5,116/5,120 exact U16 and 123,348/127,744 exact F32 pixels. The linear root has 5,117/5,120 and 123,222/127,744 respectively. + +| Size | Seed | First and second positions | First contrast | Output | +|---|---:|---|---:|---| +| 16² | 43 | Graph defaults | Default | F32 | +| 32² | 157 | (.15625,.34375), (.8125,.71875) | .3125 | U8, U16, F16, F32 | +| 32² | 347 | Same positions | .3125 | F32 | +| 64² | 317 | (.125,0), (.875,1) | .3125 | F32 | +| 32² | 431 | (.984375,.1875), (.015625,.4375) | .8125 | F32 | +| 16² | 577 | (.5625,.375) twice | .3125 | F32 | +| 16² | 661 | (.25,.5), (.75,.5) | 0 | F32 | + +In both roots, at 32²/157 and 64²/317, the three-component directions for the texel and first point, their dot product and its quotient each match all 5,120 pixels when exported. Both constant linear RGB endpoints of the linear gradient also match. The next function adds one to the quotient and divides by two. Its unclamped output matches only 652/1,024 and 2,496/4,096 F32 pixels, maximum 1.19209290e−7 in both cases. Let D be the stored dot product and R the F32 reciprocal of 1−.3125, bits 3fba2e8c. Rounding D×R+1 once, then multiplying by .5, reconstructs both the unclamped and clamped linear weights at all 5,120 pixels. At (1,0) of the 32² case D has bits 3f01187e and the stored quotient is 3f3bc689. Separate rounding gives 3f5de344 for the weight and the reference gives 3f5de345. The same arithmetic followed by clamping and subtracting from one reconstructs the first two-point weight at all 5,120 pixels. The two-point weighted color sum still differs at 238/1,024 and 384/4,096 pixels in the measured implementation. + +### Constants returned from pixel functions + +| Comparison | Renders | Exact pixels / compared | Maximum error | +|---|---:|---:|---:| +| Second color-selection root | 23 | 179,456/179,456 | 0 | +| Nine intermediate rotation values at 32² | 9 | 9,216/9,216 | 0 | +| Returned and inlined arithmetic with pure results | 84 | 247,296/247,296 | 0 | +| Literal and sampled division controls | 252 | 741,888/741,888 | 0 | + +The second color-selection root matches all 123,904 U8, 9,216 U16, 9,216 F16 and 37,120 F32 pixels in the [selection matrix](#scalar-arithmetic-across-a-call-argument). The 26 outstanding pixels used the perceptual distance. Its rotation helper multiplies the measured exponential by 60, then by π/180. π is returned by a zero-argument function. Dividing that constant by 180 gives bits 3c8efa35. The same numeric numerator read from a runtime variable gives 3c8efa36. Recognizing a pure constant result at the call boundary brings the radians from 17/1,024 to 1,024/1,024 and the complete perceptual distance from 998/1,024 to 1,024/1,024. The other intermediate comparisons are described under [shared scalar products](#two-sums-sharing-the-same-scalar-products). + +For the 84 independent renders, use the [signed field, six sizes/formats and seeds](#vector-products-in-the-direct-light-pass). Return a scalar V and store (R×(V/180), V/180, sin(V), sqrt(V)). Use π, 1.125×2.375+.4375, an explicitly passed π, an explicitly passed abs(G)+.625, π from a function with an unused varying argument, π through a second zero-argument call and π forwarded through a second single-argument call. Repeat each expression inline. Before the change the same graphs matched 194,555/247,296 pixels. Both the called and inlined varying case still match all 35,328 pixels. + +Two additional controls return an assignment of π or sequence an assignment of the varying argument before returning π. Inlined and called versions together match 32,768/70,656 in 24 renders, maximum 5.96046448e−8 in F16 and 8.74227766e−8 in F32. All U8 and U16 pixels match. These results were the same on both measured revisions. + +### Two sums sharing the same scalar products + +| Comparison | Renders | Exact pixels / compared | Maximum error | +|---|---:|---:|---:| +| Second color-selection root | 23 | 179,430/179,456 | 3.57627869e−7 F32 | +| Normalized lightness difference at 32² | 1 | 1,024/1,024 | 0 | +| Complete perceptual distance at 32² | 1 | 998/1,024 | 1.19209290e−7 F32 | +| Original graphs with two shared products | 120 | 353,280/353,280 | 0 | + +In the [color-selection matrix](#scalar-arithmetic-across-a-call-argument), 41 more root pixels match after preserving the same unrounded product across two sums. All 123,904 U8, 9,216 U16 and 9,216 F16 pixels match. The remaining 26 differences are in the 32² F32 perceptual-distance case. In the normalized lightness term, the numerator and denominator each matched at all 1,024 pixels when exported separately. Exporting their quotient previously gave 926/1,024. The sum and difference share two lightness values scaled by 100. Both operations contract the same scaled value when used together. + +For independent controls use the [direct-light signed field, sizes, formats and seeds](#vector-products-in-the-direct-light-pass). Form P=R×B and Q=G×A, then export P+Q and Q−P in two channels. Repeat with P=100R and Q=100G, swap the output channels, and reverse either sum's operand order. With the four varying factors, also expose P or Q as a third channel, divide the two results, and reverse the declaration order while keeping the output connections. These 20 graphs each have six renders. At input (bfd8e681,c00ec5b1,c05f9255,c020d2bc), written as F32 bits, (P+Q,Q−P) gives (41386778,bea0a9ae). Requesting the difference first gives (bea0a9ab,41386779). Exposing a product separately preserves its rounded value. + +The remaining rotation contribution differs at 66/1,024 pixels, with maximum 3.87430191e−7. The hue in degrees, its offset from 275, scaled width, negative square and exponential each match all 1,024 intermediate values. The conversion to radians matches only 17/1,024, maximum 1.19209290e−7. With the measured exponential E, float32(60E) multiplied by float32(π/180) reconstructs every reference radian value. MaterialCraft’s effective factor is one F32 step higher. The square-root chroma term is exact. The complete root remains in progress. + +### Scalar arithmetic across a call argument + +The second color-selection root matches **179,389/179,456 grayscale pixels in 23 renders**. Its nine archive, changed four-format and independent cases are now exact. The 14 additional renders match 47,293/47,360. All 123,904 U8, 9,216 U16 and 9,216 F16 pixels match. In F32, 37,053/37,120 match, maximum absolute error 5.06639481e−7. The 67 differing pixels all use the perceptual color-difference mode at 32². Observing that distance directly gives 949/1,024 exact F32 values, maximum 1.78813934e−7. + +For the additional inputs use N×N texels, u=(x+.5)/width, v=(y+.5)/height and Hⱼ=(((41+6j)x+(73−4j)y+(7+2j)xy+47j) mod 1021)/1020. Store (H₀,u,v,H₁) and (H₂,H₃,1−u,v) as linear RGBA32F. Take the eight rows below with seeds 79+71j, j starting at zero. At 16² use defaults. For the other rows use fixed color (.17,.57,.89) and distance weights (.875,.625,1.4375). + +| Parent | Distance mode | Use color input | Threshold | Fade | Outputs | +|---|---:|---|---:|---:|---| +| 16² | Default | Default | Default | Default | F32 | +| 64² | 1 | Yes | .3125 | .4375 | U8, U16, F16, F32 | +| 32² | 0 | Yes | .75 | .125 | F32 | +| 64² | 2 | No | .625 | .3125 | F32 | +| 32² | 3 | Yes | .5 | .6875 | U8, U16, F16, F32 | +| 64² | 4 | Yes | .8125 | .5 | F32 | +| 128² | 1 | Yes | .4 | .75 | F32 | +| 32² with 16×32 inputs | 1 | Yes | .3125 | .4375 | F32 | + +On the changed 64² case and the additional 64² mode-1 field, the RGB distance, selected distance, threshold and quotient each matched 8,192/8,192 before the fix. The next helper subtracts that quotient from one. Its output improved from 2,932/8,192 to 8,192/8,192. A scalar product or quotient with a single reader can round together with the addend inside a simple called addition or subtraction. A second reader of the product retains the rounded result. Original arguments still evaluate in their wired order. + +Nine independent graphs match **158,976/158,976 pixels in 54 renders**, maximum error zero. Use the top-left 16², 64² and 32² of the original linear RGBA32F [signed hash field](#3d-linear-gradient), multiply green by .75, and set the first two texels to (3.25,.3,1,.0625) and (−3.4875,3.625,.875,−.625). Use seeds 47,223,449. Test F32 at each size and U8, U16 and F16 at 64². Compare an inline B−R/G, that same operation through a two-argument helper, the reverse subtraction, addition, B−RG, a literal divisor 3.625, two readers of the quotient, two readers of the addend, and a wholly literal 7.75/3.625 passed to the helper. For R,G,B with F32 bits c022f465,bfb54d77,3f4cdf41, B−R/G returned from the helper stores bf7f5030. Returning the quotient alongside it gives bf7f502f and 3fe617b8. + +A tenth helper that both subtracts the quotient and adds it back internally still matches 16,011/17,664 pixels, maximum one U16 level or .000751018524 in F32. The measured correction covers the single-operation helper. + +### Vector products in the direct-light pass + +| Comparison | Renders | Exact RGBA pixels / compared | Maximum error | +|---|---:|---:|---:| +| Volume direct light, final output | 46 | 43,264/43,264 | 0 | +| Vector products returned through calls | 96 | 282,624/282,624 | 0 | +| Sums of two, four and eight returned products | 6 | 3,840/3,840 | 0 | + +All 7,424 U8, 7,424 U16, 10,752 F16 and 17,664 F32 direct-light pixels match. Use the [volume light fields, seeds and parameters](#uniform-powers-of-two-and-volume-lighting). The last differing pixel was red at (2,60) in the changed 64² F32 render. At that pixel the secondary lighting processor now stores .007045745849609375 in F16. Forcing that stage to F32 gives bits 3be6ffff in both engines. The final red now has bits 3c198a4c. + +For the independent graphs, take the upper-left 16², 64² and 32² corners of the signed 128² [four-channel hash field](#3d-linear-gradient), multiply green by .75, and replace the first two texels with (3.25,.3,1,.0625) and (−3.4875,3.625,.875,−.625). Use seeds 47, 223 and 449 respectively, selecting all four formats at 64² and F32 elsewhere. Have a function return ((a,b)×(c,d),d). Call it with (R,G,B,A) and (B,A,G,R), then sum the two returned vectors. Repeat with vector-by-scalar multiplication by c, with the two product lanes swapped, and with an assignment returning d in the third lane. For each version, export the sum, then expose each returned product’s first lane in turn, then expose the first call’s third lane. At the second texel the red sum has F32 bits 3df6666c. Exposing the first product changes the red sum to 3df66660. Reading the other component keeps the first value. Each single-consumer component contracts with its addend using its evaluated factors, including when its sibling performs an assignment. All 594,432 pixels in the [scalar packing and call controls](#pixel-products-carried-through-vector-lanes-and-calls) also match. + +The eight isolated ambient samples explain the original rounding discrepancy. For sample i let aᵢ be its stored alpha and let uᵢ be the F32 product of (1−aᵢ) and channel coefficient 3e5b2d9a, 3ea31892 or 3f800000 (F32 bits). With background b=.03310475870966911, every isolated color channel equals the rounded b×uᵢ. Start the eight-term sum with FMA(b,u₀,round(b×u₁)), apply FMA(b,uᵢ,sum) for i=2 through 7, then multiply by .125. This reconstructs every reference RGB value at 64². MaterialCraft’s normal F16 secondary stage now matches all 12,288 RGB components. At forced F32, 4,088, 4,090 and 4,089 of 4,096 components match in R, G and B. + +A separate difference survives inside the secondary stage. Its normal F16 alpha matches at 3,109/4,096 pixels, maximum .05224609375. In the observed mean, reference alpha equals the eighth ambient sample at all 4,096 pixels. A two-call control returning a pair (set a variable to x, read that variable) reproduces this ordering difference. Explicitly sequencing the write before the read in each call gives matching results. The final direct-light output matches in all 46 cases above. + +### Pixel products carried through vector lanes and calls + +| Comparison | Renders | Exact stored pixels / compared | Maximum error | +|---|---:|---:|---:| +| Scalar products and sums through vector components or reusable function calls | 108 | 594,432/594,432 | 0 | +| Volume ambient-direction helper, fixed sample count | 18 | 78,336/78,336 | 0 | +| Same helper, sample count read from a texture | 9 | 38,670/39,168 | F32 5.96046448e−8 | +| Volume direct light | 46 | 43,263/43,264 | F32 .00000370293856 | +| Volume environment light | 39 | 7,898/31,488 | U8 4, U16 829, F16 .0126953125, F32 .0560382009 | + +A varying scalar product used only in a pixel addition rounds once with the addend, including when the product passes through a vector constructor, a component selector or a function return. Reading a different component preserves that behavior. When the product itself is also output, both consumers see its rounded value. A product of two literals rounds before addition. For R, G and B with F32 bits bfd8e681, c03e5cec and c05f9255, R×G+B gives 3fc60290 and the separate product and sum give 3fc60292. MaterialCraft retains the factors already evaluated in each call. The regression checks both operand orders and the next random draw after a sibling component consumes the first draw. + +Start with the signed 128² [four-channel hash field](#3d-linear-gradient). Use the upper-left 16²/seed 53, 64²/241 and 128²/373. Render F32 at all three sizes and U8, U16 and F16 at 64². Form R×G directly, in the first lane of (R×G,A), in a scalar function return, and in a function returning the same pair. Add B in either operand order. Also output the product alongside the sum, read the sibling lane when present, and repeat with literal factors 5 and .618034005. These 18 graphs previously matched 545,872/594,432 pixels. The largest errors were one U16 level, 9.53674316e−7 in F16 and 1.90734863e−6 in F32. + +For the ambient-direction helper, encode sample index i, noise and sample count N in the first three F32 channels. Use the direct-light iteration-four noise at 16²/0 and 64²/42 with i=4 and N=32. For other cases use i=(x+3y) mod N and noise=((37x+71y+11xy) mod 1021)/1020. Use (side,seed,N) of (32,93,32), (64,271,32), (128,509,37) and (32,719,19). For the last case apply 3×noise−.75. Render all four formats at 64²/271 and F32 elsewhere. Repeat the six inputs with a literal sample count of 32, and with both i=4 and N=32 held literal. The varying-index phase uses (i+1)×float32(.618034005)+noise with one rounding. With literal i, the product rounds first. The remaining 498 mismatches are in the two F32 cases with a changing sample-count input. + +The [volume light inputs and format matrix](#uniform-powers-of-two-and-volume-lighting) give 7,424/7,424 pixels each in U8 and U16, 10,752/10,752 in F16, and 17,663/17,664 in F32 for direct light. At iteration prefixes five and six, separately read ray position, depth, and scattering/transmission at 16² with defaults and 64² with changed albedo (.3,.6,.9). These twelve images match 26,112/26,112 pixels. At prefix six the ambient direction, origin, step, maximum distance, distance along the ray, visibility and iteration index each match 4,352/4,352. A separate cosine threshold differs by 4.37113883e−8. In the changed 64² F32 case, the complete iteration outputs at prefixes 9, 17, 25 and 33 match 16,384/16,384. The final stored output differs in red at (2,60), with bits 3c1999d4 in MaterialCraft and 3c198a4c in the reference. The difference is also present in the background term. The environment-light pass uses a random draw in its first dithered step. Its per-pixel [random starting state](#pixel-processor-random-draws) remains unresolved. + +The node release suite, formatting, strict workspace Clippy, layers and the ten WebAssembly checks passed. The same executable reproduced all 180,736 Lab-to-RGB pixels, 212,480 RGB-to-Lab pixels and 42,496 blackbody pixels. + +### Volume density, dithering and color-temperature controls + +| Root | Renders | Exact RGBA pixels / compared | Maximum U8 / U16 levels | Maximum F16 / F32 error | +|---|---:|---:|---:|---:| +| Volume environment light | 39 | 7,898/31,488 | 4 / 829 | 0.0126953125 / 0.0560382009 | +| Volume direct light | 34 | 25,144/30,208 | 0 / 1 | 1.52587891e-05 / 3.70293856e-06 | +| Blackbody | 19 | 34,048/42,496 | 0 / 0 | 0 / 1.1920929e-07 | + +The two light passes each have twelve new controls in addition to the [surface and volume comparisons](#3d-surface-and-volume-render-passes). Set the position to RGBA8 (128,128,128,255) and the noise to zero. Bind original 128² F32 distance and density fields. The environment pass also uses a flat RGBA8 environment (64,128,192,255) and a 16² RGBA32F sample table (.25,.25,1,1). Unless specified, use distance −.125, dithering 0, absorption 1 and iteration 0. Store F32. + +| Side | Seed | Density | Change | +|---:|---:|---:|---| +| 16 | 53 | 0 | Empty volume | +| 16 | 109 | 1/1024 | Three renders with the stated defaults, dithering 1, or distance +.125 | +| 16 | 109 | 1/16 | Stronger density | +| 32 | 211 | 1/128 | Absorption 2, four output formats | +| 32 | 373 | (u+v)/64 | Dithering .5, absorption .75, iteration 1. Use 128² atlas texel centers (u,v). | +| 32 | 377 | 1/128 | Absorption 2, field of view 37, camera UV (.1875,.6875) | +| 16 | 691 | 1/1024 | Repeat of the zero-dither thin volume | + +For environment light, 6,400/7,680 new pixels match. The 16² thin volume is exact with dithering 0 and changes to 0/256 with dithering 1, maximum .00543540716. The varying density case matches 0/1,024, maximum .0560382009. Direct light matches 4,516/7,680 new pixels. On the thick volume it matches 1,023/1,024 at U16, maximum one level, and 291/1,024 at F32, maximum 2.98023224e−8. + +The blackbody root retains the [temperature and format comparisons](#color-temperature-range-reductions-sky-parameters-and-polygon-paths). Original pixel graphs isolate the scalar fit and the RGB conversion. In an N² F32 texture, set input x=start+(row×N+column)×step. Use (N,start,step,seed) of (16,1200,37.75,127), (64,1300,4.125,281), (32,2500,.1875,337), (128,9000,.6875,433) and (32,.1875,1/1024,701). For coefficients driven by a texture, use a=((17+23×column+7×row) mod 256)/64−.5, b=((31+13×column+19×row) mod 256)/128+.125, c=((5+3×column+17×row) mod 256)/64+1 and d=.375. + +| Five F32 renders per operation | Exact / compared | Maximum error | +|---|---:|---:| +| Fit with (.1875,1.25,−.375,2.75) | 18,799/22,784 | 5.96046448e-08 | +| Fit with (2.75,−.25,1.375,−.625) | 22,447/22,784 | 4.76837158e-07 | +| Fit with (1,1,1,1) | 22,784/22,784 | 0 | +| Fit with texture coefficients | 22,784/22,784 | 0 | +| RGB conversion with alpha 1 | 11,762/22,784 | 1.90734863e-06 | + +For the first, second and texture-coefficient sets, an independently assembled pixel graph predicts all 68,352 reference fit outputs. Evaluate p using the reusable power function on (x,d), and output (a×b+c×p)/(b+p). When that graph exposes p, numerator, denominator and quotient as four channels, MaterialCraft also matches every component of all 68,352 pixels. The fixed-coefficient discrepancies persist when calling the fit as a nested function. + +### Quad, swirl, trapezoid and vector morph comparisons + +| Root | Renders | Exact pixels / compared | Maximum U8 / U16 levels | Maximum F16 / F32 error | +|---|---:|---:|---:|---:| +| quad transform | 23 | 204,032/204,032 | 0 / 0 | 0 / 0 | +| quad transform grayscale | 23 | 204,032/204,032 | 0 / 0 | 0 / 0 | +| swirl | 18 | 171,264/171,264 | 0 / 0 | 0 / 0 | +| swirl grayscale | 18 | 171,264/171,264 | 0 / 0 | 0 / 0 | +| trapezoid transform | 18 | 171,262/171,264 | 1 / 0 | 0 / 0.00343325734 | +| trapezoid transform grayscale | 18 | 171,262/171,264 | 1 / 0 | 0 / 0.000473022461 | +| vector morph | 18 | 171,264/171,264 | 0 / 0 | 0 / 0 | +| vector morph grayscale | 18 | 171,264/171,264 | 0 / 0 | 0 / 0 | + +Every row includes the four original defaults, seed and parameter renders, the 64² four-format comparison, the independent 32² field and nine additional controls at 16² to 128². Use the [polar-field formula, rectangular edge pattern, signed range and seeds](#segment-mapping-and-normal-graph-rechecks). For color vector morph, number the image first and the vector field second. For grayscale vector morph, number the vector field first. Each quad row also includes the five [previous quad controls](#height-distance-texture-mapping-skew-and-weave). The 128² changed corners that formerly differed at six pixels now match all 16,384. + +| Root pair | Controls after the default case | +|---|---| +| Quad | p00=(.0625,.125), p01=(.1875,.84375), p10=(.90625,.078125), p11=(.75,.9375). Disable tiling only for the signed input. | +| Swirl | Matrix (1.25,.1875,−.25,.875), offset (.15625,−.3125), amount 2.75. At 128² use −1.375. | +| Trapezoid | Top stretch .3125 and bottom stretch −.1875. At 128² use top stretch −.5. For signed input use bottom stretch .75. | +| Vector morph | Amount 3.125, or −1.375 for signed input. | + +The trapezoid pair each has two remaining differences across the archived and new comparisons. The [four-format inventory](#four-format-inventory-comparison) lists the original changed settings and port names. + +### Conditional pixel draws and White Noise v2 + +White Noise v2 matches **183,808/183,808 pixels in 76 renders**, with maximum error zero. The original 19 renders improved from 104,036/143,872 to 143,872/143,872. Across the full matrix, all 122,880 U8, 8,192 U16, 11,264 F16 and 41,472 F32 values match. This generator has no input image. + +| Root controls | Renders | Exact pixels / compared | Maximum error | +|---|---:|---:|---:| +| Defaults and previous disorder, speed and format variations | 19 | 143,872/143,872 | 0 | +| Uniform and Gaussian at three seeds | 33 | 8,448/8,448 | 0 | +| Uniform, Gaussian and Triangle at four additional seeds | 24 | 31,488/31,488 | 0 | + +Use the [original settings](#per-pixel-random-initialization) for the first row. For the second row use 16² F32 at seeds 0, 1 and 137. At each seed use uniform with disorder and speed zero. For Gaussian use (disorder,speed) of (0,0), (.25,0), and speed 1 with disorder 0, .25, .5, .75, 1, 1.25, 1.5 and 2. For each distribution in the third row, render 16² F32 at seed 509 with (−.25,.6875), 32² in all four formats at seed 317 with (.125,.6875), 64² F32 at seed 709 with (.875,1.5), and 32² F16 and F32 at seed 1021 with (1.5,.25). + +Ten intermediate scalar outputs each matched 1,024/1,024 F32 pixels when selected individually. They covered the unit draw shared by both generators, radial and angular inputs, angle conversion, cosine, logarithm, squared radius, unnormalized and normalized Gaussian values, and the Gaussian result. Use 16² at seed zero with (disorder,speed) of (0,0) and (.25,1), seed one with (.5,1) and seed 137 with (.75,1). In the complete graph with disorder and speed zero, the Gaussian branch uses the third unit draw for its radius and the first for its angle. Evaluating the Gaussian expression on its own changes that order. + +For an original conditional pixel expression, evaluate its condition first. A scalar draw shared between both arms or also used outside the conditional consumes its sample before draws private to the selected arm. Multiple shared draws follow first use in the true arm, then the false arm. Nested conditionals and draws supplying another draw's range use the same cached samples. + +| Original condition and return value | Exact pixels before | Exact RGBA pixels after / compared | +|---|---:|---:| +| (T ? A : B, C, A, B) | 2 | 9,472/9,472 | +| (T ? A : B−A, C, A, B) | 2 | 9,472/9,472 | +| (T ? (A,A) : (B,A), C, C) | 4,736 | 9,472/9,472 | +| (T ? A : A−B, C, A, B) | 4,738 | 9,472/9,472 | +| (S ? (A,A) : (D,A), C, C) | 4,736 | 9,472/9,472 | +| (T ? A : (S ? B−A : B+A), C, A, B) | 2 | 9,472/9,472 | +| (T ? A : (S ? B−A : D), C, A, B) | 2 | 9,472/9,472 | +| (T ? A−B : B−A, C, A, B) | 4,736 | 9,472/9,472 | +| (T ? B−A : A−B, C, A, B) | 4,736 | 9,472/9,472 | +| (T ? E : B−E, C, A, B) | 3 | 9,472/9,472 | + +A, B, C and D are separate unit-range scalar draw nodes. E is a draw with range A. Repeated letters reuse the same node. T is normalized texel-center x < .5 and S is B < .5. Render each expression at 16² F32/seed 0, 32² F32/17, 32² in four formats/137 and 64² F32/613. All 94,720 pixels match every channel, with maximum error zero. For the third row the F32 words at (24,0) of the 32²/137 render are 3e87bb00, 3f596540, 3f22ab7c and 3f22ab7c. The [standalone vector-typed draw](#scaled-random-draws-and-offsets) remains open. + +### Packed random draws in flood-fill color + +| Root | Renders | Exact pixels before | Exact RGBA pixels after / compared | Maximum error after | +|---|---:|---:|---:|---:| +| Flood Fill 2 color | 19 | 143,858 | 143,872/143,872 | 0 | +| Flood Fill 2 random color | 19 | 143,487 | 143,872/143,872 | 0 | + +Use the [flood-fill cell maps, color fields and HSL settings](#per-pixel-random-initialization). Both roots now match 119,808 U16, 5,120 U8, 5,120 F16 and 13,824 F32 pixels apiece. Before the correction, the random-color root differed at 375 U16 and ten F32 pixels. The color root differed at five U16 and nine F32 pixels. At an absolute 32², seeds 137 and 733, and at 16², seed 839, each input bridge matches 2,304/2,304 pixels on both revisions. Each U16 random map improved from 2,299/2,304 (one level) to 2,304/2,304 (zero). All 2,304 processor and output pixels now match for each root. + +Store a scalar unit draw once per evaluation of its range. Independent lanes can then contract each scaled sample with its own offset. When a lane supplies another output that reads the rounded product, the sum uses that rounded value. At (1,0) of a 16² graph at seed zero, pack consecutive draws of ranges .999 and −1.731053, then add (.001,.352111). The two F32 result words are `3ea12485` and `bf63be1d`. Return the sum together with its input pair and the four words are `3ea12485 bf63be1e 3ea0a173 bf9ef108`. + +| Original RGBA control, seven renders each | Exact pixels before | Exact pixels after / compared | Maximum error after | +|---|---:|---:|---:| +| Packed pair plus offsets | 5,637 | 9,472/9,472 | 0 | +| Packed sum and both rounded draws | 9,472 | 9,472/9,472 | 0 | +| Sum of two single-use draws | 9,472 | 9,472/9,472 | 0 | +| One draw with two offsets | 5,846 | 9,472/9,472 | 0 | +| Shared draw with another single-use draw | 9,472 | 9,472/9,472 | 0 | +| First draw supplies the next range | 9,472 | 9,472/9,472 | 0 | + +Let A=rand(.999), B=rand(−1.731053) and C=rand(1). For the packed control, repeat the two-channel sum as RGBA. For the shared version, return the sum followed by (A,B). The four other graphs return (A+B,C,A+B,C), (A+.001,.352111−A,A+.001,.352111−A), (A+.001,B−A,A+.001,B−A) and (rand(A)+B,C,rand(A)+B,C), respectively. Repeated expressions reuse the same graph node. Use 16² F32/seed zero, 32² F32/1, 32² in four formats/137 and 64² F32/557. All 56,832 complete pixels match. The [earlier scalar controls](#scaled-random-draws-and-offsets) and the 337 initialization controls retain their results. The separately declared vector-typed random instruction remains open. + +### Scaled random draws and offsets + +At (2,0) on a 16² graph with seed 17, evaluate `r=rand(.999)` and return `r+.001`. The raw F32 result has bits `3f3563cb`. Return the sum and r together and their bits are `3f3563ca` and `3f352241`. At (4,0) with the same settings, returning `.001−r` alone gives `beb19951`. A scalar pixel draw consumed by a single addition or subtraction multiplies its unit sample by the range and adds the offset in one rounding. A reader of the scaled draw receives its rounded value. The graph's evaluation order determines which sample each draw receives. + +| Original direct control, eight renders each | Exact pixels before | Exact pixels after / compared | Maximum U16 levels | Maximum F32 error | +|---|---:|---:|---:|---:| +| Two sums, draw on left | 6,081 | 10,496/10,496 | 0 | 0 | +| Two sums, draw on right | 6,081 | 10,496/10,496 | 0 | 0 | +| Range minus offset | 7,433 | 10,496/10,496 | 0 | 0 | +| Offset minus range | 7,433 | 10,496/10,496 | 0 | 0 | +| Return each sum and its scaled draw | 10,496 | 10,496/10,496 | 0 | 0 | +| Vector-typed random instruction | 0 | 0/10,496 | 65430 | 1.73066464 | +| Horizontal coordinate as range, vertical as offset | 9,648 | 10,496/10,496 | 0 | 0 | +| Sum and difference with both scaled draws returned | 10,496 | 10,496/10,496 | 0 | 0 | + +For each control, use 16² F32/seed 17, 32² F32/0, 32² in all four formats/137, 64² F32/413 and 32² F32/673. Use ranges .999 and −1.731053, offsets .001 and .352111. In the two-sum and subtraction controls, repeat the first two results as the other two RGBA channels. In the coordinate control, return `rand(u)+v` in grayscale, using the normalized texel center. In the sum-and-difference control, return the second scaled draw minus the first, their sum, then both individual draws. All **73,472/73,472 pixels in the seven scalar graphs** match. The eighth control explicitly declares a two-component random instruction with range (.999,−1.731053). Its reference output returns zeros for the draw, while the two scalar draws packed into a vector have distinct values. MaterialCraft's vector-typed result still differs. The [337 initialization and draw-order controls](#per-pixel-random-initialization) also retain zero error. + +| Root | Renders | Exact pixels before | Exact pixels after / compared | Maximum U16 levels | Maximum F32 error | +|---|---:|---:|---:|---:|---:| +| Volume environment light | 39 | 31,387 | 31,488/31,488 | 0 | 0 | +| Flood Fill random color | 19 | 143,501 | 143,872/143,872 | 0 | 0 | +| Flood Fill random grayscale | 19 | 143,795 | 143,872/143,872 | 0 | 0 | +| Flood Fill 2 color | 19 | 143,858 | 143,858/143,872 | 1 | 1.42455101e-05 | +| Flood Fill 2 grayscale | 19 | 143,871 | 143,872/143,872 | 0 | 0 | +| Flood Fill 2 random color | 19 | 143,487 | 143,487/143,872 | 1 | 1.52587891e-05 | +| Flood Fill 2 random grayscale | 19 | 143,800 | 143,872/143,872 | 0 | 0 | + +Use the same [root fields, parameters, seeds and output storage](#per-pixel-random-initialization). The density ramp now matches 1,024/1,024 F32 pixels, and the 39 environment-light renders include 11,264 F32 pixels. The grayscale pass and the first flood-fill package now match their complete recorded matrices. The two open color roots pack scalar random draws into a vector before applying their offset. Their residuals are bounded by one U16 level and .0000152587891 in F32. All U8 and F16 pixels in this root table match. The Worley, Dissolve, diffusion, splatter and fast white-noise reruns retain their previous counts. The later white-noise generator retains the differences measured for its Gaussian distribution. + +### Per-pixel random initialization + +The first four calls to `rand(1)` at pixel (0,0) of a 32² graph give (6046590,4572138,703596,3572932) / 2²³ at seed zero. At seed one they give (3086392,1966280,4339094,3323762) / 2²³. At (16,1) of a 32×16 graph, seed 42 gives (3941566,2846122,6888364,1390724) / 2²³. These observations distinguish the graph seed, position, resolution and draw order. + +Start a 32-bit hash at zero. In order, mix the integer graph seed and the F32 bit patterns of the normalized texel center ((x+.5)/width,(y+.5)/height). For each word, set `t=(h+word)×1025` and `h=t XOR (t >> 6)`. Finish with `t=h×9` and `s=(t XOR (t >> 11))×32769`. All products and sums wrap to 32 bits. Use the low 24 bits of s to start the [measured pixel draw sequence](#pixel-processor-random-draws). This is the word-wise form of the public one-at-a-time mixing operation. [Bob Jenkins, Hash Functions](https://burtleburtle.net/bob/hash/doobs.html) + +All **95,512/95,512 RGBA32F pixels in 337 direct renders** match, maximum component error zero. The earlier 13 four-draw images and 16 fan-out and scaling controls account for 53,568 pixels. For 288 new controls, set absolute width×height to 1×1, 1×2, 1×8, 1×32, 1×256, 2×1, 2×2, 8×1, 8×2, 8×8, 32×1 or 256×1. Use parent side 16 and seeds 0–5, 7, 8, 16, 17, 31, 32, 42, 127, 128, 255, 256, 257, 4095, 65535, 65536 and 16777216. Repeat seed zero at parent sides 32 and 64. The last 20 controls use 64×8, 8×64, 16×128 and 128×16 at seeds 0, 73, 983, 879201 and 16777217. + +| Root | Renders | Exact pixels / compared | Maximum U8 / U16 levels | Maximum F16 / F32 error | +|---|---:|---:|---:|---:| +| Volume environment light | 39 | 31,387/31,488 | 0 / 0 | 0 / 0.000266551971 | +| 3D Worley noise | 34 | 312,832/312,832 | 0 / 0 | 0 / 0 | +| Dissolve | 28 | 183,040/183,040 | 0 / 0 | 0 / 0 | +| Diffusion RGBA pass | 19 | 143,872/143,872 | 0 / 0 | 0 / 0 | +| Diffusion UV pass | 19 | 143,872/143,872 | 0 / 0 | 0 / 0 | +| Diffusion grayscale pass | 19 | 143,872/143,872 | 0 / 0 | 0 / 0 | +| Diffusion normal pass | 19 | 143,872/143,872 | 0 / 0 | 0 / 0 | +| Flood Fill random color | 19 | 143,501/143,872 | 0 / 1 | 0 / 1.52587891e-05 | +| Flood Fill random grayscale | 19 | 143,795/143,872 | 0 / 1 | 0 / 1.52587891e-05 | +| Flood Fill 2 color | 19 | 143,858/143,872 | 0 / 1 | 0 / 1.42455101e-05 | +| Flood Fill 2 grayscale | 19 | 143,871/143,872 | 0 / 0 | 0 / 5.96046448e-06 | +| Flood Fill 2 random color | 19 | 143,487/143,872 | 0 / 1 | 0 / 1.52587891e-05 | +| Flood Fill 2 random grayscale | 19 | 143,800/143,872 | 0 / 1 | 0 / 1.52587891e-05 | +| Shape Splatter blend | 18 | 171,264/171,264 | 0 / 0 | 0 / 0 | +| Shape Splatter blend color | 23 | 204,032/204,032 | 0 / 0 | 0 / 0 | +| Shape Splatter to mask | 4 | 114,688/114,688 | — / — | — / 0 | +| White Noise fast | 18 | 127,488/127,488 | 0 / 0 | 0 / 0 | +| White Noise v2 | 19 | 104,036/143,872 | 165 / 39351 | 0.600250244 / 0.751115441 | + +The root counts include each root's archived and four-format measurements where available. The earlier measurements specify the [Worley position fields](#3d-volume-mask-and-worley-noise) and [Dissolve inputs](#segment-mapping-and-normal-graph-rechecks). The [volume](#volume-density-dithering-and-color-temperature-controls) and [splatter](#plane-light-splatter-symmetry-and-waveform-comparisons) comparisons give the additional held-out fields for those roots. The remaining 101 environment-light differences are F32. In the 32² density ramp, 987/1,024 pixels match and the maximum error is .000266551971. The mask row covers its four archived F32 renders. + +For Worley, Dissolve, the four diffusion passes, six flood-fill outputs and both white noises, add ten renders apiece. At 16² use defaults and seed 17. Use variant A at 32² in U8, U16, F16 and F32 with seed 137. Use variant B at 64²/413 and with a 32×16 field on a 32² graph/673. Use A with a constant 32² field/733, C with a signed 16² field/839, and A again at 32²/1237. All six single-format cases use F32. The two noise generators have no image input. For image pin j (one-based in declared probe order) and zero-based channel c, use H=((79x+53y+11xy+113j+73c+3xc) mod 1019)/1018. A grayscale pin uses channel zero. The constant is (.375,.625,.1875,.8125) and the signed field is 2.5H−.875. Worley uses normalized texel center (u,v) and position (u,v,.5+.25 sin(2π(u+v)),1). For flood-fill cell input, let sx=max(2,floor(width/5)), sy=max(3,floor(height/3)). Store (((x mod sx)+.5)/sx,((y mod sy)+.5)/sy,sx/width,sy/height) and zero cells where (floor(x/sx)+3floor(y/sy)) mod 7 is zero. Constant and signed cases replace these fields. Dissolve pin order is foreground, background, mask. For diffusion it is input/reference/mask/direction (RGBA), input (UV), input/reference/intensity (grayscale) and input/reference (normal). Flood Fill 2 color and grayscale take the cell input first and the color or grayscale field second. + +| Parameter | A | B | C | +|---|---|---|---| +| Worley scale, mode, style, invert | 9,1,0,off | 13,2,1,off | 3,3,2,on | +| Dissolve opacity, alpha blending | .5625,on | .3125,off | .8125,on | +| Diffusion iter, nbIter, dither, normal | 2,5,on,off | 4,7,off,off | 0,3,on,on | +| Flood Fill 2 color/grayscale filtering | 1 | 0 | 1 | +| White Noise v2 distribution, disorder, speed | 1,.375,.625 | 0,.8125,1.25 | 1,.1875,.375 | + +For Worley also set size (.75,1.25,1.5), Minkowski number .6875, border width .1875 and roundness .3125. Set optional diffusion controls where exposed. For Flood Fill 2 color use HSL adjustment (.125,−.1875,.25) and random range (.375,.625,.1875). For its grayscale equivalent use luminance adjustment −.1875 and random range .625. The random flood-fill outputs and fast white noise have no additional exposed numeric changes in these controls. Each residual flood-fill difference is at most one U16 level or .0000152587891 in F32. Uniform noise selects the measured per-texel stream. The later [conditional draw comparison](#conditional-pixel-draws-and-white-noise-v2) resolves the Gaussian differences in White Noise v2. + +### Sampling integer bitmap inputs through wider bridges + +An input node can have distinct readback and sampling precision. With a constant byte level 9 in a 32×17 grayscale PNG, a 32² F16 input bridge reports 3d108000 expanded to F32. A directly connected half output gives the same bits. A separate F32 filter sampling that bridge at a texel center returns 3d109091, the F32 value of 9/255. The filter also uses integer interpolation for off-center reads. A word bitmap converted to half supplies its stored half texture. A word bitmap through F32 still interpolates the normalized word texture. + +| Original controls | Renders | Exact output pixels / compared | Maximum error | +|---|---:|---:|---:| +| Two source depths and four bridge formats through a translated bilinear transform | 48 | 49,152/49,152 | 0 | +| Centered and offset filters through a half bridge | 144 | 147,456/147,456 | 0 | +| Off-center reads through U8, F16 and F32 bridges | 72 | 73,728/73,728 | 0 | +| Direct output wired to the same three bridge formats | 36 | 36,864/36,864 | 0 | + +For the first row use a 32² F32 output, seed 469, identity transform, bilinear filtering and offset (15/1024,−21/1024). Use grayscale or RGBA PNG files with zero-based channel c. On a 32×17 image use level 9 when x+c is even and 243 otherwise. On a 17×23 image use (47x+73y+13xy+31c+113) mod 256. On a 47×33 image use (11x+7c+223) mod 256. For 16-bit files, expand each level b to 257b and add (7x+3y+11c) mod 251 when b < 255. On the alternating grayscale image, the F32 word at (0,0) is 3eee4eee for the 8-bit source through all four bridges. For the word source, the same pixel gives 3eee8eef, 3eee92ef, 3eee8000 and 3eee92ef through U8, U16, F16 and F32 respectively. + +For the second row use each half bridge with an identity transform at texel centers, a translated nearest transform, a blur at intensity zero, and a bilinear pixel sampler using the translation above. For each combination of filter and grayscale or RGBA, use the [original PNG fields](#source-image-depth-and-the-three-noise-upscalers) at all three sizes for bytes. For words use the 32×17 constant with levels (9,89,142,199)×257 and the 17×23 and 47×33 word hash. Add 32×17 constants at byte levels 1, 9, 31, 127, 143 and 250 and at their word equivalents. The fields use seed 157 and the constants use seed 379. For the last two rows use the three byte fields, the 32×17 word field and the constant 9 at both depths. Compare a translated bilinear transform, an offset bilinear pixel sampler and a direct wire. The filters render at F32. For the wire, read the declared output storage. + +All 106 earlier integer-to-half cases also match at the downstream output, **108,544/108,544 pixels**, including all 26,624 byte pixels. The half readbacks match at the same locations. The two curvature roots and three noise upscalers retain all 2,444,800 pixels in 103 renders. The [float-source integer conversion](#enlarging-bitmap-rows-and-converting-integer-images-to-half) still differs at 18 U8 and 14 U16 pixels on the signed and stepped controls, by at most one level each. + +### Enlarging bitmap rows and converting integer images to half + +| External source and destination | Renders | Exact bridge pixels / compared | Exact F32 output pixels / compared | Maximum F32 output error | +|---|---:|---:|---:|---:| +| Signed F32 fields, original sizes | 78 | 79,872/79,872 | 239,616/239,616 | 0 | +| Signed F32 fields, 17 additional growth ratios | 51 | 147,456/147,456 | 466,944/466,944 | 0 | +| Six byte PNG fields read through half | 6 | 6,144/6,144 | 1/6,144 | .000486373901 | +| Thirty word PNG fields read through half | 30 | 30,720/30,720 | 30,720/30,720 | 0 | +| Twenty byte PNG constants read through half | 20 | 20,480/20,480 | 4,096/20,480 | .000411689281 | +| Fifty word PNG constants read through half | 50 | 51,200/51,200 | 51,200/51,200 | 0 | + +A one-column input reproduces the previous [float growth difference](#float-bitmap-reduction-and-half-output). Resize 49 rows to 64. Put F32 words beae712e and 3f904fe4 in rows 5 and 6, with zeros elsewhere. Row 7 has bits 3c737400. During enlargement, map the output index and half-texel offset separately in F64, as i/s + .5/s for s=destination/source. The original 35×49 grayscale and RGBA fields now match at the bridge and at the square output. + +For the 51 additional controls, the source width and bridge width are 32. Use source heights 21, 35, 43, 45, 47, 49, 51, 55, 57 and 61 with destination height 64. Use heights 67, 71, 87, 91, 93, 97 and 105 with destination height 128. Render at the destination height squared, sampling the bridge at normalized texel centers. At each height generate three original RGBA32F images, with zero-based x, y and channel c. + +- At seed 709, use (((17x+53y+31xy+19c) mod 2047)/1024−1) × 2^((3x+7y+c) mod 8−4). +- At seed 710, reinterpret 3f800001 plus (37x+53y+13xy+31c) mod 256 as F32 bits. Negate where x+3y+c is odd. +- At seed 711, use (((21x+29y+11c+13xy) mod 1021)/1020−.5) × 2^((x+y) mod 13−5). + +For the PNG fields use the [byte and word recipes](#source-image-depth-and-the-three-noise-upscalers). For constants, bind 32×17 grayscale and repeated RGBA images to a 32² half bridge, seed 881. Byte levels are 0, 1, 9, 31, 127, 128, 143, 196, 250 and 255. Word levels are 0, 1, 3, 7, 9, 13, 16, 127, 128, 129, 251, 513, 1023, 2117, 2313, 4118, 8193, 15427, 22001, 32079, 32767, 39114, 49197, 65529 and 65535. + +Filter both axes at the source integer precision. A byte value b reports the half of b/255 rounded toward zero at the bridge. At byte level 9, that is 3d108000 expanded to F32. A word source uses the [three-row diffusion weights](#non-power-of-two-float-image-inputs-and-curvature) in word units with one new random sample per interleaved channel. Start the generator at 1, multiply by 48271 modulo 2147483647, and divide by 2147483647 for a unit draw r. Truncate original word + received error + 16(r−.5) and clamp to the word range. Values 0 through 2 read and reconstruct as zero. Value 3 reads as 2/65536 and reconstructs as 3. For larger values q, store the half of q/65535 rounded toward zero, and reconstruct as min(65535,65536×stored). Propagate original minus reconstructed. For word level 2313 the first three expanded channel words are 3d100000, 3d102000 and 3d10c000. + +The reference F32 consumer of these byte sources reads the unrounded filtered byte divided by 255. Its half bridge readback and the consumer value are distinct. This discrepancy accounted for all 22,527 differing downstream pixels in the two byte rows. The [subsequent sampling controls](#sampling-integer-bitmap-inputs-through-wider-bridges) resolve them. The float-input to U8 and U16 controls retain 18,414/18,432 and 18,418/18,432 exact pixels, with maximum errors of one stored level. Both curvature roots retain 176,384/176,384 across 20 renders each. Each of the three noise upscalers retains 697,344/697,344 across 21. + +### Float bitmap reduction and half output + +| Bound input and bridge storage, read through F32 | Renders | Exact pixels before | Exact pixels after / compared | Maximum F32 error after | +|---|---:|---:|---:|---:| +| Signed F32 images read through F32 | 78 | 238,988 | 239,608/239,616 | 9.31322575e-10 | +| F32 images through U8 | 18 | 18,400 | 18,414/18,432 | 0.0039215982 | +| F32 images through U16 | 18 | 18,399 | 18,418/18,432 | 1.52597204e-05 | +| F32 images through F16 | 18 | 4,979 | 18,432/18,432 | 0 | +| Byte and word images through U8 | 36 | 36,854 | 36,864/36,864 | 0 | +| Byte and word images through U16 | 36 | 36,846 | 36,864/36,864 | 0 | +| Byte and word images through F16 | 36 | 6,605 | 6,605/36,864 | 0.359375 | +| Byte and word images through F32 | 36 | 36,846 | 36,864/36,864 | 0 | + +Use the [original float fields and shapes](#non-power-of-two-float-image-inputs-and-curvature) and [byte and word fields](#source-image-depth-and-the-three-noise-upscalers). Every channel must match. On the signed 35×49 field at seed 277, the 16×64 bridge retains one different texel in each of the grayscale and RGBA measurements. At (5,7), channel zero has bits `3c737400` in the reference and `3c737401` in MaterialCraft. Reading these bridges at the parent square size gives the eight differing pixels in the first row. Integer-to-half conversion also retains differences. + +| Additional direct control | Renders | Exact pixels / compared | Maximum finite error | +|---|---:|---:|---:| +| Constants in grayscale and RGBA | 48 | 49,152/49,152 | 0 | +| Midpoints, underflow, overflow and signed fields | 37 | 37,888/37,888 | 0 | +| Four different constants in one RGBA image | 1 | 1,024/1,024 | 0 | +| Close row values and simple row controls | 43 | 11,008/11,008 | 0 | + +For a filter axis, let s=target/source, k=min(1,s), and c=(output+.5)/s. At input i the triangle weight is k×max(0,1−k×abs(i+.5−c)). Normalize the surviving weights separately, left to right, in F64. Retaining the outer k changes midpoint decisions on reduction. At width N=47, 65 or 67, bind a one-row float image with bits `3f000000` plus (13x+7j+3xj+j²) mod 64, where j is 15, 14 or 14 respectively. With a 16×1 F32 bridge, samples 11, 9 and 4 have bits `3f00001d`, `3f00001d` and `3f00001f`. For the other 40 rows, use widths 19, 25, 29, 35, 37, 41, 47, 67, 73 and 91. Store x/16−1, ((31x+5x²+9) mod 61)/51, (((19x+7x²+5) mod 32)−17)/8, or (x mod 7)−3. The table counts the 16² final outputs. The row regressions also check the 16×1 bridge. + +For an F32 source and half output, resize both axes at F32 storage first. Visit the output pixels in row-major order. Add the accumulated error to each original channel value, clamp at zero and round to nearest half with ties upward. Propagate original minus stored value to neighboring pixels using the [three-row diffusion weights](#non-power-of-two-float-image-inputs-and-curvature). A constant (1+2⁻¹¹,−1,.125,.12505) on a 32×17 input at 32² gives (1+2⁻¹⁰,0,.125,.125) at (0,0), (1,0,.125,.125) at (1,0), and (1+2⁻¹⁰,0,.125,.125+2⁻¹³) at (2,0). + +For 48 constant renders, use the same dimensions with values −10, −1, −.01, 0, .0001, .001, .01, .035294117647, .051234, .125, .12505, .21875, .241234, .501234, .813579, .998, 1, 1.125, 1.312345, 1.999, 2.345678, 8.12345, 32.6789 and 76.234 in grayscale and repeated RGBA. The 37 grayscale boundary renders cover four sequences. Use each entry as a constant, then the full sequence indexed by (3x+5y) mod length. + +- 65504, 65505, 65519, 65520, 65521, 65535, 65536, 10¹⁰, −10¹⁰. +- 2⁻²⁶, 2⁻²⁵, 3×2⁻²⁵, 2⁻²⁴, 2⁻¹⁴−2⁻²⁵, 1+2⁻¹¹, 1+3×2⁻¹¹. +- 0, −.5, 1.5, .375, .625, .12505, .999, 1.001, 4. +- −10⁻¹², 9×10⁻⁹, .00034, .99, −2.75, 0, 5.5, .1875. + +The boundary comparison includes the positions of infinite samples. At a constant 65520, the first five half values are positive infinity, zero, zero, positive infinity and zero. Both curvature roots retain 176,384/176,384 pixels across 20 renders apiece, and each of the three noise upscalers retains 697,344/697,344 across 21 renders. Their [word-depth comparison](#source-image-depth-and-the-three-noise-upscalers) locates the earlier source and mask differences. + +### Source image depth and the three noise upscalers + +| Root | Renders | Exact grayscale pixels before | Exact grayscale pixels after / compared | Maximum error after | +|---|---:|---:|---:|---:| +| Noise Upscale 1 | 21 | 695,768 | 697,344/697,344 | 0 | +| Noise Upscale 2 | 21 | 695,877 | 697,344/697,344 | 0 | +| Noise Upscale 3 | 21 | 693,752 | 697,344/697,344 | 0 | + +Use the [upscaler inputs, offsets and seeds](#tile-random-cell-fields-and-noise-upscaling) and the [Min blend comparison](#min-and-max-blend-weights). Each matrix includes 491,520 U8, 32,768 U16, 32,768 F16 and 140,288 F32 pixels. On the 32×17 word source at seed 977, the source and mask bridges now agree on 1,024/1,024 U8 texels apiece and each of the three 64² F32 final outputs agrees on 4,096/4,096 pixels. + +A PNG's original channel depth matters even when its decoded numbers are identical. Bind a 32×17 grayscale PNG containing 9 at eight bits or 2,313 at sixteen bits, and cook a 32² U8 input. The byte file gives six 9s at the start of the first row. The word file gives 8, 8, 9, 9, 9, 8. Binding the byte file again restores all six 9s. The graph's image declaration, exposed ports and authored resources retain their original representation. + +When the source has fewer levels than the destination, filter each axis at source depth. When reducing word samples to bytes, use the original word, add the received error in byte units multiplied by 257, then add the centered random fraction multiplied by 256. Take the high byte after saturation. For diffusion, measure the error between the normalized original and stored sample. The order of random draws, error weights and separable filter are specified in [Non-power-of-two float image inputs and curvature](#non-power-of-two-float-image-inputs-and-curvature). + +| Bridge storage, read through F32 | Renders | Exact output pixels before | Exact output pixels after / compared | Largest absolute output error after | +|---|---:|---:|---:|---:| +| U8 | 36 | 16,716 | 36,854/36,864 | 0.00392156839 | +| U16 | 36 | 19,962 | 36,846/36,864 | 0.00392156839 | +| F16 | 36 | 6,605 | 6,605/36,864 | 0.359375 | +| F32 | 36 | 19,962 | 36,846/36,864 | 0.00392156839 | + +For all 144 controls, use 32×17, 17×23 and 47×33 inputs on a 32² graph at seed 157, in grayscale and RGBA. Define W=((97x+71y+13xy+157+79c+5xc)×197 +11y²+53x) mod 65536. Use (W mod 256) at eight bits, the identical decoded field (W mod 256)×257 at sixteen bits, and W at sixteen bits. Three further sixteen-bit fields are constant (15427,32079,39114,49197), constant (9,89,142,199)×257 and an endpoint field alternating W mod 512 for even W with 65535−(W mod 512) for odd W. Grayscale uses channel zero. Counts compare every output channel. A small number of reduction-boundary differences remain at byte and word working precision. The wider independent controls also retain discrepancies in half-float conversion. + +### Non-power-of-two float image inputs and curvature + +The final F32 output on the 32×17 stepped normal field now matches all 1,024 pixels for both roots. The previous RGBA16 input matched 201/1,024 within one level. The corrected input matches 1,024/1,024 with zero error. Each root now matches all archived, four-format, independent and held-out cases. The normal fields, seeds and parameter settings are specified in [Curvature from original normal fields](#curvature-from-original-normal-fields). + +| Root | Renders | Exact pixels before | Exact pixels after / compared | Maximum error after | +|---|---:|---:|---:|---:| +| Curvature | 20 | 175,774 | 176,384/176,384 | 0 | +| Curvature smooth | 20 | 176,030 | 176,384/176,384 | 0 | + +Each root covers 8,192 U8, 122,880 U16, 8,192 F16 and 37,120 F32 grayscale pixels. The 32×17 RGBA32F input exercises a distinct bitmap resampling path. At each output texel center filter with a triangle of radius max(1, source length / destination length) in source texel units. Drop out-of-bounds taps and normalize the remaining weights. When the width grows, filter vertically first. Otherwise filter horizontally first. Write the intermediate in its working precision. A unit impulse at the center of a 3×3 or 35×21 F32 input, filtered to 16², gives respective F32 bits 3f524000 and 3dbac261 at (8,8). + +For normalized output, quantize the F32 input before filtering. Scan from top left in channel order. For each channel advance s=48271s mod 2147483647 from initial state 1. Center s/2147483647 on zero. For U8, round that fraction to the nearest 1/255 before centering. Add the received quantization error and centered noise in output-level units, then round and saturate the sample. Spread the difference between the original and stored level using the Sierra weights (5,3) to the right, (2,4,5,4,2) on the next row and (2,3,2) two rows below, all divided by 32. Discard errors beyond an edge. For constant RGBA (.21875,.25,.5,.75) at 32×17, the first two output texels at 32² have U16 levels (14335,16383,32768,49152) and (14336,16384,32767,49151). + +| Independent input controls | Renders | Exact output pixels before | Exact output pixels after / compared | Largest absolute output error | +|---|---:|---:|---:|---:| +| F32 center impulses and steps | 6 | 2,402 | 3,072/3,072 | 0 | +| Signed F32 fields | 78 | 24,464 | 238,988/239,616 | 9.53674316e-7 | +| F32 input through U8 storage | 18 | 4,730 | 18,400/18,432 | 1/255 within F32 rounding | +| F32 input through U16 storage | 18 | 3,230 | 18,399/18,432 | 1/65535 within F32 rounding | +| F32 input through F16 storage | 18 | 4,979 | 4,979/18,432 | 34.25 | + +For the signed field use H=((97x+71y+13xy+11s+79c+5xc) mod 1021)/1020 then (3H−1.25) × 2^((x+3y) mod 11−5). Use RGBA and the first channel alone. Source sizes are 17×19, 23×11, 9×7, 17², 31×33, 19×47, 67×21, 73×63, 35×49, 41×27, 91×55 and a 16×32 control. Use seed 277 and repeat 23×11 with seed 571. Compare 32², 64×16 and 16×64 bridge outputs through an F32 identity read at the parent square size. + +For each stored-format group, use the constant above at 32×17. Use H with 11s replaced by 214 and 79c by 23c at 23×17, 31×17, 47×73 and 41×27. Use (floor(11H)+2)/16 at 17×32, and the signed field with seed 307 at 23×19, 17×49 and 9×7. Read all results through F32 at 32². Residuals remain on input storage boundaries and on float reductions. The F16 input conversion still differs, particularly for negative values. + +### Min and Max blend weights + +Noise Upscale 2 now matches 695,877/697,344 pixels across all 21 [upscaler cases](#tile-random-cell-fields-and-noise-upscaling). The remaining difference occurs on the 32×17 source. Maximum errors at U8, U16 and F16 are zero and the maximum F32 error is 0.00439214706. Applying the corrected blend to the measured intermediate textures reproduces all 168,960/168,960 pixels across twelve original parameter cases. + +For Min and Max in source-alpha, ignore-alpha and premultiplied interpretations, multiply the selected foreground color by its weight, then accumulate the background product with a fused multiply-add. Read the mask and participating foreground alpha through the complement of their transparencies. For example, with foreground 46/255, background 79/255 and opacity .56, Min gives F32 bits 3e730783. + +| Independent controls | Renders | Exact pixels before | Exact pixels after / compared | Maximum error after | +|---|---:|---:|---:|---:| +| Gray and RGBA, interpretations 0, 1 and 3 | 96 | 92,110 | 135,168/135,168 | 0 | +| Straight RGBA, interpretation 2 | 24 | 12,244 | 12,244/33,792 | 1 level at U8/U16, .00048828125 at F16, 2.38418579e-7 at F32 | + +Run both modes with opacity .56, with and without a mask. Use 16²/191 and 64²/541 at F32, and 32²/307 in all four output formats. For RGBA source j starting at 1 and channel c starting at 0, use ((97x+71y+13xy+11s+57j+79c+5xc) mod 1021)/1020. For a gray source or mask use ((97x+71y+13xy+11(s+79i)) mod 1021)/1020 with zero-based pin index i. The color pin order is foreground, background, mask and the gray pin order is foreground, background, mask. Use U8 input bridges for the gray blend and F32 for the color blend. The straight-color controls remain open. + +### Tile Random, cell fields and noise upscaling + +After the [pattern seed](#local-seed-expressions-in-pattern-graphs) and [blend](#filtering-unequal-inputs-to-a-blend) changes, the pattern-package Tile Random matches all **176,384/176,384** pixels across 20 renders. Its [four-format inventory cases](#four-format-inventory-comparison), independent 32² case and four archived cases contribute 132,096 pixels. Eleven new inputs add 44,288. The two 64² F32 circle renders at seeds 251 and 947 contain 507 and 510 distinct stored levels respectively. Counts below cover the end-to-end cases in this matrix. + +| Root | Renders | Exact pixels / compared | Maximum U8 / U16 error (levels) | Maximum F16 / F32 error | +|---|---:|---:|---:|---:| +| Dirt 5 | 19 | 156,858/156,928 | 0 / 4 | 6.10351562e-05 / 5.0842762e-05 | +| Cells 1, second package | 20 | 158,598/173,312 | 1 / 0 | 0 / 1.96695328e-06 | +| Cells 4 | 21 | 174,284/174,336 | 0 / 53,506 | 0 / 0.491874591 | +| Cells 4, second package | 21 | 174,310/174,336 | 223 / 0 | 0 / 0.667963699 | +| Noise Upscale 1 | 21 | 695,768/697,344 | 0 / 0 | 0 / 0.00784313679 | +| Noise Upscale 2 | 21 | 678,381/697,344 | 0 / 1 | 0 / 0.00439214706 | +| Noise Upscale 3 | 21 | 693,752/697,344 | 0 / 0 | 0 / 0.00769269466 | +| Tile Random, pattern package | 20 | 176,384/176,384 | 0 / 0 | 0 / 0 | + +For Tile Random use H=((73x+37y+11xy+k) mod 1021)/1020 in the pattern and background pins, with k=29 and 72. Start at defaults at 16²/137. At 64²/251 choose pattern 3 and (5,3) tiles, and render all four formats. At 128²/353 use pattern 2 and (9,7). At 32²/479 use a 32×16 U16 source, pattern 3 and (3,7), disabling non-square expansion. At 32²/557 use 2.5H−.875, pattern 2, (1,3), independent size randomness .125 and .625 and position randomness .1875. Use constant .375 with pattern 3 and (3,1) at 32²/733. At 64²/827 select pattern 0 (no stamp), (4,5) and filter 0. The [image-stamp comparison](#tile-random-image-and-soft-patterns) covers the image selector and all three filters. Repeat the 64² circle field at seed 947. The changed settings share pattern-specific value .3125, rotation randomness .375, shape rotation .125, interstice .1875 and split threshold .625. + +For the seven other roots use the same H with k=19 on the first pin and 132 on the second. Renders use defaults at 16²/71, four formats at 64²/181, F32 at 128²/269, a 32×16 U16 input at 32²/383, a signed 32² field at seed 487, a constant .375 field at 32²/617, the 64² field at seed 701, and a 32² impulse at (floor(w/3),floor(h/2)) with seed 883. For roots with image inputs add a 32×17 U16 field at 32²/977. Use unsigned H on the signed case's mask. Dirt 5 has no input pins or exposed numeric controls. At 64²/181 its first differing pattern map matches 4,094/4,096 U16 pixels within one level. + +For the cell roots use (scale, disorder)=(5,.6875) on the 64² fields, (13,.6875) on the 128² and rectangular fields, (1,.125) for the flat input and (9,.125) for the signed and impulse inputs. Disable non-square expansion on rectangular inputs. Select disorder speed .625 where exposed. Cells 1 uses angle .0625, angle randomness .1875, anisotropy .25 at .125 turns, size (.875,1.125), scale .8125, luminance randomness .375 and offset (.1875,−.3125). Select pattern 4 on the large and rectangular cases and 3 on the others. For Cells 4 use color source 1 except on the flat case, and pseudo-random seed 17 on the two 64² modular fields and 37 on the others. + +Set the two offset pairs on the first and second upscalers to (.1875,−.4375) and (−.3125,.125) on the 64² fields, (−.5625,.3125) and (.6875,−.1875) on the large and rectangular cases, and (0,0) and (.5,−.5) on the other changed cases. The third upscaler has source and mask inputs only. The first and third match all pixels in 20 of 21 renders. Both first differ on the 32×17 U16 source at their U8 image inputs. The source matches 702/1,024 within two levels, and the third upscaler's mask matches 679/1,024 within one. For the second upscaler the final Min blend also differs on power-of-two inputs. At 64²/181 both of its 128² U8 inputs match but 2,126 final F32 pixels differ by at most 5.96046448e-8. + +### Emboss lighting and physical pixel size + +An original height impulse at (16,16), intensity 1, light angle zero and a .5 gray base gives .625 at the impulse and .375 immediately to its right. The pixel to its left equals .5. For a general height H use dx=H(x,y)−H(x−1,y), dy=H(x,y)−H(x,y−1). A tiled axis wraps and an untiled axis clamps. Scale intensity by min(width,height)/256. Multiply cosine and sine of the angle in turns by the respective physical pixel sizes, then by that scale. Use F32 radians. Round the x product and accumulate the y product with one fused multiply-add. A right-angle rotation retains the small computed cosine. + +For each RGB channel, accumulate light×highlight on the base when light is positive, or light×(1−shadow) when negative, with one fused multiply-add. Preserve the base alpha. A gray base uses the arithmetic mean of the three highlight or three shadow components before calculating the signed contribution. At 32²/277 use a .5 base, the impulse above, highlight (.75,.25,.125,.5) and shadow (.125,.875,.375,.25). The impulse and its right neighbor have raw F32 values .546875 and .4322917. Swapping single-channel red, green and blue tints leaves the gray output identical. + +| Original controls | Renders | Exact pixels before the corresponding change | Exact pixels after / compared | Maximum error after | +|---|---:|---:|---:|---:| +| Gray ramps, steps, impulses and modular fields | 192 | 86,649 | 330,240/330,240 | 0 | +| RGBA bases and independent colored tints | 128 | 207,552 | 425,984/425,984 | 0 | +| Rectangular outputs and four tiling modes | 96 | 17,223 | 147,456/147,456 | 0 | +| Colored tints over a gray base | 32 | 31,026 | 81,920/81,920 | 0 | +| Independent tint and base values | 32 | 31,363 | 81,920/81,920 | 0 | + +For the first 192 renders use the horizontal and vertical ramps x/(w−1), y/(h−1), a center impulse, a horizontal step and H=((53x+71y+19xy+23) mod 509)/508. Use .5+(H−.5)/32 for the low-amplitude field. Bases are .25, .5, .75 and H. Compare default intensity 5 and 0, .25, .625, 1, 1.375 and 2. Use axial angles 0, .25, .5 and .75 turns and oblique angles .125 and −.1875. Vary both physical axes between .1 and 4 and use (.5,2) to distinguish them. Compare 16², 32² and 64² with seed 97+29j in field order. Read F32 throughout and U8, U16 and F16 on the 64² H base. Use F32 and U16 heights. For the rectangles use 32×64 and 64×16, the .5 base and H height, angles 0, .25 and .1875, physical size (.5,2), tiling masks 0 through 3, four output formats and seed 563. + +For RGBA use the [independent modular color field](#filtering-unequal-inputs-to-a-blend) with s=193 and j=2. Compare the step, impulse, H and low-amplitude heights at 32² F32 and at 64² U16, F16 and F32. Use intensity 2, angles 0 and .1875, and the default, custom, reversed and alpha-zero tints. For gray tint tests repeat the impulse at 32² and the low-amplitude field at 64² in all four formats. Use seed 277 with the constant base, or 457 with H and four independent tint pairs. One such pair is (.147,.913,.718,.0625) and (.796,.344,.521,.875). The 480 original controls match **1,067,520/1,067,520 raw pixels**, maximum error zero. + +Curvature now matches **175,774/176,384** final pixels across the [20 normal-field renders](#curvature-from-original-normal-fields), up from 2,025. All U8, U16 and F16 samples and 36,510/37,120 F32 samples match. The largest F32 difference is .0001068115234375. The two emboss branches use a dynamic physical pixel size of 204.8/side. Applying the measured lighting to the reference's two incoming height fields reproduces all 88,576 U16 branch pixels from the eleven additional cases. The one remaining end-to-end difference occurs on the 32×17 stepped input at 32². The first different stage is its RGBA16 image input, which matches 201/1,024 pixels within one level, just as in [smooth curvature](#filtering-unequal-inputs-to-a-blend). + +### Filtering unequal inputs to a blend + +An original 2×2 grayscale field with row-major values (0,.25,.75,1) distinguishes direct 8× enlargement from three successive 2× filters. Connect it to one port of a 16² Copy blend, seed 317. Read the foreground at full opacity, the background at zero opacity, or a mask between white and black. At (2,7) and (6,12) the U16 foreground produces levels 26,112 and 42,495. An F32 mask produces levels 102 and 165 in U8. The comparable U16 background produces F16 values .3984375 and .64794921875. + +For larger jumps, each axis takes a factor-two step while its distance to the destination exceeds one doubling or halving. The final pass filters both axes to the destination. For example, an 8×16 input to 64² visits 16×32 then 32×32 then 64×64. In weighted blends each resized port uses the higher precision of that port and the destination, including the final filtered image. The order observed is U8, U16, F16, F32. An unmasked grayscale Copy at full opacity, a background at zero opacity and the selected input of a full-opacity Switch use destination storage for the copied input. Rounding the unrelated port to the same higher precision gave a different result in the independent mixed-format controls. + +| Original controls | Renders | Exact pixels before | Exact pixels after / compared | Maximum error after (integer levels or native float units) | +|---|---:|---:|---:|---| +| Individual foreground, background and mask impulses | 3 | 68 | 768/768 | 0 | +| Five layouts and individual ports | 152 | 59,404 | 164,864/164,864 | 0 | +| Independent rectangular gray and RGBA fields | 160 | 33,516 | 174,592/174,592 | 0 | +| Ports with different source formats | 48 | 19,980 | 49,152/49,152 | 0 | +| Copy, Add, Add Sub and Switch at three opacities | 144 | 93,665 | 147,455/147,456 | LUM16 1 | +| Inputs passed through intermediate nodes at different sizes | 96 | 293,493 | 381,372/393,216 | LUM16F 0.083984375, LUM32F 0.0839429498, LUM16 5501, LUM8 22 | + +For the gray controls, set H=((97x+71y+13xy+11s) mod 1021)/1020 with s=107. Use 2.5H−.75 for signed fields. Compare 8²→32², 64²→16², 8×16→64², 64×8→32² and 32²→32². Repeat the 8²→32² and 64²→16² foregrounds at seed 391. In the independent inputs use 4×32→64², 64×4→16², 128×32→8², 8²→32² and 16×64→4², opacity .375 and seed 431. For RGBA output, add 57j+79c+5xc inside the numerator of H for port j and channel c. Masks and gray controls use s=431+17j. Compare all four source and destination formats. At 8²→32² additionally set the resized and other port formats to (U8,F32), (F32,U8), (U16,F16) and (F16,U16). Use s=551+73j at opacity .375. For the 144 mode controls use U16 and F32 sources, seeds 613 and 719, three output formats, and opacity 0, .375 or 1. One U16 pixel still differs by one level. The 96 rerenders with intermediate nodes have residuals on 32² and 128² inputs to a 64² blend. + +The following root results include both the blend change and the [local pattern seed change](#local-seed-expressions-in-pattern-graphs). Use the [spot, brick, cell and cloud inputs](#random-draws-in-pattern-properties-and-iterations) and the [normal fields](#curvature-from-original-normal-fields). + +| Root | Renders | Exact pixels before both changes | Exact pixels after / compared | Maximum U8 / U16 error (levels) | Maximum F16 / F32 error | +|---|---:|---:|---:|---:|---:| +| Black and white spots 1 | 19 | 27,157 | 131,316/172,288 | 1 / 5 | 0.00048828125 / 6.47306442e-05 | +| Black and white spots 3 | 19 | 34,974 | 124,148/172,288 | 1 / 3 | 0.00048828125 / 5.4359436e-05 | +| Brick 1 | 19 | 170,632 | 170,632/172,288 | 0 / 1 | 1.52587891e-05 / 1.52587891e-05 | +| Brick 2 | 19 | 171,992 | 171,992/172,288 | 0 / 1 | 6.10351562e-05 / 1.52662396e-05 | +| Brick 3 | 19 | 51,064 | 168,676/172,288 | 0 / 3 | 0 / 1.52587891e-05 | +| Cells 1 | 19 | 171,491 | 171,491/172,288 | 0 / 3 | 0.00048828125 / 3.67760658e-05 | +| Clouds 1 | 19 | 122,064 | 136,408/172,288 | 1 / 11 | 0.00048828125 / 0.000112771988 | +| Clouds 2 | 18 | 138,259 | 154,536/155,904 | 1 / 3 | 0.00048828125 / 2.30669975e-05 | +| Creased | 19 | 112 | 243/172,288 | 99 / 40,002 | 0.387939453 / 0.483289391 | +| Crystal 1 | 19 | 146 | 99,700/172,288 | 46 / 11,996 | 0.183105469 / 0.451787651 | +| Crystal 2 | 19 | 113 | 113/172,288 | 151 / 58,015 | 0.592163086 / 0.821276069 | +| Curvature smooth | 20 | 54,757 | 176,030/176,384 | 0 / 0 | 0 / 3.05473804e-05 | + +Smooth curvature matches all samples in 19 of its 20 renders. Its remaining 354 differences occur only on the 32×17 stepped input rendered at 32². The first different stage is the RGBA16 input bridge, where 201/1,024 pixels match and the largest channel error is one level. At (0,0) the first two channels read 14,335 and 16,383 in the reference app and 14,336 and 16,384 in MaterialCraft. All 139,264 U8, U16 and F16 final samples match. In Brick 3 the complete U8 and F16 outputs also match. Creased and Crystal 2 still diverge at the first pattern stage. + +### Curvature from original normal fields + +| Root | Exact pixels / compared | Maximum U8 / U16 error (levels) | Maximum F16 / F32 error | +|---|---:|---:|---:| +| Curvature | 2,025/176,384 | 22 / 5,756 | 0.087890625 / 1.70635545 | +| Curvature smooth | 54,757/176,384 | 1 / 7 | 0.00048828125 / 6.10351562e-05 | + +For each root combine the four archive cases and five [inventory renders](#four-format-inventory-comparison) with eleven original normal-map renders. At centered UV coordinates let a=.5sin(2πu)+.25cos(4πv), b=.5cos(2πv)−.25sin(4πu) and z=sqrt(max(0,1−a²−b²)). Encode (a,b,z) as .5+.5×component in RGBA32F. Alpha is ((19x+43y+7xy) mod 255)/254. The stepped field substitutes a=((11x+5y) mod 13−6)×.09375 and b=((3x+7y) mod 9−4)×.125. The flat field sets a=b=0. In the signed case multiply encoded RGB by 2.5 and subtract .75. Read every final grayscale sample at its declared storage precision. + +| Input and output | Size / seed | Curvature intensity / invert green / normal format | +|---|---|---| +| Wave, F32 | 16² / 53 | Defaults | +| Wave, all four output formats | 64² / 157 | 1.375 / false / 1 | +| Wave, F32 | 64² / 157 | .625 / true / 0 | +| Steps, F32 | 128² / 239 | 2.75 / true / 1 | +| Flat, F32 | 32² / 389 | Defaults | +| Signed wave, F32 | 32² / 467 | .1875 / false / 0 | +| 32×17 stepped input, F32 | 32² / 523 | 2.75 / true / 1 | +| Wave, F32 | 64² / 787 | 1.375 / false / 1 | + +Curvature smooth exposes only the normal format. Both roots match all 1,024 flat-control samples. In the 64²/157 F32 curvature graph, both transformed normal maps and both grayscale channel extractions match all 4,096 pixels apiece. The uniform background matches all 1,024 pixels. Both emboss outputs differ at every pixel, with U16 errors up to 673 and 2,876 levels respectively. This isolates the first difference before their final blend. + +In the smooth graph, both 64² channel extractions match exactly. A 16² U16 blend of a transformed channel with the 64² grayscale source matches 240/256 pixels, maximum one level. Both inputs to this blend match before resizing. At this setting the final F32 output matches 2,440/4,096 with maximum error 4.57763672e-5. Both roots remain open. + +### Local seed expressions in pattern graphs + +In a clean-room control, a single original square records three successive opacity draws in RGB with alpha 1. Give its quadrant, iterate or switch a local integer seed of 43. A visit with seed 7 starts the stamp and child property streams at 50 when it inherits the incoming seed and at 43 when it resets. The first opacity draw has F32 bits 3f4fd146 and 3e98dd54 respectively. A random draw inside the local seed expression itself uses the incoming visit seed. Its update is s=(16,294,893×s+10,493,233) mod 2²⁴ and its value is s/2²⁴. The first draw at 7 has bits 3ed93158. An assignment in this expression is visible to subsequent properties on the same stamp. + +For the first group, render a 16² F32 square at seeds 0, 2, 7, 43, 317, 65,537 and 1,048,575. Set the local seed after recording the three expression draws and use inheritance both ways. On a nested graph use quadrant slot 3 or the repeated iterate child, at 64² and seeds 0, 2, 7, 43 and 317. At the same five seeds compare literal and computed 43 on the original 16² stamp. In separate controls read the integer variable `$randomseed` or test whether it is defined inside the expression and the opacity. The getter returns zero and the binding is absent on the tested pattern visits. A positive constant of 43 and two distinct defined-variable marker values distinguish these observations from a failed expression. Read all four channels from the raw output. + +| Original F32 controls | Renders | Exact pixels before | Exact pixels after / compared | Maximum error before | Maximum error after | +|---|---:|---:|---:|---:|---:| +| Seed function on a quadrant, iterate or switch | 42 | 8,736 | 10,752/10,752 | 0.93937701 | 0 | +| Nested visits and literal or computed seeds | 60 | 151,520 | 168,960/168,960 | 0.959448397 | 0 | +| Assignment read on the same stamp | 10 | 1,600 | 2,560/2,560 | 1 | 0 | +| Integer seed getter on the stamp and repeated child | 40 | 7,456 | 10,240/10,240 | 0.870084286 | 0 | +| Constant, integer getter and defined-variable controls | 30 | 6,432 | 7,680/7,680 | 317 | 0 | + +All 182 renders match 200,192/200,192 pixels. The 18 independent iteration cases in four output formats and 72 property controls also retain all 129,024 exact pixels. In Brick 3 at 64²/223, the two 32² U16 pattern maps improved from 64 to 1,024 and from 840 to 996 exact pixels. The maximum errors after the change are zero and one integer level. At the same setting the Crystal 1 pattern map improved from 0 to 4,067/4,096, with maximum error one level. Both roots have remaining differences downstream. + +### Random draws in pattern properties and iterations + +A pattern property starts its own random sequence at the visit seed. For each draw use s=(A×s+C) mod 2²⁴, then return floor(s/2)/2²³. Three draws recorded as the R, G and B channels of an original square stamp distinguish the following sequences. Seeds 0 and 1 constrain the missing low bit of each candidate state. Seeds 2, 5, 42, 223, 743 and 65,537 independently reproduce all three channels. + +| Property | A | C | +|---|---:|---:| +| Opacity | 3,626,811 | 51,137 | +| Branch offset | 14,154,961 | 50,989 | +| Pattern offset | 1,823,937 | 50,707 | +| Pattern size | 5,812,301 | 50,411 | +| Rotation | 3,470,325 | 50,131 | +| Variation | 12,382,630 | 50,647 | +| Iteration count | 9,501,597 | 50,591 | +| Switch | 14,464,988 | 50,111 | + +For offset, size, rotation and variation, assign the three draws to a float4 variable with alpha 1 and return the property's ordinary typed value. Read the variable from the opacity of the child square in the upper-left quadrant of a 16² F32 image. A preceding opacity function can consume three further draws without changing the offset, size or rotation sequences. Use the same assignment on the iteration count and switch, return 1 or false, and read the initial or left child. + +The initial iterate output receives the visit seed. Each repetition advances it once with A=8,532,665 and C=14,533. Starting from zero the first four repeated children receive 14,533, 4,831,522, 11,773,527 and 8,285,092. To read each child's seed, draw a square with three independent opacity draws. Set its width to .75/count, height to .5 and horizontal offset to (ordinal+.5)/count−.5. Test the root and initial output and 1, 2, 4, 16 and 64 repetitions in F32 at 64² with seeds 0, 1, 2, 42, 223 and at 128² with seed 743. Repeat the initial, four- and sixteen-child cases at 64² with seed 7 in F32 and 317 in four formats, and at 128² with seed 1,297 in F32. Test quadrant slots 0, 3 and the nested pair 1 then 2, a reset to 317, and a computed count of floor(rand(1))+4, using 32²/11, 64²/107, 64²/65,537 and 64²/1,048,575. + +| Original pattern controls | Renders | Exact pixels before | Exact pixels after / compared | Maximum error after | +|---|---:|---:|---:|---:| +| Iteration output and counts 1–64 | 42 | 170,496 | 258,048/258,048 | 0 | +| Iteration format and seed controls | 18 | 69,120 | 110,592/110,592 | 0 | +| Quadrant placement and property combinations | 48 | 264,865 | 294,912/294,912 | 0 | +| Nested quadrants, initial output and seed reset | 20 | 41,600 | 66,560/66,560 | 0 | +| Three recorded draws per property | 72 | 17,408 | 18,432/18,432 | 0 | +| Count and switch properties, including a computed count | 20 | 11,392 | 17,408/17,408 | 0 | + +All 37 archive renders across eight previously matched roots that use iteration or property functions still match, totaling **827,392/827,392 pixels** with maximum error zero. These include both brick tile helpers, position debug, Checker 2, histogram compute, paths polygon, Weave 3 and White Noise. + +The following roots use their own procedural fields. The [spot and brick settings](#spot-and-brick-pattern-generators) give the first five matrices. For the other six, add ten renders to the archive and [four-format inventory](#four-format-inventory-comparison). Use defaults at 16²/83, then 32²/139, 64²/223, 64²/743, 128²/293, 32²/419 and 32²/577. Render F32 throughout and all four formats at 64²/223. The two 64² seeds share their parameters. In order of the five changed configurations, Cells 1 uses (distance, disorder) of (3,9.375), (7,37.5), (19,68.75), (1,0) and (31,100). Set disorder to .125, .4375, .6875, 0 and 1 on Clouds 1, Creased and Crystal 1. Set warp intensity to 1.75, 11.5, 37.25, 0 and 63.5 on Creased and both crystals. Clouds 2 exposes no numeric setting. + +| Root | Renders | Exact pixels before | Exact pixels after / compared | Maximum U8 / U16 error after (levels) | Maximum F16 / F32 error after | +|---|---:|---:|---:|---:|---:| +| Black and white spots 1 | 19 | 108 | 27,157/172,288 | 17 / 5,193 | 0.0673828125 / 0.081654489 | +| Black and white spots 3 | 19 | 122 | 34,974/172,288 | 1 / 857 | 0.00048828125 / 0.00813311338 | +| Brick 1 | 19 | 170,632 | 170,632/172,288 | 0 / 1 | 1.52587891e-05 / 1.52587891e-05 | +| Brick 2 | 19 | 171,992 | 171,992/172,288 | 0 / 1 | 6.10351562e-05 / 1.52662396e-05 | +| Brick 3 | 19 | 51,048 | 51,064/172,288 | 145 / 38,763 | 0.569335938 / 0.730708778 | +| Cells 1 | 19 | 143 | 171,491/172,288 | 0 / 3 | 0.00048828125 / 3.67760658e-05 | +| Clouds 1 | 19 | 113 | 122,064/172,288 | 1 / 11 | 0.00048828125 / 0.000112771988 | +| Clouds 2 | 18 | 106 | 138,259/155,904 | 1 / 3 | 0.00048828125 / 4.58359718e-05 | +| Creased | 19 | 108 | 112/172,288 | 139 / 38,215 | 0.544921875 / 0.545176744 | +| Crystal 1 | 19 | 164 | 146/172,288 | 237 / 64,404 | 0.929046631 / 0.929198672 | +| Crystal 2 | 19 | 87 | 113/172,288 | 151 / 58,015 | 0.592163086 / 0.821276069 | + +Cells 1 matches all 8,192 U8 pixels. At 64²/223 the U16 pattern map matches 4,077/4,096 with maximum error one level. At the same setting the three spot-1 pattern maps match 229/256, 3,731/4,096 and 967/1,024 with maximum one level each. The final additive blend combines 16² and 64² inputs. Starting with the reference's two intermediate images, two successive bilinear doublings reconstruct its 4,096/4,096 output levels exactly. Direct 4× bilinear enlargement reproduces 847/4,096, maximum error 2,867 levels. Bricks 1 and 2 retain their measured [edge-coordinate differences](#brick-edge-distances-and-storage-precision). + +For Clouds 1, the three pattern maps at 64²/223 match 1,023/1,024, 254/256 and 4,074/4,096 U16 pixels, all within one level. For Clouds 2 they match 1,022/1,024, 4,080/4,096 and 256/256. The first pattern maps of Creased and both crystals still differ substantially at the same seed. Crystal 1 also loses 18 exact pixels across its root matrix. All eleven roots remain open. + +### Brick edge distances and storage precision + +To isolate the one-level differences in the [brick renders](#spot-and-brick-pattern-generators), read the pattern map at F32 before the final transform. Compare the same node at U16 with its normal output wiring. Use the 32²/139, 64²/223 and 128²/293 smooth settings in the linked matrix. + +| F32 pattern map | 32² output, 32² map | 64² output, 32² map | 128² output, 64² map | Largest F32 error | +|---|---:|---:|---:|---:| +| Brick 1 | 940/1,024 | 584/1,024 | 2,180/4,096 | 5.72204590e−6 | +| Brick 2 | 992/1,024 | 620/1,024 | 2,072/4,096 | 9.53674316e−7 | + +For both implementations separately, the standard U16 storage conversion of these F32 maps predicts 12,288/12,288 stored pixels, maximum zero. Clamp to [0,1], discard bits below 2⁻²⁰, multiply by 65,535 and round to the nearest integer with ties down. At (7,1) in the 32² map of the 64² first brick, the two F32 edge values are 3cdff221 in the reference and 3cdff1c5 in MaterialCraft. Those values store as levels 1,792 and 1,791. + +An original single-stamp graph separates coverage from placement. Use an unrotated grayscale maximum-blended stamp with smoothness .375. Render the following (width, height, center offset) tuples at 16²/seed 83, 32²/139, 64²/223 and 128²/293. Offsets are from (.5,.5). + +| Width | Height | Center offset | +|---:|---:|---| +| .921875 | .421875 | (0,−.25), (.5,.25) or (0,0) | +| .9609375 | .2109375 | (0,−.375) | +| .4609375 | .2109375 | (−.075,.125) | +| 1 | 1 | (0,0) | + +Keep each footprint and replace the beveled stamp (shape 9) with a pyramid (shape 8). Read horizontal edge distance as the maximum of each pyramid column and vertical distance as the maximum of each row. For each axis let t=clamp(distance×float32(1/.375),0,1), s=float32(t²), c=float32(s×t) and evaluate 3s−2c with a rounded 3s. Multiplying the two axis fades reconstructs **130,560/130,560 F32 bevel pixels**, maximum zero. Computing s×(3−2t) instead gives 112,795/130,560. MaterialCraft already uses the measured edge polynomial. Its local stamp coordinates are the remaining difference in these single-stamp renders. + +### Spot and brick pattern generators + +Each root generates its own grayscale input. The 19 renders per root combine four archive cases, the five [inventory renders](#four-format-inventory-comparison) and ten further settings. Across the 19, each root produced 8,192 U8, 122,880 U16, 8,192 F16 and 33,024 F32 pixels. + +| Root | Exact pixels / compared | Maximum U8 / U16 error (levels) | Maximum F16 / F32 error | +|---|---:|---:|---:| +| Black and white spots 1 | 108/172,288 | 166 / 48,142 | 0.650512695 / 0.782735884 | +| Black and white spots 3 | 122/172,288 | 144 / 54,770 | 0.564941406 / 0.67150037 | +| Brick 1 | 170,632/172,288 | 0 / 1 | 1.52587891e-05 / 1.52587891e-05 | +| Brick 2 | 171,992/172,288 | 0 / 1 | 6.10351562e-05 / 1.52662396e-05 | +| Brick 3 | 51,048/172,288 | 145 / 38,763 | 0.569335938 / 0.730708778 | + +| Size / seed | Spots, disorder | Bricks 1 and 2, tiling / smoothness / gap | Brick 3, tiling / roundness / luminance variation / luminance seed / random position / disorder | +|---|---:|---|---| +| 16² / 83 | Default | Defaults | Defaults | +| 32² / 139 | .15625 | 1 / .125 / .0625 | 1 / .1875 / .25 / 7 / 1 / .0625 | +| 64² / 223 and 743 | .4375 | 2 / .375 / .15625 | 2 / .375 / .625 / 17 / 2 / .3125 | +| 128² / 293 | .8125 | 3 / .6875 / .25 | 3 / .625 / .8125 / 67 / 4 / .6875 | +| 32² / 419 | 1 | 2 / 0 / .3125 | 2 / 0 / 0 / 31 / 2 / 0 | +| 32² / 139, flat control | 0 | 1 / 0 / 0 | 1 / 0 / 0 / 1 / 1 / 0 | + +Render F32 for every row and seed. Also render U8, U16 and F16 at 64²/223. Read each pattern map before its first downstream image operation. At this setting the three spot-1 maps match 0/256, 0/4,096 and 93/1,024 U16 pixels respectively. The three spot-3 maps match 0/1,024, 2/65,536 and 21/256. All three maps already differ with their default settings at 16². + +At 64²/223 the 32² U16 pattern maps before the final transform of bricks 1 and 2 match 952/1,024 and 1,016/1,024 pixels respectively, with a maximum error of one level in each. Both maps match all 256 default pixels at 16², and both match all 1,024 pixels in the flat control. The third brick graph has two pattern maps. At 64²/223 they match 64/1,024 and 840/1,024 U16 pixels, with maximum errors of 32,260 and 8,778. Both match all 1,024 pixels in the flat control. These readbacks separate the first two bricks' small edge differences from the third brick's variable placement and luminance. + +### Beveled square, gradient and wave stamps + +The pattern Tile Generator matches **217,222/226,048** pixels in 43 renders. Before the profile changes it matched 182,039/226,048. U8 matches 16,381/16,384 and U16 matches 162,929/164,608, each with maximum error one level. F16 matches 15,234/16,384 with maximum .0009765625. F32 matches 22,678/28,672 with maximum 3.33786011e−6. The root remains in progress. + +Start with the [four-format inventory inputs](#four-format-inventory-comparison) and add 34 renders. Use defaults, then set X Amount and Y Amount to (1,1) and (2,2). For these three configurations run 16² U16, 32² F32 and 64² in four formats. With (2,2) select pattern identifiers 2, 3, 4, 5, 6, 8, 10 and 11 individually, at 32² F32 and 64² U16. In the order given, the eleven configurations use seed 111+19j starting at j=0. + +| Single-stamp controls | Renders | Exact stored pixels / compared | Largest stored error¹ | +|---|---:|---:|---:| +| Beveled square | 119 | 451,766/578,816 | 1 | +| Horizontal and vertical gradients | 40 | 116,093/163,840 | 1 | +| Wave frequency at eight variations | 8 | 43,727/131,072 | 1.93715096e-06 | +| Translated and out-of-range bevel and wave | 24 | 74,072/98,304 | 1 | + +¹ Integer errors use stored levels. The bevel’s maximum F32 error is 3.81469727e−6, the gradient’s is 5.96046448e−8 and the wave’s is 1.93715096e−6 in the first three sets, respectively. + +For shape 9 the two axes fade independently. On each axis take t=clamp((1−abs(x))/variation,0,1) and apply 3t²−2t³, then multiply the axis results. A nonpositive variation produces a flat stamp. At local coordinates (−.984375,0) and (−.984375,−.984375) with variation .0625, the stored F32 values have bits 3e200000 and 3cc80000. The independent bevel controls use variations 0, .0625, .125, .25, .375, .5, .75, .875 and 1 with seeds 133+11j. Render a unit stamp at 16² and 32² F32, 64² in four formats and 128² F32. At 0, .25, .5 and 1 add a quarter-turn and a (.875,.625) stamp at .0625 turns with offset (.125,−.1875). + +For shape 10, scale the horizontal ramp (x+1)/2 by 1−max(variation,0). In an additive F32 output, variation 1.25 produces a negative ramp. At 64², compare zero turns and .25 turns for variations −.25, 0, .0625, .1875, .25, .375, .5, .75, 1 and 1.25, seeds 101+7j. Under maximum blending the reference’s zero-variation ramp, scaled and clipped for each variation, predicts all 81,920 F32 texels. The full renderer comparison includes placement error. + +For shape 11 the radial term is max(0,1−x²−y²). In eight 128² F32 unit-stamp fields, multiplying the measured column waveform by the reference radial stamp gives 131,072/131,072 exact pixels. Use variations 0, .0625, .1875, .25, .375, .5, .75 and 1, seeds 463+37j. The fitted waveform uses 1.5+6×max(variation,0) cycles per local x unit, a periodic triangle, and a parabolic correction. Local waveform rounding and absolute placement still differ. The separate 64² U16/F32 cases cover −.25 and 1.25, offsets (.0078125,.0078125) at .0625, .375 and .71875, and size (1.375,.6875) at offset (−.0625,.125) and variation .3125. Use seeds 181+19j. + +The [radial profile comparisons](#radial-stamp-profiles-and-pattern-generators) give the previous placement controls. At 64² and 128², float32(2(i+.5)(1−2⁻²⁴)/N−1) predicts the unit gradient coordinates. Four of the 32 axis values at 32² still disagree. Rotated and translated coordinates remain open. + +### Parquet 1 and outstanding inventory controls + +Parquet 1 matches all 289,024 stored pixels across 25 renders. The maximum error is zero in every format. + +| Output | Renders | Exact / compared | +|---|---:|---:| +| LUM8 | 8 | 140,288/140,288 | +| LUM16 | 4 | 25,600/25,600 | +| LUM16F | 4 | 25,600/25,600 | +| LUM32F | 9 | 97,536/97,536 | + +Use the four original archive cases, the [64² format sweep and independent 32² case](#four-format-inventory-comparison), then the following sixteen original parameter cases. Each row lists (Tiling, Luminance_Variation), square output side and seed. The graph has no input pins. + +| Tiling | Luminance variation | Side | Seed | Outputs | +|---:|---:|---:|---:|---| +| 1 | 0 | 32 | 31 | F32 | +| 1 | .125 | 64 | 191 | F32 | +| 2 | .375 | 32 | 653 | U8, U16, F16, F32 | +| 3 | .6875 | 128 | 467 | U8, U16, F16, F32 | +| 4 | 1 | 64 | 977 | U8, U16, F16, F32 | +| 5 | .53125 | 256 | 131 | F32 | +| 7 | .25 | 16 | 821 | F32 | + +Two other roots pass the independent 32² control and retain differences in the nine-render comparison. + +| Root | Exact / compared | Maximum U8 / U16 levels | Maximum F16 / F32 | +|---|---:|---:|---:| +| `pattern_arc_pavement.sbs/arc_pavement` | 132,092/132,096 | 0 / 65535 | 0 / 0 | +| `spot_emboss.sbs/spot_emboss` | 131,394/132,096 | 4 / 411 | 0.00634765625 / 0.00627452135 | + +Arc Pavement differs at four pixels in the archived U16 output. Spot Emboss differs at two pixels in each of the four changed 64² outputs, as well as in its archived U8 cases. + +The table below rechecks one control for each of the 149 roots marked Too hard before the directional stamp measurements. The 32² independent input, parameter values and seed are specified in the [four-format inventory](#four-format-inventory-comparison). The one 64² row uses that root’s changed F32 case. Results use local revision `25ddf9e` except for Arc Pavement, whose matched independent control was replayed at `9ab2e6d`. The three full comparisons above use the latter revision. Later measurements of a root supersede this dated control. Every pixel of an RGBA output must match in all four channels. + +| Root | Control | Format | Exact / compared | Maximum absolute error or cook result | +|---|---|---|---:|---:| +| `directionnal_noise.sbs/directionnal_noise` | 32² independent | LUM32F | 191/1,024 | 2.13086605e-05 | +| `dirt_1.sbs/dirt_1` | 32² independent | LUM32F | 1,023/1,024 | 1.52587891e-05 | +| `dirt_3.sbs/dirt_3` | 32² independent | LUM32F | 1,023/1,024 | 1.52587891e-05 | +| `dirt_6.sbs/dirt_6` | 32² independent | LUM32F | 381/1,024 | 0.121068738 | +| `dirt_gradient.sbs/dirt_gradient` | 32² independent | LUM32F | 0/1,024 | 0.481860787 | +| `fibers_1.sbs/fibers_1` | 32² independent | LUM32F | 1,008/1,024 | 1.52587891e-05 | +| `fluid.sbs/fluid` | 32² independent | LUM32F | 0/1,024 | 0.546566069 | +| `fractal_sum_base.sbs/fractal_sum_base` | 32² independent | LUM32F | 1/1,024 | 0.115129322 | +| `fur_1.sbs/fur_1` | 32² independent | LUM32F | 885/1,024 | 3.05175781e-05 | +| `fur_2.sbs/fur_2` | 32² independent | LUM32F | 6/1,024 | 7.00354576e-06 | +| `fur_3.sbs/fur_3` | 32² independent | LUM32F | 773/1,024 | 3.05175781e-05 | +| `fur_4.sbs/fur_4` | 32² independent | LUM32F | 817/1,024 | 3.05175781e-05 | +| `gaussian_spots_2.sbs/gaussian_spots_2` | 32² independent | LUM32F | 27/1,024 | 3.96370888e-06 | +| `gradient_linear_1.sbs/gradient_linear_1` | 32² independent | LUM32F | 896/1,024 | 6.67572021e-06 | +| `highpass.sbs/highpass` | 32² independent | RGBA32F | 287/1,024 | 1.1920929e-07 | +| `make_it_tile_patch.sbs/make_it_tile_patch` | 32² independent | RGBA32F | 230/1,024 | 0.535881579 | +| `make_it_tile_patch_grayscale.sbs/make_it_tile_patch_grayscale` | 32² independent | LUM32F | 230/1,024 | 0.459052384 | +| `me_water_level.sbs/scratches_2` | 32² independent | RGBA32F | 0/1,024 | 0.300794378 | +| `mesh_1.sbs/mesh_1` | 32² independent | LUM32F | 0/1,024 | 0.856000617 | +| `mesh_2.sbs/mesh_2` | 32² independent | LUM32F | 48/1,024 | 0.984206913 | +| `messy_fibers_1.sbs/messy_fibers_1` | 32² independent | LUM32F | 339/1,024 | 4.6312809e-05 | +| `messy_fibers_2.sbs/messy_fibers_2` | 32² independent | LUM32F | 3/1,024 | 0.00293257833 | +| `messy_fibers_3.sbs/messy_fibers_3` | 32² independent | LUM32F | 1/1,024 | 1.16668423 | +| `messy_fibers_4.sbs/messy_fibers_4` | 32² independent | LUM32F | 0/1,024 | 0.775814459 | +| `microscope_view.sbs/microscope_view` | 32² independent | LUM32F | 0/1,024 | 0.398368992 | +| `moisture_noise.sbs/moisture_noise` | 32² independent | LUM32F | 19/1,024 | 7.79032707e-05 | +| `mosaic.sbs/mosaic` | 32² independent | RGBA32F | 0/1,024 | 0.694117658 | +| `mosaic.sbs/mosaic_grayscale` | 32² independent | LUM32F | 11/1,024 | 0.505882375 | +| `multi_directional_warp.sbs/multi_directional_warp_color` | 32² independent | RGBA32F | 56/1,024 | 0.200000018 | +| `multi_directional_warp.sbs/multi_directional_warp_grayscale` | 32² independent | LUM32F | 611/1,024 | 0.105882347 | +| `noise_bnw_spots_1.sbs/bnw_spots_1` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_bnw_spots_1_v2.sbs/bnw_spots_1` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_bnw_spots_3.sbs/bnw_spots_3` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_bnw_spots_3_v2.sbs/bnw_spots_3` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_cells_1.sbs/cells_1` | 32² independent | LUM32F | 241/1,024 | 4.76837158e-07 | +| `noise_clouds_1.sbs/clouds_1` | 32² independent | LUM32F | 928/1,024 | 1.52587891e-05 | +| `noise_clouds_1_v2.sbs/clouds_1` | 32² independent | LUM32F | 2/1,024 | 9.65595245e-06 | +| `noise_clouds_2.sbs/clouds_2` | 32² independent | LUM32F | 1,020/1,024 | 2.28881836e-05 | +| `noise_clouds_2_v2.sbs/clouds_2` | 32² independent | LUM32F | 11/1,024 | 0.00367540121 | +| `noise_creased.sbs/creased` | 32² independent | LUM32F | 0/1,024 | 0.451300859 | +| `noise_crystal_1.sbs/crystal_1` | 32² independent | LUM32F | 1,010/1,024 | 1.92448497e-05 | +| `noise_crystal_2.sbs/crystal_2` | 32² independent | LUM32F | 0/1,024 | 0.508284688 | +| `noise_directional_noise_1.sbs/directional_noise_1` | 32² independent | LUM32F | 800/1,024 | 2.67028809e-05 | +| `noise_directional_noise_1_v2.sbs/directional_noise_1` | 32² independent | LUM32F | 0/1,024 | 0.00392669439 | +| `noise_directional_noise_2.sbs/directional_noise_2` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_directional_noise_2_v2.sbs/directional_noise_2` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_directional_noise_3.sbs/directional_noise_3` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_directional_noise_3_v2.sbs/directional_noise_3` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_directional_noise_4.sbs/directional_noise_4` | 32² independent | LUM32F | 54/1,024 | 1.78813934e-06 | +| `noise_directional_noise_4_v2.sbs/directional_noise_4` | 32² independent | LUM32F | 46/1,024 | 2.32458115e-06 | +| `noise_directional_scratches.sbs/directional_scratches` | 32² independent | LUM32F | 698/1,024 | 5.12599945e-06 | +| `noise_directional_scratches_v2.sbs/directional_scratches` | 32² independent | LUM32F | 506/1,024 | 4.62494791e-06 | +| `noise_dirt_1.sbs/dirt_1` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_dirt_1_v2.sbs/dirt_1` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_dirt_2.sbs/dirt_2` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_dirt_3.sbs/dirt_3` | 32² independent | LUM32F | 50/1,024 | 3.20076942e-05 | +| `noise_dirt_3_v2.sbs/dirt_3` | 32² independent | LUM32F | 23/1,024 | 2.25305557e-05 | +| `noise_dirt_4.sbs/dirt_4` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_dirt_4_v2.sbs/dirt_4` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_dirt_5.sbs/dirt_5` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_dirt_5_v2.sbs/dirt_5` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_dirt_gradient.sbs/dirt_gradient` | 32² independent | LUM32F | 0/1,024 | 0.257863402 | +| `noise_dirt_gradient_v2.sbs/dirt_gradient` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_fluid.sbs/fluid` | 32² independent | LUM32F | 0/1,024 | 0.332752407 | +| `noise_fractal_sum_base.sbs/fractal_sum_base` | 32² independent | LUM32F | 0/1,024 | 0.150255591 | +| `noise_fractal_sum_base.sbs/fractal_sum_base_2` | 32² independent | LUM32F | 0/1,024 | 0.121705964 | +| `noise_fractal_sum_base_v2.sbs/noise_blend` | 32² independent | LUM32F | 82/1,024 | 0.392156869 | +| `noise_fractal_sum_base_v2.sbs/noise_upscale` | 32² independent | LUM32F | 0/1,024 | 0.228064887 | +| `noise_fur_1.sbs/fur_1` | 32² independent | LUM32F | 2/1,024 | 1.6450882e-05 | +| `noise_fur_2.sbs/fur_2` | 32² independent | LUM32F | 4/1,024 | 1.35451555e-05 | +| `noise_fur_3.sbs/fur_3` | 32² independent | LUM32F | 3/1,024 | 1.21295452e-05 | +| `noise_gaussian_noise.sbs/gaussian_noise` | 32² independent | LUM32F | 46/1,024 | 3.57627869e-07 | +| `noise_gaussian_noise_v2.sbs/gaussian_noise` | 32² independent | LUM32F | 44/1,024 | 3.57627869e-07 | +| `noise_gaussian_spots_2.sbs/gaussian_spots_2` | 32² independent | LUM32F | 23/1,024 | 1.37388706e-05 | +| `noise_gaussian_spots_2_v2.sbs/gaussian_spots_2` | 32² independent | LUM32F | 2/1,024 | 1.42455101e-05 | +| `noise_liquid.sbs/liquid` | 32² independent | LUM32F | 0/1,024 | 0.209913433 | +| `noise_messy_fibers_1.sbs/messy_fibers_1` | 32² independent | LUM32F | 18/1,024 | 2.97576189e-05 | +| `noise_messy_fibers_1_v2.sbs/messy_fibers_1` | 32² independent | LUM32F | 17/1,024 | 1.94311142e-05 | +| `noise_messy_fibers_2.sbs/messy_fibers_2` | 32² independent | LUM32F | 6/1,024 | 4.4375658e-05 | +| `noise_messy_fibers_2_v2.sbs/messy_fibers_2` | 32² independent | LUM32F | 4/1,024 | 5.65648079e-05 | +| `noise_messy_fibers_3.sbs/messy_fibers_3` | 32² independent | LUM32F | 37/1,024 | 1.16653473 | +| `noise_messy_fibers_3_v2.sbs/messy_fibers_3` | 32² independent | LUM32F | 3/1,024 | 1.1268341 | +| `noise_microscope_view.sbs/microscope_view` | 32² independent | LUM32F | 0/1,024 | 0.103792138 | +| `noise_moisture_noise.sbs/moisture_noise` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_moisture_noise_1_v2.sbs/moisture_noise_1` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_moisture_noise_2.sbs/moisture_noise_2` | 32² independent | LUM32F | — | Pattern traversal budget | +| `noise_perlin_noise.sbs/perlin_noise` | 32² independent | LUM32F | 996/1,024 | 3.05771828e-05 | +| `noise_perlin_noise_v2.sbs/perlin_noise` | 32² independent | LUM32F | 97/1,024 | 5.66244125e-07 | +| `noise_plasma.sbs/plasma` | 32² independent | LUM32F | 1,005/1,024 | 1.52587891e-05 | +| `non_uniform_blur.sbs/non_uniform_blur_grayscale_sample` | 32² independent | LUM32F | 669/1,024 | 0.00784315169 | +| `non_uniform_blur.sbs/non_uniform_blur_sample` | 32² independent | RGBA32F | 247/1,024 | 0.00784315169 | +| `normal_to_height_2.sbs/normal_to_height` | 32² independent | LUM32F | 270/1,024 | 0.305256728 | +| `paper_path.sbs/paper_path` | 32² independent | LUM32F | 7/1,024 | 0.0057874918 | +| `parquet_1.sbs/parquet_1` | 32² independent | LUM32F | 1,024/1,024 | 0 | +| `paths_tools.sbs/paths_trace` | 32² independent | RGBA32F | 901/1,024 | 1.66666675 | +| `pattern_arc_pavement.sbs/arc_pavement` | 32² independent | LUM32F | 1,024/1,024 | 0 | +| `pattern_brick_1.sbs/brick_1` | 32² independent | LUM32F | 712/1,024 | 2.08616257e-06 | +| `pattern_brick_2.sbs/brick_2` | 32² independent | LUM32F | 444/1,024 | 1.02072954e-06 | +| `pattern_fibers_1.sbs/fibers_1` | 32² independent | LUM32F | 1,008/1,024 | 1.52587891e-05 | +| `pattern_fibers_2.sbs/fibers_2` | 64² changed | LUM32F | 3,976/4,096 | 3.05175781e-05 | +| `pattern_mesh_1.sbs/mesh_1` | 32² independent | LUM32F | 0/1,024 | 0.856000617 | +| `pattern_mesh_2.sbs/mesh_2` | 32² independent | LUM32F | 48/1,024 | 0.984206913 | +| `pattern_polygon_2.sbs/polygon_2` | 32² independent | LUM32F | 1,012/1,024 | 1.52587891e-05 | +| `pattern_shape.sbs/shape_base` | 32² independent | LUM32F | 720/1,024 | 1.37090683e-06 | +| `pattern_splatter_circular.sbs/splatter_circular` | 32² independent | LUM32F | 1,003/1,024 | 0.921568625 | +| `pattern_splatter_circular.sbs/splatter_circular_color` | 32² independent | RGBA32F | 1,003/1,024 | 0.996078431 | +| `pattern_tile_generator.sbs/tile_generator_color` | 32² independent | RGBA32F | 0/1,024 | 4.99215698 | +| `pattern_tile_random.sbs/tile_random_color` | 32² independent | RGBA32F | 735/1,024 | 1 | +| `pattern_tile_random_2.sbs/tile_random_2` | 32² independent | LUM32F | 363/1,024 | 1 | +| `pattern_weave_1.sbs/weave_1` | 32² independent | LUM32F | 0/1,024 | 1 | +| `pattern_weave_2.sbs/weave_2` | 32² independent | LUM32F | 26/1,024 | 0.780254856 | +| `pavement_1.sbs/pavement_1` | 32² independent | LUM32F | 64/1,024 | 0.718337655 | +| `pbr_render_ortho.sbs/blue_noise` | 32² independent | RGBA32F | 0/1,024 | 1.99178356 | +| `pbr_render_ortho.sbs/ibl_shadow_pass` | 32² independent | RGBA32F | 0/1,024 | 28.3294125 | +| `pbr_render_ortho.sbs/sphere_displace` | 32² independent | RGBA32F | 1,022/1,024 | 1.52587891e-05 | +| `perlin_noise_zoom.sbs/perlin_noise_zoom` | 32² independent | LUM32F | 48/1,024 | 6.2584877e-07 | +| `quantize_color.sbs/kmeans_iteration` | 32² independent | RGBA32F | 4,080/4,096 | 5.96046448e-08 | +| `radial_blur.sbs/radial_blur_grayscale` | 32² independent | LUM32F | 315/1,024 | 0.00073248148 | +| `replace_color.sbs/replace_color` | 32² independent | RGBA32F | 0/1,024 | 0.244705796 | +| `rt_caustics.sbs/rt_caustics_base` | 32² independent | LUM32F | 199/1,024 | 0.0106643774 | +| `scratches_1.sbs/scratches_1` | 32² independent | LUM32F | 508/1,024 | 1.59740448e-05 | +| `scratches_2.sbs/scratches_2` | 32² independent | LUM32F | 9/1,024 | 1.24573708e-05 | +| `scratches_4.sbs/scratches_4` | 32² independent | LUM32F | 0/1,024 | 1 | +| `shape.sbs/shape_base` | 32² independent | LUM32F | 720/1,024 | 1.37090683e-06 | +| `shape_splatter_v2.sbs/shape_splatter_compute_normal` | 32² independent | RGBA32F | 0/1,024 | 0.979619235 | +| `slope_blur.sbs/slope_blur` | 32² independent | RGBA32F | 0/1,024 | 0.76862745 | +| `slope_blur.sbs/slope_blur_grayscale` | 32² independent | LUM32F | 12/1,024 | 0.32941179 | +| `slope_blur.sbs/slope_blur_grayscale_2` | 32² independent | LUM32F | 12/1,024 | 0.32941179 | +| `splatter.sbs/splatter` | 32² independent | LUM32F | 112/1,024 | 0.475806788 | +| `splatter_circular.sbs/splatter_circular` | 32² independent | LUM32F | 959/1,024 | 1.00000006 | +| `splatter_circular.sbs/splatter_circular_color` | 32² independent | RGBA32F | 879/1,024 | 0.996078431 | +| `splatter_color.sbs/splatter_color` | 32² independent | RGBA32F | 112/1,024 | 0.484412894 | +| `spline_tools.sbs/internal_tools/modify_spline_property_sub` | 32² independent | RGBA32F | 969/1,024 | 0.261176467 | +| `spline_tools.sbs/internal_tools/points_preview` | 32² independent | LUM32F | 1,024/1,024 on the exported output | External font unavailable | +| `spline_tools.sbs/internal_tools/resample_spline_data` | 32² independent | RGBA32F | 986/1,024 | 0.5 | +| `spline_tools.sbs/internal_tools/select_spline_sub` | 32² independent | RGBA32F | 30,720/32,768 | 0.5 | +| `spline_tools.sbs/internal_tools/spline_warp_sub` | 32² independent | RGBA32F | 992/1,024 | 0.181807004 | +| `spot_emboss.sbs/spot_emboss` | 32² independent | RGBA32F | 1,024/1,024 | 0 | +| `starburst.sbs/starburst` | 32² independent | LUM32F | 796/1,024 | 0.853360829 | +| `tile_generator.sbs/tile_generator` | 32² independent | LUM32F | 862/1,024 | 3.93390656e-06 | +| `tile_generator_color.sbs/tile_generator_color` | 32² independent | RGBA32F | 494/1,024 | 1 | +| `tile_random.sbs/tile_random` | 32² independent | LUM32F | 724/1,024 | 1.00000006 | +| `tile_random.sbs/tile_random_color` | 32² independent | RGBA32F | 148/1,024 | 1.00000006 | +| `tileable_material_to_mesh_material.sbs/tileable_material_to_mesh_material` | 32² independent | RGBA32F | 477/1,024 | 5.96046448e-08 | +| `vertical_noise.sbs/vertical_noise` | 32² independent | LUM32F | 215/1,024 | 2.12192535e-05 | +| `weave_1.sbs/weave_1` | 32² independent | LUM32F | 0/1,024 | 1 | +| `weave_2.sbs/weave_2` | 32² independent | LUM32F | 6/1,024 | 0.243778139 | +| `wood_fibers_1.sbs/wood_fibers_1` | 32² independent | LUM32F | 985/1,024 | 1.93715096e-05 | +| `wood_fibers_2.sbs/wood_fibers_2` | 32² independent | LUM32F | — | Pattern traversal budget | + +Of the 149 controls, three match exactly and 125 have measured pixel differences. Twenty pattern traversals reached the execution budget. One text graph requires an external font. The 20 incomplete traversals produced no comparable pixels. The font case exported 1,024 matching pixels with a cook error on its text branch and stays open. + +### Uniform arc tangents and pavement rotations + +Arc Pavement now matches all 132,096 pixels in the nine [previous render comparisons](#quarter-turn-stamps-and-render-bounds). The four missing pixels at y=104 in the default 256² image now match. An additional 18 renders expose differences on continuous stamp profiles and image inputs. Across all 27 renders, 202,429/211,200 pixels match. The maximum errors by format are 0 U8 levels, 12,009 U16 levels, 0 in F16, and .197752327 in F32. + +The full default graph draws 322 stamps. To compare its individual parameters, initialize a counter to zero before the first Iterate, increment it once per drawn stamp, and draw the selected parameter as a one-pixel square in a 32-column grid at 256² F32, seed 0. Record the index, both offset components, both size components and the rotation. Add two to signed offsets and rotations for these reads. Before the fix the two apps agreed on every index, offset and size, but only 14/322 rotations. The maximum difference was .00001859665 turns. All six fields now match, including all 322 rotations and all 393,216 stored pixels. Replaying the twenty [isolated edge controls](#quarter-turn-stamps-and-render-bounds) matches all 1,310,720 F32 pixels. + +The rotation uses the arc tangent of a two-component vector. The first-octant approximation that already matched the pixel processor also fits node parameters, value processors and pattern parameters. These three scopes divide the smaller absolute component by the larger and round each polynomial product and sum separately. Pixel processing uses its reciprocal and fused dot-product arithmetic. At (1,.1316152) the uniform result has F32 bits `3e061f75` and the pixel result has bits `3e061f76`. At (1,1) both runtime results have bits `3f490fe1`. A literal (1,1) gives `3f490fdb` in all four scopes. + +| Original angle controls | Cases | Exact image pixels | Exact typed scalars | Maximum error | +|---|---:|---:|---:|---:| +| Quadrants, axes and two literal vectors in four scopes | 100 | 44,544/44,544 | 25/25 | 0 | +| Signed zeros, exponent boundaries and an ordinary off-axis vector in four scopes | 60 | 11,520/11,520 | 15/15 | 0 | +| One angle per pixel on four pattern grids | 4 | 10,240/10,240 | — | 0 | + +For the first row, test the eight signed permutations of (1,.1316152), the four diagonals, the four unit axes, zero, (.379,−.811), (−.812,.323), (.015625,.0068359375), (−.875,−.296875), (2⁻²⁴,−2⁻²²) and (128,4.875). Alternate sides 16 and 32, using seed 897 + 31i. Use literal (1,1) and (.379,−.811) at 16². For the second row use 16² and seed 967+i, with (0,−0), (−0,1), (−0,−1), (−1,−0), (−t,−t), (t,m), (m,t), (1,t), (m,1), (1,m), (m,m), (2m,m), (2¹²⁶,2¹²⁵), (2¹²⁷,2¹²⁶) and (1.25,.23243791), where t=2⁻¹²⁷ and m=2⁻¹²⁶. The large final power-of-two pair distinguishes scalar division from the rounded pixel reciprocal. + +For the grids use sides 64, 32, 64 and 32 and seed 719+37j. The first grid evaluates (1,(i+.5)/4096). For the other three set b=1+((7i mod 29)/16) and a=b(i+f)/N². Use (b,a), (−a,b) and (−b,−a) with f=.25,.75,.25 respectively. Draw in row order with a single Iterate and square stamps of size .875/N. + +| Additional Arc Pavement controls | Exact pixels / compared | Maximum error | +|---|---:|---:| +| Defaults, square controls and varied discs | 55,552/55,552 | 0 | +| Paraboloid, bell, pyramid and capsule | 7,819/10,240 | .00000987947 F32 | +| First image, filter controls 0, 1 and 2 | 6,210/12,288 | .197752327 F32 | +| Independent image | 752/1,024 | 12,009 U16 levels | + +For defaults use 16², 32² and 128² F32 at seeds 101, 271 and 401. Set scale 1, five patterns, six arcs, square width .625 and height .8125 for 64² in all four formats at seed 829. For the discs set scale 2, nine patterns, minimum three, amount randomness .375, five arcs, width .78125, height .6875, pattern scale .875, width and height randomness .125 and .25, global width randomness .1875, height decrease .375 and color randomness .625. Use 64²/43, 128²/191 and 32²/503. Change this configuration to shape 4, 5, 8 or 15 with variation .375 at seed 547, alternating 64² and 32². For the first three image controls use the square configuration with image input, variation .25 and color randomness .3125 at 64² F32/607. Bind the independent grayscale field from the [four-format comparison](#four-format-inventory-comparison). For the last image use the varied configuration with filter 0 and the original 128² grayscale ramp at 32² U16/787. + +These image tests also expose a separate file-handoff difference. Reopening the [saved Arc Pavement file](#integer-defaults-in-saved-graph-interfaces) and rendering the three image-filter cases produced black. The original file has 2,026 nonzero pixels in each. Its six previously reported saved-file comparisons exercised the default and disc controls. + +### Other roots using uniform arc tangents + +These measurements follow the [uniform arc-tangent correction](#uniform-arc-tangents-and-pavement-rotations). For each root, replay its archived defaults, seeds and changed controls, then the [four 64² formats and the independent 32² input](#four-format-inventory-comparison). For both Stripes roots also replay the nine [hard-edge and filtered controls](#facet-masks-and-stripe-boundaries). Integer maxima count stored levels. + +| Root | Cases | Exact pixels / compared | Maximum U8 / U16 | Maximum F16 / F32 | +|---|---:|---:|---:|---:| +| Bevel Smooth debug position | 13 | 246,632/246,784 | 64 / 16384 | 0.25 / 0.25 | +| Dirt 4 | 9 | No comparable pixels | — | — | +| Dirt 4, second version | 9 | No comparable pixels | — | — | +| Non-uniform blur sample, grayscale | 9 | 96,971/132,096 | 4 / 771 | 0.01171875 / 0.0117647052 | +| Non-uniform blur sample, color | 9 | 50,664/132,096 | 4 / 771 | 0.0119628906 / 0.011764735 | +| Circular splatter, grayscale | 9 | 130,917/132,096 | 223 / 57311 | 0.874511719 / 0.921568625 | +| Circular splatter, color | 9 | 130,678/132,096 | 254 / 65535 | 0.996078491 / 0.996078431 | +| Pattern Stripes | 18 | 215,036/215,040 | 255 / 65535 | 1 / 1 | +| Irradiance hit UV debug | 8 | 115,708/115,712 | 0 / 0 | 0 / 7.4505806e-09 | +| Standalone Stripes | 18 | 215,012/215,040 | 0 / 65535 | 0 / 0 | + +The remaining hard edge on Pattern Stripes is (23,59) at 128². MaterialCraft returns zero and the reference returns one at that pixel in each of the four output formats. Standalone Stripes matches every hard-edge control and retains 28 differences in the archived U16 renders. Both Dirt 4 versions reach the pattern traversal budget before producing an image in all nine cases. The additional [wired irradiance controls](#environment-rotation-and-wired-irradiance-samples) include nonfinite stamp parameters and remain open. + +### Runtime selection across disconnected image sockets + +All 66 two-input cases in [image selection in saved graphs](#image-selection-in-saved-pattern-graphs) now match **194,304/194,304 pixels**, maximum error zero. A selector read at runtime uses the first wired image socket at or above the requested index. Requests above the last socket use the last image. With only slots 0 and 3 wired, a request for 1 or 12 samples slot 3, and −1 samples slot 0. With no images the stamp contributes nothing. A literal selecting an empty socket still contributes nothing. This resolves the 8,832 differing pixels in the previous two-pin measurement. + +Use the same four 16² constant fields with byte values 31, 79, 151 and 229. Wire all four, {0,2,3}, {0,2}, {1,3}, {2}, no sockets, {0,3}, {1}, or {0}. Read an exposed integer set to −1, 0, 1, 2, 3, 4 and 12, then repeat with a literal 12. Repeat the seven runtime selections with all four sockets and packed pattern types 256, 257 and 259. The runtime index takes precedence even at zero. Across the 93 F32 renders the selected byte values agree at **23,808/23,808 pixels**. The raw float results agree at **14,848/23,808**, maximum 2.98023224e−8. The thirty earlier fixed four-input cases still match 5,632/7,680 raw F32 pixels and all 7,680 selected bytes. The remaining raw error occurs when rendering the selected constant image. + +Arc Pavement retains its separate measurements of 202,429/211,200 CPU-cooked pixels and 112,896/112,896 saved-file pixels. The earlier [file handoff](#image-selection-in-saved-pattern-graphs) gives the version and parameters. + +### Image selection in saved pattern graphs + +When opening Arc Pavement, the first image socket is `pattern0`. An omitted `imageindex` selects that socket. MaterialCraft previously wrote an explicit 1 when saving such a graph. The reference app then sampled an empty second socket. MaterialCraft now defaults the index to zero, and its numeric image selector and SBS writer use the same slot numbers. For automation that sets `imageindex` explicitly, use 5 for the sixth connected image. A nonzero positive selector also overrides the slot embedded in pattern codes 256 through 511. A negative selector draws nothing in the measured controls. + +Use one full-frame grayscale image stamp. With one 64² pin, bind a constant byte 173 or a checker alternating bytes 0 and 255. Test a white square, generic image type 1 with selectors 0, 1, 2 and omitted, packed types 256 and 257, and a graph-controlled image type with selectors 0 or 1. All 73,728/73,728 F32 pixels match over 18 renders. With two inputs, bind the same constant to the first slot and the checker to the second. Test omitted, negative, zero, one and two, three packed forms, then a variable selector reading 0, 1 and 2. For each configuration compare 16² and 32² F32 and 64² U8, U16, F16 and F32, seed 859+13j+i. + +| How the slot was specified | Renders | Exact pixels / compared | Maximum error | +|---|---:|---:|---| +| Two pins, fixed selections and runtime slots zero or one | 60 | 176,640/176,640 | 0 | +| Two pins, runtime slot two | 6 | 8,832/17,664 | 255 U8, 65,535 U16, 1 F16/F32 | +| Two pins, additional packed selections at 16² F32 | 12 | 3,072/3,072 | 0 | +| Four distinct constant pins at 16² F32 | 30 | 5,632/7,680 | 2.98023224e−8 | + +For the four-pin case use byte levels 31, 79, 151 and 229. At seed 885, cross pattern types 1, 256, 257, 258 and 259 with indices 0, 1, 2, 3, 4 and −1. Rounding both float outputs back to bytes gives 7,680/7,680 identical socket selections. The remaining raw float differences are in the sampled value. With two pins a runtime request for slot two samples the last pin in the reference app, while MaterialCraft produces black. This explains all differences in the 66 two-pin renders. + +For saved-file fidelity, start at format version `1.1.0.202502`, save and reopen through MaterialCraft's ordinary `file.saveAs`, then open the resulting file directly in the reference app and compare it with the original in that same app. Arc Pavement matches all 112,896/112,896 pixels across the six [original handoff cases](#integer-defaults-in-saved-graph-interfaces) and all 18 [expanded root cases](#uniform-arc-tangents-and-pavement-rotations), maximum error zero. This includes the three 64² F32 image inputs that previously returned black and the independent 32² U16 input. Spot Emboss again matches all 33,792/33,792 pixels across six cases. The two files saved with their original `0.1.3` header still have the documented load failure. The separate MaterialCraft cook comparison for Arc Pavement remains at 202,429/211,200 matching pixels. + +### Integer defaults in saved graph interfaces + +Two packages with a `0.1.3` format header failed to reopen in the reference app after MaterialCraft Save As. Changing only that field to `1.1.0.202502` in a temporary copy let the reference app open both packages. Spot Emboss then reproduced all six original renders. Arc Pavement reproduced its default render, but six scalar integer settings had no readable default on the saved graph. The [earlier round trips](#vector-equality-lab-to-rgb-and-sbs-round-trips) cover a separate function library and a package that failed to load. + +A minimal graph declared three signed integer defaults of −3, 37 and 16,777,217. With `constantValueInt32` in each input declaration the reference app reported three unset defaults and a new instance reported 0, 0 and 0. With `constantValueInt1` it reported all three original integers both on the declaration and on the instance. A separate value processor reading the largest control returned 16,777,216 with either spelling. MaterialCraft now writes the one-lane spelling for scalar integer and enumeration defaults on graph interfaces. On Arc Pavement the public interface then reported `scale=1`, `pattern_amount=12`, `pattern_min_amount=1`, `arcs_amount=14`, `pattern=2` and `input_image_filtering=0`. + +For the end-to-end check, set the input package header to `1.1.0.202502`, use MaterialCraft's ordinary `file.saveAs`, then open the resulting file directly in the reference app. Compare each saved file against the original graph cooked in that same app. Use the default controls at 128² U16, the [changed controls and original input fields](#quarter-turn-stamps-and-render-bounds) at 64² in U8, U16, F16 and F32 with seed 42, and the independent fields at 32² F32 with seed 113. + +| Saved graph | Renders | Exact pixels / compared | Maximum channel error | +|---|---:|---:|---:| +| Spot Emboss | 6 | 33,792/33,792 | 0 | +| Arc Pavement | 6 | 33,792/33,792 | 0 | + +Ordinary saves preserve the source format version. The two observed load failures with the original header remain open. The figures in this table measure saved-file fidelity within the reference app. MaterialCraft's own render comparisons are recorded under [quarter-turn stamps and render bounds](#quarter-turn-stamps-and-render-bounds). + +### Empty size-dependent pattern branches + +The two black-and-white Spots 1 graphs repeatedly visit a switch whose condition depends only on the output dimensions. At 32² its selected child is disconnected. The CPU cook now remembers that decision within the current cook and skips later copies of the empty branch. It includes the branch depth when normalizing roughness. Function assignments, random draws, image sampling and per-visit inputs stay on the evaluated path. The maximum number of evaluated visits, repeated children, stamp copies and pixel samples retain their existing limits. + +| Original controls | Renders | Exact / compared | Maximum error | +|---|---:|---:|---:| +| Small repeated switch | 8 | 43,520/43,520 | 0 | +| Shared switch at two depths | 8 | 43,520/43,520 | 0 | +| 1,024 × 1,024 repeated switch | 1 | 256/256 | 0 | + +In a grayscale pattern graph, use a switch with only its right output connected to a unit square. Its predicate is the X component of the log₂ output size ≥ 6. For the first row, use an Iterate with an initial unit square and two repeats of an inner Iterate that visits the switch three times. Use additive drawing, white stamps and roughness zero. For the second row, use roughness one. Draw a unit square on the root quadrant, connect slot 0 to the switch, and connect slot 3 to an empty quadrant whose slot 3 reaches the same switch. Use sides 16, 32, 64 and 128, seed 373 + side, and U16 and F32 output. For the final row use the first graph at 16² F32 and seed 389, with both repeat counts set to 1,024. Previously the first sixteen renders matched and the final render stopped at the execution limit. An additional CPU regression exercises a seed expression that increments a user variable at a disconnected switch. + +| Root | Exact / compared | U8 exact / total · max levels | U16 exact / total · max levels | F16 exact / total · max absolute | F32 exact / total · max absolute | +|---|---:|---:|---:|---:|---:| +| `noise_bnw_spots_1.sbs/bnw_spots_1` | 3,216/132,096 | 3,040/4,096 · 1 | 176/118,784 · 5958 | 0/4,096 · 0.0029296875 | 0/5,120 · 0.00304281712 | +| `noise_bnw_spots_1_v2.sbs/bnw_spots_1` | 35,010/132,096 | 32,285/118,784 · 16 | 851/4,096 · 146 | 1,847/4,096 · 0.00231933594 | 27/5,120 · 0.0022289902 | + +Each root now produces comparable output in all nine renders. Use defaults at 128² and 256² with seed zero and at 128² with seed 42. The changed cases use scale 2, disorder .37 and roughness .6. On the second version also set disorder speed .6, anisotropy .3, anisotropy angle .125 and tile offset (.17,.29). Run the changed settings at 128²/seed zero, at 64²/seed 42 in the four formats and at 32²/seed 113 in F32. These graphs have no image inputs. At 32² the first version matches 0/1,024, maximum .00304281712, and the second matches 8/1,024, maximum .000147402287. + +Of the [twenty previously incomplete pattern controls](#parquet-1-and-outstanding-inventory-controls), eighteen still reach the traversal limit at 32² on this revision. No comparison pixels are available for those eighteen. + +The seventeen repeated inventory matrices returned the same per-format counts and maxima as before. The matched-resolution Position Debug preview and sixteen additional Spot Emboss renders matched all 86,528 pixels. + +### Quarter-turn stamps and render bounds + +For an axis-aligned rectangle whose edges pass through pixel centers, the sample on the right or bottom edge belongs to the rectangle. Rotation by whole quarter turns and a negative stamp dimension preserve this ownership in image space. At 64², a .625 × .25 rectangle centered at (.5078125,.5078125) and rotated .25 turns covers columns 25 through 40 and rows 13 through 52, inclusive. The CPU cook now uses exact quarter-turn axes and measures these boundaries in image space. A reversed render-region interval selects [0,1] on that axis. Increasing intervals retain their supplied endpoints. + +| Original F32 controls | Renders | Previous exact | Current exact / compared | Current maximum absolute error | +|---|---:|---:|---:|---:| +| Square and disc | 36 | 257,761 | 258,048/258,048 | 0 | +| Pyramid and gradient | 36 | 231,067 | 233,454/258,048 | 1.1920929e-07 | +| Signed dimensions and render bounds | 16 | 64,229 | 65,536/65,536 | 0 | +| Subregion, square | 8 | 28,684 | 32,768/32,768 | 0 | +| Subregion, gradient | 8 | 23,990 | 29,042/32,768 | 1.78813934e-07 | +| Rotated squares | 78 | 4,542,662 | 4,542,719/4,542,720 | 1 | + +For the first two rows, render a single untiled stamp with roughness zero, size (.625,.25) and offset (1/128,1/128) from the image center. Use shapes 2, 3, 8 and 10, turns 0, .25, .5, .75, −.25 and 1.25, and sides 32, 64 and 128. With zero-based shape and angle indices, the seed is 577 + 71 × shape index + 17 × angle index + side. + +For the third row, use side 64, the same offset, shape 2 and turns 0 or .25. First negate X, Y or both stamp dimensions. Then use positive dimensions and reverse each full render axis in turn or both together. Finally crop only X or only Y to [.25,.75]. The seed is 237 + 13 × configuration index + angle index. For the fourth and fifth rows, use [3/16,13/16] × [1/4,3/4] and [5/16,15/16] × [1/8,7/8]. Reverse neither axis, X, Y or both, in that order. Use shapes 2 and 10 at zero rotation, seed 717 + 13 × configuration index + shape. + +For the final row, render the following (width, height, turns, X offset, Y offset) at sides 16, 32, 64, 128, 256 and 512. The seed is 361 + 47 × configuration index + side. + +(0.375, 0.625, 0, 0, 0) (0.5, 0.75, 0.125, 0, 0) (0.5, 0.75, -0.125, 0.03125, -0.125) (0.375, 0.625, 0.0625, 0.109375, -0.1875) (0.433, 0.219, 0.071, 0.127, -0.192) (0.755, 0.391, 0.13125, -0.1113, 0.1437) (0.625, 0.25, 0.25, 0.0078125, 0.0078125) (0.75, 0.5, 0.125, 0.001953125, -0.00390625) (0.8193, 0.517, 0.31, 0.0682, -0.1083) (0.75, 0.75, 0.03125, -0.05, 0.081) (0.017578125, 0.013671875, 0.075, 0.123046875, 0.0673828125) (0.355, 0.28, -0.073, 0.412, 0.327) (0.87, 0.22, 0.3125, -0.2725, 0.405). + +One oblique square pixel at 512² differs by 1.0. The 256² Arc Pavement root retains four U16 differences at (17,104), (110,104), (145,104) and (238,104), each 65,535 levels. For each pixel, take the contributing square's computed center, dimensions and angle from MaterialCraft, wrap the center into the image, and render it alone in both apps. Shift its center along the outward normal towards that pixel by 0, .0004, .0008, −.0008 and .002 pixels. Both apps return zero at the target at the first two offsets and one at .0008. All 1,310,720 pixels in the twenty F32 renders agree. The native full graph still covers the four target pixels. Its computed stamp parameters and tiling remain to be compared. + +| Root | Renders | Exact / compared | Maximum U8 / U16 levels | Maximum F16 / F32 | +|---|---:|---:|---:|---:| +| Gradient Linear 1 | 47 | 435,120/435,968 | 1 / 1 | 0.000244140625 / 1.52587891e-05 | +| Gradient Linear 3 | 23 | 265,072/277,760 | 0 / 2 | 0 / 3.05175781e-05 | +| Spot Emboss | 25 | 218,368/218,368 | 0 / 0 | 0 / 0 | + +All three rows include the four archive renders, the [four-format sweep and independent 32² control](#four-format-inventory-comparison). For both gradients, add eight (tiling, rotation, side) groups [(1,0,16), (3,1,32), (2,0,64), (5,2,128), (1,1,256), (4,3,64), (3,0,32), (1,1,32)]. Use F32, plus U8, U16 and F16 for the second and fourth groups. The seed is 197 + 53 × group index. Gradient Linear 1 additionally uses [(1,0,16), (1,1,64), (1,2,64), (1,3,64), (2,0,32), (3,1,128), (4,2,32), (5,3,64), (7,0,128), (8,1,256), (2,2,16), (3,3,32)], seed 1991 + 47 × group index. Add U8, U16 and F16 to groups 1, 2, 3 and 6 using zero-based indices. The remaining mismatches in Gradient Linear 1 occur at rotation 3. At tiling 4, rotation 3 and side 64 the earliest observed difference is in the U16 pattern image, with 4,000/4,096 exact pixels and a maximum of one level. + +For Spot Emboss, the sixteen additional renders use the following (side, seed, light X, light Y, intensity) groups [(16,37,.5,.5,5), (32,907,.25,.75,2), (64,131,.75,.125,1), (128,521,.4375,.5625,4), (64,359,.5,.5,0), (32,977,.875,.875,3), (64,419,.0625,.1875,9)]. The first group uses all default parameters. The other groups use highlight (.875,.625,.25,.75) and shadow (.125,.25,.4375,.625). Use F32 throughout, adding U8, U16 and F16 for zero-based groups 1, 3 and 5. Generate 32² input fields for even groups and 64² for odd groups. With pixel indices x, y and group index j, the U16 height is (16381 × floor(x/4) + 271y + 37xy + 421j) modulo 65536. RGBA8 is (13x+11y+19j, 23y+5x, 9xy+17j, 3x+7y+29j), each channel modulo 256. All 25 Spot Emboss renders are exact, including the previously differing [archived cases and four changed renders](#parquet-1-and-outstanding-inventory-controls). + +Twenty-one previously verified roots with a reachable pattern or directional blur filter match all 3,334,656 pixels in 164 equal-resolution renders. The [controlled 128² Position Debug preview](#tinted-stamp-offsets-and-alpha) supplies the equal-resolution comparison for the capped preview. + +### Tinted stamp offsets and alpha + +The directional gradient and hemisphere add signed variation to each channel after tint and opacity. The hemisphere applies the offset inside its support disk. Color blend modes 1 and 2 composite the premultiplied source over the background with its signed alpha. Mode 0 adds RGB and accumulates alpha as background alpha plus source alpha times the remaining background transparency. Grayscale modes 1 and 2 take the maximum. A constant RGBA background in a grayscale graph contributes the mean of its three color channels. + +| F32 single-stamp controls | Renders | Previous exact | Current exact / compared | Maximum absolute error | +|---|---:|---:|---:|---:| +| Transparent RGBA | 18 | 5,076 | 14,042/18,432 | 7.30156898e-07 | +| RGBA over a fixed background | 12 | 2,661 | 11,182/12,288 | 1.1920929e-07 | +| Square, gradient and hemisphere over a fixed background | 30 | 2,296 | 28,924/30,720 | 5.96046448e-07 | + +Use a centered unit stamp at 32² with roughness zero. For the 18 transparent controls set tint (.75,.375,1,.625). Use (blend mode, global opacity) of (0,1), (0,.5) and (1,.5), seeds 431, 468 and 505, for shapes 17 and 18 at variation 0, .25 and −.125. The next twelve controls use background (.5,.375,.75,.875), global opacity .5 and color blend modes 1 or 2 at those same three variations. For the last thirty controls use the same background, global opacity .5, all three modes, and run RGBA with that tint or grayscale with a white stamp. Use shape 2 at variation zero and shapes 17 and 18 at −.125 and .875. The seed is 943+9×shape+j, with j=0 for the first variation and j=1 for the second. + +For the transparent gradient at opacity .5 and variation −.125, pixel (16,16) has F32 bits bb880000, bd844000, 3d140000 and 3d140000. The unit square at opacity .5 over the stated background returns (.734375,.4921875,1.0625,.9140625) in mode 0 and (.578125,.375,.828125,.9140625) in modes 1 and 2. + +Across the earlier [260 profile renders](#directional-and-additive-stamp-profiles), exact pixels increased from 727,162 to 746,795 of 892,928. RGBA16 now matches 56,868/57,344, maximum one level. RGBA32F matches 28,361/57,344, maximum 2.42888927e−6. Earlier RGBA maxima were 12,544 levels and .191407166 respectively. Lower-coverage and transformed stamps retain coordinate differences. + +Fifteen previously exact inventory roots with reachable pattern filters match 2,544,128/2,544,128 pixels in 112 equal-resolution renders. For [Position Debug](#position-debug), the 16² zero-distance control has two 4096² internal images in the full graph. Its full render matches 256/256. If only MaterialCraft caps those images at 128², 236/256 output pixels match the full reference, maximum 128 U8 levels. To compare the preview, explicitly set the reference pattern filter and its source pixel processor to 128² and keep the graph at 16². All 256 output pixels then match. All seven observed node images agree on 34,048/34,048 pixels including both 128² intermediates. + +### Directional and additive stamp profiles + +Eight built-in shapes were measured in original single-stamp graphs. Across 260 renders, the complete renderer improved from 297,007 to 727,162 exact pixels out of 892,928. Color requires all four stored channels to match. Integer maxima are channel levels. + +| Shape | Renders | Previous exact | Current exact / compared | Maximum U8 / U16 | Maximum F16 / F32 | +|---|---:|---:|---:|---:|---:| +| 7 | 22 | 64,360 | 65,705/77,824 | 0 / 1 | 3.05175781e-05 / 4.76837158e-07 | +| 12 | 36 | 33,547 | 98,446/122,880 | 0 / 1 | 0.00048828125 / 1.4603138e-06 | +| 13 | 36 | 4,828 | 91,739/122,880 | 0 / 1 | 1.90734863e-06 / 8.94069672e-07 | +| 14 | 36 | 49,550 | 102,396/122,880 | 1 / 1 | 0.000122070312 / 1.08778477e-06 | +| 15 | 36 | 68,714 | 117,354/122,880 | 1 / 1 | 0.00048828125 / 4.24683094e-06 | +| 16 | 22 | 64,624 | 65,947/77,824 | 0 / 1 | 7.62939453e-06 / 1.78813934e-07 | +| 17 | 36 | 5,559 | 90,439/122,880 | 1 / 12544 | 0.00048828125 / 0.191406265 | +| 18 | 36 | 5,825 | 95,136/122,880 | 0 / 12544 | 0.00048828125 / 0.191407166 | + +Start from a single centered unit stamp with no background, unit opacity, roughness zero and blend mode 1. Declare the graph output and stamp consistently grayscale or RGBA. For variation 0, .25, .5 and 1 (index j), compare grayscale 32² F32, then 64² U8, U16, F16 and F32. Use seed 177+size+j. At .25 also compare 64² RGBA16 and RGBA32F with tint (.75,.375,1,.625). For shapes 12–15, 17 and 18, add four controls at 32² F32 and 64² U16/F32, seed 491+73j+size. Use a unit stamp at variation −.25, a (1.375,.6875) stamp at .0625 turns with offset (.109375,−.1875) and variation .3125, a (.75,1.125) stamp at .25 turns with offset (−.0625,.125) and variation .71875, then a unit stamp at offset (.0078125,.0078125) and variation 1.25. Repeat the first additional control with the same 64² color tint. + +Shapes 12 and 13 multiply a signed quartic bell by a horizontal mask. For 12 the mask is 1−3u²+2u³ with u=clamp(x/(1−max(variation,0)),0,1). At variation 1 the positive half is cut off. For 13 the mask is (1−|x|)². Shape 14 multiplies the same smooth mask, using (x+1)/2 horizontally, by the normalized ring 6.75t(1−t)², where t=min(x²+y²,1). Shape 15 uses max(0,1−20(y²+max(0,|x|−.77×max(variation,0))²)). Shapes 7 and 16 use the measured pixel square root for their conical falloff. + +In the scalar profile controls, shape 17 adds variation to (x+1)/2. Shape 18 adds it to the hemisphere height inside the disk and returns zero outside. Their floating outputs exceed one in the positive-variation controls. At the 64² unit-stamp coordinates from the [radial controls](#radial-stamp-profiles-and-pattern-generators), both scalar profiles predict all 4,096 samples at each of four variations. Absolute stamp placement, signed blending and the order of variation and color tint affect the full-render results. For shape 17 at (0,0), variation .25, the tinted reference red/green channels are .253662109375/.2518310546875 and the current channels are .120849609375/.0604248046875. + +| Inventory root | Renders | Exact / compared | Maximum U8 / U16 | Maximum F16 / F32 | +|---|---:|---:|---:|---:| +| creased.sbs/creased | 9 | 41,224/132,096 | 1 / 632 | 0.00048828125 / 0.000534534454 | +| crystal_2.sbs/crystal_2 | 9 | 102,021/132,096 | 13 / 4663 | 0.0494384766 / 0.0494220853 | +| fluid.sbs/fluid | 9 | 295/132,096 | 52 / 33520 | 0.20111084 / 0.201334268 | +| make_it_tile_patch.sbs/make_it_tile_patch | 9 | 12,322/132,096 | 196 / 47176 | 0.719848633 / 0.719859615 | +| make_it_tile_patch_grayscale.sbs/make_it_tile_patch_grayscale | 9 | 19,086/132,096 | 144 / 26181 | 0.399658203 / 0.459052384 | +| mesh_1.sbs/mesh_1 | 9 | 38,454/132,096 | 0 / 544 | 0 / 1.52587891e-05 | +| mesh_2.sbs/mesh_2 | 9 | 34,148/132,096 | 0 / 1102 | 0 / 1.52606517e-05 | +| messy_fibers_3.sbs/messy_fibers_3 | 9 | 126,928/132,096 | 1 / 3 | 0.0009765625 / 5.23328781e-05 | +| noise_creased.sbs/creased | 9 | 37,716/132,096 | 1 / 775 | 0.00048828125 / 0.000442534685 | +| noise_crystal_2.sbs/crystal_2 | 9 | 41,321/132,096 | 1 / 620 | 0.005859375 / 0.00588941574 | +| noise_directional_scratches.sbs/directional_scratches | 9 | 111,002/132,096 | 1 / 1 | 0.00048828125 / 5.30481339e-06 | +| noise_directional_scratches_v2.sbs/directional_scratches | 9 | 129,384/132,096 | 1 / 1 | 0.000122070312 / 6.22868538e-06 | +| noise_dirt_3.sbs/dirt_3 | 9 | 106,101/132,096 | 1 / 3 | 0.00048828125 / 3.20076942e-05 | + +These nine-render comparisons include the original archived defaults, seed and changed setting, the 64² four-format sweep and the independent 32² case from the [inventory measurements](#four-format-inventory-comparison). In the 32² comparison Mesh 1 improved from 0 to 1,020 exact, Mesh 2 from 48 to 992, Messy Fibers 3 from 1 to 48 and Noise Creased from 0 to 136, each out of 1,024. All thirteen roots retain measured differences. + +### Radial stamp profiles and pattern generators + +A single stamp in an original grayscale pattern graph isolates the local profile. For each shape, use a centered stamp of size (1,1), then a quarter-turn, then size (1.375,.6875) at .0625 turns with offset (.109375,−.1875). Render at 16² F32/seed 433, 32² F32/127, 64² in U8, U16, F16 and F32/733, and 128² F32/983. The counts compare stored pixels for all 21 renders per shape. + +| Shape identifier | Previous exact | Current exact / compared | Maximum U8 / U16 levels | Maximum F16 / F32 error | +|---|---:|---:|---:|---:| +| 4 | 66,880 | 66,884/102,144 | 1 / 1 | 0.00048828125 / 1.66893005e-06 | +| 5 | 25,043 | 61,752/102,144 | 0 / 1 | 0.00048828125 / 1.04308128e-06 | +| 6 | 52,799 | 61,127/102,144 | 0 / 1 | 0.000244140625 / 1.37090683e-06 | + +Shape 4 uses max(0,1−t), where t is the squared radius computed with a rounded x² and a fused y×y addition. Shape 5 uses (1−t)⁴, evaluated as the expanded polynomial in Horner order inside the unit circle. Shape 6 uses the pixel base-two exponential of −t×float32(11.1×log₂(e)), subtracts .0000151, then clamps at zero. The old shape 5 reached errors of 64 U8 levels, 16,384 U16 levels and .250000358 in F32. It now matches all 12,288 U8 pixels. + +A coordinate check isolates the remaining placement error. For a unit stamp, estimate each axis as float32((i+.5)×2×(1−2⁻²⁴)/N−1), with one final rounding. At 64² the quartic and Gaussian profiles each match 4,094/4,096 F32 samples with those coordinates. At 128² each matches 16,383/16,384. The regression checks include the 64² texels (0,32), (20,16), and (32,32). The stored output comparisons above include the complete renderer and translated and rotated stamps. + +| Root | Renders | Exact / compared | Maximum U16 levels | Maximum F32 error | +|---|---:|---:|---:|---:| +| Alveolus | 26 | 300,544/302,336 | 1000 | 0 | +| Gaussian 1 | 18 | 168,522/171,264 | 2 | 1.52587891e-05 | +| Gaussian 2 | 18 | 169,796/171,264 | 1 | 1.52587891e-05 | +| Gaussian spots 1 | 9 | 1,573/132,096 | 65535 | 1.16203201 | +| Noise Gaussian spots 1 | 9 | 493/132,096 | 65518 | 0.905901405 | +| Noise Gaussian spots 1 v2 | 9 | 2,984/132,096 | 65153 | 1.05418956 | +| Pattern Alveolus | 18 | 170,440/171,264 | 2 | 0 | +| Pattern Gaussian 1 | 18 | 168,522/171,264 | 2 | 1.52587891e-05 | +| Pattern Gaussian 2 | 18 | 169,796/171,264 | 1 | 1.52587891e-05 | + +Each generator includes defaults at 128² and 256²/seed 0, 128²/seed 42, changed settings at 128²/0 and 64²/42 in four output formats, and 32² F32/113. The three spots generators use disorder .3, scale 2 and disorder .37, and the same scale/disorder with speed .6, anisotropy .3, angle .125 and tile offset (.17,.29), respectively. Their spatial patterns still differ across formats. All nine roots generate their own inputs. + +For the two Alveolus and four Gaussian generators, add nine controls. Use defaults at 16² F32/23, 64² in four formats/107, 128² F32/347, 32² F32/457 and /521, and 64² F32/587. Alveolus uses tiling 2, filled gradients and interstice width .125, with tiling 3, empty gradients and width .25 at seed 521. Gaussian uses tiling 2, raised to 3 at 128². Disable non-square expansion at seed 457 on the three pattern-package variants. The 26 Alveolus renders include eight fresh repeats of the original four renders and the four-format controls. Its F32, F16 and U8 pixels now all match. The remaining 1,792 pixels are U16. The [earlier placement comparison](#alveolus-quadrant-placement-and-falloff) gives the nonzero quadrant offsets and intermediate output. + +### 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. + +### Small graph parents and raytrace positions + +| Comparison | Renders | Exact stored pixels / compared | Maximum error | +|---|---:|---:|---:| +| First PBR renderer, raytrace position | 26 | 142,340/142,340 | 0 | +| Second PBR renderer, raytrace position | 26 | 142,340/142,340 | 0 | +| Pixel centers and dimensions, runtime parent sizes | 44 | 9,552/9,552 | 0 | +| Saved parent sizes, including a 1×1 canvas in four formats | 12 | 693/693 | 0 | + +The two raytrace-position roots each matched 142,080/142,080 RGBA pixels across their 18 renders at sizes 16² through 256². An earlier 8² request produced 16² in MaterialCraft. The parent-size command, package reader, writer and cook now preserve each axis down to a single texel. A width or height in pixels rounds up to the next power of two. An explicit log2 size sets the exponent directly. + +For each raytrace position, wire the original offset grayscale field to Height and the levels range field to both Opacity and Blue Noise. Run native defaults at 128² and 256² with seed zero and at 128² with seed 42. For the changed 128² case set shape 1, shape scale .7, position (.1,−.2,.3), plane size (.7,1.3), displacement .2, UV tiling 2, sphere UV scale (2,3), plane and cylinder UV scales (2,1), cylinder length 1.5, radius .7, UV offset (.125,.25), rotation .125, direction .2 and rotation around that direction .3. Repeat the changed case at 64²/seed 42 in four storage formats and include the independent 32²/seed 113 F32 case. The [input-field definitions and independent cases](#four-format-inventory-comparison) give the pixel formulas. + +For the modular cases use original grayscale inputs H=((37x+41y+7xy+53j) mod 509)/508, where j is 0 for Blue Noise, 1 for Height and 2 for Opacity. Store linear RGB (H,H,H), alpha 1. Run defaults at 16²/43. At 32²/157 use shape 1, scale .8125, position (.0625,−.125,.1875), plane size (.75,1.25), displacement .125, UV tiling 1.25, cylinder length 1.5, radius .625 and UV offset (.1875,−.3125). Run all four storage formats and repeat F32 at seed 751. Use shape 2 at 64²/293 and again with 16×8 inputs at 16²/599. At 16²/463 apply 2.5H−.75, set shape 0 and UV offset (−.5,.0625). + +Eight more renders of each raytrace root use the 8² modular inputs. Request 8² F32 with defaults at seed 43 and 2² F32 with defaults at seed 499. Apply the changed shape-1 settings above at 4²/571 in all four formats, 8² F16/749 and 8² F32/827. Each root matched 260/260 pixels in these small renders. Across the complete matrix each matched 5,136 U8, 5,136 U16, 5,200 F16 and 126,868 F32 pixels. + +For the standalone dimension check emit (u,v,width,height) using the pixel center and the function's reported size. Request (1,8), (8,1), (2,2), (2,8), (4,4), (4,16), (8,8), (3,5), (6,9), (17,31) and (32,32) in U8, U16, F16 and F32. Use seeds 108 through 398 in steps of 29. The three non-power-of-two requests give 4×8, 8×16 and 32×32. A separately saved 1×1 graph gives (.5,.5,1,1) in each format at seed 79. For the eight saved F32 packages, use independent parent exponents (0,0), (0,3), (2,0), (1,1), (2,3), (3,3), (4,2), (5,4) and a constant scalar pixel function with output bits 3fc5672a. A transient 1×1 request on the original coordinate graph with the default parent setting produced a 2048² reference output. Those four dimension mismatches are excluded from the exact-pixel counts above. + +The core, formats, engine and UI release suites, engine panic hunt, formatting, layers, strict workspace Clippy and ten WebAssembly checks passed. The offscreen toolbar regression selected 1×8, and the saved frame displayed both dimensions in Properties. The full offscreen suite passed 45/47 tests. The material assignment frame and parameter preview cook timed out on isolated reruns of both the changed and cached pre-change UI executables. + +### Irradiance with a connected pass index + +| Comparison | Exact pixels or typed values / compared | Maximum error | +|---|---:|---:| +| First renderer, eighth pass, original 17 image observations | 120,232/120,320 | 1 U16 level, .015625 F16, .00390625 F32 | +| Nine image observations with the index wired | 4,537/4,608 | .001953125 F16 | +| Next index, 17 default and nine wired observations | 26/26 float values | 0 | + +After the [vector product rounding change](#vector-products-in-the-direct-light-pass), the default 128², seed-42 128² and default 256² renders match 16,370/16,384, 16,370/16,384 and 65,481/65,536. In the changed 64² F32 case the first half-float processor now matches 4,094/4,096. The other two processors match all their pixels. Both blends carry the two differences through to the output. The first differing red at (28,20) is still 7.48046875 against 7.4765625. All nine [changed-shape and input cases](#first-renderer-eighth-irradiance-pass) retain exact images and index values. + +For the wired cases, connect a scalar Value Processor returning the exposed start value to the root’s pass-index input. Connect its two outputs directly to the wrapper outputs. Use the seven original image fields from the preceding pass comparison, selecting its first matching size. Keep the wrapped graph’s exposed settings at their defaults. Run 16² with start −1 at seed 11 and 0 at seed 27, 32² with .5 at seed 43, 16² with 3 at seed 61 and 32² with 7.25 at seeds 211 and 401. Repeat the start-3 case with each of the four wrapper format requests. The measured inner output is RGBA16F on all nine renders. Both applications return 0, 1, 1.5, 4 and 8.25 for the five distinct inputs. The two first images match 256/256 each, the .5 case matches 991/1,024, the four start-3 cases match 255/256 each and both 7.25 cases match 1,007/1,024. + +Across all 26 observations the image totals are 4,352/4,352 U8, 4,351/4,352 U16, 107,108/107,264 F16 and 8,958/8,960 F32. The largest errors by format are zero, one level, .015625 and .00390625. The image output remains in progress. + +### First renderer eighth irradiance pass + +| Stored output | Observations | Exact / compared | Maximum error | +|---|---:|---:|---:| +| RGBA8 | 2 | 4,352/4,352 pixels | 0 | +| RGBA16 | 2 | 4,351/4,352 pixels | 1 level | +| RGBA16F | 5 | 102,563/102,656 pixels | .015625 | +| RGBA32F | 8 | 8,957/8,960 pixels | .00390625 | +| Next pass index, float | 17 | 17/17 values | 0 | + +The previously timed-out default 128², seed-42 128² and default 256² renders completed. They matched 16,368/16,384, 16,368/16,384 and 65,478/65,536 RGBA16F pixels. Their maximum errors were .015625, .015625 and .0078125. The other measurements use the four 64² storage formats at seed 42, the independent 32²/113 field and nine new fields. The two outputs are compared separately. All 17 index values were 1 with the pass-index input unwired. + +For the nine new fields use the seven relevant [procedural irradiance inputs](#material-bundles-and-the-eighth-irradiance-pass), connecting H to the blue-noise port. Use default controls at 16²/37. Set shape scale .8125, UV tiling 1.5 and displacement .125 for the other eight cases. Use shape 0 at 32²/173, repeat at seed 439, then use the alternate previous image at seed 173. Use shape 1 at 16²/359 with black environment and emissive. Use shape 2 at 16²/251 in all four storage formats. These inputs matched all 4,608 pixels and all nine pass-index values. + +In the changed 64² F32 render all seven input images matched at their stored precision. The first half-float pixel processor matched 4,093/4,096 pixels. Its red at (28,20) is 7.48046875 in MaterialCraft and 7.4765625 in the reference. The two other processors matched all 4,096 pixels each. The two blends carried the first processor’s three discrepancies to the output. The arithmetic behind those three pixels and the earlier default-case differences remains open. + +### Voronoi distortion and shared noise inputs + +| Root | Stock tables, exact / compared | Stock maximum F32 error | Shared table, exact / compared | Shared maximum U8 / U16 / F16 / F32 errors | +|---|---:|---:|---:|---:| +| 3D Voronoi | 146,688/149,760 | 0.304064572 | 5,632/5,632 | 0 / 0 / 0 / 0 | +| 3D fractal | 146,688/149,760 | 0.205578864 | 5,475/5,632 | 10 / 2,458 / .03759765625 / .0571730733 | +| 2D Voronoi | 146,688/149,760 | 0.368969858 | 5,632/5,632 | 0 / 0 / 0 / 0 | +| 2D fractal | 146,688/149,760 | 0.175076187 | 5,632/5,632 | 0 / 0 / 0 / 0 | + +With the two applications’ stock tables, each root matched all 146,688 pixels in the 27 renders with zero distortion intensity. The remaining three 32² F32 renders per root differ at every pixel. They enable distortion. The seven additional renders use the same original noise table in both applications. All pixels match in three roots. The 3D fractal still differs in 157 pixels with this shared input. + +The 30 stock cases include the eight original 16² to 256² renders, four changed 64² formats and the independent 32² field. Add ten cases with default settings at 16²/37, four formats at 32²/139, another F32 at 32²/457, distance mode 1 at 32²/257, mode 2 at 16²/347, mode 3 at 32²/521 and a distorted 32²/373 case. For the two 3D graphs use position (u,v,.25+.5H,1), where u and v are normalized pixel centers and H=((37x+41y+7xy) mod 509)/508. Use a 32×16 source for mode 1 and scale every channel by 2.5 then subtract .75 for mode 3. The two 2D graphs have no image inputs. For the changed cases set scale 3, size (.8125,1.125,.6875), offset (.1875,−.375,.0625), disorder .6875 in 3D or (.6875,.375,.8125) in 2D, distance scale 1.125, Minkowski exponent 1.625 and style 0. The fractal levels are 1 to 3, roughness .625, lacunarity 2 and opacity .8125. The distorted case uses distance mode 0, distortion intensity .3125, distortion scale multiplier 1.5, rounded curve .3125 and inversion. + +For the other seven stock controls, hold the first 32² field and seed 373 fixed. Start with the undistorted mode-0 settings. Change only intensity, only the scale multiplier, only rounded curve and only inversion to their distorted-case values, then enable both distortion controls together, and finally enable rounded curve and inversion together. Each graph matches all 5,120 pixels in the five controls with zero intensity. Both positive-intensity controls differ at 1,024/1,024 pixels. + +Replace the bitmap feeding the distortion calculation with the original 16-row [shuffled table](#basic-and-ridged-3d-perlin). Keep the distorted settings and render 16² F32/97 with intensity .1875 and multiplier .75, 32²/373 in all four formats, 32² F32/607, and 16² F32/461 with the signed input, intensity .5 and multiplier 2. In the 3D fractal’s 32² F32/373 case, reading the three noise terms gives 1,024, 994 and 1,024 exact values. The middle term’s maximum error is .4943066984. It differs only in columns 0 to 3 and rows 6 to 18. The five octave outputs match 996, 996, 995, 995 and 995 of 1,024 pixels. Their combined output matches 997/1,024, maximum .0374994278. The table substitution isolates the asset-dependent differences and leaves this 3D fractal discrepancy open. + +### Eighth raytraced specular passes + +| Renderer | Renders | Exact RGBA pixels / compared | Maximum U8 / U16 levels | Maximum F16 / F32 error | +|---|---:|---:|---:|---:| +| First | 26 | 142,061/142,340 | 0 / 0 | .0009765625 / .000030517578125 | +| Second | 26 | 142,337/142,340 | 0 / 0 | .000244140625 / 0 | + +The four original renders that exceeded the earlier time limit finished for both roots. Set the input images and changed parameters from the [four-format inventory](#four-format-inventory-comparison) for the corresponding specular pass. At 128² with defaults, 256² with defaults, 128² with seed 42, and 128² with changed settings, the first renderer matched 16,344/16,384, 65,355/65,536, 16,344/16,384 and 16,369/16,384 RGBA16F pixels. The second matched 16,383/16,384, 65,535/65,536, 16,383/16,384 and 16,384/16,384. Its three differences occur in these default-setting renders. + +Add the four changed 64² output formats and the independent 32² input. For the additional fields use the [normal, position and modular channels](#normal-maps-panoramas-and-primitive-shapes). Order the eight inputs by identifier. Use defaults at 16²/seed 43. At 32²/157 use shape 1, shape scale .8125, plane size (.75,1.25), rotation .0625, rotation direction −.125, displacement .125, UV tiling 1.25 and offset (.1875,−.3125). Test all four storage formats and repeat F32 at seed 751. At 64²/293 and with 16×8 inputs at 16²/599 use shape 2 and rotation .125. At 16²/463 use signed fields, shape 0, rotation .1875 and offset (−.5,.0625). The [small-parent comparison](#small-graph-parents-and-raytrace-positions) supplies the other eight renders per root, which matched a further 260/260 pixels per root. + +Read the three pixel processors and two blends at changed 64²/42 and shape-2 64²/293. Every image input matched in the first renderer’s changed case, including all 4,194,304 environment texels. The first processor matched 4,090/4,096 and 4,094/4,096 in the two cases, maximum .00018310546875. The final blend matched 4,095/4,096 in each. Its differing green channel at (1,50) in the changed case reads −.04119873046875 in MaterialCraft and −.041168212890625 in the reference. In the second renderer, all five intermediates matched every pixel in both 64² cases. The three default-case F16 differences in the second renderer still need localization. + +### Position-to-normal outputs in both renderers + +| Root | Renders | Exact RGBA pixels / compared | Maximum error | +|---|---:|---:|---:| +| First PBR renderer, position to normal | 30 | 515,328/515,328 | 0 | +| Second PBR renderer, position to normal | 30 | 515,328/515,328 | 0 | + +The first 18 cases per root include four archived renders, four output formats at 64², the independent 32² input and nine modular-field renders. They now match 171,264/171,264 pixels each. The earlier comparisons differed at 20 and five F16 pixels respectively. Twelve fresh renders per root repeat the four archived settings in the native precision, explicit F16 and explicit F32. They contribute 344,064 exact pixels per root. The fresh default F32 output includes the previously differing 256² coordinates. + +Use the original byte position ramp with the varying-alpha background on the first renderer and the curved normal map on the second. Run defaults at 128² and 256², seed zero, and at 128² with seed 42. For the changed 128² case use seed zero, shape 1, scale .7, plane size (.7,1.3), UV tiling 2, sphere UV scale (2,3), plane and cylinder UV scales (2,1), cylinder length 1.5, UV offset (.125,.25), rotation .125, rotation direction .2 and rotation around that direction .3. Use normal format 1 and enable normal recomputation. The [byte input formulas and independent input](#four-format-inventory-comparison) specify all channels. + +For the nine additional cases, use the [modular fields, sizes and seeds](#normal-maps-panoramas-and-primitive-shapes). The position pin uses the position field. The other pin uses the ordinary RGBA field or the normal field according to its identifier. Set shape to 1, 2 and 0 for A, B and C. Enable recomputation in A and B, use alternate normal format in B, UV tiling 1.25, sphere UV scale (.875,1.125), shape scale .8125 and plane size (.75,1.25). Use rotations .0625, .125 and .1875. Use UV offset (.1875,−.3125) for A and B, and (−.5,.0625) for C. + +### Sobel normals and nadir projection + +| Root | Renders | Exact RGBA pixels / compared | Maximum U8 / U16 / F16 / F32 error | +|---|---:|---:|---| +| First Sobel normal | 27 | 213,504/213,504 | 0 / 0 / 0 / 0 | +| Nadir extract | 18 | 174,336/174,336 | 0 / 0 / 0 / 0 | +| Nadir patch | 17 | 172,780/173,312 | 0 / 1 / 3.814697266e-06 / 0.0004730224609 | + +The first Sobel normal now matches all 171,264 pixels in the [earlier Sobel matrix](#segment-mapping-and-normal-graph-rechecks), including the 232 differing pixels in that report. Nadir extract now matches all 132,096 pixels in its original, four-format and independent cases. The earlier binary matched 132,064 with maximum F32 error .00468292832. Its 32 differences were present before the [pixel quotient correction](#pixel-quotients-and-volume-mask-interpolation). Use the original linear byte foreground at 128² and 256² with seed zero, then 128² at seed 42. The changed render uses rotation .125, scale 3 and gamma mode 1 at 128². Repeat that setting in the [four-format and independent cases](#four-format-inventory-comparison). + +For nine more renders per root, set D=((7 floor(x/3)+11 floor(y/5)) mod 19)/18. Use 16² F32 at seed 83, four output formats at 64²/179, 128² F32/277, 64×32 input on a 64² F32 canvas/379, 32×64 input on a 32² F32 canvas/479, and repeat 64² F32/577. For Sobel, use height −.375 on columns divisible by 13, 1.625 on the remaining rows divisible by 11, and D elsewhere. Use defaults at 16². At 64², 128², 64×32 and 32×64 use intensities .375, 2.625, 0 and −1.25 and normal formats 0, 1, 0 and 1 respectively. For nadir extract, use (u,v,D,A) at normalized texel centers with A=.875 on x> ((h >> 28)+4)) XOR h)×277803737 modulo 2³², then XOR it with h >> 22. Round each input to float32 before sampling. + +| Inputs | Size and seed | Exact pixels, sine and cosine together | +|---|---|---:| +| R=(q+.625)π/2²⁴, with q=64i, i, 1966080+i, 4194304+i−32768, or a sample without replacement from 0..4194303 using NumPy default_rng(117) | Five 256² fields, seed 113 | 655,360/655,360 | +| R=float32(i/65535)×float32(2π), or R with bits `0x3f490fdb-32768+i` | Two 256² fields, seed 42 | 262,144/262,144 | +| R=(26h/2³²−13)π, R=(2h/2³²−1)×1037287, or float bits with sign i mod 2, exponent floor(i/2) mod 255 and mantissa h mod 2²³ | Three 256² fields, seed 137 | 393,216/393,216 | +| Float32((i mod 32−16)π/2), offset its unsigned bit pattern by floor(i/32) mod 17−8 and replace nonfinite inputs by zero | 256², seed 137 | 131,072/131,072 | +| Cycle through ±0, ±.1, .625, π/4, −π/4, π/2, π, ±2π, 589.9901123047, −974634.875, ±2³⁴, ±∞ and NaN in that order | 16², seed 17 | 512/512 | +| Literal-only .625, −π/4 and 2π | Three 16² cases per operation, seed 17 | 1,536/1,536 | + +For Cartesian coordinates, read radius from red and angle from green. In the two 128² signed fields use radius 9i/16384−4.5 and angle (2h/2³²−1) multiplied by 13π or 1037287. A third field cycles radius through (0,−0,1,−1,.375,−1.25) and changes angle every seven pixels through (0,−0,π/4,π/2,π,2π,−2π,−974634.875). The 16² literal control uses (.875,.625). Read each component separately at seed 313. Before this correction, the direct large-angle cosine coordinate matched 1/16,384 pixels with maximum error .184980124. + +The atlas crop root matches **378,880/378,880 pixels in 37 cases**, maximum error zero. In the [wired atlas wrapper](#atlas-crop-with-wired-value-inputs), default and .125-turn rotation each match 114,688/114,688 RGBA32F pixels across seven parent-size, seed and precision settings. Grid view, zero count and count two each match 16,384/16,384. Adjusting the final processor itself to U8, U16, F16 and F32 gives eight further matching 64² outputs, 32,768/32,768 pixels. This includes the 128 differing edge pixels previously measured at .125 turns and 256². + +For twelve additional wrapper cases, keep the single shape table and white index field. At 128² bind linear RGBA bytes (3xy+19y+7x, 5x−31y, 17x+11y, 23x+13y), modulo 256. At 16² use v=(17x+53y) mod 256 and background (v,255−v,3xy mod 256,(7x+3y) mod 256). Opacity is zero where (floor(x/3)+floor(y/2)) mod 3 is zero and (37x+11y) mod 256 elsewhere. Test −.1875 turns without the grid and .3125 turns with the grid, grid opacity .375 and selection opacity .625. Each rotation matches 33,792/33,792 at 32² seed 73, 64² seed 137 with four parent precision requests and 128² seed 313. The instance stores RGBA32F in all twelve cases. + +With the [planar projection inputs](#grayscale-and-color-3d-planar-projection), .125 turns still matches 16,335/16,384 LUM16 pixels and 16,378/16,384 RGBA8 pixels. Maxima are 226 and one stored level. A separate graph computing sine or cosine in the node's output-size function gives `3f350503` for both operations at float32(π/4). This is a distinct arithmetic path from the per-pixel function. + +### Runtime angles and circular gradient + +The Circular Gradient root matches **163,840/163,840 pixels** in thirteen cases, maximum error zero. Its default outputs at 128² and 256² with seed zero and 128² with seed 42 match all 98,304 pixels. Set the two points to (.3,.6) and (.8,.7), angle .2 and non-square expansion off. At 128² seed zero the authored output matches 16,384/16,384. At 64² seed 42, U8, U16, F16 and F32 each match 4,096/4,096. For an independent rotation, use (.71875,.21875), (.0625,.8125), angle −.15625 and enable non-square expansion. The 128² F32 output at seed 71 and all four formats at 64² seed 137 match another 32,768/32,768 pixels. This root takes no image input. + +Nearest-sample R and G from an RGBA32F input and emit the angle of the vector (R,G) in radians. The six runtime fields below match **230,400/230,400 raw LUM32F samples**. Maximum finite error is zero. All 186 nonfinite outputs in the axes field agree bit for bit. The signed field previously matched 5/16,384 with maximum error .000235080719. + +| Field | Definition | Exact pixels / total | +|---|---|---:| +| Signed channels, 128² | R and G from the original field under [3D linear gradient](#3d-linear-gradient), seed zero | 16,384/16,384 | +| First octant, 128² | R=1, G=i/16,383, seed zero | 16,384/16,384 | +| One turn, 256² | R=float32(i/65,535) times float32(2π), G=1−R, seed 42 | 65,536/65,536 | +| Near π/4, 256² | R has bits `0x3f490fdb-32768+i`. G=float32(8h/2³²−4), h=(747796405i+2891336453) modulo 2³², seed 42 | 65,536/65,536 | +| Axes and exceptional values, 32² | At x and y independently cycle through +0, −0, 1, −1, +∞, −∞, quiet NaN, 2⁻¹⁴⁰, 2⁻¹²⁰ and 2¹²⁰, seed zero | 1,024/1,024 | +| Exponent range, 256² | R=2^(x−128), G=2^(y−128). Negate R when (x+y) mod 3 is zero and G when (x+2y) mod 5 is zero, seed 91 | 65,536/65,536 | + +Here i is the row-major pixel index. The first-octant fit is quartic in the smaller-to-larger magnitude ratio. It uses the measured runtime reciprocal and the same fused accumulation order as a four-channel dot product. In the other quadrants, reflection across the vertical and horizontal axes requires different additions of π/2 or π. Four separate literal-only controls at 32², seed zero, with vectors (1,1), (−1,−1), (.2,−.6) and (0,0) match another 4,096/4,096 LUM32F pixels. The runtime (1,1) angle has bits `0x3f490fe1` and the literal result has bits `0x3f490fdb`. + +### Pixel Processor random draws + +Emit four independent calls to `rand(1)` as RGBA32F. In the reference app the four values recover a unique initial 24-bit state at each of **27,968/27,968 pixels**. Advance the state with `s=(3626811*s+51137) mod 2^24` and return `floor(s/2)/2^23`. The four outputs then match at every pixel, maximum error zero. Use square canvases of sides 8, 16, 32, 64 and 128 at seed zero, also 32² at seeds 1, 2, 42 and 137, and 32×16 and 16×32 at seeds zero and 42. The first 32² pixel starts from 9,091,073 at seed zero and 3,342,178 at seed 42. + +Four additional original graphs replicate a single draw to RGBA, reuse two draws in alternating channels, double a reused draw, or apply ranges 1, 1, −2 and .375 to successive draws. At 16², 32² and 64² with seed zero and 32² with seed 42, all **25,600/25,600 reference pixels** agree with the corresponding channel expressions, maximum error zero. The MaterialCraft evaluator now matches the progression given the recovered initial state. Before the [per-pixel initialization fix](#per-pixel-random-initialization), the native and CPU four-draw images at 32² matched 0/1,024 entire pixels at seeds zero and 42, with maximum component errors .995849967 and .989675045. + +### Color conversion, checker and clone + +The ACEScg-to-linear-sRGB root matches **131,072/131,072 RGBA pixels across eight cases**, maximum component error zero. Bind the following original linear RGBA8 fields directly to its image input. At integer texel `(x,y)` on an `N×N` field, let `U=floor(255*x/(N-1))` and `V=floor(255*y/(N-1))`. Arithmetic in the four stored byte channels wraps modulo 256. + +- Foreground RGBA is `(17*x+31*y, 3*x+7*y, 11*x+5*y, 5*x+11*y)`. +- Background RGBA is `(29*x+13*y, 255-U, V, 13*x+3*y)`. +- The scalar mask is `7*x+9*y`. + +For the first four cases, use the foreground field at 128² and 256² with seed zero, repeat 128² with seed 42, then substitute the background at 128² with seed zero. The RGBA8 outputs match 16,384, 65,536, 16,384 and 16,384 pixels respectively. For the four remaining cases, keep the 128² background input, cook at 64² with seed 42, and select U8, U16, F16 and F32 on the final processor. Each format matches 4,096/4,096 pixels. The float32 output contains 4,096 distinct RGBA values and spans −0.53148961 to 1.51964462. + +Two other roots matched the original four eight-bit cases at 128²/256², including seed 42 and the changed settings below. Each matched 114,688/114,688 eight-bit pixels, maximum error zero. The first 64² seed-42 format sweep exposed the differences below. + +| Root and changed setting | U8 exact / max | U16 exact / max | F16 exact / max | F32 exact / max | +|---|---:|---:|---:|---:| +| `checker_1.sbs/checker_1`, tiling 3, 45-degree rotation enabled | 4,096 / 0 | 4,096 / 0 | 3,740 / 4.8828125e-4 | 4,096 / 0 | +| `clone.sbs/clone`, offset (.17, −.25), mask blur 0, original foreground and mask | 4,096 / 0 | 4,073 / 1 | 4,096 / 0 | 994 / 1.192093e-7 | + +Each format column compares all channels of 4,096 pixels. Clone uses 128² input fields in the 64² cases. + +### Clone mask and alpha rounding + +In the 64² Clone graph the transformed foreground, source image and blurred mask each matched all 4,096 source pixels. The final normal-copy Blend produced the entire U16 and F32 discrepancy. After correcting that operation, all eight cases listed above match **131,072/131,072 pixels**, maximum error zero. This includes 4,096/4,096 each in RGBA8, RGBA16, RGBA16F and RGBA32F at 64². + +For an independent 64² Blend control, form byte-valued foreground `(17*x+31*y, 7*x+3*y, 11*x+5*y, 5*x+11*y)`, background `(29*x+13*y, 128+7*x, 5+5*y, 13*x+3*y)` and mask `7*x+9*y`, each modulo 256. Use default normal-copy blending and seed zero. Test each as linear U8 and as float32 normalized by 255. The grayscale float fields may be encoded as equal RGB channels with an opaque alpha and connected to a grayscale input. + +For each input format, compare the varying fields, an opaque foreground, a white mask, white and black foreground RGB, white and black background RGB, zero background alpha, and constant foreground alpha 127 with mask 159. Repeat the first three controls with grayscale source and background. Each of these 24 float-output cases matches 4,096/4,096 pixels, maximum error zero. + +With float inputs, repeat the varying field, black background RGB and zero background alpha at global opacity .3 and .625. Repeat at .3 with alpha blending disabled. For signed fields replace each normalized input component `v` with `3*v-1` and run at opacity .3 and 1. Finally test opacity .07 with and without the mask, and opacity 1e-8 with the mask. All 24 controls match 4,096/4,096 pixels each, maximum error zero. + +The measured operation first takes the complement of mask transparency in float32, then multiplies by the global opacity. Color weights take the complement of foreground transparency. Output coverage uses the original foreground alpha. Fusing the background contribution into the weighted foreground reproduces the measured RGB rounding, including negative inputs and non-opaque coverage. + +### Height to normal in world units + +Both roots in `height_to_normal_world_units.sbs` match **131,072/131,072 RGBA pixels each** across eight cases. For a square grayscale height input, store `(17*x+31*y) mod 256` at each integer coordinate. Use default settings at 128² and 256², repeat 128² with seed 42, then set `surface_size=100`, `height_depth=8`, `normal_format=0` and `sampling=1` at 128² with seed zero. Each root matches 16,384, 65,536, 16,384 and 16,384 RGBA8 pixels respectively. Keep those changed settings and the 128² input, then cook at 64² with seed 42. U8, U16, F16 and F32 each match 4,096/4,096 pixels for both roots. Every maximum error is zero. Each 64² output contains 49 distinct normals. + +### Height distance, texture mapping, skew and weave + +Twelve roots match **163,840/163,840 pixels each**, maximum component error zero, across thirteen cases per root. The total is **1,966,080/1,966,080 pixels**. Both versions of the render helpers were cooked separately. Read the final output bridge at its native dimensions and storage precision. The F32 controls below contain 36 distinct outputs for the height-distance root, 42 for Weave 3 and at least 3,682 for each mapping, shift or skew root. + +| Package and graph | First changed case at 128² | Independent field and changed settings | +|---|---|---| +| `normal_to_height_hq.sbs/base_algorithm_height_distance` | Intensity .6, light angle .3, light offset .4, detail balance .6 | Height field, respectively .875, .125, .375 and .5 | +| `pbr_render.sbs` and `pbr_render2.sbs`, `PBR_render_mapping_color` | Substitute foreground for background texture | Color and UV fields, background color (.25,.5,.75,.375) | +| Both render packages, `PBR_render_mapping_grayscale` | Substitute full-range gray for limited-range gray | Height and UV fields, same background color | +| Both render packages, `chroma_shift` | Radius 2, angle .125 turns | Color field, radius 3.5, angle .3125 turns | +| `skew.sbs/skew` and `skew_grayscale` | Axis 1, amount .35, align 0 | Color or height field, axis 0, amount −.3125, align 2 | +| `uv_mapper.sbs/uv_mapper_color_sub` and `uv_mapper_grayscale_sub` | Filtering mode 0 | Color or height and UV fields, filtering mode 1. Color background (.25,.5,.75,.375) | +| `weave_3.sbs/weave_3` | Tiling 2, rotation enabled | Tiling 3, rotation disabled | + +For each root the first three cases use defaults at 128² and 256² with seed zero, then 128² with seed 42. The fourth uses the first changed setting in the table at 128² and seed zero. Each root matches 16,384, 65,536, 16,384 and 16,384 pixels respectively. Height distance and Weave 3 use LUM16 here. The other roots use eight-bit output. At 64² use seed 42, the same changed control and U8, U16, F16 and F32 output. Each matches 4,096/4,096. Inputs keep their 128² source dimensions, except the limited-range gray fixture, which has a 64² counterpart. + +Use the foreground and background byte fields specified under [color conversion, checker and clone](#color-conversion-checker-and-clone). The full-range gray is `(17*x+31*y) mod 256` and the limited-range gray is `32+((17*x+31*y) mod 160)`. At side N the original UV input is `(floor(255*x/(N−1)),floor(255*y/(N−1)),128,255)`. Height distance and grayscale skew take the full-range gray, chroma shift and color skew take the foreground. UV mapping takes the background or limited-range gray. Weave 3 has no image input. + +For the five independent cases, use F32 at 128² with seed 71 and all four formats at 64² with seed 137. Inputs match the canvas size. Generate byte channels modulo 256 at integer (x,y). Color is `(11*x+37*y+29,41*x−19*y,3*x+79*y+1,13*x+7*y)`, height is its red channel and UV is `(5*x+3*y,9*y−7*x,round(255*y/(N−1)),A)`, where A is zero on `(x+y) mod 7 = 0` and 255 elsewhere. Each root matches all 16,384 float pixels and 4,096 pixels in each 64² format. + +The same independent checks exposed remaining differences in five additional roots. All four 64² formats at seed 137 are exact. At 128² and seed 71 their F32 outputs differ as follows. + +| Root | Changed control | Exact pixels / total | Maximum component error | +|---|---|---:|---:| +| `pattern_stripes.sbs/stripes` | Stripes 9, width .28125, softness .125, shift 3, align 2, filtering disabled | 16,341/16,384 | 1 | +| `quad_transform.sbs/quad_transform` | Color field, tiling enabled, four corners (.1,.125), (.2,.9), (.9,.2), (.8,.85) in parameter order p00, p01, p10, p11 | 16,378/16,384 | .00387579203 | +| `quad_transform.sbs/quad_transform_grayscale` | Height field, same corners | 16,378/16,384 | .000564604998 | +| `quantize_color.sbs/modify_color_palette_sub` | Color field, 16-bit ID equal to 4,369 times `(7*x+13*y) mod 16` | 254/256 | 1.19209290e-7 | +| `shape_splatter.sbs/shape_splatter_blend_color` | Two active patterns, color input opacity .625, HSL adjustment (.125,−.25,.0625) | 16,381/16,384 | 8.94069672e-8 | + +For the palette control use selection mode 1, index 6, spread .125, contrast .25, distance color space 0, mode 1, opacity .375, override (.8,.125,.3) and HSL (.125,−.25,.0625). For the splatter control, bind Color to the background and second data input, UV to the color input and first data input. For pattern number j from 1 through 8, its RGBA bytes are `(13*x+11*y+23*j,5*x+31*j,17*y+13*j,19*x+7*y+29*j)` modulo 256. + +For `spline_tools.sbs/internal_tools/compute_bridge_distance`, wire a Float2 value processor returning (2,1) into parent size and an Integer value processor into spline amount. Enable non-square correction. Bind the original 16² coordinate circle described under [spline preprocessing with wired counts](#spline-preprocessing-with-wired-counts). With count 1, the LUM32F outputs at 16² seed zero, 32² seed 42 and 64² seed 137 match 256/256, 1,024/1,024 and 4,096/4,096, maximum zero. With count 2 the counts are 252/256, 992/1,024 and 4,032/4,096. The respective maxima are 5.96046448e-8, .228374884 and .0570636913. + +### Alveolus quadrant placement and falloff + +In an original blank 64² pattern graph, follow the lower-left quadrant one, two or three times and draw a square of size (.25, .25) at the leaf. With zero offsets its centers are (16, 48), (8, 56) and (4, 60) in pixel-edge coordinates. Applying (.25, .125) to either the branch offset or the pattern offset moves the center by (16, 8) texels at every depth, with tiling at the image bounds. The size still shrinks at each depth. A separate unit Gaussian stamp shows a circular cutoff and a falloff of approximately `max(0, exp(-11.1*r²) - exp(-11.1))` in local coordinates. At 64², unit opacity and F32, the maximum difference between that analytic profile and the observed red channel is 3.5e-7. + +The corrected offsets and Gaussian profile bring the default Alveolus pattern stage from **0/8,192** LUM16 pixels (maximum error 55,100) to **8,096/8,192** (maximum error 1). The following table compares the final output bridge. This generator uses no input image. + +| Case | Size | Seed | Output format | Exact pixels / total | Maximum error | +|---|---:|---:|---|---:|---:| +| Defaults | 128² | 0 and 42 | LUM16 | 16,192/16,384 each | 2 | +| Defaults | 256² | 0 | LUM16 | 64,896/65,536 | 2 | +| `Gradient_Filled_Cells=true`, `Interstice_Width=.1` | 128² | 0 | LUM16 | 16,264/16,384 | 1,000 | +| Same changed parameters | 64² | 42 | LUM8, LUM16, LUM16F, LUM32F | 4,096/4,096 each | 0 | + +### Anisotropic blur + +For the grayscale root bind `(17*x+31*y) mod 256`. For the color root use the same value in R, `U` in G, `255-V` in B and 255 in A. The definitions of `U` and `V` are under [color conversion, checker and clone](#color-conversion-checker-and-clone). At 128² the color input bridge matches all 16,384 pixels. The first directional pass already differs. + +| Case | Color exact / total | Gray exact / total | Maximum error, color / gray | +|---|---:|---:|---:| +| Defaults, 128², eight-bit | 11,526/16,384 | 11,526/16,384 | 1 / 1 | +| Angle .125 turns, anisotropy .8, 128², eight-bit | 3,228/16,384 | 3,310/16,384 | 16 / 16 | +| Quality 1, intensity 4, 256², eight-bit | 65,536/65,536 | 65,536/65,536 | 0 / 0 | +| Same 256² input and changed settings at 64², seed 42, U8, U16, F16, F32 | 4,096/4,096 each | 4,096/4,096 each | 0 / 0 | + +At the first directional pass the default color case matches 11,944/16,384 pixels with maximum error 1. With angle .125 it matches 2,997/16,384 with maximum error 21. A separate F32 impulse at (64,64) on a 128² field, intensity 10 and angle .125, has nonzero samples on both sides of the diagonal. + +### Pixel Processor canvas and mip maxima + +The `mip_max` helpers in `rt_irradiance.sbs` and `rt_shadows.sbs` each match **167,168/167,168 pixels in 17 cases**, maximum error zero. Each exposes one grayscale input and uses fixed internal parameters. The four first-pass cases account for 114,688 pixels, the four precision cases and independent 32² case for 17,408, and the eight cases below for 35,072. The earlier four-format table records the original size discrepancy. + +At 64², compare the input bridge, nine reduced-resolution processors, the final processor and its output bridge on the 64² levels field from the four-format table. Each root matches 13,656/13,656 pixels across all twelve stages. The reductions produce LUM8 at 32², 16², 8², 4², 2² and four times at 1². The last processor and output bridge produce LUM32F at 64². Previously the final processor inherited its first sampled texture's 32² dimensions. + +| Original grayscale input | Output and seed | Exact pixels per root | Maximum error | +|---|---|---:|---:| +| U8 at 16² and 128², (17x+53y+7xy) mod 251 | Same size, F32, seeds 41 and 137 respectively | 16,640/16,640 | 0 | +| U16 at 64², (711x+1337y+17xy) mod 65521 | 64² U8, U16, F16 and F32, seed 71 | 16,384/16,384 | 0 | +| 64×16 F32, (((17x−31y+3xy) mod 237)−63)/127 in RGB, alpha one | 32² F32, seed 211 | 1,024/1,024 | 0 | +| 16×32 U8, constant 93 | 32² U16, seed 313 | 1,024/1,024 | 0 | + +For the isolated size control, supply a 16×8 linear RGBA8 texture with (11x+31y+3xy) mod 256 in RGB and opaque alpha. Sample red at `$pos` with nearest filtering in a grayscale F32 processor. Use graph sides 32, 64 and 128 with seeds 0, 42 and 137 respectively. Missing output size, parent-relative (0,0) and input-relative (0,0) each match 1,024, 4,096 and 16,384 pixels at the parent sizes. Absolute size exponents (5,4) match all 512 pixels at each parent size. The 16×8 input is exact throughout. + +With the same input, a zero-intensity blur uses the input dimensions for missing or input-relative size and matches 128/128 pixels. Absolute 32×16 matches 512/512 at every parent size. Explicit parent-relative blur still differs when resizing to 32², 64² and 128². The exact counts are 631/1,024, 1,476/4,096 and 4,738/16,384, with maximum byte errors 17, 38 and 49 respectively. + +### Fixed graph and instance output sizes + +Both `pattern_tile_sampler.sbs/arrow` and `tile_sampler.sbs/arrow` specify an absolute 512×512 graph output. MaterialCraft now imports and saves that size separately from the default parent canvas. Each output of a graph instance also retains the dimensions and storage precision of its source. Downstream connections and cache hits use the selected output port. + +For a size control, draw a centered white square half the canvas width and height on black. Give its graph an absolute output size of (6,5) in base-two exponents. With parent sizes 64²/U8, 128²/U16, 256²/F16 and 128²/F32, the stored output is 64×32. All four cases match 2,048/2,048 pixels, maximum error zero. Use seed zero for the first two cases and 42 for the last two. + +A second control fixes only the final processor to 64×32 F32. Place the child in an original wrapper with a 128² or 64² parent. Exercise inherited instance size, parent-relative (0,0), and absolute (5,4). For each setting also request U8, U16, F16 and F32 on the instance. Each of these 18 cases produces a 64×32 LUM32F image and matches 2,048/2,048 pixels, maximum error zero. A two-output evaluator regression separately exercises a 64×32 F32 port, a 4×8 U8 port, their downstream consumers and a cached cook. + +Neither Arrow root has input pins or exposed parameters. Restoring the fixed size brought each to 261,338/262,144 LUM8 pixels at its default 512² size, including seed 42, with maximum error 131. With a 64² parent and seed 42 the stored dimensions remained 512². The following counts precede the transform filtering correction. + +| Stored format | Exact pixels / total | Maximum error | +|---|---:|---:| +| LUM8 | 261,338/262,144 | 131 | +| LUM16 | 261,338/262,144 | 33,667 | +| LUM16F | 260,826/262,144 | 0.513916015625 | +| LUM32F | 260,826/262,144 | 0.5137255192 | + +### Transform edges and floating-point filtering + +Both Arrow roots now match **1,835,008/1,835,008 pixels each**, maximum error zero. Repeat the 512²/U8 default twice at seed zero and once at seed 42. Then use a 64² parent and seed 42 with LUM8, LUM16, LUM16F and LUM32F on the final Blend. Every run returns a 512² image and matches 262,144/262,144 pixels. Checker 1 also matches **131,072/131,072 pixels**, maximum error zero, across the eight cases under [color conversion, checker and clone](#color-conversion-checker-and-clone). Its rotated 64² half-float result went from 3,740/4,096 to 4,096/4,096. + +The first two mismatching Arrow stages transform a uniform white image with tiling off. A smaller control uses an original white 128² RGBA8 input with a transparent matte and bilinear filtering. Translate by (.25,.375) texels. The last column, last row and bottom-right corner of its RGBA32F output contain 49,151/65,535, 40,959/65,535 and 30,720/65,535 respectively. Each outside sample contributes the matte according to its own weight. Two further controls use matrix (1.23654997,0,0,4) with UV offset (.118276998,0), or matrix (1.01874995,−.982617021,1.01874995,.982617021) with offset (0,.367500007). These three transforms match 16,384/16,384 pixels in each of four output formats, maximum error zero. + +To isolate matte precision, move a 128² image two UV units along both axes with tiling off. Set the matte to (.5,.1,−.312345,1.144444). Use U8, U16, F16 and F32 input storage and repeat with each of the four output formats. All 16 cases match 16,384/16,384 pixels each. In the F32 outputs the red channel retains the source-format levels 127/255, 32,767/65,535, .5 and .5 respectively. + +For floating-point filtering, use the original signed 128² RGBA field specified under [3D linear gradient](#3d-linear-gradient). Store it first as F16 and then as F32. Use a tiled identity transform, F32 output, seed zero and offsets in texels of (.37,.18), (−.129,.678), (.601,0), (0,0), (.0039,.496) and (.501953125,.376953125). Each of these 12 cases matches 16,384/16,384 pixels, maximum error zero. The measured filter quantizes the four weights to a sum of 256. Per component it aligns contributing texels to their largest exponent with four extra significand bits, truncates, accumulates the weighted sum, and rounds to the source precision with halfway cases away from zero. + +The same sampler was measured independently inside a Pixel Processor. Bind a 128² RGBA field to input zero, add a texel offset divided by 128 to the pixel-center UV, then read the input with bilinear filtering into an RGBA32F output. Run offsets (.25,.375), (.37,.18) and (−.129,.678) for each of U16, F16 and F32 input storage. All nine runs match 16,384/16,384 pixels each, **147,456/147,456** overall, maximum component error zero. The F16 and F32 cases use the same signed input field and produce different filtered values. + +### Linear gradient 2 and multiangle albedo + +Each root matches **131,072/131,072 pixels in eight cases**, maximum component error zero. Use defaults at 128² and 256² with seed zero, repeat 128² with seed 42, then run the changed settings at 128² with seed zero. Those four runs match 16,384, 65,536, 16,384 and 16,384 pixels respectively. Keep the changed settings and render at 64² with seed 42. Each of U8, U16, F16 and F32 matches 4,096/4,096 pixels for both roots. + +- `gradient_linear_2` generates its own input. The first four outputs are LUM16. For the changed cases set `Tiling=3` and `rotation=1`. +- `multiangle_to_albedo` uses the foreground field on input 1 and the background field on inputs 2 through 8, as specified under [color conversion, checker and clone](#color-conversion-checker-and-clone). The first four outputs are RGBA8. For the changed cases set `samples_amount=4` and keep the 128² inputs for the 64² format sweep. + +Six additional albedo cases use a different original image on each of the eight pins. For input number `j=1..8` the RGBA bytes are `((17+j)*x+(11+2*j)*y+29*j, (7*j+1)*x+5*y+13*j, 3*x+(13*j+1)*y+41*j, (5+j)*x+(11-j)*y+23*j)` modulo 256. Match the input and output dimensions. The default at 64² with seed zero matches 4,096/4,096 RGBA8 pixels. Four samples at 128² and seed 137 match 16,384/16,384 RGBA8 pixels. At 32² and seed 42 the same setting matches 1,024/1,024 pixels in each of U8, U16, F16 and F32. Maximum error is zero throughout. + +### Atlas crop with wired value inputs + +For `atlas_spliter.sbs/crop_and_transform_sub`, connect constant value processors to `shape_count` and `shape_data_table_size`. Use count 1, table size (1,1), and a single RGBA32F table texel (0,0,1,1). Bind a transparent 16² background and solid white 16² shape-index and opacity images. For the 128² color image, use linear RGBA8 texels `((17*x+31*y)%256, floor(255*x/127), 255-floor(255*y/127), (7*x+13*y)%256)`. Give the instance a parent-relative (0,0) size. The reference app returns RGBA32F at its authored precision. + +| Rotation | 128² seed 0 or 42, exact / max | 256² seed 0, exact / max | 64² seed 42, exact / max | +|---|---:|---:|---:| +| Default | 16,384/16,384 · 0 | 49,152/65,536 · 0.250003815 | 4,096/4,096 · 0 | +| .125 turns | 16,320/16,384 · 1 | 49,091/65,536 · 1 | 4,064/4,096 · 0.996078431 | + +The 16,384 differences at default rotation and 256² occupy exactly the lower-right 128² quadrant. At 128², three further controls each match 16,384/16,384, maximum error zero. Enable grid view, set count and table dimensions to zero, or set count to 2 and table dimensions to (1,2), respectively. All three use the same single table texel. + +Set the final Pixel Processor's storage explicitly, keep the 128² input, and cook at 64² with seed 42. At default rotation, RGBA8, RGBA16, RGBA16F and RGBA32F each match 4,096/4,096 pixels, maximum error zero. At .125 turns, each matches 4,064/4,096. The respective maximum errors are 254, 65,278, 0.995605469 and 0.996078431. + +### Spline preprocessing with wired counts + +For `spline_tools.sbs/internal_tools/scatter_splines_on_splines_preprocess`, wire integer value processors to `input_spline_amount` and `custom_spline_amount`. Use input counts 1 and 2, custom count 1, `side=3`, `amount_mode=0` and `spline_amount_per_spline=1`. The 16² grayscale mask stores `(11*x+7*y)%256`. An original 16² circle coordinate buffer and its tangent buffer supply the other two images. + +At 16² with seed zero or 42 and at 32² with seed zero, the two input counts return the exact integers 1 and 2 in all six comparisons, maximum error zero. With count 1 the image has two distinct RGBA8 values. All three images match 32,768/32,768 pixels after the instance retains the 2048×16 source dimensions. Before the fix MaterialCraft returned a 16² or 32² image through the wrapper. + +To reproduce with a fresh pair of circle buffers, initialize two 16×16 RGBA32F images to zero. For `x=0..15`, let `a=2π(x+.5)/16`. In row zero, store `(.375+.1875*cos(a), .625+.1875*sin(a), 1, -1)` and `(-sin(a), cos(a), 0, 1)`. A separate run with these fields also matches all six typed integers and all 98,304 RGBA8 pixels through the wrapper, maximum error zero. + +With the 16² parent, seed zero and count 1, set the output FX-Map storage explicitly to RGBA8, RGBA16, RGBA16F and RGBA32F. Each matches 32,768/32,768 pixels, maximum error zero. The reference app twice failed to return an image for the disconnected zero-count default within six minutes. That case has no pixel count or error measurement. + +### Facet masks and stripe boundaries + +**Mask to facets** matches **52,736/52,736 pixels in 17 cases**, maximum component error zero. Four original 16² RGBA32F cases use the striped mask or mask gradient described below, seeds zero and 42, and thresholds .5 and .3. Four more at 64² seed 42 use the original gradient at threshold .3 and cover RGBA8, RGBA16, RGBA16F and RGBA32F. A 32² seed 113 control uses the independent gray1 field at .3. + +For the eight further cases, test all-black and all-white 16² masks at seeds 37 and 57 with threshold .5. For the spatial mask use (9x+7y+3xy) mod 256 inside the union of a circle with center (.35N,.4N) and radius .29N and the region x>.65N, y>.5N. Set all other pixels to zero. Use 32² F32 seed 71 at threshold .5, then 64² in four formats and 128² F32 at threshold .625, with seeds 137 and 193 respectively. Those eight cases match 34,304/34,304 pixels, including 689 distinct RGBA32F values at 64². + +For **both Stripes roots**, use 13 stripes, width .71875, softness .3125, shift 4, align 0 and filtering enabled. Each matches 17,408/17,408 pixels across 32² F32 seed 37 and 64² seed 137 in four formats. With nine stripes, width .28125, softness .125, shift 3, align 2 and filtering disabled at 128² seed 71, the pattern-package root matches 16,341/16,384 pixels in each format. The standalone-package root matches 16,329/16,384 in each format. The maxima for both are 255 U8 levels, 65,535 U16 levels or 1 in F16/F32. + +### Four-format inventory comparison + +This sweep covers **375 roots and 406 output producers** that were unresolved when the sweep began. Each row reports a 64² parent with seed 42. Set the producer of the named output to U8, U16, F16 and F32 in turn. Retain the graph’s declared size rules and the dimensions of each bound input. A separate 32² F32 run at seed 113 covers **383 producers in 352 roots**. The other roots have the dedicated controls linked from the inventory. The first-pass records below supply defaults, alternate resolutions and seed comparisons. The per-root sections above retain the more demanding controls, including measured failures when the sweep happens to match. + +Each numeric cell gives **exact pixels / total pixels · maximum absolute component error**. A pixel counts only when every channel matches. For a typed output the unit is one complete value. Unsigned errors use stored levels, and F16/F32 comparisons use the raw bit patterns and finite component differences. ¹ indicates a local storage grid or format discrepancy. ² indicates nonfinite components. A dash for the maximum means no finite pair. A size pair gives local dimensions followed by reference dimensions. Cook errors and incompatible dimensions have no comparable samples. The four requested formats can yield the same typed output or a fixed image size. + +The 64² checkpoint column identifies the code used for that row. In build order, `checked` includes pixel product fusion, `sampler` includes the first float texture filter, `filtered` includes transform matte behavior, `bridge` includes source-precision input resizing, `angle` adds the runtime arc tangent, `gray` adds grayscale reads of color, `scope` adds value coordinates, `value` also averages color in value reads, and `loop` adds typed zero for skipped loops. The 32² comparison uses the `scope` checkpoint. The reference app is version 16.0.7 with the Direct3D 11 backend. Later work has its own dated numerical records. + +#### Procedural inputs + +The 64² input name includes the source side when applicable. All pixel indices start at zero. Unless another format is specified, color fields are linear RGBA bytes. Reduce byte expressions modulo 256. For source side N use U=floor(255x/(N−1)), V=floor(255y/(N−1)) and T=17x+31y. + +| Input name | Generation | +|---|---| +| `position`, `normal`, `texture`, `texture-color` | (U,V,128,255), (128,128,255,255), gray T and (T,U,255−V,255), respectively | +| `offset-gray`, `offset-alpha`, `levels-range` | Gray T, (T,U,255−V,7x+13y), and 32+(T mod 160) | +| `blend-fg-alpha`, `blend-bg-alpha`, `blend-mask` | (T,3x+7y,11x+5y,5x+11y), (29x+13y,255−U,V,13x+3y), and gray 7x+9y | +| `material-input-j` | (13jx+7y+11j,3x+19jy+53j,floor(x/5) XOR (j×(23+9×floor(y/3))),7x+11y+17j) | +| `material-id`, `curved-normal` | Eight equal vertical strips of opaque red, green, blue, white, cyan, magenta, yellow and black. For the normal use X=.55sin(2πx/N), Y=.5cos(2πy/N), Z=√(1−X²−Y²), and round 127.5×(component+1) | +| `crop-rectangle-64`, `flood-bbox-128` | Opaque white on x=12…51, y=20…43, transparent elsewhere. For the float bounding boxes set X=floor(x/32)/4 and Y=floor(y/32)/4, then store (X,Y,X+.25,Y+.25) | +| `hdr-field-128` | With u=(x+.5)/128 and v=(y+.5)/128, store RGBA32F (4u,3v−1,4+4sin(2πu)cos(2πv),((7x+11y) mod 256)/255) | +| `original-mask-16`, `original-mask-gradient-16`, `original-rgba-16` | Gray 210 for even floor(x/3)+floor(y/4), 40 otherwise. The gradient is 11x+7y. RGBA uses (17x,17y,11x+7y,A), with A=64 when x+y is divisible by three and 255 otherwise | +| `original-hald-identity-512`, `original-palette-128`, `original-id16-128` | Use the 64-level identity lookup above. The palette is sixteen vertical HSV stripes with hue j/16, saturation .7, value .9 and alpha 1, rounded to bytes. The ID field is 17×(floor(x/32)+4×floor(y/32)) | +| Irradiance and volume inputs | At 16², the position and environment use floor(255×(index+.5)/16) for XY, with a constant blue byte of 128 or 192. The normal is (128,128,255,255). Sample tables are (64,64,255,255) or (64,192,255,255). The gray half-distance is byte 128. Float distance fields are 128 and −.1, and float thin density is .001 in RGB with alpha one | +| Paths and splines | The closed seven-point path uses a circle of radius .4 about (.5,.5) in row 1 of a 16² buffer. The tagged endpoints repeat the first position. The offset spline places 16 records in row zero around (.4,.6). Sparse facet and spline controls retain the recorded original buffers described below | + +For the independent 32² inputs, number the bound pins in alphabetical order starting at t=1. The table lists the actual field on each pin. For `grayt` use G=((11+2t)x+(37+4t)y+3xy+29t) mod 256. For `colort` use (G,41x−19y+11t,3x+79y+t,13x+7y+31t). A position field uses (U,V,floor((3U+V)/4),255). A normal uses X=.9(x/31−.5), Y=.7(y/31−.5), Z=√(1−X²−Y²) with the same byte encoding. The rectangle is white on x=3…23 and y=8…26, black elsewhere. When a structured original remains bound, its basename appears in the last column. The table records numerical evidence for those original bytes. Exact file fingerprints for the archived sparse and noise inputs follow the table. + +| Root and output | 64² checkpoint | Bound 64² inputs and settings | 64² U8 | 64² U16 | 64² F16 | 64² F32 | 32² F32 and inputs | +|---|---|---|---:|---:|---:|---:|---| +| `3d_perlin_noise.sbs/3D_perlin_noise` · output (LUM) | checked | position=position-128
scale=6 | 17/4,096 · 175 | 0/4,096 · 45078 | 0/4,096 · 0.687866211 | 0/4,096 · 0.687842071 | 0/1,024 · 0.659080476
position=position | +| `3d_perlin_noise.sbs/3D_ridged_noise_fractal` · output (LUM) | checked | position=position-128
roughness=0.7 | 57/4,096 · 92 | 0/4,096 · 23627 | 3/4,096 · 0.360351562 | 0/4,096 · 0.360533118 | 0/1,024 · 0.376043171
position=position | +| `3d_planar_projection.sbs/3d_planar_projection` · output (LUM) | value | position=position-256, texture=texture-256, wsnormal=normal-256
defaults | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
position=position, texture=gray2, wsnormal=normal | +| `3d_planar_projection.sbs/3d_planar_projection_color` · output (RGBA) | value | position=position-256, texture=texture-color-256, wsnormal=normal-256
defaults | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
position=position, texture=color2, wsnormal=normal | +| `3d_texture_render.sbs/3d_texture_surface_render_irradiance` · output (RGBA) | value | see input group 1
i=128 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
same pin order | +| `3d_texture_render.sbs/3d_texture_surface_render_position` · output (RGBA) | checked | input=sdf-half-16
camera_uv_position=(0.35,0.6), camera_distance=3 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 3,906/4,096 · 0.00048828125 | 0/4,096 · 1.26957893e-05 | 0/1,024 · 1.26957893e-05
input=sdf-half-16 | +| `3d_texture_render.sbs/3d_texture_volume_render_ibl_pass` · output (RGBA) | checked | see input group 2
absorption=2 | 912/4,096 · 4 | 1/4,096 · 885 | 110/4,096 · 0.013671875 | 0/4,096 · 0.0135003328 | 0/1,024 · 0.0134982467
same pin order | +| `3d_texture_render.sbs/3d_texture_volume_render_light_pass` · output (RGBA) | checked | density=volume-density-thin, noise=irradiance-blue_noise, position=irradiance-position, sdf=sdf-negative-16
albedo=(0.3,0.6,0.9) | 4,096/4,096 · 0 | 4,045/4,096 · 2 | 4,069/4,096 · 6.10351562e-05 | 362/4,096 · 3.02419066e-05 | 141/1,024 · 7.41332769e-06
density=volume-density-thin, noise=irradiance-blue_noise, position=irradiance-position, sdf=sdf-negative-16 | +| `3d_viewer.sbs/ibl_specular_contrib_anisotropic/panoramic_lod` · Diffuse (RGBA) | value | input=offset-alpha-128
defaults | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=color1 | +| `3d_volume_mask.sbs/3d_volume_mask` · output (LUM) | checked | position=position-128
shape=1, rotation=(0.1,0.2,0.3), size=(0.8,0.6,1), feather_width=0.1 | 4,096/4,096 · 0 | 4,088/4,096 · 1 | 4,083/4,096 · 0.015625 | 302/4,096 · 0.000900268555 | 123/1,024 · 1.14440918e-05
position=position | +| `3d_worley_noise.sbs/3D_worley_noise` · output (LUM) | checked | position=position-128
style=1, border_width=0.2, roundness=0.1 | 49/4,096 · 129 | 0/4,096 · 33338 | 5/4,096 · 0.508789062 | 0/4,096 · 0.508701503 | 0/1,024 · 0.523628771
position=position | +| `alveolus.sbs/alveolus` · Alveolus (LUM) | checked | none
Gradient_Filled_Cells=true, Interstice_Width=0.1 | 3,352/4,096 · 255 | 3,352/4,096 · 65535 | 3,352/4,096 · 1 | 3,352/4,096 · 1 | 1,008/1,024 · 0.0152590219 | +| `anisotropic_blur.sbs/anisotropic_blur` · Anisotropic_Blur (RGBA) | value | Source=texture-color-256
Quality=1, Intensity=4 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
Source=color1 | +| `anisotropic_blur.sbs/anisotropic_blur_grayscale` · Anisotropic_Blur (LUM) | value | Source=offset-gray-256
Quality=1, Intensity=4 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
Source=gray1 | +| `bevel_smooth.sbs/blur_gaussian_grayscale` · Blur_HQ (LUM) | value | Source=offset-gray-128
intensity=5 | 2,652/4,096 · 2 | 503/4,096 · 372 | 873/4,096 · 0.005859375 | 439/4,096 · 0.00568625331 | 1,024/1,024 · 0
Source=gray1 | +| `bevel_smooth.sbs/debug/bevel_smooth_debug_position` · output (RGBA) | value | input=position-128
mode=true, pixel_position=(0.25,0.75) | 3,109/4,096 · 204 | 3,109/4,096 · 52428 | 3,109/4,096 · 1.05004883 | 3,109/4,096 · 1.05 | 1,024/1,024 · 0
input=position | +| `bevel_smooth.sbs/jump_flood_segment_iteration` · output (RGBA) | value | input=texture-color-128
distance_mode=1, scale=(1,0.5) | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=color1 | +| `blackbody.sbs/blackbody` · output (RGBA) | checked | none
temperature=12000 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 0/4,096 · 5.96046448e-08 | 0/1,024 · 5.96046448e-08 | +| `blend.sbs/color` · Color (RGBA) | checked | Background=blend-bg-alpha-256, Foreground=blend-fg-alpha-256, Mask=blend-mask-256
Opacity=0.67 | 4,094/4,096 · 1 | 4,082/4,096 · 110 | 4,094/4,096 · 0.00170898438 | 1,345/4,096 · 0.00166922808 | 1,021/1,024 · 0.00676953793
Background=color1, Foreground=color2, Mask=gray3 | +| `blend.sbs/color_burn` · Color_Burn (RGBA) | checked | Background=blend-bg-alpha-256, Foreground=blend-fg-alpha-256, Mask=blend-mask-256
Opacity=0.67 | 4,096/4,096 · 0 | 4,090/4,096 · 1 | 4,096/4,096 · 0 | 1,006/4,096 · 1.1920929e-07 | 1,020/1,024 · 0.135751605
Background=color1, Foreground=color2, Mask=gray3 | +| `blend.sbs/color_dodge` · Color_Dodge (RGBA) | checked | Background=blend-bg-alpha-256, Foreground=blend-fg-alpha-256, Mask=blend-mask-256
Opacity=0.67 | 4,096/4,096 · 0 | 4,088/4,096 · 1 | 4,096/4,096 · 0 | 2,202/4,096 · 5.96046448e-08 | 524/1,024 · 5.96046448e-08
Background=color1, Foreground=color2, Mask=gray3 | +| `blend.sbs/dissolve_2` · output (RGBA) | checked | background=blend-bg-alpha-256, foreground=blend-fg-alpha-256, mask=blend-mask-256
opacity=0.67 | 2,491/4,096 · 196 | 2,491/4,096 · 50344 | 2,491/4,096 · 0.768066406 | 2,109/4,096 · 0.768196866 | 669/1,024 · 0.960784314
background=color1, foreground=color2, mask=gray3 | +| `blend.sbs/luminosity` · Exclusion (RGBA) | value | Background=blend-bg-alpha-256, Foreground=blend-fg-alpha-256, Mask=blend-mask-256
Opacity=0.67 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
Background=color1, Foreground=color2, Mask=gray3 | +| `blur_hq.sbs/blur_hq` · Blur_HQ (RGBA) | value | Source=offset-alpha-128
Intensity=1 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
Source=color1 | +| `blur_hq.sbs/blur_hq_grayscale` · Blur_HQ (LUM) | value | Source=offset-gray-128
Intensity=1 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
Source=gray1 | +| `bnw_spots_1.sbs/bnw_spots_1` · BnW_Spots (LUM) | checked | none
Disorder=0.35 | 22/4,096 · 217 | 0/4,096 · 55788 | 1/4,096 · 0.851074219 | 0/4,096 · 0.851272523 | 1/1,024 · 0.544572145 | +| `bnw_spots_3.sbs/bnw_spots_3` · BnW_Spots_3 (LUM) | checked | none
Disorder=0.35 | 37/4,096 · 196 | 0/4,096 · 50175 | 1/4,096 · 0.765441895 | 0/4,096 · 0.765622027 | 0/1,024 · 0.427085683 | +| `brick_1.sbs/brick_1` · Brick (LUM) | checked | none
Tiling=2, Edge_Smoothness=0.2, Interstice_Width=0.2 | 2,464/4,096 · 255 | 2,464/4,096 · 65535 | 2,464/4,096 · 1 | 2,464/4,096 · 1 | 928/1,024 · 0.00692760944 | +| `brick_2.sbs/brick_2` · Brick_2 (LUM) | checked | none
Tiling=2, Edge_Smoothness=0.2, Interstice_Width=0.2 | 2,368/4,096 · 255 | 2,368/4,096 · 65535 | 2,368/4,096 · 1 | 2,368/4,096 · 1 | 448/1,024 · 0.225268938 | +| `brick_3.sbs/brick_3` · Bricks (LUM) | checked | none
Roundness=0.3, Lum_var=0.7, Disorder=0.3, Tiling=2 | 1,064/4,096 · 148 | 1,064/4,096 · 37925 | 1,064/4,096 · 0.578857422 | 1,064/4,096 · 0.578698397 | 168/1,024 · 0.58255893 | +| `cartesian_polar_transformation.sbs/cartesian_to_polar` · output (RGBA) | value | input=blend-bg-alpha-128
defaults | 4,096/4,096 · 0 | 4,095/4,096 · 26 | 4,095/4,096 · 0.00048828125 | 4,095/4,096 · 0.000396728516 | 1,024/1,024 · 0
input=color1 | +| `cartesian_polar_transformation.sbs/cartesian_to_polar_grayscale` · output (LUM) | value | input=levels-range-64
defaults | 4,096/4,096 · 0 | 4,095/4,096 · 17 | 4,095/4,096 · 0.000244140625 | 4,095/4,096 · 0.000259429216 | 1,024/1,024 · 0
input=gray1 | +| `cartesian_polar_transformation.sbs/polar_to_cartesian` · output (RGBA) | angle | input=blend-bg-alpha-128
defaults | 4,095/4,096 · 1 | 4,094/4,096 · 58 | 4,094/4,096 · 0.000732421875 | 4,094/4,096 · 0.000885009766 | 1,023/1,024 · 0.00361639261
input=color1 | +| `cartesian_polar_transformation.sbs/polar_to_cartesian_grayscale` · output (LUM) | angle | input=levels-range-64
defaults | 4,095/4,096 · 1 | 4,094/4,096 · 130 | 4,094/4,096 · 0.001953125 | 4,094/4,096 · 0.00198367238 | 1,023/1,024 · 0.00144961476
input=gray1 | +| `cells_1.sbs/cells_1` · Cells (LUM) | checked | none
Distance=7, Disorder=25 | 51/4,096 · 161 | 0/4,096 · 41413 | 5/4,096 · 0.631591797 | 0/4,096 · 0.631928951 | 0/1,024 · 0.696351647 | +| `channel_mixer.sbs/channel_mixer` · Output (RGBA) | checked | Input=blend-fg-alpha-128
red_channel=(50,25,10,5), green_channel=(-10,100,10,0), blue_channel=(20,0,50,25), monochrome=true | 0/4,096 · 228 | 0/4,096 · 58651 | 0/4,096 · 0.894958496 | 0/4,096 · 0.894956894 | 0/1,024 · 0.909117267
Input=color1 | +| `checker_1.sbs/checker_1` · Checker (LUM) | filtered | none
Tiling=3, Rotate_45_Degrees=true | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `chrominance_extract.sbs/chrominance_extract` · Chrominance_Extract (RGBA) | checked | Source=blend-bg-alpha-128
defaults | 2,551/4,096 · 1 | 2,551/4,096 · 258 | 2,551/4,096 · 0.00439453125 | 2,551/4,096 · 0.00392174721 | 659/1,024 · 0.00392174721
Source=color1 | +| `clone.sbs/clone` · Clone (RGBA) | filtered | Mask=blend-mask-128, Source=blend-fg-alpha-128
Offset=(0.17,-0.25), Blur_Mask=0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `clouds_1.sbs/clouds_1` · Clouds (LUM) | checked | none
Disorder=0.4 | 44/4,096 · 140 | 1/4,096 · 35949 | 2/4,096 · 0.548339844 | 0/4,096 · 0.54854019 | 0/1,024 · 0.583147138 | +| `clouds_2.sbs/clouds_2` · Clouds_2 (LUM) | checked | none
defaults | 55/4,096 · 139 | 0/4,096 · 35594 | 6/4,096 · 0.54296875 | 0/4,096 · 0.54312177 | 0/1,024 · 0.435591429 | +| `color_space_conversion.sbs/acescg_to_linear_srgb` · output (RGBA) | filtered | input=blend-bg-alpha-128
defaults | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `color_space_conversion.sbs/srgb_to_acescg` · output (RGBA) | checked | input=blend-bg-alpha-128
defaults | 4,096/4,096 · 0 | 4,067/4,096 · 1 | 4,093/4,096 · 0.000122070312 | 46/4,096 · 2.38418579e-07 | 11/1,024 · 2.38418579e-07
input=color1 | +| `color_temperature_adjustment.sbs/color_temperature_adjustment` · output (RGBA) | value | input=blend-fg-alpha-128
temp=0.25, magreen=-0.2, color_space=1 | 4,095/4,096 · 1 | 4,095/4,096 · 257 | 4,095/4,096 · 0.00390625 | 4,095/4,096 · 0.00392156839 | 1,024/1,024 · 0
input=color1 | +| `color_to_mask.sbs/color_to_mask` · output (LUM) | checked | Input=blend-fg-alpha-128
color=(0.8,0.2,0.4), mask_range=0.3, mask_softness=0.1, keying_type=1, flatten_alpha=true | 4,074/4,096 · 255 | 4,074/4,096 · 65535 | 4,074/4,096 · 1 | 4,074/4,096 · 1 | 1,018/1,024 · 1
Input=color1 | +| `color_to_mask_v2.sbs/color_to_mask` · output (LUM) | checked | color_input=blend-bg-alpha-128, input=blend-fg-alpha-128
use_color_input=true, threshold=0.3, selection_fade=0.2, distance_color_space=1, distance_weights=(1,0.5,1.5) | 4,096/4,096 · 0 | 4,078/4,096 · 1 | 4,083/4,096 · 0.0009765625 | 443/4,096 · 3.33786011e-06 | 148/1,024 · 2.38418579e-06
color_input=color1, input=color2 | +| `composite.sbs/composite/blends/blend_content` · output (RGBA) | checked | background=blend-bg-alpha-128, foreground=blend-fg-alpha-128, mask=blend-mask-128
Opacity=0.37, Blending_Mode=3 | 4,096/4,096 · 0 | 4,093/4,096 · 1 | 4,096/4,096 · 0 | 2,114/4,096 · 5.96046448e-08 | 1,016/1,024 · 1
background=color1, foreground=color2, mask=gray3 | +| `composite.sbs/composite/blends/blend_content_pre_post_composite` · output (RGBA) | checked | background=blend-bg-alpha-128, foreground=blend-fg-alpha-128
Opacity=0.37, Blending_Mode=3 | 4,096/4,096 · 0 | 4,089/4,096 · 1 | 4,096/4,096 · 0 | 2,018/4,096 · 5.96046448e-08 | 543/1,024 · 1
background=color1, foreground=color2 | +| `composite.sbs/composite/blends/blend_matte` · output (LUM) | checked | background=offset-gray-128, foreground=levels-range-64
defaults | 0/4,096 · 145 | 0/4,096 · 37250 | 0/4,096 · 0.567993164 | 0/4,096 · 0.568396799 | 2/1,024 · 0.834894292
background=gray1, foreground=gray2 | +| `composite.sbs/composite/filters/filter_transformation` · Output (RGBA) | checked | Input=blend-fg-alpha-128
matrix=(1,0.25,-0.5,1), offset=(0.125,-0.25), filtering=1 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,020/1,024 · 1
Input=color1 | +| `constant_values.sbs/integer/constant_integer4` · output (int4) | gray | none
integer4_value=(-31,0,1,2147483647) | 0/1 · 4.2949673e+09 | 0/1 · 4.2949673e+09 | 0/1 · 4.2949673e+09 | 0/1 · 4.2949673e+09 | 0/1 · 4.2949673e+09 | +| `creased.sbs/creased` · Creased (LUM) | checked | none
Warp_Intensity=20, Disorder=0.3 | 43/4,096 · 146 | 0/4,096 · 37532 | 3/4,096 · 0.572509766 | 0/4,096 · 0.572693318 | 0/1,024 · 0.34687297 | +| `crop.sbs/crop` · output (RGBA) | value | input=blend-fg-alpha-128
show_crop_area=false, input_size=(128,128), matrix=(1.2,0.25,-0.125,0.8), offset=(0.1,-0.15), filtering=1 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=color1 | +| `crop.sbs/crop` · area (RGBA) | value | input=blend-fg-alpha-128
show_crop_area=false, input_size=(128,128), matrix=(1.2,0.25,-0.125,0.8), offset=(0.1,-0.15), filtering=1 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=color1 | +| `crop.sbs/crop_grayscale` · output (LUM) | value | input=offset-gray-128
show_crop_area=false, input_size=(128,128), matrix=(1.2,0.25,-0.125,0.8), offset=(0.1,-0.15), filtering=1 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=gray1 | +| `crop.sbs/crop_grayscale` · area (LUM) | value | input=offset-gray-128
show_crop_area=false, input_size=(128,128), matrix=(1.2,0.25,-0.125,0.8), offset=(0.1,-0.15), filtering=1 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=gray1 | +| `crystal_1.sbs/crystal_1` · Crystal (LUM) | checked | none
Warp_Intensity=10, Disorder=0.35 | 78/4,096 · 168 | 0/4,096 · 43208 | 0/4,096 · 0.658927917 | 0/4,096 · 0.659312377 | 0/1,024 · 0.766939715 | +| `crystal_2.sbs/crystal_2` · Crystal_2 (LUM) | checked | none
Warp_Intensity=10 | 47/4,096 · 182 | 0/4,096 · 46586 | 0/4,096 · 0.710449219 | 0/4,096 · 0.710852653 | 0/1,024 · 0.600114677 | +| `curvature.sbs/curvature` · Output (LUM) | checked | Input=curved-normal-128
intensity=2, invert_green=true, normal_format=1 | 81/4,096 · 22 | 1/4,096 · 5756 | 6/4,096 · 0.087890625 | 1/4,096 · 0.0878310204 | 0/1,024 · 0.713176146
Input=normal | +| `curvature_smooth.sbs/curvature_smooth` · height (LUM) | checked | input=curved-normal-128
normal_format=1 | 4,083/4,096 · 1 | 1,445/4,096 · 3 | 3,754/4,096 · 0.00048828125 | 1,445/4,096 · 4.58061695e-05 | 592/1,024 · 1.53183937e-05
input=normal | +| `diffusion.sbs/impl/pass_RGBA` · output (RGBA) | checked | direction=curved-normal-128, input=blend-fg-alpha-128, mask=blend-mask-128, reference=blend-bg-alpha-128
iter=3, nbIter=16, dither=true | 35/4,096 · 124 | 9/4,096 · 31735 | 11/4,096 · 0.483886719 | 5/4,096 · 0.484244436 | 12/1,024 · 0.474744245
direction=normal, input=color2, mask=gray3, reference=color4 | +| `diffusion.sbs/impl/pass_UV` · output (RGBA) | checked | input=position-128
iter=3, nbIter=16 | 2,554/4,096 · 192 | 1,905/4,096 · 49216 | 1,905/4,096 · 0.750976562 | 1,833/4,096 · 0.750980422 | 267/1,024 · 0.758823559
input=position | +| `diffusion.sbs/impl/pass_gray` · output (LUM) | checked | input=offset-gray-128, intensity=levels-range-64, reference=blend-bg-alpha-128
iter=3, nbIter=16, dither=true | 275/4,096 · 75 | 75/4,096 · 19121 | 91/4,096 · 0.291748047 | 64/4,096 · 0.2917656 | 7/1,024 · 0.306589752
input=gray1, intensity=gray2, reference=color3 | +| `diffusion.sbs/impl/pass_normal` · output (RGBA) | checked | input=curved-normal-128, reference=curved-normal-128
iter=3, nbIter=16, dither=true | 332/4,096 · 91 | 4/4,096 · 23349 | 20/4,096 · 0.356201172 | 0/4,096 · 0.356286973 | 16/1,024 · 0.125420004
input=normal, reference=normal | +| `directional_distance.sbs/directional_distance` · output (LUM) | value | angle_map=levels-range-64, distance_map=levels-range-64, input=crop-rectangle-64
output=1, max_distance=0.2, angle=0.125, angle_map_multiplier=0.25 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
angle_map=gray1, distance_map=gray2, input=rectangle | +| `directional_distance.sbs/directional_distance` · uv (RGBA) | value | angle_map=levels-range-64, distance_map=levels-range-64, input=crop-rectangle-64
output=1, max_distance=0.2, angle=0.125, angle_map_multiplier=0.25 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
angle_map=gray1, distance_map=gray2, input=rectangle | +| `directionnal_noise.sbs/directionnal_noise` · Directionnal_Noise (LUM) | checked | none
defaults | 6/4,096 · 221 | 0/4,096 · 56887 | 0/4,096 · 0.867797852 | 0/4,096 · 0.868038811 | 0/1,024 · 0.783939391 | +| `dirt_1.sbs/dirt_1` · Dirt (LUM) | checked | none
Disorder=0.4 | 35/4,096 · 237 | 6/4,096 · 60905 | 8/4,096 · 0.929046631 | 6/4,096 · 0.929355118 | 0/1,024 · 0.616165075 | +| `dirt_3.sbs/dirt_3` · Film_Dust (LUM) | checked | none
Disorder=0.4 | 93/4,096 · 224 | 3/4,096 · 57618 | 4/4,096 · 1.09405518 | 3/4,096 · 1.09495693 | 0/1,024 · 0.756450712 | +| `dirt_5.sbs/dirt_5` · White_Spots (LUM) | checked | none
defaults | 672/4,096 · 243 | 635/4,096 · 62456 | 635/4,096 · 0.952599525 | 635/4,096 · 0.953009048 | 123/1,024 · 0.669190332 | +| `dirt_6.sbs/dirt_6` · White_Stains (LUM) | checked | none
defaults | 118/4,096 · 255 | 90/4,096 · 65535 | 0/4,096 · 1.19921875 | 0/4,096 · 1.19999991 | 0/1,024 · 0.726540804 | +| `dirt_gradient.sbs/dirt_gradient` · Dirt_Gradient (LUM) | checked | none
defaults | 12/4,096 · 255 | 0/4,096 · 65425 | 0/4,096 · 0.998325348 | 0/4,096 · 0.998324568 | 0/1,024 · 0.731058508 | +| `fibers_1.sbs/fibers_1` · Rope (LUM) | checked | none
Tiling=2 | 16/4,096 · 188 | 0/4,096 · 48235 | 4/4,096 · 0.735839844 | 0/4,096 · 0.736018926 | 0/1,024 · 0.0354467034 | +| `flood_fill.sbs/flood_fill_to_random_color` · output (RGBA) | checked | input=flood-bbox-128
defaults | 0/4,096 · 251 | 0/4,096 · 64288 | 0/4,096 · 0.98085022 | 0/4,096 · 0.980972027 | 0/1,024 · 0.951476281
input=flood-bbox-128 | +| `flood_fill.sbs/flood_fill_to_random_grayscale` · output (LUM) | checked | input=flood-bbox-128
defaults | 28/4,096 · 246 | 0/4,096 · 63364 | 0/4,096 · 0.966690063 | 0/4,096 · 0.966872638 | 0/1,024 · 0.853513394
input=flood-bbox-128 | +| `flood_fill_2.sbs/flood_fill_to_color` · output (RGBA) | checked | color_input=blend-bg-alpha-128, input=flood-bbox-128
hsl_adjustement=(0.1,0.2,-0.1), hsl_random=(0.2,0.1,0.1), filtering_mode=1 | 0/4,096 · 180 | 0/4,096 · 46114 | 0/4,096 · 0.703369141 | 0/4,096 · 0.703650177 | 0/1,024 · 0.644458398
color_input=color1, input=flood-bbox-128 | +| `flood_fill_2.sbs/flood_fill_to_grayscale` · output (LUM) | checked | grayscale_input=levels-range-64, input=flood-bbox-128
luminance_adjustement=0.2, luminance_random=0.1, filtering_mode=1 | 336/4,096 · 20 | 1/4,096 · 5186 | 60/4,096 · 0.0791015625 | 0/4,096 · 0.0791372955 | 3/1,024 · 0.0657403171
grayscale_input=gray1, input=flood-bbox-128 | +| `flood_fill_2.sbs/flood_fill_to_random_color` · output (RGBA) | checked | input=flood-bbox-128
defaults | 0/4,096 · 251 | 0/4,096 · 64288 | 0/4,096 · 0.98085022 | 0/4,096 · 0.980972027 | 0/1,024 · 0.951476281
input=flood-bbox-128 | +| `flood_fill_2.sbs/flood_fill_to_random_grayscale` · output (LUM) | checked | input=flood-bbox-128
defaults | 19/4,096 · 249 | 0/4,096 · 64050 | 0/4,096 · 0.977127075 | 0/4,096 · 0.977340349 | 0/1,024 · 0.951964607
input=flood-bbox-128 | +| `fluid.sbs/fluid` · Fluid (LUM) | checked | none
Disorder=0.3, Warp_Intensity=10, Flow=0.3, Pattern_Lenght=0.75, Pattern_Width=0.2 | 18/4,096 · 210 | 0/4,096 · 53947 | 2/4,096 · 0.822875977 | 0/4,096 · 0.823176099 | 0/1,024 · 0.646288291 | +| `fractal_sum_base.sbs/fractal_sum_base` · Fractal_Sum_Base (LUM) | checked | none
Roughness=0.7, GlobalOpacity=0.75, MinLevel=2, MaxLevel=8 | 127/4,096 · 36 | 0/4,096 · 9013 | 8/4,096 · 0.137573242 | 0/4,096 · 0.137529567 | 0/1,024 · 0.115114063 | +| `fur_1.sbs/fur_1` · Fur (LUM) | checked | none
Disorder=0.4 | 18/4,096 · 255 | 9/4,096 · 65478 | 0/4,096 · 1.55157471 | 0/4,096 · 1.5521629 | 0/1,024 · 0.950347155 | +| `fur_2.sbs/fur_2` · Fur_2 (LUM) | checked | none
Disorder=0.3, Waves_Scale=0.5, Waves_Rotation=0.125 | 1/4,096 · 249 | 0/4,096 · 63919 | 0/4,096 · 0.975170135 | 0/4,096 · 0.97533028 | 0/1,024 · 0.509616658 | +| `fur_3.sbs/fur_3` · Fur_3 (LUM) | checked | none
Density=0.4, Disorder=0.2 | 19/4,096 · 249 | 0/4,096 · 63797 | 2/4,096 · 0.973403931 | 0/4,096 · 0.973479849 | 0/1,024 · 0.794445702 | +| `fur_4.sbs/fur_4` · Fur_4 (LUM) | checked | none
Disorder=0.3 | 42/4,096 · 255 | 30/4,096 · 65535 | 32/4,096 · 1 | 30/4,096 · 1 | 6/1,024 · 0.996810864 | +| `gaussian_1.sbs/gaussian_1` · Gaussian_Spots (LUM) | value | none
Tiling=2 | 4,096/4,096 · 0 | 4,064/4,096 · 1 | 4,096/4,096 · 0 | 4,064/4,096 · 1.52587891e-05 | 1,024/1,024 · 0 | +| `gaussian_2.sbs/gaussian_2` · Gaussian_Spots_2 (LUM) | value | none
Tiling=2 | 4,096/4,096 · 0 | 4,032/4,096 · 1 | 4,096/4,096 · 0 | 4,032/4,096 · 1.52587891e-05 | 1,024/1,024 · 0 | +| `gaussian_spots_1.sbs/gaussian_spots_1` · Few_Gauss (LUM) | checked | none
Disorder=0.3 | 37/4,096 · 209 | 1/4,096 · 53631 | 2/4,096 · 0.863525391 | 0/4,096 · 0.864231735 | 10/1,024 · 0.997272894 | +| `gaussian_spots_2.sbs/gaussian_spots_2` · Gauss_Spots (LUM) | checked | none
Disorder=0.3 | 40/4,096 · 255 | 2/4,096 · 65535 | 2/4,096 · 1.18993378 | 2/4,096 · 1.19044852 | 0/1,024 · 0.624857013 | +| `gradient_axial.sbs/gradient_axial` · output (LUM) | value | none
point_1=(0.15,0.3), point_2=(0.7,0.85), non_square_expansion=false | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0 | +| `gradient_axial.sbs/gradient_axial_reflected` · output (LUM) | value | none
point_1=(0.15,0.3), point_2=(0.7,0.85), non_square_expansion=false | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0 | +| `gradient_circular.sbs/gradient_circular` · output (LUM) | angle | none
point_1=(0.3,0.6), point_2=(0.8,0.7), angle=0.2, non_square_expansion=false | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `gradient_linear_1.sbs/gradient_linear_1` · Simple_Gradient (LUM) | checked | none
Tiling=3, rotation=1 | 4,032/4,096 · 1 | 4,032/4,096 · 1 | 3,872/4,096 · 0.00048828125 | 3,936/4,096 · 1.33514404e-05 | 384/1,024 · 0.34570837 | +| `gradient_linear_2.sbs/gradient_linear_2` · Simple_Gradient_2 (LUM) | filtered | none
Tiling=3, rotation=1 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `gradient_linear_3.sbs/gradient_linear_3` · output (LUM) | checked | none
Tiling=3, position=0.3, rotation=1 | 4,096/4,096 · 0 | 3,712/4,096 · 2 | 640/4,096 · 0.0009765625 | 2,432/4,096 · 2.00867653e-05 | 864/1,024 · 5.96046448e-08 | +| `gradient_radial.sbs/gradient_radial` · output (LUM) | checked | none
shape=1, point_1=(0.3,0.6), point_2=(0.8,0.7), non_square_expansion=false | 4,096/4,096 · 0 | 4,090/4,096 · 1 | nonfinite cook | nonfinite cook | 507/1,024 · 7.74860382e-07² | +| `hald_clut.sbs/hald_clut` · output (RGBA) | value | input=blend-fg-alpha-128, lut=original-hald-identity-512
lut_intensity_by_input_alpha=false | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=color1, lut=original-hald-identity-512 | +| `hbao.sbs/hbao_mip` · output (LUM) | checked | input=offset-gray-128
mip=3 | 3,200/4,096 · 1 | 256/4,096 · 66 | 2,560/4,096 · 0.0009765625 | 0/4,096 · 0.00100710988 | 8/1,024 · 0.00863063335
input=gray1 | +| `hbao_2.sbs/hbao_mip` · output (LUM) | checked | input=offset-gray-128
mip=3 | 3,200/4,096 · 1 | 256/4,096 · 66 | 2,560/4,096 · 0.0009765625 | 0/4,096 · 0.00100710988 | 8/1,024 · 0.00863063335
input=gray1 | +| `hbao_2.sbs/hbao_subsample` · output (LUM) | filtered | input=levels-range-64, mip_input=offset-gray-128
angle=0.125, mip=3, jiterring=0.5, offset_multiplier=(0.75,1.25) | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,035/4,096 · 5.96046448e-08 | 1,004/1,024 · 5.96046448e-08
input=gray1, mip_input=gray2 | +| `hdr_merge.sbs/average_luminance_merge` · output (RGBA) | value | input=hdr-field-128
exposure_delta=2 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=hdr-field-128 | +| `hdr_range_viewer.sbs/hdr_range_viewer_grayscale` · output (RGBA) | checked | input=hdr-field-128
range_min=0, range_max=4 | 2,906/4,096 · 1 | 2,906/4,096 · 257 | 2,906/4,096 · 0.00439453125 | 2,906/4,096 · 0.0039215982 | 717/1,024 · 0.00392156933
input=hdr-field-128 | +| `height_blend.sbs/height_blend` · blended_height (LUM) | checked | height_bottom=offset-gray-128, height_top=levels-range-64, mask=blend-mask-128
height_position=0.35, contrast=0.6, mode=1, opacity=0.7 | 1,899/4,096 · 29 | 1,780/4,096 · 7540 | 1,795/4,096 · 0.114990234 | 1,780/4,096 · 0.115042463 | 502/1,024 · 0.103863969
height_bottom=gray1, height_top=gray2, mask=gray3 | +| `height_blend.sbs/height_blend` · height_mask (LUM) | checked | height_bottom=offset-gray-128, height_top=levels-range-64, mask=blend-mask-128
height_position=0.35, contrast=0.6, mode=1, opacity=0.7 | 1,928/4,096 · 85 | 1,928/4,096 · 22025 | 1,928/4,096 · 0.336181641 | 1,928/4,096 · 0.336087614 | 660/1,024 · 0.196429372
height_bottom=gray1, height_top=gray2, mask=gray3 | +| `height_to_normal_world_units.sbs/height_to_normal_world_units` · output (RGBA) | filtered | input=offset-gray-128
surface_size=100, height_depth=8, normal_format=0, sampling=1 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `height_to_normal_world_units.sbs/height_to_normal_world_units_2` · output (RGBA) | filtered | input=offset-gray-128
surface_size=100, height_depth=8, normal_format=0, sampling=1 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `highpass.sbs/highpass` · Highpass (RGBA) | checked | Source=blend-fg-alpha-128
Radius=2 | 4,096/4,096 · 0 | 4,081/4,096 · 1 | 4,096/4,096 · 0 | 1,002/4,096 · 5.96046448e-08 | 287/1,024 · 1.1920929e-07
Source=color1 | +| `highpass.sbs/highpass_grayscale` · Highpass (LUM) | value | Source=offset-gray-128
Radius=2 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
Source=gray1 | +| `histogram_scan.sbs/histogram_scan` · Output (LUM) | checked | Input_1=offset-gray-128
Position=0.4, Contrast=0.6, Invert_Position=true | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 3,358/4,096 · 5.96046448e-08 | 896/1,024 · 5.96046448e-08
Input_1=gray1 | +| `histogram_shift.sbs/histogram_shift` · output (LUM) | checked | input=offset-gray-128
position=0.3 | 4,096/4,096 · 0 | 4,002/4,096 · 1 | 4,096/4,096 · 0 | 4,002/4,096 · 1.52587891e-05 | 1,004/1,024 · 1.52587891e-05
input=gray1 | +| `histogram_tools.sbs/histogram_compute` · cdf (LUM) | value | input=offset-gray-128
histogram_resolution=7 | 116/128 · 1 | 44/128 · 272 | 72/128 · 0.00415039062 | 44/128 · 0.00415039062 | 128/128 · 0
input=gray1 | +| `histogram_tools.sbs/histogram_compute` · histogram (LUM) | value | input=offset-gray-128
histogram_resolution=7 | 124/128 · 255 | 124/128 · 65535 | 24/128 · 13.25 | 24/128 · 13.25 | 128/128 · 0
input=gray1 | +| `make_it_tile_patch.sbs/make_it_tile_patch` · Make_It_Tile_Patch (RGBA) | checked | Source=blend-fg-alpha-128
Mask_Size=0.8, Mask_Precision=0.7, Mask_Warping=0.1, Pattern_size_width=120, Pattern_size_height=160, Disorder=0.25, Size_Variation=0.15, Octave=2, Rotation=0.125 | 12/4,096 · 255 | 9/4,096 · 65535 | 9/4,096 · 1 | 9/4,096 · 1 | 158/1,024 · 1
Source=color1 | +| `make_it_tile_patch_grayscale.sbs/make_it_tile_patch_grayscale` · Make_It_Tile_Patch (LUM) | checked | Source=offset-gray-128
Mask_Size=0.8, Mask_Precision=0.7, Mask_Warping=0.1, Pattern_size_width=120, Pattern_size_height=160, Disorder=0.25, Size_Variation=0.15, Octave=2, Rotation=0.125 | 34/4,096 · 216 | 9/4,096 · 55426 | 10/4,096 · 0.845703125 | 9/4,096 · 0.845746636 | 158/1,024 · 0.873212839
Source=gray1 | +| `material_transforms.sbs/material_transforms` · Diffuse (RGBA) | checked | Diffuse_In=material-input-1-128, Emissive_In=material-input-5-128, Height_In=material-input-3-128, Opacity_In=material-input-4-128, Specular_In=material-input-2-128
ScaleUV=(75,125), Rotation=0.125, Offset=(0.125,-0.25) | 4,009/4,096 · 1 | 3,928/4,096 · 253 | 3,928/4,096 · 0.00390625 | 3,928/4,096 · 0.00386054814 | 1,010/1,024 · 0.00379949808
Diffuse_In=color1, Emissive_In=color2, Height_In=color3, Opacity_In=color4, Specular_In=color5 | +| `material_transforms.sbs/material_transforms` · Specular (RGBA) | checked | Diffuse_In=material-input-1-128, Emissive_In=material-input-5-128, Height_In=material-input-3-128, Opacity_In=material-input-4-128, Specular_In=material-input-2-128
ScaleUV=(75,125), Rotation=0.125, Offset=(0.125,-0.25) | 4,056/4,096 · 1 | 3,935/4,096 · 205 | 3,939/4,096 · 0.00317382812 | 3,935/4,096 · 0.00312809646 | 1,010/1,024 · 0.00329595804
Diffuse_In=color1, Emissive_In=color2, Height_In=color3, Opacity_In=color4, Specular_In=color5 | +| `material_transforms.sbs/material_transforms` · Height (LUM) | checked | Diffuse_In=material-input-1-128, Emissive_In=material-input-5-128, Height_In=material-input-3-128, Opacity_In=material-input-4-128, Specular_In=material-input-2-128
ScaleUV=(75,125), Rotation=0.125, Offset=(0.125,-0.25) | 4,095/4,096 · 1 | 4,057/4,096 · 58 | 4,060/4,096 · 0.0009765625 | 4,057/4,096 · 0.000885039568 | 1,010/1,024 · 0.00204470754
Diffuse_In=color1, Emissive_In=color2, Height_In=color3, Opacity_In=color4, Specular_In=color5 | +| `material_transforms.sbs/material_transforms` · Opacity (LUM) | checked | Diffuse_In=material-input-1-128, Emissive_In=material-input-5-128, Height_In=material-input-3-128, Opacity_In=material-input-4-128, Specular_In=material-input-2-128
ScaleUV=(75,125), Rotation=0.125, Offset=(0.125,-0.25) | 4,093/4,096 · 1 | 4,057/4,096 · 49 | 4,066/4,096 · 0.0009765625 | 4,057/4,096 · 0.000747680664 | 1,010/1,024 · 0.00202944875
Diffuse_In=color1, Emissive_In=color2, Height_In=color3, Opacity_In=color4, Specular_In=color5 | +| `material_transforms.sbs/material_transforms` · Emissive (RGBA) | checked | Diffuse_In=material-input-1-128, Emissive_In=material-input-5-128, Height_In=material-input-3-128, Opacity_In=material-input-4-128, Specular_In=material-input-2-128
ScaleUV=(75,125), Rotation=0.125, Offset=(0.125,-0.25) | 4,081/4,096 · 1 | 4,057/4,096 · 179 | 4,061/4,096 · 0.0029296875 | 4,057/4,096 · 0.00273138285 | 1,010/1,024 · 0.00372320414
Diffuse_In=color1, Emissive_In=color2, Height_In=color3, Opacity_In=color4, Specular_In=color5 | +| `me_water_level.sbs/scratches_2` · Thorns (RGBA) | checked | none
Pattern_size_width=60, Pattern_size_height=140, Disorder=0.3 | 0/4,096 · 87 | 0/4,096 · 22444 | 0/4,096 · 0.342529297 | 0/4,096 · 0.342473418 | 0/1,024 · 0.300794378 | +| `mean_of_least_variance.sbs/mlv_color_iteration` · output (RGBA) | checked | input=blend-fg-alpha-128
intensity=3, smoothness=0.3, criterion=1, gaussian=true, affect_alpha=true | 4,096/4,096 · 0 | 4,093/4,096 · 1 | 4,096/4,096 · 0 | 990/4,096 · 1.1920929e-07 | 194/1,024 · 1.1920929e-07
input=color1 | +| `mean_of_least_variance.sbs/mlv_grayscale_iteration` · output (LUM) | checked | input=offset-gray-128
intensity=3, smoothness=0.3, criterion=1, gaussian=true | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 2,627/4,096 · 5.96046448e-08 | 667/1,024 · 1.1920929e-07
input=gray1 | +| `median_filter.sbs/median_filter_color` · output (RGBA) | filtered | input=blend-fg-alpha-128
kernel_size=1, filter_type=1, affect_alpha=true | 3,517/4,096 · 194 | 3,517/4,096 · 49858 | 3,517/4,096 · 0.760437012 | 3,517/4,096 · 0.760784321 | 1,023/1,024 · 0.223529428
input=color1 | +| `mesh_1.sbs/mesh_1` · Mesh (LUM) | checked | none
Tiling=2, Rotate_45_Degrees=true | 8/4,096 · 255 | 0/4,096 · 65535 | 0/4,096 · 1 | 0/4,096 · 1 | 0/1,024 · 0.856000617 | +| `mesh_2.sbs/mesh_2` · Mesh_2 (LUM) | checked | none
Tiling=2, Rotation=true | 96/4,096 · 255 | 80/4,096 · 65535 | 80/4,096 · 1 | 80/4,096 · 1 | 48/1,024 · 0.984206913 | +| `mesh_adaptive_material_blender.sbs/mesh_material_blender_2_inputs` · Composited_Diffuse (RGBA) | checked | see input group 3
Material_Transfo_1=(0.75,0.125,0.25,0.5), Height_Range_1=(0.2,0.8), Specular_Range_1=(0.1,0.7) | 4,064/4,096 · 1 | 4,036/4,096 · 257 | 4,042/4,096 · 0.00390625 | 1,437/4,096 · 0.00392156839 | 1,019/1,024 · 0.0039061904
same pin order | +| `mesh_adaptive_material_blender.sbs/mesh_material_blender_2_inputs` · Composited_Height (LUM) | checked | see input group 4
Material_Transfo_1=(0.75,0.125,0.25,0.5), Height_Range_1=(0.2,0.8), Specular_Range_1=(0.1,0.7) | 4,092/4,096 · 1 | 4,091/4,096 · 257 | 4,091/4,096 · 0.00415039062 | 3,092/4,096 · 0.00392156839 | 1,023/1,024 · 0.00261437893
same pin order | +| `mesh_adaptive_material_blender.sbs/mesh_material_blender_2_inputs` · Composited_Specular (RGBA) | checked | see input group 5
Material_Transfo_1=(0.75,0.125,0.25,0.5), Height_Range_1=(0.2,0.8), Specular_Range_1=(0.1,0.7) | 0/4,096 · 192 | 0/4,096 · 49344 | 0/4,096 · 0.753051758 | 0/4,096 · 0.752941176 | 0/1,024 · 0.811764702
same pin order | +| `mesh_adaptive_material_blender.sbs/mesh_material_blender_4_inputs` · Composited_Diffuse (RGBA) | checked | see input group 6
Material_Transfo_1=(0.75,0.125,0.25,0.5), Height_Range_1=(0.2,0.8), Specular_Range_1=(0.1,0.7) | 3,977/4,096 · 1 | 3,853/4,096 · 257 | 3,862/4,096 · 0.00390625 | 2,767/4,096 · 0.00392156839 | 1,023/1,024 · 0.00181466341
same pin order | +| `mesh_adaptive_material_blender.sbs/mesh_material_blender_4_inputs` · Composited_Height (LUM) | checked | see input group 7
Material_Transfo_1=(0.75,0.125,0.25,0.5), Height_Range_1=(0.2,0.8), Specular_Range_1=(0.1,0.7) | 4,094/4,096 · 1 | 4,094/4,096 · 257 | 4,094/4,096 · 0.00415039062 | 4,094/4,096 · 0.00392156839 | 1,024/1,024 · 0
same pin order | +| `mesh_adaptive_material_blender.sbs/mesh_material_blender_4_inputs` · Composited_Specular (RGBA) | checked | see input group 8
Material_Transfo_1=(0.75,0.125,0.25,0.5), Height_Range_1=(0.2,0.8), Specular_Range_1=(0.1,0.7) | 0/4,096 · 190 | 0/4,096 · 48830 | 0/4,096 · 0.745117188 | 0/4,096 · 0.745098025 | 4/1,024 · 0.772549018
same pin order | +| `mesh_adaptive_material_blender.sbs/mesh_material_blender_8_inputs` · Composited_Diffuse (RGBA) | checked | see input group 9
Material_Transfo_1=(0.75,0.125,0.25,0.5), Height_Range_1=(0.2,0.8), Specular_Range_1=(0.1,0.7) | 4,032/4,096 · 1 | 4,030/4,096 · 257 | 4,030/4,096 · 0.00439453125 | 3,730/4,096 · 0.00392156839 | 1,024/1,024 · 0
same pin order | +| `mesh_adaptive_material_blender.sbs/mesh_material_blender_8_inputs` · Composited_Height (LUM) | checked | see input group 10
Material_Transfo_1=(0.75,0.125,0.25,0.5), Height_Range_1=(0.2,0.8), Specular_Range_1=(0.1,0.7) | 4,092/4,096 · 1 | 4,092/4,096 · 257 | 4,092/4,096 · 0.00415039062 | 4,092/4,096 · 0.00392156839 | 1,024/1,024 · 0
same pin order | +| `mesh_adaptive_material_blender.sbs/mesh_material_blender_8_inputs` · Composited_Specular (RGBA) | checked | see input group 11
Material_Transfo_1=(0.75,0.125,0.25,0.5), Height_Range_1=(0.2,0.8), Specular_Range_1=(0.1,0.7) | 0/4,096 · 189 | 0/4,096 · 48573 | 0/4,096 · 0.741210938 | 0/4,096 · 0.741176456 | 4/1,024 · 0.921568631
same pin order | +| `messy_fibers_1.sbs/messy_fibers_1` · Messy_Fibers (LUM) | checked | none
Rotation_Var=90, Links_Number=10, Disorder=0.3, Emboss_Intensity=0.5 | 11/4,096 · 250 | 0/4,096 · 64213 | 0/4,096 · 0.979415894 | 0/4,096 · 0.979830824 | 0/1,024 · 0.981659172 | +| `messy_fibers_2.sbs/messy_fibers_2` · Lines (LUM) | checked | none
Lines_Number=25, Disorder=0.3 | 14/4,096 · 255 | 6/4,096 · 65535 | 0/4,096 · 2.16217041 | 0/4,096 · 2.1632987 | 0/1,024 · 2.01119667 | +| `messy_fibers_3.sbs/messy_fibers_3` · Spike_Fibers (LUM) | checked | none
Rotation_Var=90, Disorder=0.3, Rotation=0.25 | 1,503/4,096 · 255 | 1,497/4,096 · 65535 | 212/4,096 · 1.16601562 | 109/4,096 · 1.1666851 | 1/1,024 · 1.16668423 | +| `messy_fibers_4.sbs/messy_fibers_4` · Sponge_Stains (LUM) | checked | none
defaults | 9/4,096 · 241 | 0/4,096 · 61957 | 1/4,096 · 0.945007324 | 0/4,096 · 0.945403206 | 0/1,024 · 0.921232916 | +| `microscope_view.sbs/microscope_view` · Microscope_View (LUM) | checked | none
Warp_intensity=6, Disorder=0.3 | 1/4,096 · 255 | 0/4,096 · 65474 | 0/4,096 · 0.999069214 | 0/4,096 · 0.9990692 | 0/1,024 · 0.842359186 | +| `min_max.sbs/min_max` · min (float) | value | Input=levels-range-64
defaults | 0/1 · 5.96046448e-08 | 0/1 · 5.96046448e-08 | 0/1 · 5.96046448e-08 | 0/1 · 5.96046448e-08 | 1/1 · 0
Input=gray1 | +| `min_max.sbs/min_max` · max (float) | value | Input=levels-range-64
defaults | 1/1 · 0 | 1/1 · 0 | 1/1 · 0 | 1/1 · 0 | 1/1 · 0
Input=gray1 | +| `moisture_noise.sbs/moisture_noise` · Moisture_Noise (LUM) | checked | none
Pattern_size_width=60, Pattern_size_height=140, Disorder=0.3 | 56/4,096 · 140 | 6/4,096 · 35895 | 9/4,096 · 0.547485352 | 0/4,096 · 0.547717758 | 0/1,024 · 0.405112803 | +| `mosaic.sbs/mosaic` · Mosaic (RGBA) | checked | Effect=levels-range-64, Source=blend-fg-alpha-128
Samples=4, Intensity=0.25 | 0/4,096 · 153 | 0/4,096 · 39321 | 0/4,096 · 0.599731445 | 0/4,096 · 0.600000009 | 0/1,024 · 0.694117658
Effect=gray1, Source=color2 | +| `mosaic.sbs/mosaic_grayscale` · Mosaic (LUM) | checked | Effect=levels-range-64, Source=offset-gray-128
Samples=4, Intensity=0.25 | 48/4,096 · 102 | 48/4,096 · 26214 | 48/4,096 · 0.399902344 | 48/4,096 · 0.400000006 | 11/1,024 · 0.505882375
Effect=gray1, Source=gray2 | +| `multi_directional_warp.sbs/multi_directional_warp_color` · output (RGBA) | checked | input=blend-bg-alpha-128, intensity_input=offset-gray-128
intensity=4, warp_angle=0.125, mode=1, directions=2 | 152/4,096 · 112 | 152/4,096 · 28784 | 152/4,096 · 0.438964844 | 152/4,096 · 0.43921569 | 56/1,024 · 0.200000018
input=color1, intensity_input=gray2 | +| `multi_directional_warp.sbs/multi_directional_warp_grayscale` · output (LUM) | checked | input=offset-gray-128, intensity_input=levels-range-64
intensity=4, warp_angle=0.125, mode=1, directions=2 | 2,167/4,096 · 46 | 2,167/4,096 · 11822 | 2,167/4,096 · 0.180664062 | 2,167/4,096 · 0.180392146 | 611/1,024 · 0.105882347
input=gray1, intensity_input=gray2 | +| `multiangle_to_albedo.sbs/multiangle_to_albedo` · albedo (RGBA) | filtered | input_1=blend-fg-alpha-128, input_2=blend-bg-alpha-128, input_3=blend-bg-alpha-128, input_4=blend-bg-alpha-128, input_5=blend-bg-alpha-128, input_6=blend-bg-alpha-128, input_7=blend-bg-alpha-128, input_8=blend-bg-alpha-128
samples_amount=4 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `noise_anisotropic_noise.sbs/anisotropic_noise` · Anisotropic_Noise (LUM) | checked | none
X_Amount=8, Y_Amount=64, rotate=true, smoothness=0.5, smoothness_interpolation=0.25 | 3,404/4,096 · 255 | 1,349/4,096 · 65471 | 1,681/4,096 · 0.999023438 | 1,349/4,096 · 0.999023438 | 438/1,024 · 0.0019531846 | +| `noise_anisotropic_noise_v2.sbs/anisotropic_noise_v2` · output (LUM) | value | none
X_Amount=8, Y_Amount=64, rotate=true, smoothness=0.5, smoothness_interpolation=0.25, disorder=0.3, disorder_speed=0.5 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0 | +| `noise_bnw_spots_1.sbs/bnw_spots_1` · output (LUM) | checked | none
scale=2, disorder=0.37, roughness=0.6 | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_bnw_spots_1_v2.sbs/bnw_spots_1` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, roughness=0.6, tile_offset=(0.17,0.29) | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_bnw_spots_3.sbs/bnw_spots_3` · output (LUM) | checked | none
scale=2, disorder=0.37 | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_bnw_spots_3_v2.sbs/bnw_spots_3` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, tile_offset=(0.17,0.29) | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_cells_1.sbs/cells_1` · output (LUM) | checked | none
scale=2, disorder=0.37 | 64/4,096 · 85 | 0/4,096 · 21913 | 8/4,096 · 0.334472656 | 0/4,096 · 0.334366918 | 0/1,024 · 0.312387526 | +| `noise_cells_1_v2.sbs/cells_1` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, angle=0.125, angle_random=0.2, pattern=3, pattern_size=(0.8,1.2), pattern_scale=0.8, luminance_random=0.25, tile_offset=(0.17,0.29) | 0/4,096 · 59 | 0/4,096 · 14988 | 0/4,096 · 0.228515625 | 0/4,096 · 0.228701174 | 0/1,024 · 0.0729952455 | +| `noise_cells_4.sbs/cells_4` · output (LUM) | checked | input=offset-gray-128
scale=2, disorder=0.37, color_source=1, pseudo_random_seed=11 | 687/4,096 · 166 | 687/4,096 · 42559 | 687/4,096 · 0.648925781 | 687/4,096 · 0.649408698 | 90/1,024 · 0.823483601
input=gray1 | +| `noise_cells_4_v2.sbs/cells_4` · output (LUM) | checked | input=offset-gray-128
scale=2, disorder=0.37, disorder_speed=0.6, color_source=1, pseudo_random_seed=11 | 1,400/4,096 · 111 | 1,400/4,096 · 28400 | 1,400/4,096 · 0.433105469 | 1,400/4,096 · 0.433356225 | 353/1,024 · 0.433356225
input=gray1 | +| `noise_clouds_1.sbs/clouds_1` · output (LUM) | checked | none
scale=2, disorder=0.37 | 65/4,096 · 129 | 0/4,096 · 33005 | 9/4,096 · 0.503417969 | 0/4,096 · 0.503617346 | 0/1,024 · 0.366951793 | +| `noise_clouds_1_v2.sbs/clouds_1` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, tile_offset=(0.17,0.29) | 59/4,096 · 100 | 0/4,096 · 25779 | 8/4,096 · 0.393066406 | 0/4,096 · 0.393369287 | 0/1,024 · 0.363682389 | +| `noise_clouds_2.sbs/clouds_2` · output (LUM) | checked | none
scale=2, disorder=0.37 | 64/4,096 · 92 | 1/4,096 · 23488 | 6/4,096 · 0.358398438 | 0/4,096 · 0.358411312 | 0/1,024 · 0.271892846 | +| `noise_clouds_2_v2.sbs/clouds_2` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, tile_offset=(0.17,0.29) | 83/4,096 · 71 | 1/4,096 · 18337 | 10/4,096 · 0.279785156 | 0/4,096 · 0.279799819 | 0/1,024 · 0.27019763 | +| `noise_creased.sbs/creased` · output (LUM) | checked | none
scale=2, disorder=0.37, warp_intensity=0.4 | 82/4,096 · 104 | 2/4,096 · 26838 | 4/4,096 · 0.409423828 | 2/4,096 · 0.40952161 | 0/1,024 · 0.366201252 | +| `noise_crystal_1.sbs/crystal_1` · output (LUM) | checked | none
scale=2, disorder=0.37 | 71/4,096 · 102 | 0/4,096 · 26232 | 1/4,096 · 0.400058746 | 0/4,096 · 0.400280991 | 0/1,024 · 0.333630634 | +| `noise_crystal_2.sbs/crystal_2` · output (LUM) | checked | none
scale=2, disorder=0.37 | 48/4,096 · 189 | 0/4,096 · 48510 | 6/4,096 · 0.739868164 | 0/4,096 · 0.740217775 | 0/1,024 · 0.561198354 | +| `noise_directional_noise_1.sbs/directional_noise_1` · output (LUM) | checked | none
scale=2, disorder=0.37, angle=0.125, angle_random=0.2 | 1/4,096 · 250 | 0/4,096 · 64279 | 0/4,096 · 1.3684082 | 0/4,096 · 1.36927214 | 0/1,024 · 1.44740984 | +| `noise_directional_noise_1_v2.sbs/directional_noise_1` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, angle=0.125, angle_random=0.2, tile_offset=(0.17,0.29) | 0/4,096 · 213 | 0/4,096 · 54794 | 0/4,096 · 1.91894531 | 0/4,096 · 1.9202345 | 0/1,024 · 1.42954385 | +| `noise_directional_noise_2.sbs/directional_noise_2` · output (LUM) | checked | none
scale=2, disorder=0.37, angle=0.125, angle_random=0.2 | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_directional_noise_2_v2.sbs/directional_noise_2` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, angle=0.125, angle_random=0.2, tile_offset=(0.17,0.29) | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_directional_noise_3.sbs/directional_noise_3` · output (LUM) | checked | none
scale=2, disorder=0.37, angle=0.125, angle_random=0.2 | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_directional_noise_3_v2.sbs/directional_noise_3` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, angle=0.125, angle_random=0.2, tile_offset=(0.17,0.29) | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_directional_noise_4.sbs/directional_noise_4` · output (LUM) | checked | none
scale=2, disorder=0.37, angle=0.125, angle_random=0.2 | 33/4,096 · 171 | 0/4,096 · 44073 | 4/4,096 · 0.672271729 | 0/4,096 · 0.67251296 | 0/1,024 · 0.624325883 | +| `noise_directional_noise_4_v2.sbs/directional_noise_4` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, angle=0.125, angle_random=0.2, tile_offset=(0.17,0.29) | 44/4,096 · 168 | 0/4,096 · 43073 | 5/4,096 · 0.68711853 | 0/4,096 · 0.687143391 | 0/1,024 · 0.599172756 | +| `noise_directional_scratches.sbs/directional_scratches` · output (LUM) | checked | none
scale=2, disorder=0.37, angle=0.125, angle_random=0.2, pattern_size=(0.8,1.2), pattern_amount=0.6, pattern_size_random=(0.1,0.2) | 1,079/4,096 · 250 | 1,065/4,096 · 64250 | 1,065/4,096 · 0.979980469 | 1,065/4,096 · 0.980386198 | 483/1,024 · 0.851179719 | +| `noise_directional_scratches_v2.sbs/directional_scratches` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, angle=0.125, angle_random=0.2, pattern_size=(0.8,1.2), tile_offset=(0.17,0.29), pattern_amount=0.6, pattern_size_random=(0.1,0.2) | 1,558/4,096 · 206 | 1,430/4,096 · 52891 | 1,430/4,096 · 0.806640625 | 1,430/4,096 · 0.807068884 | 253/1,024 · 0.825664742 | +| `noise_dirt_1.sbs/dirt_1` · output (LUM) | checked | none
scale=2, disorder=0.37 | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_dirt_1_v2.sbs/dirt_1` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, tile_offset=(0.17,0.29) | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_dirt_2.sbs/dirt_2` · output (LUM) | checked | none
scale=2, disorder=0.37 | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_dirt_3.sbs/dirt_3` · output (LUM) | checked | none
scale=2, disorder=0.37 | 123/4,096 · 177 | 83/4,096 · 45560 | 83/4,096 · 0.694824219 | 83/4,096 · 0.695203125 | 0/1,024 · 0.458531976 | +| `noise_dirt_3_v2.sbs/dirt_3` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, tile_offset=(0.17,0.29) | 47/4,096 · 126 | 1/4,096 · 32344 | 3/4,096 · 0.493225098 | 0/4,096 · 0.493531004 | 0/1,024 · 0.518233344 | +| `noise_dirt_4.sbs/dirt_4` · output (LUM) | angle | none
scale=2, disorder=0.37 | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_dirt_4_v2.sbs/dirt_4` · output (LUM) | angle | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, tile_offset=(0.17,0.29) | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_dirt_5.sbs/dirt_5` · output (LUM) | checked | none
scale=2, disorder=0.37 | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_dirt_5_v2.sbs/dirt_5` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, tile_offset=(0.17,0.29) | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_dirt_gradient.sbs/dirt_gradient` · output (LUM) | checked | none
disorder=0.37 | 2/4,096 · 239 | 0/4,096 · 61336 | 0/4,096 · 1.77966309 | 0/4,096 · 1.78030248 | 0/1,024 · 0.360767424 | +| `noise_dirt_gradient_v2.sbs/dirt_gradient` · output (LUM) | checked | none
disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125 | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_fluid.sbs/fluid` · output (LUM) | checked | none
scale=2, disorder=0.37, pattern_size=(0.8,1.2), warp_intensity=0.4 | 68/4,096 · 126 | 0/4,096 · 32244 | 4/4,096 · 0.491943359 | 0/4,096 · 0.492016941 | 0/1,024 · 0.347934932 | +| `noise_fractal_sum_base.sbs/fractal_sum_base` · output (LUM) | checked | none
Roughness=0.6, GlobalOpacity=0.8, MinLevel=2, MaxLevel=5 | 53/4,096 · 105 | 0/4,096 · 27008 | 5/4,096 · 0.412109375 | 0/4,096 · 0.412115663 | 0/1,024 · 0.319676518 | +| `noise_fractal_sum_base.sbs/fractal_sum_base_2` · output (LUM) | checked | none
Roughness=0.6, GlobalOpacity=0.8, MinLevel=2, MaxLevel=5 | 65/4,096 · 97 | 0/4,096 · 24926 | 5/4,096 · 0.380249023 | 0/4,096 · 0.380346403 | 0/1,024 · 0.295078933 | +| `noise_fractal_sum_base_v2.sbs/noise_blend` · output (LUM) | checked | input=offset-gray-128, previous=levels-range-64
roughness=0.6, global_opacity=0.8, min_level=1, max_level=3, level=2, contrast=0.8 | 4/4,096 · 80 | 4/4,096 · 20560 | 4/4,096 · 0.313476562 | 4/4,096 · 0.313725471 | 82/1,024 · 0.392156869
input=gray1, previous=gray2 | +| `noise_fractal_sum_base_v2.sbs/noise_upscale` · output (LUM) | checked | input=levels-range-64
defaults | 64/4,096 · 15 | 0/4,096 · 3791 | 0/4,096 · 0.228057861 | 0/4,096 · 0.228064887 | 0/1,024 · 0.228064887
input=gray1 | +| `noise_fur_1.sbs/fur_1` · output (LUM) | checked | none
scale=2, disorder=0.37 | 8/4,096 · 255 | 7/4,096 · 65535 | 0/4,096 · 2.29673576 | 0/4,096 · 2.29806608 | 0/1,024 · 1.16170315 | +| `noise_fur_2.sbs/fur_2` · output (LUM) | checked | none
scale=2, waves_scale=0.25, waves_rotation=0.2 | 14/4,096 · 191 | 0/4,096 · 49242 | 2/4,096 · 0.751342773 | 0/4,096 · 0.751376905 | 0/1,024 · 0.445814531 | +| `noise_fur_3.sbs/fur_3` · output (LUM) | checked | none
scale=2, disorder=0.37, waves_amount=3 | 11/4,096 · 191 | 0/4,096 · 48925 | 0/4,096 · 0.74621582 | 0/4,096 · 0.746538982 | 0/1,024 · 0.513960555 | +| `noise_gaussian_noise.sbs/gaussian_noise` · output (LUM) | checked | none
scale=2, disorder=0.37 | 0/4,096 · 159 | 0/4,096 · 40736 | 0/4,096 · 0.621582031 | 0/4,096 · 0.621597558 | 0/1,024 · 0.218729451 | +| `noise_gaussian_noise_v2.sbs/gaussian_noise` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, tile_offset=(0.17,0.29) | 0/4,096 · 195 | 0/4,096 · 50135 | 0/4,096 · 0.897216797 | 0/4,096 · 0.897545502 | 0/1,024 · 0.339412361 | +| `noise_gaussian_spots_1.sbs/gaussian_spots_1` · output (LUM) | checked | none
scale=2, disorder=0.37 | 28/4,096 · 177 | 0/4,096 · 45368 | 0/4,096 · 0.691833496 | 0/4,096 · 0.69227396 | 2/1,024 · 1.04430412 | +| `noise_gaussian_spots_1_v2.sbs/gaussian_spots_1` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, tile_offset=(0.17,0.29) | 23/4,096 · 215 | 0/4,096 · 55101 | 0/4,096 · 0.840454102 | 0/4,096 · 0.84077388 | 0/1,024 · 1.1514894 | +| `noise_gaussian_spots_2.sbs/gaussian_spots_2` · output (LUM) | checked | none
scale=2, disorder=0.37 | 37/4,096 · 149 | 0/4,096 · 38197 | 0/4,096 · 0.582519531 | 0/4,096 · 0.582842484 | 0/1,024 · 0.877645788 | +| `noise_gaussian_spots_2_v2.sbs/gaussian_spots_2` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, tile_offset=(0.17,0.29) | 20/4,096 · 253 | 0/4,096 · 65028 | 1/4,096 · 1.05671692 | 0/4,096 · 1.05743184 | 0/1,024 · 0.613122775 | +| `noise_liquid.sbs/liquid` · output (LUM) | checked | none
scale=2, disorder=0.37, warp_intensity=0.4 | 0/4,096 · 154 | 0/4,096 · 39615 | 0/4,096 · 0.604248047 | 0/4,096 · 0.604488969 | 0/1,024 · 0.2390953 | +| `noise_messy_fibers_1.sbs/messy_fibers_1` · output (LUM) | checked | none
scale=2, disorder=0.37, angle=0.125, angle_random=0.2, lines_number=8 | 7/4,096 · 252 | 0/4,096 · 64724 | 1/4,096 · 0.987136841 | 0/4,096 · 0.987619292 | 0/1,024 · 0.988889564 | +| `noise_messy_fibers_1_v2.sbs/messy_fibers_1` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, angle=0.125, angle_random=0.2, tile_offset=(0.17,0.29), lines_number=8 | 7/4,096 · 232 | 0/4,096 · 59482 | 0/4,096 · 0.907287598 | 0/4,096 · 0.907628112 | 0/1,024 · 0.806026489 | +| `noise_messy_fibers_2.sbs/messy_fibers_2` · output (LUM) | checked | none
scale=2, disorder=0.37, angle=0.125, angle_random=0.2, links_number=8 | 20/4,096 · 255 | 10/4,096 · 65535 | 2/4,096 · 2.58886719 | 0/4,096 · 2.58883643 | 0/1,024 · 2.50310458 | +| `noise_messy_fibers_2_v2.sbs/messy_fibers_2` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, angle=0.125, angle_random=0.2, tile_offset=(0.17,0.29), lines_number=8 | 40/4,096 · 255 | 33/4,096 · 65535 | 0/4,096 · 2.7121582 | 0/4,096 · 2.71319878 | 0/1,024 · 2.26003554 | +| `noise_messy_fibers_3.sbs/messy_fibers_3` · output (LUM) | checked | none
scale=2, disorder=0.37, angle=0.125, angle_random=0.2, color_random=0.25 | 29/4,096 · 255 | 21/4,096 · 65535 | 21/4,096 · 1.1640625 | 21/4,096 · 1.1643126 | 2/1,024 · 1.16184852 | +| `noise_messy_fibers_3_v2.sbs/messy_fibers_3` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, angle=0.125, angle_random=0.2, luminance_random=0.25, tile_offset=(0.17,0.29) | 0/4,096 · 255 | 0/4,096 · 65535 | 0/4,096 · 1.16308594 | 0/4,096 · 1.1639756 | 0/1,024 · 1.11929643 | +| `noise_microscope_view.sbs/microscope_view` · output (LUM) | checked | none
scale=2, disorder=0.37, warp_intensity=0.4 | 0/4,096 · 197 | 0/4,096 · 50531 | 0/4,096 · 0.770599365 | 0/4,096 · 0.771053366 | 0/1,024 · 0.152535662 | +| `noise_moisture_noise.sbs/moisture_noise` · output (LUM) | checked | none
scale=2, disorder=0.37, pattern_size=(0.8,1.2), pattern_angle=0.125, pattern_angle_random=0.2, global_opacity=0.8 | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_moisture_noise_1_v2.sbs/moisture_noise_1` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, pattern_size=(0.8,1.2), tile_offset=(0.17,0.29), pattern_angle=0.125, pattern_angle_random=0.2, global_opacity=0.8 | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_moisture_noise_2.sbs/moisture_noise_2` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, disorder_anisotropy=0.3, disorder_anisotropy_angle=0.125, pattern_size=(0.8,1.2), tile_offset=(0.17,0.29), pattern_angle=0.125, pattern_angle_random=0.2, global_opacity=0.8 | execution budget | execution budget | execution budget | execution budget | execution budget | +| `noise_perlin_noise.sbs/perlin_noise` · output (LUM) | checked | none
scale=2, disorder=0.37 | 176/4,096 · 15 | 2/4,096 · 3818 | 11/4,096 · 0.0581054688 | 1/4,096 · 0.0582590103 | 0/1,024 · 0.266117394 | +| `noise_perlin_noise_v2.sbs/perlin_noise` · output (LUM) | checked | none
scale=2, disorder=0.37, disorder_speed=0.6, tile_offset=(0.17,0.29) | 11/4,096 · 76 | 0/4,096 · 19520 | 0/4,096 · 0.297607422 | 0/4,096 · 0.29785502 | 0/1,024 · 0.236935616 | +| `noise_plasma.sbs/plasma` · output (LUM) | checked | none
scale=2, disorder=0.37 | 164/4,096 · 44 | 0/4,096 · 11163 | 0/4,096 · 0.170257568 | 0/4,096 · 0.170336485 | 0/1,024 · 0.22627604 | +| `noise_upscale_1.sbs/noise_upscale_1` · Noise_ResolutionX2 (LUM) | checked | Source=offset-gray-128
Offset1X=0.17, Offset1Y=0.23, Offset2X=-0.125, Offset2Y=0.375 | 12,334/16,384 · 20 | 10,336/16,384 · 5184 | 10,658/16,384 · 0.0791015625 | 10,145/16,384 · 0.0791027546 | 2,759/4,096 · 0.0647692829
Source=gray1 | +| `noise_upscale_2.sbs/noise_upscale_2` · Noise_ResolutionX2_2 (LUM) | checked | Source=offset-gray-128
Offset1X=0.17, Offset1Y=0.23, Offset2X=-0.125, Offset2Y=0.375 | 13,079/16,384 · 12 | 12,706/16,384 · 2879 | 12,715/16,384 · 0.0439453125 | 10,841/16,384 · 0.04392156 | 2,468/4,096 · 0.0373333395
Source=gray1 | +| `noise_upscale_3.sbs/noise_upscale_3` · Noise_ResolutionX2_3 (LUM) | checked | Mask=blend-mask-128, Source=levels-range-64
defaults | 16,384/16,384 · 0 | 16,375/16,384 · 1 | 15,176/16,384 · 0.00048828125 | 12,398/16,384 · 5.96046448e-08 | 156/4,096 · 0.00392246246
Mask=gray1, Source=gray2 | +| `noise_voronoi.sbs/3d_voronoi` · output (LUM) | checked | position=blend-fg-alpha-128
scale=2, disorder=0.37 | 4,096/4,096 · 0 | 4,095/4,096 · 1 | 4,096/4,096 · 0 | 3,462/4,096 · 5.96046448e-08 | 850/1,024 · 5.96046448e-08
position=color1 | +| `noise_voronoi.sbs/3d_voronoi_fractal` · output (LUM) | checked | position=blend-fg-alpha-128
scale=2, disorder=0.37, roughness=0.6, global_opacity=0.8, min_level=1, max_level=3 | 4,096/4,096 · 0 | 4,072/4,096 · 1 | 4,096/4,096 · 0 | 14/4,096 · 1.78813934e-07 | 4/1,024 · 1.78813934e-07
position=color1 | +| `noise_voronoi.sbs/voronoi` · output (LUM) | checked | none
scale=2, disorder=(0.37,0.259,0.111) | 4,096/4,096 · 0 | 4,093/4,096 · 1 | 4,096/4,096 · 0 | 3,584/4,096 · 5.96046448e-08 | 887/1,024 · 5.96046448e-08 | +| `noise_voronoi.sbs/voronoi_fractal` · output (LUM) | checked | none
scale=2, disorder=(0.37,0.259,0.111), roughness=0.6, global_opacity=0.8, min_level=1, max_level=3 | 4,096/4,096 · 0 | 4,067/4,096 · 1 | 4,092/4,096 · 0.00048828125 | 11/4,096 · 2.38418579e-07 | 4/1,024 · 1.78813934e-07 | +| `non_square_transform.sbs/non_square_transform` · output (RGBA) | gray | input=blend-fg-alpha-128
tile_mode=1, tile=(2,3), offset=(0.125,-0.25), rotation=0.125, tile_safe_rotation=false | 4,038/4,096 · 1 | 3,960/4,096 · 235 | 3,960/4,096 · 0.00360107422 | 3,960/4,096 · 0.00358587503 | 1,004/1,024 · 0.00372320414
input=color1 | +| `non_square_transform.sbs/non_square_transform_greyscale` · output (LUM) | gray | input=offset-gray-128
tile_mode=1, tile=(2,3), offset=(0.125,-0.25), rotation=0.125, tile_safe_rotation=false | 4,063/4,096 · 1 | 3,960/4,096 · 195 | 3,964/4,096 · 0.0029296875 | 3,960/4,096 · 0.00297552347 | 1,004/1,024 · 0.00329594314
input=gray1 | +| `non_uniform_blur.sbs/non_uniform_blur_grayscale_sample` · Output (LUM) | angle | Effect=levels-range-64, Source=offset-gray-128
Intensity=0.7, Samples=8, Angle=0.125, Asymmetry=0.25, Anisotropy=0.5, InnerRotation=0.2 | 2,353/4,096 · 3 | 2,353/4,096 · 771 | 2,353/4,096 · 0.01171875 | 2,353/4,096 · 0.0117647052 | 669/1,024 · 0.00784315169
Effect=gray1, Source=gray2 | +| `non_uniform_blur.sbs/non_uniform_blur_sample` · Output (RGBA) | angle | Effect=levels-range-64, Source=blend-fg-alpha-128
Intensity=0.7, Samples=8, Angle=0.125, Asymmetry=0.25, Anisotropy=0.5, InnerRotation=0.2 | 1,024/4,096 · 3 | 1,024/4,096 · 771 | 1,024/4,096 · 0.0119628906 | 1,024/4,096 · 0.011764735 | 247/1,024 · 0.00784315169
Effect=gray1, Source=color2 | +| `non_uniform_rotation.sbs/non_uniform_rotation_color` · output (RGBA) | value | input=blend-bg-alpha-128, rotation_map=offset-gray-128, rotation_pivot_map=blend-bg-alpha-128
rotation_angle_multiplier=0.5, rotation_angle_offset=0.125, pivot_position=(0.3,0.7) | 4,095/4,096 · 1 | 4,092/4,096 · 103 | 4,092/4,096 · 0.00170898438 | 4,092/4,096 · 0.00157165527 | 1,024/1,024 · 0
input=color1, rotation_map=gray2, rotation_pivot_map=color3 | +| `non_uniform_rotation.sbs/non_uniform_rotation_grayscale` · output (LUM) | value | input=offset-gray-128, rotation_map=levels-range-64, rotation_pivot_map=blend-bg-alpha-128
rotation_angle_multiplier=0.5, rotation_angle_offset=0.125, pivot_position=(0.3,0.7) | 4,096/4,096 · 0 | 4,092/4,096 · 130 | 4,093/4,096 · 0.00244140625 | 4,092/4,096 · 0.00198370218 | 1,024/1,024 · 0
input=gray1, rotation_map=gray2, rotation_pivot_map=color3 | +| `normal_normalise.sbs/normal_normalise` · Normalise (RGBA) | checked | Normal=curved-normal-128
defaults | 4,032/4,096 · 1 | 4,024/4,096 · 193 | 4,032/4,096 · 0.00305175781 | 3,216/4,096 · 0.00293892622 | 862/1,024 · 1.1920929e-07
Normal=normal | +| `normal_sobel.sbs/normal_sobel` · output (RGBA) | checked | input=offset-gray-128
intensity=0.6, normal_format=1 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 2,975/4,096 · 1.1920929e-07 | 1,015/1,024 · 1.1920929e-07
input=gray1 | +| `normal_sobel.sbs/normal_sobel_2` · output (RGBA) | checked | input=offset-gray-128
intensity=0.6, normal_format=1 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 2,975/4,096 · 1.1920929e-07 | 1,014/1,024 · 1.1920929e-07
input=gray1 | +| `normal_to_height_2.sbs/normal_to_height` · height (LUM) | checked | Input=curved-normal-128
normal_format=1, Relief_Balance=(0.2,0.6,0.8), global_opacity=0.6 | 2,823/4,096 · 69 | 2,752/4,096 · 17727 | 2,753/4,096 · 0.270507812 | 2,752/4,096 · 0.270496666 | 270/1,024 · 0.305134654
Input=normal | +| `normal_to_height_hq.sbs/base_algorithm_height_distance` · output (LUM) | bridge | input=offset-gray-128
intensity=0.6, light_angle=0.3, light_offset=0.4, detail_balance=0.6 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `normal_transform.sbs/normal_transform` · output (RGBA) | angle | input=curved-normal-128
offset=(0.125,-0.25), normal_format=1, matrix22=(0,-1,1,0), handle_scale_and_skew_transformation=true | 4,096/4,096 · 0 | 4,095/4,096 · 1 | 4,096/4,096 · 0 | 3,626/4,096 · 1.1920929e-07 | 868/1,024 · 1.1920929e-07
input=normal | +| `panorama_gradients.sbs/panorama_gradient_2_points` · output (RGBA) | checked | none
point_1_position=(0.2,0.3), point_2_position=(0.8,0.6), point_1_contrast=0.3 | 4,096/4,096 · 0 | 4,045/4,096 · 1 | 4,088/4,096 · 0.00048828125 | 49/4,096 · 4.17232513e-07 | 19/1,024 · 4.76837158e-07 | +| `panorama_gradients.sbs/panorama_gradient_linear` · output (RGBA) | checked | none
point_position=(0.3,0.4), top_color=(0.2,0.7,0.4), bottom_color=(0.8,0.1,0.3), contrast=0.25 | 4,096/4,096 · 0 | 4,070/4,096 · 1 | 4,091/4,096 · 0.000122070312 | 0/4,096 · 1.78813934e-07 | 0/1,024 · 1.93715096e-07 | +| `panorama_nadir_extract.sbs/nadir_extract` · output (RGBA) | value | input=blend-fg-alpha-128
rotation=0.125, scale=3, output_gamma=1 | 4,096/4,096 · 0 | 4,094/4,096 · 34 | 4,094/4,096 · 0.00048828125 | 4,094/4,096 · 0.000518798828 | 1,024/1,024 · 0
input=color1 | +| `panorama_nadir_patch.sbs/panorama_nadir_patch` · output (RGBA) | angle | input=blend-fg-alpha-128, mask_input=levels-range-64
show_frames_helper=false, frame_thickness=0.1, patch_scale=0.5, patch_size=(0.7,1.2), patch_rotation=0.125, patch_hardness=0.8, source_position=(0.6,0.7), patch_position=(0.4,0.8) | 4,096/4,096 · 0 | 4,085/4,096 · 30 | 4,095/4,096 · 0.00048828125 | 4,022/4,096 · 0.000457763672 | 1,004/1,024 · 4.85777855e-06
input=color1, mask_input=gray2 | +| `panorama_physical_sun_sky.sbs/Impl/GetOneParam` · output (float3) | checked | input=blend-fg-alpha-128
elevationK=0.5, turbidity=2, albedo=0.5, paramIndex=2 | 0/1 · 1.1920929e-07 | 0/1 · 1.1920929e-07 | 0/1 · 1.1920929e-07 | 0/1 · 1.1920929e-07 | 0/1 · 7.51018524e-06
input=color1 | +| `panorama_position.sbs/panorama_3d_position` · output (RGBA) | checked | none
up_vector=1 | 4,096/4,096 · 0 | 4,086/4,096 · 1 | 4,096/4,096 · 0 | 292/4,096 · 2.38418579e-07 | 43/1,024 · 2.38418579e-07 | +| `panorama_rotation.sbs/panorama_rotation` · output (RGBA) | angle | input=blend-fg-alpha-128
rotation=0.125, direction_angle=0.125, pre_rotation_around_pole=0.125, post_rotation_around_pole=-0.125 | 4,090/4,096 · 1 | 4,083/4,096 · 63 | 4,083/4,096 · 0.0009765625 | 4,083/4,096 · 0.000961303711 | 1,023/1,024 · 0.0012512207
input=color1 | +| `panorama_shape.sbs/panorama_line_light` · output (RGBA) | checked | background_image_input=blend-fg-alpha-128, pattern_image_input=levels-range-64, shape_image_input=blend-bg-alpha-128
point_2_position=(0.8,0.6,1), up_vector=1, shape_color=(0.2,0.6,0.8), shape_exposure=2, line_thickness=0.2 | 4,093/4,096 · 1 | 4,081/4,096 · 4 | 4,093/4,096 · 0.00048828125 | 3,608/4,096 · 6.66379929e-05 | 904/1,024 · 6.27338886e-06
background_image_input=color1, pattern_image_input=gray2, shape_image_input=color3 | +| `panorama_shape.sbs/panorama_plane_light` · output (RGBA) | value | background_image_input=blend-fg-alpha-128, pattern_image_input=levels-range-64, shape_image_input=blend-bg-alpha-128
up_vector=1, shape_color=(0.2,0.6,0.8), shape_exposure=2, plane_scale=0.8, plane_size=(0.7,1.2), plane_rotation=(0.125,0.25,0) | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
background_image_input=color1, pattern_image_input=gray2, shape_image_input=color3 | +| `panorama_shape.sbs/panorama_shape` · output (RGBA) | angle | input=blend-fg-alpha-128
offset=(0.125,-0.25), matrix22=(0,-1,1,0), shape=1, shape_color=(0.2,0.6,0.8), shape_intensity=2, hotspot_intensity=3, hotspot_size=0.3, hotspot_falloff=0.7 | 4,096/4,096 · 0 | 4,083/4,096 · 1 | 4,092/4,096 · 0.00048828125 | 3,804/4,096 · 1.07288361e-05 | 941/1,024 · 6.31809235e-06
input=color1 | +| `panorama_shape.sbs/panorama_shape_2` · output (RGBA) | angle | background_image_input=blend-bg-alpha-128, shape_image_input=blend-fg-alpha-128
offset=(0.125,-0.25), matrix22=(0,-1,1,0), shape=1, shape_color=(0.2,0.6,0.8), hotspot_size=0.3, hotspot_falloff=0.7, shape_exposure=2 | 4,096/4,096 · 0 | 4,081/4,096 · 1 | 4,094/4,096 · 7.62939453e-06 | 2,734/4,096 · 4.9829483e-05 | 680/1,024 · 3.71932983e-05
background_image_input=color1, shape_image_input=color2 | +| `panorama_shape.sbs/panorama_sphere_light` · output (RGBA) | checked | background_image_input=blend-fg-alpha-128, sphere_image_input=blend-bg-alpha-128
up_vector=1, sphere_world_position=(1,2,3), sphere_uv_position=(0.3,0.6), sphere_radius=1, sphere_exposure=2 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,069/4,096 · 1.90734863e-06 | 1,018/1,024 · 1.90734863e-06
background_image_input=color1, sphere_image_input=color2 | +| `panorama_shape.sbs/panorama_spot` · output (RGBA) | checked | input=blend-fg-alpha-128
scale=3, shape_color=(0.2,0.6,0.8), shape_intensity=2, hotspot_intensity=3, hotspot_size=0.3, hotspot_falloff=0.7, position=(0.3,0.6) | 4,095/4,096 · 1 | 4,056/4,096 · 1 | 4,089/4,096 · 0.00048828125 | 2,826/4,096 · 2.76565552e-05 | 705/1,024 · 3.71932983e-05
input=color1 | +| `panorama_straighten_horizon.sbs/panorama_straighten_horizon` · output (RGBA) | angle | input=blend-fg-alpha-128
enable_horizon_correction=true, horizon_p1=(0.2,0.4), horizon_p2=(0.7,0.6), horizontal_rotation=0.125 | 0/4,096 · 225 | 0/4,096 · 57829 | 0/4,096 · 0.882263184 | 0/4,096 · 0.882413983 | 0/1,024 · 0.937407508
input=color1 | +| `paper_path.sbs/paper_path` · Paper_Path (LUM) | checked | none
Pattern_size_width=130, Pattern_size_height=80, Disorder=0.2 | 2,334/4,096 · 255 | 2,297/4,096 · 65535 | 45/4,096 · 1.16601562 | 18/4,096 · 1.1666851 | 7/1,024 · 0.0057874918 | +| `parquet_1.sbs/parquet_1` · Parquet (LUM) | checked | none
Tiling=2, Luminance_Variation=0.3 | 4,016/4,096 · 106 | 4,016/4,096 · 27242 | 4,016/4,096 · 0.415527344 | 4,016/4,096 · 0.41568628 | 1,008/1,024 · 0.43921569 | +| `paths_tools.sbs/Impl/compute_paths_lengths` · lengths (LUM) | loop | paths=original-paths-seven
passthrough=true, interm_lengths=true, scale=(0.7,1.2) | 1/1 · 0 | 1/1 · 0 | 1/1 · 0 | 1/1 · 0 | loop result type
paths=original-paths-seven | +| `paths_tools.sbs/Impl/facets_to_paths_impl_link_template` · output (RGBA) | value | input=original-facets-gradient
radius=2, init=true, foreach=2, finally=(0.2,0.4,0.6,0.8) | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=original-facets-gradient | +| `paths_tools.sbs/Impl/facets_to_paths_impl_stitch_template` · output (RGBA) | checked | input=original-facets-gradient
radius=2, init=true, foreach=2, finally=(0.2,0.4,0.6,0.8) | 0/4,096 · 204 | 0/4,096 · 52428 | 0/4,096 · 0.799804688 | 0/4,096 · 0.800000012 | 0/1,024 · 0.800000012
input=original-facets-gradient | +| `paths_tools.sbs/Impl/mask_to_facets` · output (RGBA) | value | mask=original-mask-gradient-16
threshold=0.3 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
mask=gray1 | +| `paths_tools.sbs/Impl/sort_by_blue` · output (RGBA) | loop | input=original-rgba-16
passthrough=true, count=32 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | loop result type
input=color1 | +| `paths_tools.sbs/paths_polygon` · paths (RGBA) | checked | none
nbSides=7 | 256/256 · 0 | 254/256 · 1 | 256/256 · 0 | 250/256 · 5.60283661e-06 | 250/256 · 5.60283661e-06 | +| `paths_tools.sbs/paths_trace` · tracing (RGBA) | checked | background=original-rgba-16, paths=original-paths-seven
trace_corners=true, trace_vertices=true, thickness=1.5 | 3,686/4,096 · 239 | 2,192/4,096 · 61469 | 3,411/4,096 · 1.37158203 | 0/4,096 · 1.37210912 | 890/1,024 · 1.75791217
background=color1, paths=original-paths-seven | +| `paths_tools.sbs/vertex_processor` · paths (RGBA) | checked | input_1=original-rgba-16, input_2=original-mask-16, input_3=original-rgba-16, input_4=original-mask-16, input_5=original-rgba-16, input_6=original-mask-16, input_7=original-rgba-16, input_8=original-mask-16, paths=original-paths-seven
fetchPrevCount=1, fetchNextCount=1, imageInputCount=2, perVertex=(0.25,0.75) | 3,869/4,096 · 191 | 3,869/4,096 · 49151 | 3,857/4,096 · 0.75 | 3,791/4,096 · 0.75 | 968/1,024 · 0.75
input_1=color1, input_2=gray2, input_3=color3, input_4=gray4, input_5=color5, input_6=gray6, input_7=color7, input_8=gray8, paths=original-paths-seven | +| `paths_tools.sbs/vertex_processor_simple` · paths (RGBA) | checked | input_1=original-rgba-16, input_2=original-mask-16, input_3=original-rgba-16, input_4=original-mask-16, paths=original-paths-seven
imageInputCount=2, perVertex=(0.25,0.75) | 3,869/4,096 · 191 | 3,869/4,096 · 49151 | 3,857/4,096 · 0.75 | 3,791/4,096 · 0.75 | 968/1,024 · 0.75
input_1=color1, input_2=gray2, input_3=color3, input_4=gray4, paths=original-paths-seven | +| `pattern_alveolus.sbs/alveolus` · output (LUM) | value | none
Tiling=2, Gradient_Filled_Cells=true, Interstice_Width=0.15 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0 | +| `pattern_arc_pavement.sbs/arc_pavement` · output (LUM) | angle | pattern_input=offset-gray-128
scale=2, pattern_amount=7, pattern_amount_random=0.2, arcs_amount=8, pattern=3, pattern_variation=0.3, pattern_scale=0.8, pattern_width=0.6, pattern_height=0.7, pattern_width_random=0.2, color_random=0.3 | 3,218/4,096 · 254 | 3,207/4,096 · 65269 | 3,210/4,096 · 0.995605469 | 3,207/4,096 · 0.99593389 | 849/1,024 · 0.999720931
pattern_input=gray1 | +| `pattern_brick_1.sbs/brick_1` · output (LUM) | sampler | none
scale=2, edge_smoothness=0.3, interstice_width=0.2 | 2,688/4,096 · 65 | 2,688/4,096 · 16641 | 2,688/4,096 · 0.25390625 | 2,688/4,096 · 0.253936917 | 672/1,024 · 0.12161243 | +| `pattern_brick_2.sbs/brick_2` · output (LUM) | sampler | none
scale=2, edge_smoothness=0.3, interstice_width=0.2 | 2,560/4,096 · 30 | 2,560/4,096 · 7601 | 2,560/4,096 · 0.116210938 | 2,560/4,096 · 0.115979761 | 384/1,024 · 0.187185353 | +| `pattern_cube_3d.sbs/cube_3d` · output (LUM) | sampler | none
scale=0.35, orientation_offset=(0.17,0.32), size=(0.7,1,1.3) | 4,096/4,096 · 0 | 4,087/4,096 · 1 | 4,096/4,096 · 0 | 1,653/4,096 · 2.98023224e-07 | 432/1,024 · 2.98023224e-07 | +| `pattern_cube_3d.sbs/cube_3d_gbuffers` · position (RGBA) | sampler | none
scale=0.35, orientation_offset=(0.17,0.32), size=(0.7,1,1.3) | 4,096/4,096 · 0 | 4,086/4,096 · 1 | 4,064/4,096 · 0.00048828125 | 1,342/4,096 · 2.98023224e-07 | 330/1,024 · 2.38418579e-07 | +| `pattern_cube_3d.sbs/cube_3d_gbuffers` · normal (RGBA) | sampler | none
scale=0.35, orientation_offset=(0.17,0.32), size=(0.7,1,1.3) | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0 | +| `pattern_cube_3d.sbs/cube_3d_gbuffers` · depth (LUM) | sampler | none
scale=0.35, orientation_offset=(0.17,0.32), size=(0.7,1,1.3) | 4,096/4,096 · 0 | 4,087/4,096 · 1 | 4,096/4,096 · 0 | 1,653/4,096 · 2.98023224e-07 | 432/1,024 · 2.98023224e-07 | +| `pattern_cube_3d.sbs/cube_3d_gbuffers` · uv (RGBA) | sampler | none
scale=0.35, orientation_offset=(0.17,0.32), size=(0.7,1,1.3) | 4,096/4,096 · 0 | 4,090/4,096 · 1 | 4,093/4,096 · 0.000244140625 | 1,277/4,096 · 2.98023224e-07 | 324/1,024 · 2.38418579e-07 | +| `pattern_fibers_1.sbs/fibers_1` · output (LUM) | sampler | none
Tiling=2 | 1,872/4,096 · 8 | 56/4,096 · 2010 | 300/4,096 · 0.0302734375 | 56/4,096 · 0.0306706131 | 0/1,024 · 0.0354467034 | +| `pattern_fibers_2.sbs/fibers_2` · output (LUM) | sampler | none
Tiling=2 | 1,424/4,096 · 11 | 160/4,096 · 2879 | 464/4,096 · 0.0439453125 | 160/4,096 · 0.0439307094 | 0/1,024 · 0.0511024594 | +| `pattern_gaussian_1.sbs/gaussian_1` · output (LUM) | value | none
Tiling=2 | 4,096/4,096 · 0 | 4,064/4,096 · 1 | 4,096/4,096 · 0 | 4,064/4,096 · 1.52587891e-05 | 1,024/1,024 · 0 | +| `pattern_gaussian_2.sbs/gaussian_2` · output (LUM) | value | none
Tiling=2 | 4,096/4,096 · 0 | 4,032/4,096 · 1 | 4,096/4,096 · 0 | 4,032/4,096 · 1.52587891e-05 | 1,024/1,024 · 0 | +| `pattern_mesh_1.sbs/mesh_1` · output (LUM) | sampler | none
Tiling=2, Rotate_45_Degrees=true | 16/4,096 · 225 | 0/4,096 · 57804 | 0/4,096 · 0.882080078 | 0/4,096 · 0.882032499 | 0/1,024 · 0.856000617 | +| `pattern_mesh_2.sbs/mesh_2` · output (LUM) | sampler | none
Tiling=2, Rotation=true | 96/4,096 · 255 | 80/4,096 · 65535 | 80/4,096 · 1 | 80/4,096 · 1 | 48/1,024 · 0.984206913 | +| `pattern_polygon_2.sbs/polygon_2` · output (LUM) | sampler | none
Tiling=2, Scale=0.8, Rotation=0.125, Sides=5, Curve=0.2, Gradient=0.6, InvertGradient=true | 4,080/4,096 · 1 | 3,160/4,096 · 3 | 3,992/4,096 · 0.00048828125 | 3,160/4,096 · 4.57912683e-05 | 768/1,024 · 3.05175781e-05 | +| `pattern_shape.sbs/hemisphere` · output (LUM) | sampler | none
scale=0.7, size_xy=(0.7,1.2), angle=0.125 | 4,096/4,096 · 0 | 4,091/4,096 · 1 | nonfinite cook | nonfinite cook | 201/1,024 · 4.38094139e-06² | +| `pattern_shape.sbs/shape_base` · output (LUM) | sampler | none
scale=0.7, pattern=3, pattern_specific=0.3, size_xy=(0.7,1.2), angle=0.125 | 4,096/4,096 · 0 | 4,072/4,096 · 1 | 4,088/4,096 · 0.00048828125 | 2,910/4,096 · 1.43051147e-06 | 717/1,024 · 1.37090683e-06 | +| `pattern_splatter_circular.sbs/splatter_circular` · Splatter_Circular (LUM) | angle | background=levels-range-64, pattern_input_1=offset-gray-128, pattern_input_2=levels-range-64, pattern_input_3=levels-range-64, pattern_input_4=levels-range-64, pattern_input_5=levels-range-64, pattern_input_6=levels-range-64
pattern_amount=7, pattern_amount_random=0.2, pattern=3, pattern_scale=0.8, ring_amount=2, radius=0.35, radius_random=0.15, angle_random=0.2, spiral_factor=0.1, pattern_rotation_random=0.3, pattern_size=(0.7,1.2) | 3,986/4,096 · 223 | 3,986/4,096 · 57311 | 3,986/4,096 · 0.874511719 | 3,986/4,096 · 0.874509797 | 976/1,024 · 0.976470588
background=gray1, pattern_input_1=gray2, pattern_input_2=gray3, pattern_input_3=gray4, pattern_input_4=gray5, pattern_input_5=gray6, pattern_input_6=gray7 | +| `pattern_splatter_circular.sbs/splatter_circular_color` · Splatter_Circular (RGBA) | angle | background=blend-bg-alpha-128, pattern_input_1=blend-fg-alpha-128, pattern_input_2=blend-bg-alpha-128, pattern_input_3=blend-bg-alpha-128, pattern_input_4=blend-bg-alpha-128, pattern_input_5=blend-bg-alpha-128, pattern_input_6=blend-bg-alpha-128
pattern_amount=7, pattern_amount_random=0.2, pattern=3, pattern_scale=0.8, ring_amount=2, radius=0.35, radius_random=0.15, angle_random=0.2, spiral_factor=0.1, pattern_rotation_random=0.3, pattern_size=(0.7,1.2) | 3,986/4,096 · 254 | 3,986/4,096 · 65278 | 3,986/4,096 · 0.996078491 | 3,986/4,096 · 0.996078431 | 976/1,024 · 0.996078431
background=color1, pattern_input_1=color2, pattern_input_2=color3, pattern_input_3=color4, pattern_input_4=color5, pattern_input_5=color6, pattern_input_6=color7 | +| `pattern_stripes.sbs/stripes` · Stripes (LUM) | value | none
Stripes=7, Width=0.35, Softness=0.2, Shift=5, Align=1 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0 | +| `pattern_tile_generator.sbs/tile_generator` · output (LUM) | value | background=offset-gray-128, pattern_input_1=levels-range-64, pattern_input_2=levels-range-64, pattern_input_3=levels-range-64, pattern_input_4=levels-range-64, pattern_input_5=levels-range-64, pattern_input_6=levels-range-64
scale=2, pattern=3, pattern_specific=(0.3,0), x_amount=7, y_amount=3, pattern_rotation_random=0.3, pattern_size=(0.7,1.2), rotation=0.125 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
background=gray1, pattern_input_1=gray2, pattern_input_2=gray3, pattern_input_3=gray4, pattern_input_4=gray5, pattern_input_5=gray6, pattern_input_6=gray7 | +| `pattern_tile_generator.sbs/tile_generator_color` · output (RGBA) | sampler | background=blend-bg-alpha-128, pattern_input_1=blend-fg-alpha-128, pattern_input_2=blend-bg-alpha-128, pattern_input_3=blend-bg-alpha-128, pattern_input_4=blend-bg-alpha-128, pattern_input_5=blend-bg-alpha-128, pattern_input_6=blend-bg-alpha-128
scale=2, pattern=3, pattern_specific=(0.3,0), x_amount=7, y_amount=3, pattern_rotation_random=0.3, pattern_size=(0.7,1.2), rotation=0.125 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 0/4,096 · 4.953125 | 0/4,096 · 4.95686245 | 0/1,024 · 4.99215698
background=color1, pattern_input_1=color2, pattern_input_2=color3, pattern_input_3=color4, pattern_input_4=color5, pattern_input_5=color6, pattern_input_6=color7 | +| `pattern_tile_random.sbs/tile_random` · output (LUM) | sampler | background_input=levels-range-64, pattern_input=offset-gray-128
pattern=3, pattern_specific=0.3, x_amount=7, y_amount=3, pattern_rotation_random=0.3, shape_rotation=0.125 | 3,030/4,096 · 223 | 3,030/4,096 · 57311 | 3,030/4,096 · 1 | 3,030/4,096 · 1.00000006 | 746/1,024 · 1.00000006
background_input=gray1, pattern_input=gray2 | +| `pattern_tile_random.sbs/tile_random_color` · output (RGBA) | sampler | background_input=blend-fg-alpha-128, pattern_input=blend-bg-alpha-128
pattern=3, pattern_specific=0.3, x_amount=7, y_amount=3, pattern_rotation_random=0.3, shape_rotation=0.125 | 3,030/4,096 · 250 | 3,030/4,096 · 64250 | 2,440/4,096 · 1 | 2,440/4,096 · 1.00000006 | 598/1,024 · 1.00000006
background_input=color1, pattern_input=color2 | +| `pattern_tile_random_2.sbs/tile_random_2` · output (LUM) | sampler | bevel_distance_map=levels-range-64, mask_map=levels-range-64, random_size_map=offset-gray-128, random_slant_map=levels-range-64, round_corners_radius_map=levels-range-64
amount_x=7, amount_y=3, random_size_multiplier=0.7, round_corners_radius=0.1, shape_rotation=0.125, random_position_multiplier=0.5 | 1,751/4,096 · 255 | 1,746/4,096 · 65535 | 1,746/4,096 · 1 | 1,746/4,096 · 1 | 363/1,024 · 1
bevel_distance_map=gray1, mask_map=gray2, random_size_map=gray3, random_slant_map=gray4, round_corners_radius_map=gray5 | +| `pattern_tile_random_2.sbs/tile_random_2` · flood_fill_data1 (RGBA) | sampler | bevel_distance_map=levels-range-64, mask_map=levels-range-64, random_size_map=offset-gray-128, random_slant_map=levels-range-64, round_corners_radius_map=levels-range-64
amount_x=7, amount_y=3, random_size_multiplier=0.7, round_corners_radius=0.1, shape_rotation=0.125, random_position_multiplier=0.5 | 1,194/4,096 · 253 | 1,194/4,096 · 64954 | 1,194/4,096 · 0.990722656 | 1,194/4,096 · 0.991127551 | 258/1,024 · 0.996064007
bevel_distance_map=gray1, mask_map=gray2, random_size_map=gray3, random_slant_map=gray4, round_corners_radius_map=gray5 | +| `pattern_triangle_grid.sbs/triangle_grid_base` · output (RGBA) | sampler | color_input=blend-bg-alpha-128, height=offset-gray-128, vector_map=blend-bg-alpha-128
x_amount=7, y_amount=3, random_position_multiplier=0.5, height_random=0.5, rotation=0.125, rotation_disorder=0.3 | 4,095/4,096 · 1 | 4,088/4,096 · 1 | 4,040/4,096 · 0.00048828125 | 2,649/4,096 · 5.96046448e-07 | 641/1,024 · 4.47034836e-07
color_input=color1, height=gray2, vector_map=color3 | +| `pattern_weave_1.sbs/weave_1` · output (LUM) | sampler | none
Tiling=2, rotate_45_degrees=true | 0/4,096 · 255 | 0/4,096 · 65535 | 0/4,096 · 1 | 0/4,096 · 1 | 0/1,024 · 1 | +| `pattern_weave_2.sbs/weave_2` · output (LUM) | sampler | none
scale=2, rotate_45_degrees=true, Disorder=0.25 | 166/4,096 · 255 | 108/4,096 · 65535 | 109/4,096 · 1 | 108/4,096 · 1 | 0/1,024 · 0.860593565 | +| `pavement_1.sbs/pavement_1` · Pavement (LUM) | sampler | none
Roudness=0.75 | 368/4,096 · 255 | 368/4,096 · 65535 | 368/4,096 · 1 | 368/4,096 · 1 | 0/1,024 · 0.718337655 | +| `pbr_render.sbs/PBR_render_mapping_color` · output (RGBA) | bridge | texture=blend-fg-alpha-128, uv=position-128
defaults | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `pbr_render.sbs/PBR_render_mapping_grayscale` · output (RGBA) | bridge | texture=offset-gray-128, uv=position-128
defaults | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `pbr_render.sbs/chroma_shift` · output (RGBA) | bridge | input=blend-fg-alpha-128
radius=2, angle=0.125 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `pbr_render.sbs/environment_map_rescale` · output (RGBA) | sampler | input=blend-bg-alpha-128
defaults | 512/4,096 · 155 | 0/4,096 · 39853 | 0/4,096 · 0.705078125 | 0/4,096 · 0.705963194 | 0/1,024 · 1.06516372
input=color1 | +| `pbr_render.sbs/get_max_coords/get_max_coord` · Maximum (float2) | scope | input=levels-range-64
defaults | 1/1 · 0 | 1/1 · 0 | 1/1 · 0 | 1/1 · 0 | separate root controls | +| `pbr_render.sbs/ibl_specular_contrib_anisotropic/panoramic_lod` · Diffuse (RGBA) | sampler | input=blend-bg-alpha-128
defaults | 4,092/4,096 · 1 | 1,127/4,096 · 1 | 3,587/4,096 · 0.00048828125 | 0/4,096 · 7.65919685e-06 | 7/1,024 · 1.1920929e-07
input=color1 | +| `pbr_render.sbs/position_to_normal` · output (RGBA) | sampler | input=blend-bg-alpha-128, position=position-128
shape=1, shape_scale=0.7, plane_size=(0.7,1.3), uv_tiling=2, sphere_uv_scale=(2,3), plane_uv_scale=(2,1), cylinder_uv_scale=(2,1), cylinder_length=1.5, uv_offset=(0.125,0.25), rotation=0.125, rotation_direction=0.2, rotation_around_direction=0.3, normal_format=1, recompute_normals=true | 3,226/4,096 · 9 | 1,062/4,096 · 2220 | 1,221/4,096 · 0.0338134766 | 0/4,096 · 0.0338821262 | 0/1,024 · 0.0451358557
input=color1, position=position | +| `pbr_render.sbs/raytrace_position` · output (RGBA) | sampler | blue_noise=levels-range-64, height=offset-gray-128, opacity=levels-range-64
shape=1, shape_scale=0.7, shape_position=(0.1,-0.2,0.3), plane_size=(0.7,1.3), displacement_intensity=0.2, uv_tiling=2, sphere_uv_scale=(2,3), plane_uv_scale=(2,1), cylinder_uv_scale=(2,1), cylinder_length=1.5, cylinder_radius=0.7, uv_offset=(0.125,0.25), rotation=0.125, rotation_direction=0.2, rotation_around_direction=0.3 | 3,696/4,096 · 253 | 3,607/4,096 · 64898 | 3,665/4,096 · 1.49023438 | 0/4,096 · 1.49027765 | 0/1,024 · 1.47207022
blue_noise=gray1, height=gray2, opacity=gray3 | +| `pbr_render.sbs/raytraced_irradiance_pass_8` · output (RGBA) | sampler | blue_noise=blend-bg-alpha-128, emissive=blend-bg-alpha-128, environment=hdr-field-128, height=offset-gray-128, normal=curved-normal-128, position=position-128, previous=blend-bg-alpha-128
defaults | 2,665/4,096 · 147 | 2,661/4,096 · 37823 | 0/4,096 · 6.45703125 | 0/4,096 · 6.45703125 | 219/1,024 · 7.4375
blue_noise=color1, emissive=color2, environment=hdr-field-128, height=gray4, normal=normal, position=position, previous=color7 | +| `pbr_render.sbs/raytraced_irradiance_pass_8` · next_pass_index (float) | sampler | blue_noise=blend-bg-alpha-128, emissive=blend-bg-alpha-128, environment=hdr-field-128, height=offset-gray-128, normal=curved-normal-128, position=position-128, previous=blend-bg-alpha-128
defaults | 1/1 · 0 | 1/1 · 0 | 1/1 · 0 | 1/1 · 0 | 1/1 · 0
blue_noise=color1, emissive=color2, environment=hdr-field-128, height=gray4, normal=normal, position=position, previous=color7 | +| `pbr_render.sbs/raytraced_specular_pass_8` · output (RGBA) | sampler | aniso_angle_level=blend-bg-alpha-128, blue_noise=levels-range-64, emissive=blend-bg-alpha-128, environment=hdr-field-128, height=offset-gray-128, normal=curved-normal-128, position=position-128, specular_color_roughness=blend-bg-alpha-128
shape=1, shape_scale=0.7, plane_size=(0.7,1.3), displacement_intensity=0.2, uv_tiling=2, cylinder_length=1.5, cylinder_radius=0.7, uv_offset=(0.125,0.25), rotation=0.125, rotation_direction=0.2, rotation_around_direction=0.3 | 3,808/4,096 · 1 | 1,698/4,096 · 128 | 112/4,096 · 0.00390625 | 112/4,096 · 0.00390625 | 1,023/1,024 · 1.1920929e-07
aniso_angle_level=color1, blue_noise=gray2, emissive=color3, environment=hdr-field-128, height=gray5, normal=normal, position=position, specular_color_roughness=color8 | +| `pbr_render2.sbs/PBR_render_mapping_color` · output (RGBA) | bridge | texture=blend-fg-alpha-128, uv=position-128
defaults | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `pbr_render2.sbs/PBR_render_mapping_grayscale` · output (RGBA) | bridge | texture=offset-gray-128, uv=position-128
defaults | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `pbr_render2.sbs/chroma_shift` · output (RGBA) | bridge | input=blend-fg-alpha-128
radius=2, angle=0.125 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `pbr_render2.sbs/environment_map_rescale` · output (RGBA) | sampler | input=blend-bg-alpha-128
defaults | 512/4,096 · 155 | 0/4,096 · 39853 | 0/4,096 · 0.705078125 | 0/4,096 · 0.705963194 | 0/1,024 · 1.06516372
input=color1 | +| `pbr_render2.sbs/get_max_coords/get_max_coord` · Maximum (float2) | scope | input=levels-range-64
defaults | 1/1 · 0 | 1/1 · 0 | 1/1 · 0 | 1/1 · 0 | separate root controls | +| `pbr_render2.sbs/ibl_specular_contrib_anisotropic/panoramic_lod` · Diffuse (RGBA) | value | input=blend-bg-alpha-128
defaults | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=color1 | +| `pbr_render2.sbs/lod` · Diffuse (RGBA) | value | input=blend-bg-alpha-128
defaults | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=color1 | +| `pbr_render2.sbs/position_to_normal` · output (RGBA) | sampler | normal=curved-normal-128, position=position-128
shape=1, shape_scale=0.7, plane_size=(0.7,1.3), uv_tiling=2, sphere_uv_scale=(2,3), plane_uv_scale=(2,1), cylinder_uv_scale=(2,1), cylinder_length=1.5, uv_offset=(0.125,0.25), rotation=0.125, rotation_direction=0.2, rotation_around_direction=0.3, normal_format=1, recompute_normals=true | 3,895/4,096 · 2 | 403/4,096 · 399 | 1,874/4,096 · 0.00610351562 | 0/4,096 · 0.00607806444 | 0/1,024 · 0.00274163485
normal=normal, position=position | +| `pbr_render2.sbs/raytrace_position` · output (RGBA) | sampler | blue_noise=levels-range-64, height=offset-gray-128, opacity=levels-range-64
shape=1, shape_scale=0.7, shape_position=(0.1,-0.2,0.3), plane_size=(0.7,1.3), displacement_intensity=0.2, uv_tiling=2, sphere_uv_scale=(2,3), plane_uv_scale=(2,1), cylinder_uv_scale=(2,1), cylinder_length=1.5, cylinder_radius=0.7, uv_offset=(0.125,0.25), rotation=0.125, rotation_direction=0.2, rotation_around_direction=0.3 | 3,722/4,096 · 253 | 3,621/4,096 · 64898 | 3,683/4,096 · 1.49023438 | 0/4,096 · 1.49027765 | 0/1,024 · 1.47399312
blue_noise=gray1, height=gray2, opacity=gray3 | +| `pbr_render2.sbs/raytraced_irradiance_is_pass_8` · output (RGBA) | value | emissive=blend-bg-alpha-128, environment=hdr-field-128, height=offset-gray-128, noise=levels-range-64, normal=curved-normal-128, position=position-128, previous=blend-bg-alpha-128, sample_table=blend-bg-alpha-128
shape=1, shape_scale=0.7, plane_size=(0.7,1.3), displacement_intensity=0.2, uv_tiling=2, cylinder_length=1.5, cylinder_radius=0.7, uv_offset=(0.125,0.25), rotation=0.125, rotation_direction=0.2, rotation_around_direction=0.3, pass_index_1=2 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
emissive=color1, environment=hdr-field-128, height=gray3, noise=gray4, normal=normal, position=position, previous=color7, sample_table=color8 | +| `pbr_render2.sbs/raytraced_specular_pass_8` · output (RGBA) | sampler | aniso_angle_level=blend-bg-alpha-128, blue_noise=levels-range-64, emissive=blend-bg-alpha-128, environment=hdr-field-128, height=offset-gray-128, normal=curved-normal-128, position=position-128, specular_color_roughness=blend-bg-alpha-128
shape=1, shape_scale=0.7, plane_size=(0.7,1.3), displacement_intensity=0.2, uv_tiling=2, cylinder_length=1.5, cylinder_radius=0.7, uv_offset=(0.125,0.25), rotation=0.125, rotation_direction=0.2, rotation_around_direction=0.3 | 4,053/4,096 · 1 | 3,211/4,096 · 96 | 2,839/4,096 · 0.001953125 | 2,839/4,096 · 0.001953125 | 1,023/1,024 · 3.81469727e-06
aniso_angle_level=color1, blue_noise=gray2, emissive=color3, environment=hdr-field-128, height=gray5, normal=normal, position=position, specular_color_roughness=color8 | +| `pbr_render_ortho.sbs/blue_noise` · output (RGBA) | sampler | none
dithering=0.5 | 9/4,096 · 255 | 0/4,096 · 65535 | 0/4,096 · 1.99951172 | 0/4,096 · 1.99996763 | 0/1,024 · 1.99178356 | +| `pbr_render_ortho.sbs/environment_map_rescale` · output (RGBA) | sampler | input=blend-bg-alpha-128
defaults | 512/4,096 · 155 | 0/4,096 · 39853 | 0/4,096 · 0.705078125 | 0/4,096 · 0.705963194 | 0/1,024 · 1.06516372
input=color1 | +| `pbr_render_ortho.sbs/ibl_shadow_pass` · output (RGBA) | sampler | blue_noise=blend-fg-alpha-128, environment=hdr-field-128, normal=curved-normal-128
seq=3, total_samples=8, horizontal_rotation=0.125 | 0/4,096 · 255 | 0/4,096 · 65535 | 0/4,096 · 31.453125 | 0/4,096 · 31.4588242 | 0/1,024 · 28.3294125
blue_noise=color1, environment=hdr-field-128, normal=normal | +| `pbr_render_ortho.sbs/mipmap_generator` · Diffuse (RGBA) | sampler | input=blend-bg-alpha-128
defaults | 3,872/4,096 · 66 | 3,008/4,096 · 16919 | 2,766/4,096 · 0.258041382 | 0/4,096 · 0.25817919 | 17/1,024 · 0.017053945
input=color1 | +| `pbr_render_ortho.sbs/rotate_environment` · output (RGBA) | angle | input=blend-fg-alpha-128
amount=0.125, directionAngle=0.2, aroundPoleBefore=0.125, aroundPoleAfter=0.25, exposure=1 | 4,027/4,096 · 2 | 3,958/4,096 · 470 | 3,959/4,096 · 0.0068359375 | 3,958/4,096 · 0.00741589069 | 1,007/1,024 · 0.00659191608
input=color1 | +| `pbr_render_ortho.sbs/sphere_displace` · output (RGBA) | sampler | input=offset-gray-128
displacement_intensity=0.2, uv_offset=(0.125,0.25), samples=8, size=0.7 | 4,096/4,096 · 0 | 4,090/4,096 · 2 | 4,096/4,096 · 0 | 4,090/4,096 · 3.05175781e-05 | 1,022/1,024 · 1.52587891e-05
input=gray1 | +| `pbr_render_ortho.sbs/vector_shadow_pass` · output (RGBA) | sampler | environment=hdr-field-128, light_uv_coord_image_input=blend-bg-alpha-128, normal=curved-normal-128, white_noise=blend-fg-alpha-128
seq=3, samples=8 | 4,082/4,096 · 126 | 3,901/4,096 · 32393 | 3,969/4,096 · 0.995117188 | 3,816/4,096 · 0.994867861 | 1,024/1,024 · 0
environment=hdr-field-128, light_uv_coord_image_input=color2, normal=normal, white_noise=color4 | +| `perlin_noise_zoom.sbs/perlin_noise_zoom` · Noise_Zoom (LUM) | sampler | none
Distance=8, Disorder=0.3 | 44/4,096 · 149 | 2/4,096 · 38164 | 4/4,096 · 0.58190918 | 0/4,096 · 0.582338475 | 0/1,024 · 0.511653885 | +| `pre_multiply_straight.sbs/premult_to_straight` · output (RGBA) | bridge | input=blend-bg-alpha-128
defaults | 4,095/4,096 · 1 | 4,095/4,096 · 257 | 4,095/4,096 · 0.00390625 | 4,095/4,096 · 0.00392156839 | 1,024/1,024 · 0
input=color1 | +| `quad_transform.sbs/quad_transform` · output (RGBA) | bridge | input=blend-fg-alpha-128
p00=(0.1,0.125), p01=(0.2,0.9), p10=(0.9,0.2), p11=(0.8,0.85), enable_tiling=true | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=color1 | +| `quad_transform.sbs/quad_transform_grayscale` · output (LUM) | bridge | input=offset-gray-128
p00=(0.1,0.125), p01=(0.2,0.9), p10=(0.9,0.2), p11=(0.8,0.85), enable_tiling=true | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=gray1 | +| `quantize_color.sbs/color_conversions/convert_Lab_to_RGB` · output (RGBA) | sampler | input=blend-bg-alpha-128
defaults | 4,096/4,096 · 0 | 4,064/4,096 · 1 | 4,089/4,096 · 0.000244140625 | 566/4,096 · 4.59887087e-06 | 159/1,024 · 1.43051147e-06
input=color1 | +| `quantize_color.sbs/color_conversions/convert_RGB_to_Lab` · output (RGBA) | sampler | input=blend-fg-alpha-128
keep_alpha=true | 4,096/4,096 · 0 | 4,053/4,096 · 1 | 4,093/4,096 · 0.00048828125 | 480/4,096 · 3.57627869e-07 | 2/1,024 · 4.17232513e-07
input=color1 | +| `quantize_color.sbs/get_min_max/GetMaxFromAlpha_v2` · Maximum (RGBA) | sampler | input=blend-bg-alpha-128
defaults | 1/1 · 0 | 1/1 · 0 | 1/1 · 0 | 1/1 · 0 | 1/1 · 0
input=color1 | +| `quantize_color.sbs/kmeans_iteration` · output (RGBA) | sampler | input=blend-fg-alpha-128, seeds=original-palette-128
k=4, ignore_alpha=true, color_space=1 | 3,600/4,096 · 255 | 3,600/4,096 · 65535 | 3,584/4,096 · 1977.125 | 3,584/4,096 · 1978.05885 | 3,584/4,096 · 2014.94087
input=color1, seeds=original-palette-128 | +| `quantize_color.sbs/modify_color_palette_sub` · palette (RGBA) | bridge | id=original-id16-128, palette=original-palette-128
color_selection_mode=1, color_index=3, color_selection_spread=0.2, color_selection_contrast=0.4, distance_color_space=1, mode=1, opacity=0.6, override_color=(0.2,0.6,0.8), hsl=(0.1,0.2,-0.1) | 256/256 · 0 | 256/256 · 0 | 256/256 · 0 | 256/256 · 0 | 256/256 · 0
id=original-id16-128, palette=original-palette-128 | +| `radial_blur.sbs/radial_blur_grayscale` · output (LUM) | sampler | input=offset-gray-128
samples=16, angle=0.2, center_position=(0.5,0.5) | 4,083/4,096 · 1 | 2,771/4,096 · 23 | 3,937/4,096 · 0.00048828125 | 2,771/4,096 · 0.000350952148 | 315/1,024 · 0.00073248148
input=gray1 | +| `replace_color.sbs/replace_color` · ToTargetColor (RGBA) | sampler | Input=blend-fg-alpha-128
SourceColor=(0.2,0.3,0.4), TargetColor=(0.8,0.7,0.1) | 0/4,096 · 61 | 0/4,096 · 15809 | 0/4,096 · 0.241210938 | 0/4,096 · 0.241241872 | 0/1,024 · 0.244705796
Input=color1 | +| `rt_caustics.sbs/rt_caustics_base` · output (LUM) | sampler | height=offset-gray-128, noise=levels-range-64, normal=curved-normal-128
photon_grid_size=1, surface_height_scale=0.2, surface_height_position=0.7, surface_ior=1.5, photon_size=6, jittering=0.25, light_position=(0.3,0.7) | 3,822/4,096 · 83 | 729/4,096 · 21227 | 495/4,096 · 0.323730469 | 281/4,096 · 0.323898762 | 199/1,024 · 0.0106643774
height=gray1, noise=gray2, normal=normal | +| `rt_irradiance.sbs/compute_irradiance` · output (RGBA) | sampler | emissive=blend-bg-alpha-128, hit_uv=blend-fg-alpha-128, normal=curved-normal-128
defaults | 3,868/4,096 · 1 | 2/4,096 · 98 | 1,416/4,096 · 0.00146484375 | 0/4,096 · 0.00150150061 | 55/1,024 · 0.000606775284
emissive=color1, hit_uv=color2, normal=normal | +| `rt_irradiance.sbs/compute_ray_direction` · output (RGBA) | sampler | noise=levels-range-64, normal=curved-normal-128
defaults | 4,092/4,096 · 1 | 3,914/4,096 · 23 | 4,053/4,096 · 0.00048828125 | 0/4,096 · 0.000345274806 | 0/1,024 · 2.98023224e-07
noise=gray1, normal=normal | +| `rt_irradiance.sbs/debug_hit_uv` · output (RGBA) | angle | input=blend-fg-alpha-128
defaults | 37/4,096 · 135 | 37/4,096 · 34695 | 37/4,096 · 0.529296875 | 37/4,096 · 0.529411778 | 7/1,024 · 0.607843159
input=color1 | +| `rt_irradiance.sbs/mip_max` · output (LUM) | sampler | input=levels-range-64
defaults | size 32×32 / 64×64 | size 32×32 / 64×64 | size 32×32 / 64×64 | size 32×32 / 64×64 | size 16×16 / 32×32
input=gray1 | +| `rt_irradiance.sbs/panoramic_lod` · Diffuse (RGBA) | sampler | input=blend-bg-alpha-128
defaults | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=color1 | +| `rt_shadows.sbs/mip_max` · output (LUM) | sampler | input=levels-range-64
defaults | size 32×32 / 64×64 | size 32×32 / 64×64 | size 32×32 / 64×64 | size 32×32 / 64×64 | size 16×16 / 32×32
input=gray1 | +| `safe_transform.sbs/safe_transform` · output (RGBA) | sampler | input=blend-fg-alpha-128
tile=2, offset_mode=1, offset=(0.125,-0.25), rotation=0.125, tile_safe_rotation=false, symmetry=1 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=color1 | +| `safe_transform.sbs/safe_transform_grayscale` · output (LUM) | sampler | input=offset-gray-128
tile=2, offset_mode=1, offset=(0.125,-0.25), rotation=0.125, tile_safe_rotation=false, symmetry=1 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=gray1 | +| `scratches_1.sbs/scratches_1` · Scratches (LUM) | sampler | none
Pattern_size_width=130, Pattern_size_height=80, Disorder=0.25, Rotation_Var=15, Rotation=30 | 1,951/4,096 · 198 | 978/4,096 · 50874 | 879/4,096 · 0.775802612 | 878/4,096 · 0.776283483 | 248/1,024 · 0.901990709 | +| `scratches_2.sbs/scratches_2` · Thorns (LUM) | sampler | none
Pattern_size_width=130, Pattern_size_height=80, Disorder=0.25 | 28/4,096 · 254 | 13/4,096 · 65365 | 4/4,096 · 1.49499512 | 0/4,096 · 1.49516 | 0/1,024 · 1.17333403 | +| `scratches_4.sbs/scratches_4` · Thorns_3 (LUM) | sampler | none
defaults | 12/4,096 · 255 | 5/4,096 · 65535 | 5/4,096 · 1 | 5/4,096 · 1 | 0/1,024 · 1 | +| `shape.sbs/shape_base` · output (LUM) | sampler | none
pattern=3, pattern_specific=0.3, scale=0.7, size_xy=(0.7,1.2), angle=0.125 | 4,096/4,096 · 0 | 4,072/4,096 · 1 | 4,088/4,096 · 0.00048828125 | 2,910/4,096 · 1.43051147e-06 | 717/1,024 · 1.37090683e-06 | +| `shape_mapper.sbs/shape_mapper` · output (LUM) | sampler | input=offset-gray-128
rotation=0.125, shape=1, pattern_amount=6, segments=5, radius=0.3, width=0.7, flip_1on_2=true | 3,533/4,096 · 34 | 1,686/4,096 · 8738 | 1,735/4,096 · 0.133300781 | 1,686/4,096 · 0.13333334 | 1,018/1,024 · 0.0025177598
input=gray1 | +| `shape_splatter.sbs/shape_splatter_blend` · output (LUM) | sampler | see input group 12
pattern_number=3, luminance_adjustement=0.2, luminance_random=0.3, color_input_opacity=0.4 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
same pin order | +| `shape_splatter.sbs/shape_splatter_blend_color` · output (RGBA) | bridge | see input group 13
pattern_number=3, color_input_opacity=0.4 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
same pin order | +| `shape_splatter.sbs/shape_splatter_data_extract` · position (RGBA) | sampler | splatter_data_1=blend-bg-alpha-128, splatter_data_2=blend-fg-alpha-128
defaults | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,003/4,096 · 1.1920929e-07 | 1,024/1,024 · 0
splatter_data_1=color1, splatter_data_2=color2 | +| `shape_splatter.sbs/shape_splatter_data_extract` · uv_texture_space (RGBA) | sampler | splatter_data_1=blend-bg-alpha-128, splatter_data_2=blend-fg-alpha-128
defaults | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,181/4,096 · 1.1920929e-07 | 300/1,024 · 1.1920929e-07
splatter_data_1=color1, splatter_data_2=color2 | +| `shape_splatter.sbs/shape_splatter_data_extract` · bounding_box_size (RGBA) | sampler | splatter_data_1=blend-bg-alpha-128, splatter_data_2=blend-fg-alpha-128
defaults | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 3,902/4,096 · 2.98023224e-08 | 1,024/1,024 · 0
splatter_data_1=color1, splatter_data_2=color2 | +| `shape_splatter.sbs/shape_splatter_data_extract` · uv_shape_space (RGBA) | sampler | splatter_data_1=blend-bg-alpha-128, splatter_data_2=blend-fg-alpha-128
defaults | 4,096/4,096 · 0 | 4,032/4,096 · 1 | 4,032/4,096 · 7.62939453e-06 | 3,782/4,096 · 7.62939453e-06 | 1,024/1,024 · 0
splatter_data_1=color1, splatter_data_2=color2 | +| `shape_splatter.sbs/shape_splatter_data_extract` · pattern_id (LUM) | sampler | splatter_data_1=blend-bg-alpha-128, splatter_data_2=blend-fg-alpha-128
defaults | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
splatter_data_1=color1, splatter_data_2=color2 | +| `shape_splatter.sbs/shape_splatter_data_extract` · shape_angle (LUM) | sampler | splatter_data_1=blend-bg-alpha-128, splatter_data_2=blend-fg-alpha-128
defaults | 4,096/4,096 · 0 | 4,032/4,096 · 1 | 4,096/4,096 · 0 | 4,032/4,096 · 7.62939453e-06 | 1,024/1,024 · 0
splatter_data_1=color1, splatter_data_2=color2 | +| `shape_splatter.sbs/shape_splatter_data_extract` · shape_index (RGBA) | sampler | splatter_data_1=blend-bg-alpha-128, splatter_data_2=blend-fg-alpha-128
defaults | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
splatter_data_1=color1, splatter_data_2=color2 | +| `shape_splatter_v2.sbs/mipmap_tools/Mipmap_N_from_O_color` · output (RGBA) | sampler | input=blend-fg-alpha-128
N=2, O=1 | 3,968/4,096 · 255 | 3,968/4,096 · 65535 | 3,968/4,096 · 1 | 3,968/4,096 · 1 | 992/1,024 · 1
input=color1 | +| `shape_splatter_v2.sbs/shape_splatter_compute_normal` · output (RGBA) | sampler | input_0=blend-fg-alpha-128, input_1=blend-bg-alpha-128, input_2=blend-bg-alpha-128, input_3=blend-bg-alpha-128, input_4=blend-bg-alpha-128, input_5=blend-bg-alpha-128, input_6=levels-range-64, input_7=levels-range-64
x_amount=7, y_amount=3, position_distribution_mode=1, amount=7 | 0/4,096 · 255 | 0/4,096 · 65462 | 0/4,096 · 0.998477936 | 0/4,096 · 0.99889338 | 0/1,024 · 0.979619235
input_0=color1, input_1=color2, input_2=color3, input_3=color4, input_4=color5, input_5=color6, input_6=gray7, input_7=gray8 | +| `skew.sbs/skew` · Skew (RGBA) | bridge | Source=blend-fg-alpha-128
Axis=1, Amount=0.35, Align=0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `skew.sbs/skew_grayscale` · Skew (LUM) | bridge | Source=offset-gray-128
Axis=1, Amount=0.35, Align=0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `slope_blur.sbs/slope_blur` · Slope_Blur (RGBA) | sampler | Effect=levels-range-64, Source=blend-fg-alpha-128
Samples=4, Intensity=3, mode=0 | 0/4,096 · 158 | 0/4,096 · 40606 | 0/4,096 · 0.619384766 | 0/4,096 · 0.619607851 | 0/1,024 · 0.76862745
Effect=gray1, Source=color2 | +| `slope_blur.sbs/slope_blur_grayscale` · Slope_Blur (LUM) | sampler | Effect=levels-range-64, Source=offset-gray-128
Samples=4, Intensity=3, mode=0 | 63/4,096 · 58 | 63/4,096 · 14906 | 63/4,096 · 0.227539062 | 63/4,096 · 0.227450997 | 12/1,024 · 0.32941179
Effect=gray1, Source=gray2 | +| `slope_blur.sbs/slope_blur_grayscale_2` · Slope_Blur (LUM) | sampler | Effect=levels-range-64, Source=offset-gray-128
Samples=4, Intensity=3, mode=0 | 63/4,096 · 58 | 63/4,096 · 14906 | 63/4,096 · 0.227539062 | 63/4,096 · 0.227450997 | 12/1,024 · 0.32941179
Effect=gray1, Source=gray2 | +| `smart_auto_tile.sbs/pattern_find_edges_step` · mask_output (RGBA) | sampler | baseColor=blend-fg-alpha-128, height=levels-range-64, mask_input=blend-bg-alpha-128, normal=curved-normal-128
grid_resolution=5, edge_use_threshold_per_channel=true, edge_threshold=0.3 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0 | 1,024/1,024 · 0
baseColor=color1, height=gray2, mask_input=color3, normal=normal | +| `splatter.sbs/splatter` · Splatter_Grayscale (LUM) | sampler | Source=offset-gray-128
Pattern_size_width=130, Pattern_size_height=80, Disorder=0.25, Rotation_Var=15, Rotation=30, Grid_Number=3, PatternSize=1, Pan_X=0.15, Pan_Y=-0.2, Gain=0.7 | 244/4,096 · 147 | 235/4,096 · 37779 | 235/4,096 · 0.576171875 | 235/4,096 · 0.576470613 | 87/1,024 · 0.664316773
Source=gray1 | +| `splatter_circular.sbs/splatter_circular` · Splatter_Circular (LUM) | sampler | Source=offset-gray-128, background=levels-range-64
Rotation=30, Number=7, Radius=0.35, Radius_Random=0.2, Pattern=3, PatternSize=(0.15,0.2), PatternSize_Random=0.2 | 3,968/4,096 · 221 | 3,968/4,096 · 56797 | 3,968/4,096 · 1 | 3,968/4,096 · 1.00000006 | 972/1,024 · 1.00000006
Source=gray1, background=gray2 | +| `splatter_circular.sbs/splatter_circular_color` · Splatter_Circular (RGBA) | sampler | Source=blend-fg-alpha-128, background=blend-bg-alpha-128
rotation=0.125, pattern=3, pattern_specific=0.3, radius=0.3, random_mask=0.25, number=7, radius_random=0.2, pattern_size=(0.15,0.2), pattern_size_Random=0.2 | 3,517/4,096 · 247 | 3,517/4,096 · 63479 | 3,517/4,096 · 0.96862793 | 3,517/4,096 · 0.968627449 | 872/1,024 · 1
Source=color1, background=color2 | +| `splatter_color.sbs/splatter_color` · Splatter (RGBA) | sampler | Source=blend-fg-alpha-128, Source_alpha=levels-range-64
Pattern_size_width=130, Pattern_size_height=80, Disorder=0.25, Rotation_Var=15, Rotation=30, Grid_Number=3, PatternSize=1, Pan_X=0.15, Pan_Y=-0.2, Gain=0.7 | 238/4,096 · 109 | 238/4,096 · 28089 | 238/4,096 · 0.42855835 | 238/4,096 · 0.428610656 | 97/1,024 · 0.508613691
Source=color1, Source_alpha=gray2 | +| `spline_tools.sbs/internal_tools/2dtransform_spline_sub` · spline_coords (RGBA) | sampler | spline_coords=original-offset-circle-spline_coords, spline_data=original-offset-circle-spline_data
flip_direction=true, matrix22=(0,-1,1,0), offset=(0.1,-0.2) | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 3,988/4,096 · 5.96046448e-08 | 1,024/1,024 · 0
spline_coords=original-offset-circle-spline_coords, spline_data=original-offset-circle-spline_data | +| `spline_tools.sbs/internal_tools/2dtransform_spline_sub` · spline_data (RGBA) | sampler | spline_coords=original-offset-circle-spline_coords, spline_data=original-offset-circle-spline_data
flip_direction=true, matrix22=(0,-1,1,0), offset=(0.1,-0.2) | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 3,967/4,096 · 5.96046448e-08 | 1,024/1,024 · 0
spline_coords=original-offset-circle-spline_coords, spline_data=original-offset-circle-spline_data | +| `spline_tools.sbs/internal_tools/2dtransform_spline_sub` · spline_amount (int) | sampler | spline_coords=original-offset-circle-spline_coords, spline_data=original-offset-circle-spline_data
flip_direction=true, matrix22=(0,-1,1,0), offset=(0.1,-0.2) | 1/1 · 0 | 1/1 · 0 | 1/1 · 0 | 1/1 · 0 | 1/1 · 0
spline_coords=original-offset-circle-spline_coords, spline_data=original-offset-circle-spline_data | +| `spline_tools.sbs/internal_tools/compute_bridge_distance` · output (LUM) | bridge | input=original-offset-circle-spline_coords
non_square_correction=false | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=original-offset-circle-spline_coords | +| `spline_tools.sbs/internal_tools/compute_spline_length_init` · output (LUM) | sampler | input=original-offset-circle-spline_coords
non_square_correction=false | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 3,873/4,096 · 8.56816769e-08 | 1,011/1,024 · 7.4505806e-09
input=original-offset-circle-spline_coords | +| `spline_tools.sbs/internal_tools/compute_spline_tangents` · spline_data (RGBA) | sampler | spline_coords=original-offset-circle-spline_coords, spline_data=original-offset-circle-spline_data
mode=1 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 3,873/4,096 · 1.78813934e-07 | 1,014/1,024 · 1.1920929e-07
spline_coords=original-offset-circle-spline_coords, spline_data=original-offset-circle-spline_data | +| `spline_tools.sbs/internal_tools/modify_spline_property_sub` · spline_coords (RGBA) | sampler | map=original-mask-gradient-16, spline_coords=original-offset-circle-spline_coords, spline_data=original-offset-circle-spline_data
sampling_mode=1, property=1, opacity=0.6, blending_mode=1 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 3,898/4,096 · 0.177734375 | 3,810/4,096 · 0.177648306 | 969/1,024 · 0.261176467
map=gray1, spline_coords=original-offset-circle-spline_coords, spline_data=original-offset-circle-spline_data | +| `spline_tools.sbs/internal_tools/normalize_spline_distance` · output (LUM) | sampler | input=original-mask-gradient-16
defaults | 4,093/4,096 · 1 | 3,126/4,096 · 3 | 3,965/4,096 · 0.0625 | 66/4,096 · 0.0169067383 | 1,024/1,024 · 0
input=gray1 | +| `spline_tools.sbs/internal_tools/points_preview` · output (LUM) | sampler | point_list=original-offset-circle-spline_coords
show_labels=false, show_points=true, points_size=0.02 | external font | external font | external font | external font | external font
point_list=original-offset-circle-spline_coords | +| `spline_tools.sbs/internal_tools/resample_spline_data` · spline_data (RGBA) | sampler | spline_coords=original-offset-circle-spline_coords, spline_data=original-offset-circle-spline_data, uv=original-rgba-16
defaults | 4,092/4,096 · 1 | 3,813/4,096 · 13 | 3,856/4,096 · 0.000244140625 | 3,446/4,096 · 0.000185694546 | 1,024/1,024 · 0
spline_coords=original-offset-circle-spline_coords, spline_data=original-offset-circle-spline_data, uv=color3 | +| `spline_tools.sbs/internal_tools/resample_spline_data` · spline_coords (RGBA) | sampler | spline_coords=original-offset-circle-spline_coords, spline_data=original-offset-circle-spline_data, uv=original-rgba-16
defaults | 3,813/4,096 · 128 | 3,707/4,096 · 32768 | 3,772/4,096 · 0.5 | 3,396/4,096 · 0.5 | 986/1,024 · 0.5
spline_coords=original-offset-circle-spline_coords, spline_data=original-offset-circle-spline_data, uv=color3 | +| `spline_tools.sbs/internal_tools/select_spline_sub` · output (RGBA) | sampler | data=original-offset-circle-spline_data
spline_index=0, output=1, selection_mode=1, range_start=1, range_end=1, start=0.2, end=0.8 | 30,720/32,768 · 128 | 30,720/32,768 · 32768 | 30,720/32,768 · 0.5 | 30,720/32,768 · 0.5 | 30,720/32,768 · 0.5
data=original-offset-circle-spline_data | +| `spline_tools.sbs/internal_tools/spline_warp_sub` · spline_coords (RGBA) | sampler | attenuation_curve=original-mask-gradient-16, intensity_map=original-mask-gradient-16, spline_coords=original-offset-circle-spline_coords, spline_data=original-offset-circle-spline_data, vector_map=original-rgba-16
warp_intensity=0.2, warp_center=0.4, sampling_mode=1, use_vector_map=true, use_attenuation_curve=true, start_attenuation=0.2, end_attenuation=0.3 | 4,032/4,096 · 33 | 4,032/4,096 · 8481 | 4,032/4,096 · 0.129150391 | 4,032/4,096 · 0.129411757 | 992/1,024 · 0.181807004
attenuation_curve=gray1, intensity_map=gray2, spline_coords=original-offset-circle-spline_coords, spline_data=original-offset-circle-spline_data, vector_map=color5 | +| `spot_emboss.sbs/spot_emboss` · Spot_Emboss (RGBA) | sampler | Height=levels-range-64, Source=blend-fg-alpha-128
Light_Position_X=0.3, Light_Position_Y=0.7, Intensity=2, Highlight_Color=(0.8,0.6,0.3,1), Shadow_Color=(0.1,0.2,0.4,1) | 20/4,096 · 183 | 20/4,096 · 47134 | 20/4,096 · 0.863037109 | 15/4,096 · 0.863529354 | 8/1,024 · 0.545882344
Height=gray1, Source=color2 | +| `starburst.sbs/starburst` · Starburst (LUM) | sampler | none
Branches=12, BlurAmount=1, Randomness=0.3, SizeMin=0.1, SizeMax=0.8, SizeVariation=0.2, Tiling=2 | 3,272/4,096 · 236 | 3,184/4,096 · 60659 | 3,184/4,096 · 0.925292969 | 3,184/4,096 · 0.92559699 | 784/1,024 · 0.776928335 | +| `stripes.sbs/stripes` · Stripes (LUM) | angle | none
Stripes=7, Width=0.35, Softness=0.2, Shift=6, Align=1 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0 | +| `swirl.sbs/swirl` · output (RGBA) | sampler | input=blend-fg-alpha-128
matrix22=(1.2,0.15,-0.2,0.9), offset=(0.125,-0.25), amount=3 | 4,094/4,096 · 1 | 4,094/4,096 · 63 | 4,094/4,096 · 0.0009765625 | 4,094/4,096 · 0.000961303711 | 1,024/1,024 · 0
input=color1 | +| `swirl.sbs/swirl_grayscale` · output (LUM) | sampler | input=offset-gray-128
matrix22=(1.2,0.15,-0.2,0.9), offset=(0.125,-0.25), amount=3 | 4,094/4,096 · 1 | 4,094/4,096 · 63 | 4,094/4,096 · 0.0009765625 | 4,094/4,096 · 0.000961303711 | 1,024/1,024 · 0
input=gray1 | +| `symmetry_slice.sbs/symmetry_slice` · Symmetry_Slice (RGBA) | sampler | Source=blend-fg-alpha-128
Symmetry_Mode=2, Transfer_Mode=1, Blend=0.3, Flip_Side=true, Flip_Side2=true | 2,916/4,096 · 7 | 2,859/4,096 · 1632 | 2,833/4,096 · 0.0249023438 | 1,485/4,096 · 0.0248995423 | 442/1,024 · 1.1920929e-07
Source=color1 | +| `tile_generator.sbs/tile_generator` · TileGenerator (LUM) | sampler | Source=offset-gray-128, background=levels-range-64
Nb_X=7, Nb_Y=3, Scale=0.8, ScaleVariation=0.2, Offset=0.5 | 3,586/4,096 · 69 | 3,585/4,096 · 17827 | 3,302/4,096 · 0.271850586 | 3,302/4,096 · 0.272031903 | 831/1,024 · 0.276015699
Source=gray1, background=gray2 | +| `tile_generator_color.sbs/tile_generator_color` · TileGenerator_Color (RGBA) | sampler | Source=blend-fg-alpha-128, background=blend-bg-alpha-128
Nb_X=7, Nb_Y=3, Scale=0.8, ScaleVariation=0.2, Offset=0.5 | 3,344/4,096 · 80 | 3,302/4,096 · 20446 | 1,934/4,096 · 0.963867188 | 1,934/4,096 · 0.964705944 | 494/1,024 · 1
Source=color1, background=color2 | +| `tile_random.sbs/tile_random` · output (LUM) | sampler | background_input=levels-range-64, pattern_input=offset-gray-128
x_amount=7, y_amount=3, pattern=3, pattern_rotation_random=0.3 | 2,725/4,096 · 223 | 2,725/4,096 · 57311 | 2,725/4,096 · 1 | 2,725/4,096 · 1.00000006 | 723/1,024 · 1.00000006
background_input=gray1, pattern_input=gray2 | +| `tile_random.sbs/tile_random_color` · output (RGBA) | sampler | background_input_1=blend-fg-alpha-128, pattern_input=blend-bg-alpha-128
x_amount=7, y_amount=3, pattern=3, pattern_rotation_random=0.3 | 2,725/4,096 · 250 | 2,725/4,096 · 64250 | 511/4,096 · 1 | 511/4,096 · 1.00000006 | 150/1,024 · 1.00000006
background_input_1=color1, pattern_input=color2 | +| `tile_sampler.sbs/arrow` · output (LUM) | filtered | none
defaults | 262,144/262,144 · 0 | 262,144/262,144 · 0 | 262,144/262,144 · 0 | 262,144/262,144 · 0 | separate root controls | +| `tileable_material_to_mesh_material.sbs/tileable_material_to_mesh_material` · Specular (RGBA) | sampler | AO=levels-range-64, Curvature=levels-range-64, Diffuse=blend-bg-alpha-128, Normal_WS=curved-normal-128, Specular=blend-bg-alpha-128
Pre_Lighting_Intensity=0.3, AO_Intensity=0.5, Edges_Sharpness_Intensity=0.2, AO_Intensity_Specular=0.4 | 4,096/4,096 · 0 | 4,090/4,096 · 1 | 4,096/4,096 · 0 | 1,331/4,096 · 5.96046448e-08 | 363/1,024 · 5.96046448e-08
AO=gray1, Curvature=gray2, Diffuse=color3, Normal_WS=normal, Specular=color5 | +| `tileable_material_to_mesh_material.sbs/tileable_material_to_mesh_material` · Diffuse (RGBA) | sampler | AO=levels-range-64, Curvature=levels-range-64, Diffuse=blend-bg-alpha-128, Normal_WS=curved-normal-128, Specular=blend-bg-alpha-128
Pre_Lighting_Intensity=0.3, AO_Intensity=0.5, Edges_Sharpness_Intensity=0.2, AO_Intensity_Specular=0.4 | 3,843/4,096 · 1 | 2,849/4,096 · 103 | 2,861/4,096 · 0.00170898438 | 1,262/4,096 · 0.00156864524 | 322/1,024 · 0.00156867504
AO=gray1, Curvature=gray2, Diffuse=color3, Normal_WS=normal, Specular=color5 | +| `trapezoid_transform.sbs/trapezoid_transform` · output (RGBA) | sampler | input=blend-fg-alpha-128
top_stretch=0.3, bottom_stretch=-0.2 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=color1 | +| `trapezoid_transform.sbs/trapezoid_transform_grayscale` · output (LUM) | sampler | input=offset-gray-128
top_stretch=0.3, bottom_stretch=-0.2 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0
input=gray1 | +| `uv_mapper.sbs/uv_mapper_color_sub` · output (RGBA) | bridge | input=blend-bg-alpha-128, uv=position-128
filtering_mode=0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `uv_mapper.sbs/uv_mapper_grayscale_sub` · output (LUM) | bridge | input=levels-range-64, uv=position-128
filtering_mode=0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `vector_morph.sbs/vector_morph` · output (RGBA) | sampler | input=blend-fg-alpha-128, vector_field=blend-bg-alpha-128
amount=3 | 3,835/4,096 · 221 | 3,801/4,096 · 56909 | 3,801/4,096 · 0.868286133 | 3,801/4,096 · 0.868375674 | 1,024/1,024 · 0
input=color1, vector_field=color2 | +| `vector_morph.sbs/vector_morph_grayscale` · output (LUM) | sampler | input=levels-range-64, vector_field=blend-fg-alpha-128
amount=3 | 4,091/4,096 · 127 | 4,091/4,096 · 32611 | 4,091/4,096 · 0.497558594 | 4,091/4,096 · 0.497611985 | 1,024/1,024 · 0
input=gray1, vector_field=color2 | +| `vertical_noise.sbs/vertical_noise` · Vertical_Noise (LUM) | sampler | none
Disorder=0.3 | 70/4,096 · 158 | 1/4,096 · 40470 | 3/4,096 · 0.617553711 | 0/4,096 · 0.617534697 | 0/1,024 · 0.488726646 | +| `waveform_01_v2.sbs/waveform_01_v2` · Waveform (LUM) | sampler | none
pattern=3, samples=128, function=1, roughness=0.7, scale=16, amplitude_min=0.1, amplitude_max=0.8, noise=0.25, disorder=0.3, disorder_speed=0.6 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0 | +| `waveform_1.sbs/waveform_1` · Waveform (LUM) | sampler | none
SizeMin=0.1, SizeMax=0.8, Samples=128, WaveNumber=3, Noise=0.2, Pattern=3 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0 | +| `weave_1.sbs/weave_1` · Weave (LUM) | sampler | none
Tiling=2, Rotate_45_Degrees=true | 0/4,096 · 255 | 0/4,096 · 65535 | 0/4,096 · 1 | 0/4,096 · 1 | 0/1,024 · 1 | +| `weave_2.sbs/weave_2` · Weave_2 (LUM) | sampler | none
Tiling=2, Disorder=0.3, Rotate_45_Degrees=true | 0/4,096 · 160 | 0/4,096 · 41142 | 0/4,096 · 0.627441406 | 0/4,096 · 0.627786696 | 10/1,024 · 0.243762881 | +| `weave_3.sbs/weave_3` · Weave_3 (LUM) | bridge | none
Tiling=2, Rotation=true | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | separate root controls | +| `weave_4.sbs/weave_4` · Weave_4 (LUM) | sampler | none
Tiling=2, Rotation=true | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 4,096/4,096 · 0 | 1,024/1,024 · 0 | +| `white_noise.sbs/white_noise_fast` · output (LUM) | sampler | none
defaults | 14/4,096 · 253 | 0/4,096 · 65120 | 1/4,096 · 0.993654251 | 0/4,096 · 0.99366051 | 0/1,024 · 0.952913761 | +| `white_noise_v2.sbs/white_noise_v2` · output (LUM) | sampler | none
noise_distribution=1, disorder=0.3, disorder_speed=0.6 | 37/4,096 · 169 | 1/4,096 · 43567 | 7/4,096 · 0.671630859 | 0/4,096 · 0.671823263 | 0/1,024 · 0.592708588 | +| `wood_fibers_1.sbs/wood_fibers_1` · Wood_Fibers (LUM) | sampler | none
Disorder=0.3 | 1/4,096 · 251 | 1/4,096 · 64474 | 1/4,096 · 0.983825684 | 1/4,096 · 0.98381361 | 0/1,024 · 0.980358532 | +| `wood_fibers_2.sbs/wood_fibers_2` · Wood_Noise (LUM) | sampler | none
defaults | execution budget | execution budget | execution budget | execution budget | execution budget | + +#### Wide input groups + +| Group | Bound inputs at 64² | Bound inputs at 32² | +|---:|---|---| +| 1 | blue_noise=irradiance-blue_noise, environment=irradiance-environment, normal=irradiance-normal, position=irradiance-position, sample_table=irradiance-samples-polar192, sdf=irradiance-sdf-hdr | blue_noise=irradiance-blue_noise, environment=irradiance-environment, normal=irradiance-normal, position=irradiance-position, sample_table=irradiance-samples-polar192, sdf=irradiance-sdf-hdr | +| 2 | density=volume-density-thin, importance_sampling=irradiance-samples-polar64, input=irradiance-environment, noise=irradiance-blue_noise, position=irradiance-position, sdf=sdf-negative-16 | density=volume-density-thin, importance_sampling=irradiance-samples-polar64, input=irradiance-environment, noise=irradiance-blue_noise, position=irradiance-position, sdf=sdf-negative-16 | +| 3 | Material_1_Diffuse_Black=material-input-1-128, Material_1_Height_Black=material-input-5-128, Material_1_Specular_Black=material-input-3-128, Material_2_Diffuse_White=material-input-2-128, Material_2_Height_White=material-input-6-128, Material_2_Specular_White=material-input-4-128, SVG_Mask=material-id-128 | Material_1_Diffuse_Black=color1, Material_1_Height_Black=color2, Material_1_Specular_Black=color3, Material_2_Diffuse_White=color4, Material_2_Height_White=color5, Material_2_Specular_White=color6, SVG_Mask=material-id-128 | +| 4 | Material_1_Diffuse_Black=material-input-1-128, Material_1_Height_Black=material-input-5-128, Material_1_Specular_Black=material-input-3-128, Material_2_Diffuse_White=material-input-2-128, Material_2_Height_White=material-input-6-128, Material_2_Specular_White=material-input-4-128, SVG_Mask=material-id-128 | Material_1_Diffuse_Black=color1, Material_1_Height_Black=color2, Material_1_Specular_Black=color3, Material_2_Diffuse_White=color4, Material_2_Height_White=color5, Material_2_Specular_White=color6, SVG_Mask=material-id-128 | +| 5 | Material_1_Diffuse_Black=material-input-1-128, Material_1_Height_Black=material-input-5-128, Material_1_Specular_Black=material-input-3-128, Material_2_Diffuse_White=material-input-2-128, Material_2_Height_White=material-input-6-128, Material_2_Specular_White=material-input-4-128, SVG_Mask=material-id-128 | Material_1_Diffuse_Black=color1, Material_1_Height_Black=color2, Material_1_Specular_Black=color3, Material_2_Diffuse_White=color4, Material_2_Height_White=color5, Material_2_Specular_White=color6, SVG_Mask=material-id-128 | +| 6 | Hue_Shift_SVG_Mask=material-id-128, Material_1_Diffuse_Black=material-input-1-128, Material_1_Height_Black=material-input-9-128, Material_1_Specular_Black=material-input-6-128, Material_2_Diffuse_Red=material-input-2-128, Material_2_Height_Red=material-input-10-128, Material_2_Specular_Red=material-input-8-128, Material_3_Diffuse_Green=material-input-3-128, Material_3_Height_Green=material-input-11-128, Material_3_Specular_Green=material-input-5-128, Material_4_Diffuse_Blue=material-input-4-128, Material_4_Height_Blue=material-input-12-128, Material_4_Specular_Blue=material-input-7-128 | Hue_Shift_SVG_Mask=material-id-128, Material_1_Diffuse_Black=color2, Material_1_Height_Black=color3, Material_1_Specular_Black=color4, Material_2_Diffuse_Red=color5, Material_2_Height_Red=color6, Material_2_Specular_Red=color7, Material_3_Diffuse_Green=color8, Material_3_Height_Green=color9, Material_3_Specular_Green=color10, Material_4_Diffuse_Blue=color11, Material_4_Height_Blue=color12, Material_4_Specular_Blue=color13 | +| 7 | Hue_Shift_SVG_Mask=material-id-128, Material_1_Diffuse_Black=material-input-1-128, Material_1_Height_Black=material-input-9-128, Material_1_Specular_Black=material-input-6-128, Material_2_Diffuse_Red=material-input-2-128, Material_2_Height_Red=material-input-10-128, Material_2_Specular_Red=material-input-8-128, Material_3_Diffuse_Green=material-input-3-128, Material_3_Height_Green=material-input-11-128, Material_3_Specular_Green=material-input-5-128, Material_4_Diffuse_Blue=material-input-4-128, Material_4_Height_Blue=material-input-12-128, Material_4_Specular_Blue=material-input-7-128 | Hue_Shift_SVG_Mask=material-id-128, Material_1_Diffuse_Black=color2, Material_1_Height_Black=color3, Material_1_Specular_Black=color4, Material_2_Diffuse_Red=color5, Material_2_Height_Red=color6, Material_2_Specular_Red=color7, Material_3_Diffuse_Green=color8, Material_3_Height_Green=color9, Material_3_Specular_Green=color10, Material_4_Diffuse_Blue=color11, Material_4_Height_Blue=color12, Material_4_Specular_Blue=color13 | +| 8 | Hue_Shift_SVG_Mask=material-id-128, Material_1_Diffuse_Black=material-input-1-128, Material_1_Height_Black=material-input-9-128, Material_1_Specular_Black=material-input-6-128, Material_2_Diffuse_Red=material-input-2-128, Material_2_Height_Red=material-input-10-128, Material_2_Specular_Red=material-input-8-128, Material_3_Diffuse_Green=material-input-3-128, Material_3_Height_Green=material-input-11-128, Material_3_Specular_Green=material-input-5-128, Material_4_Diffuse_Blue=material-input-4-128, Material_4_Height_Blue=material-input-12-128, Material_4_Specular_Blue=material-input-7-128 | Hue_Shift_SVG_Mask=material-id-128, Material_1_Diffuse_Black=color2, Material_1_Height_Black=color3, Material_1_Specular_Black=color4, Material_2_Diffuse_Red=color5, Material_2_Height_Red=color6, Material_2_Specular_Red=color7, Material_3_Diffuse_Green=color8, Material_3_Height_Green=color9, Material_3_Specular_Green=color10, Material_4_Diffuse_Blue=color11, Material_4_Height_Blue=color12, Material_4_Specular_Blue=color13 | +| 9 | Hue_Shift_SVG_Mask=material-id-128, Material_1_Diffuse_Black=material-input-1-128, Material_1_Height_Black=material-input-15-128, Material_1_Specular_Black=material-input-11-128, Material_2_Diffuse_Red=material-input-2-128, Material_2_Height_Red=material-input-16-128, Material_2_Specular_Red=material-input-13-128, Material_3_Diffuse_Green=material-input-3-128, Material_3_Height_Green=material-input-17-128, Material_3_Specular_Green=material-input-8-128, Material_4_Diffuse_Blue=material-input-4-128, Material_4_Height_Blue=material-input-18-128, Material_4_Specular_Blue=material-input-12-128, Material_5_Diffuse_Yellow=material-input-5-128, Material_5_Height_Yellow=material-input-19-128, Material_5_Specular_Yellow=material-input-9-128, Material_6_Diffuse_Magenta=material-input-23-128, Material_6_Height_Magenta=material-input-24-128, Material_6_Specular_Magenta=material-input-25-128, Material_7_Diffuse_Cyan=material-input-6-128, Material_7_Height_Cyan=material-input-20-128, Material_7_Specular_Cyan=material-input-14-128, Material_8_Diffuse_White=material-input-7-128, Material_8_Height_White=material-input-21-128, Material_8_Specular_White=material-input-10-128 | Hue_Shift_SVG_Mask=material-id-128, Material_1_Diffuse_Black=color2, Material_1_Height_Black=color3, Material_1_Specular_Black=color4, Material_2_Diffuse_Red=color5, Material_2_Height_Red=color6, Material_2_Specular_Red=color7, Material_3_Diffuse_Green=color8, Material_3_Height_Green=color9, Material_3_Specular_Green=color10, Material_4_Diffuse_Blue=color11, Material_4_Height_Blue=color12, Material_4_Specular_Blue=color13, Material_5_Diffuse_Yellow=color14, Material_5_Height_Yellow=color15, Material_5_Specular_Yellow=color16, Material_6_Diffuse_Magenta=color17, Material_6_Height_Magenta=color18, Material_6_Specular_Magenta=color19, Material_7_Diffuse_Cyan=color20, Material_7_Height_Cyan=color21, Material_7_Specular_Cyan=color22, Material_8_Diffuse_White=color23, Material_8_Height_White=color24, Material_8_Specular_White=color25 | +| 10 | Hue_Shift_SVG_Mask=material-id-128, Material_1_Diffuse_Black=material-input-1-128, Material_1_Height_Black=material-input-15-128, Material_1_Specular_Black=material-input-11-128, Material_2_Diffuse_Red=material-input-2-128, Material_2_Height_Red=material-input-16-128, Material_2_Specular_Red=material-input-13-128, Material_3_Diffuse_Green=material-input-3-128, Material_3_Height_Green=material-input-17-128, Material_3_Specular_Green=material-input-8-128, Material_4_Diffuse_Blue=material-input-4-128, Material_4_Height_Blue=material-input-18-128, Material_4_Specular_Blue=material-input-12-128, Material_5_Diffuse_Yellow=material-input-5-128, Material_5_Height_Yellow=material-input-19-128, Material_5_Specular_Yellow=material-input-9-128, Material_6_Diffuse_Magenta=material-input-23-128, Material_6_Height_Magenta=material-input-24-128, Material_6_Specular_Magenta=material-input-25-128, Material_7_Diffuse_Cyan=material-input-6-128, Material_7_Height_Cyan=material-input-20-128, Material_7_Specular_Cyan=material-input-14-128, Material_8_Diffuse_White=material-input-7-128, Material_8_Height_White=material-input-21-128, Material_8_Specular_White=material-input-10-128 | Hue_Shift_SVG_Mask=material-id-128, Material_1_Diffuse_Black=color2, Material_1_Height_Black=color3, Material_1_Specular_Black=color4, Material_2_Diffuse_Red=color5, Material_2_Height_Red=color6, Material_2_Specular_Red=color7, Material_3_Diffuse_Green=color8, Material_3_Height_Green=color9, Material_3_Specular_Green=color10, Material_4_Diffuse_Blue=color11, Material_4_Height_Blue=color12, Material_4_Specular_Blue=color13, Material_5_Diffuse_Yellow=color14, Material_5_Height_Yellow=color15, Material_5_Specular_Yellow=color16, Material_6_Diffuse_Magenta=color17, Material_6_Height_Magenta=color18, Material_6_Specular_Magenta=color19, Material_7_Diffuse_Cyan=color20, Material_7_Height_Cyan=color21, Material_7_Specular_Cyan=color22, Material_8_Diffuse_White=color23, Material_8_Height_White=color24, Material_8_Specular_White=color25 | +| 11 | Hue_Shift_SVG_Mask=material-id-128, Material_1_Diffuse_Black=material-input-1-128, Material_1_Height_Black=material-input-15-128, Material_1_Specular_Black=material-input-11-128, Material_2_Diffuse_Red=material-input-2-128, Material_2_Height_Red=material-input-16-128, Material_2_Specular_Red=material-input-13-128, Material_3_Diffuse_Green=material-input-3-128, Material_3_Height_Green=material-input-17-128, Material_3_Specular_Green=material-input-8-128, Material_4_Diffuse_Blue=material-input-4-128, Material_4_Height_Blue=material-input-18-128, Material_4_Specular_Blue=material-input-12-128, Material_5_Diffuse_Yellow=material-input-5-128, Material_5_Height_Yellow=material-input-19-128, Material_5_Specular_Yellow=material-input-9-128, Material_6_Diffuse_Magenta=material-input-23-128, Material_6_Height_Magenta=material-input-24-128, Material_6_Specular_Magenta=material-input-25-128, Material_7_Diffuse_Cyan=material-input-6-128, Material_7_Height_Cyan=material-input-20-128, Material_7_Specular_Cyan=material-input-14-128, Material_8_Diffuse_White=material-input-7-128, Material_8_Height_White=material-input-21-128, Material_8_Specular_White=material-input-10-128 | Hue_Shift_SVG_Mask=material-id-128, Material_1_Diffuse_Black=color2, Material_1_Height_Black=color3, Material_1_Specular_Black=color4, Material_2_Diffuse_Red=color5, Material_2_Height_Red=color6, Material_2_Specular_Red=color7, Material_3_Diffuse_Green=color8, Material_3_Height_Green=color9, Material_3_Specular_Green=color10, Material_4_Diffuse_Blue=color11, Material_4_Height_Blue=color12, Material_4_Specular_Blue=color13, Material_5_Diffuse_Yellow=color14, Material_5_Height_Yellow=color15, Material_5_Specular_Yellow=color16, Material_6_Diffuse_Magenta=color17, Material_6_Height_Magenta=color18, Material_6_Specular_Magenta=color19, Material_7_Diffuse_Cyan=color20, Material_7_Height_Cyan=color21, Material_7_Specular_Cyan=color22, Material_8_Diffuse_White=color23, Material_8_Height_White=color24, Material_8_Specular_White=color25 | +| 12 | background_color=levels-range-64, color_input=levels-range-64, pattern_1=levels-range-64, pattern_2=levels-range-64, pattern_3=levels-range-64, pattern_4=levels-range-64, pattern_5=levels-range-64, pattern_6=levels-range-64, pattern_7=levels-range-64, pattern_8=levels-range-64, splatter_data_1=blend-fg-alpha-128, splatter_data_2=blend-bg-alpha-128 | background_color=gray1, color_input=gray2, pattern_1=gray3, pattern_2=gray4, pattern_3=gray5, pattern_4=gray6, pattern_5=gray7, pattern_6=gray8, pattern_7=gray9, pattern_8=gray10, splatter_data_1=color11, splatter_data_2=color12 | +| 13 | background_color=blend-bg-alpha-128, color_input=blend-bg-alpha-128, pattern_1=blend-bg-alpha-128, pattern_2=blend-bg-alpha-128, pattern_3=blend-bg-alpha-128, pattern_4=blend-bg-alpha-128, pattern_5=blend-bg-alpha-128, pattern_6=blend-bg-alpha-128, pattern_7=blend-bg-alpha-128, pattern_8=blend-bg-alpha-128, splatter_data_1=blend-fg-alpha-128, splatter_data_2=blend-bg-alpha-128 | background_color=color1, color_input=color2, pattern_1=color3, pattern_2=color4, pattern_3=color5, pattern_4=color6, pattern_5=color7, pattern_6=color8, pattern_7=color9, pattern_8=color10, splatter_data_1=color11, splatter_data_2=color12 | + +| Original procedural file | SHA-256 of recorded input | +|---|---| +| `irradiance-blue_noise.png` | `a343e22b62b454354fbdbb8a42a533ed58de615730c13a08b35b200699974742` | +| `original-paths-seven.exr` | `9eca99f28823ccd6a9d2008d348bac6bacbe074f6074629779dca8ff31bae6a2` | +| `original-facets-gradient.exr` | `4b7f8cb83b6fee5e95e0adea357b8fb75b0c0c4a99b7133db75b37005e9d4c47` | +| `original-offset-circle-spline_coords.exr` | `a0a299005e150a5d0b9a0880fcd71fb70b12f10a52a793a56d239b829d657457` | +| `original-offset-circle-spline_data.exr` | `6b246ba71fb60fe87fee053da0faffb6a5aa5db99338f7fd9d6cd8751b4381de` | + +## 2026-11-17 root comparisons + +The clean-room comparisons below use the 16.0.7 reference app with the Direct3D 11 backend and a release MaterialCraft CPU cook. They compare the raw output bridge at its stored precision. A pixel counts only when every channel agrees. Integer errors are in stored levels. Floating errors are absolute. Each case starts from the graph defaults. Where a row selects another storage format, set the final processor's format to absolute in both apps before cooking. + +### 3D linear gradient + +Bind a linear RGBA8 position map at the output size `N`. At zero-based texel `(x,y)`, set R and G to the nearest integers to `255*x/(N-1)` and `255*y/(N-1)`, with ties to even. Set B to 128 and A to 255. Use the default UV points, or set `points_position_mode=1` for world mode. The oblique case sets the world points to `(.2,.1,.3)` and `(.8,.9,.6)` and contrast to .35. The float output includes values outside the unit interval. + +| Case | Size | Seed | Format | Exact pixels / total | Maximum error | +|---|---:|---:|---|---:|---:| +| Default UV | 256² / 512² | 0 | LUM32F | 65,536/65,536 and 262,144/262,144 | 0 | +| Default world points | 256² / 512² | 0 | LUM32F | 65,536/65,536 and 262,144/262,144 | 0 | +| Default UV | 128² | 42 | LUM32F | 16,384/16,384 | 0 | +| UV, contrast .6 | 256² / 512² | 0 | LUM32F | 26,043/65,536 and 104,172/262,144 | 2.384186e-7 | +| Oblique | 256² / 512² | 0 | LUM32F | 38,634/65,536 and 154,536/262,144 | 1.192093e-7 | +| Oblique | 128² | 42 | LUM8 | 16,384/16,384 | 0 | +| Oblique | 128² | 42 | LUM16 | 16,379/16,384 | 1 | +| Oblique | 128² | 42 | LUM16F | 16,367/16,384 | 2.44140625e-4 | + +At 256² the two default cases previously matched 46,763 and 32,755 float pixels. A separate pair of 128² probes for each of float2, float3 and float4 isolated the dot product. Use a varying signed RGBA32F input and dot its leading lanes with themselves or with the corresponding prefix of `(.2126,.7152,.0722,-.39)`. The measured accumulation starts with the rounded Y product and fuses X, then Z and W when present. All 98,304 sampled dot and squared-length results now agree exactly. Literal-only dot, division and interpolation expressions retain their separately measured rounding. + +For the signed test image, number RGBA components in row-major order starting at zero. Compute `v = i*747796405 + 2891336453`, then `v = ((v >> ((v >> 28)+4)) ^ v)*277803737` with unsigned 32-bit wrap at both steps. Store `8*((v ^ (v >> 22))/2^32)-4` as float32. Interpolating R to G with B as the factor and dividing R by the float32 value 1.7320508 each match 16,384/16,384 pixels with zero error. With G as the divisor, 14,372/16,384 match and the maximum error is 4.8828125e-4. Multiplying R by a separately captured reference reciprocal of G reproduces all 16,384 reference quotients. A standalone `R*G-B` probe matches 11,721/16,384 with a maximum error of 1.907349e-6. Fusing that product and subtraction reproduces every reference pixel. At 256² the contrast-.6 reference output is exactly a fused `gradient*2.5-.75` on the zero-contrast reference image. Separate graph operations and reciprocal approximation remain open. The unconnected Position case from the first pass also remains open. + +### Basic and ridged 3D Perlin + +Use the same position ramp. For a controlled comparison, bind an original 1024×16 grayscale lookup to the internal bitmap in both apps. With one Python `random.Random(104729)` instance, shuffle a fresh list of integers 0 through 1023 for each successive row. Write each entry as the nearest integer to `65535*entry/1023` in a linear 16-bit PNG. Both internal lookup outputs matched all 16,384 levels with zero error. The changed parameter is `scale=6` for basic Perlin and `roughness=.7` for ridged Perlin. Use an 8-bit parent format. + +| Case | Size | Seed | Format | Basic exact / total | Basic max | Ridged exact / total | Ridged max | +|---|---:|---:|---|---:|---:|---:|---:| +| Default | 128² | 0 | LUM8 | 16,383/16,384 | 1 | 16,384/16,384 | 0 | +| Default | 256² | 0 | LUM8 | 65,534/65,536 | 1 | 65,536/65,536 | 0 | +| Default | 128² | 42 | LUM8 | 16,384/16,384 | 0 | 16,384/16,384 | 0 | +| Changed | 128² | 0 | LUM8 | 16,384/16,384 | 0 | 16,384/16,384 | 0 | +| Changed | 128² | 42 | LUM16 | 16,360/16,384 | 1 | 16,304/16,384 | 1 | +| Changed | 128² | 42 | LUM16F | 16,384/16,384 | 0 | 16,378/16,384 | 4.8828125e-4 | +| Changed | 128² | 42 | LUM32F | 12,105/16,384 | 5.066395e-7 | 3,119/16,384 | 4.172326e-7 | + +The changed float case previously matched 10,399 pixels for basic Perlin and 3,926 for ridged Perlin. Whole-graph rounding remains visible in both. A separate seed-zero comparison used each app's shipped lookup, with MaterialCraft's tracked CC0 image read from Git. Basic Perlin matched 173/16,384 at 128² and 662/65,536 at 256², with maximum errors of 203 levels at both sizes. Ridged Perlin matched 176/16,384 and 768/65,536, with maximum errors of 139 and 154 levels. The shared lookup isolates an asset-dependent difference from the arithmetic. + +### Grayscale and color 3D planar projection + +Bind the position ramp above and a constant world-space normal of RGBA8 `(128,128,255,255)`. The grayscale texture is `T=(17*x+31*y) mod 256`. The color texture is RGBA8 `(T,R,255-G,(251+3*x+5*y) mod 256)`, where R and G are the position ramp bytes. Keep all input maps linear and the same size as the graph. The rotated case sets `rotation=.125` and `scale=.38`. Each format pair below gives the grayscale and color output formats respectively. + +| Case | Size | Seed | Formats | Grayscale exact / total | Gray max | Color exact / total | Color max | +|---|---:|---:|---|---:|---:|---:|---:| +| Default | 128² | 0 | LUM16, RGBA8 | 16,384/16,384 | 0 | 16,384/16,384 | 0 | +| Default | 256² | 0 | LUM16, RGBA8 | 65,536/65,536 | 0 | 65,536/65,536 | 0 | +| Default | 128² | 42 | LUM16, RGBA8 | 16,384/16,384 | 0 | 16,384/16,384 | 0 | +| Rotated | 128² | 0 | LUM16, RGBA8 | 16,334/16,384 | 226 | 16,378/16,384 | 1 | +| Rotated | 64² | 42 | LUM8, RGBA8 | 4,094/4,096 | 1 | 4,094/4,096 | 1 | +| Rotated | 64² | 42 | LUM16, RGBA16 | 4,093/4,096 | 32 | 4,093/4,096 | 32 | +| Rotated | 64² | 42 | LUM16F, RGBA16F | 4,093/4,096 | 4.8828125e-4 | 4,093/4,096 | 4.8828125e-4 | +| Rotated | 64² | 42 | LUM32F, RGBA32F | 4,093/4,096 | 4.882888e-4 | 4,093/4,096 | 4.882888e-4 | + +Before the sampler change the default 256² cases matched 65,048 grayscale pixels and 65,492 RGBA pixels. An independent one-processor graph isolates the integer texture read. In a 256² source, use the 2×2 block starting at (12,15). Light one corner at a time, then repeat with corner levels `(.37,.13,.91,.68)` rounded to the input precision, in row-major order. For output pixel (x,y), sample at `((12.5+x/256)/256,(15.5+y/256)/256)`. Run all five patterns with RGBA8 and RGBA16 input and read the red channel into LUM32F. All 655,360 pixels match exactly. + +In units of 1/256 texel, the rounded horizontal and vertical fractions are `dx` and `dy`. The bottom-right weight is `q=floor((dx*dy+128)/256)`. The other three weights in row-major order are `256-dx-dy+q`, `dx-q` and `dy-q`. Accumulate the four normalized 16-bit levels with these integer weights, divide by 256 and round half up. A separate 128² high-frequency texture sweep at seven fixed offsets matched all 114,688 pixels, including wrapped edges. The rotated graph cases still differ with this sampler. Floating-source filtering has separate rounding behavior and remains open. + +### 3D surface and volume render passes + +The four rows of the inventory preceding `position_debug` share one package. The small output side `N` is 16 for irradiance, volume IBL and volume light, and 32 for surface position. The large case doubles both dimensions. The surface position parent is 8-bit. The other parents are float32. At the small and large sizes, generate new input ramps with byte values `U=floor(255*(x+.5)/N)` and `V=floor(255*(y+.5)/N)`. Bind all images as linear. + +- Surface irradiance uses a constant float SDF of 128, position `(U,V,128,255)`, normal `(128,128,255,255)`, sample table `(64,64,255,255)`, environment `(U,V,192,255)` and grayscale noise `(17*x+31*y) mod 256`. The changed case sets `i=16` and albedo to `(.3,.6,.9)`. +- Surface position uses a constant white SDF. The changed case enables the ground plane and sets camera UV to `(.35,.6)` and field of view to 65 degrees. +- The volume passes use constant float SDF −.1 and density .001, the same position ramp, and the noise formula evaluated at the noise input's native 256². IBL also uses the irradiance sample table and environment. Its changed case sets `i=1` and absorption to 2. Volume light sets light intensity to 2 and light UV to `(.3,.6)` for its changed case. + +Each cell gives **exact pixels / total (maximum error)**. The native output formats in column order are RGBA32F, RGBA8, RGBA16F and RGBA16F. + +| Case | Surface irradiance | Surface position | Volume IBL | Volume light | +|---|---:|---:|---:|---:| +| Small, defaults, seed 0 | 0/256 (8.940697e-8) | 1,024/1,024 (0) | 9/256 (.00634765625) | 250/256 (6.103516e-5) | +| Large, defaults, seed 0 | 0/1,024 (7.450581e-8) | 4,096/4,096 (0) | 44/1,024 (.00634765625) | 994/1,024 (.0001220703125) | +| Small, defaults, seed 42 | 0/256 (8.940697e-8) | 1,024/1,024 (0) | 8/256 (.00537109375) | 250/256 (6.103516e-5) | +| Small, changed, seed 0 | 0/256 (8.940697e-8) | 1,023/1,024 (1) | 9/256 (.009765625) | 250/256 (6.103516e-5) | +| Small, changed, seed 42, RGBA8 | 256/256 (0) | 1,023/1,024 (1) | 69/256 (3) | 255/256 (1) | +| Small, changed, seed 42, RGBA16 | 256/256 (0) | 1,023/1,024 (246) | 0/256 (701) | 250/256 (2) | +| Small, changed, seed 42, RGBA16F | 256/256 (0) | 410/1,024 (4) | 3/256 (.0107421875) | 250/256 (6.103516e-5) | +| Small, changed, seed 42, RGBA32F | 0/256 (8.940697e-8) | 0/1,024 (.67333984375) | 0/256 (.010691524) | 0/256 (4.068762e-5) | + +**Irradiance.** Replace noise by zero, environment by `(64,128,192,255)` and position by `(128,128,128,255)`. Both renders become spatially constant and all six input bridges match. RGB still differs by at most 8.940697e-8 and alpha is exact. Changing only the sample table from byte `(64,64,255,255)` to float `(.25,.25,1,1)` makes all 256 RGBA32F pixels exact. Replacing only the normal by `(.5,.5,1,1)` gives 0/256 and maximum error 1.192093e-7. The remaining difference depends on the sampled direction even with flat lighting. + +**Surface position.** A black SDF with defaults at 16² matched 256/256 RGBA8 pixels. The changed camera at 64² still matches 4,092/4,096 with maximum error 2. At 32² and RGBA32F, changing only field of view gives 0/1,024 with maximum error 1.490116e-7. Changing only camera UV gives 0/1,024 with maximum error 1.269579e-5. With both changes the largest error occurs at (0,2), where X is −7683.423 in MaterialCraft and −7684.096 in the reference. Alpha agrees at every pixel. Integer storage hides much of this coordinate difference. + +**Volume integration.** At 16² and RGBA32F, replace noise by zero, position by `(128,128,128,255)` and the IBL environment by `(64,128,192,255)`. All six IBL inputs and all four light inputs match exactly. IBL still gives 0/256 with maximum error .00578630. Disabling dithering reduces this to 3.039837e-6 with 16/256 exact at both seeds 0 and 42. With nonconstant inputs and dithering disabled the maximum is .0002391934 and 12/256 match. Light gives 0/256 on the flat inputs with maximum error .0001328364, or .0001164377 with dithering disabled. Setting density to zero makes both flat, undithered renders exact at all 256 pixels. Nonzero-density integration remains open. + +### Position debug + +All **622,592/622,592 RGBA pixels** match across 14 cases, with maximum component error zero. The two previously failing 256² sphere cases match the original reference captures, including all 17 colored texels in each. Changing `debug_pos` from `(.5,.5)` to `(.25,.75)` changes four pixels between reference images. Both internal 4096² processors cook at full size. + +Use a float32 parent, the RGBA8 position ramp above and an original signed-distance atlas. For side `N=128` or 256, let `s=N/16`, `X=((x mod s)+.5)/s-.5`, `Y=((y mod s)+.5)/s-.5`, and `Z=(floor(x/s)+16*floor(y/s)+.5)/256-.5`. Compute `sqrt(X²+Y²+Z²)-.3` and store the result in each RGB channel of a float32 EXR with alpha 1. + +| Probe | Size | Seed | Output formats | Exact pixels / total | Maximum error | +|---|---:|---:|---|---:|---:| +| Default debug point | 128² | 0 and 42 | RGBA32F | 32,768/32,768 | 0 | +| Default and changed debug point | 256² | 0 | RGBA32F | 131,072/131,072 | 0 | +| Changed debug point | 128² | 42 | RGBA8, RGBA16, RGBA16F, RGBA32F | 65,536/65,536 | 0 | +| Changed debug point | 256² | 42 | Same four formats | 262,144/262,144 | 0 | +| Changed point, plane and shifted sphere | 256² | 42 | RGBA32F | 131,072/131,072 | 0 | + +The plane uses `.55*X+.3*Y-.7*Z+.06`. The shifted sphere uses `sqrt((X-.125)²+(Y+.1)²+(Z-.125)²)-.36`. Both produced the same sparse marker as the centered sphere for the changed debug point. The 128² cases had zero colored texels. The parity mark covers these output images and settings. + +### Panoramic LOD + +The panorama helper exposes one image input. For its first-pass fixtures, let `U=floor(255*x/(N-1))`, `V=floor(255*y/(N-1))` and `T=(17*x+31*y) mod 256`. Bind linear RGBA8 `(T,U,255-V,255)`. The alpha case uses `(7*x+13*y) mod 256` for A. The new reference outputs for all three first-pass cases match their archived raw pixels exactly. The fractional-alpha input and opaque input produce identical output here. The four 64² cases use the varying-alpha color texture from the planar projection comparison. + +| Input | Size | Seed | Format | Exact pixels / total | Maximum error | +|---|---:|---:|---|---:|---:| +| Opaque | 128² | 0 and 42 | RGBA8 | 15,883/16,384 each | 125 | +| Opaque | 256² | 0 | RGBA8 | 63,309/65,536 | 126 | +| Varying alpha | 128² | 0 | RGBA8 | 15,883/16,384 | 125 | +| Flat (23,139,211), alpha 75 or 255 | 128² | 0 | RGBA8 | 16,128/16,384 each | 116 | +| Varying alpha | 64² | 42 | RGBA8 / RGBA16 | 3,964/4,096 each | 1 / 257 | +| Same input | 64² | 42 | RGBA16F / RGBA32F | 3,964/4,096 each | .00439453125 / .0039215982 | + +MaterialCraft previously sampled the full-resolution input for every bilinear transform. The 128² and 256² opaque cases then matched 719 and 5,015 pixels. An isolated transform uses a 2048×1024 RGBA8 input `(T,x mod 256,(255-y) mod 256,255)`, a 128² output, matrix `diag(-1,1.99309003)`, offset `(0,.5)`, horizontal-only wrap and opaque black matte. Its input bridge matches all 2,097,152 texels. The transform improved from 8,216/16,384 (maximum 117) to 16,384/16,384 (0). Changing the vertical scale to 2 improved from 8,192/16,384 (103) to 16,384/16,384 (0). When the first-pass 128² input is resized to the same 2048×1024 bridge, 1,923,823/2,097,152 input texels match (maximum 2). The two transforms give 16,287 and 16,284 exact output pixels, both with maximum 1. The full graph still differs along rows 0 and 47 with a flat input. + +For an independent mip-level check, generate a 128² RGBA grid using the row-major unsigned hash from the gradient probe. Use the low 8 or 16 bits of the final hash for each integer channel. For a signed float input store `4*hash/2^32-2` in float32. Run an identity transform at 128², 64², 32² and 16². With automatic mip selection, both RGBA8-to-RGBA8 and RGBA16-to-RGBA16 match 21,760/21,760 pixels with zero error. For RGBA8 input and output, setting the manual mip level to 0, 1 or 2 also gives 21,760/21,760 at each level. An automatic uniform scale of 1.5 gives the same exact count. For the signed RGBA32F input and output, the four sizes match 16,384, 2,781, 308 and 29 pixels respectively, with maxima 0, 1.192093e-7, 5.960464e-8 and 2.980232e-8. Float filtering remains open. + +### 3D volume mask and Worley noise + +Use the first-pass linear position texture. For side `N`, store RGBA8 `(floor(255*x/(N-1)),floor(255*y/(N-1)),128,255)`. The mask's rotated case uses cylinder shape 1, rotation `(.1,.2,.3)`, size `(.8,.6,1)` and feather width .1. The Worley border case sets style 1, border width .2 and roundness .1. For its 64² output-format sweep, round the two position channels to nearest instead of flooring. Each cell gives exact pixels / total (maximum error). + +| Case | Volume mask | Worley noise | +|---|---:|---:| +| 128², defaults, seed 0, LUM16 | 16,384/16,384 (0) | 1/16,384 (44,494) | +| 256², defaults, seed 0, LUM16 | 65,536/65,536 (0) | 3/65,536 (44,494) | +| 128², defaults, seed 42, LUM16 | 16,384/16,384 (0) | 1/16,384 (43,865) | +| 128², scale .4 for mask or 6 for Worley, seed 0, LUM16 | 16,384/16,384 (0) | 2/16,384 (40,476) | +| 128², rotated mask or Worley border, seed 0, LUM16 | 16,326/16,384 (1) | 1/16,384 (32,729) | +| Same settings, seed 42, LUM8 (mask 128², Worley 64²) | 16,383/16,384 (1) | 45/4,096 (138) | +| Same sizes and seed, LUM16 | 16,326/16,384 (1) | 0/4,096 (35,289) | +| Same sizes and seed, LUM16F | 16,349/16,384 (.0078125) | 4/4,096 (.53833008) | +| Same sizes and seed, LUM32F | 664/16,384 (.000015258789) | 0/4,096 (.53847277) | + +**Mask.** The 128² cylinder with default rotation, size and feathering gives 16,379/16,384 exact LUM16 pixels, with maximum error 1. The RGBA16 position bridge matches all 16,384 pixels. In LUM32F, changing only cylinder rotation gives 564/16,384 (1.907349e-6), only size gives 14,088/16,384 (9.536743e-7), and only feather width gives 13,716/16,384 (3.814697e-6). A cube with `position_input=1` and `position_worldspace=(.375,.375,.5)` matches 16,384/16,384 float pixels exactly. + +**Worley.** With a constant input position of `(0,0,0,255)`, no LUM32F pixel matches in the 32² default case at seed 0 (maximum .02120566) or seed 42 (.07068205). The graph's internal random table uses four draws. A standalone Pixel Processor writing four successive `rand(1)` values to RGBA16 reproduces a discrepancy before any cell-distance calculation. It gives 0/1,024 exact pixels at 32², seed 0 (maximum 65,122), 0/16,384 at 128², seed 0 (65,136), and 0/16,384 at 128², seed 42 (65,348). At seed 0 the first reference pixel changes with resolution, from `(47238,35719,5497,27913)` to `(37730,56747,64327,4184)`. MaterialCraft returns `(42015,40251,56435,61318)` at both sizes. The subsequent [per-pixel initialization comparison](#per-pixel-random-initialization) covers these settings and the complete 34-render Worley matrix. + +### November 17 validation + +All six new regression tests failed with their corresponding fixes disabled or absent. The release suites for nodes, evaluation and formats passed 246 tests. Two opt-in format interoperability tests were skipped. Workspace formatting, strict all-target Clippy, dependency layers and WebAssembly checks passed. Raw captures and generated input images were kept outside the repository. + ## Remaining differences +The following entries record the first pass. The dated comparisons above give the newer results for revisited roots. + - **`3d_gradient.sbs/3d_linear_gradient` - Too hard for this pass:** Corrected the wrong channel mapping and normalized-integer bilinear sampling offset. Compared generated position maps in UV and world modes, with zero and nonzero contrast, at 256 and 512 pixels (eight cases). Remaining 32-bit differences reach 7.153e-7; some values straddle a 16-bit rounding boundary by one level. The default world-mode case matches every pixel after 16-bit conversion at both sizes, but full float parity is not established. Further work needs matching the reference shader arithmetic rounding. An unconnected Position input yields NaNs in the reference app; MaterialCraft retains its actionable non-finite arithmetic error. Moving to the next node. - **`3d_perlin_noise.sbs/3D_perlin_noise` - Too hard for this pass:** Exact at 128x128 for defaults, seed 42, and scale 6. At 256x256, 3 of 65,536 eight-bit pixels remain one level different: (x=246,y=155), (25,179), and (154,227). Input maps are generated linear XY ramps with Z=128/255 and alpha=1. The output-format error is fixed; residual arithmetic/conversion rounding still prevents a parity mark. @@ -79,7 +17092,7 @@ The first pass classifies all 546 roots: 166 Parity and 380 Too hard. These meas - **`3d_texture_render.sbs/position_debug` - Too hard for this pass:** Initial zero/positive/midpoint fields and checker fields produce constant images and are insufficient for a parity mark. A generated signed sphere-distance atlas and original position map produce nonconstant 256x256 RGBA32F outputs. Center and changed debug-selection cases each match 65,519/65,536 pixels; 17 pixels per case differ by up to 1.0. Both internal 4096x4096 processors cook at full native size. -- **`3d_volume_mask.sbs/3d_volume_mask` - Too hard for this pass:** Corrected omitted nearest sampling and finite clamping after division by zero. Default 128x128, default 256x256, and changed-scale 128x128 outputs are exact (98,304 sixteen-bit pixels). Box mode has four one-level differences; rotated, resized, narrow-feather box mode has 58 one-level differences. All five cases cook successfully. +- **`3d_volume_mask.sbs/3d_volume_mask` - Too hard for this pass:** Corrected omitted nearest sampling and finite clamping after division by zero. Default 128x128, default 256x256, and changed-scale 128x128 outputs are exact (98,304 sixteen-bit pixels). Cylinder mode has four one-level differences; rotated, resized, narrow-feather cylinder mode has 58 one-level differences. All five cases cook successfully. - **`3d_worley_noise.sbs/3D_worley_noise` - Too hard for this pass:** All cooks succeed, but the noise field differs substantially. Defaults at 128x128/256x256, seed 42, scale 6, and border style have only 1, 3, 1, 2, and 1 matching sixteen-bit pixels respectively; maximum difference is 44,494 levels. Changing omitted sampler defaults does not resolve this. @@ -1101,7 +18114,7 @@ The first pass classifies all 546 roots: 166 Parity and 380 Too hard. These meas - **`pbr_render2.sbs/height_adjust` - Parity:** All 98,304 output pixels (LUM8) match across 3 recorded cases: defaults at 128x128/256x256 and seed 42. Connectable value pins retain their defaults; nondefault values require a wired reference fixture and remain unverified. -## Validation +## First-pass validation - Final release CLI and native desktop builds pass, including the unassigned-variable, grayscale Pixel Processor, integer-conversion, and output-bridge changes. Formatting, dependency layers, and all ten WebAssembly crate checks pass. An independent inventory rescan agrees with all 546 roots, and all 320 package links resolve. - Workspace Clippy is blocked by an existing `chunks_exact_to_as_chunks` lint in the text primitive. Clippy for the four changed library crates passes with that existing lint suppressed. diff --git a/docs/sbs-root-nodes.md b/docs/sbs-root-nodes.md index 0066be80..c18a1082 100644 --- a/docs/sbs-root-nodes.md +++ b/docs/sbs-root-nodes.md @@ -15,8 +15,11 @@ for this inventory. - Input pins are reported for context: image inputs (type `1` or `2`) and value inputs with `isConnectable=1`. Ordinary exposed parameters are not input pins. - Paths retain package folders and exact graph identifiers; each link opens the containing SBS package. Paths are relative to `assets/sbs/`. -This is a structural inventory for MaterialCraft's clean-room implementation. It does not -assert that graphs cook successfully or are independent of bitmap resources. +The inventory describes the structure of the repository's SBS files. A listed root can still +need an external bitmap or fail to render. The project records the maintainer's authorship +statement for the graph library and the individual resource licenses in its [asset attribution](../ATTRIBUTION.md). +Each parity result links to measured outputs for specific cases. The [comparison method](parity-fixes.md#comparison-method-and-provenance) +explains how to read the raw-pixel counts, typed values and local evaluator traces. ## Results @@ -35,56 +38,256 @@ 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 covers all **546 roots**: **166 Parity** and **380 Too hard**. Parity applies only to the recorded cases; it is not a claim of complete functional parity. +The first pass covered all **546 roots**, with **166 Parity** and **380 Too hard**. The current inventory has **494 Parity (90.5%)**, **52 In progress** and **0 Too hard**. The first eleven open roots match every pixel across 1,059 recorded single-processor settings. Each still differs in at least one eight-processor capture. The November 17–28 comparisons give 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) · [November 22 measurements](parity-fixes.md#2026-11-22-root-comparisons) · [November 23 measurements](parity-fixes.md#2026-11-23-root-comparisons) · [November 24 measurements](parity-fixes.md#2026-11-24-root-comparisons) · [November 25 measurements](parity-fixes.md#2026-11-25-root-comparisons) · [November 26 measurements](parity-fixes.md#2026-11-26-root-comparisons) · [November 27 measurements](parity-fixes.md#2026-11-27-root-comparisons) · [November 28 measurements](parity-fixes.md#2026-11-28-root-comparisons) + +Writable quadrant tints now match 16,896/16,896 pixels in 44 settings across four output formats, up from 4,608. Fixed and published inputs through a graph instance match 3,840/3,840 original and 3,840/3,840 reopened pixels. Connected image properties match all 18,432 original and all 18,432 reopened pixels across 32 settings, up from 15,168 on each side. Live float4 and integer initial values remain open. The earlier explicit undefined-tint controls covered 70,656 pixels across original squares, ordinary saves, Gaussian and ramp shapes and connected images. [Connected images](parity-fixes.md#connected-image-properties-and-the-first-quadrant-draw) · [Writable floats](parity-fixes.md#first-reads-of-writable-quadrant-floats) · [Explicit undefined tints](parity-fixes.md#undefined-components-in-a-computed-quadrant-tint) + +Six upstream filters now match 27,648/27,648 original and 27,648/27,648 reopened pixels across four output formats, up from 24,192 on each side. Both directions of an image connection through a graph instance also match 4,608/4,608 F32 pixels on each side. [Published filter properties, fixed controls and raw errors](parity-fixes.md#published-filter-properties-upstream-of-a-quadrant-draw) + +At least **50 of the 52 open roots** have two different reference outputs for the same graph settings on one and eight processors. This includes the first eleven open roots, 31 later noise roots and eight moisture, caustic, scratch and fiber roots. Across twelve returns per processor count, MaterialCraft matches every pixel that stayed fixed across all 24 reference captures in three measured F32 settings. Spots 1 gives 259/259, Moisture Noise 4,088/4,088 and Wood Fibers 1 4,070/4,070. Individual frames still differ. At 128 × 32, both Moisture Noise pattern nodes now finish their 36 emitted trees. All 16,384 whole-root pixels match across four formats on one and eight processors and again after ordinary saves. [Dense quadrants and the Dirt 4 rectangle](parity-fixes.md#dense-seeded-quadrants-in-moisture-noise-and-dirt-4) [Repeated pixel counts and iteration controls](parity-fixes.md#repeated-noise-pixels-and-the-moisture-noise-iteration-count) [31-root comparison by format](parity-fixes.md#reference-repeatability-across-31-open-noise-roots) · [Eight further roots and fixed-processor repeats](parity-fixes.md#reference-variation-in-eight-further-roots) + +An explicit file link into the configured library also survives an ordinary save when the library later changes. Four Waveform v2 callers reproduce 8,448/8,448 original pixels under both library settings. [File and catalog links](parity-fixes.md#keeping-an-explicit-file-link-when-the-configured-library-changes) + +The reference app’s own ordinary Save also preserves relative package links in Points Preview and Waveform v2. Its compiler rejects their older detached dependencies after either application saves only the caller. Opening and saving the external packages at their existing paths restores all 2,048 Points Preview pixels and all 256 Waveform pixels in these five reference-saved callers on both processor counts. [Live links and compiler results](parity-fixes.md#ordinary-save-in-the-reference-app-with-the-same-live-dependencies) + +Both roots in `tile_random.sbs` now match 484,864/484,864 pixels across 221 settings with either live edits or freshly bound images. Each setting matches one and eight reference processors. Replaying the edits on ordinary saves also matches every pixel. All 32 preconfigured files opened directly with 106,496/106,496 pixels exact. An independent control that edits one of two graph instances now matches all 26,624 F32 pixels with its child fixed at 32². Maximum error is zero on every route. [Whole-root counts, edit sequence and remaining instance differences](parity-fixes.md#live-preview-sampling-in-tile-random) + +In separate paired instances, the child image bridge now follows the dimensions of its own input wire. All 120 bridge outputs match 203,264/203,264 pixels, with another 18,432/18,432 on each of the original and ordinary-save routes in four formats. [Bridge reproduction](parity-fixes.md#input-relative-dimensions-on-a-child-image-bridge) The FX-Map now inherits size and storage precision from its background. All 20 downstream outputs match 32,256/32,256 pixels and the twelve explicit precision cases match 5,632/5,632. [Pattern background reproduction](parity-fixes.md#input-relative-size-and-precision-on-a-pattern-background) + +The two roots in `pattern_tile_random.sbs` match all 425,216 grayscale pixels in 104 settings and all 728,832 color pixels in 179 settings. Each output format matched on one processor, eight processors and ordinary reopen. [Whole-root settings and the shared pattern property correction](parity-fixes.md#returned-vectors-in-pattern-properties) + +The color graph in `pattern_tile_generator.sbs` matches 777,472/777,472 pixels across 339 distinct settings on one processor, on eight and after reopening an ordinary save. The additional 320 single-channel color settings match 128,000/128,000 archived F32 pixels. [Settings, exact counts and maximum errors](parity-fixes.md#component-reads-in-color-tile-function-arguments) + +The two roots in `pattern_splatter_circular.sbs` each match all 216,064 pixels across 70 distinct settings on one processor, on eight and after reopening an ordinary save. [Grayscale and color counts by format](parity-fixes.md#circular-pattern-angles-and-random-draws-with-computed-bounds) + +Grayscale Splatter Circular and Splatter Circular Color each match 190,720/190,720 pixels across 62 distinct settings on one processor, on eight and on ordinary reopen. [Grayscale settings and counts](parity-fixes.md#grayscale-splatter-circular-across-four-output-formats) · [Color settings and counts](parity-fixes.md#splatter-circular-color-and-assignments-before-a-later-function-call) + +Stored pattern-vector arithmetic matches all 36,096 F32 pixels in 141 settings on both processor counts and after an ordinary save. Regression comparisons on 36 previously qualified roots match 1,350,656/1,350,656 pixels. [Vector order and exact counts](parity-fixes.md#storing-computed-vectors-in-a-quadrant-function) + +Shared draws and packed channel selections around pure pattern functions now match all 23,040 pixels in 90 procedural settings on both processor counts and on ordinary reopen. The 221 grayscale Tile Generator settings and 71 settings from 15 other qualified roots remain exact. At that revision, the two roots in `pattern_splatter_circular.sbs` matched 13 of 54 whole settings each. [Exact counts, controls and remaining differences](parity-fixes.md#shared-draws-and-channel-selection-across-pure-pattern-calls) + +Pattern Fibers 1 matches all 24 established outputs and twelve further rectangular settings, on one processor, on eight and after saving. [Parameters and exact counts](parity-fixes.md#pattern-fibers-1-at-default-and-changed-tiling) + +Pattern Weave 2 matches all 95 whole settings on one and eight processors and after saving. All 43 earlier saved renders also match. [Whole results by storage format](parity-fixes.md#full-pattern-weave-2-comparisons-at-both-processor-counts) + +Arc Pavement matches all 93 whole settings on both processor counts and after an ordinary save, including the previously differing image and analytic shapes. [Exact counts by format and the reopened comparisons](parity-fixes.md#full-arc-pavement-comparisons-across-shape-selections-and-ordinary-saves) + +Noise Clouds 1 v2 and Noise Clouds 2 v2 now each render 60/60 established originals and 15/15 archived saves. Directional Noise 3 v2 at 64 × 16, seed 42, matches all 4,096 original and all 4,096 reopened pixels across four formats at both processor counts. [Root and procedural comparisons](parity-fixes.md#rectangular-clouds-and-directional-noise-graphs-with-seeded-quadrant-offsets) Two 128 × 128 outputs and their ordinary saves render with the remaining differences measured below. [Raw word counts and the four remaining Clouds rectangles](parity-fixes.md#two-more-whole-outputs-in-noise-clouds-1-v2) + +Noise BNW Spots 3 v2 renders all 62 established originals and all 14 archived ordinary saves. Its last archived U8 rectangle matches 2,048/2,048 pixels on both processor counts. At 32 × 16, seed 105532, Dirt 4 v2 matches all 2,048 pixels across four formats on its originals and ordinary saves. Both roots reproduce their MaterialCraft originals on eight configured reopens, 10,240/10,240 pixels. [Saved outputs and cook times](parity-fixes.md#ordinary-saves-and-release-cook-times-for-the-two-rectangles) [Bound arithmetic in seeded quadrant properties](parity-fixes.md#bound-arithmetic-in-seeded-quadrant-properties) + +At three 64 × 64 F32 residuals in BNW Spots 3 v2, 33 individual stamps and nine ordered sums match every pixel on both processor counts and on ordinary reopen. [Stamp values and reduced trees](parity-fixes.md#individual-paraboloids-and-additive-order-in-noise-bnw-spots-3-v2) + +Two independent sets of Iterate seed controls now match 20,480/20,480 pixels on one and eight processors and on ordinary reopen. The 38 established Tile Random originals and their saves retain their previous pixel words. [Branch seeds, storage formats and whole-root errors](parity-fixes.md#the-incoming-seed-on-the-initial-branch-of-an-iterate) + +With tiling off, 52/60 additional settings across eight Noise graphs render at 16 × 32 and 32 × 16. Of the 52 completed buffers, 35 match exactly on one processor, 36 on eight and 35 on ordinary reopen. [Per-format exact counts, maximum errors and remaining work limits](parity-fixes.md#untiled-spots-clouds-directional-noise-and-dirt-at-two-rectangular-sizes) + +Wood Fibers 2 now renders all 18 established settings. Its previously blocked 256 × 256 default matches 65,381/65,536 archived U16 pixels, with maximum error two levels. Across ten tiled Noise roots, 48/60 settings and their ordinary saves render. [Per-root scores, seeds, parameters and remaining execution limits](parity-fixes.md#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) + +Noise Dirt 4, Noise Moisture Noise 1 v2 and Noise Moisture Noise 2 now render their earlier blocked 32 × 32 setting at seed 113. The new defaults and changed parameters cover 24 original renders and 24 ordinary saves. [Exact pixels and maximum error by storage format](parity-fixes.md#recovered-dirt-4-and-moisture-renders-at-seed-113) + +Noise BNW Spots 1 v2 matches both untiled rectangles in U8, U16 and F16 on one processor and after saving. Noise BNW Spots 3 v2 matches its untiled 16 × 32 default in the same three formats. F32 differences remain. [Whole outputs, normal saves and iterator comparisons](parity-fixes.md#untiled-spots-outputs-and-the-second-dirt-gradient-iteration) + +Noise Dirt Gradient v2 matches both untiled U8 and F16 rectangles on one processor and after ordinary saves, 2,560/2,560 pixels in each format. Five of the eight whole settings match on each route. [Axis-specific background filtering, stored counts and remaining differences](parity-fixes.md#filtering-a-resized-pattern-background-on-each-axis) + +The single-tree controls of Noise Dirt 5 match all 5,120 F32 pixels on one processor and after an ordinary save. Summed over 20 independent window and format settings, 737,280/737,280 pixels match on both one-processor routes. The eight-processor capture matches 732,040/737,280. [Reproduction and per-window maximum errors](parity-fixes.md#a-complete-quadrant-tree-with-one-physical-copy-per-draw) + +Noise Dirt 5 now renders all 60 originals and all 12 archived ordinary saves in its tiled series. Complete images match in 31/60 comparisons on one processor, 30/60 on eight and 8/12 archived saves. At seeds 113 and 42 a difference of one U16 level appears at the FX-Map output before Levels. [Raw counts, repeated captures and shared branch expressions](parity-fixes.md#shared-branch-expressions-and-all-sixty-noise-dirt-5-renders) · [Ten earlier recovered settings](parity-fixes.md#ten-recovered-whole-noise-dirt-5-settings) + +Noise Dirt 1 matches all 43,008 pixels in 12 further settings and Noise Dirt 5 all 40,960 in eight, both on one processor and after ordinary saves. Noise Dirt 1 v2 at 64 × 32 also improved from 1,981 to 2,048 exact F32 pixels. [Tiled subtrees, threshold controls and eight-processor scores](parity-fixes.md#deferring-two-tiled-subtrees-until-a-quadrant-batch-fills) Noise Dirt 1 matches 41/60 ordinary tiled settings on one processor and 32/60 on eight. Noise Dirt 2 matches 53/60 on one and 51/60 on eight. Two wider Noise Dirt 1 originals match 10,239/10,240 F32 pixels on one processor. Their ordinary saves match all 10,240. [Receiving quadrant, independent fields and Noise Dirt 5 comparisons](parity-fixes.md#the-receiving-half-of-a-quadrant-in-two-tiled-trees) Three additional tall Noise Dirt 1 images and their saves match 43,008/43,008 F32 pixels on one processor. [Four-batch threshold and rectangular comparisons](parity-fixes.md#four-full-batches-in-two-tiled-quadrant-trees) [Two-tree tile copies, all formats and ordinary saves](parity-fixes.md#tiled-copies-across-two-complete-quadrant-trees) [Earlier tiled measurements](parity-fixes.md#fixed-image-draws-in-tiled-dirt-graphs) With graph tiling off, Noise Dirt 5 and Noise Dirt Gradient each match eight additional settings and their ordinary saves, 10,240/10,240 pixels per graph. [Five related roots, iteration counts and remaining errors](parity-fixes.md#whole-untiled-dirt-relatives-and-the-depth-seven-iteration) With graph tiling off, Dirt 1 matches all 13 original and reopened settings on one processor and all nine additional settings at three other seeds. [Two-tree order, raw counts and ordinary saves](parity-fixes.md#unfinished-draws-across-two-untiled-quadrant-trees) [Earlier single-tree comparisons](parity-fixes.md#fixed-image-draw-order-in-untiled-noise-dirt-1) In Dirt 1 at 128 × 256, all 32,764 locations shared by seven U16 reads now match. At (59,61) the five individual draws are each exact. Two signed controls independently confirm their order in the combined reference image. [Individual draw comparisons](parity-fixes.md#five-individual-image-draws-at-one-dirt-1-pixel) [Isolated drawing depths and raw values](parity-fixes.md#individual-drawing-depths-at-a-dirt-1-rounding-boundary) On Dirt 2 every one of the 785,643 invariant reference pixels is exact. [Complete render coverage, errors and timing](parity-fixes.md#complete-render-coverage-for-the-two-fixed-image-dirt-graphs) [Formats and repeat comparisons](parity-fixes.md#expanded-image-and-save-comparisons-for-dirt-1-and-dirt-2) Both measured Dirt 2 formats at 32 × 16 match all 512 original and reopened pixels. The Dirt 1 v2 rectangle still reaches its traversal limit. [Whole images and procedural input controls](parity-fixes.md#streaming-deep-quadrants-that-draw-the-same-connected-image) + +Dirt 3 and Dirt Gradient have each produced all 60 established originals across the recorded passes. A signed pair of depth-seven contributions isolates the stable one-level Spots 3 difference at (30,57). [Dirt-family comparisons](parity-fixes.md#rectangular-dirt-family-settings-recovered-by-the-shared-evaluator) · [Spots 3 draw order](parity-fixes.md#two-depth-seven-draws-at-a-stored-rounding-boundary) + +Directional Noise 3 has rendered 52 of 60 original settings and ten of twelve archived ordinary saves. The eight newly completed originals match 52,138/52,224 pixels on one processor and 52,156/52,224 on eight. [Drawing parents, per-format errors and ordinary saves](parity-fixes.md#drawing-parents-and-terminal-children-in-directional-noise-3) [Rectangular raw comparisons](parity-fixes.md#accounting-for-a-streamed-draw-and-its-tile-copies) [Extended comparison and ordinary saves](parity-fixes.md#rectangular-and-additional-seed-coverage-in-directional-noise-3) Across the 17 completed outputs in the first 19 settings, 141,209/141,568 pixels matched on one processor and 141,288 on eight. [Storage breakdown and two ordinary saves](parity-fixes.md#streaming-equal-ranked-analytic-stamps-through-one-output-image) Directional Noise 1 v2 renders all 60 originals and all 12 ordinary saves. Both still have pixel differences. [Recovered Directional Noise 3 settings](parity-fixes.md#reused-properties-across-adjacent-groups-of-terminal-quadrants) · [Complete Directional Noise 1 v2 comparison](parity-fixes.md#complete-render-coverage-in-the-second-version-of-directional-noise-1) + +Noise BNW Spots 3 v2 renders two more originals and one more ordinary save at 128 × 512. Noise Clouds 1 now renders all 60 originals and 15 saves, with 43, 37 and 9 complete images exact on the one-processor, eight-processor and reopened comparisons respectively. [Tall Spots 3 v2 render](parity-fixes.md#sample-coverage-of-narrow-and-circular-quadrant-stamps) · [Complete Clouds 1 comparison](parity-fixes.md#complete-rectangular-render-coverage-in-the-first-clouds-graph) + +Noise BNW Spots 3 now renders all 62 established settings and all 14 ordinary saves. Complete images match in 34/62 one-processor originals, 32/62 eight-processor originals and 8/14 saves. The eight previously blocked rectangular settings all render. Across four formats at 64 × 16 and 64 × 32 it matches 12,288/12,288 pixels on one processor and 12,287/12,288 on eight. One U16 pixel differs by one level. Its two previously blocked ordinary saves match 3,072/3,072 pixels. [Parameters, shared evaluator and ordinary saves](parity-fixes.md#reusing-terminal-quadrant-properties-in-dense-rectangular-renders) + +Noise BNW Spots 1 has 66/86 exact original frames on one processor, 38/86 on eight and 16/19 exact ordinary saves. Totals are 825,314/841,728, 776,619/841,728 and 196,239/196,352 pixels. At 128 × 64 seed 456809 the established F32 capture rose from 6,499 to 6,606/8,192 on one processor and fell from 6,166 to 6,105/8,192 on eight. The shared renderer carries unfinished quadrant subtrees into the next pair and collecting group. The 32 × 16 original at seed 456654 gained four exact F32 pixels on both processor settings. [Seven changed settings, ordinary saves and raw errors](parity-fixes.md#receiving-quadrant-subtrees-after-the-second-pair-fills) · [Earlier third-tree transfers](parity-fixes.md#carrying-unfinished-quadrant-draws-into-a-third-tree) · [Two-tree rectangular comparisons](parity-fixes.md#final-transfers-between-unfinished-quadrant-groups) + +Noise BNW Spots 1 v2 has 62/87 exact original frames on one processor, 58/87 on eight and 13/19 exact ordinary saves in the established settings. Three 16 × 32 settings with two active quadrant trees improved from 1,420 to 1,478/1,536 F32 pixels on one processor and on reopening. Against the fresh eight-processor capture the total went from 1,417 to 1,397/1,536. The maximum is 2⁻²³ on each route. The 64 procedural controls match 1,048,572/1,048,576 original pixels and all 1,048,576 reopened pixels. Four earlier F32 settings still match all 2,304 pixels on one processor and on reopening, and three further seeds match 2,048/2,048 on both routes. [Two-tree boundary, original settings and repeats](parity-fixes.md#finishing-a-quadrant-copy-batch-in-the-next-tree) · [Single-tree cut child](parity-fixes.md#returning-the-cut-child-of-a-completed-outer-quadrant) · [Earlier four-format totals](parity-fixes.md#completing-partial-copy-batches-above-inactive-quadrants) + +Directional Noise 1 retains 734,118/734,464 original pixels on one processor, 734,140/734,464 on eight and 123,081/123,136 across 12 ordinary saves. All seven tested interior Dot and Switch routes match 258,048/258,048 original and 258,048/258,048 reopened pixels across four formats, maximum zero. [Interior route settings and whole-root counts](parity-fixes.md#interior-routes-between-terminal-quadrants) · [Outer routes and repeated captures](parity-fixes.md#outer-routes-into-the-final-three-active-quadrant-levels) + +Nested Curvature, Curvature Smooth and Normal Sobel each match 2,304/2,304 original and 2,304/2,304 reopened pixels. Panorama 3D Position now reopens in the reference desktop and matches 2,304/2,304 pixels across six renders of an ordinary SBS save. Panorama Shape, Shape 2 and Spot each match 2,304/2,304 original and 2,304/2,304 reopened pixels in the same six settings. [Fixed vector arguments and whole-root counts](parity-fixes.md#float-vector-arguments-in-nested-functions) [Save, reopen and desktop comparisons](parity-fixes.md#ordinary-sbs-saves-with-verified-library-dependencies) [Working precision, blur inputs and whole-root counts](parity-fixes.md#output-precision-in-nested-generators-and-blurs) + +Six-level quadrant counters and first-position fields match 473,088/473,088 typed pixels on originals and again on ordinary saves. The 34 measurements across ten catalog roots with the same tree topology retain their earlier outputs. A self-referential assignment driven by a published parent value still differs. [Variable scopes, raw counts and a one-level isolate](parity-fixes.md#independent-writable-variables-in-six-level-quadrant-trees) + +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) + +An image wired through a graph instance retains its per-pin pixel size, tiling and pixel ratio. All 331,776/331,776 U16 pixels match on original and reopened flat and nested graphs. U8, F16 and F32 each match a further 73,728/73,728 pixels on both passes. [Sampling settings, overrides and raw comparisons](parity-fixes.md#sampling-properties-on-graph-inputs-and-outputs) + +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) + +Original Sequence controls and their ordinary saves each match 11,264/11,264 pixels in each of three image contexts and 44/44 typed Value Processor results. A further 72/72 typed values match across seeds and dimensions. Fourteen conditional graphs now match 14,336/14,336 pixels in each image context and 56/56 typed floats, on originals and ordinary saves. Discarded loops still differ. [Shared conditional draws and writes](parity-fixes.md#conditional-inputs-shared-across-function-branches) [Procedure, exact counts and maximum errors](parity-fixes.md#sequence-evaluation-and-scalar-random-values) + +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) + +BNW Spots 1, Clouds 1 and Clouds 2 each match 9,216/9,216 direct U16 pixels and a further 9,216/9,216 across four actual output formats. Reopened graphs have the same counts and maximum error 0. At the disputed 256² seed, all three now match 65,536/65,536 in the live desktop. The standalone renderer differs from that same desktop by six, two and four pixels. Repeated desktop cooks at eight and sixteen eligible processors also vary at 256². All new 128 × 64 captures match 8,192/8,192. The subsequent comparison matches 3,177,984/3,177,984, 787,712/787,712 and 771,328/771,328 one-processor pixels respectively. Of 32 further eight-processor frames per root at previously disputed settings, 11, 4 and 5 match completely. Each root also matches all 81,920 filtered pixels in four formats, on originals and ordinary saves. [Repeated raw outputs and first differing FX-Map texels](parity-fixes.md#archived-noise-settings-and-repeated-intermediate-reads) [Filtered root outputs](parity-fixes.md#filtering-root-outputs-through-two-graph-instances) [Multi-processor counts and stable pixels](parity-fixes.md#repeated-desktop-renders-of-the-three-early-noise-roots) All captured intermediate ports also match the desktop across three settings per root. In a seven-level additive control, 120 group pairs match 1,966,080/1,966,080 desktop pixels. [Per-root counts and renderer order](parity-fixes.md#intermediate-noise-outputs-and-the-order-of-overlapping-pattern-draws) [Direct desktop and standalone comparisons](parity-fixes.md#live-desktop-and-standalone-rendering-of-three-noise-roots) [Nested sizes, seeds and output formats](parity-fixes.md#computed-caller-sizes-on-bnw-spots-1-and-clouds-1-and-2) + +Hemisphere now matches 173,568/173,568 pixels across 25 settings. Shape Base matches 344,064/344,064 across 68 settings with its size expression active. These counts hold for the catalog original and the ordinary save, with maximum error 0. Shared size controls match 127,216/127,216 pixels across 515 settings on each side. [Graph sizes and corrected comparison procedure](parity-fixes.md#graph-output-size-functions-and-signed-offsets) + +Changing the observed generator samples in MaterialCraft reproduces the first eight-processor root output exactly for BNW Spots 1, Clouds 1 and Clouds 2. Across four reads the replay matches 131,072/131,072, 65,536/65,536 and 131,068/131,072 U16 pixels respectively, with maxima of 0, 0 and 2 codes. [Coordinates, control and repeat measurements](parity-fixes.md#replaying-the-differing-generator-samples) + +Computed integer seeds match 18,432/18,432 original and 18,432/18,432 reopened pixels. With these seeds, BNW Spots 1, Clouds 1 and Clouds 2 each match 9,216/9,216 in eight nested settings and 2,304/2,304 on the two desktop reopens. With caller-driven float operands in five seed expressions, each root improves from 6,657/26,880 exact U16 pixels to 26,880/26,880 on both originals and ordinary saves. Direct graph- and node-seed checks each match all 8,192 F32 pixels. All corrected maxima are zero. The 256² worker comparisons still differ, so all three roots remain in progress. [Runtime scalar arithmetic](parity-fixes.md#runtime-scalar-arithmetic-in-graph-and-node-seeds) [Seed inheritance and saved-file comparisons](parity-fixes.md#computed-graph-seeds-on-load-evaluation-and-save) + +A vector with one connected operand now matches 72/72 original typed values, 10/10 reopened values and 17,024/17,024 Pixel Processor and FX-Map pixels. The scan of root graph bodies found no reachable one-wire vector with its first port disconnected. [Vector construction and saved-file measurements](parity-fixes.md#single-connected-operands-in-vector-constructors) + +Panorama Plane Light matches 212,736/212,736 pixels across 32 original settings and 41,472/41,472 after reopening. [Interpolation probes and whole-root counts](parity-fixes.md#packed-products-in-the-second-endpoint-of-a-pixel-interpolation) + +The eighth specular pass in the second package (root 408) matches all 143,300 original pixels at 38 settings, all 16,704 pixels after reopening and all 81,920 intermediate F32 pixels in the environment and material controls. [Whole-root measurements](parity-fixes.md#whole-and-reopened-eighth-specular-passes) + +In the first package, all 17 default-index irradiance settings match 120,320/120,320 pixels, with 4,608/4,608 exact across nine connected-index settings after correcting input resizing and scalar angle precision. All 26 next-index values match. Nine reopens reproduced another 3,840 pixels and nine index values. [Irradiance measurements](parity-fixes.md#whole-and-reopened-first-renderer-irradiance-pass) + +The first renderer's eighth specular pass matches 143,300/143,300 original and rectangular pixels, 16,704/16,704 after reopening, and 81,920/81,920 in each of the two environment readouts. [Whole specular measurements](parity-fixes.md#whole-first-renderer-specular-pass-after-the-switch-correction) [Wired irradiance and rotation readouts](parity-fixes.md#scalar-float-precision-in-nested-graph-instances) · [Rectangular image input and connected-index measurements](parity-fixes.md#rectangular-image-inputs-on-graph-instances) · [Default-index measurements](parity-fixes.md#eighth-irradiance-pass-with-default-and-connected-indices) · [Switch Blend controls and saved files](parity-fixes.md#switch-blend-with-parameter-driven-endpoint-opacity) + +Eight original called-function graphs now match all 49,152 F32 pixels when a step is copied before a later assignment. Four saves reopened in both applications and matched another 24,576 pixels. The sampled-alpha assignment case remains open. [Copied steps and retained arithmetic comparisons](parity-fixes.md#copied-steps-in-called-pixel-sums) + +In the two eighth specular passes, the corrected pixel arithmetic matched all 2,304 scanline pixels across zero through eight contributions. The changed 128² pass 396 scores 16,384/16,384 · 0 in F16 and the default 128² pass 408 scores 16,384/16,384 · 0. All 376,832 pixels in the direct and reusable function graphs match, as do all 131,072 reopened pixels. [Raw counts and procedural inputs](parity-fixes.md#reciprocal-division-through-pixel-function-calls) + +Spline preprocessing matched 622,592/622,592 pixels and 16/16 integer outputs, including the disconnected default. Each complete library save reproduced another 131,072 pixels and counts 0, 1 and 21. [Inputs, parameters and file paths](parity-fixes.md#spline-preprocessing-with-empty-inputs-and-complete-library-saves) + +The production cook and its reopened file now match 1,024/1,024 F32 pixels on both explicit one-worker reference runs for dense 32² BNW Spots 3 v2. The desktop comparison gives 894/1,024, and two eight-worker reference runs match each other on 887/1,024. [Bounded terminal Quadrant work](parity-fixes.md#bounded-work-for-terminal-quadrant-siblings) [Dense Quadrant and saved-file measurements](parity-fixes.md#dense-quadrant-traversal-and-reference-worker-counts) + +Twelve original ancestor-offset controls matched 61,440/61,440 pixels. Three reopens matched another 15,360/15,360. In the two dense BNW Spots 3 packages, the tested square F32 settings that completed matched 4,608/4,608 pixels on the explicit one-worker renderer. Three settings still reached the execution budget. [Returning squares, renderer repeats and per-format counts](parity-fixes.md#branch-offsets-center-culling-and-two-dense-spot-graphs) + +Across five whole spots and cloud graphs, ordinary Quadrant traversal matched 1,803,008/1,803,008 pixels on the explicit one-worker renderer. The current cook matched 1,797,291/1,803,008 pixels against the desktop. Repeated eight-worker renders differed on identical settings. [Whole graphs, generator readouts and repeat counts](parity-fixes.md#patterns-with-an-explicit-reference-worker-count) + +Each of ten corrected scalar-luminosity saves opened in the reference app. The two applications matched all 14,080 reopened grayscale and color pixels. [Scalar Quadrant luminosity in saved packages](parity-fixes.md#scalar-quadrant-luminosity-in-saved-packages) + +The shared pattern-variable checks match **55,680/55,680 pixels**, including saved files, direct predicates and branch offsets. Two controlled F32 overlap graphs also produced different images on repeated eight-worker reference renders. [Position, depth and iteration](parity-fixes.md#position-depth-and-iteration-in-pattern-expressions) · [Worker count and repeated renders](parity-fixes.md#worker-count-and-repeatability-of-overlapping-patterns) + +[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) + +Pattern center culling matched all 356,352 pixels across 204 renders. Background-only resizing matched all 150,528 pixels across 84 renders. The mixed-size square controls now match all 188,160 pixels, and the 288 independent depth controls match all 73,728 pixels. [Opacity and accumulator measurements](parity-fixes.md#pattern-opacity-near-zero-and-color-accumulation) [Pattern backgrounds, saved graphs and affected roots](parity-fixes.md#pattern-backgrounds-and-center-culling) + +Both unit-region stamp sweeps match every F32 pixel, 1,392,640 across 200 renders and 1,802,240 across 264. All 350 scalar components also match in direct typed comparisons and after a package save. [Decimal graph parameters](parity-fixes.md#decimal-graph-parameters-on-the-control-channel) · [Far-vertex precision and root rechecks](parity-fixes.md#scaling-the-far-vertex-of-an-analytic-stamp) + +Filtered F32 pixel reads now match 41,664/41,664 pixels across 150 renders. The nearest and directly wired controls preserve subnormal inputs. [Sampler measurements and capture timings](parity-fixes.md#subnormal-values-in-filtered-pixel-reads) + +Odd-sized grayscale bitmap resources match 116,736/116,736 pixels directly and 90,112/90,112 across downstream sampling controls. [Bitmap and saved-package measurements](parity-fixes.md#original-channel-precision-of-odd-sized-grayscale-bitmap-resources) + +Linear RGBA bitmap resources match 108,544/108,544 pixels on two procedural fields. [Exact counts by format and saved-package results](parity-fixes.md#stored-levels-of-linear-color-bitmap-resources) + +Uniform source and channel-width controls matched 212,192/212,192 pixels across 1,503 renders. The material and blending roots also retained their [rectangular comparisons](parity-fixes.md#rectangular-inputs-and-reopened-outputs-on-seven-roots). [Measurements and saved packages](parity-fixes.md#uniform-channel-width-and-grayscale-rounding-in-node-properties) + +Node-property integer reads and Blend property controls matched 330,080/330,080 pixels across 203 renders, including 40 previously failed cooks. [Measurements and saved packages](parity-fixes.md#unbound-integer-variables-in-node-properties) + +Automatic samples of an embedded bitmap changed on repeated reference renders in three of five dimension pairs. The U16 Bitmap buffers and explicit bilinear samples were stable. [Raw readbacks in both render orders](parity-fixes.md#first-and-repeated-automatic-samples-of-an-embedded-bitmap) + +Choosing axial taps for a one-axis directional footprint recovered 53,078 pixels across 390 renders. Pattern Stripes retained 762,880/762,880. [Measurements and saved packages](parity-fixes.md#oblique-directional-filters-with-one-zero-pixel-extent) + +Wide literal pattern backgrounds matched 17,920/17,920 pixels directly and again after saving. The seven wide bitmap stamp renders now match 1,792/1,792 pixels. [Measurements and saved packages](parity-fixes.md#finite-hdr-backgrounds-in-empty-pattern-graphs) + +Bitmap file-default and explicit data reads matched all 570,112 pixels across 329 renders. Reopening 24 saved packages matched another 203,520/203,520 pixels and reproduced each original buffer in both applications. [Measurements and saved packages](parity-fixes.md#bitmap-file-transfer-and-stored-channel-precision) + +Grayscale bitmap stamps matched every stored F32 word across the 120 composites, 312 individual-stamp renders and 60 reopened renders. The wider background controls have separate measured differences. [Measurements and saved packages](parity-fixes.md#stored-coverage-before-grayscale-bitmap-stamp-opacity) + +Odd-sized linear RGBA bitmaps matched 100,352/100,352 direct pixels and 45,056/45,056 pixels after downstream sampling. [Measurements and saved packages](parity-fixes.md#odd-sized-linear-color-bitmap-resources) + +The 120 mixed-stamp renders matched 69,631/69,632 F32 pixels across slot, filtering and blend changes. [Measurements and saved packages](parity-fixes.md#grayscale-bitmap-stamp-ordering-across-slots-and-filters) + +Grayscale output from normalized RGB bitmaps matched 100,352/100,352 pixels across 48 renders. [Measurements and saved packages](parity-fixes.md#grayscale-conversion-on-the-first-bitmap-filter-pass) + +Enlarged RGBA pattern backgrounds now match 71,680/71,680 pixels across 280 independent renders. The earlier source-storage tests still differ at 121 grayscale zero signs. [Background sign measurements](parity-fixes.md#signs-of-zero-in-enlarged-color-backgrounds) + +The 32²-to-16² signed threshold controls match 2,048/2,048 pixels. [Floating texture filter measurements](parity-fixes.md#signed-zero-in-floating-point-texture-filtering) + +Connected F32 backgrounds now match all 2,048 same-size pixels. Across 132 further renders with changed input sizes, the maximum absolute error is zero. Some RGBA zeros still differ in sign. [Connected background counts and file checks](parity-fixes.md#connected-floating-point-pattern-backgrounds) + +Direct links to missing pattern inputs use the field default. All 53,760 opacity, size and iteration-count pixels and all 8,960 seed-inheritance pixels match. [Direct-link cases and saved-file checks](parity-fixes.md#direct-pattern-links-with-an-unbound-variable) + +Pattern declarations and sparse image selectors match 199,680/199,680 and 88,320/88,320 pixels in their respective controls. Automatic filtering and uninitialized counters retain differences. [Declarations, image selections and remaining differences](parity-fixes.md#pattern-variable-declarations-and-fixed-image-selectors) + +Assignments in quadrant mode expressions now stay within the expression. All 49,920 child-color pixels match. [Mode writes and remaining input-scope differences](parity-fixes.md#assignments-in-quadrant-mode-expressions) + +Empty quadrants now skip inactive stamp properties. The variable-writing controls match 49,120/49,920 pixels over 117 renders. [Measured property scopes](parity-fixes.md#active-properties-of-empty-and-drawing-quadrants) + +Reading inherited variables directly reduced cook time on six Dirt 1 and BNW Spots 3 cases from 128–133 seconds to 43–44 seconds across two runs. The five completed cases retained every measured output bit. [Timings and root checks](parity-fixes.md#pattern-expression-variables-and-cook-time) + +The reference reopened 26 function packages saved by MaterialCraft. All 6,400 pixels and 24 typed values match. [Saved argument checks](parity-fixes.md#connectable-numeric-arguments-in-saved-function-graphs) [Unconnected argument controls](parity-fixes.md#unconnected-function-arguments) + +[Runtime square-root measurements](parity-fixes.md#runtime-pixel-square-roots) cover both exponent parities and the signed domain. + +[Luminance EXR measurements](parity-fixes.md#luminance-exr-input) cover Y and YA inputs at half and single precision. + +[Four-format results by root and output](parity-fixes.md#four-format-inventory-comparison) cover 375 roots. The same table includes the independent 32² measurements for 352 roots. + +Reduced Sharpen now matches 16,704/16,704 pixels on the held-out signed field and 158,688/158,688 on six further fields. Four requested 1² cases still differ in output extent. [Filter measurements](parity-fixes.md#sharpen-at-reduced-output-sizes) + +A change to Gaussian stamp coverage was checked against 61 roots. Additional rectangular captures reopened both brick-generator Tile helpers. [Root checks](parity-fixes.md#root-checks-after-clipping-gaussian-stamps) [Tile input and shape comparisons](parity-fixes.md#rectangular-fields-in-the-two-brick-generator-tile-helpers) + +Both Alveolus roots now match every measured pixel. The corrected stamp coordinates also match all 2,032,128 pixels in the 72 zero- and half-turn gradient controls. [Coordinate and complete-root measurements](parity-fixes.md#pixel-coordinates-for-whole-pixel-pattern-stamps) + +The reference app reopened both intact Alveolus graphs saved with the corrected SBS schema header. In each app all 1,363,456 pixels across 50 reopened renders match that app’s output before saving. [Save and reopen measurements](parity-fixes.md#reopening-sbs-files-with-release-number-headers) + +All 368,640 square-mask pixels match in the 135 extended quarter-turn renders. The 45 displaced-window ramps match 101,216/101,376 pixels, with maximum F32 error 2⁻²². [Tiled draw controls, saved files and root rechecks](parity-fixes.md#tiled-draws-in-cropped-windows-and-quarter-turn-bounds) + +All 185,856 pixels match on 44 unrotated subpixel geometries across three patterns. Four intact roots gained exact pixels. Dirt 3 has one U16 difference in its 17-render matrix. [Subpixel stamp measurements, saved files and intact roots](parity-fixes.md#drawing-axis-aligned-stamps-smaller-than-one-pixel) + +Seven of 40 intact roots gained exact pixels after correcting rotated stamp bounds. Cells 1 matches 145,664/145,664 in its original matrix and 113,662/113,664 on new settings. All six saves reproduce 496,640/496,640 pixels after reopening in each app. [Root measurements, single-stamp reproductions and saved files](parity-fixes.md#bounds-and-pixel-coordinates-of-rotated-pattern-stamps) + +Cells 1 reached measured parity across 89 distinct settings, including 512² and reopened files. The first 256² Crystal 2 comparison identified five differing positions. [Pixel counts, parameters and remaining differences](parity-fixes.md#interpolation-across-pairs-of-pixels-in-cells-1) + +Crystal 2 now matches all 5,104,128 pixels across 99 distinct settings through 512². Six other roots gained matching pixels when subdividing pattern quadrants. [Root counts, reproducible inputs and repeat variability](parity-fixes.md#sibling-positions-in-subdivided-pattern-quadrants) + +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) + +Fibers 1 matched all 9,430,272 pixels across 87 settings. Fluid now matches all 25,969,920 across 121. [Fiber settings](parity-fixes.md#fibers-1-and-fluid-through-1024-pixels-per-side) · [Fluid measurements and package reopens](parity-fixes.md#short-directional-blur-tap-order-on-rectangular-inputs) + +Directional Noise matches 40,572,160/40,572,160 pixels over 136 settings through 2048². BNW Spots 3 now matches every captured intermediate. [Coordinate measurements and round-trip checks](parity-fixes.md#interpolated-coordinates-on-clipped-squares-and-quarter-turns) + +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 | SBS package / graph path | Input pins | Hidden in library | Parity status | |---|---:|---|---| -| [3d_gradient.sbs/3d_linear_gradient](../assets/sbs/3d_gradient.sbs) | 1 | No | [Too hard: remaining float rounding](parity-fixes.md#remaining-differences) | -| [3d_perlin_noise.sbs/3D_perlin_noise](../assets/sbs/3d_perlin_noise.sbs) | 1 | No | [Too hard: 3 pixels remain](parity-fixes.md#remaining-differences) | +| [3d_gradient.sbs/3d_linear_gradient](../assets/sbs/3d_gradient.sbs) | 1 | No | [Parity · 12 wired and 5 disconnected cases, four formats](parity-fixes.md#runtime-reciprocal-and-3d-gradient-contrast) | +| [3d_perlin_noise.sbs/3D_perlin_noise](../assets/sbs/3d_perlin_noise.sbs) | 1 | No | [Parity · 347,136 exact pixels in 34 shared-lookup renders, bundled defaults differ](parity-fixes.md#3d-noise-with-two-original-permutation-tables) | | [3d_perlin_noise.sbs/3D_perlin_noise_fractal](../assets/sbs/3d_perlin_noise.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [3d_perlin_noise.sbs/3D_ridged_noise_fractal](../assets/sbs/3d_perlin_noise.sbs) | 1 | No | [Too hard: 3 pixels remain](parity-fixes.md#remaining-differences) | -| [3d_planar_projection.sbs/3d_planar_projection](../assets/sbs/3d_planar_projection.sbs) | 3 | No | [Too hard: sampling boundaries](parity-fixes.md#remaining-differences) | -| [3d_planar_projection.sbs/3d_planar_projection_color](../assets/sbs/3d_planar_projection.sbs) | 3 | No | [Too hard: sampling boundaries](parity-fixes.md#remaining-differences) | +| [3d_perlin_noise.sbs/3D_ridged_noise_fractal](../assets/sbs/3d_perlin_noise.sbs) | 1 | No | [Parity · 525,824 exact pixels in 78 shared-lookup renders, bundled defaults differ](parity-fixes.md#3d-noise-with-two-original-permutation-tables) | +| [3d_planar_projection.sbs/3d_planar_projection](../assets/sbs/3d_planar_projection.sbs) | 3 | No | [Parity · 15 projection cases, 168,960 exact pixels](parity-fixes.md#uniform-angles-and-planar-projection) | +| [3d_planar_projection.sbs/3d_planar_projection_color](../assets/sbs/3d_planar_projection.sbs) | 3 | No | [Parity · 15 projection cases, 168,960 exact pixels](parity-fixes.md#uniform-angles-and-planar-projection) | | [3d_simplex_noise.sbs/3d_simplex_noise](../assets/sbs/3d_simplex_noise.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [3d_texture_jump_flood.sbs/3d_texture_jump_flood_iteration](../assets/sbs/3d_texture_jump_flood.sbs) | 1 | Yes | [Parity: 5 cases](parity-fixes.md#verified-cases) | | [3d_texture_position.sbs/3d_texture_position](../assets/sbs/3d_texture_position.sbs) | 0 | No | [Parity: native 4K atlas](parity-fixes.md#verified-cases) | -| [3d_texture_render.sbs/3d_texture_surface_render_irradiance](../assets/sbs/3d_texture_render.sbs) | 6 | Yes | [Too hard: float rounding](parity-fixes.md#remaining-differences) | -| [3d_texture_render.sbs/3d_texture_surface_render_position](../assets/sbs/3d_texture_render.sbs) | 1 | Yes | [Too hard: 4 camera pixels](parity-fixes.md#remaining-differences) | -| [3d_texture_render.sbs/3d_texture_volume_render_ibl_pass](../assets/sbs/3d_texture_render.sbs) | 6 | Yes | [Too hard: volume integration](parity-fixes.md#remaining-differences) | -| [3d_texture_render.sbs/3d_texture_volume_render_light_pass](../assets/sbs/3d_texture_render.sbs) | 4 | Yes | [Too hard: 8 pixels remain](parity-fixes.md#remaining-differences) | -| [3d_texture_render.sbs/position_debug](../assets/sbs/3d_texture_render.sbs) | 2 | Yes | [Too hard: 34 traced pixels](parity-fixes.md#remaining-differences) | +| [3d_texture_render.sbs/3d_texture_surface_render_irradiance](../assets/sbs/3d_texture_render.sbs) | 6 | Yes | [Parity · 47,360 exact pixels in 71 renders](parity-fixes.md#surface-irradiance-and-uniform-power) | +| [3d_texture_render.sbs/3d_texture_surface_render_position](../assets/sbs/3d_texture_render.sbs) | 1 | Yes | [Parity · 92,928 exact pixels in 39 renders](parity-fixes.md#surface-position-and-signed-pixel-products) | +| [3d_texture_render.sbs/3d_texture_volume_render_ibl_pass](../assets/sbs/3d_texture_render.sbs) | 6 | Yes | [Parity · 39 renders, 31,488 exact pixels](parity-fixes.md#scaled-random-draws-and-offsets) | +| [3d_texture_render.sbs/3d_texture_volume_render_light_pass](../assets/sbs/3d_texture_render.sbs) | 4 | Yes | [Parity · 46 renders, all 43,264 RGBA pixels exact](parity-fixes.md#vector-products-in-the-direct-light-pass) | +| [3d_texture_render.sbs/position_debug](../assets/sbs/3d_texture_render.sbs) | 2 | Yes | [Parity · 14 sphere and plane cases, plus a matched 128² preview](parity-fixes.md#tinted-stamp-offsets-and-alpha) | | [3d_texture_transform.sbs/3d_texture_offset_color](../assets/sbs/3d_texture_transform.sbs) | 1 | No | [Parity: 5 cases](parity-fixes.md#verified-cases) | | [3d_texture_transform.sbs/3d_texture_offset_grayscale](../assets/sbs/3d_texture_transform.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [3d_viewer.sbs/ibl_specular_contrib_anisotropic/panoramic_lod](../assets/sbs/3d_viewer.sbs) | 1 | Yes | [Too hard: transform filtering](parity-fixes.md#remaining-differences) | -| [3d_volume_mask.sbs/3d_volume_mask](../assets/sbs/3d_volume_mask.sbs) | 1 | No | [Too hard: 62 pixels remain](parity-fixes.md#remaining-differences) | -| [3d_worley_noise.sbs/3D_worley_noise](../assets/sbs/3d_worley_noise.sbs) | 1 | No | [Too hard: noise field mismatch](parity-fixes.md#remaining-differences) | -| [alveolus.sbs/alveolus](../assets/sbs/alveolus.sbs) | 0 | Yes | [Too hard: cell field mismatch](parity-fixes.md#remaining-differences) | +| [3d_viewer.sbs/ibl_specular_contrib_anisotropic/panoramic_lod](../assets/sbs/3d_viewer.sbs) | 1 | Yes | [Parity · 20 cases, 219,392 exact pixels](parity-fixes.md#large-transform-offsets-and-additive-blends) | +| [3d_volume_mask.sbs/3d_volume_mask](../assets/sbs/3d_volume_mask.sbs) | 1 | No | [Parity · 116 renders, all 1,029,632 pixels exact](parity-fixes.md#pixel-quotients-and-volume-mask-interpolation) | +| [3d_worley_noise.sbs/3D_worley_noise](../assets/sbs/3d_worley_noise.sbs) | 1 | No | [Parity · 34 renders, 312,832 exact pixels](parity-fixes.md#per-pixel-random-initialization) | +| [alveolus.sbs/alveolus](../assets/sbs/alveolus.sbs) | 0 | Yes | [Parity · 1,016,064/1,016,064 pixels across 66 renders](parity-fixes.md#pixel-coordinates-for-whole-pixel-pattern-stamps) · [Single-stamp render-region comparisons](parity-fixes.md#pattern-coordinates-under-a-change-of-render-region) · [Gaussian disc-boundary sweeps](parity-fixes.md#gaussian-coverage-at-the-disc-boundary) · [262,144/262,144 pixels after isolating the generator](parity-fixes.md#alveolus-filters-after-the-first-differing-stage) · [Two-stamp reconstruction at eight sizes](parity-fixes.md#four-source-pixels-in-the-filled-alveolus-cells) | | [angle_to_vector.sbs/angle_to_vector](../assets/sbs/angle_to_vector.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [anisotropic_blur.sbs/anisotropic_blur](../assets/sbs/anisotropic_blur.sbs) | 1 | No | [Too hard: blur kernel](parity-fixes.md#remaining-differences) | -| [anisotropic_blur.sbs/anisotropic_blur_grayscale](../assets/sbs/anisotropic_blur.sbs) | 1 | No | [Too hard: blur kernel](parity-fixes.md#remaining-differences) | -| [atlas_spliter.sbs/crop_and_transform_sub](../assets/sbs/atlas_spliter.sbs) | 7 | Yes | [Too hard: typed-input comparison](parity-fixes.md#remaining-differences) | +| [anisotropic_blur.sbs/anisotropic_blur](../assets/sbs/anisotropic_blur.sbs) | 1 | No | [Parity · 29 renders, 200,192 exact pixels across four formats](parity-fixes.md#integer-and-oblique-directional-blur) | +| [anisotropic_blur.sbs/anisotropic_blur_grayscale](../assets/sbs/anisotropic_blur.sbs) | 1 | No | [Parity · 29 renders, 200,192 exact pixels across four formats](parity-fixes.md#integer-and-oblique-directional-blur) | +| [atlas_spliter.sbs/crop_and_transform_sub](../assets/sbs/atlas_spliter.sbs) | 7 | Yes | [Parity · 37 wired cases, 378,880 exact pixels](parity-fixes.md#runtime-pixel-sine-cosine-and-atlas-rotation) | | [atlas_spliter.sbs/max_ba](../assets/sbs/atlas_spliter.sbs) | 1 | Yes | [Parity: 3 cases](parity-fixes.md#verified-cases) | | [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/debug/bevel_smooth_debug_position](../assets/sbs/bevel_smooth.sbs) | 1 | Yes | [Too hard: stamp coverage](parity-fixes.md#remaining-differences) | -| [bevel_smooth.sbs/jump_flood_segment_iteration](../assets/sbs/bevel_smooth.sbs) | 1 | Yes | [Too hard: segment selection](parity-fixes.md#remaining-differences) | -| [blackbody.sbs/blackbody](../assets/sbs/blackbody.sbs) | 0 | No | [Too hard: float rounding](parity-fixes.md#remaining-differences) | +| [bevel_smooth.sbs/blur_gaussian_grayscale](../assets/sbs/bevel_smooth.sbs) | 1 | Yes | [Parity · 26 renders, 311,552 exact grayscale pixels](parity-fixes.md#wide-blur-windows-and-bevel-blur) | +| [bevel_smooth.sbs/debug/bevel_smooth_debug_position](../assets/sbs/bevel_smooth.sbs) | 1 | Yes | [Parity · 38 renders, 354,560 exact pixels across four formats](parity-fixes.md#texture-sampling-in-pattern-functions) | +| [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 | [Parity · 19 renders, 42,496 exact RGBA pixels](parity-fixes.md#literal-arguments-inside-pixel-function-calls) | | [blend.sbs/add](../assets/sbs/blend.sbs) | 3 | Yes | [Parity: 5 cases](parity-fixes.md#verified-cases) | -| [blend.sbs/add_sub](../assets/sbs/blend.sbs) | 3 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [blend.sbs/color](../assets/sbs/blend.sbs) | 3 | No | [Too hard: color conversion](parity-fixes.md#remaining-differences) | -| [blend.sbs/color_burn](../assets/sbs/blend.sbs) | 3 | No | [Too hard: 7 pixels remain](parity-fixes.md#remaining-differences) | -| [blend.sbs/color_dodge](../assets/sbs/blend.sbs) | 3 | No | [Too hard: 7 pixels remain](parity-fixes.md#remaining-differences) | +| [blend.sbs/add_sub](../assets/sbs/blend.sbs) | 3 | Yes | [Parity · 7 renders, 311,296 exact pixels](parity-fixes.md#source-alpha-rounding-in-highpass) | +| [blend.sbs/color](../assets/sbs/blend.sbs) | 3 | No | [Parity · 18 cases, 171,264 exact pixels](parity-fixes.md#gradient-interpolation-color-blend-and-chrominance) | +| [blend.sbs/color_burn](../assets/sbs/blend.sbs) | 3 | No | [Parity · 18 cases, 171,264 exact RGBA pixels](parity-fixes.md#color-burn-and-color-dodge) | +| [blend.sbs/color_dodge](../assets/sbs/blend.sbs) | 3 | No | [Parity · 18 cases, 171,264 exact RGBA pixels](parity-fixes.md#color-burn-and-color-dodge) | | [blend.sbs/copy](../assets/sbs/blend.sbs) | 3 | Yes | [Parity: 5 cases](parity-fixes.md#verified-cases) | | [blend.sbs/difference](../assets/sbs/blend.sbs) | 3 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [blend.sbs/dissolve_2](../assets/sbs/blend.sbs) | 3 | No | [Too hard: stochastic pixels](parity-fixes.md#remaining-differences) | +| [blend.sbs/dissolve_2](../assets/sbs/blend.sbs) | 3 | No | [Parity · 28 renders, 183,040 exact pixels](parity-fixes.md#per-pixel-random-initialization) | | [blend.sbs/exclusion](../assets/sbs/blend.sbs) | 3 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [blend.sbs/hard_light](../assets/sbs/blend.sbs) | 3 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | +| [blend.sbs/hard_light](../assets/sbs/blend.sbs) | 3 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) · [Twelve settings and all selected outputs reopened](parity-fixes.md#rectangular-inputs-and-reopened-outputs-on-seven-roots) | | [blend.sbs/linear_burn](../assets/sbs/blend.sbs) | 3 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [blend.sbs/luminosity](../assets/sbs/blend.sbs) | 3 | No | [Too hard: 2 pixels remain](parity-fixes.md#remaining-differences) | +| [blend.sbs/luminosity](../assets/sbs/blend.sbs) | 3 | No | [Parity · 15 cases, 165,120 exact pixels](parity-fixes.md#luminosity-axial-gradients-color-lookup-and-luminance-merge) | | [blend.sbs/max](../assets/sbs/blend.sbs) | 3 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [blend.sbs/min](../assets/sbs/blend.sbs) | 3 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [blend.sbs/multiply](../assets/sbs/blend.sbs) | 3 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | @@ -96,53 +299,53 @@ The first pass covers all **546 roots**: **166 Parity** and **380 Too hard**. Pa | [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 | [Too hard: blur kernel](parity-fixes.md#remaining-differences) | -| [blur_hq.sbs/blur_hq_grayscale](../assets/sbs/blur_hq.sbs) | 1 | No | [Too hard: blur kernel](parity-fixes.md#remaining-differences) | -| [bnw_spots_1.sbs/bnw_spots_1](../assets/sbs/bnw_spots_1.sbs) | 0 | Yes | [Too hard: noise field](parity-fixes.md#remaining-differences) | -| [bnw_spots_3.sbs/bnw_spots_3](../assets/sbs/bnw_spots_3.sbs) | 0 | Yes | [Too hard: noise field](parity-fixes.md#remaining-differences) | -| [brick_1.sbs/brick_1](../assets/sbs/brick_1.sbs) | 0 | Yes | [Too hard: pattern placement](parity-fixes.md#remaining-differences) | -| [brick_2.sbs/brick_2](../assets/sbs/brick_2.sbs) | 0 | Yes | [Too hard: pattern placement](parity-fixes.md#remaining-differences) | -| [brick_3.sbs/brick_3](../assets/sbs/brick_3.sbs) | 0 | Yes | [Too hard: pattern placement](parity-fixes.md#remaining-differences) | -| [brick_generator.sbs/resources/Tile](../assets/sbs/brick_generator.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [cartesian_polar_transformation.sbs/cartesian_to_polar](../assets/sbs/cartesian_polar_transformation.sbs) | 1 | No | [Too hard: sampling/rounding](parity-fixes.md#remaining-differences) | -| [cartesian_polar_transformation.sbs/cartesian_to_polar_grayscale](../assets/sbs/cartesian_polar_transformation.sbs) | 1 | No | [Too hard: sampling/rounding](parity-fixes.md#remaining-differences) | -| [cartesian_polar_transformation.sbs/polar_to_cartesian](../assets/sbs/cartesian_polar_transformation.sbs) | 1 | No | [Too hard: sampling/rounding](parity-fixes.md#remaining-differences) | -| [cartesian_polar_transformation.sbs/polar_to_cartesian_grayscale](../assets/sbs/cartesian_polar_transformation.sbs) | 1 | No | [Too hard: sampling/rounding](parity-fixes.md#remaining-differences) | -| [cells_1.sbs/cells_1](../assets/sbs/cells_1.sbs) | 0 | Yes | [Too hard: noise field](parity-fixes.md#remaining-differences) | -| [channel_mixer.sbs/channel_mixer](../assets/sbs/channel_mixer.sbs) | 1 | No | [Too hard: function parameter output](parity-fixes.md#remaining-differences) | -| [checker_1.sbs/checker_1](../assets/sbs/checker_1.sbs) | 0 | Yes | [Too hard: scaled filtering](parity-fixes.md#remaining-differences) | +| [blur_hq.sbs/blur_hq](../assets/sbs/blur_hq.sbs) | 1 | No | [Parity · 5,487,872/5,487,872 pixels across 142 distinct settings](parity-fixes.md#accumulating-the-first-aligned-pair-in-a-sheared-blur) · [Previous 110 settings and isolated alpha](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) · [Fourteen downstream root comparisons](parity-fixes.md#downstream-root-captures-after-the-aligned-blur-correction) | +| [blur_hq.sbs/blur_hq_grayscale](../assets/sbs/blur_hq.sbs) | 1 | No | [Parity · 5,487,872/5,487,872 pixels across 142 distinct settings](parity-fixes.md#accumulating-the-first-aligned-pair-in-a-sheared-blur) · [Previous 110 settings and isolated alpha](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) · [Fourteen downstream root comparisons](parity-fixes.md#downstream-root-captures-after-the-aligned-blur-correction) | +| [bnw_spots_1.sbs/bnw_spots_1](../assets/sbs/bnw_spots_1.sbs) | 0 | Yes | [In progress · 125 single-processor settings exact, 3,177,932/3,177,984 pixels on eight processors](parity-fixes.md#compositing-complete-seven-level-additive-quadrant-trees) · [Earlier multi-processor measurements](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) · [Explicit renderer workers and repeatability](parity-fixes.md#patterns-with-an-explicit-reference-worker-count) · [Saved graph seed and output-format checks](parity-fixes.md#graph-random-seed-inheritance-on-save-and-in-nested-graphs) · [Caller-size and four-format reopens](parity-fixes.md#computed-caller-sizes-on-bnw-spots-1-and-clouds-1-and-2) · [139,264 original and reopened desktop pixels](parity-fixes.md#live-desktop-and-standalone-rendering-of-three-noise-roots) · [First differing generator and repeated whole outputs](parity-fixes.md#archived-noise-settings-and-repeated-intermediate-reads) | +| [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) · [118-setting recheck after draw ordering](parity-fixes.md#compositing-complete-seven-level-additive-quadrant-trees) | +| [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) | +| [brick_2.sbs/brick_2](../assets/sbs/brick_2.sbs) | 0 | Yes | [Parity · 124 renders, 3,175,936/3,175,936 pixels](parity-fixes.md#fractional-stamp-vertices-and-the-last-covered-pixel) · [27,136/27,136 downstream pixels](parity-fixes.md#isolating-the-generators-in-spots-bricks-and-cells) · [Earlier generator settings](parity-fixes.md#square-and-rectangular-pattern-generators) | +| [brick_3.sbs/brick_3](../assets/sbs/brick_3.sbs) | 0 | Yes | [Parity · 100 renders, 1,295,872/1,295,872 pixels](parity-fixes.md#wrapped-stamp-centers-in-brick-3) · [64,000/64,000 downstream pixels](parity-fixes.md#isolating-the-generators-in-spots-bricks-and-cells) · [Depth opacity measurements](parity-fixes.md#stored-opacity-across-pattern-depths) | +| [brick_generator.sbs/resources/Tile](../assets/sbs/brick_generator.sbs) | 1 | Yes | [Parity · 347,136/347,136 pixels in 106 renders, 32 reopened settings](parity-fixes.md#image-inputs-and-bell-stamps-in-brick-generator-tile) | +| [cartesian_polar_transformation.sbs/cartesian_to_polar](../assets/sbs/cartesian_polar_transformation.sbs) | 1 | No | [Parity · 171,264 exact pixels in 18 renders](parity-fixes.md#segment-mapping-and-normal-graph-rechecks) | +| [cartesian_polar_transformation.sbs/cartesian_to_polar_grayscale](../assets/sbs/cartesian_polar_transformation.sbs) | 1 | No | [Parity · 171,264 exact pixels in 18 renders](parity-fixes.md#segment-mapping-and-normal-graph-rechecks) | +| [cartesian_polar_transformation.sbs/polar_to_cartesian](../assets/sbs/cartesian_polar_transformation.sbs) | 1 | No | [Parity · 28 renders, all 306,688 pixels exact](parity-fixes.md#reverse-polar-sampling-in-color-and-grayscale) | +| [cartesian_polar_transformation.sbs/polar_to_cartesian_grayscale](../assets/sbs/cartesian_polar_transformation.sbs) | 1 | No | [Parity · 28 renders, all 306,688 pixels exact](parity-fixes.md#reverse-polar-sampling-in-color-and-grayscale) | +| [cells_1.sbs/cells_1](../assets/sbs/cells_1.sbs) | 0 | Yes | [Parity · 89 settings, 2,975,232/2,975,232 pixels](parity-fixes.md#interpolation-across-pairs-of-pixels-in-cells-1) · [27,136/27,136 downstream pixels](parity-fixes.md#isolating-the-generators-in-spots-bricks-and-cells) | +| [channel_mixer.sbs/channel_mixer](../assets/sbs/channel_mixer.sbs) | 1 | No | [Parity · 18 cases, 171,264 exact pixels](parity-fixes.md#large-transform-offsets-and-additive-blends) | +| [checker_1.sbs/checker_1](../assets/sbs/checker_1.sbs) | 0 | Yes | [Parity · eight cases, four formats](parity-fixes.md#transform-edges-and-floating-point-filtering) | | [checker_2.sbs/checker_2](../assets/sbs/checker_2.sbs) | 0 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [chrominance_extract.sbs/chrominance_extract](../assets/sbs/chrominance_extract.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [chrominance_extract.sbs/chrominance_extract](../assets/sbs/chrominance_extract.sbs) | 1 | No | [Parity · 18 cases, 171,264 exact pixels](parity-fixes.md#gradient-interpolation-color-blend-and-chrominance) | | [clamp.sbs/clamp](../assets/sbs/clamp.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [clamp.sbs/clamp_grayscale](../assets/sbs/clamp.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [clone.sbs/clone](../assets/sbs/clone.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [clamp.sbs/clamp_grayscale](../assets/sbs/clamp.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) · [Twelve settings and all selected outputs reopened](parity-fixes.md#rectangular-inputs-and-reopened-outputs-on-seven-roots) | +| [clone.sbs/clone](../assets/sbs/clone.sbs) | 2 | No | [Parity · eight cases, four formats](parity-fixes.md#clone-mask-and-alpha-rounding) | | [clone_patch.sbs/transform_from_center](../assets/sbs/clone_patch.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [clone_patch.sbs/transform_to_center](../assets/sbs/clone_patch.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [clone_patch.sbs/transform_to_center_grayscale](../assets/sbs/clone_patch.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [clouds_1.sbs/clouds_1](../assets/sbs/clouds_1.sbs) | 0 | Yes | [Too hard: noise field](parity-fixes.md#remaining-differences) | -| [clouds_2.sbs/clouds_2](../assets/sbs/clouds_2.sbs) | 0 | Yes | [Too hard: noise field](parity-fixes.md#remaining-differences) | -| [color_space_conversion.sbs/acescg_to_linear_srgb](../assets/sbs/color_space_conversion.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [clouds_1.sbs/clouds_1](../assets/sbs/clouds_1.sbs) | 0 | Yes | [In progress · 68 single-processor settings exact, 707,570/707,584 pixels on 32 eight-processor renders](parity-fixes.md#compositing-complete-seven-level-additive-quadrant-trees) · [Earlier multi-processor measurements](parity-fixes.md#draw-order-at-six-quadrant-subdivisions) · [Intermediate recheck](parity-fixes.md#interpolated-coordinates-on-clipped-squares-and-quarter-turns) · [21 of 22 differences matched on repeats, two texels isolated](parity-fixes.md#repeated-cloud-renders-and-two-generator-texels) · [Explicit renderer workers and repeatability](parity-fixes.md#patterns-with-an-explicit-reference-worker-count) · [Saved graph seed and output-format checks](parity-fixes.md#graph-random-seed-inheritance-on-save-and-in-nested-graphs) · [Caller-size and four-format reopens](parity-fixes.md#computed-caller-sizes-on-bnw-spots-1-and-clouds-1-and-2) · [139,264 original and reopened desktop pixels](parity-fixes.md#live-desktop-and-standalone-rendering-of-three-noise-roots) · [First differing generator and repeated whole outputs](parity-fixes.md#archived-noise-settings-and-repeated-intermediate-reads) | +| [clouds_2.sbs/clouds_2](../assets/sbs/clouds_2.sbs) | 0 | Yes | [In progress · 1,792,256/1,792,256 pixels across 97 single-processor settings, 1,792,196/1,792,256 on eight](parity-fixes.md#two-child-draw-order-when-neighboring-subtrees-cross-different-tile-batches) · [Earlier two-child tile comparisons](parity-fixes.md#wrapped-draw-order-for-two-children-below-depth-seven) · [Earlier repeated renders](parity-fixes.md#pixel-center-rounding-at-the-near-stamp-vertex) · [Intermediate recheck](parity-fixes.md#interpolated-coordinates-on-clipped-squares-and-quarter-turns) · [All 12 differences matched on repeats](parity-fixes.md#repeated-cloud-renders-and-two-generator-texels) · [Single-processor and reopened results](parity-fixes.md#compositing-complete-seven-level-additive-quadrant-trees) · [1,176,794/1,176,832 pixels across 67 single-processor settings](parity-fixes.md#single-processor-comparisons-for-clouds-2-and-five-dirt-fields) · [Tile-copy controls and untiled F32 replay](parity-fixes.md#tile-copies-and-the-draw-order-in-clouds-2) · [untiled generator measurements and four-format reopens](parity-fixes.md#untiled-draw-order-for-two-and-four-children-below-depth-seven) · [two-child tiled generator recheck](parity-fixes.md#wrapped-draw-order-for-four-children-below-depth-seven) · [Explicit renderer workers and repeatability](parity-fixes.md#patterns-with-an-explicit-reference-worker-count) · [Saved graph seed and output-format checks](parity-fixes.md#graph-random-seed-inheritance-on-save-and-in-nested-graphs) · [Caller-size and four-format reopens](parity-fixes.md#computed-caller-sizes-on-bnw-spots-1-and-clouds-1-and-2) · [139,264 original and reopened desktop pixels](parity-fixes.md#live-desktop-and-standalone-rendering-of-three-noise-roots) · [First differing generator and repeated whole outputs](parity-fixes.md#archived-noise-settings-and-repeated-intermediate-reads) | +| [color_space_conversion.sbs/acescg_to_linear_srgb](../assets/sbs/color_space_conversion.sbs) | 1 | No | [Parity · eight cases in four formats](parity-fixes.md#color-conversion-checker-and-clone) | | [color_space_conversion.sbs/acescg_to_srgb](../assets/sbs/color_space_conversion.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [color_space_conversion.sbs/linear_srgb_to_acescg](../assets/sbs/color_space_conversion.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [color_space_conversion.sbs/linear_srgb_to_srgb](../assets/sbs/color_space_conversion.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [color_space_conversion.sbs/linear_srgb_to_srgb_grayscale](../assets/sbs/color_space_conversion.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [color_space_conversion.sbs/srgb_to_acescg](../assets/sbs/color_space_conversion.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [color_space_conversion.sbs/srgb_to_acescg](../assets/sbs/color_space_conversion.sbs) | 1 | No | [Parity · 171,264 exact pixels across 18 renders](parity-fixes.md#color-conversion-gradient-height-and-histogram-controls) | | [color_space_conversion.sbs/srgb_to_linear_srgb](../assets/sbs/color_space_conversion.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [color_space_conversion.sbs/srgb_to_linear_srgb_grayscale](../assets/sbs/color_space_conversion.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [color_temperature_adjustment.sbs/color_temperature_adjustment](../assets/sbs/color_temperature_adjustment.sbs) | 1 | No | [Too hard: 2 pixels remain](parity-fixes.md#remaining-differences) | -| [color_to_mask.sbs/color_to_mask](../assets/sbs/color_to_mask.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [color_to_mask_v2.sbs/color_to_mask](../assets/sbs/color_to_mask_v2.sbs) | 2 | No | [Too hard: 1 pixel remains](parity-fixes.md#remaining-differences) | +| [color_temperature_adjustment.sbs/color_temperature_adjustment](../assets/sbs/color_temperature_adjustment.sbs) | 1 | No | [Parity · 18 cases, 171,264 exact RGBA pixels](parity-fixes.md#color-temperature-range-reductions-sky-parameters-and-polygon-paths) | +| [color_to_mask.sbs/color_to_mask](../assets/sbs/color_to_mask.sbs) | 1 | Yes | [Parity · 18 cases, 168,192 exact pixels](parity-fixes.md#levels-endpoints-camera-tangents-and-uniform-exponentials) | +| [color_to_mask_v2.sbs/color_to_mask](../assets/sbs/color_to_mask_v2.sbs) | 2 | No | [Parity · 23 renders, all 179,456 grayscale pixels exact](parity-fixes.md#constants-returned-from-pixel-functions) | | [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 | [Too hard: pixel differences](parity-fixes.md#remaining-differences) | +| [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 | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [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) | | [composite.sbs/composite/blends/blend_matte_fg_passthrough](../assets/sbs/composite.sbs) | 2 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [composite.sbs/composite/filters/filter_mask](../assets/sbs/composite.sbs) | 2 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [composite.sbs/composite/filters/filter_split_rgb_a](../assets/sbs/composite.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [composite.sbs/composite/filters/filter_transformation](../assets/sbs/composite.sbs) | 1 | Yes | [Too hard: pixel differences](parity-fixes.md#remaining-differences) | +| [composite.sbs/composite/filters/filter_transformation](../assets/sbs/composite.sbs) | 1 | Yes | [Parity · 18 cases, 171,264 exact pixels](parity-fixes.md#stored-precision-in-transform-mip-levels) | | [composite.sbs/composite/filters/filter_transformation_grayscale](../assets/sbs/composite.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [constant_values.sbs/constant_boolean](../assets/sbs/constant_values.sbs) | 0 | No | [Parity: 3 typed values](parity-fixes.md#verified-cases) | | [constant_values.sbs/float/constant_float](../assets/sbs/constant_values.sbs) | 0 | No | [Parity: 3 typed values](parity-fixes.md#verified-cases) | @@ -152,88 +355,88 @@ The first pass covers all **546 roots**: **166 Parity** and **380 Too hard**. Pa | [constant_values.sbs/integer/constant_integer](../assets/sbs/constant_values.sbs) | 0 | No | [Parity: 3 typed values](parity-fixes.md#verified-cases) | | [constant_values.sbs/integer/constant_integer2](../assets/sbs/constant_values.sbs) | 0 | No | [Parity: 3 typed values](parity-fixes.md#verified-cases) | | [constant_values.sbs/integer/constant_integer3](../assets/sbs/constant_values.sbs) | 0 | No | [Parity: 3 typed values](parity-fixes.md#verified-cases) | -| [constant_values.sbs/integer/constant_integer4](../assets/sbs/constant_values.sbs) | 0 | No | [Too hard: integer limit](parity-fixes.md#remaining-differences) | +| [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 | [Too hard: noise field](parity-fixes.md#remaining-differences) | -| [crop.sbs/crop](../assets/sbs/crop.sbs) | 1 | No | [Too hard: pixel differences](parity-fixes.md#remaining-differences) | -| [crop.sbs/crop_grayscale](../assets/sbs/crop.sbs) | 1 | No | [Too hard: pixel differences](parity-fixes.md#remaining-differences) | -| [crystal_1.sbs/crystal_1](../assets/sbs/crystal_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [crystal_2.sbs/crystal_2](../assets/sbs/crystal_2.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [curvature.sbs/curvature](../assets/sbs/curvature.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [curvature_smooth.sbs/curvature_smooth](../assets/sbs/curvature_smooth.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [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) | +| [crystal_2.sbs/crystal_2](../assets/sbs/crystal_2.sbs) | 0 | Yes | [Parity · 99 settings, 5,104,128/5,104,128 pixels](parity-fixes.md#sibling-positions-in-subdivided-pattern-quadrants) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) | +| [curvature.sbs/curvature](../assets/sbs/curvature.sbs) | 1 | No | [Parity · 20 renders, 176,384 exact pixels](parity-fixes.md#sampling-integer-bitmap-inputs-through-wider-bridges) · [Twelve settings and all selected outputs reopened](parity-fixes.md#rectangular-inputs-and-reopened-outputs-on-seven-roots) · [Six nested cases, 2,304/2,304 after reopening](parity-fixes.md#output-precision-in-nested-generators-and-blurs) | +| [curvature_smooth.sbs/curvature_smooth](../assets/sbs/curvature_smooth.sbs) | 1 | Yes | [Parity · 20 renders, 176,384 exact pixels](parity-fixes.md#sampling-integer-bitmap-inputs-through-wider-bridges) · [Six nested cases, 2,304/2,304 after reopening](parity-fixes.md#output-precision-in-nested-generators-and-blurs) | | [curvature_smooth_v2.sbs/compute_curvature_v2](../assets/sbs/curvature_smooth_v2.sbs) | 2 | Yes | [Parity: 6 cases](parity-fixes.md#verified-cases) | -| [diffusion.sbs/impl/pass_RGBA](../assets/sbs/diffusion.sbs) | 4 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [diffusion.sbs/impl/pass_UV](../assets/sbs/diffusion.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [diffusion.sbs/impl/pass_gray](../assets/sbs/diffusion.sbs) | 3 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [diffusion.sbs/impl/pass_normal](../assets/sbs/diffusion.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [directional_distance.sbs/directional_distance](../assets/sbs/directional_distance.sbs) | 3 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [directionnal_noise.sbs/directionnal_noise](../assets/sbs/directionnal_noise.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [dirt_1.sbs/dirt_1](../assets/sbs/dirt_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [dirt_3.sbs/dirt_3](../assets/sbs/dirt_3.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [dirt_5.sbs/dirt_5](../assets/sbs/dirt_5.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [dirt_6.sbs/dirt_6](../assets/sbs/dirt_6.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [dirt_gradient.sbs/dirt_gradient](../assets/sbs/dirt_gradient.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [diffusion.sbs/impl/pass_RGBA](../assets/sbs/diffusion.sbs) | 4 | Yes | [Parity · 19 renders, 143,872 exact pixels](parity-fixes.md#per-pixel-random-initialization) | +| [diffusion.sbs/impl/pass_UV](../assets/sbs/diffusion.sbs) | 1 | Yes | [Parity · 19 renders, 143,872 exact pixels](parity-fixes.md#per-pixel-random-initialization) | +| [diffusion.sbs/impl/pass_gray](../assets/sbs/diffusion.sbs) | 3 | Yes | [Parity · 19 renders, 143,872 exact pixels](parity-fixes.md#per-pixel-random-initialization) | +| [diffusion.sbs/impl/pass_normal](../assets/sbs/diffusion.sbs) | 2 | Yes | [Parity · 19 renders, 143,872 exact pixels](parity-fixes.md#per-pixel-random-initialization) | +| [directional_distance.sbs/directional_distance](../assets/sbs/directional_distance.sbs) | 3 | No | [Parity · 32 renders, both outputs exact across 342,528 pixels](parity-fixes.md#distance-output-channels-axis-wrapping-and-cutoffs) | +| [directionnal_noise.sbs/directionnal_noise](../assets/sbs/directionnal_noise.sbs) | 0 | Yes | [Parity · 136 settings, 40,572,160/40,572,160 pixels](parity-fixes.md#interpolated-coordinates-on-clipped-squares-and-quarter-turns) · [Earlier measurements](parity-fixes.md#draw-order-at-six-quadrant-subdivisions) | +| [dirt_1.sbs/dirt_1](../assets/sbs/dirt_1.sbs) | 0 | Yes | [In progress · 2,579,712/2,579,712 pixels across 80 whole settings on one processor, 2,579,658 on eight, 16 reopens measured](parity-fixes.md#four-child-pattern-order-as-a-tile-copy-batch-fills) · [Earlier comparison · 2,579,712/2,579,712 pixels across 80 single-processor settings, 2,579,658/2,579,712 on eight](parity-fixes.md#wrapped-draw-order-for-four-children-below-depth-seven) · [Earlier measurements](parity-fixes.md#wave-frequency-and-phase-in-directional-noise) · [Overlapping disc additions](parity-fixes.md#overlapping-disc-additions-in-dirt-1) · [Six reference repeats](parity-fixes.md#repeated-dirt-pattern-stages) · [2,316,507/2,316,544 pixels across 68 single-processor settings](parity-fixes.md#single-processor-comparisons-for-clouds-2-and-five-dirt-fields) · [untiled generator measurements and four-format reopens](parity-fixes.md#untiled-draw-order-for-two-and-four-children-below-depth-seven) · [partial copies and whole-root recheck](parity-fixes.md#individual-tile-copies-across-a-pattern-draw-boundary) · [Saved graph seed and output-format checks](parity-fixes.md#graph-random-seed-inheritance-on-save-and-in-nested-graphs) · [84 Blur settings, 50,176/50,176 across output formats](parity-fixes.md#working-precision-of-blur-inputs) | +| [dirt_3.sbs/dirt_3](../assets/sbs/dirt_3.sbs) | 0 | Yes | [In progress · 68 single-processor settings exact, 2,316,526/2,316,544 pixels on eight processors](parity-fixes.md#three-terminal-children-in-seven-level-quadrant-trees) · [Earlier distinct settings](parity-fixes.md#original-and-reopened-dirt-moisture-and-cellular-noise-fields) · [Earlier measurements](parity-fixes.md#wave-frequency-and-phase-in-directional-noise) · [Earlier isolation](parity-fixes.md#bounds-and-pixel-coordinates-of-rotated-pattern-stamps) · [Six reference repeats](parity-fixes.md#repeated-dirt-pattern-stages) · [2,316,511/2,316,544 pixels across 68 single-processor settings](parity-fixes.md#single-processor-comparisons-for-clouds-2-and-five-dirt-fields) · [Saved graph seed and output-format checks](parity-fixes.md#graph-random-seed-inheritance-on-save-and-in-nested-graphs) | +| [dirt_5.sbs/dirt_5](../assets/sbs/dirt_5.sbs) | 0 | Yes | [In progress · 2,662,656/2,662,656 pixels on one processor, 2,661,672/2,662,656 on eight across 95 settings](parity-fixes.md#three-active-quadrant-levels-in-dirt-5-and-dirt-gradient) · [2,005,576/2,006,016 pixels across 40 new renders](parity-fixes.md#wave-frequency-and-phase-in-directional-noise) · [Earlier measurements](parity-fixes.md#stored-opacity-across-pattern-depths) · [Six reference repeats](parity-fixes.md#repeated-dirt-pattern-stages) · [2,299,232/2,300,160 pixels across 67 single-processor settings](parity-fixes.md#single-processor-comparisons-for-clouds-2-and-five-dirt-fields) · [Saved graph seed and output-format checks](parity-fixes.md#graph-random-seed-inheritance-on-save-and-in-nested-graphs) | +| [dirt_6.sbs/dirt_6](../assets/sbs/dirt_6.sbs) | 0 | Yes | [In progress · 2,563,328/2,563,328 pixels across 79 whole settings on one processor, 2,561,906 on eight, 16 reopens measured](parity-fixes.md#four-child-pattern-order-as-a-tile-copy-batch-fills) · [Earlier comparison · 2,593,024/2,593,024 pixels across 84 single-processor settings, 2,591,547/2,593,024 on eight](parity-fixes.md#individual-tile-copies-across-a-pattern-draw-boundary) · [Previous four-child generator results](parity-fixes.md#wrapped-draw-order-for-four-children-below-depth-seven) · [Earlier measurements](parity-fixes.md#original-and-reopened-dirt-moisture-and-cellular-noise-fields) · [Earlier measurements](parity-fixes.md#wave-frequency-and-phase-in-directional-noise) · [Earlier isolation](parity-fixes.md#drawing-axis-aligned-stamps-smaller-than-one-pixel) · [Six reference repeats](parity-fixes.md#repeated-dirt-pattern-stages) · [2,298,882/2,300,160 pixels across 67 single-processor settings](parity-fixes.md#single-processor-comparisons-for-clouds-2-and-five-dirt-fields) · [untiled generator measurements and four-format reopens](parity-fixes.md#untiled-draw-order-for-two-and-four-children-below-depth-seven) · [Saved graph seed and output-format checks](parity-fixes.md#graph-random-seed-inheritance-on-save-and-in-nested-graphs) | +| [dirt_gradient.sbs/dirt_gradient](../assets/sbs/dirt_gradient.sbs) | 0 | Yes | [In progress · 143/143 settings and 3,272,960/3,272,960 pixels on one processor, 50/143 settings and 3,272,132/3,272,960 pixels on eight](parity-fixes.md#final-pair-and-middle-batch-copies-in-dirt-gradient) · [Earlier ten-batch measurements](parity-fixes.md#ten-batches-in-the-horizontal-dirt-gradient-source) · [Previous 127 settings](parity-fixes.md#eight-middle-batches-in-the-horizontal-dirt-gradient-source) · [Earlier three-pair comparison](parity-fixes.md#three-consecutive-full-pairs-in-the-final-dirt-gradient-quadrant) · [Earlier second-quadrant comparison](parity-fixes.md#dirt-gradient-when-groups-50-and-51-fill-the-second-quadrant) · [Earlier final-pair comparison](parity-fixes.md#final-horizontal-pair-with-a-short-receiver-in-dirt-gradient) · [Earlier middle and penultimate pair comparison](parity-fixes.md#middle-and-penultimate-horizontal-subtree-pairs-in-dirt-gradient) · [Earlier receiving-quadrant comparison](parity-fixes.md#full-receiving-quadrants-and-seven-batch-prefixes-in-dirt-gradient) · [Earlier deferred-copy comparison](parity-fixes.md#deferred-copies-in-horizontal-dirt-gradient-batches) · [Earlier preceding-subtree comparison](parity-fixes.md#horizontal-pattern-batches-ending-in-the-preceding-subtree) · [Earlier both-axis comparison](parity-fixes.md#eight-full-subtree-pairs-in-dirt-gradient) · [Nine horizontal generator settings](parity-fixes.md#a-late-copy-in-the-penultimate-horizontal-subtree-pair) · [Earlier horizontal comparison](parity-fixes.md#individual-tile-copies-after-two-full-horizontal-batches) · [Previous 111-setting comparison](parity-fixes.md#paired-subtree-capacity-in-horizontally-tiled-dirt-gradient) · [Five of nine horizontal generator settings exact](parity-fixes.md#the-first-subtree-pair-in-the-final-dirt-gradient-quadrant) · [2,662,010/2,662,656 pixels on one processor, 2,662,090/2,662,656 on eight across 95 settings](parity-fixes.md#three-active-quadrant-levels-in-dirt-5-and-dirt-gradient) · [2,005,640/2,006,016 pixels across 40 new renders](parity-fixes.md#wave-frequency-and-phase-in-directional-noise) · [Earlier measurements](parity-fixes.md#draw-order-at-six-quadrant-subdivisions) · [Six reference repeats](parity-fixes.md#repeated-dirt-pattern-stages) · [2,299,615/2,300,160 pixels across 67 single-processor settings](parity-fixes.md#single-processor-comparisons-for-clouds-2-and-five-dirt-fields) · [Saved graph seed and output-format checks](parity-fixes.md#graph-random-seed-inheritance-on-save-and-in-nested-graphs) | | [exposure.sbs/exposure](../assets/sbs/exposure.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [extend_shape.sbs/extend_shape_color](../assets/sbs/extend_shape.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [extend_shape.sbs/extend_shape_grayscale](../assets/sbs/extend_shape.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [facing_normal.sbs/facing_normal](../assets/sbs/facing_normal.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [fibers_1.sbs/fibers_1](../assets/sbs/fibers_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [fibers_1.sbs/fibers_1](../assets/sbs/fibers_1.sbs) | 0 | Yes | [Parity · 9,430,272/9,430,272 across 87 distinct settings](parity-fixes.md#fibers-1-and-fluid-through-1024-pixels-per-side) | | [flood_fill.sbs/flood_fill_step](../assets/sbs/flood_fill.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [flood_fill.sbs/flood_fill_to_bbox_size](../assets/sbs/flood_fill.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [flood_fill.sbs/flood_fill_to_position](../assets/sbs/flood_fill.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [flood_fill.sbs/flood_fill_to_random_color](../assets/sbs/flood_fill.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [flood_fill.sbs/flood_fill_to_random_grayscale](../assets/sbs/flood_fill.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [flood_fill.sbs/flood_fill_to_random_color](../assets/sbs/flood_fill.sbs) | 1 | Yes | [Parity · 19 renders, 143,872 exact pixels](parity-fixes.md#scaled-random-draws-and-offsets) | +| [flood_fill.sbs/flood_fill_to_random_grayscale](../assets/sbs/flood_fill.sbs) | 1 | Yes | [Parity · 19 renders, 143,872 exact pixels](parity-fixes.md#scaled-random-draws-and-offsets) | | [flood_fill_2.sbs/flood_fill_impl/flood_fill_step_A](../assets/sbs/flood_fill_2.sbs) | 2 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [flood_fill_2.sbs/flood_fill_impl/flood_fill_step_A_switch](../assets/sbs/flood_fill_2.sbs) | 4 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [flood_fill_2.sbs/flood_fill_impl/flood_fill_step_B](../assets/sbs/flood_fill_2.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [flood_fill_2.sbs/flood_fill_to_bbox_size](../assets/sbs/flood_fill_2.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [flood_fill_2.sbs/flood_fill_to_color](../assets/sbs/flood_fill_2.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [flood_fill_2.sbs/flood_fill_to_grayscale](../assets/sbs/flood_fill_2.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [flood_fill_2.sbs/flood_fill_to_color](../assets/sbs/flood_fill_2.sbs) | 2 | No | [Parity · 19 renders, 143,872 exact RGBA pixels](parity-fixes.md#packed-random-draws-in-flood-fill-color) | +| [flood_fill_2.sbs/flood_fill_to_grayscale](../assets/sbs/flood_fill_2.sbs) | 2 | No | [Parity · 19 renders, 143,872 exact pixels](parity-fixes.md#scaled-random-draws-and-offsets) | | [flood_fill_2.sbs/flood_fill_to_position](../assets/sbs/flood_fill_2.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [flood_fill_2.sbs/flood_fill_to_random_color](../assets/sbs/flood_fill_2.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [flood_fill_2.sbs/flood_fill_to_random_grayscale](../assets/sbs/flood_fill_2.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [flood_fill_2.sbs/flood_fill_to_random_color](../assets/sbs/flood_fill_2.sbs) | 1 | No | [Parity · 19 renders, 143,872 exact RGBA pixels](parity-fixes.md#packed-random-draws-in-flood-fill-color) | +| [flood_fill_2.sbs/flood_fill_to_random_grayscale](../assets/sbs/flood_fill_2.sbs) | 1 | No | [Parity · 19 renders, 143,872 exact pixels](parity-fixes.md#scaled-random-draws-and-offsets) | | [floodfill_to_index.sbs/pass](../assets/sbs/floodfill_to_index.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [fluid.sbs/fluid](../assets/sbs/fluid.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [fractal_sum_base.sbs/fractal_sum_base](../assets/sbs/fractal_sum_base.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [fur_1.sbs/fur_1](../assets/sbs/fur_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [fur_2.sbs/fur_2](../assets/sbs/fur_2.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [fur_3.sbs/fur_3](../assets/sbs/fur_3.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [fur_4.sbs/fur_4](../assets/sbs/fur_4.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [fluid.sbs/fluid](../assets/sbs/fluid.sbs) | 0 | Yes | [Parity · 25,969,920/25,969,920 pixels across 121 distinct settings](parity-fixes.md#short-directional-blur-tap-order-on-rectangular-inputs) | +| [fractal_sum_base.sbs/fractal_sum_base](../assets/sbs/fractal_sum_base.sbs) | 0 | Yes | [Parity · 18 renders, 145,664 exact pixels](parity-fixes.md#stored-grayscale-stops-and-scalar-levels-controls) | +| [fur_1.sbs/fur_1](../assets/sbs/fur_1.sbs) | 0 | Yes | [Parity · 9,250,048/9,250,048 pixels across 85 distinct settings](parity-fixes.md#fur-across-two-rectangular-render-series) | +| [fur_2.sbs/fur_2](../assets/sbs/fur_2.sbs) | 0 | Yes | [In progress · 97 single-processor settings exact, 9,007,353/9,414,912 pixels on eight processors](parity-fixes.md#parent-and-leaf-draws-in-fur-2-and-gaussian-spots-2) · [Earlier measurements](parity-fixes.md#fur-across-two-rectangular-render-series) · [Saved graph seed and output-format checks](parity-fixes.md#graph-random-seed-inheritance-on-save-and-in-nested-graphs) | +| [fur_3.sbs/fur_3](../assets/sbs/fur_3.sbs) | 0 | Yes | [Parity · 9,250,048/9,250,048 pixels across 85 distinct settings](parity-fixes.md#fur-across-two-rectangular-render-series) | +| [fur_4.sbs/fur_4](../assets/sbs/fur_4.sbs) | 0 | Yes | [Parity · 9,250,048/9,250,048 pixels across 85 distinct settings](parity-fixes.md#fur-across-two-rectangular-render-series) | | [fxaa.sbs/fxaa_grayscale](../assets/sbs/fxaa.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [gaussian_1.sbs/gaussian_1](../assets/sbs/gaussian_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [gaussian_2.sbs/gaussian_2](../assets/sbs/gaussian_2.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [gaussian_spots_1.sbs/gaussian_spots_1](../assets/sbs/gaussian_spots_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [gaussian_spots_2.sbs/gaussian_spots_2](../assets/sbs/gaussian_spots_2.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [gaussian_1.sbs/gaussian_1](../assets/sbs/gaussian_1.sbs) | 0 | Yes | [Parity · 9,242,880/9,242,880 pixels across 82 distinct settings](parity-fixes.md#gaussian-generators-and-spots-through-1024-pixels-per-side) | +| [gaussian_2.sbs/gaussian_2](../assets/sbs/gaussian_2.sbs) | 0 | Yes | [Parity · 9,242,880/9,242,880 pixels across 82 distinct settings](parity-fixes.md#gaussian-generators-and-spots-through-1024-pixels-per-side) | +| [gaussian_spots_1.sbs/gaussian_spots_1](../assets/sbs/gaussian_spots_1.sbs) | 0 | Yes | [Parity · 9,203,712/9,203,712 pixels across 73 distinct settings](parity-fixes.md#gaussian-generators-and-spots-through-1024-pixels-per-side) | +| [gaussian_spots_2.sbs/gaussian_spots_2](../assets/sbs/gaussian_spots_2.sbs) | 0 | Yes | [In progress · 97 single-processor settings exact, 8,944,516/9,414,912 pixels on eight processors](parity-fixes.md#parent-and-leaf-draws-in-fur-2-and-gaussian-spots-2) · [Earlier measurements](parity-fixes.md#gaussian-generators-and-spots-through-1024-pixels-per-side) · [Saved graph seed and output-format checks](parity-fixes.md#graph-random-seed-inheritance-on-save-and-in-nested-graphs) | | [glow.sbs/clamp](../assets/sbs/glow.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [gradient_axial.sbs/gradient_axial](../assets/sbs/gradient_axial.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [gradient_axial.sbs/gradient_axial_reflected](../assets/sbs/gradient_axial.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [gradient_circular.sbs/gradient_circular](../assets/sbs/gradient_circular.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [gradient_linear_1.sbs/gradient_linear_1](../assets/sbs/gradient_linear_1.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [gradient_linear_2.sbs/gradient_linear_2](../assets/sbs/gradient_linear_2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [gradient_linear_3.sbs/gradient_linear_3](../assets/sbs/gradient_linear_3.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [gradient_radial.sbs/gradient_radial](../assets/sbs/gradient_radial.sbs) | 0 | No | [Too hard: 64 one-level pixels](parity-fixes.md#remaining-differences) | +| [gradient_axial.sbs/gradient_axial](../assets/sbs/gradient_axial.sbs) | 0 | No | [Parity · 15 cases, 165,120 exact pixels](parity-fixes.md#luminosity-axial-gradients-color-lookup-and-luminance-merge) | +| [gradient_axial.sbs/gradient_axial_reflected](../assets/sbs/gradient_axial.sbs) | 0 | No | [Parity · 15 cases, 165,120 exact pixels](parity-fixes.md#luminosity-axial-gradients-color-lookup-and-luminance-merge) | +| [gradient_circular.sbs/gradient_circular](../assets/sbs/gradient_circular.sbs) | 0 | No | [Parity · 13 cases across sizes, seeds and storage formats](parity-fixes.md#runtime-angles-and-circular-gradient) | +| [gradient_linear_1.sbs/gradient_linear_1](../assets/sbs/gradient_linear_1.sbs) | 0 | No | [Parity · 958,208/958,208 pixels in 79 renders, 32 reopened settings](parity-fixes.md#rotated-stamp-coordinates-in-gradient-linear-1-and-bnw-spots) | +| [gradient_linear_2.sbs/gradient_linear_2](../assets/sbs/gradient_linear_2.sbs) | 0 | No | [Parity · 8 cases, grayscale in four formats](parity-fixes.md#linear-gradient-2-and-multiangle-albedo) | +| [gradient_linear_3.sbs/gradient_linear_3](../assets/sbs/gradient_linear_3.sbs) | 0 | No | [Parity · 847,616/847,616 pixels across 50 renders](parity-fixes.md#gradient-linear-3-and-its-reopened-file) | +| [gradient_radial.sbs/gradient_radial](../assets/sbs/gradient_radial.sbs) | 0 | No | [Parity · 171,264 exact pixels across 18 renders](parity-fixes.md#color-conversion-gradient-height-and-histogram-controls) | | [grid_atlas.sbs/grid_atlas_color](../assets/sbs/grid_atlas.sbs) | 16 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [grid_atlas.sbs/grid_atlas_grayscale](../assets/sbs/grid_atlas.sbs) | 16 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [hald_clut.sbs/hald_clut](../assets/sbs/hald_clut.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [hbao.sbs/hbao_mip](../assets/sbs/hbao.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [hbao_2.sbs/hbao_mip](../assets/sbs/hbao_2.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [hbao_2.sbs/hbao_subsample](../assets/sbs/hbao_2.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [hald_clut.sbs/hald_clut](../assets/sbs/hald_clut.sbs) | 2 | No | [Parity · 15 cases, 165,120 exact pixels](parity-fixes.md#luminosity-axial-gradients-color-lookup-and-luminance-merge) | +| [hbao.sbs/hbao_mip](../assets/sbs/hbao.sbs) | 1 | Yes | [Parity · 171,264 exact pixels in 18 renders](parity-fixes.md#centered-transform-resizing-and-untiled-edges) | +| [hbao_2.sbs/hbao_mip](../assets/sbs/hbao_2.sbs) | 1 | Yes | [Parity · 171,264 exact pixels in 18 renders](parity-fixes.md#centered-transform-resizing-and-untiled-edges) | +| [hbao_2.sbs/hbao_subsample](../assets/sbs/hbao_2.sbs) | 2 | Yes | [Parity · 19 cases, 171,520 exact pixels](parity-fixes.md#large-transform-offsets-and-additive-blends) | | [hdr_exposure_preview.sbs/hdr_exposure_preview](../assets/sbs/hdr_exposure_preview.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [hdr_merge.sbs/average_luminance_merge](../assets/sbs/hdr_merge.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [hdr_range_viewer.sbs/hdr_range_viewer_grayscale](../assets/sbs/hdr_range_viewer.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [height_blend.sbs/height_blend](../assets/sbs/height_blend.sbs) | 3 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [hdr_merge.sbs/average_luminance_merge](../assets/sbs/hdr_merge.sbs) | 1 | Yes | [Parity · 15 cases, 165,120 exact pixels](parity-fixes.md#luminosity-axial-gradients-color-lookup-and-luminance-merge) | +| [hdr_range_viewer.sbs/hdr_range_viewer_grayscale](../assets/sbs/hdr_range_viewer.sbs) | 1 | No | [Parity · 18 cases, 167,424 exact pixels](parity-fixes.md#signed-levels-driven-grayscale-weights-and-grayscale-gradients) · [Twelve settings and all selected outputs reopened](parity-fixes.md#rectangular-inputs-and-reopened-outputs-on-seven-roots) | +| [height_blend.sbs/height_blend](../assets/sbs/height_blend.sbs) | 3 | No | [Parity · 342,528 exact pixels across 32 renders](parity-fixes.md#color-conversion-gradient-height-and-histogram-controls) | | [height_extrude.sbs/impl/acceleration_struct_impl](../assets/sbs/height_extrude.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [height_to_normal_world_units.sbs/height_to_normal_world_units](../assets/sbs/height_to_normal_world_units.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [height_to_normal_world_units.sbs/height_to_normal_world_units_2](../assets/sbs/height_to_normal_world_units.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [highpass.sbs/highpass](../assets/sbs/highpass.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [highpass.sbs/highpass_grayscale](../assets/sbs/highpass.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [height_to_normal_world_units.sbs/height_to_normal_world_units](../assets/sbs/height_to_normal_world_units.sbs) | 1 | Yes | [Parity · eight cases in four formats](parity-fixes.md#height-to-normal-in-world-units) | +| [height_to_normal_world_units.sbs/height_to_normal_world_units_2](../assets/sbs/height_to_normal_world_units.sbs) | 1 | No | [Parity · eight cases in four formats](parity-fixes.md#height-to-normal-in-world-units) | +| [highpass.sbs/highpass](../assets/sbs/highpass.sbs) | 1 | No | [Parity · 21 renders, 177,408 exact pixels](parity-fixes.md#source-alpha-rounding-in-highpass) | +| [highpass.sbs/highpass_grayscale](../assets/sbs/highpass.sbs) | 1 | No | [Parity · 30 renders, 216,576 exact pixels](parity-fixes.md#source-alpha-rounding-in-highpass) | | [histogram_range.sbs/histogram_range](../assets/sbs/histogram_range.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [histogram_scan.sbs/histogram_scan](../assets/sbs/histogram_scan.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [histogram_scan.sbs/histogram_scan](../assets/sbs/histogram_scan.sbs) | 1 | No | [Parity · 171,264 exact pixels across 18 renders](parity-fixes.md#color-conversion-gradient-height-and-histogram-controls) | | [histogram_scan_non_uniform.sbs/histogram_scan_non_uniform](../assets/sbs/histogram_scan_non_uniform.sbs) | 3 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [histogram_select.sbs/histogram_select](../assets/sbs/histogram_select.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [histogram_shift.sbs/histogram_shift](../assets/sbs/histogram_shift.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [histogram_tools.sbs/histogram_compute](../assets/sbs/histogram_tools.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [histogram_shift.sbs/histogram_shift](../assets/sbs/histogram_shift.sbs) | 1 | No | [Parity · 171,264 exact pixels in 18 renders](parity-fixes.md#segment-mapping-and-normal-graph-rechecks) | +| [histogram_tools.sbs/histogram_compute](../assets/sbs/histogram_tools.sbs) | 1 | No | [Parity · 4,608 exact pixels across 32 renders](parity-fixes.md#color-conversion-gradient-height-and-histogram-controls) | | [histogram_tools.sbs/horizontal_max](../assets/sbs/histogram_tools.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [id_to_mask.sbs/id_to_mask_color](../assets/sbs/id_to_mask.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [id_to_mask.sbs/id_to_mask_grayscale](../assets/sbs/id_to_mask.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | @@ -243,228 +446,228 @@ The first pass covers all **546 roots**: **166 Parity** and **380 Too hard**. Pa | [linear_srgb_conversion.sbs/convert_to_linear_grayscale](../assets/sbs/linear_srgb_conversion.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [linear_srgb_conversion.sbs/convert_to_srgb](../assets/sbs/linear_srgb_conversion.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [linear_srgb_conversion.sbs/convert_to_srgb_grayscale](../assets/sbs/linear_srgb_conversion.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [make_it_tile_patch.sbs/make_it_tile_patch](../assets/sbs/make_it_tile_patch.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [make_it_tile_patch_grayscale.sbs/make_it_tile_patch_grayscale](../assets/sbs/make_it_tile_patch_grayscale.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [material_switch.sbs/material_switch](../assets/sbs/material_switch.sbs) | 24 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [material_transforms.sbs/material_transforms](../assets/sbs/material_transforms.sbs) | 5 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [me_water_level.sbs/scratches_2](../assets/sbs/me_water_level.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [mean_of_least_variance.sbs/mlv_color_iteration](../assets/sbs/mean_of_least_variance.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [mean_of_least_variance.sbs/mlv_grayscale_iteration](../assets/sbs/mean_of_least_variance.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [median_filter.sbs/median_filter_color](../assets/sbs/median_filter.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [make_it_tile_patch.sbs/make_it_tile_patch](../assets/sbs/make_it_tile_patch.sbs) | 1 | No | [Parity · 21,366,784/21,366,784 pixels across 127 distinct settings](parity-fixes.md#diagonal-blur-across-rectangular-tile-edges) | +| [make_it_tile_patch_grayscale.sbs/make_it_tile_patch_grayscale](../assets/sbs/make_it_tile_patch_grayscale.sbs) | 1 | No | [Parity · 21,366,784/21,366,784 pixels across 127 distinct settings](parity-fixes.md#diagonal-blur-across-rectangular-tile-edges) | +| [material_switch.sbs/material_switch](../assets/sbs/material_switch.sbs) | 24 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) · [Twelve settings and all selected outputs reopened](parity-fixes.md#rectangular-inputs-and-reopened-outputs-on-seven-roots) | +| [material_transforms.sbs/material_transforms](../assets/sbs/material_transforms.sbs) | 5 | Yes | [Parity · 856,320 exact pixels across every output](parity-fixes.md#material-bundles-and-the-eighth-irradiance-pass) | +| [me_water_level.sbs/scratches_2](../assets/sbs/me_water_level.sbs) | 0 | Yes | [Parity · 5,414,144/5,414,144 pixels across 113 distinct settings](parity-fixes.md#starting-coordinates-of-narrow-rotated-stamps) | +| [mean_of_least_variance.sbs/mlv_color_iteration](../assets/sbs/mean_of_least_variance.sbs) | 1 | Yes | [Parity · 195,840/195,840 pixels across 34 distinct settings](parity-fixes.md#pixel-ratio-in-rectangular-directional-filters) | +| [mean_of_least_variance.sbs/mlv_grayscale_iteration](../assets/sbs/mean_of_least_variance.sbs) | 1 | Yes | [Parity · 195,840/195,840 pixels across 34 distinct settings](parity-fixes.md#pixel-ratio-in-rectangular-directional-filters) | +| [median_filter.sbs/median_filter_color](../assets/sbs/median_filter.sbs) | 1 | No | [Parity · 171,264 exact pixels across 18 renders](parity-fixes.md#color-conversion-gradient-height-and-histogram-controls) | | [median_filter.sbs/median_filter_grayscale](../assets/sbs/median_filter.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [mesh_1.sbs/mesh_1](../assets/sbs/mesh_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [mesh_2.sbs/mesh_2](../assets/sbs/mesh_2.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [mesh_1.sbs/mesh_1](../assets/sbs/mesh_1.sbs) | 0 | Yes | [Parity · 8,912,896/8,912,896 pixels across 73 distinct settings](parity-fixes.md#fixed-and-input-driven-rotation-bounds-for-oblique-stamps) | +| [mesh_2.sbs/mesh_2](../assets/sbs/mesh_2.sbs) | 0 | Yes | [Parity · 8,912,896/8,912,896 pixels across 73 distinct settings](parity-fixes.md#affine-mip-selection-on-rectangular-and-skewed-footprints) | | [mesh_adaptive_base_color.sbs/base_color_2_inputs](../assets/sbs/mesh_adaptive_base_color.sbs) | 2 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [mesh_adaptive_base_color.sbs/base_color_4_inputs](../assets/sbs/mesh_adaptive_base_color.sbs) | 2 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [mesh_adaptive_base_color.sbs/base_color_8_inputs](../assets/sbs/mesh_adaptive_base_color.sbs) | 2 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [mesh_adaptive_material_blender.sbs/mesh_material_blender_2_inputs](../assets/sbs/mesh_adaptive_material_blender.sbs) | 7 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [mesh_adaptive_material_blender.sbs/mesh_material_blender_4_inputs](../assets/sbs/mesh_adaptive_material_blender.sbs) | 13 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [mesh_adaptive_material_blender.sbs/mesh_material_blender_8_inputs](../assets/sbs/mesh_adaptive_material_blender.sbs) | 25 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [mesh_adaptive_material_blender.sbs/mesh_material_blender_2_inputs](../assets/sbs/mesh_adaptive_material_blender.sbs) | 7 | Yes | [Parity · 513,792 exact pixels across every output](parity-fixes.md#material-bundles-and-the-eighth-irradiance-pass) | +| [mesh_adaptive_material_blender.sbs/mesh_material_blender_4_inputs](../assets/sbs/mesh_adaptive_material_blender.sbs) | 13 | Yes | [Parity · 513,792 exact pixels across every output](parity-fixes.md#material-bundles-and-the-eighth-irradiance-pass) | +| [mesh_adaptive_material_blender.sbs/mesh_material_blender_8_inputs](../assets/sbs/mesh_adaptive_material_blender.sbs) | 25 | Yes | [Parity · 513,792 exact pixels across every output](parity-fixes.md#material-bundles-and-the-eighth-irradiance-pass) | | [mesh_data_combiner.sbs/mesh_data_combiner](../assets/sbs/mesh_data_combiner.sbs) | 11 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [messy_fibers_1.sbs/messy_fibers_1](../assets/sbs/messy_fibers_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [messy_fibers_2.sbs/messy_fibers_2](../assets/sbs/messy_fibers_2.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [messy_fibers_3.sbs/messy_fibers_3](../assets/sbs/messy_fibers_3.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [messy_fibers_4.sbs/messy_fibers_4](../assets/sbs/messy_fibers_4.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [microscope_view.sbs/microscope_view](../assets/sbs/microscope_view.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [min_max.sbs/min_max](../assets/sbs/min_max.sbs) | 1 | No | [Too hard: remaining typed-value difference](parity-fixes.md#remaining-differences) | -| [moisture_noise.sbs/moisture_noise](../assets/sbs/moisture_noise.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [mosaic.sbs/mosaic](../assets/sbs/mosaic.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [mosaic.sbs/mosaic_grayscale](../assets/sbs/mosaic.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [multi_directional_warp.sbs/multi_directional_warp_color](../assets/sbs/multi_directional_warp.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [multi_directional_warp.sbs/multi_directional_warp_grayscale](../assets/sbs/multi_directional_warp.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [multiangle_to_albedo.sbs/multiangle_to_albedo](../assets/sbs/multiangle_to_albedo.sbs) | 8 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [messy_fibers_1.sbs/messy_fibers_1](../assets/sbs/messy_fibers_1.sbs) | 0 | Yes | [Parity · 3,996,928/3,996,928 pixels across 82 distinct settings](parity-fixes.md#messy-fibers-and-microscope-view-through-1024-pixels-per-side) | +| [messy_fibers_2.sbs/messy_fibers_2](../assets/sbs/messy_fibers_2.sbs) | 0 | Yes | [Parity · 3,996,928/3,996,928 pixels across 82 distinct settings](parity-fixes.md#messy-fibers-and-microscope-view-through-1024-pixels-per-side) | +| [messy_fibers_3.sbs/messy_fibers_3](../assets/sbs/messy_fibers_3.sbs) | 0 | Yes | [Parity · 3,950,592/3,950,592 pixels across 70 distinct settings](parity-fixes.md#messy-fibers-and-microscope-view-through-1024-pixels-per-side) | +| [messy_fibers_4.sbs/messy_fibers_4](../assets/sbs/messy_fibers_4.sbs) | 0 | Yes | [Parity · 3,915,008/3,915,008 pixels across 77 distinct settings](parity-fixes.md#messy-fibers-and-microscope-view-through-1024-pixels-per-side) | +| [microscope_view.sbs/microscope_view](../assets/sbs/microscope_view.sbs) | 0 | Yes | [Parity · 3,996,928/3,996,928 pixels across 82 distinct settings](parity-fixes.md#messy-fibers-and-microscope-view-through-1024-pixels-per-side) | +| [min_max.sbs/min_max](../assets/sbs/min_max.sbs) | 1 | No | [Parity · both scalar outputs exact in 25 cases](parity-fixes.md#color-temperature-range-reductions-sky-parameters-and-polygon-paths) | +| [moisture_noise.sbs/moisture_noise](../assets/sbs/moisture_noise.sbs) | 0 | Yes | [In progress · all 4,272,384 pixels on one processor, 4,271,875/4,272,384 on eight across 110 settings](parity-fixes.md#completing-short-paired-quadrant-batches-in-moisture-noise) · [Earlier late and underfilled batches](parity-fixes.md#late-and-underfilled-draw-batches-in-moisture-noise) · [Earlier sparse quadrant comparison](parity-fixes.md#sparse-quadrant-parents-and-leaves-in-moisture-noise) · [Previous 110-setting comparison](parity-fixes.md#two-independent-pattern-sources-in-moisture-noise) · [1,535 differing generator pixels reproduced by changing addition order](parity-fixes.md#zero-luminosity-draws-and-addition-order-in-moisture-noise) · [Earlier whole-root comparisons](parity-fixes.md#original-and-reopened-dirt-moisture-and-cellular-noise-fields) · [Earlier measurements](parity-fixes.md#moisture-noise-across-repeated-original-renders) · [4,161,468/4,161,792 pixels in 94 single-processor settings](parity-fixes.md#moisture-spot-and-cell-fields-across-processors-and-saved-packages) · [Saved graph seed and output-format checks](parity-fixes.md#graph-random-seed-inheritance-on-save-and-in-nested-graphs) | +| [mosaic.sbs/mosaic](../assets/sbs/mosaic.sbs) | 2 | No | [Parity · 17 renders, 142,592 exact pixels](parity-fixes.md#gradient-warp-displacement-and-sampling) | +| [mosaic.sbs/mosaic_grayscale](../assets/sbs/mosaic.sbs) | 2 | No | [Parity · 17 renders, 142,592 exact pixels](parity-fixes.md#gradient-warp-displacement-and-sampling) | +| [multi_directional_warp.sbs/multi_directional_warp_color](../assets/sbs/multi_directional_warp.sbs) | 2 | No | [Parity · 19 cases, 175,360 exact pixels and intermediate stages confirmed](parity-fixes.md#multi-directional-warp-and-intermediate-storage) | +| [multi_directional_warp.sbs/multi_directional_warp_grayscale](../assets/sbs/multi_directional_warp.sbs) | 2 | No | [Parity · 19 cases, 175,360 exact pixels and intermediate stages confirmed](parity-fixes.md#multi-directional-warp-and-intermediate-storage) | +| [multiangle_to_albedo.sbs/multiangle_to_albedo](../assets/sbs/multiangle_to_albedo.sbs) | 8 | No | [Parity · 14 cases, including eight distinct input images](parity-fixes.md#linear-gradient-2-and-multiangle-albedo) | | [multiangle_to_normal.sbs/angle_to_normal](../assets/sbs/multiangle_to_normal.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [multiangle_to_normal.sbs/angle_weight](../assets/sbs/multiangle_to_normal.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [noise_anisotropic_noise.sbs/anisotropic_noise](../assets/sbs/noise_anisotropic_noise.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_anisotropic_noise_v2.sbs/anisotropic_noise_v2](../assets/sbs/noise_anisotropic_noise_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_bnw_spots_1.sbs/bnw_spots_1](../assets/sbs/noise_bnw_spots_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_bnw_spots_1_v2.sbs/bnw_spots_1](../assets/sbs/noise_bnw_spots_1_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_bnw_spots_3.sbs/bnw_spots_3](../assets/sbs/noise_bnw_spots_3.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_bnw_spots_3_v2.sbs/bnw_spots_3](../assets/sbs/noise_bnw_spots_3_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_cells_1.sbs/cells_1](../assets/sbs/noise_cells_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_cells_1_v2.sbs/cells_1](../assets/sbs/noise_cells_1_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_cells_4.sbs/cells_4](../assets/sbs/noise_cells_4.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_cells_4_v2.sbs/cells_4](../assets/sbs/noise_cells_4_v2.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_clouds_1.sbs/clouds_1](../assets/sbs/noise_clouds_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_clouds_1_v2.sbs/clouds_1](../assets/sbs/noise_clouds_1_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_clouds_2.sbs/clouds_2](../assets/sbs/noise_clouds_2.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_clouds_2_v2.sbs/clouds_2](../assets/sbs/noise_clouds_2_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_creased.sbs/creased](../assets/sbs/noise_creased.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_crystal_1.sbs/crystal_1](../assets/sbs/noise_crystal_1.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_crystal_2.sbs/crystal_2](../assets/sbs/noise_crystal_2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_directional_noise_1.sbs/directional_noise_1](../assets/sbs/noise_directional_noise_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_directional_noise_1_v2.sbs/directional_noise_1](../assets/sbs/noise_directional_noise_1_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_directional_noise_2.sbs/directional_noise_2](../assets/sbs/noise_directional_noise_2.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_directional_noise_2_v2.sbs/directional_noise_2](../assets/sbs/noise_directional_noise_2_v2.sbs) | 0 | No | [Too hard: measurement timeout](parity-fixes.md#remaining-differences) | -| [noise_directional_noise_3.sbs/directional_noise_3](../assets/sbs/noise_directional_noise_3.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_directional_noise_3_v2.sbs/directional_noise_3](../assets/sbs/noise_directional_noise_3_v2.sbs) | 0 | No | [Too hard: measurement timeout](parity-fixes.md#remaining-differences) | -| [noise_directional_noise_4.sbs/directional_noise_4](../assets/sbs/noise_directional_noise_4.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_directional_noise_4_v2.sbs/directional_noise_4](../assets/sbs/noise_directional_noise_4_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_directional_scratches.sbs/directional_scratches](../assets/sbs/noise_directional_scratches.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_directional_scratches_v2.sbs/directional_scratches](../assets/sbs/noise_directional_scratches_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_dirt_1.sbs/dirt_1](../assets/sbs/noise_dirt_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_dirt_1_v2.sbs/dirt_1](../assets/sbs/noise_dirt_1_v2.sbs) | 0 | No | [Too hard: measurement timeout](parity-fixes.md#remaining-differences) | -| [noise_dirt_2.sbs/dirt_2](../assets/sbs/noise_dirt_2.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_dirt_3.sbs/dirt_3](../assets/sbs/noise_dirt_3.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_dirt_3_v2.sbs/dirt_3](../assets/sbs/noise_dirt_3_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_dirt_4.sbs/dirt_4](../assets/sbs/noise_dirt_4.sbs) | 0 | Yes | [Too hard: cook timeout](parity-fixes.md#remaining-differences) | -| [noise_dirt_4_v2.sbs/dirt_4](../assets/sbs/noise_dirt_4_v2.sbs) | 0 | No | [Too hard: cook timeout](parity-fixes.md#remaining-differences) | -| [noise_dirt_5.sbs/dirt_5](../assets/sbs/noise_dirt_5.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_dirt_5_v2.sbs/dirt_5](../assets/sbs/noise_dirt_5_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_dirt_gradient.sbs/dirt_gradient](../assets/sbs/noise_dirt_gradient.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_dirt_gradient_v2.sbs/dirt_gradient](../assets/sbs/noise_dirt_gradient_v2.sbs) | 0 | No | [Too hard: cook timeout](parity-fixes.md#remaining-differences) | -| [noise_fluid.sbs/fluid](../assets/sbs/noise_fluid.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_fractal_sum_base.sbs/fractal_sum_base](../assets/sbs/noise_fractal_sum_base.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_fractal_sum_base.sbs/fractal_sum_base_2](../assets/sbs/noise_fractal_sum_base.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_fractal_sum_base_v2.sbs/noise_blend](../assets/sbs/noise_fractal_sum_base_v2.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [noise_anisotropic_noise.sbs/anisotropic_noise](../assets/sbs/noise_anisotropic_noise.sbs) | 0 | Yes | [Parity · 18 renders, all 171,264 pixels exact](parity-fixes.md#quarter-turn-directional-blur) · [Saved graph seed and output-format checks](parity-fixes.md#graph-random-seed-inheritance-on-save-and-in-nested-graphs) | +| [noise_anisotropic_noise_v2.sbs/anisotropic_noise_v2](../assets/sbs/noise_anisotropic_noise_v2.sbs) | 0 | No | [Parity · 18 renders, all 171,264 pixels exact](parity-fixes.md#high-pass-anisotropic-noise-and-triangle-grid-controls) | +| [noise_bnw_spots_1.sbs/bnw_spots_1](../assets/sbs/noise_bnw_spots_1.sbs) | 0 | Yes | [In progress · 66/86 on one processor, 38/86 on eight, 16/19 ordinary saves](parity-fixes.md#receiving-quadrant-subtrees-after-the-second-pair-fills) · [Third-tree transfers](parity-fixes.md#carrying-unfinished-quadrant-draws-into-a-third-tree) · [Completed second-tree batches](parity-fixes.md#completed-quadrant-batches-before-a-later-tree) · [Two-tree transfers](parity-fixes.md#final-transfers-between-unfinished-quadrant-groups) · [Earlier sibling transfer](parity-fixes.md#quadrant-batch-order-after-a-sibling-transfer) · [Earlier receiving groups](parity-fixes.md#full-copy-batches-received-across-repeated-quadrant-trees) · [Two rectangular F32 settings across repeated captures and saves](parity-fixes.md#finishing-a-quadrant-copy-batch-in-the-next-tree) · [Two more exact F32 settings on one processor and after reopen](parity-fixes.md#pending-quadrant-siblings-and-the-first-full-receiving-batch) · [Third carried pair and outer routing](parity-fixes.md#carrying-the-third-quadrant-pair-through-an-outer-iteration) · [Earlier cross-tree measurements](parity-fixes.md#full-copy-batches-spanning-successive-quadrant-trees) · [Neighboring quadrants](parity-fixes.md#physical-copy-batches-across-neighboring-quadrants) · [Ninth-batch comparison](parity-fixes.md#connected-graph-depth-and-the-ninth-quadrant-batch) · [Eighth-batch comparison](parity-fixes.md#the-next-full-batch-in-an-eight-level-quadrant-tree) · [Previous 86-setting comparison and 19 saves](parity-fixes.md#a-full-copy-batch-in-the-last-root-quadrant) · [Earlier six batches](parity-fixes.md#leading-copy-batches-in-complete-quadrant-trees) · [Measured physical copy boundary](parity-fixes.md#physical-copy-boundaries-in-dense-quadrant-subtrees) · [Inactive descendants affect draw order, 21/21 independently replayed F32 values](parity-fixes.md#connected-inactive-descendants-and-dense-quadrant-draw-order) · [Eight additional 64 × 32 F32 isolates cook](parity-fixes.md#bounded-work-for-empty-terminal-quadrants) · [Five levels combined, original and reopened, each 8,192/8,192 F32](parity-fixes.md#wide-first-level-shapes-in-additive-quadrant-trees) · [Depths 3–6 match 32,768/32,768 isolated F32 pixels](parity-fixes.md#submission-order-in-underfilled-eight-level-quadrant-trees) · [Earlier 60-setting comparison](parity-fixes.md#connected-quadrant-depth-and-amplified-spot-patterns) · [Zero roughness exact in U16 and F32](parity-fixes.md#grayscale-pattern-output-at-zero-roughness) · [Draw order, 18 changed-format comparisons](parity-fixes.md#draw-order-for-overlapping-procedural-grayscale-stamps) · [12 settings and four attempted reopens](parity-fixes.md#moisture-spot-and-cell-fields-across-processors-and-saved-packages) · [Explicit renderer workers and repeatability](parity-fixes.md#patterns-with-an-explicit-reference-worker-count) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_bnw_spots_1_v2.sbs/bnw_spots_1](../assets/sbs/noise_bnw_spots_1_v2.sbs) | 0 | No | [In progress · 6/8 additional untiled originals on one processor, 6/8 on eight and 6/8 ordinary saves](parity-fixes.md#untiled-spots-outputs-and-the-second-dirt-gradient-iteration) · [Earlier comparison · 839,460/842,752 on one processor, 830,536/842,752 on eight and 137,715/139,008 in 19 saves](parity-fixes.md#finishing-a-quadrant-copy-batch-in-the-next-tree) · [Three additional F32 settings exact on one processor and ordinary reopens](parity-fixes.md#returning-the-cut-child-of-a-completed-outer-quadrant) · [Earlier two-child measurements](parity-fixes.md#filling-a-quadrant-batch-from-two-transferred-children) · [512/512 at 32 × 16 on one processor and reopening](parity-fixes.md#drawing-the-children-of-a-transferred-quadrant) · [Repeated parents, three new seeds and processor repeats](parity-fixes.md#repeated-drawing-quadrants-and-full-batches-in-the-outer-pair) · [Earlier half-quadrants and reference repeats](parity-fixes.md#which-half-quadrant-completes-the-next-copy-batch) · [Previous tile-copy fix](parity-fixes.md#tile-copies-in-the-last-two-active-quadrant-levels) · [Earlier 87-setting comparison](parity-fixes.md#copy-batches-from-the-final-quadrant-pair-and-the-following-group) · [Final pattern stage and 16² addition-order replay](parity-fixes.md#final-pattern-draws-above-inactive-quadrants-in-spots-1-v2) · [Parameters and earlier comparison](parity-fixes.md#whole-root-precision-and-saved-comparisons-for-the-three-neighboring-spot-graphs) · [All 87 original settings and 19 saves rechecked](parity-fixes.md#dense-settings-recovered-in-the-third-spots-graph) · [Depth-local variable writes fixed, 28,082/28,160 on twelve whole guards](parity-fixes.md#inherited-and-writable-variables-across-quadrant-depths) · [Two additional 64 × 32 isolates, each 2,048/2,048 F32](parity-fixes.md#bounded-work-for-empty-terminal-quadrants) · [Levels 7–8, 8,047/8,192 F32 on original, 8,048/8,192 reopened](parity-fixes.md#wide-first-level-shapes-in-additive-quadrant-trees) · [Earlier spot comparison](parity-fixes.md#connected-quadrant-depth-and-amplified-spot-patterns) · [Zero roughness exact in U16 and F32](parity-fixes.md#grayscale-pattern-output-at-zero-roughness) · [Draw order, 18 changed-format comparisons](parity-fixes.md#draw-order-for-overlapping-procedural-grayscale-stamps) · [12 settings and four attempted reopens](parity-fixes.md#moisture-spot-and-cell-fields-across-processors-and-saved-packages) · [Explicit renderer workers and repeatability](parity-fixes.md#patterns-with-an-explicit-reference-worker-count) · [6/6 tiled settings render, 4 exact on one processor](parity-fixes.md#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_bnw_spots_3.sbs/bnw_spots_3](../assets/sbs/noise_bnw_spots_3.sbs) | 0 | Yes | [In progress · 62/62 originals and 14/14 saves render, 732,937/733,184 pixels on one processor and 733,011/733,184 on eight](parity-fixes.md#reusing-terminal-quadrant-properties-in-dense-rectangular-renders) · [Two individually exact contributions explain a stable U16 difference](parity-fixes.md#two-depth-seven-draws-at-a-stored-rounding-boundary) · [Six earlier recovered settings, 49,131/49,152 on one processor, 49,132/49,152 on eight](parity-fixes.md#dense-settings-recovered-in-the-third-spots-graph) · [Earlier 48 settings, 671,452/671,744 pixels on one processor, 671,526/671,744 on eight](parity-fixes.md#whole-root-precision-and-saved-comparisons-for-the-three-neighboring-spot-graphs) · [Earlier spot comparison](parity-fixes.md#deep-pattern-samples-in-custom-render-and-tiling-regions) · [Earlier matrix](parity-fixes.md#bnw-spots-3-and-cells-1-pattern-sources) · [64² precision and remaining traversal limits](parity-fixes.md#precision-of-two-dense-noise-generators-in-custom-regions) · [12 settings and four attempted reopens](parity-fixes.md#moisture-spot-and-cell-fields-across-processors-and-saved-packages) · [Explicit worker counts](parity-fixes.md#branch-offsets-center-culling-and-two-dense-spot-graphs) · [Four-format square and reopened comparisons](parity-fixes.md#two-dense-spots-packages-across-storage-formats) · [Five F32 returns per processor count at 64²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_bnw_spots_3_v2.sbs/bnw_spots_3](../assets/sbs/noise_bnw_spots_3_v2.sbs) | 0 | No | [In progress · 62/62 established originals and 14/14 archived saves render](parity-fixes.md#bound-arithmetic-in-seeded-quadrant-properties) · [Previous comparison · 58/62 established originals and 13/14 archived saves render](parity-fixes.md#seeded-quadrant-properties-with-a-live-tint-multiplier) · [33 single draws and nine ordered sums, all exact](parity-fixes.md#individual-paraboloids-and-additive-order-in-noise-bnw-spots-3-v2) · [3/4 additional untiled originals on one processor, 3/4 on eight and 3/4 ordinary saves](parity-fixes.md#untiled-spots-outputs-and-the-second-dirt-gradient-iteration) · [Earlier comparison · 48/62 originals and 10/14 saves have rendered, including the 128 × 512 U16 and F32 originals](parity-fixes.md#sample-coverage-of-narrow-and-circular-quadrant-stamps) · [16 earlier recoveries, 185,202/193,536 on one processor and 184,698/193,536 on eight](parity-fixes.md#recovered-settings-in-the-second-version-of-the-third-spots-graph) · [Three recovered saves, 5,999/6,144](parity-fixes.md#recovered-settings-in-the-second-version-of-the-third-spots-graph) · [Dense 32² comparison](parity-fixes.md#bounded-work-for-terminal-quadrant-siblings) · [Earlier comparison · 339,986/347,136 pixels on one processor, 341,093/347,136 on eight · 30 of 62 settings rendered](parity-fixes.md#whole-root-precision-and-saved-comparisons-for-the-three-neighboring-spot-graphs) · [Earlier spot comparison](parity-fixes.md#bnw-spots-3-and-cells-1-pattern-sources) · [12 settings and four attempted reopens](parity-fixes.md#moisture-spot-and-cell-fields-across-processors-and-saved-packages) · [bounded stage counts at scale two](parity-fixes.md#four-cloud-noise-generators-and-repeated-saved-file-comparisons) · [Explicit worker counts](parity-fixes.md#branch-offsets-center-culling-and-two-dense-spot-graphs) · [Dense F32 traversal and worker repeats](parity-fixes.md#dense-quadrant-traversal-and-reference-worker-counts) · [Four-format square and reopened comparisons](parity-fixes.md#two-dense-spots-packages-across-storage-formats) · [2/6 tiled settings render, 0 exact on one processor](parity-fixes.md#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) · [4/4 untiled settings render](parity-fixes.md#untiled-spots-clouds-directional-noise-and-dirt-at-two-rectangular-sizes) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_cells_1.sbs/cells_1](../assets/sbs/noise_cells_1.sbs) | 0 | Yes | [Parity · 928,000/928,000 pixels across 88 distinct settings on one and eight processors](parity-fixes.md#inverting-the-stored-pixel-projection-in-scaled-stamp-regions) · [Earlier scaled-window comparisons](parity-fixes.md#projecting-stamp-vertices-relative-to-pixel-centers-in-scaled-windows) · [Earlier root comparisons](parity-fixes.md#bnw-spots-3-and-cells-1-pattern-sources) · [717,776/729,344 pixels in 60 settings at one and eight processors](parity-fixes.md#moisture-spot-and-cell-fields-across-processors-and-saved-packages) | +| [noise_cells_1_v2.sbs/cells_1](../assets/sbs/noise_cells_1_v2.sbs) | 0 | No | [Parity · 947,456/947,456 pixels across 89 distinct settings on one and eight processors](parity-fixes.md#inverting-the-stored-pixel-projection-in-scaled-stamp-regions) · [Earlier scaled-window comparisons](parity-fixes.md#projecting-stamp-vertices-relative-to-pixel-centers-in-scaled-windows) · [Earlier root comparisons](parity-fixes.md#original-and-reopened-dirt-moisture-and-cellular-noise-fields) · [Earlier measurements](parity-fixes.md#streaming-repeated-pattern-visits) · [745,614/748,800 pixels in 61 settings at one and eight processors](parity-fixes.md#moisture-spot-and-cell-fields-across-processors-and-saved-packages) | +| [noise_cells_4.sbs/cells_4](../assets/sbs/noise_cells_4.sbs) | 1 | Yes | [Parity · 1,028,608/1,028,608 pixels across 79 distinct settings](parity-fixes.md#distance-propagation-on-rectangular-and-tied-cellular-fields) · [Earlier measurements](parity-fixes.md#original-and-reopened-dirt-moisture-and-cellular-noise-fields) · [Earlier measurements](parity-fixes.md#paths-caustics-and-cell-fields-after-pattern-sampling) | +| [noise_cells_4_v2.sbs/cells_4](../assets/sbs/noise_cells_4_v2.sbs) | 1 | No | [Parity · 1,028,608/1,028,608 pixels across 79 distinct settings](parity-fixes.md#distance-propagation-on-rectangular-and-tied-cellular-fields) · [Earlier measurements](parity-fixes.md#original-and-reopened-dirt-moisture-and-cellular-noise-fields) · [Earlier measurements](parity-fixes.md#paths-caustics-and-cell-fields-after-pattern-sampling) | +| [noise_clouds_1.sbs/clouds_1](../assets/sbs/noise_clouds_1.sbs) | 0 | Yes | [In progress · all 60 originals and 15 saves render, 729,224/729,344 original pixels on one processor and 729,126/729,344 on eight](parity-fixes.md#complete-rectangular-render-coverage-in-the-first-clouds-graph) · [Earlier comparison · 725,131/725,248 whole pixels on one processor, 725,033 on eight, 58/60 settings rendered](parity-fixes.md#four-child-pattern-order-as-a-tile-copy-batch-fills) · [Earlier comparison · 725,069/725,248 whole pixels on one processor, 725,041 on eight, 58/60 settings rendered](parity-fixes.md#tile-copy-batches-across-repeated-six-level-quadrant-trees) · [Earlier comparison · 724,953/725,248 whole pixels on one processor, 725,009 on eight, 58/60 settings rendered](parity-fixes.md#six-level-quadrant-draw-order-after-an-iteration-or-switch) · [Earlier comparison · 724,362/725,248 one-processor pixels in 58/60 settings across four formats, 2 execution-limit settings](parity-fixes.md#four-cloud-noise-generators-and-repeated-saved-file-comparisons) · [Earlier scale comparisons](parity-fixes.md#cloud-and-crystal-pattern-sources-across-scales) · [Explicit renderer workers and repeatability](parity-fixes.md#patterns-with-an-explicit-reference-worker-count) · [Five F32 returns per processor count at 32²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_clouds_1_v2.sbs/clouds_1](../assets/sbs/noise_clouds_1_v2.sbs) | 0 | No | [In progress · 60/60 originals and 15/15 archived saves render](parity-fixes.md#rectangular-clouds-and-directional-noise-graphs-with-seeded-quadrant-offsets) · [Earlier comparison · 58/60 established originals and 14/15 archived saves render](parity-fixes.md#two-more-whole-outputs-in-noise-clouds-1-v2) · [Earlier comparison · 674,152/692,480 whole pixels on one processor, 666,536 on eight, 56/60 settings rendered](parity-fixes.md#whole-and-saved-outputs-for-noise-clouds-1-v2-at-the-four-child-batch-boundary) · [10,490,530 terminal and parent draws in the blocked rectangle](parity-fixes.md#counting-terminal-draws-in-the-two-remaining-clouds-variants) · [Earlier comparison · 110,592/110,592 isolated single-tree pixels on one processor, 40,960/40,960 after reopen, four whole settings measured](parity-fixes.md#four-child-pattern-order-as-a-tile-copy-batch-fills) · [Earlier comparison · 662,116/692,480 one-processor pixels in 56/60 settings across four formats, 4 execution-limit settings](parity-fixes.md#four-cloud-noise-generators-and-repeated-saved-file-comparisons) · [Earlier scale comparisons](parity-fixes.md#cloud-and-crystal-pattern-sources-across-scales) · [6/6 tiled settings render, 5 exact on one processor](parity-fixes.md#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) · [8/8 untiled settings render](parity-fixes.md#untiled-spots-clouds-directional-noise-and-dirt-at-two-rectangular-sizes) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_clouds_2.sbs/clouds_2](../assets/sbs/noise_clouds_2.sbs) | 0 | Yes | [In progress · 729,344/729,344 whole pixels on one processor, 729,321 on eight, 60/60 settings rendered](parity-fixes.md#eight-level-two-child-drawing-across-equal-tile-and-render-windows) · [Earlier comparison · 729,341/729,344 whole pixels on one processor, 729,324 on eight, 60/60 settings rendered](parity-fixes.md#tile-copy-batches-across-repeated-six-level-quadrant-trees) · [Earlier comparison · 729,319/729,344 whole pixels on one processor, 729,310 on eight, 60/60 settings rendered](parity-fixes.md#six-level-quadrant-draw-order-after-an-iteration-or-switch) · [Earlier comparison · 729,177/729,344 one-processor pixels in 60/60 settings across four formats](parity-fixes.md#four-cloud-noise-generators-and-repeated-saved-file-comparisons) · [Earlier scale comparisons](parity-fixes.md#cloud-and-crystal-pattern-sources-across-scales) | +| [noise_clouds_2_v2.sbs/clouds_2](../assets/sbs/noise_clouds_2_v2.sbs) | 0 | No | [In progress · 60/60 originals and 15/15 archived saves render](parity-fixes.md#rectangular-clouds-and-directional-noise-graphs-with-seeded-quadrant-offsets) · [Earlier comparison · 722,941/725,248 whole pixels on one processor, 722,261 on eight, 58/60 settings rendered](parity-fixes.md#whole-and-saved-outputs-for-noise-clouds-2-v2-with-equal-window-batching) · [Both rectangular settings still reach the limit](parity-fixes.md#two-more-whole-outputs-in-noise-clouds-1-v2) · [7,313,940 terminal and parent draws in the blocked rectangle](parity-fixes.md#counting-terminal-draws-in-the-two-remaining-clouds-variants) · [Earlier comparison · 129,319/131,072 F32 stage pixels on one processor, six settings and three reopens measured](parity-fixes.md#eight-level-two-child-drawing-across-equal-tile-and-render-windows) · [Earlier comparison · 719,209/725,248 one-processor pixels in 58/60 settings across four formats, 2 execution-limit settings](parity-fixes.md#four-cloud-noise-generators-and-repeated-saved-file-comparisons) · [Earlier scale comparisons](parity-fixes.md#cloud-and-crystal-pattern-sources-across-scales) · [Default 16² F32, 256/256 on one processor and 252/256 on eight](parity-fixes.md#single-branch-controls-in-complete-quadrant-trees) · [6/6 tiled settings render, 5 exact on one processor](parity-fixes.md#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) · [8/8 untiled settings render](parity-fixes.md#untiled-spots-clouds-directional-noise-and-dirt-at-two-rectangular-sizes) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_creased.sbs/creased](../assets/sbs/noise_creased.sbs) | 0 | No | [Parity · 787,456/787,456 pixels across 54 distinct settings on one and eight processors](parity-fixes.md#creased-and-crystal-noise-sources-on-one-and-eight-processors) · [Archived settings](parity-fixes.md#original-and-reopened-dirt-moisture-and-cellular-noise-fields) · [Earlier measurements](parity-fixes.md#directional-and-additive-stamp-profiles) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) | +| [noise_crystal_1.sbs/crystal_1](../assets/sbs/noise_crystal_1.sbs) | 0 | No | [Parity · 809,216/809,216 pixels across 64 distinct settings on one and eight processors](parity-fixes.md#creased-and-crystal-noise-sources-on-one-and-eight-processors) · [Archived settings](parity-fixes.md#original-and-reopened-dirt-moisture-and-cellular-noise-fields) · [Earlier measurements](parity-fixes.md#cloud-and-crystal-pattern-sources-across-scales) | +| [noise_crystal_2.sbs/crystal_2](../assets/sbs/noise_crystal_2.sbs) | 0 | No | [Parity · 809,216/809,216 pixels across 64 distinct settings on one and eight processors](parity-fixes.md#creased-and-crystal-noise-sources-on-one-and-eight-processors) · [Archived settings](parity-fixes.md#original-and-reopened-dirt-moisture-and-cellular-noise-fields) · [Earlier measurements](parity-fixes.md#cloud-and-crystal-pattern-sources-across-scales) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) | +| [noise_directional_noise_1.sbs/directional_noise_1](../assets/sbs/noise_directional_noise_1.sbs) | 0 | Yes | [In progress · 734,118/734,464 whole pixels across 60 settings on one processor, 734,140 on eight](parity-fixes.md#final-three-quadrant-levels-in-directional-noise-1) · [Seven interior routes and their ordinary saves](parity-fixes.md#interior-routes-between-terminal-quadrants) · [Outer routes and five ordinary reopens](parity-fixes.md#outer-routes-into-the-final-three-active-quadrant-levels) · [Partly wrapped copies and seven reopens](parity-fixes.md#partly-wrapped-copies-in-directional-noise-1) · [Copy counts across sampling windows](parity-fixes.md#terminal-quadrant-order-across-sampling-windows) · [Earlier directional measurements](parity-fixes.md#directional-noise-and-scratch-pattern-sources) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_directional_noise_1_v2.sbs/directional_noise_1](../assets/sbs/noise_directional_noise_1_v2.sbs) | 0 | No | [In progress · earlier stages and maximum-blend control exact at 16² and 32², additive differences remain](parity-fixes.md#addition-and-maximum-blending-in-directional-noise-1-v2) · [Earlier comparison · 60/60 originals and 12/12 saves render, 626,333/734,464 original pixels on one processor and 633,052 on eight](parity-fixes.md#complete-render-coverage-in-the-second-version-of-directional-noise-1) · [Earlier comparison · 56/60 whole settings rendered, 618,970/726,272 pixels on one processor, 625,683 on eight](parity-fixes.md#sixty-whole-settings-for-three-directional-and-dirt-noise-packages) · [Earlier comparison · 133,251/142,592 pixels in 18 comparable renders](parity-fixes.md#directional-noise-and-scratch-pattern-sources) · [6/6 tiled settings render, 3 exact on one processor](parity-fixes.md#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) · [8/8 untiled settings render](parity-fixes.md#untiled-spots-clouds-directional-noise-and-dirt-at-two-rectangular-sizes) · [Untiled F32 original and ordinary save](parity-fixes.md#seeded-quadrant-properties-with-a-live-tint-multiplier) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_directional_noise_2.sbs/directional_noise_2](../assets/sbs/noise_directional_noise_2.sbs) | 0 | Yes | [In progress · 60/60 original settings and 12/12 archived reopens rendered](parity-fixes.md#all-sixty-original-directional-noise-2-settings) · [Additive wave overlap controls](parity-fixes.md#additive-wave-overlaps-in-directional-noise-2) · [Two-branch F32 words and configured saves](parity-fixes.md#a-second-branch-beside-a-wrapped-wave) · [Earlier comparison · 103,497/107,776 pixels in 11 comparable renders](parity-fixes.md#directional-noise-and-scratch-pattern-sources) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) · [Single-tree fork order and six exact 16² sibling pairs](parity-fixes.md#drawing-a-shared-quadrant-path-with-its-last-child) · [Nine repeated trees and the draw batch boundary](parity-fixes.md#an-unfinished-draw-batch-across-repeated-quadrant-pairs) | +| [noise_directional_noise_2_v2.sbs/directional_noise_2](../assets/sbs/noise_directional_noise_2_v2.sbs) | 0 | No | [In progress · 60/60 original settings and 12/12 archived reopens rendered](parity-fixes.md#whole-images-for-sixty-directional-noise-2-v2-settings) · [Earlier comparison · 64² across four formats and configured saves](parity-fixes.md#a-tiled-square-in-directional-noise-2-v2) · [Earlier comparison · all four tiled 64 × 32 formats and saves render, F32 differences measured](parity-fixes.md#floored-modulo-in-seeded-drawing-properties) · [Earlier comparison · 105,116/107,776 pixels in 11 comparable renders](parity-fixes.md#directional-noise-and-scratch-pattern-sources) · [2/6 tiled settings render, 0 exact on one processor](parity-fixes.md#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) · [8/8 untiled settings render](parity-fixes.md#untiled-spots-clouds-directional-noise-and-dirt-at-two-rectangular-sizes) · [Untiled original and ordinary save, remaining tiled F32 limit](parity-fixes.md#seeded-quadrant-properties-with-a-live-tint-multiplier) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) · [Two individual waves fixed by shared floating-point modulo](parity-fixes.md#floating-point-modulo-at-a-rounded-period) · [All 60 originals and 12 archived reopens after the modulo correction](parity-fixes.md#all-directional-noise-2-v2-settings-after-the-modulo-correction) | +| [noise_directional_noise_3.sbs/directional_noise_3](../assets/sbs/noise_directional_noise_3.sbs) | 0 | Yes | [In progress · 60/60 originals and 12/12 archived ordinary saves rendered](parity-fixes.md#seeded-placement-in-the-remaining-directional-noise-3-rectangles) · [Earlier 52 originals and ten archived reopens](parity-fixes.md#drawing-parents-and-terminal-children-in-directional-noise-3) · [Earlier 44/60 settings and four ordinary saves](parity-fixes.md#accounting-for-a-streamed-draw-and-its-tile-copies) · [Earlier comparison · 40/60 settings rendered, 407,151/407,808 exact pixels on one and 407,274 on eight](parity-fixes.md#rectangular-and-additional-seed-coverage-in-directional-noise-3) · [First 19 settings · 17/19 established originals render, 141,209/141,568 pixels on one and 141,288 on eight](parity-fixes.md#streaming-equal-ranked-analytic-stamps-through-one-output-image) · [Earlier comparison · 15/19 original settings have rendered, eight additional settings and three ordinary saves compared](parity-fixes.md#reused-properties-across-adjacent-groups-of-terminal-quadrants) · [Earlier comparison · 7/19 whole renders completed, 7,168/7,424 exact pixels](parity-fixes.md#discarding-pattern-stamps-that-miss-every-output-sample) · [Original stage comparisons](parity-fixes.md#directional-noise-and-scratch-pattern-sources) · [Five F32 returns per processor count at 32²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) · [16-bit storage boundary and sixteen isolated wave branches](parity-fixes.md#an-additive-wave-at-a-16-bit-storage-boundary) | +| [noise_directional_noise_3_v2.sbs/directional_noise_3](../assets/sbs/noise_directional_noise_3_v2.sbs) | 0 | No | [In progress · 60 originals and 12 archived reopens rendered, 52/60 original images exact on one processor](parity-fixes.md#all-sixty-settings-in-directional-noise-3-v2) · [Earlier comparison · three larger F32 rectangles exact on both processor counts](parity-fixes.md#three-larger-rectangles-in-directional-noise-3-v2) · [Seven tiled F16 settings and 14,592/14,592 on ordinary reopens](parity-fixes.md#seven-tiled-half-precision-settings-in-directional-noise-3-v2) · [Earlier comparison · 64 × 16 at seed 42 exact in four formats on both file routes](parity-fixes.md#rectangular-clouds-and-directional-noise-graphs-with-seeded-quadrant-offsets) · [Earlier comparison · untiled rectangle exact in four formats, four tiled F16 saves 7,424/7,424, three settings reach the work limit](parity-fixes.md#half-precision-inputs-to-levels) · [Earlier rectangle and tiled stage comparisons](parity-fixes.md#a-recovered-rectangle-and-repeated-outputs-in-directional-noise-3-v2) · [Earlier 19-setting panel](parity-fixes.md#discarding-pattern-stamps-that-miss-every-output-sample) · [Original stage comparisons](parity-fixes.md#directional-noise-and-scratch-pattern-sources) · [2/6 tiled settings render, 2 exact on one processor](parity-fixes.md#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) · [0/8 untiled settings render](parity-fixes.md#untiled-spots-clouds-directional-noise-and-dirt-at-two-rectangular-sizes) · [Untiled F32 limits at both rectangles](parity-fixes.md#seeded-quadrant-properties-with-a-live-tint-multiplier) | +| [noise_directional_noise_4.sbs/directional_noise_4](../assets/sbs/noise_directional_noise_4.sbs) | 0 | Yes | [In progress · 60 originals and 12 archived reopens, 18/60 originals exact on one processor](parity-fixes.md#whole-image-comparisons-for-both-directional-noise-4-roots) · [Earlier comparison · 134,015/144,640 pixels in 19 comparable renders](parity-fixes.md#directional-noise-and-scratch-pattern-sources) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_directional_noise_4_v2.sbs/directional_noise_4](../assets/sbs/noise_directional_noise_4_v2.sbs) | 0 | No | [In progress · 60 originals and 12 archived reopens, 21/60 originals exact on one processor](parity-fixes.md#whole-image-comparisons-for-both-directional-noise-4-roots) · [Earlier comparison · 134,664/144,640 pixels in 19 comparable renders](parity-fixes.md#directional-noise-and-scratch-pattern-sources) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_directional_scratches.sbs/directional_scratches](../assets/sbs/noise_directional_scratches.sbs) | 0 | Yes | [Parity · 86/86 settings and 2,571,520/2,571,520 pixels on each processor count, 64 exact saves](parity-fixes.md#directional-scratches-across-scaled-projection-windows) · [Earlier scaled generator comparisons](parity-fixes.md#scaled-scratch-and-gaussian-noise-and-spot-generators) | +| [noise_directional_scratches_v2.sbs/directional_scratches](../assets/sbs/noise_directional_scratches_v2.sbs) | 0 | No | [Parity · 86/86 settings and 2,571,520/2,571,520 pixels on each processor count, 64 exact saves](parity-fixes.md#directional-scratches-across-scaled-projection-windows) · [Earlier scaled generator comparisons](parity-fixes.md#scaled-scratch-and-gaussian-noise-and-spot-generators) | +| [noise_dirt_1.sbs/dirt_1](../assets/sbs/noise_dirt_1.sbs) | 0 | Yes | [In progress · 12 additional settings exact on one processor and on ordinary saves, 7/12 on eight](parity-fixes.md#deferring-two-tiled-subtrees-until-a-quadrant-batch-fills) · [Earlier comparison · 41/60 whole tiled settings on one processor, two additional wide saves match 10,240/10,240 F32 pixels](parity-fixes.md#the-receiving-half-of-a-quadrant-in-two-tiled-trees) · [Earlier comparison · 41/60 whole tiled originals on one, 32/60 on eight, three additional tall F32 originals and saves exact](parity-fixes.md#four-full-batches-in-two-tiled-quadrant-trees) · [Five-batch tiled comparison](parity-fixes.md#tiled-copies-across-two-complete-quadrant-trees) · [Earlier comparison · 37/60 whole tiled settings exact on one processor, 32/60 on eight](parity-fixes.md#fixed-image-draws-in-tiled-dirt-graphs) · [All 60 originals and 12 archived ordinary saves rendered](parity-fixes.md#complete-render-coverage-for-the-two-fixed-image-dirt-graphs) · [13/13 untiled settings and nine additional whole settings exact on one processor and on reopening](parity-fixes.md#unfinished-draws-across-two-untiled-quadrant-trees) · [Five individually exact draws and their reference order](parity-fixes.md#five-individual-image-draws-at-one-dirt-1-pixel) · [Earlier U16 differences at 128 × 256](parity-fixes.md#individual-drawing-depths-at-a-dirt-1-rounding-boundary) · [58/60 originals and 11/12 archived ordinary saves rendered](parity-fixes.md#expanded-image-and-save-comparisons-for-dirt-1-and-dirt-2) · [Additional 32 × 16 F32 original and ordinary save](parity-fixes.md#streaming-deep-quadrants-that-draw-the-same-connected-image) · [Earlier comparison · 34/60 whole settings rendered, 508,903/512,256 pixels on one processor, 509,696 on eight](parity-fixes.md#whole-renders-and-reopened-settings-for-two-dirt-noise-generators) · [Earlier comparison · 11/19 whole outputs, 104,064/107,776 pixels](parity-fixes.md#dirt-noise-sources-and-downstream-stages) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_dirt_1_v2.sbs/dirt_1](../assets/sbs/noise_dirt_1_v2.sbs) | 0 | No | [In progress · 64 × 32 F32 control improved to 2,048/2,048 on one processor, 2,036/2,048 on its save](parity-fixes.md#deferring-two-tiled-subtrees-until-a-quadrant-batch-fills) · [Earlier comparison · 6/8 additional untiled originals on one, 6/8 on eight and all twelve iteration controls exact](parity-fixes.md#whole-untiled-dirt-relatives-and-the-depth-seven-iteration) · [Earlier comparison · 32 × 16 F32 still reaches the traversal guard](parity-fixes.md#streaming-deep-quadrants-that-draw-the-same-connected-image) · [Earlier comparison · 28/60 whole settings rendered, 427,334/430,336 pixels on one processor, 428,390 on eight](parity-fixes.md#whole-renders-and-reopened-settings-for-two-dirt-noise-generators) · [Earlier comparison · 11/19 whole outputs, 107,082/107,776 pixels](parity-fixes.md#dirt-noise-sources-and-downstream-stages) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_dirt_2.sbs/dirt_2](../assets/sbs/noise_dirt_2.sbs) | 0 | Yes | [In progress · all 20 selected originals and four archived save buffers reproduce the earlier measurements](parity-fixes.md#deferring-two-tiled-subtrees-until-a-quadrant-batch-fills) · [Earlier comparison · 53/60 whole tiled originals exact on one processor, 51/60 on eight](parity-fixes.md#tiled-copies-across-two-complete-quadrant-trees) · [Earlier comparison · 53/60 whole tiled settings exact on one processor, 51/60 on eight](parity-fixes.md#fixed-image-draws-in-tiled-dirt-graphs) · [All 60 originals and 12 archived ordinary saves rendered](parity-fixes.md#complete-render-coverage-for-the-two-fixed-image-dirt-graphs) · [58/60 originals and 11/12 archived ordinary saves rendered](parity-fixes.md#expanded-image-and-save-comparisons-for-dirt-1-and-dirt-2) · [Additional 32 × 16 U16 and F32 originals and saves exact](parity-fixes.md#streaming-deep-quadrants-that-draw-the-same-connected-image) · [Earlier comparison · 34/60 whole settings rendered, 512,247/512,256 pixels on one processor, 512,251 on eight](parity-fixes.md#whole-outputs-and-saved-settings-for-noise-dirt-2-and-noise-dirt-3) · [Earlier comparison · 11/19 whole outputs, 107,184/107,776 pixels](parity-fixes.md#dirt-noise-sources-and-downstream-stages) | +| [noise_dirt_3.sbs/dirt_3](../assets/sbs/noise_dirt_3.sbs) | 0 | Yes | [In progress · 60/60 originals have now rendered across the recorded passes](parity-fixes.md#rectangular-dirt-family-settings-recovered-by-the-shared-evaluator) · [Earlier comparison · 775,891/777,472 exact whole pixels on one processor, 775,939 on eight, 58/60 settings rendered](parity-fixes.md#compositing-a-single-seven-level-tree-through-pattern-controls) · [Earlier comparison · 58/60 whole settings rendered, 775,891/777,472 pixels on one processor, 775,939 on eight](parity-fixes.md#whole-outputs-and-saved-settings-for-noise-dirt-2-and-noise-dirt-3) · [Earlier comparison · 19/19 whole outputs, 135,236/142,592 pixels](parity-fixes.md#dirt-noise-sources-and-downstream-stages) · [6/6 tiled settings render, 4 exact on one processor](parity-fixes.md#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) · [8/8 untiled settings render](parity-fixes.md#untiled-spots-clouds-directional-noise-and-dirt-at-two-rectangular-sizes) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_dirt_3_v2.sbs/dirt_3](../assets/sbs/noise_dirt_3_v2.sbs) | 0 | No | [In progress · 771,398/777,472 whole pixels on one processor, 771,548 on eight, 58/60 settings rendered](parity-fixes.md#whole-and-saved-outputs-for-noise-dirt-3-v2) · [Earlier comparison · 17/19 whole outputs, 136,738/141,568 pixels](parity-fixes.md#dirt-noise-sources-and-downstream-stages) · [6/6 tiled settings render, 4 exact on one processor](parity-fixes.md#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) · [8/8 untiled settings render](parity-fixes.md#untiled-spots-clouds-directional-noise-and-dirt-at-two-rectangular-sizes) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_dirt_4.sbs/dirt_4](../assets/sbs/noise_dirt_4.sbs) | 0 | Yes | [In progress · 1,536/1,536 with both equal-size Sharpen modes and 384/384 on F16 reopens](parity-fixes.md#half-precision-inputs-to-sharpen) · [Earlier comparison · 6/8 complete additional settings on one processor, 8/8 on eight and 7/8 ordinary saves](parity-fixes.md#recovered-dirt-4-and-moisture-renders-at-seed-113) · [Earlier comparison · 10/19 whole renders completed, 89,052/105,728 exact pixels](parity-fixes.md#discarding-pattern-stamps-that-miss-every-output-sample) · [Recovered 16 × 32 F32 setting, 512/512 exact pixels on one processor](parity-fixes.md#rectangular-dirt-family-settings-recovered-by-the-shared-evaluator) · [Original stage comparisons](parity-fixes.md#dirt-noise-sources-and-downstream-stages) · [32 × 16, U8 and F32 exact on both processor counts](parity-fixes.md#dense-seeded-quadrants-in-moisture-noise-and-dirt-4) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_dirt_4_v2.sbs/dirt_4](../assets/sbs/noise_dirt_4_v2.sbs) | 0 | No | [In progress · 128 × 32 scale 2 renders in four formats on original and ordinary reopen](parity-fixes.md#one-repeated-branch-in-dirt-4-v2) · [Earlier comparison · 128 × 32 scale 3 variation isolated to one U8 texel, whole cook still reaches its limit](parity-fixes.md#a-one-level-pattern-change-before-sharpen-in-dirt-4-v2) · [Earlier comparison · 32 × 16 at seed 105532, 2,048/2,048 across four formats](parity-fixes.md#bound-arithmetic-in-seeded-quadrant-properties) · [Previous comparison · 1,536/1,536 with both equal-size Sharpen modes and 384/384 on F16 reopens](parity-fixes.md#half-precision-inputs-to-sharpen) · [Earlier comparison · 5/19 whole renders completed, 99,535/99,584 exact pixels](parity-fixes.md#discarding-pattern-stamps-that-miss-every-output-sample) · [Recovered 16 × 32 F32 setting, 512/512 exact pixels on one processor](parity-fixes.md#rectangular-dirt-family-settings-recovered-by-the-shared-evaluator) · [Original stage comparisons](parity-fixes.md#dirt-noise-sources-and-downstream-stages) · [Earlier 32 × 16 work limit at seed 105532](parity-fixes.md#dense-seeded-quadrants-in-moisture-noise-and-dirt-4) · [Five F32 returns per processor count at 128 × 32](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_dirt_5.sbs/dirt_5](../assets/sbs/noise_dirt_5.sbs) | 0 | Yes | [In progress · all 60 originals and 12 archived saves render, 31/60 exact on one processor and 30/60 on eight](parity-fixes.md#shared-branch-expressions-and-all-sixty-noise-dirt-5-renders) · [Single-tree F32 comparison, 5,120/5,120 on one processor and after reopening](parity-fixes.md#a-complete-quadrant-tree-with-one-physical-copy-per-draw) · [Earlier comparison · 58/60 tiled whole settings render, all ten recovered settings also measured after ordinary saves](parity-fixes.md#ten-recovered-whole-noise-dirt-5-settings) · [Earlier comparison · eight additional tiled settings and ordinary saves match 40,960/40,960 pixels on one processor, 4/8 settings on eight](parity-fixes.md#deferring-two-tiled-subtrees-until-a-quadrant-batch-fills) · [Earlier comparison · 8/8 additional untiled originals on one, 5/8 on eight, 8/8 ordinary saves](parity-fixes.md#whole-untiled-dirt-relatives-and-the-depth-seven-iteration) · [Earlier comparison · six of eight additional wide settings exact on one processor, both 128 × 64 formats match all 8,187 invariant locations](parity-fixes.md#the-receiving-half-of-a-quadrant-in-two-tiled-trees) · [Earlier comparison · 48/60 whole settings rendered, 701,551/701,696 pixels on one processor, 701,572 on eight](parity-fixes.md#sixty-whole-settings-for-three-directional-and-dirt-noise-packages) · [Recovered 32 × 16 F32 setting, 512/512 exact pixels on one processor](parity-fixes.md#rectangular-dirt-family-settings-recovered-by-the-shared-evaluator) · [Earlier comparison · 32² now exact](parity-fixes.md#deep-pattern-samples-in-custom-render-and-tiling-regions) · [Earlier matrix](parity-fixes.md#dirt-noise-sources-and-downstream-stages) · [64² precision and remaining traversal limits](parity-fixes.md#precision-of-two-dense-noise-generators-in-custom-regions) · [Five F32 returns per processor count at 32²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) · [32² Iterate regression across four formats](parity-fixes.md#one-repeated-branch-in-dirt-4-v2) | +| [noise_dirt_5_v2.sbs/dirt_5](../assets/sbs/noise_dirt_5_v2.sbs) | 0 | No | [In progress · 6/8 additional untiled originals on one, 6/8 on eight, 6/8 ordinary saves](parity-fixes.md#whole-untiled-dirt-relatives-and-the-depth-seven-iteration) · [Earlier comparison · 11/19 whole outputs, 107,341/107,776 pixels](parity-fixes.md#dirt-noise-sources-and-downstream-stages) · [Recovered 32 × 16 F32 setting, 457/512 exact pixels on one processor](parity-fixes.md#rectangular-dirt-family-settings-recovered-by-the-shared-evaluator) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) · [32² Iterate regression across four formats](parity-fixes.md#one-repeated-branch-in-dirt-4-v2) | +| [noise_dirt_gradient.sbs/dirt_gradient](../assets/sbs/noise_dirt_gradient.sbs) | 0 | Yes | [In progress · 8/8 additional untiled originals on one, 7/8 on eight, 8/8 ordinary saves](parity-fixes.md#whole-untiled-dirt-relatives-and-the-depth-seven-iteration) · [Earlier comparison · 60/60 originals have now rendered across the recorded passes](parity-fixes.md#rectangular-dirt-family-settings-recovered-by-the-shared-evaluator) · [Earlier comparison · 58/60 whole settings rendered, 653,612/654,592 pixels on one processor, 653,621 on eight](parity-fixes.md#sixty-whole-settings-for-three-directional-and-dirt-noise-packages) · [Earlier comparison · 19/19 whole outputs, 141,554/142,592 pixels](parity-fixes.md#dirt-noise-sources-and-downstream-stages) · [Five F32 returns per processor count at 16 × 32](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_dirt_gradient_v2.sbs/dirt_gradient](../assets/sbs/noise_dirt_gradient_v2.sbs) | 0 | No | [In progress · 5/8 additional untiled originals on each processor count, 5/8 ordinary saves, all U8 and F16 pixels exact on one processor](parity-fixes.md#filtering-a-resized-pattern-background-on-each-axis) · [Earlier comparison · 1/8 additional untiled originals on one, 2/8 on eight, 1/8 ordinary saves](parity-fixes.md#whole-untiled-dirt-relatives-and-the-depth-seven-iteration) · [Earlier comparison · 40/60 whole settings rendered, 428,169/464,640 exact pixels on one processor, 434,967 on eight](parity-fixes.md#sixty-whole-renders-after-correcting-the-inner-iterator) · [Recovered 32 × 16 F32 setting, 361/512 exact pixels on one processor](parity-fixes.md#rectangular-dirt-family-settings-recovered-by-the-shared-evaluator) · [Nested initial branch, 704/704 middle-stage samples](parity-fixes.md#initial-branch-of-a-nested-pattern-iterator) · [Earlier 19 outputs](parity-fixes.md#dirt-noise-sources-and-downstream-stages) · [Single-tree final stage, 2,816/2,816 F32 pixels with wrapping off](parity-fixes.md#single-branch-controls-in-complete-quadrant-trees) · [6/6 tiled settings render, 3 exact on one processor](parity-fixes.md#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_fluid.sbs/fluid](../assets/sbs/noise_fluid.sbs) | 0 | No | [Parity · 71 whole settings, 1,266,944/1,266,944 pixels on each processor count, 15 exact reopens](parity-fixes.md#noise-fluid-across-procedural-controls-and-stored-formats) · [Earlier 53 settings](parity-fixes.md#diagonal-blur-across-rectangular-tile-edges) · [Fourteen downstream root comparisons](parity-fixes.md#downstream-root-captures-after-the-aligned-blur-correction) | +| [noise_fractal_sum_base.sbs/fractal_sum_base](../assets/sbs/noise_fractal_sum_base.sbs) | 0 | Yes | [Parity · 18 renders, 145,664 exact pixels](parity-fixes.md#stored-grayscale-stops-and-scalar-levels-controls) | +| [noise_fractal_sum_base.sbs/fractal_sum_base_2](../assets/sbs/noise_fractal_sum_base.sbs) | 0 | Yes | [Parity · 18 renders, 145,664 exact pixels](parity-fixes.md#stored-grayscale-stops-and-scalar-levels-controls) | +| [noise_fractal_sum_base_v2.sbs/noise_blend](../assets/sbs/noise_fractal_sum_base_v2.sbs) | 2 | Yes | [Parity · 17 renders, 142,592 exact pixels](parity-fixes.md#box-blur-and-signed-pixel-sizes) | | [noise_fractal_sum_base_v2.sbs/noise_disorder](../assets/sbs/noise_fractal_sum_base_v2.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [noise_fractal_sum_base_v2.sbs/noise_upscale](../assets/sbs/noise_fractal_sum_base_v2.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_fur_1.sbs/fur_1](../assets/sbs/noise_fur_1.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_fur_2.sbs/fur_2](../assets/sbs/noise_fur_2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_fur_3.sbs/fur_3](../assets/sbs/noise_fur_3.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_gaussian_noise.sbs/gaussian_noise](../assets/sbs/noise_gaussian_noise.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_gaussian_noise_v2.sbs/gaussian_noise](../assets/sbs/noise_gaussian_noise_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_gaussian_spots_1.sbs/gaussian_spots_1](../assets/sbs/noise_gaussian_spots_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_gaussian_spots_1_v2.sbs/gaussian_spots_1](../assets/sbs/noise_gaussian_spots_1_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_gaussian_spots_2.sbs/gaussian_spots_2](../assets/sbs/noise_gaussian_spots_2.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_gaussian_spots_2_v2.sbs/gaussian_spots_2](../assets/sbs/noise_gaussian_spots_2_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_liquid.sbs/liquid](../assets/sbs/noise_liquid.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_messy_fibers_1.sbs/messy_fibers_1](../assets/sbs/noise_messy_fibers_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_messy_fibers_1_v2.sbs/messy_fibers_1](../assets/sbs/noise_messy_fibers_1_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_messy_fibers_2.sbs/messy_fibers_2](../assets/sbs/noise_messy_fibers_2.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_messy_fibers_2_v2.sbs/messy_fibers_2](../assets/sbs/noise_messy_fibers_2_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_messy_fibers_3.sbs/messy_fibers_3](../assets/sbs/noise_messy_fibers_3.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_messy_fibers_3_v2.sbs/messy_fibers_3](../assets/sbs/noise_messy_fibers_3_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_microscope_view.sbs/microscope_view](../assets/sbs/noise_microscope_view.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_moisture_noise.sbs/moisture_noise](../assets/sbs/noise_moisture_noise.sbs) | 0 | Yes | [Too hard: measurement timeout](parity-fixes.md#remaining-differences) | -| [noise_moisture_noise_1_v2.sbs/moisture_noise_1](../assets/sbs/noise_moisture_noise_1_v2.sbs) | 0 | No | [Too hard: measurement timeout](parity-fixes.md#remaining-differences) | -| [noise_moisture_noise_2.sbs/moisture_noise_2](../assets/sbs/noise_moisture_noise_2.sbs) | 0 | No | [Too hard: measurement timeout](parity-fixes.md#remaining-differences) | -| [noise_perlin_noise.sbs/perlin_noise](../assets/sbs/noise_perlin_noise.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_perlin_noise_v2.sbs/perlin_noise](../assets/sbs/noise_perlin_noise_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_plasma.sbs/plasma](../assets/sbs/noise_plasma.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_upscale_1.sbs/noise_upscale_1](../assets/sbs/noise_upscale_1.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_upscale_2.sbs/noise_upscale_2](../assets/sbs/noise_upscale_2.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_upscale_3.sbs/noise_upscale_3](../assets/sbs/noise_upscale_3.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_voronoi.sbs/3d_voronoi](../assets/sbs/noise_voronoi.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_voronoi.sbs/3d_voronoi_fractal](../assets/sbs/noise_voronoi.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_voronoi.sbs/voronoi](../assets/sbs/noise_voronoi.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [noise_voronoi.sbs/voronoi_fractal](../assets/sbs/noise_voronoi.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [non_square_transform.sbs/non_square_transform](../assets/sbs/non_square_transform.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [non_square_transform.sbs/non_square_transform_greyscale](../assets/sbs/non_square_transform.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [non_uniform_blur.sbs/non_uniform_blur_grayscale_sample](../assets/sbs/non_uniform_blur.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [non_uniform_blur.sbs/non_uniform_blur_sample](../assets/sbs/non_uniform_blur.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [non_uniform_rotation.sbs/non_uniform_rotation_color](../assets/sbs/non_uniform_rotation.sbs) | 3 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [non_uniform_rotation.sbs/non_uniform_rotation_grayscale](../assets/sbs/non_uniform_rotation.sbs) | 3 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [noise_fractal_sum_base_v2.sbs/noise_upscale](../assets/sbs/noise_fractal_sum_base_v2.sbs) | 1 | Yes | [Parity · 17 renders, 142,592 exact pixels](parity-fixes.md#tone-curve-sampling-and-saved-handles) | +| [noise_fur_1.sbs/fur_1](../assets/sbs/noise_fur_1.sbs) | 0 | No | [Parity · 62/62 settings and 811,264/811,264 pixels on each processor count, 15 exact saved-file comparisons](parity-fixes.md#fur-1-across-scaled-windows-and-saved-files) · [Earlier stored-opacity comparison](parity-fixes.md#stored-opacity-across-pattern-depths) | +| [noise_fur_2.sbs/fur_2](../assets/sbs/noise_fur_2.sbs) | 0 | No | [In progress · 794,404/821,504 exact whole pixels on one processor, 780,516 on eight, 62/62 settings rendered](parity-fixes.md#compositing-a-single-seven-level-tree-through-pattern-controls) · [Earlier comparison · 130,666/178,432 exact pixels, first difference in FX-Map](parity-fixes.md#fur-pattern-sources-and-downstream-filters) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_fur_3.sbs/fur_3](../assets/sbs/noise_fur_3.sbs) | 0 | No | [In progress · 132,982/178,432 exact pixels, first difference in FX-Map](parity-fixes.md#fur-pattern-sources-and-downstream-filters) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_gaussian_noise.sbs/gaussian_noise](../assets/sbs/noise_gaussian_noise.sbs) | 0 | Yes | [Parity · 91/91 settings and 2,855,168/2,855,168 pixels on each processor count, 68 exact saves](parity-fixes.md#gaussian-noise-across-scaled-projection-windows) · [Earlier scaled generator comparisons](parity-fixes.md#tiling-periods-on-rectangular-gaussian-noise-graphs) | +| [noise_gaussian_noise_v2.sbs/gaussian_noise](../assets/sbs/noise_gaussian_noise_v2.sbs) | 0 | No | [Parity · 91/91 settings and 2,855,168/2,855,168 pixels on each processor count, 68 exact saves](parity-fixes.md#gaussian-noise-across-scaled-projection-windows) · [Earlier scaled generator comparisons](parity-fixes.md#tiling-periods-on-rectangular-gaussian-noise-graphs) | +| [noise_gaussian_spots_1.sbs/gaussian_spots_1](../assets/sbs/noise_gaussian_spots_1.sbs) | 0 | Yes | [Parity · 79/79 settings and 2,808,832/2,808,832 pixels on each processor count, 65 exact saves](parity-fixes.md#gaussian-spots-1-across-scaled-projection-windows) · [Earlier scaled generator comparisons](parity-fixes.md#scaled-scratch-and-gaussian-noise-and-spot-generators) | +| [noise_gaussian_spots_1_v2.sbs/gaussian_spots_1](../assets/sbs/noise_gaussian_spots_1_v2.sbs) | 0 | No | [Parity · 79/79 settings and 2,808,832/2,808,832 pixels on each processor count, 65 exact saves](parity-fixes.md#gaussian-spots-1-across-scaled-projection-windows) · [Earlier scaled generator comparisons](parity-fixes.md#scaled-scratch-and-gaussian-noise-and-spot-generators) | +| [noise_gaussian_spots_2.sbs/gaussian_spots_2](../assets/sbs/noise_gaussian_spots_2.sbs) | 0 | Yes | [In progress · 796,492/809,216 whole pixels on one processor, 791,872 on eight, 56/62 settings rendered](parity-fixes.md#whole-and-saved-outputs-for-the-two-gaussian-spots-2-noise-generators) · [Earlier comparison · 132,670/174,336 exact pixels · 2 additional cases exceeded the traversal limit](parity-fixes.md#gaussian-pattern-sources-and-repeat-limits) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_gaussian_spots_2_v2.sbs/gaussian_spots_2](../assets/sbs/noise_gaussian_spots_2_v2.sbs) | 0 | No | [In progress · 772,363/809,216 whole pixels on one processor, 766,177 on eight, 56/62 settings rendered](parity-fixes.md#whole-and-saved-outputs-for-the-two-gaussian-spots-2-noise-generators) · [Earlier comparison · 136,601/174,336 exact pixels · 2 additional cases exceeded the traversal limit](parity-fixes.md#gaussian-pattern-sources-and-repeat-limits) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) | +| [noise_liquid.sbs/liquid](../assets/sbs/noise_liquid.sbs) | 0 | No | [Parity · 91/91 settings, 820,480/820,480 pixels on one processor, eight and ordinary reopen](parity-fixes.md#gradient-warp-on-stretched-pixels) · [Previous comparison · 135,824/142,592 pixels](parity-fixes.md#liquid-fiber-and-related-noise-sources) | +| [noise_messy_fibers_1.sbs/messy_fibers_1](../assets/sbs/noise_messy_fibers_1.sbs) | 0 | Yes | [Parity · 60/60 settings and 775,424/775,424 pixels on each processor count, 38 exact saves](parity-fixes.md#noise-library-messy-fibers-and-microscope-view) · [Earlier fiber and noise comparisons](parity-fixes.md#liquid-fiber-and-related-noise-sources) | +| [noise_messy_fibers_1_v2.sbs/messy_fibers_1](../assets/sbs/noise_messy_fibers_1_v2.sbs) | 0 | No | [Parity · 60/60 settings and 775,424/775,424 pixels on each processor count, 38 exact saves](parity-fixes.md#noise-library-messy-fibers-and-microscope-view) · [Earlier fiber and noise comparisons](parity-fixes.md#liquid-fiber-and-related-noise-sources) | +| [noise_messy_fibers_2.sbs/messy_fibers_2](../assets/sbs/noise_messy_fibers_2.sbs) | 0 | Yes | [Parity · 60/60 settings and 775,424/775,424 pixels on each processor count, 38 exact saves](parity-fixes.md#noise-library-messy-fibers-and-microscope-view) · [Earlier fiber and noise comparisons](parity-fixes.md#liquid-fiber-and-related-noise-sources) | +| [noise_messy_fibers_2_v2.sbs/messy_fibers_2](../assets/sbs/noise_messy_fibers_2_v2.sbs) | 0 | No | [Parity · 60/60 settings and 775,424/775,424 pixels on each processor count, 38 exact saves](parity-fixes.md#noise-library-messy-fibers-and-microscope-view) · [Earlier fiber and noise comparisons](parity-fixes.md#liquid-fiber-and-related-noise-sources) | +| [noise_messy_fibers_3.sbs/messy_fibers_3](../assets/sbs/noise_messy_fibers_3.sbs) | 0 | Yes | [Parity · 60/60 settings and 775,424/775,424 pixels on each processor count, 38 exact saves](parity-fixes.md#noise-library-messy-fibers-and-microscope-view) · [Earlier fiber and noise comparisons](parity-fixes.md#liquid-fiber-and-related-noise-sources) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) | +| [noise_messy_fibers_3_v2.sbs/messy_fibers_3](../assets/sbs/noise_messy_fibers_3_v2.sbs) | 0 | No | [Parity · 60/60 settings and 775,424/775,424 pixels on each processor count, 38 exact saves](parity-fixes.md#noise-library-messy-fibers-and-microscope-view) · [Earlier fiber and noise comparisons](parity-fixes.md#liquid-fiber-and-related-noise-sources) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) | +| [noise_microscope_view.sbs/microscope_view](../assets/sbs/noise_microscope_view.sbs) | 0 | No | [Parity · 60/60 settings and 775,424/775,424 pixels on each processor count, 38 exact saves](parity-fixes.md#noise-library-messy-fibers-and-microscope-view) · [Earlier fiber and noise comparisons](parity-fixes.md#liquid-fiber-and-related-noise-sources) | +| [noise_moisture_noise.sbs/moisture_noise](../assets/sbs/noise_moisture_noise.sbs) | 0 | Yes | [In progress · 11/19 whole outputs, 107,093/107,776 exact pixels](parity-fixes.md#liquid-fiber-and-related-noise-sources) · [128 × 32 original and reopened, 16,384/16,384 pixels](parity-fixes.md#dense-seeded-quadrants-in-moisture-noise-and-dirt-4) | +| [noise_moisture_noise_1_v2.sbs/moisture_noise_1](../assets/sbs/noise_moisture_noise_1_v2.sbs) | 0 | No | [In progress · 5/8 complete additional settings on one processor, 5/8 on eight and 5/8 ordinary saves](parity-fixes.md#recovered-dirt-4-and-moisture-renders-at-seed-113) · [Earlier comparison · 11/19 whole outputs, 104,176/107,776 exact pixels](parity-fixes.md#liquid-fiber-and-related-noise-sources) | +| [noise_moisture_noise_2.sbs/moisture_noise_2](../assets/sbs/noise_moisture_noise_2.sbs) | 0 | No | [In progress · 6/8 complete additional settings on one processor, 6/8 on eight and 6/8 ordinary saves](parity-fixes.md#recovered-dirt-4-and-moisture-renders-at-seed-113) · [Earlier comparison · 11/19 whole outputs, 104,071/107,776 exact pixels](parity-fixes.md#liquid-fiber-and-related-noise-sources) | +| [noise_perlin_noise.sbs/perlin_noise](../assets/sbs/noise_perlin_noise.sbs) | 0 | Yes | [Parity · 60/60 settings and 775,424/775,424 pixels on each processor count, 15 exact saves](parity-fixes.md#perlin-noise-and-plasma-across-rectangular-projections) · [Earlier noise settings](parity-fixes.md#liquid-fiber-and-related-noise-sources) | +| [noise_perlin_noise_v2.sbs/perlin_noise](../assets/sbs/noise_perlin_noise_v2.sbs) | 0 | No | [Parity · 60/60 settings and 775,424/775,424 pixels on each processor count, 15 exact saves](parity-fixes.md#perlin-noise-and-plasma-across-rectangular-projections) · [Earlier noise settings](parity-fixes.md#liquid-fiber-and-related-noise-sources) | +| [noise_plasma.sbs/plasma](../assets/sbs/noise_plasma.sbs) | 0 | No | [Parity · 60/60 settings and 775,424/775,424 pixels on each processor count, 15 exact saves](parity-fixes.md#perlin-noise-and-plasma-across-rectangular-projections) · [Earlier noise settings](parity-fixes.md#liquid-fiber-and-related-noise-sources) | +| [noise_upscale_1.sbs/noise_upscale_1](../assets/sbs/noise_upscale_1.sbs) | 1 | No | [Parity · 21 renders, 697,344 exact pixels](parity-fixes.md#sampling-integer-bitmap-inputs-through-wider-bridges) | +| [noise_upscale_2.sbs/noise_upscale_2](../assets/sbs/noise_upscale_2.sbs) | 1 | No | [Parity · 21 renders, 697,344 exact pixels](parity-fixes.md#sampling-integer-bitmap-inputs-through-wider-bridges) | +| [noise_upscale_3.sbs/noise_upscale_3](../assets/sbs/noise_upscale_3.sbs) | 2 | No | [Parity · 21 renders, 697,344 exact pixels](parity-fixes.md#sampling-integer-bitmap-inputs-through-wider-bridges) | +| [noise_voronoi.sbs/3d_voronoi](../assets/sbs/noise_voronoi.sbs) | 1 | No | [Parity · 174,080 exact pixels in 82 shared-lookup renders, bundled defaults differ](parity-fixes.md#shared-pixel-assignments-in-voronoi-color-selection) · [Saved graph comparisons](parity-fixes.md#package-ownership-of-saved-function-calls) · [Stock tables](parity-fixes.md#voronoi-distortion-and-shared-noise-inputs) | +| [noise_voronoi.sbs/3d_voronoi_fractal](../assets/sbs/noise_voronoi.sbs) | 1 | No | [Parity · 174,080 exact pixels in 82 shared-lookup renders, bundled defaults differ](parity-fixes.md#3d-fractal-voronoi-after-correcting-bitmap-lookup-reduction) · [Saved graph comparisons](parity-fixes.md#package-ownership-of-saved-function-calls) · [Stock tables](parity-fixes.md#voronoi-distortion-and-shared-noise-inputs) | +| [noise_voronoi.sbs/voronoi](../assets/sbs/noise_voronoi.sbs) | 0 | No | [Parity · 174,080 exact pixels in 82 shared-lookup renders, bundled defaults differ](parity-fixes.md#shared-pixel-assignments-in-voronoi-color-selection) · [Saved graph comparisons](parity-fixes.md#package-ownership-of-saved-function-calls) · [Stock tables](parity-fixes.md#voronoi-distortion-and-shared-noise-inputs) | +| [noise_voronoi.sbs/voronoi_fractal](../assets/sbs/noise_voronoi.sbs) | 0 | No | [Parity · 174,080 exact pixels in 82 shared-lookup renders, bundled defaults differ](parity-fixes.md#fractal-voronoi-roots-with-shared-lookup-tables) · [Saved graph comparisons](parity-fixes.md#package-ownership-of-saved-function-calls) · [Stock tables](parity-fixes.md#voronoi-distortion-and-shared-noise-inputs) | +| [non_square_transform.sbs/non_square_transform](../assets/sbs/non_square_transform.sbs) | 1 | No | [Parity · 204,032 exact pixels in 23 renders](parity-fixes.md#rotated-transforms-and-fractional-texture-coordinates) | +| [non_square_transform.sbs/non_square_transform_greyscale](../assets/sbs/non_square_transform.sbs) | 1 | No | [Parity · 204,032 exact pixels in 23 renders](parity-fixes.md#rotated-transforms-and-fractional-texture-coordinates) | +| [non_uniform_blur.sbs/non_uniform_blur_grayscale_sample](../assets/sbs/non_uniform_blur.sbs) | 2 | Yes | [Parity · 19 cases, 175,360 exact pixels](parity-fixes.md#directional-warp-orientation-and-input-precision) | +| [non_uniform_blur.sbs/non_uniform_blur_sample](../assets/sbs/non_uniform_blur.sbs) | 2 | Yes | [Parity · 19 cases, 175,360 exact pixels](parity-fixes.md#directional-warp-orientation-and-input-precision) | +| [non_uniform_rotation.sbs/non_uniform_rotation_color](../assets/sbs/non_uniform_rotation.sbs) | 3 | No | [Parity · 206,336 exact pixels in 26 renders](parity-fixes.md#segment-mapping-and-normal-graph-rechecks) | +| [non_uniform_rotation.sbs/non_uniform_rotation_grayscale](../assets/sbs/non_uniform_rotation.sbs) | 3 | No | [Parity · 171,264 exact pixels in 18 renders](parity-fixes.md#segment-mapping-and-normal-graph-rechecks) | | [normal_color.sbs/normal_color](../assets/sbs/normal_color.sbs) | 0 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [normal_intensity.sbs/normal_intensity](../assets/sbs/normal_intensity.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [normal_invert.sbs/normal_invert](../assets/sbs/normal_invert.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [normal_mapper.sbs/normal_mapper](../assets/sbs/normal_mapper.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [normal_normalise.sbs/normal_normalise](../assets/sbs/normal_normalise.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [normal_sobel.sbs/normal_sobel](../assets/sbs/normal_sobel.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [normal_sobel.sbs/normal_sobel_2](../assets/sbs/normal_sobel.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [normal_to_height_2.sbs/normal_to_height](../assets/sbs/normal_to_height_2.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [normal_to_height_hq.sbs/base_algorithm_height_distance](../assets/sbs/normal_to_height_hq.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [normal_transform.sbs/normal_transform](../assets/sbs/normal_transform.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [normal_normalise.sbs/normal_normalise](../assets/sbs/normal_normalise.sbs) | 1 | No | [Parity · 18 renders, all 171,264 pixels exact](parity-fixes.md#normal-maps-panoramas-and-primitive-shapes) | +| [normal_sobel.sbs/normal_sobel](../assets/sbs/normal_sobel.sbs) | 1 | Yes | [Parity · 27 renders, all 213,504 pixels exact](parity-fixes.md#sobel-normals-and-nadir-projection) · [Six nested cases, 2,304/2,304 after reopening](parity-fixes.md#output-precision-in-nested-generators-and-blurs) | +| [normal_sobel.sbs/normal_sobel_2](../assets/sbs/normal_sobel.sbs) | 1 | No | [Parity · 171,264 exact pixels in 18 renders](parity-fixes.md#segment-mapping-and-normal-graph-rechecks) | +| [normal_to_height_2.sbs/normal_to_height](../assets/sbs/normal_to_height_2.sbs) | 1 | No | [Parity · 18 renders, all 145,664 pixels exact](parity-fixes.md#global-blend-opacity-in-normal-to-height) | +| [normal_to_height_hq.sbs/base_algorithm_height_distance](../assets/sbs/normal_to_height_hq.sbs) | 1 | Yes | [Parity · 13 cases, 163,840 exact pixels](parity-fixes.md#height-distance-texture-mapping-skew-and-weave) | +| [normal_transform.sbs/normal_transform](../assets/sbs/normal_transform.sbs) | 1 | No | [Parity · 18 renders, all 171,264 pixels exact](parity-fixes.md#normal-maps-panoramas-and-primitive-shapes) | | [normal_uncombine.sbs/get_intensity_iteration](../assets/sbs/normal_uncombine.sbs) | 2 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [normal_vector_rotation.sbs/normal_vector_rotation](../assets/sbs/normal_vector_rotation.sbs) | 2 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [panorama_gradients.sbs/panorama_gradient_2_points](../assets/sbs/panorama_gradients.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [panorama_gradients.sbs/panorama_gradient_linear](../assets/sbs/panorama_gradients.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [panorama_nadir_extract.sbs/nadir_extract](../assets/sbs/panorama_nadir_extract.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [panorama_nadir_patch.sbs/panorama_nadir_patch](../assets/sbs/panorama_nadir_patch.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [panorama_physical_sun_sky.sbs/Impl/GetOneParam](../assets/sbs/panorama_physical_sun_sky.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [panorama_position.sbs/panorama_3d_position](../assets/sbs/panorama_position.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [panorama_rotation.sbs/panorama_rotation](../assets/sbs/panorama_rotation.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [panorama_shape.sbs/panorama_line_light](../assets/sbs/panorama_shape.sbs) | 3 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [panorama_shape.sbs/panorama_plane_light](../assets/sbs/panorama_shape.sbs) | 3 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [panorama_shape.sbs/panorama_shape](../assets/sbs/panorama_shape.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [panorama_shape.sbs/panorama_shape_2](../assets/sbs/panorama_shape.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [panorama_shape.sbs/panorama_sphere_light](../assets/sbs/panorama_shape.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [panorama_shape.sbs/panorama_spot](../assets/sbs/panorama_shape.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [panorama_straighten_horizon.sbs/panorama_straighten_horizon](../assets/sbs/panorama_straighten_horizon.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [paper_path.sbs/paper_path](../assets/sbs/paper_path.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [parquet_1.sbs/parquet_1](../assets/sbs/parquet_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [paths_tools.sbs/Impl/compute_paths_lengths](../assets/sbs/paths_tools.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [paths_tools.sbs/Impl/facets_to_paths_impl_link_template](../assets/sbs/paths_tools.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [paths_tools.sbs/Impl/facets_to_paths_impl_stitch_template](../assets/sbs/paths_tools.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [panorama_gradients.sbs/panorama_gradient_2_points](../assets/sbs/panorama_gradients.sbs) | 0 | No | [Parity · 19 renders, all 143,104 RGBA pixels exact](parity-fixes.md#scalar-products-used-by-sums-inside-a-called-function) | +| [panorama_gradients.sbs/panorama_gradient_linear](../assets/sbs/panorama_gradients.sbs) | 0 | No | [Parity · 19 renders, all 143,104 RGBA pixels exact](parity-fixes.md#scalar-products-used-by-sums-inside-a-called-function) | +| [panorama_nadir_extract.sbs/nadir_extract](../assets/sbs/panorama_nadir_extract.sbs) | 1 | No | [Parity · 18 renders, all 174,336 pixels exact](parity-fixes.md#sobel-normals-and-nadir-projection) | +| [panorama_nadir_patch.sbs/panorama_nadir_patch](../assets/sbs/panorama_nadir_patch.sbs) | 2 | No | [Parity · 282,880/282,880 pixels across 56 distinct settings](parity-fixes.md#pixel-subtraction-and-texture-coordinates-at-the-panorama-equator) | +| [panorama_physical_sun_sky.sbs/Impl/GetOneParam](../assets/sbs/panorama_physical_sun_sky.sbs) | 1 | Yes | [Parity · 25 exact float3 outputs](parity-fixes.md#color-temperature-range-reductions-sky-parameters-and-polygon-paths) | +| [panorama_position.sbs/panorama_3d_position](../assets/sbs/panorama_position.sbs) | 0 | No | [Parity · 2,304/2,304 original pixels and 2,304/2,304 after ordinary SBS reopening in the reference desktop](parity-fixes.md#ordinary-sbs-saves-with-verified-library-dependencies) · [Earlier measurements · 18 renders, all 171,264 pixels exact](parity-fixes.md#normal-maps-panoramas-and-primitive-shapes) | +| [panorama_rotation.sbs/panorama_rotation](../assets/sbs/panorama_rotation.sbs) | 1 | No | [Parity · 206,336 exact pixels in 26 renders](parity-fixes.md#segment-mapping-and-normal-graph-rechecks) | +| [panorama_shape.sbs/panorama_line_light](../assets/sbs/panorama_shape.sbs) | 3 | No | [Parity · 30 renders, all 241,152 pixels exact](parity-fixes.md#panoramic-line-light-and-horizon-across-the-seam) | +| [panorama_shape.sbs/panorama_plane_light](../assets/sbs/panorama_shape.sbs) | 3 | No | [Parity · 212,736/212,736 pixels at 32 settings, 41,472/41,472 after reopening](parity-fixes.md#packed-products-in-the-second-endpoint-of-a-pixel-interpolation) · [Earlier measurements](parity-fixes.md#nadir-patch-after-reopening-its-linked-shape-package) | +| [panorama_shape.sbs/panorama_shape](../assets/sbs/panorama_shape.sbs) | 1 | No | [Parity · six nested settings, 2,304/2,304 original pixels and 2,304/2,304 on ordinary SBS reopen](parity-fixes.md#float-vector-arguments-in-nested-functions) · [Earlier measurements · 18 renders, all 171,264 pixels exact](parity-fixes.md#normal-maps-panoramas-and-primitive-shapes) | +| [panorama_shape.sbs/panorama_shape_2](../assets/sbs/panorama_shape.sbs) | 2 | No | [Parity · six nested settings, 2,304/2,304 original pixels and 2,304/2,304 on ordinary SBS reopen](parity-fixes.md#float-vector-arguments-in-nested-functions) · [Earlier measurements · 18 renders, all 171,264 pixels exact](parity-fixes.md#normal-maps-panoramas-and-primitive-shapes) | +| [panorama_shape.sbs/panorama_sphere_light](../assets/sbs/panorama_shape.sbs) | 2 | No | [Parity · 171,264 exact pixels in 18 renders](parity-fixes.md#segment-mapping-and-normal-graph-rechecks) · [Six nested cases, 2,304/2,304 after reopening](parity-fixes.md#output-precision-in-nested-generators-and-blurs) | +| [panorama_shape.sbs/panorama_spot](../assets/sbs/panorama_shape.sbs) | 1 | Yes | [Parity · six nested settings, 2,304/2,304 original pixels and 2,304/2,304 on ordinary SBS reopen](parity-fixes.md#float-vector-arguments-in-nested-functions) · [Earlier measurements · 36 renders, all 189,696 RGBA pixels exact](parity-fixes.md#undefined-quotients-in-a-unit-interval-and-panorama-spot-lighting) | +| [panorama_straighten_horizon.sbs/panorama_straighten_horizon](../assets/sbs/panorama_straighten_horizon.sbs) | 1 | No | [Parity · 26 renders, all 212,480 pixels exact](parity-fixes.md#panoramic-line-light-and-horizon-across-the-seam) | +| [paper_path.sbs/paper_path](../assets/sbs/paper_path.sbs) | 0 | Yes | [Parity · 446,720/446,720 pixels across 45 distinct settings](parity-fixes.md#reopened-paper-fiber-gaussian-and-shape-generators) | +| [parquet_1.sbs/parquet_1](../assets/sbs/parquet_1.sbs) | 0 | Yes | [Parity · 25 renders, 289,024 exact pixels](parity-fixes.md#parquet-1-and-outstanding-inventory-controls) | +| [paths_tools.sbs/Impl/compute_paths_lengths](../assets/sbs/paths_tools.sbs) | 1 | Yes | [Parity · 39,990/39,990 pixels across 129 distinct settings](parity-fixes.md#repeating-increments-in-finite-path-length-loops) · [Earlier fixed-point and path-header measurements](parity-fixes.md#finite-loops-that-reach-a-fixed-point-in-path-length-graphs) | +| [paths_tools.sbs/Impl/facets_to_paths_impl_link_template](../assets/sbs/paths_tools.sbs) | 1 | Yes | [Parity · 18 renders, all 57,600 pixels exact](parity-fixes.md#marked-variable-reads-in-path-and-mipmap-graphs) | +| [paths_tools.sbs/Impl/facets_to_paths_impl_stitch_template](../assets/sbs/paths_tools.sbs) | 1 | Yes | [Parity · 18 renders, all 57,600 pixels exact](parity-fixes.md#marked-variable-reads-in-path-and-mipmap-graphs) | | [paths_tools.sbs/Impl/get_number_of_valid_paths](../assets/sbs/paths_tools.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [paths_tools.sbs/Impl/mask_to_facets](../assets/sbs/paths_tools.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [paths_tools.sbs/Impl/sort_by_blue](../assets/sbs/paths_tools.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [paths_tools.sbs/Impl/mask_to_facets](../assets/sbs/paths_tools.sbs) | 1 | Yes | [Parity · 17 cases, 52,736 exact pixels](parity-fixes.md#facet-masks-and-stripe-boundaries) | +| [paths_tools.sbs/Impl/sort_by_blue](../assets/sbs/paths_tools.sbs) | 1 | Yes | [Parity · 14 cases, 25,856 exact pixels](parity-fixes.md#skipped-loops-and-path-buffers) | | [paths_tools.sbs/Utils/RelativeToInputPP](../assets/sbs/paths_tools.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [paths_tools.sbs/paths_polygon](../assets/sbs/paths_tools.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [paths_tools.sbs/paths_trace](../assets/sbs/paths_tools.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [paths_tools.sbs/vertex_processor](../assets/sbs/paths_tools.sbs) | 9 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [paths_tools.sbs/vertex_processor_simple](../assets/sbs/paths_tools.sbs) | 5 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_alveolus.sbs/alveolus](../assets/sbs/pattern_alveolus.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_arc_pavement.sbs/arc_pavement](../assets/sbs/pattern_arc_pavement.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_brick_1.sbs/brick_1](../assets/sbs/pattern_brick_1.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_brick_2.sbs/brick_2](../assets/sbs/pattern_brick_2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_brick_generator.sbs/resources/Tile](../assets/sbs/pattern_brick_generator.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | +| [paths_tools.sbs/paths_polygon](../assets/sbs/paths_tools.sbs) | 0 | No | [Parity · 31 RGBA settings, 9,216 exact pixels on each processor count and 2,304 after reopening](parity-fixes.md#initial-branch-of-a-nested-pattern-iterator) · [Archived polygon buffers](parity-fixes.md#color-temperature-range-reductions-sky-parameters-and-polygon-paths) | +| [paths_tools.sbs/paths_trace](../assets/sbs/paths_tools.sbs) | 2 | No | [Parity · 31/31 settings and 73,984/73,984 pixels on each processor count, 9 exact saves](parity-fixes.md#paths-trace-with-rectangular-path-and-background-inputs) · [Earlier path settings](parity-fixes.md#paths-caustics-and-cell-fields-after-pattern-sampling) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) | +| [paths_tools.sbs/vertex_processor](../assets/sbs/paths_tools.sbs) | 9 | No | [Parity · 18 renders, all 57,600 pixels exact](parity-fixes.md#marked-variable-reads-in-path-and-mipmap-graphs) | +| [paths_tools.sbs/vertex_processor_simple](../assets/sbs/paths_tools.sbs) | 5 | No | [Parity · 18 renders, all 57,600 pixels exact](parity-fixes.md#marked-variable-reads-in-path-and-mipmap-graphs) | +| [pattern_alveolus.sbs/alveolus](../assets/sbs/pattern_alveolus.sbs) | 0 | No | [Parity · 884,992/884,992 pixels across 58 renders](parity-fixes.md#pixel-coordinates-for-whole-pixel-pattern-stamps) · [Single-stamp render-region comparisons](parity-fixes.md#pattern-coordinates-under-a-change-of-render-region) · [Gaussian disc-boundary sweeps](parity-fixes.md#gaussian-coverage-at-the-disc-boundary) · [262,144/262,144 pixels after isolating the generator](parity-fixes.md#alveolus-filters-after-the-first-differing-stage) · [Two-stamp reconstruction at eight sizes](parity-fixes.md#four-source-pixels-in-the-filled-alveolus-cells) | +| [pattern_arc_pavement.sbs/arc_pavement](../assets/sbs/pattern_arc_pavement.sbs) | 1 | No | [Parity · 791,296/791,296 pixels across 93 settings on one and eight processors and ordinary saves](parity-fixes.md#full-arc-pavement-comparisons-across-shape-selections-and-ordinary-saves) · [Earlier comparison · 319,717/320,256 pixels across 47 distinct settings](parity-fixes.md#isolated-arc-pavement-draws-in-a-nonunit-render-region) · [Earlier rotation measurements](parity-fixes.md#pattern-rotation-phase) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) | +| [pattern_brick_1.sbs/brick_1](../assets/sbs/pattern_brick_1.sbs) | 0 | No | [Parity · 96/96 settings and 1,237,248/1,237,248 pixels on each processor count, 47 exact saves](parity-fixes.md#brick-pattern-generators-across-square-and-rectangular-outputs) · [Earlier fractional-edge comparisons](parity-fixes.md#fractional-edges-of-axis-aligned-pattern-stamps) · [Earlier settings](parity-fixes.md#paper-brick-fiber-mesh-polygon-and-shape-roots) | +| [pattern_brick_2.sbs/brick_2](../assets/sbs/pattern_brick_2.sbs) | 0 | No | [Parity · 96/96 settings and 1,237,248/1,237,248 pixels on each processor count, 47 exact saves](parity-fixes.md#brick-pattern-generators-across-square-and-rectangular-outputs) · [Earlier fractional-edge comparisons](parity-fixes.md#fractional-edges-of-axis-aligned-pattern-stamps) · [Earlier settings](parity-fixes.md#paper-brick-fiber-mesh-polygon-and-shape-roots) | +| [pattern_brick_generator.sbs/resources/Tile](../assets/sbs/pattern_brick_generator.sbs) | 1 | Yes | [Parity · 347,136/347,136 pixels in 106 renders, 32 reopened settings](parity-fixes.md#projecting-stamp-vertices-through-shifted-render-regions) | | [pattern_checker_1.sbs/checker_1](../assets/sbs/pattern_checker_1.sbs) | 0 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [pattern_cube_3d.sbs/cube_3d](../assets/sbs/pattern_cube_3d.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_cube_3d.sbs/cube_3d_gbuffers](../assets/sbs/pattern_cube_3d.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_fibers_1.sbs/fibers_1](../assets/sbs/pattern_fibers_1.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_fibers_2.sbs/fibers_2](../assets/sbs/pattern_fibers_2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_gaussian_1.sbs/gaussian_1](../assets/sbs/pattern_gaussian_1.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_gaussian_2.sbs/gaussian_2](../assets/sbs/pattern_gaussian_2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_mesh_1.sbs/mesh_1](../assets/sbs/pattern_mesh_1.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_mesh_2.sbs/mesh_2](../assets/sbs/pattern_mesh_2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_polygon_2.sbs/polygon_2](../assets/sbs/pattern_polygon_2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_shape.sbs/hemisphere](../assets/sbs/pattern_shape.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_shape.sbs/shape_base](../assets/sbs/pattern_shape.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_splatter_circular.sbs/splatter_circular](../assets/sbs/pattern_splatter_circular.sbs) | 7 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_splatter_circular.sbs/splatter_circular_color](../assets/sbs/pattern_splatter_circular.sbs) | 7 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_stripes.sbs/stripes](../assets/sbs/pattern_stripes.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_tile_generator.sbs/tile_generator](../assets/sbs/pattern_tile_generator.sbs) | 7 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_tile_generator.sbs/tile_generator_color](../assets/sbs/pattern_tile_generator.sbs) | 7 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_tile_random.sbs/tile_random](../assets/sbs/pattern_tile_random.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_tile_random.sbs/tile_random_color](../assets/sbs/pattern_tile_random.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [pattern_cube_3d.sbs/cube_3d](../assets/sbs/pattern_cube_3d.sbs) | 0 | No | [Parity · 18 renders, all 171,264 pixels exact](parity-fixes.md#normal-maps-panoramas-and-primitive-shapes) | +| [pattern_cube_3d.sbs/cube_3d_gbuffers](../assets/sbs/pattern_cube_3d.sbs) | 0 | No | [Parity · 60 renders, all 685,056 pixels exact](parity-fixes.md#normal-maps-panoramas-and-primitive-shapes) | +| [pattern_fibers_1.sbs/fibers_1](../assets/sbs/pattern_fibers_1.sbs) | 0 | No | [Parity · 438,528/438,528 pixels across 36 settings on both processor counts and ordinary saves](parity-fixes.md#pattern-fibers-1-at-default-and-changed-tiling) · [Earlier comparison · 416,799/424,192 pixels across 24 renders](parity-fixes.md#pattern-rotation-phase) | +| [pattern_fibers_2.sbs/fibers_2](../assets/sbs/pattern_fibers_2.sbs) | 0 | No | [Parity · 446,720/446,720 pixels across 45 distinct settings](parity-fixes.md#reopened-paper-fiber-gaussian-and-shape-generators) | +| [pattern_gaussian_1.sbs/gaussian_1](../assets/sbs/pattern_gaussian_1.sbs) | 0 | No | [Parity · 360,704/360,704 pixels across 38 distinct settings](parity-fixes.md#reopened-gaussian-polygon-and-weave-pattern-generators) · [Earlier measurements](parity-fixes.md#radial-stamp-profiles-and-pattern-generators) | +| [pattern_gaussian_2.sbs/gaussian_2](../assets/sbs/pattern_gaussian_2.sbs) | 0 | No | [Parity · 475,392/475,392 pixels across 44 distinct settings](parity-fixes.md#reopened-paper-fiber-gaussian-and-shape-generators) | +| [pattern_mesh_1.sbs/mesh_1](../assets/sbs/pattern_mesh_1.sbs) | 0 | No | [Parity · 2,927,872/2,927,872 pixels across 59 distinct settings](parity-fixes.md#fixed-and-input-driven-rotation-bounds-for-oblique-stamps) | +| [pattern_mesh_2.sbs/mesh_2](../assets/sbs/pattern_mesh_2.sbs) | 0 | No | [Parity · 2,927,872/2,927,872 pixels across 59 distinct settings](parity-fixes.md#fixed-and-input-driven-rotation-bounds-for-oblique-stamps) | +| [pattern_polygon_2.sbs/polygon_2](../assets/sbs/pattern_polygon_2.sbs) | 0 | No | [Parity · 332,032/332,032 pixels across 39 distinct settings](parity-fixes.md#reopened-gaussian-polygon-and-weave-pattern-generators) · [Earlier measurements](parity-fixes.md#paper-brick-fiber-mesh-polygon-and-shape-roots) | +| [pattern_shape.sbs/hemisphere](../assets/sbs/pattern_shape.sbs) | 0 | No | [Parity · 25 settings, 173,568/173,568 original and reopened pixels exact](parity-fixes.md#graph-output-size-functions-and-signed-offsets) | +| [pattern_shape.sbs/shape_base](../assets/sbs/pattern_shape.sbs) | 0 | Yes | [Parity · 68 settings, 344,064/344,064 original and reopened pixels exact](parity-fixes.md#graph-output-size-functions-and-signed-offsets) | +| [pattern_splatter_circular.sbs/splatter_circular](../assets/sbs/pattern_splatter_circular.sbs) | 7 | No | [Parity · 216,064/216,064 pixels across 70 distinct settings on both processor counts and ordinary saves](parity-fixes.md#circular-pattern-angles-and-random-draws-with-computed-bounds) · [Earlier comparison · 179,684/186,368 exact pixels across 54 settings on both processor counts and ordinary saves](parity-fixes.md#circular-splatter-geometry-and-the-order-of-random-draws) · [Compile-time and public switch comparisons](parity-fixes.md#compile-time-conditions-before-a-shared-pattern-draw) · [Earlier comparison · 130,917/132,096 exact pixels in 9 renders](parity-fixes.md#other-roots-using-uniform-arc-tangents) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) | +| [pattern_splatter_circular.sbs/splatter_circular_color](../assets/sbs/pattern_splatter_circular.sbs) | 7 | No | [Parity · 216,064/216,064 pixels across 70 distinct settings on both processor counts and ordinary saves](parity-fixes.md#circular-pattern-angles-and-random-draws-with-computed-bounds) · [Earlier comparison · 175,089/186,368 exact pixels across 54 settings on both processor counts and ordinary saves](parity-fixes.md#circular-splatter-geometry-and-the-order-of-random-draws) · [Compile-time and public switch comparisons](parity-fixes.md#compile-time-conditions-before-a-shared-pattern-draw) · [Earlier comparison · 130,678/132,096 exact pixels in 9 renders](parity-fixes.md#other-roots-using-uniform-arc-tangents) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) | +| [pattern_stripes.sbs/stripes](../assets/sbs/pattern_stripes.sbs) | 0 | No | [Parity · 762,880/762,880 pixels across 83 distinct settings](parity-fixes.md#pixel-ratio-in-rectangular-directional-filters) | +| [pattern_tile_generator.sbs/tile_generator](../assets/sbs/pattern_tile_generator.sbs) | 7 | No | [Parity · 757,504/757,504 pixels across 221 distinct settings](parity-fixes.md#selected-blend-inputs-and-odd-sized-float-backgrounds-in-tile-generators) · [Previous bitmap-slot comparisons](parity-fixes.md#pattern-draw-order-for-fixed-and-runtime-image-slots) · [Previous storage and whole-root comparisons](parity-fixes.md#parameter-controlled-sizes-and-half-precision-pattern-backgrounds) · [Earlier whole-root comparison](parity-fixes.md#beveled-square-gradient-and-wave-stamps) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) · [conditional draws and returned channels](parity-fixes.md#shared-random-draws-in-pattern-branches-and-returned-color-channels) · [packed arguments and returned draws](parity-fixes.md#returned-channels-of-a-packed-argument-in-pattern-functions) | +| [pattern_tile_generator.sbs/tile_generator_color](../assets/sbs/pattern_tile_generator.sbs) | 7 | No | [Parity · 777,472/777,472 pixels across 339 settings on both processor counts and ordinary reopen](parity-fixes.md#component-reads-in-color-tile-function-arguments) · [Previous comparison · 634,737/765,184 pixels across 331 archived settings](parity-fixes.md#three-related-tile-roots-with-the-current-evaluator) · [Earlier comparison · 621,344/765,184 pixels across 331 distinct settings](parity-fixes.md#selected-blend-inputs-and-odd-sized-float-backgrounds-in-tile-generators) · [Previous bitmap-slot comparisons](parity-fixes.md#pattern-draw-order-for-fixed-and-runtime-image-slots) · [Previous storage and whole-root comparisons](parity-fixes.md#parameter-controlled-sizes-and-half-precision-pattern-backgrounds) · [Earlier whole-root comparison](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) · [conditional draws and returned channels](parity-fixes.md#shared-random-draws-in-pattern-branches-and-returned-color-channels) · [packed arguments and returned draws](parity-fixes.md#returned-channels-of-a-packed-argument-in-pattern-functions) | +| [pattern_tile_random.sbs/tile_random](../assets/sbs/pattern_tile_random.sbs) | 2 | No | [Parity · 425,216/425,216 pixels across 104 settings on both processor counts and ordinary reopen](parity-fixes.md#returned-vectors-in-pattern-properties) · [Previous comparison · 331,402/339,200 across 79 settings](parity-fixes.md#driven-seeds-in-pattern-nodes) · [Previous comparison · 300,698/316,672 in 52 established settings and 10,414/10,752 in 20 rectangular and square controls](parity-fixes.md#rectangular-expansion-in-the-two-random-tile-roots) · [Previous comparison · 300,698/316,672 pixels across 52 archived settings](parity-fixes.md#three-related-tile-roots-with-the-current-evaluator) · [Earlier comparison · 291,084/316,672 pixels across 52 distinct settings](parity-fixes.md#selected-blend-inputs-and-odd-sized-float-backgrounds-in-tile-generators) · [Previous bitmap-slot comparisons](parity-fixes.md#pattern-draw-order-for-fixed-and-runtime-image-slots) · [Previous storage and whole-root comparisons](parity-fixes.md#parameter-controlled-sizes-and-half-precision-pattern-backgrounds) · [Earlier whole-root comparison](parity-fixes.md#tile-random-image-and-soft-patterns) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) · [conditional draws and returned channels](parity-fixes.md#shared-random-draws-in-pattern-branches-and-returned-color-channels) · [packed arguments and returned draws](parity-fixes.md#returned-channels-of-a-packed-argument-in-pattern-functions) | +| [pattern_tile_random.sbs/tile_random_color](../assets/sbs/pattern_tile_random.sbs) | 2 | No | [Parity · 728,832/728,832 pixels across 179 settings on both processor counts and ordinary reopen](parity-fixes.md#returned-vectors-in-pattern-properties) · [Previous comparison · 635,800/642,816 across 154 settings](parity-fixes.md#driven-seeds-in-pattern-nodes) · [Previous comparison · 602,588/619,776 in 126 established settings and 10,414/10,752 in 20 rectangular and square controls](parity-fixes.md#rectangular-expansion-in-the-two-random-tile-roots) · [Previous comparison · 601,273/619,776 pixels across 126 archived settings](parity-fixes.md#three-related-tile-roots-with-the-current-evaluator) · [Earlier comparison · 498,989/619,776 pixels across 126 distinct settings](parity-fixes.md#selected-blend-inputs-and-odd-sized-float-backgrounds-in-tile-generators) · [Previous bitmap-slot comparisons](parity-fixes.md#pattern-draw-order-for-fixed-and-runtime-image-slots) · [Previous storage and whole-root comparisons](parity-fixes.md#parameter-controlled-sizes-and-half-precision-pattern-backgrounds) · [Earlier whole-root comparison](parity-fixes.md#signed-bitmap-blend-precision) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) · [conditional draws and returned channels](parity-fixes.md#shared-random-draws-in-pattern-branches-and-returned-color-channels) · [packed arguments and returned draws](parity-fixes.md#returned-channels-of-a-packed-argument-in-pattern-functions) | | [pattern_tile_random_2.sbs/functions/debug_find_cell](../assets/sbs/pattern_tile_random_2.sbs) | 0 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [pattern_tile_random_2.sbs/tile_random_2](../assets/sbs/pattern_tile_random_2.sbs) | 5 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_tile_sampler.sbs/arrow](../assets/sbs/pattern_tile_sampler.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_triangle_grid.sbs/triangle_grid_base](../assets/sbs/pattern_triangle_grid.sbs) | 3 | Yes | [Too hard: measurement timeout](parity-fixes.md#remaining-differences) | -| [pattern_weave_1.sbs/weave_1](../assets/sbs/pattern_weave_1.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pattern_weave_2.sbs/weave_2](../assets/sbs/pattern_weave_2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pavement_1.sbs/pavement_1](../assets/sbs/pavement_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [pattern_tile_random_2.sbs/tile_random_2](../assets/sbs/pattern_tile_random_2.sbs) | 5 | No | [Parity · 285,184 exact pixels in 38 renders](parity-fixes.md#shared-lookups-and-environment-shadow-pass) | +| [pattern_tile_sampler.sbs/arrow](../assets/sbs/pattern_tile_sampler.sbs) | 0 | Yes | [Parity · seven 512×512 runs, four formats](parity-fixes.md#transform-edges-and-floating-point-filtering) | +| [pattern_triangle_grid.sbs/triangle_grid_base](../assets/sbs/pattern_triangle_grid.sbs) | 3 | Yes | [Parity · 18 renders, all 171,264 pixels exact](parity-fixes.md#high-pass-anisotropic-noise-and-triangle-grid-controls) | +| [pattern_weave_1.sbs/weave_1](../assets/sbs/pattern_weave_1.sbs) | 0 | No | [Parity · 332,032/332,032 pixels across 39 distinct settings](parity-fixes.md#reopened-gaussian-polygon-and-weave-pattern-generators) · [Earlier measurements](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) | +| [pattern_weave_2.sbs/weave_2](../assets/sbs/pattern_weave_2.sbs) | 0 | No | [Parity · 3,139,840/3,139,840 pixels across 95 whole settings on both processor counts and ordinary saves](parity-fixes.md#full-pattern-weave-2-comparisons-at-both-processor-counts) · [Earlier comparison · 3,139,489/3,139,840 pixels across 95 distinct settings](parity-fixes.md#saved-splatter-and-weave-graphs-across-independent-fields) · [Earlier measurements](parity-fixes.md#fixed-and-input-driven-rotation-bounds-for-oblique-stamps) | +| [pavement_1.sbs/pavement_1](../assets/sbs/pavement_1.sbs) | 0 | Yes | [Parity · 2,927,872/2,927,872 pixels across 59 distinct settings](parity-fixes.md#fixed-and-input-driven-rotation-bounds-for-oblique-stamps) | | [pbr_albedo_safe_color.sbs/pbr_albedo_safe_color](../assets/sbs/pbr_albedo_safe_color.sbs) | 2 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [pbr_dielectric_F0.sbs/pbr_dielectric_F0](../assets/sbs/pbr_dielectric_F0.sbs) | 0 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | +| [pbr_dielectric_F0.sbs/pbr_dielectric_F0](../assets/sbs/pbr_dielectric_F0.sbs) | 0 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) · [Twelve settings and all selected outputs reopened](parity-fixes.md#rectangular-inputs-and-reopened-outputs-on-seven-roots) | | [pbr_metal_reflectance.sbs/pbr_metal_reflectance](../assets/sbs/pbr_metal_reflectance.sbs) | 0 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [pbr_render.sbs/PBR_render_mapping_color](../assets/sbs/pbr_render.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pbr_render.sbs/PBR_render_mapping_grayscale](../assets/sbs/pbr_render.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pbr_render.sbs/chroma_shift](../assets/sbs/pbr_render.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pbr_render.sbs/environment_map_rescale](../assets/sbs/pbr_render.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pbr_render.sbs/get_max_coords/get_max_coord](../assets/sbs/pbr_render.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pbr_render.sbs/ibl_specular_contrib_anisotropic/panoramic_lod](../assets/sbs/pbr_render.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pbr_render.sbs/position_to_normal](../assets/sbs/pbr_render.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pbr_render.sbs/raytrace_position](../assets/sbs/pbr_render.sbs) | 4 | Yes | [Too hard: cook timeout](parity-fixes.md#remaining-differences) | -| [pbr_render.sbs/raytraced_irradiance_pass_8](../assets/sbs/pbr_render.sbs) | 10 | Yes | [Too hard: cook timeout](parity-fixes.md#remaining-differences) | -| [pbr_render.sbs/raytraced_specular_pass_8](../assets/sbs/pbr_render.sbs) | 9 | Yes | [Too hard: cook timeout](parity-fixes.md#remaining-differences) | -| [pbr_render2.sbs/PBR_render_mapping_color](../assets/sbs/pbr_render2.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pbr_render2.sbs/PBR_render_mapping_grayscale](../assets/sbs/pbr_render2.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pbr_render2.sbs/chroma_shift](../assets/sbs/pbr_render2.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pbr_render2.sbs/environment_map_rescale](../assets/sbs/pbr_render2.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pbr_render2.sbs/get_max_coords/get_max_coord](../assets/sbs/pbr_render2.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [pbr_render.sbs/PBR_render_mapping_color](../assets/sbs/pbr_render.sbs) | 2 | Yes | [Parity · 13 cases, 163,840 exact pixels](parity-fixes.md#height-distance-texture-mapping-skew-and-weave) | +| [pbr_render.sbs/PBR_render_mapping_grayscale](../assets/sbs/pbr_render.sbs) | 2 | Yes | [Parity · 13 cases, 163,840 exact pixels](parity-fixes.md#height-distance-texture-mapping-skew-and-weave) | +| [pbr_render.sbs/chroma_shift](../assets/sbs/pbr_render.sbs) | 1 | Yes | [Parity · 13 cases, 163,840 exact pixels](parity-fixes.md#height-distance-texture-mapping-skew-and-weave) | +| [pbr_render.sbs/environment_map_rescale](../assets/sbs/pbr_render.sbs) | 1 | Yes | [Parity · 171,264 exact pixels in 18 renders](parity-fixes.md#centered-transform-resizing-and-untiled-edges) | +| [pbr_render.sbs/get_max_coords/get_max_coord](../assets/sbs/pbr_render.sbs) | 1 | Yes | [Parity · 12 typed coordinate comparisons](parity-fixes.md#value-processor-coordinates) | +| [pbr_render.sbs/ibl_specular_contrib_anisotropic/panoramic_lod](../assets/sbs/pbr_render.sbs) | 1 | Yes | [Parity · 18 cases, 186,624 exact pixels](parity-fixes.md#stored-precision-in-transform-mip-levels) | +| [pbr_render.sbs/position_to_normal](../assets/sbs/pbr_render.sbs) | 2 | Yes | [Parity · 30 renders, all 515,328 RGBA pixels exact](parity-fixes.md#position-to-normal-outputs-in-both-renderers) | +| [pbr_render.sbs/raytrace_position](../assets/sbs/pbr_render.sbs) | 4 | Yes | [Parity · 26 renders, all 142,340 RGBA pixels exact](parity-fixes.md#small-graph-parents-and-raytrace-positions) | +| [pbr_render.sbs/raytraced_irradiance_pass_8](../assets/sbs/pbr_render.sbs) | 10 | Yes | [Parity · 124,928/124,928 original pixels, 26/26 typed outputs, nine exact reopens](parity-fixes.md#whole-and-reopened-first-renderer-irradiance-pass) · [Scalar rotation measurements](parity-fixes.md#scalar-float-precision-in-nested-graph-instances) · [Rectangular input measurements](parity-fixes.md#rectangular-image-inputs-on-graph-instances) · [Default-index matrix](parity-fixes.md#eighth-irradiance-pass-with-default-and-connected-indices) · [Wired processor readouts](parity-fixes.md#whole-specular-outputs-and-wired-irradiance-stages) · [Stored product component and assignment-order controls](parity-fixes.md#component-reads-and-writes-across-pixel-function-calls) · [Earlier 26-setting matrix](parity-fixes.md#irradiance-with-a-connected-pass-index) · [First processor, 4,096/4,096 in both F16 and F32 across called ray steps](parity-fixes.md#assigned-ray-steps-inside-pixel-function-calls) · [Earlier first-processor comparison](parity-fixes.md#stored-products-in-pixel-expressions-and-irradiance-ray-steps) | +| [pbr_render.sbs/raytraced_specular_pass_8](../assets/sbs/pbr_render.sbs) | 9 | Yes | [Parity · 143,300/143,300 original and rectangular pixels, five exact SBS reopens and five exact environment controls](parity-fixes.md#whole-first-renderer-specular-pass-after-the-switch-correction) · [Selected Switch readouts](parity-fixes.md#switch-blend-with-parameter-driven-endpoint-opacity) · [Earlier whole outputs, 143,296/143,300 original and rectangular, 16,703/16,704 reopened](parity-fixes.md#whole-specular-outputs-and-wired-irradiance-stages) · [Switch precision measurements](parity-fixes.md#signed-zero-when-switch-blend-selects-a-floating-point-color-input) · [Earlier F16 comparisons](parity-fixes.md#eighth-raytraced-specular-passes) · [rectangular fields and saved packages](parity-fixes.md#rectangular-inputs-and-remaining-half-float-pixels-in-the-eighth-specular-passes) · [Environment controls and F32 boundary values](parity-fixes.md#environment-and-intermediate-precision-in-the-eighth-specular-passes) · [Reciprocal rounding and 128² recheck](parity-fixes.md#reciprocal-division-through-pixel-function-calls) | +| [pbr_render2.sbs/PBR_render_mapping_color](../assets/sbs/pbr_render2.sbs) | 2 | No | [Parity · 13 cases, 163,840 exact pixels](parity-fixes.md#height-distance-texture-mapping-skew-and-weave) | +| [pbr_render2.sbs/PBR_render_mapping_grayscale](../assets/sbs/pbr_render2.sbs) | 2 | No | [Parity · 13 cases, 163,840 exact pixels](parity-fixes.md#height-distance-texture-mapping-skew-and-weave) | +| [pbr_render2.sbs/chroma_shift](../assets/sbs/pbr_render2.sbs) | 1 | Yes | [Parity · 13 cases, 163,840 exact pixels](parity-fixes.md#height-distance-texture-mapping-skew-and-weave) | +| [pbr_render2.sbs/environment_map_rescale](../assets/sbs/pbr_render2.sbs) | 1 | Yes | [Parity · 171,264 exact pixels in 18 renders](parity-fixes.md#centered-transform-resizing-and-untiled-edges) | +| [pbr_render2.sbs/get_max_coords/get_max_coord](../assets/sbs/pbr_render2.sbs) | 1 | Yes | [Parity · 12 typed coordinate comparisons](parity-fixes.md#value-processor-coordinates) | | [pbr_render2.sbs/height_adjust](../assets/sbs/pbr_render2.sbs) | 3 | Yes | [Parity: 3 cases](parity-fixes.md#verified-cases) | -| [pbr_render2.sbs/ibl_specular_contrib_anisotropic/panoramic_lod](../assets/sbs/pbr_render2.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pbr_render2.sbs/lod](../assets/sbs/pbr_render2.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pbr_render2.sbs/position_to_normal](../assets/sbs/pbr_render2.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pbr_render2.sbs/raytrace_position](../assets/sbs/pbr_render2.sbs) | 4 | Yes | [Too hard: cook timeout](parity-fixes.md#remaining-differences) | -| [pbr_render2.sbs/raytraced_irradiance_is_pass_8](../assets/sbs/pbr_render2.sbs) | 9 | Yes | [Too hard: cook timeout](parity-fixes.md#remaining-differences) | -| [pbr_render2.sbs/raytraced_specular_pass_8](../assets/sbs/pbr_render2.sbs) | 9 | Yes | [Too hard: cook timeout](parity-fixes.md#remaining-differences) | +| [pbr_render2.sbs/ibl_specular_contrib_anisotropic/panoramic_lod](../assets/sbs/pbr_render2.sbs) | 1 | Yes | [Parity · 18 cases, 186,624 exact pixels](parity-fixes.md#large-transform-offsets-and-additive-blends) | +| [pbr_render2.sbs/lod](../assets/sbs/pbr_render2.sbs) | 1 | Yes | [Parity · 18 cases, 171,264 exact pixels](parity-fixes.md#stored-precision-in-transform-mip-levels) | +| [pbr_render2.sbs/position_to_normal](../assets/sbs/pbr_render2.sbs) | 2 | Yes | [Parity · 30 renders, all 515,328 RGBA pixels exact](parity-fixes.md#position-to-normal-outputs-in-both-renderers) | +| [pbr_render2.sbs/raytrace_position](../assets/sbs/pbr_render2.sbs) | 4 | Yes | [Parity · 26 renders, all 142,340 RGBA pixels exact](parity-fixes.md#small-graph-parents-and-raytrace-positions) | +| [pbr_render2.sbs/raytraced_irradiance_is_pass_8](../assets/sbs/pbr_render2.sbs) | 9 | Yes | [Parity · 18 renders, 136,704 exact RGBA pixels](parity-fixes.md#material-bundles-and-the-eighth-irradiance-pass) | +| [pbr_render2.sbs/raytraced_specular_pass_8](../assets/sbs/pbr_render2.sbs) | 9 | Yes | [Parity · 143,300/143,300 original pixels across 38 settings, five exact SBS reopens](parity-fixes.md#whole-and-reopened-eighth-specular-passes) · [rectangular fields and saved packages](parity-fixes.md#rectangular-inputs-and-remaining-half-float-pixels-in-the-eighth-specular-passes) · [Environment controls and F32 boundary values](parity-fixes.md#environment-and-intermediate-precision-in-the-eighth-specular-passes) · [Reciprocal rounding and 128² recheck](parity-fixes.md#reciprocal-division-through-pixel-function-calls) | | [pbr_render2.sbs/sat/sat_iteration](../assets/sbs/pbr_render2.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [pbr_render_ortho.sbs/blue_noise](../assets/sbs/pbr_render_ortho.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pbr_render_ortho.sbs/environment_map_rescale](../assets/sbs/pbr_render_ortho.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [pbr_render_ortho.sbs/blue_noise](../assets/sbs/pbr_render_ortho.sbs) | 0 | Yes | [Parity · 285,184 exact pixels in 38 renders](parity-fixes.md#shared-lookups-and-environment-shadow-pass) | +| [pbr_render_ortho.sbs/environment_map_rescale](../assets/sbs/pbr_render_ortho.sbs) | 1 | Yes | [Parity · 171,264 exact pixels in 18 renders](parity-fixes.md#centered-transform-resizing-and-untiled-edges) | | [pbr_render_ortho.sbs/get_max_coord](../assets/sbs/pbr_render_ortho.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [pbr_render_ortho.sbs/ibl_shadow_pass](../assets/sbs/pbr_render_ortho.sbs) | 3 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pbr_render_ortho.sbs/mipmap_generator](../assets/sbs/pbr_render_ortho.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pbr_render_ortho.sbs/rotate_environment](../assets/sbs/pbr_render_ortho.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [pbr_render_ortho.sbs/sphere_displace](../assets/sbs/pbr_render_ortho.sbs) | 1 | Yes | [Too hard: cook timeout](parity-fixes.md#remaining-differences) | -| [pbr_render_ortho.sbs/vector_shadow_pass](../assets/sbs/pbr_render_ortho.sbs) | 4 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [perlin_noise_zoom.sbs/perlin_noise_zoom](../assets/sbs/perlin_noise_zoom.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [pbr_render_ortho.sbs/ibl_shadow_pass](../assets/sbs/pbr_render_ortho.sbs) | 3 | Yes | [Parity · 151,040 exact pixels in 27 renders](parity-fixes.md#shared-lookups-and-environment-shadow-pass) | +| [pbr_render_ortho.sbs/mipmap_generator](../assets/sbs/pbr_render_ortho.sbs) | 1 | Yes | [Parity · 171,264 exact pixels in 18 renders](parity-fixes.md#centered-transform-resizing-and-untiled-edges) | +| [pbr_render_ortho.sbs/rotate_environment](../assets/sbs/pbr_render_ortho.sbs) | 1 | Yes | [Parity · 18 renders, all 171,264 RGBA pixels exact](parity-fixes.md#environment-rotation-and-wired-irradiance-samples) | +| [pbr_render_ortho.sbs/sphere_displace](../assets/sbs/pbr_render_ortho.sbs) | 1 | Yes | [Parity · 31/31 settings and 157,952/157,952 pixels on each processor count, 9 exact saves](parity-fixes.md#sphere-displacement-on-rectangular-height-fields) · [Earlier sphere comparisons](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) | +| [pbr_render_ortho.sbs/vector_shadow_pass](../assets/sbs/pbr_render_ortho.sbs) | 4 | Yes | [Parity · 28 cases, 211,456 exact pixels](parity-fixes.md#large-transform-offsets-and-additive-blends) | +| [perlin_noise_zoom.sbs/perlin_noise_zoom](../assets/sbs/perlin_noise_zoom.sbs) | 0 | Yes | [Parity · 332,032/332,032 pixels across 39 distinct settings](parity-fixes.md#reopened-perlin-scratches-shape-and-weave-generators) · [Earlier measurements](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) | | [pow.sbs/pow](../assets/sbs/pow.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [pow.sbs/pow_grayscale](../assets/sbs/pow.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [pre_multiply_straight.sbs/premult_to_straight](../assets/sbs/pre_multiply_straight.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [quad_transform.sbs/quad_transform](../assets/sbs/quad_transform.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [quad_transform.sbs/quad_transform_grayscale](../assets/sbs/quad_transform.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [pre_multiply_straight.sbs/premult_to_straight](../assets/sbs/pre_multiply_straight.sbs) | 1 | No | [Parity · 19 cases, 172,288 exact pixels](parity-fixes.md#large-transform-offsets-and-additive-blends) | +| [quad_transform.sbs/quad_transform](../assets/sbs/quad_transform.sbs) | 1 | No | [Parity · 204,032/204,032 pixels in 23 renders](parity-fixes.md#quad-swirl-trapezoid-and-vector-morph-comparisons) | +| [quad_transform.sbs/quad_transform_grayscale](../assets/sbs/quad_transform.sbs) | 1 | No | [Parity · 204,032/204,032 pixels in 23 renders](parity-fixes.md#quad-swirl-trapezoid-and-vector-morph-comparisons) | | [quantize.sbs/quantize](../assets/sbs/quantize.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [quantize.sbs/quantize_grayscale](../assets/sbs/quantize.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [quantize_2.sbs/quantize_grayscale](../assets/sbs/quantize_2.sbs) | 2 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | @@ -473,17 +676,17 @@ The first pass covers all **546 roots**: **166 Parity** and **380 Too hard**. Pa | [quantize_color.sbs/bitonic_sort/graph/initial_iteration](../assets/sbs/quantize_color.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [quantize_color.sbs/bitonic_sort/graph/remap_sorting](../assets/sbs/quantize_color.sbs) | 2 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [quantize_color.sbs/bitonic_sort/graph/remap_sorting_256x1](../assets/sbs/quantize_color.sbs) | 2 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [quantize_color.sbs/color_conversions/convert_Lab_to_RGB](../assets/sbs/quantize_color.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [quantize_color.sbs/color_conversions/convert_RGB_to_Lab](../assets/sbs/quantize_color.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [quantize_color.sbs/color_conversions/convert_Lab_to_RGB](../assets/sbs/quantize_color.sbs) | 1 | Yes | [Parity · 180,736 exact pixels, including after MaterialCraft Save As and external reopen](parity-fixes.md#vector-equality-lab-to-rgb-and-sbs-round-trips) | +| [quantize_color.sbs/color_conversions/convert_RGB_to_Lab](../assets/sbs/quantize_color.sbs) | 1 | Yes | [Parity · 29 renders, all 212,480 RGBA pixels exact](parity-fixes.md#literal-pixel-divisors-and-rgb-to-lab) | | [quantize_color.sbs/create_color_palette_16colors](../assets/sbs/quantize_color.sbs) | 2 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [quantize_color.sbs/get_min_max/GetMaxFromAlpha_v2](../assets/sbs/quantize_color.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [quantize_color.sbs/get_min_max/GetMaxFromAlpha_v2](../assets/sbs/quantize_color.sbs) | 1 | Yes | [Parity · 33 renders, all 36 output pixels exact](parity-fixes.md#alpha-maximum-and-one-texel-reductions) | | [quantize_color.sbs/get_min_max/GetMaxFromAlpha_v3](../assets/sbs/quantize_color.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [quantize_color.sbs/helpers/cdf_pass](../assets/sbs/quantize_color.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [quantize_color.sbs/kmeans_iteration](../assets/sbs/quantize_color.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [quantize_color.sbs/modify_color_palette_sub](../assets/sbs/quantize_color.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [quantize_color.sbs/kmeans_iteration](../assets/sbs/quantize_color.sbs) | 2 | Yes | [Parity · 33/33 settings and 135,168/135,168 RGBA pixels on each processor count, 10 exact saves](parity-fixes.md#weighted-color-accumulation-in-the-palette-iteration) · [Earlier stage measurements](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) | +| [quantize_color.sbs/modify_color_palette_sub](../assets/sbs/quantize_color.sbs) | 2 | Yes | [Parity · 15,104/15,104 palette entries across 59 distinct settings](parity-fixes.md#modifying-a-256-entry-color-palette) · [Earlier palette measurement](parity-fixes.md#height-distance-texture-mapping-skew-and-weave) | | [quantize_color.sbs/view_color_palette_sub](../assets/sbs/quantize_color.sbs) | 2 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [radial_blur.sbs/radial_blur_grayscale](../assets/sbs/radial_blur.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [replace_color.sbs/replace_color](../assets/sbs/replace_color.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [radial_blur.sbs/radial_blur_grayscale](../assets/sbs/radial_blur.sbs) | 1 | No | [Parity · 591,616/591,616 pixels across 80 distinct settings](parity-fixes.md#diagonal-mip-selection-on-rotated-rectangular-bitmaps) · [Earlier radial measurements](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) · [both isolated branches match in all six cases per shape](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) | +| [replace_color.sbs/replace_color](../assets/sbs/replace_color.sbs) | 1 | No | [Parity · 39/39 settings, 170,240/170,240 pixels on one processor, eight and ordinary reopen](parity-fixes.md#hue-rotation-and-saturation-in-replace-color) · [Previous comparison · 148,752/157,952 pixels across 31 settings](parity-fixes.md#hue-and-chroma-rounding-near-equal-rgb-channels) · [Earlier whole-root and direct color comparisons](parity-fixes.md#hue-saturation-lightness-and-replace-color) | | [rgb-a_merge.sbs/rgb-a_merge](../assets/sbs/rgb-a_merge.sbs) | 2 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [rgb-a_split.sbs/rgb-a_split](../assets/sbs/rgb-a_split.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [rgba_merge.sbs/rgba_merge](../assets/sbs/rgba_merge.sbs) | 4 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | @@ -492,98 +695,98 @@ The first pass covers all **546 roots**: **166 Parity** and **380 Too hard**. Pa | [rt_ao_v2.sbs/mip_max_step](../assets/sbs/rt_ao_v2.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [rt_bent_normal.sbs/pp_template/pp_template_64c](../assets/sbs/rt_bent_normal.sbs) | 3 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [rt_bent_normal_v2.sbs/mip_max_step](../assets/sbs/rt_bent_normal_v2.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [rt_caustics.sbs/rt_caustics_base](../assets/sbs/rt_caustics.sbs) | 3 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [rt_irradiance.sbs/compute_irradiance](../assets/sbs/rt_irradiance.sbs) | 5 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [rt_irradiance.sbs/compute_ray_direction](../assets/sbs/rt_irradiance.sbs) | 4 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [rt_irradiance.sbs/debug_hit_uv](../assets/sbs/rt_irradiance.sbs) | 3 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [rt_irradiance.sbs/mip_max](../assets/sbs/rt_irradiance.sbs) | 1 | Yes | [Too hard: output size differs](parity-fixes.md#remaining-differences) | -| [rt_irradiance.sbs/panoramic_lod](../assets/sbs/rt_irradiance.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [rt_caustics.sbs/rt_caustics_base](../assets/sbs/rt_caustics.sbs) | 3 | Yes | [In progress · 167,462/172,288 across 19 established settings, four ordinary saves compared](parity-fixes.md#whole-caustic-scratch-splatter-tile-and-vertical-noise-comparisons) · [Earlier comparison · 152,777/172,288 pixels in 19 renders](parity-fixes.md#paths-caustics-and-cell-fields-after-pattern-sampling) | +| [rt_irradiance.sbs/compute_irradiance](../assets/sbs/rt_irradiance.sbs) | 5 | Yes | [Parity · 32 renders, all 217,088 RGBA pixels exact](parity-fixes.md#environment-rotation-and-wired-irradiance-samples) | +| [rt_irradiance.sbs/compute_ray_direction](../assets/sbs/rt_irradiance.sbs) | 4 | Yes | [Parity · 32 renders, all 217,088 RGBA pixels exact](parity-fixes.md#environment-rotation-and-wired-irradiance-samples) | +| [rt_irradiance.sbs/debug_hit_uv](../assets/sbs/rt_irradiance.sbs) | 3 | Yes | [Parity · 677,376/677,376 pixels across 346 distinct settings](parity-fixes.md#caller-texture-precision-in-typed-reads-and-the-uv-debug-marker) | +| [rt_irradiance.sbs/mip_max](../assets/sbs/rt_irradiance.sbs) | 1 | Yes | [Parity · 167,168 exact pixels in 17 cases](parity-fixes.md#pixel-processor-canvas-and-mip-maxima) | +| [rt_irradiance.sbs/panoramic_lod](../assets/sbs/rt_irradiance.sbs) | 1 | Yes | [Parity · 18 cases, 186,624 exact pixels](parity-fixes.md#large-transform-offsets-and-additive-blends) | | [rt_irradiance.sbs/template/pp_template](../assets/sbs/rt_irradiance.sbs) | 3 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [rt_shadows.sbs/mip_max](../assets/sbs/rt_shadows.sbs) | 1 | Yes | [Too hard: output size differs](parity-fixes.md#remaining-differences) | +| [rt_shadows.sbs/mip_max](../assets/sbs/rt_shadows.sbs) | 1 | Yes | [Parity · 167,168 exact pixels in 17 cases](parity-fixes.md#pixel-processor-canvas-and-mip-maxima) | | [rt_shadows.sbs/template/pp_template](../assets/sbs/rt_shadows.sbs) | 4 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [rt_shadows_v2.sbs/mip_max_step](../assets/sbs/rt_shadows_v2.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [safe_transform.sbs/safe_transform](../assets/sbs/safe_transform.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [safe_transform.sbs/safe_transform_grayscale](../assets/sbs/safe_transform.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [scratches_1.sbs/scratches_1](../assets/sbs/scratches_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [scratches_2.sbs/scratches_2](../assets/sbs/scratches_2.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [scratches_4.sbs/scratches_4](../assets/sbs/scratches_4.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [shape.sbs/shape_base](../assets/sbs/shape.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [shape_mapper.sbs/shape_mapper](../assets/sbs/shape_mapper.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [safe_transform.sbs/safe_transform](../assets/sbs/safe_transform.sbs) | 1 | No | [Parity · 171,264 exact pixels in 18 renders](parity-fixes.md#rotated-transforms-and-fractional-texture-coordinates) | +| [safe_transform.sbs/safe_transform_grayscale](../assets/sbs/safe_transform.sbs) | 1 | No | [Parity · 171,264 exact pixels in 18 renders](parity-fixes.md#rotated-transforms-and-fractional-texture-coordinates) | +| [scratches_1.sbs/scratches_1](../assets/sbs/scratches_1.sbs) | 0 | Yes | [Parity · 332,032/332,032 pixels across 39 distinct settings](parity-fixes.md#reopened-perlin-scratches-shape-and-weave-generators) · [Earlier measurements](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) | +| [scratches_2.sbs/scratches_2](../assets/sbs/scratches_2.sbs) | 0 | Yes | [In progress · 27/27 exact on one processor, 13/27 on eight and 27/27 on ordinary reopen](parity-fixes.md#scratches-2-across-all-established-settings-and-two-new-rectangles) · [Earlier comparison · 118,291/142,592 whole pixels, first differing stages measured](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) | +| [scratches_4.sbs/scratches_4](../assets/sbs/scratches_4.sbs) | 0 | Yes | [Parity · 315,648/315,648 pixels across 38 distinct settings](parity-fixes.md#reopened-perlin-scratches-shape-and-weave-generators) · [Earlier measurements](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) | +| [shape.sbs/shape_base](../assets/sbs/shape.sbs) | 0 | Yes | [Parity · 332,032/332,032 pixels across 39 distinct settings](parity-fixes.md#reopened-perlin-scratches-shape-and-weave-generators) · [Earlier saved-branch measurements](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) | +| [shape_mapper.sbs/shape_mapper](../assets/sbs/shape_mapper.sbs) | 1 | No | [Parity · 310,784/310,784 pixels](parity-fixes.md#wired-spline-helpers-and-shape-mapping) | | [shape_splatter.sbs/min_max](../assets/sbs/shape_splatter.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [shape_splatter.sbs/shape_splatter_blend](../assets/sbs/shape_splatter.sbs) | 12 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [shape_splatter.sbs/shape_splatter_blend_color](../assets/sbs/shape_splatter.sbs) | 12 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [shape_splatter.sbs/shape_splatter_data_extract](../assets/sbs/shape_splatter.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [shape_splatter.sbs/shape_splatter_to_mask](../assets/sbs/shape_splatter.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | +| [shape_splatter.sbs/shape_splatter_blend](../assets/sbs/shape_splatter.sbs) | 12 | No | [Parity · 18 renders, 171,264 exact pixels](parity-fixes.md#per-pixel-random-initialization) | +| [shape_splatter.sbs/shape_splatter_blend_color](../assets/sbs/shape_splatter.sbs) | 12 | No | [Parity · 23 renders, 204,032 exact pixels](parity-fixes.md#per-pixel-random-initialization) | +| [shape_splatter.sbs/shape_splatter_data_extract](../assets/sbs/shape_splatter.sbs) | 2 | No | [Parity · 19 cases on seven outputs, 1,206,016 exact pixels](parity-fixes.md#large-transform-offsets-and-additive-blends) | +| [shape_splatter.sbs/shape_splatter_to_mask](../assets/sbs/shape_splatter.sbs) | 1 | No | [Parity · 4 renders, 114,688 exact pixels](parity-fixes.md#per-pixel-random-initialization) | | [shape_splatter_v2.sbs/bitonic_sort/graph/bitonic_sort_iteration](../assets/sbs/shape_splatter_v2.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [shape_splatter_v2.sbs/bitonic_sort/graph/initial_iteration](../assets/sbs/shape_splatter_v2.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [shape_splatter_v2.sbs/bitonic_sort/graph/remap_sorting](../assets/sbs/shape_splatter_v2.sbs) | 2 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [shape_splatter_v2.sbs/grid_to_scanline](../assets/sbs/shape_splatter_v2.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [shape_splatter_v2.sbs/mipmap_tools/Mipmap_N_from_O_color](../assets/sbs/shape_splatter_v2.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [shape_splatter_v2.sbs/mipmap_tools/Mipmap_N_from_O_color](../assets/sbs/shape_splatter_v2.sbs) | 1 | Yes | [Parity · 18 renders, all 287,232 pixels exact](parity-fixes.md#marked-variable-reads-in-path-and-mipmap-graphs) | | [shape_splatter_v2.sbs/poisson_disc/poisson_disc_iteration](../assets/sbs/shape_splatter_v2.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [shape_splatter_v2.sbs/scanline_to_z_order](../assets/sbs/shape_splatter_v2.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [shape_splatter_v2.sbs/shape_splatter_compute_normal](../assets/sbs/shape_splatter_v2.sbs) | 10 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [shape_splatter_v2.sbs/shape_splatter_compute_normal](../assets/sbs/shape_splatter_v2.sbs) | 10 | Yes | [Parity · 292,864/292,864 pixels in 144 whole renders across four formats](parity-fixes.md#component-rounding-in-the-shape-splatter-normal) | | [shape_splatter_v2_companion.sbs/shape_splatter_to_mask](../assets/sbs/shape_splatter_v2_companion.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [skew.sbs/skew](../assets/sbs/skew.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [skew.sbs/skew_grayscale](../assets/sbs/skew.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [slope_blur.sbs/slope_blur](../assets/sbs/slope_blur.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [slope_blur.sbs/slope_blur_grayscale](../assets/sbs/slope_blur.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [slope_blur.sbs/slope_blur_grayscale_2](../assets/sbs/slope_blur.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [smart_auto_tile.sbs/pattern_find_edges_step](../assets/sbs/smart_auto_tile.sbs) | 4 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [splatter.sbs/splatter](../assets/sbs/splatter.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [splatter_circular.sbs/splatter_circular](../assets/sbs/splatter_circular.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [splatter_circular.sbs/splatter_circular_color](../assets/sbs/splatter_circular.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [splatter_color.sbs/splatter_color](../assets/sbs/splatter_color.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [skew.sbs/skew](../assets/sbs/skew.sbs) | 1 | No | [Parity · 13 cases, 163,840 exact pixels](parity-fixes.md#height-distance-texture-mapping-skew-and-weave) | +| [skew.sbs/skew_grayscale](../assets/sbs/skew.sbs) | 1 | No | [Parity · 13 cases, 163,840 exact pixels](parity-fixes.md#height-distance-texture-mapping-skew-and-weave) | +| [slope_blur.sbs/slope_blur](../assets/sbs/slope_blur.sbs) | 2 | No | [Parity · 18 renders, 145,664 exact pixels](parity-fixes.md#gradient-warp-displacement-and-sampling) | +| [slope_blur.sbs/slope_blur_grayscale](../assets/sbs/slope_blur.sbs) | 2 | Yes | [Parity · 18 renders, 145,664 exact pixels](parity-fixes.md#gradient-warp-displacement-and-sampling) | +| [slope_blur.sbs/slope_blur_grayscale_2](../assets/sbs/slope_blur.sbs) | 2 | No | [Parity · 18 renders, 145,664 exact pixels](parity-fixes.md#gradient-warp-displacement-and-sampling) | +| [smart_auto_tile.sbs/pattern_find_edges_step](../assets/sbs/smart_auto_tile.sbs) | 4 | Yes | [Parity · 16 cases, 3,185,920 exact pixels](parity-fixes.md#tile-edge-masks-and-normalized-spline-distances) | +| [splatter.sbs/splatter](../assets/sbs/splatter.sbs) | 1 | No | [Parity · 403,712/403,712 pixels across 93 distinct settings](parity-fixes.md#automatic-filtering-after-resizing-a-bound-bitmap) · [Earlier field comparisons](parity-fixes.md#saved-splatter-and-weave-graphs-across-independent-fields) · [Earlier measurements](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) · [471 bitmap controls across eight output types](parity-fixes.md#recheck-of-471-bitmap-sampling-and-placement-groups) | +| [splatter_circular.sbs/splatter_circular](../assets/sbs/splatter_circular.sbs) | 2 | Yes | [Parity · 62 whole settings, 190,720/190,720 pixels on one and eight processors and on ordinary reopen](parity-fixes.md#grayscale-splatter-circular-across-four-output-formats) · [Earlier comparison · 139,334/142,592 across 19 established settings, four ordinary saves compared](parity-fixes.md#whole-caustic-scratch-splatter-tile-and-vertical-noise-comparisons) · [Earlier comparison · 139,297/142,592 whole pixels, first differing stages measured](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) | +| [splatter_circular.sbs/splatter_circular_color](../assets/sbs/splatter_circular.sbs) | 2 | Yes | [Parity · 62 whole settings, 190,720/190,720 pixels on one and eight processors and on ordinary reopen](parity-fixes.md#splatter-circular-color-and-assignments-before-a-later-function-call) · [Earlier comparison · 17/35 exact on both processor counts and ordinary reopen](parity-fixes.md#grayscale-splatter-circular-across-four-output-formats) · [Earlier comparison · 140,218/142,592 across 19 established settings, four ordinary saves compared](parity-fixes.md#whole-caustic-scratch-splatter-tile-and-vertical-noise-comparisons) · [Earlier comparison · 140,218/142,592 whole pixels, first differing stages measured](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) | +| [splatter_color.sbs/splatter_color](../assets/sbs/splatter_color.sbs) | 2 | No | [Parity · 354,560/354,560 pixels across 55 distinct settings](parity-fixes.md#saved-splatter-and-weave-graphs-across-independent-fields) · [Earlier measurements](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) · [471 bitmap controls across eight output types](parity-fixes.md#recheck-of-471-bitmap-sampling-and-placement-groups) | | [spline_tools.sbs/-----WIP-----/circular_array_wip](../assets/sbs/spline_tools.sbs) | 2 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [spline_tools.sbs/-----WIP-----/displace_spline_by_spline_wip](../assets/sbs/spline_tools.sbs) | 4 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [spline_tools.sbs/internal_tools/2dtransform_spline_sub](../assets/sbs/spline_tools.sbs) | 3 | Yes | [Too hard: value-input case not verified](parity-fixes.md#remaining-differences) | +| [spline_tools.sbs/internal_tools/2dtransform_spline_sub](../assets/sbs/spline_tools.sbs) | 3 | Yes | [Parity · 87,570/87,570 pixels and values](parity-fixes.md#wired-spline-helpers-and-shape-mapping) | | [spline_tools.sbs/internal_tools/append_splines_sub](../assets/sbs/spline_tools.sbs) | 6 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [spline_tools.sbs/internal_tools/compute_bridge_distance](../assets/sbs/spline_tools.sbs) | 3 | Yes | [Too hard: value-input case not verified](parity-fixes.md#remaining-differences) | +| [spline_tools.sbs/internal_tools/compute_bridge_distance](../assets/sbs/spline_tools.sbs) | 3 | Yes | [Parity · 54,528/54,528 pixels](parity-fixes.md#wired-spline-helpers-and-shape-mapping) | | [spline_tools.sbs/internal_tools/compute_spline_distance_iteration](../assets/sbs/spline_tools.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [spline_tools.sbs/internal_tools/compute_spline_length_init](../assets/sbs/spline_tools.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [spline_tools.sbs/internal_tools/compute_spline_tangents](../assets/sbs/spline_tools.sbs) | 3 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [spline_tools.sbs/internal_tools/compute_spline_length_init](../assets/sbs/spline_tools.sbs) | 2 | Yes | [Parity · 43,776/43,776 pixels](parity-fixes.md#wired-spline-helpers-and-shape-mapping) | +| [spline_tools.sbs/internal_tools/compute_spline_tangents](../assets/sbs/spline_tools.sbs) | 3 | Yes | [Parity · 43,776 exact pixels in 27 renders](parity-fixes.md#clamped-texture-reads-in-spline-graphs) | | [spline_tools.sbs/internal_tools/get_spline_point_data](../assets/sbs/spline_tools.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [spline_tools.sbs/internal_tools/modify_spline_property_sub](../assets/sbs/spline_tools.sbs) | 4 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [spline_tools.sbs/internal_tools/normalize_spline_distance](../assets/sbs/spline_tools.sbs) | 1 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [spline_tools.sbs/internal_tools/points_preview](../assets/sbs/spline_tools.sbs) | 3 | Yes | [Too hard: value-input case not verified](parity-fixes.md#remaining-differences) | -| [spline_tools.sbs/internal_tools/resample_spline_data](../assets/sbs/spline_tools.sbs) | 3 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [spline_tools.sbs/internal_tools/scatter_splines_on_splines_preprocess](../assets/sbs/spline_tools.sbs) | 5 | Yes | [Too hard: value-input case not verified](parity-fixes.md#remaining-differences) | -| [spline_tools.sbs/internal_tools/select_spline_sub](../assets/sbs/spline_tools.sbs) | 3 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [spline_tools.sbs/internal_tools/spline_warp_sub](../assets/sbs/spline_tools.sbs) | 6 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [spot_emboss.sbs/spot_emboss](../assets/sbs/spot_emboss.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [starburst.sbs/starburst](../assets/sbs/starburst.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [stripes.sbs/stripes](../assets/sbs/stripes.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [spline_tools.sbs/internal_tools/modify_spline_property_sub](../assets/sbs/spline_tools.sbs) | 4 | Yes | [Parity · 28,928 exact pixels in 19 renders](parity-fixes.md#clamped-texture-reads-in-spline-graphs) | +| [spline_tools.sbs/internal_tools/normalize_spline_distance](../assets/sbs/spline_tools.sbs) | 1 | Yes | [Parity · 16 cases, 52,480 exact pixels](parity-fixes.md#tile-edge-masks-and-normalized-spline-distances) | +| [spline_tools.sbs/internal_tools/points_preview](../assets/sbs/spline_tools.sbs) | 3 | Yes | [In progress · 26,880/26,880 with two matched fonts, 14,592/14,592 on direct reopen with compatible dependencies, older loose links still fail](parity-fixes.md#overlapping-glyphs-and-points-preview-file-handoff) · [25,088/25,088 empty and point-only pixels](parity-fixes.md#font-line-height-and-coverage-over-a-constant-background) · [Five linked files saved in place, 17,920/17,920 and 2,048/2,048 direct](parity-fixes.md#saving-older-linked-packages-at-their-existing-paths) · [2,048/2,048 on each file and catalog selection](parity-fixes.md#points-preview-graph-links-after-switching-the-configured-library) · [Open file and catalog callers follow saved edits and undo, 2,048/2,048 pixels](parity-fixes.md#saving-a-catalog-dependency-while-its-callers-stay-open) | +| [spline_tools.sbs/internal_tools/resample_spline_data](../assets/sbs/spline_tools.sbs) | 3 | Yes | [Parity · 29,952 exact pixels in 19 renders](parity-fixes.md#clamped-texture-reads-in-spline-graphs) | +| [spline_tools.sbs/internal_tools/scatter_splines_on_splines_preprocess](../assets/sbs/spline_tools.sbs) | 5 | Yes | [Parity · 622,592/622,592 pixels and 16/16 counts, both full-library saves exact](parity-fixes.md#spline-preprocessing-with-empty-inputs-and-complete-library-saves) · [Four output formats](parity-fixes.md#spline-preprocessing-with-wired-counts) | +| [spline_tools.sbs/internal_tools/select_spline_sub](../assets/sbs/spline_tools.sbs) | 3 | Yes | [Parity · 622,592 exact pixels in 19 renders](parity-fixes.md#clamped-texture-reads-in-spline-graphs) | +| [spline_tools.sbs/internal_tools/spline_warp_sub](../assets/sbs/spline_tools.sbs) | 6 | Yes | [Parity · 28,928 exact pixels in 19 renders](parity-fixes.md#clamped-texture-reads-in-spline-graphs) | +| [spot_emboss.sbs/spot_emboss](../assets/sbs/spot_emboss.sbs) | 2 | No | [Parity · 218,368 exact cook pixels and six exact saved-file renders](parity-fixes.md#image-selection-in-saved-pattern-graphs) · [Twelve settings and all selected outputs reopened](parity-fixes.md#rectangular-inputs-and-reopened-outputs-on-seven-roots) | +| [starburst.sbs/starburst](../assets/sbs/starburst.sbs) | 0 | No | [Parity · 284,416/284,416 pixels across 55 distinct settings](parity-fixes.md#reopened-starburst-symmetry-tile-and-waveform-graphs) · [Earlier measurements](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) · [Saved graph seed and output-format checks](parity-fixes.md#graph-random-seed-inheritance-on-save-and-in-nested-graphs) | +| [stripes.sbs/stripes](../assets/sbs/stripes.sbs) | 0 | Yes | [Parity · 635,904/635,904 pixels across 53 distinct settings](parity-fixes.md#pixel-ratio-in-rectangular-directional-filters) | | [summed_area_table.sbs/summed_area_table_iteration](../assets/sbs/summed_area_table.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [summed_area_table_2.sbs/summed_area_table_iteration](../assets/sbs/summed_area_table_2.sbs) | 1 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [swirl.sbs/swirl](../assets/sbs/swirl.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [swirl.sbs/swirl_grayscale](../assets/sbs/swirl.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [swirl.sbs/swirl](../assets/sbs/swirl.sbs) | 1 | No | [Parity · 171,264/171,264 pixels in 18 renders](parity-fixes.md#quad-swirl-trapezoid-and-vector-morph-comparisons) | +| [swirl.sbs/swirl_grayscale](../assets/sbs/swirl.sbs) | 1 | No | [Parity · 171,264/171,264 pixels in 18 renders](parity-fixes.md#quad-swirl-trapezoid-and-vector-morph-comparisons) | | [symmetry.sbs/symmetry](../assets/sbs/symmetry.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [symmetry_slice.sbs/symmetry_slice](../assets/sbs/symmetry_slice.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [symmetry_slice.sbs/symmetry_slice](../assets/sbs/symmetry_slice.sbs) | 1 | No | [Parity · 313,088/313,088 pixels across 54 distinct settings](parity-fixes.md#reopened-starburst-symmetry-tile-and-waveform-graphs) · [Earlier measurements](parity-fixes.md#plane-light-splatter-symmetry-and-waveform-comparisons) | | [templates.sbs/Templates/Standard_Materials/Extended_Material](../assets/sbs/templates.sbs) | 0 | Yes | [Parity: 3 cases](parity-fixes.md#verified-cases) | | [templates.sbs/Templates/Standard_Materials/Simple_Material](../assets/sbs/templates.sbs) | 0 | Yes | [Parity: 3 cases](parity-fixes.md#verified-cases) | | [threshold.sbs/threshold](../assets/sbs/threshold.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [tile_generator.sbs/tile_generator](../assets/sbs/tile_generator.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [tile_generator_color.sbs/tile_generator_color](../assets/sbs/tile_generator_color.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [tile_random.sbs/tile_random](../assets/sbs/tile_random.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [tile_random.sbs/tile_random_color](../assets/sbs/tile_random.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [tile_sampler.sbs/arrow](../assets/sbs/tile_sampler.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [tileable_material_to_mesh_material.sbs/tileable_material_to_mesh_material](../assets/sbs/tileable_material_to_mesh_material.sbs) | 5 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [trapezoid_transform.sbs/trapezoid_transform](../assets/sbs/trapezoid_transform.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [trapezoid_transform.sbs/trapezoid_transform_grayscale](../assets/sbs/trapezoid_transform.sbs) | 1 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [uv_mapper.sbs/uv_mapper_color_sub](../assets/sbs/uv_mapper.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [uv_mapper.sbs/uv_mapper_grayscale_sub](../assets/sbs/uv_mapper.sbs) | 2 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [tile_generator.sbs/tile_generator](../assets/sbs/tile_generator.sbs) | 2 | Yes | [Parity · 284,416/284,416 across 55 settings and 81,920/81,920 in the 24 new settings, including reopen](parity-fixes.md#selected-channels-in-pattern-expressions) · [Earlier measurements](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) · [Bricks 01 tile and noise stages](parity-fixes.md#tile-luminance-variation-in-bricks-01) | +| [tile_generator_color.sbs/tile_generator_color](../assets/sbs/tile_generator_color.sbs) | 2 | Yes | [Parity · 284,416/284,416 pixels across 55 distinct settings](parity-fixes.md#reopened-starburst-symmetry-tile-and-waveform-graphs) · [Earlier measurements](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) | +| [tile_random.sbs/tile_random](../assets/sbs/tile_random.sbs) | 2 | Yes | [Parity · 277,760/277,760 grayscale pixels in 145 settings with live edits, fresh inputs and ordinary reopen](parity-fixes.md#live-preview-sampling-in-tile-random) · [Independent filtering at two stamps sharing one image](parity-fixes.md#filtering-after-independent-edits-to-stamps-sharing-an-image) · [Previous comparison · 111,207/142,592 pixels across 19 settings on both processor counts and ordinary reopen](parity-fixes.md#returned-vectors-in-pattern-properties) · [Previous comparison · 111,364/142,592 across 19 established settings, four ordinary saves compared](parity-fixes.md#whole-caustic-scratch-splatter-tile-and-vertical-noise-comparisons) · [Earlier comparison · 111,364/142,592 whole pixels, first differing stages measured](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) · [saved authored and disc branches each match 4,864/4,864](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) · [Seed offsets on the initial iterator branch](parity-fixes.md#the-incoming-seed-on-the-initial-branch-of-an-iterate) | +| [tile_random.sbs/tile_random_color](../assets/sbs/tile_random.sbs) | 2 | Yes | [Parity · 207,104/207,104 color pixels in 76 settings with live edits, fresh inputs and ordinary reopen](parity-fixes.md#live-preview-sampling-in-tile-random) · [Independent filtering at two stamps sharing one image](parity-fixes.md#filtering-after-independent-edits-to-stamps-sharing-an-image) · [Previous comparison · 111,194/142,592 pixels across 19 settings on both processor counts and ordinary reopen](parity-fixes.md#returned-vectors-in-pattern-properties) · [Previous comparison · 111,228/142,592 across 19 established settings, four ordinary saves compared](parity-fixes.md#whole-caustic-scratch-splatter-tile-and-vertical-noise-comparisons) · [Earlier comparison · 111,228/142,592 whole pixels, first differing stages measured](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) · [saved authored and disc branches each match 4,864/4,864](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) · [Seed offsets on the initial iterator branch](parity-fixes.md#the-incoming-seed-on-the-initial-branch-of-an-iterate) | +| [tile_sampler.sbs/arrow](../assets/sbs/tile_sampler.sbs) | 0 | Yes | [Parity · seven 512×512 runs, four formats](parity-fixes.md#transform-edges-and-floating-point-filtering) | +| [tileable_material_to_mesh_material.sbs/tileable_material_to_mesh_material](../assets/sbs/tileable_material_to_mesh_material.sbs) | 5 | No | [Parity · both outputs, 358,912 exact pixels in 42 renders](parity-fixes.md#diffuse-and-specular-outputs-of-the-mesh-material-graph) | +| [trapezoid_transform.sbs/trapezoid_transform](../assets/sbs/trapezoid_transform.sbs) | 1 | No | [Parity · 848,384 exact pixels in 68 renders across four formats](parity-fixes.md#trapezoid-coordinates-under-fixed-clipping) | +| [trapezoid_transform.sbs/trapezoid_transform_grayscale](../assets/sbs/trapezoid_transform.sbs) | 1 | No | [Parity · 848,384 exact pixels in 68 renders across four formats](parity-fixes.md#trapezoid-coordinates-under-fixed-clipping) | +| [uv_mapper.sbs/uv_mapper_color_sub](../assets/sbs/uv_mapper.sbs) | 2 | Yes | [Parity · 13 cases, 163,840 exact pixels](parity-fixes.md#height-distance-texture-mapping-skew-and-weave) | +| [uv_mapper.sbs/uv_mapper_grayscale_sub](../assets/sbs/uv_mapper.sbs) | 2 | Yes | [Parity · 13 cases, 163,840 exact pixels](parity-fixes.md#height-distance-texture-mapping-skew-and-weave) | | [value_get_size.sbs/get_size_color](../assets/sbs/value_get_size.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | | [value_get_size.sbs/get_size_grayscale](../assets/sbs/value_get_size.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) | -| [vector_morph.sbs/vector_morph](../assets/sbs/vector_morph.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [vector_morph.sbs/vector_morph_grayscale](../assets/sbs/vector_morph.sbs) | 2 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [vertical_noise.sbs/vertical_noise](../assets/sbs/vertical_noise.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [waveform_01_v2.sbs/waveform_01_v2](../assets/sbs/waveform_01_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [waveform_1.sbs/waveform_1](../assets/sbs/waveform_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [weave_1.sbs/weave_1](../assets/sbs/weave_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [weave_2.sbs/weave_2](../assets/sbs/weave_2.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [weave_3.sbs/weave_3](../assets/sbs/weave_3.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [weave_4.sbs/weave_4](../assets/sbs/weave_4.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [white_noise.sbs/white_noise](../assets/sbs/white_noise.sbs) | 0 | Yes | [Parity: 3 cases](parity-fixes.md#verified-cases) | -| [white_noise.sbs/white_noise_fast](../assets/sbs/white_noise.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [white_noise_v2.sbs/white_noise_v2](../assets/sbs/white_noise_v2.sbs) | 0 | No | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [wood_fibers_1.sbs/wood_fibers_1](../assets/sbs/wood_fibers_1.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | -| [wood_fibers_2.sbs/wood_fibers_2](../assets/sbs/wood_fibers_2.sbs) | 0 | Yes | [Too hard: remaining pixel differences](parity-fixes.md#remaining-differences) | +| [vector_morph.sbs/vector_morph](../assets/sbs/vector_morph.sbs) | 2 | No | [Parity · 171,264/171,264 pixels in 18 renders](parity-fixes.md#quad-swirl-trapezoid-and-vector-morph-comparisons) | +| [vector_morph.sbs/vector_morph_grayscale](../assets/sbs/vector_morph.sbs) | 2 | No | [Parity · 171,264/171,264 pixels in 18 renders](parity-fixes.md#quad-swirl-trapezoid-and-vector-morph-comparisons) | +| [vertical_noise.sbs/vertical_noise](../assets/sbs/vertical_noise.sbs) | 0 | Yes | [In progress · 142,295/142,592 across 19 established settings, four ordinary saves compared](parity-fixes.md#whole-caustic-scratch-splatter-tile-and-vertical-noise-comparisons) · [Earlier comparison · 142,088/142,592 whole pixels, first differing stages measured](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) · [Bricks 01 tile and noise stages](parity-fixes.md#tile-luminance-variation-in-bricks-01) | +| [waveform_01_v2.sbs/waveform_01_v2](../assets/sbs/waveform_01_v2.sbs) | 0 | No | [In progress · 313,088/313,088 originals, 179,968/179,968 reopens from a library path](parity-fixes.md#portable-function-links-when-opening-a-library-graph-from-disk) · [Function-link controls](parity-fixes.md#waveform-v2-with-library-and-file-based-hash-functions) · [Older relative hash dependency, 167,194/179,968](parity-fixes.md#reopened-starburst-symmetry-tile-and-waveform-graphs) · [Earlier measurements](parity-fixes.md#plane-light-splatter-symmetry-and-waveform-comparisons) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) · [179,968/179,968 with the updated dependency header](parity-fixes.md#version-of-a-detached-function-package-and-waveform-reopening) · [Unused and invoked file controls](parity-fixes.md#unused-and-unavailable-relative-functions) · [Portable SBS copy with detached functions, 179,968/179,968](parity-fixes.md#reopening-a-portable-copy-with-detached-function-packages) · [Relative function file saved in place, 179,968/179,968 and 8,448/8,448 direct](parity-fixes.md#saving-older-linked-packages-at-their-existing-paths) · [Linked function edit and undo with callers open, 8,448/8,448 per state](parity-fixes.md#editing-the-linked-function-with-a-waveform-caller-open) · [Catalog and relative links saved inside the library, 8,448/8,448 under each library selection](parity-fixes.md#keeping-catalog-links-when-saving-a-caller-inside-its-library) · [Open file and catalog callers follow saved edits and undo, 8,448/8,448 pixels](parity-fixes.md#saving-a-catalog-dependency-while-its-callers-stay-open) | +| [waveform_1.sbs/waveform_1](../assets/sbs/waveform_1.sbs) | 0 | Yes | [Parity · 313,088/313,088 pixels across 54 distinct settings](parity-fixes.md#reopened-starburst-symmetry-tile-and-waveform-graphs) · [Earlier measurements](parity-fixes.md#plane-light-splatter-symmetry-and-waveform-comparisons) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) | +| [weave_1.sbs/weave_1](../assets/sbs/weave_1.sbs) | 0 | Yes | [Parity · 332,032/332,032 pixels across 39 distinct settings](parity-fixes.md#reopened-perlin-scratches-shape-and-weave-generators) · [Earlier measurements](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) | +| [weave_2.sbs/weave_2](../assets/sbs/weave_2.sbs) | 0 | Yes | [Parity · 3,139,840/3,139,840 pixels across 95 distinct settings](parity-fixes.md#saved-splatter-and-weave-graphs-across-independent-fields) · [Earlier measurements](parity-fixes.md#fixed-and-input-driven-rotation-bounds-for-oblique-stamps) | +| [weave_3.sbs/weave_3](../assets/sbs/weave_3.sbs) | 0 | Yes | [Parity · 13 cases, 163,840 exact pixels](parity-fixes.md#height-distance-texture-mapping-skew-and-weave) | +| [weave_4.sbs/weave_4](../assets/sbs/weave_4.sbs) | 0 | Yes | [Parity · 360,704/360,704 pixels across 38 distinct settings](parity-fixes.md#reopened-perlin-scratches-shape-and-weave-generators) · [Earlier measurements](parity-fixes.md#plane-light-splatter-symmetry-and-waveform-comparisons) | +| [white_noise.sbs/white_noise](../assets/sbs/white_noise.sbs) | 0 | Yes | [Parity · 13 renders, 254,208 exact pixels](parity-fixes.md#stored-grayscale-stops-and-scalar-levels-controls) | +| [white_noise.sbs/white_noise_fast](../assets/sbs/white_noise.sbs) | 0 | Yes | [Parity · 18 renders, 127,488 exact pixels](parity-fixes.md#per-pixel-random-initialization) | +| [white_noise_v2.sbs/white_noise_v2](../assets/sbs/white_noise_v2.sbs) | 0 | No | [Parity · 76 renders, 183,808 exact pixels](parity-fixes.md#conditional-pixel-draws-and-white-noise-v2) | +| [wood_fibers_1.sbs/wood_fibers_1](../assets/sbs/wood_fibers_1.sbs) | 0 | Yes | [In progress · 331,421/332,032 pixels across 39 distinct settings](parity-fixes.md#repeated-wood-fiber-renders-and-isolated-drawing-depths) · [Earlier stage measurements](parity-fixes.md#tile-weave-splatter-and-fiber-stage-comparisons) | +| [wood_fibers_2.sbs/wood_fibers_2](../assets/sbs/wood_fibers_2.sbs) | 0 | Yes | [In progress · 18/18 established outputs now render, 65,381/65,536 archived U16 pixels at 256 × 256](parity-fixes.md#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) · [Earlier comparison · 17/18 whole renders completed, 55,649/60,672 exact pixels](parity-fixes.md#discarding-pattern-stamps-that-miss-every-output-sample) · [216 isolated stamp comparisons](parity-fixes.md#individual-wood-fibers-2-stamps) | diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 48518bf8..cb53dba9 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -43,9 +43,8 @@ automation + tests), weighted by how much of the day each area carries. **Remain | Platforms | 4 | 50% | Windows, macOS, Linux, FreeBSD and web builds compile; browser file I/O; packaging scripts and release workflows | First release run | | **Total** | **100** | **≈ 69%** | | | -Beyond the reference app: every edit is a command available through MCP, the CLI and the app's -control channel (including synthetic mouse and keyboard input), the engine runs headless with the -same results, and everything compiles to WebAssembly. +MaterialCraft exposes every edit as a command through its MCP server, CLI and control channel, +including synthetic mouse and keyboard input. The same engine runs headless and compiles to WebAssembly. ## Method