From a05863e541571928d636ace8da4bc653501c4aa2 Mon Sep 17 00:00:00 2001 From: Thorsten Renk Date: Tue, 11 Mar 2014 11:53:57 +0200 Subject: [PATCH] Cloud shadows for urban effect/random buildings --- Effects/building.eff | 1 + Effects/model-combined.eff | 295 +++++++++++++++++--- Effects/urban.eff | 417 ++++++++++++++++++++++++++++- Shaders/ubershader-lightfield.frag | 12 +- Shaders/urban-lightfield.frag | 10 +- 5 files changed, 699 insertions(+), 36 deletions(-) diff --git a/Effects/building.eff b/Effects/building.eff index 4f6657ba2..d175fadf0 100644 --- a/Effects/building.eff +++ b/Effects/building.eff @@ -184,6 +184,7 @@ Shaders/building-ubershader.vert Shaders/ubershader-lightfield.frag + Shaders/cloud-shadowfunc.frag diff --git a/Effects/model-combined.eff b/Effects/model-combined.eff index 158c83c12..54e5d9a9c 100644 --- a/Effects/model-combined.eff +++ b/Effects/model-combined.eff @@ -127,27 +127,54 @@ please see Docs/README.model-combined.eff for documentation orientation/model/roll-deg - - /environment/ground-visibility-m - - - /environment/visibility-m - - - /environment/ground-haze-thickness-m - - - /rendering/scene/scattering - - - /environment/terminator-relative-position-m - - - /sim/rendering/shaders/skydome - - - /sim/rendering/rembrandt/enabled - + /environment/ground-visibility-m + /environment/visibility-m + /environment/ground-haze-thickness-m + /rendering/scene/scattering + /environment/terminator-relative-position-m + /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 + /sim/rendering/rembrandt/enabled @@ -397,6 +424,7 @@ please see Docs/README.model-combined.eff for documentation Shaders/ubershader.vert Shaders/ubershader-lightfield.frag + Shaders/cloud-shadowfunc.frag @@ -804,16 +832,221 @@ please see Docs/README.model-combined.eff for documentation eye_alt - - cloud_self_shading - float - cloud_self_shading - - - moonlight - float - moonlight - + + cloud_self_shading + float + cloud_self_shading + + + moonlight + 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 + rembrandt_enabled diff --git a/Effects/urban.eff b/Effects/urban.eff index 521292806..f591af046 100644 --- a/Effects/urban.eff +++ b/Effects/urban.eff @@ -173,8 +173,8 @@ Shaders/urban-lightfield.vert - Shaders/urban-lightfield.frag + Shaders/cloud-shadowfunc.frag tangent 6 @@ -343,6 +343,213 @@ 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 + + + @@ -452,6 +659,7 @@ Shaders/urban-lightfield.vert Shaders/urban-lightfield.frag + Shaders/cloud-shadowfunc.frag tangent @@ -542,7 +750,212 @@ fogstructure float fogstructure - + + + 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 + diff --git a/Shaders/ubershader-lightfield.frag b/Shaders/ubershader-lightfield.frag index 50b179f7f..a01fd3d27 100644 --- a/Shaders/ubershader-lightfield.frag +++ b/Shaders/ubershader-lightfield.frag @@ -37,6 +37,7 @@ uniform int nmap_enabled; uniform int refl_enabled; uniform int refl_map; uniform int grain_texture_enabled; +uniform int cloud_shadow_flag; uniform float amb_correction; uniform float dirt_b_factor; @@ -80,6 +81,8 @@ uniform vec3 dirt_r_color; uniform vec3 dirt_g_color; uniform vec3 dirt_b_color; +float shadow_func (in float x, in float y, in float noise, in float dist); + // uniform mat4 osg_ViewMatrixInverse; // uniform mat4 osg_ViewMatrix; @@ -246,9 +249,14 @@ void main (void) else pf = pow(nDotHV, gl_FrontMaterial.shininess); - //vec4 Diffuse = gl_LightSource[0].diffuse * nDotVP; + vec3 relPos; + if (cloud_shadow_flag == 1) + { + relPos = (gl_ModelViewMatrixInverse * vec4 (vertVec,0.0)).xyz; + light_diffuse = light_diffuse * shadow_func(relPos.x, relPos.y, 1.0, dist); + } + vec4 Diffuse = light_diffuse * nDotVP; - //vec4 Specular = gl_FrontMaterial.specular * gl_LightSource[0].specular * pf; vec4 Specular = gl_FrontMaterial.specular * light_diffuse * pf; vec4 color = gl_Color + Diffuse * gl_FrontMaterial.diffuse; diff --git a/Shaders/urban-lightfield.frag b/Shaders/urban-lightfield.frag index 6d721b40e..eea85c5c6 100644 --- a/Shaders/urban-lightfield.frag +++ b/Shaders/urban-lightfield.frag @@ -50,6 +50,7 @@ uniform float fogstructure; uniform float cloud_self_shading; uniform vec3 night_color; uniform bool random_buildings; +uniform int cloud_shadow_flag; const float scale = 1.0; int linear_search_steps = 10; @@ -62,6 +63,7 @@ const float terminator_width = 200000.0; float alt; float eShade; +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); @@ -342,6 +344,12 @@ void main (void) vec3 l = gl_LightSource[0].position.xyz; vec3 diffuse = gl_Color.rgb * max(0.0, dot(N, l)); + + float dist = length(relPos); + if (cloud_shadow_flag == 1) + {diffuse = diffuse * shadow_func(relPos.x, relPos.y, 1.0, dist);} + + float shadow_factor = 1.0; // Shadow @@ -403,7 +411,7 @@ if (quality_level > 2) // here comes the terrain haze model -float dist = length(relPos); + float delta_z = hazeLayerAltitude - eye_alt;