dilevin / computer-graphics-ray-tracing

Computer Graphics Assignment about Ray Tracing
1 stars 5 forks source link

Loading bar for main.cpp #84

Open gursi26 opened 1 day ago

gursi26 commented 1 day ago

No question here, just wanted to mention that one could slightly alter main.cpp to add a loading bar, so you have an idea of how long a render will take. The slightly modified main loop is below.

    int c = 0;
    double max_c = height * width;

    // For each pixel (i,j)
    for (unsigned i = 0; i < height; ++i)
    {
        for (unsigned j = 0; j < width; ++j)
        {
            c += 1;

            // Set background color
            Eigen::Vector3d rgb(0, 0, 0);

            // Compute viewing ray
            Ray ray;
            viewing_ray(camera, i, j, width, height, ray);

            // Shoot ray and collect color
            raycolor(ray, 1.0, objects, lights, 0, rgb);

            // Write double precision color into image
            auto clamp = [](double s)
            { return std::max(std::min(s, 1.0), 0.0); };
            rgb_image[0 + 3 * (j + width * i)] = 255.0 * clamp(rgb(0));
            rgb_image[1 + 3 * (j + width * i)] = 255.0 * clamp(rgb(1));
            rgb_image[2 + 3 * (j + width * i)] = 255.0 * clamp(rgb(2));

            printf("[%f / 100]\r", 100 * (c / max_c));
            fflush(stdout);
        }
    }

This will output how much of the render is complete (out of 100).