0

I have a picture of a tree in OpenGL as a 2D texture. I want to remove the background (skyblue) or rather make that part transparent. How can I do this in the fragment shader. The closest I came up with is removing the pixels of the texture that are above a threshold value. For e.g

#version 330
in vec2 texCoord;
out vec4 outColor;

uniform sampler2D theTexture;

void main()
{
  vec4 texel = texture(theTexture, texCoord);
  if(texel.b < threshold)
     discard;
  outColor = texel;

}

jaykumarark
  • 2,359
  • 6
  • 35
  • 53
  • 1
    And what's wrong with that solution? – j-p Apr 28 '14 at 00:39
  • This will not work as you describe it, because it discards pixels that are ***below*** a threshold value. As your question is written now, you just have to flip the sign in the comparison. – Andon M. Coleman Apr 28 '14 at 01:13

0 Answers0