使用 GL_DEPTH_TEST 和透明纹理渲染故障 [英] Rendering glitch with GL_DEPTH_TEST and transparent textures

查看:24
本文介绍了使用 GL_DEPTH_TEST 和透明纹理渲染故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从一个角度看,我的灌木是这样的:

From one angle my shrubs look like this:

从另一个角度来看,它们是这样的:

From the other, they look like this:

我的理论是,从第一个角度看灌木时,灌木后面的所有方块都已经画好了,所以在画灌木时,只是把它们画到了上面.

My theory is that when looking at the shrubs from the first angle, all the blocks behind the shrub have already been drawn, so when it comes to draw the shrub, it just draws them overtop.

然而,从另一个角度来看,它基本上是先尝试绘制灌木,然后当​​它绘制灌木后面的块时,它会检查深度缓冲区并发现已经有东西挡住了块的视野,所以它不会渲染它,导致出现深蓝色方块(我的透明色).

From the other angle, however, it's basically trying to draw the shrub first, and then when it goes to draw the block behind the shrub, it checks the depth buffer and sees that there's something already blocking the view of the block, so it doesn't render it, causing the navy blue squares (my clear color).

我真的不知道如何解决这个问题.禁用深度测试会导致各种其他错误.有没有办法将顶点或多边形标记为具有透明度,以便它知道它仍然需要渲染后面的内容?

I really have no idea how to fix this issue though. Disabling the depth test causes all kinds of other errors. Is there some way to flag the vertex or polygon as having transparency so that it knows it still needs to render what's behind?

找到这个.这是唯一的解决方案吗?将我的透明块和不透明块分开,然后几乎每一帧都在 CPU 上手动对它们进行排序,因为玩家可以四处移动?必须有一种方法将其委托给 GPU...

Found this. Is this the only solution? To separate my transparent and opaque blocks, and then manually sort them on the CPU pretty much every single frame because the player can move around? There has to be a way to delegate this to the GPU...

推荐答案

该链接(和 CPU 排序)用于 alpha 混合.如果您只需要 Alpha 测试(而不是混合),那么您不需要对任何内容进行排序.只需启用 alpha 测试,保持启用深度测试,一切都会好起来的.

That link (and sorting on CPU) is for alpha blending. If you need only Alpha Testing (not Blending), then you don't need to sort anything. Just enable alpha test, keeping depth test enabled, and everything will be rendered fine.

请参阅此处:http://www.opengl.org/wiki/Transparency_Sorting您需要需要进行 Alpha 测试的Alpha 测试",而不是需要排序的标准半透明".

See here: http://www.opengl.org/wiki/Transparency_Sorting You need "Alpha test" that requires alpha testing, not "Standard translucent" that requires sorting.

这篇关于使用 GL_DEPTH_TEST 和透明纹理渲染故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