Fix nans for MIS renderer

This commit is contained in:
hal8174 2025-09-08 23:38:06 +02:00
parent 2269bd102d
commit 95092b1571
Signed by: hal8174
SSH key fingerprint: SHA256:NN98ZYwnrreQLSOV/g+amY7C3yL/mS1heD7bi5t6PPw

View file

@ -24,7 +24,7 @@ where
let mut r = camera.forward(x, y, rng);
let mut count = 0;
let mut last_bsdf_pdf = 0.0;
let mut last_bsdf_pdf = 1.0;
while let Some(i) = scene.intersect(r, 0.001, Float::INFINITY) {
let frame = i.tangent_frame();
@ -40,9 +40,16 @@ where
let dist = i.t() / r.dir().length();
let path_pdf = last_bsdf_pdf;
let nee_pdf = i.light_pdf() * dist * dist / w_in.y();
let nee_pdf = if i.light_pdf() != 0.0 {
i.light_pdf() * dist * dist / w_in.y()
} else {
0.0
};
let b = path_pdf / (path_pdf + nee_pdf);
let b = path_pdf / (path_pdf + nee_pdf + 0.000001);
if b.is_nan() {
dbg!(b, path_pdf, nee_pdf);
}
sum += b * alpha * light.emit(w_in, rng);
}
}