VertexAnimationPass.cpp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "VertexAnimationPass.h"
  9. namespace AZ::Render
  10. {
  11. RPI::Ptr<VertexAnimationPass> VertexAnimationPass::Create(const RPI::PassDescriptor& descriptor)
  12. {
  13. return aznew VertexAnimationPass{ descriptor };
  14. }
  15. VertexAnimationPass::VertexAnimationPass(const RPI::PassDescriptor& descriptor)
  16. : BaseClass{ descriptor }
  17. {
  18. m_frameTimer.Stamp();
  19. }
  20. void VertexAnimationPass::SetSourceBuffer(Data::Instance<RPI::Buffer> sourceBuffer)
  21. {
  22. m_sourceBuffer = sourceBuffer;
  23. }
  24. void VertexAnimationPass::SetTargetBuffer(Data::Instance<RPI::Buffer> targetBuffer)
  25. {
  26. m_targetBuffer = targetBuffer;
  27. }
  28. void VertexAnimationPass::SetInstanceOffsetBuffer(Data::Instance<RPI::Buffer> instanceOffsetBuffer)
  29. {
  30. m_instanceOffsetBuffer = instanceOffsetBuffer;
  31. }
  32. void VertexAnimationPass::SetInstanceCount(u32 instanceCount)
  33. {
  34. m_instanceCount = instanceCount;
  35. }
  36. void VertexAnimationPass::SetVertexCountPerInstance(u32 vertexCountPerInstance)
  37. {
  38. m_vertexCountPerInstance = vertexCountPerInstance;
  39. }
  40. void VertexAnimationPass::SetTargetVertexStridePerInstance(u32 targetVertexStridePerInstance)
  41. {
  42. m_targetVertexStridePerInstance = targetVertexStridePerInstance;
  43. }
  44. void VertexAnimationPass::BuildInternal()
  45. {
  46. AttachBufferToSlot("SourceData", m_sourceBuffer);
  47. AttachBufferToSlot("TargetData", m_targetBuffer);
  48. AttachBufferToSlot("InstanceOffsetData", m_instanceOffsetBuffer);
  49. RHI::BufferViewDescriptor sourceBufferView;
  50. sourceBufferView.m_elementOffset = 0;
  51. sourceBufferView.m_elementCount = m_vertexCountPerInstance;
  52. sourceBufferView.m_elementSize = 12;
  53. FindAttachmentBinding(Name{ "SourceData" })->m_unifiedScopeDesc.SetAsBuffer(sourceBufferView);
  54. RHI::BufferViewDescriptor targetBufferView;
  55. targetBufferView.m_elementOffset = 0;
  56. targetBufferView.m_elementCount = m_targetVertexStridePerInstance * m_instanceCount;
  57. targetBufferView.m_elementSize = 12;
  58. FindAttachmentBinding(Name{ "TargetData" })->m_unifiedScopeDesc.SetAsBuffer(targetBufferView);
  59. RHI::BufferViewDescriptor instanceOffsetBufferView;
  60. instanceOffsetBufferView.m_elementOffset = 0;
  61. instanceOffsetBufferView.m_elementCount = m_instanceCount;
  62. instanceOffsetBufferView.m_elementSize = 12;
  63. FindAttachmentBinding(Name{ "InstanceOffsetData" })->m_unifiedScopeDesc.SetAsBuffer(instanceOffsetBufferView);
  64. BaseClass::BuildInternal();
  65. }
  66. void VertexAnimationPass::FrameBeginInternal(FramePrepareParams params)
  67. {
  68. m_shaderResourceGroup->SetConstant(m_frameTimeNameIndex, m_frameTime);
  69. m_shaderResourceGroup->SetConstant(m_vertexCountPerInstanceNameIndex, m_vertexCountPerInstance);
  70. m_shaderResourceGroup->SetConstant(m_targetVertexStridePerInstanceNameIndex, m_targetVertexStridePerInstance);
  71. m_frameTime += m_frameTimer.StampAndGetDeltaTimeInSeconds();
  72. BaseClass::FrameBeginInternal(params);
  73. }
  74. } // namespace AZ::Render