Home > Sample essays > Unreal Engine 4 Procedural Terrain Generator: Create Realistic Landscapes in Minutes

Essay: Unreal Engine 4 Procedural Terrain Generator: Create Realistic Landscapes in Minutes

Essay details and download:

  • Subject area(s): Sample essays
  • Reading time: 11 minutes
  • Price: Free download
  • Published: 1 April 2019*
  • Last Modified: 23 July 2024
  • File format: Text
  • Words: 3,143 (approx)
  • Number of pages: 13 (approx)

Text preview of this essay:

This page of the essay has 3,143 words.



The project was to build a procedural terrain generator using the game engine Unreal Engine 4 (Epic Games, 2016). The main objective of this project would be to save the time of game designers to construct a terrain for a game. Furthermore the main aspect of this terrain generator is that it use the procedural generation to create data, in fact the level geometry is entirely created through an algorithm instead of being created manually by a 3D designer.

The generator allows users to create and customize the terrain through the parameters that regulate the behaviour of the algorithms of the procedural generation. In this way it was possible to meet the needs of all the users which will use this project.

This project was realized by combining the use of scripts in C++ and Unreal engine's blueprints, a visual node-based scripting interface. The blueprints allow users to change the algorithms of the procedural generation without requiring users to change or write any line of code. Consequently, in order to use this tool, it is not required any knowledge of C++.

The project could be subject to further improvements, for example would be possible to implement a procedural forest on top of the terrain created or would be ideal to add a custom shader that allows the terrain to have a more realistic look.

All the project objectives have been achieved. An UI has been added in the tool which allow users to modify the terrain through a wide range of parameters and furthermore, it contains some default examples showing the different type of terrain that could be created. Lastly user can save locally, in the PC where the project is launched, the parameters of the terrains created.

How to access the project

URL: https://vimeo.com/162823122

In order to run the simulation normally, it is necessary to open the project with Unreal Engine 4.8 (or higher) and press Launch. Although, it could be possible to modify the behaviour of the project accessing the main blueprint ProceduralTerrainGeneratorAA. The UI in the project briefly explains how the project works and how it is possible to create new procedurally generated terrain.

Table of Contents

Summary 1

How to access the project 1

Introduction 3

Why procedural generation? 3

Benefits of the project 3

Methodologies 4

Noise Implementation 4

Perlin Noise 5

UI Interface 6

Saving the Terrain 7

Results 7

Building the Terrain 7

Communication between Blueprints and C++ 10

Discussion 11

First Procedural Terrain Generator 11

Suitable for Everyone 11

Conclusion 12

References 13

Appendix 1: Project Proposal 14

Appendix 2: Summary of Research Report 21

Appendix 3: Initial Project Requirements 22

Appendix 4: Screenshots of the Blueprints 23

Appendix 5: Project Resources & References 25

Table of Contents

Introduction

The project was to build a procedural terrain generator using the game engine Unreal Engine 4. Before starting any development on this project, a research has been carried out to understand how was possible to create a tool like this using Unreal Engine. Few months before the start of this project, a new version of Unreal Engine 4.8 was released, containing for the first time the Procedural Mesh Component (Epic Games, 2016) which allows users to create procedural meshes at runtime using C++ and blueprints. As a consequence, it has been decided to research more in-depth how this component worked and how was possible to build a procedural terrain at runtime.

Why procedural generation?

It was decided to use the procedural generation method because nowadays it is frequently used in order to create unique experiences and random features on each playthrough. The main advantage of procedural generation is that it requires small file sizes in order to produce large amount of data. Furthermore, it is useful because game designers can work over an algorithm to generate all the content necessary, instead of creating all the details of a game by hand.  This project was focused on using a procedural algorithm that would have created a terrain, ready for an in-game implementation.

Benefits of the project

