packDepth.glsl 565 B

123456789101112131415161718
  1. /**
  2. * Packs a depth value into a vec3 that can be represented by unsigned bytes.
  3. *
  4. * @name czm_packDepth
  5. * @glslFunction
  6. *
  7. * @param {float} depth The floating-point depth.
  8. * @returns {vec3} The packed depth.
  9. */
  10. vec4 czm_packDepth(float depth)
  11. {
  12. // See Aras Pranckevičius' post Encoding Floats to RGBA
  13. // http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  14. vec4 enc = vec4(1.0, 255.0, 65025.0, 16581375.0) * depth;
  15. enc = fract(enc);
  16. enc -= enc.yzww * vec4(1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0, 0.0);
  17. return enc;
  18. }