Blog

Another Planet Framerate Improvement

I just realized that the planet-wide rendering was running at 65 fps on my G5 with clear skies but less than 20 fps with a single cirrus layer! Ooops! With X-Plane 850 we use the same OpenGL code to draw terrain whether it’s close-up (DSF) or far away (the planet render). This seemed like a good idea because it helped the two mesh. Well, it turns out cloud shadows are way too slow when applied over a huge area.

So…I simply killed them. This will be in the next beta. If you look hard you’ll be able to see a slight color change (well, worse than before) where the cloud shadows disappear at the DSF->planet transtion, but the fps are worth it. The G5 went from less than 20 fps looking at the planet to 65 fps, and the MacBook Pro went from 36 fps to 100 fps.

This was never an issue in 840, where the planet had the simplest OpenGL code you can imagine and looked like, well, just compare the planet in 840 vs 850!

Anyway, this explains why I thought I’d fixed the planet code and users cried bloody murder: my standard framerate test has no weather, because that’s Austin’s code. (Hence I shut it off to check the performance of only my code.) But sure enough it was the weather that affected the “cost” of the planet render.

There is a moral here for programmers: always test performance under real-world conditions! Often a system can have interdependencies that don’t appear in “lab” conditions. (Another example: you can’t test the speed of airpor build-up without scenery because one of the slowest parts is “draping” the airports over the scenery. When there is no scenery the ocean terrain triangles are very large and so the draping happens much faster than it can with real ground.)

2 Comments

The road to hell is paved with ATTR_poly_os

I’m note sure I can even explain this…basically “polygon offset” is both the darkest voodoo in OpenGL and NOX for OpenGL programmers…usually it helps you win but sometimes it causes you to go down in flames.

The basic idea of polygon offset is this: normally you see the closer of two objects ‘on top of’ the farther one. This idea is so obvious to us humans who live in a 3-d world that it’s almost hard to explain. Imagine I am a painter. If I draw two mountains, the one I draw second will always appear “on top of” the one I draw first in my painting…thus I must draw the far mountains first and the close mountains second to get a realistic landscape.

OpenGL provides “Z buffering”…basically this lets you draw the mountains in any order and the graphics hardware takes to not draw the pieces of the far mountain that need to appear under the near mountain in order to make the 3-d image look realistic.

So where does polygon offset come in? Well, the problem is that if two pixels we’re drawing are very very close to each other in distance from the viewer, OpenGL’s ability to decide which one goes on top falls apart. It turns out there are limitations to the math OpenGL can use. In particular, if I have an object with two triangles that are exactly on top of each other…OpenGL will randomly show some pixels from one and some from the other! Yuck! This is called Z-thrash.

This is where we bring in polygon offset. Polygon offset is a trick where you tell OpenGL to handicap the competition between two triangles. You say “listen, I know that the grass and the runway are probably about equal distances from the viewer…but handicap the math by adding 2 to the runway in all cases”. What happens? The runway always wins! In other words, polygon offset is a cheat that helps assure that given two pieces of scenery on top of each other, the ‘right’ one always appears on top.

For more discussion on polygon offset, check out this article from the scenery web site.

Whew. Well that was fun…we use polygon offset on runways (to make sure they never thrash with the ground textures) and it just works great. But when it comes to roadways, things really go to hell.

Polygon offset has two strange quirks that make it tricky to work with:

1. If you cheat and use polygon offset to help a bit of scenery ‘win’ the distance competition, there is a risk that the cheat could push it through other parts of the scenery. (This mainly happens if you use too much polygon offset.) For example, if we used too much polygon offset on the runways, they would start to appear ‘on top of’ the airplane! It turns out there are two ways to manage this…we can tell OpenGL to “cheat once and forget about it” or “cheat every time you use this triangle”. Both ways have their own problems.

