Skip to content

Commit 8eaca77

Browse files
committed
Use slightly faster, but not as good, float rand() function.
1 parent 40cea9f commit 8eaca77

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

assets/shaders/Random.glsl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#extension GL_EXT_control_flow_attributes : require
22

33
// Generates a seed for a random number generator from 2 inputs plus a backoff
4-
// https://github.com/nvpro-samples/optix_prime_baking/blob/master/random.h
4+
// https://github.com/nvpro-samples/optix_prime_baking/blob/332a886f1ac46c0b3eea9e89a59593470c755a0e/random.h
5+
// https://github.com/nvpro-samples/vk_raytracing_tutorial_KHR/tree/master/ray_tracing_jitter_cam
56
// https://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm
67
uint InitRandomSeed(uint val0, uint val1)
78
{
@@ -26,10 +27,13 @@ uint RandomInt(inout uint seed)
2627

2728
float RandomFloat(inout uint seed)
2829
{
29-
// Float version using bitmask from Numerical Recipes
30-
const uint one = 0x3f800000;
31-
const uint msk = 0x007fffff;
32-
return uintBitsToFloat(one | (msk & (RandomInt(seed) >> 9))) - 1;
30+
//// Float version using bitmask from Numerical Recipes
31+
//const uint one = 0x3f800000;
32+
//const uint msk = 0x007fffff;
33+
//return uintBitsToFloat(one | (msk & (RandomInt(seed) >> 9))) - 1;
34+
35+
// Faster version from NVIDIA examples; quality good enough for our use case.
36+
return (float(RandomInt(seed) & 0x00FFFFFF) / float(0x01000000));
3337
}
3438

3539
vec2 RandomInUnitDisk(inout uint seed)

0 commit comments

Comments
 (0)