From 3970bad285fbb46df9482e0db0915962ecbc58f9 Mon Sep 17 00:00:00 2001 From: Thorsten Renk Date: Mon, 5 May 2014 15:27:32 +0300 Subject: [PATCH] Updates to Earthview, based on work by Anton Gomez Alvedro --- Effects/planet-cloudlayer.eff | 3 - Effects/planet.eff | 11 +- Nasal/earthview.nas | 57 ++++++++- Shaders/planet-cloudlayer.frag | 1 - Shaders/planet.frag | 13 +-- gui/dialogs/earthview.xml | 206 ++++++++++++++++++++++++++++++++- preferences.xml | 3 + 7 files changed, 274 insertions(+), 20 deletions(-) diff --git a/Effects/planet-cloudlayer.eff b/Effects/planet-cloudlayer.eff index 10be15214..bd0850561 100644 --- a/Effects/planet-cloudlayer.eff +++ b/Effects/planet-cloudlayer.eff @@ -17,8 +17,6 @@ - - /sim/rendering/shaders/generic 2.0 @@ -31,7 +29,6 @@ GL_ARB_fragment_shader - true diff --git a/Effects/planet.eff b/Effects/planet.eff index 37a68c79c..a17ffcf89 100644 --- a/Effects/planet.eff +++ b/Effects/planet.eff @@ -21,6 +21,7 @@ /environment/visibility-m /earthview/cloudsphere-flag + /earthview/cloud-shadow-flag 6 @@ -29,8 +30,6 @@ - - /sim/rendering/shaders/generic 2.0 @@ -43,7 +42,6 @@ GL_ARB_fragment_shader - true @@ -141,6 +139,13 @@ use-clouds + + use_cloud_shadows + bool + + use-cloud-shadows + + diff --git a/Nasal/earthview.nas b/Nasal/earthview.nas index f1efb4df7..0070402d9 100644 --- a/Nasal/earthview.nas +++ b/Nasal/earthview.nas @@ -4,7 +4,7 @@ var start = func() { -if (earthview_running_flag == 1) {return;} +if (earthview_running_flag ==1) {return;} earthview_running_flag = 1; @@ -13,6 +13,20 @@ var lon = getprop("/position/longitude-deg"); earth_model.node = earthview.place_earth_model("Models/Astro/earth.xml",lat, lon, 0.0, 0.0, 0.0, 0.0); cloudsphere_model.node = earthview.place_earth_model("Models/Astro/cloudsphere.xml",lat, lon, 0.0, 0.0, 0.0, 0.0); + +# set Basic Weather off +props.globals.getNode("/environment/config/enabled").setBoolValue(0); +props.globals.getNode("/environment/params/metar-updates-environment").setBoolValue(0); + +# set some reasonable defaults + +setprop("/environment/visibility-m", 80000.0); +setprop("/sim/rendering/mie", 0.0); +setprop("/sim/rendering/rayleigh", 0.00002); +setprop("/sim/rendering/dome-density", 1.0); + +control_loop(); + } var stop = func () { @@ -20,6 +34,7 @@ var stop = func () { earth_model.node.remove(); cloudsphere_model.node.remove(); setprop("/earthview/control_loop_flag",0); + earthview_running_flag = 0; } @@ -70,7 +85,7 @@ model.getNode("load", 1).remove(); setprop("/earthview/heading-deg",90); setprop("/earthview/control_loop_flag",1); -control_loop(); + return model; } @@ -96,14 +111,50 @@ setprop("/earthview/longitude-deg", lon); setprop("/earthview/roll-deg", -(90-lat)); setprop("/earthview/yaw-deg", -lon); +# now set scattering paramaters + +if (getprop("/earthview/mrd-flag") == 1) + { + var rayleigh = 0.0002; + var mie = 0.001; + var density = 1.0; + + if (altitude1 < 300000.0) + { + setprop("/sim/rendering/rayleigh",rayleigh); + setprop("/sim/rendering/mie",mie); + setprop("/sim/rendering/dome-density",density); + } + else if (altitude1 < 650000.0) + { + rayleigh = rayleigh - 0.00018 * (altitude1-300000.0)/350000.0; + mie = mie - 0.001 * (altitude1-300000.0)/350000.0; + density = 1.0; + setprop("/sim/rendering/rayleigh",rayleigh); + setprop("/sim/rendering/mie",mie); + setprop("/sim/rendering/dome-density",density); + } + else + { + rayleigh = 0.00002; + mie = 0.0; + density = 1.0; + setprop("/sim/rendering/rayleigh",rayleigh); + setprop("/sim/rendering/mie",mie); + setprop("/sim/rendering/dome-density",density); + } + + } if (getprop("/earthview/control_loop_flag") ==1) {settimer( func {control_loop(); },0);} } -var earthview_running_flag = 0; + var ft_to_m = 0.30480; var m_to_ft = 1.0/ft_to_m; var earth_model = {}; var cloudsphere_model = {}; +var earthview_running_flag = 0; + diff --git a/Shaders/planet-cloudlayer.frag b/Shaders/planet-cloudlayer.frag index b640e0552..596e1e098 100644 --- a/Shaders/planet-cloudlayer.frag +++ b/Shaders/planet-cloudlayer.frag @@ -63,5 +63,4 @@ void main() fragColor = color * texel + specular; gl_FragColor = fragColor; - //gl_FragColor = (0.5,0.5,0.5,1.0); } diff --git a/Shaders/planet.frag b/Shaders/planet.frag index 92d9c740e..2364eea0c 100644 --- a/Shaders/planet.frag +++ b/Shaders/planet.frag @@ -10,6 +10,7 @@ varying vec3 VTangent; uniform float visibility; uniform bool use_clouds; +uniform bool use_cloud_shadows; uniform sampler2D texture; uniform sampler2D shadowtex; @@ -44,11 +45,11 @@ void main() float xOffset = -0.005 * dot(normalize(lightDir), normalize(VTangent)); float yOffset = -0.005 * dot(normalize(lightDir), normalize(VBinormal)); - if (use_clouds) + if ((use_cloud_shadows)&&(use_clouds)) {shadowTexel = texture2D(shadowtex, vec2(gl_TexCoord[0].s-xOffset, gl_TexCoord[0].t-yOffset));} else - {shadowTexel = vec4 (0.0,0.0,0.0,0.0);} - + {shadowTexel = vec4 (0.0,0.0,0.0,0.0);} + texel = texture2D(texture, gl_TexCoord[0].st); vec3 light_specular = vec3 (1.0, 1.0, 1.0); @@ -61,7 +62,7 @@ void main() intensity = length(light_specular); light_specular = mix(dawn.rgb, light_specular, smoothstep(0.0, 0.2, NdotL)); - float specular_enhancement = 4.0 * (1.0 -smoothstep(0.0, 0.3,length(texel.rgb - vec3 (0.007,0.019, 0.078)))); + float specular_enhancement = 4.0 * (1.0 -smoothstep(0.0, 0.1,length(texel.rgb - vec3 (0.007,0.019, 0.078)))); if (NdotL > 0.0) { color += diffuse_term * NdotL * (1.0-shadowTexel.a); @@ -84,13 +85,11 @@ void main() float angle = dot(normalize(ecViewDir), normalize(normal)); float distance_through_atmosphere = 10.0 / ((angle)+0.001); - vec4 fogColor = vec4 (0.83,0.9,1.0,1.0) * clamp(length(diffuse_term.rgb * max(NdotL,0.0)),0.0,1.0); + vec4 fogColor = vec4 (0.83,0.9,1.0,1.0) * clamp(length(diffuse_term.rgb * clamp(NdotL,0.01, 0.99)),0.0,1.0); //float visibility = 80.0; float fogFactor = exp(-distance_through_atmosphere/(visibility/1000.0)); fragColor = mix(fogColor, fragColor, fogFactor); - //fragColor.rgb = fog_Func(fragColor.rgb, fogType); gl_FragColor = fragColor; - //gl_FragColor = (0.5,0.5,0.5,1.0); } diff --git a/gui/dialogs/earthview.xml b/gui/dialogs/earthview.xml index c91be553f..695d4d74c 100644 --- a/gui/dialogs/earthview.xml +++ b/gui/dialogs/earthview.xml @@ -52,17 +52,60 @@ + cloudsphere-flag 0 1 left /earthview/cloudsphere-flag + + dialog-apply + cloudsphere-flag + + + + + /earthview/cloudsphere-flag + 1 + 0 + right + + + + + /earthview/cloudsphere-flag + cloud-shadow-flag + 1 + 1 + left + /earthview/cloud-shadow-flag + + dialog-apply + cloud-shadow-flag + + + + + + 2 + 0 + right + + + + + 2 + 1 + left + /earthview/mrd-flag dialog-apply + + + hbox + + + left + + + true + + + + + hbox + right + + /earthview/cloud-shadow-flag + + + + /earthview/cloud-shadow-flag + cloud-rotation-angle + 0.0 + 360.0 + 0.1 + true + /earthview/cloudsphere-angle + + dialog-apply + cloud-rotation-angle + + + + + %.3f + true + /earthview/cloudsphere-angle + + + + hbox + + + left + + + true + + + + + hbox + right + + /earthview/mrd-flag + + + + /earthview/mrd-flag + mie-factor + 0.0 + 0.01 + 0.001 + true + /sim/rendering/mie + + dialog-apply + mie-factor + + + + + %.3f + true + /sim/rendering/mie + + + + + hbox + right + + /earthview/mrd-flag + + + + /earthview/mrd-flag + rayleigh-factor + 0.0 + 0.001 + 0.00002 + /sim/rendering/rayleigh + + dialog-apply + rayleigh-factor + + + + + %.5f + true + /sim/rendering/rayleigh + + + + + hbox + right + + /earthview/mrd-flag + + + + density-factor + /earthview/mrd-flag + 0.0 + 1.0 + 0.1 + /sim/rendering/dome-density + + dialog-apply + density-factor + + + + + %.1f + true + /sim/rendering/dome-density + + + + + hbox + right + + + + + visibility + 30000.0 + 250000.0 + 10.0 + /environment/visibility-m + + dialog-apply + visibility + + true + + + + %.1f + true + /environment/visibility-m + +