Mod 1 - 3 CG Hidden Lines
Mod 1 - 3 CG Hidden Lines
Computer graphics
Hidden Lines/Surfaces
Visible-Surface Detection
Problem:
Given a scene and a projection,
what can we see?
Hidden line/surface removal
Wire frame Hidden line removal
2. Here surface visibility is determined. 2. Here line visibility or point visibility is determined.
3. It is performed at the precision with which each object is 3. It is performed using the resolution of the display device.
defined, No resolution is considered.
4. Calculations are not based on the resolution of the display 4. Calculations are resolution base, so the change is difficult
so change of object can be easily adjusted. to adjust.
5. These were developed for vector graphics system. 5. These are developed for raster devices.
10. If the number of objects in the scene increases, 10. In this method complexity increase with the complexity
computation time also increases. of visible parts.
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
11
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
16
Z-Buffering
Z-Buffer Algorithm
▪ It is also called a Depth Buffer Algorithm.
▪ Depth buffer algorithm is simplest image space
algorithm.
▪ For each pixel on the display screen, we keep a
record of the depth of an object within the pixel
that lies closest to the observer.
▪ In addition to depth, we also record the intensity
that should be displayed to show the object.
Depth buffer is an extension of the frame buffer.
Depth buffer algorithm requires 2 arrays,
intensity and depth each of which is indexed by
pixel coordinates (x, y).
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 }