第七章 Hidden Surface Removal
-
Upload
samuel-simmons -
Category
Documents
-
view
75 -
download
2
description
Transcript of 第七章 Hidden Surface Removal
1
第七章 Hidden Surface Removal
2
Hidden-Line Removal
Hidden-Surface Removal
方法: 1. Back-Face Removal 2. Depth-Buffer Z-Buffer 3. Scan-Line Method
4. Depth Sorting 5. Area Subdivision 6. Octree Method
3
Hidden-LineHidden-Surface Removal
Object Space 用物體的幾何定義來計算。 物體 → 幾何定義 → 點、線、面
→ 決定哪部分物體是看得到的 → 畫出看得到的部分物體 → 畫素畫出
Image Space 用畫出物體的畫素 (pixels) 來計算。 物體 → 物體畫出來的畫素 → 畫素
→ 決定哪些畫素是看得到的 → 畫出看得到的畫素 → 畫素畫出
4
Back-Face Removal
利用平面程式來決定哪些平面在後面,即看不到的平面Plane Equation
在 Right-Handed Coordinate System
如果
0 DCzByAx
0 dzCyBxA則 ),,( zyx
在“ Inside” of plan),,( zyx
0 DCzByAx
點與面的關係
5
Identify all hidden surfaces
特點: 1. 快速決定 Completely Visible
Completely Hidden
因為在幾何運算較簡單 2. Partially Hidden
Need more test 再處理 可先處理大部分的面
fast
Y
X
Zviewpoint
viewDirection
N(A,B,C)
>0
<0
平面Plane 看不到Invisible, hidden
0 DCzByAx
6
假設 為 viewing position 。
向一平面 看去。
● 如果 true
Back Face
Cannot see from
0 DCzByAx
),,( zyx
),,( zyx
0 dzCyBxA
7
Normal Vector of Plane 0 DCzByAx
N(A,B,C)
Normal Vector 的 Component C 是平行 Viewing Direction
● 如果 C<0
Normal Vector points away from viewing position 指向離開 Back Face
Z
C
0 DCzByAx
8
Plane Equation
3 points on the plane (not colinear)
0 DCzByAx
333
222
111
zyx
zyx
zyx
33
22
11
1
1
1
zy
zy
zy
A
33
22
11
1
1
1
zx
zx
zx
B 1
1
1
33
22
11
yx
yx
yx
C
333
222
111
zyx
zyx
zyx
D 0
1
1
1
1
333
222
111
zyx
zyx
zyx
zyx
9
Two Planes
Plane 1 :
Plane 2 :
01111 DzCyBxA
02222 DzCyBxA
0212121 CCBBAA Plane 1 Plane 1
Plane 1 Plane 12
1
2
1
2
1
C
C
B
B
A
A
2
1
2
1
2
1
2
1
D
D
C
C
B
B
A
A 相同
10
Depth - Buffer Algorithm
Z – Buffer Algorithm
Image Space
● Test Visibility one pixel at a time
● For each (x,y) pixel, the surface with the smallest Z
at that position is visible
11
●
●
●
●
3S
ViewingDirection
,,( yx )3z
,,( yx )3z
,,( yx )2z
,,( yx )1z3S2S
1S
遠→ Z 大近→ Z 小
的 Z 值最小,有最小 Z 值,只顯示畫出 亮度
3Z
3Z3S),,( 3zyx
Intensity of S3 (Z3) Saved for position (x,y)
123 ZZZ
12
2 buffers
Depth Buffer : Store Z-value for each (x,y) position,
儲存所有 (x,y) 位置的
Refresh Buffer : Store Intensity Value for each (x,y) position
儲存所有 (x,y) 位置的
Z 值
亮度
13
步驟:0. Depth Normalized 0~1
Initially, all positions
Depth Buffer 1 (Maximum)
Refresh Buffer Background
1. 處理每一 Surface ,轉成畫素,計算每一個 (x,y) 位置
的 Z-value
2. 比較相同 (x,y) 位置的 Z-value
3. 如果新的 Z 比較小,儲存新的 Z 改變 Intensity
14
Depth – Buffer Algorithm
(Z - Buffer) 1. Initialize Depth Buffer and Refresh Buffer 。
初始值 所有的 (x,y) 位置 Depth (x,y)=1
Refresh (x,y)=Background
2. 計算 Surface 上每一 (x,y) 點的 Z 值。
設 Z(x,y) =z 為其 Z 值。
I (x,y) =i 為其亮度 Intensity 。
15
3. If Z (x,y)<Depth (x,y) Z 在前面
Then set Depth (x,y) = Z (x,y)
Refresh (x,y) = I (x,y)
If z < 目前 Depth (x,y) 不在前
Not Vision
4. 重複處理所有 Surfaces 的所有 (x,y) 位置。
16
Depth-Buffer(Z-Buffer) 方法
相當於是尋找最小的 zi 以表現 (x,y) 畫出的亮度Depth–Buffer
Refresh–Buffer最小 Z 值,表現其亮度及畫出
,,( yx )1z
,,( yx )2z
,,( yx )3z
,,( yx )4z
z1 最小
,,( yx )1z
(x,y) 位置只畫出 的亮度顏色,,( yx )1z
17
Scan - Line Method
Image-Space● one scan line at a time 一次處理一條掃描線● 所有與 Scan line 有 intersection 交點的 edges 邊線, 將被用來判斷一 Surface 面是否 Visible
1. 所有的面的邊緣列出並 sorted in order of increasing x 。
2. 一條一條 Scan line 從左到右掃描通過所有 Surface 。
3. Scan line 與 Surface 交點給一 flag 。
Scan Line
outsideinside
outside
X+ON OFF
從左進入 (outside→inside) → 給 ON
從右離開 (outside→inside) → 給 OFF
18
Line 1 通過 AB, BC, HE, EF
Line 1 AB → BC 只有 S1 flag ON Intensity for S1 ON 只畫 S1 HE → EF 只有 S2 flag ON
A
B
CH
D G
E
F
S1S2
1
23
23
Scan line1
Line 2 通過 DA, HE, BC, FG DA →HE S1 ON HE →BC BOTH ON BC →FG S1 OFF S2 ON FG → S2 OFF
19
● 只有一個 Surface ON
只畫一個 Surface
● Both Surface ON
計算 depth ,詳細比較 例如 depth of S1< S2
則顯示 S1 ,直到通過 BCS1
S2
ON
ON
ON
ON
ON
ON
ON
OFF
OFF
OFF
OFF
1OFF
2
3
OFF→Background
20
Depth – Sorting Method
Image-Space
Object-Space
● 在 Object-Space 比較深度 在 Image-Space 做 Scan-conversion 由遠到近畫出
● Both
1. Surfaces 做 Depth Z 由大到小的排列 •Object Space•Largest Z-value of each surface
Z 大 P, Q,R, S, T Z小
Surfaces
21
2. Resolve ambiguities 。解決不清楚處 Reordering 。重排 Z 大 → Z 小
3. Surfaces 以 Depth Z 大到小的順序,做 Scan-Conversion 畫出。
•由遠而近, Z 大 → Z 小•Image Space
主要方法 Sorting in Object Space
Scan-Conversion in Image Spacealso call painter’s Algorithm
22
假設有 P,Q,R,… Surface
由大 Z 到小 z 排列
•假如在 Depth 上沒有重疊 → 依序做 Scan-convert
•假如在 Depth 上有重疊 → Test
23
假設有 Q 與 P 重疊以下 Test Q 與 P , 4 項 Test
1. 2 個 Surfaces 投影到 X-Y plane ,在 X-Y plane 上2 個 Surfaces 的 Bounding Rectangle 沒有重疊,在X-extent , Y-extent 都無重疊。
2. Surface P is on outside of Q.
3. Surface Q is on inside of P.
4. 2 個 Surface 在 X-Y 平面 plane 上的投影沒有重疊。
( 同一側 )
(Zpmax>ZQmax)相對於 view plane, outside 遠
inside 近
(Zpmax<ZQmax)outside 遠inside 近
( 同一側 )
24
Q
Zv
XvNo Depth Overlap
P
Zv
Q
Xv
P
Q
Zv
Yv
P
1.
有 Depth overlap No overlap
inXY
Direction
25
2.
P is “outside” Q
P is “outside” Q
Zv
Xv
outside
inside
QP
Zv
Xv
outside
insideQ
P
ViewDirection
26
3.
P is “inside” Q
P is “inside” Q
Zv
Xv
Q
P
Zv
Xv
Q
P
27
計算方法
Test 1:比較 Bounding Rectangles 的 X-extent , Y-extent 之座標。
Test 2:Q plane Equation EX + FY + GZ + H = 0 Vertices of P 代入 Q plane e.q.
Ex + Fy + Gz + H > 0 P outside Q
(x,y,z)
28
Test 3:P plane equation
AX + BY + GZ + D = 0
Vertices of Q 代入 P plane equation
Ax’ + By’ + Cz’ + D < 0
Q inside P
(x’,y’,z’)
29
Test 4:
1. 計算是否有 intersection 。
2.Surfaces 在 X-Y 平面上的投影 projection 是否有 intersection 。
y
x
y
x
30
交疊交切複雜時,先分割小的單純面。
Q
Q1
Q2
31
以上 4 Test1) 如果至少 1 個正確成立 保持原來 order
2) 如果全部不成立 Interchange P,Q( 交換 P,Q)
將 P,Q 在 sorted order list 中之位置交換
•P,Q,R 原來 Z 大→ Z 小•Swap P,Q•Swap R,Q•結果 Q R P
1. 不成立2.P 代入 R equation<0
3.R 代入 P equation>04. 不成立
原來 Z 大→ Z 小P Q R
Z 大
Z 小
P QR
view
(Z 大到 Z 小 )
32
Area Subdivision MethodImage Space
•一直連續分割一個區域成數個小方塊。•直到每小方塊都是單純的 Visible or Hidden or No Surface
1. Subdivision
2. Single visible surface or No surface
3. If NOT → subdivision → (1)
4. Smallest division → a pixel
33
Area SubdivisionWarnock’s Algorithm
比較Subdivided Area 小方塊與Surface
的關係
SurroundingSurfaceSurface 完全包含 Area
OverlappingSurfaceSurface部分在內部分在外
InsideSurfaceSurface 完全在 Area 內
OutsideSurfaceSurface 完全在 Area 外
Surface
Area
S
Area Area
S
Area
Surface
34
結果
1. Surfaces 都在 Area outside
→ Background color displayed in the area
2. 只有一個 Surface 且是 inside or overlapping
→ 先填 area 為 Background color ,在畫 Surface 在area 內的部分
3. 只有一個 Surface 且是 Surrounding
→ area 全畫 Surrounding Surface 的顏色4. 超過 1 個 Surfaces 是 inside , overlapping , or
surrounding ,但有一 Surrounding 為最小 Z
→ area 畫此最小 Z( 最近 ) 的 Surrounding Surface
35
如果以下有 1 個成立,就不必再做 Subdivision 。
1. 全部 Surfaces 都是 outside the area 。2. 在 area 內只有 1 個 inside , overlapping , or
surrounding 的 surface 。3. 一個 Surrounding surface 的 Z 值最小,蓋過其他
surface 。
intersectionsurrounding
outsideinside
Area
ViewDir.
Z
X
X
36
●
● ●
● ● ●
● ● ● ●
● ● ● ● ●
● ● ● ● ● ●
● ● ● ● ● ● ●
● ● ● ● ● ● ● ●
pixel position
Surface S1
● ● ● ● ● ● ● ●
● ● ● ● ● ● ●
● ● ● ● ● ●
● ● ● ● ●
● ● ● ●
● ● ●
● ●
●
先畫
Surface S2
● ● ● ● ● ● ● ●
● ● ● ● ● ● ●
● ● ● ● ● ●
● ● ● ● ●
● ● ● ● ●
● ● ● ● ● ●
● ● ● ● ● ● ●
● ● ● ● ● ● ● ●
Final Image
○
○ ○
○ ○ ○
○ ○ ○ ○
○ ○ ○ ○
○ ○ ○
○ ○
○
Hidden Area(S2)
37
如果 Subdivision 一直到 area 小的為 1 個 pixel
→compare depth
→類似 Z-buffer
變化的 area 分割法,以具有 min Z 的 surface 來subdivide a area ,沿著 surface boundary 做 subdivision
A1 A2
S
38
Quadtree 四分樹
•area 分成四份•比較每一份中 surface 與 area 的關係•Visible Hidden Inside Outside 關係清楚著色畫出•不清楚者再做 Quadtree division
12
3 0
39
Octree 八分樹
for viewing volume
project octree nodes onto viewing surfaces
0,1,2,3 → front octants → visible4,5,6,7 → back octants → hidden → removed
730
12
45
6
view
3
0
2
1
view