Author: Ben Supnik

New Texture Commands

If you look at a lot of the text file formats we often have something like this:

TEXTURE
TEXTURE_LIT
TEXTURE_NOWRAP
TEXTURE_NOWRAP_LIT

etc. It’s a bit of a disasteer. The problem is that the command is encoding two separate ideas:

  1. What the texture is used for (primary texture vs. lit vs. composite vs. mask)
  2. How the texture is loaded (with wrapped vs clamped edges)

What got me looking at this was a test Sergio did with some ground lighting. He had texture compression on and his nice lighting and halo textures were absolutely trashed, because texture compression isn’t very nice to alpha masks.

Internally we deal with this by marking textures as “not to be compressed” — this is why the clouds don’t look ugly. I thought, “why don’t I make this available in OBJ and pol files…that’s not very hard”. But do we really want this?

TEXTURE_LIT_NOCOMP
TEXTURE_LIT_NOCOMP_NOWRAP

So I’m thinking we may need a syntax that separates the “what” (what slot in the scenery the texture is used for) from its settings. Something like this:

TEXTURE2 -nocomp -wrap my_truck.png
TEXTURE2_LIT -comp -nowrap my_truck_LIT.png

The “flags” would affect how the texture is loaded (the two obvious ones are wrapping/clamp controls, and compression-inhibition) and the command name would say what the texture is used for.

I am also looking at adding normal maps to objects – this would be a third texture attached to the object (so you could have a base texture, normal map, and lit texture). The advantage of this scheme is we’d need only three commands with a pile of flags.

Anyway, just something I’m thinking about.

(One thing I haven’t worked out is how this would interface with dataref-driven textures, which would require yet more file format gunk.)

Posted in File Formats, Scenery by | Comments Off on New Texture Commands

How to Make X-Plane “wicked fast”

Here’s a hack that you can do to make X-Plane a lot faster: switch back to ENV scenery.

Okay, this is a completely ludicrous statement, but … if I take X-Plane 860 (default settings) and turn off birds, cars and high detailed world, then view runway 6 with no panel, I get 45 fps with DSF vs. 83 fps with ENV. Load times are also faster too – the KSBD tile takes about 3 seconds to load vs 0.22 for the ENV.

Now of course you wouldn’t want to use the ENVs if you’ve used the global DSF scenery — even on the most simple axis the DSF scenery is superior, with typically around 150,000 to 300,000 triangles per tile rather than 60,000 in an ENV. (There’s a lot more going on in a DSF than just that.) So ENVs are a lot faster because they do a lot less. You get what you pay for.

Just for fun I tried running X-Plane “7.0 beta 0”, which was sort of a 7.0 preview, really more like X-Plane 6.70. It runs at about 85-90 fps. But it turns out that you’ll get the same thing out of X-Plane 860 by replacing the new bezier-curve-based runway layout with the old simple square one. I also noticed that there are no runway shoulders in 7.00b0. It does beg the question: while I tried to set them up as similarly as possible, how man other things is X-Plane 860 doing that we just don’t notice, but that cost fps?

I mention this in the context of the hardware requirements for future versions of X-Plane. We do sometimes raise the hardware needed to use X-Plane by putting in more graphic detail (that consumes more hardware) and not providing a fallback to the old way X-Plane looked. But I think what creates the sense of “I need a new computer” even more is how tempting and desirable the new technology is compared to the old.

When you look at computer performance in a given market, additional computer performance translates into additional usefulness up to a certain point. Past that point, the additional performance is worthless. This drives the price/performance ratio of the entire market — you can see it with desktop computers.

It used to be that desktop computers cost $1000. Then we hit a day when all new computers could word process, send email, and surf the web with no trouble. At that point, buying a faster computer is pointless, and thus computers started to drop in price. This makes companies like Intel fairly unhappy.

But the flight sim world doesn’t have this problem yet – every bit of new computer performance can be invested in more realistic graphics, something that there is clearly an appetite for.

In this context, my concerns will always be:

  • Efficiency. For the same hardware and graphics detail, is the framerate getting better, or at least not worse? (Previous comparisons of 8.60 with 7.63 show 8.60 to be faster with ENVs…I think that 7.00b0’s apparent speed is because it’s missing a ton of features that the version 7 run introduced.)
  • Lowest config. How far down can we strip the graphics to let users with older hardware keep playing with the most recent airplanes and features?
  • Highest config. How much hardware can we soak up and convert to graphics detail? Are users with the newest systems getting their visual “money’s worth”?
Comments Off on How to Make X-Plane “wicked fast”

Growing Pains for Mac Users

We are now seeing two sets of Mac OpenGL driver-related bug reports: problems with the new Mac Book Pros (with an nVideo GeForce 8600) and with the new iMacs (with an ATI Radeon HD2400 or HD2600).

This doesn’t surprise me for two reasons (both of which are speculation, btw…I am not privy to what goes on inside Apple):

  1. Both of these cards are “next-gen” in a major way: DX-10 compatible hardware. That means they have a lot of cool new features. My speculation is that this larger jump in functionality of the hardware means more changes (and more bugs) in the drivers.
  2. We’re getting closer and closer to the next major OS upgrade (10.5), but this new hardware has to run 10.4. So I wouldn’t be surprised if everyone at Apple is fighting two fires at once, limiting resources.

So while this is frustrating to Mac users who have these machines, I would encourage patience. I don’t think we’ve seen to date a Mac that has been “left broken” — several machines have had problems with the drivers in their initial intro, and Apple usually fixes them as soon as possible. In the long term I believe that these will both be really nice X-Plane machines.

Posted in Development by | 3 Comments

Why Don’t the Cars Drive Backward?

Why don’t the cars drive backward when you pull the slider backward in replay mode? The short answer is “because we don’t care enough to fix it”, but a better answer might be “it would take a lot of programming time and suck up more resources from X-Plane to fix this…and we think our customers would rather that we focus our programming and your hardware resources on framerate.”

The cars are an interesting special case of a whole number of sim phenomena that we don’t attempt to track carefully in replay. Replay is designed to allow you to watch your flight – it would be cool if the scenery was doing the exact same thing during replay as during the flight, but I don’t think it’s essential for training purposes and it does come with a cost.

First remember: replay mode works by saving past values of the sim to RAM. So the more we save, the more RAM we chew up saving past history, and the less time we can save before we run out of virtual memory.

Now in some cases, the motion of dynamic sim objects is at least somewhat random. In this case we can’t easily “reverse” the algorithm that generated the motion.

But the cars are more problematic.

Not only is their motion somewhat random (each time a car makes a turn at a fork in the road it randomly decides which way to go), the cars are maintained in memory in a way that allows us to figure out who has to make the next turn very rapidly without using a lot of CPU. As much as the cars are a CPU hog, they would be much much worse without this memory structure.

The problem is, the memory structure is organized based on time flowing forward. That is, we can only tell you which car needs CPU attention next if the cars are driving forward. Put time into reverse and we now know which car needed our help last! Not useful!

So to make the cars drive backward we would have to transform this data structure every time the flow of time changed. I think it would be more annoying to have this massive CPU recomputation each time you rewound the replay than it would be nice to have the cars move backward. Why not have two data structures, one for forward, one for reverse? Well, now we’ve saved CPU but burned RAM. Either way, we’re talking about hardware resources that could be used for more scenery or more framerate.

The cars have yet another behavior that makes them hard to reverse: they are born and die! A car is born any time we realize that there aren’t enough cars on the road for the given rendering settings. A car dies any time it gets too far away from the user’s plane or reaches a point in the road where it can’t procede. (Typically these are 1-way streets that dead-end. This happens because the road data we use has very poor flow information, leading to some really strange streets.)

This cycle of cars being born and dying maintains a reasonably constant car population over time, and a car population that is near your plane as you fly. But to reverse traffic, we would have to reincarnate cars that had died previously. This would mean spending memory on remembering what cars had died. (Even if the algorithm to decide where a car is born, the algorithm to predict where a car will die is quite complex, because it requires looking at the entire set of steps the car would make during its life until it reaches the “point where it is killed”. So computing this information is out of the question.)

