EEVEE: Volumetrics: Add support for soft volumetric shadows

Soft surface shadows were already supported but now we support
soft shadows of the volume themselves.

This is only enabled if the light casts shadow and the scene soft
shadows toggle is enabled.
This commit is contained in:
Clément Foucault 2021-03-19 18:21:29 +01:00
parent 355f884b2f
commit 89ef0da551
4 changed files with 27 additions and 9 deletions

View File

@ -855,10 +855,10 @@ typedef struct EEVEE_CommonUniformBuffer {
float vol_jitter[3], pad6; /* vec3 */
float vol_coord_scale[4]; /* vec4 */
/* -- 16 byte aligned -- */
float vol_history_alpha; /* float */
float vol_light_clamp; /* float */
float vol_shadow_steps; /* float */
int vol_use_lights; /* bool */
float vol_history_alpha; /* float */
float vol_shadow_steps; /* float */
int vol_use_lights; /* bool */
int vol_use_soft_shadows; /* bool */
/* Screen Space Reflections */
/* -- 16 byte aligned -- */
float ssr_quality, ssr_thickness, ssr_pixelsize[2]; /* vec4 */

View File

@ -184,7 +184,9 @@ void EEVEE_volumes_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
float integration_start = scene_eval->eevee.volumetric_start;
float integration_end = scene_eval->eevee.volumetric_end;
common_data->vol_light_clamp = scene_eval->eevee.volumetric_light_clamp;
/* TODO(fclem) Use clamp to modulate the light radius for
* volume lighting and avoid very bright highlights. */
// common_data->vol_light_clamp = scene_eval->eevee.volumetric_light_clamp;
common_data->vol_shadow_steps = (float)scene_eval->eevee.volumetric_shadow_samples;
if ((scene_eval->eevee.flag & SCE_EEVEE_VOLUMETRIC_SHADOWS) == 0) {
common_data->vol_shadow_steps = 0;
@ -216,11 +218,13 @@ void EEVEE_volumes_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
}
/* Disable clamp if equal to 0. */
if (common_data->vol_light_clamp == 0.0) {
common_data->vol_light_clamp = FLT_MAX;
}
/* TODO(fclem) Re-implement */
// if (common_data->vol_light_clamp == 0.0) {
// common_data->vol_light_clamp = FLT_MAX;
// }
common_data->vol_use_lights = (scene_eval->eevee.flag & SCE_EEVEE_VOLUMETRIC_LIGHTS) != 0;
common_data->vol_use_soft_shadows = (scene_eval->eevee.flag & SCE_EEVEE_SHADOW_SOFT) != 0;
if (!e_data.dummy_scatter) {
const float scatter[4] = {0.0f, 0.0f, 0.0f, 0.0f};

View File

@ -12,9 +12,9 @@ layout(std140) uniform common_block
vec4 volJitter;
vec4 volCoordScale; /* To convert volume uvs to screen uvs */
float volHistoryAlpha;
float volLightClamp;
float volShadowSteps;
bool volUseLights;
bool volUseSoftShadows;
/* Screen Space Reflections */
vec4 ssrParameters;
float ssrBorderFac;

View File

@ -127,6 +127,20 @@ vec3 participating_media_extinction(vec3 wpos, sampler3D volume_extinction)
vec3 light_volume_shadow(LightData ld, vec3 ray_wpos, vec4 l_vector, sampler3D volume_extinction)
{
#if defined(VOLUME_SHADOW)
/* If light is shadowed, use the shadow vector, if not, reuse the light vector. */
if (volUseSoftShadows && ld.l_shadowid >= 0.0) {
ShadowData sd = shadows_data[int(ld.l_shadowid)];
if (ld.l_type == SUN) {
l_vector.xyz = shadows_cascade_data[int(sd.sh_data_index)].sh_shadow_vec;
/* No need for length, it is recomputed later. */
}
else {
l_vector.xyz = shadows_cube_data[int(sd.sh_data_index)].position.xyz - ray_wpos;
l_vector.w = length(l_vector.xyz);
}
}
/* Heterogeneous volume shadows */
float dd = l_vector.w / volShadowSteps;
vec3 L = l_vector.xyz / volShadowSteps;