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