Hidden Surface Removal 1 HiddenLine Removal HiddenSurface Removal







































- Slides: 39

第七章 Hidden Surface Removal 1

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 2


Back-Face Removal 利用平面程式來決定 哪些平面在後面,即看不到的平面 Plane Equation 在Right-Handed Coordinate System 如果 則 在“Inside” of plan 點與面的關係 4

<0 N(A, B, C) >0 Y X Z view point view Direction 平面 Plane 看不到 Invisible, hidden Identify all hidden surfaces 特點: 1. 快速決定 Completely Visible Completely Hidden 因為在幾何運算較簡單 2. Partially Hidden Need more test 可先處理大部分的面 再處理 5 fast

為viewing position。 假設 向一平面 看去。 true ● 如果 Back Face Cannot see from 6

Normal Vector of Plane N(A, B, C) Z Normal Vector 的 Component C 是平行 Viewing Direction ● 如果C<0 Normal Vector points away from viewing position 指向離開 Back Face C 7

Plane Equation 3 points on the plane (not colinear) 8

Two Planes Plane 1: Plane 2: Plane 1 相同 9

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 10

● ● Viewing Direction 遠→Z 大 近→Z 小 的Z值最小, 有最小Z值,只顯示畫出 Intensity of S 3 (Z 3) Saved for position (x, y) 11 亮度

2 buffers Depth Buffer:Store Z-value for each (x, y) position, 儲存所有(x, y)位置的 Z值 Refresh Buffer:Store Intensity Value for each (x, y) position 儲存所有(x, y)位置的 亮度 12

步驟: 0. Depth Normalized 0~1 Initially, all positions Depth Buffer Refresh Buffer 1 (Maximum) Background 1. 處理每一Surface,轉成畫素,計算每一個(x, y)位置 的Z-value 2. 比較相同(x, y)位置的Z-value 3. 如果新的Z比較小,儲存新的Z改變Intensity 13

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。 14

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)位置。 15


Scan - Line Method Image-Space ● one scan line at a time 一次處理一條掃描線 line有intersection交點的edges邊線, 將被用來判斷一Surface面是否Visible 1. 所有的面的邊緣列出並sorted in order of increasing x。 ● 所有與Scan 2. 一條一條Scan line從左到右掃描通過所有Surface。 3. Scan line與Surface交點給一flag。 從左進入(outside→inside) →給ON 從右離開(outside→inside) →給OFF 17 outside Scan Line ON inside outside OFF X+

B 1 2 3 E S 1 Scan line 1 F A H D S 2 C 2 3 G Line 1 通過AB, BC, HE, EF Line 1 AB → BC 只有S 1 flag ON Intensity for S 1 ON 只畫S 1 HE → EF 只有S 2 flag ON Line 2 通過DA, HE, BC, FG DA →HE S 1 ON HE →BC BOTH ON BC →FG S 1 OFF S 2 ON FG → S 2 OFF 18

● 只有一個Surface ON 只畫一個Surface ● Both Surface ON 計算depth,詳細比較 例如depth of S 1< S 2 則顯示S 1 ,直到通過BC S 2 S 1 ON ON ON OFF 1 OFF 2 ON OFF 19 3 OFF→Background

Depth – Sorting Method ● Both Image-Space Object-Space ● 在Object-Space比較深度 在Image-Space做Scan-conversion由遠到近畫出 1. Surfaces 做Depth Z由大到小的排列 • Object Space • Largest Z-value of each surface Z大 P, Q, R, S, T Z小 20 Surfaces

2. Resolve ambiguities。解決不清楚處 Reordering。重排 Z大 → Z小 3. Surfaces 以Depth Z大到小的順序,做Scan-Conversion 畫出。 • 由遠而近,Z大 → Z小 • Image Space 主要方法 Sorting in Object Space Scan-Conversion in Image Space also call painter’s Algorithm 21


假設有Q與P重疊 以下Test Q與P,4項Test 1. 2個Surfaces投影到X-Y plane,在X-Y plane上2個 Surfaces的Bounding Rectangle沒有重疊,在Xextent,Y-extent都無重疊。 (同一側) 2. Surface P is on outside of Q. (Zpmax>ZQmax) outside 遠 相對於view plane, inside 近 (同一側) 3. Surface Q is on inside of P. (Zpmax<ZQmax) outside 遠 inside 近 4. 2個Surface在X-Y平面plane上的投影沒有重疊。 23

1. Zv Zv P P Q Q Xv No Depth Overlap Yv Zv 有Depth overlap No overlap X in Direction Y P Q Xv 24

2. Zv P outside Q View Direction inside P is “outside” Q Xv Zv outside inside Q P P is “outside” Q Xv 25

3. Zv P P is “inside” Q Q Xv 26

計算方法 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. (x, y, z) Ex + Fy + Gz + H > 0 P outside Q 27

Test 3: P plane equation AX + BY + GZ + D = 0 Vertices of Q代入P plane equation (x’, y’, z’) Ax’ + By’ + Cz’ + D < 0 Q inside P 28

Test 4: 1. 計算是否有intersection。 y y x x 2. Surfaces在X-Y平面上的投影projection是否有 intersection。 29



Area Subdivision Method Image 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 32

Area Subdivision Warnock’s Algorithm Subdivided Area小方塊 的關係 比較 與 Surface Area Surrounding Surface完全 包含Area S Area Overlapping Surface 部分在內 部分在外 Area S Inside Surface完全 在Area內 33 Area Outside Surface完全 在Area外

結果 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 34

如果以下有1個成立,就不必再做Subdivision。 1. 全部Surfaces都是outside the area。 2. 在area內只有1個inside,overlapping,or surrounding的 surface。 3. 一個Surrounding surface的Z值最小,蓋過其他surface。 X outside intersection surrounding Z View Dir. Area X 35

pixel position 先畫 Surface S 1 Surface S 2 Final Image Hidden Area(S 2) 36

如果Subdivision一直到area小的為 1個pixel →compare depth →類似 Z-buffer 變化的area分割法,以具有 min Z的surface來subdivide a area,沿著surface boundary做subdivision S A 1 A 2 37

Quadtree 四分樹 2 • area分成四份 • 比較每一份中surface與area的關係 • Visible Hidden Inside Outside 關係清楚著色畫出 • 不清楚者再做Quadtree division 38 3 1 0

Octree 八分樹 for viewing volume 6 5 1 4 0 2 3 7 view 0 1 3 2 project octree nodes onto viewing surfaces 0, 1, 2, 3 → front octants → visible 4, 5, 6, 7 → back octants → hidden → removed 39