Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: How to computing the vertex normal vector?

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2014
    Posts
    14

    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?

  2. #2
    Junior Member Regular Contributor Agent D's Avatar
    Join Date
    Sep 2011
    Location
    Innsbruck, Austria
    Posts
    151
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2014
    Posts
    14
    Quote Originally Posted by Agent D View Post
    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.
    Thank you! I use meshlab to computer vertex normal and read them into OpenGL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •