10
10
11
11
12
12
13
- bool traceRay(in ImmutableRay_t _immutable, inout MutableRay_t _mutable)
13
+ void traceRay(in bool anyHit, in ImmutableRay_t _immutable, inout MutableRay_t _mutable)
14
14
{
15
- const bool anyHit = _immutable.anyHit;
16
-
17
15
int objectID = - 1 ;
18
16
float intersectionT = _immutable.maxT;
19
17
for (int i= 0 ; i< SPHERE_COUNT; i++ )
@@ -30,10 +28,9 @@ bool traceRay(in ImmutableRay_t _immutable, inout MutableRay_t _mutable)
30
28
}
31
29
_mutable.objectID = objectID;
32
30
_mutable.intersectionT = intersectionT;
33
- // hit
34
- return anyHit;
35
31
}
36
32
33
+ #if 0
37
34
// the interaction here is the interaction at the illuminator-end of the ray, not the receiver
38
35
vec3 nbl_glsl_light_deferred_eval_and_prob(out float pdf, in Sphere sphere, in vec3 origin, in nbl_glsl_AnisotropicViewSurfaceInteraction interaction, in Light light)
39
36
{
@@ -80,8 +77,93 @@ nbl_glsl_LightSample nbl_glsl_light_generate_and_remainder_and_pdf(out vec3 rema
80
77
81
78
return nbl_glsl_createLightSample(L,interaction);
82
79
}
80
+ #endif
81
+
82
+ bool closestHitProgram(in uint depth, in uint _sample, inout Ray_t ray, inout nbl_glsl_xoroshiro64star_state_t scramble_state)
83
+ {
84
+ const MutableRay_t _mutable = ray._mutable;
85
+
86
+ Sphere sphere = spheres[_mutable.objectID];
87
+ const uint bsdfLightIDs = sphere.bsdfLightIDs;
88
+
89
+ vec3 throughput = ray._payload.throughput;
90
+
91
+ // add emissive
92
+ const uint lightID = bitfieldExtract(bsdfLightIDs,16 ,16 );
93
+ if (lightID!= INVALID_ID_16BIT) // has emissive
94
+ ray._payload.accumulation += throughput* Light_getRadiance(lights[lightID]);
95
+
96
+ // check if we even have a BSDF at all
97
+ uint bsdfID = bitfieldExtract(bsdfLightIDs,0 ,16 );
98
+ if (bsdfID!= INVALID_ID_16BIT)
99
+ {
100
+ BSDFNode bsdf = bsdfs[bsdfID];
101
+ #ifdef KILL_DIFFUSE_SPECULAR_PATHS
102
+ if (BSDFNode_isNotDiffuse(bsdf))
103
+ {
104
+ if (ray._payload.hasDiffuse)
105
+ return true;
106
+ }
107
+ else
108
+ ray._payload.hasDiffuse = true;
109
+ #endif
110
+
111
+ // rand
112
+ mat2x3 epsilon = rand3d(depth,_sample,scramble_state);
113
+
114
+ // intersection stuffs
115
+ const vec3 intersection = ray._immutable.origin+ ray._immutable.direction* _mutable.intersectionT;
116
+
117
+ nbl_glsl_AnisotropicViewSurfaceInteraction interaction;
118
+ {
119
+ nbl_glsl_IsotropicViewSurfaceInteraction isotropic;
83
120
121
+ isotropic.V.dir = - ray._immutable.direction;
122
+ // isotropic.V.dPosdScreen = screw that
123
+ isotropic.N = Sphere_getNormal(sphere,intersection);
124
+ isotropic.NdotV = dot (isotropic.V.dir,isotropic.N);
125
+ isotropic.NdotV_squared = isotropic.NdotV* isotropic.NdotV;
84
126
127
+ interaction = nbl_glsl_calcAnisotropicInteraction(isotropic);
128
+ }
129
+
130
+
131
+
132
+
133
+ float maxT = FLT_MAX;
134
+ nbl_glsl_AnisotropicMicrofacetCache _cache;
135
+
136
+ // do I need this?
137
+ const vec3 throughputCIE_Y = transpose (nbl_glsl_sRGBtoXYZ)[1 ]* throughput;
138
+ const float monochromeEta = dot (throughputCIE_Y,BSDFNode_getEta(bsdf)[0 ])/ (throughputCIE_Y.r+ throughputCIE_Y.g+ throughputCIE_Y.b);
139
+
140
+ // sample BSDF
141
+ float bsdfPdf; vec3 bsdfSampleL;
142
+ {
143
+ nbl_glsl_LightSample _sample = nbl_glsl_bsdf_cos_generate(interaction,epsilon[0 ],bsdf,monochromeEta,_cache);
144
+ // the value of the bsdf divided by the probability of the sample being generated
145
+ throughput *= nbl_glsl_bsdf_cos_remainder_and_pdf(bsdfPdf,_sample,interaction,bsdf,monochromeEta,_cache);
146
+ //
147
+ bsdfSampleL = _sample.L;
148
+ }
149
+
150
+ const float bsdfPdfThreshold = 0.0001 ;
151
+ // OETF smallest perceptible value
152
+ const float lumaThroughputThreshold = getLuma(nbl_glsl_eotf_sRGB(vec3 (1.0 )/ 255.0 ));
153
+ if (bsdfPdf> bsdfPdfThreshold && getLuma(throughput)> lumaThroughputThreshold)
154
+ {
155
+ ray._payload.throughput = throughput;
156
+
157
+ // trace new ray
158
+ ray._immutable.origin = intersection+ bsdfSampleL* (1.0 /* kSceneSize*/ )* getStartTolerance(depth);
159
+ ray._immutable.maxT = maxT;
160
+ ray._immutable.direction = bsdfSampleL;
161
+ return false;
162
+ }
163
+ }
164
+ return true;
165
+ }
166
+ #if 0
85
167
bool closestHitProgram(in uint depth, in uint _sample, inout Ray_t ray, inout nbl_glsl_xoroshiro64star_state_t scramble_state)
86
168
{
87
169
const MutableRay_t _mutable = ray._mutable;
@@ -204,4 +286,5 @@ bool closestHitProgram(in uint depth, in uint _sample, inout Ray_t ray, inout nb
204
286
}
205
287
}
206
288
return true;
207
- }
289
+ }
290
+ #endif
0 commit comments