Original Post
I've been working a lot on getting Tangent Space bump mapping working in my OpenGL renderer lately. I've got the shader for it built, got a routine to generated normals/tangents/bitangents very nicely (it's kinda like Nvidia's Mesh Mender), and I have really nice looking results if whatever you're rendering doesn't have any mirrored UV's... Unfortunately 90% of the animated models we're going to be using will be using a mirrored texture, so this is a problem. I realize fully well that the tangents and/or bitangents need to be "flipped" (inversed, in this case i think) on any triangles where the UV's are "reversed", but actually detecting that and flipping them is throwing me for a bit of a loop. First off: How do you detect if a tangent/bitangent needs to be flipped? At http://www.terathon.com/code/tangent.html they show how to calculate the "handedness" of the vector, which is simply:
tangent[a].w = (Dot(Cross(n, t), tan2[a]) < 0.0F) ? -1.0F : 1.0F;
In this case tan2 would be the bitangent, n is the normal, and t is the actual orthogonalized tangent. This makes a lot of sense (though I wonder why the don't cross the tangent and bitangent and compare that to the normal...), but doesn't seem to give me the results I would expect. In my mesh processing utility I've got it so that it generates "smoothing groups" for each vector. For the mesh normals that smoothing group is based on angle, but for the tangents and bitangents I've got it based on handedness as calculated above. This gives me two smoothing groups for each of 'em, and when processing the final, per-vertex normals I simply inverse any vectors that got put in the "-1" smoothing group. Sadly this doesn't work. For one, All of my faces seem to end up in the same group regaurdless of their orientation, but even more worrying than that is that even if I fudge the code to, say, always inverse the tangent vector, the lighting doesn't seem to change at all! This got me thinking: If the tangent is flipped, do you have the inverse the normal instead of the tangent? Everyone says that you have to flip the vectors on any mirrored UV's, but now that I think about it I don't know that I've ever heard anyone specify which vector to flip! If anyone has some insight into these questions (How do you figure out which vectors need flipping, and which ones do you flip when you do figure that out), I would be most appreciative! Thanks! [Edited by - Toji on September 30, 2005 12:47:01 AM]



