简体   繁体   中英

iOs OpenGL ES 2.0 blending with shader on device and on simulator

Here is the fragment of fragment shader code (I need make blending in the shader):

float a = texture2D(tMask, texCoords).x; // opacity of current pixel from mask texture.
if ( a == 0.0)
    discard;
else {
    vec4 dst_clr = texture2D(tBkgText, posCoords); // color of current pixel in current framebuffer.
    vec4 src_clr = vec4(vColor.rgb, sOpacity);
    gl_FragColor = src_clr * a + dst_clr * (1.0 - a);
}

Here are the blending function and equation:

glBlendFunc(GL_ONE, GL_ZERO);
glBlendEquation(GL_FUNC_ADD);

And here are results on device (left) and on simulator (right):

在设备上在模拟器上

How to make so that it works like on an emulator?

UPDATE:

I've removed discard :

float a = texture2D(tMask, texCoords).x; // opacity of current pixel from mask texture.
vec4 dst_clr = texture2D(tBkgText, posCoords); // color of current pixel in current framebuffer.
vec4 src_clr = vec4(vColor.rgb, sOpacity);
gl_FragColor = src_clr * a + dst_clr * (1.0 - a);

Now result on the device looks like:

在没有“丢弃”的设备上

I resolved this problem with adding glFlush after glDrawArrays . The problem was that the texture was not updated when the drawing occurs in its associated framebuffer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM