From 291711ee24bf79f3da31c2079e756b7901e77fb3 Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Thu, 7 Dec 2017 13:41:36 +0100 Subject: [PATCH] Fixed weird black pixel bugs in TAA due to sqrt in TAA shader with very slightly negative number when computing color variance --- libraries/render-utils/src/taa.slf | 8 ++++---- libraries/render-utils/src/taa.slh | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libraries/render-utils/src/taa.slf b/libraries/render-utils/src/taa.slf index 9334d2a5e7..b4ad713a7a 100644 --- a/libraries/render-utils/src/taa.slf +++ b/libraries/render-utils/src/taa.slf @@ -31,11 +31,11 @@ void main() { } // Debug region before debug or fxaa region X - float distToRegionFXAA = fragUV.x - taa_getRegionFXAA().x; +/* float distToRegionFXAA = fragUV.x - taa_getRegionFXAA().x; if (distToRegionFXAA > 0.0) { outFragColor = vec4(taa_evalFXAA(fragUV), 1.0); return; - } + }*/ // vec3 nearFragUV = taa_findClosestFragment3x3(fragUV); // vec2 fragVel = taa_fetchVelocityMap(nearFragUV.xy); @@ -46,13 +46,13 @@ void main() { vec3 sourceColor; vec3 historyColor; - vec2 prevFragUV = taa_fetchSourceAndHistory(fragUV, fragVel, fragJitterPix, sourceColor, historyColor); + vec2 prevFragUV = taa_fetchSourceAndHistory(fragUV, fragVel, sourceColor, historyColor); vec3 nextColor = sourceColor; if (taa_constrainColor()) { // clamp history to neighbourhood of current sample - historyColor = taa_evalConstrainColor(sourceColor, fragUV, fragVel, fragDepth, fragJitterPix, historyColor); + historyColor = taa_evalConstrainColor(sourceColor, fragUV, fragVel, fragDepth, historyColor); } if (taa_feedbackColor()) { diff --git a/libraries/render-utils/src/taa.slh b/libraries/render-utils/src/taa.slh index 4e5f0e76ba..d276f2870d 100644 --- a/libraries/render-utils/src/taa.slh +++ b/libraries/render-utils/src/taa.slh @@ -255,7 +255,7 @@ vec3 taa_fetchVelocityMapBest(vec2 uv) { return vec3(best.xy, taa_fetchDepth(uv)); } -vec2 taa_fetchSourceAndHistory(vec2 fragUV, vec2 fragVelocity, vec2 fragJitterPix, out vec3 sourceColor, out vec3 historyColor) { +vec2 taa_fetchSourceAndHistory(vec2 fragUV, vec2 fragVelocity, out vec3 sourceColor, out vec3 historyColor) { sourceColor = taa_fetchSourceMap(fragUV).xyz; vec2 prevFragUV = fragUV - fragVelocity; @@ -272,7 +272,7 @@ float Luminance(vec3 rgb) { #define MINMAX_3X3_ROUNDED 1 -mat3 taa_evalNeighbourColorVariance(vec3 sourceColor, vec2 fragUV, vec2 fragVelocity, float fragZe, vec2 fragJitterPix) { +mat3 taa_evalNeighbourColorVariance(vec3 sourceColor, vec2 fragUV, vec2 fragVelocity, float fragZe) { vec2 texelSize = taa_getTexelSize(); @@ -317,7 +317,7 @@ mat3 taa_evalNeighbourColorVariance(vec3 sourceColor, vec2 fragUV, vec2 fragVelo vec3 mu = sumSamples / vec3(9.0); - vec3 sigma = sqrt(sumSamples2 / vec3(9.0) - mu * mu); + vec3 sigma = sqrt(max(sumSamples2 / vec3(9.0) - mu * mu, vec3(0))); float gamma = params.covarianceGamma; vec3 cmin = mu - gamma * sigma; @@ -326,7 +326,7 @@ mat3 taa_evalNeighbourColorVariance(vec3 sourceColor, vec2 fragUV, vec2 fragVelo return mat3(cmin, cmax, mu); } -mat3 taa_evalNeighbourColorRegion(vec3 sourceColor, vec2 fragUV, vec2 fragVelocity, float fragZe, vec2 fragJitterPix) { +mat3 taa_evalNeighbourColorRegion(vec3 sourceColor, vec2 fragUV, vec2 fragVelocity, float fragZe) { vec2 imageSize = taa_getImageSize(); vec2 texelSize = taa_getTexelSize(); vec3 cmin, cmax, cavg; @@ -463,13 +463,13 @@ vec3 taa_clampColor(vec3 colorMin, vec3 colorMax, vec3 colorSource, vec3 color) //} } -vec3 taa_evalConstrainColor(vec3 sourceColor, vec2 sourceUV, vec2 sourceVel, float sourceZe, vec2 sourceJitterPix, vec3 candidateColor) { +vec3 taa_evalConstrainColor(vec3 sourceColor, vec2 sourceUV, vec2 sourceVel, float sourceZe, vec3 candidateColor) { mat3 colorMinMaxAvg; if (taa_covarianceClipColor()) { - colorMinMaxAvg = taa_evalNeighbourColorVariance(sourceColor, sourceUV, sourceVel, sourceZe, sourceJitterPix); + colorMinMaxAvg = taa_evalNeighbourColorVariance(sourceColor, sourceUV, sourceVel, sourceZe); } else { - colorMinMaxAvg = taa_evalNeighbourColorRegion(sourceColor, sourceUV, sourceVel, sourceZe, sourceJitterPix); + colorMinMaxAvg = taa_evalNeighbourColorRegion(sourceColor, sourceUV, sourceVel, sourceZe); } // clamp history to neighbourhood of current sample