3 // written by Thorsten Renk, Oct 2011, based on default.frag
4 // Ambient term comes in gl_Color.rgb.
5 varying vec4 diffuse_term;
10 //varying vec2 worldPos;
11 varying vec3 ecViewdir;
12 varying vec3 ecNormal;
15 uniform sampler2D texture;
16 uniform sampler3D NoiseTex;
17 uniform sampler2D snow_texture;
18 uniform sampler2D detail_texture;
19 uniform sampler2D mix_texture;
20 uniform sampler2D grain_texture;
21 uniform sampler2D dot_texture;
22 uniform sampler2D gradient_texture;
23 //uniform sampler2D foam_texture;
26 //varying float yprime_alt;
27 //varying float mie_angle;
28 varying float steepness;
29 varying float grad_dir;
32 uniform float visibility;
33 uniform float avisibility;
34 uniform float scattering;
35 uniform float terminator;
36 uniform float terrain_alt;
37 uniform float hazeLayerAltitude;
38 uniform float overcast;
39 uniform float eye_alt;
40 uniform float snowlevel;
41 uniform float dust_cover_factor;
42 uniform float lichen_cover_factor;
43 uniform float wetness;
44 uniform float fogstructure;
45 uniform float snow_thickness_factor;
46 uniform float cloud_self_shading;
48 uniform float windspeed;
49 uniform float grain_strength;
50 uniform float intrinsic_wetness;
51 uniform float transition_model;
52 uniform float hires_overlay_bias;
53 uniform float dot_density;
54 uniform float dot_size;
55 uniform float dust_resistance;
56 uniform float osg_SimulationTime;
57 uniform int quality_level;
58 uniform int tquality_level;
60 const float EarthRadius = 5800000.0;
61 const float terminator_width = 200000.0;
70 float rand2D(in vec2 co){
71 return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
74 float cosine_interpolate(in float a, in float b, in float x)
76 float ft = x * 3.1415927;
77 float f = (1.0 - cos(ft)) * .5;
79 return a*(1.0-f) + b*f;
82 float simple_interpolate(in float a, in float b, in float x)
84 return a + smoothstep(0.0,1.0,x) * (b-a);
87 float interpolatedNoise2D(in float x, in float y)
89 float integer_x = x - fract(x);
90 float fractional_x = x - integer_x;
92 float integer_y = y - fract(y);
93 float fractional_y = y - integer_y;
95 float v1 = rand2D(vec2(integer_x, integer_y));
96 float v2 = rand2D(vec2(integer_x+1.0, integer_y));
97 float v3 = rand2D(vec2(integer_x, integer_y+1.0));
98 float v4 = rand2D(vec2(integer_x+1.0, integer_y +1.0));
100 float i1 = simple_interpolate(v1 , v2 , fractional_x);
101 float i2 = simple_interpolate(v3 , v4 , fractional_x);
103 return simple_interpolate(i1 , i2 , fractional_y);
108 float Noise2D(in vec2 coord, in float wavelength)
110 return interpolatedNoise2D(coord.x/wavelength, coord.y/wavelength);
114 float dotNoise2D(in float x, in float y, in float fractionalMaxDotSize)
116 float integer_x = x - fract(x);
117 float fractional_x = x - integer_x;
119 float integer_y = y - fract(y);
120 float fractional_y = y - integer_y;
122 if (rand2D(vec2(integer_x+1.0, integer_y +1.0)) > dot_density)
125 float xoffset = (rand2D(vec2(integer_x, integer_y)) -0.5);
126 float yoffset = (rand2D(vec2(integer_x+1.0, integer_y)) - 0.5);
127 float dotSize = 0.5 * fractionalMaxDotSize * max(0.25,rand2D(vec2(integer_x, integer_y+1.0)));
130 vec2 truePos = vec2 (0.5 + xoffset * (1.0 - 2.0 * dotSize) , 0.5 + yoffset * (1.0 -2.0 * dotSize));
132 float distance = length(truePos - vec2(fractional_x, fractional_y));
134 return 1.0 - smoothstep (0.3 * dotSize, 1.0* dotSize, distance);
137 float DotNoise2D(in vec2 coord, in float wavelength, in float fractionalMaxDotSize)
139 return dotNoise2D(coord.x/wavelength, coord.y/wavelength, fractionalMaxDotSize);
144 float light_func (in float x, in float a, in float b, in float c, in float d, in float e)
148 // use the asymptotics to shorten computations
149 if (x > 30.0) {return e;}
150 if (x < -15.0) {return 0.0;}
152 return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
156 // a fade function for procedural scales which are smaller than a pixel
158 float detail_fade (in float scale, in float angle, in float dist)
160 float fade_dist = 2000.0 * scale * angle/max(pow(steepness,4.0), 0.1);
162 return 1.0 - smoothstep(0.5 * fade_dist, fade_dist, dist);
166 // this determines how light is attenuated in the distance
167 // physically this should be exp(-arg) but for technical reasons we use a sharper cutoff
168 // for distance > visibility
170 float fog_func (in float targ)
176 // for large altitude > 30 km, we switch to some component of quadratic distance fading to
177 // create the illusion of improved visibility range
179 targ = 1.25 * targ * smoothstep(0.04,0.06,targ); // need to sync with the distance to which terrain is drawn
183 {return exp(-targ - targ * targ * targ * targ);}
184 else if (alt < 50000.0)
186 fade_mix = (alt - 30000.0)/20000.0;
187 return fade_mix * exp(-targ*targ - pow(targ,4.0)) + (1.0 - fade_mix) * exp(-targ - pow(targ,4.0));
191 return exp(- targ * targ - pow(targ,4.0));
200 yprime_alt = diffuse_term.a;
201 //diffuse_term.a = 1.0;
202 mie_angle = gl_Color.a;
203 float effective_scattering = min(scattering, cloud_self_shading);
205 // distance to fragment
206 float dist = length(relPos);
207 // angle of view vector with horizon
208 float ct = dot(vec3(0.0, 0.0, 1.0), relPos)/dist;
209 // float altitude of fragment above sea level
210 float msl_altitude = (relPos.z + eye_alt);
213 vec3 shadedFogColor = vec3(0.65, 0.67, 0.78);
214 // this is taken from default.frag
216 float NdotL, NdotHV, fogFactor;
217 vec4 color = gl_Color;
219 vec3 lightDir = gl_LightSource[0].position.xyz;
220 vec3 halfVector = normalize(normalize(lightDir) + normalize(ecViewdir));
230 vec4 specular = vec4(0.0);
234 // get noise at different wavelengths
236 // used: 5m, 5m gradient, 10m, 10m gradient: heightmap of the closeup terrain, 10m also snow
238 // 250m: detail texel
239 // 500m: distortion and overlay
240 // 1500m: overlay, detail, dust, fog
241 // 2000m: overlay, detail, snow, fog
245 float noise_10m = Noise2D(rawPos.xy, 10.0);
246 float noise_5m = Noise2D(rawPos.xy ,5.0);
247 float noise_2m = Noise2D(rawPos.xy ,2.0);
248 float noise_1m = Noise2D(rawPos.xy ,1.0);
249 float noise_01m = Noise2D(rawPos.xy, 0.1);
258 float noise_25m = Noise2D(rawPos.xy, 25.0);
259 float noise_50m = Noise2D(rawPos.xy, 50.0);
262 float noise_250m = Noise2D(rawPos.xy,250.0);
263 float noise_500m = Noise2D(rawPos.xy, 500.0);
264 float noise_1500m = Noise2D(rawPos.xy, 1500.0);
265 float noise_2000m = Noise2D(rawPos.xy, 2000.0);
269 float dotnoise_2m = DotNoise2D(rawPos.xy, 2.0 * dot_size,0.5);
270 float dotnoise_10m = DotNoise2D(rawPos.xy, 10.0 * dot_size, 0.5);
271 float dotnoise_15m = DotNoise2D(rawPos.xy, 15.0 * dot_size, 0.33);
273 float dotnoisegrad_10m;
279 float distortion_factor = 1.0;
286 texel = texture2D(texture, gl_TexCoord[0].st);
287 float local_autumn_factor = texel.a;
288 grain_texel = texture2D(grain_texture, gl_TexCoord[0].st * 25.0);
289 gradient_texel = texture2D(gradient_texture, gl_TexCoord[0].st * 4.0);
291 stprime = gl_TexCoord[0].st * 80.0;
292 stprime = stprime + normalize(relPos).xy * 0.01 * (dotnoise_10m + dotnoise_15m);
293 dot_texel = texture2D(dot_texture, vec2 (stprime.y, stprime.x) );
295 // we need to fade procedural structures when they get smaller than a single pixel, for this we need
296 // to know under what angle we see the surface
298 float view_angle = abs(dot(normalize(normal), normalize(ecViewdir)));
299 float sfactor = sqrt(2.0 * (1.0-steepness)/0.03) + abs(ct)/0.15;
301 // the snow texel is generated procedurally
302 if (msl_altitude +500.0 > snowlevel)
304 snow_texel = vec4 (0.95, 0.95, 0.95, 1.0) * (0.9 + 0.1* noise_500m + 0.1* (1.0 - noise_10m) );
305 snow_texel.r = snow_texel.r * (0.9 + 0.05 * (noise_10m + noise_5m));
306 snow_texel.g = snow_texel.g * (0.9 + 0.05 * (noise_10m + noise_5m));
308 noise_term = 0.1 * (noise_500m-0.5) ;
309 noise_term = noise_term + 0.2 * (noise_50m -0.5) * detail_fade(50.0, view_angle, 0.5*dist) ;
310 noise_term = noise_term + 0.2 * (noise_25m -0.5) * detail_fade(25.0, view_angle, 0.5*dist) ;
311 noise_term = noise_term + 0.3 * (noise_10m -0.5) * detail_fade(10.0, view_angle, 0.8*dist) ;
312 noise_term = noise_term + 0.3 * (noise_5m - 0.5) * detail_fade(5.0, view_angle, dist);
313 noise_term = noise_term + 0.15 * (noise_2m -0.5) * detail_fade(2.0, view_angle, dist);
314 noise_term = noise_term + 0.08 * (noise_1m -0.5) * detail_fade(1.0, view_angle, dist);
315 snow_texel.a = snow_texel.a * 0.2+0.8* smoothstep(0.2,0.8, 0.3 +noise_term + snow_thickness_factor +0.0001*(msl_altitude -snowlevel) );
318 // the mixture/gradient texture
319 mix_texel = texture2D(mix_texture, gl_TexCoord[0].st * 1.3);
320 if (mix_texel.a <0.1) {mix_flag = 0;}
322 // the hires overlay texture is loaded with parallax mapping
324 stprime = vec2 (0.86*gl_TexCoord[0].s + 0.5*gl_TexCoord[0].t, 0.5*gl_TexCoord[0].s - 0.86*gl_TexCoord[0].t);
325 distortion_factor = 0.97 + 0.06 * noise_500m;
326 stprime = stprime * distortion_factor * 15.0;
327 stprime = stprime + normalize(relPos).xy * 0.022 * (noise_10m + 0.5 * noise_5m +0.25 * noise_2m - 0.875 );
329 detail_texel = texture2D(detail_texture, stprime);
330 if (detail_texel.a <0.1) {flag = 0;}
334 // texture preparation according to detail level
336 // mix in hires texture patches
342 // first the second texture overlay
343 // transition model 0: random patch overlay without any gradient information
344 // transition model 1: only gradient-driven transitions, no randomness
349 nSum = 0.18 * (2.0 * noise_2000m + 2.0 * noise_1500m + noise_500m);
350 nSum = mix(nSum, 0.5, max(0.0, 2.0 * (transition_model - 0.5)));
351 nSum = nSum + 0.4 * (1.0 -smoothstep(0.9,0.95, abs(steepness)+ 0.05 * (noise_50m - 0.5))) * min(1.0, 2.0 * transition_model);
352 mix_factor = smoothstep(0.5, 0.54, nSum);
353 texel = mix(texel, mix_texel, mix_factor);
354 local_autumn_factor = texel.a;
357 // then the detail texture overlay
364 dist_fact = 0.1 * smoothstep(15000.0,40000.0, dist) - 0.03 * (1.0 - smoothstep(500.0,5000.0, dist));
365 nSum = ((1.0 -noise_2000m) + noise_1500m + 2.0 * noise_250m +noise_50m)/5.0;
366 nSum = nSum - 0.08 * (1.0 -smoothstep(0.9,0.95, abs(steepness)));
367 mix_factor = smoothstep(0.47, 0.54, nSum +hires_overlay_bias- dist_fact);
368 if (mix_factor > 0.8) {mix_factor = 0.8;}
369 texel = mix(texel, detail_texel,mix_factor);
373 // rock for very steep gradients
375 if (gradient_texel.a > 0.0)
377 texel = mix(texel, gradient_texel, 1.0 - smoothstep(0.75,0.8,abs(steepness)+ 0.00002* msl_altitude + 0.05 * (noise_50m - 0.5)));
378 local_autumn_factor = texel.a;
381 // the dot vegetation texture overlay
383 texel.rgb = mix(texel.rgb, dot_texel.rgb, dot_texel.a * (dotnoise_10m + dotnoise_15m) * detail_fade(1.0 * (dot_size * (1.0 +0.1*dot_size)), view_angle,dist));
384 texel.rgb = mix(texel.rgb, dot_texel.rgb, dot_texel.a * dotnoise_2m * detail_fade(0.1 * dot_size, view_angle,dist));
387 // then the grain texture overlay
389 texel.rgb = mix(texel.rgb, grain_texel.rgb, grain_strength * grain_texel.a * (1.0 - mix_factor) * (1.0-smoothstep(2000.0,5000.0, dist)));
391 // for really hires, add procedural noise overlay
392 texel.rgb = texel.rgb * (1.0 + 0.4 * (noise_01m-0.5) * detail_fade(0.1, view_angle, dist)) ;
396 float autumn_factor = season * 2.0 * (1.0 - local_autumn_factor) ;
399 texel.r = min(1.0, (1.0 + 2.5 * autumn_factor) * texel.r);
401 texel.b = max(0.0, (1.0 - 4.0 * autumn_factor) * texel.b);
404 if (local_autumn_factor < 1.0)
406 intensity = length(texel.rgb) * (1.0 - 0.5 * smoothstep(1.1,2.0,season));
407 texel.rgb = intensity * normalize(mix(texel.rgb, vec3(0.23,0.17,0.08), smoothstep(1.1,2.0, season)));
410 //const vec4 dust_color = vec4 (0.76, 0.71, 0.56, 1.0);
411 const vec4 dust_color = vec4 (0.76, 0.65, 0.45, 1.0);
412 const vec4 lichen_color = vec4 (0.17, 0.20, 0.06, 1.0);
415 float gradient_factor = smoothstep(0.5, 1.0, steepness);
416 texel = mix(texel, lichen_color, gradient_factor * (0.4 * lichen_cover_factor + 0.8 * lichen_cover_factor * 0.5 * (noise_10m + (1.0 - noise_5m))) );
418 texel = mix(texel, dust_color, clamp(0.5 * dust_cover_factor *dust_resistance + 3.0 * dust_cover_factor * dust_resistance *(((noise_1500m - 0.5) * 0.125)+0.125 ),0.0, 1.0) );
420 float snow_mix_factor = 0.0;
421 if (msl_altitude +500.0 > snowlevel)
423 snow_alpha = smoothstep(0.75, 0.85, abs(steepness));
424 snow_mix_factor = snow_texel.a* smoothstep(snowlevel, snowlevel+200.0, snow_alpha * msl_altitude+ (noise_2000m + 0.1 * noise_10m -0.55) *400.0);
425 texel = mix(texel, snow_texel, snow_mix_factor);
431 // get distribution of water when terrain is wet
433 float combined_wetness = min(1.0, wetness + intrinsic_wetness);
434 float water_threshold1;
435 float water_threshold2;
436 float water_factor =0.0;
439 if ((dist < 5000.0)&& (quality_level > 3) && (combined_wetness>0.0))
441 water_threshold1 = 1.0-0.5* combined_wetness;
442 water_threshold2 = 1.0 - 0.3 * combined_wetness;
443 water_factor = smoothstep(water_threshold1, water_threshold2 , (0.3 * (2.0 * (1.0-noise_10m) + (1.0 -noise_5m)) * (1.0 - smoothstep(2000.0, 5000.0, dist))) - 5.0 * (1.0 -steepness));
446 // darken wet terrain
448 texel.rgb = texel.rgb * (1.0 - 0.6 * combined_wetness);
450 // surf - terrain is too bad...
451 /* foam_texel.rgb =vec3 (1.0, 1.0, 1.0);
452 foam_texel.rg = 0.7 * foam_texel.rg +0.3 * noise_2m * foam_texel.rg;
453 float surf_strength = 1.0 + windspeed/5.0;
454 float surf_sine = sin(osg_SimulationTime+5.0*noise_25m);
455 float surf_steepcorr = 1.0 -smoothstep(0.99,1.01,abs(steepness));
456 float surf_alt = (relPos.z+eye_alt ) - 20.0 * surf_steepcorr ;//+ noise_10m * surf_steepcorr
457 texel.rgb = mix(foam_texel.rgb, texel.rgb, smoothstep((0.3 +0.3*surf_strength+ surf_sine) * surf_steepcorr-20.0, (0.3+ surf_strength + surf_sine) * surf_steepcorr-19.0, surf_alt));
460 // light computations
463 vec4 light_specular = gl_LightSource[0].specular;
465 // If gl_Color.a == 0, this is a back-facing polygon and the
466 // normal should be reversed.
467 //n = (2.0 * gl_Color.a - 1.0) * normal;
468 n = normal;//vec3 (nvec.x, nvec.y, sqrt(1.0 -pow(nvec.x,2.0) - pow(nvec.y,2.0) ));
471 NdotL = dot(n, lightDir);
473 noisegrad_10m = (noise_10m - Noise2D(rawPos.xy+ 0.05 * normalize(lightDir.xy),10.0))/0.05;
474 noisegrad_5m = (noise_5m - Noise2D(rawPos.xy+ 0.05 * normalize(lightDir.xy),5.0))/0.05;
475 noisegrad_2m = (noise_2m - Noise2D(rawPos.xy+ 0.05 * normalize(lightDir.xy),2.0))/0.05;
476 noisegrad_1m = (noise_1m - Noise2D(rawPos.xy+ 0.05 * normalize(lightDir.xy),1.0))/0.05;
478 dotnoisegrad_10m = (dotnoise_10m - DotNoise2D(rawPos.xy+ 0.05 * normalize(lightDir.xy),10.0 * dot_size,0.5))/0.05;
481 NdotL = NdotL + (noisegrad_10m * detail_fade(10.0, view_angle,dist) + 0.5* noisegrad_5m * detail_fade(5.0, view_angle,dist)) * mix_factor/0.8;
482 NdotL = NdotL + 0.15 * noisegrad_2m * mix_factor/0.8 * detail_fade(2.0,view_angle,dist);
483 NdotL = NdotL + 0.1 * noisegrad_2m * detail_fade(2.0,view_angle,dist);
484 NdotL = NdotL + 0.05 * noisegrad_1m * detail_fade(1.0, view_angle,dist);
485 NdotL = NdotL + (1.0-snow_mix_factor) * 0.3* dot_texel.a * (0.5* dotnoisegrad_10m * detail_fade(1.0 * dot_size, view_angle, dist) +0.5 * dotnoisegrad_10m * noise_01m * detail_fade(0.1, view_angle, dist)) ;
488 color += diffuse_term * NdotL;
489 NdotHV = max(dot(n, halfVector), 0.0);
490 if (gl_FrontMaterial.shininess > 0.0)
491 specular.rgb = ((gl_FrontMaterial.specular.rgb + (water_factor * vec3 (1.0, 1.0, 1.0)))
493 * pow(NdotHV, gl_FrontMaterial.shininess + (20.0 * water_factor)));
495 color.a = 1.0;//diffuse_term.a;
496 // This shouldn't be necessary, but our lighting becomes very
497 // saturated. Clamping the color before modulating by the texture
498 // is closer to what the OpenGL fixed function pipeline does.
499 color = clamp(color, 0.0, 1.0);
504 fragColor = color * texel + specular;
506 // here comes the terrain haze model
509 float delta_z = hazeLayerAltitude - eye_alt;
511 if (dist > max(40.0, 0.04 * min(visibility,avisibility)))
512 //if ((gl_FragCoord.y > ylimit) || (gl_FragCoord.x < zlimit1) || (gl_FragCoord.x > zlimit2))
523 float distance_in_layer;
524 float transmission_arg;
529 // we solve the geometry what part of the light path is attenuated normally and what is through the haze layer
531 if (delta_z > 0.0) // we're inside the layer
533 if (ct < 0.0) // we look down
535 distance_in_layer = dist;
536 vAltitude = min(distance_in_layer,min(visibility, avisibility)) * ct;
537 delta_zv = delta_z - vAltitude;
539 else // we may look through upper layer edge
542 if (H > delta_z) {distance_in_layer = dist/H * delta_z;}
543 else {distance_in_layer = dist;}
544 vAltitude = min(distance_in_layer,visibility) * ct;
545 delta_zv = delta_z - vAltitude;
548 else // we see the layer from above, delta_z < 0.0
551 if (H < (-delta_z)) // we don't see into the layer at all, aloft visibility is the only fading
553 distance_in_layer = 0.0;
558 vAltitude = H + delta_z;
559 distance_in_layer = vAltitude/H * dist;
560 vAltitude = min(distance_in_layer,visibility) * (-ct);
561 delta_zv = vAltitude;
566 // ground haze cannot be thinner than aloft visibility in the model,
567 // so we need to use aloft visibility otherwise
570 transmission_arg = (dist-distance_in_layer)/avisibility;
577 if (visibility < avisibility)
579 if (quality_level > 3)
581 transmission_arg = transmission_arg + (distance_in_layer/(1.0 * visibility + 1.0 * visibility * fogstructure * 0.06 * (noise_1500m + noise_2000m -1.0) ));
586 transmission_arg = transmission_arg + (distance_in_layer/visibility);
588 // this combines the Weber-Fechner intensity
589 eqColorFactor = 1.0 - 0.1 * delta_zv/visibility - (1.0 - effective_scattering);
594 if (quality_level > 3)
596 transmission_arg = transmission_arg + (distance_in_layer/(1.0 * avisibility + 1.0 * avisibility * fogstructure * 0.06 * (noise_1500m + noise_2000m - 1.0) ));
600 transmission_arg = transmission_arg + (distance_in_layer/avisibility);
602 // this combines the Weber-Fechner intensity
603 eqColorFactor = 1.0 - 0.1 * delta_zv/avisibility - (1.0 - effective_scattering);
608 transmission = fog_func(transmission_arg);
610 // there's always residual intensity, we should never be driven to zero
611 if (eqColorFactor < 0.2) eqColorFactor = 0.2;
614 float lightArg = (terminator-yprime_alt)/100000.0;
618 hazeColor.b = light_func(lightArg, 1.330e-05, 0.264, 2.527, 1.08e-05, 1.0);
619 hazeColor.g = light_func(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
620 hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
623 // now dim the light for haze
624 eShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1;
630 intensity = length(hazeColor);
631 float mie_magnitude = 0.5 * smoothstep(350000.0, 150000.0, terminator-sqrt(2.0 * EarthRadius * terrain_alt));
632 hazeColor = intensity * ((1.0 - mie_magnitude) + mie_magnitude * mie_angle) * normalize(mix(hazeColor, vec3 (0.5, 0.58, 0.65), mie_magnitude * (0.5 - 0.5 * mie_angle)) );
635 intensity = length(hazeColor);
637 if (intensity > 0.0) // this needs to be a condition, because otherwise hazeColor doesn't come out correctly
641 // high altitude desaturation of the haze color
642 hazeColor = intensity * normalize (mix(hazeColor, intensity * vec3 (1.0,1.0,1.0), 0.7* smoothstep(5000.0, 50000.0, alt)));
645 hazeColor.x = hazeColor.x * 0.83;
646 hazeColor.y = hazeColor.y * 0.9;
649 // additional blue in indirect light
650 float fade_out = max(0.65 - 0.3 *overcast, 0.45);
651 intensity = length(hazeColor);
652 hazeColor = intensity * normalize(mix(hazeColor, 1.5* shadedFogColor, 1.0 -smoothstep(0.25, fade_out,eShade) ));
654 // change haze color to blue hue for strong fogging
655 hazeColor = intensity * normalize(mix(hazeColor, shadedFogColor, (1.0-smoothstep(0.5,0.9,eqColorFactor))));
659 // reduce haze intensity when looking at shaded surfaces, only in terminator region
660 float shadow = mix( min(1.0 + dot(n,lightDir),1.0), 1.0, 1.0-smoothstep(0.1, 0.4, transmission));
661 hazeColor = mix(shadow * hazeColor, hazeColor, 0.3 + 0.7* smoothstep(250000.0, 400000.0, terminator));
667 fragColor.rgb = mix(eqColorFactor * hazeColor * eShade , fragColor.rgb,transmission);
670 gl_FragColor = fragColor;
674 else // if dist < threshold no fogging at all
676 gl_FragColor = fragColor;