@cesium/engine 21.0.1 → 22.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. package/Build/ThirdParty/Workers/zip-web-worker.js +10 -7
  2. package/Build/Workers/chunk-23T2IPHV.js +55 -0
  3. package/Build/Workers/{chunk-TGJQMEL4.js → chunk-2AM4E2WD.js} +2 -2
  4. package/Build/Workers/{chunk-4CORGH7N.js → chunk-2MWF4IES.js} +16 -14
  5. package/Build/Workers/{chunk-3RKX3UFI.js → chunk-2RCIRXNI.js} +1 -1
  6. package/Build/Workers/{chunk-LV3G32QE.js → chunk-3YTMGEXW.js} +5 -1424
  7. package/Build/Workers/{chunk-PJAA7QSC.js → chunk-4BHWJWS3.js} +6 -6
  8. package/Build/Workers/{chunk-FE565QHX.js → chunk-5JKH4AMT.js} +2 -2
  9. package/Build/Workers/{chunk-KZ7GDSAJ.js → chunk-6HKAPCSO.js} +1 -1
  10. package/Build/Workers/{chunk-VVALNLSH.js → chunk-A53R2F2L.js} +4 -4
  11. package/Build/Workers/{chunk-KVB73ECP.js → chunk-A6YFUGJO.js} +7 -7
  12. package/Build/Workers/{chunk-QNOIRRJK.js → chunk-AJYWXC6I.js} +4 -4
  13. package/Build/Workers/{chunk-UKA7OISV.js → chunk-AOIO5VUS.js} +282 -2284
  14. package/Build/Workers/{chunk-OBS5EMZ6.js → chunk-B7JRBTT6.js} +10 -10
  15. package/Build/Workers/{chunk-5YXA47QD.js → chunk-CHNDJRYA.js} +20 -18
  16. package/Build/Workers/{chunk-X3ZV3XNO.js → chunk-CJOV55CW.js} +20 -18
  17. package/Build/Workers/{chunk-W6I3LNPF.js → chunk-COGPE5Z2.js} +10 -8
  18. package/Build/Workers/{chunk-2QPH5QDK.js → chunk-CW7W27IZ.js} +14 -10
  19. package/Build/Workers/{chunk-MXOGBWMP.js → chunk-DICY26ID.js} +20 -16
  20. package/Build/Workers/{chunk-W6KMV4F5.js → chunk-DMEFNTUV.js} +69 -7
  21. package/Build/Workers/{chunk-T7HU6E7G.js → chunk-DQSJEOZY.js} +1 -1
  22. package/Build/Workers/{chunk-ASVODZNK.js → chunk-GDU4RZSZ.js} +16 -36
  23. package/Build/Workers/{chunk-MQPDOWGH.js → chunk-GKWOUMYA.js} +1 -1
  24. package/Build/Workers/{chunk-A2SP2EJZ.js → chunk-GTY4K4IA.js} +9 -7
  25. package/Build/Workers/{chunk-KEPPNSBL.js → chunk-H6Q7E4BQ.js} +8 -6
  26. package/Build/Workers/{chunk-JG3C3LPY.js → chunk-HHGOFZVQ.js} +7 -5
  27. package/Build/Workers/chunk-HXKUEOOD.js +352 -0
  28. package/Build/Workers/{chunk-UFSYRVC5.js → chunk-I4REFVXB.js} +4 -4
  29. package/Build/Workers/{chunk-LU7DLY2L.js → chunk-IL5F6WEE.js} +3 -3
  30. package/Build/Workers/{chunk-RVRN4KDB.js → chunk-JKXPC5HD.js} +2 -2
  31. package/Build/Workers/{chunk-CBPNIEGH.js → chunk-KKGD7HAW.js} +13 -11
  32. package/Build/Workers/{chunk-DTKSVIH5.js → chunk-KROSQJUA.js} +2 -2
  33. package/Build/Workers/{chunk-42EJCSIV.js → chunk-L4JLDVCM.js} +5 -5
  34. package/Build/Workers/{chunk-LPKJSIMD.js → chunk-LIYMRHGR.js} +15 -13
  35. package/Build/Workers/{chunk-J2XQVKVH.js → chunk-MKMZHRB3.js} +74 -35
  36. package/Build/Workers/{chunk-CSDYSXBI.js → chunk-MO25ZQ2I.js} +14 -12
  37. package/Build/Workers/{chunk-3YNW5K6O.js → chunk-O6RZEKHZ.js} +12 -12
  38. package/Build/Workers/{chunk-RR3NCT4R.js → chunk-OOCGX2OD.js} +4 -4
  39. package/Build/Workers/{chunk-XG54SG4O.js → chunk-OXFU5HNU.js} +13 -5
  40. package/Build/Workers/{chunk-P2UKEFCK.js → chunk-P5CGIJUY.js} +2 -2
  41. package/Build/Workers/{chunk-DBHL2UVG.js → chunk-QEANVUGT.js} +2 -2
  42. package/Build/Workers/{chunk-2SI7DEW5.js → chunk-QFBCIX7J.js} +8 -6
  43. package/Build/Workers/{chunk-DDXI6UYW.js → chunk-QUAH3XOT.js} +4 -4
  44. package/Build/Workers/{chunk-PZUZCAX3.js → chunk-RXZDTDIY.js} +13 -9
  45. package/Build/Workers/{chunk-YZ3RCE45.js → chunk-SPA2KPH3.js} +14 -12
  46. package/Build/Workers/chunk-TDSVSW5A.js +1460 -0
  47. package/Build/Workers/{chunk-G3CKZ34K.js → chunk-UG2DPFOL.js} +8 -6
  48. package/Build/Workers/{chunk-IKUOV6DO.js → chunk-URGEDZBS.js} +7 -7
  49. package/Build/Workers/{chunk-U2GR5FDL.js → chunk-V35NQOJC.js} +21 -11
  50. package/Build/Workers/chunk-W4XUEDU5.js +2058 -0
  51. package/Build/Workers/chunk-WB4TSSBQ.js +3514 -0
  52. package/Build/Workers/{chunk-EBDZDBJN.js → chunk-WTLYD4FE.js} +19 -15
  53. package/Build/Workers/{chunk-WQZL6CA2.js → chunk-Y4ALZ4SS.js} +9 -7
  54. package/Build/Workers/{chunk-DAJKOQW6.js → chunk-YF2NVO5B.js} +19 -13
  55. package/Build/Workers/{chunk-XJVRYJVZ.js → chunk-YSYSXSHF.js} +1 -1
  56. package/Build/Workers/{chunk-YNOVMSUX.js → chunk-YX562XOB.js} +15 -11
  57. package/Build/Workers/{chunk-J3KPR6DJ.js → chunk-YZWA5B4R.js} +15 -13
  58. package/Build/Workers/{chunk-NYYQZ3LH.js → chunk-Z6DFT4D3.js} +15 -11
  59. package/Build/Workers/combineGeometry.js +24 -21
  60. package/Build/Workers/createBoxGeometry.js +18 -15
  61. package/Build/Workers/createBoxOutlineGeometry.js +16 -13
  62. package/Build/Workers/createCircleGeometry.js +28 -24
  63. package/Build/Workers/createCircleOutlineGeometry.js +21 -17
  64. package/Build/Workers/createCoplanarPolygonGeometry.js +35 -31
  65. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +33 -29
  66. package/Build/Workers/createCorridorGeometry.js +32 -28
  67. package/Build/Workers/createCorridorOutlineGeometry.js +30 -26
  68. package/Build/Workers/createCylinderGeometry.js +20 -17
  69. package/Build/Workers/createCylinderOutlineGeometry.js +20 -16
  70. package/Build/Workers/createEllipseGeometry.js +28 -24
  71. package/Build/Workers/createEllipseOutlineGeometry.js +21 -17
  72. package/Build/Workers/createEllipsoidGeometry.js +19 -16
  73. package/Build/Workers/createEllipsoidOutlineGeometry.js +18 -15
  74. package/Build/Workers/createFrustumGeometry.js +18 -15
  75. package/Build/Workers/createFrustumOutlineGeometry.js +18 -15
  76. package/Build/Workers/createGeometry.js +28 -22
  77. package/Build/Workers/createGroundPolylineGeometry.js +25 -21
  78. package/Build/Workers/createPlaneGeometry.js +16 -13
  79. package/Build/Workers/createPlaneOutlineGeometry.js +15 -12
  80. package/Build/Workers/createPolygonGeometry.js +35 -31
  81. package/Build/Workers/createPolygonOutlineGeometry.js +32 -28
  82. package/Build/Workers/createPolylineGeometry.js +27 -23
  83. package/Build/Workers/createPolylineVolumeGeometry.js +33 -29
  84. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +29 -25
  85. package/Build/Workers/createRectangleGeometry.js +30 -26
  86. package/Build/Workers/createRectangleOutlineGeometry.js +23 -19
  87. package/Build/Workers/createSimplePolylineGeometry.js +25 -21
  88. package/Build/Workers/createSphereGeometry.js +19 -16
  89. package/Build/Workers/createSphereOutlineGeometry.js +18 -15
  90. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  91. package/Build/Workers/createVectorTileClampedPolylines.js +16 -13
  92. package/Build/Workers/createVectorTileGeometries.js +24 -21
  93. package/Build/Workers/createVectorTilePoints.js +15 -12
  94. package/Build/Workers/createVectorTilePolygons.js +24 -20
  95. package/Build/Workers/createVectorTilePolylines.js +16 -13
  96. package/Build/Workers/createVerticesFromCesium3DTilesTerrain.js +91 -0
  97. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +28 -23
  98. package/Build/Workers/createVerticesFromHeightmap.js +28 -23
  99. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +26 -279
  100. package/Build/Workers/createWallGeometry.js +26 -22
  101. package/Build/Workers/createWallOutlineGeometry.js +25 -21
  102. package/Build/Workers/decodeDraco.js +10 -10
  103. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
  104. package/Build/Workers/decodeI3S.js +13 -11
  105. package/Build/Workers/gaussianSplatSorter.js +4 -4
  106. package/Build/Workers/gaussianSplatTextureGenerator.js +4 -4
  107. package/Build/Workers/incrementallyBuildTerrainPicker.js +121 -0
  108. package/Build/Workers/transcodeKTX2.js +6 -6
  109. package/Build/Workers/transferTypedArrayTest.js +1 -1
  110. package/Build/Workers/upsampleQuantizedTerrainMesh.js +24 -20
  111. package/Build/Workers/upsampleVerticesFromCesium3DTilesTerrain.js +95 -0
  112. package/Source/Core/ArcGISTiledElevationTerrainProvider.js +2 -2
  113. package/Source/Core/AxisAlignedBoundingBox.js +36 -0
  114. package/Source/Core/Cesium3DTilesTerrainData.js +932 -0
  115. package/Source/Core/Cesium3DTilesTerrainGeometryProcessor.js +1868 -0
  116. package/Source/Core/Cesium3DTilesTerrainProvider.js +1052 -0
  117. package/Source/Core/CesiumTerrainProvider.js +2 -2
  118. package/Source/Core/Color.js +23 -6
  119. package/Source/Core/EllipsoidalOccluder.js +2 -2
  120. package/Source/Core/FeatureDetection.js +0 -2
  121. package/Source/Core/GoogleEarthEnterpriseMetadata.js +1 -1
  122. package/Source/Core/GoogleEarthEnterpriseTerrainData.js +2 -1
  123. package/Source/Core/GoogleEarthEnterpriseTerrainProvider.js +1 -1
  124. package/Source/Core/HeightmapTerrainData.js +12 -22
  125. package/Source/Core/HilbertOrder.js +0 -6
  126. package/Source/Core/ITwinPlatform.js +6 -6
  127. package/Source/Core/IntersectionTests.js +80 -0
  128. package/Source/Core/Ion.js +1 -1
  129. package/Source/Core/IonResource.js +35 -27
  130. package/Source/Core/PixelFormat.js +2 -2
  131. package/Source/Core/QuantizedMeshTerrainData.js +24 -57
  132. package/Source/Core/Resource.js +15 -11
  133. package/Source/Core/S2Cell.js +6 -18
  134. package/Source/Core/TaskProcessor.js +1 -1
  135. package/Source/Core/TerrainData.js +2 -1
  136. package/Source/Core/TerrainEncoding.js +215 -38
  137. package/Source/Core/TerrainMesh.js +215 -8
  138. package/Source/Core/TerrainPicker.js +607 -0
  139. package/Source/Core/TerrainProvider.js +151 -0
  140. package/Source/Core/TexturePacker.js +27 -12
  141. package/Source/Core/Transforms.js +28 -19
  142. package/Source/Core/VRTheWorldTerrainProvider.js +2 -2
  143. package/Source/Core/binarySearch.js +1 -1
  144. package/Source/Core/createWorldBathymetryAsync.js +2 -2
  145. package/Source/Core/createWorldTerrainAsync.js +3 -3
  146. package/Source/Core/loadImageFromTypedArray.js +9 -3
  147. package/Source/Core/mergeSort.js +1 -1
  148. package/Source/DataSources/BillboardGraphics.js +1 -1
  149. package/Source/DataSources/BillboardVisualizer.js +7 -4
  150. package/Source/DataSources/PropertyArray.js +2 -2
  151. package/Source/Renderer/AutomaticUniforms.js +61 -0
  152. package/Source/Renderer/Buffer.js +32 -0
  153. package/Source/Renderer/BufferUsage.js +3 -1
  154. package/Source/Renderer/Context.js +98 -14
  155. package/Source/Renderer/Pass.js +10 -9
  156. package/Source/Renderer/Sync.js +104 -0
  157. package/Source/Renderer/TextureAtlas.js +67 -27
  158. package/Source/Renderer/UniformState.js +12 -0
  159. package/Source/Renderer/VertexArray.js +1 -1
  160. package/Source/Scene/ArcGisMapServerImageryProvider.js +1 -1
  161. package/Source/Scene/ArcGisMapService.js +1 -1
  162. package/Source/Scene/Azure2DImageryProvider.js +99 -13
  163. package/Source/Scene/BatchTable.js +2 -2
  164. package/Source/Scene/Billboard.js +75 -28
  165. package/Source/Scene/BillboardCollection.js +24 -15
  166. package/Source/Scene/BillboardTexture.js +56 -7
  167. package/Source/Scene/BingMapsImageryProvider.js +1 -1
  168. package/Source/Scene/BoundingVolumeSemantics.js +54 -62
  169. package/Source/Scene/Cesium3DTile.js +3 -3
  170. package/Source/Scene/Cesium3DTilesVoxelProvider.js +1 -1
  171. package/Source/Scene/Cesium3DTileset.js +1 -1
  172. package/Source/Scene/EdgeFramebuffer.js +245 -0
  173. package/Source/Scene/FrameState.js +12 -0
  174. package/Source/Scene/GaussianSplat3DTileContent.js +12 -16
  175. package/Source/Scene/GaussianSplatPrimitive.js +12 -8
  176. package/Source/Scene/GaussianSplatSorter.js +2 -2
  177. package/Source/Scene/Globe.js +4 -2
  178. package/Source/Scene/GlobeSurfaceTile.js +28 -70
  179. package/Source/Scene/GlobeSurfaceTileProvider.js +11 -0
  180. package/Source/Scene/GltfBufferViewLoader.js +18 -0
  181. package/Source/Scene/GltfLoader.js +46 -8
  182. package/Source/Scene/Google2DImageryProvider.js +48 -41
  183. package/Source/Scene/GoogleEarthEnterpriseMapsProvider.js +1 -1
  184. package/Source/Scene/I3SDataProvider.js +1 -1
  185. package/Source/Scene/I3SDecoder.js +3 -3
  186. package/Source/Scene/ITwinData.js +4 -4
  187. package/Source/Scene/ImageryLayer.js +1 -1
  188. package/Source/Scene/Implicit3DTileContent.js +18 -7
  189. package/Source/Scene/ImplicitSubtree.js +3 -3
  190. package/Source/Scene/ImplicitTileset.js +2 -2
  191. package/Source/Scene/IonImageryProvider.js +15 -84
  192. package/Source/Scene/IonImageryProviderFactory.js +194 -0
  193. package/Source/Scene/LabelCollection.js +54 -36
  194. package/Source/Scene/MetadataComponentType.js +5 -5
  195. package/Source/Scene/MetadataTableProperty.js +3 -9
  196. package/Source/Scene/Model/EdgeDetectionPipelineStage.js +42 -0
  197. package/Source/Scene/Model/EdgeVisibilityPipelineStage.js +800 -0
  198. package/Source/Scene/Model/MetadataPipelineStage.js +7 -7
  199. package/Source/Scene/Model/ModelDrawCommand.js +69 -0
  200. package/Source/Scene/Model/ModelImagery.js +4 -0
  201. package/Source/Scene/Model/ModelRuntimeNode.js +2 -2
  202. package/Source/Scene/Model/ModelRuntimePrimitive.js +13 -2
  203. package/Source/Scene/Model/ModelSceneGraph.js +15 -3
  204. package/Source/Scene/Model/ModelUtility.js +0 -1
  205. package/Source/Scene/Model/NodeRenderResources.js +1 -1
  206. package/Source/Scene/Model/PrimitiveRenderResources.js +1 -1
  207. package/Source/Scene/OIT.js +11 -1
  208. package/Source/Scene/PickFramebuffer.js +134 -50
  209. package/Source/Scene/Picking.js +195 -89
  210. package/Source/Scene/QuadtreePrimitive.js +34 -26
  211. package/Source/Scene/QuadtreeTile.js +66 -46
  212. package/Source/Scene/ResourceLoaderState.js +1 -1
  213. package/Source/Scene/Scene.js +160 -16
  214. package/Source/Scene/ScreenSpaceCameraController.js +1 -1
  215. package/Source/Scene/SensorVolumePortionToDisplay.js +6 -6
  216. package/Source/Scene/SingleTileImageryProvider.js +3 -3
  217. package/Source/Scene/Terrain.js +5 -5
  218. package/Source/Scene/TerrainFillMesh.js +1 -0
  219. package/Source/Scene/TileMapServiceImageryProvider.js +2 -2
  220. package/Source/Scene/UrlTemplateImageryProvider.js +1 -1
  221. package/Source/Scene/View.js +3 -0
  222. package/Source/Scene/VoxelPrimitive.js +196 -189
  223. package/Source/Scene/VoxelShape.js +2 -0
  224. package/Source/Scene/createWorldImageryAsync.js +1 -1
  225. package/Source/Shaders/BillboardCollectionFS.glsl +115 -62
  226. package/Source/Shaders/BillboardCollectionFS.js +115 -63
  227. package/Source/Shaders/BillboardCollectionVS.glsl +44 -37
  228. package/Source/Shaders/BillboardCollectionVS.js +45 -38
  229. package/Source/Shaders/Builtin/Constants/passCesium3DTile.glsl +1 -1
  230. package/Source/Shaders/Builtin/Constants/passCesium3DTile.js +1 -1
  231. package/Source/Shaders/Builtin/Constants/passCesium3DTileClassification.glsl +1 -1
  232. package/Source/Shaders/Builtin/Constants/passCesium3DTileClassification.js +1 -1
  233. package/Source/Shaders/Builtin/Constants/passCesium3DTileClassificationIgnoreShow.glsl +1 -1
  234. package/Source/Shaders/Builtin/Constants/passCesium3DTileClassificationIgnoreShow.js +1 -1
  235. package/Source/Shaders/Builtin/Constants/passCesium3DTileEdges.glsl +10 -0
  236. package/Source/Shaders/Builtin/Constants/passCesium3DTileEdges.js +12 -0
  237. package/Source/Shaders/Builtin/Constants/passGaussianSplats.glsl +1 -1
  238. package/Source/Shaders/Builtin/Constants/passGaussianSplats.js +1 -1
  239. package/Source/Shaders/Builtin/Constants/passOpaque.glsl +1 -1
  240. package/Source/Shaders/Builtin/Constants/passOpaque.js +1 -1
  241. package/Source/Shaders/Builtin/Constants/passOverlay.glsl +1 -1
  242. package/Source/Shaders/Builtin/Constants/passOverlay.js +1 -1
  243. package/Source/Shaders/Builtin/Constants/passTranslucent.glsl +1 -1
  244. package/Source/Shaders/Builtin/Constants/passTranslucent.js +1 -1
  245. package/Source/Shaders/Builtin/Constants/passVoxels.glsl +1 -1
  246. package/Source/Shaders/Builtin/Constants/passVoxels.js +1 -1
  247. package/Source/Shaders/Builtin/CzmBuiltins.js +2 -0
  248. package/Source/Shaders/GlobeVS.glsl +1 -1
  249. package/Source/Shaders/GlobeVS.js +1 -1
  250. package/Source/Shaders/Model/EdgeDetectionStageFS.glsl +58 -0
  251. package/Source/Shaders/Model/EdgeDetectionStageFS.js +60 -0
  252. package/Source/Shaders/Model/EdgeVisibilityStageFS.glsl +83 -0
  253. package/Source/Shaders/Model/EdgeVisibilityStageFS.js +85 -0
  254. package/Source/Shaders/Model/ModelFS.glsl +5 -0
  255. package/Source/Shaders/Model/ModelFS.js +5 -0
  256. package/Source/Shaders/Model/PrimitiveOutlineStageFS.glsl +0 -1
  257. package/Source/Shaders/Model/PrimitiveOutlineStageFS.js +0 -1
  258. package/Source/Shaders/ShadowVolumeAppearanceFS.glsl +7 -15
  259. package/Source/Shaders/ShadowVolumeAppearanceFS.js +7 -15
  260. package/Source/ThirdParty/Workers/zip-web-worker.js +1 -1
  261. package/Source/ThirdParty/zip-module.wasm +0 -0
  262. package/Source/Workers/createVerticesFromCesium3DTilesTerrain.js +46 -0
  263. package/Source/Workers/incrementallyBuildTerrainPicker.js +108 -0
  264. package/Source/Workers/upsampleVerticesFromCesium3DTilesTerrain.js +55 -0
  265. package/index.d.ts +488 -31
  266. package/index.js +202 -190
  267. package/package.json +3 -2
