CPSC 453 - Intro to Computer Graphics
TA Page - Fall 2008
| Instructor: | F. Samavati |
| Homepage: | CPSC 453 |
| TA: | Luke Olsen |
| Tut02 TA: | John Brosz (TA page) |
| Email: |
|
| Lab time: | Tut01: MW @ 12pm in MS239 |
| Tut03: MW @ 2pm in MS239 |
Assignments
| Released | Due | Demo Timetable | ||
| Assignment 1 | Fractal Shop | Sept. 19 | Oct. 5 @ 11:59pm | |
| Assignment 2 | Modeling | Oct. 6 | Oct. 26 @ 11:59pm | |
| Assignment 3 | 3D Mesh Viewer | Oct. 25 | Nov. 16 @ 11:59pm | |
| Assignment 4 | Ray-Tracing | Nov. 16 | Dec. 7 @ 11:59pm | No demos Competition details |
Submission guidelines:
- We'll be using the
submitsystem. The syntax (checkman submit) is:
submit [ -a assign ] [ -c course ] files...
- Combine all files into a single archive file with TAR or ZIP. For example, to create a tar.gz archive of files in a directory with relative path ./codedir/, use the following commands:
tar -cf codedir.tar codedir/* gzip codedir.tar
- Don't submit compiled object files (*.o), Qt MOC files (moc_*), executables, etc. Just code and a Makefile is enough.
- Code must be written in C/C++, with rendering in OpenGL and window management via GLUT or Qt.
- Any external code must be approved by the instructor or TA, and must be properly cited in the documentation (source code and readme).
- Failure to adhere to the guidelines may result in a grade of zero and possibly academic sanctions by the department or University.
Lab Notes
For some labs I'll be typing up notes and posting them here.
Code posted so far:
- GLUT: helloGL.cpp + Makefile
- Qt: barebones.tar.gz
- Trackball exercise: trackball-ex.cpp
- Surface generation: surfaceGen.cpp
- Unprojection: unproject.cpp
News
A4 marks posted
Click title to readOkay, so this is the last post of the year. You can find your mark below. Let me know if you have any questions or would like to see a breakdown of your mark.
Happy holidays and best in 2009!
Vote for your favorite!
Click title to readThe submissions for the ray tracing competition are now live, so check it out and vote for your favorite image.
Also, if you missed the final review session you can find the notes here.
This will probably be the last post of the semester, so good luck to all of you on the final exam and the rest of your Comp Sci career! It has been great being your TA.
Dec. 3 lab - A4 Q&A
Click title to readThe final lab of the semester is devoted to working on Assignment 4. A few reminders:
- The final review is next Monday, Dec. 8 @ 4pm. The room is ST126.
- The last assignment is due on Sunday @ 11:59pm. Use the submit system as usual.
- Make sure you include several images in your README file to illustrate all implemented features (required and bonus). Also, draw attention to the features in the write-up or the image caption.
Ray tracing competition
As mentioned previously, we're holding a competition to see who can generate the best image with their ray-tracer. The winner will be chosen by John Brosz and myself, and we will create a web gallery of the images.
- If you want to participate, email your best image by the end of Monday the 8th.
- Prizes: junk food, Half-Life 2 + Episode 1 on Steam, and a letter from Prof. Samavati confirming your victory.
- The winner will be notified via email by the end of next week.
Dec. 1 lab - More ray tracing primitives
Click title to readToday I covered a few more intersection tests for your assignment, including disks, cylinders, cones, toruses, and polygons.
We also talked about how to do your lighting calculations (use global ambient term, clamp the color intensities at 1), antialiasing (fire 4 or more rays through each pixel, take the average as the pixel's final color), and adding a variable to the materials to indicate whether a surface is reflective (boolean value) and/or how reflective it is (floating point value).
Assignment 3 marks posted
Click title to readYou can find your marks below. Let me know if you have any questions.
Nov. 26 lab - Intersection testing
Click title to readIn today's lab we went through a few examples of intersection testing for ray-tracing, including: spheres, planes, triangles, quads, and axis-aligned bounding boxes. There aren't any online notes for this since it is mostly covered in the course notes.
A few comments:
- If you want to get full marks for the MD2 bonus, you'll need to implement smooth-shading. Translation: you'll need to have per-vertex normals and interpolate them across the triangle, which requires barycentric coordinates. The ray-triangle intersection test shown today gives you barycentric coords.
- You can do ray-quad intersection by splitting the quad into two triangles (or in general, you can find intersections with convex polyhedra by splitting into triangles). However, there are problems with this approach, mostly in that the barycentric coords of two adjacent triangles are not smooth. See the following image (click to enlarge):
For more information:
I posted up some notes on how to use transparency (alpha blending) in OpenGL today. It probably won't help much for your last assignment, but may be useful for you someday.
Nov. 24 lab - Ray generation and scene description
Click title to readIn today's lab, I went into some of the nuts and bolts of the ray-tracing engine. The material is based around the pseudocode for tracing a single ray covered in lecture. Assuming such a framework, then you need to wrap some scene description and ray generation around it. [See the notes here.]
For representing the generated image, you can use the provided PPM files*. Alternatively, you might want to look into the QImage class, which gives you fairly fast pixel access as well as the ability to easily save to a variety of file formats.
* Note that there is a small bug in the pixelmap.cpp file. There should be a space between the magic number 'P6' and the image width (near the end of the file, the ostream operator). You can fix it yourself, or get a fixed version here.
A4 update
Click title to readI was away for Wednesday's lab, but I'm sure you were in capable hands with John Brosz. As you've seen, the fourth assignment has been released. As usual, I recommend that you start working on it ASAP -- it is usually considered the hardest assignment by students, and there are many little issues to come across and debug.
Also be sure to read the requirements and submission procedure carefully. It can be a fun assignment if you put some time into it -- once you get the basics working, its fun to play around with different settings, rays, objects, and so on. Keep your eyes on this page for details on a ray-tracing competition!
Nov. 12 lab - A3 work session
Click title to readToday's lab was mostly devoted to Assignment 3 Q&A. Good luck finishing it up for Sunday, and don't hesitate to fire me an email if you get stuck on something.
Important note
Regarding the assignment requirement that states "Display the object inside and at the center of the viewport," it has been clarified to me that this means you should normalize the model -- that is, scale and translate each loaded model so that it lies within a fixed portion of the viewport.
Typically this involves finding the bounding box of the model (i.e. the min/max values of each coordinate) and the centroid (average of all vertices), and then scaling and translating the model so that it fits into a unit box at the origin. You're free to define another standard coordinate system (for example, so that the model is standing on the x-z plane), but be sure to document your decision.
Nov. 5 lab - A3 bonus stuff
Click title to readIn today's lab, we had a pizza and beer party to celebrate Obama's victory. You should have been there!
...
I'm kidding of course. No one wanted to celebrate that.
Since a lot of people were off celebrating their midterm victory (or at least survival), I decided to cover bonus-related material for the assignment. This includes using timers for animations, texture mapping, and using the mouse for affine transformations.
Nov. 3 lab - Lighting
Click title to readIn today's lab I covered lighting and shading in OpenGL. This is a big topic for which the theory will be covered later on in the course, so the material I presented was more focused on simply how to get it working for your assignment.
Also, if you're looking for the link to the various material parameters, here's the link:
http://www.cs.utk.edu/~kuck/materials_ogl.htm
Graphics in the real world
In case you ever wonder, "Is the stuff we're learning in this course actually used in industry?", check out this bullet-point blurb from the Xbox Arcade game Vigilante 8:
Granted, that is a port of a 10-year old game, but still... :). That's practically your last assignment!
Oct. 29 lab - Assignment 3
Click title to readIn today's lab we went through the requirements for the third assignment, an MD2 mesh viewer.
See the lab notes here.
Assignment 3 posted
Click title to readThe third assignment has now been posted. You will be writing a program to load and render a 3D polygon mesh, based on the MD2 file format.
Due: Nov. 16 @ 11:59pm.
Oct. 22 lab - Tensor product subdivision
Click title to readToday I went through an example of how to compute tensor product subdivision on a control point grid. The example I used was linear subdivision, in which existing points remain in the same place and new points are inserted between the old points. Hopefully this will help you to code up the cubic B-spline tensor product surface for the assignment.
You can find the notes here.
The demo timetable for the second assignment is also available now. Demos will take place during lab time next Monday (the 27th).
Oct. 20 lab - Unprojection
Click title to readIn today's lab I covered a few different topics:
- Mapping window coordinates to world coordinates is a fundamental problem in graphics, one with many different approaches of varying complexity. So far we've looked at a couple of ways to set up your projection so that world coordinates can be easily computed (eg. the virtual trackball mapping to [0,1]x[0,1]). In lab today we looked at a more generic way to do it based solely on the current viewport and modelview/projection matrices, using
gluUnProject(...). Here's a sample code snippet:
// assume you have mouse coordinates mx & mz GLint vp[4]; GLdouble pm[16], mvm[16]; glGetIntegerv(GL_VIEWPORT, vp); glGetDoublev(GL_MODELVIEW_MATRIX, mvm); glGetDoublev(GL_PROJECTION_MATRIX, pm); GLdouble wx, wy, wz; gluUnProject(mx, win_h - my, 0, mvm, pm, vp, &wx, &wy, &wz); // now wx & wy contain the x,y coordinates in worldspace of your point.
- Sample code: unproject.cpp
- Note that this only works, in the form presented above, for orthographic projections and tranformations confined to the x-y plane. To see for yourself, replace the rotation in unproject.cpp with a rotation around the y axis and see what happens. The reasons for this are beyond the scope of this lab, so just trust me for now. :-)
- I went through the tensor-product control point generation code that was posted over the weekend (surfaceGen.cpp). As a coding exercise, change the code to render a surface in wireframe rather than just points.
- Editing control points Related to the problem of "where did the user click?" is the question of "did they click near something interesting?" I.e., for Assignment 2, did the user click near an existing control point to edit it?
- Again there are many solutions, but I recommend a simple one. Just map your mouse click to world coords w as usual, and then find the closest control point cp to that position, i.e.
min{cp} ||w - cp||. If the distance is less than some threshold value, select the point (and then, for example, move the point to the mouse position until the mouse is released). If its further than the threshold, then add a new point.
- Again there are many solutions, but I recommend a simple one. Just map your mouse click to world coords w as usual, and then find the closest control point cp to that position, i.e.
Surface generation code for A2
Click title to readJohn Brosz has kindly written up a few functions that you can use for the second assignment, if you wish. The code in surfaceGen.cpp
- generates control points for planes and toruses;
- has an option to add noise to the generated points;
- draws the surfaces as a point cloud; and,
- has functions for loading and saving the points to a file.
Feel free to use the code in your assignment (with attribution of course).
Oct. 15 lab - Display lists
Click title to readIn today's lab I returned the first assignment and covered a few topics related to the second.
- Its important to note the distinction between Bezier curves (continuous) versus B-spline subdivision curves (discrete). The parameters you use to control the "smoothness" of each curve is different, so be aware when programming.
- Multiple GL widgets/contexts in Qt. You can have multiple
QGLWidgets in an application; for example, you can instantiate theRendererclass twice and add each to the window to have 2 independent rendering areas in your application. Some tips:- To share data between the two contexts, there are a few options -- globals, signals and slots to pass data, and static class variables are a few ways that come to mind.
- To share display lists between the contexts, you have to specify it in the constructor of the
QGLWidget. See here for info.
- Display lists: see the posted notes?.
A1 marking
Click title to readI haven't been able to finish the marking as soon as I'd planned, but I hope to have the marks ready for Wednesday's lab.
UPDATE
Assignment 1 marks have now been posted. Let me know if you can't find your mark or have a question about grading.
Oct. 8 lab - Virtual trackball etc.
Click title to read
In today's lab, we covered:
- A sample solution for the first assignment. I quickly went through some code that used STL vectors and a simple Point class to compute and store the fractal points.
- Virtual trackball rotation. I didn't have time to type up the notes, but here's a PDF of my notes. Yay technology!
- A couple of suggested methods for converting window coordinates to world coordinates (useful for the 2D part of Assignment 2). The easiest way is to set up an orthographic projection with the same dimensions as your window, i.e.
glOrtho(0, w, 0, h, -1, 1);. [See any problems with this approach? ] Another approach is to use the same coordinate conversion of the virtual trackball.
Coding exercise: fill in the missing parts (marked by "To-do:" comments) in this trackball code, based on the posted notes. trackball-ex.cpp
Assignment 2 posted
Click title to readThe second assignment has been posted. Try to take a look at it before the next lab. It may look daunting at first glance but each component is hopefully straightforward.
Demo signup + Important assignment note
Click title to readSorry for not getting this ready before last week's labs, but there is now a demo signup sheet available.
Since this is during lab time, no one should have any time conflicts. If for some reason you can't make it, let me know and we can set up another time.
ICT power outage
There has been some consternation regarding the ICT power outage this weekend. I have been assured that this outage won't affect any primary assignment resources. Meaning: the graphics lab in MS239 will be functional, as will the submit system, and most or all of the servers (csa, csb, ...) will be online throughout the weekend.
So don't slack off this weekend expecting an extension -- it won't be coming. ;-)
Oct. 1 lab
Click title to readIn today's lab I covered a somewhat random selection of OpenGL stuff.
- The main topic was transformations: rotation, translation, and scaling. We discussed the concept of the modelview matrix, which converts object coordinates to world coordinates. Each transformation specified by GL functions --
glScalef,glRotatef,glTranslatef-- is right-multiplied with the current modelview matrix. The upshot is that transformations are applied in the reverse order of the function calls.- We discussed ways to undo transformations, of which there are a few ways. 1) To clear all transformations, call
glLoadIdentity(). 2) Each transformation has an inverse transform that is easily derived. Example: a scaling by 2 can be undone by scaling by 0.5. 3) UseglPushMatrix()to save the current modelview matrix, andglPopMatrix()to restore it later. - We also discussed how to use pushes and pops to instance an object, or render a single object in several places in a scene.
- We discussed ways to undo transformations, of which there are a few ways. 1) To clear all transformations, call
- We also discussed how to draw text in OpenGL using
glutBitmapCharacter()andglRasterPos__().
Sep. 29 lab
Click title to readIn Monday's lab I talked about the first assignment, clarifying some of the requirements and discussing the Koch snowflake in a bit of detail. An important aspect is efficiency -- not just in your computation of a fractal, but in your drawing it to the screen. You should be storing the fractal points and just iterating through them in the DrawGL() function.
Good luck finishing up the assignment, and don't forget to submit your code before the deadline Sunday night.
submit -a 1 -c 453 files...
Using GLUT in Visual Studio
Click title to readFor those of you coding in Windows, you may find this GLUT + Visual Studio tutorial helpful.
The main thing is to configure the project to link in the OpenGL and GLUT libraries (.lib files), much like the Makefile does under Linux.
[Thanks to Evan for the link. ]
Lab 3
Click title to readBesides talking about GLUT menus in today's lab, I also talked a bit about the C++ STL, and STL vectors in particular.
One thing to bear in mind is that C++ is not garbage-collected, so remember to free up any memory pointed to by vector elements before you empty the vector. For example, the following code would create a memory leak:
vector<int*> x; x.push_back(new int(4)); x.resize(0);
because the int* pushed onto x is dangling -- nothing refers to it anymore. Remember to delete the memory before erasing the pointer, eg. delete x[0];.
PDFCreator
Click title to readFor the assignments your readme is supposed to be in PDF format. If you're stuck on how to create a PDF, I'd suggest installing a program called PDFCreator.
PDFCreator installs a virtual printer that allows you to create a PDF from any program with a Print function. In particular, you can use it to easily print a Word document to PDF.
For the brave souls, there's always LaTeX. :-)
SSH client for Windows
Click title to readHere's a link to a recommended SSH client for Windows:
SSHwin32.exe (5.8MB)
You may find this useful for testing code written at home to make sure it compiles on the lab machines.
Here's a list of departmental machines that you can access from outside the University. From there, you can SSH into a lab machine (check the names listed in the lab, they're Pixar and Shrek-themed, eg. woody, shrek, fiona, etc.).
GLUT for Win32
Click title to readHere's a distribution of GLUT for Windows.
http://www.xmission.com/~nate/glut.html
Just copy the files to the directories indicated in the readme file, and you should be good to go.
- glut.h -> copy to ...\VC98\include\GL\.
- glut.dll -> copy to C:\Windows\system32\ (or wherever your Windows directory is)
- glut.lib -> copy to ..\VC98\lib\.
Barebones QT app
Click title to readHere's a link to the barebones QT/OpenGL application.
There is a related exercise that you can work through if you're up to it.
Grades
Indexed by last 4 digits of student ID
Tutorial 01
| ID | A1 (/100) | A2 (/100) | A3 (/100) | A4 (/100) |
| 7070 | 55 | 70 | 83 | 90 |
| 3148 | 107 | 105 | 88 | 85 |
| 6793 | 94 | 89 | 51 | 73 |
| 9211 | 99 | 67 | 75 | |
| 1813 | 77 | |||
| 1891 | 97 | 25 | ||
| 6248 | 110 | 105 | 110 | 130 |
| 8378 | 96 | 110 | 115 | 125 |
| 4695 | 114 | 96 | 103 | 97 |
| 2446 | 92 | 40 | 77 | 53 |
| 3135 | 93 | 78 | 63 | |
| 3703 | 80 | 45 | 32 | 51 |
| 2544 | 100 | 87 | 69 | 76 |
| 2998 | 100 | 100 | 106 | 100 |
| Average | 88.5 | 75.3 | 81 | 88 |
Tutorial 03
| ID | A1 (/100) | A2 (/100) | A3 (/100) | A4 (/100) |
| 6135 | 86 | 56 | 60 | 36 |
| 0184 | 115 | 88 | 127 | 118 |
| 8335 | 78 | |||
| 1570 | 96 | 64 | 131 | 85 |
| 6126 | 103 | 100 | 94 | 88 |
| 5304 | 95 | 93 | 88 | 108 |
| 1919 | 106 | 81 | 121 | 74 |
| 3290 | 94 | 85 | 22 | 42 |
| 4515 | 107 | 120 | 140 | 133 |
| 8324 | 95 | 35 | 105 | 53 |
| 3789 | 98 | 93 | 127 | 70 |
| Average | 96.5 | 81.5 | 101.5 | 80.7 |
Links
- OpenGL Basics
- The graphics pipeline
- GLUT samples [Rob the Bloke]
- NeHe Tutorials [left-side navigation]
- The Red Book [GL programming reference]
- The Blue Book [GL function reference]
- GLUT reference
- C++ standard template library (STL)
- Qt 2.30 for Windows
