Simplst possible TBN-Matrix giving weird results

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);


The worldspaceNormal is just the normal of the surface multiplied by the model-matrix, with w-component 0.0, of course.

• Red (.x) is up in world space? Is that common in opengl? TBN vs -> ps looks like mine usually (in HLSL), but ofc i use mul() instead of *. But i guess i'd expect green (.y) to be up? – Stormwind Aug 25 '16 at 12:45
• Yes, green is usually up, its just the lookAt matrix with z being up. – Liess Jemai Aug 25 '16 at 16:06
• Ok.. (nm lookat). I just wonder if you should have worldspaceNormal.yxz or worldspaceNormal.zxy everywhere Plus that the normals in the texture must fit accordingly. You have the .xyz components correctly, not such that for example .y is omitted? – Stormwind Aug 25 '16 at 17:23
• Found the problem. The TBN apparently needs to be constructed as the following: mat3(worldspaceNormal, biTangent, tangent);. So tangent and normal need to be flipped. Don't know why, maybe a Vulkan thing. – Liess Jemai Aug 25 '16 at 18:17
• Hmok, yes the order must be correct. And it's always good to ensure it is homogenous throughout the application. Ie. if you try with your other 3D models and normal textures, they all behave well :-). – Stormwind Aug 25 '16 at 19:12

Found the problem. The TBN apparently needs to be constructed as the following: mat3(worldspaceNormal, biTangent, tangent);. So tangent and normal need to be flipped. Don't know why, maybe a Vulkan thing.