I know this is an old question, but I had the same problem and I will post a solution if someone needs it in the future.
float packColor(vec3 color) { return color.r + color.g * 256.0 + color.b * 256.0 * 256.0; } vec3 unpackColor(float f) { vec3 color; color.b = floor(f / 256.0 / 256.0); color.g = floor((f - color.b * 256.0 * 256.0) / 256.0); color.r = floor(f - color.b * 256.0 * 256.0 - color.g * 256.0);
As long as the float packaged by packColor is not in the range [0, 1], but in the range [0, 16777215], you should not have any problems with accuracy. But if you normalize the float in the range [0,1], you will have problems with accuracy!
Note that you also cannot store alpha (this way), since highp float is 24 bits long and not 32 bits as commonly used. In the vertex shader, you can use this code without problems (the default accuracy is highp), but in the fragment shader you have to be sure that you use only high precision!
source share