1
0
Fork 0

ALS maintenance, haze color balance at low light improved and dependent on air pollution

This commit is contained in:
Thorsten Renk 2014-12-11 13:02:40 +02:00
parent b1e356e538
commit f2c81c9dcb
20 changed files with 223 additions and 272 deletions

View file

@ -58,7 +58,7 @@
<wrap-t>clamp</wrap-t>-->
</texture-unit>
<program>
<vertex-shader>Shaders/cloud-impostor-lightfield.vert</vertex-shader>
<vertex-shader>Shaders/cloud-impostor-ALS.vert</vertex-shader>
<fragment-shader>Shaders/cloud-static-lightfield.frag</fragment-shader>
</program>
<uniform>

View file

@ -25,6 +25,7 @@
<use_alt_landing_light><use>/sim/rendering/als-secondary-lights/use-alt-landing-light</use></use_alt_landing_light>
<landing_light1_offset><use>/sim/rendering/als-secondary-lights/landing-light1-offset-deg</use></landing_light1_offset>
<landing_light2_offset><use>/sim/rendering/als-secondary-lights/landing-light2-offset-deg</use></landing_light2_offset>
<air_pollution><use>/environment/air-pollution-norm</use></air_pollution>
</parameters>
<technique n="8">
<predicate>
@ -115,6 +116,11 @@
<type>float</type>
<value><use>cloud_self_shading</use></value>
</uniform>
<uniform>
<name>air_pollution</name>
<type>float</type>
<value><use>air_pollution</use></value>
</uniform>
<uniform>
<name>horizon_roughness</name>
<type>float</type>

View file

@ -876,6 +876,7 @@
<vertex-shader>Shaders/terrain-ALS-detailed.vert</vertex-shader>
<fragment-shader>Shaders/terrain-ALS-detailed.frag</fragment-shader>
<fragment-shader>Shaders/noise.frag</fragment-shader>
<fragment-shader>Shaders/hazes.frag</fragment-shader>
</program>
<uniform>
<name>visibility</name>
@ -967,6 +968,11 @@
<type>float</type>
<value><use>cloud_self_shading</use></value>
</uniform>
<uniform>
<name>air_pollution</name>
<type>float</type>
<value><use>air_pollution</use></value>
</uniform>
<uniform>
<name>moonlight</name>
<type>float</type>
@ -1103,6 +1109,7 @@
<program>
<vertex-shader>Shaders/generic-ALS-base.vert</vertex-shader>
<fragment-shader>Shaders/terrain-ALS-base.frag</fragment-shader>
<fragment-shader>Shaders/hazes.frag</fragment-shader>
</program>
<uniform>
<name>visibility</name>
@ -1159,6 +1166,11 @@
<type>float</type>
<value><use>moonlight</use></value>
</uniform>
<uniform>
<name>air_pollution</name>
<type>float</type>
<value><use>air_pollution</use></value>
</uniform>
<uniform>
<name>texture</name>
<type>sampler-2d</type>

View file

@ -1051,6 +1051,7 @@
<program>
<vertex-shader>Shaders/water-ALS.vert</vertex-shader>
<fragment-shader>Shaders/water-ALS-base.frag</fragment-shader>
<fragment-shader>Shaders/hazes.frag</fragment-shader>
</program>
<!--<uniform>
<name>water_reflection</name>
@ -1221,6 +1222,11 @@
<type>float</type>
<value><use>cloud_self_shading</use></value>
</uniform>
<uniform>
<name>air_pollution</name>
<type>float</type>
<value><use>air_pollution</use></value>
</uniform>
<!-- sea colors -->
<uniform>
<name>sea_r</name>

View file

@ -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

View file

@ -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);

View file

@ -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)

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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);

View file

@ -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;
}

View file

@ -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);

View file

@ -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;
}

View file

@ -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));

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}