2016-07-28 13:21:27 +02:00
|
|
|
#version 450
|
|
|
|
|
|
|
|
uniform sampler2D tex;
|
|
|
|
uniform sampler2D tex2;
|
2016-07-31 23:25:33 +02:00
|
|
|
#ifdef _Veloc
|
|
|
|
uniform sampler2D sveloc;
|
|
|
|
#endif
|
2016-07-28 13:21:27 +02:00
|
|
|
|
|
|
|
in vec2 texCoord;
|
2016-10-12 17:52:27 +02:00
|
|
|
out vec4 fragColor;
|
2016-07-28 13:21:27 +02:00
|
|
|
|
2016-07-31 23:25:33 +02:00
|
|
|
const float SMAA_REPROJECTION_WEIGHT_SCALE = 30.0;
|
|
|
|
|
2016-07-28 13:21:27 +02:00
|
|
|
void main() {
|
2016-07-31 23:25:33 +02:00
|
|
|
vec4 current = texture(tex, texCoord);
|
2016-07-28 13:21:27 +02:00
|
|
|
|
2016-07-31 23:25:33 +02:00
|
|
|
#ifdef _Veloc
|
2016-10-17 17:39:40 +02:00
|
|
|
// Velocity is assumed to be calculated for motion blur, so we need to inverse it for reprojection
|
|
|
|
vec2 velocity = -textureLod(sveloc, texCoord, 0.0).rg;
|
|
|
|
|
|
|
|
// Reproject current coordinates and fetch previous pixel
|
|
|
|
vec4 previous = texture(tex2, texCoord + velocity);
|
|
|
|
|
|
|
|
// Attenuate the previous pixel if the velocity is different
|
|
|
|
#ifdef _SMAA
|
|
|
|
float delta = abs(current.a * current.a - previous.a * previous.a) / 5.0;
|
|
|
|
#else
|
|
|
|
const float delta = 0.0;
|
|
|
|
#endif
|
|
|
|
float weight = 0.5 * clamp(1.0 - sqrt(delta) * SMAA_REPROJECTION_WEIGHT_SCALE, 0.0, 1.0);
|
|
|
|
|
|
|
|
// Blend the pixels according to the calculated weight:
|
2017-06-26 15:37:10 +02:00
|
|
|
fragColor = vec4(mix(current.rgb, previous.rgb, weight), 1.0);
|
2016-07-31 23:25:33 +02:00
|
|
|
#else
|
|
|
|
vec4 previous = texture(tex2, texCoord);
|
2017-06-26 15:37:10 +02:00
|
|
|
fragColor = vec4(mix(current.rgb, previous.rgb, 0.5), 1.0);
|
2016-07-31 23:25:33 +02:00
|
|
|
#endif
|
2016-07-28 13:21:27 +02:00
|
|
|
}
|