CS 248 - Introduction to Computer Graphics
Spring Quarter, 1995
Demos on Monday, May 8
Writeups due on Tuesday, May 9 by 5:00pm
Your assignment is to write a scan converter for rasterizing interactively specified triangles. You will also implement a postprocess that redraws a previously specified set of triangles using supersampling and averaging down to reduce aliasing artifacts. Your scan converter and postprocessor will be used in the renderer you will write in assignments #3 and #4.
Use any pattern of subpixel positions and any corresponding weights (summing to 1) that you like, and be prepared to verbally defend (in informal terms) the quality of antialiasing that it produces. Some patterns work well, and some do not, as we shall discuss in class. Allow slider control over the number of samples per pixel (variable s in appendix A). In order to verify that your algorithm behaves correctly, provide the user with the option to assign a unique 24-bit color (random colors are fine) to each triangle. When this option is selected, you should not draw triangles with XOR. Make sure that pixels along polygon edges and at polygon edge crossings (in case of overlapping triangles) contain reasonable antialiasing.
Your method for insuring that triangles mesh perfectly should not require global knowledge about the list of triangles to be scan converted. In other words, it should be a set of rules that can be applied when scan converting a single triangle, without knowing about the others. Since insuring perfect meshing in the vicinity of T-intersections requires knowing about other triangles, we do not require you to handle these. We also do not require any particular behavior at a vertex shared by triangles that do not completely wind around the vertex, i.e. at the center of a pie with one or more slices missing.
Page 948 of the textbook describes two solutions to non-integer vertices: a floating point algorithm and a fixed point algorithm (i.e. by multiplying by a fixed constant (the book suggests 1000)). We suggest a floating point algorithm, mainly because it will be easier to code.
We will follow the same demo and submission procedure as in the last assignment. The assignment will be graded on correctness (50 points), efficiency (30 points), programming style (10 points), and the elegance of your user interface (10 points).
In addition to an interactive interface, your program should be capable of reading triangle coordinates from a text file, so that we can test it with "grader data." Be prepared to demonstrate your program on a grader data file that we will provide on the spot during the demo. The file contains one text line per triangle. Each line consists of three pairs of floating point numbers that represent the X,Y-coordinates of the three vertices of each triangle. For example, the file
10 20 15 25 8.5 16.5tells your program to draw one triangle with vertices (10,20), (15,25), and (8.5,16.5). Treat your canvas as occupying the all-positive quadrant in X and Y. To be sure you can read our format, we have placed some sample files in /usr/class/cs248/data/triangles.
Try to anticipate every nasty triangle and set of triangles that we will want to test, including degenerate triangles and out-of-bounds vertices. Note that the test files we provide should not be considered adequate for debugging your meshing rules and anti-aliasing; they are merely provided as examples of the file format your program should be able to read. Exhaustively testing your meshing rules and anti-aliasing is your task.
We intend to measure the speed of your scan converter during the demos by giving you a large file of triangles and timing your "Redraw" function using a stopwatch. Be prepared to handle up to 10000 triangles. We will measure your redraw time with and without antialiasing enabled. Since your rendering time with antialiasing enabled will include a component due to updating the accumulation buffer, and all your redraw times will include a component due to displaying the result, you should provide some means to control your active drawing area within the canvas. This control can be either interactive or at program startup. Allow a drawing area of 100 x 100 pixels. We will use this size for our speed measurements.
You may work alone or in teams of two or three. For a team of two, you must implement two of the following bells and whistles. For a team of three, you must implement five. Alternatives are acceptable if approved in advance. If you have completed the assignment and wish to earn extra credit, you may add more bells and whistles.
Let "canvas" and "temp" be 24-bit pixel arrays. Let "triangle color" be a 24-bit color unique to each triangle.
1 clear canvas to black 2 for (i=1; i<=s; i++) (for s subpixel positions) 3 clear temp to black 4 for each triangle 5 translate triangle vertices for this subpixel position 6 for each pixel in triangle (using your scan converter) 7 temp color <-- triangle color 8 for each pixel in canvas 9 canvas color <-- ((i-1)/i)*canvas color + 1/i*temp color 10 display changed portion of canvas
Line 7 causes later triangles to occlude earlier triangles in temp. This "painter's algorithm" occlusion ordering is in lieu of a hidden-surface algorithm, which you will implement in your next assignment.
Line 9 implements a box filter, i.e. all subpixel positions are given equal weight. By modifying this interpolation formula to include a weight that varies with subpixel position relative to the center of the filter kernel, you can implement other reconstruction filters.
Line 10 causes the screen to be updated after all triangles have been rendered at each subpixel position, thus implementing a kind of progressive refinement. This is the required functionality. If you want to see your scan converter run faster, provide a check box that allows the user to disable display until the end of the scan conversion process.
If your progressive refinement is working correctly, what you should see is: after the first supersample location -> a canvas with all triangles at full intensity but with jaggies, after the second -> an average of two full-intensity images that are slightly spatially offset from one another, producing a bit of blurring, and after all s positions -> a nicely antialiased image. I'll show you some examples of antialiased images. Meanwhile, look at figure 3.56 in the text. The method they use to produce that figure is different (that is prefiltering, not supersampling and averaging down), but the visual effects are similar.
One final hint. For large numbers of samples (i.e. large values of s), line 9 will yield significant quantization artifacts. In these situations, you may need to use canvas arrays of 16-bit or 32-bit integers (one each for R,G, and B), sum your temp images into this array without first scaling each contribution (i.e. don't scale by 1/i), then normalize into a third array of 8-bit per color component pixels for display on the SGI. I don't require that you implement this, but if you do, you will have the pleasure of being able to progressively refine your images even for large s. Be careful of memory consumption. Don't try to compute large (wide and high) RGB images using 32-bit integer arrays. You'll bring your machine to its knees.