-
Notifications
You must be signed in to change notification settings - Fork 940
Description
Sorry - I'm not 100% sure if this should be an issue, feel free to discard if considered not applicable!
[The following refers to cosine_pdf::value()
— @hollasch]
Consider the following:
raytracing.github.io/src/TheRestOfYourLife/pdf.h
Lines 58 to 61 in 5c312de
virtual double value(const vec3& direction) const override { | |
auto cosine = dot(unit_vector(direction), uvw.w()); | |
return (cosine <= 0) ? 0 : cosine/pi; | |
} |
and
raytracing.github.io/src/TheRestOfYourLife/main.cc
Lines 56 to 61 in 5c312de
auto pdf_val = p.value(scattered.direction()); | |
return emitted | |
+ srec.attenuation * rec.mat_ptr->scattering_pdf(r, rec, scattered) | |
* ray_color(scattered, background, world, lights, depth-1) | |
/ pdf_val; |
a cosine_pdf.value
returning zero can result in a division by zero in the main loop, and cause a NaN
.
When adding some debug prints to my own implementation, on a conditional of pdf_val == 0
, I got plenty of those, and they were causing NaN
s.
However, for some reason, adding the similar debug prints to the example scene in this repo, I was unable to reproduce it. Wonder if that is just due to some implementation bug on my part, random luck, or something else.
Should there be some additional logic somewhere? E.g.
- make sure the pdf's don't return zeroes?
- make sure that we don't divide by zero at the end of
ray_color
?- return something else conditionally; what?
- other, what?