Professional Documents
Culture Documents
Lect5 1
Lect5 1
Inf4/MSc
Computer Graphics
Lecture 5
Hidden Surface Removal and Rasterization
Taku Komura
1
Computer Graphics
Inf4/MSc
2
Computer Graphics Visibility (hidden surface
Inf4/MSc
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)
3
– wrong visibility correct visibility
Computer Graphics
Inf4/MSc
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
Computer Graphics
Inf4/MSc
5
Computer Graphics
Inf4/MSc
–
Or if N.V > 0 we are viewing the
back face so polygon is obscured.
6
Computer Graphics
Inf4/MSc
7
Computer Graphics
Inf4/MSc
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).
•Recursively divide each side until each node View of scene from above
contains only 1 polygon.
Computer Graphics
Inf4/MSc
BSP Tree. 5
5a
5b
2
•Choose polygon arbitrarily
3
•Divide scene into front (relative to 1 4
normal) and back half-spaces.
Lecture 9 19/10/20079
Computer Graphics
BSP Tree.
Inf4/MSc
5a
2 5b
•Choose polygon arbitrarily
BSP Tree.
Inf4/MSc
5
5a
2 5b
•Choose polygon arbitrarily
3
•Divide scene into front (relative to 1 4
normal) and back half-spaces.
Lecture 9 19/10/2007
13
Computer Graphics
Inf4/MSc
BSP performance measure
• Tree construction and traversal (object-space
ordering algorithm – good for relatively few static
primitives, precise)
• Overdraw: maximum
• Front-to-back traversal is more efficient
• Record which region has been filled in already
• Terminate when all regions of the screen is filled
in
• S. Chen and D. Gordon. “Front-to-Back Display of BSP Trees.” IEEE
Computer Graphics & Algorithms, pp 79–85. September 1991.
Lecture 9 19/10/2007
14
Computer Graphics
Inf4/MSc
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.
15
Computer Graphics
Inf4/MSc
16
Computer Graphics
Inf4/MSc
17
Computer Graphics
Inf4/MSc
18
Computer Graphics
Inf4/MSc
19
Computer Graphics
Inf4/MSc
Implementation.
• Initialise frame buffer to background
colour.
• Initialise depth buffer to z = max. value for
far clipping plane
• For each triangle
– Calculate value for z for each pixel inside
– Update both frame and depth buffer
20
Computer Graphics
Inf4/MSc
Filling in Triangles
• Scan line algorithm
– Filling in the triangle by drawing horizontal
lines from top to bottom
• Barycentric coordinates
– Checking whether a pixel is inside / outside the
triangle
Computer Graphics
Inf4/MSc
Triangle Rasterization
• Consider a 2D triangle with vertices p0 , p1 , p2.
• Let p be any point in the plane. We can always
find a, b, c such that
22
Computer Graphics
Inf4/MSc
Computing the baricentric
coordinates of the interior pixels
• The triangle is composed of 3 points p0 (x0,y0), p1 (x1, y1), p2(x2,y2)
24
Computer Graphics
Inf4/MSc
Scanning inside the triangle
• Once we've identified the bounding box,
we loop over each pixel in the box.
• For each pixel, we first compute the
corresponding (x, y) coordinates in the
canonical view volume
• Next we convert these into barycentric
coordinates for the triangle being drawn.
• Only if the barycentric coordinates
are within the range of [0,1], we
plot it (and compute the depth)
25
Computer Graphics
Inf4/MSc
26
Computer Graphics
Inf4/MSc
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
27
Computer Graphics
Inf4/MSc
Ex. Architectural scenes
Here there can be an enormous amount of occlusion
Lecture 9 19/10/2007
28
Computer Graphics
Inf4/MSc
Occlusion at various levels
Lecture 9 19/10/2007
29
Computer Graphics
Inf4/MSc
Portal Culling (object-space)
D F
C B E
Model scene as a graph:
• Nodes: Cells (or rooms) G
A
• Edges: Portals (or doors)