3
0

DepthOfFieldWriteFocusDepthFromGpuPass.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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, RHI::ScopeAttachmentStage::ComputeShader);
  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(
  38. m_autoFocusDataBufferIndex, m_bufferRef->GetBufferView());
  39. BindPassSrg(context, m_shaderResourceGroup);
  40. m_shaderResourceGroup->Compile();
  41. }
  42. void DepthOfFieldWriteFocusDepthFromGpuPass::SetScreenPosition(const AZ::Vector2& screenPosition)
  43. {
  44. m_autoFocusScreenPosition = screenPosition;
  45. }
  46. void DepthOfFieldWriteFocusDepthFromGpuPass::SetBufferRef(RPI::Ptr<RPI::Buffer> bufferRef)
  47. {
  48. m_bufferRef = bufferRef;
  49. }
  50. void DepthOfFieldWriteFocusDepthFromGpuPass::BuildInternal()
  51. {
  52. AZ_Assert(m_bufferRef != nullptr, "%s has a null buffer when calling BuildInternal.", GetPathName().GetCStr());
  53. AttachBufferToSlot(Name("DofDepthInputOutput"), m_bufferRef);
  54. }
  55. } // namespace Render
  56. } // namespace AZ