#If you want to encode data in less than
1 messages · Page 1 of 1 (latest)
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
?
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
first is the shader supports bitwise operation?
then bitshift and bitmask
something like this?
yes
ah but indeed they dont support it
is the shader supports division and integer modulo?...
you can replace <<n and >>n to *2^n and /2^n
and &(2^n)-1 to %2^n
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
doesnt matter, as long as there is space for storing them
yeah so by that I mean, X should only have 1 byte and Y 3 bytes
then you need to change the mask value
oh, how should it be?
aa h! perfect, then it is working with bitwise operations
ah no weird, it works well on editor but not in game?
i just realize modulo and bitwise work differently in negative value, you need unsigned type
yup they are all uint
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