Archived

This topic is now archived and is closed to further replies.

jvff

Diffuse lighting problem

Recommended Posts

Hello, I''m currently trying to implement lighting on my raytracer. I started off by Phong shading but it wasn''t working. So I decided to take it step by step. So I started to implement Diffuse lighting. The problem is I can''t seem to get it working. My code: r = r + r * lr * normal.dot(light) * diff; Where r is surface color, lr is light color, normal and light are unit vectors and diff is the surface''s diffuse constant. When debugging, the resulting color differences along a sphere are tiny, making the first 2 digits always the same, producing a sphere with a single color when converted to 24 bit colors for printing on screen. The back of the sphere is black, meaning it isn''t receiving any light, which is correct. But what about the monocolor? Is there some error on my code? Thank you for your answers, JVFF

Share this post


Link to post
Share on other sites
I think you''ve got one too many ''r''s in there - I''ve not done raytracing, but it would make sense to me that

color at a point = sum of all ( lightcolor * normal.dot(light) * diff)

If you''re doing that iteratively I can understand the first ''r = r'' bit, but are you sure you should be multiplying that second term by r?

Share this post


Link to post
Share on other sites