Class
- Namespace
- CoreFramework.Random
[BurstCompile]
public static class HashBasedNoiseUtils
- Inheritance
-
object
Fields
ChaChaPrime1
A constant representing the hexadecimal value 0x61707865 (“expa”), derived from the standard ChaCha block constants. Used as a prime value in hash-based noise generation and ChaCha operations.
public const uint ChaChaPrime1 = 1634760805
Field Value
- uint
ChaChaPrime1Ul
A constant 64-bit unsigned integer used as one of the ChaCha cryptographic primes. Represents the hexadecimal value 0x6170786561707865UL.
public const ulong ChaChaPrime1Ul = 7021244195892394085
Field Value
- ulong
ChaChaPrime2
A prime constant derived from ChaCha block constants, used in ChaCha-based algorithms for noise generation and hashing operations.
public const uint ChaChaPrime2 = 857760878
Field Value
- uint
ChaChaPrime2Ul
A constant 64-bit prime value used in ChaCha-based hash and noise computations.
public const ulong ChaChaPrime2Ul = 3684054920645862510
Field Value
- ulong
ChaChaPrime3
A predefined prime constant used in ChaCha-based number manipulation algorithms. Represents the hexadecimal value 0x79622D32 (interpreted as “2-by”).
public const uint ChaChaPrime3 = 2036477234
Field Value
- uint
ChaChaPrime3Ul
A constant used as a part of ChaCha-inspired hashing operations in the form of a 64-bit unsigned integer. The value is derived from the string “2-by2-by”.
public const ulong ChaChaPrime3Ul = 8746603121115016498
Field Value
- ulong
ChaChaPrime4
A predefined constant used in ChaCha-based noise generation operations. Represents the hexadecimal value 0x6B206574.
public const uint ChaChaPrime4 = 1797285236
Field Value
- uint
ChaChaPrime4Ul
A constant prime value used in ChaCha-based noise generation algorithms.
public const ulong ChaChaPrime4Ul = 7719281312000927092
Field Value
- ulong
DerivEps
A small incremental value used for numerical derivation calculations within hashing-based noise utilities.
private const float DerivEps = 0.001
Field Value
- float
GoldenRatio
A constant value derived from the mathematical golden ratio, used as a mixing constant in hash-based noise functions.
public const uint GoldenRatio = 2654435769
Field Value
- uint
GoldenRatioUl
A constant representing the golden ratio in unsigned 64-bit format, commonly used for hashing and noise generation calculations.
public const ulong GoldenRatioUl = 11400714819323198485
Field Value
- ulong
InvUintMax
The reciprocal of the maximum value for a 32-bit unsigned integer, used for normalization.
private const float InvUintMax = 2.3283064E-10
Field Value
- float
MurmurHash3Final1
A constant used as a final mixing value in MurmurHash3 algorithm computations.
public const uint MurmurHash3Final1 = 2246822507
Field Value
- uint
MurmurHash3Final1Ul
A constant value used in the finalization step of the MurmurHash3 hash algorithm.
public const ulong MurmurHash3Final1Ul = 9650029242287828579
Field Value
- ulong
MurmurHash3Final2
A constant used in the final mixing step of the MurmurHash3 algorithm.
public const uint MurmurHash3Final2 = 3266489909
Field Value
- uint
MurmurHash3Final2Ul
A constant value used as part of the MurmurHash3 finalization steps.
public const ulong MurmurHash3Final2Ul = 14029467366897019727
Field Value
- ulong
Prime1
A large prime number with non-boring bits used as a constant in hash-based noise calculations.
public const int Prime1 = 198491317
Field Value
- int
Prime1Ul
A 64-bit prime constant used in xxHash64 and related hashing techniques for ensuring good entropy.
public const ulong Prime1Ul = 15485907386658061715
Field Value
- ulong
Prime2
A large prime number with well-distributed bits, used in various noise generation algorithms for hashing and position computations.
public const int Prime2 = 6542989
Field Value
- int
Prime2Ul
A constant 64-bit prime number used for hashing in noise generation algorithms, particularly in MurmurHash3 and xxHash implementations.
public const ulong Prime2Ul = 14029467366897019727
Field Value
- ulong
Prime3
A large prime number used for noise generation algorithms with well-distributed bits.
public const int Prime3 = 357239
Field Value
- int
Prime3Ul
A 64-bit prime constant used in hash-based noise calculations. Combines characteristics of the golden ratio and irregular prime to improve distribution.
public const ulong Prime3Ul = 1609587929392839161
Field Value
- ulong
SimplexF2
Constant value defined as (√3 - 1) / 2, used as a skew factor in the 2D Simplex noise algorithm.
public static readonly float SimplexF2
Field Value
- float
SimplexF3
A constant used in 3D Simplex Noise calculations for skewing coordinates.
public const float SimplexF3 = 0.33333334
Field Value
- float
SimplexG2
The unskewing factor used in 2D Simplex noise calculations. This constant is derived as (3 - √3) / 6 and helps transform simplex grid coordinates back to Euclidean space.
public static readonly float SimplexG2
Field Value
- float
SimplexG3
The unskew factor for 3D Simplex noise, used in the conversion process between space coordinates and skewed simplex grid coordinates.
public const float SimplexG3 = 0.16666667
Field Value
- float
Methods
AmplitudeSum(int, float, float)
Max possible sum for geometric series of amplitudes with ‘gain’. Useful to remap fBm-like outputs back to [-1,1] or [0,1] ranges.
internal static float AmplitudeSum(int octaves, float amplitude, float gain)
Parameters
octaves
intamplitude
floatgain
float
Returns
- float
CellularDistance2(float2, CellularDistance)
private static float CellularDistance2(float2 d, HashBasedNoiseUtils.CellularDistance metric)
Parameters
d
float2metric
HashBasedNoiseUtils.CellularDistance
Returns
- float
CellularDistance3(float3, CellularDistance)
private static float CellularDistance3(float3 d, HashBasedNoiseUtils.CellularDistance metric)
Parameters
d
float3metric
HashBasedNoiseUtils.CellularDistance
Returns
- float
CellularVein01(in Cellular2DResult, float)
Vein/edge intensity from a Cellular result, normalized to [0,1]. Uses 1 - saturate((F2 - F1) / edgeWidth) so the value is bright near borders.
public static float CellularVein01(in HashBasedNoiseUtils.Cellular2DResult r, float edgeWidth = 0.1)
Parameters
r
HashBasedNoiseUtils.Cellular2DResultedgeWidth
float
Returns
- float
CellularVein01(in Cellular3DResult, float)
Vein/edge intensity from a Cellular result, normalized to [0,1] (3D overload).
public static float CellularVein01(in HashBasedNoiseUtils.Cellular3DResult r, float edgeWidth = 0.12)
Parameters
r
HashBasedNoiseUtils.Cellular3DResultedgeWidth
float
Returns
- float
CellularVeinExp01(in Cellular2DResult, float)
Exponential edge falloff for veins. Higher k produces thinner, sharper lines. Output in [0,1].
public static float CellularVeinExp01(in HashBasedNoiseUtils.Cellular2DResult r, float k = 8)
Parameters
r
HashBasedNoiseUtils.Cellular2DResultk
float
Returns
- float
CellularVeinExp01(in Cellular3DResult, float)
Exponential edge falloff (3D overload). Output in [0,1].
public static float CellularVeinExp01(in HashBasedNoiseUtils.Cellular3DResult r, float k = 8)
Parameters
r
HashBasedNoiseUtils.Cellular3DResultk
float
Returns
- float
ChaCha20Setup()
Configures the initial state for the ChaCha20 cryptographic algorithm, preparing it for operations.
internal static void ChaCha20Setup()
ChaChaQuarterAdvanced(ulong, ulong)
Generates a pseudo-random 64-bit unsigned integer using a modified ChaCha quarter round process.
internal static ulong ChaChaQuarterAdvanced(ulong index, ulong seed)
Parameters
index
ulongThe index used in the ChaCha quarter round algorithm.
seed
ulongThe seed value used to introduce randomness to the algorithm.
Returns
- ulong
A pseudo-random 64-bit unsigned integer derived from the input index and seed.
ChaChaQuarterRound(ref uint, ref uint, ref uint, ref uint)
Performs a ChaCha quarter round operation on the provided input values.
internal static void ChaChaQuarterRound(ref uint prime, ref uint key1, ref uint key2, ref uint input)
Parameters
prime
uintA reference to the prime value used in the operation.
key1
uintA reference to the first key used in the operation.
key2
uintA reference to the second key used in the operation.
input
uintA reference to the input value that will be modified during the operation.
ChaChaQuarterRound(ref ulong, ref ulong, ref ulong, ref ulong)
Performs a single ChaCha quarter round operation on the provided prime, keys, and input values.
internal static void ChaChaQuarterRound(ref ulong prime, ref ulong key1, ref ulong key2, ref ulong input)
Parameters
prime
ulongReference to the prime value to be modified during the operation.
key1
ulongReference to the first key value to be modified during the operation.
key2
ulongReference to the second key value to be modified during the operation.
input
ulongReference to the input value to be modified during the operation.
ChaChaQuarterRoundAdvanced(uint, uint)
Computes a processed 32-bit unsigned integer based on the ChaCha quarter-round algorithm, enhanced with additional mixing patterns, using the given index and seed as inputs.
internal static uint ChaChaQuarterRoundAdvanced(uint index, uint seed)
Parameters
index
uintThe input index value used for computation.
seed
uintThe seed value used to add variability to the computation.
Returns
- uint
A 32-bit unsigned integer resulting from the advanced ChaCha quarter-round computation.
ChaChaQuarterRoundSimple(uint, uint)
Performs a simplified ChaCha quarter-round operation on the given index and seed values.
internal static uint ChaChaQuarterRoundSimple(uint index, uint seed)
Parameters
index
uintThe index value used in the calculation, typically representing a noise coordinate.
seed
uintA seed value used to add variability to the computation.
Returns
- uint
A 32-bit unsigned integer result derived from the ChaCha quarter-round process.
ChaChaQuarterRoundSimple(ulong, ulong)
Performs a simplified ChaCha quarter round operation on the provided index and seed values. Uses predefined constants and bitwise operations to generate a transformed 64-bit value.
internal static ulong ChaChaQuarterRoundSimple(ulong index, ulong seed)
Parameters
index
ulongThe 64-bit index value used in the transformation.
seed
ulongThe 64-bit seed value used as an additional input for the transformation.
Returns
- ulong
A 64-bit unsigned integer result produced by the simplified ChaCha quarter round operation.
Fade(float)
Applies a smoothing function to a value to produce a smooth transition in the range [0, 1]. Perlin's quintic fade curve: 6t5 - 15t4 + 10t^3.
public static float Fade(float t)
Parameters
t
floatFractional coordinate in the range [0, 1].
Returns
- float
Smoothed value in the range [0, 1].
FadeDeriv(float)
Derivative of Perlin's quintic fade: 30t4 − 60t3 + 30t^2.
public static float FadeDeriv(float t)
Parameters
t
float
Returns
- float
Grad2(uint, float, float)
Computes a 2D gradient value based on a corner hash and local offsets.
private static float Grad2(uint hash, float dx, float dy)
Parameters
hash
uintHash for the corner (low bits used).
dx
floatLocal x offset from the corner.
dy
floatLocal y offset from the corner.
Returns
- float
Calculated gradient value.
Grad2Vec(uint)
Returns a 2D gradient unit-ish vector based on low bits of hash
.
internal static float2 Grad2Vec(uint hash)
Parameters
hash
uint
Returns
Grad3(uint, float, float, float)
Computes a gradient value based on the hash and the given offsets.
private static float Grad3(uint hash, float dx, float dy, float dz)
Parameters
hash
uintHash value used to determine the gradient vector.
dx
floatOffset along the x-axis from the corner.
dy
floatOffset along the y-axis from the corner.
dz
floatOffset along the z-axis from the corner.
Returns
- float
The dot product of the gradient vector and the offset vector.
Grad3Vec(uint)
Returns a 3D gradient vector from 12 canonical directions.
internal static float3 Grad3Vec(uint hash)
Parameters
hash
uint
Returns
MangledBitsBalancedMix(uint, uint)
Generates a hashed value for the given index and seed using a balanced mix approach.
internal static uint MangledBitsBalancedMix(uint index, uint seed)
Parameters
index
uintThe input index used for hashing.
seed
uintThe seed value to influence the hash generation.
Returns
- uint
A hashed unsigned integer value derived from the input index and seed.
MangledBitsBalancedMix(ulong, ulong)
Applies a balanced mixing strategy to mangle the provided index and seed using bitwise operations and multiplication with predefined constants for generating a pseudorandom value.
internal static ulong MangledBitsBalancedMix(ulong index, ulong seed)
Parameters
index
ulongThe input index to be mangled.
seed
ulongThe seed value used for mixing with the index.
Returns
- ulong
A mangled 64-bit unsigned integer value derived from the index and seed.
MangledBitsRotational(uint, uint)
Generates a pseudo-random value by applying rotational manipulations to the index and seed.
internal static uint MangledBitsRotational(uint index, uint seed)
Parameters
index
uintThe input index for generating the pseudo-random value.
seed
uintThe seed value used to influence the randomness of the output.
Returns
- uint
A pseudo-random 32-bit unsigned integer value derived from the input index and seed.
MangledBitsRotational(ulong, ulong)
Generates a 64-bit hash value using a rotational mixing and mangling approach.
internal static ulong MangledBitsRotational(ulong index, ulong seed)
Parameters
index
ulongThe input index used as part of the hash calculation.
seed
ulongThe seed value used to randomize the result.
Returns
- ulong
A 64-bit hash value derived from the index and seed using rotational bit manipulation and mixing.
MangledBitsShiftXOR(uint, uint)
Generates a deterministically “mangled” unsigned integer value by applying a series of bitwise operations and transformations.
internal static uint MangledBitsShiftXOR(uint index, uint seed)
Parameters
index
uintThe input index value used for generating the mangled result.
seed
uintThe seed value used to introduce variability to the generated result.
Returns
- uint
An unsigned integer that is the result of the mangling operations.
MangledBitsShiftXOR(ulong, ulong)
Computes a pseudo-randomized 64-bit unsigned integer using bitwise mangling operations on the input index and seed values.
internal static ulong MangledBitsShiftXOR(ulong index, ulong seed)
Parameters
index
ulongThe input index value to be used for the calculation.
seed
ulongThe seed value used to introduce variability in the calculation.
Returns
- ulong
A pseudo-randomized 64-bit unsigned integer derived from the input index and seed.
MaxCellularF1_2D(CellularDistance, float)
private static float MaxCellularF1_2D(HashBasedNoiseUtils.CellularDistance metric, float jitter)
Parameters
metric
HashBasedNoiseUtils.CellularDistancejitter
float
Returns
- float
MaxCellularF1_3D(CellularDistance, float)
private static float MaxCellularF1_3D(HashBasedNoiseUtils.CellularDistance metric, float jitter)
Parameters
metric
HashBasedNoiseUtils.CellularDistancejitter
float
Returns
- float
MixOctave(uint, int)
Mix a 32-bit seed with an octave index.
internal static uint MixOctave(uint seed, int octave)
Parameters
seed
uintoctave
int
Returns
- uint
MixOctave(ulong, int)
Mix a 64-bit seed with an octave index.
internal static ulong MixOctave(ulong seed, int octave)
Parameters
seed
ulongoctave
int
Returns
- ulong
NormalizeF101(in Cellular2DResult, CellularDistance, float)
Normalizes F1 to [0,1] using a conservative metric/jitter bound (2D).
0 near feature sites, 1 at farthest plausible locations given jitter
.
public static float NormalizeF101(in HashBasedNoiseUtils.Cellular2DResult r, HashBasedNoiseUtils.CellularDistance metric, float jitter)
Parameters
r
HashBasedNoiseUtils.Cellular2DResultmetric
HashBasedNoiseUtils.CellularDistancejitter
float
Returns
- float
NormalizeF101(in Cellular3DResult, CellularDistance, float)
Normalizes F1 to [0,1] using a conservative metric/jitter bound (3D).
public static float NormalizeF101(in HashBasedNoiseUtils.Cellular3DResult r, HashBasedNoiseUtils.CellularDistance metric, float jitter)
Parameters
r
HashBasedNoiseUtils.Cellular3DResultmetric
HashBasedNoiseUtils.CellularDistancejitter
float
Returns
- float
NormalizeF1Inv01(in Cellular2DResult, CellularDistance, float)
Convenience: inverted normalized F1 (soft “blob” mask) in [0,1]. 1 near sites, 0 far from sites.
public static float NormalizeF1Inv01(in HashBasedNoiseUtils.Cellular2DResult r, HashBasedNoiseUtils.CellularDistance metric, float jitter)
Parameters
r
HashBasedNoiseUtils.Cellular2DResultmetric
HashBasedNoiseUtils.CellularDistancejitter
float
Returns
- float
NormalizeF1Inv01(in Cellular3DResult, CellularDistance, float)
3D overload of
public static float NormalizeF1Inv01(in HashBasedNoiseUtils.Cellular3DResult r, HashBasedNoiseUtils.CellularDistance metric, float jitter)
Parameters
r
HashBasedNoiseUtils.Cellular3DResultmetric
HashBasedNoiseUtils.CellularDistancejitter
float
Returns
- float
Perlin(float, float, float, uint, uint, uint, uint, uint, uint, uint, uint)
Generates a 3D Perlin noise value based on hashed gradient coordinates and fractional positions.
internal static float Perlin(float xf, float yf, float zf, uint h000, uint h100, uint h010, uint h110, uint h001, uint h101, uint h011, uint h111)
Parameters
xf
floatFractional x-coordinate in the range [0,1].
yf
floatFractional y-coordinate in the range [0,1].
zf
floatFractional z-coordinate in the range [0,1].
h000
uintHash value for the gradient at the (0, 0, 0) corner of the unit cube.
h100
uintHash value for the gradient at the (1, 0, 0) corner of the unit cube.
h010
uintHash value for the gradient at the (0, 1, 0) corner of the unit cube.
h110
uintHash value for the gradient at the (1, 1, 0) corner of the unit cube.
h001
uintHash value for the gradient at the (0, 0, 1) corner of the unit cube.
h101
uintHash value for the gradient at the (1, 0, 1) corner of the unit cube.
h011
uintHash value for the gradient at the (0, 1, 1) corner of the unit cube.
h111
uintHash value for the gradient at the (1, 1, 1) corner of the unit cube.
Returns
- float
A smooth noise value in the range [-1,1].
Perlin(float, float, uint, uint, uint, uint)
Corner‑hash driven Perlin 2D. Callers pass the four corner hashes and the local fractional offsets inside the cell. This keeps the only 32 vs 64 difference (how you generate the corner IDs) out of the core.
internal static float Perlin(float xf, float yf, uint h00, uint h10, uint h01, uint h11)
Parameters
xf
floatFractional x in [0,1) relative to the cell’s lower corner.
yf
floatFractional y in [0,1) relative to the cell’s lower corner.
h00
uintHash at (0,0) corner.
h10
uintHash at (1,0) corner.
h01
uintHash at (0,1) corner.
h11
uintHash at (1,1) corner.
Returns
- float
Smooth 2D noise value in [-1,1].
PerlinWithDeriv(float, float, float, uint, uint, uint, uint, uint, uint, uint, uint, out float3)
Corner-hash Perlin 3D with analytic gradient. Inputs are fractional coords and eight corner hashes.
internal static float PerlinWithDeriv(float xf, float yf, float zf, uint h000, uint h100, uint h010, uint h110, uint h001, uint h101, uint h011, uint h111, out float3 d)
Parameters
xf
floatyf
floatzf
floath000
uinth100
uinth010
uinth110
uinth001
uinth101
uinth011
uinth111
uintd
float3
Returns
- float
PerlinWithDeriv(float, float, uint, uint, uint, uint, out float2)
Corner-hash Perlin 2D with analytic gradient. Inputs are fractional coords (0..1) inside cell and the four corner hashes.
internal static float PerlinWithDeriv(float xf, float yf, uint h00, uint h10, uint h01, uint h11, out float2 d)
Parameters
xf
floatyf
floath00
uinth10
uinth01
uinth11
uintd
float2
Returns
- float
RotateLeft(uint, int)
Rotates the bits of a 32-bit unsigned integer to the left by a specified offset.
public static uint RotateLeft(uint value, int offset)
Parameters
value
uintThe 32-bit unsigned integer whose bits are to be rotated.
offset
intThe number of positions to rotate the bits to the left.
Returns
- uint
The result of the bitwise left rotation.
RotateLeft(ulong, int)
Performs a left rotation of the bits in the given unsigned 32-bit integer value.
public static ulong RotateLeft(ulong value, int offset)
Parameters
value
ulongThe unsigned 32-bit integer value to be rotated.
offset
intThe number of bit positions to rotate left.
Returns
- ulong
The resulting value after performing the left rotation.
ToNegOneToOne(uint)
Converts an unsigned integer value to a floating-point value in the range [-1, 1].
public static float ToNegOneToOne(uint value)
Parameters
value
uintUnsigned integer value to be converted.
Returns
- float
Floating-point value in the range [-1, 1] derived from the input.
ToZeroToOne(uint)
Converts an unsigned integer value to a floating-point value in the range [0, 1].
public static float ToZeroToOne(uint value)
Parameters
value
uintUnsigned integer value to be converted.
Returns
- float
Floating-point value in the range [0, 1] derived from the input.