flashbit-manipulationgpubit-shiftagal

Is there a way to do bitwise-shift operations in AGAL?


If I encode all colors into one single float value (RGB) as:

//Each Channels are from 0 - 255
red << 16 | green << 8 | blue;

How can I retrieve those color channels back in AGAL? There doesn't seem to be any bitwise operators.


Solution

  • You should not need to do this. Use BYTES_4 input in a vertex stream and your packed color will be unpacked for you automatically! Textures do the same thing. Constant registers are 4 float all the time anyway. You should start to think of colors as 4 vectors with 4 values in the [0..1] range.

    That said, remember that a bit shift is just a division and truncation. x>>1 is the same as trunc(x/2.0). AGAL does not have truncation but fractional part, and trunc(x) is the same as x-frac(x) for positive x.