BillboardCollectionVS.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "#ifdef INSTANCED\n\
  3. attribute vec2 direction;\n\
  4. #endif\n\
  5. attribute vec4 positionHighAndScale;\n\
  6. attribute vec4 positionLowAndRotation;\n\
  7. attribute vec4 compressedAttribute0;\n\
  8. attribute vec4 compressedAttribute1;\n\
  9. attribute vec4 compressedAttribute2;\n\
  10. attribute vec4 eyeOffset;\n\
  11. attribute vec4 scaleByDistance;\n\
  12. attribute vec4 pixelOffsetScaleByDistance;\n\
  13. attribute vec4 compressedAttribute3;\n\
  14. attribute vec2 sdf;\n\
  15. #if defined(VERTEX_DEPTH_CHECK) || defined(FRAGMENT_DEPTH_CHECK)\n\
  16. attribute vec4 textureCoordinateBoundsOrLabelTranslate;\n\
  17. #endif\n\
  18. #ifdef VECTOR_TILE\n\
  19. attribute float a_batchId;\n\
  20. #endif\n\
  21. varying vec2 v_textureCoordinates;\n\
  22. #ifdef FRAGMENT_DEPTH_CHECK\n\
  23. varying vec4 v_textureCoordinateBounds;\n\
  24. varying vec4 v_originTextureCoordinateAndTranslate;\n\
  25. varying vec4 v_compressed;\n\
  26. varying mat2 v_rotationMatrix;\n\
  27. #endif\n\
  28. varying vec4 v_pickColor;\n\
  29. varying vec4 v_color;\n\
  30. #ifdef SDF\n\
  31. varying vec4 v_outlineColor;\n\
  32. varying float v_outlineWidth;\n\
  33. #endif\n\
  34. const float UPPER_BOUND = 32768.0;\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. const float SHIFT_RIGHT12 = 1.0 / 4096.0;\n\
  44. const float SHIFT_RIGHT8 = 1.0 / 256.0;\n\
  45. const float SHIFT_RIGHT7 = 1.0 / 128.0;\n\
  46. const float SHIFT_RIGHT5 = 1.0 / 32.0;\n\
  47. const float SHIFT_RIGHT3 = 1.0 / 8.0;\n\
  48. const float SHIFT_RIGHT2 = 1.0 / 4.0;\n\
  49. const float SHIFT_RIGHT1 = 1.0 / 2.0;\n\
  50. 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\
  51. {\n\
  52. vec2 halfSize = imageSize * scale * 0.5;\n\
  53. halfSize *= ((direction * 2.0) - 1.0);\n\
  54. vec2 originTranslate = origin * abs(halfSize);\n\
  55. #if defined(ROTATION) || defined(ALIGNED_AXIS)\n\
  56. if (validAlignedAxis || rotation != 0.0)\n\
  57. {\n\
  58. float angle = rotation;\n\
  59. if (validAlignedAxis)\n\
  60. {\n\
  61. vec4 projectedAlignedAxis = czm_modelViewProjection * vec4(alignedAxis, 0.0);\n\
  62. angle += sign(-projectedAlignedAxis.x) * acos(sign(projectedAlignedAxis.y) * (projectedAlignedAxis.y * projectedAlignedAxis.y) /\n\
  63. (projectedAlignedAxis.x * projectedAlignedAxis.x + projectedAlignedAxis.y * projectedAlignedAxis.y));\n\
  64. }\n\
  65. float cosTheta = cos(angle);\n\
  66. float sinTheta = sin(angle);\n\
  67. rotationMatrix = mat2(cosTheta, sinTheta, -sinTheta, cosTheta);\n\
  68. halfSize = rotationMatrix * halfSize;\n\
  69. }\n\
  70. else\n\
  71. {\n\
  72. rotationMatrix = mat2(1.0, 0.0, 0.0, 1.0);\n\
  73. }\n\
  74. #endif\n\
  75. mpp = czm_metersPerPixel(positionEC);\n\
  76. positionEC.xy += (originTranslate + halfSize) * czm_branchFreeTernary(sizeInMeters, 1.0, mpp);\n\
  77. positionEC.xy += (translate + pixelOffset) * mpp;\n\
  78. return positionEC;\n\
  79. }\n\
  80. #ifdef VERTEX_DEPTH_CHECK\n\
  81. float getGlobeDepth(vec4 positionEC)\n\
  82. {\n\
  83. vec4 posWC = czm_eyeToWindowCoordinates(positionEC);\n\
  84. float globeDepth = czm_unpackDepth(texture2D(czm_globeDepthTexture, posWC.xy / czm_viewport.zw));\n\
  85. if (globeDepth == 0.0)\n\
  86. {\n\
  87. return 0.0;\n\
  88. }\n\
  89. vec4 eyeCoordinate = czm_windowToEyeCoordinates(posWC.xy, globeDepth);\n\
  90. return eyeCoordinate.z / eyeCoordinate.w;\n\
  91. }\n\
  92. #endif\n\
  93. void main()\n\
  94. {\n\
  95. vec3 positionHigh = positionHighAndScale.xyz;\n\
  96. vec3 positionLow = positionLowAndRotation.xyz;\n\
  97. float scale = positionHighAndScale.w;\n\
  98. #if defined(ROTATION) || defined(ALIGNED_AXIS)\n\
  99. float rotation = positionLowAndRotation.w;\n\
  100. #else\n\
  101. float rotation = 0.0;\n\
  102. #endif\n\
  103. float compressed = compressedAttribute0.x;\n\
  104. vec2 pixelOffset;\n\
  105. pixelOffset.x = floor(compressed * SHIFT_RIGHT7);\n\
  106. compressed -= pixelOffset.x * SHIFT_LEFT7;\n\
  107. pixelOffset.x -= UPPER_BOUND;\n\
  108. vec2 origin;\n\
  109. origin.x = floor(compressed * SHIFT_RIGHT5);\n\
  110. compressed -= origin.x * SHIFT_LEFT5;\n\
  111. origin.y = floor(compressed * SHIFT_RIGHT3);\n\
  112. compressed -= origin.y * SHIFT_LEFT3;\n\
  113. #ifdef FRAGMENT_DEPTH_CHECK\n\
  114. vec2 depthOrigin = origin.xy;\n\
  115. #endif\n\
  116. origin -= vec2(1.0);\n\
  117. float show = floor(compressed * SHIFT_RIGHT2);\n\
  118. compressed -= show * SHIFT_LEFT2;\n\
  119. #ifdef INSTANCED\n\
  120. vec2 textureCoordinatesBottomLeft = czm_decompressTextureCoordinates(compressedAttribute0.w);\n\
  121. vec2 textureCoordinatesRange = czm_decompressTextureCoordinates(eyeOffset.w);\n\
  122. vec2 textureCoordinates = textureCoordinatesBottomLeft + direction * textureCoordinatesRange;\n\
  123. #else\n\
  124. vec2 direction;\n\
  125. direction.x = floor(compressed * SHIFT_RIGHT1);\n\
  126. direction.y = compressed - direction.x * SHIFT_LEFT1;\n\
  127. vec2 textureCoordinates = czm_decompressTextureCoordinates(compressedAttribute0.w);\n\
  128. #endif\n\
  129. float temp = compressedAttribute0.y * SHIFT_RIGHT8;\n\
  130. pixelOffset.y = -(floor(temp) - UPPER_BOUND);\n\
  131. vec2 translate;\n\
  132. translate.y = (temp - floor(temp)) * SHIFT_LEFT16;\n\
  133. temp = compressedAttribute0.z * SHIFT_RIGHT8;\n\
  134. translate.x = floor(temp) - UPPER_BOUND;\n\
  135. translate.y += (temp - floor(temp)) * SHIFT_LEFT8;\n\
  136. translate.y -= UPPER_BOUND;\n\
  137. temp = compressedAttribute1.x * SHIFT_RIGHT8;\n\
  138. float temp2 = floor(compressedAttribute2.w * SHIFT_RIGHT2);\n\
  139. vec2 imageSize = vec2(floor(temp), temp2);\n\
  140. #ifdef FRAGMENT_DEPTH_CHECK\n\
  141. float labelHorizontalOrigin = floor(compressedAttribute2.w - (temp2 * SHIFT_LEFT2));\n\
  142. float applyTranslate = 0.0;\n\
  143. if (labelHorizontalOrigin != 0.0)\n\
  144. {\n\
  145. applyTranslate = 1.0;\n\
  146. labelHorizontalOrigin -= 2.0;\n\
  147. depthOrigin.x = labelHorizontalOrigin + 1.0;\n\
  148. }\n\
  149. depthOrigin = vec2(1.0) - (depthOrigin * 0.5);\n\
  150. #endif\n\
  151. #ifdef EYE_DISTANCE_TRANSLUCENCY\n\
  152. vec4 translucencyByDistance;\n\
  153. translucencyByDistance.x = compressedAttribute1.z;\n\
  154. translucencyByDistance.z = compressedAttribute1.w;\n\
  155. translucencyByDistance.y = ((temp - floor(temp)) * SHIFT_LEFT8) / 255.0;\n\
  156. temp = compressedAttribute1.y * SHIFT_RIGHT8;\n\
  157. translucencyByDistance.w = ((temp - floor(temp)) * SHIFT_LEFT8) / 255.0;\n\
  158. #endif\n\
  159. #if defined(VERTEX_DEPTH_CHECK) || defined(FRAGMENT_DEPTH_CHECK)\n\
  160. temp = compressedAttribute3.w;\n\
  161. temp = temp * SHIFT_RIGHT12;\n\
  162. vec2 dimensions;\n\
  163. dimensions.y = (temp - floor(temp)) * SHIFT_LEFT12;\n\
  164. dimensions.x = floor(temp);\n\
  165. #endif\n\
  166. #ifdef ALIGNED_AXIS\n\
  167. vec3 alignedAxis = czm_octDecode(floor(compressedAttribute1.y * SHIFT_RIGHT8));\n\
  168. temp = compressedAttribute2.z * SHIFT_RIGHT5;\n\
  169. bool validAlignedAxis = (temp - floor(temp)) * SHIFT_LEFT1 > 0.0;\n\
  170. #else\n\
  171. vec3 alignedAxis = vec3(0.0);\n\
  172. bool validAlignedAxis = false;\n\
  173. #endif\n\
  174. vec4 pickColor;\n\
  175. vec4 color;\n\
  176. temp = compressedAttribute2.y;\n\
  177. temp = temp * SHIFT_RIGHT8;\n\
  178. pickColor.b = (temp - floor(temp)) * SHIFT_LEFT8;\n\
  179. temp = floor(temp) * SHIFT_RIGHT8;\n\
  180. pickColor.g = (temp - floor(temp)) * SHIFT_LEFT8;\n\
  181. pickColor.r = floor(temp);\n\
  182. temp = compressedAttribute2.x;\n\
  183. temp = temp * SHIFT_RIGHT8;\n\
  184. color.b = (temp - floor(temp)) * SHIFT_LEFT8;\n\
  185. temp = floor(temp) * SHIFT_RIGHT8;\n\
  186. color.g = (temp - floor(temp)) * SHIFT_LEFT8;\n\
  187. color.r = floor(temp);\n\
  188. temp = compressedAttribute2.z * SHIFT_RIGHT8;\n\
  189. bool sizeInMeters = floor((temp - floor(temp)) * SHIFT_LEFT7) > 0.0;\n\
  190. temp = floor(temp) * SHIFT_RIGHT8;\n\
  191. pickColor.a = (temp - floor(temp)) * SHIFT_LEFT8;\n\
  192. pickColor /= 255.0;\n\
  193. color.a = floor(temp);\n\
  194. color /= 255.0;\n\
  195. vec4 p = czm_translateRelativeToEye(positionHigh, positionLow);\n\
  196. vec4 positionEC = czm_modelViewRelativeToEye * p;\n\
  197. #if defined(FRAGMENT_DEPTH_CHECK) || defined(VERTEX_DEPTH_CHECK)\n\
  198. float eyeDepth = positionEC.z;\n\
  199. #endif\n\
  200. positionEC = czm_eyeOffset(positionEC, eyeOffset.xyz);\n\
  201. positionEC.xyz *= show;\n\
  202. #if defined(EYE_DISTANCE_SCALING) || defined(EYE_DISTANCE_TRANSLUCENCY) || defined(EYE_DISTANCE_PIXEL_OFFSET) || defined(DISTANCE_DISPLAY_CONDITION) || defined(DISABLE_DEPTH_DISTANCE)\n\
  203. float lengthSq;\n\
  204. if (czm_sceneMode == czm_sceneMode2D)\n\
  205. {\n\
  206. lengthSq = czm_eyeHeight2D.y;\n\
  207. }\n\
  208. else\n\
  209. {\n\
  210. lengthSq = dot(positionEC.xyz, positionEC.xyz);\n\
  211. }\n\
  212. #endif\n\
  213. #ifdef EYE_DISTANCE_SCALING\n\
  214. float distanceScale = czm_nearFarScalar(scaleByDistance, lengthSq);\n\
  215. scale *= distanceScale;\n\
  216. translate *= distanceScale;\n\
  217. if (scale == 0.0)\n\
  218. {\n\
  219. positionEC.xyz = vec3(0.0);\n\
  220. }\n\
  221. #endif\n\
  222. float translucency = 1.0;\n\
  223. #ifdef EYE_DISTANCE_TRANSLUCENCY\n\
  224. translucency = czm_nearFarScalar(translucencyByDistance, lengthSq);\n\
  225. if (translucency == 0.0)\n\
  226. {\n\
  227. positionEC.xyz = vec3(0.0);\n\
  228. }\n\
  229. #endif\n\
  230. #ifdef EYE_DISTANCE_PIXEL_OFFSET\n\
  231. float pixelOffsetScale = czm_nearFarScalar(pixelOffsetScaleByDistance, lengthSq);\n\
  232. pixelOffset *= pixelOffsetScale;\n\
  233. #endif\n\
  234. #ifdef DISTANCE_DISPLAY_CONDITION\n\
  235. float nearSq = compressedAttribute3.x;\n\
  236. float farSq = compressedAttribute3.y;\n\
  237. if (lengthSq < nearSq || lengthSq > farSq)\n\
  238. {\n\
  239. positionEC.xyz = vec3(0.0);\n\
  240. }\n\
  241. #endif\n\
  242. mat2 rotationMatrix;\n\
  243. float mpp;\n\
  244. #ifdef DISABLE_DEPTH_DISTANCE\n\
  245. float disableDepthTestDistance = compressedAttribute3.z;\n\
  246. #endif\n\
  247. #ifdef VERTEX_DEPTH_CHECK\n\
  248. if (lengthSq < disableDepthTestDistance) {\n\
  249. float depthsilon = 10.0;\n\
  250. vec2 labelTranslate = textureCoordinateBoundsOrLabelTranslate.xy;\n\
  251. vec4 pEC1 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(0.0), origin, labelTranslate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);\n\
  252. float globeDepth1 = getGlobeDepth(pEC1);\n\
  253. if (globeDepth1 != 0.0 && pEC1.z + depthsilon < globeDepth1)\n\
  254. {\n\
  255. vec4 pEC2 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(0.0, 1.0), origin, labelTranslate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);\n\
  256. float globeDepth2 = getGlobeDepth(pEC2);\n\
  257. if (globeDepth2 != 0.0 && pEC2.z + depthsilon < globeDepth2)\n\
  258. {\n\
  259. vec4 pEC3 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(1.0), origin, labelTranslate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);\n\
  260. float globeDepth3 = getGlobeDepth(pEC3);\n\
  261. if (globeDepth3 != 0.0 && pEC3.z + depthsilon < globeDepth3)\n\
  262. {\n\
  263. positionEC.xyz = vec3(0.0);\n\
  264. }\n\
  265. }\n\
  266. }\n\
  267. }\n\
  268. #endif\n\
  269. positionEC = addScreenSpaceOffset(positionEC, imageSize, scale, direction, origin, translate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);\n\
  270. gl_Position = czm_projection * positionEC;\n\
  271. v_textureCoordinates = textureCoordinates;\n\
  272. #ifdef LOG_DEPTH\n\
  273. czm_vertexLogDepth();\n\
  274. #endif\n\
  275. #ifdef DISABLE_DEPTH_DISTANCE\n\
  276. if (disableDepthTestDistance == 0.0 && czm_minimumDisableDepthTestDistance != 0.0)\n\
  277. {\n\
  278. disableDepthTestDistance = czm_minimumDisableDepthTestDistance;\n\
  279. }\n\
  280. if (disableDepthTestDistance != 0.0)\n\
  281. {\n\
  282. float zclip = gl_Position.z / gl_Position.w;\n\
  283. bool clipped = (zclip < -1.0 || zclip > 1.0);\n\
  284. if (!clipped && (disableDepthTestDistance < 0.0 || (lengthSq > 0.0 && lengthSq < disableDepthTestDistance)))\n\
  285. {\n\
  286. gl_Position.z = -gl_Position.w;\n\
  287. #ifdef LOG_DEPTH\n\
  288. czm_vertexLogDepth(vec4(czm_currentFrustum.x));\n\
  289. #endif\n\
  290. }\n\
  291. }\n\
  292. #endif\n\
  293. #ifdef FRAGMENT_DEPTH_CHECK\n\
  294. if (sizeInMeters) {\n\
  295. translate /= mpp;\n\
  296. dimensions /= mpp;\n\
  297. imageSize /= mpp;\n\
  298. }\n\
  299. #if defined(ROTATION) || defined(ALIGNED_AXIS)\n\
  300. v_rotationMatrix = rotationMatrix;\n\
  301. #else\n\
  302. v_rotationMatrix = mat2(1.0, 0.0, 0.0, 1.0);\n\
  303. #endif\n\
  304. float enableDepthCheck = 0.0;\n\
  305. if (lengthSq < disableDepthTestDistance)\n\
  306. {\n\
  307. enableDepthCheck = 1.0;\n\
  308. }\n\
  309. float dw = floor(clamp(dimensions.x, 0.0, SHIFT_LEFT12));\n\
  310. float dh = floor(clamp(dimensions.y, 0.0, SHIFT_LEFT12));\n\
  311. float iw = floor(clamp(imageSize.x, 0.0, SHIFT_LEFT12));\n\
  312. float ih = floor(clamp(imageSize.y, 0.0, SHIFT_LEFT12));\n\
  313. v_compressed.x = eyeDepth;\n\
  314. v_compressed.y = applyTranslate * SHIFT_LEFT1 + enableDepthCheck;\n\
  315. v_compressed.z = dw * SHIFT_LEFT12 + dh;\n\
  316. v_compressed.w = iw * SHIFT_LEFT12 + ih;\n\
  317. v_originTextureCoordinateAndTranslate.xy = depthOrigin;\n\
  318. v_originTextureCoordinateAndTranslate.zw = translate;\n\
  319. v_textureCoordinateBounds = textureCoordinateBoundsOrLabelTranslate;\n\
  320. #endif\n\
  321. #ifdef SDF\n\
  322. vec4 outlineColor;\n\
  323. float outlineWidth;\n\
  324. temp = sdf.x;\n\
  325. temp = temp * SHIFT_RIGHT8;\n\
  326. outlineColor.b = (temp - floor(temp)) * SHIFT_LEFT8;\n\
  327. temp = floor(temp) * SHIFT_RIGHT8;\n\
  328. outlineColor.g = (temp - floor(temp)) * SHIFT_LEFT8;\n\
  329. outlineColor.r = floor(temp);\n\
  330. temp = sdf.y;\n\
  331. temp = temp * SHIFT_RIGHT8;\n\
  332. float temp3 = (temp - floor(temp)) * SHIFT_LEFT8;\n\
  333. temp = floor(temp) * SHIFT_RIGHT8;\n\
  334. outlineWidth = (temp - floor(temp)) * SHIFT_LEFT8;\n\
  335. outlineColor.a = floor(temp);\n\
  336. outlineColor /= 255.0;\n\
  337. v_outlineWidth = outlineWidth / 255.0;\n\
  338. v_outlineColor = outlineColor;\n\
  339. #endif\n\
  340. v_pickColor = pickColor;\n\
  341. v_color = color;\n\
  342. v_color.a *= translucency;\n\
  343. }\n\
  344. ";