Download presentation
Presentation is loading. Please wait.
Published byJasper Fleming Modified over 8 years ago
1
2D rendering Szirmay-Kalos László
2
Reference state (modeling space) vectorization Modeling transform World window Screen or appWindow viewport Normalized device space Clipping + viewport transform Képernyőre vetítés rasterization (-1,-1) (1,1) viewport 2D rendering pipeline Screen space
3
Vectorization [0,1]: t 1 = 0, t 2 = 1/n,..., t n =1 r 1 =r(0), r 2 = r(t 2 ), …, r n = r(1) r1r1 r(t), t in [0,1] r2r2 rn rn
4
diagonal Non-diagonal Convex Concave Theorem: Every simple polygon of 4+ vertices has diagonal, i.e. it can be decomposed to triangles via diagonals. Decomposing a polygon to triangles
5
p i is ear if p i-1 – p i+1 is diagonal l Ear can be cut! l Ear clipping: Find an ear and cut! diagonal pipi p i-1 p i+1 Two ears theorem: Every simple polygon of 4+ vertices has at least 2 ears. Ear
6
0 1 2 3 43 Ear clipping
7
Modeling transformation (x, y) = o + u + v u v o , ) (x, y) S x 0 0 0 S y 0 0 0 1 cos sin 0 -sin cos 0 0 0 1 1 0 0 0 1 0 p x p y 1
8
View transformation: Center of the camera window to the origin (x,y) window xv = x-c x yv = y-c y (cx,cy)(cx,cy) wxwx wywy 1 0 0 0 -c x -c y 1 [xv, yv, 1] = [x, y, 1] world (xv, yv) window wxwx wywy
9
Projection: Camera window to a square of corners (-1, -1) and (1, 1) xc = xv * 2/w x yc = yv * 2/w y 2/w x 0 0 2/w y 0 0 1 [xc, yc, 1] = [xv, yv, 1] (xv, yv) window wxwx wywy (1,1) (xc,yc) Normalized device (-1,-1)
10
Viewport transformation: From normalized device space to screen space (1,1) (xc,yc) Normalized device (-1,-1) viewport (X,Y)(X,Y) (vx,vy)(vx,vy) vwvw vhvh Screen X = v w (xc+1)/2+v x Y = v h (yc+1)/2+v y glViewport(vx, vy, vw, vh);
11
Clipping x min x max y min y max x > x min = -1 x y min = -1 y < y max = +1 (x, y) Inside Outside Point clipping:
12
Clipping x min x > x min (x, y) Inside Outside
13
Clipping y min y > y min (x, y) Inside Outside
14
x max x < x max (x, y) InsideOutside Clipping
15
y < y max (x, y) Inside Outside
16
Line segment clipping x(t) = x 1 + (x 2 - x 1 )t, y(t) = y 1 + (y 2 - y 1 )t x = x max Intersection: x max = x 1 + (x 2 - x 1 )t t = (x max -x 1 )/(x 2 -x 1 ) x i = x max y i = y 1 + (y 2 - y 1 ) (x max -x 1 )/(x 2 -x 1 ) x1, y1x1, y1 x2, y2x2, y2 x max xi, yixi, yi
17
Sutherland-Hodgeman poligon clipping PolygonClip(p[n] q[m]) m = 0; for( i=0; i < n; i++) { if (p[i] inside) { q[m++] = p[i]; if (p[i+1] outside) q[m++] = Intersect(p[i], p[i+1], boundary); } else { if (p[i+1] inside) q[m++] = Intersect(p[i], p[i+1], boundary); }
18
Rasterization transformationclipping rasterizationPixel ops Frame buffer model Geometric primitives: 0.1-1 microsec / primitive Pixels Few nanosec / pixel
19
Line segment rasterization Explicit equation of the line: y = mx + b Drawing algorithm: for( x = x1; x <= x2; x++) { Y = m*x + b; y = Round( Y ); write( x, y ); } x1x2
20
Incremental principle Equation: Y(X) = mX + b = Y(X-1) + m DDADrawLine(int x1, int y1, int x2, int y2) { float m = (y2 - y1)/(x2 - x1); float y = y1; for(int x = x1; x <= x2; x++) { int Y = round(y); WRITE(x, Y, color); y = y+m; }
21
DDA line rasterization hardware X countery register x1 m y1 XY CLK
22
Triangle fill (X1,Y1)(X1,Y1) (X2,Y2)(X2,Y2) (X3,Y3)(X3,Y3) y x(y)x(y) Dx/Dy x(y+1)x(y+2) Dx/Dy
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.