0% found this document useful (0 votes)
5 views43 pages

10 SurfaceDetection En

The document discusses visible surface detection techniques in computer graphics, focusing on back face culling, depth-buffer methods, and the A-buffer method. It explains the importance of determining visible surfaces to enhance rendering efficiency and accuracy, detailing various algorithms and their applications. Additionally, it highlights challenges such as Z-fighting and limitations of certain methods like the scan-line approach.

Uploaded by

Shruti Tripathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views43 pages

10 SurfaceDetection En

The document discusses visible surface detection techniques in computer graphics, focusing on back face culling, depth-buffer methods, and the A-buffer method. It explains the importance of determining visible surfaces to enhance rendering efficiency and accuracy, detailing various algorithms and their applications. Additionally, it highlights challenges such as Z-fighting and limitations of certain methods like the scan-line approach.

Uploaded by

Shruti Tripathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

CG apes from Dawn of the Planet of the Apes, 2014

Computer Graphics
Διαγραφή Πίσω Επιφανειών και Απόκρυψη

Andreas Aristidou
[email protected]
http://www.andreasaristidou.com
Review: Rendering Pipeline
▪ We almost completed the rendering pipeline:
▪ Modeling transformations
▪ Viewing transformations
▪ Projection transformations
▪ Clipping
▪ Scan conversion
▪ Now we know everything about how to draw a
polygon on the screen, except for determining
the non-visible subjects, or else visible surface
detection.

EPL426 | Computer Graphics


Visible Surface Determination and Back Face Culling
▪ Specifies the part of each object that is visible in the final image
▪ Why are back face culling algorithms needed?
▪ Avoid creating incorrect images
▪ Speed up the creation of images
▪ We must determine what is visible within a scene from a chosen viewing position
▪ For 3D worlds this is known as visible surface detection or hidden surface elimination

To render or not to render, that is the question…


EPL426 | Computer Graphics
Contents
▪ Today we will deal with visible surface detection techniques:
▪ Why Surface Detection;
▪ Detect the back of the object
▪ Depth-buffer Method
▪ A-buffer Method
▪ Scan-line Method

EPL426 | Computer Graphics


Invisible entities
▪ When would a polygon be invisible?
▪ Polygons that are outside the field of view
▪ If from the polygon we see its back (backfacing)
▪ If the polygon is hidden from another that is closer to the viewpoint
▪ As you can imagine, for performance reasons we do not want to deal with
polygons that are invisible (outside field of view or backfacing)
▪ For rendering and proper visualization, we need to know if a polygon is hidden
from another object.

EPL426 | Computer Graphics


Visible Surface Detection
There are many algorithms and techniques that have been developed from time
to time to solve visible surface detection
▪ Some methods require more processing time.
▪ Some methods require more memory.
▪ Others can only be applied to specific data types

EPL426 | Computer Graphics


Two Main Approaches
▪ Visible surface detection algorithms are broadly classified as:
▪ Object Space Methods: Compares objects and parts of objects to each other within
the scene definition to determine which surfaces are visible
▪ Image Space Methods: Visibility is decided point-by-point at each pixel position on
the projection plane
▪ Image space methods are by far the more common

EPL426 | Computer Graphics


Back-Face Detection
▪ We assume that our objects are solid
▪ Each polygon has "back and forth", depending on the order of its edges
▪ The simplest thing we can do is to find the faces on the back of the polyhedron
and discard them
▪ Polygons whose slash does not look towards the camera are not rendered

Pi

EPL426 | Computer Graphics


Back-Face Detection
▪ We know from before that a point (x, y, z) is behind a polygon surface if:

Ax + By + Cz + D  0
▪ where A, B, C & D are the plane parameters for the surface
▪ This can actually be made even easier if we organise things to suit ourselves

EPL426 | Computer Graphics


Back-Face Detection
▪ Ensure we have a right handed system with the viewing direction along the
negative z-axis
▪ Now we can simply say that if the z component of the polygon’s normal is less
than zero the surface cannot be seen

EPL426 | Computer Graphics


Back-Face Detection
▪ We can simplify this method if we assume that the vertical vector N on the
surface of the polygon has the Cartesian values (A,B,C).

▪ If V is a vector in the direction of projection, then the polygon is a back surface


and it is not visible if V●N > 0.

EPL426 | Computer Graphics


Back-Face Detection
▪ In general back-face detection can be expected to eliminate about half of the
polygon surfaces in a scene from further visibility tests
▪ More complicated surfaces though scupper us!
▪ We need better techniques to handle these kind of situations

EPL426 | Computer Graphics


Back-Face Detection
▪ On the surface of polygons whose vertical vectors point away from the camera
are always invisible:

Note: backface detection


alone doesn’t solve the
hidden-surface problem!

EPL426 | Computer Graphics


Backface culling assumes objects are closed
No Backface culling With Backface culling

https://en.wikipedia.org/wiki/Back-face_culling

A triangle facing away from you is only guaranteed to be invisible if there’s something else in front of.
This is only guaranteed for closed, solid objects (e.g. a sphere)
Objects with ‘holes’ may expose back-facing triangles to the viewer; backface culling results in errors
(see skulls on right)
EPL426 | Computer Graphics
Back-Face Detection
▪ Most objects on stage are usually "solid" and non-transparent!
▪ What happens if it's not?

EPL426 | Computer Graphics


Depth-Buffer Methods
▪ Compares surface depth values throughout a scene for each pixel position on
the projection plane
▪ Usually applied to scenes only containing polygons
▪ As depth values can be computed easily, this tends to be very fast
▪ Also often called the z-buffer method

EPL426 | Computer Graphics


Depth-Buffer Methods

• Each surface is processed separately, one


point at a time along the surface
• The S1 surface is closer to the projection
plane, so (x,y) displays the value of the
object S1.

EPL426 | Computer Graphics


Depth-Buffer Algorithm
1. Initialise the depth buffer and frame buffer so that for all buffer positions (x, y)
depthBuff(x, y) = 1.0
frameBuff(x, y) = bgColour

EPL426 | Computer Graphics


Depth-Buffer Algorithm
2. Process each polygon in a scene, one at a time
▪ For each projected (x, y) pixel position of a polygon, calculate the depth z (if
not already known)
▪ If z < depthBuff(x, y), compute the surface colour at that position and set
depthBuff(x, y) = z
frameBuff(x, y) = surfColour(x, y)

After all surfaces are processed depthBuff and frameBuff will store correct values

EPL426 | Computer Graphics


Depth-Buffer Algorithm
void zBuffer() {
int x, y;
for (y = 0; y < YMAX; y++)
for (x = 0; x < XMAX; x++) {
WritePixel (x, y, BACKGROUND_VALUE);
WriteZ (x, y, 1);
}
for each polygon {
for each pixel in polygon’s projection {
//plane equation
double pz = Z-value at pixel (x, y);
if (pz <= ReadZ (x, y)) {
// New point is closer to front of view
WritePixel (x, y, color at pixel (x, y))
WriteZ (x, y, pz);
}
}
}
}
EPL426 | Computer Graphics
Depth-Buffer Algorithm

255 255 255 255 255 255 255 255 64 64 64 64 64 64 64 64 64 64 64 64 64 64 255

255 255 255 255 255 255 255 255 64 64 64 64 64 64 64 64 64 64 64 64 255 255

255 255 255 255 255 255 255 255 64 64 64 64 64 64 64 64 64 64 255 255 255

255 255 255 255 255 255 255 255 64 64 64 64 64 64 64 64 255 255 255 255

255 255 255 255 255 255 255 255 + 64 64 64


= 64 64 64 255 255 255 255 255

255 255 255 255 255 255 255 255 64 64 64 64 255 255 255 255 255 255

255 255 255 255 255 255 255 255 64 64 255 255 255 255 255 255 255

255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255

64 64 64 64 64 64 64 255 integer Z-buffer with 64 64 64 64 64 64 64 255

64

64
64

64
64

64
64

64
64

64
64

255
255

255
255

255
near = 0, far = 255 64

64
64

64
64

64
64

64
64

64
64

255
255

255
255

255

64 64 64 64 255 255 255 255 127 64 64 64 64 255 255 255 255

64 64 64 255 255 255 255 255 + 127 127


= 64 64 64 255 255 255 255 255

64 64 255 255 255 255 255 255 127 127 127 64 64 127 255 255 255 255 255

64 255 255 255 255 255 255 255 127 127 127 127 64 127 127 127 255 255 255 255

255 255 255 255 255 255 255 255 127 127 127 127 127 127 127 127 127 127 255 255 255

EPL426 | Computer Graphics


Iterative Calculations
▪ The depth-buffer algorithm proceeds by starting at the top vertex of the polygon
▪ Then we recursively calculate the x-coordinate values down a left edge of the
polygon
▪ The x value for the beginning position on each scan line can be calculated from the
previous one
1
x' = x − where m is the slope
m
▪ Depth values along the edge being considered are calculated using

A +B
z' = z − m
C
EPL426 | Computer Graphics
Iterative Calculations

top scan line

y scan line

y - 1 scan line

bottom scan line

x x’

EPL426 | Computer Graphics


Z-Fighting
▪ Z-fighting occurs when two primitives have similar values in the z-buffer

Two intersecting cubes

EPL426 | Computer Graphics


A-Buffer Method
▪ The A-buffer method is an extension of the depth-buffer method
▪ The A-buffer method is visibility detection method developed at Lucasfilm
Studios for the rendering system REYES (Renders Everything You Ever Saw)

EPL426 | Computer Graphics


A-Buffer Method
▪ The A-buffer expands on the depth buffer method to allow transparencies
▪ The key data structure in the A-buffer is the accumulation buffer

EPL426 | Computer Graphics


A-Buffer Method
▪ If depth is >= 0, then the surface data field stores the depth of that pixel
position as before
▪ If depth < 0 then the data filed stores a pointer to a linked list of surface data

EPL426 | Computer Graphics


A-Buffer Method
▪ Surface information in the A-buffer includes:
▪ RGB intensity components
▪ Opacity parameter
▪ Depth
▪ Percent of area coverage
▪ Surface identifier
▪ Other surface rendering parameters
▪ The algorithm proceeds just like the depth buffer algorithm
▪ The depth and opacity values are used to determine the final colour of a pixel

EPL426 | Computer Graphics


Painter’s Algorithm

Deadpool © Twentieth Century Fox, Marvel Entertainment

EPL426 | Computer Graphics


Scan-Line Method
▪ An image space method for identifying visible surfaces
▪ Computes and compares depth values along the various scan-lines for a scene

EPL426 | Computer Graphics


Depth-Sorting Method (Painter’s Algorithm)

z z
zmax zmax

S S
z’max
zmin S’
z’max zmin
S’

z’min z’min

x x
No Depth Overlap Depth Overlap

EPL426 | Computer Graphics


Visibility (Priority) Ordering
▪ You would draw the P1 after P2 to see the correct result (Painters Algorithm)

◼ Given a set of S polygons and a viewpoint C, find a series of {P1…Pn} at S such that
any Pi polygon does not hide any of the polygons {Pi+1…Pn}.
◼ Another way to think about it: for every 2 polygons intersected by a ray through the C,
Pi ; has a higher priority than Pj, (with i < j)

P2

C P1
t2
t1

EPL426 | Computer Graphics


Depth-Sorting Algorithm (Painter’s Algorithm)
▪ Simple approach: Deliver the polygons from back to front, "painting above"
from the previous polygons:

EPL426 | Computer Graphics


Depth-Sorting Algorithm (Painter’s Algorithm)

EPL426 | Computer Graphics


Depth-Sorting Algorithm (Painter’s Algorithm)

EPL426 | Computer Graphics


Principle of the painter's algorithm
▪ Sort objects (or polygons) from the back to the front
▪ To get the final picture: we draw them in this order which allows the last (nearest) to be painted above
(overwrite) the previous ones (further away)

P4
P2
P3
C
P5 P1

▪ It is a hybrid approach as the first step, the sorting, is in the object space and the second in
the image space
▪ The hardest part is sorting

EPL426 | Computer Graphics


Z-sort at Projection Space
▪ Simple back-to-front sorting of all polygons based on their center

P4
P2
P3
C
P5 P1

EPL426 | Computer Graphics


Z-sort at Projection Space
▪ It doesn't always work, e.g.

EPL426 | Computer Graphics


Scan-Line Method Limitations
▪ The scan-line method runs into trouble when surfaces cut through each other
or otherwise cyclically overlap
▪ Such surfaces need to be divided

EPL426 | Computer Graphics


Scan-Line Method Limitations
▪ The Intersecting polygons also present a problem
▪ Even non-intersecting polygons can form a circle without a valid order of
visibility:

EPL426 | Computer Graphics


Analytic Visibility Algorithms
▪ Early visibility algorithms calculate the set of visible parts of the polygon
directly, and then present the individual segments on a monitor:

EPL426 | Computer Graphics


Analytic Visibility Algorithms
▪ What is the minimum worst-case cost of computing the fragments for a scene
composed of n polygons?

▪ Answer:
O(n2)

EPL426 | Computer Graphics


Summary
▪ We need to make sure that we only draw visible surfaces when rendering
scenes
▪ There are a number of techniques for doing this such as
▪ Back face detection
▪ Depth-buffer method
▪ A-buffer method
▪ Scan-line method
▪ Next time we will look at some more techniques and think about which
techniques are suitable for which situations

EPL426 | Computer Graphics

You might also like