|
1554 | 1554 |
|
1555 | 1555 |
|
1556 | 1556 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1557 | | - scattered = ray(rec.p, scatter_direction, r_in.time()); |
| 1557 | + scattered = ray(rec.p, unit_vector(scatter_direction), r_in.time()); |
1558 | 1558 | 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; |
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 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 |
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 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1639 | | - auto scatter_direction = random_in_hemisphere(rec.normal); |
1640 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
| 1638 | + auto scatter_direction = rec.normal + random_unit_vector(); |
1641 | 1639 |
|
1642 | 1640 | // Catch degenerate scatter direction |
1643 | 1641 | if (scatter_direction.near_zero()) |
1644 | 1642 | scatter_direction = rec.normal; |
1645 | 1643 |
|
1646 | | - scattered = ray(rec.p, scatter_direction, r_in.time()); |
| 1644 | + scattered = ray(rec.p, unit_vector(scatter_direction), r_in.time()); |
1647 | 1645 | alb = albedo->value(rec.u, rec.v, rec.p); |
1648 | 1646 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1649 | 1647 | pdf = 0.5 / pi; |
|
1652 | 1650 | } |
1653 | 1651 |
|
1654 | 1652 | 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++ |
1657 | 1656 | } |
1658 | 1657 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1659 | 1658 | [Listing [scatter-mod]: <kbd>[material.h]</kbd> Modified PDF] |
|
1690 | 1689 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1691 | 1690 | auto scatter_direction = random_in_hemisphere(rec.normal); |
1692 | 1691 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1693 | | - scattered = ray(rec.p, scatter_direction, r_in.time()); |
| 1692 | + scattered = ray(rec.p, unit_vector(scatter_direction), r_in.time()); |
1694 | 1693 | alb = albedo->value(rec.u, rec.v, rec.p); |
1695 | 1694 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1696 | 1695 | pdf = 0.5 / pi; |
|
0 commit comments