   packing floats to various formats
  I'm trying to store my normals and depth into one RGBA16f Render target.  I want to have 32 bits of precision for  my depth and use the rest for my normals.X and Y Normal values will be stored in the red channel  using the following code and i'll reconstruct Z in the shader using the cross product.//Thanks Pavel Tumik! @paveltumik for the original code in comments//pack: f1=(f1+1)*0.5; f2=(f2+1)*0.5; res=floor(f1*1000)+f2;inline float PackFloat16bit2(float2 src){return floorf((src.x+1)*0.5f * 100.0f)+((src.y+1)*0.4f);}//unpack: f2=frac(res); f1=(res-f2)/1000; f1=(f1-0.5)*2;f2=(f2-0.5)*2;inline float2 UnPackFloat16bit2(float src){float2 o;float fFrac = frac(src);o.y = (fFrac-0.4f)*2.5f;o.x = ((src-fFrac)/100.0f-0.5f)*2;return o;}Now that leaves me with the depth information which i want to store in the Green and Blue channels.  I haven't been able to find any info on packing a 32 bit float into 2 16fs in a shader.  Any help would be awesome :)   
  You could probably just use your existing functions (or something simmilar to them), but in revsere. Use "UnPackFloat16bit2" to "pack" the input float into two output floats, then use "PackFloat16bit2" to "unpack" two input floats into one output.I haven't tested this, but here's a commented version of a pack/unpack routine:float2 SplitFloatInTwo( float i ){  //tweak these until you find numbers that give good quality  const float    shift = 0.7;  const float    large =1000.0;  const float invLarge = 1.0/1000.0;  //change where the decimal point is  i *= shift;  //split at the decimal point  float fractional = fract( i );  float whole = i - fractional;  //rescale so the two new numbers both have a whole and fractional part  // i.e. spread out over the whole float-range to get good precision  fractional *= large;  whole *= invLarge;  return float2( whole, fractional );}float ReassembleFloatFromTwo( float2 i ){  //Same numbers from SplitFloatInTwo  const float invShift = 1.0/0.7;  const float    large =1000.0;  const float invLarge = 1.0/1000.0;  float whole = i.x;  float fractional = i.y;  //undo the re-scaling  fractional *= invLarge;  whole *= large;  //whole should be an integer now. fractional should be less than 1.0.  //Add to reassemble them.  float output = whole + fractional;  //change the decimal point back to the right place  output *= invShift;  return output;};Quote:Original post by sgsrulesI'm trying to store my normals and depth into one RGBA16f Render target.  I want to have 32 bits of precision for  my depth and use the rest for my normals.I do the same in my renderer. With the assumption, that a 16 bit float has a mantissa of 10 bits and that you want to store a depth value of 0..1 you can use the following unpack/pack methods(GLSL):// pack depth into 16bit x,y componentpackDepth( out vec4 _target, in float depth){  // 10 bits = 1024  float tmp_depth = depth*1000;  // store hi-lo value, restrict to 10 bit mantissa  _target.x = floor(tmp_depth);   _target.y = fract(tmp_depth);}float unpackDepth( in vec4 _source){  return (target.x+target.y)/1000;}