fix a possible cause of NaNs

main
jbb01 6 months ago
parent cb4dcc53f1
commit 77c1a87e4f

@ -180,7 +180,13 @@ public final class SimpleRenderer implements Renderer {
} else { } else {
var mixed = new MixtureProbabilityDensityFunction(new TargetingProbabilityDensityFunction(hit.position(), scene.getLights()), pdf, 0.5); var mixed = new MixtureProbabilityDensityFunction(new TargetingProbabilityDensityFunction(hit.position(), scene.getLights()), pdf, 0.5);
var direction = mixed.generate(random); var direction = mixed.generate(random);
var factor = pdf.value(direction) / mixed.value(direction);
var idealPdf = pdf.value(direction);
var actualPdf = mixed.value(direction);
if (actualPdf == 0) break; // when actualPdf is 0, the ray should have never been generated by mixed.generate
var factor = idealPdf / actualPdf;
attenuation = Color.multiply(attenuation, Color.multiply(a, factor)); attenuation = Color.multiply(attenuation, Color.multiply(a, factor));
ray = new Ray(hit.position(), direction); ray = new Ray(hit.position(), direction);

Loading…
Cancel
Save