From 9f18a432cba499a42da96f3fa1b3a465c4b7fdc9 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 29 Sep 2026 23:51:04 +0200 Subject: [PATCH] CultMath: document phacelle and record Johansen's MPL-2.0 provenance design.md names CultPhasor as the second struct-return consumer and describes phacelle (stripe wave vector, weight, normalization, exact gradient and its two discontinuity classes, exact pruning). THIRD-PARTY-NOTICES.md, in both the package root and the Unity package, cites Rune Skovbo Johansen's Phacelle Noise (MPL-2.0) and records that the 3D-cell generalisation, the caller-supplied side vector, the exact gradient and the exact pruning are new. Co-Authored-By: Claude Opus 5.5 --- packages/cultmath/THIRD-PARTY-NOTICES.md | 15 ++++++++++++ packages/cultmath/docs/design.md | 23 +++++++++++++++++-- .../THIRD-PARTY-NOTICES.md | 15 ++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/packages/cultmath/THIRD-PARTY-NOTICES.md b/packages/cultmath/THIRD-PARTY-NOTICES.md index 1de744a7..73f2461a 100644 --- a/packages/cultmath/THIRD-PARTY-NOTICES.md +++ b/packages/cultmath/THIRD-PARTY-NOTICES.md @@ -19,3 +19,18 @@ permutation and scale as `snoise(float3)`. - Copyright 2011 Ashima Arts. - Upstream: - License: MIT. + +## Phacelle Noise + +`math.phacelle` and `cultmath_phacelle` follow Rune Skovbo Johansen's Phacelle +noise (Shadertoy `t3dyWl`; erosion filter `wXcfWn`; blog, March 2026), read +from the C# port `PhacelleNoise` in `lpmitchell/AdvancedTerrainErosion` +(`AdvancedTerrainErosion.cs`, converted to burstable C# by Luke Mitchell, +2026). The cell weight, the phase blend and the normalization follow it. The +3D-cell generalisation, the caller-supplied stripe wave vector, the exact +gradient and the exact pruning are new here. + +- Copyright (c) 2025 Rune Skovbo Johansen. +- Upstream: +- License: MPL-2.0 (). CultMath's Unity package + is MPL-2.0, so the licence is compatible. diff --git a/packages/cultmath/docs/design.md b/packages/cultmath/docs/design.md index e14927fe..0858ee8c 100644 --- a/packages/cultmath/docs/design.md +++ b/packages/cultmath/docs/design.md @@ -128,8 +128,8 @@ whose HLSL return type is a plain struct of `float`/`floatN`/`int`/`intN` fields is compared to its C# counterpart field by field, recursing into each field's own components, down to bit-for-bit scalars, matching each leaf's declaration path (field names, not just position) and declared type as well -as its value. `CultCellular` (`math.cs`, `cellular`) is the first and, for -now, only consumer. A struct return with a mismatched, reordered-by-name, or +as its value. `CultCellular` (`math.cs`, `cellular`) and `CultPhasor` +(`math.cs`, `phacelle`) are its consumers. A struct return with a mismatched, reordered-by-name, or retyped field does not get a second comparison path or a shape of its own; it fails the same walk that already handles a bare vector return. @@ -264,6 +264,25 @@ together, laid out as `float4(gradient.xyz, value.w)`, with no value-only twin which is the right domain for `pcg3d`/`pcg4d`'s O(1) hash inputs but would turn an unclamped octave count into a multi-billion-iteration loop for these two mirrors. +- `phacelle(float3 p, float3 side, float offset, float normalization)` is Rune + Skovbo Johansen's Phacelle noise ("phase + cell": a stripe pattern built by + blending one cosine/sine wave per jittered cell), generalised to 3D cells. It + returns `CultPhasor { cos, sin }`, each `(∇, value)`. `side` is the stripe + wave vector, whose length is 2π times the stripe frequency; in 3D the + perpendicular to the flow is not unique, so the caller chooses it (on a unit + sphere, `cross(p̂, flow)`). `offset` is the phase in cycles. It visits 4×4×4 + cells with `pcg3d`-hashed jitter in `[-0.5, 0.5)`, weights each wave by + `max(0, exp(-2d²) - 0.01111)`, and normalizes the blended phasor as upstream + does (length 1 where the raw length is at least `1 - normalization`, scaled + by `1 / (1 - normalization)` below). The gradient is exact, weight + derivatives and normalization included, rather than upstream's + `∇cos ≈ -sin·side`, which ignores the weight gradient. It is discontinuous + where the raw length crosses the normalization threshold and where a cell's + weight leaves its support (distance 1.4998); the value is continuous at both. + Cells whose per-axis lower bound `Σ max(0, |local - g| - 0.5)²` is at least + 2.25 have weight exactly 0 and are skipped, which changes no output bit; + `PhacelleTests` pins that against an internal overload with the prune + disabled. No 2D variant exists; nothing consumes one. Integer hashing uses the PCG hashes from Jarzynski and Olano, "Hash Functions for GPU Rendering" (JCGT 9(3), 2020): `pcg(uint)` is O'Neill's RXS-M-XS 32/32 diff --git a/packages/cultmath/unity/org.gamecult.cultmath/THIRD-PARTY-NOTICES.md b/packages/cultmath/unity/org.gamecult.cultmath/THIRD-PARTY-NOTICES.md index 1de744a7..73f2461a 100644 --- a/packages/cultmath/unity/org.gamecult.cultmath/THIRD-PARTY-NOTICES.md +++ b/packages/cultmath/unity/org.gamecult.cultmath/THIRD-PARTY-NOTICES.md @@ -19,3 +19,18 @@ permutation and scale as `snoise(float3)`. - Copyright 2011 Ashima Arts. - Upstream: - License: MIT. + +## Phacelle Noise + +`math.phacelle` and `cultmath_phacelle` follow Rune Skovbo Johansen's Phacelle +noise (Shadertoy `t3dyWl`; erosion filter `wXcfWn`; blog, March 2026), read +from the C# port `PhacelleNoise` in `lpmitchell/AdvancedTerrainErosion` +(`AdvancedTerrainErosion.cs`, converted to burstable C# by Luke Mitchell, +2026). The cell weight, the phase blend and the normalization follow it. The +3D-cell generalisation, the caller-supplied stripe wave vector, the exact +gradient and the exact pruning are new here. + +- Copyright (c) 2025 Rune Skovbo Johansen. +- Upstream: +- License: MPL-2.0 (). CultMath's Unity package + is MPL-2.0, so the licence is compatible.