displaying hundreeds of md2 models

Hi, I am working on RTS game. The only problem is that I am unable to display more than 150 md2 models (500-700 triangles) because my fps is low (it equals 7 for 400 models). I need help. Does anybody know how to display md2 models fast?? I tried to use display lists and vertex arrays but speed didn’t change. I’ve also discovered that lighting and calcuating normals makes fps lower so I am not using it anymore. But still I don’t know what to do. I was thinking of reducing the number of triangles depending on distance between model and camera but I can’t find any information, and I daon’y know how to implement it. Somebody in this FaQ asked about md2 interpolation optimisations, but there was no responses. I need some tips how to fasten my game. (I am sure that drawing models lowers fps)

700 * 400 * 7 = nearly 2 million tris/sec
That is quite a lot.

You know, full 3d rts have fewer units at the same time on the screen. And you need obviously simpler models.

There is no completely general and correct way to have a simplified mesh from a high density one.

So, it will depends on your needs :
Serious Sam had a LOD system for geometry, connected with a Lightwave plugin. Each level with lower detail share all its vertices from the higher levels. This is good to reuse vertices, but it gives not the best visual results.
For Doom3 , the low poly model seems to be done from a NURBS or subdivision algorithm.

Maybe you can try to collapse the smallest edges to a single vertex, up to some threshold. Search for LOD, mesh simplification, etc and read what was said for the topic you mentionned. http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/011445.html
Mesh simplification is more math& algo related : http://www.opengl.org/discussion_boards/cgi_directory/forumdisplay.cgi?action=topics&number=6

[This message has been edited by ZbuffeR (edited 01-31-2004).]

Isn’t it time we locked both of these (almost identical) threads?

Go google for “view independent progressive mesh simplification”. And don’t double post.

One other option is to have diffrent versions of the same object.

Near object version high triangle count.
Med distance object med triangle count.
Far object low triangle count, or even a textured qaud(billboarding object).

Why stop at hundreeds? Go for meeeelions!

Are you implementing Culling? Those nasty faces behind your models are being rendered too, wasting tons of processing power. Culling should get rid of those polys by removing(ignoring) them when rendering. OpenGL has a culling setting you can enable, but it affects all poly’s rendered after it untill it is disabled. So you would have to find some way to implement a “detect” feature.

Hrm. The more I look at it, it seems opengl does the “detecting” by itself, so all you need to do is enable it.

I was playing with md2 models a while ago… making a nice little war between 2 AIs… anyway what i did to speed it up was I calculated the distance between the model and the camera, and lets say it is under 50 units away, u render the whole model; but lets say it is over 50 units away, then i render every other triangle

NOTE: depending on how the model was formed this method could cut the head of the guy or could just put some holes in him (which is what it’s suppose to do)

This works very nicely, and u can configure it as needed… just for the term, it’s kinda a method of LOD

How I could help, if you need further explanation just put something here and I will try to respond.

Hope I could Help

More effective than just backface culling is culling out the objects that aren’t in the view. Make sure you do that.

As for the LOD, I suggest you just ask your artists to produce two versions of each mesh and use the simple one when it’s far away from the camera. It’s not much of a trouble, simple objects are fast to model and you can use the same textures. This is also the only way to ensure quality, optimized low-res models. I wouldn’t worry about vertex reuse, the low-res models shouldn’t have many vertices anyways.


Something else which might speed up the rendering time is to draw objects closer to the camera first, then objects further away later. That way, if two objects overlap, you’ll have less redraw on the Z-Buffer, Color Buffer, and Stencil Buffer (if you’re using it). You wouldn’t need to be exact about it either…square roots are processor intensive. You’d probably be able to get away with a linear comparison, a square root table, or even a list of square roots, and if you find your table’s too short, calculate an additional term and add it to the table. This is all theory, though…I have no practice with it. :slight_smile:


I think its odd everyone appears to be fixated upon LOD schemes, and whilst I agree that you’ll need some LOD system in there other possibilities exist to improve performance.

For example is each MD2 a unqiue instance? In other words are you animating 150 models at once? Doesn’t matter how optimsied you’re interpolation is that will still take a good chunk of time.

It could be as the first poster suggested that you’re limited by either polygon count, fillrate or sending data over the bus. In which case there is little that could be done.

However if you are using 1 instance per model, then i’d suggest looking at re-using model data, sharing instances between many models. This can seriously cut down the amount of animation going on as well as the amount of data being sent to the card.

I recently did exactly the same thing, but with approx 300 md2 models in Director/sw3d and manged to get a decent 30 fps. The only way I achieved this was to have just 6 instances of the md2 model. Each instance was a different animation of the same md2. So i had walk, idle, shoot, and 3 death routines. Then each entity had a simple state machine which determined which animation to use. When one got shot, it would wait until the animation looped and switch state to a death animation.

There are issues such as every entity is step locked , where they all animate with the same walk frame, but that can be fixed by using multiple walk animations that variy the start frame slightly. As each animation loop is pretty short the delay between switching animations is barely noticable.

For my purposes having two armies of the ‘invader’ alien md2 model (350 polys) fight out on a large terrain, it worked great. Of course another advantage is that both sides used the same md2 model, I simply had two textures one for each army to distingush them.

Bear in mind that SW3D is far from optimal, ASAIK it sets up the render states per mesh. So even though I had 2 sets of 150 models using the same texture, the whole material and texture states were reset per model! Coding this up in openGL would remove that limitation and should gain a reasonable boost in performance.

So perhaps think about what you’re trying to achieve in a different way would be more fruitful.

Oh I should point out that each of the 300 entities also had its own animating shadow, done via simply projecting the mesh to a plane. Far from optimal solution, but quick and easy to implement. So in effect there were actually 600 models being rendered. When all in view I think the fps dropped to about 20. However to get around that I introduced a simple varable to track the camera distance to the ground, past a certain point the shadow models were faded out and eventually removed.