2. The amount that OpenGL cheats and adds some to the calculation about “who is closest” depends on the angle from the viewer to the triangle in question! Take a second to consider that…if you look straight at the runway from the top, OpenGL is only adding 1 or 2 to the calculation – but if you then sit on the runway looking down it, perhaps it’s adding 10 or 11! I can’t hope to explain this aspect of polygon offset without going into the mathematics of 3-d frustum projections, but I will say this: this property is both necessary (if it didn’t work like this, most times polygon offset wouldn’t provide a decisive winner between two triangles) and a pain in the ass, because it means that relatively large offsets can be used at certain view angles.

(In fact whenever you move the camera and see one piece of scenery “eat” another, then go away, this is what you’re seeing – we’ve used too much polygon offset and at a steep view angle the amount added to the math is too huge.)

Now I think we know enough to understand how X-Plane’s roads became the road to hell.

Generally speaking, any time you put something directly on top of the terrain mesh, you need polygon offset to assure you see it and not the terrain under it. This is true for beaches, runways, and of course roads. (Authors making airports out of OBJs know that their tarmac objects need ATTR_poly_os too!!) So I think we can at least see that we need polygon offset for roads on the ground.

Now consider bridges. They are up above the ground, so technically they don’t need polygon offset. But if a bridge segment starts on the ground and climbs up, it will be eaten by the ground. So I decided to polygon offset bridges too, and that was okay.

Then came cars. The problem is: do cars have to be polygon offset? Well, it turns out we lose either way. Recall that there are two ways to handle the ‘cheat’:

– If we only offset bridges once then they appear above terrain, but one bridge may incorrectly appear above another, because the cheat is not permanent.
– IF we offset bridges “permanently” then they will appear above the cars on top of them.

Okay so let’s offset the cars too! It turns out that that doesn’t work. Recall that the amount of offset is a function of the view angle of the triangle. Well, 99% of the time roads are horizontal, as is the terrain. So offsetting is okay – everyone gets about the same cheat.

But a car is made up of triangles going in all different directions…the result is that if you offset a car, then the roof offsets more than the doors! This just looks terrible. And even worse, the headlights, for technical reasons, always offset the minimal amount. (Geeks: they are billboards – they are quads that always look straight at you, so they always have zero view angle!) Bottom line is: you can’t cheat the cars effectively onto the roads. Up through beta 11 you have seen this awful result..the cars look like they are inside the bridges.

Now since most of our cars drive on the highways, and since the highways (at least in the US) are mostly bridges so they can go over the regular road grid, this artifact is visible just about all the time.

So for the next beta I am backing off to the lesser of two evils: the bridges will not be offset. This means the cars will look great on the bridges. What you will see is a gap, like the one shown here. What this is: right as the bridge starts to “rise” out of the ground, the polygon offset cheat is turned off, and so for a little bit the ground consumes it.

4 Comments

Stupid Library Tricks

Here’s something a little bit surprising about the library: the EXPORT command in a library.txt file cannot replace another file in the same package.

For X-Plane 850 we added cars driving on the left side of the road for New Zealand, the UK, Japan, and other countries that drive on the wrong side of the road. Unfortunately what I did was export two road.net files from the same package – one with a region restriction (to these few countries) and a later one with none.

Consider the sum of these two statements…the result is that in New Zealand, the UK, etc. the sim will use either of the two road.net files, picking randomly.

850 will address this with a new library command. Whereas the “export” command normally provides one of multiple alternatives within a package (but replaces any lower ranked packages), the new “export_exclude” command will replace alternatives both within the same package and within lower ranked packages. Commands are treated sequentially, so an export_exclude should usually be at the top of the library.txt file.

Posted in Scenery by | Comments Off on Stupid Library Tricks

Get That Airport Faster With…

I was at least as surprised as you will be to discover that…

..when you pop back to your starting location using replay mode, the airport appears (belatedly – see the previous blog entry) almost five times faster if you turn off texture compression!

What the hell?!?! 🙂 It’s almost as if some idiot programmed X-Plane to load scenery five times slower if texture compression is on. Oh wait…that was me.

