0% found this document useful (0 votes)
28 views77 pages

3dcg08 05vsd

The document discusses several algorithms for visible surface determination and hidden surface removal in computer graphics, including back-face culling, depth-sort algorithm, binary space-partitioning trees, and z-buffer algorithm.

Uploaded by

Manav Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views77 pages

3dcg08 05vsd

The document discusses several algorithms for visible surface determination and hidden surface removal in computer graphics, including back-face culling, depth-sort algorithm, binary space-partitioning trees, and z-buffer algorithm.

Uploaded by

Manav Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 77

Computer Graphics

Bing-Yu Chen
National Taiwan University
Visible-Surface Determination
 Back-Face Culling
 The Depth-Sort Algorithm
 Binary Space-Partitioning Trees
 The z-Buffer Algorithm
 Scan-Line Algorithm
 Visible-Surface Ray Tracing
(Ray Casting)
 Warnock’s Algorithm
Visible-Surface Determination
= Hidden Surface Removal
 Determining what to render at each pixel.
 A point is visible if there exists a direct line-of-sight to
it, unobstructed by another other objects (visible
surface determination).
 Moreover, some objects may be invisible because
there are behind the camera, outside of the field-of-
view, too far away (clipping) or back faced (back-
face culling).
Hidden Surfaces: why care?
 Occlusion: Closer (opaque) objects
along same viewing ray obscure more
distant ones.
 Reasons for removal
 Efficiency: As with clipping, avoid
wasting work on invisible
objects.
 Correctness: The image will look wrong if
we don’t model occlusion properly.
Back-Face Culling = Front Facing
x
B

C
D

E
F
H

z G
Back-Face Culling = Front Facing
 use cross-product to get the normal
of the face (not the actual normal)
 use inner-product to check the
facing
v1
N  (v2  v1 )  (v3  v1 )
N

v2
V v3
Clipping (View Frustum Culling)
view frustum

occlusion
back
eye
face

view frustum
List-Priority Algorithms
 The Painter’s Algorithm
 The Depth-Sort Algorithm
 Binary Space-Partitioning Trees
The Painter’s
Algorithm

 Draw primitives
from back to front
need for depth
comparisons.
The Painter’s
Algorithm
 for the planes with constant z
 not for real 3D, just for 2½D

 sort all polygons according to the smallest


(farthest) z coordinate of each
 scan convert each polygon in ascending
order of smallest z coordinate (i.e., back to
front)
The Depth-Sort Algorithm
 sort all polygons according to the smallest
(farthest) z coordinate of each
 resolve any ambiguities that sorting may
cause when the polygons’ z extents
overlap, splitting polygons if necessary
 scan convert each polygon in ascending
order of smallest z coordinate (i.e., back to
front)
Overlap Cases

y y
x
R
Q P
P Q
P Q

z x x
Overlap Detection
 Do the polygons’x not overlap?
 Do the polygons’y not overlap?
 Is P entirely on the opposite side of
Q’s plane from the viewpoint?
 Is Q entirely on the same side of
P’s plane as the viewpoint?
 Do the projections of the polygons
onto the (x,y) plane not overlap?
Binary Space-Partitioning Trees
 An improved painter’s
algorithm f(p)>0
 Key observation:
f(p)<0

T3
T1
T5
T2
Ax+By+Cz+D=0
T4 f(p): n(p-a)=0
Binary Space-Partitioning Trees
T1
- +

T2 T3
T1

T3
T2
Binary Space-Partitioning Trees
T1
- +

T2
- +
T1
T3

T3
T2
Splitting triangles
a a

A A
c c

B B

b b
BSP Tree Construction
BSPtree makeBSP(L: list of polygons) {
if (L is empty) {
return the empty tree;
}
Choose a polygon P from L to serve as root;
Split all polygons in L according to P
return new TreeNode (
P,
makeBSP(polygons on negative side of P),
makeBSP(polygons on positive side of P))
}
 Splitting polygons is expensive! It helps to choose P wisely
at each step.
 Example: choose five candidates, keep the one that splits
the fewest polygons.
BSP Tree Display
void showBSP(v: Viewer, T: BSPtree) {
if (T is empty) return;
P = root of T;
if (viewer is in front of P)
{ showBSP(back subtree of
T); draw P;
showBSP(front subtree of T);
} else {
showBSP(front subtree of T);
draw P;
showBSP(back subtree of T);
}
} 2D BSP demo
Binary Space-Partitioning Trees
P1 P1
A P2 front back

1 P2 P2

back
3 front front back
D B
2
D C A B
3,1, 3,2,1 1,2,3
C
2 2,1,3

 extremely efficient for static objects


Binary Space-Partitioning Trees
 Same BSP tree can be used for
any eye position, constructed only
once if the scene if static.
 It does not matter whether the
tree is balanced. However, splitting
triangles is expensive and try to
avoid it by picking up different
partition planes.
BSP Tree
6 5

9
7 10 8
1
11
2

4
3
BSP Tree
6 5 1

inside outside
9
ones ones
7 10 8
1
11
2

4
3
BSP Tree
6 5 1

2 5
9 3 6
4 7
7 10 8
8
1 9
10
11
11
2

4
3
BSP Tree
6 1
5

5
9 9b
6 8
7 10 11 7 9b
8
9a b
1 9a 11
10 b
11
11 11
2 a a
4
3
BSP Tree
6 5
1

9 9b 2 5

7 10 11 3 6 8
8
9a b
1
11 4 7 9b
11
2 a
4 9a 11
b
3 10

11a
BSP Tree
6 5
1

9 9b 2 5

7 10 11 3 6 8
8
9a b
1
11 4 7 9b
11
2 a
4 9a 11
point b
3 10

