9df995dd26
First version of temporal antialiasing and contrast adaptive sharpening for GA. Works well in most cases but still has a few issues that will need additional time. This is only the passes and shaders with no exposure to the editor. TAA and CAS can be turned on by enabling their respective passes in the pipeline. All of the code has been previously reviewed in smaller PRs into the taa_staging branch: aws-lumberyard-dev#29 aws-lumberyard-dev#53 aws-lumberyard-dev#73 aws-lumberyard-dev#79 aws-lumberyard-dev#84 Main issues: - Bloom doesn't play nice with TAA and seems to greatly amplify any flickering - AuxGeom jitters with the camera, so TAA doesn't currently work well in editor - Transparencies don't have correct motion vectors. History rectification keeps this from looking too bad, but could still be improved - There is still more that could be done to inhibit flickering, usually from specular aliasing - Motion vectors aren't correct on POM unless PDO is turned on, which can result in some blurring during motion. - SSAO can contribute to flickering in its default half res configuration. Changing this to full res mitigates the problem. Squashed merge of the following: * [ATOM-13987] Initial checkin of Taa pass. * TAA pass setup WIP. (does not work yet due to pass configuration issues). * Taa WIP - Camera motion vectors fixed and hooked up. TAA does simple reprojection and rejection based on depth. * Small update to use lerp and add some comments. * Fix issue with attachments not being set up on bindings at initialization. Fixing issue with half-pixel offsets in TAA shader * - Motion vector passes now use the same output with mesh motion vectors overwriting camera motion vectors. - Taa pass now works with multiple pipelines. - Cleaned up TAA shader a bit. * Fixes from PR review. * Adding check for multiple attachments of the same name with different resources in Pass::ImportAttachments(). * Adding camera jitter with configurable position count. Updated TAA to blend in tonemapped space. * Fixes from PR review. Fixing camera motion vectors for background (infinite distance) * Updates to taa shader from PR review * Adding a rcp input color size. * Fix comment on PassAttachment::Update() * Updates for PR review. * Fixing missing const on the FrameAttachment* in Pass's call to FindAttachment() * Taa WIP - Adding filtering to both the current pixel and history. Adding rectification based on variance clipping. Adding some basic anti-flickering. Removing rejection based on depth. * Updates from PR code review. Mostly better commenting and naming. * Adding contrast adaptive sharpening based on AMD FidelityFX CAS to help with the softness added by TAA. * Changing to using luminance for sharpening instead of just green. Added some comments. * Moving Taa's NaN check to a better location. Disabling TAA and sharpening in prep for check in. * Updates from PR feedback.
86 lines
3.0 KiB
Plaintext
86 lines
3.0 KiB
Plaintext
/*
|
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
* its licensors.
|
|
*
|
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
* distribution (the "License"). All use of this software is governed by the License,
|
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
*
|
|
*/
|
|
|
|
#include <scenesrg.srgi>
|
|
#include <Atom/Features/PostProcessing/PostProcessUtil.azsli>
|
|
|
|
#define TILE_DIM_X 16
|
|
#define TILE_DIM_Y 16
|
|
|
|
ShaderResourceGroup PassSrg : SRG_PerPass
|
|
{
|
|
Texture2D<float4> m_inputColor;
|
|
RWTexture2D<float4> m_outputColor;
|
|
|
|
float m_strength; // Strength of the sharpening effect. Range from 0 to 1.
|
|
}
|
|
|
|
|
|
// Constrast Adaptive Sharpening, based on AMD FidelityFX CAS - https://gpuopen.com/fidelityfx-cas/
|
|
|
|
// This shader sharpens the input based on the contrast of the local neighborhood
|
|
// so that only areas that need sharpening are sharpened, while high constast areas
|
|
// are mostly left alone.
|
|
|
|
[numthreads(TILE_DIM_X, TILE_DIM_Y, 1)]
|
|
void MainCS(
|
|
uint3 dispatchThreadID : SV_DispatchThreadID,
|
|
uint3 groupID : SV_GroupID,
|
|
uint groupIndex : SV_GroupIndex)
|
|
{
|
|
uint2 pixelCoord = dispatchThreadID.xy;
|
|
|
|
// Fetch local neighborhood to determin sharpening weight.
|
|
// a
|
|
// b c d
|
|
// e
|
|
|
|
float3 sampleA = PassSrg::m_inputColor[pixelCoord + int2( 0, -1)].rgb;
|
|
float3 sampleB = PassSrg::m_inputColor[pixelCoord + int2(-1, 0)].rgb;
|
|
float3 sampleC = PassSrg::m_inputColor[pixelCoord + int2( 0, 0)].rgb;
|
|
float3 sampleD = PassSrg::m_inputColor[pixelCoord + int2( 1, 0)].rgb;
|
|
float3 sampleE = PassSrg::m_inputColor[pixelCoord + int2( 0, 1)].rgb;
|
|
|
|
float lumA = GetLuminance(sampleA);
|
|
float lumB = GetLuminance(sampleB);
|
|
float lumC = GetLuminance(sampleC);
|
|
float lumD = GetLuminance(sampleD);
|
|
float lumE = GetLuminance(sampleE);
|
|
|
|
// Get the min and max. Just use the green channel for luminance.
|
|
float minLum = min(min(lumA, lumB), min(lumC, min(lumD, lumE)));
|
|
float maxLum = max(max(lumA, lumB), max(lumC, max(lumD, lumE)));
|
|
|
|
float dMinLum = minLum; // Distance from 0 to minimum
|
|
float dMaxLum = 1.0 - maxLum; // Distance from 1 to the maximum
|
|
|
|
// baseSharpening is higher when local contrast is lower to avoid over-sharpening.
|
|
float baseSharpening = min(dMinLum, dMaxLum) / max(maxLum, 0.0001);
|
|
baseSharpening = sqrt(baseSharpening); // bias towards more sharpening
|
|
|
|
// Negative weights for sharpening effect, center pixel is always weighted 1.
|
|
float developerMaximum = lerp(-0.125, -0.2, PassSrg::m_strength);
|
|
float weight = baseSharpening * developerMaximum;
|
|
float totalWeight = weight * 4 + 1.0;
|
|
|
|
float3 output =
|
|
(
|
|
sampleA * weight +
|
|
sampleB * weight +
|
|
sampleC +
|
|
sampleD * weight +
|
|
sampleE * weight
|
|
) / totalWeight;
|
|
|
|
PassSrg::m_outputColor[pixelCoord] = float4(output, 1.0);
|
|
}
|