I have a 3ds loader that also compute per face normals, per face tangents and per face binormals.
But the results is ugly (not smooth).
To make it smooth I must compute the per vertex normals, per vertex tangents and per vertex binormals. Any idea how I will do that?
Try iterating over each triangle in the mesh, calculating each triangle’s normal as you go, and adding the normal to each vertex in the triangle.
for( each mesh triangle T )
Vertex& A = verts[T.indices];
Vertex& B = verts[T.indices];
Vertex& C = verts[T.indices];
// Assume a clockwise winding
Vector N = normalize(cross(C.pos - A.pos, B.pos - A.pos));
// Accumulate normals
A.N += N;
B.N += N;
C.N += N;
Once you have iterated the entire triangle list, iterate over the vertices and normalize the normals. From these vertex normals you can derive the tangent and binormal vectors using a variety of methods.
I assume you already have the data structures in place.
I recently did something of that sort for Doom 3 models (though I’m having a normalizing cube map dilemna)… anyways, the bottom of this page Bump mapping tutorial mentions breifly how to do the tangent, normal, and binormal for a polygon, and it is easily extened to a mesh, by summing the per triangle tangent basis vectors (normal, binormal, tangent) for each component vertex in the triangle, then normalizing the three vectors for each vertex after going through all of the triangles. Next, for each vertex, compute the vector to the light source(s), and eye position for specular lighting, and the transformed tangent space VertexToLight and VertexToEye are:
TSLight.x = sTangent DOT3 VertexToLight;
TSLight.y = tTangent DOT3 VertexToLight;
TSLight.z = vertNormal DOT3 VertexToLight;
TSEye.x = sTangent DOT3 VertexToEye;
Mike, did you fix your cubemap?
I’ve been playing with those Doom3 models recently, too. Cyberdemon blew me clean away :eek: