World
Wide Guide | Knowledge Bank |
Kukushkin's Notebook | Basics
of Simulation
FS5 simulates motion by displaying a series of snapshots
of the scenery, similar to TV. Each such snapshot is called a frame. The
number of frames displayed in one second is referred to as frame rate.
Because each frame is computed separately, the frame rate depends upon the
number of computations FS5 has to do to complete each frame.
On the same PC, the frame rate may be very high in areas with simple scenery, like synth scenery only, and very low in areas with a complex scenery with many textured objects. The need for reasonably high frame rates has led to many compromises in the graphics engine of FS5. These compromises greatly reduce the amount of computations needed to be done, but also impose many limits on what can be done using this engine. Not every kind of landscape can be implemented as FS5 scenery.
One of the basic ideas of the FS5 graphics engine is that there is no hidden surface removal between different objects. All objects in an area are drawn, but in an order than ensures that objects that are partially or completely covered get over-painted by covering objects. This method allows a realistic rendering of the scenery in most cases without any need for slow and complex computations needed for a 'true' hidden surface removal.
FS5 programs the display adapter to have two video pages. While one page is visible, FS5 draws the next frame on the other one. When the next frame is complete, FS5 switches the visible page. Then, the second page containing the just completed frame is displayed and FS5 draws the next frame on the first page. This technique ensures that the process of over-painting of hidden objects is not visible.
The Flicker/Speed setting in the Preferences/Display dialog box controls when the visible page is switched. When it is set to "No flicker/Slow", FS5 waits for a retrace signal before switching pages. Because FS5 spends some time waiting, the frame rate is reduced. When this option is set to "Much flicker/Fast", FS5 does not wait until retrace and displays the page immediately. Because the video card continues to show the old (but already under repainting) video page for a short period of time, 'flickering' occurs. FS5 never erases the frame buffer before drawing a new frame. It is assumed that the scenery fills the whole view window and it is the responsibility of the scenery designer to ensure this. This is not very difficult because the default scenery of FS5 already contains the whole world. The only possible source of problems I know are transparent synth tiles (see below).
When FS5 starts to draw a new frame, it begins with the sky. Then, all cloud layers above the viewer are displayed. This means, for example, that it is impossible to see mountains in FS5 with tops covered by clouds -- the mountains are displayed later and over-paint any clouds. Then, flat parts of the synth scenery are displayed.
The most easy-to-understand description of the synth scenery I know comes with BGLGEN, and the most complete description comes with FSASM.
Synth tiles are not drawn immediately. Instead, the attributes of synth tiles that are close enough to the aircraft are buffered in a two-dimensional array. When two different (conflicting) scenery files define the same tile, the second file simply overwrites the corresponding array element, instead of drawing the tile for the second time. After all loaded scenery files have been processed, flat tiles are drawn using the information from the array.
Although each synth tile has its own altitude, FS5 displays all synth scenery as one plane. The relative altitude of the aircraft above this plane is determined by the relative altitude above the tile directly below the aircraft. As the aircraft moves, other tiles with sometimes different altitude appear below. Then, FS5 adjusts the altitude of this plane in order to maintain a correct relative altitude to the tile below. This causes the ground to "float" up or down, depending on its elevation change.
In FS5, there are two ways of specifying the altitude of visual scenery objects. For each object, either the ground altitude can be specified, or its absolute altitude above the mean sea level. The absolute altitude is used for objects like runways, where keeping the correct relative altitude to the aircraft is more important than a pleasing visual appearance. For this reason, such objects do not float up/down together with the ground, thus sometimes appearing floating in the air or buried deep below the ground. Absolute altitude is also used for objects that do not sit on the ground, like hot air balloons. Most other objects are put on the ground altitude. They always appear sitting on the ground, but they float up/down together with the ground when the elevation of synth tiles changes.
Because the default synth scenery covers the whole world, scenery designers normally do not have to worry about filling the whole view window -- it is automatically filled by the sky and the synth scenery. However, there is one exception. If a synth scenery tile is fully covered by ground polygons or other objects, the user can never see it. So it would be quite reasonable to instruct FS5 not to draw the tile at all, thus improving the frame rate. There is a special "transparent" kind of tile that allows doing this. Such tiles are never drawn, they are used only to specify the correct ground elevation. It is very important to ensure that these tiles are completely covered, otherwise previous frames will not be completely over-painted and flickering rests of object can appear in uncovered areas. Maybe a good idea for a Bermuda Triangle scenery :-)
Finally, the visual scenery is displayed. Visual scenery contains all visible objects, roads, rivers, ground polygons, etc. except objects defined in the synth scenery. The visual scenery contains three kinds of objects: 2-D objects, priority 2-D objects and 3-D objects. FS5 uses different algorithms for each kind of object to determine the drawing order.
When displaying the visual scenery, FS5 first draws all 2-D objects from all sceneries, then all priority 2-D objects from all sceneries and finally all 3-D objects from all sceneries. The main difference between 2-D and 3-D objects is that the drawing order of 2-D objects does not depend on the position of the viewer. 2-D objects are drawn in the order they appear in scenery files. 2-D objects from multiple scenery files are drawn in the order determined by priorities in the scenery library. The user can change this order by arranging scenery library layers. Most "flat" objects in FS5, like roads, rivers, taxiways, ground polygons, lakes and fuel "boxes", are implemented as 2-D objects. All priority 2-D objects have a "layer" parameter. These "layers" determine the drawing order.
Objects from all sceneries with layer 0 are drawn first, thus having the lowest priority. Objects with the highest layer are drawn last, thus having the highest priority. The advantage of priority 2-D objects is that the drawing order does not depend on the order of scenery files. This is also the main disadvantage, because the user has no possibility to solve scenery conflicts except for disabling conflicting sceneries. Runways in the default scenery and most add-ons are implemented as priority 2-D objects. The (commercial) Europe 1 scenery uses priority 2-D objects for all its ground textures, thus making adding ground polygons difficult. 3-D objects are drawn in an order that is supposed to ensure that more distant objects get over-painted by less-distant ones. Each object has a "reference point", and objects are sorted for drawing according to the distance between the viewer and their reference points. While this method allows realistic rendering of the scenery in most cases, it creates difficulties when the distance between 3-D objects is comparable to their sizes. For example, it is almost impossible to implement hilly cityscapes in FS5 -- the graphics engine would not be able to determine the correct drawing order.
Mountains and buildings from the synth scenery, dynamic scenery objects, other aircraft and the own aircraft from external views are sorted and displayed together with visual 3-D objects. After displaying the visual scenery, FS5 draws all cloud layers situated below the viewer. This makes it impossible, for example, to see tops of mountains above clouds - all mountains below the horizon will be over-painted by the clouds. The world in FS5 is quite complex and having to display all visible objects would lead to an unacceptable frame rate. For this reason, every visible object has a so-called visibility range and is only drawn if its distance to the viewpoint does not exceed this range.