raytracing.github.io
raytracing.github.io copied to clipboard
Book 1 Chapter 7.2 `dev_major`: `render` part of code has bug (sphere shape is unstable)
with this code: https://github.com/RayTracing/raytracing.github.io/blob/806ab499cc220d044f4abff57fe01612bd9a6e82/books/RayTracingInOneWeekend.html#L1626-L1633
image output is unstable:
1st run
2nd run
3rd run
and many more. notice how unstable the bottom and top of the sphere is. however, with the original code in master
, a stable image is produced:
1st run
2nd run
3rd run
put the line under row(height) for loop auto t = (j + random_double()) / (image_height-1);
inside antialiasing sampling for loop. your code should looks like following.
for (int j = 0; j < image_height; ++j) { std::clog << "\rScanlines remaining: " << (image_height - j) << ' ' << std::flush;
for (int i = 0; i < image_width; ++i) {
color pixel_color(0, 0, 0);
for (int sample = 0; sample < samples_per_pixel; ++sample) {
auto t = (j + random_double()) / (image_height-1);
auto s = (i + random_double()) / (image_width-1);
std::clog << t << std::endl;
ray r = cam.get_ray(s, t);
pixel_color += ray_color(r, world, max_depth);
}
write_color(std::cout, pixel_color, samples_per_pixel);
}
}
if you leave that t value only changes every time you go to next scanline, you will have vertical sampling insufficient which looks like the results you posted above.
@xw901103 that's my point, the code that they gave in dev_major
is wrong.
Sorry for the delay. Yes, this is a definite bug I introduced. Thank you for catching it.
Fixed in PR #1097.