EEVEE: Shadow: Fix cascade shadowmap bias multiplicator

This fixes the issue where sun shadowmaps needs a very big bias value to
make any difference.

The bias is now in world space and not dependant on shadow bounds.

Unfortunatelly this breaks compatibility with previous version and old
scene are likely to need user intervention to fix.

Also fixes the property range.

Fix T71661 EEVEE shadow from sun on incorrect face
This commit is contained in:
Clément Foucault 2020-02-14 12:17:06 +01:00
parent 38ced52d34
commit 31ad86884c
Notes: blender-bot 2023-02-14 00:37:17 +01:00
Referenced by issue #71661, EEVEE shadow from sun on incorrect face
4 changed files with 14 additions and 2 deletions

View File

@ -4461,5 +4461,14 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
}
/* EEVEE: Cascade shadow bias fix */
LISTBASE_FOREACH (Light *, light, &bmain->lights) {
if (light->type == LA_SUN) {
/* Should be 0.0004 but for practical reason we make it bigger.
* Correct factor is scene dependent. */
light->bias *= 0.002f;
}
}
}
}

View File

@ -398,6 +398,7 @@ typedef struct EEVEE_ShadowCascadeRender {
float projmat[MAX_CASCADE_NUM][4][4];
float viewmat[4][4], viewinv[4][4];
float radius[MAX_CASCADE_NUM];
float original_bias;
float cascade_max_dist;
float cascade_exponent;
float cascade_fade;

View File

@ -40,7 +40,6 @@ void EEVEE_shadows_cascade_add(EEVEE_LightsInfo *linfo, EEVEE_Light *evli, Objec
EEVEE_ShadowCascade *csm_data = linfo->shadow_cascade_data + linfo->cascade_len;
EEVEE_ShadowCascadeRender *csm_render = linfo->shadow_cascade_render + linfo->cascade_len;
sh_data->bias = max_ff(la->bias * 0.00002f, 0.0f);
eevee_contact_shadow_setup(la, sh_data);
linfo->shadow_cascade_light_indices[linfo->cascade_len] = linfo->num_light;
@ -51,6 +50,7 @@ void EEVEE_shadows_cascade_add(EEVEE_LightsInfo *linfo, EEVEE_Light *evli, Objec
csm_render->cascade_count = la->cascade_count;
csm_render->cascade_exponent = la->cascade_exponent;
csm_render->cascade_max_dist = la->cascade_max_dist;
csm_render->original_bias = max_ff(la->bias, 0.0f);
linfo->num_cascade_layer += la->cascade_count;
}
@ -380,6 +380,8 @@ static void eevee_shadow_cascade_setup(EEVEE_LightsInfo *linfo,
#endif
}
/* Bias is in clipspace, divide by range. */
shdw_data->bias = csm_render->original_bias * 0.05f / fabsf(sh_far - sh_near);
shdw_data->near = sh_near;
shdw_data->far = sh_far;
}

View File

@ -294,7 +294,7 @@ static void rna_def_light_shadow(StructRNA *srna, bool sun)
prop = RNA_def_property(srna, "shadow_buffer_bias", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "bias");
RNA_def_property_range(prop, 0.001f, 9999.0f);
RNA_def_property_range(prop, 0.0f, FLT_MAX);
RNA_def_property_ui_range(prop, 0.001f, 5.0f, 1.0, 3);
RNA_def_property_ui_text(prop, "Shadow Buffer Bias", "Bias for reducing self shadowing");
RNA_def_property_update(prop, 0, "rna_Light_update");