In my previous two posts I described the problem of Z thrash in some detail, as well as the problems that polygon offset can have in fixing it. I also described how draping addresses these problems. In this post, I will tr to provide some specific rules for how to overlay geometry in your scenery.
Whenever possible ,use draping rather than polygon offset. If your goal is to put a marking on the ground, draping will always do that correctly, while polygon offset can create artifacts if not used properly.
For x-Plane 9, this means preferring draped .pol files to OBJs for putting markings on the ground.
For x-Plane 10, this means using the upcoming ATTR_draped instead of ATTR_poly_os to put markings on the ground.
When you do need to use ATTR_poly_os in an object, you do not need to increase the number – this number is not a layering indication; ATTR_poly_os geometry is drawn in the order it appears in your OBJ. Always have ATTR_poly_os geometry before any 3-d geometry you might want to include.
Finally, if you use ATTR_poly_os, be aware that you’ll want to use a low layer group like markings; if poly-os geometry is drawn after 3-d, you’ll see artifacts.
In my previous post I described Z thrash and how polygon offset is used to fix it. Now we can look at draping and runways.
The fundamental problem with sloped runways is that a runway is made up of tiles, but the ground underneath it may change slopes in unrelated locations. The following diagram illustrates the problem.

This is a side view of a sloped runwy: the green line is the underlying bumpy terrain and the black line is the runway, divided into multiple tiles. Recall from last time that we can only avoid Z-thrash using polygon offset if the two polygons are truly coplanar. Therefore, we can look at four ways to handle the situation and evaluate them for quality:
- In the top picture, the runway simply runs right through the terrain. This case won’t work, with or without polygon offset. In some cases the terrain is on top, and in some cases the runway is on top. The gap between the runway and terrain might be quite large for a significantly sloped runway.
- In the second picture, we move the runway up to clear all but the tallest part of the terrain. This won’t Z-thrash, but it will look pretty bad. There can be a large gap between the runway and the terrain; if you run your airplane off the side of the runway, you’re going to fall. The gap between the runway and terrain will be quite noticeable.
- The third picture is close – each runway tile is clamped to the terrain. But this still isn’t good enough; while most runway tiles now sit on the ground perfectly, a few will take a ‘short cut’ over or under the ground, like the case I have circled in red. So we’ll have less Z thrash, but some parts of the runway will still be broken.
- The last picture is what we really need: we break the runway tiles up into even smaller pieces where the terrain makes a change. The last tile on the right is now two tiles, each of which can sit perfectly on part of the terrain. Only in this last case can we apply polygon offset and get a nice clean runway.
This last case is exactly what X-Plane does. This technique is called draping – the sim ‘drapes’ the overlaid runway tiles on top of the runway like a rug. The sim breaks the tiles into pieces so that each tile can sit perfectly on the underlying terrain.
The real work of draping is not just in figuring out where the terrain below the tile is, it is in cutting the tile into the appropriate pieces that can ‘sit right’. The following pictures show this process in 3-d.
This is a screen-shot of a small piece of taxiway at KSAN. I have drawn in the outline of the draped polygon in yellow and the terrain triangles in blue. (The terrain triangles are quite large, so we can only see part of them running through the scene.
This is a wire frame of the problem at hand: we need to insert the yellow polygon into X-Plane, but we need to make sure that no triangles that we generate cross the blue line. The blue lines essentially represent “ridge lines” in the underlying mesh.
If we just had to draw the yellow polygon, we could triangulate it using the thick gray lines shown in this picture. However, this would not be good; the big gray triangle in the middle of this picture runways right across a blue line – there’s no way that this big gray triangle can “drape” properly across the ridge line.
This is what actually ends up happening. The gray lines are cuts we need to triangulate the polygon; the red line are cuts we need to not cross the ridge line, and the purple lines are cuts we need to ensure that everything is broken down into triangles (since that’s what the video card really wants). Once we have this triangulation, we can place every vertex on the ground and it will “drape” the way it should.
In my next post I’ll describe how you can use draping in your scenery to create images on the ground without Z thrash.
I think I have mentioned draping repeatedly, as well as Z thrash, without ever clearly explaining what either of these things are. I happen to have some pictures from recent work on draping, so here’s the basic situation.
What Is Thrash?
Warning to OpenGL purists: I’m going to play fast and loose with a number of OpenGL rules. Basically what I say here is the worst case. Sometimes things work out better than I describe, but if you don’t handle the worst case, you’re going to have problems some times. Nitpickers, consider yourself “on notice”.
When drawing 3-d polygons in OpenGL, if two polygons are coplanar, most of the time they will experience “Z thrash” – that is, the hidden surface removal hardware on the graphics card removes some parts of one polygon and some parts of the other, often removing different parts on each frame in a flickering pattern. The results look like this:
In this picture on the left, we see the raw result of coplanar airport polygons on top of the sandy desert terrain that is the airport surface area. As you can see, the graphics card has been a bit random in deciding whether the runways are “hidden” by the ground or not. If you could see the camera moving, you would see that the pattern of missing taxiways ‘flickers’ as the camera moves.
If there is an overall take-away point so far, it’s this: you can’t just layer coplanar triangles without getting a mess.
(What about moving the runway slightly higher than the pavement? This would have several problems. First, the amount we’d have to move them is horribly dependent on camera angle and video card Z-buffer performance. Second, we’d see the gap between layers; for markings that really do need to be coplanar, like a rubber mark on a taxiway, this would appear as a bug.)
The Cure is Worse Than the Disease
Fortunately if we have truly coplanar geometry, OpenGL gives us a weapon to fight this: polygon offset. Polygon offset is a cheat that tells the video card: “listen, if you ever have doubts about the runway and the ground, favor the runways by a little bit.” It’s a little bit like putting a spread on a football game: the ground would have to be closer than the runway by a margin before we stop seeing.
When we have coplanar geometry, we can use polygon offset to handicap the geometry we want on top. Problem solved, right? So why do I keep writing blog posts with titles like: The Sordid History of ATTR_poly_os or The road to hell is paved with ATTR_poly_os?
Polygon offset has three problems that can bite you:
- The amount of ‘margin’ you get depends on the camera angle. This can make for some truly bizarre effects. The only way to safely manage this is to carefully minimize the margin. (This is a problem for the programmer, not the artist.)
- Because the margin must be minimized, the geometry really has to be coplanar – small cheats can exceed the margin.
- The margin you give your top polygon applies to anything else that is nearby, which can cause even more weird artifacts. For example, if you polygon offset a taxiway, it can start appearing through the nose wheels of airplane. That’s another aspect that must be carefully controlled.
If there’s a take-away to polygon offset, it’s this: polygon offset can help fight Z-thrash, but it must be used in a very narrow set of cases, and it must be used very carefully.
In my next post I’ll describe how X-Plane uses draping to fight Z-thrash for sloped runways.
X-Farm has been canceled. Sorry.
However, there are some new MeshTool builds. Release candidate three fixes a crash on quit on Windows and fixes the SHAPEFILE_MASK command. Builds are here:
Speaking of Mesh scenery: Oahu’s out!
I didn’t think we’d be able to show this, but…
http://www.x-plane.com/blog/wp-content/uploads/2011/04/snout_view2.mov
Yes, X-Farm will have global lighting…
If there’s one thing I hear over and over from our users, it’s this:
Why are there so few farm animals in X-Plane? The deer on the runway are my favorite feature in the whole sim! Why aren’t there more animals in X-Plane? Please add more!!!
Now first, I’m going to let slip a little secret, because I know you guys are desperate for tidbits on X-Plane 10. The big feature in X-Plane 10 that is taking us so long to get right: moose! While the deer on the runway aren’t going to clock in at much more than 300 lbs, a fully loaded bull moose weighs about as much as a C152 at MTOW. (At least, according to Wikipedia…I’m not convinced a C152 that weighs as much as a moose can get off the ground.) Trust me, you don’t want to hit one of these things, even in a 747.
But that’s not the big news here. The big news here is a new simulator product we’ll be releasing this fall: X-Farm. X-Farm will be the first animal simulator to work entirely from first principles. X-Farm will use shoulder-blade-element-theory to calculate the forces on each part of each animal’s skeletal structure to simulate what the animal would do in the real world. Wanna put the head of an alpaca on a gorilla? Go for it! (Actually, that’s a terrible idea – Camelids spit.) Think Rover would look cute with 6 legs and a stinger? Our animal-modeling application Animal-Maker will let you fully customize your animals.
X-Farm will feature a completely rewritten Animal Traffic Control (ATC) module, with AI Animals that wander around the farm on their own, and herding dogs to chase after them. (The initial version will feature only 20 animals at a time, but we’ll be able to scale this number up over time; the animal AI is fully multi-core for great performance on your new Core i7.)
It’s too soon for me to give specific hardware guidelines, but I’m thinking a DirectX 11-class video card will be best for X-Farm; we’re putting a ton of new shader features into the core engine to support fur on the animals and grass for the fields. The facade system is greatly enhanced and can be used to build a variety of fences and paddocks to keep your animals where you want them.
Finally, I think we’ll eventually be able to get plugin support into X-Farm, so that you can customize the behavior of your animals and create custom animations. Hopefully Wade and I will have time to port XSquawkBox to X-Farm (new name: XSquawk), so that you can create flocks of birds and let them loose in your favorite VATSIM ARTCC. I hear ZBW loves that kind of thing.
*EDIT (By: Chris): I added some screenshots for all the impatient followers who just can’t wait another second to get some sneak previews of some farming. Obviously these are still rough drafts. I’m still working on getting the farmer to look as muscular and rugged as I really do. It’s close but not quite right just yet. Please do NOT ask for more screenshots. We have a pact here as developers that I’ll explain to you a bit since Ben already let the cat out of the bag about the product. Each time we get a request for more screenshots we do two things: 1) We drink from our glass of scotch 2) We go to our whiteboards and move the release date of the product out by one full week. We do this to be spiteful of course. We have so many products stocked up here just waiting for release but it’s more fun to watch the mania ensue. Coming Soon; Surgery Simulator “Demonstrate that steady hand as you remove the remote control that your dog swallowed from his upper intestinal tract”. We’re still working on the price of this one but let’s just say we’ll be doing a wallet-ectomy on you. Post Office Simulator “You get to live the life through Postal Employee Newman’s Eyes. ‘The mail never stops!’ Stack and sort bag after bag of mail trying to beat your best score.” and finally Department of Motor Vehicle simulator “Take a ticket and get back in line”. We’re hoping to release this one around fall of 2012 but that depends on how many screenshot requests we get. This one is very unique. You can play the worker at the counter handing out tickets. You also get to instruct people to get into the wrong line and then laugh at them as it takes them 45 mins to figure it out. There’s also a level where you have to put your “Next Agent Please” sign up as fast as you can. Beat your previous times. Play with your friends on multiplayer! Who gets to take their 4 hour break first?!
From fearless leader:
X-Plane 9.68 is here (in Beta) for Mac, Windows, and Linux!
Just some TEENY little tweaks and enhancements to make v9.xx perfect:
- new airport and NAVAID data
- fix for lighting in non-generic instruments with esys (rare bug)
- sound stays on when X-Plane is pushed to background on windows… as requested, and now in sync with Mac version for better consistency
- improvement in the situation saving and loading
Just run your installer (from X-Plane.com) with the BETA options turned ON to get it
Have at it and let me know how it goes!
austin
ps: X-Plane 10 is much, much, much slower in coming along than I planned.. but it is much, much better as well. It is slow because I have raised the bar ridiculously high for this release, simply because I CAN. SO, I am keeping v9 totally bug-free while v10 is developed, which I am hoping to have ready by the end of this year.
I am hoping to have v10 ready quite a bit sooner than that.
One user asked me about slow performance with an overlay scenery he created using GMaps. There are three things you need for fast orthophotos in X-Plane, and unfortunately his scenery is missing one.
Use DDS
I’ve written before about DDS. They key points here for orthophoto performance are:
- Since DDS is already compressed, the CPU has to do less work preparing the texture if it is going to be compressed.
- Since DDS is already pre-minified (meaning the smaller versions of the texture are already computed), if you are not running at ‘extreme’ resolution, the sim can simply load a lower res version. With png, X-Plane must load the full size version and scale it down on the CPU.
- Since DDS is already pre-minified, the sim doesn’t have to compute those minified versions of the texture on the CPU.
All of these things lead to much faster texture load times with DDS.
Use LOAD_CENTER
LOAD_CENTER is a directive that can be put in a .pol or .ter file to tell X-Plane at what location the texture needs to be at maximum resolution; X-Plane will reduce the resolution of the texture as you fly away from that point. LOAD_CENTER is important for orthophotos for a few reasons:
- It saves VRAM, since textures that are far away won’t be loaded at full resolution.
- When combined with DDS, it improves load time. Since some textures are loaded far away, they can be loaded at lower resolution, which (per above) is quick for a DDS file – less data, less load time.
Note that LOAD_CENTER causes X-Plane to reload the textures while you fly, so it requires at least one extra core to work well. It’s really important to use DDS with LOAD_CENTER; otherwise that reload time can get expensive.
Use a base mesh, not draped .pol overlays.
This is probably the most important thing: if you want to cover a lot of area with orthophotos, you need to rebuild the base mesh using .ter files, not cover it with .pol files. There are a few problems with using .pol files:
- Draped polygons are only ‘built’ for areas relatively near the airplane. So even under ideal circumstances, they are going to disappear in the far view. This way of using them (only when near the airplane) is a memory savings based on their intended use: for small surface areas like airports.
- Similarly, since the draped polygons are being built and destroyed as you fly, the amount of extra CPU work while flying is quite a bit higher with .pol files than with a base mesh (which only has to page the actual terrain). So a computer that might be fine paging .ter files can get behind in its work for .pol files. (Authors often use .pol files because they are easy to work with – specify a rectangle and X-Plane does the cutting and slicing…well, that work is happening while you fly, burning up CPU power that could be used to page the orthophotos.)
- Since .pol files cover the base mesh, you pay for your mesh twice – once when X-Plane draws the base mesh and once when it covers over it with polygons. This means twice the VRAM used to draw a frame and twice the fill rate.
If you want high performance orthophotos over an area any larger than an airport or down-town, please use .ter files!
Comments should work again – sorry about that. The anti-spam captcha plugin had a directory permissions problem. We need that anti-spam protection though – without it WordPress is a magnet for spam-bots.
This is a view of the underlying vector data for the current KBOS taxiway layout. It is floating above the ground because the data hasn’t been “draped” onto the layout yet. There are two copies because the data has been debugged once for each DSF tile that the airport spans; when the actual paint is put down, only one copy of the lines will end up on either DSF, so we don’t have double triangles.