Call Material function from Material Custom node

Hello there
Does anyone knows if it’s possible to call a Material function from the HLSL code of a Material custom node ?
I’m not able to find this anywhere :worried:
Thanks

1 Like

Does this ringa bell to someone ? I’m currently rewriting the ALL huge thing in HLSL while call a Material function from a Material custom node would really help.

Use this:

Just don’t use the #ifndef stuff. 4.26

Hi
Thanks for your reply but I fear the case I have is more specific (unless I’m missing something)
Here is a good sample of what I’m trying to achieve:
Given one input base color (blue) and 1 input opacity value (0.99) I want to set original OR modified values based on a Collection Param > 0.5. See Screenshot below.


The thing is, having a look at the HLSL compiled version, the basecolor and opacity are not assigned and the custome node is called in the void:

MaterialFloat3 Local0 = lerp(MaterialFloat3(0.00000000, 0.00000000, 0.00000000), Material.VectorExpressions[1].rgb, MaterialFloat(Material.ScalarExpressions[0].x));
MaterialFloat4 Local1 = MaterialCollection0.Vectors[0];
MaterialFloat Local2 = 0.0f;
MaterialFloat Local3 = 0.0f;
MaterialFloat Local4 = CustomExpression0(Parameters, Local1.g, (MaterialFloat3(0.00000000, 0.00000000, 1.00000000) + MaterialFloat3(1.00000000, 0.00000000, 0.00000000)), (0.99000001 / 4.00000000), MaterialFloat3(0.00000000, 0.00000000, 1.00000000), 0.99000001, Local2, Local3);

	PixelMaterialInputs.EmissiveColor = Local0;
	PixelMaterialInputs.Opacity = Local3;
	PixelMaterialInputs.OpacityMask = 1.00000000;
	PixelMaterialInputs.BaseColor = Local2;

with

MaterialFloat CustomExpression0(FMaterialPixelParameters Parameters, MaterialFloat Some_Collection_Param, MaterialFloat3 InComputedBaseColor, MaterialFloat InComputedOpacity, MaterialFloat3 InOriginalBaseColor, MaterialFloat InOriginalOpacity, inout MaterialFloat OutBaseColor, inout MaterialFloat OutOpacity)
{
[branch]
	if (Some_Collection_Param > 0.5)
	{
		OutBaseColor = InComputedBaseColor;
		OutOpacity = InComputedOpacity;
	}
	else
	{
		OutBaseColor = InOriginalBaseColor;
		OutOpacity = InOriginalOpacity;
	}
	return 0;
}

Do you know if there would be a way to make this work ?
Thanks

What’s wrong with just plugging the same values of the function into the Custom and re-wrtiting the function within the custom?

While technically possible to rewrite within the custom, the initial material blueprint is HUGE. It contains a lot of material functions that I have to rewrite. Among them, the Texture variation, for example.
It’s a huge task to rewrite this very complex shader in HLSL so I’m looking for a more productive way to achieve this.

… but the engine does do it for you?

Can you read the hlsl of the material and copy paste the relevant sections?

Better yet, you can make it into a .usf and then call the Usf in the custom node.
(Granted I do not remember exactly how that’s done, I know I did do it once).

Yes I can do that using the Window > Shader Code > HLSL code menu item from the material blueprint but to give you and idea, the current version contains ~= 500 MaterialFloat* locals and I still need to provide HLSL readability to tech artists, static bool controls and variable change abilities For now, the custom node I’m writting has 15 inputs.
Picking relevant functions as you suggested makes sense but I fear not with a so big shader material.
The ability to call a Material function from HLSL would be awesome.

4 Likes