Transparency and the depth buffer

Hi all!

My program involves drawing textures with transparency - for the branches of a tree, for example, I have a texture of the tree with the gaps between the branches made clear by setting the texture’s alpha channel to 0 there.

The problem is that opengl updates the depth buffer even where the texture is clear - so objects that are drawn afterwards and behind the tree are not visible in the gaps between the branches.

This also affects the drawing of clouds, etc… and it would be too expensive in frame rate to fix it with more geometry.

I’ve tried to use glAlphaFunc(GL_GREATER,0.05); to stop drawing of pixels with high transparency, but the depth buffer is still updated there…

I know I can solve this by depth sorting the objects I draw, but I’d like to avoid that if possible - it’d (again) be too much of a speed loss to depth sort 3000 trees…

Thanks in advance,

Nick

Are you sure that the Alpha Test is enabled?
// glEnable( GL_ALPHA_TEST );
Also try different alpha reference values.
I think, glAlphaFunc( GL_GREATER, 0.25…0.75 ) may be better.

And you can disable blending - you don’t need it.

Depthsorting of 3000 trees is possible in realtime. There’s a qsort() function that can do this for you, I used it back in my Glide days to do depthsorting and it worked great. Since the sort time with qsort is proportional to log2(n) it wont be much slower to double the number of trees either.

Humus is right.

Besides, there is no other way for you to achieve what you want… You need to apply the painter algorithm (further->nearer) when you want to play with transparency ! (Yeah, it’s boring, I know !).

Regards.

Eric

Thanks everyone! It turns out I hadn’t done glEnable(GL_ALPHA_TEST) (one of those “doh!” moments )

I think it works ok without the depth sorting as I’m just doing simple clear areas and opaque areas with no blending required… maybe I’ll need qsort() for the clouds though

Nick

[This message has been edited by nickL (edited 06-01-2000).]

If only we had a full ICD for the PowerVR cards. They do depth sorting in hardware… Can we wait for the Kryo?

Paul