Skip to content

Minor adjustments to TAA anti flicker #97

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
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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
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, float antiFlicker)
void VarianceNeighbourhood(inout NeighbourhoodSamples samples, float historyLuma, float colorLuma, float2 antiFlickerParams)
{
CTYPE moment1 = 0;
CTYPE moment2 = 0;
Expand Down Expand Up @@ -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
}

Expand Down