|Build a NextGen Game Car: Part IV [Texture Baking]|
Software: Autodesk Maya
Author: Valentin Nadolu (AMC Studio)
Author Website: http://www.amc.ro
1. The Normal Map:
In games, the normal map is used to add details to low-poly geometry. The information can be extracted from a high-resolution mesh and then applied to the ingame model to improve its aspect. The major advantage of this technique is that it can vastly improve the look of a low-res asset without having a big impact on rendering performance.
Here is how it all works.
As mentioned in the low-res portion of this tutorial, lightning of an object in a realtime 3d environment is done by using normals, which are a vertex attribute. The major disadvantage of this technique is that the shading quality is proportional with the number of polygons.
Building a next gen object is almost synonym with using normal maps. Instead of relying of mathematical procedures to determine the way light is reflected off a surface, the "per pixel" lightning method uses a normal map to define the normal’s direction in every point of its geometry. The major advantage is that the normals can be calculated from a high-res version of the asset. Each pixel in the normal map will define the normal of that point in 3d space as follows: the three color channels R (red), G (green) and B (blue) will determine the X (red), Y (green) and Z (blue) values of the normal. There are two types of normal maps used in games:
a. Object (World) Space Normal Map. Can be easily identified by the fact that it looks like a rainbow. Each color channel defines the absolute coordinates of the normal in world space. This type of map is used for static, non-deformable objects and it is usually avoided as it is hard to change in Photoshop after it is generated.
b. Tangent Space Normal Map. Can be easily recognized by being predominantly blue. Each pixel defines the deviation of the normal from the value calculated with the "per vertex: method by using a local coordinate system (X, Y, Z will instead be U, V, N). This is the most used type of normal maps in games as it is easy to edit in Photoshop and it can be applied to deformable meshes.
A good idea is to save a new scene before starting to prepare the scene for baking. This will ensure that all the settings used for baking are saved separately in this new scene and are easy to go back to in case of anything needing a rebake.
All the meshes should be recombined by following these rules:
1. The low-res geometry will be separated in such a way that every object has only one material. For example, the door geometry will be separate from the door window, even if in the final scene they will probably be merged together. Naming these meshes should be done by using a simple to follow naming convention like this: body_low, glass_low, interior_low.
2. As mentioned before, intersections must be avoided by separating objects because they can cause artifacts in the baked textures. For example, if the interior has intersections, I will separate it into different objects that will intersect each other but will not contain intersections themselves. Naming should be something like interior_low 1, interior_low 2.
3. The high-res geometry will be recombined in a similar way to the low-res geometry. Each previously created low-res geometry should have a corresponding high-res counterpart named something like: body_high, glass_high, interior_high, etc.
These naming rules will help speed up baking by making each high-res/low-res pair easier to select.
Don’t forget to apply Smooth on the high-res meshes before baking!
Texture baking in Maya can be done by using the Transfer Maps utility found under Lightning/Shading->Transfer Maps...
The "target meshes" section is for the low-res meshes and the "source meshes" section is for the high-res versions. The settings in the next image are a good starting point for baking. The settings that usually need tweaking are "Search envelope" and "Max search depth:"
For each pair of meshes, a normal map will be generated. If there is more than one normal map for one particular material, these baked normal maps can be recombined in Photoshop by using the Overlay blend mode.
The combined textures can be loaded on the bump channel of a Phong material. The "Use as" drop box in the bump2d node has to be set to "Tangent Space Normals" for the normal map to correctly be displayed when high quality rendering is enabled (Renderer->High Quality Rendering in the viewport menu)
This is how the mesh looks with normal vertex based shading.
This is how the mesh looks with normal maps applied in High Quality Rendering.
2. The Ambient Occlusion Map:
This is a bit easier to explain: basically, the ambient occlusion (AO) map contains the amount of "visibility" stored for each pixel. The more occluded that point is in 3d space in relation to its surroundings, the darker the pixel will be on the AO texture. I will not go into detail about how this is calculated, I will stick to showing how it is generated and used. Because occlusion is influenced by all the objects in the scene, this map does not require the low and high-res models to be separated to minimize the number of intersections.
Texture generation is similar in steps to the generation of normal maps. The next image presents some of the settings used. One thing to mention is that for the AO baking, the "Max Search Depth" setting is ignored. This is replaced by "Occlusion Max Distance", which usually require a value larger than 50 to give proper results.
The value for "Occlusion rays" is directly proportional to the quality of the final texture and the rendering time. For a test render, a value of 16 will be enough, but to obtain a smooth texture, I use a much higher value, usually a power of 2 (64, 128). Be careful, high values in this field will cause the rendering time to increase dramatically!
The resulting image is a grayscale that can be put on top of the painted color texture using Multiply. This will add depth to the diffuse texture, making it look more realistic.
Usually ambient occlusion maps take more time to bake than normal maps, so some patience is required. Do a lot of test renders with low "Occlusion Rays" values to make sure all the details show up on the map before doing a full resolution render that can even take more than half an hour to complete.
Now that these textures have been baked, you are ready to move on to the next and final chapter of this tutorial, texturing.
All links for this tutorial:
1. Build a NextGen Game Car: Part I [High-res Modeling]
2. Build a NextGen Game Car: Part II [Low-res model]
3. Build a NextGen Game Car: Part III [UV Layout]
4. Build a NextGen Game Car: Part IV [Texture Baking]
5. Build a NextGen Game Car: Part V [Texturing]