|
1086 | 1086 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1087 | 1087 | vec3 ray_color(const ray& r, const hittable& world) { |
1088 | 1088 | hit_record rec; |
1089 | | - if (world.hit(r, 0.0, infinity, rec)) { |
| 1089 | + if (world.hit(r, 0.001, infinity, rec)) { |
1090 | 1090 | return 0.5 * (rec.normal + vec3(1,1,1)); |
1091 | 1091 | } |
1092 | 1092 |
|
|
1408 | 1408 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1409 | 1409 | vec3 ray_color(const ray& r, const hittable& world) { |
1410 | 1410 | hit_record rec; |
| 1411 | + |
1411 | 1412 | if (world.hit(r, 0.0, infinity, rec)) { |
1412 | 1413 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1413 | 1414 | vec3 target = rec.p + rec.normal + random_in_unit_sphere(); |
|
1432 | 1433 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1433 | 1434 | vec3 ray_color(const ray& r, const hittable& world, int depth) { |
1434 | 1435 | hit_record rec; |
1435 | | - if (world.hit(r, 0.0, infinity, rec)) { |
1436 | | - // If we've exceeded the ray bounce limit, no more light is gathered. |
1437 | | - if (depth <= 0) |
1438 | | - return vec3(0,0,0); |
| 1436 | + |
| 1437 | + // If we've exceeded the ray bounce limit, no more light is gathered. |
| 1438 | + if (depth <= 0) |
| 1439 | + return vec3(0,0,0); |
| 1440 | + |
| 1441 | + if (world.hit(r, 0.001, infinity, rec)) { |
1439 | 1442 | vec3 target = rec.p + rec.normal + random_in_unit_sphere(); |
1440 | 1443 | return 0.5 * ray_color(ray(rec.p, target - rec.p), world, depth-1); |
1441 | 1444 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
|
1571 | 1574 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1572 | 1575 | vec3 ray_color(const ray& r, const hittable& world, int depth) { |
1573 | 1576 | hit_record rec; |
1574 | | - if (world.hit(r, 0.0, infinity, rec)) { |
1575 | | - // If we've exceeded the ray bounce limit, no more light is gathered. |
1576 | | - if (depth <= 0) |
1577 | | - return vec3(0,0,0); |
| 1577 | + |
| 1578 | + // If we've exceeded the ray bounce limit, no more light is gathered. |
| 1579 | + if (depth <= 0) |
| 1580 | + return vec3(0,0,0); |
| 1581 | + |
| 1582 | + if (world.hit(r, 0.001, infinity, rec)) { |
1578 | 1583 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1579 | 1584 | vec3 target = rec.p + rec.normal + random_unit_vector(); |
1580 | 1585 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
|
1583 | 1588 |
|
1584 | 1589 | vec3 unit_direction = unit_vector(r.direction()); |
1585 | 1590 | auto t = 0.5*(unit_direction.y() + 1.0); |
1586 | | - return (1-t)*vec3(1, 1, 1) + t*vec3(0.5, 0.7, 1.0); |
| 1591 | + return (1.0-t)*vec3(1.0, 1.0, 1.0) + t*vec3(0.5, 0.7, 1.0); |
1587 | 1592 | } |
1588 | 1593 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1589 | 1594 | [Listing [ray-color-unit-sphere]: <kbd>[main.cc]</kbd> ray_color() with replacement diffuse] |
|
1647 | 1652 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1648 | 1653 | vec3 ray_color(const ray& r, const hittable& world, int depth) { |
1649 | 1654 | hit_record rec; |
1650 | | - if (world.hit(r, 0.0, infinity, rec)) { |
1651 | | - // If we've exceeded the ray bounce limit, no more light is gathered. |
1652 | | - if (depth <= 0) |
1653 | | - return vec3(0,0,0); |
| 1655 | + |
| 1656 | + // If we've exceeded the ray bounce limit, no more light is gathered. |
| 1657 | + if (depth <= 0) |
| 1658 | + return vec3(0,0,0); |
| 1659 | + |
| 1660 | + if (world.hit(r, 0.001, infinity, rec)) { |
1654 | 1661 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1655 | 1662 | vec3 target = rec.p + random_in_hemisphere(rec.normal); |
1656 | 1663 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
|
1895 | 1902 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1896 | 1903 | vec3 ray_color(const ray& r, const hittable& world, int depth) { |
1897 | 1904 | hit_record rec; |
1898 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
| 1905 | + |
| 1906 | + // If we've exceeded the ray bounce limit, no more light is gathered. |
| 1907 | + if (depth <= 0) |
| 1908 | + return vec3(0,0,0); |
| 1909 | + |
1899 | 1910 | if (world.hit(r, 0.001, infinity, rec)) { |
1900 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1901 | | - // If we've exceeded the ray bounce limit, no more light is gathered. |
1902 | | - if (depth <= 0) |
1903 | | - return vec3(0,0,0); |
1904 | 1911 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1905 | 1912 | ray scattered; |
1906 | 1913 | vec3 attenuation; |
|
0 commit comments