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

BillboardCollectionVS.js 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "uniform float u_threePointDepthTestDistance;\n\
  3. in vec2 direction;\n\
  4. in vec4 positionHighAndScale;\n\
  5. in vec4 positionLowAndRotation;\n\
  6. in vec4 compressedAttribute0; // pixel offset, translate, horizontal origin, vertical origin, show, direction, texture coordinates (texture offset)\n\
  7. in vec4 compressedAttribute1; // aligned axis, translucency by distance, image width\n\
  8. in vec4 compressedAttribute2; // label horizontal origin, image height, color, pick color, size in meters, valid aligned axis, 13 bits free\n\
  9. in vec4 eyeOffset; // eye offset in meters, 4 bytes free (texture range)\n\
  10. in vec4 scaleByDistance; // near, nearScale, far, farScale\n\
  11. in vec4 pixelOffsetScaleByDistance; // near, nearScale, far, farScale\n\
  12. in vec4 compressedAttribute3; // distance display condition near, far, disableDepthTestDistanceSq, dimensions\n\
  13. in vec2 sdf; // sdf outline color (rgb) and width (w)\n\
  14. in float splitDirection; // splitDirection\n\
  15. #ifdef VS_THREE_POINT_DEPTH_CHECK\n\
  16. in vec4 textureCoordinateBoundsOrLabelTranslate; // the min and max x and y values for the texture coordinates\n\
  17. #endif\n\
  18. #ifdef VECTOR_TILE\n\
  19. in float a_batchId;\n\
  20. #endif\n\
  21. \n\
  22. out vec2 v_textureCoordinates;\n\
  23. out vec4 v_compressed; // x: eyeDepth, y: applyTranslate & enableDepthCheck, z: dimensions, w: imageSize\n\
  24. \n\
  25. out vec4 v_pickColor;\n\
  26. out vec4 v_color;\n\
  27. flat out vec2 v_splitDirectionAndEllipsoidDepthEC; // x: splitDirection, y: ellipsoid depth in eye coordinates\n\
  28. #ifdef SDF\n\
  29. out vec4 v_outlineColor;\n\
  30. out float v_outlineWidth;\n\
  31. #endif\n\
  32. \n\
  33. const float UPPER_BOUND = 32768.0;\n\
  34. \n\
  35. const float SHIFT_LEFT16 = 65536.0;\n\
  36. const float SHIFT_LEFT12 = 4096.0;\n\
  37. const float SHIFT_LEFT8 = 256.0;\n\
  38. const float SHIFT_LEFT7 = 128.0;\n\
  39. const float SHIFT_LEFT5 = 32.0;\n\
  40. const float SHIFT_LEFT3 = 8.0;\n\
  41. const float SHIFT_LEFT2 = 4.0;\n\
  42. const float SHIFT_LEFT1 = 2.0;\n\
  43. \n\
  44. const float SHIFT_RIGHT12 = 1.0 / 4096.0;\n\
  45. const float SHIFT_RIGHT8 = 1.0 / 256.0;\n\
  46. const float SHIFT_RIGHT7 = 1.0 / 128.0;\n\
  47. const float SHIFT_RIGHT5 = 1.0 / 32.0;\n\
  48. const float SHIFT_RIGHT3 = 1.0 / 8.0;\n\
  49. const float SHIFT_RIGHT2 = 1.0 / 4.0;\n\
  50. const float SHIFT_RIGHT1 = 1.0 / 2.0;\n\
  51. \n\
  52. vec4 addScreenSpaceOffset(vec4 positionEC, vec2 imageSize, float scale, vec2 direction, vec2 origin, vec2 translate, vec2 pixelOffset, vec3 alignedAxis, bool validAlignedAxis, float rotation, bool sizeInMeters, out mat2 rotationMatrix, out float mpp)\n\
  53. {\n\
  54. // Note the halfSize cannot be computed in JavaScript because it is sent via\n\
  55. // compressed vertex attributes that coerce it to an integer.\n\
  56. vec2 halfSize = imageSize * scale * 0.5;\n\
  57. halfSize *= ((direction * 2.0) - 1.0);\n\
  58. \n\
  59. vec2 originTranslate = origin * abs(halfSize);\n\
  60. \n\
  61. #if defined(ROTATION) || defined(ALIGNED_AXIS)\n\
  62. if (validAlignedAxis || rotation != 0.0)\n\
  63. {\n\
  64. float angle = rotation;\n\
  65. if (validAlignedAxis)\n\
  66. {\n\
  67. vec4 projectedAlignedAxis = czm_modelView3D * vec4(alignedAxis, 0.0);\n\
  68. angle += sign(-projectedAlignedAxis.x) * acos(sign(projectedAlignedAxis.y) * (projectedAlignedAxis.y * projectedAlignedAxis.y) /\n\
  69. (projectedAlignedAxis.x * projectedAlignedAxis.x + projectedAlignedAxis.y * projectedAlignedAxis.y));\n\
  70. }\n\
  71. \n\
  72. float cosTheta = cos(angle);\n\
  73. float sinTheta = sin(angle);\n\
  74. rotationMatrix = mat2(cosTheta, sinTheta, -sinTheta, cosTheta);\n\
  75. halfSize = rotationMatrix * halfSize;\n\
  76. }\n\
  77. else\n\
  78. {\n\
  79. rotationMatrix = mat2(1.0, 0.0, 0.0, 1.0);\n\
  80. }\n\
  81. #endif\n\
  82. \n\
  83. mpp = czm_metersPerPixel(positionEC);\n\
  84. positionEC.xy += (originTranslate + halfSize) * czm_branchFreeTernary(sizeInMeters, 1.0, mpp);\n\
  85. positionEC.xy += (translate + pixelOffset) * mpp;\n\
  86. \n\
  87. return positionEC;\n\
  88. }\n\
  89. \n\
  90. #ifdef VS_THREE_POINT_DEPTH_CHECK\n\
  91. float getGlobeDepth(vec4 positionEC)\n\
  92. {\n\
  93. vec4 posWC = czm_eyeToWindowCoordinates(positionEC);\n\
  94. \n\
  95. float globeDepth = czm_unpackDepth(texture(czm_globeDepthTexture, posWC.xy / czm_viewport.zw));\n\
  96. \n\
  97. if (globeDepth == 0.0)\n\
  98. {\n\
  99. return 0.0; // not on the globe\n\
  100. }\n\
  101. \n\
  102. vec4 eyeCoordinate = czm_windowToEyeCoordinates(posWC.xy, globeDepth);\n\
  103. return eyeCoordinate.z / eyeCoordinate.w;\n\
  104. }\n\
  105. #endif\n\
  106. void main()\n\
  107. {\n\
  108. // Modifying this shader may also require modifications to Billboard._computeScreenSpacePosition\n\
  109. \n\
  110. // unpack attributes\n\
  111. vec3 positionHigh = positionHighAndScale.xyz;\n\
  112. vec3 positionLow = positionLowAndRotation.xyz;\n\
  113. float scale = positionHighAndScale.w;\n\
  114. \n\
  115. #if defined(ROTATION) || defined(ALIGNED_AXIS)\n\
  116. float rotation = positionLowAndRotation.w;\n\
  117. #else\n\
  118. float rotation = 0.0;\n\
  119. #endif\n\
  120. \n\
  121. float compressed = compressedAttribute0.x;\n\
  122. \n\
  123. vec2 pixelOffset;\n\
  124. pixelOffset.x = floor(compressed * SHIFT_RIGHT7);\n\
  125. compressed -= pixelOffset.x * SHIFT_LEFT7;\n\
  126. pixelOffset.x -= UPPER_BOUND;\n\
  127. \n\
  128. vec2 origin;\n\
  129. origin.x = floor(compressed * SHIFT_RIGHT5);\n\
  130. compressed -= origin.x * SHIFT_LEFT5;\n\
  131. \n\
  132. origin.y = floor(compressed * SHIFT_RIGHT3);\n\
  133. compressed -= origin.y * SHIFT_LEFT3;\n\
  134. \n\
  135. origin -= vec2(1.0);\n\
  136. \n\
  137. float show = floor(compressed * SHIFT_RIGHT2);\n\
  138. compressed -= show * SHIFT_LEFT2;\n\
  139. \n\
  140. vec2 textureCoordinatesBottomLeft = czm_decompressTextureCoordinates(compressedAttribute0.w);\n\
  141. vec2 textureCoordinatesRange = czm_decompressTextureCoordinates(eyeOffset.w);\n\
  142. vec2 textureCoordinates = textureCoordinatesBottomLeft + direction * textureCoordinatesRange;\n\
  143. \n\
  144. float temp = compressedAttribute0.y * SHIFT_RIGHT8;\n\
  145. pixelOffset.y = -(floor(temp) - UPPER_BOUND);\n\
  146. \n\
  147. vec2 translate;\n\
  148. translate.y = (temp - floor(temp)) * SHIFT_LEFT16;\n\
  149. \n\
  150. temp = compressedAttribute0.z * SHIFT_RIGHT8;\n\
  151. translate.x = floor(temp) - UPPER_BOUND;\n\
  152. translate.x *= SHIFT_RIGHT2; // undo translateX scaling (helps preserve subpixel precision, see BillboardCollection.js attribute writer for more info)\n\
  153. \n\
  154. translate.y += (temp - floor(temp)) * SHIFT_LEFT8;\n\
  155. translate.y -= UPPER_BOUND;\n\
  156. translate.y *= SHIFT_RIGHT2;\n\
  157. \n\
  158. temp = compressedAttribute1.x * SHIFT_RIGHT8;\n\
  159. float temp2 = floor(compressedAttribute2.w * SHIFT_RIGHT2);\n\
  160. \n\
  161. vec2 imageSize = vec2(floor(temp), temp2);\n\
  162. \n\
  163. #ifdef EYE_DISTANCE_TRANSLUCENCY\n\
  164. vec4 translucencyByDistance;\n\
  165. translucencyByDistance.x = compressedAttribute1.z;\n\
  166. translucencyByDistance.z = compressedAttribute1.w;\n\
  167. \n\
  168. translucencyByDistance.y = ((temp - floor(temp)) * SHIFT_LEFT8) / 255.0;\n\
  169. \n\
  170. temp = compressedAttribute1.y * SHIFT_RIGHT8;\n\
  171. translucencyByDistance.w = ((temp - floor(temp)) * SHIFT_LEFT8) / 255.0;\n\
  172. #endif\n\
  173. \n\
  174. #ifdef VS_THREE_POINT_DEPTH_CHECK\n\
  175. temp = compressedAttribute3.w;\n\
  176. temp = temp * SHIFT_RIGHT12;\n\
  177. \n\
  178. vec2 dimensions;\n\
  179. dimensions.y = (temp - floor(temp)) * SHIFT_LEFT12;\n\
  180. dimensions.x = floor(temp);\n\
  181. #endif\n\
  182. \n\
  183. #ifdef ALIGNED_AXIS\n\
  184. vec3 alignedAxis = czm_octDecode(floor(compressedAttribute1.y * SHIFT_RIGHT8));\n\
  185. temp = compressedAttribute2.z * SHIFT_RIGHT5;\n\
  186. bool validAlignedAxis = (temp - floor(temp)) * SHIFT_LEFT1 > 0.0;\n\
  187. #else\n\
  188. vec3 alignedAxis = vec3(0.0);\n\
  189. bool validAlignedAxis = false;\n\
  190. #endif\n\
  191. \n\
  192. vec4 color = czm_decodeRGB8(compressedAttribute2.x);\n\
  193. vec4 pickColor = czm_decodeRGB8(compressedAttribute2.y);\n\
  194. \n\
  195. temp = compressedAttribute2.z * SHIFT_RIGHT8;\n\
  196. bool sizeInMeters = floor((temp - floor(temp)) * SHIFT_LEFT7) > 0.0;\n\
  197. temp = floor(temp) * SHIFT_RIGHT8;\n\
  198. \n\
  199. pickColor.a = (temp - floor(temp)) * SHIFT_LEFT8;\n\
  200. pickColor.a /= 255.0;\n\
  201. \n\
  202. color.a = floor(temp);\n\
  203. color.a /= 255.0;\n\
  204. \n\
  205. ///////////////////////////////////////////////////////////////////////////\n\
  206. \n\
  207. vec4 p = czm_translateRelativeToEye(positionHigh, positionLow);\n\
  208. vec4 positionEC = czm_modelViewRelativeToEye * p;\n\
  209. \n\
  210. positionEC = czm_eyeOffset(positionEC, eyeOffset.xyz);\n\
  211. positionEC.xyz *= show;\n\
  212. \n\
  213. ///////////////////////////////////////////////////////////////////////////\n\
  214. \n\
  215. #if defined(EYE_DISTANCE_SCALING) || defined(EYE_DISTANCE_TRANSLUCENCY) || defined(EYE_DISTANCE_PIXEL_OFFSET) || defined(DISTANCE_DISPLAY_CONDITION) || defined(DISABLE_DEPTH_DISTANCE)\n\
  216. float lengthSq;\n\
  217. if (czm_sceneMode == czm_sceneMode2D)\n\
  218. {\n\
  219. // 2D camera distance is a special case\n\
  220. // treat all billboards as flattened to the z=0.0 plane\n\
  221. lengthSq = czm_eyeHeight2D.y;\n\
  222. }\n\
  223. else\n\
  224. {\n\
  225. lengthSq = dot(positionEC.xyz, positionEC.xyz);\n\
  226. }\n\
  227. #endif\n\
  228. \n\
  229. #ifdef EYE_DISTANCE_SCALING\n\
  230. float distanceScale = czm_nearFarScalar(scaleByDistance, lengthSq);\n\
  231. scale *= distanceScale;\n\
  232. translate *= distanceScale;\n\
  233. // push vertex behind near plane for clipping\n\
  234. if (scale == 0.0)\n\
  235. {\n\
  236. positionEC.xyz = vec3(0.0);\n\
  237. }\n\
  238. #endif\n\
  239. \n\
  240. float translucency = 1.0;\n\
  241. #ifdef EYE_DISTANCE_TRANSLUCENCY\n\
  242. translucency = czm_nearFarScalar(translucencyByDistance, lengthSq);\n\
  243. // push vertex behind near plane for clipping\n\
  244. if (translucency == 0.0)\n\
  245. {\n\
  246. positionEC.xyz = vec3(0.0);\n\
  247. }\n\
  248. #endif\n\
  249. \n\
  250. #ifdef EYE_DISTANCE_PIXEL_OFFSET\n\
  251. float pixelOffsetScale = czm_nearFarScalar(pixelOffsetScaleByDistance, lengthSq);\n\
  252. pixelOffset *= pixelOffsetScale;\n\
  253. #endif\n\
  254. \n\
  255. #ifdef DISTANCE_DISPLAY_CONDITION\n\
  256. float nearSq = compressedAttribute3.x;\n\
  257. float farSq = compressedAttribute3.y;\n\
  258. if (lengthSq < nearSq || lengthSq > farSq)\n\
  259. {\n\
  260. positionEC.xyz = vec3(0.0);\n\
  261. }\n\
  262. #endif\n\
  263. \n\
  264. mat2 rotationMatrix;\n\
  265. float mpp;\n\
  266. \n\
  267. float enableDepthCheck = 1.0;\n\
  268. #ifdef DISABLE_DEPTH_DISTANCE\n\
  269. float disableDepthTestDistanceSq = compressedAttribute3.z;\n\
  270. if (disableDepthTestDistanceSq == 0.0 && czm_minimumDisableDepthTestDistance != 0.0)\n\
  271. {\n\
  272. disableDepthTestDistanceSq = czm_minimumDisableDepthTestDistance;\n\
  273. }\n\
  274. \n\
  275. if (lengthSq < disableDepthTestDistanceSq || disableDepthTestDistanceSq < 0.0)\n\
  276. {\n\
  277. enableDepthCheck = 0.0;\n\
  278. }\n\
  279. #endif\n\
  280. \n\
  281. v_splitDirectionAndEllipsoidDepthEC.y = czm_infinity;\n\
  282. vec3 ellipsoidCenter = czm_view[3].xyz;\n\
  283. vec3 rayDirection = normalize(positionEC.xyz);\n\
  284. czm_ray ray = czm_ray(vec3(0.0), rayDirection);\n\
  285. vec3 ellipsoid_inverseRadii = czm_ellipsoidInverseRadii;\n\
  286. czm_raySegment intersection = czm_rayEllipsoidIntersectionInterval(ray, ellipsoidCenter, ellipsoid_inverseRadii);\n\
  287. \n\
  288. if (!czm_isEmpty(intersection))\n\
  289. {\n\
  290. v_splitDirectionAndEllipsoidDepthEC.y = intersection.start;\n\
  291. }\n\
  292. \n\
  293. v_compressed.y = enableDepthCheck;\n\
  294. \n\
  295. #ifdef VS_THREE_POINT_DEPTH_CHECK\n\
  296. if (lengthSq < (u_threePointDepthTestDistance * u_threePointDepthTestDistance) && (enableDepthCheck == 1.0)) {\n\
  297. float depthsilon = 10.0;\n\
  298. vec2 depthOrigin;\n\
  299. // Horizontal origin for labels comes from a special attribute. If that value is 0, this is a billboard - use the regular origin.\n\
  300. // Otherwise, transform the label origin to -1, 0, 1 (right, center, left).\n\
  301. depthOrigin.x = floor(compressedAttribute2.w - (temp2 * SHIFT_LEFT2));\n\
  302. depthOrigin.x = czm_branchFreeTernary(depthOrigin.x == 0.0, origin.x, depthOrigin.x - 2.0);\n\
  303. depthOrigin.y = origin.y;\n\
  304. \n\
  305. vec4 pEC1 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(0.0), depthOrigin, vec2(0.0), pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);\n\
  306. float globeDepth1 = getGlobeDepth(pEC1);\n\
  307. \n\
  308. if (globeDepth1 != 0.0 && pEC1.z + depthsilon < globeDepth1)\n\
  309. {\n\
  310. vec4 pEC2 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(0.0, 1.0), depthOrigin, vec2(0.0), pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);\n\
  311. float globeDepth2 = getGlobeDepth(pEC2);\n\
  312. \n\
  313. if (globeDepth2 != 0.0 && pEC2.z + depthsilon < globeDepth2)\n\
  314. {\n\
  315. vec4 pEC3 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(1.0), depthOrigin, vec2(0.0), pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);\n\
  316. float globeDepth3 = getGlobeDepth(pEC3);\n\
  317. if (globeDepth3 != 0.0 && pEC3.z + depthsilon < globeDepth3)\n\
  318. {\n\
  319. // \"Discard\" this vertex, as three key points fail depth test.\n\
  320. positionEC.xyz = vec3(0.0);\n\
  321. }\n\
  322. }\n\
  323. }\n\
  324. }\n\
  325. #endif\n\
  326. // Write out the eyespace depth before applying the screen space offset, but after potentially \"discarding\" the vertex\n\
  327. // by setting its eyespace position to zero, via the three-point depth test above.\n\
  328. v_compressed.x = positionEC.z;\n\
  329. \n\
  330. positionEC = addScreenSpaceOffset(positionEC, imageSize, scale, direction, origin, translate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);\n\
  331. gl_Position = czm_projection * positionEC;\n\
  332. v_textureCoordinates = textureCoordinates;\n\
  333. \n\
  334. #ifdef LOG_DEPTH\n\
  335. czm_vertexLogDepth();\n\
  336. #endif\n\
  337. \n\
  338. #ifdef DISABLE_DEPTH_DISTANCE\n\
  339. \n\
  340. if (disableDepthTestDistanceSq != 0.0)\n\
  341. {\n\
  342. // Don't try to \"multiply both sides\" by w. Greater/less-than comparisons won't work for negative values of w.\n\
  343. float zclip = gl_Position.z / gl_Position.w;\n\
  344. bool clipped = (zclip < -1.0 || zclip > 1.0);\n\
  345. // disableDepthTestDistanceSq can be less than zero if it's explicitly set to -1 in JS (as a sentinel value equivalent to infinity)\n\
  346. if (!clipped && (disableDepthTestDistanceSq < 0.0 || (lengthSq > 0.0 && lengthSq < disableDepthTestDistanceSq)))\n\
  347. {\n\
  348. // Position z on the near plane.\n\
  349. gl_Position.z = -gl_Position.w;\n\
  350. #ifdef LOG_DEPTH\n\
  351. v_depthFromNearPlusOne = 1.0;\n\
  352. #endif\n\
  353. }\n\
  354. }\n\
  355. #endif\n\
  356. \n\
  357. #ifdef SDF\n\
  358. vec4 outlineColor = czm_decodeRGB8(sdf.x);\n\
  359. float outlineWidth;\n\
  360. \n\
  361. temp = sdf.y;\n\
  362. temp = temp * SHIFT_RIGHT8;\n\
  363. float temp3 = (temp - floor(temp)) * SHIFT_LEFT8;\n\
  364. temp = floor(temp) * SHIFT_RIGHT8;\n\
  365. outlineWidth = (temp - floor(temp)) * SHIFT_LEFT8;\n\
  366. outlineColor.a = floor(temp);\n\
  367. outlineColor.a /= 255.0;\n\
  368. \n\
  369. v_outlineWidth = outlineWidth / 255.0;\n\
  370. v_outlineColor = outlineColor;\n\
  371. v_outlineColor.a *= translucency;\n\
  372. #endif\n\
  373. \n\
  374. v_pickColor = pickColor;\n\
  375. \n\
  376. v_color = color;\n\
  377. v_color.a *= translucency;\n\
  378. v_splitDirectionAndEllipsoidDepthEC.x = splitDirection;\n\
  379. }\n\
  380. ";