This project offers to the users the possibility to implement into their games or projects, a fully customizable procedurally generated terrain. Since it will create a terrain through a procedural algorithm, game designers will not need to spend any time on the creation of a terrain for their games. Moreover, at the moment there are no procedural terrain generator available on the Unreal Engine’s marketplace (Epic Games, 2016), so if further improvements will be done to this tool, it could be the first plug-in with this functionality.

Methodologies

The research initially went into looking if it was possible to develop a tool, in Unreal Engine, that would have allowed users to generate a procedural terrain at runtime. As shown from the research done, few months before starting the development on this project, the new version of Unreal Engine 4.8 was released, containing for the first time the Procedural Mesh Component. This Procedural Mesh Component was responsible for creating any procedural mesh at runtime, so it was necessary to understand its behaviour in order to create the procedural terrain. The research has shown that the main feature of any procedural content is the noise. A noise function takes an integer as a parameter, known also as seed, and return random values based on the parameter chosen. Moreover, if the same parameters are chosen again the noise function will always return the same value. Subsequently, the research went into finding a way to allow users to limit the randomness given from the procedural algorithms. This has been possible connecting all the parameters of the noise algorithms to the UI (User Interface) of the project, through the use of the blueprints in the project. As a result, users could create and customize their own terrain at runtime, simply modifying the parameters in the UI of the tool.  

Noise Implementation

In order to implement the noise into the project it was required to implement a free plug-in that generates a fast version of Simplex noise in 1D, 2D, 3D and in 4D (DevDav, 2015). Implementing this plug-in, it was possible to access the scripts in C++ through the use of blueprints within the Unreal Editor. In fact, the first prototype of this project already implemented all the essential functions, but it was necessary to improve the quality of the terrain generated. It was decided to extend the research about the behaviour of the noise functions, so it would be possible to modify the algorithms and implement new parameters in order to improve the quality of the noise generated. Since there are not many projects like this, it has been hard to find a solution to this problem.

Perlin Noise

Investigating the topics covered in the research report, it was possible to find a solution, in fact, it was necessary to add to the procedural algorithm two new parameters: the number of octaves and the persistence. By adding these two parameters the terrain was not anymore created by a Simplex noise, but would be based on multiple coherent-noise functions that added together form the Perlin Noise (Libnoise, 2003). Each of these functions are called octaves and each octave increase the amount of details of Perlin Noise because each octave has double the frequency of the previous octave.

Furthermore, the persistence determines how quickly the amplitudes diminish for each successive octaves, in fact the amplitude of each successive octave is equal to the persistence value and the amplitude value of the previous octave.

   

The sum of these octaves and the persistence function generate a Perlin noise function that gives to the procedural terrain a great amount of details (depending on the number of octaves). The Simplex noise previously used to generate the terrain resulted in a terrain too simple and with flat mountains, because the function generated did not use the number of octaves and the persistence as its parameters.

UI Interface

In order to allow users to customise their own terrain, it was required to build an UI interface to let designers change the parameters of the material at runtime, without accessing the blueprints in the editor. The first prototype could generate just one terrain per time, so after the first one was generate, it was necessary to quit the application and access to the blueprints in the editor to change the parameters of the terrain. Many modifications had to be done to the main blueprints of the project ProceduralTerrainGeneratorAA in order to include all the new functionalities and connect all of them to the UI of the tool.

Saving the Terrain

Following the feedbacks received afterwards the prototype session, the research went into looking a way to save the model and exporting the whole terrain as an FBX file, so it could have been ready for an implementation in any other software for 3D modelling. Unfortunately, currently the new Procedural Mesh Component derives from the UMeshComponent and not from the UStaticMeshComponent so it does not contain an UStaticMesh asset that would allow the exporting as FBX file. The way found to overcome this problem was to implement a GameSaveObject (Epic Games, 2016), which would have been responsible for saving to the hard drive all the parameters of a terrain generated. Even if the stretch goal of exporting the terrains has not been succeeded, it would be possible to load a terrain previously saved locally by the user.  

