+ unsigned layerOffset = 0; // Oh, this is ugly!
+
+ // fog/mist/haze cloud layer does not work with 3d clouds yet :-(
+ bool setGroundCloudLayer = _rootNode->getBoolValue("set-ground-cloud-layer", false ) &&
+ false == (fgGetBool("/sim/rendering/shader-effects", false ) &&
+ fgGetBool("/sim/rendering/clouds3d-enable", false ) );
+
+ if( setGroundCloudLayer ) {
+ // create a cloud layer #0 starting at the ground if its fog, mist or haze
+
+ // make sure layer actually starts at ground and set it's bottom at a constant
+ // value below the station's elevation
+ const double LAYER_BOTTOM_STATION_OFFSET =
+ fgGetDouble( "/environment/params/fog-mist-haze-layer/offset-from-station-elevation-ft", -200 );
+
+ SGMetarCloud::Coverage coverage = SGMetarCloud::COVERAGE_NIL;
+ double thickness = 0;
+ double alpha = 1.0;
+
+ if( isFG ) { // fog
+ coverage = SGMetarCloud::getCoverage( isBC ?
+ fgGetString( "/environment/params/fog-mist-haze-layer/fog-bc-2dlayer-coverage", SGMetarCloud::COVERAGE_SCATTERED_STRING ) :
+ fgGetString( "/environment/params/fog-mist-haze-layer/fog-2dlayer-coverage", SGMetarCloud::COVERAGE_BROKEN_STRING )
+ );
+
+ thickness = isMI ?
+ fgGetDouble("/environment/params/fog-mist-haze-layer/fog-shallow-thickness-ft",30) - LAYER_BOTTOM_STATION_OFFSET : // shallow fog, 10m/30ft
+ fgGetDouble("/environment/params/fog-mist-haze-layer/fog-thickness-ft",500) - LAYER_BOTTOM_STATION_OFFSET; // fog, 150m/500ft
+ alpha = fgGetDouble("/environment/params/fog-mist-haze-layer/fog-2dlayer-alpha", 1.0);
+ } else if( isBR ) { // mist
+ coverage = SGMetarCloud::getCoverage(fgGetString("/environment/params/fog-mist-haze-layer/mist-2dlayer-coverage", SGMetarCloud::COVERAGE_OVERCAST_STRING));
+ thickness = fgGetDouble("/environment/params/fog-mist-haze-layer/mist-thickness-ft",2000) - LAYER_BOTTOM_STATION_OFFSET;
+ alpha = fgGetDouble("/environment/params/fog-mist-haze-layer/mist-2dlayer-alpha",0.8);
+ } else if( isHZ ) { // haze
+ coverage = SGMetarCloud::getCoverage(fgGetString("/environment/params/fog-mist-haze-layer/mist-2dlayer-coverage", SGMetarCloud::COVERAGE_OVERCAST_STRING));
+ thickness = fgGetDouble("/environment/params/fog-mist-haze-layer/haze-thickness-ft",2000) - LAYER_BOTTOM_STATION_OFFSET;
+ alpha = fgGetDouble("/environment/params/fog-mist-haze-layer/haze-2dlayer-alpha",0.6);
+ }
+
+ if( coverage != SGMetarCloud::COVERAGE_NIL ) {
+
+ // if there is a layer above the fog, limit the top to one foot below that layer's bottom
+ if( metarClouds.size() > 0 && metarClouds[0].getCoverage() != SGMetarCloud::COVERAGE_CLEAR )
+ thickness = metarClouds[0].getAltitude_ft() - LAYER_BOTTOM_STATION_OFFSET - 1;
+
+ SGPropertyNode_ptr layerNode = cloudsNode->getChild(LAYER, 0, true );
+ layerNode->setDoubleValue( "coverage-type", SGCloudLayer::getCoverageType(coverage_string[coverage]) );
+ layerNode->setStringValue( "coverage", coverage_string[coverage] );
+ layerNode->setDoubleValue( "elevation-ft", _station_elevation + LAYER_BOTTOM_STATION_OFFSET );
+ layerNode->setDoubleValue( "thickness-ft", thickness );
+ layerNode->setDoubleValue( "visibility-m", _min_visibility );
+ layerNode->setDoubleValue( "alpha", alpha );
+ _min_visibility = _max_visibility =
+ fgGetDouble("/environment/params/fog-mist-haze-layer/visibility-above-layer-m",20000.0); // assume good visibility above the fog
+ layerOffset = 1; // shudder
+ }
+ }
+
+ for( unsigned i = 0; i < 5-layerOffset; i++ ) {
+ SGPropertyNode_ptr layerNode = cloudsNode->getChild(LAYER, i+layerOffset, true );
+ SGMetarCloud::Coverage coverage = i < metarClouds.size() ? metarClouds[i].getCoverage() : SGMetarCloud::COVERAGE_CLEAR;
+ double elevation =
+ i >= metarClouds.size() || coverage == SGMetarCloud::COVERAGE_CLEAR ?
+ -9999.0 :
+ metarClouds[i].getAltitude_ft() + _station_elevation;
+
+ layerNode->setDoubleValue( "alpha", 1.0 );