MC Terrain

A terrain system for Unity that you can build on to create your own games
Compatible for Unity 2021.3.0f1 upwards
Published by Lizoft


Overview

MC Terrain is an implementation of the marching cubes method to generate terrain from 3D noise. Because the terrain is generated as a 3D array of cubes it is possible for the player to interact with the terrain allowing it to be raised and lowered. After the terrain has been altered, the code simply marches the cubes again and the updated terrain is displayed.

The project includes a procedural endless terrain implementation, achieved by dividing the terrain into 16x16 chunks that are 100 cubes high, and as the player is moved across the terrain, chunks are created and hidden as needed to keep the player in the centre of the play area. The play area is described by a 512 x 512 biome map texture. The texture wraps on both axes allowing for a potentially infinite play area.

The project also includes a biome implementation allowing eleven different biomes to be described, each populated by different terrain textures, scenery and vegetation.

Please note that no scenery items except for the grass are included with the package, and only a very basic player capsule is included.

Features

• Marching cubes terrain generation
• Player can raise and lower terrain
• Endless map scrolling
• Everything procedurally generated from a single seed
• 11 Biomes, set up using scriptable objects
• Option to use your own biome and height maps
• Different trees, bushes, rocks, stones and grass can be set for each biome type (no scenery prefabs are included)
• GPU Instanced grass
• Water implementation (no water shaders are included)

Quick Start Guide
Quick Start Guide

MC Terrain can be installed and running with just a couple of mouse clicks!

Changing the Player Controller
Changing the Player Controller

Once MC Terrain is running, the first thing to do it to replace the TempPlayer GameObject with a fully featured Player Controller. You can use either Third Person or First Person Controllers.

Using the URP or the HDRP
Using the URP or the HDRP

MC Terrain can use the Standard Render Pipeline, the Universal Render Pipeline or the High Definition Render Pipeline.

Biomes
Biomes

Biomes are set up using Scriptable Objects, and there are settings to change the look and feel of the biomes.

Terrain Settings
Terrain Settings

Terrain is generated using 3D noise and there are a number of settings to change the look of the terrain.

Modify the Terrain
Modifying the Terrain

The terrain can be raised and lowered in-game allowing the player to change the landscape and dig out tunnels and caves.

Adding Water
Adding Water

Water can be added by creating a Water Plane GameObject.

Adding Scenery
Adding Scenery

Each biome can have different scenery objects, with settings to choose how the scenery is displayed.

Dev Mode Options
Dev Mode Options

There are a selection of Dev Mode Options available for working with MC Terrain.

Grass Prefab
Grass Prefab

Grass is added using GPU Instanced prefabs.

Shaders

To get a different texture on the sides of the terrain (eg. rock) compared to the flatter areas (eg. grass) a Triplanar shader is used. Triplanar is a method of generating UVs and sampling a texture by projecting in world space. The input Texture is sampled 3 times, once in each of the world X, Y and Z axes. The resulting information is planar projected onto the model, blended by the normal, or surface angle, with the flatter areas using the grass texture and the steeper areas using the rock texture.

For the Standard Render Pipeline I referenced an excellent article found here:
https://catlikecoding.com/unity/tutorials/advanced-rendering/triplanar-mapping/ 

Triplanar Shader for HDRP

Triplanar Shader for the HDRP - opens in a new window

For both the Universal Render Pipeline and the High Definition Render Pipeline I made use of Shadergraph and its Triplanar node, and used the Dot Product of the Normal Vector to lerp between the two texture inputs as can be seen in the image. The image shows the High Definition Render Pipeline version. The only difference between the two versions of the shader is the Active Targets setting, which I changed to URP for the Universal Render Pipeline version.

© Copyright 2023 MC Terrain. All Rights Reserved.