Real-Time Rendering——16.2 Tessellation and Triangulation曲面细分和三角测量

Tessellation is the process of splitting a surface into a set of polygons. Here, we focus on tessellating polygonal surfaces; curved surface tessellation is discussed in Section 17.6.Polygonal tessellation can be undertaken for a variety of reasons. The most common is that all graphics APIs and hardware are optimized for triangles. Triangles are almost like atoms, in that any surface can be made from them and rendered. Converting a complex polygon into triangles is called triangulation.

曲面细分是将一个曲面分割成一组多边形的过程。在这里,我们专注于曲面细分多边形表面;曲面曲面细分将在第17.6节中讨论。多边形曲面细分有多种原因。最常见的是所有图形API和硬件都是针对三角形优化的。三角形几乎就像原子一样,任何表面都可以用它们来制作和渲染。将复杂的多边形转换成三角形称为三角剖分。

There are several possible goals when tessellating polygons. For example, an algorithm to be used may handle only convex polygons. Such tessellation is called convex partitioning. The surface may need to be subdivided (meshed) to store at each vertex the effect of shadows or interreflections using global illumination techniques [400]. Figure 16.1 shows examples of these different types of tessellation. Non-graphical reasons for tessellation include requirements such as having no triangle be larger than some given area, or for triangles to have angles at their vertices all be larger than some minimum angle. Delaunay triangulation has a requirement that each circle formed by the vertices of each triangle does not contain any of the remaining vertices, which maximizes the minimum angles. While such restrictions are normally a part of nongraphical applications such as finite element analysis, these can also serve to improve the appearance of a surface. Long, thin triangles are often worth avoiding, as they can cause artifacts when interpolating over distant vertices. They also can be inefficient to rasterize [530].

细分多边形时有几个可能的目标。例如,要使用的算法可能只处理凸多边形。这种细分被称为凸分割。该表面可能需要细分(网格化),以使用全局照明技术在每个顶点存储阴影或相互反射的效果[400]。图16.1显示了这些不同类型的细分的例子。细分的非图形原因包括诸如没有三角形大于某个给定面积,或者三角形在其顶点的角度都大于某个最小角度的要求。Delaunay三角剖分有一个要求,即由每个三角形的顶点形成的每个圆不包含任何剩余的顶点,这使得最小角度最大化。虽然这种限制通常是有限元分析等非图形应用的一部分,但它们也可以用来改善表面的外观。细长的三角形通常值得避免,因为它们会在对远处的顶点进行插值时导致伪像。它们也可能是低效的光栅化[530]。

Figure 16.1. Various types of tessellation. The leftmost polygon is not tessellated, the next is partitioned into convex regions, the next is triangulated, and the rightmost is uniformly meshed.

图16.1。各种类型的细分。最左边的多边形没有被细分,接下来的被分割成凸区域,接下来的被三角化,最右边的被均匀网格化。

Most tessellation algorithms work in two dimensions. They assume that all points in the polygon are in the same plane. However, some model creation systems can generate polygon facets that are badly warped and non-planar. A common case of this problem is the warped quadrilateral that is viewed nearly edge-on; this may form what is referred to as an hourglass or a bowtie quadrilateral. See Figure 16.2. While this particular polygon can be triangulated simply by creating a diagonal edge, more complex warped polygons cannot be so easily managed.

大多数镶嵌算法在二维空间中工作。他们假设多边形中的所有点都在同一平面上。然而,一些模型创建系统可以生成严重扭曲和非平面的多边形面。这个问题的一个常见例子是翘曲的四边形,几乎是从边上看的;这可能形成所谓的沙漏或蝶形四边形。参见图16.2。虽然这个特殊的多边形可以简单地通过创建一条对角线来进行三角剖分,但是更复杂的扭曲多边形就不那么容易管理了。

Figure 16.2. Warped quadrilateral viewed edge-on, forming an ill-defined bowtie or hourglass figure,along with the two possible triangulations. 

图16.2。从侧面看,扭曲的四边形形成了一个模糊的蝴蝶结或沙漏形状,以及两个可能的三角形。

When warped polygons are possible, one quick corrective action is to project the vertices onto a plane that is perpendicular to the polygon’s approximate normal.The normal for this plane is often found by computing the projected areas on the three orthogonal xy, xz, and yz planes. That is, the polygon’s area on the yz plane,found by dropping the x-coordinates, is the value for the x-component, on xz the y,and on xy the z. This method of computing an average normal is called Newell’s formula [1505, 1738].

当多边形可能扭曲时,一个快速的纠正措施是将顶点投影到垂直于多边形近似法线的平面上。该平面的法线通常通过计算三个正交xy、xz和yz平面上的投影面积来找到。也就是说,多边形在yz平面上的面积(通过丢弃x坐标得到)是x分量的值,在xz上是y,在xy上是z。这种计算平均法线的方法称为Newell公式[1505,1738]。

The polygon cast onto this plane may still have self-intersection problems, where two or more of its edges cross. More elaborate and computationally expensive methods are then necessary. Zou et al. [1978] discuss previous work based on minimizing surface area or dihedral angles of the resulting tessellation, and present algorithms for optimizing a few non-planar polygons together in a set.

投射到该平面上的多边形可能仍然存在自相交问题,即其两条或多条边相交。因此,需要更复杂、计算量更大的方法。Zou等人[1978]讨论了基于最小化表面面积或所得细分的二面角的先前工作,并提出了用于优化一组中的几个非平面多边形的算法。

Schneider and Eberly [1574], Held [714], O’Rourke [1339], and de Berg et al. [135] each give an overview of a variety of triangulation methods. The most basic triangulation algorithm is to examine each line segment between any two given points on a polygon and see if it intersects or overlaps any edge of the polygon. If it does, the line segment cannot be used to split the polygon, so we examine the next possible pair of points. Else, split the polygon into two parts using this segment and triangulate these new polygons by the same method. This method is extremely slow, at O(n3).

Schneider和Eberly [1574]、Held [714]、O'Rourke [1339]和de Berg等人[135]分别概述了各种三角测量方法。最基本的三角剖分算法是检查多边形上任意两点之间的每条线段,并查看它是否与多边形的任何边相交或重叠。如果是这样,线段就不能用来分割多边形,所以我们检查下一对可能的点。否则,使用此线段将多边形分割成两部分,并用相同的方法对这些新多边形进行三角剖分。这种方法非常慢,为O(n3)。

A more efficient method is ear clipping, which is O(n2) when done as two processes.First, a pass is made over the polygon to find the ears, that is, to look at all triangles with vertex indices i, (i+1), (i+2) (modulo n) and check if the line segment i, (i+2) does not intersect any polygon edges. If it does not, then triangle (i + 1) forms an ear. See Figure 16.3. Each ear available is removed from the polygon in turn, and the triangles at vertices i and (i + 2) are reexamined to see if they are now ears or not. Eventually all ears are removed and the polygon is triangulated. Other, more complex methods of triangulation are O(n log n) and some are effectively O(n) for typical cases. Pseudocode for ear clipping and other, faster triangulation methods is given by Schneider and Eberly [1574].

一种更有效的方法是耳朵剪裁,当作为两个过程进行时,它是O(n2)。首先,对多边形进行遍历以找到耳朵,即查看顶点索引为I、(i+1)、(i+2)(模n)的所有三角形,并检查线段I、(i+2)是否不与任何多边形边相交。如果不是,那么三角形(i + 1)形成一个耳朵。参见图16.3。依次从多边形中移除每个可用的耳朵,并重新检查顶点I和(i + 2)处的三角形,以查看它们现在是否是耳朵。最终,所有的耳朵都被移除,多边形被三角化。其他更复杂的三角剖分方法是O(n log n ),对于典型情况,一些方法是有效的O(n)。Schneider和Eberly [1574]给出了耳朵剪裁和其他更快的三角测量方法的伪代码。

Figure 16.3. Ear clipping. A polygon with potential ears at v2, v4, and v5 shown. On the right, the ear at v4 is removed. The neighboring vertices v3 and v5 are reexamined to see if they now form ears; v5 does. 

图16.3。剪耳朵。显示了在v2、v4和v5处有潜在耳朵的多边形。在右侧,v4处的耳朵被移除。相邻顶点v3和v5被重新检查以查看它们现在是否形成耳朵;v5有。

Rather than triangulating, partitioning a polygon into convex regions can be more efficient, both in storage and further computation costs. Code for a robust convexity test is given by Schorn and Fisher [1576]. Convex polygons can easily be represented by fans or strips of triangles, as discussed in Section 16.4. Some concave polygons can be treated as fans (such polygons are called star-shaped), but detecting these requires more work [1339, 1444]. Schneider and Eberly [1574] give two convex partitioning methods, a quick and dirty method and an optimal one.

