Terrain engine

Im coding a flightsim… I got some questions about terrain engines… first Ill explain how my “engine” is working:

loads 1024x1024 height maps, put everything in a matrix, 1.0f == 1.0 meters, then you load how many quads you need, each quad have its own texture, mip-mapping its auto-generated by glu.

What I want to know:

How to just make visible the quads that are in the view-range… without using quadtrees or octrees. This is possible? or should I use quadtrees?

Thanks and sorry about bad english.


try to split your map into blocks of let’s say 32x32 cells (each cell is a quad).
Then, apply frustum culling on each block. If visible, cull each cell contained in the block, and then draw…

Anyone ever try an Octree for terrain? I’ve has such good success using it for other geometry I am thinking about giving it a shot.

I don’t think an octree would be a good idea for a general terrain renderer.

Octrees are a good choice for geometry with a bounding volume approaching the 1:1:1 ratio measured along the x,y and z axis. Subdivision is isotropic on all 3 axes. The size ratio of a standard terrain is more something like 1:1:0.04, approaching the optimum ratio for a quadtree (1:1:0). Ussually, terrains have a very large base surface on the x,z plane, and a small elevation in y. If you use an octree on such geometry, most of it’s leaves will be empty, and it will degenerate into a quadtree.

Though, if you are using high terrains with a small surface (such as a small terrain patch with very high and steep mountains), then an octree might be interesting. But that’s not the general case.

  • Alex

Well it depends on what you want to do.
If you want to draw only the quads in a radius around the viewer or the player in a game: Then just set the far clipping of the perspective matrix to the desired radius.
Then add a skybox or skysphere with the radius-1 around the player to hide the background.
Now lets say it is independant from the camera or the player.
The simplist is to calculate the distance from each quad to the point. And then only draw if distance is smaller than the radius.
This is not perfect in performance because of the many square roots or sines.
If you need it even faster then i can only think of octrees or quadtrees.


I’ll just give my 2 cents here…

when I did a terrain renderer a while back, using a 512x512 block, I decided not to use a quadtree, but to simply used a fixed size grid, where each grid cell could be subdivided vertically if needed. the main advantage this gave was because the terrain had overhangs and such, so although the average cell contained pointers to 9 triangles, cells on an overhang had huge numbers (thing 120), thus, chopping them apart vertically was the answer, but only when there were more than x triangles over z height range.

it took about 9 seconds to generate this on a p-4 1600. 25 on my 533

the block was subdivided too. for fustrum culling and occlusion culling.