Custom shader code in Unreal Engine — Part 1: Setup and Configuration | by biq | Medium
I followed above instruction to allow Custom node in the material graph to import the shader script located within the project directory.
I have created a plugin within a project, and created ush shader scripts within the plugin.
In the details panel of the Custom node, there is “Include file paths” section where I can add the include file path.
Using this feature, I can directly define a function within the ush file without wrapping it with a struct, and use it within the Custom node’s code.
Bellow is what my ush file and the code in custom node is like roughly.
ush file
float3 myfunc(in float2 uv) {
...
}
code in the Custom Node
return myfunc(uv);
Then, I added additional outputs to the node.
Say, I added output parmeter named vec
.
ush file
float3 myfunc(in float2 uv, out float3 vec) {
...
}
code in the Custom Node
return myfunc(uv, vec);
If I do not connect the output value vec
to any other node, the code runs fine.
However if I connect the value of vec
to use it, following error occurs.
error: redifinition of myfunc
The solution I found is, stop using the “Include file paths” section in the node’s detail panel,
and just use the old way of import.
ush file
struct MyStruct {
float3 myfunc(in float2 uv, out float3 vec) {
...
}
}
code in the Custom Node
#inlucde "path/to/some.ush"
MyStruct s;
return s.myfunc(uv, vec);
It seems there is some bug with “Include file paths”.
I think it is copy and pasting the content of the included file multiple times if additional output parameter is added.