From 3a29c19b2bffdd664981543c2f68151a6520b48b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Tue, 2 Mar 2021 16:28:16 +0100 Subject: EEVEE: Fix incorrect volumetric light shadowing The shadowing was computed on the light distance squared, leaking to much light since it was integrating the extinction behind the ligth itself. Also bump the maximum shadow max step to the actual UI values. Otherwise we get shadowing under evaluated because `dd` is too small. --- source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl index 9b852a57ec4..b1e3a40e8d2 100644 --- a/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl @@ -98,7 +98,7 @@ vec3 light_volume(LightData ld, vec4 l_vector) return tint * lum; } -#define VOLUMETRIC_SHADOW_MAX_STEP 32.0 +#define VOLUMETRIC_SHADOW_MAX_STEP 128.0 vec3 participating_media_extinction(vec3 wpos, sampler3D volume_extinction) { @@ -115,10 +115,10 @@ vec3 light_volume_shadow(LightData ld, vec3 ray_wpos, vec4 l_vector, sampler3D v #if defined(VOLUME_SHADOW) /* Heterogeneous volume shadows */ float dd = l_vector.w / volShadowSteps; - vec3 L = l_vector.xyz * l_vector.w; + vec3 L = l_vector.xyz / volShadowSteps; vec3 shadow = vec3(1.0); - for (float s = 0.5; s < VOLUMETRIC_SHADOW_MAX_STEP && s < (volShadowSteps - 0.1); s += 1.0) { - vec3 pos = ray_wpos + L * (s / volShadowSteps); + for (float s = 1.0; s < VOLUMETRIC_SHADOW_MAX_STEP && s <= volShadowSteps; s += 1.0) { + vec3 pos = ray_wpos + L * s; vec3 s_extinction = participating_media_extinction(pos, volume_extinction); shadow *= exp(-s_extinction * dd); } -- cgit v1.2.3