Ambient occlusion comes in many shapes and sizes and it can be hard to understand what it really is all about. Let’s see how what and where ambient occlusion or AO as it is shortened is present in Blender and what we can do with it.
Ambient occlusion is an effect that can be used to add contact shadow in crevasses, detail areas or where different objects meet in a digital 3D world. The effect was introduced to simulate more realistic shadows. With the introduction of ray-traced render engines the realism is solved within the renderer itself. But we can still add it as an effect even in these kinds of render engines.
Let’s see how Blender implements the different variations of ambient occlusion and how we can use them.
What is Ambient Occlusion?
Ambient Occlusion is the idea that where objects meet, less light will be able to find its way in and shadows appear in those areas. It is most seen around detail and crevasses.
However, no shadow without light, so we can also think of Ambient Occlusion as the biproduct of soft light. As light fades away when it tries to get in between objects, Ambient Occlusion takes over and fades edges around and between objects into shadow.
When adding ambient occlusion into our scenes we often introduce more contrast between the detail areas where ambient occlusion becomes more prominent and plainer areas with less detail. This is often a desirable effect to have, but as always, it depends on the artists goals and choices.
What is the difference between ambient occlusion and ambient light?
Ambient Occlusion is a term used in digital 3D graphics to describe contact shadows. Ambient light on the other hand is mostly used by photographers. When a photographer refers to ambient light, they mean light that is naturally added to a scene. It can also be thought of as the lighting starting point.
The photographer has limited control over the ambient light. It can be daylight or artificially added light. The ambient light influences the photos shot and can be both useful and a hindrance for the photographer. The quality of the light does not matter, it can still be considered ambient light.
With this background in mind we have a version of ambient occlusion in Blender that comes close to resembling an ambient light rather than an ambient occlusion as we know it. The terminology can be a bit misleading here.
What types of AO are there in Blender?
There are several ways we can have ambient occlusion in Blender. It differences between Eevee and Cycles. It is available both on a global scale as a post processing effect or as part of the world settings directly in Cycles. But as we just brought up, this kind of ambient occlusion in Cycles, is more like ambient light.
Another way to globally enable ambient occlusion is to use the Ambient occlusion pass in Blender and enable it as a post processing effect through the compositor.
We can also create several types of local ambient occlusion effects. These range from shader based to texture based.
At last, we can also bake ambient occlusion to textures that we can use for our assets either internally in Blender or externally, for instance, in a game engine. Here is a list.
We can also use ambient occlusion in the viewport to help us see detail as we work.
- Cycles world settings
- Post-processing effect as part of Eevees settings
- The AO shader node
- Through an Ambient occlusion texture map
- Applied as a post-processing effect added in the compositor through a Cycles render pass.
- Bake ambient occlusion texture maps
- Viewport ambient occlusion to enhance detail as we work
Let’s cover them one by one.
Cycles ambient occlusion world settings
This ambient occlusion is rarely used in final renders, at least as far as I know. We can try to use it in interior renders if we have problems with fireflies or we can use it to light up a scene or asset for test renders.
What it does is that it adds ambient light to the scene and overrides global illumination. Ambient occlusion is really a biproduct of accurate rendering with a ray-tracer like Cycles. This means that we don’t really need to turn this on. We already have it as part of global illumination.
But let’s see what it is, you may still find it useful.
To add ambient occlusion in Cycles go to the world settings tab in the properties panel and find the Ambient Occlusion section and enable it on the checkbox.
When you enable this your scene will light so that it overpowers your existing light setup. This is what we earlier touched on as being ambient light rather than ambient occlusion.
My understanding here is that this kind of ambient occlusion overrides Cycles global illumination or adds to it according to the factor value we find in the settings.
According to the manual the factor setting simulates soft global illumination. A factor of 1.0 is supposed to mimic the use of a white world color in the settings just above.
External content: Blender manual ambient occlusion
We also have a distance value. This determines how far away objects can be to contribute to the shadows created by the effect. Lower values will bring more light to your scene. If you go to the extreme, crevasses and detail can even seem to light up instead of becoming covered in shadow.
You should be aware that this kind of ambient occlusion breaks the physical accuracy of the render engine.
There is another setting relevant for global ambient occlusion in cycles. In the render tab we find the simplify section. If we expand the viewport and render subsections, we find AO bounces.
If this isn’t set to zero, ambient occlusion will take over after the specified number of bounces. For instance, if we set this to two, we will let global illumination do two bounces in the scene before AO takes over.
Even if this ambient occlusion fakes light and breaks the physical accuracy, a benefit is that it is performance friendly and can help reduce fireflies in interior renders.
Ambient occlusion with Eevee
In Eevee, ambient occlusion is a post-processing effect. We find it in the properties panel among the render settings. Open the Ambient Occlusion section to reveal the properties. To enable it, press the checkbox on the section headline.
In Eevee, ambient occlusion makes much more sense. We rely mostly on information gathered from different views. For instance, the screen space, maybe a reflection plane, which is just another view to add information to the scene or an irradiance volume that samples light so that we can emit bounce light according to that sample location.
Overall, we are just gathering information from different perspectives of the scene to make it complete.
It only makes sense to add ambient occlusion into the mix so that we can utilize all the available information to create the render we want.
I recently authored another article covering the Eevee render settings that you can find here:
Related content: A guide to Blender Eevee render settings
For completions sake, we will cover ambient occlusion in Eevee here as well. But for an alternative view and more in depth, check out the article above.
The distance parameter adjust how far away surrounding objects can be to still contribute to the AO. A higher number will result in more and darker shadow.
The factor blends AO on top of the original image. with a factor of zero we have turned off ambient occlusion. Note though that the slider goes from 0 to 1 but we can type a higher number into the field. We can, for instance, have a factor of five hundred if we felt that it was a fair value.
The trace precision is a bit tricky, it short, don’t touch it. But if you have artefacts you can adjust this to see if it solves the problem. It will give you a performance hit in complex scenes but may sometimes solve those problems.
The bent normal refers to the angle most light hits the surface as opposed to the tangent normal witch is the direction the face is pointing. It is supposed to give slightly more accurate ambient occlusion.
As far as I know, it doesn’t have a performance impact. So, in general, we want this to be on.
The last setting, bounce approximation takes the light hitting an object into account. An object with more light gets less occlusion. This is a good setting to leave on as it increases realism.
In Eevee ambient occlusion is a much more essential tool than in Cycles. It gives us more control over our scenes. For instance, we may have irradiance volumes that give excessive light in some areas while providing good indirect lighting in other areas. In those cases, we can use ambient occlusion to dial back the indirect light where it is less desired.
Many different techniques play together to get a nice final render in Eevee, and ambient occlusion is one of those tools.
How the AO Shader node works
The AO shader has limitations in both Cycles and Eevee right now. Some of the settings in the node only works in Cycles while Eevee depend on the global settings for this shader.
Using Cycles, we can’t render the AO node with GPU and Optix. We must fall back on Cuda for Nvidia graphics cards. If we have an AMD card, we can use OpenCL.
The AO node is also relatively expensive in terms of performance in Cycles. If we need maximum performance, we may benefit form baking ambient occlusion instead. We will touch on that further below.
Let’s start in Eevee. We can use the color and normal inputs. The distance is Cycles only and instead; we use the global post-processing settings in the render tab. This means that we can’t have different distances for different shaders. But we can still work around that by adding a color ramp node after the ambient occlusion node.
All properties without an input or output node are also cycles only. This leaves us with the Color and AO outputs for now.
If we turn off global ambient occlusion the AO output will stop working. But the color output will work either way.
Here is an example.
We are using Eevee and ambient occlusion is turned on. We can put a color or use a texture as input in the ambient occlusion shader that we pass to the mixRBG node.
The AO output is piped to a colorramp so that we can adjust the AO effect. In this case I turned up the black a lot to make it very prominent in the occluded areas. Then I added a green tint before the ambient occlusion shadow fades away.
We mix this back with the color in the mixRGB node set to multiply with the factor slider set to 1. We can lower this value to fade away the ambient occlusion effect.
Thanks to the compatibility between Eevee and Cycles we can use the same node setup, but in Cycles the other settings are used as well.
You can see that there is some difference in color, we can probably tweak the scene to make them more similar. But that is not why we are here. The overall effect is the same. You can see the similarities. Now, let’s go through the rest of the settings applicable to Cycles.
The distance input should be clear by now, it tells how far away other objects can be to influence the ambient occlusion.
The sampling setting determine how many rays are cast. More samples mean smoother ambient occlusion. But too many samples also have a performance impact. You want this as low as possible while still clearing up noise. If the AO doesn’t clear up enough, we can complement it with denoising. At least for still images.
The inside checkbox switches the ambient occlusion around so that peaks rather than crevasses are detected.
Only local change the node so that only the object itself influence where the ambient occlusion goes.
Both settings are especially useful when using the AO node to create masks. Something that this node is very commonly used for.
How to use an Ambient occlusion texture map
We can use an ambient occlusion map to increase contrast and put emphasis on details and crevasses locally for a single object or as part of a texture set. This is less computationally heavy than the ambient occlusion node but instead, it costs RAM. We need to strike a balance between RAM usage with pre-baked assets compared to straight up calculating at render time.
Some textures are baked specifically for one object. This is often the case for textures used in games and real-time applications. Another kind of texture is a seamless texture. An Ambient occlusion map can be part of a seamless texture set as well together with other PBR maps.
Both kinds of texture can be used in the same way. Only the first example needs to match the texture to the correct object, obviously.
We can use an AO texture as it is meant, to create shadow in crevasses and detail areas. But we can also use it as a mask or combining it with other textures to create a more complex masks just like with the ambient occlusion node.
Here I will show you how we can use it the traditional way.
The simplest way is to combine the AO map with the diffuse or albedo texture through a mixRGB node set to multiply, then use the factor slider to adjust how much of the AO you want to come through.
Here is a node setup example:
The texture is from texture haven and we use the diffuse, roughness, normal and displacement texture together with the AO. The lighting is just the sky texture that was introduced in Blender version 2.90.
This first example is the node setup above.
In this next example we use no ambient occlusion texturue, instead we plug the diffuse straight to the principled BSDF.
This last example is with the AO node plugged into the lower socket of the mixRGB node instead. We could further tweak this with a color ramp node if we wanted. Keep in mind that this image takes significantly longer to render since I could not use Optix and had to fall back on Cuda combined with the longer render time for an AO node.
Personally, I think the first result is the best where we include the AO texture. Still, I rarely come around to use them.
How to use ambient occlusion in the compositor
Ambient Occlusion in the compositor works well when we want AO across the whole scene, and we need some more control after we completed the render. Using the AO pass together with a colorram,p mix node or a curve are a few examples of how we can adjust the AO pass and combine it with the original footage. It is like how we do it in the shader editor.
To use ambient occlusion in the compositor we need the AO pass. To enable this in Eevee we first need to enable ambient occlusion in the render settings. For Cycles, there is no prerequisites.
The passes can be found in the view layer properties tab in the properties panel. Find the passes section and light subsection.
At the bottom you will find the Ambient Occlusion pass. Enable it before you render your scene.
Once the scene is rendered, we can access the pass in the compositor. Go to the compositor workspace and press use nodes.
In the render layer node, you will have an AO output. connect it to a color ramp node and the colorramp to the bottom socket of a mix node. Then set the mix node to multiply.
Connect the image to the top color socket in the mix node and the mix node to the output.
Now we can use the color ramp and the factor to adjust the amount and level of the AO.
How to bake ambient occlusion
Baking ambient occlusion isn’t much different than baking any other pass in Blender. There are two ways we can bake ambient occlusion natively in Blender. We can either bake the AO pass for our selected object or we can setup a shader that ends in an emission shader and bake the emit pass.
Let’s go over how we bake the AO pass first. These are our requirements
- A mesh object with a UV map.
- A shader on the object with a disconnected image texture node.
- An image texture attached to the above-mentioned image texture node.
- Cycles render engine
Keep in mind that Optix does not support baking so if you are on an Nvidia graphics card, you likely have to switch to Cuda or bake with the CPU.
Make sure your interface is setup so that you have both the shader editor and a 3D viewport accessible, then go to the properties panel and find the render tab.
In the bake section set the bake type to ambient occlusion, select your object in the 3D viewport and select the disconnected image texture node with the loaded image. Then press bake in the properties panel.
When the bake is done, don’t forget to go to the image editor and save your baked image.
The second way is to bake an emit pass. The difference here is that we don’t bake the actual AO pass, instead we setup a shader to mimic ambient occlusion. Most likely using the AO node and a colorramp to adjust it.
This is the node setup.
Make sure to select the image texture node and switch from ambient occlusion to emit in the baking section then press bake.
Ambient occlusion in the viewport
There is also a feature we can enable if we want to have ambient occlusion in the viewport as we model. This can help us see detail more clearly as we work. It is called cavity and is a viewport shading feature we can turn on in solid viewport mode or in the workbench engine.
Keep in mind that this kind of ambient occlusion can also be performance heavy. You will have to weight that in as you use it. The upside is that it looks nice in the viewport.
To enable it, set the shading mode to solid and open the viewport shading menu with the arrow button found in the top right corner.
In the options section check cavity and a few extra settings will appear.
We can have world, screen space or both types of cavity enabled. Screen cavity is faster but doesn’t take the geometry into account while world is more accurate.
We can also adjust the intensity for valleys and ridges.
By now you realized that Ambient Occlusion is a diverse topic and sometimes a bit confusing. When we hear the term ambient occlusion it can be hard to know what is meant at first. After reading this guide, you are better prepared to use ambient occlusion. I also think you are better prepared as you hear about ambient occlusion elsewhere and you will easier be able to understand what kind of ambient occlusion is being referenced.
Thanks for your time.