1
0
Fork 0

Support for creating high altitude noctilucent clouds in Advanced Weather/ALS

This commit is contained in:
Thorsten Renk 2014-01-30 11:08:35 +02:00
parent fb48ba3384
commit 1c1bcda8d6
9 changed files with 340 additions and 4 deletions

View file

@ -0,0 +1,156 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/cloud-noctilucent</name>
<parameters>
<texture n ="0">
</texture>
<terminator><use>/environment/terminator-relative-position-m</use></terminator>
<altitude><use>/sim/rendering/eye-altitude-m</use></altitude>
<cloud_self_shading><use>/environment/cloud-self-shading</use></cloud_self_shading>
<moonlight><use>/environment/moonlight</use></moonlight>
</parameters>
<technique n="9">
<predicate>
<and>
<property>/sim/rendering/shaders/skydome</property>
<property>/sim/rendering/clouds3d-enable</property>
<less-equal>
<value type="float">1.0</value>
<shader-language/>
</less-equal>
</and>
</predicate>
<pass n="0">
<!-- This is apparently not used, so maybe we'll blow it way soon. -->
<lighting>true</lighting>
<material>
<ambient type="vec4d">0.5 0.5 0.5 1.0</ambient>
<diffuse type="vec4d">0.5 0.5 0.5 1.0</diffuse>
<color-mode>off</color-mode>
</material>
<alpha-test>
<comparison>greater</comparison>
<reference type="float">0.01</reference>
</alpha-test>
<shade-model>smooth</shade-model>
<blend>
<source>src-alpha</source>
<destination>one-minus-src-alpha</destination>
</blend>
<depth>
<write-mask>false</write-mask>
</depth>
<render-bin>
<bin-number>9</bin-number>
<bin-name>DepthSortedBin</bin-name>
</render-bin>
<texture-unit>
<unit>0</unit>
<type><use>texture[0]/type</use></type>
<image><use>texture[0]/image</use></image>
<filter><use>texture[0]/filter</use></filter>
<wrap-s><use>texture[0]/wrap-s</use></wrap-s>
<wrap-t><use>texture[0]/wrap-t</use></wrap-t>
<!--<wrap-s>clamp</wrap-s>
<wrap-t>clamp</wrap-t>-->
</texture-unit>
<program>
<vertex-shader>Shaders/cloud-noctilucent-lightfield.vert</vertex-shader>
<fragment-shader>Shaders/cloud-static-lightfield.frag</fragment-shader>
</program>
<uniform>
<name>baseTexture</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>terminator</name>
<type>float</type>
<value><use>terminator</use></value>
</uniform>
<uniform>
<name>altitude</name>
<type>float</type>
<value><use>altitude</use></value>
</uniform>
<uniform>
<name>cloud_self_shading</name>
<type>float</type>
<value><use>cloud_self_shading</use></value>
</uniform>
<uniform>
<name>moonlight</name>
<type>float</type>
<value><use>moonlight</use></value>
</uniform>
<vertex-program-two-side>true</vertex-program-two-side>
</pass>
</technique>
<technique n="10">
<predicate>
<and>
<property>/sim/rendering/clouds3d-enable</property>
<less-equal>
<value type="float">1.0</value>
<shader-language/>
</less-equal>
</and>
</predicate>
<pass n="0">
<!-- This is apparently not used, so maybe we'll blow it way soon. -->
<lighting>true</lighting>
<material>
<ambient type="vec4d">0.5 0.5 0.5 1.0</ambient>
<diffuse type="vec4d">0.5 0.5 0.5 1.0</diffuse>
<color-mode>off</color-mode>
</material>
<alpha-test>
<comparison>greater</comparison>
<reference type="float">0.01</reference>
</alpha-test>
<shade-model>smooth</shade-model>
<blend>
<source>src-alpha</source>
<destination>one-minus-src-alpha</destination>
</blend>
<depth>
<write-mask>false</write-mask>
</depth>
<render-bin>
<bin-number>9</bin-number>
<bin-name>DepthSortedBin</bin-name>
</render-bin>
<texture-unit>
<unit>0</unit>
<type><use>texture[0]/type</use></type>
<image><use>texture[0]/image</use></image>
<filter><use>texture[0]/filter</use></filter>
<wrap-s><use>texture[0]/wrap-s</use></wrap-s>
<wrap-t><use>texture[0]/wrap-t</use></wrap-t>
<!--<wrap-s>clamp</wrap-s>
<wrap-t>clamp</wrap-t>-->
</texture-unit>
<program>
<vertex-shader>Shaders/cloud-static.vert</vertex-shader>
<fragment-shader>Shaders/cloud-static.frag</fragment-shader>
</program>
<uniform>
<name>baseTexture</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>terminator</name>
<type>float</type>
<value><use>terminator</use></value>
</uniform>
<uniform>
<name>altitude</name>
<type>float</type>
<value><use>altitude</use></value>
</uniform>
<vertex-program-two-side>true</vertex-program-two-side>
</pass>
</technique>
</PropertyList>

View file

@ -427,6 +427,8 @@
<fog-structure type="double" userarchive="y">0.0</fog-structure>
<cloud-self-shading type="double" userarchive="n">1.0</cloud-self-shading>
<moonlight type="double" userarchive="n">0.0</moonlight>
<!-- config for noctilucent cloud generation -->
<create-noctilucent-clouds type="bool" userarchive="n">false</create-noctilucent-clouds>
<!-- definitions for the environment at surface interface -->
<surface>
<scattering type="double" userarchive="n">0.7</scattering>

View file

@ -530,6 +530,12 @@ else if (type == "Cirrocumulus") {
else {path = "Models/Weather/cirrocumulus10.xml";}
}
}
else if (type=="Noctilucent") {
if (rn>0.75) {path = "Models/Weather/noctilucent7.xml";}
else if (rn > 0.5) {path = "Models/Weather/noctilucent8.xml";}
else if (rn > 0.25) {path = "Models/Weather/noctilucent9.xml";}
else {path = "Models/Weather/noctilucent10.xml";}
}
else if (type == "Cirrocumulus (cloudlet)") {
cloudAssembly = local_weather.cloud.new(type, subtype);

View file

@ -144,7 +144,7 @@ for (i=0; i< max_num_streaks; i=i+1)
}
}
print("Cloud count: ",counter);
#print("Cloud count: ",counter);
}

View file

@ -415,6 +415,9 @@ var tile_counter = getprop(lw~"tiles/tile-counter");
var buffer_flag = getprop(lw~"config/buffer-flag");
var d_max = weather_tile_management.cloud_view_distance + 1000.0;
# noctilucent clouds should not be deleted with the tile, hence they're assigned to tile zero
if (find("noctilucent",path) != -1)
{tile_counter=0;}
# check if we deal with a convective cloud - no need to do this any more, convective clouds go via a different system

View file

