DepthOfFieldReadBackFocusDepthPass.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Memory/SystemAllocator.h>
  10. #include <Atom/RPI.Public/Pass/ParentPass.h>
  11. #include <Atom/RPI.Public/Buffer/Buffer.h>
  12. #include <PostProcessing/DepthOfFieldWriteFocusDepthFromGpuPass.h>
  13. #include <PostProcessing/DepthOfFieldCopyFocusDepthToCpuPass.h>
  14. namespace AZ
  15. {
  16. namespace Render
  17. {
  18. class DepthOfFieldSettings;
  19. //! This pass is used to get the depth value for the specified screen coordinates.
  20. class DepthOfFieldReadBackFocusDepthPass final
  21. : public RPI::ParentPass
  22. {
  23. public:
  24. AZ_RTTI(AZ::Render::DepthOfFieldReadBackFocusDepthPass, "{8738691C-1D8C-4F96-8B4F-2152A4550470}", AZ::RPI::ParentPass);
  25. AZ_CLASS_ALLOCATOR(DepthOfFieldReadBackFocusDepthPass, SystemAllocator);
  26. static RPI::Ptr<DepthOfFieldReadBackFocusDepthPass> Create(const RPI::PassDescriptor& descriptor);
  27. DepthOfFieldReadBackFocusDepthPass(const RPI::PassDescriptor& descriptor);
  28. ~DepthOfFieldReadBackFocusDepthPass();
  29. // Set pass parameter interfaces...
  30. void SetScreenPosition(const AZ::Vector2& screenPosition);
  31. float GetFocusDepth();
  32. float GetNormalizedFocusDistanceForAutoFocus() const;
  33. protected:
  34. // Pass behavior overrides...
  35. void CreateChildPassesInternal() override;
  36. void FrameBeginInternal(FramePrepareParams params) override;
  37. private:
  38. void UpdateAutoFocus(DepthOfFieldSettings& dofSettings);
  39. // Used to avoid buffer name conflicts when creating multiple DepthOfFieldReadBackFocusDepthPass
  40. static uint32_t s_bufferInstance;
  41. AZ::Data::Instance<RPI::Buffer> m_buffer;
  42. RPI::Ptr<DepthOfFieldWriteFocusDepthFromGpuPass> m_getDepthPass;
  43. RPI::Ptr<DepthOfFieldCopyFocusDepthToCpuPass> m_readbackPass;
  44. float m_normalizedFocusDistanceForAutoFocus = 0.0f;
  45. float m_delayTimer = 0.0f;
  46. bool m_isMovingFocus = false;
  47. };
  48. } // namespace Render
  49. } // namespace AZ