packingFunctions.fx 460 B

12345678910111213141516
  1. vec4 pack(float depth)
  2. {
  3. const vec4 bit_shift = vec4(255.0 * 255.0 * 255.0, 255.0 * 255.0, 255.0, 1.0);
  4. const vec4 bit_mask = vec4(0.0, 1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0);
  5. vec4 res = fract(depth * bit_shift);
  6. res -= res.xxyz * bit_mask;
  7. return res;
  8. }
  9. float unpack(vec4 color)
  10. {
  11. const vec4 bit_shift = vec4(1.0 / (255.0 * 255.0 * 255.0), 1.0 / (255.0 * 255.0), 1.0 / 255.0, 1.0);
  12. return dot(color, bit_shift);
  13. }