mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-24 16:39:13 +01:00
The motion blur took the movement of the vehicle the camera sits in and nothing else, so in freefly (and the debug camera) the world got no blur from the camera at all. Low over grass the texture under the camera then moved tens of pixels a frame and strobed: rings around the camera, at the distances its pattern repeats, stronger with shift and ctrl, gone above about 20 m, worst on a 165 Hz screen. * the camera with no vehicle of its own blurs the world with its movement since the frame before, as a vehicle does with get_future_movement(); a jump of 50 m or more (a camera preset) is no movement * that movement is held to half a metre a frame: the blur takes the scene where the camera will be, and a camera faster than that passes the ground at the bottom of the screen within a frame, where its motion turned over into a bright band. with the shutter of the blur it still smears metres * the blur shader skips samples off the picture instead of reading its edge row again and again
47 lines
1.4 KiB
GLSL
47 lines
1.4 KiB
GLSL
in vec2 f_coords;
|
|
layout(location = 0) out vec4 out_color;
|
|
|
|
#texture (color_tex, 0, RGB)
|
|
uniform sampler2D color_tex;
|
|
|
|
#texture (velocity_tex, 1, RG)
|
|
uniform sampler2D velocity_tex;
|
|
|
|
#texture (depth_tex, 2, R)
|
|
uniform sampler2D depth_tex;
|
|
|
|
#include <common>
|
|
|
|
void main()
|
|
{
|
|
float ori_depth = texture(depth_tex, f_coords).x;
|
|
|
|
vec2 texelSize = 1.0 / vec2(textureSize(color_tex, 0));
|
|
vec2 velocity = texture(velocity_tex, f_coords).xy * param[0].x;
|
|
|
|
float speed = length(velocity / texelSize);
|
|
int nSamples = clamp(int(speed), 1, 32);
|
|
|
|
float depth_diff = 0.001 * 8.0;
|
|
vec4 result = vec4(0.0);
|
|
|
|
result += vec4(texture(color_tex, f_coords).rgb, 1.0);
|
|
|
|
for (int i = 1; i < nSamples; ++i)
|
|
{
|
|
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)
|
|
result += vec4(texture(color_tex, coord).rgb, 1.0);
|
|
}
|
|
|
|
out_color = vec4((result.rgb / result.w), 1.0);
|
|
}
|