임시
This commit is contained in:
@@ -1,17 +1,6 @@
|
||||
|
||||
#include "Engine_Shader_Defines.hlsli"
|
||||
|
||||
struct SkinngMesh
|
||||
{
|
||||
float3 vPosition;
|
||||
float3 vNormal;
|
||||
float3 vTangent;
|
||||
float3 vBinormal;
|
||||
float2 vTexcoord;
|
||||
};
|
||||
|
||||
|
||||
|
||||
matrix g_WorldMatrix, g_ViewMatrix, g_ProjMatrix;
|
||||
|
||||
bool g_bRimLight;
|
||||
@@ -25,13 +14,11 @@ float3 g_vRimColor;
|
||||
float4 g_TestColor;
|
||||
vector g_vCamPosition;
|
||||
|
||||
Texture2D g_DiffuseTexture : register(t0);
|
||||
Texture2D g_NormalTexture : register(t1);
|
||||
Texture2D g_DAOTexture : register(t2);
|
||||
Texture2D g_THVTexture : register(t3);
|
||||
Texture2D g_SurfaceParamsTexture : register(t4);
|
||||
|
||||
StructuredBuffer<SkinngMesh> g_SkinngMesh : register(t5);
|
||||
Texture2D g_DiffuseTexture;
|
||||
Texture2D g_NormalTexture;
|
||||
Texture2D g_DAOTexture;
|
||||
Texture2D g_THVTexture;
|
||||
Texture2D g_SurfaceParamsTexture;
|
||||
|
||||
float3 g_RootColor;
|
||||
float3 g_TipColor;
|
||||
@@ -67,31 +54,26 @@ struct VS_OUT
|
||||
float4 vWorldPos : TEXCOORD1;
|
||||
float4 vProjPos : TEXCOORD2;
|
||||
};
|
||||
VS_OUT VS_MAIN(VS_IN In, uint vertexID : SV_VertexID)
|
||||
|
||||
VS_OUT VS_MAIN(VS_IN In)
|
||||
{
|
||||
VS_OUT 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);
|
||||
|
||||
//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);
|
||||
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);
|
||||
|
||||
matrix matWV, matWVP;
|
||||
|
||||
vector vPosition = float4(g_SkinngMesh[vertexID].vPosition, 1.f);
|
||||
|
||||
vector vNormal = float4(g_SkinngMesh[vertexID].vNormal, 0.f);
|
||||
vector vBinormal = float4(g_SkinngMesh[vertexID].vBinormal, 0.f);
|
||||
vector vTangent = float4(g_SkinngMesh[vertexID].vTangent, 0.f);
|
||||
|
||||
matrix matWV, matWVP;
|
||||
matWV = mul(g_WorldMatrix, g_ViewMatrix);
|
||||
matWVP = mul(matWV, g_ProjMatrix);
|
||||
|
||||
@@ -99,8 +81,7 @@ VS_OUT VS_MAIN(VS_IN In, uint vertexID : SV_VertexID)
|
||||
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 = g_SkinngMesh[vertexID].vTexcoord;
|
||||
//In.vTexcoord;
|
||||
Out.vTexcoord = In.vTexcoord;
|
||||
Out.vWorldPos = mul(vPosition, g_WorldMatrix);
|
||||
Out.vProjPos = Out.vPosition;
|
||||
return Out;
|
||||
@@ -124,10 +105,10 @@ VS_OUT_CAPTUREDMODEL VS_CAPTUREDMODEL(VS_IN In)
|
||||
|
||||
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 ) +
|
||||
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);
|
||||
@@ -219,10 +200,13 @@ struct PS_OUT
|
||||
PS_OUT PS_MAIN(PS_IN In)
|
||||
{
|
||||
PS_OUT Out;
|
||||
|
||||
|
||||
vector vMtrlDiffuse = g_DiffuseTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
vector vSurface = g_SurfaceParamsTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
if (vMtrlDiffuse.a < 0.2f) { discard; }
|
||||
if (vMtrlDiffuse.a < 0.2f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
float3 vNormalDecoded = DecodeNormalFromRG(g_NormalTexture, DefaultSampler, In.vTexcoord);
|
||||
float3x3 WorldMatrix = float3x3(In.vTangent, In.vBinormal * -1.f, In.vNormal);
|
||||
|
||||
@@ -39,8 +39,6 @@ void CBroom::Priority_Update(_float fTimeDelta)
|
||||
void CBroom::Update(_float fTimeDelta)
|
||||
{
|
||||
m_pModelCom->Play_Animation(fTimeDelta, m_pTransformCom);
|
||||
|
||||
m_pModelCom->ComputeSkinning();
|
||||
}
|
||||
|
||||
void CBroom::Late_Update(_float fTimeDelta)
|
||||
@@ -61,6 +59,9 @@ HRESULT CBroom::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;
|
||||
@@ -69,9 +70,6 @@ HRESULT CBroom::Render()
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pModelCom->Bind_CS_Output(5, i)))
|
||||
return E_FAIL;
|
||||
|
||||
|
||||
if (FAILED(m_pModelCom->Render(i))) {
|
||||
return E_FAIL;
|
||||
|
||||
@@ -83,8 +83,6 @@ void CPlayer::Priority_Update(_float fTimeDelta)
|
||||
|
||||
void CPlayer::Update(_float fTimeDelta)
|
||||
{
|
||||
m_pModelCom->ComputeSkinning();
|
||||
|
||||
Key_Input(fTimeDelta);
|
||||
|
||||
m_pFSM->Update(fTimeDelta);
|
||||
@@ -124,9 +122,6 @@ HRESULT CPlayer::Render()
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pModelCom->Bind_CS_Output(5, i)))
|
||||
return E_FAIL;
|
||||
|
||||
if (FAILED(m_pModelCom->Render(i))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
@@ -1,64 +1,134 @@
|
||||
float PI = 3.141592;
|
||||
|
||||
struct Mesh
|
||||
struct KeyFrame
|
||||
{
|
||||
float3 vPosition;
|
||||
float3 vNormal;
|
||||
float3 vTangent;
|
||||
float3 vBinormal;
|
||||
float2 vTexcoord;
|
||||
|
||||
uint4 vBlendIndex;
|
||||
float4 vBlendWeight;
|
||||
float3 vScale;
|
||||
float4 vRotation;
|
||||
float3 vTranslation;
|
||||
float fTrackPosition;
|
||||
};
|
||||
|
||||
struct SkinngMesh
|
||||
struct BoneInfo
|
||||
{
|
||||
float3 vPosition;
|
||||
float3 vNormal;
|
||||
float3 vTangent;
|
||||
float3 vBinormal;
|
||||
float2 vTexcoord;
|
||||
int ParentIndex;
|
||||
};
|
||||
|
||||
struct BoneMatrix
|
||||
{
|
||||
row_major float4x4 LocalMatrix;
|
||||
row_major float4x4 CombinedMatrix;
|
||||
|
||||
};
|
||||
|
||||
StructuredBuffer<Mesh> g_MeshBufferInput : register(t0);
|
||||
RWStructuredBuffer<SkinngMesh> gSkinngMeshOutput : register(u0);
|
||||
StructuredBuffer<KeyFrame> g_KeyFrameBufferInput : register(t0);
|
||||
StructuredBuffer<BoneInfo> g_BoneInoBufferInput : register(t1);
|
||||
|
||||
RWStructuredBuffer<BoneMatrix> gBoneMatrixOutput : register(u0);
|
||||
|
||||
cbuffer g_ConstantBuffer : register(b0)
|
||||
{
|
||||
row_major float4x4 BoneMatrix[512];
|
||||
float CurrentTime;
|
||||
float Duration;
|
||||
float Speed;
|
||||
int BoneCount;
|
||||
|
||||
float4x4 PreTransformMatrix;
|
||||
|
||||
};
|
||||
|
||||
//[numthreads(256, 1, 1)]
|
||||
float4x4 QuatToMatrix(float4 q)
|
||||
{
|
||||
float x = q.x;
|
||||
float y = q.y;
|
||||
float z = q.z;
|
||||
float w = q.w;
|
||||
|
||||
float xx = x * x;
|
||||
float yy = y * y;
|
||||
float zz = z * z;
|
||||
|
||||
float xy = x * y;
|
||||
float xz = x * z;
|
||||
float yz = y * z;
|
||||
float wx = w * x;
|
||||
float wy = w * y;
|
||||
float wz = w * z;
|
||||
|
||||
float4x4 m;
|
||||
|
||||
m[0][0] = 1.0 - 2.0 * (yy + zz);
|
||||
m[0][1] = 2.0 * (xy + wz);
|
||||
m[0][2] = 2.0 * (xz - wy);
|
||||
m[0][3] = 0.0;
|
||||
|
||||
m[1][0] = 2.0 * (xy - wz);
|
||||
m[1][1] = 1.0 - 2.0 * (xx + zz);
|
||||
m[1][2] = 2.0 * (yz + wx);
|
||||
m[1][3] = 0.0;
|
||||
|
||||
m[2][0] = 2.0 * (xz + wy);
|
||||
m[2][1] = 2.0 * (yz - wx);
|
||||
m[2][2] = 1.0 - 2.0 * (xx + yy);
|
||||
m[2][3] = 0.0;
|
||||
|
||||
m[3][0] = 0.0;
|
||||
m[3][1] = 0.0;
|
||||
m[3][2] = 0.0;
|
||||
m[3][3] = 1.0;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
float4x4 MakeTRS(float3 scale, float4 rot, float3 trans)
|
||||
{
|
||||
float4x4 S =
|
||||
{
|
||||
scale.x, 0, 0, 0,
|
||||
0, scale.y, 0, 0,
|
||||
0, 0, scale.z, 0,
|
||||
0, 0, 0, 1
|
||||
};
|
||||
|
||||
float4x4 R = QuatToMatrix(normalize(rot));
|
||||
|
||||
float4x4 T =
|
||||
{
|
||||
1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
trans.x, trans.y, trans.z, 1
|
||||
};
|
||||
|
||||
return mul(S, mul(R, T));
|
||||
}
|
||||
|
||||
[numthreads(256, 1, 1)]
|
||||
void CS_MAIN(uint3 DispatchThreadID : SV_DispatchThreadID)
|
||||
{
|
||||
uint iIndex = DispatchThreadID.x;
|
||||
uint boneIndex = DispatchThreadID.x;
|
||||
if (boneIndex >= BoneCount)
|
||||
return;
|
||||
|
||||
Mesh mesh = g_MeshBufferInput[iIndex];
|
||||
KeyFrame k = g_KeyFrameBufferInput[boneIndex];
|
||||
BoneInfo bi = g_BoneInoBufferInput[boneIndex];
|
||||
|
||||
float fWeightW = 1.f -
|
||||
(mesh.vBlendWeight.x + mesh.vBlendWeight.y + mesh.vBlendWeight.z);
|
||||
float3 s = k.vScale;
|
||||
float4 r = k.vRotation;
|
||||
float3 t = k.vTranslation;
|
||||
|
||||
matrix SkinMatrix =
|
||||
BoneMatrix[mesh.vBlendIndex.x] * mesh.vBlendWeight.x +
|
||||
BoneMatrix[mesh.vBlendIndex.y] * mesh.vBlendWeight.y +
|
||||
BoneMatrix[mesh.vBlendIndex.z] * mesh.vBlendWeight.z +
|
||||
BoneMatrix[mesh.vBlendIndex.w] * fWeightW;
|
||||
float4x4 local = MakeTRS(s, r, t);
|
||||
|
||||
float4 vPosition = mul(float4(mesh.vPosition, 1), SkinMatrix);
|
||||
float4 vNormal = mul(float4(mesh.vNormal, 0), SkinMatrix);
|
||||
float4 vBinormal = mul(float4(mesh.vBinormal, 0), SkinMatrix);
|
||||
float4 vTangent = mul(float4(mesh.vTangent, 0), SkinMatrix);
|
||||
float4x4 combined;
|
||||
|
||||
if (bi.ParentIndex < 0)
|
||||
{
|
||||
combined = mul(local, PreTransformMatrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
combined = mul(local, gBoneMatrixOutput[bi.ParentIndex].CombinedMatrix);
|
||||
}
|
||||
|
||||
SkinngMesh outv;
|
||||
outv.vPosition = vPosition.xyz;
|
||||
outv.vNormal = vNormal.xyz;
|
||||
outv.vTangent = vTangent.xyz;
|
||||
outv.vBinormal = vBinormal.xyz;
|
||||
outv.vTexcoord = mesh.vTexcoord;
|
||||
|
||||
gSkinngMeshOutput[iIndex] = outv;
|
||||
gBoneMatrixOutput[boneIndex].LocalMatrix = local;
|
||||
gBoneMatrixOutput[boneIndex].CombinedMatrix = combined;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
|
||||
#include "Engine_Shader_Defines.hlsli"
|
||||
|
||||
struct SkinngMesh
|
||||
{
|
||||
float3 vPosition;
|
||||
float3 vNormal;
|
||||
float3 vTangent;
|
||||
float3 vBinormal;
|
||||
float2 vTexcoord;
|
||||
};
|
||||
|
||||
|
||||
#include "Engine_Shader_Defines.hlsli"
|
||||
|
||||
matrix g_WorldMatrix, g_ViewMatrix, g_ProjMatrix;
|
||||
|
||||
@@ -25,13 +14,11 @@ float3 g_vRimColor;
|
||||
float4 g_TestColor;
|
||||
vector g_vCamPosition;
|
||||
|
||||
Texture2D g_DiffuseTexture : register(t0);
|
||||
Texture2D g_NormalTexture : register(t1);
|
||||
Texture2D g_DAOTexture : register(t2);
|
||||
Texture2D g_THVTexture : register(t3);
|
||||
Texture2D g_SurfaceParamsTexture : register(t4);
|
||||
|
||||
StructuredBuffer<SkinngMesh> g_SkinngMesh : register(t5);
|
||||
Texture2D g_DiffuseTexture;
|
||||
Texture2D g_NormalTexture;
|
||||
Texture2D g_DAOTexture;
|
||||
Texture2D g_THVTexture;
|
||||
Texture2D g_SurfaceParamsTexture;
|
||||
|
||||
float3 g_RootColor;
|
||||
float3 g_TipColor;
|
||||
@@ -67,31 +54,26 @@ struct VS_OUT
|
||||
float4 vWorldPos : TEXCOORD1;
|
||||
float4 vProjPos : TEXCOORD2;
|
||||
};
|
||||
VS_OUT VS_MAIN(VS_IN In, uint vertexID : SV_VertexID)
|
||||
|
||||
VS_OUT VS_MAIN(VS_IN In)
|
||||
{
|
||||
VS_OUT 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);
|
||||
|
||||
//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);
|
||||
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);
|
||||
|
||||
matrix matWV, matWVP;
|
||||
|
||||
vector vPosition = float4(g_SkinngMesh[vertexID].vPosition, 1.f);
|
||||
|
||||
vector vNormal = float4(g_SkinngMesh[vertexID].vNormal, 0.f);
|
||||
vector vBinormal = float4(g_SkinngMesh[vertexID].vBinormal, 0.f);
|
||||
vector vTangent = float4(g_SkinngMesh[vertexID].vTangent, 0.f);
|
||||
|
||||
matrix matWV, matWVP;
|
||||
matWV = mul(g_WorldMatrix, g_ViewMatrix);
|
||||
matWVP = mul(matWV, g_ProjMatrix);
|
||||
|
||||
@@ -99,8 +81,7 @@ VS_OUT VS_MAIN(VS_IN In, uint vertexID : SV_VertexID)
|
||||
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 = g_SkinngMesh[vertexID].vTexcoord;
|
||||
//In.vTexcoord;
|
||||
Out.vTexcoord = In.vTexcoord;
|
||||
Out.vWorldPos = mul(vPosition, g_WorldMatrix);
|
||||
Out.vProjPos = Out.vPosition;
|
||||
return Out;
|
||||
@@ -124,10 +105,10 @@ VS_OUT_CAPTUREDMODEL VS_CAPTUREDMODEL(VS_IN In)
|
||||
|
||||
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 ) +
|
||||
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);
|
||||
@@ -219,10 +200,13 @@ struct PS_OUT
|
||||
PS_OUT PS_MAIN(PS_IN In)
|
||||
{
|
||||
PS_OUT Out;
|
||||
|
||||
|
||||
vector vMtrlDiffuse = g_DiffuseTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
vector vSurface = g_SurfaceParamsTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
if (vMtrlDiffuse.a < 0.2f) { discard; }
|
||||
if (vMtrlDiffuse.a < 0.2f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
float3 vNormalDecoded = DecodeNormalFromRG(g_NormalTexture, DefaultSampler, In.vTexcoord);
|
||||
float3x3 WorldMatrix = float3x3(In.vTangent, In.vBinormal * -1.f, In.vNormal);
|
||||
|
||||
@@ -40,8 +40,6 @@ void CGoblin::Priority_Update(_float fTimeDelta)
|
||||
void CGoblin::Update(_float fTimeDelta)
|
||||
{
|
||||
m_pModelCom->Play_Animation(fTimeDelta, m_pTransformCom);
|
||||
|
||||
m_pModelCom->ComputeSkinning();
|
||||
}
|
||||
|
||||
void CGoblin::Late_Update(_float fTimeDelta)
|
||||
@@ -71,9 +69,6 @@ HRESULT CGoblin::Render()
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pModelCom->Bind_CS_Output(5, 0)))
|
||||
return E_FAIL;
|
||||
|
||||
if (FAILED(m_pModelCom->Render(i))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
@@ -75,8 +75,6 @@ void CPlayer::Priority_Update(_float fTimeDelta)
|
||||
|
||||
void CPlayer::Update(_float fTimeDelta)
|
||||
{
|
||||
m_pModelCom->ComputeSkinning();
|
||||
|
||||
Key_Input(fTimeDelta);
|
||||
|
||||
m_pFSM->Update(fTimeDelta);
|
||||
@@ -114,8 +112,6 @@ HRESULT CPlayer::Render()
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pModelCom->Bind_CS_Output(5, i)))
|
||||
return E_FAIL;
|
||||
|
||||
if (FAILED(m_pModelCom->Render(i))) {
|
||||
return E_FAIL;
|
||||
|
||||
@@ -1,64 +1,134 @@
|
||||
float PI = 3.141592;
|
||||
|
||||
struct Mesh
|
||||
struct KeyFrame
|
||||
{
|
||||
float3 vPosition;
|
||||
float3 vNormal;
|
||||
float3 vTangent;
|
||||
float3 vBinormal;
|
||||
float2 vTexcoord;
|
||||
|
||||
uint4 vBlendIndex;
|
||||
float4 vBlendWeight;
|
||||
float3 vScale;
|
||||
float4 vRotation;
|
||||
float3 vTranslation;
|
||||
float fTrackPosition;
|
||||
};
|
||||
|
||||
struct SkinngMesh
|
||||
struct BoneInfo
|
||||
{
|
||||
float3 vPosition;
|
||||
float3 vNormal;
|
||||
float3 vTangent;
|
||||
float3 vBinormal;
|
||||
float2 vTexcoord;
|
||||
int ParentIndex;
|
||||
};
|
||||
|
||||
struct BoneMatrix
|
||||
{
|
||||
row_major float4x4 LocalMatrix;
|
||||
row_major float4x4 CombinedMatrix;
|
||||
|
||||
};
|
||||
|
||||
StructuredBuffer<Mesh> g_MeshBufferInput : register(t0);
|
||||
RWStructuredBuffer<SkinngMesh> gSkinngMeshOutput : register(u0);
|
||||
StructuredBuffer<KeyFrame> g_KeyFrameBufferInput : register(t0);
|
||||
StructuredBuffer<BoneInfo> g_BoneInoBufferInput : register(t1);
|
||||
|
||||
RWStructuredBuffer<BoneMatrix> gBoneMatrixOutput : register(u0);
|
||||
|
||||
cbuffer g_ConstantBuffer : register(b0)
|
||||
{
|
||||
row_major float4x4 BoneMatrix[512];
|
||||
float CurrentTime;
|
||||
float Duration;
|
||||
float Speed;
|
||||
int BoneCount;
|
||||
|
||||
float4x4 PreTransformMatrix;
|
||||
|
||||
};
|
||||
|
||||
//[numthreads(256, 1, 1)]
|
||||
float4x4 QuatToMatrix(float4 q)
|
||||
{
|
||||
float x = q.x;
|
||||
float y = q.y;
|
||||
float z = q.z;
|
||||
float w = q.w;
|
||||
|
||||
float xx = x * x;
|
||||
float yy = y * y;
|
||||
float zz = z * z;
|
||||
|
||||
float xy = x * y;
|
||||
float xz = x * z;
|
||||
float yz = y * z;
|
||||
float wx = w * x;
|
||||
float wy = w * y;
|
||||
float wz = w * z;
|
||||
|
||||
float4x4 m;
|
||||
|
||||
m[0][0] = 1.0 - 2.0 * (yy + zz);
|
||||
m[0][1] = 2.0 * (xy + wz);
|
||||
m[0][2] = 2.0 * (xz - wy);
|
||||
m[0][3] = 0.0;
|
||||
|
||||
m[1][0] = 2.0 * (xy - wz);
|
||||
m[1][1] = 1.0 - 2.0 * (xx + zz);
|
||||
m[1][2] = 2.0 * (yz + wx);
|
||||
m[1][3] = 0.0;
|
||||
|
||||
m[2][0] = 2.0 * (xz + wy);
|
||||
m[2][1] = 2.0 * (yz - wx);
|
||||
m[2][2] = 1.0 - 2.0 * (xx + yy);
|
||||
m[2][3] = 0.0;
|
||||
|
||||
m[3][0] = 0.0;
|
||||
m[3][1] = 0.0;
|
||||
m[3][2] = 0.0;
|
||||
m[3][3] = 1.0;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
float4x4 MakeTRS(float3 scale, float4 rot, float3 trans)
|
||||
{
|
||||
float4x4 S =
|
||||
{
|
||||
scale.x, 0, 0, 0,
|
||||
0, scale.y, 0, 0,
|
||||
0, 0, scale.z, 0,
|
||||
0, 0, 0, 1
|
||||
};
|
||||
|
||||
float4x4 R = QuatToMatrix(normalize(rot));
|
||||
|
||||
float4x4 T =
|
||||
{
|
||||
1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
trans.x, trans.y, trans.z, 1
|
||||
};
|
||||
|
||||
return mul(S, mul(R, T));
|
||||
}
|
||||
|
||||
[numthreads(256, 1, 1)]
|
||||
void CS_MAIN(uint3 DispatchThreadID : SV_DispatchThreadID)
|
||||
{
|
||||
uint iIndex = DispatchThreadID.x;
|
||||
uint boneIndex = DispatchThreadID.x;
|
||||
if (boneIndex >= BoneCount)
|
||||
return;
|
||||
|
||||
Mesh mesh = g_MeshBufferInput[iIndex];
|
||||
KeyFrame k = g_KeyFrameBufferInput[boneIndex];
|
||||
BoneInfo bi = g_BoneInoBufferInput[boneIndex];
|
||||
|
||||
float fWeightW = 1.f -
|
||||
(mesh.vBlendWeight.x + mesh.vBlendWeight.y + mesh.vBlendWeight.z);
|
||||
float3 s = k.vScale;
|
||||
float4 r = k.vRotation;
|
||||
float3 t = k.vTranslation;
|
||||
|
||||
matrix SkinMatrix =
|
||||
BoneMatrix[mesh.vBlendIndex.x] * mesh.vBlendWeight.x +
|
||||
BoneMatrix[mesh.vBlendIndex.y] * mesh.vBlendWeight.y +
|
||||
BoneMatrix[mesh.vBlendIndex.z] * mesh.vBlendWeight.z +
|
||||
BoneMatrix[mesh.vBlendIndex.w] * fWeightW;
|
||||
float4x4 local = MakeTRS(s, r, t);
|
||||
|
||||
float4 vPosition = mul(float4(mesh.vPosition, 1), SkinMatrix);
|
||||
float4 vNormal = mul(float4(mesh.vNormal, 0), SkinMatrix);
|
||||
float4 vBinormal = mul(float4(mesh.vBinormal, 0), SkinMatrix);
|
||||
float4 vTangent = mul(float4(mesh.vTangent, 0), SkinMatrix);
|
||||
float4x4 combined;
|
||||
|
||||
if (bi.ParentIndex < 0)
|
||||
{
|
||||
combined = mul(local, PreTransformMatrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
combined = mul(local, gBoneMatrixOutput[bi.ParentIndex].CombinedMatrix);
|
||||
}
|
||||
|
||||
SkinngMesh outv;
|
||||
outv.vPosition = vPosition.xyz;
|
||||
outv.vNormal = vNormal.xyz;
|
||||
outv.vTangent = vTangent.xyz;
|
||||
outv.vBinormal = vBinormal.xyz;
|
||||
outv.vTexcoord = mesh.vTexcoord;
|
||||
|
||||
gSkinngMeshOutput[iIndex] = outv;
|
||||
gBoneMatrixOutput[boneIndex].LocalMatrix = local;
|
||||
gBoneMatrixOutput[boneIndex].CombinedMatrix = combined;
|
||||
}
|
||||
|
||||
@@ -187,6 +187,24 @@ void CAnimation::InterpAnim(CAnimation* pPreAnim, vector<CBone*>& Bones, float f
|
||||
|
||||
#ifdef EDITOR_PROJECT
|
||||
|
||||
void CAnimation::Set_KeyFrameDesc()
|
||||
{
|
||||
for (auto& Channel : m_Channels)
|
||||
{
|
||||
m_KeyFrame.push_back(Channel->Get_KeyFrameDesc());
|
||||
}
|
||||
}
|
||||
|
||||
_uint CAnimation::Get_KeyFrameCount()
|
||||
{
|
||||
for (auto& Channel : m_Channels)
|
||||
{
|
||||
m_KeyCount+=Channel->Get_KeyFrameCount();
|
||||
}
|
||||
|
||||
return m_KeyCount;
|
||||
}
|
||||
|
||||
HRESULT CAnimation::Initialize(const vector<CBone*>& Bones, const aiAnimation* pAIAnimation)
|
||||
{
|
||||
m_strName = pAIAnimation->mName.data;
|
||||
@@ -216,6 +234,8 @@ HRESULT CAnimation::Initialize(const vector<CBone*>& Bones, const aiAnimation* p
|
||||
if (FAILED(Combined_Initialize())) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnimation::SaveAsBinary(HANDLE hFile, DWORD& dwByte)
|
||||
|
||||
@@ -54,6 +54,12 @@ HRESULT CChannel::Initialize(const vector<CBone*>& Bones, const aiNodeAnim* pAIC
|
||||
KeyFrame.vRotation = vRotation;
|
||||
KeyFrame.vTranslation = vTranslation;
|
||||
|
||||
|
||||
m_KeyFrame.fTrackPosition = KeyFrame.fTrackPosition;
|
||||
m_KeyFrame.vScale = vScale;
|
||||
m_KeyFrame.vRotation = vRotation;
|
||||
m_KeyFrame.vTranslation = vTranslation;
|
||||
|
||||
m_KeyFrames.push_back(KeyFrame);
|
||||
}
|
||||
|
||||
@@ -301,6 +307,11 @@ HRESULT CChannel::Initialize(const CModel* pModel, SaveChannel* pSaveChannel)
|
||||
KeyFrame.vRotation = vRotation;
|
||||
KeyFrame.vTranslation = vTranslation;
|
||||
|
||||
m_KeyFrame.fTrackPosition = KeyFrame.fTrackPosition;
|
||||
m_KeyFrame.vScale = vScale;
|
||||
m_KeyFrame.vRotation = vRotation;
|
||||
m_KeyFrame.vTranslation = vTranslation;
|
||||
|
||||
m_KeyFrames.push_back(KeyFrame);
|
||||
}
|
||||
|
||||
|
||||
@@ -289,7 +289,7 @@ HRESULT CMesh::Initialize_Prototype(MODEL eType, const CModel* pModel, SaveMesh*
|
||||
|
||||
#pragma endregion
|
||||
|
||||
Create_RawVB(m_RawVertices);
|
||||
//Create_RawVB(m_RawVertices);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
@@ -507,20 +507,6 @@ HRESULT CMesh::Ready_VertexBuffer_For_Anim(const CModel* pModel, SaveMesh* _Save
|
||||
if (FAILED(m_pDevice->CreateBuffer(&VBDesc, &InitialVBData, &m_pVB)))
|
||||
return E_FAIL;
|
||||
|
||||
|
||||
m_RawVertices.resize(m_iNumVertices);
|
||||
|
||||
for (_uint i = 0; i < m_iNumVertices; i++)
|
||||
{
|
||||
m_RawVertices[i].vPosition = pVertices[i].vPosition;
|
||||
m_RawVertices[i].vNormal = pVertices[i].vNormal;
|
||||
m_RawVertices[i].vTangent = pVertices[i].vTangent;
|
||||
m_RawVertices[i].vBinormal = pVertices[i].vBinormal;
|
||||
m_RawVertices[i].vTexcoord = pVertices[i].vTexcoord;
|
||||
|
||||
m_RawVertices[i].vBlendIndex = pVertices[i].vBlendIndex;
|
||||
m_RawVertices[i].vBlendWeight = pVertices[i].vBlendWeight;
|
||||
}
|
||||
|
||||
Safe_Delete_Array(pVertices);
|
||||
|
||||
@@ -528,61 +514,6 @@ HRESULT CMesh::Ready_VertexBuffer_For_Anim(const CModel* pModel, SaveMesh* _Save
|
||||
}
|
||||
|
||||
|
||||
HRESULT CMesh::Create_RawVB(vector<MESH_DESC>& RawVertices)
|
||||
{
|
||||
m_iRawVertexStride = sizeof(MESH_DESC);
|
||||
|
||||
D3D11_BUFFER_DESC desc{};
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.ByteWidth = m_iRawVertexStride *m_iNumVertices;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.StructureByteStride = m_iRawVertexStride;
|
||||
desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
|
||||
|
||||
D3D11_SUBRESOURCE_DATA init{};
|
||||
init.pSysMem = RawVertices.data();
|
||||
|
||||
m_pDevice->CreateBuffer(&desc, &init, &m_pVBMesh);
|
||||
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
void CMesh::ComputSkinning(CComputeShader* ComputeShader, ID3D11Buffer* ConstantBuffer)
|
||||
{
|
||||
if (ComputeShader == nullptr)
|
||||
return;
|
||||
|
||||
_uint iGroupCountX = (m_iNumVertices + 255) / 256;
|
||||
|
||||
ID3D11Buffer* CSBuffers[] = {
|
||||
m_pVBMesh
|
||||
};
|
||||
|
||||
vector<D3D11_MAPPED_SUBRESOURCE> OutSubResources = {};
|
||||
D3D11_MAPPED_SUBRESOURCE VBInstanceResource = {};
|
||||
|
||||
OutSubResources = ComputeShader->Dispatch(0, 0, _float3((_float)iGroupCountX, 1.f, 1.f), CSBuffers, ConstantBuffer);
|
||||
}
|
||||
|
||||
void CMesh::FillBoneDesc(const vector<_float4x4>& CombinedMatrices, BONE_DESC* pOut)
|
||||
{
|
||||
for (size_t i = 0; i < m_iNumBones; ++i)
|
||||
{
|
||||
const _float4x4& offset = m_offsetMatrices[i];
|
||||
const _float4x4& combined = CombinedMatrices[m_BoneIndices[i]];
|
||||
|
||||
_matrix matOffset = XMLoadFloat4x4(&offset);
|
||||
_matrix matCombined = XMLoadFloat4x4(&combined);
|
||||
|
||||
XMStoreFloat4x4(&pOut->BoneMatrix[i], matOffset * matCombined);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
HRESULT CMesh::Initialize(void* pArg)
|
||||
{
|
||||
return S_OK;
|
||||
@@ -891,7 +822,6 @@ void CMesh::Free()
|
||||
__super::Free();
|
||||
|
||||
Safe_Delete_Array(m_pBoneMatrices);
|
||||
SAFE_RELEASE(m_pVBMesh);
|
||||
}
|
||||
|
||||
void CMesh::Describe_Entity()
|
||||
|
||||
@@ -175,30 +175,9 @@ _bool CModel::Play_Animation(_float fTimeDelta,CTransform* pTransform)
|
||||
m_iPreAnimIndex = m_iCurrentAnimIndex;
|
||||
}
|
||||
|
||||
for (_int i = 0; i < m_Bones.size(); ++i)
|
||||
for (auto& pBone : m_Bones)
|
||||
{
|
||||
m_Bones[i]->Update_CombinedTransformationMatrix(m_Bones, XMLoadFloat4x4(&m_PreTransformMatrix));
|
||||
|
||||
if (i == m_iRootBoneIndex) { // 루트본의 매트릭스를 갱신했다면 애니메이션에 맞게 이동량을 루트본에서 트랜스폼으로 보정시킴
|
||||
if (true == m_pLerpAnim->IsLerping()) { // 럴프중이었으면 이동량 반영 x
|
||||
_matrix currAnimMatrix = Get_BoneMatrix(m_iRootBoneIndex);
|
||||
currAnimMatrix.r[3] = XMVectorSet(0.f, 0.f, 0.f, 1.f);
|
||||
m_Bones[i]->Set_CombinedTransformationMatrixPtr(currAnimMatrix);
|
||||
}
|
||||
else {
|
||||
_matrix currAnimMatrix = Get_BoneMatrix(m_iRootBoneIndex); // 현재 루트본의 컴바인드 트랜스폼을 꺼내오고
|
||||
_matrix deltaAnimMatrix = XMMatrixMultiply(XMMatrixInverse(nullptr, m_PrevAnimationMatrix), currAnimMatrix); // 이전 트랜스폼이랑 비교해서 델타매트릭스를 꺼냄
|
||||
_vector momentum = XMMatrixMultiply(deltaAnimMatrix, XMMatrixRotationQuaternion(m_pTransform->Get_QuarternionVector())).r[3];
|
||||
deltaAnimMatrix.r[3] = XMVectorSetW(momentum, 0.f);
|
||||
|
||||
m_pTransform->AccumulateMomentum(deltaAnimMatrix.r[3]); // 모체 트랜스폼에 이동량 반영
|
||||
//m_pTransform->Set_State(STATE::POSITION, m_pTransform->Get_State(STATE::POSITION) + deltaAnimMatrix.r[3]);
|
||||
|
||||
m_PrevAnimationMatrix = currAnimMatrix;
|
||||
currAnimMatrix.r[3] = XMVectorSet(0.f, 0.f, 0.f, 1.f);
|
||||
m_Bones[i]->Set_CombinedTransformationMatrixPtr(currAnimMatrix); // 루트본의 이동량 소거
|
||||
}
|
||||
}
|
||||
pBone->Update_CombinedTransformationMatrix(m_Bones, XMLoadFloat4x4(&m_PreTransformMatrix));
|
||||
}
|
||||
|
||||
if(m_bIsFinishedAnim)
|
||||
@@ -902,73 +881,39 @@ HRESULT CModel::Assimp_Model_Load(const _char* pModelFilePath, MODEL eType, _fma
|
||||
|
||||
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)
|
||||
sizeof(KEYFRAME_DESC),
|
||||
sizeof(BONEINFO_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;
|
||||
}
|
||||
|
||||
_uint CS_OutputStrides[] = {
|
||||
sizeof(BONE_DESC)
|
||||
};
|
||||
|
||||
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);
|
||||
L"../Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl", "CS_MAIN",(_uint)m_Bones.size(), 2, 1, 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);
|
||||
cbDesc.ByteWidth = sizeof(ANIMSTATE_DESC);
|
||||
|
||||
if (FAILED(m_pDevice->CreateBuffer(&cbDesc, nullptr, &m_pConstantBuffer)))
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HRESULT CModel::Bind_CS_Output(_uint Index, _uint iBufferIndex)
|
||||
{
|
||||
if (m_pComputeShader == nullptr)
|
||||
@@ -979,6 +924,92 @@ HRESULT CModel::Bind_CS_Output(_uint Index, _uint iBufferIndex)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void CModel::UpdateAnimationCS()
|
||||
{
|
||||
D3D11_MAPPED_SUBRESOURCE sub{};
|
||||
if (SUCCEEDED(m_pContext->Map(m_pConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &sub)))
|
||||
{
|
||||
ANIMSTATE_DESC* pDesc = (ANIMSTATE_DESC*)sub.pData;
|
||||
|
||||
CAnimation* pAnim = m_Animations[m_iCurrentAnimIndex];
|
||||
pDesc->CurrentTime = pAnim->Get_CurrentTrackPosition();
|
||||
pDesc->Duration = pAnim->Get_Duration();
|
||||
pDesc->Speed = pAnim->Get_AnimSpeed();
|
||||
pDesc->BoneCount = (_uint)m_Bones.size();
|
||||
pDesc->PreTransformMatrix = m_PreTransformMatrix;
|
||||
|
||||
m_pContext->Unmap(m_pConstantBuffer, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void CModel::ComputeAnimation()
|
||||
{
|
||||
UpdateAnimationCS();
|
||||
|
||||
_uint iGroupCountX = ((_uint)m_Bones.size() + 255) / 256;
|
||||
|
||||
ID3D11Buffer* inputs[2] = {
|
||||
m_pKeyFrameBuffer,
|
||||
m_pBoneInfoBuffer
|
||||
};
|
||||
|
||||
vector<D3D11_MAPPED_SUBRESOURCE> OutSubResources = {};
|
||||
D3D11_MAPPED_SUBRESOURCE VBInstanceResource = {};
|
||||
|
||||
OutSubResources = m_pComputeShader->Dispatch(0, 0, _float3((_float)iGroupCountX, 1.f, 1.f), inputs, m_pConstantBuffer);
|
||||
}
|
||||
|
||||
|
||||
HRESULT CModel::Create_KeyFrameVB()
|
||||
{
|
||||
for (_uint i = 0; i < (_uint)m_Animations[m_iCurrentAnimIndex]->Get_KeyCount(); i++)
|
||||
{
|
||||
m_KeyFrame.push_back(m_Animations[m_iCurrentAnimIndex]->Get_KeyFrameDesc(i));
|
||||
}
|
||||
|
||||
|
||||
D3D11_BUFFER_DESC desc{};
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.ByteWidth = (_int)sizeof(KEYFRAME_DESC) * m_Animations[m_iCurrentAnimIndex]->Get_KeyFrameCount();
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.StructureByteStride = (_int)sizeof(KEYFRAME_DESC);
|
||||
desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
|
||||
|
||||
D3D11_SUBRESOURCE_DATA init{};
|
||||
init.pSysMem = m_KeyFrame.data();
|
||||
|
||||
m_pDevice->CreateBuffer(&desc, &init, &m_pKeyFrameBuffer);
|
||||
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CModel::Create_BoneInfoVB()
|
||||
{
|
||||
for (size_t i = 0; i < m_Bones.size(); i++)
|
||||
{
|
||||
m_BoneInfo[i].ParentIndex = m_Bones[i]->Get_ParentBoneIndex();
|
||||
}
|
||||
|
||||
|
||||
D3D11_BUFFER_DESC desc{};
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.ByteWidth = (_int)sizeof(BONEINFO_DESC) * (_uint)m_Bones.size();
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.StructureByteStride = (_int)sizeof(BONEINFO_DESC);
|
||||
desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
|
||||
|
||||
D3D11_SUBRESOURCE_DATA init{};
|
||||
init.pSysMem = m_BoneInfo.data();
|
||||
|
||||
m_pDevice->CreateBuffer(&desc, &init, &m_pBoneInfoBuffer);
|
||||
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void CModel::Get_BoneMatrix()
|
||||
{
|
||||
m_BoneMatrix.resize(m_Bones.size());
|
||||
@@ -988,8 +1019,6 @@ void CModel::Get_BoneMatrix()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
HRESULT CModel::Initialize_Prototype(MODEL eType, const _char* pModelFilePath, _fmatrix PreTransformMatrix)
|
||||
{
|
||||
m_eType = eType;
|
||||
@@ -1327,12 +1356,18 @@ 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;
|
||||
|
||||
if (m_eType == MODEL::ANIM)
|
||||
{
|
||||
Create_Con();
|
||||
|
||||
if (FAILED(Create_CS()))
|
||||
return E_FAIL;
|
||||
|
||||
Create_KeyFrameVB();
|
||||
Create_BoneInfoVB();
|
||||
}
|
||||
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,13 @@ class ENGINE_DLL CAnimation : public CBase
|
||||
_float Get_CurrentTrackPosition() { return m_fCurrentTrackPosition; }
|
||||
void Set_AnimSpeed(_float fSpeed) { m_fAnimSpeed = fSpeed; }
|
||||
_float Get_AnimSpeed() { return m_fAnimSpeed; }
|
||||
|
||||
_uint Get_ChannelCount() { return m_iNumChannels; }
|
||||
_float Get_Duration() { return m_fDuration; }
|
||||
void Set_KeyFrameDesc();
|
||||
KEYFRAME_DESC Get_KeyFrameDesc(_uint iIndex) { return m_KeyFrame[iIndex]; }
|
||||
_uint Get_KeyCount() { return (_uint)m_KeyFrame.size(); }
|
||||
_uint Get_KeyFrameCount();
|
||||
#ifdef EDITOR_PROJECT
|
||||
private:
|
||||
HRESULT Initialize(const vector<class CBone*>& Bones, const aiAnimation* pAIAnimation);
|
||||
@@ -64,6 +71,10 @@ class ENGINE_DLL CAnimation : public CBase
|
||||
vector<_int> m_DestBones; // 이 애니메이션에서 영향을 받는 본들의 집합
|
||||
vector<LERPDESC> m_StartKeyFrames; // 이 애니메이션의 영향을 받는 본들의 초기값
|
||||
vector<_matrix> m_vBoneTransformationMatrix = {};
|
||||
|
||||
_int m_iRawVertexStride = {};
|
||||
vector<KEYFRAME_DESC> m_KeyFrame;
|
||||
_int m_KeyCount = {};
|
||||
public:
|
||||
static CAnimation* Create(HANDLE hFile, DWORD& dwByte);
|
||||
// 바이너리
|
||||
|
||||
@@ -27,14 +27,13 @@ class ENGINE_DLL CBone final : public CBase
|
||||
_float3 Get_LocalPosition();
|
||||
void Update_CombinedTransformationMatrix(const vector<CBone*>& Bones, _fmatrix PreTransformMatrix);
|
||||
void Set_TransformationMatrix(_fmatrix TransformationMatrix); // 애니메이션에서 현재 로컬 매트릭스를 변경할 때 사용된다
|
||||
|
||||
_int Get_ParentBoneIndex() { return m_iParentBoneIndex; }
|
||||
private:
|
||||
_char m_szName[MAX_PATH] = {}; // 본의 이름
|
||||
_float4x4 m_TransformationMatrix = {}; // 본의 현재 로컬 매트릭스
|
||||
_float4x4 m_CombinedTransformationMatrix = {}; // 본의 루트노드로부터 상대적인 복합매트릭스 ( 부모노드는 PreTranformMatrix와 월드좌표로부터 상대적임 )
|
||||
_int m_iParentBoneIndex = { -1 }; // 부모본의 인덱스 ( 모델에 있는 본벡터의 인덱스 ) ( 부모는 인덱스 -1 고정 )
|
||||
_float4x4 m_matInitial = {};
|
||||
|
||||
private:
|
||||
HRESULT Initialize(HANDLE hFile, DWORD& dwByte);
|
||||
// 바이너리
|
||||
@@ -59,4 +58,4 @@ class ENGINE_DLL CBone final : public CBase
|
||||
|
||||
};
|
||||
|
||||
NS_END
|
||||
NS_END
|
||||
|
||||
@@ -35,6 +35,8 @@ class ENGINE_DLL CChannel : public CBase
|
||||
return !strcmp(pChannelname, m_szName);
|
||||
}
|
||||
_char* Get_Name() { return m_szName; }
|
||||
KEYFRAME_DESC Get_KeyFrameDesc() { return m_KeyFrame; }
|
||||
_int Get_KeyFrameCount() { return (_int)m_KeyFrames.size(); }
|
||||
private:
|
||||
HRESULT Initialize(HANDLE hFile, DWORD& dwByte);
|
||||
// 바이너리
|
||||
@@ -53,7 +55,9 @@ class ENGINE_DLL CChannel : public CBase
|
||||
_matrix m_BoneTransformationMatrix = {};
|
||||
_float m_fPrevYaw = 0.f;
|
||||
_bool m_bInitialRootRotSaved = {false};
|
||||
_float4 m_vInitialRootRot = {};
|
||||
_float4 m_vInitialRootRot = {};
|
||||
|
||||
KEYFRAME_DESC m_KeyFrame;
|
||||
public:
|
||||
static CChannel* Create(const vector<class CBone*>& Bones, _uint iIndex); // 럴프전용
|
||||
static CChannel* Create(HANDLE hFile, DWORD& dwByte);
|
||||
|
||||
@@ -358,4 +358,27 @@ typedef struct tagOnCollsionInfo
|
||||
|
||||
}ON_COLLISION_INFO;
|
||||
|
||||
typedef struct tagKeyFrameDesc
|
||||
{
|
||||
_float3 vScale;
|
||||
_float4 vRotation;
|
||||
_float3 vTranslation;
|
||||
_float fTrackPosition;
|
||||
|
||||
}KEYFRAME_DESC;
|
||||
|
||||
typedef struct tagBoneInfo
|
||||
{
|
||||
_int ParentIndex;
|
||||
|
||||
}BONEINFO_DESC;
|
||||
|
||||
|
||||
typedef struct tagBoneMatrix
|
||||
{
|
||||
_float4x4 LocalMatrix;
|
||||
_float4x4 CombinedMatrix;
|
||||
|
||||
}BONE_DESC;
|
||||
|
||||
NS_END
|
||||
|
||||
@@ -6,36 +6,6 @@ NS_BEGIN(Engine)
|
||||
|
||||
class ENGINE_DLL CMesh final : public CVIBuffer
|
||||
{
|
||||
public:
|
||||
typedef struct tagMeshDesc
|
||||
{
|
||||
_float3 vPosition = {};
|
||||
_float3 vNormal = {};
|
||||
_float3 vTangent = {};
|
||||
_float3 vBinormal = {};
|
||||
_float2 vTexcoord = {};
|
||||
|
||||
XMUINT4 vBlendIndex = {};
|
||||
_float4 vBlendWeight = {};
|
||||
|
||||
}MESH_DESC;
|
||||
|
||||
typedef struct tagSkinngMeshDesc
|
||||
{
|
||||
_float3 vPosition = {};
|
||||
_float3 vNormal = {};
|
||||
_float3 vTangent = {};
|
||||
_float3 vBinormal = {};
|
||||
_float2 vTexcoord = {};
|
||||
|
||||
}SKINNG_MESH_DESC;
|
||||
|
||||
typedef struct tagBoneDesc
|
||||
{
|
||||
_float4x4 BoneMatrix[512];
|
||||
}BONE_DESC;
|
||||
|
||||
|
||||
private:
|
||||
CMesh(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
|
||||
CMesh(const CMesh& rhs);
|
||||
@@ -66,10 +36,6 @@ class ENGINE_DLL CMesh final : public CVIBuffer
|
||||
virtual HRESULT Bind_Resources_Instance(ID3D11Buffer* pVBInstance, _uint iInstanceStride, _uint iBufferCount);
|
||||
virtual HRESULT Render_Instance(_uint iNumInstance);
|
||||
|
||||
void ComputSkinning(class CComputeShader* ComputeShader, ID3D11Buffer* ConstantBuffer);
|
||||
|
||||
void FillBoneDesc(const vector<_float4x4>& CombinedMatrices, BONE_DESC* pOut);
|
||||
|
||||
_uint Get_Vertex() { return m_iNumVertices; }
|
||||
private:
|
||||
virtual HRESULT Initialize_Prototype(HANDLE hFile, DWORD& dwByte);
|
||||
@@ -81,7 +47,7 @@ class ENGINE_DLL CMesh final : public CVIBuffer
|
||||
HRESULT Ready_VertexBuffer_For_NonAnim(SaveMesh* _SaveMesh, _fmatrix PreTransformMatrix);
|
||||
HRESULT Ready_VertexBuffer_For_Anim(const class CModel* pModel, SaveMesh* _SaveMesh);
|
||||
|
||||
HRESULT Create_RawVB(vector<MESH_DESC>& RawVertices);
|
||||
|
||||
|
||||
//
|
||||
private:
|
||||
@@ -99,16 +65,9 @@ class ENGINE_DLL CMesh final : public CVIBuffer
|
||||
//
|
||||
|
||||
private:
|
||||
MESH_DESC m_MeshDesc = {};
|
||||
BONE_DESC m_BoneDesc = {};
|
||||
_uint m_iNumBuffer = {};
|
||||
_uint m_iNumMeshes = {};
|
||||
_int m_iRootBoneIndex = { -1 };
|
||||
_int m_iRawVertexStride = {};
|
||||
|
||||
vector<MESH_DESC> m_RawVertices;
|
||||
|
||||
ID3D11Buffer* m_pVBMesh = { nullptr };
|
||||
|
||||
public:
|
||||
static CMesh* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, HANDLE hFile, DWORD& dwByte);
|
||||
|
||||
@@ -7,32 +7,15 @@ NS_BEGIN(Engine)
|
||||
class ENGINE_DLL CModel final : public CComponent
|
||||
{
|
||||
public:
|
||||
typedef struct tagMeshDesc
|
||||
typedef struct tagAnimStateDesc
|
||||
{
|
||||
_float3 vPosition = {};
|
||||
_float3 vNormal = {};
|
||||
_float3 vTangent = {};
|
||||
_float3 vBinormal = {};
|
||||
_float2 vTexcoord = {};
|
||||
_float CurrentTime;
|
||||
_float Duration;
|
||||
_float Speed;
|
||||
_int BoneCount;
|
||||
_float4x4 PreTransformMatrix;
|
||||
|
||||
XMUINT4 vBlendIndex = {};
|
||||
_float4 vBlendWeight = {};
|
||||
}MESH_DESC;
|
||||
|
||||
typedef struct tagSkinngMeshDesc
|
||||
{
|
||||
_float3 vPosition = {};
|
||||
_float3 vNormal = {};
|
||||
_float3 vTangent = {};
|
||||
_float3 vBinormal = {};
|
||||
_float2 vTexcoord = {};
|
||||
|
||||
}SKINNG_MESH_DESC;
|
||||
|
||||
typedef struct tagBoneDesc
|
||||
{
|
||||
_float4x4 BoneMatrix[512];
|
||||
}BONE_DESC;
|
||||
}ANIMSTATE_DESC;
|
||||
|
||||
private:
|
||||
CModel(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
|
||||
@@ -94,9 +77,13 @@ static _int Get_BoneIndex(const _char* pBoneName, vector<class CBone*> Bones); /
|
||||
HRESULT Bind_Material(_uint iMeshIndex, class CShader* pShader);
|
||||
|
||||
#pragma endregion
|
||||
void ComputeSkinning();
|
||||
|
||||
void Create_Con();
|
||||
HRESULT Bind_CS_Output(_uint Index, _uint iBufferIndex);
|
||||
void UpdateAnimationCS();
|
||||
void ComputeAnimation();
|
||||
HRESULT Create_KeyFrameVB();
|
||||
HRESULT Create_BoneInfoVB();
|
||||
void Get_BoneMatrix();
|
||||
|
||||
public:
|
||||
@@ -169,13 +156,15 @@ static _int Get_BoneIndex(const _char* pBoneName, vector<class CBone*> Bones); /
|
||||
private:
|
||||
HRESULT Create_CS();
|
||||
|
||||
MESH_DESC m_MeshDesc = {};
|
||||
BONE_DESC m_BoneDesc = {};
|
||||
_uint m_iNumBuffer = {};
|
||||
vector<KEYFRAME_DESC> m_KeyFrame = {};
|
||||
vector<BONEINFO_DESC> m_BoneInfo = {};
|
||||
|
||||
class CComputeShader* m_pComputeShader = {};
|
||||
ID3D11Buffer* m_pConstantBuffer = { nullptr };
|
||||
_uint AccumulatedVertexCount = {};
|
||||
|
||||
ID3D11Buffer* m_pKeyFrameBuffer = { nullptr };
|
||||
ID3D11Buffer* m_pBoneInfoBuffer = { nullptr };
|
||||
|
||||
private:
|
||||
// 바이너리
|
||||
|
||||
Reference in New Issue
Block a user