The Terrain for seganx engine is going to be completed. in this post I will describe the geometry algorithms I used for rendering the terrain briefly. my approach to design this feature was easy to use, simple and straight forward implementing. Artist/Level designer can easily:
– create geometry every where and every amount that was required.
– increase performance by implementing LOD and patching geometries to reach minimum draw call.
As I mentioned before, everything in the scene is a kind of node member. In this method the terrain is like the other members ( mesh, particle, sound, … ). The terrain is a node member too. Thus for importing terrain to the scene we must create terrain and attach it to the node and then add the node to the scene. so we can create any number of terrain and add them to the scene. But to reaching the goals which mentioned above I design terrain members with some more information.
Each terrain member has a fixed 33×33 vertices placed in grid style. I choose this size because I want to generate 6 levels of details. With 33×33 vertices we have 32×32 quads for first level. This means if we half each level for 6 times, finally we will have one quad for lowest level of details. Choosing vertices for each level will do by using 6 static fixed size LOD structures called TerrainLOD that used for all terrain members. Thus, there is no need to more indices/vertices for each level and we just choose a correct LOD structure depends on view distance. So for rendering all terrain members I used a big buffer and append to that big buffer vertices of all terrain members in view port. Appending process just applied on vertices which described in LOD structure. Finally, the terrain will draw by one draw call.
T-junction problem appears between terrain blocks with different LOD and make terrain ugly. The picture in below illustrate this problem clearly:
There are several ways to remove these junction problems. according to ‘Geometry Data’ of terrain in engine I defined and implemented a simple structure to describe indices for each LOD. this structure split indices for each LOD to 9 part :
TerrainChunk center; // standard center
TerrainChunk sideFUL; // standard 4 sides
TerrainChunk sideLOD; // simplified 4 sides
Indices of center in this structure contain polygon indices that cover the center except 4 sides “up, right, down, left”. these sides will covered by sideFUL or sideLOD. sideFUL contain indices to cover with all polygons in that LOD and sideLOD contain simplified indices.
Choosing which side ( sideFUL or sideLOD ) to use as indices is simple. we can easily predict the LOD of neighbors. to predict LOD of each neighbors I compute the neighbor’s position by adding fixed terrain size to current position. by passing this position to some special functions we can get neighbor’s LOD number depend on current camera properties. for each neighbor which uses less details we append sideLOD to the big buffer, otherwise we use sideFUL. here is an screen shot for terrain in wire frame mode :
My next task is choosing and implementing terrain material system. current system support multilayer material system. but implementing brush, gathering information of each brush on terrain to increasing performance, optimization and optimization and optimization still need more and more and more works. but now I have to spend more time to cnep game project.
Categorised as: Game World