From e0f736ec1028f63159f4ff71cf4cb119416e7b45 Mon Sep 17 00:00:00 2001 From: clayjohn Date: Tue, 9 Jul 2024 15:29:45 -0700 Subject: [PATCH] Properly linearize depth buffer for SSAO when using orthogonal camera --- .../renderer_rd/shaders/effects/ss_effects_downsample.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/servers/rendering/renderer_rd/shaders/effects/ss_effects_downsample.glsl b/servers/rendering/renderer_rd/shaders/effects/ss_effects_downsample.glsl index 4f81e36c58d..0332e239938 100644 --- a/servers/rendering/renderer_rd/shaders/effects/ss_effects_downsample.glsl +++ b/servers/rendering/renderer_rd/shaders/effects/ss_effects_downsample.glsl @@ -50,7 +50,7 @@ layout(r16f, set = 2, binding = 3) uniform restrict writeonly image2DArray dest_ vec4 screen_space_to_view_space_depth(vec4 p_depth) { if (params.orthogonal) { vec4 depth = p_depth * 2.0 - 1.0; - return ((depth + (params.z_far + params.z_near) / (params.z_far - params.z_near)) * (params.z_far - params.z_near)) / 2.0; + return -(depth * (params.z_far - params.z_near) - (params.z_far + params.z_near)) / 2.0; } float depth_linearize_mul = params.z_near; @@ -68,7 +68,7 @@ vec4 screen_space_to_view_space_depth(vec4 p_depth) { float screen_space_to_view_space_depth(float p_depth) { if (params.orthogonal) { float depth = p_depth * 2.0 - 1.0; - return ((depth + (params.z_far + params.z_near) / (params.z_far - params.z_near)) * (params.z_far - params.z_near)) / (2.0 * params.z_far); + return -(depth * (params.z_far - params.z_near) - (params.z_far + params.z_near)) / 2.0; } float depth_linearize_mul = params.z_near;