overte-Armored-Dragon/libraries/render-utils/src/taa.slf
2024-02-28 15:23:04 -08:00

50 lines
1.5 KiB
Text

<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// <$_SCRIBE_FILENAME$>
// Generated on <$_SCRIBE_DATE$>
//
// Created by Sam Gateau on 8/14/2017
// Copyright 2017 High Fidelity, Inc.
// Copyright 2024 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
<@include taa.slh@>
layout(location=0) in vec2 varTexCoord0;
layout(location=0) out vec4 outFragColor;
void main() {
vec2 fragUV = varTexCoord0;
// Debug region before debug or fxaa region X
float distToRegionFXAA = fragUV.x - taa_getRegionFXAA().x;
if (distToRegionFXAA > 0.0) {
outFragColor = vec4(taa_evalFXAA(fragUV), 1.0);
return;
}
vec4 sourceColor;
vec4 historyColor;
vec2 fragVel = taa_fetchVelocityMapBest(fragUV).xy;
bool needsTAA = taa_fetchSourceAndHistory(fragUV, fragVel, sourceColor, historyColor);
vec4 nextColor = sourceColor;
if (needsTAA) {
// clamp history to neighbourhood of current sample
historyColor.rgb = mix(historyColor.rgb, taa_evalConstrainColor(sourceColor.rgb, fragUV, fragVel, historyColor.rgb).rgb, float(taa_constrainColor()));
if (taa_feedbackColor()) {
nextColor = taa_evalFeedbackColor(sourceColor, historyColor, params.blend);
} else {
nextColor = mix(historyColor, sourceColor, params.blend);
}
nextColor.rgb = taa_resolveColor(mix(sourceColor.rgb, nextColor.rgb, nextColor.a));
}
outFragColor = nextColor;
}