11
a
BSP Tree Traversal
6 5
1

9 9b 2 5

7 10 11 3 6 8
8
9a b
1
11 4 7 9b
11
2 a
4 9a 11
point b
3 10

11
a
BSP Tree Traversal
6 5
1

9 9b 2 5

7 10 11 3 6 8
8
9a b
1
11 4 7 9b
11
2 a
4 9a 11
point b
3 10

11
a
The z-Buffer Algorithm
 Resolve depths at the pixel level
 Idea: add Z to frame buffer,
when a pixel is drawn, check
whether it is closer than what’s
already in the frame buffer
The z-Buffer Algorithm

+ =

+ =
The z-Buffer Algorithm
void zBuffer() {
int pz;
for (each polygon) {
for (each pixel in polygon’s projection) {
pz=polygon’s z-value at (x,y);
if (pz>=ReadZ(x,y)) {
WriteZ(x,y,pz);
WritePixel(x,y,color);
}
}
}
}
The z-Buffer Algorithm

y
y y
z1
y1 za  z1  (z1  z2 ) y11  y2s
za zp zb Scan line y1  y s
ys zb  z1  (z1  z3 )
y2 y1  y
z2
3
xb  x p
z p  zb  (zb  z a )
y3 z3 xb 
xa
z-Buffer: Example

color buffer depth buffer


The z-Buffer Algorithm
 Benefits
 Easy to implement
 Works for any geometric primitive
 Parallel operation in hardware
 independent of order of polygon
drawn
 Limitations
 Memory required for depth buffer
 Quantization and aliasing artifacts
 Overfill
 Transparency does not work well
Scan-Line Algorithm
y E

B
γ+2
γ+1
γ D

C
β
F
α

A
x
Scan-Line Algorithm
AET contents

Scan line Entries

ET entry x Δx ID α AB AC
ymax
β ABAC FD FE
γ,γ+1 ABDE CB FE

PT entry ID Plane eq. Shading info In-out γ+2 ABCB DE FE

 ET = edge table
 PT = polygon table
 AET = active-edge table
General Scan-Line Algorithm
add surfaces to polygon table (PT);
initialize active-edge table (AET);

for (each scan line) {


update AET;

for (each pixel on


scan line) {
determine surfaces in AET that project to pixel;
find closest such surface;
determine closest surface’s shade at pixel;
}
}
Ray Tracing = Ray Casting
select center of projection and window on viewplane;
for (each scan line in image) {
for (each pixel in scan line) {
determine ray from center of projection through pixel;
for (each object in scene) {
if (object is intersected and is closest considered thus far)
record intersection and object name;
}
set pixel’s color to that at closest object intersection;
}
}
Ray Casting

Center of
projection
Window
Ray Casting (Appel, 1968)
Ray Casting (Appel, 1968)
Ray Casting (Appel, 1968)
Ray Casting (Appel, 1968)


n
Li  N
nls
k a Ia   i I d k i s

 k R V  
i1
Ray Casting (Appel, 1968)

direct illumination
Spatial Partitioning
Spatial Partitioning

A B
Spatial Partitioning

B
3 2
Space Subdivision
Approaches

Uniform grid K-d tree


Space Subdivision
Approaches

Quadtree (2D) BSP tree


Octree (3D)
Uniform Grid
Uniform Grid
Preprocess scene
1. Find bounding box
Uniform Grid
Preprocess scene
1. Find bounding box
2. Determine grid resolution
Uniform Grid
Preprocess scene
1. Find bounding box
2. Determine grid resolution
3. Place object in cell if its
bounding box overlaps the
cell
Uniform Grid
Preprocess scene
1. Find bounding box
2. Determine grid resolution
3. Place object in cell if its
bounding box overlaps
the cell
4. Check that object
overlaps cell (expensive!)
Uniform Grid Traversal
Preprocess scene
Traverse grid
3D line = 3D-
DDA
From Uniform Grid to Quadtree
Quadtree (Octrees)

subdivide the space adaptively


Quadtree Data Structure

Quadrant Numbering
Quadtree Data Structure

Quadrant Numbering
Quadtree Data Structure

Quadrant Numbering
Quadtree Data Structure

Quadrant Numbering
From Quadtree to Octree
y

z
K-d Tree
A

Leaf nodes correspond to unique regions in space


K-d Tree
A

Leaf nodes correspond to unique regions in space


K-d Tree
A

Leaf nodes correspond to unique regions in space


K-d Tree
C A

A
K-d Tree
C A

C
B

A
K-d Tree
C A

D B

C
B

A
K-d Tree
C A

D B

C
B
D
A
K-d Tree
A

D B

B C C

Leaf nodes correspond to unique regions in space


K-d Tree Traversal
A

D B

B C C

Leaf nodes correspond to unique regions in space


Warnock’s
Algorithm
 an area-subdivision algorithm
Warnock’s
Algorithm
1. all the polygons are disjoint from the area
2. there is only one intersecting or only one
contained polygon
3. there is a single surrounding polygon, but
no intersecting or contained polygons
4. more than one polygon is intersecting,
contained in, or surrounding the area, but
one is a surrounding polygon that is in
front of all the other polygons
Warnock’s
Algorithm

surrounding intersecting contained disjoint


Warnock’s
Algorithm
x x
Contained
polygon Intersecting
polygon

Surrounding
polygon
Intersecting
polygon
Surrounding
polygon
z z
Performance of Four Algorithms
for Visible-Surface Determination
Number of Polygons
Algorithm
100 2,500 60,000

Depth sort 1 10 507

z-buffer 54 54 54

Scan line 5 21 100

Warnock area subdivision 11 64 307

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy