Shader Node "If Then Else": How does it work?

Can only be static as there’s no way to make a dynamic boolean parameter in UE (to my knowledge at least). If you try to create one you’ll find that it’s just a static boolean exposed to the material instance and can’t be set at runtime.

Now, I thought perhaps you could use a custom node to return a boolean value and use that as the input, but it doesn’t seem to work either. Custom nodes can only return floats and material attributes and just using a 1/0 didn’t work. (plus I guess what good would it be if you had to use a custom node for it? At that point you may as well just stick the if statement in the custom node)… So I took a look at the generated code;

If you try this:

This is the generated HLSL:

lerp(MaterialFloat3(0.00000000f,0.00000000f,0.00000000f),Material.PreshaderBuffer[0].yzw,Material.PreshaderBuffer[0].x);

I’m not sure what the material preshade buffer is, but this definitely isn’t an “if”, and it’s just throwing away the nodes inputs so it doesn’t matter what you plug into it. I can only assume it’s broken, this is the first I’ve seen this node so I don’t even know how long it’s been in the editor, might be some relic from the UE3 days.

The material editor has a bunch of strange nodes that don’t make any real sense, dynamic branch is another one; It’s not a dynamic branch at all, it’s just the regular if node (which is a ternary op) in a trenchcoat.

If you want to read a very long and tedious discussion about that one you can see it here: Shader Dynamic branch not working?

1 Like