/* * 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. * */ #pragma once #include #include namespace AZ { namespace Render { //! Must match the struct in FastDepthAwareBlurHor.azsl and FastDepthAwareBlurVer.azsl struct FastDepthAwareBlurPassConstants { //! The texture dimensions of blur output AZStd::array m_outputSize; //! The size of a pixel relative to screenspace UV //! Calculated by taking the inverse of the texture dimensions AZStd::array m_pixelSize; //! The size of half a pixel relative to screenspace UV AZStd::array m_halfPixelSize; //! How much a value is reduced from pixel to pixel on a perfectly flat surface float m_constFalloff = 2.0f / 3.0f; //! Threshold used to reduce computed depth difference during blur and thus the depth falloff //! Can be thought of as a bias that blurs curved surfaces more like flat surfaces //! but generally not needed and can be set to 0.0f float m_depthFalloffThreshold = 0.0f; //! How much the difference in depth slopes between pixels affects the blur falloff. //! The higher this value, the sharper edges will appear float m_depthFalloffStrength = 50.0f; u32 PADDING[3]; //! Calculates size constants based on texture size input void InitializeFromSize(RHI::Size outputTextureSize); //! Sets the constants to be forwarded to the shader void SetConstants(float constFalloff, float depthFalloffThreshold, float depthFalloffStrength); }; //! Pass for an optimized horizontal blur with edge detection class FastDepthAwareBlurHorPass final : public RPI::ComputePass { AZ_RPI_PASS(FastDepthAwareBlurHorPass); public: AZ_RTTI(AZ::Render::FastDepthAwareBlurHorPass, "{934F3772-06DA-42E3-A305-2921FFCEDCD4}", AZ::RPI::ComputePass); AZ_CLASS_ALLOCATOR(FastDepthAwareBlurHorPass, SystemAllocator, 0); virtual ~FastDepthAwareBlurHorPass() = default; //! Creates an FastDepthAwareBlurHorPass static RPI::Ptr Create(const RPI::PassDescriptor& descriptor); //! Sets the constants to be forwarded to the shader void SetConstants(float constFalloff, float depthFalloffThreshold, float depthFalloffStrength); protected: // Behavior functions override... void FrameBeginInternal(FramePrepareParams params) override; private: FastDepthAwareBlurHorPass(const RPI::PassDescriptor& descriptor); // SRG binding indices... AZ::RHI::ShaderInputNameIndex m_constantsIndex = "m_constants"; FastDepthAwareBlurPassConstants m_passConstants; }; //! Pass for an optimized vertical blur with edge detection class FastDepthAwareBlurVerPass final : public RPI::ComputePass { AZ_RPI_PASS(FastDepthAwareBlurVerPass); public: AZ_RTTI(AZ::Render::FastDepthAwareBlurVerPass, "{0DCB71EB-5417-4351-AADE-444DBCDF980E}", AZ::RPI::ComputePass); AZ_CLASS_ALLOCATOR(FastDepthAwareBlurVerPass, SystemAllocator, 0); virtual ~FastDepthAwareBlurVerPass() = default; //! Creates an FastDepthAwareBlurVerPass static RPI::Ptr Create(const RPI::PassDescriptor& descriptor); void SetConstants(float constFalloff, float depthFalloffThreshold, float depthFalloffStrength); protected: // Behavior functions override... void FrameBeginInternal(FramePrepareParams params) override; private: FastDepthAwareBlurVerPass(const RPI::PassDescriptor& descriptor); // SRG binding indices... AZ::RHI::ShaderInputNameIndex m_constantsIndex = "m_constants"; FastDepthAwareBlurPassConstants m_passConstants; }; } // namespace Render } // namespace AZ