Rasterization May 1, 2006 Triangles Only We will discuss the - - PDF document

rasterization
SMART_READER_LITE
LIVE PREVIEW

Rasterization May 1, 2006 Triangles Only We will discuss the - - PDF document

Rasterization May 1, 2006 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


slide-1
SLIDE 1

Rasterization

May 1, 2006

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.

slide-2
SLIDE 2

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)

slide-3
SLIDE 3
slide-4
SLIDE 4

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
  • n screen coordinates (x’, y’):

                        =             1 ' ' ' z y x q p n m l k j i h g f e d c b a w w z w y w x

slide-5
SLIDE 5
  • 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)

) (

1 2 1 2

w w t w w t s − + ⋅ =

slide-6
SLIDE 6
slide-7
SLIDE 7

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).

slide-8
SLIDE 8
  • (x’1, y’1), (x’2, y’2), (x’3, y’3) are obtained

from P1, P2, P3 by:

) 1 1 ) 1 (( 1 ' ' ' 1 ' ' ' , 1 ' ' '

2 2 2 1 1 1 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1

            +             − =             =                         =                         =             z y x t z y x t M z y x M w w z w y w x z y x M w w z w y w x z y x M w w z w y w x

Since We have:

            =                         =            

2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1

' ' ' 1 , ' ' ' 1 w w z w y w x z y x M w w z w y w x z y x M             +             − =             ⋅ +             − =            

2 2 2 2 2 2 2 1 1 1 1 1 1 1 2 2 2 1 1 1 3 3 3 3 3 3 3

' ' ' ' ' ' ) 1 ( 1 1 ) 1 ( ' ' ' w w z w y w x t w w z w y w x t z y x M t z y x M t w w z w y w x

slide-9
SLIDE 9

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 ( ( ) ' , ' (

2 1 2 2 1 1 2 1 2 2 1 1 3 3

w t w t w y t w y t w t w t w x t w x t y x ⋅ + − ⋅ + − ⋅ + − ⋅ + − =

2 1 2 2 1 1 2 1

) 1 ( ' ' ) 1 ( ) 1 ( w t w t w x t w x t x s x s ⋅ + − ⋅ + − = ⋅ + −

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

  • r conversely

Surprisingly, x’1 and x’2 disappear.

) ( ) 1 (

1 2 1 2 2 1 2

w w t w w t w t w t w t s − + ⋅ = ⋅ + − ⋅ =

2 2 1 1 2 1 1

) ( ) 1 ( w w w s w s w s w s w s t + − ⋅ = − + ⋅ ⋅ =