COMP30019 Project 1

This is the first project of the subject COMP30019 (Graphics and Interaction) in the University of Melbourne, 2016 Semester 2.

Specification is available here

Special Note

unity_ObjectToWorld and unity_WorldToObject are replaced by _Object2World and _World2Object to support Unity 5.3.6f1. It appears that the change will be reversed automatically in higher Unity version (tested on 5.4.0f3).

Usage

Open Graphics Project 1/Assets/_Scenes/Main.unity with Unity, either play in the editor or build and run on a platform that supports keyboard and mouse input, there will be a scene containing randomly generated terrain and water, with lighting, camera control and boundaries applied.

As mentioned in spec, use WSAD keys to move, use mouse and Q/E keys to change pitch/yaw/roll.

Many parameters are adjustable in the Unity Editor, such as the initial heightmap points and colors of terrain.

Implementation

Terrain Generation

The terrain is generated by procedurally creating a heightmap (as 2D array), followed by mesh generation where heights are applied to mesh vertices.

The heightmap is generated using the Diamond Square Algorithm, where the random magnitude is halved in each iteration. In cases that a point is out of bound, only 3 (instead of 4) points will be taken. The result of heightmap generation is a 2D array of floats ranged 0 to 1 as heights.

The result is then applied to generate the mesh, using Unity's MeshFilter component, similar as the earlier labs did. Vertices, vertex colors and normal vectors are calculated and added.

Control and Constraints

The player object is associated with the main camera in the scene, the script on it reads keyboard and mouse input every frame and apply the transform. Note that x-axis rotation is limited to [0, -90] and [270, 360] degree for more natural control.

Terrain and player have colliders associated, so that the player can be blocked by terrain. The player is also restricted from going beyond the terrain or going too high in the sky, which is implemented by simply putting invisible walls around the terrain.

Shaders

This project uses custom shaders to make lighting effects, shaders are adopted from Lab05, and modified to suit the need of the project. There is a shader for opaque object and one for objects with transparency, being only slightly different.

Shader of the terrain is configured to have low specular and high diffusion components.

Water is represented as a semi-transparent plane, which is implemented by passing a custom alpha variable to the shader, the shader is also specified to have high specular and low diffusion components.