Screen Space Ambient Occlusion#
Screen space ambient occlusion (SSAO) is a technique used for efficiently approximating how each point in the scene is affected by ambient light. SSAO is implemented in a fragment shader, which executes once per fragment – a single full screen pass. In its simplest form, the algorithm samples the depth buffer (stored in a texture) around the current pixel and attempts to estimate the occlusion for the current fragment. However, this approach results in hundreds of random accesses to the depth texture stored in system memory, which will inevitably thrash the cache and result in poor performance.
If an application implements SSAO, it is recommended that the algorithm implements a form of hierarchical-Z buffer (Hi-Z, HZB) optimisation. This involves performing a hierarchical Z pre-pass to build a mipchain for the hardware calculated depth buffer. Building the depth mipchain involves progressively taking either the minimum or maximum depth value for a tile of pixels (for example, 4 x 4) and storing the value in the next mip level.
Hierarchical Z-buffer optimisation significantly improves the rate of convergence for ray intersection by reducing the number of steps to find an intersection, and significantly improves cache efficiency. This is because a small region defining the working area at each level of the mipchain will likely reside in cache, which significantly reduces accesses to system memory. Overall this results in improved performance and massively reduced system memory bandwidth. A white paper explaining one such approach can be found here.