Material Function Complexity vs Separate Smaller Functions?

Hi all,
this is my first question here, as our studio recently switched to Unreal Engine and I was tasked into creating terrain shaders/materials, which brings me to my first question concerning material functions!

I was wondering what is best between having 1 material function that takes care of 3 textures( DIFF, SPEC and NRM), or 3 separate functions so that both functions for the DIFF and SPEC textures are rather simple, and the function for the NRM map is more complex?

I am doing World Aligned/Tri-planar projection, and the DIFF and SPEC parts are just some simple Lerps, but the NRM part does more then just Lerping. If all 3 textures go through the same function, does it mean that function gets called 3 times? If yes, wouldn’t it be faster to use separate, smaller functions for the DIFF and SPEC maps instead?

Thanks for your time!
Steph

Hey Stephane, As far as I know (and please someone, correct me if I am wrong) if you have three copies of one material function, which are assigned to Diff, Spec, Norm, it will be used three times.
a material function is basically nothing more than a pre-made group of nodes.
There is no advantage besides easier to use/faster to place than constantly recreating them.

so in your case, it might be better to have a separate material function for the specific thing you need it for.
That said, if an input/output and the nodes between them are not connected to other input/outputs those nodes will not be called.

So if the material function has 3 inputs (X, Y, Z), and three outputs (X, Y, Z), and the nodes between them do not mix and match. (so all nodes from X do not combine with Y or Z) you could make one material function out of it.

On another unrelated note, UE4 is a physically based renderer (PBR), meaning that Diffuse is outdated, and should be replaced with Albedo.
Specular map is almost never needed, and should be replaced by a roughness map for accurate realistic light reflective values.
Loads of documentation on PBR: Physically Based Rendering Encyclopedia - Google Docs

Hi Luos, thanks for the reply and the tips about Albedo & roughness, this helps a lot moving forward :slight_smile: