Procedural Terrain Generation With Unity

Programming realistic environments with C# through the algorithmic manipulation of mesh and vegetation data.

Last updated 2022-01-10 | 4.5

- Use various algorithmic approaches to create procedurally generated content.
- Manipulated terrain meshes with code to create realistic looking landscapes.
- Texture terrain meshes procedurally.

What you'll learn

Use various algorithmic approaches to create procedurally generated content.
Manipulated terrain meshes with code to create realistic looking landscapes.
Texture terrain meshes procedurally.
Discuss the design principles involved in producing aesthetically pleasing terrains.
Manipulate the render settings in Unity to produce better looking camera results.
Create custom Unity windows and graphical user interface elements for use inside the Editor.

* Requirements

* You should be familiar with C# and the Unity Game Development Engine.
* You should have a healthy respect for mathematics.
* You should be fascinated by procedural generation and what it can accomplish.

Description

The creation of beautiful virtual terrains isn't just the domain of the artist, but also of the programmer. What if you could use your programming skills in C# to manipulate a mesh to create realistic landscapes, using algorithms developed by researchers studying landscape formation and erosion? Well now you can.

In this course, Penny introduces procedural terrain generation techniques using her internationally acclaimed holistic teaching style and expertise from over 25 years of teaching, research and work in games and computer graphics. Throughout the course you will follow along with hands-on workshops, designed to teach you the fundamental techniques used for generating realistic virtual landscapes.

Learn how to program and work with:

  • Voronoi Tessellation

  • Midpoint Displacement

  • Perlin Noise

  • Splat Maps

  • Trees and Vegetation

  • Clouds

  • Weather

  • Erosion

  • ...and water

Contents and Overview
The course begins by examining the nature of a landscape and the design considerations you should include in making decisions on structure, colour and vegetation. You'll learn what makes for a natural looking terrain, so you can replicate this in Unity.

Following on, we will examine some of the most popular algorithms used in generating terrains (including many fractal and tessellation techniques) that can be used together, to form random and yet convincing mountainous vistas.

Once you are confident with landscape formation, we'll move onto texturing the terrain with a variety of images that can be placed via splatmaps onto differing heights and gradients. Then, continue to decorate the terrain with trees, rocks and grass placed with an algorithmic approach before investigating erosion methods, that will add that extra level of realism.

The course concludes with the development of a cloud generation system and an exploration of particle systems for adding rain, snow and other atmospheric effects to the finalised landscape.

Throughout, we'll be developing our own custom Unity editor code that will allow you to build extra functionality and structure into the Unity Inspector, as well as create Editor Windows of your very own.

What students are saying about Penny's courses:

  • Penny is an excellent instructor and she does a great job of breaking down complex concepts into smaller, easy-to-understand topics.

  • Penny's teaching style is exceptionally well-motivated and illustrated.

  • This course is awesome. The lecturer explains everything you need to know and encourages you to experiment and challenge yourself.

Who this course is for:

  • Anyone interested in learning the algorithms used in procedural generation.
  • Those wanting to develop code to manipulate meshes, to produce realistic landscapes.
  • Anyone keen to find out how to write custom Unity inspector editors.

Course content

13 sections • 87 lectures

How to Study This Course Preview 00:37

Join the H3D Student Community Preview 01:26

H3D has a bustling online student community.  Here's how to get involved.

Welcome Preview 02:06

This video is a short introduction to the course content.

FAQs Preview 00:14

This article addresses common general questions about my courses.

Behind the Scenes of a Terrain Object Preview 05:04

This lecture examines the data structures involved in the storage of a terrain and then gives an overview of the Unity Terrain object.

Manual Terrain Creation Part 1 Preview 18:27

In this two part lecture we will step through all the existing terrain creation tools implemented in Unity to give you a better feel for what's possible.

Manual Terrain Creation Part 2 Preview 13:31

In the second half of this two part lecture we will examine the adding of details to a terrain and finalise our discussion on the terrain object.

Design Principles for Terrain Aesthetics Preview 09:38

In this lecture we will examine some of the design principles that will help you take your terrain design skills to the next level.

Landscape Reproduction Challenge Preview 03:34

For this challenge you should recreate your favourite vista as a Unity Terrain. 

Quiz 1

Test your knowledge about Unity Terrain Object.

Getting Ready to Create a Custom Editor Preview 16:30

In this lecture we will begin by getting the Unity environment ready for creating a custom editor that will be used to control the terrain settings.

Generating Random Heights Part 1 Preview 19:56

In this lecture we will create the code for our first customised part of the editor and hook it up ready to implement a random height creation algorithm.

