18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-24 13:09:16 +01:00

fix(render): the free camera blurs with its own movement in the OpenGL 4.6 and Vulkan renderers

This commit is contained in:
2026-11-23 20:55:50 +01:00
parent d4f22061ee
commit 51c76da927
10 changed files with 164 additions and 4 deletions

View File

@@ -0,0 +1,27 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
#include "rendering/common/freecameramotion.h"
glm::vec3 gfx::free_camera_motion::next_frame(glm::dvec3 const &Position)
{
glm::vec3 movement{0.f};
if (m_previous)
{
auto const step{glm::vec3{Position - *m_previous}};
// a position that isn't a number (a camera gone wrong) fails the comparison and gives no movement either
if (auto const length{glm::length(step)}; length < static_cast<float>(jump))
{
movement = (length > longest) ? step * (longest / length) : step;
}
}
m_previous = Position;
return movement;
}

View File

@@ -0,0 +1,45 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
// the motion blur of the camera with no vehicle of its own (freefly, the editor): the world is blurred by the movement of the
// camera, as it is by the movement of the vehicle the camera sits in. without it the ground racing under a low camera strobes in
// rings, at the distances its texture repeats. the movement from the frame before to this one stands for the one to come
#pragma once
#include <glm/glm.hpp>
#include <optional>
namespace gfx
{
class free_camera_motion
{
public:
// from this far in a frame on the camera jumped (a camera preset, another place of the scenery), which is no movement
static constexpr double jump{50.0};
// the longest movement of a frame the blur is given. it draws the scene where the camera will be: a faster camera (shift, ctrl)
// passes the ground at the bottom of the screen within a frame, ends up behind it there, and its motion turns over into a
// bright band. half a metre a frame still blurs metres with the shutter of the motion blur
static constexpr float longest{0.5f};
// the camera of the frame. gives its movement since the frame before, no longer than the longest one; none in the first frame
// and after a jump
glm::vec3 next_frame(glm::dvec3 const &Position);
// the camera sits in a vehicle: the free camera starts anew the next time
void reset()
{
m_previous.reset();
}
private:
std::optional<glm::dvec3> m_previous;
};
} // namespace gfx