Sign in to follow this  
gchewood

Trouble getting SSAO working with HLSL

Recommended Posts

I'm trying to get SSAO working in xna 4. The simplest implementation I've found is given in this article: http://www.theorangeduck.com/page/pure-depth-ssao

as it works purely from a depthmap. (the hlsl code I'm using is identical to that in the article)

I'm getting this kind of banding (see attachment).

Based on the directions of the bands, I assume the problem is with my depth map?

Here's the shader I'm using to render it:

 

float MaxDepth=200;

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;
	
	output.Position=mul(input.Position,WorldViewProjectionMatrix);
        output.Depth=output.Position.z;
    return output;
}


float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
	return float4(input.Depth/MaxDepth,input.Depth/MaxDepth,input.Depth/MaxDepth,1);
}

Can anyone help?

 

Thanks in advance!

 

Share this post


Link to post
Share on other sites

 depthCapture = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);

 

I'm guessing that's my mistake? Should it be Single instead of Color?

Share this post


Link to post
Share on other sites

Yeah, that should do it. You only need a single channel, and you need it to be, at the very minimum, 16 bits. Single is 32bit floating point, so that should be good. Right now you're just using 8 bits.

 

Note that floating point render targets require point sampling when you sample from them, but that shouldn't be an issue in your case.

Edited by phil_t

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this