Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have just spent my first half hour playing with the shader language.

I have modified the basic program I have which renders the texture, to allow me to colour the texture.

varying vec2 texCoord;
uniform sampler2D texSampler;

/* Given the texture coordinates, our pixel shader grabs the corresponding
 * color from the texture.
void main() {
  //gl_FragColor = texture2D(texSampler, texCoord);
    gl_FragColor = vec4(0,1,0,1)*vec4(texture2D(texSampler,texCoord).xyz,1);

I have noticed how this affects my transparent textures, and I believe I am loosing the alpha channel which would explain why previously transparent area's appear totally black.

If I use the following line instead, I am shown the transparent area's

gl_FragColor = vec4(0,1,0,1)*vec4(texture2D(texSampler,texCoord).aaa,1);

How can I retain the transparency after this modification to the colour?

I have seen various things about a .w property, and also luminous, but my tweaks with those and the .aaa property are not working XD

share|improve this question
OpenGL ES 2.0 (WebGL) – Chris Jan 10 '11 at 23:05
up vote 2 down vote accepted

You seem to be throwing away the alpha channel each time you try and play with multiplying the colour part of the texture. You should be able to get to it through either "a" or "w" and then copy it through unchanged.

gl_FragColor = vec4(0,1,0,1)*vec4(texture2D(texSampler,texCoord).xyz,texture2D(texSampler,texCoord).w);

(While I'm guessing this should work, it's been a while since I've played with shader stuff)

share|improve this answer
Worked first time, thanks for you help! :) – Chris Jan 10 '11 at 23:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.