Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / light source direction with phong Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Peter Bone

March 11, 2005, 08:17 AM

I'm writing a phong shader for my software renderer. I've written the code to interpolate the vertex normals across the triangle but then I realized that the direction to the light source vector will also change across the surface (assuming the light source is fairly close to the objects and the triangles are fairly large). How do people deal with this? Do you also interpolate the light source direction vectors across the surface or do you calculate the position of each pixel in 3D space and calculate the source direction for each one or what? Maybe you just make sure the light source is a long way away but I like the variation of intensity that a close light source creates on large flat surfaces - using my Gouraud shader.

Thanks

Peter Bone

 
Reedbeta

March 11, 2005, 02:40 PM

Yes, we linearly interpolate the vector to the light source over the triangle, in the same way that vertex normals are interpolated.

Note that both normals and light vectors should be normalized after interpolation (i.e. for each pixel). Vertex normals should also be normalized before interpolation (in addition to after interpolation), but light vectors should NOT be normalized before interpolation.

 
Peter Bone

March 14, 2005, 07:46 AM

Thanks. Yes I'm normalizing my vertex normals before and after interpolation. Why should the light source direction not be normalized before interpolation?
Also, does anyone know where I can find a fixed point square root function (preferably in pascal) to speed up my normalization? It's now the only bit of floating point I'm still using.

Thanks

Peter Bone

 
Reedbeta

March 14, 2005, 11:39 PM

If the light source direction is normalized before the interpolation, then the output of the interpolation will not be correct - the resulting vector will not point at the light. It would be too complicated to show why with ASCII-art, but you can see this most easily by drawing a diagram that shows the light source close to one corner of a triangle - consider what happens to the light source vector as it is interpolated, and what would happen if you normalized it before interpolation.

 
This thread contains 4 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.