diff --git a/books/RayTracingTheRestOfYourLife.html b/books/RayTracingTheRestOfYourLife.html index 6fba1a37..180580b6 100644 --- a/books/RayTracingTheRestOfYourLife.html +++ b/books/RayTracingTheRestOfYourLife.html @@ -1554,9 +1554,9 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight - scattered = ray(rec.p, scatter_direction, r_in.time()); + scattered = ray(rec.p, unit_vector(scatter_direction), r_in.time()); alb = albedo->value(rec.u, rec.v, rec.p); - pdf = dot(rec.normal, unit_vector(scattered.direction())) / pi; + pdf = dot(rec.normal, scattered.direction()) / pi; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ return true; } @@ -1625,7 +1625,7 @@ reflected rays weighted by Lambertian, so $\cos(\theta_o)$, but we'll change the scattering PDF. Instead of having our scattering PDF perfectly match the Lambertian distribution -- again -- $\cos(\theta_o)$, we'll just use a uniform pdf about the hemisphere, $1/2\pi$. This will still -converge to the correct answer, all we've done is change the PDF, but since the PDF is now less of a +converge on the correct answer, all we've done is change the PDF, but since the PDF is now less of a perfect match for the real distribution, it will take longer to converge: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ @@ -1635,15 +1635,13 @@ bool scatter( const ray& r_in, const hit_record& rec, color& alb, ray& scattered, double& pdf ) const override { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight - auto scatter_direction = random_in_hemisphere(rec.normal); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ + 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, scatter_direction, r_in.time()); + 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; @@ -1652,8 +1650,9 @@ } double scattering_pdf(const ray& r_in, const hit_record& rec, const ray& scattered) const { - auto cosine = dot(rec.normal, unit_vector(scattered.direction())); - return cosine < 0 ? 0 : cosine/pi; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight + return 0.5 / pi; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Listing [scatter-mod]: [material.h] Modified PDF] @@ -1690,7 +1689,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight auto scatter_direction = random_in_hemisphere(rec.normal); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ - scattered = ray(rec.p, scatter_direction, r_in.time()); + 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;