Download presentation

Presentation is loading. Please wait.

Published byMichael Ellis Modified over 6 years ago

1
03/12/02 (c) 2002 University of Wisconsin, CS559 Last Time Some Visibility (Hidden Surface Removal) algorithms –Painter’s Draw in some order Things drawn later overwrite things drawn earlier –Depth Buffer Keep a buffer that stores depth at each pixel Overwrite pixel (and depth) if the incoming pixel is closer to the viewer

2
03/12/02 (c) 2002 University of Wisconsin, CS559 Today More Visibility Algorithms –A-buffer –Scanline method –Depth Sorting –Area Subdivision –BSP Trees –Exact 2.5D Visibility

3
03/12/02 (c) 2002 University of Wisconsin, CS559 OpenGL Depth Buffer OpenGL defines a depth buffer as its visibility algorithm The enable depth testing: glEnable(GL_DEPTH_TEST) To clear the depth buffer: glClear(GL_DEPTH_BUFFER_BIT) –To clear color and depth: glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) The number of bits used for the depth values can be specified (windowing system dependent, and hardware may impose limits based on available memory) The comparison function can be specified: glDepthFunc(…)

4
03/12/02 (c) 2002 University of Wisconsin, CS559 Z-Buffer and Transparency Must render in back to front order Otherwise, would have to store first opaque polygon behind transparent one Partially transparent Opaque 1st 2nd 3rd Front 1st or 2nd Recall this color and depth 3rd: To know what to do now

5
03/12/02 (c) 2002 University of Wisconsin, CS559 The A-buffer (Image Precision) Handles transparent surfaces and a form of anti-aliasing At each pixel, maintain a list of polygons sorted by depth, and a sub-pixel coverage mask for each polygon –Sub-pixel mask: Matrix of bits saying which parts of the pixel are covered by the polygon Algorithm: When drawing a pixel (first pass): –if polygon is opaque and covers pixel, insert into list, removing all polygons farther away –if polygon is transparent or only partially covers pixel, insert into list, but don’t remove farther polygons

6
03/12/02 (c) 2002 University of Wisconsin, CS559 The A-buffer (2) Algorithm: Rendering pass –At each pixel, traverse buffer using polygon colors and coverage masks to composite: Advantage: –Can do more than Z-buffer Anti-aliasing, transparent surfaces without ordering –Coverage mask idea can be used in other visibility algorithms Disadvantages: –Not in hardware, and slow in software –Still at heart a z-buffer: Over-rendering and depth quantization problems over =

7
03/12/02 (c) 2002 University of Wisconsin, CS559 Scan Line Algorithm (Image Precision) Assume polygons do not intersect one another –Except maybe at edges or vertices Observation: across any given scan line, the visible polygon can change only at an edge Algorithm: –fill all polygons simultaneously –at each scan line, have all edges that cross scan line in AEL –keep record of current depth at current pixel - use to decide which is in front in filling span

8
03/12/02 (c) 2002 University of Wisconsin, CS559 Scan Line Algorithm (2) zszs xsxs zszs xsxs zszs xsxs Spans Where polygons overlap, draw front polygon

9
03/12/02 (c) 2002 University of Wisconsin, CS559 Scan Line Algorithm (3) Advantages: –Simple –Potentially fewer quantization errors (more bits available for depth) –Don’t over-render (each pixel only drawn once) –Filter anti-aliasing can be made to work (have information about all polygons at each pixel) Disadvantages: –Invisible polygons clog AEL, ET –Non-intersection criteria may be hard to meet

10
03/12/02 (c) 2002 University of Wisconsin, CS559 Depth Sorting (Object Precision, in view space) An example of a list-priority algorithm Sort polygons on depth of some point Render from back to front (modifying order on the fly) Rendering: For surface S with greatest depth –If no overlap in depth with other polygons, scan convert –Else, for overlaps in depth, test for overlaps in the image plane If none, scan convert and go to next polygon –If S, S’ overlap in depth and in image plane, swap order and try again –If S, S’ have been swapped already, split and reinsert

