raytracing.github.io icon indicating copy to clipboard operation
raytracing.github.io copied to clipboard

Book 1 Chapter 7.2 `dev_major`: `render` part of code has bug (sphere shape is unstable)

Open LollipopFt opened this issue 2 years ago • 1 comments

with this code: https://github.com/RayTracing/raytracing.github.io/blob/806ab499cc220d044f4abff57fe01612bd9a6e82/books/RayTracingInOneWeekend.html#L1626-L1633

image output is unstable: 1st run image 2nd run image 3rd run image

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 image 2nd run image 3rd run image

LollipopFt avatar Aug 27 '22 06:08 LollipopFt

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 avatar Sep 19 '22 12:09 xw901103

@xw901103 that's my point, the code that they gave in dev_major is wrong.

LollipopFt avatar Sep 25 '22 10:09 LollipopFt

Sorry for the delay. Yes, this is a definite bug I introduced. Thank you for catching it.

hollasch avatar Sep 28 '22 20:09 hollasch

Fixed in PR #1097.

hollasch avatar May 11 '23 04:05 hollasch