Simple landscape
In this tutorial you’ll learn how to set up a basic landscape. Landscapes are great to easily get a large world without having to worry much about the performance cost. We’ll also introduce you to directional lighting, which is usefull on landscapes, since they’ll get lighted by the sun (or moon) most of the time anyway.

What do we need?
- First of all, we’ll need a TVLandscape instance. TVLandscape is the class with the landscape functionality in it.
- We’ll ofcourse need a texture to be applied on the landscape, which is found in the common folder.
- To give the landscape some height, mountains etc, we’ll use a heightmap to load the landscape from. A heightmap is greyscale most of the time, where white will be the higher heights of the landscape and black will be the lower area’s.
- We’re going to use a directional light to light the landscape with, so we’ll need an integer to store its ID as well.
How do we set up the scene?
- Of course we’ll need to instantiate the TVLandscape class to use it. This is done the same way as actors or meshes, by calling this line:
Note that the parameter is optional and is just a name for the landscape, it doesn’t mean anything.
- Now we’re going to give the landscape the geometry and height. This is done by this line:
The first parameter is the path to the heightmap. You don’t need to load it as a texture, you can just let the TVLandscape do it.
The second parameter defines the precision of the landscape. Ofcourse we can’t have a vertex for every pixel if we’re loading a 2048×2048 heightmap, since that will result in too many vertices. That’s why there’s a smart algorithm to reduce the amount of vertices and triangles. The higher the precision, the more triangles and vertices. In this case we’ll just use an average precision.
The third and fourth parameters will divide the landscape into so called chunks. Chunks are handy when you’ve got massive terains, since they can be disabled, so it won’t have to render it when out of sight. In this case we’re making a 4×4 grid of chunks. They are all a size of 256×256 units (just a default value, you can’t change it as far as i know). So this will result in a 1024×1024 landscape.
The next 3 parameters define the starting position of the landscape. We’ll set it to (-512,0,-512), so when you’re at (0,0,0), you’ll be in the middle of the landscape, that can be handy when positioning the camera.
The last parameter defines wether the landscape should be smoothed. In this case we want a nice smooth terrain, but there might be occasions where you’d like to keep everything edgy.
- Now we’ll apply the texture and material to the landscape. You know how this is done, since it’s exactly the same as with meshes and actors.
- We want the diffuse texture to be smaller, so it will look like there’s more detail. That’s why we’re setting:
This might look counter intuitive. Setting the scale to 4 will decrease the size of the texture? Well, there’s a good explanation for this. When you’re setting the scale to 4, you’re actually telling the engine that when it wants to get the color of a given u,v coordinate, it should multiply the u,v coordinate by 4,4 and then reading the color. This will result in a smaller texture. It will be repeating itself though, since the texture will not be big enough to fill the whole landscape.
- Last thing we’re going to do is making a directional light. The sun is at a great distance from the earth, so all light rays are more or less parallel to eachother. To achieve that with a pointlight would be really hard. That’s why there’s a directional light available in the light engine of TV. The directional light will shine from the same angle on every object. This means that it has no position or attenuation (falloff), so it’s a bit harder to get the effect you want sometimes. To set the light up we’re calling:
The first parameter is the direction of the light, so right now its shining from sky down to the earth in a 45 degree angle, along the y and x axis.
The next 3 parameters are the color of the light, pretty straightforward again.
The fifth parameter is the name of the light (it’s possible to set one, though it’s advised to keep track of the lights yourself to increase the speed).
The last parameter is the specularlevel. This defines the amount of shinyness of the light on the objects.
- There’s just 1 thing we forgot to do, we need to position the camera. You can get the height of the landscape at point (0,0) by calling:
This will get the height of the landscape at point (0,0) and add 50 to it. We’ve done this so our camera will be above the landscape instead of inside it.
How do we render this?
- There’s just 1 thing to render at the moment, this is the TVLandscape. You can render it just as easy as an actor or mesh, by calling:
Land.Render()
Things you can add/change yourself
- You can try to play around with the directional light to see what effect it will have on the landscape.
- I liked playing with the heightmap to get a landscape i knew (i tried making a small valley with a river (just the height, not water etc), and it’s pretty cool seeing a 2D image translated to 3D. Try making your own landscape with something like paint or photoshop.