Cloud rendering in X-Plane 10

Tyler Young

When thinking about how X-Plane 10 will render clouds, my guess was that a modern personal computer is fast enough to draw clouds that are made of puffy little bits that are each 1 meter across. Not a bad start to drawing clouds, right? To make them of puffy little bits that are each 1 meter across, where each puffy bit is 1 polygon?

If a cloud is made of puffs, and each puff is a meter across, and each puff is 1 polygon on the video card, then that seems a decent way to build clouds in a flight sim, right?

Let’s go briefly through the math.

X-Plane 10 has a maximum visibility of 100 miles, and it goes from the surface up to 45,000 feet. With roughly 2000 meters in a mile and 1 meter in 3 feet, that makes a maximum visibly area of 100 miles * 2000 meters/mile * 100 miles * 2000 meters/mile * 45,000 feet / 3 feet/meter = 600,000,000,000,000 cubic meters.

This means that to render solid clouds in your flying area for X-Plane 10, your video card has to draw just 600,000,000,000,000 puffs of cloud. The graphics card needs to be able to do this at 60 frames per second in order to have some processing power left over for stuff on the ground. That means the video card needs to handle 60 frames/sec * 600,000,000,000,000 puffs of cloud = 36,000,000,000,000,000 polygons per second of cloud puffs. If it can do this, it can perform a basic cloud rendering with 1 meter puffs across the sky.

Now, if there is one polygon every meter, and you can see for 100 miles at high altitudes, then you will be looking through roughly 200,000 meters. With one puff per meter, that makes 200,000 cloud puffs to look through.

That does not sound so bad.

Of course, to fly through these clouds, each pixel on your screen must be filled 200,000 times (once for each puff of cloud in the 200,000 visible meters). If you’re running at a very low resolution of 1024×768 at 60 frames per second, your video card will be filling 200,000 puffs of cloud x 1024 pixels wide x 768 pixels high x 60 times/sec = 10,000,000,000,000 pixels per second.

So, to do the rather basic job of filling the sky with clouds whose (polygonal) puffs are each one meter across (a reasonable size to see up close), your video card would need to draw 36,000,000,000,000,000 polygons per second and 10,000,000,000,000 pixels per second.

As it turns out, a high-end video card today can deal with 700,000,000 polygons per second and 11,200,000,000 pixels per second. These numbers are for the Nvidia GTS 450, but other high end cards won’t be terribly far off.

So with this video card, you would need:

36,000,000,000,000,000 / 700,000,000 = 51 million of them to do the polygons, and

10,000,000,000,000 / 11,200,000,000 = 892 of them to do the pixels.

The current best-of-the-best video cards are 51 million times too slow to draw clouds this way.

Clearly, we need a totally new strategy for drawing clouds in X-Plane 10, because no home users have 51 million video cards lying around.

Our new strategy is a display of resultions of buckets. Imagine this: we have high resolution cloud geometry. Each puff is 1 meter across, but those puffs only go out, say, 10 meters. In other words, you can see cloud puffs that are 1 meter across, but you can only see them up to 10 meters away. You only see small, detailed puffs up close. That makes just 10 meters of puffs in each direction, making for 1,000 puffs. Our video cards can handle that number.

Then, for puffs that are between 10 and 100 meters away, we draw puffs that are 10 meters across. At 1 puff per 10 meters, with 100 meters of these puffs, this makes another 1,000 puffs to draw.

We just covered ten times the space of the first draw, but using the same number of puffs as we did in the smaller area. We just made the puffs that were farther away bigger. Sure, the bigger puffs are less detailed, but since they are farther away, you wouldn’t be able to see the 1 meter diameter puffs anyway–they are too far away to gain any advantage from that kind of detail.

Then, from 100 meters to 1,000 meters, we draw puffs that are 100 meters across. We have 1 puff every 100 meters for a 1,000 meter range, making for another 1,000 puffs. Now, we’re covering a full kilometer, the better part of a mile, with just 3,000 cloud puffs.

What about when we get to 100 kilometers? Each puff can be drawn, say, 10 kilometers across, since it’s so far away that you won’t notice any loss of detail. Again, 1 puff every 10 kilometers in a 100 kilometer range makes for another 1,000 puffs.

No matter how big the sky, each level of detail only costs us 1,000 puffs.

As it turns out, seven levels of detail are plenty. We call each of these levels of detail a “resolution.” Seven resolutions gives small (1 meter wide) puff up close, and huge puffs far away (as seen from orbit). We wind up with only 7,000 puffs–no modern video card would break a sweat drawing that!

This is the trick to the cloud rendering in x-Plane 10: we draw a lot of small puffs up close, and a few huge puffs far away. This gives you all the detail you want up close, with the general cloud layout visible from 100 miles away. There is no need to draw tiny, 1 meter wide cloud puffs from 100 miles away–you could never see them from that far away.

So, our display of the weather uses about seven resolutions of cloud puffs, with maybe a few thousand puffs at each resolution, for a total of a few tens of thousands of puffs.

With this new strategy, you won’t need 51 million video cards at all. In fact, you’ll do well with just one video card–perfect for a home computer.

We aren’t done optimizing the performance yet, though.

Each resolution contains all the cloud puffs around you, including the ones behind you. We have no reason to have the video card draw the puffs behind you–that would slow you down for nothing. Instead, we break each resolution down into 27 “buckets,” each one a 3-dimensional grid in 3 x 3 x 3 pieces, just like a Rubik’s Cube. This, though, is a Rubik’s Cube that you fly around inside of, where each cube is a bucket. Now, we will only draw the buckets that are in front of you where you can actually see them. This doubles the frame rate again, since about half the buckets are in front of you and half are behind.

So, the weather display in X-Plane 10 contains about 7 resolutions, with each resolution distributing its several thousand puffs into 27 buckets. This way, we only draw the cloud puffs in front of you, at a level of detail that you can see at that distance.

This is what makes it possible to run the weather at 100 frames per second on my Mac with one video card. This gives us the detail we want, with the long-range visibility we want, at the frame rate we need.

Never miss an update.

More X-Plane news comes every month. Sign up below to never miss an announcement.