Dynamic Branching for materials

Hi!

I was hoping to get some clarity about the Dynamic Branch material function found here:

/Engine/Functions/Engine_MaterialFunctions02/Utility/DynamicBranch

The description says:

“The code connected to the “Color Input 1” will be executed if the alpha is greater than 0 and the “Color Input 0” input code will be evaluated if the alpha is 0. Dynamic branches are best used when masking 20 or more instructions or a texture sample.”

However, it does when viewing the generated hlsl (DirectX SM6) it doesn’t seem to implement an actual branch, instead produces this:

float3 Local22 =  select_internal( (abs(  Local1  - 0.00000000f) > 0.00000100f) ,  select_internal( (  Local1  >= 0.00000000f) , 12.50000000f , Local21 ) , Local21 ); 

and I would expect to see something more like:

[branch]
if(local1 > 0)
{
      //code for output 1
}
else
{
      //code for output 2
}

When looking inside the Dynamic Branch function, it is just an “if” node checking if the input > 0

Please can you confirm if this is all intended or if it is mislabed?

I am aware of future intention to add “if-then-else” node feature, as mentioned at 38:16 of https://youtu.be/KYmd_LNlw2c?si=OHvOyX2-PE3iG4As&t=2296 which looks to be a true dynamic branch, does this have a planned release version yet? And if possible please could you tell me the scope of the engine changes required to implement that node.

Thank you!

UDN Dynamic Branch.zip(432 KB)

Steps to Reproduce
In my test I set up a simple unlit material using the “Dynamic Branch” function to mask between a float, and some texture samples.

I viewed the shader code generated at Window/Shader Code/Direct SM6/High Quality.

I have attached screenshots in a zip folder.

Hi Will,

I chatted briefly with the devs working on the material translator, and I have two updates for you. First, the current dynamic branching behavior you are seeing is intended and will not be changed. Second, we are not looking to change that behavior because we are actively working on a brand-new implementation of the material translator that will support proper dynamic branching out of the box. I cannot give you an exact date for when these changes will ship, but we will try to release them as soon as we can. Depending on your project deadline, you’ll still be able to pick this up in time. Please let me know your thoughts on this and if anything else is unclear.

Cheers,

Tim

Ok, that’s good to hear! If you don’t have any further questions, I will close out the case. Please feel free to let me know if there is anything else you need answered before then.

Thank you that is good to know.