This repository has been archived on 2023-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
eruption/src/shader/pathtracing/rand/random.glsl

31 lines
823 B
GLSL

#ifndef __RANDOM_GLSL__
#define __RANDOM_GLSL__
#define _ONE_AT_A_TIME_
//#define _XOSHIRO_
#include "one-at-a-time.glsl"
#include "xoshiro.glsl"
// Construct a float with half-open range [0:1] using low 23 bits.
// All zeroes yields 0.0, all ones yields the next smallest representable value below 1.0.
float floatConstruct(in uint m) {
const uint ieeeMantissa = 0x007FFFFFu; // binary32 mantissa bitmask
const uint ieeeOne = 0x3F800000u; // 1.0 in IEEE binary32
m &= ieeeMantissa; // Keep only mantissa bits (fractional part)
m |= ieeeOne; // Add fractional part to 1.0
return uintBitsToFloat(m) - 1.0;
}
void init_random_state(in float seed) {
INIT_STATE_FUNCTION(seed);
}
float random() {
return floatConstruct(HASH_FUNCTION());
}
#endif