noise rng maths
This commit is contained in:
parent
de8a2dbe09
commit
2541a6d96c
2 changed files with 122 additions and 3 deletions
121
src/Maths.cs
121
src/Maths.cs
|
|
@ -35,7 +35,10 @@ public static class Maths
|
|||
// public static int roundi(float value) => MathF.Round(value)
|
||||
|
||||
public static float precision(float x, float p)
|
||||
=> round(x * p) / p;
|
||||
{
|
||||
float ps = p < 1.0f ? 1 / p : p;
|
||||
return round(x * ps) / ps;
|
||||
}
|
||||
|
||||
public static float smooth_start(float t) => (t * t * t);
|
||||
public static float smooth_stop(float t)
|
||||
|
|
@ -94,6 +97,122 @@ public static class Maths
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SquirrelNoise5 - Squirrel's Raw Noise utilities (version 5)
|
||||
/// Converted to C# from original C++ implementation by Squirrel Eiserloh
|
||||
/// </summary>
|
||||
public static class Noise
|
||||
{
|
||||
// Bit noise constants
|
||||
private const uint SQ5_BIT_NOISE1 = 0xd2a80a3f;
|
||||
private const uint SQ5_BIT_NOISE2 = 0xa884f197;
|
||||
private const uint SQ5_BIT_NOISE3 = 0x6C736F4B;
|
||||
private const uint SQ5_BIT_NOISE4 = 0xB79F3ABB;
|
||||
private const uint SQ5_BIT_NOISE5 = 0x1b56c4f5;
|
||||
|
||||
// Constants for higher dimensional noise
|
||||
private const int PRIME1 = 198491317;
|
||||
private const int PRIME2 = 6542989;
|
||||
private const int PRIME3 = 357239;
|
||||
|
||||
/// <summary>
|
||||
/// Fast hash of an int32 into a different (unrecognizable) uint32
|
||||
/// </summary>
|
||||
private static uint GetNoise(int positionX, uint seed)
|
||||
{
|
||||