Every Unity.Mathematics using, alias and qualified name under Assets\Scripts and tools now names CultMath. The nine `using static ...noise;` lines are gone: snoise lives on CultMath's math. UnityExtensions loses float4.ToColor and Color.ToFloat4, which duplicate the bridge's ToColor and ToCultMath; the float3 colour pair stays because the bridge has none. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
28 lines
630 B
C#
28 lines
630 B
C#
using CultMath;
|
|
using static CultMath.math;
|
|
|
|
public static class Noise1D
|
|
{
|
|
private const float HASHSCALE = 0.1031f;
|
|
|
|
static float hash(float p)
|
|
{
|
|
float3 p3 = frac(float3(p) * HASHSCALE);
|
|
p3 += dot(p3, p3.yzx + 19.19f);
|
|
return frac((p3.x + p3.y) * p3.z);
|
|
}
|
|
|
|
static float fade(float t) { return t * t * t * (t * (6f* t - 15f) + 10f); }
|
|
|
|
static float grad(float hash, float p)
|
|
{
|
|
int i = (int)(1e4 * hash);
|
|
return (i & 1) == 0 ? p : -p;
|
|
}
|
|
|
|
public static float noise(float p)
|
|
{
|
|
float pi = floor(p), pf = p - pi, w = fade(pf);
|
|
return lerp(grad(hash(pi), pf), grad(hash(pi + 1.0f), pf - 1.0f), w) * 2.0f;
|
|
}
|
|
}
|