Visible Surface Detection
Visible Surface Detection
Object space methods
Image space methods
Back-Face Detection
yv (x,y,z) is behind the polygon if
xv Ax+By+Cz<0
N=(A,B,C)
zv or
Vview
A polygon is a backface if
Vview . N >0
if Vview is parallel to zv axis:
if C<0 then backface
if C=0 then polygon cannot
be seen
Depth-Buffer Method (z-Buffer)
Compares depths of the
yv
surfaces and uses the color
xv
(x,y) of the closest one to the view
zv plane
view plane
Depth buffer – depth values of
surfaces for (x,y)
0 ≤ depth ≤ 1
Object space method Frame buffer (refresh buffer) –
color value for (x,y)
Depth-Buffer Method (z-Buffer)
1. depthbuffer(x,y) = 1.0
framebuffer(x,y) = background color
2. Process each polygon one at a time
2.1. For each projected (x,y) pixel position of a polygon,
calculate depth z.
2.2. If z < depthbuffer(x,y)
compute surface color,
set depthbuffer(x,y) = z,
framebuffer(x,y) = surfacecolor(x,y)
Depth-Buffer Method (z-Buffer)
Calculating Depth:
At (x,y): Ax+By+Cz+D=0
z=(-Ax-By-D)/C
For (x+1, y): z’ = z-(A/C)
For x’=x-1/m, y’=y-1:
z’= z+(A/m+B)/C
A-Buffer Method
Depth: a real number
≥0 : single surface
<0 : multiple surfaces
Surface info: surface data or pointer
opaque transparent
Surface data:
RGB intensity
opacity
Linked list:
depth
depth surface info percent of area coverage
surface identifier
etc.
Scan-Line Method
yv
For each scan-line, examine all
polygon surface projections
intersecting that scan line to
determine which are visible. Then
enter the surface color of that
position in the frame buffer.
xv Edge table:
• coordinate endpoints of each line
• inverse slope of each line
• pointers to surface table
Image space method Surface table:
• plane coefficients (A,B,C)
• surface material properties
• pointers to edge table
Scan-Line Method
Algorithm:
yv
1 1. Form an active edge list that contains
only the edges that cross the current
2 scan line, sorted in order of increasing x.
3
2. Define a flag for each surface to indicate
xv whether a position along a scan line is
inside or outside the surface.
3. Process pixel positions across each scan
line from left to right. Locate visible
positions of surfaces along the scan line.
Scan-Line Method
Divide surfaces to eliminate the
overlap.
Visible Line Detection
(Wireframe visibility)
If the projected edge endpoints of a line segment are both
within the projected area of a surface, compare the
depth of the endpoints to the surface depth at those
(x,y) positions.
If both endpoints are behind the surface => hidden edge
If both endpoints are in front of the surface => visible edge
Otherwise calculate the intersections and the depth value
of the intersection point.
• If for both intersection points, edge has greater depth
than the surface => part of the edge is behind the
surface
• If one edge endpoint has greater depth and the other
has less depth than the surface => edge penetrates
the surface
Then, calculate the penetration point
Depth Cueing
fdepth(d) is multiplied by each pixel’s color
fdepth(d) = (dmax-d)/(dmax-dmin)
d: distance of a point from the viewing position
dmin: 0.0
dmax: 1.0
OpenGL
glPolygonMode(GL_FRONT_AND BACK, GL_LINE)
• displays both visible and hidden edges
glEnable (GL_FOG)
glFogi (GL_FOG_MODE, GL_LINEAR)
• generates fog effect. Uses depth cueing.
glEnable (GL_CULL_FACE)
glDisable (GL_CULL_FACE)
glCullFace (mode)
• used for backface removal
• GL_BACK (default), GL_FRONT (if inside a building),
GL_FRONT_AND_BACK
OpenGL
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH)
• initializes GLUT, requests a depth buffer and a frame buffer
glClear (GL_DEPTH_BUFFER_BIT)
• initially depth buffer has the background color. It must be cleared every time
before displaying a new frame.
glEnable (GL_DEPTH_TEST)
glDisable (GL_DEPTH_TEST)
• to activate depth buffer routines
glClearDepth (maxDept)
• to set maxDepth to another value (0.0 – 1.0)
glDepthRange (nearNormDept, farNormDept)
• to adjust normalization values (defaults: near- 0.0, far- 1.0)
OpenGL
glDepthFunction (testCondition)
• to specify a test condition for depth-buffer routines
• GL_LESS (default), GL_GREATER, GL_EQUAL,
GL_NOTEQUAL, GL_LEQUAL, GL_GEQUAL, GL_NEVER,
GL_ALWAYS
glDepthMask (writeStatus)
• to set the status of depth-buffer routines
• TRUE: read/write
• FALSE: read only