From 60f63cb2afbdfe1b64654366d52a0f10bf0bf11b Mon Sep 17 00:00:00 2001 From: Thorsten Renk Date: Thu, 20 Apr 2017 11:27:47 +0300 Subject: [PATCH] Earthview: support for heightmapping and moonlight illumination --- Effects/planet-cloudlayer.eff | 26 +++++++++++++------- Effects/planet.eff | 23 +++++++++++------ Shaders/planet-cloudlayer.frag | 4 +++ Shaders/planet-high.frag | 45 +++++++++++++++++++++++++++++----- 4 files changed, 76 insertions(+), 22 deletions(-) diff --git a/Effects/planet-cloudlayer.eff b/Effects/planet-cloudlayer.eff index ae2b354f4..b1d495f22 100644 --- a/Effects/planet-cloudlayer.eff +++ b/Effects/planet-cloudlayer.eff @@ -23,20 +23,21 @@ /earthview/cloud-normal-flag /earthview/shade-effect /sim/time/sun-angle-rad - /environment/air-pollution-norm + /environment/moonlight + /environment/air-pollution-norm /earthview/roi-x1 /earthview/roi-y1 /earthview/lightning /sim/rendering/als-filters/use-filtering - /sim/rendering/als-filters/gamma - /sim/rendering/als-filters/brightness - /environment/surface/delta-T-cloud + /sim/rendering/als-filters/gamma + /sim/rendering/als-filters/brightness + /environment/surface/delta-T-cloud /sim/rendering/als-filters/grey-factor - /sim/rendering/als-filters/black-factor - /sim/rendering/als-filters/use-night-vision - /sim/rendering/als-filters/use-IR-vision - /sim/startup/xsize - /sim/startup/ysize + /sim/rendering/als-filters/black-factor + /sim/rendering/als-filters/use-night-vision + /sim/rendering/als-filters/use-IR-vision + /sim/startup/xsize + /sim/startup/ysize @@ -199,6 +200,13 @@ sun-angle + + moonlight + float + + moonlight + + lightning float diff --git a/Effects/planet.eff b/Effects/planet.eff index 5ee7549aa..a6f1d71e3 100644 --- a/Effects/planet.eff +++ b/Effects/planet.eff @@ -40,16 +40,18 @@ /earthview/cloud-shadow-flag /earthview/overlay-texture-flag /sim/time/sun-angle-rad + /environment/moonlight /sim/rendering/als-filters/use-filtering /sim/rendering/als-filters/gamma - /sim/rendering/als-filters/brightness - /environment/surface/delta-T-cloud + /sim/rendering/als-filters/brightness + /environment/surface/delta-T-cloud /sim/rendering/als-filters/grey-factor - /sim/rendering/als-filters/black-factor - /sim/rendering/als-filters/use-night-vision - /sim/rendering/als-filters/use-IR-vision - /sim/startup/xsize - /sim/startup/ysize + /sim/rendering/als-filters/black-factor + /sim/rendering/als-filters/use-night-vision + /sim/rendering/als-filters/use-IR-vision + /sim/startup/xsize + /sim/startup/ysize + 15 @@ -197,6 +199,13 @@ visibility + + moonlight + float + + moonlight + + air_pollution float diff --git a/Shaders/planet-cloudlayer.frag b/Shaders/planet-cloudlayer.frag index 451586fbe..9e1f62930 100644 --- a/Shaders/planet-cloudlayer.frag +++ b/Shaders/planet-cloudlayer.frag @@ -11,6 +11,7 @@ varying vec3 VTangent; uniform float shade_effect; uniform float sun_angle; uniform float air_pollution; +uniform float moonlight; uniform float roi_x1; uniform float roi_y1; @@ -138,6 +139,9 @@ void main() float darkness_fact = 1.0 - smoothstep(0.0,0.2, length(color.rgb)); color.rgb += lightning_color(gl_TexCoord[0].st) * (1.0 - texel.a) * lightning * darkness_fact; + vec3 moonLightColor = vec3 (0.095, 0.095, 0.15) * moonlight; + + color.rgb += moonLightColor; color.a = 1.0;//diffuse_term.a; color = clamp(color, 0.0, 1.0); diff --git a/Shaders/planet-high.frag b/Shaders/planet-high.frag index 5a423a8bd..5d7a839db 100644 --- a/Shaders/planet-high.frag +++ b/Shaders/planet-high.frag @@ -10,6 +10,7 @@ varying vec3 VTangent; uniform float visibility; uniform float air_pollution; +uniform float moonlight; uniform float sun_angle; uniform bool use_clouds; uniform bool use_cloud_shadows; @@ -41,26 +42,45 @@ void main() // normal should be reversed. n = (2.0 * gl_Color.a - 1.0) * normal; n = normalize(n); - - vec4 nmap = texture2D(normal_texture, gl_TexCoord[0].st); - + + float parallaxFactor = max(1.0 - dot(normalize(ecViewDir), n),0.0); vec3 VBinormal; VBinormal = normalize(cross(normal, VTangent)); + + float xOffset1 = -1.0 * dot(ecViewDir, normalize(VTangent)); + float yOffset1 = -1.0 * dot(ecViewDir, VBinormal); + + vec2 grad_dir = normalize (vec2 (xOffset1, yOffset1)); + + vec4 nmap = texture2D(normal_texture, gl_TexCoord[0].st); + + + + float hmap = 1.0 - nmap.a; + nmap = texture2D(normal_texture, gl_TexCoord[0].st - 0.0005 * grad_dir * hmap * 2.0 * parallaxFactor); + + // sanity processing for normal map when alpha is close to zero + nmap.rgb = normalize(nmap.rgb); + //if (nmap.b < 0.0) {nmap.b = -nmap.b;} + vec3 N = nmap.rgb * 2.0 - 1.0; - N = normalize(N.x * normalize(VTangent) * 0.6 + N.y * VBinormal * 0.6 + N.z * n); + N = normalize(N.x * normalize(VTangent) * 0.6 + N.y * VBinormal * 0.6 + N.z * n); float xOffset = -0.005 * dot(lightDir, normalize(VTangent)); float yOffset = -0.005 * dot(lightDir, VBinormal); + + + 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);} - texel = texture2D(texture, gl_TexCoord[0].st); + texel = texture2D(texture, gl_TexCoord[0].st - 0.0005 * grad_dir * hmap * 2.0 * parallaxFactor); float night_light = (1.0 -texel.a); texel.a = 1.0; grainTexel = texture2D(grain_texture, gl_TexCoord[0].st * 40.0); @@ -114,6 +134,10 @@ void main() * light_specular * (1.0-shadowTexel.a) * pow(NdotHV, gl_FrontMaterial.shininess)); } + + vec3 moonLightColor = vec3 (0.095, 0.095, 0.15) * moonlight; + color.rgb += moonLightColor; + color.a = diffuse_term.a; @@ -146,14 +170,23 @@ void main() vec4 fogColor = vec4 (0.83,0.9,1.0,1.0) * fogLighting; vec3 rayleighColor = vec3 (0.17, 0.52, 0.87) * fogLighting; + float heightFactor = exp(-hmap * 0.8); + distance_through_atmosphere *= heightFactor; + float fogFactor = exp(-distance_through_atmosphere/(visibility/1000.0)); float rayleighFactor = exp(-distance_through_atmosphere/(300.0 / (1.0 + 4.0 * air_pollution)) ); + + fragColor.rgb = mix(rayleighColor, fragColor.rgb, rayleighFactor); fragColor = mix(fogColor, fragColor, fogFactor); fragColor.rgb = filter_combined(fragColor.rgb); - gl_FragColor = clamp(fragColor, 0.0, 1.0); + + + + gl_FragColor = clamp(fragColor, 0.0, 1.0); + }