Download presentation

Presentation is loading. Please wait.

Published byEthan Gilmore Modified over 6 years ago

1
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA

2
LEARNING OBJECTIVES In this chapter you will learn about: – –Height maps – –Creating and rendering a height map – –Hidden surface removal – –The Z-buffer algorithm – –The painter’s algorithm – –Clipping – –Two-dimensional line clipping – –Cohen-Sutherland clipping – –Liang-Barsky clipping – –The clipping of polygons – –Three-dimensional clipping – –Level of Detail (LOD) algorithms

3
HEIGHT MAPS Height maps, also called height fields, are predominantly used in computer games for realistic terrain generation. A height map is stored as a two-dimensional array consisting of x- and z-values. Each x- and z-coordinate is assigned a certain value (a y-coordinate) representing the height of a specific point on a 3D surface. Height maps can thus be described as simple two- dimensional arrays containing height values, sampled at evenly spaced intervals.

4
HEIGHT MAPS Height maps, as a function of x- and z- coordinates, can be represented using the following equation:

5
HEIGHT MAPS

6
Creating and Rendering a Height Map [see the textbook and online source code for a detailed discussion and examples].

7
HIDDEN SURFACE REMOVAL Culling is the process of comparing the position and orientation of polygons against the view volume’s field of view, with polygons facing away from the camera being eliminated. This elimination minimized the amount of computational overhead involved with hidden surface removal. Culling is basically a test determining the visibility of an object, and based on this test the object can be removed if not visible – a process known as hidden surface removal. A culling test is based on a simple vector calculation, specifically, the dot product between a polygon’s normal and the line-of-sight vector (the vector from the center of projection to the polygon). If the result of the dot product is positive then we can flag the polygon as visible (with its normal facing towards the viewer).

8
HIDDEN SURFACE REMOVAL There are two main hidden surface removal algorithm classes: – –object space algorithms – –image space algorithms. [see the textbook for a detailed example and discussion].

9
The Z-Buffer Algorithm The most common hidden surface removal algorithm is called the z-buffer algorithm. This image space algorithm was developed in 1975 by Edwin Catmull, current president of Walt Disney and Pixar Animation Studios. Z-buffering, sometimes referred to as depth- buffering, stores the depth values for each pixel being drawn in the frame buffer’s depth buffer. This stored depth data, or z-values, are then used by the algorithm to determine the pixels that should be drawn. [see the textbook for a detailed example and discussion].

10
The Painter’s Algorithm The painter’s algorithm orders polygons based on their distance from the viewer. This distance is calculated from the polygon’s centroid to the point of view.

11
The Painter’s Algorithm It is also possible to draw the objects of a scene in a front-to-back manner, resulting in the reverse painter’s algorithm. There is one serious flaw in the painter’s hidden surface removal algorithm – the overlapping of three or more polygons can cause it to fail. Another problem is encountered when two or more polygons intersect each other.

12
CLIPPING Clipping is an optimization operation resulting in the display of only visible objects. Clipping can be performed at the image space level, object space level or at both. Image space clipping, as with image space hidden surface removal, occurs during the rasterization phase and is done on a per-pixel basis. It defines a clipping filter operating on a pixel-by-pixel basis, determining whether a particular pixel lies within the specified viewport or not. Object space clipping is on the other hand either plane- based in object space or boundary-based in screen space. When performing plane-based clipping, we have to convert our view space boundaries to an object space clipping-plane, subsequently testing for the visibility of vertices inside this clipping-plane.

13
CLIPPING Boundary-based clipping clips against screen boundaries while in screen space by flagging the intersection of objects with planes adjacent to the x-, y- and z-axes.

14
Two-Dimensional Line Clipping Two-dimensional line clipping or line-segment clipping determines the primitives, or sections of primitives, visible to the viewer. All lines located within the predefined view volume pass the clipping test and are sent to the rasterizer for display. Primitives not located within the view volume are culled or eliminated. The lines, or primitives, partially located within the view volume are clipped so that only their visible sections are sent to the rasterizer for display.

