mirror of
https://github.com/storytold/materialcraft.git
synced 2026-11-29 01:23:53 +01:00
Preserve material defaults, input interpretation and instance caps
This commit is contained in:
1 parent
d7caf47065
commit
eab6bc703b
9 files changed
+94
-9
No files matched your search
+9
-1
@@ -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
|
||||
|
||||
@@ -435,6 +435,23 @@ 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};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use craft_texture::Image;
|
||||
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};
|
||||
|
||||
@@ -48,15 +49,21 @@ 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 bytes = read(path)?;
|
||||
let image = materialcraft_formats::decode(&bytes, linear)?;
|
||||
let image = materialcraft_formats::decode_with_color_space(&bytes, space)?;
|
||||
if image.integer_sampling()
|
||||
&& let Some(format) = materialcraft_core::png_sample_format(&bytes)
|
||||
{
|
||||
|
||||
@@ -278,8 +278,8 @@ pub(crate) fn cook_node(
|
||||
&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()),
|
||||
// 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),
|
||||
));
|
||||
|
||||
@@ -2,6 +2,42 @@ use materialcraft_core::{FunctionGraph, Graph, OutputFormat, Package, ParameterI
|
||||
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");
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -335,7 +335,10 @@ impl<'text> SbsReader<'text, '_> {
|
||||
continue;
|
||||
}
|
||||
|
||||
let default = exposed_default(code, child_element(input, "defaultValue").and_then(sbs_constant).as_ref());
|
||||
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(
|
||||
|
||||
@@ -241,6 +241,11 @@ impl SbsWriter {
|
||||
);
|
||||
if let Some(current) = graph.inputs.get(&exposed.id).and_then(constant_xml) {
|
||||
let _ = write!(out, "<materialcraftValue>{current}</materialcraftValue>");
|
||||
// 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, "<materialcraftDefault>{authored}</materialcraftDefault>");
|
||||
}
|
||||
}
|
||||
super::parameter_widget::write(out, exposed);
|
||||
let _ = write!(out, "{group}</paraminput>");
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user