我正在尝试混合具有透明区域的纹理:
I am trying to blend textures which have transparent areas:
glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, ...); glVertexPointer( 2, GL_FLOAT, 0, ... ); glEnable (GL_BLEND); glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );除非我添加 glDisable(GL_DEPTH_TEST),否则顶部纹理的透明部分会覆盖它们下方的所有内容(而不是混合).有没有办法在不禁用深度的情况下做到这一点?我尝试了各种混合功能,但没有任何帮助.
Unless I add glDisable(GL_DEPTH_TEST), transparent parts of the top textures overwrite everything beneath them (instead of blending). Is there any way to do this without disabling depth? I have tried various blending functions but none of the helped.
推荐答案启用深度测试实际上并不按深度对几何图形进行排序——在通常的 GL_LESS 情况下,它只是阻止基元绘制,如果它们并不比之前绘制的更靠近观察者.这允许您以您想要的任何顺序绘制不透明的几何体,并且仍然可以获得所需的结果,但是混合几何体的正确渲染通常需要混合对象后面的所有内容都已经被渲染.
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:
或者,如果您的内容总是完全不透明或完全透明,您可以启用 Alpha 测试并禁用混合,但我猜这不是您想要的.
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.
更多推荐
将透明纹理与深度混合
发布评论