Calculating the deformed Tangent

I’m using a normal skinning system to deform my vertex positions and normals (X number of bones + per vertex weighting).

I also have a Tangent attribute. I’m doing the deformation in shader, so instead of deforming the tangent by the same code as the normal, I’d like to recreate the tangent using the old normal and tangent and the new deformed normal.

Here is what I’ve come up with:
Tangent.w holds the handedness of the system. I.e the desired direction of the binormal compared to the normal/tangent.
If w is 1 then the system is left handed,
if w is -1 then the system is right handed.

binormal = cross(Normal, Tangent) * Tangent.w

deformedTangent = cross(binormal, deformedNormal) * Tangent.w

As far as I can tell this gives the correct results. I’m pretty sure it always gives a perpendicular vector to the normal, but I’m wondering if it will always point in the correct direction?

Any thoughts?

like this?

http://www.terathon.com/code/tangent.html

Ya, thats the code I use to generate my original Tangent.

I’m not quite sure what you’re up to here. Do you intend to keep the tangent basis orthonormal, or do you want to shear it slightly?

In either case it seems like it should work alright, as long as dot(deformed,original) > 0 (i.e. deformed normal is on the positive half-space of the original tangent plane). That is it should have roughly the same orientation, albeit slightly rotated or sheared with respect to the original.

The intent is to recreate an orthonormal tangent basis after the normal has been deformed. I could simply subject the tangent to the same deformations as the normal, but I’d like to have a faster method if possible. This is what I came up.