mirror of
https://github.com/storytold/materialcraft.git
synced 2026-11-28 17:19:17 +01:00
Match rotated stamp interpolation across pixel pairs
This commit is contained in:
1 parent
0061c94df4
commit
bc0fda7726
5 files changed
+96
-14
No files matched your search
@@ -114,7 +114,7 @@ impl PixelPlanes {
|
||||
pub fn row(&self, y: u32) -> impl Fn(u32) -> Option<[f32; 2]> + '_ {
|
||||
let vertical = match &self.mapping {
|
||||
Mapping::Aligned { axes, .. } => [f64::from(axes[1].sample(y)), 0.0],
|
||||
Mapping::Oblique { planes, origin } => planes.each_ref().map(|plane| plane.y_term(f64::from(y) + 0.5 - origin[1])),
|
||||
Mapping::Oblique { planes, origin } => planes.each_ref().map(|plane| plane.y_term(y, f64::from(y) + 0.5 - origin[1])),
|
||||
};
|
||||
move |x| match &self.mapping {
|
||||
Mapping::Aligned { axes, swap } => {
|
||||
@@ -124,7 +124,7 @@ impl PixelPlanes {
|
||||
}
|
||||
Mapping::Oblique { planes, origin } => {
|
||||
let dx = f64::from(x) + 0.5 - origin[0];
|
||||
let uv: [f32; 2] = std::array::from_fn(|i| planes[i].sample(dx, vertical[i]));
|
||||
let uv: [f32; 2] = std::array::from_fn(|i| planes[i].sample(x, dx, vertical[i]));
|
||||
uv.iter().all(|v| v.abs() <= 1.0).then_some(uv)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,17 +4,20 @@ use crate::function::{pixel_divide, truncate_float};
|
||||
pub(super) struct Plane {
|
||||
base: f64,
|
||||
step: [f64; 2],
|
||||
negative_bias: f64,
|
||||
pair_offset: [[f64; 2]; 2],
|
||||
quantum: f64,
|
||||
inverse_quantum: f64,
|
||||
}
|
||||
|
||||
impl Plane {
|
||||
pub(super) fn y_term(&self, dy: f64) -> f64 {
|
||||
dy * self.step[1]
|
||||
pub(super) fn y_term(&self, y: u32, dy: f64) -> f64 {
|
||||
dy * self.step[1] + self.pair_offset[1][(y & 1) as usize]
|
||||
}
|
||||
|
||||
pub(super) fn sample(&self, dx: f64, y_term: f64) -> f32 {
|
||||
let value = self.base + dx * self.step[0] + y_term;
|
||||
truncate_float(if value < 0.0 { value + self.negative_bias } else { value })
|
||||
pub(super) fn sample(&self, x: u32, dx: f64, y_term: f64) -> f32 {
|
||||
let value = self.base + dx * self.step[0] + self.pair_offset[0][(x & 1) as usize] + y_term;
|
||||
let fixed = (value * self.inverse_quantum).floor();
|
||||
truncate_float((if fixed < 0.0 { fixed + 1.0 } else { fixed }) * self.quantum)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +29,7 @@ pub(super) fn planes(triangle: &Triangle, frame: &Footprint, size: [f32; 2], [[l
|
||||
return None;
|
||||
}
|
||||
let anchor = triangle.far_axis.map_or(0, |axis| axis + 1);
|
||||
Some(std::array::from_fn(|component| {
|
||||
let planes: [Plane; 2] = std::array::from_fn(|component| {
|
||||
let gradient: [f32; 2] = std::array::from_fn(|axis| {
|
||||
let difference = aligned_sum([f64::from(vertices[axis + 1][component]), -f64::from(vertices[0][component])], 1);
|
||||
let span = truncate_float(difference * 0.5);
|
||||
@@ -44,8 +47,19 @@ pub(super) fn planes(triangle: &Triangle, frame: &Footprint, size: [f32; 2], [[l
|
||||
if gradient[i].is_sign_negative() { -magnitude } else { magnitude }
|
||||
});
|
||||
let base = truncate_float(aligned_sum([terms[0], terms[1], f64::from(vertices[anchor][component])], 5));
|
||||
Plane { base: f64::from(base), step: gradient.map(f64::from), negative_bias: units[0].max(units[1]) / 64.0 }
|
||||
}))
|
||||
let step = gradient.map(f64::from);
|
||||
let unit = units[0].max(units[1]);
|
||||
// The two samples of a pair share the value at their midpoint. Its signed
|
||||
// half-step discards gradient bits below a quarter of the larger gradient's ULP.
|
||||
let quarter = unit * 0.25;
|
||||
let pair_offset = step.map(|v| {
|
||||
let half_remainder = (v - (v / quarter).trunc() * quarter) * 0.5;
|
||||
[half_remainder, -half_remainder]
|
||||
});
|
||||
let quantum = unit / 64.0;
|
||||
Plane { base: f64::from(base), step, pair_offset, quantum, inverse_quantum: quantum.recip() }
|
||||
});
|
||||
planes.iter().all(|p| p.quantum.is_finite()).then_some(planes)
|
||||
}
|
||||
|
||||
/// Align signed operands at a shared exponent before cancellation in the interpolation setup.
|
||||
|
||||
@@ -437,6 +437,38 @@ fn subpixel_rotated_stamp_interpolates_its_ramp_and_paraboloid() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rotated_paraboloid_interpolates_across_neighboring_pixel_pairs() {
|
||||
let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant);
|
||||
graph.nodes[0].parameters = BTreeMap::from([
|
||||
("patterntype".into(), Value::Int(4)),
|
||||
("branchoffset".into(), Value::Float2([-0.5; 2])),
|
||||
("frameoffset".into(), Value::Float2([0.046_721_816, 0.413_024_96])),
|
||||
("patternsize".into(), Value::Float2([0.106_382_97; 2])),
|
||||
("patternrotation".into(), Value::Float(0.430_651_3)),
|
||||
]);
|
||||
let variables = BTreeMap::from([("$tiling".into(), Value::Int(3))]);
|
||||
let image = cook_at_dimensions(graph, &variables, 350314, 64, 128).unwrap().remove(0);
|
||||
for (x, y, bits) in [(1, 48, 0x3ecb_3c42), (1, 52, 0x3f4e_334f), (5, 52, 0x3ee8_375a)] {
|
||||
assert_eq!(image.get_gray(x, y, false).to_bits(), bits);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shallow_rotated_ramp_stores_the_interpolated_coordinate_before_shading() {
|
||||
let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant);
|
||||
graph.nodes[0].parameters = BTreeMap::from([
|
||||
("patterntype".into(), Value::Int(10)),
|
||||
("branchoffset".into(), Value::Float2([-0.5; 2])),
|
||||
("frameoffset".into(), Value::Float2([0.415_625, 0.480_468_75])),
|
||||
("patternsize".into(), Value::Float2([0.386_718_75, 0.25])),
|
||||
("patternrotation".into(), Value::Float(0.000_273_437_5)),
|
||||
]);
|
||||
let variables = BTreeMap::from([("$tiling".into(), Value::Int(0))]);
|
||||
let image = cook_at_dimensions(graph, &variables, 360680, 32, 64).unwrap().remove(0);
|
||||
assert_eq!(image.get_gray(8, 31, false).to_bits(), 0x3de5_bb68);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn oblique_stamp_retains_the_small_cross_axis_step_on_a_thin_ramp() {
|
||||
let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant);
|
||||
|
||||
@@ -534,6 +534,40 @@ For each root’s 25 follow-up renders, the 5,120 U8, 553,728 U16, 78,336 F16 an
|
||||
|
||||
In a single-worker release run, four interleaved measurements of the 128² default, 256² default and 512² filled cases gave median whole-graph cook times of 46, 259 and 1,138 ms for Alveolus (previously 45, 247 and 1,068 ms). Pattern Alveolus took 45, 253 and 1,083 ms (previously 43, 238 and 1,045 ms).
|
||||
|
||||
### Interpolation across pairs of pixels in Cells 1
|
||||
|
||||
The last differing Cells 1 sample came from a white paraboloid at (1,52) on a 64×128 image. Given the same three vertices, an independently drawn triangle reproduced the reference’s two signed F32 coordinates, .3740799427 and .2336531430. The previous CPU result was .3740799129 for the first coordinate. The pattern output stored `3f4e334f` in the reference and `3f4e3350` in MaterialCraft. Reuse the [single stamp, resolution and seed](#bounds-and-pixel-coordinates-of-rotated-pattern-stamps). Its pixels (1,48), (1,52) and (5,52) now store `3ecb3c42`, `3f4e334f` and `3ee8375a` in both apps.
|
||||
|
||||
An original right triangle isolates the interpolation step. Give its vertices screen coordinates (0,0), (1024,0) and (0,1024) with clip W=1. Assign a scalar attribute A, A+1024g and A+1024h. Select integer x and y from 0 through 15, set A to F32(−g(x+.5)−h(y+.5)), and store the three attributes as F32 before drawing. This puts the sample near zero and exposes low bits that would disappear on conversion to the output format. In 6,240 signed samples with gradient exponent differences from 0 through 12, the new calculation matched 6,240/6,240, maximum error zero. On three independent sets with other starting values and translated triangles, all 819,200, 819,200 and 652,280 measured coordinate components matched the device. Across a further 77,822 components from stamp triangles, 77,821 matched, maximum 1.90734863e−6.
|
||||
|
||||
The opposite half-steps of a two-pixel pair use a common precision. Taking one ULP of the larger gradient as U, truncate each signed gradient to multiples of U/4 for the half-step from the pair midpoint. Store the accumulated sample on a grid of U/64 before conversion to F32. A second regression checks the shallow horizontal ramp at (8,31) on a 32×64 image. Use center (.415625,.48046875), size (.38671875,.25), rotation .0002734375 turns, tiling off and seed 360680. The reference stores `3de5bb68`. Both regressions failed on the preceding build.
|
||||
|
||||
| F32 stamp comparison | Renders | Previous exact | Current exact / pixels | Maximum error now |
|
||||
|---|---:|---:|---:|---:|
|
||||
| Translated ramp | 210 | 860,128 | 860,160/860,160 | 0 |
|
||||
| Translated paraboloid | 210 | 860,071 | 860,160/860,160 | 0 |
|
||||
| Extended-turn ramp | 99 | 337,757 | 337,920/337,920 | 0 |
|
||||
| Extended-turn paraboloid | 99 | 337,743 | 337,920/337,920 | 0 |
|
||||
| Pyramid at ordinary angles | 30 | 159,717 | 159,744/159,744 | 0 |
|
||||
| Rotated subpixel ramp | 220 | 309,757 | 309,759/309,760 | 9.53674316e−07 |
|
||||
| Rotated subpixel paraboloid | 220 | 309,749 | 309,759/309,760 | 2.98023224e−06 |
|
||||
| Individual draws from BNW Spots 1 | 1,052 | 820,191 | 820,249/820,304 | 1.67638063e−07 |
|
||||
|
||||
The rotated subpixel ramp and paraboloid each have one differing pixel. Both use the 16×32 placement, the first pair of subpixel extents and .3305 turns. In a separate angular sweep, use turns (.0001220703125,.0002734375,−.0007453125,.00128125,.00390625,.01607,.2499,.5003,−1.0001,−.74934,1.50014,.43065130710601807,.1171875). At zero-based angle i and size j, select (32×64,64×32,64²,128×64)[j] and seed 360607+73i+j. Center the stamp at (.415625+.03125j, .53125−.05078125(i mod 3)). Set the width to .375+.01171875(i mod 5), negated at j=2, and the height to .25+.046875j. Across the 52 geometries all 212,992 pixels matched for each of square, horizontal ramp, paraboloid and pyramid. The previous exact counts were 212,992, 212,868, 212,811 and 212,819 respectively. [Translated, extended-turn and subpixel settings](#bounds-and-pixel-coordinates-of-rotated-pattern-stamps)
|
||||
|
||||
| Intact root, distinct settings | Renders | U8 exact · max | U16 exact · max | F16 exact · max | F32 exact · max |
|
||||
|---|---:|---:|---:|---:|---:|
|
||||
| Cells 1, union of original settings | 89 | 615,168/615,168 · 0 | 916,736/916,736 · 0 | 615,168/615,168 · 0 | 828,160/828,160 · 0 |
|
||||
| Crystal 2, new settings | 40 | 414,208/414,208 · 0 | 693,243/693,248 · 1 | 414,208/414,208 · 0 | 693,243/693,248 · 1.52587891e−05 |
|
||||
|
||||
Cells 1 matches all 2,975,232 pixels in 89 distinct combinations of dimensions, seed, exposed values and output format. The 42-render expansion uses (16²,32²,64×128,128×64,128²,256×128,128×256,256²,512×256,256×512,512²,256²). Use (distance, disorder) = (default), (1,0), (23,21.875), (7,51.5625), (16,37.5), (3,2.34375), (11,71.875), (19,93.75), (9,12.5), (29,100), (default), (default). The seeds at j=0,2,10,11 are 0,350314,0,42. Elsewhere use 361003+41j. Render U16/F32 at every size and add U8/F16 at j=0,1,2,5,6,7,9,10,11. MaterialCraft saves of this matrix and the preceding 24-render matrix reopened in both apps and retained all 2,708,480 and 113,664 pixels respectively. [Earlier Cells 1 matrices and parameter controls](#bounds-and-pixel-coordinates-of-rotated-pattern-stamps)
|
||||
|
||||
Crystal 2 improved from 145,662 to 145,664/145,664 on 17 earlier renders and matches 40,192/40,192 on ten additional historical settings. It remains in progress. For the 40 new settings use dimensions (16×32,32×16,64²,128×64,64×128,128²,256×128,128×256,256²,512²,512×256,256×512) and warp intensities (default,0,1.25,3.4375,9.625,13.875,27.75,42.5,61.75,default,31,.125). Defaults use seed 0. Use seed 42 at j=1 and 364651+53j elsewhere. Render all four formats at j=0,2,3,4,6,7,8,9 and U16/F32 elsewhere. At 256², intensity 61.75 and seed 365075, three of the 65,536 U16 pattern samples differ by one level. At (108,73) the pattern stage stores 34,666 against 34,665, then levels stores 28,192 against 28,191. The warp spreads the three differences to five output pixels. All 2,214,912 pixels in the root’s MaterialCraft save reproduce the original within each app.
|
||||
|
||||
The other 39 rechecked intact roots retained their counts and maximum errors on their earlier matrices. Across eight saved graphs, all 5,420,032 pixels matched the corresponding originals after reopening in each app. The extended-angle ramp that previously differed on 19 saved-file samples now matches all 49,152 cross-app samples. The two spots roots retain their outstanding differences in the intact graphs.
|
||||
|
||||
In four alternating single-worker release runs at 64², median cook times for BNW Spots 1 and BNW Spots 3 went from 186.2 to 211.4 ms and from 150.9 to 176.9 ms. On the 16² four-way stress graph, depth seven went from 33.2 to 33.5 ms and depth nine from 527.0 to 548.5 ms. All 296 release node tests, formatting, strict workspace Clippy, layers and WebAssembly passed.
|
||||
|
||||
### Bounds and pixel coordinates of rotated pattern stamps
|
||||
|
||||
A white square, horizontal ramp and paraboloid distinguish the bounding rectangle of a stamp from its coordinate rotation. Translating both the stamp and its render window by an integer preserves their relative positions and exposes rounding when the corners are stored. The measured bounds use the uniform sine and cosine of the original rotation in turns. Each vertex retains its snapping displacement in pattern space. The two signed coordinates use the pixel rotation of the angle in radians and the original stamp dimensions. A rotated stamp narrower than one pixel still interpolates across the padded triangle. MaterialCraft now uses these coordinates for drawing and for culling repeated subpixel stamps.
|
||||
|
||||
@@ -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 **386 Parity**, **160 In progress** and **0 Too hard**. The November 17–20 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) · [November 19 measurements](parity-fixes.md#2026-11-19-root-comparisons) · [November 20 measurements](parity-fixes.md#2026-11-20-root-comparisons)
|
||||
The first pass covered all **546 roots**, with **166 Parity** and **380 Too hard**. The current inventory has **387 Parity**, **159 In progress** and **0 Too hard**. The November 17–20 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) · [November 19 measurements](parity-fixes.md#2026-11-19-root-comparisons) · [November 20 measurements](parity-fixes.md#2026-11-20-root-comparisons)
|
||||
|
||||
[Pattern tiling axes and copy bounds across 215 renders](parity-fixes.md#tiling-axes-and-pattern-copy-bounds) · [Grayscale sampler measurements](parity-fixes.md#grayscale-sampling-of-color-inputs) · [Value sampling across 240 typed comparisons](parity-fixes.md#value-processor-texture-filtering) · [Five saved graphs reopened in the reference](parity-fixes.md#saved-filter-graphs-and-scalar-levels-controls)
|
||||
|
||||
@@ -83,6 +83,8 @@ All 185,856 pixels match on 44 unrotated subpixel geometries across three patter
|
||||
|
||||
Seven of 40 intact roots gained exact pixels after correcting rotated stamp bounds. Cells 1 matches 145,664/145,664 in its original matrix and 113,662/113,664 on new settings. All six saves reproduce 496,640/496,640 pixels after reopening in each app. [Root measurements, single-stamp reproductions and saved files](parity-fixes.md#bounds-and-pixel-coordinates-of-rotated-pattern-stamps)
|
||||
|
||||
Cells 1 reached measured parity across 89 distinct settings, including 512² and reopened files. Crystal 2 retains five differing positions on a new 256² setting. [Pixel counts, parameters and remaining differences](parity-fixes.md#interpolation-across-pairs-of-pixels-in-cells-1)
|
||||
|
||||
## Complete inventory
|
||||
|
||||
| SBS package / graph path | Input pins | Hidden in library | Parity status |
|
||||
@@ -154,7 +156,7 @@ Seven of 40 intact roots gained exact pixels after correcting rotated stamp boun
|
||||
| [cartesian_polar_transformation.sbs/cartesian_to_polar_grayscale](../assets/sbs/cartesian_polar_transformation.sbs) | 1 | No | [Parity · 171,264 exact pixels in 18 renders](parity-fixes.md#segment-mapping-and-normal-graph-rechecks) |
|
||||
| [cartesian_polar_transformation.sbs/polar_to_cartesian](../assets/sbs/cartesian_polar_transformation.sbs) | 1 | No | [Parity · 28 renders, all 306,688 pixels exact](parity-fixes.md#reverse-polar-sampling-in-color-and-grayscale) |
|
||||
| [cartesian_polar_transformation.sbs/polar_to_cartesian_grayscale](../assets/sbs/cartesian_polar_transformation.sbs) | 1 | No | [Parity · 28 renders, all 306,688 pixels exact](parity-fixes.md#reverse-polar-sampling-in-color-and-grayscale) |
|
||||
| [cells_1.sbs/cells_1](../assets/sbs/cells_1.sbs) | 0 | Yes | [In progress · 113,662/113,664 pixels on 24 additional renders](parity-fixes.md#bounds-and-pixel-coordinates-of-rotated-pattern-stamps) · [27,136/27,136 downstream pixels](parity-fixes.md#isolating-the-generators-in-spots-bricks-and-cells) |
|
||||
| [cells_1.sbs/cells_1](../assets/sbs/cells_1.sbs) | 0 | Yes | [Parity · 89 settings, 2,975,232/2,975,232 pixels](parity-fixes.md#interpolation-across-pairs-of-pixels-in-cells-1) · [27,136/27,136 downstream pixels](parity-fixes.md#isolating-the-generators-in-spots-bricks-and-cells) |
|
||||
| [channel_mixer.sbs/channel_mixer](../assets/sbs/channel_mixer.sbs) | 1 | No | [Parity · 18 cases, 171,264 exact pixels](parity-fixes.md#large-transform-offsets-and-additive-blends) |
|
||||
| [checker_1.sbs/checker_1](../assets/sbs/checker_1.sbs) | 0 | Yes | [Parity · eight cases, four formats](parity-fixes.md#transform-edges-and-floating-point-filtering) |
|
||||
| [checker_2.sbs/checker_2](../assets/sbs/checker_2.sbs) | 0 | Yes | [Parity: 4 cases](parity-fixes.md#verified-cases) |
|
||||
@@ -205,7 +207,7 @@ Seven of 40 intact roots gained exact pixels after correcting rotated stamp boun
|
||||
| [crop.sbs/crop](../assets/sbs/crop.sbs) | 1 | No | [Parity · 48 renders, all 377,344 pixels across both outputs exact](parity-fixes.md#half-precision-crop-area-and-input-sizes) |
|
||||
| [crop.sbs/crop_grayscale](../assets/sbs/crop.sbs) | 1 | No | [Parity · 48 renders, all 377,344 pixels across both outputs exact](parity-fixes.md#half-precision-crop-area-and-input-sizes) |
|
||||
| [crystal_1.sbs/crystal_1](../assets/sbs/crystal_1.sbs) | 0 | Yes | [Parity · 1,966,336/1,966,336 pixels in 64 distinct renders, 32 reopened settings](parity-fixes.md#stored-stamp-vertices-in-crystal-1) |
|
||||
| [crystal_2.sbs/crystal_2](../assets/sbs/crystal_2.sbs) | 0 | Yes | [In progress · 145,662/145,664 pixels across 17 renders](parity-fixes.md#bounds-and-pixel-coordinates-of-rotated-pattern-stamps) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) |
|
||||
| [crystal_2.sbs/crystal_2](../assets/sbs/crystal_2.sbs) | 0 | Yes | [In progress · five differing positions across 40 new renders](parity-fixes.md#interpolation-across-pairs-of-pixels-in-cells-1) · [Stamp-width recheck](parity-fixes.md#pixel-reciprocals-for-stamp-edge-widths) |
|
||||
| [curvature.sbs/curvature](../assets/sbs/curvature.sbs) | 1 | No | [Parity · 20 renders, 176,384 exact pixels](parity-fixes.md#sampling-integer-bitmap-inputs-through-wider-bridges) |
|
||||
| [curvature_smooth.sbs/curvature_smooth](../assets/sbs/curvature_smooth.sbs) | 1 | Yes | [Parity · 20 renders, 176,384 exact pixels](parity-fixes.md#sampling-integer-bitmap-inputs-through-wider-bridges) |
|
||||
| [curvature_smooth_v2.sbs/compute_curvature_v2](../assets/sbs/curvature_smooth_v2.sbs) | 2 | Yes | [Parity: 6 cases](parity-fixes.md#verified-cases) |
|
||||
|
||||
Reference in new issue
Block a user