CS488 - Introduction to Computer Graphics - Lecture 13
Polygons
Projecting a Polygon
Lines project to lines so projecting the vertices projects a polygon in 3D
to a polygon on the view plane.
Triangles
Sooner or later almost all polygons are converted to triangles
- there is not a unique way of doing so
- try to avoid long skinny triangles
Scan Conversion
Scan converting a triangle (in 2D)
- Start at the scan line of the uppermost vertex
- Until you get to the middle vertex
- Intersect each scan line with two triangle edges
- Paint pixels between the intersections
- Until you get to the lowest vertex
- Intersect each scan line with two triangle edges
- Paint pixels between the intersections
Scan converting a polygon (in 2D)
sort vertices in direction perpendicular to the scan lines
for each scan line
if scan line contains the next vertex
update and sort edge list
inside = false
for each pixel
if on next edge
inside = !inside
if (inside)
paint pixel
Exercise. Expand "update and sort edge list" to make this a working
algorithm.
Exercise. Hand execute your expanded algorithm on a triangle to make sure
that you understand how it works.
Exercise. Hand execute your expanded algorithm on a non-convex polygon.
Hidden Surface Removal
Every polygon, in 3D, has two sides
- the normal vector differentiates the sides
- different sides may have different properties
It is very convenient to assume that surfaces are closed
- Why?
- Naturally open surfaces, e.g., a piece of paper, can be closed by
adding polygons
Then we can say that every polygon has only a single side with visual
properties
- The normal vector points away from this surface
Backface Culling
Do not render any polygon with n.E < 0.
- On average this cuts the rendering effort in half.
- Remember that E is the ray from the polygon to the eye, not the view
direction.
Does not handle occlusion, so we need to finish off with one of the
following algorithms.
Painter's Algorithm
Sort polygons back to front, then render backmost first.
- device-independent
- slow if there's lots of occlusion
- sorting may not be possible, which makes things hard.
- potentially O(n^2), but rarely is that bad. n: number of polygons.
Warnock's Algorithm
Divide and conquer
- Start with whole window
- Divide into four subwindows
- For each window
- If window has a single polygon
- paint it clipped to the window
- else if window is a single pixel
- paint closest one pixel polygon
- else
- go to 1 with subwindow (recurse)
- exit
Warnock's algorithm is
- easy to implement, device independent
- slow, often O(p.n). p: number of pixels.
- often used in quasi 2D applications where there is little
occlusion.
Depth-Buffer Algorithm (also called zed-buffer)
Use a second frame buffer with depth values stored in it
- Initalize depth-buffer to far plane distance
- If a pixel has z less than the current depth buffer value
- Write it, and
- Update the depth buffer
The depth buffer algorithm is
- easy to implement
- fast, O(n)
- no longer memory-intensive, though it used to be
Almost all graphics cards have hardware depth buffers.
Using the depth buffer may be hard the first time.
Return to: