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:
27
rendering/common/freecameramotion.cpp
Normal file
27
rendering/common/freecameramotion.cpp
Normal 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;
|
||||
}
|
||||
45
rendering/common/freecameramotion.h
Normal file
45
rendering/common/freecameramotion.h
Normal 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
|
||||
@@ -1738,13 +1738,20 @@ void opengl46_renderer::Render_pass(viewport_config &vp, rendermode const Mode)
|
||||
if (vp.main && !vp.custom_backbuffer) // TODO: update window sizes also for extra viewports
|
||||
target_size = Global.fb_size;
|
||||
|
||||
// the motion blur only when something in the view moves: the vehicle of the camera, or a vehicle drawn in the last frame.
|
||||
// the camera with no vehicle of its own (freefly, the editor) blurs the world with its own movement, as a vehicle does with
|
||||
// its (rendering/common/freecameramotion.h)
|
||||
if (vp.main && (Global.pCamera.m_owner != nullptr))
|
||||
m_freecamera.reset();
|
||||
auto const freecameramovement{(vp.main && (Global.pCamera.m_owner == nullptr)) ? m_freecamera.next_frame(Global.pCamera.Pos) : glm::vec3{0.f}};
|
||||
// the motion blur only when something in the view moves: the vehicle of the camera, the camera with no vehicle of its own,
|
||||
// or a vehicle drawn in the last frame.
|
||||
// with nothing moving the velocity is zero everywhere, the blur takes a single sample of each pixel and gives back the
|
||||
// image it was given, so the velocity target, its resolve and the blur are left out and the picture stays the same.
|
||||
// a vehicle setting off is blurred from its second frame, when its velocity is still far below a pixel
|
||||
auto const motionblur{
|
||||
Global.gfx_postfx_motionblur_enabled
|
||||
&& (m_vehiclesmoved
|
||||
|| (freecameramovement != glm::vec3{0.f})
|
||||
|| ((Global.pCamera.m_owner != nullptr) && (Global.pCamera.m_owner->get_future_movement() != glm::dvec3{0.0})))};
|
||||
|
||||
if (!Global.gfx_skippipeline)
|
||||
@@ -1805,6 +1812,12 @@ void opengl46_renderer::Render_pass(viewport_config &vp, rendermode const Mode)
|
||||
glm::mat4 mv = OpenGLMatrices.data(GL_MODELVIEW);
|
||||
future = glm::translate(mv, -glm::vec3(vehicle->get_future_movement())) * glm::inverse(mv);
|
||||
}
|
||||
else if (freecameramovement != glm::vec3{0.f})
|
||||
{
|
||||
// with the temporal anti-aliasing the velocities to the last frame hold the movement of the camera already
|
||||
glm::mat4 mv = OpenGLMatrices.data(GL_MODELVIEW);
|
||||
future = glm::translate(mv, -freecameramovement) * glm::inverse(mv);
|
||||
}
|
||||
|
||||
// the cluster grid and its lists of lights are kept up only while something reads them: the shading or the heatmap.
|
||||
// the lists exist for a perspective view; without them the shading goes through the first few lights, as does the pass
|
||||
|
||||
@@ -51,6 +51,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "rendering/opengl46/opengl46shadowfit.h"
|
||||
#include "rendering/common/scenewalk.h"
|
||||
#include "rendering/common/temporalaa.h"
|
||||
#include "rendering/common/freecameramotion.h"
|
||||
#include "rendering/common/screenreflections.h"
|
||||
|
||||
// bare-bones render controller, in lack of anything better yet
|
||||
@@ -867,6 +868,8 @@ class opengl46_renderer : public gfx_renderer, public gfx::scene_walk {
|
||||
std::unique_ptr<gl::postfx> m_pfx_motionblur;
|
||||
std::unique_ptr<gl::postfx> m_pfx_taa;
|
||||
gfx::temporal_aa m_taa;
|
||||
// the movement of the camera with no vehicle of its own in the main view, for the motion blur
|
||||
gfx::free_camera_motion m_freecamera;
|
||||
std::unique_ptr<gl::postfx> m_pfx_tonemapping;
|
||||
std::unique_ptr<gl::postfx> m_pfx_chromaticaberration;
|
||||
|
||||
|
||||
@@ -1584,9 +1584,15 @@ void vulkan14_renderer::render_viewport(std::size_t const Index)
|
||||
render_ray_scene(vp);
|
||||
}
|
||||
|
||||
// the camera with no vehicle of its own (freefly, the editor) blurs the world with its own movement, as a vehicle does with its
|
||||
// (rendering/common/freecameramotion.h)
|
||||
if (vp.main && (Global.pCamera.m_owner != nullptr))
|
||||
m_freecamera.reset();
|
||||
auto const freecameramovement{(vp.main && (Global.pCamera.m_owner == nullptr)) ? m_freecamera.next_frame(Global.pCamera.Pos) : glm::vec3{0.f}};
|
||||
// the motion blur only when something in the view moves (see opengl46_renderer::Render_pass())
|
||||
auto const motionblur{Global.gfx_postfx_motionblur_enabled && targets.motion &&
|
||||
(m_vehiclesmoved || ((Global.pCamera.m_owner != nullptr) && (Global.pCamera.m_owner->get_future_movement() != glm::dvec3{0.0})))};
|
||||
(m_vehiclesmoved || (freecameramovement != glm::vec3{0.f}) ||
|
||||
((Global.pCamera.m_owner != nullptr) && (Global.pCamera.m_owner->get_future_movement() != glm::dvec3{0.0})))};
|
||||
|
||||
setup_matrices();
|
||||
m_renderpass.draw_stats = {};
|
||||
@@ -1602,6 +1608,12 @@ void vulkan14_renderer::render_viewport(std::size_t const Index)
|
||||
glm::mat4 mv = OpenGLMatrices.data(GL_MODELVIEW);
|
||||
future = glm::translate(mv, -glm::vec3(vehicle->get_future_movement())) * glm::inverse(mv);
|
||||
}
|
||||
else if (freecameramovement != glm::vec3{0.f})
|
||||
{
|
||||
// with the temporal anti-aliasing the velocities to the last frame hold the movement of the camera already
|
||||
glm::mat4 mv = OpenGLMatrices.data(GL_MODELVIEW);
|
||||
future = glm::translate(mv, -freecameramovement) * glm::inverse(mv);
|
||||
}
|
||||
|
||||
// the light clusters of the viewport (the buffers of the grid are taken by each viewport in turn), and the lights of the pass
|
||||
auto const clusters{Global.gfx_lights_clustered || Global.gfx_lights_clusterheatmap};
|
||||
|
||||
@@ -29,6 +29,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "rendering/common/shadowfit.h"
|
||||
#include "rendering/common/gpuparticles.h"
|
||||
#include "rendering/common/temporalaa.h"
|
||||
#include "rendering/common/freecameramotion.h"
|
||||
#include "rendering/common/screenreflections.h"
|
||||
#include "rendering/particles.h"
|
||||
#include "model/material.h"
|
||||
@@ -566,6 +567,8 @@ class vulkan14_renderer : public gfx_renderer, public gfx::scene_walk
|
||||
bool m_vehiclesmoved{true};
|
||||
// the temporal anti-aliasing of the main viewport (gfx.antialiasing taa), whose jitter and history dlss takes too
|
||||
gfx::temporal_aa m_taa;
|
||||
// the movement of the camera with no vehicle of its own in the main view, for the motion blur
|
||||
gfx::free_camera_motion m_freecamera;
|
||||
// dlss of the main viewport (gfx.antialiasing dlss): the size the scene is drawn at and the window it's upscaled to, planned at
|
||||
// the start (0: dlss is off); the next frame starts its history anew
|
||||
glm::ivec2 m_dlssrender{0};
|
||||
|
||||
Reference in New Issue
Block a user