Diffuse lighting calculations in ray-tracer I am trying to write a ray-tracer. The lighting part is proving to work but not accurately. To debug I simplified the scene to a single sphere centered at the origin with a radius of 1 and a point light shining from above (0, 2, 0). The camera is at (0, 0, 4).

ambient 0.2 0.2 0.2
specular 0 0 0
shininess 1
emission 0 0 0
diffuse 0 1 1 

The image I'm rendering seems wrong - should its cutoff be lower closer to the equator of the sphere?

Any help would be appreciated.
Some elementary trigonometry tells you what to expect from this situation.



The angle to see the shadow terminator is marked on the diagram, and a use of SOHCAHTOA tells you it's $\cos^{-1}\tfrac{1}{2} = 60^\circ$. Yours looks higher than that so your intuition seems correct. Stepping through the lighting code will help you see where it's going wrong, and you should consider writing unit tests for it, so that it's easier to provoke bugs like this in isolation.

Something else you might try to help narrow down the problem space is replacing the diffuse calculation with 1 iff $L.N &gt; 0$ (i.e. if the light is in front of the surface), 0 o/w. That will give you a sharp line instead of a gradient, and if that sharp line is in the wrong place, you know the input vectors are wrong. If it's in the right place, the problem is in the diffuse shader itself.