Presentation is loading. Please wait.

Presentation is loading. Please wait.

(c) 2002 University of Wisconsin, CS559

Similar presentations


Presentation on theme: "(c) 2002 University of Wisconsin, CS559"— Presentation transcript:

1 (c) 2002 University of Wisconsin, CS559
Last Time Drawing Polygons Project 2 10/24/02 (c) 2002 University of Wisconsin, CS559

2 (c) 2002 University of Wisconsin, CS559
Today Antialiasing Hidden Surface Removal Homework 4 10/24/02 (c) 2002 University of Wisconsin, CS559

3 (c) 2002 University of Wisconsin, CS559
Anti-Aliasing Lines drawn using Bresenham’s algorithm, and polygons drawn using our fill rules, both have jagged edges Why, from a sampling perspective? (Think, a line is infinitely thin) How can we fix it? 10/24/02 (c) 2002 University of Wisconsin, CS559

4 (c) 2002 University of Wisconsin, CS559
Anti-Aliasing Two general approaches: Area sampling and super-sampling Area sampling approaches sample primitives with a box (or Gaussian, or whatever) rather than spikes Requires primitives that have area (lines with width) Sometimes referred to as pre-filtering Super-sampling samples at higher resolution, then filters down the resulting image Sometimes called post-filtering The prevalent form of anti-aliasing in hardware 10/24/02 (c) 2002 University of Wisconsin, CS559

5 Unweighted Area Sampling
Consider a line as having thickness (all good drawing programs do this) Consider pixels as little squares Fill pixels according to the proportion of their square covered by the line Other variations weigh the contribution according to where in the square the primitive falls 1/8 1/4 .914 1/8 1/4 .914 1/4 1/8 .914 1/4 1/8 10/24/02 (c) 2002 University of Wisconsin, CS559

6 Alpha-based Anti-Aliasing
1/8 Rather than setting the intensity according to coverage, set the  The pixel gets the line color, but with <=1 This supports the correct drawing of primitives one on top of the other Draw back to front, and composite each primitive over the existing image Only some hidden surface removal algorithms support it 1/4 .914 1/8 1/4 .914 1/4 1/8 .914 1/4 1/8 10/24/02 (c) 2002 University of Wisconsin, CS559

7 (c) 2002 University of Wisconsin, CS559
Super-sampling Sample at a higher resolution than required for display, and filter image down Issues of which samples to take, and how to average them 4 to 16 samples per pixel is typical Samples might be on a uniform grid, or randomly positioned, or other variants Number of samples can be adapted 10/24/02 (c) 2002 University of Wisconsin, CS559

8 (c) 2002 University of Wisconsin, CS559
Where We Stand At this point we know how to: Convert points from local to window coordinates Clip polygons and lines to the view volume Determine which pixels are covered by any given line or polygon Anti-alias Next thing: Determine which polygon is in front 10/24/02 (c) 2002 University of Wisconsin, CS559

9 (c) 2002 University of Wisconsin, CS559
Visibility Given a set of polygons, which is visible at each pixel? (in front, etc.). Also called hidden surface removal Very large number of different algorithms known. Two main classes: Object precision: computations that operate on primitives Image precision: computations at the pixel level All the spaces in the viewing pipeline maintain depth, so we can work in any space World, View and Canonical Screen spaces might be used Depth can be updated on a per-pixel basis as we scan convert polygons or lines 10/24/02 (c) 2002 University of Wisconsin, CS559

10 (c) 2002 University of Wisconsin, CS559
Visibility Issues Efficiency – it is slow to overwrite pixels, or scan convert things that cannot be seen Accuracy - answer should be right, and behave well when the viewpoint moves Must have technology that handles large, complex rendering databases In many complex worlds, few things are visible How much of the real world can you see at any moment? Complexity - object precision visibility may generate many small pieces of polygon 10/24/02 (c) 2002 University of Wisconsin, CS559

11 Painters Algorithm (Image Precision)
Choose an order for the polygons based on some choice (e.g. depth to a point on the polygon) Render the polygons in that order, deepest one first This renders nearer polygons over further Difficulty: works for some important geometries (2.5D - e.g. VLSI) doesn’t work in this form for most geometries - need at least better ways of determining ordering Fails zs Which point for choosing ordering? xs 10/24/02 (c) 2002 University of Wisconsin, CS559

12 The Z-buffer (1) (Image Precision)
For each pixel on screen, have at least two buffers Color buffer stores the current color of each pixel The thing to ultimately display Z-Buffer stores at each pixel the depth of the nearest thing seen so far Also called the depth buffer Initialize this buffer to a value corresponding to the furthest point (z=1.0 for canonical and window space) As a polygon is filled in, compute the depth value of each pixel that is to be filled if depth < z-buffer depth, fill in pixel color and new depth else disregard 10/24/02 (c) 2002 University of Wisconsin, CS559

13 (c) 2002 University of Wisconsin, CS559
The Z-buffer (2) Advantages: Simple and now ubiquitous in hardware A z-buffer is part of what makes a graphics card “3D” Computing the required depth values is simple Disadvantages: Over-renders - worthless for very large collections of polygons Depth quantization errors can be annoying Can’t easily do transparency or filtering for anti-aliasing (Requires keeping information about partially covered polygons) 10/24/02 (c) 2002 University of Wisconsin, CS559

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

15 (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(…) 10/24/02 (c) 2002 University of Wisconsin, CS559

16 The A-buffer (Image Precision)
Handles transparent surfaces and filter anti-aliasing At each pixel, maintain a pointer to a list of polygons sorted by depth, and a sub-pixel coverage mask for each polygon Matrix of bits saying which parts of the pixel are covered Algorithm: When drawing a pixel: 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 10/24/02 (c) 2002 University of Wisconsin, CS559

17 (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 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 But, used in high quality rendering tools over = 10/24/02 (c) 2002 University of Wisconsin, CS559

18 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 10/24/02 (c) 2002 University of Wisconsin, CS559

19 (c) 2002 University of Wisconsin, CS559
Scan Line Algorithm (2) zs zs xs Spans xs zs Where polygons overlap, draw front polygon xs 10/24/02 (c) 2002 University of Wisconsin, CS559

20 (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/24/02 (c) 2002 University of Wisconsin, CS559

21 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 10/24/02 (c) 2002 University of Wisconsin, CS559

22 (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 S’ z S S’ x S z S’ x S S’ 10/24/02 (c) 2002 University of Wisconsin, CS559

23 (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 - (n2) fragments from n polygons 10/24/02 (c) 2002 University of Wisconsin, CS559

24 (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: a polygon is completely in front of everything else in that region no surfaces project to the region only one surface is completely inside the region, overlaps the region, or surrounds the region 10/24/02 (c) 2002 University of Wisconsin, CS559

25 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 10/24/02 (c) 2002 University of Wisconsin, CS559

26 (c) 2002 University of Wisconsin, CS559
Warnock’s Algorithm Regions labeled with case used to classify them: One polygon in front Empty One polygon inside, surrounding or intersecting Small regions not labeled Note it’s a rendering algorithm and a HSR algorithm at the same time Assuming you can draw squares 2 3 2 2 3 3 3 2 3 3 3 1 3 1 1 1 1 3 3 3 3 3 2 3 3 3 2 2 2 2 10/24/02 (c) 2002 University of Wisconsin, CS559

27 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 10/24/02 (c) 2002 University of Wisconsin, CS559


Download ppt "(c) 2002 University of Wisconsin, CS559"

Similar presentations


Ads by Google