1
0
Fork 0

More variation for the ALS aurora simulation, WIP

This commit is contained in:
Thorsten Renk 2017-04-27 14:18:55 +03:00
parent 5c62d4663c
commit 2f99804dba
3 changed files with 242 additions and 3 deletions

View file

@ -17,6 +17,7 @@
<aurora_vsize><use>/environment/aurora/vsize</use></aurora_vsize>
<aurora_hsize><use>/environment/aurora/hsize</use></aurora_hsize>
<aurora_ray_factor><use>/environment/aurora/ray-factor</use></aurora_ray_factor>
<aurora_penetration_factor><use>/environment/aurora/penetration-factor</use></aurora_penetration_factor>
<lthickness><use>/environment/ground-haze-thickness-m</use></lthickness>
<terminator><use>/environment/terminator-relative-position-m</use></terminator>
<terrain_alt><use>/environment/mean-terrain-elevation-m</use></terrain_alt>
@ -172,6 +173,11 @@
<name>aurora_ray_factor</name>
<type>float</type>
<value><use>aurora_ray_factor</use></value>
</uniform>
<uniform>
<name>aurora_penetration_factor</name>
<type>float</type>
<value><use>aurora_penetration_factor</use></value>
</uniform>
<uniform>
<name>horizon_roughness</name>

226
Nasal/aurora.nas Executable file
View file

@ -0,0 +1,226 @@
###########################################################
# Aurora Borealis manager
#
# this runs once at startup to randomize Aurora appearance
# a little and otherwise simulates detailed Aurora evolution
# only when requested by the user
###########################################################
var aurora_manager = {
running_flag : 0,
storm_probability: 0.1,
storm_flag: 0,
storm_duration: 0,
storm_timer: 0,
afterglow_flag: 0,
afterglow_timer: 0,
strength_bg: 0,
strength_target: 0,
strength_current: 0,
strength_rate: 0.015,
ray_bg: 0,
ray_target: 0,
ray_current: 0,
ray_rate: 0.005,
glow_bg: 0,
glow_target: 0,
glow_current: 0,
glow_rate: 0.02,
upper_bg: 0,
upper_target: 0,
upper_current: 0,
upper_rate: 0.025,
delta_t: 0.1,
init: func {
var rn = rand();
setprop("/environment/aurora/penetration-factor", rn);
rn = rand();
setprop("/environment/aurora/ray-factor", 0.8 * rn);
me.ray_bg = 0.4 * rn;
rn = rand();
setprop("/environment/aurora/patchiness", rn);
rn = rand();
setprop("/environment/aurora/upper-alt-factor", rn);
me.upper_bg = 0.5 * rn;
me.strength_bg = 0.4 * rand();
me.strength_rate = me.strength_rate * me.delta_t;
me.ray_rate = me.ray_rate * me.delta_t;
me.glow_rate = me.glow_rate * me.delta_t;
me.upper_rate = me.upper_rate * me.delta_t;
# me.storm_probability = me.storm_probability * me.delta_t;
},
state: func {
var state = getprop("/environment/aurora/aurora-manager");
print("Aurora state manager");
if (state == 1) {me.start();}
else {me.stop();}
},
start: func {
if (me.running_flag == 1) {return;}
print("Starting aurora manager.");
me.running_flag = 1;
me.ray_target = me.ray_bg;
me.upper_target = me.upper_bg;
me.strength_target = getprop("/environment/aurora/set-strength");
me.ray_current = me.ray_target;
me.upper_current = me.ray_target;
me.strength_current = me.ray_target;
me.update();
},
stop: func {
me.running_flag = 0;
print("Stopping aurora manager.");
},
update: func {
if (me.running_flag == 0) {return;}
if ((rand() < me.storm_probability) and (me.storm_flag == 0) and (me.afterglow_flag == 0))# init auroral storm
{
me.storm_flag = 1;
me.storm_timer = 0;
me.storm_duration = 60.0 + rand() * 120.0;
me.storm_duration *= 0.4;
print("Auroral storm duration: ", me.storm_duration, " s");
}
if (me.storm_flag == 1)
{
if (me.storm_timer < me.storm_duration)
{
me.strength_target = 1.0;
me.ray_target = 0.7;
me.upper_target = 1.0;
}
else
{
me.ray_target = me.ray_bg;
me.storm_flag = 0;
me.afterglow_timer = 0;
me.afterglow_flag = 1;
}
me.storm_timer = me.storm_timer + me.delta_t;
}
if (me.afterglow_flag == 1)
{
if (me.afterglow_timer < 60)
{
me.glow_target = 1.0 - me.strength_bg;
}
else if (me.afterglow_timer < 120)
{
me.upper_target = me.upper_bg;
me.strength_target = me.strength_bg;
me.glow_target = 0.0;
}
else
{
me.afterglow_flag = 0;
}
me.afterglow_timer = me.afterglow_timer + me.delta_t;
}
me.evolve();
settimer (func me.update(), me.delta_t);
},
evolve: func {
if (me.strength_current < me.strength_target)
{
me.strength_current = me.strength_current + me.strength_rate;
if (me.strength_current > me.strength_target) {me.strength_current = me.strength_target;}
}
else if (me.strength_current > me.strength_target)
{
me.strength_current = me.strength_current - me.strength_rate;
if (me.strength_current < me.strength_target) {me.strength_current = me.strength_target;}
}
if (me.ray_current < me.ray_target)
{
me.ray_current = me.ray_current + me.ray_rate;
if (me.ray_current > me.ray_target) {me.ray_current = me.ray_target;}
}
else if (me.ray_current > me.ray_target)
{
me.ray_current = me.ray_current - me.ray_rate;
if (me.ray_current < me.ray_target) {me.ray_current = me.ray_target;}
}
if (me.upper_current < me.upper_target)
{
me.upper_current = me.upper_current + me.upper_rate;
if (me.upper_current > me.upper_target) {me.upper_current = me.upper_target;}
}
else if (me.upper_current > me.upper_target)
{
me.upper_current = me.upper_current - me.upper_rate;
if (me.upper_current < me.upper_target) {me.upper_current = me.upper_target;}
}
if (me.glow_current < me.glow_target)
{
me.glow_current = me.glow_current + me.glow_rate;
if (me.glow_current > me.glow_target) {me.glow_current = me.glow_target;}
}
else if (me.glow_current > me.glow_target)
{
me.glow_current = me.glow_current - me.glow_rate;
if (me.glow_current < me.glow_target) {me.glow_current = me.glow_target;}
}
setprop("/environment/aurora/set-strength", me.strength_current);
setprop("/environment/aurora/ray-factor", me.ray_current);
setprop("/environment/aurora/upper-alt-factor", me.upper_current);
setprop("/environment/aurora/afterglow", me.glow_current);
},
};
aurora_manager.init();

View file

@ -35,6 +35,7 @@ uniform float aurora_strength;
uniform float aurora_hsize;
uniform float aurora_vsize;
uniform float aurora_ray_factor;
uniform float aurora_penetration_factor;
uniform float landing_light1_offset;
uniform float landing_light2_offset;
uniform float landing_light3_offset;
@ -147,14 +148,20 @@ void main()
float hArg = dot(nView, direction);
float aurora_v = smoothstep(0.2 - 0.6 * aurora_vsize * (1.0 - 0.8* aurora_ray_factor) , 0.2 , costheta + hNoiseAurora) * (1.0- smoothstep(0.3, 0.3 + aurora_vsize, costheta + hNoiseAurora));
aurora_v *= (1.0 + 5.0 * aurora_ray_factor * (1.0 -smoothstep(0.2 - 0.6 * aurora_vsize * (1.0 - 0.8* aurora_ray_factor), 0.3, costheta + hNoiseAurora)));
float aurora_vEdge = 0.2 - 0.6 * aurora_vsize * (1.0 - 0.8* aurora_ray_factor);
float aurora_vArg = costheta + hNoiseAurora;
float aurora_v = smoothstep(aurora_vEdge , 0.2 , costheta + hNoiseAurora) * (1.0- smoothstep(0.3, 0.3 + aurora_vsize, aurora_vArg));
aurora_v *= (1.0 + 5.0 * aurora_ray_factor * (1.0 -smoothstep(aurora_vEdge, 0.3, aurora_vArg)));
float aurora_h = smoothstep(1.0 - aurora_hsize, 1.0, hArg);
float aurora_time = 0.01 * osg_SimulationTime;
vec3 auroraBaseColor = vec3 (0.0, 0.2, 0.1);
vec3 auroraFringeColor = vec3 (0.4, 0.15, 0.2);
float fringe_factor = 1.0 - smoothstep(aurora_vEdge, aurora_vEdge + 0.08, aurora_vArg);
fringe_factor *= aurora_strength * aurora_penetration_factor;
auroraBaseColor = mix(auroraBaseColor, auroraFringeColor, fringe_factor );
float aurora_ray = mix(1.0, Noise2D(vec2(cbeta, 0.01 * aurora_time), 0.001), aurora_ray_factor);