Rasterization May 14, 2007. Triangles Only We will discuss the rasterization of triangles only. Why?...

18
Rasterization May 14, 2007
  • date post

    20-Dec-2015
  • Category

    Documents

  • view

    216
  • download

    0

Transcript of Rasterization May 14, 2007. Triangles Only We will discuss the rasterization of triangles only. Why?...

Rasterization

May 14, 2007

Triangles Only• We will discuss the rasterization of

triangles only.

• Why?– Polygon can be decomposed into triangles.– A triangle is always convex.– Results in algorithms that are more

hardware friendly.

Being Hardware Friendly• [Angel 4e] Section 7.11.3 or • [Angel 3e] Section 8.11.6:

– Intersect scan lines with polygon edges.

– Sort the intersections, first by scan lines, then by order of x on each scan line.

– It works for polygons in general, not just in triangles.

– O(n log n) complexity feasible in software implementation only (i.e., not hardware friendly)

Color and Z

• Now we know which pixels must be drawn. The next step is to find their colors and Z’s.

• Gouraud shading: linear interpolation of the vertex colors.

• Isn’t it straightforward?– Interpolate along the edges. (Y direction)– Then interpolate along the span. (X

direction)

Interpolation in World Space vs Screen Space

• p1=(x1, y1, z1, c1); p2=(x2, y2, z2, c2); p3=(x3, y3, z3, c3) in world space

• If (x3, y3) = (1-t)(x1, y1) + t(x2, y2) then z3=(1-t)z1+t z2; c3=(1-t)c1+t c2

• But, remember that we are interpolating on screen coordinates (x’, y’):

1

'

'

'

z

y

x

qpnm

lkji

hgfe

dcba

w

wz

wy

wx

• Let p’1=(x’1, y’1); p’2=(x’2, y’2) and p’3=(x’3, y’3)= (1-s)(x’1, y’1) + s(x’2, y’2)

• Does s=t? If not, should we compute z3 and c3 by s or t?

• Express s in t (or vice versa), we get something like:

• So, if we interpolate z on screen space, we get the z of “some other point on the line”

• This is OK for Z’s, but may be a problem for texture coordinates (topic of another lecture)

)( 121

2

wwtw

wts

Appendix

Derivation of s and t

• Two end points P1=(x1, y1, z1) and P2=(x2, y2, z2). Let P3=(1-t)P1+(t)P2

• After projection, P1, P2, P3 are projected to (x’1, y’1), (x’2, y’2), (x’3, y’3) in screen coordinates. Let (x’3, y’3)=(1-s)(x’1, y’1) + s(x’2, y’2).

• (x’1, y’1), (x’2, y’2), (x’3, y’3) are obtained from P1, P2, P3 by:

)

11

)1((

1

'

'

'

1

'

'

'

,

1

'

'

'

2

2

2

1

1

1

3

3

3

3

33

33

33

2

2

2

2

22

22

22

1

1

1

1

11

11

11

z

y

x

tz

y

x

tMz

y

x

M

w

wz

wy

wx

z

y

x

M

w

wz

wy

wx

z

y

x

M

w

wz

wy

wx

Since

We have:

2

22

22

22

2

2

2

1

11

11

11

1

1

1

'

'

'

1

,'

'

'

1 w

wz

wy

wx

z

y

x

M

w

wz

wy

wx

z

y

x

M

2

22

22

22

1

11

11

11

2

2

2

1

1

1

3

33

33

33

'

'

'

'

'

'

)1(

11

)1('

'

'

w

wz

wy

wx

t

w

wz

wy

wx

t

z

y

x

Mtz

y

x

Mt

w

wz

wy

wx

When P3 is projected to the screen, we get (x’3, y’3) by dividing by w, so:

But remember that

(x’3, y’3)=(1-s)(x’1, y’1) + s(x’2, y’2)

Looking at x coordinate, we have

))1(

'')1(,

)1(

'')1(()','(

21

2211

21

221133 wtwt

wytwyt

wtwt

wxtwxtyx

21

221121 )1(

'')1()1(

wtwt

wxtwxtxsxs

We may rewrite s in terms of t, w1, w2, x’1, and x’2.

In fact,

or conversely

Surprisingly, x’1 and x’2 disappear.

)()1( 121

2

21

2

wwtw

wt

wtwt

wts

221

1

21

1

)()1( wwws

ws

wsws

wst