Download presentation
Presentation is loading. Please wait.
1
© University of Wisconsin, CS559 Spring 2004
Last Time Drawing Polygons Fill rules: non-exterior, parity, non-zero winding number Sweep fill algorithm (also called scanline algorithm) Fill one row at a time Keep track of left and right edges, update incrementally from one row to the next Bottom of edges is in, top of edges is out, remove horizontal edges Simplest for convex, can be extended to concave Antialiasing Smooth objects before drawing – pre-filtering Supersample and smooth results – post-filtering 3/9/04 © University of Wisconsin, CS559 Spring 2004
2
© University of Wisconsin, CS559 Spring 2004
Today More anti-aliasing Visibility (what’s in front) 3/9/04 © University of Wisconsin, CS559 Spring 2004
3
Alpha-based Anti-Aliasing
1/8 Set the of a pixel to simulate a thick line 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 3/9/04 © University of Wisconsin, CS559 Spring 2004
4
© University of Wisconsin, CS559 Spring 2004
Calculating Consider a line as having thickness (all good drawing programs do this) Consider pixels as little squares Set according to the proportion of the square covered by the line The sub-pixel coverage interpretation of 1/8 1/4 .914 1/8 1/4 .914 1/4 1/8 .914 1/4 1/8 3/9/04 © University of Wisconsin, CS559 Spring 2004
5
© University of Wisconsin, CS559 Spring 2004
Weighted Sampling Instead of using the proportion of the area covered by the line, use convolution to do the sampling Equivalent to filtering the line then point sampling the result Place the “filter” at each pixel, and integrate product of pixel and line Common filters are cones (like Bartlett) or Gaussians 3/9/04 © University of Wisconsin, CS559 Spring 2004
6
© University of Wisconsin, CS559 Spring 2004
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 3/9/04 © University of Wisconsin, CS559 Spring 2004
7
© University of Wisconsin, CS559 Spring 2004
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 Actually, run Bresenham-like algorithm on z and w before perspective divide 3/9/04 © University of Wisconsin, CS559 Spring 2004
8
© University of Wisconsin, CS559 Spring 2004
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 environments, 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 3/9/04 © University of Wisconsin, CS559 Spring 2004
9
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 3/9/04 © University of Wisconsin, CS559 Spring 2004
10
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 3/9/04 © University of Wisconsin, CS559 Spring 2004
11
© University of Wisconsin, CS559 Spring 2004
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 – rasterizes polygons even if they are not visible Depth quantization errors can be annoying Can’t easily do transparency or filter-based anti-aliasing (Requires keeping information about partially covered polygons) 3/9/04 © University of Wisconsin, CS559 Spring 2004
12
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 3/9/04 © University of Wisconsin, CS559 Spring 2004
13
© University of Wisconsin, CS559 Spring 2004
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(…) Sometimes want to draw furthest thing, or equal to depth in buffer 3/9/04 © University of Wisconsin, CS559 Spring 2004
14
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 3/9/04 © University of Wisconsin, CS559 Spring 2004
15
© University of Wisconsin, CS559 Spring 2004
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 = 3/9/04 © University of Wisconsin, CS559 Spring 2004
16
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, using concave-handling version of sweep-fill algorithm at each scan line, have all edges that cross scan line in Active Edge List keep record of current depth at current pixel - use to decide which is in front in filling span 3/9/04 © University of Wisconsin, CS559 Spring 2004
17
© University of Wisconsin, CS559 Spring 2004
Scan Line Algorithm (2) zs zs xs Spans xs zs Where polygons overlap, draw front polygon Spans xs 3/9/04 © University of Wisconsin, CS559 Spring 2004
18
© University of Wisconsin, CS559 Spring 2004
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 Active Edge List, Edge Table Non-intersection criteria may be hard to meet 3/9/04 © University of Wisconsin, CS559 Spring 2004
19
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 3/9/04 © University of Wisconsin, CS559 Spring 2004
20
© University of Wisconsin, CS559 Spring 2004
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’ 3/9/04 © University of Wisconsin, CS559 Spring 2004
21
© University of Wisconsin, CS559 Spring 2004
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 space, before rasterization Disadvantages: Over-rendering Potentially very large number of splits - (n2) fragments from n polygons 3/9/04 © University of Wisconsin, CS559 Spring 2004
22
© University of Wisconsin, CS559 Spring 2004
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 3/9/04 © University of Wisconsin, CS559 Spring 2004
23
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 3/9/04 © University of Wisconsin, CS559 Spring 2004
24
© University of Wisconsin, CS559 Spring 2004
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 3/9/04 © University of Wisconsin, CS559 Spring 2004
25
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 3/9/04 © University of Wisconsin, CS559 Spring 2004
26
© University of Wisconsin, CS559 Spring 2004
BSP-Tree Example A A C 4 3 - + B C - B + - + 1 3 2 4 1 2 3/9/04 © University of Wisconsin, CS559 Spring 2004
27
© University of Wisconsin, CS559 Spring 2004
Project 2 Intro You are given the following: Rooms, defined in 2D by the edges that surround the room The height of the ceiling Each edge is marked opaque or clear For each clear edge, there is a pointer to the thing on the other side You know where the viewer is and what the field of view is The viewer is given as (cx,cy,cz) position The view frustum is given as a direction vector (dx,dy,dz) and an angle for the field of view (dx,dy,dz) (cx,cy,cz) 3/9/04 © University of Wisconsin, CS559 Spring 2004
28
© University of Wisconsin, CS559 Spring 2004
Project 2 (2) You don’t have everything needed to do this project yet, but you can do the hardest part Represent the frustum as a left and right clipping line You don’t have to worry about the top and bottom Each clip line starts at the viewer’s position and goes to infinity in the viewing direction Write a procedure that clips an edge to the view frustum This takes a frustum and returns the endpoints of the clipped edge, or a flag to indicate that the edge is not visible 3/9/04 © University of Wisconsin, CS559 Spring 2004
29
© University of Wisconsin, CS559 Spring 2004
Project 2 (3) Write a procedure that takes a room and a frustum, and draws the room Clip each edge to the frustum If the edge is visible, draw the wall that the edge represents Create the 3D wall from the 2d piece of edge Project the vertices Draw the polygon in 2D If the edge is clear, do nothing right now Draw the floor and ceiling first, because they will be behind everything 3/9/04 © University of Wisconsin, CS559 Spring 2004
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.