Skip to content

Small TAA Anti-flicker changes #555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Ignoring the disable SSR flags for recursive rendering.
- Removed logic in the UI to disable parameters for contact shadows and fog volume components as it was going against the concept of the volume system.
- Fixed the sub surface mask not being taken into account when computing ray traced sub surface scattering.
- Slightly changed the TAA anti-flicker mechanism so that it is more aggressive on almost static images (only on High preset for now).

## [7.1.1] - 2019-09-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Shader "Hidden/HDRP/TemporalAA"
#define CENTRAL_FILTERING NO_FILTERING
#define HISTORY_CLIP DIRECT_CLIP
#define ANTI_FLICKER 1
#define ANTI_FLICKER_MV_DEPENDENT 0
#define VELOCITY_REJECTION (defined(ENABLE_MV_REJECTION) && 0)
#define PERCEPTUAL_SPACE 1
#define PERCEPTUAL_SPACE_ONLY_END 0 && (PERCEPTUAL_SPACE == 0)
Expand All @@ -63,6 +64,7 @@ Shader "Hidden/HDRP/TemporalAA"
#define CENTRAL_FILTERING BLACKMAN_HARRIS
#define HISTORY_CLIP DIRECT_CLIP
#define ANTI_FLICKER 1
#define ANTI_FLICKER_MV_DEPENDENT 1
#define VELOCITY_REJECTION defined(ENABLE_MV_REJECTION)
#define PERCEPTUAL_SPACE 1
#define PERCEPTUAL_SPACE_ONLY_END 0 && (PERCEPTUAL_SPACE == 0)
Expand Down Expand Up @@ -163,7 +165,13 @@ Shader "Hidden/HDRP/TemporalAA"
// --------------- Get neighbourhood information and clamp history ---------------
float colorLuma = GetLuma(filteredColor);
float historyLuma = GetLuma(history);
GetNeighbourhoodCorners(samples, historyLuma, colorLuma, float2(_AntiFlickerIntensity, _ContrastForMaxAntiFlicker));

#if ANTI_FLICKER_MV_DEPENDENT || VELOCITY_REJECTION
float motionVectorLength = length(motionVector);
#else
float motionVectorLength = 0.0f;
#endif
GetNeighbourhoodCorners(samples, historyLuma, colorLuma, float2(_AntiFlickerIntensity, _ContrastForMaxAntiFlicker), motionVectorLength);

history = GetClippedHistory(filteredColor, history, samples.minNeighbour, samples.maxNeighbour);
filteredColor = SharpenColor(samples, filteredColor, sharpenStrength);
Expand All @@ -189,7 +197,7 @@ Shader "Hidden/HDRP/TemporalAA"
// --------------- Blend to final value and output ---------------

#if VELOCITY_REJECTION
float lengthMV = length(motionVector) * 10;
float lengthMV = motionVectorLength * 10;
blendFactor = ModifyBlendWithMotionVectorRejection(_InputVelocityMagnitudeHistory, lengthMV, prevUV, blendFactor, _SpeedRejectionIntensity);
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ void MinMaxNeighbourhood(inout NeighbourhoodSamples samples)
samples.avgNeighbour *= rcp(NEIGHBOUR_COUNT);
}

void VarianceNeighbourhood(inout NeighbourhoodSamples samples, float historyLuma, float colorLuma, float2 antiFlickerParams)
void VarianceNeighbourhood(inout NeighbourhoodSamples samples, float historyLuma, float colorLuma, float2 antiFlickerParams, float motionVectorLen)
{
CTYPE moment1 = 0;
CTYPE moment2 = 0;
Expand All @@ -552,20 +552,29 @@ void VarianceNeighbourhood(inout NeighbourhoodSamples samples, float historyLuma
// and high temporal contrast, we let the history to be closer to be unclipped. To achieve, the min/max bounds
// are extended artificially more.
#if ANTI_FLICKER
stDevMultiplier = 1.4;
stDevMultiplier = 1.5;
float temporalContrast = saturate(abs(colorLuma - historyLuma) / Max3(0.2, colorLuma, historyLuma));
stDevMultiplier += lerp(0.0, antiFlickerParams.x, smoothstep(0.05, antiFlickerParams.y, temporalContrast));
#if ANTI_FLICKER_MV_DEPENDENT
const float screenDiag = length(_ScreenSize.xy);
const float maxFactorScale = 2.25f; // when stationary
const float minFactorScale = 0.8f; // when moving more than slightly
float localizedAntiFlicker = lerp(antiFlickerParams.x * minFactorScale, antiFlickerParams.x * maxFactorScale, saturate(1.0f - 2.0f * (motionVectorLen * screenDiag)));
#else
float localizedAntiFlicker = antiFlickerParams.x;
#endif
stDevMultiplier += lerp(0.0, localizedAntiFlicker, smoothstep(0.05, antiFlickerParams.y, temporalContrast));

#endif
samples.minNeighbour = moment1 - stdDev * stDevMultiplier;
samples.maxNeighbour = moment1 + stdDev * stDevMultiplier;
}

void GetNeighbourhoodCorners(inout NeighbourhoodSamples samples, float historyLuma, float colorLuma, float2 antiFlickerParams)
void GetNeighbourhoodCorners(inout NeighbourhoodSamples samples, float historyLuma, float colorLuma, float2 antiFlickerParams, float motionVecLen)
{
#if NEIGHBOUROOD_CORNER_METHOD == MINMAX
MinMaxNeighbourhood(samples);
#else
VarianceNeighbourhood(samples, historyLuma, colorLuma, antiFlickerParams);
VarianceNeighbourhood(samples, historyLuma, colorLuma, antiFlickerParams, motionVecLen);
#endif
}

Expand Down