Optimizing Object Performance

This article describes how to optimize the performance of scenery and airplanes that use OBJs. OBJs are often the most expensive part of an airplane or scenery pack, so careful construction of OBJs can help.

= Identifying Performance Limitations =

There are three typical scenarios for object performance tuning:


 * 1) You have a small number of objects with a lot of detail in each one.  Typically you will be constrained on "detail" - that is, the total VRAM used by all objects, total number of vertices, and sometimes attributes.  A typical scenario might be an airplane, where there are only 20 objects, but each one uses a huge texture, a huge normal map, and has a ton of vertices.
 * 2) You have a moderate number of objects, each with a moderate amount of geometry.  But do to the repetition, the total vertex count is very high.  This is a case where the "leverage" of repeating an object causes problems.  A typical case might be a jetway that has a lot of detail and is placed into an airport scenery package 200 times.
 * 3) You have a huge number of objects; pure object count is the limiting factor, even though the objects themselves are quite trivial.  This can happen when objects are used to build cities, e.g. you have 10,000 building objects in a small area.

Before you can optimize your airplane or scenery, you must identify which scenario you are in. The best way to do this is to reduce the 'cost' of your scenery/airplane and watch performance change. When you find a crude technique that improves framerate, you know where your costs are.
 * Reduce the size of textures in photoshop.
 * Temporarily remove parts of a model to reduce vertex count.
 * Remove some objects from the scenery pack.

= Optimizing Detail =

If you have a few objects and are still having performance problems, there are a few things to look out for:

First, be aware of overall vertex count. X-Plane can handle fairly large models, but at some point you will run out of vertex budget. Use LOD to simplify meshes when viewed from far away. Two notes on LOD use for vertex count:
 * Don't use LOD to save a small nummer of vertices. For example, LOD to reduce from 100 to 50 vertices is not a win for detail-bound models.  But if your airplane is 500,000 vertices when viewed up close, LOD might be a real win.
 * You get maxmimum performance when an object is not drawn at all because the maximum LOD distance is set low. Separate details that can be eliminated entirely into their own objects, then set their LOD very low to avoid them.  The very act of drawing an OBJ is expensive, even if it contains one OBJ, so you save setup costs in this case.

The total amount of texture used by a model or scenery can start to crowd out VRAM. Here LOD is important too. If an object is not drawn at all because we are farther away than its highest LOD, then its texture won't have to sit in VRAM. But this only works if the texture is not used by any objects.
 * Organize your textures so that all details are in one texture, then use LOD to try to eliminate details when viewed far away.

Example: if you are building an airport, put all of your trucks, cones, and other small objects into one texture. Keep the terminals separate. The terminals will be visible from 10 miles away, but if all of the details have low LOD, the detail texture may not be used at all when on final approach, cutting down VRAM use.

Be aware that the cockpit object's texture is never compressed or reduced in size, so use this texture sparingly; use it only for details that must be crisp to make the plane flyable. If the user is running at a low texture setting, there is a reason for it!

= Optimizing Leveraged Geometry =

When you have a moderate number of high-cost objects, the total geometry can start to add up. For example, 200 jetways with 10,000 vertices each will add two million vertices to the scene. It's likely that all of the jetways are visible when the user flies over the airport; two million vertices is a lot, particularly when the rest of the world must be drawn too.

When working on an object that will be placed many times and has a lot of detail, use LOD carefully to avoid high vertex count. For example, it's fine to have a high detail jetway with 10,000 vertices as long as we have another LOD with only 1000 vertices and a reasonable transition distance. At any one time, most jetways won't be nearby and will take only 1000 vertices (for 200,000 vertices total) with maybe one jetway using 10,000 vertices. That's almost a 10x savings in vertex count.

But be aware: there is a cost to having lots of LODs, so generally you should only use two or three LODs.

= Optimizing Total Object Count =

When placing a large number of objects, the object count becomes the most important factor. Most users will have machines that can draw between 3000 and 8000 objects, per frame, depending on rendering settings, hardware, and drivers. When building cities, it's pretty easy to exceed these numbers.

The most effective way to cut object count is to make the farthest LOD of your objects be not too far away. When an object is beyond its maximum LOD distance, it is not drawn at all, reducing object count. X-Plane is very very fast at eliminating objects that are beyond their LOD distance. For example, X-Plane can easily draw an OBJ for every taxiway light (over 10,000 objects at KORD) because the LOD distance is only 500m on each light. Thus of those 10,000 objects, almost all of them are eliminated rapidly.

When object count gets large, small mistakes in the OBJs themselves start to add up. A single attribute in an OBJ can add one batch and make the OBJ twice as slow on the CPU to draw. For an airplane cockpit this is no problem, but if the OBJ is repeated 5000 times then we've added 5000 batches. When building an object that will be placed many times:
 * Do not use attributes if you can possibly avoid it.
 * Keep LOD low when possible.
 * If possible, use only triangles; avoid lines and animation.