From 19358bba2d3094c16fc0cc880d6ed9337c2ce168 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Fri, 10 Apr 2020 13:52:10 +0200 Subject: [PATCH 1/2] small adjust to taa antiflicker --- .../Runtime/PostProcessing/PostProcessSystem.cs | 5 ++++- .../Shaders/TemporalAntiAliasing.shader | 3 ++- .../Shaders/TemporalAntialiasing.hlsl | 13 ++++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs index 0a728a5ff34..0436bf1501e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs @@ -955,7 +955,10 @@ void DoTemporalAntialiasing(CommandBuffer cmd, HDCamera camera, RTHandle source, float maxAntiflicker = 3.5f; float motionRejectionMultiplier = Mathf.Lerp(0.0f, 250.0f, camera.taaMotionVectorRejection * camera.taaMotionVectorRejection * camera.taaMotionVectorRejection); - var taaParameters = new Vector4(camera.taaHistorySharpening, Mathf.Lerp(minAntiflicker, maxAntiflicker, camera.taaAntiFlicker), motionRejectionMultiplier, 0.0f); + // The anti flicker becomes much more aggressive on higher values + float temporalContrastForMaxAntiFlicker = 0.7f - Mathf.Lerp(0.0f, 0.3f, Mathf.SmoothStep(0.5f, 1.0f, camera.taaAntiFlicker)); + + var taaParameters = new Vector4(camera.taaHistorySharpening, Mathf.Lerp(minAntiflicker, maxAntiflicker, camera.taaAntiFlicker), motionRejectionMultiplier, temporalContrastForMaxAntiFlicker); Vector2 historySize = new Vector2(prevHistory.referenceSize.x * prevHistory.scaleFactor.x, prevHistory.referenceSize.y * prevHistory.scaleFactor.y); var rtScaleForHistory = camera.historyRTHandleProperties.rtHandleScale; diff --git a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/TemporalAntiAliasing.shader b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/TemporalAntiAliasing.shader index 6ab2c6ba83c..f495059c61a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/TemporalAntiAliasing.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/TemporalAntiAliasing.shader @@ -81,6 +81,7 @@ Shader "Hidden/HDRP/TemporalAA" #define _HistorySharpening _TaaPostParameters.x #define _AntiFlickerIntensity _TaaPostParameters.y #define _SpeedRejectionIntensity _TaaPostParameters.z + #define _ContrastForMaxAntiFlicker _TaaPostParameters.w TEXTURE2D_X(_InputVelocityMagnitudeHistory); @@ -162,7 +163,7 @@ Shader "Hidden/HDRP/TemporalAA" // --------------- Get neighbourhood information and clamp history --------------- float colorLuma = GetLuma(filteredColor); float historyLuma = GetLuma(history); - GetNeighbourhoodCorners(samples, historyLuma, colorLuma, _AntiFlickerIntensity); + GetNeighbourhoodCorners(samples, historyLuma, colorLuma, float2(_AntiFlickerIntensity, _ContrastForMaxAntiFlicker)); history = GetClippedHistory(filteredColor, history, samples.minNeighbour, samples.maxNeighbour); filteredColor = SharpenColor(samples, filteredColor, sharpenStrength); diff --git a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/TemporalAntialiasing.hlsl b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/TemporalAntialiasing.hlsl index 06fbd5322fd..0eb2906c180 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/TemporalAntialiasing.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/TemporalAntialiasing.hlsl @@ -526,7 +526,7 @@ void MinMaxNeighbourhood(inout NeighbourhoodSamples samples) samples.avgNeighbour *= rcp(NEIGHBOUR_COUNT); } -void VarianceNeighbourhood(inout NeighbourhoodSamples samples, float historyLuma, float colorLuma, float antiFlicker) +void VarianceNeighbourhood(inout NeighbourhoodSamples samples, float historyLuma, float colorLuma, float2 antiFlickerParams) { CTYPE moment1 = 0; CTYPE moment2 = 0; @@ -554,19 +554,18 @@ void VarianceNeighbourhood(inout NeighbourhoodSamples samples, float historyLuma #if ANTI_FLICKER stDevMultiplier = 1.4; float temporalContrast = saturate(abs(colorLuma - historyLuma) / Max3(0.2, colorLuma, historyLuma)); - stDevMultiplier += lerp(0.0, antiFlicker, smoothstep(0.1, 0.7, temporalContrast)); + stDevMultiplier += lerp(0.0, antiFlickerParams.x, smoothstep(0.05, antiFlickerParams.y, temporalContrast)); #endif - - samples.minNeighbour = moment1 - stDevMultiplier * stdDev; - samples.maxNeighbour = moment1 + stDevMultiplier * stdDev; + samples.minNeighbour = moment1 - stdDev * stDevMultiplier; + samples.maxNeighbour = moment1 + stdDev * stDevMultiplier; } -void GetNeighbourhoodCorners(inout NeighbourhoodSamples samples, float historyLuma, float colorLuma, float antiFlicker) +void GetNeighbourhoodCorners(inout NeighbourhoodSamples samples, float historyLuma, float colorLuma, float2 antiFlickerParams) { #if NEIGHBOUROOD_CORNER_METHOD == MINMAX MinMaxNeighbourhood(samples); #else - VarianceNeighbourhood(samples, historyLuma, colorLuma, antiFlicker); + VarianceNeighbourhood(samples, historyLuma, colorLuma, antiFlickerParams); #endif } From a64eba7bde6fd7490553e687b2c2d9d151f25e51 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Fri, 10 Apr 2020 13:53:56 +0200 Subject: [PATCH 2/2] Changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 17598262317..8952b720c06 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -647,6 +647,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added override Ambient Occlusion option on debug windows - Added Custom Post Processes with 3 injection points: Before Transparent, Before Post Process and After Post Process - Added draft of minimal interactive path tracing (experimental) based on DXR API - Support only 4 area light, lit and unlit shader (non-shadergraph) +- Small adjustments to TAA anti flicker (more aggressive on high values). ### Fixed - Fixed wizard infinite loop on cancellation