Search code examples
c++graphicscolorsrenderingraytracing

Raytracer help - Background color writing over some colors?


I'm implementing Peter Shirley's "Raytracer in a Weekend: The next week" and I'm having some trouble with rendering a scene with a light. I'm not sure if the issue is the background color or the light itself but the raytracer seems to be working fine in any scenes that have no lights.

The image rendered is supposed to be: enter image description here

but actually turns out as: enter image description here

When I try to troubleshoot and change the background color to blue the image is:

enter image description here

Any ideas why this could be??


Solution

  • I found my answer here :https://computergraphics.stackexchange.com/questions/10160/raytracer-help-background-color-writing-over-some-colors

    @PaulHK helped me realize that there was a bug in my Lambertian class and once I realized this, the image rendered perfectly

    This was his answer: " just had a quick browse through your code. In Lambertion::scatter there is a comment about attenuating light based on distance. For a raytracer this is not required as the distribution of rays themselves cause attenuation over distance. Typically albedo values get multiplied by the current paths attenuation (an exception would be importance sampling as that uses weighted samples) I didn't check the whole project source so I'm making a bit of a guess."