SSAO [Screen Space Ambient Occlusion] Demo + Source

A place to show off your latest screenshots and for people to comment on them. Only start a new thread here if you have some nice images to show off!
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA

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

Post by nullsquared » Sat Jan 03, 2009 9:59 pm

Wow, cool :)

In Portalized we are using baked AO for tight occlusions on singular objects, and SSAO for inter-object occlusion (well, SSGI on high settings).

I bet you can make the SSAO work much faster for you, I will help you optimize every single bit of it, I know for a fact that it can perform much better than in this demo. First of all, what normal/depth texture formats are you using? Second, are you using my random samples or your own? What kind of blur are you doing on it? What GPU are you using?
0 x

User avatar
Praetorian
Google Summer of Code Student
Google Summer of Code Student
Posts: 171
Joined: Fri Aug 10, 2007 10:37 pm
Location: WA - USA

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

Post by Praetorian » Sat Jan 03, 2009 10:33 pm

Thanks for the quick response, at the moment I'm more or less using it as it is in the demo since I've never really read too heavily into SSAO and I haven't had time to 'dissect' it and figure out how it works :) . So I am using the same texture formats as the demo (128 bit for the normal/depth, and I just tried with 64bit and it caused a slight performance increase and no really noticable lessening of precision/quality). I am using your random samples, and the blur for the moment is simply a blurred texture read in the ambient shader for all my objects (not as efficient as blurring the whole thing, but I've been juggling graphics improvements with physics engine issues and haven't had as much time as I'd like to focus on this :? ). My GPU is a 512mb AGP GeForce 7600GS, and the rest of my computer is ancient (my cpu is a much greater performance bottleneck at the moment).
0 x
My Google summer of code 2011 topic: Unit Testing Framework
My Google summer of code thread
My Google summer of code wiki page

User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA

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

Post by nullsquared » Sat Jan 03, 2009 10:44 pm

Ah, excellent. A rather low-profile GPU, this is exactly what we need to accelerate the speed :D I'll code up some improvements and upload a new demo.
0 x

Godlike
Kobold
Posts: 27
Joined: Thu Jul 10, 2008 2:22 pm

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

Post by Godlike » Wed Feb 11, 2009 10:57 am

Hi there, I tried the demo but OGRE.LOL shows me this lines:

10:53:45: Loading library RenderSystem_Direct3D9
10:53:48: OGRE EXCEPTION(7:InternalErrorException): Could not load dynamic library RenderSystem_Direct3D9. System Error: Impossible to find the specified module.
in DynLib::load at D:\Ogre_CVS\ogrenew\OgreMain\src\OgreDynLib.cpp (line 80)

Of course my machine has DX9 updated to latest version (and GPU supports DX10 I think).
0 x

Godlike
Kobold
Posts: 27
Joined: Thu Jul 10, 2008 2:22 pm

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

Post by Godlike » Wed Feb 11, 2009 1:10 pm

I was also thinking, but maybe I am wrong, couldn't it be a good idea to calculate SSAO on a halved in size z buffer?
This would cut off almost three quarters of GPU work first of all.
More, it would cut off the need of blurring a full res SSAO layer because stretching it from half to the size of the main render already blurs it enough (tested with Photoshop).
The only drawback is that on the edges with more AO contrast you have some blur but if you keep SSAO layer at a max of 40% multiplication it's quite fine, considering the performance gain you could have :oops:

Sorry if I wrote a bunch of bullshiz, I am not a shader programmer or anything so I may be completely wrong :mrgreen:
0 x

User avatar
Wretched_Wyx
Orc
Posts: 498
Joined: Thu Mar 16, 2006 5:27 pm
Contact:

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

Post by Wretched_Wyx » Wed Feb 11, 2009 2:51 pm

You could certainly mirror the blending modes of Photoshop, but I do believe quality change due to resizing will be quite different between Photoshop and Ogre (or other rendering systems). I know that you can double the size of a (smaller than render window resolution) RTT to get a cheap blur, but am quite curious how such methods would work here...
0 x

Godlike
Kobold
Posts: 27
Joined: Thu Jul 10, 2008 2:22 pm

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

Post by Godlike » Wed Feb 11, 2009 7:44 pm

Ye ye, I'm not sure of anything, but I think this might be an idea to try.
I can see, though, that textures stretched in Ps and in hardware look quite similar and here we are only averaging a matrix of 2x2 so there shouldn't be that much difference unless you use special options like "sharper edges" and such.

Anyway, even if hardware scaling will look less "blurry" than the Photoshop one, a multiply of 30-40% should still look good, and less grainy than a full res unblurred.
As I said, I think the only countereffect could be a bit of blur on some polys silhouettes (the ones where contrast of SSAO is higher respect to what is behind).

It's all a matter of accepting this drop in quality to have a very effective filter for visuals.
And after all, on higher resolutions, this error becomes less and less visible 8)

