Visible-urface Detection IV60 omputer graphics set : Hidden urfaces Problem: Given a scene and a projection, what can we see? Jack van Wijk TU/e Visible-urface Detection Terminology: Visible-surface detection vs. hidden-surface removal Hidden-line removal vs. hidden-surface removal Many algorithms: omplexity scene Type of objects Hardware Visible-urface 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 Object space Image space H&B 6-:50 Visible-urface Detection 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 H&B 6-:50 Visible-urface Detection 5 Four algorithms: Back-face elimination Depth-buffer Depth-sorting Ray-casting But there are many other. H&B 6
Back-face elimination We cannot see the back-face of solid objects: Hence, these can be ignored Back-face elimination We cannot see the back-face of solid objects: Hence, these can be ignored N V V N > 0 : back face V V N < 0 :front face N H&B 6-:50-505 H&B 6-:50-505 Back-face elimination Object-space method Works fine for convex polyhedra: ±50% removed oncave or overlapping polyhedra: require additional processing Interior of objects can not be viewed Partiallisible front faces Depth-Buffer Algorithm Image-space method Aka z-buffer algorithm Normalized view volume Algorithm: Draw polygons, Remember the color most in front. H&B 6-:50-505 front = visible pixel View plane H&B 6-:505-508 Depth-Buffer Algorithm var zbuf: array[n,n] of real; { z-buffer: 0=near, =far } fbuf: array[n,n] of color; { frame-buffer } For all <= i, j <=N do zbuf[i,j] :=.0; col[i,j] := Backgroundolour; For all polygons do { scan conversion } For all covered pixels (i,j) do alculate depth z; If z < zbuf[i,j] then { closer! } zbuf[i,j] := z; fbuf[i,j] := surfacecolor(i,j); orting H&B 6-:505-508 Depth-Buffer Algorithm Fast calculation z: use coherence. polygon Plane : Ax + By + z + D = 0 scan line Ax By D Hence : z( x, y) = y A( x + ) By D Also : z( x +, y) = x x+ A Thus : z( x +, y) = z( x, y) B Also: z ( x, y) = z( x, y ) + H&B 6-:505-508
Depth-Buffer Algorithm + Easy to implement + Hardware supported + Polygons can be processed in arbitrary order + Fast: ~ #polygons, #covered pixels - osts memory - olor calculation sometimes done multiple times - Transparancy is tricky H&B 6-:505-508 Depth-orting Algorithm Image and Object space Aka Painter s algorithm. ort surfaces for depth. Draw them back to front Depth-orting Algorithm implistic version sorting: ort polygons for (average/frontal) z-value Depth-orting Algorithm A polygon can be drawn if all remaining polygons satisfy one of the following tests:!?!?!?!?. No overlap of bounding rectangles of and. is completely behind plane of. is completely in front of plane of. Projections and do not overlap Depth-orting Algorithm. No overlap of bounding rectangles of and Depth-orting Algorithm 5. is completely behind plane of ubstitute all vertices of in plane equation, and test if the result is always negative.
Depth-orting Algorithm 6. is completely in front of plane of ubstitute all vertices of in plane equation of, and test if the result is always positive Depth-orting Algorithm 7. Projections and do not overlap Depth-orting Algorithm 8 If all tests fail: wap and, and restart with. Depth-orting Algorithm 9 Problems: circularity and intersections olution: ut up polygons. Depth-orting Algorithm 0 - Tricky to implement - Polygons have to be known from the start - low: ~ #polygons Ray-casting Algorithm Image-space method Related to depth-buffer, order is different Normalized view volume + Fine for certain types of objects, such as plots of z=f(x, y) or non-intersecting spheres + Produces exact boundaries polygons 0.5 0-0.5-0 0 z front = visible pixel View plane Algorithm: Per pixel: - alculate intersection points - Determine front one H&B 6-0:58-59
Ray-casting Algorithm Var fbuf: array[n,n] of colour; { frame-buffer } n : integer; { #intersections } z : array[maxintsec] of real; { intersections } p : array[maxintsec] of object; { corresp. objects } For all <= i, j <=N do { for alle pixels } For all objects do alculate intersections and add these to z and p, keeping z and p sorted; if n > then fbuf[i,j] := surfacecolor(p[], z[]); H&B 6-0:58-59 Ray-casting Algorithm Acceleration intersection calculations: Use (hierarchical) bounding boxes z H&B 6-0:58-59 Ray-casting algorithm + 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 - loooow: ~ #objects*pixels, little coherence + pecial case of ray-tracing H&B 6-0:58-59 omparison 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: imple scene, few objects: depth-sort Quadratic surfaces: ray-casting Otherwise: depth-buffer Many additional methods to boost performance (kdtrees, scene decomposition, etc.) H&B 6-:59 OpenGL backface removal glenable(gl_ull_fae); // Turn culling on glullface(mode); // pecify what to cull mode = GL_FRONT or GL_BAK // GL_BAK is default W: front Orientation matters! If you want to change the default: glfrontface(vertexorder); // Order of vertices vertexorder = GL_W or // lockwise GL_W; // ounterclockwise (default) W: back OpenGL depth-buffer functions glenable(gl_depth_tet); // Turn testing on gllear(gl_depth_buffer_bit); // lear depth-buffer, // typically once per frame gldepthfunc(condition); // hange test used condition: GL_LE // loser: visible (default) GL_GREATER // Farther: visible Note: range between z near and z far is mapped to [0,], using one or two bytes precision. If z far has an unnecessarily high value, you loose precision, and artifacts can appear. H&B 6-:5-55 H&B 6-:5-55 5
Next We know how to determine what is visible, and we looked at illumination and shading. Next: Let s consider more advanced shading. 6