Textures MP

In this MP you will

  1. Auto-generate a terrain (with no user input)
  2. Have two shader programs, one for color and one for texture
  3. Let the user change the color and texture

This MP is core, with no elective components. It assumes you have already completed the Terrain 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 Terrain MP does

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

2.2 Material entry

Add one more <input type="text" ...> in your HTML. Support three types of entry:

Respond to changes in the text entry field as soon as they occur (i.e., without waiting for a button event). Do this by parsing the material test in a change event listener on the text entry input; leave the terrain generation on the click event listener you already have on the button input.

2.3 Two shader programs

Compile and link two different shader programs during setup, picking between them each frame based on the results of the last material entry change listener.

The non-texture shader program should use a uniform vec4 RGBA color and have both diffuse and specular light. The alpha channel in the color should be treated as a an amount of specular shine to add, not as opacity, and should not be copied into the output image. Instead, have the specular intensity (computed via either the Phong or Blinn-Phong model) by multiplied by 3α3\alpha. In the real world light that is used to create a shine is not available to create diffuse light; simulate this by multiplying the diffuse intensity by (1α)(1-\alpha).

The with-texture shader program should use a uniform sampler2D texture and in vec2 texture coordinate. It should have diffuse light only with the diffuse color coming from the texture, no specular light at all. You should modify your terrain generation to place a texture coordinate with every vertex, with (0,0) in one corner and (1,1) in the other. Because the non-texture shader will ignore attributes it doesn’t have an in variable for, you can use this same modified geometry for both shaders.

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. One example might be the following:

A video of an example result. The two textures used are luther.png and testgrid.png, both of which are pre-loaded on the submission server.