@@ -1,4 +1,6 @@
1
1
  uniform sampler2D u_atlas;
2
+ uniform float u_coarseDepthTestDistance;
3
+ uniform float u_threePointDepthTestDistance;
2
4
 
3
5
  #ifdef VECTOR_TILE
4
6
  uniform vec4 u_highlightColor;
@@ -14,18 +16,33 @@ in vec4 v_outlineColor;
14
16
  in float v_outlineWidth;
15
17
  #endif
16
18
 
17
- #ifdef FRAGMENT_DEPTH_CHECK
19
+ in vec4 v_compressed; // x: eyeDepth, y: applyTranslate & enableDepthCheck, z: dimensions, w: imageSize
20
+ const float SHIFT_LEFT1 = 2.0;
21
+ const float SHIFT_RIGHT1 = 1.0 / 2.0;
22
+
23
+ #ifdef FS_THREE_POINT_DEPTH_CHECK
18
24
  in vec4 v_textureCoordinateBounds; // the min and max x and y values for the texture coordinates
19
25
  in vec4 v_originTextureCoordinateAndTranslate; // texture coordinate at the origin, billboard translate (used for label glyphs)
20
- in vec4 v_compressed; // x: eyeDepth, y: applyTranslate & enableDepthCheck, z: dimensions, w: imageSize
21
26
  in mat2 v_rotationMatrix;
22
27
 
23
28
  const float SHIFT_LEFT12 = 4096.0;
24
- const float SHIFT_LEFT1 = 2.0;
25
29
 
26
30
  const float SHIFT_RIGHT12 = 1.0 / 4096.0;
27
- const float SHIFT_RIGHT1 = 1.0 / 2.0;
31
+ #endif
32
+
33
+ float getGlobeDepthAtCoords(vec2 st)
34
+ {
35
+ float logDepthOrDepth = czm_unpackDepth(texture(czm_globeDepthTexture, st));
36
+ if (logDepthOrDepth == 0.0)
37
+ {
38
+ return 0.0; // not on the globe
39
+ }
40
+
41
+ vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, logDepthOrDepth);
42
+ return eyeCoordinate.z / eyeCoordinate.w;
43
+ }
28
44
 
45
+ #ifdef FS_THREE_POINT_DEPTH_CHECK
29
46
  float getGlobeDepth(vec2 adjustedST, vec2 depthLookupST, bool applyTranslate, vec2 dimensions, vec2 imageSize)
30
47
  {
31
48
  vec2 lookupVector = imageSize * (depthLookupST - adjustedST);
@@ -42,19 +59,10 @@ float getGlobeDepth(vec2 adjustedST, vec2 depthLookupST, bool applyTranslate, ve
42
59
  }
43
60
 
44
61
  vec2 st = ((lookupVector - translation + labelOffset) + gl_FragCoord.xy) / czm_viewport.zw;
45
- float logDepthOrDepth = czm_unpackDepth(texture(czm_globeDepthTexture, st));
46
-
47
- if (logDepthOrDepth == 0.0)
48
- {
49
- return 0.0; // not on the globe
50
- }
51
-
52
- vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, logDepthOrDepth);
53
- return eyeCoordinate.z / eyeCoordinate.w;
62
+ return getGlobeDepthAtCoords(st);
54
63
  }
55
64
  #endif
56
65
 
57
-
58
66
  #ifdef SDF
59
67
 
60
68
  // Get the distance from the edge of a glyph at a given position sampling an SDF texture.
@@ -85,11 +93,91 @@ vec4 getSDFColor(vec2 position, float outlineWidth, vec4 outlineColor, float smo
85
93
  }
86
94
  #endif
87
95
 
96
+ #ifdef FS_THREE_POINT_DEPTH_CHECK
97
+ void doThreePointDepthTest(float eyeDepth, bool applyTranslate) {
98
+
99
+ if (eyeDepth < -u_threePointDepthTestDistance) return;
100
+ float temp = v_compressed.z;
101
+ temp = temp * SHIFT_RIGHT12;
102
+
103
+ vec2 dimensions;
104
+ dimensions.y = (temp - floor(temp)) * SHIFT_LEFT12;
105
+ dimensions.x = floor(temp);
106
+
107
+ temp = v_compressed.w;
108
+ temp = temp * SHIFT_RIGHT12;
109
+
110
+ vec2 imageSize;
111
+ imageSize.y = (temp - floor(temp)) * SHIFT_LEFT12;
112
+ imageSize.x = floor(temp);
113
+
114
+ vec2 adjustedST = v_textureCoordinates - v_textureCoordinateBounds.xy;
115
+ adjustedST = adjustedST / vec2(v_textureCoordinateBounds.z - v_textureCoordinateBounds.x, v_textureCoordinateBounds.w - v_textureCoordinateBounds.y);
116
+
117
+ float epsilonEyeDepth = v_compressed.x + czm_epsilon1;
118
+ float globeDepth1 = getGlobeDepth(adjustedST, v_originTextureCoordinateAndTranslate.xy, applyTranslate, dimensions, imageSize);
119
+
120
+ // negative values go into the screen
121
+ if (globeDepth1 == 0.0 || globeDepth1 < epsilonEyeDepth) return;
122
+
123
+ float globeDepth2 = getGlobeDepth(adjustedST, vec2(0.0, 1.0), applyTranslate, dimensions, imageSize); // top left corner
124
+ if (globeDepth2 == 0.0 || globeDepth2 < epsilonEyeDepth) return;
125
+
126
+ float globeDepth3 = getGlobeDepth(adjustedST, vec2(1.0, 1.0), applyTranslate, dimensions, imageSize); // top right corner
127
+ if (globeDepth3 == 0.0 || globeDepth3 < epsilonEyeDepth) return;
128
+
129
+ // All three key points are occluded, discard the fragment (and by extension the entire billboard)
130
+ discard;
131
+ }
132
+ #endif
133
+
134
+ // Extra manual depth testing is done to allow more control over how a billboard is occluded
135
+ // by the globe when near and far from the camera.
136
+ void doDepthTest(float globeDepth) {
137
+ float temp = v_compressed.y;
138
+ temp = temp * SHIFT_RIGHT1;
139
+ float temp2 = (temp - floor(temp)) * SHIFT_LEFT1;
140
+ bool enableDepthCheck = temp2 != 0.0;
141
+ if (!enableDepthCheck) return;
142
+
143
+ float eyeDepth = v_compressed.x;
144
+
145
+ #ifdef FS_THREE_POINT_DEPTH_CHECK
146
+ // If the billboard is clamped to the ground and within a given distance, we do a 3-point depth test. This test is performed in the vertex shader, unless
147
+ // vertex texture sampling is not supported, in which case we do it here.
148
+ bool applyTranslate = floor(temp) != 0.0;
149
+ doThreePointDepthTest(eyeDepth, applyTranslate);
150
+
151
+ #elif defined(VS_THREE_POINT_DEPTH_CHECK)
152
+ // Since discarding vertices is not possible, the vertex shader sets eyeDepth to 0 to indicate the depth test failed. Apply the discard here.
153
+ if (eyeDepth > -u_threePointDepthTestDistance) {
154
+ if (eyeDepth == 0.0) {
155
+ discard;
156
+ }
157
+ return;
158
+ }
159
+ #endif
160
+
161
+ // If we're far away, we just compare against a flat, camera-facing depth-plane at the ellipsoid's center.
162
+ // If we're close, we compare against the globe depth texture (which includes depth from the 3D tile pass).
163
+
164
+ if (globeDepth == 0.0) return; // Not on globe
165
+ float distanceToEllipsoidCenter = -length(czm_viewerPositionWC); // depth is negative by convention
166
+ float testDistance = (eyeDepth > -u_coarseDepthTestDistance) ? globeDepth : distanceToEllipsoidCenter;
167
+ if (eyeDepth < testDistance) {
168
+ discard;
169
+ }
170
+ }
171
+
88
172
  void main()
