# 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:

but it actually turns out as:

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

Hopefully someone who has implemented this raytracer before or who has intuition about raytracing has an idea why this might be happening??

• Are you using bvh? If you are, can you try disabling it and see what you get? – lightxbulb Aug 29 at 10:54
• @lightxbulb thanks for the reply! I was not using BVH for this example, but tried to disable it from the project anyways and it didn't make a difference in the rendered output... – Jackie Aug 29 at 14:31
• I looked through your code, and nothing struck me as wrong at first glance, that's why I suggested testing without a bvh. Currently my only guess is that it could be an issue due to self-intersection, since the lighting seems to fail at angles that are more shallow. I would suggest trying to change: if(!scene.hit(r, 0.001, infinity, rec)) to if(!scene.hit(r, 0.01, infinity, rec)) and see if that changes anything. – lightxbulb Aug 29 at 16:03
• @lightxbulb hmm.. this still didn't change how the render looks. But thanks for the help and direction! I will keep troubleshooting and if you think of any other ideas, let me know :) – Jackie Aug 29 at 21:42
• I 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. – PaulHK Aug 31 at 7:21