Transparency for cut-outs without ordering?

I’d like to use texture transparency for cut-outs, but not have to order my geometry from back to front.

So I want to tell OpenGL to only update the Z-buffer only when that pixel is not transparent. Is there a way to do that?

I know ordering would still be required for partial transparency (including feathering around the edge of a cut-out), but if my textures are either completely transparent or completely opaque at each pixel then there really shouldn’t be any need for sorting.

Is this simple task really not possible in OpenGL?


It sounds like you want to use the alpha test. Try this:

glAlphaFunc(GL_LESS, 0.5F);

Make sure that your texture’s alpha gets output into the final color, and then any fragments with an alpha less than 0.5 will get rejected. You don’t want blending with this, so either disable it or use

glBlendFunc(GL_ONE, GL_ZERO);

– Eric Lengyel

Originally posted by Eric Lengyel:
glAlphaFunc(GL_LESS, 0.5F);
Ah, thanks! I knew there must be a way. That should be GL_GREATER though. Otherwise we are keeping the transparent stuff and throwing away the opaque stuff :slight_smile:

You can still combine this with blending too. Using a value like 0.05f means only pixels that are almost completely transparent will be thrown away, but the rest will blend as normal. (Most of my geometry will be sorted, but some is harder to deal with. This should fix it when such items are just sharp cut-outs).

Thanks again,

You’re right – it should be GL_GREATER. I was recently working with some textures that had the alpha inverted, so I needed GL_LESS.

pop goes the NDA