CMPS-3480 Computer Graphics
Lab-13

Overview:

Elements:

1. Applying a circular texture map to an object.

   We will use lab6.cpp and OpenGL texture mapping.

   a. take a picture of a coin
   b. convert the picture to a PPM file
   c. define an Image object for your coin picture
   d. define an OpenGL texture-map
   e. generate some points-on-a-circle
   f. construct a circular triangle fan
   g. find the texture coordinates of each vertex
   h. apply the texture coordinates to each vertex
   i. adjust the texture center and radius to fit the object
   j. admire the beauty

this coin was found in my backyard
coin picture taken with my phone camera



2. Texture-map a ray-traced triangle.

   We will use lab10.cpp - with triangles added from lab-10

   a. get a texture-map, such as selfie-dog
   b. define an Image object for your picture
   c. define in Object class a flag indicating texture-mapped triangle
   d. define in Object class: Vec texCoord[3]
   e. define in Object an Image pointer
   f. set an Image pointer to your texture-map
   g. render your triangle
   h. at intersection, generate the barycentric coordinates of the hit-point
   i. define in Object class u,v,w barycentric coordinate save area
   j. in trace, check for textured triangle
   k. scale the 3 texture-coordinates by the 3 barycentric values
   l. sum the values
   m. get the color address in the data stream
   n. set the close-hit color to the data stream color
   o. admire the beauty


Phong shading model

The process above for texturing a triangle has many of the components
needed to apply Phong shading to a triangle.

1. Define in the Object class: Vec vertNormal[3];
   Store the surface normal of each triangle vertex here.

   Some parts of each normal may be entered by-hand into an array.

2. For the vase and bowling pin:

      a. For each vertex of the object...
         - Build the vertex normal from the vertex position.
              This can be done because the object is centered at the origin.
              The position vector points directly away from the center
              of the object.
         - Set the y-value to zero.
         - Normalize the vector.
      b. At triangle intersection, capture and save the barycentric u, v, w.
      c. In trace, check if the triangle hit object has Phong shading.
      d. Scale the 3 vertex normals by the barycentric coordinates.
         Sum the total.
         The result will be one vector.

         Psuedocode:
            phong_norm.x <--- vec[0].x*u + vec[1].x*v + vec[2].x*w
            phong_norm.y <--- vec[0].y*u + vec[1].y*v + vec[2].y*w
            phong_norm.z <--- vec[0].z*u + vec[1].z*v + vec[2].z*w

      e. Normalize the vector.
      f. Store this vector as your close-hit normal value.
      g. Continue with the rest of the trace function.

3. The object should look smoother, but not perfect.

4. For a better look, you must modify the normal y-value at each level
   of the vase or bowling-pin. You can setup an array for this just like
   the array that holds the levels and radii.
   Give it a try.

5. The study of Phong shading requires setup of at least one scene that
   shows an extreme close-up of your object.