Why normal maps are predominantly blue instead of a random color?
I guess normal vectors of a 3D object can point in every direction, like:
(1.0, 0.1, 0.5), (0.1, -0.5, 0.3), (-0.51, 0.46, -1.0) ...
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.Sign up to join this community
There are two types of normal maps commonly used in game development. The way you are thinking they should work is the way one type works (model-space normal maps), but most games use another type (tangent-space normal maps) which is why you associate mostly-blue textures with normal maps.
With model-space normal maps, each channel encodes the precise value of the normal using the same coordinate system as the vertices of the model it's used with. This means different parts of the normal map will have different hues, but pixels near each other will usually have similar colors. An example of a model-space normal map appears above (source).
Tangent-space normal maps are usually light blue. This type of map defines normals in a coordinate space unique to each pixel's position on the surface of the mesh. It uses the (interpolated) vertex normal as the Z axis, and two other orthogonal vectors, called the tangent and bitangent, as the X and Y axes. Essentially, you can think of the normals in the map as an "offset" from the normal for that pixel calculated by interpolating the vertex normals. The tangent and bitangent vectors are also interpolated from vertex data, and determine which direction on the mesh corresponds to "up" and "left" in the normal map. The image provided in the question provides an excellent example of what a typical tangent-space normal map looks like, so I won't provide another example here.
The components of a normal normally (no pun intended) range from
[-1, 1]. But components of a color in an image range from
[0, 1] (or
[0, 255] but usually they're normalized to
[0, 1]). So normals are scaled and offset such that the normal
(0, 0, 1) becomes the color
(0.5, 0.5, 1). This is the light blue color you see in normal maps, and it indicates no deviation from the interpolated vertex normal when using tangent-space normals.
The reason tangent-space normals are preferred over model-space normals is due to the fact that they are easier to create, and can be used for multiple meshes. Additionally, if used with an animated mesh, tangent-space normals are always used, because the normals are constantly changing.
The normal map mostly points outward from a surface. Assuming you go with the usual mapping of the Z component of the XYZ normal vectors being the "depth" direction and an that mapping to the B component of the RGB color space, you'll end up with most normal vectors being primarily blue.
If the texture were, say, red, then that would mean that the normal map is a surface that's mostly pointing off to the right. You can see that feature on your sample image as the right-most edge of the bumps have a reddish tint to them.
A complete surface of a reddish color wouldn't make any sense. That would indicate a surface that is entirely facing off towards the right. That would just be modeled with geometry, not part of a normal map.