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?