3
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ OpenGL ES 2.0 (WebGL) \$\endgroup\$ – Chris Jan 10 '11 at 23:05
2
\$\begingroup\$

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)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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