Thousands of trees? Model details/billboard

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

Thousands of trees? Model details/billboard

Post by suliman »

Hi
Im doing a airplane game with lots of trees (many hundred seen at the same time) etc scattered over the terrain (I will also have units/buildings but much fewer). How to keep it fast?

1. Can i scale model-quality based on how far they are from camera? Is it automatic?
2. Do nodes cost gpu/cpu when they are outside view of the camera (like behind)? Is this automatic?
3. Should i switch nodes to billboards if they are far away? How is this done?

Thanks for your help
Erik
rcalvin
Posts: 31
Joined: Tue Jan 08, 2013 1:58 am

Re: Thousands of trees? Model details/billboard

Post by rcalvin »

You've basically got the right idea, I think.

1) Mesh LODing isn't automated as far as I know, but it shouldn't be too hard to do. You would just check how far from the camera a tree is and, if it's beyond some threshold, swap it out for a lower poly version. I probably wouldn't check every tree every frame, since that doesn't seem like much of an optimization! I would probably group tree nodes into "patches" and then work on patches of trees rather than individuals. Also, you probably wouldn't need to check or update them every frame. You could probably skip a few!

2) I think that is occlusion culling, and that it is indeed automatic.

3) Just make it another step in your LOD system. Instead of a single plane, I might use 2 crossed with identical textures so I don't need to rotate them to the camera all the time.


Also, I think this is probably a good candidate for shader instancing, but I don't know enough about it to really say any more.
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

Re: Thousands of trees? Model details/billboard

Post by suliman »

but what is most important? Number of faces on the model? I use 3ds-file format, would that matter for irrlicht?

When i add 400 "trees", each a 3ds of simply a 16 face sphere and a rectangle (no textures even) and this brings irrlicht from 100 to 50 fps, which seems wierd as i can run shogun 2 total war at decent framerate with thousands of models on screen each with hundreds of faces.

And switching between different quality models, doesnt that require a lot of processing? I need to create and remove nodes each time right? Or should a I create all 3 levels (lets say) of complexity models at startup and simply swith switch which one is enabled at each time?

thanks
codetiger
Posts: 103
Joined: Wed May 02, 2012 9:24 am
Location: Chennai, India
Contact:

Re: Thousands of trees? Model details/billboard

Post by codetiger »

Rendering 100s of nodes will definitely affect your fps. It is not easy to render 1000+ objects on screen without advanced OpenGL techniques or tricks.

If your mesh and texture are same for all trees, the you can try instancing. Or you can try mesh batching if the trees have different mesh.
IrrNaCl - Irrlicht Port for Google Chrome Native Client - Demo

Iyan 3D - Make your own 3d animation using your iOS Device
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

Re: Thousands of trees? Model details/billboard

Post by suliman »

ok i know what instancing is but not how to do it, is there support for it in irrlicht? And what about the other questions if you know?
CuteAlien
Admin
Posts: 9670
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Thousands of trees? Model details/billboard

Post by CuteAlien »

No official support so far. Bitplane started coding it once (see http://svn.bitplane.net/misc/trunk/irr/CImpostorNode/) and if you search for "impostors" in the forum you find probably some more info. I think he got something working, but not completed.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

Re: Thousands of trees? Model details/billboard

Post by suliman »

Yeah hardly something for a non-advanced user of irrlicht then sadly. But does anyone know:

1. No automatic mesh LOD i guess?
2. If i do my own, should i create and remove nodes (meshes?) when changing LOD? Or create them all at level creation (each tree has 3 different nodes which varying complexity) and just switch which version is visible? Is that better?
3. Does mesh-format matter when it comes to performance? I use 3ds for my statics but its not very practical to import/export from 3dsmax, size changes. Any more practical solutions?

thanks
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Re: Thousands of trees? Model details/billboard

Post by polylux »

I don't know if you have already given MeshCombiner a go.
Answering 1 & 2: It's not so much about the geometric complexity of your trees but rather the traversion of all the scene nodes (and hence redundant draw calls) that slow down your rendering step. MeshCombiner would account for that.
3: Nope, as the engine keeps its own independent representation of the model.
beer->setMotivationCallback(this);
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

Re: Thousands of trees? Model details/billboard

Post by suliman »

1. Im confused, the program i can download there draws many textures on a flat "ground"/plane, there doesnt seem to be any models at all drawn. Im clearly missing something.
2. I dont understand this really. Isnt the point of LOD to reduce polycount? And if i do should i create and remove old or switch visibility?
3. So 3ds-format is advised from 3ds max? Its the easiest format to work with? Because it changes the size in a wierd way when exporting.

thanks for helping out
erik
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Re: Thousands of trees? Model details/billboard

Post by polylux »

Ad 1: What's the issue there exactly? Can you elaborate?
Ad 2: Basically yes, LOD reduces the geom. complexity which comes in handy when you display distant objects. As I said, the polycount itself will not be the big issues assuming your tree model is rather lowpoly (can we have an exact count?). It's rather the overhead you create drawing each tree separately. So ways to go would be let MeshCombiner make one big mesh out of your 'forest' or - given you use the same model for all the trees - use hardware instancing. AFAIK there are some examplary implementations of the latter somewhere on the forums. If you merely wanna do it the easy way, give MeshCombiner a try.
Ad 3: Exporting models from blender I usually use .3ds as I've experienced the least problems with it. I'd love to use collada as it's an open format though I always seem to have issues once I open such files in irrlicht.
beer->setMotivationCallback(this);
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

Re: Thousands of trees? Model details/billboard

Post by suliman »

the example (the downloadable one) adds lots of planes ("plane.obj" is the file in question).
It seemed to only optimize lots of texture drawing. But i guess it helps in drawing models as well... (As seen with the dwarfs). Im maybe just a bit confused on what it does.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Thousands of trees? Model details/billboard

Post by serengeor »

suliman wrote:the example (the downloadable one) adds lots of planes ("plane.obj" is the file in question).
It seemed to only optimize lots of texture drawing. But i guess it helps in drawing models as well... (As seen with the dwarfs). Im maybe just a bit confused on what it does.
It puts everything into one (or more?) mesh buffers and also batches textures into a bigger one (texture atlas) so the draw calls are reduced more or less to the minimum.
Working on game: Marrbles (Currently stopped).
mikkis
Posts: 64
Joined: Mon Jan 28, 2013 2:38 pm
Location: Fi

Re: Thousands of trees? Model details/billboard

Post by mikkis »

serengeor wrote:
suliman wrote:But i guess it helps in drawing models as well... (As seen with the dwarfs).
You can batch static models, you cant animate batched models.
Got fps 150 -> 300 when batched my grass.

Code: Select all

 
        array<IMeshSceneNode*> nodes;
        for(int q=0;q<10000;q++)
        {
            const float S=50;
            float x = ((float)rand()/(float)RAND_MAX) * S - (S/2.f);
            float z = ((float)rand()/(float)RAND_MAX) * S - (S/2.f);
 
            node->setPosition(vector3df(x,0,z));
            nodes.push_back(node);
        }
 
        CMeshCombiner* combiner = new CMeshCombiner(0.8f, ETPT_TILE);
        IMesh* combinedMesh = combiner->combineMeshes(sceneManager, nodes, "../media/grass.irrmesh");
        IMeshSceneNode* k = sceneManager->addMeshSceneNode(combinedMesh);
        k->setMaterialFlag(EMF_LIGHTING,false);
 
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

Re: Thousands of trees? Model details/billboard

Post by suliman »

ok seems cool, will look into it more
Can i still rotate, move and scale the individual nodes even if their meshes is combined or how does this work? Seems like it from the picture with the dwarves. So only drawback is no animation? Can i remove one of them later on or do i need to redo the combination then?

erik
mikkis
Posts: 64
Joined: Mon Jan 28, 2013 2:38 pm
Location: Fi

Re: Thousands of trees? Model details/billboard

Post by mikkis »

Code: Select all

 
Can i still rotate, move and scale the individual nodes even if their meshes is combined or how does this work? 
 
No. When using CMeshCombiner, it creates 1 object which contains all data.

Code: Select all

 
Can i remove one of them later on or do i need to redo the combination then?
 
Cant remove invidual objects, so need to re-create it. Better use it only for static scenes, and do not add any dynamic models to it,
so no need to re-create it.
Post Reply