【发布时间】:2021-11-08 06:12:22
【问题描述】:
正如标题所说,我一直在尝试使用 BitShifting 在 c# 中将 4 个完整的 0-255 字节打包成 1 个整数。我正在尝试压缩一些数据,目前使用 40 字节的数据。但实际上理论上我只需要 12 个字节,但要做到这一点,我需要将所有数据压缩成 3 个整数。
目前我的数据是:
float3 pos; // Position Relative to Object
float4 color; // RGB is Compressed into X, Y is MatID, Z and W are unused
float3 normal; // A simple Normal -1 to 1 range
但理论上我可以压缩到:
int pos; // X, Y, Z, MatID - These are never > 200 nor negative
int color; // R, G, B, Unused Fourth Byte
int normal; // X, Y, Z, [0, 255] = [-1, 1] with 128 being 0, Unused Fourth Byte Should be plenty accurate for my needs
所以我的问题是我该怎么做呢?我对 Bit Shifting 相当陌生,并且没有设法获得很多工作。
【问题讨论】:
-
我没有看到任何“位移”代码。问题是什么?
-
“我一直在尝试使用 BitShifting 在 c# 中将 4 个完整的 0-255 字节打包成 1 个整数”-> 尝试发布代码,具体问题是什么 :)
-
0000 0000 0000 0000 0000 0000 0000 0000使用此布局向我们展示您希望它如何工作 -
为什么要将浮点数转换为整数?您可能会丢失精度数据。
-
@kiner_shah 在我的情况下,我不需要非常接近浮点数的精度,我只需要 0-255 的值就可以得到几乎相同的结果。
标签: c# unity3d compression