Page 1 of 1

LOD on meshes

Posted: Wed Mar 09, 2011 12:56 am
by Jorus
Greetings,
I'm wondering if still any example on how to implement LOD on meshes.
My idea would be make a big city like in Grand Theft Auto, so i think LOD would be crucial.

PS. c++ beginner here.

Posted: Wed Mar 09, 2011 1:21 am
by Radikalizm
Dynamic LOD is pretty hard to accomplish, as far as I know the only implementation of this is inside the terrain scene node, but I've only skimmed through that code once in the past, so I couldn't tell if this would be applicable to other meshes (probably not)

You could however implement a scene node which holds a set of pre-made meshes each with increasing detail with every iteration and write it so that the active level of detail changes based on distance from the player

But for a C++ beginner this might be a bit too much, so I'd suggest to keep it simple until you are completely familiar with the language

EDIT:

For city scenes it might be better to go with some more advanced occlusion mechanisms instead of dynamic LOD, since such scenes allow for a great deal of optimisation in that field
Irrlicht supports occlusion queries I believe, so you could check those out

Posted: Wed Mar 09, 2011 3:29 am
by Jorus
Thanks for your answer.
Anyway should be exist an easy loophole, a simple code that could explain it better.

PS. I apologize but English isn't exactly my main language.

Image

This pic shows what is my idea of lod, its just hard to realize in C++

Posted: Wed Mar 09, 2011 3:58 am
by sudi
Actually Jorus that pic is easy to achieve with irrlicht....it just depends on how you want it. You could change irrlicht so that a meshscenenode/animatedmeshscenenode holds different meshes for each LOD level or implement a triangle reducing lib there are some out there. and then decide on rendertime which mesh to use.

Another solution would be to not mess with irrlicht and implement the lod one level higher with your entities so that they hold several scenenode which they set to visible/invisible when needed. or create a managing scenenode who decides which of its children sould be visible depending on camera distance.

And of course use some culling technics city scenes are perfect for those you could for example easily disable rendering of objects in another block which simply cannot be scene the player and then for the rest occlusion queries or something like that.

Posted: Wed Mar 09, 2011 9:45 am
by Gorbstein
Jorus wrote: This pic shows what is my idea of lod, its just hard to realize in C++
If I wanted to do it the easiest way to get me started I'd pre-create N different levels of detail (polygon complexity) for my models using whatever modelling software. Some modelling software can do this for you, or has functions to at least reduce the poly count (like optimise, in 3ds max). Then, I'd choose which view distances I want to display each of these N models. You'd have to find a balance based on speed and how good the models look at certain distances.

I'd make a custom scenenode (look at the tutorials) and instead of only holding one mesh, I'd have an array of N meshes, one for each detail level. When it comes to rendering, I'd find out how far away the node is from the camera, then render the best LOD mesh for that.

Here's some pseudo code off the top of my head.. you should be able to fill in the blanks using the tutorial examples.

Code: Select all


class MultiLODMeshSceneNode : public ISceneNode
{


//3 meshes - 3 levels of detail
IMesh* meshes[3];
//pointer to current level of detail
IMesh* currentLOD;
//  > SQUARED < distances where you want the LODs active
float distance1,distance2,distance3;

loadMeshes( ..list of filenames..)
{
   meshes[0] = smgr->getMesh("meshlod1.3ds");
   meshes[1] = smgr->getMesh("meshlod2.3ds");
   ....repeat for all levels of detail....
}

updateLOD(vector3df cameraLocation)
{
    //squared distance between camera and this scene node
    float distanceSQ = cameraLocation.getDistanceFromSQ(location_of_this_scenenode);
    
    if(distanceSQ < distance1) currentLOD = meshes[0];
    if(distanceSQ >distance1 && distanceSQ < distance2) currentLOD= meshes[1];
    ..repeat for all levels of detail ..
    
}

render()
{
  ..set up render stuff etc..

  //draw current lod mesh
  driver->drawMeshBuffer(currentLOD);
}


};

So you'd call loadMeshes at startup, then each frame call updateLOD and pass it the camera position.

Posted: Wed Mar 09, 2011 10:26 am
by polylux
I'd say Radikalizm is right, for city scenes the main portion of optimization is efficient occlusion culling. When moving though the streets you'll see some buildings, the rest is occluded.
Plus, if you'll do it as in GTA, most of the buildings consist of a couple of boxes so LOD won't do much here.

Posted: Wed Mar 09, 2011 10:56 am
by REDDemon
the best thing you can do is replace every building/groupOfBuilding with a axial billboard (with low texture resolution, up to 256x256 pixels) when you are looking the building from far.

if every building is made up of few polygons the best optimiziations you can do is culling building that are not visibles. When you are looking from far textures are optimized with mipmap(that's automatic), but you can always add custom mipmaps (lower resolution than autogenerated mipmaps, remember to blurr a bit those images). or just change LOD parameter of material settings.. Since you are moving using roads in a GTA style game you can instead of adding billboards for buildings add a "fake" at the end of roads. the idea is the same of paint the road on a wall:

Image

Posted: Wed Mar 09, 2011 12:28 pm
by hendu
And the billboard solution will only get better once it's done in hw (see devsh's thread).

Posted: Wed Mar 09, 2011 3:00 pm
by polylux
Right. Impostors are a good way to go.

Posted: Wed Mar 09, 2011 10:35 pm
by Mel
It is also a common error to rely on the distance to switch the levels of detail, It is better to use the covered area of the object on screen to make an approach of what LOD display. That can be calculated using the bounding box projection on screen, perhaps.

Posted: Wed Mar 09, 2011 11:50 pm
by Jorus
polylux wrote:When moving though the streets you'll see some buildings, the rest is occluded.
Occlusion culling would be awesome, i will search for an example tutorial on how implement it. Thanks anyone for his own answers.

Edit: Just did some "googling", is occlusion culling already implemented in Irrlicht?
I'm using the last svn revision (at the moment 3605).

Posted: Thu Mar 10, 2011 5:54 am
by Jorus
My last edit: I finally found what was looking for, LOD was implemented by default in another engine but always based on Irrlicht, its name is Lightfeather 3D. I'm switching there, atleast until i'll learn C++.

Posted: Thu Mar 10, 2011 9:05 am
by hybrid
Yes, occlusion culling is already implemented in Irrlicht. Simple discrete LOD is probably best kept in a scene node animator, at least as long as only different resolutions of some mesh are used.
When including impostors it depends on which implementation you use. bitplane's version was making use of grouping many impostors into one node to speed up the rendering a lot. This would require some higher level of access to the meshes, as you'd group many scene nodes into one.
BTW: Without C++ knowledge lf is also a little too much for you probably...