Skip to content

Commit 7b300b3

Browse files
committed
InOneWeekend: update ray_color() to match source
Resolves #391
1 parent 812edae commit 7b300b3

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

books/RayTracingInOneWeekend.html

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@
10861086
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
10871087
vec3 ray_color(const ray& r, const hittable& world) {
10881088
hit_record rec;
1089-
if (world.hit(r, 0.0, infinity, rec)) {
1089+
if (world.hit(r, 0.001, infinity, rec)) {
10901090
return 0.5 * (rec.normal + vec3(1,1,1));
10911091
}
10921092

@@ -1408,6 +1408,7 @@
14081408
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
14091409
vec3 ray_color(const ray& r, const hittable& world) {
14101410
hit_record rec;
1411+
14111412
if (world.hit(r, 0.0, infinity, rec)) {
14121413
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
14131414
vec3 target = rec.p + rec.normal + random_in_unit_sphere();
@@ -1432,10 +1433,12 @@
14321433
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
14331434
vec3 ray_color(const ray& r, const hittable& world, int depth) {
14341435
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)) {
14391442
vec3 target = rec.p + rec.normal + random_in_unit_sphere();
14401443
return 0.5 * ray_color(ray(rec.p, target - rec.p), world, depth-1);
14411444
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
@@ -1571,10 +1574,12 @@
15711574
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
15721575
vec3 ray_color(const ray& r, const hittable& world, int depth) {
15731576
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)) {
15781583
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
15791584
vec3 target = rec.p + rec.normal + random_unit_vector();
15801585
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
@@ -1583,7 +1588,7 @@
15831588

15841589
vec3 unit_direction = unit_vector(r.direction());
15851590
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);
15871592
}
15881593
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15891594
[Listing [ray-color-unit-sphere]: <kbd>[main.cc]</kbd> ray_color() with replacement diffuse]
@@ -1647,10 +1652,12 @@
16471652
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
16481653
vec3 ray_color(const ray& r, const hittable& world, int depth) {
16491654
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)) {
16541661
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
16551662
vec3 target = rec.p + random_in_hemisphere(rec.normal);
16561663
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
@@ -1895,12 +1902,12 @@
18951902
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
18961903
vec3 ray_color(const ray& r, const hittable& world, int depth) {
18971904
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+
18991910
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);
19041911
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
19051912
ray scattered;
19061913
vec3 attenuation;

0 commit comments

Comments
 (0)