PDA

View Full Version : Easy way to test whether you are loading normals correctly?



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

carsten neumann
10-17-2014, 05:29 AM
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.

GClements
10-17-2014, 08:00 AM
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.

Ruggero Visitnin
10-17-2014, 02:43 PM
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.

ahad0001
10-19-2014, 03:58 PM
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 ?

tmason
10-19-2014, 04:12 PM
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/

Dan Bartlett
10-20-2014, 02:26 AM
An easy way to visualize your normals is to draw them using lines, using {position, position + normal} as the start & end points.