Procedural Terrain Material (Unreal Engine 4)
2014-08-23
You can read or watch many tutorials on how to texture a terrain using layer blends. Although that is a valid way to texture a terrain, I think that most of the work you put into texturing the terrain is redundant.
Take the classical grass, rock and sand terrain material. The flats always get the grass, the rock goes on the slopes and the sand goes on the beach. This would be something similar to this:
But if this rule holds up in your scene, why not encode it in the terrain shader?
Here is how I did it:
The first is the slope detection is done with the material function SlopeBlend. Originally I used the World_Align_Blend, as describes in the Stylized Landscape. But I found that offered little control, over the blend smoothness, the arguments where confusing and the function was way to complicated. So I elected to write my own as a very simple one:
This function is quite simple. We compare the current normal with the up vector (0, 0, 1). This is done using the dot product. The dot product return 1 for equality and 0 when it is perpendicular. To achieve the desired blend we just scale the out desired range to 0 - 1. And this is how the slope looks:
The HeightBlend could also be done with HeightLerp, but again, I opted to write a simpler function:
The actual hight is moved by the height parameter so that the result is 0 at the desired height. The sharpness then spreads the 0-1 range over the given value. The result is that the values are blended over the given height.
And this is the result of the terrain shader, no blend maps, no ugly watter: