Merge pull request #587 from SpicyGangjeong/MapTool

Map tool
This commit is contained in:
JinhoBa
2025-12-29 17:34:48 +09:00
committed by GitHub
19 changed files with 407 additions and 90 deletions
@@ -90,6 +90,8 @@ HRESULT CLight_Main::Capture_PreShadow()
_float4x4 ProjMatrix = {}; XMStoreFloat4x4(&ProjMatrix, Get_OffCenterProjMatrix(xmViewMatrix, vNeededPos));
m_pGameInstance->Render_PreShadow(ViewMatrix, ProjMatrix);
m_pGameInstance->Update_Volumetric();
return S_OK;
}
@@ -557,23 +557,23 @@ float2 CalcVelocityUV(float4 vCurrentProjPos, float4 vPreviousProjPos, float fIn
float3 DownSampleFast(Texture2D SrcTexture2D, float2 vCenterTexcoord, float2 vSrcTexelSize, float2 vResolution)
{
float2 uv = float2(0.f, 0.f);
float3 vCenterColor = SrcTexture2D.SampleLevel(BorderZeroSampler, vCenterTexcoord, 0);
float3 vCenterColor = SrcTexture2D.SampleLevel(BorderZeroSampler, vCenterTexcoord, 0).rgb;
uv = vCenterTexcoord + vSrcTexelSize * float2(-1.0, -1.0);
float3 fLTColor = BilinearFetches(vResolution, SrcTexture2D, uv, BorderZeroSampler);
float3 fLTColor = BilinearFetches(vResolution, SrcTexture2D, uv, BorderZeroSampler).rgb;
uv = vCenterTexcoord + vSrcTexelSize * float2(0.0, -1.0);
float3 fTColor = SrcTexture2D.SampleLevel(BorderZeroSampler, uv, 0);
float3 fTColor = SrcTexture2D.SampleLevel(BorderZeroSampler, uv, 0).rgb;
uv = vCenterTexcoord + vSrcTexelSize * float2(+1.0, -1.0);
float3 fRTColor = BilinearFetches(vResolution, SrcTexture2D, uv, BorderZeroSampler);
float3 fRTColor = BilinearFetches(vResolution, SrcTexture2D, uv, BorderZeroSampler).rgb;
uv = vCenterTexcoord + vSrcTexelSize * float2(-1.0, 0.0);
float3 fLColor = SrcTexture2D.SampleLevel(BorderZeroSampler, uv, 0);
float3 fLColor = SrcTexture2D.SampleLevel(BorderZeroSampler, uv, 0).rgb;
uv = vCenterTexcoord + vSrcTexelSize * float2(1.0, 0.0);
float3 fRColor = SrcTexture2D.SampleLevel(BorderZeroSampler, uv, 0);
float3 fRColor = SrcTexture2D.SampleLevel(BorderZeroSampler, uv, 0).rgb;
uv = vCenterTexcoord + vSrcTexelSize * float2(-1.0, +1.0);
float3 fLBColor = BilinearFetches(vResolution, SrcTexture2D, uv, BorderZeroSampler);
float3 fLBColor = BilinearFetches(vResolution, SrcTexture2D, uv, BorderZeroSampler).rgb;
uv = vCenterTexcoord + vSrcTexelSize * float2(0.0, 1.0);
float3 fBColor = SrcTexture2D.SampleLevel(BorderZeroSampler, uv, 0);
float3 fBColor = SrcTexture2D.SampleLevel(BorderZeroSampler, uv, 0).rgb;
uv = vCenterTexcoord + vSrcTexelSize * float2(+1.0, +1.0);
float3 fRBColor = BilinearFetches(vResolution, SrcTexture2D, uv, BorderZeroSampler);
float3 fRBColor = BilinearFetches(vResolution, SrcTexture2D, uv, BorderZeroSampler).rgb;
return vCenterColor * 0.25f + (fLTColor + fRTColor + fLBColor + fRBColor) * 0.0625f + (fTColor + fLColor + fRColor + fBColor) * 0.125f;
}
@@ -28,11 +28,14 @@ cbuffer g_ConstantBuffer : register(b0) // b0 << 이 숫자와 컨스턴트 쉐
row_major matrix InvProjMatrix;
row_major matrix InvViewMatrix;
row_major matrix ShadowViewMatrix;
row_major matrix ShadowViewProjMatrix;
float fAsymmetryParameter;
float padding0;
float padding1;
float padding2;
}
uint iNumLight;
float fHeightOffset;
float fBaseHeight;
};
float ConvertNdcZToDepth(float ndcZ);
float SliceTickness(float ndcZ, uint dimZ);
@@ -5,16 +5,17 @@ static const float EPSILON = 1e-6f;
struct LightData
{
uint itype;
float3 vDirection;
float3 vPosition;
float fRange;
float4 vColor;
float3 vDirection;
float fRange;
float4 vPosition;
float4 vDiffuse;
};
//StructuredBuffer<LightData> g_LightBuffer : register(t1);
StructuredBuffer<LightData> g_LightBuffer : register(t0);
Texture2D<float4> g_ShadowMap : register(t1);
Texture2D<float4> NoiseTexture : register(t2);
SamplerState g_Sampler : register(s0);
RWTexture3D<float4> g_VolumeUAV : register(u0);
@@ -39,18 +40,22 @@ cbuffer g_ConstantBuffer : register(b0) // b0 << 이 숫자와 컨스턴트 쉐
row_major matrix InvProjMatrix;
row_major matrix InvViewMatrix;
row_major matrix ShadowViewMatrix;
row_major matrix ShadowViewProjMatrix;
float fAsymmetryParameter;
float padding0;
float padding1;
float padding2;
}
uint iNumLight;
float fHeightOffset;
float fBaseHeight;
};
float3 ConvertThreadIdToNdc(uint3 id, uint3 dims);
float ConvertNdcZToDepth(float ndcZ);
float3 ConvertToWorldPosition(float3 ndc, float depth);
float3 ConvertThreadIdToWorldPosition(uint3 id, uint3 dims);
float HenyeyGreensteinPhaseFunction(float3 vInputDir, float3 vOutputDir, float fAnisotropy);
float ComputePointLightVisible(float3 vLightDir, float fRange);
float ComputeShadowVisibility(float3 vWorldPosition);
// 볼륨 텍스쳐 밀도, 산란 계산
[numthreads(8, 8, 4)]
void CS_MAIN( uint3 DispatchThreadID : SV_DispatchThreadID)
@@ -60,18 +65,40 @@ void CS_MAIN( uint3 DispatchThreadID : SV_DispatchThreadID)
if (!all(DispatchThreadID < dims))
return;
float3 worldPosition = ConvertThreadIdToWorldPosition(DispatchThreadID, dims);
float3 toCamera = normalize(vCameraPosition - worldPosition);
float3 vWorldPosition = ConvertThreadIdToWorldPosition(DispatchThreadID, dims);
float3 toCamera = normalize(vCameraPosition - vWorldPosition);
float3 lighting = vLightColor.rgb * vLightColor.a;
float3 lightDir = normalize(vLightDirection);
float3 toLight = -lightDir;
float3 lighting = float3(0.1f, 0.1f, 0.1f); //vLightColor.rgb * vLightColor.a;
float phase = HenyeyGreensteinPhaseFunction(lightDir, toCamera, fAsymmetryParameter);
float3 lightDir = float3(0.f, 0.f, 0.f);
lighting += vLightColor.rgb * vLightColor.rgb * phase;
[loop]
for (uint i = 0; i < iNumLight; ++i)
{
float visibility = 1.f;
if (0.f < length(g_LightBuffer[i].vDirection))
{
lightDir = normalize(g_LightBuffer[i].vDirection);
visibility = ComputeShadowVisibility(vWorldPosition);
g_VolumeUAV[DispatchThreadID] = float4(lighting * fLightIntensity * fDensity, fDensity);
}
else
{
lightDir = vWorldPosition - g_LightBuffer[i].vPosition.xyz;
visibility = ComputePointLightVisible(lightDir, g_LightBuffer[i].fRange);
lightDir = normalize(lightDir);
}
float3 toLight = -lightDir;
float phase = HenyeyGreensteinPhaseFunction(lightDir, toCamera, fAsymmetryParameter);
lighting += g_LightBuffer[i].vDiffuse.rgb * g_LightBuffer[i].vDiffuse.a * phase * visibility;
}
float fHeightDensity = max(0.1f, exp(-(vWorldPosition.y - fBaseHeight) * fHeightOffset)) * fDensity;
g_VolumeUAV[DispatchThreadID] = float4(lighting * fLightIntensity * fHeightDensity, fHeightDensity);
}
float3 ConvertThreadIdToNdc(uint3 id, uint3 dims)
@@ -109,3 +136,26 @@ float HenyeyGreensteinPhaseFunction(float3 vInputDir, float3 vOutputDir, float f
float denom = pow(1.f + (fAsymmetryParameter * fAsymmetryParameter) - 2.f * fAsymmetryParameter * cosTheta, 3.f / 2.f);
return (1.f / (4.f * PI)) * ((1.f - (fAsymmetryParameter * fAsymmetryParameter)) / max(denom, EPSILON));
}
float ComputePointLightVisible(float3 vLightDir, float fRange)
{
float fDistance = length(vLightDir);
if (fDistance < fRange)
return 1.f;
else
return 0.f;
}
float ComputeShadowVisibility(float3 vWorldPosition)
{
float4 vShadowCoord = mul(float4(vWorldPosition, 1.f), ShadowViewProjMatrix);
float3 DepthUV = vShadowCoord.xyz / vShadowCoord.w;
DepthUV.x = DepthUV.x * 0.5f + 0.5f;
DepthUV.y = DepthUV.y * -0.5f + 0.5f;
//float fNoise = NoiseTexture.SampleLevel(g_Sampler, DepthUV.xy, 4).r;
return 1.f;
}
@@ -88,10 +88,6 @@ float g_fUsingSurfaceParams;
matrix g_BoneMatrices[512];
struct VS_IN
{
float3 vPosition : POSITION;
@@ -118,6 +118,7 @@ void CMainLight::Update(_float fTimeDelta)
void CMainLight::Late_Update(_float fTimeDelta)
{
}
HRESULT CMainLight::Render()
@@ -557,23 +557,23 @@ float2 CalcVelocityUV(float4 vCurrentProjPos, float4 vPreviousProjPos, float fIn
float3 DownSampleFast(Texture2D SrcTexture2D, float2 vCenterTexcoord, float2 vSrcTexelSize, float2 vResolution)
{
float2 uv = float2(0.f, 0.f);
float3 vCenterColor = SrcTexture2D.SampleLevel(BorderZeroSampler, vCenterTexcoord, 0);
float3 vCenterColor = SrcTexture2D.SampleLevel(BorderZeroSampler, vCenterTexcoord, 0).rgb;
uv = vCenterTexcoord + vSrcTexelSize * float2(-1.0, -1.0);
float3 fLTColor = BilinearFetches(vResolution, SrcTexture2D, uv, BorderZeroSampler);
float3 fLTColor = BilinearFetches(vResolution, SrcTexture2D, uv, BorderZeroSampler).rgb;
uv = vCenterTexcoord + vSrcTexelSize * float2(0.0, -1.0);
float3 fTColor = SrcTexture2D.SampleLevel(BorderZeroSampler, uv, 0);
float3 fTColor = SrcTexture2D.SampleLevel(BorderZeroSampler, uv, 0).rgb;
uv = vCenterTexcoord + vSrcTexelSize * float2(+1.0, -1.0);
float3 fRTColor = BilinearFetches(vResolution, SrcTexture2D, uv, BorderZeroSampler);
float3 fRTColor = BilinearFetches(vResolution, SrcTexture2D, uv, BorderZeroSampler).rgb;
uv = vCenterTexcoord + vSrcTexelSize * float2(-1.0, 0.0);
float3 fLColor = SrcTexture2D.SampleLevel(BorderZeroSampler, uv, 0);
float3 fLColor = SrcTexture2D.SampleLevel(BorderZeroSampler, uv, 0).rgb;
uv = vCenterTexcoord + vSrcTexelSize * float2(1.0, 0.0);
float3 fRColor = SrcTexture2D.SampleLevel(BorderZeroSampler, uv, 0);
float3 fRColor = SrcTexture2D.SampleLevel(BorderZeroSampler, uv, 0).rgb;
uv = vCenterTexcoord + vSrcTexelSize * float2(-1.0, +1.0);
float3 fLBColor = BilinearFetches(vResolution, SrcTexture2D, uv, BorderZeroSampler);
float3 fLBColor = BilinearFetches(vResolution, SrcTexture2D, uv, BorderZeroSampler).rgb;
uv = vCenterTexcoord + vSrcTexelSize * float2(0.0, 1.0);
float3 fBColor = SrcTexture2D.SampleLevel(BorderZeroSampler, uv, 0);
float3 fBColor = SrcTexture2D.SampleLevel(BorderZeroSampler, uv, 0).rgb;
uv = vCenterTexcoord + vSrcTexelSize * float2(+1.0, +1.0);
float3 fRBColor = BilinearFetches(vResolution, SrcTexture2D, uv, BorderZeroSampler);
float3 fRBColor = BilinearFetches(vResolution, SrcTexture2D, uv, BorderZeroSampler).rgb;
return vCenterColor * 0.25f + (fLTColor + fRTColor + fLBColor + fRBColor) * 0.0625f + (fTColor + fLColor + fRColor + fBColor) * 0.125f;
}
@@ -28,11 +28,14 @@ cbuffer g_ConstantBuffer : register(b0) // b0 << 이 숫자와 컨스턴트 쉐
row_major matrix InvProjMatrix;
row_major matrix InvViewMatrix;
row_major matrix ShadowViewMatrix;
row_major matrix ShadowViewProjMatrix;
float fAsymmetryParameter;
float padding0;
float padding1;
float padding2;
}
uint iNumLight;
float fHeightOffset;
float fBaseHeight;
};
float ConvertNdcZToDepth(float ndcZ);
float SliceTickness(float ndcZ, uint dimZ);
@@ -5,16 +5,17 @@ static const float EPSILON = 1e-6f;
struct LightData
{
uint itype;
float3 vDirection;
float3 vPosition;
float fRange;
float4 vColor;
float3 vDirection;
float fRange;
float4 vPosition;
float4 vDiffuse;
};
//StructuredBuffer<LightData> g_LightBuffer : register(t1);
StructuredBuffer<LightData> g_LightBuffer : register(t0);
Texture2D<float4> g_ShadowMap : register(t1);
Texture2D<float4> NoiseTexture : register(t2);
SamplerState g_Sampler : register(s0);
RWTexture3D<float4> g_VolumeUAV : register(u0);
@@ -39,18 +40,22 @@ cbuffer g_ConstantBuffer : register(b0) // b0 << 이 숫자와 컨스턴트 쉐
row_major matrix InvProjMatrix;
row_major matrix InvViewMatrix;
row_major matrix ShadowViewMatrix;
row_major matrix ShadowViewProjMatrix;
float fAsymmetryParameter;
float padding0;
float padding1;
float padding2;
}
uint iNumLight;
float fHeightOffset;
float fBaseHeight;
};
float3 ConvertThreadIdToNdc(uint3 id, uint3 dims);
float ConvertNdcZToDepth(float ndcZ);
float3 ConvertToWorldPosition(float3 ndc, float depth);
float3 ConvertThreadIdToWorldPosition(uint3 id, uint3 dims);
float HenyeyGreensteinPhaseFunction(float3 vInputDir, float3 vOutputDir, float fAnisotropy);
float ComputePointLightVisible(float3 vLightDir, float fRange);
float ComputeShadowVisibility(float3 vWorldPosition);
// 볼륨 텍스쳐 밀도, 산란 계산
[numthreads(8, 8, 4)]
void CS_MAIN( uint3 DispatchThreadID : SV_DispatchThreadID)
@@ -60,18 +65,40 @@ void CS_MAIN( uint3 DispatchThreadID : SV_DispatchThreadID)
if (!all(DispatchThreadID < dims))
return;
float3 worldPosition = ConvertThreadIdToWorldPosition(DispatchThreadID, dims);
float3 toCamera = normalize(vCameraPosition - worldPosition);
float3 vWorldPosition = ConvertThreadIdToWorldPosition(DispatchThreadID, dims);
float3 toCamera = normalize(vCameraPosition - vWorldPosition);
float3 lighting = vLightColor.rgb * vLightColor.a;
float3 lightDir = normalize(vLightDirection);
float3 toLight = -lightDir;
float3 lighting = float3(0.1f, 0.1f, 0.1f); //vLightColor.rgb * vLightColor.a;
float phase = HenyeyGreensteinPhaseFunction(lightDir, toCamera, fAsymmetryParameter);
float3 lightDir = float3(0.f, 0.f, 0.f);
lighting += vLightColor.rgb * vLightColor.rgb * phase;
[loop]
for (uint i = 0; i < iNumLight; ++i)
{
float visibility = 1.f;
if (0.f < length(g_LightBuffer[i].vDirection))
{
lightDir = normalize(g_LightBuffer[i].vDirection);
visibility = ComputeShadowVisibility(vWorldPosition);
g_VolumeUAV[DispatchThreadID] = float4(lighting * fLightIntensity * fDensity, fDensity);
}
else
{
lightDir = vWorldPosition - g_LightBuffer[i].vPosition.xyz;
visibility = ComputePointLightVisible(lightDir, g_LightBuffer[i].fRange);
lightDir = normalize(lightDir);
}
float3 toLight = -lightDir;
float phase = HenyeyGreensteinPhaseFunction(lightDir, toCamera, fAsymmetryParameter);
lighting += g_LightBuffer[i].vDiffuse.rgb * g_LightBuffer[i].vDiffuse.a * phase * visibility;
}
float fHeightDensity = max(0.1f, exp(-(vWorldPosition.y - fBaseHeight) * fHeightOffset)) * fDensity;
g_VolumeUAV[DispatchThreadID] = float4(lighting * fLightIntensity * fHeightDensity, fHeightDensity);
}
float3 ConvertThreadIdToNdc(uint3 id, uint3 dims)
@@ -109,3 +136,26 @@ float HenyeyGreensteinPhaseFunction(float3 vInputDir, float3 vOutputDir, float f
float denom = pow(1.f + (fAsymmetryParameter * fAsymmetryParameter) - 2.f * fAsymmetryParameter * cosTheta, 3.f / 2.f);
return (1.f / (4.f * PI)) * ((1.f - (fAsymmetryParameter * fAsymmetryParameter)) / max(denom, EPSILON));
}
float ComputePointLightVisible(float3 vLightDir, float fRange)
{
float fDistance = length(vLightDir);
if (fDistance < fRange)
return 1.f;
else
return 0.f;
}
float ComputeShadowVisibility(float3 vWorldPosition)
{
float4 vShadowCoord = mul(float4(vWorldPosition, 1.f), ShadowViewProjMatrix);
float3 DepthUV = vShadowCoord.xyz / vShadowCoord.w;
DepthUV.x = DepthUV.x * 0.5f + 0.5f;
DepthUV.y = DepthUV.y * -0.5f + 0.5f;
//float fNoise = NoiseTexture.SampleLevel(g_Sampler, DepthUV.xy, 4).r;
return 1.f;
}
@@ -724,6 +724,11 @@ _matrix CGameInstance::Get_Transform_Matrix(D3DTS eState)
return m_pPipeLine->Get_Transform_Matrix(eState);
}
_matrix CGameInstance::Get_ShadowTransform_Matrix(D3DTS eState, SHADOW eShadowType)
{
return m_pPipeLine->Get_ShadowTransform_Matrix(eState, eShadowType);
}
const _float4* CGameInstance::Get_CamPosition()
{
return m_pPipeLine->Get_CamPosition();
@@ -819,6 +824,15 @@ HRESULT CGameInstance::Render_Lights(_uint _iCurrentLevel, CShader* pShader, CVI
return m_pLight_Manager->Render_Lights(_iCurrentLevel, pShader, pVIBuffer);
}
list<class CLight*>* CGameInstance::Get_LightList(_uint _iCurrentLevel)
{
return m_pLight_Manager->Get_LightList(_iCurrentLevel);
}
_uint CGameInstance::Get_NumLight(_uint _iCurrentLevel)
{
return m_pLight_Manager->Get_NumLight(_iCurrentLevel);
}
HRESULT CGameInstance::Add_ColliderGroup(_uint iColliderGroup, class CCollider* pBounding)
{
@@ -908,6 +922,11 @@ HRESULT CGameInstance::Clear_RenderTarget(const _wstring& strRenderTargetKey)
return m_pRenderTarget_Manager->Clear_RenderTarget(strRenderTargetKey);
}
ID3D11ShaderResourceView* CGameInstance::Get_RenderTarget_SRV(const _wstring& strRenderTargetKey)
{
return m_pRenderTarget_Manager->Get_RenderTarget_SRV(strRenderTargetKey);
}
#ifdef _DEBUG
void CGameInstance::RenderTarget_Debuger()
{
@@ -1324,6 +1343,11 @@ void CGameInstance::Setting_Volumetirc(_float fDensity, _float fLightIntensity,
m_pVolumetric->Setting_Volumetirc(fDensity , fLightIntensity , fAsymmetryParameter, fDepthPackExponent);
}
void CGameInstance::Update_Volumetric()
{
m_pVolumetric->Update();
}
#pragma endregion
void CGameInstance::Release_Engine()
{
@@ -84,6 +84,14 @@ const LIGHT_DESC* CLight_Manager::Get_Light_Info(_uint _iCurrentLevel, _uint _iL
return (*iter)->Get_LightDesc();
}
_uint CLight_Manager::Get_NumLight(_uint _iCurrentLevel)
{
if(true == m_Lights[_iCurrentLevel].empty())
return 0;
return static_cast<_uint>(m_Lights[_iCurrentLevel].size());
}
HRESULT CLight_Manager::Render_Lights(_uint iCurrentLevel, CShader* pShader, CVIBuffer* pVIBuffer)
{
@@ -24,6 +24,23 @@ _matrix CPipeLine::Get_Transform_Matrix(D3DTS eState)
return XMLoadFloat4x4(&m_TransformStateMatrices[ENUM_CLASS(eState)]);
}
_matrix CPipeLine::Get_ShadowTransform_Matrix(D3DTS eState, SHADOW eShadowType)
{
_uint iPass = UINT_MAX;
if (0 < ((_ubyte)eShadowType & (_ubyte)SHADOW::SHADOW_NEAR)) {
iPass = 0;
}
else if (0 < ((_ubyte)eShadowType & (_ubyte)SHADOW::SHADOW_MIDDLE)) {
iPass = 1;
}
else if (0 < ((_ubyte)eShadowType & (_ubyte)SHADOW::SHADOW_FAR)) {
iPass = 2;
}
assert(iPass != UINT_MAX);
return XMLoadFloat4x4(&m_ShadowTransformStateMatrices[iPass][ENUM_CLASS(eState)]);
}
const _float4* CPipeLine::Get_CamPosition()
{
return &m_vCamPosition;
@@ -252,6 +252,16 @@ HRESULT CRenderTarget_Manager::Clear_RenderTarget(const _wstring& strRenderTarge
return S_OK;
}
ID3D11ShaderResourceView* CRenderTarget_Manager::Get_RenderTarget_SRV(const _wstring& strRenderTargetKey)
{
CRenderTarget* pRenderTarget = Find_RenderTarget(strRenderTargetKey);
if(nullptr == pRenderTarget)
return nullptr;
return pRenderTarget->Get_SRV();
}
HRESULT CRenderTarget_Manager::Accumulate_RenderTarget(CVIBuffer_Rect* pVIBuffer, CShader* pShader,
const _wstring& wstrRenderTarget_SrcA, const _wstring& wstrRenderTarget_SrcB,
+132 -9
View File
@@ -27,18 +27,71 @@ HRESULT CVolumetric::Initialize()
if(FAILED(CreateResourceViews()))
return E_FAIL;
if(FAILED(Create_SamplerState()))
return E_FAIL;
return S_OK;
}
void CVolumetric::Update()
{
}
void CVolumetric::Cumpute_Volume()
{
EVENTSCOPE_("Render_Cumpute_Volume");
XMStoreFloat4x4(&m_ShadowViewMatrix,
m_pGameInstance->Get_ShadowTransform_Matrix(D3DTS::VIEW, SHADOW::SHADOW_MIDDLE));
XMStoreFloat4x4(&m_ShadowViewProjMatrix,
m_pGameInstance->Get_ShadowTransform_Matrix(D3DTS::VIEW, SHADOW::SHADOW_MIDDLE) *
m_pGameInstance->Get_ShadowTransform_Matrix(D3DTS::PROJ, SHADOW::SHADOW_MIDDLE)
);
/* Light Buffer Update */
D3D11_MAPPED_SUBRESOURCE LightSubResource = {};
if (FAILED(m_pContext->Map(m_pLightInfoBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &LightSubResource)))
{
MSG_BOX("Failed to Map : CVolumetric");
}
else
{
_uint iCurentLevel = m_pGameInstance->Get_CurrentLevelID();
m_iNumLights = min(m_iMaxNumLights, m_pGameInstance->Get_NumLight(iCurentLevel));
if (0 != m_iNumLights)
{
CS_LIGHT_DESC* pDesc = static_cast<CS_LIGHT_DESC*>(LightSubResource.pData);
list<class CLight*>* Lights = m_pGameInstance->Get_LightList(iCurentLevel);
_uint iIndex = 0;
for (auto& Light : *Lights)
{
const LIGHT_DESC* pLihgtDesc = Light->Get_LightDesc();
memcpy(&pDesc[iIndex].vDiffuse, &pLihgtDesc->vDiffuse, sizeof(_float4));
if(LIGHT::DIRECTIONAL != pLihgtDesc->eType)
{
memcpy(&pDesc[iIndex].vPosition, pLihgtDesc->pPosition, sizeof(_float3));
ZeroMemory(&pDesc[iIndex].vDirection, sizeof(_float3));
}
else
memcpy(&pDesc[iIndex].vDirection , pLihgtDesc->pDirection, sizeof(_float4));
pDesc[iIndex].fRange = pLihgtDesc->fRange;
++iIndex;
if (m_iMaxNumLights <= iIndex)
break;
}
}
m_pContext->Unmap(m_pLightInfoBuffer, 0);
}
/* Constannt Buffer Update */
D3D11_MAPPED_SUBRESOURCE ConstantSubResource = {};
if (FAILED(m_pContext->Map(m_pConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &ConstantSubResource)))
@@ -74,10 +127,13 @@ void CVolumetric::Cumpute_Volume()
XMStoreFloat4x4(&pDesc->InvProjMatrix, m_pGameInstance->Get_Transform_Matrix(D3DTS::PROJ_INV));
XMStoreFloat4x4(&pDesc->InvViewMatrix, m_pGameInstance->Get_Transform_Matrix(D3DTS::VIEW_INV));
XMStoreFloat4x4(&pDesc->ShadowViewMatrix, XMLoadFloat4x4(&m_ShadowViewMatrix));
XMStoreFloat4x4(&pDesc->ShadowViewProjMatrix, XMLoadFloat4x4(&m_ShadowViewProjMatrix));
pDesc->fAsymmetryParameter = m_fAsymmetryParameter;
pDesc->padding0 = 0.f;
pDesc->padding1 = 0.f;
pDesc->padding2 = 0.f;
pDesc->iNumLight = m_iNumLights;
pDesc->fHeightOffset = m_fHieghtOffset;
pDesc->fBaseHeight = m_fBaseHeight;
m_pContext->Unmap(m_pConstantBuffer, 0);
}
@@ -88,6 +144,15 @@ void CVolumetric::Cumpute_Volume()
//SRV, UAV 바인딩
m_pContext->CSSetUnorderedAccessViews(0, 1, &m_pVolumeUAV, nullptr);
m_pContext->CSSetShaderResources(0, 1, &m_pLightInfoSRV);
// Sampler 바인딩
m_pContext->CSSetSamplers(0, 1, &m_pSamplerState);
// 쉐도우 맵 바인딩
ID3D11ShaderResourceView* ShadowSRV[1] = { m_pGameInstance->Get_RenderTarget_SRV(TEXT("Target_Shadow_Middle")) };
m_pContext->CSSetShaderResources(1, 1, ShadowSRV);
m_pContext->CSSetShaderResources(2, 1, &m_pNoiseTexture);
//컴퓨트 쉐이더 실행
XMUINT3 vGroupCount = { (160 + 7) / 8, (90 + 7) / 8, (128 + 3) / 4 };
@@ -169,6 +234,9 @@ void CVolumetric::Free()
SAFE_RELEASE(m_pConstantBuffer);
SAFE_RELEASE(m_pLightInfoBuffer);
SAFE_RELEASE(m_pLightInfoSRV);
SAFE_RELEASE(m_pSamplerState);
SAFE_RELEASE(m_pNoiseTexture);
SAFE_RELEASE(m_pAccVolumeUAV);
SAFE_RELEASE(m_pAccVolumeSRV);
@@ -197,6 +265,8 @@ void CVolumetric::Describe_Entity()
GUI::SliderFloat("LightIntensity", &m_fLightIntensity, 0.01f, 0.5f, "%.4f");
GUI::SliderFloat("AsymmetryParameter", &m_fAsymmetryParameter, -0.9f, 0.9f, "%.4f");
GUI::SliderFloat("DepthPackExponent", &m_fDepthPackExponent, 0.01f, 5.f);
GUI::SliderFloat("HieghtOffset", &m_fHieghtOffset, 0.f, 1.f, "%.5f");
GUI::InputFloat("BaseHeight", &m_fBaseHeight, 0.1f, 1.f);
}
GUI::End();
@@ -268,8 +338,6 @@ HRESULT CVolumetric::CreateBuffers()
cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
cbDesc.ByteWidth = sizeof(CS_VOLUME_CONSTANT_DESC);
D3D11_SUBRESOURCE_DATA CBInitialDesc = {};
if (FAILED(m_pDevice->CreateBuffer(&cbDesc, nullptr, &m_pConstantBuffer)))
return E_FAIL;
@@ -304,13 +372,26 @@ HRESULT CVolumetric::CreateBuffers()
XMStoreFloat4x4(&pDesc->InvViewMatrix, m_pGameInstance->Get_Transform_Matrix(D3DTS::VIEW_INV));
pDesc->fAsymmetryParameter = 0.0f;
pDesc->padding0 = 0.f;
pDesc->padding1 = 0.f;
pDesc->padding2 = 0.f;
pDesc->iNumLight = 0;
pDesc->fHeightOffset = 0.f;
pDesc->fBaseHeight = 0.f;
m_pContext->Unmap(m_pConstantBuffer, 0);
}
// 라이트 정보 버퍼 생성
D3D11_BUFFER_DESC cbLIghtDesc = {};
cbLIghtDesc.Usage = D3D11_USAGE_DYNAMIC;
cbLIghtDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
cbLIghtDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
cbLIghtDesc.ByteWidth = sizeof(CS_LIGHT_DESC) * m_iMaxNumLights;
cbLIghtDesc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
cbLIghtDesc.StructureByteStride = sizeof(CS_LIGHT_DESC);
if (FAILED(m_pDevice->CreateBuffer(&cbLIghtDesc, nullptr, &m_pLightInfoBuffer)))
return E_FAIL;
return S_OK;
}
@@ -358,6 +439,48 @@ HRESULT CVolumetric::CreateResourceViews()
if (FAILED(m_pDevice->CreateUnorderedAccessView(m_pAccumulateTexture3D, &UAV_Decs, &m_pAccVolumeUAV)))
return E_FAIL;
// Light Info SRV
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
srvDesc.Format = DXGI_FORMAT_UNKNOWN;
srvDesc.ViewDimension = D3D_SRV_DIMENSION_BUFFER;
srvDesc.Buffer.FirstElement = 0;
srvDesc.Buffer.NumElements = m_iMaxNumLights;
if (FAILED(m_pDevice->CreateShaderResourceView(m_pLightInfoBuffer, &srvDesc, &m_pLightInfoSRV)))
return E_FAIL;
// Noise Texture SRV
if(FAILED(CreateDDSTextureFromFile(m_pDevice,
TEXT("C:/MeshTable/Game/Environment/MasterMaterials/BaseTextures/Noise/T_PerlinNoise.dds"),
nullptr,
&m_pNoiseTexture
)))
{
assert(false);
return E_FAIL;
}
return S_OK;
}
HRESULT CVolumetric::Create_SamplerState()
{
D3D11_SAMPLER_DESC desc = {};
desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
desc.MinLOD = 0.0f;
desc.MaxLOD = D3D11_FLOAT32_MAX;
if (FAILED(m_pDevice->CreateSamplerState(&desc, &m_pSamplerState)))
{
assert(false);
return E_FAIL;
}
return S_OK;
}
+6 -1
View File
@@ -94,7 +94,7 @@ class ENGINE_DLL CGameInstance final : public CBase
}
return hr;
}
void Set_LayerEnabled(_bool isEnable);
class CLayer* Get_Layer(_uint iLayerLevelIndex, const _wstring& strLayerTag);
void Clear_Objects_With_Layers(_uint iLevelIndex);
@@ -136,6 +136,7 @@ class ENGINE_DLL CGameInstance final : public CBase
void Set_Transform(D3DTS eState, _fmatrix TransformStateMatrix);
const _float4x4* Get_Transform_Float4x4(D3DTS eState);
_matrix Get_Transform_Matrix(D3DTS eState);
_matrix Get_ShadowTransform_Matrix(D3DTS eState, SHADOW eShadowType);
const _float4* Get_CamPosition();
const _vector Get_CamXMPosition();
void Transform_Frustum_ToLocalSpace(_fmatrix WorldMatrixInverse);
@@ -158,6 +159,8 @@ class ENGINE_DLL CGameInstance final : public CBase
void Delete_Light(_uint _iCurrentLevel, class CLight* _pLight);
const LIGHT_DESC* Get_Light_Info(_uint _iCurrentLevel, _uint _iLightIndex);
HRESULT Render_Lights(_uint _iCurrentLevel, class CShader* pShader, class CVIBuffer* pVIBuffer);
list<class CLight*>* Get_LightList(_uint _iCurrentLevel);
_uint Get_NumLight(_uint _iCurrentLevel);
#pragma endregion
#pragma region COLLIDER_MANAGER
HRESULT Add_ColliderGroup(_uint iColliderGroup, class CCollider* pBounding);
@@ -183,6 +186,7 @@ class ENGINE_DLL CGameInstance final : public CBase
HRESULT Finish_RenderTarget(class CVIBuffer_Rect* pVIBuffer, class CShader* pShader, const _wstring& wstrRenderTargetOriginal, const _wstring& wstrRenderTargetBloomed, SHADER_PASS_DEFERRED ePass);
HRESULT Bind_CS_RenderTarget(_uint iIndex, const _wstring& strTargetTag);
HRESULT Clear_RenderTarget(const _wstring& strRenderTargetKey);
ID3D11ShaderResourceView* Get_RenderTarget_SRV(const _wstring& strRenderTargetKey);
#ifdef _DEBUG
void RenderTarget_Debuger();
HRESULT Render_RenderTarget_Debug(class CShader* pShader, class CVIBuffer_Rect* pVIBuffer);
@@ -272,6 +276,7 @@ class ENGINE_DLL CGameInstance final : public CBase
ID3D11ShaderResourceView* Get_VolumeSRV();
_float* Get_DepthPackExponentPtr();
void Setting_Volumetirc(_float fDensity, _float fLightIntensity, _float fAsymmetryParameter, _float fDepthPackExponent);
void Update_Volumetric();
#pragma endregion
@@ -15,7 +15,8 @@ class CLight_Manager final : public CBase
void Delete_Light(_uint _iCurrentLevel, class CLight* _pLight);
void Light_Clear(_uint _iCurrentLevel);
const LIGHT_DESC* Get_Light_Info(_uint _iCurrentLevel ,_uint _iLightIndex);
list<class CLight*>* Get_LightList(_uint _iCurrentLevel) { return &m_Lights[_iCurrentLevel]; }
_uint Get_NumLight(_uint _iCurrentLevel);
public:
HRESULT Render_Lights(_uint iCurrentLevel, class CShader* pShader, class CVIBuffer* pVIBuffer);
+1
View File
@@ -27,6 +27,7 @@ class CPipeLine final : public CBase
void Set_Transform(D3DTS eState, _fmatrix TransformStateMatrix);
const _float4x4* Get_Transform_Float4x4(D3DTS eState);
_matrix Get_Transform_Matrix(D3DTS eState);
_matrix Get_ShadowTransform_Matrix(D3DTS eState, SHADOW eShadowType);
const _float4* Get_CamPosition();
const _vector Get_CamXMPosition();
@@ -23,7 +23,7 @@ class CRenderTarget_Manager final : public CBase
HRESULT Copy_RenderTargetAToB(const _wstring& strATag, const _wstring& strBTag);
HRESULT Bind_CS_RenderTarget(_uint iIndex, const _wstring& strTargetTag);
HRESULT Clear_RenderTarget(const _wstring& strRenderTargetKey);
ID3D11ShaderResourceView* Get_RenderTarget_SRV(const _wstring& strRenderTargetKey);
// 두 랜더타겟을 하나로 모음
HRESULT Accumulate_RenderTarget(class CVIBuffer_Rect* pVIBuffer, class CShader* pShader, const _wstring& wstrRenderTarget_SrcA, const _wstring& wstrRenderTarget_SrcB, const _wstring& wstrRenderTarget_Target, SHADER_PASS_DEFERRED ePass);
// 랜더 타겟의 크기를 dest로 다시 맞춤
+29 -6
View File
@@ -27,12 +27,22 @@ class CVolumetric final : public CBase
_float4x4 InvProjMatrix;
_float4x4 InvViewMatrix;
_float4x4 ShadowViewMatrix;
_float4x4 ShadowViewProjMatrix;
_float fAsymmetryParameter;
_float padding0;
_float padding1;
_float padding2;
_uint iNumLight;
_float fHeightOffset;
_float fBaseHeight;
}CS_VOLUME_CONSTANT_DESC;
typedef struct tagCSLightDesc
{
_float3 vDirection;
_float fRange;
_float4 vPosition;
_float4 vDiffuse;
}CS_LIGHT_DESC;
private:
CVolumetric(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
@@ -46,7 +56,7 @@ class CVolumetric final : public CBase
HRESULT Dispatch();
ID3D11ShaderResourceView* Get_VolumeSRV() { return m_pAccVolumeSRV; }
_float* Get_DepthPackExponentPtr() { return &m_fDepthPackExponent; }
_float* Get_DepthPackExponentPtr() { return &m_fDepthPackExponent; }
void Setting_Volumetirc(_float fDensity , _float fLightIntensity, _float fAsymmetryParameter , _float fDepthPackExponent);
private:
@@ -56,6 +66,8 @@ class CVolumetric final : public CBase
ID3D11Texture3D* m_pTexture3D = { nullptr };
ID3D11Texture3D* m_pAccumulateTexture3D = { nullptr };
ID3D11ShaderResourceView* m_pNoiseTexture = { nullptr };
ID3D11ShaderResourceView* m_pVolumeSRV = {nullptr};
ID3D11UnorderedAccessView* m_pVolumeUAV = { nullptr };
@@ -64,6 +76,7 @@ class CVolumetric final : public CBase
ID3D11Buffer* m_pConstantBuffer = { nullptr };
ID3D11Buffer* m_pLightInfoBuffer = { nullptr };
ID3D11ShaderResourceView* m_pLightInfoSRV = { nullptr };
ID3D11ComputeShader* m_pCSVolumeCalculate = { nullptr };
ID3DBlob* m_pCSBlobCalculate = { nullptr };
@@ -71,10 +84,19 @@ class CVolumetric final : public CBase
ID3D11ComputeShader* m_pCSVolumeAccumulate = { nullptr };
ID3DBlob* m_pCSBlobAccumulate = { nullptr };
ID3D11SamplerState* m_pSamplerState = { nullptr };
_float m_fDensity = { 0.953f }; // 밀도
_float m_fLightIntensity = { 0.01f }; // 광원 강도
_float m_fLightIntensity = { 0.01f }; // 광원 강도
_float m_fAsymmetryParameter = { 0.5344f }; // 이방성 계수 값이 클 수록 들어오는 방향으로 나가는 빛의 양이 많아짐
_float m_fDepthPackExponent = { 1.f }; // 깊이 비선형 분포 지수
_float m_fDepthPackExponent = { 1.f }; // 깊이 비선형 분포 지수
_float m_fHieghtOffset = { 0.f };
_float m_fBaseHeight = { 0.f };
_uint m_iNumLights = { 1 };
_uint m_iMaxNumLights = { 20 };
_float4x4 m_ShadowViewMatrix = {};
_float4x4 m_ShadowViewProjMatrix = {};
#ifdef _DEBUG
class CRenderEventDebugger m_AnnotationHelper = {};
@@ -87,6 +109,7 @@ class CVolumetric final : public CBase
HRESULT CreateBlob();
HRESULT CreateBuffers();
HRESULT CreateResourceViews();
HRESULT Create_SamplerState();
public:
static CVolumetric* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);