diff --git a/Effects/cloud-impostor.eff b/Effects/cloud-impostor.eff
index 13c675304..dd645ac45 100644
--- a/Effects/cloud-impostor.eff
+++ b/Effects/cloud-impostor.eff
@@ -58,7 +58,7 @@
clamp-->
- Shaders/cloud-impostor-lightfield.vert
+ Shaders/cloud-impostor-ALS.vert
Shaders/cloud-static-lightfield.frag
diff --git a/Effects/skydome.eff b/Effects/skydome.eff
index 4d4824113..1a77c5f97 100644
--- a/Effects/skydome.eff
+++ b/Effects/skydome.eff
@@ -25,6 +25,7 @@
+
@@ -115,6 +116,11 @@
float
+
+ air_pollution
+ float
+
+
horizon_roughness
float
diff --git a/Effects/terrain-default.eff b/Effects/terrain-default.eff
index 7f00ed977..d7bbe8de7 100644
--- a/Effects/terrain-default.eff
+++ b/Effects/terrain-default.eff
@@ -876,6 +876,7 @@
Shaders/terrain-ALS-detailed.vert
Shaders/terrain-ALS-detailed.frag
Shaders/noise.frag
+ Shaders/hazes.frag
visibility
@@ -967,6 +968,11 @@
float
+
+ air_pollution
+ float
+
+
moonlight
float
@@ -1103,6 +1109,7 @@
Shaders/generic-ALS-base.vert
Shaders/terrain-ALS-base.frag
+ Shaders/hazes.frag
visibility
@@ -1159,6 +1166,11 @@
float
+
+ air_pollution
+ float
+
+
texture
sampler-2d
diff --git a/Effects/water.eff b/Effects/water.eff
index 6dc1a23b3..f8ec8360c 100644
--- a/Effects/water.eff
+++ b/Effects/water.eff
@@ -1051,6 +1051,7 @@
Shaders/water-ALS.vert
Shaders/water-ALS-base.frag
+ Shaders/hazes.frag
sea_r
diff --git a/Shaders/3dcloud-ALS.vert b/Shaders/3dcloud-ALS.vert
index 29ffc489e..11d076de5 100644
--- a/Shaders/3dcloud-ALS.vert
+++ b/Shaders/3dcloud-ALS.vert
@@ -146,7 +146,7 @@ void main(void)
// two times terminator width governs how quickly light fades into shadow
float terminator_width = 200000.0;
- float earthShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1;
+ float earthShade = 1.0- 0.9* smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt);
// compute the light at the position
vec4 light_diffuse;
@@ -158,7 +158,7 @@ void main(void)
light_diffuse.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
light_diffuse.a = 1.0;
- intensity = (1.0 - (0.5 * (1.0 - earthShade))) * length(light_diffuse.rgb);
+ intensity = (1.0 - (0.8 * (1.0 - earthShade))) * length(light_diffuse.rgb);
light_diffuse.rgb = intensity * normalize(mix(light_diffuse.rgb, shadedFogColor, (1.0 - smoothstep(0.5,0.9, min(scattering, cloud_self_shading) ))));
// correct ambient light intensity and hue before sunrise
diff --git a/Shaders/airfield-ALS.frag b/Shaders/airfield-ALS.frag
index 6ea8eaef6..6e8b833e1 100644
--- a/Shaders/airfield-ALS.frag
+++ b/Shaders/airfield-ALS.frag
@@ -63,19 +63,11 @@ float light_distance_fading(in float dist);
float fog_backscatter(in float avisibility);
vec3 rayleigh_out_shift(in vec3 color, in float outscatter);
+vec3 get_hazeColor(in float light_arg);
vec3 searchlight();
vec3 landing_light(in float offset);
-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.0;}
-
-return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
-}
float detail_fade (in float scale, in float angle, in float dist)
{
@@ -312,11 +304,8 @@ if (quality_level > 3)
float lightArg = (terminator-yprime_alt)/100000.0;
- vec3 hazeColor;
+ vec3 hazeColor = get_hazeColor(lightArg);
- hazeColor.b = light_func(lightArg, 1.330e-05, 0.264, 2.527, 1.08e-05, 1.0);
- hazeColor.g = light_func(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
- hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
// Rayleigh color shift due to out-scattering
@@ -483,10 +472,16 @@ hazeColor = mix(shadow * hazeColor, hazeColor, 0.3 + 0.7* smoothstep(250000.0, 4
hazeColor = clamp(hazeColor,0.0,1.0);
+// don't let the light fade out too rapidly
+lightArg = (terminator + 200000.0)/100000.0;
+float minLightIntensity = min(0.2,0.16 * lightArg + 0.5);
+vec3 minLight = minLightIntensity * vec3 (0.2, 0.3, 0.4);
+
+hazeColor.rgb *= eqColorFactor * eShade;
+hazeColor.rgb = max(hazeColor.rgb, minLight.rgb);
-
-fragColor.rgb = mix((eqColorFactor * hazeColor * eShade)+secondary_light * fog_backscatter(avisibility), fragColor.rgb,transmission);
+fragColor.rgb = mix(hazeColor+secondary_light * fog_backscatter(avisibility), fragColor.rgb,transmission);
diff --git a/Shaders/cloud-impostor-lightfield.vert b/Shaders/cloud-impostor-ALS.vert
similarity index 98%
rename from Shaders/cloud-impostor-lightfield.vert
rename to Shaders/cloud-impostor-ALS.vert
index 0992cfd65..712206e03 100644
--- a/Shaders/cloud-impostor-lightfield.vert
+++ b/Shaders/cloud-impostor-ALS.vert
@@ -94,7 +94,7 @@ void main(void)
float earthShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1;
//float intensity = length(light_diffuse.rgb);
- float intensity = (1.0 - (0.5 * (1.0 - earthShade))) * length(light_diffuse.rgb);
+ float intensity = (1.0 - (0.8 * (1.0 - earthShade))) * length(light_diffuse.rgb);
//light_diffuse.rgb = intensity * normalize(mix(light_diffuse.rgb, shadedFogColor, (1.0 - smoothstep(0.5,0.9, cloud_self_shading ))));
light_diffuse.rgb = intensity * normalize(mix(light_diffuse.rgb, shadedFogColor, (1.0 - smoothstep(0.5,0.9, cloud_self_shading ))));
if (earthShade < 0.6)
diff --git a/Shaders/drunway-ALS.frag b/Shaders/drunway-ALS.frag
index 241ff9913..5b4c2852d 100644
--- a/Shaders/drunway-ALS.frag
+++ b/Shaders/drunway-ALS.frag
@@ -63,22 +63,9 @@ float rayleigh_in_func(in float dist, in float air_pollution, in float avisibili
vec3 searchlight();
vec3 landing_light(in float offset);
vec3 rayleigh_out_shift(in vec3 color, in float outscatter);
+vec3 get_hazeColor(in float light_arg);
-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.0;}
-
-return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
-}
-
-// this determines how light is attenuated in the distance
-// physically this should be exp(-arg) but for technical reasons we use a sharper cutoff
-// for distance > visibility
void main()
@@ -286,11 +273,9 @@ if ((dist < 5000.0)&& (quality_level > 3) && (wetness>0.0))
float lightArg = (terminator-yprime_alt)/100000.0;
-vec3 hazeColor;
+vec3 hazeColor = get_hazeColor(lightArg);
+
-hazeColor.b = light_func(lightArg, 1.330e-05, 0.264, 2.527, 1.08e-05, 1.0);
-hazeColor.g = light_func(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
-hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
// Rayleigh color shifts
@@ -459,8 +444,15 @@ if (intensity > 0.0) // this needs to be a condition, because otherwise hazeColo
hazeColor = mix(shadow * hazeColor, hazeColor, 0.3 + 0.7* smoothstep(250000.0, 400000.0, terminator));
}
+// don't let the light fade out too rapidly
+lightArg = (terminator + 200000.0)/100000.0;
+float minLightIntensity = min(0.2,0.16 * lightArg + 0.5);
+vec3 minLight = minLightIntensity * vec3 (0.2, 0.3, 0.4);
-fragColor.rgb = mix((eqColorFactor * hazeColor * eShade) +secondary_light * fog_backscatter(avisibility) , fragColor.rgb,transmission);
+hazeColor.rgb *= eqColorFactor * eShade;
+hazeColor.rgb = max(hazeColor.rgb, minLight.rgb);
+
+fragColor.rgb = mix( hazeColor +secondary_light * fog_backscatter(avisibility) , fragColor.rgb,transmission);
}
diff --git a/Shaders/hazes.frag b/Shaders/hazes.frag
index 24026be78..1b7ae7895 100644
--- a/Shaders/hazes.frag
+++ b/Shaders/hazes.frag
@@ -1,4 +1,7 @@
// -*-C++-*-
+
+uniform float air_pollution;
+
// standard ALS fog function with exp(-d/D) fading and cutoff at low altitude and exp(-d^2/D^2) at high altitude
const float AtmosphericScaleHeight = 8500.0;
@@ -72,3 +75,28 @@ color.b = color.b * (1.0 - 1.6 * outscatter);
return color;
}
+
+// the generalized logistic function used to compute lightcurves
+
+float light_curve (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.0;}
+
+return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
+}
+
+// the haze color function
+
+vec3 get_hazeColor(in float lightArg)
+{
+vec3 hazeColor;
+hazeColor.r = light_curve(lightArg, 8.305e-06, 0.161, 4.827-3.0 *air_pollution, 3.04e-05, 1.0);
+hazeColor.g = light_curve(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
+hazeColor.b = light_curve(lightArg, 1.330e-05, 0.264, 1.527+ 2.0*air_pollution, 1.08e-05, 1.0);
+
+return hazeColor;
+}
diff --git a/Shaders/model-ALS-base.frag b/Shaders/model-ALS-base.frag
index cceea17da..2cb73536a 100644
--- a/Shaders/model-ALS-base.frag
+++ b/Shaders/model-ALS-base.frag
@@ -47,7 +47,9 @@ float alt_factor(in float eye_alt, in float vertex_alt);
float light_distance_fading(in float dist);
float fog_backscatter(in float avisibility);
+
vec3 rayleigh_out_shift(in vec3 color, in float outscatter);
+vec3 get_hazeColor(in float light_arg);
vec3 searchlight();
vec3 landing_light(in float offset);
@@ -143,11 +145,8 @@ void main()
float lightArg = (terminator-yprime_alt)/100000.0;
-vec3 hazeColor;
+vec3 hazeColor = get_hazeColor(lightArg);
-hazeColor.b = light_func(lightArg, 1.330e-05, 0.264, 2.527, 1.08e-05, 1.0);
-hazeColor.g = light_func(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
-hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
// Rayleigh color shift due to in-scattering
@@ -293,12 +292,18 @@ hazeColor = intensity * normalize(mix(hazeColor, shadedFogColor, (1.0-smoothste
float shadow = mix( min(1.0 + dot(normal,lightDir),1.0), 1.0, 1.0-smoothstep(0.1, 0.4, transmission));
hazeColor = mix(shadow * hazeColor, hazeColor, 0.3 + 0.7* smoothstep(250000.0, 400000.0, terminator));
+// don't let the light fade out too rapidly
+lightArg = (terminator + 200000.0)/100000.0;
+float minLightIntensity = min(0.2,0.16 * lightArg + 0.5);
+vec3 minLight = minLightIntensity * vec3 (0.2, 0.3, 0.4);
+hazeColor *= eqColorFactor * eShade;
+hazeColor.rgb = max(hazeColor.rgb, minLight.rgb);
// determine the right mix of transmission and haze
-fragColor.rgb = mix((eqColorFactor * hazeColor * eShade) + secondary_light * fog_backscatter(avisibility), fragColor.rgb,transmission);
+fragColor.rgb = mix(hazeColor + secondary_light * fog_backscatter(avisibility), fragColor.rgb,transmission);
diff --git a/Shaders/model-ALS-ultra.frag b/Shaders/model-ALS-ultra.frag
index 94a9ec40a..61f9241fd 100644
--- a/Shaders/model-ALS-ultra.frag
+++ b/Shaders/model-ALS-ultra.frag
@@ -99,6 +99,7 @@ float light_distance_fading(in float dist);
float fog_backscatter(in float avisibility);
vec3 rayleigh_out_shift(in vec3 color, in float outscatter);
+vec3 get_hazeColor(in float lightArg);
vec3 searchlight();
vec3 landing_light(in float offset);
@@ -492,11 +493,8 @@ void main (void)
/// BEGIN fog color
- vec3 hazeColor;
+ vec3 hazeColor = get_hazeColor(fog_lightArg);
- hazeColor.b = light_func(fog_lightArg-0.5, 1.330e-05, 0.264, 2.527, 1.08e-05, 1.0);
- hazeColor.g = light_func(fog_lightArg-0.5, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
- hazeColor.r = light_func(fog_lightArg-0.5, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
float rShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt + 420000.0);
float lightIntensity = length(hazeColor * effective_scattering) * rShade;
@@ -549,7 +547,14 @@ void main (void)
/// END Rayleigh fog
+ // don't let the light fade out too rapidly
+ lightArg = (terminator + 200000.0)/100000.0;
+ float minLightIntensity = min(0.2,0.16 * lightArg + 0.5);
+ vec3 minLight = minLightIntensity * vec3 (0.2, 0.3, 0.4);
+ hazeColor *= eqColorFactor * fog_earthShade;
+ hazeColor.rgb = max(hazeColor.rgb, minLight.rgb);
- fragColor.rgb = mix(eqColorFactor * hazeColor * fog_earthShade +secondary_light * fog_backscatter(avisibility), fragColor.rgb,transmission);
+
+ fragColor.rgb = mix(hazeColor +secondary_light * fog_backscatter(avisibility), fragColor.rgb,transmission);
gl_FragColor = fragColor;
}
diff --git a/Shaders/runway-ALS.frag b/Shaders/runway-ALS.frag
index 2330118d8..412bd7379 100644
--- a/Shaders/runway-ALS.frag
+++ b/Shaders/runway-ALS.frag
@@ -64,23 +64,7 @@ float rayleigh_in_func(in float dist, in float air_pollution, in float avisibili
vec3 searchlight();
vec3 landing_light(in float offset);
vec3 rayleigh_out_shift(in vec3 color, in float outscatter);
-
-
-
-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.0;}
-
-return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
-}
-
-// this determines how light is attenuated in the distance
-// physically this should be exp(-arg) but for technical reasons we use a sharper cutoff
-// for distance > visibility
+vec3 get_hazeColor(in float light_arg);
@@ -300,11 +284,8 @@ if ((dist < 5000.0)&& (quality_level > 3) && (wetness>0.0))
float lightArg = (terminator-yprime_alt)/100000.0;
- vec3 hazeColor;
+ vec3 hazeColor = get_hazeColor(lightArg);
- hazeColor.b = light_func(lightArg, 1.330e-05, 0.264, 2.527, 1.08e-05, 1.0);
- hazeColor.g = light_func(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
- hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
// Rayleigh color shifts
@@ -470,9 +451,15 @@ if (intensity > 0.0) // this needs to be a condition, because otherwise hazeColo
}
hazeColor = clamp(hazeColor, 0.0, 1.0);
+// don't let the light fade out too rapidly
+lightArg = (terminator + 200000.0)/100000.0;
+float minLightIntensity = min(0.2,0.16 * lightArg + 0.5);
+vec3 minLight = minLightIntensity * vec3 (0.2, 0.3, 0.4);
+hazeColor.rgb *= eqColorFactor * eShade;
+hazeColor.rgb = max(hazeColor.rgb, minLight.rgb);
-fragColor.rgb = mix((eqColorFactor * hazeColor * eShade)+secondary_light * fog_backscatter(avisibility), fragColor.rgb,transmission);
+fragColor.rgb = mix(hazeColor +secondary_light * fog_backscatter(avisibility), fragColor.rgb,transmission);
diff --git a/Shaders/skydome-ALS.frag b/Shaders/skydome-ALS.frag
index a13e7cc15..77372d6cf 100644
--- a/Shaders/skydome-ALS.frag
+++ b/Shaders/skydome-ALS.frag
@@ -22,6 +22,7 @@ uniform float saturation;
uniform float visibility;
uniform float avisibility;
uniform float scattering;
+uniform float terminator;
uniform float cloud_self_shading;
uniform float horizon_roughness;
uniform float landing_light1_offset;
@@ -39,6 +40,17 @@ float fog_backscatter(in float avisibility);
vec3 searchlight();
vec3 landing_light(in float offset);
+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.0;}
+
+return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
+}
+
float miePhase(in float cosTheta, in float g)
{
float g2 = g*g;
@@ -203,6 +215,19 @@ hazeBlendAngle = hazeBlendAngle + 0.1 * altFactor;
hazeBlendAngle = hazeBlendAngle + (1.0-horizon_roughness) * altFactor2 * 0.1 * Noise2D(vec2(0.0,cphi), 0.3);
terrainHazeColor = clamp(terrainHazeColor,0.0,1.0);
+
+
+// don't let the light fade out too rapidly
+float lightArg = (terminator + 200000.0)/100000.0;
+float minLightIntensity = min(0.2,0.16 * lightArg + 0.5);
+vec3 minLight = minLightIntensity * vec3 (0.2, 0.3, 0.4);
+
+// this is for the bare Rayleigh and Mie sky, highly altitude dependent
+color.rgb = max(color.rgb, minLight.rgb * (1.0- alt/100000.0) * (1.0 - costheta));
+
+// this is for the terrain drawn
+terrainHazeColor = max(terrainHazeColor.rgb, minLight.rgb);
+
color = mix(color, terrainHazeColor ,smoothstep(hazeBlendAngle + ctterrain, 0.0+ctterrain, ct));
@@ -228,11 +253,15 @@ color = mix(color, terrainHazeColor ,smoothstep(hazeBlendAngle + ctterrain, 0.0+
// mix fog the skydome with the right amount of haze
+// this is for the terrain drawn
+hColor = max(hColor.rgb, minLight.rgb);
+
hColor = clamp(hColor,0.0,1.0);
-//color = transmission * color + (1.0-transmission) * eqColorFactor * hColor ;
+
color = mix((eqColorFactor * hColor)+secondary_light * fog_backscatter(avisibility),color, transmission);
+
gl_FragColor = vec4(color, 1.0);
gl_FragDepth = 0.1;
}
diff --git a/Shaders/skydome-ALS.vert b/Shaders/skydome-ALS.vert
index 5d083844c..be16e6fce 100644
--- a/Shaders/skydome-ALS.vert
+++ b/Shaders/skydome-ALS.vert
@@ -12,6 +12,7 @@ uniform float terminator;
uniform float avisibility;
uniform float visibility;
uniform float terrain_alt;
+uniform float air_pollution;
varying vec3 rayleigh;
varying vec3 mie;
@@ -256,12 +257,15 @@ void main()
earthShade = 0.9 * smoothstep((terminator_width+ terminator), (-terminator_width + terminator), yprime) + 0.1;
float lightArg = (terminator-yprime)/100000.0;
- vec4 light_diffuse;
- light_diffuse.b = light_func(lightArg, 1.330e-05, 0.264, 2.527, 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 = 0.0;
- hazeColor = light_diffuse.xyz;
+
+ hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 4.827-3.0*air_pollution, 3.04e-05, 1.0);
+ hazeColor.g = light_func(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
+ hazeColor.b = light_func(lightArg, 1.330e-05, 0.264, 1.527+2.0*air_pollution, 1.08e-05, 1.0);
+
+ //new
+ //hazeColor.r = light_func(lightArg, 3.495e-05, 0.161, 3.878, 0.000129, 1.0);
+ //hazeColor.g = light_func(lightArg, 1.145e-05, 0.161, 3.827, 1.783e-05, 1.0);
+ //hazeColor.b = light_func(lightArg, 0.234, 0.141, 2.572, 0.257, 1.0);
float intensity = length(hazeColor.xyz);
float mie_magnitude = 0.5 * smoothstep(350000.0, 150000.0, terminator -sqrt(2.0 * EarthRadius * terrain_alt));
diff --git a/Shaders/terrain-ALS-base.frag b/Shaders/terrain-ALS-base.frag
index 755245a5b..07f83f420 100644
--- a/Shaders/terrain-ALS-base.frag
+++ b/Shaders/terrain-ALS-base.frag
@@ -30,52 +30,15 @@ const float terminator_width = 200000.0;
float alt;
float eShade;
+float fog_func (in float targ, in float alt);
+vec3 get_hazeColor(in float light_arg);
+
float luminance(vec3 color)
{
return dot(vec3(0.212671, 0.715160, 0.072169), color);
}
-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.0;}
-
-return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
-}
-
-// this determines how light is attenuated in the distance
-// physically this should be exp(-arg) but for technical reasons we use a sharper cutoff
-// for distance > visibility
-
-float fog_func (in float targ)
-{
-
-
-float fade_mix;
-
-// for large altitude > 30 km, we switch to some component of quadratic distance fading to
-// create the illusion of improved visibility range
-
-targ = 1.25 * targ * smoothstep(0.04,0.06,targ); // need to sync with the distance to which terrain is drawn
-
-
-if (alt < 30000.0)
- {return exp(-targ - targ * targ * targ * targ);}
-else if (alt < 50000.0)
- {
- fade_mix = (alt - 30000.0)/20000.0;
- return fade_mix * exp(-targ*targ - pow(targ,4.0)) + (1.0 - fade_mix) * exp(-targ - pow(targ,4.0));
- }
-else
- {
- return exp(- targ * targ - pow(targ,4.0));
- }
-
-}
void main()
{
@@ -208,19 +171,15 @@ else
-transmission = fog_func(transmission_arg);
+transmission = fog_func(transmission_arg, alt);
// there's always residual intensity, we should never be driven to zero
if (eqColorFactor < 0.2) eqColorFactor = 0.2;
float lightArg = (terminator-yprime_alt)/100000.0;
+vec3 hazeColor = get_hazeColor(lightArg);
-vec3 hazeColor;
-
-hazeColor.b = light_func(lightArg, 1.330e-05, 0.264, 2.527, 1.08e-05, 1.0);
-hazeColor.g = light_func(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
-hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
// now dim the light for haze
@@ -261,18 +220,22 @@ float shadow = mix( min(1.0 + dot(normal,lightDir),1.0), 1.0, 1.0-smoothstep(0.1
hazeColor = mix(shadow * hazeColor, hazeColor, 0.3 + 0.7* smoothstep(250000.0, 400000.0, terminator));
+
+
+// don't let the light fade out too rapidly
+lightArg = (terminator + 200000.0)/100000.0;
+float minLightIntensity = min(0.2,0.16 * lightArg + 0.5);
+vec3 minLight = minLightIntensity * vec3 (0.2, 0.3, 0.4);
+hazeColor *= eqColorFactor * eShade;
+hazeColor.rgb = max(hazeColor.rgb, minLight.rgb);
+
// determine the right mix of transmission and haze
+fragColor.rgb = mix(hazeColor, fragColor.rgb,transmission);
+}
-fragColor.xyz = mix(eqColorFactor * hazeColor * eShade, fragColor.xyz,transmission);
gl_FragColor = fragColor;
}
-else // if dist < 40.0 no fogging at all
-{
-gl_FragColor = fragColor;
-}
-
-}
diff --git a/Shaders/terrain-ALS-detailed.frag b/Shaders/terrain-ALS-detailed.frag
index 672cf3425..294066ca6 100644
--- a/Shaders/terrain-ALS-detailed.frag
+++ b/Shaders/terrain-ALS-detailed.frag
@@ -51,48 +51,12 @@ float mie_angle;
float Noise2D(in vec2 coord, in float wavelength);
float Noise3D(in vec3 coord, in float wavelength);
+float fog_func (in float targ, in float alt);
+vec3 get_hazeColor(in float light_arg);
-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.0;}
-
-return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
-}
-
-// this determines how light is attenuated in the distance
-// physically this should be exp(-arg) but for technical reasons we use a sharper cutoff
-// for distance > visibility
-
-float fog_func (in float targ)
-{
-float fade_mix;
-
-// for large altitude > 30 km, we switch to some component of quadratic distance fading to
-// create the illusion of improved visibility range
-
-targ = 1.25 * targ * smoothstep(0.04,0.06,targ); // need to sync with the distance to which terrain is drawn
-
-
-if (alt < 30000.0)
- {return exp(-targ - targ * targ * targ * targ);}
-else if (alt < 50000.0)
- {
- fade_mix = (alt - 30000.0)/20000.0;
- return fade_mix * exp(-targ*targ - pow(targ,4.0)) + (1.0 - fade_mix) * exp(-targ - pow(targ,4.0));
- }
-else
- {
- return exp(- targ * targ - pow(targ,4.0));
- }
-
-}
void main()
{
@@ -460,19 +424,16 @@ else
-transmission = fog_func(transmission_arg);
+transmission = fog_func(transmission_arg, alt);
// there's always residual intensity, we should never be driven to zero
if (eqColorFactor < 0.2) eqColorFactor = 0.2;
float lightArg = (terminator-yprime_alt)/100000.0;
+vec3 hazeColor = get_hazeColor(lightArg);
-vec3 hazeColor;
-hazeColor.b = light_func(lightArg, 1.330e-05, 0.264, 2.527, 1.08e-05, 1.0);
-hazeColor.g = light_func(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
-hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
// now dim the light for haze
@@ -515,12 +476,21 @@ if (intensity > 0.0) // this needs to be a condition, because otherwise hazeColo
// reduce haze intensity when looking at shaded surfaces, only in terminator region
float shadow = mix( min(1.0 + dot(n,lightDir),1.0), 1.0, 1.0-smoothstep(0.1, 0.4, transmission));
hazeColor = mix(shadow * hazeColor, hazeColor, 0.3 + 0.7* smoothstep(250000.0, 400000.0, terminator));
+
+ // don't let the light fade out too rapidly
+ lightArg = (terminator + 200000.0)/100000.0;
+ float minLightIntensity = min(0.2,0.16 * lightArg + 0.5);
+ vec3 minLight = minLightIntensity * vec3 (0.2, 0.3, 0.4);
+
+ hazeColor *= eqColorFactor * eShade;
+ hazeColor.rgb = max(hazeColor.rgb, minLight.rgb);
+
}
-fragColor.rgb = mix(eqColorFactor * hazeColor * eShade , fragColor.rgb,transmission);
+fragColor.rgb = mix(hazeColor , fragColor.rgb,transmission);
gl_FragColor = fragColor;
diff --git a/Shaders/terrain-ALS-ultra.frag b/Shaders/terrain-ALS-ultra.frag
index a68060f77..e0d063ef5 100644
--- a/Shaders/terrain-ALS-ultra.frag
+++ b/Shaders/terrain-ALS-ultra.frag
@@ -81,19 +81,11 @@ float light_distance_fading(in float dist);
float fog_backscatter(in float avisibility);
vec3 rayleigh_out_shift(in vec3 color, in float outscatter);
+vec3 get_hazeColor(in float light_arg);
vec3 searchlight();
vec3 landing_light(in float offset);
-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.0;}
-
-return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
-}
// a fade function for procedural scales which are smaller than a pixel
@@ -481,13 +473,10 @@ if ((dist < 5000.0) && (combined_wetness>0.0))
fragColor = color * texel + specular;
-
- vec3 hazeColor;
float lightArg = (terminator-yprime_alt)/100000.0;
- hazeColor.b = light_func(lightArg, 1.330e-05, 0.264, 2.527, 1.08e-05, 1.0);
- hazeColor.g = light_func(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
- hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
+ vec3 hazeColor = get_hazeColor(lightArg);
+
// Rayleigh color shift due to out-scattering
float rayleigh_length = 0.5 * avisibility * (2.5 - 1.9 * air_pollution)/alt_factor(eye_alt, eye_alt+relPos.z);
@@ -649,12 +638,18 @@ if (intensity > 0.0) // this needs to be a condition, because otherwise hazeColo
}
+// don't let the light fade out too rapidly
+lightArg = (terminator + 200000.0)/100000.0;
+float minLightIntensity = min(0.2,0.16 * lightArg + 0.5);
+vec3 minLight = minLightIntensity * vec3 (0.2, 0.3, 0.4);
+hazeColor.rgb *= eqColorFactor * eShade;
+hazeColor.rgb = max(hazeColor.rgb, minLight.rgb);
// finally, mix fog in
-fragColor.rgb = mix((eqColorFactor * hazeColor * eShade)+secondary_light * fog_backscatter(avisibility) , fragColor.rgb,transmission);
+fragColor.rgb = mix((hazeColor)+secondary_light * fog_backscatter(avisibility) , fragColor.rgb,transmission);
}
diff --git a/Shaders/urban-ALS.frag b/Shaders/urban-ALS.frag
index a8944a448..6dd77f12e 100644
--- a/Shaders/urban-ALS.frag
+++ b/Shaders/urban-ALS.frag
@@ -81,32 +81,12 @@ float light_distance_fading(in float dist);
float fog_backscatter(in float avisibility);
vec3 rayleigh_out_shift(in vec3 color, in float outscatter);
+vec3 get_hazeColor(in float light_arg);
vec3 searchlight();
vec3 landing_light(in float offset);
-
-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.0;}
-
-return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
-}
-
-// this determines how light is attenuated in the distance
-// physically this should be exp(-arg) but for technical reasons we use a sharper cutoff
-// for distance > visibility
-
-
-
-
-
-
void QDM(inout vec3 p, inout vec3 v)
{
const int MAX_LEVEL = TEXTURE_MIP_LEVELS;
@@ -349,11 +329,9 @@ if (gquality_level > 2)
float lightArg = (terminator-yprime_alt)/100000.0;
-vec3 hazeColor;
+vec3 hazeColor = get_hazeColor(lightArg);
+
-hazeColor.b = light_func(lightArg, 1.330e-05, 0.264, 2.527, 1.08e-05, 1.0);
-hazeColor.g = light_func(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
-hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
// Rayleigh color shifts
@@ -533,7 +511,15 @@ if (intensity > 0.0) // this needs to be a condition, because otherwise hazeColo
}
-finalColor.rgb = mix((eqColorFactor * hazeColor * eShade) +secondary_light * fog_backscatter(avisibility), finalColor.rgb,transmission);
+// don't let the light fade out too rapidly
+lightArg = (terminator + 200000.0)/100000.0;
+float minLightIntensity = min(0.2,0.16 * lightArg + 0.5);
+vec3 minLight = minLightIntensity * vec3 (0.2, 0.3, 0.4);
+hazeColor *= eqColorFactor * eShade;
+hazeColor.rgb = max(hazeColor.rgb, minLight.rgb);
+
+
+finalColor.rgb = mix( hazeColor +secondary_light * fog_backscatter(avisibility), finalColor.rgb,transmission);
}
diff --git a/Shaders/water-ALS-base.frag b/Shaders/water-ALS-base.frag
index 5cecaea45..ed96f3829 100644
--- a/Shaders/water-ALS-base.frag
+++ b/Shaders/water-ALS-base.frag
@@ -59,11 +59,9 @@ vec3 specular_light;
const float terminator_width = 200000.0;
const float EarthRadius = 5800000.0;
-////fog "include" /////
-//uniform int fogType;
-vec3 fog_Func(vec3 color, int type);
-//////////////////////
+float fog_func (in float targ, in float alt);
+vec3 get_hazeColor(in float light_arg);
/////// functions /////////
@@ -145,46 +143,6 @@ void sumWaves(float angle, float dangle, float windScale, float factor, out floa
}
-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.0;}
-
-return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
-}
-
-// this determines how light is attenuated in the distance
-// physically this should be exp(-arg) but for technical reasons we use a sharper cutoff
-// for distance > visibility
-
-float fog_func (in float targ)
-{
-
-
-float fade_mix;
-
-// for large altitude > 30 km, we switch to some component of quadratic distance fading to
-// create the illusion of improved visibility range
-
-targ = 1.25 * targ; // need to sync with the distance to which terrain is drawn
-
-
-if (eye_alt < 30000.0)
- {return exp(-targ - targ * targ * targ * targ);}
-else if (eye_alt < 50000.0)
- {
- fade_mix = (eye_alt - 30000.0)/20000.0;
- return fade_mix * exp(-targ*targ - pow(targ,4.0)) + (1.0 - fade_mix) * exp(-targ - pow(targ,4.0));
- }
-else
- {
- return exp(- targ * targ - pow(targ,4.0));
- }
-
-}
void main(void)
{
@@ -535,18 +493,15 @@ else
}
-transmission = fog_func(transmission_arg);
+transmission = fog_func(transmission_arg, eye_alt);
// there's always residual intensity, we should never be driven to zero
if (eqColorFactor < 0.2) eqColorFactor = 0.2;
float lightArg = (terminator-yprime_alt)/100000.0;
+vec3 hazeColor = get_hazeColor(lightArg);
-vec3 hazeColor;
-hazeColor.b = light_func(lightArg, 1.330e-05, 0.264, 2.527, 1.08e-05, 1.0);
-hazeColor.g = light_func(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
-hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
// now dim the light for haze
float eShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt);
@@ -583,9 +538,16 @@ if (intensity > 0.0) // this needs to be a condition, because otherwise hazeColo
hazeColor = intensity * normalize(mix(hazeColor, shadedFogColor, (1.0-smoothstep(0.5,0.9,eqColorFactor))));
}
-
+ // don't let the light fade out too rapidly
+ lightArg = (terminator + 200000.0)/100000.0;
+ float minLightIntensity = min(0.2,0.16 * lightArg + 0.5);
+ vec3 minLight = minLightIntensity * vec3 (0.2, 0.3, 0.4);
- finalColor.rgb = mix(eqColorFactor * hazeColor * eShade, finalColor.rgb,transmission);
+ hazeColor *= eqColorFactor * eShade;
+ hazeColor.rgb = max(hazeColor.rgb, minLight.rgb);
+
+
+ finalColor.rgb = mix(hazeColor, finalColor.rgb,transmission);
}
diff --git a/Shaders/water-ALS-high.frag b/Shaders/water-ALS-high.frag
index 468055d53..28f2439c2 100644
--- a/Shaders/water-ALS-high.frag
+++ b/Shaders/water-ALS-high.frag
@@ -88,6 +88,7 @@ float light_distance_fading(in float dist);
float fog_backscatter(in float avisibility);
vec3 rayleigh_out_shift(in vec3 color, in float outscatter);
+vec3 get_hazeColor(in float light_arg);
vec3 searchlight();
vec3 landing_light(in float offset);
@@ -521,11 +522,8 @@ void main(void)
finalColor *= vec4 (ambient_light.rgb + secondary_light * light_distance_fading(dist), ambient_light.a);
float lightArg = (terminator-yprime_alt)/100000.0;
-
- vec3 hazeColor;
- hazeColor.b = light_func(lightArg, 1.330e-05, 0.264, 2.527, 1.08e-05, 1.0);
- hazeColor.g = light_func(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
- hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
+ vec3 hazeColor = get_hazeColor(lightArg); ;
+
// Rayleigh color shift due to out-scattering
@@ -693,7 +691,15 @@ if (intensity > 0.0) // this needs to be a condition, because otherwise hazeColo
}
- finalColor.rgb = mix(eqColorFactor * hazeColor * eShade +secondary_light * fog_backscatter(avisibility), finalColor.rgb,transmission);
+ // don't let the light fade out too rapidly
+ lightArg = (terminator + 200000.0)/100000.0;
+ float minLightIntensity = min(0.2,0.16 * lightArg + 0.5);
+ vec3 minLight = minLightIntensity * vec3 (0.2, 0.3, 0.4);
+
+ hazeColor *= eqColorFactor * eShade;
+ hazeColor.rgb = max(hazeColor.rgb, minLight.rgb);
+
+ finalColor.rgb = mix(hazeColor +secondary_light * fog_backscatter(avisibility), finalColor.rgb,transmission);
}