Ambient occlusion is a method to approximate how bright light should be shining on any specific part of a surface, based on the light and it’s environment. This is used to add realism.
Wikipedia has a nice paragraph that explains what is done.
Ambient occlusion is most often calculated by casting rays in every direction from the surface. Rays which reach the background or “sky” increase the brightness of the surface, whereas a ray which hits any other object contributes no illumination. As a result, points surrounded by a large amount of geometry are rendered dark, whereas points with little geometry on the visible hemisphere appear light.
Here is a highly technical article about it.
Ambient light is a light type in computer graphics that is used to simulate global illumination. Ambient occlusion is simply a simulation of the shadowing caused by objects blocking the ambient light. Because ambient light is environmental, unlike other types of lighting, ambient occlusion does not depend on light direction. As such, it can be pre-computed for static objects.
Without AO (left) Note that the shadow in the left image is caused by directional light, with AO (right).
In traditional Ray Tracing ambient occlusion is simulated by sampling rays from a certain point, which takes a shape of a hemisphere, and then is checked for intersection with the scene (also called Object Space AO).
Notice how ray samples are used to simulate AO integration.
Notice the aliasing (dots) caused by ambient occlusion under-sampling.
Because the ray tracing sampling technique is too slow to be used in real time computer graphics, other methods emerged that simulate this behavior. One notable approach is called Screen Space Ambient Occlusion (SSAO).
SSAO is a screen-space technique developed by Crytek. The ambient occlusion is computed in a full-screen pass, using the Z-buffer as the only input.
The ambient occlusion factor
kA of each pixel is estimated by testing a set of points distributed in a hemi-sphere around the pixel’s location. This effectively simulates the traditional ray tracing approach in screen space.
The value of
kA depends on the samples that are in front of the value in the Z-buffer. If half or more of the samples pass a depth test (that is, they arec closer to the camera than the center pixel), then
kA receives a value of 1. A smaller number of samples result
kA less than 1.
SSAO component of a typical game scene
Ambient occlusion usually means applying data that represents how much ambient light hits a surface. That data is usually a gray scale texture or vertex colors depending on the implementation.
To compute the data the most common way is the render the scene with with a solid white texture and 1 point light multiple times, moving the point light each time to a different location on a sphere or hemisphere. The results of all the renders are averaged and that gives you the data about each particular location in the scene and how much light hits that location.
For example a place in the scene that in always bright no matter where you put the light will be bright where as a place that is dark no matter where you put the light will be dark. The result is that you get something that will put dark shadows in crevices and cracks and soft lighting where objects would generally cast a shadow.