I just read the HLSL code generated by the material compiler in UE-4.7 and I noticed that IF nodes generate code like “LocalXX = Condition ? LocalYY : LocalZZ”
Shader fully evaluates both LocalYY and LocalZZ before assigning them to LocalXX even if one of the values is not used. I don’t know if GPUs like branching but this seems like a waste of instructions to me! I haven’t checked this on newer versions of the engine yet but if it is not fixed yet, I hope that it will be one day!
I don’t know how things are in directx 12 but previously all branches where evaluated, this is one of the reasons why using IF statement should be avoided.
@TS100101
Thanks for the link! I will test this, probably it can actually improve performance in cases like if (…) { /* ton of code / } else { / ton of code */ }
But I wonder if this is going to be included in the Material Editor one day.