Screen Space Ambient Occlusion

28 June 2008. I just ran across IƱigo Quilez – RGBA’s treasure trove of AO experimentation and research references. He’s the rgba responsible for the SSAO demos kindernoiser and kindercrasher. This explanation of the lighting in Plastic 195/95/256 is an example of the quality, in depth information you’ll find there.



Plastic by RGBA.


Screen-Space Ambient Occlusion has recently been popularized by Crytek’s Martin Mittring in a presentation at Siggraph 2007, see section 8.5.4.3 for details. The basic idea is to do a full screen pass wherein z-buffer data is sampled around each pixel and a darkening value is computed based on depth differences. Sampling occurs randomly in three space in a sphere around each pixel (see the paragraph for details), and darkening is proportional to the number of sampled occluders. Here’s an example of their results:

Some debate on the technique has occurred on gamedev.net, with the initial discussion here resulting in an algorithm and techniques for resolving sampling artifacts that occur on flat gradients in the scene. Ultimately a nice 4k demo using the technique on rendered Julia fractals is presented. This method based strictly on depth sampling works best with this sort of highly detailed geometry.

25 May 2008. A new version of the demo Kindercrasher has been posted. Inigo has a page of explanation including some shader fragments here.


Robust methods for achieving hardware accelerated AO are presented in the influential paper Hardware Accelerated Ambient Occlusion Techniques on GPUs by Perumaal Shanmugam and Okan Arikan. Unlike most presentations, this method yields results similar to ground truth AO calculations. In this paper, the AO search is split into two phases, one for high frequency near detail, and another phase for low frequency detail with a wider search. The second phase in particular is of interest, it allows large objects to occlude each other as they pass. The low frequency pass is described by this image:

Peter-Pike Sloan et al., have recently published Image-Based Proxy Accumulation for Real-Time Soft Global Illumination which works by accumulating shadowing and indirect illumination in screen space splats. As with other AO methods, a further pass is necessary to introduce direct illumination.

A very cheap method is developed within Blender by Mike Pan, with convincing results. The effect is a bit much at deep depth discontinuities, but given the simplicity of the approach, it could be considered quite acceptable. The image on the left is the simple flat shaded image for comparison. The trick involved here is very clever – the depth buffer is blurred, then subtracted from the original depth buffer. The image is clamped and scaled to reduce artifacts and subtracted from the original image. This method is about a zillion times cheaper than any of the others presented on this page.

This technique and several variations are discussed in detail in the Siggraph 2006 paper, Image Enhancement by Unsharp Masking the Depth Buffer. Several NPR effects are achieved by mapping the depth discontinuities to look up tables to get Gooch like effects. For more, see the project website.

Another technique just in, pointed out by Ignacio in the comments: Ambient Occlusive Crease Shading, by Fox & Compton. For each pixel, nearby pixels are sampled, and dot products between normals are scaled by distance between samples to compute occlusion. The resulting pass is bloomed, blurred, and contrast enhanced before being applied to the framebuffer. The page includes the pixel shader doing the work.

19 April 2008

Via Ziggyware: Alex Urbano Alvarez has generously released an SSAO implementation for XNA GS 2.


The movie shows that in general screen space ambient occlusion makes for a lively and attractive image. It also highlights artifacts that can result from not taking linear depth into account. The effect here is not scaling well with depth; shadows are uniformly thick no matter how far the object is from the camera, note that the shadow halo around the top of the pillars is as wide as the halo on the bottom of the pillars. The effect is not taking depth discontinuity into account. This variation of the effect could be further developed for NPR applications; for example, with some thresholding an attractive toon shader could result.

This thread at BlitzBasic shows what I believe to be the same algorithm as Alvarez. The artifacts in the game example late in the thread are largely hidden by the lighting in the scene. It seems if you are not after a photorealistic result, this algorithm can sweeten your look.

Post to Twitter Post to Delicious Post to Facebook

  • Another alternative discussed at gd-algorithms recently is:

    Ambient Occlusive Crease Shading
    http://www.shalinor.com/code.html

    the main difference is that it does not only use the depth buffer, but also the screen space normals, which are generally available in deferred shading engines.
  • admin
    Thanks for the link Ignacio! I've updated the survey.
  • Two more of interest:

    http://en.wikipedia.org/wiki/Screen_Space_Ambie... - by the actual algorithm designer at Crytek.

    http://rgba.scenesp.org/iq/computer/articles/ss... - reverse engineered, as it were. I don't think he's got it quite right: a flat surface will shadow itself half the time if you count all samples in the sphere, so I think you want to throw out half the occlusions and use what's left. But, he's close.
  • admin
    Thanks Eric! I do like watching kindernoiser in any case :)

    I hadn't spotted the SSAO article at Wikipedia, I like the idea of documenting algorithms and research there.
  • admin
    Level of Detail has a thread going on SSAO.

    http://levelofdetail.wordpress.com/2008/02/10/2...
  • admin
    An article with some phonecam capture at GDC08

    http://www.4gamer.net/games/047/G004713/2008022...

    The official description of the talk is:

    Real-Time Ambient Occlusion
    14:50-15:10, Room 3004 (West Hall), Friday, Feb 22
    NVIDIA Speaker: Miguel Sainz
    This lecture does a review of multiple depth-buffer-based ambient occlusion techniques. Three of the described algorithms are ray-marching in the depth buffer, an algorithm based on accumulating solid angles, and a new hybrid method called tangent tracing. Real-time demonstrations included!

    via this page, I've found the slides!
  • admin
  • cowness
    Here's another algorithm... this one's for a 3DSMax renderer though, but anyway, the pseudo-code should look the same...

    http://www.malmer.nu/index.php/2008-04-09_ssao-...
  • nullsquared
    The last paragraph there with the "limitations" is very, very crappy. First of all, ghosting can be practically 100% eliminated using a correct quadratic falloff for the occlusion. Second, the technique scales very, very well with depth (if you're using a linear view-space depth buffer, that is) - both far away and up close objects occlude themselves and others rather correctly. And third, the shadows are only uniform if your sampling sphere is in screen-space, which it shouldn't be. With a view-space random sampling sphere for dithering, the shadows are NOT uniform.
  • admin
    nullsquared: I modified the last paragraph to make it clear that I am talking about the implementation shown in the video.
  • nullsquared
    Ah, very nice :). Sorry, I get a little defensive of cool stuff (even when it's not mine xD) when there's a misconception. Anyways, I've been playing with some SSAO of my own, if anyone would like a look: http://www.ogre3d.org/phpBB2/viewtopic.php?t=41320
  • admin
    I like your implementation on the Ogre forum, it's very easy to understand, the dithering from the texture is a nice touch. Have you tried bilateral filtering as a method of reducing halos? Jeremey Shopf suggests it here - http://levelofdetail.wordpress.com/2007/11/01/i... . It seems like a good solution.
  • nullsquared
    Just figured I might mention I just released the actual Ogre SSAO demo. It includes rather updated code, that I'd say looks and feels a lot better. Same post in the Ogre showcase forum.
  • nullsquared
    Well, not the "same" post, I deleted the old one, but I mean the same title xD
  • admin
    Here's nullsquared's new demo. The shots look pretty nice!

    http://www.ogre3d.org/phpBB2/viewtopic.php?t=42350
  • admin
    There's an excellent tutorial, in Russian, here:

    http://steps3d.narod.ru/tutorials/ssao-tutorial...

    Google translated:

    http://translate.google.com/translate?u=http%3A...

    It contains several code samples, and improvements based on data available from G-buffers.

    Finally there's a full OpenGL based test program where you can play with shaders and algorithms.
  • admin
    nVidia has posted a whitepaper and demo on SSAO.

    http://developer.download.nvidia.com/SDK/10.5/d...

    http://developer.download.nvidia.com/SDK/10.5/d...

    Their method uses horizon-split ambient occlusion, but steps in screen-space, not eye-space. They use bilateral filtering to reduce the typical depth discontinuity artifacts seen with SSAO.

    There are some notes here on HSAO.

    http://levelofdetail.wordpress.com/2008/02/27/r...
  • admin
    Newly posted, a chapter from a Siggraph course on recent rendering techniques:

    http://ati.amd.com/developer/SIGGRAPH08%5CChapt...

    on StarCraft II's use of SSAO. The unique twist is that they use SSAO to fake low frequency diffuse inter-reflection as well as crease emphasis. They accomplish it by taking samples at two distances; near samples for creasing, and far samples for fake diffuse inter-reflection.
  • Seen the new horizon-based AO stuff, extremely neat. Though it's definitely a bit slower than regular SSAO, yet still real-time :)
  • admin
    nVidia can impose SSAO on a game. It looks good, although I'm not entirely sure it's kosher to go back in and modify a game's look that way without involving the developers.

    http://www.nzone.com/object/nzone_ambientocclus...

    I must admit that SSAO provides visible improvement in some of the examples they've posted. If a driver provides anti-aliasing or texture filtering, that's legit; those definitely provide a qualitative improvement to an image. SSAO however invokes an aesthetic modification on the game however.

    I imagine that I would appreciate it in the case that a game was not strongly art directed, but if a game had a strong aesthetic sense, this seems like maybe not such a good thing.

    What do you think?
  • This page was a great resource for SSAO links. I have written an online Flash implementation in AS3 utilizing PixelBender which you can check out here :) http://kode80.com/ssao2
blog comments powered by Disqus

Bad Behavior has blocked 476 access attempts in the last 7 days.