From 8ac85e6a9ebc69c631983a74d1d4f9c26cfa12ad Mon Sep 17 00:00:00 2001 From: clayjohn Date: Mon, 16 Aug 2021 22:17:38 -0700 Subject: [PATCH] Normalize the results of octahedral decompression --- drivers/gles2/shaders/scene.glsl | 2 +- drivers/gles3/shaders/scene.glsl | 2 +- servers/visual_server.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gles2/shaders/scene.glsl b/drivers/gles2/shaders/scene.glsl index 4247d0eafb7..9d7a9aa16bb 100644 --- a/drivers/gles2/shaders/scene.glsl +++ b/drivers/gles2/shaders/scene.glsl @@ -115,7 +115,7 @@ vec3 oct_to_vec3(vec2 e) { vec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y)); float t = max(-v.z, 0.0); v.xy += t * -sign(v.xy); - return v; + return normalize(v); } #endif diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index a59e0adadec..373f1dabc78 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -264,7 +264,7 @@ vec3 oct_to_vec3(vec2 e) { vec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y)); float t = max(-v.z, 0.0); v.xy += t * -sign(v.xy); - return v; + return normalize(v); } #endif diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index 7f7a48825d6..90ea3025e7d 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -376,7 +376,7 @@ Vector3 VisualServer::oct_to_norm(const Vector2 v) { float t = MAX(-res.z, 0.0f); res.x += t * -SGN(res.x); res.y += t * -SGN(res.y); - return res; + return res.normalized(); } // Convert Octohedron-mapped normalized tangent vector back to Cartesian