Page 1 of 2

[Zlib/libPNG] SimpleSSAO - 1 Line SSAO | Now on BitBucket!

Posted: Wed Jan 25, 2012 7:55 pm
by Mind Calamity
Hello guys and gals of the OGRE Community!

So, this is my first thread in the Showcase forum, I hope anyone finds it useful.

This is a simple class I made for simple implementation of SSAO in anyone's application.
It's based on nullsquared's SSAO demo (Well it's basically the same I just cleaned up the code and made it portable). (Thanks null!)

On:
Image

Off:
Image

<Moved instructions to the BitBucket repository page.>

BitBucket repository: here.
Precompiled demo: here.
Wiki Page: SimpleSSAO.
Hope you find this useful! :)

Any comments are much appreciated.

Update 20/11/2012: Made some changes that should fix some problems, thanks to ppClarity :)
Update 1/6/2013: Refactored the source, made some directory changes for the demos and added a few fixes. Changed license to zlib/libpng, now hosting on BitBucket. Also updated to Ogre 1.8.
Update 28/8/2015: Fixed broken repo links from changing my BitBucket username.

Re: SimpleSSAO - 1 Line SSAO

Posted: Fri Jan 27, 2012 8:23 pm
by KungFooMasta
Wow! That is super simple! I'm still aways from using fancy effects like SSAO in my projects, but this will definately be of use when I get to that stage. Thanks for the simple release. :D

Re: SimpleSSAO - 1 Line SSAO

Posted: Fri Jan 27, 2012 10:24 pm
by macleod
Can I use Normal and Specular maps too ?

Re: SimpleSSAO - 1 Line SSAO

Posted: Sat Jan 28, 2012 7:20 am
by Mind Calamity
Thanks KungFooMasta, the simplicity of your 2D renderer inspired me to do something simple, light and easy-to-use.
macleod wrote:Can I use Normal and Specular maps too ?
You should be able to, although I haven't tried it yet myself.

Re: SimpleSSAO - 1 Line SSAO

Posted: Sat Jan 28, 2012 6:12 pm
by madmarx
Yeah, null was doing really great stuff with Ogre. Very good that you have put this one in 1 class.

Re: SimpleSSAO - 1 Line SSAO

Posted: Tue Jan 31, 2012 11:21 am
by Tubulii
Thanks for the release,

but I get several errors when I try to start the precompiled demo:
The plugin file contains to much plugins (which do not exist)

And finally:

Code: Select all

OGRE EXCEPTION(7:InternalErrorException): Unable to Set create State: CG ERROR : The parameter used is invalid. in CgFxScriptLoader::CgStateListener::init at D:/Libraries/ogre/PlugIns/CgProgramManager\src/OgreCgProgramManagerDll.cpp (line 67)
Could you fix this?

Re: SimpleSSAO - 1 Line SSAO

Posted: Tue Jan 31, 2012 1:49 pm
by Mind Calamity
@Tubulii:

Thanks for reporting that, I didn't notice because I have the Cg toolkit installed.

I included the cg.dll file and removed all the unnecessary plugins that were not included anyway.

So, now it should work.

To save you a sec: Click!

@madmarx:

Yeah, seems so.

Re: SimpleSSAO - 1 Line SSAO

Posted: Wed Feb 01, 2012 2:51 am
by shenjoku
This is pretty awesome. We're still a long ways away from polishing the game and graphics, but once we get there I'm definitely going to try to include this. Great work :)

I have a few questions:
1.) What do you have to do for shutdown and when is a good time to delete the created PFXSSAO object?
2.) Any idea how to make this work with the depth shadowmap PCF shadows that come with Ogre? Or is it you can only use one or the other? I'm still kind of new to the world of shadow rendering.

Re: SimpleSSAO - 1 Line SSAO

Posted: Fri Feb 03, 2012 4:08 am
by zarfius
I converted this to Mogre. Code is available on my blog.

Thanks Mind Calamity you made it very easy :)

