Why the background of a texture gets black if the alpha channel gets changed in the fragment shader?

Viewed 137

I have the following texture which has transparency and it renders okay.

enter image description here

I want to fade this texture by changing the displayed alpha channel of each pixel, so I wrote this on the fragment shader

void main()
{
  fragColor = texture(uTexture, texturePosition);
  fragColor.a = uAlpha;
}

This works as expected, except now where the texture is transparent it renders like it's behind something that is black

enter image description here

I'm missing something? Why adding an alpha channel changes the background of the texture to black?

1 Answers

I found a solution, but I don't understand why this works

void main()
{
  fragColor = texture(uTexture, texturePosition);
  fragColor *= vec4(uAlpha);
}

enter image description here

Related