@
That would be truly amazing.
However, how the compiler will decide what goes under IF, and what stays before it?
In context of this network:
http://image.prntscr.com/image/05b4fcea2a2d43e891e9a5d435758221.png
Texture.SampleGrad should go into respective IF and ELSE sections, and the green comment blocks should be done before IF statement
There probably needs to be some sort of marker nodes to specify where branching ends. And what if you want to calculate several values under same IF/ELSE, and not just one Vector4 ?
Additionally, there is an issue with texture sample nodes, that are set to use explicit derivatives or level. They will not share samplers between different textures.
While this improvement to the compiler can potentially be exceptionally good, I imagine it being quite a bunch of complicated work.
Alternatively, would it be possible to make a change to the custom node, so in addition to outputting a float4, you could output float4x4, which would be broken down to 4 Vector4 material pins?
This or similar change to custom node would probably cover 99% of needs of anyone who wants to use more advanced things in pixel shader, dynamic branching included. And something tells me that it should not be very hard to implement.
@Maximum-Dev mentioning you here, because I noticed you were interested in landscape material optimizations. This is one of the features that would bring major render time reduction for terrain.
Lastly, I am quite surprised that dynamic flow control in pixel shaders is not receiving a lot of community attention. To my best knowledge, it has been used quite extensively in recent and no so recent released titles. Area of its application is quite limited. It works best that something, that occupies large screen spaces. Landscapes, Water surfaces, Large cliffs. However potential performance gain is unmatched.