From 494a639782ac5b08ecc9b4101f34b6d72ecaf11f Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 22 Jun 2026 13:52:08 +0200 Subject: [PATCH] Fix Debug Draw shapes manual depth test when using resolution upscaling --- Source/Engine/Debug/DebugDraw.cpp | 5 ++++- Source/Shaders/DebugDraw.shader | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index 18552dcec..a4febc613 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -136,7 +136,7 @@ typedef DebugDraw::Vertex Vertex; GPU_CB_STRUCT(ShaderData { Matrix ViewProjection; - Float2 Padding; + Float2 SceneDepthUVScale; float ClipPosZBias; uint32 EnableDepthTest; }); @@ -861,6 +861,9 @@ void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTe Matrix::Multiply(view.View, view.Projection, vp); Matrix::Transpose(vp, data.ViewProjection); data.ClipPosZBias = view.IsPerspectiveProjection() ? -0.2f : 0.0f; // Reduce Z-fighting artifacts (eg. editor grid) + data.SceneDepthUVScale = Float2::One; + if (enableDepthTest && renderContext.Buffers->DepthBuffer && target && ScriptingObject::Cast(target->GetParent())) + data.SceneDepthUVScale = renderContext.Buffers->DepthBuffer->Size() / ((GPUTexture*)target->GetParent())->Size(); data.EnableDepthTest = enableDepthTest; context->UpdateCB(cb, &data); context->BindCB(0, cb); diff --git a/Source/Shaders/DebugDraw.shader b/Source/Shaders/DebugDraw.shader index 62576dd17..5994a111c 100644 --- a/Source/Shaders/DebugDraw.shader +++ b/Source/Shaders/DebugDraw.shader @@ -4,7 +4,7 @@ META_CB_BEGIN(0, Data) float4x4 ViewProjection; -float2 Padding; +float2 SceneDepthUVScale; float ClipPosZBias; bool EnableDepthTest; META_CB_END @@ -39,7 +39,7 @@ float4 PS(VS2PS input) : SV_Target FLATTEN if (EnableDepthTest) { - float sceneDepthDeviceZ = SceneDepthTexture.Load(int3(input.Position.xy, 0)).r; + float sceneDepthDeviceZ = SceneDepthTexture.Load(int3(input.Position.xy * SceneDepthUVScale, 0)).r; float interpolatedDeviceZ = input.Position.z; clip(DEPTH_DIFF(sceneDepthDeviceZ, interpolatedDeviceZ)); }