ReflectionScreenSpaceBlurChildPass.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 "ReflectionScreenSpaceBlurChildPass.h"
  9. namespace AZ
  10. {
  11. namespace Render
  12. {
  13. RPI::Ptr<ReflectionScreenSpaceBlurChildPass> ReflectionScreenSpaceBlurChildPass::Create(const RPI::PassDescriptor& descriptor)
  14. {
  15. RPI::Ptr<ReflectionScreenSpaceBlurChildPass> pass = aznew ReflectionScreenSpaceBlurChildPass(descriptor);
  16. return AZStd::move(pass);
  17. }
  18. ReflectionScreenSpaceBlurChildPass::ReflectionScreenSpaceBlurChildPass(const RPI::PassDescriptor& descriptor)
  19. : RPI::FullscreenTrianglePass(descriptor)
  20. {
  21. }
  22. void ReflectionScreenSpaceBlurChildPass::FrameBeginInternal(FramePrepareParams params)
  23. {
  24. // get attachment size
  25. RPI::PassAttachment* inputAttachment = GetInputBinding(0).GetAttachment().get();
  26. AZ_Assert(inputAttachment, "ReflectionScreenSpaceBlurChildPass: Input binding has no attachment!");
  27. RHI::Size size = inputAttachment->m_descriptor.m_image.m_size;
  28. if (m_imageSize != size)
  29. {
  30. m_imageSize = size;
  31. m_invOutputScale = (m_passType == PassType::Vertical) ? static_cast<float>(pow(2.0f, m_mipLevel)) : 1.0f;
  32. m_updateSrg = true;
  33. }
  34. float outputScale = 1.0f / m_invOutputScale;
  35. uint32_t outputWidth = static_cast<uint32_t>(m_imageSize.m_width * outputScale);
  36. uint32_t outputHeight = static_cast<uint32_t>(m_imageSize.m_height * outputScale);
  37. params.m_viewportState = RHI::Viewport(0, static_cast<float>(outputWidth), 0, static_cast<float>(outputHeight));
  38. params.m_scissorState = RHI::Scissor(0, 0, outputWidth, outputHeight);
  39. FullscreenTrianglePass::FrameBeginInternal(params);
  40. }
  41. void ReflectionScreenSpaceBlurChildPass::CompileResources(const RHI::FrameGraphCompileContext& context)
  42. {
  43. if (m_updateSrg)
  44. {
  45. m_shaderResourceGroup->SetConstant(m_invOutputScaleNameIndex, m_invOutputScale);
  46. m_shaderResourceGroup->SetConstant(m_mipLevelNameIndex, m_mipLevel);
  47. m_updateSrg = false;
  48. }
  49. FullscreenTrianglePass::CompileResources(context);
  50. }
  51. } // namespace RPI
  52. } // namespace AZ