branchFreeTernary.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "/**\n\
  3. * Branchless ternary operator to be used when it's inexpensive to explicitly\n\
  4. * evaluate both possibilities for a float expression.\n\
  5. *\n\
  6. * @name czm_branchFreeTernary\n\
  7. * @glslFunction\n\
  8. *\n\
  9. * @param {bool} comparison A comparison statement\n\
  10. * @param {float} a Value to return if the comparison is true.\n\
  11. * @param {float} b Value to return if the comparison is false.\n\
  12. *\n\
  13. * @returns {float} equivalent of comparison ? a : b\n\
  14. */\n\
  15. float czm_branchFreeTernary(bool comparison, float a, float b) {\n\
  16. float useA = float(comparison);\n\
  17. return a * useA + b * (1.0 - useA);\n\
  18. }\n\
  19. \n\
  20. /**\n\
  21. * Branchless ternary operator to be used when it's inexpensive to explicitly\n\
  22. * evaluate both possibilities for a vec2 expression.\n\
  23. *\n\
  24. * @name czm_branchFreeTernary\n\
  25. * @glslFunction\n\
  26. *\n\
  27. * @param {bool} comparison A comparison statement\n\
  28. * @param {vec2} a Value to return if the comparison is true.\n\
  29. * @param {vec2} b Value to return if the comparison is false.\n\
  30. *\n\
  31. * @returns {vec2} equivalent of comparison ? a : b\n\
  32. */\n\
  33. vec2 czm_branchFreeTernary(bool comparison, vec2 a, vec2 b) {\n\
  34. float useA = float(comparison);\n\
  35. return a * useA + b * (1.0 - useA);\n\
  36. }\n\
  37. \n\
  38. /**\n\
  39. * Branchless ternary operator to be used when it's inexpensive to explicitly\n\
  40. * evaluate both possibilities for a vec3 expression.\n\
  41. *\n\
  42. * @name czm_branchFreeTernary\n\
  43. * @glslFunction\n\
  44. *\n\
  45. * @param {bool} comparison A comparison statement\n\
  46. * @param {vec3} a Value to return if the comparison is true.\n\
  47. * @param {vec3} b Value to return if the comparison is false.\n\
  48. *\n\
  49. * @returns {vec3} equivalent of comparison ? a : b\n\
  50. */\n\
  51. vec3 czm_branchFreeTernary(bool comparison, vec3 a, vec3 b) {\n\
  52. float useA = float(comparison);\n\
  53. return a * useA + b * (1.0 - useA);\n\
  54. }\n\
  55. \n\
  56. /**\n\
  57. * Branchless ternary operator to be used when it's inexpensive to explicitly\n\
  58. * evaluate both possibilities for a vec4 expression.\n\
  59. *\n\
  60. * @name czm_branchFreeTernary\n\
  61. * @glslFunction\n\
  62. *\n\
  63. * @param {bool} comparison A comparison statement\n\
  64. * @param {vec3} a Value to return if the comparison is true.\n\
  65. * @param {vec3} b Value to return if the comparison is false.\n\
  66. *\n\
  67. * @returns {vec3} equivalent of comparison ? a : b\n\
  68. */\n\
  69. vec4 czm_branchFreeTernary(bool comparison, vec4 a, vec4 b) {\n\
  70. float useA = float(comparison);\n\
  71. return a * useA + b * (1.0 - useA);\n\
  72. }\n\
  73. ";