This PDF mentions dynamic branching being used to skip unnecessary projections in Tri-Plannar mapping on page 33
I’ve ran a short test in UE4 to see how large is the actual performance gain.
-
A test scene included a piece of uneven terrain, that takes all the screen space, one directional light and a skylight, no static lighting.
-
Tests were carried out on GTX 770, at 1920x1080. Data below is taken from GPU profiler BasePass time for 10 captures and averaged.
-
Terrain material consisted of 6 tri-way layers, basecolor only, 2k textures. Layers were roughly painted in to be somewhat equally distributed.
[HR][/HR]
- First version was created using typical material editor nodes:
[INDENT]
Material Editor Nodes(No dynamic branching) - 2.69ms[/INDENT]
- Second version of landscape material was done with custom node, where all 6 layers were present together, but X,Y and Z triplannar projections are being skipped, depending on surface normal, as described in above-mentioned PDF:
[INDENT]
*
Tighten Factor 0 * - 3.28ms
Tighten Factor 0.3 - 1.64ms
Tighten Factor 0.5 -1.52ms
*Tighten Factor 0.9 * -1.48ms[/INDENT]
- Third landscape material was same as second, but with addition of branching out landscape layers, fully covered by other layers:
[INDENT]Tighten Factor 0 - 1.77ms
Tighten Factor 0.3 - 1.50ms
Tighten Factor 0.5 -1.40ms
Tighten Factor 0.9 -1.26ms [/INDENT]
- Fourth version of material was same as third, but with [flatten] atribute before IF statement:
[INDENT]Custom Node([flatten] attribute) - 3.28ms[/INDENT]
- And lastly, a fifth version was a custom node with no if statements at all:
[INDENT]Custom Node(No dynamic branching) - 3.11ms[/INDENT]
[HR][/HR]
Graph:
[SPOILER]
[/SPOILER]
[HR][/HR]
Interpreting the results, the first thing to note is the difference between Test 1 and 5
I think that most of the difference comes from using SampleGrad. In addition, I think material translator performs optimizations, like marking texture size and tighten factor as unifrom, etc.
Then there is a jump in render time for Test 2 between Tighten Factor set at 0 and 0.3. Performance gain is mostly influenced by area of flat terrain, which occupies roughly 40% of screen space. With Tighten factor of 0.3 XZ and YZ projections are skipped.
As we add layer branching in test 3, render times are further reduced.
Visually, Tighten Factor values above 0.5 deliver a lot of stretching, so it is unlikely that anything above that will be used.
By introducing dynamic branching in this case, I’ve got a considerable performance increase. Of course this test is not anywhere conclusive and it cannot be applied for every case and the results will vary greatly material to material, but it clearly shows the benefits of skipping texture samplers with dynamic flow control.
I’d kindly ask anyone interested in this feature to upvote these answer hub posts: 1]([FEATURE REQUEST]Dynamic flow control in materials - Rendering - Unreal Engine Forums) and 2