Why does the OpenGL shader blending function of two transparent PNG photos turn black?

Photo 1 is:

Photo 2 is:

Of course, photo 2 is partially transparent

But when I mix them in shaders like this:

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

They partially turn black as follows:

I'm confused about why it produces black. I know that the mixing function is basically realized in this way:

A*(1-alpha)+B*alpha

resolvent:

Black will not be generated. It is the color of the background. It is displayed because you want to mix the two colors and their alpha. When the generated alpha value is less than 1, you will see the black background

You should blend RGB color values based only on the alpha of the second image, as follows:

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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>