[UE5] 在Custom 节点中自定义函数
在Custom节点中直接定义函数是会报错的
float MyFunction(float A, float B)
{
return A + B;
}
return MyFunction(Input0, Input1);
error: function definition is not allowed here.
原因是我们写的custom代码最终是被生成到一个临时的Material.ush文件中。
需要改成如下这样:
struct CustomFunctions // 任何名字都可以
{
float test(float x)
{
return x;
}
};
CustomFunctions CF;
float4 fragColor = CF.test(0);
return fragColor;
参考:
Can't define function in hlsl on custom shader node. - #2 by martinortiz - Programming & Scripting - Epic Developer Community Forums