I have a texture that's from the color attachment of an FBO in OpenGL ES 2.0, so I have limited control over the number of channels in the image.
Suppose I only need the color from the R channel of this texture. If I immediately swizzle out the R in the fragment shader like this:
float brightness = texture2D(u_texture, v_texCoord).r;
can I expect the GPU to know not to bother looking up G, B, and A?
I figure this is something that might vary from device to device, depending on the optimizations of the shader compiler, but to me this looks like a very obvious and easy optimization.
I'd like to know if I can be reasonably confident that almost all GPUs will make the optimization. This shader is a multiple-texture shader, and I'd hate to get surprised by some percentage of devices running it much slower than what I've tested on. If I cannot, then I may want to take pains to use a different method of generating my image so I can ensure a texture with fewer channels.