Now Playing
Now Playing
Now Playing
• Assignment 2 is out
• Due next Tuesday by the end of class
Last Time
• Discussed clipping
• Points
• Lines
• Polygons
• Introduced Assignment 2
Today
• Introduce rasterization
• Talk about some line drawing algorithms
• Discuss line anti-aliasing
Rendering Pipeline
• Input:
• Line segment definition
• m=∞
Line Algorithm #1:
Brute Force
• Test every pixel:
Line Algorithm #1:
Brute Force
ForEach y = 0:ImageHeight-1
{
ForEach x = 0:ImageWidth-1
{
if (y == round( m*x + b ))
if((x>=x0)&&(x<=x1))
Output[x,y] = LineColor;
}
}
Brute Force:
Pros and Cons
• Pros:
• Very simple to implement
• Cons:
• Very slow
ForEach x = x0:x1
{
y = round( m*x + b );
Output[x,y] = LineColor;
}
Line Traversal Problem
Line Algorithm #2a:
Line Traversal++
• Can be pipelined
• Cons:
• Still needs floating point round
Incremental Line
Traversal
function DrawLine(LineColor, x0, y0, x1, y1)
float y = y0;
• Cons:
• Still needs floating point round
• No more rounding
• Cons:
• Still floating point
• Hard to pipeline
...
m
Test
Value
Subtracted
Value
Line Algorithm #5:
Bresenham’s Algorithm
if(x0>x1) flip ((x0,y0), (x1, y1));
int y = y0;
int error = 0;
• So how do we do it?
• Algorithm #4 stored the offset from the pixel
center
• Cons:
• Cannot be easily pipelined
• #5: Bresenham’s
Available online:
http://xplsv.tv/movie.php?id=1942
How Do They Look?
• So now we know how to draw lines
• But they don’t look very good:
• Why not?
• Aliasing
Better Looking Lines
• There are ways to make lines look better:
• Hacky: Just draw wider lines
• Better: Anti-aliasing
1/4
2/4
2/4
1/4
No 2x2 Downsampled to
antialiasing Supersampled original size
Supersampling
• So why is this a good idea?
• Processing at a higher resolution produces more
accurate data
• Less aliasing
Incorrect
Gaussian
(Correct)
Next Time
• Finish up anti-aliasing
• Ratio method
• Continuing with rasterization
• Shape and polygon drawing
• Assignment 2 due