mirror of
https://github.com/storytold/materialcraft.git
synced 2026-11-28 17:19:17 +01:00
Inherit pattern dimensions and precision from the background
This commit is contained in:
1 parent
e451dad109
commit
0cb32afbeb
8 files changed
+72
-12
No files matched your search
@@ -310,7 +310,7 @@ pub(crate) fn cook_node(
|
||||
let started_ms = now_ms();
|
||||
let mut output_bases: Option<Arc<[_]>> = None;
|
||||
let result: Result<Vec<NodeOutput>, 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)
|
||||
|
||||
@@ -33,7 +33,7 @@ impl<'a> PreparedGraph<'a> {
|
||||
pub fn input_base(&self, id: NodeId, cooked: &crate::Cooked) -> Option<crate::ResolvedBaseParameters> {
|
||||
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
|
||||
|
||||
@@ -1837,10 +1837,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, port) in [("pixel_processor", "input0"), ("svg", "background"), ("fx_map", "background")] {
|
||||
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];
|
||||
@@ -1864,9 +1904,9 @@ fn enabled_generators_use_parent_size_and_seed_with_input_image_properties() {
|
||||
}
|
||||
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);
|
||||
}
|
||||
@@ -1881,8 +1921,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]);
|
||||
@@ -1892,7 +1932,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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -11,6 +11,8 @@ pub struct NodeDefinition {
|
||||
pub inputs: Vec<PortDefinition>,
|
||||
/// 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<PortDefinition>,
|
||||
pub params: Vec<ParameterDefinition>,
|
||||
/// A generator takes its size from the graph, not from an input
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -59,6 +59,18 @@ The first pass classifies all 546 roots: 166 Parity and 380 Too hard. These meas
|
||||
|
||||
## 2026-11-27 root comparisons
|
||||
|
||||
### 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.
|
||||
|
||||
### 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.
|
||||
|
||||
@@ -45,7 +45,7 @@ At least **50 of the 52 open roots** have two different reference outputs for th
|
||||
|
||||
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. Eight downstream FX-Map outputs still differ in dimensions. [Reproduction and counts](parity-fixes.md#input-relative-dimensions-on-a-child-image-bridge)
|
||||
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)
|
||||
|
||||
|
||||
Reference in new issue
Block a user