You are on page 1of 36

Hidden line and surface removal

algorithms (2)

Graphical Processing Systems - UTCN 1

Hidden line and surface removal algorithms
1. Floating horizon algorithm
2. Back-face culling
3. Area subdivision algorithm
4. Depth buffer algorithms
5. Depth sorting algorithms
6. Scan-line algorithms
7. Octree algorithm
8. Ray casting algorithms
9. BSP trees

Graphical Processing Systems - UTCN 2

Conceptual model of 3D viewing process
zL View
zwc Plane

yS Center of
xS xV Projection,
U Position


window pixel

Window definition Viewport definition Window’s content Scan conversion onto the
in projection plane in projection plane inside the viewport raster screen

Graphical Processing Systems - UTCN 3

UTCN 4 . T.  The algorithm consists of three steps: 1. Sort all polygons according to the 1 greatest (furthest) z coordinate of each 2. R.G. back to front). Depth Sorting Algorithm  Published in 1972..L. Scan convert each polygon in descending order of greatest z coordinate (i.. Proceedings of the ACM National Conference. by Newell.E. “A Solution to the Hidden Surface Problem”. Sancha..e.5. Newell. 2  Known as painter’s algorithm  paint the polygons into the frame buffer in order of decreasing distance from the 3 viewpoint. M. Graphical Processing Systems . splitting polygons if necessary 3. Resolve any ambiguities thas may cause when the polygons’ z extents overlap.

Cases of ambiguities z y x y x B x Graphical Processing Systems .UTCN 5 .

Depth sorting algorithm – 5 tests  Let us consider the polygon P at the far end of the sorted list  Before scan converting P into the frame buffer. Graphical Processing Systems . 2.UTCN 6 . 3. The Q polygon is marked to avoid the infinitely swapping.  If all 5 tests fail. and the algorithm proceeds as before. it is tested against each polygon Q whose z extent overlaps the z extent of P. The unsplit polygon is discharged.  The tests 3 and 4 are performed. The test proves P cannot obscure Q and that P can be written in the list before Q. Polygons’ x extents not overlap. Polygons’ y extents not overlap. and therefore test whether Q can be scan-converted before P. it can be assumed for the moment that P actually obscures Q. with the polygons reversed: 1) Entire Q on the opposite side of P’s plane from the viewpoint 2) Entire P on the same side of Q’s plane as the viewpoint  If the tests 3) and 4) succeed the polygon Q is moved to the end of the list and it becomes the new P. Entire P on the opposite side of Q’s plane from the viewpoint.y) plane not overlap. Entire Q on the same side of P’s plane as the viewpoint. 5.  There are 5 tests in order of increasing complexity: 1. Projections of the polygons onto the (x. and its pieces are inserted into the list in proper z order.  If the tests 3) and 4) fail again it means that either P or Q must be split by the plane of the other. 4.

UTCN 7 . Test 1 and 2 y y x x Graphical Processing Systems .

Test 3 and 4 z z P P Q Q x x Test 3: draw P.UTCN 8 . Q Viewing direction Graphical Processing Systems . Q Test 4: draw P.

Test 5 y x Graphical Processing Systems .UTCN 9 .

Q’ Than test 4 for P’ and Q’. Test 3) and 4) – swap P and Q z z Q -> P’ Q -> P’ P -> Q’ P -> Q’ x x Test 3): test 3 for P and Q fails. draw P’. Test 4): test 4 for P and Q fails. draw P’. than test 3 for P’ and Q’.UTCN 10 . Q’ Viewing direction Graphical Processing Systems .

UTCN 11 .Cycle testing and splitting If not successful in box testing and swapping. then split P P P Q Q Q P Graphical Processing Systems .

. G. PhD Thesis.6. by Watkins. D. of Utah. Romney.. C.C.. by Bouknight. Watkins (1970)  Published in 1967.S. G. G. CACM.W.  Published in 1970. by Wylie.. Erdahl. vol 13(9).C.UTCN 12 . W.. Computer Science Dept. (1967).  Published in 1970. “A Procedure for Generation of Three- Dimensional Half-Toned Computer Graphics Presentations”. “Halftone Perspective Drawings by Computer”. W.. Bouknight (1970). FJCC 67. Evans. Univ. A. Scan-Line Algorithms  Wylie et al.J..  Extension of the Ordered Edge List Algorithm (see course “Scan-Conversion(3)”)  Uses the scan line coherence and edge coherence  Works with all polygons that define an object rather than a single polygon as in the Ordered Edge List Algorithm Graphical Processing Systems . “A Real Time Visible Surface Algorithm”.

Algorithm steps 1. Create Active-Edge Table (AET) C E F B x Graphical Processing Systems . Create Edge Table (ET) D y 2. Create Polygon Table (PT) A 3.UTCN 13 .

∆x = 1/m)  AB. Polygon identification number is the polygon to which the edge belongs x ymax ∆x ID next edge Graphical Processing Systems . ∆x is the inverse slope of  EF.Create Edge Table (ET)  All no horizontal edges y D A  Horizontal edges are ignored  Edge sorted into buckets based on each edge’s smaller y coordinate C E  Within each bucket the edges are ordered by increasing x coordinate of their lower F endpoint B  Each table entry contains: x 1. x coordinate of the end with the smaller y  ET: coordinate  AC 2. ∆y = 1. DF the edge (∆y = m∆x. is the step from one scan line to the next. BC 4.UTCN 14 . y coordinate of the edge’s other end  DE 3. x increment ∆x.

Shading or color information B 3.C.e.UTCN 15 . C. Coefficients of the plane equation (i.Create Polygon Table (PT)  One entry for each polygon y D A  Each table entry contains the polygon ID  Each polygon is described by at least the following information: C E 1.B.D Shading in-out info flag Graphical Processing Systems . D) F 2. B. initialized to false x  PT:  ABC  DEF ID A. A. An in-out Boolean flag.

AC. DF c  d: AB. AC. DF  e: DE. DE.Create Active-Edge Table (AET)  Contains the edges intersected by the current scan line  Edges are ordered by the x coordinate of the intersections between the active edges and the current scan line y  AET: D e  a: AB. BC. BC d A  b: AB. EF. DE. DF  c: AB. DF C b E F a B x Graphical Processing Systems .UTCN 16 .

texture.g. left to right y D  Update in-out flags  Compute the depth order at A the intersections in-out P1: 0 1 0 0  Visible polygon in-out P2: 0 0 1 0  Graphics attributes (e. etc) E F B x Graphical Processing Systems .Scan line parsing  Pixel to pixel.UTCN 17 . 1 Pixel color. filling 1 C pattern.

on M3 the depth A calculation can be avoided  Order in M2 remains the same M1 M2 M3 M4 until in M4  Depth coherence C  If polygons do not penetrate E each other  If the same edges are in the F AET on one scan line as are on the preceding scan line and in the same order B  Then.UTCN 18 . no changes in depth relationships on any part of x the scan line  No new depth computations are needed Graphical Processing Systems .Scan line algorithm optimization  Scan line coherence: y  If polygons do not intersect D each other (in object space)  Then.

y) extents of the surfaces  When a surface is moved from ST to AST it is decomposed into a set of polygons  When a surface leaves the AST all associated polygons are discarded add surfaces to ST. for each scan line { update AST. find closest such surface. for each pixel on scan line { determine surfaces in AST that project to pixel. determine the graphics attribute of the closest surface.Scan line algorithm extension  Extend the Scan Line Algorithm to general surfaces (curved surfaces)  ET replaced by ST (Surface Table)  AET replaced by AST (Active Surface Table) sorted by the (x. } } Graphical Processing Systems .UTCN 19 . initialize AST.

published by “An Efficient Visible Surface Program”. “Scan Line Methods for Displaying Parametrically Defined Surfaces”.J. J.UTCN 20 . J. by Lane. A. (1975).Scan line algorithm extension  Scan line z-buffer algorithm  Meyer. Report to the National Science Foundation.  uses a z-buffer to resolve the visible surface problem  A single scan line frame buffer and z-buffer is used for each scan line  Scan line algorithms for curved surfaces  Lane-Carpenter Algorithm  Published in 1980. Carpenter. Ohio State University. T..  Uses Patch Table (PT) and Active Patch Table (APT)  Does the subdivision only as required when the scan line begins to intersect a patch. rather than in a preprocessing step  The patch position is analyzed by the patch’s control points that define its convex hull Graphical Processing Systems . and Blinn. L.. Whitted. Communications of the ACM.

Convex hull property Graphical Processing Systems .UTCN 21 .

Octree Based Algorithms 7 6 4 3 4 3 2 3 0 1 2 3 7 4 4 0 1 0 1 2 3 4 5 6 7 Graphical Processing Systems .UTCN 22 .7.

(2) 1 4 4 5 three neighbors of the closest octant in any order. and then x 2 3  Back to front enumeration 2 3 6 6 2 3  The nodes are listed in order in which any 6 6 6 33 7 3 3 6 727 node is guaranteed not to obscure any node 4 6 3 1 4 5 5 listed after it 6 3 25 1  Orthographic projection 4 5  Display order: (1) the farthest octant.Octree encoded objects  Octree regular structure gives nonintersecting cubes 7 6  Octree is partially presorted 4 3  Octree enumeration could improve the 4 3 2 operations (i.g. variate z.UTCN 23 . visibility computation): 3  Slice based enumeration 4 4  Iterate through the octants in slice perpendicular to one of the axes 0 1  Orthographic projection  E. (3) closest octant 4 5 Graphical Processing Systems . then y.e.

1.0.U. .gives up(U)/down(D) face. 7.R z Graphical Processing Systems .3 B. B. . front(F)/back(B) face y Back to front enumeration and visible faces 2 3 V Visible 2 3 z y x Back to front order 6 2 3 faces 6 6 7 3 3 6 33 6 2 4 6 6 7 7 3 1 . + .L + .2.3.U.1.0 B.4.6. + 2.4.R 4 5 .L 4 5 5 6 3 25 1 .5.D.6.7.7.U.5. + + 4.0. + 6.5 F.L + + + 0.7. 1.3.6.R + + .Octree enumeration for visibility  Eight back to front orders given by the viewer’s relative position  Positive x coordinate means the right (R) face is visible.5.5.R 4 5 + . 5.4. and negative x means the left (L) face is visible  Similarly: y+/.2. .2.7 F. .6.1.D. F.UTCN 24 . z+/.2 B.D.0.L 1 4 4 5 x .4.

Goldstein and Nagel (1968). 8. and later apply it in graphics  Whitted and Kay: extended ray tracing to handle specular reflection and refraction Graphical Processing Systems . and Kay (1979)  Appel: uses a sparse grid of rays to compute the 1 shadows  Goldstein and Nagel: simulate the trajectories of ballistic projectiles and Screen nuclear particles. Ray Casting Algorithms  Ray tracing. Whitted Pixel (1980).UTCN 25 . ray casting Viewer  Developed by Appel (1968).

in corners of each pixel. etc. e. on CSG hierarchy)  Antialiasing ray tracing  Point sampling on a regular grid produces aliasing images  Adaptive supersampling (additional samples by more rays).)  Efficiency for visible surface ray tracing  Optimize the intersection computation  Avoid intersection computation  Hierarchical bounding volumes  Efficient hierarchy traversal  Automatically hierarchy generation  Spatial partitioning  Computing Boolean set operations  Compute the visibility for 3D union. ellipsoid. difference. etc.Ray casting issues  Computing intersections  Ray (parametric line) and a polygon  Line and cylinder.UTCN 26 . and intersection of two solids (e. cube. sphere.g. Graphical Processing Systems .g. paraboloid.g.  Line and quadrics (e.

Ray casting issues 1 p31 2 p21 p11 6 p41 4 3 7 p32 5 p42 p12 1 p22 2 3 4 5 6 7  Hierarchical bounding boxes  Efficient extents 8 9 10 11 12 Graphical Processing Systems .UTCN 27 .

UTCN 28 . octree  Automatically hierarchy generation  Spatial partitioning  Efficient hierarchy traversal  Optimize the intersection computation Graphical Processing Systems .Ray casting issues R1 1 2 3 4 R2 1 2 3 4 R3  Quadtree.

UTCN 29 .Ray casting issues 8 8 6 8 23 3 6 246 4 8 15 8 7 7 7 7 2 1 8 3 4 5 7 1  Automatically hierarchy generation  Spatial partitioning  Efficient hierarchy traversal  Optimize the intersection computation Graphical Processing Systems .

UTCN 30 .Ray casting issues 2 6 8 R3 R2 R1 3 4 5 1 7  Automatically hierarchy generation  Spatial partitioning  Efficient hierarchy traversal  Optimize the intersection computation Graphical Processing Systems .

H. Compute polygon planes 2. but the objects do not  Steps: 1. but cannot be obscured by clusters on the other side  Suited for applications in which the viewpoint changes. Kedem... Kedem and Naylor in 1980  Published in 1980. who considered the space as a set of clusters separated by planes (faces):  Clusters that are on the same side of the plane as the eyepoint can obscure.9. BSP Trees  Binary Space Partitioning Trees (BSP Trees)  Developed by Fuchs. B.. “ON Visible Surface Generation by A Priori Tree Structures”. Naylor.F. by Fuchs. Z. Determine the normal vector for each polygonal face 3.  The basic idea has been published in 1969 by Schumacker. Visualize the polygons in order infered from the BSP tree and the viewer’s position Graphical Processing Systems . Add nodes by analyzing the relative position of other faces relative to the current parent node 2. Build the BSP tree 1. Chose the root node 4.M. SIGGRAPH 80.UTCN 31 .

Example 5 3 5a back 5b front 2 3 1 4 6 2 5b 7 5a 7 6 1 4 Graphical Processing Systems .UTCN 32 .BSP Trees .

Example 5 2 3 5a back 2a 5b front 2b 6 4 3 6 5b 7 front back 7 1 4 2b 1 front back 5a 2a Graphical Processing Systems .UTCN 33 .BSP Trees .

UTCN 34 .BSP Trees .Example 5 2 3 5a back 2a 5b front 2b 3 6 7 6 front back 7 front back 1 4 2b 1 5b 4 front back 5a 2a Graphical Processing Systems .

Root face F 3.BSP Trees .UTCN 35 . Root face F 3. Front space polygons Front Space Back Space Display order: Viewer 1. Back space polygons Front Space Back Space Graphical Processing Systems . Back space polygons 2.Display Viewer Display order: 1. Front space polygons 2.

5b. 2b. 6.UTCN 36 . BSP Trees . 7.Display 4 5 2 3 5a back 2a 5b front 2b 2 7 3 6 7 Viewer 6 front 7 front back back 6 8 3 1 1 4 2b 1 5b 4 front back 5 9 5a 2a Display order: 4. 2a Graphical Processing Systems . 1. 3. 5a.