15
Two-Dimensional Line Clipping The subsequent figure illustrates the following four possible clipping situations: A The line is completely visible within the predefined view volume, thus passing the clipping test. B The line is completely outside the predefined view volume and can be eliminated from the drawing process. C The line extends from outside the clipping region, enters the view volume and exits it again at another point. Lines like these must be clipped at both ends of the view volume. D The line segment is only partially within the predefined view volume. Its section outside of the clipping region must thus be clipped.

16
Two-Dimensional Line Clipping

17
There are several line clipping algorithms, such as the Cohen-Sutherland clipping algorithm, Liang-Barsky clipping, and Cyrus-Beck clipping. The core issue with clipping algorithms is determining the intersection of two lines.

18
Two-Dimensional Line Clipping The clipping process determines these intersections and can be described by the following three steps: 1 Take the input coordinates of a line, (x1, y1) and (x2, y2), as input. 2 Read the coordinates of the clipping rectangle. 3 Generate the clipped line coordinates, (x1’, y1’) and (x2’, y2’), by comparing the input values of the line to the coordinates of the clipping region.

19
Two-Dimensional Line Clipping Extending the mathematical approach used for calculating the intersection of two lines to determine the point of intersection of a line and clipping rectangle is relatively simple.

20
Cohen-Sutherland Clipping The Cohen-Sutherland two-dimensional line clipping algorithm can be considered a brute-force approach to the clipping problem. The algorithm basically divides the clipping region into a number of sections (specifically nine regions), each with its own unique 4-bit binary number, called an outcode.

21
Cohen-Sutherland Clipping [see the textbook for a detailed discussion and example].

22
Liang-Barsky Clipping The Liang-Barsky two-dimensional line clipping algorithm uses the parametric form of a line and the clipping window to determine the clipping coordinates of lines intersecting the clipping volume. This algorithm is significantly more efficient than Cohen-Sutherland clipping.

23
Liang-Barsky Clipping

24
To summarize, the Liang-Barsky clipping algorithm consists of the following steps: 1 Define all line segments in parametric form. 2 Set the minimum and maximum values for t (tmin ¼ 0 and tmax ¼ 1). 3 Calculate all the t values located between tmin and tmax. 4 Determine whether the arbitrary values of each parametric line lie within the clipping window. a If the line intersects, shorten the line segment via a floating- point division. b If the line doesn’t intersect the clipping window, discard it. 5 Display all clipped line segments.

25
Clipping Polygons Extending two-dimensional line clipping to polygons involves the clipping of polygons against a clipping rectangle or against other polygons, as is the case with hidden surface removal. Polygon clipping algorithms are derived from simple line clipping algorithms. We can thus clip a polygon against the edges of a clipping rectangle. There is, however, a problem with this approach – –clipping concave polygons can result in several additional polygons as shown in Figure 12-19.

26
Clipping Polygons

27
The The illustrated problem is not encountered when working with convex polygons. The only solution to this problem is to consider the clipped region as a single polygon or to tessellate (divide) the polygon into a number of convex polygons

28
Clipping Polygons

29
Three-Dimensional Clipping Three-dimensional objects are clipped against a bounding volume as opposed to a clipping rectangle. Specifically, when clipping in 3D space we need to consider the intersections of lines and planes or polygons and planes as opposed to the clipping of lines against lines, which is the case with 2D space. A simple technique often employed to reject objects completely outside the clipping volume and to accept objects entirely inside it is to create a bounding sphere for the object and to subsequently test its edges against that of the view volume. A bounding volume, or bounding box, is simply a volume containing a geometric object.

30
Three-Dimensional Clipping

32
INTRODUCTION TO LEVEL OF DETAIL (LOD) ALGORITHMS Level of Detail algorithms are concerned with the complexity of geometric objects; basically decreasing an object’s mesh complexity (the number of polygons) as the distance between the object and the viewer increases. The main reason for using these algorithms is to increase the efficiency of a rendering operation by lessening the workload on the graphics system.

33
INTRODUCTION TO LEVEL OF DETAIL (LOD) ALGORITHMS

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