03-19-2004, 05:13 AM
I'm now learning bump mapping technique with the orange book,
but I don't understand how to calculate tangent vector.
According to the book,
tangent vector can be computed as;
vec3 t = normalize(gl_NormalMatrix * Tangent);
but there's no details to how to set up Tangent variable.
More, the source code doesn't have been uploaded at 3dshaders.com.
help! need a little help!
03-19-2004, 09:23 AM
For texture local space you need to have at least two or three vectors to specify the local orientation of a vertex.
The normal is the local z-axis, you already have this in most models, the tangent is the local x-axis, the binormal (the cross product of normal and tangent in a right-handed coordinate system)
How to generate these for an arbitrary model which has normals is tricky. (That's the part you're looking for?)
Choose an up-vector of you model, the up-direction and the normal build a plane, the normalized cross-product of the up-vector and the normal gives the tangent. Another cross vector gets the right binormal.
This doesn't work if the up vector is colinear with the normal, but hey, you can define another right-direction. Or a cylindical wrap-direction along the tangents around the model.
If you have the tangent, binormal and normal, just sent them as additioinal vertex attributes, normal is obvious, tangent and binormal are put into glMultiTexCoord3f calls normally, you could also use the glColor3f if you don't need a color.
The simplest thing for first steps would be an xy-quad where all four vertices get the same local axis vectors, tangent = (1,0,0), binormal = (0,1,0), normal = (0,0,1).
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.