Question

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.

Was it helpful?

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.

OTHER TIPS

Here's a described case where I found bitwise operations in AGAL useful when unpacking stuff from RGB color channels. It assumes you already know the arithmetic equivalents to bit-wise operations tho: http://forum.alternativaplatform.com/posts/list/10343.page#78542

A modulus can be done in AGAL where a%b = frc(a/b)*b . Since, for example, bitmask &1, &3 oeprations are simply modulus operations for 2 and 4 respectively (ie. &(modDivisor-1) ), you can use those. Shifting left/right is simply multiplication/division by power of 2 (2^n), where n is the number of bits shifted. Or '|' operations is simply addition, after shifting left yr digits, of course..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top