diff --git a/Effects/skydome.eff b/Effects/skydome.eff index f1d2fb625..4d4824113 100644 --- a/Effects/skydome.eff +++ b/Effects/skydome.eff @@ -15,6 +15,16 @@ /environment/mean-terrain-elevation-m /environment/cloud-self-shading /local-weather/config/small-scale-persistence + /sim/startup/xsize + /sim/startup/ysize + /sim/current-view/pitch-offset-deg + /sim/current-view/heading-offset-deg + /sim/current-view/field-of-view + /sim/rendering/als-secondary-lights/use-searchlight + /sim/rendering/als-secondary-lights/use-landing-light + /sim/rendering/als-secondary-lights/use-alt-landing-light + /sim/rendering/als-secondary-lights/landing-light1-offset-deg + /sim/rendering/als-secondary-lights/landing-light2-offset-deg @@ -40,8 +50,10 @@ smooth back - Shaders/skydome.vert - Shaders/skydome.frag + Shaders/skydome-ALS.vert + Shaders/skydome-ALS.frag + Shaders/noise.frag + Shaders/secondary_lights.frag mK @@ -108,6 +120,56 @@ float horizon_roughness + + view_pitch_offset + float + view_pitch_offset + + + view_heading_offset + float + view_heading_offset + + + field_of_view + float + view_fov + + + landing_light1_offset + float + landing_light1_offset + + + landing_light2_offset + float + landing_light2_offset + + + use_searchlight + int + use_searchlight + + + use_landing_light + int + use_landing_light + + + use_alt_landing_light + int + use_alt_landing_light + + + display_xsize + int + display_xsize + + + display_ysize + int + display_ysize + diff --git a/Effects/tree.eff b/Effects/tree.eff index 5c4cade57..8210b0a29 100644 --- a/Effects/tree.eff +++ b/Effects/tree.eff @@ -39,6 +39,16 @@ /sim/rendering/shaders/forest /environment/sea/surface/wind-from-east-fps /environment/sea/surface/wind-from-north-fps + /sim/startup/xsize + /sim/startup/ysize + /sim/current-view/pitch-offset-deg + /sim/current-view/heading-offset-deg + /sim/current-view/field-of-view + /sim/rendering/als-secondary-lights/use-searchlight + /sim/rendering/als-secondary-lights/use-landing-light + /sim/rendering/als-secondary-lights/use-alt-landing-light + /sim/rendering/als-secondary-lights/landing-light1-offset-deg + /sim/rendering/als-secondary-lights/landing-light2-offset-deg /local-weather/cloud-shadows/cloudpos-x[0] /local-weather/cloud-shadows/cloudpos-y[0] /local-weather/cloud-shadows/cloudpos-x[1] @@ -119,10 +129,11 @@ true - Shaders/tree-haze.vert + Shaders/tree-ALS.vert Shaders/noise.frag Shaders/cloud-shadowfunc.frag - Shaders/tree-haze.frag + Shaders/tree-ALS.frag + Shaders/secondary_lights.frag visibility @@ -199,6 +210,36 @@ float windN + + air_pollution + float + air_pollution + + + view_pitch_offset + float + view_pitch_offset + + + view_heading_offset + float + view_heading_offset + + + field_of_view + float + view_fov + + + landing_light1_offset + float + landing_light1_offset + + + landing_light2_offset + float + landing_light2_offset + cloudpos1_x float @@ -404,6 +445,31 @@ int cloud_shadow_flag + + use_searchlight + int + use_searchlight + + + use_landing_light + int + use_landing_light + + + use_alt_landing_light + int + use_alt_landing_light + + + display_xsize + int + display_xsize + + + display_ysize + int + display_ysize + texture sampler-2d @@ -478,10 +544,11 @@ 0.1 - Shaders/tree-haze.vert + Shaders/tree-ALS.vert Shaders/noise.frag Shaders/cloud-shadowfunc.frag - Shaders/tree-haze.frag + Shaders/tree-ALS.frag + Shaders/secondary_lights.frag visibility @@ -558,6 +625,36 @@ float windN + + air_pollution + float + air_pollution + + + view_pitch_offset + float + view_pitch_offset + + + view_heading_offset + float + view_heading_offset + + + field_of_view + float + view_fov + + + landing_light1_offset + float + landing_light1_offset + + + landing_light2_offset + float + landing_light2_offset + cloudpos1_x float @@ -763,6 +860,31 @@ int cloud_shadow_flag + + use_searchlight + int + use_searchlight + + + use_landing_light + int + use_landing_light + + + use_alt_landing_light + int + use_alt_landing_light + + + display_xsize + int + display_xsize + + + display_ysize + int + display_ysize + texture sampler-2d diff --git a/Shaders/airfield-ALS.frag b/Shaders/airfield-ALS.frag index 407545b5f..9928696ac 100644 --- a/Shaders/airfield-ALS.frag +++ b/Shaders/airfield-ALS.frag @@ -58,9 +58,12 @@ float Noise2D(in vec2 coord, in float wavelength); 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(in float dist); -vec3 landing_light(in float dist, in float offset); +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) { @@ -270,20 +273,21 @@ if (quality_level > 3) - + vec3 secondary_light = vec3 (0.0,0.0,0.0); if (use_searchlight == 1) { - color.rgb += searchlight(dist); + secondary_light += searchlight(); } if (use_landing_light == 1) { - color.rgb += landing_light(dist, landing_light1_offset); + secondary_light += landing_light(landing_light1_offset); } if (use_alt_landing_light == 1) { - color.rgb += landing_light(dist, landing_light2_offset); + secondary_light += landing_light(landing_light2_offset); } + color.rgb +=secondary_light * light_distance_fading(dist); fragColor = color * texel + specular; @@ -464,7 +468,8 @@ if ((quality_level>5) && (tquality_level>5)) 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; diff --git a/Shaders/runway-ALS.frag b/Shaders/runway-ALS.frag index 884afc672..00e34a428 100644 --- a/Shaders/runway-ALS.frag +++ b/Shaders/runway-ALS.frag @@ -52,8 +52,11 @@ float mie_angle; float shadow_func (in float x, in float y, in float noise, in float dist); float Noise2D(in vec2 coord, in float wavelength); float fog_func (in float targ, in float alt); -vec3 searchlight(in float dist); -vec3 landing_light(in float dist, in float offset); +float light_distance_fading(in float dist); +float fog_backscatter(in float avisibility); + +vec3 searchlight(); +vec3 landing_light(in float offset); @@ -248,19 +251,22 @@ if ((dist < 5000.0)&& (quality_level > 3) && (wetness>0.0)) // saturated. Clamping the color before modulating by the texture // 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) { - color.rgb += searchlight(dist); + secondary_light.rgb += searchlight(); } if (use_landing_light == 1) { - color.rgb += landing_light(dist, landing_light1_offset); + secondary_light += landing_light(landing_light1_offset); } if (use_alt_landing_light == 1) { - color.rgb += landing_light(dist, landing_light2_offset); + secondary_light += landing_light(landing_light2_offset); } + color.rgb +=secondary_light * light_distance_fading(dist); fragColor = color * texel + specular; @@ -418,11 +424,11 @@ if (intensity > 0.0) // this needs to be a condition, because otherwise hazeColo 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)); } +hazeColor = clamp(hazeColor, 0.0, 1.0); - -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; diff --git a/Shaders/secondary_lights.frag b/Shaders/secondary_lights.frag index 051e5e157..a7cfc6c73 100644 --- a/Shaders/secondary_lights.frag +++ b/Shaders/secondary_lights.frag @@ -6,7 +6,19 @@ uniform float field_of_view; uniform float view_pitch_offset; uniform float view_heading_offset; -vec3 searchlight(in float dist) +float light_distance_fading(in float dist) +{ +return min(1.0, 10000.0/(dist*dist)); +} + +float fog_backscatter(in float avisibility) +{ +return 0.5* min(1.0,10000.0/(avisibility*avisibility)); +} + + + +vec3 searchlight() { vec2 center = vec2 (float(display_xsize) * 0.5, float(display_ysize) * 0.4); @@ -18,14 +30,14 @@ float angularDist = length(gl_FragCoord.xy -center); if (angularDist < lightRadius) { headlightIntensity = pow(cos(angularDist/lightRadius * 1.57075),2.0); - headlightIntensity = headlightIntensity * min(1.0, 10000.0/(dist*dist)); + //headlightIntensity = headlightIntensity * //headlightIntensity*= clamp(1.0 + 0.15 * log(1000.0/(dist*dist)),0.0,1.0); return headlightIntensity * vec3 (0.5,0.5, 0.5); } else return vec3 (0.0,0.0,0.0); } -vec3 landing_light(in float dist, in float offset) +vec3 landing_light(in float offset) { float fov_h = field_of_view; @@ -52,7 +64,7 @@ float angularDist = length(gl_FragCoord.xy -center); if (angularDist < lightRadius) { landingLightIntensity = pow(cos(angularDist/lightRadius * 1.57075),2.0); - landingLightIntensity *= min(1.0, 10000.0/(dist*dist)); + //landingLightIntensity *= min(1.0, 10000.0/(dist*dist)); return landingLightIntensity * vec3 (0.5,0.5, 0.5); } else return vec3 (0.0,0.0,0.0); diff --git a/Shaders/skydome.frag b/Shaders/skydome-ALS.frag similarity index 81% rename from Shaders/skydome.frag rename to Shaders/skydome-ALS.frag index 326fd000c..a13e7cc15 100644 --- a/Shaders/skydome.frag +++ b/Shaders/skydome-ALS.frag @@ -1,3 +1,5 @@ +// -*-C++-*- + #version 120 // Atmospheric scattering shader for flightgear @@ -22,9 +24,21 @@ uniform float avisibility; uniform float scattering; uniform float cloud_self_shading; uniform float horizon_roughness; +uniform float landing_light1_offset; +uniform float landing_light2_offset; + +uniform int use_searchlight; +uniform int use_landing_light; +uniform int use_alt_landing_light; const float EarthRadius = 5800000.0; +float Noise2D(in vec2 coord, in float wavelength); +float fog_backscatter(in float avisibility); + +vec3 searchlight(); +vec3 landing_light(in float offset); + float miePhase(in float cosTheta, in float g) { float g2 = g*g; @@ -42,40 +56,7 @@ float rayleighPhase(in float cosTheta) return 1.5 * (2.0 + 0.5*cosTheta*cosTheta); } -float rand2D(in vec2 co){ - return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); -} -float simple_interpolate(in float a, in float b, in float x) -{ -return a + smoothstep(0.0,1.0,x) * (b-a); -} - -float interpolatedNoise2D(in float x, in float y) -{ - float integer_x = x - fract(x); - float fractional_x = x - integer_x; - - float integer_y = y - fract(y); - float fractional_y = y - integer_y; - - float v1 = rand2D(vec2(integer_x, integer_y)); - float v2 = rand2D(vec2(integer_x+1.0, integer_y)); - float v3 = rand2D(vec2(integer_x, integer_y+1.0)); - float v4 = rand2D(vec2(integer_x+1.0, integer_y +1.0)); - - float i1 = simple_interpolate(v1 , v2 , fractional_x); - float i2 = simple_interpolate(v3 , v4 , fractional_x); - - return simple_interpolate(i1 , i2 , fractional_y); -} - -float Noise2D(in vec2 coord, in float wavelength) -{ -return interpolatedNoise2D(coord.x/wavelength, coord.y/wavelength); - -} - void main() { @@ -225,14 +206,34 @@ terrainHazeColor = clamp(terrainHazeColor,0.0,1.0); color = mix(color, terrainHazeColor ,smoothstep(hazeBlendAngle + ctterrain, 0.0+ctterrain, ct)); +// add the brightening of fog by lights + + vec3 secondary_light = vec3 (0.0,0.0,0.0); + + if (use_searchlight == 1) + { + secondary_light.rgb += 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); + } + + + + // mix fog the skydome with the right amount of haze hColor = clamp(hColor,0.0,1.0); -color = transmission * color + (1.0-transmission) * eqColorFactor * hColor; +//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.vert b/Shaders/skydome-ALS.vert similarity index 100% rename from Shaders/skydome.vert rename to Shaders/skydome-ALS.vert diff --git a/Shaders/terrain-ALS-ultra.frag b/Shaders/terrain-ALS-ultra.frag index bdcfa4e4b..b8b648457 100644 --- a/Shaders/terrain-ALS-ultra.frag +++ b/Shaders/terrain-ALS-ultra.frag @@ -82,9 +82,12 @@ float Strata3D(in vec3 coord, in float wavelength, in float variation); 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(in float dist); -vec3 landing_light(in float dist, in float offset); +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) { @@ -463,18 +466,22 @@ 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) { - color.rgb += searchlight(dist); + secondary_light += searchlight(); } if (use_landing_light == 1) { - color.rgb += landing_light(dist, landing_light1_offset); + secondary_light += landing_light(landing_light1_offset); } - if (use_alt_landing_light == 1) + if (use_alt_landing_light == 1) { - color.rgb += landing_light(dist, landing_light2_offset); + secondary_light += landing_light(landing_light2_offset); } + color.rgb +=secondary_light * light_distance_fading(dist); fragColor = color * texel + specular; @@ -668,7 +675,7 @@ fragColor.rgb = mix(fragColor.rgb, rayleighColor,rayleighStrength); // finally, mix fog in -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; diff --git a/Shaders/tree-haze.frag b/Shaders/tree-ALS.frag similarity index 88% rename from Shaders/tree-haze.frag rename to Shaders/tree-ALS.frag index cba24a8a2..498071f16 100644 --- a/Shaders/tree-haze.frag +++ b/Shaders/tree-ALS.frag @@ -22,9 +22,12 @@ uniform float hazeLayerAltitude; uniform float overcast; uniform float eye_alt; uniform float dust_cover_factor; +uniform float landing_light1_offset; +uniform float landing_light2_offset; - - +uniform int use_searchlight; +uniform int use_landing_light; +uniform int use_alt_landing_light; uniform int quality_level; uniform int tquality_level; @@ -36,6 +39,12 @@ float alt; float mie_angle; +float light_distance_fading(in float dist); +float fog_backscatter(in float avisibility); + +vec3 searchlight(); +vec3 landing_light(in float offset); + float luminance(vec3 color) { return dot(vec3(0.212671, 0.715160, 0.072169), color); @@ -145,7 +154,28 @@ void main() texel = mix(texel, dust_color, clamp(0.6 * dust_cover_factor ,0.0, 1.0) ); } - vec4 fragColor = vec4 (gl_Color.xyz,1.0) * texel; + +// ALS secondary light sources + + vec3 secondary_light = vec3 (0.0,0.0,0.0); + + if ((quality_level>5) && (tquality_level>5)) + { + 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); + } + } + + vec4 fragColor = vec4 (gl_Color.rgb +secondary_light * light_distance_fading(dist),1.0) * texel; @@ -299,21 +329,15 @@ intensity = length(hazeColor); hazeColor = intensity * normalize(mix(hazeColor, 1.5* shadedFogColor, 1.0 -smoothstep(0.25, fade_out,eShade) )); // change haze color to blue hue for strong fogging -//intensity = length(hazeColor); + hazeColor = intensity * normalize(mix(hazeColor, shadedFogColor, (1.0-smoothstep(0.5,0.9,eqColorFactor)))); -// reduce haze intensity when looking at shaded surfaces, only in terminator region - -//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)); - // determine the right mix of transmission and haze -//fragColor.xyz = transmission * fragColor.xyz + (1.0-transmission) * eqColorFactor * hazeColor * earthShade; - -fragColor.rgb = mix(eqColorFactor * hazeColor * eShade, fragColor.rgb,transmission); +hazeColor = clamp(hazeColor,0.0,1.0); +fragColor.rgb = mix(eqColorFactor * hazeColor * eShade + secondary_light * fog_backscatter(avisibility), fragColor.rgb,transmission); gl_FragColor = fragColor; diff --git a/Shaders/tree-haze.vert b/Shaders/tree-ALS.vert similarity index 100% rename from Shaders/tree-haze.vert rename to Shaders/tree-ALS.vert