diff --git a/Docs/README.local_weather.html b/Docs/README.local_weather.html index dea448563..f9bff84cd 100644 --- a/Docs/README.local_weather.html +++ b/Docs/README.local_weather.html @@ -7,7 +7,7 @@ -

Local Weather Package - v0.5

+

Local Weather Package - v0.61

1. Introduction

@@ -15,13 +15,13 @@ The aim of a local weather system is to simulate weather phenomena tied to speci This is in contrast to the current (v.2.0.0) weather system of Flightgear where weather changes affect the weather everywhere in the simulated world and are (with few exceptions) not tied to specific locations. In such a system, it is impossible to observe e.g. the approach of a rainfront while flying in sunshine.

-The local weather package ultimately aims to provide the functionality to simulate such local phenomena. In version 0.5, the package supplies various cloud placement algorithms, as well as local control over most major weather parameters (visibility, pressure, temperature, rain, snow, thermal lift...) through interpolation routines and event volumes. However, basically all features currently present can and will eventually be improved.

+The local weather package ultimately aims to provide the functionality to simulate such local phenomena. In version 0.61, the package supplies various cloud placement algorithms, as well as local control over most major weather parameters (visibility, pressure, temperature, rain, snow, thermal lift...) through interpolation routines and event volumes. For long-range flights, it automatically provides transitions between different weather patterns. However, basically all features currently present can and will eventually be improved.

-As of version 0.5, the system does not contain dynamics (development of convective clouds, wind displacement of clouds...). Since wind and dynamics are closely related, any wind parameters can currently not be controlled from the local weather algorithms.

+As of version 0.61, the system does not contain dynamics (development of convective clouds, wind displacement of clouds...). Since wind and dynamics are closely related, any wind parameters can currently not be controlled from the local weather algorithms.

2. Installation

-The package needs to be unpacked in the Flightgear root directory. It writes content into the Nasal/, gui/, gui/dialogs/, Shaders, Effects/, and Models/Weather/ subdirectories. The installation does not overwrite any of the default Flightgear files, but to be accessible from the menu, one must copy gui/menubar.xml.alt to the default menubar.xml or copy the last two lines of the environemnt menu calling local_weather and local_weather_tiles into the default file.

+The package needs to be unpacked in the Flightgear root directory. It writes content into the Nasal/, gui/, gui/dialogs/, Shaders, Effects/, Docs/, and Models/Weather/ subdirectories. The installation does not overwrite any of the default Flightgear files, but to be accessible from the menu, one must copy gui/menubar.xml.alt to the default menubar.xml or copy the last two lines of the environemnt menu calling local_weather and local_weather_tiles into the default file.

This adds the items Local Weather and Local weather tiles to the Environment menu when Flightgear is up. The central functionality is contained in local_weather.nas which is loaded at startup and identifies itself with a message, but does not start any functions unless called from the GUI.

@@ -29,7 +29,7 @@ This adds the items Local Weather and Local weather tiles to the < The general rule is that the gui is not hardened against problematic user input, for example it will not reject meaningless input. It is recommended to watch the console, because some level of warnings and errors are passed to the console. Placement calls may sometimes take a significant time to execute especially for large numbers of clouds tied in a complicated way to the terrain. Placing 500 barrier clouds against a small barrier may take a minute to compute.

-The first menu contains the low level cloud placement functions. Currently four options are supported: Place a single cloud, Place a cloud streak, Start the convective system, Create barrier clouds and Place a cloud layer.

+The first menu contains the low level cloud placement functions. Its purpose is mainly for developing cloud patterns without having to resort to re-type the underlying Nasal code every time. Currently four options are supported: Place a single cloud, Place a cloud streak, Start the convective system, Create barrier clouds and Place a cloud layer.

@@ -83,31 +83,47 @@ The picture illustrates the result of a layer generation call for Nimbostratus c

Tile placement

-The second menu is used to place complete weather tiles based on low-level calls. Currently it contains several demo tiles indicating what can be done.

+The second menu is used to place complete weather tiles based on low-level calls. It is intended for the user to automatically create the various weather patterns during flight.

-The dropdown menu is used to select the type of weather tile to build. In addition, two parameters can be entered. The first is the tile orientation. Some tiles, most notably incoming fronts, have a direction along which the weather changes. The tiles are set up in such a way that fronts come from north, changing orientation rotates the whole tile to the specified direction. As soon as wind is implemented in the local weather system, the tile orientation will essentially also govern the wind direction (clearly, there is a relation between from where a front comes and the wind direction).

+The dropdown menu is used to select the type of weather tile to build. The menu contains two groups of tiles - the first six are classified by airmass, whereas the last two are scenarios intended for soaring. In addition, two parameters can be entered. The first is the tile orientation. Some tiles, most notably incoming fronts, have a direction along which the weather changes. The tiles are set up in such a way that fronts come from north, changing orientation rotates the whole tile to the specified direction. As soon as wind is implemented in the local weather system, the tile orientation will essentially also govern the wind direction (clearly, there is a relation between from where a front comes and the wind direction). Currently, the functionality of tile orientation is there, but mostly untested and at the moment not particularly useful.

The second parameter, the altitude offset, is as of now a provisorium. Cloud layer placement calls are specified for absolute altitudes and calibrated at sea level. As a result, layers are placed too low in mountainous terrain. Eventually, the system is to receive a terrain presampling function to determine just where exactly low cloud layers should be placed when a weather tile is set up. Until this is in place, the user must manually specify a suitable altitude offset for all cloud layers.

-The following pictures show the results of tile setups 'Incoming rainfront' and 'Summer rain':

+The dropdown menu for the tile selection mode controls the long-range behaviour of weather. It specifies according to what rules tiles are automatically generated once the aircraft reaches the border of the original tile. The option 'single tile' creates a single weather tile as specified without automatic generation of further tiles. The option 'repeat tile' creates new tiles of the same type as the originally selected tile. This does not mean that weather will be unchanged during flight, as both parameters like pressure, temperature and visibility as well as the positioning of cloud banks are randomized to some degree. In addition, each tile typically contains 2-5 different cloud scenarios, so five repeated generations of 'low-pressure-border' tiles may never result in the same arrangement of cloud layers. Necertheless, the option will keep weather conditions roughly the same. This is different with the (somewhat optimistically named) 'realistic weather'. This option allows transitions between different airmasses, thus one may select 'low-pressure-core' initially, but as the flight goes on, eventually a region of high pressure and clear skies may be reached. Currently this change between airmasses does not include transitions across fronts. Moreover, it does not cover arctic or tropical weather conditions - those will be covered in a future release. Note that 'realistic weather' does not work for the two soaring scenarios.

+ +The menu then contains four options. 'Terrain presampling' is currently not yet functional. 'Worker threads' is an option to distribute the work flow. Usually, the local weather package will compute a task till it is done before starting the next. Thus, creating a new weather tile may lead to a few seconds freeze, before Flightgear continues normally. With 'worker threads' selected, computations will be split across several frames. The advantage is that Flightgear stays responsive during loading and unloading of weather tiles, and in general the flight continues smoothly, albeit with reduced framerate. However, selecting this option does not guarantee that an operation is finished by the time another is beginning - thus there may be situations in which the loading of a new tile blocks unloading of an old one and so on, in essence leading to processes competing for access to the weather array, resulting in an extended period of very low framerates. Dependent on system performance, this may or may not be acceptable to the user. 'asymmetric range' is an experimental performance-improving option (see below). Finally, 'detailed clouds' will change the technique for generating Cumulus clouds from a multilayer model to multiple cloudlets filling a box. This improves the visual appearance of the clouds significantly, albeit at the expense of a (significant) loss of framerate. Rendering multiple tiles of dense Cumulus development with detailed clouds will quite possibly freeze even a powerful system.

+ + + +The following pictures show the results of tile setups 'Low-pressure-border' and 'High-pressure-border':

- +

- +

4. Cloud models

-The package contains a number of different cloud models, both static ones for Cirrus and Cirrocumulus clouds as well as rotated ones for Altocumulus, Cumulus, Cumulonimbus, Stratus and Nimbostratus cloudlet models. Neither the cloud textures, nor the models nor the transformations are perfected, and any aspect can be improved. Currently the clouds cannot reach the sophistication of the shader-based standard 3-d clouds of Flightgear, but there is no reason in principle why they should not eventually reach that level. The problem is finding a good balance between spending a lot of CPU time to make a single cloud model appear perfect, and the performance degradation that occurs if hundreds of clouds are placed in the sky. The basic aim is to provide realistic appearance for clouds from a standard view position (in cockpit looking forward), to retain acceptable appearance from other positions and to allow large cloud layers.

+The package contains a number of different cloud models, both static ones for Cirrus and Cirrocumulus clouds as well as rotated ones for Altocumulus, Cirrostratus, Cumulus, Cumulonimbus, Stratus and Nimbostratus cloudlet models. Neither the cloud textures, nor the models nor the transformations are perfected, and any aspect can be improved. Currently the standard clouds cannot quite reach the sophistication of the shader-based standard 3-d clouds of Flightgear, but the detailed Cumulus clouds are on the verge of catching up.

-Currently all clouds which need to be rotated are treated in the Shaders using a view-axis based rotation by two angles. This generally looks okay from a normal flight position, but rapid change of the view axis (looking around), especially straight up or down, causes unrealistic cloud movement. Any static picture of clouds however is (almost) guaranteed to look fine.

+

+ +

+ +These are rendered by a different technique: While the default Cumulus models consist of multiple layers rotated around the center of the model, the detailed Cumulus clouds consist of multiple (up to 24) individual cloudlets, rotating each around its own center, randomly distributed into a box. This not only improves the visual appearance, but also leads to a more realistic distribution of cloud sizes and shapes in the sky. In addition, when circling below the cloud (as done when soaring) the effect of the cloudlet rotation is less pronounced. The price to pay is that rendering detailed clouds costs about a factor 4 more performance, so they may not be suitable for all systems.

+ +The general problem is finding a good balance between spending a lot of CPU time to make a single cloud model appear perfect, and the performance degradation that occurs if hundreds of clouds are placed in the sky. The basic aim is to provide realistic appearance for clouds from a standard view position (in cockpit looking forward), to retain acceptable appearance from other positions and to allow large cloud layers.

+ + + +Currently all clouds which need to be rotated are treated in the Shaders using a view-axis based rotation by two angles. This generally looks okay from a normal flight position, but rapid change of the view axis (looking around), especially straight up or down, causes unrealistic cloud movement. Any static picture of clouds however is (almost) guaranteed to look fine. This means that shader effects need to be 'on' in order to see most of the clouds.

5. Local weather parameters

@@ -141,16 +157,20 @@ Effect volumes are always specified between a minimum and a maximum altitude, an where geometry is a flag (1: circular, 2: elliptical and 3: rectangular), lat and lon are the latitude and longitude, r1 and r2 are the two size parameters for the elliptic or rectangular shape (for the circular shape, only the first is used), phi is the rotation angle of the shape (not used for circular shape), alt_low and alt_high are the altitude boundaries, vis, rain, snow, turb and lift are weather parameters which are either set to the value they should assume, or to -1 if they are not to be used, or to -2 if a function instead of a parameter is to be used. Since thermal lift can be set to negative values in a sink, a separate flag is provided in this case.

+In version 0.61, thermal lift is implemented by function. There is no easy way to implement any weather parameter by function in an effect volume, as this requires some amount of Nasal coding. +

6. Property tree structure

The internal state of the local weather system is found in the property tree under local-weather/. In this directory, various loop flags are found. They indicate the state of the main monitoring loops - they are set to 1 if a loop is running, setting them to zero terminates the loop.

-The local-weather folder contains various subdirectories. clouds/ contains the record of all visible weather phenomena (clouds, precipitation layers, lightning...) in a subdirectory cloud[i]/. The total number of all models placed is accessible as local-weather/clouds/cloud-number. Inside each cloud/ subdirectory, there is a string type specifying the type of object and subdirectories position/ and orientation which contain the position and spatial orientation of the model inside the scenery. Note that the orientation property is obsolete for clouds which are rotated by the shader.

+The local-weather folder contains various subdirectories. clouds/ contains the record of all visible weather phenomena (clouds, precipitation layers, lightning...) in a subdirectory tile[j]/cloud[i]/. The total number of all models placed is accessible as local-weather/clouds/cloud-number. Inside each cloud/ subdirectory, there is a string type specifying the type of object and subdirectories position/ and orientation which contain the position and spatial orientation of the model inside the scenery. Note that the orientation property is obsolete for clouds which are rotated by the shader.

The local-weather/effect-volumes/ subfolder contains the management of the effect volumes. It has the total count of specified effect volumes, along with the count of currently active volumes for each property. If volumes are defined, their properties are stored under local-weather/effect-volumes/effect-volume[i]/. In each folder, there are position/ and volume/ storing the spatial position and extent of the volume, as well as the active-flag which is set to 1 if the airplane is in the volume and the geometry flag which determines if the volume has circular, elliptical or rectangular shape. Finally, the effects/ subfolder holds flags determining of a property is to be set when the volume is active and the corresponding values. On entry, the effect volumes also create a subfolder restore/ in which the conditions as they were when the volume was entered are saved.

local-weather/interpolation/ holds all properties which are set by the interpolation system, as well as subfolders station[i]/ in which the weather station information for the interpolation are found. Basically, here is the state of the weather as it is outside of effect volumes. Since parameters may be set to different values in effect volumes, the folder local-weather/current/ contains the weather as the local weather system currently thinks it should be. Currently, weather is actually passed to the Flightgear environment system through several workarounds. In a clean C++ supported version, the parameters should be read from here.

+local-weather/tiles stores the information of the 9 managed weather tiles (the one the airplane is currently in, and the 8 surrounding it). By default each directory contains the tile center coordinates and a flag if it has been generated. Tiles are not generated unless a minimum distance to the tile center has been reached. Once this happens, the tile type is written as a code, and the cloud, interpolation and effect volume information corresponding to the tile is generated.

+

7. Weather tile setup

Examples for weather tile setup can be found in Nasal/weather-tiles.nas. Each tile is generated by a sequence of Nasal function calls to first set weather stations, then to draw the cloud layers, and effect volumes. Finally, all necessary loops must be started. It is a bit awkward to have to write in Nasal to customize the system, but I can't think of a reasonable GUI for the task, except marking every placement on a map which exceeds my coding skills a bit. The problem is that there is no real standard solution - every weather tile needs different calls, sometimes a large one generating many clouds, sometimes several smaller ones.

@@ -165,8 +185,23 @@ If the cloud layer has an orientation, then all placement coordinates should be To make your own tile visible, an entry in the menu gui/dialogs/local_weather_tiles.xml needs to be created and the name needs to be added with a tile setup call to the function set_tile in Nasal/local_weather.nas. +

8. Performance tuning

-

8. Known issues

+With default settings, the local weather package generates a 40x40 km weather tile when the aircraft is closer than 35 km to the tile center and unloads it when the aircraft is more than 37 km away. This means that the system can generate at most 4 tiles at once and clouds are visible for at least 15 km and up to 30 km (the latter number determined by fading in the shaders). However, rendering and managing multiple overcast cloud layers in a region of 80x80 km is a significant drain on performance. For older systems, a few things can be tried:

+ +* the menu option 'asymmetric range' decreases loading and unloading ranges in a 45 degree sector behind the aircraft. This means that in straight flight, less tiles will be loaded at the same time, as tiles in the rear are unloaded more quickly. The option is currently experimental.

+ +* a further reduction in the amount of simultaneously generated tiles can be achieved by changing the ranges. These are exposed in the property tree as local-weather/config/distance-to-load-tile-m and local-weather/config/distance-to-remove-tile-m. Note that the removal range must be larger than the loading range - otherwise just generated tiles will be immediately unloaded! Ranges below 20 km will guarantee that only one tile is loaded at a time, but will create empty spots when no tile is loaded. A range above 28 km will guarantee that the aircraft never flies in an empty tile, but empty sky in front will be visible. Finally, ranges above 56 km guarantee that all 9 tiles (a region of 120x120 km) are managed at all times - but will most likely cause a severe drop in framerate for most scenarios.

+ +* if this does not help, try avoiding scenarios with large cloud count. As a rule, low pressure areas have high cloud count, high pressure areas have a low cloud count.

+ +* a drastic solution is to set the visual ranges lower. Currently, cloud models are set to be visible up to 30 km. Changing the visibility range in the range animation of all cloud model xml wrappers will improve performance accordingly. To achieve a nice fading into the background instead of a sudden disappearance, it is recommended to adjust the visibility range in the shaders accordingly. It would probably be good to expose the visual range as a property, but currently it's not yet done, as passing a property to the shader requires Flightgear CVS and cannot be done in 2.0.0.

+ +Performance for overcast layers currently is a limiting issue and there are a few ideas around how to improve it - dependent if these work or not, future releases may work better.

+ +* a different issue is a characteristic small pause every 3 seconds. This is caused by the interpolation loop resetting the weather parameters. Currently, a computationally expensive workaround is needed to do so, causing the problem. Work on a better environment controller is on the way, however until that modification to the core Flightgear code is implemented, the best solution is to set the loop time in Nasal/local-weather.nas to a larger value.

+ +

9. Known issues

