Depth buffer rendered over objects


I’m having a bit of a problem with the depth buffer. When I’m using blending, it seems that the depth buffer gets mixed together with the blended image. As soon as I call glDisable(GL_DEPTH_TEST), the entire contents of the depth buffer get written over the render target. If I keep the depth buffer on but disable blending, everything is fine. Here’s what I mean:

Here’s the render code:



// render the particles
glDrawArraysInstanced(GL_TRIANGLES, 0, model_.getVertCount(), NUM_OF_PARTICLES);


No clue as to what’s going on. Any help would be appreciated!

Thanks in advance!

EDIT: Just before I went to bed I got an idea and it worked: enabling back face culling removed the issue. I was trying to find a way to delete the topic as to not clutter the forums but I couldn’t find a button for it. Anyway, if anyone experiences similar artifacts then here’s your solution! ^^

The problem you were seeing is caused by your blending function being order dependent (i.e. you only get the correct blending result if you render from back to front). Perhaps you are already sorting your spheres by distance from the camera (if not you should, otherwise the issue will come back), but that will not ensure that the triangles that make up each sphere are also rendered from back to front. Enabling back face culling solves the problem because then the problematic triangles are simply dropped - for more complicated (esp. non-convex) geometry backface culling is not enough to get a correct result (although possible a good-enough one :wink: ).