VignettePass.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/VignettePass.h>
  9. #include <PostProcess/PostProcessFeatureProcessor.h>
  10. #include <Atom/RPI.Public/RenderPipeline.h>
  11. #include <Atom/RPI.Public/Scene.h>
  12. namespace AZ
  13. {
  14. namespace Render
  15. {
  16. RPI::Ptr<VignettePass> VignettePass::Create(const RPI::PassDescriptor& descriptor)
  17. {
  18. RPI::Ptr<VignettePass> pass = aznew VignettePass(descriptor);
  19. return AZStd::move(pass);
  20. }
  21. VignettePass::VignettePass(const RPI::PassDescriptor& descriptor)
  22. : RPI::ComputePass(descriptor)
  23. {
  24. }
  25. bool VignettePass::IsEnabled() const
  26. {
  27. if (!ComputePass::IsEnabled())
  28. {
  29. return false;
  30. }
  31. const RPI::Scene* scene = GetScene();
  32. if (!scene)
  33. {
  34. return false;
  35. }
  36. PostProcessFeatureProcessor* fp = scene->GetFeatureProcessor<PostProcessFeatureProcessor>();
  37. const RPI::ViewPtr view = GetRenderPipeline()->GetDefaultView();
  38. if (!fp)
  39. {
  40. return false;
  41. }
  42. PostProcessSettings* postProcessSettings = fp->GetLevelSettingsFromView(view);
  43. if (!postProcessSettings)
  44. {
  45. return false;
  46. }
  47. const VignetteSettings* VignetteSettings = postProcessSettings->GetVignetteSettings();
  48. if (!VignetteSettings)
  49. {
  50. return false;
  51. }
  52. return VignetteSettings->GetEnabled();
  53. }
  54. void VignettePass::FrameBeginInternal(FramePrepareParams params)
  55. {
  56. // Must match the struct in Vignette.azsl
  57. struct Constants
  58. {
  59. AZStd::array<u32, 2> m_outputSize;
  60. AZStd::array<float, 2> m_outputCenter;
  61. float m_strength = Vignette::DefaultIntensity;
  62. AZStd::array<float, 3> m_pad;
  63. } constants{};
  64. RPI::Scene* scene = GetScene();
  65. PostProcessFeatureProcessor* fp = scene->GetFeatureProcessor<PostProcessFeatureProcessor>();
  66. if (fp)
  67. {
  68. RPI::ViewPtr view = scene->GetDefaultRenderPipeline()->GetDefaultView();
  69. PostProcessSettings* postProcessSettings = fp->GetLevelSettingsFromView(view);
  70. if (postProcessSettings)
  71. {
  72. VignetteSettings* VignetteSettings = postProcessSettings->GetVignetteSettings();
  73. if (VignetteSettings)
  74. {
  75. constants.m_strength = VignetteSettings->GetIntensity();
  76. }
  77. }
  78. }
  79. AZ_Assert(GetOutputCount() > 0, "VignettePass: No output bindings!");
  80. RPI::PassAttachment* outputAttachment = GetOutputBinding(0).GetAttachment().get();
  81. AZ_Assert(outputAttachment != nullptr, "VignettePass: Output binding has no attachment!");
  82. RHI::Size size = outputAttachment->m_descriptor.m_image.m_size;
  83. constants.m_outputSize[0] = size.m_width;
  84. constants.m_outputSize[1] = size.m_height;
  85. constants.m_outputCenter[0] = (size.m_width - 1) * 0.5f;
  86. constants.m_outputCenter[1] = (size.m_height -1) * 0.5f;
  87. m_shaderResourceGroup->SetConstant(m_constantsIndex, constants);
  88. RPI::ComputePass::FrameBeginInternal(params);
  89. }
  90. } // namespace Render
  91. } // namespace AZ