@@ -313,7 +313,6 @@ Light lights[LIGHT_COUNT] =
313
313
struct ImmutableRay_t
314
314
{
315
315
vec3 origin;
316
- float maxT;
317
316
vec3 direction;
318
317
#if defined(TRIANGLE_METHOD)|| defined(RECTANGLE_METHOD)
319
318
vec3 normalAtOrigin;
@@ -375,21 +374,13 @@ void missProgram(in ImmutableRay_t _immutable, inout Payload_t _payload)
375
374
{
376
375
vec3 finalContribution = _payload.throughput;
377
376
// #define USE_ENVMAP
378
- // true miss
379
- if (_immutable.maxT>= FLT_MAX)
380
- {
381
- #ifdef USE_ENVMAP
382
- vec2 uv = SampleSphericalMap(_immutable.direction);
383
- finalContribution *= textureLod(envMap, uv, 0.0 ).rgb;
384
- #else
385
- const vec3 kConstantEnvLightRadiance = vec3 (0.15 , 0.21 , 0.3 );
386
- finalContribution *= kConstantEnvLightRadiance;
387
- #endif
388
- }
389
- else
390
- {
391
- finalContribution *= _payload.otherTechniqueHeuristic;
392
- }
377
+ #ifdef USE_ENVMAP
378
+ vec2 uv = SampleSphericalMap(_immutable.direction);
379
+ finalContribution *= textureLod(envMap, uv, 0.0 ).rgb;
380
+ #else
381
+ const vec3 kConstantEnvLightRadiance = vec3 (0.15 , 0.21 , 0.3 );
382
+ finalContribution *= kConstantEnvLightRadiance;
383
+ #endif
393
384
_payload.accumulation += finalContribution;
394
385
}
395
386
@@ -493,7 +484,7 @@ mat2x3 rand3d(in uint protoDimension, in uint _sample, inout nbl_glsl_xoroshiro6
493
484
return retval;
494
485
}
495
486
496
- void traceRay(in bool anyHit , in ImmutableRay_t _immutable, inout MutableRay_t _mutable );
487
+ int traceRay(inout float intersectionT , in ImmutableRay_t _immutable);
497
488
bool closestHitProgram(in uint depth, in uint _sample, inout Ray_t ray, inout nbl_glsl_xoroshiro64star_state_t scramble_state);
498
489
499
490
void main()
@@ -520,6 +511,7 @@ void main()
520
511
521
512
vec3 color = vec3 (0.0 );
522
513
float meanLumaSquared = 0.0 ;
514
+ // TODO: if we collapse the nested for loop, then all GPUs will get `MAX_DEPTH` factor speedup, not just NV with separate PC
523
515
for (int i= 0 ; i< SAMPLES; i++ )
524
516
{
525
517
nbl_glsl_xoroshiro64star_state_t scramble_state = scramble_start_state;
@@ -528,7 +520,6 @@ void main()
528
520
// raygen
529
521
{
530
522
ray._immutable.origin = camPos;
531
- ray._immutable.maxT = FLT_MAX;
532
523
533
524
vec4 tmp = NDC;
534
525
// apply stochastic reconstruction filter
@@ -555,19 +546,20 @@ void main()
555
546
#endif
556
547
}
557
548
558
- // trace
559
- for (int j= 1 ; j<= MAX_DEPTH; j+= 2 )
549
+ // bounces
560
550
{
561
- const ImmutableRay_t _immutable = ray._immutable;
562
- traceRay(false,_immutable,ray._mutable);
563
-
564
- if (ray._mutable.intersectionT>= _immutable.maxT)
551
+ bool hit = true; bool rayAlive = true;
552
+ for (int d= 1 ; d<= MAX_DEPTH && hit && rayAlive; d+= 2 )
565
553
{
566
- missProgram(_immutable,ray._payload);
567
- break ;
554
+ ray._mutable.intersectionT = FLT_MAX;
555
+ ray._mutable.objectID = traceRay(ray._mutable.intersectionT,ray._immutable);
556
+ hit = ray._mutable.objectID!=-1 ;
557
+ if (hit)
558
+ rayAlive = closestHitProgram(3u, i, ray, scramble_state);
568
559
}
569
- else if (closestHitProgram(j,i,ray,scramble_state))
570
- break ;
560
+ // was last trace a miss?
561
+ if (! hit)
562
+ missProgram(ray._immutable,ray._payload);
571
563
}
572
564
573
565
vec3 accumulation = ray._payload.accumulation;
0 commit comments