Jump to content
  • Advertisement
Sign in to follow this  

not all polygons are transparent

This topic is 3959 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello, I'm loading a model which uses a .tga file for transparency of tree leafs. It works except a lot of the leaves do not show the leaf behind. All the leaves show the background image OK it's just that the some leaves show the background image but not the leaves behind, so they appear to have a background image imposed on the quad. This is very difficult to explain verbally :s, but hope someone gets what I mean. I'm using 3ds/ase models, do I need to do something with the order of objects before I save the file? EG is leaf z position important and if so how do I get the model in the correct order? Thanks should say I load the models as a displaylist of objects and use the blend command for transparency eg


		/************set transparency******************/
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);			/*Enable Alpha Blending*/




Share this post

Link to post
Share on other sites
It sounds to me like a depth-buffer-related problem. Transparency and depth buffers don't mix well. Some of the leaves in front are being drawn before some of the leaves behind. This causes nearer values in the depth buffer, which prevent the leaves behind from appearing. The background image and some of the leaves in the back are visible because they just happen to be rendered before the leaves in front of them.

To fix this, you could:

(a) draw the scene in two passes. First draw everything that's opaque, then draw everything that has transparency. This generally works only in scenes where you never have a transparent object in front of another transparent object.

(b) sort the scene so that objects are drawn from most-distant to nearest (this is known as the painter's algorithm). You can combine this with (a) so that you need to sort only transparent objects. If objects overlap, or it isn't feasible to sort them, then this method could be difficult or error-prone. In some cases (particle systems, for example) this method is easy and reliable. Bit of a case-by-case thing, really.

(c) you could switch off alpha blending and use alpha testing instead. You would lose partial transparency and some antialiasing effects, but this gets rid of the problem in a very fast, simple manner. You can switch back to blending for the rest of the scene if you like.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!