Presentation is loading. Please wait.

Presentation is loading. Please wait.

© University of Wisconsin, CS559 Fall 2004

Similar presentations


Presentation on theme: "© University of Wisconsin, CS559 Fall 2004"— Presentation transcript:

1 © University of Wisconsin, CS559 Fall 2004
Last Time Filling polygons Anti-aliasing Visibility Painter’s algorithm Z-Buffer 11/02/04 © University of Wisconsin, CS559 Fall 2004

2 © University of Wisconsin, CS559 Fall 2004
Today Hidden Surface Removal More Z-buffer A-buffer BSP Tree algorithms Project 2 11/02/04 © University of Wisconsin, CS559 Fall 2004

3 © University of Wisconsin, CS559 Fall 2004
Visibility Recap You are given a set of polygons to draw and you need to figure out which one is visible at every pixel Issues include: 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 Complexity – object precision visibility may generate many small pieces of polygon 11/02/04 © University of Wisconsin, CS559 Fall 2004

4 Z-Buffer and Transparency
Say you want to render transparent surfaces (alpha not 1) with a z-buffer Must render in back to front order Otherwise, would have to store at least the first opaque polygon behind transparent one Front Partially transparent 3rd 1st or 2nd 3rd: Need depth of 1st and 2nd Opaque 2nd Opaque 1st 1st or 2nd Must recall this color and depth 11/02/04 © University of Wisconsin, CS559 Fall 2004

5 © University of Wisconsin, CS559 Fall 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 11/02/04 © University of Wisconsin, CS559 Fall 2004

6 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 Coverage mask: Matrix of bits saying which parts of the pixel are covered Algorithm: Drawing pass (do not directly display the result) 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 11/02/04 © University of Wisconsin, CS559 Fall 2004

7 © University of Wisconsin, CS559 Fall 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 = 11/02/04 © University of Wisconsin, CS559 Fall 2004

8 © University of Wisconsin, CS559 Fall 2004
Area Subdivision Exploits area coherence: Small areas of an image are likely to be covered by only one polygon The practical truth of this assertion varies over the years (it’s currently going from mostly false to more true) 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 11/02/04 © University of Wisconsin, CS559 Fall 2004

9 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 11/02/04 © University of Wisconsin, CS559 Fall 2004

10 © University of Wisconsin, CS559 Fall 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 11/02/04 © University of Wisconsin, CS559 Fall 2004

11 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 11/02/04 © University of Wisconsin, CS559 Fall 2004

12 © University of Wisconsin, CS559 Fall 2004
BSP-Tree Example A A C 4 3 - + B C - B + - + 1 3 2 4 1 2 11/02/04 © University of Wisconsin, CS559 Fall 2004

13 © University of Wisconsin, CS559 Fall 2004
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 11/02/04 © University of Wisconsin, CS559 Fall 2004

14 © University of Wisconsin, CS559 Fall 2004
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 5 2 3 4 1 6 11/02/04 © University of Wisconsin, CS559 Fall 2004

15 Building Example (Done)
1 - + 2 3a - + + 3b 2 4b 4a 3b 4b + + + 6 5b 5a 1 4a 3a 6 11/02/04 © University of Wisconsin, CS559 Fall 2004

16 © University of Wisconsin, CS559 Fall 2004
BSP-Tree Rendering Observation: Things on the opposite side of a splitting plane from the viewpoint cannot obscure things on the same side as the viewpoint Rendering algorithm is recursive descent of the BSP Tree At each node (for back to front rendering): Recurse down the side of the sub-tree that does not contain the viewpoint Test viewpoint against the split plane to decide which tree Draw the polygon in the splitting plane Paint over whatever has already been drawn Recurse down the side of the tree containing the viewpoint 11/02/04 © University of Wisconsin, CS559 Fall 2004

17 © University of Wisconsin, CS559 Fall 2004
Using a BSP-Tree Observation: Things on the opposite side of a splitting plane from the viewpoint cannot obscure things on the same side as the viewpoint A statement about rays – a ray must hit something on this side of the split plane before it hits the split plane and before it hits anything on the back side NOT a statement about distance – things on the far side of the plane can be closer than things on the near side Gives a relative ordering of the polygons, not absolute in terms of depth or any other quantity Split plane 11/02/04 © University of Wisconsin, CS559 Fall 2004

