From dc791861d28b588b72d5190b58a9fdf87a975af3 Mon Sep 17 00:00:00 2001 From: Thorsten Renk Date: Tue, 2 Dec 2014 11:18:02 +0200 Subject: [PATCH] ALS maintenance: proper order of argument in smoothstep, night behaviour of wake, streamlining of if() statements,... --- Effects/bowwave.eff | 4 +- Shaders/agriculture-ALS.frag | 37 +++++-------------- Shaders/airfield-ALS.frag | 2 +- ...wwave_lightfield.frag => bowwave-ALS.frag} | 13 ++----- Shaders/drunway-ALS.frag | 2 +- Shaders/model-ALS-base.frag | 4 +- Shaders/rock-ALS.frag | 2 +- Shaders/runway-ALS.frag | 3 +- Shaders/terrain-ALS-base.frag | 5 +-- Shaders/terrain-ALS-detailed.frag | 3 +- Shaders/terrain-ALS-ultra.frag | 2 +- Shaders/tree-ALS.frag | 2 +- Shaders/urban-ALS.frag | 33 +++++------------ Shaders/urban-ALS.vert | 15 -------- .../{wake_lightfield.vert => wake-ALS.vert} | 0 Shaders/water-ALS-base.frag | 2 +- Shaders/water-ALS-high.frag | 4 +- 17 files changed, 38 insertions(+), 95 deletions(-) rename Shaders/{bowwave_lightfield.frag => bowwave-ALS.frag} (97%) rename Shaders/{wake_lightfield.vert => wake-ALS.vert} (100%) diff --git a/Effects/bowwave.eff b/Effects/bowwave.eff index 18e693985..2f629c372 100644 --- a/Effects/bowwave.eff +++ b/Effects/bowwave.eff @@ -379,9 +379,9 @@ - Shaders/wake_lightfield.vert + Shaders/wake-ALS.vert - Shaders/bowwave_lightfield.frag + Shaders/bowwave-ALS.frag water_reflection diff --git a/Shaders/agriculture-ALS.frag b/Shaders/agriculture-ALS.frag index a44a79b3d..2c9074313 100644 --- a/Shaders/agriculture-ALS.frag +++ b/Shaders/agriculture-ALS.frag @@ -463,14 +463,21 @@ if ((dist < 5000.0)&& (quality_level > 3) && (combined_wetness>0.0)) float outscatter = 1.0-exp(-dist/rayleigh_length); fragColor.rgb = rayleigh_out_shift(fragColor.rgb,outscatter); +// Rayleigh color shift due to in-scattering + +float rShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt-340000.0); +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); + + // here comes the terrain haze model float delta_z = hazeLayerAltitude - eye_alt; if (dist > 0.04 * min(visibility,avisibility)) -//if ((gl_FragCoord.y > ylimit) || (gl_FragCoord.x < zlimit1) || (gl_FragCoord.x > zlimit2)) -//if (dist > 40.0) { alt = eye_alt; @@ -597,7 +604,7 @@ hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0); // now dim the light for haze -eShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1; +eShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt); // Mie-like factor @@ -638,36 +645,12 @@ 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) +secondary_light * fog_backscatter(avisibility), fragColor.rgb,transmission); - -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; -} - - } diff --git a/Shaders/airfield-ALS.frag b/Shaders/airfield-ALS.frag index 7e6f10b44..16c629569 100644 --- a/Shaders/airfield-ALS.frag +++ b/Shaders/airfield-ALS.frag @@ -435,7 +435,7 @@ hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0); // now dim the light for haze -eShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1; +eShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt); // Mie-like factor diff --git a/Shaders/bowwave_lightfield.frag b/Shaders/bowwave-ALS.frag similarity index 97% rename from Shaders/bowwave_lightfield.frag rename to Shaders/bowwave-ALS.frag index 1337a8ec0..57df432e4 100644 --- a/Shaders/bowwave_lightfield.frag +++ b/Shaders/bowwave-ALS.frag @@ -287,14 +287,6 @@ void main(void) finalColor = refl + specular * smoothstep(0.3, 0.6, ground_scattering); - // cover = 0; - - /*if(cover >= 1.5){ - finalColor = refl + specular; - } else { - finalColor = refl; - }*/ - //add foam float foamSlope = 0.05 + 0.01 * windScale; @@ -309,7 +301,7 @@ void main(void) } //generate final colour - finalColor *= ambient_light+ alpha0 * 0.35; + finalColor *= ambient_light;//+ alpha0 * 0.35; @@ -420,7 +412,8 @@ 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 = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1; +float eShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt); + // Mie-like factor diff --git a/Shaders/drunway-ALS.frag b/Shaders/drunway-ALS.frag index 06ce3c1dc..2b7878657 100644 --- a/Shaders/drunway-ALS.frag +++ b/Shaders/drunway-ALS.frag @@ -399,7 +399,7 @@ hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0); // now dim the light for haze -eShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1; +eShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt); // Mie-like factor diff --git a/Shaders/model-ALS-base.frag b/Shaders/model-ALS-base.frag index 2daa906dd..34446dc58 100644 --- a/Shaders/model-ALS-base.frag +++ b/Shaders/model-ALS-base.frag @@ -93,9 +93,7 @@ void main() float effective_scattering = min(scattering, cloud_self_shading); - - - eShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1; + eShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt); vec4 light_specular = gl_LightSource[0].specular * (eShade - 0.1); // If gl_Color.a == 0, this is a back-facing polygon and the diff --git a/Shaders/rock-ALS.frag b/Shaders/rock-ALS.frag index dd8a389c3..9981d531a 100755 --- a/Shaders/rock-ALS.frag +++ b/Shaders/rock-ALS.frag @@ -601,7 +601,7 @@ hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0); // now dim the light for haze -eShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1; +eShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt); // Mie-like factor diff --git a/Shaders/runway-ALS.frag b/Shaders/runway-ALS.frag index ea70494f7..ad7595611 100644 --- a/Shaders/runway-ALS.frag +++ b/Shaders/runway-ALS.frag @@ -224,8 +224,7 @@ if ((dist < 5000.0)&& (quality_level > 3) && (wetness>0.0)) // light computations - - eShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1; + eShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt); vec4 light_specular = gl_LightSource[0].specular * eShade; // If gl_Color.a == 0, this is a back-facing polygon and the diff --git a/Shaders/terrain-ALS-base.frag b/Shaders/terrain-ALS-base.frag index aa5af160f..755245a5b 100644 --- a/Shaders/terrain-ALS-base.frag +++ b/Shaders/terrain-ALS-base.frag @@ -17,12 +17,10 @@ varying float mie_angle; uniform float visibility; uniform float avisibility; uniform float scattering; -//uniform float ground_scattering; uniform float terminator; uniform float terrain_alt; uniform float hazeLayerAltitude; uniform float overcast; -//uniform float altitude; uniform float eye_alt; uniform float cloud_self_shading; @@ -226,8 +224,7 @@ hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0); // now dim the light for haze - -eShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1; +eShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt); // Mie-like factor diff --git a/Shaders/terrain-ALS-detailed.frag b/Shaders/terrain-ALS-detailed.frag index 6f09a699b..672cf3425 100644 --- a/Shaders/terrain-ALS-detailed.frag +++ b/Shaders/terrain-ALS-detailed.frag @@ -476,7 +476,8 @@ hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0); // now dim the light for haze -eShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1; +eShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt); + // Mie-like factor diff --git a/Shaders/terrain-ALS-ultra.frag b/Shaders/terrain-ALS-ultra.frag index 43c7953ea..79c6902ff 100644 --- a/Shaders/terrain-ALS-ultra.frag +++ b/Shaders/terrain-ALS-ultra.frag @@ -598,7 +598,7 @@ hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0); // now dim the light for haze -eShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1; +eShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt); // Mie-like factor diff --git a/Shaders/tree-ALS.frag b/Shaders/tree-ALS.frag index 4ce9e1ab6..c6befd8ae 100644 --- a/Shaders/tree-ALS.frag +++ b/Shaders/tree-ALS.frag @@ -314,7 +314,7 @@ 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 = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1; +float eShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt); // Mie-like factor diff --git a/Shaders/urban-ALS.frag b/Shaders/urban-ALS.frag index b39700e1a..56be23d73 100644 --- a/Shaders/urban-ALS.frag +++ b/Shaders/urban-ALS.frag @@ -348,6 +348,14 @@ if (quality_level > 2) float outscatter = 1.0-exp(-dist/rayleigh_length); finalColor.rgb = rayleigh_out_shift(finalColor.rgb,outscatter); +// Rayleigh color shift due to in-scattering + + float rShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt-340000.0); + float lightIntensity = length(light_diffuse.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); + finalColor.rgb = mix(finalColor.rgb, rayleighColor,rayleighStrength); + // here comes the terrain haze model @@ -468,7 +476,7 @@ hazeColor.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0); // now dim the light for haze -eShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1; +eShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt); // Mie-like factor @@ -517,35 +525,14 @@ 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(light_diffuse.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); -finalColor.rgb = mix(finalColor.rgb, rayleighColor,rayleighStrength); - - finalColor.rgb = mix((eqColorFactor * hazeColor * eShade) +secondary_light * fog_backscatter(avisibility), finalColor.rgb,transmission); -gl_FragColor = finalColor; } -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(light_diffuse.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); -finalColor.rgb = mix(finalColor.rgb, rayleighColor,rayleighStrength); + gl_FragColor = finalColor; -} - - - // gl_FragColor = finalColor; if (dot(normal,-V) > 0.1) { vec4 iproj = gl_ProjectionMatrix * p; diff --git a/Shaders/urban-ALS.vert b/Shaders/urban-ALS.vert index e8af40a04..ef47f4fdf 100644 --- a/Shaders/urban-ALS.vert +++ b/Shaders/urban-ALS.vert @@ -143,16 +143,6 @@ void main() // early culling of vertices which can't be seen due to ground haze despite being in aloft visibility range float delta_z = hazeLayerAltitude - eye_alt; -//if (((dist * (relPos.z - delta_z)/relPos.z > visibility ) && (relPos.z < 0.0) && (delta_z < 0.0) && (dist > 30000.0))) -if (0==1) - { - gl_Position = vec4(0.0, 0.0, -1000.0, 1.0); // move outside of view frustrum, gets culled before reaching fragment shader - earthShade = 1.0; - mie_angle = 1.0; - yprime_alt = 0.0; - } -else - { // branch dependent on daytime @@ -284,11 +274,6 @@ float shade_depth = 1.0 * smoothstep (0.6,0.95,ground_scattering) * (1.0-smooth constantColor = gl_FrontMaterial.emission + gl_Color * (gl_LightModel.ambient + light_ambient); - - - - -} } diff --git a/Shaders/wake_lightfield.vert b/Shaders/wake-ALS.vert similarity index 100% rename from Shaders/wake_lightfield.vert rename to Shaders/wake-ALS.vert diff --git a/Shaders/water-ALS-base.frag b/Shaders/water-ALS-base.frag index f27fee810..5cecaea45 100644 --- a/Shaders/water-ALS-base.frag +++ b/Shaders/water-ALS-base.frag @@ -549,7 +549,7 @@ 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 = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1; +float eShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt); // Mie-like factor diff --git a/Shaders/water-ALS-high.frag b/Shaders/water-ALS-high.frag index dd33fa61b..efe9354f9 100644 --- a/Shaders/water-ALS-high.frag +++ b/Shaders/water-ALS-high.frag @@ -535,7 +535,7 @@ void main(void) // Rayleigh color shift due to in-scattering -float rShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt-340000.0) + 0.1; + float rShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt-340000.0); float lightIntensity = length(gl_Color.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); @@ -653,7 +653,7 @@ 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 = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1; +float eShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt); // Mie-like factor