0% found this document useful (0 votes)
505 views29 pages

Computer Graphics Hidden Surfaces

This document discusses algorithms for visible surface detection in 3D computer graphics. It begins by introducing the problem of determining what surfaces are visible given a 3D scene and projection. It then defines key terms and notes there are many algorithms that vary based on scene complexity, object types, and hardware. The two main types of algorithms are object-space, which determines visible parts of objects, and image-space, which determines visibility on a per-pixel basis. Four common algorithms are then described in more detail: back-face elimination, depth buffering, depth sorting, and ray casting. The document concludes by comparing the algorithms and noting choices depend on scene complexity, object types, and available hardware.

Uploaded by

dsathiya
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)
505 views29 pages

Computer Graphics Hidden Surfaces

This document discusses algorithms for visible surface detection in 3D computer graphics. It begins by introducing the problem of determining what surfaces are visible given a 3D scene and projection. It then defines key terms and notes there are many algorithms that vary based on scene complexity, object types, and hardware. The two main types of algorithms are object-space, which determines visible parts of objects, and image-space, which determines visibility on a per-pixel basis. Four common algorithms are then described in more detail: back-face elimination, depth buffering, depth sorting, and ray casting. The document concludes by comparing the algorithms and noting choices depend on scene complexity, object types, and available hardware.

Uploaded by

dsathiya
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/ 29

Computer graphics

Hidden Surfaces
Visible-Surface Detection 1
Problem:
Given a scene and a projection,
what can we see?
Visible-Surface Detection 2
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 3
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

Object space Image space


Visible-Surface Detection 4
Visible-surface detection = sort for depth
• what and in what order varies
Performance: use coherence
• Objects
• Position in world space
• Position in image space
• Time
Visible-Surface Detection 5
Four algorithms:
• Back-face elimination
• Depth-buffer
• Depth-sorting
• Ray-casting
But there are many other.
Back-face elimination 1
We cannot see the back-face of solid objects:
Hence, these can be ignored

V  N  0 : back face
N V

H&B 16-2:504-505
Back-face elimination 2
We cannot see the back-face of solid objects:
Hence, these can be ignored

V  N  0 : front face
V

N
Back-face elimination 3
• 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
Depth-Buffer Algorithm 1
• Image-space method
• Aka z-buffer algorithm
Normalized view volume

Algorithm:
Draw polygons,
yv
Remember the
xv
color most in front.
zv
front =
visible pixel View plane
Depth-Buffer Algorithm 3
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 4
+ 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-Sorting Algorithm 1
• Image and Object space
• Aka Painter’s algorithm

1. Sort surfaces for depth


2. Draw them back to front
Depth-Sorting Algorithm 2
Simplistic version sorting:
• Sort polygons for (average/frontal) z-value

4 4?
3!
3 3?
4!
2 2?
1!
1 1?
2!
xv xv
display display
zv zv
Depth-Sorting Algorithm 3
A polygon S can be drawn if all remaining polygons S’
satisfy one of the following tests:

1. No overlap of bounding rectangles of S and S’


2. S is completely behind plane of S’
3. S’ is completely in front of plane of S
4. Projections S and S’ do not overlap
Depth-Sorting Algorithm 4
1. No overlap of bounding rectangles of S and S’

yv S
S
S’
S’
xv xv

display
zv
Depth-Sorting Algorithm 5
2. S is completely behind plane of S’
Substitute all vertices of S in plane equation S’, and
test if the result is always negative.

yv S
S
S’
S’
xv xv

display
zv
Depth-Sorting Algorithm 6
3. S’ is completely in front of plane of S
Substitute all vertices of S’ in plane equation of S, and
test if the result is always positive

yv S
S
S’
S’
xv xv

display
zv
Depth-Sorting Algorithm 7
4. Projections S and S’ do not overlap

yv S

S’
S
S’
xv xv

display
zv
Depth-Sorting Algorithm 8
If all tests fail: Swap S and S’,
and restart with S’.

S’
S S’’
xv

display
zv
Depth-Sorting Algorithm 9
Problems: circularity and intersections
Solution: Cut up polygons.

yv yv

xv xv
Depth-Sorting Algorithm 10
- Tricky to implement
- Polygons have to be known from the start
- Slow: ~ #polygons2
1
0.5
3
0
-0.5
2
-1
0

1 1

+ Fine for certain types of objects, 2

3
0

such as plots of z=f(x, y) or


non-intersecting spheres
+ Produces exact boundaries polygons
Ray-casting Algorithm 1
• Image-space method
• Related to depth-buffer, order is different
Normalized view volume

Algorithm:
z Per pixel:
yv
- Calculate
xv
intersection points
- Determine front one
zv
front =
visible pixel View plane
Ray-casting Algorithm 3
Acceleration intersection calculations:
Use (hierarchical) bounding boxes

z
yv
xv

zv
Ray-casting algorithm 4
+ Relatively easy to implement
+ For some objects very suitable (for instance
spheres and other quadratic surfaces)
+ Transparency can be dealt with easily

- Objects must be known in advance


- Sloooow: ~ #objects*pixels, little coherence
+ Special case of ray-tracing
Comparison
• Hardware available? Use depth-buffer, possibly in
combination with back-face elimination or depth-sort for
part of scene.
• If not, choose dependent on complexity scene and type
of objects:
– Simple scene, few objects: depth-sort
– Quadratic surfaces: ray-casting
– Otherwise: depth-buffer
• Many additional methods to boost performance (kD-
trees, scene decomposition, etc.)
OpenGL backface removal
glEnable(GL_CULL_FACE); // Turn culling on
glCullFace(mode); // Specify what to cull
mode = GL_FRONT or GL_BACK // GL_BACK is default
3 2
2 3
CCW: CW:
front back
4 1 1 4

Orientation matters! If you want to change the default:


glFrontFace(vertexOrder); // Order of vertices
vertexOrder = GL_CW or // Clockwise
GL_CCW; // Counterclockwise (default)

H&B 16-11:523-525
OpenGL depth-buffer functions
glEnable(GL_DEPTH_TEST); // Turn testing on
glClear(GL_DEPTH_BUFFER_BIT); // Clear depth-buffer,
// typically once per frame
glDepthFunc(condition); // Change test used
condition: GL_LESS // Closer: visible (default)
GL_GREATER // Farther: visible

Note: range between znear and zfar is mapped to [0,1], using one or
two bytes precision. If zfar has an unnecessarily high value,
you loose precision, and artifacts can appear.
Next…
• We know how to determine what is visible,
and we looked at illumination and shading.
• Next: Let’s consider more advanced shading.

You might also like