SSAO help

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
jingquan
Posts: 222
Joined: Sun Aug 20, 2006 4:10 am
Contact:

SSAO help

Post by jingquan »

WTF!? :evil: I hit submit and my internet instantly killed my text, and hitting back made me retype. :cry: Oh, nevermind.

I'm working on screen space ambient occlusion and got to the point where I had to sample my depthmaps at specific points, but I'm getting major artifacts like strange silhouette of objects and major bandings:

Sure my depthmap is precise enough as I encoded the 3color components in it as well. (The R8B8G8A8, which should give me 32-....bits? Is it called that?

I'm suspecting it's due to the projection of the several eyerays for depth difference. What do you think?
Last edited by jingquan on Thu Mar 20, 2008 12:47 pm, edited 1 time in total.
jingquan
Posts: 222
Joined: Sun Aug 20, 2006 4:10 am
Contact:

Post by jingquan »

A little update: I had to optimize my depth values to get rid of the banding. The ghosting was caused by the incorrect camera frustum.

Image

Now it looks like a really bad toon shading. I'll check out my eyeray depth tmr, and that's probably causing the sampling problems.

BTW, is sourceforge screwing up again?
jingquan
Posts: 222
Joined: Sun Aug 20, 2006 4:10 am
Contact:

HELppppp.....

Post by jingquan »

Ok, I can't get it to work. If anyone have any experiences with shaders, you can check out my current screen space ambient occlusion code and see if there's any glaring mistake I made, which there should be?
Thank you.
Last edited by jingquan on Wed Mar 05, 2008 5:28 am, edited 1 time in total.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

I'm not too sure if this would make a difference, but you seem to use integers alot in the shader. Sometimes not placing a ".0" after a constant can cause undesired effects.

Cheers

PS: In most cases SSAO is really just an overhyped toon shader, so you may be closer than you think?
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
jingquan
Posts: 222
Joined: Sun Aug 20, 2006 4:10 am
Contact:

Post by jingquan »

Ok, thanks, but it looks the same. Right now I'm getting some lines at the corners, something like a toon shader, but they disappear when I change my view to another position. Also, there's lots of noise everywhere.

I changed the eyespace position.
Last edited by jingquan on Wed Mar 05, 2008 5:28 am, edited 1 time in total.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Im doing something like this:

Code: Select all

float Depth = (Read depth at pixel position);
float occludeFactor = 0.0;

Loop through samples (Around 4 - 16 samples usually)
{
float OtherDepth = (Read depth at neighbouring pixel position);
occludeFactor += clamp(Depth - otherDepth,0.001,0.999);
}

occludeFactor *= 50.0; // Multiply by a high number.
Thats the basic theory, its very simple. Offcourse some tweaking and adjustment is needed to get a decent look.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
jingquan
Posts: 222
Joined: Sun Aug 20, 2006 4:10 am
Contact:

Post by jingquan »

Looks like its not going to work for me. Here's the latest version if you would like to give it a try: http://pastebin.com/m528517a0

Right now I'm using it as a very expensive postprocess to generate grains for my scene, and it actually looks a little better with it. :wink:

Thanks.
jingquan
Posts: 222
Joined: Sun Aug 20, 2006 4:10 am
Contact:

Post by jingquan »

I'm not sure if it's a coincident that my shaders refuse to work since I last coded my SSAOs in Notepad. :D Rendermonkey is too much of a trouble setting up.

Anyway, I tried another form of SSAO: the crease shading. http://www.shalinor.com/code.html and it doesn't quite work either. There is only shading between objects at some parts but there isn't any shading happening on the object itself. e.g. My mesh level doesn't gets crease-shaded at corners, except certain parts that are sticking out which are rarely shaded too.

Image

I'm sure my normal (the one with red/blue/black...colors) and the position (4 squares with light colors on every object) passes are correct.

If anyone could help me I'm so happy. :D

Code: http://pastebin.com/m1dbf2833
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

I already gave you the pseudo code for my SSAO, why not try it? Its really easy to implement. You also won't need any position/normal info, just depth.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
jingquan
Posts: 222
Joined: Sun Aug 20, 2006 4:10 am
Contact:

Post by jingquan »

OK, I've tried your depth method and it looks good, at least for a fancy toon shader.

Sorry, anyway, here's what I'm looking at:

Image

Good that its highlighting everything, but is it suppose to be doing it at the topright end of meshes? I encoded my depth to use all of the color channels but there's still light bandings.

Here's my code: http://pastebin.com/m331b0b1b

Let me know how I can optimize it further, thanks Blindside.





EDIT: FIXXXXXED!!!!! :D

Image

It's so sweet! I was rushing it and forgotten about looping all the samples. (simply change PxOffsets[1] to PxOffsets in the last code) :wink:

There's a slight problem with it....Shouldn't the tabletop and weapon be non-shaded? How can I create a range based on the amount of depth differenced so that only values with slight depth diff would be shaded? Also, is there a way to get rid of the banding?

EDIT: Banding gotten rid by giving the 2nd depth a slight depth bias.

EDIT2: I tried a simple cutaway for the SSAO.

Code: Select all

        float ao = clamp(centerDepth - sampleDepth, 0.001, 0.999);
	if (ao < 0.022)
	color += ao;
Any better ideas?

BTW, what's the use of multiplying with a large number?

Thanks!
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Hehe nice going, first shadow maps then ssao, you seem to be benefiting quite a bit from my advice. :lol:

I used a similar approach to your cutoff for the SSAO, though I don't have the code on me, I think I scaled by the same factor that causes the ssao itself (the depth difference), to create some kind of parabolic effect.

Good luck, It's starting to look pretty nice.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
jingquan
Posts: 222
Joined: Sun Aug 20, 2006 4:10 am
Contact:

Post by jingquan »

Hehe nice going, first shadow maps then ssao, you seem to be benefiting quite a bit from my advice.
Yesss, master of shadows! :lol: I'll want to do cubemapping too. :D

What is a parabolic effect? I'd like to try out your method too.

Anyway, here's the depth SSAO which looks great with a blur. It runs rast too since I do not have to render my scene twice (I don't have MRT support :( ) for depth and normals if I use the crysis method (which doesn't work too).

http://www.orandysoftware.com/user_files/decssao.jpg

SSAO + my scene:

http://www.orandysoftware.com/user_files/decnorm.jpg

BTW, is there a post processing method to fake irradiance? I tried spreading areas that are bright but it looked like bad bloom.

Thanks bliindside.
cooljayman
Posts: 22
Joined: Wed Mar 05, 2008 8:25 am

Post by cooljayman »

jinquan that looks great! could you post the source please(not just the shader)?:) How are you doing the passes for your depth/normal map? I'm having trouble working out how to arrange the quad rendering. Thanks in advance
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

That does look nice, maybe a comparison shot of the scene with/without SSAO is in order? I think the difference will be quite amusing :D
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
jingquan
Posts: 222
Joined: Sun Aug 20, 2006 4:10 am
Contact:

Post by jingquan »

Here's the exact original scene without SSAO: http://www.orandysoftware.com/user_files/decorg.jpg Download the images and compare it slide by slide. You'll find out some area would look more 3D.

Here's how I do it in C#:

1st. Render everything you want SSAO to affect using the depth shader to a RTT, else hide it

Code: Select all

                        WorldNode.SetMaterialType(depth.MaterialType);
                        tablenode.SetMaterialType(depth.MaterialType);
                        tablenode2.SetMaterialType(depth.MaterialType);
                        ......
                        plantnode1.Visible = false;
                        fernnode1.Visible = false;
                        fernnode2.Visible = false;
                        smoke.Visible = false;
                        driver.SetRenderTarget(lum.rtdepth, true, true, new Color(0, 0, 0, 0));
                        scene.DrawAll();
2nd. Grab the texture and load it on the onscreen quad, applying SSAO as well.

Code: Select all

            rtao = driver.CreateRenderTargetTexture(new Dimension2D(512, 512));
            rtdepth = driver.CreateRenderTargetTexture(new Dimension2D(512, 512));

            SSAO.Wireframe = false;
            SSAO.Lighting = false;
            SSAO.Texture1 = rtdepth;

            ushort[] indices = { 0, 1, 2, 3, 4, 5 };
            driver.SetRenderTarget(rtao, true, true, new Color(0, 0, 0, 0));
            driver.SetMaterial(SSAO);
            driver.SetTransform(TransformationState.World, AbsoluteTransformation);
            driver.DrawIndexedTriangleList(Vertices, 6, indices, 2);
I think that's all. There's a post processing framework lying somewhere in the forum too, you can have a look at it.
Post Reply