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.

Introduction

绪论

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.

直到今天,地形渲染都是由CPU进行计算、GPUCPU共同完成渲染的。可以实现一种快速地形渲染器,在当前3D图形硬件基础上获得最佳工作性能。通过几何Mipmap,将地形分成一系列小的网格,称为缀片。每个缀片根据当前视图划分三角形,放到一个三角形条带中。须特别注意防止空缺和T-型顶点在相邻的缀片之间出现。可赋予地形任意数量的纹理,通过多Alpha混合渲染通道组合。由于地形的三角网格随时可能改变,不能使用顶点法线作光照处理,而需要使用预生成的光照图。为了减少缀片在不同的镶嵌级别之间切换时发生破裂,这里引入了几何变形。随后将看到,地形的切分中包含了一些非常有用的优化。

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.

长期以来,地形渲染都是一个活跃的研究领域。尽管出现了一些优秀的算法,但由于计算要求高,几乎没有被游戏开发者们实际采用。另一个原因是,对于传统的地形渲染方法如ROAMVDPM等,现代GPU不倾向于使用CPU生成的动态顶点数据。游戏开发者的解决方案是建立非常低分辨率的地图,在地形编排时进行调整以达到视觉优化。与室内场景相比,地形可见度更加难以协调。甚至有游戏关卡设计者选择只显示远景的案例。

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.

已经有许多关于地形网格渲染的工作。经典的算法如ROAMVDPM试图生成一系列能理想地适合地形的三角形,地形通过高度图给出。这里的“理想”定义为对给定的品质标准使用尽可能少的三角形。但这是若干年前的目标,如今情况已有改变。

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

<-未完待续->

翻译:食人鬼的臂章

原文地址:http://www.gamedev.net/reference/articles/article1936.asp

原文代码:http://www.gamedev.net/columns/hardcore/geomorph/Terrain_Src.zip

欢迎批评指正!

Advertisements
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 )

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: