Files
o3de/Gems/Atom/Feature/Common/Assets/Shaders/PostProcessing/DepthOfFieldComposite.azsl
T
galibzon cc615a8f32 [ATOM-15472] Shader Build Pipeline: Remove Deprecated Files And Funct… (#1079)
* [ATOM-15472] Shader Build Pipeline: Remove Deprecated Files And Functions That
Predate The Shader Supervariants

These are the essential impactful changes as a result of deprecating the
ShaderResourceGroupAsset.

* Addressed feedback by @moudgils. Better comments in header files.

* More updates related with deprecation of ShaderResourceGroupAsset

* Deleted the temporary version 2 classes.

* Updated version of the shader asset builders.

* Updated version of all the shader related classes impacted
by the Supervariant concept and deprecation of ShaderResourceGroupAsset

* Changes to *.pass and DGI, Reflections and RayTracing.

* changes to material related assets

* changes to core lights

* Changes to auxgeom/dynamic draw.

* changes to decals, lyshine, imguipass

* changes to RPI Pass classes

* Shader for SceneSrg, ViewSrg and ForwardPass Srgs.

* changes to mesh, skinned mesh, Morphtarget.

* Fixes to RayTracingPass.cpp & now allow empty srg in shaders.

* Updated Atom_RPI.Tests

* Simplified InstanceDatabase by removing AddHandler

------------------------------------------------------------------------------------
* Updated DiffuseGI precompiled shaders.
Added RayTracingSceneSrg and RayTracingMaterialSrg shader asset.
Updated ShaderAssetCreator::Clone to handle the supervariant when processing root variants.
Co-authored-by: Doug McDiarmid <dmcdiar@amazon.com>
------------------------------------------------------------------------------------

* Changed semantics for some PassSrg to SRG_PerPass_WithFallback.

AuxGeom/FixedShapeProcessor.cpp requires SRG_PerDraw on ObjectSrg.

Removed names of SceneSrg and ViewSrg from RPISystemDescriptor.cpp

* Moved ShaderLib/Atom/Features/DummyEntryFunctions.azsli
To  Gems/Atom/RPI/Assets/ShaderLib/Atom/RPI/DummyEntryFunctions.azsli

Removed redundant checking for finalization in
ShaderResourceGroupLayout.cpp

* Fixed race condition bug for Shader::FindOrCreate.
InstanceDatabase<>::CreateInstance() needs to be atomic
for instance creation and initialization.

Added optional InstanceHandler::CreateFunctionWithParams to accomodate
to the needs of Instances that need more than an asset reference
to be able to be created an initialzed.

Removed ShaderResourceGroup::FindOrCreate() only ::Create is available
now.

* Renamed scene_and_view_srgs.* as SceneAndViewSrgs.*

Changed GetAzslFileOfOrigin for GetUniqueId

* Fixed unit tests.

* Reverted the serialization name of m_uniqueId back to
"m_azslFileOfOrigin" so precompiled shaders don't fail
in layout comparison.

* Fixed AtomCore.Tests
Removed non-applicable test. InstanceDatabase.AddHandler() is not
available anymore.

* The Null rhi is re-enabled for shader compilation.

Signed-off-by: garrieta <garrieta@amazon.com>
2021-06-11 07:48:23 -05:00

159 lines
6.8 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 <Atom/Features/PostProcessing/FullscreenPixelInfo.azsli>
#include <Atom/Features/PostProcessing/FullscreenVertex.azsli>
#include "DepthOfField.azsli"
#include <viewsrg.srgi>
ShaderResourceGroup PassSrg : SRG_PerPass_WithFallback
{
Texture2D<float4> m_InputColor;
Texture2D<float4> m_InputDepth;
Texture2D<float4> m_FrontResult_division2;
Texture2D<float4> m_FrontResult_division4;
Texture2D<float4> m_FrontResult_division8;
Texture2D<float4> m_BackResult_division2;
Texture2D<float4> m_BackResult_division4;
Texture2D<float4> m_BackResult_division8;
// scale / offset to convert DofFactor to blend ratio for back buffer.
float2 m_backBlendFactorDivision2;
float2 m_backBlendFactorDivision4;
float2 m_backBlendFactorDivision8;
// scale / offset to convert DofFactor to blend ratio for front buffer.
float2 m_frontBlendFactorDivision2;
float2 m_frontBlendFactorDivision4;
float2 m_frontBlendFactorDivision8;
Sampler LinearSampler
{
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
AddressW = Clamp;
};
}
option enum class DepthOfFieldDebugColoring
{
Disabled,
Enabled
}
o_dofMode = DepthOfFieldDebugColoring::Disabled;
inline float3 ConvertDebugColor(float3 color, float3 debugColor)
{
switch(o_dofMode)
{
case DepthOfFieldDebugColoring::Disabled:
{
return color;
}
case DepthOfFieldDebugColoring::Enabled:
{
return color * debugColor;
}
}
}
PSOutput MainPS(VSOutput IN)
{
PSOutput OUT;
float4 readColor = (float4)0;
float3 colorSum = (float3)0;
// Combine from the back buffer to the front.
////////////////////////////////////////////////////////////////////////
// Background
// Calculate the blend ratio.
// On the background side, calculate the blend ratio from the depth value on the depth buffer.
// The blend ratio can also be calculated from DofFactor on the blur buffer, but the depth buffer has a higher resolution.
float depth = InvertDepth(PassSrg::m_InputDepth.Sample(PassSrg::LinearSampler, IN.m_texCoord).r);
float far = ViewSrg::m_dof.m_cameraParameters.x;
float near = ViewSrg::m_dof.m_cameraParameters.y;
float focusDistance = ViewSrg::m_dof.m_cameraParameters.z;
float dofFactor = ConvertDofFactor(depth, far, near, focusDistance);
float blendBackDivision8 = ConvertBlend(dofFactor, PassSrg::m_backBlendFactorDivision8);
float blendBackDivision4 = ConvertBlend(dofFactor, PassSrg::m_backBlendFactorDivision4);
float blendBackDivision2 = ConvertBlend(dofFactor, PassSrg::m_backBlendFactorDivision2);
// Buffer composition is done from back to front.
// On the other hand, the blend ratio is a value from the center toward the back.
// Therefore, when overlapping buffers, it is necessary to invert the blend ratio.
float blendBackFromDiv8ToDiv4 = saturate(1.0f - blendBackDivision8);
float blendBackFromDiv4ToDiv2 = saturate(1.0f - blendBackDivision4);
float blendBackFromDiv2ToOriginal = saturate(1.0f - blendBackDivision2);
// back Division8
readColor = PassSrg::m_BackResult_division8.Sample(PassSrg::LinearSampler, IN.m_texCoord);
colorSum = ConvertDebugColor(readColor.rgb,float3(1, 0, 0));
// back Division4
readColor = PassSrg::m_BackResult_division4.Sample(PassSrg::LinearSampler, IN.m_texCoord);
readColor.rgb = ConvertDebugColor(readColor.rgb, float3(0.9, 0.5, 0));
colorSum = lerp(colorSum, readColor.rgb, blendBackFromDiv8ToDiv4);
// back Division2
readColor = PassSrg::m_BackResult_division2.Sample(PassSrg::LinearSampler, IN.m_texCoord);
readColor.rgb = ConvertDebugColor(readColor.rgb, float3(0.7, 0.7, 0));
colorSum = lerp(colorSum, readColor.rgb, blendBackFromDiv4ToDiv2);
// original
readColor = PassSrg::m_InputColor.Sample(PassSrg::LinearSampler, IN.m_texCoord);
readColor.rgb = ConvertDebugColor(readColor.rgb, float3(0, 1, 0));
colorSum = lerp(colorSum, readColor.rgb, blendBackFromDiv2ToOriginal);
// output original alpha
OUT.m_color.a = readColor.a;
////////////////////////////////////////////////////////////////////////
// Foreground
// Calculate the blend ratio.
// On the foreground side, calculate the blend ratio from the alpha value (DofFactor) on the blurred buffer.
// This alpha value is blurred, so can blur the front and back border.
float4 readColorFrontDivision2 = PassSrg::m_FrontResult_division2.Sample(PassSrg::LinearSampler, IN.m_texCoord);
float4 readColorFrontDivision4 = PassSrg::m_FrontResult_division4.Sample(PassSrg::LinearSampler, IN.m_texCoord);
float4 readColorFrontDivision8 = PassSrg::m_FrontResult_division8.Sample(PassSrg::LinearSampler, IN.m_texCoord);
float blendFrontDivision2 = ConvertBlend(readColorFrontDivision2.a, PassSrg::m_frontBlendFactorDivision2);
float blendFrontDivision4 = ConvertBlend(readColorFrontDivision4.a, PassSrg::m_frontBlendFactorDivision4);
float blendFrontDivision8 = ConvertBlend(readColorFrontDivision8.a, PassSrg::m_frontBlendFactorDivision8);
blendFrontDivision2 = max(0.0f, blendFrontDivision2);
blendFrontDivision4 = max(0.0f, blendFrontDivision4);
blendFrontDivision8 = max(0.0f, blendFrontDivision8);
// The blend ratio used is subtracted from the previous buffer's blend ratio.
// Because it blends the most blurred buffers.
// The blend ratio of the frontmost buffer is used as is.
blendFrontDivision2 = saturate(blendFrontDivision2 - blendFrontDivision4);
blendFrontDivision4 = saturate(blendFrontDivision4 - blendFrontDivision8);
blendFrontDivision8 = saturate(blendFrontDivision8);
readColorFrontDivision2.rgb = ConvertDebugColor(readColorFrontDivision2.rgb, float3(0, 0.7, 0.7));
readColorFrontDivision4.rgb = ConvertDebugColor(readColorFrontDivision4.rgb, float3(0, 0.5, 0.9));
readColorFrontDivision8.rgb = ConvertDebugColor(readColorFrontDivision8.rgb, float3(0, 0, 1));
colorSum = lerp(colorSum, readColorFrontDivision2.rgb, blendFrontDivision2);
colorSum = lerp(colorSum, readColorFrontDivision4.rgb, blendFrontDivision4);
colorSum = lerp(colorSum, readColorFrontDivision8.rgb, blendFrontDivision8);
OUT.m_color.rgb = colorSum;
return OUT;
}