Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 3 of 3 FirstFirst 123
Results 21 to 23 of 23

Thread: Ray intersection with GLSL

  1. #21
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,983
    Quote Originally Posted by romulogcerqueira View Post
    2) If I remove the tranpose operation on TBN matrix, I got the following result, with corners filled and the center of sonar image in black:
    A matrix whose columns are the world-space T,B,N vectors transforms from tangent space to world space. Its inverse (which is the same as the transpose provided that the matrix is orthonormal) transforms from world space to tangent space. Lighting calculations can be done in either space. You can either transform the normal from the normal map from tangent space to world space, or the eye and light vectors from into tangent space. But if you're doing raytracing, you'd want the reflection vector in world space.

    Quote Originally Posted by romulogcerqueira View Post
    If I just modify the bitangent vector by sum of cross(N,T) and cross(T,N), I got a weird result.
    The cross product is anti-commutative, i.e. AB=-BA. If you add those two, you'll get zero (to within the accuracy of floating-point calculations).

    Also: linear interpolation doesn't preserve orthogonality or length, so you may need to account for this in the fragment shader.

  2. #22
    Junior Member Newbie
    Join Date
    Dec 2017
    Posts
    28
    Quote Originally Posted by GClements View Post
    A matrix whose columns are the world-space T,B,N vectors transforms from tangent space to world space. Its inverse (which is the same as the transpose provided that the matrix is orthonormal) transforms from world space to tangent space. Lighting calculations can be done in either space. You can either transform the normal from the normal map from tangent space to world space, or the eye and light vectors from into tangent space. But if you're doing raytracing, you'd want the reflection vector in world space.
    I have used the normal mapping only to change the normal directions and create a more realistic sonar simulation. I transformed back the normal to world space on fragment shader.

    Code :
            vec3 normalRGB = texture2D(normalTex, gl_TexCoord[0].xy).rgb;
            vec3 normalMap = (normalRGB * 2.0 - 1.0) * TBN;
            vec3 nWorldNormal = normalize(normalMap);


    Could you kindly give me an example how can I solve this issue?

  3. #23
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,983
    Quote Originally Posted by romulogcerqueira View Post
    Could you kindly give me an example how can I solve this issue?
    What is your issue exactly?

    A normal map gives you a normal vector at any given point on the surface. But that normal vector is typically for a flat, horizontal surface (i.e. a normal of (0,0,1) points away from the surface). To "wrap" it onto a curved surface you need to transform the vector you get from the normal map into some other coordinate system, so you provide a transformation matrix at each vertex. You only need to provide two of the axes (typically X and Z), and compute Y=ZX. Typically X is the tangent, Y the bitangent, Z the normal, so the matrix has columns B,T,N where B=cross(N,T).

    The first thing to check is that you're generating correct tangents. Typically, you'd transform the texture-space S-axis into object space.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •