[add] MB Spread

This commit is contained in:
kimnuri
2025-12-21 11:41:48 +09:00
parent 25f3eef86a
commit dc5b8dbe00
19 changed files with 131 additions and 26 deletions
@@ -191,6 +191,7 @@ HRESULT CGoblin::Render()
}
m_pModelCom->Bind_OutPut_SRV_VS(31, 0);
m_pModelCom->Bind_OutPut_SRV_VS_Prev(32, 0);
if (FAILED(m_pModelCom->Render(i))) {
return E_FAIL;
@@ -193,6 +193,7 @@ HRESULT CGoblin_Mage::Render()
}
m_pModelCom->Bind_OutPut_SRV_VS(31, 0);
m_pModelCom->Bind_OutPut_SRV_VS_Prev(32, 0);
if (FAILED(m_pModelCom->Render(i))) {
return E_FAIL;
@@ -179,6 +179,7 @@ HRESULT CGoblin_Spector::Render()
}
m_pModelCom->Bind_OutPut_SRV_VS(31, 0);
m_pModelCom->Bind_OutPut_SRV_VS_Prev(32, 0);
if (FAILED(m_pModelCom->Render(i))) {
return E_FAIL;
@@ -272,6 +272,7 @@ HRESULT CPlayer::Render()
m_pModelCom->Bind_OutPut_SRV_VS(31, 0);
m_pModelCom->Bind_OutPut_SRV_VS_Prev(32, 0);
if (FAILED(m_pModelCom->Render(i))) {
return E_FAIL;
@@ -189,6 +189,7 @@ HRESULT CRanrak::Render()
}
m_pModelCom->Bind_OutPut_SRV_VS(31, 0);
m_pModelCom->Bind_OutPut_SRV_VS_Prev(32, 0);
if (FAILED(m_pModelCom->Render(i))) {
return E_FAIL;
+2
View File
@@ -199,6 +199,7 @@ HRESULT CTroll::Render()
}
m_pModelCom->Bind_OutPut_SRV_VS(26, 0);
m_pModelCom->Bind_OutPut_SRV_VS_Prev(27, 0);
if (FAILED(m_pModelCom->Render(i))) {
return E_FAIL;
@@ -278,6 +279,7 @@ HRESULT CTroll::Render_OutLine()
}
m_pModelCom->Bind_OutPut_SRV_VS(26, 0);
m_pModelCom->Bind_OutPut_SRV_VS_Prev(27, 0);
if (FAILED(m_pModelCom->Render(i))) {
return E_FAIL;
@@ -326,6 +326,13 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLUR(PS_IN In)
}
float4 vBlurredColor = vAccColorSum / max(fAccWeight, FLT_EPSILON5);
float2 vBlurredVelo = vAccVeloSum / max(fAccWeight, FLT_EPSILON5);
if (length(vAccVeloSum) < FLT_EPSILON5)
{
Out.vColor = g_ColorTexture.Sample(ClampLinearSampler, vCenterUV);
Out.vVelocity = float2(0.5f, 0.5f);
return Out;
}
Out.vColor = vBlurredColor;
Out.vVelocity = vBlurredVelo * 0.5f + 0.5f;
return Out;
@@ -54,6 +54,7 @@ Texture2D g_Maya_Specular_RoughnessTexture;
Texture2D g_AnisotropyTexture;
StructuredBuffer<BoneOut> g_BoneBuffer : register(t26);
StructuredBuffer<BoneOut> g_PrevBoneBuffer : register(t27);
Texture2D g_SurfaceParamsTexture;
@@ -132,8 +133,19 @@ VS_OUT VS_MAIN(VS_IN In)
g_BoneBuffer[In.vBlendIndex.z].LocalCombined) * w.z
+ mul(g_OffsetMatrix[In.vBlendIndex.w],
g_BoneBuffer[In.vBlendIndex.w].LocalCombined) * w.w;
matrix PrevBoneMatrix =
mul(g_OffsetMatrix[In.vBlendIndex.x],
g_PrevBoneBuffer[In.vBlendIndex.x].LocalCombined) * w.x
+ mul(g_OffsetMatrix[In.vBlendIndex.y],
g_PrevBoneBuffer[In.vBlendIndex.y].LocalCombined) * w.y
+ mul(g_OffsetMatrix[In.vBlendIndex.z],
g_PrevBoneBuffer[In.vBlendIndex.z].LocalCombined) * w.z
+ mul(g_OffsetMatrix[In.vBlendIndex.w],
g_PrevBoneBuffer[In.vBlendIndex.w].LocalCombined) * w.w;
vector vPosition = mul(vector(In.vPosition, 1.f), BoneMatrix);
vector vPrevPosition = mul(vector(In.vPosition, 1.f), PrevBoneMatrix);
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);
@@ -154,7 +166,7 @@ VS_OUT VS_MAIN(VS_IN In)
Out.vTexcoord = In.vTexcoord;
Out.vWorldPos = mul(vPosition, g_WorldMatrix);
Out.vProjPos = Out.vPosition;
Out.vPrevProjPos = mul(vector(In.vPosition, 1.f), matPrevWVP);
Out.vPrevProjPos = mul(vPrevPosition, matPrevWVP);
return Out;
}
@@ -176,11 +188,24 @@ VS_OUT VS_MAIN_OUTLINE_READ(VS_IN In)
+ mul(g_OffsetMatrix[In.vBlendIndex.w],
g_BoneBuffer[In.vBlendIndex.w].LocalCombined) * w.w;
matrix PrevBoneMatrix =
mul(g_OffsetMatrix[In.vBlendIndex.x],
g_PrevBoneBuffer[In.vBlendIndex.x].LocalCombined) * w.x
+ mul(g_OffsetMatrix[In.vBlendIndex.y],
g_PrevBoneBuffer[In.vBlendIndex.y].LocalCombined) * w.y
+ mul(g_OffsetMatrix[In.vBlendIndex.z],
g_PrevBoneBuffer[In.vBlendIndex.z].LocalCombined) * w.z
+ mul(g_OffsetMatrix[In.vBlendIndex.w],
g_PrevBoneBuffer[In.vBlendIndex.w].LocalCombined) * w.w;
vector vPosition = mul(vector(In.vPosition, 1.f), BoneMatrix);
vector vPrevPosition = mul(vector(In.vPosition, 1.f), PrevBoneMatrix);
vector vNormal = mul(vector(In.vNormal, 0.f), BoneMatrix);
vector vPrevNormal = mul(vector(In.vNormal, 0.f), PrevBoneMatrix);
vector vBinormal = mul(vector(In.vBinormal, 0.f), BoneMatrix);
vector vTangent = mul(vector(In.vTangent, 0.f), BoneMatrix);
vPosition.xyz += (vNormal.xyz * g_fOutLineThickness).xyz;
vPrevPosition.xyz += (vPrevNormal.xyz * g_fOutLineThickness).xyz;
matrix matWV, matWVP;
@@ -198,7 +223,7 @@ VS_OUT VS_MAIN_OUTLINE_READ(VS_IN In)
Out.vTexcoord = In.vTexcoord;
Out.vWorldPos = mul(vPosition, g_WorldMatrix);
Out.vProjPos = Out.vPosition;
Out.vPrevProjPos = mul(vPosition, matPrevWVP);
Out.vPrevProjPos = mul(vPrevPosition, matPrevWVP);
return Out;
}
@@ -72,6 +72,7 @@ Texture2D g_AnisotropyTexture : register(t30);
StructuredBuffer<BoneOut> g_BoneBuffer : register(t31);
StructuredBuffer<BoneOut> g_PrevBoneBuffer : register(t32);
int g_iBinded_Texture[27];
@@ -133,8 +134,20 @@ VS_OUT VS_MAIN(VS_IN In)
g_BoneBuffer[In.vBlendIndex.w].LocalCombined) * w.w;
matrix PrevBoneMatrix =
mul(g_OffsetMatrix[In.vBlendIndex.x],
g_PrevBoneBuffer[In.vBlendIndex.x].LocalCombined) * w.x
+ mul(g_OffsetMatrix[In.vBlendIndex.y],
g_PrevBoneBuffer[In.vBlendIndex.y].LocalCombined) * w.y
+ mul(g_OffsetMatrix[In.vBlendIndex.z],
g_PrevBoneBuffer[In.vBlendIndex.z].LocalCombined) * w.z
+ mul(g_OffsetMatrix[In.vBlendIndex.w],
g_PrevBoneBuffer[In.vBlendIndex.w].LocalCombined) * w.w;
float4 skinnedPos = mul(float4(In.vPosition, 1.f), BoneMatrix);
float4 skinnedPrevPos = mul(float4(In.vPosition, 1.f), PrevBoneMatrix);
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;
@@ -154,11 +167,7 @@ VS_OUT VS_MAIN(VS_IN In)
Out.vTexcoord = In.vTexcoord;
Out.vWorldPos = mul(skinnedPos, g_WorldMatrix);
Out.vProjPos = Out.vPosition;
Out.vPrevProjPos = mul(skinnedPos, matPrevWVP);
Out.vTexcoord = In.vTexcoord;
Out.vProjPos = Out.vPosition;
Out.vPrevProjPos = mul(skinnedPos, matPrevWVP);
Out.vPrevProjPos = mul(skinnedPrevPos, matPrevWVP);
return Out;
}
@@ -194,11 +203,24 @@ VS_OUT_OUTLINE VS_MAIN_OUTLINE(VS_IN In)
+ mul(g_OffsetMatrix[In.vBlendIndex.w],
g_BoneBuffer[In.vBlendIndex.w].LocalCombined) * w.w;
matrix PrevBoneMatrix =
mul(g_OffsetMatrix[In.vBlendIndex.x],
g_PrevBoneBuffer[In.vBlendIndex.x].LocalCombined) * w.x
+ mul(g_OffsetMatrix[In.vBlendIndex.y],
g_PrevBoneBuffer[In.vBlendIndex.y].LocalCombined) * w.y
+ mul(g_OffsetMatrix[In.vBlendIndex.z],
g_PrevBoneBuffer[In.vBlendIndex.z].LocalCombined) * w.z
+ mul(g_OffsetMatrix[In.vBlendIndex.w],
g_PrevBoneBuffer[In.vBlendIndex.w].LocalCombined) * w.w;
vector vPosition = mul(vector(In.vPosition, 1.f), BoneMatrix);
vector vPrevPosition = mul(vector(In.vPosition, 1.f), PrevBoneMatrix);
vector vNormal = mul(vector(In.vNormal, 0.f), BoneMatrix);
vector vPrevNormal = mul(vector(In.vNormal, 0.f), PrevBoneMatrix);
vector vBinormal = mul(vector(In.vBinormal, 0.f), BoneMatrix);
vector vTangent = mul(vector(In.vTangent, 0.f), BoneMatrix);
vPosition.xyz += (vNormal.xyz * g_fOutLineThickness).xyz;
vPrevPosition.xyz += (vPrevNormal.xyz * g_fOutLineThickness).xyz;
matrix matWV, matWVP;
@@ -216,7 +238,7 @@ VS_OUT_OUTLINE VS_MAIN_OUTLINE(VS_IN In)
Out.vTexcoord = In.vTexcoord;
Out.vWorldPos = mul(vPosition, g_WorldMatrix);
Out.vProjPos = Out.vPosition;
Out.vPrevProjPos = mul(vPosition, matPrevWVP);
Out.vPrevProjPos = mul(vPrevPosition, matPrevWVP);
return Out;
}
struct VS_OUT_CAPTUREDMODEL
@@ -1,6 +1,7 @@
#include "Engine_Shader_Defines.hlsli"
matrix g_WorldMatrix, g_ViewMatrix, g_ProjMatrix;
float4x4 g_PrevWorldMatrix, g_PrevViewMatrix, g_PrevProjMatrix;
Texture2D g_DiffuseTexture;
Texture2D g_NormalTexture;
@@ -34,6 +35,7 @@ struct VS_OUT
float2 vTexcoord : TEXCOORD0;
float4 vWorldPos : TEXCOORD2;
float4 vProjPos : TEXCOORD3;
float4 vPrevProjPos : TEXCOORD4;
};
VS_OUT VS_MAIN(VS_IN In, uint iGPUIndex : SV_InstanceID)
@@ -41,12 +43,17 @@ VS_OUT VS_MAIN(VS_IN In, uint iGPUIndex : SV_InstanceID)
VS_OUT Out = (VS_OUT) 0;
matrix matW, matWV, matWVP;
matrix matPrevW, matPrevWV, matPrevWVP;
row_major matrix TransformMatrix = float4x4(In.vRight, In.vUp, In.vLook, In.vTranslation);
matW = TransformMatrix;
matWV = mul(matW, g_ViewMatrix);
matWVP = mul(matWV, g_ProjMatrix);
matPrevW = TransformMatrix;
matPrevWV = mul(matW, g_ViewMatrix);
matPrevWVP = mul(matWV, g_ProjMatrix);
vector vPosition = mul(vector(In.vPosition, 1.f), matWVP);
@@ -57,6 +64,7 @@ VS_OUT VS_MAIN(VS_IN In, uint iGPUIndex : SV_InstanceID)
Out.vTexcoord = In.vTexcoord;
Out.vWorldPos = mul(vector(In.vPosition, 1.f), matW);
Out.vProjPos = vPosition;
Out.vPrevProjPos = mul(vector(In.vPosition, 1.f), matPrevWVP);
return Out;
}
@@ -70,6 +78,7 @@ struct PS_IN
float2 vTexcoord : TEXCOORD0;
float4 vWorldPos : TEXCOORD2;
float4 vProjPos : TEXCOORD3;
float4 vPrevProjPos : TEXCOORD4;
};
struct PS_OUT
@@ -79,6 +88,7 @@ struct PS_OUT
float4 vDepth : SV_TARGET2;
float4 vColor : SV_Target3;
float4 vSurface : SV_Target4;
float2 vVelocityUV : SV_Target5;
};
PS_OUT PS_MAIN(PS_IN In)
@@ -102,7 +112,8 @@ PS_OUT PS_MAIN(PS_IN In)
Out.vDepth = float4(In.vProjPos.z / In.vProjPos.w, In.vProjPos.w / g_fFar, g_fUsingSurfaceParams, 0.0f);
Out.vColor = float4(0.f, 0.f, 0.f, 1.f);
Out.vSurface = float4(g_SurfaceParamsTexture.Sample(DefaultSampler, In.vTexcoord).xy, 1.f, 1.f);
Out.vVelocityUV = CalcVelocityUV(In.vProjPos, In.vPrevProjPos);
return Out;
}
@@ -81,6 +81,7 @@ HRESULT CDummyObject::Render()
m_pModelCom->Bind_OutPut_SRV_VS(31, 0);
m_pModelCom->Bind_OutPut_SRV_VS_Prev(32, 0);
if (FAILED(m_pModelCom->Render(i))) {
return E_FAIL;
@@ -163,6 +163,7 @@ HRESULT CGoblin::Render()
}
m_pModelCom->Bind_OutPut_SRV_VS(31, 0);
m_pModelCom->Bind_OutPut_SRV_VS_Prev(32, 0);
if (FAILED(m_pModelCom->Render(i))) {
return E_FAIL;
@@ -134,6 +134,7 @@ HRESULT CGoblin_Spector::Render()
}
m_pModelCom->Bind_OutPut_SRV_VS(31, 0);
m_pModelCom->Bind_OutPut_SRV_VS_Prev(32, 0);
if (FAILED(m_pModelCom->Render(i))) {
return E_FAIL;
@@ -173,6 +173,7 @@ HRESULT CPlayer::Render()
}
m_pModelCom->Bind_OutPut_SRV_VS(31, 0);
m_pModelCom->Bind_OutPut_SRV_VS_Prev(32, 0);
if (FAILED(m_pModelCom->Render(i))) {
return E_FAIL;
+1
View File
@@ -207,6 +207,7 @@ HRESULT CTroll::Render()
}
m_pModelCom->Bind_OutPut_SRV_VS(31, 0);
m_pModelCom->Bind_OutPut_SRV_VS_Prev(32, 0);
if (FAILED(m_pModelCom->Render(i))) {
return E_FAIL;
@@ -326,6 +326,13 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLUR(PS_IN In)
}
float4 vBlurredColor = vAccColorSum / max(fAccWeight, FLT_EPSILON5);
float2 vBlurredVelo = vAccVeloSum / max(fAccWeight, FLT_EPSILON5);
if (length(vAccVeloSum) < FLT_EPSILON5)
{
Out.vColor = g_ColorTexture.Sample(ClampLinearSampler, vCenterUV);
Out.vVelocity = float2(0.5f, 0.5f);
return Out;
}
Out.vColor = vBlurredColor;
Out.vVelocity = vBlurredVelo * 0.5f + 0.5f;
return Out;
+29 -8
View File
@@ -1503,7 +1503,13 @@ HRESULT CModel::Create_BoneMatrixVB()
desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
HRESULT hr = m_pDevice->CreateBuffer(&desc, nullptr, &m_pBoneMatrixBuffer);
if (FAILED(hr)) {
return E_FAIL;
}
hr = m_pDevice->CreateBuffer(&desc, nullptr, &m_pPrevBoneMatrixBuffer);
if (FAILED(hr)) {
return E_FAIL;
}
D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc{};
uavDesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
@@ -1511,11 +1517,9 @@ HRESULT CModel::Create_BoneMatrixVB()
uavDesc.Buffer.FirstElement = 0;
uavDesc.Buffer.NumElements = (_uint)m_Bones.size();
m_pDevice->CreateUnorderedAccessView(
m_pBoneMatrixBuffer,
&uavDesc,
&m_pBoneMatrixUAV
);
if(FAILED(m_pDevice->CreateUnorderedAccessView(m_pBoneMatrixBuffer, &uavDesc, &m_pBoneMatrixUAV))){
return E_FAIL;
}
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc1 = {};
srvDesc1.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
@@ -1523,8 +1527,13 @@ HRESULT CModel::Create_BoneMatrixVB()
srvDesc1.Buffer.FirstElement = 0;
srvDesc1.Buffer.NumElements = (_uint)m_Bones.size();
if (FAILED(m_pDevice->CreateShaderResourceView(m_pBoneMatrixBuffer, &srvDesc1, &m_pBoneMatrixSRV)))
if (FAILED(m_pDevice->CreateShaderResourceView(m_pBoneMatrixBuffer, &srvDesc1, &m_pBoneMatrixSRV))){
return E_FAIL;
}
if (FAILED(m_pDevice->CreateShaderResourceView(m_pPrevBoneMatrixBuffer, &srvDesc1, &m_pPrevBoneMatrixSRV))){
return E_FAIL;
}
return S_OK;
@@ -1619,6 +1628,9 @@ HRESULT CModel::Create_Local()
void CModel::ComputeAnimation(_uint AnimIndex,_uint MeshIndex)
{
// MotionBlurr용 버퍼 카피
m_pContext->CopyResource(m_pPrevBoneMatrixBuffer, m_pBoneMatrixBuffer);
ComputeLocal(AnimIndex,MeshIndex);
if (m_pComputeShader == nullptr)
@@ -1754,6 +1766,13 @@ void CModel::Bind_OutPut_SRV_VS(_uint iIndex, _uint iBufferIndex)
&m_pBoneMatrixSRV);
}
void CModel::Bind_OutPut_SRV_VS_Prev(_uint iIndex, _uint iBufferIndex)
{
m_pContext->VSSetShaderResources(iIndex,
1, // 버퍼 개수
&m_pPrevBoneMatrixSRV);
}
#ifdef _DEBUG
HRESULT CModel::Initialize_Prototype(MODEL eType, const _char* pModelFilePath, _fmatrix PreTransformMatrix, _uint iLevel)
@@ -2328,10 +2347,12 @@ void CModel::Free()
SAFE_RELEASE(m_pParentBuffer);
SAFE_RELEASE(m_pBoneLocalBuffer);
SAFE_RELEASE(m_pBoneMatrixBuffer);
SAFE_RELEASE(m_pPrevBoneMatrixBuffer);
SAFE_RELEASE(m_pLocalMatrixBuffer);
SAFE_RELEASE(m_pParentSRV);
SAFE_RELEASE(m_pParentSRV);
SAFE_RELEASE(m_pBoneLocalSRV);
SAFE_RELEASE(m_pBoneMatrixSRV);
SAFE_RELEASE(m_pPrevBoneMatrixSRV);
SAFE_RELEASE(m_pBoneMatrixUAV);
SAFE_RELEASE(m_pLocalMatrixSRV);
SAFE_RELEASE(m_pLocalMatrixUAV);
@@ -223,9 +223,6 @@ HRESULT CShader::Begin(_uint iPassIndex)
m_pContext->IASetInputLayout(m_InputLayouts[iPassIndex]);
/* Apply를 반드시 호출해야만 쉐이더로 그려진다. */
/* Apply이전에 쉐이더에 전달할 모든 데이터들을 다 던져놓아야한다. */
m_pEffect->GetTechniqueByIndex(0)->GetPassByIndex(iPassIndex)->Apply(0, m_pContext);
return S_OK;
+9 -6
View File
@@ -98,6 +98,7 @@ class ENGINE_DLL CModel final : public CComponent
void ComputeAnimation(_uint AnimIndex, _uint MeshIndex);
void ComputeLocal(_uint AnimIndex, _uint MeshIndex);
void Bind_OutPut_SRV_VS(_uint iIndex, _uint iBufferIndex);
void Bind_OutPut_SRV_VS_Prev(_uint iIndex, _uint iBufferIndex);
void ComputeAnimation_Second(_uint AnimIndex);
void InItialize_BoneIndex();
@@ -229,17 +230,19 @@ class ENGINE_DLL CModel final : public CComponent
ID3D11Buffer* m_pConstantBuffer = { nullptr };
ID3D11Buffer* m_pParentBuffer = { nullptr };
ID3D11Buffer* m_pBoneMatrixBuffer = { nullptr };
ID3D11Buffer* m_pPrevBoneMatrixBuffer = { nullptr };
ID3D11Buffer* m_pBoneLocalBuffer = { nullptr };
ID3D11Buffer* m_pLocalMatrixBuffer = { nullptr };
ID3D11ShaderResourceView* m_pParentSRV = {};
ID3D11ShaderResourceView* m_pBoneLocalSRV = {};
ID3D11ShaderResourceView* m_pBoneMatrixSRV = {};
ID3D11ShaderResourceView* m_pLocalMatrixSRV = {};
ID3D11ShaderResourceView* m_pParentSRV = { nullptr };
ID3D11ShaderResourceView* m_pBoneLocalSRV = { nullptr };
ID3D11ShaderResourceView* m_pBoneMatrixSRV = { nullptr };
ID3D11ShaderResourceView* m_pPrevBoneMatrixSRV = { nullptr };
ID3D11ShaderResourceView* m_pLocalMatrixSRV = { nullptr };
ID3D11UnorderedAccessView* m_pBoneMatrixUAV = {};
ID3D11UnorderedAccessView* m_pLocalMatrixUAV = {};
ID3D11UnorderedAccessView* m_pBoneMatrixUAV = { nullptr };
ID3D11UnorderedAccessView* m_pLocalMatrixUAV = { nullptr };
#pragma endregion