89
173
  {
90
174
  if (v_splitDirection < 0.0 && gl_FragCoord.x > czm_splitPosition) discard;
91
175
  if (v_splitDirection > 0.0 && gl_FragCoord.x < czm_splitPosition) discard;
92
176
 
177
+ vec2 fragSt = gl_FragCoord.xy / czm_viewport.zw;
178
+ float globeDepth = getGlobeDepthAtCoords(fragSt);
179
+ doDepthTest(globeDepth);
180
+
93
181
  vec4 color = texture(u_atlas, v_textureCoordinates);
94
182
 
95
183
  #ifdef SDF
@@ -156,53 +244,18 @@ void main()
156
244
  out_FragColor = color;
157
245
 
158
246
  #ifdef LOG_DEPTH
159
- czm_writeLogDepth();
160
- #endif
161
-
162
- #ifdef FRAGMENT_DEPTH_CHECK
163
- float temp = v_compressed.y;
164
-
165
- temp = temp * SHIFT_RIGHT1;
166
-
167
- float temp2 = (temp - floor(temp)) * SHIFT_LEFT1;
168
- bool enableDepthTest = temp2 != 0.0;
169
- bool applyTranslate = floor(temp) != 0.0;
170
-
171
- if (enableDepthTest) {
172
- temp = v_compressed.z;
173
- temp = temp * SHIFT_RIGHT12;
174
-
175
- vec2 dimensions;
176
- dimensions.y = (temp - floor(temp)) * SHIFT_LEFT12;
177
- dimensions.x = floor(temp);
178
-
179
- temp = v_compressed.w;
180
- temp = temp * SHIFT_RIGHT12;
181
-
182
- vec2 imageSize;
183
- imageSize.y = (temp - floor(temp)) * SHIFT_LEFT12;
184
- imageSize.x = floor(temp);
185
-
186
- vec2 adjustedST = v_textureCoordinates - v_textureCoordinateBounds.xy;
187
- adjustedST = adjustedST / vec2(v_textureCoordinateBounds.z - v_textureCoordinateBounds.x, v_textureCoordinateBounds.w - v_textureCoordinateBounds.y);
188
-
189
- float epsilonEyeDepth = v_compressed.x + czm_epsilon1;
190
- float globeDepth1 = getGlobeDepth(adjustedST, v_originTextureCoordinateAndTranslate.xy, applyTranslate, dimensions, imageSize);
191
-
192
- // negative values go into the screen
193
- if (globeDepth1 != 0.0 && globeDepth1 > epsilonEyeDepth)
194
- {
195
- float globeDepth2 = getGlobeDepth(adjustedST, vec2(0.0, 1.0), applyTranslate, dimensions, imageSize); // top left corner
196
- if (globeDepth2 != 0.0 && globeDepth2 > epsilonEyeDepth)
197
- {
198
- float globeDepth3 = getGlobeDepth(adjustedST, vec2(1.0, 1.0), applyTranslate, dimensions, imageSize); // top right corner
199
- if (globeDepth3 != 0.0 && globeDepth3 > epsilonEyeDepth)
200
- {
201
- discard;
202
- }
203
- }
204
- }
247
+ // If we've made it here, we passed our manual depth test, above. But the automatic depth test will
248
+ // still run, and some fragments of the billboard may clip against the globe. To prevent that,
249
+ // ensure the depth value we write out is in front of the globe depth.
250
+ float depthArg = v_depthFromNearPlusOne;
251
+
252
+ if (globeDepth != 0.0) { // On the globe
253
+ float globeDepthFromNearPlusOne = (-globeDepth - czm_currentFrustum.x) + 1.0;
254
+ float nudge = max(globeDepthFromNearPlusOne * 5e-6, czm_epsilon7);
255
+ float globeOnTop = max(1.0, globeDepthFromNearPlusOne - nudge);
256
+ depthArg = min(depthArg, globeOnTop);
205
257
  }
206
- #endif
207
258
 
208
- }
259
+ czm_writeLogDepth(depthArg);
260
+ #endif
261
+ }
@@ -1,5 +1,7 @@
1
1
  //This file is automatically rebuilt by the Cesium build process.
2
2
  export default "uniform sampler2D u_atlas;\n\
3
+ uniform float u_coarseDepthTestDistance;\n\
4
+ uniform float u_threePointDepthTestDistance;\n\
3
5
  \n\
4
6
  #ifdef VECTOR_TILE\n\
5
7
  uniform vec4 u_highlightColor;\n\
@@ -15,18 +17,33 @@ in vec4 v_outlineColor;\n\
15
17
  in float v_outlineWidth;\n\
16
18
  #endif\n\
17
19
  \n\
18
- #ifdef FRAGMENT_DEPTH_CHECK\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
+ #ifdef FS_THREE_POINT_DEPTH_CHECK\n\
19
25
  in vec4 v_textureCoordinateBounds; // the min and max x and y values for the texture coordinates\n\
20
26
  in vec4 v_originTextureCoordinateAndTranslate; // texture coordinate at the origin, billboard translate (used for label glyphs)\n\
21
- in vec4 v_compressed; // x: eyeDepth, y: applyTranslate & enableDepthCheck, z: dimensions, w: imageSize\n\
22
27
  in mat2 v_rotationMatrix;\n\
23
28
  \n\
24
29
  const float SHIFT_LEFT12 = 4096.0;\n\
25
- const float SHIFT_LEFT1 = 2.0;\n\
26
30
  \n\
27
31
  const float SHIFT_RIGHT12 = 1.0 / 4096.0;\n\
28
- const float SHIFT_RIGHT1 = 1.0 / 2.0;\n\
32
+ #endif\n\
33
+ \n\
34
+ float getGlobeDepthAtCoords(vec2 st)\n\
35
+ {\n\
36
+ float logDepthOrDepth = czm_unpackDepth(texture(czm_globeDepthTexture, st));\n\
37
+ if (logDepthOrDepth == 0.0)\n\
38
+ {\n\
39
+ return 0.0; // not on the globe\n\
40
+ }\n\
41
+ \n\
42
+ vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, logDepthOrDepth);\n\
43
+ return eyeCoordinate.z / eyeCoordinate.w;\n\
44
+ }\n\
29
45
  \n\
46
+ #ifdef FS_THREE_POINT_DEPTH_CHECK\n\
30
47
  float getGlobeDepth(vec2 adjustedST, vec2 depthLookupST, bool applyTranslate, vec2 dimensions, vec2 imageSize)\n\
31
48
  {\n\
32
49
  vec2 lookupVector = imageSize * (depthLookupST - adjustedST);\n\
@@ -43,19 +60,10 @@ float getGlobeDepth(vec2 adjustedST, vec2 depthLookupST, bool applyTranslate, ve
43
60
  }\n\
44
61
  \n\
45
62
  vec2 st = ((lookupVector - translation + labelOffset) + gl_FragCoord.xy) / czm_viewport.zw;\n\
46
- float logDepthOrDepth = czm_unpackDepth(texture(czm_globeDepthTexture, st));\n\
47
- \n\
48
- if (logDepthOrDepth == 0.0)\n\
49
- {\n\
50
- return 0.0; // not on the globe\n\
51
- }\n\
52
- \n\
53
- vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, logDepthOrDepth);\n\
54
- return eyeCoordinate.z / eyeCoordinate.w;\n\
63
+ return getGlobeDepthAtCoords(st);\n\
55
64
  }\n\
