Graphics Pipeline Rasterization CMSC 435634 Drawing Terms Primitive

  • Slides: 21
Download presentation
Graphics Pipeline Rasterization CMSC 435/634

Graphics Pipeline Rasterization CMSC 435/634

Drawing Terms • Primitive – Basic shape, drawn directly – Compare to building from

Drawing Terms • Primitive – Basic shape, drawn directly – Compare to building from simpler shapes • Rasterization or Scan Conversion – Find pixels for a primitive – Usually for algorithms that generate all pixels for one primitive at a time – Compare to ray tracing: all primitives for one pixel

Line Drawing • Given endpoints of line, which pixels to draw?

Line Drawing • Given endpoints of line, which pixels to draw?

Line Drawing • Given endpoints of line, which pixels to draw?

Line Drawing • Given endpoints of line, which pixels to draw?

Line Drawing • Given endpoints of line, which pixels to draw? ? ? ?

Line Drawing • Given endpoints of line, which pixels to draw? ? ? ? ? • Assume one pixel per column (x index), which row (y index)? • Choose based on relation of line to midpoint between candidate pixels

Line Drawing • Choose with decision variable • Plug midpoint into implicit line equation

Line Drawing • Choose with decision variable • Plug midpoint into implicit line equation • Incremental update

Line Drawing • Implicit line equation • Midpoint algorithm y = y 0 d

Line Drawing • Implicit line equation • Midpoint algorithm y = y 0 d = f(x 0+1, y 0+0. 5) for x = x 0 to x 1 draw(x, y) if (d < 0) then y = y+1 d = d + (x 1 - x 0) + (y 0 - y 1) else d = d + (y 0 - y 1)

Polygon Rasterization • Problem – How to generate filled polygons (by determining which pixel

Polygon Rasterization • Problem – How to generate filled polygons (by determining which pixel positions are inside the polygon) – Conversion from continuous to discrete domain • Concepts – Spatial coherence – Span coherence – Edge coherence

Scanning Rectangles for ( y from y 0 to y 1 ) for (

Scanning Rectangles for ( y from y 0 to y 1 ) for ( x from x 0 to x 1 ) Write Pixel (x, y)

Scanning Rectangles (2) for ( y from y 0 to y 1 ) for

Scanning Rectangles (2) for ( y from y 0 to y 1 ) for ( x from x 0 to x 1 ) Write Pixel (x, y)

Scanning Rectangles (3) for ( y from y 0 to y 1 ) for

Scanning Rectangles (3) for ( y from y 0 to y 1 ) for ( x from x 0 to x 1 ) Write Pixel (x, y)

Barycentric Coordinates • Use non-orthogonal coordinates to describe position relative to vertices – Scaled

Barycentric Coordinates • Use non-orthogonal coordinates to describe position relative to vertices – Scaled edge equations • 0 on edge, 1 at opposite vertex

Barycentric Example

Barycentric Example

Barycentric Coordinates • Computing coordinates – Equations for α, β and γ in book

Barycentric Coordinates • Computing coordinates – Equations for α, β and γ in book – Solutions to linear equations of x, y • Ratio of areas / ratio of cross products – Area = 0. 5*b*h – Length of cross product = 2*area of triangle • Matrix form

Area Computation

Area Computation

Barycentric Matrix Computation • Edge equation for each coordinate • Plug in known values

Barycentric Matrix Computation • Edge equation for each coordinate • Plug in known values at the vertices

Barycentric Matrix Computation • Write linear system in matrix form • Solve

Barycentric Matrix Computation • Write linear system in matrix form • Solve

Barycentric Matrix Computation • Solutions = rows of inverse matrix

Barycentric Matrix Computation • Solutions = rows of inverse matrix

Barycentric Rasterization For all x do For all y do Compute (a, b, g)

Barycentric Rasterization For all x do For all y do Compute (a, b, g) for (x, y) If (a [0, 1] and b [0, 1] and g [0, 1] then c = a*c 0 + b*c 1 + g*c 2 Draw pixel (x, y) with color c

Barycentric Rasterization xmin xmax ymin ymax for = floor(min(x 0, x 1, x 2))

Barycentric Rasterization xmin xmax ymin ymax for = floor(min(x 0, x 1, x 2)) = ceiling(max(x 0, x 1, x 2)) = floor(min(y 0, y 1, y 2)) = ceiling(max(y 0, y 1, y 2)) y = ymin to ymax do for x = xmin to xmax do a = a(x, y) b = a(x, y) g = g(x, y) If (a [0, 1] and b [0, 1] and g [0, 1] then c = a*c 0 + b*c 1 + g*c 2 Draw pixel (x, y) with color c

Incremental Computation • a, b, and g are linear in x and y •

Incremental Computation • a, b, and g are linear in x and y • What about a(x+1, y)?