0

I have no problem with manipulating the mesh itself,but each tile(which is basically a square of 4 vertices and the whole terrain mesh is made of a grid of tiles)has to be able to be given a different texture of my choosing.So far I can only give the mesh 1 texture and make it repeat itself by changing the UV values of the CUSTOMVERTEX-es in the vertex buffer.I can't however make different tile textures like here:http://classic.battle.net/war3/images/neutral/heroes/ss02.jpg -you can see that there are grass tiles and some dirt tiles on the side and some gravel to the left.

I had the stupid idea of making each tile a seperate mesh,but that was just..heavier and the textures didnt clamp well.I'm sure there has to be some function to let me texture seperate squares of the terrainmesh :(

tshepang
  • 12,111
  • 21
  • 91
  • 136
none
  • 39
  • 1
  • 3

1 Answers1

1

One way of doing it is to use an alpha map to define which texture goes where on the terrain. Usually you bind 4 or more textures to a shader and the use another texture and it's rgba components to define where textures should appear.

Let's say you have grass, dirt, sand and snow and an alpha map texture. The red component controls the grass visibility, green component controls dirt, blue component controls sand and alpha component controls snow.

In the pixel shader you read from the alphamap and then using the values in the rgba components you mix from the grass,sand,dirt snow textures.

Some pseudo code:

float4 mix = sampler.read(alphaTexture,alphaTexCoord);
float4 finalColor = sampler.read(grassTexture,texCoord) * mix.r + 
                    sampler.read(dirtTexture,texCoord) * mix.g + 
                    sampler.read(sandTexture,texCoord) * mix.b + 
                    sampler.read(snowTexture,texCoord) * mix.a; 

As you can see if in the alpha map you have a color value of 0,0,1,0 that fragment will be sand and so on.

The terrain in this video is textured by this technique : http://www.youtube.com/watch?v=-mBpMYYtJCo

You can use 8 textures and 2 alpha maps too.

Hope that helps.

Barış Uşaklı
  • 13,440
  • 7
  • 40
  • 66