Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.