From f463db316fc9eae9f26a83605d1c05f662b6e7de Mon Sep 17 00:00:00 2001 From: Roz K Date: Wed, 4 Jan 2023 15:24:18 +0100 Subject: [PATCH] Fix signed integers normalisation. --- cpp/render/render_opengles.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cpp/render/render_opengles.cpp b/cpp/render/render_opengles.cpp index 39c87c3..a31fc23 100644 --- a/cpp/render/render_opengles.cpp +++ b/cpp/render/render_opengles.cpp @@ -421,6 +421,12 @@ static void rk_buckets_alloc( } } +#define rk_pack_short_norm(_f) (static_cast((_f) * 32767.f) & 65536) +// #define rk_pack_short_norm(_f) (((static_cast((_f) * 32767.f) - 1) / 2) & 65535) + +#define rk_pack_int10_norm(_f) (static_cast((_f) * 511.f) & 1023) +// #define rk_pack_int10_norm(_f) (((static_cast((_f) * 1023.f) - 1) / 2) & 1023) + static void rk_pack_vec3_float( unsigned const count, rk_instance_index const * const __restrict indices, @@ -459,7 +465,7 @@ static void rk_pack_vec3_short_norm( rk_instance_index const * const last_index = indices + count; rk_vec3_short * __restrict dst = reinterpret_cast(_dst); rk_vec3_float const * const __restrict src = reinterpret_cast(_src); - #define _convert(s) (static_cast((s) * ((s) < 0.f ? 32768.f : 32767.f))) + #define _convert(s) rk_pack_short_norm(s) for (rk_instance_index const * __restrict index = indices; index < last_index; ++index, ++dst) { rk_vec3_float const & input = src[*index]; dst->x = _convert(input.x); @@ -494,7 +500,7 @@ static void rk_pack_vec3_int10_norm( rk_instance_index const * const last_index = indices + count; rk_vec3_int10 * __restrict dst = reinterpret_cast(_dst); rk_vec3_float const * const __restrict src = reinterpret_cast(_src); - #define _convert(s) (static_cast((s) * ((s) < 0.f ? 512.f : 511.f)) & 1023) + #define _convert(s) rk_pack_int10_norm(s) for (rk_instance_index const * __restrict index = indices; index < last_index; ++index, ++dst) { rk_vec3_float const & input = src[*index]; *dst = _convert(input.x) | (_convert(input.y) << 10) | (_convert(input.z) << 20); @@ -542,7 +548,7 @@ static void rk_pack_mat3_int10_norm( rk_instance_index const * const last_index = indices + count; rk_mat3_int10 * __restrict dst = reinterpret_cast(_dst); rk_mat3_float const * const __restrict src = reinterpret_cast(_src); - #define _convert(s) (static_cast((s) * ((s) < 0.f ? 512.f : 511.f)) & 1023) + #define _convert(s) rk_pack_int10_norm(s) for (rk_instance_index const * __restrict index = indices; index < last_index; ++index, ++dst) { rk_mat3_float const & input = src[*index]; dst->x = _convert(input.x.x) | (_convert(input.x.y) << 10) | (_convert(input.x.z) << 20);