Fixing the Normal Pass

The normal pass is a compositor pass that allows you to bake normal maps from the camera.


When you check that box, one extra output called “Normal” will appear in the compositor.


If you connect that output to the “Image” input at composite node, your rendered image will looks like this:


You can see the red, the green but where is the blue?

To answer this question, let’s make a normal map from this simpler object:

https://image.ibb.co/csST6a/simplier_object.png

Here is a shoot from the top view:

https://image.ibb.co/fmBhXF/wrong_top_view.png

In this image, it is easier to see the problem. The top and the right faces are not visible. But there is something there:

https://image.ibb.co/jhwfma/negative_colors.png

If you drag your mouse over the image in the UV/Image Editor, you will notice that the places where these faces should be have negative color values.

This happens because the Normal Pass stores the normal vector (the direction where the faces are facing to) into color values. The x is stored in the red; the y, in the green; and the z, in the blue. Thus, when the normal vector is pointing towards a direction where the x is negative, the red is also negative. But an image can’t store negative color values. Then, the correctly baked normal maps stores the negative directions between 0 and 0.5 in the color values and the positive ones between 0.5 and 1.0.

https://image.ibb.co/gGEiNF/normal_pass_vs_correctly_baked.png

What we need to do is to push the negative directions to above zero and shrink their bounds so they can fit into the color value’s bounds.

First we have to separate the colors so we can work on them individually. So, add a Separate RGBA node and connect the “Normal” output to it:

https://image.ibb.co/nxrDNF/separate_rgb.png

Now, for each color (except alpha), add two Math nodes. Set the first one to Add, link the color to any value and set the other value to 1.0. Set the second node to Divide, link the result of the Add node to the upper value and set the lower value to 2.0:

https://preview.ibb.co/m9f4wa/additions_and_divisions.png

Let’s merge the color values together. add a Combine RGBA and link all the Divide nodes of each color to their respective input in the Combine RGBA node and link this node to the compositor output node.

https://preview.ibb.co/kuOeUv/colors_merged_together.png

The result is now better. It looks more like a normal map:

https://image.ibb.co/dDOPwa/better_normal_pass_map.png

But there still something wrong. If you use this “normal map” in a surface, you will notice that left side reflects to the right and the right, to the left.

https://preview.ibb.co/bPFMba/inverted_illumination.png

For some reason, the red value is inverted. Let’s revert it by adding a Invert node to it.

https://image.ibb.co/bCPm9v/red_revertion.png

Now, your normal map is ready to use. Remember to save it in the best quality as possible. After all, for a normal map, color is everything.

https://image.ibb.co/my0ONF/color_quality.png

Set the anti-aliasing to off if you are working with a low resolution normal map and don’t want the bevel effect.