0

I am using this fragment shader:

#version 150 core

uniform sampler2D texture1;

in vec4 pass_Color;
in vec2 pass_TextureCoord;

out vec4 out_Color;

void main(void) {
    out_Color = pass_Color;
    // Override out_Color with our texture pixel
    out_Color = texture(texture1, pass_TextureCoord) * pass_Color  ;
}

Now to pass_Color i give an rgba value. I change up the alpha value. the texture is rgba aswell, its a PNG file. I use blending mode GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA.

Now the problem is that the alpha value that I pass in doesn't affect anything..

and I want it to..

Michael IV
  • 11,016
  • 12
  • 92
  • 223
Amit Assaraf
  • 512
  • 11
  • 34
  • What exactly are you wanting it to affect (it almost looks like you expect blending to occur within your fragment shader by setting out_Color twice...)? It's really the value of texture (texture1, pass_TextureCoord).a * pass_Color.a that you are interested in, by the way (that is the value used for blending, not pass_Color.a). – Andon M. Coleman Aug 24 '13 at 19:44
  • What do you mean? the .a on the texture() call doesnt compile – Amit Assaraf Aug 24 '13 at 19:49
  • What I meant was that only the alpha component affects blending. And you are multiplying the alpha component of the texture by the alpha component of pass_Color.a. It is the result of multiplying the two that determines how your fragment is blended. – Andon M. Coleman Aug 24 '13 at 20:08

1 Answers1

0

I ended up doing this:

vec4 tex =  texture(texture1, pass_TextureCoord);
out_Color = vec4(tex.r*(pass_Color[0]),tex.g*(pass_Color[1]),tex.b*(pass_Color[2]),tex.a*(pass_Color[3])) ;

Works just fine!

Amit Assaraf
  • 512
  • 11
  • 34
  • 5
    That does not make any sense, you should stick to the same component selection syntax for consistency. Use `tex [0] * pass_Color [0]` or `tex.r * pass_Color.r` so people can understand your code. Furthermore, you can just do `tex.rgba * pass_Color.rgba` or `tex * pass_Color` and get the same results without making your code unnecessarily difficult to read. – Andon M. Coleman Aug 24 '13 at 20:17
  • 2
    If that works and the original did not, that sounds like your driver is *incredibly* buggy. – Nicol Bolas Aug 24 '13 at 23:42
  • No it turns out the alpha value was not passed in correctly.. So I thought that this is what made it work.. but it was actually something else.. – Amit Assaraf Aug 25 '13 at 10:08