diff --git a/src/main/java/eu/jonahbauer/raytracing/render/renderer/SimpleRenderer.java b/src/main/java/eu/jonahbauer/raytracing/render/renderer/SimpleRenderer.java index e3c6a1e..15a8ecc 100644 --- a/src/main/java/eu/jonahbauer/raytracing/render/renderer/SimpleRenderer.java +++ b/src/main/java/eu/jonahbauer/raytracing/render/renderer/SimpleRenderer.java @@ -180,7 +180,13 @@ public final class SimpleRenderer implements Renderer { } else { var mixed = new MixtureProbabilityDensityFunction(new TargetingProbabilityDensityFunction(hit.position(), scene.getLights()), pdf, 0.5); 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)); ray = new Ray(hit.position(), direction);