From 21987c4c5df1e46c722f7dae4f959e4202286f65 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 25 Aug 2017 16:58:05 -0700 Subject: [PATCH] Adding the code for the color clamping --- libraries/render-utils/src/taa.slf | 22 +++----- libraries/render-utils/src/taa.slh | 54 +++++++++++-------- .../utilities/render/antialiasing.qml | 14 +++-- 3 files changed, 50 insertions(+), 40 deletions(-) diff --git a/libraries/render-utils/src/taa.slf b/libraries/render-utils/src/taa.slf index 4b02757702..48f4c83bcf 100644 --- a/libraries/render-utils/src/taa.slf +++ b/libraries/render-utils/src/taa.slf @@ -20,22 +20,16 @@ layout(location = 0) out vec4 outFragColor; void main() { - vec3 fragUV = taa_findClosestFragment3x3(varTexCoord0); - // vec3 fragUV = vec3(varTexCoord0, taa_fetchDepth(varTexCoord0)); - vec2 fragVel = taa_fetchVelocityMap(fragUV.xy); - vec3 sourceColor; + vec3 nearFragUV = taa_findClosestFragment3x3(varTexCoord0); + vec2 fragVel = taa_fetchVelocityMap(nearFragUV.xy); + vec2 fragUV = varTexCoord0; + + /*vec3 sourceColor; vec3 historyColor; - //vec3 nextColor = taa_temporalReprojection(fragUV.xy, fragVel, fragUV.z); - vec2 prevFragUV = taa_fetchSourceAndHistory(fragUV.xy, fragVel, sourceColor, historyColor); - /* vec3 sourceColor = taa_fetchSourceMap(fragUV.xy).xyz; - vec2 prevFragUV = fragUV.xy - fragVel; - vec3 historyColor = sourceColor; - if (!(any(lessThan(prevFragUV, vec2(0.0))) || any(greaterThan(prevFragUV, vec2(1.0))))) { - historyColor = taa_fetchHistoryMap(prevFragUV).xyz; - }*/ - + vec2 prevFragUV = taa_fetchSourceAndHistory(fragUV, fragVel, sourceColor, historyColor); vec3 nextColor = mix(historyColor, sourceColor, params.blend); - + */ + vec3 nextColor = taa_temporalReprojection(fragUV, fragVel, nearFragUV.z); outFragColor = vec4(nextColor, 1.0); } diff --git a/libraries/render-utils/src/taa.slh b/libraries/render-utils/src/taa.slh index 1b2e0e3300..862ef62bb2 100644 --- a/libraries/render-utils/src/taa.slh +++ b/libraries/render-utils/src/taa.slh @@ -141,48 +141,52 @@ vec2 taa_fetchSourceAndHistory(vec2 fragUV, vec2 fragVelocity, out vec3 sourceCo return prevFragUV; } +float Luminance(vec3 rgb) { + return rgb.x/4.0 + rgb.y/2.0 + rgb.z/4.0; +} + vec3 taa_temporalReprojection(vec2 fragUV, vec2 fragVelocity, float fragZe) { vec3 sourceColor; vec3 historyColor; vec2 prevFragUV = taa_fetchSourceAndHistory(fragUV, fragVelocity, sourceColor, historyColor); - vec3 nextColor = mix(historyColor, sourceColor, params.blend); + vec4 texel1 = vec4(historyColor, 1.0); + vec4 texel0 = vec4(sourceColor, 1.0); - return taa_resolveColor(nextColor); +vec2 imageSize = getWidthHeight(0); +vec2 texelSize = getInvWidthHeight(); -/* const float _SubpixelThreshold = 0.5; const float _GatherBase = 0.5; const float _GatherSubpixelMotion = 0.1666; + const float _FeedbackMin = 0.1; + const float _FeedbackMax = 0.9; - float2 texel_vel = ss_vel / _MainTex_TexelSize.xy; - float texel_vel_mag = length(texel_vel) * fragZe; - float k_subpixel_motion = saturate(_SubpixelThreshold / (FLT_EPS + texel_vel_mag)); + vec2 texel_vel = fragVelocity * imageSize; + float texel_vel_mag = length(texel_vel) * -fragZe; + float k_subpixel_motion = clamp(_SubpixelThreshold / (0.0001 + texel_vel_mag), 0.0, 1.0); float k_min_max_support = _GatherBase + _GatherSubpixelMotion * k_subpixel_motion; - float2 ss_offset01 = k_min_max_support * float2(-_MainTex_TexelSize.x, _MainTex_TexelSize.y); - float2 ss_offset11 = k_min_max_support * float2(_MainTex_TexelSize.x, _MainTex_TexelSize.y); - float4 c00 = taa_fetchSourceMap(uv - ss_offset11); - float4 c10 = taa_fetchSourceMap(uv - ss_offset01); - float4 c01 = taa_fetchSourceMap(uv + ss_offset01); - float4 c11 = taa_fetchSourceMap(uv + ss_offset11); + vec2 ss_offset01 = k_min_max_support * vec2(-texelSize.x, texelSize.y); + vec2 ss_offset11 = k_min_max_support * vec2(texelSize.x, texelSize.y); + vec4 c00 = taa_fetchSourceMap(fragUV - ss_offset11); + vec4 c10 = taa_fetchSourceMap(fragUV - ss_offset01); + vec4 c01 = taa_fetchSourceMap(fragUV + ss_offset01); + vec4 c11 = taa_fetchSourceMap(fragUV + ss_offset11); - float4 cmin = min(c00, min(c10, min(c01, c11))); - float4 cmax = max(c00, max(c10, max(c01, c11))); + vec4 cmin = min(c00, min(c10, min(c01, c11))); + vec4 cmax = max(c00, max(c10, max(c01, c11))); #if USE_YCOCG || USE_CLIPPING - float4 cavg = (c00 + c10 + c01 + c11) / 4.0; + vec4 cavg = (c00 + c10 + c01 + c11) / 4.0; #endif - #else - #error "missing keyword MINMAX_..." - #endif // shrink chroma min-max #if USE_YCOCG - float2 chroma_extent = 0.25 * 0.5 * (cmax.r - cmin.r); - float2 chroma_center = texel0.gb; + vec2 chroma_extent = 0.25 * 0.5 * (cmax.r - cmin.r); + vec2 chroma_center = texel0.gb; cmin.yz = chroma_center - chroma_extent; cmax.yz = chroma_center + chroma_extent; cavg.yz = chroma_center; @@ -206,11 +210,15 @@ vec3 taa_temporalReprojection(vec2 fragUV, vec2 fragVelocity, float fragZe) float unbiased_diff = abs(lum0 - lum1) / max(lum0, max(lum1, 0.2)); float unbiased_weight = 1.0 - unbiased_diff; float unbiased_weight_sqr = unbiased_weight * unbiased_weight; - float k_feedback = lerp(_FeedbackMin, _FeedbackMax, unbiased_weight_sqr); + float k_feedback = mix(_FeedbackMin, _FeedbackMax, unbiased_weight_sqr); // output - return lerp(texel0, texel1, k_feedback); - */ + vec3 nextColor = mix(texel0, texel1, k_feedback).xyz; + + + // vec3 nextColor = mix(texel0, texel1, params.blend); + + return taa_resolveColor(nextColor); } <$declareColorWheel()$> diff --git a/scripts/developer/utilities/render/antialiasing.qml b/scripts/developer/utilities/render/antialiasing.qml index 4f048a6533..dc37bddf59 100644 --- a/scripts/developer/utilities/render/antialiasing.qml +++ b/scripts/developer/utilities/render/antialiasing.qml @@ -7,15 +7,23 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html // + import QtQuick 2.5 -import QtQuick.Layouts 1.3 import QtQuick.Controls 1.4 +import QtQuick.Layouts 1.3 + +import "../lib/styles-uit" +//import "../../controls-uit" as HifiControls + + import "configSlider" import "../lib/plotperf" -Column { +Rectangle { id: root; - // color: hifi.colors.baseGray; + + HifiConstants { id: hifi; } + color: hifi.colors.baseGray; Column { id: antialiasing