I am making a raytracer and I added diffuse coloring. Actually, it is working but if there are multiple objects in a pixel it doesn't give correct result. However, If I remove one object and render image it gives correct result. By the way, sphere is front of mesh I checked it. I mean
It adds just ambient lighting because the diffuse color function returns zero since N.L is negative.
What can I do? I mean is it a common mistake for ray tracing?
You might want to check for the part that intersects your ray with the sphere, and the plane, and returns the closest hit.
For the black pixels on the bottom sphere, the following should happen: