diff --git a/Effects/model-interior-display.eff b/Effects/model-interior-display.eff index 93e596d10..e85cf74af 100644 --- a/Effects/model-interior-display.eff +++ b/Effects/model-interior-display.eff @@ -103,10 +103,12 @@ Shaders/model-interior-ALS-detailed.vert + Shaders/shadows-include.vert Shaders/model-interior-display-ALS.frag Shaders/secondary_lights.frag Shaders/noise.frag Shaders/filters-ALS.frag + Shaders/shadows-include.frag visibility @@ -439,6 +441,34 @@ int grain-texture-enabled + + + shadow_tex + sampler-2d + 10 + + + shadows_enabled + bool + + shadows_enabled + + + + sun_atlas_size + int + + sun_atlas_size + + + + + shadow_mapping_enabled + bool + + shadow-mapping-enabled + + diff --git a/Effects/model-interior.eff b/Effects/model-interior.eff index c4863a24b..6428b6a23 100644 --- a/Effects/model-interior.eff +++ b/Effects/model-interior.eff @@ -64,6 +64,7 @@ 0.0 0 0.0 + false @@ -141,10 +142,12 @@ Shaders/model-interior-ALS-detailed.vert + Shaders/shadows-include.vert Shaders/model-interior-ALS-detailed.frag Shaders/secondary_lights.frag Shaders/noise.frag Shaders/filters-ALS.frag + Shaders/shadows-include.frag visibility @@ -467,6 +470,34 @@ int grain-texture-enabled + + + shadow_tex + sampler-2d + 10 + + + shadows_enabled + bool + + shadows_enabled + + + + sun_atlas_size + int + + sun_atlas_size + + + + + shadow_mapping_enabled + bool + + shadow-mapping-enabled + + @@ -527,11 +558,13 @@ Shaders/model-interior-ALS-base.vert + Shaders/shadows-include.vert Shaders/model-interior-ALS-base.frag Shaders/hazes.frag Shaders/secondary_lights.frag Shaders/noise.frag Shaders/filters-ALS.frag + Shaders/shadows-include.frag visibility @@ -749,6 +782,34 @@ int use-flashlight + + + shadow_tex + sampler-2d + 10 + + + shadows_enabled + bool + + shadows_enabled + + + + sun_atlas_size + int + + sun_atlas_size + + + + + shadow_mapping_enabled + bool + + shadow-mapping-enabled + + diff --git a/Shaders/model-interior-ALS-base.frag b/Shaders/model-interior-ALS-base.frag index 96d890aff..979174d60 100644 --- a/Shaders/model-interior-ALS-base.frag +++ b/Shaders/model-interior-ALS-base.frag @@ -43,6 +43,8 @@ uniform int use_searchlight; uniform int implicit_lightmap_enabled; uniform int use_flashlight; +uniform bool shadow_mapping_enabled; + const float EarthRadius = 5800000.0; const float terminator_width = 200000.0; @@ -60,6 +62,8 @@ vec3 get_hazeColor(in float light_arg); vec3 flashlight(in vec3 color, in float radius); vec3 filter_combined (in vec3 color) ; +float getShadowing(); + float luminance(vec3 color) { return dot(vec3(0.212671, 0.715160, 0.072169), color); @@ -135,14 +139,18 @@ void main() NdotL = dot(n, lightDir); //NdotL = dot(n, (gl_ModelViewMatrix * vec4 (light_vec,0.0)).xyz); if (NdotL > 0.0) { - + float shadowmap = 1.0; + if (shadow_mapping_enabled) { + shadowmap = getShadowing(); + } diffuse.rgb += 2.0 * diffuse.rgb * (1.0 - opacity.a); - color += diffuse * NdotL * opacity; + color += diffuse * NdotL * opacity * shadowmap; NdotHV = max(dot(n, halfVector), 0.0); if (gl_FrontMaterial.shininess > 0.0) specular.rgb = (gl_FrontMaterial.specular.rgb * light_specular.rgb - * pow(NdotHV, gl_FrontMaterial.shininess)); + * pow(NdotHV, gl_FrontMaterial.shininess) + * shadowmap); } color.a = diffuse.a; // This shouldn't be necessary, but our lighting becomes very diff --git a/Shaders/model-interior-ALS-base.vert b/Shaders/model-interior-ALS-base.vert index 7a650f3e7..aabece957 100644 --- a/Shaders/model-interior-ALS-base.vert +++ b/Shaders/model-interior-ALS-base.vert @@ -36,6 +36,10 @@ uniform float overcast; uniform float ground_scattering; uniform float moonlight; +uniform bool shadow_mapping_enabled; + +void setupShadows(vec4 eyeSpacePos); + // 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; @@ -237,4 +241,8 @@ 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; + + if (shadow_mapping_enabled) { + setupShadows(gl_ModelViewMatrix * gl_Vertex); + } } diff --git a/Shaders/model-interior-ALS-detailed.frag b/Shaders/model-interior-ALS-detailed.frag index 35075a47b..eb78c86d7 100644 --- a/Shaders/model-interior-ALS-detailed.frag +++ b/Shaders/model-interior-ALS-detailed.frag @@ -59,6 +59,8 @@ uniform int lightmap_enabled; uniform int lightmap_multi; uniform int grain_texture_enabled; +uniform bool shadow_mapping_enabled; + const float EarthRadius = 5800000.0; const float terminator_width = 200000.0; @@ -76,6 +78,8 @@ vec3 addLights(in vec3 color1, in vec3 color2); vec3 flashlight(in vec3 color, in float radius); vec3 filter_combined (in vec3 color) ; +float getShadowing(); + float luminance(vec3 color) { return dot(vec3(0.212671, 0.715160, 0.072169), color); @@ -151,9 +155,12 @@ void main() NdotL = dot(n, lightDir); //NdotL = dot(n, (gl_ModelViewMatrix * vec4 (light_vec,0.0)).xyz); if (NdotL > 0.0) { - + float shadowmap = 1.0; + if (shadow_mapping_enabled) { + shadowmap = getShadowing(); + } diffuse.rgb += 2.0 * diffuse.rgb * (1.0 - opacity.a); - color += diffuse * NdotL * opacity; + color += diffuse * NdotL * opacity * shadowmap; //NdotHV = max(dot(n, halfVector), 0.0); if (gl_FrontMaterial.shininess > 0.0) { @@ -162,7 +169,9 @@ void main() NdotHV = max(0.0, dot(n,HV)); specular = (gl_FrontMaterial.specular.rgb * (light_specular.rgb+2.0*light_specular.rgb*(1.0-opacity.a)) - * pow(NdotHV, gl_FrontMaterial.shininess)*opacity.rgb); + * pow(NdotHV, gl_FrontMaterial.shininess) + * opacity.rgb + * shadowmap); } } color.a = diffuse.a; diff --git a/Shaders/model-interior-ALS-detailed.vert b/Shaders/model-interior-ALS-detailed.vert index 8010c8650..639d6815b 100644 --- a/Shaders/model-interior-ALS-detailed.vert +++ b/Shaders/model-interior-ALS-detailed.vert @@ -46,6 +46,9 @@ uniform float residual_ambience_r; uniform float residual_ambience_g; uniform float residual_ambience_b; +uniform bool shadow_mapping_enabled; + +void setupShadows(vec4 eyeSpacePos); // This is the value used in the skydome scattering shader - use the same here for consistency? const float EarthRadius = 5800000.0; @@ -297,6 +300,9 @@ else // the faster, full-day version without lightfields gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0; gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0; + if (shadow_mapping_enabled) { + setupShadows(gl_ModelViewMatrix * gl_Vertex); + } } diff --git a/Shaders/model-interior-display-ALS.frag b/Shaders/model-interior-display-ALS.frag index 4251f57de..009048ecb 100644 --- a/Shaders/model-interior-display-ALS.frag +++ b/Shaders/model-interior-display-ALS.frag @@ -65,6 +65,8 @@ uniform int lightmap_enabled; uniform int lightmap_multi; uniform int grain_texture_enabled; +uniform bool shadow_mapping_enabled; + const float EarthRadius = 5800000.0; const float terminator_width = 200000.0; @@ -82,6 +84,8 @@ vec3 addLights(in vec3 color1, in vec3 color2); vec3 flashlight(in vec3 color, in float radius); vec3 filter_combined (in vec3 color) ; +float getShadowing(); + float luminance(vec3 color) { return dot(vec3(0.212671, 0.715160, 0.072169), color); @@ -259,14 +263,18 @@ void main() NdotL = dot(n, lightDir); //NdotL = dot(n, (gl_ModelViewMatrix * vec4 (light_vec,0.0)).xyz); if (NdotL > 0.0) { - + float shadowmap = 1.0; + if (shadow_mapping_enabled) { + shadowmap = getShadowing(); + } diffuse.rgb += 2.0 * diffuse.rgb * (1.0 - opacity.a); - color += diffuse * NdotL * opacity; + color += diffuse * NdotL * opacity * shadowmap; NdotHV = max(dot(n, halfVector), 0.0); if (gl_FrontMaterial.shininess > 0.0) specular.rgb = (gl_FrontMaterial.specular.rgb * light_specular.rgb - * pow(NdotHV, gl_FrontMaterial.shininess)); + * pow(NdotHV, gl_FrontMaterial.shininess) + * shadowmap); } color.a = diffuse.a; // This shouldn't be necessary, but our lighting becomes very