Schnulla

08-18-2010, 03:02 PM

Hi,

I just compared these two articles:

Article 1 (http://anonym.to/?http://tinyurl.com/ynfens)

Article 2 (http://anonym.to/?http://tinyurl.com/39k378k)

In Article 1 a TBN matrix is calculated which

transforms a point from tangent to object space:

(Tx, Bx, Nx)

(Ty, By, Ny)

(Tz, Bz, Nz)

Then they calculate the inverse of this matrix which

can transform a point from object to tangent space

and use this matrix in the shader here (http://wiki.gamedev.net/index.php/OpenGL:Tutorials:GLSL_Bump_Mapping).

In Article 2 the TBN matrix (or the TBN vectors)

is calculated like this:

generateNormalAndTangent(float3 v1, float3 v2, text2 st1, text2 st2)

{

float3 normal = v1.crossProduct(v2);

float coef = 1/ (st1.u * st2.v - st2.u * st1.v);

float3 tangent;

tangent.x = coef * ((v1.x * st2.v) + (v2.x * -st1.v));

tangent.y = coef * ((v1.y * st2.v) + (v2.y * -st1.v));

tangent.z = coef * ((v1.z * st2.v) + (v2.z * -st1.v));

float3 binormal = normal.crossProduct(tangent);

}

The code is nearly the same except that the input parameters

are already direction vectors. But the main difference is

that no inverse matrix is calculated.

Now my question:

Since there is no inverse calculated in Article 2

I would say this function calculates a TBN matrix which

transforms from tangent to object space. So first I was

wondering if the plan is really to transform all normal

map texture values from tangent to object space.

But I think the solving is in the shader because there

I found the following code:

v.x = dot (vertexPosition, t);

v.y = dot (vertexPosition, b);

v.z = dot (vertexPosition, n);

eyeVec = normalize (v);

The way the dot products are applied I would say

vertexPosition is multiplied with a TBN matrix

that looks like this:

(Tx, Ty, Tz)

(Bx, By, Bz)

(Nx, Ny, Nz)

This is the transpose (and thus the inverse, since

the matrices are orthogonal) of the matrix that

transforms a point from tangent to object space

as mentioned at the beginning of my post, right?

So to sum up. Is my understanding correct that the

approach in Article 2 calculates a TBN matrix

that transforms from tangent to object space and

then later in the shader the transpose of this

matrix is used as inverse matrix to transform

from object to tangent space (actually from

eye to tangent space because of the multiplication

with the normal matrix)?

If yes then I would prefer the second approach

since it requires less calculations and code.

Please let me know if I am wrong? Thanks!!

Best regards!

I just compared these two articles:

Article 1 (http://anonym.to/?http://tinyurl.com/ynfens)

Article 2 (http://anonym.to/?http://tinyurl.com/39k378k)

In Article 1 a TBN matrix is calculated which

transforms a point from tangent to object space:

(Tx, Bx, Nx)

(Ty, By, Ny)

(Tz, Bz, Nz)

Then they calculate the inverse of this matrix which

can transform a point from object to tangent space

and use this matrix in the shader here (http://wiki.gamedev.net/index.php/OpenGL:Tutorials:GLSL_Bump_Mapping).

In Article 2 the TBN matrix (or the TBN vectors)

is calculated like this:

generateNormalAndTangent(float3 v1, float3 v2, text2 st1, text2 st2)

{

float3 normal = v1.crossProduct(v2);

float coef = 1/ (st1.u * st2.v - st2.u * st1.v);

float3 tangent;

tangent.x = coef * ((v1.x * st2.v) + (v2.x * -st1.v));

tangent.y = coef * ((v1.y * st2.v) + (v2.y * -st1.v));

tangent.z = coef * ((v1.z * st2.v) + (v2.z * -st1.v));

float3 binormal = normal.crossProduct(tangent);

}

The code is nearly the same except that the input parameters

are already direction vectors. But the main difference is

that no inverse matrix is calculated.

Now my question:

Since there is no inverse calculated in Article 2

I would say this function calculates a TBN matrix which

transforms from tangent to object space. So first I was

wondering if the plan is really to transform all normal

map texture values from tangent to object space.

But I think the solving is in the shader because there

I found the following code:

v.x = dot (vertexPosition, t);

v.y = dot (vertexPosition, b);

v.z = dot (vertexPosition, n);

eyeVec = normalize (v);

The way the dot products are applied I would say

vertexPosition is multiplied with a TBN matrix

that looks like this:

(Tx, Ty, Tz)

(Bx, By, Bz)

(Nx, Ny, Nz)

This is the transpose (and thus the inverse, since

the matrices are orthogonal) of the matrix that

transforms a point from tangent to object space

as mentioned at the beginning of my post, right?

So to sum up. Is my understanding correct that the

approach in Article 2 calculates a TBN matrix

that transforms from tangent to object space and

then later in the shader the transpose of this

matrix is used as inverse matrix to transform

from object to tangent space (actually from

eye to tangent space because of the multiplication

with the normal matrix)?

If yes then I would prefer the second approach

since it requires less calculations and code.

Please let me know if I am wrong? Thanks!!

Best regards!