LOD on meshes

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.
Post Reply
Jorus
Posts: 4
Joined: Wed Mar 09, 2011 12:49 am

LOD on meshes

Post 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.
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post 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
Jorus
Posts: 4
Joined: Wed Mar 09, 2011 12:49 am

Post 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++
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post 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.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Gorbstein
Posts: 37
Joined: Wed Nov 25, 2009 8:44 pm
Location: Scotland

Post 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.
Image
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post 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.
beer->setMotivationCallback(this);
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Post 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
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Post by hendu »

And the billboard solution will only get better once it's done in hw (see devsh's thread).
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post by polylux »

Right. Impostors are a good way to go.
beer->setMotivationCallback(this);
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post 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.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Jorus
Posts: 4
Joined: Wed Mar 09, 2011 12:49 am

Post 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).
Jorus
Posts: 4
Joined: Wed Mar 09, 2011 12:49 am

Post 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++.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post 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...
Post Reply