Hi everyone,
For the last days, I worked on a proof of concept of a branching node. And what I can say is that it’s far from being easy as it’s completely against the flow of the material compiler
I managed to do something like this:
This sounds good but there are 2 drawbacks:
- For such a simple example, this is taking longer to render. I have capture from Pix from Xbox but as I have absolutely no idea if I can post it other than UDN and Xbox Dev forum, I won’t take the risk. But roughly, the pixel pass, while having less instructions is having a general higher cost per instructions which makes it longer to process when branching. The good thing is that on a bigger scale of things branched out (like a triplanar sampling for example) it would probably be beneficial.
- It fails to compile because DDX/DDY cannot be into the branch. It also fails when the sampling into the branches are not using SampleGrad (so a simple sampling fails). It’s an API limitation apparently and triggers X4014 error (cannot have divergent gradient operations inside flow control). So it means that the idea to replace the “if node”, that uses abs() and some math to make the condition, with a real “if” and the “branch” tag sound quite optimistic. (I initially started to tackle this topic in an optimistic mood in fact :P)
For this second point, I added a dynamic amount of input called “StopBranch” that will exclude code from the branch:
And it works fine now.
This is a proof of concept, this probably fails hard when you link element between branches (but why would you do that if you decide to force a branch).
What I plan to do is still to experiment it on the landscape. Considering there that I want to challenge this with texture arrays to see what’s best for our project (because you guessed it, it’s very context-dependent and only profiling could give a hint on if it’s worth). It can be both in fact (Branching and Texture arrays).
The hard question: can I make the code public? Unfortunately, I don’t think so. This code is tied to my current project (professional) and is currently very hacky and untested (so not even a possibility of a pull request). Most likely, to make this properly (aka: public release), that would need a big commitment and that’s the point of my post. The material compiler is not tailored to produce code like that and that would need quite a refactor of it.
However, as you’ve seen, we need it and so it naturally adds me into the group of people interested by such a feature