Custom Shader Code in Unreal Engine — Part 2: Modularization
Intro
This is the second installment of the UE4 custom shader development series, where we have a look at how to use custom shader code in your materials, as well as build and reference a resuable codebase. In the first part we discussed setting up the environment to house our shaders in a plugin.
Preface
Custom shader code will be embedded in larger framework, autogenerated by Unreal Engine’s shader compiler. The way this is presented to the user of the engine’s material editor, is the Custom Expression node. This node enables you to write HLSL code and access pretty much any function and variable setup in the shader framework.
Material Setup
Custom Expression
The most basic setup to get things going, is creating a new material and adding a Custom Expression node. The customized HLSL we start off with, simply returns a constant RGB color. Why we use a return statement here, will be explained in a minute.