* The local weather system does not mix well with the standard weather system. 3d cloud layers can be placed in the absence of effect volumes, but any effect volume causing precipitation will let the layer behave in a strange way. Likewise, 2d cloud layers can be placed, but may or may not lead to strange rendering artefacts. Local weather, as long as interpolation and effect volumes are running, will in general overwrite all other settings - bother real weather METAR and user-specified settings from the menu. The results of mixing standard and local weather settings are unpredictable, and may not lead to the desired results.

@@ -174,8 +209,18 @@ To make your own tile visible, an entry in the menu gui/dialogs/local_weather * Rain and snow may not start properly. For me, rain is only generated when I switch 'Shader effects' on and off in the menu on startup, otherwise neither moving the menu slider nor entering an effect volume generate rain. This seems to be a bug of some Flightgear versions, not of the local weather system.

+* Especially with multiple overcast layers, loading and unloading weather tiles may take a long time / cause severe drops in framerate. Please refer to performance tuning to solve such problems. In general, overcast layers do require a system on the high end of the performance scale to render properly.

-Thorsten Renk, April 2010 +* The local weather package is able to occasionally trigger errors like 'Warning:: Picked up error in TriangleIntersect'. These seem to be a problem in the core Flightgear code - the package does nothing but placing normal (rather simple) AC3D models into the scenery.

+ +* The thermals in the soaring scenarios need a CVS patch to work.

+ +

10. Credits

+ +The model of a thermal has been developed by Patrice Poly. The shader code used to transform clouds is heavily based on prior work by Stuart Buchanan.

