1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-13 08:35:20 +02:00

Fix shadow flicker on camera offset update (#15709)

This commit is contained in:
sfan5
2025-01-25 10:47:52 +01:00
committed by GitHub
parent 7c6ade0fc5
commit b861f0c5c5
4 changed files with 25 additions and 22 deletions

View File

@@ -36,7 +36,7 @@ void DirectionalLight::createSplitMatrices(const Camera *cam)
// adjusted camera positions
v3f cam_pos_world = cam->getPosition();
// if world position is less than 1 block away from the captured
// if world position is less than 1 node away from the captured
// world position then stick to the captured value, otherwise recapture.
if (cam_pos_world.getDistanceFromSQ(last_cam_pos_world) < BS * BS)
cam_pos_world = last_cam_pos_world;
@@ -84,9 +84,16 @@ DirectionalLight::DirectionalLight(const u32 shadowMapResolution,
farPlane(farValue), mapRes(shadowMapResolution), pos(position)
{}
void DirectionalLight::update_frustum(const Camera *cam, Client *client, bool force)
void DirectionalLight::updateCameraOffset(const Camera *cam)
{
if (dirty && !force)
createSplitMatrices(cam);
should_update_map_shadow = true;
dirty = true;
}
void DirectionalLight::updateFrustum(const Camera *cam, Client *client)
{
if (dirty)
return;
float zNear = cam->getCameraNode()->getNearValue();
@@ -106,16 +113,6 @@ void DirectionalLight::update_frustum(const Camera *cam, Client *client, bool fo
getPosition(), getDirection(), future_frustum.radius, future_frustum.length);
should_update_map_shadow = true;
dirty = true;
// when camera offset changes, adjust the current frustum view matrix to avoid flicker
v3s16 cam_offset = cam->getOffset();
if (cam_offset != shadow_frustum.camera_offset) {
v3f rotated_offset = shadow_frustum.ViewMat.rotateAndScaleVect(
intToFloat(cam_offset - shadow_frustum.camera_offset, BS));
shadow_frustum.ViewMat.setTranslation(shadow_frustum.ViewMat.getTranslation() + rotated_offset);
shadow_frustum.player += intToFloat(shadow_frustum.camera_offset - cam->getOffset(), BS);
shadow_frustum.camera_offset = cam_offset;
}
}
void DirectionalLight::commitFrustum()