It was forgotten to remove pdf_value = scattering_pdf; in listing 29.
In listing 29 pdf_value is added as an argument in the call to rec.mat->scatter(), but the value of pdf_value set by that call is never used, because a few lines below pdf_value is set to scattering_pdf. As a result the changes to material::scatter() introduced in listing 28 are not actually used. Removing pdf_value = scattering_pdf; from listing 29, would resolve that problem. Or, even better, highlight double pdf_value = scattering_pdf; in red to mark it for removal relative to listing 21 (or listing 19).
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
|
class camera { |
|
... |
|
private: |
|
... |
|
|
|
color ray_color(const ray& r, int depth, const hittable& world) const { |
|
... |
|
|
|
ray scattered; |
|
color attenuation; |
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
|
double pdf_value; |
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
|
color color_from_emission = rec.mat->emitted(rec.u, rec.v, rec.p); |
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
|
if (!rec.mat->scatter(r, rec, attenuation, scattered, pdf_value)) |
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
|
return color_from_emission; |
|
|
|
double scattering_pdf = rec.mat->scattering_pdf(r, rec, scattered); |
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
|
pdf_value = scattering_pdf; |
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
|
|
|
... |
|
} |
|
|
|
... |
|
}; |
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
[Listing [scatter-ray-color]: <kbd>[camera.h]</kbd> Updated ray_color function with returned PDF value] |
This may relate to issue #1543.
It was forgotten to remove
pdf_value = scattering_pdf;in listing 29.In listing 29
pdf_valueis added as an argument in the call torec.mat->scatter(), but the value ofpdf_valueset by that call is never used, because a few lines belowpdf_valueis set toscattering_pdf. As a result the changes tomaterial::scatter()introduced in listing 28 are not actually used. Removingpdf_value = scattering_pdf;from listing 29, would resolve that problem. Or, even better, highlightdouble pdf_value = scattering_pdf;in red to mark it for removal relative to listing 21 (or listing 19).raytracing.github.io/books/RayTracingTheRestOfYourLife.html
Lines 2408 to 2441 in 4dbfa6f
This may relate to issue #1543.