/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #include #include #include #include #include #include namespace AZ { namespace Render { SkinnedMeshVertexStreamProperties::SkinnedMeshVertexStreamProperties() { // Attributes of the input buffers used for skinning m_inputStreamInfo[static_cast(SkinnedMeshInputVertexStreams::Position)] = SkinnedMeshVertexStreamInfo{ RHI::Format::R32G32B32_FLOAT, sizeof(AZ::PackedVector3f), Name{"SkinnedMeshInputPositions"}, Name{"m_sourcePositions"}, RHI::ShaderSemantic{Name{"UNUSED"}} }; m_inputStreamInfo[static_cast(SkinnedMeshInputVertexStreams::Normal)] = SkinnedMeshVertexStreamInfo{ RHI::Format::R32G32B32_FLOAT, sizeof(AZ::PackedVector3f), Name{"SkinnedMeshInputNormals"}, Name{"m_sourceNormals"}, RHI::ShaderSemantic{Name{"UNUSED"}} }; m_inputStreamInfo[static_cast(SkinnedMeshInputVertexStreams::Tangent)] = SkinnedMeshVertexStreamInfo{ RHI::Format::R32G32B32A32_FLOAT, sizeof(AZ::Vector4), Name{"SkinnedMeshInputTangents"}, Name{"m_sourceTangents"}, RHI::ShaderSemantic{Name{"UNUSED"}} }; m_inputStreamInfo[static_cast(SkinnedMeshInputVertexStreams::BiTangent)] = SkinnedMeshVertexStreamInfo{ RHI::Format::R32G32B32_FLOAT, sizeof(AZ::PackedVector3f), Name{"SkinnedMeshInputBiTangents"}, Name{"m_sourceBiTangents"}, RHI::ShaderSemantic{Name{"UNUSED"}} }; m_inputStreamInfo[static_cast(SkinnedMeshInputVertexStreams::BlendIndices)] = SkinnedMeshVertexStreamInfo{ RHI::Format::R32G32B32A32_UINT, sizeof(AZ::Vector4), Name{"SkinnedMeshInputBlendIndices"}, Name{"m_sourceBlendIndices"}, RHI::ShaderSemantic{Name{"UNUSED"}} }; m_inputStreamInfo[static_cast(SkinnedMeshInputVertexStreams::BlendWeights)] = SkinnedMeshVertexStreamInfo{ RHI::Format::R32G32B32A32_FLOAT, sizeof(AZ::Vector4), Name{"SkinnedMeshInputBlendWeights"}, Name{"m_sourceBlendWeights"}, RHI::ShaderSemantic{Name{"UNUSED"}} }; m_inputStreamInfo[static_cast(SkinnedMeshInputVertexStreams::Color)] = SkinnedMeshVertexStreamInfo{ RHI::Format::R32G32B32A32_FLOAT, sizeof(AZ::Vector4), Name{"SkinnedMeshInputColors"}, Name{"m_sourceColors"}, RHI::ShaderSemantic{Name{"UNUSED"}} }; // Attributes of the vertex buffers that are not used or modified during skinning, but are shared between all target models that share the same source m_staticStreamInfo[static_cast(SkinnedMeshStaticVertexStreams::UV_0)] = SkinnedMeshVertexStreamInfo{ RHI::Format::R32G32_FLOAT, sizeof(float[2]), Name{"SkinnedMeshStaticUVs"}, Name{"unused"}, RHI::ShaderSemantic{Name{"UV"}} }; m_staticStreamInfo[static_cast(SkinnedMeshStaticVertexStreams::Color)] = SkinnedMeshVertexStreamInfo{ RHI::Format::R32G32B32A32_FLOAT, sizeof(AZ::Vector4), Name{"SkinnedMeshStaticColors"}, Name{"unused"}, RHI::ShaderSemantic{Name{"COLOR"}} }; // Attributes of the vertex streams of the target model that is written to during skinning m_outputStreamInfo[static_cast(SkinnedMeshOutputVertexStreams::Position)] = SkinnedMeshOutputVertexStreamInfo{ RHI::Format::R32G32B32_FLOAT, sizeof(AZ::PackedVector3f), Name{"SkinnedMeshOutputPositions"}, Name{"m_targetPositions"}, RHI::ShaderSemantic{Name{"POSITION"}}, SkinnedMeshInputVertexStreams::Position }; m_outputStreamInfo[static_cast(SkinnedMeshOutputVertexStreams::Normal)] = SkinnedMeshOutputVertexStreamInfo{ RHI::Format::R32G32B32_FLOAT, sizeof(AZ::PackedVector3f), Name{"SkinnedMeshOutputNormals"}, Name{"m_targetNormals"}, RHI::ShaderSemantic{Name{"NORMAL"}}, SkinnedMeshInputVertexStreams::Normal }; m_outputStreamInfo[static_cast(SkinnedMeshOutputVertexStreams::Tangent)] = SkinnedMeshOutputVertexStreamInfo{ RHI::Format::R32G32B32A32_FLOAT, sizeof(AZ::Vector4), Name{"SkinnedMeshOutputTangents"}, Name{"m_targetTangents"}, RHI::ShaderSemantic{Name{"TANGENT"}}, SkinnedMeshInputVertexStreams::Tangent }; m_outputStreamInfo[static_cast(SkinnedMeshOutputVertexStreams::BiTangent)] = SkinnedMeshOutputVertexStreamInfo{ RHI::Format::R32G32B32_FLOAT, sizeof(AZ::PackedVector3f), Name{"SkinnedMeshOutputBiTangents"}, Name{"m_targetBiTangents"}, RHI::ShaderSemantic{Name{"BITANGENT"}}, SkinnedMeshInputVertexStreams::BiTangent }; m_outputStreamInfo[static_cast(SkinnedMeshOutputVertexStreams::Color)] = SkinnedMeshOutputVertexStreamInfo{ RHI::Format::R32G32B32A32_FLOAT, sizeof(AZ::Vector4), Name{"SkinnedMeshOutputColors"}, Name{"m_targetColors"}, RHI::ShaderSemantic{Name{"COLOR"}}, SkinnedMeshInputVertexStreams::Color }; { auto bufferPoolDesc = AZStd::make_unique(); bufferPoolDesc->m_bindFlags = RHI::BufferBindFlags::ShaderRead; // Skinning input buffers have read-only access bufferPoolDesc->m_heapMemoryLevel = RHI::HeapMemoryLevel::Device; RPI::ResourcePoolAssetCreator creator; creator.Begin(Uuid::CreateRandom()); creator.SetPoolDescriptor(AZStd::move(bufferPoolDesc)); creator.SetPoolName("SkinnedMeshInputStreamPool"); creator.End(m_inputStreamResourcePool); } { auto bufferPoolDesc = AZStd::make_unique(); // Static buffers that don't change during skinning are used strictly as input assembly buffers bufferPoolDesc->m_bindFlags = RHI::BufferBindFlags::InputAssembly; bufferPoolDesc->m_heapMemoryLevel = RHI::HeapMemoryLevel::Device; RPI::ResourcePoolAssetCreator creator; creator.Begin(Uuid::CreateRandom()); creator.SetPoolDescriptor(AZStd::move(bufferPoolDesc)); creator.SetPoolName("SkinnedMeshStaticStreamPool"); creator.End(m_staticStreamResourcePool); } { auto bufferPoolDesc = AZStd::make_unique(); // Output buffers are both written to during skinning and used as input assembly buffers bufferPoolDesc->m_bindFlags = RHI::BufferBindFlags::InputAssembly | RHI::BufferBindFlags::ShaderReadWrite; bufferPoolDesc->m_heapMemoryLevel = RHI::HeapMemoryLevel::Device; RPI::ResourcePoolAssetCreator creator; creator.Begin(Uuid::CreateRandom()); creator.SetPoolDescriptor(AZStd::move(bufferPoolDesc)); creator.SetPoolName("SkinnedMeshOutputStreamPool"); creator.End(m_outputStreamResourcePool); } }; const SkinnedMeshVertexStreamInfo& SkinnedMeshVertexStreamProperties::GetInputStreamInfo(SkinnedMeshInputVertexStreams stream) const { return m_inputStreamInfo[static_cast(stream)]; } const SkinnedMeshVertexStreamInfo& SkinnedMeshVertexStreamProperties::GetStaticStreamInfo(SkinnedMeshStaticVertexStreams stream) const { return m_staticStreamInfo[static_cast(stream)]; } const SkinnedMeshOutputVertexStreamInfo& SkinnedMeshVertexStreamProperties::GetOutputStreamInfo(SkinnedMeshOutputVertexStreams stream) const { return m_outputStreamInfo[static_cast(stream)]; } Data::Asset SkinnedMeshVertexStreamProperties::GetInputStreamResourcePool() const { return m_inputStreamResourcePool; } Data::Asset SkinnedMeshVertexStreamProperties::GetStaticStreamResourcePool() const { return m_staticStreamResourcePool; } Data::Asset SkinnedMeshVertexStreamProperties::GetOutputStreamResourcePool() const { return m_outputStreamResourcePool; } uint32_t SkinnedMeshVertexStreamProperties::GetMaxSupportedVertexCount() const { return aznumeric_cast(std::numeric_limits::max()) * aznumeric_cast(std::numeric_limits::max()); } }// namespace Render }// namespace AZ