DepthOfFieldBokehBlurPass.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/FullscreenTrianglePass.h>
  10. #include <PostProcessing/PostProcessingShaderOptionBase.h>
  11. namespace AZ
  12. {
  13. namespace Render
  14. {
  15. //! Pass used to apply Bokeh Depth of Field blur onto a lighting buffer.
  16. class DepthOfFieldBokehBlurPass final
  17. : public RPI::FullscreenTrianglePass
  18. , public PostProcessingShaderOptionBase
  19. {
  20. AZ_RPI_PASS(DepthOfFieldBokehBlurPass);
  21. public:
  22. AZ_RTTI(AZ::Render::DepthOfFieldBokehBlurPass, "{B6C292B1-0360-4472-9955-E74CBD5EFC25}", AZ::RPI::FullscreenTrianglePass);
  23. AZ_CLASS_ALLOCATOR(DepthOfFieldBokehBlurPass, SystemAllocator);
  24. virtual ~DepthOfFieldBokehBlurPass() = default;
  25. //! Creates a DepthOfFieldBokehBlurPass
  26. static RPI::Ptr<DepthOfFieldBokehBlurPass> Create(const RPI::PassDescriptor& descriptor);
  27. // Set pass parameter interfaces...
  28. void SetRadiusMinMax(float min, float max);
  29. void UpdateSampleTexcoords(uint32_t divisionNumber, float viewAspectRatio);
  30. protected:
  31. // Behaviour functions override...
  32. void InitializeInternal() override;
  33. void FrameBeginInternal(FramePrepareParams params) override;
  34. private:
  35. DepthOfFieldBokehBlurPass(const RPI::PassDescriptor& descriptor);
  36. void InitializeShaderVariant();
  37. void UpdateCurrentShaderVariant();
  38. // SRG binding indices...
  39. RHI::ShaderInputNameIndex m_sampleNumberIndex = "m_sampleNumber";
  40. RHI::ShaderInputNameIndex m_radiusMinIndex = "m_radiusMin";
  41. RHI::ShaderInputNameIndex m_radiusMaxIndex = "m_radiusMax";
  42. RHI::ShaderInputNameIndex m_sampleTexcoordsRadiusIndex = "m_sampleTexcoordsRadius";
  43. // maximum number of samples.
  44. // Sampled in the order of 6, 12, 18, 24 from the center to the periphery.
  45. // The maximum number od samplingd at this time is 6 + 12 + 18 + 24.
  46. static constexpr int SampleMax = 60;
  47. uint32_t m_sampleNumber = 6;
  48. float m_radiusMin = 0.0f;
  49. float m_radiusMax = 0.0f;
  50. AZStd::array<AZStd::array<float, 4>, SampleMax> m_sampleTexcoords;
  51. // Scope producer functions...
  52. void CompileResources(const RHI::FrameGraphCompileContext& context) override;
  53. void BuildCommandListInternal(const RHI::FrameGraphExecuteContext& context) override;
  54. bool m_needToUpdateShaderVariant = true;
  55. const AZ::Name m_optionName;
  56. const AZStd::vector<AZ::Name> m_optionValues;
  57. };
  58. } // namespace Render
  59. } // namespace AZ