Link to home
Start Free TrialLog in
Avatar of DJ_AM_Juicebox
DJ_AM_Juicebox

asked on

lighting a face of a polygon

Hi,

I needed help with figuring out how to shade a polygon face in my primitive 3d rendering engine. Interactive mind, you gave me a solution, I want to see if these are the correct steps:

1) Find center (x,y,z) point of the face by averaging the location of its vertices.
2) Find the vector that points from the center point above to the light source (p).
Q: What is my light source anyways? I mean, do I just pick an x,y,z lightsource somewhere in my scene and that's it? I'd like to use just a constant directional light I think.
3) Find the surface normal of the face (N).
4) Find the cosine of the angle between p and N (A).
5) Multiply each RGB component of my face color by Cos A.
Q: What does that look like? Take a fictional RGB component (128, 50, 0):

     double d = cos(A);
     r = 128 * d;
     g = 50 * d;
     b = 0 * d;

I know the extra bit to make it a bit more realistic was added, but if I can get the above working first that will be a good start.

Thanks
Avatar of ozo
ozo
Flag of United States of America image

   double d = cos(A);
     r = 128 * d;
     g = 50 * d;
     b = 0 * d;
Yes. that's the right idea
> I'd like to use just a constant directional light I think.
Then put the light source at infinity so you just use a fixed vector to the light source regardless of the where the center of the face is
Avatar of DJ_AM_Juicebox
DJ_AM_Juicebox

ASKER

> Then put the light source at infinity so you just use a fixed vector to the light source regardless of the where the center of the face is

I don't quite understand that - how exactly would that look?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok I guess the formula is setup now, just have to see if it works now.