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

@@ -34,6 +34,8 @@ add_executable(${UNIT_TESTS_NAME}
"${CMAKE_SOURCE_DIR}/editor/editorFouling.cpp"
# which textures the shadow maps draw without the alpha test
"${CMAKE_SOURCE_DIR}/rendering/common/texturealpha.cpp"
# and the movement of the free camera the motion blur takes
"${CMAKE_SOURCE_DIR}/rendering/common/freecameramotion.cpp"
# and the http client the editor fetches its aids with
"${CMAKE_SOURCE_DIR}/editor/editorHttp.cpp"
${UNIT_TEST_CASES})

View File

@@ -0,0 +1,56 @@
#include "stdafx.h"
#include "doctest.h"
#include "rendering/common/freecameramotion.h"
#include <limits>
// the movement of the camera with no vehicle of its own, which the motion blur takes: the step since the frame before, held to
// half a metre, and none for the first frame, after a jump or after the camera sat in a vehicle
TEST_CASE("free camera motion: the first frame gives no movement, the next ones the step since the frame before")
{
gfx::free_camera_motion motion;
CHECK(motion.next_frame(glm::dvec3{100.0, 10.0, -50.0}) == glm::vec3{0.f});
auto const step{motion.next_frame(glm::dvec3{100.25, 10.0, -50.0})};
CHECK(step.x == doctest::Approx(0.25f));
CHECK(step.y == 0.f);
CHECK(step.z == 0.f);
// a camera standing still
CHECK(motion.next_frame(glm::dvec3{100.25, 10.0, -50.0}) == glm::vec3{0.f});
}
TEST_CASE("free camera motion: a fast camera is held to the longest movement, in its direction")
{
gfx::free_camera_motion motion;
motion.next_frame(glm::dvec3{0.0});
auto const step{motion.next_frame(glm::dvec3{3.0, 0.0, -4.0})};
CHECK(glm::length(step) == doctest::Approx(gfx::free_camera_motion::longest));
CHECK(step.x == doctest::Approx(0.3f));
CHECK(step.y == 0.f);
CHECK(step.z == doctest::Approx(-0.4f));
}
TEST_CASE("free camera motion: a jump is no movement, and the frame after it moves from where the camera landed")
{
gfx::free_camera_motion motion;
motion.next_frame(glm::dvec3{0.0});
CHECK(motion.next_frame(glm::dvec3{0.0, 0.0, gfx::free_camera_motion::jump}) == glm::vec3{0.f});
CHECK(motion.next_frame(glm::dvec3{0.0, 0.0, gfx::free_camera_motion::jump + 0.1}).z == doctest::Approx(0.1f));
}
TEST_CASE("free camera motion: after a reset the camera starts anew")
{
gfx::free_camera_motion motion;
motion.next_frame(glm::dvec3{0.0});
motion.reset();
CHECK(motion.next_frame(glm::dvec3{0.2, 0.0, 0.0}) == glm::vec3{0.f});
CHECK(motion.next_frame(glm::dvec3{0.4, 0.0, 0.0}).x == doctest::Approx(0.2f));
}
TEST_CASE("free camera motion: a position that isn't a number gives no movement")
{
gfx::free_camera_motion motion;
motion.next_frame(glm::dvec3{0.0});
CHECK(motion.next_frame(glm::dvec3{std::numeric_limits<double>::quiet_NaN(), 0.0, 0.0}) == glm::vec3{0.f});
// nor does the frame after it, which would move from that position
CHECK(motion.next_frame(glm::dvec3{0.1, 0.0, 0.0}) == glm::vec3{0.f});
}