lib-random.glsl
Public Functions:
getBlueNoiseThreshold
getBlueNoiseThresholdTemporal
fibonacci1D
fibonacci2D
fibonacci2DDitheredTemporal
Import from library
Copied to your clipboardimport lib-defines.glsl
A 2D blue noise texture containing scalar values
Copied to your clipboard//: param auto texture_blue_noiseuniform sampler2D texture_blue_noise;
Blue noise texture resolution
Copied to your clipboardconst ivec2 texture_blue_noise_size = ivec2(256);
Current frame random seed
Copied to your clipboard//: param auto random_seeduniform int alg_random_seed;
Get an uniform random value based on pixel coordinates.
Copied to your clipboardfloat getBlueNoiseThreshold(){return texture(texture_blue_noise, gl_FragCoord.xy / vec2(texture_blue_noise_size)).x + 0.5 / 65536.0;}
Get an uniform random value based on pixel coordinates and frame id.
Copied to your clipboardfloat getBlueNoiseThresholdTemporal(){return fract(getBlueNoiseThreshold() + M_GOLDEN_RATIO * alg_random_seed);}
Return the ith number from fibonacci sequence.
Copied to your clipboardfloat fibonacci1D(int i){return fract((float(i) + 1.0) * M_GOLDEN_RATIO);}
Return the ith couple from the fibonacci sequence. nbSample is required to get an uniform distribution.
Copied to your clipboardvec2 fibonacci2D(int i, int nbSamples){return vec2((float(i)+0.5) / float(nbSamples),fibonacci1D(i));}
Return the ith couple from the fibonacci sequence. nbSample is required to get an uniform distribution. This version has a per frame and per pixel pseudo-random rotation applied.
Copied to your clipboardvec2 fibonacci2DDitheredTemporal(int i, int nbSamples){vec2 s = fibonacci2D(i, nbSamples);s.x += getBlueNoiseThresholdTemporal();return s;}