1

[Intended for deferred lighting calculations in a game]

Lets say I have an arbitrary triangle with vertices ABC, Normals DEF and Texture coordinates LMN.

Now, we have vectors

G = B-A
H = C-A

O = M-L
P = N-L

The next step is to calculate the Tangent Space:

G = O.s * T + O.t * U
H = P.s * T + P.t * U

Here's where I got stuck...

G and H are 3 dimensional vectors while O and P are 2 dimensional.

How does the multiplication to tangent space work from this point on? And once tangent space is determined, how do I get the binormal and Tangent? Is T the binormal and U the tangent?

  • 1
    This question appears to be off-topic because it is not about programming. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Mathematics Stack Exchange](http://math.stackexchange.com/) would be a better place to ask. – jww Sep 06 '14 at 12:02
  • My apologies. I thought that the question was about programming as it was related to 3D graphics and well...lighting. – Colorfully Monochrome Sep 06 '14 at 18:25
  • May I ask why this was put on hold as a duplicate. I was actually using the other question as a reference but need clarification on the details of it. (Confused on how to solve for T and U, which was covered in the other one but not in a way I understood). – Colorfully Monochrome Sep 06 '14 at 18:28
  • @user2841239 if you look at the first answer in that question you will find almost the same clarification for that equation... but as I wrote before the letters are confusing so you probably missed it. – Spektre Sep 07 '14 at 05:34

1 Answers1

1

well I do not use texture coordinates for mine TBN matrix calculations

Your names are confusing so let me rewrite triangle 3D points to p0,p1,p2. You need TBN matrix T,B,N (tangent,binormal,normal)

  1. normal

    normal is perpendicular to triangle surface so you get it by cross product of the triangle vertices:

    N=(p1-p0)x(p2-p0)
    

    the direction depends on your needs so you can use also this N=(p2-p0)x(p1-p0) this is the only vector that is straight forward

  2. tangent,binormal

    both lies on the triangle surface plane and should be compatible with the rest of the mesh. This is tricky and depends on the mesh geometry. If you have generated geometry (like sphere ,...) then you can set initial direction vector to some axis. From that is easy just use cross product. For example for rotational geometry around Z-axis: T=(0.0,0.0,1.0) x N B=N x T also here is the direction dependent on your needs so you may use reverse cross operands order

If you do not compute TBN compatible for whole geometry then you will get lighting artifacts

Sometimes whole mesh uses distorted single whole rectangle texture like for example in this ellipsoid head:

ellipsoid texture

Only in that case texture coordinates represent the tangent and binormal space coordinate and only then you can use them to get T,B. I do not use this approach so I will use your equations.

Let t0,t1,t2 be the 2D texture coordinates of your triangle (respect to points p0,p1,p2):

(p1-p0) = (t1-t0).s * T + (t1-t0).t * B
(p2-p0) = (t2-t0).s * T + (t2-t0).t * B

this is system of linear equations (6 unknowns 6 equations) so solve it and compute the T,B (tangent,binormal). Look here How to calculate Tangent and Binormal?. The solution is also there (with the same letters as you use)

Community
  • 1
  • 1
Spektre
  • 49,595
  • 11
  • 110
  • 380