Sei sulla pagina 1di 33

Graphics Rendering Pipeline

• Rendering is the conversion of a scene into an


image:

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.

Point Clipping: Remove points outside window.


•A point is either entirely inside the window or not
(xR, yT)
Q xL <= x <= xR
P
yB <= y <= yT
Q is inside
(xL, yB) P is outside
Clipping
Line Clipping: Remove portion of line segment
outside window

•Can we use point clipping for the end points?

1
2

Point clipping works


Clipping
Line Clipping: Remove portion of line segment
outside window

• How about these lines?

3
5

Point clipping does not work


Clipping
Cohen and Sutherland
Clipping
Cohen and Sutherland
4 bit code to indicate the zone of end points of line
with respect to window

1xxx

xxx1 0000 xx1x

x1xx
Clipping
Cohen and Sutherland
4 bit code to indicate the zone of end points of line
with respect to window

1001 1000 1010

0001 0000 0010

0101 0100 0110


Clipping
Cohen and Sutherland

Trivially accept case


•line is totally visible
•if both ends of the line have outcode as 0000

Trivially accept
Clipping
Cohen and Sutherland

Trivially reject case


•line is totally invisible
•logical AND of the two end points outcodes

Trivially reject
Clipping
Cohen and Sutherland

If not trivially reject and accept case


•line is potentially visible

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

•simple, still popular


•limited to rectangular region
•extension to 3D clipping using 3D orthographic
view volume is straightforward
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)

•any convex region

B
Parametric line (input line AB):

L(t ) = A + (B − A)t ;t ∈ (0,1)

A
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)

P Implicit line (window edge):


n
l (Q ) = (Q − P ).n
•Q
Tells us on which side of the line the point Q is.
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)

Evaluate
l (Q ) = (Q − P ).n

If > 0 inside halfspace of line (plane)


P If < 0 outside halfspace of line (plane)
n
If = 0 on the line
Outside
•Q
Should give indications for trivial accept
Inside and reject cases.
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)

Window edge l (Q ) = (Q − P ).n

Line segment L(t ) = A + t (B − A)


P
n
Outside Trivial Reject l ( A) < 0 AND l (B ) < 0
•Q
Trivial Accept l ( A) > 0 AND l (B ) > 0
Inside
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)

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)

n Which ‘t’ to select ?

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)

If t Emax > t Lmin


Reject
Clipping
Cyrus Beck Line Clipping
(Liang and Barsky)
Arbitrary Convex Window

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

window viewport (xvr, yvt)


(xwr, ywt)

(xw, yw) (xv, yv)


(xwl, ywb) (xvl, yvb)

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

Distance ratios for each coordinate:


For x:
∆x ∆x x −x x −x L
=w
; v w wl
= v
⇒x = (x − x ) + x
vl
v
v
w wl vl
Lw
L v
L w
L v
L w

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

If the two aspect ratios are the same no shape distortion


Clipping/Windowing
Window to Viewport Mapping
Normalized Device Coordinates: Intermediate coordinate system to
facilitate device independenc for specifying viewport.
(1,1)
window viewport

(0,0)
World space NDC space Screen space

Potrebbero piacerti anche