The Material function

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.

Getting ready

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 ...

Get Unreal Engine 4 Scripting with C++ Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.