Jump to content
  • Advertisement
Sign in to follow this  
iSina

Transparency and DepthBuffer

This topic is 3739 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

I would like to give transparency to some objects. I do that using glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Say A is behind B and B is transparent but if A is rendered before B then this blending method does not work due to depth buffer. But when I enable depth buffer, the rendered model gets weird. So how do I achieve correct transparency with our without disabling depth buffer? Thanks

Share this post


Link to post
Share on other sites
Advertisement
The answer to this problem is straightforward, but the solution is not. You have to draw the objects or polygons from furthest from the camera to closest.

There are a few ways of doing this.

A:
If only a few objects or polygons in your scene are transparent, put a m_bTransparency flag or something on their object and when you come across them during rendering, put them in a list and render them after everything that doesn't have the flag set is rendered. (And put the in their order in distance from camera)

B:
If you're unsure of what will be transparent in your world it gets harder. You can partition your world out using BSP (Binary Space Partitioning) or a similar method and draw the spaces that are furthest away from the camera to closest. That should solve your problem.

http://en.wikipedia.org/wiki/Binary_space_partitioning

Share this post


Link to post
Share on other sites
Quote:
Original post by iSina
Say A is behind B and B is transparent but if A is rendered before B then this blending method does not work due to depth buffer.

So A has a greater distance to the camera than B? It should work then, except you don't have GL_LESS or GL_LEQUAL depth compare mode (GL_LESS being default).

What are the results you get? Any screenshots?


Like cmptrgy412 said, the way to get "correct" blending is to draw the transparent objects after the opaque ones and in back-to-front order.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!