11
03/12/02 (c) 2002 University of Wisconsin, CS559 Depth Sorting (2) Testing for overlaps: Start drawing when first condition is met: –x-extents or y-extents do not overlap –S is behind the plane of S’ –S’ is in front of the plane of S –S and S’ do not intersect in the image plane S S’ S or z x S S’ z x S S

12
03/12/02 (c) 2002 University of Wisconsin, CS559 Depth sorting Advantages: –Filter anti-aliasing works fine Composite in back to front order with a sequence of over operations –No depth quantization error Depth comparisons carried out in high-precision view space Disadvantages: –Over-rendering –Potentially very large number of splits - (n 2 ) fragments from n polygons

13
03/12/02 (c) 2002 University of Wisconsin, CS559 Area Subdivision Exploits area coherence: Small areas of an image are likely to be covered by only one polygon Three easy cases for determining what’s in front in a given region: 1.a polygon is completely in front of everything else in that region 2.no surfaces project to the region 3.only one surface is completely inside the region, overlaps the region, or surrounds the region

14
03/12/02 (c) 2002 University of Wisconsin, CS559 Warnock’s Area Subdivision (Image Precision) Start with whole image If one of the easy cases is satisfied (previous slide), draw what’s in front Otherwise, subdivide the region and recurse If region is single pixel, choose surface with smallest depth Advantages: –No over-rendering –Anti-aliases well - just recurse deeper to get sub-pixel information Disadvantage: –Tests are quite complex and slow

15
03/12/02 (c) 2002 University of Wisconsin, CS559 Warnock’s Algorithm Regions labeled with case used to classify them: 1)One polygon in front 2)Empty 3)One polygon inside, surrounding or intersecting Small regions not labeled 222 2222 2 2 3 3 3 333 3 3 3 3 3 333 3 3 1 11 1 1

16
03/12/02 (c) 2002 University of Wisconsin, CS559 BSP-Trees (Object Precision) Construct a binary space partition tree –Tree gives a rendering order –A list-priority algorithm Tree splits 3D world with planes –The world is broken into convex cells –Each cell is the intersection of all the half-spaces of splitting planes on tree path to the cell Also used to model the shape of objects, and in other visibility algorithms –BSP visibility in games does not necessarily refer to this algorithm

17
03/12/02 (c) 2002 University of Wisconsin, CS559 BSP-Tree Example A C B 2 4 1 3 A B C 3241 - - - + ++

18
03/12/02 (c) 2002 University of Wisconsin, CS559 Building BSP-Trees Choose polygon (arbitrary) Split its cell using plane on which polygon lies –May have to chop polygons in two (Clipping!) Continue until each cell contains only one polygon fragment Splitting planes could be chosen in other ways, but there is no efficient optimal algorithm for building BSP trees –Optimal means minimum number of polygon fragments in a balanced tree

19
03/12/02 (c) 2002 University of Wisconsin, CS559 Building Example We will build a BSP tree, in 2D, for a 3 room building –Ignoring doors Splitting edge order is shown –“Back” side of edge is side with the number 1 2 34 5 6

20
03/12/02 (c) 2002 University of Wisconsin, CS559 Building Example (1) 1 23b4b 5 6 1 3a, 4a, 62, 3b, 4b, 5 - + 4a 3a

21
03/12/02 (c) 2002 University of Wisconsin, CS559 Building Example (2) 1 23b4b 5a 6 1 3a, 4a, 6 - + 4a 3a 3b, 5b 2 4b, 5a -+ 5b

22
03/12/02 (c) 2002 University of Wisconsin, CS559 Building Example (3) 1 23b4b 5a 6 1 - + 4a 3a 2 4b, 5a - + 5b 4a, 6 3a + 5b 3b +

23
03/12/02 (c) 2002 University of Wisconsin, CS559 Building Example (Done) 1 23b4b 5a 6 1 - + 4a 3a 2 - + 5b 3a + 3b + 4a 6 + 5b 4b 5a +

Similar presentations

© 2021 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google