Jump to content
  • Advertisement
Sign in to follow this  

SSAO in HLSL (solved)

This topic is 3658 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

EDIT: If anyone has similar problems.. The white lines were caused by using point filtering on the depth buffer but when switched to linear filtering fixed the problem. I also used a varying radius and pushed my test samples out with the normal. This helped remove some artifacts. Still not perfect and has halo problem in some cases. [image removed] ---- Original Post ----- Hi, Sorry for another SSAO post but after going through the others I still havent solved my problem and I can't afford to rip out any more of my hair. I am trying to do SSAO with a deferred shader and I have quite a few problems with it. I am not sure if some of these are problems with unprojecting but I have tried 2 ways of calculating the view direction. I have been following a lot of threads and in particular these 2: SSAO SSAO woes (I had similar problems when trying this tutorial but didn't find a solution) The problems: 1) My first problem is that it looks more like a weird lighting shader and seems to give some mimic of reflection as a rotate around the object. 2) My second problem is the weird white lines that I get down the screen. EDIT: I have tried using PIX and although i am fairly new to it I cant see any problems. I am using the debug run times and I have tried the reference rasterizer and it still produces the same results. :-( here is some of the code (some bits taken from Inigo Quilez page) :

float TestAO(float3 vOrigin, float3 vOffset, float cmpDist)
	float4 vPos = float4(vOrigin + vOffset, 1);
	vPos = mul(vPos, m_projection);
	vPos.y = -vPos.y;

	float2 ScreenPos = (0.5 * vPos.xy / vPos.w) + float2( 0.5, 0.5 );	

	float tDepth = tex2D(gb_depth, ScreenPos).r * f_zMax;

        float zd = 50.0*max( length(vOrigin+vOffset)-tDepth, 0.0 );
        // also tried this:
        // float zd = 50.0*max( cmpDist - tDepth, 0.0 );
        return (1.0/(1.0+zd*zd));              // occlusion = 1/( 1 + 2500*max{dist,0)^2 )

The relevant part of the pixel shader:
	 // testOffset[16] is a an array of random vectors (varying lengths less than 1).
	 // rad is the sphere radius to test around
         // oDepth is the current test depth from the depth texture.

	float rad = 0.5f;
	float AO=0.0f;
	for (int t=0;t<16;t++)
		AO += TestAO(viewPos, testOffset[t] * rad , oDepth);

	AO = AO / 16.0f;
	Output.col = float4(AO, AO, AO,0);

I am also not sure what size radius I should be using. I have tried a few different values which all look different (and wrong at the same time) so not sure what is correct. I am doing all calculations in view space and have tried values of 10.0 to 0.01. [image removed] I am not sure if I am unprojecting correctly but I have tried it two ways and they both came out with the same results. I tried calculating the view directions to each vertex of the full screen plane and then normalizing the interpolated result in the pixel shader. I have also tried calculating the vertex position for each vertex in the vertex shader (as a float4) and then interpolating that and dividing by w to get the unprojected position. Any help or suggestions would be much appreciated and if I have been too vague or you need more details then I can post more up. Thanks a lot. EDIT(2 or 3 is it now): changed the picture. No point really in updating all the code on this post as it died before it started but if anyone has similar problems and wants more details then feel free to message me. EDIT(n): Removed broken links [Edited by - jrmcv on June 29, 2008 4:32:04 PM]

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!