MorphTargetInputBuffers.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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/Feature/SkinnedMesh/SkinnedMeshInputBuffers.h>
  9. #include <SkinnedMesh/SkinnedMeshOutputStreamManager.h>
  10. #include <Atom/RPI.Reflect/ResourcePoolAssetCreator.h>
  11. #include <Atom/RPI.Reflect/Buffer/BufferAssetCreator.h>
  12. #include <Atom/RPI.Reflect/Model/ModelAssetCreator.h>
  13. #include <Atom/RPI.Reflect/Model/ModelLodAssetCreator.h>
  14. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  15. #include <Atom/RPI.Public/Model/Model.h>
  16. #include <Atom/RHI/Factory.h>
  17. #include <AzCore/std/algorithm.h>
  18. #include <AzCore/Math/PackedVector3.h>
  19. namespace AZ
  20. {
  21. namespace Render
  22. {
  23. MorphTargetInputBuffers::MorphTargetInputBuffers(const RPI::BufferAssetView& bufferAssetView, const AZStd::string& bufferNamePrefix)
  24. {
  25. m_vertexDeltaBuffer = RPI::Buffer::FindOrCreate(bufferAssetView.GetBufferAsset());
  26. if (m_vertexDeltaBuffer)
  27. {
  28. m_vertexDeltaBufferView = m_vertexDeltaBuffer->GetRHIBuffer()->BuildBufferView(bufferAssetView.GetBufferViewDescriptor());
  29. m_vertexDeltaBufferView->SetName(Name(bufferNamePrefix + "MorphTargetVertexDeltaView"));
  30. }
  31. }
  32. void MorphTargetInputBuffers::SetBufferViewsOnShaderResourceGroup(const Data::Instance<RPI::ShaderResourceGroup>& perInstanceSRG)
  33. {
  34. // Set the delta buffer
  35. RHI::ShaderInputBufferIndex srgIndex = perInstanceSRG->FindShaderInputBufferIndex(Name{ "m_vertexDeltas" });
  36. AZ_Error("MorphTargetInputBuffers", srgIndex.IsValid(), "Failed to find shader input index for 'm_positionDeltas' in the skinning compute shader per-instance SRG.");
  37. [[maybe_unused]] bool success = perInstanceSRG->SetBufferView(
  38. srgIndex, m_vertexDeltaBufferView.get());
  39. AZ_Error("MorphTargetInputBuffers", success, "Failed to bind buffer view for vertex deltas");
  40. }
  41. } // namespace Render
  42. }// namespace AZ