
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















Computer Graphics Hidden Surface Removal
n Drawing polygonal faces on screen consumes CPU cycles n We cannot see every surface in scene n To save time, draw only surfaces we see n Surfaces we cannot see and their elimination methods: n Occluded surfaces: hidden surface removal (visibility) n Back faces: back face culling n Faces outside view volume: viewing frustrum culling n Definitions: n Object space techniques: applied before vertices are mapped to pixels n Image space techniques: applied after vertices have been rasterized
n Goal: determine which objects are visible to the eye
n Determine what colors to use to paint the pixels
n Active research subject - lots of algorithms have been proposed in the past (and is still a hot topic)
n Where is visiblity performed in the graphics pipeline?
modeling and viewing
v1, m
v2, m2 v3, m
per vertex lighting projection
interpolate clipping vertex colors
viewport mapping
Rasterization texturing Shading visibility Display
Note: Map (x,y) values to screen (draw) and use z value for depth testing
n Method used in most of graphics hardware (and thus OpenGL): Z-buffer (or depth buffer) algorithm
n Requires lots of memory
n Recall: after projection transformation, in viewport transformation n x,y used to draw screen image, mapped to viewport n z component is mapped to pseudo-depth with range [0,1]
n Objects/polygons are made up of vertices
n Hence, we know depth z at polygon vertices
n Point on object seen through pixel may be between vertices
n Need to interpolate to find z
n Basic Z-buffer idea:
n rasterize every input polygon n For every pixel in the polygon interior, calculate its corresponding z value (by interpolation) n Track depth values of closest polygon (smallest z) so far n Paint the pixel with the color of the polygon whose z value is the closest to the eye.
For each polygon {
for each pixel (x,y) inside the polygon projection area {
if (z_polygon_pixel(x,y) < depth_buffer(x,y) ) {
depth_buffer(x,y) = z_polygon_pixel(x,y);
color_buffer(x,y) = polygon color at (x,y) } } }
Note: know depths at vertices. Interpolate for interior z_polygon_pixel(x, y) depths
eye
Z = 0.
Z = 0.
Top View
Correct Final image
Step 2: Draw the blue polygon (assuming the OpenGL program draws blue polyon first โ the order does not affect the final result any way).
eye
Z = 0.
Z = 0. 1.0 1.0 1.0 1. 1.0 1.0 1.0 1.
0.5 0.5 1.0 1. 0.5 0.5 1.0 1.
Step 3: Draw the yellow polygon
eye
Z = 0.
Z = 0.
z-buffer drawback: wastes resources by rendering a face and then drawing over it
n Recall that we chose parameters a and b to map z from range [near, far] to pseudodepth range[0,1] n This mapping is almost linear close to eye n Non-linear further from eye, approaches asymptote n Also limited number of bits n Thus, two z values close to far plane may map to same pseudodepth: Errors!!
Actual z
-Pz
1
N
F
F N
โ
F N
โ
n Primarily three commands to do HSR
n glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB) instructs openGL to create depth buffer
n glEnable(GL_DEPTH_TEST) enables depth testing
n glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) initializes the depth buffer every time we draw a new picture
n If we find backface, do not draw, save rendering resources n There must be other forward face(s) closer to eye n F is face of object we want to test if backface n P is a point on F n Form view vector, V as (eye โ P) n N is normal to face F
Backface test: F is backface if N.V < 0 why??
void Mesh::drawFrontFaces( )
{
for(int f = 0;f < numFaces; f++) { if(isBackFace(f, โฆ.) continue; glBegin(GL_POLYGON); { int in = face[f].vert[v].normIndex; int iv = face[v].vert[v].vertIndex; glNormal3f(norm[in].x, norm[in].y, norm[in].z; glVertex3f(pt[iv].x, pt[iv].y, pt[iv].z); glEnd( );
} Ref: case study 7.5, pg 406, Hill