Game Development Community

Making a Terrain in T3D From Start to Finish

by Jacob Dankovchik · 05/19/2009 (9:11 pm) · 31 comments

In this tutorial, I'll be working with L3DT. It is a very useful program for terrains and can do very simple terrain very quickly, or if you take the time to really unlock it's features, has many powerful tools for advanced work. You can buy it here on GG, as the L3DT For Torque, however with Torque 3D that version isn't really any more helpful anymore. Or you can get it from www.bundysoft.com/L3DT/. If you purchase from the main site, you'll have access to pre-release development builds. Your choice.

In this guide, I'll cover the basic randomized generation in L3DT. I won't take the time to get into more advanced concepts as that would take too long to write about in depth. This will thoroughly cover how to do a basic terrain and if you really wish to learn how to do higher-end work, this will be a good stepping stone.


So to start, we open L3DT. Go to file, New Project. In the window that comes up, Designable Map (recommended) should already be highlighted. If not, select it and click next. This will set us up to create a generated terrain but that will also be able to be edited by hand, if need be.

In the next menu that comes up that says Heightfield size, change the width and height (default value of 1024) to 2048. This is a fairly large terrain we'll be making for this example, only to demonstrate something with quite a bit of meat in it right off the bat. If you really want, you can go smaller though.

Below the dimensions is something that says "Horiz. scale (m)". This is how many meters you want each pixel to represent. When you import your heightmap into T3D, you'll want to set the squareSize variable to the same value as this. Since the default 10 is excessively large for Torque, change it to 1. This will create a terrain scaled to 2048x2048 meters, plenty large enough.
img193.imageshack.us/img193/1418/mapsize.jpg
Click next. In the next menu, Design map size, you won't need to change anything. This is if you want to change the resolution of the first stage of the process, the Design Map. That's nothing we need to worry about here.

The next menu, Design Map Parameters, is where you really put it together. For this demonstration, I'll go ahead and make a set of sharp mountains. To do this, move the Average altitude slider all the way to the right for land. Move the Altitude range up a few notches as well, for my own I'm setting it to the mark before last. For Scale of features, I'll move my slider up a couple tick marks. The very name of those variables should be quite self-explanatory.


The next 4 variables are what really do the shaping that will make your terrain what it is. Since I want to go with some sharp, jagged mountains I'll give my terrain a high Noise strength. This will make the map very bumpy and detailed. I'm setting mine to the tick mark before last.

Noise shape is what will determine what form you want it to take. To the left towards rolling you'll get smooth curves and bumps. To the right towards fractal, you'll get more of sharp lines and edges. Since we're going for sharp mountains, we'll want our noise to have a fractal shape. My marker is put in between the next to last marker and the marker before that.

Cliffs and terraces can add quite a bit of detail however a little bit goes a long way. If you get carried away with this variable you can easily get a terrain that is not at all what you wanted. You will have little platform and sharp drops all over the terrain. Sometimes this is desirable depending on what you are making, but for this we'll set it to something low. I'll go with the third tick mark.

Erosion adds great detail to a scene but at the cost of great generation times. Nevertheless, I feel our mountains should have some strong erosion so I'm going for the center tick.

Since we won't want anything to do with Lakes, leave that slider at few. That variable will make certain parts prone to form lakes.

Climate is one of the very great features of L3DT. Your climate is a detailed file that says which textures go where. It can be very simple, or very very detailed. For this we'll keep it simple and go with the default climate of Temperate.
img193.imageshack.us/img193/221/designsettings.jpg
In the next menu, Calculation Queue, only leave Design map selected since we're going to do this step by step. Click OK and it should go to work spitting out some stuff that flips by so fast you can't even really read it. After that, you are presented with a very low-resolution map with varying shades of greens and browns. This is your design map. Each pixel of it contains detailed information on the terrain, the level of all formation variables. This is passed off to the heightmap generator and a heightmap is formed by calculating and interpolating between the design map pixels. Up at the toolbar is a pencil looking tool, this is the design map pencil. With this you can manually edit your design map. Since L3DT's website contains detailed information on this, I won't go into it here.
img41.imageshack.us/img41/7314/designmap.jpg
Also on that bar, the 5th button over, is a series of green arrows with the word Calc above it. Click that and you are again greeted with the Calculation Queue. Heightfield should be checked. Again, one step at a time, so, click OK. You'll be greeted with a small window with some colors zipping by and probably mostly talking about erosion. This is where the heightmap is being formed and this map take a while, so feel free to go grab a drink or take a restroom break at this point in time.
img195.imageshack.us/img195/3629/heightprogress.jpg

