Duck! tragedy
The saga continues! At an alarmingly slow pace.
Alpha transparency and the Z-buffer are not friends, nor are they bum chums, so I suppose I’ll just have to render tiles in the correct order manually. I feel compelled to blame communism for this.

P.S. Duck does have feet now, it’s just the Z-buffer deciding they shouldn’t be drawn. Who died and made Z-buffer king, eh?
Nicholas Howes

7 comments by 3 or more people
[Skip to the latest comment]Nick Forrington
If you use one of the overloads on SpriteBatch.draw you can specify a depth for each sprite which might help you out. I think you have to pass SpriteSortOptions.BackToFront to SpriteBatch.Begin to enable that.
I didn’t think you could get problems like that with the Z-buffer and full transparency (as fully transparent pixels shouldn’t write to the Z-buffer?)
Quack!
19 Sep 2006, 02:04
Nick Howes
I’m using polygons and an orthagonal projection rather than 2D sprites. It wouldn’t work if fully transparent pixels didn’t write to the Z-buffer, as then sprites with smooth edges would have a weird jaggedy transparent edge. Wouldn’t be a problem in your game if you’re only doing 1-bit transparency. If you think about it I don’t think the Z-buffer can handle variable alpha like this; what values could it write in the part-transparent parts of the depth map that would make sense? I think the solution generally is to draw all opaque polygons with full Z-buffer, then draw all transparent polygons in back-to-front order with the Z-buffer read-only (probably the one thing I remember from the Graphics module in my 3rd year).
19 Sep 2006, 09:42
Matthew Jones
I concur with the remembering-from-graphics-ness. In fact I think I answered that question on the exam.
19 Sep 2006, 09:52
Nick Forrington
Z-buffers don’t handle variable alpha, but a fully transparent pixel shouldn’t write to the Z-buffer as technically that pixel has not been drawn. Perhaps XNA doesn’t do that by default.
Not sure what you mean by 1-bit transparency, I’m using an 8-bit alpha channel but all my pixels are fully opaque or fully transparent (so far at least). But yeah, for variable transparency I think you just have to draw from back to front.
This post is getting dangerously geeky :-)
19 Sep 2006, 11:46
Nick Howes
That’s what I meant, you having no half-transparent pixels. There would be no correct behaviour for writing to a z-buffer for this pixel.
I don’t think it’s actually a big problem, I just need to draw the tiles left-to-right and bottom-to-top, rather than top-to-bottom as I’m doing now.
19 Sep 2006, 11:59
Nick Forrington
Ahh, from the screen shot it looked like it was mis-drawing pixels that should be fully transparent.
Yeah drawing bottom to top was what I thought when I saw it.
What is it with you and pseudo-3D? :-)
19 Sep 2006, 12:06
Nick Howes
I larve it.
19 Sep 2006, 12:08
Add a comment