From 651d85b45ff29b803ddd4fc96bd2b949401b240d Mon Sep 17 00:00:00 2001 From: hyunbin14 Date: Wed, 17 Dec 2025 19:49:48 +0900 Subject: [PATCH] =?UTF-8?q?[Add]=20=EC=BB=B4=EC=89=90=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jusin154_Team3D/Client/Private/Broom.cpp | 11 +- .../Client/Private/BroomRacerAI.cpp | 15 +- .../Client/Private/CamPosition_Shoulder.cpp | 9 + Jusin154_Team3D/Client/Private/Goblin.cpp | 20 +- .../Client/Private/Goblin_Mage.cpp | 18 +- .../Client/Private/Goblin_Mage_States.cpp | 5 +- .../Client/Private/Goblin_Spector.cpp | 9 +- .../Client/Private/Goblin_States.cpp | 5 +- .../Client/Private/Level_GamePlay.cpp | 20 +- .../Client/Private/NPC_Ollivander.cpp | 20 +- Jusin154_Team3D/Client/Private/Player.cpp | 23 +- .../Client/Private/Player_States.cpp | 18 +- Jusin154_Team3D/Client/Private/Troll.cpp | 28 +- Jusin154_Team3D/Client/Public/Player.h | 1 + .../ShaderFiles/Shader_Mesh_Compute.hlsl | 414 +++++++++++++++--- .../ShaderFiles/Shader_NPC_PBR_Anim.hlsl | 65 ++- .../ShaderFiles/Shader_VtxAnimMesh.hlsl | 173 +++++--- Jusin154_Team3D/Editor/Private/Goblin.cpp | 19 +- .../Editor/Private/Goblin_Spector.cpp | 9 +- Jusin154_Team3D/Editor/Private/Player.cpp | 16 +- Jusin154_Team3D/Editor/Private/Troll.cpp | 9 +- Jusin154_Team3D/Editor/Private/Wand.cpp | 22 +- .../ShaderFiles/Shader_Mesh_Compute.hlsl | 414 +++++++++++++++--- Jusin154_Team3D/Engine/Private/Animation.cpp | 27 +- Jusin154_Team3D/Engine/Private/Channel.cpp | 151 +++---- .../Engine/Private/ComputeShader.cpp | 28 ++ Jusin154_Team3D/Engine/Private/Mesh.cpp | 38 +- Jusin154_Team3D/Engine/Private/Model.cpp | 411 +++++++++++++---- .../Engine/Private/Prototype_Manager.cpp | 7 + Jusin154_Team3D/Engine/Public/Animation.h | 6 +- Jusin154_Team3D/Engine/Public/Bone.h | 4 + Jusin154_Team3D/Engine/Public/Channel.h | 8 +- Jusin154_Team3D/Engine/Public/ComputeShader.h | 2 + Jusin154_Team3D/Engine/Public/Engine_Macro.h | 2 +- Jusin154_Team3D/Engine/Public/Engine_Struct.h | 20 +- Jusin154_Team3D/Engine/Public/Mesh.h | 13 +- Jusin154_Team3D/Engine/Public/Model.h | 70 +-- 37 files changed, 1629 insertions(+), 501 deletions(-) diff --git a/Jusin154_Team3D/Client/Private/Broom.cpp b/Jusin154_Team3D/Client/Private/Broom.cpp index 7aae1c143..18bc9ede1 100644 --- a/Jusin154_Team3D/Client/Private/Broom.cpp +++ b/Jusin154_Team3D/Client/Private/Broom.cpp @@ -176,17 +176,24 @@ HRESULT CBroom::Render() for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { + if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) { return E_FAIL; } - if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) { + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { return E_FAIL; } if (FAILED(m_pModelCom->Begin(i, m_pShaderCom))) { return E_FAIL; } + m_pModelCom->Bind_OutPut_SRV_VS(26, 0); + if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } diff --git a/Jusin154_Team3D/Client/Private/BroomRacerAI.cpp b/Jusin154_Team3D/Client/Private/BroomRacerAI.cpp index e89649390..343faf2f0 100644 --- a/Jusin154_Team3D/Client/Private/BroomRacerAI.cpp +++ b/Jusin154_Team3D/Client/Private/BroomRacerAI.cpp @@ -189,13 +189,20 @@ HRESULT CBroomRacerAI::Render_Shadow(SHADOW eType) for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { + return E_FAIL; + + } + if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_ANIM::SHADOW)))) { return E_FAIL; } - if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_ANIM::DEFAULT)))) { - return E_FAIL; - } + m_pModelCom->Bind_OutPut_SRV_VS(31, 0); if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; diff --git a/Jusin154_Team3D/Client/Private/CamPosition_Shoulder.cpp b/Jusin154_Team3D/Client/Private/CamPosition_Shoulder.cpp index 9c709dc05..31e9814d5 100644 --- a/Jusin154_Team3D/Client/Private/CamPosition_Shoulder.cpp +++ b/Jusin154_Team3D/Client/Private/CamPosition_Shoulder.cpp @@ -3,6 +3,7 @@ #include "CamPosition_Target.h" #include "GameInstance.h" #include "Camera_Gaze.h" +#include "Player.h" CCamPosition_Shoulder::CCamPosition_Shoulder(ID3D11Device* pDevice, ID3D11DeviceContext* pContext) : CCamPosition(pDevice, pContext) @@ -100,6 +101,14 @@ void CCamPosition_Shoulder::Update(_float fTimeDelta) #ifdef _DEBUG Describe_Entity(); #endif // _DEBUG + + if (dynamic_cast(m_pOwner)->Get_UIState() == ENUM_CLASS(UI_STATE::GAMEPLAYER)) + { + m_bMovable = true; + } + else { + m_bMovable = false; + } if (m_pGameInstance->Key_Up(DIK_PGDN)) { m_bDampingParentPos = !m_bDampingParentPos; } diff --git a/Jusin154_Team3D/Client/Private/Goblin.cpp b/Jusin154_Team3D/Client/Private/Goblin.cpp index d6d3eb529..54f35bbcf 100644 --- a/Jusin154_Team3D/Client/Private/Goblin.cpp +++ b/Jusin154_Team3D/Client/Private/Goblin.cpp @@ -174,18 +174,24 @@ HRESULT CGoblin::Render() for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { return E_FAIL; } if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) { return E_FAIL; } - if (FAILED(m_pShaderCom->Begin(iShaderPass))) { return E_FAIL; } + m_pModelCom->Bind_OutPut_SRV_VS(31, 0); + if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } @@ -240,13 +246,21 @@ HRESULT CGoblin::Render_Shadow(SHADOW eType) _uint iNumMeshes = m_pModelCom->Get_NumMeshes(); for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { return E_FAIL; + } if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_ANIM::SHADOW)))) { return E_FAIL; } + m_pModelCom->Bind_OutPut_SRV_VS(31, 0); + if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } diff --git a/Jusin154_Team3D/Client/Private/Goblin_Mage.cpp b/Jusin154_Team3D/Client/Private/Goblin_Mage.cpp index dc5453767..b88882f45 100644 --- a/Jusin154_Team3D/Client/Private/Goblin_Mage.cpp +++ b/Jusin154_Team3D/Client/Private/Goblin_Mage.cpp @@ -175,7 +175,12 @@ HRESULT CGoblin_Mage::Render() } for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { return E_FAIL; } @@ -187,6 +192,8 @@ HRESULT CGoblin_Mage::Render() return E_FAIL; } + m_pModelCom->Bind_OutPut_SRV_VS(31, 0); + if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } @@ -233,13 +240,20 @@ HRESULT CGoblin_Mage::Render_Shadow(SHADOW eType) _uint iNumMeshes = m_pModelCom->Get_NumMeshes(); for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { return E_FAIL; } if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_ANIM::SHADOW)))) { return E_FAIL; } + m_pModelCom->Bind_OutPut_SRV_VS(31, 0); + if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } diff --git a/Jusin154_Team3D/Client/Private/Goblin_Mage_States.cpp b/Jusin154_Team3D/Client/Private/Goblin_Mage_States.cpp index abfb9d7f7..a32bc683d 100644 --- a/Jusin154_Team3D/Client/Private/Goblin_Mage_States.cpp +++ b/Jusin154_Team3D/Client/Private/Goblin_Mage_States.cpp @@ -382,7 +382,7 @@ void CGoblin_Mage::Behavior_HitEnter() { if (m_fHitDegree >= 90.f) { - _int iRandIndex = m_pGameInstance->Real_Random_Int(0, 5); + _int iRandIndex = m_pGameInstance->Real_Random_Int(0, 3); switch (iRandIndex) { case 0: @@ -467,7 +467,8 @@ HRESULT CGoblin_Mage::Behavior_HitExitCheck(_float fTimeDelta) } } } - else + + if(m_eHitSpell == ENUM_CLASS(SKILL_TYPE::ACCIO)) { if (!m_bPos) { diff --git a/Jusin154_Team3D/Client/Private/Goblin_Spector.cpp b/Jusin154_Team3D/Client/Private/Goblin_Spector.cpp index 0cc39e596..07b7261f5 100644 --- a/Jusin154_Team3D/Client/Private/Goblin_Spector.cpp +++ b/Jusin154_Team3D/Client/Private/Goblin_Spector.cpp @@ -161,7 +161,12 @@ HRESULT CGoblin_Spector::Render() for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { return E_FAIL; } @@ -173,6 +178,8 @@ HRESULT CGoblin_Spector::Render() return E_FAIL; } + m_pModelCom->Bind_OutPut_SRV_VS(31, 0); + if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } diff --git a/Jusin154_Team3D/Client/Private/Goblin_States.cpp b/Jusin154_Team3D/Client/Private/Goblin_States.cpp index 58e064e89..d7951ad20 100644 --- a/Jusin154_Team3D/Client/Private/Goblin_States.cpp +++ b/Jusin154_Team3D/Client/Private/Goblin_States.cpp @@ -458,7 +458,7 @@ void CGoblin::Behavior_HitEnter() { if (m_fHitDegree >= 90.f) { - _int iRandIndex = m_pGameInstance->Real_Random_Int(0, 5); + _int iRandIndex = m_pGameInstance->Real_Random_Int(0, 3); switch (iRandIndex) { case 0: @@ -543,7 +543,8 @@ HRESULT CGoblin::Behavior_HitExitCheck(_float fTimeDelta) } } } - else + + if (m_eHitSpell == ENUM_CLASS(SKILL_TYPE::ACCIO)) { if (!m_bPos) { diff --git a/Jusin154_Team3D/Client/Private/Level_GamePlay.cpp b/Jusin154_Team3D/Client/Private/Level_GamePlay.cpp index 1741b6faa..d7346d648 100644 --- a/Jusin154_Team3D/Client/Private/Level_GamePlay.cpp +++ b/Jusin154_Team3D/Client/Private/Level_GamePlay.cpp @@ -509,21 +509,25 @@ HRESULT CLevel_GamePlay::Ready_Layer_Player(const _wstring& strLayerTag) { if (FAILED(m_pGameInstance->Add_GameObject_ToLayer(g_iStaticLevel, NEXT_LEVEL, strLayerTag))) { return E_FAIL; + } + + /*for (_uint i = 0; i < 1; ++i) { if (FAILED(m_pGameInstance->Add_GameObject_ToLayer(g_iStaticLevel, NEXT_LEVEL, strLayerTag))) { return E_FAIL; } + }*/ return S_OK; } HRESULT CLevel_GamePlay::Ready_Layer_BroomRacerAI(const _wstring& strLayerTag) { - for (_uint i = 0; i < 1; ++i) { - if (FAILED(m_pGameInstance->Add_GameObject_ToLayer(g_iStaticLevel, NEXT_LEVEL, strLayerTag, m_pBroomRaceManager))) { - return E_FAIL; - } - } + //for (_uint i = 0; i < 1; ++i) { + // if (FAILED(m_pGameInstance->Add_GameObject_ToLayer(g_iStaticLevel, NEXT_LEVEL, strLayerTag, m_pBroomRaceManager))) { + // return E_FAIL; + // } + //} return S_OK; } @@ -534,7 +538,7 @@ HRESULT CLevel_GamePlay::Ready_Layer_Item(const _wstring& strLayerTag) HRESULT CLevel_GamePlay::Ready_Layer_RaceRing(const _wstring& strLayerTag) { - for (_uint i = 0; i < 50; ++i) { + for (_uint i = 0; i < 1; ++i) { if (FAILED(m_pGameInstance->Add_GameObject_ToLayer(g_iStaticLevel, NEXT_LEVEL, strLayerTag, m_pBroomRaceManager))) { return E_FAIL; } @@ -564,12 +568,12 @@ HRESULT CLevel_GamePlay::Ready_Layer_Monster() { for (_uint i = 0; i < 1; ++i) { - if (FAILED(m_pGameInstance->Add_GameObject_ToLayer(g_iStaticLevel, NEXT_LEVEL, LAYER_MONSTER,&i))) { + if (FAILED(m_pGameInstance->Add_GameObject_ToLayer(g_iStaticLevel, NEXT_LEVEL, LAYER_MONSTER))) { return E_FAIL; } } - for (_uint i = 0; i < 1; ++i) + for (_uint i = 0; i <1; ++i) { if (FAILED(m_pGameInstance->Add_GameObject_ToLayer(g_iStaticLevel, NEXT_LEVEL, LAYER_MONSTER, &i))) { return E_FAIL; diff --git a/Jusin154_Team3D/Client/Private/NPC_Ollivander.cpp b/Jusin154_Team3D/Client/Private/NPC_Ollivander.cpp index d2a9006c8..6c0f3e601 100644 --- a/Jusin154_Team3D/Client/Private/NPC_Ollivander.cpp +++ b/Jusin154_Team3D/Client/Private/NPC_Ollivander.cpp @@ -56,7 +56,12 @@ HRESULT CNPC_Ollivander::Render() for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { return E_FAIL; } @@ -66,6 +71,9 @@ HRESULT CNPC_Ollivander::Render() if (FAILED(m_pModelCom->Begin(i, m_pShaderCom))) { return E_FAIL; } + + m_pModelCom->Bind_OutPut_SRV_VS(26, 0); + if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } @@ -89,12 +97,20 @@ HRESULT CNPC_Ollivander::Render_Shadow(SHADOW eType) for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { return E_FAIL; } if (FAILED(m_pModelCom->Begin(i, m_pShaderCom))) { return E_FAIL; } + + m_pModelCom->Bind_OutPut_SRV_VS(26, 0); + if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } diff --git a/Jusin154_Team3D/Client/Private/Player.cpp b/Jusin154_Team3D/Client/Private/Player.cpp index 236719d6e..59dece4c3 100644 --- a/Jusin154_Team3D/Client/Private/Player.cpp +++ b/Jusin154_Team3D/Client/Private/Player.cpp @@ -253,17 +253,25 @@ HRESULT CPlayer::Render() for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { + if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) { return E_FAIL; } - if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) { + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { return E_FAIL; } if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_ANIM::DEFAULT)))) { return E_FAIL; } + + m_pModelCom->Bind_OutPut_SRV_VS(31, 0); + if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } @@ -292,14 +300,21 @@ HRESULT CPlayer::Render_Shadow(SHADOW eType) for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { return E_FAIL; } - if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_ANIM::SHADOW)))) { return E_FAIL; } + m_pModelCom->Bind_OutPut_SRV_VS(31, 0); + + if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } diff --git a/Jusin154_Team3D/Client/Private/Player_States.cpp b/Jusin154_Team3D/Client/Private/Player_States.cpp index 1cdba3014..efb94cbb3 100644 --- a/Jusin154_Team3D/Client/Private/Player_States.cpp +++ b/Jusin154_Team3D/Client/Private/Player_States.cpp @@ -53,7 +53,8 @@ void CPlayer::Get_UIState(_int UIState) HRESULT CPlayer::InputAction() { - if ((m_eUIState != ENUM_CLASS(UI_STATE::SPELL))) { + if ((m_eUIState != ENUM_CLASS(UI_STATE::SPELL) && + m_eUIState !=ENUM_CLASS(UI_STATE::QUEST_CANVES))) { if ( m_pGameInstance->Key_Down(DIK_SPACE) || m_pGameInstance->Key_Down(DIK_LCONTROL) @@ -86,6 +87,11 @@ HRESULT CPlayer::InputAction() if (m_pGameInstance->Key_Down(DIK_T)) m_pInfoInstance->Key_Input(ENUM_CLASS(KEYINPUT::INPUT_T)); return S_OK; } + if (m_pGameInstance->Key_Down(DIK_TAB)) + { + if (m_pGameInstance->Key_Down(DIK_TAB)) m_pInfoInstance->Key_Input(ENUM_CLASS(KEYINPUT::INPUT_TAB)); + return S_OK; + } } return E_FAIL; @@ -93,7 +99,8 @@ HRESULT CPlayer::InputAction() HRESULT CPlayer::InputMove() { - if ((m_eUIState != ENUM_CLASS(UI_STATE::SPELL))) { + if ((m_eUIState != ENUM_CLASS(UI_STATE::SPELL) && + m_eUIState != ENUM_CLASS(UI_STATE::QUEST_CANVES))) { if (m_pGameInstance->Key_Pressing(DIK_W) || m_pGameInstance->Key_Pressing(DIK_A) @@ -109,7 +116,8 @@ HRESULT CPlayer::InputMove() HRESULT CPlayer::InputKeyUpMove() { - if ((m_eUIState != ENUM_CLASS(UI_STATE::SPELL))) { + if ((m_eUIState != ENUM_CLASS(UI_STATE::SPELL) && + m_eUIState != ENUM_CLASS(UI_STATE::QUEST_CANVES))) { if (m_pGameInstance->Key_Up(DIK_W) || m_pGameInstance->Key_Up(DIK_A) || m_pGameInstance->Key_Up(DIK_S) @@ -123,7 +131,8 @@ HRESULT CPlayer::InputKeyUpMove() HRESULT CPlayer::InputSpell() { - if ((m_eUIState != ENUM_CLASS(UI_STATE::SPELL))) { + if ((m_eUIState != ENUM_CLASS(UI_STATE::SPELL) && + m_eUIState != ENUM_CLASS(UI_STATE::QUEST_CANVES))) { if ( m_pGameInstance->Key_Down(DIK_1) || m_pGameInstance->Key_Down(DIK_2) @@ -1625,6 +1634,7 @@ HRESULT CPlayer::Behavior_HitExitCheck() void CPlayer::Behavior_HitExit() { m_pFSM->Disable_State(FSMSTATE::HIT); + m_bLookAt = false; } void CPlayer::Behavior_Broom_RideEnter() diff --git a/Jusin154_Team3D/Client/Private/Troll.cpp b/Jusin154_Team3D/Client/Private/Troll.cpp index d0ab1dedb..f6c187f82 100644 --- a/Jusin154_Team3D/Client/Private/Troll.cpp +++ b/Jusin154_Team3D/Client/Private/Troll.cpp @@ -194,7 +194,12 @@ HRESULT CTroll::Render() _uint iNumMeshes = m_pModelCom->Get_NumMeshes(); for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { return E_FAIL; } @@ -206,6 +211,8 @@ HRESULT CTroll::Render() return E_FAIL; } + m_pModelCom->Bind_OutPut_SRV_VS(26, 0); + if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } @@ -266,7 +273,12 @@ HRESULT CTroll::Render_OutLine() for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { return E_FAIL; } @@ -278,6 +290,8 @@ HRESULT CTroll::Render_OutLine() return E_FAIL; } + m_pModelCom->Bind_OutPut_SRV_VS(26, 0); + if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } @@ -299,13 +313,21 @@ HRESULT CTroll::Render_Shadow(SHADOW eType) _uint iNumMeshes = m_pModelCom->Get_NumMeshes(); for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { return E_FAIL; } if (FAILED(m_pModelCom->Begin(i, m_pShaderCom))) { return E_FAIL; } + + m_pModelCom->Bind_OutPut_SRV_VS(26, 0); + if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } diff --git a/Jusin154_Team3D/Client/Public/Player.h b/Jusin154_Team3D/Client/Public/Player.h index 23ab26580..87b1aaef0 100644 --- a/Jusin154_Team3D/Client/Public/Player.h +++ b/Jusin154_Team3D/Client/Public/Player.h @@ -24,6 +24,7 @@ class CPlayer final : public CUnit void Set_SpellHit(_bool bHit) { m_bSpellHit = bHit; } void Set_Shield(_bool bShield) { m_bShield = bShield; } void Start_CameraShake(_float fTime, _float fIntense); + _int Get_UIState() { return m_eUIState; } #ifdef _DEBUG void Render_CameraCoordinateSystem(); #endif // _DEBUG 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 523ae0eff..086caa1b2 100644 --- a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl +++ b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl @@ -1,5 +1,3 @@ -float PI = 3.141592; - struct KeyFrame { float3 vScale; @@ -17,104 +15,402 @@ struct Channel struct LocalPos { - float3 Scale; - float pad0; - - float4 Rotation; - - float3 Translation; - float pad1; + row_major float4x4 Local; + row_major float4x4 Combined; + row_major float4x4 LocalCombined; }; +struct BoneLocal +{ + row_major float4x4 BoneLocal; +}; StructuredBuffer g_KeyFrameBuffer : register(t0); StructuredBuffer g_ChannelBuffer : register(t1); +StructuredBuffer g_PrevKeyFrameBuffer : register(t2); +StructuredBuffer g_PrevChannelBuffer : register(t3); +StructuredBuffer g_ParentBuffer : register(t4); +StructuredBuffer g_BoneLocalBuffer : register(t5); +StructuredBuffer g_BoneRemap : register(t6); RWStructuredBuffer g_LocalPosOutput : register(u0); - cbuffer AnimCB : register(b0) { float CurrentTime; float Duration; - float Speed; + int MeshBoneCount; int BoneCount; + + int RootBoneIndex; + int padding1; + float PrevTime; + float BlendRatio; row_major float4x4 PreTransformMatrix; + float4 RootInitRot; }; -float4 quatSlerp(float4 q1, float4 q2, float t) +static const float EPS = 1e-6f; + +float4 QuatNormalize(float4 q) { - float cosTheta = dot(q1, q2); + return q * rsqrt(max(dot(q, q), EPS)); +} + +float4 QuatSlerp(float4 a, float4 b, float t) +{ + a = QuatNormalize(a); + b = QuatNormalize(b); + + float cosTheta = dot(a, b); if (cosTheta < 0.0f) { - q2 = -q2; + b = -b; cosTheta = -cosTheta; } if (cosTheta > 0.9995f) - return normalize(lerp(q1, q2, t)); + return QuatNormalize(lerp(a, b, t)); - float theta = acos(cosTheta); - float sinTheta = sin(theta); + float theta = acos(saturate(cosTheta)); + float sinTheta = max(sin(theta), EPS); - float w1 = sin((1.0f - t) * theta) / sinTheta; - float w2 = sin(t * theta) / sinTheta; + float w0 = sin((1.0f - t) * theta) / sinTheta; + float w1 = sin(t * theta) / sinTheta; - return q1 * w1 + q2 * w2; + return a * w0 + b * w1; +} + +float4x4 MakeAffine(float3 scale, float4 rot, float3 trans) +{ + rot = QuatNormalize(rot); + + float xx = rot.x * rot.x; + float yy = rot.y * rot.y; + float zz = rot.z * rot.z; + float xy = rot.x * rot.y; + float xz = rot.x * rot.z; + float yz = rot.y * rot.z; + float wx = rot.w * rot.x; + float wy = rot.w * rot.y; + float wz = rot.w * rot.z; + + float4x4 M; + + M._11 = (1 - 2 * (yy + zz)) * scale.x; + M._12 = (2 * (xy + wz)) * scale.x; + M._13 = (2 * (xz - wy)) * scale.x; + M._14 = 0; + + M._21 = (2 * (xy - wz)) * scale.y; + M._22 = (1 - 2 * (xx + zz)) * scale.y; + M._23 = (2 * (yz + wx)) * scale.y; + M._24 = 0; + + M._31 = (2 * (xz + wy)) * scale.z; + M._32 = (2 * (yz - wx)) * scale.z; + M._33 = (1 - 2 * (xx + yy)) * scale.z; + M._34 = 0; + + M._41 = trans.x; + M._42 = trans.y; + M._43 = trans.z; + M._44 = 1; + + return M; +} + +uint FindKeyIndexCur(uint start, uint count, float t) +{ + uint lo = 0; + uint hi = count - 1; + + float t0 = g_KeyFrameBuffer[start + 0].fTrackPosition; + if (t <= t0) + return 0; + + float tLast = g_KeyFrameBuffer[start + hi].fTrackPosition; + if (t >= tLast) + return hi - 1; + + while (hi - lo > 1) + { + uint mid = (lo + hi) >> 1; + float tm = g_KeyFrameBuffer[start + mid].fTrackPosition; + if (t < tm) + hi = mid; + else + lo = mid; + } + return lo; +} + +uint FindKeyIndexPrev(uint start, uint count, float t) +{ + uint lo = 0; + uint hi = count - 1; + + float t0 = g_PrevKeyFrameBuffer[start + 0].fTrackPosition; + if (t <= t0) + return 0; + + float tLast = g_PrevKeyFrameBuffer[start + hi].fTrackPosition; + if (t >= tLast) + return hi - 1; + + while (hi - lo > 1) + { + uint mid = (lo + hi) >> 1; + float tm = g_PrevKeyFrameBuffer[start + mid].fTrackPosition; + if (t < tm) + hi = mid; + else + lo = mid; + } + return lo; } -[numthreads(256, 1, 1)] -void CS_LocalSRT(uint3 DTID : SV_DispatchThreadID) +float3 GetRow3(float4 v) { - uint boneIndex = DTID.x; - if (boneIndex >= (uint) BoneCount) - return; - - float time = CurrentTime; - - Channel channel = g_ChannelBuffer[boneIndex]; + return v.xyz; +} - LocalPos result; - - uint firstIndex = channel.StartIndex; - uint keyCount = channel.KeyCount; - uint lastIndex = firstIndex + keyCount - 1; +float4x4 SampleLocalPrev(uint bone, float t) +{ + Channel ch = g_PrevChannelBuffer[bone]; + if (ch.KeyCount == 0) + return g_BoneLocalBuffer[bone].BoneLocal; - KeyFrame keyLast = g_KeyFrameBuffer[lastIndex]; + uint start = ch.StartIndex; + uint count = ch.KeyCount; - if (time >= keyLast.fTrackPosition) + if (count == 1) { - result.Scale = keyLast.vScale; - result.Rotation = keyLast.vRotation; - result.Translation = keyLast.vTranslation; - result.pad0 = result.pad1 = 0.0f; + KeyFrame k = g_PrevKeyFrameBuffer[start]; + float3 trans = k.vTranslation; + float4 rot = k.vRotation; + + if (bone == RootBoneIndex) + { + trans = 0; + rot = RootInitRot; + } + return MakeAffine(k.vScale, rot, trans); + } + + uint i0 = FindKeyIndexPrev(start, count, t); + uint i1 = i0 + 1; + + KeyFrame k0 = g_PrevKeyFrameBuffer[start + i0]; + KeyFrame k1 = g_PrevKeyFrameBuffer[start + i1]; + + float denom = max(EPS, (k1.fTrackPosition - k0.fTrackPosition)); + float ratio = saturate((t - k0.fTrackPosition) / denom); + + float3 scale = lerp(k0.vScale, k1.vScale, ratio); + float3 trans = lerp(k0.vTranslation, k1.vTranslation, ratio); + float4 rot = QuatSlerp(k0.vRotation, k1.vRotation, ratio); + + if (bone == RootBoneIndex) + { + trans = 0; + rot = RootInitRot; + } + return MakeAffine(scale, rot, trans); +} + +float4x4 SampleLocal(uint bone, float t) +{ + Channel ch = g_ChannelBuffer[bone]; + if (ch.KeyCount == 0) + return g_BoneLocalBuffer[bone].BoneLocal; + + uint start = ch.StartIndex; + uint count = ch.KeyCount; + + if (count == 1) + { + KeyFrame k = g_KeyFrameBuffer[start]; + float3 trans = k.vTranslation; + float4 rot = k.vRotation; + + if (bone == RootBoneIndex) + { + trans = 0; + rot = RootInitRot; + } + return MakeAffine(k.vScale, rot, trans); + } + + uint i0 = FindKeyIndexCur(start, count, t); + uint i1 = i0 + 1; + + KeyFrame k0 = g_KeyFrameBuffer[start + i0]; + KeyFrame k1 = g_KeyFrameBuffer[start + i1]; + + float denom = max(EPS, (k1.fTrackPosition - k0.fTrackPosition)); + float ratio = saturate((t - k0.fTrackPosition) / denom); + + float3 scale = lerp(k0.vScale, k1.vScale, ratio); + float3 trans = lerp(k0.vTranslation, k1.vTranslation, ratio); + float4 rot = QuatSlerp(k0.vRotation, k1.vRotation, ratio); + + if (bone == RootBoneIndex) + { + trans = 0; + rot = RootInitRot; + } + return MakeAffine(scale, rot, trans); +} +void SampleLocalTRS_Cur(uint bone, float t, out float3 S, out float4 R, out float3 T) +{ + Channel ch = g_ChannelBuffer[bone]; + + if (ch.KeyCount == 0) + { + S = float3(1, 1, 1); + R = float4(0, 0, 0, 1); + T = float3(0, 0, 0); + return; + } + + uint start = ch.StartIndex; + uint count = ch.KeyCount; + + if (count == 1) + { + KeyFrame k = g_KeyFrameBuffer[start]; + S = k.vScale; + R = QuatNormalize(k.vRotation); + T = k.vTranslation; } else { - for (uint i = 0; i < keyCount - 1; ++i) - { - KeyFrame Sour = g_KeyFrameBuffer[firstIndex + i]; - KeyFrame Dest = g_KeyFrameBuffer[firstIndex + i + 1]; + uint i0 = FindKeyIndexCur(start, count, t); + uint i1 = i0 + 1; - if (time >= Sour.fTrackPosition && time <= Dest.fTrackPosition) - { - float ratio = (time - Sour.fTrackPosition) / - (Dest.fTrackPosition - Sour.fTrackPosition); + KeyFrame k0 = g_KeyFrameBuffer[start + i0]; + KeyFrame k1 = g_KeyFrameBuffer[start + i1]; - result.Scale = lerp(Sour.vScale, Dest.vScale, ratio); - result.Rotation = quatSlerp(Sour.vRotation, Dest.vRotation, ratio); - result.Translation = lerp(Sour.vTranslation, Dest.vTranslation, ratio); - result.pad0 = result.pad1 = 0.0f; - break; - } - } + float denom = max(EPS, (k1.fTrackPosition - k0.fTrackPosition)); + float ratio = saturate((t - k0.fTrackPosition) / denom); + + S = lerp(k0.vScale, k1.vScale, ratio); + T = lerp(k0.vTranslation, k1.vTranslation, ratio); + R = QuatSlerp(k0.vRotation, k1.vRotation, ratio); } - g_LocalPosOutput[channel.BoneIndex] = result; - return; - - + if (bone == RootBoneIndex) + { + T = 0; + R = RootInitRot; + } } + +void SampleLocalTRS_Prev(uint bone, float t, out float3 S, out float4 R, out float3 T) +{ + Channel ch = g_PrevChannelBuffer[bone]; + + if (ch.KeyCount == 0) + { + S = float3(1, 1, 1); + R = float4(0, 0, 0, 1); + T = float3(0, 0, 0); + return; + } + + uint start = ch.StartIndex; + uint count = ch.KeyCount; + + if (count == 1) + { + KeyFrame k = g_PrevKeyFrameBuffer[start]; + S = k.vScale; + R = QuatNormalize(k.vRotation); + T = k.vTranslation; + } + else + { + uint i0 = FindKeyIndexPrev(start, count, t); + uint i1 = i0 + 1; + + KeyFrame k0 = g_PrevKeyFrameBuffer[start + i0]; + KeyFrame k1 = g_PrevKeyFrameBuffer[start + i1]; + + float denom = max(EPS, (k1.fTrackPosition - k0.fTrackPosition)); + float ratio = saturate((t - k0.fTrackPosition) / denom); + + S = lerp(k0.vScale, k1.vScale, ratio); + T = lerp(k0.vTranslation, k1.vTranslation, ratio); + R = QuatSlerp(k0.vRotation, k1.vRotation, ratio); + } + + if (bone == RootBoneIndex) + { + T = 0; + R = RootInitRot; + } +} + + +float4x4 SampleBlendedLocal(uint bone) +{ + float br = saturate(BlendRatio); + + if (br <= 0.0f) + return SampleLocalPrev(bone, PrevTime); + if (br >= 1.0f) + return SampleLocal(bone, CurrentTime); + + float3 sA, sB, tA, tB; + float4 rA, rB; + + SampleLocalTRS_Prev(bone, PrevTime, sA, rA, tA); + SampleLocalTRS_Cur(bone, CurrentTime, sB, rB, tB); + + float3 s = lerp(sA, sB, br); + float3 t = lerp(tA, tB, br); + float4 r = QuatSlerp(rA, rB, br); + + if (bone == RootBoneIndex) + { + t = 0; + r = RootInitRot; + } + + return MakeAffine(s, r, t); +} + +[numthreads(256, 1, 1)] +void CS_MAIN(uint3 DTid : SV_DispatchThreadID) +{ + uint globalBone = DTid.x; + if (globalBone >= (uint) BoneCount) + return; + + float4x4 localMat = SampleBlendedLocal(globalBone); + g_LocalPosOutput[globalBone].Local = localMat; + + float4x4 combined = localMat; + int p = g_ParentBuffer[globalBone]; + while (p != -1) + { + combined = mul(combined, SampleBlendedLocal((uint) p)); + p = g_ParentBuffer[p]; + } + + combined = mul(combined, PreTransformMatrix); + g_LocalPosOutput[globalBone].Combined = combined; + + for (uint local = 0; local < (uint) MeshBoneCount; ++local) + { + if (g_BoneRemap[local] == globalBone) + { + g_LocalPosOutput[local].LocalCombined = combined; + } + } +} + diff --git a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_NPC_PBR_Anim.hlsl b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_NPC_PBR_Anim.hlsl index 5d0bf49b5..702b009c7 100644 --- a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_NPC_PBR_Anim.hlsl +++ b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_NPC_PBR_Anim.hlsl @@ -1,7 +1,16 @@ #include "Engine_Shader_Defines.hlsli" +struct BoneOut +{ + row_major float4x4 Local; + row_major float4x4 Combined; + row_major float4x4 LocalCombined; + +}; float4x4 g_WorldMatrix, g_ViewMatrix, g_ProjMatrix; +matrix g_OffsetMatrix[256]; + int g_bRimLight; int g_bUseNormalMap; @@ -44,6 +53,7 @@ Texture2D g_Maya_Specular_ColorTexture; Texture2D g_Maya_Specular_RoughnessTexture; Texture2D g_AnisotropyTexture; +StructuredBuffer g_BoneBuffer : register(t26); Texture2D g_SurfaceParamsTexture; @@ -103,13 +113,19 @@ VS_OUT VS_MAIN(VS_IN In) { VS_OUT Out; - float fWeightW = 1.f - (In.vBlendWeight.x + In.vBlendWeight.y + In.vBlendWeight.z); - + float4 w = In.vBlendWeight; + float sumW = max(dot(w, 1.0f), 1e-6f); + w /= sumW; + matrix BoneMatrix = - mul(g_BoneMatrices[In.vBlendIndex.x], In.vBlendWeight.x) + - mul(g_BoneMatrices[In.vBlendIndex.y], In.vBlendWeight.y) + - mul(g_BoneMatrices[In.vBlendIndex.z], In.vBlendWeight.z) + - mul(g_BoneMatrices[In.vBlendIndex.w], fWeightW); + mul(g_OffsetMatrix[In.vBlendIndex.x], + g_BoneBuffer[In.vBlendIndex.x].LocalCombined) * w.x + + mul(g_OffsetMatrix[In.vBlendIndex.y], + g_BoneBuffer[In.vBlendIndex.y].LocalCombined) * w.y + + mul(g_OffsetMatrix[In.vBlendIndex.z], + g_BoneBuffer[In.vBlendIndex.z].LocalCombined) * w.z + + mul(g_OffsetMatrix[In.vBlendIndex.w], + g_BoneBuffer[In.vBlendIndex.w].LocalCombined) * w.w; vector vPosition = mul(vector(In.vPosition, 1.f), BoneMatrix); vector vNormal = mul(vector(In.vNormal, 0.f), BoneMatrix); @@ -135,13 +151,19 @@ VS_OUT VS_MAIN_OUTLINE_READ(VS_IN In) { VS_OUT Out; - float fWeightW = 1.f - (In.vBlendWeight.x + In.vBlendWeight.y + In.vBlendWeight.z); - + float4 w = In.vBlendWeight; + float sumW = max(dot(w, 1.0f), 1e-6f); + w /= sumW; + matrix BoneMatrix = - mul(g_BoneMatrices[In.vBlendIndex.x], In.vBlendWeight.x) + - mul(g_BoneMatrices[In.vBlendIndex.y], In.vBlendWeight.y) + - mul(g_BoneMatrices[In.vBlendIndex.z], In.vBlendWeight.z) + - mul(g_BoneMatrices[In.vBlendIndex.w], fWeightW); + mul(g_OffsetMatrix[In.vBlendIndex.x], + g_BoneBuffer[In.vBlendIndex.x].LocalCombined) * w.x + + mul(g_OffsetMatrix[In.vBlendIndex.y], + g_BoneBuffer[In.vBlendIndex.y].LocalCombined) * w.y + + mul(g_OffsetMatrix[In.vBlendIndex.z], + g_BoneBuffer[In.vBlendIndex.z].LocalCombined) * w.z + + mul(g_OffsetMatrix[In.vBlendIndex.w], + g_BoneBuffer[In.vBlendIndex.w].LocalCombined) * w.w; vector vPosition = mul(vector(In.vPosition, 1.f), BoneMatrix); vector vNormal = mul(vector(In.vNormal, 0.f), BoneMatrix); @@ -173,12 +195,19 @@ VS_OUT_SHADOW VS_MAIN_SHADOW(VS_IN In) { VS_OUT_SHADOW Out; - float fWeightW = 1.f - (In.vBlendWeight.x + In.vBlendWeight.y + In.vBlendWeight.z); - - matrix BoneMatrix = mul(g_BoneMatrices[In.vBlendIndex.x], In.vBlendWeight.x) + - mul(g_BoneMatrices[In.vBlendIndex.y], In.vBlendWeight.y) + - mul(g_BoneMatrices[In.vBlendIndex.z], In.vBlendWeight.z) + - mul(g_BoneMatrices[In.vBlendIndex.w], fWeightW); + float4 w = In.vBlendWeight; + float sumW = max(dot(w, 1.0f), 1e-6f); + w /= sumW; + + matrix BoneMatrix = + mul(g_OffsetMatrix[In.vBlendIndex.x], + g_BoneBuffer[In.vBlendIndex.x].LocalCombined) * w.x + + mul(g_OffsetMatrix[In.vBlendIndex.y], + g_BoneBuffer[In.vBlendIndex.y].LocalCombined) * w.y + + mul(g_OffsetMatrix[In.vBlendIndex.z], + g_BoneBuffer[In.vBlendIndex.z].LocalCombined) * w.z + + mul(g_OffsetMatrix[In.vBlendIndex.w], + g_BoneBuffer[In.vBlendIndex.w].LocalCombined) * w.w; vector vPosition = mul(vector(In.vPosition, 1.f), BoneMatrix); diff --git a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_VtxAnimMesh.hlsl b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_VtxAnimMesh.hlsl index 397cbd87c..70679fcb3 100644 --- a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_VtxAnimMesh.hlsl +++ b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_VtxAnimMesh.hlsl @@ -1,7 +1,15 @@ #include "Engine_Shader_Defines.hlsli" +struct BoneOut +{ + row_major float4x4 Local; + row_major float4x4 Combined; + row_major float4x4 LocalCombined; +}; + matrix g_WorldMatrix, g_ViewMatrix, g_ProjMatrix; +matrix g_OffsetMatrix[256]; int g_bRimLight; int g_bUseNormalMap; @@ -24,41 +32,45 @@ float g_fDisolveEdgeWidth; float4 g_vDisolveEdgeColor; float4 g_vCamPosition; -Texture2D g_DAOTexture; -Texture2D g_THVTexture; -Texture2D g_SurfaceParamsTexture; -Texture2D g_DeadDisolveTexture; -Texture2D g_DeadDisolveBurnTexture; float2 g_vSRVFlag; float3 g_vPBR_Flag; -Texture2D g_DiffuseTexture; -Texture2D g_SpecularTexture; -Texture2D g_AmbientTexture; -Texture2D g_EmissiveTexture; -Texture2D g_MossDiffuseTexture; -Texture2D g_NormalTexture; -Texture2D g_MossNormalTexture; -Texture2D g_NormalBlendTexture; -Texture2D g_SROBlendTexture; -Texture2D g_MROBlendTexture; -Texture2D g_ReflectionTexture; -Texture2D g_DiffuseBlend; -Texture2D g_MossSROTexture; -Texture2D g_MossMROTexture; -Texture2D g_MetalnessTexture; -Texture2D g_Diffuse_RoughnessTexture; -Texture2D g_AmbientOcclusionTexture; -Texture2D g_UnknownTexture; -Texture2D g_SheenTexture; -Texture2D g_ClearcoadTexture; -Texture2D g_TransmissionTexture; -Texture2D g_Maya_BaseTexture; -Texture2D g_Maya_SpecularTexture; -Texture2D g_Maya_Specular_ColorTexture; -Texture2D g_Maya_Specular_RoughnessTexture; -Texture2D g_AnisotropyTexture; +Texture2D g_DAOTexture : register(t0); +Texture2D g_THVTexture : register(t1); +Texture2D g_SurfaceParamsTexture : register(t2); +Texture2D g_DeadDisolveTexture : register(t3); +Texture2D g_DeadDisolveBurnTexture : register(t4); + +Texture2D g_DiffuseTexture : register(t5); +Texture2D g_SpecularTexture : register(t6); +Texture2D g_AmbientTexture : register(t7); +Texture2D g_EmissiveTexture : register(t8); +Texture2D g_MossDiffuseTexture : register(t9); +Texture2D g_NormalTexture : register(t10); +Texture2D g_MossNormalTexture : register(t11); +Texture2D g_NormalBlendTexture : register(t12); +Texture2D g_SROBlendTexture : register(t13); +Texture2D g_MROBlendTexture : register(t14); +Texture2D g_ReflectionTexture : register(t15); +Texture2D g_DiffuseBlend : register(t16); +Texture2D g_MossSROTexture : register(t17); +Texture2D g_MossMROTexture : register(t18); +Texture2D g_MetalnessTexture : register(t19); +Texture2D g_Diffuse_RoughnessTexture : register(t20); +Texture2D g_AmbientOcclusionTexture : register(t21); +Texture2D g_UnknownTexture : register(t22); +Texture2D g_SheenTexture : register(t23); +Texture2D g_ClearcoadTexture : register(t24); +Texture2D g_TransmissionTexture : register(t25); +Texture2D g_Maya_BaseTexture : register(t26); +Texture2D g_Maya_SpecularTexture : register(t27); +Texture2D g_Maya_Specular_ColorTexture : register(t28); +Texture2D g_Maya_Specular_RoughnessTexture : register(t29); +Texture2D g_AnisotropyTexture : register(t30); + + +StructuredBuffer g_BoneBuffer : register(t31); int g_iBinded_Texture[27]; @@ -74,6 +86,9 @@ float g_fUsingSurfaceParams; matrix g_BoneMatrices[512]; + + + struct VS_IN { float3 vPosition : POSITION; @@ -100,35 +115,45 @@ struct VS_OUT VS_OUT VS_MAIN(VS_IN In) { VS_OUT Out; - - float fWeightW = 1.f - (In.vBlendWeight.x + In.vBlendWeight.y + In.vBlendWeight.z); - + + float4 w = In.vBlendWeight; + float sumW = max(dot(w, 1.0f), 1e-6f); + w /= sumW; + matrix BoneMatrix = - mul(g_BoneMatrices[In.vBlendIndex.x], In.vBlendWeight.x) + - mul(g_BoneMatrices[In.vBlendIndex.y], In.vBlendWeight.y) + - mul(g_BoneMatrices[In.vBlendIndex.z], In.vBlendWeight.z) + - mul(g_BoneMatrices[In.vBlendIndex.w], fWeightW); - - vector vPosition = mul(vector(In.vPosition, 1.f), BoneMatrix); - vector vNormal = mul(vector(In.vNormal, 0.f), BoneMatrix); - vector vBinormal = mul(vector(In.vBinormal, 0.f), BoneMatrix); - vector vTangent = mul(vector(In.vTangent, 0.f), BoneMatrix); + mul(g_OffsetMatrix[In.vBlendIndex.x], + g_BoneBuffer[In.vBlendIndex.x].LocalCombined) * w.x + + mul(g_OffsetMatrix[In.vBlendIndex.y], + g_BoneBuffer[In.vBlendIndex.y].LocalCombined) * w.y + + mul(g_OffsetMatrix[In.vBlendIndex.z], + g_BoneBuffer[In.vBlendIndex.z].LocalCombined) * w.z + + mul(g_OffsetMatrix[In.vBlendIndex.w], + g_BoneBuffer[In.vBlendIndex.w].LocalCombined) * w.w; - matrix matWV, matWVP; - matWV = mul(g_WorldMatrix, g_ViewMatrix); - matWVP = mul(matWV, g_ProjMatrix); - Out.vPosition = mul(vPosition, matWVP); - Out.vNormal = normalize(mul(vNormal, g_WorldMatrix)).xyz; - Out.vBinormal = normalize(mul(vBinormal, g_WorldMatrix)).xyz; - Out.vTangent = normalize(mul(vTangent, g_WorldMatrix)).xyz; - Out.vTexcoord = In.vTexcoord; - Out.vWorldPos = mul(vPosition, g_WorldMatrix); - Out.vProjPos = Out.vPosition; + float4 skinnedPos = mul(float4(In.vPosition, 1.f), BoneMatrix); + float3 skinnedNormal = mul(float4(In.vNormal, 0.f), BoneMatrix).xyz; + float3 skinnedTangent = mul(float4(In.vTangent, 0.f), BoneMatrix).xyz; + float3 skinnedBinormal = mul(float4(In.vBinormal, 0.f), BoneMatrix).xyz; + + matrix matWV = mul(g_WorldMatrix, g_ViewMatrix); + matrix matWVP = mul(matWV, g_ProjMatrix); + + Out.vPosition = mul(skinnedPos, matWVP); + Out.vWorldPos = mul(skinnedPos, g_WorldMatrix); + + Out.vNormal = normalize(mul(float4(skinnedNormal, 0.f), g_WorldMatrix).xyz); + Out.vTangent = normalize(mul(float4(skinnedTangent, 0.f), g_WorldMatrix).xyz); + Out.vBinormal = normalize(mul(float4(skinnedBinormal, 0.f), g_WorldMatrix).xyz); + + Out.vTexcoord = In.vTexcoord; + Out.vProjPos = Out.vPosition; + return Out; } + struct VS_OUT_OUTLINE { float4 vPosition : SV_Position; @@ -144,13 +169,19 @@ VS_OUT_OUTLINE VS_MAIN_OUTLINE(VS_IN In) { VS_OUT_OUTLINE Out; - float fWeightW = 1.f - (In.vBlendWeight.x + In.vBlendWeight.y + In.vBlendWeight.z); - + float4 w = In.vBlendWeight; + float sumW = max(dot(w, 1.0f), 1e-6f); + w /= sumW; + matrix BoneMatrix = - mul(g_BoneMatrices[In.vBlendIndex.x], In.vBlendWeight.x) + - mul(g_BoneMatrices[In.vBlendIndex.y], In.vBlendWeight.y) + - mul(g_BoneMatrices[In.vBlendIndex.z], In.vBlendWeight.z) + - mul(g_BoneMatrices[In.vBlendIndex.w], fWeightW); + mul(g_OffsetMatrix[In.vBlendIndex.x], + g_BoneBuffer[In.vBlendIndex.x].LocalCombined) * w.x + + mul(g_OffsetMatrix[In.vBlendIndex.y], + g_BoneBuffer[In.vBlendIndex.y].LocalCombined) * w.y + + mul(g_OffsetMatrix[In.vBlendIndex.z], + g_BoneBuffer[In.vBlendIndex.z].LocalCombined) * w.z + + mul(g_OffsetMatrix[In.vBlendIndex.w], + g_BoneBuffer[In.vBlendIndex.w].LocalCombined) * w.w; vector vPosition = mul(vector(In.vPosition, 1.f), BoneMatrix); vector vNormal = mul(vector(In.vNormal, 0.f), BoneMatrix); @@ -240,12 +271,26 @@ VS_OUT_SHADOW VS_MAIN_SHADOW(VS_IN In) { VS_OUT_SHADOW Out; - float fWeightW = 1.f - (In.vBlendWeight.x + In.vBlendWeight.y + In.vBlendWeight.z); + //float fWeightW = 1.f - (In.vBlendWeight.x + In.vBlendWeight.y + In.vBlendWeight.z); - matrix BoneMatrix = mul(g_BoneMatrices[In.vBlendIndex.x], In.vBlendWeight.x) + - mul(g_BoneMatrices[In.vBlendIndex.y], In.vBlendWeight.y) + - mul(g_BoneMatrices[In.vBlendIndex.z], In.vBlendWeight.z) + - mul(g_BoneMatrices[In.vBlendIndex.w], fWeightW); + //matrix BoneMatrix = mul(g_BoneMatrices[In.vBlendIndex.x], In.vBlendWeight.x) + + // mul(g_BoneMatrices[In.vBlendIndex.y], In.vBlendWeight.y) + + // mul(g_BoneMatrices[In.vBlendIndex.z], In.vBlendWeight.z) + + // mul(g_BoneMatrices[In.vBlendIndex.w], fWeightW); + + float4 w = In.vBlendWeight; + float sumW = max(dot(w, 1.0f), 1e-6f); + w /= sumW; + + matrix BoneMatrix = + mul(g_OffsetMatrix[In.vBlendIndex.x], + g_BoneBuffer[In.vBlendIndex.x].LocalCombined) * w.x + + mul(g_OffsetMatrix[In.vBlendIndex.y], + g_BoneBuffer[In.vBlendIndex.y].LocalCombined) * w.y + + mul(g_OffsetMatrix[In.vBlendIndex.z], + g_BoneBuffer[In.vBlendIndex.z].LocalCombined) * w.z + + mul(g_OffsetMatrix[In.vBlendIndex.w], + g_BoneBuffer[In.vBlendIndex.w].LocalCombined) * w.w; /* ?ㅽ궎??*/ vector vPosition = mul(vector(In.vPosition, 1.f), BoneMatrix); diff --git a/Jusin154_Team3D/Editor/Private/Goblin.cpp b/Jusin154_Team3D/Editor/Private/Goblin.cpp index 25ae59676..3f74967be 100644 --- a/Jusin154_Team3D/Editor/Private/Goblin.cpp +++ b/Jusin154_Team3D/Editor/Private/Goblin.cpp @@ -146,10 +146,14 @@ HRESULT CGoblin::Render() } for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { return E_FAIL; } - if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) { return E_FAIL; } @@ -158,6 +162,8 @@ HRESULT CGoblin::Render() return E_FAIL; } + m_pModelCom->Bind_OutPut_SRV_VS(31, 0); + if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } @@ -198,13 +204,20 @@ HRESULT CGoblin::Render_Shadow(SHADOW eType) _uint iNumMeshes = m_pModelCom->Get_NumMeshes(); for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { return E_FAIL; } if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_ANIM::SHADOW)))) { return E_FAIL; } + m_pModelCom->Bind_OutPut_SRV_VS(31, 0); + if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } diff --git a/Jusin154_Team3D/Editor/Private/Goblin_Spector.cpp b/Jusin154_Team3D/Editor/Private/Goblin_Spector.cpp index e18299c42..bc00d8faf 100644 --- a/Jusin154_Team3D/Editor/Private/Goblin_Spector.cpp +++ b/Jusin154_Team3D/Editor/Private/Goblin_Spector.cpp @@ -116,7 +116,12 @@ HRESULT CGoblin_Spector::Render() _uint iShaderPass = ENUM_CLASS(SHADER_PASS_ANIM::SPECTOR); for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { return E_FAIL; } @@ -128,6 +133,8 @@ HRESULT CGoblin_Spector::Render() return E_FAIL; } + m_pModelCom->Bind_OutPut_SRV_VS(31, 0); + if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } diff --git a/Jusin154_Team3D/Editor/Private/Player.cpp b/Jusin154_Team3D/Editor/Private/Player.cpp index 67a100789..12dd623cd 100644 --- a/Jusin154_Team3D/Editor/Private/Player.cpp +++ b/Jusin154_Team3D/Editor/Private/Player.cpp @@ -155,17 +155,25 @@ HRESULT CPlayer::Render() for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { - return E_FAIL; - } - if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) { return E_FAIL; } + + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { + return E_FAIL; + } + if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_ANIM::DEFAULT)))) { return E_FAIL; } + m_pModelCom->Bind_OutPut_SRV_VS(31, 0); + if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } diff --git a/Jusin154_Team3D/Editor/Private/Troll.cpp b/Jusin154_Team3D/Editor/Private/Troll.cpp index 0365600e6..b87e9dbeb 100644 --- a/Jusin154_Team3D/Editor/Private/Troll.cpp +++ b/Jusin154_Team3D/Editor/Private/Troll.cpp @@ -189,7 +189,12 @@ HRESULT CTroll::Render() } for (_uint i = 0; i < iNumMeshes; i++) { - if (FAILED(m_pModelCom->Bind_BoneMatrices(i, m_pShaderCom, "g_BoneMatrices"))) { + if (FAILED(m_pShaderCom->Bind_Matrices( + "g_OffsetMatrix", + m_pModelCom->Get_OffsetMatrix(i).data(), + (_int)m_pModelCom->Get_OffsetMatrix(i).size() + ))) + { return E_FAIL; } @@ -201,6 +206,8 @@ HRESULT CTroll::Render() return E_FAIL; } + m_pModelCom->Bind_OutPut_SRV_VS(31, 0); + if (FAILED(m_pModelCom->Render(i))) { return E_FAIL; } diff --git a/Jusin154_Team3D/Editor/Private/Wand.cpp b/Jusin154_Team3D/Editor/Private/Wand.cpp index 36ee6d691..18a54edfe 100644 --- a/Jusin154_Team3D/Editor/Private/Wand.cpp +++ b/Jusin154_Team3D/Editor/Private/Wand.cpp @@ -43,16 +43,7 @@ HRESULT CWand::Initialize(void* pArg) void CWand::Priority_Update(_float fTimeDelta) { - _matrix socketMatrix = {}; - - socketMatrix = XMLoadFloat4x4(m_pSocketMatrices); - - for (int i = 0; i < 3; ++i) { - socketMatrix.r[i] = XMVector3Normalize(socketMatrix.r[i]); - } - - m_pTransformCom->Set_WorldMatrix(socketMatrix * XMLoadFloat4x4(m_pParentTransformCom->Get_WorldMatrixPtr())); - XMStoreFloat4x4(&m_pWandTipMatrix, XMLoadFloat4x4(m_pModelCom->Get_BoneMatrixPtr("Effect")) * m_pTransformCom->Get_XMWorldMatrix()); + #ifdef _DEBUG Describe_Entity(); @@ -68,6 +59,17 @@ void CWand::Update(_float fTimeDelta) void CWand::Late_Update(_float fTimeDelta) { + _matrix socketMatrix = {}; + + socketMatrix = XMLoadFloat4x4(m_pSocketMatrices); + + for (int i = 0; i < 3; ++i) { + socketMatrix.r[i] = XMVector3Normalize(socketMatrix.r[i]); + } + + m_pTransformCom->Set_WorldMatrix(socketMatrix * XMLoadFloat4x4(m_pParentTransformCom->Get_WorldMatrixPtr())); + XMStoreFloat4x4(&m_pWandTipMatrix, XMLoadFloat4x4(m_pModelCom->Get_BoneMatrixPtr("Effect")) * m_pTransformCom->Get_XMWorldMatrix()); + m_pGameInstance->Add_RenderGroup(RENDER::BLEND, this); } 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 523ae0eff..086caa1b2 100644 --- a/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl +++ b/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl @@ -1,5 +1,3 @@ -float PI = 3.141592; - struct KeyFrame { float3 vScale; @@ -17,104 +15,402 @@ struct Channel struct LocalPos { - float3 Scale; - float pad0; - - float4 Rotation; - - float3 Translation; - float pad1; + row_major float4x4 Local; + row_major float4x4 Combined; + row_major float4x4 LocalCombined; }; +struct BoneLocal +{ + row_major float4x4 BoneLocal; +}; StructuredBuffer g_KeyFrameBuffer : register(t0); StructuredBuffer g_ChannelBuffer : register(t1); +StructuredBuffer g_PrevKeyFrameBuffer : register(t2); +StructuredBuffer g_PrevChannelBuffer : register(t3); +StructuredBuffer g_ParentBuffer : register(t4); +StructuredBuffer g_BoneLocalBuffer : register(t5); +StructuredBuffer g_BoneRemap : register(t6); RWStructuredBuffer g_LocalPosOutput : register(u0); - cbuffer AnimCB : register(b0) { float CurrentTime; float Duration; - float Speed; + int MeshBoneCount; int BoneCount; + + int RootBoneIndex; + int padding1; + float PrevTime; + float BlendRatio; row_major float4x4 PreTransformMatrix; + float4 RootInitRot; }; -float4 quatSlerp(float4 q1, float4 q2, float t) +static const float EPS = 1e-6f; + +float4 QuatNormalize(float4 q) { - float cosTheta = dot(q1, q2); + return q * rsqrt(max(dot(q, q), EPS)); +} + +float4 QuatSlerp(float4 a, float4 b, float t) +{ + a = QuatNormalize(a); + b = QuatNormalize(b); + + float cosTheta = dot(a, b); if (cosTheta < 0.0f) { - q2 = -q2; + b = -b; cosTheta = -cosTheta; } if (cosTheta > 0.9995f) - return normalize(lerp(q1, q2, t)); + return QuatNormalize(lerp(a, b, t)); - float theta = acos(cosTheta); - float sinTheta = sin(theta); + float theta = acos(saturate(cosTheta)); + float sinTheta = max(sin(theta), EPS); - float w1 = sin((1.0f - t) * theta) / sinTheta; - float w2 = sin(t * theta) / sinTheta; + float w0 = sin((1.0f - t) * theta) / sinTheta; + float w1 = sin(t * theta) / sinTheta; - return q1 * w1 + q2 * w2; + return a * w0 + b * w1; +} + +float4x4 MakeAffine(float3 scale, float4 rot, float3 trans) +{ + rot = QuatNormalize(rot); + + float xx = rot.x * rot.x; + float yy = rot.y * rot.y; + float zz = rot.z * rot.z; + float xy = rot.x * rot.y; + float xz = rot.x * rot.z; + float yz = rot.y * rot.z; + float wx = rot.w * rot.x; + float wy = rot.w * rot.y; + float wz = rot.w * rot.z; + + float4x4 M; + + M._11 = (1 - 2 * (yy + zz)) * scale.x; + M._12 = (2 * (xy + wz)) * scale.x; + M._13 = (2 * (xz - wy)) * scale.x; + M._14 = 0; + + M._21 = (2 * (xy - wz)) * scale.y; + M._22 = (1 - 2 * (xx + zz)) * scale.y; + M._23 = (2 * (yz + wx)) * scale.y; + M._24 = 0; + + M._31 = (2 * (xz + wy)) * scale.z; + M._32 = (2 * (yz - wx)) * scale.z; + M._33 = (1 - 2 * (xx + yy)) * scale.z; + M._34 = 0; + + M._41 = trans.x; + M._42 = trans.y; + M._43 = trans.z; + M._44 = 1; + + return M; +} + +uint FindKeyIndexCur(uint start, uint count, float t) +{ + uint lo = 0; + uint hi = count - 1; + + float t0 = g_KeyFrameBuffer[start + 0].fTrackPosition; + if (t <= t0) + return 0; + + float tLast = g_KeyFrameBuffer[start + hi].fTrackPosition; + if (t >= tLast) + return hi - 1; + + while (hi - lo > 1) + { + uint mid = (lo + hi) >> 1; + float tm = g_KeyFrameBuffer[start + mid].fTrackPosition; + if (t < tm) + hi = mid; + else + lo = mid; + } + return lo; +} + +uint FindKeyIndexPrev(uint start, uint count, float t) +{ + uint lo = 0; + uint hi = count - 1; + + float t0 = g_PrevKeyFrameBuffer[start + 0].fTrackPosition; + if (t <= t0) + return 0; + + float tLast = g_PrevKeyFrameBuffer[start + hi].fTrackPosition; + if (t >= tLast) + return hi - 1; + + while (hi - lo > 1) + { + uint mid = (lo + hi) >> 1; + float tm = g_PrevKeyFrameBuffer[start + mid].fTrackPosition; + if (t < tm) + hi = mid; + else + lo = mid; + } + return lo; } -[numthreads(256, 1, 1)] -void CS_LocalSRT(uint3 DTID : SV_DispatchThreadID) +float3 GetRow3(float4 v) { - uint boneIndex = DTID.x; - if (boneIndex >= (uint) BoneCount) - return; - - float time = CurrentTime; - - Channel channel = g_ChannelBuffer[boneIndex]; + return v.xyz; +} - LocalPos result; - - uint firstIndex = channel.StartIndex; - uint keyCount = channel.KeyCount; - uint lastIndex = firstIndex + keyCount - 1; +float4x4 SampleLocalPrev(uint bone, float t) +{ + Channel ch = g_PrevChannelBuffer[bone]; + if (ch.KeyCount == 0) + return g_BoneLocalBuffer[bone].BoneLocal; - KeyFrame keyLast = g_KeyFrameBuffer[lastIndex]; + uint start = ch.StartIndex; + uint count = ch.KeyCount; - if (time >= keyLast.fTrackPosition) + if (count == 1) { - result.Scale = keyLast.vScale; - result.Rotation = keyLast.vRotation; - result.Translation = keyLast.vTranslation; - result.pad0 = result.pad1 = 0.0f; + KeyFrame k = g_PrevKeyFrameBuffer[start]; + float3 trans = k.vTranslation; + float4 rot = k.vRotation; + + if (bone == RootBoneIndex) + { + trans = 0; + rot = RootInitRot; + } + return MakeAffine(k.vScale, rot, trans); + } + + uint i0 = FindKeyIndexPrev(start, count, t); + uint i1 = i0 + 1; + + KeyFrame k0 = g_PrevKeyFrameBuffer[start + i0]; + KeyFrame k1 = g_PrevKeyFrameBuffer[start + i1]; + + float denom = max(EPS, (k1.fTrackPosition - k0.fTrackPosition)); + float ratio = saturate((t - k0.fTrackPosition) / denom); + + float3 scale = lerp(k0.vScale, k1.vScale, ratio); + float3 trans = lerp(k0.vTranslation, k1.vTranslation, ratio); + float4 rot = QuatSlerp(k0.vRotation, k1.vRotation, ratio); + + if (bone == RootBoneIndex) + { + trans = 0; + rot = RootInitRot; + } + return MakeAffine(scale, rot, trans); +} + +float4x4 SampleLocal(uint bone, float t) +{ + Channel ch = g_ChannelBuffer[bone]; + if (ch.KeyCount == 0) + return g_BoneLocalBuffer[bone].BoneLocal; + + uint start = ch.StartIndex; + uint count = ch.KeyCount; + + if (count == 1) + { + KeyFrame k = g_KeyFrameBuffer[start]; + float3 trans = k.vTranslation; + float4 rot = k.vRotation; + + if (bone == RootBoneIndex) + { + trans = 0; + rot = RootInitRot; + } + return MakeAffine(k.vScale, rot, trans); + } + + uint i0 = FindKeyIndexCur(start, count, t); + uint i1 = i0 + 1; + + KeyFrame k0 = g_KeyFrameBuffer[start + i0]; + KeyFrame k1 = g_KeyFrameBuffer[start + i1]; + + float denom = max(EPS, (k1.fTrackPosition - k0.fTrackPosition)); + float ratio = saturate((t - k0.fTrackPosition) / denom); + + float3 scale = lerp(k0.vScale, k1.vScale, ratio); + float3 trans = lerp(k0.vTranslation, k1.vTranslation, ratio); + float4 rot = QuatSlerp(k0.vRotation, k1.vRotation, ratio); + + if (bone == RootBoneIndex) + { + trans = 0; + rot = RootInitRot; + } + return MakeAffine(scale, rot, trans); +} +void SampleLocalTRS_Cur(uint bone, float t, out float3 S, out float4 R, out float3 T) +{ + Channel ch = g_ChannelBuffer[bone]; + + if (ch.KeyCount == 0) + { + S = float3(1, 1, 1); + R = float4(0, 0, 0, 1); + T = float3(0, 0, 0); + return; + } + + uint start = ch.StartIndex; + uint count = ch.KeyCount; + + if (count == 1) + { + KeyFrame k = g_KeyFrameBuffer[start]; + S = k.vScale; + R = QuatNormalize(k.vRotation); + T = k.vTranslation; } else { - for (uint i = 0; i < keyCount - 1; ++i) - { - KeyFrame Sour = g_KeyFrameBuffer[firstIndex + i]; - KeyFrame Dest = g_KeyFrameBuffer[firstIndex + i + 1]; + uint i0 = FindKeyIndexCur(start, count, t); + uint i1 = i0 + 1; - if (time >= Sour.fTrackPosition && time <= Dest.fTrackPosition) - { - float ratio = (time - Sour.fTrackPosition) / - (Dest.fTrackPosition - Sour.fTrackPosition); + KeyFrame k0 = g_KeyFrameBuffer[start + i0]; + KeyFrame k1 = g_KeyFrameBuffer[start + i1]; - result.Scale = lerp(Sour.vScale, Dest.vScale, ratio); - result.Rotation = quatSlerp(Sour.vRotation, Dest.vRotation, ratio); - result.Translation = lerp(Sour.vTranslation, Dest.vTranslation, ratio); - result.pad0 = result.pad1 = 0.0f; - break; - } - } + float denom = max(EPS, (k1.fTrackPosition - k0.fTrackPosition)); + float ratio = saturate((t - k0.fTrackPosition) / denom); + + S = lerp(k0.vScale, k1.vScale, ratio); + T = lerp(k0.vTranslation, k1.vTranslation, ratio); + R = QuatSlerp(k0.vRotation, k1.vRotation, ratio); } - g_LocalPosOutput[channel.BoneIndex] = result; - return; - - + if (bone == RootBoneIndex) + { + T = 0; + R = RootInitRot; + } } + +void SampleLocalTRS_Prev(uint bone, float t, out float3 S, out float4 R, out float3 T) +{ + Channel ch = g_PrevChannelBuffer[bone]; + + if (ch.KeyCount == 0) + { + S = float3(1, 1, 1); + R = float4(0, 0, 0, 1); + T = float3(0, 0, 0); + return; + } + + uint start = ch.StartIndex; + uint count = ch.KeyCount; + + if (count == 1) + { + KeyFrame k = g_PrevKeyFrameBuffer[start]; + S = k.vScale; + R = QuatNormalize(k.vRotation); + T = k.vTranslation; + } + else + { + uint i0 = FindKeyIndexPrev(start, count, t); + uint i1 = i0 + 1; + + KeyFrame k0 = g_PrevKeyFrameBuffer[start + i0]; + KeyFrame k1 = g_PrevKeyFrameBuffer[start + i1]; + + float denom = max(EPS, (k1.fTrackPosition - k0.fTrackPosition)); + float ratio = saturate((t - k0.fTrackPosition) / denom); + + S = lerp(k0.vScale, k1.vScale, ratio); + T = lerp(k0.vTranslation, k1.vTranslation, ratio); + R = QuatSlerp(k0.vRotation, k1.vRotation, ratio); + } + + if (bone == RootBoneIndex) + { + T = 0; + R = RootInitRot; + } +} + + +float4x4 SampleBlendedLocal(uint bone) +{ + float br = saturate(BlendRatio); + + if (br <= 0.0f) + return SampleLocalPrev(bone, PrevTime); + if (br >= 1.0f) + return SampleLocal(bone, CurrentTime); + + float3 sA, sB, tA, tB; + float4 rA, rB; + + SampleLocalTRS_Prev(bone, PrevTime, sA, rA, tA); + SampleLocalTRS_Cur(bone, CurrentTime, sB, rB, tB); + + float3 s = lerp(sA, sB, br); + float3 t = lerp(tA, tB, br); + float4 r = QuatSlerp(rA, rB, br); + + if (bone == RootBoneIndex) + { + t = 0; + r = RootInitRot; + } + + return MakeAffine(s, r, t); +} + +[numthreads(256, 1, 1)] +void CS_MAIN(uint3 DTid : SV_DispatchThreadID) +{ + uint globalBone = DTid.x; + if (globalBone >= (uint) BoneCount) + return; + + float4x4 localMat = SampleBlendedLocal(globalBone); + g_LocalPosOutput[globalBone].Local = localMat; + + float4x4 combined = localMat; + int p = g_ParentBuffer[globalBone]; + while (p != -1) + { + combined = mul(combined, SampleBlendedLocal((uint) p)); + p = g_ParentBuffer[p]; + } + + combined = mul(combined, PreTransformMatrix); + g_LocalPosOutput[globalBone].Combined = combined; + + for (uint local = 0; local < (uint) MeshBoneCount; ++local) + { + if (g_BoneRemap[local] == globalBone) + { + g_LocalPosOutput[local].LocalCombined = combined; + } + } +} + diff --git a/Jusin154_Team3D/Engine/Private/Animation.cpp b/Jusin154_Team3D/Engine/Private/Animation.cpp index f00f3e254..5337e4d9b 100644 --- a/Jusin154_Team3D/Engine/Private/Animation.cpp +++ b/Jusin154_Team3D/Engine/Private/Animation.cpp @@ -34,7 +34,7 @@ CAnimation::CAnimation(const CAnimation& rhs) SAFE_ADDREF(pChannel); } } -_bool CAnimation::Update_TransformationMatrices(const vector& Bones, LOCALPOS_DESC** pLocalPosArray, _bool bIsLoop, _float fTimeDelta, _bool bIsSpine, vector<_uint> BoneMask,_vector vector[3]) +_bool CAnimation::Update_TransformationMatrices(const vector& Bones, _bool bIsLoop, _float fTimeDelta, _bool bIsSpine, vector<_uint> BoneMask,_vector vector[3], _int RootBoneIndex) { m_fTempTrack += fTimeDelta * m_fAnimSpeed; m_fProgress = m_fTickPerSecond * fTimeDelta * m_fAnimSpeed; @@ -50,24 +50,16 @@ _bool CAnimation::Update_TransformationMatrices(const vector& Bone Depart_Animation(); m_fCurrentTrackPosition = m_fProgress; m_fTempTrack = 0.f; - ResetRootMotion(); - ProgressAnimation(Bones, pLocalPosArray, bIsSpine, BoneMask, vector); + ProgressAnimation(Bones, bIsSpine, BoneMask, vector, RootBoneIndex); return true; } } - ProgressAnimation(Bones, pLocalPosArray, bIsSpine, BoneMask, vector); + ProgressAnimation(Bones, bIsSpine, BoneMask, vector, RootBoneIndex); return false; } -void CAnimation::ResetRootMotion() -{ - for (auto& pChannel : m_Channels){ - pChannel->ResetRootMotion(); - } -} - void CAnimation::Depart_Animation() { m_fCurrentTrackPosition = 0.f; @@ -346,7 +338,6 @@ void CAnimation::CreateGPUData(ID3D11Device* pDevice) CreateKeyFrameBuffer(pDevice, keyframes); CreateChannelBuffer(pDevice, channels); - } @@ -429,14 +420,14 @@ HRESULT CAnimation::Initialize(const vector& Bones, const CModel* pModel return S_OK; } -void CAnimation::ProgressAnimation(const vector& Bones, LOCALPOS_DESC** pLocalPosArray, _bool bIsSpine,vector<_uint>BoneMask,_vector vector[3]) +void CAnimation::ProgressAnimation(const vector& Bones, _bool bIsSpine,vector<_uint>BoneMask,_vector vector[3], _int RootBoneIndex) { _uint iIndex = {}; if (m_vBoneTransformationMatrix.size() > 0) { m_vBoneTransformationMatrix.clear(); } for (auto& pChannel : m_Channels) { - pChannel->Update_TransformationMatirx(Bones, pLocalPosArray, m_fCurrentTrackPosition, &m_CurrentKeyFrameIndices[iIndex++], bIsSpine, BoneMask, vector); + pChannel->Update_TransformationMatirx(Bones, m_fCurrentTrackPosition, &m_CurrentKeyFrameIndices[iIndex++], bIsSpine, BoneMask, vector,RootBoneIndex); m_vBoneTransformationMatrix.push_back(pChannel->Get_BoneTransformationMatrix()); } } @@ -474,7 +465,7 @@ HRESULT CAnimation::CreateKeyFrameBuffer(ID3D11Device* pDevice,vectorCreateShaderResourceView(m_pChannelBuffer, &srvDesc, &m_pChannelSrv))) return E_FAIL; diff --git a/Jusin154_Team3D/Engine/Private/Channel.cpp b/Jusin154_Team3D/Engine/Private/Channel.cpp index 9619fed79..8ee67bc1e 100644 --- a/Jusin154_Team3D/Engine/Private/Channel.cpp +++ b/Jusin154_Team3D/Engine/Private/Channel.cpp @@ -113,115 +113,92 @@ HRESULT CChannel::Initialize(const vector& Bones, _uint iIndex) void CChannel::Update_TransformationMatirx( const vector& Bones, - LOCALPOS_DESC** pLocalPosArray, _float fCurrentTrackPosition, _uint* pCurrentKeyFrameIndex, _bool bIsSpine, vector<_uint> BoneMask, - _vector vector[3]) + _vector vector[3], + _int RootBoneIndex) { - - if (0.f == fCurrentTrackPosition) - *pCurrentKeyFrameIndex = 0; - - KEYFRAME LastKeyFrame = m_KeyFrames.back(); - - _vector vScale{}; - _vector vRotation{}; - _vector vTranslation{}; - - if (fCurrentTrackPosition >= LastKeyFrame.fTrackPosition) + if (m_iBoneIndex == RootBoneIndex ||Bones[m_iBoneIndex]->IsCPUEvaluated()) { - vScale = XMLoadFloat3(&LastKeyFrame.vScale); - vRotation = XMLoadFloat4(&LastKeyFrame.vRotation); - vTranslation = XMVectorSetW(XMLoadFloat3(&LastKeyFrame.vTranslation), 1.f); - } + if (0.f == fCurrentTrackPosition) + *pCurrentKeyFrameIndex = 0; - else - { - while (fCurrentTrackPosition >= m_KeyFrames[*pCurrentKeyFrameIndex + 1].fTrackPosition) - ++*pCurrentKeyFrameIndex; + KEYFRAME LastKeyFrame = m_KeyFrames.back(); - _float3 vSourScale{}, vDestScale{}; - _float4 vSourRotation{}, vDestRotation{}; - _float3 vSourTranslation{}, vDestTranslation{}; + _vector vScale{}; + _vector vRotation{}; + _vector vTranslation{}; - vSourScale = m_KeyFrames[*pCurrentKeyFrameIndex].vScale; - vDestScale = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vScale; - - vSourRotation = m_KeyFrames[*pCurrentKeyFrameIndex].vRotation; - vDestRotation = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vRotation; - - vSourTranslation = m_KeyFrames[*pCurrentKeyFrameIndex].vTranslation; - vDestTranslation = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vTranslation; - - _float fRatio = (fCurrentTrackPosition - m_KeyFrames[*pCurrentKeyFrameIndex].fTrackPosition) / - (m_KeyFrames[*pCurrentKeyFrameIndex + 1].fTrackPosition - m_KeyFrames[*pCurrentKeyFrameIndex].fTrackPosition); - - vScale = XMVectorLerp(XMLoadFloat3(&vSourScale), XMLoadFloat3(&vDestScale), fRatio); - vRotation = XMQuaternionSlerp(XMLoadFloat4(&vSourRotation), XMLoadFloat4(&vDestRotation), fRatio); - vTranslation = XMVectorSetW(XMVectorLerp(XMLoadFloat3(&vSourTranslation), XMLoadFloat3(&vDestTranslation), fRatio), 1.f); - - } - if (!bIsSpine) - { - m_IsUpper = BoneMask[m_iBoneIndex]; - m_ilayerIndex = m_IsUpper ? 1 : 0; - //LocalPos = pLocalPosArray[m_ilayerIndex][m_iBoneIndex]; - } - else - { - //LocalPos = pLocalPosArray[0][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")|| Bones[m_iBoneIndex]->Compare_Name("root")) - { - if (vector) + if (fCurrentTrackPosition >= LastKeyFrame.fTrackPosition) { - vector[0] = vScale; - vector[1] = vRotation; - vector[2] = vTranslation; + vScale = XMLoadFloat3(&LastKeyFrame.vScale); + vRotation = XMLoadFloat4(&LastKeyFrame.vRotation); + vTranslation = XMVectorSetW(XMLoadFloat3(&LastKeyFrame.vTranslation), 1.f); } - } - if (bIsSpine) - { - m_BoneTransformationMatrix = - XMMatrixAffineTransformation(vScale, XMVectorSet(0.f, 0.f, 0.f, 1.f), vRotation, vTranslation); + else + { + while (fCurrentTrackPosition >= m_KeyFrames[*pCurrentKeyFrameIndex + 1].fTrackPosition) + ++*pCurrentKeyFrameIndex; - Bones[m_iBoneIndex]->Set_TransformationMatrix(m_BoneTransformationMatrix); - } - else - { - if (m_ilayerIndex == 1) + _float3 vSourScale{}, vDestScale{}; + _float4 vSourRotation{}, vDestRotation{}; + _float3 vSourTranslation{}, vDestTranslation{}; + + vSourScale = m_KeyFrames[*pCurrentKeyFrameIndex].vScale; + vDestScale = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vScale; + + vSourRotation = m_KeyFrames[*pCurrentKeyFrameIndex].vRotation; + vDestRotation = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vRotation; + + vSourTranslation = m_KeyFrames[*pCurrentKeyFrameIndex].vTranslation; + vDestTranslation = m_KeyFrames[*pCurrentKeyFrameIndex + 1].vTranslation; + + _float fRatio = (fCurrentTrackPosition - m_KeyFrames[*pCurrentKeyFrameIndex].fTrackPosition) / + (m_KeyFrames[*pCurrentKeyFrameIndex + 1].fTrackPosition - m_KeyFrames[*pCurrentKeyFrameIndex].fTrackPosition); + + vScale = XMVectorLerp(XMLoadFloat3(&vSourScale), XMLoadFloat3(&vDestScale), fRatio); + vRotation = XMQuaternionSlerp(XMLoadFloat4(&vSourRotation), XMLoadFloat4(&vDestRotation), fRatio); + vTranslation = XMVectorSetW(XMVectorLerp(XMLoadFloat3(&vSourTranslation), XMLoadFloat3(&vDestTranslation), fRatio), 1.f); + + } + if (!bIsSpine) + { + m_IsUpper = BoneMask[m_iBoneIndex]; + m_ilayerIndex = m_IsUpper ? 1 : 0; + } + if (m_iBoneIndex == RootBoneIndex) + { + if (vector) + { + vector[0] = vScale; + vector[1] = vRotation; + vector[2] = vTranslation; + } + } + + if (bIsSpine) { m_BoneTransformationMatrix = XMMatrixAffineTransformation(vScale, XMVectorSet(0.f, 0.f, 0.f, 1.f), vRotation, vTranslation); Bones[m_iBoneIndex]->Set_TransformationMatrix(m_BoneTransformationMatrix); } + else + { + if (m_ilayerIndex == 1) + { + m_BoneTransformationMatrix = + XMMatrixAffineTransformation(vScale, XMVectorSet(0.f, 0.f, 0.f, 1.f), vRotation, vTranslation); + + Bones[m_iBoneIndex]->Set_TransformationMatrix(m_BoneTransformationMatrix); + } + } } - - } -void CChannel::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; -} - - KEYFRAME* CChannel::Get_Frame(_uint iIndex) { return &m_KeyFrames[iIndex]; diff --git a/Jusin154_Team3D/Engine/Private/ComputeShader.cpp b/Jusin154_Team3D/Engine/Private/ComputeShader.cpp index 1e16b428c..8a6d629df 100644 --- a/Jusin154_Team3D/Engine/Private/ComputeShader.cpp +++ b/Jusin154_Team3D/Engine/Private/ComputeShader.cpp @@ -113,6 +113,34 @@ vector CComputeShader::Dispatch(_uint iSRVIndex, _uint return StagingSubResources; } +void CComputeShader::Dispatch_ExternalSRV_UAV( + _uint srvStartSlot, _uint uavStartSlot, + const _float3& groupCount, + ID3D11ShaderResourceView** ppSRVs, _uint srvCount, + ID3D11UnorderedAccessView** ppUAVs, _uint uavCount, + ID3D11Buffer* pConstantBuffer) +{ + m_pContext->CSSetShader(m_pComputeShader, nullptr, 0); + if (pConstantBuffer) + m_pContext->CSSetConstantBuffers(0, 1, &pConstantBuffer); + + m_pContext->CSSetShaderResources(srvStartSlot, srvCount, ppSRVs); + m_pContext->CSSetUnorderedAccessViews(uavStartSlot, uavCount, ppUAVs, nullptr); + + m_pContext->Dispatch((UINT)groupCount.x, (UINT)groupCount.y, (UINT)groupCount.z); + + ID3D11ShaderResourceView* nullSRV[16] = {}; + ID3D11UnorderedAccessView* nullUAV[8] = {}; + m_pContext->CSSetShaderResources(srvStartSlot, srvCount, nullSRV); + m_pContext->CSSetUnorderedAccessViews(uavStartSlot, uavCount, nullUAV, nullptr); + + ID3D11Buffer* nullCB = nullptr; + m_pContext->CSSetConstantBuffers(0, 1, &nullCB); + m_pContext->CSSetShader(nullptr, nullptr, 0); +} + + + void CComputeShader::Bind_SRV(_uint iIndex) { m_pContext->CSSetShaderResources(iIndex, // 시작슬롯 번호 diff --git a/Jusin154_Team3D/Engine/Private/Mesh.cpp b/Jusin154_Team3D/Engine/Private/Mesh.cpp index 7578b974e..81f001606 100644 --- a/Jusin154_Team3D/Engine/Private/Mesh.cpp +++ b/Jusin154_Team3D/Engine/Private/Mesh.cpp @@ -23,8 +23,9 @@ HRESULT CMesh::Bind_BoneMatrices(const vector& Bones, CShader* pSh for (size_t i = 0; i < m_iNumBones; ++i) { XMStoreFloat4x4(&m_pBoneMatrices[i], - XMLoadFloat4x4(&m_offsetMatrices[i]) * Bones[m_BoneIndices[i]]->Get_CombinedTransformationMatrix()); + /*XMLoadFloat4x4(&m_offsetMatrices[i]) **/ Bones[m_BoneIndices[i]]->Get_CombinedTransformationMatrix()); } + if (0 == m_iNumBones) { return S_OK; } @@ -341,6 +342,7 @@ HRESULT CMesh::Ready_VertexBuffer_For_Anim(const CModel* pModel, SaveMesh* _Save pVertices[i].vTexcoord = _float2(0.f, 0.f); } + m_iNumBones = (_uint)_SaveMesh->Bones.size(); m_offsetMatrices.reserve(m_iNumBones); @@ -363,6 +365,7 @@ HRESULT CMesh::Ready_VertexBuffer_For_Anim(const CModel* pModel, SaveMesh* _Save if (-1 == iBoneIndex) return E_FAIL; + m_BoneRemap.push_back((_uint)iBoneIndex); m_BoneIndices.push_back(iBoneIndex); m_offsetMatrices.push_back(OffsetMatrix); @@ -409,12 +412,43 @@ HRESULT CMesh::Ready_VertexBuffer_For_Anim(const CModel* pModel, SaveMesh* _Save if (FAILED(m_pDevice->CreateBuffer(&VBDesc, &InitialVBData, &m_pVB))) return E_FAIL; + Create_BoneRemapBuffer(); + Safe_Delete_Array(pVertices); return S_OK; } +HRESULT CMesh::Create_BoneRemapBuffer() +{ + D3D11_BUFFER_DESC desc{}; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.ByteWidth = sizeof(_uint) * (_uint)m_BoneRemap.size(); + desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + desc.CPUAccessFlags = 0; + desc.StructureByteStride = sizeof(_uint); + desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; + + D3D11_SUBRESOURCE_DATA init{}; + init.pSysMem = m_BoneRemap.data(); + + m_pDevice->CreateBuffer(&desc, &init, &m_pBoneRemapBuffer); + + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc{}; + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; + srvDesc.Format = DXGI_FORMAT_UNKNOWN; + srvDesc.Buffer.FirstElement = 0; + srvDesc.Buffer.NumElements = (_uint)m_BoneRemap.size(); + + m_pDevice->CreateShaderResourceView( + m_pBoneRemapBuffer, + &srvDesc, + &m_pBoneRemapSRV); + + return S_OK; +} + HRESULT CMesh::Initialize(void* pArg) { @@ -642,6 +676,8 @@ void CMesh::Free() { __super::Free(); + SAFE_RELEASE(m_pBoneRemapBuffer); + SAFE_RELEASE(m_pBoneRemapSRV); Safe_Delete_Array(m_pBoneMatrices); } #ifdef _DEBUG diff --git a/Jusin154_Team3D/Engine/Private/Model.cpp b/Jusin154_Team3D/Engine/Private/Model.cpp index b9fa4019d..edd772521 100644 --- a/Jusin154_Team3D/Engine/Private/Model.cpp +++ b/Jusin154_Team3D/Engine/Private/Model.cpp @@ -146,14 +146,6 @@ _bool CModel::Play_Animation(_float fTimeDelta, CTransform* pTransform) _bool CModel::Play_Anim(_float fTimeDelta, CTransform* pTransform) { - /*if (m_bLoopRestarted) - { - m_vPrevRootPos = { 0,0,0 }; - m_bLoopRestarted = false; - }*/ - - //ComputeAnimation(m_iCurrentAnimIndex); - if (m_iPreAnimIndex >= 0 && m_iPreAnimIndex != m_iCurrentAnimIndex) { m_fBlendTime += fTimeDelta; @@ -165,9 +157,7 @@ _bool CModel::Play_Anim(_float fTimeDelta, CTransform* pTransform) CAnimation* pCurAnim = m_Animations[m_iCurrentAnimIndex]; CAnimation* pPreAnim = m_Animations[m_iPreAnimIndex]; - m_bIsFinishedAnim = pCurAnim->Update_TransformationMatrices(m_Bones, m_pLocalPos, m_bIsLoop, fTimeDelta, true, m_iBoneMask, m_vector); - - pCurAnim->InterpAnim(pPreAnim, m_Bones, m_fRatio); + m_bIsFinishedAnim = pCurAnim->Update_TransformationMatrices(m_Bones, m_bIsLoop, fTimeDelta, true, m_iBoneMask, m_vector,m_iRootBoneIndex); if (m_fRatio >= 1.f) { @@ -177,11 +167,17 @@ _bool CModel::Play_Anim(_float fTimeDelta, CTransform* pTransform) } else { - m_bIsFinishedAnim = m_Animations[m_iCurrentAnimIndex]->Update_TransformationMatrices(m_Bones, m_pLocalPos, m_bIsLoop, fTimeDelta, true, m_iBoneMask, m_vector); + m_bIsFinishedAnim = m_Animations[m_iCurrentAnimIndex]->Update_TransformationMatrices(m_Bones, m_bIsLoop, fTimeDelta, true, m_iBoneMask, m_vector, m_iRootBoneIndex); m_iPreAnimIndex = m_iCurrentAnimIndex; } - + + for (_uint i = 0; i < Get_NumMeshes(); i++) + { + ComputeAnimation(m_iCurrentAnimIndex, i); + } + + if (m_bIsFinishedAnim) { if (m_bIsLoop) @@ -208,25 +204,29 @@ _bool CModel::Play_Anim(_float fTimeDelta, CTransform* pTransform) m_bInitialRootRotSaved = false; } - for (auto& pBone : m_Bones) + m_Bones[m_iRootBoneIndex]->Update_CombinedTransformationMatrix(m_Bones, XMLoadFloat4x4(&m_PreTransformMatrix)); + + for (_uint i = 0; i < m_Bones.size(); ++i) { - pBone->Update_CombinedTransformationMatrix(m_Bones, XMLoadFloat4x4(&m_PreTransformMatrix)); + if (m_Bones[i]->IsCPUEvaluated()) + { + if (i == m_iRootBoneIndex) + continue; + + m_Bones[i]->Update_CombinedTransformationMatrix( + m_Bones, + XMLoadFloat4x4(&m_PreTransformMatrix) + ); + } } + BeginFrame(); + return m_bIsFinishedAnim; } _bool CModel::Play_Dual_Anim(_float fTimeDelta, CTransform* pTransform) { - /*if (m_bLoopRestarted) - { - m_vPrevRootPos = { 0,0,0 }; - m_bLoopRestarted = false; - }*/ - - //ComputeAnimation(m_iCurrentAnimIndex); - //ComputeAnimation_Second(m_iCurrSecondAnimIndex); - if (m_iPreAnimIndex >= 0 && m_iPreAnimIndex != m_iCurrentAnimIndex) { m_fBlendTime += fTimeDelta; @@ -242,12 +242,10 @@ _bool CModel::Play_Dual_Anim(_float fTimeDelta, CTransform* pTransform) CAnimation* pSecondAnim = m_Animations[m_iCurrSecondAnimIndex]; - m_bIsFinishedAnim = pCurAnim->Update_TransformationMatrices(m_Bones, m_pLocalPos, m_bIsLoop, fTimeDelta, true, m_iBoneMask, m_vector); - pCurAnim->InterpAnim(pPreAnim, m_Bones, m_fRatio); + m_bIsFinishedAnim = pCurAnim->Update_TransformationMatrices(m_Bones, m_bIsLoop, fTimeDelta, true, m_iBoneMask, m_vector, m_iRootBoneIndex); - m_bIsSecondFinishedAnim = pSecondAnim->Update_TransformationMatrices(m_Bones, m_pLocalPos, m_bIsSecondLoop, fTimeDelta, false, m_iBoneMask); + m_bIsSecondFinishedAnim = pSecondAnim->Update_TransformationMatrices(m_Bones, m_bIsSecondLoop, fTimeDelta, false, m_iBoneMask,nullptr, m_iRootBoneIndex); - pSecondAnim->InterpSecondAnim(pCurAnim, m_iBoneMask, m_Bones, m_fSecondRatio); if (m_fRatio >= 1.f) { m_iPreAnimIndex = m_iCurrentAnimIndex; @@ -275,9 +273,9 @@ _bool CModel::Play_Dual_Anim(_float fTimeDelta, CTransform* pTransform) } - m_bIsFinishedAnim = m_Animations[m_iCurrentAnimIndex]->Update_TransformationMatrices(m_Bones, m_pLocalPos, m_bIsLoop, fTimeDelta, true, m_iBoneMask, m_vector); + m_bIsFinishedAnim = m_Animations[m_iCurrentAnimIndex]->Update_TransformationMatrices(m_Bones, m_bIsLoop, fTimeDelta, true, m_iBoneMask, m_vector); - m_bIsSecondFinishedAnim = m_Animations[m_iCurrSecondAnimIndex]->Update_TransformationMatrices(m_Bones, m_pLocalPos, m_bIsSecondLoop, fTimeDelta, false, m_iBoneMask); + m_bIsSecondFinishedAnim = m_Animations[m_iCurrSecondAnimIndex]->Update_TransformationMatrices(m_Bones, m_bIsSecondLoop, fTimeDelta, false, m_iBoneMask); m_Animations[m_iCurrSecondAnimIndex]->InterpSecondAnim(m_Animations[m_iCurrentAnimIndex], m_iBoneMask, m_Bones, m_fSecondRatio); m_iPreAnimIndex = m_iCurrentAnimIndex; @@ -338,11 +336,20 @@ _bool CModel::Play_Dual_Anim(_float fTimeDelta, CTransform* pTransform) } } + m_Bones[m_iRootBoneIndex]->Update_CombinedTransformationMatrix(m_Bones, XMLoadFloat4x4(&m_PreTransformMatrix)); - - for (auto& pBone : m_Bones) + for (_uint i = 0; i < m_Bones.size(); ++i) { - pBone->Update_CombinedTransformationMatrix(m_Bones, XMLoadFloat4x4(&m_PreTransformMatrix)); + if (m_Bones[i]->IsCPUEvaluated()) + { + if (i == m_iRootBoneIndex) + continue; + + m_Bones[i]->Update_CombinedTransformationMatrix( + m_Bones, + XMLoadFloat4x4(&m_PreTransformMatrix) + ); + } } return m_bIsFinishedAnim; @@ -364,8 +371,8 @@ void CModel::Set_AnimationIndex(_uint iIndex, _bool isLoop, _float fAmount, _boo { m_iPreAnimIndex = m_iCurrentAnimIndex; - m_Animations[m_iCurrentAnimIndex]->Depart_Animation(); - m_Animations[m_iCurrentAnimIndex]->Set_AnimSpeed(1.f); + /* m_Animations[m_iCurrentAnimIndex]->Depart_Animation(); + m_Animations[m_iCurrentAnimIndex]->Set_AnimSpeed(1.f);*/ } m_fBlendTime = 0.f; @@ -562,19 +569,47 @@ void CModel::Initialize_RootBone() } } -const _float4x4* CModel::Get_BoneMatrixPtr(const _char* pBoneName) const +void CModel::BeginFrame() { - vector::const_iterator iter = find_if(m_Bones.begin(), m_Bones.end(), [&](CBone* pBone)->_bool - { - if (true == pBone->Compare_Name(pBoneName)) - return true; + fill(m_CPUBoneMask.begin(), m_CPUBoneMask.end(), false); +} - return false; - }); +vector<_float4x4> CModel::Get_OffsetMatrix(_int iIndex) +{ + return m_Meshes[iIndex]->Get_OffsetMatrix(); +} + +void CModel::Apply_CPUMask_ToBones() +{ + for (size_t i = 0; i < m_Bones.size(); ++i) + m_Bones[i]->SetCPUEvaluated(m_CPUBoneMask[i]); +} - return (*iter)->Get_CombinedTransformationMatrixPtr(); +void CModel::Mark_CPUChain(_int boneIdx) +{ + while (boneIdx >= 0) + { + if (m_CPUBoneMask[boneIdx]) + break; + m_CPUBoneMask[boneIdx] = true; + boneIdx = m_Parent[boneIdx]; + } +} + +const _float4x4* CModel::Get_BoneMatrixPtr(const _char* pBoneName) +{ + _int boneIdx = Get_BoneIndex(pBoneName); + + if (boneIdx < 0) + return nullptr; + + Mark_CPUChain(boneIdx); + + Apply_CPUMask_ToBones(); + + return m_Bones[boneIdx]->Get_CombinedTransformationMatrixPtr(); } _matrix CModel::Get_BoneMatrix(const _char* pBoneName) const @@ -587,7 +622,6 @@ _matrix CModel::Get_BoneMatrix(const _char* pBoneName) const return false; }); - return (*iter)->Get_CombinedTransformationMatrix(); } @@ -1334,37 +1368,6 @@ HRESULT CModel::Assimp_Model_Load(const _char* pModelFilePath, MODEL eType, _fma #endif // EDITOR_PROJECT - - -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::InItialize_BoneIndex() { for (_uint i = 0; i < (_uint)m_Bones.size(); i++) @@ -1428,14 +1431,57 @@ void CModel::Initialize_BoneMasks() } } +HRESULT CModel::Create_ComputeShader() +{ + _uint CS_InputStrides[] = { + sizeof(KEYFRAME_DESC), // 키프레임 + sizeof(CHANNEL_DESC), // 채널 + sizeof(KEYFRAME_DESC), // 이전애님 키프레임 + sizeof(CHANNEL_DESC), // 이전애님 채널 + sizeof(int), // 부모 인덱스 + sizeof(_float4x4), // 로컬좌표 + sizeof(_uint) + }; + + _uint CS_OutputStrides[] = { + sizeof(BONE_DESC), + }; + + CComputeShader::CS_INFO CS_Desc = {}; + + CS_Desc.iNumElement = (_uint)m_Bones.size(); + CS_Desc.iNumInputBuffer = 7; + CS_Desc.iNumOutputBuffer = 1; + + CS_Desc.iInputStructStride = CS_InputStrides; + CS_Desc.iOutputStructStride = CS_OutputStrides; + + m_pComputeShader = (CComputeShader*)m_pGameInstance->Clone_Asset_Prototype(g_iStaticLevel, TEXT("CS_Model"), &CS_Desc, nullptr); + + if (nullptr == m_pComputeShader) { + return E_FAIL; + } + + return S_OK; +} + +HRESULT CModel::Create_Temp() +{ + for (auto& anim : m_Animations) + { + anim->CreateGPUData(m_pDevice); + } + return S_OK; +} + HRESULT CModel::Create_ParentVB() { D3D11_BUFFER_DESC desc{}; desc.Usage = D3D11_USAGE_DEFAULT; - desc.ByteWidth = (_int)sizeof(PARENT_DESC) * (_uint)m_Bones.size(); + desc.ByteWidth = sizeof(_int) * (_uint)m_Bones.size(); desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; desc.CPUAccessFlags = 0; - desc.StructureByteStride = (_int)sizeof(PARENT_DESC); + desc.StructureByteStride = sizeof(_int); desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; D3D11_SUBRESOURCE_DATA init{}; @@ -1443,9 +1489,189 @@ HRESULT CModel::Create_ParentVB() m_pDevice->CreateBuffer(&desc, &init, &m_pParentBuffer); + return S_OK; +} + +HRESULT CModel::Create_BoneLocalVB() +{ + D3D11_BUFFER_DESC desc{}; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.ByteWidth = sizeof(_float4x4) * (_uint)m_Bones.size(); + desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + desc.CPUAccessFlags = 0; + desc.StructureByteStride = sizeof(_float4x4); + desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; + + D3D11_SUBRESOURCE_DATA init{}; + init.pSysMem = m_BoneLocal.data(); + + m_pDevice->CreateBuffer(&desc, &init, &m_pBoneLocalBuffer); return S_OK; } + +HRESULT CModel::Create_BoneMatrixVB() +{ + _uint iCount = (_uint)m_Bones.size(); + _uint iStride = sizeof(BONE_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_pBoneMatrixBuffer); + + + D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc{}; + uavDesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; + uavDesc.Format = DXGI_FORMAT_UNKNOWN; + uavDesc.Buffer.FirstElement = 0; + uavDesc.Buffer.NumElements = (_uint)m_Bones.size(); + + m_pDevice->CreateUnorderedAccessView( + m_pBoneMatrixBuffer, + &uavDesc, + &m_pBoneMatrixUAV + ); + + + return S_OK; +} + + +HRESULT CModel::Create_Const() +{ + + D3D11_BUFFER_DESC cbDesc = {}; + cbDesc.Usage = D3D11_USAGE_DYNAMIC; + cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; + cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + cbDesc.ByteWidth = sizeof(ANIMSTATE_DESC); + + D3D11_SUBRESOURCE_DATA CBInitialDesc = {}; + + if (FAILED(m_pDevice->CreateBuffer(&cbDesc, nullptr, &m_pConstantBuffer))) + return E_FAIL; + + return S_OK; +} + +HRESULT CModel::Create_ParentSrv() +{ + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; + srvDesc.Format = DXGI_FORMAT_UNKNOWN; + srvDesc.Buffer.FirstElement = 0; + srvDesc.Buffer.NumElements = (_uint)m_Bones.size(); + + if (FAILED(m_pDevice->CreateShaderResourceView(m_pParentBuffer, &srvDesc, &m_pParentSRV))) + return E_FAIL; + + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc1 = {}; + srvDesc1.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; + srvDesc1.Format = DXGI_FORMAT_UNKNOWN; + srvDesc1.Buffer.FirstElement = 0; + srvDesc1.Buffer.NumElements = (_uint)m_Bones.size(); + + if (FAILED(m_pDevice->CreateShaderResourceView(m_pBoneMatrixBuffer, &srvDesc1, &m_pBoneMatrixSRV))) + return E_FAIL; + + return S_OK; +} + +HRESULT CModel::Create_BoneLocalSrv() +{ + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; + srvDesc.Format = DXGI_FORMAT_UNKNOWN; + srvDesc.Buffer.FirstElement = 0; + srvDesc.Buffer.NumElements = (_uint)m_Bones.size(); + + if (FAILED(m_pDevice->CreateShaderResourceView(m_pBoneLocalBuffer, &srvDesc, &m_pBoneLocalSRV))) + return E_FAIL; + + return S_OK; +} + +void CModel::ComputeAnimation(_uint AnimIndex,_uint MeshIndex) +{ + D3D11_MAPPED_SUBRESOURCE ConstantSubResource = {}; + + if (SUCCEEDED(m_pContext->Map(m_pConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &ConstantSubResource))) + { + ANIMSTATE_DESC* pDesc = static_cast(ConstantSubResource.pData); + + auto* anim = m_Animations[AnimIndex]; + pDesc->CurrentTime = anim->Get_CurrentTrackPosition(); + pDesc->Duration = anim->Get_Duration(); + pDesc->MeshBoneCount = m_Meshes[MeshIndex]->Get_NumBone(); + pDesc->BoneCount = (_uint)m_Bones.size(); + pDesc->RootBoneIndex = m_iRootBoneIndex; + pDesc->PrevTime = m_Animations[m_iPreAnimIndex]->Get_CurrentTrackPosition(); + pDesc->BlendRatio = m_fRatio; + pDesc->PreTransformMatrix = m_PreTransformMatrix; + pDesc->RootInitRot = m_vInitialRootRot; + m_pContext->Unmap(m_pConstantBuffer, 0); + } + + if (m_pComputeShader == nullptr) + return; + + _uint iGroupCountX = (_uint)(m_Bones.size() + 255) / 256; + + ID3D11Buffer* CSBuffers[] = + { + m_Animations[AnimIndex]->Get_KeyFrameBuffer(), + m_Animations[AnimIndex]->Get_ChannelBuffer(), + m_Animations[m_iPreAnimIndex]->Get_KeyFrameBuffer(), + m_Animations[m_iPreAnimIndex]->Get_ChannelBuffer(), + m_pParentBuffer, + m_pBoneLocalBuffer, + m_Meshes[MeshIndex]->Get_BoneRemapBuffer() + }; + + auto* anim = m_Animations[AnimIndex]; + ID3D11ShaderResourceView* srvs[] = + { + anim->Get_KeyFrameSrv(), + anim->Get_ChannelSrv(), + m_Animations[m_iPreAnimIndex]->Get_KeyFrameSrv(), + m_Animations[m_iPreAnimIndex]->Get_ChannelSrv(), + m_pParentSRV, + m_pBoneLocalSRV, + m_Meshes[MeshIndex]->Get_BoneRemapSRV() + }; + + ID3D11UnorderedAccessView* uavs[] = + { + m_pBoneMatrixUAV + }; + + m_pComputeShader->Dispatch_ExternalSRV_UAV( + 0, + 0, + _float3((_float)iGroupCountX, 1.f, 1.f), + srvs, + 7, + uavs, + 1, + m_pConstantBuffer + ); +} + + +void CModel::Bind_OutPut_SRV_VS(_uint iIndex, _uint iBufferIndex) +{ + m_pContext->VSSetShaderResources(iIndex, + 1, // 버퍼 개수 + &m_pBoneMatrixSRV); +} + + #ifdef _DEBUG HRESULT CModel::Initialize_Prototype(MODEL eType, const _char* pModelFilePath, _fmatrix PreTransformMatrix) { @@ -1878,23 +2104,33 @@ HRESULT CModel::Initialize(void* pArg) if (m_eType == MODEL::ANIM || m_eType == MODEL::PBR_ANIM || m_eType == MODEL::ANIM_LOCAL) { + m_CPUBoneMask.resize(m_Bones.size(), false); Initialize_RootBone(); InItialize_BoneIndex(); Initialize_BoneMasks(); - /*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(); + m_Parent[i] = m_Bones[i]->Get_ParentBoneIndex(); } - if (FAILED(Create_CS())) - return E_FAIL; + m_BoneLocal.resize(m_Bones.size()); + for (size_t i = 0; i < (_uint)m_Bones.size(); i++) + { + m_BoneLocal[i] = m_Bones[i]->Get_TransformationMatrix(); + } - Create_Con(); - Create_LocalPosVB(); - Create_ParentVB();*/ + Create_Const(); + Create_Temp(); + Create_BoneMatrixVB(); + Create_ParentVB(); + Create_BoneLocalVB(); + Create_ParentSrv(); + Create_BoneLocalSrv(); + + if (FAILED(Create_ComputeShader())) + return E_FAIL; } @@ -2005,7 +2241,12 @@ void CModel::Free() SAFE_RELEASE(m_pComputeShader); SAFE_RELEASE(m_pConstantBuffer); SAFE_RELEASE(m_pParentBuffer); - SAFE_RELEASE(m_pLocalPosBuffer); + SAFE_RELEASE(m_pBoneLocalBuffer); + SAFE_RELEASE(m_pBoneMatrixBuffer); + SAFE_RELEASE(m_pParentSRV); + SAFE_RELEASE(m_pBoneLocalSRV); + SAFE_RELEASE(m_pBoneMatrixSRV); + SAFE_RELEASE(m_pBoneMatrixUAV); for (auto& pAnimation : m_Animations) { SAFE_RELEASE(pAnimation); diff --git a/Jusin154_Team3D/Engine/Private/Prototype_Manager.cpp b/Jusin154_Team3D/Engine/Private/Prototype_Manager.cpp index b45e90203..aa2f072f0 100644 --- a/Jusin154_Team3D/Engine/Private/Prototype_Manager.cpp +++ b/Jusin154_Team3D/Engine/Private/Prototype_Manager.cpp @@ -149,6 +149,13 @@ HRESULT CPrototype_Manager::Ready_EngineAssets() } + if (FAILED(Add_Asset_Prototype(g_iStaticLevel, TEXT("CS_Model"), + CComputeShader::Create(m_pDevice, m_pContext, + L"../Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl", "CS_MAIN")))) { + return E_FAIL; + + } + #pragma endregion return S_OK; diff --git a/Jusin154_Team3D/Engine/Public/Animation.h b/Jusin154_Team3D/Engine/Public/Animation.h index 11b20fbfc..67e5283c5 100644 --- a/Jusin154_Team3D/Engine/Public/Animation.h +++ b/Jusin154_Team3D/Engine/Public/Animation.h @@ -11,9 +11,8 @@ class ENGINE_DLL CAnimation : public CBase CAnimation(const CAnimation& rhs); virtual ~CAnimation() = default; public: - _bool Update_TransformationMatrices(const vector& Bones, LOCALPOS_DESC** pLocalPosArray, _bool bIsLoop, _float fTimeDelta, _bool bIsSpine, vector<_uint> BoneMask,_vector vector[3] = nullptr); - void ProgressAnimation(const vector& Bones,LOCALPOS_DESC** pLocalPosArray, _bool bIsSpine, vector<_uint> BoneMask, _vector vector[3]); - void ResetRootMotion(); + _bool Update_TransformationMatrices(const vector& Bones, _bool bIsLoop, _float fTimeDelta, _bool bIsSpine, vector<_uint> BoneMask,_vector vector[3] = nullptr, _int RootBoneIndex = -1); + void ProgressAnimation(const vector& Bones, _bool bIsSpine, vector<_uint> BoneMask, _vector vector[3], _int RootBoneIndex); void Depart_Animation(); void Set_AnimPause(_bool bValue) { m_bPause = bValue; } _float Get_AnimProgressRatio(); @@ -38,6 +37,7 @@ class ENGINE_DLL CAnimation : public CBase _float Get_AnimSpeed() { return m_fAnimSpeed; } _uint Get_ChannelCount() { return m_iNumChannels; } + _uint Get_KeyFrameCount() { return m_iKeyframeCount; } _float Get_Duration() { return m_fDuration; } ID3D11Buffer* Get_KeyFrameBuffer() { return m_pKeyFrameBuffer; } diff --git a/Jusin154_Team3D/Engine/Public/Bone.h b/Jusin154_Team3D/Engine/Public/Bone.h index 300bc6680..83c6f4236 100644 --- a/Jusin154_Team3D/Engine/Public/Bone.h +++ b/Jusin154_Team3D/Engine/Public/Bone.h @@ -30,12 +30,16 @@ class ENGINE_DLL CBone final : public CBase void Set_TransformationMatrix(_fmatrix TransformationMatrix); // 애니메이션에서 현재 로컬 매트릭스를 변경할 때 사용된다 _float4x4 Get_TransformationMatrix() { return m_TransformationMatrix; } _int Get_ParentBoneIndex() { return m_iParentBoneIndex; } + void SetCPUEvaluated(bool Evaluat) { m_bCPUEvaluated = Evaluat; } + _bool IsCPUEvaluated() const { return m_bCPUEvaluated; } + private: _string m_strName = {}; _float4x4 m_TransformationMatrix = {}; // 본의 현재 로컬 매트릭스 _float4x4 m_CombinedTransformationMatrix = {}; // 본의 루트노드로부터 상대적인 복합매트릭스 ( 부모노드는 PreTranformMatrix와 월드좌표로부터 상대적임 ) _float4x4 m_matInitial = {}; _int m_iParentBoneIndex = { -1 }; // 부모본의 인덱스 ( 모델에 있는 본벡터의 인덱스 ) ( 부모는 인덱스 -1 고정 ) + _bool m_bCPUEvaluated = false; private: HRESULT Initialize(HANDLE hFile, DWORD& dwByte); // 바이너리 diff --git a/Jusin154_Team3D/Engine/Public/Channel.h b/Jusin154_Team3D/Engine/Public/Channel.h index 2a670bbe2..4ef7dc7c4 100644 --- a/Jusin154_Team3D/Engine/Public/Channel.h +++ b/Jusin154_Team3D/Engine/Public/Channel.h @@ -23,10 +23,9 @@ class ENGINE_DLL CChannel : public CBase CHANNEL_DESC Fill_GPU_ChannelDesc(); public: - void Update_TransformationMatirx(const vector& Bones, LOCALPOS_DESC** pLocalPosArray, _float fCurrentTrackPosition, _uint* pCurrentKeyFrameIndex, _bool bIsSpine, vector<_uint> BoneMask, _vector vector[3]); + void Update_TransformationMatirx(const vector& Bones, _float fCurrentTrackPosition, _uint* pCurrentKeyFrameIndex, _bool bIsSpine, vector<_uint> BoneMask, _vector vector[3], _int RootBoneIndex); _int Get_BoneIndex() { return { m_iBoneIndex }; } void Set_BoneIndex(_int iBoneIndex) { m_iBoneIndex = iBoneIndex; } - void ResetRootMotion(); _matrix Get_BoneTransformationMatrix() { return m_BoneTransformationMatrix; } KEYFRAME* Get_Frame(_uint iIndex); @@ -58,13 +57,8 @@ class ENGINE_DLL CChannel : public CBase vector m_KeyFrames; // 키프레임 벡터 _float3 m_vPrevRootPos = { 0.f, 0.f, 0.f }; _int m_ilayerIndex = 0; - _float4 m_vPrevRootRot = { 0.f, 0.f, 0.f,0.f }; - _float4 m_vInitialRootRot = {}; _matrix m_BoneTransformationMatrix = {}; - LOCALPOS_DESC LocalPos = {}; vector m_KeyFrameDesc; - _bool m_bInitialRootPos = { false }; - _bool m_bInitialRootRotSaved = { false }; _bool m_IsUpper = false; public: // 바이너리 diff --git a/Jusin154_Team3D/Engine/Public/ComputeShader.h b/Jusin154_Team3D/Engine/Public/ComputeShader.h index 5b80aebd2..88b74bdaf 100644 --- a/Jusin154_Team3D/Engine/Public/ComputeShader.h +++ b/Jusin154_Team3D/Engine/Public/ComputeShader.h @@ -26,10 +26,12 @@ class ENGINE_DLL CComputeShader final : public CComponent virtual HRESULT Initialize(void* pArg); public: vector Dispatch(_uint iSRVIndex, _uint iUAVIndex, _float3 vGroupCount, ID3D11Buffer** ppBuffers, ID3D11Buffer* pConstantBuffer = nullptr); + void Dispatch_ExternalSRV_UAV(_uint srvStartSlot, _uint uavStartSlot, const _float3& groupCount, ID3D11ShaderResourceView** ppSRVs, _uint srvCount, ID3D11UnorderedAccessView** ppUAVs, _uint uavCount, ID3D11Buffer* pConstantBuffer); void Bind_OutPut_SRV(_uint iIndex, _uint iBufferIndex); void Bind_OutPut_SRV_VS(_uint iIndex, _uint iBufferIndex); ID3D11ComputeShader* Get_Compute() { return m_pComputeShader; } ID3D11UnorderedAccessView* GetOutputUAV(_uint iIndex) const; + ID3D11Buffer* Get_OutputBuffer(_int iIndex) {return m_pOutputBuffer[iIndex]; } private: void Bind_SRV(_uint iIndex); void Bind_UAV(_uint iIndex); diff --git a/Jusin154_Team3D/Engine/Public/Engine_Macro.h b/Jusin154_Team3D/Engine/Public/Engine_Macro.h index 520ba7ea9..d874d291e 100644 --- a/Jusin154_Team3D/Engine/Public/Engine_Macro.h +++ b/Jusin154_Team3D/Engine/Public/Engine_Macro.h @@ -39,7 +39,7 @@ #elif Bin #undef ASSERT_HYUNBIN #define ASSERT_HYUNBIN(expression) assert(expression) -#define OPTIONAL_TRUE_KEYINPUTGUICHECK ||true +//#define OPTIONAL_TRUE_KEYINPUTGUICHECK ||true #elif 인혁 #undef ASSERT_INHYUK #define ASSERT_INHYUK(expression) assert(expression) diff --git a/Jusin154_Team3D/Engine/Public/Engine_Struct.h b/Jusin154_Team3D/Engine/Public/Engine_Struct.h index d306051c7..2fcc09540 100644 --- a/Jusin154_Team3D/Engine/Public/Engine_Struct.h +++ b/Jusin154_Team3D/Engine/Public/Engine_Struct.h @@ -415,26 +415,14 @@ typedef struct tagChannelDesc //_uint Padding; }CHANNEL_DESC; - -typedef struct tagParentDesc -{ - _int ParentIndex; -}PARENT_DESC; - -typedef struct tagLocalPos -{ - _float3 Scale; - _float pad0; - _float4 Rotation; - _float3 Translation; - _float pad1; -}LOCALPOS_DESC; - -typedef struct tagBoneDesc +typedef struct tagBoneMatrix { + _float4x4 Local; _float4x4 Combined; + _float4x4 LocalCombined; }BONE_DESC; + typedef struct tagSSAO_Geometry_Hemisphere { _float3 SamplePos[SSAO_SAMPLE_NUMBER]; }SSAO_GEOMETRY_HEMISPHERE; diff --git a/Jusin154_Team3D/Engine/Public/Mesh.h b/Jusin154_Team3D/Engine/Public/Mesh.h index 58521725d..59e2a3193 100644 --- a/Jusin154_Team3D/Engine/Public/Mesh.h +++ b/Jusin154_Team3D/Engine/Public/Mesh.h @@ -18,15 +18,16 @@ class ENGINE_DLL CMesh final : public CVIBuffer void SeT_MaterialIndex(_uint iMaterialIndex) { m_iMaterialIndex = iMaterialIndex; } const _char* Get_Name() const { return m_strName.c_str(); } + _int Get_NumBone() { return m_iNumBones; } HRESULT Bind_BoneMatrices(const vector& Bones, class CShader* pShader, const _char* pConstantName); HRESULT Bind_BoneMatrices(_float4x4* pCombinedMatrices, class CShader* pShader, const _char* pConstantName); HRESULT Render_Indexed(_uint IndexCount, _uint StartIndexLocation, _uint BaseVertexLocation); - #ifdef EDITOR_PROJECT private: virtual HRESULT Initialize_Prototype(MODEL eType, vector& Bones, const aiMesh* pAIMesh, _fmatrix& PreTransformMatrix); HRESULT Ready_VertexBuffer_For_NonAnim(const aiMesh* pAIMesh, _fmatrix PreTransformMatrix); HRESULT Ready_VertexBuffer_For_Anim(vector& Bones, const aiMesh* pAIMesh); + public: static CMesh* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, MODEL eType, vector& Bones, const aiMesh* pAIMesh, _fmatrix& PreTransformMatrix); #endif // EDITOR_PROJECT @@ -38,13 +39,16 @@ class ENGINE_DLL CMesh final : public CVIBuffer virtual HRESULT Render_Instance(_uint iNumInstance); _uint Get_Vertex() { return m_iNumVertices; } + vector<_float4x4> Get_OffsetMatrix() { return m_offsetMatrices; } + ID3D11ShaderResourceView* Get_BoneRemapSRV() { return m_pBoneRemapSRV; } + ID3D11Buffer* Get_BoneRemapBuffer() { return m_pBoneRemapBuffer; } private: virtual HRESULT Initialize(void* pArg) override; // 바이너리 virtual HRESULT Initialize_Prototype(MODEL eType, const class CModel* pModel, SaveMesh* _SaveMesh, _fmatrix PreTransformMatrix); HRESULT Ready_VertexBuffer_For_NonAnim(SaveMesh* _SaveMesh, _fmatrix PreTransformMatrix); HRESULT Ready_VertexBuffer_For_Anim(const class CModel* pModel, SaveMesh* _SaveMesh); - + HRESULT Create_BoneRemapBuffer(); private: _string m_strName = { }; _uint m_iMaterialIndex = {}; @@ -54,6 +58,11 @@ class ENGINE_DLL CMesh final : public CVIBuffer vector<_int> m_BoneIndices; _float4x4* m_pBoneMatrices = { nullptr }; vector<_float4x4> m_offsetMatrices; + vector<_uint> m_BoneRemap; + ID3D11ShaderResourceView* m_pBoneRemapSRV = nullptr; + ID3D11Buffer* m_pBoneRemapBuffer = nullptr; + + // 바이너리 std::vector<_uint> m_Indices; diff --git a/Jusin154_Team3D/Engine/Public/Model.h b/Jusin154_Team3D/Engine/Public/Model.h index 8894c519b..38c373a42 100644 --- a/Jusin154_Team3D/Engine/Public/Model.h +++ b/Jusin154_Team3D/Engine/Public/Model.h @@ -11,10 +11,15 @@ class ENGINE_DLL CModel final : public CComponent { _float CurrentTime; _float Duration; - _float Speed; + _int MeshBoneCount; _int BoneCount; - _float4x4 PreTransformMatrix; + _int RootBoneIndex; + _int Padding; + _float PrevTime; + _float BlendRatio; + _float4x4 PreTransformMatrix; + _float4 RootInitRot; }ANIMSTATE_DESC; private: @@ -59,28 +64,32 @@ class ENGINE_DLL CModel final : public CComponent void Set_BlendDuration(_float Duration) { m_fBlendDuration = Duration; } #pragma endregion #pragma region Mesh - const _char* Get_MeshName(_uint iIndex); - _uint Get_NumMeshes() const { return m_iNumMeshes; } - void Update_RootBone(_float Amount = 1.f); - void Initialize_RootBone(); + const _char* Get_MeshName(_uint iIndex); + _uint Get_NumMeshes() const { return m_iNumMeshes; } + void Update_RootBone(_float Amount = 1.f); + void Initialize_RootBone(); + void BeginFrame(); + vector<_float4x4> Get_OffsetMatrix(_int iIndex); + void Apply_CPUMask_ToBones(); + void Mark_CPUChain(_int boneIdx); #pragma endregion #pragma region Bone HRESULT Bind_BoneMatrices(_uint iMeshIndex, class CShader* pShader, const _char* pConstantName); - const _float4x4* Get_BoneMatrixPtr(const _char* pBoneName) const; + const _float4x4* Get_BoneMatrixPtr(const _char* pBoneName); _matrix Get_BoneMatrix(const _char* pBoneName) const; _matrix Get_BoneLocalMatrix(const _char* pBoneName) const; static _int Get_BoneIndex(const _char* pBoneName, vector Bones); // 본의 벡터와 이름을 넘겨주면 인덱스를 넘겨줌 ( n 순회 ) _int Get_BoneIndex(const _char* pBoneName) const; _matrix Get_BoneMatrix(_uint iBoneIndex); void Combined_BoneMatrix(); - #pragma endregion #pragma region Material HRESULT Bind_Material(_uint iMeshIndex, class CShader* pShader); HRESULT Begin(_uint iMeshIndex, class CShader* pShader, _bool OutLine = false); #pragma endregion - void ComputeAnimation(_uint AnimIndex); + void ComputeAnimation(_uint AnimIndex, _uint MeshIndex); + void Bind_OutPut_SRV_VS(_uint iIndex, _uint iBufferIndex); void ComputeAnimation_Second(_uint AnimIndex); void InItialize_BoneIndex(); @@ -146,8 +155,7 @@ class ENGINE_DLL CModel final : public CComponent _int m_iCurrSecondAnimIndex = { -1 }; _int m_iBoneIndex[ENUM_CLASS(BLEND_BONE::END)] = { -1,-1,-1,-1,-1,-1 }; vector> m_BoneMask; - - + vector<_bool> m_CPUBoneMask; // 바이너리 SaveModel* m_pSaveModel = { nullptr }; @@ -161,18 +169,19 @@ class ENGINE_DLL CModel final : public CComponent _matrix m_BoneTransformationMatrix = {}; _float4 m_vInitialRootRot = {}; - _float m_fRadius = { 0.f }; // 컬링용 Radius - _int m_iRootBoneIndex = { -1 }; // 루트본의 인덱스 + _float m_fRadius = { 0.f }; // 컬링용 Radius + _int m_iRootBoneIndex = { -1 }; // 루트본의 인덱스 _vector m_vector[3]; vector<_uint> m_iBoneMask; _bool m_bInitialRootPos = { false }; _bool m_bInitialRootRotSaved = { false }; _bool m_bLoopRestarted = false; - _bool m_bIsSecondFinishedAnim = { false }; - _bool m_bIsSecondLoop = { false }; - _bool m_bRatio = { false }; - _bool m_bRootBone = {}; + _bool m_bIsSecondFinishedAnim = { false }; + _bool m_bIsSecondLoop = { false }; + _bool m_bRatio = { false }; + _bool m_bRootBone = {}; + _float4x4 m_RootMatrix = {}; private: #ifdef EDITOR_PROJECT @@ -184,26 +193,37 @@ class ENGINE_DLL CModel final : public CComponent #pragma region Compute private: + HRESULT Create_ComputeShader(); HRESULT Create_ParentVB(); - void Create_Temp(); - void Create_LocalPosVB(); + HRESULT Create_BoneLocalVB(); + HRESULT Create_Temp(); + HRESULT Create_BoneMatrixVB(); + HRESULT Create_Const(); + HRESULT Create_ParentSrv(); + HRESULT Create_BoneLocalSrv(); - _uint m_iNumBuffer = {}; + _uint m_iNumBuffer = {}; + + vector<_int> m_Parent = {}; + vector<_float4x4> m_BoneLocal = {}; - vector m_Parent = {}; vector m_AnimRanges; - LOCALPOS_DESC* m_pLocalPos[2] = { nullptr }; - class CComputeShader* m_pComputeShader = nullptr; ID3D11Buffer* m_pConstantBuffer = { nullptr }; - ID3D11Buffer* m_pParentBuffer = { nullptr }; - ID3D11Buffer* m_pLocalPosBuffer = { nullptr }; + ID3D11Buffer* m_pBoneMatrixBuffer = { nullptr }; + ID3D11Buffer* m_pBoneLocalBuffer = { nullptr }; + + ID3D11ShaderResourceView* m_pParentSRV = {}; + ID3D11ShaderResourceView* m_pBoneLocalSRV = {}; + ID3D11ShaderResourceView* m_pBoneMatrixSRV = {}; + ID3D11UnorderedAccessView* m_pBoneMatrixUAV = {}; #pragma endregion private: + // 바이너리 virtual HRESULT Initialize_Prototype(MODEL eType, const _char* pModelFilePath, _fmatrix PreTransformMatrix); void LoadAdditionalAnimations(const char* ModelFilePath);