Advertisement

Better OpenGL Lighting tutorial

Started by January 22, 2003 11:04 PM
4 comments, last by sakky 22 years, 1 month ago
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?
Take back the internet with the most awsome browser around, FireFox
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 - |
Advertisement
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.
Take back the internet with the most awsome browser around, FireFox
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 )
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 - |
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.

This topic is closed to new replies.

Advertisement