From c022f52f11e2df5ab051f3ad201efb33b2fe2ade Mon Sep 17 00:00:00 2001 From: nklbdev Date: Fri, 30 Jun 2023 17:17:37 +0500 Subject: [PATCH 1/2] Fix wrong type casting for octahedral tangents --- servers/rendering_server.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index 0c5c263265c2..4c6b76515731 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -402,9 +402,9 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint const Vector3 *src = array.ptr(); for (int i = 0; i < p_vertex_array_len; i++) { Vector2 res = src[i].octahedron_encode(); - int16_t vector[2] = { - (int16_t)CLAMP(res.x * 65535, 0, 65535), - (int16_t)CLAMP(res.y * 65535, 0, 65535), + uint16_t vector[2] = { + (uint16_t)CLAMP(res.x * 65535, 0, 65535), + (uint16_t)CLAMP(res.y * 65535, 0, 65535), }; memcpy(&vw[p_offsets[ai] + i * p_vertex_stride], vector, 4); @@ -422,9 +422,9 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint for (int i = 0; i < p_vertex_array_len; i++) { const Vector3 src(src_ptr[i * 4 + 0], src_ptr[i * 4 + 1], src_ptr[i * 4 + 2]); Vector2 res = src.octahedron_tangent_encode(src_ptr[i * 4 + 3]); - int16_t vector[2] = { - (int16_t)CLAMP(res.x * 65535, 0, 65535), - (int16_t)CLAMP(res.y * 65535, 0, 65535), + uint16_t vector[2] = { + (uint16_t)CLAMP(res.x * 65535, 0, 65535), + (uint16_t)CLAMP(res.y * 65535, 0, 65535), }; memcpy(&vw[p_offsets[ai] + i * p_vertex_stride], vector, 4); @@ -437,9 +437,9 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint for (int i = 0; i < p_vertex_array_len; i++) { const Vector3 src(src_ptr[i * 4 + 0], src_ptr[i * 4 + 1], src_ptr[i * 4 + 2]); Vector2 res = src.octahedron_tangent_encode(src_ptr[i * 4 + 3]); - int16_t vector[2] = { - (int16_t)CLAMP(res.x * 65535, 0, 65535), - (int16_t)CLAMP(res.y * 65535, 0, 65535), + uint16_t vector[2] = { + (uint16_t)CLAMP(res.x * 65535, 0, 65535), + (uint16_t)CLAMP(res.y * 65535, 0, 65535), }; memcpy(&vw[p_offsets[ai] + i * p_vertex_stride], vector, 4); From 1d16704faf220bf9535c380450348dccf0fb2ca7 Mon Sep 17 00:00:00 2001 From: nklbdev Date: Sat, 1 Jul 2023 18:46:52 +0500 Subject: [PATCH 2/2] Potencially fix nan's on octahedral tangents in RenderingServer --- scene/3d/sprite_3d.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index 9f7ff05924ab..6e44696fe4d9 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -647,11 +647,11 @@ SpriteBase3D::SpriteBase3D() { // Create basic mesh and store format information. for (int i = 0; i < 4; i++) { - mesh_normals.write[i] = Vector3(0.0, 0.0, 0.0); - mesh_tangents.write[i * 4 + 0] = 0.0; + mesh_normals.write[i] = Vector3(0.0, 0.0, 1.0); + mesh_tangents.write[i * 4 + 0] = 1.0; mesh_tangents.write[i * 4 + 1] = 0.0; mesh_tangents.write[i * 4 + 2] = 0.0; - mesh_tangents.write[i * 4 + 3] = 0.0; + mesh_tangents.write[i * 4 + 3] = 1.0; mesh_colors.write[i] = Color(1.0, 1.0, 1.0, 1.0); mesh_uvs.write[i] = Vector2(0.0, 0.0); mesh_vertices.write[i] = Vector3(0.0, 0.0, 0.0);