与三角剖分相比,将多边形分割成凸区域在存储和进一步的计算成本方面更有效。Schorn和Fisher [1576]给出了稳健凸性检验的代码。凸多边形可以很容易地用扇形或三角形带来表示,如16.4节所讨论的。一些凹多边形可以被视为扇形(这种多边形被称为星形),但检测这些需要更多的工作[1339,1444]。Schneider和Eberly [1574]给出了两种凸划分方法,一种是快速的脏方法,另一种是最优方法。

Polygons are not always made of a single outline. Figure 16.4 shows a polygon made of three outlines, also called loops or contours. Such descriptions can always be converted to a single-outline polygon by carefully generating join edges (also called keyholed or bridge edges) between loops. Eberly [403] discusses how to find the mutually visible vertices that define such edges. This conversion process can also be reversed to retrieve the separate loops.

多边形并不总是由单一轮廓组成。图16.4显示了一个由三个轮廓组成的多边形,也称为环或等高线。通过仔细生成循环之间的连接边(也称为锁眼边或桥边),此类描述始终可以转换为单轮廓多边形。Eberly [403]讨论了如何找到定义这些边的相互可见的顶点。这个转换过程也可以反过来检索单独的循环。

Figure 16.4. A polygon with three outlines converted to a single-outline polygon. Join edges are shown in red. Blue arrows inside the polygon show the order in which vertices are visited to make a single loop. 

图16.4。有三条轮廓线的多边形转换为单轮廓线的多边形。接合边显示为红色。多边形内部的蓝色箭头显示了访问顶点以形成单个循环的顺序。

Writing a robust and general triangulator is a difficult undertaking. Various subtle bugs, pathological cases, and precision problems make foolproof code surprisingly tricky to create. One way to finesse the triangulation problem is to use the graphics accelerator itself to directly render a complex polygon. The polygon is rendered as a triangle fan to the stencil buffer. By doing so, the areas that should be filled are drawn an odd number of times, the concavities and holes drawn an even number. By using the invert mode for the stencil buffer, only the filled areas are marked at the end of this first pass. See Figure 16.5. In the second pass the triangle fan is rendered again,using the stencil buffer to allow only the filled area to be drawn. This method can even be used to render polygons with multiple outlines by drawing the triangles formed by every loop. The major drawbacks are that each polygon has to be rendered using two passes and the stencil buffer clears every frame, and that the depth buffer cannot be used directly. The technique can be useful for display of some user interactions, such as showing the interior of a complex selection area drawn on the fly.

编写一个健壮的通用三角测量程序是一件困难的事情。各种微妙的错误、病理情况和精度问题使得创建万无一失的代码异常棘手。解决三角剖分问题的一种方法是使用图形加速器本身来直接渲染复杂的多边形。多边形在模具缓冲区中呈现为一个三角形扇形。通过这样做,应该填充的区域被绘制奇数次,凹面和孔被绘制偶数次。通过对模板缓冲区使用反转模式,在第一遍结束时只标记填充区域。参见图16.5。在第二遍中,再次渲染三角形扇形,使用模板缓冲区只允许绘制填充区域。这种方法甚至可以通过绘制每个循环形成的三角形来渲染具有多个轮廓的多边形。主要的缺点是每个多边形必须使用两次渲染,模板缓冲区清除每一帧,深度缓冲区不能直接使用。该技术对于显示一些用户交互很有用,比如显示动态绘制的复杂选择区域的内部。

Figure 16.5. Triangulation by rasterization, using odd/even parity for what area is visible. The polygon on the left is drawn into the stencil buffer as a fan of three triangles from vertex 0. The first triangle [0, 1, 2] (middle left) fills in its area, including space outside the polygon. Triangle [0, 2, 3] (middle right) fills its area, changing the parity of areas A and B to an even number of draws, thus making them empty. Triangle [0, 3, 4] (right) fills in the rest of the polygon. 

图16.5。通过光栅化进行三角测量,对可见区域使用奇偶校验。左边的多边形被绘制到模板缓冲区中,作为从顶点0开始的三个三角形的扇形。第一个三角形[0,1,2](左中)填充其区域,包括多边形外部的空间。三角形[0,2,3](中右)填充其区域,将区域A和B的奇偶性改为偶数个平局,从而使其为空。三角形[0,3,4](右)填充多边形的其余部分。

猜你喜欢

转载自blog.csdn.net/m0_37609239/article/details/126966303