SSAO banding [SOLVED]

Started by
9 comments, last by manxankur 14 years, 6 months ago
Hi all, Another soul has entered the fun that is SSAO. I've been working on it for the past two days and i've finally got something worth showing. It's not 100% to my satisfaction though, hopefully someone can spot something i'm doing wrong. I've already checked out what all the other forums and other on line articles on SSAO. I tried fixing the banding issues with the texture with the random normals but that didn't really help. Another thing is that only one side of the scene has the ao but the opposite side doesn't, something is definitely wrong there. Here are some screenshots, Hopefully you'll be able to see the banding and the none ao side issues: Free Image Hosting at www.ImageShack.us Here is the shader:

#define NUM_SAMPLE_POINTS	32

float3 GetScrnPosFrmTexCoord( float2 UV, float Depth )
{
	//compute screen-space position
	float4 position;
	position.x = UV.x * 2.0f - 1.0f;
	position.y = UV.y * 2.0f - 1.0f;
	position.z = Depth;

	return position.xyz;
}

float3 GetTexCoordFrmScrnPos( float3 ScrnPos )
{
	return 0.5f * (ScrnPos + 1.0f);
}

float ReadDepth( float2 coord )
{
	float2 camerarange = float2(1.0f, 1000.0f);
	return (2.0 * camerarange.x) / (camerarange.y + camerarange.x - tex2D( DepthSampler, coord ).x * (camerarange.y - camerarange.x));	
}

VertexToPixel SSAOVertexShader( AppToVertex Input )
{
	VertexToPixel output = (VertexToPixel)0;

    output.Position = Input.Position;
    output.TexCoord = Input.TexCoord.xy + g_halfPixel;
    
    return output;
}

float4 SSAOPixelShader( VertexToPixel Input ) : COLOR0
{
	float depth = ReadDepth( Input.TexCoord );
	float3 scrn_pos = GetScrnPosFrmTexCoord( Input.TexCoord, depth );
	float3 normal = 2.0f * tex2D( RNSampler, Input.TexCoord ) - 1.0f;
	
	float4 rtn_val = 0;
	
	for( int i = 0; i < NUM_SAMPLE_POINTS; ++i )
	{
		float3 rflc_ray = reflect( 2.0f * sampleOffsets - 1.0f, normal );
		float3 new_pos = scrn_pos + (rflc_ray * 0.03f);
		
		float2 new_uv = GetTexCoordFrmScrnPos( new_pos );
		
		float new_depth = ReadDepth( new_uv + g_halfPixel );
		
		float3 new_scrn_pos = GetScrnPosFrmTexCoord( new_uv, new_depth );

		float zd = 500.0f * max( depth - new_depth ,0 );
		rtn_val += 1.0f / ( 1.0f + zd * zd  );
	}
	
	rtn_val /= NUM_SAMPLE_POINTS;
	rtn_val.a = 1.0f;
	return rtn_val;
}



Any idea what could be going wrong? [Edited by - manxankur on October 17, 2009 2:52:27 PM]
--General blog: http://turnbasedstupidity.blogspot.com/Game Dev blog: http://indieing-in-india.blogspot.com/
Advertisement
Hi there,

I don't know much about SSAO but your pictures look like heavy edge-bleeding. This may be caused by your blur radius is too large.
Hi,

I removed my blur pass but i'm still getting the same problem. Thanks for the suggestion.
--General blog: http://turnbasedstupidity.blogspot.com/Game Dev blog: http://indieing-in-india.blogspot.com/
Sorry for the offtopic, but this looks exactly as a tutorial for XNA in spanish (if i remember well) [smile]
Quote:Original post by solenoidz
Sorry for the offtopic, but this looks exactly as a tutorial for XNA in spanish (if i remember well) [smile]


Heh, you mean the source code? I have tried other people's source code and this is my version, it is giving me the best result atm :( It's because of my depth buffer, i do the old z/w trick and not the Crytek way of z/far.
--General blog: http://turnbasedstupidity.blogspot.com/Game Dev blog: http://indieing-in-india.blogspot.com/
Well, I don't remember the exact source sode from the sample to compare with yours. It's just the 3D model and the effect applied to it that looked familiar to me.
Hi,

This is the Spanish website that he's talking about:

http://www.codeplex.com/XNACommunity/Wiki/View.aspx?title=SSAO&referringTitle=Home

You can download the source code and take a look at it.

Ok, so I think I was confused your project with the one from the link above. In that project, if you increase the sample radius too much then the object starts experiencing "edge-bleeding". However, your problem seems to be similar to this one:

http://www.gamedev.net/community/forums/topic.asp?topic_id=529162&whichpage=1�

Look at his pics in 3rd post or something like that. Then, Viik explains the mistake at the very end. Maybe it can help you pin point the problem.
Hi b_thangvn,

The screenshot and videos on this website:

http://www.codeplex.com/XNACommunity/Wiki/View.aspx?title=SSAO&referringTitle=Home

show the exact same problem that i'm having. There are dark bands around the pillers. This doesn't look like the SSAO done by Crytek or the big screenshot by Viik in this post:

http://www.gamedev.net/community/forums/topic.asp?topic_id=529162&whichpage=1�

There are no dark bands around the female statue in the middle of the scene. How do i get this sort of result?

--General blog: http://turnbasedstupidity.blogspot.com/Game Dev blog: http://indieing-in-india.blogspot.com/
Quote:Original post by b_thangvn
Hi,

This is the Spanish website that he's talking about:

http://www.codeplex.com/XNACommunity/Wiki/View.aspx?title=SSAO&referringTitle=Home

You can download the source code and take a look at it.

Ok, so I think I was confused your project with the one from the link above. In that project, if you increase the sample radius too much then the object starts experiencing "edge-bleeding". However, your problem seems to be similar to this one:

http://www.gamedev.net/community/forums/topic.asp?topic_id=529162&whichpage=1�

Look at his pics in 3rd post or something like that. Then, Viik explains the mistake at the very end. Maybe it can help you pin point the problem.


This is interesting.

The final result is clearly wrong, as you can see in the video... where should allo those shadows come from ? For the most part, the shadows are just fake, bordering the edges. As far as I'm concerned, there is any physical reason.

BUT the result is anyway pleasing (just take a look when the SSAO level is increased) !!

Although I've not implemented it yet (it will come soon), I've seen many videos about it... and most of them had a physically wrong effect.

I guess that SSAO works because human eyes like light intensity changing. So it doesn't matter if SSAO is perfect or just an approximation: as far as it changes the shadowing of the scene, it's fine.

As a profane, just my opinion ;)
Hi,

Like I said, the Spanish code has that problem because his sample radius is too large. Look at his screenshot that says radius : 7. If you set the radius to be around 1 then there is no problem.

Uhm, I look a little bit at your code and I don't see why you have that problem. But again, I have to look at the Spanish guy code to compare to yours. Maybe that's something you can do: download his code, play around with it, then figure out why increasing the radius causes the edge-bleeding.

Viik's SSAO is different. He used semi-random texture, and there are more optimization for his SSAO as well. Oh, you can also check out SSAO of the free D3D10 book we have here on GDev:

http://wiki.gamedev.net/index.php/D3DBook:Book_Cover

I'm sorry that I can't be more helpful. I'm not working on SSAO right now but I love to get back to it soon. Good luck !

This topic is closed to new replies.

Advertisement