Add smin_grad and cellular value-and-gradient primitives to CultMath
smin_grad(float4,float4,float) carries Inigo Quilez's cubic-polynomial smooth minimum to invariant 8's value-and-gradient form: the gradient blend lerp(b,a,h) is the exact analytic derivative, not an approximation, since the h-derivative terms cancel algebraically inside the smoothing band. cellular(float3) is Worley's cellular texture basis function (SIGGRAPH 1996), searched over the jittered 3x3x3 neighbourhood of pcg3d-selected feature points. It returns the new CultCellular struct (nearest, edge, id), following the repo's existing degenerate-normal convention (GameCult.Geometry.CultGeometryIsoSurface.EmitOrientedTriangle) to return a finite zero gradient instead of NaN at a feature point. Both are fresh implementations from the cited literature, not ports, so they get a design.md/doc-comment citation instead of a THIRD-PARTY-NOTICES entry. design.md gains an "Invariant 8: Value-and-Gradient Primitives" section documenting both primitives' semantics and conventions. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
29e50ad315
commit
1dca43596e
4 changed files with 142 additions and 1 deletions
25
packages/cultmath/src/CultMath/CultCellular.cs
Normal file
25
packages/cultmath/src/CultMath/CultCellular.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
namespace CultMath;
|
||||
|
||||
/// <summary>
|
||||
/// The value-and-gradient result of <see cref="math.cellular(float3)"/> (invariant 8's one struct
|
||||
/// return shape). Every field follows the same <c>float4(gradient.xyz, value.w)</c> layout as a
|
||||
/// bare value-and-gradient return.
|
||||
/// </summary>
|
||||
public struct CultCellular
|
||||
{
|
||||
/// <summary>(∇F1, F1): the gradient and distance to the nearest feature point.</summary>
|
||||
public float4 nearest;
|
||||
|
||||
/// <summary>(∇F2 - ∇F1, F2 - F1): for lineae along cell borders.</summary>
|
||||
public float4 edge;
|
||||
|
||||
/// <summary>The nearest cell's pcg3d hash, mapped to [0, 1).</summary>
|
||||
public float id;
|
||||
|
||||
public CultCellular(float4 nearest, float4 edge, float id)
|
||||
{
|
||||
this.nearest = nearest;
|
||||
this.edge = edge;
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue