diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2021-03-19 14:16:53 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2021-03-19 23:11:06 +0300 |
commit | 54f52cac7ccd92c82b9353fd7167f75461618dd7 (patch) | |
tree | 21c033d9ef271461d2d0c94265c813c1f34b23b1 /source | |
parent | 884f934a853f7043a7e5a6ea380d560c858a78b7 (diff) |
EEVEE: Volumetrics: Fix sun volumetric shadow
Sun lights are treated as distant light source and need to gather
shadowing from the full frustum.
This might have performance impact on certain scenes.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl index 5b747d66e4d..8c2d1f8a5cb 100644 --- a/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl @@ -113,6 +113,19 @@ vec3 light_volume_shadow(LightData ld, vec3 ray_wpos, vec4 l_vector, sampler3D v /* Heterogeneous volume shadows */ float dd = l_vector.w / volShadowSteps; vec3 L = l_vector.xyz / volShadowSteps; + + if (ld.l_type == SUN) { + /* For sun light we scan the whole frustum. So we need to get the correct endpoints. */ + vec3 ndcP = project_point(ViewProjectionMatrix, ray_wpos); + vec3 ndcL = project_point(ViewProjectionMatrix, ray_wpos + l_vector.xyz) - ndcP; + + vec3 frustum_isect = ndcP + ndcL * line_unit_box_intersect_dist_safe(ndcP, ndcL); + + L = project_point(ViewProjectionMatrixInverse, frustum_isect) - ray_wpos; + L /= volShadowSteps; + dd = length(L); + } + vec3 shadow = vec3(1.0); for (float s = 1.0; s < VOLUMETRIC_SHADOW_MAX_STEP && s <= volShadowSteps; s += 1.0) { vec3 pos = ray_wpos + L * s; |