As always, modularity is one of the best practices in programming. Material shaders are no exception: it is far better if your shader blocks are modular, and can be boxed out and identified as named functions. This way, not only are your shader blocks clearer, but they can also be reused in multiple Material shaders, or even exported to your local UE4 library for future use in other projects.
A reusable or repeatable block of shader functionality can be factored out of your custom material shader program. In this example, we'll write a simple function series—Square
, Square2
, Square3
, and Square4
—that squares input values. Get ready to perform the work in this recipe by opening a UE4 project and navigating to the Content Browser.