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
|
|
|
|
|
|
|
|
#ifdef GL_ES
|
|
|
|
precision mediump float;
|
|
|
|
#endif
|
|
|
|
|
2016-07-10 00:51:39 +02:00
|
|
|
#include "../compiled.glsl"
|
2016-10-17 17:39:40 +02: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 gbuffer0;
|
|
|
|
|
|
|
|
uniform sampler2D tex;
|
|
|
|
uniform mat4 prevVP;
|
2016-04-20 19:35:22 +02:00
|
|
|
uniform vec3 eye;
|
|
|
|
uniform vec3 eyeLook;
|
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-08-07 23:12:14 +02:00
|
|
|
// const float motionBlurIntensity = 1.0;
|
|
|
|
// const int samples = 8;
|
2016-04-02 18:19:52 +02:00
|
|
|
|
2016-04-20 19:35:22 +02:00
|
|
|
vec2 getVelocity(vec2 coord, float depth) {
|
|
|
|
vec4 currentPos = vec4(coord.xy * 2.0 - 1.0, depth, 1.0);
|
2016-10-23 15:32:26 +02:00
|
|
|
vec4 worldPos = vec4(getPos(eye, eyeLook, viewRay, depth), 1.0);
|
2016-03-23 15:09:12 +01:00
|
|
|
vec4 previousPos = prevVP * worldPos;
|
|
|
|
previousPos /= previousPos.w;
|
|
|
|
vec2 velocity = (currentPos - previousPos).xy / 40.0;
|
|
|
|
return velocity;
|
|
|
|
}
|
|
|
|
|
2016-04-02 18:19:52 +02:00
|
|
|
void main() {
|
2017-03-12 17:29:22 +01:00
|
|
|
fragColor.rgb = texture(tex, texCoord).rgb;
|
2016-04-02 18:19:52 +02:00
|
|
|
|
|
|
|
// Do not blur masked objects
|
2016-05-19 22:22:41 +02:00
|
|
|
if (texture(gbuffer0, texCoord).a == 1.0) {
|
2016-04-02 18:19:52 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-13 00:08:11 +02:00
|
|
|
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
|
|
|
|
if (depth == 1.0) {
|
2016-04-20 19:35:22 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-03-23 15:09:12 +01:00
|
|
|
|
2016-07-18 20:28:52 +02:00
|
|
|
float blurScale = 1.0 * motionBlurIntensity; //currentFps / targeFps;
|
2016-07-31 11:49:55 +02:00
|
|
|
// blurScale *= -1.0;
|
|
|
|
vec2 velocity = getVelocity(texCoord, depth) * blurScale;
|
2016-04-20 19:35:22 +02:00
|
|
|
|
2016-03-23 15:09:12 +01:00
|
|
|
vec2 offset = texCoord;
|
2016-04-02 18:19:52 +02:00
|
|
|
int processed = 1;
|
2016-03-23 15:09:12 +01:00
|
|
|
// for(int i = 1; i < samples; ++i) {
|
2016-04-02 18:19:52 +02:00
|
|
|
offset += velocity;
|
2016-05-19 22:22:41 +02:00
|
|
|
if (texture(gbuffer0, offset).a != 1.0) {
|
2017-03-12 17:29:22 +01:00
|
|
|
fragColor.rgb += texture(tex, offset).rgb;
|
2016-04-02 18:19:52 +02:00
|
|
|
processed++;
|
|
|
|
}
|
2016-03-23 00:17:21 +01:00
|
|
|
|
2016-04-02 18:19:52 +02:00
|
|
|
offset += velocity;
|
2016-05-19 22:22:41 +02:00
|
|
|
if (texture(gbuffer0, offset).a != 1.0) {
|
2017-03-12 17:29:22 +01:00
|
|
|
fragColor.rgb += texture(tex, offset).rgb;
|
2016-04-02 18:19:52 +02:00
|
|
|
processed++;
|
|
|
|
}
|
2016-03-23 15:09:12 +01:00
|
|
|
|
2016-04-02 18:19:52 +02:00
|
|
|
offset += velocity;
|
2016-05-19 22:22:41 +02:00
|
|
|
if (texture(gbuffer0, offset).a != 1.0) {
|
2017-03-12 17:29:22 +01:00
|
|
|
fragColor.rgb += texture(tex, offset).rgb;
|
2016-04-02 18:19:52 +02:00
|
|
|
processed++;
|
|
|
|
}
|
2016-03-23 15:09:12 +01:00
|
|
|
|
2016-04-02 18:19:52 +02:00
|
|
|
offset += velocity;
|
2016-05-19 22:22:41 +02:00
|
|
|
if (texture(gbuffer0, offset).a != 1.0) {
|
2017-03-12 17:29:22 +01:00
|
|
|
fragColor.rgb += texture(tex, offset).rgb;
|
2016-04-02 18:19:52 +02:00
|
|
|
processed++;
|
|
|
|
}
|
2016-03-23 15:09:12 +01:00
|
|
|
|
2016-04-02 18:19:52 +02:00
|
|
|
offset += velocity;
|
2016-05-19 22:22:41 +02:00
|
|
|
if (texture(gbuffer0, offset).a != 1.0) {
|
2017-03-12 17:29:22 +01:00
|
|
|
fragColor.rgb += texture(tex, offset).rgb;
|
2016-04-02 18:19:52 +02:00
|
|
|
processed++;
|
|
|
|
}
|
2016-03-23 15:09:12 +01:00
|
|
|
|
2016-04-02 18:19:52 +02:00
|
|
|
offset += velocity;
|
2016-05-19 22:22:41 +02:00
|
|
|
if (texture(gbuffer0, offset).a != 1.0) {
|
2017-03-12 17:29:22 +01:00
|
|
|
fragColor.rgb += texture(tex, offset).rgb;
|
2016-04-02 18:19:52 +02:00
|
|
|
processed++;
|
|
|
|
}
|
2016-03-23 15:09:12 +01:00
|
|
|
|
2016-04-02 18:19:52 +02:00
|
|
|
offset += velocity;
|
2016-05-19 22:22:41 +02:00
|
|
|
if (texture(gbuffer0, offset).a != 1.0) {
|
2017-03-12 17:29:22 +01:00
|
|
|
fragColor.rgb += texture(tex, offset).rgb;
|
2016-04-02 18:19:52 +02:00
|
|
|
processed++;
|
|
|
|
}
|
2016-03-23 15:09:12 +01:00
|
|
|
|
2016-04-02 18:19:52 +02:00
|
|
|
offset += velocity;
|
2016-05-19 22:22:41 +02:00
|
|
|
if (texture(gbuffer0, offset).a != 1.0) {
|
2017-03-12 17:29:22 +01:00
|
|
|
fragColor.rgb += texture(tex, offset).rgb;
|
2016-04-02 18:19:52 +02:00
|
|
|
processed++;
|
|
|
|
}
|
2016-03-23 15:09:12 +01:00
|
|
|
// }
|
2017-03-12 17:29:22 +01:00
|
|
|
|
|
|
|
fragColor.rgb /= processed;
|
2016-03-23 00:17:21 +01:00
|
|
|
}
|