[add] no-ssao
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
cbuffer GLOBAL_SSAO_DATA : register(b10)
|
||||
{
|
||||
float3 SamplePos[64];
|
||||
float4 SamplePos[64];
|
||||
};
|
||||
|
||||
#endif // ENGINE_SHADER_BUFFERS_HLSLI
|
||||
|
||||
@@ -141,9 +141,9 @@ PS_OUT_LIGHT PS_MAIN_DIRECTIONAL(PS_IN In)
|
||||
|
||||
float2 uv = In.vTexcoord;
|
||||
|
||||
float3 vAlbedo = g_DiffuseTexture.Sample(DefaultSampler, uv).rgb;
|
||||
float3 vNormal = normalize(g_NormalTexture.Sample(DefaultSampler, uv).xyz * 2.f - 1.f);
|
||||
float4 vDepth = g_DepthTexture.Sample(DefaultSampler, uv);
|
||||
float3 vAlbedo = g_DiffuseTexture.Sample(DefaultSampler, uv).rgb;
|
||||
float3 vNormal = normalize(g_NormalTexture.Sample(DefaultSampler, uv).xyz * 2.f - 1.f);
|
||||
float4 vDepth = g_DepthTexture.Sample(DefaultSampler, uv);
|
||||
float fAmbientOcclusion = g_SSAOInputTexture.Sample(DefaultSampler, uv).r;
|
||||
|
||||
float fViewZ = vDepth.y * g_fFar;
|
||||
@@ -571,7 +571,6 @@ PS_OUT_FLT4_SINGLE PS_MAIN_EMBOSS(PS_IN In)
|
||||
{
|
||||
case 0:
|
||||
/* None */
|
||||
vColor = float3(0.f, 0.f, 0.f);
|
||||
break;
|
||||
case 1:
|
||||
/* Basic_Apply */
|
||||
@@ -919,16 +918,16 @@ PS_OUT_SSAO_AMBIENT_OCCLUSION PS_SSAO_AMBIENT_OCCLUSION(PS_IN In)
|
||||
|
||||
float4 vCenterViewPosition;
|
||||
{
|
||||
vCenterViewPosition.x = uv.x * 2 - 1;
|
||||
vCenterViewPosition.y = uv.y * -2 + 1;
|
||||
vCenterViewPosition.x = uv.x * 2.f - 1.f;
|
||||
vCenterViewPosition.y = uv.y * -2.f + 1.f;
|
||||
vCenterViewPosition.z = vDepthDesc.x;
|
||||
vCenterViewPosition.w = 1.f;
|
||||
vCenterViewPosition *= fCenterViewSpaceZ;
|
||||
vCenterViewPosition = mul(vCenterViewPosition, g_invmatProj);
|
||||
vCenterViewPosition /= vCenterViewPosition.w;
|
||||
}
|
||||
float3 vNormal = normalize(g_NormalTexture.Sample(PointSampler, uv).xyz * 2.f - 1.f);
|
||||
float3 vCenterViewNormal = mul(vNormal, (float3x3) g_ViewMatrix);
|
||||
float3 vCenterProjNormal = mul(vCenterViewNormal, (float3x3) g_ProjMatrix);
|
||||
float3 vCenterViewNormal = mul(vNormal, (float3x3)g_ViewMatrix);
|
||||
|
||||
float2 vNoiseScale = g_vResolution / 4.f;
|
||||
float3 vNoise = g_SSAONoiseTexture.Sample(SsaoDataSampler, uv * vNoiseScale).xyz;
|
||||
@@ -943,25 +942,19 @@ PS_OUT_SSAO_AMBIENT_OCCLUSION PS_SSAO_AMBIENT_OCCLUSION(PS_IN In)
|
||||
float3 vViewSamplePosVec = mul(SamplePos[i], toViewTBNMatrix); // TANSPACE -> VIEW
|
||||
float4 vViewSamplePos = vCenterViewPosition + float4(vViewSamplePosVec * g_fSSAORadius, 0.f);
|
||||
float4 vNDCSampleOffset = mul(vViewSamplePos, g_ProjMatrix);
|
||||
vNDCSampleOffset /= vNDCSampleOffset.w;
|
||||
vNDCSampleOffset /= vNDCSampleOffset.w;
|
||||
|
||||
float2 sampleUV = vNDCSampleOffset.xy * 0.5f + 0.5f;
|
||||
// 스크린 밖이면 스킵
|
||||
float2 sampleUV;
|
||||
sampleUV.x = vNDCSampleOffset.x * 0.5f + 0.5f;
|
||||
sampleUV.y = vNDCSampleOffset.y * -0.5f + 0.5f;
|
||||
|
||||
if (sampleUV.x < 0 || sampleUV.x > 1
|
||||
|| sampleUV.y < 0 || sampleUV.y > 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
float fRecordedSampleViewPosDepth = g_DepthTexture.Sample(PointSampler, sampleUV).y * g_fFar;
|
||||
float fIsOccluded = 1.f;
|
||||
if (g_bSSAO_INVERT)
|
||||
{
|
||||
fIsOccluded = (fRecordedSampleViewPosDepth < vViewSamplePos.z - g_fSSAO_BIAS) ? 1.0f : 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
fIsOccluded = (fRecordedSampleViewPosDepth > vViewSamplePos.z - g_fSSAO_BIAS) ? 1.0f : 0.0f;
|
||||
}
|
||||
float fIsOccluded = (fRecordedSampleViewPosDepth < vViewSamplePos.z - g_fSSAO_BIAS) ? 1.0f : 0.0f;
|
||||
|
||||
float fRangeCheck = smoothstep(0.f, 1.f, g_fSSAORadius / abs(vViewSamplePos.z - fRecordedSampleViewPosDepth));
|
||||
fIsOccluded *= fRangeCheck;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
cbuffer GLOBAL_SSAO_DATA : register(b10)
|
||||
{
|
||||
float3 SamplePos[64];
|
||||
float4 SamplePos[64];
|
||||
};
|
||||
|
||||
#endif // ENGINE_SHADER_BUFFERS_HLSLI
|
||||
|
||||
@@ -141,9 +141,9 @@ PS_OUT_LIGHT PS_MAIN_DIRECTIONAL(PS_IN In)
|
||||
|
||||
float2 uv = In.vTexcoord;
|
||||
|
||||
float3 vAlbedo = g_DiffuseTexture.Sample(DefaultSampler, uv).rgb;
|
||||
float3 vNormal = normalize(g_NormalTexture.Sample(DefaultSampler, uv).xyz * 2.f - 1.f);
|
||||
float4 vDepth = g_DepthTexture.Sample(DefaultSampler, uv);
|
||||
float3 vAlbedo = g_DiffuseTexture.Sample(DefaultSampler, uv).rgb;
|
||||
float3 vNormal = normalize(g_NormalTexture.Sample(DefaultSampler, uv).xyz * 2.f - 1.f);
|
||||
float4 vDepth = g_DepthTexture.Sample(DefaultSampler, uv);
|
||||
float fAmbientOcclusion = g_SSAOInputTexture.Sample(DefaultSampler, uv).r;
|
||||
|
||||
float fViewZ = vDepth.y * g_fFar;
|
||||
@@ -571,7 +571,6 @@ PS_OUT_FLT4_SINGLE PS_MAIN_EMBOSS(PS_IN In)
|
||||
{
|
||||
case 0:
|
||||
/* None */
|
||||
vColor = float3(0.f, 0.f, 0.f);
|
||||
break;
|
||||
case 1:
|
||||
/* Basic_Apply */
|
||||
@@ -919,16 +918,16 @@ PS_OUT_SSAO_AMBIENT_OCCLUSION PS_SSAO_AMBIENT_OCCLUSION(PS_IN In)
|
||||
|
||||
float4 vCenterViewPosition;
|
||||
{
|
||||
vCenterViewPosition.x = uv.x * 2 - 1;
|
||||
vCenterViewPosition.y = uv.y * -2 + 1;
|
||||
vCenterViewPosition.x = uv.x * 2.f - 1.f;
|
||||
vCenterViewPosition.y = uv.y * -2.f + 1.f;
|
||||
vCenterViewPosition.z = vDepthDesc.x;
|
||||
vCenterViewPosition.w = 1.f;
|
||||
vCenterViewPosition *= fCenterViewSpaceZ;
|
||||
vCenterViewPosition = mul(vCenterViewPosition, g_invmatProj);
|
||||
vCenterViewPosition /= vCenterViewPosition.w;
|
||||
}
|
||||
float3 vNormal = normalize(g_NormalTexture.Sample(PointSampler, uv).xyz * 2.f - 1.f);
|
||||
float3 vCenterViewNormal = mul(vNormal, (float3x3) g_ViewMatrix);
|
||||
float3 vCenterProjNormal = mul(vCenterViewNormal, (float3x3) g_ProjMatrix);
|
||||
float3 vCenterViewNormal = mul(vNormal, (float3x3)g_ViewMatrix);
|
||||
|
||||
float2 vNoiseScale = g_vResolution / 4.f;
|
||||
float3 vNoise = g_SSAONoiseTexture.Sample(SsaoDataSampler, uv * vNoiseScale).xyz;
|
||||
@@ -943,25 +942,19 @@ PS_OUT_SSAO_AMBIENT_OCCLUSION PS_SSAO_AMBIENT_OCCLUSION(PS_IN In)
|
||||
float3 vViewSamplePosVec = mul(SamplePos[i], toViewTBNMatrix); // TANSPACE -> VIEW
|
||||
float4 vViewSamplePos = vCenterViewPosition + float4(vViewSamplePosVec * g_fSSAORadius, 0.f);
|
||||
float4 vNDCSampleOffset = mul(vViewSamplePos, g_ProjMatrix);
|
||||
vNDCSampleOffset /= vNDCSampleOffset.w;
|
||||
vNDCSampleOffset /= vNDCSampleOffset.w;
|
||||
|
||||
float2 sampleUV = vNDCSampleOffset.xy * 0.5f + 0.5f;
|
||||
// 스크린 밖이면 스킵
|
||||
float2 sampleUV;
|
||||
sampleUV.x = vNDCSampleOffset.x * 0.5f + 0.5f;
|
||||
sampleUV.y = vNDCSampleOffset.y * -0.5f + 0.5f;
|
||||
|
||||
if (sampleUV.x < 0 || sampleUV.x > 1
|
||||
|| sampleUV.y < 0 || sampleUV.y > 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
float fRecordedSampleViewPosDepth = g_DepthTexture.Sample(PointSampler, sampleUV).y * g_fFar;
|
||||
float fIsOccluded = 1.f;
|
||||
if (g_bSSAO_INVERT)
|
||||
{
|
||||
fIsOccluded = (fRecordedSampleViewPosDepth < vViewSamplePos.z - g_fSSAO_BIAS) ? 1.0f : 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
fIsOccluded = (fRecordedSampleViewPosDepth > vViewSamplePos.z - g_fSSAO_BIAS) ? 1.0f : 0.0f;
|
||||
}
|
||||
float fIsOccluded = (fRecordedSampleViewPosDepth < vViewSamplePos.z - g_fSSAO_BIAS) ? 1.0f : 0.0f;
|
||||
|
||||
float fRangeCheck = smoothstep(0.f, 1.f, g_fSSAORadius / abs(vViewSamplePos.z - fRecordedSampleViewPosDepth));
|
||||
fIsOccluded *= fRangeCheck;
|
||||
|
||||
@@ -50,8 +50,13 @@ HRESULT CGameInstance::Initialize_Engine(const ENGINE_DESC& EngineDesc, ID3D11De
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef 기무리
|
||||
m_pThreadHolder = CThreadHolder::Create(12);
|
||||
#endif // 기무리
|
||||
#ifndef 기무리
|
||||
m_pThreadHolder = CThreadHolder::Create(6);
|
||||
#endif // !기무리
|
||||
|
||||
m_pThreadHolder = CThreadHolder::Create( 6 );
|
||||
|
||||
if (nullptr == m_pThreadHolder) {
|
||||
return E_FAIL;
|
||||
|
||||
@@ -461,7 +461,7 @@ PSX::PxController* CPhysX_Manager::Add_BoxController(PSX::PxBoxControllerDesc& D
|
||||
PSX::PxController* pController = { nullptr };
|
||||
|
||||
pController = m_pCCTManager->createController(Desc);
|
||||
|
||||
|
||||
return pController;
|
||||
}
|
||||
|
||||
@@ -500,12 +500,10 @@ HRESULT CPhysX_Manager::Initialize()
|
||||
return E_FAIL;
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
|
||||
if (FAILED(Connect_DebugServer())) {
|
||||
//ASSERT_NURI(false);
|
||||
//ASSERT_JINWOO(false);
|
||||
}
|
||||
|
||||
#endif // _DEBUG
|
||||
|
||||
{ // 씬 세팅
|
||||
|
||||
@@ -37,10 +37,20 @@ void CRenderer::Render()
|
||||
#ifdef _DEBUG
|
||||
Describe_Entitiy();
|
||||
m_pGameInstance->RenderTarget_Debuger();
|
||||
static _bool m_bToggleDebug = false;
|
||||
|
||||
if (m_pGameInstance->Key_Pressing(DIK_F10)) {
|
||||
Render_Debug();
|
||||
}
|
||||
else {
|
||||
GUI::Begin("RenderTarget Debuger");
|
||||
GUI::Checkbox("DebugToggle", &m_bToggleDebug);
|
||||
if (m_bToggleDebug) {
|
||||
Render_Debug();
|
||||
}
|
||||
GUI::End();
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -525,16 +535,16 @@ void CRenderer::Render_SSAO()
|
||||
#ifdef _DEBUG
|
||||
static _bool bSSAO = { true };
|
||||
static _uint iKernelSize = SSAO_SAMPLE_NUMBER;
|
||||
static _float fSSAORadius = 1.5f;
|
||||
static _float fSSAO_BIAS = 0.1f;
|
||||
static _float fSSAORadius = 0.8f;
|
||||
static _float fSSAO_BIAS = 0.1f * fSSAORadius;
|
||||
static _bool bInverted = { false };
|
||||
GUI::Begin("Renderer");
|
||||
GUI::Checkbox("bSSAO ", &bSSAO);
|
||||
if (true == bSSAO) {
|
||||
GUI::SameLine();
|
||||
if (GUI::CollapsingHeader("SSAO")) {
|
||||
GUI::DragFloat("fSSAORadius ", &fSSAORadius, 0.001f, 0.f, 3.f, "%.3f");
|
||||
GUI::DragFloat("fSSAO_BIAS", &fSSAO_BIAS, 0.001f, 0.f, 2.f, "%.3f");
|
||||
GUI::DragFloat("fSSAORadius ", &fSSAORadius, 0.0001f, -3.f, 3.f, "%.5f");
|
||||
GUI::DragFloat("fSSAO_BIAS", &fSSAO_BIAS, 0.0001f, -2.f, 2.f, "%.5f");
|
||||
GUI::Checkbox("Inverted", &bInverted);
|
||||
}
|
||||
}
|
||||
@@ -557,19 +567,15 @@ void CRenderer::Render_SSAO()
|
||||
}
|
||||
|
||||
// Bind_Resorces
|
||||
if (FAILED(m_pShader->Bind_Matrix("g_WorldMatrix", &m_WorldMatrix))){
|
||||
if (FAILED(m_pShader->Bind_Matrix("g_ViewMatrix", m_pGameInstance->Get_Transform_Float4x4(D3DTS::VIEW)))){
|
||||
assert(false);
|
||||
return ;
|
||||
}
|
||||
if (FAILED(m_pShader->Bind_Matrix("g_ViewMatrix", &m_ViewMatrix))){
|
||||
if (FAILED(m_pShader->Bind_Matrix("g_ProjMatrix", m_pGameInstance->Get_Transform_Float4x4(D3DTS::PROJ)))){
|
||||
assert(false);
|
||||
return ;
|
||||
}
|
||||
if (FAILED(m_pShader->Bind_Matrix("g_ProjMatrix", &m_ProjMatrix))){
|
||||
assert(false);
|
||||
return ;
|
||||
}
|
||||
if (FAILED(m_pShader->Bind_Matrix("g_invMatView", m_pGameInstance->Get_Transform_Float4x4(D3DTS::VIEW_INV)))){
|
||||
if (FAILED(m_pShader->Bind_Matrix("g_invMatView", m_pGameInstance->Get_Transform_Float4x4(D3DTS::VIEW_INV) ))){
|
||||
assert(false);
|
||||
return ;
|
||||
}
|
||||
@@ -609,8 +615,8 @@ void CRenderer::Render_SSAO()
|
||||
assert(false);
|
||||
return;
|
||||
}
|
||||
//m_pContext->VSSetConstantBuffers(10, 1, &m_pGlobalStaticCB);
|
||||
//m_pContext->PSSetConstantBuffers(10, 1, &m_pGlobalStaticCB);
|
||||
m_pContext->VSSetConstantBuffers(10, 1, &m_pGlobalStaticCB);
|
||||
m_pContext->PSSetConstantBuffers(10, 1, &m_pGlobalStaticCB);
|
||||
}
|
||||
{
|
||||
// Bind_Targets
|
||||
|
||||
@@ -76,7 +76,7 @@ HRESULT CRenderer::Ready_ShadowDepthStencilView(_uint iSizeX, _uint iSizeY)
|
||||
|
||||
void CRenderer::Fill_Geometry(_uint iNumSample)
|
||||
{
|
||||
uniform_real_distribution<_float> rand_Normal(0, 1.f);
|
||||
uniform_real_distribution<_float> rand_Normal(0.f, 1.f);
|
||||
uniform_real_distribution<_float> rand_Minus(-1.f, 1.f);
|
||||
mt19937 m_Rng{ random_device{}() };
|
||||
|
||||
@@ -86,11 +86,11 @@ void CRenderer::Fill_Geometry(_uint iNumSample)
|
||||
vPos = {
|
||||
rand_Minus(m_Rng),
|
||||
rand_Minus(m_Rng),
|
||||
rand_Minus(m_Rng)
|
||||
rand_Normal(m_Rng)
|
||||
};
|
||||
vPos = XMVector3Normalize(vPos) * rand_Normal(m_Rng);
|
||||
fScale = ((_float)iIndexSample / (_float)iNumSample);
|
||||
fScale = CMyTools::Lerp_f1D(0.1f, 1.f, fScale * fScale);
|
||||
fScale = CMyTools::Lerp_f1D(0.f, 1.f, fScale * fScale);
|
||||
vPos *= fScale;
|
||||
XMStoreFloat3(&m_tagSSAOGeometry.SamplePos[iIndexSample].vPos, vPos);
|
||||
}
|
||||
@@ -99,7 +99,7 @@ void CRenderer::Fill_Geometry(_uint iNumSample)
|
||||
m_tagSSAOGeometryDirections.vDir[iIndexDir] = {
|
||||
rand_Minus(m_Rng),
|
||||
rand_Minus(m_Rng),
|
||||
rand_Minus(m_Rng),
|
||||
0.f,
|
||||
0.f
|
||||
};
|
||||
}
|
||||
@@ -113,10 +113,10 @@ void CRenderer::Fill_Geometry(_uint iNumSample)
|
||||
texDesc.SampleDesc.Quality = 0;
|
||||
texDesc.Usage = D3D11_USAGE_IMMUTABLE;
|
||||
texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
|
||||
|
||||
D3D11_SUBRESOURCE_DATA initData = {};
|
||||
initData.pSysMem = &m_tagSSAOGeometryDirections;
|
||||
initData.SysMemPitch = sizeof(_float4);
|
||||
initData.pSysMem = &m_tagSSAOGeometryDirections;
|
||||
initData.SysMemPitch = sizeof(_float4) * texDesc.Width; // 16 * 4 = 64
|
||||
|
||||
if (FAILED(m_pDevice->CreateTexture2D(&texDesc, &initData, &m_pSSAO_NoiseTexture))) {
|
||||
assert(false);
|
||||
@@ -131,7 +131,6 @@ void CRenderer::Fill_Geometry(_uint iNumSample)
|
||||
|
||||
m_pDevice->CreateShaderResourceView(m_pSSAO_NoiseTexture, &srvDesc, &m_pSSAO_NoiseSRV);
|
||||
|
||||
|
||||
{
|
||||
D3D11_BUFFER_DESC desc = {};
|
||||
desc.ByteWidth = sizeof(SSAO_GEOMETRY_HEMISPHERE);
|
||||
@@ -141,7 +140,7 @@ void CRenderer::Fill_Geometry(_uint iNumSample)
|
||||
|
||||
D3D11_SUBRESOURCE_DATA initData = {};
|
||||
initData.pSysMem = &m_tagSSAOGeometry;
|
||||
initData.SysMemPitch = sizeof(_float4);
|
||||
initData.SysMemPitch = 0;
|
||||
|
||||
HRESULT hr = m_pDevice->CreateBuffer(&desc, &initData, &m_pGlobalStaticCB);
|
||||
|
||||
@@ -229,12 +228,12 @@ HRESULT CRenderer::Initialize()
|
||||
|
||||
/* Target_SSAO_AmbientOcclusion */
|
||||
if (FAILED(m_pGameInstance->Add_RenderTarget(TEXT("Target_SSAO_AmbientOcclusion"), (_uint)Viewport.Width, (_uint)Viewport.Height,
|
||||
DXGI_FORMAT_R32_FLOAT, _float4(0.f, 0.f, 0.0f, 0.0f)))) {
|
||||
DXGI_FORMAT_R32_FLOAT, _float4(1.f, 1.f, 1.f, 1.f)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
/* Target_SSAO_BLUR */
|
||||
if (FAILED(m_pGameInstance->Add_RenderTarget(TEXT("Target_SSAO_BLUR"), (_uint)Viewport.Width, (_uint)Viewport.Height,
|
||||
DXGI_FORMAT_R32_FLOAT, _float4(0.f, 0.f, 0.0f, 0.0f)))) {
|
||||
DXGI_FORMAT_R32_FLOAT, _float4(1.f, 1.f, 1.f, 1.f)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
@@ -432,7 +431,6 @@ HRESULT CRenderer::Initialize()
|
||||
|
||||
Fill_Geometry(SSAO_SAMPLE_NUMBER);
|
||||
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
CRenderer* CRenderer::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
@@ -468,6 +466,9 @@ void CRenderer::Free()
|
||||
RenderObjects.clear();
|
||||
}
|
||||
|
||||
SAFE_RELEASE(m_pGlobalStaticCB);
|
||||
SAFE_RELEASE(m_pSSAO_NoiseTexture);
|
||||
SAFE_RELEASE(m_pSSAO_NoiseSRV);
|
||||
SAFE_RELEASE(m_pPreShadowDSV);
|
||||
SAFE_RELEASE(m_pShadowDSV);
|
||||
SAFE_RELEASE(m_pShader);
|
||||
|
||||
@@ -442,6 +442,7 @@ typedef struct tagBoneDesc
|
||||
|
||||
typedef struct tagSSAO_SamplePos {
|
||||
_float3 vPos = { }; // xy(-1, 1) z(0, 1)
|
||||
_float fPad = {};
|
||||
}SSAO_SAMPLE;
|
||||
|
||||
typedef struct tagSSAO_Geometry_Hemisphere {
|
||||
|
||||
Reference in New Issue
Block a user