Sunday, April 7, 2013

SSAO: Screen Space Ambient Occlusion

SSAO: Screen Space Ambient Occlusion


  Screen space ambient occlusion is technique which globally illuminates the scene in screen space.  It is done through approximating the occlusion function on visible surfaces by sampling the depth of neighboring pixels. This is all done in screen space; hence SSAO (Screen Space Ambient Occlusion).  There are many different ways to achieve SSAO, but I will be focusing on the technique used in Starcraft 2.


  In the first pass, the linearized depth and surface normals are rendered to a texture.  In the second pass, a fullscreen quad is rendered and multiple samples are taken from neighboring points to the current pixel.  They are sampled and then are offset in 3D space from this pixel.  They are then converted back to screen space to compare and sample the depth found in the first pass.  This is done within the fragment shader.  This allows us to see if the sampled point's depth is farther or closer than the actual point's depth.  If it is closer, then there is something covering the sampled point.


  The occlusion function gives off zero occlusion if the depth delta is negative, high occlusion if the depth delta is small, or the occlusion falls back to zero beyond a certain depth delta, where the depth delta is the difference between the depth of sample point and the depth sampled at the point.


  After calculating the SSAO, you need to blur your scene in order to reduce the noise within the picture.  This can be done with either a 2D gaussian blur or a 1D bi-lateral blur, one in the X direction, one in the Y for a total of 2 passes.  You will also want to retain the sharp edges within your scene.  This is done by sampling a pixel, and then determining whether the pixel's depth is below a certain threshold, or if the dot product of the normal of the sample pixel is below a certain threshold.  If it is, then the kernel has a zero weight factor on the current pixel.


  With all of this implemented, you will have then successfully developed SSAO within your game.  You can then use SSAO combined with other effects to really make your game pop, and achieve that high quality visual style.

No comments:

Post a Comment