summaryrefslogtreecommitdiffstats
path: root/servers/rendering_server.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'servers/rendering_server.cpp')
-rw-r--r--servers/rendering_server.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp
index 6e9b525f31..e5d8800366 100644
--- a/servers/rendering_server.cpp
+++ b/servers/rendering_server.cpp
@@ -340,7 +340,7 @@ void _get_axis_angle(const Vector3 &p_normal, const Vector4 &p_tangent, float &r
if (d < 0.0) {
r_angle = CLAMP((1.0 - r_angle / Math_PI) * 0.5, 0.0, 0.49999);
} else {
- r_angle = (r_angle / Math_PI) * 0.5 + 0.5;
+ r_angle = CLAMP((r_angle / Math_PI) * 0.5 + 0.5, 0.500008, 1.0);
}
}
@@ -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),