将纹理图像与alpha配合使用可使网格“透视" [英] Using texture image with alpha makes mesh 'see through'

查看:135
本文介绍了将纹理图像与alpha配合使用可使网格“透视"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在启用Back-Culling的Android OpenGL ES 2.0中渲染obj文件.纹理图像中只有一部分(脖子上的项链)实际上具有alpha.

I am rendering an obj file in OpenGL ES 2.0 on Android with Back-Culling enabled. Only some part (the necklace around the neck) of the texture image actually has alpha.

仅渲染网格时,看起来不错:

When rendering only the mesh, it looks fine :

但是,在启用纹理时,我可以透过网格看到另一面.您可以在下面看到位于身体后面的右手.任何想法可能出什么问题吗?

However, on enabling the texture, I am able to see through the mesh onto the other side. You can see below that the right hand which is behind the body also becomes visible. Any ideas what might be going wrong ?

我尝试了以下方法:

  1. 启用/禁用背面剔除
  2. 检查顶点的顺序
  3. 检查法线是否在某些点内

但是似乎没有任何效果.任何其他方向将不胜感激.

But nothing seem to work. Any other direction would be appreciated.

我打开了纹理图像,并通过在图像编辑程序中将其保存为没有alpha图层的方式将所有透明区域填充为黑色.这就是现在的样子:

I opened up the texture image and filled all the transparent area with black color by saving it as no alpha layer in a image editing program. And this is how it looks now :

透明度问题不见了,但是我无法正确看到项链.

Transparency issue is gone, but then I won't be able to see the necklace properly.

Alpha混合和Z缓冲区是否会成为问题?如链接中所述?它声称"Z缓冲区不适用于透明多边形."

Edit 3 : Can Alpha-blending and the Z-buffer be an issue as described in the link ? It claims 'The Z buffer doesn't work for transparent polygons.'

推荐答案

对于深度缓冲区和alpha混合的冲突,有很多解决方案.

There are quite a few solutions for the conflict of the depth buffer and alpha blending.

在您的情况下,最好只禁用混合并丢弃片段着色器中的像素.

In your case it might be best to simply disable the blending and discard the pixels in the fragment shader.

您可能在附件的边框上只有一些半透明的像素,其余的是1.00.0.因此,也许像alpha < 0.5丢弃其他项这样的传递,将alpha设置为1.0.

You probably just have some semitransparent pixels on the borders of the accessory the rest is either 1.0 or 0.0. So maybe a pass such as if alpha < 0.5 discard else set alpha to 1.0.

另一种方法是简单地确保最后绘制了这些混合对象.如果场景中只有此类对象之一,则它应该起作用.但是,如果您在一个后面有多个,那么您可能会再次遇到问题.

Another way would simply make sure that those blended objects are drawn last. If you have only one of such objects on the scene it should work. But if you have multiple one behind the other you may again encounter issues.

这篇关于将纹理图像与alpha配合使用可使网格“透视"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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