This is a common misconception. If-statements aren’t expensive per se, but they have some quirks which can make them useless for performance gains.
First of all, conditional assignments are extremely cheap. Example: [icode]x = myBoolean ? 10 : 5;[/icode]
Secondly, on OpenGL cards with dynamic branching, if-statements can actually increase performance. Many people want to use if-statements to skip work in shaders, realize that they give no performance gain (but also don’t performance cost!) and proclaim that if-statements are slow. GPUs runs shaders in groups, usually of 16x16 pixels, but the processors on your GPU aren’t very flexible. If you have an if-else-statement in your shader and 255 pixels pass the if-statement and just a single pixel does (= enters the else-block), all 256 shader executions will run both the if and else blocks. For example, I had code that skipped work for pixels with depth=1.0 (meaning the sky was visible so I can skip some computations) and it worked very well, since the sky pixels were generally a continuous area on the screen, so a significant number of 16x16 blocks could skip the computation. If you on the other hand were to look at the sky through the branches of a tree, this would break down since most 16x16 blocks would have at least a few pixels that the branches or leaves covered, so the whole block would have to run the computations.