本文介绍了将多个纹理图像融合到3D地面上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

计算机游戏如何发挥作用?我将对几何图形使用高度图(尽管稍后将对其进行优化),但我想知道例如绘制"我的地面的最佳技术是什么?到处都是草,到处都是土路,城镇内的砾石,每种材料之间的平滑过渡.

How do computer games render their ground? I will be using a heightmap for geometry (though I will later optimize it) but I am wondering what the best technique is, for example, to 'paint' my ground; grass most everywhere, dirt paths here and there, gravel inside towns, and smooth transitions between each type of material.

我是否仅使用巨大的预烘焙纹理?当我可以平铺现有纹理时,这似乎效率很低.那么,对于每个现有纹理,我是否都使用巨大的Alpha贴图?从理论上讲,这对我来说还可以,但是我实际上将如何去做,其后果是什么?我真的不知道从哪里开始,而且我的Google搜索也不是很有效.

Do I just use a huge pre-baked texture? That seems very inefficient, when I could tile existing textures. So then do I use a huge alpha map for each existing texture? In theory it sounds okay to me but how do I actually go about doing that and what are the consequences? I really don't know where to start, and my Google searches aren't proving very effective.

我宁愿不必将纹理捕捉"到网格(即,空间(0,0)是草,空间(0,2)是尘土,空间(0,1)是草脏过渡) ;我宁愿能够随意绘画,以使其看起来更具说服力.当然,这将是简单的方法,但是在图形质量和真实感"方面却是一个很大的牺牲.

I'd rather not have to 'snap' the texture to the grid (i.e. space (0,0) is grass, space (0,2) is dirt, space (0,1) is grass-dirt transition); I'd rather be able to arbitrarily paint so that it looks more convincing. Of course that would be the easy way but it's too much of a sacrifice in graphics quality and 'realism'.

我主要是在这里寻找理论和选择.我正在使用OpenGL,因此,如果您能提供有关OpenGL的工作方式以及我可能从未听说过的功能的提示,那将是很棒的.

I'm mostly just looking for theory and options here. I'm using OpenGL so if you can provide tips as far as OpenGL's way of doing things, and functions that I may never have heard of, that would be great.

为澄清起见,《遗忘》是我所要寻找的很好的参考.我不知道地面的几何形状如何(高度图,静态3D模型等),但是它们的地形具有不同的地面类型以及它们之间的平滑过渡,就像我所说的那样.这是一个示例图像,请注意,鹅卵石如何不切实际但平滑地融合到草中: http://www.elitistsnob.com/images/Oblivion%202006-05-21%2008-38-25-15.jpg

Just for clarification, Oblivion is a good reference as to what I'm looking for. I don't know how the ground's geometry is (heightmap, static 3D models, etc) but their terrain has different ground types and smooth transitions between them, like I'm talking about. Here's an example image, notice how the cobblestone blends into the grass, unrealistically but smoothly: http://www.elitistsnob.com/images/Oblivion%202006-05-21%2008-38-25-15.jpg

我想我也从《 Game Programming Gems》一书中读到了有关此内容的信息,但是当时我并没有对此特别注意,现在是夏天,我无法进入大学的图书馆进行检查!我现在正在寻找目录,如果找到它将会进行编辑,但是直到八月中旬我仍然无法阅读.

Also I think I read about this in one of the Game Programming Gems books, but I didn't pay much attention to it at the time, and now that it's summer I don't have access to my university's library to check! I'm looking for tables of contents right now and will edit if I find it, but I will still not be able to read it until mid August.

啊,游戏编程宝石7的标题为为户外地形渲染映射大纹理"的第5.8章,听起来确实是我所需要的,但是我的U图书馆甚至没有那本书!在其他《 Game Programming Gems》一书中,我找不到任何完全像这样的东西,尽管有一些关于地形几何的文章.

Ah man, Game Programming Gems 7 has a chapter 5.8 titled "Mapping Large Textures for Outdoor Terrain Rendering", that sounds like exactly what I need, but my U's library doesn't even have that book! I couldn't find anything exactly like this in the other Game Programming Gems books, though a couple had some terrain geometry articles.

推荐答案

