• 10-17-2014, 02:56 AM
tmason
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.?

• 10-17-2014, 04:29 AM
carsten neumann
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.
• 10-17-2014, 07:00 AM
GClements
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.
• 10-17-2014, 01:43 PM
Ruggero Visitnin
Quote:

Originally Posted by tmason
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.?

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.
• 10-19-2014, 03:12 PM
tmason
Quote: