[Feature Request] Material editor loops

I’ve seen this discussed a lot but I’m surprised I couldn’t find a formal request. It’d be extremely useful to have while and for loops in the form of native material editor nodes. It would eliminate the need for custom code node usage in a huge variety of effects.

Yep. It is actually quite strange that this was not requested before. Upvoted. These two feature requests are also somewhat relevant.

bump for justice.

I think the reasoning behind not having them is that you have to be verrry careful with these in shaders or you’ll kill performance. Seems like the thought is, if you are writing your own node you know enough to use loops wisely.

Though additional math and certain flow control would be great to have in materials, whenever you have some kind of switch, engine actually should precomile shaders for each material possibility. However there’s indeed ticket for better flow control, I believe.

Well… 4.20.2 version has been released, and UnrealEngine still does not have this functionality…Why? How to raise the importance of this serious problem?

P.S.: I need loops (for/while) functionality to implement RayMarching on signed distance function in post processing stage…
At the moment we have to make plug-ins, but it’s very inconvenient and you can lose compatibility because of use private functions… UE developers, save us! Add for/while loops into Material graphics editor please…

You can use the custom expression node, no need for plugins. Custom Expressions | Unreal Engine Documentation

In this expression node I can’t use functions in code, but they are very necessary, especially for reusable code in shader…
Also, I can’t use external functions, which are declared in the graphic editor of materials.
For this reason, the only way out - use of plugins or some dirty hacks like this code in Custom Expression Node:

#include "/Engine/Private/iacopoHlslStructures.ush"
return iacopoHlslFunctions.OrangeBright();

found here: https://forums.unrealengine.com/development-discussion/rendering/113855-extending-custom-hlsl-custom-expressions

I made a ray traces in UE4 and I used both custom nodes, shader code that I added to the loaded shader files in the engine, and recursive functions in the material editor. I am unable to see why using functions in a shader is not doable. If you are thinking of calling a CPU function from a shader, then that is not possible. The closest thing would be a GPGPU style issue where the result determines the next action on the cpu.

You can implement a raymarcher using UE4, I did it.

“I have made a SDF renderer in OenGL before”
Can you show results?
Thanks, btw.

ray marching != ray tracing in general terms, loops and functions in shaders are needed in many techniques and effects and it is this that is not implemented in UE4… RayMarching already implemented in UE4 by me through dirty hack in CustomExpression node (see link above)
Result: Unreal Engine 4 - Pure RayMarching on Signed Distance Function - YouTube

It uses the same techniques and concept to a large degree. The math is a bit different, but you need loops for raymarching as well. Functions you can also make and call as you see fit. The way you did it is indeed not too beautiful, but it also not required. You could just write the loops yourself inside a custom node, if you dont want to import the script through a hack, as you put it.

I have made a SDF renderer in OenGL before, and I have done raytracing and raymarching in UE4. The editor sucks, but it is workable. I just made changes in another editor and copied the result in.

Good work, btw. Really nice and smooth results.

In fact I can.

Use functions declared within a struct for that.