From 70b05249cb9d553132b769a574bc35a5373f6ff0 Mon Sep 17 00:00:00 2001 From: bonj Date: Tue, 11 Jul 2023 11:44:15 +0200 Subject: [PATCH] Fix #109040: Don't calculate homogenous offset if viewspace offset is 0 Users were reporting offset issues when the retopology overlay was disabled. The reason those issues were happening is because of `vs_offset = min(vs_offset, vs_z * -0.5);`. That line is necessary for proper functioning of the retopology overlay, but causes issues at lower offset values (such as zero, when the retopology overlay is disabled). Fixes #109640 Pull Request: https://projects.blender.org/blender/blender/pulls/109657 --- source/blender/draw/intern/shaders/common_view_lib.glsl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/blender/draw/intern/shaders/common_view_lib.glsl b/source/blender/draw/intern/shaders/common_view_lib.glsl index a7a81d155f2..20b09576d37 100644 --- a/source/blender/draw/intern/shaders/common_view_lib.glsl +++ b/source/blender/draw/intern/shaders/common_view_lib.glsl @@ -262,7 +262,11 @@ vec3 point_world_to_view(vec3 p) * Offset is in viewspace, so positive values are closer to the camera. */ float get_homogenous_z_offset(float vs_z, float hs_w, float vs_offset) { - if (ProjectionMatrix[3][3] == 0.0) { + if (vs_offset == 0.0) { + /* Don't calculate homogenous offset if viewspace offset is zero. */ + return 0.0; + } + else if (ProjectionMatrix[3][3] == 0.0) { /* Clamp offset to half of Z to avoid floating point precision errors. */ vs_offset = min(vs_offset, vs_z * -0.5); /* From "Projection Matrix Tricks" by Eric Lengyel: