CG Chapter 6

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 21

COMPUTER GRAPHICS

Lecture 6
Hidden Surface Removal and Rasterization

1
HIDDEN SURFACE REMOVAL

 Drawing polygonal faces on screen


consumes CPU cycles
 Illumination
 We cannot see every surface in scene
 We don’t want to waste time rendering primitives
which don’t contribute to the final image.

2
VISIBILITY (HIDDEN SURFACE
REMOVAL)
 A correct rendering requires correct visibility calculations
 Correct visibility
 when multiple opaque polygons cover the same screen space, only
the closest one is visible (remove the other hidden surfaces)

 wrong visibility correct visibility

3
VISIBILITY OF PRIMITIVES
 A scene primitive can be invisible for 3 reasons:
 Primitive lies outside field of view
 Primitive is back-facing
 Primitive is occluded by one or more objects nearer
the viewer

4
VISIBLE SURFACE ALGORITHMS.

•Object space techniques: applied before vertices are mapped to


pixels
•Back face culling, Painter’s algorithm, BSP trees

•Image space techniques: applied while the vertices are being


rasterized
•Z-buffering

5
BACK FACE CULLING.
 The vertices of polyhedra are oriented
in an anticlockwise manner when
viewed from outside – surface normal
N points out.
 Project a polygon.
 Test z component of surface
normal. If negative – cull, since
normal points away from viewer.
 Or if N.V > 0 we are viewing the
back face so polygon is obscured.

6
PAINTERS ALGORITHM (OBJECT SPACE).
 Draw surfaces in back
to front order – nearer
polygons “paint” over
farther ones.
 Supports transparency.
 Key issue is order
determination.

7
BSP (BINARY SPACE PARTITIONING)
TREE.
•One of class of “list-priority” algorithms – returns
ordered list of polygon fragments for specified view 5
point (static pre-processing stage).

•Choose polygon arbitrarily 2

•Divide scene into front (relative to normal) and


back half-spaces. 3
1 4
•Split any polygon lying on both sides.

•Choose a polygon from each side – split scene


again.

•Recursively divide each side until each node View of scene from above
contains only 1 polygon.
BSP TREE.
5
5a
5b
2
•Choose polygon arbitrarily
3
•Divide scene into front (relative to 1 4
normal) and back half-spaces.

•Split any polygon lying on both sides.

•Choose a polygon from each side – split


scene again. front back
3

•Recursively divide each side until each 4


node contains only 1 polygon. 1 5b
2
5a

Lecture 9 919/10/2007
BSP TREE. 5

5a
2 5b
•Choose polygon arbitrarily

•Divide scene into front (relative to 3


1 4
normal) and back half-spaces.

•Split any polygon lying on both sides.

•Choose a polygon from each side –


split scene again. front back
3

•Recursively divide each side until each 2


front 4
node contains only 1 polygon. 5b
5a 1
BSP TREE. 5
5a
2 5b
•Choose polygon arbitrarily
3
•Divide scene into front (relative to 1 4
normal) and back half-spaces.

•Split any polygon lying on both sides.

•Choose a polygon from each side – split


scene again. 3
front back

•Recursively divide each side until 2 4


front
each node contains only 1 polygon.
5a 1 5b
BSP TREE.
 A lot of computation required at start.
 Try to split polygons along good dividing plane
 Intersecting polygon splitting may be costly
 Cheap to check visibility once tree is set up.

 Efficient when objects don’t change very often in the


scene.

Lecture 9 1219/10/2007
Z-BUFFERING : IMAGE SPACE
APPROACH
Basic Z-buffer idea:
 rasterize every input polygon
 For every pixel in the polygon interior, calculate
its corresponding z value (by interpolation)
 Track depth values of closest polygon (smallest z)
so far
 Paint the pixel with the color of the polygon
whose z value is the closest to the eye.

13
14
15
16
17
IMPLEMENTATION.
 Initialise frame buffer to background colour.
 Initialise depth buffer to z = max. value for far clipping
plane
 For each triangle
 Calculatevalue for z for each pixel inside
 Update both frame and depth buffer

18
WHY IS Z-BUFFERING SO POPULAR ?
Advantage
 Simple to implement in hardware.
 Memory for z-buffer is now not expensive
 Diversity of primitives – not just polygons.
 Unlimited scene complexity
 Don’t need to calculate object-object intersections.

Disadvantage
 Extra memory
 May have to use point sampling

19
Z-BUFFER PERFORMANCE
 Brute-force image-space algorithm scores best for
complex scenes – easy to implement and is very
general.
 Storage overhead: O(1)

 Time to resolve visibility to screen precision: O(n)


 n: number of polygons

20
PORTAL CULLING (OBJECT-SPACE)
D F

C B E
Model scene as a graph:
• Nodes: Cells (or rooms) A
G

• Edges: Portals (or doors)

Graph gives us:


• Potentially visible set
A
1.Render the room
B
2.If portal to the next room is visible, render
the connected room in the portal region C D E
3.Repeat the process along the scene graph
2119/10/2007

You might also like