From ef4644f3bbcd6a7a63125e65d86a4eacc3dfaa89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Thu, 30 May 2024 15:59:09 +0200 Subject: [PATCH] EEVEE-Next: Implement LOD bias for sun light This reduces the impact of tagging volumes and transparent object when a sunlight is present. --- .../eevee_next/shaders/eevee_shadow_tag_usage_lib.glsl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/blender/draw/engines/eevee_next/shaders/eevee_shadow_tag_usage_lib.glsl b/source/blender/draw/engines/eevee_next/shaders/eevee_shadow_tag_usage_lib.glsl index d05d398a837..d1dd7523f78 100644 --- a/source/blender/draw/engines/eevee_next/shaders/eevee_shadow_tag_usage_lib.glsl +++ b/source/blender/draw/engines/eevee_next/shaders/eevee_shadow_tag_usage_lib.glsl @@ -53,9 +53,11 @@ void shadow_tag_usage_tilemap_directional(uint l_idx, vec3 P, vec3 V, float radi vec3 lP = light_world_to_local_direction(light, P); - /* TODO(Miguel Pozo): Implement lod_bias support. */ + LightSunData sun = light_sun_data_get(light); + if (radius == 0.0) { int level = shadow_directional_level(light, lP - light_position_get(light)); + level = clamp(level + lod_bias, sun.clipmap_lod_min, sun.clipmap_lod_max); ShadowCoordinates coord = shadow_directional_coordinates_at_level(light, lP, level); shadow_tag_usage_tile(light, coord.tilemap_tile, 0, coord.tilemap_index); } @@ -64,6 +66,8 @@ void shadow_tag_usage_tilemap_directional(uint l_idx, vec3 P, vec3 V, float radi vec3 end_lP = light_world_to_local_direction(light, P + V * radius); int min_level = shadow_directional_level(light, start_lP - light_position_get(light)); int max_level = shadow_directional_level(light, end_lP - light_position_get(light)); + min_level = clamp(min_level + lod_bias, sun.clipmap_lod_min, sun.clipmap_lod_max); + max_level = clamp(max_level + lod_bias, sun.clipmap_lod_min, sun.clipmap_lod_max); for (int level = min_level; level <= max_level; level++) { ShadowCoordinates coord_min = shadow_directional_coordinates_at_level(