3
0

EyeAdaptationPass.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #include <PostProcessing/EyeAdaptationPass.h>
  9. #include <Atom/RHI/Factory.h>
  10. #include <Atom/RHI/FrameGraphAttachmentInterface.h>
  11. #include <Atom/RHI/FrameGraphInterface.h>
  12. #include <Atom/RHI/PipelineState.h>
  13. #include <Atom/RPI.Public/Base.h>
  14. #include <Atom/RPI.Public/Pass/PassUtils.h>
  15. #include <Atom/RPI.Public/RenderPipeline.h>
  16. #include <Atom/RHI/RHISystemInterface.h>
  17. #include <Atom/RPI.Public/RPIUtils.h>
  18. #include <Atom/RPI.Public/Scene.h>
  19. #include <Atom/RPI.Public/View.h>
  20. #include <Atom/RPI.Reflect/Pass/PassTemplate.h>
  21. #include <Atom/RPI.Reflect/Shader/ShaderAsset.h>
  22. #include <PostProcess/PostProcessFeatureProcessor.h>
  23. #include <PostProcess/ExposureControl/ExposureControlSettings.h>
  24. namespace AZ
  25. {
  26. namespace Render
  27. {
  28. static const char* const EyeAdaptationBufferName = "EyeAdaptationBuffer";
  29. RPI::Ptr<EyeAdaptationPass> EyeAdaptationPass::Create(const RPI::PassDescriptor& descriptor)
  30. {
  31. RPI::Ptr<EyeAdaptationPass> pass = aznew EyeAdaptationPass(descriptor);
  32. return pass;
  33. }
  34. EyeAdaptationPass::EyeAdaptationPass(const RPI::PassDescriptor& descriptor)
  35. : RPI::ComputePass(descriptor)
  36. {
  37. }
  38. void EyeAdaptationPass::InitBuffer()
  39. {
  40. ExposureCalculationData defaultData;
  41. RPI::CommonBufferDescriptor desc;
  42. desc.m_poolType = RPI::CommonBufferPoolType::ReadWrite;
  43. desc.m_bufferName = EyeAdaptationBufferName;
  44. desc.m_byteCount = sizeof(ExposureCalculationData);
  45. desc.m_elementSize = aznumeric_cast<uint32_t>(desc.m_byteCount);
  46. desc.m_bufferData = &defaultData;
  47. m_buffer = RPI::BufferSystemInterface::Get()->CreateBufferFromCommonPool(desc);
  48. }
  49. void EyeAdaptationPass::BuildInternal()
  50. {
  51. if (!m_buffer)
  52. {
  53. InitBuffer();
  54. }
  55. AttachBufferToSlot(EyeAdaptationDataInputOutputSlotName, m_buffer);
  56. }
  57. bool EyeAdaptationPass::IsEnabled() const
  58. {
  59. if (!ComputePass::IsEnabled() || m_pipeline == nullptr)
  60. {
  61. return false;
  62. }
  63. AZ::RPI::Scene* scene = GetScene();
  64. bool enabled = false;
  65. if (scene)
  66. {
  67. PostProcessFeatureProcessor* fp = scene->GetFeatureProcessor<PostProcessFeatureProcessor>();
  68. AZ::RPI::ViewPtr view = GetRenderPipeline()->GetFirstView(GetPipelineViewTag());
  69. if (fp)
  70. {
  71. PostProcessSettings* postProcessSettings = fp->GetLevelSettingsFromView(view);
  72. if (postProcessSettings)
  73. {
  74. ExposureControlSettings* settings = postProcessSettings->GetExposureControlSettings();
  75. if (settings)
  76. {
  77. enabled = true;
  78. }
  79. }
  80. }
  81. }
  82. return enabled;
  83. }
  84. void EyeAdaptationPass::FrameBeginInternal(FramePrepareParams params)
  85. {
  86. AZ::RPI::ComputePass::FrameBeginInternal(params);
  87. AZ::RPI::Scene* scene = GetScene();
  88. if (scene)
  89. {
  90. PostProcessFeatureProcessor* fp = scene->GetFeatureProcessor<PostProcessFeatureProcessor>();
  91. if (fp)
  92. {
  93. AZ::RPI::ViewPtr view = GetRenderPipeline()->GetFirstView(GetPipelineViewTag());
  94. PostProcessSettings* postProcessSettings = fp->GetLevelSettingsFromView(view);
  95. if (postProcessSettings)
  96. {
  97. ExposureControlSettings* settings = postProcessSettings->GetExposureControlSettings();
  98. if (settings)
  99. {
  100. settings->UpdateBuffer();
  101. view->GetShaderResourceGroup()->SetBufferView(m_exposureControlBufferInputIndex, settings->GetBufferView());
  102. }
  103. }
  104. }
  105. }
  106. }
  107. } // namespace Render
  108. } // namespace AZ