Shader transparency?


I just want to understand why, in this shader (rgb split), when I try to get the alpha chanel of tex0, I end up with a kind of red image ? how can I solve this and keep the original colors ?

#version 120

uniform sampler2DRect tex0;
uniform float amount = 0.01;
uniform float angle = 0.5;
uniform int invert = 0;

varying vec2 texCoordVarying;

void main() {
    vec2 offset = amount * vec2( cos(angle), sin(angle));
    vec4 cr = texture2DRect(tex0, texCoordVarying + offset);
    vec4 cga = texture2DRect(tex0, texCoordVarying);
    vec4 cb = texture2DRect(tex0, texCoordVarying - offset);
    vec4 alpha = texture2DRect(tex0, texCoordVarying);
    gl_FragColor = vec4(cr.r, cga.g, cb.b, alpha.a);

Thank’s !


Hello @GllmSlvn. A “kind of a red image” is a too broad term. If you are passing a red image, I would expect “a kind of a red image”.

what do you see if you print as result:

gl_FragColor = texture2DRect(tex0, texCoordVarying);

If you are not seeing the image that you are passing, then something is wrong either in where you pass the texture to the shader or in the coordinate.

Also note that

    vec4 cga = texture2DRect(tex0, texCoordVarying);


    vec4 alpha = texture2DRect(tex0, texCoordVarying);

Are the same, this could be one variable.