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
This commit is contained in:
bonj
2023-07-11 11:44:15 +02:00
committed by Clément Foucault
parent 40f89d23cb
commit 70b05249cb

View File

@@ -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: