IPhone OpenGL ES: Applying Depth Test on Textures with Transparent Pixels for 2D Game

I currently have mixing and depth testing for a 2D game. When I paint my textures, the "top" texture removes some of the bottom textures if they overlap. It is clear that transparent texture pixels are taken into account in depth analysis and will eliminate all the colors of the drawn bottom textures if they overlap. Also, alpha blends are not displayed correctly. Are there any features that can show OpenGL not to include transparent pixels in deep checks?

+2


source to share


4 answers


No, It is Immpossible. This applies to all hardware depth measurements.

GL (full or ES- and D3D) have the same model - they draw in the order you specify the polygons. If you draw polygon A in front of polygon B, and logical polygon A must be in front on polygon B, polygon B will not be colored (subject to depth test).



The solution is to draw the polygons in order from the farthest to the closest current view. Fortunately, in a 2D game, this should just be simple (for example, you probably won't have to do it very often).

In 3D games, BSPs are the primary solution to this problem.

+2


source


glEnable( GL_ALPHA_TEST );
glAlphaFunc( GL_EQUAL, 1.0f );

      



This will discard all pixels with the alpha of everything except fully opaque. These pixels will then not be displayed in the Z-buffer. This, however, affects various Z-Buffer pipeline optimizations, so it can lead to serious slowdowns. Use it if you really are too.

+3


source


if you are using shaders you can try disabling blending and discarding pixels with alpha 0

if(texColor.w == 0.0)
    discard;

      

+2


source


What type of mixing do you use?

glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

      

Any fragments with the letter 0 from the record should be placed in the depth buffer.

0


source







All Articles