Skip to content

Commit

Permalink
Traktor: Using Catmull-Rom filter to reduce blurriness of TAA in motion.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed Mar 7, 2024
1 parent 6c69a41 commit 441f7fb
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion data/Source/System/World/Antialias/Shaders/Taa/Temporal.xdi
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,43 @@ vec4 ColorClamp(in texture2D currentFrame, in sampler currentSampler, vec4 curre
return clamp(historyColor, bmn - E, bmx + E);
}
vec4 CatmullRomFilterSample(in texture2D tx, in sampler smp, vec2 uv)
{
// return texture(sampler2D(tex, smp), uv);
#define TEX sampler2D(tx, smp)
vec2 texsiz = vec2(textureSize( TEX, 0 ).xy);
vec4 rtMetrics = vec4( 1.0 / texsiz.xy, texsiz.xy );
vec2 position = rtMetrics.zw * uv;
vec2 centerPosition = floor(position - 0.5) + 0.5;
vec2 f = position - centerPosition;
vec2 f2 = f * f;
vec2 f3 = f * f2;
const float c = 0.5; //note: [0;1] ( SMAA_FILMIC_REPROJECTION_SHARPNESS / 100.0 )
vec2 w0 = -c * f3 + 2.0 * c * f2 - c * f;
vec2 w1 = (2.0 - c) * f3 - (3.0 - c) * f2 + 1.0;
vec2 w2 = -(2.0 - c) * f3 + (3.0 - 2.0 * c) * f2 + c * f;
vec2 w3 = c * f3 - c * f2;
vec2 w12 = w1 + w2;
vec2 tc12 = rtMetrics.xy * (centerPosition + w2 / w12);
vec3 centerColor = textureLod(TEX, vec2(tc12.x, tc12.y), 0).rgb;
vec2 tc0 = rtMetrics.xy * (centerPosition - 1.0);
vec2 tc3 = rtMetrics.xy * (centerPosition + 2.0);
vec4 color =
vec4(textureLod(TEX, vec2(tc12.x, tc0.y ), 0).rgb, 1.0) * (w12.x * w0.y ) +
vec4(textureLod(TEX, vec2(tc0.x, tc12.y), 0).rgb, 1.0) * (w0.x * w12.y) +
vec4(centerColor, 1.0) * (w12.x * w12.y) +
vec4(textureLod(TEX, vec2(tc3.x, tc12.y), 0).rgb, 1.0) * (w3.x * w12.y) +
vec4(textureLod(TEX, vec2(tc12.x, tc3.y ), 0).rgb, 1.0) * (w12.x * w3.y );
return vec4( color.rgb / color.a, 1.0 );
}
vec4 TemporalAntiAlias(
in texture2D currentFrame,
in texture2D previousFrame,
Expand Down Expand Up @@ -54,7 +91,8 @@ vec4 TemporalAntiAlias(
if (!Clipped(uv - Vuv))
{
// Sample previous colour,
const vec4 cp = texture(sampler2D(previousFrame, linearSampler), uv - Vuv);
//const vec4 cp = texture(sampler2D(previousFrame, linearSampler), uv - Vuv);
const vec4 cp = CatmullRomFilterSample(previousFrame, linearSampler, uv - Vuv);
// Clamp previous colour to current color neighbourhood.
const vec4 ccp = ColorClamp(currentFrame, linearSampler, cc, cp, uv - Juv);
Expand Down

0 comments on commit 441f7fb

Please sign in to comment.