That’s probably more information than you wanted to know. Generally speaking, if someting unrelated to the flight model doesn’t replay in replay mode, it’s probably because it would be too “expensive” to remember its history. The cars are the most complex example, but definitely not the only example!

Posted in Development, Scenery by | Comments Off on Why Don’t the Cars Drive Backward?

Dual Core? Definitely

Austin hinted on the X-Plane news list that X-Plane will in the future use a second core to load scenery much more smoothly than it does in the past. Each time we take a whack at the scenery load code, we reduce the load time by a significant multiple, so we’re still not at truly no-pause flying, but we will be getting a lot closer in the future.

A few years ago when people asked “should I get a dual CPU machine” (this was before dual-core chips were ubiquitous) I hesitated to say yes. This is on longer the case – dual core is definitely the way you want to go.

The price performance curve is such that dual core chips are definitely in the sweet spot. In the past a true dual CPU machine costed big bucks, but now unless you buy the absolute cheapest machine, you’re going to get a dual core chip. I never recommend buying the absolute cheapest hardware — usually to get those last few dollars of price savings, the machine (or GPU) has been stripped down of major features, so you’re losing tons of performance for really marginal savings in dollars.

X-Plane’s usage of the second core has gone up too, already in 860 and the second core will be even more important in version 9.

Our usage of the second core isn’t about trying to raise X-Plane’s system requirements, it’s about not leaving “money on the table”. We need to make X-Plane run efficiently as possible on as many combinations of hardware as possible. This means giving you the best flight sim experience you can get whether you have an older single-core machine with a low-end graphics card or a new dual-core chip with the latest huge graphics card and four tons of VRAM.

The important thing here is: usage of dual core chips requires code changes. We have to write new code in X-Plane to teach it how to safely run some work on one core and other work on another. This is all about efficiency – if you have a dual-core chip there is nothing efficient about leaving one core doing nothing! We’d be leaving half the computing power of the chip idle.

So if you don’t have a dual-core chip, the sim will still run (just as it does now). But whereas the gap between single and dual-core chips is smaller now (because the dual-core users have half a chip idle a lot of the time), the gap will become larger as we utilize the second core more fully and dual-core users get to really take advantage of all of that computing power.

6 Comments

Image Formats and File Extensions

This goes into the bucket of “weird X-Plane behavior”: X-Plane will try both PNG and BMP file extensions when opening images, no matter what is in your file. How we got to this state is, at best, confusing.

Originally, most X-Plane image files did not contain a suffix. So an ENV file contains “grass” and X-Plane would change that to grass.bmp.

Then we added PNG support. X-Plane would try grass.png and then grass.bmp. In this case, not having the extensions turned out to be handy — authors could simply bulk-convert their images and go on with life.

With most new scenery system files, the extensions are a lot more rigid:

  • The extension appears in the referencing file.
  • The sim only tries that extension.
  • If the format doesn’t match the extension, it’s an error.

So if you want a DSF file to reference a facade, it’s buildings.fac and if that .fac file is actually a forest file, it’s an error. The sim won’t try to decide which is more correct, the header of the file or the extension, it will just go “you’re nuts” and bail out.

But (for historical reasons) images are an exception. Keeping with the “any extension goes” theme for images, X-Plane will actually try PNG and then BMP versions of your file. The extension has to match the format…that is if you call your bmp foo.png X-Plane won’t load it at all.

We have PNG as our primary image format and BMP for backward compatibility. But it’s imaginable that we could have DDS and PNG both as primary formats — PNG for images that need lossless fidelity and DDS for images where compression is acceptable. In such an event, X-Plane’s tendency to try every extension means authors can bulk-convert from PNG to DDS (making their packages load faster) and go home happy.

Posted in Development, File Formats, Scenery by | Comments Off on Image Formats and File Extensions

The case for DDS

Jonathan Harris suggested I look into .dds as an image format for X-Plane. I think he’s got a good idea.

