From 54f52cac7ccd92c82b9353fd7167f75461618dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Fri, 19 Mar 2021 12:16:53 +0100 Subject: 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. --- .../blender/draw/engines/eevee/shaders/volumetric_lib.glsl | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'source/blender/draw') 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; -- cgit v1.2.3