DisplayMapperPass.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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/RHI/CommandList.h>
  11. #include <Atom/RHI/DeviceDrawItem.h>
  12. #include <Atom/RHI/ScopeProducer.h>
  13. #include <Atom/RPI.Public/Pass/ParentPass.h>
  14. #include <Atom/RPI.Public/Pass/FullscreenTrianglePass.h>
  15. #include <Atom/RPI.Public/Shader/Shader.h>
  16. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  17. #include <Atom/RPI.Reflect/Pass/FullscreenTrianglePassData.h>
  18. #include <Atom/Feature/ACES/AcesDisplayMapperFeatureProcessor.h>
  19. #include <Atom/Feature/DisplayMapper/DisplayMapperConfigurationDescriptor.h>
  20. #include <DisplayMapper/AcesOutputTransformLutPass.h>
  21. #include <DisplayMapper/AcesOutputTransformPass.h>
  22. #include <DisplayMapper/ApplyShaperLookupTablePass.h>
  23. #include <DisplayMapper/BakeAcesOutputTransformLutPass.h>
  24. #include <DisplayMapper/DisplayMapperFullScreenPass.h>
  25. #include <DisplayMapper/OutputTransformPass.h>
  26. #include <AzFramework/Windowing/WindowBus.h>
  27. namespace AZ
  28. {
  29. namespace Render
  30. {
  31. static const char* const DisplayMapperPassTemplateName = "DisplayMapperTemplate";
  32. /**
  33. * The display mapper pass.
  34. * This pass implements grading and output transform passes.
  35. * If an ACES output transform is configured, the respective passes implement the
  36. * ACES Reference Rendering Transform(RRT) and Output Device Transform(ODT).
  37. *
  38. * The passes created will be in the form of
  39. * <HDR Grading LUT>, <Output Transform>, <LDR Grading LUT>
  40. *
  41. * <HDR Grading LUT> if enabled, is an instance of ApplyShaperLookupTablePass
  42. * <Output Transform> depends on the DisplayMapper function:
  43. * Aces - AcesOutputTransformPass
  44. * AcesLUT - BakeAcesOutputTransformLutPass, AcesOutputTransformLutPass
  45. * Passthrough - DisplayMapperFullscreenPass
  46. * Gamma Correction - DisplayMapperFullscreenPass
  47. * <LDR Grading LUT> if enabled, is an instance of ApplyShaperLookupTablePass
  48. * [GFX TODO][ATOM-4189] Optimize the passthrough function in the DisplayMapper
  49. */
  50. class DisplayMapperPass
  51. : public RPI::ParentPass
  52. {
  53. AZ_RPI_PASS(DisplayMapperPass);
  54. public:
  55. AZ_RTTI(DisplayMapperPass, "{B022D9D6-BDFA-4435-B27C-466DC4C91D18}", RPI::ParentPass);
  56. AZ_CLASS_ALLOCATOR(DisplayMapperPass, SystemAllocator);
  57. virtual ~DisplayMapperPass() = default;
  58. //! Creates a DisplayMapperPass
  59. static RPI::Ptr<DisplayMapperPass> Create(const RPI::PassDescriptor& descriptor);
  60. protected:
  61. DisplayMapperPass(const RPI::PassDescriptor& descriptor);
  62. // Pass behavior overrides
  63. void BuildInternal() final;
  64. void InitializeInternal() final;
  65. void FrameBeginInternal(FramePrepareParams params) final;
  66. void FrameEndInternal() final;
  67. void CreateChildPassesInternal() final;
  68. private:
  69. void ConfigureDisplayParameters();
  70. void BuildGradingLutTemplate();
  71. void CreateGradingAndAcesPasses();
  72. void UpdateDisplayMapperConfiguration();
  73. void ClearChildren();
  74. // Return true if it needs a separate ldr color grading pass
  75. bool UsesLdrGradingLutPass() const;
  76. // Return true if it needs an output transform pass (for doing certain tonemapping and gamma correction)
  77. bool UsesOutputTransformPass() const;
  78. DisplayMapperConfigurationDescriptor m_displayMapperConfigurationDescriptor;
  79. DisplayMapperConfigurationDescriptor m_defaultDisplayMapperConfigurationDescriptor;
  80. bool m_mergeLdrGradingLut = false;
  81. RPI::AssetReference m_outputTransformOverrideShader;
  82. bool m_needToRebuildChildren = false;
  83. const RPI::PassAttachmentBinding* m_pipelineOutput = nullptr;
  84. AZ::Render::DisplayMapperParameters m_displayMapperParameters = {};
  85. AZStd::shared_ptr<RPI::PassTemplate> m_acesOutputTransformTemplate;
  86. AZStd::shared_ptr<RPI::PassTemplate> m_acesOutputTransformLutTemplate;
  87. AZStd::shared_ptr<RPI::PassTemplate> m_bakeAcesOutputTransformLutTemplate;
  88. AZStd::shared_ptr<RPI::PassTemplate> m_passthroughTemplate;
  89. AZStd::shared_ptr<RPI::PassTemplate> m_sRGBTemplate;
  90. AZStd::shared_ptr<RPI::PassTemplate> m_ldrGradingLookupTableTemplate;
  91. AZStd::shared_ptr<RPI::PassTemplate> m_outputTransformTemplate;
  92. RPI::Ptr<AcesOutputTransformPass> m_acesOutputTransformPass = nullptr;
  93. RPI::Ptr<BakeAcesOutputTransformLutPass> m_bakeAcesOutputTransformLutPass = nullptr;
  94. RPI::Ptr<AcesOutputTransformLutPass> m_acesOutputTransformLutPass = nullptr;
  95. RPI::Ptr<DisplayMapperFullScreenPass> m_displayMapperPassthroughPass = nullptr;
  96. RPI::Ptr<DisplayMapperFullScreenPass> m_displayMapperSRGBPass = nullptr;
  97. RPI::Ptr<ApplyShaperLookupTablePass> m_ldrGradingLookupTablePass = nullptr;
  98. RPI::Ptr<OutputTransformPass> m_outputTransformPass = nullptr;
  99. const Name m_applyShaperLookupTableOutputName = Name{ "ApplyShaperLookupTableOutput" };
  100. const Name m_applyShaperLookupTablePassName = Name{ "ApplyShaperLookupTable" };
  101. const Name m_ldrGradingLookupTablePassName = Name{ "LdrGradingLookupTable" };
  102. const Name m_acesOutputTransformPassName = Name{ "AcesOutputTransform" };
  103. const Name m_bakeAcesOutputTransformLutPassName = Name{ "BakeAcesOutputTransformLut" };
  104. const Name m_acesOutputTransformLutPassName = Name{ "AcesLutPass" };
  105. const Name m_displayMapperPassthroughPassName = Name{ "DisplayMapperPassthrough" };
  106. const Name m_displayMapperSRGBPassName = Name{ "DisplayMapperSRGB" };
  107. const Name m_outputTransformPassName = Name{ "OutputTransform" };
  108. RHI::Format m_displayBufferFormat = RHI::Format::Unknown;
  109. };
  110. } // namespace Render
  111. } // namespace AZ