# Dynamic flow control in materials

**URL:** <https://forums.unrealengine.com/t/dynamic-flow-control-in-materials/68393>\
**Category:** Rendering\
**Tags:** unreal-engine\
**Created:** [July 7, 2016, 12:52pm UTC](https://forums.unrealengine.com/t/dynamic-flow-control-in-materials/68393 "2016-07-07T12:52:49Z")\
**Posts on this page:** 1\
**Showing post:** 63

<div class="post-metadata">

**Author:** ![John\_Alcatraz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@John\_Alcatraz](https://forums.unrealengine.com/u/John_Alcatraz)\
**Post date:** [June 15, 2020, 5:28am UTC](https://forums.unrealengine.com/t/dynamic-flow-control-in-materials/68393/63 "2020-06-15T05:28:25Z")

</div>

> [@Calvinatorr](#):
>
> [MostHost LA](https://forums.unrealengine.com/core/) came across this again and thought it’s only responsible to post what I believe is the solution here. It can be done as when the code generated via the material editor gets compiled to asm, it will the code for each result into its own branch.
> 
> So to achieve this you just use a custom node with the BRANCH HLSL macro as so.
> 
> ![0.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/1/8/187f63112db257c125a26af936b518ba780362ee.jpeg)
> 
> Inspecting the pixel in the API call in RenderDoc shows this asm, which to me is a pretty clear indicator that this actually works (surprisingly).  
> I believe this is also the same on PS4 when the code gets ported to PSGL. Not sure about other platforms.
> 
> ![1.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/e/7/e7deff8174794795cf703c5bb516b2e314195572.png)
> 
> Please let me know if you think is somehow wrong, but to me it seems as clear as day that this should work.

I have tried to replicate your results, but I could not do so. I have tested in both 4.25.1 and 4.22.2, and both versions give me the same result, that no branching actually happens:

 ![UE4Editor_2020-06-15_07-24-06.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/8/a/8a67406385146787ece820a2b1a4f23d05c52605.jpeg)

You see the material has a bunch of very heavy noise nodes, to see if it works or not. I have placed a plane in the level with this material applied, and set the screen percentage to 200% to easily see any performance issues caused by the pixel shader.

No matter if the Param is 0 or 1, my Base Pass takes around 17 ms in this case. If I replace the “Param” parameter with a static “0”, the Base Pass time goes down to 0.5 ms, so that’s how it should be if it would work.

Have you done anything else to make it work for you?

---

_[View the full topic](https://forums.unrealengine.com/t/dynamic-flow-control-in-materials/68393)._
