Page 1 of 6

SSAO [Screen Space Ambient Occlusion] Demo + Source

Posted: Sun Jun 22, 2008 11:25 pm
by nullsquared
Edit: Some additional screen-shots!

Off:
Image
On:
Image

Off:
Image
On:
Image

And less emphasis on the SSAO:

Off:
Image
On:
Image

====================================================

Download:
- http://cheapfilehost.com/file.php?file= ... 98b2013f4b
- http://www.MegaShare.com/434579
- courtesy of tuan kuranes : http://tuan.kuranes.free.fr/OgreDemo_SSAO.zip
(if anyone would like to mirror it, please do so, and I'll post the link here)

Make sure you read the readme. All source is included, along with binaries. No blur is done on the SSAO.

Image

Image

Image

// just same playing around at 1024x768
Image

(yes, the same scene from the shadows demo, with improved lighting! :lol:)

I've yet to make it work completely under OpenGL. BTW, you can use this as a demo to reconstruct a 3D view-space position from linear view-space depth.

Issues: It won't work on non-SM 3.0 cards as it is right now, since I'm using a 128-bit G-buffer; no multi render targets, but there's a an R32G32B32A32 floating point render target being used. First thing you can do is compile with R16G16B16A16 instead, which halves the amount of bits for each pixel from 128 to 64. You can also just use a single channel texture just for the depth (R16 or R32), and use the provided computeViewNorm() shader function to calculate the normals from the position. Note that this is a lot less accurate than storing the actual interpolated normals, but it tends to work fine enough in most cases.

I'd love to see if anyone integrates this into their own stuff. The only problem is that there is a lot of manual code:
- manually generating the information for the SSAO
- manually generating the SSAO into an off-screen texture
- manually projecting the SSAO in the ambient shader
But I found Ogre's compositors just not powerful enough to do this in such a simple manner such as effect->update(). Or maybe I just don't understand how to use them :lol:. If anyone wishes for guidance, please post so.

Posted: Mon Jun 23, 2008 1:30 am
by Samuelgames
HOLY SHIT

You managed to add f***ing specular WITH SSAO :o

Null, i love you.

EDIT:

Wow wait, this is not just 'specular', this shit is dynamic

(now do that on HL2) [/post on FP]

Posted: Mon Jun 23, 2008 1:37 am
by nullsquared
Samuelgames wrote:HOLY SHIT

You managed to add f***ing specular WITH SSAO :o

Null, i love you.
:)
EDIT:

Wow wait, this is not just 'specular', this shit is dynamic
Yeah, my demo scenes suck, so just place some knots with space to see that it is indeed dynamic.
(now do that on HL2) [/post on FP]
I'm sorry, but Ogre > Source (at least the rendering portion), and thus I declare the above statement impossible. :lol: :roll:

Posted: Mon Jun 23, 2008 1:50 am
by Samuelgames
nullsquared wrote: I'm sorry, but Ogre > Source (at least the rendering portion), and thus I declare the above statement impossible. :lol: :roll:
The just fact that Ogre is Opensource and Multi Plataform makes it better.

And it is a lot better than source in rendering terms
Yeah, my demo scenes suck, so just place some knots with space to see that it is indeed dynamic.
I mean, that is not specular, that is light reflection

Posted: Mon Jun 23, 2008 2:01 am
by nullsquared
Samuelgames wrote: I mean, that is not specular, that is light reflection
Uh. Not to burst your bubble, but no light is getting reflected here (no global illumination). Just some relatively nice SSAO + diffuse/specular shading with soft shadows.

Posted: Mon Jun 23, 2008 2:10 am
by Samuelgames
nullsquared wrote:
Samuelgames wrote: I mean, that is not specular, that is light reflection
Uh. Not to burst your bubble, but no light is getting reflected here (no global illumination). Just some relatively nice SSAO + diffuse/specular shading with soft shadows.
Then i'm blind.

It just, doesn't look like specular

Posted: Mon Jun 23, 2008 2:12 am
by nullsquared
Guys, no one is testing this? Seems like people are reading the thread but forgetting to post, which is the biggest point since this is far from "finished and generally usable easily" ;)
Samuelgames wrote:
nullsquared wrote:
Samuelgames wrote: I mean, that is not specular, that is light reflection
Uh. Not to burst your bubble, but no light is getting reflected here (no global illumination). Just some relatively nice SSAO + diffuse/specular shading with soft shadows.
Then i'm blind.

