Sunday, September 13, 2009

Marking the Ground? Use a .pol or .lin.

The rule is very simple: if you want to put a marking on the ground, your results will be much better if you use a .pol (draped polygon) or .lin (draped line) than if you use an OBJ. In fact, an OBJ is probably the worst way to put markings on the ground.

Requirements for Good Looking Markings

In order for markings to look good you need to have three things happen:
  1. You need to make sure your markings are at the exact same level as the ground itself.
  2. You need to use polygon offset to tell X-Plane to tell the video card that these are "coplanar" (at the same height) triangles that must be managed in a special way.
  3. You must guarantee that the draw order is: the stuff under your markings, your markings, then the 3-d buildings and other 3-d stuff.
With these requirements we can compare .pol/.lin files to OBJs:
  1. .pol and .lin files always "drape" to the ground, so they always meet rule 1 perfectly. With an OBJ you can set the height of your OBJ to 0 but on sloped terrain this won't be correct.
  2. .lin and .pol files are always "polygon offset" automatically, so they always meet rule 2 perfectly. With an OBJ you need to use ATTR_poly_os.
  3. ATTR_layer_group (or LAYER_GROUP) tell the OBJ or pol/lin in what order to draw, so you can set this correctly in all cases. The default values if you don't specify a layer group are more appropriate to the task of markings on the ground when you use a pol/lin - that is, by default they meet rule 3 perfectly. By comparison, an OBJ may not be in the right draw order.
So we can see from these 3 rules that you will always get the rules right just by using a pol or lin, but you have to be very careful and may still not get the rules right when using an OBJ.

Performance? Think .pol

When you have a large number of small markings, the performance of a .pol is going to be significantly superior to the performance of an OBJ. For example, imagine an airport where you want to draw on-pavement signs for all taxiways and runways. With an OBJ, to get the height right, you'd need to use a large number of small objects. (With one large object, it will be nearly impossible to make the OBJ markings be on the ground when far from the object center.)

When you use a large number of .pol markings that share one common texture and all have the same .pol file, X-Plane merges them behind the scene into one huge object-like pile of triangles. The cost of drawing all of those polygons will be similar to the cost of drawing just one object! That's a huge speed win.

Floating Objects Are Wrong

What I see most commonly in scenery packs that are sent to me and have thrashing problems are OBJs that have a height other than 0. This is simply the wrong way to create overlaid geometry in X-Plane, and it will produce artifacts in a wide variety of situations. At best, the "floating" objects will cause airplanes driving over the marking to look like they "sink in". At worst, the offset you pick will be too small for the video card's resolution and you'll get thrash anyway.

There is no one right vertical offset for all scenarios, and even if there was, it would still look ugly! See the above rules for what an OBJ really has to do.

How Do I Get a .pol into my scenery.

Well that is the $10,000 question. I must admit that I don't know what Overlay Editor's capabilities are in this regard. WED 1.1 will be able to add draped polygons, including texture coordinate editing of the polygons. I've been working on the texture coordinate editor in WED this weekend and am hoping to get some kind of WED 1.1 preview built this week.

With WED 1.1 the process is fairly simple:
  • Create your texture.
  • Create a single .pol text file that names the texture, so you can use it.
  • In WED 1.1 you can select the .pol from the list of resources for your scenery pack, and then use the "polygon create tool" to simply draw the draped polygons into place.
  • Once the draped polygons are created, you can select the polygon and open the "texture coordinate editor" tab to edit the way the texture is applied to the polygon.
My hope is that this process will be easier than creating markings using a 3-d editor - you can still edit the texture coordinates, but you can do so directly in WED.

3 comments:

Hotdog said...

Hi Ben,

Interesting as always. Are there any plans to support some kind of overlay mesh in the future? I see guys using airport functionality trying to fix problems in the existing X-Plane mesh. This could be a way to test "fixes" or "enhancements" that could be approved and added to future render farm sessions?

Kind regards

Benjamin Supnik said...

Not yet. X-plane's scenery architecture makes fixing mesh problems locally (not on a tile boundary) very, very difficult.

So...first priority is: improve tool chain for mesh generation. If after it is possible to build a new mesh from a UI people are still fighting to correct local areas, then I will revisit this.

But right now it is nearly impossible for a non-programmer to regenerate a base mesh, so I don't think the notion of regenning a base mesh has really gotten a fair shake.

Cormac said...

Hi Ben,
Glad to hear WED v1.1 might make an appearance soon and that it will have polygon editing. I fully understand the advantages of using .pol over .obj for airport surface markings but one area where .obj has an advantage is the ability to define the size of the marking components in a reproducible fashion. This would be particularly useful in order to provide such markings for use in OpenSceneryX or any other library for scenery authors whose skill levels don't extend to building their own components. I am not aware of OE's or WED's ability to size (or even shape) polygons precisely and repeatedly, i.e., not using the mark-I eyeball.

Besides, I still think taxiway and other ground markings should be provided for in the same way as taxiway signs, with users availing of a simple scripting system to leverage a compact set of graphics resources to produce any of the infinite array of possible ground markings.