2

I turned OFF the depth buffer reading and writting. I'm rendering something on top of a previous render. Is there a way to query the current depth buffer (from the previous render) and test it against the current fragment being drawn ?

My goal is to change the color when something is behind a geometry. gl_FragDepth, and gl_FragCoord.z seems to give me the current fragment depth being rendered, but not the value of the depth buffer at this fragment location.

Is there a way to achieve this ?

  • 3
    [OpenGL - How to access depth buffer values? - Or: gl_FragCoord.z vs. Rendering depth to texture](https://stackoverflow.com/questions/23362076/opengl-how-to-access-depth-buffer-values-or-gl-fragcoord-z-vs-rendering-d) – Rabbid76 Aug 17 '20 at 17:12
  • mmmh ok, I think I will do it in 2 passes so. – Sébastien Bémelmans Aug 17 '20 at 17:17
  • 1
    What are you trying to achieve? If the depth test is enabled, the framebuffer is only written under a certain condition. Yon can render "on top" in 2 passes with 2 different [Depth Test](https://www.khronos.org/opengl/wiki/Depth_Test) conditions e.g. `GL_LESS`/`GL_GEQUAL`. – Rabbid76 Aug 17 '20 at 17:19
  • yes, that's the idea. I don't want to disturb the main rendering by adding a RBO for the depth buffer. This is just visualisations things for debug. So I will do a render in z pass, and a render in z fails over the previous render. – Sébastien Bémelmans Aug 17 '20 at 17:21

0 Answers0