ReflectionScreenSpaceDownsampleDepthLinearChildPass.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 "ReflectionScreenSpaceDownsampleDepthLinearChildPass.h"
  9. #include <Atom/RPI.Public/Scene.h>
  10. #include <Atom/RPI.Public/RenderPipeline.h>
  11. #include <SpecularReflections/SpecularReflectionsFeatureProcessor.h>
  12. namespace AZ
  13. {
  14. namespace Render
  15. {
  16. RPI::Ptr<ReflectionScreenSpaceDownsampleDepthLinearChildPass> ReflectionScreenSpaceDownsampleDepthLinearChildPass::Create(const RPI::PassDescriptor& descriptor)
  17. {
  18. RPI::Ptr<ReflectionScreenSpaceDownsampleDepthLinearChildPass> pass = aznew ReflectionScreenSpaceDownsampleDepthLinearChildPass(descriptor);
  19. return AZStd::move(pass);
  20. }
  21. ReflectionScreenSpaceDownsampleDepthLinearChildPass::ReflectionScreenSpaceDownsampleDepthLinearChildPass(const RPI::PassDescriptor& descriptor)
  22. : RPI::FullscreenTrianglePass(descriptor)
  23. {
  24. }
  25. void ReflectionScreenSpaceDownsampleDepthLinearChildPass::FrameBeginInternal(FramePrepareParams params)
  26. {
  27. RPI::Scene* scene = m_pipeline->GetScene();
  28. SpecularReflectionsFeatureProcessorInterface* specularReflectionsFeatureProcessor = scene->GetFeatureProcessor<SpecularReflectionsFeatureProcessorInterface>();
  29. AZ_Assert(specularReflectionsFeatureProcessor, "ReflectionScreenSpaceDownsampleDepthLinearChildPass requires the SpecularReflectionsFeatureProcessor");
  30. // get attachment size
  31. RPI::PassAttachment* inputAttachment = GetInputBinding(0).GetAttachment().get();
  32. AZ_Assert(inputAttachment, "ReflectionScreenSpaceDownsampleDepthLinearChildPass: Input binding has no attachment!");
  33. RHI::Size size = inputAttachment->m_descriptor.m_image.m_size;
  34. bool halfResolution = specularReflectionsFeatureProcessor->GetSSROptions().m_halfResolution;
  35. if (m_imageSize != size || m_halfResolution != halfResolution)
  36. {
  37. m_imageSize = size;
  38. m_halfResolution = halfResolution;
  39. m_invOutputScale = (m_mipLevel == 0 && m_halfResolution) ? 2 : static_cast<float>(pow(2.0f, m_mipLevel));
  40. m_updateSrg = true;
  41. }
  42. float outputScale = 1.0f / m_invOutputScale;
  43. uint32_t outputWidth = static_cast<uint32_t>(m_imageSize.m_width * outputScale);
  44. uint32_t outputHeight = static_cast<uint32_t>(m_imageSize.m_height * outputScale);
  45. params.m_viewportState = RHI::Viewport(0, static_cast<float>(outputWidth), 0, static_cast<float>(outputHeight));
  46. params.m_scissorState = RHI::Scissor(0, 0, outputWidth, outputHeight);
  47. FullscreenTrianglePass::FrameBeginInternal(params);
  48. }
  49. void ReflectionScreenSpaceDownsampleDepthLinearChildPass::CompileResources(const RHI::FrameGraphCompileContext& context)
  50. {
  51. if (m_updateSrg)
  52. {
  53. m_shaderResourceGroup->SetConstant(m_invOutputScaleNameIndex, m_invOutputScale);
  54. m_shaderResourceGroup->SetConstant(m_mipLevelNameIndex, m_mipLevel);
  55. m_shaderResourceGroup->SetConstant(m_halfResolutionNameIndex, m_halfResolution);
  56. // Note: when processing mip0 both the mipLevel and previousMipLevel are set to 0
  57. uint32_t previousMipLevel = AZStd::max(0, aznumeric_cast<int32_t>(m_mipLevel) - 1);
  58. RHI::Size previousMipImageSize = m_mipLevel == 0 ? m_imageSize : m_imageSize.GetReducedMip(previousMipLevel);
  59. m_shaderResourceGroup->SetConstant(m_previousMipLevelNameIndex, previousMipLevel);
  60. m_shaderResourceGroup->SetConstant(m_previousMipWidthNameIndex, previousMipImageSize.m_width);
  61. m_shaderResourceGroup->SetConstant(m_previousMipHeightNameIndex, previousMipImageSize.m_height);
  62. m_updateSrg = false;
  63. }
  64. FullscreenTrianglePass::CompileResources(context);
  65. }
  66. } // namespace RPI
  67. } // namespace AZ