From aa46d166990b6b9890900c208ef9ec7cfb927181 Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Thu, 22 Feb 2018 10:09:03 +0100 Subject: [PATCH] A bit of cleanup in TAA shaders --- libraries/render-utils/src/taa.slh | 17 +++++++++++++---- libraries/render-utils/src/taa_blend.slf | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libraries/render-utils/src/taa.slh b/libraries/render-utils/src/taa.slh index 3b3e275da1..bca0356949 100644 --- a/libraries/render-utils/src/taa.slh +++ b/libraries/render-utils/src/taa.slh @@ -38,6 +38,10 @@ layout(std140) uniform taaParamsBuffer { #define GET_BIT(bitfield, bitIndex) bool((bitfield) & (1 << (bitIndex))) +bool taa_isDebugEnabled() { + return GET_BIT(params.flags.x, 0); +} + bool taa_showDebugCursor() { return GET_BIT(params.flags.x, 1); } @@ -247,14 +251,19 @@ vec2 taa_fromEyeUVToFragUV(vec2 eyeUV, int stereoSide) { return fragUV; } -vec2 taa_fetchSourceAndHistory(vec2 fragUV, vec2 fragVelocity, out vec3 sourceColor, out vec3 historyColor) { - sourceColor = taa_fetchSourceMap(fragUV).xyz; +vec2 taa_computePrevFragAndEyeUV(vec2 fragUV, vec2 fragVelocity, out vec2 prevEyeUV) { int stereoSide = 0; vec2 eyeUV = taa_fromFragUVToEyeUVAndSide(fragUV, stereoSide); - vec2 prevEyeUV = eyeUV - fragVelocity; + prevEyeUV = eyeUV - fragVelocity; + return taa_fromEyeUVToFragUV(prevEyeUV, stereoSide); +} + +vec2 taa_fetchSourceAndHistory(vec2 fragUV, vec2 fragVelocity, out vec3 sourceColor, out vec3 historyColor) { + vec2 prevEyeUV; + vec2 prevFragUV = taa_computePrevFragAndEyeUV(fragUV, fragVelocity, prevEyeUV); + sourceColor = taa_fetchSourceMap(fragUV).xyz; historyColor = sourceColor; - vec2 prevFragUV = taa_fromEyeUVToFragUV(prevEyeUV, stereoSide); if (!(any(lessThan(prevEyeUV, vec2(0.0))) || any(greaterThan(prevEyeUV, vec2(1.0))))) { historyColor = taa_fetchHistoryMap(prevFragUV).xyz; } diff --git a/libraries/render-utils/src/taa_blend.slf b/libraries/render-utils/src/taa_blend.slf index bb81f4989f..aca934ca71 100644 --- a/libraries/render-utils/src/taa_blend.slf +++ b/libraries/render-utils/src/taa_blend.slf @@ -145,6 +145,7 @@ void main(void) { if (!(any(lessThan(prevTexCoord, vec2(0.0))) || any(greaterThan(prevTexCoord, vec2(1.0))))) { prevColor = texture(historyMap, prevTexCoord).xyz; } + outFragColor.xyz = mix(prevColor, vec3(1,0,1), clamp(distance(prevColor, nextColor) - 0.01, 0, 1)); if (pixVelocityLength > params.debugShowVelocityThreshold) {