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, input.uv).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!
↧