I am trying to implement Normal-Oriented SSAO and i'm having an issue with the results. Portions of the screen are inverted/wrong, typically half way through the screen but not always, it seems tied to the camera, but can also be anything lol. Here is the resulting render:
And here is the SSAO Shader:
void main()
{
vec3 WorldPosition = texture(GPositionsTexture, In_TexCoords).xyz;
vec3 WorldNormal = normalize(UnScaleNormal( texture( GNormalsTexture, In_TexCoords ).xyz ));
vec3 Random = texture(KernalNoiseTexture, In_TexCoords * KernelNoiseScale).xyz;
vec3 Tangent = normalize(Random - WorldNormal * dot(Random, WorldNormal));
vec3 BiTangent = cross(WorldNormal, Tangent);
mat3 TBN = mat3(Tangent, BiTangent, WorldNormal);
float Occlusion = 0.0;
for (int i = 0; i < KERNEL_SIZE; ++i)
{
// get sample position:
vec3 Sample = inverse(TBN) * Kernel[i];
Sample = Sample * Radius + WorldPosition;
// project sample position:
vec4 Offset = vec4(Sample, 1.0);
Offset = CamData.Projection * CamData.View * Offset;
Offset.xy /= Offset.w;
Offset.xy = Offset.xy * 0.5 + 0.5;
// get sample depth:
float SampleDepth = texture(GPositionsTexture, Offset.xy).z;
// range check & accumulate:
float RangeCheck= abs(WorldPosition.z - SampleDepth) < Radius ? 1.0 : 0.0;
Occlusion += (SampleDepth <= Sample.z ? 1.0 : 0.0) * RangeCheck;
}
Occlusion = 1 - (Occlusion / KERNEL_SIZE);
Out_Diffuse = pow(Occlusion, Power);
}
vec3 Sample = TBN * Kernel[i];
is going from world to tangent, but it needs to go from tangent to world. that's just by looking at my code. I'll try the inverse when i have time and report back. \$\endgroup\$ – Richmar1 Dec 31 '19 at 8:12vec3 Sample = inverse(TBN) * Kernel[i];
going to modify the code in post \$\endgroup\$ – Richmar1 Jan 1 '20 at 0:54float SampleDepth = texture(GPositionsTexture, Offset.xy).z;
is what's causing the black issue. Offset.xy is going way out of bounds of (0,1) it's trying to access outside of the screen. Not sure why, but it may be my kernel math with TBN \$\endgroup\$ – Richmar1 Jan 2 '20 at 7:58