Results 1 to 6 of 6

Thread: Regarding Tangent space

  1. #1
    Member Contributor
    Join Date
    Jan 2012
    Posts
    81

    Regarding Tangent space

    Hello Everyone,

    I am reading about Normal mapping from OpenGL 4.0 Shading Language Cookbook. I could understand about the concept of tangent space. But I'm not able to understand how exactly the matrix is created for transforming vectors to the tangent space.

    The matrix is generated like this:

    Vertex Shader:
    Code :
    #version 400
    layout (location = 0) in vec3 VertexPosition;
    layout (location = 1) in vec3 VertexNormal;
     
    layout (location = 2) in vec2 VertexTexCoord;
    layout (location = 3) in vec4 VertexTangent;
     
    // .. Other uniforms
     
    void main(void)
    {
       // Transform normal and tangent to eye space
       vec3 norm = normalize(NormalMatrix * VertexNormal);
       vec3 tang = normalize(NormalMatrix * vec3(VertexTangent));
     
       // Compute the binormal
       vec3 binormal = normalize(cross( norm, tang ))
                               * VertexTangent.w;
     
       mat3 toObjectLocal = mat3(
                                 tang.x, binormal.x, norm.x,
                                 tang.y, binormal.y, norm.y,
                                 tang.z, binormal.z, norm.z 
                                );
     
       // .. continues
    }

    Can anyone please explain this?
    Thanks in advance!

  2. #2
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    Re: Regarding Tangent space

    Tangent, Bitangent (binormal is IMHO a terrible misnomer since this vector is tangential to the surface not orthogonal to it) and normal are the three basis vectors of tangent space. The matrix is simply a change of base from tangent space to object space (the space in which normal, tangent, bitangent are expressed).
    Therefore its rows are the basis vectors of the source space (here: tangent space) expressed as vectors in the destination space (here: object space).

    PS: I hope I didn't mix up rows/columns in the above, but you get the idea

  3. #3
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,674

    Re: Regarding Tangent space

    Bitangent (binormal is IMHO a terrible misnomer since this vector is tangential to the surface not orthogonal to it)
    Not in this case.

    The "Bi" in binormal refers to the tangent and normal vectors. It is "normal" to the "Bi": tangent and normals.

    The problem with the term "binormal" is that it assumes that the binormal is normal: orthogonal to the tangent and normals. It isn't. In the above case it is, but that's because the people who wrote the code were lazy and didn't properly create a tangent space basis. A proper basis can have the tangent and bitangent not be orthogonal to one another.

    "Bitangent" is a surface property, which may be orthogonal to the tangent and normal but does not have to be. "Binormal" is a geometric property which is, by definition, orthogonal to them.

    So they refer to two different things. And since he's constructing the binormal orthogonally, it is correct to call it "binormal".

  4. #4
    Member Contributor
    Join Date
    Jan 2012
    Posts
    81

    Re: Regarding Tangent space

    Thanks Alfonse Reinheart, Carsten Neumann.

    @Carsten Neumann:

    >> The matrix is simply a change of base from tangent space to object space

    Well now i'm confused. Isn't it from eye space to tangent space?

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,650

    Re: Regarding Tangent space

    Quote Originally Posted by Alfonse Reinheart
    Quote Originally Posted by carsten neumann
    Bitangent (binormal is IMHO a terrible misnomer since this vector is tangential to the surface not orthogonal to it)
    And since he's constructing the binormal orthogonally, it is correct to call it "binormal".
    Another take on this:

    Quote Originally Posted by [url="http://www.terathon.com/code/tangent.html"
    Computing Tangent Space Basis Vectors for an Arbitrary Mesh[/url] (Eric Lengyel)]Bitangent versus Binormal

    The term binormal is commonly used as the name of the second tangent direction (that is perpendicular to the surface normal and u-aligned tangent direction). This is a misnomer. The term binormal pops up in the study of curves and completes what is known as a Frenet frame about a particular point on a curve. Curves have a single tangent direction and two orthogonal normal directions, hence the terms normal and binormal. When discussing a coordinate frame at a point on a surface, there is one normal direction and two tangent directions, which should be called the tangent and bitangent.
    Eric's explanation makes more sense to me.

  6. #6
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    Re: Regarding Tangent space

    Well now i'm confused. Isn't it from eye space to tangent space?
    Ah, your code uses the vectors after applying the normal matrix, so yes it is between the eye and tangent spaces.

Similar Threads

  1. tangent space
    By giugio in forum OpenGL: General
    Replies: 1
    Last Post: 03-20-2012, 04:37 AM
  2. Texture space is not tangent space: Discussion
    By ste3e in forum OpenGL: General
    Replies: 2
    Last Post: 04-28-2011, 06:03 AM
  3. how calculate tangent and binormal for tangent space ?
    By airseb in forum OpenGL: General
    Replies: 2
    Last Post: 08-09-2005, 05:12 AM
  4. Tangent-Space to World-Space
    By adamnation in forum OpenGL: General
    Replies: 2
    Last Post: 06-09-2005, 06:52 AM
  5. Tangent-Space????
    By TurboCG in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 07-08-2002, 02:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean