So my application uses mostly rgba textures for rendering, but in a few cases I use alpha masks for things like rendering text.
I'd like the output of my fragment shader to be the value of the texture sampler at the given coordinate multiplied by a color uniform I pass in. The problem is that I can't find a simple solution that handles both cases.
So for rgba textures this gives the desired result:
gl_FragColor = texture2D(diffuseTexture, varTexcoord.st, 0.0) * color;
But for alpha textures, the output is always black. I'm assuming the texture sampler treats every pixel of an alpha texture as: rgba(0, 0, 0, alpha), and I want it to be treated as rgba(1, 1, 1, alpha). I can get the desired result on alpha textures with this:
gl_FragColor = texture2D(diffuseTexture, varTexcoord.st, 0.0).w * color;
But obviously this breaks the rgba textures.
I'm fairly new to GLSL, and I'm wondering if there's a good way to handle both cases, or if I'm going to have to have 2 different shaders, or else convert all my aplha textures to rgba.
edit:
I think I'm going to end up re-packing my alpha textures as GL_LUMINANCE_ALPHA textures when loading assets.