summaryrefslogtreecommitdiff
path: root/drivers/gles2/shaders/material.glsl
diff options
context:
space:
mode:
authormookiexl <mookiexl@gmail.com>2016-10-03 12:28:32 +0200
committerRĂ©mi Verschelde <remi@verschelde.fr>2016-10-03 12:28:32 +0200
commit0b12ebba1143888ee76302c33bbf67508717f42f (patch)
tree41fa1fd520ea71f73087d3ec066e368dbfe0505f /drivers/gles2/shaders/material.glsl
parent1d2743302f8e118011e5fe51fbc7bf310acb30d4 (diff)
Limit directional shadow draw distance, fixes #559, optimization (#1991)
* Shadow fadeout exponent hardcoded for now, should be user configurable. * optimization - skip shadows outside visible range
Diffstat (limited to 'drivers/gles2/shaders/material.glsl')
-rw-r--r--drivers/gles2/shaders/material.glsl12
1 files changed, 12 insertions, 0 deletions
diff --git a/drivers/gles2/shaders/material.glsl b/drivers/gles2/shaders/material.glsl
index 477a451f2f..e5be25757d 100644
--- a/drivers/gles2/shaders/material.glsl
+++ b/drivers/gles2/shaders/material.glsl
@@ -980,6 +980,12 @@ FRAGMENT_SHADER_CODE
#ifdef LIGHT_USE_SHADOW
#ifdef LIGHT_TYPE_DIRECTIONAL
+ float shadow_fade_exponent=5.0; //hardcoded for now
+ float shadow_fade=pow(length(vertex_interp)/light_attenuation.g,shadow_fade_exponent);
+
+// optimization - skip shadows outside visible range
+ if(shadow_fade<1.0){
+
#ifdef LIGHT_USE_PSSM
@@ -1105,6 +1111,12 @@ FRAGMENT_SHADER_CODE
shadow_attenuation=SAMPLE_SHADOW_TEX(shadow_coord.xy,shadow_coord.z);
#endif
+
+ shadow_attenuation=mix(shadow_attenuation,1.0,shadow_fade);
+ }else{
+ shadow_attenuation=1.0;
+ };
+
#endif
#ifdef LIGHT_TYPE_OMNI