I’ve got a problem with an SSAO shader I’m working on. For some reason, it doesn’t seem to do anything at all. I’m correctly getting the position and linear depth (see pics below), but unfortunately it’s not outputting anything… Whole screen is white. You can assume that I’ve debugged it to the point that it’s definitely the shader code, not something CPU side.

I store the depth and normals in one texture then linearize the depth in the SSAO shader. Here’s the main code:

```
void main() {
vec4 normDepth = texture2D(u_normalDepthTexture, v_texCoords);
vec3 position = CalcPos(normDepth.a);
//mat3 rotMat = CalcRotMat(normDepth.xyz);
float occlusion = 0.0;
for(int i = 0; i < u_sampleKernelSize; i++)
{
vec3 sample = u_sampleKernel[i];
sample = sample * u_radius + position;
vec4 offset = u_proj * vec4(sample, 1.0);
offset.xy /= offset.w;
offset.xy = offset.xy * 0.5 + 0.5;
vec4 sampleColor = texture2D(u_normalDepthTexture, offset.xy);
float sampleDepth = sampleColor.a;
float linearSampleDepth = (2.0 * u_projAB.x) / (u_cam.y + u_cam.x - sampleDepth * (u_cam.y - u_cam.x));
if(abs(position.z - linearSampleDepth) < u_radius)
{
occlusion += (linearSampleDepth <= sample.z) ? 1.0 : 0.0;
}
}
gl_FragColor = vec4(1.0 - (occlusion / float(u_sampleKernelSize)));
}
```

and CalcPos if necessary:

```
vec3 CalcPos(float depth)
{
float linearDepth = (2.0 * u_cam.x) / (u_cam.y + u_cam.x - depth * (u_cam.y - u_cam.x));
vec4 pos = u_invProj * vec4(v_texCoords * 2.0 - 1.0, linearDepth, 1.0);
return pos.xyz / pos.w;
}
```

I haven’t implemented noise or kernel orientation yet, I just want to get the basics working.

Reconstructed position:

http://puu.sh/gZtE2/5ee9cb5f1a.jpg

Depth (non linear):

http://puu.sh/gZtGC/d837394c30.png

I’d appreciate any help. Thanks