Skip to content

Commit

Permalink
Merge pull request godotengine#65804 from clayjohn/octahedral-decode
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga committed Sep 14, 2022
2 parents 3f0692f + ef4f968 commit f11745d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions servers/rendering_server.cpp
Expand Up @@ -1114,7 +1114,8 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, Vector<uint8_t

for (int j = 0; j < p_vertex_len; j++) {
const uint32_t v = *(const uint32_t *)&r[j * vertex_elem_size + offsets[i]];
w[j] = Vector3((v & 0x3FF) / 1023.0, ((v >> 10) & 0x3FF) / 1023.0, ((v >> 20) & 0x3FF) / 1023.0) * Vector3(2, 2, 2) - Vector3(1, 1, 1);

w[j] = Vector3::octahedron_decode(Vector2((v & 0xFFFF) / 65535.0, ((v >> 16) & 0xFFFF) / 65535.0));
}

ret[i] = arr;
Expand All @@ -1129,11 +1130,12 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, Vector<uint8_t

for (int j = 0; j < p_vertex_len; j++) {
const uint32_t v = *(const uint32_t *)&r[j * vertex_elem_size + offsets[i]];

w[j * 4 + 0] = ((v & 0x3FF) / 1023.0) * 2.0 - 1.0;
w[j * 4 + 1] = (((v >> 10) & 0x3FF) / 1023.0) * 2.0 - 1.0;
w[j * 4 + 2] = (((v >> 20) & 0x3FF) / 1023.0) * 2.0 - 1.0;
w[j * 4 + 3] = ((v >> 30) / 3.0) * 2.0 - 1.0;
float tangent_sign;
Vector3 res = Vector3::octahedron_tangent_decode(Vector2((v & 0xFFFF) / 65535.0, ((v >> 16) & 0xFFFF) / 65535.0), &tangent_sign);
w[j * 4 + 0] = res.x;
w[j * 4 + 1] = res.y;
w[j * 4 + 2] = res.z;
w[j * 4 + 3] = tangent_sign;
}

ret[i] = arr;
Expand Down

0 comments on commit f11745d

Please sign in to comment.