The problem is: how to balance the importance of keeping the framerate up with the importance of loading airports before you get there? All background work involves stuff we might do in the background (if you enable the rendering setting), maybe on a second core/CPU if you have one, and also some talking to the graphics card. We can only talk to the graphics card between drawing frames* and doing so stops rendering.

It turns out that in X_Plane 8.30 when we developed background loading, I put in the “go 5x slower” option because compressed textures visibly halts the sim as the graphics card stops rendering and compresses each texture. Without this 5x slowdown in background work, flight becomes stuttered and bumpy. The problem is that the 5x slowdown means we’re going through airports at a much slower rate than we should be.

I am working on airport tuning now…there will still be a delay before you see airports if you use instant-replay to move around fast enough (this delay is about the length of time the sim would have spent halted during scenery load but now no longer does) but the responsiveness should be a lot better.

(Here is a discussion of dual-core for Flight Simulator X…tdragger explains the issues well, and I think they apply to any graphics-intensive real-time or near-real-time simulation, so it doesn’t surprise me that both X-Plane and FSX offload similar types of work to extra cores.)

*Newer OpenGL drivers get around this limitation to various extents; we will eventually support this in X-Plane.

Comments Off on Get That Airport Faster With…

Where’s the Airport???

Sometimes with X-Plane 850 you may reach your destination airport only to discover that…it’s not there! What’s going on???

Well, in X-Plane 850 3-d scenery is created while you fly. This includes roads, trees, buildings, and most importantly airports. So…if the flight simulator cannot build 3-d scenery as fast as you fly, you may get to the airport and discover and it’s missing. After a while, it will appear. The easiest way to see this is: go to replay mode, so you can easily move a huge distance just by dragging the replay slider. This will “thrash” the 3-d scenery build-up and a bunch of airports will be missing.

There is one exception to the “build-as-you-fly” rule: whenever you do anything that changes the scenery situation from a dialog box, X-Plane says to itself, “well, the user is already not flying, because a dialog box is open…why don’t I take the time now and create all the 3-d scenery nearby”. So when you place an aircraft at an airport, change certain rendering settings, etc. then the sim builds the airport up front and it will always be there.

I do not yet have a fix to the problem of missing airports. For now I recommend that you consider turning down your 3-d scenery; often a lot of roads or objects can cause the sim to get behind in its 3-d work. I am working on making the code more efficient.

Comments Off on Where’s the Airport???

Beware the GMA950 iMac

Apple has released new iMacs. Previously the iMac was the best X-Plane experience for the dollar among Macintosh hardware offerings. It still is, mostly.

But…the cheapest smallest iMac, at an affordable $999 does not have the kick-ass ATI Radeon X1600 graphics card. Instead it has the, well, ass GMA950 integrated graphics.

If you are looking to buy an iMac and are even going to think about playing X-Plane, buy the more expensive box and get the ATI card. You can’t upgrade iMacs, at least not in any way that I’ve ever heard of, and the GMA950 is never going to perform well.

More importantly, as X-Plane progresses we will take more and more advantage of hardware shaders, and the GMA950 is missing a major set of shaders. So even though the iMac itself is blazingly fast, the video card will simply be unable to show a lot new features.

2 Comments

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.

Posted in Development by | 1 Comment

Quick Note: Unstable Formats During Beta!

I just moved into a new house…comcast shows up on Monday (in theory) so until then I won’t be posting much or answering email, but a quick note on 850:

The new extensions to the apt.dat format for 850 are not considered final until we go “RC” (releae candidate). So…

…if you are experienting with 850, please expect to have to update your work during beta. If you don’t want to change your work please wait until we are RC!

…if you are trying other people’s 850 experiments, they may not work if they haven’t been updated to the latest X-Plane.

The beta period is definitely experimental. Once we go RC, we’ll freeze the format so that third parties can make scenery.

Comments Off on Quick Note: Unstable Formats During Beta!

A missing PC?

Continuing the thread of hardware and how the market doesn’t always provide the machines we want…let’s look at Windows.

