Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Alright so I have my code to draw out a big landscape using C++ and DirectX. I had it textured with one texture and then needed to add more. I saw people doing it where they had 1 texture image and the image contained 2 textures. Thats what I made, it's a 256x128 image. My problem now is that since my terrain automatically generated the coordinates to UV map 1 texture now it is displaying both textures. I need to make it so when the height of the world is high enough it is 1 texture and everything under is another texture. My code for the UV coordinates,

Vertices[y * WIDTH * x].U = x / 1.28;

Vertices[y * WIDTH * x].V = y / 1.28;

those are my mapping coordinates, X is the current X value of the vertice it is drawing and the Y value is its current y position. The heightmap is 128x128 so I divided by 1.28 to make it so that each polygon had the texture UV mapped on it. The height is calculated as well since I am loading a heightmap and im trying to get it so when it is high enough it UV maps 1 half of the image and if it is the other it UV maps the other side of the image. Someone please help!

share|improve this question
I went through Atlas maps and so on for a game I made, you might find some useful info here: irrlicht.sourceforge.net/forum/viewtopic.php?f=6&t=33235 –  Valmond Aug 18 '12 at 22:06
add comment

1 Answer

up vote 1 down vote accepted

The texture you described with two textures packed in one is called a texture atlas. That can be useful for certain things, but I don't think it's an appropriate choice in this case, because as you found out, it breaks tiling.

What you probably want is called multi-texturing or texture splatting (those are some good terms to google). This involves setting up two separate texture objects and binding them both when you want to draw your terrain, then using a shader that samples both textures and blends between them based on height (or some other factor, such as vertex color).

Which version of Direct3D are you using, and how much experience with shaders do you have? Based on that, I might be able to give you some more specific help. I'm not very familiar with Direct3D 9 and below, though.

share|improve this answer
+1 Just some precisions, it would most probably be multi-texturing AND texture splatting (you need at least 1 texture as look-up and 2 for say grass and stone for example) OR use multi textures and a sort of height-of-vertex (or other like say perlin noise in some sort of way). 2)Watch out for filtering problems for the 'look-up' texture as that can cause tiling to be visible too (there are plenty of information on google as Nathan Reed points out). You might want too look up triplanar mapping which is dead useful too) –  Valmond Aug 18 '12 at 22:05
Okay I will try to do it that way, but I am not very good with shaders so I would have to try that code. –  dvds414 Aug 19 '12 at 3:17
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.