blogspot stats

Realtime SSAO with After Effects and Pixel Bender

5. October 2009 – 09:00

Tags: , , , , , ,

Realtime SSAO with After Effects and Pixel Bender

Screen Space Ambient Occlusion or SSAO is a method to compute an approximated AO pass in real-time!

This is done by using the depth information of a 3D object or scene that has been stored from the Z-(depth) buffer of the renderer.

Go ahead and try the interactive demo or see a video example!


The technique was introduced 2007 at Siggraph by Crytek Studios and is becoming an often used feature within next generation live-3d engines or cg/video post applications.

After playing with the ray traced inside-out AO and having to realize that it´s not quite doable with Pixel Blender, I turned to SSAO and quickly got some nice results.

In short it´s all about importance sampling.

SmartSSAO looks up the depth information of 12 surrounding samples and checks if they get occluded to average the AO value.
sp_ssao3

The disadvantages lie in the nature of SSAO being “screen spaced” which means that it can´t take objects from the off into account, and the result has to be blurred to reduce the inevitable noise.
Also there is no ray bouncing, so classic AO is visually superior – but hey… who can argue with “real-time”?

View another video of the buffer and the solo SSAO pass without/with blurring.
Please note that those strange looking anomalies on the buddahs arms originate from the badly ranged zmap I produced in a hurry.


To sum it all up:

SSAO makes it possible to have AO in places where it normally isn´t possible – e.g. real-time engines (yes – even for Flash/Papervision), or within a video post process.

All that’s needed is the Zbuffer of a 3D rendering.

You can download the Shader here or get it packed with an AFX example.


Hint: As said before, the SSAO pass needs to be blurred in order to clear out the emerging noise – but don´t overdo it, as the blurring will “bleed” the result over to unwanted areas.
This could be targeted by a special SSAO blur filter that would again have to take the depth map into account.



Click here to see this screenshot as video

sp_ssao2


Update:

I feel like I should adress the X,Y-offset params of the filter which can be used to tweak the “shadow direction”.
“Shadow direction” in quotes as (SS)AO is all about indirect lightning so this is a real “tweak” or an unrealistic param – which I thought might come in handy in some cases.

I was asked if the shader was performant enaugh for flash – and even if it looks a bit ugly codewise as I had to get rid of a loop – it surely is.

So I updated the package and made this small interactive flex demo :


Be sure to try unchecking “color SSAO?” and “show SSAO?” to get an impression.

You can grab the source here.


Update 2:

The filter now features an additional sampling radius parameter which controls the dispersion and allows to adjust it to the desired level of detail – this should also make it more useable for papervision.

I hope this little experiment will be of use to somebody out there and would love to hear any suggestions.

  1. 7 Responses to “Realtime SSAO with After Effects and Pixel Bender”

  2. THIS is crazy. Both thumbs up. I am really jealous..

    By Sebastian on Oct 8, 2009

  3. Nice! I’ve not yet looked into your shader but it looks like if you had some sort of directed light source in your scene that is coming from the left?
    I am thinking of integrating this into our visualization module. Check the demo at:
    http://www.vpr-solutions.de/images/CGI360/CGI360.html

    By Helmut on Dec 1, 2009

  4. Hi Helmut,

    glad you like the shader and find it useful.

    And you are right – as ambient occlusion is an approximation of global illumination, the object should be shadowed equally with no recognizable light direction (dome-/skylight).

    However I integrated an X/Y offset to tweak the direction as I found it useful to have some small “relighting” feature.

    Even while unrealistically in terms of AO, it helps to bring out certain features of a scene or object and as AO is an approximation and 2D SSAO even more so…

    I took a look at your visualization module.
    Nice work with the client and rendering.

    If you would load an additional Z-depth map for every image, you could indeed use the shader to dynamically shadow the object.

    But I think this would only make sense if the user was given some kind of real-time control over the effect (like a dragable lightsource for example).
    Otherwise it would be better to render a real AO pass directly into the image-sequence.

    But if you are looking for a way to relight/reshadow the scene in real-time – this would work while I have to point out that there is a simpler and better approach to pure relighting using normalmaps.

    However the actual kernel uses two methods the flashplayer doesn´t support: a function call and a loop.
    But with some unlovely hardcoding you can get rid of both.

    If you need any help or suggestions on the implementation or relighting in general please feel free to contact me.

    Cheers!

    - Jan

    By flashgordon on Dec 1, 2009

  5. Hi Jan, we already have the z-buffer in our demo. Otherwise it would be very hard to change the wheels for example.
    How can I contact you? You should be able to see may email right?

    By Helmut on Dec 3, 2009

  6. Excellent, so you are already set :)
    I can be contacted via info@smart-page.net and yes I can see your mail so will get back to you.

    By flashgordon on Dec 3, 2009

  7. Very Cool..Have been wanting to see this in Pixel Bender for a long time.

    By Satya Meka on Jan 12, 2010

  8. Thanks Satya,

    your “Bad TV” shader looks also very cool – great work.

    By flashgordon on Jan 12, 2010

Post a Comment

Security Code: