Ambient Occlusion

In computer graphics, “ambient” lighting is a way to roughly model indirect
lighting. “Bounce” lighting, you might call it; it’s light which hits an
object not because it is coming directly from a light source, but rather
because it has bounced off some other surfaces in the area, before finally
illuminating this one.

In computer graphics, we usually model ambient light by simply declaring that
there’s a constant amount of light in the scene that’s going to hit absolutely
everything. So everything in the scene will receive this much light simply by
existing, no matter what else might be going on.

In this scene, for example, you can see a very little
bit of shadow being cast onto the mountain on the right side of the image.

That shadowed area isn’t pure black because even though there’s no direct light
hitting the mountain there, it’s still being illuminated by the scene’s ambient,
indirect light.

The problem with this method of simulating ambient light is that in the real
world, the amount of reflected light isn’t actually constant. It can be blocked
by other nearby objects, and even can change color based upon nearby surfaces
absorbing or reflecting different colors. Treating ambient light as if it’s a
universal constant can actually make objects look ‘flat’.

In computer graphics, when we reduce the amount of ambient light on a surface based
upon other nearby geometry that might be getting in the way of that light, we call
that “ambient occlusion”. Drag the slider below to the left to see it in action,
on this skeleton:

With ambient occlusion (drag the circlular thumb to the left in the image
above, if you’ve not done so already), you can suddenly see all the details of
the skeleton’s rib cage, and you get a sense of how deep his jaw is; both are
actually occluding quite a lot of ambient light. You get a similar effect on
the mountains in the backdrop, where their crags again block a lot of light.

Similarly, in the graveyard below, the ambient occlusion helps pick out the
fluting of columns, and the details of statues which otherwise were being
washed out by the flat ambient lighting.

These days, most games perform ambient occlusion in screen space; that is, we
render the screen image, and then figure out how much ambient light is being
occluded for each pixel of the image, based only on what’s visible on screen.

This approach is called “Screen-Space Ambient Occlusion”, or SSAO for short.
And there are a lot of different ways to do it, but they all involve checking
the depth of pixels in an area.

Basically, you check a bunch of randomly chosen positions around each pixel,
and check whether any of those are behind other things in the image. So to go
back to the skeleton example, when we’re checking the pixels of the skeleton’s
backbone, we’d find that a lot of those randomly chosen positions would end up
behind the skeleton’s ribs or sternum, and as a result we decide that the
skeleton’s backbone is highly occluded, and receives less ambient light than do
the bones in the front.

And that’s pretty much all there is to it! Ambient Occlusion is one of those
things which makes a very small contribution to a game’s final image quality,
but lifts everything by that small amount; it makes everything appear a little
more three-dimensional.

I didn’t initially plan to have AO in MMORPG Tycoon 2 at all; I didn’t think
it was appropriate for the game’s visual style. But my artist badgered me
about it so often that I finally implemented it. I did it mostly to demonstrate
to him how it didn’t make any difference, and wasn’t worth the time or effort..
but in the end, once I saw it working I realised that he’d been right all along,
and I shouldn’t have been dragging my feet on it this whole time.

The moral of the story: When you’re lucky enough to have smart people working
for you, listen to their advice!