Creating a Landscape
This recipe covers the basics of making a Landscape, which is a newer alternative to using the Terrain tool. It features a more painterly tool set, and can also import Heightmaps from software such as Vue or Terragen. Heightmaps are black and white textures where light tones influence a surface to push it upwards, and darker tones effect it less. Our goals will be to model a simple Landscape asset, and paint texture layers on it. Afterward, we'll scatter trees and rocks across it using the Foliage tool (which isn't limited to foliage).
Getting ready
Open UDK fresh, and from the File | New menu load the map template Midday Lighting. You may want to read about the technological basis for the Landscape tool at http://udn.epicgames.com/Three/Landscape.html.
How to do it...
Generating a Landscape asset:
- To open Landscape Mode, click the icon which resembles a mountain with an L on it, shown here. Above it, the other icon with a mountain is for Terrain.
- The Landscape Edit dialog will display. Drag its top or bottom to show the range of tools it offers. Click the icon [ ] next to Editing to hide that section.
- You will see in the Create New section a Heightmap Import field in which you can specify an external .RAW or .R16 file of the type generated in Vue for instance. That's one way to get started, based on existing topological data.
- The other way is to start from scratch. Adjust the Heightmap Size | Size (vertices) 0x0 field to
255 x 255
. Underneath, set the Component Size to 257. You will notice the Create Landscape button below become available. Click that, and your settings will be transferred onto a new actor in the scene, situated at 0,0,0 in the world. You can read about valid heightmap sizes (and other creation notes) at http://udn.epicgames.com/Three/LandscapeCreating.html. They even provide a Recommended Landscape Sizes table. - Press Shift + 1 then select the actor Landscape_0, and move it down a little in the side view to avoid running through the default box geometry in the scene, as in the next screenshot. Notice the orthographic wireframe reveals the density of the Landscape. Compared to the Terrain tool, it can retain a lot more detail and still function well. The values we've entered have also yielded a fairly large surface.
- Activate Landscape Mode again, to restore the Landscape Edit dialog. The Editing section will now be exposed again, and now it will show the asset name. Under this notice the active Paint Tools tool is Paint. Further down you'll see a Tool Strength slider, which effects intensity of strokes applied to the surface. Below that there is a Brushes section, which includes a highlighted Falloff type that is set to Smooth. Below that, there are sliders for Brush Size (which is the radius of the brush cursor), and Brush Falloff, which provides a control for softness/hardness for the stamp. For the most part these tools are similar to the Terrain editing tools.
- As you adjust the Brush Size you will notice in the view there is a radius/falloff circle which pulses and will interactively scale.
- Stroke on the surface and you'll notice nothing much happens. This is because the brush will only work with Ctrl held down. Hold Ctrl and brush around the base of the default block in the scene. Don't worry if it isn't very elegant.
- The default brush raises the landscape by 0.3. Raise this if it helps you get the height you want quicker. Or you can increment your strokes to let it build up.
- To paint downwards, or to depress the surface, hold Ctrl + Shift while making a brush stroke. Again, work around the boundary you just built up, as below. After this, in terms of where to brush, it becomes an artistic endeavor, and it would be a good idea to play a bit before continuing. Pay particular attention to the horizon of the scene, or the straight edge of the Landscape component, to hide the flat edge from players. The next example can be found in Packt_01_LandscapeBasics_DEMO.UDK.
There's more...
- The measures to generate a valid heightmap will vary depending on where you get your source data. To keep things simple, I am going to just use Photoshop for this example. On www.udk.com/forums you will find some information on heightmap generation in software such as Vue, Terragen, and so on.
- Open Photoshop, and choose File | New document. Set it at
509 x 509
(this is one of the recommended landscape sizes). Fill it with black. - Apply the Filter | Difference Clouds. This generates a noisy base. Then select the Burn tool, size it quite big, and darken around the picture edges. This will mean the edge of the terrain is a bit lower than the center in the final output, which is good for dealing with the eventual visible horizon. You can Dodge white or Burn black features as you wish everywhere else.
- This next part is the most important step for getting a valid heightmap. Go to Image | Mode and set it to Greyscale and 8 bit. Save the image in .BMP format as HeightmapTest.BMP to your desktop.
Why that step matters is because the UDN documentation says to save out a grayscale .RAW file in 16 bit mode. You can try it, but it may not work, and if it does you may get extreme results for the landscape altitude.
- Instead, saving a .BMP allows us to use a handy free tool HMCS (Height Map Conversion Software) from http://www.lilchips.com/hmcs2.asp. Download and install this, open it, and choose File | Open and grab HeightmapTest.bmp from your desktop. You should get immediate feedback in the viewer as to the altitude interpolation of your image, which looks rather steep.
- At the top of the HMCS menu, choose Adjust | Altitude. You can also press the icon [ ] or press Ctrl + L. A dialog will show that lets you specify high and low settings for altitude. Enter High = 4096 and Low = 0. The results will look more modest in HMCS, but look nicer in UDK.
- Now go to the File menu and choose Save As (or press Ctrl + A). It is very important in Save as type to choose not .BMP but .R16 (since UDK only reads .RAW and .R16 files for heightmaps). An example is shown:
- Now in UDK, delete any Landscape you may have already, and click on Landscape Mode [ ]. By the Heightmap Import | Heightmap field, click the browse icon [ ] and choose your saved .R16 file. It will show up there and auto-assign Heightmap Size | Size (vertices) and Component Size settings.
- Click on the Format | Unsigned and Format | PC radio buttons, then click the Create Landscape icon below, which should now be available. If you cannot see a landscape suddenly jump into view don't be scared. The pivot will be at Z=0 but the geometry may import much lower in the scene, well below Z=0. Switch to Wireframe view (Alt + 1) to find the actor. Press Shift + 1 to enter Camera Mode and move the landscape up to a position where it lines up with the map template's central block. Watch out for the red KillZ line in the side view, as shown next. The terrain should be completely above that if you intend the player to walk on it, and you should place the PlayerStart above the land too.
Applying Materials to your Landscape
- The Terrain tool applies several Materials to a Terrain patch using layers driven by unique assets, shown here, that are generated through the Terrain Editing Mode dialog:
- Landscape takes a different approach, using just one Material, which has its layers of textures built up in the Material Editor. The content of the layers is set there and given Parameter Names. These are matched with named Layers added in the Landscape Editor. The designer then uses the Paint tool to brush on masks for each layer. The layers don't require any additional asset to be saved out. The same layers that hold the Material mask can be locally sculpted too. The contribution of each layer can be set through a Blend value.
- Load the file Packt_01_LandscapePaint_Start.UDK. You'll see an untextured landscape waiting for a Material to be assigned to it.
- Select the Landscape actor and press F4. Its properties will appear. The first section, Landscape, contains a Landscape Material field. This is where you'll assign a Material from the Content Browser. You can at a pinch choose a regular Material, but it will simply cover the entire surface and won't be editable.
- To allow layer painting, create a new Material in the Content Browser called YourPackage.Material.Landscape_LayersTest_mat. Double-click the Material.
- Set up the nodes as shown in the next screenshot. To load a texture, highlight the desired texture in the browser then in the Material Editor hold T and click in the canvas area. If you haven't chosen a texture, the keyboard shortcut will work, but give you an empty Texture Sample, and you can fill it in the node's properties using the Use selected object in Content Browser icon [ ]. The nodes have had unused inputs and outputs hidden using the icon [ ].
- To add the node TerrainCoords, which tells the texture how to distribute on the Landscape surface, right-click in the canvas, and choose Terrain | New Terrain Layer Coords. In its properties set the Mapping Scale to 256 which matches the landscape component size. If you have good tiling textures to source, then this value can be smaller and you'll get nicer texture resolution.
- To add the node Layer, right-click and choose Terrain | New Terrain Layer Weight. What this does is set which texture will appear on which layer of the Landscape. In its properties, give each Layer node a Parameter Name. It is normal to name the layers after the texture they represent such as grass, snow, dirt, and so on. In this case, enter first and second and third. Then compile the Material by pressing [ ].
- In the scene, select the Landscape actor and press F4. In its Landscape | Landscape Material and assign your Material from the Content Browser: YourPackage.Material.Landscape_LayersTest_mat. On the object only one layer of the Material will be apparent.
- Click on Landscape Mode and go to the editor section, under Target Layer | Edit Mode click the Edit radio button, as show below. This allows you to add a new layer. In the Add Layer Name field type first, then click the icon next to it [ ].
- Again, in the Add Layer Name field type second, then click the [ ] icon again. Add another called third to complete matching the layers against the textures.
- Now with either of these layers highlighted you can hold Ctrl and brush with the Paint tool to apply a hand-drawn weight mask for the texture. Hold Ctrl + Alt to decrease the weight mask (although actually what this does is increase the weight of all the other layers as they combine to a value of 1.0). For this reason it seems best to have more than two layers contributing.
- This covers the basics of getting up and running with the Landscape creation and Material tools. There is a lot more about improving the land forms using Normal maps and the Landscape Gizmo in the UDN documentation, in particular: http://udn.epicgames.com/Three/LandscapeEditing.html.
- A simple example of the Landscape layering process using a Material set up with a Terrain Layer Weight network, shown below, can be found in the provided content Packt_01_LandscapePaint_DEMO.UDK.
Tip
A Landscape Gizmo is a tool similar to a volume which is used to copy and paste, and export, selections of the Landscape through a heightmap for duplication purposes, modularization, and external refinement. They can be automatically fitted to a region selection and their properties allow the height value of data contained in the gizmo to be relatively scaled. Gizmos are created as a function of the Region Tools | Region Selection tool in the Editing brushes of the Landscape Editor.