2

I am trying to implement this SAO algorithm.

I am getting the following result :

result

I can't figure out why I have the nose on top of the walls, it seems to be a z-buffer issue.

Here are my input values :

const float projScale = 100.0;
const float radius = 0.9;
const float bias = 0.0005;
const float intensityDivR6 = pow(radius, 6);

I am using the original shader without modifications, except that I disable the usage of mipmaps of the depth buffer.

My depth buffer (on different scene, sorry) :

depth

genpfault
  • 51,148
  • 11
  • 85
  • 139
Xavier Bigand
  • 317
  • 3
  • 10

3 Answers3

2

It should be an issue with the zbuffer linearization or it's not between -1 and 1.

Bruno Deligny
  • 36
  • 1
  • 2
1

Thank you Bruno, I finally figure out what were the issues. The first was that I didn't transform my Z correctly, they use a specific pre-pass to make the Z linear and put it between -1 and 1. I was using an incompatible method to do it.

I also had to negate my near and far planes values directly in the projection matrix to compute correctly some uniforms.

Result : result

Xavier Bigand
  • 317
  • 3
  • 10
  • Can you post the solution please? I am implementing the same algorithm, and I may face some of the problems you encountered. I did not negate my near/far planes but it seems to work without doing it. However, whenever my camera is close to an object, I obtaine a wrong self-occlusion (http://i.imgur.com/OWriRrK.png). I am not sure about this but it could be linked to the problem you had. – David Peicho Dec 21 '16 at 16:24
  • You should negate the near and far plane to avoid accumulation of errors that in some situations might seems getting a correct result. I took some times to understand my issues because of that. You have AO on the front corner of your plane because it is not infinite, except that I am not sure that your result is wrong. Have you some other pictures? – Xavier Bigand Dec 21 '16 at 19:23
  • Yes sure, I have some others on the Sponza scene. The scene fits in a bounding sphere with a 23 units radius. The result is quite good : http://i.imgur.com/lXFuOXP.png (you can see the scene settings on the top right). But whenever I increase a bit the radius, I can see the same effect appearing, when I put the camera close, I get self occlusion: http://i.imgur.com/TqRaoy0.png There is something I forgot to mention, my near/far are automatically updated to fit according to what the camera actually see from the sceen. – David Peicho Dec 22 '16 at 09:51
  • Thanks, I succeed to fix it! I posted my solution as an answer in case someone else has the same issue. – David Peicho Dec 22 '16 at 14:58
0

I had a similar problem, having visual wrong occlusion, linked to the near/far, so I decided to give you what I've done to fix it.

The problem I had is discribed in a previous comment. I was getting self occlusion, when the camera was close to an object or when the radius was really too big.

If you take a closer look at the conversion from depth buffer value to camera-space value (the reconstructCSZ function from the g3d engine), you will see that replacing the depth by 0 will give you the near plane if you work with positive near/far. So, what it means is that every time you will get a tap outside the model, you will get a z component equals to near, which will give you wrong occlusion for fragments having a z close to 0. You basically have to discard each taps that are located on the near plane, to avoid them being taken into account when comptuing the full contribution.

David Peicho
  • 453
  • 4
  • 16