Thursday, September 14, 2006

Lights and LOD

EDIT FROM 2/19/07: this article mentions some bugs with light visibility from X-Plane 850 betas. These bugs were fixed, and the mechanism of detachment is entirely internal to X-Plane. So please bear in mind when reading this that while this describes the internal engine of X-Plane, you as an author don't need to DO anything special for lights.

One user reported that the taxiway lights are visible a very long way away from the airport. This is true, but it is probably not a cause for concern. By comparison, the airport beacon has a way of disappearing - hopefully less so in beta 11. Here's what's going on:

(When I say "light" in this blog post, I mean the little ball of color that is supposed to simulate the look of a light bulb. "Fixture" refers to the 3-d object modeling the real-world device that holds that bulb in place. The actual rays of light cast are not simulated - that's why the approach lights don't illuminate part of the plane no matter where you fly. Current graphics hardware just doesn't give us that ability yet.)

In X-Plane 850 all "lights" are made via OBJ8 objects. The OBJ8 object may contain both 3-d geomemtry that forms the fixture, and one or more "lights", created via either the LIGHT_NAMED or LIGHT_CUSTOM command. Objects may also have multiple versions based on LOD. If you don't use ATTR_LOD, a single LOD range is assigned by X-Plane based on how big your object is. (Bigger objects will need to be visible farther away.)

Now here's where it gets weird. Some of the lights in an object are "detached" by X-Plane from the OBJ and stored separately in the scenery. We do this for performance - the detached lights can be fed to the graphics card via a different mechanism that is much faster than regular OBJ drawing. One of the effects of light detachment is that the detached lights are no longer limited by the LOD of the object. They instead are drawn to much further distances. The fixtures of the objects, however, are never detached...thus some of the airport light OBJs in X-Plane are only visible to 500 meters. We can get away with such a low distance because the light bulb itself is detached and will remain visible.

So which lights are detached? Well, it depends on a number of factors - lights are only detached if they are not subject to animation and they are simple enough to be drawn in bulk. Which lights are these? It's hard to predict.

So the airport beacon and taxiway light work differently; the taxiway lights are very simple and are detached - hence they are visible a long way away. The airport beacon lights are animated (the light bulbs rotate with the fixture), and are never detached. Thus the airport beacon is subject to LOD constraints and taxiway lights are not.

If you set the world level of detail setting to "low" or "very low" it simply reduces the LOD ranges of all objects. Thus on "very low" the airport beacon may be seen to disappear before the (detached) taxiway lights. For beta 11 I have tried to set the airport beacon LOD large to be enough that even on such low settings the beacon will be visible farther away.

There is one more piece to the puzzle: all lights become dimmer with distance. So in theory our hope is that the lights will become fully dim due to distance before we stop drawing them with LOD, producing a gradual fade-out rather than a sudden disappearance. But if we don't tune all of these parameters right, lights can randomly appear to disappear in the distance instantaniously.

If there's a moral of the story, I'm not sure what it is, except perhaps: this new light system is very new, and I am sure our artists will tune it a bit over the next few versions of X-Plane, helping to hide these implementation artifacts.

1 comment:

Anonymous said...

I recently drove by an airport (OLB) shortly after sunset and noticed a very strong flickering effect on the runway and city lights . Would be neat if X-Plane could simulate / fake that, too :)