-
Notifications
You must be signed in to change notification settings - Fork 944
Closed
Milestone
Description
This listing in the section about "Using a Uniform PDF Instead of a Perfect Match":
raytracing.github.io/books/RayTracingTheRestOfYourLife.html
Lines 1631 to 1656 in 62ce2e6
class lambertian : public material { | |
public: | |
... | |
bool scatter( | |
const ray& r_in, const hit_record& rec, color& alb, ray& scattered, double& pdf | |
) const override { | |
auto scatter_direction = rec.normal + random_unit_vector(); | |
// Catch degenerate scatter direction | |
if (scatter_direction.near_zero()) | |
scatter_direction = rec.normal; | |
scattered = ray(rec.p, unit_vector(scatter_direction), r_in.time()); | |
alb = albedo->value(rec.u, rec.v, rec.p); | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight | |
pdf = 0.5 / pi; | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ | |
return true; | |
} | |
double scattering_pdf(const ray& r_in, const hit_record& rec, const ray& scattered) const { | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight | |
return 0.5 / pi; | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ | |
} | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
doesn't seem to actually sample using a uniform PDF. It still samples from
rec.normal + random_unit_vector()
, so cosine-weighted. The PDF value, pdf = 0.5 / pi;
, is set as-if it was sampled uniformly. The final image looks good, because the error is cancelled by a wrong scattering_pdf
of 0.5 / pi
. That should remain cosine/pi
, irrespective of which sampling PDF is chosen.gau-nernst and k4lizen
Metadata
Metadata
Assignees
Labels
No labels