@@ -94,7 +94,7 @@ struct Unidirectional
9494 uint32_t address = glsl::bitfieldInsert<uint32_t>(protoDimension, _sample, MAX_DEPTH_LOG2, MAX_SAMPLES_LOG2);
9595 uint32_t3 seqVal = sampleSequence[address + i].xyz;
9696 seqVal ^= randGen ();
97- return vector3_type (seqVal) * asfloat (0x2f800004u);
97+ return vector3_type (seqVal) * bit_cast<scalar_type> (0x2f800004u);
9898 }
9999
100100 scalar_type getLuma (NBL_CONST_REF_ARG (vector3_type) col)
@@ -177,6 +177,7 @@ struct Unidirectional
177177 scene.lights[lightID], intersection, interaction,
178178 isBSDF, eps0, depth, scene.toNextEvent (lightID)
179179 );
180+ //printf("%f %f %f\n", nee_sample.L.direction.x, nee_sample.L.direction.y, nee_sample.L.direction.z);
180181
181182 // We don't allow non watertight transmitters in this renderer
182183 bool validPath = nee_sample.NdotL > numeric_limits<scalar_type>::min ;
@@ -195,47 +196,51 @@ struct Unidirectional
195196 {
196197 ext::MaterialSystem::Material material;
197198 material.type = bxdf.materialType;
198- params_type params;
199+
200+ bxdf::BxDFClampMode _clamp;
201+ _clamp = (bxdf.materialType == ext::MaterialSystem::Material::Type::DIELECTRIC) ? bxdf::BxDFClampMode::BCM_ABS : bxdf::BxDFClampMode::BCM_MAX;
202+ // example only uses isotropic bxdfs
203+ params_type params = params_type::template create<sample_type, isotropic_type, isocache_type>(nee_sample, interaction.isotropic, _cache.iso_cache, _clamp);
199204
200205 // TODO: does not yet account for smooth dielectric
201- if (!isBSDF && bxdf.materialType == ext::MaterialSystem::Material::DIFFUSE)
202- {
203- params = params_type::template create<sample_type, isotropic_type>(nee_sample, iso_interaction , bxdf::BCM_MAX);
204- }
205- else if (!isBSDF && bxdf.materialType != ext::MaterialSystem::Material::DIFFUSE)
206- {
207- if (bxdf.params.is_aniso)
208- params = params_type::template create<sample_type, anisotropic_type, anisocache_type>(nee_sample, interaction, _cache, bxdf::BCM_MAX);
209- else
210- {
211- isocache_type isocache = _cache.iso_cache;
212- params = params_type::template create<sample_type, isotropic_type, isocache_type>(nee_sample, iso_interaction, isocache , bxdf::BCM_MAX);
213- }
214- }
215- else if (isBSDF && bxdf.materialType == ext::MaterialSystem::Material::DIFFUSE)
216- {
217- params = params_type::template create<sample_type, isotropic_type>(nee_sample, iso_interaction , bxdf::BCM_ABS);
218- }
219- else if (isBSDF && bxdf.materialType != ext::MaterialSystem::Material::DIFFUSE)
220- {
221- if (bxdf.params.is_aniso)
222- params = params_type::template create<sample_type, anisotropic_type, anisocache_type>(nee_sample, interaction, _cache, bxdf::BCM_ABS);
223- else
224- {
225- isocache_type isocache = _cache.iso_cache;
226- params = params_type::template create<sample_type, isotropic_type, isocache_type>(nee_sample, iso_interaction, isocache , bxdf::BCM_ABS);
227- }
228- }
206+ // if (!isBSDF && bxdf.materialType == ext::MaterialSystem::Material::DIFFUSE)
207+ // {
208+ // params = params_type::template create<sample_type, isotropic_type>(nee_sample, interaction.isotropic , bxdf::BCM_MAX);
209+ // }
210+ // else if (!isBSDF && bxdf.materialType != ext::MaterialSystem::Material::DIFFUSE)
211+ // {
212+ // if (bxdf.params.is_aniso)
213+ // params = params_type::template create<sample_type, anisotropic_type, anisocache_type>(nee_sample, interaction, _cache, bxdf::BCM_MAX);
214+ // else
215+ // {
216+ // isocache_type isocache = _cache.iso_cache;
217+ // params = params_type::template create<sample_type, isotropic_type, isocache_type>(nee_sample, interaction.isotropic, _cache.iso_cache , bxdf::BCM_MAX);
218+ // }
219+ // }
220+ // else if (isBSDF && bxdf.materialType == ext::MaterialSystem::Material::DIFFUSE)
221+ // {
222+ // params = params_type::template create<sample_type, isotropic_type>(nee_sample, interaction.isotropic , bxdf::BCM_ABS);
223+ // }
224+ // else if (isBSDF && bxdf.materialType != ext::MaterialSystem::Material::DIFFUSE)
225+ // {
226+ // if (bxdf.params.is_aniso)
227+ // params = params_type::template create<sample_type, anisotropic_type, anisocache_type>(nee_sample, interaction, _cache, bxdf::BCM_ABS);
228+ // else
229+ // {
230+ // isocache_type isocache = _cache.iso_cache;
231+ // params = params_type::template create<sample_type, isotropic_type, isocache_type>(nee_sample, interaction.isotropic, _cache.iso_cache , bxdf::BCM_ABS);
232+ // }
233+ // }
229234
230235 quotient_pdf_type bsdf_quotient_pdf = materialSystem.quotient_and_pdf (material, bxdf.params, params);
231236 bsdf_quotient_pdf.quotient *= bxdf.albedo * throughput;
232237 neeContrib_pdf.quotient *= bsdf_quotient_pdf.quotient;
233238 const scalar_type otherGenOverChoice = bsdf_quotient_pdf.pdf * rcpChoiceProb;
234- // const scalar_type otherGenOverLightAndChoice = otherGenOverChoice / bsdf_quotient_pdf.pdf;
235- // neeContrib_pdf.quotient *= otherGenOverChoice / (1.f + otherGenOverLightAndChoice * otherGenOverLightAndChoice); // balance heuristic
239+ const scalar_type otherGenOverLightAndChoice = otherGenOverChoice / bsdf_quotient_pdf.pdf;
240+ neeContrib_pdf.quotient *= otherGenOverChoice / (1.f + otherGenOverLightAndChoice * otherGenOverLightAndChoice); // balance heuristic
236241
237242 // TODO: ifdef NEE only
238- neeContrib_pdf.quotient *= otherGenOverChoice;
243+ // neeContrib_pdf.quotient *= otherGenOverChoice;
239244
240245 ray_type nee_ray;
241246 nee_ray.origin = intersection + nee_sample.L.direction * t * Tolerance<scalar_type>::getStart (depth);
@@ -247,7 +252,7 @@ struct Unidirectional
247252 }
248253 }
249254
250- return false ; // NEE only
255+ // return false; // NEE only
251256
252257 // sample BSDF
253258 scalar_type bxdfPdf;
@@ -259,12 +264,17 @@ struct Unidirectional
259264 anisocache_type _cache;
260265 sample_type bsdf_sample = materialSystem.generate (material, bxdf.params, interaction, eps1, _cache);
261266
267+ bxdf::BxDFClampMode _clamp;
268+ _clamp = (bxdf.materialType == ext::MaterialSystem::Material::Type::DIELECTRIC) ? bxdf::BxDFClampMode::BCM_ABS : bxdf::BxDFClampMode::BCM_MAX;
269+ // example only uses isotropic bxdfs
270+ params_type params = params_type::template create<sample_type, isotropic_type, isocache_type>(bsdf_sample, interaction.isotropic, _cache.iso_cache, _clamp);
271+
262272 // TODO: does not yet account for smooth dielectric
263- params_type params;
264- if (!isBSDF && bxdf.materialType == ext::MaterialSystem::Material::DIFFUSE)
265- {
266- params = params_type::template create<sample_type, isotropic_type>(bsdf_sample, iso_interaction, bxdf::BCM_MAX);
267- }
273+ // params_type params;
274+ // if (!isBSDF && bxdf.materialType == ext::MaterialSystem::Material::DIFFUSE)
275+ // {
276+ // params = params_type::template create<sample_type, isotropic_type>(bsdf_sample, iso_interaction, bxdf::BCM_MAX);
277+ // }
268278 // else if (!isBSDF && bxdf.materialType != ext::MaterialSystem::Material::DIFFUSE)
269279 // {
270280 // if (bxdf.params.is_aniso)
@@ -292,7 +302,8 @@ struct Unidirectional
292302
293303 // the value of the bsdf divided by the probability of the sample being generated
294304 quotient_pdf_type bsdf_quotient_pdf = materialSystem.quotient_and_pdf (material, bxdf.params, params);
295- throughput *= bsdf_quotient_pdf.quotient;
305+ throughput *= bxdf.albedo * bsdf_quotient_pdf.quotient;
306+ bxdfPdf = bsdf_quotient_pdf.pdf;
296307 bxdfSample = bsdf_sample.L.direction;
297308 }
298309
@@ -351,7 +362,6 @@ struct Unidirectional
351362 hit = ray.objectID.id != -1 ;
352363 if (hit)
353364 rayAlive = closestHitProgram (1 , i, ray, scene);
354-
355365 }
356366 if (!hit)
357367 missProgram (ray);
0 commit comments