Skip to content
Procedural generation of a landscape using Unity 3D
C# ShaderLab
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
Txt Files

Procedural Landscape

Code that dynamically generates a stochastic landscape (terrain + ocean) along with an orbiting sun using Unity.
NB: The ripples on the water aren't exactly realistic.

Made for Project A of COMP30019: Graphics & Interaction.

Tech Stack

  • C#
  • Unity 3D


Modeling of fractal landscape:

  • The land segment was implemented by generating a plane and then offsetting the y-values of the vertices by using the Diamond Square Algorithm. The code to do this was referenced from code written by Ather Omar from the following YouTube tutorial: Furthermore, extra functions were added to calculate the maximum and minimum y-values of the vertices and to also to shift the land mesh generated so that 1/3rd of it would be below the ocean surface.

  • The ocean surface was simply implemented as a plane at y=0.

Camera Motion:

  • The camera rotation uses input from the mouse and updates the transform (rotation) of the camera based off this input. The camera movement uses input from the keyboard and updates the transform (position) based off this input. The camera's vertical rotation values are restricted so that the camera is unable to do 'flips'. The camera collision was implemented by using sphere casting. This restricted the camera from moving any further towards the terrain if the sphere casted was intersecting with a mesh collider.

Surface Properties:

  • The colours of the land were inspired by the snow capped mountains of Andalsnes in Norway. In terms of the shading model, the colours of the vertices were first defined according to height when the land mesh was generated and then blended with a grass texture in the fragment shader to make it look more realistic. Note:- it was implemented so that the snow caps would only be visible if the terrain height exceeded a threshold height value. For the water surface, all the vertices were given one colour when the mesh was generated. This was blended with an ocean surface texture to promote realism.

  • In terms of the illumination model, Phong's illumination model was applied to each vertex using code from the COMP30019 Week 6 Tutorial. For the land, the specular component was removed as the land would not need to be glossy. For the ocean surface, the Specular Reflectivity Component was set to 200 to give it sharp highlights.

  • The sun was made by using a point light source and generating a sphere around it. A standard shader was used to give the sphere a slight yellow hue/ emission. Its motion has been implemented such that it revolves around the terrain, making it possible to observe both the sunrise and sunset. The speed of the sun's orbit can be adjusted via the inspector.

  • The ripples on the surface of water were generated by displacing the vertices using a combination of a sin and cos function in the vertex shader. The normals were then dynamically recalculated using approximations for the bitangent and tangent of the vertex. This enabled light to be reflected off each wave/ripple.

Build Status - Complete

You can’t perform that action at this time.