diff --git a/Jusin154_Team3D/Client/Private/Broom.cpp b/Jusin154_Team3D/Client/Private/Broom.cpp index 705d3dbde..a0d336b21 100644 --- a/Jusin154_Team3D/Client/Private/Broom.cpp +++ b/Jusin154_Team3D/Client/Private/Broom.cpp @@ -38,6 +38,18 @@ void CBroom::Priority_Update(_float fTimeDelta) void CBroom::Update(_float fTimeDelta) { + m_pModelCom->ComputeAnimation(); + + static _uint m_iIndex = 0; + + if (m_pGameInstance->Key_Down(DIK_1)) + m_iIndex++; + if (m_pGameInstance->Key_Down(DIK_2)) + m_iIndex--; + + m_pModelCom->Set_AnimationIndex(m_iIndex); + + m_pModelCom->Play_Animation(fTimeDelta, m_pTransformCom); } diff --git a/Jusin154_Team3D/Client/Private/Level_GamePlay.cpp b/Jusin154_Team3D/Client/Private/Level_GamePlay.cpp index a3201bcad..0b170fda7 100644 --- a/Jusin154_Team3D/Client/Private/Level_GamePlay.cpp +++ b/Jusin154_Team3D/Client/Private/Level_GamePlay.cpp @@ -140,8 +140,8 @@ HRESULT CLevel_GamePlay::Ready_Layer_Player(const _wstring& strLayerTag) if (FAILED(m_pGameInstance->Add_GameObject_ToLayer(g_iStaticLevel, NEXT_LEVEL, strLayerTag))) return E_FAIL; - if (FAILED(m_pGameInstance->Add_GameObject_ToLayer(g_iStaticLevel, NEXT_LEVEL, strLayerTag))) - return E_FAIL; + /*if (FAILED(m_pGameInstance->Add_GameObject_ToLayer(g_iStaticLevel, NEXT_LEVEL, strLayerTag))) + return E_FAIL;*/ return S_OK; } diff --git a/Jusin154_Team3D/Client/Private/Player.cpp b/Jusin154_Team3D/Client/Private/Player.cpp index 15822f9ac..2420c9b4e 100644 --- a/Jusin154_Team3D/Client/Private/Player.cpp +++ b/Jusin154_Team3D/Client/Private/Player.cpp @@ -77,18 +77,23 @@ HRESULT CPlayer::Initialize(void* pArg) void CPlayer::Priority_Update(_float fTimeDelta) { m_pTransformCom->RewindMomentum(); - m_pTransformCom->Set_State(STATE::POSITION, m_pCharacter_Controller->Get_Position()); + __super::Priority_Update(fTimeDelta); } void CPlayer::Update(_float fTimeDelta) { + m_pModelCom->ComputeAnimation(); + + Key_Input(fTimeDelta); - + m_pFSM->Update(fTimeDelta); - + m_pModelCom->Play_Animation(fTimeDelta, m_pTransformCom); + + __super::Update(fTimeDelta); Describe_Entity(); m_pCharacter_Controller->Move(fTimeDelta); @@ -96,6 +101,9 @@ void CPlayer::Update(_float fTimeDelta) void CPlayer::Late_Update(_float fTimeDelta) { + + m_pTransformCom->Set_State(STATE::POSITION, m_pCharacter_Controller->Get_Position()); + m_pGameInstance->Add_RenderGroup(RENDER::BLEND, this); __super::Late_Update(fTimeDelta); diff --git a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl index 271d90fd9..645fd6d0c 100644 --- a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl +++ b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl @@ -8,127 +8,144 @@ struct KeyFrame float fTrackPosition; }; -struct BoneInfo +struct Channel { - int ParentIndex; + uint StartIndex; + uint KeyCount; + uint BoneIndex; }; -struct BoneMatrix +struct LocalPos { - row_major float4x4 LocalMatrix; - row_major float4x4 CombinedMatrix; + float3 Scale; + float pad0; + float4 Rotation; + + float3 Translation; + float pad1; }; -StructuredBuffer g_KeyFrameBufferInput : register(t0); -StructuredBuffer g_BoneInoBufferInput : register(t1); -RWStructuredBuffer gBoneMatrixOutput : register(u0); +StructuredBuffer g_KeyFrameBuffer : register(t0); +StructuredBuffer g_ChannelBuffer : register(t1); -cbuffer g_ConstantBuffer : register(b0) +RWStructuredBuffer g_LocalPosOutput : register(u0); + + +cbuffer AnimCB : register(b0) { float CurrentTime; float Duration; float Speed; int BoneCount; - float4x4 PreTransformMatrix; - + row_major float4x4 PreTransformMatrix; }; -float4x4 QuatToMatrix(float4 q) +float4 quatSlerp(float4 q1, float4 q2, float t) { - float x = q.x; - float y = q.y; - float z = q.z; - float w = q.w; + float cosTheta = dot(q1, q2); - float xx = x * x; - float yy = y * y; - float zz = z * z; + if (cosTheta < 0.0f) + { + q2 = -q2; + cosTheta = -cosTheta; + } - float xy = x * y; - float xz = x * z; - float yz = y * z; - float wx = w * x; - float wy = w * y; - float wz = w * z; + if (cosTheta > 0.9995f) + return normalize(lerp(q1, q2, t)); - float4x4 m; + float theta = acos(cosTheta); + float sinTheta = sin(theta); - m[0][0] = 1.0 - 2.0 * (yy + zz); - m[0][1] = 2.0 * (xy + wz); - m[0][2] = 2.0 * (xz - wy); - m[0][3] = 0.0; + float w1 = sin((1.0f - t) * theta) / sinTheta; + float w2 = sin(t * theta) / sinTheta; - m[1][0] = 2.0 * (xy - wz); - m[1][1] = 1.0 - 2.0 * (xx + zz); - m[1][2] = 2.0 * (yz + wx); - m[1][3] = 0.0; - - m[2][0] = 2.0 * (xz + wy); - m[2][1] = 2.0 * (yz - wx); - m[2][2] = 1.0 - 2.0 * (xx + yy); - m[2][3] = 0.0; - - m[3][0] = 0.0; - m[3][1] = 0.0; - m[3][2] = 0.0; - m[3][3] = 1.0; - - return m; + return q1 * w1 + q2 * w2; } -float4x4 MakeTRS(float3 scale, float4 rot, float3 trans) -{ - float4x4 S = - { - scale.x, 0, 0, 0, - 0, scale.y, 0, 0, - 0, 0, scale.z, 0, - 0, 0, 0, 1 - }; - - float4x4 R = QuatToMatrix(normalize(rot)); - - float4x4 T = - { - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - trans.x, trans.y, trans.z, 1 - }; - - return mul(S, mul(R, T)); -} [numthreads(256, 1, 1)] -void CS_MAIN(uint3 DispatchThreadID : SV_DispatchThreadID) +void CS_LocalSRT(uint3 DTID : SV_DispatchThreadID) { - uint boneIndex = DispatchThreadID.x; - if (boneIndex >= BoneCount) + uint boneIndex = DTID.x; + if (boneIndex >= (uint) BoneCount) return; - KeyFrame k = g_KeyFrameBufferInput[boneIndex]; - BoneInfo bi = g_BoneInoBufferInput[boneIndex]; + float time = CurrentTime; + if (Duration > 0) + time = min(time, Duration); - float3 s = k.vScale; - float4 r = k.vRotation; - float3 t = k.vTranslation; + Channel channel = g_ChannelBuffer[boneIndex]; - float4x4 local = MakeTRS(s, r, t); + LocalPos result; - float4x4 combined; - - if (bi.ParentIndex < 0) + if (channel.KeyCount == 0) { - combined = mul(local, PreTransformMatrix); - } - else - { - combined = mul(local, gBoneMatrixOutput[bi.ParentIndex].CombinedMatrix); + result.Scale = float3(1, 1, 1); + result.Rotation = float4(0, 0, 0, 1); + result.Translation = float3(0, 0, 0); + result.pad0 = result.pad1 = 0.0f; + + g_LocalPosOutput[boneIndex] = result; + return; } - gBoneMatrixOutput[boneIndex].LocalMatrix = local; - gBoneMatrixOutput[boneIndex].CombinedMatrix = combined; + uint firstIndex = channel.StartIndex; + uint lastIndex = channel.StartIndex + channel.KeyCount - 1; + + KeyFrame keyframe1 = g_KeyFrameBuffer[firstIndex]; + KeyFrame keyframe2 = g_KeyFrameBuffer[lastIndex]; + + if (time <= keyframe1.fTrackPosition) + { + result.Scale = keyframe1.vScale; + result.Rotation = keyframe1.vRotation; + result.Translation = keyframe1.vTranslation; + result.pad0 = result.pad1 = 0.0f; + + g_LocalPosOutput[boneIndex] = result; + return; + } + + if (time >= keyframe2.fTrackPosition) + { + result.Scale = keyframe2.vScale; + result.Rotation = keyframe2.vRotation; + result.Translation = keyframe2.vTranslation; + result.pad0 = result.pad1 = 0.0f; + + g_LocalPosOutput[boneIndex] = result; + return; + } + + for (uint i = 0; i < channel.KeyCount - 1; ++i) + { + uint A = channel.StartIndex + i; + uint B = channel.StartIndex + i + 1; + + KeyFrame ka = g_KeyFrameBuffer[A]; + KeyFrame kb = g_KeyFrameBuffer[B]; + + if (time >= ka.fTrackPosition && time <= kb.fTrackPosition) + { + float t = (time - ka.fTrackPosition) / (kb.fTrackPosition - ka.fTrackPosition); + + result.Scale = lerp(ka.vScale, kb.vScale, t); + result.Rotation = quatSlerp(ka.vRotation, kb.vRotation, t); + result.Translation = lerp(ka.vTranslation, kb.vTranslation, t); + result.pad0 = result.pad1 = 0.0f; + + g_LocalPosOutput[boneIndex] = result; + return; + } + } + + result.Scale = keyframe2.vScale; + result.Rotation = keyframe2.vRotation; + result.Translation = keyframe2.vTranslation; + result.pad0 = result.pad1 = 0.0f; + + g_LocalPosOutput[boneIndex] = result; } diff --git a/Jusin154_Team3D/Editor/Private/Broom.cpp b/Jusin154_Team3D/Editor/Private/Broom.cpp index d31202546..76e8578f3 100644 --- a/Jusin154_Team3D/Editor/Private/Broom.cpp +++ b/Jusin154_Team3D/Editor/Private/Broom.cpp @@ -66,9 +66,6 @@ HRESULT CBroom::Render() return E_FAIL; } - if (FAILED(m_pModelCom->Bind_CS_Output(5, i))) - return E_FAIL; - if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } diff --git a/Jusin154_Team3D/Editor/Private/DummyObject.cpp b/Jusin154_Team3D/Editor/Private/DummyObject.cpp index 006d8b704..72c59ab06 100644 --- a/Jusin154_Team3D/Editor/Private/DummyObject.cpp +++ b/Jusin154_Team3D/Editor/Private/DummyObject.cpp @@ -44,7 +44,7 @@ void CDummyObject::Priority_Update(_float fTimeDelta) void CDummyObject::Update(_float fTimeDelta) { - m_pModelCom->ComputeSkinning(); + m_pModelCom->ComputeAnimation(); m_pModelCom->Play_Animation(fTimeDelta,m_pTransformCom); @@ -77,9 +77,6 @@ HRESULT CDummyObject::Render() if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_ANIM::DEFAULT)))) { return E_FAIL; } - - if (FAILED(m_pModelCom->Bind_CS_Output(5, i))) - return E_FAIL; if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; diff --git a/Jusin154_Team3D/Editor/Private/Level_ObjectViewer.cpp b/Jusin154_Team3D/Editor/Private/Level_ObjectViewer.cpp index 42781e230..2d1795709 100644 --- a/Jusin154_Team3D/Editor/Private/Level_ObjectViewer.cpp +++ b/Jusin154_Team3D/Editor/Private/Level_ObjectViewer.cpp @@ -30,10 +30,10 @@ HRESULT CLevel_ObjectViewer::Initialize() return E_FAIL; } - /*if (FAILED(Ready_Layer_Camera(TEXT("Layer_Camera")))) + if (FAILED(Ready_Layer_Camera(TEXT("Layer_Camera")))) { return E_FAIL; - }*/ + } if (FAILED(Ready_Layer_Dummy(TEXT("Layer_Dummy")))) { @@ -58,7 +58,7 @@ void CLevel_ObjectViewer::Update(_float fTimeDelta) Find_Anim(); - m_Test->Describe_Entity(); + //m_Test->Describe_Entity(); } HRESULT CLevel_ObjectViewer::Render() @@ -702,8 +702,8 @@ HRESULT CLevel_ObjectViewer::Ready_Layer_Dummy(const _wstring& strLayerTag) - if (FAILED(m_pGameInstance->Add_GameObject_ToLayer(g_iStaticLevel, NEXT_LEVEL, strLayerTag))) - return E_FAIL; + //if (FAILED(m_pGameInstance->Add_GameObject_ToLayer(g_iStaticLevel, NEXT_LEVEL, strLayerTag))) + // return E_FAIL; /*if (FAILED(m_pGameInstance->Add_GameObject_ToLayer(g_iStaticLevel, NEXT_LEVEL, strLayerTag))) return E_FAIL;*/ diff --git a/Jusin154_Team3D/Editor/Private/Player.cpp b/Jusin154_Team3D/Editor/Private/Player.cpp index 844eede6f..e36298e70 100644 --- a/Jusin154_Team3D/Editor/Private/Player.cpp +++ b/Jusin154_Team3D/Editor/Private/Player.cpp @@ -70,7 +70,6 @@ void CPlayer::Priority_Update(_float fTimeDelta) void CPlayer::Update(_float fTimeDelta) { m_pModelCom->ComputeAnimation(); - Key_Input(fTimeDelta); m_pFSM->Update_State(fTimeDelta); diff --git a/Jusin154_Team3D/Editor/Private/RootModelPart.cpp b/Jusin154_Team3D/Editor/Private/RootModelPart.cpp index a9fda49f4..61acedece 100644 --- a/Jusin154_Team3D/Editor/Private/RootModelPart.cpp +++ b/Jusin154_Team3D/Editor/Private/RootModelPart.cpp @@ -71,6 +71,7 @@ void CRootModelPart::Update_Anim(_float fTimeDelta) { pModel->Set_PlayAnim(m_pMainModel->Get_PlayAnim()); pModel->Set_AnimSpeed(m_pMainModel->Get_AnimSpeed()); + pModel->ComputeAnimation(); pModel->Play_Animation(fTimeDelta,m_pTransformCom); } } @@ -98,7 +99,8 @@ void CRootModelPart::Change_Model(_uint iIndex) CModel* pModel = m_ModelParts[iIndex]->Get_Component(); pModel->Set_AnimationIndex(m_iAnimIndex); - pModel->Set_CurrentTrackPosition(m_fTrackPosition); + pModel->Set_CurrentTrackPosition(m_fTrackPosition); + pModel->ComputeAnimation(); pModel->Play_Animation(0.f, m_pTransformCom); if (iIndex == ENUM_CLASS(PARTSTYPE::BODY)) @@ -112,6 +114,7 @@ void CRootModelPart::Set_Animation(_uint iAnimIndex) { m_pMainModel->Set_AnimationIndex(iAnimIndex); m_pMainModel->Set_CurrentTrackPosition(0.f); + m_pMainModel->ComputeAnimation(); m_pMainModel->Play_Animation(0.f, m_pTransformCom); for (auto& PartObject : m_ModelParts) { @@ -120,6 +123,7 @@ void CRootModelPart::Set_Animation(_uint iAnimIndex) { pModel->Set_AnimationIndex(m_pMainModel->Get_AnimIndex()); pModel->Set_CurrentTrackPosition(m_pMainModel->Get_CurrentTrackPosition()); + pModel->ComputeAnimation(); pModel->Play_Animation(0.f, m_pTransformCom); } } diff --git a/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl b/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl index 271d90fd9..645fd6d0c 100644 --- a/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl +++ b/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl @@ -8,127 +8,144 @@ struct KeyFrame float fTrackPosition; }; -struct BoneInfo +struct Channel { - int ParentIndex; + uint StartIndex; + uint KeyCount; + uint BoneIndex; }; -struct BoneMatrix +struct LocalPos { - row_major float4x4 LocalMatrix; - row_major float4x4 CombinedMatrix; + float3 Scale; + float pad0; + float4 Rotation; + + float3 Translation; + float pad1; }; -StructuredBuffer g_KeyFrameBufferInput : register(t0); -StructuredBuffer g_BoneInoBufferInput : register(t1); -RWStructuredBuffer gBoneMatrixOutput : register(u0); +StructuredBuffer g_KeyFrameBuffer : register(t0); +StructuredBuffer g_ChannelBuffer : register(t1); -cbuffer g_ConstantBuffer : register(b0) +RWStructuredBuffer g_LocalPosOutput : register(u0); + + +cbuffer AnimCB : register(b0) { float CurrentTime; float Duration; float Speed; int BoneCount; - float4x4 PreTransformMatrix; - + row_major float4x4 PreTransformMatrix; }; -float4x4 QuatToMatrix(float4 q) +float4 quatSlerp(float4 q1, float4 q2, float t) { - float x = q.x; - float y = q.y; - float z = q.z; - float w = q.w; + float cosTheta = dot(q1, q2); - float xx = x * x; - float yy = y * y; - float zz = z * z; + if (cosTheta < 0.0f) + { + q2 = -q2; + cosTheta = -cosTheta; + } - float xy = x * y; - float xz = x * z; - float yz = y * z; - float wx = w * x; - float wy = w * y; - float wz = w * z; + if (cosTheta > 0.9995f) + return normalize(lerp(q1, q2, t)); - float4x4 m; + float theta = acos(cosTheta); + float sinTheta = sin(theta); - m[0][0] = 1.0 - 2.0 * (yy + zz); - m[0][1] = 2.0 * (xy + wz); - m[0][2] = 2.0 * (xz - wy); - m[0][3] = 0.0; + float w1 = sin((1.0f - t) * theta) / sinTheta; + float w2 = sin(t * theta) / sinTheta; - m[1][0] = 2.0 * (xy - wz); - m[1][1] = 1.0 - 2.0 * (xx + zz); - m[1][2] = 2.0 * (yz + wx); - m[1][3] = 0.0; - - m[2][0] = 2.0 * (xz + wy); - m[2][1] = 2.0 * (yz - wx); - m[2][2] = 1.0 - 2.0 * (xx + yy); - m[2][3] = 0.0; - - m[3][0] = 0.0; - m[3][1] = 0.0; - m[3][2] = 0.0; - m[3][3] = 1.0; - - return m; + return q1 * w1 + q2 * w2; } -float4x4 MakeTRS(float3 scale, float4 rot, float3 trans) -{ - float4x4 S = - { - scale.x, 0, 0, 0, - 0, scale.y, 0, 0, - 0, 0, scale.z, 0, - 0, 0, 0, 1 - }; - - float4x4 R = QuatToMatrix(normalize(rot)); - - float4x4 T = - { - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - trans.x, trans.y, trans.z, 1 - }; - - return mul(S, mul(R, T)); -} [numthreads(256, 1, 1)] -void CS_MAIN(uint3 DispatchThreadID : SV_DispatchThreadID) +void CS_LocalSRT(uint3 DTID : SV_DispatchThreadID) { - uint boneIndex = DispatchThreadID.x; - if (boneIndex >= BoneCount) + uint boneIndex = DTID.x; + if (boneIndex >= (uint) BoneCount) return; - KeyFrame k = g_KeyFrameBufferInput[boneIndex]; - BoneInfo bi = g_BoneInoBufferInput[boneIndex]; + float time = CurrentTime; + if (Duration > 0) + time = min(time, Duration); - float3 s = k.vScale; - float4 r = k.vRotation; - float3 t = k.vTranslation; + Channel channel = g_ChannelBuffer[boneIndex]; - float4x4 local = MakeTRS(s, r, t); + LocalPos result; - float4x4 combined; - - if (bi.ParentIndex < 0) + if (channel.KeyCount == 0) { - combined = mul(local, PreTransformMatrix); - } - else - { - combined = mul(local, gBoneMatrixOutput[bi.ParentIndex].CombinedMatrix); + result.Scale = float3(1, 1, 1); + result.Rotation = float4(0, 0, 0, 1); + result.Translation = float3(0, 0, 0); + result.pad0 = result.pad1 = 0.0f; + + g_LocalPosOutput[boneIndex] = result; + return; } - gBoneMatrixOutput[boneIndex].LocalMatrix = local; - gBoneMatrixOutput[boneIndex].CombinedMatrix = combined; + uint firstIndex = channel.StartIndex; + uint lastIndex = channel.StartIndex + channel.KeyCount - 1; + + KeyFrame keyframe1 = g_KeyFrameBuffer[firstIndex]; + KeyFrame keyframe2 = g_KeyFrameBuffer[lastIndex]; + + if (time <= keyframe1.fTrackPosition) + { + result.Scale = keyframe1.vScale; + result.Rotation = keyframe1.vRotation; + result.Translation = keyframe1.vTranslation; + result.pad0 = result.pad1 = 0.0f; + + g_LocalPosOutput[boneIndex] = result; + return; + } + + if (time >= keyframe2.fTrackPosition) + { + result.Scale = keyframe2.vScale; + result.Rotation = keyframe2.vRotation; + result.Translation = keyframe2.vTranslation; + result.pad0 = result.pad1 = 0.0f; + + g_LocalPosOutput[boneIndex] = result; + return; + } + + for (uint i = 0; i < channel.KeyCount - 1; ++i) + { + uint A = channel.StartIndex + i; + uint B = channel.StartIndex + i + 1; + + KeyFrame ka = g_KeyFrameBuffer[A]; + KeyFrame kb = g_KeyFrameBuffer[B]; + + if (time >= ka.fTrackPosition && time <= kb.fTrackPosition) + { + float t = (time - ka.fTrackPosition) / (kb.fTrackPosition - ka.fTrackPosition); + + result.Scale = lerp(ka.vScale, kb.vScale, t); + result.Rotation = quatSlerp(ka.vRotation, kb.vRotation, t); + result.Translation = lerp(ka.vTranslation, kb.vTranslation, t); + result.pad0 = result.pad1 = 0.0f; + + g_LocalPosOutput[boneIndex] = result; + return; + } + } + + result.Scale = keyframe2.vScale; + result.Rotation = keyframe2.vRotation; + result.Translation = keyframe2.vTranslation; + result.pad0 = result.pad1 = 0.0f; + + g_LocalPosOutput[boneIndex] = result; } diff --git a/Jusin154_Team3D/Engine/Private/Animation.cpp b/Jusin154_Team3D/Engine/Private/Animation.cpp index 4d7d644fe..27c4cac77 100644 --- a/Jusin154_Team3D/Engine/Private/Animation.cpp +++ b/Jusin154_Team3D/Engine/Private/Animation.cpp @@ -23,6 +23,7 @@ CAnimation::CAnimation(const CAnimation& rhs) , m_fTickPerSecond{ rhs.m_fTickPerSecond } , m_pSaveAnim{ rhs.m_pSaveAnim } , m_fAnimSpeed{rhs.m_fAnimSpeed } + ,m_iBoneCount{rhs.m_iBoneCount} { memcpy_s(m_TickPerSeconds, sizeof(_float) * 2, rhs.m_TickPerSeconds, sizeof(_float) * 2); @@ -32,7 +33,7 @@ CAnimation::CAnimation(const CAnimation& rhs) SAFE_ADDREF(pChannel); } } -_bool CAnimation::Update_TransformationMatrices(const vector& Bones, _bool bIsLoop, _float fTimeDelta,CTransform*pTransform) +_bool CAnimation::Update_TransformationMatrices(const vector& Bones, const LOCALPOS_DESC* pLocalPosArray, _bool bIsLoop, _float fTimeDelta,CTransform*pTransform) { //m_fCurrentTrackPosition += m_TickPerSeconds[m_bPause] * fTimeDelta; m_fCurrentTrackPosition += m_fTickPerSecond * fTimeDelta * m_fAnimSpeed; @@ -52,7 +53,7 @@ _bool CAnimation::Update_TransformationMatrices(const vector& Bone if (m_vBoneTransformationMatrix.size() > 0) m_vBoneTransformationMatrix.clear(); for (auto& pChannel : m_Channels) { - pChannel->Update_TransformationMatirx(Bones, m_fCurrentTrackPosition, &m_CurrentKeyFrameIndices[iIndex++],pTransform); + pChannel->Update_TransformationMatirx(Bones, pLocalPosArray, m_fCurrentTrackPosition, &m_CurrentKeyFrameIndices[iIndex++],pTransform); m_vBoneTransformationMatrix.push_back(pChannel->Get_BoneTransformationMatrix()); } @@ -184,26 +185,35 @@ void CAnimation::InterpAnim(CAnimation* pPreAnim, vector& Bones, float f } } +void CAnimation::CreateGPUData(ID3D11Device* pDevice) +{ + vector channels; + vector keyframes; + + channels.resize(m_iBoneCount); + + for (auto& pChannel : m_Channels) + { + CHANNEL_DESC desc = pChannel->Fill_GPU_ChannelDesc(); + desc.StartIndex = (_uint)keyframes.size(); + + pChannel->Fill_GPU_Keyframes(keyframes); + + channels[desc.BoneIndex] = desc; + } + + m_iChannelCount = (_uint)channels.size(); + m_iKeyframeCount = (_uint)keyframes.size(); + + CreateKeyFrameBuffer(pDevice, keyframes); + CreateChannelBuffer(pDevice, channels); + +} + #ifdef EDITOR_PROJECT -void CAnimation::Set_KeyFrameDesc() -{ - for (auto& Channel : m_Channels) - { - m_KeyFrame.push_back(Channel->Get_KeyFrameDesc()); - } -} -_uint CAnimation::Get_KeyFrameCount() -{ - for (auto& Channel : m_Channels) - { - m_KeyCount+=Channel->Get_KeyFrameCount(); - } - - return m_KeyCount; -} HRESULT CAnimation::Initialize(const vector& Bones, const aiAnimation* pAIAnimation) { @@ -294,7 +304,7 @@ HRESULT CAnimation::Initialize(HANDLE hFile, DWORD& dwByte) return S_OK; } -HRESULT CAnimation::Initialize(const CModel* pModel, SaveAnimation* pSaveAnimation) +HRESULT CAnimation::Initialize(const vector& Bones, const CModel* pModel, SaveAnimation* pSaveAnimation) { m_pSaveAnim = pSaveAnimation; @@ -306,6 +316,8 @@ HRESULT CAnimation::Initialize(const CModel* pModel, SaveAnimation* pSaveAnimati m_CurrentKeyFrameIndices.resize(m_iNumChannels); + m_iBoneCount = (_uint)Bones.size(); + for (size_t i = 0; i < m_iNumChannels; i++) { CChannel* pChannel = CChannel::Create(pModel, &pSaveAnimation->Channels[i]); @@ -333,6 +345,64 @@ _uint CAnimation::Get_BoneIndex(const char* pChannelName) return _uint(); } +HRESULT CAnimation::CreateKeyFrameBuffer(ID3D11Device* pDevice,vector keyframe) +{ + D3D11_BUFFER_DESC desc{}; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.ByteWidth = (_int)sizeof(KEYFRAME_DESC) * m_iKeyframeCount; + desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + desc.CPUAccessFlags = 0; + desc.StructureByteStride = (_int)sizeof(KEYFRAME_DESC); + desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; + + D3D11_SUBRESOURCE_DATA init{}; + init.pSysMem = keyframe.data(); + + pDevice->CreateBuffer(&desc, &init, &m_pKeyFrameBuffer); + + + + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX; + srvDesc.Format = DXGI_FORMAT_UNKNOWN; + srvDesc.Buffer.FirstElement = 0; + srvDesc.Buffer.NumElements = m_iKeyframeCount; + + if (FAILED(pDevice->CreateShaderResourceView(m_pKeyFrameBuffer, &srvDesc, &m_pKeyFrameSrv))) + return E_FAIL; + + + return S_OK; +} + +HRESULT CAnimation::CreateChannelBuffer(ID3D11Device* pDevice, vector channel) +{ + D3D11_BUFFER_DESC desc{}; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.ByteWidth = (_int)sizeof(CHANNEL_DESC) * m_iChannelCount; + desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + desc.CPUAccessFlags = 0; + desc.StructureByteStride = (_int)sizeof(CHANNEL_DESC); + desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; + + D3D11_SUBRESOURCE_DATA init{}; + init.pSysMem = channel.data(); + + pDevice->CreateBuffer(&desc, &init, &m_pChannelBuffer); + + + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX; + srvDesc.Format = DXGI_FORMAT_UNKNOWN; + srvDesc.Buffer.FirstElement = 0; + srvDesc.Buffer.NumElements = m_iChannelCount; + + if (FAILED(pDevice->CreateShaderResourceView(m_pChannelBuffer, &srvDesc, &m_pChannelSrv))) + return E_FAIL; + + return S_OK; +} + CAnimation* CAnimation::Create(HANDLE hFile, DWORD& dwByte) { CAnimation* pInstance = new CAnimation(); @@ -346,11 +416,11 @@ CAnimation* CAnimation::Create(HANDLE hFile, DWORD& dwByte) return pInstance; } -CAnimation* CAnimation::Create(const CModel* pModel, SaveAnimation* pSaveAnimation) +CAnimation* CAnimation::Create(const vector& Bones, const CModel* pModel, SaveAnimation* pSaveAnimation) { CAnimation* pInstance = new CAnimation(); - if (FAILED(pInstance->Initialize(pModel, pSaveAnimation))) + if (FAILED(pInstance->Initialize(Bones,pModel, pSaveAnimation))) { MSG_BOX("Failed to Created : CAnimation"); SAFE_RELEASE(pInstance); @@ -374,6 +444,18 @@ void CAnimation::Free() m_Channels.clear(); m_CurrentKeyFrameIndices.clear(); + + m_KeyFrameDesc.clear(); + m_ChannelDesc.clear(); + + if (m_pKeyFrameSrv&& m_pChannelSrv) + { + SAFE_RELEASE(m_pKeyFrameBuffer); + SAFE_RELEASE(m_pChannelBuffer); + SAFE_RELEASE(m_pKeyFrameSrv); + SAFE_RELEASE(m_pChannelSrv); + } + } ; void CAnimation::Describe_Entity() diff --git a/Jusin154_Team3D/Engine/Private/Channel.cpp b/Jusin154_Team3D/Engine/Private/Channel.cpp index 92c014004..4b3a29790 100644 --- a/Jusin154_Team3D/Engine/Private/Channel.cpp +++ b/Jusin154_Team3D/Engine/Private/Channel.cpp @@ -54,18 +54,40 @@ HRESULT CChannel::Initialize(const vector& Bones, const aiNodeAnim* pAIC KeyFrame.vRotation = vRotation; KeyFrame.vTranslation = vTranslation; - - m_KeyFrame.fTrackPosition = KeyFrame.fTrackPosition; - m_KeyFrame.vScale = vScale; - m_KeyFrame.vRotation = vRotation; - m_KeyFrame.vTranslation = vTranslation; - m_KeyFrames.push_back(KeyFrame); } return S_OK; } +void CChannel::Fill_GPU_Keyframes(vector& outKeyframes) +{ + for (_uint i = 0; i < m_iNumKeyFrames; i++) + { + const KEYFRAME& src = m_KeyFrames[i]; + + KEYFRAME_DESC dst{}; + dst.vScale = src.vScale; + dst.vRotation = src.vRotation; + dst.vTranslation = src.vTranslation; + dst.fTrackPosition = src.fTrackPosition; + + outKeyframes.push_back(dst); + } +} + +CHANNEL_DESC CChannel::Fill_GPU_ChannelDesc() +{ + CHANNEL_DESC desc{}; + desc.StartIndex = 0; + desc.KeyCount = m_iNumKeyFrames; + desc.BoneIndex = m_iBoneIndex; + + return desc; +} + + + HRESULT CChannel::SaveAsBinary(HANDLE hFile, DWORD& dwByte) { string strName = m_szName; @@ -106,84 +128,104 @@ HRESULT CChannel::Initialize(const vector& Bones, _uint iIndex) } -void CChannel::Update_TransformationMatirx(const vector& Bones, _float fCurrentTrackPosition, _uint* pCurrentKeyFrameIndex, CTransform* pTransform) - +void CChannel::Update_TransformationMatirx(const vector& Bones, const LOCALPOS_DESC* pLocalPosArray, _float fCurrentTrackPosition, _uint* pCurrentKeyFrameIndex, CTransform* pTransform) { - if (0.f == fCurrentTrackPosition) { - *pCurrentKeyFrameIndex = 0; - } - KEYFRAME LastKeyFrame = m_KeyFrames.back(); - - _vector vScale = {}; - _vector vRotation = {}; - _vector vTranslation = {}; - - if (fCurrentTrackPosition >= LastKeyFrame.fTrackPosition) - { - vScale = XMLoadFloat3(&LastKeyFrame.vScale); - vRotation = XMLoadFloat4(&LastKeyFrame.vRotation); - vTranslation = XMVectorSetW(XMLoadFloat3(&LastKeyFrame.vTranslation), 1.f); - } - else { - while (fCurrentTrackPosition >= m_KeyFrames[*pCurrentKeyFrameIndex + 1].fTrackPosition) { - ++*pCurrentKeyFrameIndex; - } - - _float3 vSrcScale = {}, vDstScale = {}; - _float4 vSrcRotation = {}, vDstRotation = {}; - _float3 vSrcTranslation = {}, vDstTranslation = {}; - - vSrcScale = m_KeyFrames[*pCurrentKeyFrameIndex].vScale; - vDstScale = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vScale; - - vSrcRotation = m_KeyFrames[*pCurrentKeyFrameIndex].vRotation; - vDstRotation = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vRotation; - - vSrcTranslation = m_KeyFrames[*pCurrentKeyFrameIndex].vTranslation; - vDstTranslation = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vTranslation; - - _float fRatio = (fCurrentTrackPosition - m_KeyFrames[*pCurrentKeyFrameIndex].fTrackPosition) / - (m_KeyFrames[*pCurrentKeyFrameIndex + 1].fTrackPosition - m_KeyFrames[*pCurrentKeyFrameIndex].fTrackPosition); - - vScale = XMVectorLerp(XMLoadFloat3(&vSrcScale), XMLoadFloat3(&vDstScale), fRatio); - vRotation = XMQuaternionSlerp(XMLoadFloat4(&vSrcRotation), XMLoadFloat4(&vDstRotation), fRatio); - vTranslation = XMVectorSetW(XMVectorLerp(XMLoadFloat3(&vSrcTranslation), XMLoadFloat3(&vDstTranslation), fRatio), 1.f); - } + //if (0.f == fCurrentTrackPosition) { + // *pCurrentKeyFrameIndex = 0; + //} + //KEYFRAME LastKeyFrame = m_KeyFrames.back(); + + //_vector vScale = {}; + //_vector vRotation = {}; + //_vector vTranslation = {}; + + //if (fCurrentTrackPosition >= LastKeyFrame.fTrackPosition) + //{ + // vScale = XMLoadFloat3(&LastKeyFrame.vScale); + // vRotation = XMLoadFloat4(&LastKeyFrame.vRotation); + // vTranslation = XMVectorSetW(XMLoadFloat3(&LastKeyFrame.vTranslation), 1.f); + //} + //else { + // while (fCurrentTrackPosition >= m_KeyFrames[*pCurrentKeyFrameIndex + 1].fTrackPosition) { + // ++*pCurrentKeyFrameIndex; + // } + + // _float3 vSrcScale = {}, vDstScale = {}; + // _float4 vSrcRotation = {}, vDstRotation = {}; + // _float3 vSrcTranslation = {}, vDstTranslation = {}; + + // vSrcScale = m_KeyFrames[*pCurrentKeyFrameIndex].vScale; + // vDstScale = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vScale; + + // vSrcRotation = m_KeyFrames[*pCurrentKeyFrameIndex].vRotation; + // vDstRotation = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vRotation; + + // vSrcTranslation = m_KeyFrames[*pCurrentKeyFrameIndex].vTranslation; + // vDstTranslation = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vTranslation; + + // _float fRatio = (fCurrentTrackPosition - m_KeyFrames[*pCurrentKeyFrameIndex].fTrackPosition) / + // (m_KeyFrames[*pCurrentKeyFrameIndex + 1].fTrackPosition - m_KeyFrames[*pCurrentKeyFrameIndex].fTrackPosition); + + // vScale = XMVectorLerp(XMLoadFloat3(&vSrcScale), XMLoadFloat3(&vDstScale), fRatio); + // vRotation = XMQuaternionSlerp(XMLoadFloat4(&vSrcRotation), XMLoadFloat4(&vDstRotation), fRatio); + // vTranslation = XMVectorSetW(XMVectorLerp(XMLoadFloat3(&vSrcTranslation), XMLoadFloat3(&vDstTranslation), fRatio), 1.f); + //} + + + + const LOCALPOS_DESC& LocalPos = pLocalPosArray[m_iBoneIndex]; + + _vector vScale = XMLoadFloat3(&LocalPos.Scale); + _vector vRotation = XMLoadFloat4(&LocalPos.Rotation); + _vector vTranslation = XMVectorSet( + LocalPos.Translation.x, + LocalPos.Translation.y, + LocalPos.Translation.z, + 1.f); + if (Bones[m_iBoneIndex]->Compare_Name("Reference") && pTransform != nullptr) { _float3 vCurRootPos; XMStoreFloat3(&vCurRootPos, vTranslation); - _vector vDeltaLocal = XMLoadFloat3(&vCurRootPos) - XMLoadFloat3(&m_vPrevRootPos); - - _vector vDeltaAdjusted = {}; - XMMATRIX pre = XMLoadFloat4x4(&m_PreTransformMatrix); - vDeltaAdjusted = XMVector3TransformNormal(vDeltaLocal, pre); + + if (!m_bInitialRootPos) + { + m_bInitialRootPos = true; + vTranslation = XMVectorZero(); + } + else + { + _vector vDeltaLocal = XMLoadFloat3(&vCurRootPos) - XMLoadFloat3(&m_vPrevRootPos); - _vector vRight = pTransform->Get_State(STATE::RIGHT); - _vector vUp = pTransform->Get_State(STATE::UP); - _vector vLook = pTransform->Get_State(STATE::LOOK); + _vector vDeltaAdjusted = {}; - _float dx = XMVectorGetX(vDeltaAdjusted); - _float dy = XMVectorGetY(vDeltaAdjusted); - _float dz = XMVectorGetZ(vDeltaAdjusted); + vDeltaAdjusted = XMVector3TransformNormal(vDeltaLocal, pre); - _vector vDeltaWorld = vRight * dx + (-vUp * dz) + vLook * dy; + _vector vRight = pTransform->Get_State(STATE::RIGHT); + _vector vUp = pTransform->Get_State(STATE::UP); + _vector vLook = pTransform->Get_State(STATE::LOOK); - vDeltaWorld *= 0.01f; + _float dx = XMVectorGetX(vDeltaAdjusted); + _float dy = XMVectorGetY(vDeltaAdjusted); + _float dz = XMVectorGetZ(vDeltaAdjusted); - _vector vCurrentPos = pTransform->Get_State(STATE::POSITION); - _vector vTargetPos = vCurrentPos + vDeltaWorld; + _vector vDeltaWorld = vRight * dx + (-vUp * dz) + vLook * dy; - //pTransform->Set_State(STATE::POSITION, vTargetPos); - pTransform->AccumulateMomentum(vDeltaWorld); + vDeltaWorld *= 0.01f; - m_vPrevRootPos = vCurRootPos; - vTranslation = XMVectorZero(); + _vector vCurrentPos = pTransform->Get_State(STATE::POSITION); + _vector vTargetPos = vCurrentPos + vDeltaWorld; - ///////////////////////////////////// + pTransform->Set_State(STATE::POSITION, vTargetPos); + //pTransform->AccumulateMomentum(vDeltaWorld); + + m_vPrevRootPos = vCurRootPos; + vTranslation = XMVectorZero(); + } + /////////////////////////////////// _float4 curRotF4; XMStoreFloat4(&curRotF4, vRotation); @@ -307,10 +349,6 @@ HRESULT CChannel::Initialize(const CModel* pModel, SaveChannel* pSaveChannel) KeyFrame.vRotation = vRotation; KeyFrame.vTranslation = vTranslation; - m_KeyFrame.fTrackPosition = KeyFrame.fTrackPosition; - m_KeyFrame.vScale = vScale; - m_KeyFrame.vRotation = vRotation; - m_KeyFrame.vTranslation = vTranslation; m_KeyFrames.push_back(KeyFrame); } @@ -362,4 +400,6 @@ void CChannel::Free() __super::Free(); m_KeyFrames.clear(); + + m_KeyFrameDesc.clear(); } diff --git a/Jusin154_Team3D/Engine/Private/ComputeShader.cpp b/Jusin154_Team3D/Engine/Private/ComputeShader.cpp index 7d46182a5..eebd01e99 100644 --- a/Jusin154_Team3D/Engine/Private/ComputeShader.cpp +++ b/Jusin154_Team3D/Engine/Private/ComputeShader.cpp @@ -83,9 +83,6 @@ vector CComputeShader::Dispatch(_uint iSRVIndex, _uint if (SUCCEEDED(m_pContext->Map(m_pOutputStagingBuffer[i], 0, D3D11_MAP_READ, 0, &StagingSubResource))) { - - CInstance_Model::CS_PARTICLE_VALUE_DESC* pValueDesc = static_cast(StagingSubResource.pData); - StagingSubResources.push_back(StagingSubResource); m_pContext->Unmap(m_pOutputStagingBuffer[i], 0); @@ -124,6 +121,37 @@ void CComputeShader::Bind_OutPut_SRV(_uint iIndex, _uint iBufferIndex) } +ID3D11UnorderedAccessView* CComputeShader::GetOutputUAV(_uint iIndex) const +{ + return m_pOutputUAV[iIndex]; +} + +vector CComputeShader::ReadBackOutputs() +{ + std::vector StagingSubResources; + StagingSubResources.reserve(m_iNumOutputBuffer); + + for (_uint i = 0; i < m_iNumOutputBuffer; ++i) + { + if (m_pOutputStagingBuffer[i] == nullptr || m_pOutputBuffer[i] == nullptr) + continue; + + m_pContext->CopyResource(m_pOutputStagingBuffer[i], m_pOutputBuffer[i]); + + D3D11_MAPPED_SUBRESOURCE mapped = {}; + if (SUCCEEDED(m_pContext->Map(m_pOutputStagingBuffer[i], 0, + D3D11_MAP_READ, 0, &mapped))) + { + StagingSubResources.push_back(mapped); + + m_pContext->Unmap(m_pOutputStagingBuffer[i], 0); + } + } + + return StagingSubResources; + +} + void CComputeShader::Reset() { //다ì�Œ ëžœë�”ë§� 패스ì—� ì—°ê´€ë�˜ì§€ 않ë�„ë¡� 초기화 diff --git a/Jusin154_Team3D/Engine/Private/GameInstance.cpp b/Jusin154_Team3D/Engine/Private/GameInstance.cpp index 52fc982e6..e2387d636 100644 --- a/Jusin154_Team3D/Engine/Private/GameInstance.cpp +++ b/Jusin154_Team3D/Engine/Private/GameInstance.cpp @@ -126,11 +126,13 @@ void CGameInstance::Update_Engine(_float fTimeDelta) m_pObject_Manager->Update(fTimeDelta); + m_pPhysX_Manager->Update(fTimeDelta); + m_pObject_Manager->Late_Update(fTimeDelta); m_pLevel_Manager->Update(fTimeDelta); m_pObject_Manager->Clear_DeadObj(); - m_pPhysX_Manager->Update(fTimeDelta); + //m_pObstacle_Manager->Refresh_Region(); } diff --git a/Jusin154_Team3D/Engine/Private/LerpAnim.cpp b/Jusin154_Team3D/Engine/Private/LerpAnim.cpp index e4b4aa8c3..ed36a6c1d 100644 --- a/Jusin154_Team3D/Engine/Private/LerpAnim.cpp +++ b/Jusin154_Team3D/Engine/Private/LerpAnim.cpp @@ -1,4 +1,4 @@ -#include "pch.h" +#include "pch.h" #include "LerpAnim.h" #include "Channel.h" #include "Bone.h" @@ -17,13 +17,13 @@ _bool CLerpAnim::Update_TransformationMatrices(const vector& Bones, _flo return false; } - _uint iIndex = {}; + /*_uint iIndex = {}; for (auto& pChannel : m_Channels) { if (true == m_Movable[iIndex]) { pChannel->Update_TransformationMatirx(Bones, m_fCurrentTrackPosition, &m_CurrentKeyFrameIndices[iIndex]); } iIndex++; - } + }*/ return true; } @@ -50,9 +50,9 @@ HRESULT CLerpAnim::Initialize(_uint iNumBone, _float fTickPerSecond, const vecto } void CLerpAnim::Begin(const vector& Bones, vector& StartFrames, vector& EndFrames, _float fDuration, _uint iRootBoneIndex) { - { // ÃʱâÈ­ + { // 초기화 - //KEYFRAME kf = { // Ç×µîÇà·ÄÀÇ Å°ÇÁ·¹ÀÓ + //KEYFRAME kf = { // 항등행렬ì�˜ 키프레임 // { 1.f, 1.f, 1.f }, // { 0.f, 0.f, 0.f, 1.f }, // { 0.f, 0.f, 0.f}, @@ -61,19 +61,19 @@ void CLerpAnim::Begin(const vector& Bones, vector& Start m_fDuration = fDuration; m_fCurrentTrackPosition = 0.f; for (_uint i = 0; i < m_iNumChannels; ++i) { - m_Channels[i]->Set_Frame(1, m_InitialFrames[i]); // ³¡ÇÁ·¹ÀÓÀ» Ãʱ⠰ªÀ¸·Î ä¿ì±â + m_Channels[i]->Set_Frame(1, m_InitialFrames[i]); // ë��프레임ì�„ 초기 값으로 채우기 } fill(m_CurrentKeyFrameIndices.begin(), m_CurrentKeyFrameIndices.end(), 0); fill(m_Movable.begin(), m_Movable.end(), false); } - { // ½ÇÁ¦ °ª ä¿ì±â - for (LERPDESC& Desc : EndFrames) // ³¡ÇÁ·¹ÀÓÀ» ½ÇÁ¦ °ªÀ¸·Î ä¿ì±â + { // 실제 ê°’ 채우기 + for (LERPDESC& Desc : EndFrames) // ë��프레임ì�„ 실제 값으로 채우기 { _int iIndex = Desc.iSlot; Desc.tagKeyFrame.fTrackPosition = m_fDuration; m_Channels[iIndex]->Set_Frame(1, Desc.tagKeyFrame); } - for (_uint i = 0; i < StartFrames.size(); ++i) { // ½ÃÀÛ ÇÁ·¹ÀÓÀ» ÇöÀç º» »óÅ ŰÇÁ·¹ÀÓÀ¸·Î ä¿ì±â + for (_uint i = 0; i < StartFrames.size(); ++i) { // 시작 프레임ì�„ 현재 본 ìƒ�태 키프레임으로 채우기 _int iIndex = StartFrames[i].iSlot; m_Movable[iIndex] = true; m_Channels[iIndex]->Set_Frame(0, StartFrames[i].tagKeyFrame); @@ -101,4 +101,4 @@ void CLerpAnim::Free() m_CurrentKeyFrameIndices.clear(); } -; \ No newline at end of file +; diff --git a/Jusin154_Team3D/Engine/Private/Model.cpp b/Jusin154_Team3D/Engine/Private/Model.cpp index a24db4184..5ae671060 100644 --- a/Jusin154_Team3D/Engine/Private/Model.cpp +++ b/Jusin154_Team3D/Engine/Private/Model.cpp @@ -160,7 +160,7 @@ _bool CModel::Play_Animation(_float fTimeDelta,CTransform* pTransform) _float fRatio = m_fBlendTime / m_fBlendDuration; fRatio = min(fRatio, 1.f); - m_bIsFinishedAnim = m_Animations[m_iCurrentAnimIndex]->Update_TransformationMatrices(m_Bones, m_bIsLoop, fTimeDelta, pTransform); + m_bIsFinishedAnim = m_Animations[m_iCurrentAnimIndex]->Update_TransformationMatrices(m_Bones, m_pLocalPos, m_bIsLoop, fTimeDelta, pTransform); m_Animations[m_iCurrentAnimIndex]->InterpAnim(m_Animations[m_iPreAnimIndex], m_Bones, fRatio); if (fRatio >= 1.f) @@ -171,7 +171,7 @@ _bool CModel::Play_Animation(_float fTimeDelta,CTransform* pTransform) } else { - m_bIsFinishedAnim = m_Animations[m_iCurrentAnimIndex]->Update_TransformationMatrices(m_Bones, m_bIsLoop, fTimeDelta, pTransform); + m_bIsFinishedAnim = m_Animations[m_iCurrentAnimIndex]->Update_TransformationMatrices(m_Bones, m_pLocalPos, m_bIsLoop, fTimeDelta, pTransform); m_iPreAnimIndex = m_iCurrentAnimIndex; } @@ -180,8 +180,11 @@ _bool CModel::Play_Animation(_float fTimeDelta,CTransform* pTransform) pBone->Update_CombinedTransformationMatrix(m_Bones, XMLoadFloat4x4(&m_PreTransformMatrix)); } - if(m_bIsFinishedAnim) + if (m_bIsFinishedAnim) + { m_Animations[m_iCurrentAnimIndex]->ResetRootMotion(); + m_Animations[m_iCurrentAnimIndex]->Depart_Animation(); + } return m_bIsFinishedAnim; } @@ -881,25 +884,53 @@ HRESULT CModel::Assimp_Model_Load(const _char* pModelFilePath, MODEL eType, _fma HRESULT CModel::Create_CS() { - _uint CS_InputStrides[] = { - sizeof(KEYFRAME_DESC), - sizeof(BONEINFO_DESC) + _uint CS1_InputStrides[] = { + sizeof(KEYFRAME_DESC), + sizeof(CHANNEL_DESC), + }; + + _uint CS1_OutputStrides[] = { + sizeof(LOCALPOS_DESC), }; - _uint CS_OutputStrides[] = { - sizeof(BONE_DESC) - }; + m_pComputeShader = CComputeShader::Create(m_pDevice, m_pContext, L"../Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl", + "CS_LocalSRT", (_uint)m_Bones.size(), 0, 1, nullptr, CS1_OutputStrides + ); - m_pComputeShader = CComputeShader::Create(m_pDevice, m_pContext, - L"../Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl", "CS_MAIN",(_uint)m_Bones.size(), 2, 1, CS_InputStrides, CS_OutputStrides); - - if (m_pComputeShader == nullptr) + if (!m_pComputeShader) return E_FAIL; return S_OK; } +void CModel::Create_Temp() +{ + for (auto& anim : m_Animations) + { + anim->CreateGPUData(m_pDevice); + } +} + +void CModel::Create_LocalPosVB() +{ + _uint iCount = (_uint)m_Bones.size(); + _uint iStride = sizeof(LOCALPOS_DESC); + + D3D11_BUFFER_DESC desc = {}; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.ByteWidth = iStride * iCount; + desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS; + desc.CPUAccessFlags = 0; + desc.StructureByteStride = iStride; + desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; + + HRESULT hr = m_pDevice->CreateBuffer(&desc, nullptr, &m_pLocalPosBuffer); + + return; +} + + void CModel::Create_Con() { D3D11_BUFFER_DESC cbDesc = {}; @@ -913,17 +944,6 @@ void CModel::Create_Con() } - -HRESULT CModel::Bind_CS_Output(_uint Index, _uint iBufferIndex) -{ - if (m_pComputeShader == nullptr) - return E_FAIL; - - m_pComputeShader->Bind_OutPut_SRV(Index, iBufferIndex); - - return S_OK; -} - void CModel::UpdateAnimationCS() { D3D11_MAPPED_SUBRESOURCE sub{}; @@ -937,7 +957,6 @@ void CModel::UpdateAnimationCS() pDesc->Speed = pAnim->Get_AnimSpeed(); pDesc->BoneCount = (_uint)m_Bones.size(); pDesc->PreTransformMatrix = m_PreTransformMatrix; - m_pContext->Unmap(m_pConstantBuffer, 0); } } @@ -948,63 +967,40 @@ void CModel::ComputeAnimation() _uint iGroupCountX = ((_uint)m_Bones.size() + 255) / 256; - ID3D11Buffer* inputs[2] = { - m_pKeyFrameBuffer, - m_pBoneInfoBuffer + CAnimation* pAnim = m_Animations[m_iCurrentAnimIndex]; + ID3D11ShaderResourceView* srvs[2] = { + pAnim->Get_KeyFrameSrv(), + pAnim->Get_ChannelSrv(), }; - vector OutSubResources = {}; - D3D11_MAPPED_SUBRESOURCE VBInstanceResource = {}; + m_pContext->CSSetShader(m_pComputeShader->Get_Compute(), nullptr, 0); + m_pContext->CSSetConstantBuffers(0, 1, &m_pConstantBuffer); + m_pContext->CSSetShaderResources(0, 2, srvs); - OutSubResources = m_pComputeShader->Dispatch(0, 0, _float3((_float)iGroupCountX, 1.f, 1.f), inputs, m_pConstantBuffer); + ID3D11UnorderedAccessView* uavs[1] = { m_pComputeShader->GetOutputUAV(0) }; + m_pContext->CSSetUnorderedAccessViews(0, 1, uavs, nullptr); + + m_pContext->Dispatch(iGroupCountX, 1, 1); + + auto outSubs = m_pComputeShader->ReadBackOutputs(); + m_pLocalPos = static_cast(outSubs[0].pData); } -HRESULT CModel::Create_KeyFrameVB() +HRESULT CModel::Create_ParentVB() { - for (_uint i = 0; i < (_uint)m_Animations[m_iCurrentAnimIndex]->Get_KeyCount(); i++) - { - m_KeyFrame.push_back(m_Animations[m_iCurrentAnimIndex]->Get_KeyFrameDesc(i)); - } - - D3D11_BUFFER_DESC desc{}; desc.Usage = D3D11_USAGE_DEFAULT; - desc.ByteWidth = (_int)sizeof(KEYFRAME_DESC) * m_Animations[m_iCurrentAnimIndex]->Get_KeyFrameCount(); + desc.ByteWidth = (_int)sizeof(PARENT_DESC) * (_uint)m_Bones.size(); desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; desc.CPUAccessFlags = 0; - desc.StructureByteStride = (_int)sizeof(KEYFRAME_DESC); + desc.StructureByteStride = (_int)sizeof(PARENT_DESC); desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; D3D11_SUBRESOURCE_DATA init{}; - init.pSysMem = m_KeyFrame.data(); + init.pSysMem = m_Parent.data(); - m_pDevice->CreateBuffer(&desc, &init, &m_pKeyFrameBuffer); - - - return S_OK; -} - -HRESULT CModel::Create_BoneInfoVB() -{ - for (size_t i = 0; i < m_Bones.size(); i++) - { - m_BoneInfo[i].ParentIndex = m_Bones[i]->Get_ParentBoneIndex(); - } - - - D3D11_BUFFER_DESC desc{}; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.ByteWidth = (_int)sizeof(BONEINFO_DESC) * (_uint)m_Bones.size(); - desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - desc.CPUAccessFlags = 0; - desc.StructureByteStride = (_int)sizeof(BONEINFO_DESC); - desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; - - D3D11_SUBRESOURCE_DATA init{}; - init.pSysMem = m_BoneInfo.data(); - - m_pDevice->CreateBuffer(&desc, &init, &m_pBoneInfoBuffer); + m_pDevice->CreateBuffer(&desc, &init, &m_pParentBuffer); return S_OK; @@ -1061,7 +1057,7 @@ HRESULT CModel::Initialize_Prototype(MODEL eType, const _char* pModelFilePath, _ return E_FAIL; } - if (FAILED(Ready_Animations())) { + if (FAILED(Ready_Animations(m_Bones))) { return E_FAIL; } return S_OK; @@ -1348,14 +1344,21 @@ HRESULT CModel::Initialize(void* pArg) if (m_eType == MODEL::ANIM) - { - Create_Con(); + { + Create_Temp(); + m_Parent.resize(m_Bones.size()); + for (size_t i = 0; i < (_uint)m_Bones.size(); i++) + { + m_Parent[i].ParentIndex = m_Bones[i]->Get_ParentBoneIndex(); + } if (FAILED(Create_CS())) return E_FAIL; - Create_KeyFrameVB(); - Create_BoneInfoVB(); + Create_Con(); + Create_LocalPosVB(); + Create_ParentVB(); + } @@ -1413,13 +1416,13 @@ HRESULT CModel::Ready_Bones(const std::vector& allNodes, _int currentI return S_OK; } -HRESULT CModel::Ready_Animations() +HRESULT CModel::Ready_Animations(const vector& Bones) { m_iNumAnimations = m_pSaveModel->AnimationCount; for (size_t i = 0; i < m_iNumAnimations; i++) { - CAnimation* pAnimation = CAnimation::Create(this, &m_pSaveModel->Animations[i]); + CAnimation* pAnimation = CAnimation::Create(Bones,this, &m_pSaveModel->Animations[i]); if (nullptr == pAnimation) return E_FAIL; @@ -1460,6 +1463,11 @@ void CModel::Free() { __super::Free(); + + SAFE_RELEASE(m_pComputeShader); + SAFE_RELEASE(m_pConstantBuffer); + SAFE_RELEASE(m_pParentBuffer); + SAFE_RELEASE(m_pLocalPosBuffer); for (auto& pAnimation : m_Animations) { SAFE_RELEASE(pAnimation); } @@ -1483,8 +1491,8 @@ void CModel::Free() m_SaveModel.clear(); - SAFE_RELEASE(m_pComputeShader); - SAFE_RELEASE(m_pConstantBuffer); + m_Parent.clear(); + m_AnimRanges.clear(); } void CModel::Describe_Entity() diff --git a/Jusin154_Team3D/Engine/Public/Animation.h b/Jusin154_Team3D/Engine/Public/Animation.h index 4456c6bff..3140d3dd6 100644 --- a/Jusin154_Team3D/Engine/Public/Animation.h +++ b/Jusin154_Team3D/Engine/Public/Animation.h @@ -11,7 +11,7 @@ class ENGINE_DLL CAnimation : public CBase CAnimation(const CAnimation& rhs); virtual ~CAnimation() = default; public: - _bool Update_TransformationMatrices(const vector& Bones, _bool bIsLoop, _float fTimeDelta, class CTransform* pTransform = nullptr); + _bool Update_TransformationMatrices(const vector& Bones, const LOCALPOS_DESC* pLocalPosArray, _bool bIsLoop, _float fTimeDelta, class CTransform* pTransform = nullptr); void ResetRootMotion(); void Depart_Animation(); void Set_AnimPause(_bool bValue) { m_bPause = bValue; } @@ -21,6 +21,7 @@ class ENGINE_DLL CAnimation : public CBase void Set_AnimProgressPostion(const _char* pChannelName, _uint iPosition); vector<_int>* Capture_Bones(); void InterpAnim(CAnimation* pPreAnim, vector& Bones, float fRatio); + void CreateGPUData(ID3D11Device* pDevice); vector Get_StartFrameInformations() { return m_StartKeyFrames; } const _string& Get_Name() const { return m_strName; } @@ -32,10 +33,11 @@ class ENGINE_DLL CAnimation : public CBase _uint Get_ChannelCount() { return m_iNumChannels; } _float Get_Duration() { return m_fDuration; } - void Set_KeyFrameDesc(); - KEYFRAME_DESC Get_KeyFrameDesc(_uint iIndex) { return m_KeyFrame[iIndex]; } - _uint Get_KeyCount() { return (_uint)m_KeyFrame.size(); } - _uint Get_KeyFrameCount(); + + ID3D11Buffer* Get_KeyFrameBuffer() { return m_pKeyFrameBuffer; } + ID3D11Buffer* Get_ChannelBuffer() { return m_pChannelBuffer; } + ID3D11ShaderResourceView* Get_KeyFrameSrv() { return m_pKeyFrameSrv; } + ID3D11ShaderResourceView* Get_ChannelSrv() { return m_pChannelSrv; } #ifdef EDITOR_PROJECT private: HRESULT Initialize(const vector& Bones, const aiAnimation* pAIAnimation); @@ -47,11 +49,16 @@ class ENGINE_DLL CAnimation : public CBase private: HRESULT Initialize(HANDLE hFile, DWORD& dwByte); // ë°”ì�´ë„ˆë¦¬ - HRESULT Initialize(const class CModel* pModel,SaveAnimation* pSaveAnimation); + HRESULT Initialize(const vector& Bones, const class CModel* pModel,SaveAnimation* pSaveAnimation); // HRESULT Combined_Initialize(); _uint Get_BoneIndex(const char* pChannelName); + HRESULT CreateKeyFrameBuffer(ID3D11Device* pDevice, vector keyframe); + HRESULT CreateChannelBuffer(ID3D11Device* pDevice, vector channel); + + + private: SaveAnimation* m_pSaveAnim = { nullptr }; _char m_szName[MAX_PATH] = {}; @@ -70,15 +77,22 @@ class ENGINE_DLL CAnimation : public CBase vector<_int> m_DestBones; // ì�´ 애니메ì�´ì…˜ì—�서 ì˜�í–¥ì�„ 받는 본들ì�˜ ì§‘í•© vector m_StartKeyFrames; // ì�´ 애니메ì�´ì…˜ì�˜ ì˜�í–¥ì�„ 받는 본들ì�˜ 초기값 - vector<_matrix> m_vBoneTransformationMatrix = {}; + vector<_matrix> m_vBoneTransformationMatrix = {}; - _int m_iRawVertexStride = {}; - vector m_KeyFrame; - _int m_KeyCount = {}; + _uint m_iChannelCount; + _uint m_iKeyframeCount; + _uint m_iBoneCount; + vector m_KeyFrameDesc; + vector m_ChannelDesc; + + ID3D11Buffer* m_pKeyFrameBuffer; + ID3D11Buffer* m_pChannelBuffer; + ID3D11ShaderResourceView* m_pKeyFrameSrv = {}; + ID3D11ShaderResourceView* m_pChannelSrv = {}; public: static CAnimation* Create(HANDLE hFile, DWORD& dwByte); // ë°”ì�´ë„ˆë¦¬ - static CAnimation* Create(const class CModel* pModel, SaveAnimation* pSaveAnimation); + static CAnimation* Create(const vector& Bones, const class CModel* pModel, SaveAnimation* pSaveAnimation); // CAnimation* Clone(); virtual void Free() override; diff --git a/Jusin154_Team3D/Engine/Public/Channel.h b/Jusin154_Team3D/Engine/Public/Channel.h index f70a5a29e..759f3718c 100644 --- a/Jusin154_Team3D/Engine/Public/Channel.h +++ b/Jusin154_Team3D/Engine/Public/Channel.h @@ -13,19 +13,23 @@ class ENGINE_DLL CChannel : public CBase #ifdef EDITOR_PROJECT private: HRESULT Initialize(const vector& Bones, const aiNodeAnim* pAIChannel); + public: HRESULT SaveAsBinary(HANDLE hFile, DWORD& dwByte); static CChannel* Create(const vector& Bones, const aiNodeAnim* pAIChannel); + void Fill_GPU_Keyframes(vector& outKeyframes); + CHANNEL_DESC Fill_GPU_ChannelDesc(); #endif // EDITOR_PROJECT public: - void Update_TransformationMatirx(const vector& Bones, _float fCurrentTrackPosition, _uint* pCurrentKeyFrameIndex,class CTransform* pTransform=nullptr); + void Update_TransformationMatirx(const vector& Bones, const LOCALPOS_DESC* pLocalPosArray, _float fCurrentTrackPosition, _uint* pCurrentKeyFrameIndex,class CTransform* pTransform=nullptr); _int Get_BoneIndex() { return { m_iBoneIndex }; } void Set_BoneIndex(_int iBoneIndex) { m_iBoneIndex = iBoneIndex; } void ResetRootMotion() { m_vPrevRootPos = { 0.f, 0.f, 0.f }; m_vPrevRootRot = { 0.f,0.f,0.f,0.f }; m_bInitialRootRotSaved = false; + m_bInitialRootPos = false; } _matrix Get_BoneTransformationMatrix() { return m_BoneTransformationMatrix; } @@ -35,8 +39,6 @@ class ENGINE_DLL CChannel : public CBase return !strcmp(pChannelname, m_szName); } _char* Get_Name() { return m_szName; } - KEYFRAME_DESC Get_KeyFrameDesc() { return m_KeyFrame; } - _int Get_KeyFrameCount() { return (_int)m_KeyFrames.size(); } private: HRESULT Initialize(HANDLE hFile, DWORD& dwByte); // ë°”ì�´ë„ˆë¦¬ @@ -55,9 +57,10 @@ class ENGINE_DLL CChannel : public CBase _matrix m_BoneTransformationMatrix = {}; _float m_fPrevYaw = 0.f; _bool m_bInitialRootRotSaved = {false}; + _bool m_bInitialRootPos = { false }; _float4 m_vInitialRootRot = {}; - KEYFRAME_DESC m_KeyFrame; + vector m_KeyFrameDesc; public: static CChannel* Create(const vector& Bones, _uint iIndex); // 럴프전용 static CChannel* Create(HANDLE hFile, DWORD& dwByte); diff --git a/Jusin154_Team3D/Engine/Public/ComputeShader.h b/Jusin154_Team3D/Engine/Public/ComputeShader.h index 89980d890..69e66bcff 100644 --- a/Jusin154_Team3D/Engine/Public/ComputeShader.h +++ b/Jusin154_Team3D/Engine/Public/ComputeShader.h @@ -17,6 +17,8 @@ class ENGINE_DLL CComputeShader final : public CBase vector Dispatch(_uint iSRVIndex, _uint iUAVIndex, _float3 vGroupCount, ID3D11Buffer** ppBuffers, ID3D11Buffer* pConstantBuffer = nullptr); void Bind_OutPut_SRV(_uint iIndex, _uint iBufferIndex); ID3D11ComputeShader* Get_Compute() { return m_pComputeShader; } + ID3D11UnorderedAccessView* GetOutputUAV(_uint iIndex) const; + vector ReadBackOutputs(); private: void Bind_SRV(_uint iIndex); void Bind_UAV(_uint iIndex); diff --git a/Jusin154_Team3D/Engine/Public/Engine_Struct.h b/Jusin154_Team3D/Engine/Public/Engine_Struct.h index 3a5545a87..9ad49e3c9 100644 --- a/Jusin154_Team3D/Engine/Public/Engine_Struct.h +++ b/Jusin154_Team3D/Engine/Public/Engine_Struct.h @@ -371,18 +371,33 @@ typedef struct tagKeyFrameDesc }KEYFRAME_DESC; -typedef struct tagBoneInfo +typedef struct tagChannelDesc +{ + _uint StartIndex; + _uint KeyCount; + _uint BoneIndex; + //_uint Padding; +}CHANNEL_DESC; + + +typedef struct tagParentDesc { _int ParentIndex; +}PARENT_DESC; -}BONEINFO_DESC; - - -typedef struct tagBoneMatrix +typedef struct tagLocalPos { - _float4x4 LocalMatrix; - _float4x4 CombinedMatrix; + _float3 Scale; + _float pad0; + _float4 Rotation; + _float3 Translation; + _float pad1; +}LOCALPOS_DESC; +typedef struct tagBoneDesc +{ + _float4x4 Combined; }BONE_DESC; + NS_END diff --git a/Jusin154_Team3D/Engine/Public/Model.h b/Jusin154_Team3D/Engine/Public/Model.h index cedd067e4..4f070c18e 100644 --- a/Jusin154_Team3D/Engine/Public/Model.h +++ b/Jusin154_Team3D/Engine/Public/Model.h @@ -79,11 +79,9 @@ static _int Get_BoneIndex(const _char* pBoneName, vector Bones); / #pragma endregion void Create_Con(); - HRESULT Bind_CS_Output(_uint Index, _uint iBufferIndex); void UpdateAnimationCS(); void ComputeAnimation(); - HRESULT Create_KeyFrameVB(); - HRESULT Create_BoneInfoVB(); + HRESULT Create_ParentVB(); void Get_BoneMatrix(); public: @@ -156,16 +154,23 @@ static _int Get_BoneIndex(const _char* pBoneName, vector Bones); / private: HRESULT Create_CS(); - _uint m_iNumBuffer = {}; - vector m_KeyFrame = {}; - vector m_BoneInfo = {}; + void Create_Temp(); + + void Create_LocalPosVB(); + + _uint m_iNumBuffer = {}; + + vector m_Parent = {}; + vector m_AnimRanges; + + LOCALPOS_DESC* m_pLocalPos = { nullptr }; + + class CComputeShader* m_pComputeShader = nullptr; - class CComputeShader* m_pComputeShader = {}; ID3D11Buffer* m_pConstantBuffer = { nullptr }; - ID3D11Buffer* m_pKeyFrameBuffer = { nullptr }; - ID3D11Buffer* m_pBoneInfoBuffer = { nullptr }; - + ID3D11Buffer* m_pParentBuffer = { nullptr }; + ID3D11Buffer* m_pLocalPosBuffer = { nullptr }; private: // ë°”ì�´ë„ˆë¦¬ virtual HRESULT Initialize_Prototype(MODEL eType, const _char* pModelFilePath, _fmatrix PreTransformMatrix); @@ -180,7 +185,7 @@ static _int Get_BoneIndex(const _char* pBoneName, vector Bones); / HRESULT Ready_Meshes(); HRESULT Ready_Materials(const _char* pModelFilePath); HRESULT Ready_Bones(const std::vector& allNodes, _int currentIndex, _int parentIndex); - HRESULT Ready_Animations(); + HRESULT Ready_Animations(const vector& Bones); // public: