armory/Shaders/taa_pass/taa_pass.frag.glsl

45 lines
1.1 KiB
Plaintext
Raw Normal View History

2016-07-28 13:21:27 +02:00
#version 450
#include "compiled.inc"
2018-02-18 19:10:14 +01:00
2016-07-28 13:21:27 +02:00
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() {
2018-12-06 15:23:08 +01:00
vec4 current = textureLod(tex, texCoord, 0.0);
2020-05-11 09:03:13 +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;
2020-05-11 09:03:13 +02:00
#ifdef _InvY
2018-12-20 22:37:39 +01:00
velocity.y = -velocity.y;
#endif
2016-10-17 17:39:40 +02:00
// Reproject current coordinates and fetch previous pixel
2018-12-06 15:23:08 +01:00
vec4 previous = textureLod(tex2, texCoord + velocity, 0.0);
2016-10-17 17:39:40 +02:00
// 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
2018-12-06 15:23:08 +01:00
vec4 previous = textureLod(tex2, texCoord, 0.0);
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
}