Sub topic 13
Baking the Ambient Occlusion Map
Ambient occlusion (AO) is a grayscale map that stores how much nearby geometry blocks ambient light. Creases, contact areas, and deep recesses become darker. Unlike a normal map, an AO map does not change the surface direction. It supplies shading information that a material can multiply into its base color or lighting.
A high-poly mesh can contain small cavities that the low-poly mesh does not model. Baking transfers that occlusion to the low-poly mesh's UV layout.
Prepare the AO bake
Use the same high-poly and low-poly pair prepared for the normal bake:
- Apply the transforms on both objects.
- Make sure the low-poly object has a clean, non-overlapping UV layout.
- Select the high-poly object first.
- Select the low-poly object last and make it active.
- Add an Image Texture node to the low-poly material.
- Create a new image, such as
Asset_ao, with the required resolution.
Set the image to Non-Color. AO is measured data, not display color. Treating it as sRGB changes its numeric values and can produce incorrect shading.
Bake ambient occlusion
In the Render Properties, choose Cycles as the render engine. In the Bake panel, enable Selected to Active when the high-poly object is selected as the source and the low-poly object is active as the target.
Set Margin to a value such as 16 pixels. Set Max Ray Distance or the cage extrusion so rays reach the nearby high-poly surface without passing through unrelated parts. A distance that is too small causes empty areas. A distance that is too large can capture occlusion from the wrong object or another side of the model.
Run the bake with the bake type set to Ambient Occlusion. Save the image immediately after the bake.
Automate the bake with Python
This script creates the target image, makes its Image Texture node active, selects the source and target correctly, and saves the result.
import bpy
high = bpy.data.objects["Asset_high"]
low = bpy.data.objects["Asset_low"]
scene = bpy.context.scene
scene.render.engine = "CYCLES"
scene.render.bake.use_selected_to_active = True
scene.render.bake.margin = 16
scene.render.bake.cage_extrusion = 0.02
image = bpy.data.images.new("Asset_ao", 2048, 2048)
image.colorspace_settings.name = "Non-Color"
material = low.active_material
material.use_nodes = True
texture = material.node_tree.nodes.new("ShaderNodeTexImage")
texture.image = image
material.node_tree.nodes.active = texture
bpy.ops.object.select_all(action="DESELECT")
high.select_set(True)
low.select_set(True)
bpy.context.view_layer.objects.active = low
bpy.ops.object.bake(type="AO")
image.filepath_raw = "//Asset_ao.png"
image.file_format = "PNG"
image.save()Preview the AO image by connecting it temporarily to the material's Base Color. Dark areas should appear in creases and contact zones, not across entire faces.
Exercise
The AO bake has dark halos around the entire low-poly object. What should you check first?
Show answer
Reduce the cage extrusion or max ray distance, then check whether the high-poly source contains nearby geometry that should not contribute to the bake.