10
10
11
11
12
12
13
- bool traceRay(in ImmutableRay_t _immutable)
13
+ bool traceRay(in ImmutableRay_t _immutable, inout MutableRay_t _mutable )
14
14
{
15
15
const bool anyHit = bitfieldExtract(_immutable.typeDepthSampleIx,31 ,1 )!= 0 ;
16
16
@@ -28,8 +28,8 @@ bool traceRay(in ImmutableRay_t _immutable)
28
28
// if (anyHit && closerIntersection && anyHitProgram(_immutable))
29
29
// break;
30
30
}
31
- rayStack[stackPtr]. _mutable.objectID = objectID;
32
- rayStack[stackPtr]. _mutable.intersectionT = intersectionT;
31
+ _mutable.objectID = objectID;
32
+ _mutable.intersectionT = intersectionT;
33
33
// hit
34
34
return anyHit;
35
35
}
@@ -82,18 +82,18 @@ nbl_glsl_LightSample nbl_glsl_light_generate_and_remainder_and_pdf(out vec3 rema
82
82
}
83
83
84
84
85
- void closestHitProgram(in ImmutableRay_t _immutable , inout nbl_glsl_xoroshiro64star_state_t scramble_state)
85
+ bool closestHitProgram(inout Ray_t ray , inout nbl_glsl_xoroshiro64star_state_t scramble_state)
86
86
{
87
- const MutableRay_t mutable = rayStack[stackPtr] ._mutable;
87
+ const MutableRay_t _mutable = ray ._mutable;
88
88
89
- Sphere sphere = spheres[mutable .objectID];
90
- vec3 intersection = _immutable.origin+ _immutable.direction* mutable .intersectionT;
89
+ Sphere sphere = spheres[_mutable .objectID];
90
+ vec3 intersection = ray. _immutable.origin+ ray. _immutable.direction* _mutable .intersectionT;
91
91
92
92
nbl_glsl_AnisotropicViewSurfaceInteraction interaction;
93
93
{
94
94
nbl_glsl_IsotropicViewSurfaceInteraction isotropic;
95
95
96
- isotropic.V.dir = - _immutable.direction;
96
+ isotropic.V.dir = - ray. _immutable.direction;
97
97
// isotropic.V.dPosdScreen = screw that
98
98
isotropic.N = Sphere_getNormal(sphere,intersection);
99
99
isotropic.NdotV = dot (isotropic.V.dir,isotropic.N);
@@ -105,22 +105,22 @@ void closestHitProgram(in ImmutableRay_t _immutable, inout nbl_glsl_xoroshiro64s
105
105
const uint bsdfLightIDs = sphere.bsdfLightIDs;
106
106
const uint lightID = bitfieldExtract(bsdfLightIDs,16 ,16 );
107
107
108
- vec3 throughput = rayStack[stackPtr] ._payload.throughput;
108
+ vec3 throughput = ray ._payload.throughput;
109
109
110
110
// finish MIS
111
111
if (lightID!= INVALID_ID_16BIT) // has emissive
112
112
{
113
113
float lightPdf;
114
- vec3 lightVal = nbl_glsl_light_deferred_eval_and_prob(lightPdf,sphere,_immutable.origin,interaction,lights[lightID]);
115
- rayStack[stackPtr] ._payload.accumulation += throughput* lightVal/ (1.0 + lightPdf* lightPdf* rayStack[stackPtr] ._payload.otherTechniqueHeuristic);
114
+ vec3 lightVal = nbl_glsl_light_deferred_eval_and_prob(lightPdf,sphere,ray. _immutable.origin,interaction,lights[lightID]);
115
+ ray ._payload.accumulation += throughput* lightVal/ (1.0 + lightPdf* lightPdf* ray ._payload.otherTechniqueHeuristic);
116
116
}
117
117
118
- const int sampleIx = bitfieldExtract(_immutable.typeDepthSampleIx,0 ,DEPTH_BITS_OFFSET);
119
- const int depth = bitfieldExtract(_immutable.typeDepthSampleIx,DEPTH_BITS_OFFSET,DEPTH_BITS_COUNT);
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);
120
120
121
121
// check if we even have a BSDF at all
122
122
uint bsdfID = bitfieldExtract(bsdfLightIDs,0 ,16 );
123
- if (depth < MAX_DEPTH && bsdfID!= INVALID_ID_16BIT)
123
+ if (bsdfID!= INVALID_ID_16BIT)
124
124
{
125
125
// common preload
126
126
BSDFNode bsdf = bsdfs[bsdfID];
@@ -129,11 +129,11 @@ void closestHitProgram(in ImmutableRay_t _immutable, inout nbl_glsl_xoroshiro64s
129
129
#ifdef KILL_DIFFUSE_SPECULAR_PATHS
130
130
if (BSDFNode_isNotDiffuse(bsdf))
131
131
{
132
- if (rayStack[stackPtr] ._payload.hasDiffuse)
133
- return ;
132
+ if (ray ._payload.hasDiffuse)
133
+ return true ;
134
134
}
135
135
else
136
- rayStack[stackPtr] ._payload.hasDiffuse = true;
136
+ ray ._payload.hasDiffuse = true;
137
137
#endif
138
138
139
139
@@ -189,21 +189,22 @@ void closestHitProgram(in ImmutableRay_t _immutable, inout nbl_glsl_xoroshiro64s
189
189
const float lumaThroughputThreshold = bsdfPdfThreshold;
190
190
if (bsdfPdf> bsdfPdfThreshold && (! doNEE || bsdfPdf< FLT_MAX) && getLuma(throughput)> lumaThroughputThreshold)
191
191
{
192
- rayStack[stackPtr] ._payload.throughput = throughput* rcpChoiceProb;
192
+ ray ._payload.throughput = throughput* rcpChoiceProb;
193
193
194
194
float heuristicFactor = rcpChoiceProb- 1.0 ; // weightNonGenerator/weightGenerator
195
195
heuristicFactor /= doNEE ? lightPdf: bsdfPdf; // weightNonGenerator/(weightGenerator*probGenerated)
196
196
heuristicFactor *= heuristicFactor; // (weightNonGenerator/(weightGenerator*probGenerated))^2
197
197
if (doNEE)
198
198
heuristicFactor = 1.0 / (1.0 / bsdfPdf+ heuristicFactor* bsdfPdf); // numerically stable, don't touch
199
- rayStack[stackPtr] ._payload.otherTechniqueHeuristic = heuristicFactor;
199
+ ray ._payload.otherTechniqueHeuristic = heuristicFactor;
200
200
201
201
// trace new ray
202
- rayStack[stackPtr] ._immutable.origin = intersection+ _sample.L* (doNEE ? maxT: 1.0 /* kSceneSize*/ )* getStartTolerance(depth);
203
- rayStack[stackPtr] ._immutable.maxT = maxT;
204
- rayStack[stackPtr] ._immutable.direction = _sample.L;
205
- rayStack[stackPtr] ._immutable.typeDepthSampleIx = bitfieldInsert(sampleIx,depth+ 2 ,DEPTH_BITS_OFFSET,DEPTH_BITS_COUNT)| (doNEE ? ANY_HIT_FLAG: 0 );
206
- stackPtr ++ ;
202
+ ray ._immutable.origin = intersection+ _sample.L* (doNEE ? maxT: 1.0 /* kSceneSize*/ )* getStartTolerance(depth);
203
+ ray ._immutable.maxT = maxT;
204
+ ray ._immutable.direction = _sample.L;
205
+ ray ._immutable.typeDepthSampleIx = bitfieldInsert(sampleIx,depth+ 2 ,DEPTH_BITS_OFFSET,DEPTH_BITS_COUNT)| (doNEE ? ANY_HIT_FLAG: 0 );
206
+ return false ;
207
207
}
208
208
}
209
+ return true;
209
210
}
0 commit comments