56
65
  #endif\n\
57
66
  \n\
58
- \n\
59
67
  #ifdef SDF\n\
60
68
  \n\
61
69
  // Get the distance from the edge of a glyph at a given position sampling an SDF texture.\n\
@@ -86,11 +94,91 @@ vec4 getSDFColor(vec2 position, float outlineWidth, vec4 outlineColor, float smo
86
94
  }\n\
87
95
  #endif\n\
88
96
  \n\
97
+ #ifdef FS_THREE_POINT_DEPTH_CHECK\n\
98
+ void doThreePointDepthTest(float eyeDepth, bool applyTranslate) {\n\
99
+ \n\
100
+ if (eyeDepth < -u_threePointDepthTestDistance) return;\n\
101
+ float temp = v_compressed.z;\n\
102
+ temp = temp * SHIFT_RIGHT12;\n\
103
+ \n\
104
+ vec2 dimensions;\n\
105
+ dimensions.y = (temp - floor(temp)) * SHIFT_LEFT12;\n\
106
+ dimensions.x = floor(temp);\n\
107
+ \n\
108
+ temp = v_compressed.w;\n\
109
+ temp = temp * SHIFT_RIGHT12;\n\
110
+ \n\
111
+ vec2 imageSize;\n\
112
+ imageSize.y = (temp - floor(temp)) * SHIFT_LEFT12;\n\
113
+ imageSize.x = floor(temp);\n\
114
+ \n\
115
+ vec2 adjustedST = v_textureCoordinates - v_textureCoordinateBounds.xy;\n\
116
+ adjustedST = adjustedST / vec2(v_textureCoordinateBounds.z - v_textureCoordinateBounds.x, v_textureCoordinateBounds.w - v_textureCoordinateBounds.y);\n\
117
+ \n\
118
+ float epsilonEyeDepth = v_compressed.x + czm_epsilon1;\n\
119
+ float globeDepth1 = getGlobeDepth(adjustedST, v_originTextureCoordinateAndTranslate.xy, applyTranslate, dimensions, imageSize);\n\
120
+ \n\
121
+ // negative values go into the screen\n\
122
+ if (globeDepth1 == 0.0 || globeDepth1 < epsilonEyeDepth) return;\n\
123
+ \n\
124
+ float globeDepth2 = getGlobeDepth(adjustedST, vec2(0.0, 1.0), applyTranslate, dimensions, imageSize); // top left corner\n\
125
+ if (globeDepth2 == 0.0 || globeDepth2 < epsilonEyeDepth) return;\n\
126
+ \n\
127
+ float globeDepth3 = getGlobeDepth(adjustedST, vec2(1.0, 1.0), applyTranslate, dimensions, imageSize); // top right corner\n\
128
+ if (globeDepth3 == 0.0 || globeDepth3 < epsilonEyeDepth) return;\n\
129
+ \n\
130
+ // All three key points are occluded, discard the fragment (and by extension the entire billboard) \n\
131
+ discard;\n\
132
+ }\n\
133
+ #endif\n\
134
+ \n\
135
+ // Extra manual depth testing is done to allow more control over how a billboard is occluded \n\
136
+ // by the globe when near and far from the camera.\n\
137
+ void doDepthTest(float globeDepth) {\n\
138
+ float temp = v_compressed.y;\n\
139
+ temp = temp * SHIFT_RIGHT1;\n\
140
+ float temp2 = (temp - floor(temp)) * SHIFT_LEFT1;\n\
141
+ bool enableDepthCheck = temp2 != 0.0;\n\
142
+ if (!enableDepthCheck) return;\n\
143
+ \n\
144
+ float eyeDepth = v_compressed.x;\n\
145
+ \n\
146
+ #ifdef FS_THREE_POINT_DEPTH_CHECK\n\
147
+ // If the billboard is clamped to the ground and within a given distance, we do a 3-point depth test. This test is performed in the vertex shader, unless\n\
148
+ // vertex texture sampling is not supported, in which case we do it here.\n\
149
+ bool applyTranslate = floor(temp) != 0.0;\n\
150
+ doThreePointDepthTest(eyeDepth, applyTranslate);\n\
151
+ \n\
152
+ #elif defined(VS_THREE_POINT_DEPTH_CHECK)\n\
153
+ // Since discarding vertices is not possible, the vertex shader sets eyeDepth to 0 to indicate the depth test failed. Apply the discard here.\n\
154
+ if (eyeDepth > -u_threePointDepthTestDistance) {\n\
155
+ if (eyeDepth == 0.0) {\n\
156
+ discard;\n\
157
+ }\n\
158
+ return;\n\
159
+ }\n\
160
+ #endif\n\
161
+ \n\
162
+ // If we're far away, we just compare against a flat, camera-facing depth-plane at the ellipsoid's center.\n\
163
+ // If we're close, we compare against the globe depth texture (which includes depth from the 3D tile pass).\n\
164
+ \n\
165
+ if (globeDepth == 0.0) return; // Not on globe \n\
166
+ float distanceToEllipsoidCenter = -length(czm_viewerPositionWC); // depth is negative by convention\n\
167
+ float testDistance = (eyeDepth > -u_coarseDepthTestDistance) ? globeDepth : distanceToEllipsoidCenter;\n\
168
+ if (eyeDepth < testDistance) {\n\
169
+ discard;\n\
170
+ }\n\
171
+ }\n\
172
+ \n\
89
173
  void main()\n\
