# Connecting smoothly N textures on terrain

I started to create my own terrain in a quite common way, just like this: http://www.rastertek.com/tertut18.html . It is infinite and automatically generated (by using coherent noise). The areas are determined by using Voronoi noise (http://www.ctvisualeffects.com/renderman/maya_pattern_animation/cellnoise.jpg .

I am using triangle list with shared vertices. I'd like to create areas textured differently that are connected smoothly with each other. I came up with something like giving every vertex the texture id, e.g.:

0 - grass
1 - snow
2 - sand


I was thinking about sending the texture ids (the 0, 1, 2) to the shader in the TEXCOORD semantic (the z value), however I have no further idea on how to use them there to actually blend the textures smoothly.

Could you give me any hints, please? I'd be really grateful.

// EDIT

I ended up giving each vertex weights of each texture. But this is completely not generic solution and quite heavy as I have to change vertex structure when adding another area which has another texture.

• Won't terrain blend maps work better for you? m4x0r.com/blog/2010/05/blending-terrain-textures . You essentially need your grass, snow, sand textures and another special purpose texture containing the weight/influence of each detail texture for the current pixel. The weights are stored in separate RGBA channels (hence 4 detail textures use one blend map). – teodron Aug 24 '13 at 9:36
• And yeah, possible duplicate of other questions (e.g. gamedev.stackexchange.com/questions/12767/… ) – teodron Aug 24 '13 at 9:39
• @teodron Actually I think it would be hard to apply it to my situation. My terrain is unlimited and automatically generated (while moving) using perlin noise. I would need to determine whether it is blending from right to left, left to right, bottom to top and so on (there are a lot of cases unfortunately), since you cannot create one universal alpha map that fits all of the directions. Or maybe I have weak knowledge about it and don't see the correct way of doing this. – tobi Aug 24 '13 at 11:13
• you should mention this in your question (your terrain is generated on the fly and is infinite). You can still use the same approach while having only one texture mapping (TEXCOORD uv set) for all textures. The blend weights can be given by associating different textures (snow, grass, sand) with different height intervals (something on these lines gamedev.stackexchange.com/questions/13819/… ). Is this cutting it for you? – teodron Aug 24 '13 at 12:04
• @teodron Ok, I've edited the question. I have seen that topic and I was thinking abou 3D texture, but assuming we have gradient water->sand->grass. How do you blend water and grass? You need another gradient water->grass->sand and so on, and this makes it more complicated. – tobi Aug 24 '13 at 12:18