View
218
Download
1
Tags:
Embed Size (px)
Citation preview
The visibility problem
• What polygons are visible?• There are few visible polygons.
– Avoid redundant processing
• Three classes of non visible objects– Outside the volume (view frustum culling)– Facing away (back-face culling)– Occluded (occlusion culling)
Clipping
• 2D clipping– Line / polygon clipping by the viewport– 3D frustum culling– Occlusion culling– Lines are used for polygons
Convex
• Convex polygon – line between every two points belong to the polygon.
• The intersection of two convex regions – convex region (single).
• The intersection of convex and concave ?
• Clipping – intersection of a polygon with rectangle.
Clipping lines
• Both points inside – trivially accepted
• Brute force:– Calculate the infinite line-edge intersection– Check if the intersection is on the edge/line
Cohen-Sutherland algorithm
• Trivial acceptance
• Trivial rejection
• Subdivision into two trivial parts
• Especially effective in two common cases:– Large viewports– Small viewports
Cohen-Sutherland algorithm
• Region coding• Assign code to endpoints• Simple calculation
– Sign for bit value– Zero for acceptance– And for rejection– Or for acceptance
0 - in1 - out
1
34
2
bit
y y min
y y max
x x max
x x min
y y min
y y max
x x max
x x min
Cohen-Sutherland example• Line AB
• And(A,B) = 0, Or(A,B) ≠ 0• Test A with bottom edge• Create AC (rejected) and CB• Code(C) = 0 → Choose B• Test B with the right/top edge
A
CD
E
B
Cohen-SutherlandC-S -Clip
C - S -Clip
(
code code
if ( ( and ) 0 ) then return
if ( ( or ) 0 ) then draw( )
else if (OutsideWindow( ) ) then
begin
Window boundary of leftmost non - zero bit of
(
end
else
Window boundary of leftmost non -
P x y P x y x x y y
C P C P
C C
C C P P
P
Edge C
P P P Edge
P P x x y y
Edge
0 0 0 1 1 1
0 0 1 1
0 1
0 1 0 1
0
0
2 0 1
1 2
( , ), ( , ), , , , )
( ); ( );
! ;
, ;
;
, ;
, , , , , );
min max min max
min max min max
zero bit of
(
end
C
P P P Edge
P P x x y y
1
2 0 1
0 2
;
, ;
, , , , , );min max min max
C-S -Clip
Cyrus-Beck algorithm
• Put line in a parametric form
P(t) = P0 + (P1 – P0)t
• Calculate 4 line-edge intersections – only 1D
• Check if there is intersection
P0
P1
C1
C0
Cyrus-Beck algorithm
• Denote L(t) = P0+(P1 P0)t, t[0,1] .
• PiD is a point on the edge Li
D with normal NiD.
• For every vector V colinear with LiD, VNi
D = 0.
• Specifically, for V=L(t) PiD,
0 = NiD(L(t) Pi
D)
NiD
P0
P1
L(t)
L(t1)PiD
L(t3)PiD
PiDLi
D
Cyrus-Beck algorithm0 = Ni
D (L(t) PiD)
= NiD (P0 + (P1 P0)t Pi
D)
= NiD (P0 Pi
D) + NiD ((P1 P0)t)
Solving for t, where = (P1 P0):
Works especially fast when rectangle is upright
Di
Di
Di
Di
Di
Di
N
PPN
PPN
PPNt 0
01
0
Cyrus-Beck algorithm• If Ni
D = 0, L and LiD are parallel
• The intersections of L and LiD are computed
• If ti[0,1], there might be an intersection
• Based on the sign of NiD, each point is
classified as PE (potentially entering) or PL (potentially leaving)
• PE with the largest t and PL with the smallest t define the intersection
Di
Di
Di
Di
Di
Di
N
PPN
PPN
PPNt 0
01
0
P1
P1
PE
PE
PL
PLPE
PL
P0
P1
P0
P1
PL
PE
Cohen-Sutherland – polygons
• Create a list of vertices – {v1, …, vn}
• Clip against a single infinite edge
Cohen-Sutherland – polygons
s
p
Inside Outside
s
p
Inside Outside
s
pInside Outside
s
p
Inside Outside
1st Output
i
Output No Output
i
2nd Output
Output
Hierarchical clipping
• Build hierarchical scene representation– The bounding box of root includes the children
• Test the root node– If it is outside, stop and discard everything– If it’s fully inside, render everything– Otherwise, test recursively every child