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

Hi guys!

It’s just a simple question but how the shader node “ifThenElse” does work? :thinking:

I don’t have any results with it. So if anybody finds how it works, I’m curious to know :grin:

Quick note: It’s not the same node as “If” (which compares two entries)

Thank you guys!

1 Like

Didn’t even know this node existed, it seems like the static switch node makes this redundant, no?

I agree with you :grin:

Actually, it’s just for curiosity’s sake.

I don’t understand this new node (it doesn’t exist in 5.4) but maybe it be usefull… Or maybe it’s just a forgotten test from dev, I don’t know ^^

hmmm is the “if” node static though?

my first impression of it made me thought that it wasn’t static.

the static switch generates two permutations, and only executes one branch. but maybe the “if” node executes both and the condition could be a dynamic value. like the other “if” node with the A-B comparison.

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

yeah that’s pretty much how i expected it to work. that’s why i thought you could use a 0/1 number instead of a static bool. hence not being static.

but you said

not sure if you were talking about another node. that confused me.

anyways great dissecting work.