Skip to main content
gamedev.net
🔒 Locked

Computing tangent vector

Started by LukeSkyRunner Apr 19, 2004 at 3:51 PM 0 replies 300+ views
Original Post
LukeSkyRunner
LukeSkyRunner
According to the tutorial about per pixel lighting I''m reading, to compute the tangent vector of a polygon we must do the following operations: Vec1 = Vertex3 – Vertex2 Vec2 = Vertex1 – Vertex2 DeltaU1 = Vertex3.u - Vertex2.u DeltaU2 = Vertex1.u - Vertex2.u DirectionV = normalize( DeltaU2*Vec1 - DeltaU1*Vec2 ) DirectionU = normalize( cross( DirectionV, Vertex.n ) ) DirectionW = normalize( cross( DirectionU, DirectionV ) ) But wich one here is the tangent vector? DirectionU I suppose... thats right?
Lutz
Lutz
Hey!

EVERY vector which is perpendicular to the normal vector is a tangent vector. Tangent vectors are vectors which are parallel to your triangle. Also the binormal is a tangent vector!

What is done in your code is the following:

1) Compute some vector (namely DirectionV) which is parallel to the triangle. Thus, DirectionV is a tangent vector. DirectionV is parallel to the triangle since it is a linear combination of the vector from vertex 2 to 3 and the vector from vertex 2 to 1 (DeltaU2*Vec1 - DeltaU1*Vec2). Vec1 and Vec2 span the triangle.

2) Compute another tangent vector (namely DirectionU) which is perpendicular to DirectionV. Since it should also be a tangent vector, it must also be perpendicular to the triangle normal vector. This is done by using the cross product cross(DirectionV, Vertex.n).

Note: You have Vertex.n in your code, which should rather be triangle.n if you want the tangent vector of a triangle, not of a vertex.

3) You now have two tangent vectors Direction U and Direction V. By DirectionW = cross(DirectionU, DirectionV) you get the vector perpendicular to both, that is you get the normal vector. Actually, if you use the triangle normal instead of Vertex.n, you can leave the last step.

Anyway, since DirectionU, DirectionV and DirectionW is a right-handed perpendicular coordinate system, you usually call

DirectionU tangent vector,
DirectionV binormal vector and
DirectionW normal vector.

So, you were right ;-)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.