Ok. So Finally, I have solved the problem. This problem I been working on for a couple of weeks. Had to go through several books in math, gamedev etc. Went through all my code, to see if I had something I did missunderstand.
Finally I found the problem! I was trying to store normals in the texture, with values between [-1, 1], I did not think about the ...
You're not correctly inverting the mapping you used to store the depth value. When storing it you use:
vDepth = -(vPos.z - NearPlane) / ( FarPlane - NearPlane);
Then you reconstruct it as:
const float depth = normalDepth.w * (FarPlane - NearPlane);
but this misses both the offset by NearPlane, and the negative sign to flip the Z axis (since it points out ...
One way to do it: first find the maximum x using atomics on a shared variable. Then, have each thread compare its local version of x to the found maximum, and store to y only if they are equal.
shared uint x, y;
uint localX, localY;
// each thread computes its localX and localY
barrier(); // ensure all threads have done the ...