Generating Random Heights Part 2 Preview 19:24

This lecture continues the development of the first custom editor for the terrain and now concentrates on your very first procedural algorithm for modifying height values.

Loading Height Map Data from an Image Preview 16:31

In this lecture we'll use height data from real world geography and load it in as an image to set the heights on a terrain.

Quiz 2

Test your knowledge of the Unity Terrain Object

Solution Code Preview 00:05

Completed code developed to this point.

Noise Theory Preview 05:58

In this lecture we will take a look at the theory behind one of the most popular algorithms used for creating terrain.

Implementing Simple Perlin Noise Preview 19:09

In this lecture we will implement a simple version of Perlin Noise and use it to adjust the height map for a terrain.

Brownian Motion Preview 18:00

This lecture builds on the last introducing the idea of adding several Perlin Noise functions together in another popular algorithm called fractal Brownian motion.

A Quick Note About GUITable Code Preview 02:14

This is a short lecture explaining how to pad out the area around the GUITable if you run into troubles later on.

Multiple Perlin Noise Preview 19:57

In this lecture we will create a table of Perlin Noise parameters in the inspector and pass them to a new method for adding multiple curves to a terrain.

Solution Code Preview 00:05

Completed code developed to this point.

What is Voronoi Tessellation Preview 02:48

This lecture provides a quick introduction to Voronoi Tessellation and explains how the phenomena can be replicated to create mountainous landscapes.

Creating Mountain Peaks Preview 19:25

In this lecture we will create a procedurally generated peak with surrounding sloped terrain inspired by Voronoi tessellation.

Modifying Mountain Slopes Preview 19:29

In this lecture we will examine the use of mathematical functions to alter the slope types created on the side of mountains.

Multiple Random Peaks Preview 13:32

This lecture begins with a challenge to see if you can complete the functionality of the Voronoi component by yourself.  It then continues by providing a solution and suggesting ways to integrate Voronoi peaks into terrain creation.

Adding a Choice of Function Types Preview 10:34

This lecture will take you through the process of integrating multiple functions into the code to use with the voronoi peaks.

Solution Code Preview 00:05

Completed code developed to this point.

Introduction to MPD Preview 01:58

In this lecture we will begin looking at a popular terrain generating algorithm called Midpoint Displacement.

The Diamond Step Preview 18:54

In this lecture we will start building the Midpoint Displacement algorithm and concentrate on the Diamond Step.

The Square Step Preview 19:58

This lecture continues the development of the Midpoint Displacement Algorithm by adding in the Square Step.

Smoothing Part 1 Preview 15:18

This lecture will discuss the creation of a smoothing algorithm to rid your terrain of sharp peaks.

Smoothing Part 2 Preview 05:57

In the second part of the smoothing lecture we will examine how to add a smooth amount to the algorithm.

Solution Code Preview 00:05

Completed code developed to this point.

New Splatmap format for Unity V.2018.3 Preview 00:11

This article will explain how to update the code in this section to deal with changes made to the terrain structure in Unity V.2018.3

Splatmaps Preview 19:30

In this video we will start exploring the use of textures for colouring the terrain and develop code to add them for use by splatmaps.

Specifying Texture Heights Preview 12:52

In this lecture we will add the logic to our code to develop the blending functionality of the splatmap to draw different textures at different terrain heights.

Blending Texture Overlaps Preview 19:51

In this lecture we will look at how to feather and blend the edges where two textures meet on the terrain.

Running out of Room in the Inspector Editor? Preview 04:28

In this short lecture I will show you how to expand the available space in the inspector editor by adding a scrollbar.

Texturing on Steep Terrain Preview 19:59

In this lecture we will extend the splat map functionality to restrict certain textures to be placed on terrain based on the steepness.

Creating a Procedural Texture Preview 19:37

In this video we will create an editor window and give it the functionality to display a procedurally generated texture.

Making a Seamless Texture Preview 12:37

In this lecture we will modify the noise algorithm being used to develop a seamless texture.

Saving a Texture into the Assets Folder Preview 04:23

In this lecture we will add saving functionality to the editor window to save the generated image to a png file in the Asset folder.

Modifying Global Pixel Values Preview 13:35

Sometimes the resolution of the final image isn't quite what you'd like.  In this lecture we will add extra features to improve the image quality.

Solution Code Preview 00:05

Completed code developed to this point.

Displaying Heightmap Challenge Preview 08:13

This exercise will challenge your knowledge of height maps and editor coding.

Working with Tree Prototypes Part 1 Preview 15:16

In this lecture we will start working with the data structure that holds the information about trees and other vegetation.

