BloomBlurPass.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.Public/Pass/RenderPass.h>
  11. #include <Atom/RPI.Public/Pass/Pass.h>
  12. #include <Atom/RPI.Public/Pass/ParentPass.h>
  13. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  14. #include <Atom/RPI.Public/Shader/Shader.h>
  15. #include <Atom/RPI.Reflect/Pass/DownsampleMipChainPassData.h>
  16. #include <Atom/RHI/ConstantsData.h>
  17. #include <Atom/Feature/PostProcess/Bloom/BloomConstants.h>
  18. namespace AZ
  19. {
  20. namespace Render
  21. {
  22. class BloomBlurChildPass;
  23. // Pass for blurring downsampled images
  24. class BloomBlurPass
  25. : public RPI::ParentPass
  26. {
  27. AZ_RPI_PASS(BloomBlurPass);
  28. public:
  29. AZ_RTTI(BloomBlurPass, "{02E41C48-5CC7-4277-B66E-009E4D6D32BA}", ParentPass);
  30. AZ_CLASS_ALLOCATOR(BloomBlurPass, SystemAllocator);
  31. virtual ~BloomBlurPass() = default;
  32. //! Creates a BloomBlurPass
  33. static RPI::Ptr<BloomBlurPass> Create(const RPI::PassDescriptor& descriptor);
  34. protected:
  35. BloomBlurPass(const RPI::PassDescriptor& descriptor);
  36. // Pass behaviour overrides...
  37. void BuildInternal() override;
  38. void FrameBeginInternal(FramePrepareParams params) override;
  39. void GetInputInfo();
  40. void UpdateParameters();
  41. void BuildKernelData();
  42. void BuildChildPasses();
  43. void UpdateChildren();
  44. void CreateBinding(BloomBlurChildPass* pass, uint32_t mipLevel, bool isHorizontalPass);
  45. void GenerateWeightOffset(float sigma, uint32_t kernelRadius);
  46. void PrepareBuffer(uint32_t blurStageIndex);
  47. float KernelRadiusClamp(float radius);
  48. float Gaussian1D(float x, float sigma);
  49. RPI::DownsampleMipChainPassData m_passData;
  50. AZStd::vector<AZStd::vector<float>> m_weightData;
  51. AZStd::vector<AZStd::vector<float>> m_offsetData;
  52. AZStd::vector<uint32_t> m_kernelRadiusData;
  53. AZStd::vector<Data::Instance<RPI::Buffer>> m_weightBuffer;
  54. AZStd::vector<Data::Instance<RPI::Buffer>> m_offsetBuffer;
  55. AZStd::vector<float> m_kernelScreenPercents = {
  56. AZ::Render::Bloom::DefaultScreenPercentStage0,
  57. AZ::Render::Bloom::DefaultScreenPercentStage1,
  58. AZ::Render::Bloom::DefaultScreenPercentStage2,
  59. AZ::Render::Bloom::DefaultScreenPercentStage3,
  60. AZ::Render::Bloom::DefaultScreenPercentStage4
  61. };
  62. float m_kernelSizeScale = AZ::Render::Bloom::DefaultKernelSizeScale;
  63. uint32_t m_inputWidth = 0;
  64. uint32_t m_inputHeight = 0;
  65. uint8_t m_stageCount = AZ::Render::Bloom::MaxStageCount;
  66. bool m_paramsUpdated = true;
  67. };
  68. // Child pass spawned by parent blur pass, one child do gaussian blur on single downsampled level in one direction
  69. class BloomBlurChildPass
  70. : public RPI::ComputePass
  71. {
  72. AZ_RPI_PASS(BloomBlurChildPass);
  73. friend class BloomBlurPass;
  74. public:
  75. AZ_RTTI(BloomBlurChildPass, "{85D3FE9B-D347-40D6-B666-B4DF855F5B80}", RenderPass);
  76. AZ_CLASS_ALLOCATOR(BloomBlurChildPass, SystemAllocator);
  77. virtual ~BloomBlurChildPass() = default;
  78. //! Creates a BloomBlurChildPass
  79. static RPI::Ptr<BloomBlurChildPass> Create(const RPI::PassDescriptor& descriptor);
  80. void UpdateParameters(
  81. Data::Instance<RPI::Buffer> offsetBuffer,
  82. Data::Instance<RPI::Buffer> weightBuffer,
  83. uint32_t radius,
  84. bool direction,
  85. uint32_t mipLevel,
  86. uint32_t imageWidth,
  87. uint32_t imageHeight);
  88. protected:
  89. BloomBlurChildPass(const RPI::PassDescriptor& descriptor);
  90. // Pass Behaviour Overrides...
  91. void FrameBeginInternal(FramePrepareParams params) override;
  92. // output texture vertical dimension required by compute shader
  93. RHI::ShaderInputNameIndex m_offsetsInputIndex = "m_offsets";
  94. RHI::ShaderInputNameIndex m_weightsInputIndex = "m_weights";
  95. RHI::ShaderInputNameIndex m_kernelRadiusInputIndex = "m_kernelRadius";
  96. RHI::ShaderInputNameIndex m_directionInputIndex = "m_direction";
  97. RHI::ShaderInputNameIndex m_sourceImageSizeInputIndex = "m_sourceImageSize";
  98. RHI::ShaderInputNameIndex m_sourceImageTexelSizeInputIndex = "m_sourceImageTexelSize";
  99. RHI::ShaderInputNameIndex m_mipLevelInputIndex = "m_mipLevel";
  100. Data::Instance<RPI::Buffer> m_offsetBuffer;
  101. Data::Instance<RPI::Buffer> m_weightBuffer;
  102. uint32_t m_sourceImageWidth;
  103. uint32_t m_sourceImageHeight;
  104. };
  105. } // namespace RPI
  106. } // namespace AZ