How to stop cleaning OpenGL background on transparent textures

I have an iOS OpenGL ES 2.0 3D game, and I'm working on making transparent textures work beautifully, in this particular example for a fence.

I will start with the final result. Bits of green background / transparent color pass along the edges of the fence - note that these are not ALL edges, and some of them are in order:

Background bleed evidence

The reason for the absence of bleeding in the upper right corner is the order of operations. As can be seen from the following pictures, the drawing procedure includes some buildings that stretch in front of the fence. But most of them after the fence:

Draw progression with depth

, - . , . , .

, , , , ( , -, , ).

.

shader - :

lowp vec4 texVal = texture2D(sTexture, texCoord);
if(texVal.w < 0.5)
    discard;

PVR mipmapping - 0 1 , - :

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

:

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

!

EDIT - , , LINEAR/NEAREST, . . / :

enter image description here

+5
2

-,

lowp vec4 texVal = texture2D(sTexture, texCoord); if(texVal.w < 0.9) discard;

+1

, , , OpenGL. , , . :

glClearColor(1, 0, 1, 0);
glClear(GL_COLOR_BUFFER_BIT);

. , , , . , , glClear. :

glColorMask(false, false, false, true);
glClearColor(1, 0, 1, 0);
glClear(GL_COLOR_BUFFER_BIT);
glColorMask(true, true, true, true);

, , , -. . - OpenGL , !

0

All Articles