Shaders for Shadows
Shader code for rendering shadows of translucent occluders, soft shadows and single scattering with moment shadow maps.
 All Classes Files Functions Variables Pages
RandomNumbers.fx
Go to the documentation of this file.
1 
10 float GetRandomNumber(uint Seed){
11  // Apply the Wang hash function
12  Seed=(Seed^61)^(Seed>>16);
13  Seed*=9;
14  Seed=Seed^(Seed>>4);
15  Seed*=0x27d4eb2d;
16  Seed=Seed^(Seed>>15);
17  // Go back to a floating point value
18  return Seed*pow(0.5f,32);
19 }
20 
21 
24 float GetRandomNumber(float2 FloatingPointSeed){
25 #if D3D_VERSION==9
26  // Use a cheap linear congruential generator
27  return frac(dot(float2(136212.21236f,230875.1235f),FloatingPointSeed));
28 #elif D3D_VERSION==11
29  // Convert the seed to an integer
30  uint Seed=asuint(FloatingPointSeed[0])^asuint(FloatingPointSeed[1]);
31  return GetRandomNumber(Seed);
32 #endif
33 }
34 
37 float GetRandomNumber(float3 FloatingPointSeed){
38 #if D3D_VERSION==9
39  // Use a cheap linear congruential generator
40  return frac(dot(float3(136212.21236f,230875.1235f,239108.472f),FloatingPointSeed));
41 #elif D3D_VERSION==11
42  // Convert the seed to an integer
43  uint Seed=asuint(FloatingPointSeed[0])^asuint(FloatingPointSeed[1])^asuint(FloatingPointSeed[2]);
44  return GetRandomNumber(Seed);
45 #endif
46 }
47 
50 float GetRandomNumber(float4 FloatingPointSeed){
51 #if D3D_VERSION==9
52  // Use a cheap linear congruential generator
53  return frac(dot(float4(136212.21236f,230875.1235f,239108.472f,489123.434f),FloatingPointSeed));
54 #elif D3D_VERSION==11
55  // Convert the seed to an integer
56  uint Seed=asuint(FloatingPointSeed[0])^asuint(FloatingPointSeed[1])^asuint(FloatingPointSeed[2])^asuint(FloatingPointSeed[3]);
57  return GetRandomNumber(Seed);
58 #endif
59 }
float GetRandomNumber(uint Seed)