Even if the condition is always false, you're still adding an if-statement to every single pixel you draw with this shader, and that's going to take a nonzero amount of time.
I'm guessing you're confused because you've read statements to the effect that shader dynamic branching is slow when different pixels take different branches. It's especially slow in that case, but it's not free even when all the pixels take the same branch. There is a cost just to have the branch in there.
Typically, the way people handle flags like this is to generate multiple versions of the shader, e.g. one with the texturing code enabled and one with it disabled. This is known as the "ubershader" approach. It can be done using #defines
, or it can also be done using uniform bool
variables and different entry points. People often write shader-generators to create all the different combinations automatically, or add the combinations as different techniques in an effect file.
Another approach is to write a shader that always samples the texture, and just set it to a 1x1 white texture when the texture is not used. This will be quite fast to sample, although not as fast as removing the texture altogether, and it simplifies the code.