From 572a7203882144b51e241f7a3b0e8d6a9a5395e7 Mon Sep 17 00:00:00 2001 From: Thorsten Renk Date: Tue, 11 Mar 2014 12:25:47 +0200 Subject: [PATCH] Cloud shadows for water shader effect --- Effects/water-inland.eff | 269 +++++++++++++++++++++++-- Effects/water.eff | 367 +++++++++++++++++++++++++--------- Shaders/water_lightfield.frag | 16 +- 3 files changed, 531 insertions(+), 121 deletions(-) diff --git a/Effects/water-inland.eff b/Effects/water-inland.eff index dcb917e79..09796b3c3 100644 --- a/Effects/water-inland.eff +++ b/Effects/water-inland.eff @@ -138,6 +138,48 @@ /sim/rendering/shaders/skydome + + /local-weather/cloud-shadows/cloudpos-x[0] + /local-weather/cloud-shadows/cloudpos-y[0] + /local-weather/cloud-shadows/cloudpos-x[1] + /local-weather/cloud-shadows/cloudpos-y[1] + /local-weather/cloud-shadows/cloudpos-x[2] + /local-weather/cloud-shadows/cloudpos-y[2] + /local-weather/cloud-shadows/cloudpos-x[3] + /local-weather/cloud-shadows/cloudpos-y[3] + /local-weather/cloud-shadows/cloudpos-x[4] + /local-weather/cloud-shadows/cloudpos-y[4] + /local-weather/cloud-shadows/cloudpos-x[5] + /local-weather/cloud-shadows/cloudpos-y[5] + /local-weather/cloud-shadows/cloudpos-x[6] + /local-weather/cloud-shadows/cloudpos-y[6] + /local-weather/cloud-shadows/cloudpos-x[7] + /local-weather/cloud-shadows/cloudpos-y[7] + /local-weather/cloud-shadows/cloudpos-x[8] + /local-weather/cloud-shadows/cloudpos-y[8] + /local-weather/cloud-shadows/cloudpos-x[9] + /local-weather/cloud-shadows/cloudpos-y[9] + /local-weather/cloud-shadows/cloudpos-x[10] + /local-weather/cloud-shadows/cloudpos-y[10] + /local-weather/cloud-shadows/cloudpos-x[11] + /local-weather/cloud-shadows/cloudpos-y[11] + /local-weather/cloud-shadows/cloudpos-x[12] + /local-weather/cloud-shadows/cloudpos-y[12] + /local-weather/cloud-shadows/cloudpos-x[13] + /local-weather/cloud-shadows/cloudpos-y[13] + /local-weather/cloud-shadows/cloudpos-x[14] + /local-weather/cloud-shadows/cloudpos-y[14] + /local-weather/cloud-shadows/cloudpos-x[15] + /local-weather/cloud-shadows/cloudpos-y[15] + /local-weather/cloud-shadows/cloudpos-x[16] + /local-weather/cloud-shadows/cloudpos-y[16] + /local-weather/cloud-shadows/cloudpos-x[17] + /local-weather/cloud-shadows/cloudpos-y[17] + /local-weather/cloud-shadows/cloudpos-x[18] + /local-weather/cloud-shadows/cloudpos-y[18] + /local-weather/cloud-shadows/cloudpos-x[19] + /local-weather/cloud-shadows/cloudpos-y[19] + /local-weather/cloud-shadows/cloud-shadow-flag /environment/sea/color_r @@ -273,27 +315,6 @@ texture[3]/internal-format - 5 @@ -340,6 +361,7 @@ Shaders/water_lightfield.vert Shaders/water_lightfield.frag + Shaders/cloud-shadowfunc.frag sea_r diff --git a/Effects/water.eff b/Effects/water.eff index 31ee0369a..98fda8344 100644 --- a/Effects/water.eff +++ b/Effects/water.eff @@ -118,61 +118,67 @@ - - /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/cloud-self-shading - - - /environment/moonlight - - - /sim/rendering/shaders/skydome - - - /environment/fog-structure - - - /environment/sea/surface/ice-cover - - - /sim/rendering/shaders/landmass - + /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/cloud-self-shading + /environment/moonlight + /sim/rendering/shaders/skydome + /environment/fog-structure + /environment/sea/surface/ice-cover + /sim/rendering/shaders/landmass - - /environment/sea/color_r - - - /environment/sea/color_g - - - /environment/sea/color_b - + /environment/sea/color_r + /environment/sea/color_g + /environment/sea/color_b + + /local-weather/cloud-shadows/cloudpos-x[0] + /local-weather/cloud-shadows/cloudpos-y[0] + /local-weather/cloud-shadows/cloudpos-x[1] + /local-weather/cloud-shadows/cloudpos-y[1] + /local-weather/cloud-shadows/cloudpos-x[2] + /local-weather/cloud-shadows/cloudpos-y[2] + /local-weather/cloud-shadows/cloudpos-x[3] + /local-weather/cloud-shadows/cloudpos-y[3] + /local-weather/cloud-shadows/cloudpos-x[4] + /local-weather/cloud-shadows/cloudpos-y[4] + /local-weather/cloud-shadows/cloudpos-x[5] + /local-weather/cloud-shadows/cloudpos-y[5] + /local-weather/cloud-shadows/cloudpos-x[6] + /local-weather/cloud-shadows/cloudpos-y[6] + /local-weather/cloud-shadows/cloudpos-x[7] + /local-weather/cloud-shadows/cloudpos-y[7] + /local-weather/cloud-shadows/cloudpos-x[8] + /local-weather/cloud-shadows/cloudpos-y[8] + /local-weather/cloud-shadows/cloudpos-x[9] + /local-weather/cloud-shadows/cloudpos-y[9] + /local-weather/cloud-shadows/cloudpos-x[10] + /local-weather/cloud-shadows/cloudpos-y[10] + /local-weather/cloud-shadows/cloudpos-x[11] + /local-weather/cloud-shadows/cloudpos-y[11] + /local-weather/cloud-shadows/cloudpos-x[12] + /local-weather/cloud-shadows/cloudpos-y[12] + /local-weather/cloud-shadows/cloudpos-x[13] + /local-weather/cloud-shadows/cloudpos-y[13] + /local-weather/cloud-shadows/cloudpos-x[14] + /local-weather/cloud-shadows/cloudpos-y[14] + /local-weather/cloud-shadows/cloudpos-x[15] + /local-weather/cloud-shadows/cloudpos-y[15] + /local-weather/cloud-shadows/cloudpos-x[16] + /local-weather/cloud-shadows/cloudpos-y[16] + /local-weather/cloud-shadows/cloudpos-x[17] + /local-weather/cloud-shadows/cloudpos-y[17] + /local-weather/cloud-shadows/cloudpos-x[18] + /local-weather/cloud-shadows/cloudpos-y[18] + /local-weather/cloud-shadows/cloudpos-x[19] + /local-weather/cloud-shadows/cloudpos-y[19] + /local-weather/cloud-shadows/cloud-shadow-flag @@ -235,27 +241,7 @@ render-bin/bin-name - + 2 @@ -319,27 +305,6 @@ texture[7]/internal-format - 5 @@ -407,6 +372,7 @@ Shaders/water_lightfield.vert Shaders/water_lightfield.frag + Shaders/cloud-shadowfunc.frag sea_r diff --git a/Shaders/water_lightfield.frag b/Shaders/water_lightfield.frag index b53b79f7c..a00b3294a 100644 --- a/Shaders/water_lightfield.frag +++ b/Shaders/water_lightfield.frag @@ -62,6 +62,7 @@ uniform float sea_b; uniform int quality_level; uniform int ocean_flag; +uniform int cloud_shadow_flag; vec3 specular_light; @@ -72,11 +73,14 @@ const float EarthRadius = 5800000.0; ////fog "include" ///// //uniform int fogType; -vec3 fog_Func(vec3 color, int type); +//vec3 fog_Func(vec3 color, int type); +float shadow_func (in float x, in float y, in float noise, in float dist); ////////////////////// /////// functions ///////// + + float rand2D(in vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } @@ -297,6 +301,7 @@ void main(void) float noise_50m = Noise3D(rawPos.xyz, 50.0); float noise_250m = Noise3D(rawPos.xyz,250.0); + float noise_500m = Noise3D(rawPos.xyz,500.0); float noise_1500m = Noise3D(rawPos.xyz,1500.0); float noise_2000m = Noise3D(rawPos.xyz,2000.0); float noise_2500m = Noise3D(rawPos.xyz, 2500.0); @@ -531,7 +536,14 @@ void main(void) vec4 finalColor; - + + float shadowValue; + if (cloud_shadow_flag == 1) + { + shadowValue = shadow_func(relPos.x, relPos.y, 0.3 * noise_250m + 0.5 * noise_500m+0.2 * noise_1500m, dist); + specular = specular * shadowValue; + refl = refl * (0.7 + 0.3 *shadowValue); + } finalColor = refl + specular * smoothstep(0.3, 0.6, ground_scattering);