Skip to content

Commit 479b3c6

Browse files
authored
Merge pull request #970 from RayTracing/revert-934-fix-uniform-sampling
Revert "Fix uniform sampling"
2 parents 88f6dae + d6df036 commit 479b3c6

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

books/RayTracingTheRestOfYourLife.html

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,9 +1554,9 @@
15541554

15551555

15561556
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
1557-
scattered = ray(rec.p, scatter_direction, r_in.time());
1557+
scattered = ray(rec.p, unit_vector(scatter_direction), r_in.time());
15581558
alb = albedo->value(rec.u, rec.v, rec.p);
1559-
pdf = dot(rec.normal, unit_vector(scattered.direction())) / pi;
1559+
pdf = dot(rec.normal, scattered.direction()) / pi;
15601560
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
15611561
return true;
15621562
}
@@ -1625,7 +1625,7 @@
16251625
reflected rays weighted by Lambertian, so $\cos(\theta_o)$, but we'll change the scattering PDF.
16261626
Instead of having our scattering PDF perfectly match the Lambertian distribution -- again --
16271627
$\cos(\theta_o)$, we'll just use a uniform pdf about the hemisphere, $1/2\pi$. This will still
1628-
converge to the correct answer, all we've done is change the PDF, but since the PDF is now less of a
1628+
converge on the correct answer, all we've done is change the PDF, but since the PDF is now less of a
16291629
perfect match for the real distribution, it will take longer to converge:
16301630

16311631
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
@@ -1635,15 +1635,13 @@
16351635
bool scatter(
16361636
const ray& r_in, const hit_record& rec, color& alb, ray& scattered, double& pdf
16371637
) const override {
1638-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
1639-
auto scatter_direction = random_in_hemisphere(rec.normal);
1640-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1638+
auto scatter_direction = rec.normal + random_unit_vector();
16411639

16421640
// Catch degenerate scatter direction
16431641
if (scatter_direction.near_zero())
16441642
scatter_direction = rec.normal;
16451643

1646-
scattered = ray(rec.p, scatter_direction, r_in.time());
1644+
scattered = ray(rec.p, unit_vector(scatter_direction), r_in.time());
16471645
alb = albedo->value(rec.u, rec.v, rec.p);
16481646
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
16491647
pdf = 0.5 / pi;
@@ -1652,8 +1650,9 @@
16521650
}
16531651

16541652
double scattering_pdf(const ray& r_in, const hit_record& rec, const ray& scattered) const {
1655-
auto cosine = dot(rec.normal, unit_vector(scattered.direction()));
1656-
return cosine < 0 ? 0 : cosine/pi;
1653+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
1654+
return 0.5 / pi;
1655+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
16571656
}
16581657
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16591658
[Listing [scatter-mod]: <kbd>[material.h]</kbd> Modified PDF]
@@ -1690,7 +1689,7 @@
16901689
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
16911690
auto scatter_direction = random_in_hemisphere(rec.normal);
16921691
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1693-
scattered = ray(rec.p, scatter_direction, r_in.time());
1692+
scattered = ray(rec.p, unit_vector(scatter_direction), r_in.time());
16941693
alb = albedo->value(rec.u, rec.v, rec.p);
16951694
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
16961695
pdf = 0.5 / pi;

0 commit comments

Comments
 (0)