@@ -35,48 +35,54 @@ void PerspectiveCamera_GeneratePaths(
35
35
// Camera
36
36
GLOBAL Camera const * restrict camera ,
37
37
// Image resolution
38
- int img_width ,
39
- int img_height ,
38
+ int output_width ,
39
+ int output_height ,
40
+ // Pixel domain buffer
41
+ GLOBAL int const * restrict pixel_idx ,
42
+ // Size of pixel domain buffer
43
+ GLOBAL int const * restrict num_pixels ,
40
44
// RNG seed value
41
45
uint rng_seed ,
42
46
// Current frame
43
47
uint frame ,
44
48
// Rays to generate
45
- GLOBAL ray * rays ,
49
+ GLOBAL ray * restrict rays ,
46
50
// RNG data
47
- GLOBAL uint * random ,
51
+ GLOBAL uint * restrict random ,
48
52
GLOBAL uint const * restrict sobolmat ,
49
53
// Path buffer
50
- GLOBAL Path * paths
54
+ GLOBAL Path * restrict paths
51
55
)
52
56
{
53
- int2 global_id ;
54
- global_id .x = get_global_id (0 );
55
- global_id .y = get_global_id (1 );
57
+ int global_id = get_global_id (0 );
56
58
57
59
// Check borders
58
- if (global_id . x < img_width && global_id . y < img_height )
60
+ if (global_id < * num_pixels )
59
61
{
62
+ int idx = pixel_idx [global_id ];
63
+ int y = idx / output_width ;
64
+ int x = idx % output_width ;
65
+
60
66
// Get pointer to ray & path handles
61
- GLOBAL ray * my_ray = rays + global_id . y * img_width + global_id . x ;
62
- GLOBAL Path * my_path = paths + global_id . y * img_width + global_id . x ;
67
+ GLOBAL ray * my_ray = rays + global_id ;
68
+ GLOBAL Path * my_path = paths + y * output_width + x ;
63
69
64
70
// Initialize sampler
65
71
Sampler sampler ;
66
72
#if SAMPLER == SOBOL
67
- uint scramble = random [global_id . x + img_width * global_id . y ] * 0x1fe3434f ;
73
+ uint scramble = random [x + output_width * y ] * 0x1fe3434f ;
68
74
69
75
if (frame & 0xF )
70
76
{
71
- random [global_id . x + img_width * global_id . y ] = WangHash (scramble );
77
+ random [x + output_width * y ] = WangHash (scramble );
72
78
}
73
79
74
80
Sampler_Init (& sampler , frame , SAMPLE_DIM_CAMERA_OFFSET , scramble );
75
81
#elif SAMPLER == RANDOM
76
- uint scramble = global_id . x + img_width * global_id . y * rng_seed ;
82
+ uint scramble = x + output_width * y * rng_seed ;
77
83
Sampler_Init (& sampler , scramble );
78
84
#elif SAMPLER == CMJ
79
- uint rnd = random [global_id . x + img_width * global_id . y ];
85
+ uint rnd = random [x + output_width * y ];
80
86
uint scramble = rnd * 0x1fe3434f * ((frame + 133 * rnd ) / (CMJ_DIM * CMJ_DIM ));
81
87
Sampler_Init (& sampler , frame % (CMJ_DIM * CMJ_DIM ), SAMPLE_DIM_CAMERA_OFFSET , scramble );
82
88
#endif
@@ -86,8 +92,8 @@ void PerspectiveCamera_GeneratePaths(
86
92
87
93
// Calculate [0..1] image plane sample
88
94
float2 img_sample ;
89
- img_sample .x = (float )global_id . x / img_width + sample0 .x / img_width ;
90
- img_sample .y = (float )global_id . y / img_height + sample0 .y / img_height ;
95
+ img_sample .x = (float )x / output_width + sample0 .x / output_width ;
96
+ img_sample .y = (float )y / output_height + sample0 .y / output_height ;
91
97
92
98
// Transform into [-0.5, 0.5]
93
99
float2 h_sample = img_sample - make_float2 (0.5f , 0.5f );
@@ -118,62 +124,69 @@ void PerspectiveCamera_GeneratePaths(
118
124
// Physical camera implemenation.
119
125
// This kernel is being used if aperture > 0.
120
126
KERNEL void PerspectiveCameraDof_GeneratePaths (
121
- // Camera
122
- GLOBAL Camera const * camera ,
123
- // Image resolution
124
- int img_width ,
125
- int img_height ,
126
- // RNG seed value
127
- uint rng_seed ,
128
- // Current frame
129
- uint frame ,
130
- // Rays to generate
131
- GLOBAL ray * rays ,
132
- // RNG data
133
- GLOBAL uint * random ,
134
- GLOBAL uint const * restrict sobolmat ,
135
- GLOBAL Path * paths
127
+ // Camera
128
+ GLOBAL Camera const * restrict camera ,
129
+ // Image resolution
130
+ int output_width ,
131
+ int output_height ,
132
+ // Pixel domain buffer
133
+ GLOBAL int const * restrict pixel_idx ,
134
+ // Size of pixel domain buffer
135
+ GLOBAL int const * restrict num_pixels ,
136
+ // RNG seed value
137
+ uint rng_seed ,
138
+ // Current frame
139
+ uint frame ,
140
+ // Rays to generate
141
+ GLOBAL ray * restrict rays ,
142
+ // RNG data
143
+ GLOBAL uint * restrict random ,
144
+ GLOBAL uint const * restrict sobolmat ,
145
+ // Path buffer
146
+ GLOBAL Path * restrict paths
136
147
)
137
148
{
138
- int2 global_id ;
139
- global_id .x = get_global_id (0 );
140
- global_id .y = get_global_id (1 );
149
+ int global_id = get_global_id (0 );
141
150
142
- // Check borders
143
- if (global_id . x < img_width && global_id . y < img_height )
144
- {
145
- // Get pointer to ray & path handles
146
- GLOBAL ray * my_ray = rays + global_id . y * img_width + global_id . x ;
147
- GLOBAL Path * my_path = paths + global_id . y * img_width + global_id . x ;
151
+ // Check borders
152
+ if (global_id < * num_pixels )
153
+ {
154
+ int idx = pixel_idx [ global_id ];
155
+ int y = idx / output_width ;
156
+ int x = idx % output_width ;
148
157
149
- // Initialize sampler
150
- Sampler sampler ;
158
+ // Get pointer to ray & path handles
159
+ GLOBAL ray * my_ray = rays + global_id ;
160
+ GLOBAL Path * my_path = paths + y * output_width + x ;
161
+
162
+ // Initialize sampler
163
+ Sampler sampler ;
151
164
#if SAMPLER == SOBOL
152
- uint scramble = random [global_id . x + img_width * global_id . y ] * 0x1fe3434f ;
165
+ uint scramble = random [x + output_width * y ] * 0x1fe3434f ;
153
166
154
- if (frame & 0xF )
155
- {
156
- random [global_id . x + img_width * global_id . y ] = WangHash (scramble );
157
- }
167
+ if (frame & 0xF )
168
+ {
169
+ random [x + output_width * y ] = WangHash (scramble );
170
+ }
158
171
159
- Sampler_Init (& sampler , frame , SAMPLE_DIM_CAMERA_OFFSET , scramble );
172
+ Sampler_Init (& sampler , frame , SAMPLE_DIM_CAMERA_OFFSET , scramble );
160
173
#elif SAMPLER == RANDOM
161
- uint scramble = global_id . x + img_width * global_id . y * rng_seed ;
162
- Sampler_Init (& sampler , scramble );
174
+ uint scramble = x + output_width * y * rng_seed ;
175
+ Sampler_Init (& sampler , scramble );
163
176
#elif SAMPLER == CMJ
164
- uint rnd = random [global_id . x + img_width * global_id . y ];
165
- uint scramble = rnd * 0x1fe3434f * ((frame + 133 * rnd ) / (CMJ_DIM * CMJ_DIM ));
166
- Sampler_Init (& sampler , frame % (CMJ_DIM * CMJ_DIM ), SAMPLE_DIM_CAMERA_OFFSET , scramble );
177
+ uint rnd = random [x + output_width * y ];
178
+ uint scramble = rnd * 0x1fe3434f * ((frame + 133 * rnd ) / (CMJ_DIM * CMJ_DIM ));
179
+ Sampler_Init (& sampler , frame % (CMJ_DIM * CMJ_DIM ), SAMPLE_DIM_CAMERA_OFFSET , scramble );
167
180
#endif
168
181
169
182
// Generate pixel and lens samples
170
183
float2 sample0 = Sampler_Sample2D (& sampler , SAMPLER_ARGS );
171
184
float2 sample1 = Sampler_Sample2D (& sampler , SAMPLER_ARGS );
172
185
173
- // Calculate [0..1] image plane sample
174
- float2 img_sample ;
175
- img_sample .x = (float )global_id . x / img_width + sample0 .x / img_width ;
176
- img_sample .y = (float )global_id . y / img_height + sample0 .y / img_height ;
186
+ // Calculate [0..1] image plane sample
187
+ float2 img_sample ;
188
+ img_sample .x = (float )x / output_width + sample0 .x / output_width ;
189
+ img_sample .y = (float )y / output_height + sample0 .y / output_height ;
177
190
178
191
// Transform into [-0.5, 0.5]
179
192
float2 h_sample = img_sample - make_float2 (0.5f , 0.5f );
0 commit comments