2016-07-31 23:25:33 +02:00
|
|
|
// Per-Object Motion Blur
|
|
|
|
// http://john-chapman-graphics.blogspot.com/2013/01/per-object-motion-blur.html
|
|
|
|
#version 450
|
|
|
|
|
2018-08-30 15:42:25 +02:00
|
|
|
#include "compiled.inc"
|
2016-07-31 23:25:33 +02:00
|
|
|
|
2016-08-01 10:55:13 +02:00
|
|
|
uniform sampler2D sveloc;
|
2016-07-31 23:25:33 +02:00
|
|
|
uniform sampler2D tex;
|
2016-08-11 22:24:45 +02:00
|
|
|
// uniform vec2 texStep;
|
2017-12-26 01:58:40 +01:00
|
|
|
uniform float frameScale;
|
2016-07-31 23:25:33 +02:00
|
|
|
|
2016-08-01 10:55:13 +02:00
|
|
|
in vec2 texCoord;
|
2016-10-12 17:52:27 +02:00
|
|
|
out vec4 fragColor;
|
2016-07-31 23:25:33 +02:00
|
|
|
|
|
|
|
void main() {
|
2018-12-06 15:23:08 +01:00
|
|
|
vec2 velocity = textureLod(sveloc, texCoord, 0.0).rg * motionBlurIntensity * frameScale;
|
2020-05-11 09:03:13 +02:00
|
|
|
|
|
|
|
#ifdef _InvY
|
2019-06-06 04:22:49 +02:00
|
|
|
velocity.y = -velocity.y;
|
|
|
|
#endif
|
2020-05-11 09:03:13 +02:00
|
|
|
|
2018-12-06 15:23:08 +01:00
|
|
|
fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb;
|
2016-08-01 10:55:13 +02:00
|
|
|
|
|
|
|
// float speed = length(velocity / texStep);
|
|
|
|
// const int MAX_SAMPLES = 8;
|
|
|
|
// int samples = clamp(int(speed), 1, MAX_SAMPLES);
|
|
|
|
const int samples = 8;
|
2018-11-27 21:34:42 +01:00
|
|
|
for (int i = 0; i < samples; ++i) {
|
|
|
|
vec2 offset = velocity * (float(i) / float(samples - 1) - 0.5);
|
2018-12-06 15:23:08 +01:00
|
|
|
fragColor.rgb += textureLod(tex, texCoord + offset, 0.0).rgb;
|
2018-11-27 21:34:42 +01:00
|
|
|
}
|
2017-03-12 17:29:22 +01:00
|
|
|
fragColor.rgb /= float(samples + 1);
|
2016-07-31 23:25:33 +02:00
|
|
|
}
|