Here I have a couple of screens:
http://img22.imageshack.us/img22/8900/done01ld6.jpg
http://img22.imageshack.us/img22/1434/done11os4.jpg

Animated! http://img22.imageshack.us/img22/5906/doneanimgu8.gif
0 x

User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany

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

Post by xadhoom » Wed Feb 11, 2009 9:14 pm

In the Starcraft2 tech explanation they do a low res SSAO: http://www.ogre3d.org/forums/viewtopic.php?f=1&t=47475
It is worth to be read!

xad
0 x

Godlike
Kobold
Posts: 27
Joined: Thu Jul 10, 2008 2:22 pm

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

Post by Godlike » Wed Feb 11, 2009 9:17 pm

LOL so my idea is not completely out of this world :D
0 x

osknoes
Gnoblar
Posts: 15
Joined: Tue Jan 20, 2009 4:33 am
Location: Montreal, Canada

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

Post by osknoes » Sat Mar 28, 2009 12:52 am

Hi guys!
I'm working in my SSAO. I'm using the nullsquared SSAO as a base (what a great work!).
I've read all the thread more than once to understand what really I'm doing, not just go forward and copy paste the code.
As zeal did, I'm using compositors. I learn I've to pass my right_far_corner from my original camera to my material, without using the compositor camera properties. I learned too, that I can't use the projection matrix from the compositor because that's wrong (working with nullsquared proj matrix).

After sometime working on it, I got a problem and I don't know how to solve it. When I try to get new values from my NormalDepth map, I get wrong coordinates. For the depth map I use length(viewpos.xyz), as nullsquared does. I've debugged my viewPos map, and looks right. The viewDirection vector looks right too(black/green/yellow/red).

vertex :

Code: Select all

VS_OUTPUT quad_vs(float4 Pos : POSITION){
   VS_OUTPUT Out;
   Pos.xy 	= sign(Pos.xy);
   Out.Pos 	= float4(Pos.xy, 0, 1); 
   Out.texCoord.x = 0.5 * (1.0 + Pos.x);
   Out.texCoord.y = 0.5 * (1.0 - Pos.y);
   Out.viewDirection = float3(ViewDirection.x * Out.Pos.x, ViewDirection.y * Out.Pos.y, ViewDirection.z);   
   return Out;
}
pixel : only the code to get the new texturecoordinates

Code: Select all

float depth = tex2D(Tex0, IN.texCoord).a; // depth map
float3 se 	= normalize(IN.viewDirection) * depth;	
float4 ssT 	= mul(Proj, float4(se, 1.0));
return float4(tex2D(Tex0, ssT.xy/ssT.w).rgb, 1);	
Here two comparative pics. The first is just drawing the normal map with the input texCoords.
Image

The second one is using the code above.
Image

Help will be really really appreciated!
0 x

User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA

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

Post by nullsquared » Sat Mar 28, 2009 1:35 pm

Hm...

Can I see a screenshot of this:

Code: Select all

float3 se    = normalize(IN.viewDirection) * depth;  
(as the final colour)

Also, can I see the exact code you're using to calculate your projection matrix?

Last thing, I have a newer demo that does the same thing via compositors, it's much cleaner than this old demo: http://www.ogre3d.org/forums/viewtopic.php?f=11&t=47927
0 x

osknoes
Gnoblar
Posts: 15
Joined: Tue Jan 20, 2009 4:33 am
Location: Montreal, Canada

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

Post by osknoes » Sat Mar 28, 2009 3:34 pm

First of all, just to say I solved it, and now it works. I'm happy I did it! ;)
I'm using the projection matrix from my original camera and I pass the matrix to the material. Btw, it will be really nice if we find why doesn't work with your matrix.
Btw, here the pic you asked:
Image
And here the code of the initial projection matrix I was using :

Code: Select all

static const float4x4 Proj =
{
    0.5,    0,    0,  0.5,
    0,   -0.5,    0,  0.5,
    0,      0,    1,    0,
    0,      0,    0,    1
};
Here the new one :
- .cpp :

Code: Select all

