From 734544ea40bbea6cc9a8e9e619fd4785081c6e45 Mon Sep 17 00:00:00 2001 From: kimnuri Date: Tue, 16 Dec 2025 00:41:15 +0900 Subject: [PATCH] [add] BakedShadow --- .../Client/Private/Camera_Debug.cpp | 8 +- Jusin154_Team3D/Client/Private/Land.cpp | 22 +++++ .../Client/Private/Level_Loading.cpp | 52 +++-------- Jusin154_Team3D/Client/Private/Light_Main.cpp | 93 +++++++++++++++++-- .../Client/Private/MapObject_Render.cpp | 5 +- Jusin154_Team3D/Client/Public/Land.h | 1 + Jusin154_Team3D/Client/Public/Level_Loading.h | 3 +- Jusin154_Team3D/Client/Public/Light_Main.h | 4 +- .../ShaderFiles/Shader_Deferred.hlsl | 8 +- .../ShaderFiles/Shader_VtxAnimMesh.hlsl | 2 +- .../Resources/ShaderFiles/Shader_VtxMesh.hlsl | 2 +- .../ShaderFiles/Shader_VtxNorTex.hlsl | 2 +- .../ShaderFiles/Shader_Deferred.hlsl | 8 +- .../Engine/Private/GameInstance.cpp | 9 +- Jusin154_Team3D/Engine/Private/PipeLine.cpp | 3 + Jusin154_Team3D/Engine/Private/Renderer.cpp | 36 ++++--- Jusin154_Team3D/Engine/Private/Transform.cpp | 10 +- Jusin154_Team3D/Engine/Public/Engine_Enum.h | 4 +- Jusin154_Team3D/Engine/Public/Engine_Macro.h | 3 + Jusin154_Team3D/Engine/Public/GameInstance.h | 3 +- Jusin154_Team3D/Engine/Public/Renderer.h | 7 +- Jusin154_Team3D/Engine/Public/Transform.h | 2 +- 22 files changed, 185 insertions(+), 102 deletions(-) diff --git a/Jusin154_Team3D/Client/Private/Camera_Debug.cpp b/Jusin154_Team3D/Client/Private/Camera_Debug.cpp index 782382ece..2920c5b3c 100644 --- a/Jusin154_Team3D/Client/Private/Camera_Debug.cpp +++ b/Jusin154_Team3D/Client/Private/Camera_Debug.cpp @@ -21,10 +21,6 @@ void CCamera_Debug::Priority_Update(_float fTimeDelta) m_pGameInstance->Bind_Camera(g_iStaticLevel, CAMERA_DEBUG, false); #endif // _DEBUG -} - -void CCamera_Debug::Update(_float fTimeDelta) -{ if (FAILED(m_pGameInstance->IsBinded_Camera(CAMERA_DEBUG))) { return; } @@ -88,6 +84,10 @@ void CCamera_Debug::Update(_float fTimeDelta) __super::Bind_Matrices(); } +void CCamera_Debug::Update(_float fTimeDelta) +{ +} + void CCamera_Debug::Late_Update(_float fTimeDelta) { if (FAILED(m_pGameInstance->IsBinded_Camera(CAMERA_DEBUG))) { diff --git a/Jusin154_Team3D/Client/Private/Land.cpp b/Jusin154_Team3D/Client/Private/Land.cpp index 960ff6a0d..27eeb9ecc 100644 --- a/Jusin154_Team3D/Client/Private/Land.cpp +++ b/Jusin154_Team3D/Client/Private/Land.cpp @@ -47,6 +47,28 @@ HRESULT CLand::Render() return S_OK; } +HRESULT CLand::Render_Shadow(SHADOW eType) +{ + if (FAILED(m_pTransformCom->Bind_ShaderResource(m_pShaderCom, "g_WorldMatrix"))) { + return E_FAIL; + } + if (FAILED(m_pGameInstance->Bind_Shadow_Resource(m_pShaderCom, "g_ViewMatrix", D3DTS::VIEW, eType))) { + return E_FAIL; + } + if (FAILED(m_pGameInstance->Bind_Shadow_Resource(m_pShaderCom, "g_ProjMatrix", D3DTS::PROJ, eType))) { + return E_FAIL; + } + if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_MESH::SHADOW)))) { + return E_FAIL; + } + + if (FAILED(m_pModelCom->Render(0))) { + return E_FAIL; + } + + return S_OK; +} + HRESULT CLand::Initialize_Prototype() { return S_OK; diff --git a/Jusin154_Team3D/Client/Private/Level_Loading.cpp b/Jusin154_Team3D/Client/Private/Level_Loading.cpp index 3cd16af2a..ebb975b87 100644 --- a/Jusin154_Team3D/Client/Private/Level_Loading.cpp +++ b/Jusin154_Team3D/Client/Private/Level_Loading.cpp @@ -1,14 +1,13 @@ #include "pch.h" #include "Level_Loading.h" - #include "Loader.h" +#include "Light_Main.h" #include "GameInstance.h" #include "Layer.h" #include "Level_Logo.h" #include "Level_GamePlay.h" #include "Level_Restart.h" #include "Level_Field.h" - #include "Intro_Image.h" #include "Intro_BG.h" #include "Loding_Panel.h" @@ -23,9 +22,6 @@ HRESULT CLevel_Loading::Initialize(LEVEL eNextLevelID) m_eNextLevelID = eNextLevelID; m_pLoader = CLoader::Create(m_pDevice, m_pContext, eNextLevelID); - //m_ShadowDesc.vAt = _float4(-10.f, -10.f, 10.f, 1.f); - //m_ShadowDesc.fWidth = 300.f; - //m_ShadowDesc.fHeight = 300.f; if (nullptr == m_pLoader) { return E_FAIL; } @@ -64,7 +60,6 @@ void CLevel_Loading::Update(_float fTimeDelta) } } - if (m_bNextLevel == true) { pair> pairLevel = { nullptr, nullptr }; @@ -77,10 +72,8 @@ void CLevel_Loading::Update(_float fTimeDelta) } break; case LEVEL::GAMEPLAY: { - //m_ShadowDesc.vAt = _float4(-194, 18.5f, -153.f, 1.f); - //m_ShadowDesc.fHeight = 1000.f; - //m_ShadowDesc.fWidth = 1000.f; pairLevel = CLevel_GamePlay::Create(m_pDevice, m_pContext, m_eNextLevelID, nullptr); + Capture_TerrainPreShadow(); } break; case LEVEL::FIELD: { @@ -90,12 +83,10 @@ void CLevel_Loading::Update(_float fTimeDelta) { pairLevel = CLevel_Restart::Create(m_pDevice, m_pContext, m_eNextLevelID); } break; - default: assert(false); // E_IMPL break; } -// Capture_TerrainPreShadow(m_ShadowDesc); if (SUCCEEDED(m_pGameInstance->Change_Level(pairLevel.first))) { if (nullptr != pairLevel.second) { @@ -115,34 +106,17 @@ HRESULT CLevel_Loading::Render() return S_OK; } -// -//void CLevel_Loading::Capture_TerrainPreShadow(SHADOW_LIGHT_DESC& ShadowDesc) -//{ -// CLayer* pLayer = m_pGameInstance->Get_Layer(NEXT_LEVEL, LAYER_BACKGROUND); -// if (nullptr != pLayer) { -// ShadowDesc.fFar = 1000.f; -// ShadowDesc.fNear = 0.1f; -// _float3 vRollPichYaw = { 35.2643897f, 45.f, 0.f }; // (1, -1, 1) 방향 look -// -// _matrix matRotation = XMMatrixRotationRollPitchYaw( -// XMConvertToRadians(vRollPichYaw.x), XMConvertToRadians(vRollPichYaw.y), XMConvertToRadians(vRollPichYaw.z)); -// -// XMStoreFloat4(&ShadowDesc.vEye, XMLoadFloat4(&ShadowDesc.vAt) - matRotation.r[2] * (ShadowDesc.fFar * 0.25f)); -// -// if (FAILED(m_pGameInstance->Ready_Shadow_Light(ShadowDesc))) { -// assert(false); -// } -// -// const list* pObjects = pLayer->Get_Objects(); -// _float4 vPos = {}; -// for (auto& pObject : *pObjects) { -// if (FAILED(m_pGameInstance->Add_RenderGroup(RENDER::PRESHADOW, pObject))) { -// assert(false); -// } -// } -// m_pGameInstance->Render_PreShadow(); -// } -//} + +void CLevel_Loading::Capture_TerrainPreShadow() +{ + CLayer* pLayer = m_pGameInstance->Get_Layer(NEXT_LEVEL, LAYER_LIGHT); + assert(nullptr != pLayer); + CLight_Main* pLight = pLayer->Get_Object(); + assert(nullptr != pLight); + if (FAILED(pLight->Capture_PreShadow())) { + assert(false); + } +} HRESULT CLevel_Loading::Ready_Layer_BackGround(const _wstring& strLayerTag) { diff --git a/Jusin154_Team3D/Client/Private/Light_Main.cpp b/Jusin154_Team3D/Client/Private/Light_Main.cpp index 65509d283..660f25f3d 100644 --- a/Jusin154_Team3D/Client/Private/Light_Main.cpp +++ b/Jusin154_Team3D/Client/Private/Light_Main.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "Light_Main.h" #include "GameInstance.h" +#include "Layer.h" CLight_Main::CLight_Main(ID3D11Device* pDevice, ID3D11DeviceContext* pContext) : CGameObject(pDevice, pContext) @@ -22,14 +23,10 @@ HRESULT CLight_Main::Initialize(void* pArg) if (FAILED(__super::Initialize(pArg))){ return E_FAIL; } - - if (FAILED(Ready_Components())){ return E_FAIL; } - m_pTransformCom->Set_State(STATE::LOOK, XMVectorSet(1.f, -1.f, 1.f, 0.f)); - return S_OK; } @@ -43,11 +40,7 @@ void CLight_Main::Priority_Update(_float fTimeDelta) void CLight_Main::Update(_float fTimeDelta) { #ifdef _DEBUG - GUI::Begin("LIGHT", 0, IMGUI_GLOBAL_BEGIN_FLAG); - if (GUI::CollapsingHeader("Main_Light")) { - m_pLightCom->Describe_Entity(); - } - GUI::End(); + Describe_Entity(); #endif // _DEBUG } @@ -60,10 +53,51 @@ HRESULT CLight_Main::Render() return S_OK; } +HRESULT CLight_Main::Capture_PreShadow() +{ + _vector vRotq = m_pTransformCom->Get_QuarternionVector(); + _uint iLevel = NEXT_LEVEL; + CLayer* pLayer = m_pGameInstance->Get_Layer(iLevel, LAYER_BACKGROUND); + assert(nullptr != pLayer); + + const list* pObjects = pLayer->Get_Objects(); + for (auto& pObject : *pObjects) { + if (FAILED(m_pGameInstance->Add_RenderGroup(RENDER::PRESHADOW, pObject))) { + assert(false); + } + } + vector<_float3> vNeededPos = {}; + vNeededPos.reserve(12); + { + // 외곽이 더 많아지면 많아질수록 더 정밀한 경계가 가능 + // 하지만 더 실제보다 멀리 외곽을 두르면 필요한 것보다 더 많이 찍게 됨 + // 결국 딱 맞춰서 찍는게 제일 중요함 + vNeededPos.emplace_back(_float3(-112, 155, 362)); + vNeededPos.emplace_back(_float3(- 188, 10, 476)); + vNeededPos.emplace_back(_float3(- 571, 19, 476)); + vNeededPos.emplace_back(_float3(- 326, -64, 480)); + vNeededPos.emplace_back(_float3(569, 77, 250)); + vNeededPos.emplace_back(_float3(320, -236, 360)); + vNeededPos.emplace_back(_float3(570, 277, -277)); + vNeededPos.emplace_back(_float3(570, 176, -527)); + vNeededPos.emplace_back(_float3(- 108, -64, -1146)); + vNeededPos.emplace_back(_float3(- 824, 128, -533)); + vNeededPos.emplace_back(_float3(- 826, 145, -150)); + vNeededPos.emplace_back(_float3(- 256, -92, -414)); + } + _matrix xmViewMatrix = m_pTransformCom->Get_WorldMatrixInv(); + _float4x4 ViewMatrix = {}; XMStoreFloat4x4(&ViewMatrix, xmViewMatrix); + _float4x4 ProjMatrix = {}; XMStoreFloat4x4(&ProjMatrix, Get_OffCenterProjMatrix(xmViewMatrix, vNeededPos)); + + m_pGameInstance->Render_PreShadow(ViewMatrix, ProjMatrix); + return S_OK; +} + HRESULT CLight_Main::Ready_Components() { __super::Ready_Components(nullptr); + m_pTransformCom->LookAt(XMVectorSet(1.f, -1.f, 1.f, 1.f)); LIGHT_DESC LightDesc{}; LightDesc.eType = LIGHT::DIRECTIONAL; @@ -95,6 +129,33 @@ HRESULT CLight_Main::Bind_ShaderResources() return S_OK; } +_matrix CLight_Main::Get_OffCenterProjMatrix(_fmatrix ViewMatrix, vector<_float3>& WorldPositions) +{ + _float fMinX = FLT_MAX; + _float fMinY = FLT_MAX; + _float fMinZ = FLT_MAX; + _float fMaxX = -FLT_MAX; + _float fMaxY = -FLT_MAX; + _float fMaxZ = -FLT_MAX; + + _uint iPosNum = (_uint)WorldPositions.size(); + for (_uint iIndexPoint = 0; iIndexPoint < iPosNum; ++iIndexPoint) + { + _vector vLightViewPos = XMVector4Transform(XMVectorSetW(XMLoadFloat3(&WorldPositions[iIndexPoint]), 1.f), ViewMatrix); + + _float x = XMVectorGetX(vLightViewPos); + _float y = XMVectorGetY(vLightViewPos); + _float z = XMVectorGetZ(vLightViewPos); + + fMinX = min(fMinX, x); fMaxX = max(fMaxX, x); + fMinY = min(fMinY, y); fMaxY = max(fMaxY, y); + fMinZ = min(fMinZ, z); fMaxZ = max(fMaxZ, z); + } + + return XMMatrixOrthographicOffCenterLH(fMinX, fMaxX, fMinY, fMaxY, fMinZ, fMaxZ); +} + + CLight_Main* CLight_Main::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext) { CLight_Main* pInstance = new CLight_Main(pDevice, pContext); @@ -131,6 +192,20 @@ void CLight_Main::Free() void CLight_Main::Describe_Entity() { + GUI::Begin("LIGHT", 0, IMGUI_GLOBAL_BEGIN_FLAG); + if (GUI::CollapsingHeader("Main_Light")) { + if (GUI::Button("Capture_PreShadow") || m_pGameInstance->Key_Down(DIK_F12)) { + if (FAILED(Capture_PreShadow())) { + assert(false); + } + } + m_pLightCom->Describe_Entity(); + if (GUI::Button("Sync_CamToLight")) { + m_pTransformCom->Set_WorldMatrix(m_pGameInstance->Get_Transform_Matrix(D3DTS::VIEW_INV)); + m_pTransformCom->Set_State(STATE::POSITION, XMVectorSet(0.f, 0.f, 0.f, 1.f)); + } + } + GUI::End(); } #endif // _DEBUG diff --git a/Jusin154_Team3D/Client/Private/MapObject_Render.cpp b/Jusin154_Team3D/Client/Private/MapObject_Render.cpp index e8a80393a..e9d4c5275 100644 --- a/Jusin154_Team3D/Client/Private/MapObject_Render.cpp +++ b/Jusin154_Team3D/Client/Private/MapObject_Render.cpp @@ -87,6 +87,7 @@ void CMapObject_Render::Late_Update(_float fTimeDelta) { case MAPOBJECT_RENDER_TYPE::NORMAL: m_pGameInstance->Add_RenderGroup(RENDER::NONBLEND, this); + //Set_Shadow(m_pGameInstance->IsIn_ShadowViewFrustum(XMLoadFloat4((_float4*)&m_CombinedWorldMatrix.m[3][0]), m_fRadius)); break; case MAPOBJECT_RENDER_TYPE::GLASS: break; @@ -139,10 +140,6 @@ HRESULT CMapObject_Render::Render_Shadow(SHADOW eType) for (_uint i = 0; i < iMeshes; i++) { - if (FAILED(m_pModelComs[0]->Bind_Material(i, m_pShaderCom))) { - return E_FAIL; - } - if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_MESH::SHADOW)))) { return E_FAIL; } diff --git a/Jusin154_Team3D/Client/Public/Land.h b/Jusin154_Team3D/Client/Public/Land.h index 2533d6bd4..728e868e8 100644 --- a/Jusin154_Team3D/Client/Public/Land.h +++ b/Jusin154_Team3D/Client/Public/Land.h @@ -29,6 +29,7 @@ class CLand final : public CGameObject virtual void Update(_float fTimeDelta) override; virtual void Late_Update(_float fTimeDelta) override; virtual HRESULT Render() override; + virtual HRESULT Render_Shadow(SHADOW eType) override; private: CShader* m_pShaderCom = { nullptr }; diff --git a/Jusin154_Team3D/Client/Public/Level_Loading.h b/Jusin154_Team3D/Client/Public/Level_Loading.h index 7ca7f5aeb..e56a4945d 100644 --- a/Jusin154_Team3D/Client/Public/Level_Loading.h +++ b/Jusin154_Team3D/Client/Public/Level_Loading.h @@ -15,10 +15,9 @@ class CLevel_Loading final : public CLevel virtual void Update(_float fTimeDelta) override; virtual HRESULT Render() override; virtual _uint Get_NextLevelID() override { return ENUM_CLASS(m_eNextLevelID); }; - //virtual void Capture_TerrainPreShadow(SHADOW_LIGHT_DESC& ShadowDesc); + virtual void Capture_TerrainPreShadow(); private: - //SHADOW_LIGHT_DESC m_ShadowDesc = {}; LEVEL m_eNextLevelID = { LEVEL::END }; class CLoader* m_pLoader = { nullptr }; diff --git a/Jusin154_Team3D/Client/Public/Light_Main.h b/Jusin154_Team3D/Client/Public/Light_Main.h index 71ffeed40..a56ac9081 100644 --- a/Jusin154_Team3D/Client/Public/Light_Main.h +++ b/Jusin154_Team3D/Client/Public/Light_Main.h @@ -17,15 +17,18 @@ class CLight_Main final : public CGameObject virtual void Update(_float fTimeDelta) override; virtual void Late_Update(_float fTimeDelta) override; virtual HRESULT Render() override; + virtual HRESULT Capture_PreShadow(); private: CLight* m_pLightCom = { nullptr }; + private: virtual HRESULT Initialize_Prototype() override; virtual HRESULT Initialize(void* pArg) override; HRESULT Ready_Components(); HRESULT Bind_ShaderResources(); + _matrix Get_OffCenterProjMatrix(_fmatrix ViewMatrix, vector<_float3>& WorldPositions); public: static CLight_Main* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext); @@ -33,7 +36,6 @@ class CLight_Main final : public CGameObject virtual void Free() override; #ifdef _DEBUG virtual void Describe_Entity() override; - #endif // _DEBUG }; diff --git a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Deferred.hlsl b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Deferred.hlsl index 92045482b..0f41528af 100644 --- a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Deferred.hlsl +++ b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Deferred.hlsl @@ -11,7 +11,6 @@ float g_fFar; float g_fShadowFar_NEAR; float g_fShadowFar_MIDDDLE; float g_fShadowFar_FAR; -float g_fPreShadowFar; float g_fCascadeSplitRatioNear; float g_fCascadeSplitRatioFar; uint g_iMaxShadowWidth; @@ -628,12 +627,7 @@ PS_OUT_BACKBUFFER PS_MAIN_COMBINED(PS_IN In) // Middle -> Far 경계 부드럽게 fVisibilityDynamic = lerp(fVisibilityDynamic, fVisibility_Dynamic_Far, fCascadeBlend_MiddleToFar); - // PreShadow(Static)로 넘어가는 구간(원하는 대로 조절) - float fStaticShadowBlendStartRatio = 0.70f; - float fStaticShadowBlendEndRatio = 0.95f; - - float fStaticShadowBlendWeight = smoothstep(fStaticShadowBlendStartRatio, fStaticShadowBlendEndRatio, fDepthRatio); - float fVisibilityCombined = lerp(fVisibilityDynamic, fVisibility_Static, fStaticShadowBlendWeight); + float fVisibilityCombined = min(fVisibility_Static, fVisibilityDynamic); // 최소 밝기 float fMinShadowBrightness = 0.25f; diff --git a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_VtxAnimMesh.hlsl b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_VtxAnimMesh.hlsl index 6cddf20d4..201453c28 100644 --- a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_VtxAnimMesh.hlsl +++ b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_VtxAnimMesh.hlsl @@ -563,7 +563,7 @@ technique11 DefaultTechnique pass ShadowPass // 1 { SetRasterizerState(RS_Default); - SetDepthStencilState(DSS_Default, 0); + SetDepthStencilState(DSS_None, 0); SetBlendState(BS_None, float4(0.f, 0.f, 0.f, 0.f), 0xffffffff); VertexShader = compile vs_5_0 VS_MAIN_SHADOW(); GeometryShader = NULL; diff --git a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_VtxMesh.hlsl b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_VtxMesh.hlsl index 0f33f9ce5..6aa91fc07 100644 --- a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_VtxMesh.hlsl +++ b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_VtxMesh.hlsl @@ -790,7 +790,7 @@ technique11 MeshTechnique11 pass ShadowPass { SetRasterizerState(RS_Default); - SetDepthStencilState(DSS_Default, 0); + SetDepthStencilState(DSS_None, 0); SetBlendState(BS_None, float4(0.f, 0.f, 0.f, 0.f), 0xffffffff); VertexShader = compile vs_5_0 VS_MAIN_SHADOW(); GeometryShader = NULL; diff --git a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_VtxNorTex.hlsl b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_VtxNorTex.hlsl index 87dba8b51..bebec3563 100644 --- a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_VtxNorTex.hlsl +++ b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_VtxNorTex.hlsl @@ -249,7 +249,7 @@ technique11 NorTexTechnique11 pass ShadowPass // 3 { SetRasterizerState(RS_Default); - SetDepthStencilState(DSS_Default, 0); + SetDepthStencilState(DSS_None, 0); SetBlendState(BS_None, float4(0.f, 0.f, 0.f, 0.f), 0xffffffff); VertexShader = compile vs_5_0 VS_MAIN_SHADOW(); GeometryShader = NULL; diff --git a/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Deferred.hlsl b/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Deferred.hlsl index 92045482b..0f41528af 100644 --- a/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Deferred.hlsl +++ b/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Deferred.hlsl @@ -11,7 +11,6 @@ float g_fFar; float g_fShadowFar_NEAR; float g_fShadowFar_MIDDDLE; float g_fShadowFar_FAR; -float g_fPreShadowFar; float g_fCascadeSplitRatioNear; float g_fCascadeSplitRatioFar; uint g_iMaxShadowWidth; @@ -628,12 +627,7 @@ PS_OUT_BACKBUFFER PS_MAIN_COMBINED(PS_IN In) // Middle -> Far 경계 부드럽게 fVisibilityDynamic = lerp(fVisibilityDynamic, fVisibility_Dynamic_Far, fCascadeBlend_MiddleToFar); - // PreShadow(Static)로 넘어가는 구간(원하는 대로 조절) - float fStaticShadowBlendStartRatio = 0.70f; - float fStaticShadowBlendEndRatio = 0.95f; - - float fStaticShadowBlendWeight = smoothstep(fStaticShadowBlendStartRatio, fStaticShadowBlendEndRatio, fDepthRatio); - float fVisibilityCombined = lerp(fVisibilityDynamic, fVisibility_Static, fStaticShadowBlendWeight); + float fVisibilityCombined = min(fVisibility_Static, fVisibilityDynamic); // 최소 밝기 float fMinShadowBrightness = 0.25f; diff --git a/Jusin154_Team3D/Engine/Private/GameInstance.cpp b/Jusin154_Team3D/Engine/Private/GameInstance.cpp index 834ada1c9..6bbfaddd0 100644 --- a/Jusin154_Team3D/Engine/Private/GameInstance.cpp +++ b/Jusin154_Team3D/Engine/Private/GameInstance.cpp @@ -679,9 +679,14 @@ HRESULT CGameInstance::Add_RenderGroup(RENDER eRenderGroup, CGameObject* pRender return m_pRenderer->Add_RenderGroup(eRenderGroup, pRenderObject); } -void CGameInstance::Render_PreShadow() +void CGameInstance::Render_PreShadow(const _float4x4& ViewMatrix, const _float4x4& ProjMatrix) { - return m_pRenderer->Render_PreShadow(); + return m_pRenderer->Render_PreShadow(ViewMatrix, ProjMatrix); +} + +HRESULT CGameInstance::Bind_PreShadowMatrix(CShader* pShader, const _char* pConstants, D3DTS eType) +{ + return m_pRenderer->Bind_PreShadowMatrix(pShader, pConstants, eType); } void CGameInstance::Set_Transform(D3DTS eState, _fmatrix TransformStateMatrix) diff --git a/Jusin154_Team3D/Engine/Private/PipeLine.cpp b/Jusin154_Team3D/Engine/Private/PipeLine.cpp index 7a1d4b009..a7440a8dd 100644 --- a/Jusin154_Team3D/Engine/Private/PipeLine.cpp +++ b/Jusin154_Team3D/Engine/Private/PipeLine.cpp @@ -171,6 +171,9 @@ HRESULT CPipeLine::Bind_Shadow_Resource(CShader* pShader, const _char* pConstant else if (0 < ((_ubyte)eShadowType & (_ubyte)SHADOW::SHADOW_FAR)) { iPass = 2; } + else if (0 < ((_ubyte)eShadowType & (_ubyte)SHADOW::SHADOW_PRE)) { + return m_pGameInstance->Bind_PreShadowMatrix(pShader, pConstantName, eType); + } assert(iPass != UINT_MAX); return pShader->Bind_Matrix(pConstantName, &m_ShadowTransformStateMatrices[iPass][ENUM_CLASS(eType)]); diff --git a/Jusin154_Team3D/Engine/Private/Renderer.cpp b/Jusin154_Team3D/Engine/Private/Renderer.cpp index 7af0c3da1..ceb166ce9 100644 --- a/Jusin154_Team3D/Engine/Private/Renderer.cpp +++ b/Jusin154_Team3D/Engine/Private/Renderer.cpp @@ -56,17 +56,14 @@ void CRenderer::Render() #endif } -void CRenderer::Render_PreShadow() +void CRenderer::Render_PreShadow(const _float4x4& ViewMatrix, const _float4x4& ProjMatrix) { if (FAILED(m_pGameInstance->Begin_MRT(TEXT("MRT_PreShadow"), m_pPreShadowDSV))) { return; } - const _float4x4* pMatrices = m_pGameInstance->Get_ShadowMatricesPtr(0); - m_PreShadowFar = m_pGameInstance->Get_ShadowBoxFar(0); - for (int i = 0; i < ENUM_CLASS(D3DTS::END); ++i) { - m_PreShadowMatrices[i] = pMatrices[i]; - } + m_PreShadowView = ViewMatrix; + m_PreShadowProj = ProjMatrix; D3D11_VIEWPORT ViewPortOldDesc; D3D11_VIEWPORT ViewPortDesc; @@ -76,8 +73,8 @@ void CRenderer::Render_PreShadow() { ViewPortDesc.TopLeftX = 0; ViewPortDesc.TopLeftY = 0; - ViewPortDesc.Width = (_float)g_iMaxShadowWidth; - ViewPortDesc.Height = (_float)g_iMaxShadowHeight; + ViewPortDesc.Width = (_float)g_iPreShadowWidth; + ViewPortDesc.Height = (_float)g_iPreShadowHeight; ViewPortDesc.MinDepth = 0.f; ViewPortDesc.MaxDepth = 1.f; } @@ -87,7 +84,7 @@ void CRenderer::Render_PreShadow() for (auto& pRenderObject : m_RenderObjects[ENUM_CLASS(RENDER::PRESHADOW)]) { if (nullptr != pRenderObject) { - if (FAILED(pRenderObject->Render_Shadow(SHADOW::END))) { + if (FAILED(pRenderObject->Render_Shadow(SHADOW::SHADOW_PRE))) { assert(false); } } @@ -103,6 +100,20 @@ void CRenderer::Render_PreShadow() m_pContext->RSSetViewports(iNumViewOldPort, &ViewPortOldDesc); } +HRESULT CRenderer::Bind_PreShadowMatrix(class CShader* pShader, const _char* pConstants, D3DTS eType) +{ + if (D3DTS::VIEW == eType) { + if (FAILED(pShader->Bind_Matrix(pConstants, &m_PreShadowView))) { + return E_FAIL; + } + } else if (D3DTS::PROJ == eType) { + if (FAILED(pShader->Bind_Matrix(pConstants, &m_PreShadowProj))) { + return E_FAIL; + } + } + return S_OK; +} + void CRenderer::Render_Occlusion() { COMPUTE_TIMEDELTA("Timer_Render_Occlusion"); @@ -385,13 +396,10 @@ void CRenderer::Render_Combined() if (FAILED(m_pGameInstance->Bind_Shadow_Resource(m_pShader, "g_LightProjMatrix_FAR", D3DTS::PROJ, SHADOW::SHADOW_FAR))) { return; } - if (FAILED(m_pShader->Bind_RawValue("g_fPreShadowFar", m_pGameInstance->Get_CurrentCameraFar(), sizeof(_float)))) { + if (FAILED(m_pShader->Bind_Matrix("g_PreShadowLightViewMatrix", &m_PreShadowView))) { return; } - if (FAILED(m_pShader->Bind_Matrix("g_PreShadowLightViewMatrix", &m_PreShadowMatrices[ENUM_CLASS(D3DTS::VIEW)]))) { - return; - } - if (FAILED(m_pShader->Bind_Matrix("g_PreShadowLightProjMatrix", &m_PreShadowMatrices[ENUM_CLASS(D3DTS::PROJ)]))) { + if (FAILED(m_pShader->Bind_Matrix("g_PreShadowLightProjMatrix", &m_PreShadowProj))) { return; } } diff --git a/Jusin154_Team3D/Engine/Private/Transform.cpp b/Jusin154_Team3D/Engine/Private/Transform.cpp index 1f46548c2..99514bf64 100644 --- a/Jusin154_Team3D/Engine/Private/Transform.cpp +++ b/Jusin154_Team3D/Engine/Private/Transform.cpp @@ -488,12 +488,14 @@ void CTransform::Describe_Entity() GUI::DragFloat4("Look", (_float*)(&m_WorldMatrix._31), 1.f, 0.f, 0.f, "%.3f"); GUI::DragFloat4("Pos", (_float*)(&m_WorldMatrix._41), 1.f, 0.f, 0.f, "%.3f"); - + + _vector vRotRPY = Get_RollPitchYawVector(); static _float3 s_vRotation = {}; - - if(GUI::InputFloat3("Rotation", (_float*)&s_vRotation)) + XMStoreFloat3(&s_vRotation, vRotRPY); + _float3 vDegrees = { XMConvertToDegrees(s_vRotation.x),XMConvertToDegrees(s_vRotation.y),XMConvertToDegrees(s_vRotation.z) }; + if(GUI::InputFloat3("Rotation", (_float*)&vDegrees)) { - Rotation(s_vRotation.x, s_vRotation.y, s_vRotation.z); + Rotation(XMConvertToRadians(vDegrees.x), XMConvertToRadians(vDegrees.y), XMConvertToRadians(vDegrees.z)); } GUI::TreePop(); diff --git a/Jusin154_Team3D/Engine/Public/Engine_Enum.h b/Jusin154_Team3D/Engine/Public/Engine_Enum.h index 61decf635..22b123a3c 100644 --- a/Jusin154_Team3D/Engine/Public/Engine_Enum.h +++ b/Jusin154_Team3D/Engine/Public/Engine_Enum.h @@ -15,7 +15,9 @@ enum class SHADOW : _ubyte { SHADOW_NEAR = 1 << 0 , SHADOW_MIDDLE = 1 << 1 , SHADOW_FAR = 1 << 2 - , END = 3 + , SHADOW_PRE = 1 << 3 +//////////////// + , END = 3 // 케스케이드 셰도우 한정 }; diff --git a/Jusin154_Team3D/Engine/Public/Engine_Macro.h b/Jusin154_Team3D/Engine/Public/Engine_Macro.h index 0acf0150c..12c09029e 100644 --- a/Jusin154_Team3D/Engine/Public/Engine_Macro.h +++ b/Jusin154_Team3D/Engine/Public/Engine_Macro.h @@ -100,6 +100,9 @@ #define SSAO_SAMPLE_NUMBER 64 #define TIMER_SHORT_LERP 0.16f +constexpr unsigned int g_iPreShadowWidth = 16384; +constexpr unsigned int g_iPreShadowHeight = 9216; + constexpr unsigned int g_iMaxShadowWidth = 16384; constexpr unsigned int g_iMaxShadowHeight = 9216; //constexpr unsigned int g_iMaxShadowWidth = 4096; diff --git a/Jusin154_Team3D/Engine/Public/GameInstance.h b/Jusin154_Team3D/Engine/Public/GameInstance.h index f04e36197..b93971b9c 100644 --- a/Jusin154_Team3D/Engine/Public/GameInstance.h +++ b/Jusin154_Team3D/Engine/Public/GameInstance.h @@ -101,7 +101,8 @@ class ENGINE_DLL CGameInstance final : public CBase #pragma region RENDERER HRESULT Add_RenderGroup(RENDER eRenderGroup, class CGameObject* pRenderObject); - void Render_PreShadow(); + void Render_PreShadow(const _float4x4& ViewMatrix, const _float4x4& ProjMatrix); + HRESULT Bind_PreShadowMatrix(class CShader* pShader, const _char* pConstants, D3DTS eType); #pragma endregion #pragma region ASSET_MANAGER diff --git a/Jusin154_Team3D/Engine/Public/Renderer.h b/Jusin154_Team3D/Engine/Public/Renderer.h index 2012f4d5a..04c9dd6ae 100644 --- a/Jusin154_Team3D/Engine/Public/Renderer.h +++ b/Jusin154_Team3D/Engine/Public/Renderer.h @@ -13,7 +13,8 @@ class CRenderer final : public CBase public: void Render(); HRESULT Add_RenderGroup(RENDER eRenderGroup, class CGameObject* pRenderObject); - void Render_PreShadow(); + void Render_PreShadow(const _float4x4& ViewMatrix, const _float4x4& ProjMatrix); + HRESULT Bind_PreShadowMatrix(class CShader* pShader, const _char* pConstants, D3DTS eType); #ifdef _DEBUG private: @@ -48,8 +49,8 @@ class CRenderer final : public CBase ID3D11Texture2D* m_pSSAO_NoiseTexture = { nullptr }; ID3D11Buffer* m_pGlobalStaticCB = { nullptr }; - _float m_PreShadowFar = {}; - _float4x4 m_PreShadowMatrices[ENUM_CLASS(D3DTS::END)] = {}; + _float4x4 m_PreShadowView = {}; + _float4x4 m_PreShadowProj = {}; /* TunningParam */ _int m_iToneMappingType = { 0 }; diff --git a/Jusin154_Team3D/Engine/Public/Transform.h b/Jusin154_Team3D/Engine/Public/Transform.h index f6e78b736..10ccd801d 100644 --- a/Jusin154_Team3D/Engine/Public/Transform.h +++ b/Jusin154_Team3D/Engine/Public/Transform.h @@ -73,7 +73,7 @@ class ENGINE_DLL CTransform final : void Rotation(_float3& vRadian); void Rotation(_fvector vRPY); - // Up, Down 벡터를 바라보게 하면 터짐 + // Up, Down 벡터를 바라보게 하면 터짐, w에 1 있어야함 void LookAt(_fvector vAt); void LookAt_Lerp(_fvector vAt, _float fTimeDelta, _float fSpeed); void LookAt_Horizontal(_fvector vAt);