Merge branch 'Develope' into Thread
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "LerpAnim.h"
|
||||
#include "GameObject.h"
|
||||
#include "Transform.h"
|
||||
#include "ComputeShader.h"
|
||||
|
||||
CModel::CModel(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
: CComponent{ pDevice, pContext }
|
||||
@@ -899,6 +900,96 @@ HRESULT CModel::Assimp_Model_Load(const _char* pModelFilePath, MODEL eType, _fma
|
||||
|
||||
#endif // EDITOR_PROJECT
|
||||
|
||||
HRESULT CModel::Create_CS()
|
||||
{
|
||||
_uint vertexCount = 0;
|
||||
_uint MaxvertexCount = 0;
|
||||
for (_uint i = 0; i < m_Meshes.size(); ++i)
|
||||
{
|
||||
vertexCount = m_Meshes[i]->Get_Vertex();
|
||||
if (MaxvertexCount < vertexCount)
|
||||
MaxvertexCount = vertexCount;
|
||||
}
|
||||
|
||||
_uint CS_InputStrides[] = {
|
||||
sizeof(MESH_DESC)
|
||||
};
|
||||
|
||||
size_t meshCount = m_Meshes.size();
|
||||
|
||||
_uint* CS_OutputStrides = new _uint[meshCount];
|
||||
|
||||
for (size_t i = 0; i < meshCount; i++)
|
||||
{
|
||||
CS_OutputStrides[i] = sizeof(SKINNG_MESH_DESC)*(_uint)meshCount;
|
||||
}
|
||||
|
||||
|
||||
m_pComputeShader = CComputeShader::Create(m_pDevice, m_pContext,
|
||||
L"../Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl", "CS_MAIN", MaxvertexCount, 1, (_uint)meshCount, CS_InputStrides,CS_OutputStrides);
|
||||
|
||||
if (m_pComputeShader == nullptr)
|
||||
return E_FAIL;
|
||||
|
||||
Safe_Delete_Array(CS_OutputStrides);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void CModel::ComputeSkinning()
|
||||
{
|
||||
Get_BoneMatrix();
|
||||
for (_uint i = 0; i < m_iNumMeshes; ++i)
|
||||
{
|
||||
D3D11_MAPPED_SUBRESOURCE ConstantSubResource{};
|
||||
if (SUCCEEDED(m_pContext->Map(m_pConstantBuffer, 0,
|
||||
D3D11_MAP_WRITE_DISCARD, 0, &ConstantSubResource)))
|
||||
{
|
||||
CMesh::BONE_DESC* pDesc =
|
||||
static_cast<CMesh::BONE_DESC*>(ConstantSubResource.pData);
|
||||
|
||||
m_Meshes[i]->FillBoneDesc(m_BoneMatrix,pDesc);
|
||||
|
||||
m_pContext->Unmap(m_pConstantBuffer, 0);
|
||||
}
|
||||
|
||||
m_Meshes[i]->ComputSkinning(m_pComputeShader, m_pConstantBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
void CModel::Create_Con()
|
||||
{
|
||||
D3D11_BUFFER_DESC cbDesc = {};
|
||||
cbDesc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
||||
cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
cbDesc.ByteWidth = sizeof(BONE_DESC);
|
||||
|
||||
if (FAILED(m_pDevice->CreateBuffer(&cbDesc, nullptr, &m_pConstantBuffer)))
|
||||
return;
|
||||
}
|
||||
|
||||
HRESULT CModel::Bind_CS_Output(_uint Index, _uint iBufferIndex)
|
||||
{
|
||||
if (m_pComputeShader == nullptr)
|
||||
return E_FAIL;
|
||||
|
||||
m_pComputeShader->Bind_OutPut_SRV(Index, iBufferIndex);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void CModel::Get_BoneMatrix()
|
||||
{
|
||||
m_BoneMatrix.resize(m_Bones.size());
|
||||
for (size_t i =0; i < m_Bones.size(); i++)
|
||||
{
|
||||
m_BoneMatrix[i] = (*m_Bones[i]->Get_CombinedTransformationMatrixPtr());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
HRESULT CModel::Initialize_Prototype(MODEL eType, const _char* pModelFilePath, _fmatrix PreTransformMatrix)
|
||||
{
|
||||
m_eType = eType;
|
||||
@@ -1226,6 +1317,13 @@ HRESULT CModel::Initialize(void* pArg)
|
||||
m_pTransform = m_pOwner->Get_Component<CTransform>();
|
||||
SAFE_ADDREF(m_pTransform);
|
||||
|
||||
Create_Con();
|
||||
|
||||
if (FAILED(Create_CS()))
|
||||
return E_FAIL;
|
||||
|
||||
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -1349,8 +1447,11 @@ void CModel::Free()
|
||||
SAFE_RELEASE(m_pLerpAnim);
|
||||
|
||||
m_SaveModel.clear();
|
||||
}
|
||||
|
||||
SAFE_RELEASE(m_pComputeShader);
|
||||
SAFE_RELEASE(m_pConstantBuffer);
|
||||
|
||||
}
|
||||
void CModel::Describe_Entity()
|
||||
{
|
||||
//GUI::Begin("Model_Desc");
|
||||
|
||||
Reference in New Issue
Block a user