Imagine you’re working on a scene in Unreal Engine 5 and you want certain objects to stand out. One way to achieve this is with a post-process outline shader. In this tutorial, we’ll build one from scratch using Unreal Engine 5’s Material Editor and then apply it to the entire level.
You’ll learn how to sample scene depth, detect object edges, control outline thickness and intensity, choose custom colors, and apply the finished effect across your entire level for clean, stylized visuals.
Creating the Post-Process Material
We’ll start by creating the material that will contain our outline effect
In the Content Browser, right-click and choose Material
Name the material something like M_OutlineShader
Double-click to open the material and look at the Material Domain in the Details panel
By default, it will be set to Surface but we need to change it to Post Process
This tells Unreal that the material isn’t going to be applied directly to the surface of an object
Instead, it will process the rendered image after the scene has been drawn
Now we can start building the outline
Creating the Outline Thickness
The first thing we need is control over how thick the outline will be
Hold down the S-key and left-click in the Material Editor to create a Scalar Parameter
Rename it to Outline Thickness
Set its default value to 1.0
Next, right-click and search for a Blur Sample Offsets
Connect the Outline Thickness to this new node
Next, search for a Sample Scene Depth
We’ll use depth information from the scene to determine where the edges of objects are
We need several depth samples, each looking at a slightly different location around the current pixel
Create four Scene Depth expressions by using CTRL + D to duplicate the node
Each one should use a Pixel Offset so that we’re sampling pixels around the current screen position rather than repeatedly sampling the exact same location
Connect the Blur Sample Offset 0.1 pin to the Pixel Offset of the first Sample Scene Depth node
Connect the Blur Sample Offset 1.0 pin to the Pixel Offset of the second Sample Scene Depth node
Connect the Blur Sample Offset 0.-1 pin to the Pixel Offset of the third Sample Scene Depth node
Connect the Blur Sample Offset -1.0 pin to the Pixel Offset of the fourth Sample Scene Depth node
The idea is simple – we’re looking at the depth immediately around the current pixel
If those neighboring pixels have significantly different depth values, we’re probably sitting near an object’s edge
Select these six nodes and use the C-key to add a Comment
Rename the Comment to Outline Thickness
Comparing the Depth Samples
Now we need to combine those samples
Hold down the A-key and add three add nodes to combine the depth values from the neighboring pixels
Connect the Depth Using Pixel Offset pin of the first Sample Scene Depth to the A pin of the first Add node
Connect the Depth Using Pixel Offset pin of the second Sample Scene Depth to the B pin of the first Add node
Connect the Depth Using Pixel Offset pin of the third Sample Scene Depth to the A pin of the second Add node
Connect the Depth Using Pixel Offset pin of the fourth Sample Scene Depth to the B pin of the second Add node
Connect the first Add node to the A pin of the third Add node
Connect the second Add node to the B pin of the third Add node
The goal is to create a value representing the difference between the surrounding depth samples and the current depth
Add a fourth Add node and connect the third Add node to the B pin
Hold down the 2-key and left-click to add a Vector 2 node
Connect this Vector 2 node to the Pixel Offset pin of a fifth Sample Scene Depth node
Hold down the M-key to add a Multiply node
Connect the Depth Using Pixel Offset pin to the A pin of the Multiply node
Change the B Value to -4.0
Connect the Multiply node to the A pin of the fourth Add node
Search for an Absolute node (Abs)
Add a second Multiply node
Connect the fourth Add node to the Absolute node
Connect the Absolute node to the A pin of the second Multiply node
At this point, we have the foundation of our outline mask
Select these nine nodes and use the C-key to add a Comment
Rename the Comment to Depth Samples
Controlling the Outline Strength
The raw edge detection can be quite subtle, so let’s give ourselves another parameter to control its strength
Create another Scalar Parameter and call it Outline Amount
Set its default value to 0.1
Connect this Parameter to the B pin of the second Multiply node
Hold down the E-key to add a Power node
Connect the second Multiply node to the Base pin of the Power node
Next, create another Scalar Parameter and call it Outline Power
Change the Value to 1.0
Connect this Parameter to the Exp pin of the Power node
After the Power node, add a Saturate node and connect the Power node
This clamps the resulting value between 0 and 1, giving us a clean mask
Select these four nodes and use the C-key to add a Comment
Rename the Comment to Outline Strength
Improving the Depth Calculation
Now we can use the scene depth itself to help normalize the result
Add a third Multiply node and connect the Saturate node to the B pin
Search for a Scene Depth node
Hold down the D-key to add a Divide node
Connect the Scene Depth node to the A pin
Change the value to a large value such as 8000
Hold down the O-key to add a 1 Minus node
This will invert the result
Connect the Divide node to the 1 Minus node
This will multiply this value with the outline mask we created earlier
Add a second Saturate node and connect the 1 Minus to it
Connect this second Saturate node to the A pin of the third Multiply node
The resulting value will act as our final outline mask – pixels near detected depth discontinuities will approach 1, while areas without an edge will approach 0
Select these five nodes and use the C-key to add a Comment
Rename the Comment to Depth Calculation
Choosing the Outline Color
Now that we have an outline mask, we need to decide what color the outline should be
Add a fourth Multiply node
Connect the third Multiple node to the A pin
Search for a Vector Parameter and rename it to Outline Color
Select these two nodes and use the C-key to add a Comment
Rename the Comment to Outline Color
Combining the Outline With the Scene
We don’t want to replace the entire scene with our outline color
We only want to place the outline over the existing image
Hold down the L-key to add a Lerp node
Connect the Outline Color to the B pin of the Lerp Node
Connect the fourth Multiply node to the Alpha pin
Search for a Scene Texture node
Change the Scene Texture ID to Post Process Input 0
This gives us the scene as it currently exists before our post-process material modifies it
Add a Component Mask
Connect the Color pin of the Scene Texture to the Mask
Select the Mask node and activate the Blue value in the Details panel
Connect the Mask to the A pin of the Lerp node
Select these three nodes and use the C-key to add a Comment
Rename the Comment to Combine Outline and Scene
Connect the Lerp result to the material’s Emissive Color output
At this point, the material is ready
Applying the Shader to the Level
Save and apply the material
Now we need to tell Unreal to use it as a post-process effect
Under the Quick Add menu, search for Post Process Volume
Select the volume and enable Infinite Extent (Unbound)
This is important because it makes the post-process volume affect the entire level rather than only the area physically covered by the volume
Search for Materials and open the Post Process Materials
Add an Array and then Asset Reference
Select your Material in the Content Browser and then click on the left-pointing arrow icon next to the Asset Reference
Once the material is assigned, the shader should immediately begin processing the scene
Adjusting the Effect
If everything is connected correctly, you should now see an outline around objects in your scene
The nice thing about building the shader with parameters is that we can adjust its appearance without rebuilding the material
Right-click on your Material and make a Material Instance
Don’t forget to change the Material to the Material Instance for your Post Process
If you double-click to open the Material Instance, you will see four Parameters that can now be easily changed
CONCLUSION You’ve now built a flexible outline shader from scratch and applied it through a post-process volume in Unreal Engine 5. This technique provides a useful foundation for interaction indicators, selection effects, and stylized rendering in your projects.