Jump to content

  • Log In with Google      Sign In   
  • Create Account

Trouble getting SSAO working with HLSL


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 gchewood   Members   -  Reputation: 236

Like
0Likes
Like

Posted 27 March 2013 - 06:02 PM

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!

 

Attached Thumbnails

  • ssao.jpg


Sponsor:

#2 phil_t   Crossbones+   -  Reputation: 4109

Like
0Likes
Like

Posted 27 March 2013 - 06:12 PM

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



#3 gchewood   Members   -  Reputation: 236

Like
0Likes
Like

Posted 27 March 2013 - 06:20 PM

 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?



#4 phil_t   Crossbones+   -  Reputation: 4109

Like
0Likes
Like

Posted 27 March 2013 - 06:30 PM

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, 27 March 2013 - 06:30 PM.


#5 gchewood   Members   -  Reputation: 236

Like
0Likes
Like

Posted 27 March 2013 - 06:46 PM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS