diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2021-03-19 20:21:29 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2021-03-19 23:11:06 +0300 |
commit | 89ef0da5513a2bc85a518b0941807ecdd6980a66 (patch) | |
tree | d436fdeb933a944d05957d2fc3e791a013b683f0 /source/blender | |
parent | 355f884b2f0932e0e1d50e9506d4c0e3bf6e2289 (diff) |
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.
Diffstat (limited to 'source/blender')
4 files changed, 27 insertions, 9 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h index ca10e01e3f5..cbaf55809c6 100644 --- a/source/blender/draw/engines/eevee/eevee_private.h +++ b/source/blender/draw/engines/eevee/eevee_private.h @@ -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 */ diff --git a/source/blender/draw/engines/eevee/eevee_volumes.c b/source/blender/draw/engines/eevee/eevee_volumes.c index 52c96bf51e7..136737f7d8b 100644 --- a/source/blender/draw/engines/eevee/eevee_volumes.c +++ b/source/blender/draw/engines/eevee/eevee_volumes.c @@ -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}; diff --git a/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl b/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl index b3174afc799..d7996ab4bd1 100644 --- a/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl @@ -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; diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl index 6d7ddd4e56e..11fd3418a72 100644 --- a/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl @@ -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; |