2016-03-23 15:09:12 +01:00
|
|
|
// Based on GPU Gems 3
|
|
|
|
// http://http.developer.nvidia.com/GPUGems3/gpugems3_ch27.html
|
2016-03-23 00:17:21 +01:00
|
|
|
#version 450
|
|
|
|
|
2018-08-30 15:42:25 +02:00
|
|
|
#include "compiled.inc"
|
2017-12-13 14:21:42 +01:00
|
|
|
#include "std/gbuffer.glsl"
|
2016-07-10 00:51:39 +02:00
|
|
|
|
2016-05-13 00:08:11 +02:00
|
|
|
uniform sampler2D gbufferD;
|
2016-03-23 00:17:21 +01:00
|
|
|
uniform sampler2D tex;
|
|
|
|
uniform mat4 prevVP;
|
2016-04-20 19:35:22 +02:00
|
|
|
uniform vec3 eye;
|
|
|
|
uniform vec3 eyeLook;
|
2017-11-04 18:35:34 +01:00
|
|
|
uniform vec2 cameraProj;
|
2017-12-26 01:58:40 +01:00
|
|
|
uniform float frameScale;
|
2016-03-23 00:17:21 +01:00
|
|
|
|
|
|
|
in vec2 texCoord;
|
2016-08-07 23:12:14 +02:00
|
|
|
in vec3 viewRay;
|
2016-10-12 17:52:27 +02:00
|
|
|
out vec4 fragColor;
|
2016-03-23 00:17:21 +01:00
|
|
|
|
2016-04-20 19:35:22 +02:00
|
|
|
vec2 getVelocity(vec2 coord, float depth) {
|
2020-05-11 09:03:13 +02:00
|
|
|
#ifdef _InvY
|
2019-02-10 18:08:38 +01:00
|
|
|
coord.y = 1.0 - coord.y;
|
|
|
|
#endif
|
2016-04-20 19:35:22 +02:00
|
|
|
vec4 currentPos = vec4(coord.xy * 2.0 - 1.0, depth, 1.0);
|
2018-12-05 17:47:45 +01:00
|
|
|
vec4 worldPos = vec4(getPos(eye, eyeLook, normalize(viewRay), depth, cameraProj), 1.0);
|
2016-03-23 15:09:12 +01:00
|
|
|
vec4 previousPos = prevVP * worldPos;
|
|
|
|
previousPos /= previousPos.w;
|
|
|
|
vec2 velocity = (currentPos - previousPos).xy / 40.0;
|
2020-05-11 09:03:13 +02:00
|
|
|
#ifdef _InvY
|
2019-06-06 04:05:44 +02:00
|
|
|
velocity.y = -velocity.y;
|
|
|
|
#endif
|
2016-03-23 15:09:12 +01:00
|
|
|
return velocity;
|
|
|
|
}
|
|
|
|
|
2016-04-02 18:19:52 +02:00
|
|
|
void main() {
|
2018-12-06 15:23:08 +01:00
|
|
|
fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb;
|
2020-05-11 09:03:13 +02:00
|
|
|
|
2018-12-06 15:23:08 +01:00
|
|
|
float depth = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
|
2016-05-13 00:08:11 +02:00
|
|
|
if (depth == 1.0) {
|
2016-04-20 19:35:22 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-03-23 15:09:12 +01:00
|
|
|
|
2017-12-26 01:58:40 +01:00
|
|
|
float blurScale = motionBlurIntensity * frameScale;
|
2016-07-31 11:49:55 +02:00
|
|
|
vec2 velocity = getVelocity(texCoord, depth) * blurScale;
|
2020-05-11 09:03:13 +02:00
|
|
|
|
2016-03-23 15:09:12 +01:00
|
|
|
vec2 offset = texCoord;
|
2016-04-02 18:19:52 +02:00
|
|
|
int processed = 1;
|
2018-11-27 21:34:42 +01:00
|
|
|
for(int i = 0; i < 8; ++i) {
|
2016-04-02 18:19:52 +02:00
|
|
|
offset += velocity;
|
2019-02-10 18:08:38 +01:00
|
|
|
fragColor.rgb += textureLod(tex, offset, 0.0).rgb;
|
|
|
|
processed++;
|
2018-11-27 21:34:42 +01:00
|
|
|
}
|
2017-03-12 17:29:22 +01:00
|
|
|
fragColor.rgb /= processed;
|
2016-03-23 00:17:21 +01:00
|
|
|
}
|