Fix signed integers normalisation.

This commit is contained in:
Roz K 2023-01-04 15:24:18 +01:00
parent 59d13684be
commit f463db316f
Signed by: roz
GPG Key ID: 51FBF4E483E1C822
1 changed files with 9 additions and 3 deletions

View File

@ -421,6 +421,12 @@ static void rk_buckets_alloc(
}
}
#define rk_pack_short_norm(_f) (static_cast<rk_int>((_f) * 32767.f) & 65536)
// #define rk_pack_short_norm(_f) (((static_cast<rk_int>((_f) * 32767.f) - 1) / 2) & 65535)
#define rk_pack_int10_norm(_f) (static_cast<rk_int>((_f) * 511.f) & 1023)
// #define rk_pack_int10_norm(_f) (((static_cast<rk_int>((_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<rk_vec3_short *>(_dst);
rk_vec3_float const * const __restrict src = reinterpret_cast<rk_vec3_float const *>(_src);
#define _convert(s) (static_cast<rk_short>((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<rk_vec3_int10 *>(_dst);
rk_vec3_float const * const __restrict src = reinterpret_cast<rk_vec3_float const *>(_src);
#define _convert(s) (static_cast<rk_int>((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<rk_mat3_int10 *>(_dst);
rk_mat3_float const * const __restrict src = reinterpret_cast<rk_mat3_float const *>(_src);
#define _convert(s) (static_cast<rk_int>((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);