Mod 2 Lecture 3 CG Hidden Lines
Mod 2 Lecture 3 CG Hidden Lines
Lecture 3
Computer graphics
Hidden Surfaces
Visible-Surface Detection
Problem:
Given a scene and a projection,
what can we see?
Visible-Surface Detection
Terminology:
Visible-surface detection vs. hidden-surface removal
Hidden-line removal vs. hidden-surface removal
Many algorithms:
• Complexity scene
• Type of objects
• Hardware
Visible-Surface Detection
Two main types of algorithms:
Object space: Determine which part of the object
are visible
Image space: Determine per pixel which point of
an object is visible
• Image-Space Methods:
– Visibility is decided at each pixel position in the
projection plane.
e.g. Z-Buffer algorithm
Back-Face Elimination
Don’t draw surfaces facing away from viewpoint:
– Assumes objects are solid polyhedra
• Usually combined with additional methods c
– Compute polygon normal n:
• Assume counter-clockwise vertex
n
order
a
• For a triangle (a, b, c): n = (b – a) (c – a)
b
– Compute vector from viewpoint to any y
point p on polygon v:
– Facing away (don’t draw) if n and v are
pointed in opposite directions
dot product n · v > 0 x
z
8
Back Face Elimination
z
Back-face elimination
We cannot see the back-face of solid objects:
Hence, these can be ignored
V N 0 : back face
N V
Back-face elimination
We can see the front-face of solid objects:
Hence, that face is accepted
V N 0 : front face
V
N
Back-face elimination
• Object-space method
• Works fine for convex polyhedra: ±50% removed
• Concave or overlapping polyhedra: require additional
processing
• Interior of objects can not be viewed
Partially visible front faces
Back-Face Culling Example
n1·v = (2, 1, 2) · (-1, 0, -1)
= -2 – 2 = -4,
n2 = (-3, 1, -2) So n1·v < 0
n1 = (2, 1, 2)
So n1 front facing polygon
13
Z-Buffering
Z-Buffer Algorithm
• Most widely used Image-space algorithm.
• Easy to implement, both in software and
hardware. y
• Incremental computation.
(x, y)
x
z
Depth-Buffer Algorithm
• Image-space method
• Otherwise called z-buffer algorithm
Normalized view volume
Algorithm:
Draw polygons,
yv
Remember the
xv
color most in front.
zv Stores two arrays
front =
1. Z depth, z(x,y)
visible pixel View plane
2. Pixel data,I(x,y)
Depth-Buffer Algorithm
Fast calculation z: use coherence.
polygon Plane : Ax By Cz D 0
scan line Ax By D
Hence : z ( x, y )
y C
A( x 1) By D
Also : z ( x 1, y )
C
x x+1 A
Thus : z ( x 1, y ) z ( x, y )
display C
B
Also : z ( x, y ) z ( x, y 1)
C
Depth-Buffer Algorithm
+ Easy to implement
+ Hardware supported
+ Polygons can be processed in arbitrary order
+ Fast: ~ #polygons, #covered pixels
- Costs memory
- Color calculation sometimes done multiple times
- Transparancy is tricky
Depth-Buffer Algorithm
var zbuf: array[N,N] of real; { z-buffer: 0=near, 1=far }
fbuf: array[N,N] of color; { frame-buffer }