Task 039: Terrain Generation

Your task is to create a program that will generate a fractal terrain. The user should be able to set the number of iterations used by the algorithm, and the smoothness / roughness of the result. With this assignment you should, among other things, learn how to work with 3D data, and try some basic procedural scene modelling methods.

Screenshot of an older version of the application 039terrain: Terrain Screenshot


The algorithm starts with four vertices located at the corners of a square, which are given random heights. In the middle of the square we add a new point. The height of this point is calculated as the average height of the four points ("diamond step"). To add a point grid is needed to soften the peaks, whereby we appear four new vertices. Their heights again calculated as the average height (here 3, the next iterations typically 4) of adjacent pixels ( "square step"). Method recursively / iteratively applied to the (smallest) squares resulting grid. The principle of the algorithm is illustrated in FIG.

If the algorithm only proceeded as just described, all it would generate is a smooth surface. However, one can introduce random vertical displacements to the points as well, during recursion. This magnitude of this feature, and how the random displacement changes with recursion level, crucially determines the final appearance of the generated terrain.

Steps of the algorithm


Further information can e.g. be found here:

If you want, you can also implement additional non-trivial techniques to gain bonus points, e.g.:


The template application 039terrain from the repository grcis serves as the basis of this project.Your main task will be to extend the Regenerate() method, that is invoked after changing of the parameters, and pressing of the "Regenerate terrain" button.
There also exists a class SceneBrep, to which you can easily add new vertices (AddVertex()), their normals (SetNormal()), texture coordinates (SetTxtCoord()) and colours (SetColor(), see the method Render()); its usage is can be seen in glControl1_Load(). The rendering of the scene data contained in SceneBrep, and a simple camera are implemented in Render() and SetCamera(), respectively. For a successful completion of this assignment, it is not necessary (but also not prohibited) to alter these two classes - the basic functionality of conversion to a triangle mesh is sufficient. This conversion from the data in SceneBrep and its transfer to the video card is done via the method PrepareData(). A utility library for texture management can be found in TexLib.cs.

Application behaviour when "Regenerate terrain:" is pressed: the application should not exhibit sudden changes in terrain shape when "regenerate" is invoked if only a finer/coarser resolution of the same mesh is desired. Of course the terrain appearance can and should change if parameters are altered: but if only fineness parameters are altered, the overall shape should stay the same.

Flight over the terrain ("hovercraft")

Optionally (for additional bonus points) you can try to implement interactive flights above the ground in a hovercraft. A hovercraft has very limited mobility in the vertical direction, and basically always follows the terrain (i.e. flies at some fixed height above it). Navigating the terrain should be via classical keyboard controls (arrow keys or "WASD"), or the mouse. You can also implement a viewing direction that is partially independent of the vehicle's forward movement - a hovercraft can have considerable inertia, but rotate around the vertical axis faster. You can freely chose relevant parameters, such as the flight altitude over the terrain, acceleration, inertia, gravity influence, or smoother movement over rough terrain (height smoothing function terrain). Just make sure you properly document what you do in this regard, so that we can give you the extra points you deserve!

The flight simulation should call the method Simulate ( double time ). As with other tasks in this course, time is measured in seconds and the task of calling this function is to "simulate" movement from the last call until a given time. This method is always called immediately before rendering a 3D scene.

What to hand in

As solution of the assignment, you minimally have to send us the file Terrain.cs. If you have used a different terrain generation method than the one described above, please also describe it in a short accompanying text. The same goes for any interesting extensions you implemented. You can also send in a screenshot of your app in action, or a link to a gallery of images rendered with it (but this is not required).


Hand in the assignment until: 25. 2. 2017


Up to 26 points + bonus according to the following scoring system:

  • 10 points -basic generation of a non-textured / monochrome terrain with settings for smoothness / roughness and the number of iterations. At least some normals are set, and there is a possibility for setting the dimensions of the terrain.
  • 4 points - initialisation of the terrain via a PNG image.
  • 2 points - correct normals at all vertices, which leads to nice shading.
  • 2 points - basic non-trivial texturing of the terrain.
  • 3 to 8 points - ability to fly over the terrain ("hovercraft mode").
  • bonus - for interesting additions, and particularly pretty rendering. Possible additions: volcanoes, rivers, controllable sea-level. Rendering: bonus for multiple textures, semi-transparent water, etc.).


Visual Studio project: 039terrain.

Source file

Modify and hand in the source file: Terrain.cs
As a comment in the first line, please include your name!
Please also return your name as parameter of the function Form1.InitParams()!
Also, if you add any features beyond the baseline ones (hovercraft mode, etc.), please include a description!

Copyright (C) 2016 J. Pelikán & A. Wilkie, last change: 2015-10-26 01:59:27 +0100 (Mo, 26 Okt 2015)