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

BillboardCollectionFS.js 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "uniform sampler2D u_atlas;\n\
  3. uniform float u_coarseDepthTestDistance;\n\
  4. uniform float u_threePointDepthTestDistance;\n\
  5. \n\
  6. #ifdef VECTOR_TILE\n\
  7. uniform vec4 u_highlightColor;\n\
  8. #endif\n\
  9. \n\
  10. in vec2 v_textureCoordinates;\n\
  11. in vec4 v_pickColor;\n\
  12. in vec4 v_color;\n\
  13. flat in vec2 v_splitDirectionAndEllipsoidDepthEC;\n\
  14. \n\
  15. #ifdef SDF\n\
  16. in vec4 v_outlineColor;\n\
  17. in float v_outlineWidth;\n\
  18. #endif\n\
  19. \n\
  20. in vec4 v_compressed; // x: eyeDepth, y: applyTranslate & enableDepthCheck, z: dimensions, w: imageSize\n\
  21. const float SHIFT_LEFT1 = 2.0;\n\
  22. const float SHIFT_RIGHT1 = 1.0 / 2.0;\n\
  23. \n\
  24. float getGlobeDepthAtCoords(vec2 st)\n\
  25. {\n\
  26. float logDepthOrDepth = czm_unpackDepth(texture(czm_globeDepthTexture, st));\n\
  27. if (logDepthOrDepth == 0.0)\n\
  28. {\n\
  29. return 0.0; // not on the globe\n\
  30. }\n\
  31. \n\
  32. vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, logDepthOrDepth);\n\
  33. return eyeCoordinate.z / eyeCoordinate.w;\n\
  34. }\n\
  35. \n\
  36. #ifdef SDF\n\
  37. \n\
  38. // Get the distance from the edge of a glyph at a given position sampling an SDF texture.\n\
  39. float getDistance(vec2 position)\n\
  40. {\n\
  41. return texture(u_atlas, position).r;\n\
  42. }\n\
  43. \n\
  44. // Samples the sdf texture at the given position and produces a color based on the fill color and the outline.\n\
  45. vec4 getSDFColor(vec2 position, float outlineWidth, vec4 outlineColor, float smoothing)\n\
  46. {\n\
  47. float distance = getDistance(position);\n\
  48. \n\
  49. if (outlineWidth > 0.0)\n\
  50. {\n\
  51. // Don't get the outline edge exceed the SDF_EDGE\n\
  52. float outlineEdge = clamp(SDF_EDGE - outlineWidth, 0.0, SDF_EDGE);\n\
  53. float outlineFactor = smoothstep(SDF_EDGE - smoothing, SDF_EDGE + smoothing, distance);\n\
  54. vec4 sdfColor = mix(outlineColor, v_color, outlineFactor);\n\
  55. float alpha = smoothstep(outlineEdge - smoothing, outlineEdge + smoothing, distance);\n\
  56. return vec4(sdfColor.rgb, sdfColor.a * alpha);\n\
  57. }\n\
  58. else\n\
  59. {\n\
  60. float alpha = smoothstep(SDF_EDGE - smoothing, SDF_EDGE + smoothing, distance);\n\
  61. return vec4(v_color.rgb, v_color.a * alpha);\n\
  62. }\n\
  63. }\n\
  64. #endif\n\
  65. \n\
  66. bool getDepthTestEnabled() {\n\
  67. float temp = v_compressed.y;\n\
  68. temp = temp * SHIFT_RIGHT1;\n\
  69. float temp2 = (temp - floor(temp)) * SHIFT_LEFT1;\n\
  70. return temp2 != 0.0;\n\
  71. }\n\
  72. \n\
  73. float getRelativeEyeDepth(float eyeDepth, float distanceToEllipsoid, float epsilon) {\n\
  74. float depthDifferential = eyeDepth - distanceToEllipsoid;\n\
  75. float depthRatio = abs(depthDifferential / distanceToEllipsoid);\n\
  76. if (depthRatio < epsilon) {\n\
  77. // The approximations are imprecise, so use an epsilon check for small value differences and assume a value of 0.0\n\
  78. return 0.0;\n\
  79. }\n\
  80. \n\
  81. return depthDifferential;\n\
  82. }\n\
  83. \n\
  84. // Extra manual depth testing is done to allow more control over how a billboard is occluded\n\
  85. // by the globe when near and far from the camera.\n\
  86. void doDepthTest(float eyeDepth, float globeDepth) {\n\
  87. \n\
  88. #ifdef VS_THREE_POINT_DEPTH_CHECK\n\
  89. // Since discarding vertices is not possible, the vertex shader sets eyeDepth to 0 to indicate the depth test failed. Apply the discard here.\n\
  90. if (eyeDepth > -u_threePointDepthTestDistance) {\n\
  91. if (eyeDepth == 0.0) {\n\
  92. discard;\n\
  93. }\n\
  94. return;\n\
  95. }\n\
  96. #endif\n\
  97. bool useGlobeDepth = eyeDepth > -u_coarseDepthTestDistance;\n\
  98. if (useGlobeDepth && globeDepth == 0.0) {\n\
  99. // Pixel is not on the globe, so there is no distance to compare against. Pass.\n\
  100. return;\n\
  101. }\n\
  102. \n\
  103. // If the camera is close, compare against the globe depth texture that includes depth from the 3D tile pass.\n\
  104. if (useGlobeDepth && getRelativeEyeDepth(eyeDepth, globeDepth, czm_epsilon1) < 0.0) {\n\
  105. discard;\n\
  106. }\n\
  107. }\n\
  108. \n\
  109. #ifdef LOG_DEPTH\n\
  110. void writeDepth(float eyeDepth, float globeDepth, float distanceToEllipsoid) {\n\
  111. // If we've made it here, the manual depth test above determined that this fragment should be visible.\n\
  112. // But the automatic depth test must still run in order to write the result to the depth buffer, and its results may\n\
  113. // disagree with our manual depth test's results. To prefer our manual results when in front of the globe, apply an offset towards the camera.\n\
  114. \n\
  115. float depthArg = v_depthFromNearPlusOne;\n\
  116. \n\
  117. if (globeDepth != 0.0 && getRelativeEyeDepth(eyeDepth, distanceToEllipsoid, czm_epsilon3) > 0.0) {\n\
  118. float globeDepthFromNearPlusOne = (-globeDepth - czm_currentFrustum.x) + 1.0;\n\
  119. float nudge = max(globeDepthFromNearPlusOne * 5e-6, czm_epsilon7);\n\
  120. float globeOnTop = max(1.0, globeDepthFromNearPlusOne - nudge);\n\
  121. depthArg = min(depthArg, globeOnTop);\n\
  122. }\n\
  123. \n\
  124. czm_writeLogDepth(depthArg);\n\
  125. }\n\
  126. #endif\n\
  127. \n\
  128. void main()\n\
  129. {\n\
  130. if (v_splitDirectionAndEllipsoidDepthEC.x < 0.0 && gl_FragCoord.x > czm_splitPosition) {\n\
  131. discard;\n\
  132. }\n\
  133. if (v_splitDirectionAndEllipsoidDepthEC.x > 0.0 && gl_FragCoord.x < czm_splitPosition) {\n\
  134. discard;\n\
  135. }\n\
  136. \n\
  137. if (getDepthTestEnabled()) {\n\
  138. vec2 fragSt = gl_FragCoord.xy / czm_viewport.zw;\n\
  139. float eyeDepth = v_compressed.x;\n\
  140. float globeDepth = getGlobeDepthAtCoords(fragSt);\n\
  141. float distanceToEllipsoid = -v_splitDirectionAndEllipsoidDepthEC.y;\n\
  142. doDepthTest(eyeDepth, globeDepth);\n\
  143. \n\
  144. #ifdef LOG_DEPTH\n\
  145. writeDepth(eyeDepth, globeDepth, distanceToEllipsoid);\n\
  146. #endif\n\
  147. }\n\
  148. \n\
  149. vec4 color = texture(u_atlas, v_textureCoordinates);\n\
  150. \n\
  151. #ifdef SDF\n\
  152. float outlineWidth = v_outlineWidth;\n\
  153. vec4 outlineColor = v_outlineColor;\n\
  154. \n\
  155. // Get the current distance\n\
  156. float distance = getDistance(v_textureCoordinates);\n\
  157. \n\
  158. #if (__VERSION__ == 300 || defined(GL_OES_standard_derivatives))\n\
  159. float smoothing = fwidth(distance);\n\
  160. // Get an offset that is approximately half the distance to the neighbor pixels\n\
  161. // 0.354 is approximately half of 1/sqrt(2)\n\
  162. vec2 sampleOffset = 0.354 * vec2(dFdx(v_textureCoordinates) + dFdy(v_textureCoordinates));\n\
  163. \n\
  164. // Sample the center point\n\
  165. vec4 center = getSDFColor(v_textureCoordinates, outlineWidth, outlineColor, smoothing);\n\
  166. \n\
  167. // Sample the 4 neighbors\n\
  168. vec4 color1 = getSDFColor(v_textureCoordinates + vec2(sampleOffset.x, sampleOffset.y), outlineWidth, outlineColor, smoothing);\n\
  169. vec4 color2 = getSDFColor(v_textureCoordinates + vec2(-sampleOffset.x, sampleOffset.y), outlineWidth, outlineColor, smoothing);\n\
  170. vec4 color3 = getSDFColor(v_textureCoordinates + vec2(-sampleOffset.x, -sampleOffset.y), outlineWidth, outlineColor, smoothing);\n\
  171. vec4 color4 = getSDFColor(v_textureCoordinates + vec2(sampleOffset.x, -sampleOffset.y), outlineWidth, outlineColor, smoothing);\n\
  172. \n\
  173. // Equally weight the center sample and the 4 neighboring samples\n\
  174. color = (center + color1 + color2 + color3 + color4)/5.0;\n\
  175. #else\n\
  176. // If no derivatives available (IE 10?), just do a single sample\n\
  177. float smoothing = 1.0/32.0;\n\
  178. color = getSDFColor(v_textureCoordinates, outlineWidth, outlineColor, smoothing);\n\
  179. #endif\n\
  180. \n\
  181. color = czm_gammaCorrect(color);\n\
  182. #else\n\
  183. color = czm_gammaCorrect(color);\n\
  184. color *= czm_gammaCorrect(v_color);\n\
  185. #endif\n\
  186. \n\
  187. // Fully transparent parts of the billboard are not pickable.\n\
  188. #if !defined(OPAQUE) && !defined(TRANSLUCENT)\n\
  189. if (color.a < 0.005) // matches 0/255 and 1/255\n\
  190. {\n\
  191. discard;\n\
  192. }\n\
  193. #else\n\
  194. // The billboard is rendered twice. The opaque pass discards translucent fragments\n\
  195. // and the translucent pass discards opaque fragments.\n\
  196. #ifdef OPAQUE\n\
  197. if (color.a < 0.995) // matches < 254/255\n\
  198. {\n\
  199. discard;\n\
  200. }\n\
  201. #else\n\
  202. if (color.a >= 0.995) // matches 254/255 and 255/255\n\
  203. {\n\
  204. discard;\n\
  205. }\n\
  206. #endif\n\
  207. #endif\n\
  208. \n\
  209. #ifdef VECTOR_TILE\n\
  210. color *= u_highlightColor;\n\
  211. #endif\n\
  212. out_FragColor = color;\n\
  213. }\n\
  214. ";