Sheet 03: Rasterization

Exercise: Hello third dimension (5 Points)

Familiarize yourself with the third dimension and the provided source code. While running the program you can interactively rotate the view by dragging with the left mouse button and pan the view by dragging with the right mouse button. Pressing the CTRL key while dragging allows you to control the other degrees of freedom. The rendered image itself should look colorful and a little bit broken. It might look for instance as shown in Figure 1. It could also look slightly different. It visualizes the geometry’s normals. Pressing the keys: F, G or P changes the overall color. Do not change the initial viewing angle of the scene for your submission! It is your task to render the geometry with correct occlusion. The provided code for this exercise already contains parts from the previous task: GLFW and GLEW initialization are encapsulated in classes inside the Utils folder. That folder also contains matrix and vector classes, which will be used in this and upcoming exercises.

Normal visualization with one normal per triangle: the teapot surface appears faceted. Normal colors evaluated at vertices and interpolated across the teapot triangles. Interpolated normal visualization across the teapot surface.

Figure 1: Initial State

You do not need to modify the code in Utils. For this assignment, it is sufficient to edit only the classes in the Hello_Triangles directory. Your shader source files are located in the res subfolder. The GLHelper files assist in compiling these shaders.

Exercise: Hello light source position (10 points)

Before we do the actual shading below we want to visualize the point light source's position by rendering a white cube with side length of 2. Its default position should be at (-35, 35, 35) and by pressing the space bar it should start rotating around the y-axis in the origin at 45 degrees per second. Pressing the space bar again should pause/resume the rotation at its current position. Additionally, the character R-key should reset the animation and all user interactions to the initial state. When the application starts the animation should be paused in the reset state.

Exercise: Hello shading (20 points)

Implement \textit{Flat}, \textit{Gouraud} and \textit{Phong} shading with the \textit{Phong} illumination model as shown in Figure~\ref{fig:shading}. The keys: \texttt{F}, \texttt{G} and \texttt{P} switch to the corresponding technique and use the predefined diffuse colors. The point light source's cube should have a pure white emission color. No other objects emit light. The material's ambient color should be (0.05, 0.05, 0.05), its specular color (1, 1, 1) and the shininess value should be set to 50. The point light source's coefficients should be set to (0.9, 0.9, 0.9) for all three light components.

Additionally, the program must support the following user input:

  • Spacebar: Toggles animation on/off
  • F: Switch to Flat Shading
  • G: Switch to Gouraud Shading
  • P: Switch to Phong Shading
  • R key: Resets the animation and the view

When the application starts, the animation must be paused in the reset state.

Loading

Solution.
Use the mouse to interact with the scene. Spacebar: Toggles animation on/off F: Switch to Flat Shading G: Switch to Gouraud Shading P: Switch to Phong Shading R key: Resets the animation and the view

Text description and demo controls

A teapot stands above a ground plane. A small white cube marks the point light source. The surface nearest the viewer hides surfaces behind it. Flat, Gouraud and Phong shading use the same geometry but different interpolation of the lighting calculation.

Flat shading produces a constant surface normal on each triangle. Gouraud shading interpolates vertex lighting across the triangle. Phong shading interpolates normals and evaluates lighting per fragment, allowing a specular highlight to vary within a triangle. The white light cube can orbit the origin about the y-axis at 45 degrees per second.

Focus the demo with Tab. F selects flat shading, G Gouraud shading, and P Phong shading. Space starts or pauses the light animation; R resets animation and view. Camera rotation and panning currently require mouse dragging.