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.

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.

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.

[QUOTE=tmason;1262155]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.[/QUOTE]

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.

[QUOTE=ahad0001;1262197]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 ?[/QUOTE]

An easy way to visualize your normals is to draw them using lines, using {position, position + normal} as the start & end points.