Jump to content
  • Advertisement

Archived

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

sakky

Better OpenGL Lighting tutorial

This topic is 5681 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Will there be a better OpenGL lighting tutorial from NeHe. I would like to see one that goes over glColorMaterial and other things that surround it. Maybe a few tips and tricks on how to get SMOOTH lighting using vertex normals and what not. I would also like to see some vertex_program tutorials from NeHe. Are there any thoughts on some in the near future?

Share this post


Link to post
Share on other sites
Advertisement
I would aggree that lighting is something thats quite complex to get right. (it''s simple when you know how gl handles it), it''s just it doesn''t initially seem logical. (even though it really is), so we need a good tutorial.

I don''t really see any point in a tut on vertex programs. I can''t really explain my reasons for this view without offending a lot of people. So I won''t.

| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |

Share this post


Link to post
Share on other sites
Yes, a vertex_program tutorials would be a little odd wouldn''t it? Because they are all made for different reasons. I should restate my question to a more appropiate one. How would you load and use one with OpenGL.

I would like to know how to get the vertex normals. I have a model format that is in a most early stage od development. Its a text file that has all the vertex infromation in it.

I have face normals as of right now. But I would like to use vertex normals to get better shading effects. So I would like to know how to compute the vertex normal.

Share this post


Link to post
Share on other sites
If you have the face normals, finding the vertex normals is easy. All you do is loop through each vertex, checking to see if a face indexes it, and if so, add its normal to the vertex normal. Once you finish looping through all of the faces, you divide the vertex normal by the number of faces that share it, keeping a variable to keep track of this during the loop is ideal.
So say the vertex is shared by 3 faces, the math would end up looking like this (The loop does this for you, this is just an expanded example).

VertexNormal = (Face1.Normal + Face2.Normal + Face3.Normal)/3
All it is really doing is finding the average.

After you do this for every vertex in the model, you''ll have the vertex normals. For a code example, you can head on over to gameTutorials''s 3ds model loading code. It shows how to mass-compute vertex normals.

(If I screwed anything up or unclear please correct me )

Share this post


Link to post
Share on other sites
don''t divide by the number of faces, normalize the normal.

eg,

say you add:

1,0,0
and
0,1,0

divide by two you get:

0.5,0.5,0

normalize you get:

0.707,0.707,0

different normal...

| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |

Share this post


Link to post
Share on other sites
I remember having posted a vertex program example with source code and a complete walkthrough. I think you still can find it in the dowloads section (of NeHe Productions homepage) under the letter ''c''. It''s a remake of the cel-shading tutorial.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!