18 © University of Wisconsin, CS559 Fall 2004
Rendering Example 1 5b 9 5a 6 - + 2 Eye 3a - 3b 2 4b + + 8 7 5 4a 3b 4b + + 1 4 + 3a 4a 6 5b 5a 1 2 6 3 Back-to-front rendering order is 3a,4a,6,1,4b,5a,2,3b,5b 11/02/04 © University of Wisconsin, CS559 Fall 2004

19 © University of Wisconsin, CS559 Fall 2004
BSP-Tree Rendering (2) Advantages: One tree works for any viewing point Filter anti-aliasing and transparency work Have back to front ordering for compositing Can also render front to back, and avoid drawing back polygons that cannot contribute to the view Uses two trees – an extra one that subdivides the window Major innovation in Quake Disadvantages: Can be many small pieces of polygon Over-rendering 11/02/04 © University of Wisconsin, CS559 Fall 2004

20 © University of Wisconsin, CS559 Fall 2004
Exact Visibility An exact visibility algorithm tells you what is visible and only what is visible No over-rendering Warnock’s algorithm is an example Difficult to achieve efficiently in practice Small detail objects in an environment make it particularly difficult But, in mazes and other simple environments, exact visibility is extremely efficient 11/02/04 © University of Wisconsin, CS559 Fall 2004

21 © University of Wisconsin, CS559 Fall 2004
Cells and Portals Assume the world can be broken into cells Simple shapes Rooms in a building, for instance Define portals to be the transparent boundaries between cells Doorways between rooms, windows, etc In a world like this, can determine exactly which parts of which rooms are visible Then render visible rooms plus contents 11/02/04 © University of Wisconsin, CS559 Fall 2004

22 Cell-Portal Example (1)
View 11/02/04 © University of Wisconsin, CS559 Fall 2004

23 Cell and Portal Visibility
Start in the cell containing the viewer, with the full viewing frustum Render the walls of that room and its contents Recursively clip the viewing frustum to each portal out of the cell, and call the algorithm on the cell beyond the portal 11/02/04 © University of Wisconsin, CS559 Fall 2004

24 Cell-Portal Example (2)
View 11/02/04 © University of Wisconsin, CS559 Fall 2004

25 Cell-Portal Example (3)
View 11/02/04 © University of Wisconsin, CS559 Fall 2004

26 Cell-Portal Example (4)
View 11/02/04 © University of Wisconsin, CS559 Fall 2004

27 Cell-Portal Example (5)
View 11/02/04 © University of Wisconsin, CS559 Fall 2004

28 Cell-Portal Example (6)
View 11/02/04 © University of Wisconsin, CS559 Fall 2004

29 Cell-Portal Operations
Must clip polygons to the current view frustum (not the original one) Can be done with additional hardware clipping planes, if you have them Must clip the view frustum to the portal Easiest to clip portal to frustum, then set frustum to exactly contain clipped portal In Project 2, you implement these things in software, for a 2.5d environment 11/02/04 © University of Wisconsin, CS559 Fall 2004

30 Cell-Portal Properties
Advantages Extremely efficient - only looks at cells that are actually visible: visibility culling Easy to modify for approximate visibility - render all of partially visible cells, let depth buffer clean up Can handle mirrors as well - flip world about the mirror and pretend mirror is a portal Disadvantages Restricted to environments with good cell/portal structure 11/02/04 © University of Wisconsin, CS559 Fall 2004

31 © University of Wisconsin, CS559 Fall 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 viewing angle and an angle for the field of view X (cx,cy,cz) 11/02/04 © University of Wisconsin, CS559 Fall 2004

32 © University of Wisconsin, CS559 Fall 2004
Project 2 (2) 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 11/02/04 © University of Wisconsin, CS559 Fall 2004

33 © University of Wisconsin, CS559 Fall 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, recurse into neighboring polygon Draw the floor and ceiling first, because they will be behind everything 11/02/04 © University of Wisconsin, CS559 Fall 2004

34 © University of Wisconsin, CS559 Fall 2004
Where We Stand So far we know how to: Transform between spaces Draw polygons Decide what’s in front Next Deciding a pixel’s intensity and color 11/02/04 © University of Wisconsin, CS559 Fall 2004


Download ppt "© University of Wisconsin, CS559 Fall 2004"

Similar presentations


Ads by Google