DepthOfFieldWriteFocusDepthFromGpuPass.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 <Atom/RHI/CommandList.h>
  9. #include <PostProcessing/DepthOfFieldWriteFocusDepthFromGpuPass.h>
  10. namespace AZ
  11. {
  12. namespace Render
  13. {
  14. RPI::Ptr<DepthOfFieldWriteFocusDepthFromGpuPass> DepthOfFieldWriteFocusDepthFromGpuPass::Create(const RPI::PassDescriptor& descriptor)
  15. {
  16. RPI::Ptr<DepthOfFieldWriteFocusDepthFromGpuPass> pass = aznew DepthOfFieldWriteFocusDepthFromGpuPass(descriptor);
  17. return pass;
  18. }
  19. DepthOfFieldWriteFocusDepthFromGpuPass::DepthOfFieldWriteFocusDepthFromGpuPass(const RPI::PassDescriptor& descriptor)
  20. : RPI::ComputePass(descriptor)
  21. {
  22. }
  23. void DepthOfFieldWriteFocusDepthFromGpuPass::SetupFrameGraphDependencies(RHI::FrameGraphInterface frameGraph)
  24. {
  25. AZ_Assert(m_bufferRef != nullptr, "%s has a null buffer when calling Prepare.", GetPathName().GetCStr());
  26. ComputePass::SetupFrameGraphDependencies(frameGraph);
  27. RHI::BufferScopeAttachmentDescriptor desc;
  28. desc.m_attachmentId = m_bufferRef->GetAttachmentId();
  29. desc.m_bufferViewDescriptor = m_bufferRef->GetBufferViewDescriptor();
  30. desc.m_loadStoreAction.m_loadAction = AZ::RHI::AttachmentLoadAction::DontCare;
  31. frameGraph.UseShaderAttachment(desc, AZ::RHI::ScopeAttachmentAccess::Write);
  32. }
  33. void DepthOfFieldWriteFocusDepthFromGpuPass::CompileResources(const RHI::FrameGraphCompileContext& context)
  34. {
  35. AZ_Assert(m_shaderResourceGroup != nullptr, "%s has a null shader resource group when calling Compile.", GetPathName().GetCStr());
  36. m_shaderResourceGroup->SetConstant(m_autoFocusScreenPositionIndex, m_autoFocusScreenPosition);
  37. m_shaderResourceGroup->SetBufferView(m_autoFocusDataBufferIndex, m_bufferRef->GetBufferView());
  38. BindPassSrg(context, m_shaderResourceGroup);
  39. m_shaderResourceGroup->Compile();
  40. }
  41. void DepthOfFieldWriteFocusDepthFromGpuPass::SetScreenPosition(const AZ::Vector2& screenPosition)
  42. {
  43. m_autoFocusScreenPosition = screenPosition;
  44. }
  45. void DepthOfFieldWriteFocusDepthFromGpuPass::SetBufferRef(RPI::Ptr<RPI::Buffer> bufferRef)
  46. {
  47. m_bufferRef = bufferRef;
  48. }
  49. void DepthOfFieldWriteFocusDepthFromGpuPass::BuildInternal()
  50. {
  51. AZ_Assert(m_bufferRef != nullptr, "%s has a null buffer when calling BuildInternal.", GetPathName().GetCStr());
  52. AttachBufferToSlot(Name("DofDepthInputOutput"), m_bufferRef);
  53. }
  54. } // namespace Render
  55. } // namespace AZ