[news] | [about us] | [games] | [current projects] | [contact] |
Starting with v0.5, the terrain engine features a brand-new texture synthesis algorithm that should be pretty flexible. It's not difficult to set up the texturing, though it often requires some tweaking to really look good. This page serves to explain to you how to use this new feature and also a bit of the inner workings of the algorithm. If you have trouble understanding my explanations, (which wouldn't surprise me at all,) there is an example at the end of the page. Enough talk, let's get to the goods.
First you need to tell the engine how many base textures you want to use in your landscape. You can think of every base texture as a kind of terrain, like grass, rock, snow and so on. To do this, you put the following line into the map definition file (.MAP):
numtextures x
The 'x' should obviously be replaced by the number of textures you are intending to use. After that, you are ready to give the engine information about which textures actually to use and where to place them. Each base texture is specified in one line using the following format:
tex.i "texfilename height_inf slope_inf minheight maxheight heightfalloff minslope maxslope slopefalloff"
Where:
i is the number of the current texture, ranging from 1 to the value specified with numtextures. All textures must be defined or the engine will complain.
texfilename is the file name of the texture image. You can use either PCX files or PNG files in 8 bit paletted, 8 bit grayscale or 24 bit RGB format. Note that the filename must be given relative to the the base directory of the engine, and backslashes must be escaped to TWO backslashes (\\), as in C.
height_inf and slope_inf are the influences of height and slope on the placement of this texture. I recommend choosing them in such a way that they are both in the range from 0 to 1 and add together to 1. What this does is the following: the higher the influence value, the more important the respective factor is in deciding where to place the texture. Hence, if height_inf is set to 0, the texture doesn't care about height at all, and if it's set to 1 and slope_inf to 0, it uses only height but not slope for its placement. Of course you can use any value in between.
minheight and maxheight define the optimal height range for this texture. These values range from 0 to 255. Note that the texture is not necessarily limited to the range specified here because there is also the slope that might affect its placement.
heightfalloff is the size of the falloff region at both sides of the height range. The larger this value, the smoother the texture borders will be; if you set it to 0, the texture will have very sharp borders.
minheight, maxheight and slopefalloff do the same thing as their height counterparts, only for slope. Slope is specified in degrees (0-90).
For every texel in the terrain texture, the algorithm performs these steps:
1. Step through all base textures, computing weight for this texture as follows: a) Compute height factor: If the texture is in the specified height range, this is 1, else fade to zero according to the falloff value. Then the factor is multiplied by the height_inf value. b) Compute slope factor in the same manner. c) Add those two factors together. d) Clamp the value to the range [0;1]. d) Finally, square the resulting value to increase contrast a bit. 2. Get the sum of all the texture weights and divide them by it so that the weights sum up to 1. 3. Use the weights to blend the base textures together. 4. Use the light direction vector and the terrain normal to light the resulting texel.
Sometimes the engine has stepped through all base textures but found no single one that had any influence on a given texel. In such a case it colors this point with an annoying purple color to point this problem out to you and give you the possibility to correct it.
Here is a short example of how to use all this.
numtextures 4 // nr texfile inf height slope tex.1 "gfx\\tex\\grass2_large.pcx .5 .5 40 150 50 0 10 10" tex.2 "gfx\\tex\\rock_large.pcx .5 .5 150 200 100 20 90 10" tex.3 "gfx\\tex\\mud.png .4 .6 0 40 5 0 3 0" tex.4 "gfx\\tex\\snow.png 1 0 200 255 30 0 0 0"
Note how the base textures are split up into the available height space so that mud will occupy the lowest regions, grass will be placed a bit higher, rock above it and snow on the very top. Also, the slope influence factor for mud was increased a bit to have it in only the flattest areas (0-3 degrees, no falloff). Snow, on the other hand, is placed solely according to height, namely in the highest region from 200-255, with a bit of falloff to smooth it out. You can see that its slope factors were set to 0 since they won't matter anyway. Grass and rock overlap a lot through their large height falloff values, however their slope values let grass be placed in the flatter regions while rock dominates in steeper areas.
Well, that was my quick explanation of the texture synthesis algorithm I use in my terrain engine. If something is still unclear, you want to know more about how it's implemented or you feel like commenting on something, feel free to mail me!