我最近在OpenGL中编写了一个小型地形渲染引擎,该引擎的功能与您所讨论的类似.最好将我使用的技术描述为纹理喷涂.

I have recently written a small terrain rendering engine in OpenGL that does something similar to what you are talking about. The technique I use is best described as texture splatting.

我使用五个纹理来完成此任务.这些纹理中的四个是细节纹理:草,岩石,水和沙子.这些纹理较小,为512x512,并且在整个地形上平铺.第五个纹理是混合贴图.混合贴图是一个覆盖整个地形的巨大纹理,在我的情况下为4096x4096.

I use five textures to accomplish this. Four of these textures are detail textures: grass, rock, water, and sand. These textures are smallish, 512x512 textures, and they are tiled across the terrain. The fifth texture is a mixmap. The mixmap is a giant texture that covers the entire terrain, in my case is 4096x4096.

此混合图使用所有4个颜色通道(r,g,b,a)来描述要在该特定位置显示多少细节纹理.我正在使用红色通道来确定沙子的不透明度,绿色用于草,蓝色用于水,alpha用于岩石.该混合图是在初始化时根据高度图计算得出的,我使用海拔高度来确定这些值.例如,在海平面附近,我主要需要水,因此我在蓝色通道中设置了较高的值,而在其他通道中设置了较低的值.当我爬上高山时,由于需要大量的岩石纹理,因此将Alpha颜色通道设置为较高的值,但我将所有其他颜色通道设置为较低的值.

This mixmap uses all 4 color channels (r,g,b,a) to describe how much of a detail texture to display at that specific location. I am using the red color channel to determine how opaque the sand is, green is for grass, blue is for water, and alpha is for rock. This mixmap is calculated based off of the heightmap at initialization and I use altitudes to determine these values. For instance, close to the sea level, I mostly want water, so I set a high value in the blue channel and low values in the other channels. As I get higher into the mountains, I set the alpha color channel to a high value since I want a lot of rock texture, but I set all of the other color channels to lower values.

然后将这个混合贴图用于片段着色器中,在这里我将使用混合贴图的这些颜色通道,并使用它们来组合细节纹理.这是我用于片段着色器的GLSL代码:

This mixmap is then put to use in the fragment shader, where I take these color channels of the mixmap and use them to combine the detail textures. Here is the GLSL code I am using for the fragment shader:

uniform sampler2D alpha;
uniform sampler2D grass;
uniform sampler2D water;
uniform sampler2D rock;
uniform sampler2D sand;
uniform float texscale;

varying vec3 normal, lightDir ;

void main()
{
   // Get the color information
   vec3 alpha    = texture2D( alpha, gl_TexCoord[0].st ).rgb;
   vec3 texSand  = texture2D( sand, gl_TexCoord[0].st * texscale ).rgb;
   vec3 texGrass = texture2D( grass,  gl_TexCoord[0].st * texscale ).rgb;
   vec3 texWater = texture2D( water, gl_TexCoord[0].st * texscale ).rgb;
   vec3 texRock  = texture2D( rock,  gl_TexCoord[0].st * texscale ).rgb;

   // Mix the colors together
   texSand *= mixmap.r;
   texGrass = mix(texSand,  texGrass, mixmap.g);
   texWater = mix(texGrass, texWater, mixmap.b);
   vec3 tx  = mix(texWater, texRock,  mixmap.a);

   // Lighting calculations
   vec3 dl = gl_LightSource[0].diffuse.rgb;
   vec3 al = gl_LightSource[0].ambient.rgb;
   vec3 n = normalize(normal);
   vec3 d = tx * (dl * max( dot ( n, lightDir), 0.0 ) + al );

   // Apply the lighting to the final color
   vec4 finalColor = vec4( min(d, 1.0), 1.0);
   gl_FragColor = mix(gl_Fog.color, finalColor, fogFactor);
}

均匀texscale是一个值,该值确定在地面上平铺细节纹理的次数.较高的值会使细节纹理看起来更清晰,但有使它们看起来更重复的风险.

The uniform texscale is a value that determines how many times the detail textures are tiled across the terrain. Higher values will make the detail textures look more crisp at the risk of making them look more repetitious.

这篇关于将多个纹理图像融合到3D地面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 15:09