Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Rendering
3D Scene 2D Image
Graphics Rendering Pipeline
Modeling
Transformation Viewing
Model 1 Transformation
M1
Model 2 M2 3DWorld V 3D View
Scene Scene
Mn
Model n
2D
Image
Rasterization 2D Scene Projection
Clipping
Extraction of data/primitives inside a region of
interest “window”
=> Discard (parts of ) primitives outside window.
1
2
3
5
1xxx
x1xx
Clipping
Cohen and Sutherland
4 bit code to indicate the zone of end points of line
with respect to window
Trivially accept
Clipping
Cohen and Sutherland
Trivially reject
Clipping
Cohen and Sutherland
Potentially visible
Clipping
Cohen and Sutherland
If potentially visible
•subdivide into segments and apply trivial acceptance
and rejection test
•segments by intersection with window edges
•edges in any order but consistent
(e.g., top-bottom, right-left)
D
B B
A A
Result
Clipping
Cohen and Sutherland
B
Parametric line (input line AB):
A
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
Evaluate
l (Q ) = (Q − P ).n
P
n
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
L(t ) = A + (B − A)t
l (Q ) = (Q − P ).n
A B
l (L(t )) = 0; solve for t
P n (L(t ) − P ).n = 0
( A + t (B − A) − P ).n = 0
( A − P ).n + t (B − A).n = 0
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
( A − P ).n
B
t=
A (B − A).n
( A − P ).n
P t=
n ( A − P ).n − (B − P ).n
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
B (t=1)
A (t=0)
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
B (t=1)
( A − P ).n
t=
(B − A).n
n D = (B − A).n
D > 0 label t as tE
Entering
A (t=0)
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
B (t=1)
( A − P ).n
t=
(B − A).n
D = (B − A).n
n D < 0 label t as tL
Leaving
A (t=0)
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
B (t=1)
t of interest:
max
largest tE t E
n smallest tL t Lmin
A (t=0)
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
V6 V5 P2
E5
E6
V7 E4 V4
E3
E7
P1 V8 V3
E8 E2
E1
V1 V2
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
Arbitrary Convex Window
V6 V5
E1xE 2 : positive
P2
E5 E 2 xE 3 : positive
E6 .
V7 E4 V4
.
E3 .
E7
P1 V8 V3
E8 E2
E1
V1 V2 Polygon is convex if for all
adjacent edges the sign of
cross product is same.
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
Arbitrary Window
E1xE 2 : positive
V6 V5 E 2 xE 3 : positive
E4 E 3 xE 4 : negative
V4 .
E3 V3 .
E2 .
E1
V1 V2
Polygon is non-convex
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
Arbitrary Window
Make the polygon convex by
V6 V5 P2
adding the edge V3V5
E4 P4
V4 Clip against the convex polygon
E3 V3 => P3P4
P3
E2
P1 E1
V1 V2
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
Arbitrary Window
Clip against the triangle
V5
=> P5P4
P4
V4
Subtract P5P4 from P3P4
P5 V3
P3 => P3P5
Windowing
Window to Viewport Mapping
Window: rectangular region of interest in scene
Viewport: rectangular region on device
Need mapping from window point (xw,yw) to viewport point (xv, yv)
Windowing
Window to Viewport Mapping
Length and height of window: Lw and Hw
Length and height of viewport: Lv and Hv
For y:
∆y ∆y y −y y −y H
=
w
;v w
=wb
⇒y =v
(y − y ) + y
vb
v
v
w wb vb
Hw
Hv
H w
H H v w
H H
w
: window aspect ratio , : viewport aspect ratio
v
Lw
L v
(0,0)
World space NDC space Screen space