0

I'm trying to perform the depth peeling algorithm, to draw in correct order transparent objects in a scene already full of opaque objects (A terrain that almost occludes the transparent objects most of the time).

I have already separated the draw calls for opaque/transparent objects, drawing the opaque ones first. The problem lies in that each one of the "transparent objects drawing passes" the algorithm needs will actually use it's own (empty) z-buffer, but I need to check if a opaque object is occluding the view before drawing, and hence I need to reuse the z-buffer obtained after drawing the opaque objects multiple times, and not a empty one each.

Im aware i could dump the z-buffer state after drawing the opaque objects to a texture, and performing the depth comparisons from it in the fragment shader, but im afraid that performing the depth comparisons in the fragment shader would be extremelly slow. There is another faster way to solve that problem?

Edit: My target is a 3.X OpenGL version, so using the A-buffer is not an option in this particular case.

Ivelate
  • 298
  • 2
  • 10
  • 3
    *but im afraid that performing the depth comparisons in the fragment shader would be extremelly slow* Have you profiled it? Otherwise, do not worry too much. Comparing against a depht in a fragment shader is exactly what you're supposed to do in many other scenarios, for instance shadow mapping, up to the point that this is exposed directly by the OpenGL API through the usage of `sampler2Dshadow` and `GL_TEXTURE_COMPARE_MODE` set to `GL_COMPARE_REF_TO_TEXTURE`... – peppe Feb 17 '16 at 22:57
  • Oh, i was supposing that standard depth comparisons against the depth buffer would be much faster than "letting pass" the pixels to the fragment shader, and discarding them there using discard; . Considering that in my case terrain occludes most of the time the transparent objects, it worried me to "waste" processing time in that. However, if its not that a big deal, i will do it that way. Im going to profile it anyways, just in case. Thanks! – Ivelate Feb 17 '16 at 23:08

0 Answers0