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
This commit is contained in:
mookiexl 2016-10-03 12:28:32 +02:00 committed by Rémi Verschelde
parent 1d2743302f
commit 0b12ebba11
2 changed files with 22 additions and 3 deletions

View File

@ -5456,9 +5456,16 @@ void RasterizerGLES2::_setup_light(uint16_t p_light) {
}
light_data[VL_LIGHT_ATTENUATION][0]=l->vars[VS::LIGHT_PARAM_ENERGY];
light_data[VL_LIGHT_ATTENUATION][1]=l->vars[VS::LIGHT_PARAM_RADIUS];
light_data[VL_LIGHT_ATTENUATION][2]=l->vars[VS::LIGHT_PARAM_ATTENUATION];
light_data[VL_LIGHT_ATTENUATION][0] = l->vars[VS::LIGHT_PARAM_ENERGY];
if (l->type == VS::LIGHT_DIRECTIONAL) {
light_data[VL_LIGHT_ATTENUATION][1] = l->directional_shadow_param[VS::LIGHT_DIRECTIONAL_SHADOW_PARAM_MAX_DISTANCE];
}
else{
light_data[VL_LIGHT_ATTENUATION][1] = l->vars[VS::LIGHT_PARAM_RADIUS];
}
light_data[VL_LIGHT_ATTENUATION][2] = l->vars[VS::LIGHT_PARAM_ATTENUATION];
light_data[VL_LIGHT_SPOT_ATTENUATION][0]=Math::cos(Math::deg2rad(l->vars[VS::LIGHT_PARAM_SPOT_ANGLE]));
light_data[VL_LIGHT_SPOT_ATTENUATION][1]=l->vars[VS::LIGHT_PARAM_SPOT_ATTENUATION];

View File

@ -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