diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-06-17 13:03:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-17 13:03:48 +0200 |
commit | 569a2b5bd7ad8e2851f4b99147f4463454daffad (patch) | |
tree | 72fcabfb7943ac66015bc882fd4deafded5798b1 | |
parent | 3a2e9fdf88964db2d42e84a46d6d09efe75f654f (diff) | |
parent | ff0ac9d916b7d2145a3bb000b3cf2be38c3937bc (diff) |
Merge pull request #9230 from supagu/normals-fix
Fixed decompression of normals
-rw-r--r-- | servers/visual_server.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index caaef46d24..6c57275b3a 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -463,7 +463,7 @@ Error VisualServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint32_ for (int i = 0; i < p_vertex_array_len; i++) { - uint8_t vector[4] = { + int8_t vector[4] = { CLAMP(src[i].x * 127, -128, 127), CLAMP(src[i].y * 127, -128, 127), CLAMP(src[i].z * 127, -128, 127), @@ -1231,11 +1231,12 @@ Array VisualServer::_get_array_from_surface(uint32_t p_format, PoolVector<uint8_ if (p_format & ARRAY_COMPRESS_NORMAL) { PoolVector<Vector3>::Write w = arr.write(); + const float multiplier = 1.f / 127.f; for (int j = 0; j < p_vertex_len; j++) { - const uint8_t *v = (const uint8_t *)&r[j * total_elem_size + offsets[i]]; - w[j] = Vector3(float(v[0] / 255.0) * 2.0 - 1.0, float(v[1] / 255.0) * 2.0 - 1.0, float(v[2] / 255.0) * 2.0 - 1.0); + const int8_t *v = (const int8_t *)&r[j * total_elem_size + offsets[i]]; + w[j] = Vector3(float(v[0]) * multiplier, float(v[1]) * multiplier, float(v[2]) * multiplier); } } else { PoolVector<Vector3>::Write w = arr.write(); @@ -1291,7 +1292,7 @@ Array VisualServer::_get_array_from_surface(uint32_t p_format, PoolVector<uint8_ for (int j = 0; j < p_vertex_len; j++) { const uint8_t *v = (const uint8_t *)&r[j * total_elem_size + offsets[i]]; - w[j] = Color(float(v[0] / 255.0) * 2.0 - 1.0, float(v[1] / 255.0) * 2.0 - 1.0, float(v[2] / 255.0) * 2.0 - 1.0, float(v[3] / 255.0) * 2.0 - 1.0); + w[j] = Color(float(v[0] / 255.0), float(v[1] / 255.0), float(v[2] / 255.0), float(v[3] / 255.0)); } } else { PoolVector<Color>::Write w = arr.write(); |