You are on page 1of 33

Rasterization

Reading:
HB: 3-5
Rendering Pipeline

Geometry
Geometry Model/View
Model/View Perspective
Perspective
Lighting
Lighting Clipping
Clipping
Database
Database Transform.
Transform. Transform.
Transform.

Scan
Scan Depth
Depth Frame-
Frame-
Texturing
Texturing Blending
Blending Buffer
Conversion
Conversion Test
Test Buffer
Rasterization
is the task of taking an image
described in a
vector graphics format
(shapes) and converting it
into a raster image (pixels or
dots) for output on a
video display or printer, or
for storage in a bitmap file
format.
Rasterization
• Line Drawing Algorithms
• Polygon Filling Algorithms
• Clipping Algorithms
• -----------
• -----------
Line Drawing Techniques
Important line qualities:
• Continuous appearance
• Uniform thickness and
brightness
• Turn on the pixels
nearest the ideal line
• How fast is the line
generated
Displays – Pixels
Special Lines - Horizontal
Special Lines - Horizontal
Increment x by 1, keep y constant
Special Lines - Vertical
Special Lines - Vertical
Keep x constant, increment y by 1
Special Lines - Diagonal
Special Lines - Diagonal
Increment x by 1, increment y by 1
Problem
Given two points (P, Q) on the screen (with
integer coordinates) determine which pixels
should be drawn to display a unit width line
Q

P
Problem
Given two points (P, Q) on the screen (with
integer coordinates) determine which pixels
should be drawn to display a unit width line
Q

P
Problem
Given two points (P, Q) on the screen (with
integer coordinates) determine which pixels
should be drawn to display a unit width line
Q

P
Arbitrary Lines – All Cases
m=0
m=1
m = -1
m=∞
m = -∞
|m| < 1
0<m<1
-1 < m < 0 y1  y0
|m| > 1 y  mx  b, m 
m>1
x1  x0
m < -1
Arbitrary Lines
y  mx  b Q

If m < 1
Take steps in x and determine where to fill y
If m > 1
Take steps in y and determine where to fill x

Other lines by swapping x, y or negating


Simple Algorithm
Case: If m < 1
Start from (xL, yL) and draw to (xH, yH)
where xL< xH

( x0, y0 ) = ( xL, yL )
For ( i = 0; i <= xH-xL; i++ ) y  mx  b
DrawPixel ( xi, Round ( yi ) ) y = m xi+1 + b
i+1
xi+1 = xi + 1 = m ( xi + 1 ) + b
yi+1 = yi + m =>
= m xi + m + b
=y +m
Simple Algorithm - Example
y  mx  b

(6,4)

(0,2)
Simple Algorithm - Example
y  mx  b
yH  yL
m xH  xL  4602  13
(6,4)

(0,2)
Simple Algorithm - Example
y  mx  b
yH  yL
m xH  xL  4602  13
(6,4)

x0
y2 (0,2)

( x0, y0 ) = ( xL, yL )
For ( i = 0; i <= xH-xL; i++ )
DrawPixel ( xi, Round ( yi ) )
xi+1 = xi + 1
yi+1 = yi + m
Simple Algorithm - Example
y  mx  b
yH  yL
m xH  xL  4602  13
(6,4)
x 1
y 7
3
 2.33...
(0,2)

( x0, y0 ) = ( xL, yL )
For ( i = 0; i <= xH-xL; i++ )
DrawPixel ( xi, Round ( yi ) )
xi+1 = xi + 1
yi+1 = yi + m
Simple Algorithm - Example
y  mx  b
yH  yL
m xH  xL  4602  13
(6,4)
x2
y 8
3
 2.66...
(0,2)

( x0, y0 ) = ( xL, yL )
For ( i = 0; i <= xH-xL; i++ )
DrawPixel ( xi, Round ( yi ) )
xi+1 = xi + 1
yi+1 = yi + m
Simple Algorithm - Example
y  mx  b
yH  yL
m xH  xL  4602  13
(6,4)

x 3
y 3 (0,2)

( x0, y0 ) = ( xL, yL )
For ( i = 0; i <= xH-xL; i++ )
DrawPixel ( xi, Round ( yi ) )
xi+1 = xi + 1
yi+1 = yi + m
Simple Algorithm - Example
y  mx  b
yH  yL
m xH  xL  4602  13
(6,4)
x4
y  103  3.33...
(0,2)

( x0, y0 ) = ( xL, yL )
For ( i = 0; i <= xH-xL; i++ )
DrawPixel ( xi, Round ( yi ) )
xi+1 = xi + 1
yi+1 = yi + m
Simple Algorithm - Example
y  mx  b
yH  yL
m xH  xL  4602  13
(6,4)
x5
y 11
3
 3.66...
(0,2)

( x0, y0 ) = ( xL, yL )
For ( i = 0; i <= xH-xL; i++ )
DrawPixel ( xi, Round ( yi ) )
xi+1 = xi + 1
yi+1 = yi + m
Simple Algorithm - Example
y  mx  b
yH  yL
m xH  xL  4602  13
(6,4)

x6
y4 (0,2)

( x0, y0 ) = ( xL, yL )
For ( i = 0; i <= xH-xL; i++ )
DrawPixel ( xi, Round ( yi ) )
xi+1 = xi + 1
yi+1 = yi + m
Simple Algorithm - Exercise
Fill circles between given end points of line.

(6,2)
(0,1)
( x0, y0 ) = ( xL, yL )
For ( i = 0; i <= xH-xL; i++ )
DrawPixel ( xi, Round ( yi ) )
xi+1 = xi + 1
yi+1 = yi + m
Simple Algorithm - Exercise
Write an algorithm for m>1 and fill circles between given
end points of line.
(6,5)

(2,0)
Simple Algorithm - Exercise
Fill circles between given end points of line.
(0,5)

(6,0)
Simple Algorithm - Exercise
Fill circles between given end points of line.
(3,5)

(6,0)
Simple Algorithm - Problems
– Floating point operations
– Rounding
– Can we do better?
References
1. http://courses.cs.tamu.edu/schaefer/441_Spring2007/
2. Donald Hearn, M. Pauline Baker, Computer Graphics with
OpenGL, Third Edition, Prentice Hall, 2004.
3. http://www.cs.virginia.edu/~gfx/Courses/2004/Intro.Spring.04/

You might also like