Notes about tangent vectors.

This explains what tangent vectors are good for.

In some cases it might be useful to compute things not in model-space coordinates but in texture space coordinates. For example, if you look up a vector in a texture map, this vector has usually an orientation relative to the projection plane. If you rotate this triangle that uses this vector, the vector must be rotated as well. The problem is to find the rotation matrix.

This is where tangent vectors come into play. The shader editor provides two additioal vertex attributes:

attribute vec3 attrTangent;
attribute vec3 attrBitangent;

These tangent vectors define an orthogonal coordinate system in texture space. They are created for each vertex by using the positions and texture coordinates of the incident triangle. The 'attrTangent' vector represents the positive 's' axis of the 2D texture coordinates in the 3D triangle and the 'attrBitangent' represents the positive 't' axis of the 2D texture coordinates in the 3D triangle.

You can visualize the tangent vectors by checking the 'Show tangent spaqce' check-box in the scene tab. The tangent is drawn in red, the bitangent in green and the vertex normal in blue.

The tangent, bitangent and normal attributes of a vertex define an orthonormalbasis. You can use this basis to transform vectors out of the texture space coordinate system ( also called tangent space ) to the model space coordinate system in which your test model is defined. If you want to transform a model space vector into tangent space, you must multiply that vector with the transpose of this matrix.

To create a matrix, that transforms from tangent to model space, you can do the following:

mat3 tangentToModelMatrix;
tangentToModelMatrix[0] = attrTangent;
tangentToModelMatrix[1] = attrBitangent;
tangentToModelMatrix[2] = gl_Normal;

and transforming a tangent space vector is done with a multiplication:

vec3 tangentVector = ...
vec3 modelVector = tangentToModelMatrix * tangentVector;


Generated on Sun Mar 2 17:12:31 2008 for Shader Maker by  doxygen 1.5.4