Correct quadrant placement and Gaussian falloff in pattern maps

This commit is contained in:
chasse20 committed 2026-11-18 01:01:14 -05:00
1 parent 1149831797
commit ee7efcd4fc
5 files changed
+73 -7

No files matched your search

+2 -2
View File
@@ -94,7 +94,7 @@ pub(crate) fn cook(context: &CookContext) -> CookResult {
PatternNodeKind::Dot => {}
PatternNodeKind::Quadrant => {
let offset = vector("branchoffset");
visit.center = [visit.center[0] + offset[0] * visit.extent, visit.center[1] + offset[1] * visit.extent];
visit.center = [visit.center[0] + offset[0], visit.center[1] + offset[1]];
let pattern = integer("patterntype");
let pattern = if pattern == 1 { integer("imageindex").max(1).saturating_add(255) } else { pattern };
if pattern != 0 {
@@ -106,7 +106,7 @@ pub(crate) fn cook(context: &CookContext) -> CookResult {
};
stamps.push(PatternStamp {
center: [visit.center[0] + offset[0] * visit.extent, visit.center[1] + offset[1] * visit.extent],
center: [visit.center[0] + offset[0], visit.center[1] + offset[1]],
size: vector("patternsize").map(|size| size * visit.extent),
rotation: scalar("patternrotation"),
color,
+4 -1
View File
@@ -12,7 +12,10 @@ pub(super) fn coverage(pattern: i32, x: f32, y: f32, variation: f32) -> Result<f
}
3 => radial,
4 => radial * radial,
5 => (-4.0 * radius_squared).exp(),
5 => {
const FALLOFF: f32 = 11.1;
((-FALLOFF * radius_squared).exp() - (-FALLOFF).exp()).max(0.0)
}
6 => (1.0 - radius_squared.sqrt()).max(0.0).powi(4),
7 => (1.0 - x.abs().max(y.abs())).max(0.0),
8 => {
+37
View File
@@ -92,6 +92,43 @@ fn subpixel_quadrants_do_not_accumulate_at_shared_edges() {
assert!(image.data().iter().all(|value| (*value - 0.25).abs() < 1e-6), "mean {}", image.mean()[0]);
}
#[test]
fn quadrant_offsets_use_canvas_units_at_each_depth() {
for (depth, origin, side) in [(1, [16_i64, 48], 8), (2, [8, 56], 4), (3, [4, 60], 2)] {
for property in ["branchoffset", "frameoffset"] {
let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant);
for index in 0..depth {
let child = graph.add(PatternNodeKind::Quadrant).unwrap();
graph.nodes[index].children[2] = Some(child);
}
let leaf = &mut graph.nodes[depth].parameters;
leaf.insert("patterntype".into(), Value::Int(2));
leaf.insert("patternsize".into(), Value::Float2([0.25; 2]));
leaf.insert(property.into(), Value::Float2([0.25, 0.125]));
let image = cook("fx_map", BTreeMap::from([("pattern".into(), Value::PatternGraph(Box::new(graph)))]), &[]);
let [cx, cy] = [origin[0] + 16, (origin[1] + 8) % 64];
for y in 0..64 {
for x in 0..64 {
let inside = (x - cx + side / 2).rem_euclid(64_i64) < side && (y - cy + side / 2).rem_euclid(64_i64) < side;
assert_eq!(image.get_gray(x, y, false), if inside { 1.0 } else { 0.0 }, "{property} at depth {depth}, ({x},{y})");
}
}
}
}
}
#[test]
fn gaussian_stamp_reaches_zero_at_the_edge_of_the_unit_disk() {
let mut graph = PatternGraph::with_root(PatternNodeKind::Quadrant);
graph.nodes[0].parameters.insert("patterntype".into(), Value::Int(6));
let image = cook("fx_map", BTreeMap::from([("pattern".into(), Value::PatternGraph(Box::new(graph)))]), &[]);
assert_eq!(image.get_gray(0, 0, false), 0.0);
for (x, expected) in [(0, 0.000006), (8, 0.002491), (16, 0.073742), (24, 0.542005), (31, 0.994580)] {
let value = image.get_gray(x, 31, false);
assert!((value - expected).abs() < 1.0e-6, "x={x}, {value} vs {expected}");
}
}
#[test]
fn grayscale_max_patterns_do_not_accumulate_opacity() {
let mut graph = PatternGraph::with_root(PatternNodeKind::Iterate);
+26
View File
@@ -99,6 +99,32 @@ Each format column compares all channels of 4,096 pixels. Clone uses 128² input
Both roots in `height_to_normal_world_units.sbs` match **131,072/131,072 RGBA pixels each** across eight cases. For a square grayscale height input, store `(17*x+31*y) mod 256` at each integer coordinate. Use default settings at 128² and 256², repeat 128² with seed 42, then set `surface_size=100`, `height_depth=8`, `normal_format=0` and `sampling=1` at 128² with seed zero. Each root matches 16,384, 65,536, 16,384 and 16,384 RGBA8 pixels respectively. Keep those changed settings and the 128² input, then cook at 64² with seed 42. U8, U16, F16 and F32 each match 4,096/4,096 pixels for both roots. Every maximum error is zero. Each 64² output contains 49 distinct normals.
### Alveolus quadrant placement and falloff
In an original blank 64² pattern graph, follow the lower-left quadrant one, two or three times and draw a square of size (.25, .25) at the leaf. With zero offsets its centers are (16, 48), (8, 56) and (4, 60) in pixel-edge coordinates. Applying (.25, .125) to either the branch offset or the pattern offset moves the center by (16, 8) texels at every depth, with tiling at the image bounds. The size still shrinks at each depth. A separate unit Gaussian stamp shows a circular cutoff and a falloff of approximately `max(0, exp(-11.1*r²) - exp(-11.1))` in local coordinates. At 64², unit opacity and F32, the maximum difference between that analytic profile and the observed red channel is 3.5e-7.
The corrected offsets and Gaussian profile bring the default Alveolus pattern stage from **0/8,192** LUM16 pixels (maximum error 55,100) to **8,096/8,192** (maximum error 1). The following table compares the final output bridge. This generator uses no input image.
| Case | Size | Seed | Output format | Exact pixels / total | Maximum error |
|---|---:|---:|---|---:|---:|
| Defaults | 128² | 0 and 42 | LUM16 | 16,192/16,384 each | 2 |
| Defaults | 256² | 0 | LUM16 | 64,896/65,536 | 2 |
| `Gradient_Filled_Cells=true`, `Interstice_Width=.1` | 128² | 0 | LUM16 | 16,264/16,384 | 1,000 |
| Same changed parameters | 64² | 42 | LUM8, LUM16, LUM16F, LUM32F | 4,096/4,096 each | 0 |
### Anisotropic blur
For the grayscale root bind `(17*x+31*y) mod 256`. For the color root use the same value in R, `U` in G, `255-V` in B and 255 in A. The definitions of `U` and `V` are under [color conversion, checker and clone](#color-conversion-checker-and-clone). At 128² the color input bridge matches all 16,384 pixels. The first directional pass already differs.
| Case | Color exact / total | Gray exact / total | Maximum error, color / gray |
|---|---:|---:|---:|
| Defaults, 128², eight-bit | 11,526/16,384 | 11,526/16,384 | 1 / 1 |
| Angle .125 turns, anisotropy .8, 128², eight-bit | 3,228/16,384 | 3,310/16,384 | 16 / 16 |
| Quality 1, intensity 4, 256², eight-bit | 65,536/65,536 | 65,536/65,536 | 0 / 0 |
| Same 256² input and changed settings at 64², seed 42, U8, U16, F16, F32 | 4,096/4,096 each | 4,096/4,096 each | 0 / 0 |
At the first directional pass the default color case matches 11,944/16,384 pixels with maximum error 1. With angle .125 it matches 2,997/16,384 with maximum error 21. A separate F32 impulse at (64,64) on a 128² field, intensity 10 and angle .125, has nonzero samples on both sides of the diagonal.
## 2026-11-17 root comparisons
The clean-room comparisons below use the 16.0.7 reference app with the Direct3D 11 backend and a release MaterialCraft CPU cook. They compare the raw output bridge at its stored precision. A pixel counts only when every channel agrees. Integer errors are in stored levels. Floating errors are absolute. Each case starts from the graph defaults. Where a row selects another storage format, set the final processor's format to absolute in both apps before cooking.
+4 -4
View File
@@ -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 **170 Parity**, **14 In progress** and **362 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 **170 Parity**, **17 In progress** and **359 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)
## Complete inventory
@@ -60,10 +60,10 @@ The first pass covered all **546 roots**, with **166 Parity** and **380 Too hard
| [3d_viewer.sbs/ibl_specular_contrib_anisotropic/panoramic_lod](../assets/sbs/3d_viewer.sbs) | 1 | Yes | [In progress · input resizing and transform filtering measured](parity-fixes.md#panoramic-lod) |
| [3d_volume_mask.sbs/3d_volume_mask](../assets/sbs/3d_volume_mask.sbs) | 1 | No | [In progress · box rotation and feathering differ](parity-fixes.md#3d-volume-mask-and-worley-noise) |
| [3d_worley_noise.sbs/3D_worley_noise](../assets/sbs/3d_worley_noise.sbs) | 1 | No | [In progress · random sequence differs before distance evaluation](parity-fixes.md#3d-volume-mask-and-worley-noise) |
| [alveolus.sbs/alveolus](../assets/sbs/alveolus.sbs) | 0 | Yes | [Too hard: cell field mismatch](parity-fixes.md#remaining-differences) |
| [alveolus.sbs/alveolus](../assets/sbs/alveolus.sbs) | 0 | Yes | [In progress · 64² format sweep exact, larger fields differ](parity-fixes.md#alveolus-quadrant-placement-and-falloff) |
| [angle_to_vector.sbs/angle_to_vector](../assets/sbs/angle_to_vector.sbs) | 1 | No | [Parity: 4 cases](parity-fixes.md#verified-cases) |
| [anisotropic_blur.sbs/anisotropic_blur](../assets/sbs/anisotropic_blur.sbs) | 1 | No | [Too hard: blur kernel](parity-fixes.md#remaining-differences) |
| [anisotropic_blur.sbs/anisotropic_blur_grayscale](../assets/sbs/anisotropic_blur.sbs) | 1 | No | [Too hard: blur kernel](parity-fixes.md#remaining-differences) |
| [anisotropic_blur.sbs/anisotropic_blur](../assets/sbs/anisotropic_blur.sbs) | 1 | No | [In progress · first directional pass differs](parity-fixes.md#anisotropic-blur) |
| [anisotropic_blur.sbs/anisotropic_blur_grayscale](../assets/sbs/anisotropic_blur.sbs) | 1 | No | [In progress · rotated kernel differs](parity-fixes.md#anisotropic-blur) |
| [atlas_spliter.sbs/crop_and_transform_sub](../assets/sbs/atlas_spliter.sbs) | 7 | Yes | [Too hard: typed-input comparison](parity-fixes.md#remaining-differences) |
| [atlas_spliter.sbs/max_ba](../assets/sbs/atlas_spliter.sbs) | 1 | Yes | [Parity: 3 cases](parity-fixes.md#verified-cases) |
| [auto_crop.sbs/min_max](../assets/sbs/auto_crop.sbs) | 1 | Yes | [Parity: 3 cases](parity-fixes.md#verified-cases) |