+ + +Thorsten Renk, May 2010 diff --git a/Docs/carrier-ops08.jpg b/Docs/carrier-ops08.jpg new file mode 100644 index 000000000..139c48e3b Binary files /dev/null and b/Docs/carrier-ops08.jpg differ diff --git a/Docs/clouds-detailed01.jpg b/Docs/clouds-detailed01.jpg new file mode 100644 index 000000000..e380880e3 Binary files /dev/null and b/Docs/clouds-detailed01.jpg differ diff --git a/Docs/clouds-lpb01.jpg b/Docs/clouds-lpb01.jpg new file mode 100644 index 000000000..6a8def019 Binary files /dev/null and b/Docs/clouds-lpb01.jpg differ diff --git a/Docs/menu2.jpg b/Docs/menu2.jpg index 740a01984..ba50407bb 100644 Binary files a/Docs/menu2.jpg and b/Docs/menu2.jpg differ diff --git a/Effects/clouds-thin.eff b/Effects/clouds-thin.eff index 86dfebe40..827da1893 100644 --- a/Effects/clouds-thin.eff +++ b/Effects/clouds-thin.eff @@ -1,68 +1,58 @@ - Effects/clouds-thin - - - - - - - - /sim/rendering/shader-effects - - 1.0 - - - - - - - true - - 0.5 0.5 0.5 1.0 - 0.5 0.5 0.5 1.0 - off - - - greater - 0.01 - - smooth - - src-alpha - one-minus-src-alpha - - - false - - - 10 - DepthSortedBin - - - 0 - - texture[0]/type - - - texture[0]/image - - - texture[0]/filter - - - texture[0]/wrap-s - - - texture[0]/wrap-t - - + true + + 0.5 0.5 0.5 1.0 + 0.5 0.5 0.5 1.0 + off + + + greater + 0.01 + + smooth + + src-alpha + one-minus-src-alpha + + + false + + + 10 + DepthSortedBin + + + 0 + texture[0]/type + texture[0]/image + texture[0]/filter + texture[0]/wrap-s + texture[0]/wrap-t + - - - Shaders/clouds-thin.vert - Shaders/clouds-thin.frag - - - - baseTexture - sampler-2d - 0 - - true - - + + + baseTexture + sampler-2d + 0 + + true + + diff --git a/Effects/clouds-thinlayer.eff b/Effects/clouds-thinlayer.eff new file mode 100644 index 000000000..8d22f82c5 --- /dev/null +++ b/Effects/clouds-thinlayer.eff @@ -0,0 +1,64 @@ + + + Effects/clouds-layered + + + + + + + + /sim/rendering/shader-effects + + 1.0 + + + + + + + true + + 0.5 0.5 0.5 1.0 + 0.5 0.5 0.5 1.0 + off + + + greater + 0.01 + + smooth + + src-alpha + one-minus-src-alpha + + + false + + + 10 + DepthSortedBin + + + 0 + texture[0]/type + texture[0]/image + texture[0]/filter + texture[0]/wrap-s + texture[0]/wrap-t + + + + Shaders/clouds-thinlayer.vert + Shaders/clouds-thinlayer.frag + + + baseTexture + sampler-2d + 0 + + true + + + diff --git a/Effects/test.eff b/Effects/test.eff new file mode 100644 index 000000000..c5b4e8435 --- /dev/null +++ b/Effects/test.eff @@ -0,0 +1,81 @@ + + + Effects/test + + + + + + + + /sim/rendering/shader-effects + + 1.0 + + + + + + + true + + 0.5 0.5 0.5 1.0 + 0.5 0.5 0.5 1.0 + off + + + greater + 0.01 + + smooth + + src-alpha + one-minus-src-alpha + + + false + + + 10 + DepthSortedBin + + + 0 + texture[0]/type + texture[0]/image + texture[0]/filter + texture[0]/wrap-s + texture[0]/wrap-t + + + + + Shaders/test.vert + Shaders/test.frag + + + + baseTexture + sampler-2d + 0 + + + shading + float + 0.5 + + true + + + diff --git a/Nasal/local_weather.nas b/Nasal/local_weather.nas index 72adbc244..3f9609731 100644 --- a/Nasal/local_weather.nas +++ b/Nasal/local_weather.nas @@ -1,8 +1,59 @@ -################################################# +######################################################## # routines to set up, transform and manage local weather -# Thorsten Renk, April 2010 -################################################# +# Thorsten Renk, May 2010 +# thermal model by Patrice Poly, April 2010 +######################################################## + +# function purpose +# +# calc_geo to compute the latitude to meter conversion +# calc_d_sq to compute a distance square in local Cartesian approximation +# volume_effect_loop to check if the aircraft has entered an effect volume +# interpolation_loop to continuously interpolate weather parameters between stations +# thermal_lift _loop to manage the detailed thermal lift model +# thermal_lift_start to start the detailed thermal model +# effect_volume_start to manage parameters when an effect volume is entered +# effect_volume_stop to manage parameters when an effect volume is left +# setVisibility to set the visibility to a given value +# setRain to set rain to a given value +# setSnow to set snow to a given value +# setTemperature to set temperature to a given value +# setPressure to set pressure to a given value +# setDewpoint to set the dewpoint to a given value +# setLift to set thermal lift to a given value - obsolete +# ts_factor (helper function for thermal lift model) +# tl_factor (helper function for thermal lift model) +# calcLift_max to calculate the maximal available thermal lift for given altitude +# calcLift to calculate the thermal lift at aircraft position +# randomize_pos to randomize the position of clouds placed in a streak call +# select_cloud_model to select a path to the cloud model, given the cloud type and subtype +# create_cloud to place a single cloud into the scenery +# create_cloud_vec to place a single cloud into an array to be written later +# clear_all to remove all clouds, effect volumes and weather stations and stop loops +# create_cumosys wrapper to place a convective cloud system based on terrain coverage +# cumulus_loop to place 25 Cumulus clouds each frame +# create_cumulus to place a convective cloud system based on terrain coverage +# terrain_presampling to get information about terrain elevation +# create_rise_clouds to create a barrier cloud system +# create_streak to create a cloud streak +# create_layer to create a cloud layer with optional precipitation +# cloud_placement_loop to place clouds from a storage array into the scenery +# create_effect_volume to create an effect volume +# effect_placement_loop to place effect volumes from a storage array +# create_effect_volume_vec to create effect volumes in a storage array +# set_weather_station to specify a weather station for interpolation +# streak_wrapper wrapper to execute streak from menu +# convection wrapper wrapper to execute convective clouds from menu +# barrier wrapper wrapper to execute barrier clouds from menu +# single_cloud_wrapper wrapper to create single cloud from menu +# layer wrapper wrapper to create layer from menu +# set_tile to call a weather tile creation from menu +# startup to prepare the package at startup + +################################### +# geospatial helper functions +################################### var calc_geo = func(clat) { @@ -12,66 +63,85 @@ m_to_lon = 1.0/lon_to_m; } +var calc_d_sq = func (lat1, lon1, lat2, lon2) { + +var x = (lat1 - lat2) * lat_to_m; +var y = (lon1 - lon2) * lon_to_m; + +return (x*x + y*y); +} + + ################################### # effect volume management loop ################################### -var effect_volume_loop = func { +var effect_volume_loop = func (index, n_active) { +var n = 25; var evNode = props.globals.getNode("local-weather/effect-volumes", 1).getChildren("effect-volume"); -var viewpos = geo.viewer_position(); +var esize = size(evNode); +var viewpos = geo.aircraft_position(); +var active_counter = n_active; + +var i_max = index + 25; +if (i_max > esize) {i_max = esize;} + +for (var i = index; i < i_max; i = i+1) + { + e = evNode[i]; -foreach (var e; evNode) { var flag = 0; #default assumption is that we're not in the volume - var geometry = e.getNode("geometry").getValue(); - var elat = e.getNode("position/latitude-deg").getValue(); - var elon = e.getNode("position/longitude-deg").getValue(); var ealt_min = e.getNode("position/min-altitude-ft").getValue() * ft_to_m; var ealt_max = e.getNode("position/max-altitude-ft").getValue() * ft_to_m; - var rx = e.getNode("volume/size-x").getValue(); - var ry = e.getNode("volume/size-y").getValue(); - var phi = e.getNode("volume/orientation-deg").getValue(); - phi = phi * math.pi/180.0; - - var evpos = geo.Coord.new(); - evpos.set_latlon(elat,elon,ealt_min); - - var d = viewpos.distance_to(evpos); - #print(d); - - var active_flag = e.getNode("active-flag").getValue(); # see if the node was active previously if ((viewpos.alt() > ealt_min) and (viewpos.alt() < ealt_max)) # we are in the correct alt range { + # so we load geometry next + var geometry = e.getNode("geometry").getValue(); + var elat = e.getNode("position/latitude-deg").getValue(); + var elon = e.getNode("position/longitude-deg").getValue(); + var rx = e.getNode("volume/size-x").getValue(); + + if (geometry == 1) # we have a cylinder { - if (d < rx) {flag =1;} + var d_sq = calc_d_sq(viewpos.lat(), viewpos.lon(), elat, elon); + if (d_sq < (rx*rx)) {flag =1;} } - if (geometry == 2) # we have an elliptic shape + else if (geometry == 2) # we have an elliptic shape { + # get orientation + var ry = e.getNode("volume/size-y").getValue(); + var phi = e.getNode("volume/orientation-deg").getValue(); + phi = phi * math.pi/180.0; # first get unrotated coordinates - var xx = (viewpos.lon() - evpos.lon()) * lon_to_m; - var yy = (viewpos.lat() - evpos.lat()) * lat_to_m; + var xx = (viewpos.lon() - elon) * lon_to_m; + var yy = (viewpos.lat() - elat) * lat_to_m; # then rotate to align with the shape var x = xx * math.cos(phi) - yy * math.sin(phi); var y = yy * math.cos(phi) + xx * math.sin(phi); # then check elliptic condition if ((x*x)/(rx*rx) + (y*y)/(ry*ry) <1) {flag = 1;} } - if (geometry == 3) # we have a rectangular shape + else if (geometry == 3) # we have a rectangular shape { + # get orientation + var ry = e.getNode("volume/size-y").getValue(); + var phi = e.getNode("volume/orientation-deg").getValue(); + phi = phi * math.pi/180.0; # first get unrotated coordinates - var xx = (viewpos.lon() - evpos.lon()) * lon_to_m; - var yy = (viewpos.lat() - evpos.lat()) * lat_to_m; + var xx = (viewpos.lon() - elon) * lon_to_m; + var yy = (viewpos.lat() - elat) * lat_to_m; # then rotate to align with the shape var x = xx * math.cos(phi) - yy * math.sin(phi); var y = yy * math.cos(phi) + xx * math.sin(phi); # then check rectangle condition if ((x>-rx) and (x-ry) and (y 80000.0) and (d<100000.0)) {s.remove();} } var vis = sum_vis/sum_norm; @@ -141,20 +244,30 @@ var p = sum_p/sum_norm; var D = sum_D/sum_norm; var T = sum_T/sum_norm; -iNode.getNode("visibility-m",1).setValue(vis); +# a simple altitude model for visibility - increase it with increasing altitude + +vis = vis + 0.3 * getprop("position/altitude-ft"); + +if (vis > 0.0) {iNode.getNode("visibility-m",1).setValue(vis);} # a redundancy check iNode.getNode("temperature-degc",1).setValue(T); iNode.getNode("dewpoint-degc",1).setValue(D); -iNode.getNode("pressure-sea-level-inhg",1).setValue(p); +if (p>0.0) {iNode.getNode("pressure-sea-level-inhg",1).setValue(p);} # a redundancy check # now check if an effect volume writes the property and set only if not flag = props.globals.getNode("local-weather/effect-volumes/number-active-vis").getValue(); -if (flag ==0) +if ((flag ==0) and (vis > 0.0)) { cNode.getNode("visibility-m").setValue(vis); setVisibility(vis); } +flag = props.globals.getNode("local-weather/effect-volumes/number-active-lift").getValue(); +if (flag ==0) + { + cNode.getNode("thermal-lift").setValue(0.0); + } + # no need to check for these, as they are not modelled in effect volumes cNode.getNode("temperature-degc",1).setValue(T); @@ -163,14 +276,87 @@ setTemperature(T); cNode.getNode("dewpoint-degc",1).setValue(D); setDewpoint(D); -cNode.getNode("pressure-sea-level-inhg",1).setValue(p); -setPressure(p); +if (p>0.0) {cNode.getNode("pressure-sea-level-inhg",1).setValue(p); setPressure(p);} if (getprop(lw~"interpolation-loop-flag") ==1) {settimer(interpolation_loop, 3.0);} } +################################### +# thermal lift loop +################################### + +var thermal_lift_loop = func { + +var cNode = props.globals.getNode(lw~"current", 1); +var lNode = props.globals.getNode(lw~"lift",1); + +var apos = geo.aircraft_position(); + +var tlat = lNode.getNode("latitude-deg").getValue(); +var tlon = lNode.getNode("longitude-deg").getValue(); +var tpos = geo.Coord.new(); +tpos.set_latlon(tlat,tlon,0.0); + +var d = apos.distance_to(tpos); +var alt = getprop("position/altitude-ft"); + + +var R = lNode.getNode("radius").getValue(); +var height = lNode.getNode("height").getValue(); +var cn = lNode.getNode("cn").getValue(); +var sh = lNode.getNode("sh").getValue(); +var max_lift = lNode.getNode("max_lift").getValue(); +var f_lift_radius = lNode.getNode("f_lift_radius").getValue(); + +# print(d," ", alt, " ", R, " ", height, " ", cn, " ", sh," ", max_lift," ", f_lift_radius, " ",0.0); + +var lift = calcLift(d, alt, R, height, cn, sh, max_lift, f_lift_radius, 0.0); +# print(lift); + +cNode.getChild("thermal-lift").setValue(lift); + +if (getprop(lw~"lift-loop-flag") ==1) {settimer(thermal_lift_loop, 0);} +} + +################################### +# thermal lift loop startup +################################### + +var thermal_lift_start = func (ev) { + +# copy the properties from effect volume to the lift folder + +var lNode = props.globals.getNode(lw~"lift",1); +lNode.getNode("radius",1).setValue(ev.getNode("effects/radius").getValue()); +lNode.getNode("height",1).setValue(ev.getNode("effects/height").getValue()); +lNode.getNode("cn",1).setValue(ev.getNode("effects/cn").getValue()); +lNode.getNode("sh",1).setValue(ev.getNode("effects/sh").getValue()); +lNode.getNode("max_lift",1).setValue(ev.getNode("effects/max_lift").getValue()); +lNode.getNode("f_lift_radius",1).setValue(ev.getNode("effects/f_lift_radius").getValue()); + +lNode.getNode("latitude-deg",1).setValue(ev.getNode("position/latitude-deg").getValue()); +lNode.getNode("longitude-deg",1).setValue(ev.getNode("position/longitude-deg").getValue()); + +# and start the lift loop, unless another one is already running +# so we block overlapping calls + +if (getprop(lw~"lift-loop-flag") == 0) +{setprop(lw~"lift-loop-flag",1); thermal_lift_loop();} + +} + +################################### +# thermal lift loop stop +################################### + +var thermal_lift_stop = func { + +setprop(lw~"lift-loop-flag",0); +setprop(lw~"current/thermal-lift",0.0); +} + #################################### # action taken when in effect volume #################################### @@ -222,9 +408,17 @@ if (ev.getNode("effects/thermal-lift-flag", 1).getValue()==1) var lift = ev.getNode("effects/thermal-lift").getValue(); ev.getNode("restore/thermal-lift",1).setValue(cNode.getNode("thermal-lift").getValue()); cNode.getNode("thermal-lift").setValue(lift); + #setLift(ev.getNode("position/latitude-deg").getValue(),ev.getNode("position/longitude-deg").getValue(),1); ev.getNode("restore/number-entry-lift",1).setValue(getprop(lw~"effect-volumes/number-active-lift")); setprop(lw~"effect-volumes/number-active-lift",getprop(lw~"effect-volumes/number-active-lift")+1); } +else if (ev.getNode("effects/thermal-lift-flag", 1).getValue()==2) # thermal by function + { + ev.getNode("restore/thermal-lift",1).setValue(cNode.getNode("thermal-lift").getValue()); + ev.getNode("restore/number-entry-lift",1).setValue(getprop(lw~"effect-volumes/number-active-lift")); + setprop(lw~"effect-volumes/number-active-lift",getprop(lw~"effect-volumes/number-active-lift")+1); + thermal_lift_start(ev); + } } @@ -289,6 +483,14 @@ if (ev.getNode("effects/thermal-lift-flag", 1).getValue()==1) else if ((n_active -1) == n_entry) {var lift = ev.getNode("restore/thermal-lift").getValue();} else {var lift = cNode.getNode("thermal-lift").getValue();} cNode.getNode("thermal-lift").setValue(lift); + # some cheat code + # setLift(ev.getNode("position/latitude-deg").getValue(),ev.getNode("position/longitude-deg").getValue(),0); + + setprop(lw~"effect-volumes/number-active-lift",getprop(lw~"effect-volumes/number-active-lift")-1); + } +else if (ev.getNode("effects/thermal-lift-flag", 1).getValue()==2) # thermal by function + { + thermal_lift_stop(); setprop(lw~"effect-volumes/number-active-lift",getprop(lw~"effect-volumes/number-active-lift")-1); } @@ -366,6 +568,7 @@ var setPressure = func (p) { # essentially we update the entry in config and reinit environment setprop(ec~"boundary/entry[0]/pressure-sea-level-inhg",p); +setprop(ec~"aloft/entry[0]/pressure-sea-level-inhg",p); fgcommand("reinit", props.Node.new({subsystem:"environment"})); } @@ -386,15 +589,115 @@ fgcommand("reinit", props.Node.new({subsystem:"environment"})); # set thermal lift to given value #################################### -var setLift = func (L) { +var setLift = func (lat, lon, flag) { -# this doesn't actually work with Flightgear 2.0.0 since environement overwrites the -# setting - so it's a hope for CVS -# -> probably obsolete as CVS patch reads out /local-weather/current +# this is a cheat - if you have an AI thermal present, this sets its coordinates to the +# current position -setprop("environment/thermal-lift",L); +if (flag==1) + { + setprop("ai/models/thermal/position/latitude-deg",lat); + setprop("ai/models/thermal/position/longitude-deg",lon); + } +else + { + setprop("ai/models/thermal/position/latitude-deg",0.1); + setprop("ai/models/thermal/position/longitude-deg",0.1); + + } + +#setprop("environment/thermal-lift",L); } +######################################### +# compute thermal lift in detailed model +######################################### + +var ts_factor = func (t, alt, height) { + +# no time dependence modelled yet +return 1.0; + + +var t_a = t - (alt/height) * t1 -t1; + +if (t_a<0) {return 0.0;} +else if (t_a= t1) and (t < t2)) {return 1.0;} +else if (t_a >= t2) {return 0.5 - 0.5 * math.cos((1.0-(t2-t_a)/(t3-t2))*math.pi);} +} + +var tl_factor = func (t, alt, height) { + +# no time dependence modelled yet +return 1.0; + +var t_a = t - (alt/height) * t1; + +if (t_a<0) {return 0.0;} +else if (t_a= t1) and (t < t2)) {return 1.0;} +else if (t_a >= t2) {return 0.5 - 0.5 * math.cos((1.0-(t2-t_a)/(t3-t2))*math.pi);} +} + + +var calcLift_max = func (alt, max_lift, height) { + +# no lift below ground +if (alt < 0.0) {return 0.0;} + +# lift ramps up to full within 200 m +else if (alt < 200.0*m_to_ft) + {return max_lift * 0.5 * (1.0 + math.cos((1.0-alt/(200.0*m_to_ft))*math.pi));} + +# constant max. lift in main body +else if ((alt > 200.0*m_to_ft) and (alt < height)) + {return max_lift;} + +# decreasing lift from cloudbase to 10% above base +else if ((alt > height ) and (alt < height*1.1)) + {return max_lift * 0.5 * (1.0 - math.cos((1.0-10.0*alt/height)*math.pi));} + +# no lift available above +else {return 0.0;} +} + + + +var calcLift = func (d, alt, R, height, cn, sh, max_lift, f_lift_radius, t) { + +# radius of slice at given altitude +var r_total = (cn + alt/height*(1.0-cn)) * (R - R * (1.0- sh ) * (1.0 - ((2.0*alt/height)-1.0)*((2.0*alt/height)-1.0))); + + +# print("r_total: ", r_total, "d: ",d); +# print("alt: ", alt, "height: ",height); + +# no lift if we're outside the radius or above the thermal +if ((d > r_total) or (alt > 1.1*height)) { return 0.0; } + +# fraction of radius providing lift +var r_lift = f_lift_radius * r_total; + +# print("r_lift: ", r_lift); + +# if we are in the sink portion, get the max. sink for this time and altitude and adjust for actual position +if ((d < r_total ) and (d > r_lift)) + { + var s_max = 0.5 * calcLift_max(alt, max_lift, height) * ts_factor(t, alt, height); + # print("s_max: ", s_max); + return s_max * math.sin(math.pi * (1.0 + (d-r_lift) * (1.0/(r_total - r_lift)))); + } +# else we are in the lift portion, get the max. lift for this time and altitude and adjust for actual position +else + { + var l_max = calcLift_max(alt, max_lift, height) * tl_factor(t, alt, height); + # print("l_max: ", l_max); + return l_max * math.cos(math.pi * (d/(2.0 * r_lift))); + } +} + + ########################################################### # randomize positions of clouds created in a fixed pattern ########################################################### @@ -404,14 +707,44 @@ var randomize_pos = func (type, alt_var, pos_var_x, pos_var_y, dir) { # it is rather stupid coding to force the randomization call after the streak call, and I'll probably # restructure the whole thing soon -var cloudNode = props.globals.getNode("local-weather/clouds", 1).getChildren("cloud"); +dir = dir * math.pi/180.0; + +if (getprop(lw~"tmp/thread-flag") == 1) + { + var s = size(clouds_type); + for (i=0; i 0.8) {path = "Models/Weather/cumulus_sl7.xml";} + else if (rn > 0.6) {path = "Models/Weather/cumulus_sl8.xml";} + else if (rn > 0.4) {path = "Models/Weather/cumulus_sl9.xml";} + else if (rn > 0.2) {path = "Models/Weather/cumulus_sl10.xml";} + else {path = "Models/Weather/cumulus_sl11.xml";} + } + else if (subtype == "large") { + if (rn > 0.8) {path = "Models/Weather/cumulus_sl1.xml";} + else if (rn > 0.6) {path = "Models/Weather/cumulus_sl2.xml";} + else if (rn > 0.4) {path = "Models/Weather/cumulus_sl3.xml";} + else if (rn > 0.2) {path = "Models/Weather/cumulus_sl4.xml";} + else {path = "Models/Weather/cumulus_sl5.xml";} + } + + } + else if (type == "Altocumulus"){ if (subtype == "small") { if (rn > 0.8) {path = "Models/Weather/altocumulus_shader6.xml";} @@ -516,13 +868,14 @@ else if ((type == "Cumulonimbus") or (type == "Cumulonimbus (rain)")) { } } else if (type == "Cirrus") { - if (subtype == "small") { - if (rn > 0.5) {path = "Models/Weather/cirrus1.xml";} - else {path = "Models/Weather/cirrus2.xml";} + if (subtype == "large") { + if (rn > 0.66) {path = "Models/Weather/cirrus1.xml";} + else if (rn > 0.33) {path = "Models/Weather/cirrus2.xml";} + else {path = "Models/Weather/cirrus3.xml";} } - else if (subtype == "large") { - if (rn > 0.5) {path = "Models/Weather/cirrus1.xml";} - else {path = "Models/Weather/cirrus2.xml";} + else if (subtype == "small") { + if (rn > 0.5) {path = "Models/Weather/cirrus_amorphous1.xml";} + else {path = "Models/Weather/cirrus_amorphous2.xml";} } } else if (type == "Cirrocumulus") { @@ -532,7 +885,7 @@ else if (type == "Cirrocumulus") { } else if (subtype == "large") { if (rn > 0.5) {path = "Models/Weather/cirrocumulus1.xml";} - else {path = "Models/Weather/cirrocumulus2.xml";} + else {path = "Models/Weather/cirrocumulus4.xml";} } } else if (type == "Nimbus") { @@ -567,6 +920,68 @@ else if (type == "Stratus") { else {path = "Models/Weather/stratus_layer5.xml";} } } +else if (type == "Stratus (thin)") { + if (subtype == "small") { + if (rn > 0.8) {path = "Models/Weather/stratus_tlayer1.xml";} + else if (rn > 0.6) {path = "Models/Weather/stratus_tlayer2.xml";} + else if (rn > 0.4) {path = "Models/Weather/stratus_tlayer3.xml";} + else if (rn > 0.2) {path = "Models/Weather/stratus_tlayer4.xml";} + else {path = "Models/Weather/stratus_tlayer5.xml";} + } + else if (subtype == "large") { + if (rn > 0.8) {path = "Models/Weather/stratus_tlayer1.xml";} + else if (rn > 0.6) {path = "Models/Weather/stratus_tlayer2.xml";} + else if (rn > 0.4) {path = "Models/Weather/stratus_tlayer3.xml";} + else if (rn > 0.2) {path = "Models/Weather/stratus_tlayer4.xml";} + else {path = "Models/Weather/stratus_tlayer5.xml";} + } + } +else if (type == "Cirrostratus") { + if (subtype == "small") { + if (rn > 0.75) {path = "Models/Weather/cirrostratus1.xml";} + else if (rn > 0.5) {path = "Models/Weather/cirrostratus2.xml";} + else if (rn > 0.25) {path = "Models/Weather/cirrostratus3.xml";} + else {path = "Models/Weather/cirrostratus4.xml";} + } + else if (subtype == "large") { + if (rn > 0.75) {path = "Models/Weather/cirrostratus1.xml";} + else if (rn > 0.5) {path = "Models/Weather/cirrostratus2.xml";} + else if (rn > 0.25) {path = "Models/Weather/cirrostratus3.xml";} + else {path = "Models/Weather/cirrostratus4.xml";} + } + } +else if (type == "Fog (thin)") { + if (subtype == "small") { + if (rn > 0.8) {path = "Models/Weather/stratus_thin1.xml";} + else if (rn > 0.6) {path = "Models/Weather/stratus_thin2.xml";} + else if (rn > 0.4) {path = "Models/Weather/stratus_thin3.xml";} + else if (rn > 0.2) {path = "Models/Weather/stratus_thin4.xml";} + else {path = "Models/Weather/stratus_thin5.xml";} + } + else if (subtype == "large") { + if (rn > 0.8) {path = "Models/Weather/stratus_thin1.xml";} + else if (rn > 0.6) {path = "Models/Weather/stratus_thin2.xml";} + else if (rn > 0.4) {path = "Models/Weather/stratus_thin3.xml";} + else if (rn > 0.2) {path = "Models/Weather/stratus_thin4.xml";} + else {path = "Models/Weather/stratus_thin5.xml";} + } + } +else if (type == "Fog (thick)") { + if (subtype == "small") { + if (rn > 0.8) {path = "Models/Weather/stratus_thick1.xml";} + else if (rn > 0.6) {path = "Models/Weather/stratus_thick2.xml";} + else if (rn > 0.4) {path = "Models/Weather/stratus_thick3.xml";} + else if (rn > 0.2) {path = "Models/Weather/stratus_thick4.xml";} + else {path = "Models/Weather/stratus_thick5.xml";} + } + else if (subtype == "large") { + if (rn > 0.8) {path = "Models/Weather/stratus_thick1.xml";} + else if (rn > 0.6) {path = "Models/Weather/stratus_thick2.xml";} + else if (rn > 0.4) {path = "Models/Weather/stratus_thick3.xml";} + else if (rn > 0.2) {path = "Models/Weather/stratus_thick4.xml";} + else {path = "Models/Weather/stratus_thick5.xml";} + } + } else {print("Cloud type ", type, " subtype ",subtype, " not available!");} @@ -578,20 +993,28 @@ return path; # place a single cloud ########################################################### -var create_cloud = func(type, path, lat, long, alt, heading, rain_flag) { +var create_cloud = func(type, path, lat, long, alt, heading, rnd_flag) { + +var tile_counter = getprop(lw~"tiles/tile-counter"); var n = props.globals.getNode("local-weather/clouds", 1); -var cloud_number = n.getNode("cloud-number").getValue(); - for (var i = cloud_number; 1; i += 1) - if (n.getChild("cloud", i, 0) == nil) - break; - cl = n.getChild("cloud", i, 1); +var c = n.getChild("tile",tile_counter,1); -var m = props.globals.getNode("models", 1); +var cloud_number = n.getNode("placement-index").getValue(); for (var i = cloud_number; 1; i += 1) + if (c.getChild("cloud", i, 0) == nil) + break; + cl = c.getChild("cloud", i, 1); + n.getNode("placement-index").setValue(i); + + +var model_number = n.getNode("model-placement-index").getValue(); +var m = props.globals.getNode("models", 1); + for (var i = model_number; 1; i += 1) if (m.getChild("model", i, 0) == nil) break; - model = m.getChild("model", i, 1); + model = m.getChild("model", i, 1); + n.getNode("model-placement-index").setValue(i); @@ -602,9 +1025,8 @@ var altN = cl.getNode("position/altitude-ft", 1); altN.setValue(alt); var hdgN = cl.getNode("orientation/true-heading-deg", 1); hdgN.setValue(heading); var pitchN = cl.getNode("orientation/pitch-deg", 1); pitchN.setValue(0.0); var rollN = cl.getNode("orientation/roll-deg", 1);rollN.setValue(0.0); -#cl.getNode("velocities/true-airspeed-kt", 1).setValue(kias); -#cl.getNode("velocities/vertical-speed-fps", 1).setValue(0.0); -#cl.getNode("position/trafo-flag", 1).setValue(1); + +cl.getNode("tile-index",1).setValue(tile_counter); model.getNode("path", 1).setValue(path); model.getNode("legend", 1).setValue("Cloud"); @@ -614,13 +1036,29 @@ model.getNode("elevation-ft-prop", 1).setValue(altN.getPath()); model.getNode("heading-deg-prop", 1).setValue(hdgN.getPath()); model.getNode("pitch-deg-prop", 1).setValue(pitchN.getPath()); model.getNode("roll-deg-prop", 1).setValue(rollN.getPath()); +model.getNode("tile-index",1).setValue(tile_counter); model.getNode("load", 1).remove(); n.getNode("cloud-number").setValue(n.getNode("cloud-number").getValue()+1); - } + +########################################################### +# place a single cloud into a vector to be processed +# in a split loop +########################################################### + +var create_cloud_vec = func(type, path, lat, long, alt, heading, rain_flag) { + +append(clouds_type,type); +append(clouds_path,path); +append(clouds_lat,lat); +append(clouds_lon,long); +append(clouds_alt,alt); +append(clouds_orientation,heading); + +} ########################################################### # clear all clouds and effects ########################################################### @@ -629,8 +1067,9 @@ var clear_all = func { # clear the clouds and models -var cloudNode = props.globals.getNode("local-weather/clouds", 1); -cloudNode.removeChildren("cloud"); +var cloudNode = props.globals.getNode(lw~"clouds", 1); +cloudNode.removeChildren("tile"); + var modelNode = props.globals.getNode("models", 1).getChildren("model"); foreach (var m; modelNode) @@ -652,6 +1091,8 @@ props.globals.getNode("local-weather/effect-volumes", 1).removeChildren("effect- setprop(lw~"effect-loop-flag",0); setprop(lw~"interpolation-loop-flag",0); +setprop(lw~"tile-loop-flag",0); +setprop(lw~"lift-loop-flag",0); setprop(lw~"tmp/generate-thermal-lift-flag",0); # also remove rain and snow effects @@ -659,14 +1100,100 @@ setprop(lw~"tmp/generate-thermal-lift-flag",0); setRain(0.0); setSnow(0.0); +# set placement indices to zero + +setprop(lw~"clouds/placement-index",0); +setprop(lw~"clouds/model-placement-index",0); +setprop(lw~"effect-volumes/effect-placement-index",0); +setprop(lw~"tiles/tile-counter",0); + + } + ########################################################### -# place a cumulus system +# detailed Cumulus clouds created from multiple sprites +########################################################### + +var create_detailed_cumulus_cloud = func (lat, lon, alt, size) { + +#print(size); + +if (size>2.0) + { + var height = 1200; + var n = 24; + var x = 800.0; + var y = 300.0; + var edge = 0.3; + } + +else if (size>1.0) + { + var height = 400; + var n = 8; + var x = 400.0; + var y = 200.0; + var edge = 0.3; + } +else + { + var height = 100; + var n = 4; + var x = 200.0; + var y = 200.0; + var edge = 1.0; + } + +var alpha = rand() * 180.0; + + + +create_streak("Cumulus (cloudlet)",lat,lon, alt+ 0.5* (height +cloud_vertical_size_map["Cumulus"] * ft_to_m),n,0.0,edge,1,0.0,0.0,alpha,1.0); +randomize_pos("Cumulus (cloudlet)",height,x,y,alpha); + +} + +########################################################### +# wrappers for convective cloud system to distribute +# call across several frames if needed ########################################################### var create_cumosys = func (blat, blon, balt, nc, size) { +# realistic Cumulus has somewhat larger models, so compensate to get the same coverage +if (getprop(lw~"config/detailed-clouds-flag") == 1) + {nc = int(0.5 * nc);} + +if (getprop(lw~"tmp/thread-flag") == 1) + {setprop(lw~"tmp/convective-status", "computing"); + cumulus_loop(blat, blon, balt, nc, size);} + +else + {create_cumulus(blat, blon, balt, nc, size); + print("Convective system done!");} +} + + + +var cumulus_loop = func (blat, blon, balt, nc, size) { + +var n = 25; + +if (nc < 0) {print("Convective system done!");setprop(lw~"tmp/convective-status", "idle");return;} + +#print("nc is now: ",nc); +create_cumulus(blat, blon, balt, n, size); + +settimer( func {cumulus_loop(blat, blon, balt, nc-n, size) },0); +} + +########################################################### +# place a convective cloud system +########################################################### + +var create_cumulus = func (blat, blon, balt, nc, size) { + var path = "Models/Weather/blank.ac"; @@ -674,6 +1201,8 @@ var i = 0; var p = 0.0; var rn = 0.0; var place_lift_flag = 0; +var strength = 0.0; +var detail_flag = getprop(lw~"config/detailed-clouds-flag"); var sec_to_rad = 2.0 * math.pi/86400; @@ -700,6 +1229,7 @@ while (i < nc) { p = 0.0; place_lift_flag = 0; + strength = 0.0; var x = (2.0 * rand() - 1.0) * size; var y = (2.0 * rand() - 1.0) * size; @@ -720,24 +1250,48 @@ while (i < nc) { { if (rand() + (2.0 * p) > 1.0) { - path = select_cloud_model("Cumulus","large"); place_lift_flag = 1; + path = select_cloud_model("Cumulus","large"); place_lift_flag = 1; strength=1.0; } else {path = select_cloud_model("Cumulus","small");} - create_cloud("Cumulus", path, lat, lon, balt, 0.0, 0); - + if (getprop(lw~"tmp/generate-thermal-lift-flag") != 3) # see if we produce blue thermals + { + if (getprop(lw~"tmp/thread-flag") == 1) + { + if (detail_flag == 0){create_cloud_vec("Cumulus",path,lat,lon, balt, 0.0, 0);} + else {create_detailed_cumulus_cloud(lat, lon, balt, p + strength+rand());} + } + else + { + if (detail_flag == 0){create_cloud("Cumulus", path, lat, lon, balt, 0.0, 0);} + else {create_detailed_cumulus_cloud(lat, lon, balt, p + strength+rand());} + } + } + # now see if we need to create a thermal - first check the flag if (getprop(lw~"tmp/generate-thermal-lift-flag") == 1) { # now check if convection is strong if (place_lift_flag == 1) - { - var lift = 1.0 + 20.0 * p * rand(); - var radius = 300 + 300 * rand(); - create_effect_volume(1, lat, lon, radius, radius, 0.0, 0.0, balt+500.0, -1, -1, -1, -1, lift, 1); - + { + var lift = 3.0 + 20.0 * p * rand(); + var radius = 500 + 500 * rand(); + create_effect_volume(1, lat, lon, radius, radius, 0.0, 0.0, balt+500.0, -1, -1, -1, -1, lift, 1); } # end if place_lift_flag } # end if generate-thermal-lift-flag + else if ((getprop(lw~"tmp/generate-thermal-lift-flag") == 2) or (getprop(lw~"tmp/generate-thermal-lift-flag") == 3)) + { + + if (place_lift_flag == 1) + { + var lift = 3.0 + 20.0 * p * rand(); + var radius = 500 + 500 * rand(); + create_effect_volume(1, lat, lon, 1.2*radius, 1.2*radius, 0.0, 0.0, balt+500.0, -1, -1, -1, -1, lift, -2); + } # end if place_lift_flag + + } # end if generate-thermal-lift-flag + + } # end if rand < p i = i + 1; } # end while @@ -750,7 +1304,7 @@ while (i < nc) { var terrain_presampling = func { -var size = 15000.0; +var size = 20000.0; var blat = getprop("position/latitude-deg"); var blon = getprop("position/longitude-deg"); var elevation = 0.0; @@ -895,8 +1449,17 @@ for (var i=0; i 5.0) {flag = 1;} else {path = select_cloud_model(type,"large");} } - #var label = get_label(type); - if (flag==0){create_cloud("tmp_cloud", path, lat, long, balt, 0.0, 0);} + + #if (rand() > 0.5) {var beta = 0.0;} else {var beta = 180.0;} + + if (flag==0){ + if (getprop(lw~"tmp/thread-flag") == 1) + {create_cloud_vec("tmp_cloud", path, lat, long, balt, 0.0, 0);} + else + {create_cloud("tmp_cloud", path, lat, long, balt, 0.0, 0);} + + + } } } @@ -944,7 +1507,10 @@ while(i 135.0) and (abs(dir-current_heading) < 225.0)) + { + d_load = 0.7 * d_load; + d_remove = 0.7 * d_remove; + } + } + + #print(d); + if ((d < distance_to_load) and (flag==0)) # the tile needs to be generated, unless it already has been + { + setprop(lw~"tiles/tile-counter",getprop(lw~"tiles/tile-counter")+1); + print("Building tile unique index ",getprop(lw~"tiles/tile-counter")); + generate_tile(code, tpos.lat(), tpos.lon(),0); + t.getNode("generated-flag").setValue(1); + t.getNode("tile-index",1).setValue(getprop(lw~"tiles/tile-counter")); + } + + if ((d > distance_to_remove) and (flag==1)) # the tile needs to be deleted if it exists + { + print("Removing tile, unique index ", t.getNode("tile-index").getValue()); + remove_tile(t.getNode("tile-index").getValue()); + t.getNode("generated-flag").setValue(0); + } + i = i + 1; + } # end foreach + + #print("Minimum distance to: ",i_min); + + if (i_min != 4) # we've entered a different tile + { + print("Changing active tile to direction ", i_min); + change_active_tile(i_min); + } + +if (getprop(lw~"tile-loop-flag") ==1) {settimer(tile_management_loop, 5.0);} + +} + + +################################### +# tile generation call +################################### + +var generate_tile = func (code, lat, lon, index) { + +setprop(lw~"tiles/tmp/latitude-deg", lat); +setprop(lw~"tiles/tmp/longitude-deg",lon); + +if (getprop(lw~"tmp/tile-management") == "repeat tile") + { + if (code == "altocumulus_sky"){weather_tiles.set_altocumulus_tile();} + else if (code == "broken_layers") {weather_tiles.set_broken_layers_tile();} + else if (code == "stratus") {weather_tiles.set_overcast_stratus_tile();} + else if (code == "cumulus_sky") {weather_tiles.set_fair_weather_tile();} + else if (code == "gliders_sky") {weather_tiles.set_gliders_sky_tile();} + else if (code == "blue_thermals") {weather_tiles.set_blue_thermals_tile();} + else if (code == "summer_rain") {weather_tiles.set_summer_rain_tile();} + else if (code == "high_pressure_core") {weather_tiles.set_high_pressure_core_tile();} + else if (code == "high_pressure") {weather_tiles.set_high_pressure_tile();} + else if (code == "high_pressure_border") {weather_tiles.set_high_pressure_border_tile();} + else if (code == "low_pressure_border") {weather_tiles.set_low_pressure_border_tile();} + else if (code == "low_pressure") {weather_tiles.set_low_pressure_tile();} + else if (code == "low_pressure_core") {weather_tiles.set_low_pressure_core_tile();} + } +else if (getprop(lw~"tmp/tile-management") == "realistic weather") + { + var rn = rand(); + + if (code == "low_pressure_core") + { + if (rn > 0.3) {weather_tiles.set_low_pressure_core_tile();} + else {weather_tiles.set_low_pressure_tile();} + } + else if (code == "low_pressure") + { + if (rn > 0.3) {weather_tiles.set_low_pressure_tile();} + else if (rn > 0.15) {weather_tiles.set_low_pressure_core_tile();} + else {weather_tiles.set_low_pressure_border_tile();} + } + else if (code == "low_pressure_border") + { + if (rn > 0.3) {weather_tiles.set_low_pressure_border_tile();} + else if (rn > 0.15) {weather_tiles.set_low_pressure_tile();} + else {weather_tiles.set_high_pressure_border_tile();} + } + else if (code == "high_pressure_border") + { + if (rn > 0.3) {weather_tiles.set_high_pressure_border_tile();} + else if (rn > 0.15) {weather_tiles.set_high_pressure_tile();} + else {weather_tiles.set_low_pressure_border_tile();} + } + else if (code == "high_pressure") + { + if (rn > 0.3) {weather_tiles.set_high_pressure_tile();} + else if (rn > 0.15) {weather_tiles.set_high_pressure_border_tile();} + else {weather_tiles.set_high_pressure_core_tile();} + } + else if (code == "high_pressure_core") + { + if (rn > 0.3) {weather_tiles.set_high_pressure_core_tile();} + else {weather_tiles.set_high_pressure_tile();} + } + + } # end if mode == realistic weather +} + + +################################### +# tile removal call +################################### + + +var remove_tile_loop = func (index) { + +var n = 100; + +var flag_mod = 0; + +#var mvec = props.globals.getNode("models", 1).getChildren("model"); +#var msize = size(mvec); + +var status = getprop(lw~"tmp/thread-status"); + +if ((status == "computing") or (status == "placing")) # the array is blocked + { + settimer( func {remove_tile_loop(index); },0); # try again next frame + return; + } +else if (status == "idle") # we initialize the loop + { + mvec = props.globals.getNode("models", 1).getChildren("model"); + msize = size(mvec); + setprop(lw~"tmp/last-reading-pos-mod", msize); + setprop(lw~"tmp/thread-status", "removing"); + } + +var lastpos = getprop(lw~"tmp/last-reading-pos-mod"); + +# print("msize: ", msize, "lastpos ", lastpos); + +if (lastpos < (msize-1)) {var istart = lastpos;} else {var istart = (msize-1);} + +if (istart<0) {istart=0;} + +var i_min = istart - n; +if (i_min < -1) {i_min =-1;} + +for (var i = istart; i > i_min; i = i- 1) + { + m = mvec[i]; + if (m.getNode("legend",1).getValue() == "Cloud") + { + if (m.getNode("tile-index").getValue() == index) + { + m.remove(); + } + } + } + +if (i<0) {flag_mod = 1;} + + +if (flag_mod == 0) {setprop(lw~"tmp/last-reading-pos-mod",i); } + +if (flag_mod == 0) # we still have work to do + {settimer( func {remove_tile_loop(index); },0);} +else + { + print("Tile deletion loop finished!"); + setprop(lw~"tmp/thread-status", "idle"); + setprop(lw~"clouds/placement-index",0); + setprop(lw~"clouds/model-placement-index",0); + } + +} + +# this is to avoid two tile removal loops starting at the same time + +var waiting_loop = func (index) { + +var status = getprop(lw~"tmp/thread-status"); + +if (status == "idle") {remove_tile_loop(index);} + +else { + print("Removal of ",index, " waiting for idle thread..."); + settimer( func {waiting_loop(index); },1.0); + } +} + +var remove_tile = func (index) { + +var n = size(props.globals.getNode("local-weather/clouds").getChild("tile",index,1).getChildren("cloud")); +props.globals.getNode("local-weather/clouds", 1).removeChild("tile",index); +setprop(lw~"clouds/cloud-number",getprop(lw~"clouds/cloud-number")-n); + +if (getprop(lw~"tmp/thread-flag") == 1) + #{remove_tile_loop(index);} + #{waiting_loop(index);} + # call the model removal in the next frame, because its initialization takes time + # and we do a lot in this frame + {settimer( func {waiting_loop(index); },0);} +else + { + var modelNode = props.globals.getNode("models", 1).getChildren("model"); + foreach (var m; modelNode) + { + if (m.getNode("legend").getValue() == "Cloud") + { + if (m.getNode("tile-index").getValue() == index) + { + m.remove(); + } + } + } + } + + +var effectNode = props.globals.getNode("local-weather/effect-volumes").getChildren("effect-volume"); + +foreach (var e; effectNode) + { + if (e.getNode("tile-index").getValue() == index) + { + e.remove(); + setprop(lw~"effect-volumes/number",getprop(lw~"effect-volumes/number")-1); + } + } + +# set placement indices to zero to reinitiate search for free positions + +setprop(lw~"clouds/placement-index",0); +setprop(lw~"clouds/model-placement-index",0); +setprop(lw~"effect-volumes/effect-placement-index",0); + +} + + + +################################### +# active tile change and neighbour +# recomputation +################################### + +var change_active_tile = func (index) { + +var t = props.globals.getNode(lw~"tiles").getChild("tile",index,0); + +var lat = t.getNode("latitude-deg").getValue(); +var lon = t.getNode("longitude-deg").getValue(); +var alpha = getprop(lw~"tmp/tile-orientation-deg"); + +if (index == 0) + { + copy_entry(4,8); + copy_entry(3,7); + copy_entry(1,5); + copy_entry(0,4); + create_neighbour(lat,lon,0,alpha); + create_neighbour(lat,lon,1,alpha); + create_neighbour(lat,lon,2,alpha); + create_neighbour(lat,lon,3,alpha); + create_neighbour(lat,lon,6,alpha); + } +else if (index == 1) + { + copy_entry(3,6); + copy_entry(4,7); + copy_entry(5,8); + copy_entry(0,3); + copy_entry(1,4); + copy_entry(2,5); + create_neighbour(lat,lon,0,alpha); + create_neighbour(lat,lon,1,alpha); + create_neighbour(lat,lon,2,alpha); + } +else if (index == 2) + { + copy_entry(4,6); + copy_entry(1,3); + copy_entry(2,4); + copy_entry(5,7); + create_neighbour(lat,lon,0,alpha); + create_neighbour(lat,lon,1,alpha); + create_neighbour(lat,lon,2,alpha); + create_neighbour(lat,lon,5,alpha); + create_neighbour(lat,lon,8,alpha); + } +else if (index == 3) + { + copy_entry(1,2); + copy_entry(4,5); + copy_entry(7,8); + copy_entry(0,1); + copy_entry(3,4); + copy_entry(6,7); + create_neighbour(lat,lon,0,alpha); + create_neighbour(lat,lon,3,alpha); + create_neighbour(lat,lon,6,alpha); + } +else if (index == 5) + { + copy_entry(1,0); + copy_entry(4,3); + copy_entry(7,6); + copy_entry(2,1); + copy_entry(5,4); + copy_entry(8,7); + create_neighbour(lat,lon,2,alpha); + create_neighbour(lat,lon,5,alpha); + create_neighbour(lat,lon,8,alpha); + } +else if (index == 6) + { + copy_entry(4,2); + copy_entry(3,1); + copy_entry(6,4); + copy_entry(7,5); + create_neighbour(lat,lon,0,alpha); + create_neighbour(lat,lon,3,alpha); + create_neighbour(lat,lon,6,alpha); + create_neighbour(lat,lon,7,alpha); + create_neighbour(lat,lon,8,alpha); + } +else if (index == 7) + { + copy_entry(3,0); + copy_entry(4,1); + copy_entry(5,2); + copy_entry(6,3); + copy_entry(7,4); + copy_entry(8,5); + create_neighbour(lat,lon,6,alpha); + create_neighbour(lat,lon,7,alpha); + create_neighbour(lat,lon,8,alpha); + } +else if (index == 8) + { + copy_entry(4,0); + copy_entry(7,3); + copy_entry(8,4); + copy_entry(5,1); + create_neighbour(lat,lon,2,alpha); + create_neighbour(lat,lon,5,alpha); + create_neighbour(lat,lon,6,alpha); + create_neighbour(lat,lon,7,alpha); + create_neighbour(lat,lon,8,alpha); + } + +} + +##################################### +# copy tile info in neighbour matrix +##################################### + +var copy_entry = func (from_index, to_index) { + +var tNode = props.globals.getNode(lw~"tiles"); + +var f = tNode.getChild("tile",from_index,0); +var t = tNode.getChild("tile",to_index,0); + +t.getNode("latitude-deg").setValue(f.getNode("latitude-deg").getValue()); +t.getNode("longitude-deg").setValue(f.getNode("longitude-deg").getValue()); +t.getNode("generated-flag").setValue(f.getNode("generated-flag").getValue()); +t.getNode("tile-index").setValue(f.getNode("tile-index").getValue()); +} + +##################################### +# create adjacent tile coordinates +##################################### + +var create_neighbour = func (blat, blon, index, alpha) { + +var x = 0.0; +var y = 0.0; +var phi = alpha * math.pi/180.0; + +calc_geo(blat); + +if ((index == 0) or (index == 3) or (index == 6)) {x =-40000.0;} +if ((index == 2) or (index == 5) or (index == 8)) {x = 40000.0;} + +if ((index == 0) or (index == 1) or (index == 2)) {y = 40000.0;} +if ((index == 6) or (index == 7) or (index == 8)) {y = -40000.0;} + +var t = props.globals.getNode(lw~"tiles").getChild("tile",index,0); + +t.getNode("latitude-deg",1).setValue(blat + get_lat(x,y,phi)); +t.getNode("longitude-deg",1).setValue(blon + get_lon(x,y,phi)); +t.getNode("generated-flag",1).setValue(0); +t.getNode("tile-index",1).setValue(-1); +} + +##################################### +# find the 8 adjacent tile coordinates +# after the initial setup call +##################################### + +var create_neighbours = func (blat, blon, alpha) { + +var x = 0.0; +var y = 0.0; +var phi = alpha * math.pi/180.0; + +calc_geo(blat); + +x = -40000.0; y = 40000.0; +setprop(lw~"tiles/tile[0]/latitude-deg",blat + get_lat(x,y,phi)); +setprop(lw~"tiles/tile[0]/longitude-deg",blon + get_lon(x,y,phi)); +setprop(lw~"tiles/tile[0]/generated-flag",0); +setprop(lw~"tiles/tile[0]/tile-index",-1); + +x = 0.0; y = 40000.0; +setprop(lw~"tiles/tile[1]/latitude-deg",blat + get_lat(x,y,phi)); +setprop(lw~"tiles/tile[1]/longitude-deg",blon + get_lon(x,y,phi)); +setprop(lw~"tiles/tile[1]/generated-flag",0); +setprop(lw~"tiles/tile[1]/tile-index",-1); + +x = 40000.0; y = 40000.0; +setprop(lw~"tiles/tile[2]/latitude-deg",blat + get_lat(x,y,phi)); +setprop(lw~"tiles/tile[2]/longitude-deg",blon + get_lon(x,y,phi)); +setprop(lw~"tiles/tile[2]/generated-flag",0); +setprop(lw~"tiles/tile[2]/tile-index",-1); + +x = -40000.0; y = 0.0; +setprop(lw~"tiles/tile[3]/latitude-deg",blat + get_lat(x,y,phi)); +setprop(lw~"tiles/tile[3]/longitude-deg",blon + get_lon(x,y,phi)); +setprop(lw~"tiles/tile[3]/generated-flag",0); +setprop(lw~"tiles/tile[3]/tile-index",-1); + +# this is the current tile +x = 0.0; y = 0.0; +setprop(lw~"tiles/tile[4]/latitude-deg",blat + get_lat(x,y,phi)); +setprop(lw~"tiles/tile[4]/longitude-deg",blon + get_lon(x,y,phi)); +setprop(lw~"tiles/tile[4]/generated-flag",1); +setprop(lw~"tiles/tile[4]/tile-index",1); + +x = 40000.0; y = 0.0; +setprop(lw~"tiles/tile[5]/latitude-deg",blat + get_lat(x,y,phi)); +setprop(lw~"tiles/tile[5]/longitude-deg",blon + get_lon(x,y,phi)); +setprop(lw~"tiles/tile[5]/generated-flag",0); +setprop(lw~"tiles/tile[5]/tile-index",-1); + +x = -40000.0; y = -40000.0; +setprop(lw~"tiles/tile[6]/latitude-deg",blat + get_lat(x,y,phi)); +setprop(lw~"tiles/tile[6]/longitude-deg",blon + get_lon(x,y,phi)); +setprop(lw~"tiles/tile[6]/generated-flag",0); +setprop(lw~"tiles/tile[6]/tile-index",-1); + +x = 0.0; y = -40000.0; +setprop(lw~"tiles/tile[7]/latitude-deg",blat + get_lat(x,y,phi)); +setprop(lw~"tiles/tile[7]/longitude-deg",blon + get_lon(x,y,phi)); +setprop(lw~"tiles/tile[7]/generated-flag",0); +setprop(lw~"tiles/tile[7]/tile-index",-1); + +x = 40000.0; y = -40000.0; +setprop(lw~"tiles/tile[8]/latitude-deg",blat + get_lat(x,y,phi)); +setprop(lw~"tiles/tile[8]/longitude-deg",blon + get_lon(x,y,phi)); +setprop(lw~"tiles/tile[8]/generated-flag",0); +setprop(lw~"tiles/tile[8]/tile-index",-1); +} + +################### +# global variables +################### + +# these already exist in different namespace, but for ease of typing we define them here as well + +var lat_to_m = 110952.0; # latitude degrees to meters +var m_to_lat = 9.01290648208234e-06; # meters to latitude degrees +var ft_to_m = 0.30480; +var m_to_ft = 1.0/ft_to_m; +var inhg_to_hp = 33.76389; +var hp_to_inhg = 1.0/inhg_to_hp; +var lon_to_m = 0.0; #local_weather.lon_to_m; +var m_to_lon = 0.0; # local_weather.m_to_lon; +var lw = "/local-weather/"; + +# storage array for model vector + +var mvec = []; +var msize = 0; + +################### +# helper functions +################### + +var calc_geo = func(clat) { + +lon_to_m = math.cos(clat*math.pi/180.0) * lat_to_m; +m_to_lon = 1.0/lon_to_m; +} + +var get_lat = func (x,y,phi) { + +return (y * math.cos(phi) - x * math.sin(phi)) * m_to_lat; +} + +var get_lon = func (x,y,phi) { + +return (x * math.cos(phi) + y * math.sin(phi)) * m_to_lon; +} diff --git a/Nasal/weather_tiles.nas b/Nasal/weather_tiles.nas index 19de571c8..28911b3f0 100644 --- a/Nasal/weather_tiles.nas +++ b/Nasal/weather_tiles.nas @@ -2,11 +2,30 @@ # tile setup calls #################################### +var tile_start = func { + +if (getprop(lw~"tmp/thread-flag") == 1){setprop(lw~"tmp/thread-status","computing");} + +} + +var tile_finished = func { + +setprop(lw~"clouds/placement-index",0); + +if (getprop(lw~"tmp/thread-flag") == 1){setprop(lw~"tmp/thread-status","placing");} +} + + + + + #################################### -# Altocumulus sky +# test tile #################################### -var set_altocumulus_tile = func { +var set_4_8_stratus_tile = func { + +tile_start(); var x = 0.0; var y = 0.0; @@ -19,8 +38,558 @@ var alt_offset = getprop(lw~"tmp/tile-alt-offset-ft"); # get tile center coordinates -var blat = getprop("position/latitude-deg"); -var blon = getprop("position/longitude-deg"); +var blat = getprop(lw~"tiles/tmp/latitude-deg"); +var blon = getprop(lw~"tiles/tmp/longitude-deg"); +calc_geo(blat); + +# first weather info for tile center (lat, lon, visibility, temperature, dew point, pressure) + +local_weather.set_weather_station(blat, blon, 35000.0, 14.0, 12.0, 29.78); + +create_4_8_cirrostratus_patches(blat, blon, 25000, alpha); +# create_stratocumulus_bank(blat, blon, 3000+alt_offset, alpha); +# create_4_8_stratus_patches(blat, blon, 3000+alt_offset, alpha); +tile_finished(); + +} + + +#################################### +# high pressure core +#################################### + +var set_high_pressure_core_tile = func { + +tile_start(); + +setprop(lw~"tiles/code","high_pressure_core"); + +var x = 0.0; +var y = 0.0; +var lat = 0.0; +var lon = 0.0; + +var alpha = getprop(lw~"tmp/tile-orientation-deg"); +var phi = alpha * math.pi/180.0; +var alt_offset = getprop(lw~"tmp/tile-alt-offset-ft"); + +# get tile center coordinates + +var blat = getprop(lw~"tiles/tmp/latitude-deg"); +var blon = getprop(lw~"tiles/tmp/longitude-deg"); +calc_geo(blat); + +# get probabilistic values for the weather parameters + +var vis = 35000.0 + rand() * 20000.0; +var T = 20.0 + rand() * 10.0; +var spread = 5.0 + 3.0 * rand(); +var D = T - spread; +var p = 1033.0 + rand() * 10.0; + +# and set them at the tile center +local_weather.set_weather_station(blat, blon, vis, T, D, p * hp_to_inhg); + +# weak cumulus development + +var alt = spread * 1000; +var strength = rand() * 0.05; + +local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0); + + +tile_finished(); + +} + + +#################################### +# high pressure +#################################### + +var set_high_pressure_tile = func { + +tile_start(); + +setprop(lw~"tiles/code","high_pressure"); + +var x = 0.0; +var y = 0.0; +var lat = 0.0; +var lon = 0.0; + +var alpha = getprop(lw~"tmp/tile-orientation-deg"); +var phi = alpha * math.pi/180.0; +var alt_offset = getprop(lw~"tmp/tile-alt-offset-ft"); + +# get tile center coordinates + +var blat = getprop(lw~"tiles/tmp/latitude-deg"); +var blon = getprop(lw~"tiles/tmp/longitude-deg"); +calc_geo(blat); + +# get probabilistic values for the weather parameters + +var vis = 25000.0 + rand() * 15000.0; +var T = 15.0 + rand() * 10.0; +var spread = 4.0 + 2.0 * rand(); +var D = T - spread; +var p = 1023.0 + rand() * 10.0; + +# and set them at the tile center +local_weather.set_weather_station(blat, blon, vis, T, D, p * hp_to_inhg); + +# moderate cumulus development + +var alt = spread * 1000; + + + +var rn = rand(); + +if (rn > 0.5) + { + # cloud scenario 1: possible Cirrus over Cumulus + var strength = 0.2 + rand() * 0.4; + local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0); + + # if cumulus are weak, increase likelihood of Cirrus (the logic is the other way round + # but this makes no difference and is easier to implement) + + # try to place two spatially separated Cirrus clouds + + if (rand() > 2.0 * strength) + { + x = 2000.0 + rand() * 16000.0; + y = 2.0 * (rand()-0.5) * 18000; + alt = 25000.0 + rand() * 5000.0; + var path = local_weather.select_cloud_model("Cirrus", "small"); + local_weather.create_cloud("Cirrus", path, blat + get_lat(x,y,phi), blon+get_lon(x,y,phi), alt + alt_offset,alpha, 0); + } + + if (rand() > 2.0 * strength) + { + x = -2000.0 - rand() * 16000.0; + y = 2.0 * (rand()-0.5) * 18000; + alt = 25000.0 + rand() * 5000.0; + var path = local_weather.select_cloud_model("Cirrus", "small"); + local_weather.create_cloud("Cirrus", path, blat + get_lat(x,y,phi), blon+get_lon(x,y,phi), alt + alt_offset,alpha, 0); + } + } +else if (rn > 0.0) + { + # cloud scenario 2: Cirrostratus over weak Cumulus + + var strength = 0.2 + rand() * 0.2; + local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0); + + create_2_8_cirrostratus(blat, blon, alt+alt_offset+25000.0, alpha); + } + +tile_finished(); + +} + + +#################################### +# high pressure border +#################################### + +var set_high_pressure_border_tile = func { + +tile_start(); + +setprop(lw~"tiles/code","high_pressure_border"); + +var x = 0.0; +var y = 0.0; +var lat = 0.0; +var lon = 0.0; + +var alpha = getprop(lw~"tmp/tile-orientation-deg"); +var phi = alpha * math.pi/180.0; +var alt_offset = getprop(lw~"tmp/tile-alt-offset-ft"); + +# get tile center coordinates + +var blat = getprop(lw~"tiles/tmp/latitude-deg"); +var blon = getprop(lw~"tiles/tmp/longitude-deg"); +calc_geo(blat); + +# get probabilistic values for the weather parameters + +var vis = 20000.0 + rand() * 12000.0; +var T = 12.0 + rand() * 10.0; +var spread = 3.0 + 2.0 * rand(); +var D = T - spread; +var p = 1013.0 + rand() * 10.0; + +# and set them at the tile center +local_weather.set_weather_station(blat, blon, vis, T, D, p * hp_to_inhg); + + +# now a random selection of different possible cloud configuration scenarios + +var alt = spread * 1000; + +var rn = rand(); + + +if (rn > 0.833) + { + # cloud scenario 1: Altocumulus patch over weak Cumulus + var strength = 0.1 + rand() * 0.1; + local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0); + + x = 2.0 * (rand()-0.5) * 5000; + y = 2.0 * (rand()-0.5) * 5000; + local_weather.create_streak("Altocumulus",blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 12000.0+alt+alt_offset,30,1000.0,0.2, 30,1000.0,0.2,alpha ,1.0); + local_weather.randomize_pos("Altocumulus",1500.0,800.0,800.0,alpha); + } +else if (rn > 0.666) + { + # cloud scenario 2: Altocumulus streaks + var strength = 0.15 + rand() * 0.2; + local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0); + + x = 2.0 * (rand()-0.5) * 10000; + y = 2.0 * (rand()-0.5) * 10000; + local_weather.create_streak("Altocumulus",blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 12000.0+alt+alt_offset,25,700.0,0.2, 10,700.0,0.2,alpha ,1.4); + x = 2.0 * (rand()-0.5) * 10000; + y = 2.0 * (rand()-0.5) * 10000; + local_weather.create_streak("Altocumulus",blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 12000.0+alt+alt_offset,22,750.0,0.2, 8,750.0,0.2,alpha ,1.1); + local_weather.randomize_pos("Altocumulus",1500.0,800.0,800.0,alpha); + } +else if (rn > 0.5) + { + # cloud scenario 3: Cirrus + + var strength = 0.1 + rand() * 0.1; + local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0); + + x = 2.0 * (rand()-0.5) * 3000; + y = 2.0 * (rand()-0.5) * 3000; + local_weather.create_streak("Cirrus",blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 22000.0+alt+alt_offset,3,9000.0,0.0, 1,8000.0,0.0,alpha ,1.0); + local_weather.randomize_pos("Cirrus",1500.0,800.0,800.0,alpha); + } +else if (rn > 0.333) + { + # cloud scenario 4: Cumulonimbus banks + + var strength = 0.7 + rand() * 0.3; + local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0); + + for (var i = 0; i < 3; i = i + 1) + { + x = 2.0 * (rand()-0.5) * 16000; + y = 2.0 * (rand()-0.5) * 16000; + + create_cloud_bank("Cumulonimbus", blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), alt+alt_offset, 1600.0, 800.0, 3000.0, 9, alpha); + } + } +else if (rn > 0.166) + { + # cloud scenario 5: scattered Stratus + + var strength = 0.4 + rand() * 0.2; + local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0); + + var size_offset = 0.5 * m_to_ft * local_weather.cloud_vertical_size_map["Stratus_structured"]; + + local_weather.create_streak("Stratus (structured)",blat, blon, alt+6000.0+alt_offset+size_offset,18,0.0,0.3,18,0.0,0.3,0.0,1.0); + local_weather.randomize_pos("Stratus (structured)",1000.0,20000.0,20000.0,0.0); + } +else if (rn > 0.0) + { + # cloud scenario 6: Cirrocumulus + + var strength = 0.2 + rand() * 0.2; + local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0); + + x = 2.0 * (rand()-0.5) * 5000; + y = 2.0 * (rand()-0.5) * 5000; + + + var path = local_weather.select_cloud_model("Cirrocumulus", "large"); + local_weather.create_cloud("Cirrocumulus", path, blat + get_lat(x,y,phi), blon+get_lon(x,y,phi), alt + alt_offset +22000,alpha, 0); + + } + + + +tile_finished(); + +} + +#################################### +# low pressure border +#################################### + +var set_low_pressure_border_tile = func { + +tile_start(); + +setprop(lw~"tiles/code","low_pressure_border"); + +var x = 0.0; +var y = 0.0; +var lat = 0.0; +var lon = 0.0; + +var alpha = getprop(lw~"tmp/tile-orientation-deg"); +var phi = alpha * math.pi/180.0; +var alt_offset = getprop(lw~"tmp/tile-alt-offset-ft"); + +# get tile center coordinates + +var blat = getprop(lw~"tiles/tmp/latitude-deg"); +var blon = getprop(lw~"tiles/tmp/longitude-deg"); +calc_geo(blat); + +# get probabilistic values for the weather parameters + +var vis = 15000.0 + rand() * 10000.0; +var T = 10.0 + rand() * 10.0; +var spread = 2.0 + 2.0 * rand(); +var D = T - spread; +var p = 1003.0 + rand() * 10.0; + +# and set them at the tile center +local_weather.set_weather_station(blat, blon, vis, T, D, p * hp_to_inhg); + +# altitude for the lowest layer +alt = spread * 1000.0; + +# now a random selection of different possible cloud configuration scenarios + +var rn = rand(); + +if (rn > 0.75) + { + # cloud scenario 1: a low 4/8 stratus patches, thin patches above + + alt = alt + local_weather.cloud_vertical_size_map["Stratus"] * 0.5 * m_to_ft; + create_4_8_stratus_patches(blat, blon, alt+alt_offset,alpha); + create_4_8_tstratus_patches(blat, blon, alt+alt_offset+6000,alpha); + } +else if (rn > 0.5) + { + # cloud scenario 2: a low 4/8 undulatus, thin patches above + + alt = alt + local_weather.cloud_vertical_size_map["Stratus"] * 0.5 * m_to_ft; + create_4_8_sstratus_undulatus(blat, blon, alt+alt_offset,alpha); + create_2_8_tstratus(blat, blon, alt+alt_offset+7000,alpha); + } +else if (rn > 0.25) + { + # cloud scenario 3: low Stratocumulus + + alt = alt + local_weather.cloud_vertical_size_map["Stratus"] * 0.5 * m_to_ft; + create_stratocumulus_bank(blat, blon, alt+alt_offset,alpha); + create_2_8_sstratus(blat, blon, alt+alt_offset+3000,alpha); + create_2_8_tstratus(blat, blon, alt+alt_offset+9000,alpha); + } +else if (rn > 0.0) + { + # cloud scenario 4: dense low Stratocumulus + + alt = alt + local_weather.cloud_vertical_size_map["Stratus"] * 0.5 * m_to_ft; + create_stratocumulus_bank(blat, blon, alt+alt_offset,alpha); + create_stratocumulus_bank(blat, blon, alt+alt_offset,alpha); + create_2_8_sstratus(blat, blon, alt+alt_offset+8000,alpha); + } + + +tile_finished(); + +} + +#################################### +# low pressure +#################################### + +var set_low_pressure_tile = func { + +tile_start(); + +setprop(lw~"tiles/code","low_pressure"); + +var x = 0.0; +var y = 0.0; +var lat = 0.0; +var lon = 0.0; + +var alpha = getprop(lw~"tmp/tile-orientation-deg"); +var phi = alpha * math.pi/180.0; +var alt_offset = getprop(lw~"tmp/tile-alt-offset-ft"); + +# get tile center coordinates + +var blat = getprop(lw~"tiles/tmp/latitude-deg"); +var blon = getprop(lw~"tiles/tmp/longitude-deg"); +calc_geo(blat); + +# get probabilistic values for the weather parameters + +var vis = 10000.0 + rand() * 10000.0; +var T = 5.0 + rand() * 10.0; +var spread = 1.0 + 2.0 * rand(); +var D = T - spread; +var p = 993.0 + rand() * 10.0; + +# and set them at the tile center +local_weather.set_weather_station(blat, blon, vis, T, D, p * hp_to_inhg); + +# altitude for the lowest layer +alt = spread * 1000.0; + +var rn = rand(); + + +if (rn > 0.75) + { + + # cloud scenario 1: two patches of Nimbostratus with precipitation + # overhead broken stratus layers + # cloud count 1050 + + x = 2.0 * (rand()-0.5) * 11000.0; + y = 2.0 * (rand()-0.5) * 11000.0; + var beta = rand() * 360.0; + + local_weather.create_layer("Nimbus", blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), alt+alt_offset, 500.0, 12000.0, 7000.0, beta, 1.0, 0.2, 1, 1.0); + local_weather.create_effect_volume(2, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 10000.0, 6000.0, beta, 0.0, alt + alt_offset, 5000.0, 0.3, -1, -1, -1,0 ); + local_weather.create_effect_volume(2, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 9000.0, 5000.0, beta, 0.0, alt+alt_offset-300.0, 1500.0, 0.5, -1, -1, -1,0 ); + + x = 2.0 * (rand()-0.5) * 11000.0; + y = 2.0 * (rand()-0.5) * 11000.0; + var beta = rand() * 360.0; + + local_weather.create_layer("Nimbus", blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), alt+alt_offset, 500.0, 10000.0, 6000.0, beta, 1.0, 0.2, 1, 1.0); + local_weather.create_effect_volume(2, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 9000.0, 5000.0, beta, 0.0, alt + alt_offset, 5000.0, 0.3, -1, -1, -1,0 ); + local_weather.create_effect_volume(2, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 8000.0, 4000.0, beta, 0.0, alt+alt_offset-300.0, 1500.0, 0.5, -1, -1, -1,0 ); + + create_4_8_sstratus_undulatus(blat, blon, alt+alt_offset +3000.0, alpha); + create_2_8_tstratus(blat, blon, alt+alt_offset +6000.0, alpha); + } +else if (rn >0.5) + { + # cloud scenario 2: 8/8 Stratus with light precipitation + # above broken cover + # cloud count 1180 + + alt = alt + local_weather.cloud_vertical_size_map["Stratus"] * 0.5 * m_to_ft; + create_8_8_stratus(blat, blon, alt+alt_offset,alpha); + local_weather.create_effect_volume(3, blat, blon, 18000.0, 18000.0, 0.0, 0.0, 1800.0, 8000.0, -1, -1, -1, -1, 0); + local_weather.create_effect_volume(3, blat, blon, 14000.0, 14000.0, 0.0, 0.0, 1500.0, 6000.0, 0.1, -1, -1, -1,0 ); + create_2_8_sstratus(blat, blon, alt+alt_offset+3000,alpha); + } +else if (rn >0.25) + { + # cloud scenario 3: multiple broken layers + # cloud count 1350 + + alt = alt + local_weather.cloud_vertical_size_map["Stratus"] * 0.5 * m_to_ft; + create_4_8_stratus(blat, blon, alt+alt_offset,alpha); + create_4_8_stratus_patches(blat, blon, alt+alt_offset+3000,alpha); + create_4_8_sstratus_undulatus(blat, blon, alt+alt_offset+6000,alpha); + create_2_8_tstratus(blat, blon, alt+alt_offset+8000,alpha); + } +else if (rn >0.0) + { + # cloud scenario 4: a low 6/8 layer and some clouds above + # cloud count 650 + + alt = alt + local_weather.cloud_vertical_size_map["Stratus"] * 0.5 * m_to_ft; + create_6_8_stratus(blat, blon, alt+alt_offset,alpha); + create_2_8_sstratus(blat, blon, alt+alt_offset+6000,alpha); + } + +tile_finished(); + +} + + +#################################### +# low pressure core +#################################### + +var set_low_pressure_core_tile = func { + +tile_start(); + +setprop(lw~"tiles/code","low_pressure_core"); + +var x = 0.0; +var y = 0.0; +var lat = 0.0; +var lon = 0.0; + +var alpha = getprop(lw~"tmp/tile-orientation-deg"); +var phi = alpha * math.pi/180.0; +var alt_offset = getprop(lw~"tmp/tile-alt-offset-ft"); + +# get tile center coordinates + +var blat = getprop(lw~"tiles/tmp/latitude-deg"); +var blon = getprop(lw~"tiles/tmp/longitude-deg"); +calc_geo(blat); + +# get probabilistic values for the weather parameters + +var vis = 8000.0 + rand() * 7000.0; +var T = 3.0 + rand() * 7.0; +var spread = 1.0 + 1.0 * rand(); +var D = T - spread; +var p = 983.0 + rand() * 10.0; + +# and set them at the tile center +local_weather.set_weather_station(blat, blon, vis, T, D, p * hp_to_inhg); + + +# set a closed Nimbostratus layer + +alt = spread * 1000.0 + local_weather.cloud_vertical_size_map["Nimbus"] * 0.5 * m_to_ft; + +#print("alt: ",spread*1000); + +create_8_8_nimbus(blat, blon, alt+alt_offset, alpha); + +# and a precipitation layer below, more rain in the center of the tile + +local_weather.create_effect_volume(3, blat, blon, 20000.0, 20000.0, alpha, 0.0, alt + alt_offset, 3000.0, 0.3, -1, -1, -1,0 ); +local_weather.create_effect_volume(3, blat , blon, 16000.0, 16000.0, alpha, 0.0, alt + alt_offset - 300.0, 1500.0, 0.5, -1, -1, -1,0 ); + + +# and some broken Stratus cover above + +var rn = rand(); + +if (rn > 0.5){create_4_8_stratus_patches(blat, blon, alt+alt_offset+3000.0, alpha);} +else {create_4_8_stratus(blat, blon, alt+alt_offset+3000.0, alpha);} + + +tile_finished(); + +} + +#################################### +# Altocumulus sky +# cloud count 1400/tile +#################################### + +var set_altocumulus_tile = func { + +tile_start(); + +var alpha = getprop(lw~"tmp/tile-orientation-deg"); +var phi = alpha * math.pi/180.0; +var alt_offset = getprop(lw~"tmp/tile-alt-offset-ft"); + +# get tile center coordinates + +var blat = getprop(lw~"tiles/tmp/latitude-deg"); +var blon = getprop(lw~"tiles/tmp/longitude-deg"); calc_geo(blat); # first weather info for tile center (lat, lon, visibility, temperature, dew point, pressure) @@ -29,22 +598,26 @@ local_weather.set_weather_station(blat, blon, 35000.0, 22.0, 14.0, 30.02); # then draw the Altocumulus streaks, dense at 15.000 ft, sparse at 17.000 ft -local_weather.create_streak("Altocumulus",blat, blon, 15000.0+alt_offset,40,900.0,0.2, 40,900.0,0.2,0.0 ,1.0); -local_weather.create_streak("Altocumulus",blat, blon, 17000.0+alt_offset,18,1900.0,0.35,18,1900.0,0.35,0.0,1.0); -local_weather.randomize_pos("Altocumulus",1000.0,600.0,600.0,0.0); +local_weather.create_streak("Altocumulus",blat, blon, 15000.0+alt_offset,40,1000.0,0.2, 40,1000.0,0.2,alpha ,1.0); +local_weather.create_streak("Altocumulus",blat, blon, 17000.0+alt_offset,18,2000.0,0.35,18,2000.0,0.35,alpha,1.0); +local_weather.randomize_pos("Altocumulus",1500.0,800.0,800.0,alpha); -# start the interpolation loop +tile_finished(); -if (getprop(lw~"interpolation-loop-flag") == 0) -{setprop(lw~"interpolation-loop-flag",1); local_weather.interpolation_loop();} } + + + #################################### # Overcast stratus sky +# cloud count 1000/tile #################################### var set_overcast_stratus_tile = func { +tile_start(); + var x = 0.0; var y = 0.0; var lat = 0.0; @@ -56,8 +629,8 @@ var alt_offset = getprop(lw~"tmp/tile-alt-offset-ft"); # get tile center coordinates -var blat = getprop("position/latitude-deg"); -var blon = getprop("position/longitude-deg"); +var blat = getprop(lw~"tiles/tmp/latitude-deg"); +var blon = getprop(lw~"tiles/tmp/longitude-deg"); calc_geo(blat); # first weather info for tile center (lat, lon, visibility, temperature, dew point, pressure) @@ -67,12 +640,12 @@ local_weather.set_weather_station(blat, blon, 10000.0, 14.0, 12.0, 29.78); # then draw the Stratus layers var size_offset = 0.5 * m_to_ft * local_weather.cloud_vertical_size_map["Stratus"]; -local_weather.create_streak("Stratus",blat, blon, 1500.0+alt_offset+size_offset,30,1200.0,0.2, 30,1200.0,0.2,0.0 ,1.0); +local_weather.create_streak("Stratus",blat, blon, 1500.0+alt_offset+size_offset,32,1250.0,0.2, 32,1250.0,0.2,0.0 ,1.0); local_weather.randomize_pos("Stratus",0.0,600.0,600.0,0.0); size_offset = 0.5 * m_to_ft * local_weather.cloud_vertical_size_map["Stratus_structured"]; -local_weather.create_streak("Stratus (structured)",blat, blon, 5000.0+alt_offset+size_offset,18,2500.0,0.3,18,2500.0,0.3,0.0,1.0); -local_weather.randomize_pos("Stratus (structured)",0.0,600.0,600.0,0.0); +local_weather.create_streak("Stratus (structured)",blat, blon, 5000.0+alt_offset+size_offset,16,2500.0,0.3,16,2500.0,0.3,0.0,1.0); +local_weather.randomize_pos("Stratus (structured)",0.0,1200.0,1200.0,0.0); # reduce visibility even more below lowest layer @@ -81,25 +654,21 @@ local_weather.randomize_pos("Stratus (structured)",0.0,600.0,600.0,0.0); local_weather.create_effect_volume(3, blat, blon, 18000.0, 18000.0, 0.0, 0.0, 1800.0, 8000.0, -1, -1, -1, -1, 0); local_weather.create_effect_volume(3, blat, blon, 14000.0, 14000.0, 0.0, 0.0, 1500.0, 6000.0, 0.1, -1, -1, -1,0 ); -# start the interpolation loop -if (getprop(lw~"interpolation-loop-flag") == 0) -{setprop(lw~"interpolation-loop-flag",1); local_weather.interpolation_loop();} - -# start the effect volume loop - -if (getprop(lw~"effect-loop-flag") == 0) -{setprop(lw~"effect-loop-flag",1); local_weather.effect_volume_loop();} +tile_finished(); } #################################### # Incoming rainfront +# cloud count 1500/tile #################################### var set_rainfront_tile = func { +tile_start(); + var x = 0.0; var y = 0.0; var lat = 0.0; @@ -111,8 +680,8 @@ var alt_offset = getprop(lw~"tmp/tile-alt-offset-ft"); # get tile center coordinates -var blat = getprop("position/latitude-deg"); -var blon = getprop("position/longitude-deg"); +var blat = getprop(lw~"tiles/tmp/latitude-deg"); +var blon = getprop(lw~"tiles/tmp/longitude-deg"); calc_geo(blat); # first weather info for tile center (lat, lon, visibility, temperature, dew point, pressure) @@ -151,29 +720,22 @@ local_weather.create_effect_volume(2, blat+get_lat(x,y,phi), blon+get_lon(x,y,ph local_weather.create_effect_volume(3, blat, blon, 20000.0, 20000.0, 0.0, 2100.0, 85000.0, 18000.0, -1, -1, -1, -1,0 ); -# start the interpolation loop +tile_finished(); -if (getprop(lw~"interpolation-loop-flag") == 0) -{setprop(lw~"interpolation-loop-flag",1); local_weather.interpolation_loop();} -# start the effect volume loop - -if (getprop(lw~"effect-loop-flag") == 0) -{setprop(lw~"effect-loop-flag",1); local_weather.effect_volume_loop();} } #################################### # Broken layers +# cloud count 550/tile #################################### var set_broken_layers_tile = func { -var x = 0.0; -var y = 0.0; -var lat = 0.0; -var lon = 0.0; +tile_start(); + var alpha = getprop(lw~"tmp/tile-orientation-deg"); var phi = alpha * math.pi/180.0; @@ -181,8 +743,8 @@ var alt_offset = getprop(lw~"tmp/tile-alt-offset-ft"); # get tile center coordinates -var blat = getprop("position/latitude-deg"); -var blon = getprop("position/longitude-deg"); +var blat = getprop(lw~"tiles/tmp/latitude-deg"); +var blon = getprop(lw~"tiles/tmp/longitude-deg"); calc_geo(blat); # first weather info for tile center (lat, lon, visibility, temperature, dew point, pressure) @@ -201,19 +763,21 @@ local_weather.randomize_pos("Stratus (structured)",1000.0,20000.0,20000.0,0.0); local_weather.create_streak("Stratus (structured)",blat, blon, 7000.0+alt_offset+size_offset,11,0.0,0.5,11,0.0,0.5,0.0,1.0); local_weather.randomize_pos("Stratus (structured)",1000.0,20000.0,20000.0,0.0); -# start the interpolation loop +tile_finished(); + -if (getprop(lw~"interpolation-loop-flag") == 0) -{setprop(lw~"interpolation-loop-flag",1); local_weather.interpolation_loop();} } #################################### # Fair weather and Cumulus +# cloud count max. 800/tile #################################### var set_fair_weather_tile = func { +tile_start(); + var x = 0.0; var y = 0.0; var lat = 0.0; @@ -225,8 +789,9 @@ var alt_offset = getprop(lw~"tmp/tile-alt-offset-ft"); # get tile center coordinates -var blat = getprop("position/latitude-deg"); -var blon = getprop("position/longitude-deg"); + +var blat = getprop(lw~"tiles/tmp/latitude-deg"); +var blon = getprop(lw~"tiles/tmp/longitude-deg"); calc_geo(blat); # first weather info for tile center (lat, lon, visibility, temperature, dew point, pressure) @@ -235,15 +800,13 @@ local_weather.set_weather_station(blat, blon, 35000.0, 20.0, 16.0, 1018 * hp_to_ # add convective clouds -var strength = 1; + +var strength = 1.0; var n = int(4000 * strength); # calculate the number of placement tries from tile size 20x20km and strength -local_weather.create_cumosys(blat,blon, 3000.0+alt_offset,n, 20000.0); +local_weather.create_cumosys(blat,blon, 3000.0 + alt_offset, n, 20000.0); +tile_finished(); -# start the interpolation loop - -if (getprop(lw~"interpolation-loop-flag") == 0) -{setprop(lw~"interpolation-loop-flag",1); local_weather.interpolation_loop();} } @@ -254,6 +817,8 @@ if (getprop(lw~"interpolation-loop-flag") == 0) var set_gliders_sky_tile = func { +tile_start(); + var x = 0.0; var y = 0.0; var lat = 0.0; @@ -265,15 +830,15 @@ var alt_offset = getprop(lw~"tmp/tile-alt-offset-ft"); # get tile center coordinates -var blat = getprop("position/latitude-deg"); -var blon = getprop("position/longitude-deg"); +var blat = getprop(lw~"tiles/tmp/latitude-deg"); +var blon = getprop(lw~"tiles/tmp/longitude-deg"); calc_geo(blat); # first weather info for tile center (lat, lon, visibility, temperature, dew point, pressure) local_weather.set_weather_station(blat, blon, 35000.0, 20.0, 16.0, 1018 * hp_to_inhg); -# switch the placement of thermal effect volumes on -setprop(lw~"tmp/generate-thermal-lift-flag",1); +# switch the placement of thermal effect volumes on: 1: constant lift 2: by function +setprop(lw~"tmp/generate-thermal-lift-flag",2); # add convective clouds @@ -283,29 +848,18 @@ var n = int(4000 * strength); # calculate the number of placement tries from til local_weather.create_cumosys(blat,blon, 3000.0+alt_offset,n, 20000.0); -# start the interpolation loop - -if (getprop(lw~"interpolation-loop-flag") == 0) -{setprop(lw~"interpolation-loop-flag",1); local_weather.interpolation_loop();} - -# start the effect volume loop - -if (getprop(lw~"effect-loop-flag") == 0) -{setprop(lw~"effect-loop-flag",1); local_weather.effect_volume_loop();} - - +tile_finished(); } - - - #################################### -# Summer rain +# Blue thermals #################################### -var set_summer_rain_tile = func { +var set_blue_thermals_tile = func { + +tile_start(); var x = 0.0; var y = 0.0; @@ -318,8 +872,52 @@ var alt_offset = getprop(lw~"tmp/tile-alt-offset-ft"); # get tile center coordinates -var blat = getprop("position/latitude-deg"); -var blon = getprop("position/longitude-deg"); +var blat = getprop(lw~"tiles/tmp/latitude-deg"); +var blon = getprop(lw~"tiles/tmp/longitude-deg"); +calc_geo(blat); + +# first weather info for tile center (lat, lon, visibility, temperature, dew point, pressure) +local_weather.set_weather_station(blat, blon, 45000.0, 20.0, 15.0, 1018 * hp_to_inhg); + +# switch the placement of thermal effect volumes on: 1: constant lift 2: by function 3: blue +setprop(lw~"tmp/generate-thermal-lift-flag",3); + + +# add convective clouds + +var strength = 0.9; +var n = int(4000 * strength); # calculate the number of placement tries from tile size 20x20km and strength +local_weather.create_cumosys(blat,blon, 5000.0+alt_offset,n, 20000.0); + + +tile_finished(); + + +} + + +#################################### +# Summer rain +# cloud count max. 1200/tile +#################################### + +var set_summer_rain_tile = func { + +tile_start(); + +var x = 0.0; +var y = 0.0; +var lat = 0.0; +var lon = 0.0; + +var alpha = getprop(lw~"tmp/tile-orientation-deg"); +var phi = alpha * math.pi/180.0; +var alt_offset = getprop(lw~"tmp/tile-alt-offset-ft"); + +# get tile center coordinates + +var blat = getprop(lw~"tiles/tmp/latitude-deg"); +var blon = getprop(lw~"tiles/tmp/longitude-deg"); calc_geo(blat); # first weather info for tile center (lat, lon, visibility, temperature, dew point, pressure) @@ -336,15 +934,7 @@ var strength = 1.5; var n = int(4000 * strength); # calculate the number of placement tries from tile size 20x20km and strength local_weather.create_cumosys(blat,blon, 3000.0+alt_offset,n, 20000.0); -# start the interpolation loop - -if (getprop(lw~"interpolation-loop-flag") == 0) -{setprop(lw~"interpolation-loop-flag",1); local_weather.interpolation_loop();} - -# start the effect volume loop - -if (getprop(lw~"effect-loop-flag") == 0) -{setprop(lw~"effect-loop-flag",1); local_weather.effect_volume_loop();} +tile_finished(); } @@ -375,6 +965,8 @@ local_weather.randomize_pos("Cumulonimbus",1000.0,1000.0,1000.0,30.0); var set_cirrus_sky_tile = func { +tile_start(); + var x = 0.0; var y = 0.0; var lat = 0.0; @@ -386,8 +978,8 @@ var alt_offset = getprop(lw~"tmp/tile-alt-offset-ft"); # get tile center coordinates -var blat = getprop("position/latitude-deg"); -var blon = getprop("position/longitude-deg"); +var blat = getprop(lw~"tiles/tmp/latitude-deg"); +var blon = getprop(lw~"tiles/tmp/longitude-deg"); calc_geo(blat); # first weather info for tile center (lat, lon, visibility, temperature, dew point, pressure) @@ -435,10 +1027,244 @@ var strength = 0.4; var n = int(4000 * strength); # calculate the number of placement tries from tile size 20x20km and strength local_weather.create_cumosys(blat,blon, 4000.0+alt_offset,n, 20000.0); -# start the interpolation loop +tile_finished(); +} + + +#################################### +# mid-level cloud setup calls +#################################### + +var create_8_8_stratus = func (lat, lon, alt, alpha) { + +local_weather.create_streak("Stratus",lat, lon, alt,32,1250.0,0.0,32,1250.0,0.0,alpha,1.0); +local_weather.randomize_pos("Stratus",500.0,400.0,400.0,alpha); +} + + +var create_8_8_nimbus = func (lat, lon, alt, alpha) { + +local_weather.create_streak("Nimbus",lat, lon, alt,32,1250.0,0.0,32,1250.0,0.0,alpha,1.0); +local_weather.randomize_pos("Nimbus",500.0,200.0,200.0,alpha); +} + + +var create_6_8_stratus = func (lat, lon, alt, alpha) { + +local_weather.create_streak("Stratus",lat, lon, alt,20,0.0,0.2,20,0.0,0.2,alpha,1.0); +local_weather.randomize_pos("Stratus",500.0,20000.0,20000.0,alpha); +} + + +var create_4_8_stratus = func (lat, lon, alt, alpha) { + +var phi = alpha * math.pi/180.0; +var x = 2.0 * (rand()-0.5) * 15000; +var y = 2.0 * (rand()-0.5) * 15000; +var beta = rand() * 360.0; + +local_weather.create_streak("Stratus",lat+get_lat(x,y,phi), lon+get_lon(x,y,phi), alt,20,1200.0,0.3,12,1200.0,0.3,beta,1.2); +local_weather.randomize_pos("Stratus",500.0,400.0,400.0,beta); + +var x = 2.0 * (rand()-0.5) * 15000; +var y = 2.0 * (rand()-0.5) * 15000; +var beta = rand() * 360.0; + +local_weather.create_streak("Stratus",lat+get_lat(x,y,phi), lon+get_lon(x,y,phi), alt,18,1000.0,0.3,10,1000.0,0.3,beta,1.5); +local_weather.randomize_pos("Stratus",500.0,400.0,400.0,beta); + +var x = 2.0 * (rand()-0.5) * 15000; +var y = 2.0 * (rand()-0.5) * 15000; +var beta = rand() * 360.0; + +local_weather.create_streak("Stratus",lat+get_lat(x,y,phi), lon+get_lon(x,y,phi), alt,15,1000.0,0.3,18,1000.0,0.3,beta,2.0); +local_weather.randomize_pos("Stratus",500.0,400.0,400.0,beta); +} + +var create_4_8_stratus_patches = func (lat, lon, alt, alpha) { + +var phi = alpha * math.pi/180.0; + +for (var i=0; i<16; i=i+1) + { + var x = 2.0 * (rand()-0.5) * 18000; + var y = 2.0 * (rand()-0.5) * 18000; + var beta = (rand() -0.5) * 180.0; + local_weather.create_streak("Stratus",lat+get_lat(x,y,phi), lon+get_lon(x,y,phi), alt,4,950.0,0.2,6,950.0,0.2,alpha+beta,1.0); +local_weather.randomize_pos("Stratus",300.0,500.0,500.0,alpha+beta); + } + +} + +var create_4_8_tstratus_patches = func (lat, lon, alt, alpha) { + +var phi = alpha * math.pi/180.0; + +for (var i=0; i<16; i=i+1) + { + var x = 2.0 * (rand()-0.5) * 18000; + var y = 2.0 * (rand()-0.5) * 18000; + var beta = (rand() -0.5) * 180.0; + local_weather.create_streak("Stratus (thin)",lat+get_lat(x,y,phi), lon+get_lon(x,y,phi), alt,4,950.0,0.2,6,950.0,0.2,alpha+beta,1.0); +local_weather.randomize_pos("Stratus (thin)",300.0,500.0,500.0,alpha+beta); + } + +} + + +var create_4_8_sstratus_patches = func (lat, lon, alt, alpha) { + +var phi = alpha * math.pi/180.0; + +for (var i=0; i<16; i=i+1) + { + var x = 2.0 * (rand()-0.5) * 18000; + var y = 2.0 * (rand()-0.5) * 18000; + var beta = (rand() -0.5) * 180.0; + local_weather.create_streak("Stratus (structured)",lat+get_lat(x,y,phi), lon+get_lon(x,y,phi), alt,4,950.0,0.2,6,950.0,0.2,alpha+beta,1.0); +local_weather.randomize_pos("Stratus (structured)",300.0,500.0,500.0,alpha+beta); + } + +} + + +var create_4_8_cirrostratus_patches = func (lat, lon, alt, alpha) { + +var phi = alpha * math.pi/180.0; + +for (var i=0; i<6; i=i+1) + { + var x = 2.0 * (rand()-0.5) * 12000; + var y = 2.0 * (rand()-0.5) * 12000; + var beta = (rand() -0.5) * 180.0; + local_weather.create_streak("Cirrostratus",lat+get_lat(x,y,phi), lon+get_lon(x,y,phi), alt,4,2500.0,0.2,4,2500.0,0.2,alpha+beta,1.0); +local_weather.randomize_pos("Cirrostratus",300.0,600.0,600.0,alpha+beta); + } + +} + + +var create_4_8_stratus_undulatus = func (lat, lon, alt, alpha) { + +var phi = alpha * math.pi/180.0; +var x = 2.0 * (rand()-0.5) * 5000; +var y = 2.0 * (rand()-0.5) * 5000; +var tri = 1.5 + 1.5*rand(); +var beta = (rand() -0.5) * 60.0; + +local_weather.create_streak("Stratus",lat+get_lat(x,y+4000,phi), lon+get_lon(x,y+4000,phi), alt,10,800.0,0.25,12,2800.0,0.15,alpha+90.0+beta,tri); +local_weather.randomize_pos("Stratus",500.0,400.0,600.0,alpha+90.0+beta); +local_weather.create_streak("Stratus",lat+get_lat(x,y-4000,phi), lon+get_lon(x,y-4000,phi), alt,10,800.0,0.25,12,2800.0,0.15,alpha+270.0+beta,tri); +local_weather.randomize_pos("Stratus",500.0,400.0,600.0,alpha+270.0+beta); +} + +var create_4_8_tstratus_undulatus = func (lat, lon, alt, alpha) { + +var phi = alpha * math.pi/180.0; +var x = 2.0 * (rand()-0.5) * 5000; +var y = 2.0 * (rand()-0.5) * 5000; +var tri = 1.5 + 1.5*rand(); +var beta = (rand() -0.5) * 60.0; + +local_weather.create_streak("Stratus (thin)",lat+get_lat(x,y+4000,phi), lon+get_lon(x,y+4000,phi), alt,10,800.0,0.25,12,2800.0,0.15,alpha+90.0+beta,tri); +local_weather.randomize_pos("Stratus (thin)",500.0,400.0,600.0,alpha+90.0+beta); +local_weather.create_streak("Stratus (thin)",lat+get_lat(x,y-4000,phi), lon+get_lon(x,y-4000,phi), alt,10,800.0,0.25,12,2800.0,0.15,alpha+270.0+beta,tri); +local_weather.randomize_pos("Stratus (thin)",500.0,400.0,600.0,alpha+270.0+beta); +} + +var create_4_8_sstratus_undulatus = func (lat, lon, alt, alpha) { + +var phi = alpha * math.pi/180.0; +var x = 2.0 * (rand()-0.5) * 5000; +var y = 2.0 * (rand()-0.5) * 5000; +var tri = 1 + 1.5*rand(); +var beta = (rand() -0.5) * 60.0; + +local_weather.create_streak("Stratus (structured)",lat+get_lat(x,y,phi), lon+get_lon(x,y,phi), alt,20,900.0,0.25,12,2800.0,0.15,alpha+90.0+beta,tri); +local_weather.randomize_pos("Stratus (structured)",500.0,400.0,600.0,alpha+90.0+beta); +} + + +var create_2_8_stratus = func (lat, lon, alt, alpha) { + +var phi = alpha * math.pi/180.0; + +for (var i=0; i<8; i=i+1) + { + var x = 2.0 * (rand()-0.5) * 18000; + var y = 2.0 * (rand()-0.5) * 18000; + var beta = (rand() -0.5) * 180.0; + local_weather.create_streak("Stratus",lat+get_lat(x,y,phi), lon+get_lon(x,y,phi), alt,5,900.0,0.2,7,900.0,0.2,alpha+beta,1.0); +local_weather.randomize_pos("Stratus",300.0,500.0,500.0,alpha+beta); + } + +} + +var create_2_8_tstratus = func (lat, lon, alt, alpha) { + +var phi = alpha * math.pi/180.0; + +for (var i=0; i<8; i=i+1) + { + var x = 2.0 * (rand()-0.5) * 18000; + var y = 2.0 * (rand()-0.5) * 18000; + var beta = (rand() -0.5) * 180.0; + local_weather.create_streak("Stratus (thin)",lat+get_lat(x,y,phi), lon+get_lon(x,y,phi), alt,5,900.0,0.2,7,900.0,0.2,alpha+beta,1.0); +local_weather.randomize_pos("Stratus (thin)",300.0,500.0,500.0,alpha+beta); + } + +} + +var create_2_8_sstratus = func (lat, lon, alt, alpha) { + +var phi = alpha * math.pi/180.0; + +for (var i=0; i<8; i=i+1) + { + var x = 2.0 * (rand()-0.5) * 18000; + var y = 2.0 * (rand()-0.5) * 18000; + var beta = (rand() -0.5) * 180.0; + local_weather.create_streak("Stratus (structured)",lat+get_lat(x,y,phi), lon+get_lon(x,y,phi), alt,5,900.0,0.2,7,900.0,0.2,alpha+beta,1.0); +local_weather.randomize_pos("Stratus (structured)",300.0,500.0,500.0,alpha+beta); + } + +} + +var create_2_8_cirrostratus = func (lat, lon, alt, alpha) { + +var phi = alpha * math.pi/180.0; + +for (var i=0; i<3; i=i+1) + { + var x = 2.0 * (rand()-0.5) * 12000; + var y = 2.0 * (rand()-0.5) * 12000; + var beta = (rand() -0.5) * 180.0; + local_weather.create_streak("Cirrostratus",lat+get_lat(x,y,phi), lon+get_lon(x,y,phi), alt,4,2300.0,0.2,4,2300.0,0.2,alpha+beta,1.0); +local_weather.randomize_pos("Cirrostratus",300.0,600.0,600.0,alpha+beta); + } + +} + + +var create_stratocumulus_bank = func (lat, lon, alt, alpha) { + +var phi = alpha * math.pi/180.0; +var x = 2.0 * (rand()-0.5) * 10000; +var y = 2.0 * (rand()-0.5) * 10000; +var tri = 1.5 + 1.5*rand(); +var beta = (rand() -0.5) * 60.0; + +local_weather.create_streak("Cumulus",lat+get_lat(x,y+4000,phi), lon+get_lon(x,y+4000,phi), alt,15,400.0,0.2,20,400.0,0.2,alpha+90.0+beta,tri); +local_weather.randomize_pos("Cumulus",500.0,400.0,400.0,alpha+90.0+beta); +local_weather.create_streak("Cumulus",lat+get_lat(x,y-4000,phi), lon+get_lon(x,y-4000,phi), alt,15,400.0,0.2,20,400.0,0.2,alpha+270.0+beta,tri); +local_weather.randomize_pos("Cumulus",500.0,400.0,400.0,alpha+270.0+beta); +} + +var create_cloud_bank = func (type, lat, lon, alt, x1, x2, height, n, alpha) { + +local_weather.create_streak(type,lat,lon, alt+ 0.5* height,n,0.0,0.0,1,0.0,0.0,alpha,1.0); +local_weather.randomize_pos(type,height,x1,x2,alpha); -if (getprop(lw~"interpolation-loop-flag") == 0) -{setprop(lw~"interpolation-loop-flag",1); local_weather.interpolation_loop();} } ################### @@ -462,6 +1288,11 @@ return (x * math.cos(phi) + y * math.sin(phi)) * m_to_lon; } +var get_n = func(strength) { + +return int(4000 * strength); +} + ################### # global variables ################### diff --git a/Shaders/clouds-layered.vert b/Shaders/clouds-layered.vert index 8fe33a9cd..8846f0ee5 100644 --- a/Shaders/clouds-layered.vert +++ b/Shaders/clouds-layered.vert @@ -3,8 +3,8 @@ varying float fogFactor; -float shade = 0.2; -float cloud_height = 3000.0; +float shade = 0.4; +float cloud_height = 1000.0; void main(void) { @@ -23,13 +23,15 @@ void main(void) // Do the matrix multiplication by [ u r w pos]. Assume no // scaling in the homogeneous component of pos. gl_Position = vec4(0.0, 0.0, 0.0, 1.0); - gl_Position.xyz = gl_Vertex.x * u; + gl_Position.xyz = gl_Vertex.x * u ; gl_Position.xyz += gl_Vertex.y * r * 1.0; - gl_Position.xyz += gl_Vertex.z * w * 0.4; + gl_Position.xyz += gl_Vertex.z * w * 1.0;//0.4; //gl_Position.xyz += gl_Vertex.y * r * wScale; //gl_Position.xyz += gl_Vertex.z * w * hScale; gl_Position.xyz += gl_Color.xyz; + gl_Position.z = gl_Position.z * 0.4; + // Determine a lighting normal based on the vertex position from the // center of the cloud, so that sprite on the opposite side of the cloud to the sun are darker. float n = dot(normalize(-gl_LightSource[0].position.xyz), @@ -56,6 +58,6 @@ void main(void) gl_BackColor = gl_FrontColor; // Fog doesn't affect clouds as much as other objects. - fogFactor = exp( -gl_Fog.density * fogCoord * 0.2); + fogFactor = exp( -gl_Fog.density * fogCoord * 0.5); fogFactor = clamp(fogFactor, 0.0, 1.0); } diff --git a/Shaders/clouds-thick.vert b/Shaders/clouds-thick.vert index f8024c3d0..996208295 100644 --- a/Shaders/clouds-thick.vert +++ b/Shaders/clouds-thick.vert @@ -3,7 +3,7 @@ varying float fogFactor; -float shade = 0.5; +float shade = 0.6; float cloud_height = 1000.0; void main(void) diff --git a/Shaders/clouds-thinlayer.frag b/Shaders/clouds-thinlayer.frag new file mode 100644 index 000000000..4222fbfc8 --- /dev/null +++ b/Shaders/clouds-thinlayer.frag @@ -0,0 +1,11 @@ +uniform sampler2D baseTexture; +varying float fogFactor; + +void main(void) +{ + vec4 base = texture2D( baseTexture, gl_TexCoord[0].st); + vec4 finalColor = base * gl_Color; + gl_FragColor.rgb = mix(gl_Fog.color.rgb, finalColor.rgb, fogFactor ); + gl_FragColor.a = mix(0.0, finalColor.a, fogFactor); +} + diff --git a/Shaders/clouds-thinlayer.vert b/Shaders/clouds-thinlayer.vert new file mode 100644 index 000000000..4f500a151 --- /dev/null +++ b/Shaders/clouds-thinlayer.vert @@ -0,0 +1,63 @@ +// -*-C++-*- +#version 120 + +varying float fogFactor; + +float shade = 0.7; +float cloud_height = 1000.0; + +void main(void) +{ + + gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; + vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0); + vec4 l = gl_ModelViewMatrixInverse * vec4(0.0,0.0,1.0,1.0); + vec3 u = normalize(ep.xyz - l.xyz); + + // Find a rotation matrix that rotates 1,0,0 into u. u, r and w are + // the columns of that matrix. + vec3 absu = abs(u); + vec3 r = normalize(vec3(-u.y, u.x, 0)); + vec3 w = cross(u, r); + + // Do the matrix multiplication by [ u r w pos]. Assume no + // scaling in the homogeneous component of pos. + gl_Position = vec4(0.0, 0.0, 0.0, 1.0); + gl_Position.xyz = gl_Vertex.x * u ; + gl_Position.xyz += gl_Vertex.y * r * 1.0; + gl_Position.xyz += gl_Vertex.z * w * 1.0;//0.4; + //gl_Position.xyz += gl_Vertex.y * r * wScale; + //gl_Position.xyz += gl_Vertex.z * w * hScale; + gl_Position.xyz += gl_Color.xyz; + + gl_Position.z = gl_Position.z * 0.2; + + // Determine a lighting normal based on the vertex position from the + // center of the cloud, so that sprite on the opposite side of the cloud to the sun are darker. + float n = dot(normalize(-gl_LightSource[0].position.xyz), + normalize(mat3x3(gl_ModelViewMatrix) * (- gl_Position.xyz)));; + + // Determine the position - used for fog and shading calculations + vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Position); + float fogCoord = abs(ecPosition.z); + float fract = smoothstep(0.0, cloud_height, gl_Position.z + cloud_height); + + // Final position of the sprite + gl_Position = gl_ModelViewProjectionMatrix * gl_Position; + +// Determine the shading of the sprite based on its vertical position and position relative to the sun. + n = min(smoothstep(-0.5, 0.0, n), fract); +// Determine the shading based on a mixture from the backlight to the front + vec4 backlight = gl_LightSource[0].diffuse * shade; + + gl_FrontColor = mix(backlight, gl_LightSource[0].diffuse, n); + gl_FrontColor += gl_FrontLightModelProduct.sceneColor; + + // As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out. + gl_FrontColor.a = min(smoothstep(100.0, 300.0, fogCoord), 1 - smoothstep(25000.0, 30000.0, fogCoord)); + gl_BackColor = gl_FrontColor; + + // Fog doesn't affect clouds as much as other objects. + fogFactor = exp( -gl_Fog.density * fogCoord * 0.2); + fogFactor = clamp(fogFactor, 0.0, 1.0); +} diff --git a/Shaders/test.frag b/Shaders/test.frag new file mode 100644 index 000000000..4222fbfc8 --- /dev/null +++ b/Shaders/test.frag @@ -0,0 +1,11 @@ +uniform sampler2D baseTexture; +varying float fogFactor; + +void main(void) +{ + vec4 base = texture2D( baseTexture, gl_TexCoord[0].st); + vec4 finalColor = base * gl_Color; + gl_FragColor.rgb = mix(gl_Fog.color.rgb, finalColor.rgb, fogFactor ); + gl_FragColor.a = mix(0.0, finalColor.a, fogFactor); +} + diff --git a/Shaders/test.vert b/Shaders/test.vert new file mode 100644 index 000000000..e991cb9d1 --- /dev/null +++ b/Shaders/test.vert @@ -0,0 +1,91 @@ +// -*-C++-*- +#version 120 + +varying float fogFactor; + +//attribute vec3 usrAttr3; +//attribute vec3 usrAttr4; + +//float textureIndexX = usrAttr3.r; +//float textureIndexY = usrAttr3.g; +//float wScale = usrAttr3.b; +//float hScale = usrAttr4.r; +//float shade = usrAttr4.g; +//float cloud_height = usrAttr4.b; + +//float shade = usrAttr3.r; +//float cloud_height = usrAttr3.g; +//float scale = usrAttr3.b; + +float shading; + +float shade = 0.3; +float cloud_height = 1000.0; +float scale = 0.5; + +void main(void) +{ + //shade = 0.1 * shade; + //scale = 0.1 * scale; + + gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; + vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0); + vec4 l = gl_ModelViewMatrixInverse * vec4(0.0,0.0,1.0,1.0); + vec3 view = normalize(ep.xyz - l.xyz); + + vec4 posh = gl_ModelViewMatrixInverse * normalize(vec4(gl_Vertex.x,gl_Vertex.y,gl_Vertex.z,1.0)); + vec3 pos = normalize(ep.xyz - posh.xyz); + + mat4 sprime = mat4(1.0,0.0,0.0,0.0,0.0,0.5,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0); + mat4 scale = gl_ModelViewMatrix * sprime * gl_ModelViewMatrixInverse; + + float dist = sqrt(gl_Vertex.x * gl_Vertex.x + gl_Vertex.y * gl_Vertex.y + gl_Vertex.z * gl_Vertex.z); + //vec3 u = normalize(smoothstep(500.0, 1500.0, dist) * pos + (1.0 - smoothstep(500.0, 1500.0, dist)) * view); + //vec3 u = normalize(mix(pos, view, smoothstep(500.0,1500.0,dist))); + vec3 u = view; + + // Find a rotation matrix that rotates 1,0,0 into u. u, r and w are + // the columns of that matrix. + vec3 absu = abs(u); + vec3 r = normalize(vec3(-u.y, u.x, 0)); + vec3 w = cross(u, r); + + // Do the matrix multiplication by [ u r w pos]. Assume no + // scaling in the homogeneous component of pos. + gl_Position = vec4(0.0, 0.0, 0.0, 1.0); + gl_Position.xyz = gl_Vertex.x * u; + gl_Position.xyz += gl_Vertex.y * r * 1.0; + gl_Position.xyz += gl_Vertex.z * w * scale; + //gl_Position.xyz += gl_Vertex.y * r * wScale; + //gl_Position.xyz += gl_Vertex.z * w * hScale; + gl_Position.xyz += gl_Color.xyz; + + // Determine a lighting normal based on the vertex position from the + // center of the cloud, so that sprite on the opposite side of the cloud to the sun are darker. + float n = dot(normalize(-gl_LightSource[0].position.xyz), + normalize(mat3x3(gl_ModelViewMatrix) * (- gl_Position.xyz)));; + + // Determine the position - used for fog and shading calculations + vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Position); + float fogCoord = abs(ecPosition.z); + float fract = smoothstep(0.0, cloud_height, gl_Position.z + cloud_height); + + // Final position of the sprite + gl_Position = gl_ModelViewProjectionMatrix * gl_Position; + +// Determine the shading of the sprite based on its vertical position and position relative to the sun. + n = min(smoothstep(-0.5, 0.0, n), fract); +// Determine the shading based on a mixture from the backlight to the front + vec4 backlight = gl_LightSource[0].diffuse * shade; + + gl_FrontColor = mix(backlight, gl_LightSource[0].diffuse, n); + gl_FrontColor += gl_FrontLightModelProduct.sceneColor; + + // As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out. + gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1 - smoothstep(15000.0, 20000.0, fogCoord)); + gl_BackColor = gl_FrontColor; + + // Fog doesn't affect clouds as much as other objects. + fogFactor = exp( -gl_Fog.density * fogCoord * 0.2); + fogFactor = clamp(fogFactor, 0.0, 1.0); +} diff --git a/Sounds/GE-M134.wav b/Sounds/GE-M134.wav deleted file mode 100644 index e50a76a67..000000000 Binary files a/Sounds/GE-M134.wav and /dev/null differ diff --git a/Sounds/HOT.wav b/Sounds/HOT.wav deleted file mode 100644 index 0e8b262fb..000000000 Binary files a/Sounds/HOT.wav and /dev/null differ diff --git a/Sounds/TC1.wav b/Sounds/TC1.wav deleted file mode 100644 index b9872b906..000000000 Binary files a/Sounds/TC1.wav and /dev/null differ diff --git a/Sounds/ec_rotor_in.wav b/Sounds/ec_rotor_in.wav deleted file mode 100644 index aa11da320..000000000 Binary files a/Sounds/ec_rotor_in.wav and /dev/null differ diff --git a/Sounds/ec_rotor_out2.wav b/Sounds/ec_rotor_out2.wav deleted file mode 100644 index 2784d4b1c..000000000 Binary files a/Sounds/ec_rotor_out2.wav and /dev/null differ diff --git a/Sounds/fenestron_ec135.wav b/Sounds/fenestron_ec135.wav deleted file mode 100644 index 2e4dd5e07..000000000 Binary files a/Sounds/fenestron_ec135.wav and /dev/null differ diff --git a/Sounds/flight_ec135_out.wav b/Sounds/flight_ec135_out.wav deleted file mode 100644 index 291a5aada..000000000 Binary files a/Sounds/flight_ec135_out.wav and /dev/null differ diff --git a/Sounds/idle_ec135_out.wav b/Sounds/idle_ec135_out.wav deleted file mode 100644 index b5e72dc73..000000000 Binary files a/Sounds/idle_ec135_out.wav and /dev/null differ diff --git a/Sounds/strt_ec135_out2.wav b/Sounds/strt_ec135_out2.wav deleted file mode 100644 index 44dc683ef..000000000 Binary files a/Sounds/strt_ec135_out2.wav and /dev/null differ diff --git a/Sounds/warn2600.wav b/Sounds/warn2600.wav deleted file mode 100644 index 8f4776c03..000000000 Binary files a/Sounds/warn2600.wav and /dev/null differ diff --git a/Sounds/warn650.wav b/Sounds/warn650.wav deleted file mode 100644 index 3a7ec4218..000000000 Binary files a/Sounds/warn650.wav and /dev/null differ diff --git a/gui/dialogs/local_weather.xml b/gui/dialogs/local_weather.xml index a61f53eb4..40cc093f6 100644 --- a/gui/dialogs/local_weather.xml +++ b/gui/dialogs/local_weather.xml @@ -74,9 +74,12 @@ Cirrus Cumulus Cumulonimbus + Fog (thin) + Fog (thick) Nimbus Stratus Stratus (structured) + Stratus (thin) dialog-apply @@ -236,11 +239,15 @@ Altocumulus Cirrus Cumulus + Cumulus (cloudlet) Cumulonimbus Cumulonimbus (rain) + Fog (thin) + Fog (thick) Nimbus Stratus Stratus (structured) + Stratus (thin) dialog-apply @@ -647,10 +654,14 @@ Altocumulus Cirrus Cumulus + Cumulus (cloudlet) Cumulonimbus + Fog (thin) + Fog (thick) Nimbus Stratus Stratus (structured) + Stratus (thin) dialog-apply diff --git a/gui/dialogs/local_weather_tiles.xml b/gui/dialogs/local_weather_tiles.xml index 4c7ea9bfd..e1d072ca7 100644 --- a/gui/dialogs/local_weather_tiles.xml +++ b/gui/dialogs/local_weather_tiles.xml @@ -24,14 +24,23 @@ 25 true /local-weather/tmp/tile-type - Altocumulus sky - Broken layers - Cirrus sky - Fair weather + High-pressure-core + High-pressure + High-pressure-border + Low-pressure-border + Low-pressure + Low-pressure-core + --- + + + + Glider's sky - Incoming rainfront - Overcast stratus sky - Summer rain + Blue thermals + + + + dialog-apply @@ -44,27 +53,96 @@ - 120 + 115 170 - 50 + 40 25 /local-weather/tmp/tile-orientation-deg - 170 + 155 170 - 250 + 240 170 - 40 + 50 25 /local-weather/tmp/tile-alt-offset-ft + + 10 + 130 + + + + + 150 + 130 + 140 + 25 + true + /local-weather/tmp/tile-management + single tile + repeat tile + realistic weather + + dialog-apply + + + + + 10 + 90 + 15 + 15 + + /local-weather/tmp/presampling-flag + + dialog-apply + + + + + 150 + 90 + 15 + 15 + + /local-weather/tmp/thread-flag + + dialog-apply + + + + + 10 + 60 + 15 + 15 + + /local-weather/tmp/asymmetric-tile-loading-flag + + dialog-apply + + + + + 150 + 60 + 15 + 15 + + /local-weather/config/detailed-clouds-flag + + dialog-apply + + + 10 10 diff --git a/gui/menubar.xml.alt b/gui/menubar.xml.alt new file mode 100644 index 000000000..cf844318d --- /dev/null +++ b/gui/menubar.xml.alt @@ -0,0 +1,654 @@ + + +

