Skip to content

Commit 8d2ce9a

Browse files
committed
Reorder ray_color() parameters
1 parent a82bb45 commit 8d2ce9a

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

books/RayTracingTheNextWeek.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,7 @@
17351735
the new `emitted` value.
17361736

17371737
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1738-
vec3 ray_color(const ray& r, hittable& world, const vec3& background, int depth) {
1738+
vec3 ray_color(const ray& r, const vec3& background, hittable& world, int depth) {
17391739
hit_record rec;
17401740

17411741
// If we've exceeded the ray bounce limit, no more light is gathered.
@@ -1752,13 +1752,15 @@
17521752
if (!rec.mat_ptr->scatter(r, rec, attenuation, scattered))
17531753
return emitted;
17541754

1755-
return emitted + attenuation * ray_color(scattered, world, background, depth-1);
1755+
return emitted + attenuation * ray_color(scattered, background, world, depth-1);
17561756
}
17571757
...
17581758

17591759
int main() {
17601760
...
1761-
color += ray_color(r, world, vec3(0,0,0), max_depth);
1761+
const vec3 background(0,0,0);
1762+
...
1763+
color += ray_color(r, background, world, max_depth);
17621764
...
17631765
}
17641766
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/TheNextWeek/main.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <iostream>
2424

2525

26-
vec3 ray_color(const ray& r, hittable& world, const vec3& background, int depth) {
26+
vec3 ray_color(const ray& r, const vec3& background, hittable& world, int depth) {
2727
hit_record rec;
2828

2929
// If we've exceeded the ray bounce limit, no more light is gathered.
@@ -41,7 +41,7 @@ vec3 ray_color(const ray& r, hittable& world, const vec3& background, int depth)
4141
if (!rec.mat_ptr->scatter(r, rec, attenuation, scattered))
4242
return emitted;
4343

44-
return emitted + attenuation * ray_color(scattered, world, background, depth-1);
44+
return emitted + attenuation * ray_color(scattered, background, world, depth-1);
4545
}
4646

4747

@@ -451,7 +451,7 @@ int main() {
451451
auto u = (i + random_double()) / image_width;
452452
auto v = (j + random_double()) / image_height;
453453
ray r = cam.get_ray(u, v);
454-
color += ray_color(r, world, background, max_depth);
454+
color += ray_color(r, background, world, max_depth);
455455
}
456456
color.write_color(std::cout, samples_per_pixel);
457457
}

0 commit comments

Comments
 (0)