Fog MP

In this MP you will

  1. Auto-generate a terrain (with no user input)
  2. Respond to keys to move and rotate the camera
  3. Add user-controllable fog

This MP is elective, with no core components. It assumes you have already completed the Flight MP.

1 Overview

You will submit a webpage that has

Submit an HTML file and any number of js, glsl, json, css, and image files. Do not include spaces in file names as the submission server does not process them well.

You are welcome to use a JavaScript math library, such as the one used in in-class examples or others you might know.

2 Specification

2.1 Everything the Flight MP does

This MP is an extension of the Flight MP; it should have all the inputs, algorithms, and operations of that MP.

2.2 Fog

Have the background be white or a pale off-white color. Use that same color for the fog.

Have fog that falls off with an exponential fall-off: v=efdv = e^{-fd} where vv is how visible objects are, ff is a fogginess parameter and dd is distance between camera and fragment. For the common projection matrix, dd can be approximated as 1 / gl_FragCoord.w. Initially the fog density parameter should be chosen such that some terrain is visible but the presence of fog is obvious.

Fog should be applied after lighting. Compute the full lit color and mix that with the fog color based on the computed visibility parameter.

2.3 On-press keys

In your keydown listener add handling a few keys:

Keep all of the previous key responses from Flight too.

3 Evaluating your results

On both your development machine and when submitted to the submission server and then viewed by clicking the HTML link, the resulting page should show a random terrain with visible fog. Holding down the WASD and arrow keys should fly around the terrain, with perceived fogginess decreasing as terrain is approached. Typing the FGH keys should change fog presence and density. One example might be the following:

A video of an example result, with keys being pressed displayed in the video. Note the flight happens as keys are held while the fog changes happen as they are typed. Note also that the terrain vanishes from view with sufficient distance or fog density.