Tile based terrain

Hello everyone,

So, here is my problem - I try to create tile based terrain like in Warcraft3 game and here is what i have right now -> dota.brainmarket.ru/temp/Screenshot-Panda.png its look this looks exactly as i want but it’s very slow. Right now every tile is a node because i found only one way to assign several textures with texcoord to 2 triangles(1 tile) - through the Node. It’s also take a big amount of memory. So all my terrain right now is a big amount of nodes in scenegraph. I think that performance is so low because of big amount nodes. Is it possible to add big amount of polygons on the fly with different textures but with only one Node in scenegraph?

Regards,
Rrrichi

PS Sorry for my English it’s not my native language.

One answer is to assemble a lot of different nodes under a common root node, and then call root.flattenStrong(), which will attempt to combine them into as few nodes as possible.

Note that one GeomNode can contain multiple different Geoms, and each Geom represents a separate call to the graphics card. So usually for optimization purposes a Geom is the smallest atomic unit of drawing that you need to minimize.

Note that the optimal number of Geoms may be fewer than the number you have, but it may also be more than one. If you have the entire terrain in only one Geom, Panda will send it all to the graphics card in one call–which means it cannot remove the parts of the terrain that are behind the camera, so your graphics card will be forced to draw every vertex every frame. The point at which this becomes more expensive than drawing lots of little Geoms depends on your particular graphics card.

But finally, you need to understand that each Geom needs to have exactly the same render state, by the nature of graphics card calls. Clearly, in order to set up and draw a group of triangles, Panda needs to first issue a series of commands to set the appropriate render state, and then issue the command to draw the set of triangles with that render state. For each different render state, the process must repeat.

Thus, if two different tiles have different textures, they cannot be combined into a single Geom, because they have different render states and therefore must be drawn separately.

So the bottom line is, you can assemble all of your tiles together and call flattenStrong, which will move them all into a single GeomNode which contains lots of Geoms, which therefore won’t do much for your render performance.

Ideally, you need to find a way to apply just one texture (or one combination of texture layers) for many different tiles, without having to have a different texture state for each tile. One trick is to mosaic your individual textures together into one very large texture, and choose your UV’s for each tile appropriate to index into this large texture. This, incidentally, is what egg-palettize can do for you automatically.

David