jbg
jbg

Reputation: 1003

OpenGLES 2.0 fragment shader alpha fail?

I would expect my texture to disappear completely with the following fragment shader:

varying mediump vec2 text_coord_out;
uniform sampler2D sampler;

void main()
{
    gl_FragColor = texture2D(sampler, text_coord_out);
    gl_FragColor.w *= 0.0;
}

. . .it doesn't. I've also tried gl_FragColor.a. Thoughts?

Upvotes: 3

Views: 7234

Answers (4)

Kibernetik
Kibernetik

Reputation: 3018

gl_FragColor.w = 0;

should work. Probably *= operation bewilders GLSL compiler.

Upvotes: 0

Patt Mehta
Patt Mehta

Reputation: 4194

Use gl_fragColor = only once

  1. perform all operations on different variables like another vec4 in this case
  2. you can use this as the output, like:

vec4 red = vec4( 1,0,0,1 );
gl_fragColor = red;

Upvotes: 7

jbg
jbg

Reputation: 1003

OMG...I totally fixed this. Fragment shader looks like this:

varying mediump float text_alpha_out;
varying mediump vec2 text_coord_out;
uniform sampler2D sampler;

void main()
{
    gl_FragColor = texture2D(sampler, text_coord_out);
    gl_FragColor = gl_FragColor * text_alpha_out;
}

and my blending looks like this:

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

Upvotes: 9

Nicol Bolas
Nicol Bolas

Reputation: 473174

Why should it disappear? The alpha value of the output color has no meaning unless you give it a meaning. Typically, that means using some form of blending. Note that the link describes desktop OpenGL; the GL ES equivalent works much the same way, but desktop GL may have more features than ES.

Upvotes: 4

Related Questions