octDecode.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default " /**\n\
  3. * Decodes a unit-length vector in 'oct' encoding to a normalized 3-component Cartesian vector.\n\
  4. * The 'oct' encoding is described in \"A Survey of Efficient Representations of Independent Unit Vectors\",\n\
  5. * Cigolle et al 2014: http://jcgt.org/published/0003/02/01/\n\
  6. *\n\
  7. * @name czm_octDecode\n\
  8. * @param {vec2} encoded The oct-encoded, unit-length vector\n\
  9. * @param {float} range The maximum value of the SNORM range. The encoded vector is stored in log2(rangeMax+1) bits.\n\
  10. * @returns {vec3} The decoded and normalized vector\n\
  11. */\n\
  12. vec3 czm_octDecode(vec2 encoded, float range)\n\
  13. {\n\
  14. if (encoded.x == 0.0 && encoded.y == 0.0) {\n\
  15. return vec3(0.0, 0.0, 0.0);\n\
  16. }\n\
  17. \n\
  18. encoded = encoded / range * 2.0 - 1.0;\n\
  19. vec3 v = vec3(encoded.x, encoded.y, 1.0 - abs(encoded.x) - abs(encoded.y));\n\
  20. if (v.z < 0.0)\n\
  21. {\n\
  22. v.xy = (1.0 - abs(v.yx)) * czm_signNotZero(v.xy);\n\
  23. }\n\
  24. \n\
  25. return normalize(v);\n\
  26. }\n\
  27. \n\
  28. /**\n\
  29. * Decodes a unit-length vector in 'oct' encoding to a normalized 3-component Cartesian vector.\n\
  30. * The 'oct' encoding is described in \"A Survey of Efficient Representations of Independent Unit Vectors\",\n\
  31. * Cigolle et al 2014: http://jcgt.org/published/0003/02/01/\n\
  32. *\n\
  33. * @name czm_octDecode\n\
  34. * @param {vec2} encoded The oct-encoded, unit-length vector\n\
  35. * @returns {vec3} The decoded and normalized vector\n\
  36. */\n\
  37. vec3 czm_octDecode(vec2 encoded)\n\
  38. {\n\
  39. return czm_octDecode(encoded, 255.0);\n\
  40. }\n\
  41. \n\
  42. /**\n\
  43. * Decodes a unit-length vector in 'oct' encoding packed into a floating-point number to a normalized 3-component Cartesian vector.\n\
  44. * The 'oct' encoding is described in \"A Survey of Efficient Representations of Independent Unit Vectors\",\n\
  45. * Cigolle et al 2014: http://jcgt.org/published/0003/02/01/\n\
  46. *\n\
  47. * @name czm_octDecode\n\
  48. * @param {float} encoded The oct-encoded, unit-length vector\n\
  49. * @returns {vec3} The decoded and normalized vector\n\
  50. */\n\
  51. vec3 czm_octDecode(float encoded)\n\
  52. {\n\
  53. float temp = encoded / 256.0;\n\
  54. float x = floor(temp);\n\
  55. float y = (temp - x) * 256.0;\n\
  56. return czm_octDecode(vec2(x, y));\n\
  57. }\n\
  58. \n\
  59. /**\n\
  60. * Decodes three unit-length vectors in 'oct' encoding packed into two floating-point numbers to normalized 3-component Cartesian vectors.\n\
  61. * The 'oct' encoding is described in \"A Survey of Efficient Representations of Independent Unit Vectors\",\n\
  62. * Cigolle et al 2014: http://jcgt.org/published/0003/02/01/\n\
  63. *\n\
  64. * @name czm_octDecode\n\
  65. * @param {vec2} encoded The packed oct-encoded, unit-length vectors.\n\
  66. * @param {vec3} vector1 One decoded and normalized vector.\n\
  67. * @param {vec3} vector2 One decoded and normalized vector.\n\
  68. * @param {vec3} vector3 One decoded and normalized vector.\n\
  69. */\n\
  70. void czm_octDecode(vec2 encoded, out vec3 vector1, out vec3 vector2, out vec3 vector3)\n\
  71. {\n\
  72. float temp = encoded.x / 65536.0;\n\
  73. float x = floor(temp);\n\
  74. float encodedFloat1 = (temp - x) * 65536.0;\n\
  75. \n\
  76. temp = encoded.y / 65536.0;\n\
  77. float y = floor(temp);\n\
  78. float encodedFloat2 = (temp - y) * 65536.0;\n\
  79. \n\
  80. vector1 = czm_octDecode(encodedFloat1);\n\
  81. vector2 = czm_octDecode(encodedFloat2);\n\
  82. vector3 = czm_octDecode(vec2(x, y));\n\
  83. }\n\
  84. \n\
  85. ";