Blending transparent textures with depth

℡╲_俬逩灬. 提交于 2019-11-30 15:21:40

Enabling depth test doesn’t actually sort your geometry by depth—in the usual GL_LESS case, it merely prevents primitives from drawing if they aren’t closer to the viewer than what has previously been drawn. This allows you to draw opaque geometry in whatever order you want and still get the desired result, but correct rendering of blended geometry typically requires everything behind the blended object to have already been rendered.

Here’s what you should be doing to get a mix of opaque and blended geometry to look right:

  1. Separate your blended geometry from your opaque geometry.
  2. Sort your blended geometry from back to front.
  3. Draw all the opaque geometry first as usual.
  4. Draw your blended geometry in sorted order. You’ll want to leave depth testing enabled but temporarily disable depth writes with glDepthMask(GL_FALSE).

Alternately, if your content is always either fully opaque or fully transparent, you can just enable alpha testing and disable blending, but I’m guessing that’s not what you’re looking for.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!