|
|
|
|
|
|
return JenkinsHash(v.x ^ JenkinsHash(v.y) ^ JenkinsHash(v.z) ^ JenkinsHash(v.w)); |
|
|
|
} |
|
|
|
|
|
|
|
// Construct a float with half-open range [0:1] using low 23 bits. |
|
|
|
// Construct a float with half-open range [0, 1) using low 23 bits. |
|
|
|
float ConstructFloat(uint m) { |
|
|
|
const uint ieeeMantissa = 0x007FFFFFu; // Binary FP32 mantissa bitmask |
|
|
|
const uint ieeeOne = 0x3F800000u; // 1.0 in FP32 IEEE |
|
|
|
float ConstructFloat(int m) { |
|
|
|
const int ieeeMantissa = 0x007FFFFF; // Binary FP32 mantissa bitmask |
|
|
|
const int ieeeOne = 0x3F800000; // 1.0 in FP32 IEEE |
|
|
|
m &= ieeeMantissa; // Keep only mantissa bits (fractional part) |
|
|
|
m |= ieeeOne; // Add fractional part to 1.0 |
|
|
|
m &= ieeeMantissa; // Keep only mantissa bits (fractional part) |
|
|
|
m |= ieeeOne; // Add fractional part to 1.0 |
|
|
|
|
|
|
|
float f = asfloat(m); // Range [1, 2) |
|
|
|
return f - 1; // Range [0, 1) |
|
|
|
} |
|
|
|
float f = asfloat(m); // Range [1:2] |
|
|
|
return f - 1; // Range [0:1] |
|
|
|
float ConstructFloat(uint m) |
|
|
|
{ |
|
|
|
return ConstructFloat(asint(m)); |
|
|
|
// Pseudo-random value in half-open range [0:1]. The distribution is reasonably uniform. |
|
|
|
// Pseudo-random value in half-open range [0, 1). The distribution is reasonably uniform. |
|
|
|
// Ref: https://stackoverflow.com/a/17479300 |
|
|
|
float GenerateHashedRandomFloat(uint x) |
|
|
|
{ |
|
|
|