baking ambient occlusion maps
In this chapter of the Blender Basics tutorial series some of the more common 'extras' will be explained, useful features that can augment the production process or add 'value' (a 'feature' or 'function') to low-poly models when used for game development; the various 'bake' options available in Blender 3D for instance, which provide 3D artists with a relatively quick way to make the different image 'types' often used in games, predominantly to improve the general fidelity of in-game assets.
It's expected that you be familiar with Blender or have at least gone through the previous chapters of Learning Blender 3D tutorial series; as this next section involves itself with more advanced production processes, you need to understand what you're doing with Blender before embarking on this next exercise in content creation.
The following material was written for Blender 2.49a+/- or below. For an up-to-date version that addresses learning the latest Blender release, click here.
Ambient occlusion maps ^
What is "ambient occlusion"? It's essentially a form of non-directional object shading that's the result of background 'ambient' (bounced) light within a scene - its ostensibly based on the physical characteristic of an object and how its actual structure blocks or 'occludes' light, rather than necessarily being influenced by directional lighting in a general sense.
To illustrate this more clearly, the images below show the Blender Basics tutorial chair rendered with texture maps baked under the two lighting situations mentioned above - 'ambient' and 'directional'. The first image shows the chair lit by 'ambient' light, the 'soft' non-directional lighting in the scene produces an 'ambient occlusion' map when baked. The chair in the second image is lit by 'directional' lighting, baking that produces a completely different result called a 'shadow' map, a map that corresponds directly to the direction of the light source illuminating the chair.
The bottom image shows both 'bakes' with their respective UVW map overlaid to highlight how each type of lighting situation bake relates to the chair and UV's; the process of 'baking' any form of 'map', including 'ambient occlusion' maps, will produce images similar to the bottom image.
Ambient occlusion is non-directional lighting which bakes 'shading' to images maps
Shadow maps is directional lighting which bakes shadows to image maps based on the position of lighting relative to objects in a scene
The difference between a shadow and ambient occlusion bake
Baking ambient occlusion maps ^
The process of baking images for the purposes of generating 2D assets useful when making content for games with Blender relies on the presence of two things; 1) a UVW map and 2) a texture - without these the process won't work and will result in an errors; as they're essential items make sure the model to be baked has both. To check this switch to the UV/Image Editor view (split the interface, click the "UV/Image Editor" button or press "Shift+F10" to open the Editor in the current view), the image that's going to be used during the bake process should be visible, if not, select the mesh, press TAB to enter Edit mode and select a face that has both a UVW map and texture applied so as to 'force' Blender to display the image it will bake to (it also allows progress to be monitored as it happens). From this point on the simplest and most straightforward ambient occlusion bakes make use of Blenders default settings, so that's what we'll use from here on out.
Tutorial chair before being baked for ambient occlusion
Switching to render baking buttons ^
Baking any type of map in Blender means switching to the appropriate 'mode' and set of 'buttons'. To do this for baking ambient occlusion press "F10" to switch to the "Scene": "Render" buttons (using F10 will switch to "Scene" buttons and toggle through the different "Render" options each time the shortcut key is pressed), then click on the panel titled "Bake" to access the various setting and options available for render baking each type of map, "Full Render" being the default.
Using F10 to switch to Blender "Scene" and "Render" buttons
Selecting ambient occlusion bake option ^
Once the bake panel is open click the "Ambient Occlusion" button so Blender knows it's about to bake an ambient occlusion map, then make sure that "Margin:" is set to "2" or above, this ensures there's enough 'bleed' room around the edges of the UVW map to prevent gaps, artifacts and other baking anomalies appearing in the resulting image - check to see if you've allowed enough room between UVW map islands, else areas will bleed into each other or be repeat rendered.
Default basic settings for ambient occlusion baking 1) set the render bake to "Ambient Occlusion" and 2) set margin value
Start the 'bake' render process ^
Before proceeding make sure the mesh has both a UVW map and texture applied and the correct options for ambient occlusion bakes have been set. Once done, select the object then click the large button titled "Bake" in the "Bake" panel to start the rendering process, Blender will then calculate and incrementally 'bake' the objects ambient occlusion to the texture slot originally applied to the mesh, as shown below - this may take a few minutes depending on the size of the texture image used in the texture slot, and complexity of the model. Keep in mind that Blender is not overwriting the actual texture image that's linked to the texture slot, but instead writing data to a temporary 'buffer' ready to be saved.
Clicking the "Bake" button initiates the process of calculating and rendering the ambient occlusion map
The final basic ambient occlusion map based on the default settings
Saving render baked ambient occlusion maps ^
Once Blender has finished rendering the ambient occlusion map - which is indicated by the mouse cursor reverting back to the 'pointer' and the presence of a "*" to the right of the 'Image' menu ("Image*"), it will need to be saved, ideally to a 'loss-less' compression format like "BMP" (Bitmap) or "Targa Raw".
To do this select "Image » Save As..." in the UV/Image Editor header to open the file browse window (as shown in the first image below). On opening (second image below), select an appropriate format from the "Save Image" drop down menu; where necessary click the double headed arrow button top-left to browse to a different location if the file needs to be saved else where; type a file name and click the "Save Image" button top right, Blender will then save the baked ambient occlusion map to the chosen location.
Design note: On saving the new texture Blender will over-ride any previously UVW mapped images with this newly created one so, if necessary, the original texture image may need to be re-established with the texture slot of the material, or by reconnecting the texture slot back to the material applied to the mesh.
Saving the resulting ambient occlusion map
Saving the ambient occlusion bake using TGA RAW loss-less compression format
Using the ambient occlusion map ^
The whole purpose of baking an ambient occlusion map like this is to then 'blend' it with the original 'diffuse' texture applied to the model to make an object with a better sense of depth - this usually means the two types of image (plain 'diffuse' and 'ambient occlusion') are mixed together in a photo-editor so one image is laid over the top of the other with their separate 'features' merged or blended together to make a single image then re-applied over the model as shown below. Typically this can be done using "Hard Light" or some other, similar image filter. And that's it, ambient occlusion map baked from the model, the results saved, mixed with the original and re-applied to the mesh.
Ambient occlusion image merged with the diffuse to create a more visually interesting texture to apply to the finished model
Ambient occlusion maps can be baked for all manner of objects, although there are some caveats to doing so depending on what is being baked; baking a terrain for example has different core problems to solve, more often than not related to the physical size of a terrain mesh itself (either sections of, or whole objects). Having said that, the process of baking ambient occlusion is the same regardless, there are a number of different options available when baking, but the basics as explained above, will mean being able to produce good quality artwork without worrying too much about the more advanced complexities of the process.