We help IT Professionals succeed at work.

lighting a face of a polygon

DJ_AM_Juicebox
on
290 Views
Last Modified: 2013-12-26
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
Comment
Watch Question

ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
   double d = cos(A);
     r = 128 * d;
     g = 50 * d;
     b = 0 * d;
Yes. that's the right idea
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
> 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

Author

Commented:
> 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
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Ok I guess the formula is setup now, just have to see if it works now.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.