Blurring the edge: Blending Meshes with terrain in UE4

July 29, 2017
Posted in 2017
July 29, 2017 Jori

Hello everyone! There were a lot of questions on twitter about the Terrain Blending material I made for RITE of ILK in Unreal Engine 4.

Because of that, we decided to write out and post a quick blogpost explaining its magical ways! The material allows for a static mesh to automatically blend with the terrain material when it intersects with the terrain.


Static Image

(Figure 01: Material blending in action!)


Before I get going, I want to give credit to Artstation user Victor A.who created a free for download, awesome material example, for anyone that is interested to see how the technique works.



(Figure 02: on the right you can easily see the edge where the mesh is stuck into the mud.

The Basics
We use Unreal Engine 4 and the effect is created by using the “DistanceToNearestSurface” node. This will return a black and white mask from your model that is black at intersecting points with other models and white where it doesn’t intersect. By using this value to lerp the stone texture with the mud texture, you gain a smooth transition from one texture to the other.


(Figure 03: The material nodes that create the material blend


We distorted the DistanceToNearestSurface value by using a perlin noise to create a more splashy mask, rather than a straight up gradient.


image(Figure 04: pixel depth dither)

Blurring the edges
Although the transition is smooth, you could opt to use a dither along the edge to further blur the edge with the terrain. I use the same mask generated by the DistanceToNearestSurface node and run it through an if statement so that it will dither everything that is not pure white.

And that is all! It’s not that difficult and the results are amazing!

As a side note you will have to make sure the mesh you are using this technique on has “Affect Distance Field” disabled, otherwise it will generate the distance field on itself. It is also a sound idea to put these nodes into a material function so you could easily drop this functionality into any material you might want. 😀

Happy building and we would love to see some of your awesome results!

Make sure to check out our twitter and facebook for other constant updates and development issues!



Jori Kamp
Game Designer at Turtleneck Studios

, , , , ,