mirror of
https://github.com/storytold/materialcraft.git
synced 2026-11-27 16:49:28 +01:00
Resolve runtime pattern image indices across disconnected sockets
This commit is contained in:
1 parent
67da2d0b8b
commit
eb85b90cce
4 files changed
+46
-18
No files matched your search
@@ -33,6 +33,8 @@ pub(crate) fn cook(context: &CookContext) -> CookResult {
|
||||
}
|
||||
}
|
||||
|
||||
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 });
|
||||
@@ -105,12 +107,16 @@ pub(crate) fn cook(context: &CookContext) -> CookResult {
|
||||
visit.center = [visit.center[0] + offset[0], visit.center[1] + offset[1]];
|
||||
let mut pattern = integer("patterntype");
|
||||
if pattern == 1 || (256..256 + crate::MAX_IMAGE_INPUTS as i32).contains(&pattern) {
|
||||
// Zero uses the slot encoded in the pattern. The generic image pattern starts at slot zero.
|
||||
pattern = match integer("imageindex") {
|
||||
0 => pattern.max(256),
|
||||
index if index > 0 => index.saturating_add(256),
|
||||
_ => 0,
|
||||
let requested = integer("imageindex");
|
||||
let slot = if functions.get(&(node.id, "imageindex")).is_some_and(|program| !program.output_is_literal()) {
|
||||
// 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 {
|
||||
// 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 })
|
||||
};
|
||||
pattern = slot.map_or(0, |i| i.saturating_add(256));
|
||||
}
|
||||
if pattern != 0 {
|
||||
let offset = vector("frameoffset");
|
||||
|
||||
@@ -449,23 +449,37 @@ fn patterns_reject_cycles_and_bound_exponential_traversal() {
|
||||
fn image_selectors_use_zero_based_slots_and_override_packed_patterns() {
|
||||
use craft_texture::{Image, Kind};
|
||||
|
||||
let inputs = [None, Some(Image::filled(4, 4, Kind::Gray, [0.25; 4])), Some(Image::filled(4, 4, Kind::Gray, [0.75; 4]))];
|
||||
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, expected) in [
|
||||
(1, None, 0.25),
|
||||
(1, Some(0), 0.25),
|
||||
(1, Some(1), 0.75),
|
||||
(1, Some(2), 0.0),
|
||||
(256, Some(1), 0.75),
|
||||
(257, None, 0.75),
|
||||
(258, Some(1), 0.75),
|
||||
(257, Some(-1), 0.0),
|
||||
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 {
|
||||
node.parameters.insert("imageindex".into(), Value::Int(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))]));
|
||||
@@ -479,7 +493,7 @@ fn image_selectors_use_zero_based_slots_and_override_packed_patterns() {
|
||||
inputs: &inputs,
|
||||
params: ¶meters,
|
||||
resource: &|_| None,
|
||||
vars: &BTreeMap::new(),
|
||||
vars: &vars,
|
||||
};
|
||||
let image = (definition.cook)(&context).unwrap().remove(0);
|
||||
assert_eq!(image.get(2, 2, false)[0], expected, "pattern {pattern}, slot {slot:?}");
|
||||
|
||||
@@ -1806,6 +1806,14 @@ These measurements follow the [uniform arc-tangent correction](#uniform-arc-tang
|
||||
|
||||
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.
|
||||
|
||||
@@ -405,7 +405,7 @@ The first pass covered all **546 roots**, with **166 Parity** and **380 Too hard
|
||||
| [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 | [In progress · 202,429/211,200 cook pixels and 24 exact saved-file renders](parity-fixes.md#image-selection-in-saved-pattern-graphs) |
|
||||
| [pattern_arc_pavement.sbs/arc_pavement](../assets/sbs/pattern_arc_pavement.sbs) | 1 | No | [In progress · 202,429/211,200 cook pixels, 24 exact saved-file renders, runtime socket probes](parity-fixes.md#runtime-selection-across-disconnected-image-sockets) |
|
||||
| [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) |
|
||||
|
||||
Reference in new issue
Block a user