Skip to content

Commit e6dd2cb

Browse files
make sample and depth explicit
1 parent 9cec232 commit e6dd2cb

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

examples_tests/42.FragmentShaderPathTracer/common.glsl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ struct ImmutableRay_t
315315
vec3 origin;
316316
float maxT;
317317
vec3 direction;
318-
int typeDepthSampleIx;
318+
bool anyHit;
319319
#if defined(TRIANGLE_METHOD)||defined(RECTANGLE_METHOD)
320320
vec3 normalAtOrigin;
321321
bool wasBSDFAtOrigin;
@@ -355,16 +355,16 @@ bool anyHitProgram(in ImmutableRay_t _immutable)
355355

356356

357357
#define INTERSECTION_ERROR_BOUND_LOG2 (-8.0)
358-
float getTolerance_common(in int depth)
358+
float getTolerance_common(in uint depth)
359359
{
360360
float depthRcp = 1.0/float(depth);
361361
return INTERSECTION_ERROR_BOUND_LOG2;// *depthRcp*depthRcp;
362362
}
363-
float getStartTolerance(in int depth)
363+
float getStartTolerance(in uint depth)
364364
{
365365
return exp2(getTolerance_common(depth));
366366
}
367-
float getEndTolerance(in int depth)
367+
float getEndTolerance(in uint depth)
368368
{
369369
return 1.0-exp2(getTolerance_common(depth)+1.0);
370370
}
@@ -501,7 +501,7 @@ mat2x3 rand3d(in uint protoDimension, in uint _sample, inout nbl_glsl_xoroshiro6
501501
}
502502

503503
bool traceRay(in ImmutableRay_t _immutable, inout MutableRay_t _mutable);
504-
bool closestHitProgram(inout Ray_t ray, inout nbl_glsl_xoroshiro64star_state_t scramble_state);
504+
bool closestHitProgram(in uint depth, in uint _sample, inout Ray_t ray, inout nbl_glsl_xoroshiro64star_state_t scramble_state);
505505

506506
void main()
507507
{
@@ -548,8 +548,7 @@ void main()
548548
// for depth of field we could do another stochastic point-pick
549549
tmp = invMVP*tmp;
550550
ray._immutable.direction = normalize(tmp.xyz/tmp.w-camPos);
551-
552-
ray._immutable.typeDepthSampleIx = bitfieldInsert(i,1,DEPTH_BITS_OFFSET,DEPTH_BITS_COUNT);
551+
ray._immutable.anyHit = false;
553552

554553
#if defined(TRIANGLE_METHOD)||defined(RECTANGLE_METHOD)
555554
ray._immutable.normalAtOrigin = vec3(0.0,0.0,0.0);
@@ -577,7 +576,7 @@ void main()
577576
}
578577
else if (!anyHitType)
579578
{
580-
if (closestHitProgram(ray,scramble_state))
579+
if (closestHitProgram(j,i,ray,scramble_state))
581580
break;
582581
}
583582
}

examples_tests/42.FragmentShaderPathTracer/litBySphere.frag

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
bool traceRay(in ImmutableRay_t _immutable, inout MutableRay_t _mutable)
1414
{
15-
const bool anyHit = bitfieldExtract(_immutable.typeDepthSampleIx,31,1)!=0;
15+
const bool anyHit = _immutable.anyHit;
1616

1717
int objectID = -1;
1818
float intersectionT = _immutable.maxT;
@@ -42,7 +42,7 @@ vec3 nbl_glsl_light_deferred_eval_and_prob(out float pdf, in Sphere sphere, in v
4242
return Light_getRadiance(light);
4343
}
4444

45-
nbl_glsl_LightSample nbl_glsl_light_generate_and_remainder_and_pdf(out vec3 remainder, out float pdf, out float newRayMaxT, in vec3 origin, in nbl_glsl_AnisotropicViewSurfaceInteraction interaction, in vec3 u, in int depth)
45+
nbl_glsl_LightSample nbl_glsl_light_generate_and_remainder_and_pdf(out vec3 remainder, out float pdf, out float newRayMaxT, in vec3 origin, in nbl_glsl_AnisotropicViewSurfaceInteraction interaction, in vec3 u, in uint depth)
4646
{
4747
// normally we'd pick from set of lights, using `u.z`
4848
const Light light = lights[0];
@@ -82,7 +82,7 @@ nbl_glsl_LightSample nbl_glsl_light_generate_and_remainder_and_pdf(out vec3 rema
8282
}
8383

8484

85-
bool closestHitProgram(inout Ray_t ray, inout nbl_glsl_xoroshiro64star_state_t scramble_state)
85+
bool closestHitProgram(in uint depth, in uint _sample, inout Ray_t ray, inout nbl_glsl_xoroshiro64star_state_t scramble_state)
8686
{
8787
const MutableRay_t _mutable = ray._mutable;
8888

@@ -114,9 +114,6 @@ bool closestHitProgram(inout Ray_t ray, inout nbl_glsl_xoroshiro64star_state_t s
114114
vec3 lightVal = nbl_glsl_light_deferred_eval_and_prob(lightPdf,sphere,ray._immutable.origin,interaction,lights[lightID]);
115115
ray._payload.accumulation += throughput*lightVal/(1.0+lightPdf*lightPdf*ray._payload.otherTechniqueHeuristic);
116116
}
117-
118-
const int sampleIx = bitfieldExtract(ray._immutable.typeDepthSampleIx,0,DEPTH_BITS_OFFSET);
119-
const int depth = bitfieldExtract(ray._immutable.typeDepthSampleIx,DEPTH_BITS_OFFSET,DEPTH_BITS_COUNT);
120117

121118
// check if we even have a BSDF at all
122119
uint bsdfID = bitfieldExtract(bsdfLightIDs,0,16);
@@ -138,7 +135,7 @@ bool closestHitProgram(inout Ray_t ray, inout nbl_glsl_xoroshiro64star_state_t s
138135

139136

140137
const float bsdfGeneratorProbability = BSDFNode_getMISWeight(bsdf);
141-
mat2x3 epsilon = rand3d(depth,sampleIx,scramble_state);
138+
mat2x3 epsilon = rand3d(depth,_sample,scramble_state);
142139

143140
float rcpChoiceProb;
144141
const bool doNEE = nbl_glsl_partitionRandVariable(bsdfGeneratorProbability,epsilon[0].z,rcpChoiceProb);
@@ -202,7 +199,7 @@ bool closestHitProgram(inout Ray_t ray, inout nbl_glsl_xoroshiro64star_state_t s
202199
ray._immutable.origin = intersection+_sample.L*(doNEE ? maxT:1.0/*kSceneSize*/)*getStartTolerance(depth);
203200
ray._immutable.maxT = maxT;
204201
ray._immutable.direction = _sample.L;
205-
ray._immutable.typeDepthSampleIx = bitfieldInsert(sampleIx,depth+2,DEPTH_BITS_OFFSET,DEPTH_BITS_COUNT)|(doNEE ? ANY_HIT_FLAG:0);
202+
ray._immutable.anyHit = doNEE;
206203
return false;
207204
}
208205
}

0 commit comments

Comments
 (0)