Output
Output
302
Basics of Computer Graphics
Module: Rasterization Module
Dr
Avinash Sharma
Spring 2021
CS7.302
(Point) Pipeline in Action
World
Coord
aftModelView
Camera
Coord
Projection
Canonical
Coord
Viewport
Window
Coord
I Lines are made out of two points. Triangles and polygons are made out
of 3 or more points.
CS7.302
Lines in Action
I
aft
Lines are rasterized to the pixel
grid of the window.
CS7.302
Clipping Lines
I
aft
End points map to window
coordinates independently.
CS7.302
Clipping Lines
I
aft
End points map to window
coordinates independently.
CS7.302
Triangles in Action
I
aft
Un-filled triangles are
uninteresting. Filled ones
represent surfaces.
CS7.302
Clipping Triangles
I
aft
Only parts of the triangle may lie
in the window.
CS7.302
Primitive Pipeline
Vertex/Point
aft
Vertex Processing
Primitive Assembly
I
I
From points, lines, triangles/polygons
Frame Buffer
CS7.302
Linear Interpolation of Properties
I
aft
Each pixel needs: colour, depth, and texture coordinate.
CS7.302
Vertex Processing
I
aft
Apply ModelView and Projection matrices to the vertex
CS7.302
Rasterization
I
aft
Apply viewport transformation.
I Interpolate values for each pixel and queue the pixels or fragments for
Dr
further processing.
CS7.302
Pixel or Fragment Processing
I
aft
The pixels generated by the rasterization stage are processed in
arbitrary order by this stage.
CS7.302
Programmable GPUs
I
aft
Graphics Processing Units are programmable today
I GPUs used parallel processing with 2-4 vertex and 32-64 pixel
processing units, all working in parallel. Together, considerable
Dr
computing power was in a GPU
I Clever idea: Use the power for other processing: matrix multiplication,
FFT, sorting, image processing, etc.
CS7.302
Primitive Pipeline: Summary
Vertex/Point
I
aft
Basic primitives: Points, Lines,
Triangles/Polygons.
Vertex Processing
Pixel Processing
Frame Buffer
CS7.302
Scan Conversion or Rasterization
I
aft
Primitives are defined using points, which have been mapped to the
screen coordinates.
CS7.302
Scan Converting a Point
I
aft
The 3D point has been transformed to its screen coordinates (u, v).
CS7.302
Scan Converting a Line
I
aft
Identify the grid-points that lie on the line and colour them.
Problem: Given two end-points on the grid, find the pixels on the line
connecting them.
Dr
I Incremental algorithm or Digital Differential Analyzer (DDA) algorithm.
I Mid-Point Algorithm
CS7.302
Line on an Integer Grid
aft
Dr
CS7.302
Incremental Algorithm
x
x
aft
Function DrawLine(x1 , y1 , x2 , y2 , colour)
x2 x1 , y
x1 , y y1
While (x < x2 )
y2 y1 , slope y/ x
CS7.302
Incremental Algorithm With Integers
x
aft
Function DrawLine(x1 , y1 , x2 , y2 , colour)
x2 x1 , y
While (x < x2 )
y2 y1 , sl
x x + 1, sl += y.
if (sl x) {y y + 1, sl -= x}
Dr
EndWhile
WritePixel (x2 , y2 , colour)
EndFunction
CS7.302
Points to Consider
I
aft
If abs(slope) > 1, step through y values, adding inverse slopes to x at
each step.
CS7.302
Two Options at Each Step!
aft
NE
Dr
M
E
CS7.302
Mid-Point Line Algorithm
I
aft
Line equation: ax + by + c = 0, a > 0.
Let 0 < slope = y/ x = a/b < 1.0
I dE = F(ME ) = d + a, dNE = d + a + b
Dr
I Therefore, E = a, NE =a+b
CS7.302
Pseudocode
d
aft
Function DrawLine (x1 , y1 , x2 , y2 , colour)
a (y2 y1 ), b
2a + b, E
While (x < x2 )
(x1 x2 ), x
2a, NE
x1 , y
2(a + b)
y1
WritePixel(x, y, colour)
if (d < 0) // East
d d + E, x x+1
Dr
else // North-East
d d + NE , x x + 1, y y+1
EndWhile
WritePixel(i, j, colour)
EndFunction
CS7.302
Example: (10, 10) to (20, 17)
aft
F(x, y) = 7x 10y + 30, a = 7, b = 10
d0 = 2 ⇤ 7 10 = 4, E = 2 ⇤ 7 = 14, NE =
CS7.302
Patterned Line
I
aft
Represent the pattern as an array of booleans/bits, say, 16 pixels long.
Fill first half with 1 and rest with 0 for dashed lines.
CS7.302
Shared Points/Edges
I
aft
It is common to have points common between two lines and edges
between two polygons.
I Solution: Treat the intervals closed on the left and open on the right.
Dr
[xm , xM ) & [ym , yM )
I Thus, edges of polygons on the top and right boundaries are not drawn.
CS7.302
aft
Dr
CS7.302
Clipping
I
aft
Often, many points map to outside the range in the normalized 2D
space.
CS7.302
Clipping Points
I
aft
Clip rectangle: (xm , ym ) to (xM , yM ).
I Can use this to clip any primitives: Scan convert normally. Check above
condition before writing the pixel.
Dr
I Simple, but perhaps we do more work than necessary.
CS7.302
Clipping Lines
aft
Dr