In blending, we draw opaque objects first with z-write and test enabled. Then we disable z-write with test enabled for drawing translucent objects. While drawing translucent objects we are drawing them back to front order so why do we need to disable writing into z-buffer?
2 Answers
Because if you don't, they can obstruct other translucent objects that will be drawn later to the scene, or even parts of the same object. The fact you draw them back to front doesn't mean that the obstruction cannot take place.
If you were to draw an object which has some inner structure, it wouldn't be rendered if the outside surface was rendered first. Similar thing can happen to a concave object. Moreover the back to front ordering is not always easy to construct, especially if you have intersecting or intertwined objects in your scene

- 32,158
- 14
- 82
- 96

- 494
- 1
- 3
- 14
-
@Pavel Beliy: I added your comment in your answer. – Peter O. Apr 18 '15 at 16:15
If you render strictly back to front, there is no need to disable depth write. I can think of a couple of reasons why you may want to disable it anyway:
The sorting is not really perfect. While you get the wrong rendering result either way, it intuitively makes sense that blending in the wrong order would cause less noticeable artifacts than having geometry eliminated entirely. So disabling the depth write would most likely reduce the error from imperfect sorting. Sorting perfectly is non-trivial in the general case, and can even require splitting of polygons. See my answer here for more details about the difficulties: Some questions about OpenGL transparency.
Avoiding the depth write could improve efficiency. I sort of doubt that this will be very significant. But generally, it's always a good idea to avoid doing unnecessary work. And since writing the depth is definitely not needed in this case, you might as well skip it.

- 1
- 1

- 53,228
- 8
- 93
- 133