Using the Terrain Tools in Unity
Learn to create and manage a wide range of terrains in your apps by using Unity’s powerful Terrain Tools and the all new Terrain Toolbox API. By Mauro Fuentes.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Using the Terrain Tools in Unity
35 mins
- Getting Started
- Installing the Terrain Editor
- Installing the Terrain Tools Sample Asset Pack
- Understanding the Terrain Toolbox as a Toolbox
- Getting to Know the “Create New Terrain” Tab
- Creating Your First Terrain
- Looking Over Your First Terrain
- Understanding the General Section
- Introducing the Cool New Gizmo Feature
- Importing Heightmaps
- Terrain Textures
- Exploring the Terrain Settings Tab
- Terrain Utilities Tab
- Looking at the Terrain Edit Section
- Reviewing the Terrain Layers Section
- Examining the Layers
- Creating Palettes
- Adding the Palette to the Terrain
- Introducing Splatmaps
- Applying Splatmaps
- Experimenting on Your Own
- Importing and Saving Presets
- Exploring the Terrain Visualization Tab
- Revisiting the Old Terrain Component
- Create Neighbor Terrains
- Paint Terrain
- Reviewing the Brushes
- Height Brushes
- Paint Brushes
- Stamp Brushes
- Sculpting Brushes
- Erosion Brushes
- Transform Brushes
- Effect Brushes
- Introduction to Brush Masks
- Brush Mask Filters
- Combining Everything
- Painting Details and Trees
- Where to Go From Here?
Exploring the Terrain Settings Tab
The Terrain Settings tab on the Toolbox is exactly the same as the Terrain Settings tab on the Terrain component… but you can only apply the former, as you’ve read before, to all terrains.
So this…
Is the same as this:
The difference is that, now, you can apply changes locally to each terrain, through the Terrain component, or globally to all terrains in the scene, through the Terrain Toolbox.
If you want to know more about basic settings, please also check this amazing tutorial by Brian Moakley Introduction to Unity: Terrain Generation.
Terrain Utilities Tab
Welcome to one the most important tools. Terrain Utilities is where the Toolbox really exploits its “one-for-all” power.
As a quick introduction, this tab allows you to safely erase terrains. No more lost terrains cluttering your project. Also, you can manage all your layers and splatmaps from here.
Looking at the Terrain Edit Section
In the past, it was common to forget about your terrains and end up having lots of unused files. The worst-case scenario was to erase an important terrain. As you know, they’re assets, so if you erase them… there’s no undo.
Finally (!), you can get rid of unneeded terrains safely. Just select a terrain and click Erase. Unity will take care of the TerrainData for you.
Reviewing the Terrain Layers Section
To begin afresh, open Scene 2. It’s your turn to practice. Your goal is to repeat the process of creating a terrain using a heightmap texture.
Use the values below in the General settings, then add the heightmap located in Assets/RW/Scenes/Scene 2/Heightmap 2. As always, remember to rename the GameObject and the linked TerrainData object, like you did before. This helps you keep track of them.
- Width: 8000
- Length: 8000
- Height: 2500
- Resolution: 1025
- Base Map Distance: 20000
Remember, practice makes perfect!
Next, it’s time to look at terrain layers.
Examining the Layers
Before you continue, try to wrap your head around this: A Terrain Layer is an asset. It’s a file in your project that holds textures to paint Terrains. Textures are also assets. Terrains are assets. Palettes are assets. Material Palettes are assets. You are an asset. The writer of this tutorial is an asset. Ray Wenderlich himself is an asset… the whole world is an asset! :]
Joking aside, you have to be extra careful about which asset’s values you’re changing. Otherwise, if you’re looking at a global asset, you’ll end up changing global values. The solution to this is to learn to properly use and edit Layers.
Navigate to Assets/RW/Scenes/Scene 2/TerrainLayers 2 to explore the layers you need for this part of the tutorial.
You can always create new layers by right-clicking in the Unity Editor window and selecting Create and then Terrain Layer. You’ll then add the relevant Diffuse, Normal Map and Mask Map textures.
Now that you have an overview of layers, you can create palettes.
Creating Palettes
Layers in the Toolbox work exactly as they do in popular programs like GIMP, Substance Painter and Photoshop. They stack on top of each other and blend according to alpha values:
A palette is just a group of layers. It’s a key element in the hierarchy of tools in your toolbox:
To create one, go back to the Toolbox, navigate to Terrain Utilities and, in the Terrain Layers section, click the Plus button to add a new layer.
Select snow 2 from the assets you just saw, then drag and drop it into your new layer slot.
Order matters here (the top layer will be rendered over all of the others), so repeat this process with dirt 2, then moss 2, and finally rock 2 to complete your palette.
Finally, press the Save button in the top right of the Terrain Layers section to save this group of layers as a palette preset. You will be prompted to create a new palette; press OK. For easy reference, you can save it to the same path as the layers: Assets/RW/Scenes/Scene 2/TerrainLayers 2. Name this palette something comfortable, like PaletteScene 2.
Adding the Palette to the Terrain
Done! Now, you’re ready to add the palette to your terrain. Select your terrain in the Scene view and click the Add to Terrain button.
Your mountain will now be snow-tinted, like this:
Next, you’ll learn how to use splatmaps to make this mountain more awesome!
Introducing Splatmaps
A splatmap is a texture that uses its own color channels as layer masks. Normally, a splatmap uses four channels: green, blue, red and alpha.
That means, instead of painting snow, rocks and grass directly, you paint green, blue, red and alpha. This decouples the painting process from the chosen textures.
Suppose tomorrow, you decide to change the snow texture to… er… lava. You’d only need to change the texture, not the paint strokes.
In practical terms, you could have:
- Snow on the green channel.
- Rocks on the blue one.
- Grass on the red one.
- Dry grass on the alpha.
So, how can you apply a splatmap to your mountain?
Applying Splatmaps
Inside your toolbox, go back to Terrain Utilities and locate Terrain Splatmaps.
Click the Plus button to add a new splatmap, just like you did to add a new layer. Drag and drop RW/Scenes/Scene 2/SplatMap 2 into your new splatmap slot, then click Apply to Terrain.
One more step for the magic: Make sure your Terrain object is selected in the Hierarchy, then click Apply to Terrain… and marvel!!
To recap, each layer in your palette corresponds to a color in the splatmap: Unity paints snow everywhere it’s red, moss everywhere it’s blue, etc. Once again, order matters here. Feel free to reorder the layers in your palette to swap the channels in your splatmap.
The final result: