How to computing the vertex normal vector?

Dear All:
I am learning to write a Phong shader using GLSL. I think the normal vector of each vertex should be computing correctly and provided to the vertex shader and fragment shader to simulating phong mode. How to computing vertex normal vector of a triangle mesh?
I refer to the codes in OpenGL SuperBible, in these codes, GLBatch class is used to represent a triangle mesh and draw the mesh.
I find that the example codes of SuperBible didnot compute the vertex normal, but in the vertex shader and fragment shader, vertex normal vector is used to calculate diffuse and specular components as a input , does the GLBatch class compute vertex normal automatically?

The simple, straight forward way to compute vertex normals for a generic polygon mesh is to compute the normal for each triangle and take the averge of all triangles that a vertex is attached to.

This can be done by setting all normals to 0, adding the normalized normal of each triangle to all vertices of the triangle and then normalizing all the vertex normals.
I don’t know if the GLBatch class does that. I don’t own the blue book and never took a look at it.

In some cases, the vertex normals do not match the averaged adjacent triangle normals, because of the actual shape of the sampled geometry, so ideally you would want to use a model file format where you simply load the normals exported from a modelling program.

[QUOTE=Agent D;1260719]The simple, straight forward way to compute vertex normals for a generic polygon mesh is to compute the normal for each triangle and take the averge of all triangles that a vertex is attached to.

This can be done by setting all normals to 0, adding the normalized normal of each triangle to all vertices of the triangle and then normalizing all the vertex normals.
I don’t know if the GLBatch class does that. I don’t own the blue book and never took a look at it.

In some cases, the vertex normals do not match the averaged adjacent triangle normals, because of the actual shape of the sampled geometry, so ideally you would want to use a model file format where you simply load the normals exported from a modelling program.[/QUOTE]

Thank you! I use meshlab to computer vertex normal and read them into OpenGL

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.