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
|
|
|
|
|
|
|
|
#ifdef GL_ES
|
|
|
|
precision mediump float;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "../compiled.glsl"
|
|
|
|
|
|
|
|
uniform sampler2D gbuffer0;
|
2016-08-01 10:55:13 +02:00
|
|
|
uniform sampler2D sveloc;
|
2016-07-31 23:25:33 +02:00
|
|
|
uniform sampler2D tex;
|
|
|
|
|
2016-08-01 10:55:13 +02:00
|
|
|
uniform vec2 texStep;
|
2016-07-31 23:25:33 +02:00
|
|
|
|
2016-08-01 10:55:13 +02:00
|
|
|
in vec2 texCoord;
|
2016-07-31 23:25:33 +02:00
|
|
|
|
|
|
|
void main() {
|
2016-08-01 10:55:13 +02:00
|
|
|
vec2 velocity = texture(sveloc, texCoord).rg;
|
|
|
|
// velocityScale = currentFps / targetFps;
|
|
|
|
// velocity *= velocityScale;
|
2016-07-31 23:25:33 +02:00
|
|
|
|
2016-08-01 10:55:13 +02:00
|
|
|
vec4 col = texture(tex, texCoord);
|
|
|
|
|
2016-07-31 23:25:33 +02:00
|
|
|
// Do not blur masked objects
|
|
|
|
if (texture(gbuffer0, texCoord).a == 1.0) {
|
2016-08-01 10:55:13 +02:00
|
|
|
gl_FragColor = col;
|
2016-07-31 23:25:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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;
|
2016-07-31 23:25:33 +02:00
|
|
|
|
2016-08-01 10:55:13 +02:00
|
|
|
// for (int i = 1; i < samples; ++i) {
|
|
|
|
vec2 offset = velocity * (float(0) / float(samples - 1) - 0.5);
|
|
|
|
col += texture(tex, texCoord + offset);
|
|
|
|
//
|
|
|
|
offset = velocity * (float(1) / float(samples - 1) - 0.5);
|
|
|
|
col += texture(tex, texCoord + offset);
|
|
|
|
offset = velocity * (float(2) / float(samples - 1) - 0.5);
|
|
|
|
col += texture(tex, texCoord + offset);
|
|
|
|
offset = velocity * (float(3) / float(samples - 1) - 0.5);
|
|
|
|
col += texture(tex, texCoord + offset);
|
|
|
|
offset = velocity * (float(4) / float(samples - 1) - 0.5);
|
|
|
|
col += texture(tex, texCoord + offset);
|
|
|
|
offset = velocity * (float(5) / float(samples - 1) - 0.5);
|
|
|
|
col += texture(tex, texCoord + offset);
|
|
|
|
offset = velocity * (float(6) / float(samples - 1) - 0.5);
|
|
|
|
col += texture(tex, texCoord + offset);
|
|
|
|
offset = velocity * (float(7) / float(samples - 1) - 0.5);
|
|
|
|
col += texture(tex, texCoord + offset);
|
2016-07-31 23:25:33 +02:00
|
|
|
// }
|
2016-08-01 10:55:13 +02:00
|
|
|
col /= float(samples);
|
|
|
|
|
|
|
|
gl_FragColor = col;
|
2016-07-31 23:25:33 +02:00
|
|
|
}
|