Friday, 17 January 2014

A simple trick to reuse parts of a normal map

Have you ever wanted to reuse parts of a normal map only to realise the copied part doesn't render as expected?
This is because normal maps take the direction of the normals, reduces them to colours and applies them to a 2D texture. If you simply copy a piece of detail and flip it to fit your UVs, while your detail will fine, the colours have been untouched and therefore the normals are still pointing where they were before.

This leads to problems and is why the render doesn't look correct. The details were flipped but not the normals!
This is what I will explain how to counter with an extremely simple trick.

The thing to understand is each colour channel points in a different direction. Depending on the engine, the directions will be different. In the case of Blender, RED is X, GREEN is Y and BLUE is Z

 Here is an example. I want to copy a piece of detail to another area of the normal map.

The first step is to copy and flip the piece of detail.

As you can see, the detail is flipped but the normals are not since the colours haven't been touched.

The next step is done in an editing software. Any software that can edit RGB channels independently will work. Select the new piece of detail and go into a channel editing window.

From the screenshot above you can see that we need to flip the RED channel because we flipped the detail along the X axis (to the right). The GREEN channel does not need to be flipped because the Y component of the normals is already correct since we only flipped the image in the X direction.

So this is what we do. We select the area we mirrored, go into channels window and invert the colours. Dark things will become lighter and vice versa meaning the direction of that component of the normal will be reversed. So instead of pointing where it was before, it'll point in the way we want.

Here is the result. You can see how the lighting now matches meaning the two are now pretty much identical, but oriented differently. Now lighting will behave as expected.

I hope this was helpful!

No comments:

Post a Comment