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:
@@ -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()
|
||||
|
Reference in New Issue
Block a user