Tangent Space

Last updated 2018/12/17

Technical background

Normal vectors in a normal map are expressed in tangent space where normals always point roughly in the positive z direction. Tangent space is a space that's local to the surface of a triangle: the normals are relative to the local reference frame of the individual triangles.

A great and short explanation of what a tangent space is.... but, what exactly is that supposed to mean?

Let's make an example: Imagine someone is telling you to go straight north for 100 kilometers. Easy thing to do, right? Well, kind of. We know what everyone means by north but this isn't as obvious as it seems. Someone could refer to the magnetic north pole or the geographic north pole. The reason why we don't ask this question every time is that we just happen to have agreed on which one to use globally.
A similar situation is present with the tangent space. So which direction a normal vector in a baked normal map is referring to depends on the tangent space used. There are different ways to calculate the tangent space and for years, developers used different methods in their applications. This can even vary within the application itself. For example, the 3dsMax viewport uses a different tangent space method than V-Ray does.

So why does it matter and is it a big deal?

Mismatching tangent space between baker and target

This is what happens if a models baked tangent space is not matching the tangent space used by the host application. You can see that there are ugly dark gradients all over the place.

What would that mean in terms of our example of the north pole above?
Let's assume our baked normal map is just the instruction to go 100km north. It doesn't specify if it meant to go north towards the geographic or the magnetic north pole. We can't determine that based on just the information we have. All we know is to go north. Let's say the baking tool refers to 100 km north as a direction towards the geographic north pole. If we interpret the information of going 100km north the same way the baking tool did we will have a matching tangent space and end up arriving where we were supposed to. If, however, we assumed that the information was meant to be used in regards to the magnetic north pole, we will not end up at the right place - this is what we can see in the example for the mismatching tangent space.

It can be more or less apparent, depending on the difference of the normals between the high and low-poly models (which is extreme in this particular model). This example is one of the worst possible cases you could encounter and is thus somewhat blown out of proportion to demonstrate the effect. A real-world model would likely show less pronounced artifacts.

Before you bake your models, make sure you know which tangent space the game engine your model is used in utilizes. Check which tangent space is required and make sure the tool you use for baking is capable of providing it. Many offline renderers, like V-Ray or Scanline, are not suitable for baking into different - or even any known - tangent spaces.

These days, more and more renderers and game engines use the MikkT tangent space calculation method, so this is probably a sign of an establishing standard.