MorphTargetComputePass.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 <MorphTargets/MorphTargetComputePass.h>
  9. #include <SkinnedMesh/SkinnedMeshFeatureProcessor.h>
  10. #include <Atom/Feature/SkinnedMesh/SkinnedMeshOutputStreamManagerInterface.h>
  11. #include <Atom/RPI.Public/Shader/Shader.h>
  12. #include <Atom/RHI/CommandList.h>
  13. namespace AZ
  14. {
  15. namespace Render
  16. {
  17. MorphTargetComputePass::MorphTargetComputePass(const RPI::PassDescriptor& descriptor)
  18. : RPI::ComputePass(descriptor)
  19. {
  20. }
  21. RPI::Ptr<MorphTargetComputePass> MorphTargetComputePass::Create(const RPI::PassDescriptor& descriptor)
  22. {
  23. RPI::Ptr<MorphTargetComputePass> pass = aznew MorphTargetComputePass(descriptor);
  24. return pass;
  25. }
  26. Data::Instance<RPI::Shader> MorphTargetComputePass::GetShader() const
  27. {
  28. return m_shader;
  29. }
  30. void MorphTargetComputePass::SetFeatureProcessor(SkinnedMeshFeatureProcessor* skinnedMeshFeatureProcessor)
  31. {
  32. m_skinnedMeshFeatureProcessor = skinnedMeshFeatureProcessor;
  33. }
  34. void MorphTargetComputePass::BuildInternal()
  35. {
  36. // The same buffer that skinning writes to is used to manage the computed vertex deltas that are passed from the
  37. // morph target pass to the skinning pass. This simplifies things by only requiring one class to manage the memory
  38. AttachBufferToSlot(Name{ "MorphTargetDeltaOutput" }, SkinnedMeshOutputStreamManagerInterface::Get()->GetBuffer());
  39. }
  40. void MorphTargetComputePass::SetupFrameGraphDependencies(RHI::FrameGraphInterface frameGraph)
  41. {
  42. if (m_skinnedMeshFeatureProcessor)
  43. {
  44. m_skinnedMeshFeatureProcessor->SetupMorphTargetScope(frameGraph);
  45. }
  46. ComputePass::SetupFrameGraphDependencies(frameGraph);
  47. }
  48. void MorphTargetComputePass::BuildCommandListInternal(const RHI::FrameGraphExecuteContext& context)
  49. {
  50. if (m_skinnedMeshFeatureProcessor)
  51. {
  52. SetSrgsForDispatch(context);
  53. m_skinnedMeshFeatureProcessor->SubmitMorphTargetDispatchItems(context, context.GetSubmitRange().m_startIndex, context.GetSubmitRange().m_endIndex);
  54. }
  55. }
  56. } // namespace Render
  57. } // namespace AZ