@ -4081,7 +4081,12 @@ setlistener(lw~"config/target-framerate", func {target_framerate = getprop(lw~"c
setlistener(lw~"config/small-scale-persistence", func {weather_tiles.small_scale_persistence = getprop(lw~"config/small-scale-persistence");});
setlistener(lw~"config/ground-haze-factor", func {ground_haze_factor = getprop(lw~"config/ground-haze-factor");});
setlistener(lw~"config/aux-max-vis-range-m", func {max_vis_range = math.exp(getprop(lw~"config/aux-max-vis-range-m")); setprop(lw~"config/max-vis-range-m",max_vis_range);});
setlistener(lw~"config/aux-max-vis-range-m", func {
max_vis_range = math.exp(getprop(lw~"config/aux-max-vis-range-m"));
setprop(lw~"config/max-vis-range-m",max_vis_range);
if (max_vis_range>120000.0){setprop("/sim/rendering/camera-group/zfar",max_vis_range);}
});
setlistener(lw~"config/temperature-offset-degc", func {temperature_offset = getprop(lw~"config/temperature-offset-degc");});
@ -4396,7 +4401,7 @@ var ec = "/environment/config/";
# a hash map of the strength for convection associated with terrain types
var landcover_map = {BuiltUpCover: 0.35, Town: 0.35, Freeway:0.35, BarrenCover:0.3, HerbTundraCover: 0.25, GrassCover: 0.2, CropGrassCover: 0.2, EvergreenBroadCover: 0.2, EvergreenNeedleCover: 0.2, Sand: 0.25, Grass: 0.2, Grassland: 0.2, Ocean: 0.01, Marsh: 0.05, Lake: 0.01, ShrubCover: 0.15, Landmass: 0.2, CropWoodCover: 0.15, MixedForestCover: 0.15, DryCropPastureCover: 0.25, MixedCropPastureCover: 0.2, IrrCropPastureCover: 0.15, DeciduousBroadCover: 0.1, DeciduousNeedleCover: 0.1, Bog: 0.05, pa_taxiway : 0.35, pa_tiedown: 0.35, pc_taxiway: 0.35, pc_tiedown: 0.35, Glacier: 0.03, SnowCover: 0.04, DryLake: 0.3, IntermittentStream: 0.2, DryCrop: 0.2, Lava: 0.3, GolfCourse: 0.2, Rock: 0.3, Construction: 0.35, PackIce: 0.04, NaturalCrop: 0.2};
var landcover_map = {BuiltUpCover: 0.35, Town: 0.35, Freeway:0.35, BarrenCover:0.3, HerbTundraCover: 0.25, GrassCover: 0.2, CropGrassCover: 0.2, EvergreenBroadCover: 0.2, EvergreenNeedleCover: 0.2, Sand: 0.25, Grass: 0.2, Grassland: 0.2, Ocean: 0.01, Marsh: 0.05, Lake: 0.01, ShrubCover: 0.15, Landmass: 0.2, CropWoodCover: 0.15, MixedForestCover: 0.15, DryCropPastureCover: 0.25, MixedCropPastureCover: 0.2, MixedCrop: 0.2, IrrCropPastureCover: 0.15, DeciduousBroadCover: 0.1, DeciduousNeedleCover: 0.1, Bog: 0.05, Littoral: 0.05, pa_taxiway : 0.35, pa_tiedown: 0.35, pc_taxiway: 0.35, pc_tiedown: 0.35, Glacier: 0.03, SnowCover: 0.04, DryLake: 0.3, IntermittentStream: 0.2, DryCrop: 0.2, Lava: 0.3, GolfCourse: 0.2, Rock: 0.3, Construction: 0.35, PackIce: 0.04, NaturalCrop: 0.2};
# a hash map of average vertical cloud model sizes
@ -4523,7 +4528,7 @@ var scattering_shader_flag = 0;
var wxradar_support_flag = 1;
var ground_haze_factor = 1.0;
var max_vis_range = 120000.0;
var max_vis_range = math.exp(getprop(lw~"config/aux-max-vis-range-m"));
var temperature_offset = 0.0;
var current_mean_alt = 0.0;
var air_pollution_norm = 0.0;

View file

@ -1145,6 +1145,7 @@ for (var i = index; i < i_max; i = i+1)
for (var j = 0; j < s; j = j+1)
{
if (active_tile_list[j] == c.index) {flag = 1; break;}
if (c.index == 0) {flag =1; break;} # clouds in tile index 0 are special
}
if (flag == 0)

View file

@ -54,6 +54,17 @@ var dir_index = getprop(lw~"tiles/tmp/dir-index");
local_weather.assemble_effect_array();
# add a noctilucent cloud patch
var tile_index = getprop("local-weather/tiles/tile-counter");
if ((tile_index == 1) and (getprop("environment/create-noctilucent-clouds")==1))
{
alpha = 0.0;
var blat = getprop(lw~"tiles/tmp/latitude-deg");
var blon = getprop(lw~"tiles/tmp/longitude-deg");
create_noctilucent_patch(blat, blon, 272000.0, alpha);
}
# reset lighting
local_weather.top_shade = 1.0;
@ -4377,6 +4388,17 @@ if (local_weather.wxradar_support_flag == 1)
}
var create_noctilucent_patch = func (lat, lon, alt, alpha) {
var phi = alpha * math.pi/180.0;
var x = 2.0 * (rand()-0.5) * 40000;
var y = 2.0 * (rand()-0.5) * 40000;
local_weather.create_streak("Noctilucent",lat+get_lat(x,y,phi), lon+get_lon(x,y,phi), alt,1500.0,20,10000.0,0.0, 3000.0, 8,10000.0,0.0,3000.0,alpha,1.5);
}
var create_2_8_cirrocumulus_patches = func (lat, lon, alt, alpha) {

View file

@ -0,0 +1,141 @@
// -*-C++-*-
#version 120
varying float fogFactor;
varying vec3 hazeColor;
uniform float terminator;
uniform float altitude;
uniform float cloud_self_shading;
uniform float moonlight;
const float shade = 1.0;
const float cloud_height = 1000.0;
const float EarthRadius = 5800000.0;
// light_func is a generalized logistic function fit to the light intensity as a function
// of scaled terminator position obtained from Flightgear core
float light_func (in float x, in float a, in float b, in float c, in float d, in float e)
{
x = x-0.5;
// use the asymptotics to shorten computations
if (x > 30.0) {return e;}
if (x < -15.0) {return 0.03;}
return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
}
void main(void)
{
vec3 shadedFogColor = vec3 (0.65, 0.67, 0.78);
vec3 moonLightColor = vec3 (0.095, 0.095, 0.15) * moonlight;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
//gl_TexCoord[0] = gl_MultiTexCoord0 + vec4(textureIndexX, textureIndexY, 0.0, 0.0);
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);
gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
gl_Position.x = gl_Vertex.x;
gl_Position.y += gl_Vertex.y;
gl_Position.z += gl_Vertex.z;
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);
vec3 relVector = gl_Position.xyz - ep.xyz;
gl_Position = gl_ModelViewProjectionMatrix * gl_Position;
// Light at the final position
// first obtain normal to sun position
vec3 lightFull = (gl_ModelViewMatrixInverse * gl_LightSource[0].position).xyz;
vec3 lightHorizon = normalize(vec3(lightFull.x,lightFull.y, 0.0));
// yprime is the distance of the vertex into sun direction, corrected for altitude
//float vertex_alt = max(altitude * 0.30480 + relVector.z,100.0);
float vertex_alt = altitude + relVector.z;
float yprime = -dot(relVector, lightHorizon);
float yprime_alt = yprime -sqrt(2.0 * EarthRadius * vertex_alt);
// compute the light at the position
//vec4 light_diffuse;
float lightArg = (terminator-yprime_alt)/100000.0;
//light_diffuse.b = light_func(lightArg, 1.330e-05, 0.264, 2.227, 1.08e-05, 1.0);
//light_diffuse.g = light_func(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
//light_diffuse.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
//light_diffuse.a = 1.0;
float light_intensity = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
vec4 light_diffuse = vec4 (0.57, 0.57, 0.9, 1.0);
light_diffuse.rgb = light_intensity * light_diffuse.rgb;
float intensity = length(light_diffuse.rgb);
//light_diffuse.rgb = intensity * normalize(mix(light_diffuse.rgb, shadedFogColor, (1.0 - smoothstep(0.5,0.9, cloud_self_shading ))));
// 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 = light_diffuse * shade;
gl_FrontColor = mix(backlight, light_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 = 0.2 * min(smoothstep(100.0, 250.0, fogCoord), 1.0 - smoothstep(250000.0, 300000.0, fogCoord));
// During the day, noctilucent clouds are invisible
gl_FrontColor.a = gl_FrontColor.a * (1.0 - smoothstep(4.0,8.0,lightArg));
// Fog doesn't affect rain as much as other objects.
//fogFactor = exp( -gl_Fog.density * fogCoord * 0.4);
//fogFactor = clamp(fogFactor, 0.0, 1.0);
float fadeScale = 0.05 + 0.2 * log(fogCoord/1000.0);
if (fadeScale < 0.05) fadeScale = 0.05;
fogFactor = exp( -gl_Fog.density * fogCoord * fadeScale);
hazeColor = light_diffuse.rgb;
hazeColor.r = hazeColor.r * 0.83;
hazeColor.g = hazeColor.g * 0.9;
// in sunset or sunrise conditions, do extra shading of clouds
// two times terminator width governs how quickly light fades into shadow
float terminator_width = 200000.0;
// now dim the light
float earthShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1;
if (earthShade < 0.8)
{
intensity = length(light_diffuse.rgb);
gl_FrontColor.rgb = intensity * normalize(mix(gl_FrontColor.rgb, shadedFogColor, 1.0 -smoothstep(0.1, 0.8,earthShade ) ));
}
hazeColor = hazeColor * earthShade;
gl_FrontColor.rgb = gl_FrontColor.rgb * earthShade;
gl_FrontColor.rgb = gl_FrontColor.rgb + moonLightColor * (1.0 - smoothstep(0.4, 0.5, earthShade));
hazeColor.rgb = hazeColor.rgb + moonLightColor * (1.0 - smoothstep(0.4, 0.5, earthShade));
gl_BackColor = gl_FrontColor;
}