Sub topic 13
Baking the ambient occlusion map
This chapter assumes you have already prepared a high-poly and low-poly pair with applied transforms and clean UVs. It also assumes you have set up the Selected to Active workflow and baked the normal map. The AO bake reuses nearly all of that setup, so the new material here is what AO stores, what differs from the normal bake, and what goes wrong.
What the bake produces
An ambient occlusion (AO) map is a grayscale image. White marks surface points that see the whole hemisphere above them. Darker values mark points partly blocked by nearby geometry, such as creases, gaps between plates, and the base of a bolt. The baker fires rays from each texel of the low-poly UV layout over the surface. It measures how many rays escape without hitting geometry, then writes that fraction into the image.
With Selected to Active, the rays are cast against the high-poly object. The low-poly mesh therefore receives the occlusion of the detailed sculpt, including the crevices that the low-poly mesh does not have.
Two properties follow from this:
- AO is view-independent. It depends only on geometry, so it is safe to bake once and reuse.
- AO is data, not color. The values describe a quantity, not a visible tint, so the image must not be color-managed like a photo.
Setup differences from the normal bake
The AO bake needs the same pieces as the normal bake: a target image, an active Image Texture node, both objects selected, and the low-poly object active. A few points are specific to AO.
- Use a separate image. Create a second image such as
Asset_ao. If you bake into the normal map's image, you overwrite it, becauseClear Imageis on by default. - Set the image to Non-Color. A Non-Color image is read as raw values with no sRGB transform. If you leave it as sRGB, the numbers are stored the same, but the image is later interpreted with a curve. Midtones then look wrong in the material. You set the color space on the image datablock, not on the bake.
- Make the new Image Texture node active. The baker writes to whichever image node is active in the low-poly material. A common mistake is leaving the normal map node active, which silently overwrites it.
- Keep the cage and ray distance settings. The same
cage_extrusionandmax_ray_distancevalues that worked for the normal bake usually work for AO. They decide which high-poly surface each texel sees.
Settings that affect AO quality
AO is a sampled estimate, so noise is its main quality problem. Each texel's value comes from a limited number of rays, and too few rays produce grain in the result.
| Setting | Effect on AO | Practical guidance |
|---|---|---|
| Samples (`scene.cycles.samples`) | More rays per texel, less noise | 64 is a quick draft. Use 256 or more for final bakes. |
| Resolution | Detail of occlusion shadows | Match the texel density you chose in the UV layout chapter. |
| Margin | Padding around UV islands | 16 px suits 2048 maps. See the margin chapter. |
| Denoise | Removes grain after baking | Optional. It can soften sharp creases. |
Higher samples cost time linearly. If you are not sure how much you need, bake at 64 and look at the flat areas. Grain there means you need more samples.
Running the bake in Python
This script assumes Asset_high and Asset_low exist, and that Asset_low already has a material. It creates the AO image, activates its node, selects the pair, and bakes.
import bpy
high = bpy.data.objects["Asset_high"]
low = bpy.data.objects["Asset_low"]
img = bpy.data.images.new("Asset_ao", 2048, 2048)
img.colorspace_settings.name = 'Non-Color'
nodes = low.active_material.node_tree.nodes
tex = nodes.new('ShaderNodeTexImage')
tex.image = img
nodes.active = tex
bpy.ops.object.select_all(action='DESELECT')
high.select_set(True)
low.select_set(True)
bpy.context.view_layer.objects.active = low
bpy.context.scene.render.bake.use_selected_to_active = True
bpy.ops.object.bake(type='AO')
img.filepath_raw = "//Asset_ao.png"
img.file_format = 'PNG'
img.save()The script relies on the scene already using Cycles with your cage and margin settings from the normal bake. If you run it in a fresh file, set scene.render.engine = 'CYCLES' first, or the bake operator will fail. Saving the image is required. A baked image exists only in memory until you save it or pack it, so closing Blender without saving loses it.
Doing it in the interface
- Select the high-poly object, then Ctrl-click the low-poly object so it is active.
- In the Render Properties, set the engine to Cycles and open Bake.
- Set Bake Type to Ambient Occlusion and enable Selected to Active.
- In the low-poly material, select the AO image node so it has the highlighted outline.
- Click Bake and wait for the progress bar.
- In the Image Editor, choose Image, then Save As. Save before doing anything else.
Using the result
The AO map does not plug into the Normal socket. The usual options are:
- Multiply into Base Color. This darkens crevices in the albedo. It is a quick way to preview the bake, but it bakes lighting into the color, so the shading will not respond to scene lighting changes.
- Pack into a channel. Many game engines read occlusion from a channel of a packed texture, for example the red channel of an ORM (Occlusion, Roughness, Metallic) map. Check what your target expects.
- Use as a separate occlusion input. glTF and some engines have a dedicated occlusion slot that applies it only to indirect light. This is the most physically correct use.
The next chapter covers wiring maps into the material in detail.
Common AO artifacts
| Symptom | Likely cause | Fix |
|---|---|---|
| Entire map is white | Wrong objects selected, or the high-poly was not selected | Select both, with the low-poly active |
| Map is black in patches | Rays start inside the high-poly surface | Increase `cage_extrusion`, or check the high-poly normals |
| Grainy flat areas | Too few samples | Raise samples, or denoise |
| Dark lines along UV island borders | Margin too small | Raise margin |
| Normal map was overwritten | Wrong image node active | Bake into a separate image, and activate its node |
| Map looks washed out in the material | Image is set to sRGB | Set it to Non-Color |
Checking your bake
Open the saved image in the Image Editor and look for three things. Flat surfaces should be near white. Creases and gaps should read as smooth dark gradients, not stepped bands. The areas outside the UV islands should show the bleed from the margin, not empty black. Then apply it in a material, as the next chapter shows, and orbit the model to confirm the shading matches the sculpt.
Exercise
You bake an AO map and find that your previously baked normal map image now contains grayscale occlusion instead. What happened, and how do you prevent it?
Show answer
The AO bake wrote into the normal map's image because that image's Image Texture node was still the active node in the low-poly material (and Clear Image replaced its contents). Prevent it by creating a separate image for AO, adding its own Image Texture node, and making that node active before baking. Also save each image to disk right after its bake.
Exercise
Why must the baked AO image use the Non-Color color space, and where do you set it?
Show answer
AO values are data, not a visible color. An sRGB setting applies a transfer curve when the image is read, which shifts midtones and makes the occlusion look wrong in the material. Set it on the image itself: in the Image Texture node's color space dropdown, or in Python with img.colorspace_settings.name = 'Non-Color'.