One thing that is difficult when working with complex materials is the maze of connection between nodes.
Last time I had some group of nodes calculating a uv coordinate with some offset, and I used the results as input in several other nodes further on in the material. This gave me quite a maze of connections, and I couldn’t find a way to make it look less complex…
To me it would seem easier if I could store this result in a variable, and reuse it in other parts of the material. I’ve attached images explaining what I mean.
You could also look at it like ‘wireless connections’ between node, based on a variable name. Obviously for each variable name, only one node can ‘set’ it, while multiple nodes can ‘get’ it.
I hope I make my idea clear and that other people understand why this would make materials cleaner.
A way of organizing complex material setups is using functions.
Your “rest of the rather complex material” would be a simple node in the material graph with inputs as needed.
KVogler, someone one the answerhub also gave this answer, but this is not exactly the same. Functions are for reusing functionality, but I want to reuse results of computations somewhere else in the same material. If I would reuse functionality, it would recalculate the whole thing over again several times, which is not what I want. On top of that, the material function would still require several inputs, which is also not helping me at all with the messyness. The situation is that I have some output, and it needs to function as input for several other nodes somewhere else. I would like to be able to do this without dragging a connection between all those nodes.
In my example. I calculate several things:
-a corrected UV coordinate for the current pixel
-a corrected UV coordinate for the center of the effect I want to add
-the sin of the clamped distance between the current pixel and the center of the effect.
-And several other more
the effect I’m making in the material has several aspects to it. For each aspect, I need a certain subset of the results of the above calculations. This is getting messy. Ofcourse I could place a collection of nodes in a material function, but if I reuse it in several places, it would redo the calculations several times, which is not neccesary. Also these material functions would still require several inputs from UV coordinates and material parameters. I would end up making even more complex connections between nodes, because now on each place I need them, I need to connect SEVERAL inputs to it, would be even worse.
Why has something like this not been done yet. Imagine how much easier it would be to create complex materials with a feature like this. Epic, you guys reading this?
This would be nice. A local variable essentially (which it probably becomes when it’s compiled anyway). We implemented something like this in the UE3 material editor at the last place I worked.
+1, this would be really useful to keep things tidy in complex material setups, specially in places where you calculate/process one thing and then plug it in multiple places (i.e. a mask used in color/roughness/spec, etc)
It is completely different to material functions. A material function recalculates every time. A local variable could be used to store this result and reuse it multiple times without recalculating.
Nope.
What is described in the thread offers no benefit of over existing material editor functionality.
Whenever you slap 20 nodes of same material function and wire them to keep the graph clean, or place one material function and send over spaghetti net to 20 pins, it makes no difference.
If you are concerned about duplicate HLSL code being generated by material translator, you should not worry about it. It is handled by fxc/hlslcc.
As someone coming from unity while daily using shaderforge, I miss this feature… set and get nodes kept things so clean. I hate the fact that I have so many noodles overlapping eachother.
Just realized I duplicated this request!
Deleting my post and adding my examples here.
Amplify Shader editor for Unity does this, and it made my materials so, so much cleaner. Particularly anything with lots of math where a term needs to be computed once but reused in many places.
EVEN if Material Functions didn’t calculate the result every time (proof of this?), they still require using new files - which is a mess. Using variables keeps the whole setup in the editor, clean and quick.
Cables going everywhere is hard to read. we NEED this feature as it is so much tidier! I use Amplify Shader Editor extensively on Unity and develope high end shaders with it. I want to replicate these shaders for Unreals marketplace but my god it gets messy, yes, you can can bend the wires around by adding nodules etc but I’m not an electrician. Also the O.P is from 2015!! will we ever see this feature?
Just thought about this a bit further:
If you are concerned for redundant calculation due to multiple calls to a function another possibility would be using render targets.
It keeps the results and gets only updated when you want it to. This may require a bit more logic to it than a straight forward var declaration but should work.