diff --git a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Local_Compute.hlsl b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Local_Compute.hlsl index dd8cb9381..602d99a61 100644 --- a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Local_Compute.hlsl +++ b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Local_Compute.hlsl @@ -42,9 +42,9 @@ cbuffer AnimCB : register(b0) float BlendRatio; int RootBoneIndex; + int PlayHeadBone; int HeadBoneIndex; float HeadAimWeight; - float paddding1; float3 TargetDir_Local; float padding; @@ -332,8 +332,45 @@ row_major float4x4 SampleBlendedLocal(uint bone) T = 0; R = RootInitRot; } + + float4x4 M = MakeAffine(S, R, T); + + if (PlayHeadBone == 1) + { + if (bone == HeadBoneIndex && HeadAimWeight > 0.f) + { + float3 curFwd = normalize(float3(M._31, M._32, M._33)); + float3 target = normalize(TargetDir_Local); - return MakeAffine(S, R, T); + float3 axis = cross(curFwd, target); + float axisLen = length(axis); + + if (axisLen > EPS) + { + axis /= axisLen; + + float angle = acos(saturate(dot(curFwd, target))); + angle *= HeadAimWeight; + + float4 qAim = float4(axis * sin(angle * 0.5f), cos(angle * 0.5f)); + qAim = QuatNormalize(qAim); + + row_major float4x4 AimM = + MakeAffine(float3(1, 1, 1), qAim, float3(0, 0, 0)); + + M = mul(AimM, M); + } + } + } + + + + return M; + + + + + //return MakeAffine(S, R, T); } [numthreads(256, 1, 1)] 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 de4ca9daf..6b87a5ef5 100644 --- a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl +++ b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl @@ -24,9 +24,10 @@ cbuffer AnimCB : register(b0) float BlendRatio; int RootBoneIndex; + int PlayHeadBone; int HeadBoneIndex; float HeadAimWeight; - float paddding1; + float3 TargetDir_Local; float padding; diff --git a/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Local_Compute.hlsl b/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Local_Compute.hlsl index d82a9ea23..602d99a61 100644 --- a/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Local_Compute.hlsl +++ b/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Local_Compute.hlsl @@ -42,9 +42,9 @@ cbuffer AnimCB : register(b0) float BlendRatio; int RootBoneIndex; + int PlayHeadBone; int HeadBoneIndex; float HeadAimWeight; - float paddding1; float3 TargetDir_Local; float padding; @@ -333,9 +333,44 @@ row_major float4x4 SampleBlendedLocal(uint bone) R = RootInitRot; } + float4x4 M = MakeAffine(S, R, T); + + if (PlayHeadBone == 1) + { + if (bone == HeadBoneIndex && HeadAimWeight > 0.f) + { + float3 curFwd = normalize(float3(M._31, M._32, M._33)); + float3 target = normalize(TargetDir_Local); + + float3 axis = cross(curFwd, target); + float axisLen = length(axis); + + if (axisLen > EPS) + { + axis /= axisLen; + + float angle = acos(saturate(dot(curFwd, target))); + angle *= HeadAimWeight; + + float4 qAim = float4(axis * sin(angle * 0.5f), cos(angle * 0.5f)); + qAim = QuatNormalize(qAim); + + row_major float4x4 AimM = + MakeAffine(float3(1, 1, 1), qAim, float3(0, 0, 0)); + + M = mul(AimM, M); + } + } + } + + + + return M; + + - return MakeAffine(S, R, T); + //return MakeAffine(S, R, T); } [numthreads(256, 1, 1)] 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 de4ca9daf..6b87a5ef5 100644 --- a/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl +++ b/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Mesh_Compute.hlsl @@ -24,9 +24,10 @@ cbuffer AnimCB : register(b0) float BlendRatio; int RootBoneIndex; + int PlayHeadBone; int HeadBoneIndex; float HeadAimWeight; - float paddding1; + float3 TargetDir_Local; float padding; diff --git a/Jusin154_Team3D/Engine/Private/Model.cpp b/Jusin154_Team3D/Engine/Private/Model.cpp index e13ef7e13..16c6be949 100644 --- a/Jusin154_Team3D/Engine/Private/Model.cpp +++ b/Jusin154_Team3D/Engine/Private/Model.cpp @@ -1708,9 +1708,9 @@ void CModel::ComputeLocal(_uint AnimIndex, _uint MeshIndex) pDesc->PrevTime = m_Animations[m_iPreAnimIndex]->Get_CurrentTrackPosition(); pDesc->BlendRatio = m_fRatio; pDesc->RootBoneIndex = m_iRootBoneIndex; + pDesc->PlayHeadBone = m_bHeadBone; pDesc->HeadBoneIndex = m_iBoneIndex[ENUM_CLASS(BLEND_BONE::HEAD)]; pDesc->HeadAimWeight = 1.f; - pDesc->paddding1 = 0.f; if (m_iBoneIndex[ENUM_CLASS(BLEND_BONE::HEAD)] != -1) { _vector dirWS = XMVector3Normalize(m_vTargetPos - m_pTransform->Get_State(STATE::POSITION)); diff --git a/Jusin154_Team3D/Engine/Public/Model.h b/Jusin154_Team3D/Engine/Public/Model.h index 4aeb61011..260168000 100644 --- a/Jusin154_Team3D/Engine/Public/Model.h +++ b/Jusin154_Team3D/Engine/Public/Model.h @@ -20,9 +20,9 @@ class ENGINE_DLL CModel final : public CComponent _float BlendRatio; _int RootBoneIndex; + _int PlayHeadBone; _int HeadBoneIndex; _float HeadAimWeight; - _float paddding1; _float3 TargetDir_Local; _float padding; @@ -50,6 +50,7 @@ class ENGINE_DLL CModel final : public CComponent void Set_Temp(_bool Temp) { m_bTemp = Temp; } void Set_TargetPos(_vector vTargetPos) { m_vTargetPos = vTargetPos; } void Set_HeadPos(_vector vHeadPos) { m_vHeadPos = vHeadPos; } + void Play_HeadBone(_bool bPlay) { m_bHeadBone = bPlay; } #pragma endregion #pragma region Animation _bool Play_Animation(_float fTimeDelta, class CTransform* pTransform = nullptr); // 애니메이션에 델타타임을 넣어줌 @@ -204,6 +205,7 @@ class ENGINE_DLL CModel final : public CComponent _bool m_bTemp = {false}; _vector m_vTargetPos = XMVectorZero(); _vector m_vHeadPos = XMVectorZero(); + _bool m_bHeadBone = { false }; private: