6
6
#extension GL_GOOGLE_include_directive : require
7
7
8
8
#define SPHERE_COUNT 8
9
- #define POLYGON_METHOD 0 // 0 area sampling, 1 solid angle sampling, 2 approximate projected solid angle sampling
9
+ #define POLYGON_METHOD 2 // 0 area sampling, 1 solid angle sampling, 2 approximate projected solid angle sampling
10
10
#include "common.glsl"
11
11
12
12
#define TRIANGLE_COUNT 1
@@ -87,132 +87,18 @@ vec3 nbl_glsl_light_generate_and_pdf(out float pdf, out float newRayMaxT, in vec
87
87
}
88
88
89
89
90
- bool closestHitProgram( in uint depth , in uint _sample, inout Ray_t ray, inout nbl_glsl_xoroshiro64star_state_t scramble_state )
90
+ uint getBSDFLightIDAndDetermineNormal( out vec3 normal , in uint objectID, in vec3 intersection )
91
91
{
92
- const MutableRay_t _mutable = ray._mutable;
93
-
94
- const uint objectID = _mutable.objectID;
95
- Sphere sphere = spheres[_mutable.objectID];
96
-
97
- // interaction stuffs
98
- const ImmutableRay_t _immutable = ray._immutable;
99
- const vec3 intersection = _immutable.origin+ _immutable.direction* _mutable.intersectionT;
100
- uint bsdfLightIDs;
101
- nbl_glsl_AnisotropicViewSurfaceInteraction interaction;
92
+ if (objectID< SPHERE_COUNT)
102
93
{
103
- nbl_glsl_IsotropicViewSurfaceInteraction isotropic;
104
-
105
- isotropic.V.dir = - _immutable.direction;
106
- // isotropic.V.dPosdScreen = screw that
107
- if (objectID< SPHERE_COUNT)
108
- {
109
- Sphere sphere = spheres[objectID];
110
- isotropic.N = Sphere_getNormal(sphere,intersection);
111
- bsdfLightIDs = sphere.bsdfLightIDs;
112
- }
113
- else
114
- {
115
- Triangle tri = triangles[objectID- SPHERE_COUNT];
116
- isotropic.N = normalize (Triangle_getNormalTimesArea(tri));
117
- bsdfLightIDs = tri.bsdfLightIDs;
118
- }
119
- isotropic.NdotV = dot (isotropic.V.dir,isotropic.N);
120
- isotropic.NdotV_squared = isotropic.NdotV* isotropic.NdotV;
121
-
122
- interaction = nbl_glsl_calcAnisotropicInteraction(isotropic);
94
+ Sphere sphere = spheres[objectID];
95
+ normal = Sphere_getNormal(sphere,intersection);
96
+ return sphere.bsdfLightIDs;
123
97
}
124
-
125
- //
126
- vec3 throughput = ray._payload.throughput;
127
-
128
- // add emissive and finish MIS
129
- const uint lightID = bitfieldExtract(bsdfLightIDs,16 ,16 );
130
- if (lightID!= INVALID_ID_16BIT) // has emissive
98
+ else
131
99
{
132
- float lightPdf;
133
- ray._payload.accumulation += nbl_glsl_light_deferred_eval_and_prob(lightPdf,lights[lightID],ray)* throughput/ (1.0 + lightPdf* lightPdf* ray._payload.otherTechniqueHeuristic);
134
- }
135
-
136
- // check if we even have a BSDF at all
137
- uint bsdfID = bitfieldExtract(bsdfLightIDs,0 ,16 );
138
- if (bsdfID!= INVALID_ID_16BIT)
139
- {
140
- BSDFNode bsdf = bsdfs[bsdfID];
141
- #ifdef KILL_DIFFUSE_SPECULAR_PATHS
142
- if (BSDFNode_isNotDiffuse(bsdf))
143
- {
144
- if (ray._payload.hasDiffuse)
145
- return true;
146
- }
147
- else
148
- ray._payload.hasDiffuse = true;
149
- #endif
150
-
151
- const bool isBSDF = BSDFNode_isBSDF(bsdf);
152
- // rand
153
- mat2x3 epsilon = rand3d(depth,_sample,scramble_state);
154
-
155
- // thresholds
156
- const float bsdfPdfThreshold = 0.0001 ;
157
- const float lumaContributionThreshold = getLuma(nbl_glsl_eotf_sRGB(vec3 (1.0 )/ 255.0 )); // OETF smallest perceptible value
158
- const vec3 throughputCIE_Y = transpose (nbl_glsl_sRGBtoXYZ)[1 ]* throughput;
159
- const float monochromeEta = dot (throughputCIE_Y,BSDFNode_getEta(bsdf)[0 ])/ (throughputCIE_Y.r+ throughputCIE_Y.g+ throughputCIE_Y.b);
160
-
161
- // do NEE
162
- const float neeSkipProbability = BSDFNode_getNEESkipProb(bsdf);
163
- float rcpChoiceProb;
164
- if (nbl_glsl_partitionRandVariable(neeSkipProbability,epsilon[0 ].z,rcpChoiceProb))
165
- {
166
- vec3 neeContrib; float lightPdf, t;
167
- nbl_glsl_LightSample nee_sample = nbl_glsl_light_generate_and_remainder_and_pdf(
168
- neeContrib,lightPdf,t,
169
- intersection,interaction,
170
- isBSDF,epsilon[0 ],depth
171
- );
172
- // We don't allow non watertight transmitters in this renderer
173
- bool validPath = nee_sample.NdotL> 0.0 ;
174
- // but if we allowed non-watertight transmitters (single water surface), it would make sense just to apply this line by itself
175
- nbl_glsl_AnisotropicMicrofacetCache _cache;
176
- validPath = validPath && nbl_glsl_calcAnisotropicMicrofacetCache(_cache,interaction,nee_sample,monochromeEta);
177
- if (validPath)
178
- {
179
- float bsdfPdf;
180
- neeContrib *= nbl_glsl_bsdf_cos_remainder_and_pdf(bsdfPdf,nee_sample,interaction,bsdf,monochromeEta,_cache)* throughput;
181
- const float oc = bsdfPdf* rcpChoiceProb;
182
- neeContrib /= 1.0 / oc+ oc/ (lightPdf* lightPdf); // MIS weight
183
- if (bsdfPdf< FLT_MAX && getLuma(neeContrib)> lumaContributionThreshold && traceRay(t,intersection+ nee_sample.L* t* getStartTolerance(depth),nee_sample.L)==-1 )
184
- ray._payload.accumulation += neeContrib;
185
- }
186
- }
187
-
188
- // sample BSDF
189
- float bsdfPdf; vec3 bsdfSampleL;
190
- {
191
- nbl_glsl_AnisotropicMicrofacetCache _cache;
192
- nbl_glsl_LightSample bsdf_sample = nbl_glsl_bsdf_cos_generate(interaction,epsilon[1 ],bsdf,monochromeEta,_cache);
193
- // the value of the bsdf divided by the probability of the sample being generated
194
- throughput *= nbl_glsl_bsdf_cos_remainder_and_pdf(bsdfPdf,bsdf_sample,interaction,bsdf,monochromeEta,_cache);
195
- //
196
- bsdfSampleL = bsdf_sample.L;
197
- }
198
-
199
- // additional threshold
200
- const float lumaThroughputThreshold = lumaContributionThreshold;
201
- if (bsdfPdf> bsdfPdfThreshold && getLuma(throughput)> lumaThroughputThreshold)
202
- {
203
- ray._payload.throughput = throughput;
204
- ray._payload.otherTechniqueHeuristic = (1.0 - neeSkipProbability)/ bsdfPdf; // numerically stable, don't touch
205
- ray._payload.otherTechniqueHeuristic *= ray._payload.otherTechniqueHeuristic;
206
-
207
- // trace new ray
208
- ray._immutable.origin = intersection+ bsdfSampleL* (1.0 /* kSceneSize*/ )* getStartTolerance(depth);
209
- ray._immutable.direction = bsdfSampleL;
210
- #if POLYGON_METHOD== 2
211
- ray._immutable.normalAtOrigin = interaction.isotropic.N;
212
- ray._immutable.wasBSDFAtOrigin = isBSDF;
213
- #endif
214
- return true;
215
- }
100
+ Triangle tri = triangles[objectID- SPHERE_COUNT];
101
+ normal = normalize (Triangle_getNormalTimesArea(tri));
102
+ return tri.bsdfLightIDs;
216
103
}
217
- return false;
218
104
}
0 commit comments