Jump to content
  • Advertisement
Sign in to follow this  
gchewood

Trouble getting SSAO working with HLSL

This topic is 1942 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement

 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

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!