Ambient Occlusion in Game Art (part 1)

There are no lights in this image (which is of a tree)

What Is Ambient Occlusion?

Ambient occlusion creates the look of soft shadows, a very pleasing trait in computer graphics that often favor crispness and sharp precise edges over softness and subtlety. But Ambient Occlusion (AO) is not actually lighting at all, but rather a material/surface property applied to geometry!

Ambient Occlusion in Game Art Image 2

How it works

AO shaders look at the geometry they are applied to, and then output a color on the surface of that geometry. When two objects are close enough, AO makes them start casting (typically) black shadows on each other. As they move away, some soft grey winds up being shared. When far enough apart, the objects no longer influence each other at all, and remain, say, white. AO has custom properties that can be set, such as how dark crevices are, how light open areas are, and at what distance in world units darkness falls off completely, leaving the lighter color untouched.

Still no lights (image example)

This mimics the real-world phenomenon of contact shadows; less light bounces out of corners and crevices than off flat areas. It also helps achieve an overcast look, where the sky as a whole is a light source, hitting objects from every conceivable angle and softening or sometimes even removing shadows. On its own, AO looks nice, but it really looks good when combined with global lighting.

I love the smell of fresh baked textures…

AO is computationally quite expensive, which means it takes a lot of processing power to calculate, which could be a problem in a game that’s ideally running at 60 or more frames per second. Fortunately, there is a solution to this problem: fancy global bounce lighting and AO can be pre-calculated, or “baked,” before the game runs, which allows for extremely high quality lighting solutions to be shown in real-time.

Baked Lighting and AO

Baking involves turning the complex lighting and AO into a texture, or picture file, which is then mapped onto geometry. Many game engines (eg: Unity and Unreal) will internally do this for you with very little interaction from you, the developer. This technique works best on static “world art”, or objects that don’t move much, which are most things in a typical well-lit game. If you take a look outside your window, you’ll notice some people and cars are moving, but not much else. Those non-moving objects don’t change much from one moment to the next, so they are begging to be baked out. On the other hand, if a game character walked away, but their shadow was left behind, that would look strange.

Example baked out tree texture

Once baked, AO is quite easy and fast for computers to draw onscreen; all the tricky math is already completed. A static image is fetched from graphics memory and mapped onto an object, something most GPUs/graphics cards can do without breaking a sweat. The result: a better looking game!

Next article we will look at why Ambient Occlusion is an important part of game art asset creation, and some clever ways we can use it. There may be giant robots.