Spatial sorting
Chapter 4 discusses scenes that renders a hierarchical structure, and the order of the object drawn in the scene is determined by depth priority, almost all, rendering the scene is not correct in this way. For example, if the two non-intersecting objects along the eye sight is to be drawn, then the object of the farther will be drawn first. In the depth traversal, if there is an object behind the nearest object, the way the scene is drawn is incorrect. Therefore, if a scenario is to be correctly drawn, the only way is to be sorted. The examples given above will only illustrate the necessity of sorting. In the real game, this sort can be simplified when the scene is modeled, for example in a township model containing a large number of buildings. The real sorting mechanism may be more complex, especially when the object is not intended, but there is a certain entanglement. In fact, if a scene includes a transparent object, it is very difficult to determine a correct draw order, and even segment the object. For example, the trees in the outdoor scene, each of them is achieved by the multilateral shape mixed by the intersection.
The basic premise of space sorting is to avoid plotting a pixel multiple times on the screen, which means that a pixel is drawn, because the entire screen must be drawn, so the ideal depth is complex. Sex is 1; that is, each pixel is only drawn once. The higher the depth complexity, the lower the screen refresh rate.
A typical sorting method is now a depth cache, and it has been discussed in Chapter 3. This method is determined in pixels, and the depth value between the farthest and recent cutting sheets is stored in the depth cache. The color value of each pixel is stored in the frame buffer. It is assumed that the depth cache starts the test and writing function. If the color of a pixel wants to draw in the frame buffer, its depth value must be less than the depth value of the current pixel color, This process is very slow for the prior renderer, but with hardware acceleration support, the depth cache is a well-universal depth sort solution.
The depth cache requires a triangle to handle the pixels surrounded by the enclosed, but when the triangle is not drawn, do not give them to the renderer to determine, the decision of the object (the space algorithm) It is better than the decision (icon spatial algorithm) in pixels. This chapter will discuss the relatively advanced spatial sorting algorithm. 12.1 is a summary of the four-fork tree and the topic tree, which provides a rule division scheme for the scene. The four-tree is used to divide the plane rectangle, and the top tree is divided into the rectangular square. However, the sorting scheme required by many games is related to the game scene data. For an indoor scene, naturally use a natural sort mode (12.2 theme) related to the viewport (the subject of the topic), a scene of an outdoor scene and the need to correctly draw a mixed polygon: two fork spatial sections Very useful, Section 12.3 will describe how to build this tree and how it is used to hide face cutting, visibility determination, selection, and collision monitoring.
12.1 quadruple tree and top forum
The scene map provides a basic mechanism for object selection, and the node binding space can greatly reduce the number of nodes sent to the renderer for the cone. If the binding space intersects with the cone, its subtree with its binding node is the root node, but this process is only based on the binding space information. There is also information about the scene structure to be more advanced in the system can be utilized. For example, in an topical system, a visible map can be created to help reduce the invisible terrain on the current viewpoint position. Especially in a terrain, there is a mountain behind the mountain, so those hidden films don't have to be dealt, although their binding spatial information intersects the cone.
Four-tree and top trees are used to divide the scene space into small units. The visibility map is also based on units. When the viewpoint is placed in a unit, a list of potential video units associated with this unit will be generated, and if the scene structure is carefully designed to support this policy, this program is very effective. This configuration of this unit-based visibility determines the scenario, the first type: the plan is based on the plane position, in which case this plane is cross-section; second The solution is based on spatial position, and in this case the entire space is spatied into a top tree. A node in the scene map represents a specific four-tree block or an eight fork block. If a node represents a quadruple block represents a node, it has four sub-nodes. If it represents an eight fork block, there are eight sub-nodes. The addition of the child node is used in the actual objects in these units. If the object moves over time, the scene map needs to be reset by connecting the object to the node or cancellation. However, the basic quadruple or top tree structure is consistent throughout the program run cycle.
A pseudo code processed by a quadruple or top tree scene is given below. The visibility list of the four-tree block stores some pointers, which points to all the nodes of all potential visible blocks based on the current blocks.
Camerablock = getBlockof (Render.camera);
Visiblelist = getVisiblecellsfrom (Camerablock);
For (Each Node In VisiBLIST)
RENDERER.DRAW (Node);
As mentioned in Chapter 4, the DRAW function recursively traverses a certain sized subtree and strives to choose the binding space before drawing. Based on the bifurcation of the ground tree division is removed in the selection based on the binding space ratio.
Of course, the difficulty of this process is to establish a visibility list. A excellent visibility decision is a Ph.D. in Seth Teller 1992, and Hanan Samet offers all two booklets published in 1989/1990 to all about the quadruple and top tree.
12.2 Entrance (Portal)
The four-fork tree and top tree space are struggled to establish a visible map on the basis of the program regarding the metabographs of the scene structure and object. The program producer has a responsibility to manually or through some kind of automated method. A method that requires less interaction is based on the inlet system. In this system, a complex visibility map is established, which is not as good as the game programmer adds additional cutting surface to cut the city smaller. Typical situations are outside viewpoints outside of a house, but they look into the house. That door is an entrance to see something in the house. But the wall near the door will close the view of the contents of many houses. So when drawing this room, the house body can be removed, even if the object is potentially hidden, and can be used together with the viewpoint position of the door frame and the viewpoint position can be used to establish a cutting surface, these cutting The surface can be used to cut, and these cuts can be supplemented as blanking treatment. Entrance technology is very useful in indoor style, because there are many walls and other objects that block sight in that case to facilitate culling processing. However, the use of inlet technology is not limited to an indoor scene. For example: A movie role visible for viewpoint may run to the building. Suppose the building is sufficiently high, and the top of the roof cannot be seen through the roof, and the cutting sheets composed of the edges of the building front and the role can be used in an inlet system. Once the role is completely behind the building (that is, the role is on the non-visibility side of the cutting piece), it will not be given to the renderer to deal with it.
Figure 12.1 Visible Demonstration of Overal
Figure 12.1 illustrates a typical situation of the entrance, the gray area in the left figure illustrates the space that needs to be processed in the standard view body. The figure is viewed, and how the entrance cutting piece limits the content considered. If you use the hierarchical mechanism in Chapter 4, this excess cut surface selection is very trivial. This blanking mechanism holds a six-bit sign. Each bit indicates whether the object is visible for the corresponding cutting flakes. This flag can be extended to use any number of bits, the pilot can store the cutting wrap of additional blanking, the same wrap can be used to cut. But in the API accelerated in the hardware, such as OpenGL and Direct3D only support a small number of cutting wraps, and an inlet system is to limit the number of excess cutting wraps if you want to use the API. A indoor scene using the inlet technology must be able to be divided into a plurality of protrusions, and the sequence of the components of the region is not important. In fact, the entrance itself is a convex polygon, and this convex parallel is present on a piece of segmentation in two bumps. Understand from this perspective: An entry is two-way, although it is not necessary, it is not necessary. However, you can build two adjacent areas into such an area, you can see another area from one inside, but you can't see the former from another. In fact, the second area does not even have a connecting port in the first one. This represents the concept of unidirectional long-distance housing, we will assume that the entrance is non-bidirectional, if the two near the area passes through a public graphic entrance, then the two areas will connect to this entrance. The two portions are coexisting in the same location.
An arbitrary complex scene can be formed in a region and inlet. For example, you can stand in a region, see another area through an entry, or you can pass another area through the entrance from that area. The rendering mechanism must be drawn from the backward order to ensure the correct virtual effect. This scheme is achieved by building an abstract direct picture. In this figure is the node of the figure, the entrance is the side of the figure. This hike is a father and son scene. Instead, it represents the relationship between adjacent areas. Each area is represented in the node in the figure, and the node includes sufficient information to support traversal of the adjacent area. The portal is connected to the regional node as the sub-node of the region to support the inlet blanking. If a region is being accessed by the neighboring graphic. However, it is not necessarily that all inlets in this area are in the view cone (or part of the space set). Continuous traversal of adjacent scenes can ignore such an entrance to effectively complete another blanking. Finally, the regional node can also have other child nodes represent the binding surface (wall of the wall, that is, if the area is a house) and the object in the region and the drawing body visible in the region. A pseudo code to draw a convex region in the inlet system is given. The object Planeset is the current renderer used to blame and cut cut surfaces. The inlet is that the cutting surface is formed by the inlet convex polygon and the viewpoint position.
Void Render (Region Region)
{
IF (not region.beingvisited)
{
Region.beingvisited = true;
For (Each Portal in Region)
{
IF (Portal.isvisiblewithrespectTto (Planset))
{
PlaneSet.Add (Portal.Planes);
Render (Portal.adjacentregion);
}
}
Render (Region.BoundingPlanes);
RENDER (Region.ContainerDObject);
Region.beingvisited = false;
}
}
Figure 12.2 Simple entrance example
Figure 12.3 L-shaped area in the inlet system
The access flag is required in several cases, one is that the area has a two-way entry to connect to the adjacent area, and the other is that this area has a single entry entry. Or out. This avoids tracing cycles in the abstract graph. Figure 12.2 shows a simple set of convex areas, portions, and corresponding clubs. Although the region must be visualized. However, a non-actuated region can also be processed by the inlet system through a non-visible wall cutting convex area. The entrance uses a representative of a typical entrance - the mouth (door, window) on a wall. Door 12.3 shows how a L-type area is represented in the inlet system.
As mentioned earlier, the entry surface can be used to blanking and cut, however rendered performance must be considered. If a scenario has a large number of portions, there is a large number of additional cutting surfaces at the same time, which may be very huge and even smaller cutting in blanking and clipping. The surface and dependence depth are cache into a better choice.
The same problem is also generated when the additional cut surface added to the system is given to a convex polygon entry. This way you have two options. One is to blanking with a conventional cutting surface. The other is approximation: instead of the original old construction inlet through approximately a relatively small convex polygon, it may produce such a situation: the object that may be removed in the original case is reserved. . The key to the trade-off is the comparison of the time to be subjected to the time of the time, one is to adopt an additional cut surface, and the other is that only a depth cache, the latter is often closed.
12.3 Binary spatial crossbacy
A particularly universal spatial sorting method is a binary spatial score algorithm, in which the N-dimensional space is divided into a convex set. In the case of n = 2, the split structure is a straight line. In the case of n = 3, the split structure is a plane. A binary space partitioning tree is referred to as a BSP tree, which is a data structure used to represent the split. In the case of n = 3, the root node represents all spaces and contains all the spatial spatial profiles. The first sub-node or the prior to the pre-subjunction represents the correlation sub-space set on the front surface of this layer. That is, if the section is n * xd = 0 (larger is a vector), then the left sub-tree represents those N * XD> 0. The term "prior" (sub-tree) is corresponding to visibility . If the section is generated by a surface of the object and the viewpoint position is on the positive side of the cross section, the surface of this (object) is visible and is called forward. The second child node or the sub-node representation of the sub-surface-related spatial subset of the section. Any spatial subset can continue to be separated by a section, then those nodes are stored in section, and their child nodes represent smaller convex space subsets. Numerous leaf nodes represent the final spatial space set. These space sets can be bind or unlock bindings. Figure 12.4 shows a two-dimensional BSP tree. This square represents all R2, the internal node represents the cross section of the profile surface and the convex space area represented by the leaf node.
BSP tree is more common because it is not limited to the orientation of the profile. And the top and four trigems can be implemented with the BSP tree. Due to the four-brothers, a new parent node is added to the first two brothers nodes, and the old parent nodes become the "grandfather" node. A new parent node is simply added to the other two parent nodes. So the parent node of the first two brothers nodes represents the left half of the quartet, and the brothers' nodes represent the further crossbacy of these half. There is also the same way to the topic tree. A parent node and eight brother nodes will be replaced by a tree. In this tree, the old godfather node will be a Zeng Zu node, then add two "grandfather" nodes, four "father" nodes.
Figure 12.4 BSP tree
The formal papers of this topic are Fuchs, Kedem (1979), and Naylor (1980). About the FAQ (Reality.sgi.com/BSPFAQ/) of BSP provides links to this topic a general introduction and related information and source code. 12.3.1 BSP Tree Construction
Although a BSP tree is a spatial cross section, it can also spatially in the space. If an object is on the front of the cross section, then this object is associated with the former subtocks representing the nodes of this section. Similarly, if an object is in the back of the cross section, it is associated with the rear child node. When the object across the section, the type is difficult to discriminate. In this case, the object can be cut into two subjectures, each contact with one child node. If the object is a spatial space, the subjectors are also a spatial space and shared a common surface that falls on the cross section. In the implementation of a BSP tree, the objects in the scene are treated as a polygonal pool, and the shared surface and the node representing the section are stored together. Because it is possible to make a lot of segmentation, this can reduce memory consumption because common surface data is stored in one-time storage and is shared by spatial space. The pseudo code for the structure tree is given below. Prerequisites are not empty in the initial polygon.
Void Constructree (BSPtree Tree, PolygonList List)
{
Polygonlist poslist neglist;
Edgelist sharedlist;
Tree.Plane = SelectPartitionPlane (List); // Dot (n, x) -c = 0
For (Each Polygon In List) Do
{
TYPE = Classify (Polygon, Tree.Plane);
IF (Type == POSTIVE) THEN
{
// Dot (n, x) -c> = 0 for all vertices with at Least
// one posTIVE
Poslist.add (polygon);
}
Else if (Type == Transverse) THEN
{
// Dot (n, x) -c is posient for at Least One Vertex
// And NEGATIVE for At Least One Vertex.
Polygon pospoly, negpoly;
Edge shadedede;
Polygon, Tree.Plane, POSPOLY, NEGPOLY, SharedEdge;
PositiveList.Add (POSPOLY);
NegaTiveList.Add (negpoly);
Sharedlist.add (sharededed);
}
Else // Type == COINCIDENT
{
// Dot (n, x) -c = 0 for all vertices
Tree.coincident.add (polygon);
}
}
Sharedlist is not empty
{
// Find All Disjoint Polygon in the interSection of
// Partition Plane with Polygon List.
Polygonlist compont;
ComputeConnectedComponents (SharedList, Component);
Tree.coincident.Append (Component);
}
IF (POSLIST IS Not Empty)
{
Tree.positive = new bsptree;
Contructurettree (Tree.positive, POSLIST);
}
Neglist is not empty
{
Tree.negative = new bsptree;
Constructtree (Tree.negatice, Neglist);
}
The SelectPartitionPlane () function selects a cross-sectional surface that requires a program, which is a multilateral list because a typical cross-section is definitely containing one of the used polygons, but may also be selected in the case of list data. Other cross section. For example, this situation may happen when building a tree based tree-based tree. A directional binding box can be adapted to data in the table, and then the method of selecting a sectional partition is satisfied with the maximum length of its axial wire. The later choice is working hard to create a balanced BSP tree, and another option can meet the minimization of the number of polygon segments minimize such guidelines.
The SPLIT function for the triangular list is the first cutting algorithm in substantive sense (mentioned in Chapter 3), and more extensive is that the cycle on the polygon list represents whether or not the polygon is cut into true and false judgment . This makes the BSP tree can be used as a computational stereoscopic geometric operation. This pseudo code is structurally description of the front back polygons of cutting a shared point set. The shared edge is processed back to calculate the polygon in which the intersectings intersecting in the cross section. For many systems, these polygon processing is basically unnecessarily, so the shared edge code can be removed.
Finally, please note: When the constructtree function call ends, the relevant tree nodes contain consistent polygons. You can also use other termination stop criteria: 1. When the number of polygonal numbers on the front or the back is smaller than the threshold value required by the program; 2. When the depth of the tree reaches the maximum depth. Both standards mentioned in the directional binding box tree structure.
12.3.2 Hidden face elimination
Through the depth of the BSP tree, it is possible to provide a very effective polygon sorting method. The price of sorting is that the polygon has to be segmented in this process. In the static geometry, the tree can be established during the pre-processing, so the cost of sorting is not included in the cost range of real-time operation.
From the backward drawing
Figure 12.5 Multilateral shapes that cannot be sorted
First, the object farthest position is drawn, and then draw the objects that are gradually close to the point of view, which is the core of the painter algorithm. The order of object drawn is like the sequence of painters painted on the canvas: the first background, and then the foreground. The prerequisite for this method is that two visible polygons must be separated by one surface. Figure 12.5 shows a case where it cannot be separated. However, the BSP tree structure can divide the overlapping polygonal shape into an unexpected polygon, which can be drawn correctly by the polygon by the polygon of the leaf node of the tree. The following gives the pseudo code traversed, assuming that the BSP construction process does not use the shared table mechanism mentioned earlier. The monitoring of the view direction reduces the spatial cross section, because the space behind the view is invisible.
Void DrawBackTofront (BSPtree Tree, Camera Camera)
{
// Compute Signed Distance from Eye Point e to Plane
// DOT (N, X) -C = 0
FLOAT SD = Dot (Tree.Plane.n, Camera.e) -tree.plane.c;
IF (SD> 0)
{
IF (-dot (Tree.Plane.N, Camera.d)> = Camera.cos (a))
{
Tree.Negative Is Not Empty
DrawBackTofront (Tree.negative, Camera.e);
DrawPolygons (Tree.Coincident);
}
IF (Tree.Positive Is Not Empty)
DrawBackTofront (Tree.positive, Camera.e);
}
ELSE IF (SD <0)
{
IF (Dot (Tree.Plane.N, Camera.d)> = Camera.cos (a))
{
IF (Tree.Positive Is Not Empty)
DrawBackTofront (Tree.positive, Camera.e);
DrawPolygons (Tree.Coincident);
Tree.Negative Is Not Empty
DrawBackTofront (Tree.negative, Camera.e);
}
Else
{
IF (Dot (Tree.Plane.N, Camera.D)> = 0)
{
IF (-dot (Tree.Plane.N, Camera.d)> = Camera.cos (a))
{
Tree.Negative Is Not Empty
DrawBackTofront (Tree.negative, Camera.e);
DrawPolygons (Tree.Coincident);
}
IF (Tree.Positive Is Not Empty)
DrawBackTofront (Tree.positive, Camera.e);
}
Else
{
IF (Dot (Tree.Plane.N, Camera.d)> = Camera.cos (a))
{
IF (Tree.Positive Is Not Empty)
DrawBackTofront (Tree.positive, Camera.e);
DrawPolygons (Tree.Coincident);
}
Tree.Negative Is Not Empty
DrawBackTofront (Tree.negative, Camera.e);
}
}
}
The direction of the viewpoint is d, the outer expansion angle of the viewer is 2A. A cosine value will pre-calculate the stored in the Camera object to be used for choice processing. When SD <0, the dot value is used to determine if N is in the view cone. If there is, the positioning of the cross section may intersect the view cone. If it is not, the back surface of the cross section does not intersect the view cone and is not visible, so it will not be drawn, and a more accurate selection can be achieved by isolation test of the cross section and view cone. In this case, the positive and negative numbers of the points in the direction of the line direction are important.
Drawing from the front
From the backward drawing, you can draw the scene, but the price of pixel redrawing is very large. The high depth complexity is that this algorithm cannot be used in real time. It is best to draw a nearest polygon in the off-plane position. Due to the correct sorting, once an image is written, it will not be covered by another polygon. This requires a pixel indicator to indicate whether this pixel has been drawn. Note that this marker and depth cache are different. When the depth cache is used, it is not determined that the sequence of polygonal drawings, and the depth system is tested before writing. More importantly: use depth cache, one pixel can be rewritten many times
Scan line mark
The BSP tree can support this pixel label (pixel sign) in two ways, one way to track each scan line independently. When a triangle is rasterized, there is a spacing between the scan lines intersecting the triangle intersecting, these pixels are written. A one-dimensional BSP tree can be used to track write intervals. Each node represents an interval [X0, X1), where the left endpoint is included in the interval, and the right end point is not. This semi-closed range is to support each triangle to be responsible for its edges and vertical edges to ensure that the triangular shared edge and shared vertices will not be redrawn. Initial state: An empty scan line is represented by a single top BSP tree. If the screen width is w pixel, then the node interval is [0, w). Now if a triangular rasterization is intersecting the [X0, X1) interval with the scan line, the value X0 will trigger the interval to [0, X0) and [X0, W), and the left interval will be with the root node. The left sub-node is associated, and the right interval is associated with the right child node of the root node. Value X1 will further divide interpretation [X0, W) into a left sub-node and a [x1, w) on the left sub-node and one [x1, w). Figure 12.6 illustrates the rasterization process between the electric scratches. The diagram illustrates the divided interval and the X value of the interval division. Consider: A new range [x2, x3) on this scan line will be rasterized. Because of the parameters. Suppose 0 <= x0 The method of this marker is ideal for rendering with software, which will retain a lot of closed chains. Note: In the triangle side setting, the vertex property interpolation is still applicable. More importantly, if a pre-prepared interval is divided by the scanning line BSP tree, the vertex attribute of the divided interval endpoint must also interpret. Regional tag The scan line tag concept can be extended to two dimensions. A BSP tree represents the status of the current screen. When a triangle is rasterized, each line containing a triangular shape will be treated. This line is used to select a point set in the triangle, after three sides are processed, the BSP tree has 7 leaf nodes, one of which is related to the rasterized triangle. The next rasterized triangle treats its edges, but overlap is possible. Tips are the correct markup node to draw or not drawn. In fact, the regional tag algorithm creates a BSP tree, and the drawn nodes of this BSP tree are the non-intersecting areas of the pixels. These pixels will be drawn for a given frame. 12.3.3 Visibility determination Give the viewpoint. The visible row determination is the process of determining the location of the scene from the viewpoint position. In a scenario consisting of polygonal objects, knowing those objects are visible, which helps minimize the amount of data sent to the renderer, and the concept of closedness is to mention. The object to enclose the scene species is not necessarily to be treated by the renderer. Visibility information can be used to close selection (Culling), a process of determining those objects from current viewpoints, for a static scene, visibility information can be obtained during pre-processing. However, if the viewpoint can be moved, the visible object will be changed over time. Dynamic precise judgment visible set is a very large process. Most systems work hard to get an approximate minimum number of objects to be sent to the renderer, but some may be invisible. The portal system mentioned above is a good dynamic visibility determination method in the case where the number of portals is small. Both methods are described, one is used as a 3D scene, one is used as a 2D scene. In both cases, the BSP tree is used to represent the spots space and from the frontward drawing. This tree is called a scene tree (World Tree). The second BSP tree is used to store visibility information called visibility trees. Clapspace method Three-dimensional space visibility tree initial state represents the view cone, the sessile surface in the tree is the six faces of the cone. After a given viewpoint position, the scene tree is traversed, and the polygon traversed is treated with visible trees and may decompose into a sub-polygon. Eventually each polygon or visible or invisible, each sub-polygon edge and viewpoints combine a new cross-sectional assembly. The viewpoints and related surfaces form a corner cone, and any part of the corner cone is located after the sub-polygon is invisible. The visibility tree is now stored with a corner, and a further reduction is made with a polygon accessed in the scene trees. Screen space method The initial state of the visibility tree of the two-dimensional space represents a triangle associated with the screen to draw pixels. After a given point position, the scene tree is traveled, and each polygon you encounter in the traversal is projected to the screen, and then treated by the visibility tree and decomposed into a sub-polygon, each or completely visible or completely invisible. Because the scene tree is sorted from the front backward, since the entire visibility tree calculates, the sub-multilateral edges visible later will remain visible, and these sub-multilates can be stored in a list for use in the list. 12.3.4 Select mechanism and collision monitoring Assuming a BSP tree represents the entire world, a selection operation will include a linear element (straight line, ray, or line segment) and whether or not any object in the scene is intersecting. One way is to traverse this scene tree segment this linear element (similar to sweeping the wire segmentation, the translator's note). Once the sub-elements of this linear element occurs at a node, the polygon in the scene is found.