Its just a static mesh based off the GeneratedMeshComponent class (which is itself mostly taken from CustomMeshComponent). That part is really nothing fancy, although it did take some work to figure out how the triangles should connect together in smooth way and figuring out UV mapping (thanks to dmas.
The algorithm for generating the heightmap is one I just I rolled myself - it starts with a flat map, then generates number of hills and vallleys by picking a random tile then doing random walk bumping up the terrain by a given constant amount until the desired number of tiles are visited (keeping track of which tiles have already been visited). Next the entire map is smoothed out with a 2D convolution (basically averaging around each tile, the kernel is really basic as its weights all surrouding tiles equally). It repeats this number of times to “spread” the hills and valleys out on the map. This sort of simulates an “eroson” effect … Lastly I just add some random noise and smooth it out again with a smaller kernel and less iterations to given it bit of a “bumpy” appearance. Most parameters are user settable through Blueprint now.
Unfortunately UE4 landscapes can’t be generated or changed at runtime, at least last I checked. A big reason is I think is because they take advantage of some type of prebaked lighting and some advanced shader techniques which can make them look really cool. Especially as you start to add different materials to the landscape, compiling all the shaders can take a while. I think last time i tired 4 different materials in a UE4 landscape, the shader compilation took something like 30 minutes …
What needs to be done:
- Optmize the collision logic somehow to allow larger maps (either by breaking up the meshes/actors, or rolling own routine)
- Set materials on a per tile basis, also if possibly do a smooth transition somehow (not really sure how that part works, I think the UE4 landscape uses some custom shader routines which weights the materials somehow, which is why the shader compilaiton takes so long…)
- Be able to change the height dynamically in an efficient manner (i.e, not regenerating the whole mesh…)