Ray intersection with GLSL

[QUOTE=romulogcerqueira;1292653]
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:[/QUOTE]
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.

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.

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.

        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?

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.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.