@@ -265,32 +265,37 @@ struct Unidirectional
265265 // #endif
266266 }
267267
268+ measure_type getSingleSampleMeasure (uint32_t sampleID, uint32_t depth, NBL_CONST_REF_ARG (scene_type) scene)
269+ {
270+ vector3_type uvw = rand3d (0u, sampleID, randGen.rng ()); // TODO: take from scramblebuf?
271+ ray_type ray = rayGen.generate (uvw);
272+
273+ // bounces
274+ bool hit = true ;
275+ bool rayAlive = true ;
276+ for (int d = 1 ; (d <= depth) && hit && rayAlive; d += 2 )
277+ {
278+ ray.intersectionT = numeric_limits<scalar_type>::max ;
279+ ray.objectID = intersector_type::traceRay (ray, scene);
280+
281+ hit = ray.objectID.id != -1 ;
282+ if (hit)
283+ rayAlive = closestHitProgram (1 , sampleID, ray, scene);
284+ }
285+ if (!hit)
286+ missProgram (ray);
287+
288+ return ray.payload.accumulation;
289+ }
290+
268291 // Li
269292 measure_type getMeasure (uint32_t numSamples, uint32_t depth, NBL_CONST_REF_ARG (scene_type) scene)
270293 {
271294 measure_type Li = (measure_type)0.0 ;
272295 scalar_type meanLumaSq = 0.0 ;
273296 for (uint32_t i = 0 ; i < numSamples; i++)
274297 {
275- vector3_type uvw = rand3d (0u, i, randGen.rng ()); // TODO: take from scramblebuf?
276- ray_type ray = rayGen.generate (uvw);
277-
278- // bounces
279- bool hit = true ;
280- bool rayAlive = true ;
281- for (int d = 1 ; (d <= depth) && hit && rayAlive; d += 2 )
282- {
283- ray.intersectionT = numeric_limits<scalar_type>::max ;
284- ray.objectID = intersector_type::traceRay (ray, scene);
285-
286- hit = ray.objectID.id != -1 ;
287- if (hit)
288- rayAlive = closestHitProgram (1 , i, ray, scene);
289- }
290- if (!hit)
291- missProgram (ray);
292-
293- measure_type accumulation = ray.payload.accumulation;
298+ measure_type accumulation = getSingleSampleMeasure (i, depth, scene);
294299 scalar_type rcpSampleSize = 1.0 / (i + 1 );
295300 Li += (accumulation - Li) * rcpSampleSize;
296301
@@ -302,6 +307,22 @@ struct Unidirectional
302307 return Li;
303308 }
304309
310+ void generateCascades (int32_t2 coords, uint32_t numSamples, uint32_t depth, NBL_CONST_REF_ARG (scene_type) scene)
311+ {
312+ measure_type Li = (measure_type)0.0 ;
313+ scalar_type meanLumaSq = 0.0 ;
314+ for (uint32_t i = 0 ; i < numSamples; i++)
315+ {
316+ measure_type accumulation = getSingleSampleMeasure (i, depth, scene);
317+ scalar_type rcpSampleSize = 1.0 / (i + 1 );
318+ Li += (accumulation - Li) * rcpSampleSize;
319+ }
320+
321+ cascade[uint3 (coords.x, coords.y, 0 )] = float4 (Li.r, 0.0f , 0.0f , 0.0f );
322+ cascade[uint3 (coords.x, coords.y, 1 )] = float4 (0.0f , Li.g, 0.0f , 0.0f );
323+ cascade[uint3 (coords.x, coords.y, 2 )] = float4 (0.0f , 0.0f , Li.b, 0.0f );
324+ }
325+
305326 NBL_CONSTEXPR_STATIC_INLINE uint32_t MAX_DEPTH_LOG2 = 4u;
306327 NBL_CONSTEXPR_STATIC_INLINE uint32_t MAX_SAMPLES_LOG2 = 10u;
307328
0 commit comments