Search code examples
iosopengl-es-2.0render-to-texture

iOs OpenGL ES 2.0 adding textures with low opacity on device and on simulator


I have a problem with multiple drawing of textures in my program.

Blending mode is

glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_ADD);

The value of a-channel is passed into the shader from cpu-code.

precision highp float;

uniform sampler2D tShape;

uniform vec4      vColor;
uniform float     sOpacity;

varying vec4 texCoords;\n"

void main() {
    float a = texture2D(tShape, texCoords.xy).x * sOpacity;
    gl_FragColor = vec4(vColor.rgb, a);
}

It's calculated previously with

O = pow(O, 1.3);

for the best visual effect.

I draw with color (0; 0; 0) on the black transparent canvas (0;0;0;0), but with very low opacity:

0.03 -> 0.01048
0.06 -> 0.0258
0.09 -> 0.0437
0.12 -> 0.0635
...

I expect, that maximal value of point's color will be (0;0;0;1) (black, no transparent) after multiple drawings as on the simulator: enter image description here

but it isn't so on the device: enter image description here

Do you have any ideas, why is it so?

UPDATE:

Also manual blending works incorrect too (and with difference from standard).

glBlendFunc(GL_ONE, GL_ZERO);

Fragment shader code:

#extension GL_EXT_shader_framebuffer_fetch : require
precision highp float;

uniform sampler2D tShape;

uniform vec4      vColor;
uniform float     sOpacity;

varying vec4 texCoords;

void main() {
    float a = texture2D(tShape, texCoords.xy).x * sOpacity;
    gl_FragColor = vec4(vColor.rgb * a, a) + (gl_LastFragData[0] * (1.0 - a));
}

Result on the simulator: enter image description here

Result on the device: enter image description here


Solution

  • After some experiments I've understood, that this problem is in supported precision of device . So on the iPad Air this problem appears less than on iPad 4, 3.