rasterization
play

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


  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.

  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)

  3. 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’):       x ' w a b c d x       y ' w e f g h y       =       z ' w i j k l z       w m n p q 1      

  4. • 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: t w = s 2 + − w t ( w w ) 1 2 1 • 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)

  5. Appendix Derivation of s and t • Two end points P 1 =(x 1 , y 1 , z 1 ) and P 2 =(x 2 , y 2 , z 2 ). Let P 3 =(1-t)P 1 +(t)P 2 • After projection, P 1 , P 2 , P 3 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 ).

  6. • (x ’ 1 , y ’ 1 ), (x ’ 2 , y ’ 2 ), (x ’ 3 , y ’ 3 ) are obtained from P 1 , P 2 , P 3 by:  x ' w   x   x ' w   x  1 1 1 2 2 2         y ' w y y ' w y         1 1 = 1 2 2 = 2 M , M         ' ' z w z z w z 1 1 1 2 2 2         w 1 w 1         1 2  x ' w   x   x   x  3 3 3 1 2         y ' w y y y         3 3 = 3 = − 1 + 2 M M (( 1 t ) t )         z ' w z z z 3 3 3 1 2         w 1 1 1         3 Since  x   x ' w   x   x ' w  1 1 1 2 2 2         y y ' w y y ' w         1 = 1 1 2 = 2 2 M , M         z z ' w z z ' w 1 1 1 2 2 2         1 w 1 w         1 2 We have:  x ' w   x   x  3 3 1 2       y ' w y y       3 3 = − 1 + ⋅ 2 ( 1 t ) M t M       z ' w z z 3 3 1 2       w 1 1       3  x ' w   x ' w  1 1 2 2     y ' w y ' w     = − 1 1 + 2 2 ( 1 t ) t     z ' w z ' w 1 1 2 2     w w     1 2

  7. When P 3 is projected to the screen, we get ( x ’ 3 , y ’ 3 ) by dividing by w , so: − + ⋅ − + ⋅ ( 1 t ) x ' w t x ' w ( 1 t ) y ' w t y ' w = ( x ' , y ' ) ( 1 1 2 2 , 1 1 2 2 ) 3 3 − + ⋅ − + ⋅ ( 1 t ) w t w ( 1 t ) w t w 1 2 1 2 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 t ) x ' w t x ' w − + ⋅ = ( 1 s ) x s x 1 1 2 2 1 2 − + ⋅ ( 1 t ) w t w 1 2 We may rewrite s in terms of t, w 1 , w 2 , x ’ 1 , and x ’ 2 . In fact, ⋅ ⋅ t w t w = = s 2 2 − + ⋅ + − ( 1 t ) w t w w t ( w w ) 1 2 1 2 1 or conversely ⋅ ⋅ s w s w = = t 1 1 ⋅ + − − + s w ( 1 s ) w s ( w w ) w 1 2 1 2 2 Surprisingly, x ’ 1 and x ’ 2 disappear.

Recommend


More recommend