# how to find tile-textures for terrain transitions

This topic is 3982 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hello, i was looking at this article http://www.gamedev.net/reference/articles/article934.asp to implement terrain transistions. but what i did not understand is, how exactly do you find out which tile-texture you need. i know that the edges are stored in 4 bits and that the corners are stored in 4 bits. but that still sums up to 256 ddifferent possible combinations. should i really do a 256 long if () else if () else if () .... else () ? probably not! so what is the way to find out which texture i need for which bitmask of corners and edges?

##### Share on other sites
If you look at their pictures and read carefully you can use something similar to the following to figure out which transitions to use (I find hex easier with binary math):
// direction values
west=0x01;
north=0x02;
east=0x04;
south=0x08;
northwest=0x10;
northeast=0x20;
southeast=0x40;
southwest=0x80;

You would only need 4 ifs for the sides,
if need side then transition |= direction_value

And 4 for the corners
if need corner then transition |= direction_value

If we had east and southwest the hex would look something like 0x84.
If we had all 4 sides and no corners, the hex would look like 0x0f.

If your transition tiles are in an array sides[15] and corners[15] then you choose the tiles to draw by using a binary AND of 0x0f for the sides or 0xf0 along with a right shift for the corners on the final transition you received.

This system works very well if you use something like paint to generate a gray scale height map and allow this algorithm to fill in the transitions. A quick and easy way to generate large maps that aren't random with little effort and then fine tune them in your map editor.

Sorry if this isn't making sense, I am tired and really should have gone to bed and answered in the morning.

##### Share on other sites
thanks!

so that would require two drawing passes per terrain, right?

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633661
• Total Posts
3013220
×