PDA

View Full Version : Transparency for cut-outs without ordering?



RobertWebb
02-14-2005, 09:43 PM
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?

Thanks,
Rob.

Eric Lengyel
02-14-2005, 09:49 PM
It sounds like you want to use the alpha test. Try this:

glEnable(GL_ALPHA_TEST);
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

RobertWebb
02-15-2005, 09:24 PM
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 :-)

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,
Rob.

Eric Lengyel
02-15-2005, 10:12 PM
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.

knackered
02-16-2005, 01:30 AM
pop goes the NDA