#If you want to encode data in less than

1 messages · Page 1 of 1 (latest)

grand sleet
#

Hi! Could you help me out on the packing and unpacking?

#

I have a byte value let's say X, that goes form 0 to 255 and want to put it somwhere in the int to do what you said,let's call it Y

#

But I dont understand verywell how the packing and unpacking works

#

should I do like

packedValue = (Y << 8) | X

and then

Y = (packedValue >> 8) & 0xFFFF
X = packedValue & 0xFFFF

?

iron heath
#

you could do

byte[] bytes = Bitconveter.GetBytes(Y);
bytes[0] = X;

To Pack and

byte[] packed;
X = packed[0];
packed[0] = 0;
Y = BitConverter.ToInt32(packed);

To Unpack

grand sleet
#

Im on the GPU btw

#

needs to happen in a compute shader

mellow parrot
#

first is the shader supports bitwise operation?
then bitshift and bitmask

grand sleet
mellow parrot
#

yes

grand sleet
#

ah but indeed they dont support it

mellow parrot
#

is the shader supports division and integer modulo?...

grand sleet
#

it should

#

yeah

mellow parrot
#

you can replace <<n and >>n to *2^n and /2^n
and &(2^n)-1 to %2^n

grand sleet
#

but wait, maybe im doing this wrong

#
packedValue = (Y << 8) | X

and then

Y = (packedValue >> 8) & 0xFFFF
X = packedValue & 0xFFFF

here Y is the bigger value, and X the smaller one

mellow parrot
#

doesnt matter, as long as there is space for storing them

grand sleet
#

yeah so by that I mean, X should only have 1 byte and Y 3 bytes

mellow parrot
#

then you need to change the mask value

grand sleet
#

oh, how should it be?

mellow parrot
#

value&0xFFFFFF for y and 0xFF for x

#

0xFFFFFF is 24 bits=3bytes

grand sleet
#

aa h! perfect, then it is working with bitwise operations

#

ah no weird, it works well on editor but not in game?

mellow parrot
#

i just realize modulo and bitwise work differently in negative value, you need unsigned type

grand sleet
#

yup they are all uint

rough sedge
#

I dont know if this has been mentioned already but we use a system where we store the index to a texture array in the uv of the mesh, making a float3 rather than a float2. This ofc adds 4 bytes per mesh