Working with Tree Prototypes Part 2 Preview 17:06

In this second part of this lecture we will start placing trees on the terrain with code.

Working With Layers Preview 12:12

In this lecture we will create an automatic layer adding method to assign the terrain object to a physics layer for later raycasting.

Setting Tree Heights Preview 14:30

In this lecture we will use ray casting to locate the true height of the terrain below vegetation objects for accurate positioning.

Setting Tree Properties Preview 19:59

This lecture starts by presenting a challenge to produce and interface that will allow full customisation of the vegetation on the surface of a terrain.

Fixing Tree Positions for Differing Terrain Scale Sizes Preview 01:06

This article will explain how to adjust your code to deal with resizing the terrain in the Inspector.

Solution Code Preview 00:05

Adding Detail Preview 19:59

In this lecture we will examine the detail map system and start populating the terrain with grass and rocks.

Detail Settings Preview 19:06

In this lecture we will examine how to add in height and slope ranges to the placement of detail as well as modify the visibility distance.

Advanced Detail Settings Preview 07:32

In this lecture extra properties will be set to modify the appearance of the surface details.

Solution Code Preview 00:05

Completed code developed to this point.

Adding Water Preview 13:05

In this lecture we will add a water object to the terrain through code.

Shoreline Creation Part 1 Preview 19:59

In this lecture we will start building a procedural mesh to follow the shoreline of a terrain.

Shoreline Creation Part 2 Preview 16:59

In this lecture we will continue building the shoreline by combining the quads into a mesh and adding an animated texture.

Solution Code Preview 00:05

Completed code developed to this point.

Erosion Preview 01:40

This lecture introduces the types of erosion that will be implemented as algorithms in this section.

Rain Preview 13:36

In this lecture we will setup the inspector editor with erosion parameters and then create the most simplest of the erosion algorithms, rain.

Thermal Preview 11:22

In this lecture we will add the functionality to simulate thermal erosion on our terrain.

Tidal Preview 05:06

In this lecture we will examine areas where the water plane is added and create an algorithm to erode away shorelines.

River Preview 14:55

In this lecture we will examine one of the more complex erosions systems that can be simulated on a terrain; running water.

Wind Preview 15:33

In this lecture we will add in the functionality to erode the height map of a terrain by simulating wind.

Wind Direction Preview 09:38

In this lecture we will extend the wind algorithm to allow for the specification of a wind direction to cause the ripples to form in different ways across the terrain.

Canyon Challenge Preview 15:42

In this video you will be challenged to create a canyon that makes its way across the terrain.

Solution Code Preview 00:05

Completed code developed to this point.

Fog Preview 14:40

In this lecture we will examine how fog can be used to create the sense of a large environment while hiding the edges of the world from the player.

Clouds Part 1 Preview 19:16

In this video we will begin our examination of creating particle clouds.

Clouds Part 2 Preview 17:51

This lecture follows on from the previous by creating a fully fledged cloud from programmatically created particles.

Cloud Management Preview 13:02

In this lecture we get the clouds moving across the terrain at different speeds and set them to respawn at the starting location.

Cloud Painting Preview 06:40

In this lecture we will examine a way to paint the particles in a cloud different colours based on their position in the cloud.

Using Clouds Preview 15:20

In this lecture we will add the clouds to the terrain and then examine the creation of different cloud types.

Cloud Shadows Preview 19:38

This lecture completes the cloud creation exercises by adding shadows to the clouds that will appear on the terrain.

Sky Domes Preview 14:16

In this lecture we will add a skydome with scrolling texture across the surface to the terrain.

Particles for Weather Effects Part 1 Preview 11:16

In this lecture we will take a look at how to create a rain particle system as well as discuss how particles can enhance the look of your final project.

Particles for Weather Effects Part 1 - Continued Preview 09:00

In this lecture we will take a look at how to create a rain particle system as well as discuss how particles can enhance the look of your final project.

Particles for Weather Effects Part 2 Preview 12:50

In this lecture we will complete our look at the particle system for creating rain and add a few visual enhancements to the terrain to match the atmosphere.

Solution Code Preview 00:05

Completed code developed to this point.

Updates to Post Processing Stack for V.2018.3 Preview 00:08

In this lecture I will show you how to fix a conflict thrown up by the Post Processing Stack when you try and add it to your projects.

Advanced Render Settings Preview 19:45

In this lecture we will examine a some methods for improving on the render quality of the terrain.

Final Project Preview 01:03

Final Words Preview 01:06

Here are some final words from the instructor.

Where to Now? Preview 11:16

This link provides further information on the courses you can look at taking based on your interests and skill level.