Announcements

May 02 Assignment 3 has been postponed to Friday, May 2.

CAP 6701 - Advanced Computer Graphics

Assignment 2a

Look for updates.

Due Monday, March 24, at 11:45pm.

If you have any questions, check the FAQ first to see if they have already been answered.

Objectives:

Requirements:

Failing to meet any requirements that have no explicit points allocated to them will result in points being taken off. Completing only these requirements, however, is worth no points.
  • General requirements
    • Your program must compile and run successfully on one of the linux machines in CSE313 (lin313-xx.cise.ufl.edu) that supports shader programming: lin313-01, lin313-02, lin313-03, lin313-06, lin313-09, lin313-11, & lin313-12. Note that remote execution doesn't work with shaders remotely.
    • GLSL (OpenGL Shading Language) should be used for shading language.

  • Continuation from before
    Start off with Assignment 1b, additionally meeting the following requirements mentioned in Assignment 1c:
    • From the default position, dragging the middle mouse button up must rotate the object upward, and respectively for the down, left, and right directions.
    • Rotations and scaling should be cumulative. If I begin to rotate/scale the object a second time, the object should not snap back to its original rotation or scale before continuing.
    • As in Assignment 1c, the light needs to be located above, left, behind the camera and must be stationary while the object is rotated.
    You do not need to display the mesh lines or support flat shading for this assignment, but you do not need to remove the previous functionality either. You need to support the following controls
    • Switch between the three modes - standard OpenGL lighting with smooth (Gouraud) shading (no shaders required), Phong shading, and environment mapping - with the TAB key ('\t').

  • Phong shading [45 points]

    Gouraud (standard smooth shading)

    Phong shading
    (The white lines are the vertex normals.)
    • Implement per-pixel lighting (Phong shading). Do not forget to normalize the normals in the pixel shader before computing with them, because linearly interpolated normals are not necessarily of unit length. Unlike the figure above, your program will be displaying an entire loaded mesh, and not just a single quad.
    • The light should be set above, left, behind the camera. For example, you may choose (depending on your scale):
      • light position: (-10, 10, 10)
      • light direction: (10, -10, -10)
      These lighting parameters should be the same for Gouraud shading as well, so that the results of Gouraud and Phong shading are comparable as in the above figures.

  • Environment (cube) mapping [55 points]
    • As in the figure above, draw a large cube around your object with the texture of the environment that will be reflected on the object.
    • Display the polygonal surface using cube environment mapping. In the vertex shader you compute the transformed vertex and normal coordinates. In the pixel shader, you reflect the ray from the eye to the object/model once and then compute the intersection of this ray with the cube. Based on this intersection, you compute the texture coordinates and look up the color from the appropriate texture. No lighting computation is needed.

Sample code:

A simple (skeleton) shader program with which you can start your own can be found here (updated Mar 18). Use TAB to switch between the two different shading modes. Use 't' to toggle texture display. You may reuse any or all of this code. Particularly, note:

  • BMPloader.c: An image loader for loading textures from 24-bit bitmap files. The skeleton program uses ImageLoad() to load one of the provided environment mapping bitmaps.
  • vert.h and frag.h: the vertex and fragment (pixel) shaders, respectively, as C strings.
  • cm_*.bmp: 6 images to be used for the cubic environment mapping.

TIP: (strongly recommended) Instead of hard-coding your shaders as strings (as in vert.h and frag.h), you could store them in plain text and load the full contents of each text file at runtime with fread() in C or istream::read() in C++). This way, you will neither have to add " and \n on every line, nor recompile the code when you edit your shaders.

GLEW (OpenGL Extension Wrangler Library) is to be used for OpenGL extensions. It is already installed on all the lin313-xx machines and requires an additional -lGLEW flag in the makefile to link against the library (as in the sample code).

Debugging tools:

What to submit:

  • README: a file with your name, your 4-digit id, and the project number, briefly describing how to compile and run it and anything else you think I should know. Don't spend too much time on the README.
  • Your source code (one or more files).
  • Your environment mapping images (probably the BMPs from the sample code) (one or more files).
  • makefile: that compiles your source code when invoked without any parameters. That is simply typing make on the command-line should compile the program. The name of your executable must be hw2a.

Note that your program will be tested on many models, and not just cube.off, and will be invoked, for example, as follows:

$ ./hw2a cube.off
More models are available here.

The following is a sample turnin command:
turnin -v  -c cap6701sp08  -p hw2a  README makefile hw2a.c hw2a.h vert.h frag.h PolygonMesh.h *.bmp
Make sure to verify that your files were successfully submitted as shown on the turnin page.