Custom Material Expressions
- Custom Material Expression: write custom HLSL operating on arbitrary inputs; output the result. Insert from Custom category or right-click search.
- Properties: Code (shader code; see warnings); Output Type; Description (title bar text); Inputs array (Input Name = pin label and HLSL identifier); Additional Outputs (Output Name + Output Type); Additional Defines (Define Name + Define Value); Include File Paths (include shader code outside common paths UE already provides).
- Usage: add/name Inputs; paste HLSL in Code — either a full function body with return, or a simple expression (e.g. Input.bgr); set OutputType.
- Example: blur Texture Object from Scalar Parameter using Texture2DSample loops; divide by 2*(2*r)+1; return blur.
Known Issues
Input Arguments Are Function-Local
- Custom expressions always have a return value because they are wrapped inside another function. All input arguments are declared as parameters of that outer function → function-local scope.
- Structures with member functions cannot access those parameters; copy parameters by hand into the struct if member functions need them. Example that fails: InnerStruct::Run calling Texture2DSample(Tex, TexSampler, UV) — Tex/UV not accessible inside InnerStruct.
Syntax Errors When Using HLSLcc Compiler
- Some backends using older HLSLcc report syntax errors on HLSL types such as vector and matrix. Be explicit: float4 / float4x4. Bugs being fixed; effort moving to DirectXShaderCompiler (DXC).
Warnings
- Using the custom node prevents constant folding and may use significantly more instructions than an equivalent version done with built-in nodes. Constant folding: e.g. Sin > Mul by parameter > Add can collapse to a single instruction when inputs are constant for the whole draw call. Unreal cannot collapse anything in a custom node → less efficient shaders. Best: only use Custom when it gives access to functionality not possible with existing nodes.
- Shader code written in a custom node must be valid HLSL.