Snarkpit Articles


This is the final part of my terrain tutorial series. It is aimed to teach you how to modify terrain you have built to add, remove and optimise triangles - for the purpose of increasing detail, removing it when polycounts require it, and making terrain look more natural. As in the previous two tutorials, this is not a step by step lesson that you need a certain map to follow - feel free to use any piece of triangle terrain you wish. If you want to use the example map I am using, then it can be downloaded, with the .txt file of this tutorial and the screenshots, right here...

http://www.snarkpit.com/pits/reno/tutorials/modifyingterrain.zip

In the example map shown below you can see the highly unlikely situation of having far too many triangles at one end of a piece of terrain, and far too few at the other. At the high point the terrain is very jagged and unnatural, as the few triangles means there are lots of flat sections joined by harsh angles. At the low point I have used loads of triangles, and while this lends itself to nice smooth terrain, it also means that it uses up a lot of those precious polygons. What we want is something in between - a happy medium that balances detail with efficiency.



We will begin by lowering the polycount of the lower section.


REMOVING TRIANGLES

As usual, begin by hiding everything other than what you are working on, leaving only the rocks and the encasing brushes. Now ungroup your rocks.

When removing triangles from terrain, it is almost always impossible to remove just 1, most of the time you need to remove a pair of triangles. Choosing which triangles to remove is not a science, it is a personal choice the designer needs to make and different people will remove different ones. As a general guideline, I recommend you look around for triangles which serve no real purpose to the terrain - ones which lie on a very similar plane to the ones surrounding them. The way I do this is to look at the terrain on the textured 3D view, so that you cannot see the triangles (ensure your textures are aligned or else you probably WILL be able to see!), and look around at parts that look reasonably flat. Now select part of the area and see if it is made up of more than 2 triangles. If it is, then you can probably cut down the detail there without having much of a visual effect.

After doing this, I have picked out the triangles shown below as unneccessary, and so have decided to make them the first victims.



After deleting your two triangles of choice, you will be left with a diamond shape. Our next job is to stich up this hole, and this is done by picking two opposite corners of the diamond and bringing them together. Select all of the triangles that make up one of these corners (ie. each brush that has a vertex at that corner) and go into vertex manipulation mode. Now select all of the vertices that lie on that corner (drag a selection box over that corner). If you don't get what I mean, hopefully the picture below will make help describe it.



You should now move these vertices toward the opposite corner on the top down view. How far you move them is another non-definate issue, and it is very much case specific. In my case here the triangles I deleted lay on a similar plane to the ones lower on the hump (directly above on the screenshots), and so I decided to move them all of the way to meet up with the triangles at the top as this would keep the original shape best. However if the triangles on both sides of the diamond lay on a similar plane to the deleted ones, then you would be better off moving both of them to meet in the middle. I cannot hope to get over all the possible scenarios, but it should become obvious with experience which triangles are best to modify. The latter part of this tutorial on optimising terrain may also help you choose.

Anyway, once you have moved them to meet up with x/y (horizontal) coordinates of the opposite corner, you should move them to match the z (vertical) coordinate. As in the last step, whether you move one corner all the way to meet the other corner, or you meet somewhere in the middle, is case dependant. As I stated before, it makes the most sense in my case to move my currently selected corner all the way to the coordinates of the other. This ends up as shown below...



And essentially that is all there is to removing triangles. Repeat this process throughout your terrain and you can save many polygons - but don't get TOO carried away or you might end up with a far too simplified result. Balancing detail with efficiency is an art that very few have mastered, so don't expect to get the perfect medium straight away!


ADDING TRIANGLES

So you have been overly cautious and used very few polygons for your terrain, and now you have found out your w_poly peaks at a mere 400 odd and you just wish you had made that rockwork look nicer. Well it may not be as simple as snapping your fingers and having it appear, but the process isn't all that tough either. However, please note that if you are only going to be adding more triangles to a small piece of terrain, it is easier to simply start again from scratch, as it means there is less vertical vertex alignment, and it (as by now you know) can be messy at the best of times! It is only REALLY worth adding in triangles if you are doing only a few, so if you dream of shoving hundreds into your existing terrain, I suggest you just delete your old stuff and make a new mesh using however many triangles it is you can afford.

Once again, hide everything but the rocks you are working on and the encasing brushes, and make sure the terrain is ungrouped.

As logic would suggest, the technique of adding triangles is basically the opposite of removing them, and due to this it is almost always necessary to add them in pairs. Your first move is to identify the section you want more triangles in, and once you have done this to create space for them. As is fast becoming my trademark, I'm going to once again state that this is not something I can tell you how to do, its personal choice. If you think an area is too jagged and you want to put in a couple more triangles to smoothen it out, then give it a shot. There is always the undo tool if you decide its not worth the polys or something afterwards.

I have chosen to add a couple of triangles to the high point of my rock formation. As it is the opposite of removing triangles, you must create that diamond you were left with after deleting triangles before. To do this, select all of the triangles that share the common vertex at the area you wish to add triangles. Now choose half of them and deselect the others. The ones you choose are again down to you, but its best to pick the ones that when manipulated leave as near an equilateral (all internal angles equal) shape as possible. Now select the vertices of them all that lay on that common corner point and move them. Repeat this with the other set of triangles that have vertices on this corner, but move them in the opposite direction. After doing this you should be left with a diamond shape, as below...



The quick ones amongst you should have guessed whats next - filling that diamond with two triangles. There are always two possible layouts for your two triangles, and the one you pick is situation dependant. As I mentioned before its best to keep your triangles as near equilateral as possible, as they tend to give the most natural looking shape to terrain. Wandering too far off this and having lots of really elongated triangles can leave some wierd looking unnatural shapes, so we want to avoid these as much as possible. The ideal "acceptable" zone should be between equilateral and right angled, so try to keep each angle inside every triangle below 90 degrees and above 45...but don't feel you need to crack out a protractor as its not essential you are precise! The next 2 screenshots show the 2 possible layouts for my example...



As you can see, these triangles are not very close to equilateral or even right angled, so we don't want them.



This is much better, and so its the one I'm using.

Now use vertex manipulation to line up the vertices vertically, and there you have the same terrain using more triangles, giving you more freedom for shaping it.


OPTIMISING TRIANGLES

Although this was basically covered in the last section, I feel I ought to explain it in slightly more detail here. Triangles in your mesh should be as near to equilateral as possible when looking at them along the normal vector of the textured face.

If your not "in the know" with maths (hell, even I'm not too sure if I said that bit right!), that might have sounded like gibberish. If so, try to imagine the textured face of the triangle had eyes, and was looking straight forward. This is the normal vector. Now imagine you are somewere along this line and looking back at the face - it should look somewhere near equilateral from this perspective.

For the most part though, you can simply judge the shape of the triangle from one of the 2D views, as most of the time your terrain will be near enough to facing up (if your making ground), down (for a ceiling) or straight along in one direction (for cliffs).

Sometimes you inadvertently end up with some triangles that just aren't anywhere near equilateral. So how do you go about fixing these? Well basically its both of the processes mentioned before rolled into one, without the deleting or cloning!

Going back to where we removed some triangles earlier, you can see that the triangles we moved to fill the gap are certainly NOT anywhere near equilateral.



In order to optimise this piece of terrain we are going to shift the triangle layout around on the top down view, and then line all the vertices up vertically afterwards. Unfortunately I have run out of screenshots (snarkpit only allows 8 per tutorial, for you non-tutorial authors!) so you will have to use your imagination as to how I did this, but after the previous tutorials and going through this one I don't doubt its within your abilities. Suffice to say that this is the layout I decided to use in the end, and I achieved it without deleting or building anything - I just moved around the existing triangles' vertices.



There are a few other opportunities for optimising the high detail part of the rockwork, so see if you can spot them and work out what layout you would use.


Well thats it for my terrain series of tutorials, I hope you have enjoyed them and they have helped you make better looking natural features in maps. Comments and suggestions should be left below as always.


Post ReplyView Topic
Discussion
0 starsPosted by blasterX on Tue Feb 22nd 2011 at 4:29pm

link down
0 starsPosted by Daubster on Mon Apr 9th 2007 at 7:29pm

A truly great tutorial, this is definately going to help me tons in terms of optimisation in my newest map.

Btw, you're using my 3D background colour in Hammer! ;P
0 starsPosted by Guessmyname on Wed Dec 22nd 2004 at 1:45pm

0 starsPosted by half-dude on Wed Nov 10th 2004 at 3:36pm

GORG!!!
Post ReplyView Topic