Results

The main work that has been done on this project, mainly concerned the possibility to create a procedural terrain at runtime and the creation of a UI to access all the features responsible for the creation of the ground. To solve the problems related to them was necessary to thoroughly investigate the documentation provided by Unreal Engine.

Building the Terrain

Converting the noise functions generated into a terrain mesh it has not been an easy job. Many parameters had to be taken into consideration and since the main feature of the procedural algorithms is their randomness, was not easy to predict their results. The first step necessary was to implement the marching cubes algorithm in the project. In many resources that have been investigated the implementation of the marching cubes algorithm was essential, because it was necessary in order to create a polygonal surface representation of the noise functions generated.  

The terrain surface can be entirely generated by a single function called density (Geiss, R., 2007). The density function is based on different parameters: number of octaves, persistence, frequency and position in the 3D space. Although, to add more details to the terrain, it has been decided to use two different noise functions which would sum up together in order to increase the level of details of the ground. The function will look like this:

float Density = UGenerateNoise::GenerateOctaveSimplexNoise3D(NumOctaves1, Persistence1, Frequency, (tXPos + x) / 2.0f, (tYPos + y) / 3.0f, tZPos + z) ;

Density += UGenerateNoise::GenerateOctaveSimplexNoise3D(NumOctaves2, Persistence2, Frequency * 2, (tXPos + x) / 1.0f, (tYPos + y) / 1.5f, tZPos + z); .  (1)

The result of this noise function will be a floating-point value for each point in the 3D space concerned. Since just the positive values were necessary in order to build the terrain, all the negative values have to be ignored. This has been possible simply using a default parameter that allow users to tell to the function what values should be ignored if they are situated under a certain value of Y in the 3D space. This would result in a much faster computing calculation of the floating point because almost half of the values produced by the density function were then ignored.

The construction of the polygonal mesh then would be based on the blocks generated from the floating points resulted from the density function. In fact, these “blocks” of terrain, called voxels, will then represent the surface of the procedurally generated mesh. Then was necessary to use the marching cubes algorithm in order to “cut” the voxels and generate the correct polygons for each voxel created. Determining which edges of the voxel intersect the terrain, it was possible to create triangular patches that divide the cubes in regions inside and outside the terrain. Connecting all the patches from all the voxels, it is possible to obtain a surface representation of the terrain.

In this project a lookup table for the marching cubes algorithm has been used in order to reduce the computer calculation and to generate large blocks of complex procedural terrain.

Another problem encountered while creating the terrain was the material that would be applied to it. In order to fulfil the requirements of this project, was not necessary just to create the terrain but also its look would have to satisfy the expectation of the users. Consequently, a dynamic material has been applied to the terrain in order to change its look and to blend different types of material depending on the height and the slope of the terrain. This has been possible by creating a material that would be able to access the coordinates of the world position were the material was being applied. The only way to get this information from the terrain, as investigated from the Unreal Engine documentation, was by using the two functions VertexNormalWS (to access the information regarding the slope of the terrain) and the Absolute World Position (to get the height of the terrain).

Depending on the information retrieved from the terrain, the dynamic material would apply a different material based on the height and the steepness of the ground. In fact, the dynamic material contains four sub-materials that are applied and blended together depending on the parameters chosen by the users. The four materials inserted represent some ground examples like sand, grass, rock and ice. In order to allow the users to access easily to this values, an instance of the dynamic material has been created, where users can modify just the values, instead of modifying the functions of each sub-material. A more in-depth explanation of how the dynamic material works could be found in Appendix 4.

Communication between Blueprints and C++

Further investigation went into developing a project in Unreal Engine which used a combination of code in C++ and blueprints. Since one of the main goal of this project was to allow users to modify and customise the procedural terrain based on their necessities, using blueprints was the only way to achieve this. In fact, it has been possible to create a special blueprint, called Widget, which allows designers to build a User Interface and then connect the elements of the UI, e.g. buttons or sliders, to any blueprints in the project. This has proved to be a really good way to understand how the communication between blueprints work, that is not as simple as scripting in C++.

