@@ -22,15 +22,12 @@ THE SOFTWARE.
22
22
#ifndef CAMERA_CL
23
23
#define CAMERA_CL
24
24
25
+ #include <../App/CL/common.cl>
25
26
#include <../App/CL/payload.cl>
26
- #include <../App/CL/random.cl>
27
27
#include <../App/CL/sampling.cl>
28
28
#include <../App/CL/utils.cl>
29
29
#include <../App/CL/path.cl>
30
30
31
- #define CMJ 1
32
- #define CMJ_DIM 4
33
-
34
31
35
32
/// Ray generation kernel for perspective camera.
36
33
/// Rays are generated from camera position to viewing plane
@@ -43,12 +40,11 @@ __kernel void PerspectiveCamera_GeneratePaths(
43
40
int imgwidth ,
44
41
int imgheight ,
45
42
// RNG seed value
46
- int randseed ,
43
+ uint rngseed ,
47
44
// Output rays
48
45
__global ray * rays ,
49
- __global SobolSampler * samplers ,
46
+ __global uint const * random ,
50
47
__global uint const * sobolmat ,
51
- int reset ,
52
48
int frame
53
49
#ifndef NO_PATH_DATA
54
50
,__global Path * paths
@@ -69,36 +65,22 @@ __kernel void PerspectiveCamera_GeneratePaths(
69
65
__global Path * mypath = paths + globalid .y * imgwidth + globalid .x ;
70
66
#endif
71
67
72
- // Prepare RNG
73
- Rng rng ;
74
- InitRng (randseed + globalid .x * 157 + 10433 * globalid .y , & rng );
75
-
76
- #if SOBOL == 1
77
- __global SobolSampler * sampler = samplers + globalid .y * imgwidth + globalid .x ;
78
-
79
- if (reset )
80
- {
81
- sampler -> seq = 0 ;
82
- sampler -> s0 = RandUint (& rng );
83
- }
84
- else
85
- {
86
- sampler -> seq ++ ;
87
- }
88
-
89
- float2 sample0 ;
90
- sample0 .x = SobolSampler_Sample1D (sampler -> seq , kPixelX , sampler -> s0 , sobolmat );
91
- sample0 .y = SobolSampler_Sample1D (sampler -> seq , kPixelY , sampler -> s0 , sobolmat );
92
- #elif RANDOM == 1
93
- float2 sample0 = UniformSampler_Sample2D (& rng );
94
- #elif CMJ == 1
95
- // Pass defines current current light selection and current material selection
96
- int pass = frame / (CMJ_DIM * CMJ_DIM );
97
- int pattern0 = permute (globalid .y * imgwidth + globalid .x , (1024 * 1024 ), pass * 0xc13719e1 );
98
- int subsample0 = permute (frame % (CMJ_DIM * CMJ_DIM ), CMJ_DIM * CMJ_DIM , pattern0 * 0xc517e953 );
99
- float2 sample0 = cmj (subsample0 , CMJ_DIM , pattern0 );
68
+ Sampler sampler ;
69
+ #if SAMPLER == SOBOL
70
+ uint scramble = random [globalid .x + imgwidth * globalid .y ] * 0x1fe3434f ;
71
+ Sampler_Init (& sampler , frame , SAMPLE_DIM_CAMERA_OFFSET , scramble );
72
+ #elif SAMPLER == RANDOM
73
+ uint scramble = globalid .x + imgwidth * globalid .y * rngseed ;
74
+ Sampler_Init (& sampler , scramble );
75
+ #elif SAMPLER == CMJ
76
+ uint rnd = random [globalid .x + imgwidth * globalid .y ];
77
+ uint scramble = rnd * 0x1fe3434f * ((frame + 133 * rnd ) / (CMJ_DIM * CMJ_DIM ));
78
+ Sampler_Init (& sampler , frame % (CMJ_DIM * CMJ_DIM ), SAMPLE_DIM_CAMERA_OFFSET , scramble );
100
79
#endif
101
80
81
+ // Generate sample
82
+ float2 sample0 = Sampler_Sample2D (& sampler , SAMPLER_ARGS );
83
+
102
84
// Calculate [0..1] image plane sample
103
85
float2 imgsample ;
104
86
imgsample .x = (float )globalid .x / imgwidth + sample0 .x / imgwidth ;
@@ -142,12 +124,12 @@ __kernel void PerspectiveCameraDof_GeneratePaths(
142
124
int imgwidth ,
143
125
int imgheight ,
144
126
// RNG seed value
145
- int randseed ,
127
+ uint rngseed ,
146
128
// Output rays
147
129
__global ray * rays ,
148
- __global SobolSampler * samplers ,
130
+ __global uint * random ,
149
131
__global uint const * sobolmat ,
150
- int reset
132
+ int frame
151
133
#ifndef NO_PATH_DATA
152
134
, __global Path * paths
153
135
#endif
@@ -167,36 +149,24 @@ __kernel void PerspectiveCameraDof_GeneratePaths(
167
149
__global Path * mypath = paths + globalid .y * imgwidth + globalid .x ;
168
150
#endif
169
151
170
- // Prepare RNG
171
- Rng rng ;
172
- InitRng (randseed + globalid .x * 157 + 10433 * globalid .y , & rng );
173
-
174
- //
175
- #ifdef SOBOL
176
- __global SobolSampler * sampler = samplers + globalid .y * imgwidth + globalid .x ;
177
-
178
- if (reset )
179
- {
180
- sampler -> seq = 0 ;
181
- sampler -> s0 = RandUint (& rng );
182
- }
183
- else
184
- {
185
- sampler -> seq ++ ;
186
- }
187
-
188
- float2 sample0 ;
189
- sample0 .x = SobolSampler_Sample1D (sampler -> seq , kPixelX , sampler -> s0 , sobolmat );
190
- sample0 .y = SobolSampler_Sample1D (sampler -> seq , kPixelY , sampler -> s0 , sobolmat );
191
-
192
- float2 sample1 ;
193
- sample1 .x = SobolSampler_Sample1D (sampler -> seq , kLensX , sampler -> s0 , sobolmat );
194
- sample1 .y = SobolSampler_Sample1D (sampler -> seq , kLensY , sampler -> s0 , sobolmat );
195
- #else
196
- float2 sample0 = UniformSampler_Sample2D (& rng );
197
- float2 sample1 = UniformSampler_Sample2D (& rng );
152
+ Sampler sampler ;
153
+ #if SAMPLER == SOBOL
154
+ uint scramble = random [globalid .x + imgwidth * globalid .y ] * 0x1fe3434f ;
155
+ Sampler_Init (& sampler , frame , SAMPLE_DIM_CAMERA_OFFSET , scramble );
156
+ #elif SAMPLER == RANDOM
157
+ uint scramble = globalid .x + imgwidth * globalid .y * rngseed ;
158
+ Sampler_Init (& sampler , scramble );
159
+ #elif SAMPLER == CMJ
160
+ uint rnd = random [globalid .x + imgwidth * globalid .y ];
161
+ uint scramble = rnd * 0x1fe3434f * ((frame + 133 * rnd ) / (CMJ_DIM * CMJ_DIM ));
162
+ Sampler_Init (& sampler , frame % (CMJ_DIM * CMJ_DIM ), SAMPLE_DIM_CAMERA_OFFSET , scramble );
198
163
#endif
199
164
165
+ // Generate pixel and lens samples
166
+ float2 sample0 = Sampler_Sample2D (& sampler , SAMPLER_ARGS );
167
+ float2 sample1 = Sampler_Sample2D (& sampler , SAMPLER_ARGS );
168
+
169
+
200
170
// Calculate [0..1] image plane sample
201
171
float2 imgsample ;
202
172
imgsample .x = (float )globalid .x / imgwidth + sample0 .x / imgwidth ;
0 commit comments