Ogre::MaterialPtr mat= (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().getByName("ssao"); 
GpuProgramParametersSharedPtr mSSAOParams = mat->getTechnique(0)->getPass(0)->getVertexProgramParameters();
GpuProgramParametersSharedPtr mSSAOParamsPS = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters();	
mSSAOParams->setNamedConstant("ViewDirection", farTopRight);
mSSAOParamsPS->setNamedConstant("ProjectionMatrix", m_pCurrentCamera->m_pCamera->getProjectionMatrix());
-pixel shader :

Code: Select all

float4 sample 	= float4(vp, 1.0);	
float4 ss 	= mul(ProjectionMatrix, sample);		
float2 sampleTexCoord = 0.5f * ss.xy/ss.w + float2(0.5f, 0.5f);
sampleTexCoord.y = 1 - sampleTexCoord.y;
Now I've to clean my code, etc. but then I will take a look to your new source because looks awesome one more time. I'm excited to compare how you did it (you're a expert user), and how I did it (just few weeks using ogre, and few days using compositors). I hope I will find some great tricks to optimize the algorithm or something else, because you're doing an amazing job with ogre3d.

Just one last thing, you always say that depending of the metrics we should tweak some values (radius, etc). There's a way to set this in ogre3D (like set metrics, whatever) or it's only a thing that effect the SSAO variables. I'm working with 1 u = 10 m (from 3dsmax), so any advices how to adjust it will be really appreciated too.
0 x

User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA

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

Post by nullsquared » Sat Mar 28, 2009 6:06 pm

osknoes wrote:First of all, just to say I solved it, and now it works. I'm happy I did it! ;)
I'm using the projection matrix from my original camera and I pass the matrix to the material. Btw, it will be really nice if we find why doesn't work with your matrix.

And here the code of the initial projection matrix I was using :

Code: Select all

static const float4x4 Proj =
{
    0.5,    0,    0,  0.5,
    0,   -0.5,    0,  0.5,
    0,      0,    1,    0,
    0,      0,    0,    1
};
That's not the full projection matrix. It's just a quick trick:

Code: Select all

flaot4 screenCoords = mul(projMat, pos);
screenCoords.xy /= screenCoords.w;

// this part is necessary to move the [-1..1] coordinates into texture-space [0..1]
screenCoords.xy = screenCoords.xy * 0.5 + 0.5; // or (screenCoords.xy + 1) * 0.5, same thing
// however, if you concatenate the projection matrix with the above matrix, then you get this coordinate shift for free
// just by transforming by the now slightly modified projection matrix
Now I've to clean my code, etc. but then I will take a look to your new source because looks awesome one more time. I'm excited to compare how you did it (you're a expert user), and how I did it (just few weeks using ogre, and few days using compositors). I hope I will find some great tricks to optimize the algorithm or something else, because you're doing an amazing job with ogre3d.
Well, the demo doesn't really have as many tricks as possible, but there are a few. For example, the SSAO is computed at 1/2 the screen resolution, etc. One cute trick is that you can actually encode the depth and normals into two byte RGBA textures (no floating point textures), meaning you can use a gbuffer of four RGBA8 textures, which is a lot more compatible than mixing the texture formats. I didn't do this in the demo, though.
Just one last thing, you always say that depending of the metrics we should tweak some values (radius, etc). There's a way to set this in ogre3D (like set metrics, whatever) or it's only a thing that effect the SSAO variables. I'm working with 1 u = 10 m (from 3dsmax), so any advices how to adjust it will be really appreciated too.
Ogre simply renders whatever you give it, so there are no "Ogre units" or anything like that. It all depends on how you position your camera. If the camera is near the ceiling, does that mean the room is really small or does that mean the camera is just really high up ;)? This is why you want to play with the SSAO radius (and maybe some of the other space-related variables).
0 x

Pryo
Halfling
Posts: 43
Joined: Tue Feb 24, 2009 5:39 am

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

Post by Pryo » Thu Jun 11, 2009 9:51 am

Hi nullsquared, really impressive work.

Not to contradict what I just said, I just spent the past 4 hours trying to get any of your shadow related code to work without success. I'm completely new to CG scripts among other things, so a lot of this is very tricky. I've tried several variations of swapping and changing code around to either bring some of your code into mine, or mine into yours resulting in a lot of very bad crashes (as in BSODs).

But I eventually decided to see if I can even compile your code as it stands unaltered, and that itself fails. Apparently in OGRE 1.6, ShadowListener was changed to SceneManager::Listener. I tried doing a few things to work around this but get ever more errors. And after another hour, I thought that maybe I should cry for help. Have you been working on this recently? Do you have any updated code that works in Ogre 1.6?

I saw the screenshots and got excited... Maybe I should go away and learn things step by step rather than trying to jump in the deep end!
0 x

User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA

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

Post by nullsquared » Thu Jun 11, 2009 11:04 am

Search for my SSAO compositor demo, it's newer and I believe I compiled it with Shoggoth.
0 x

Pryo
Halfling
Posts: 43
Joined: Tue Feb 24, 2009 5:39 am

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

Post by Pryo » Thu Jun 11, 2009 10:59 pm

nullsquared wrote:Search for my SSAO compositor demo, it's newer and I believe I compiled it with Shoggoth.
Thanks nullsquared. I found the thread and got your code. Unfortunately the newer demo will not run on my hardware. I'll have to come back to this in the future. I only have time now to get a very basic shadow implementation sorted out. See http://www.ogre3d.org/forums/viewtopic.php?f=5&t=50581 for my current quandary on even that front.
0 x

Lax
Gnome
Posts: 301
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 4

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

Post by Lax » Mon Feb 08, 2016 11:42 am

Hi,

thanks for the great SSAO feature!

I integrated it in my application and it works fine so far. Has somebody SSAO and normal mapping working? I read the thread but I have no clue how to integrate that feature.

Does somebody have an example?

Regards,
Lax
0 x

Post Reply