Saturday, May 06, 2006

Use of LOD with objects

First the basics: you can use the ATTR_LOD command in an object to specify what distance range an object is seen from. This has two implications:
  1. You can have your object look different (and usually less complex) from farther away.
  2. Probably more important is - your object is not drawn from arbitrarily far away. All drawing is bounded!
This second aspect is actually the more important one...because at any given time most of the objects in the sim are too far away to draw due to LOD! But this begs the question: what happens if you don't specify ATTR_LOD at all? Is your object drawn from hundreds of miles away?

The answer is: if you don't specify ATTR_LOD X-Plane calculates an LOD for your entire object that starts at 0 meters and goes to a distance where we think no one would care if your object disappeared. The calculation is based on the bounding sphere of your object.

Our built-in algorithm usually works pretty well, but there are some cases where it gets fooled. One important case is: when you merge two small objects into one big object, the LOD distance goes up, because the total area that your object covers goes up!

What this means is: if you have a dozen small taxiway signs from XTaxiMaker, they'll all disappear relatively quickly as you go away from the airport, protecting framerate (by keeping the number of drawn objects down). If you merge those into one big object, the performance of the sim changes in two ways:
  • Framerate when the objects are drawn goes up - we now draw one object instead of five. The number of objects drawn is very important to framerate.
  • The objects will be drawn more frequently, so overall framerates maybe lower.
The moral of the story is this: if you merge objects for performance, be sure to insert an ATTR_LOD statement that is apporpriate to the actual distance at which point the objects are invisible, not the total "radius" of the object! Taxi way signs are not needed after 1500 meters, even if they cover the whole airport. Similarly some packages have taxiway markings in an OBJ. These objects usually cover big areas but the lines themselves are so thin that they aren't needed when far away.

(Also beware: LOD is calculated frmo the middle of the object, so if the object is huge, take that into account.)

As a final note, ATTR_LOD is "free". X-Plane will calculate and check LOD distances on every object no matter what. If you don't use ATTR_LOD, one is generated for you. So there is no harm in adding ATTR_LOD to your object. Your framerate will only go down if you pick an LOD that is larger than the sim would have picked for you.

No comments: