Skip to content

Commit e9662fc

Browse files
committed
Update scene:render() in source to match book 3
Fixes #1048
1 parent c8b2e64 commit e9662fc

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/TheRestOfYourLife/scene.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@ class scene {
2424

2525
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
2626

27+
int sqrt_spp = int(sqrt(samples_per_pixel));
2728
for (int j = image_height-1; j >= 0; --j) {
2829
std::clog << "\rScanlines remaining: " << j << ' ' << std::flush;
2930
for (int i = 0; i < image_width; ++i) {
3031
color pixel_color(0,0,0);
31-
for (int sample = 0; sample < samples_per_pixel; ++sample) {
32-
auto u = (i + random_double()) / (image_width-1);
33-
auto v = (j + random_double()) / (image_height-1);
34-
ray r = cam.get_ray(u, v);
35-
pixel_color += ray_color(r, max_depth);
32+
for (int s_j = 0; s_j < sqrt_spp; ++s_j) {
33+
for (int s_i = 0; s_i < sqrt_spp; ++s_i) {
34+
auto u = (i + (s_i + random_double()) / sqrt_spp) / (image_width-1);
35+
auto v = (j + (s_j + random_double()) / sqrt_spp) / (image_height-1);
36+
ray r = cam.get_ray(u, v);
37+
pixel_color += ray_color(r, max_depth);
38+
}
3639
}
3740
write_color(std::cout, pixel_color, samples_per_pixel);
3841
}

0 commit comments

Comments
 (0)