summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-08-22 19:29:21 +0200
committerGitHub <noreply@github.com>2022-08-22 19:29:21 +0200
commit7b4927bb5ff8440a33043cf32c1163e2fe0830d1 (patch)
tree17425564f02d69fa536a413fa51077fc16837ff2 /core/math
parentacd8fb7bf01973fe0981012ff6707fbaafdf6c77 (diff)
parent61522d849149fe439f4435ec901689c809fea860 (diff)
Merge pull request #60309 from The-O-King/oct
Diffstat (limited to 'core/math')
-rw-r--r--core/math/vector3.cpp16
-rw-r--r--core/math/vector3.h2
2 files changed, 18 insertions, 0 deletions
diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp
index d71d365053..fdbbb8cb5c 100644
--- a/core/math/vector3.cpp
+++ b/core/math/vector3.cpp
@@ -117,6 +117,22 @@ Vector3 Vector3::octahedron_decode(const Vector2 &p_oct) {
return n.normalized();
}
+Vector2 Vector3::octahedron_tangent_encode(const float sign) const {
+ Vector2 res = this->octahedron_encode();
+ res.y = res.y * 0.5f + 0.5f;
+ res.y = sign >= 0.0f ? res.y : 1 - res.y;
+ return res;
+}
+
+Vector3 Vector3::octahedron_tangent_decode(const Vector2 &p_oct, float *sign) {
+ Vector2 oct_compressed = p_oct;
+ oct_compressed.y = oct_compressed.y * 2 - 1;
+ *sign = oct_compressed.y >= 0.0f ? 1.0f : -1.0f;
+ oct_compressed.y = Math::abs(oct_compressed.y);
+ Vector3 res = Vector3::octahedron_decode(oct_compressed);
+ return res;
+}
+
Basis Vector3::outer(const Vector3 &p_with) const {
Vector3 row0(x * p_with.x, x * p_with.y, x * p_with.z);
Vector3 row1(y * p_with.x, y * p_with.y, y * p_with.z);
diff --git a/core/math/vector3.h b/core/math/vector3.h
index eb654008b2..7cae6e2481 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -112,6 +112,8 @@ struct _NO_DISCARD_ Vector3 {
Vector2 octahedron_encode() const;
static Vector3 octahedron_decode(const Vector2 &p_oct);
+ Vector2 octahedron_tangent_encode(const float sign) const;
+ static Vector3 octahedron_tangent_decode(const Vector2 &p_oct, float *sign);
_FORCE_INLINE_ Vector3 cross(const Vector3 &p_with) const;
_FORCE_INLINE_ real_t dot(const Vector3 &p_with) const;