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
x 11

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

Post by nullsquared »

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?
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
x 5

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

Post by Praetorian »

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).
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
x 11

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

Post by nullsquared »

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.
Godlike
Kobold
Posts: 27
Joined: Thu Jul 10, 2008 2:22 pm

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

Post by Godlike »

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).
Godlike
Kobold
Posts: 27
Joined: Thu Jul 10, 2008 2:22 pm

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

Post by Godlike »

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:
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 »

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...
Godlike
Kobold
Posts: 27
Joined: Thu Jul 10, 2008 2:22 pm

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

Post by Godlike »

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
User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany
x 1

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

Post by xadhoom »

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
Godlike
Kobold
Posts: 27
Joined: Thu Jul 10, 2008 2:22 pm

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

Post by Godlike »

LOL so my idea is not completely out of this world :D
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 »

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!
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

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

Post by nullsquared »

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
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 »

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.
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

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

Post by nullsquared »

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).
Pryo
Halfling
Posts: 43
Joined: Tue Feb 24, 2009 5:39 am

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

Post by Pryo »

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!
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

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

Post by nullsquared »

Search for my SSAO compositor demo, it's newer and I believe I compiled it with Shoggoth.
Pryo
Halfling
Posts: 43
Joined: Tue Feb 24, 2009 5:39 am

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

Post by Pryo »

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.
Lax
Hobgoblin
Posts: 583
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 50

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

Post by Lax »

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

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

Post Reply