I'm implementing normal mapping and was trying different techniques of doing that. All seemed not to give me a correct result (e.g. the normals point in weird directions). To find the problem, I broke everything down to the simplest possible solution, but I cant find the problem.
Here is a picture of my scene outputting only the world-space normals:
And here is the scene outputting the transformed normals with the normal map:
As you can see, the normals are not pointed the way they should be (green should be to the right, for example). Here is the way I caluclate the TBN-Matrix (I know, its not the correct way of doing that, but I tried the "correct" ways too).
vec3 tangent = cross(worldspaceNormal, vec3(0,0,1)); vec3 biTangent = cross(tangent, worldspaceNormal); mat3 tbn = mat3(tangent, biTangent, worldspaceNormal); vec3 map = texture(normal, texCoord).rgb; map = 2 * map - vec3(1); outNormal = vec4(tbn * map, 0.0);
worldspaceNormal is just the normal of the surface multiplied by the model-matrix, with w-component
0.0, of course.