Re: SimpleSSAO - 1 Line SSAO

Posted: Fri Feb 03, 2012 9:05 am
by Mind Calamity
shenjoku wrote:This is pretty awesome. We're still a long ways away from polishing the game and graphics, but once we get there I'm definitely going to try to include this. Great work :)

I have a few questions:
1.) What do you have to do for shutdown and when is a good time to delete the created PFXSSAO object?
2.) Any idea how to make this work with the depth shadowmap PCF shadows that come with Ogre? Or is it you can only use one or the other? I'm still kind of new to the world of shadow rendering.
1. You don't need to delete it at all, as I didn't even create a destructor, but in any case I think OGRE will take care for the shutdown of the compositors, which is what PFXSSAO contains, also I don't even think you need to remove it as a listener from the scene manager either.
2. I couldn't even implement shadows properly, so I couldn't really try it, I did want to try it with PSSM though, it would look really awesome! ;)
- You can try messing with the diffuse.material to try and make it use shadows too.
zarfius wrote:I converted this to Mogre. Code is available on my blog.

Thanks Mind Calamity you made it very easy :)
Glad you liked it! Good job porting it to C#/MOGRE! Also, any particular reason not to post the code to the wiki directly ?

BTW - Guys since I suck at shader programming, did anyone find how to increase the SSAO range in the shader ?

Re: SimpleSSAO - 1 Line SSAO

Posted: Fri Feb 03, 2012 10:52 am
by duststorm
Thanks! I haven't experimented with a lot of these effects either. But with a nice package like this I might be tempted to throw it in my codebase just to try it out. Who know, it might just end up in there.
macleod wrote:Can I use Normal and Specular maps too ?
Since normal and spec mapping are regular fragment shaders, and SSAO is a compositor effect applied to the whole image after it is rendered, you can easily use them together without having to combine them into one single shader.
Just setup your normal/spec material shaders like you would normally, and add SSAO using the compositor framework.

Re: SimpleSSAO - 1 Line SSAO

Posted: Fri Feb 03, 2012 12:41 pm
by zarfius
Mind Calamity wrote:Glad you liked it! Good job porting it to C#/MOGRE! Also, any particular reason not to post the code to the wiki directly ?
Not really, I wanted it on my blog and it's a lot of effort to type it up in both places. I did add a link to it at the bottom of the wiki page though.

Re: SimpleSSAO - 1 Line SSAO

Posted: Mon Feb 06, 2012 12:08 pm
by duststorm
Does anyone know what the difference is between those two SSAO posts from nullqsuared?
http://www.ogre3d.org/forums/viewtopic.php?f=11&t=42350
http://www.ogre3d.org/forums/viewtopic.php?f=11&t=47927

I can't compare since one of them is offline.
Maybe it's a good idea to post all code examples and demos on the wiki as attachments, so we don't lose them in the future.

Concerning the other SSAO (compositor) implementation of nullsquared, lordsme contributed an improvement that makes it work for semi transparent materials. It's very interesting, have a look here:
http://ogre3d.org/forums/viewtopic.php?p=446784#p446784
Does this version work with semi transparent textures?

Re: SimpleSSAO - 1 Line SSAO

Posted: Mon Feb 06, 2012 3:24 pm
by Mind Calamity
I couldn't see the difference between the two (there is a mirrored link at the last page), and it's exactly the same as the one before.

As for that patch by lordsme, I did see it, but unfortunately I don't know how to implement it, if anyone is shader savvy please make the needed modifications.

Re: SimpleSSAO - 1 Line SSAO

Posted: Tue Feb 07, 2012 6:56 am
by satchigi
I'm impressed.
but I got a one problem that all shadows in my game turn blue.
I also fixed shadowTexturePixelFormat to PF_R8G8B8 but no help.

And is there any quick way to modify all material I have?
This SSAOmethod is really good (simplest I've seen) except one fact that need to do modify all the materials.
anyone help?

Re: SimpleSSAO - 1 Line SSAO

Posted: Tue Feb 07, 2012 3:26 pm
by duststorm
You could specify a different material scheme name for the compositor effect, that none of your materials have defined in their .material file.
Then you create a custom MaterialListener and implement your own handleSchemeNotFound() method, where you pass the renderer the correct material. So you create your SSAO materials using code. I experimented with this and gave an example here: http://www.ogre3d.org/forums/viewtopic. ... 75#p437175

Re: SimpleSSAO - 1 Line SSAO

Posted: Mon Feb 13, 2012 1:32 pm
by dudeabot
AFAIK the second one comes as a compositor, easier to integrate.

i wonder what happed to nullsquared, he did some awesome things :)

Re: SimpleSSAO - 1 Line SSAO

Posted: Tue Feb 14, 2012 9:32 am
by satchigi
dudeabot//
plz tell me where is second one. I want to try.

BTW, What do you mean for second one?

It's second one of nullsquare's ? or this post's one?

thanks

Re: SimpleSSAO - 1 Line SSAO

Posted: Tue Feb 14, 2012 10:25 am
by Mind Calamity
satchigi wrote:dudeabot//
plz tell me where is second one. I want to try.

BTW, What do you mean for second one?

It's second one of nullsquare's ? or this post's one?

thanks
Yeah, the second one is by nullsquared, but I couldn't really get that (or maybe this is the adaption of the second one ?), either way, this code uses a compositor too, it's just that it, and the material and compositor listeners are automatically created.

I forgot to add a function to retrieve the compositor instance, but I will in the next patch (I may redo the whole thing).

Re: SimpleSSAO - 1 Line SSAO

Posted: Sat Mar 03, 2012 1:44 am
by noorus
This looks promising :)
If you're interested in taking the project further... what about the advanced SSAO algorithms demonstrated with Ogre here?

Re: SimpleSSAO - 1 Line SSAO

Posted: Sat Mar 03, 2012 8:59 am
by Wolfmanfx
This sample is already incorporated in 1.8 Samplebrowser

Re: SimpleSSAO - 1 Line SSAO

Posted: Sun Mar 18, 2012 6:38 pm
by mfdesigner
Excellent work.

I've incorporated it into my engine.
There are several issues with the shadow as the video below demonstrates.



(1) I added this line to make the shadow shown (otherwise, it doesn't show when light is further away then the objects.)

Code: Select all

mSceneMgr->setShadowFarDistance( mCamera->getFarClipDistance()+1000 );
(2) only point light casts shadows. No shadow from spot or directional light.

(3) When I move camera, shadow gets clipped.

(4) at certain angle, shadow has rough edges.

(5) halo effect.

Re: SimpleSSAO - 1 Line SSAO

Posted: Sun Mar 18, 2012 10:32 pm
by Mind Calamity
As soon as I finish my current project, I'll see what I can do on improving this (and my knowledge on shaders) and fixing the bugs.

Re: SimpleSSAO - 1 Line SSAO

Posted: Tue Nov 20, 2012 1:24 am
by ppClarity
In shadowTextureCasterPreViewProj() on line 127, the argument passed to setFarClipDistance() is a constant 99990. In nullsquared's original code it uses the range variable set on line 125.

Another thing, his materials look like this:

Code: Select all

import diffuse_template from "diffuse.material"

material metal : diffuse_template
{
    set_texture_alias ambient_tex RustedMetal.jpg
    set_texture_alias diffuse_tex RustedMetal.jpg
}
Changing the farClipDistance back to range and using the above format fixed some problems I was having with illumination and shadows. However I still get some odd shadowing artifacts that I'm trying to hunt down.

Re: SimpleSSAO - 1 Line SSAO

Posted: Tue Nov 20, 2012 3:31 am
by Mind Calamity
I updated the code and the original post above with the changes you suggested.

Updated code: http://pastebin.com/uSBLgM4X (same link as in the original post, just edited)

Please test it if you can, I don't have OGRE setup properly right now.