Ambient Occlusion is a calculation that takes any particular point
and figures out how occluded this point is by the objects around it.
Many 3d renderers use ambient occlusion as part of its skylight
calculation. A skylight is
a light emitted from a sphere around your scene (like the sky
outside), and then after the
ambient occlusion value is calculated for a point, the light is
multiplied by this value to give you the final light
intensity at a particular spot. The result is an evenly lit scene with
soft shadows (or darkening) in cracks and crevices and under objects,
much like how shadows look on a cloudy day. Note in this example the
plane cuts out any light coming from under the spherical object.
To use skylight in many renderers is as simple as pressing the
skylight button and you're done, but it's always a good idea to have
some idea what's going on under the hood, so this tutorial is just a
brief discussion on how ambient occlusion is
calculated, and what this does visually to an image.
First, lets pick a point we'd like to render. Lets call this
point A. Next, we shoot out a number of rays from A in a hemispherical
direction around the face normal (since it's a ground plane, the face
normal is pointing up), and see how often
these rays are occluded by nearby objects. So in this example, we shoot
out 5 rays (in a real render we generally shoot way more than 5 rays,
but I'm
choosing 5 for simplicity). Rays 1, 2 and 3 do not hit any object on
their way up to the hemisphere. Rays 4 and 5 hit a nearby object (the
sphere), and
so these rays are occluded. So in this image, we shot out 5 rays,
and 2 are occluded, so our ratio of occluded rays vs total rays is 2/5.
Now lets look at point B, which is closer on our plane to our
sphere. We shoot again 5 rays, ray 1 and 2 are not occluded by
anything, 3,
4 and 5 hit the sphere and so are occluded. So this point is given a
value of 3/5.
Now imagine doing this again and again, point after point. For each
point we take the ratio of occluded rays over the total number of rays.
The closer this value is to 0, the less it's occluded, the closer to 1,
the more occluded it
is. So in the example above, point A would be closer to black (less
occluded), point B would be closer to white (more occluded).
In our 3d
world, that gives us the following image...
Now multiply our skylight by the inverse of the ambient occlusion
image, and we get
the skylight image from above.
So next time you're doing an outdoor scene, I highly recommend a
little skylight (as well as some other lights, such as a bright yellow
directional light for your sun) to make the image more realistic.
Note: the actual math behind implementing this technique is far
more complex, and each renderer does it a slightly different way, but
this should give you the basic idea.
Also note, renderers that include a "skylight" but not an "ambient
occlusion shader" generally do not include a maximum distance value in
their ambient occlusion calculation, which specifies a cutoff value for
how far to shoot the ray before declaring it's a non occluded ray. This
is useful for doing ambient occlusion indoors. But since a skylight is
supposed to be a simulation of a sky, and not a more general purpose
ambient occlusion shader, many do not include this feature. This causes
some confusion between what a skylight does, and what ambient occlusion
is. So as a rule of thumb, a skylight is a light that includes an
ambient occlusion calculation generally with no max dist parameter,
whereas an ambient occlusion shader just provides an occlusion image
with no light, and generally has options such as a max dist value.
Ideal of course is to have both abilities.