2023
This project makes use of various shaders and techniques, within the OpenGL render pipeline, to create a procedurally generated piece of terrain. Technniques implemented include distance based tesselation of the terrain to create more detail via an increased polygon count on areas of the terrain closer to the camera, as well as procedural generation by calculating perlin noise within a compute shader.
Options
The program features a variety of key binds which allow for the toggling of various features and implemented techniques. The key binds are as follows:
- Q – Toggle normal mapping
- E – Toggle sky box
- 1 – Toggle fog
- 2 – Toggle GL_LINE
- 3 – Toggle between using surface and CDM normals
- 4 – Switches between different texture techniques applied to the terrain
- 5 – Toggle between height map and compute shader generated heights using perlin noise
GL_LINE toggle
This is a simple toggle which allows for looking at a wireframe of the terrain instead of the default GL_FILL which displays the terrain as a full block of colour. The GL_LINE toggle is useful as it allows for more accurately seeing the effects of tesselation on the terrain.
GL_LINE
GL_FILL
Height map
This toggle switches the terrain between using a set height map, or a perlin noise generated height map. This perlin noise height map is calculated on start up via a compute shader to procedurally generate a set of heights, which will be different each time the program is run.
Height Map
Perlin noise generated heights
Normals
This toggle determines which method is used to calculate the normals of the terrain. Normals are needed as it allows for shading of the terrain based on the value of the normal, which when paired with lighting allows us to visually represent the difference in height on areas of the terrain. When no normals have been calculated the terrain will simply appear as a flat colour. Surface normals are calculated in the geometry shader by doing the dot product between two vectors going along two edges of a primitive. This will provide a new vector which would be the surface normal and will result in flat looking shading on the terrain. The central difference method (CDM) is used to give more realistic shading by calculating the normal of a specific point by using the heights of neighbouring points up, down, left and right from the concerned point.
Surface normals
Central difference method (CDM)
Tesselation
Tesselation is used on the terrain to provide more detail by increasing the number of polygons used to create it. However tesselation requires a lot of calculations on a frame by frame basis, which inevitably leads to an increase in computational power needed. To decrease the amount of calculation needed, distance based tesselation is used to only tesselate areas of the terrain closer to the camera while further areas are not as the camera won't be able to see them anyway. This leads to increased detail only on parts of the terrain that can be seen, thus saving resources.