0
$\begingroup$

I am trying to create a raytracer following peter shirley's in a weekend series. I am getting weird color distortion artifacts when I am running the code on windows. However, the code runs fine when executed on the on my mac. The only difference in code being that I had to replace drand48() with (float)rand() / (RAND_MAX + 1.0) as the former is not supported on windows.

How the image looks on windows enter image description here

How it should look enter image description here

Heres the code I am using to generate the ppm file

void writeToImgae(Vector3f *frameBuffer, RenderOptions *options)
{
    ofstream ofs("finalImage.ppm", ios::out);
    ofs << "P6\n"
            << options->width << " " << options->height << "\n255\n";
    for (uint32_t i = 0; i < options->height * options->width; ++i)
    {
        char r = (char)(255 * clamp(frameBuffer[i].x, 0.0f, 1.0f));
        char g = (char)(255 * clamp(frameBuffer[i].y, 0.0f, 1.0f));
        char b = (char)(255 * clamp(frameBuffer[i].z, 0.0f, 1.0f));
        ofs << r << g << b;
    }
    ofs.close();
    delete[] frameBuffer;
}

Would really appreciate if someone could help me with this.

$\endgroup$
2
  • $\begingroup$ Try my fork of the code: github.com/vchizhov/InOneWeekend-1 If it works it's probably due to the rng, in which case you can use the random() from my fork in rng.hpp. We discussed this in one of the issue, but it still hasn't been implemented. $\endgroup$
    – lightxbulb
    Sep 8, 2019 at 16:52
  • 2
    $\begingroup$ Also shouldn't you ofs << r << "\t" << g << "\t" << b << "\n";? $\endgroup$
    – lightxbulb
    Sep 8, 2019 at 21:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.