I’m going to keep going with “random stuff I looked at today” and see if there’s something for authors mixed in.

I spent part of today measuring shader and texture changes in our engine under heavy load – my goal was to get a sense of how much data we’d be pushing through a next-gen API (e.g. Vulkan, Metal, DX12) if we just did a straight port of the engine.  This was just a fact finding mission.

The only problem was: the numbers were just absolutely awful. Terrible. Unusable!

Then I noticed the other thing: the entire area of KSEA was littered with thousands of Fed-Ex trucks.  Just tons and tons of them!  Only Fed-Ex trucks on the road, and only Fed-Ex trucks parked on the street.

Wha?

Leftovers For Lunch

The Fed-Ex trucks were a left-over. I do this to myself all the time: I create a dumb custom scenery pack to test some part of the sim and then forget to remove it from my working X-Plane folder.

Before X-Plane 1040 there was a bug where cars and trucks on the road could crash the sim if you viewed them across a DSF tile boundary and the 3-d models were not instanced. This last point is why the bug went unfixed for so long; the car set we ship with is entirely instanced for performance.

So I built a library with a Fed-Ex truck that was intentionally not instanced to reproduce the bug and forgot about it. The custom scenery pack was why my traffic looked silly, and the non-instanced traffic was why my stats showed the rendering engine doing 4x more on the CPU work than it was supposed to.

(Since X-Plane was in debug mode, the framerate was expected to be terrible due to unoptimized code and debug checks running on an old laptop with the scenery cranked to the max.)

So there’s a take-away here and it is:

OBJs in a Custom Vehicle Pack Should Be Instancing-Friendly

There are a few custom vehicle packs for X-Plane floating around the web, and the quality of the objects with regards to performance is mixed and overall not very good – probably some of these packs pre-date X-Plane 10.

Instancing is the ability for X-Plane to draw more than one OBJ in a single instruction to the GPU. We implement instancing by observing your OBJ as we load it and noting whether the OBJ contains anything complicated (dataref usage, animation, lots of material changes) or if it is more or less just a big pile of triangles.

If we have the latter case, then we mark the object as instancing friendly, and when it is drawn, all objects of that type are collected and drawn at once. The instancing code path in X-Plane is thus separate and much faster for both X-Plane itself and the driver.

Since you can have a lot of the same car on the roads, even with a varied collection, it’s worth it to be instanced!

How to Tell If Your Object Is Instance-Friendly

To see if your object is instancing friendly:

  1. Make a custom scenery pack and place ten of the objects very close to each other (e.g. at an airport).
  2. Load the airport in X-Plane and in DRE set the art control “terrain/kill_clusters” to 1.

When you do this, all of the instanced objects that come from DSFs will disappear, and all of the non-instanced ones will remain.

Your object will be instance-friendly if:

  • It uses no animations
  • It uses no ATTRibutes mid-object – use the new GLOBAL properties instead
  • For cars, LOD is okay (but non-additive LOD will make the WED test fail). For cars you should only use one LOD anyway.
  • Only some named lights are instancing friendly; fortunately the headlight/taillight ones are.

Draped geometry is instancing-friendly, but don’t use it for vehicles.

In the new Blender 2.7 exporter (and our branch of the Blender 2.49 exporter) instancing is made quite easy: you mark an object as “instanced” and one of two things will happen:

  • Blender will write only stuff that is instancing friendly or
  • The export will fail with an error telling you what you did wrong.

Thus when you -need- something to be instanced (scenery objects, etc.) you just tell the exporter to enforce it.

Here are some things where instancing really matters:

  • Repeated buildings in autogen.
  • Static aircraft that repeat a lot.
  • “Clutter” on the ramp (baggage trucks, etc.).
  • 3-d modeled vegetation that gets repeated.
  • Cars (both parked and moving)

Here are some cases where it does not matter:

  • Aircraft-attached objects. Since aircraft attached objects aren’t usually repeated and almost always have a lot of complicated stuff, instancing doesn’t matter or work here. Instancing is really for scenery.
  • Single extremely complicated objects like the Nimitz.

Right now objects drawn with the XPLMDrawObjects API call do not benefit from instancing, but this is probably something that will change in the future, as long as every “instance” is fed through a single XPLMDrawObjects call.

About Ben Supnik

Ben is a software engineer who works on X-Plane; he spends most of his days drinking coffee and swearing at the computer -- sometimes at the same time.

