Difference between revisions of "Project4Fall13"

From Immersive Visualization Lab Wiki
Jump to: navigation, search
(3. GLSL Shader Programs (50 Points))
(3. GLSL Shader Programs (40 Points))
Line 41: Line 41:
 
==3. GLSL Shader Programs (40 Points)==
 
==3. GLSL Shader Programs (40 Points)==
  
Under construction.
+
<!--
 +
In this part of the project, you will need to add support for a water reflection-like effect for the 3D objects you used in the prior homework projects (specifically: cube, sphere, teddy, bunny, cow, teapot).
 +
 
 +
For Windows and Linux users, in order to use OpenGL extensions, you should [http://elf-stone.com/glee.php download GLee] and add the glee.h and glee.c files to your project files, or tell the linker to link with the GLee library (glee.lib or glee.dll for Windows, or libglee.a/libglee.so for Linux). OSX users will not need GLee, as OpenGL extensions are available by default.
 +
 
 +
We provide a [[Media:shader-class.zip|sample shader class]] and [[Media:shaders.zip|three sample combinations of vertex and fragment shaders]] for you to familiarize yourself with GLSL shader programming. For this exercise, extend the <tt>diffuse_shading</tt> shader to slightly move the vertices of your geometry around in random directions, by using a vertex shader. You will also need to slightly alter the colors you are rendering, by (pseudo-)randomly modifying the vertex-associated colors.
 +
 
 +
Trigonometric functions, such as sin or cos are good candidates to make something oscillate.
 +
 
 +
GLSL does not have a random number generator per se, but one can be simulated with a function such as the following:
 +
 
 +
<pre>
 +
float rand(vec2 co)
 +
{
 +
  return fract(sin(dot(co.xy,vec2(12.9898,78.233))) * 43758.5453);
 +
}
 +
</pre>
 +
 
 +
The function takes in two seed values, for which it generates an "unpredictable" number.
 +
 
 +
In your GLUT program, you should declare a uniform variable for your shader, which will consist of a time step, or time stamp, which the shader code can use to create an image just for this particular frame.
 +
 
 +
You will get points for the following things:
 +
 
 +
* Create GLSL vertex and fragment shaders for the point light from Part 1 ('''15 points''').
 +
* Create GLSL vertex and fragment shaders for the spot light from Part 1 ('''15 points''').
 +
* Create GLSL vertex and fragment shaders with support for both light sources concurrently ('''10 points'''). For this you will have to merge the code of the two shader programs into one shader program. You would determine the final color by averaging the contributions of the light sources (cumulative_light = (light_a + light_b)/2).
 +
* Demonstrate the scene with the two spheres from Part 1 with optional per-pixel shading: add support for the 'g' key to toggle your GLSL shaders on or off, to demonstrate the difference between OpenGL's built-in (per vertex) shading and your custom per-pixel shading. ('''10 points''')
 +
 
 +
-->
 +
 
 +
'''Notes'''
 +
* While most CSE lab computers do, some older computers or simpler graphics cards do not support GLSL. Be aware that this might be a problem with your personal computer.
 +
 
 +
Here are a few URLs with tutorials on how to write GLSL shader code.
 +
 
 +
* [http://www.lighthouse3d.com/opengl/glsl/ Lighthouse3D GLSL tutorials]
 +
* [http://www.clockworkcoders.com/oglsl/tutorials.html Clockworkcoders GLSL tutorials]
 +
* [http://www.khronos.org/files/opengl43-quick-reference-card.pdf GLSL quick reference]
 +
* [http://www.opengl.org/documentation/glsl/ GLSL reference documentation]
  
 
==4. Extra Credit (10 Points)==
 
==4. Extra Credit (10 Points)==

Revision as of 22:30, 25 October 2013

Contents

Project 4: Light and Shade

This project is on OpenGL lighting and shading, and includes GLSL shader programs.

This project is due on Friday, November 1st at 1:30pm. It will be discussed in Center Hall 105 on Monday, October 28th at 3:00pm.

Note that GLSL shaders, which are needed for part 2 of the assignment, will be covered in class on Tuesday, October 22nd.

1. Mouse Control (20 Points)

Start by reviving your application from assignment 2: you will need to be able to display the cube, as well as the following three 3D models into your application and display them at reasonable sizes (screen filling). The function keys should switch between the models.

These are the models you need to be able to load, you will have to unzip them to get at the OBJ files. Note that some of them are different files than before, as we now need files with normals. The OBJ reader we gave you in project 2 already parses normals.

You are welcome but not required to support the keyboard commands from assignment 2 to move around the models. However, you will need to add mouse control, which will allow rotating the model about the center of your OpenGL window, as well as scaling the model up and down. The left mouse button should be used for rotation, the right mouse button should zoom in and out when the mouse is moved up or down while it is pressed.

This video shows how the trackball-like rotation should work. We provide sample code for the trackball rotation. You will need to adapt it to the syntax of your matrix and vector classes and get it to work within your application.

To access the mouse x and y coordinates, you will need to use GLUT's callback functions glutMouseFunc(), which gets called when you press a mouse button, and glutMotionFunc(), which gets called constantly while you hold the button down and move the mouse. Note that successive trackball rotations must build on previous ones; at no point should the model snap back to a previous or default position.

2. OpenGL Lighting and Shading (40 points)

Write classes to manage light and material properties (Light and Material). As a starting point, refer to the relevant sections in Chapter 5 of the OpenGL Programming Guide, as well as the OpenGL Lighting FAQ.

Associate material properties with each of the four 3D model files: two of them should be shiny, and the other two should be shiny and diffuse - you choose which. Use colors other than white. (10 points)

Create three light sources: one directional light, one point light and one spot light. The spot light should always point towards the center of the OpenGL window. Give them initial positions and colors. Each of them must have a different position and color. The spot light should have a spot width narrow enough so that it only illuminates a small part of the surface of the models. Toggle each of them on and off with one of the number keys: 1, 2, and 3. Rotate those light sources which are on with the 3D model.

Add a freeze mode for the 3D model and toggle it with the 'm' key: when it is enabled, the model will not respond to mouse control commands and instead stay in its last orientation and size. In this mode only the enabled light sources rotate and zoom in and out.

Notes:

  • OpenGL multiplies light position and direction with the Modelview matrix when they are set. Therefore, you need to modify the Modelview matrix with your mouse control routines to rotate the light sources, independently for each light source.
  • To ascertain that the normals of your 3D models will survive zoom operations correctly, you should use the following OpenGL command: glEnable(GL_NORMALIZE).
  • By default, OpenGL uses a simplified model for the calculation of the highlights. For a more realistic model add this command to your code: glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE).

3. GLSL Shader Programs (40 Points)

Notes

  • While most CSE lab computers do, some older computers or simpler graphics cards do not support GLSL. Be aware that this might be a problem with your personal computer.

Here are a few URLs with tutorials on how to write GLSL shader code.

4. Extra Credit (10 Points)

Under construction.