Search code examples
androidopengl-esopengl-es-2.0fragment-shaderglsles

why opengl shader mix function for two transparent png photo become black?


Photo 1 is:

enter image description here

Photo 2 is:

enter image description here

Of course photo 2 is partly transparent.

But when i mix them in shader such as that:

vec4 add(vec4 one, vec4 two){
   return mix(one, two, two.a);
}

They become partly black like the following:

enter image description here

i'm so confused about why it will generate black color. I know mix function basely implements like these:

A*(1-alpha)+B*alpha

Solution

  • Finally, i solve this problem by dividing rgb by alpha

    two.rgb / two.a
    

    thought i don't know why. but i remove the black color successfully.