[Add] 컴쉐적용

This commit is contained in:
hyunbin14
2025-12-17 19:49:48 +09:00
parent 11a7e14536
commit 651d85b45f
37 changed files with 1629 additions and 501 deletions
@@ -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<KeyFrame> g_KeyFrameBuffer : register(t0);
StructuredBuffer<Channel> g_ChannelBuffer : register(t1);
StructuredBuffer<KeyFrame> g_PrevKeyFrameBuffer : register(t2);
StructuredBuffer<Channel> g_PrevChannelBuffer : register(t3);
StructuredBuffer<int> g_ParentBuffer : register(t4);
StructuredBuffer<BoneLocal> g_BoneLocalBuffer : register(t5);
StructuredBuffer<uint> g_BoneRemap : register(t6);
RWStructuredBuffer<LocalPos> 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;
}
}
}
@@ -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<BoneOut> 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);
@@ -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<BoneOut> 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);
+16 -3
View File
@@ -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;
}
@@ -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;
}
+12 -4
View File
@@ -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;
}
+8 -1
View File
@@ -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;
}
+12 -10
View File
@@ -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);
}