Home > 未分类 > Terrain Geomorphing in the Vertex Shader 译文(3)

Terrain Geomorphing in the Vertex Shader 译文(3)

Terrain Geomorphing in the Vertex Shader(3)

Materials

材质

Until now our terrain has no shading or materials yet. Applying dynamic light by using surface normals would be the easiest way to go, but would result in strange effects when patches switched tessellation levels. The reduction of vertices goes hand in hand with the loss of equal number of normals. When a normal is removed the resulting diffuse color value is removed too. The user notices such changes very easily – especially if the removed normal produced a color value which was very different from its neighboring color values.

到现在为止,我们的地形还没有被赋予任何阴影和材质。利用表面法向量赋予动态光照是最简单的方法,但是当缀片在不同级别之间切换的时候将产生奇怪的效果。顶点的减少将同时引起相同数量的法向量减少。当一个法向量被移走时,依赖于它的散射光也被移除。用户将很容易观察到这些变化,尤其是移除的法向量产生一个与它的邻近部分颜色很不一致的颜色时。

The solution to this problem is easy and well known in today’s computer graphics community. Instead of doing real time lighting we can use a pre-calculated lightmap which is by its nature more resistant to vertex removal than per-vertex lighting. Besides solving our tessellation problem, it provides us with the possibility to pre-calculate shadows into the lightmap. The disadvantage of using lightmaps is that the light’s position is now fixed to the position that was used during the lightmap’s generation.

解决该问题的方法很简单,在当前计算机图形领域也非常著名。与计算实时光照不同,我们可以预先计算出一张光照图。与逐顶点光照计算相比,这将更能够抵御顶点移除的影响。除了解决我们的镶嵌级别问题,它也使得我们能够事先将阴影计算到光照图中去。其缺点是,使用的光照图在成图时就已固定了光源的位置。

In order to apply a lightmap (see Figure 4) we need to add texture coordinates to the vertices. Since there is only one lightmap which is used for the whole terrain, it simply spans the texture coordinates from (0,0) to (1,1).

为了应用光照图(图4),我们需要将其纹理坐标赋予顶点。因为对于整个地形只有一个光照图,因此纹理坐标简单地跨度(00)到(11)。

 

4a

 

4b

Figure 4a: Lit terrain

 

Figure 4b: Same terrain with wireframe overlay

 

Now that the terrain’s mesh is set up and shaded, it’s time to apply some materials. In contrast to the lightmap we need far more detail for materials such as grass, mud or stone to look good. The texture won’t be large enough to cover the complete landscape and look good, regardless of how high the resolution of a texture might be. For example if we stretch one texture of grass over a complete terrain one wouldn’t even recognize the grass. One way to overcome this problem is to repeat material textures.

现在我们已经建立了地形网格和阴影,该应用纹理了。与光照图相比,我们需要更具细节的纹理贴图来使得如草、泥地和石头等看起来更好。贴图不能覆盖整个场景,无论它的分辨率多高。比如,如果我们将一张草的纹理贴图放到整个地形上,那几乎就认不出来那是草了。一种解决办法是重复贴图。

To achieve this we scale and wrap the texture so that it is repeated over the terrain. Setting a texture matrix we can use the same texture coordinates for the materials as for the lightmap. As we will see later this one set of (never changing) texture coordinates together with some texture matrices is sufficient for an arbitrary number of materials (each one having its own scaling factor and/or rotation) and even for moving faked cloud shadows (see below).

我们缩放和包裹贴图,使得它在整个地形上重复。设置纹理矩阵时我们可以用与光照图材质同样的坐标。我们即将看到,这个(从不用改变的)纹理坐标集合与一些纹理矩阵一起对于任意数量的材质(每一个都具有自己的缩放/旋转因子)都是有效的,甚至用于产生伪云影。

To combine a material with the lightmap two texture stages are set up using modulation (component wise multiplication). The result is written into the graphics buffer. In order to use more than one material, each material is combined with a different lightmap containing a different alpha channel. Although this would allow each material to use different color values for the lightmap too, in practice this makes hardly any sense. This results in one render pass per material which is alpha blended into the frame buffer. As we will see later a lot of fillrate can be saved if not every patch uses every material – which is the usual case (see section Optimization). Figure 5 shows how two materials are combined with lightmaps and then blended using an alpha map. (For better visualization the materials’ textures are not repeated in Figure 5)

为了组合材质和光照图,两个纹理需要进行调制(分部叠加)。其结果将写入图形缓存。为了能够使用多个材质,每个材质都与含有不同alpha通道的光照图进行组合。尽管这样也允许不同的材质为光照图使用不同的颜色,在实际应用中这几乎行不通。这使得对每个材质有一个alpha混合到帧缓存的渲染通道。我们将看到,如果不是每个缀片使用一个材质(通常的情况正是如此,见优化部分),将减少许多开销。图5显示了两个材质和光照图的组合,并通过alpha图进行混合。(为了视觉效果,图5中未重复材质的纹理贴图)。

 

5

Figure 5: Combining two render passes

 

In the top row of Figure 5 the base material is combined with the base lightmap. Since there is nothing to be drawn before this pass, no alphamap is needed. In the bottom row the second pass is combined with another lightmap. This time there is an alpha channel (invisible parts are drawn with checker boxes). The resulting image is finally alpha-blended to the first pass (right image in Figure 5).

5上,基础材质和基础光照图组合到一起。因为在这个通道之前没有任何绘图,因此不需要alpha图。图5下,第二通道与另一个光照图组合。这里采用了alpha通道(框图中的不可见部分)。其结果最终被alpha混合到第一通道上。(图5右)

It is important to note that this method allows each material pass to use a free scaling (repeating) factor for the color values which results in highly detailed materials while the lightmap does not need to be repeated since lighting values do not need as much detail. Only two texture stages are used at once, which allows combining an arbitrary number of passes. Most applications will not need more than three or four materials.

应当注意到,该方法允许每个材质通道使用任意的缩放(重复)因子计算颜色值,因而可以在不重复光照图的情况下达到较高的材质分辨率,因为光照图细节要求较低。在同一时刻只使用2个纹理进程,因此允许组合任意数量的通道。大多数应用程序都不会使用超过三到四种材质。

After all materials have been rendered, another pass can be drawn in order to simulate cloud shadows. Again we can repeat the shadows in order to get more detailed looking shadows. As we are already using a texture matrix to do scaling, we can animate the clouds easily by applying velocity to the matrix’s translation values. The effect is that the clouds’ shadows move along the surface which makes the whole scene looking far more realistic and "alive".

当所有的材质都被渲染,可另用一通道模拟云影。同前面一样,我们可以重复阴影,达到较好的视觉细节感。因为我们已经使用纹理矩阵来做缩放,因此很容易通过将速度赋予矩阵的平移分量来实现云影的动画效果。云影在地形表面的运动使得整个场景看起来更加真实和活泼。

<-未完待续->

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: