|
1554 | 1554 |
|
1555 | 1555 |
|
1556 | 1556 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
1557 |
| - scattered = ray(rec.p, unit_vector(scatter_direction), r_in.time()); |
| 1557 | + scattered = ray(rec.p, scatter_direction, r_in.time()); |
1558 | 1558 | alb = albedo->value(rec.u, rec.v, rec.p);
|
1559 |
| - pdf = dot(rec.normal, scattered.direction()) / pi; |
| 1559 | + pdf = dot(rec.normal, unit_vector(scattered.direction())) / pi; |
1560 | 1560 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
1561 | 1561 | return true;
|
1562 | 1562 | }
|
|
1625 | 1625 | reflected rays weighted by Lambertian, so $\cos(\theta_o)$, but we'll change the scattering PDF.
|
1626 | 1626 | Instead of having our scattering PDF perfectly match the Lambertian distribution -- again --
|
1627 | 1627 | $\cos(\theta_o)$, we'll just use a uniform pdf about the hemisphere, $1/2\pi$. This will still
|
1628 |
| -converge on the correct answer, all we've done is change the PDF, but since the PDF is now less of a |
| 1628 | +converge to the correct answer, all we've done is change the PDF, but since the PDF is now less of a |
1629 | 1629 | perfect match for the real distribution, it will take longer to converge:
|
1630 | 1630 |
|
1631 | 1631 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
|
1635 | 1635 | bool scatter(
|
1636 | 1636 | const ray& r_in, const hit_record& rec, color& alb, ray& scattered, double& pdf
|
1637 | 1637 | ) const override {
|
1638 |
| - auto scatter_direction = rec.normal + random_unit_vector(); |
| 1638 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
| 1639 | + auto scatter_direction = random_in_hemisphere(rec.normal); |
| 1640 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1639 | 1641 |
|
1640 | 1642 | // Catch degenerate scatter direction
|
1641 | 1643 | if (scatter_direction.near_zero())
|
1642 | 1644 | scatter_direction = rec.normal;
|
1643 | 1645 |
|
1644 |
| - scattered = ray(rec.p, unit_vector(scatter_direction), r_in.time()); |
| 1646 | + scattered = ray(rec.p, scatter_direction, r_in.time()); |
1645 | 1647 | alb = albedo->value(rec.u, rec.v, rec.p);
|
1646 | 1648 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
1647 | 1649 | pdf = 0.5 / pi;
|
|
1650 | 1652 | }
|
1651 | 1653 |
|
1652 | 1654 | double scattering_pdf(const ray& r_in, const hit_record& rec, const ray& scattered) const {
|
1653 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1654 |
| - return 0.5 / pi; |
1655 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
| 1655 | + auto cosine = dot(rec.normal, unit_vector(scattered.direction())); |
| 1656 | + return cosine < 0 ? 0 : cosine/pi; |
1656 | 1657 | }
|
1657 | 1658 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
1658 | 1659 | [Listing [scatter-mod]: <kbd>[material.h]</kbd> Modified PDF]
|
|
1689 | 1690 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
1690 | 1691 | auto scatter_direction = random_in_hemisphere(rec.normal);
|
1691 | 1692 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
1692 |
| - scattered = ray(rec.p, unit_vector(scatter_direction), r_in.time()); |
| 1693 | + scattered = ray(rec.p, scatter_direction, r_in.time()); |
1693 | 1694 | alb = albedo->value(rec.u, rec.v, rec.p);
|
1694 | 1695 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
1695 | 1696 | pdf = 0.5 / pi;
|
|
0 commit comments