There is a difference between being able to determine value at compilation time and at runtime.
false && bla
Gets eliminated because of C/C++ lazy operand evaluation rule which is standardized with left to right order.
The compiler generates no code so the machine has no overhead.
step(1.0, x) * texture2D(pic1, uv);
That will depend if x is coming from a uniform value, in which case the drivers will compile an adjustment of the shader (and put it in a combinator cache). At some point before starting to render.
(this can cause hiccups in framerate when new uniform values are encountered that cause massive shader rebuild)
x is dependant, which means it comes from a previous calculation that comes from varying values or system values, the compiler will cut your expression in 2 parts, the
lerp calculus and the
It will move the sampling of the texture in the first instructions of the shader. (provided it's unconditional in the shader flow).
So you're basically screwed when it's 0, you'll pay the sampling anyway.
In your case (0-2 wrt frag pos), I would recommend using
if (inrect(0,0,1,1)) because this is a low frequency "step" function, which means very good branch elimination in 3 quarters of the screen.