Skip to main content
gamedev.net
🔒 Locked

Tangent Vector

Started by sonka Feb 18, 2007 at 4:15 AM 6 replies 1.8k views
Original Post
sonka
sonka
Hi! I want to do bump mapping with GLSL, but I don't know how to compute the tangent of a vector. Could somebody tell me how can I do it? I've searched around the internet, but I've found nothing useful (maybe because I am not too good at using Google :] ). Thanks: sonka [ham]
Jimfing
Jimfing
Hi, this site describes how to calculate the Tangent Basis:

link
sonka
sonka
Thank you!
sonka
sonka
And can it be possible to compute it for one vertex?
Because if I computed them per-triangle, how would i pass them to vertex attributes? :-\
sonka
sonka
deleted
Jimfing
Jimfing
You cannot calculate the tangent basis for just one vertex - as the calculation requires the UV coordinates of the other verts in the triangle.

Sorry, I'm not sure what you mean by "pass them to vertex attributes".
sonka
sonka
Well, I want to pass the tangent as a parameter for glVertexAttribute.
But as I think, the tangent is same for 3 vertexes.

Hm.. calculating the tangent basis is only the first step to bump mapping. My light still has some error.. It produces very interesting things..
iNsAn1tY
iNsAn1tY
Generally, the tangent vectors of the vertices of a triangle aren't the same. Think about the way per-vertex normals are generated. Each per-vertex normal is the sum and normalization of the normals of the triangles it is a part of. The same is true of tangent vectors, with one difference: you can't generate a per-triangle tangent vector, because a tangent vector can be different for each vertex of a triangle (this is dependent on the texture coords).

I generally use this code (with modifications) to generate my tangents: http://www.terathon.com/code/tangent.php

btw, I don't bother storing the binormal/bitangent; I create it with lBinormal = cross( IN.mNormal, IN.mTangent ) in my vertex programs.
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]

Topic Locked

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

Sign in to reply to this topic.