It just, doesn't look like specular
Haha.

Posted: Mon Jun 23, 2008 2:33 am
by TSM
Great job null.

I find it amusing how you`re a watchdog on your threads (quick responses are always great!). :P

I'm generally a lurker here on Ogre - since I was investigating it for a rendering engine (but sucked up for C4, which has a terrible rendering engine ... well not terrible but not robust OR flexible at all).

I'm simply stunned that you`re 14 (8th grade?) and writing complex shaders like SSAO - just .. amazing. I've learned a lot from your code - so sorry I can't test it. I just use it as learning material!

Keep at it good sir!

Posted: Mon Jun 23, 2008 2:41 am
by nullsquared
TSM wrote:Great job null.

I find it amusing how you`re a watchdog on your threads (quick responses are always great!). :P
Well, it's night, and I'm on the computer cross-checking all of gamedev, ogre, and facepunch. I'm also txting this girl that randomly decided to tell me she's going out with this guy that's an obsessive loser, but that's a different story :lol:. (yes, I like this girl)
I'm generally a lurker here on Ogre - since I was investigating it for a rendering engine (but sucked up for C4, which has a terrible rendering engine ... well not terrible but not robust OR flexible at all).
Haha.
I'm simply stunned that you`re 14 (8th grade?) and writing complex shaders like SSAO - just .. amazing. I've learned a lot from your code - so sorry I can't test it. I just use it as learning material!
Heh, only 2 more finals (spanish and math), and I'm done with 8th grade, w00t!
Keep at it good sir!
Thanks :)

Posted: Mon Jun 23, 2008 3:41 am
by TSM
Any way to minimize the AO at the intercepts between the geometry (walls) ?

Posted: Mon Jun 23, 2008 7:49 am
by quanganht
The hell ?
Only support for SM3.0 ???

EDIT : And in the readme says "pixel shader 2.b" ?

Posted: Mon Jun 23, 2008 9:09 am
by HexiDave
quanganht wrote:The hell ?
Only support for SM3.0 ???

EDIT : And in the readme says "pixel shader 2.b" ?
What are you so surprised about? Pixel Shader 2.b is probably just cutting it to fit the shader instructions, but 2.b support is wretched. On top of that, Shader Model 2 cards would have a hard time processing all that extra stuff. I just compiled in Cg with PS 2.b and 3.0, and it came out to 285 or so instructions. That would eat a PS 2.b card most of the time.

Edit:
Oh ya, the demo. Looks absolutely fantastic - the code looks really professional, too.

Posted: Mon Jun 23, 2008 9:34 am
by jjp
Great job :)

Posted: Mon Jun 23, 2008 10:32 am
by DanielSefton
Amazing! Really, great work. I'll test it in my game ASAP.

As for the demo, it's really jerky for me. Not as in slow framerate (though it would have been useful to display it in the demo), but it randomly stops and starts. My card is an NVidia 6600, which is reasonable enough, and it supports SM3. (The AO is working fine)

Just out of interest, what card are you using to develop this with?

Edit: Also, how does this stack up against the technique used in CryEngine?

Posted: Mon Jun 23, 2008 10:47 am
by xadhoom
Hi Null!

Very great Demo. Good work! Works on my XPS with a QuadroFx 1500 smoothly :P

I currently try to derive some materials from your shadow demo. Now I have to switch to your SSAO :wink:

Btw, the odd fade problem is still there, but thats another thread :wink:

Posted: Mon Jun 23, 2008 10:48 am
by quanganht
I use GMA 950 => support PM 2.0 + VS 3.0 => can't run the demo.
But I've tried it using swiftshader v2.1. It run slow but look fine.

Posted: Mon Jun 23, 2008 11:02 am
by nullsquared
DanielSefton wrote:Amazing! Really, great work. I'll test it in my game ASAP.

As for the demo, it's really jerky for me. Not as in slow framerate (though it would have been useful to display it in the demo), but it randomly stops and starts. My card is an NVidia 6600, which is reasonable enough, and it supports SM3. (The AO is working fine)
That sounds a bit odd. Maybe its getting stuck calculating/rendering something. Which drivers?
Just out of interest, what card are you using to develop this with?
8800 GTS :D this is why I need more people testing, instead of thinking that it's good to go just because it runs at 100+ FPS here :lol:
Edit: Also, how does this stack up against the technique used in CryEngine?
Well, the general idea is the same. Of course, the guys at Crytek probably know what they're doing better than I do ;)

