Jump to content
  • Advertisement
Sign in to follow this  
serious_learner07

OpenGL surface normals and Vertex Normals

This topic is 3013 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



I have two questions regarding this topic.


1. whether OpenGL API glNormal3f computes Vertex Normal or Face Normal?
2. Face Normal or Vertex normal, which one is used for lighting calculations?

I am lot confused between these two types of normals.

Until today, I thought there is only one normal calculation. It is computed by taking cross product of two edges of a triangle. Suppose V1,V2 and V3 are the vertices of triangle, then Normal is the cross product between vector (V2-V1) and (V3-V2).

Can we call this cross product of edges as vertex Normals? If so, then how do you compute face normal.

Share this post


Link to post
Share on other sites
Advertisement
Nah the cross product is actually the face normal.
vertex normals are when you average the connecting faces into a single vertex normal.

Clear? :)

Share this post


Link to post
Share on other sites
glNormal3f doesn't compute anything. It just sets the current normal value that's used for light calculations.
"Face normal", as RouncED mentioned, can be calculated as the cross product of 2 edge "vectors". It is usually used for physics or the logic, not by the renderer (especially on modern GPU:s).
"Vertex normals" are normals specified by vertex (for every vertex). They are usually used by the renderer. They can be calculated/determined in may ways, a lot of modelling programs/tools can export vertex normals, so you don't have to calculate them yourself in the program. Usually vertex normals are calculated by averaging the face normals of the neighbouring polygons (as RouncED mentioned), taking "Smoothing Groups" into account.

To be honest, I suggest you to google the terms. I'm pretty sure you can find a lot of info about them.

Share this post


Link to post
Share on other sites
So Surface Normals and Vector Normals are computed in the following way.




// face Normal Computation
// Given edges(vector a and vector b) of a triangle
// we take its cross product to find the face normal.
vector* FaceNormal(vector* a, vector *b)
{

vector *FaceNormal = cross(a,b);
FaceNormal = Normalize(FaceNormal);
return FaceNormal;

}

// Vertex Normal computation.
// Suppose V1,V2,V3,V4 are vertices and V1,V2,V3 form a triangle
// and V1,V3,V4 form its adjacent triangle,then Using FaceNormal function
// we compute FaceNormal1(with edges V2V1 and V3V2) and
// FaceNormal2 (with edges V1V3 and V3V4) and then
// we compute the vertexNormal at V3, by averaging the FaceNormal1 and
// FaceNormal2.

vector VertexNormal(vector *FaceNormal1, vector *FaceNormal2)
{
Vector VertexNormal = (FaceNormal1 + FaceNormal2)/2;
VertexNormal = Normalize(VertexNormal);
return VertexNormal
}





Which Normal should we use for lighting calculations (i.e we specify in the function glNormal3f).

Share this post


Link to post
Share on other sites
Yeh thats right, except that when averaging normals, you can either divide by the amount (which is 2 in your example) or you can simply normalize, you dont have to do both.

Its the vertex normals that are used in lighting calculation, but with the geometry shader, you can compute face normals on the fly and flat shade.

Share this post


Link to post
Share on other sites
Um... you can't just calculate vertex normals like that.
You have to sum all the face normals of all the neighbour polygons, and you should weigh them too. After that, you have to normalize the result.
And take smoothing groups into account, or split the mesh according to the smoothing groups (you have to split the mesh if you use VBO-s).

weighing: there are different methods: you can weigh by the area of the polygons, you can weigh by the angle between the two edges that go into the vertex, etc

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!