# Little problem while calculating vertex normals (OpenGL ES)

No replies to this topic

New Member

• Members
• 1 posts

Posted 13 April 2011 - 05:59 AM

Hy guys,

I'm having a little problem with the vertex normal.

The result seems a little strange. First a look at the images:

Original model in 3D software.

Per-Fragment lighting, with mesh imported directly from an OBJ file (using normals from file).

Per-Fragment lighting, calculating the normals with my own routine.

Did you notice?
Using the normals from OBJ file everything is OK. But when I use my own routine to calculate the normals based on vertices something seems wrong.

The normals seems strange exactly when the Z becomes negative (using a Right-Hand orientation). On the other parts of the object everything is OK, but just one imaginary line across the mesh seems strange. This problem persists on others meshes, always at the same place, the Z = 0.

My routine to calculate the normals is there which everyone knows, assuming a triangle with vertices ABC:

vec3 normal = normalize(cross(C - A, B - A));

And then adding the normal result to an already calculated normal buffer.

I've seen some guys saying about calculate the area of each triangle and multiply it by the normal or even checking against the dot product between the normal on the buffer and the new normal, but I've already tried those approachs and I caught just little changes, but still with the same problem.
I also tried normalize the normals once, just after sum all normals of a vertex, but nothing seems interfere in the bug when Z = 0.

Did you seen this before? Do you know how to solve that?