packing a float into a A8R8G8B8 texture (shader)
encode (fDist is the normalized distance):
decode (vec is the rgba encoded value):
const float4 bitSh = float4( 256*256*256, 256*256, 256, 1);
const float4 bitMsk = float4( 0, 1.0/256.0, 1.0/256.0, 1.0/256.0);
float4 comp;
comp = fDist * bitSh;
comp = frac(comp);
comp -= comp.xxyz * bitMsk;
return comp;
decode (vec is the rgba encoded value):
const float4 bitShifts = float4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1);
return dot(vec.xyzw , bitShifts);

浙公网安备 33010602011771号