In Widgets, is possible to create a custom event that could be triggered every time an event in the UI occur, e.g. a button pressed or a slider moved. This custom event is called Event Dispatcher and is the only option to allow the communication between blueprints within the same project.

Discussion

The main purpose of this project was to implement a procedurally generated terrain at runtime in any Unreal Engine’s project. This would save the time of game designers and it would allow users to create huge maps without spending any time on the creation of the terrain. However, users could use this tool as a good source for learning how the new Procedural Mesh Component works since there are not many other projects available which use the procedural generation to create content.

Even if the main objective of this project was to procedurally generate a terrain, the algorithms in the source code could be accessed and modified from the users in order to create procedurally any kind of data necessary. In addition, since it is possible to adjust the parameters of the algorithms at runtime, this tool will show clearly, through the shape and the details of the terrain, the behaviour and the differences between each noise function generated.

If users have a basic understanding of the Perlin noise and its potential, it will not be difficult to change the parameters that govern the noise in order to achieve the desired result. In the future, a brief explanation of all the parameters will be added, trying to explain to all the users how the ground can be affected by changing simple parameters.

First Procedural Terrain Generator

This tool might be the first procedural terrain generator in the Unreal Engine's marketplace, so it might result in a useful resource for other users that are currently working on similar projects where the content has to be generated procedurally. Finally, the field of procedural generation is in large development, so there would be a good possibility that the Unreal Engine's community may find this tool useful and unique, once it will be released.

Suitable for Everyone

To implement this tool into another Unreal Engine’s project, is simply required to export the main blueprint ProceduralTerrainGeneratorAA and the blueprint ProceduralTerrainGeneratorBP which control the behaviour and the generation of the terrain, along with the source code. It will be then necessary to import the two blueprints with the associated source code into the project where this tool would be necessary. The tool will be ready to work as expected, without the necessity to modify any line of code. Furthermore, the source code not only contains the behaviour of the algorithms but it allows to access every thread of the noise through the node-based interface.

Conclusion

The project has been completed and it successfully meet all the goals initially set. The research carried out during the development allowed the implementation of all the main features expected. Overall, with further developments would be even possible to add this plug-in in the Unreal Engine’s marketplace, allowing other users to have an in-depth overview on how would be possible to create data procedurally using this game engine.  

Major achievements obtained:

• The creation of a procedural terrain generator tool that allow the creation of a terrain at runtime.

• An UI interface that allows user to change the parameters of the procedural algorithms without accessing any line of code.

• A deep understanding of noise functions and it is possible to use noise to generate any type of procedural content.

• A deep knowledge of how to use the game engine Unreal Engine and how to create and tools within this environment.

• Problem solving and project management skills, setting milestones and developing a project following a list of essential features to add.

Further possible improvements:

• Implementation of a forest procedural generation in order to amplify the quality of the terrain generated.

• Implementing a custom shader in order to apply a high quality dynamic texture to the terrain generated, based on the shape and the height of the ground.

• Allowing users to save the terrain created as an FBX file for an easy implementation of the terrain in other software.

• Allowing users to modify the terrain at runtime in order to create points of interest and allowing a more user customization.

About this essay:

If you use part of this page in your own work, you need to provide a citation, as follows:

Essay Sauce, Unreal Engine 4 Procedural Terrain Generator: Create Realistic Landscapes in Minutes. Available from:<https://www.essaysauce.com/sample-essays/2016-5-31-1464718416/> [Accessed 12-04-26].

These Sample essays have been submitted to us by students in order to help you with your studies.

* This essay may have been previously published on EssaySauce.com and/or Essay.uk.com at an earlier date than indicated.