TaaPass.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 <Atom/RPI.Public/Pass/ComputePass.h>
  10. #include <Atom/RPI.Reflect/Pass/ComputePassData.h>
  11. namespace AZ::Render
  12. {
  13. //! Custom data for the Taa Pass.
  14. struct TaaPassData
  15. : public RPI::ComputePassData
  16. {
  17. AZ_RTTI(TaaPassData, "{BCDF5C7D-7A78-4C69-A460-FA6899C3B960}", ComputePassData);
  18. AZ_CLASS_ALLOCATOR(TaaPassData, SystemAllocator);
  19. TaaPassData() = default;
  20. virtual ~TaaPassData() = default;
  21. static void Reflect(ReflectContext* context)
  22. {
  23. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  24. {
  25. serializeContext->Class<TaaPassData, RPI::ComputePassData>()
  26. ->Version(1)
  27. ->Field("NumJitterPositions", &TaaPassData::m_numJitterPositions)
  28. ;
  29. }
  30. }
  31. uint32_t m_numJitterPositions = 8;
  32. };
  33. class TaaPass : public RPI::ComputePass
  34. {
  35. using Base = RPI::ComputePass;
  36. AZ_RPI_PASS(TaaPass);
  37. public:
  38. AZ_RTTI(AZ::Render::TaaPass, "{AB3BD4EA-33D7-477F-82B4-21DDFB517499}", Base);
  39. AZ_CLASS_ALLOCATOR(TaaPass, SystemAllocator);
  40. virtual ~TaaPass() = default;
  41. /// Creates a TaaPass
  42. static RPI::Ptr<TaaPass> Create(const RPI::PassDescriptor& descriptor);
  43. private:
  44. // Due to a limitation in the pass system, a copy of the output must be made immediately after
  45. // running TAA to ensure the data doesn't get altered by a downstream pass. This is important because
  46. // this frame's output becomes next frame's history buffer. When there is away to mark pass outputs
  47. // as read only, we can remove this bool and related code to avoid needing to do the copy.
  48. static constexpr bool ShouldCopyHistoryBuffer = true;
  49. TaaPass(const RPI::PassDescriptor& descriptor);
  50. // Scope producer functions...
  51. void CompileResources(const RHI::FrameGraphCompileContext& context) override;
  52. // Pass behavior overrides...
  53. void FrameBeginInternal(FramePrepareParams params) override;
  54. void ResetInternal() override;
  55. void BuildInternal() override;
  56. bool UpdateAttachmentImage(uint32_t attachmentIndex);
  57. void SetupSubPixelOffsets(uint32_t haltonX, uint32_t haltonY, uint32_t length);
  58. void GenerateFilterWeights(AZ::Vector2 jitterOffset);
  59. RHI::ShaderInputNameIndex m_outputIndex = "m_output";
  60. RHI::ShaderInputNameIndex m_lastFrameAccumulationIndex = "m_lastFrameAccumulation";
  61. RHI::ShaderInputNameIndex m_constantDataIndex = "m_constantData";
  62. AZStd::array<Data::Instance<RPI::PassAttachment>, 2> m_accumulationAttachments;
  63. RPI::PassAttachmentBinding* m_inputColorBinding = nullptr;
  64. RPI::PassAttachmentBinding* m_lastFrameAccumulationBinding = nullptr;
  65. RPI::PassAttachmentBinding* m_outputColorBinding = nullptr;
  66. struct Offset
  67. {
  68. Offset() = default;
  69. // Constructor for implicit conversion from array output by HaltonSequence.
  70. Offset(AZStd::array<float, 2> offsets)
  71. : m_xOffset(offsets[0])
  72. , m_yOffset(offsets[1])
  73. {};
  74. float m_xOffset = 0.0f;
  75. float m_yOffset = 0.0f;
  76. };
  77. AZStd::array<float, 9> m_filterWeights = { 0.0f };
  78. AZStd::vector<Offset> m_subPixelOffsets;
  79. uint32_t m_offsetIndex = 0;
  80. uint8_t m_accumulationOuptutIndex = 0;
  81. };
  82. } // namespace AZ::Render