Jump to content
  • Advertisement
Sign in to follow this  
svnstrk

OpenGL Blending + Depth problem

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

hi,

recently i just found a problem that opengl cant do blending and depth at the same time. i have an object with alpha texture but it cant be rendered correctly when the depth test is on. disabling the depth test solve the problem but it seems like even when the alpha value is 0, opengl still cant render the object behind (lower depth value).

i've googled around and it seems like the best solution is to sort the object based on depth and render it sequentially which is in my scene is hard to implement. any idea how to tackle so opengl can render blended with depth test?


thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
opengl cant do blending and depth at the same time
Yes it can. It will blend your colour components just as you've configured it to, and it will also perform depth testing/writing as you've configured it to.
Your problem is that you're expecting your choice of configuration to perform operations other than what it's supposed to do.
i've googled around and it seems like the best solution is to sort the object based on depth and render it sequentially ... [/quote]Yes, this is the common solution.

To step back for a moment and think about why it "doesn't work", picture this scene:
Camera ---> Object A ----- Object B

If we draw A then B, with depth-buffering enabled:
*A will be blended over the top of the background colour (incorrect), and it will write some "close" value into the depth buffer.
*B will fail to draw at all (incorrect), because it contains "far" depth values, which fail the depth test.

If we draw A then B, with depth-buffering disabled:
*A will be blended over the top of the background colour (incorrect)
*B will be blended over the top of A (incorrect)


If we draw B then A (with depth-buffering enabled or disabled)
*B will be blended over the top of the background colour (correct)
*A will be blended over the top of B (correct)

So you can see, the way that the graphics hardware works -- blending the new object over the previously rendered pixels -- the only way to get correct results is to draw transparent objects in the right order.

any idea how to tackle so opengl can render blended with depth test?[/quote]Aside from the usual solution above, what you're searching for (drawing blended objects in an unsorted order) is called order-independent transparency, and it's a very complex and slow thing to implement. I don't know of any games that implement OIT, rather than just sorting their transparent objects from farthest-to-nearest.

Share this post


Link to post
Share on other sites
I've found that OIT (order independent transparency) to be a pretty good solution, as Hodgman said.

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!