From 463c8dba0d968fd737f71cfe58f35ee958c53e95 Mon Sep 17 00:00:00 2001 From: ExMatics HydrogenC <33123710+HydrogenC@users.noreply.github.com> Date: Tue, 4 Jun 2024 23:22:41 +0800 Subject: [PATCH] fix depth function --- Source/Engine/Graphics/Materials/DeferredMaterialShader.cpp | 4 ++-- Source/Engine/Graphics/Materials/DeformableMaterialShader.cpp | 2 +- Source/Engine/Graphics/Materials/ForwardMaterialShader.cpp | 2 +- Source/Engine/Graphics/Materials/TerrainMaterialShader.cpp | 2 +- Source/Shaders/SSAO.shader | 2 +- Source/Shaders/Shadows.shader | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/Engine/Graphics/Materials/DeferredMaterialShader.cpp b/Source/Engine/Graphics/Materials/DeferredMaterialShader.cpp index 48f56350c..1cc3abcf5 100644 --- a/Source/Engine/Graphics/Materials/DeferredMaterialShader.cpp +++ b/Source/Engine/Graphics/Materials/DeferredMaterialShader.cpp @@ -196,7 +196,7 @@ bool DeferredMaterialShader::Load() // Motion Vectors pass psDesc.DepthWriteEnable = false; psDesc.DepthEnable = true; - psDesc.DepthFunc = ComparisonFunc::LessEqual; + psDesc.DepthFunc = ComparisonFunc::GreaterEqual; psDesc.VS = _shader->GetVS("VS"); psDesc.PS = _shader->GetPS("PS_MotionVectors"); _cache.MotionVectors.Init(psDesc); @@ -214,7 +214,7 @@ bool DeferredMaterialShader::Load() psDesc.DepthClipEnable = false; psDesc.DepthWriteEnable = true; psDesc.DepthEnable = true; - psDesc.DepthFunc = ComparisonFunc::Less; + psDesc.DepthFunc = ComparisonFunc::Greater; psDesc.HS = nullptr; psDesc.DS = nullptr; GPUShaderProgramVS* instancedDepthPassVS; diff --git a/Source/Engine/Graphics/Materials/DeformableMaterialShader.cpp b/Source/Engine/Graphics/Materials/DeformableMaterialShader.cpp index f5b7f2368..4f5825713 100644 --- a/Source/Engine/Graphics/Materials/DeformableMaterialShader.cpp +++ b/Source/Engine/Graphics/Materials/DeformableMaterialShader.cpp @@ -173,7 +173,7 @@ bool DeformableMaterialShader::Load() psDesc.DepthClipEnable = false; psDesc.DepthWriteEnable = true; psDesc.DepthEnable = true; - psDesc.DepthFunc = ComparisonFunc::Less; + psDesc.DepthFunc = ComparisonFunc::Greater; psDesc.HS = nullptr; psDesc.DS = nullptr; _cache.Depth.Init(psDesc); diff --git a/Source/Engine/Graphics/Materials/ForwardMaterialShader.cpp b/Source/Engine/Graphics/Materials/ForwardMaterialShader.cpp index af2b30348..c316daff0 100644 --- a/Source/Engine/Graphics/Materials/ForwardMaterialShader.cpp +++ b/Source/Engine/Graphics/Materials/ForwardMaterialShader.cpp @@ -205,7 +205,7 @@ bool ForwardMaterialShader::Load() psDesc.DepthClipEnable = false; psDesc.DepthWriteEnable = true; psDesc.DepthEnable = true; - psDesc.DepthFunc = ComparisonFunc::Less; + psDesc.DepthFunc = ComparisonFunc::Greater; psDesc.HS = nullptr; psDesc.DS = nullptr; psDesc.VS = _shader->GetVS("VS"); diff --git a/Source/Engine/Graphics/Materials/TerrainMaterialShader.cpp b/Source/Engine/Graphics/Materials/TerrainMaterialShader.cpp index c155cb7f2..b396bd418 100644 --- a/Source/Engine/Graphics/Materials/TerrainMaterialShader.cpp +++ b/Source/Engine/Graphics/Materials/TerrainMaterialShader.cpp @@ -185,7 +185,7 @@ bool TerrainMaterialShader::Load() psDesc.DepthClipEnable = false; psDesc.DepthWriteEnable = true; psDesc.DepthEnable = true; - psDesc.DepthFunc = ComparisonFunc::Less; + psDesc.DepthFunc = ComparisonFunc::Greater; psDesc.HS = nullptr; psDesc.DS = nullptr; // TODO: masked terrain materials (depth pass should clip holes) diff --git a/Source/Shaders/SSAO.shader b/Source/Shaders/SSAO.shader index c1282a94d..e72d9a30c 100644 --- a/Source/Shaders/SSAO.shader +++ b/Source/Shaders/SSAO.shader @@ -275,7 +275,7 @@ void PrepareDepthMip(const float4 inPos, int mipLevel, out float outD0, out floa { float4 depths = depthsArr[i]; - float closest = max(max(depths.x, depths.y), max(depths.z, depths.w)); + float closest = min(min(depths.x, depths.y), min(depths.z, depths.w)); CalculateRadiusParameters(abs(closest), 1.0, dummyUnused1, dummyUnused2, falloffCalcMulSq); diff --git a/Source/Shaders/Shadows.shader b/Source/Shaders/Shadows.shader index fd2625f60..ae4888ce4 100644 --- a/Source/Shaders/Shadows.shader +++ b/Source/Shaders/Shadows.shader @@ -44,7 +44,7 @@ float RayCastScreenSpaceShadow(GBufferData gBufferData, GBufferSample gBuffer, f float3 rayUV = rayCS.xyz / rayCS.w; rayUV.xy = rayUV.xy * float2(0.5, -0.5) + float2(0.5, 0.5); float sceneDepth = SampleDepth(gBufferData, rayUV.xy) * gBufferData.ViewFar; - float rayDepth = LinearizeZ(rayUV.z) * gBufferData.ViewFar * 0.998; + float rayDepth = LinearizeZ(gBufferData, rayUV.z) * gBufferData.ViewFar * 0.998; float surfaceThickness = 0.035f + rayDepth * rayLength; float depthTestHardness = 0.005f; float lightAmount = saturate((rayDepth - sceneDepth) / depthTestHardness) * saturate((sceneDepth + surfaceThickness - rayDepth) / depthTestHardness);