mirror of
https://github.com/storytold/materialcraft.git
synced 2026-11-28 17:19:17 +01:00
Bind floored modulo in seeded drawing expressions
This commit is contained in:
1 parent
ad620075a1
commit
ca77a03786
4 files changed
+56
-3
No files matched your search
@@ -202,8 +202,8 @@ impl<'a> Builder<'a, '_> {
|
||||
self.fixed(self.variables.get(name)?)?
|
||||
}
|
||||
}
|
||||
"add" | "sub" | "mul" | "mulscalar" | "div" | "dot" | "rand" | "neg" | "sqrt" | "sin" | "cos" | "vector2" | "cartesian" | "min" | "max"
|
||||
| "lerp" => {
|
||||
"add" | "sub" | "mul" | "mulscalar" | "div" | "mod" | "dot" | "rand" | "neg" | "sqrt" | "sin" | "cos" | "vector2" | "cartesian" | "min"
|
||||
| "max" | "lerp" => {
|
||||
if op.inputs.len() > 3 {
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -88,6 +88,42 @@ fn bound_pattern_arithmetic_preserves_nested_arguments_and_shared_random_draws()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn seeded_vector_modulo_preserves_the_period_and_random_stream() {
|
||||
use super::{FunctionScope, PatternExpression};
|
||||
use crate::random::FunctionRandom;
|
||||
|
||||
let mut graph = FunctionGraph::default();
|
||||
let range = graph.add_constant(Value::Float(1.0));
|
||||
let draw = graph.add("rand", &[range], None);
|
||||
let pair = graph.add("vector2", &[draw, draw], None);
|
||||
let offset = graph.add_constant(Value::Float2([0.8125, 0.21875]));
|
||||
let shifted = graph.add("sub", &[pair, offset], None);
|
||||
let period = graph.add_constant(Value::Float2([0.375, -0.1875]));
|
||||
graph.output = Some(graph.add("mod", &[shifted, period], None));
|
||||
let program = compile(&graph, 0).unwrap();
|
||||
let variables = BTreeMap::new();
|
||||
let context = EvaluationContext {
|
||||
scope: FunctionScope::FxMap,
|
||||
variables: &variables,
|
||||
position: [0.5; 2],
|
||||
size: [16.0; 2],
|
||||
tile: true,
|
||||
images: &[],
|
||||
image_formats: &[],
|
||||
};
|
||||
let mut bound = PatternExpression::bind(&program, &variables, &BTreeSet::new(), None).expect("seeded vector modulo should bind");
|
||||
for seed in [0, 19, 42, 329_779] {
|
||||
let mut normal = FunctionRandom::image(seed);
|
||||
let mut prepared = normal;
|
||||
let value = program.evaluate_with_random(&context, &mut EvaluationState::default(), &mut normal).unwrap();
|
||||
let Value::Float2([x, y]) = value else { panic!("expected a two-component offset") };
|
||||
assert!((0.0..0.375).contains(&x) && y > -0.1875 && y <= 0.0);
|
||||
assert_eq!(bound.evaluate(&mut prepared).unwrap(), (value, None));
|
||||
assert_eq!(prepared.draw().to_bits(), normal.draw().to_bits());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn folded_integers_use_word_order_and_convert_unsigned_magnitudes() {
|
||||
let variables = BTreeMap::from([("lhs".into(), Value::Int(-5)), ("rhs".into(), Value::Int(2))]);
|
||||
|
||||
@@ -59,6 +59,23 @@ The first pass classifies all 546 roots: 166 Parity and 380 Too hard. These meas
|
||||
|
||||
## 2026-11-27 root comparisons
|
||||
|
||||
### Floored modulo in seeded drawing properties
|
||||
|
||||
Directional Noise 2 v2 at 64 × 32 and seed 195000 now returns a whole image in each of four storage formats and on their four ordinary saves. The previous evaluator reached its property budget on this setting. It had completed 5,242,880 full property evaluations and still had pending drawing work. The drawing function wraps a two-component offset using floored modulo. The general evaluator already implements that operation. The bounded drawing evaluator now uses the same implementation for its fixed and seeded operands. It preserves the random register and the offset published to subsequent properties.
|
||||
|
||||
Use scale 3, disorder, speed, anisotropy and angle randomness .34375, both angles .09375, tile offset (0,.10546875) and non-square expansion on. Keep tiling and all other defaults. The graph generates its own input. Set the node feeding the output to each storage format, save to its own file, close and reopen with the stored parameters. The four saved MaterialCraft buffers reproduce their originals, **8,192/8,192** pixels. Integer errors below are stored levels. [Earlier tiled settings](#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series)
|
||||
|
||||
| Storage | Original · one · max | Original · eight · max | Saved · one · max | Saved · eight · max |
|
||||
|---|---:|---:|---:|---:|
|
||||
| U8 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 |
|
||||
| U16 | 2,047/2,048 · 1 | 2,046/2,048 · 1 | 2,046/2,048 · 1 | 2,046/2,048 · 1 |
|
||||
| F16 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 | 2,048/2,048 · 0 |
|
||||
| F32 | 1,253/2,048 · 1.1920929e-07 | 1,348/2,048 · 1.78813934e-07 | 1,300/2,048 · 1.1920929e-07 | 1,300/2,048 · 1.1920929e-07 |
|
||||
|
||||
The original F32 reference captures themselves agree at 1,096/2,048 pixels, maximum 1.34110451e-07. The remaining differences keep the root in progress.
|
||||
|
||||
For the procedural controls, start with a two-component seeded offset. Subtract (.1875,.21875), then apply floored modulo to each component. With one shared random draw use a period of (.09375,.09375). With two independent draws use (.09375,−.125). For the third case use the signed periods in an offset that the tint assigns to a local variable used by the child. Compare 16² at seed 0, 32 × 16 at seed 42 and 16 × 32 at seed 329779 in U8, U16, F16 and F32. The 36 originals and 36 ordinary reopens each match **15,360/15,360** pixels against both reference processor counts, maximum zero. The regression compares positive and negative periods with the full evaluator and checks the next random draw at four seeds. [Seeded offsets and routing controls](#rectangular-clouds-and-directional-noise-graphs-with-seeded-quadrant-offsets)
|
||||
|
||||
### Rectangular Clouds and Directional Noise graphs with seeded quadrant offsets
|
||||
|
||||
Clouds 1 v2 and Clouds 2 v2 each produce whole images for all **60/60 established originals and 15/15 archived saves** across the recorded passes. Each previously produced 58 originals and 14 saves. The 64 × 16 Directional Noise 3 v2 at seed 42 now matches **4,096/4,096** original pixels across four formats and another **4,096/4,096** after opening its four ordinary saves, at both reference processor counts. Earlier same-setting reference differences still leave the three roots in progress. [Earlier Cloud rectangles](#two-more-whole-outputs-in-noise-clouds-1-v2) · [Earlier Directional Noise results](#a-recovered-rectangle-and-repeated-outputs-in-directional-noise-3-v2)
|
||||
|
||||
@@ -495,7 +495,7 @@ Creased matches 10,947,840/10,947,840 pixels across 100 distinct settings throug
|
||||
| [noise_directional_noise_1.sbs/directional_noise_1](../assets/sbs/noise_directional_noise_1.sbs) | 0 | Yes | [In progress · 734,118/734,464 whole pixels across 60 settings on one processor, 734,140 on eight](parity-fixes.md#final-three-quadrant-levels-in-directional-noise-1) · [Seven interior routes and their ordinary saves](parity-fixes.md#interior-routes-between-terminal-quadrants) · [Outer routes and five ordinary reopens](parity-fixes.md#outer-routes-into-the-final-three-active-quadrant-levels) · [Partly wrapped copies and seven reopens](parity-fixes.md#partly-wrapped-copies-in-directional-noise-1) · [Copy counts across sampling windows](parity-fixes.md#terminal-quadrant-order-across-sampling-windows) · [Earlier directional measurements](parity-fixes.md#directional-noise-and-scratch-pattern-sources) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) |
|
||||
| [noise_directional_noise_1_v2.sbs/directional_noise_1](../assets/sbs/noise_directional_noise_1_v2.sbs) | 0 | No | [In progress · earlier stages and maximum-blend control exact at 16² and 32², additive differences remain](parity-fixes.md#addition-and-maximum-blending-in-directional-noise-1-v2) · [Earlier comparison · 60/60 originals and 12/12 saves render, 626,333/734,464 original pixels on one processor and 633,052 on eight](parity-fixes.md#complete-render-coverage-in-the-second-version-of-directional-noise-1) · [Earlier comparison · 56/60 whole settings rendered, 618,970/726,272 pixels on one processor, 625,683 on eight](parity-fixes.md#sixty-whole-settings-for-three-directional-and-dirt-noise-packages) · [Earlier comparison · 133,251/142,592 pixels in 18 comparable renders](parity-fixes.md#directional-noise-and-scratch-pattern-sources) · [6/6 tiled settings render, 3 exact on one processor](parity-fixes.md#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) · [8/8 untiled settings render](parity-fixes.md#untiled-spots-clouds-directional-noise-and-dirt-at-two-rectangular-sizes) · [Untiled F32 original and ordinary save](parity-fixes.md#seeded-quadrant-properties-with-a-live-tint-multiplier) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) |
|
||||
| [noise_directional_noise_2.sbs/directional_noise_2](../assets/sbs/noise_directional_noise_2.sbs) | 0 | Yes | [In progress · 103,497/107,776 pixels in 11 comparable renders](parity-fixes.md#directional-noise-and-scratch-pattern-sources) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) |
|
||||
| [noise_directional_noise_2_v2.sbs/directional_noise_2](../assets/sbs/noise_directional_noise_2_v2.sbs) | 0 | No | [In progress · 105,116/107,776 pixels in 11 comparable renders](parity-fixes.md#directional-noise-and-scratch-pattern-sources) · [2/6 tiled settings render, 0 exact on one processor](parity-fixes.md#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) · [8/8 untiled settings render](parity-fixes.md#untiled-spots-clouds-directional-noise-and-dirt-at-two-rectangular-sizes) · [Untiled original and ordinary save, remaining tiled F32 limit](parity-fixes.md#seeded-quadrant-properties-with-a-live-tint-multiplier) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) |
|
||||
| [noise_directional_noise_2_v2.sbs/directional_noise_2](../assets/sbs/noise_directional_noise_2_v2.sbs) | 0 | No | [In progress · all four tiled 64 × 32 formats and saves render, F32 differences measured](parity-fixes.md#floored-modulo-in-seeded-drawing-properties) · [Earlier comparison · 105,116/107,776 pixels in 11 comparable renders](parity-fixes.md#directional-noise-and-scratch-pattern-sources) · [2/6 tiled settings render, 0 exact on one processor](parity-fixes.md#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) · [8/8 untiled settings render](parity-fixes.md#untiled-spots-clouds-directional-noise-and-dirt-at-two-rectangular-sizes) · [Untiled original and ordinary save, remaining tiled F32 limit](parity-fixes.md#seeded-quadrant-properties-with-a-live-tint-multiplier) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) |
|
||||
| [noise_directional_noise_3.sbs/directional_noise_3](../assets/sbs/noise_directional_noise_3.sbs) | 0 | Yes | [In progress · 52/60 originals and 10/12 archived ordinary saves rendered](parity-fixes.md#drawing-parents-and-terminal-children-in-directional-noise-3) · [Earlier 44/60 settings and four ordinary saves](parity-fixes.md#accounting-for-a-streamed-draw-and-its-tile-copies) · [Earlier comparison · 40/60 settings rendered, 407,151/407,808 exact pixels on one and 407,274 on eight](parity-fixes.md#rectangular-and-additional-seed-coverage-in-directional-noise-3) · [First 19 settings · 17/19 established originals render, 141,209/141,568 pixels on one and 141,288 on eight](parity-fixes.md#streaming-equal-ranked-analytic-stamps-through-one-output-image) · [Earlier comparison · 15/19 original settings have rendered, eight additional settings and three ordinary saves compared](parity-fixes.md#reused-properties-across-adjacent-groups-of-terminal-quadrants) · [Earlier comparison · 7/19 whole renders completed, 7,168/7,424 exact pixels](parity-fixes.md#discarding-pattern-stamps-that-miss-every-output-sample) · [Original stage comparisons](parity-fixes.md#directional-noise-and-scratch-pattern-sources) · [Five F32 returns per processor count at 32²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) |
|
||||
| [noise_directional_noise_3_v2.sbs/directional_noise_3](../assets/sbs/noise_directional_noise_3_v2.sbs) | 0 | No | [In progress · 64 × 16 at seed 42 exact in four formats on both file routes](parity-fixes.md#rectangular-clouds-and-directional-noise-graphs-with-seeded-quadrant-offsets) · [Earlier comparison · untiled rectangle exact in four formats, four tiled F16 saves 7,424/7,424, three settings reach the work limit](parity-fixes.md#half-precision-inputs-to-levels) · [Earlier rectangle and tiled stage comparisons](parity-fixes.md#a-recovered-rectangle-and-repeated-outputs-in-directional-noise-3-v2) · [Earlier 19-setting panel](parity-fixes.md#discarding-pattern-stamps-that-miss-every-output-sample) · [Original stage comparisons](parity-fixes.md#directional-noise-and-scratch-pattern-sources) · [2/6 tiled settings render, 2 exact on one processor](parity-fixes.md#tiled-outputs-of-ten-noise-roots-and-the-full-wood-fibers-2-series) · [0/8 untiled settings render](parity-fixes.md#untiled-spots-clouds-directional-noise-and-dirt-at-two-rectangular-sizes) · [Untiled F32 limits at both rectangles](parity-fixes.md#seeded-quadrant-properties-with-a-live-tint-multiplier) |
|
||||
| [noise_directional_noise_4.sbs/directional_noise_4](../assets/sbs/noise_directional_noise_4.sbs) | 0 | Yes | [In progress · 134,015/144,640 pixels in 19 comparable renders](parity-fixes.md#directional-noise-and-scratch-pattern-sources) · [Five F32 returns per processor count at 16²](parity-fixes.md#repeated-f32-captures-of-28-noise-roots) |
|
||||
|
||||
Reference in new issue
Block a user