# Thread: Ray intersection with GLSL

1. Originally Posted by romulogcerqueira
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.

Originally Posted by romulogcerqueira
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. A×B=-B×A. 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. Originally Posted by GClements
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. Originally Posted by romulogcerqueira
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=Z×X. 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.

#### Posting Permissions

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