Home > 计算机与 Internet > Terrain Geomorphing in the Vertex Shader 译文(1)

Terrain Geomorphing in the Vertex Shader 译文(1)

Terrain Geomorphing in the Vertex Shader

by Daniel Wagner
April 20th 2003

关键词:3D 地形 顶点着色器 几何变形

The following article is an excerpt from ShaderX2 – Shader Programming Tips and Tricks, published by Wordware presumably in August 2003 (see http://www.shaderx2.com/ for more information).

Get the source code for this article here.



Terrain rendering has heretofore been computed by a CPU and rendered by a combination of CPU and GPU. It is possible to implement a fast terrain renderer which works optimally with current 3D hardware. This is done by using geo-mipmapping which splits the terrain into a set of smaller meshes called patches. Each patch is triangulated view-dependently into one single triangle strip. Special care is taken to avoid gaps and t-vertices between neighboring patches. An arbitrary number of textures can be applied to the terrain which are combined using multiple alpha-blended rendering passes. Since the terrain’s triangulation changes over time, vertex normals cannot be used for lighting. Instead a pre-calculated lightmap is used. In order to reduce popping when a patch switches between two tessellation levels geo-morphing is implemented. As will be pointed out later, this splitting of the terrain into small patches allows some very helpful optimizations.


Why geomorphing?


Terrain rendering has been an active research area for quite a long time. Although some impressive algorithms were developed, the game development community has community has rarely used these methods because of the high computational demands. Recently, another reason for not using the classic terrain rendering approaches such as ROAM [Duc97] or VDPM [Hop98] emerged: modern GPUs just don’t like CPU generated dynamic vertex data. The game developers’ solution for this problem was to build very low resolution maps and fine-tuned terrain layout for visibility optimization. In contrast to indoor levels, terrain visibility is more difficult to tune and there are cases where the level designer just wants to show distant views.


The solution to these problems is to introduce some kind of terrain-LOD (level of detail). The problem with simple LOD methods is that at the moment of adding or removing vertices, the mesh is changed which leads to very noticeable popping effects. The only clean way out of this is to introduce geomorphing which inserts new vertices along an existing edge and later on moves that vertex to its final position. As a consequence the terrain mesh is no longer static but changes ("morphs") every frame. It is obvious that this morphing has to be done in hardware in order to achieve a high performance.

解决该问题的办法是引入一种地形LODLevel of detail,细节级别)。简单的LOD方法存在一个问题:当增加或减少顶点时,网格的改变产生可观的破裂效果。解决此问题的唯一途径是引入几何变形,即在现有的边上添加新的顶点,随后将它们移动到最终位置。因此,地形网格不再是静态的,而在每一帧都发生改变(Morphs,变形)。为了达到高的性能,显然这种变形应当在硬件中完成。

Previous Work


A lot of work has already been done on rendering terrain meshes. Classic algorithms such as ROAM and VDPM attempt to generate triangulations which optimally adapt to terrain given as a heightmap. This definition of "optimally" was defined to be as few triangles as possible for a given quality criteria. While this was a desirable aim some years ago, things have changed.


Today the absolute number of triangles is not as important. As of 2003, games such as "Unreal 2" have been released which render up to 200000 triangles per frame. An attractive terrain triangulation takes some 10000 triangles. This means that it is no longer important if we need 10000 or 20000 triangles for the terrain mesh as long as it is done fast enough. Today "fast" also implies using as little CPU processing power as possible since in real life applications the CPU usually has more things to do than just drawing terrain (e.g. AI, physics, voice-over-ip compression, etc…). The other important thing today is to create the mesh in such a way that the graphics hardware can process it quickly, which usually means the creation of long triangle strips. Both requirements are mostly unfulfilled by the classic terrain meshing algorithms.

今天,三角形绝对数量已经不再重要。在2003年发行的游戏“Unreal 2”,每帧渲染得三角形数量达到了200000个。而通常10000个三角形组成的地形就已经很具吸引力了。这意味着只要三角形的运算够快,我们使用1000020000个三角形来做地形网格已不再重要。现在的“快速”同时也意味着应尽量减少CPU处理能力的占用,因为在虚拟现实程序中,CPU常常有更多的任务要做,而不只是绘制地形(例如:人工智能、物理、IP语音压缩等等)。当前另一个重要的问题是,建立网格的方法要能方便图形硬件的快速处理,通常即是建立长的三角形带。而这两种要求在传统的地形网格算法中都无法实现。

The work in this article is based on the idea of geo-mipmapping de Boer by [Boe00]. Another piece of work that uses the idea of splitting the terrain into a fixed set of small tiles is [Sno01], although the author does not write about popping effects or how to efficiently apply materials to the mesh.

本文的工作是基于Boer [Boe00]提出的几何Mip-贴图思想。另一件工作应用了将地形切分为一些确定的小块集合[Sno01]。尽管作者没有提到破裂问题,以及怎样快速将纹理赋予网格。

Building the Mesh


The terrain mesh is created from an 8-bit heightmap which has to be sized 2^n+1 * 2^n+1 (e.g. 17*17, 33*33, 65*65, etc? in order to create n^2 * n^2 quads. The heightmap (see Figure 1a) can be created from real data (e.g. DEM) [Usg86] or by any program which can export into raw 8-bit heightmap data (e.g. Corel Bryce [Cor01]). The number of vertices of a patch changes during rendering (see view-dependent tessellation) which forbids using vertex normals for lighting. Therefore a lightmap (see Figure 1b) is used instead.

地形网格由一个8-Bit高度图建立,其大小应当是2 ^n+1 * 2^n+1(如 17 * 1733*3365*65等,以便建立n^2 * n^2的四边形嵌块)。高度图(图1a)可以根据真实数据建立(如DEM)或者由任意能够输出原始8-Bit高度图数据的程序建立(如Corel Bryce[Cor01])。在渲染过程中,缀片的顶点数量是改变的(参见 依据视图的镶嵌布局),这使得顶点法向量照明处理无法实现,因此需要使用光照图(图1b)。


1a                                1b


Figure 1a: A sample heightmap


Figure 1b: Corresponding lightmap created with Wilbur






Categories: 计算机与 Internet
  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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: