diff --git a/Effects/agriculture.eff b/Effects/agriculture.eff
index 832f934d3..2cb59f457 100644
--- a/Effects/agriculture.eff
+++ b/Effects/agriculture.eff
@@ -79,6 +79,7 @@
0.0
0.0
1.0
+ false
@@ -238,9 +239,11 @@
Shaders/terrain-ALS-ultra.vert
- Shaders/agriculture.frag
+ Shaders/agriculture-ALS.frag
Shaders/cloud-shadowfunc.frag
- Shaders/noise.frag
+ Shaders/noise.frag
+ Shaders/hazes.frag
+ Shaders/secondary_lights.frag
grain_strength
@@ -387,6 +390,36 @@
float
+
+ air_pollution
+ float
+
+
+
+ view_pitch_offset
+ float
+
+
+
+ view_heading_offset
+ float
+
+
+
+ field_of_view
+ float
+
+
+
+ landing_light1_offset
+ float
+
+
+
+ landing_light2_offset
+ float
+
+
cloudpos1_x
float
@@ -622,6 +655,36 @@
int
+
+ use_searchlight
+ int
+
+
+
+ use_landing_light
+ int
+
+
+
+ use_alt_landing_light
+ int
+
+
+
+ display_xsize
+ int
+
+
+
+ display_ysize
+ int
+
+
+
+ raise_vertex
+ bool
+
+
texture
sampler-2d
diff --git a/Shaders/agriculture.frag b/Shaders/agriculture-ALS.frag
similarity index 88%
rename from Shaders/agriculture.frag
rename to Shaders/agriculture-ALS.frag
index 71d947780..a44a79b3d 100644
--- a/Shaders/agriculture.frag
+++ b/Shaders/agriculture-ALS.frag
@@ -38,6 +38,7 @@ uniform float fogstructure;
uniform float snow_thickness_factor;
uniform float cloud_self_shading;
uniform float season;
+uniform float air_pollution;
uniform float grain_strength;
uniform float intrinsic_wetness;
uniform float overlay_fraction;
@@ -46,6 +47,8 @@ uniform float rotation_scale;
uniform float distortion_factor;
uniform float uv_xoffset;
uniform float uv_yoffset;
+uniform float landing_light1_offset;
+uniform float landing_light2_offset;
uniform float dust_resistance;
uniform float WindE;
@@ -57,6 +60,10 @@ uniform int tquality_level;
uniform int wind_effects;
uniform int cloud_shadow_flag;
uniform int rotation_flag;
+uniform int use_searchlight;
+uniform int use_landing_light;
+uniform int use_alt_landing_light;
+
const float EarthRadius = 5800000.0;
const float terminator_width = 200000.0;
@@ -71,7 +78,15 @@ float Noise2D(in vec2 coord, in float wavelength);
float Noise3D(in vec3 coord, in float wavelength);
float VoronoiNoise2D(in vec2 coord, in float wavelength, in float xrand, in float yrand);
float SlopeLines2D(in vec2 coord, in vec2 gradDir, in float wavelength, in float steepness);
+float fog_func (in float targ, in float alt);
+float rayleigh_in_func(in float dist, in float air_pollution, in float avisibility, in float eye_alt, in float vertex_alt);
+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 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)
@@ -96,35 +111,8 @@ return 1.0 - smoothstep(0.5 * fade_dist, fade_dist, dist);
}
-// 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()
{
@@ -451,11 +439,30 @@ if ((dist < 5000.0)&& (quality_level > 3) && (combined_wetness>0.0))
// is closer to what the OpenGL fixed function pipeline does.
color = clamp(color, 0.0, 1.0);
+ vec3 secondary_light = vec3 (0.0,0.0,0.0);
+ if (use_searchlight == 1)
+ {
+ secondary_light += searchlight();
+ }
+ if (use_landing_light == 1)
+ {
+ secondary_light += landing_light(landing_light1_offset);
+ }
+ if (use_alt_landing_light == 1)
+ {
+ secondary_light += landing_light(landing_light2_offset);
+ }
+ color.rgb +=secondary_light * light_distance_fading(dist);
fragColor = color * texel + specular;
+// 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);
+ float outscatter = 1.0-exp(-dist/rayleigh_length);
+ fragColor.rgb = rayleigh_out_shift(fragColor.rgb,outscatter);
+
// here comes the terrain haze model
@@ -574,7 +581,7 @@ 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;
@@ -631,9 +638,15 @@ if (intensity > 0.0) // this needs to be a condition, because otherwise hazeColo
}
+// blue Rayleigh scattering with distance
+float rShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt-340000.0) + 0.1;
+float lightIntensity = length(diffuse_term.rgb)/1.73 * rShade;
+vec3 rayleighColor = vec3 (0.17, 0.52, 0.87) * lightIntensity;
+float rayleighStrength = rayleigh_in_func(dist, air_pollution, avisibility/max(lightIntensity,0.05), eye_alt, eye_alt + relPos.z);
+fragColor.rgb = mix(fragColor.rgb, rayleighColor,rayleighStrength);
-fragColor.rgb = mix(eqColorFactor * hazeColor * eShade , fragColor.rgb,transmission);
+fragColor.rgb = mix((eqColorFactor * hazeColor * eShade) +secondary_light * fog_backscatter(avisibility), fragColor.rgb,transmission);
gl_FragColor = fragColor;
@@ -642,6 +655,15 @@ gl_FragColor = fragColor;
}
else // if dist < threshold no fogging at all
{
+
+// blue Rayleigh scattering with distance
+
+float rShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt-340000.0) + 0.1;
+float lightIntensity = length(diffuse_term.rgb)/1.73 * rShade;
+vec3 rayleighColor = vec3 (0.17, 0.52, 0.87) * lightIntensity;
+float rayleighStrength = rayleigh_in_func(dist, air_pollution, avisibility/max(lightIntensity,0.05), eye_alt, eye_alt + relPos.z);
+fragColor.rgb = mix(fragColor.rgb, rayleighColor,rayleighStrength);
+
gl_FragColor = fragColor;
}