PDA

View Full Version : transparency and the z-buffer



Jan
06-15-2001, 04:43 AM
Hi

I have some textures and I want them to be completely transparent at some positions (i.e. for sprites). Now transparency works but I have a little problem. I donīt sort the polys up to now and when I draw a partly transparent polygon and after this I draw a second one, which lies behind the first one it doesnīt shine through. I think this happens because when I draw the first one it updates the z-buffer even at positions, where nothing is drawn.
Now: Is there any way to prevent OpenGL from updating the z-buffer where a pixel is completely transparent? Or do I have to sort the polygons from back to front?

Thanks.

hoshi55
06-15-2001, 05:03 AM
you have to sort them to achieve the effect you want.

however, there is a workaround that works for some types of problem:
if your semitransparent objects are bitmap objects (billboarding) like trees or explosions etc. make sure they are drawn towards the end of your gfx pipeline and place the following:

glDepthMask(GL_FALSE);
// draw your transparent objx here!!
glDepthMask(GL_TRUE);

basically, this switches the z-buffer to READ-only. it works for me, but it depends on your type of problem if this suits you

j
06-15-2001, 05:14 AM
You can also do this:

glAlphaFunc(GL_LESS, 0.5);
glEnable(GL_ALPHA_TEST);

Then all fragments with alpha of less than 0.5 are culled before they make it into the depth buffer.

j

Tim Stirling
06-15-2001, 08:50 AM
Originally posted by j:
You can also do this:

glAlphaFunc(GL_LESS, 0.5);
glEnable(GL_ALPHA_TEST);

Then all fragments with alpha of less than 0.5 are culled before they make it into the depth buffer.

j

That is good for trees because you don't actualy want it to be transparent.