Screen Space Ambient Occlusion (SSAO)

From Valve Developer Community
Revision as of 16:40, 22 December 2010 by OneQuarterLife (talk | contribs)
Jump to navigation Jump to search
Screen Space Ambient Occlusion applied to a typical 3D scene.

Ambient Occlusion (AO) is a type of lighting technique applied in-game to create more realistic lighting. AO simulates soft shadows created by two surfaces that are close together. Typically AO is accomplished through Screen Space Ambient Occlusion (SSAO), which is a simplified way to fake realistic AO with shaders in a process fast enough for real-time rendering.

SSAO works by examining an onscreen pixel, and then comparing its location in the depth buffer (i.e. how far it is away from the player) to the pixels around it. Pixels which are close together but not coplanar (on the same face) are shaded to simulate soft shadows. To maintain playable framerates, it is not possible to sample every pixel every frame, so random sampling is used, which will inevitably create noise/grain which may be more noticeable with movement. To counter this, the SSAO pass is often Gaussian blurred to remove such grain.

SSAO in the Source Engine

Note.pngNote:For faked Ambient Occlusion per model within the Source Engine, see $ambientocclusion.
Todo: Write a tutorial on how to fix Source's depth buffer. SSAO will only work 128 units ahead unless this is done first.
Todo: Write a tutorial on creating an SSAO shader and implementing it into the engine. See Shader Authoring.

Enabling and Using Nvidia's Forced Driver SSAO

SSAO in game - the shading effect is highly visible between Breen and the table, and in the corners of the room. Note the edge "glow" bug around Breen's arm.

Nvidia's drivers feature a method that allows for SSAO to be forced on in almost any game. Enabling this feature is as simple as turning it on within Nvidia's driver control panel.

Note.pngNote:Enabling Nvidia's forced SSAO can cause significant performance penalties.

Supported games

Enabling AO in Nvidia control panel

All Source engine games except Portal have driver profiles to enable Nvidia's SSAO. SSAO in Portal can be forced on by editing Portal's driver profile with an external application such as nHancer.


Graphical Bugs

Nvidia's SSAO implmentation was designed to be general purpose, and as such, does not take a lot of Source's stock effects into account during it's calculations. This leads to bleeding in scenes with heavy fog, which can be seen on the picture below. As a fault of the actual SSAO shader, Ghosting and other related artifacts, pictured on the image above, can occur. It is recommended that you use a more modern SSAO implementation that takes the scene's normals into account if you intend to design your own shader for use in Source.

File:Ao renderbug trees.jpg
The shadows being rendered on top of fog are noticable on distant trees.