Terrain in computer graphics is certainly a hot topic. Since this is a fast growing field and there are many algorithms, this tutorial will always be work in progress. The sections available so far cover terrain generation from an image, computing normals and simulating both directional and positional lights.
在计算机图形学里地形无疑是个热点问题。由于这是一个快速发展的领域并且有很多算法,这个教程将一直视情况而更新。目前为止这个部分的教程将覆盖:从一幅图像生成地形,计算法向量和模拟定向光源、位置光源。
We'll also present a simple image library that will be used to create terrains from an image as well as saving terrains.我们将会提供一个用来从图片生成地形以及保存地形的简单的图形库。
The simplest form of terrain representation is as a regular height field, i.e. considering a regular grid in the plane XZ, with evenly spaced points, a height is attributed to each point. This representation saves a lot of space when storing the terrain because we'll only need the heights, and a reference point in the terrain, for instance the centre point in the plane XZ. Since the grid is evenly spaced we don't need to store both x and z values for each point.地形最简单的表达方式是使用一个高度域,考虑XZ平面上的一个顶点均匀分布的规则的网格,其中每个点都有一个高度属性值。这种表达方式节约了大量的空间当存储地形时,因为我们仅仅需要高度值和一个相关点,例如XZ平面的中心点。由于网格中的点是均匀分布的,我们不需要为这个点存储x z坐标值。
Starting from this premise, we can easily conceive a height map as a greyscale image, where the intensity of each pixel corresponds to a height. The following figures show an image and the corresponding terrain, generated from the height map obtained from the image.基于前述,我们很容易把高度图假想为一个灰度图其中每个像素的强度对应于高度值。下面的图像展示了图片和对应的从高度图得到的地形,这个高度是从图片获得来的。
The opposite route is also possible, i.e. form a terrain, and its height map, it is possible to create a greyscale image, where each pixel's intensity corresponds to a relative height.
相反的过程也是可能的,即从地形和高度图得到灰度图,其中每个像素的强度对应于相对高度。
There are also lots of algorithms to create artificial terrains. The logic behind them is in general quite simple. The image bellow shows a terrain artificially generated by a very simple iterative algorithm. A few of these algorithms will also be presented in here.有很多算法可以用来生成人造地形。他们背后的逻辑一般相对容易。下面的图片显示了从一个迭代算法生成的人造地形。这里将会介绍几个算法。