90
174
  {\n\
91
175
  if (v_splitDirection < 0.0 && gl_FragCoord.x > czm_splitPosition) discard;\n\
92
176
  if (v_splitDirection > 0.0 && gl_FragCoord.x < czm_splitPosition) discard;\n\
93
177
  \n\
178
+ vec2 fragSt = gl_FragCoord.xy / czm_viewport.zw;\n\
179
+ float globeDepth = getGlobeDepthAtCoords(fragSt);\n\
180
+ doDepthTest(globeDepth);\n\
181
+ \n\
94
182
  vec4 color = texture(u_atlas, v_textureCoordinates);\n\
95
183
  \n\
96
184
  #ifdef SDF\n\
@@ -157,54 +245,18 @@ void main()\n\
157
245
  out_FragColor = color;\n\
158
246
  \n\
159
247
  #ifdef LOG_DEPTH\n\
160
- czm_writeLogDepth();\n\
161
- #endif\n\
162
- \n\
163
- #ifdef FRAGMENT_DEPTH_CHECK\n\
164
- float temp = v_compressed.y;\n\
165
- \n\
166
- temp = temp * SHIFT_RIGHT1;\n\
167
- \n\
168
- float temp2 = (temp - floor(temp)) * SHIFT_LEFT1;\n\
169
- bool enableDepthTest = temp2 != 0.0;\n\
170
- bool applyTranslate = floor(temp) != 0.0;\n\
171
- \n\
172
- if (enableDepthTest) {\n\
173
- temp = v_compressed.z;\n\
174
- temp = temp * SHIFT_RIGHT12;\n\
175
- \n\
176
- vec2 dimensions;\n\
177
- dimensions.y = (temp - floor(temp)) * SHIFT_LEFT12;\n\
178
- dimensions.x = floor(temp);\n\
179
- \n\
180
- temp = v_compressed.w;\n\
181
- temp = temp * SHIFT_RIGHT12;\n\
182
- \n\
183
- vec2 imageSize;\n\
184
- imageSize.y = (temp - floor(temp)) * SHIFT_LEFT12;\n\
185
- imageSize.x = floor(temp);\n\
186
- \n\
187
- vec2 adjustedST = v_textureCoordinates - v_textureCoordinateBounds.xy;\n\
188
- adjustedST = adjustedST / vec2(v_textureCoordinateBounds.z - v_textureCoordinateBounds.x, v_textureCoordinateBounds.w - v_textureCoordinateBounds.y);\n\
189
- \n\
190
- float epsilonEyeDepth = v_compressed.x + czm_epsilon1;\n\
191
- float globeDepth1 = getGlobeDepth(adjustedST, v_originTextureCoordinateAndTranslate.xy, applyTranslate, dimensions, imageSize);\n\
192
- \n\
193
- // negative values go into the screen\n\
194
- if (globeDepth1 != 0.0 && globeDepth1 > epsilonEyeDepth)\n\
195
- {\n\
196
- float globeDepth2 = getGlobeDepth(adjustedST, vec2(0.0, 1.0), applyTranslate, dimensions, imageSize); // top left corner\n\
197
- if (globeDepth2 != 0.0 && globeDepth2 > epsilonEyeDepth)\n\
198
- {\n\
199
- float globeDepth3 = getGlobeDepth(adjustedST, vec2(1.0, 1.0), applyTranslate, dimensions, imageSize); // top right corner\n\
200
- if (globeDepth3 != 0.0 && globeDepth3 > epsilonEyeDepth)\n\
201
- {\n\
202
- discard;\n\
203
- }\n\
204
- }\n\
205
- }\n\
248
+ // If we've made it here, we passed our manual depth test, above. But the automatic depth test will\n\
249
+ // still run, and some fragments of the billboard may clip against the globe. To prevent that,\n\
250
+ // ensure the depth value we write out is in front of the globe depth.\n\
251
+ float depthArg = v_depthFromNearPlusOne;\n\
252
+ \n\
253
+ if (globeDepth != 0.0) { // On the globe\n\
254
+ float globeDepthFromNearPlusOne = (-globeDepth - czm_currentFrustum.x) + 1.0;\n\
255
+ float nudge = max(globeDepthFromNearPlusOne * 5e-6, czm_epsilon7);\n\
256
+ float globeOnTop = max(1.0, globeDepthFromNearPlusOne - nudge);\n\
257
+ depthArg = min(depthArg, globeOnTop);\n\
206
258
  }\n\
207
- #endif\n\
208
259
  \n\
209
- }\n\
210
- ";
260
+ czm_writeLogDepth(depthArg);\n\
261
+ #endif\n\
262
+ }";
@@ -1,3 +1,4 @@
1
+ uniform float u_threePointDepthTestDistance;
1
2
  #ifdef INSTANCED
2
3
  in vec2 direction;
3
4
  #endif
@@ -9,10 +10,10 @@ in vec4 compressedAttribute2; // label horizontal origin,
9
10
  in vec4 eyeOffset; // eye offset in meters, 4 bytes free (texture range)
10
11
  in vec4 scaleByDistance; // near, nearScale, far, farScale
11
12
  in vec4 pixelOffsetScaleByDistance; // near, nearScale, far, farScale
12
- in vec4 compressedAttribute3; // distance display condition near, far, disableDepthTestDistance, dimensions
13
+ in vec4 compressedAttribute3; // distance display condition near, far, disableDepthTestDistanceSq, dimensions
13
14
  in vec2 sdf; // sdf outline color (rgb) and width (w)
14
15
  in float splitDirection; // splitDirection
15
- #if defined(VERTEX_DEPTH_CHECK) || defined(FRAGMENT_DEPTH_CHECK)
16
+ #if defined(VS_THREE_POINT_DEPTH_CHECK) || defined(FS_THREE_POINT_DEPTH_CHECK)
16
17
  in vec4 textureCoordinateBoundsOrLabelTranslate; // the min and max x and y values for the texture coordinates
17
18
  #endif
18
19
  #ifdef VECTOR_TILE
@@ -20,12 +21,12 @@ in float a_batchId;
20
21
  #endif
21
22
 
22
23
  out vec2 v_textureCoordinates;
23
- #ifdef FRAGMENT_DEPTH_CHECK
24
+ #ifdef FS_THREE_POINT_DEPTH_CHECK
24
25
  out vec4 v_textureCoordinateBounds;
25
26
  out vec4 v_originTextureCoordinateAndTranslate;
26
- out vec4 v_compressed; // x: eyeDepth, y: applyTranslate & enableDepthCheck, z: dimensions, w: imageSize
27
27
  out mat2 v_rotationMatrix;
28
28
  #endif
29
+ out vec4 v_compressed; // x: eyeDepth, y: applyTranslate & enableDepthCheck, z: dimensions, w: imageSize
29
30
 
30
31
  out vec4 v_pickColor;
31
32
  out vec4 v_color;
@@ -92,7 +93,7 @@ vec4 addScreenSpaceOffset(vec4 positionEC, vec2 imageSize, float scale, vec2 dir
92
93
  return positionEC;
93
94
  }
94
95
 
95
- #ifdef VERTEX_DEPTH_CHECK
96
+ #ifdef VS_THREE_POINT_DEPTH_CHECK
96
97
  float getGlobeDepth(vec4 positionEC)
97
98
  {
98
99
  vec4 posWC = czm_eyeToWindowCoordinates(positionEC);
@@ -137,7 +138,7 @@ void main()
137
138
  origin.y = floor(compressed * SHIFT_RIGHT3);
138
139
  compressed -= origin.y * SHIFT_LEFT3;
139
140
 
140
- #ifdef FRAGMENT_DEPTH_CHECK
141
+ #ifdef FS_THREE_POINT_DEPTH_CHECK
141
142
  vec2 depthOrigin = origin.xy;
142
143
  #endif
143
144
  origin -= vec2(1.0);
@@ -176,10 +177,10 @@ void main()
176
177
 
177
178
  vec2 imageSize = vec2(floor(temp), temp2);
178
179
 
179
- #ifdef FRAGMENT_DEPTH_CHECK
180
+ #ifdef FS_THREE_POINT_DEPTH_CHECK
180
181
  float labelHorizontalOrigin = floor(compressedAttribute2.w - (temp2 * SHIFT_LEFT2));
181
182
  float applyTranslate = 0.0;
182
- if (labelHorizontalOrigin != 0.0) // is a billboard, so set apply translate to false
183
+ if (labelHorizontalOrigin != 0.0) // is a label, so set apply translate to true
183
184
  {
184
185
  applyTranslate = 1.0;
185
186
  labelHorizontalOrigin -= 2.0;
@@ -200,7 +201,7 @@ void main()
200
201
  translucencyByDistance.w = ((temp - floor(temp)) * SHIFT_LEFT8) / 255.0;
201
202
  #endif
202
203
 
203
- #if defined(VERTEX_DEPTH_CHECK) || defined(FRAGMENT_DEPTH_CHECK)
204
+ #if defined(VS_THREE_POINT_DEPTH_CHECK) || defined(FS_THREE_POINT_DEPTH_CHECK)
204
205
  temp = compressedAttribute3.w;
205
206
  temp = temp * SHIFT_RIGHT12;
206
207
 
@@ -250,10 +251,6 @@ void main()
250
251
  vec4 p = czm_translateRelativeToEye(positionHigh, positionLow);
251
252
  vec4 positionEC = czm_modelViewRelativeToEye * p;
252
253
 
253
- #if defined(FRAGMENT_DEPTH_CHECK) || defined(VERTEX_DEPTH_CHECK)
254
- float eyeDepth = positionEC.z;
255
- #endif
256
-
257
254
  positionEC = czm_eyeOffset(positionEC, eyeOffset.xyz);
258
255
  positionEC.xyz *= show;
259
256
 
@@ -311,35 +308,56 @@ void main()
311
308
  mat2 rotationMatrix;
312
309
  float mpp;
313
310
 
311
+ float enableDepthCheck = 1.0;
314
312
  #ifdef DISABLE_DEPTH_DISTANCE
315
- float disableDepthTestDistance = compressedAttribute3.z;
313
+ float disableDepthTestDistanceSq = compressedAttribute3.z;
314
+ if (disableDepthTestDistanceSq == 0.0 && czm_minimumDisableDepthTestDistance != 0.0)
315
+ {
316
+ disableDepthTestDistanceSq = czm_minimumDisableDepthTestDistance;
317
+ }
318
+
319
+ if (lengthSq < disableDepthTestDistanceSq || disableDepthTestDistanceSq < 0.0)
320
+ {
321
+ enableDepthCheck = 0.0;
322
+ }
316
323
  #endif
317
324
 
318
- #ifdef VERTEX_DEPTH_CHECK
319
- if (lengthSq < disableDepthTestDistance) {
320
- float depthsilon = 10.0;
325
+ v_compressed.y = enableDepthCheck;
321
326
 
322
- vec2 labelTranslate = textureCoordinateBoundsOrLabelTranslate.xy;
323
- vec4 pEC1 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(0.0), origin, labelTranslate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);
327
+ #ifdef VS_THREE_POINT_DEPTH_CHECK
328
+ if (lengthSq < (u_threePointDepthTestDistance * u_threePointDepthTestDistance) && (enableDepthCheck == 1.0)) {
329
+ float depthsilon = 10.0;
330
+ vec2 depthOrigin;
331
+ // Horizontal origin for labels comes from a special attribute. If that value is 0, this is a billboard - use the regular origin.
332
+ // Otherwise, transform the label origin to -1, 0, 1 (right, center, left).
333
+ depthOrigin.x = floor(compressedAttribute2.w - (temp2 * SHIFT_LEFT2));
334
+ depthOrigin.x = czm_branchFreeTernary(depthOrigin.x == 0.0, origin.x, depthOrigin.x - 2.0);
335
+ depthOrigin.y = origin.y;
336
+
337
+ vec4 pEC1 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(0.0), depthOrigin, vec2(0.0), pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);
324
338
  float globeDepth1 = getGlobeDepth(pEC1);
325
339
 
326
340
  if (globeDepth1 != 0.0 && pEC1.z + depthsilon < globeDepth1)
327
341
  {
328
- vec4 pEC2 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(0.0, 1.0), origin, labelTranslate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);
342
+ vec4 pEC2 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(0.0, 1.0), depthOrigin, vec2(0.0), pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);
329
343
  float globeDepth2 = getGlobeDepth(pEC2);
330
344
 
331
345
  if (globeDepth2 != 0.0 && pEC2.z + depthsilon < globeDepth2)
332
346
  {
333
- vec4 pEC3 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(1.0), origin, labelTranslate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);
347
+ vec4 pEC3 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(1.0), depthOrigin, vec2(0.0), pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);
334
348
  float globeDepth3 = getGlobeDepth(pEC3);
335
349
  if (globeDepth3 != 0.0 && pEC3.z + depthsilon < globeDepth3)
336
350
  {
351
+ // "Discard" this vertex, as three key points fail depth test.
337
352
  positionEC.xyz = vec3(0.0);
338
353
  }
339
354
  }
340
355
  }
341
356
  }
342
357
  #endif
358
+ // Write out the eyespace depth before applying the screen space offset, but after potentially "discarding" the vertex
359
+ // by setting its eyespace position to zero, via the three-point depth test above.
360
+ v_compressed.x = positionEC.z;
343
361
 
344
362
  positionEC = addScreenSpaceOffset(positionEC, imageSize, scale, direction, origin, translate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);
345
363
  gl_Position = czm_projection * positionEC;
@@ -350,17 +368,14 @@ if (lengthSq < disableDepthTestDistance) {
350
368
  #endif
351
369
 
352
370
  #ifdef DISABLE_DEPTH_DISTANCE
353
- if (disableDepthTestDistance == 0.0 && czm_minimumDisableDepthTestDistance != 0.0)
354
- {
355
- disableDepthTestDistance = czm_minimumDisableDepthTestDistance;
356
- }
357
371
 
358
- if (disableDepthTestDistance != 0.0)
372
+ if (disableDepthTestDistanceSq != 0.0)
359
373
  {
360
374
  // Don't try to "multiply both sides" by w. Greater/less-than comparisons won't work for negative values of w.
361
375
  float zclip = gl_Position.z / gl_Position.w;
362
376
  bool clipped = (zclip < -1.0 || zclip > 1.0);
363
- if (!clipped && (disableDepthTestDistance < 0.0 || (lengthSq > 0.0 && lengthSq < disableDepthTestDistance)))
377
+ // disableDepthTestDistanceSq can be less than zero if it's explicitly set to -1 in JS (as a sentinel value equivalent to infinity)
378
+ if (!clipped && (disableDepthTestDistanceSq < 0.0 || (lengthSq > 0.0 && lengthSq < disableDepthTestDistanceSq)))
364
379
  {
365
380
  // Position z on the near plane.
366
381
  gl_Position.z = -gl_Position.w;
@@ -371,7 +386,7 @@ if (lengthSq < disableDepthTestDistance) {
371
386
  }
372
387
  #endif
373
388
 
374
- #ifdef FRAGMENT_DEPTH_CHECK
389
+ #ifdef FS_THREE_POINT_DEPTH_CHECK
375
390
  if (sizeInMeters) {
376
391
  translate /= mpp;
377
392
  dimensions /= mpp;
@@ -383,21 +398,13 @@ if (lengthSq < disableDepthTestDistance) {
383
398
  #else
384
399
  v_rotationMatrix = mat2(1.0, 0.0, 0.0, 1.0);
385
400
  #endif
386
-
387
- float enableDepthCheck = 0.0;
388
- if (lengthSq < disableDepthTestDistance)
389
- {
390
- enableDepthCheck = 1.0;
391
- }
392
-
393
401
  float dw = floor(clamp(dimensions.x, 0.0, SHIFT_LEFT12));
394
402
  float dh = floor(clamp(dimensions.y, 0.0, SHIFT_LEFT12));
395
403
 
396
404
  float iw = floor(clamp(imageSize.x, 0.0, SHIFT_LEFT12));
397
405
  float ih = floor(clamp(imageSize.y, 0.0, SHIFT_LEFT12));
398
406
 
399
- v_compressed.x = eyeDepth;
400
- v_compressed.y = applyTranslate * SHIFT_LEFT1 + enableDepthCheck;
407
+ v_compressed.y += applyTranslate * SHIFT_LEFT1;
401
408
  v_compressed.z = dw * SHIFT_LEFT12 + dh;
402
409
  v_compressed.w = iw * SHIFT_LEFT12 + ih;
403
410
  v_originTextureCoordinateAndTranslate.xy = depthOrigin;