Skip to main content

CG Class 17, Mon 2019-21-10

2   Term projects

Start thinking. More later.

3   Lighting etc

  1. This Woman sees 100 times more colors than the average person.
  2. Phong lighting model: The total light at a pixel is the sum of
    1. Incoming ambient light times ambient reflectivity of the material at the pixel,
    2. Incoming diffuse light times diffuse reflectivity times a factor for the light source being low on the horizon,
    3. Incoming specular light times specular reflectivity times a factor for the eye not being aligned to the reflection vector, with an exponent for the material shininess,
    4. Light emitted by the material.
    5. That is not intended to be completely physical, but to give the programmer lots of parameters to tweak.
  3. In OpenGL you can do several possible levels of shading. Pick one of the following choices. Going down the list makes the shading better but costlier.
    1. Shade the whole polygon to be the color that you specified for one of the vertices.
    2. Bilinearly shade the polygon, triangle by triangle, from the colors you specified for its vertices.
    3. Use the Phong lighting model to compute the color of each vertex from that vertex's normal. Bilinearly interpolate that color over the polygon. That is called Gouraud shading.
    4. Bilinearly interpolate a surface normal at each pixel from normals that you specified at each vertex. Then normalize the length of each interpolated normal vector. Evaluate the Phong lighting model at each pixel from the interpolated normal. That is called Phong shading.
  4. Maureen Stone: Representing Colors as 3 Numbers (enrichment)
  5. Why do primary schools teach that the primary colors are Red Blue Yellow?

6   Chapter 6 programs

  1. Chapter 6

    1. wireSphere: wire frame of recursively generated sphere
    2. shadedCube: rotating cube with modified Phong shading
    3. shadedSphere1: shaded sphere using true normals and per vertex shading
    4. shadedSphere2: shaded sphere using true normals and per fragment shading
    5. shadedSphere3: shaded sphere using vertex normals and per vertex shading
    6. shadedSphere4: shaded sphere using vertex normals and per fragment shading
    7. shadedSphereEyeSpace and shadedSphereObjectSpace show how lighting computations can be carried out in these spaces
  2. Summary of the new part of shadedCube:

    1. var nBuffer = gl.createBuffer();

      Reserve a buffer id.

    2. gl.bindBuffer( gl.ARRAY_BUFFER, nBuffer );

      1. Create that buffer as a buffer of data items, one per vertex.
      2. Make it the current buffer for future buffer operations.
    3. gl.bufferData( gl.ARRAY_BUFFER, flatten(normalsArray), gl.STATIC_DRAW );

      Write a array of normals, flattened to remove metadata, into the current buffer.

    4. var vNormal = gl.getAttribLocation( program, "vNormal" );

      Get the address of the shader (GPU) variable named "vNormal".

    5. gl.vertexAttribPointer( vNormal, 3, gl.FLOAT, false, 0, 0 );

      Declare that the current buffer contains 3 floats per vertex.

    6. gl.enableVertexAttribArray( vNormal );

      Enable the array for use.

    7. (in the shader) attribute vec3 vNormal;

      Declare the variable in the vertex shader that will receive each row of the javascript array as each vertex is processed.

    8. The whole process is repeated with the vertex positions.

      Note that the variable with vertex positions is not hardwired here. You pass in whatever data you want, and your shader program uses it as you want.

7   Computing surface normals

  1. For a curved surface, the normal vector at a point on the surface is the cross product of two tangent vectors at that point. They must not be parallel to each other.
  2. If it's a parametric surface, partial derivatives are tangent vectors.
  3. A mesh is a common way to approximate a complicated surface.
  4. For a mesh of flat (planar) pieces (facets):
    1. Find the normal to each facet.
    2. Average the normals of the facets around each vertex to get a normal vector at each vertex.
    3. Apply Phong (or Gouraud) shading from those vertex normals.