scary shaders

Assigned: Friday, April 28th
Due: Monday, May 22nd, by 9:59 AM

Goals

By the time you're done with this assignment, you will have learned:

  1. How to read and process simple geometric mesh structures.

  2. How to use the OpenGL Shading Language to perform simple vertex processing.

  3. How to use the OpenGL Shading Language to implement basic per-pixel lighting models.

background

In this project we'll be writing a simple mesh viewer that makes extensive use of vertex and fragment shaders. Your project should be able to load a mesh, display it with an interactive camera, and then allow the user to select between the assigned vertex and fragment shaders and the fixed-functionality OpenGL pipeline.

We are providing several sample models for you to use during testing. These models use a very limited subset of the OBJ file format. In particular, they contain only vertices (three floating point coordinates prefaced with the letter "v") and triangular faces (three integer vertex indices prefaced with the letter "f"). You should note that the face specifications assume that vertices are indexed from one, not zero. You are only responsible for displaying triangular meshes specified in this manner, although you're welcome to implement more of the OBJ format for fun.

Getting Started

We've already provided you with a sample OpenGL application that makes limited use of the programmable pipeline. It demonstrates how to get a basic GUI program up and running with our support libraries, how to load and bind GLSL shaders, and how to draw and animate a simple polygon using a 2D orthographic projection. You may want to add menus or toolbars to your program: the support library has documentation that will help you. If you don't read the documentation, you will likely end up wasting time duplicating functionality that has already been implemented for you.

If you run into trouble while working on your project, you have several avenues available to you. Ask questions in lab, post a message on the course discussion group, or come to the instructor's office hours.

Using other systems or frameworks

Because libgfx is extremely platform independent, using it ought to allow you to develop your code on one system and trivially port it to another. However, we only officially support the library on the iMac machines in the College 8 lab, so if you run into machine- or platform-specific problems on another system, we may not be able to help you. In order for your project to be graded in lab, you must make sure that it compiles and runs on the lab machines. If your project does not compile when we attempt to grade it, you will receive very few points, if any.

You may use a different GUI toolkit (e.g., GLUT, SDL) if you like. If you decide to do this you must:

  1. Cleanly separate your GUI code from your project implementation so that the graders can easily find it
  2. Turn in all the files necessary to compile and run your program
  3. Clearly explain in your Readme file how to compile and run your code with your GUI toolkit of choice.

It is also possible to develop your project on another platform. However, you must contact the instructor at least 72 hours before the due date and make separate arrangements for the demo and grading of your program. Generally speaking, the instructor is willing to travel to any room in the Baskin Engineering and Engineering 2 buildings to see your demo, but will not venture any farther from the comfortable confines of his office.

You should note that OpenGL 2.0 and the OpenGL Shading Language are still not universally supported on all platforms and hardware configurations. Therefore, we strongly suggest that you plan to complete this assignment in the class lab.

Requirements

All students must implement the following required features.

[10 points] Basic Object Viewing
Your program should be able to read an OBJ file and render the corresponding polygonal mesh. You should automatically determine a sensible camera configuration and frustum size based on the dimensions of the mesh when it is loaded. You should also provide some form of interactive camera control so that the mesh can be viewed from any position and direction.

[15 points] Normal Processing
The OBJ files we have provided for you do not contain any normal information. To facilitate smooth shading with support for sharp corners, your program should calculate normal vectors using the per-vertex per-triangle scheme discussed in lecture. You should implement some automatic system to test for creases, and modify the normals across those edges appropriately. Additionally, you should provide some way to visualize the vertices for which the per-triangle normals do not agree.

[15 points] Pulsing Meshes
One simple yet visually interesting way to animate a mesh is to make it "pulse" by translating each vertex some fixed amount in its normal direction. By linearly interpolating each vertex position between v-cn and v+cn (where c is a constant) and then interpolating back in the opposite direction, we can make the mesh bulge outward and then recede in on itself in a smooth fashion.

You should implement this pulsing in a vertex shader (you will get no credit for transforming the vertices in your application). You should provide two separate modes of transformation: one in which all vertices are transformed at the same speed, and another in which some vertices move faster than others (which will make the mesh pulse in a seemingly random fashion).

[20 points] Phong Illumination
You should also implement per-pixel Phong Illumination in a fragment shader. You should support illumination from at least two point light sources with different positions and chromatic intensities, and also account for physical (quadratic) attenuation on some distance scale. Additionally, you should provide a simple way to toggle each of the ambient, diffuse, and specular intensity terms on and off in real-time, and also allow the user to interactively switch between the Phong and Phong-Blinn specular illumination models.

[10 points] Gooch Shading
You should also implement per-pixel Gooch Shading in a fragment shader. You may choose any cool and warm colors you like, but they should follow the general structure presented in lecture.

[10 points] Positional Shading
One way to shade a mesh that does not involve any lighting calculations is to assume that the mesh is scaled and centered inside the unit RGB color-space cube. We may then trivially assign a color value to every point on the mesh by associating its three-dimensional position with the corresponding RGB color. You should implement this "positional" shading on a per-pixel basis in a fragment program.

[20 points] Coding and Presentation
Graphics is fundamentally a visual field, so it's important that your project be pleasant to look at and have a clean interface. Likewise, we expect all code to be reasonably well designed and written. In particular, ugly, inscrutable, or ridiculously inefficient code and/or user interfaces will be heavily penalized.

Tips and Hints

Reference Implementation

Your incredibly talented and dilligent TA has provided a reference implementation for you to play around with. Note that your program is not required to exactly duplicate all the functionality present in this implementation. Rather, its purpose is to give you a general idea of what your program should do. Binaries are currently available for Windows and OS X.

The controls for the reference implementation are as follows:

pos bulge

Handing in your Project

Follow all handin instructions carefully. If you do not hand in all of the required files in the proper fashion, your project will not be graded and you will receive no points.

You must turn in the following files:

To actually turn in your finished project, follow the hand-in instructions that we have provided.

Grading

During grading, we may test your program with different data sets than those we have provided to you. Therefore, you should ensure that your code is reasonably general and provides a nice interface to load different mesh files.

Before you begin work, you should make sure that you've read the policies on grading and academic integrity in the course syllabus. Any questions as to what constitutes acceptable behavior during the development of your project should be directed to the instructor via email or the course discussion group.

Late projects will not be graded and will receive no credit. If you believe you will be unable to finish your project by the due date, you should contact the instructor at least 72 hours in advance to discuss the particulars of your situation.

A required part of the grading process will be a live demo of your finished project. You will not receive any points for your project until it has been demoed. Demos will typically occur during your scheduled lab session and will take about 10 minutes per student. However, you may arrange to demo your program to the instructor if you prefer. Such arrangements must be finalized at least 72 hours before the project is due.