NewDepthOfFieldPasses.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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/FullscreenTrianglePass.h>
  11. #include <Atom/RPI.Public/Pass/ParentPass.h>
  12. #include <PostProcessing/PostProcessingShaderOptionBase.h>
  13. namespace AZ
  14. {
  15. namespace Render
  16. {
  17. // Technique
  18. //
  19. // 1. This Depth of Field technique starts by downsampling the lighting buffer and calculating
  20. // the circle of confusion (CoC) for each downsampled pixel.
  21. //
  22. // 2. It then computes the min and max CoC for tiles of 16x16 pixels
  23. //
  24. // 3. It expands the min and max in a 3x3 region (twice, so 5x5 at the end) so that each tile
  25. // tile pixel has the min and max CoCs of the 5x5 tile region around it
  26. //
  27. // 4. We perform a 48 tap scatter-as-gather blur around each pixel
  28. //
  29. // 5. We perform a follow up 8 tap scatter-as-gather blur to fill the holes from the first blur
  30. //
  31. // 6. We composite the blurred half resolution image onto the full resolution lighting buffer
  32. //
  33. // See http://advances.realtimerendering.com/s2013/Sousa_Graphics_Gems_CryENGINE3.pptx
  34. // for a more detailed explanation.
  35. //
  36. // Notes: The name NewDepthOfField is in contrast to the previously implemented depth of field method
  37. // That method will be removed in a follow up change and at that point NewDepthOfField will be renamed
  38. // to simple DepthOfField.
  39. //! Parent pass for the new depth of field technique
  40. //! Main updates the view srg via the depth of field settings
  41. //! And enables/disables all depth of field passes based on component activation
  42. class NewDepthOfFieldParentPass final
  43. : public RPI::ParentPass
  44. {
  45. AZ_RPI_PASS(NewDepthOfFieldParentPass);
  46. public:
  47. AZ_RTTI(AZ::Render::NewDepthOfFieldParentPass, "{71F4998B-447C-4BAC-A5BE-2D2850FABB57}", AZ::RPI::ParentPass);
  48. AZ_CLASS_ALLOCATOR(NewDepthOfFieldParentPass, SystemAllocator);
  49. virtual ~NewDepthOfFieldParentPass() = default;
  50. static RPI::Ptr<NewDepthOfFieldParentPass> Create(const RPI::PassDescriptor& descriptor);
  51. bool IsEnabled() const override;
  52. protected:
  53. // Behavior functions override...
  54. void FrameBeginInternal(FramePrepareParams params) override;
  55. private:
  56. NewDepthOfFieldParentPass(const RPI::PassDescriptor& descriptor);
  57. };
  58. //! Need a class for the tile reduce pass because it dispatches a non-trivial number of threads
  59. class NewDepthOfFieldTileReducePass final
  60. : public RPI::ComputePass
  61. {
  62. AZ_RPI_PASS(NewDepthOfFieldTileReducePass);
  63. public:
  64. AZ_RTTI(AZ::Render::NewDepthOfFieldTileReducePass, "{2E072695-0847-43A6-9BE4-D6D85CFFBA41}", AZ::RPI::ComputePass);
  65. AZ_CLASS_ALLOCATOR(NewDepthOfFieldTileReducePass, SystemAllocator);
  66. virtual ~NewDepthOfFieldTileReducePass() = default;
  67. static RPI::Ptr<NewDepthOfFieldTileReducePass> Create(const RPI::PassDescriptor& descriptor);
  68. protected:
  69. // Behavior functions override...
  70. void FrameBeginInternal(FramePrepareParams params) override;
  71. private:
  72. NewDepthOfFieldTileReducePass(const RPI::PassDescriptor& descriptor);
  73. };
  74. //! Filter pass used to render the bokeh blur effect on downsampled image buffer
  75. //! This class is used for both the large filter and the small filter
  76. //! It's main purpose is calculating the sample positions and setting srg constants
  77. class NewDepthOfFieldFilterPass final
  78. : public RPI::FullscreenTrianglePass
  79. {
  80. AZ_RPI_PASS(NewDepthOfFieldFilterPass);
  81. public:
  82. AZ_RTTI(AZ::Render::NewDepthOfFieldFilterPass, "{F8A98E53-1A50-4178-A6EB-2BD0148C038B}", AZ::RPI::FullscreenTrianglePass);
  83. AZ_CLASS_ALLOCATOR(NewDepthOfFieldFilterPass, SystemAllocator);
  84. virtual ~NewDepthOfFieldFilterPass() = default;
  85. static RPI::Ptr<NewDepthOfFieldFilterPass> Create(const RPI::PassDescriptor& descriptor);
  86. protected:
  87. // Behavior functions override...
  88. void FrameBeginInternal(FramePrepareParams params) override;
  89. private:
  90. NewDepthOfFieldFilterPass(const RPI::PassDescriptor& descriptor);
  91. // SRG binding indices...
  92. AZ::RHI::ShaderInputNameIndex m_constantsIndex = "m_dofConstants";
  93. };
  94. } // namespace Render
  95. } // namespace AZ