Once all that is done, you should presented with something that hopefully looks like this:
img38.imageshack.us/img38/9946/heightmap.jpg
This is our terrain! Since that's the first image we need and it's already done, we might as well just go ahead and export it now. Right click on the picture, go to export, and click Export Active Map.
img190.imageshack.us/img190/4211/exporting.jpg
For file format, select PNG and stick it wherever you like. There will be no need to re-size the heightmap.
img199.imageshack.us/img199/7968/exportmenu.jpg
Once it's done exporting we're ready to move on. Return to the calc button and click it. Water map should already be checked, if not, check it and click Next. The next menu titled Water flooding is mostly just details we need not worry about here. If you want, you can make it turn anything below a certain elevation as sea, or you can make it freshwater, auto-flood sea will turn and sea blocks in your design map to water and flood outward to everything else, same with auto-flood lakes, only with freshwater. Anyhow, click next. The next menu with a bunch of variables we in no way need to mess with, so click OK.
img199.imageshack.us/img199/1754/wmprogress.jpg
And you should get something sort of like this:
img41.imageshack.us/img41/7599/waterr.jpg
This is our water table, a model of our groundwater. This helps in placement of grasses and other textures. Unlikely it will significantly affect our mountain set, but it's still a good idea to calculate it out anyhow for accuracy's sake.

Back to the calculation queue and this time, we're doing Attributes map. In Attributes map calc. you can make it higher resolution than your map itself, or split it. We don't need to do any of that, so click OK. After some calculations you should get something like this:
img195.imageshack.us/img195/7353/21940226.jpg

Now we have all of our terrain's data constructed, we're ready to export our alpha maps. Right click, select operations, Alpha maps, Generate maps.
img193.imageshack.us/img193/4593/alphagen.jpg
The next menu, Combine alpha layers, tells us what textures are used by our map and how much coverage the make up of the map. It will probably look something like this:
img196.imageshack.us/img196/8202/coverage.jpg
It appears we got lucky and the map only called for 4 different textures. This means we can get away with just one alpha mask and thus less headache. Look over anything you feel you need to. Also, remember what channel is what texture, as you'll need to know this later. I'll remind you in case you forget later, but nothing stops you from writing it down. Click next.

In this menu, we export our mask layer. As you can see, you can select Layers per image, file formap, high-res, split, and export now. The only thing we'll want to select here is Export alpha maps now. It will ask you to save an xml file. Stick this wherever you like, usually along with the heightmap is a good idea, and click OK.
img190.imageshack.us/img190/7761/alphaexport.jpg
You are then greeted with a colorful display that should be something like this:
img190.imageshack.us/img190/6766/alpha.jpg
We are now done with L3DT! But, before we exit, we need to get a readout on our altitude range if we want this to be correct. Navigate to the heightmap by clicking on the small button that says "Heightfield". Your heightmap image will then reload onto the display. Move your mouse to the highest point you can locate. In the bottom right corner of L3DT is says what the altitude is at your mouse position. You don't have to worry about being exact with this by the way, a few meters off won't make a noticeable difference. Now navigate to the lowest point and subtract this from your highest point. My lowest is 94m, my highest is 614. So, my height range is about 520 meters.

Save your project if you like, and we can get ready to see how our hard work has paid off.


We are now ready to open T3D. Do so and setup to create a new mission. When you get there, delete the terrain that's already there, we won't be needing it. (Don't forget to free your camera from the player, if it's attached)

Go to file, import terrain heightmap. Since our horizontal scale in L3DT was 1, make your Meters Per Pixel 1 in the menu. For Height Scale, we enter our altitude range of 520. In the heightmap image box, browse your way to your way to your heightmap and select it.

In the small box below click the plus sign, and navigate to your texture mask layer. A small note of a possible bug: Sometimes T3D won't like the name L3DT gives your mask, it will cause it to say that your mask size doesn't equal the heightmap size. For this reason, just rename it from the browse window and import it. Something simple like "mask" should give you no trouble.
img196.imageshack.us/img196/9974/import.jpg
Now here is the part where you should've written down your textures for your channels, if you didn't remember them. If you can't remember and were lazy (shame on you), go to where you saved that XML file and open it. Where you see it listing off the filenames of the textures, those are the textures each channel of the PNG represents in the order of RGBA. If that doesn't work, you'll have to reopen your L3DT project and go through the alpha map process to get a readout on your textures. I'll leave that to you as punishment if you are in this group. Live and learn.

Now, select the first of the channels, the red, and click Edit and pick the material that goes with it. This is the part where your process will most likely vary from mine since I may not have the same material files you do. You can use the default demo T3D materials, or your own if you've made your own. Since material creation is a whole other issue, I won't go into it here.

Once you have your materials assigned, go ahead and click OK. Since we're using a 2048x2048 map, which is rather large, this may take a minute or two. I've had a couple instances where T3D will crash at this step for no apparent reason. If this happens, don't panic, just try it again.

Once that's done, you should have something like this:
img193.imageshack.us/img193/4822/firstpass.jpg
Now, all may appear to be great, but it very well may not be. While our terrain is in, and working, it may not be quite perfect. If you drop your player on it and run around, you'll probably notice very quickly that the shadows look very poor and glitchy. This is not a big issue, just a small number that needs changed from it's default value. Go to the object editor, select the sun, and find the splitFadeDistances variable. I've done some playing around with this and found that usually just throwing it to "13 13 13 13" gives the best results in general. Sometimes with even larger work it needs a but further adjustment, but that shouldn't be needed here. Set that and your shadows should look vastly improved.

The next issue you may or may not notice is performance. Now, obviously you can improve this by cutting the visible distance down. But honestly, with a mountain range like this, do you want your view cut off so short when peering from the top of a mountain? Probably not. So for this, in the object editor select the terrain and find the screenError variable. The higher you make this, the quicker the terrain will lose detail over distance. Improves speed, but decreases quality, obviously. This is totally up to you to find that happy point inbetween.

Lastly, I've been hearing of some people having issues with terrains not at "0 0 0" and that are rotated. So for that reason, I just leave mine at "0 0 0" and don't rotate it to keep from having any issues I don't need.

And now of course, you can spice up the scene a bit if you like, make it a bit more flashy for screenshots. Some decent fogging, better sunlight, etc. Also, while a low screenError doesn't work for moving around, for a screenshot it certainly doesn't hurt. ;)

img190.imageshack.us/img190/982/finalb.jpg

Hopefully this tutorial has been helpful to some of you. I may write another in the future touching on the more advanced areas that I skimmed over this time around. Feel free to throw any suggestions my way. And remember, the only way to really learn how to do this yourself is to experiment. A LOT!
Page«First 1 2 Next»
#21
05/25/2009 (9:07 am)
I haven't had too much time to get into this too deep yet Nick. Hopefully someone else here can help you. I just wanted to make sure you didn't miss the 'shorter path name fix'.

Also that screen shot doesn't give much information about the files themselves. E.g. Are they 8-bit pngs? Did you try the 4 layers per image 32-bit png option from Jacob's tutorial?
#22
05/25/2009 (11:00 am)
I tried, its a professional only feature.


Using photoshop, I was able to blend the layers(and give them color) myself, but the texturing is kind of off(the entire terrain is one material except for tiny specs here and there)

And of course, sometimes it still asks for an image that doesn't exist.

I'm going to look into alternate texturing solutions(sounds professional) to fix my issue. The height map it gives me works fine, however, so I'll keep using that.
#23
05/25/2009 (12:15 pm)
Quote: its a professional only feature
I see. I have the standard 2.6 version so let me try this out...

