[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

相关推荐
zhangzhangkeji17 小时前
UE5 蓝图-游老师-18-蓝图的封装,19-继承,20-多态:父类中的变量,函数、事件,分发器,实现的接口,可以被子类直接使用,也可以被子类重写重定义
ue5
每天回答3个问题21 小时前
UE教程|unlua知识地图
ue5·腾讯·lua5.4
皇族崛起2 天前
【3D标注】- Unreal Engine 5.7 与 Python 交互基础
python·3d·ue5
一眼万里*e2 天前
UE中的UObject创建,销毁
ue5
吴梓穆5 天前
UE5 Perforce使用完全手册
ue5
zhangzhangkeji5 天前
UE5 蓝图-游老师-13-事件、函数、宏、事件分发器:在自定义蓝图(包括 UI 控件蓝图)中就可以创建事件分发器
ue5
Zhichao_975 天前
【UE5.3】小白人动画重定向
ue5
Zhichao_975 天前
【UE5.3】为人形角色建立Contrl Rig
ue5
竹欣6 天前
UE杂项(Mass 崩溃排查)
ue5
__Ryan6 天前
BlueprintImplementableEvent和BlueprintNativeEvent
c++·ue5·unreal engine