@ quanganht: I can guarantee you that a GMA 950 will not run any SSAO whatsoever in hardware.

@ TSM: Well, technically, the "creases" there are getting slightly occluded. I think it looks better than just flat ambiency at the creases of the level. It might look better with a larger AO radius, but then that makes everything else look crappy :D

@ Hexidave: Yeah, IIRC it uses 12 random samples. Simply moving those down to 8 should help out. AFAIK Crysis doesn't even do any projection inside the loop (I have *no* idea how), so that saves them speed as well. Really, there's lots of little tweaks and stuff to make it work better. For one, I could probably get rid of the 128-bit G-buffer (one texture, but it stores normals and depth), and instead store a 16-bit (or 32-bit) depth only. Then I can calculate the normals from the position, but that'll get rid of the smoothed normals and instead it'll give me the face normals :| (which doesn't look too bad for SSAO, but it just doesn't look "the best")

Re: SSAO [Screen Space Ambient Occlusion] Demo + Source

Posted: Mon Jun 23, 2008 11:15 am
by kro
Nice demo!

Runs great on 8800GTX, but when cam is very close or within a torus one of my dual screens flickers black (running windowed mode)...strange

Posted: Mon Jun 23, 2008 12:34 pm
by tuan kuranes
Very nice and smooth demo !


Here's a mirror :
http://tuan.kuranes.free.fr/OgreDemo_SSAO.zip
If you need to host some other files, just ask.

But you should really open your own googlepages site with all your ogre source demo and code. (100MB of space).

Posted: Mon Jun 23, 2008 12:52 pm
by xadhoom
It seems that the the SSAO shadows "move" heavily depending on angle
and surface on screen. In the most confusing situation it looks like a torus
knot is very near to a wall and if you rotate around it the SSAO shadow
disappears and you can see that there is a signifcant distance between wall
and knot... can this be avoided by lowering a distance threshold?
You have to turn out the flashlight to see that...

Posted: Mon Jun 23, 2008 1:04 pm
by quanganht
Well, I said it CAN'T run on my GMA 950. Then I used swiftshader v2.1
(a software rasterizer) so it ran at ~15 fps. Not bad ! I also tried running it on Radeon X1300 Mobility and it ran fast, about 50fps or more :wink:

Posted: Mon Jun 23, 2008 3:55 pm
by nullsquared
xadhoom wrote:It seems that the the SSAO shadows "move" heavily depending on angle
and surface on screen. In the most confusing situation it looks like a torus
knot is very near to a wall and if you rotate around it the SSAO shadow
disappears and you can see that there is a signifcant distance between wall
and knot... can this be avoided by lowering a distance threshold?
You have to turn out the flashlight to see that...
Well, that's really one of the bigger issues with SSAO, it's in screen space. So, obviously as the screen data (the depth) changes, so will the SSAO. The point for SSAO is not to produce 100% correct AO, but to merely trick the eye into believing there is indeed AO going on.

Posted: Mon Jun 23, 2008 4:26 pm
by nikki
Looks very nice. But I have a really old graphics card (GeForce FX 5600), and get really low FPS on most good looking stuff like this. :(

Posted: Mon Jun 23, 2008 4:33 pm
by nullsquared
nikki wrote:Looks very nice. But I have a really old graphics card (GeForce FX 5600), and get really low FPS on most good looking stuff like this. :(
Does your 5600FX even run this? Because the demo renders to a 128-bit texture (32 bits for each channel)...

Posted: Mon Jun 23, 2008 4:41 pm
by nikki
nullsquared wrote:
nikki wrote:Looks very nice. But I have a really old graphics card (GeForce FX 5600), and get really low FPS on most good looking stuff like this. :(
Does your 5600FX even run this? Because the demo renders to a 128-bit texture (32 bits for each channel)...
Yeah, it does, but then I had to count seconds per frame instead of frames per second. :roll: Don't worry about it though, I'm going to get a new graphics card anyway (its just that my motherboard was confining me to the older ones, I gotta get a new motherboard too).