diff --git a/Effects/airfield.eff b/Effects/airfield.eff new file mode 100644 index 000000000..72c4fc788 --- /dev/null +++ b/Effects/airfield.eff @@ -0,0 +1,244 @@ + + + Effects/airfield + Effects/terrain-default + + + Textures.high/Terrain/airport_grass2.png + linear-mipmap-linear + repeat + repeat + normalized + + + + + + + /sim/rendering/shaders/skydome + + + 2.0 + /sim/rendering/shaders/transition + + + + + 2.0 + + + + GL_ARB_shader_objects + GL_ARB_shading_language_100 + GL_ARB_vertex_shader + GL_ARB_fragment_shader + + + + + + true + + material/ambient + material/diffuse + material/specular + material/emissive + material/shininess + ambient-and-diffuse + + transparent + smooth + back + + -1 + RenderBin + + + Shaders/trivial.vert + Shaders/trivial.frag + + + ylimit + float + ylimit + + + zlimit1 + float + zlimit1 + + + zlimit2 + float + zlimit2 + + 0 0 0 0 + + + true + + material/ambient + material/diffuse + material/specular + material/emissive + material/shininess + ambient-and-diffuse + + transparent + transparent + smooth + back + + render-bin/bin-number + render-bin/bin-name + + + 0 + texture[13]/image + texture[13]/filter + texture[13]/wrap-s + texture[13]/wrap-t + + texture[13]/internal-format + + + + 1 + noise + + + 6 + texture[10]/image + texture[10]/filter + texture[10]/wrap-s + texture[10]/wrap-t + + texture[10]/internal-format + + + + Shaders/terrain-haze-detailed.vert + Shaders/airfield.frag + + + visibility + float + visibility + + + avisibility + float + avisibility + + + hazeLayerAltitude + float + lthickness + + + scattering + float + scattering + + + ground_scattering + float + ground_scattering + + + terminator + float + terminator + + + terrain_alt + float + terrain_alt + + + overcast + float + overcast + + + eye_alt + float + eye_alt + + + snowlevel + float + snow_level + + + dust_cover_factor + float + dust_cover_factor + + + wetness + float + wetness + + + fogstructure + float + fogstructure + + + cloud_self_shading + float + cloud_self_shading + + + moonlight + float + moonlight + + + ylimit + float + ylimit + + + zlimit1 + float + zlimit1 + + + zlimit2 + float + zlimit2 + + + quality_level + int + quality_level + + + tquality_level + int + tquality_level + + + texture + sampler-2d + 0 + + + snow_texture + sampler-2d + 6 + + + colorMode + int + 2 + + + lequal + false + + + + diff --git a/Effects/building.eff b/Effects/building.eff index 9a7b8bde5..84e0383cf 100644 --- a/Effects/building.eff +++ b/Effects/building.eff @@ -147,10 +147,10 @@ - Shaders/include_fog.vert - Shaders/building-default.vert - Shaders/include_fog.frag - Shaders/terrain-nocolor.frag + Shaders/include_fog.vert + Shaders/building-default.vert + Shaders/include_fog.frag + Shaders/terrain-nocolor.frag texture @@ -236,6 +236,16 @@ float eye_alt + + cloud_self_shading + float + cloud_self_shading + + + moonlight + float + moonlight + texture sampler-2d diff --git a/Effects/cloud-static.eff b/Effects/cloud-static.eff index c90d0c5cf..ffce59cef 100644 --- a/Effects/cloud-static.eff +++ b/Effects/cloud-static.eff @@ -4,12 +4,10 @@ - - /environment/terminator-relative-position-m - - - /sim/rendering/eye-altitude-m - + /environment/terminator-relative-position-m + /sim/rendering/eye-altitude-m + /environment/cloud-self-shading + /environment/moonlight @@ -76,6 +74,16 @@ float altitude + + cloud_self_shading + float + cloud_self_shading + + + moonlight + float + moonlight + true diff --git a/Effects/cloud.eff b/Effects/cloud.eff index 47a6efe08..08cb74964 100644 --- a/Effects/cloud.eff +++ b/Effects/cloud.eff @@ -4,19 +4,12 @@ - - /sim/rendering/clouds3d-vis-range - - - /rendering/scene/scattering - - - /environment/terminator-relative-position-m - - - /sim/rendering/eye-altitude-m + /sim/rendering/clouds3d-vis-range + /rendering/scene/scattering + /environment/terminator-relative-position-m + /sim/rendering/eye-altitude-m + /environment/cloud-self-shading + /environment/moonlight @@ -96,7 +89,17 @@ float altitude - true + + cloud_self_shading + float + cloud_self_shading + + + moonlight + float + moonlight + + diff --git a/Effects/model-default.eff b/Effects/model-default.eff index 41bfd6994..e4e4fb344 100644 --- a/Effects/model-default.eff +++ b/Effects/model-default.eff @@ -22,9 +22,9 @@ /environment/mean-terrain-elevation-m /rendering/scene/overcast /sim/rendering/eye-altitude-m - - /sim/rendering/shaders/skydome - + /environment/cloud-self-shading + /environment/moonlight + /sim/rendering/shaders/skydome @@ -64,6 +64,10 @@ shade-model cull-face + rendering-hint Shaders/terrain-haze.vert Shaders/terrain-haze.frag @@ -113,13 +113,46 @@ float scattering - - terminator - float - - terminator - - + + terminator + float + terminator + + + ground_scattering + float + ground_scattering + + + terminator + float + terminator + + + terrain_alt + float + terrain_alt + + + overcast + float + overcast + + + eye_alt + float + eye_alt + + + cloud_self_shading + float + cloud_self_shading + + + moonlight + float + moonlight + texture sampler-2d diff --git a/Effects/runway.eff b/Effects/runway.eff index 45e65f124..f049f4a00 100644 --- a/Effects/runway.eff +++ b/Effects/runway.eff @@ -61,30 +61,277 @@ - - /environment/ground-visibility-m - - - /environment/visibility-m - - - /environment/ground-haze-thickness-m - - - /rendering/scene/scattering - - - /environment/terminator-relative-position-m - - - /sim/rendering/shaders/skydome - + /environment/ground-visibility-m + /environment/visibility-m + /environment/ground-haze-thickness-m + /rendering/scene/scattering + /environment/surface/scattering + /environment/terminator-relative-position-m + /environment/mean-terrain-elevation-m + /rendering/scene/overcast + /sim/rendering/eye-altitude-m + /environment/snow-level-m + /environment/surface/dust-cover-factor + /environment/surface/lichen-cover-factor + /environment/surface/snow-thickness-factor + /environment/surface/wetness + /sim/rendering/shaders/skydome + /environment/fog-structure + /environment/cloud-self-shading + /environment/moonlight + /sim/rendering/shaders/landmass + /sim/rendering/shaders/transition 6 7 + + + + + + /sim/rendering/shaders/skydome + + + 4.0 + /sim/rendering/shaders/landmass + + + 3.0 + /sim/rendering/shaders/transition + + + + + 2.0 + + + + GL_ARB_shader_objects + GL_ARB_shading_language_100 + GL_ARB_vertex_shader + GL_ARB_fragment_shader + + + + + + true + + material/ambient + material/diffuse + material/specular + material/emissive + material/shininess + ambient-and-diffuse + + transparent + smooth + back + + -1 + RenderBin + + + Shaders/trivial.vert + Shaders/trivial.frag + + 0 0 0 0 + + + true + + material/ambient + material/diffuse + material/specular + material/emissive + material/shininess + ambient-and-diffuse + + transparent + transparent + smooth + back + + render-bin/bin-number + render-bin/bin-name + + + 0 + texture[0]/image + texture[0]/filter + texture[0]/wrap-s + texture[0]/wrap-t + texture[0]/internal-format + + + 1 + noise + + + 5 + texture[12]/image + texture[12]/filter + texture[12]/wrap-s + texture[12]/wrap-t + texture[12]/internal-format + + + 6 + texture[10]/image + texture[10]/filter + texture[10]/wrap-s + texture[10]/wrap-t + texture[10]/internal-format + + + 7 + texture[11]/image + texture[11]/filter + texture[11]/wrap-s + texture[11]/wrap-t + texture[11]/internal-format + + + Shaders/terrain-haze-detailed.vert + Shaders/runway-lightfield.frag + + + visibility + float + visibility + + + avisibility + float + avisibility + + + hazeLayerAltitude + float + lthickness + + + scattering + float + scattering + + + ground_scattering + float + ground_scattering + + + terminator + float + terminator + + + terrain_alt + float + terrain_alt + + + overcast + float + overcast + + + eye_alt + float + eye_alt + + + snowlevel + float + snow_level + + + snow_thickness_factor + float + snow_thickness_factor + + + dust_cover_factor + float + dust_cover_factor + + + lichen_cover_factor + float + lichen_cover_factor + + + wetness + float + wetness + + + fogstructure + float + fogstructure + + + cloud_self_shading + float + cloud_self_shading + + + moonlight + float + moonlight + + + quality_level + int + quality_level + + + tquality_level + int + tquality_level + + + texture + sampler-2d + 0 + + + NoiseTex + sampler-3d + 1 + + + mix_texture + sampler-2d + 5 + + + snow_texture + sampler-2d + 6 + + + detail_texture + sampler-2d + 7 + + + colorMode + int + 2 + + + + lequal + false + + + + + diff --git a/Effects/skydome.eff b/Effects/skydome.eff index 94f3bc5f8..5d1267ea0 100644 --- a/Effects/skydome.eff +++ b/Effects/skydome.eff @@ -12,7 +12,8 @@ /environment/visibility-m /environment/ground-haze-thickness-m /environment/terminator-relative-position-m - /environment/mean-terrain-elevation-m + /environment/mean-terrain-elevation-m + /environment/cloud-self-shading @@ -95,6 +96,11 @@ terrain_alt float terrain_alt + + + cloud_self_shading + float + cloud_self_shading diff --git a/Effects/terrain-default.eff b/Effects/terrain-default.eff index f51b1035c..06ee978c3 100644 --- a/Effects/terrain-default.eff +++ b/Effects/terrain-default.eff @@ -67,11 +67,14 @@ /rendering/scene/overcast /sim/rendering/eye-altitude-m /environment/snow-level-m + /environment/surface/snow-thickness-factor /environment/surface/dust-cover-factor /environment/surface/lichen-cover-factor /environment/surface/wetness /sim/rendering/shaders/skydome /environment/fog-structure + /environment/cloud-self-shading + /environment/moonlight /sim/rendering/shaders/landmass /sim/rendering/shaders/transition @@ -122,27 +125,10 @@ -1 RenderBin - - Shaders/trivial.vert Shaders/trivial.frag - 0 0 0 0 @@ -163,10 +149,6 @@ render-bin/bin-number render-bin/bin-name - 0 texture[0]/image @@ -257,6 +239,11 @@ float snow_level + + snow_thickness_factor + float + snow_thickness_factor + dust_cover_factor float @@ -277,6 +264,16 @@ float fogstructure + + cloud_self_shading + float + cloud_self_shading + + + moonlight + float + moonlight + quality_level int @@ -455,6 +452,16 @@ float eye_alt + + cloud_self_shading + float + cloud_self_shading + + + moonlight + float + moonlight + texture sampler-2d diff --git a/Effects/urban.eff b/Effects/urban.eff index 05c779b09..9722012fe 100644 --- a/Effects/urban.eff +++ b/Effects/urban.eff @@ -322,6 +322,16 @@ float fogstructure + + cloud_self_shading + float + cloud_self_shading + + + moonlight + float + moonlight + @@ -573,6 +583,16 @@ snow-level + + cloud_self_shading + float + cloud_self_shading + + + moonlight + float + moonlight + diff --git a/Effects/water-inland.eff b/Effects/water-inland.eff index 04a2da753..8d5307988 100644 --- a/Effects/water-inland.eff +++ b/Effects/water-inland.eff @@ -123,6 +123,12 @@ /sim/rendering/eye-altitude-m + + /environment/cloud-self-shading + + + /environment/moonlight + /sim/rendering/shaders/skydome @@ -145,13 +151,12 @@ 7 - - + /sim/rendering/shaders/skydome - 2.0 + 5.0 /sim/rendering/shaders/water @@ -476,6 +481,11 @@ eye_alt + + cloud_self_shading + float + cloud_self_shading + sea_r @@ -502,6 +512,370 @@ + + + + + /sim/rendering/shaders/skydome + + 4.0 + /sim/rendering/shaders/water + + + + 2.0 + + + + GL_ARB_shader_objects + GL_ARB_shading_language_100 + GL_ARB_vertex_shader + GL_ARB_fragment_shader + + + + + + + true + + + material/ambient + + + material/diffuse + + + material/specular + + ambient-and-diffuse + + + transparent + + + transparent + + smooth + back + + + render-bin/bin-number + + + render-bin/bin-name + + + + + 2 + + texture[2]/image + + + texture[2]/filter + + + texture[2]/wrap-s + + + texture[2]/wrap-t + + + texture[2]/internal-format + + + + 3 + + texture[3]/image + + + texture[3]/filter + + + texture[3]/wrap-s + + + texture[3]/wrap-t + + + texture[3]/internal-format + + + + + 5 + + texture[5]/image + + + texture[5]/filter + + + texture[5]/wrap-s + + + texture[5]/wrap-t + + + texture[5]/internal-format + + + + 6 + + texture[6]/image + + + texture[6]/filter + + + texture[6]/wrap-s + + + texture[6]/wrap-t + + + texture[6]/internal-format + + + + + Shaders/water_lightfield.vert + Shaders/water_lightfield_lr.frag + + + + water_normalmap + sampler-2d + 2 + + + water_dudvmap + sampler-2d + 3 + + + sea_foam + sampler-2d + 5 + + + perlin_normalmap + sampler-2d + 6 + + + + normalmap_dds + float + + normalmap_dds + + + + saturation + float + + + saturation + + + + WindE + float + + windE + + + + WindN + float + + windN + + + + WaveFreq + float + + WaveFreq + + + + WaveAmp + float + + WaveAmp + + + + WaveSharp + float + + WaveSharp + + + + WaveAngle + float + + WaveAngle + + + + WaveFactor + float + + WaveFactor + + + + WaveDAngle + float + + WaveDAngle + + + + + + + + visibility + float + + visibility + + + + avisibility + float + + avisibility + + + + hazeLayerAltitude + float + + lthickness + + + + scattering + float + + scattering + + + + ground_scattering + float + + ground_scattering + + + + terminator + float + + terminator + + + + terrain_alt + float + + terrain_alt + + + + overcast + float + + overcast + + + + eye_alt + float + + eye_alt + + + + cloud_self_shading + float + cloud_self_shading + + + + sea_r + float + + sea_r + + + + sea_g + float + + sea_g + + + + sea_b + float + + sea_b + + + + + + + + diff --git a/Effects/water.eff b/Effects/water.eff index 318a2cb4a..444882fe3 100644 --- a/Effects/water.eff +++ b/Effects/water.eff @@ -123,6 +123,12 @@ /sim/rendering/eye-altitude-m + + /environment/cloud-self-shading + + + /environment/moonlight + /sim/rendering/shaders/skydome @@ -136,7 +142,6 @@ /environment/sea/color_b - @@ -476,6 +481,11 @@ eye_alt + + cloud_self_shading + float + cloud_self_shading + sea_r @@ -833,6 +843,11 @@ eye_alt + + cloud_self_shading + float + cloud_self_shading + sea_r diff --git a/Environment/environment.xml b/Environment/environment.xml index e0f0015fc..43e8d8524 100644 --- a/Environment/environment.xml +++ b/Environment/environment.xml @@ -413,11 +413,14 @@ 1000000.0 0.0 0.0 + 1.0 + 0.0 0.7 0.0 0.0 0.0 + 1.0 diff --git a/Materials/regions/materials.xml b/Materials/regions/materials.xml index d5468acfe..28616e26b 100644 --- a/Materials/regions/materials.xml +++ b/Materials/regions/materials.xml @@ -2040,6 +2040,7 @@ summer + Effects/airfield Grass Airport AirportKeep diff --git a/Nasal/local_weather/cloud_definitions.nas b/Nasal/local_weather/cloud_definitions.nas index f5e9cf131..e2fb8d341 100644 --- a/Nasal/local_weather/cloud_definitions.nas +++ b/Nasal/local_weather/cloud_definitions.nas @@ -33,7 +33,7 @@ if (type == "Cumulus (cloudlet)"){ cloudAssembly.max_height = 700.0; cloudAssembly.min_cloud_width = 1300; cloudAssembly.min_cloud_height = 750; - cloudAssembly.bottom_shade = 0.7; + cloudAssembly.bottom_shade = 0.4; } else { @@ -76,7 +76,7 @@ else if (type == "Cu (volume)"){ cloudAssembly.max_height = 700.0; cloudAssembly.min_cloud_width = 1000; cloudAssembly.min_cloud_height = 1000; - cloudAssembly.bottom_shade = 0.7; + cloudAssembly.bottom_shade = 0.4; } else { @@ -175,7 +175,7 @@ else if (type == "Stratocumulus"){ cloudAssembly.max_height = 900.0; cloudAssembly.min_cloud_width = 1300; cloudAssembly.min_cloud_height = 1300; - cloudAssembly.bottom_shade = 0.6; + cloudAssembly.bottom_shade = 0.4; } else { @@ -203,7 +203,7 @@ else if (type == "Stratocumulus"){ cloudAssembly.min_height = 1000.0; cloudAssembly.max_height = 1100.0; cloudAssembly.n_sprites = 3; - cloudAssembly.bottom_shade = 0.5; + cloudAssembly.bottom_shade = 0.4; cloudAssembly.min_cloud_width = 3500.0; cloudAssembly.min_cloud_height = 1600.0; } @@ -217,7 +217,7 @@ else if (type == "Stratocumulus"){ cloudAssembly.min_height = 800.0; cloudAssembly.max_height = 1000.0; cloudAssembly.n_sprites = 5; - cloudAssembly.bottom_shade = 0.6; + cloudAssembly.bottom_shade = 0.4; cloudAssembly.min_cloud_width = 3000.0; cloudAssembly.min_cloud_height = 1100.0; } @@ -237,7 +237,7 @@ else if (type == "Cumulus (whisp)"){ cloudAssembly = local_weather.cloud.new(type, subtype); - mult = 1.0; + var mult = 1.0; # characterize the basic texture sheet cloudAssembly.texture_sheet = "/Models/Weather/altocumulus_sheet1.rgb"; @@ -264,7 +264,7 @@ else if (type == "Cumulus bottom"){ cloudAssembly = local_weather.cloud.new(type, subtype); - mult = 1.0; + var mult = 1.0; # characterize the basic texture sheet cloudAssembly.texture_sheet = "/Models/Weather/cumulus_bottom_sheet1.rgb"; @@ -272,7 +272,7 @@ else if (type == "Cumulus bottom"){ cloudAssembly.num_tex_y = 1; #characterize the cloud - cloudAssembly.bottom_shade = 0.5; + cloudAssembly.bottom_shade = 0.4; cloudAssembly.n_sprites = 4; cloudAssembly.min_width = 600.0 * mult; cloudAssembly.max_width = 800.0 * mult; @@ -290,7 +290,7 @@ else if (type == "Congestus bottom"){ cloudAssembly = local_weather.cloud.new(type, subtype); - mult = 1.0; + var mult = 1.0; # characterize the basic texture sheet cloudAssembly.texture_sheet = "/Models/Weather/cumulus_bottom_sheet1.rgb"; @@ -298,7 +298,7 @@ else if (type == "Congestus bottom"){ cloudAssembly.num_tex_y = 1; #characterize the cloud - cloudAssembly.bottom_shade = 0.5; + cloudAssembly.bottom_shade = 0.4; cloudAssembly.n_sprites = 4; cloudAssembly.min_width = 1100.0 * mult; cloudAssembly.max_width = 1400.0 * mult; @@ -373,8 +373,9 @@ else if (type == "Altocumulus"){ cloudAssembly = local_weather.cloud.new(type, subtype); - if (subtype == "small") {var mult = 0.7;} - else {var mult = 1.0;} + var mult = 1.0; + if (subtype == "small") {mult = 0.7;} + else {mult = 1.0;} # characterize the basic texture sheet cloudAssembly.texture_sheet = "/Models/Weather/altocumulus_sheet1.rgb"; @@ -400,8 +401,9 @@ else if (type == "Stratus (structured)"){ cloudAssembly = local_weather.cloud.new(type, subtype); - if (subtype == "small") {var mult = 0.7;} - else {var mult = 1.0;} + var mult = 1.0; + if (subtype == "small") {mult = 0.7;} + else {mult = 1.0;} # characterize the basic texture sheet cloudAssembly.texture_sheet = "/Models/Weather/altocumulus_sheet1.rgb"; @@ -410,7 +412,8 @@ else if (type == "Stratus (structured)"){ #characterize the cloud cloudAssembly.bottom_shade = 0.4; - cloudAssembly.n_sprites = 25; + # cloudAssembly.n_sprites = 25; + cloudAssembly.n_sprites = 12; cloudAssembly.min_width = 1700.0 * mult; cloudAssembly.max_width = 2500.0 * mult; cloudAssembly.min_height = 1700.0 * mult; @@ -428,8 +431,9 @@ else if (type == "Altocumulus perlucidus"){ # new code cloudAssembly = local_weather.cloud.new(type, subtype); - if (subtype == "small") {var mult = 0.7;} - else {var mult = 1.0;} + var mult = 1.0; + if (subtype == "small") {mult = 0.7;} + else {mult = 1.0;} # characterize the basic texture sheet cloudAssembly.texture_sheet = "/Models/Weather/altocumulus_sheet1.rgb"; @@ -502,8 +506,9 @@ else if (type == "Cirrocumulus (cloudlet)") { cloudAssembly = local_weather.cloud.new(type, subtype); - if (subtype == "small") {var mult = 0.6;} - else {var mult = 1.0;} + var mult = 1.0; + if (subtype == "small") {mult = 0.6;} + else {mult = 1.0;} # characterize the basic texture sheet cloudAssembly.texture_sheet = "/Models/Weather/cirrocumulus_sheet1.rgb"; @@ -530,8 +535,9 @@ else if (type == "Cirrocumulus (new)") { cloudAssembly = local_weather.cloud.new(type, subtype); - if (subtype == "small") {var mult = 0.7;} - else {var mult = 1.0;} + var mult = 1.0; + if (subtype == "small") {mult = 0.7;} + else {mult = 1.0;} # characterize the basic texture sheet cloudAssembly.texture_sheet = "/Models/Weather/cirrocumulus_sheet1.rgb"; @@ -557,8 +563,9 @@ else if (type == "Nimbus") { cloudAssembly = local_weather.cloud.new(type, subtype); - if (subtype == "small") {var mult = 0.7;} - else {var mult = 1.0;} + var mult = 1.0; + if (subtype == "small") {mult = 0.7;} + else {mult = 1.0;} # characterize the basic texture sheet cloudAssembly.texture_sheet = "/Models/Weather/nimbus_sheet1.rgb"; @@ -567,14 +574,16 @@ else if (type == "Nimbus") { #characterize the cloud cloudAssembly.bottom_shade = 0.6; - cloudAssembly.n_sprites = 10; + #cloudAssembly.n_sprites = 10; + cloudAssembly.n_sprites = 5; cloudAssembly.min_width = 2700.0 * mult; cloudAssembly.max_width = 3000.0 * mult; cloudAssembly.min_height = 2700.0 * mult; cloudAssembly.max_height = 3000.0 * mult; - cloudAssembly.min_cloud_width = 3500.0 * mult * mult * mult; - cloudAssembly.min_cloud_height = 100.0 * mult * mult * mult + cloudAssembly.min_height; + cloudAssembly.min_cloud_width = 3500.0 * mult; + cloudAssembly.min_cloud_height = 3200.0 * mult; cloudAssembly.z_scale = 0.4; + cloudAssembly.tracer_flag = 1; #signal that new routines are used path = "new"; @@ -583,9 +592,10 @@ else if (type == "Stratus") { cloudAssembly = local_weather.cloud.new(type, subtype); + var mult = 1.0; if (subtype == "small") { - var mult = 0.8; + mult = 0.8; cloudAssembly.texture_sheet = "/Models/Weather/cirrocumulus_sheet1.rgb"; cloudAssembly.num_tex_x = 3; cloudAssembly.num_tex_y = 3; @@ -594,11 +604,12 @@ else if (type == "Stratus") { } else { - var mult = 1.0; + mult = 1.0; cloudAssembly.texture_sheet = "/Models/Weather/stratus_sheet1.rgb"; cloudAssembly.num_tex_x = 3; cloudAssembly.num_tex_y = 2; - cloudAssembly.n_sprites = 10; + #cloudAssembly.n_sprites = 10; + cloudAssembly.n_sprites = 6; cloudAssembly.z_scale = 0.4; } @@ -609,7 +620,7 @@ else if (type == "Stratus") { cloudAssembly.min_height = 2000.0 * mult; cloudAssembly.max_height = 2500.0 * mult; cloudAssembly.min_cloud_width = 5000.0; - cloudAssembly.min_cloud_height = 50; #1.1 * cloudAssembly.max_height; + cloudAssembly.min_cloud_height = 2600 * mult; #1.1 * cloudAssembly.max_height; #signal that new routines are used @@ -620,22 +631,25 @@ else if (type == "Stratus (thin)") { cloudAssembly = local_weather.cloud.new(type, subtype); + var mult = 1.0; if (subtype == "small") { - var mult = 0.5; + mult = 0.5; cloudAssembly.texture_sheet = "/Models/Weather/cirrocumulus_sheet1.rgb"; cloudAssembly.num_tex_x = 3; cloudAssembly.num_tex_y = 3; - cloudAssembly.n_sprites = 20; + # cloudAssembly.n_sprites = 20; + cloudAssembly.n_sprites = 10; cloudAssembly.z_scale = 0.4; } else { - var mult = 1.0; + mult = 1.0; cloudAssembly.texture_sheet = "/Models/Weather/stratus_sheet1.rgb"; cloudAssembly.num_tex_x = 3; cloudAssembly.num_tex_y = 2; - cloudAssembly.n_sprites = 10; + # cloudAssembly.n_sprites = 10; + cloudAssembly.n_sprites = 6; cloudAssembly.z_scale = 0.3; } @@ -660,8 +674,9 @@ else if (type == "Cirrostratus") { cloudAssembly = local_weather.cloud.new(type, subtype); - if (subtype == "small") {var mult = 0.7;} - else {var mult = 1.0;} + var mult = 1.0; + if (subtype == "small") {mult = 0.7;} + else {mult = 1.0;} # characterize the basic texture sheet cloudAssembly.texture_sheet = "/Models/Weather/cirrostratus_sheet1.rgb"; @@ -703,9 +718,10 @@ else if (type == "Fog (thick)") { cloudAssembly = local_weather.cloud.new(type, subtype); + var mult = 1.0; if (subtype == "small") { - var mult = 0.8; + mult = 0.8; cloudAssembly.texture_sheet = "/Models/Weather/stratus_sheet1.rgb"; cloudAssembly.num_tex_x = 3; cloudAssembly.num_tex_y = 2; @@ -714,7 +730,7 @@ else if (type == "Fog (thick)") { } else { - var mult = 1.0; + mult = 1.0; cloudAssembly.texture_sheet = "/Models/Weather/stratus_sheet1.rgb"; cloudAssembly.num_tex_x = 3; cloudAssembly.num_tex_y = 2; @@ -801,7 +817,7 @@ else if (type == "Cb_box") { cloudAssembly.num_tex_y = 2; #characterize the cloud - cloudAssembly.bottom_shade = 0.6; + cloudAssembly.bottom_shade = 0.4; cloudAssembly.n_sprites = 6; cloudAssembly.min_width = 800.0; cloudAssembly.max_width = 1100.0; @@ -822,7 +838,7 @@ else if (type == "Cb_box") { cloudAssembly.num_tex_y = 2; #characterize the cloud - cloudAssembly.bottom_shade = 0.6; + cloudAssembly.bottom_shade = 0.4; cloudAssembly.n_sprites = 10; cloudAssembly.min_width = 1000.0; cloudAssembly.max_width = 1500.0; @@ -839,7 +855,7 @@ else if (type == "Cb_box") { cloudAssembly.num_tex_y = 1; #characterize the cloud - cloudAssembly.bottom_shade = 0.5; + cloudAssembly.bottom_shade = 0.4; cloudAssembly.n_sprites = 4; cloudAssembly.min_width = 1100.0; cloudAssembly.max_width = 1400.0; diff --git a/Nasal/local_weather/compat_layer.nas b/Nasal/local_weather/compat_layer.nas index ac323dc4d..7247c2d7c 100644 --- a/Nasal/local_weather/compat_layer.nas +++ b/Nasal/local_weather/compat_layer.nas @@ -156,7 +156,7 @@ var setDefaultCloudsOff = func { var layers = props.globals.getNode("/environment/clouds").getChildren("layer"); -foreach (l; layers) +foreach (var l; layers) { l.getNode("coverage-type").setValue(5); } @@ -407,29 +407,29 @@ var buffer_flag = getprop(lw~"config/buffer-flag"); var d_max = weather_tile_management.cloud_view_distance + 1000.0; -# check if we deal with a convective cloud +# check if we deal with a convective cloud - no need to do this any more, convective clouds go via a different system var convective_flag = 0; -if (find("cumulus",path) != -1) - { - if ((find("alto",path) != -1) or (find("cirro", path) != -1) or (find("strato", path) != -1)) - {convective_flag = 0;} - else if ((find("small",path) != -1) or (find("whisp",path) != -1)) - {convective_flag = 1;} - else if (find("bottom",path) != -1) - {convective_flag = 4;} - else - {convective_flag = 2;} - - } -else if (find("congestus",path) != -1) - { - if (find("bottom",path) != -1) - {convective_flag = 5;} - else - {convective_flag = 3;} - } +#if (find("cumulus",path) != -1) +# { +# if ((find("alto",path) != -1) or (find("cirro", path) != -1) or (find("strato", path) != -1)) +# {convective_flag = 0;} +# else if ((find("small",path) != -1) or (find("whisp",path) != -1)) +# {convective_flag = 1;} +# else if (find("bottom",path) != -1) +# {convective_flag = 4;} +# else +# {convective_flag = 2;} +# +# } +#else if (find("congestus",path) != -1) +# { +# if (find("bottom",path) != -1) +# {convective_flag = 5;} +# else +# {convective_flag = 3;} +# } #print("path: ", path, " flag: ", convective_flag); @@ -443,7 +443,6 @@ else if (find("congestus",path) != -1) if (getprop(lw~"tmp/buffer-status") == "placing") { - #tile_counter = getprop(lw~"tmp/buffer-tile-index"); tile_counter = buffered_tile_index; } @@ -460,18 +459,18 @@ var cloud_number = n.getNode("placement-index").getValue(); for (var i = cloud_number; 1; i += 1) if (c.getChild("cloud", i, 0) == nil) break; - cl = c.getChild("cloud", i, 1); - n.getNode("placement-index").setValue(i); +var cl = c.getChild("cloud", i, 1); +n.getNode("placement-index").setValue(i); - var placement_index = i; +var placement_index = i; var model_number = n.getNode("model-placement-index").getValue(); var m = props.globals.getNode("models", 1); for (var i = model_number; 1; i += 1) if (m.getChild("model", i, 0) == nil) break; - model = m.getChild("model", i, 1); - n.getNode("model-placement-index").setValue(i); +var model = m.getChild("model", i, 1); +n.getNode("model-placement-index").setValue(i); @@ -483,15 +482,19 @@ var hdgN = cl.getNode("orientation/true-heading-deg", 1); hdgN.setValue(heading) cl.getNode("tile-index",1).setValue(tile_counter); model.getNode("path", 1).setValue(path); -model.getNode("latitude-deg-prop", 1).setValue(latN.getPath()); -model.getNode("longitude-deg-prop", 1).setValue(lonN.getPath()); -model.getNode("elevation-ft-prop", 1).setValue(altN.getPath()); -model.getNode("heading-deg-prop", 1).setValue(hdgN.getPath()); +model.getNode("latitude-deg", 1).setValue(lat); +model.getNode("longitude-deg", 1).setValue(long); +model.getNode("elevation-ft", 1).setValue(alt); +model.getNode("heading-deg", 1).setValue(local_weather.wind.cloudlayer[0]+180.0); model.getNode("tile-index",1).setValue(tile_counter); +model.getNode("speed-kt",1).setValue(local_weather.wind.cloudlayer[1]); model.getNode("load", 1).remove(); - +#model.getNode("latitude-deg-prop", 1).setValue(latN.getPath()); +#model.getNode("longitude-deg-prop", 1).setValue(lonN.getPath()); +#model.getNode("elevation-ft-prop", 1).setValue(altN.getPath()); +#model.getNode("heading-deg-prop", 1).setValue(hdgN.getPath()); # sort the cloud into the cloud hash array @@ -655,7 +658,6 @@ if ((i < 0) or (i==0)) # now set flag that tile has been completely processed var dir_index = props.globals.getNode(lw~"tiles/tmp/dir-index").getValue(); - #props.globals.getNode(lw~"tiles").getChild("tile",dir_index).getNode("generated-flag").setValue(2); setprop(lw~"tiles/tile["~dir_index~"]/generated-flag",2); return; diff --git a/Nasal/local_weather/local_weather.nas b/Nasal/local_weather/local_weather.nas index 1bcc4fe86..5d94557d5 100644 --- a/Nasal/local_weather/local_weather.nas +++ b/Nasal/local_weather/local_weather.nas @@ -467,7 +467,7 @@ var n_stations = size(weatherStationArray); for (var i = 0; i < n_stations; i=i+1) { - s = weatherStationArray[i]; + var s = weatherStationArray[i]; var stpos = geo.Coord.new(); @@ -511,6 +511,7 @@ var D = sum_D/sum_norm + temperature_offset; var T = sum_T/sum_norm + temperature_offset; + # get an inverse distance weighted average from all defined atmospheric condition points sum_norm = 0.0; @@ -528,7 +529,7 @@ var n_iPoints = size(atmosphereIpointArray); for (var i = 0; i < n_iPoints; i=i+1) { - a = atmosphereIpointArray[i]; + var a = atmosphereIpointArray[i]; var apos = geo.Coord.new(); @@ -587,11 +588,12 @@ var scatt_alt_high = sum_scatt_alt_high/sum_norm; vis = vis * ground_haze_factor; var altitude = getprop("position/altitude-ft"); -current_mean_terrain_elevation = ialt; +# var current_mean_terrain_elevation = ialt; var alt1 = vis_alt1; var alt2 = alt1 + 1500.0; + setprop("/environment/ground-visibility-m",vis); setprop("/environment/ground-haze-thickness-m",alt2 * ft_to_m); @@ -693,6 +695,11 @@ else {var scatt = 0.95;} +# compute the cloud layer self shading correction + +var sun_angle = 1.57079632675 - getprop("/sim/time/sun-angle-rad"); +var cloud_layer_shading = 1.0 - ((1.0 - scatt_max) * math.pow(math.cos(sun_angle),100.0)); + # compute the overcast haze if (altitude < ovcst_alt_low) @@ -731,11 +738,7 @@ else if (vis/vis_before < (2.0-vlimit)) # write all properties into the weather interpolation record setprop(lwi~"mean-terrain-altitude-ft",ialt); -# if (vis > 0.0) {setprop(lwi~"visibility-m",vis);} # a redundancy check -# setprop(lwi~"temperature-degc",T); -# setprop(lwi~"dewpoint-degc",D); -# if (p > 10.0) {setprop(lwi~"pressure-sea-level-inhg",p);} -# setprop(lwi~"turbulence",0.0); + if (vis > 0.0) interpolated_conditions.visibility_m = vis; interpolated_conditions.temperature_degc = T; @@ -747,6 +750,7 @@ if (p>10.0) interpolated_conditions.pressure_sea_level_inhg = p; if (scattering_shader_flag == 1) { local_weather.setSkydomeShader(rayleigh, mie, density); + setprop("/environment/cloud-self-shading", cloud_layer_shading); } local_weather.setScattering(scatt); @@ -757,7 +761,7 @@ local_weather.setOvercast(ovcst); # now check if an effect volume writes the property and set only if not -flag = getprop("local-weather/effect-volumes/number-active-vis"); +var flag = getprop("local-weather/effect-volumes/number-active-vis"); if ((flag ==0) and (vis > 0.0) and (getprop(lw~"lift-loop-flag") == 0) and (compat_layer.smooth_visibility_loop_flag == 0)) { @@ -1532,12 +1536,12 @@ return lift; # separately ########################################################### -var create_cloud_vec = func(path, lat, long, alt, heading) { +var create_cloud_vec = func(path, lat, lon, alt, heading) { if (path == "new") # we have to switch to new cloud generating routines { local_weather.cloudAssembly.lat = lat; - local_weather.cloudAssembly.lon = long; + local_weather.cloudAssembly.lon = lon; local_weather.cloudAssembly.alt = alt; local_weather.cloudAssembly.top_shade = top_shade; @@ -1550,16 +1554,39 @@ if (path == "new") # we have to switch to new cloud generating routines local_weather.cloudAssembly.evolution_timestamp = cloud_evolution_timestamp; local_weather.cloudAssembly.rel_alt = cloudAssembly.alt - cloud_mean_altitude; } - #compat_layer.create_cloud_new(local_weather.cloudAssembly); append(cloudAssemblyArray,cloudAssembly); + # at this point we insert tracers for the depth buffer + + #if (local_weather.cloudAssembly.tracer_flag == 1) + # { + # tracerAssembly = local_weather.cloud.new("Tracer", "default"); + # tracerAssembly.texture_sheet = "/Models/Weather/nimbus_sheet1.rgb"; + # tracerAssembly.n_sprites = 1; + # tracerAssembly.bottom_shade = 0.0; + # tracerAssembly.top_shade = 0.0; + # tracerAssembly.num_tex_x = 1; + # tracerAssembly.num_tex_y = 1; + # tracerAssembly.lat = lat; + # tracerAssembly.lon = lon; + # tracerAssembly.alt = alt + local_weather.cloudAssembly.min_height *0.35 * m_to_ft ; + # tracerAssembly.min_width = local_weather.cloudAssembly.min_width * 0.35; + # tracerAssembly.max_width = local_weather.cloudAssembly.max_width * 0.35; + # tracerAssembly.min_height = local_weather.cloudAssembly.min_height * 0.35; + # tracerAssembly.max_height = local_weather.cloudAssembly.max_height * 0.35; + # tracerAssembly.min_cloud_width = local_weather.cloudAssembly.min_cloud_width * 0.35; + # tracerAssembly.min_cloud_height = local_weather.cloudAssembly.min_cloud_height * 0.35; + # tracerAssembly.z_scale = local_weather.cloudAssembly.z_scale; + # append(cloudAssemblyArray,tracerAssembly); + # } + return; } append(clouds_path,path); append(clouds_lat,lat); -append(clouds_lon,long); +append(clouds_lon,lon); append(clouds_alt,alt); append(clouds_orientation,heading); @@ -1873,6 +1900,7 @@ create_effect_volume(1, lat, lon, 2000.0, 2000.0, 0.0, 0.0, alt+1000.0, 8000.0 + var create_cumosys = func (blat, blon, balt, nc, size) { + # realistic Cumulus has somewhat larger models, so compensate to get the same coverage if (detailed_clouds_flag == 1) {nc = int(0.7 * nc);} @@ -2680,10 +2708,10 @@ var terrain_presampling_loop = func (blat, blon, nc, size, alpha) { if ((local_weather_running_flag == 0) and (local_weather_startup_flag == 0)) {return;} +var n = 25; +var n_out = 25; if (local_weather.features.fast_geodinfo == 0) - {var n = 25; - var n_out = 25; - + { # dynamically drop accuracy if framerate is low var dt = getprop("/sim/time/delta-sec"); @@ -2742,9 +2770,9 @@ for (var i=0; i weather_tile_management.cloud_view_distance) {view_distance # shift the tile centers with the windfield var tiles = props.globals.getNode("local-weather/tiles", 1).getChildren("tile"); -foreach (t; tiles) {move_tile(t);} +foreach (var t; tiles) {move_tile(t);} @@ -369,7 +371,7 @@ for(var i = 0; i < 9; i = i + 1) n = n/cloud_convective_lifetime_s * cloud_respawning_interval_s * math.sqrt(0.35); - n_res = n - int(n); + var n_res = n - int(n); n = int(n); if (rand() < n_res) {n=n+1;} @@ -437,7 +439,7 @@ if (depth ==0) {return tree_base_vec;} else {return c_vec;} var sort_into_quadtree = func (blat, blon, alpha, lat, lon, tree, object) { -xy_vec = get_cartesian (blat, blon, alpha, lat, lon); +var xy_vec = get_cartesian (blat, blon, alpha, lat, lon); sorting_recursion (xy_vec[0], xy_vec[1], tree, object, 0); diff --git a/Nasal/local_weather/weather_tile_management.nas b/Nasal/local_weather/weather_tile_management.nas index 61e0df184..3228be22e 100644 --- a/Nasal/local_weather/weather_tile_management.nas +++ b/Nasal/local_weather/weather_tile_management.nas @@ -24,6 +24,7 @@ # object purpose # +# cloud to provide the data hash for the new cloud rendering system # cloudBuffer to store a cloud in a Nasal buffer, to provide methods to move it # cloudScenery to store info for clouds in scenery, to provide methods to move and evolve them @@ -43,9 +44,6 @@ var code = getprop(lw~"tiles/tile[4]/code"); var i = 0; var d_min = 100000.0; var i_min = 0; -# var distance_to_load = getprop(lw~"config/distance-to-load-tile-m"); -# var distance_to_remove = getprop(lw~"config/distance-to-remove-tile-m"); -# var current_visibility = getprop(lw~"interpolation/visibility-m"); var current_visibility = local_weather.interpolated_conditions.visibility_m; var current_heading = getprop("orientation/heading-deg"); var loading_flag = getprop(lw~"tmp/asymmetric-tile-loading-flag"); @@ -60,10 +58,7 @@ if (distance_to_load > 65000.0) {distance_to_load = 65000.0;} if (distance_to_load < 29000.0) {distance_to_load = 29000.0;} -#if (distance_to_load > 3.0 * current_visibility) -# {distance_to_load = 3.0 * current_visibility;} -#if (distance_to_load < 29000.0) -# {distance_to_load = 29000.0;} + var distance_to_remove = distance_to_load + 20000.0; if (distance_to_remove > 65500.0) {distance_to_remove = 65500.0;} @@ -154,7 +149,6 @@ foreach (var t; tNode) { t.getNode("generated-flag").setValue(1); t.getNode("timestamp-sec").setValue(weather_dynamics.time_lw); t.getNode("tile-index",1).setValue(getprop(lw~"tiles/tile-counter")); - generate_tile(code, tpos.lat(), tpos.lon(),i); } @@ -334,9 +328,10 @@ if (((local_weather.presampling_flag == 1) and (getprop(lw~"tmp/presampling-stat # compute the new windspeed + var windspeed = 0; if (local_weather.metar_flag == 0) { - var windspeed = getprop(lw~"tmp/windspeed-kt"); + windspeed = getprop(lw~"tmp/windspeed-kt"); windspeed = windspeed + 2.0 * (rand()-0.5) * 2.0; if (windspeed < 0) {windspeed = rand();} } @@ -1549,7 +1544,7 @@ var cloud = { var c = { parents: [cloud] }; c.type = type; c.subtype = subtype; - + c.tracer_flag = 0; return c; }, remove: func { diff --git a/Nasal/local_weather/weather_tiles.nas b/Nasal/local_weather/weather_tiles.nas index 30259ff39..b08d98eaa 100644 --- a/Nasal/local_weather/weather_tiles.nas +++ b/Nasal/local_weather/weather_tiles.nas @@ -353,6 +353,7 @@ setprop(lw~"tiles/code","high_pressure"); tile_start(); + var x = 0.0; var y = 0.0; var lat = 0.0; @@ -2911,7 +2912,7 @@ var create_6_8_stratocumulus = func (lat, lon, alt, alpha) { if (local_weather.detailed_clouds_flag == 1) { - for (i=0; i< 2; i=i+1) + for (var i=0; i< 2; i=i+1) { var phi = alpha * math.pi/180.0; var x = 2.0 * (rand()-0.5) * 4000; diff --git a/Shaders/3dcloud-lightfield.vert b/Shaders/3dcloud-lightfield.vert index e965a24f9..556405a81 100644 --- a/Shaders/3dcloud-lightfield.vert +++ b/Shaders/3dcloud-lightfield.vert @@ -2,13 +2,14 @@ #version 120 varying float fogFactor; -//varying float MieFactor; varying vec3 hazeColor; uniform float range; // From /sim/rendering/clouds3d-vis-range uniform float scattering; uniform float terminator; uniform float altitude; +uniform float cloud_self_shading; +uniform float moonlight; attribute vec3 usrAttr1; attribute vec3 usrAttr2; @@ -28,9 +29,10 @@ float light_func (in float x, in float a, in float b, in float c, in float d, in { x = x-0.5; + // use the asymptotics to shorten computations if (x > 30.0) {return e;} -if (x < -15.0) {return 0.0;} +if (x < -15.0) {return 0.03;} return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d)); @@ -45,7 +47,18 @@ return x + 2.0 * x * Mie * (1.0 -0.8*x) * (1.0 -0.8*x); void main(void) { + + //shade_factor = shade_factor * cloud_self_shading; + //top_factor = top_factor * cloud_self_shading; + //shade_factor = min(shade_factor, top_factor); + //middle_factor = min(middle_factor, top_factor); + //bottom_factor = min(bottom_factor, top_factor); + float intensity; + float mix_factor; + + vec3 shadedFogColor = vec3(0.65, 0.67, 0.78);//vec3 (0.55, 0.6, 0.8); + vec3 moonLightColor = vec3 (0.095, 0.095, 0.15) * moonlight * scattering; gl_TexCoord[0] = gl_MultiTexCoord0; vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0); vec4 l = gl_ModelViewMatrixInverse * vec4(0.0,0.0,1.0,1.0); @@ -121,6 +134,10 @@ void main(void) float yprime = -dot(relVector, lightHorizon); float yprime_alt = yprime -sqrt(2.0 * EarthRadius * vertex_alt); + // 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; + // compute the light at the position vec4 light_diffuse; @@ -129,16 +146,26 @@ void main(void) light_diffuse.b = light_func(lightArg, 1.330e-05, 0.264, 2.227, 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; - - intensity = length(light_diffuse); - light_diffuse = intensity * normalize(mix(light_diffuse, 2.0*vec4 (0.55, 0.6, 0.8, 1.0), (1.0 - smoothstep(0.3,0.8, scattering)))); + light_diffuse.a = 1.0; + intensity = (1.0 - (0.5 * (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 +if (earthShade < 0.8) + { + light_diffuse.rgb = intensity * normalize(mix(light_diffuse.rgb, shadedFogColor, 1.0 -smoothstep(0.1, 0.8,earthShade ) )); + + } //gl_FrontColor = gl_LightSource[0].diffuse * shade + gl_FrontLightModelProduct.sceneColor; - gl_FrontColor = light_diffuse * shade + gl_FrontLightModelProduct.sceneColor; + //intensity = length(light_diffuse.xyz); + + gl_FrontColor.rgb = intensity * shade * normalize(mix(light_diffuse.rgb, shadedFogColor, smoothstep(0.1,0.4, (1.0 - shade) ))) ; + + //gl_FrontColor.a = 1.0; + //light_diffuse+ gl_FrontLightModelProduct.sceneColor;// * shade ;//+ gl_FrontLightModelProduct.sceneColor; // As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out. gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1.0 - smoothstep(range*0.9, range, fogCoord)); @@ -155,33 +182,31 @@ void main(void) //fogFactor = clamp(fogFactor, 0.0, 1.0); // haze of ground haze shader is slightly bluish - hazeColor = light_diffuse.xyz; - hazeColor.x = hazeColor.x * 0.83; - hazeColor.y = hazeColor.y * 0.9; + hazeColor = light_diffuse.rgb; + hazeColor.r = hazeColor.r * 0.83; + hazeColor.g = hazeColor.g * 0.9; + //hazeColor = intensity * normalize(mix(hazeColor, shadedFogColor, (1.0 - smoothstep(0.5,0.9,cloud_self_shading)) )); hazeColor = hazeColor * scattering; // in sunset or sunrise conditions, do extra shading of clouds - // 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; - + // change haze color to blue hue for strong fogging - intensity = length(hazeColor); - hazeColor = intensity * normalize(mix(hazeColor, 2.0* vec3 (0.55, 0.6, 0.8), (1.0 - smoothstep(0.3,0.8,scattering)))); + //intensity = length(hazeColor); + //hazeColor = intensity * normalize(mix(hazeColor, 2.0* vec3 (0.55, 0.6, 0.8), (1.0 - smoothstep(0.3,0.8,scattering)))); - hazeColor = hazeColor * earthShade; - gl_FrontColor.xyz = gl_FrontColor.xyz * earthShade; + //hazeColor = hazeColor * earthShade; + //gl_FrontColor.xyz = gl_FrontColor.xyz * earthShade; // Mie correction float Mie; float MieFactor; - if (shade_factor > 0.6) + if (bottom_factor > 0.6) { MieFactor = dot(normalize(lightFull), normalize(relVector)); - Mie = 1.5 * smoothstep(0.9,1.0, MieFactor) * smoothstep(0.6, 0.8, shade_factor); + Mie = 1.5 * smoothstep(0.9,1.0, MieFactor) * smoothstep(0.6, 0.8, bottom_factor); } else {Mie = 0.0;} @@ -196,5 +221,11 @@ void main(void) gl_FrontColor.b = mie_func(gl_FrontColor.b, 0.5*Mie); } - gl_BackColor = gl_FrontColor; + gl_FrontColor.rgb = gl_FrontColor.rgb + moonLightColor * (1.0 - smoothstep(0.4, 0.5, earthShade)); + hazeColor.rgb = hazeColor.rgb + moonLightColor * (1.0 - smoothstep(0.4, 0.5, earthShade)); + gl_BackColor = gl_FrontColor; + + + + } diff --git a/Shaders/3dcloud.frag b/Shaders/3dcloud.frag index a8d07665a..6cb1b4896 100644 --- a/Shaders/3dcloud.frag +++ b/Shaders/3dcloud.frag @@ -4,6 +4,9 @@ varying float fogFactor; void main(void) { vec4 base = texture2D( baseTexture, gl_TexCoord[0].st); + if (base.a <= 0.01) + discard; + vec4 finalColor = base * gl_Color; gl_FragColor.rgb = mix(gl_Fog.color.rgb, finalColor.rgb, fogFactor ); gl_FragColor.a = finalColor.a; diff --git a/Shaders/airfield.frag b/Shaders/airfield.frag new file mode 100644 index 000000000..033519c12 --- /dev/null +++ b/Shaders/airfield.frag @@ -0,0 +1,471 @@ +// -*-C++-*- + +// written by Thorsten Renk, Oct 2011, based on default.frag +// Ambient term comes in gl_Color.rgb. +varying vec4 diffuse_term; +varying vec3 normal; +//varying vec2 nvec; +varying vec3 relPos; +varying vec2 rawPos; + + +uniform sampler2D texture; +uniform sampler2D snow_texture; + + +//varying float yprime_alt; +//varying float mie_angle; +varying float steepness; + + +uniform float visibility; +uniform float avisibility; +uniform float scattering; +uniform float terminator; +uniform float terrain_alt; +uniform float hazeLayerAltitude; +uniform float overcast; +uniform float eye_alt; +uniform float snowlevel; +uniform float dust_cover_factor; +uniform float fogstructure; +uniform float cloud_self_shading; +uniform float ylimit; +uniform float zlimit1; +uniform float zlimit2; +uniform float wetness; +uniform int quality_level; +uniform int tquality_level; + + +const float EarthRadius = 5800000.0; +const float terminator_width = 200000.0; + +float alt; +float eShade; +float yprime_alt; +float mie_angle; + + + + +float rand2D(in vec2 co){ + return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); +} + +float cosine_interpolate(in float a, in float b, in float x) +{ + float ft = x * 3.1415927; + float f = (1.0 - cos(ft)) * .5; + + return a*(1.0-f) + b*f; +} + +float simple_interpolate(in float a, in float b, in float x) +{ +return a + smoothstep(0.0,1.0,x) * (b-a); +//return mix(a,b,x); +} + +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); + +} + + + +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() +{ + +//if ((gl_FragCoord.y < ylimit) && (gl_FragCoord.x > zlimit1) && (gl_FragCoord.x < zlimit2)) +// {discard;} + + +float effective_scattering = min(scattering, cloud_self_shading); +yprime_alt = diffuse_term.a; +diffuse_term.a = 1.0; +mie_angle = gl_Color.a; + +vec3 shadedFogColor = vec3(0.65, 0.67, 0.78); + +float dist = length(relPos); + +// this is taken from default.frag + vec3 n; + float NdotL, NdotHV, fogFactor; + vec4 color = gl_Color; + color.a = 1.0; + vec3 lightDir = gl_LightSource[0].position.xyz; + vec3 halfVector = gl_LightSource[0].halfVector.xyz; + vec4 texel; + vec4 snow_texel; + vec4 detail_texel; + vec4 mix_texel; + vec4 fragColor; + vec4 specular = vec4(0.0); + float intensity; + + +// get noise at different wavelengths + +// used: 5m, 5m gradient, 10m, 10m gradient: heightmap of the closeup terrain, 10m also snow +// 500m: distortion and overlay +// 1500m: overlay, detail, dust, fog +// 2000m: overlay, detail, snow, fog + +float noise_02m; +float noise_1m = Noise2D(rawPos.xy, 1.0); +float noise_2m; + +float noise_10m = Noise2D(rawPos.xy, 10.0); +float noise_5m = Noise2D(rawPos.xy,5.0); + + + +float noise_500m = Noise2D(rawPos.xy, 500.0); +float noise_1500m = Noise2D(rawPos.xy, 1500.0); +float noise_2000m = Noise2D(rawPos.xy, 2000.0); + + + + + +// + + +// get the texels + + texel = texture2D(texture, gl_TexCoord[0].st * (1.0 + 0.1 * noise_500m)); + + float distortion_factor = 1.0; + + if (quality_level > 3) + { + snow_texel = texture2D(snow_texture, gl_TexCoord[0].st); + } + + + + + +float dist_fact; +float nSum; +float mix_factor; +float water_factor = 0.0; +float water_threshold1; +float water_threshold2; + + +// get distribution of water when terrain is wet + +if ((dist < 3000.0)&& (quality_level > 3) && (wetness>0.0)) + { + water_threshold1 = 1.0-0.5* wetness; + water_threshold2 = 1.0 - 0.3 * wetness; + water_factor = smoothstep(water_threshold1, water_threshold2 , 0.5 * (noise_5m + (1.0 -noise_1m))) * (1.0 - smoothstep(1000.0, 3000.0, dist)); + } + + +// color and shade variation of the grass + + texel.rgb = texel.rgb * (0.7 + 0.1 * (noise_10m + 2.0 * noise_5m + 3.0 * noise_1m)); + + texel.r = texel.r * (1.0 + 0.14 * smoothstep(0.5,0.7, 0.33*(2.0 * noise_10m + (1.0-noise_5m)))); + + +vec4 dust_color; +float snow_alpha; + +if (quality_level > 3) + { + // mix dust + dust_color = vec4 (0.76, 0.71, 0.56, 1.0); + texel = mix(texel, dust_color, clamp(0.5 * dust_cover_factor + 3.0 * dust_cover_factor * (((noise_1500m - 0.5) * 0.125)+0.125 ),0.0, 1.0) ); + + // mix snow + snow_alpha = smoothstep(0.75, 0.85, abs(steepness)); + texel = mix(texel, snow_texel, smoothstep(snowlevel, snowlevel+200.0, snow_alpha * (relPos.z + eye_alt)+ (noise_2000m + 0.1 * noise_10m -0.55) *400.0)); + } + + +// darken grass when wet + texel.rgb = texel.rgb * (1.0 - 0.6 * wetness); + + + +// light computations + + + vec4 light_specular = gl_LightSource[0].specular ; + + // If gl_Color.a == 0, this is a back-facing polygon and the + // normal should be reversed. + //n = (2.0 * gl_Color.a - 1.0) * normal; + //n = normalize(n); + n = normal;//vec3 (nvec.x, nvec.y, sqrt(1.0 -pow(nvec.x,2.0) - pow(nvec.y,2.0) )); + n = normalize(n); + + NdotL = dot(n, lightDir); + if ((dist < 200.0) && (quality_level > 4)) + { + noise_02m = Noise2D(rawPos.xy,0.1); + NdotL = NdotL + 0.4 * (noise_02m) * (1.0 - smoothstep(50.0, 100.0, dist)) * (1.0 - water_factor); + } + + if (NdotL > 0.0) { + color += diffuse_term * NdotL; + + + NdotHV = max(dot(n, halfVector), 0.0); + + if (gl_FrontMaterial.shininess > 0.0) + specular.rgb = ((gl_FrontMaterial.specular.rgb + (water_factor * vec3 (1.0, 1.0, 1.0))) + * light_specular.rgb + * pow(NdotHV, (gl_FrontMaterial.shininess + 20.0 * water_factor))); + } + color.a = diffuse_term.a; + // This shouldn't be necessary, but our lighting becomes very + // 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); + + + + + fragColor = color * texel + specular; + +// here comes the terrain haze model + + +float delta_z = hazeLayerAltitude - eye_alt; + +if (dist > max(40.0, 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; + + +float transmission; +float vAltitude; +float delta_zv; +float H; +float distance_in_layer; +float transmission_arg; + +// angle with horizon +float ct = dot(vec3(0.0, 0.0, 1.0), relPos)/dist; + + +// we solve the geometry what part of the light path is attenuated normally and what is through the haze layer + +if (delta_z > 0.0) // we're inside the layer + { + if (ct < 0.0) // we look down + { + distance_in_layer = dist; + vAltitude = min(distance_in_layer,min(visibility, avisibility)) * ct; + delta_zv = delta_z - vAltitude; + } + else // we may look through upper layer edge + { + H = dist * ct; + if (H > delta_z) {distance_in_layer = dist/H * delta_z;} + else {distance_in_layer = dist;} + vAltitude = min(distance_in_layer,visibility) * ct; + delta_zv = delta_z - vAltitude; + } + } + else // we see the layer from above, delta_z < 0.0 + { + H = dist * -ct; + if (H < (-delta_z)) // we don't see into the layer at all, aloft visibility is the only fading + { + distance_in_layer = 0.0; + delta_zv = 0.0; + } + else + { + vAltitude = H + delta_z; + distance_in_layer = vAltitude/H * dist; + vAltitude = min(distance_in_layer,visibility) * (-ct); + delta_zv = vAltitude; + } + } + + +// ground haze cannot be thinner than aloft visibility in the model, +// so we need to use aloft visibility otherwise + + +transmission_arg = (dist-distance_in_layer)/avisibility; + + +float eqColorFactor; + + + +if (visibility < avisibility) + { + if (quality_level > 3) + { + transmission_arg = transmission_arg + (distance_in_layer/(1.0 * visibility + 1.0 * visibility * fogstructure * 0.06 * (noise_1500m + noise_2000m -1.0) )); + + } + else + { + transmission_arg = transmission_arg + (distance_in_layer/visibility); + } + // this combines the Weber-Fechner intensity + eqColorFactor = 1.0 - 0.1 * delta_zv/visibility - (1.0 - effective_scattering); + + } +else + { + if (quality_level > 3) + { + transmission_arg = transmission_arg + (distance_in_layer/(1.0 * avisibility + 1.0 * avisibility * fogstructure * 0.06 * (noise_1500m + noise_2000m - 1.0) )); + } + else + { + transmission_arg = transmission_arg + (distance_in_layer/avisibility); + } + // this combines the Weber-Fechner intensity + eqColorFactor = 1.0 - 0.1 * delta_zv/avisibility - (1.0 - effective_scattering); + } + + + +transmission = fog_func(transmission_arg); + +// 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; + +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 +eShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1; + +// Mie-like factor + +if (lightArg < 10.0) + {intensity = length(hazeColor); + float mie_magnitude = 0.5 * smoothstep(350000.0, 150000.0, terminator-sqrt(2.0 * EarthRadius * terrain_alt)); + 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)) ); + } + +// high altitude desaturation of the haze color + +intensity = length(hazeColor); +hazeColor = intensity * normalize (mix(hazeColor, intensity * vec3 (1.0,1.0,1.0), 0.7* smoothstep(5000.0, 50000.0, alt))); + +// blue hue of haze + +hazeColor.x = hazeColor.x * 0.83; +hazeColor.y = hazeColor.y * 0.9; + + +// additional blue in indirect light +float fade_out = max(0.65 - 0.3 *overcast, 0.45); +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 +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(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)); + + + + +fragColor.xyz = mix(eqColorFactor * hazeColor * eShade, fragColor.xyz,transmission); + + +gl_FragColor = fragColor; + + +} +else // if dist < threshold no fogging at all +{ +gl_FragColor = fragColor; +} + + + +} + diff --git a/Shaders/building-haze.vert b/Shaders/building-haze.vert index 2ce4c669e..95912ca2a 100644 --- a/Shaders/building-haze.vert +++ b/Shaders/building-haze.vert @@ -26,10 +26,7 @@ varying vec3 relPos; //varying float yprime; //varying float vertex_alt; varying float yprime_alt; -varying float mie_angle; - - - +//varying float mie_angle; uniform int colorMode; uniform float hazeLayerAltitude; @@ -48,6 +45,8 @@ const float terminator_width = 200000.0; float earthShade; +float mie_angle; + float light_func (in float x, in float a, in float b, in float c, in float d, in float e) { @@ -66,12 +65,12 @@ void main() vec4 light_diffuse; vec4 light_ambient; - //float yprime_alt; float yprime; float lightArg; float intensity; float vertex_alt; float scattering; + vec3 shadedFogColor = vec3(0.65, 0.67, 0.78); // this code is copied from default.vert @@ -161,27 +160,23 @@ if (terminator < 1000000.0) // the full, sunrise and sunset computation light_diffuse.b = light_func(lightArg, 1.330e-05, 0.264, 3.827, 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; + light_diffuse.a = 1.0; light_diffuse = light_diffuse * scattering; - light_ambient.b = light_func(lightArg, 0.000506, 0.131, -3.315, 0.000457, 0.5); - light_ambient.g = light_func(lightArg, 2.264e-05, 0.134, 0.967, 3.66e-05, 0.4); light_ambient.r = light_func(lightArg, 0.236, 0.253, 1.073, 0.572, 0.33); - light_ambient.a = 0.0; - - - + light_ambient.g = light_ambient.r * 0.4/0.33; + light_ambient.b = light_ambient.r * 0.5/0.33; + light_ambient.a = 1.0; // correct ambient light intensity and hue before sunrise if (earthShade < 0.5) { - light_ambient = light_ambient * (0.7 + 0.3 * smoothstep(0.2, 0.5, earthShade)); - intensity = length(light_ambient.xyz); + //light_ambient = light_ambient * (0.4 + 0.6 * smoothstep(0.2, 0.5, earthShade)); + intensity = length(light_ambient.rgb); + light_ambient.rgb = intensity * normalize(mix(light_ambient.rgb, shadedFogColor, 1.0 -smoothstep(0.1, 0.8,earthShade) )); - light_ambient.xyz = intensity * normalize(mix(light_ambient.xyz, vec3 (0.45, 0.6, 0.8), 1.0 -smoothstep(0.1, 0.8,earthShade) )); - - intensity = length(light_diffuse.xyz); - light_diffuse.xyz = intensity * normalize(mix(light_diffuse.xyz, vec3 (0.45, 0.6, 0.8), 1.0 -smoothstep(0.1, 0.7,earthShade) )); + intensity = length(light_diffuse.rgb); + light_diffuse.rgb = intensity * normalize(mix(light_diffuse.rgb, shadedFogColor, 1.0 -smoothstep(0.1, 0.7,earthShade) )); } @@ -213,8 +208,8 @@ else // the faster, full-day version without lightfields mie_angle = 1.0; if (terminator > 3000000.0) - {light_diffuse = vec4 (1.0, 1.0, 1.0, 0.0); - light_ambient = vec4 (0.33, 0.4, 0.5, 0.0); } + {light_diffuse = vec4 (1.0, 1.0, 1.0, 1.0); + light_ambient = vec4 (0.33, 0.4, 0.5, 1.0); } else { @@ -222,12 +217,12 @@ else // the faster, full-day version without lightfields light_diffuse.b = 0.78 + lightArg * 0.21; light_diffuse.g = 0.907 + lightArg * 0.091; light_diffuse.r = 0.904 + lightArg * 0.092; - light_diffuse.a = 0.0; + light_diffuse.a = 1.0; - light_ambient.b = 0.41 + lightArg * 0.08; - light_ambient.g = 0.333 + lightArg * 0.06; light_ambient.r = 0.316 + lightArg * 0.016; - light_ambient.a = 0.0; + light_ambient.g = light_ambient.r * 0.4/0.33; + light_ambient.b = light_ambient.r * 0.5/0.33; + light_ambient.a = 1.0; } light_diffuse = light_diffuse * scattering; @@ -248,7 +243,8 @@ else // the faster, full-day version without lightfields diffuse_term.a = 1.0; // Another hack for supporting two-sided lighting without using // gl_FrontFacing in the fragment shader. - gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0; - gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0; + gl_FrontColor.rgb = constant_term.rgb; + gl_BackColor.rgb = constant_term.rgb; + gl_FrontColor.a = mie_angle; gl_BackColor.a = mie_angle; } diff --git a/Shaders/cloud-static-lightfield.vert b/Shaders/cloud-static-lightfield.vert index 1efb10a4e..0de086cb1 100644 --- a/Shaders/cloud-static-lightfield.vert +++ b/Shaders/cloud-static-lightfield.vert @@ -6,6 +6,8 @@ varying vec3 hazeColor; uniform float terminator; uniform float altitude; +uniform float cloud_self_shading; +uniform float moonlight; const float shade = 1.0; const float cloud_height = 1000.0; @@ -20,7 +22,7 @@ x = x-0.5; // use the asymptotics to shorten computations if (x > 30.0) {return e;} -if (x < -15.0) {return 0.0;} +if (x < -15.0) {return 0.03;} return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d)); @@ -29,6 +31,9 @@ return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d)); void main(void) { + vec3 shadedFogColor = vec3 (0.65, 0.67, 0.78); + vec3 moonLightColor = vec3 (0.095, 0.095, 0.15) * moonlight; + gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; //gl_TexCoord[0] = gl_MultiTexCoord0 + vec4(textureIndexX, textureIndexY, 0.0, 0.0); vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0); @@ -73,18 +78,20 @@ void main(void) float lightArg = (terminator-yprime_alt)/100000.0; - light_diffuse.b = light_func(lightArg, 1.330e-05, 0.264, 2.827, 1.08e-05, 1.0); + light_diffuse.b = light_func(lightArg, 1.330e-05, 0.264, 2.227, 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; + light_diffuse.a = 1.0; + float intensity = length(light_diffuse.rgb); + light_diffuse.rgb = intensity * normalize(mix(light_diffuse.rgb, shadedFogColor, (1.0 - smoothstep(0.5,0.9, cloud_self_shading )))); // Determine the shading of the sprite based on its vertical position and position relative to the sun. n = min(smoothstep(-0.5, 0.0, n), fract); // Determine the shading based on a mixture from the backlight to the front vec4 backlight = light_diffuse * shade; - gl_FrontColor = mix(backlight, gl_LightSource[0].diffuse, n); + gl_FrontColor = mix(backlight, light_diffuse, n); gl_FrontColor += gl_FrontLightModelProduct.sceneColor; // As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out. @@ -98,9 +105,9 @@ float fadeScale = 0.05 + 0.2 * log(fogCoord/1000.0); if (fadeScale < 0.05) fadeScale = 0.05; fogFactor = exp( -gl_Fog.density * fogCoord * fadeScale); - hazeColor = light_diffuse.xyz; - hazeColor.x = hazeColor.x * 0.83; - hazeColor.y = hazeColor.y * 0.9; + hazeColor = light_diffuse.rgb; + hazeColor.r = hazeColor.r * 0.83; + hazeColor.g = hazeColor.g * 0.9; // in sunset or sunrise conditions, do extra shading of clouds @@ -112,8 +119,16 @@ float fadeScale = 0.05 + 0.2 * log(fogCoord/1000.0); // now dim the light float earthShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1; + if (earthShade < 0.8) + { + intensity = length(light_diffuse.rgb); + gl_FrontColor.rgb = intensity * normalize(mix(gl_FrontColor.rgb, shadedFogColor, 1.0 -smoothstep(0.1, 0.8,earthShade ) )); + } + hazeColor = hazeColor * earthShade; - gl_FrontColor.xyz = gl_FrontColor.xyz * earthShade; + gl_FrontColor.rgb = gl_FrontColor.rgb * earthShade; + gl_FrontColor.rgb = gl_FrontColor.rgb + moonLightColor * (1.0 - smoothstep(0.4, 0.5, earthShade)); + hazeColor.rgb = hazeColor.rgb + moonLightColor * (1.0 - smoothstep(0.4, 0.5, earthShade)); gl_BackColor = gl_FrontColor; } diff --git a/Shaders/runway-lightfield.frag b/Shaders/runway-lightfield.frag new file mode 100644 index 000000000..95104f7cc --- /dev/null +++ b/Shaders/runway-lightfield.frag @@ -0,0 +1,569 @@ +// -*-C++-*- + +// written by Thorsten Renk, Oct 2011, based on default.frag +// Ambient term comes in gl_Color.rgb. +varying vec4 diffuse_term; +varying vec3 normal; +//varying vec2 nvec; +varying vec3 relPos; +varying vec2 rawPos; +//varying vec3 ecViewdir; + + +uniform sampler2D texture; +uniform sampler3D NoiseTex; +uniform sampler2D snow_texture; +uniform sampler2D detail_texture; +uniform sampler2D mix_texture; + +//varying float yprime_alt; +//varying float mie_angle; +varying float steepness; + + +uniform float visibility; +uniform float avisibility; +uniform float scattering; +uniform float terminator; +uniform float terrain_alt; +uniform float hazeLayerAltitude; +uniform float overcast; +uniform float eye_alt; +uniform float snowlevel; +uniform float dust_cover_factor; +uniform float lichen_cover_factor; +uniform float wetness; +uniform float fogstructure; +uniform float snow_thickness_factor; +uniform float cloud_self_shading; +uniform float ylimit; +uniform float zlimit1; +uniform float zlimit2; +uniform float xslope; +uniform int quality_level; +uniform int tquality_level; + +const float EarthRadius = 5800000.0; +const float terminator_width = 200000.0; + +float alt; +float eShade; +float yprime_alt; +float mie_angle; + + + +float rand2D(in vec2 co){ + return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); +} + +float cosine_interpolate(in float a, in float b, in float x) +{ + float ft = x * 3.1415927; + float f = (1.0 - cos(ft)) * .5; + + return a*(1.0-f) + b*f; +} + +float simple_interpolate(in float a, in float b, in float x) +{ +return a + smoothstep(0.0,1.0,x) * (b-a); +//return mix(a,b,x); +} + +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); + +} + + + +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() +{ + +// drop fragments behind the mask of the instrument panel as passed by properties + + +int xoffset = int(xslope * (ylimit - gl_FragCoord.y)); + + +if ((gl_FragCoord.y < ylimit) && (gl_FragCoord.x > zlimit1 - xoffset) && (gl_FragCoord.x < zlimit2 + xoffset)) + {discard;} + + +yprime_alt = diffuse_term.a; +diffuse_term.a = 1.0; +mie_angle = gl_Color.a; +float effective_scattering = min(scattering, cloud_self_shading); + +// distance to fragment +float dist = length(relPos); +// angle of view vector with horizon +float ct = dot(vec3(0.0, 0.0, 1.0), relPos)/dist; + + + vec3 shadedFogColor = vec3(0.65, 0.67, 0.78); +// this is taken from default.frag + vec3 n; + float NdotL, NdotHV, fogFactor; + vec4 color = gl_Color; + color.a = 1.0; + vec3 lightDir = gl_LightSource[0].position.xyz; + vec3 halfVector = gl_LightSource[0].halfVector.xyz; + //vec3 halfVector = normalize(normalize(lightDir) + normalize(ecViewdir)); + vec4 texel; + vec4 snow_texel; + vec4 detail_texel; + vec4 mix_texel; + vec4 fragColor; + vec4 specular = vec4(0.0); + float intensity; + + +// get noise at different wavelengths + +// used: 5m, 5m gradient, 10m, 10m gradient: heightmap of the closeup terrain, 10m also snow +// 50m: detail texel +// 250m: detail texel +// 500m: distortion and overlay +// 1500m: overlay, detail, dust, fog +// 2000m: overlay, detail, snow, fog + +float noise_10m; +float noise_5m; +noise_10m = Noise2D(rawPos.xy, 10.0); +noise_5m = Noise2D(rawPos.xy ,5.0); + +float noisegrad_10m; +float noisegrad_5m; + +float noise_50m = Noise2D(rawPos.xy, 50.0);; +float noise_250m; +float noise_500m = Noise2D(rawPos.xy, 500.0); +float noise_1500m = Noise2D(rawPos.xy, 1500.0); +float noise_2000m = Noise2D(rawPos.xy, 2000.0); + + + + + +// + + +// get the texels + + texel = texture2D(texture, gl_TexCoord[0].st); + + float distortion_factor = 1.0; + vec2 stprime; + int flag = 1; + int mix_flag = 1; + float noise_term; + float snow_alpha; + + + + + //float view_angle = abs(dot(normal, normalize(ecViewdir))); + + if ((quality_level > 3)&&(relPos.z + eye_alt +500.0 > snowlevel)) + { + //snow_texel = texture2D(snow_texture, gl_TexCoord[0].st); + float sfactor; + snow_texel = vec4 (0.95, 0.95, 0.95, 1.0) * (0.9 + 0.1* noise_500m + 0.1* (1.0 - noise_10m) ); + snow_texel.r = snow_texel.r * (0.9 + 0.05 * (noise_10m + noise_5m)); + snow_texel.g = snow_texel.g * (0.9 + 0.05 * (noise_10m + noise_5m)); + snow_texel.a = 1.0; + noise_term = 0.1 * (noise_500m-0.5); + sfactor = sqrt(2.0 * (1.0-steepness)/0.03) + abs(ct)/0.15; + noise_term = noise_term + 0.2 * (noise_50m -0.5) * (1.0 - smoothstep(18000.0*sfactor, 40000.0*sfactor, dist) ) ; + noise_term = noise_term + 0.3 * (noise_10m -0.5) * (1.0 - smoothstep(4000.0 * sfactor, 8000.0 * sfactor, dist) ) ; + if (dist < 3000*sfactor){ noise_term = noise_term + 0.3 * (noise_5m -0.5) * (1.0 - smoothstep(1000.0 * sfactor, 3000.0 *sfactor, dist) );} + snow_texel.a = snow_texel.a * 0.2+0.8* smoothstep(0.2,0.8, 0.3 +noise_term + snow_thickness_factor +0.0001*(relPos.z +eye_alt -snowlevel) ); + + } + + if (tquality_level > 2) + { + mix_texel = texture2D(mix_texture, gl_TexCoord[0].st * 1.3); + if (mix_texel.a <0.1) {mix_flag = 0;} + } + + + if (tquality_level > 3) + { + 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); + //distortion_factor = 0.9375 + (1.0 * nvL[2]); + distortion_factor = 0.97 + 0.06 * noise_500m; + stprime = stprime * distortion_factor * 15.0; + if (quality_level > 4) + { + stprime = stprime + normalize(relPos).xy * 0.02 * (noise_10m + 0.5 * noise_5m - 0.75); + } + detail_texel = texture2D(detail_texture, stprime); + if (detail_texel.a <0.1) {flag = 0;} + } + + +// texture preparation according to detail level + +// mix in hires texture patches + +float dist_fact; +float nSum; +float mix_factor; + +if (tquality_level > 2) + { + // first the second texture overlay + + + if (mix_flag == 1) + { + nSum = 0.18 * (2.0 * noise_2000m + 2.0 * noise_1500m + noise_500m); + nSum = nSum + 0.4 * (1.0 -smoothstep(0.9,0.95, abs(steepness))); + mix_factor = smoothstep(0.5, 0.54, nSum); + texel = mix(texel, mix_texel, mix_factor); + + } + + // then the detail texture overlay + } + +if (tquality_level > 3) + { + if (dist < 40000.0) + { + if (flag == 1) + { + //noise_50m = Noise2D(rawPos.xy, 50.0); + noise_250m = Noise2D(rawPos.xy, 250.0); + dist_fact = 0.1 * smoothstep(15000.0,40000.0, dist) - 0.03 * (1.0 - smoothstep(500.0,5000.0, dist)); + nSum = ((1.0 -noise_2000m) + noise_1500m + 2.0 * noise_250m +noise_50m)/5.0; + nSum = nSum - 0.08 * (1.0 -smoothstep(0.9,0.95, abs(steepness))); + mix_factor = smoothstep(0.47, 0.54, nSum - dist_fact); + if (mix_factor > 0.8) {mix_factor = 0.8;} + texel = mix(texel, detail_texel,mix_factor); + } + } + } + + +const vec4 dust_color = vec4 (0.76, 0.71, 0.56, 1.0); +const vec4 lichen_color = vec4 (0.17, 0.20, 0.06, 1.0);; +//float snow_alpha; + +if (quality_level > 3) + { + + // mix vegetation + texel = mix(texel, lichen_color, 0.4 * lichen_cover_factor + 0.8 * lichen_cover_factor * 0.5 * (noise_10m + (1.0 - noise_5m)) ); + // mix dust + texel = mix(texel, dust_color, clamp(0.5 * dust_cover_factor + 3.0 * dust_cover_factor * (((noise_1500m - 0.5) * 0.125)+0.125 ),0.0, 1.0) ); + + // mix snow + //if (relPos.z + eye_alt +500.0 > snowlevel) + // { + // snow_alpha = smoothstep(0.75, 0.85, abs(steepness)); + //texel = mix(texel, snow_texel, texel_snow_fraction); + // texel = mix(texel, snow_texel, snow_texel.a* smoothstep(snowlevel, snowlevel+200.0, snow_alpha * (relPos.z + eye_alt)+ (noise_2000m + 0.1 * noise_10m -0.55) *400.0)); + // } + } + + + +// get distribution of water when terrain is wet + +float water_threshold1; +float water_threshold2; +float water_factor =0.0; + + +if ((dist < 5000.0)&& (quality_level > 3) && (wetness>0.0)) + { + water_threshold1 = 1.0-0.5* wetness; + water_threshold2 = 1.0 - 0.3 * wetness; + 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)); + } + +// darken wet terrain + + texel.rgb = texel.rgb * (1.0 - 0.6 * wetness); + + +// light computations + + + vec4 light_specular = gl_LightSource[0].specular; + + // If gl_Color.a == 0, this is a back-facing polygon and the + // normal should be reversed. + //n = (2.0 * gl_Color.a - 1.0) * normal; + n = normal;//vec3 (nvec.x, nvec.y, sqrt(1.0 -pow(nvec.x,2.0) - pow(nvec.y,2.0) )); + n = normalize(n); + + NdotL = dot(n, lightDir); + if ((tquality_level > 3) && (mix_flag ==1)&& (dist < 2000.0) && (quality_level > 4)) + { + noisegrad_10m = (noise_10m - Noise2D(rawPos.xy+ 0.05 * normalize(lightDir.xy),10.0))/0.05; + noisegrad_5m = (noise_5m - Noise2D(rawPos.xy+ 0.05 * normalize(lightDir.xy),5.0))/0.05; + NdotL = NdotL + 1.0 * (noisegrad_10m + 0.5* noisegrad_5m) * mix_factor/0.8 * (1.0 - smoothstep(1000.0, 2000.0, dist)); + } + if (NdotL > 0.0) { + color += diffuse_term * NdotL; + NdotHV = max(dot(n, halfVector), 0.0); + if (gl_FrontMaterial.shininess > 0.0) + specular.rgb = ((gl_FrontMaterial.specular.rgb + (water_factor * vec3 (1.0, 1.0, 1.0))) + * light_specular.rgb + * pow(NdotHV, gl_FrontMaterial.shininess + (20.0 * water_factor))); + } + color.a = diffuse_term.a; + // This shouldn't be necessary, but our lighting becomes very + // 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); + + + + + fragColor = color * texel + specular; + +// here comes the terrain haze model + + +float delta_z = hazeLayerAltitude - eye_alt; + +if (dist > max(40.0, 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; + + +float transmission; +float vAltitude; +float delta_zv; +float H; +float distance_in_layer; +float transmission_arg; + + + + +// we solve the geometry what part of the light path is attenuated normally and what is through the haze layer + +if (delta_z > 0.0) // we're inside the layer + { + if (ct < 0.0) // we look down + { + distance_in_layer = dist; + vAltitude = min(distance_in_layer,min(visibility, avisibility)) * ct; + delta_zv = delta_z - vAltitude; + } + else // we may look through upper layer edge + { + H = dist * ct; + if (H > delta_z) {distance_in_layer = dist/H * delta_z;} + else {distance_in_layer = dist;} + vAltitude = min(distance_in_layer,visibility) * ct; + delta_zv = delta_z - vAltitude; + } + } + else // we see the layer from above, delta_z < 0.0 + { + H = dist * -ct; + if (H < (-delta_z)) // we don't see into the layer at all, aloft visibility is the only fading + { + distance_in_layer = 0.0; + delta_zv = 0.0; + } + else + { + vAltitude = H + delta_z; + distance_in_layer = vAltitude/H * dist; + vAltitude = min(distance_in_layer,visibility) * (-ct); + delta_zv = vAltitude; + } + } + + +// ground haze cannot be thinner than aloft visibility in the model, +// so we need to use aloft visibility otherwise + + +transmission_arg = (dist-distance_in_layer)/avisibility; + + +float eqColorFactor; + + + +if (visibility < avisibility) + { + if (quality_level > 3) + { + transmission_arg = transmission_arg + (distance_in_layer/(1.0 * visibility + 1.0 * visibility * fogstructure * 0.06 * (noise_1500m + noise_2000m -1.0) )); + + } + else + { + transmission_arg = transmission_arg + (distance_in_layer/visibility); + } + // this combines the Weber-Fechner intensity + eqColorFactor = 1.0 - 0.1 * delta_zv/visibility - (1.0 - effective_scattering); + + } +else + { + if (quality_level > 3) + { + transmission_arg = transmission_arg + (distance_in_layer/(1.0 * avisibility + 1.0 * avisibility * fogstructure * 0.06 * (noise_1500m + noise_2000m - 1.0) )); + } + else + { + transmission_arg = transmission_arg + (distance_in_layer/avisibility); + } + // this combines the Weber-Fechner intensity + eqColorFactor = 1.0 - 0.1 * delta_zv/avisibility - (1.0 - effective_scattering); + } + + + +transmission = fog_func(transmission_arg); + +// 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; + +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 +eShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1; + +// Mie-like factor + + if (lightArg < 10.0) + { + intensity = length(hazeColor); + float mie_magnitude = 0.5 * smoothstep(350000.0, 150000.0, terminator-sqrt(2.0 * EarthRadius * terrain_alt)); + 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)) ); + } + +intensity = length(hazeColor); + +if (intensity > 0.0) // this needs to be a condition, because otherwise hazeColor doesn't come out correctly +{ + + + // high altitude desaturation of the haze color + hazeColor = intensity * normalize (mix(hazeColor, intensity * vec3 (1.0,1.0,1.0), 0.7* smoothstep(5000.0, 50000.0, alt))); + + // blue hue of haze + hazeColor.x = hazeColor.x * 0.83; + hazeColor.y = hazeColor.y * 0.9; + + + // additional blue in indirect light + float fade_out = max(0.65 - 0.3 *overcast, 0.45); + 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 + 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(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)); + } + + + + +fragColor.rgb = mix(eqColorFactor * hazeColor * eShade , fragColor.rgb,transmission); + + +gl_FragColor = fragColor; + + +} +else // if dist < threshold no fogging at all +{ +gl_FragColor = fragColor; +} + + + +} + diff --git a/Shaders/skydome.frag b/Shaders/skydome.frag index 6b721a59f..a229890bd 100644 --- a/Shaders/skydome.frag +++ b/Shaders/skydome.frag @@ -2,7 +2,8 @@ // Atmospheric scattering shader for flightgear // Written by Lauri Peltonen (Zan) -// Implementation of O'Neil's algorithm +// Implementation of O'Neil's algorithm +// Ground haze layer added by Thorsten Renk varying vec3 rayleigh; varying vec3 mie; @@ -19,6 +20,7 @@ uniform float saturation; uniform float visibility; uniform float avisibility; uniform float scattering; +uniform float cloud_self_shading; const float EarthRadius = 5800000.0; @@ -42,7 +44,9 @@ float rayleighPhase(in float cosTheta) void main() -{ +{ + + vec3 shadedFogColor = vec3(0.65, 0.67, 0.78); float cosTheta = dot(normalize(eye), gl_LightSource[0].position.xyz); // position of the horizon line @@ -86,9 +90,9 @@ void main() //color.y = 1.0 - exp(-1.3 * color.y); //color.z = 1.0 - exp(-1.3 * color.z); -if (color.x > 0.58) color.x = 1.0 - exp(-1.5 * color.x); -if (color.y > 0.58) color.y = 1.0 - exp(-1.5 * color.y); -if (color.z > 0.58) color.z = 1.0 - exp(-1.5 * color.z); +if (color.r > 0.58) color.r = 1.0 - exp(-1.5 * color.r); +if (color.g > 0.58) color.g = 1.0 - exp(-1.5 * color.g); +if (color.b > 0.58) color.b = 1.0 - exp(-1.5 * color.b); // reduce the whiteout near the horizon generated by the single scattering approximation @@ -151,7 +155,7 @@ float vis = min(visibility, avisibility); //float scattering = ground_scattering + (1.0 - ground_scattering) * smoothstep(avisibility, 1.5 * avisibility, -alt/costheta); -float eqColorFactor = 1.0 - 0.1 * delta_zv/vis - (1.0 -scattering); +float eqColorFactor = 1.0 - 0.1 * delta_zv/vis - (1.0 - min(scattering,cloud_self_shading)); // there's always residual intensity, we should never be driven to zero @@ -161,6 +165,7 @@ if (eqColorFactor < 0.2) eqColorFactor = 0.2; // postprocessing of haze color vec3 hColor = hazeColor; + // high altitude desaturation float intensity = length(hColor); hColor = intensity * normalize (mix(hColor, intensity * vec3 (1.0,1.0,1.0), 0.7* smoothstep(5000.0, 50000.0, alt))); @@ -176,14 +181,18 @@ hColor.y = 0.9 * hColor.y; float fade_out = max(0.65 - 0.3 *overcast, 0.45); intensity = length(hColor); -hColor = intensity * normalize(mix(hColor, 1.5* vec3 (0.45, 0.6, 0.8), 1.0 -smoothstep(0.25, fade_out,earthShade) )); -hColor = intensity * normalize(mix(hColor, 2.0 * vec3 (0.55, 0.6, 0.8), (1.0 - smoothstep(0.3,0.8,eqColorFactor)))); +vec3 oColor = hColor; +oColor = intensity * normalize(mix(oColor, shadedFogColor, (smoothstep(0.1,1.0,ovc)))); +color = ovc * mix(color, oColor * earthShade ,smoothstep(-0.1+ctterrain, 0.0+ctterrain, ct)) + (1-ovc) * color; +hColor = intensity * normalize(mix(hColor, 1.5 * shadedFogColor, 1.0 -smoothstep(0.25, fade_out,earthShade) )); +hColor = intensity * normalize(mix(hColor, shadedFogColor, (1.0 - smoothstep(0.5,0.9,eqColorFactor)))); +//hColor = intensity * normalize(mix(hColor, shadedFogColor, (1.0 - smoothstep(0.5,0.9,cloud_self_shading)) )); hColor = hColor * earthShade; // accounting for overcast and saturation -color = ovc * mix(color, hazeColor * earthShade ,smoothstep(-0.1+ctterrain, 0.0+ctterrain, ct)) + (1-ovc) * color; + color = sat * color + (1.0 - sat) * mix(color, black, smoothstep(0.4+cthorizon,0.2+cthorizon,ct)); diff --git a/Shaders/terrain-haze-detailed.frag b/Shaders/terrain-haze-detailed.frag index 0a9facd93..567278727 100644 --- a/Shaders/terrain-haze-detailed.frag +++ b/Shaders/terrain-haze-detailed.frag @@ -4,8 +4,9 @@ // Ambient term comes in gl_Color.rgb. varying vec4 diffuse_term; varying vec3 normal; +//varying vec2 nvec; varying vec3 relPos; -varying vec3 rawPos; +varying vec2 rawPos; //varying vec3 ecViewdir; @@ -15,8 +16,8 @@ uniform sampler2D snow_texture; uniform sampler2D detail_texture; uniform sampler2D mix_texture; -varying float yprime_alt; -varying float mie_angle; +//varying float yprime_alt; +//varying float mie_angle; varying float steepness; @@ -33,6 +34,8 @@ uniform float dust_cover_factor; uniform float lichen_cover_factor; uniform float wetness; uniform float fogstructure; +uniform float snow_thickness_factor; +uniform float cloud_self_shading; uniform int quality_level; uniform int tquality_level; @@ -41,6 +44,8 @@ const float terminator_width = 200000.0; float alt; float eShade; +float yprime_alt; +float mie_angle; @@ -135,14 +140,23 @@ void main() { +yprime_alt = diffuse_term.a; +diffuse_term.a = 1.0; +mie_angle = gl_Color.a; +float effective_scattering = min(scattering, cloud_self_shading); - +// distance to fragment float dist = length(relPos); +// angle of view vector with horizon +float ct = dot(vec3(0.0, 0.0, 1.0), relPos)/dist; + + vec3 shadedFogColor = vec3(0.65, 0.67, 0.78); // this is taken from default.frag vec3 n; float NdotL, NdotHV, fogFactor; vec4 color = gl_Color; + color.a = 1.0; vec3 lightDir = gl_LightSource[0].position.xyz; vec3 halfVector = gl_LightSource[0].halfVector.xyz; //vec3 halfVector = normalize(normalize(lightDir) + normalize(ecViewdir)); @@ -172,7 +186,7 @@ noise_5m = Noise2D(rawPos.xy ,5.0); float noisegrad_10m; float noisegrad_5m; -float noise_50m; +float noise_50m = Noise2D(rawPos.xy, 50.0);; float noise_250m; float noise_500m = Noise2D(rawPos.xy, 500.0); float noise_1500m = Noise2D(rawPos.xy, 1500.0); @@ -193,11 +207,29 @@ float noise_2000m = Noise2D(rawPos.xy, 2000.0); vec2 stprime; int flag = 1; int mix_flag = 1; + float noise_term; + float snow_alpha; - if (quality_level > 3) + + + + //float view_angle = abs(dot(normal, normalize(ecViewdir))); + + if ((quality_level > 3)&&(relPos.z + eye_alt +500.0 > snowlevel)) { - snow_texel = texture2D(snow_texture, gl_TexCoord[0].st); - //snow_texel = vec4 (0.9, 0.9, 0.95, 1.0) * (0.8 + 0.2* noise_500m + 0.1* (1.0 - noise_10m) ); + //snow_texel = texture2D(snow_texture, gl_TexCoord[0].st); + float sfactor; + snow_texel = vec4 (0.95, 0.95, 0.95, 1.0) * (0.9 + 0.1* noise_500m + 0.1* (1.0 - noise_10m) ); + snow_texel.r = snow_texel.r * (0.9 + 0.05 * (noise_10m + noise_5m)); + snow_texel.g = snow_texel.g * (0.9 + 0.05 * (noise_10m + noise_5m)); + snow_texel.a = 1.0; + noise_term = 0.1 * (noise_500m-0.5); + sfactor = sqrt(2.0 * (1.0-steepness)/0.03) + abs(ct)/0.15; + noise_term = noise_term + 0.2 * (noise_50m -0.5) * (1.0 - smoothstep(18000.0*sfactor, 40000.0*sfactor, dist) ) ; + noise_term = noise_term + 0.3 * (noise_10m -0.5) * (1.0 - smoothstep(4000.0 * sfactor, 8000.0 * sfactor, dist) ) ; + if (dist < 3000*sfactor){ noise_term = noise_term + 0.3 * (noise_5m -0.5) * (1.0 - smoothstep(1000.0 * sfactor, 3000.0 *sfactor, dist) );} + snow_texel.a = snow_texel.a * 0.2+0.8* smoothstep(0.2,0.8, 0.3 +noise_term + snow_thickness_factor +0.0001*(relPos.z +eye_alt -snowlevel) ); + } if (tquality_level > 2) @@ -253,7 +285,7 @@ if (tquality_level > 3) { if (flag == 1) { - noise_50m = Noise2D(rawPos.xy, 50.0); + //noise_50m = Noise2D(rawPos.xy, 50.0); noise_250m = Noise2D(rawPos.xy, 250.0); dist_fact = 0.1 * smoothstep(15000.0,40000.0, dist) - 0.03 * (1.0 - smoothstep(500.0,5000.0, dist)); nSum = ((1.0 -noise_2000m) + noise_1500m + 2.0 * noise_250m +noise_50m)/5.0; @@ -268,7 +300,7 @@ if (tquality_level > 3) const vec4 dust_color = vec4 (0.76, 0.71, 0.56, 1.0); const vec4 lichen_color = vec4 (0.17, 0.20, 0.06, 1.0);; -float snow_alpha; +//float snow_alpha; if (quality_level > 3) { @@ -279,8 +311,12 @@ if (quality_level > 3) texel = mix(texel, dust_color, clamp(0.5 * dust_cover_factor + 3.0 * dust_cover_factor * (((noise_1500m - 0.5) * 0.125)+0.125 ),0.0, 1.0) ); // mix snow - snow_alpha = smoothstep(0.75, 0.85, abs(steepness)); - texel = mix(texel, snow_texel, smoothstep(snowlevel, snowlevel+200.0, snow_alpha * (relPos.z + eye_alt)+ (noise_2000m + 0.1 * noise_10m -0.55) *400.0)); + if (relPos.z + eye_alt +500.0 > snowlevel) + { + snow_alpha = smoothstep(0.75, 0.85, abs(steepness)); + //texel = mix(texel, snow_texel, texel_snow_fraction); + texel = mix(texel, snow_texel, snow_texel.a* smoothstep(snowlevel, snowlevel+200.0, snow_alpha * (relPos.z + eye_alt)+ (noise_2000m + 0.1 * noise_10m -0.55) *400.0)); + } } @@ -311,7 +347,8 @@ if ((dist < 5000.0)&& (quality_level > 3) && (wetness>0.0)) // If gl_Color.a == 0, this is a back-facing polygon and the // normal should be reversed. - n = (2.0 * gl_Color.a - 1.0) * normal; + //n = (2.0 * gl_Color.a - 1.0) * normal; + n = normal;//vec3 (nvec.x, nvec.y, sqrt(1.0 -pow(nvec.x,2.0) - pow(nvec.y,2.0) )); n = normalize(n); NdotL = dot(n, lightDir); @@ -360,8 +397,7 @@ float H; float distance_in_layer; float transmission_arg; -// angle with horizon -float ct = dot(vec3(0.0, 0.0, 1.0), relPos)/dist; + // we solve the geometry what part of the light path is attenuated normally and what is through the haze layer @@ -424,7 +460,7 @@ if (visibility < avisibility) transmission_arg = transmission_arg + (distance_in_layer/visibility); } // this combines the Weber-Fechner intensity - eqColorFactor = 1.0 - 0.1 * delta_zv/visibility - (1.0 -scattering); + eqColorFactor = 1.0 - 0.1 * delta_zv/visibility - (1.0 - effective_scattering); } else @@ -438,7 +474,7 @@ else transmission_arg = transmission_arg + (distance_in_layer/avisibility); } // this combines the Weber-Fechner intensity - eqColorFactor = 1.0 - 0.1 * delta_zv/avisibility - (1.0 -scattering); + eqColorFactor = 1.0 - 0.1 * delta_zv/avisibility - (1.0 - effective_scattering); } @@ -463,41 +499,46 @@ eShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + term // Mie-like factor -if (lightArg < 10.0) - {intensity = length(hazeColor); - float mie_magnitude = 0.5 * smoothstep(350000.0, 150000.0, terminator-sqrt(2.0 * EarthRadius * terrain_alt)); - 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)) ); + if (lightArg < 10.0) + { + intensity = length(hazeColor); + float mie_magnitude = 0.5 * smoothstep(350000.0, 150000.0, terminator-sqrt(2.0 * EarthRadius * terrain_alt)); + 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)) ); + } + +intensity = length(hazeColor); + +if (intensity > 0.0) // this needs to be a condition, because otherwise hazeColor doesn't come out correctly +{ + + + // high altitude desaturation of the haze color + hazeColor = intensity * normalize (mix(hazeColor, intensity * vec3 (1.0,1.0,1.0), 0.7* smoothstep(5000.0, 50000.0, alt))); + + // blue hue of haze + hazeColor.x = hazeColor.x * 0.83; + hazeColor.y = hazeColor.y * 0.9; + + + // additional blue in indirect light + float fade_out = max(0.65 - 0.3 *overcast, 0.45); + 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 + 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(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)); } -// high altitude desaturation of the haze color - -intensity = length(hazeColor); -hazeColor = intensity * normalize (mix(hazeColor, intensity * vec3 (1.0,1.0,1.0), 0.7* smoothstep(5000.0, 50000.0, alt))); - -// blue hue of haze - -hazeColor.x = hazeColor.x * 0.83; -hazeColor.y = hazeColor.y * 0.9; - - -// additional blue in indirect light -float fade_out = max(0.65 - 0.3 *overcast, 0.45); -intensity = length(hazeColor); -hazeColor = intensity * normalize(mix(hazeColor, 1.5* vec3 (0.45, 0.6, 0.8), 1.0 -smoothstep(0.25, fade_out,eShade) )); - -// change haze color to blue hue for strong fogging -hazeColor = intensity * normalize(mix(hazeColor, 2.0 * vec3 (0.55, 0.6, 0.8), (1.0-smoothstep(0.3,0.8,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)); - -fragColor.xyz = mix(eqColorFactor * hazeColor * eShade, fragColor.xyz,transmission); +fragColor.rgb = mix(eqColorFactor * hazeColor * eShade , fragColor.rgb,transmission); gl_FragColor = fragColor; diff --git a/Shaders/terrain-haze-detailed.vert b/Shaders/terrain-haze-detailed.vert index cddfea884..511532937 100644 --- a/Shaders/terrain-haze-detailed.vert +++ b/Shaders/terrain-haze-detailed.vert @@ -20,12 +20,13 @@ // bugs with gl_FrontFacing in the fragment shader. varying vec4 diffuse_term; varying vec3 normal; +//varying vec2 nvec; varying vec3 relPos; -varying vec3 rawPos; +varying vec2 rawPos; //varying vec3 ecViewdir; //varying float earthShade; -varying float yprime_alt; +//varying float yprime_alt; varying float mie_angle; varying float steepness; @@ -39,8 +40,11 @@ uniform float visibility; uniform float overcast; uniform float ground_scattering; uniform float eye_alt; +uniform float moonlight; float earthShade; +float yprime_alt; +//float mie_angle; // This is the value used in the skydome scattering shader - use the same here for consistency? @@ -63,6 +67,8 @@ void main() vec4 light_diffuse; vec4 light_ambient; + vec3 shadedFogColor = vec3(0.65, 0.67, 0.78); + vec3 moonLightColor = vec3 (0.095, 0.095, 0.15) * moonlight; //float yprime_alt; float yprime; @@ -71,7 +77,7 @@ void main() float vertex_alt; float scattering; - rawPos = gl_Vertex.xyz; + rawPos = gl_Vertex.xy; steepness = dot(normalize(gl_Normal), vec3 (0.0, 0.0, 1.0)); @@ -81,6 +87,7 @@ void main() gl_Position = ftransform(); gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; normal = gl_NormalMatrix * gl_Normal; + //nvec = (gl_NormalMatrix * gl_Normal).xy; vec4 ambient_color, diffuse_color; if (colorMode == MODE_DIFFUSE) { diffuse_color = gl_Color; @@ -117,10 +124,9 @@ void main() scattering = ground_scattering + (1.0 - ground_scattering) * smoothstep(hazeLayerAltitude -100.0, hazeLayerAltitude + 100.0, vertex_alt); - // 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; +//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) { @@ -171,13 +177,15 @@ if (terminator < 1000000.0) // the full, sunrise and sunset computation light_diffuse.b = light_func(lightArg, 1.330e-05, 0.264, 3.827, 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; + light_diffuse.a = 1.0; light_diffuse = light_diffuse * scattering; - light_ambient.b = light_func(lightArg, 0.000506, 0.131, -3.315, 0.000457, 0.5); - light_ambient.g = light_func(lightArg, 2.264e-05, 0.134, 0.967, 3.66e-05, 0.4); + //light_ambient.b = light_func(lightArg, 0.000506, 0.131, -3.315, 0.000457, 0.5); + //light_ambient.g = light_func(lightArg, 2.264e-05, 0.134, 0.967, 3.66e-05, 0.4); light_ambient.r = light_func(lightArg, 0.236, 0.253, 1.073, 0.572, 0.33); - light_ambient.a = 0.0; + light_ambient.g = light_ambient.r * 0.4/0.33; //light_func(lightArg, 0.236, 0.253, 1.073, 0.572, 0.4); + light_ambient.b = light_ambient.r * 0.5/0.33; //light_func(lightArg, 0.236, 0.253, 1.073, 0.572, 0.5); + light_ambient.a = 1.0; @@ -185,13 +193,12 @@ if (terminator < 1000000.0) // the full, sunrise and sunset computation // correct ambient light intensity and hue before sunrise if (earthShade < 0.5) { - light_ambient = light_ambient * (0.7 + 0.3 * smoothstep(0.2, 0.5, earthShade)); - intensity = length(light_ambient.xyz); + intensity = length(light_ambient.rgb); + light_ambient.rgb = intensity * normalize(mix(light_ambient.rgb, shadedFogColor, 1.0 -smoothstep(0.1, 0.8,earthShade) )); + light_ambient.rgb = light_ambient.rgb + moonLightColor * (1.0 - smoothstep(0.4, 0.5, earthShade)); - light_ambient.xyz = intensity * normalize(mix(light_ambient.xyz, vec3 (0.45, 0.6, 0.8), 1.0 -smoothstep(0.1, 0.8,earthShade) )); - - intensity = length(light_diffuse.xyz); - light_diffuse.xyz = intensity * normalize(mix(light_diffuse.xyz, vec3 (0.45, 0.6, 0.8), 1.0 -smoothstep(0.1, 0.7,earthShade) )); + intensity = length(light_diffuse.rgb); + light_diffuse.rgb = intensity * normalize(mix(light_diffuse.rgb, shadedFogColor, 1.0 -smoothstep(0.1, 0.7,earthShade) )); } @@ -223,8 +230,8 @@ else // the faster, full-day version without lightfields mie_angle = 1.0; if (terminator > 3000000.0) - {light_diffuse = vec4 (1.0, 1.0, 1.0, 0.0); - light_ambient = vec4 (0.33, 0.4, 0.5, 0.0); } + {light_diffuse = vec4 (1.0, 1.0, 1.0, 1.0); + light_ambient = vec4 (0.33, 0.4, 0.5, 1.0); } else { @@ -232,12 +239,14 @@ else // the faster, full-day version without lightfields light_diffuse.b = 0.78 + lightArg * 0.21; light_diffuse.g = 0.907 + lightArg * 0.091; light_diffuse.r = 0.904 + lightArg * 0.092; - light_diffuse.a = 0.0; + light_diffuse.a = 1.0; - light_ambient.b = 0.41 + lightArg * 0.08; - light_ambient.g = 0.333 + lightArg * 0.06; + //light_ambient.b = 0.41 + lightArg * 0.08; + //light_ambient.g = 0.333 + lightArg * 0.06; light_ambient.r = 0.316 + lightArg * 0.016; - light_ambient.a = 0.0; + light_ambient.g = light_ambient.r * 0.4/0.33; + light_ambient.b = light_ambient.r * 0.5/0.33; + light_ambient.a = 1.0; } light_diffuse = light_diffuse * scattering; @@ -258,16 +267,19 @@ light_ambient = light_ambient * ((1.0+steepness)/2.0 * 1.2 + (1.0-steepness)/2.0 (gl_LightModel.ambient + light_ambient); // Super hack: if diffuse material alpha is less than 1, assume a // transparency animation is at work - if (gl_FrontMaterial.diffuse.a < 1.0) - diffuse_term.a = gl_FrontMaterial.diffuse.a; - else - diffuse_term.a = gl_Color.a; + // if (gl_FrontMaterial.diffuse.a < 1.0) + // diffuse_term.a = gl_FrontMaterial.diffuse.a; + //else + // diffuse_term.a = gl_Color.a; + diffuse_term.a = yprime_alt; // Another hack for supporting two-sided lighting without using // gl_FrontFacing in the fragment shader. - gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0; - gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0; - + gl_FrontColor.rgb = constant_term.rgb; //gl_FrontColor.a = 1.0; + gl_BackColor.rgb = constant_term.rgb; //gl_BackColor.a = 0.0; + gl_FrontColor.a = mie_angle; + gl_BackColor.a = mie_angle; } } + diff --git a/Shaders/terrain-haze.frag b/Shaders/terrain-haze.frag index e2c14c8f8..ee0c580f8 100644 --- a/Shaders/terrain-haze.frag +++ b/Shaders/terrain-haze.frag @@ -24,6 +24,7 @@ uniform float hazeLayerAltitude; uniform float overcast; //uniform float altitude; uniform float eye_alt; +uniform float cloud_self_shading; const float EarthRadius = 5800000.0; const float terminator_width = 200000.0; @@ -61,7 +62,7 @@ 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 +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) @@ -81,6 +82,7 @@ else void main() { + vec3 shadedFogColor = vec3(0.65, 0.67, 0.78); // this is taken from default.frag vec3 n; float NdotL, NdotHV, fogFactor; @@ -92,6 +94,7 @@ void main() vec4 specular = vec4(0.0); float intensity; + float effective_scattering = min(scattering, cloud_self_shading); vec4 light_specular = gl_LightSource[0].specular; @@ -196,14 +199,14 @@ if (visibility < avisibility) { transmission_arg = transmission_arg + (distance_in_layer/visibility); // this combines the Weber-Fechner intensity - eqColorFactor = 1.0 - 0.1 * delta_zv/visibility - (1.0 -scattering); + eqColorFactor = 1.0 - 0.1 * delta_zv/visibility - (1.0 -effective_scattering); } else { transmission_arg = transmission_arg + (distance_in_layer/avisibility); // this combines the Weber-Fechner intensity - eqColorFactor = 1.0 - 0.1 * delta_zv/avisibility - (1.0 -scattering); + eqColorFactor = 1.0 - 0.1 * delta_zv/avisibility - (1.0 -effective_scattering); } @@ -249,11 +252,11 @@ hazeColor.y = hazeColor.y * 0.9; // additional blue in indirect light float fade_out = max(0.65 - 0.3 *overcast, 0.45); intensity = length(hazeColor); -hazeColor = intensity * normalize(mix(hazeColor, 1.5* vec3 (0.45, 0.6, 0.8), 1.0 -smoothstep(0.25, fade_out,eShade) )); +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, 2.0 * vec3 (0.55, 0.6, 0.8), (1.0-smoothstep(0.3,0.8,eqColorFactor)))); +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 diff --git a/Shaders/terrain-haze.vert b/Shaders/terrain-haze.vert index 09c83163e..3c9261185 100644 --- a/Shaders/terrain-haze.vert +++ b/Shaders/terrain-haze.vert @@ -22,15 +22,9 @@ varying vec4 diffuse_term; varying vec3 normal; varying vec3 relPos; -//varying float earthShade; -//varying float yprime; -//varying float vertex_alt; varying float yprime_alt; varying float mie_angle; - - - uniform int colorMode; uniform float hazeLayerAltitude; uniform float terminator; @@ -38,8 +32,8 @@ uniform float terrain_alt; uniform float avisibility; uniform float visibility; uniform float overcast; -//uniform float scattering; uniform float ground_scattering; +uniform float moonlight; // This is the value used in the skydome scattering shader - use the same here for consistency? @@ -65,6 +59,9 @@ void main() vec4 light_diffuse; vec4 light_ambient; + vec3 shadedFogColor = vec3(0.65, 0.67, 0.78); + vec3 moonLightColor = vec3 (0.095, 0.095, 0.15) * moonlight; + //float yprime_alt; float yprime; @@ -110,6 +107,7 @@ void main() vertex_alt = max(gl_Vertex.z,100.0); scattering = ground_scattering + (1.0 - ground_scattering) * smoothstep(hazeLayerAltitude -100.0, hazeLayerAltitude + 100.0, vertex_alt); + // branch dependent on daytime if (terminator < 1000000.0) // the full, sunrise and sunset computation @@ -148,13 +146,14 @@ if (terminator < 1000000.0) // the full, sunrise and sunset computation light_diffuse.b = light_func(lightArg, 1.330e-05, 0.264, 3.827, 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; + light_diffuse.a = 1.0; light_diffuse = light_diffuse * scattering; - light_ambient.b = light_func(lightArg, 0.000506, 0.131, -3.315, 0.000457, 0.5); - light_ambient.g = light_func(lightArg, 2.264e-05, 0.134, 0.967, 3.66e-05, 0.4); + light_ambient.r = light_func(lightArg, 0.236, 0.253, 1.073, 0.572, 0.33); - light_ambient.a = 0.0; + light_ambient.g = light_ambient.r * 0.4/0.33; + light_ambient.b = light_ambient.r * 0.5/0.33; + light_ambient.a = 1.0; @@ -162,13 +161,14 @@ if (terminator < 1000000.0) // the full, sunrise and sunset computation // correct ambient light intensity and hue before sunrise if (earthShade < 0.5) { - light_ambient = light_ambient * (0.7 + 0.3 * smoothstep(0.2, 0.5, earthShade)); + //light_ambient = light_ambient * (0.7 + 0.3 * smoothstep(0.2, 0.5, earthShade)); intensity = length(light_ambient.xyz); - light_ambient.xyz = intensity * normalize(mix(light_ambient.xyz, vec3 (0.45, 0.6, 0.8), 1.0 -smoothstep(0.1, 0.8,earthShade) )); + light_ambient.rgb = intensity * normalize(mix(light_ambient.rgb, shadedFogColor, 1.0 -smoothstep(0.1, 0.8,earthShade) )); + light_ambient.rgb = light_ambient.rgb + moonLightColor * (1.0 - smoothstep(0.4, 0.5, earthShade)); intensity = length(light_diffuse.xyz); - light_diffuse.xyz = intensity * normalize(mix(light_diffuse.xyz, vec3 (0.45, 0.6, 0.8), 1.0 -smoothstep(0.1, 0.7,earthShade) )); + light_diffuse.rgb = intensity * normalize(mix(light_diffuse.rgb, shadedFogColor, 1.0 -smoothstep(0.1, 0.7,earthShade) )); } @@ -209,12 +209,12 @@ else // the faster, full-day version without lightfields light_diffuse.b = 0.78 + lightArg * 0.21; light_diffuse.g = 0.907 + lightArg * 0.091; light_diffuse.r = 0.904 + lightArg * 0.092; - light_diffuse.a = 0.0; + light_diffuse.a = 1.0; - light_ambient.b = 0.41 + lightArg * 0.08; - light_ambient.g = 0.333 + lightArg * 0.06; light_ambient.r = 0.316 + lightArg * 0.016; - light_ambient.a = 0.0; + light_ambient.g = light_ambient.r * 0.4/0.33; + light_ambient.b = light_ambient.r * 0.5/0.33; + light_ambient.a = 1.0; } light_diffuse = light_diffuse * scattering; @@ -237,5 +237,9 @@ else // the faster, full-day version without lightfields // gl_FrontFacing in the fragment shader. gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0; gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0; + } + + + diff --git a/Shaders/tree-haze.frag b/Shaders/tree-haze.frag index 15e79bb14..5dbfd4306 100644 --- a/Shaders/tree-haze.frag +++ b/Shaders/tree-haze.frag @@ -11,7 +11,7 @@ uniform sampler2D texture; varying float yprime_alt; -varying float mie_angle; +//varying float mie_angle; uniform float visibility; @@ -24,12 +24,15 @@ uniform float overcast; uniform float eye_alt; uniform float dust_cover_factor; + + uniform int quality_level; const float EarthRadius = 5800000.0; const float terminator_width = 200000.0; float alt; +float mie_angle; float luminance(vec3 color) { @@ -82,22 +85,29 @@ void main() { + vec3 shadedFogColor = vec3(0.65, 0.67, 0.78); + vec3 lightDir = gl_LightSource[0].position.xyz; float intensity; - vec4 fragColor = gl_Color * texture2D(texture, gl_TexCoord[0].st); + mie_angle = gl_Color.a; + vec4 texel = texture2D(texture, gl_TexCoord[0].st); + if (quality_level > 3) { // mix dust - vec4 dust_color = vec4 (0.76, 0.71, 0.56, fragColor.a); + vec4 dust_color = vec4 (0.76, 0.71, 0.56, texel.a); - fragColor = mix(fragColor, dust_color, clamp(0.6 * dust_cover_factor ,0.0, 1.0) ); + texel = mix(texel, dust_color, clamp(0.6 * dust_cover_factor ,0.0, 1.0) ); } + vec4 fragColor = vec4 (gl_Color.xyz,1.0) * texel; + + // here comes the terrain haze model @@ -228,11 +238,11 @@ hazeColor.y = hazeColor.y * 0.9; // additional blue in indirect light float fade_out = max(0.65 - 0.3 *overcast, 0.45); intensity = length(hazeColor); -hazeColor = intensity * normalize(mix(hazeColor, 1.5* vec3 (0.45, 0.6, 0.8), 1.0 -smoothstep(0.25, fade_out,eShade) )); +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, 2.0 * vec3 (0.55, 0.6, 0.8), (1.0-smoothstep(0.3,0.8,eqColorFactor)))); +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 @@ -245,7 +255,7 @@ hazeColor = intensity * normalize(mix(hazeColor, 2.0 * vec3 (0.55, 0.6, 0.8), ( //fragColor.xyz = transmission * fragColor.xyz + (1.0-transmission) * eqColorFactor * hazeColor * earthShade; -fragColor.xyz = mix(eqColorFactor * hazeColor * eShade, fragColor.xyz,transmission); +fragColor.rgb = mix(eqColorFactor * hazeColor * eShade, fragColor.rgb,transmission); gl_FragColor = fragColor; diff --git a/Shaders/tree-haze.vert b/Shaders/tree-haze.vert index b61df8266..df812d1a2 100644 --- a/Shaders/tree-haze.vert +++ b/Shaders/tree-haze.vert @@ -26,7 +26,7 @@ varying vec3 relPos; //varying float yprime; //varying float vertex_alt; varying float yprime_alt; -varying float mie_angle; +//varying float mie_angle; uniform int colorMode; uniform float hazeLayerAltitude; @@ -39,6 +39,7 @@ uniform float overcast; uniform float ground_scattering; float earthShade; +float mie_angle; // This is the value used in the skydome scattering shader - use the same here for consistency? const float EarthRadius = 5800000.0; @@ -61,7 +62,8 @@ void main() vec4 light_diffuse; vec4 light_ambient; - //float yprime_alt; + vec3 shadedFogColor = vec3(0.65, 0.67, 0.78); + float yprime; float lightArg; float intensity; @@ -156,13 +158,15 @@ if (terminator < 1000000.0) // the full, sunrise and sunset computation light_diffuse.b = light_func(lightArg, 1.330e-05, 0.264, 3.827, 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; + light_diffuse.a = 1.0; light_diffuse = light_diffuse * scattering; - light_ambient.b = light_func(lightArg, 0.000506, 0.131, -3.315, 0.000457, 0.5); - light_ambient.g = light_func(lightArg, 2.264e-05, 0.134, 0.967, 3.66e-05, 0.4); light_ambient.r = light_func(lightArg, 0.236, 0.253, 1.073, 0.572, 0.33); - light_ambient.a = 0.0; + light_ambient.g = light_ambient.r * 0.4/0.33; + light_ambient.b = light_ambient.r * 0.5/0.33; + light_ambient.a = 1.0; + + @@ -170,13 +174,12 @@ if (terminator < 1000000.0) // the full, sunrise and sunset computation // correct ambient light intensity and hue before sunrise if (earthShade < 0.5) { - light_ambient = light_ambient * (0.4 + 0.6 * smoothstep(0.2, 0.5, earthShade)); - intensity = length(light_ambient.xyz); + //light_ambient = light_ambient * (0.4 + 0.6 * smoothstep(0.2, 0.5, earthShade)); + intensity = length(light_ambient.rgb); + light_ambient.rgb = intensity * normalize(mix(light_ambient.rgb, shadedFogColor, 1.0 -smoothstep(0.1, 0.8,earthShade) )); - light_ambient.xyz = intensity * normalize(mix(light_ambient.xyz, vec3 (0.45, 0.6, 0.8), 1.0 -smoothstep(0.1, 0.5,earthShade) )); - - intensity = length(light_diffuse.xyz); - light_diffuse.xyz = intensity * normalize(mix(light_diffuse.xyz, vec3 (0.45, 0.6, 0.8), 1.0 -smoothstep(0.1, 0.5,earthShade) )); + intensity = length(light_diffuse.rgb); + light_diffuse.rgb = intensity * normalize(mix(light_diffuse.rgb, shadedFogColor, 1.0 -smoothstep(0.1, 0.7,earthShade) )); } @@ -208,8 +211,8 @@ else // the faster, full-day version without lightfields mie_angle = 1.0; if (terminator > 3000000.0) - {light_diffuse = vec4 (1.0, 1.0, 1.0, 0.0); - light_ambient = vec4 (0.33, 0.4, 0.5, 0.0); } + {light_diffuse = vec4 (1.0, 1.0, 1.0, 1.0); + light_ambient = vec4 (0.33, 0.4, 0.5, 1.0); } else { @@ -217,12 +220,12 @@ else // the faster, full-day version without lightfields light_diffuse.b = 0.78 + lightArg * 0.21; light_diffuse.g = 0.907 + lightArg * 0.091; light_diffuse.r = 0.904 + lightArg * 0.092; - light_diffuse.a = 0.0; + light_diffuse.a = 1.0; - light_ambient.b = 0.41 + lightArg * 0.08; - light_ambient.g = 0.333 + lightArg * 0.06; light_ambient.r = 0.316 + lightArg * 0.016; - light_ambient.a = 0.0; + light_ambient.g = light_ambient.r * 0.4/0.33; + light_ambient.b = light_ambient.r * 0.5/0.33; + light_ambient.a = 1.0; } light_diffuse = light_diffuse * scattering; @@ -235,6 +238,8 @@ else // the faster, full-day version without lightfields vec3 diffuse = gl_FrontMaterial.diffuse.rgb * max(0.1, n); vec4 ambientColor = gl_FrontLightModelProduct.sceneColor + light_ambient * gl_FrontMaterial.ambient; gl_FrontColor = ambientColor + light_diffuse * vec4(diffuse, 1.0); + gl_FrontColor.a = mie_angle; gl_BackColor.a = mie_angle; + //gl_FrontColor.a = 1.0; gl_BackColor.a = 1.0; diff --git a/Shaders/trivial_transparent.frag b/Shaders/trivial_transparent.frag new file mode 100644 index 000000000..c03ed6e8f --- /dev/null +++ b/Shaders/trivial_transparent.frag @@ -0,0 +1,12 @@ +#version 120 +uniform sampler2D baseTexture; + + +void main(void) +{ + vec4 base = texture2D( baseTexture, gl_TexCoord[0].st); + if (base.a <= 0.01) + discard; + + gl_FragColor = vec4 (1.0, 1.0, 1.0, 1.0); +} diff --git a/Shaders/urban-lightfield.frag b/Shaders/urban-lightfield.frag index 2980701b7..3bb783173 100644 --- a/Shaders/urban-lightfield.frag +++ b/Shaders/urban-lightfield.frag @@ -14,7 +14,7 @@ #define BINARY_SEARCH_COUNT 10 #define BILINEAR_SMOOTH_FACTOR 2.0 -varying vec3 rawpos; +varying vec2 rawpos; varying vec4 ecPosition; varying vec3 VNormal; varying vec3 VTangent; @@ -43,10 +43,11 @@ uniform float terrain_alt; uniform float hazeLayerAltitude; uniform float overcast; uniform float eye_alt; -uniform float snowlevel; +uniform float mysnowlevel; uniform float dust_cover_factor; uniform float wetness; uniform float fogstructure; +uniform float cloud_self_shading; uniform vec3 night_color; const float scale = 1.0; @@ -275,6 +276,8 @@ void main (void) if ( quality_level >= 3.0 ) { linear_search_steps = 20; } + vec3 shadedFogColor = vec3(0.65, 0.67, 0.78); + float effective_scattering = min(scattering, cloud_self_shading); vec3 normal = normalize(VNormal); vec3 tangent = normalize(VTangent); //vec3 binormal = normalize(VBinormal); @@ -442,7 +445,7 @@ if (visibility < avisibility) transmission_arg = transmission_arg + (distance_in_layer/visibility); } // this combines the Weber-Fechner intensity - eqColorFactor = 1.0 - 0.1 * delta_zv/visibility - (1.0 -scattering); + eqColorFactor = 1.0 - 0.1 * delta_zv/visibility - (1.0 - effective_scattering); } else @@ -456,7 +459,7 @@ else transmission_arg = transmission_arg + (distance_in_layer/avisibility); } // this combines the Weber-Fechner intensity - eqColorFactor = 1.0 - 0.1 * delta_zv/avisibility - (1.0 -scattering); + eqColorFactor = 1.0 - 0.1 * delta_zv/avisibility - (1.0 - effective_scattering); } @@ -481,38 +484,50 @@ eShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + term // Mie-like factor -if (lightArg < 5.0) - {intensity = length(hazeColor); - float mie_magnitude = 0.5 * smoothstep(350000.0, 150000.0, terminator-sqrt(2.0 * EarthRadius * terrain_alt)); - 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)) ); + if (lightArg < 10.0) + { + intensity = length(hazeColor); + float mie_magnitude = 0.5 * smoothstep(350000.0, 150000.0, terminator-sqrt(2.0 * EarthRadius * terrain_alt)); + 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)) ); + } + + +intensity = length(hazeColor); + +if (intensity > 0.0) // this needs to be a condition, because otherwise hazeColor doesn't come out correctly + { + // Mie-like factor + + if (lightArg < 10.0) + { + float mie_magnitude = 0.5 * smoothstep(350000.0, 150000.0, terminator-sqrt(2.0 * EarthRadius * terrain_alt)); + 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)) ); + } + + // high altitude desaturation of the haze color + hazeColor = intensity * normalize (mix(hazeColor, intensity * vec3 (1.0,1.0,1.0), 0.7* smoothstep(5000.0, 50000.0, alt))); + + // blue hue of haze + + hazeColor.x = hazeColor.x * 0.83; + hazeColor.y = hazeColor.y * 0.9; + + + // additional blue in indirect light + float fade_out = max(0.65 - 0.3 *overcast, 0.45); + 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 + 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(VNormal,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)); } -// high altitude desaturation of the haze color - -intensity = length(hazeColor); -hazeColor = intensity * normalize (mix(hazeColor, intensity * vec3 (1.0,1.0,1.0), 0.7* smoothstep(5000.0, 50000.0, alt))); - -// blue hue of haze - -hazeColor.x = hazeColor.x * 0.83; -hazeColor.y = hazeColor.y * 0.9; - - -// additional blue in indirect light -float fade_out = max(0.65 - 0.3 *overcast, 0.45); -intensity = length(hazeColor); -hazeColor = intensity * normalize(mix(hazeColor, 1.5* vec3 (0.45, 0.6, 0.8), 1.0 -smoothstep(0.25, fade_out,eShade) )); - -// change haze color to blue hue for strong fogging -hazeColor = intensity * normalize(mix(hazeColor, 2.0 * vec3 (0.55, 0.6, 0.8), (1.0-smoothstep(0.3,0.8,eqColorFactor)))); - - -// reduce haze intensity when looking at shaded surfaces, only in terminator region - -float shadow = mix( min(1.0 + dot(VNormal,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)); - - finalColor.xyz = mix(eqColorFactor * hazeColor * eShade, finalColor.xyz,transmission); diff --git a/Shaders/urban-lightfield.vert b/Shaders/urban-lightfield.vert index 8e851f924..42ad2d29f 100644 --- a/Shaders/urban-lightfield.vert +++ b/Shaders/urban-lightfield.vert @@ -21,12 +21,9 @@ varying vec3 relPos; -varying vec3 rawPos; - +varying vec2 rawPos; varying vec3 VNormal; -//varying vec3 Normal; varying vec3 VTangent; -//varying vec3 VBinormal; varying vec4 ecPosition; varying vec4 constantColor; varying vec3 light_diffuse; @@ -34,7 +31,6 @@ varying vec3 light_diffuse; varying float yprime_alt; varying float mie_angle; -//varying float steepness; uniform int colorMode; @@ -46,6 +42,7 @@ uniform float visibility; uniform float overcast; uniform float ground_scattering; uniform float eye_alt; +uniform float moonlight; attribute vec3 tangent;//, binormal; @@ -73,6 +70,8 @@ void main() vec4 light_ambient; + vec3 shadedFogColor = vec3(0.65, 0.67, 0.78); + vec3 moonLightColor = vec3 (0.095, 0.095, 0.15) * moonlight; //float yprime_alt; float yprime; @@ -81,7 +80,7 @@ void main() float vertex_alt; float scattering; - rawPos = gl_Vertex.xyz; + rawPos = gl_Vertex.xy; steepness = dot(normalize(gl_Normal), vec3 (0.0, 0.0, 1.0)); VNormal = normalize(gl_NormalMatrix * gl_Normal); ecPosition = gl_ModelViewMatrix * gl_Vertex; @@ -173,7 +172,7 @@ if (terminator < 1000000.0) // the full, sunrise and sunset computation lightArg = (terminator-yprime_alt)/100000.0; // directional scattering for low sun - if (lightArg < 5.0) + if (lightArg < 10.0) {mie_angle = (0.5 * dot(normalize(relPos), normalize(lightFull)) ) + 0.5;} else {mie_angle = 1.0;} @@ -187,24 +186,24 @@ if (terminator < 1000000.0) // the full, sunrise and sunset computation light_diffuse = light_diffuse * scattering; - light_ambient.b = light_func(lightArg, 0.000506, 0.131, -3.315, 0.000457, 0.5); - light_ambient.g = light_func(lightArg, 2.264e-05, 0.134, 0.967, 3.66e-05, 0.4); light_ambient.r = light_func(lightArg, 0.236, 0.253, 1.073, 0.572, 0.33); - light_ambient.a = 0.0; - + light_ambient.g = light_ambient.r * 0.4/0.33; + light_ambient.b = light_ambient.r * 0.5/0.33; + light_ambient.a = 1.0; // correct ambient light intensity and hue before sunrise if (earthShade < 0.5) { - light_ambient = light_ambient * (0.7 + 0.3 * smoothstep(0.2, 0.5, earthShade)); - intensity = length(light_ambient.xyz); + //light_ambient = light_ambient * (0.7 + 0.3 * smoothstep(0.2, 0.5, earthShade)); + intensity = length(light_ambient.rgb); - light_ambient.xyz = intensity * normalize(mix(light_ambient.xyz, vec3 (0.45, 0.6, 0.8), 1.0 -smoothstep(0.1, 0.8,earthShade) )); + light_ambient.rgb = intensity * normalize(mix(light_ambient.xyz, shadedFogColor, 1.0 -smoothstep(0.1, 0.8,earthShade) )); + light_ambient.rgb = light_ambient.rgb + moonLightColor * (1.0 - smoothstep(0.4, 0.5, earthShade)); intensity = length(light_diffuse.xyz); - light_diffuse.xyz = intensity * normalize(mix(light_diffuse.xyz, vec3 (0.45, 0.6, 0.8), 1.0 -smoothstep(0.1, 0.7,earthShade) )); + light_diffuse.xyz = intensity * normalize(mix(light_diffuse.xyz, shadedFogColor, 1.0 -smoothstep(0.1, 0.7,earthShade) )); } diff --git a/Shaders/water_lightfield.frag b/Shaders/water_lightfield.frag index 28af9e833..e83c949a5 100644 --- a/Shaders/water_lightfield.frag +++ b/Shaders/water_lightfield.frag @@ -4,31 +4,26 @@ // © Michael Horsch - 2005 // Major update and revisions - 2011-10-07 // © Emilian Huminiuc and Vivian Meazza +// ported to lightfield shading Thorsten Renk 2012 #version 120 uniform sampler2D water_normalmap; -//uniform sampler2D water_reflection; uniform sampler2D water_dudvmap; -//uniform sampler2D water_reflection_grey; uniform sampler2D sea_foam; uniform sampler2D perlin_normalmap; uniform sampler3D Noise; uniform float saturation, Overcast, WindE, WindN; -//uniform float CloudCover0, CloudCover1, CloudCover2, CloudCover3, CloudCover4; uniform float osg_SimulationTime; -//uniform int Status; varying vec4 waterTex1; //moving texcoords varying vec4 waterTex2; //moving texcoords varying vec4 waterTex4; //viewts -//varying vec4 ecPosition; varying vec3 viewerdir; varying vec3 lightdir; -//varying vec3 normal; -varying vec3 specular_light; +//varying vec3 specular_light; varying vec3 relPos; varying float earthShade; @@ -46,17 +41,23 @@ uniform float normalmap_dds; uniform float hazeLayerAltitude; uniform float terminator; -uniform float terrain_alt; +uniform float terrain_alt; uniform float avisibility; uniform float visibility; uniform float overcast; uniform float scattering; uniform float ground_scattering; +uniform float cloud_self_shading; uniform float eye_alt; uniform float sea_r; uniform float sea_g; uniform float sea_b; + +vec3 specular_light; + +//uniform int wquality_level; + const float terminator_width = 200000.0; const float EarthRadius = 5800000.0; ////fog "include" ///// @@ -89,6 +90,9 @@ Wave wave1 = Wave(2.0, 0.5, 1.3, vec2(0.97, -0.25)); Wave wave2 = Wave(1.0, 1.0, 0.6, vec2(0.95, -0.3)); Wave wave3 = Wave(2.0, 0.5, 1.4, vec2(0.99, 0.1)); + + + float evaluateWave(in Wave w, vec2 pos, float t) { return w.amp * sin( dot(w.dir, pos) * w.freq + t * w.phase); @@ -115,7 +119,7 @@ void sumWaves(float angle, float dangle, float windScale, float factor, out floa { mat4 RotationMatrix; float deriv; - vec4 P = waterTex1 * 1024.0; + vec4 P = waterTex1 * 1024; rotationmatrix(radians(angle + dangle * windScale + 0.6 * sin(P.x * factor)), RotationMatrix); P *= RotationMatrix; @@ -174,9 +178,9 @@ if (eye_alt < 30000.0) 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)); + return fade_mix * exp(-targ*targ - pow(targ,4.0)) + (1.0 - fade_mix) * exp(-targ - pow(targ,4.0)); } -else +else { return exp(- targ * targ - pow(targ,4.0)); } @@ -186,6 +190,10 @@ else void main(void) { + + vec3 shadedFogColor = vec3(0.65, 0.67, 0.78); + float effective_scattering = min(scattering, cloud_self_shading); + float dist = length(relPos); const vec4 sca = vec4(0.005, 0.005, 0.005, 0.005); const vec4 sca2 = vec4(0.02, 0.02, 0.02, 0.02); @@ -224,35 +232,36 @@ void main(void) // we only need detail in the near zone or where the sun reflection is int detail_flag; - if ((dist > 15000.0) && (dot(normalize(vec3 (lightdir.x, lightdir.y, 0.0) ), normalize(relPos)) < 0.7 )) {detail_flag = 0;} + if ((dist > 15000.0) && (dot(normalize(vec3 (lightdir.x, lightdir.y, 0.0) ), normalize(relPos)) < 0.7 )) {detail_flag = 0;} else {detail_flag = 1;} - + + //detail_flag = 1; // sine waves float ddx, ddx1, ddx2, ddx3, ddy, ddy1, ddy2, ddy3; - + float angle; if (detail_flag == 1) { - float angle = 0.0; + angle = 0.0; wave0.freq = WaveFreq ; wave0.amp = WaveAmp; - wave0.dir = vec2(cos(radians(angle)), sin(radians(angle))); + wave0.dir = vec2 (0.0, 1.0); //vec2(cos(radians(angle)), sin(radians(angle))); - angle -= 45.0; + angle -= 45; wave1.freq = WaveFreq * 2.0 ; wave1.amp = WaveAmp * 1.25; - wave1.dir = vec2(cos(radians(angle)), sin(radians(angle))); + wave1.dir = vec2(0.70710, -0.7071); //vec2(cos(radians(angle)), sin(radians(angle))); - angle += 30.0; + angle += 30; wave2.freq = WaveFreq * 3.5; wave2.amp = WaveAmp * 0.75; - wave2.dir = vec2(cos(radians(angle)), sin(radians(angle))); + wave2.dir = vec2(0.96592, -0.2588);// vec2(cos(radians(angle)), sin(radians(angle))); - angle -= 50.0; + angle -= 50; wave3.freq = WaveFreq * 3.0 ; wave3.amp = WaveAmp * 0.75; - wave3.dir = vec2(cos(radians(angle)), sin(radians(angle))); + wave3.dir = vec2(0.42261, -0.9063); //vec2(cos(radians(angle)), sin(radians(angle))); // sum waves @@ -268,28 +277,29 @@ void main(void) wave0.freq = WaveFreq ; wave0.amp = waveamp; - wave0.dir = vec2(cos(radians(angle)), sin(radians(angle))); + wave0.dir = vec2 (0.0, 1.0); //vec2(cos(radians(angle)), sin(radians(angle))); - angle -= 20.0; + angle -= 20; wave1.freq = WaveFreq * 2.0 ; wave1.amp = waveamp * 1.25; - wave1.dir = vec2(cos(radians(angle)), sin(radians(angle))); + wave1.dir = vec2(0.93969, -0.34202);// vec2(cos(radians(angle)), sin(radians(angle))); - angle += 35.0; + angle += 35; wave2.freq = WaveFreq * 3.5; wave2.amp = waveamp * 0.75; - wave2.dir = vec2(cos(radians(angle)), sin(radians(angle))); + wave2.dir = vec2(0.965925, 0.25881); //vec2(cos(radians(angle)), sin(radians(angle))); - angle -= 45.0; + angle -= 45; wave3.freq = WaveFreq * 3.0 ; wave3.amp = waveamp * 0.75; - wave3.dir = vec2(cos(radians(angle)), sin(radians(angle))); + wave3.dir = vec2(0.866025, -0.5); //vec2(cos(radians(angle)), sin(radians(angle))); ddx2 = 0.0, ddy2 = 0.0; sumWaves(WaveAngle + WaveDAngle, -1.5, windScale, WaveFactor, ddx2, ddy2); - + ddx3 = 0.0, ddy3 = 0.0; sumWaves(WaveAngle + WaveDAngle, 1.5, windScale, WaveFactor, ddx3, ddy3); + } // end sine stuff @@ -300,9 +310,9 @@ void main(void) vec4 disdis = texture2D(water_dudvmap, vec2(waterTex2 * tscale)* windScale) * 2.0 - 1.0; - vec4 vNorm; - + vec4 vNorm; + //normalmaps vec4 nmap = texture2D(water_normalmap, vec2(waterTex1 + disdis * sca2) * windScale) * 2.0 - 1.0; vec4 nmap1 = texture2D(perlin_normalmap, vec2(waterTex1 + disdis * sca2) * windScale) * 2.0 - 1.0; @@ -318,31 +328,33 @@ void main(void) vNorm = normalize(mix(nmap, nmap1, mixFactor) * waveRoughness); if (detail_flag == 1) {vNorm.r += ddx + ddx1 + ddx2 + ddx3;} - if (normalmap_dds > 0) - vNorm = -vNorm; //dds fix + + if (normalmap_dds > 0) + {vNorm = -vNorm;} //dds fix + //load reflection - + vec4 refl ; refl.r = sea_r; refl.g = sea_g; refl.b = sea_b; - refl.a = 1.0; - + refl.a = 1.0; + float intensity; // de-saturate for reduced light - refl.rgb = mix(refl.rgb, vec3 (0.248, 0.248, 0.248), 1.0 - smoothstep(0.3, 0.7, ground_scattering)); + refl.rgb = mix(refl.rgb, vec3 (0.248, 0.248, 0.248), 1.0 - smoothstep(0.1, 0.8, ground_scattering)); // de-saturate light for overcast haze intensity = length(refl.rgb); - refl.rgb = mix(refl.rgb, intensity * vec3 (1.0, 1.0, 1.0), smoothstep(0.1, 0.8, overcast)); + refl.rgb = mix(refl.rgb, intensity * vec3 (1.0, 1.0, 1.0), 0.5 * smoothstep(0.1, 0.9, overcast)); vec3 N; - if (detail_flag == 1) - { + + vec3 N0 = vec3(texture2D(water_normalmap, vec2(waterTex1 + disdis * sca2) * windScale) * 2.0 - 1.0); vec3 N1 = vec3(texture2D(perlin_normalmap, vec2(waterTex1 + disdis * sca) * windScale) * 2.0 - 1.0); @@ -350,6 +362,8 @@ void main(void) N0 += vec3(texture2D(water_normalmap, vec2(waterTex1 * tscale) * windScale) * 2.0 - 1.0); N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex2 * tscale) * windScale) * 2.0 - 1.0); + + rotationmatrix(radians(2.0 * sin(osg_SimulationTime * 0.005)), RotationMatrix); N0 += vec3(texture2D(water_normalmap, vec2(waterTex2 * RotationMatrix * (tscale + sca2)) * windScale) * 2.0 - 1.0); N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex2 * RotationMatrix * (tscale + sca2)) * windScale) * 2.0 - 1.0); @@ -357,6 +371,7 @@ void main(void) rotationmatrix(radians(-4.0 * sin(osg_SimulationTime * 0.003)), RotationMatrix); N0 += vec3(texture2D(water_normalmap, vec2(waterTex1 * RotationMatrix + disdis * sca2) * windScale) * 2.0 - 1.0); N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex1 * RotationMatrix + disdis * sca) * windScale) * 2.0 - 1.0); + N0 *= windEffect_low; N1 *= windEffect_low; @@ -366,17 +381,16 @@ void main(void) N = normalize(mix(Normal + N0, Normal + N1, mixFactor) * waveRoughness); - if (normalmap_dds > 0) - N = -N; //dds fix - } - else - {N = vec3 (0.0, 0.0, 1.0);} - - //float lightArg = (terminator-yprime_alt)/100000.0; + if (normalmap_dds > 0) + {N = -N;} //dds fix + + specular_light = gl_Color.rgb; + + vec3 specular_color = vec3(specular_light) * pow(max(0.0, dot(N, Hv)), water_shininess) * 6.0; vec4 specular = vec4(specular_color, 0.5); @@ -391,20 +405,15 @@ void main(void) vec4 ambient_light; - - ambient_light.rgb = specular_light.rgb; + //intensity = length(specular_light.rgb); + ambient_light.rgb = max(specular_light.rgb, vec3(0.1, 0.1, 0.1)); + //ambient_light.rgb = max(intensity * normalize(vec3 (0.33, 0.4, 0.5)), vec3 (0.1,0.1,0.1)); ambient_light.a = 1.0; - - + + vec4 finalColor; - //if(cover >= 1.5) - //if (ground_scattering > 0.4) - // { - // finalColor = refl + specular; - // } else { - // finalColor = refl; - // } + finalColor = refl + specular * smoothstep(0.3, 0.6, ground_scattering); @@ -423,7 +432,7 @@ void main(void) finalColor = mix(finalColor, max(finalColor, finalColor + foam_texel), smoothstep(0.01, 0.50, N.g)); } } - + finalColor *= ambient_light; @@ -457,10 +466,9 @@ float ct = dot(vec3(0.0, 0.0, 1.0), relPos)/dist; if (delta_z > 0.0) // we're inside the layer { - if (ct < 0.0) // we look down + if (ct < 0.0) // we look down { distance_in_layer = dist; - //lambda = visibility; vAltitude = min(distance_in_layer,min(visibility,avisibility)) * ct; delta_zv = delta_z - vAltitude; } @@ -469,28 +477,27 @@ if (delta_z > 0.0) // we're inside the layer H = dist * ct; if (H > delta_z) {distance_in_layer = dist/H * delta_z;} else {distance_in_layer = dist;} - //lambda = visibility; vAltitude = min(distance_in_layer,visibility) * ct; - delta_zv = delta_z - vAltitude; + delta_zv = delta_z - vAltitude; } } else // we see the layer from above, delta_z < 0.0 - { + { H = dist * -ct; if (H < (-delta_z)) // we don't see into the layer at all, aloft visibility is the only fading { distance_in_layer = 0.0; delta_zv = 0.0; - } + } else { vAltitude = H + delta_z; - distance_in_layer = vAltitude/H * dist; + distance_in_layer = vAltitude/H * dist; vAltitude = min(distance_in_layer,visibility) * (-ct); delta_zv = vAltitude; - } + } } - + // ground haze cannot be thinner than aloft visibility in the model, // so we need to use aloft visibility otherwise @@ -506,14 +513,14 @@ if (visibility < avisibility) { transmission_arg = transmission_arg + (distance_in_layer/visibility); // this combines the Weber-Fechner intensity - eqColorFactor = 1.0 - 0.1 * delta_zv/visibility - (1.0 -scattering); + eqColorFactor = 1.0 - 0.1 * delta_zv/visibility - (1.0 -effective_scattering); } -else +else { transmission_arg = transmission_arg + (distance_in_layer/avisibility); // this combines the Weber-Fechner intensity - eqColorFactor = 1.0 - 0.1 * delta_zv/avisibility - (1.0 -scattering); + eqColorFactor = 1.0 - 0.1 * delta_zv/avisibility - (1.0 -effective_scattering); } @@ -526,7 +533,6 @@ if (eqColorFactor < 0.2) eqColorFactor = 0.2; float lightArg = (terminator-yprime_alt)/100000.0; vec3 hazeColor; -//hazeColor.rgb = specular_light.rgb; 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); @@ -536,42 +542,42 @@ float eShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width // Mie-like factor -if (lightArg < 5.0) +if (lightArg < 10.0) {intensity = length(hazeColor); float mie_magnitude = 0.5 * smoothstep(350000.0, 150000.0, terminator-sqrt(2.0 * EarthRadius * terrain_alt)); - 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)) ); + 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)) ); } // high altitude desaturation of the haze color intensity = length(hazeColor); -hazeColor = intensity * normalize (mix(hazeColor, intensity * vec3 (1.0,1.0,1.0), 0.7* smoothstep(5000.0, 50000.0, eye_alt))); - -// blue hue of haze - -hazeColor.x = hazeColor.x * 0.83; -hazeColor.y = hazeColor.y * 0.9; -// additional blue in indirect light -float fade_out = max(0.65 - 0.3 *overcast, 0.45); -intensity = length(hazeColor); -hazeColor = intensity * normalize(mix(hazeColor, 1.5* vec3 (0.45, 0.6, 0.8), 1.0 -smoothstep(0.25, fade_out,eShade) )); +if (intensity > 0.0) // this needs to be a condition, because otherwise hazeColor doesn't come out correctly + { + hazeColor = intensity * normalize (mix(hazeColor, intensity * vec3 (1.0,1.0,1.0), 0.7* smoothstep(5000.0, 50000.0, eye_alt))); -// change haze color to blue hue for strong fogging -//intensity = length(hazeColor); -hazeColor = intensity * normalize(mix(hazeColor, 2.0 * vec3 (0.55, 0.6, 0.8), (1.0-smoothstep(0.3,0.8,eqColorFactor)))); + // blue hue of haze + + hazeColor.x = hazeColor.x * 0.83; + hazeColor.y = hazeColor.y * 0.9; -// reduce haze intensity when looking at shaded surfaces, only in terminator region + // additional blue in indirect light + float fade_out = max(0.65 - 0.3 *overcast, 0.45); + intensity = length(hazeColor); + hazeColor = intensity * normalize(mix(hazeColor, 1.5* shadedFogColor, 1.0 -smoothstep(0.25, fade_out,eShade) )); -//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)); + // change haze color to blue hue for strong fogging + hazeColor = intensity * normalize(mix(hazeColor, shadedFogColor, (1.0-smoothstep(0.5,0.9,eqColorFactor)))); + } + + finalColor.rgb = mix(eqColorFactor * hazeColor * eShade, finalColor.rgb,transmission); } - gl_FragColor = finalColor; + gl_FragColor = finalColor; } diff --git a/Shaders/water_lightfield.vert b/Shaders/water_lightfield.vert index ecfafce3e..c6803a1dc 100644 --- a/Shaders/water_lightfield.vert +++ b/Shaders/water_lightfield.vert @@ -10,13 +10,12 @@ varying vec4 waterTex1; varying vec4 waterTex2; varying vec4 waterTex4; -//varying vec4 ecPosition; varying vec3 relPos; -varying vec3 specular_light; + varying vec3 viewerdir; varying vec3 lightdir; -//varying vec3 normal; + varying float earthShade; varying float yprime_alt; @@ -24,7 +23,6 @@ varying float mie_angle; uniform float osg_SimulationTime; uniform float WindE, WindN; - uniform float hazeLayerAltitude; uniform float terminator; uniform float terrain_alt; @@ -33,6 +31,9 @@ uniform float visibility; uniform float overcast; uniform float ground_scattering; + +vec3 specular_light; + // This is the value used in the skydome scattering shader - use the same here for consistency? const float EarthRadius = 5800000.0; const float terminator_width = 200000.0; @@ -68,8 +69,9 @@ void main(void) { mat4 RotationMatrix; - // vec3 N = normalize(gl_Normal); - // normal = N; + + + vec3 shadedFogColor = vec3(0.65, 0.67, 0.78); vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex; @@ -157,18 +159,19 @@ if (terminator < 1000000.0) // the full, sunrise and sunset computation specular_light.g = light_func(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0); specular_light.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0); - specular_light = specular_light * scattering; + specular_light = max(specular_light * scattering, vec3 (0.05, 0.05, 0.05)); - // correct ambient light intensity and hue before sunrise - if (earthShade < 0.5) - { intensity = length(specular_light.rgb); - specular_light.xyz = intensity * normalize(mix(specular_light.xyz, vec3 (0.45, 0.6, 0.8), 1.0 -smoothstep(0.1, 0.7,earthShade) )); - } + specular_light.rgb = intensity * normalize(mix(specular_light.rgb, shadedFogColor, 1.0 -smoothstep(0.1, 0.6,ground_scattering) )); + + // correct ambient light intensity and hue before sunrise - seems unnecessary and create artefacts though... + //if (earthShade < 0.5) + //{ + //specular_light.rgb = intensity * normalize(mix(specular_light.rgb, shadedFogColor, 1.0 -smoothstep(0.1, 0.7,earthShade) )); + //} // directional scattering for low sun if (lightArg < 10.0) - //{mie_angle = (0.5 * dot(normalize(relPos), normalize(lightFull)) ) + 0.5;} {mie_angle = (0.5 * dot(normalize(relPos), lightdir) ) + 0.5;} else {mie_angle = 1.0;} @@ -221,6 +224,8 @@ else // the faster, full-day version without lightfields } +gl_FrontColor.rgb = specular_light; +gl_BackColor.rgb = gl_FrontColor.rgb; } diff --git a/Shaders/water_lightfield_lr.frag b/Shaders/water_lightfield_lr.frag index f475cb689..1a3cca30d 100644 --- a/Shaders/water_lightfield_lr.frag +++ b/Shaders/water_lightfield_lr.frag @@ -23,7 +23,7 @@ varying vec4 waterTex2; //moving texcoords varying vec4 waterTex4; //viewts varying vec3 viewerdir; varying vec3 lightdir; -varying vec3 specular_light; +//varying vec3 specular_light; varying vec3 relPos; varying float earthShade; @@ -47,13 +47,14 @@ uniform float visibility; uniform float overcast; uniform float scattering; uniform float ground_scattering; +uniform float cloud_self_shading; uniform float eye_alt; uniform float sea_r; uniform float sea_g; uniform float sea_b; -uniform float ylimit; -uniform float zlimit1; -uniform float zlimit2; + + +vec3 specular_light; //uniform int wquality_level; @@ -190,10 +191,8 @@ void main(void) { - -if ((gl_FragCoord.y < ylimit) && (gl_FragCoord.x > zlimit1) && (gl_FragCoord.x < zlimit2)) - {discard;} - + vec3 shadedFogColor = vec3(0.65, 0.67, 0.78); + float effective_scattering = min(scattering, cloud_self_shading); float dist = length(relPos); const vec4 sca = vec4(0.005, 0.005, 0.005, 0.005); @@ -259,10 +258,10 @@ if ((gl_FragCoord.y < ylimit) && (gl_FragCoord.x > zlimit1) && (gl_FragCoord.x < wave2.amp = WaveAmp * 0.75; wave2.dir = vec2(0.96592, -0.2588);// vec2(cos(radians(angle)), sin(radians(angle))); - //angle -= 50; - //wave3.freq = WaveFreq * 3.0 ; - //wave3.amp = WaveAmp * 0.75; - //wave3.dir = vec2(0.42261, -0.9063); //vec2(cos(radians(angle)), sin(radians(angle))); + angle -= 50; + wave3.freq = WaveFreq * 3.0 ; + wave3.amp = WaveAmp * 0.75; + wave3.dir = vec2(0.42261, -0.9063); //vec2(cos(radians(angle)), sin(radians(angle))); // sum waves @@ -276,7 +275,7 @@ if ((gl_FragCoord.y < ylimit) && (gl_FragCoord.x > zlimit1) && (gl_FragCoord.x < /* angle = 0.0; float waveamp = WaveAmp * 0.75; - + wave0.freq = WaveFreq ; wave0.amp = waveamp; wave0.dir = vec2 (0.0, 1.0); //vec2(cos(radians(angle)), sin(radians(angle))); @@ -295,13 +294,13 @@ if ((gl_FragCoord.y < ylimit) && (gl_FragCoord.x > zlimit1) && (gl_FragCoord.x < wave3.freq = WaveFreq * 3.0 ; wave3.amp = waveamp * 0.75; wave3.dir = vec2(0.866025, -0.5); //vec2(cos(radians(angle)), sin(radians(angle))); - */ - //ddx2 = 0.0, ddy2 = 0.0; - //sumWaves(WaveAngle + WaveDAngle, -1.5, windScale, WaveFactor, ddx2, ddy2); + + ddx2 = 0.0, ddy2 = 0.0; + sumWaves(WaveAngle + WaveDAngle, -1.5, windScale, WaveFactor, ddx2, ddy2); - //ddx3 = 0.0, ddy3 = 0.0; - //sumWaves(WaveAngle + WaveDAngle, 1.5, windScale, WaveFactor, ddx3, ddy3); - + ddx3 = 0.0, ddy3 = 0.0; + sumWaves(WaveAngle + WaveDAngle, 1.5, windScale, WaveFactor, ddx3, ddy3); + */ } // end sine stuff @@ -319,21 +318,20 @@ if ((gl_FragCoord.y < ylimit) && (gl_FragCoord.x > zlimit1) && (gl_FragCoord.x < vec4 nmap = texture2D(water_normalmap, vec2(waterTex1 + disdis * sca2) * windScale) * 2.0 - 1.0; vec4 nmap1 = texture2D(perlin_normalmap, vec2(waterTex1 + disdis * sca2) * windScale) * 2.0 - 1.0; - rotationmatrix(radians(3.0 * sin(osg_SimulationTime * 0.0075)), RotationMatrix); - nmap += texture2D(water_normalmap, vec2(waterTex2 * RotationMatrix * tscale) * windScale) * 2.0 - 1.0; - nmap1 += texture2D(perlin_normalmap, vec2(waterTex2 * RotationMatrix * tscale) * windScale) * 2.0 - 1.0; + //rotationmatrix(radians(3.0 * sin(osg_SimulationTime * 0.0075)), RotationMatrix); + //nmap += texture2D(water_normalmap, vec2(waterTex2 * RotationMatrix * tscale) * windScale) * 2.0 - 1.0; + //nmap1 += texture2D(perlin_normalmap, vec2(waterTex2 * RotationMatrix * tscale) * windScale) * 2.0 - 1.0; nmap *= windEffect_low; nmap1 *= windEffect_low; // mix water and noise, modulated by factor vNorm = normalize(mix(nmap, nmap1, mixFactor) * waveRoughness); - if (detail_flag == 1) {vNorm.r += ddx + ddx1;} + if (detail_flag == 1) {vNorm.r += ddx + ddx1 + ddx2 + ddx3;} + if (normalmap_dds > 0) {vNorm = -vNorm;} //dds fix - - //load reflection @@ -348,7 +346,7 @@ if ((gl_FragCoord.y < ylimit) && (gl_FragCoord.x > zlimit1) && (gl_FragCoord.x < float intensity; // de-saturate for reduced light - refl.rgb = mix(refl.rgb, vec3 (0.248, 0.248, 0.248), 1.0 - smoothstep(0.1, 0.8, ground_scattering)); + refl.rgb = mix(refl.rgb, vec3 (0.248, 0.248, 0.248), 1.0 - smoothstep(0.1, 0.8, ground_scattering)); // de-saturate light for overcast haze intensity = length(refl.rgb); @@ -356,22 +354,43 @@ if ((gl_FragCoord.y < ylimit) && (gl_FragCoord.x > zlimit1) && (gl_FragCoord.x < vec3 N; + + + + vec3 N0 = vec3(texture2D(water_normalmap, vec2(waterTex1 + disdis * sca2) * windScale) * 2.0 - 1.0); + vec3 N1 = vec3(texture2D(perlin_normalmap, vec2(waterTex1 + disdis * sca) * windScale) * 2.0 - 1.0); + + N0 += vec3(texture2D(water_normalmap, vec2(waterTex1 * tscale) * windScale) * 2.0 - 1.0); + N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex2 * tscale) * windScale) * 2.0 - 1.0); + + rotationmatrix(radians(2.0 * sin(osg_SimulationTime * 0.005)), RotationMatrix); - vec3 N0 = vec3(texture2D(water_normalmap, vec2(waterTex2 * RotationMatrix * (tscale + sca2)) * windScale) * 2.0 - 1.0); - vec3 N1 = vec3(texture2D(perlin_normalmap, vec2(waterTex2 * RotationMatrix * (tscale + sca2)) * windScale) * 2.0 - 1.0); + N0 += vec3(texture2D(water_normalmap, vec2(waterTex2 * RotationMatrix * (tscale + sca2)) * windScale) * 2.0 - 1.0); + N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex2 * RotationMatrix * (tscale + sca2)) * windScale) * 2.0 - 1.0); + + rotationmatrix(radians(-4.0 * sin(osg_SimulationTime * 0.003)), RotationMatrix); + N0 += vec3(texture2D(water_normalmap, vec2(waterTex1 * RotationMatrix + disdis * sca2) * windScale) * 2.0 - 1.0); + N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex1 * RotationMatrix + disdis * sca) * windScale) * 2.0 - 1.0); N0 *= windEffect_low; N1 *= windEffect_low; - N0.r += (ddx + ddx1); - N0.g += (ddy + ddy1); + N0.r += (ddx + ddx1 + ddx2 + ddx3); + N0.g += (ddy + ddy1 + ddy2 + ddy3); N = normalize(mix(Normal + N0, Normal + N1, mixFactor) * waveRoughness); - if (normalmap_dds > 0) + if (normalmap_dds > 0) {N = -N;} //dds fix + + + + + + specular_light = gl_Color.rgb; + vec3 specular_color = vec3(specular_light) * pow(max(0.0, dot(N, Hv)), water_shininess) * 6.0; @@ -387,8 +406,9 @@ if ((gl_FragCoord.y < ylimit) && (gl_FragCoord.x > zlimit1) && (gl_FragCoord.x < vec4 ambient_light; - + //intensity = length(specular_light.rgb); ambient_light.rgb = max(specular_light.rgb, vec3(0.1, 0.1, 0.1)); + //ambient_light.rgb = max(intensity * normalize(vec3 (0.33, 0.4, 0.5)), vec3 (0.1,0.1,0.1)); ambient_light.a = 1.0; @@ -402,7 +422,7 @@ if ((gl_FragCoord.y < ylimit) && (gl_FragCoord.x > zlimit1) && (gl_FragCoord.x < if (dist < 10000.0) { - float foamSlope = 0.12 + 0.1 * windScale; + float foamSlope = 0.10 + 0.1 * windScale; vec4 foam_texel = texture2D(sea_foam, vec2(waterTex2 * tscale) * 25.0); @@ -450,7 +470,6 @@ if (delta_z > 0.0) // we're inside the layer if (ct < 0.0) // we look down { distance_in_layer = dist; - //lambda = visibility; vAltitude = min(distance_in_layer,min(visibility,avisibility)) * ct; delta_zv = delta_z - vAltitude; } @@ -459,7 +478,6 @@ if (delta_z > 0.0) // we're inside the layer H = dist * ct; if (H > delta_z) {distance_in_layer = dist/H * delta_z;} else {distance_in_layer = dist;} - //lambda = visibility; vAltitude = min(distance_in_layer,visibility) * ct; delta_zv = delta_z - vAltitude; } @@ -496,14 +514,14 @@ if (visibility < avisibility) { transmission_arg = transmission_arg + (distance_in_layer/visibility); // this combines the Weber-Fechner intensity - eqColorFactor = 1.0 - 0.1 * delta_zv/visibility - (1.0 -scattering); + eqColorFactor = 1.0 - 0.1 * delta_zv/visibility - (1.0 -effective_scattering); } else { transmission_arg = transmission_arg + (distance_in_layer/avisibility); // this combines the Weber-Fechner intensity - eqColorFactor = 1.0 - 0.1 * delta_zv/avisibility - (1.0 -scattering); + eqColorFactor = 1.0 - 0.1 * delta_zv/avisibility - (1.0 -effective_scattering); } @@ -516,7 +534,6 @@ if (eqColorFactor < 0.2) eqColorFactor = 0.2; float lightArg = (terminator-yprime_alt)/100000.0; vec3 hazeColor; -//hazeColor.rgb = specular_light.rgb; 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); @@ -535,33 +552,33 @@ if (lightArg < 10.0) // high altitude desaturation of the haze color intensity = length(hazeColor); -hazeColor = intensity * normalize (mix(hazeColor, intensity * vec3 (1.0,1.0,1.0), 0.7* smoothstep(5000.0, 50000.0, eye_alt))); - -// blue hue of haze - -hazeColor.x = hazeColor.x * 0.83; -hazeColor.y = hazeColor.y * 0.9; -// additional blue in indirect light -float fade_out = max(0.65 - 0.3 *overcast, 0.45); -intensity = length(hazeColor); -hazeColor = intensity * normalize(mix(hazeColor, 1.5* vec3 (0.45, 0.6, 0.8), 1.0 -smoothstep(0.25, fade_out,eShade) )); +if (intensity > 0.0) // this needs to be a condition, because otherwise hazeColor doesn't come out correctly + { + hazeColor = intensity * normalize (mix(hazeColor, intensity * vec3 (1.0,1.0,1.0), 0.7* smoothstep(5000.0, 50000.0, eye_alt))); -// change haze color to blue hue for strong fogging -//intensity = length(hazeColor); -hazeColor = intensity * normalize(mix(hazeColor, 2.0 * vec3 (0.55, 0.6, 0.8), (1.0-smoothstep(0.3,0.8,eqColorFactor)))); + // blue hue of haze + + hazeColor.x = hazeColor.x * 0.83; + hazeColor.y = hazeColor.y * 0.9; -// reduce haze intensity when looking at shaded surfaces, only in terminator region + // additional blue in indirect light + float fade_out = max(0.65 - 0.3 *overcast, 0.45); + intensity = length(hazeColor); + hazeColor = intensity * normalize(mix(hazeColor, 1.5* shadedFogColor, 1.0 -smoothstep(0.25, fade_out,eShade) )); -//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)); + // change haze color to blue hue for strong fogging + hazeColor = intensity * normalize(mix(hazeColor, shadedFogColor, (1.0-smoothstep(0.5,0.9,eqColorFactor)))); + } + + finalColor.rgb = mix(eqColorFactor * hazeColor * eShade, finalColor.rgb,transmission); } - gl_FragColor = finalColor; + gl_FragColor = finalColor; } diff --git a/Textures/Sky/cl_cumulus2.png b/Textures/Sky/cl_cumulus2.png index eb47a43e8..614cd1508 100644 Binary files a/Textures/Sky/cl_cumulus2.png and b/Textures/Sky/cl_cumulus2.png differ diff --git a/Textures/Sky/cl_st.png b/Textures/Sky/cl_st.png index efa1ae37f..ad4e14330 100644 Binary files a/Textures/Sky/cl_st.png and b/Textures/Sky/cl_st.png differ diff --git a/gui/dialogs/environment-settings.xml b/gui/dialogs/environment-settings.xml index f33173e3c..f10423ef2 100644 --- a/gui/dialogs/environment-settings.xml +++ b/gui/dialogs/environment-settings.xml @@ -146,25 +146,61 @@ /environment/snow-level-m - - + + + left 3 0 - + right 3 1 - dust-level + snow-thickness 3 2 0.0 + 0.6 + true + /environment/surface/snow-thickness-factor + + dialog-apply + snow-thickness + + + + + + left + 3 + 3 + + + + + left + 4 + 0 + + + + + right + 4 + 1 + + + + dust-level + 4 + 2 + 0.0 0.7 true /environment/surface/dust-cover-factor @@ -177,27 +213,27 @@ left - 3 + 4 3 left - 4 + 5 0 right - 4 + 5 1 wetness - 4 + 5 2 0.0 0.7 @@ -212,7 +248,7 @@ left - 4 + 5 3 @@ -220,20 +256,20 @@ left - 5 + 6 0 right - 5 + 6 1 lichen-level - 5 + 6 2 0.0 0.7 @@ -248,7 +284,7 @@ left - 5 + 6 3