unpackUint.glsl 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * Unpack unsigned integers of 1-4 bytes. in WebGL 1, there is no uint type,
  3. * so the return value is an int.
  4. * <p>
  5. * There are also precision limitations in WebGL 1. highp int is still limited
  6. * to 24 bits. Above the value of 2^24 = 16777216, precision loss may occur.
  7. * </p>
  8. *
  9. * @param {float|vec2|vec3|vec4} packed The packed value. For vectors, the components are listed in little-endian order.
  10. *
  11. * @return {int} The unpacked value.
  12. */
  13. int czm_unpackUint(float packedValue) {
  14. float rounded = czm_round(packedValue * 255.0);
  15. return int(rounded);
  16. }
  17. int czm_unpackUint(vec2 packedValue) {
  18. vec2 rounded = czm_round(packedValue * 255.0);
  19. return int(dot(rounded, vec2(1.0, 256.0)));
  20. }
  21. int czm_unpackUint(vec3 packedValue) {
  22. vec3 rounded = czm_round(packedValue * 255.0);
  23. return int(dot(rounded, vec3(1.0, 256.0, 65536.0)));
  24. }
  25. int czm_unpackUint(vec4 packedValue) {
  26. vec4 rounded = czm_round(packedValue * 255.0);
  27. return int(dot(rounded, vec4(1.0, 256.0, 65536.0, 16777216.0)));
  28. }