First, what is DDS? It stands for “direct draw surface”, but as a file format, it’s basically a file whose structure is the same as the memory layout for a texture in DirectX. It’s a simple image format but it does two useful things for X-Plane (or any other 3-d application):

  • It can contain compressed images using the same compression OpenGL and DirectX use (DXT compression).
  • It can contain mipmaps – smaller versions of the same image.

Now before things get out of hand, using .dds files in X-Plane would not mean converting X-Plane to use DirectX!! .dds is simply an agreement about how to arrange a file. You can easily write code to load a .dds file into an OpenGL application, and that is what we would do.

There would be three fundamental benefits to using DDS files:

File size on disk (and download).

PNG is a losslessly compressed file format. This kind of compression (the internal algorithm used by PNG is the same as ZIP files) preserves the image, but the reduction in image size is a function of how “simple” the image is. Images with a lot of detail and high frequency information (rapid changes in color) do not become much smaller than the amount of VRAM they use when compressed in a PNG. A lot of the terrain textures we use (4 MB in VRAM) are still 3 to 3.5 MB on disk!

By comparison, the texture compression used by OpenGL is lossy – the image looks worse. But the image is reduced by a factor of 4 to 8, every time. So one of these images (4 MB in VRAM when uncompressed) would be 1 MB with S3TC compression (available in a DDS file). Even for very simple PNG files, you rarely see such a reduction in size, so .dds files would be smaller, meaning faster updates and downloads.

(Another thought: if a PNG file is smaller than its VRAM requirement, it means the PNG file has lots of areas with the same color. This means the PNG file is WASTING VRAM! We encourage our artists to make use of every little pixel in an image, and this means that PNG files that are well-created for X-Plane tend to get relatively little benefit from PNG’s internal compression.)

Load Time

Image load time is a significant factor in X-Plane. There are several reasons why DDS files could load a lot faster than PNG.

  1. The actual DDS file is smaller – less data to load and process means faster performance.
  2. Because the DDS file can contain smaller copies of the image, X-Plane doesn’t have to load a huge image and reduce its size using the CPU – it can just load the small version in the file.
  3. When compressed textures are used (and they almost always should be, see my previous blog post) it takes CPU power to compress the image, slowing down load. A DDS file containing a compressed image can be sent directly to the card!

Image Quality

Now one is a little bit tricky. First, please review my previous blog post, which argues that texture compression is the best way to maximize VRAM. A DDS file will look better than a PNG file when texture compression is on. Here’s why:

The S3TC compression formats specify an EXACT way to “uncompress” and draw a compressed image. But there are MANY possible ways to compress the image. Remember that S3TC is a lossy compression – the compressed image is only an approximation of the original.

Well, it turns out that algorithms that find the best approximation of an image using S3TC are slow. So we can’t use the highest quality compression inside X-Plane when compressing PNGs for the graphics card – it would be too slow.

But the image in a DDS file is already compressed — because someone else has compressed it when creating the scenery. When converting the scenery from PNG to DDS that author can use a very slow, very high quality compression algorithm to make the DDS files. It might take 12 hours to convert the entire package from PNG to DDS, but who cares? It’s something you do once and then everyone enjoys better looking images.

In other words, because the compression is done ahead of time for a DDS file, a higher quality algorithm can produce better approximations of the original images. Since we want to use compression anyway (to optimize our use of VRAM) this is a good thing.

When is DDS not appropriate?

Any time an image must not be compressed, DDS is inappropriate, and PNG is best. There are three basic cases in X-Plane where we avoid compression (see my previous blog entry for the real examples):

  1. Any time we need to preserve tiny detail accurately, like lettering and text.
  2. Any time the alpha channel needs to be smooth.
  3. Any time a texture is magnified so large that small color changes between two pixels is noticeable. (For example, compressing the color washes used for the sky make obvious artifacts.)

DDS wouldn’t replace PNG, it would augment it.

Posted in Scenery, Tools by | 8 Comments

What Doesn’t Get Compressed?

