openglgl-triangle-stripglblendfunc

GL_TRIANGLE_STRIP and transparency problems


I want to draw transparent polygon(a pyramid for example). Some faces appear transparent where as some faces appear opaque.

Im drawing using GL_TRIANGLE_STRIP.

I have enabled blend mode, but no luck.

Please see the attached image,


enter image description here


Solution

  • This happens because of the draw order of the triangles. Some triangles get drawn first, these write their depth values to the depth texture, then the next triangle comes along and checks if there's something in front of it. If there is, then it won't render.

    If a triangle that is at the back renders first, then there's no problem, the triangle in front of it looks at the depth texture, sees that it has a greater z value so it gets correctly rendered, these are the places where the color is less transparent.

    The problem arises when the triangle at the front renders first. It writes it's depth value to the depth buffer, then the triangle in the back comes along, sees that there's already something in front of it, so it doesn't get rendered.

    You have multiple ways to solve this, you can disable depth testing, sort the triangles so they come in order or use an algorithm like depth peeling. Each of these algorithms have side effects or are simply very complex, this is why you don't see too much transparency in games.