Chosker: Good examples, but for someone who keeps preaching to read the HLSL code, you definitely didn’t in your flawed mockup of “my” version. Your two custom nodes are being executed in the wrong order. Custom nodes don’t follow a lot of the same rules that standard nodes do. They can interact with each other and be executed out of order. Which is why when you condensed the custom nodes, into one node, it functions as you’d expect; using pretty much identical logic.
If you check the HLSL code, the proper order would show CustomExpression0 as the IF branch and CustomExpression1 as the texture function. Your version of my branch places them in the wrong order(I tested it). It’s executing the texture function FIRST, THEN it’s executing the IF branch; therefore that’s where the frame cost is coming from because it’s doing the complex loop before it ever even reaches the branch IF to see which branch to execute. This isn’t an issue with dynamic branching, this is an issue with how the editor/compiler orders the custom functions. It’s in the engine, it’s just fickle right now. Ideally, there would be an option to set the CustomExpression orders kind of like with material function inputs.
even touched on this ordering topic in a live stream at one point(watch around 12:30):
And you’re wrong, I’ve used dynamic effects in them with things like camera/absolute/pixel and it still works just fine. The version I showed was for simplicity sake. I have it integrated into some game assets already and it’s working as intended. Obviously, the code isn’t as simple as the branch I was demonstrating, but it still gets the point across that the engine DOES have dynamic branching; if you use it correctly and tiptoe around it’s quirks. Personally, I have avoided using custom nodes, behind other custom nodes, and just try to collapse it into one; if needed(rarely). I try to stick to mostly regular nodes, that way the branching works without hassle.
The biggest point still rests that if you want it, it’s there and it works. Hopefully they expand on HLSL some and make it a little less finicky. You’ll just have to play around with it and make sure that the orders of the expressions are correct… If you’re trying to dynamically branch, try to avoid using any more custom nodes behind it; as they will likely give you trouble and execute out of order. If you absolutely have to, then condense the custom nodes into one; to avoid the issues that Chosker presented.
If the devs ever read this:
On the custom nodes, please give us the ability to manually override what order the custom expressions are evaluated. Right now, it seems to order them from “left to right” but it would be awesome if we could change an option and make it go from “right to left.”
Actually, scratch that. After thinking about it for a minute, that would pretty much require a rewrite of the entire shader compiling engine. I’ll just stick to using dynamic branching for saving instruction counts when they aren’t needed.
Also, even though it’s pretty quick and easy to make a custom dynamic branching IF or lerp node, it would be really nice if we had them as regular nodes like If Dynamic and Lerp Dynamic