Speaking of compression, X-Plane doesn’t compress all textures…even if “texture compression” is on, we leave uncompressed certain textures that are flagged. A rough list:

  • Most textures in the sky, like clouds and color stripes, have a lot of alpha and get wrecked by compression. They get exempted.
  • Anything related to the 2-d panel, maps, and the UI get exempted.
  • Some of the overlays like rain and snow, smoke puffs, and lights.
  • Taxiway signs get exempted…S3TC does a number on letters and numbers.
Posted in Scenery by | Comments Off on What Doesn’t Get Compressed?

Texture Compression Is Your Friend

Try this experiment: take three screen-shots (use ctlr-; to get a stable, clear view), with these settings:

  1. Extreme res, with tex compression
  2. Extreme res, without tex compression
  3. Very high res, without tex compression

Now consider the effect on VRAM. Each time you go down a texture resolution level, tex sizes are cut in half, and you cut VRAM use by a factor of 4.

If you use texture compression, you cut VRAM use by a factor of 4 for textures with alpha and a factor of 6 for textures without alpha. (Some textures are unaffected because they are internally marked as “never compress”.)

Now look at your visual results. I would argue two things:

  • At extreme res, turning off texture compression doesn’t make the image a whole lot nicer. (It does make the machine a whole lot slower!)
  • Texture compression is a lot nicer than going down a res level.

I suspect that if your machine can’t handle extreme res, you can get similar results running the whole experiment down one notch.

I think that almost everyone who has a limited machine is running with texture compression these days – we default with it on and it helps fps. I would only argue that any users who are running with a huge machine and compression off might consider turning it back on. It doesn’t hurt much and it does make the machine run faster.

(Even if you have a ton of VRAM, X-Plane can be limited by how fast texture data transfers from VRAM to the GPU, within the card. Texture compression helps this.)

Posted in Scenery by | Comments Off on Texture Compression Is Your Friend

Spankings

Austin and I have this debate over and over when we find a case where third party content doesn’t work right with X-Plane (but did in the past due to X-Plane’s permissiveness):

  • If we code X-Plane to work around the problem, users get to enjoy the scenery, and authors will never fix the problem.
  • If we code X-Plane to abort, users get grumpy, and authors fix the problem real fast.

What to do? A few versions ago I implemented the scenery warning system (the spanking system) to try to get the best of both worlds. I just discovered another problem that illustrates how this works well.

Before WED some authors made apt.dat 850 layouts by hand using a text editor, and sometimes they forgot to include a closing code on their rings and chains. I can hardly blame them, writing an apt.dat file by hand is very difficult, and I am impressed (and grateful) that they did this.

The apt.dat 850 spec is clear:

  • Pavement chunks (line code 110) must comply with the following:
    • Chunks MUST terminate in a segment point of type 113 or 114.
  • Linear features (line code 120) must comply with the following:
    • Linear features must terminate in a point of type 113, 114, 115 or 116.
    • Linear features do not need to be “closed”.
  • Airport boundaries (line code 130) must comply with the following:
    • Boundaries MUST terminate in a segment point of type 113 or 114.
    • Boundaries must be a closed loop and cannot contain holes. As with pavement chunks, the airport boundary cannot overlap itself.

So, you must have one of the closing codes at the end of a boundary, taxiway, or line. But X-Plane 860 doesn’t check this and simply assumes a “closed ring” if no code is provided. With X-Plane not telling authors, the authors never caught this mistake.

So now that I know about this (and now that X-Plane needs the end codes to be right, due to other bug fixes) it’s time for the spanking system. In future versions of X-Plane:

  • Custom scenery packages with no ending code on a polygon block will automatically be adjusted to be “ring”-type on load-in, for compatibility with X-Plane 860.
  • A detailed message will be printed per polygon in the log.txt file.
  • A single alert box will be shown to the user saying “there is a problem with the custom scenery pack XXX”.

The idea is for the dialog box to walk a fine line between being unobtrusive enough for users and annoying enough for authors.

Posted in File Formats, Scenery, Tools by | Comments Off on Spankings