Skip to content

Book 3.10.1: Probability density functions could cause NaN's? #772

@Walther

Description

@Walther

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:

virtual double value(const vec3& direction) const override {
auto cosine = dot(unit_vector(direction), uvw.w());
return (cosine <= 0) ? 0 : cosine/pi;
}

and
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 NaNs.

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?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions