智慧水务管理系统 - 精河县供水工程综合管理平台

ComputeIrradianceFS.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "uniform samplerCube u_radianceMap;\n\
  3. \n\
  4. in vec2 v_textureCoordinates;\n\
  5. \n\
  6. \n\
  7. const float twoSqrtPi = 2.0 * sqrt(czm_pi);\n\
  8. \n\
  9. // Coutesy of https://www.ppsloan.org/publications/StupidSH36.pdf\n\
  10. float computeShBasis(int index, vec3 s) {\n\
  11. if (index == 0) { // l = 0, m = 0\n\
  12. return 1.0 / twoSqrtPi;\n\
  13. }\n\
  14. \n\
  15. if (index == 1) { // l = 1, m = -1\n\
  16. return -sqrt(3.0) * s.y / twoSqrtPi;\n\
  17. }\n\
  18. \n\
  19. if (index == 2) { // l = 1, m = 0\n\
  20. return sqrt(3.0) * s.z / twoSqrtPi;\n\
  21. }\n\
  22. \n\
  23. if (index == 3) { // l = 1, m = 1\n\
  24. return -sqrt(3.0) * s.x / twoSqrtPi;\n\
  25. }\n\
  26. \n\
  27. if (index == 4) { // l = 2, m = -2\n\
  28. return sqrt(15.0) * s.y * s.x / twoSqrtPi;\n\
  29. }\n\
  30. \n\
  31. if (index == 5) { // l = 2, m = -1\n\
  32. return -sqrt(15.0) * s.y * s.z / twoSqrtPi;\n\
  33. }\n\
  34. \n\
  35. if (index == 6) { // l = 2, m = 0\n\
  36. return sqrt(5.0) * (3.0 * s.z * s.z - 1.0) / 2.0 / twoSqrtPi;\n\
  37. }\n\
  38. \n\
  39. if (index == 7) { // l = 2, m = 1\n\
  40. return -sqrt(15.0) * s.x * s.z / twoSqrtPi;\n\
  41. }\n\
  42. \n\
  43. if (index == 8) { // l = 2, m = 2\n\
  44. return sqrt(15.0) * (s.x * s.x - s.y * s.y) / 2.0 / twoSqrtPi;\n\
  45. }\n\
  46. \n\
  47. return 0.0;\n\
  48. }\n\
  49. \n\
  50. float vdcRadicalInverse(int i)\n\
  51. {\n\
  52. float r;\n\
  53. float base = 2.0;\n\
  54. float value = 0.0;\n\
  55. float invBase = 1.0 / base;\n\
  56. float invBi = invBase;\n\
  57. for (int x = 0; x < 100; x++)\n\
  58. {\n\
  59. if (i <= 0)\n\
  60. {\n\
  61. break;\n\
  62. }\n\
  63. r = mod(float(i), base);\n\
  64. value += r * invBi;\n\
  65. invBi *= invBase;\n\
  66. i = int(float(i) * invBase);\n\
  67. }\n\
  68. return value;\n\
  69. }\n\
  70. \n\
  71. vec2 hammersley2D(int i, int N)\n\
  72. {\n\
  73. return vec2(float(i) / float(N), vdcRadicalInverse(i));\n\
  74. }\n\
  75. \n\
  76. // Sample count is relatively low for the sake of performance, but should still be enough to capture directionality needed for third-order harmonics\n\
  77. const int samples = 256; \n\
  78. const float solidAngle = 1.0 / float(samples);\n\
  79. \n\
  80. void main() {\n\
  81. // Get the current coefficient based on the uv\n\
  82. vec2 uv = v_textureCoordinates.xy * 3.0;\n\
  83. int coefficientIndex = int(floor(uv.y) * 3.0 + floor(uv.x));\n\
  84. \n\
  85. for (int i = 0; i < samples; ++i) {\n\
  86. vec2 xi = hammersley2D(i, samples);\n\
  87. float phi = czm_twoPi * xi.x;\n\
  88. float cosTheta = 1.0 - 2.0 * sqrt(1.0 - xi.y * xi.y);\n\
  89. float sinTheta = sqrt(1.0 - cosTheta * cosTheta);\n\
  90. vec3 direction = normalize(vec3(sinTheta * cos(phi), cosTheta, sinTheta * sin(phi)));\n\
  91. \n\
  92. // Generate the spherical harmonics basis from the direction\n\
  93. float Ylm = computeShBasis(coefficientIndex, direction);\n\
  94. \n\
  95. vec3 lookupDirection = -direction.xyz;\n\
  96. lookupDirection.z = -lookupDirection.z;\n\
  97. \n\
  98. vec4 color = czm_textureCube(u_radianceMap, lookupDirection, 0.0);\n\
  99. \n\
  100. // Use the relevant function for this coefficient\n\
  101. out_FragColor += Ylm * color * solidAngle * sinTheta;\n\
  102. }\n\
  103. \n\
  104. }\n\
  105. ";