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 7 of 7

Thread: Easy way to test whether you are loading normals correctly?

  1. #1
    Junior Member Regular Contributor
    Join Date
    Apr 2014
    Posts
    109

    Easy way to test whether you are loading normals correctly?

    Hello,

    I think this might be a simple question but I thought I would ask experts in the forums.

    Is there a way to test whether you are loading normal correctly?

    Like a simple vertex/fragment shader code test to ensure that the normal for the vertex are correct, etc.?

    Thank you for your time.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    894
    In general, you can not do that. The normals are artist designed to help preserve the "look" of the surface the triangle mesh is approximating, so in general they can not be computed from the mesh.
    You can do a sanity check: test if the vertex normals of a triangle are pointing into the "front" half space defined by the triangle. In other words test if dot(faceNormal, vertexNormal) > 0 where faceNormal is the normal of the plane defined by the triangle's three vertices and pointing away from the front side of the triangle (as defined by the triangle's winding). This can produce false positives, but I think it should be rare; I'm not sure how many false negatives it may have, i.e. how many cases of "bad" normals are not detected this way.
    It seems easier to runs this test on the CPU (it should be a one time test anyway, not something you run every frame?). If you want to do it on the GPU I think you'll need a geometry shader, since you need to access all three vertices of a triangle to find the face normal to compare your vertex normals against.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,526
    A reasonable "sanity check" is to average the vertex normals for each face, and compare the normalised result against the normalised face normal (via dot product, giving the cosine of the angle between the vectors).

    Statistically, the results should be clustered around 1.0 (i.e the average vertex normal should be a close approximation to the face normal). If the results are clustered around -1.0, the normals are inverted. If the results show wide variation (including significant proportions of both positive and negative values), the normals are garbage.

  4. #4
    Intern Contributor
    Join Date
    Jul 2014
    Location
    Italy, Lissone
    Posts
    80
    Quote Originally Posted by tmason View Post
    Hello,

    I think this might be a simple question but I thought I would ask experts in the forums.

    Is there a way to test whether you are loading normal correctly?

    Like a simple vertex/fragment shader code test to ensure that the normal for the vertex are correct, etc.?

    Thank you for your time.
    the way to know if the normals are correct (most of the time) is send them to a fragment shader and draw them like colors, from a frontal position green should be up, blue should be at left and red should be at right.

  5. #5
    Actually i am new in OpenGL coding.. How can i learn more about OpenGL .. How can i start coding with OpenGL ?
    Anyone have a great suggestion ?

  6. #6
    Junior Member Regular Contributor
    Join Date
    Apr 2014
    Posts
    109
    Quote Originally Posted by ahad0001 View Post
    Actually i am new in OpenGL coding.. How can i learn more about OpenGL .. How can i start coding with OpenGL ?
    Anyone have a great suggestion ?
    http://www.opengl-tutorial.org/

  7. #7
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    456
    An easy way to visualize your normals is to draw them using lines, using {position, position + normal} as the start & end points.

Tags for this Thread

Posting Permissions

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