diff --git a/rendering/opengl33renderer.cpp b/rendering/opengl33renderer.cpp index 3a3008a44..5215a7b9f 100644 --- a/rendering/opengl33renderer.cpp +++ b/rendering/opengl33renderer.cpp @@ -988,6 +988,31 @@ void opengl33_renderer::Render_pass(viewport_config &vp, rendermode const Mode) auto const *vehicle = Global.pCamera.m_owner; glm::mat4 mv = OpenGLMatrices.data(GL_MODELVIEW); future = glm::translate(mv, -glm::vec3(vehicle->get_future_movement())) * glm::inverse(mv); + m_freecameraposition.reset(); + } + else if (vp.main) + { + // the free camera (freefly, debug camera) blurs the world with its own movement, as a vehicle does with its: + // without it the ground racing under a low camera strobes in rings at the distances its texture repeats. + // the movement of the frame before stands for the one to come; a jump (a camera preset) is no movement + auto const position{Global.pCamera.Pos}; + if (m_freecameraposition) + { + auto movement{glm::vec3(position - *m_freecameraposition)}; + auto const length{glm::length(movement)}; + if (length < 50.f) + { + // the blur takes the scene where the camera will be: a fast camera (shift, ctrl) moves past the ground + // at the bottom of the screen within a frame, it 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 + auto const maxmovement{0.5f}; + if (length > maxmovement) + movement *= maxmovement / length; + glm::mat4 mv = OpenGLMatrices.data(GL_MODELVIEW); + future = glm::translate(mv, -movement) * glm::inverse(mv); + } + } + m_freecameraposition = position; } Update_Lights( simulation::Lights ); diff --git a/rendering/opengl33renderer.h b/rendering/opengl33renderer.h index 4322cc2db..3e97683ae 100644 --- a/rendering/opengl33renderer.h +++ b/rendering/opengl33renderer.h @@ -469,6 +469,8 @@ class opengl33_renderer : public gfx_renderer { GLuint64 m_gllasttime = 0; double m_precipitationrotation; + // where the camera with no vehicle of its own was at the frame before, for the motion blur of its movement + std::optional m_freecameraposition; glm::mat4 perspective_projection_raw(float fovy, float aspect, float znear, float zfar); glm::mat4 perspective_projection(const viewport_proj_config &c, float n, float f, glm::mat4 &frustum); diff --git a/shaders/postfx_motionblur.frag b/shaders/postfx_motionblur.frag index 146179ac9..d2b23fd03 100644 --- a/shaders/postfx_motionblur.frag +++ b/shaders/postfx_motionblur.frag @@ -32,6 +32,10 @@ void main() vec2 offset = velocity * (float(i) / float(nSamples - 1) - 0.5); vec2 coord = f_coords + offset; + // a sample off the picture would read its edge row again and again: a fast movement towards the bottom + // of the screen (the ground racing under a low free camera) smeared it into a bright band there + if (any(lessThan(coord, 0.5 * texelSize)) || any(greaterThan(coord, vec2(1.0) - 0.5 * texelSize))) + continue; float depth = texture(depth_tex, coord).x; if (abs(depth - ori_depth) < depth_diff)