Your game's sky doesn't start and end with the skybox. A beautiful background sky is nice, and important in some settings, but it's static. If you go outside on a nice day and look around, you will often see a sky with clouds that presents itself much like the one you can make with the skybox.
But more often, you will see that and you will have clouds moving across the sky above you, blowing in the wind. In fact, you will probably notice layers of clouds—often two layers and sometimes even three layers. The lower layers whip across the view above you, while the upper layers move at a more sedate pace, sometimes even in a different direction.
In Torque we can define up to three layers of moving clouds with the Sky mission object in the MIS file that the server uses to define the game world.
For each layer, we define its altitude as a percentage of a pseudo-altitude. Now this is tricky and might be a bit difficult to understand. The first thing to get is that your player can never go up—either in camera fly mode or in a flying vehicle—high enough to reach the lowest cloud layer. In this sense, cloud layers operate somewhat like a skybox. However, you can position the three layers relative to each other. The reason for this is so that the motions of each cloud layer can be calculated in correct proportion to each other. If you have a steady wind that is the same at all altitudes, then the lowest cloud layer will seem to move faster than the others, and the highest will seem to move slower than the others. How much faster or slower depends on the distance between the cloud layers and their distance from your player, as the observer.
And that's what the cloudHeightPer properties do—they inform the visual appearance of the clouds but not their physical location in the game.
Now another consideration is that wind speeds are not the same at all altitudes in real life. Usually, the winds aloft (winds at altitudes of 1,000 feet or greater above the ground) are higher the higher you go, up to about 30,000 or 40,000 feet or so. Then it starts to get really weird.
You can plug in the movement speeds for the clouds at different altitudes using the cloudSpeedn for each specified cloudHeightPer[n] and have the game engine figure out the relative motion based on pseudo-altitude and the speed at that altitude. Unfortunately, Torque doesn't handle wind direction for clouds as well—that would be the final link needed to provide really neat cloud motion. Wind direction is specified by a single windVelocity property that applies to all layers. In real life, wind directions back and veer according to altitude, but we can't do that here.
Using the windVelocity property requires a little thought. The value is expressed as an XYZ coordinate. The third value, the Z, is irrelevant, but the X and Y values are used to calculate the vector on the horizontal plane in two dimensions. The vector then points to the world origin (or center). If we look up at the sky and imagine the X- and Y-axes pasted up there, somewhat like in Figure 18.12, we can figure out the direction.
Figure 18.12: Wind velocity conversion correcting warp.
The value "1 1 0" would describe a wind from the southeast, as illustrated in Figure 18.12, and "1 0 0" would be a wind from the east.
Now, you need to tell the engine what all those clouds you have zipping around up there actually look like. You do this by specifying an image file in the same material file that you used to specify the skybox image files. After the first six lines in that file that indicate the skybox images, the next lines indicate the cloud image files. One line equals one cloud layer, with the first line after the skybox image lines indicating layer one, the next being layer two, and the last being layer three, like this:
skyfront skyright skyback skyleft skytop skybottom no_cloud cloud2 cloud3
That is the contents of sky_book.dml. Notice the use of the name "no_cloud" for the first cloud layer. In this example I didn't want to have any clouds at that first layer, so for this layer I created an image file that has no clouds in it.
So, you are asking, how do we make a cloud texture that does have clouds? Glad you asked! Let's make one.
Launch Paint Shop Pro and create a new file that is 256 pixels by 256 pixels in size, has a transparent background, and includes 16 million (24-bit) colors.
Save this empty image file as C:\aEmaga6\control\data\maps\no_cloud.png.
Select the Air Brush tool, set it to spray white, and then spray a little bit around your new image, avoiding the edges, like in Figure 18.13. Or spray the edges, but make sure you adjust the edges so that the image is suitable for tiling.
Figure 18.13: A simple cloud texture.
Save your image as C:\aEmaga6\control\data\maps\mycloud.png. (Or you can save it as a JPG, if you like.)
Edit C:\aEmaga6\control\data\maps\sky_book.dml so that the last three lines look like this:
mycloud no_cloud no_cloud
Now run your game, and check out the clouds! Of course, you can add more cloud images for the other layers, or you can use the same image for all three.