Fix: EEVEE: Broken bias for sunlights

The pixels size was not computed in the right space.

This is the easy fix as refactoring the directional
shadows is too risky/time consuming right now.

Fix #121641
This commit is contained in:
Clément Foucault
2024-05-23 19:30:13 +02:00
parent d37342e185
commit 2e3ad7404a
2 changed files with 6 additions and 4 deletions

View File

@@ -461,7 +461,8 @@ void ShadowDirectional::clipmap_tilemaps_distribution(Light &light, const Camera
light.type = LIGHT_SUN;
/* Used for selecting the clipmap level. */
float3 location = camera.position() * float3x3(object_mat.view<3, 3>());
float3 location = transform_direction_transposed(light.object_to_world, camera.position());
/* Offset for smooth level transitions. */
light.object_to_world.x.w = location.x;
light.object_to_world.y.w = location.y;
light.object_to_world.z.w = location.z;

View File

@@ -338,17 +338,17 @@ vec3 shadow_pcf_offset(vec3 L, vec3 Ng, vec2 random)
*/
float shadow_texel_radius_at_position(LightData light, const bool is_directional, vec3 P)
{
vec3 lP = light_world_to_local_point(light, P);
float scale = 1.0;
if (is_directional) {
vec3 lP = light_world_to_local_point(light, P);
lP -= light_position_get(light);
LightSunData sun = light_sun_data_get(light);
if (light.type == LIGHT_SUN) {
/* Simplification of `coverage_get(shadow_directional_level_fractional)`. */
const float narrowing = float(SHADOW_TILEMAP_RES) / (float(SHADOW_TILEMAP_RES) - 1.0001);
scale = length(lP) * narrowing;
scale = max(scale * exp2(light.lod_bias), exp2(light.lod_min));
scale = min(scale, float(1 << sun.clipmap_lod_max));
scale = min(scale, exp2(float(sun.clipmap_lod_max)));
}
else {
/* Uniform distribution everywhere. No distance scaling.
@@ -358,6 +358,7 @@ float shadow_texel_radius_at_position(LightData light, const bool is_directional
}
}
else {
vec3 lP = light_world_to_local_point(light, P);
lP -= light_local_data_get(light).shadow_position;
/* Simplification of `exp2(shadow_punctual_level_fractional)`. */
scale = shadow_punctual_pixel_ratio(light,