diff --git a/crates/nodes/src/function/compile.rs b/crates/nodes/src/function/compile.rs index 1a8219a..dd121b3 100644 --- a/crates/nodes/src/function/compile.rs +++ b/crates/nodes/src/function/compile.rs @@ -146,7 +146,14 @@ fn compile_nested(graph: &FunctionGraph, seed: u32, depth: usize, remaining: &mu 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()); diff --git a/crates/nodes/src/function/tests.rs b/crates/nodes/src/function/tests.rs index 81af7ca..d311b22 100644 --- a/crates/nodes/src/function/tests.rs +++ b/crates/nodes/src/function/tests.rs @@ -25,6 +25,27 @@ fn operation(name: &str, arguments: &[Value], setting: Option) -> Result< evaluate(&graph, &BTreeMap::new()) } +#[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) } diff --git a/docs/parity-fixes.md b/docs/parity-fixes.md index b551156..df0fb8f 100644 --- a/docs/parity-fixes.md +++ b/docs/parity-fixes.md @@ -253,6 +253,35 @@ Literal-only pixel graphs at 16², seed 23, give 512/768 exact pixels for each l 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. + ### High-pass, anisotropic noise and triangle-grid controls | Root | Renders | Exact pixels / compared | Maximum error | diff --git a/docs/sbs-root-nodes.md b/docs/sbs-root-nodes.md index 4630696..3dec75e 100644 --- a/docs/sbs-root-nodes.md +++ b/docs/sbs-root-nodes.md @@ -35,7 +35,7 @@ A graph may accept input pins and still be a root under the dependency criterion Statuses: **Not checked**, **In progress**, **Parity** (exact pixels or typed values for the linked measured cases), or **Too hard** (reason recorded). Function calls do not count as regular graph dependencies. -The first pass covered all **546 roots**, with **166 Parity** and **380 Too hard**. The current inventory has **290 Parity**, **37 In progress** and **219 Too hard**. The November 17 and 18 comparisons include raw counts, output formats and remaining differences. [November 17 measurements](parity-fixes.md#2026-11-17-root-comparisons) · [November 18 measurements](parity-fixes.md#2026-11-18-root-comparisons) +The first pass covered all **546 roots**, with **166 Parity** and **380 Too hard**. The current inventory has **295 Parity**, **37 In progress** and **214 Too hard**. The November 17 and 18 comparisons include raw counts, output formats and remaining differences. [November 17 measurements](parity-fixes.md#2026-11-17-root-comparisons) · [November 18 measurements](parity-fixes.md#2026-11-18-root-comparisons) [Grayscale sampler measurements](parity-fixes.md#grayscale-sampling-of-color-inputs) · [Value sampling across 240 typed comparisons](parity-fixes.md#value-processor-texture-filtering) @@ -394,16 +394,16 @@ The first pass covered all **546 roots**, with **166 Parity** and **380 Too hard | [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 | [In progress · 1,029 exact pixels, intermediate lengths reach the execution limit](parity-fixes.md#skipped-loops-and-path-buffers) | -| [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) | +| [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 | [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 | [Parity · 19 polygon buffers, 5,120 exact pixels](parity-fixes.md#color-temperature-range-reductions-sky-parameters-and-polygon-paths) | | [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) | +| [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 | [In progress · 170,440/171,264 pixels across 18 renders](parity-fixes.md#radial-stamp-profiles-and-pattern-generators) | | [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) | @@ -528,7 +528,7 @@ The first pass covered all **546 roots**, with **166 Parity** and **380 Too hard | [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) |