+ + + + + + nasal + + + + + + + + nasal + + + + + + + + reset + + + + + + false + + hires-screen-capture + + + + + + + nasal + + + + + + + + old-print-dialog + + + + + + + dialog-show + sound-dialog + + + + + + + nasal + + + + + + + + dialog-show + logging + + + + + + + dialog-show + exit + + + + + + + + + + + dialog-show + display + + + + + + + dialog-show + rendering + + + + + + + dialog-show + view + + + + + + + dialog-show + cockpit-view + + + + + + + dialog-show + pilot_offset + + + + + + + dialog-show + hud + + + + + + + dialog-show + replay + + + + + + + dialog-show + static-lod + + + + + + + + + + + dialog-show + location-on-ground + + + + + + + dialog-show + location-in-air + + + + + + + dialog-show + airports + + + + + + + property-assign + /sim/presets/trim + false + + + property-randomize + /orientation/pitch-deg + 0 + 360 + + + property-randomize + /orientation/roll-deg + 0 + 360 + + + property-randomize + /orientation/heading-deg + 0 + 360 + + + + + + + dialog-show + location-of-tower + + + + + + + + autopilot + + + + + dialog-show + autopilot + + + + + + + dialog-show + route-manager + + + + + + + nasal + + + + + + + + nasal + + + + + + + + nasal + + + + + + + + + + + + dialog-show + weather_scenario + + + + + + + dialog-show + weather + + + + + + + dialog-show + clouds + + + + + + + dialog-show + timeofday + + + + + + + dialog-show + rainsnow + + + + + + + nasal + + + + + + + dialog-show + local_weather + + + + + + dialog-show + local_weather_tiles + + + + + + + + + + fuel-and-payload + + nasal + + + + + + + + dialog-show + radios + + + + + + + dialog-show + gps + + + + + + + dialog-show + instruments + + + + + + + dialog-show + stopwatch-dialog + + + + + + + dialog-show + random-failures + + + + + + + dialog-show + system-failures + + + + + + + dialog-show + instrument-failures + + + + + + + + + + + ATC-freq-search + + + + + + + dialog-show + atc-ai + + + + + + tanker + false + + dialog-show + tanker + + + + + + + multiplayer + + + + + dialog-show + chat-full + + + + + + + dialog-show + chat-menu + + + + + + + nasal + + + + + + + + nasal + + + + + + + + + + + + reinit + gui + + + + + + + reinit + input + + + + + + + panel-load + + + + + + + reinit + xml-autopilot + + + + + + + reinit + io + + + + + + + dialog-show + nasal-console + + + + + + + nasal + + + + + + + + dialog-show + devel-extensions + + + + + + + nasal + + + + + + + + dump-scenegraph + + + + + + + property-assign + /sim/rendering/print-statistics + true + + + + + + + property-adjust + /sim/rendering/on-screen-statistics + 1 + + + + + + + + + + + old-help-dialog + + + + + + joystick-info + + dialog-show + joystick-info + + + + + + + nasal + + + + + + + + nasal + + + + + + + + nasal + + + + + + + + nasal + + + + + + + tutorial-start + + dialog-show + tutorial + + + + + + tutorial-stop + false + + nasal + + + + + +