Author Topic: Calculating Tangent attribute bumpmapping  (Read 6042 times)

0 Members and 1 Guest are viewing this topic.

rrarunan

  • Associate
  • Posts: 6
Calculating Tangent attribute bumpmapping
« on: March 04, 2006, 05:34:23 AM »
From the GLSL bumpmapping tutorial :

       The line :-

       "The new thing is the T vector which is also provided by the 3d engine
       but as a vertex attribute (attribute key word in GLSL code)."

       I\'ve looked at a lot of references and I\'m still looking for a way to     :?:
       calculate the TANGENT , T Vector given a vertex and normal..

       Can anyone please help me?

JeGX

  • Global Moderator
  • Capo Crimine
  • *****
  • Posts: 2357
    • oZone3D.Net
Calculating Tangent attribute bumpmapping
« Reply #1 on: March 04, 2006, 10:34:06 AM »
Hi rrarunan,

the calculation of the tangent vector is not an easy task.
But here is a little piece of GLSL code that shows you how to calculate the tangent and binormal vectors from the vertex normal only:

Code: [Select]

vec3 tangent;
vec3 binormal;

vec3 c1 = cross( gl_Normal, vec3(0.0, 0.0, 1.0) );
vec3 c2 = cross( gl_Normal, vec3(0.0, 1.0, 0.0) );

if( length(c1)>length(c2) )
{
tangent = c1;
}
else
{
tangent = c2;
}

tangent = normalize(tangent);

binormal = cross(gl_Normal, tangent);
binormal = normalize(binormal);


This piece of code is a part of a forthcoming tutorial.  
Hope that will help you!

rrarunan

  • Associate
  • Posts: 6
Thank you..
« Reply #2 on: March 04, 2006, 06:36:31 PM »
Thanks for the code..  I really appreciate it..

 I just have two quick questions..

a)  does this mean , I can just pass the normal per-vertex and find the tangent and bi-normal vectors for the tangent space transformation?

b) While texturing the cube (I'm using a cube), do I have to texture it with just the colorMap or both the color and the normal maps..

- Arunan

 :?

JeGX

  • Global Moderator
  • Capo Crimine
  • *****
  • Posts: 2357
    • oZone3D.Net
Calculating Tangent attribute bumpmapping
« Reply #3 on: March 05, 2006, 11:05:25 AM »
a - yes, per vertex-normal is enough to find tangent and bi-normal vectors.
b - you only need the color map to texture your cube. The normal map is only used to orientate the per-pixel normal used in diffuse and specular calculations.

rrarunan

  • Associate
  • Posts: 6
Thanks a lot!
« Reply #4 on: March 05, 2006, 07:06:32 PM »
Thank you for the info..

Arunan