Getting to know the Irrlicht 3D engine - Terrains

Dec 11th, 2009 by mcasperson

In this tutorial we create an outdoor scene in Irrlicht with the built in terrain rendering.

DOWNLOAD THE DEMO AND SOURCE CODE

RETURN TO THE TUTORIAL INDEX

Irrlicht is a very versatile 3D engine, being able to display indoor and outdoor scenes with ease. Here we will create a terrain scene node to display an outdoor scene.

ApplicationManager.h / ApplicationManager.cpp

As before, we define several constant values that will determine how the terrain is displayed.

The terrain will be created using 3 bitmaps: the heightmap, the base terrain texture, and a detail map.

The height map is a black and white image where the height of the terrain is measured by the brightness of each pixel. This essentially means that white areas make mountains, and black areas make valleys. This is used to create the mesh that will represent the terrain.

Onto this terrain mesh we will add the base terrain texture. This material stretches across the entire terrain.

Typically the base material will not have enough detail when the camera is right up close. This is becoming less of an issue as PC’s get more and more memory. However, we can add some detail to the terrain material by repeating a detail texture across the surface of the terrain. This detail map is usually a non-descript image that looks like the bumps and cracks you’d find on the ground. The TERRAIN_DETAIL_SCALE constant defines how many times this image is repeated across the surface.

Because the terrain is quite large (as you would expect) we use the default values for the speed of the FPS camera (as opposed to slowing is down as we have for the last few tutorials). We also want to set it slightly above the surface of the terrain initially, and to make sure the furthest edges of the terrain can be seen we increase the cameras far value.

Next we create the terrain itself by calling the ISceneManager addTerrainSceneNode function. We only supply the height map at this point, as the default parameters are fine for our basic terrain.

By default the height of the terrain (i.e. the y value of the points painted in white in the height map) are way too high, so we scale the terrain to make it look more natural.

The terrain material is shaded before it is rendered by Irrlicht. I have used a program called T2 to create a terrain material that has shadows “baked in”. Because of this we don’t want the terrain to be lit by Irrlicht, which means we have to disable the lighting.

The two materials, the base material and the detail map, are then added to the terrain. We then tell Irrlicht that the second material layer is a detail map, and scale it so that it is repeated across the surface of the terrain.

mcasperson

Written by mcasperson

Rate this Article:

Rating: 5.0/5 (1 votes cast)

Add new comment

* You must be logged in order to leave comments, please Sign in or join us.

Comments

No comments yet, be the first to comment on this article.

Related Content