In this lesson, you will learn how to use the Shader Complexity view mode to identify expensive GPU operations and refactor your material graphs for better frame times.
Visualizing the Cost
When you build complex materials, especially those utilizing layering or procedural math, you can easily exceed your frame budget without realizing it. To see where your GPU is struggling, navigate to the viewport's View Mode menu (top-left) and select Optimization Viewmodes > Shader Complexity.
In this view, Unreal Engine color-codes your scene based on the number of shader instructions being executed:
- Green: Budget-friendly, standard material complexity.
- Red to White: Over budget; these areas are performing too many calculations per pixel.
Refactoring for Efficiency
Once you identify an "expensive" asset in the viewport, open its Material Graph. Most performance hits come from "expensive" nodes like World Position Offset, Parallax Occlusion Mapping, or excessive Texture Sample counts.
A common culprit is redundant math or branching. For example, if you are performing a calculation inside a material that doesn't change every frame, move that logic to the CPU or bake it into a Texture. If you are using a complex math function, look for ways to simplify the operations. Instead of performing a high-cost calculation, consider if a cheaper approximation will suffice.
For instance, replace costly Power nodes with Multiply operations where possible:
// Avoid this:
float result = pow(input, 2.0);
// Use this instead:
float result = input * input;
Another frequent offender is excessive texture fetches. If you have four different textures that are mostly constant, try packing them into the R, G, B, and A channels of a single texture. This reduces your Texture Sample count from four to one, significantly lowering the instruction cost for that material.
By regularly checking this view mode during the polish phase, you ensure that your visual fidelity doesn't come at the cost of a stuttering framerate.
Key Takeaway: Use the Shader Complexity view mode to target "red" zones and optimize your material graph by reducing instruction counts, consolidating texture lookups, and replacing expensive math functions with cheaper alternatives.