compression - GLSL - compressing/packing multiple 0-1 colours (var4) into a single var4 variable -
i trying following in glsl 2 es:
given number (say 4 example) of normalized var4 variables(rgba) reduce bit depth , pack results in single 0-1 clamped var4. stored 8 bit (per channel) texture , later unpacked. i realize result in quality loss acceptable.
so in example:
rgba 8 bit -> reduced rgba 2 bit -> packed 3 other rgba 2 bit var4s -> saved single 8 bit rgba texture -> unpacked 4 x rgba 2 bit variables -> scaled reduced quality version of original.
i realize can't bit-shifting in glsl have collection of multiplications, magic combination of has far escaped me! others have talked packing floats in vec4s problem little different.
thanks!
well, bit shifting can represented mulitplication (for left shifts) or division (for right shifts) powers of two. have take account floats stroe fractional parts shifted "out" in normal integer bitshifts.
so pack 4 normalized floats a,b,c,d normalized float x, can use
x = 1.0/255.0 * (floor(a*255.0/64.0)*64.0 + floor(b*255.0/64.0)*16.0 + floor(c*255.0/64.0)*4.0 + floor(d*255.0/64.0)); unpacking bit more complicated because can't mask out single bits. instead, can subtract significant bits reconstruct them, example this:
a = floor(x*255.0/64.0)*64.0/255.0; x -= a; b = floor(x*255.0/16.0)*16.0/255.0; x -= b; b *= 4.0; c = floor(x*255.0/4.0)*4.0/255.0; x -= c; c *= 16.0; d = x*255.0 * 64.0 / 255.0; // scan simplified x*64.0
Comments
Post a Comment