Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sanitizers reports about octahedral tangents in RenderingServer #78902

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions scene/3d/sprite_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions servers/rendering_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down