I have a little problem with a normal top.
The result seems a little strange. First look at the images:
Original model in 3D software.
http://img233.imageshack.us/img233/4421/screenshot20110412at707.png
Perforated lighting with a grid imported directly from an OBJ file (using normals from a file).
http://img97.imageshack.us/img97/2960/screenshot20110412at708.png
Perfraction lighting, calculating normals using my own program.
http://img508.imageshack.us/img508/2960/screenshot20110412at708.png
You noticed? Using normals from an OBJ file is all right. But when I use my own procedure to calculate vertex-based normals, something seems wrong.
The normals seem strange when Z becomes negative (using the orientation of the right hand). In other parts of the object, everything is in order, but only one imaginary line on the grid seems strange. This problem persists on other grids, always in the same place, Z = 0.
My normal calculation routine is what everyone knows, assuming a triangle with ABC vertices:
vec3 normal = normalize(cross(C - A, B - A));
And then adding the normal result to the already calculated normal buffer.
I saw some guys talking about calculating the area of ββeach triangle and multiplying it by normal or even checking on a dot product between normal in the buffer and the new normal, but I already tried these approaches and I caught only small changes, but still with the same a problem.
Have you seen this before? Do you know how to solve this?
Here is the code:
// Looping at each triangle vec3 distBA = vec3Subtract(vB, vA); vec3 distCA = vec3Subtract(vC, vA); vec3 normal = vec3Cross(distBA, distCA); // Each normalBuffer represents one vertex. normalBuffer[i1] = vec3Add(normal, normalBuffer[i1]); normalBuffer[i2] = vec3Add(normal, normalBuffer[i2]); normalBuffer[i3] = vec3Add(normal, normalBuffer[i3]); // After pass through all faces/triangles. // Looping at each Vertex structure. normal = vec3Normalize(normalBuffer[i]);
Thanks in advance.