mirror of
https://github.com/storytold/materialcraft.git
synced 2026-11-28 17:19:17 +01:00
Keep the stored property when a direct input link is missing
This commit is contained in:
1 parent
0a19145aed
commit
9d3de5fda6
6 files changed
+76
-3
No files matched your search
@@ -43,7 +43,7 @@ pub(crate) fn resolve_parameters(
|
||||
("fx_map", "background", _) if matches!(current, Value::Float4(_)) => ChannelMode::Broadcast,
|
||||
_ => ChannelMode::Opaque,
|
||||
};
|
||||
let (value, _) = crate::parameter_function::evaluate(function, expected, variables.to_mut(), base.seed, base.size, channels)
|
||||
let (value, _) = crate::parameter_function::evaluate(function, expected, variables.to_mut(), base.seed, base.size, channels, Some(current))
|
||||
.map_err(|error| format!("function of `{parameter}`: {error}"))?;
|
||||
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);
|
||||
@@ -58,3 +58,43 @@ pub(crate) fn resolve_parameters(
|
||||
|
||||
Ok(parameters)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{Cache, Options, cook};
|
||||
use materialcraft_core::{FunctionGraph, Graph, Package, Value, ValueType};
|
||||
use std::sync::Mutex;
|
||||
|
||||
#[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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,19 @@ pub(crate) fn evaluate(
|
||||
seed: u32,
|
||||
size: [u32; 2],
|
||||
channels: ChannelMode,
|
||||
fallback: Option<&Value>,
|
||||
) -> Result<(Value, bool), String> {
|
||||
let program = compile(function, seed)?;
|
||||
let widened = expected == ValueType::Float4 && [ValueType::Float as u32, ValueType::Float3 as u32].contains(&program.output_type());
|
||||
if program.output_type() != expected as u32 && !widened {
|
||||
return Err(format!("output must be {}", expected.label()));
|
||||
}
|
||||
// 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(), false));
|
||||
}
|
||||
|
||||
let context = EvaluationContext {
|
||||
image_formats: &[],
|
||||
|
||||
@@ -133,6 +133,7 @@ pub(crate) fn evaluate(
|
||||
resolved.seed,
|
||||
size,
|
||||
crate::parameter_function::ChannelMode::Opaque,
|
||||
None,
|
||||
)
|
||||
.map_err(|error| format!("function of `{}`: {error}", parameter.identifier()))?;
|
||||
if parameter == BaseParameter::OutputSize {
|
||||
|
||||
@@ -15,6 +15,15 @@ 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)
|
||||
|
||||
@@ -693,6 +693,22 @@ For shape mapper, the five earlier comparison sizes and four-format inputs are l
|
||||
|
||||
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.
|
||||
|
||||
### 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.
|
||||
|
||||
@@ -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 **310 Parity**, **45 In progress** and **191 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 **311 Parity**, **45 In progress** and **190 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)
|
||||
|
||||
@@ -147,7 +147,7 @@ The first pass covered all **546 roots**, with **166 Parity** and **380 Too hard
|
||||
| [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_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) |
|
||||
|
||||
Reference in new issue
Block a user