Jump to content
  • Advertisement

DX11 trying with ssao

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

Hi! I am trying to implement simple SSAO postprocess. The main source of my knowledge on this topic is that awesome tutorial.

But unfortunately something doesn't work... And after a few long hours I need some help. Here is my hlsl shader:

float3 randVec = _noise * 2.0f - 1.0f; // noise: vec: {[0;1], [0;1], 0} 
float3 tangent = normalize(randVec - normalVS * dot(randVec, normalVS)); 
float3 bitangent = cross(tangent, normalVS); 
float3x3 TBN = float3x3(tangent, bitangent, normalVS); 
float occlusion = 0.0; 
for (int i = 0; i < kernelSize; ++i) 
	float3 samplePos = samples[i].xyz; // samples: {[-1;1], [-1;1], [0;1]} 
	samplePos = mul(samplePos, TBN); 
	samplePos = positionVS.xyz + samplePos * ssaoRadius; 
	float4 offset = float4(samplePos, 1.0f); 
	offset = mul(offset, projectionMatrix); 
	offset.xy /= offset.w; 
	offset.y = -offset.y; 
	offset.xy = offset.xy * 0.5f + 0.5f; 
	float sampleDepth = tex_4.Sample(textureSampler, offset.xy).a; 
	sampleDepth = vsPosFromDepth(sampleDepth, offset.xy).z; 
	const float threshold = 0.025f; 
	float rangeCheck = abs(positionVS.z - sampleDepth) < ssaoRadius ? 1.0 : 0.0; 
	occlusion += (sampleDepth <= samplePos.z + threshold ? 1.0 : 0.0) * rangeCheck; 
occlusion = saturate(1 - (occlusion / kernelSize));

And current result: http://imgur.com/UX2X1fc

I will really appreciate for any advice!

Edited by gsc

Share this post

Link to post
Share on other sites

I don't see this very important bit of math to transform/scale your normals:

vec3 normal = normalVS.xyz * 2.0 - 1.0;
normal = normalize(normal);

I pulled this from the tutorial you referenced (although, if you arent using Normal Maps, you might not need this)

Edited by missionctrl
changed code to match OPs code

Share this post

Link to post
Share on other sites

@missionctrl yes, I have that part of math, I am using a buffer with normals in view space (look at the attachment)

@KarimIO hmmm... if the shader hasn't any mistakes, then my data from buffers should be wrong...

Generally, I have normal buffer ( and depth buffer to reconstruct VS of geometry, but for test purpose I created special position buffers to eliminate possibility of mistakes in calculations from the depth buffer.

All buffers and results here: http://imgur.com/a/nm0bA

I have no idea, why version with positions read directly from the buffer is so noisy and the second one hasn't virtually any noise.

Edited by gsc

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!