Implementing a level of Detail (LoD) system in XNA games

If you have big levels and/or a huge amount of 3d models you have to render you will find that the game gets slower and slower.

Before you try to  optimize the draw codes, please use a profiler to make sure, that the problem is not somewhere else. Maybe the update logic is the problem?

You have some ways to tackle the problem:

  1. optimize everything in your draw code and shaders
  2. tell the user to buy a better computer
  3. remove objects
  4. lower the quality of models

Or you could scale the quality with the power of the computer displaying them.

To do so in a quick (and a bit dirty) way go to your class that holds the model and decides which model is to render (might be only one there without a LoD system or damage system).

  • Add a second and third model.
  • Make low poly versions of your model. One really low and one somewhere around the quality you can life with.
  • Load these lower versions of the model in your class
  • Add some code to check the distance to the camera
  • Now simply make some if statements:
    • If(distance >500.0f) do nothing
    • If(distance > 300.0f) draw(lowest_quality_model)
    • If(distance > 100.0f) draw(average_quality_model)
    • else draw (high_quality_model)
  • Play around till the numbers make sense in your game.
  • You might also add a condition that a slow running game never renders the highest_quality_model
  • As my LoD system not only draws the model but the shadows too i could use the lowest quality model to draw the shadow.
  • I also added a condition that the game fist tries to stop drawing shadows and than lowers the quality of models even further till the point where only the lowest poly models really close to the camera a drawn and the rest is ignored.
  • Be carefull with drastic measures. It is not always good to lower the overall quality of models just because the game missed one or two frames somewhere. The problem might not be the draw code at all.

Hope this helps you.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: