Trouble getting SSAO working with HLSL

Started by
3 comments, last by gchewood 11 years, 1 month ago

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!

Advertisement

What is the format of the render target to which you're writing the depth map?

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?

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.

Yep, that sorted it thanks. Silly mistake, just reading through the documentation on surface formats made that quite obvious!

This topic is closed to new replies.

Advertisement