summaryrefslogtreecommitdiffstats
path: root/servers/rendering_server.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-02-27 10:17:43 +0100
committerRémi Verschelde <rverschelde@gmail.com>2024-02-27 10:17:43 +0100
commit8f98ed65f7d4c1da6256213769fc74ee8c836766 (patch)
tree8268cd95e56ca835429f92a8e30dd90a03f6c3d4 /servers/rendering_server.cpp
parentb21328d465df6548a8a8be23486c86469ce7ac43 (diff)
parent781cd27fe432349c36c5363be4f879b1c3c48c10 (diff)
downloadredot-engine-8f98ed65f7d4c1da6256213769fc74ee8c836766.tar.gz
Merge pull request #88738 from clayjohn/mesh_compression-tangents
Multiple fixes for compressed meshes
Diffstat (limited to 'servers/rendering_server.cpp')
-rw-r--r--servers/rendering_server.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp
index d1c3aaf6f7..e5d8800366 100644
--- a/servers/rendering_server.cpp
+++ b/servers/rendering_server.cpp
@@ -566,7 +566,8 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint64_t p_format, uint
float angle;
Vector3 axis;
// Generate an arbitrary vector that is tangential to normal.
- Vector3 tan = Vector3(0.0, 1.0, 0.0).cross(normal_src[i].normalized());
+ // This assumes that the normal is never (0,0,0).
+ Vector3 tan = Vector3(normal_src[i].z, -normal_src[i].x, normal_src[i].y).cross(normal_src[i].normalized()).normalized();
Vector4 tangent = Vector4(tan.x, tan.y, tan.z, 1.0);
_get_axis_angle(normal_src[i], tangent, angle, axis);
@@ -689,7 +690,8 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint64_t p_format, uint
// Set data for tangent.
for (int i = 0; i < p_vertex_array_len; i++) {
// Generate an arbitrary vector that is tangential to normal.
- Vector3 tan = Vector3(0.0, 1.0, 0.0).cross(normal_src[i].normalized());
+ // This assumes that the normal is never (0,0,0).
+ Vector3 tan = Vector3(normal_src[i].z, -normal_src[i].x, normal_src[i].y).cross(normal_src[i].normalized()).normalized();
Vector2 res = tan.octahedron_tangent_encode(1.0);
uint16_t vector[2] = {
(uint16_t)CLAMP(res.x * 65535, 0, 65535),