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

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
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

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

Post 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.
Last edited by Mind Calamity on Fri Aug 28, 2015 9:53 am, edited 9 times in total.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16
Contact:

Re: SimpleSSAO - 1 Line SSAO

Post 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
Creator of QuickGUI!
macleod
Kobold
Posts: 25
Joined: Sat Jan 15, 2011 7:11 pm
x 3

Re: SimpleSSAO - 1 Line SSAO

Post by macleod »

Can I use Normal and Specular maps too ?
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: SimpleSSAO - 1 Line SSAO

Post 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.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1671
Joined: Mon Jan 21, 2008 10:26 pm
x 50

Re: SimpleSSAO - 1 Line SSAO

Post by madmarx »

Yeah, null was doing really great stuff with Ogre. Very good that you have put this one in 1 class.
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
User avatar
Tubulii
Gnoblar
Posts: 5
Joined: Tue Jul 19, 2011 11:52 am

Re: SimpleSSAO - 1 Line SSAO

Post 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?
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: SimpleSSAO - 1 Line SSAO

Post 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.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
shenjoku
Gremlin
Posts: 193
Joined: Sat Aug 06, 2011 11:02 pm
x 6

Re: SimpleSSAO - 1 Line SSAO

Post 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.
User avatar
zarfius
Gnome
Posts: 367
Joined: Wed Jan 03, 2007 12:44 pm
Location: Brisbane, Australia
x 13
Contact:

Re: SimpleSSAO - 1 Line SSAO

Post by zarfius »

I converted this to Mogre. Code is available on my blog.

Thanks Mind Calamity you made it very easy :)
Craftwork Games - hand crafted entertainment.
http://www.craftworkgames.com/
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: SimpleSSAO - 1 Line SSAO

Post 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 ?
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
x 80
Contact:

Re: SimpleSSAO - 1 Line SSAO

Post 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.
Developer @ MakeHuman.org
User avatar
zarfius
Gnome
Posts: 367
Joined: Wed Jan 03, 2007 12:44 pm
Location: Brisbane, Australia
x 13
Contact:

Re: SimpleSSAO - 1 Line SSAO

Post 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.
Craftwork Games - hand crafted entertainment.
http://www.craftworkgames.com/
User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
x 80
Contact:

Re: SimpleSSAO - 1 Line SSAO

Post 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?
Developer @ MakeHuman.org
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: SimpleSSAO - 1 Line SSAO

Post 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.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
satchigi
Kobold
Posts: 35
Joined: Mon Jul 18, 2011 2:56 pm

Re: SimpleSSAO - 1 Line SSAO

Post 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?
User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
x 80
Contact:

Re: SimpleSSAO - 1 Line SSAO

Post 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
Developer @ MakeHuman.org
dudeabot
Gnome
Posts: 334
Joined: Thu Jun 28, 2007 2:12 pm
Location: Brazil
x 5
Contact:

Re: SimpleSSAO - 1 Line SSAO

Post by dudeabot »

AFAIK the second one comes as a compositor, easier to integrate.

i wonder what happed to nullsquared, he did some awesome things :)
satchigi
Kobold
Posts: 35
Joined: Mon Jul 18, 2011 2:56 pm

Re: SimpleSSAO - 1 Line SSAO

Post 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
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: SimpleSSAO - 1 Line SSAO

Post 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).
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
noorus
Halfling
Posts: 75
Joined: Wed Apr 20, 2011 9:55 pm
Location: Helsinki, Finland
x 3

Re: SimpleSSAO - 1 Line SSAO

Post by noorus »

This looks promising :)
If you're interested in taking the project further... what about the advanced SSAO algorithms demonstrated with Ogre here?
Creator of Nice Input Library, for your advanced input needs.
Image
User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 99
Contact:

Re: SimpleSSAO - 1 Line SSAO

Post by Wolfmanfx »

This sample is already incorporated in 1.8 Samplebrowser
mfdesigner
Gnoblar
Posts: 19
Joined: Sun Aug 03, 2008 9:56 pm
x 1

Re: SimpleSSAO - 1 Line SSAO

Post 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.
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: SimpleSSAO - 1 Line SSAO

Post 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.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
ppClarity
Gremlin
Posts: 194
Joined: Sat Sep 02, 2006 12:27 am
x 2

Re: SimpleSSAO - 1 Line SSAO

Post 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.
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: SimpleSSAO - 1 Line SSAO

Post 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.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
Post Reply