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)
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
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:

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)