Following Jacob's toot, everything is pretty much the same up to the point of exporting the alpha masks. The standard version only allows 8-bit images. That is fine. I ended up with 4 bmps named: mask_Alpha1.bmp, mask_Alpha2.bmp, mask_Alpha3.bmp, mask_Alpha4.bmp.
( I put them in the same place as the heightmap: C:\Torque\Torque 3D 2009 Beta 2\Genre Kits\FPS Genre Kit\game\art\terrains\ )

Now in T3D in the 'Import Terrain Heightmap' dialog, in the 'Texture Map' area click the + and add each of your alpha textures. Each of the texture files will have 3 channels (R,G,B), so if you had 4 of those alpha files like me then you will have 12 entries in that box. Select each one and hit the edit button and choose your texture for each slot. I set each channel to the same texture for each of the files. I just used the default textures that came with T3D but you could also use the same textures from L3DT I am sure, or use your own like Jacob did.

You might want to hit the plus sign and add each alpha and then edit the texture before moving on to add the next alpha so you don't get mixed up with all the channels. e.g. click + sign; add mask_Alpha1.bmp; edit each channel of that bmp file to grass1-dry; click + sign; add mask_Alpha2.bmp; edit each channel of that bmp file to rock1... etc.

I am sure you could have used png files instead of bmp and also consult the xml file, or your notes, to determine what texture to use in the channel slots for each alpha.

All of the above worked fine for me. I deleted the ground plane and added this terrain to the blank FPS genre level btw.
#24
05/25/2009 (2:09 pm)
@Nick: If you have done what comment 11 says and it still gives you an error then you had the same problem I did.

Basically your directory path is too deep and you need to move it higher up ... as close to your root as possible.

In my instance I had my folders in the "My Documents" and then "My Development" and then "Gobbo Games" and then "t3d" ... etc. No matter what I did, I kept getting the error mentioned in comment 9 even thought I tried the fixes mentioned previously.


Eventually what I did was move my t3d folder to "Development" and "Gobbo Games" under my root drive ... viola ... error went away.

I suspect that the fix mentioned in 11 was just one of those lucky ones where the person managed to get the file name (including directory) structure under a certain amount of characters and that is why it worked.

I think the bug comes from a variable inside T3D that is set to like 256 characters or something ... this is just a guess.


I was getting all the errors you mentioned and I solved it by moving my folders. Hope this helps. :)
#25
05/26/2009 (4:43 pm)
Thanks for the tutorial!
#26
06/11/2009 (8:07 am)
Thanks a lot, Jacob!

I still have a question,
how do i import a big Mosaic-tiled map using this method?

I load the heightmap and and i try to load one of the mosaic alphamaps,
Torque prompts me with the following error:

The opacitiy map does not match the height map size!

how can i upload the different mosaic-tiled alphamaps?

thanks
#27
06/24/2009 (9:19 am)
I'm getting something really wierd here:
pixollusion.com/T3D/beta2/trerrain_messup.jpg
any ideas I set everything pretty much as you did except for a couple of the terrain sliders

but as you can see somehow I seem to have holes in my geometry.

oh yeah using version 2.7 Pro Torque
#28
06/24/2009 (12:12 pm)
Looks to me like you messed up an alpha map. If you forget to import and alpha mask, don't assign a texture to one, etc. Torque will make that spot a hole in the terrain.
#29
08/06/2009 (7:01 am)
(Will also post to the Bundy forums):
If I want to crop a Heightfield, is there a preferred way to do so?

For example, if I want to import real-world terrain using this tutorial: http://www.bundysoft.com/wiki/doku.php?id=tutorials:l3dt:srtm

But, instead of a 6001x6001 pixel heightmap, I'd like to crop it to 2048x2048. Photoshop editing the TIF doesn't keep all of the metadata, so I need another way to crop. I can make a selection within L3DT, but don't seem to be able to crop it to that selection.

Any suggestions on tool/processes to edit GeoTIFs?
#30
10/06/2009 (4:23 pm)
Worked perfect for me. Thanks. It's a good starting point.
#31
10/18/2009 (10:07 pm)
Nice little how to! Combine this with Konrad's Rule based layer distribution and you have a sweet terrain.
Page«First 1 2 Next»