Jump to content
  • Advertisement
Sign in to follow this  
nerdtron

transparent rendering -- question

This topic is 3028 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'm rendering a bunch of objects, followed up by a couple transparent objects (I'm using a fixed blending function so you can partially see through the objects). This works really well. By rendering the transparent objects last as is recommended, none of the opaque objects get clipped by the transparent ones and you can see through them to the objects behind them. The problem is the interaction of the transparent objects with each other. Due to the z-buffer, the one that gets rendered last, if behind another transparent object will get hidden. Is there a good way to achieve the desired result here? Namely, I don't want transparent objects to affect each other in terms of depth, but I want the opaque objects to affect the transparent ones. In other words, if a transparent object is behind an opaque one, I shouldn't see it. But if a transparent object is behind another transparent object I should see it through the first one.

Share this post


Link to post
Share on other sites
Advertisement
You can fix the occlusion issue by disabling writing to the z-buffer when drawing transparent objects.


//Draw Opaque Objects
...

glDepthMask(GL_FALSE);

//Draw Transparent Objects
...

glDepthMask(GL_TRUE);



While now you will be able to see all of your transparent objects, unfortunately the colors will no longer be completely accurate. This may be good enough for you depending on what your scene looks like, but if you want real transparency you have to sort all of your transparent objects from far to near.

See this for more explanation:
Transparency Sorting




Share this post


Link to post
Share on other sites
But if you just disable the depth test when drawing transparent objects, what happens when a transparent object is behind an opaque object? I still want the transparent object to be hidden by an opaque object, just not by another transparent object.

Share this post


Link to post
Share on other sites
glDepthMask still performs depth testing as you suggested, but it doesnt do writing. So it is what you want. glDisable(GL_DEPTH_TEST) will cut out depth test AND write.

Share this post


Link to post
Share on other sites
That did it! Thanks! Rendering the opaque objects first, then rendering all the transparent objects with the depth mask off worked great.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!