Comp 360 Lab 3: Hidden Surface Removal and Shading Models

Due Thursday, December 1, at 11:59 PM

Overview

In this project you will write a program to load and display 3-dimensional polygonal models. You will be provided with a viewer that performs rendering with the OpenGL library. You will implement two other renderers for hidden surface removal: one using Z-buffers, and one using binary space-partition (BSP) trees. This project is worth 100 points.

Specification

Your program will take a single command-line argument: the name of a text file that defines a scene to render. The format of the text file is given in the section "Scene File Format," below. Under the Windows OS, the path to a file is passed as an argument to a program if the program is opened by dragging the file onto the program's icon.
The user can interact with the program by pressing certain keys as specified below. Pressing keys allows the user to switch renderers, switch shading models, or move the camera.

Polygonal Model Viewer using OpenGL

The first renderer using OpenGL has been provided for you. You can use this renderer as a comparison for the other renderers.
The OpenGL renderer should respond to the following keys.
Additionally, the user should be able to move the camera within the OpenGL renderer.

Free Camera Movement (10 Points)

The user should be able to move the camera (that is, the viewing point or eye point) in a way similar to a 3D first-person shooter game- for example, Quake or Unreal Tournament. The camera movement controls are given below.
The camera has a local coordinate system defined by three vectors and a point (see figure 1). The eye is the center point for the coordinate system. The up vector points in an upward direction from the eye. The right vector points towards the right of the camera. The forward vector is the cross product of up and right. The forward vector also corresponds with the direction that the camera is facing. The initial settings for this local coordinate system is given below:
vector.jpg
Figure 1: Camera coordinate system.
You should implement the following specific controls.
You should be able to use these controls to view a model from any angle. Note that the viewpoint and viewing frustum should be shared between all renderers. The user should see essentially the same thing as he changes the rendering algorithm.
Your projection parameters should correspond to setting the viewing matrix using the call glFrustum(-1,1,-1,1,1,100000). For a description of glFrustum, please refer to the following reference.

Static scene renderer: Z-Bufffer Algorithm (45 Points)

In the Z-buffer renderer, you will duplicate in software what OpenGL does in hardware. You will also implement a third shading model, Phong shading. The algorithm and data structures you need will be described in class.
Within the Z-buffer renderer, you may only use OpenGL to draw individual pixels (with glBegin(GL_POINTS)) or buffers of pixels (with glDrawPixels()).
The Z-buffer renderer should respond to the following keys.
While the Z-buffer renderer is enabled, the program should ignore camera movement input.

Dynamic scene renderer: BSP Trees Algorithm (45 Points)

The final renderer is based on BSP-trees. When you load a polygonal model at the beginning of the program, you should calculate the BSP-tree representation of the model. Once again, the algorithm and data structures you need will be covered in class.
To render a BSP tree, you should project polygons onto the viewing plane and draw them in 2 dimensions using the GL_TRIANGLES primitive. This means all your OpenGL calls should be made within an orthographic projection. The BSP tree should also handle all depth issues between different polygons, so GL_DEPTH_TEST should be disabled as well. In addition, your BSP tree renderer must perform its own lighting calculations and set the color of each vertex manually. Thus GL_LIGHTING should be disabled while this renderer is active.
The BSP tree renderer should respond to the following keys.
The user should be able to move the camera within the BSP tree renderer.

Summary

The following table summarizes the shading models and features that must be supported by each renderer.
Renderer Shading Model Features
Flat Gouraud Phong Wireframe Rendering Camera Movement
OpenGL Yes Yes No Yes Yes
Z-Buffer Yes Yes Yes No No
BSP Trees Yes Yes No No Yes

When started, the program should use the OpenGL renderer with Gouraud shading.

Implementation Notes

What To Turn In

Create a directory lab4. This directory should contain your source code and all files needed to build your program in Visual Studio or CMake. Also include a README file containing:
Zip up the folder and follow the submission instruction on the class webpage to submit your zip file.

Scene File Format

File Format Overview

Input files are ASCII text files containing a series of numbers separated by spaces (a space is any character that causes the C library function isspace() to return true.) The input file has three parts:
  1. Material Attributes
  2. Lighting Attributes
  3. Polygon Data

Material Attributes

The first seven values in the input file specify the material properties of all polygons in the model. These properties appear in the input as follows. As usual, colors are specified by their red, green, and blue components.
  1. The object's ambient coefficient. (Floating point value between 0 and 1.)
  2. The object's diffuse coefficient. (Floating point value between 0 and 1.)
  3. The object's specular coefficient. (Floating point value between 0 and 1.)
  4. The object's specular exponent. (Floating point value.)

Lighting Attributes

After the definition of material properties, the input file will contain definitions of at least one light source. The scene's lighting attributes are given in a format identical to the lighting information in lab 3 input files.
  1. The scene's ambient light color. (Three floating point values.)
  2. The number of lights in the scene - at least 1. (One integer.)
  3. For each light
    1. The light's position in space. (Three floating point values.)
    2. The light's color. (Three floating point values.)

Polygon Data

Polygon data is given in two sections. In the first section, we enumerate the coordinates for all the vertices that will be used in the polygons. Coordinates are given as floating point triples. In class we called this data the geometry of the model.
In the second section, the polygons are given as sets of integers, with three integers per polygon (our models consist only of triangles). Each integer is an index into the array of vertices defined in the geometry section. Note that indices are counted beginning at zero. In class this data was called the topology of the model.
Formally, the polygon data are given as follows.
  1. The number of unique vertices in the model. (One integer.)
  2. For each vertex
    1. The vertex's position in space. (Three floating point values.)
  3. The number of polygons in the model. (One integer.)
  4. For each polygon
    1. The indices into the vertex array of the vertices of the polygon. (Three integers.)
Below is an example of the polygon data for a small model. (Our input files do not contain comments.)
4            // Number of vertices
0 0 0      // Coordinates of 0th vertex
0 0.1 0.1       // Coordinates of 1st vertex
0.1 0 0.1       // Coordinates of 2nd vertex
0.1 0.1 0       // Coordinates of 3rd vertex
3            // Number of total triangles
0 1 2      // First polygon, consisting of 0th, 1st, and 2nd vertex
0 1 3      // First polygon, consisting of 0th, 1st, and 3rd vertex
0 2 3      // First polygon, consisting of 0th, 2nd, and 3rd vertex

Note that triangle vertices are ordered counterclockwise. That is, a polygon's vertices are listed in counterclockwise order around the outward-facing normal of the polygon. You will need to use this information to determine the normals of each polygon.
Below are links to example input files of various sizes.



File translated from TEX by TTH, version 3.85.
On 05 Nov 2009, 03:09.