Download

4.26 Documentation on new Custom Expression features, multiple outputs, material attributes

The new custom expression feature that added multiple outputs and a material attributes output type seems incredibly useful for more efficient shader code. I’ve been looking around, even in the engine source, and can’t find any information on how to use it - how do you return the multiple outputs in the format it wants or define and modify the FMaterialAttributes struct to be returned? I’ve tried messing around with it but it keeps returning {0, 0, 0, 0} for all the extra outputs other than the first return output. The first return output is as intended.

An example of the custom expr code is


#include ".../Unreal Projects/ShaderTests/Content/A.usf" return 0;

I was able to identify the solution for FMaterialAttributes. A sample .usf would be as such for reference (doesnt do anything but gets the point across):


# pragma once

struct shader {
FMaterialAttributes main(
float4 t0,
float4 t1,
float4 t2,
float4 t3)
{
FMaterialAttributes MA;
float4 o0,o1,o2;
o1.w = 0;
o2.x = 1;
o2.z = 0.5;
MA.BaseColor = o0.xyz;
MA.OpacityMask = o0.w;
MA.Metallic = o2.x;
MA.Roughness = 1 - o0.w;
return MA;
}
};

shader s;

return s.main(t0, t1, t2, t3);