From 553fd2c171503e1cdc067bdfd9adf88ab955243b Mon Sep 17 00:00:00 2001 From: Thorsten Renk Date: Mon, 17 Mar 2014 08:49:49 +0200 Subject: [PATCH] Cloud shadows for runway shader effect --- Effects/runway.eff | 279 ++++++++++++++++++++++++--------- Shaders/runway-lightfield.frag | 20 +-- 2 files changed, 214 insertions(+), 85 deletions(-) diff --git a/Effects/runway.eff b/Effects/runway.eff index 6ea0e5192..253dc8b6c 100644 --- a/Effects/runway.eff +++ b/Effects/runway.eff @@ -60,9 +60,7 @@ 0.0 false back - - /environment/rain-norm - + /environment/rain-norm /environment/ground-visibility-m @@ -122,31 +120,6 @@ - true @@ -184,36 +157,10 @@ texture[4]/wrap-t texture[4]/internal-format - - 5 - texture[12]/type - texture[12]/image - texture[12]/filter - texture[12]/wrap-s - texture[12]/wrap-t - texture[12]/internal-format - - - 6 - texture[10]/type - texture[10]/image - texture[10]/filter - texture[10]/wrap-s - texture[10]/wrap-t - texture[10]/internal-format - - - 7 - texture[11]/type - texture[11]/image - texture[11]/filter - texture[11]/wrap-s - texture[11]/wrap-t - texture[11]/internal-format - Shaders/terrain-haze-ultra.vert - Shaders/runway-lightfield.frag + Shaders/runway-lightfield.frag + Shaders/cloud-shadowfunc.frag visibility @@ -300,6 +247,211 @@ float moonlight + + cloudpos1_x + float + cloudpos1_x + + + cloudpos1_y + float + cloudpos1_y + + + cloudpos2_x + float + cloudpos2_x + + + cloudpos2_y + float + cloudpos2_y + + + cloudpos3_x + float + cloudpos3_x + + + cloudpos3_y + float + cloudpos3_y + + + cloudpos4_x + float + cloudpos4_x + + + cloudpos4_y + float + cloudpos4_y + + + cloudpos5_x + float + cloudpos5_x + + + cloudpos5_y + float + cloudpos5_y + + + cloudpos6_x + float + cloudpos6_x + + + cloudpos6_y + float + cloudpos6_y + + + cloudpos7_x + float + cloudpos7_x + + + cloudpos7_y + float + cloudpos7_y + + + cloudpos8_x + float + cloudpos8_x + + + cloudpos8_y + float + cloudpos8_y + + + cloudpos9_x + float + cloudpos9_x + + + cloudpos9_y + float + cloudpos9_y + + + cloudpos10_x + float + cloudpos10_x + + + cloudpos10_y + float + cloudpos10_y + + + cloudpos11_x + float + cloudpos11_x + + + cloudpos11_y + float + cloudpos11_y + + + cloudpos12_x + float + cloudpos12_x + + + cloudpos12_y + float + cloudpos12_y + + + cloudpos13_x + float + cloudpos13_x + + + cloudpos13_y + float + cloudpos13_y + + + cloudpos14_x + float + cloudpos14_x + + + cloudpos14_y + float + cloudpos14_y + + + cloudpos15_x + float + cloudpos15_x + + + cloudpos15_y + float + cloudpos15_y + + + cloudpos16_x + float + cloudpos16_x + + + cloudpos16_y + float + cloudpos16_y + + + cloudpos17_x + float + cloudpos17_x + + + cloudpos17_y + float + cloudpos17_y + + + cloudpos18_x + float + cloudpos18_x + + + cloudpos18_y + float + cloudpos18_y + + + cloudpos19_x + float + cloudpos19_x + + + cloudpos19_y + float + cloudpos19_y + + + cloudpos20_x + float + cloudpos20_x + + + cloudpos20_y + float + cloudpos20_y + + + cloud_shadow_flag + int + cloud_shadow_flag + quality_level int @@ -320,21 +472,6 @@ sampler-2d 4 - - mix_texture - sampler-2d - 5 - - - snow_texture - sampler-2d - 6 - - - detail_texture - sampler-2d - 7 - colorMode int diff --git a/Shaders/runway-lightfield.frag b/Shaders/runway-lightfield.frag index ea5545d44..a6df41227 100644 --- a/Shaders/runway-lightfield.frag +++ b/Shaders/runway-lightfield.frag @@ -4,7 +4,6 @@ // 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; @@ -12,13 +11,7 @@ varying vec3 ecViewdir; uniform sampler2D texture; uniform sampler2D NormalTex; -//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; @@ -37,8 +30,10 @@ uniform float wetness; uniform float fogstructure; uniform float snow_thickness_factor; uniform float cloud_self_shading; + uniform int quality_level; uniform int tquality_level; +uniform int cloud_shadow_flag; const float EarthRadius = 5800000.0; const float terminator_width = 200000.0; @@ -48,7 +43,7 @@ float eShade; float yprime_alt; float mie_angle; - +float shadow_func (in float x, in float y, in float noise, in float dist); float rand2D(in vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); @@ -142,7 +137,6 @@ 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); @@ -275,7 +269,6 @@ 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)); water_factor = smoothstep(water_threshold1, water_threshold2 , 0.5 * (noise_5m + (1.0 -noise_1m))) * (1.0 - smoothstep(1000.0, 3000.0, dist)); } @@ -291,8 +284,7 @@ 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 = normal;//vec3 (nvec.x, nvec.y, sqrt(1.0 -pow(nvec.x,2.0) - pow(nvec.y,2.0) )); + n = normal; n = normalize(n); NdotL = dot(n, lightDir); @@ -300,12 +292,12 @@ if ((dist < 5000.0)&& (quality_level > 3) && (wetness>0.0)) if (quality_level > 4) { NdotL = NdotL + (3.0 * N.r + 0.1 * (noise_01m-0.5))* (1.0 - water_factor) ; - //NdotL = NdotL + 3.0 * N.r + 0.1 * (noise_01m-0.5) ; } if (NdotL > 0.0) { + if (cloud_shadow_flag == 1) + {NdotL = NdotL * shadow_func(relPos.x, relPos.y, 1.0, dist);} 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)));