Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann.

Similar presentations


Presentation on theme: "CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann."— Presentation transcript:

1 CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann

2 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Today’s Topics Questions? Visible Surface determination –Depth Sort –Scanline algorithm

3 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Visible Surface Determination The visible surface determination algorithms we've discussed are: Back Face Culling (removal)‏ Depth Buffer method (aka z-buffer)‏ –A-Buffer method BSP Tree –Still to come: Depth Sort Scanline Algorithm Raycasting

4 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 List priority algorithms –determine a visibility ordering for objects so that a correct picture results if objects are rendered in that order –further objects are occluded by nearer ones –if parts of an object overlap in z (depth) then either a) we can determine a correct order OR b) we have to split objects so that they don't overlap in z Two list priority algorithms are –BSP Trees –Depth Sorting

5 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Depth Sorting Depth Sorting is another way to perform visible surface detection. –It is often referred to as the Painter's Algorithm. –The basic idea is to display the polygons in the frame buffer in order of decreasing distance from the viewpoint. sort polygons from near to far based on farthest z coordinate (smallest z since we're viewing down the -z axis)‏ if z extents overlap then split polygons if necessary (not always necessary) so that there are no ambiguities. draw each polygon in ascending order of smallest z coordinate (back to front)‏

6 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Depth Sorting Resolving ambiguities is the hard part of the algorithm. Before drawing a polygon P, it must be tested against all other polygons Q whose z extent overlaps P's z extents. This is to prove that P can be written before Q. Up to five tests are performed in order. If a test succeeds then P definitely does not obscure Q and therefore can be written before Q. If all Q's pass these tests against P then P is written and the next polygon on the list is the next to be tested. The 5 tests are: –1. Do the polygons' x extents not overlap? –2. Do the polygons' y extents not overlap? –3. Is P entirely on the opposite side of Q's plane from the viewpoint? –4. Is Q entirely on the same side of P's plane as the viewpoint? –5. Do the projections of the polygons (not their extents) onto the (x,y) view plane not overlap? What are these tests really saying?

7 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Depth Sorting What are these tests really saying? If all Q's pass these tests against P then P is written and the next polygon on the list is the next to be tested. The 5 tests are: –1. Do the polygons' x extents not overlap? If YES (that is, their x's don't overlap), then this means that since they don't overlap in x, then drawing P before Q is ok. –2. Do the polygons' y extents not overlap? If YES, then this means that since they don't overlap in y, then drawing P before Q is ok. –3. Is P entirely on the opposite side of Q's plane from the viewpoint? If YES, then this means that since P is fully behind Q's plane in relation to viewpoint, then drawing P before Q is ok. –4. Is Q entirely on the same side of P's plane as the viewpoint? If YES, then this means that since Q is fully in front of P's plane in relation to viewpoint, then drawing P before Q is ok. –5. Do the projections of the polygons (not their extents) onto the (x,y) view plane not overlap? (see figure 9-16 in text a) YES, b) NO)‏ If YES (that is, their projections don't overlap), then this means that since the polygons themselves don't overlap (only their extents did), then drawing P before Q is ok.

8 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Depth Sorting If all 5 tests fail, then interchange P and Q and perform only tests 3 and 4 again (call these 3' and 4'). (No need to perform 1,2, and 5, because these will yield the same answer as before.)‏ –3'. Is Q entirely on the opposite side of P's plane from the viewpoint? –4'. Is P entirely on the same side of Q's plane as the viewpoint? If either succeeds then Q does not obscure P and Q becomes the new P which is tested against all the other polygons that overlap it in z. (** make sure no infinite loop of this procedure --- see a couple of slides forward **.)‏ If they both fail too, then P or Q will be split by the plane of the other and the original unsplit polygon is discarded and the pieces are placed within the sorted list in proper z order and the algorithm continues.

9 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Depth Sorting It is possible that two polygons can fail all 5 tests and then fail the other 2 tests and still be able to be drawn correctly without splitting. However, the depth sorting algorithm would split them (unnecessarily). An example showing this is in the handout.

10 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Depth Sorting To make sure we don't get stuck in an infinite loop of reordering polygons, flag a polygon the first time it is reordered. Then if an attempt is made to reorder it again, split the polygon appropriately.

11 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Scanline Algorithm The Scanline algorithm for visible surface determination is an image precision algorithm. It is an extension to the scan conversion algorithm we discussed for filling a polygon. But now, we need to deal with a set of polygons, not just one. The Scanline algorithm processes one scanline of the frame buffer at a time. One assumption we are making (which can be overcome with modifications to the algorithm) is that no polygons penetrate each other.

12 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Scanline Algorithm 1) Create an edge table for all edges that are not horizontal (ignore those) that are projected onto the view plane. 2) Given the x,y,z coordinates of the 2 endpoints of the edge, –Sort the edges in the edge table according to the smaller y (the y of the lower endpoint) of its two endpoints and then within those with the same smaller y, sort by increasing x of the lower endpoint. 3) Each entry in the edge table contains the following information about each edge –a) x coordinate of the endpoint with smaller y –b) y coordinate of the other endpoint –c) x increment – the value to increment x when moving from one scanline to the next –d) polygon ID 4) A polygon table, keyed on polygon ID contains coefficients of the plane that polygon is on, the color info for it, and a boolean in-out flag used during the algorithm.

13 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Scanline Algorithm 5) An Active Edge Table is also stored during the running of the algorithm. For the current scanline, the active edge table contains the edges, in order of increasing x, whose projections onto the view plane intersect with the current scanline. Pseudocode for this algorithm: –Initialize frame buffer to background color –Add edges to edge table –Add polygons to polygon table –For (each scanline)‏ Update active edge table Starting at the edge with the lowest x For (each pixel in scanline)‏ –Determine if went in or out of any polygons (set appropriate in-out flags)‏ –Test in-out flags, if “in” only one polygon, draw that color –If not “in” any polygons do nothing –If “in” multiple polygons then determine which polygon is closest (make depth calculations based on plane coefficients) and draw that color

14

15 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Scanline Algorithm Modifications can be made for efficiency by exploiting different coherence properties. To reduce depth computations - –Within a scanline, the same polygon influences the color of the pixels between two edges, regardless of how many polygons we are “in”, so depth computations are only necessary when entering a polygon or leaving a polygon. –Assuming we have two or more overlapping (in z) polygons and as we scan across the scan line we leave (go past right edge of) one of the polygons. If the polygon we just left was just obscured then we don't need to compute the depth among the other polygons, we can just draw the color of the polygon that was closest (because it must still be closest). Only when leaving a closest polygon are depth calculations necessary. Example on the board.

16 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Scanline Algorithm To reduce depth computations - –If the same edges are active and in the same order from one scanline to the next, no depth computations are necessary because no depth relationship changes have occurred. Just draw the same colors in the same order (but possibly a different number of pixels each.)‏ Example on the board.

17 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Scanline Algorithm This algorithm, although specified as working only for polygons can be extended to work for arbitrary (curved) surfaces. This is accomplished (partially) by replacing the edge table and active edge table with a surface table and an active surface table.


Download ppt "CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann."

Similar presentations


Ads by Google