I have a SubGraph that I use in many of my other graphs. It has a Boolean Keyword that controls some of its behavior. To control whether that boolean keyword is on/off, the main graph also exposes the same Boolean Keyword. That’s usually fine. The problem arises when I want to use my subgraph more than once within a graph. Now it seems impossible for one of the instances to enable the keyword, and another to disable it.
To be clear, let’s say my SubGraph is called “SimpleLitSampler”. Usually my main graph will include that one time, but I have a couple of “dual material” style shaders that sample things twice. I’m unable to have one “SimpleLitSampler” in the graph enable the boolean, and the other disable it, because the only way to pass the value to the SubGraph is to expose it on the main graph.
Hi @dgoyette,
I’m curious as to what you’re trying to achieve.
Keywords ultimately generate different shaders, so they can’t be permuted in the middle of one shader execution.
You may want to use dynamic branching based on a boolean instead.
I was trying to replace a bunch of Branch nodes (dynamic branching) with Boolean Keyword nodes, based on best-practices of avoiding “ifs”. I found that I had a number of Branch nodes in a Subgraph, which branched based on a boolean input to the subgraph. I was testing out replacing those “ifs” to see if there was a performance benefit in my shaders. (Spoiler: there wasn’t.)
When I replaced the Branch with a Boolean Keyword, I immediately ran into an issue: What if I have the subgraph in my graph more than once, and I want the Keyword to be ‘true’ in one case, and ‘false’ in another. It seems like that’s not possible using keywords this way.
Ultimately I gave up on this and reverted everything when I discovered that A) It made no difference at all to runtime Graphics performance, and B) All those shader variants ballooned my build times.
So I’m just going to keep my Branch nodes. Every time branching/ifs coming up in shader performance talks, there’s always alarming suggestion to avoid them, as it’s slow. That’s what motivated this change. But it definitely wasn’t the right choice to replace that behavior with keywords.
Anyway, I’m probably not going to be pursuing this further.
Ah thanks for the details, that’s useful feedback.
In case you haven’t seen it, we have a thread on keywords & branching.
If this is for subgraphs, you may also want to use dropdowns, which makes for static branching, so that one instance can use a value from another. But this is really just when authoring.
1 Like