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
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
> 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
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
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
I don't quite understand that - how exactly would that look?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok I guess the formula is setup now, just have to see if it works now.
r = 128 * d;
g = 50 * d;
b = 0 * d;
Yes. that's the right idea