Docsity

Triangle Rasterization - Computer Graphics - Lecture Slides, Slides of Computer Graphics

Partial preview of the text

Download Triangle Rasterization - Computer Graphics - Lecture Slides and more Slides Computer Graphics in PDF only on Docsity!

Computer

Graphics

Lecture 22

Triangle

Rasterization

Flat Filling Triangles

  • For each scan line (horizontal line on the screen), find the points of intersection with the edges of the triangle. Then, draw a horizontal line between intersections and do this for all scan lines.
  • But how can we find

these points quickly?

  • Using linear

interpolation!

  • We have 3 vertices and we want to find coordinates of all points belonging to segments determined by these vertices
  • Our task is to find points: (xc,ya+1), (xd,ya+2), ... , (xm,yb-1), (xn,yb)
  • Notice that xa changes to xb in (yb-ya) steps.
  • We also have:
  • Xa = xa + 0 * (xb-xa)/(yb-ya),
  • Xb = xa + (yb-ya) * (xb-xa) / (yb-ya)

and, in general,

  • xi = xa + (yi–ya) * delta ,

where

  • delta = (xb – xa) / (yb – ya)

Pseudo code for a

triangle filling

algorithm.

The coordinates of

vertices are:

(A.x, A.y),

(B.x, B.y),

(C.x, C.y)

  • dx1, dx2, dx3 are deltas

used in interpolation

  • Horizontal line draws

horizontal segment with

coordinates

  • (S.x, Y), (E.x, Y)

S = A means that:

S.x = A.x;

S.y = A.y;

if (B.y - A.y > 0)

dx1 = (B.x-A.x) / (B.y-A.y)

else

dx1=0;