This question already has an answer here:

I've heard a lot that in shader development, you absolutely need to avoid branching and so if statements.

But why? Does this have a real impact on performances on old and modern hardware or is it more a case by case choice depending on your scenario?

When possible, it's better to use preprocessor macros but when it's not, what can we do?

What is the purpose of using flatten or branch attributes? Are there other solutions available?


marked as duplicate by ratchet freak, Julien Guertault, Nicol Bolas, Alan Wolfe, Nathan Reed Jan 25 '17 at 18:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.