In this lesson, you will learn how to bake and apply Ambient Occlusion (AO) maps to ground your 3D models with realistic, soft shadows in tight crevices and corners.
The Concept of Ambient Occlusion
While normal maps simulate surface detail by tricking the eye with lighting angles, they often fail to capture the subtle, soft shadows that naturally occur where two surfaces meet—like the gap between a wall and a floor, or the deep creases in a character’s armor. Ambient Occlusion is a grayscale map that acts as a "shadow mask," defining which parts of your object should receive less ambient light because they are partially blocked by geometry.
How it Works
When you generate an AO map, you are essentially pre-calculating how much of the "ambient" light from the environment reaches a specific pixel. Deep crevices have a low value (dark), while exposed flat surfaces have a high value (bright/white). When this map is plugged into a material’s Occlusion slot in the Unity Inspector, the shader multiplies the ambient lighting by the map’s intensity, causing those crevices to darken naturally regardless of where your primary light source is pointing.
Implementing AO in Unity
To generate these maps, you can use external tools like Substance Painter or utilize Unity’s built-in Progressive Lightmapper settings. When baking lightmaps, ensure your objects have clean Lightmap UVs (as covered in previous lessons) so the AO can be mapped accurately to the mesh surface.
Once you have your texture, assign it in your material settings:
// The Occlusion map is typically assigned to the material's occlusion slot
material.SetTexture("_OcclusionMap", myAOTexture);
material.SetFloat("_OcclusionStrength", 1.0f);
By adjusting the Occlusion Strength slider in the material inspector, you can dial in the depth. Too little, and the object looks like it is floating; too much, and the shadows look unnaturally charred. Always strive for a subtle integration that anchors your geometry firmly into your scene's lighting environment.
Key Takeaway: Ambient Occlusion maps provide the essential "contact shadows" that prevent objects from looking like they are floating, grounding them firmly in your environment by darkening areas where light is naturally obstructed.