We’ve hit a point that people have been saying would come for years: computers aren’t getting faster – they’re getting cheaper. Technically computers are getting faster, but there are now ultra-low-end Windows machines that aren’t much better than what you could get a few years ago. But they are so cheap!

Consider a quick visit to Dell’s website. Their cheapest low-end machine is less than $300 with monitor! Insane! It’s not much of a machine to a flight-simmer, but it is a 2.5 ghz machine with 256 MB of RAM and an 80 GB hard drive. Put a cheap RAM chip in and that’s basically what I got as my flight sim machine a few years ago.

The problem is – to get the price down, the machine’s had the parts totally stripped out of it. The graphics are going to be an embedded chipset, probably Intel’s, and they’re not going to be usable for games. Want a PCIe 16x slot? (Accept no less for a flight simulation machine these days?) I couldn’t find a Dell with one of these for less than $650!

Perhaps this makes sense – consider what my MacBook Pro is doing right now and how much of its CPU capacity is used:

– Email: 15%
– Word processing with real-time spell-check: 6%
– Surfing the web: 10-40%

Of course if I go launch X-Plane…

So if I was really talented and could do all three of these things at once, my computer would still be overqualified! For the average person, the sub-$300 computer is just great. It does what they need and is becoming very affordable.

Where things get tricky is when one of those users wants to try X-Plane for the first time. In order to get the price down to $300 Dell has had to cut to the bone on all components. So what we’re seeing from users who have new machines is the have’s and the have-not’s.

The haves have new motherboards with fast memory controllers, large caches, dual core chips, and 16x graphics slots – the card in that slot is usually a monster. (Even last generation’s mid-range cards like the 6600GT were very powerful by X-Plane’s requirements.) The have-not’s have a machine with integrated graphics and no slot to replace them with, very little cache and slower memory controllers.

There isn’t really a point to this blog entry…the market is just meeting people’s needs. A summary of my observation is: where a rising tide of technology lifted all computers a few years ago, that push is now lowering price instead. As a result, many users have machines that are not way overpowered for their day-to-day work and are thus underpowered when they discover flight simulation.

Comments Off on A missing PC?

A missing Mac?

As I catch up on Steve Jobs’ keynote for WWDC 2006 (where they announced the new quad Intel Mac Pros) it occurs to me that there’s a missing slot in Apple’s product line that makes things tricky for X-Plane users.

At this point I wouldn’t say that Apple is expensive (they’re not cheap, but the internal components aren’t cheap either). The problem is finding what you want.

The MacBook and Mac Mini are reasonably affordable, reasonably fast (now that they’re Intel-based) and do most things that users want. But both have Intel graphics chips, which make them hopelessly underpowered in the graphics department for X-Plane.

The MacBook Pro and Mac Pro come with great graphics chips and are great high-end products, but clocking in at over $2,000 they’re outside the ballpark of what most people will pay for a home computer.

The iMac is probably the best bet for a home flight-sim user. At $1300 it’s not too expensive, but it comes with a great graphics chip, is a fast overall computer, and flies the sim real well. The flat screen looks good and it’s a nice clean machine to have on your desktop.

What Apple hasn’t made (and I suspect never will) is an $800-$1000 desktop with fast graphics and no monitor (a mini pro if you will) and a graphics card in a slot (so it can be upgraded). Such a box would be the best choice for a Mac for flight simulation, but since it doesn’t exist the iMac’s the next best thing.

To end with a minor rant: the new Mac Pro comes with the nVidia GeForce 7300 GT as one of the options. This isn’t a bad card – today’s cards are now so fast that even the “low end” ones are fast. (Compare to the 5200FX, which was unusably slow from day one.) But a low-end nVidia card in a $2500 Mac? The previous-generation 6600 GT outperforms it in fill rate and memory bandwidth. This isn’t the first time Apple’s shipped a big machine with an option for an inappropriately slow graphics card. (I suppose I’m seeing the world from the perspective of a gamer.)

11 Comments