New Depth Of Field working quite well with a small amount of artefacts
Signed-off-by: antonmic <56370189+antonmic@users.noreply.github.com>monroegm-disable-blank-issue-2
parent
9e8e08a815
commit
d04d9883bc
@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Atom/Features/PostProcessing/FullscreenPixelInfo.azsli>
|
||||||
|
#include <Atom/Features/PostProcessing/FullscreenVertex.azsli>
|
||||||
|
#include "DepthOfField.azsli"
|
||||||
|
#include "NewDepthOfFieldCommon.azsli"
|
||||||
|
|
||||||
|
#include <viewsrg.srgi>
|
||||||
|
|
||||||
|
ShaderResourceGroup PassSrg : SRG_PerPass
|
||||||
|
{
|
||||||
|
Texture2D<float4> m_colorAndCoc;
|
||||||
|
Texture2D<float2> m_minMaxCocTile;
|
||||||
|
|
||||||
|
float4 m_textureDimensions;
|
||||||
|
|
||||||
|
NewDepthOfFieldConstants m_dofConstants;
|
||||||
|
|
||||||
|
Sampler LinearSampler
|
||||||
|
{
|
||||||
|
MinFilter = Linear;
|
||||||
|
MagFilter = Linear;
|
||||||
|
MipFilter = Linear;
|
||||||
|
AddressU = Clamp;
|
||||||
|
AddressV = Clamp;
|
||||||
|
AddressW = Clamp;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
float2 GetOffsetUV(uint index, float2 offsetMultiplier)
|
||||||
|
{
|
||||||
|
return PassSrg::m_dofConstants.samplePositions[index].xy * offsetMultiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
PSOutput MainPS(VSOutput IN)
|
||||||
|
{
|
||||||
|
// Get center sample
|
||||||
|
float2 pixelUV = IN.m_texCoord;
|
||||||
|
float4 color = PassSrg::m_colorAndCoc.Sample(PassSrg::LinearSampler, pixelUV).rgba;
|
||||||
|
float centerCoc = color.a;
|
||||||
|
|
||||||
|
// Get tile min and max
|
||||||
|
int2 tile = int2(IN.m_position.xy) / 16;
|
||||||
|
float minCoc = PassSrg::m_minMaxCocTile[tile].x;
|
||||||
|
|
||||||
|
// Aspect ratio = texture.x / texture.y = dimensions.x * dimensions.w
|
||||||
|
float aspectRatio = PassSrg::m_textureDimensions.x * PassSrg::m_textureDimensions.w;
|
||||||
|
|
||||||
|
// Sampling radius
|
||||||
|
float cocRadius = max( abs(centerCoc), -minCoc);
|
||||||
|
cocRadius *= ViewSrg::m_dof.m_cocToScreenRatio * 0.5f;
|
||||||
|
float2 offsetMultiplier = float2(cocRadius / aspectRatio, cocRadius);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
float4 negColor = float4(0, 0, 0, 0);
|
||||||
|
|
||||||
|
{
|
||||||
|
float negMin = min(0, centerCoc);
|
||||||
|
color.rgb /= abs(color.a);
|
||||||
|
color.a = 1;
|
||||||
|
|
||||||
|
for(uint i = 0; i < SAMPLES_LOOP_TOTAL; ++i)
|
||||||
|
{
|
||||||
|
// Calculate sample offset
|
||||||
|
float2 offsetUV = GetOffsetUV(i, offsetMultiplier);
|
||||||
|
|
||||||
|
// Get sample
|
||||||
|
float4 sampleColorCoc = PassSrg::m_colorAndCoc.Sample(PassSrg::LinearSampler, pixelUV + offsetUV).rgba;
|
||||||
|
|
||||||
|
// Calculate weight and adjust sample
|
||||||
|
float cocDiff = sampleColorCoc.a - centerCoc;
|
||||||
|
float weight = saturate( 2 - (20 * cocDiff));
|
||||||
|
sampleColorCoc.rgb *= (weight / abs(sampleColorCoc.a));
|
||||||
|
//
|
||||||
|
// bool isNeg = (sampleColorCoc.a < negMin);
|
||||||
|
// sampleColorCoc.a = weight;
|
||||||
|
//
|
||||||
|
// // Accumulate
|
||||||
|
// negColor += isNeg * sampleColorCoc;
|
||||||
|
// color += !isNeg * sampleColorCoc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float negRatio = negColor.a / float(SAMPLES_LOOP_TOTAL);
|
||||||
|
float alpha = negRatio > abs(centerCoc) ? -negRatio : centerCoc;
|
||||||
|
|
||||||
|
color = color * saturate(1 - negRatio) + negColor;
|
||||||
|
color.rgb /= max(color.a, COC_EPSILON);
|
||||||
|
color.rgb += negColor.rgb;
|
||||||
|
|
||||||
|
//float alpha = 1.0f;
|
||||||
|
|
||||||
|
PSOutput OUT = (PSOutput)0;
|
||||||
|
OUT.m_color.rgb = color.rgb;
|
||||||
|
OUT.m_color.a = alpha;
|
||||||
|
return OUT;
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue