# tangent-to-world space with cube maps

This topic is 4233 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I'm using tangent space normal mapping. To do that I found on this board :) a rotation matrix mat3 toTangentSpace = mat3(tangent, binormal, gl_Normal); which is calculated in the vertex shader. This works fine - but now it want to use environment cube lighting for the ambient basis. I've build a cube map which contains the diffuse/ambient lighting in this scene. But when I access the cube map in my fragment shader I can't do this via the tangent space surface normal can I? So I tried to convert it back to world-space. As far as I understood it, I need the transpose of the rotation matrix to get back to world space? I couldn't find a function in GLSL to get the transpose of a matrix, but this should do it, does it?
mat3 transpose_matrix;
transpose_matrix[0] = vec3(rotation[0][0], rotation[1][0], rotation[2][0]);
transpose_matrix[1] = vec3(rotation[0][1], rotation[1][1], rotation[2][1]);
transpose_matrix[2] = vec3(rotation[0][2], rotation[1][2], rotation[2][2]);
myWorldNormal = myTangentNormal * transpose_matrix;

And at the first moment it looked ok when I multiplied my tangent-space-normal with it, but when I rotated the object the projected lights always remain the same. I build a debug cube map with red,blue,green,.. faces: The object doesn't rotate underneath the cube map colors it's like solid textured fragments. But when the object is rotated the surface normal should point to a different location in the cube map. Any ideas what is wrong here? [depressed] thank you very much

##### Share on other sites
I figured the problem lies in the normal existing in object space when indexing the cube map.

But how Do I transform my normal from object- to world-space to get correct results when using in cubs maps?

• 10
• 17
• 9
• 14
• 41