Home > 未分类 > Terrain Geomorphing in the Vertex Shader( 4)

Terrain Geomorphing in the Vertex Shader( 4)

Geo-morphing

几何变形

One problem with geometry management using level of detail is that at some point in time vertices will have to be removed or added, which leads to the already described "popping" effect. In our case of geo-mipmapping, where the number of vertices is doubled or halved at each tessellation level change, this popping becomes very visible. In order to reduce the popping effect geo-morphing is introduced. The aim of geo-morphing is to move (morph) vertices softly into their position in the next level before that next level is activated. If this is done perfectly no popping but only slightly moving vertices are observed by the user. Although this vertex moving looks a little bit strange if a very low detailed terrain mesh is used, it is still less annoying to the user than the popping effect.

使用LOD管理几何构造的一个问题是:需要实时添加或删除一些顶点,这将导致前面所说的“破裂”现象。在如本文所述的这种几何MipMap中,镶嵌级别改变时顶点数量将加倍或者减半,因此破裂现象将非常可观。为了减轻破裂现象我们引入了几何变形。几何变形的目的是在一个级别被激活之前,将顶点从前一个级别平缓地移动(morph)到它们在另一级别中的位置。如果该过程能够较好地完成,则不会出现破裂现象,而用户仅有可能观察到顶点的一些轻微移动。尽管在使用细节非常粗糙的地形网格时变形效果看起来会有点奇怪,但仍然要好于破裂现象。

It can be shown that only vertices which have odd indices inside a patch have to move and that those vertices on even positions can stay fixed because they are not removed when switching the next coarser tessellation level. Figure 6a shows the tessellation of a patch in tessellation level 2 from a top view. Figure 6b shows the next level of tessellation coarseness (level 3). Looking at Figure 6b it becomes obvious that the vertices ‘1’, ‘2’ and ‘3’ do not have to move since they are still there in the next level. There are three possible cases, in which a vertex has to move:

可以证明,只有在缀片中具有奇数号的顶点需要被移除,而偶数号的顶点在转换到下一个较粗糙的镶嵌等级时将固定不变。图6a显示了镶嵌等级为2的缀片的顶视图。图6b显示了下一个较粗糙的等级(等级3)。观察图6b可以清楚地看到,顶点‘1’、‘2’、‘3’不需要移动,在该等级中保持不变。需要移动的顶点存在三种可能情况:

  • Case ‘A’: The vertex is on an odd x- and even y-position.
    This vertex has to move into the middle position between the next left (‘1’) and the right (‘2’) vertices.
  • Case ‘B’: The vertex is on an odd x- and odd y-position.
    This vertex has to move into the middle position between the next top-left (‘1’) and the bottom-right (‘3’) vertices.
  • Case ‘C’: The vertex is on an even x- and odd y-position.
    This vertex has to move into the middle position between the next top (‘2’) and the bottom (‘3’) vertices.
  • A’情形:顶点在X方向索引号为奇数,y方向为偶数:该顶点将移动到下一级的左(‘1’)和右(‘2’)点的中点
  • B’情形:顶点在X方向为奇数,y方向也为奇数:该顶点将移动到下一级的左上(‘1’)和右下(‘3’)点的中点
  • C’情形:顶点在X方向为偶数,y方向为偶数:该顶点将移动到下一级的上(‘2’)和下(‘3’)点的中点

Things become much clearer when taking a look at the result of the morphing process: after the morphing is done the patch is re-tessallated using the next tessellation level. Looking at Figure 6b it becomes obvious that the previously existing vertex ‘A’ had to move into the average middle position between the vertices ‘1’ and ‘2’ in order to be removed without popping.

下面清楚地显示了变形之后,缀片被新等级重新镶嵌的情形。图6b中,原有的顶点‘A’被逐渐移动到‘1’、‘2’的中点,在没有破裂的前提下达到了移除顶点的效果。

 

6a

 

6b

Figure 6a: Fine geometry with morphing vertices

 

Figure 6b: Corresponding coarser tessellation level. Only odd indexed vertices were removed

 

Optimizations

优化

Although the geometry’s creation is very fast and we are rendering the mesh using only a small number of long triangle strips (usually about some hundred strips per frame), there are quite a lot of optimizations we can do to increase the performance on the side of the processor as well as the graphics card.

尽管地形的生成非常快,在渲染时也仅用了网格的少量长三角形带(一般每帧数百带),但从处理器和图形卡的角度仍然可以通过许多优化来提高性能。

As described in the section "Materials" we use a multi-pass rendering approach to apply more than one material to the ground. In the common case most materials will be used only in small parts of the landscape and be invisible in most others. The alpha-channel of the material’s lightmap defines where which material is visible. Of course it’s a waste of GPU bandwidth to render materials on patches which don’t use that material all together (where the material’s alpha channel is completely zero in the corresponding patch’s part).

在“材质”一节我们已经讨论了使用多通道渲染来赋予地面不止一种材质。在一般情况下,大多数材质只用于地形的小部分,而在其他大部分地区不可见。材质光照图的Alpha通道定义了材质的可见部分。显然在不需要该材质的缀片上(该材质在此缀片上的Alpha通道全部为0)也一起渲染该材质浪费了GPU的带宽。

It’s easy to see, that if the part of a material’s alpha-channel which covers one distinct patch is completely set to zero, then this patch does not need to be rendered with that material. Assuming that the materials’ alpha channels won’t change during runtime we can calculate for each patch which materials will be visible and which won’t in a pre-processing step. Later at runtime, only those passes are rendered, which really contribute to the final image.

显而易见,如果一个缀片上某材质的Alpha通道被设为全0,则在该缀片上不需要渲染此材质。假设材质的Alpha通道在运行过程中不发生改变,则我们可以在预处理阶段计算对于每一个缀片哪些材质可见并在运行时只渲染实际可见的材质。

Another important optimization is to reduce the number of patches which need to be rendered at all. This is done in three steps. First a rectangle which covers the projection of the viewing frustum onto the ground plane is calculated. All patches outside that rectangle will surely not be visible. All remaining patches are culled against the viewing frustum. To do this we clip the patches’ bounding boxes against all six sides of the viewing frustum. All remaining patches are guaranteed to lie at least partially inside the camera’s visible area. Nevertheless, not all of these remaining patches will necessarily be visible, because some of them will probably be hidden from other patches (e.g. a mountain). To optimize this case we can finally use a PVS (Potentially Visible Sets) algorithm to further reduce the number of patches needed to be rendered.

另一重要的优化是:从根本上减少需要渲染的缀数量。这通过3个步骤来实现。首先计算一个包含了视见体在地形上的投影的矩形,该矩形外所有缀片为不可见。剩下的缀片通过视见体进行剔除。我们用视见体的六个面去剪裁缀片的包围盒。确保所有留下的缀片都至少有一部分位于摄像机的可见区域内部。但是,这不保证它们都可见,因为有些可能被其他缀片遮挡(如一座山)。为了继续优化,我们最终使用了PVSPotentially Visible Sets,潜在可见集合)算法来进一步减少需要渲染得缀片数量。

PVS [Air91, Tel91] is used to determine, at runtime, which patches can be seen from a given position and which are hidden by other objects (in our case also patches). Depending on the type of landscape and the viewers position a lot of patches can be removed this way. In Figure 7 the camera is placed in a valley and looks at a hill.

PVS[Air91, Tel91]被用于在运行时确定哪些缀片可见,哪些被其他物体(在此即其他缀片)遮挡。根据地形特征和观察点位置,可以移除许多缀片。在图7中,摄像机位于山谷而朝向一座山。

 

7a

 

7b

 

7c

Figure 7a: Final Image

 

Figure 7b: Without PVS

 

Figure 7c: With PVS

 

Figure 7b shows that a lot of triangles are rendered which do not contribute to the final image, because they are hidden by the front triangles forming the hill. Figure 7c shows how PVS can successfully remove most of those triangles. The nice thing about PVS is that the cost of processing power is almost zero at runtime because most calculations are done offline when the terrain is designed.

7b显示大量对最终图形没有贡献的三角形被渲染,因为它们被前部组成山的三角形所遮挡。图7c显示PVS成功地移除了大量三角形。PVS的一个优点在于,它在运行时几乎不占用任何处理能力。因为大部分计算在地形设计时就已经完成。

In order to (pre-) calculate a PVS the area of interest is divided into smaller parts. In our case it is obvious to use the patches for those parts. For example a landscape consisting of 16×16 patches requires 16×16 cells on the ground plane (z=0). To allow the camera to move up and down, it is necessary to have several layers of such cells. Tests have shown that 32 layers in a range of three times the height of the landscape are enough for fine graded PVS usage.

为了预先计算PVS,我们将计算区域划分为小部分。在本例中显然就使用缀片作为这些部分。例如,一个由16*16个缀片组成的地形需要在地平面(z=0)上建立16*16个单元。为了允许摄像机上下移动,需要若干层这样的单元。测试表明,在高程的3倍范围内,32层就已能实现较好的PVS了。

One problem with PVS is the large amount of memory needed to store all the visibility data. In a landscape with 16×16 patches and 32 layers of PVS data we get 8192 PVS cells. For each cell we have to store which of all the 16×16 patches are visible from that cell. This means that we have to store more than two million values. Fortunately we only need to store one bit values (visible/not visible) and can save the PVS as a bit field which results in a 256Kbyte data file in this example case.

PVS的缺点是:需要大量的存储空间来储存可视性数据。一个16*16个缀片组成、32层的PVS数据我们将有8192PVS单元,对于每个单元,我们又存储了关于16*16个缀片在当前单元是否可见的信息。最终我们需要存储超过2000000个数据。所幸的是我们只需要存储比特数据(可见/不可见),因此上述实例中的数据可存储在256Kb的空间中。

 

7d

Figure 8: PVS from Top View. Camera sits in the valley in the middle of the green dots

 

Figure 8 shows an example image from the PVS calculation application where the camera is located in the center of the valley (black part in the middle of the green dots). All red dots resemble those patches, which are not visible from that location. Determining whether a patch is visible from a location is done by using an LOS (line of sight) algorithm which tracks a line from the viewer’s position to the patch’s position. If the line does not hit the landscape on its way to the patch then this patch is visible from that location.

8显示了PVS计算的一个例子。摄像机位于山谷中央(中间的黑色、绿点部分)。红点表示从摄像机点不可见的位置。判断一个缀片是否可见采用了LOSLine of sight,视线)算法。它从观察者所在位置跟踪一条线到缀片所在位置。如果该线在途中没有碰撞到地面,则该缀片可见。

To optimize memory requirements the renderer distinguishes between patches which are active (currently visible) and those which aren’t. Only those patches which are currently active are fully resident in memory. The memory footprint of inactive patches is rather low (about 200 bytes per patch).

为了优化存储,渲染器将区分活动(当前可见)和不活动的缀片。只有当前活动的缀片才完全进驻内存。不活动的缀片内存占用非常低(每个约200byte)。

<-未完待续->

Advertisements
Categories: 未分类
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: