# Bones and Normals-Binormals-Tangent

Hi all;
I wanna use bones for animation(instead of keyframe), but i didnt find any paper-source-information about calculating normals, binormals and tangent vectors for the mesh. Can anybody send me some links? thanx

Originally posted by Coluna:
Hi all;
I wanna use bones for animation(instead of keyframe), but i didnt find any paper-source-information about calculating normals, binormals and tangent vectors for the mesh. Can anybody send me some links? thanx

Transform the T/B/N vectors just like the vertex, only using the upper 3x3 (rotation) of the matrix.

This assumes that you use no non-uniform scale in your animation.

If you do use non-uniform scale, you have to send the transform matrix, and then the inverse transpose of the transform matrix, using the first for position, and the second for normal/tangent/binormal.

Note that this is, of course, a hack, just like skinning normals in general is. The REAL solution would be to re-derive normals from triangles post-skinning. However, that’s not possible (or, at least, feasible) in the current vertex programming model, so we’ll make do with the hack.

If you get T,B,N from model file (such as .fbx), and attached with an skeleton animation, and you want to calculate lighting and shadowing in world space, then, the TBN matrix could be calculated in vertexshader like:
vec3 T = normalize(vec3(model_matrix * weighted_skeleton_transform_matrix * vec4(tangent_from_model, 0)));
vec3 B = normalize(vec3(model_matrix * weighted_skeleton_transform_matrix * vec4(bitangent_from_model, 0)));
vec3 N = normalize(vec3(model_matrix * weighted_skeleton_transform_matrix * vec4(normal_from_model, 0)));
TBN = mat3(T, B, N);

and then pass TBN matrix to fragmentshader, extract the normal of normal texture of tangent space and convert it to the world space like this:
vec3 normal = normalize(texture(normal_texture, uv).rgb * 2.0 - 1.0);
normal = normalize(TBN * normal);

Then do lighting or shadowing. This calculation really confused me for a long time.