Ever since I first wrote about creating object outlines in Unreal Engine 4 I have wondered if it was possible to render them as soft outlines instead of harsh binary lines. A good example of soft outlines can be found in Valve’s games like Left 4 Dead or CS:GO.
There wasn’t an easy way to blur the pixels at the time nor a decent way to down-sample the render target containing the outlined objects in order to make this blur operation cheaper. Overall it came to be too costly to come with a decent solution and so I stuck with the binary outlines you may have been in several of my earlier posts. Recently I decided to revisit this issue by doing a quick experiment using a modified version of SpiralBlur, a material node that’s available in Unreal Engine 4, that is using some custom (HLSL) shader code to blur the pixels using a spiral blur method.
Looks pretty decent, right? The effect is more expensive than the binary outlines since we perform several blur steps in the SpiralBlur-node to get to look decently smooth. Without going the custom engine route there is no way to downsample the post-process step where we sample and blur the information from the Custom Depth buffer. Later in this post I will talk about performance of the effect itself.
The Material Graph
Unfortunately I couldn’t find any official UE4 documentation on the Spiral Blur node, there is a wiki page on how to use the material node. The built-in implementation takes the scene textures and over several iterations creates….a spiral blur. The default settings are at about 128 iterations, which is pretty heavy! I’ve used this node as a reference to create my own, which samples the Custom Depth buffer instead of the scene color.
The node graph for it is reasonably simple and most of the logic happens inside the custom node which I added as a code sample below.
Performance was recorded on a 850M mobile GPU at 1280×720 with ~1.5ms measured and on my GTX 980 Ti it runs at 1920×1080 with 0.8ms for the post process material. It’s heavily depending on the amount of iterations in the spiral blur. You will want to keep the DistanceSteps and RadialSteps as low as possible while maintaining a smooth edge. In the demo I settled on 4 DistanceSteps and 8 RadialSteps which is 32 iterations.
To conclude, the answer is yes! It’s entirely possible to make soft outlines in Unreal Engine 4. I imagine there may be more efficient ways of blurring the custom depth buffer to get similar results, I simply leveraged the available shader code to quickly get to a proof of concept. It’s important to note that being far away from the object with an outline can make it look slightly less smooth, a thinner outline helps and is a matter of tweaking.