29 #include <optixu/optixu_math_namespace.h> 31 template<
unsigned int N>
32 static __host__ __device__ __inline__
unsigned int tea(
unsigned int val0,
unsigned int val1 )
34 unsigned int v0 = val0;
35 unsigned int v1 = val1;
38 for(
unsigned int n = 0; n < N; n++ )
41 v0 += ((v1<<4)+0xa341316c)^(v1+s0)^((v1>>5)+0xc8013ea4);
42 v1 += ((v0<<4)+0xad90777d)^(v0+s0)^((v0>>5)+0x7e95761e);
49 static __host__ __device__ __inline__
unsigned int lcg(
unsigned int &prev)
51 const unsigned int LCG_A = 1664525u;
52 const unsigned int LCG_C = 1013904223u;
53 prev = (LCG_A * prev + LCG_C);
54 return prev & 0x00FFFFFF;
57 static __host__ __device__ __inline__
unsigned int lcg2(
unsigned int &prev)
59 prev = (prev*8121 + 28411) % 134456;
64 static __host__ __device__ __inline__
float rnd(
unsigned int &prev)
66 return ((
float)
lcg(prev) / (
float) 0x01000000);
70 static __host__ __inline__
unsigned int mwc()
72 static unsigned long long r[4];
73 static unsigned long long carry;
74 static bool init =
false;
77 unsigned int seed = 7654321u, seed0, seed1, seed2, seed3;
78 r[0] = seed0 =
lcg2(seed);
79 r[1] = seed1 =
lcg2(seed0);
80 r[2] = seed2 =
lcg2(seed1);
81 r[3] = seed3 =
lcg2(seed2);
85 unsigned long long sum = 2111111111ull * r[3] +
93 r[0] =
static_cast<unsigned int>(sum);
94 carry =
static_cast<unsigned int>(sum >> 32);
95 return static_cast<unsigned int>(r[0]);
98 static __host__ __inline__
unsigned int random1u()
112 static __host__ __inline__
void fillRandBuffer(
unsigned int *seeds,
unsigned int N )
114 for(
unsigned int i=0; i<N; ++i )
118 static __host__ __device__ __inline__
unsigned int rot_seed(
unsigned int seed,
unsigned int frame )
static __host__ __inline__ unsigned int random1u()
static __host__ __device__ __inline__ float rnd(unsigned int &prev)
static __host__ __inline__ unsigned int mwc()
static __host__ __device__ __inline__ unsigned int tea(unsigned int val0, unsigned int val1)
static __host__ __device__ __inline__ unsigned int rot_seed(unsigned int seed, unsigned int frame)
static __host__ __inline__ void fillRandBuffer(unsigned int *seeds, unsigned int N)
static __host__ __device__ __inline__ unsigned int lcg2(unsigned int &prev)
static __host__ __inline__ optix::uint2 random2u()
static __host__ __device__ __inline__ unsigned int lcg(unsigned int &prev)