问题
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 ?
Edit:
I have tried the following :
- Enabling/Disabling back face culling
- Checking the ordering of vertices
- Checking if normals are inside at some points
But nothing seem to work. Any other direction would be appreciated.
Edit 2 :
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.
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.'
回答1:
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.
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.
来源:https://stackoverflow.com/questions/35893742/using-texture-image-with-alpha-makes-mesh-see-through