alpha blending AND z-buffer

Started by
1 comment, last by alnite 20 years, 6 months ago
I have read from somewhere that you can't use z-buffer if you want to use alpha blending. They don't work together. This is also pointed out at "Focus on 2D in Direct3D." However, I made a small app with alpha blending and z-buffer enabled and it works!? The test was done using two quads. One of them has 50% transparency and the other is 100% opaque. Without z-buffering, the quads would be drawn based on the order the DrawPrimitive calls. I first drew the transparent quad then the opaque quad. The result was as expected: the transparent quad was drawn behind the opaque. Then, I enabled z-buffering. I put the transparent quad above the opaque using z-buffer (transparent quad has lower z); but I still didn't change the order of the DrawPrimitive calls (so, transparent quad's DrawPrimitve was called first). The result? The transparent quad was drawn over the opaque quad! Check screenshots: Both shots above are taken with z-buffer enabled. The first one, I set z-buffer of the transparent quad lower than the opaque quad so the transparent quad was drawn over the opaque quad. The second one, I set z-buffer of the transparent quad higher than the opaque quad, the transparent quad was drawn behind the opaque quad. So my question is, why do people say that you can't use z-buffer with alpha blending enabled together? The small program I just made shows that you can use z-buffer and alpha blending together. [edited by - alnite on October 14, 2003 2:28:03 AM]
Advertisement
never mind. I just got some small artifacts when drawing more than two objects with a variety of transparency and z-buffer.

[edited by - alnite on October 14, 2003 4:33:27 AM]
Sure you can; but you need to draw your triangles back-to-front, and intersecting transparent triangles will be drawn incorrectly.
Also, you can control what pixels are drawn to the zbuffer using alphatesting.

This topic is closed to new replies.

Advertisement