While the terrain is certainly looking more interesting, it is in great need of some textures.
Fortunately, because you imported the Terrain Assets package when you created the project, you will have some nice textures to work with. Terrain textures must be tiled, of course, to avoid seams, but they must also contain very few features that the human eye will recognize as repeated patterns.
Alpha channels will be ignored.
Let’s begin by looking at the textures provided by the Terrain Assets package.
1. In the Project view, Assets folder, Terrain Assets, select the Terrain Textures folder.
2. Use the size slider to see the thumbnails at their maximum.
3. Click on Grass(Hill) in the second column.
4. Adjust the Inspector’s width and the preview window’s height to get a good view of the texture (Figure 2-31).
Figure 2-30. Some of the jagged peaks weathered into gentle slopes
Figure 2-31. The Grass(Hill) texture shown in the Inspector
5. Note the information given about the texture at the bottom of the Preview window.
The texture is 512 x 512. The compression is DXT1. Unity compresses all of the project’s textures into the DDS format. If you look at the top of the Inspector, you can see that you will be able to dictate how the texture is read in and processed.
6. Click on each of the other three textures to see what is available.
7. From the Terrain Grass folder, check out Grass and Grass2, making sure to note their alpha channels by toggling the RGBA button next to the Mipmap slider (Figure 2-32).
The two textures, Grass and Grass2, are not for the terrain texture. You will be using them later, though, to help dress up your terrain.
The first thing to know about the terrain textures is that the first one you apply to the terrain will fill it completely, so choose accordingly. Textures, as with the rest of the trees, detail meshes and grasses that must be loaded into the appropriate Terrain component module before they can be used. Let’s begin by flooding the terrain with the Grass(Hill) texture.
1. Select the Terrain object again to get back to the terrain tools.
2. Click on the Paint Texture tool.
3. Under the Textures preview area, select Edit Textures.
4. From the list that appears, select Add Texture (Figure 2-33).
Figure 2-32. The Grass texture not meant for a terrain texture
Figure 2-34. The Add Terrain Texture dialog
The Add Terrain Texture dialog appears (Figure 2-34).
5. Click the Texture’s Select button to bring up the Select Texture2D dialog.
6. Select Grass(Hill).
7. Click Add.
The Grass(Hill) texture is now shown in the available Textures area beneath the brushes. In the Scene view, the terrain is filled with the Grass(Hill) texture, tiled at the default 15 x 15 size (Figure 2-35). Note that this is a tiling size, not number. If you wanted the texture to appear smaller or more detailed on the terrain, you would decrease the Size parameters.
To get some practice painting a terrain texture, you will need to add another texture.
8. Click the Edit Textures button again, and select Add Texture again.
9. Select Grass&Rock, and click Add.
The new texture is added to the available textures (Figure 2-36). Note that the Grass(Hill) texture has a light blue strip at its base. This tells you that it is the currently active texture for painting.
Figure 2-36. The two available terrain textures Figure 2-35. The Add Terrain Texture dialog
10. This time, load Cliff (Layered Rock).
Figure 2-37. The Cliff (Layered Rock) texture added to the available terrain textures
The mystery is quickly solved if you select the texture in the Project view and then view its alpha channel in the Inspector. This texture, when used on regular scene objects, was probably designed to use its alpha channel as a glossiness map.
Now that you have loaded a few textures, it’s time to start painting. Once again you have the brush choices, Brush Size and Opacity. Opacity is additive, so the more you paint an area, the more opaque the coverage is. This time, however, you have a new parameter, Target Strength. This lets you set a maximum opacity that caps the additive effect. When painting between ground and foliage, you may prefer to blend with the speckled brushes rather than opacity.
1. Select the cliff texture, set the Opacity to 100, and paint the mountains.
2. Select the Grass & Rock texture and one of the more broken-up brushes.
3. Paint the transition between the grass and cliff textures. Try clicking rather than dragging the brush.
4. Load the GoodDirt texture.
5. Decrease the Brush Size, and paint several paths around your terrain (Figure 2-38).
The thumbnail for this texture appears washed out (Figure 2-37).
In earlier versions of Unity, once the scene was saved, the terrain’s splat map would be visible in the Project view. A splat map is how Unity tracks where the textures were painted on the terrain. An RGBA texture has 4 colors available: red, green, blue, and white (Figure 2-39). The first three textures are recorded using the red, green, and blue colors. The fourth color is stored in the alpha channel as white, where black is used as a mask.
Figure 2-38. The terrain with textures painted
Figure 2-39. A splat map in the Inspector from an earlier version of Unity
To get a better idea of how the last “color” looks, you would have to toggle the alpha channel to see
Figure 2-40. The splat map’s alpha channel
You may be wondering if four textures are the most you can use on the terrain. If you note the name, SplatAlpha 0, the element 0 may clue you in. If you are new to scripting, you will soon find out that array elements always count from 0, indicating that there could be more splat map elements. So it turns out you can have multiple splat maps. Do be aware that each would be one more 1.3-MB texture added to the project and cause the terrain to be rendered again on top of the first splat map in an alpha-blended way.