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

ConvolveSpecularMapFS.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "precision highp float;\n\
  3. \n\
  4. in vec3 v_textureCoordinates;\n\
  5. \n\
  6. uniform float u_roughness;\n\
  7. uniform samplerCube u_radianceTexture;\n\
  8. uniform vec3 u_faceDirection;\n\
  9. \n\
  10. float vdcRadicalInverse(int i)\n\
  11. {\n\
  12. float r;\n\
  13. float base = 2.0;\n\
  14. float value = 0.0;\n\
  15. float invBase = 1.0 / base;\n\
  16. float invBi = invBase;\n\
  17. for (int x = 0; x < 100; x++)\n\
  18. {\n\
  19. if (i <= 0)\n\
  20. {\n\
  21. break;\n\
  22. }\n\
  23. r = mod(float(i), base);\n\
  24. value += r * invBi;\n\
  25. invBi *= invBase;\n\
  26. i = int(float(i) * invBase);\n\
  27. }\n\
  28. return value;\n\
  29. }\n\
  30. \n\
  31. vec2 hammersley2D(int i, int N)\n\
  32. {\n\
  33. return vec2(float(i) / float(N), vdcRadicalInverse(i));\n\
  34. }\n\
  35. \n\
  36. vec3 importanceSampleGGX(vec2 xi, float alphaRoughness, vec3 N)\n\
  37. {\n\
  38. float alphaRoughnessSquared = alphaRoughness * alphaRoughness;\n\
  39. float phi = czm_twoPi * xi.x;\n\
  40. float cosTheta = sqrt((1.0 - xi.y) / (1.0 + (alphaRoughnessSquared - 1.0) * xi.y));\n\
  41. float sinTheta = sqrt(1.0 - cosTheta * cosTheta);\n\
  42. vec3 H = vec3(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta);\n\
  43. vec3 upVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);\n\
  44. vec3 tangentX = normalize(cross(upVector, N));\n\
  45. vec3 tangentY = cross(N, tangentX);\n\
  46. return tangentX * H.x + tangentY * H.y + N * H.z;\n\
  47. }\n\
  48. \n\
  49. // Sample count is relatively low for the sake of performance, but should still be enough to prevent artifacting in lower roughnesses\n\
  50. const int samples = 128;\n\
  51. \n\
  52. void main() {\n\
  53. vec3 normal = u_faceDirection;\n\
  54. vec3 V = normalize(v_textureCoordinates);\n\
  55. float roughness = u_roughness;\n\
  56. \n\
  57. vec4 color = vec4(0.0);\n\
  58. float weight = 0.0;\n\
  59. for (int i = 0; i < samples; ++i) {\n\
  60. vec2 xi = hammersley2D(i, samples);\n\
  61. vec3 H = importanceSampleGGX(xi, roughness, V);\n\
  62. vec3 L = 2.0 * dot(V, H) * H - V; // reflected vector\n\
  63. \n\
  64. float NdotL = max(dot(V, L), 0.0);\n\
  65. if (NdotL > 0.0) {\n\
  66. color += vec4(czm_textureCube(u_radianceTexture, L).rgb, 1.0) * NdotL;\n\
  67. weight += NdotL;\n\
  68. }\n\
  69. }\n\
  70. out_FragColor = color / weight;\n\
  71. }\n\
  72. ";