12 comments on “Third Party Cars Should Really Be Instanced

  1. I for one have noticed to many instances of police cars when flying around, not sure if this is a general bug in XP or a product of thirdparty OSM packages like world2xplane etc. not emphsizing on the latter, just an example.

    But I am pretty sure this is a general osm data biproduct, same goes with powerlines and lighthouses which seems to me are a handful in osm data.

    Glad you figured out the port performance issue to i.e. meet Vulcan API, sure hope Austin pay you enough 🙂

    Good luck with that Ben..

  2. At this point after your previous post, Ben, about instancing , I began to lean the Blender2.76b. Initially it was a dark dungeon for me after working in SketchUp. But gradually a light appears and I could to say that Blender is a powerful tool, allowing to do the cool instancing able stuff for X-Plane. So curiously, approximately, how much time will continue a work over XPBlender2.7 exporter and will there be contained a script for export AGP files. Thanks for your work.

    1. I’m not sure how soon the release will come -you can try the branch in github now. There will probably be an AGP exporter at some point but it’s not our first priority.

  3. The Vulkan API appears to be very interesting; in my experience, X-Plane with the PRO tools is quite adequate for casual simulation (i.e., home simulation or cases where folks don’t care about steady update rates). But for cases where 60-Hz steady-state frame rate is really important, X-Plane falls short, largely due to massive frame rate stutters (probably during scenery paging) even on high end GPUs (Kepler, Maxwell). If X-Plane solved this (with a new Vulkan API implementation or other), it would go a long way in our organization to being take more seriously as a real-time 3D simulation solution where we need at least 60 Hz steady state update rates (or even higher for some studies we are doing).

    1. Vulkan is necessary (but not sufficient) to have totally smooth rendering, which is a long term goal of ours.

      When I first started using X-Plane (version 6) X-Plane would actually pause for a second or two while scenery paged. So it was never a design goal at the time to have ‘no stutter’ flight. So we’re in a situation now where we have been trying to make everything as efficient as possible, but there can still be stutters.

      What we’ve started to do lately is write code that -never- stutters, e.g. all expensive operations are asynchronous on another thread. But once we work through all of our systems, we’ll also need to be on a driver that makes good guarantees about what is fast and what is slow, which Vulkan does and OpenGL (and DX11 and earlier) do not.

  4. Hi Ben, instance objects are very great, but i personaly have a little problem i can t define a library definitions for instanced objects for a small area.
    The only way to make this is defining an area from 1×1 tile and include all arround tile so the area extend to 4 tiles and this is huge area.

    How is recomendable define library for small area ? Or you looking in futere for made this more acesible?
    Thank you!

    1. It’s a design limit of the library that regions are 1×1 – it’s a feature meant to stylize an entire area (e.g. an entire continent), not to modify a single airport. We may someday be able to improve this, but it’s not going to happen any time soon.

      Higher priority to me is to remove a limitation: the library doesn’t substitute airport furniture from apt.dat. This is just how the original library was coded, but it would be better if we could make at least some of this stuff regional.

  5. Hi Ben I have a question what PC you modify X-Plane 10?
    The release of version 10.50 will not be resource-intensive textures such as for example water quality, which in other flight simulators regardless of the level of quality (very high) does not affect fps in flight simulator and X-Plane at this moment they are very resource-intensive, is it not possible to optimize the shaders to the program worked smoothly. Again, very strange decision not to develop the textures of the seasons depending on the climatic conditions of the landscape,while even in Microsoft Flight Simulator 2004 was attended by snow and drifts. while FS2004 was released in 2003. I think many simmery would have been happy to this innovation. Thank you

    1. Hi Kirill,

      Please: no more off topic posts requesting seasons. I am aware that you really, really, really want seasons because you have posted this to the blog many times.

      Please do not post about seasons again on any post that is NOT about seasons in the original topic; such blog comments by you will be deleted from now on.

  6. Thanks for this informative post!

    Are facades supposed to be instance-friendly?
    or is it a specific thing for OBJs?

    I tried “terrain/kill_clusters” and it showed me a few OBJs that aren’t instanced in a scenery Im creating a thing that I will change of course , however because it covers a big area at some places I imported OSM data and use facades for them in Xplane.

    1. Facades are never instanced. They can’t be. There are two broad categories of 3-d stuff: OBJects and “everything else.” Everything else includes terrain, POLs, forests, facades, and roads. The “Everything else” bucket is never instanced because it is never repeated; no two facades are identical.

      Only some of the OBJs can be instanced.

      But…If you have a type-2 facade, it can have attached objects and those can be instanced – same with roads; the attached objects can be instanced even if the underlying entity is not.

  7. I would really like to see are my custom objects instance-friendly but I just can´t figure out how to “Load the airport in X-Plane and in DRE set the art control “terrain/kill_clusters” to 1.”
    Could someone please come up with step by step instructions how to archieve this?

    Thanks,

    MarkV

Comments are closed.