@cesium/engine 12.0.1 → 13.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 (161) hide show
  1. package/Build/Workers/{chunk-7D6T2WYT.js → chunk-2ONAV62A.js} +14 -47
  2. package/Build/Workers/{chunk-MV7YO647.js → chunk-2SRHVCFD.js} +6 -6
  3. package/Build/Workers/{chunk-ZPTNVB3S.js → chunk-3SCCWLZS.js} +34 -8
  4. package/Build/Workers/{chunk-7CKQ7PVJ.js → chunk-54I6VSRP.js} +6 -6
  5. package/Build/Workers/{chunk-XDJ7V4NZ.js → chunk-5I3LPAS7.js} +5 -5
  6. package/Build/Workers/{chunk-GSJ6LWIS.js → chunk-5ICYLS6B.js} +35 -21
  7. package/Build/Workers/{chunk-BH5M522L.js → chunk-5JY4LYO3.js} +7 -7
  8. package/Build/Workers/{chunk-DR56WFYZ.js → chunk-APCS5YJI.js} +7 -7
  9. package/Build/Workers/{chunk-COHL4R3G.js → chunk-AXYZUG4N.js} +1 -1
  10. package/Build/Workers/{chunk-2IJZVFHY.js → chunk-B34JXFHF.js} +5 -5
  11. package/Build/Workers/{chunk-54NYY4U4.js → chunk-B6IJY6AN.js} +7 -7
  12. package/Build/Workers/{chunk-H3RMGG7L.js → chunk-BMFWWTD7.js} +5 -5
  13. package/Build/Workers/{chunk-PJHRB4YJ.js → chunk-CBE4HRBH.js} +7 -7
  14. package/Build/Workers/{chunk-U7SH6OK7.js → chunk-CNPP6TQ2.js} +4 -4
  15. package/Build/Workers/{chunk-2XOUWNPN.js → chunk-DWIKWWEE.js} +5 -5
  16. package/Build/Workers/{chunk-PNA47CR7.js → chunk-EHGQQA7C.js} +1 -1
  17. package/Build/Workers/{chunk-7EBHNJTG.js → chunk-EJ5DT5BP.js} +1 -1
  18. package/Build/Workers/{chunk-3Y4UGAYI.js → chunk-EYZFEJX3.js} +6 -6
  19. package/Build/Workers/{chunk-EMCXAVSG.js → chunk-FNCXBBCF.js} +2 -2
  20. package/Build/Workers/{chunk-NL73INJS.js → chunk-GIOZHX7U.js} +2 -2
  21. package/Build/Workers/{chunk-VHGI7D3P.js → chunk-GSLKQJM2.js} +10 -10
  22. package/Build/Workers/{chunk-647NL6VU.js → chunk-HI73PIPQ.js} +2 -2
  23. package/Build/Workers/{chunk-GRQQHWMD.js → chunk-IP7F2MVW.js} +7 -7
  24. package/Build/Workers/{chunk-LBNGHEJY.js → chunk-IXNXKVOB.js} +4 -4
  25. package/Build/Workers/{chunk-2F42VIW6.js → chunk-J7BMSSY7.js} +13 -13
  26. package/Build/Workers/{chunk-PH3T7LNP.js → chunk-K62EHZFT.js} +15 -15
  27. package/Build/Workers/{chunk-GBPW65E3.js → chunk-K6SQV4IS.js} +6 -6
  28. package/Build/Workers/{chunk-WMHJAREU.js → chunk-KO232FLP.js} +2 -2
  29. package/Build/Workers/{chunk-AER5CLXD.js → chunk-KRVALCCI.js} +5 -5
  30. package/Build/Workers/{chunk-22FZ334F.js → chunk-LFUFGHL3.js} +10 -10
  31. package/Build/Workers/{chunk-AGYO4ZSF.js → chunk-LQT2ZK7D.js} +17 -17
  32. package/Build/Workers/{chunk-KJ65M35B.js → chunk-M2AA2ARJ.js} +11 -11
  33. package/Build/Workers/{chunk-YT5PQMSP.js → chunk-MGABCOOH.js} +6 -6
  34. package/Build/Workers/{chunk-JPNFQRN7.js → chunk-NQDKNE7V.js} +13 -13
  35. package/Build/Workers/{chunk-IJWXYSFC.js → chunk-OARMSJUU.js} +2 -2
  36. package/Build/Workers/{chunk-K7QC3WDT.js → chunk-OGRXNUR2.js} +1 -1
  37. package/Build/Workers/{chunk-KKMH4BKN.js → chunk-OZTFRHA2.js} +6 -6
  38. package/Build/Workers/{chunk-DJ7K7EYK.js → chunk-PBJQFLKS.js} +11 -11
  39. package/Build/Workers/{chunk-ETXXXGMP.js → chunk-PM76TX2X.js} +6 -6
  40. package/Build/Workers/{chunk-PISTPJXS.js → chunk-PTFIVVLX.js} +12 -12
  41. package/Build/Workers/{chunk-VXVQITFC.js → chunk-R2KGFZBA.js} +13 -13
  42. package/Build/Workers/{chunk-VO4SXJXT.js → chunk-S3UM4OKP.js} +7 -7
  43. package/Build/Workers/{chunk-NELAPOO6.js → chunk-SAKQO5NX.js} +2 -2
  44. package/Build/Workers/{chunk-ENARO52I.js → chunk-T34EOLFR.js} +14 -14
  45. package/Build/Workers/{chunk-X6YBZOOA.js → chunk-THDHWSEJ.js} +4 -4
  46. package/Build/Workers/{chunk-LVHHB5T6.js → chunk-TOHDFUJM.js} +4 -4
  47. package/Build/Workers/{chunk-Q7IIOKAT.js → chunk-UBAHTE4Q.js} +1 -1
  48. package/Build/Workers/{chunk-IAX6MIST.js → chunk-WAJNX74N.js} +17 -17
  49. package/Build/Workers/{chunk-76KRKKEF.js → chunk-WE4KF4AM.js} +9 -9
  50. package/Build/Workers/{chunk-JAKTB6CE.js → chunk-WUIDEXAN.js} +7 -7
  51. package/Build/Workers/{chunk-IVCFTVYW.js → chunk-YVGU235V.js} +4 -4
  52. package/Build/Workers/{chunk-ZCCI55EY.js → chunk-ZWSWJYJP.js} +13 -13
  53. package/Build/Workers/combineGeometry.js +22 -22
  54. package/Build/Workers/createBoxGeometry.js +16 -16
  55. package/Build/Workers/createBoxOutlineGeometry.js +14 -14
  56. package/Build/Workers/createCircleGeometry.js +24 -24
  57. package/Build/Workers/createCircleOutlineGeometry.js +17 -17
  58. package/Build/Workers/createCoplanarPolygonGeometry.js +31 -31
  59. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +29 -29
  60. package/Build/Workers/createCorridorGeometry.js +27 -27
  61. package/Build/Workers/createCorridorOutlineGeometry.js +26 -26
  62. package/Build/Workers/createCylinderGeometry.js +18 -18
  63. package/Build/Workers/createCylinderOutlineGeometry.js +16 -16
  64. package/Build/Workers/createEllipseGeometry.js +24 -24
  65. package/Build/Workers/createEllipseOutlineGeometry.js +17 -17
  66. package/Build/Workers/createEllipsoidGeometry.js +17 -17
  67. package/Build/Workers/createEllipsoidOutlineGeometry.js +16 -16
  68. package/Build/Workers/createFrustumGeometry.js +16 -16
  69. package/Build/Workers/createFrustumOutlineGeometry.js +16 -16
  70. package/Build/Workers/createGeometry.js +22 -22
  71. package/Build/Workers/createGroundPolylineGeometry.js +20 -20
  72. package/Build/Workers/createPlaneGeometry.js +14 -14
  73. package/Build/Workers/createPlaneOutlineGeometry.js +13 -13
  74. package/Build/Workers/createPolygonGeometry.js +30 -30
  75. package/Build/Workers/createPolygonOutlineGeometry.js +28 -28
  76. package/Build/Workers/createPolylineGeometry.js +23 -23
  77. package/Build/Workers/createPolylineVolumeGeometry.js +31 -32
  78. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +25 -25
  79. package/Build/Workers/createRectangleGeometry.js +25 -25
  80. package/Build/Workers/createRectangleOutlineGeometry.js +18 -18
  81. package/Build/Workers/createSimplePolylineGeometry.js +21 -21
  82. package/Build/Workers/createSphereGeometry.js +17 -17
  83. package/Build/Workers/createSphereOutlineGeometry.js +16 -16
  84. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  85. package/Build/Workers/createVectorTileClampedPolylines.js +13 -13
  86. package/Build/Workers/createVectorTileGeometries.js +22 -22
  87. package/Build/Workers/createVectorTilePoints.js +12 -12
  88. package/Build/Workers/createVectorTilePolygons.js +20 -20
  89. package/Build/Workers/createVectorTilePolylines.js +13 -13
  90. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +20 -20
  91. package/Build/Workers/createVerticesFromHeightmap.js +20 -20
  92. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +17 -17
  93. package/Build/Workers/createWallGeometry.js +22 -22
  94. package/Build/Workers/createWallOutlineGeometry.js +21 -21
  95. package/Build/Workers/decodeDraco.js +11 -11
  96. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
  97. package/Build/Workers/decodeI3S.js +10 -10
  98. package/Build/Workers/transcodeKTX2.js +7 -7
  99. package/Build/Workers/transferTypedArrayTest.js +1 -1
  100. package/Build/Workers/upsampleQuantizedTerrainMesh.js +20 -20
  101. package/Source/Core/BingMapsGeocoderService.js +2 -0
  102. package/Source/Core/Check.d.ts +2 -1
  103. package/Source/Core/GoogleGeocoderService.js +110 -0
  104. package/Source/Core/ITwinPlatform.js +324 -0
  105. package/Source/Core/Ion.js +1 -1
  106. package/Source/Core/IonGeocodeProviderType.js +33 -0
  107. package/Source/Core/IonGeocoderService.js +72 -0
  108. package/Source/Core/JulianDate.js +14 -7
  109. package/Source/Core/Rectangle.js +0 -20
  110. package/Source/Core/TrackingReferenceFrame.js +45 -0
  111. package/Source/Core/defined.d.ts +11 -0
  112. package/Source/DataSources/Entity.js +15 -1
  113. package/Source/DataSources/EntityView.js +55 -4
  114. package/Source/DataSources/ModelGraphics.js +23 -1
  115. package/Source/DataSources/ModelVisualizer.js +22 -1
  116. package/Source/DataSources/SampledProperty.js +24 -0
  117. package/Source/Renderer/ContextLimits.js +1 -1
  118. package/Source/Renderer/Texture.js +104 -92
  119. package/Source/Scene/ArcGisMapService.js +1 -1
  120. package/Source/Scene/Cesium3DTileset.js +1 -1
  121. package/Source/Scene/Cesium3DTilesetStatistics.js +109 -42
  122. package/Source/Scene/DerivedCommand.js +109 -16
  123. package/Source/Scene/DynamicEnvironmentMapManager.js +202 -65
  124. package/Source/Scene/GltfTextureLoader.js +16 -1
  125. package/Source/Scene/ITwinData.js +208 -0
  126. package/Source/Scene/Label.js +17 -3
  127. package/Source/Scene/MetadataClassProperty.js +26 -0
  128. package/Source/Scene/MetadataPicking.js +108 -17
  129. package/Source/Scene/MetadataType.js +20 -0
  130. package/Source/Scene/Model/Extensions/Gpm/GltfMeshPrimitiveGpmLoader.js +6 -11
  131. package/Source/Scene/Model/Model.js +1 -1
  132. package/Source/Scene/Model/Model3DTileContent.js +23 -1
  133. package/Source/Scene/Model/ModelStatistics.js +33 -5
  134. package/Source/Scene/Model/PointCloudStylingPipelineStage.js +2 -1
  135. package/Source/Scene/PickedMetadataInfo.js +21 -3
  136. package/Source/Scene/Picking.js +7 -1
  137. package/Source/Scene/PostProcessStage.js +14 -17
  138. package/Source/Scene/PostProcessStageCollection.js +4 -16
  139. package/Source/Scene/PostProcessStageLibrary.js +13 -51
  140. package/Source/Scene/PropertyAttributeProperty.js +15 -3
  141. package/Source/Scene/PropertyTextureProperty.js +12 -0
  142. package/Source/Scene/Scene.js +17 -2
  143. package/Source/Scene/SkyBox.js +23 -4
  144. package/Source/Scene/UrlTemplateImageryProvider.js +5 -5
  145. package/Source/Scene/createGooglePhotorealistic3DTileset.js +55 -16
  146. package/Source/Scene/getMetadataProperty.js +48 -0
  147. package/Source/Shaders/Builtin/Functions/reverseLogDepth.glsl +1 -1
  148. package/Source/Shaders/Builtin/Functions/reverseLogDepth.js +1 -1
  149. package/Source/Shaders/ConvolveSpecularMapFS.glsl +1 -1
  150. package/Source/Shaders/ConvolveSpecularMapFS.js +1 -1
  151. package/Source/Shaders/DepthPlaneVS.glsl +1 -1
  152. package/Source/Shaders/DepthPlaneVS.js +1 -1
  153. package/Source/Shaders/Model/ModelFS.glsl +7 -0
  154. package/Source/Shaders/Model/ModelFS.js +7 -0
  155. package/Source/Shaders/Model/ModelVS.glsl +9 -1
  156. package/Source/Shaders/Model/ModelVS.js +9 -1
  157. package/Source/Shaders/PostProcessStages/AmbientOcclusionGenerate.glsl +66 -37
  158. package/Source/Shaders/PostProcessStages/AmbientOcclusionGenerate.js +66 -37
  159. package/index.d.ts +295 -42
  160. package/index.js +67 -61
  161. package/package.json +1 -1
@@ -4,23 +4,37 @@ import defined from "../Core/defined.js";
4
4
  import IonResource from "../Core/IonResource.js";
5
5
  import GoogleMaps from "../Core/GoogleMaps.js";
6
6
  import Resource from "../Core/Resource.js";
7
+ import oneTimeWarning from "../Core/oneTimeWarning.js";
8
+ import deprecationWarning from "../Core/deprecationWarning.js";
7
9
 
8
10
  /**
9
- * Creates a {@link Cesium3DTileset} instance for the Google Photorealistic 3D Tiles tileset.
11
+ * Creates a {@link Cesium3DTileset} instance for the Google Photorealistic 3D
12
+ * Tiles tileset.
13
+ *
14
+ * Google Photorealistic 3D Tiles can only be used with the Google geocoder. To
15
+ * confirm that you are aware of this restriction pass
16
+ * `usingOnlyWithGoogleGeocoder: true` to the apiOptions. Otherwise a one time
17
+ * warning will be displayed when this function is called.
10
18
  *
11
19
  * @function
12
20
  *
13
- * @param {string} [key=GoogleMaps.defaultApiKey] Your API key to access Google Photorealistic 3D Tiles. See {@link https://developers.google.com/maps/documentation/javascript/get-api-key} for instructions on how to create your own key.
14
- * @param {Cesium3DTileset.ConstructorOptions} [options] An object describing initialization options.
21
+ * @param {object} [apiOptions]
22
+ * @param {string} [apiOptions.key=GoogleMaps.defaultApiKey] Your API key to access Google Photorealistic 3D Tiles. See {@link https://developers.google.com/maps/documentation/javascript/get-api-key} for instructions on how to create your own key.
23
+ * @param {true} [apiOptions.onlyUsingWithGoogleGeocoder] Confirmation that this tileset will only be used with the Google geocoder.
24
+ * @param {Cesium3DTileset.ConstructorOptions} [tilesetOptions] An object describing initialization options.
15
25
  * @returns {Promise<Cesium3DTileset>}
16
26
  *
17
27
  * @see GoogleMaps
18
28
  *
19
29
  * @example
20
- * const viewer = new Cesium.Viewer("cesiumContainer");
30
+ * const viewer = new Cesium.Viewer("cesiumContainer", {
31
+ * geocoder: Cesium.IonGeocodeProviderType.GOOGLE
32
+ * });
21
33
  *
22
34
  * try {
23
- * const tileset = await Cesium.createGooglePhotorealistic3DTileset();
35
+ * const tileset = await Cesium.createGooglePhotorealistic3DTileset({
36
+ * onlyUsingWithGoogleGeocoder: true,
37
+ * });
24
38
  * viewer.scene.primitives.add(tileset));
25
39
  * } catch (error) {
26
40
  * console.log(`Error creating tileset: ${error}`);
@@ -30,27 +44,52 @@ import Resource from "../Core/Resource.js";
30
44
  * // Use your own Google Maps API key
31
45
  * Cesium.GoogleMaps.defaultApiKey = "your-api-key";
32
46
  *
33
- * const viewer = new Cesium.Viewer("cesiumContainer");
47
+ * const viewer = new Cesium.Viewer("cesiumContainer". {
48
+ * geocoder: Cesium.IonGeocodeProviderType.GOOGLE
49
+ * });
34
50
  *
35
51
  * try {
36
- * const tileset = await Cesium.createGooglePhotorealistic3DTileset();
52
+ * const tileset = await Cesium.createGooglePhotorealistic3DTileset({
53
+ * onlyUsingWithGoogleGeocoder: true,
54
+ * });
37
55
  * viewer.scene.primitives.add(tileset));
38
56
  * } catch (error) {
39
57
  * console.log(`Error creating tileset: ${error}`);
40
58
  * }
41
59
  */
42
- async function createGooglePhotorealistic3DTileset(key, options) {
43
- options = defaultValue(options, {});
44
- options.cacheBytes = defaultValue(options.cacheBytes, 1536 * 1024 * 1024);
45
- options.maximumCacheOverflowBytes = defaultValue(
46
- options.maximumCacheOverflowBytes,
60
+ async function createGooglePhotorealistic3DTileset(apiOptions, tilesetOptions) {
61
+ tilesetOptions = defaultValue(tilesetOptions, {});
62
+ tilesetOptions.cacheBytes = defaultValue(
63
+ tilesetOptions.cacheBytes,
64
+ 1536 * 1024 * 1024,
65
+ );
66
+ tilesetOptions.maximumCacheOverflowBytes = defaultValue(
67
+ tilesetOptions.maximumCacheOverflowBytes,
47
68
  1024 * 1024 * 1024,
48
69
  );
49
- options.enableCollision = defaultValue(options.enableCollision, true);
70
+ tilesetOptions.enableCollision = defaultValue(
71
+ tilesetOptions.enableCollision,
72
+ true,
73
+ );
50
74
 
51
- key = defaultValue(key, GoogleMaps.defaultApiKey);
75
+ apiOptions = defaultValue(apiOptions, defaultValue.EMPTY_OBJECT);
76
+ if (typeof apiOptions === "string") {
77
+ deprecationWarning(
78
+ "createGooglePhotorealistic3DTileset(key)",
79
+ "createGooglePhotorealistic3DTileset(key) has been deprecated. It is replaced by createGooglePhotorealistic3DTileset({key}). It will be removed in Cesium 1.126.",
80
+ );
81
+ apiOptions = { key: apiOptions };
82
+ }
83
+ if (!apiOptions.onlyUsingWithGoogleGeocoder) {
84
+ oneTimeWarning(
85
+ "google-tiles-with-google-geocoder",
86
+ "Only the Google geocoder can be used with Google Photorealistic 3D Tiles. Set the `geocode` property of Viewer constructor options. You can set additionalOptions.onlyUsingWithGoogleGeocoder to hide this warning once you have configured the geocoder.",
87
+ );
88
+ }
89
+
90
+ const key = defaultValue(apiOptions.key, GoogleMaps.defaultApiKey);
52
91
  if (!defined(key)) {
53
- return requestCachedIonTileset(options);
92
+ return requestCachedIonTileset(tilesetOptions);
54
93
  }
55
94
 
56
95
  let credits;
@@ -67,7 +106,7 @@ async function createGooglePhotorealistic3DTileset(key, options) {
67
106
  credits: credits,
68
107
  });
69
108
 
70
- return Cesium3DTileset.fromUrl(resource, options);
109
+ return Cesium3DTileset.fromUrl(resource, tilesetOptions);
71
110
  }
72
111
 
73
112
  const metadataCache = {};
@@ -0,0 +1,48 @@
1
+ import defined from "../Core/defined.js";
2
+
3
+ /**
4
+ * Return the `PropertyTextureProperty` from the given `StructuralMetadata`
5
+ * that matches the given description.
6
+ *
7
+ * If the given structural metadata is `undefined`, then `undefined` is returned.
8
+ *
9
+ * Otherwise, this method will check all the property textures in the given
10
+ * structural metadata.
11
+ *
12
+ * If it finds a property texture that has a class with an `_id` that matches
13
+ * the given name, and that contains a property for the given property name, then
14
+ * this property is returned.
15
+ *
16
+ * Otherwise, `undefined` is returned
17
+ *
18
+ * @param {StructuralMetadata} structuralMetadata The structural metadata
19
+ * @param {string} className The name of the metadata class
20
+ * @param {string} propertyName The name of the metadata property
21
+ * @returns {PropertyTextureProperty|undefined}
22
+ * @private
23
+ */
24
+ function getMetadataProperty(structuralMetadata, className, propertyName) {
25
+ if (!defined(structuralMetadata)) {
26
+ return undefined;
27
+ }
28
+ const propertyTextures = structuralMetadata.propertyTextures;
29
+ for (const propertyTexture of propertyTextures) {
30
+ const metadataClass = propertyTexture.class;
31
+ if (metadataClass.id === className) {
32
+ const properties = propertyTexture.properties;
33
+ const property = properties[propertyName];
34
+ if (defined(property)) {
35
+ return property;
36
+ }
37
+ }
38
+ }
39
+ // Note: This could check for property attributes in a similar
40
+ // way. But since picking arbitrary property attributes via the
41
+ // frame buffer is not supported yet, returning "undefined" here
42
+ // causes the picking to bail out early and safely when no
43
+ // property texture was found.
44
+ // See https://github.com/CesiumGS/cesium/issues/12225
45
+ return undefined;
46
+ }
47
+
48
+ export default getMetadataProperty;
@@ -4,7 +4,7 @@ float czm_reverseLogDepth(float logZ)
4
4
  float near = czm_currentFrustum.x;
5
5
  float far = czm_currentFrustum.y;
6
6
  float log2Depth = logZ * czm_log2FarDepthFromNearPlusOne;
7
- float depthFromNear = pow(2.0, log2Depth) - 1.0;
7
+ float depthFromNear = exp2(log2Depth) - 1.0;
8
8
  return far * (1.0 - near / (depthFromNear + near)) / (far - near);
9
9
  #endif
10
10
  return logZ;
@@ -5,7 +5,7 @@ export default "float czm_reverseLogDepth(float logZ)\n\
5
5
  float near = czm_currentFrustum.x;\n\
6
6
  float far = czm_currentFrustum.y;\n\
7
7
  float log2Depth = logZ * czm_log2FarDepthFromNearPlusOne;\n\
8
- float depthFromNear = pow(2.0, log2Depth) - 1.0;\n\
8
+ float depthFromNear = exp2(log2Depth) - 1.0;\n\
9
9
  return far * (1.0 - near / (depthFromNear + near)) / (far - near);\n\
10
10
  #endif\n\
11
11
  return logZ;\n\
@@ -62,7 +62,7 @@ void main() {
62
62
 
63
63
  float NdotL = max(dot(V, L), 0.0);
64
64
  if (NdotL > 0.0) {
65
- color += vec4(texture(u_radianceTexture, L).rgb, 1.0) * NdotL;
65
+ color += vec4(czm_textureCube(u_radianceTexture, L).rgb, 1.0) * NdotL;
66
66
  weight += NdotL;
67
67
  }
68
68
  }
@@ -63,7 +63,7 @@ void main() {\n\
63
63
  \n\
64
64
  float NdotL = max(dot(V, L), 0.0);\n\
65
65
  if (NdotL > 0.0) {\n\
66
- color += vec4(texture(u_radianceTexture, L).rgb, 1.0) * NdotL;\n\
66
+ color += vec4(czm_textureCube(u_radianceTexture, L).rgb, 1.0) * NdotL;\n\
67
67
  weight += NdotL;\n\
68
68
  }\n\
69
69
  }\n\
@@ -5,7 +5,7 @@ out vec4 positionEC;
5
5
  void main()
6
6
  {
7
7
  positionEC = czm_modelView * position;
8
- gl_Position = czm_modelViewProjection * position;
8
+ gl_Position = czm_projection * positionEC;
9
9
 
10
10
  czm_vertexLogDepth();
11
11
  }
@@ -6,7 +6,7 @@ out vec4 positionEC;\n\
6
6
  void main()\n\
7
7
  {\n\
8
8
  positionEC = czm_modelView * position;\n\
9
- gl_Position = czm_modelViewProjection * position;\n\
9
+ gl_Position = czm_projection * positionEC;\n\
10
10
  \n\
11
11
  czm_vertexLogDepth();\n\
12
12
  }\n\
@@ -28,6 +28,13 @@ SelectedFeature selectedFeature;
28
28
 
29
29
  void main()
30
30
  {
31
+ #ifdef HAS_POINT_CLOUD_SHOW_STYLE
32
+ if (v_pointCloudShow == 0.0)
33
+ {
34
+ discard;
35
+ }
36
+ #endif
37
+
31
38
  #ifdef HAS_MODEL_SPLITTER
32
39
  modelSplitterStage();
33
40
  #endif
@@ -29,6 +29,13 @@ SelectedFeature selectedFeature;\n\
29
29
  \n\
30
30
  void main()\n\
31
31
  {\n\
32
+ #ifdef HAS_POINT_CLOUD_SHOW_STYLE\n\
33
+ if (v_pointCloudShow == 0.0)\n\
34
+ {\n\
35
+ discard;\n\
36
+ }\n\
37
+ #endif\n\
38
+ \n\
32
39
  #ifdef HAS_MODEL_SPLITTER\n\
33
40
  modelSplitterStage();\n\
34
41
  #endif\n\
@@ -145,5 +145,13 @@ void main()
145
145
  gl_PointSize *= show;
146
146
  #endif
147
147
 
148
- gl_Position = show * positionClip;
148
+ // Important NOT to compute gl_Position = show * positionClip or we hit:
149
+ // https://github.com/CesiumGS/cesium/issues/11270
150
+ //
151
+ // We will discard points with v_pointCloudShow == 0 in the fragment shader.
152
+ gl_Position = positionClip;
153
+
154
+ #ifdef HAS_POINT_CLOUD_SHOW_STYLE
155
+ v_pointCloudShow = show;
156
+ #endif
149
157
  }
@@ -146,6 +146,14 @@ void main()\n\
146
146
  gl_PointSize *= show;\n\
147
147
  #endif\n\
148
148
  \n\
149
- gl_Position = show * positionClip;\n\
149
+ // Important NOT to compute gl_Position = show * positionClip or we hit:\n\
150
+ // https://github.com/CesiumGS/cesium/issues/11270\n\
151
+ //\n\
152
+ // We will discard points with v_pointCloudShow == 0 in the fragment shader.\n\
153
+ gl_Position = positionClip;\n\
154
+ \n\
155
+ #ifdef HAS_POINT_CLOUD_SHOW_STYLE\n\
156
+ v_pointCloudShow = show;\n\
157
+ #endif\n\
150
158
  }\n\
151
159
  ";
@@ -5,16 +5,21 @@ uniform sampler2D depthTexture;
5
5
  uniform float intensity;
6
6
  uniform float bias;
7
7
  uniform float lengthCap;
8
- uniform float stepSize;
9
- uniform float frustumLength;
8
+ uniform int stepCount;
9
+ uniform int directionCount;
10
10
 
11
- vec3 pixelToEye(vec2 screenCoordinate)
11
+ vec4 pixelToEye(vec2 screenCoordinate)
12
12
  {
13
13
  vec2 uv = screenCoordinate / czm_viewport.zw;
14
14
  float depth = czm_readDepth(depthTexture, uv);
15
15
  vec2 xy = 2.0 * uv - vec2(1.0);
16
16
  vec4 posEC = czm_inverseProjection * vec4(xy, depth, 1.0);
17
- return posEC.xyz / posEC.w;
17
+ posEC = posEC / posEC.w;
18
+ // Avoid numerical error at far plane
19
+ if (depth >= 1.0) {
20
+ posEC.z = czm_currentFrustum.y;
21
+ }
22
+ return posEC;
18
23
  }
19
24
 
20
25
  // Reconstruct surface normal in eye coordinates, avoiding edges
@@ -22,10 +27,10 @@ vec3 getNormalXEdge(vec3 positionEC)
22
27
  {
23
28
  // Find the 3D surface positions at adjacent screen pixels
24
29
  vec2 centerCoord = gl_FragCoord.xy;
25
- vec3 positionLeft = pixelToEye(centerCoord + vec2(-1.0, 0.0));
26
- vec3 positionRight = pixelToEye(centerCoord + vec2(1.0, 0.0));
27
- vec3 positionUp = pixelToEye(centerCoord + vec2(0.0, 1.0));
28
- vec3 positionDown = pixelToEye(centerCoord + vec2(0.0, -1.0));
30
+ vec3 positionLeft = pixelToEye(centerCoord + vec2(-1.0, 0.0)).xyz;
31
+ vec3 positionRight = pixelToEye(centerCoord + vec2(1.0, 0.0)).xyz;
32
+ vec3 positionUp = pixelToEye(centerCoord + vec2(0.0, 1.0)).xyz;
33
+ vec3 positionDown = pixelToEye(centerCoord + vec2(0.0, -1.0)).xyz;
29
34
 
30
35
  // Compute potential tangent vectors
31
36
  vec3 dx0 = positionEC - positionLeft;
@@ -40,22 +45,35 @@ vec3 getNormalXEdge(vec3 positionEC)
40
45
  return normalize(cross(dx, dy));
41
46
  }
42
47
 
48
+ const float sqrtTwoPi = sqrt(czm_twoPi);
49
+
50
+ float gaussian(float x, float standardDeviation) {
51
+ float argument = x / standardDeviation;
52
+ return exp(-0.5 * argument * argument) / (sqrtTwoPi * standardDeviation);
53
+ }
54
+
43
55
  void main(void)
44
56
  {
45
- vec3 positionEC = pixelToEye(gl_FragCoord.xy);
57
+ vec4 positionEC = pixelToEye(gl_FragCoord.xy);
46
58
 
47
- if (positionEC.z > frustumLength)
59
+ // Exit if we are too close to the back of the frustum, where the depth value is invalid.
60
+ float maxValidDepth = czm_currentFrustum.y - lengthCap;
61
+ if (-positionEC.z > maxValidDepth)
48
62
  {
49
63
  out_FragColor = vec4(1.0);
50
64
  return;
51
65
  }
52
66
 
53
- vec3 normalEC = getNormalXEdge(positionEC);
67
+ vec3 normalEC = getNormalXEdge(positionEC.xyz);
68
+ float gaussianVariance = lengthCap * sqrt(-positionEC.z);
69
+ // Choose a step length such that the marching stops just before 3 * variance.
70
+ float stepLength = 3.0 * gaussianVariance / (float(stepCount) + 1.0);
71
+ float metersPerPixel = czm_metersPerPixel(positionEC, 1.0);
72
+ // Minimum step is 1 pixel to avoid double sampling
73
+ float pixelsPerStep = max(stepLength / metersPerPixel, 1.0);
74
+ stepLength = pixelsPerStep * metersPerPixel;
54
75
 
55
- float ao = 0.0;
56
-
57
- const int ANGLE_STEPS = 4;
58
- float angleStepScale = 1.0 / float(ANGLE_STEPS);
76
+ float angleStepScale = 1.0 / float(directionCount);
59
77
  float angleStep = angleStepScale * czm_twoPi;
60
78
  float cosStep = cos(angleStep);
61
79
  float sinStep = sin(angleStep);
@@ -67,48 +85,59 @@ void main(void)
67
85
  float randomVal = texture(randomTexture, randomTexCoord).x;
68
86
  vec2 sampleDirection = vec2(cos(angleStep * randomVal), sin(angleStep * randomVal));
69
87
 
88
+ float ao = 0.0;
70
89
  // Loop over sampling directions
71
- for (int i = 0; i < ANGLE_STEPS; i++)
90
+ #if __VERSION__ == 300
91
+ for (int i = 0; i < directionCount; i++)
92
+ {
93
+ #else
94
+ for (int i = 0; i < 16; i++)
72
95
  {
96
+ if (i >= directionCount) {
97
+ break;
98
+ }
99
+ #endif
73
100
  sampleDirection = rotateStep * sampleDirection;
74
101
 
75
102
  float localAO = 0.0;
76
- vec2 radialStep = stepSize * sampleDirection;
103
+ vec2 radialStep = pixelsPerStep * sampleDirection;
77
104
 
78
- for (int j = 0; j < 6; j++)
105
+ #if __VERSION__ == 300
106
+ for (int j = 0; j < stepCount; j++)
107
+ {
108
+ #else
109
+ for (int j = 0; j < 64; j++)
79
110
  {
111
+ if (j >= stepCount) {
112
+ break;
113
+ }
114
+ #endif
80
115
  // Step along sampling direction, away from output pixel
81
- vec2 newCoords = floor(gl_FragCoord.xy + float(j + 1) * radialStep) + vec2(0.5);
116
+ vec2 samplePixel = floor(gl_FragCoord.xy + float(j + 1) * radialStep) + vec2(0.5);
82
117
 
83
118
  // Exit if we stepped off the screen
84
- if (clamp(newCoords, vec2(0.0), czm_viewport.zw) != newCoords)
85
- {
119
+ if (clamp(samplePixel, vec2(0.0), czm_viewport.zw) != samplePixel) {
86
120
  break;
87
121
  }
88
122
 
89
- vec3 stepPositionEC = pixelToEye(newCoords);
90
- vec3 stepVector = stepPositionEC - positionEC;
91
- float stepLength = length(stepVector);
92
-
93
- if (stepLength > lengthCap)
94
- {
95
- break;
96
- }
123
+ // Compute step vector from output point to sampled point
124
+ vec4 samplePositionEC = pixelToEye(samplePixel);
125
+ vec3 stepVector = samplePositionEC.xyz - positionEC.xyz;
97
126
 
127
+ // Estimate the angle from the surface normal.
98
128
  float dotVal = clamp(dot(normalEC, normalize(stepVector)), 0.0, 1.0);
99
- if (dotVal < bias)
100
- {
101
- dotVal = 0.0;
102
- }
129
+ dotVal = czm_branchFreeTernary(dotVal > bias, dotVal, 0.0);
130
+ dotVal = czm_branchFreeTernary(-samplePositionEC.z <= maxValidDepth, dotVal, 0.0);
103
131
 
104
- float weight = stepLength / lengthCap;
105
- weight = 1.0 - weight * weight;
106
- localAO = max(localAO, dotVal * weight);
132
+ // Weight contribution based on the distance from the output point
133
+ float sampleDistance = length(stepVector);
134
+ float weight = gaussian(sampleDistance, gaussianVariance);
135
+ localAO += weight * dotVal;
107
136
  }
108
137
  ao += localAO;
109
138
  }
110
139
 
111
- ao *= angleStepScale;
140
+ ao *= angleStepScale * stepLength;
112
141
  ao = 1.0 - clamp(ao, 0.0, 1.0);
113
142
  ao = pow(ao, intensity);
114
143
  out_FragColor = vec4(vec3(ao), 1.0);
@@ -6,16 +6,21 @@ uniform sampler2D depthTexture;\n\
6
6
  uniform float intensity;\n\
7
7
  uniform float bias;\n\
8
8
  uniform float lengthCap;\n\
9
- uniform float stepSize;\n\
10
- uniform float frustumLength;\n\
9
+ uniform int stepCount;\n\
10
+ uniform int directionCount;\n\
11
11
  \n\
12
- vec3 pixelToEye(vec2 screenCoordinate)\n\
12
+ vec4 pixelToEye(vec2 screenCoordinate)\n\
13
13
  {\n\
14
14
  vec2 uv = screenCoordinate / czm_viewport.zw;\n\
15
15
  float depth = czm_readDepth(depthTexture, uv);\n\
16
16
  vec2 xy = 2.0 * uv - vec2(1.0);\n\
17
17
  vec4 posEC = czm_inverseProjection * vec4(xy, depth, 1.0);\n\
18
- return posEC.xyz / posEC.w;\n\
18
+ posEC = posEC / posEC.w;\n\
19
+ // Avoid numerical error at far plane\n\
20
+ if (depth >= 1.0) {\n\
21
+ posEC.z = czm_currentFrustum.y;\n\
22
+ }\n\
23
+ return posEC;\n\
19
24
  }\n\
20
25
  \n\
21
26
  // Reconstruct surface normal in eye coordinates, avoiding edges\n\
@@ -23,10 +28,10 @@ vec3 getNormalXEdge(vec3 positionEC)\n\
23
28
  {\n\
24
29
  // Find the 3D surface positions at adjacent screen pixels\n\
25
30
  vec2 centerCoord = gl_FragCoord.xy;\n\
26
- vec3 positionLeft = pixelToEye(centerCoord + vec2(-1.0, 0.0));\n\
27
- vec3 positionRight = pixelToEye(centerCoord + vec2(1.0, 0.0));\n\
28
- vec3 positionUp = pixelToEye(centerCoord + vec2(0.0, 1.0));\n\
29
- vec3 positionDown = pixelToEye(centerCoord + vec2(0.0, -1.0));\n\
31
+ vec3 positionLeft = pixelToEye(centerCoord + vec2(-1.0, 0.0)).xyz;\n\
32
+ vec3 positionRight = pixelToEye(centerCoord + vec2(1.0, 0.0)).xyz;\n\
33
+ vec3 positionUp = pixelToEye(centerCoord + vec2(0.0, 1.0)).xyz;\n\
34
+ vec3 positionDown = pixelToEye(centerCoord + vec2(0.0, -1.0)).xyz;\n\
30
35
  \n\
31
36
  // Compute potential tangent vectors\n\
32
37
  vec3 dx0 = positionEC - positionLeft;\n\
@@ -41,22 +46,35 @@ vec3 getNormalXEdge(vec3 positionEC)\n\
41
46
  return normalize(cross(dx, dy));\n\
42
47
  }\n\
43
48
  \n\
49
+ const float sqrtTwoPi = sqrt(czm_twoPi);\n\
50
+ \n\
51
+ float gaussian(float x, float standardDeviation) {\n\
52
+ float argument = x / standardDeviation;\n\
53
+ return exp(-0.5 * argument * argument) / (sqrtTwoPi * standardDeviation);\n\
54
+ }\n\
55
+ \n\
44
56
  void main(void)\n\
45
57
  {\n\
46
- vec3 positionEC = pixelToEye(gl_FragCoord.xy);\n\
58
+ vec4 positionEC = pixelToEye(gl_FragCoord.xy);\n\
47
59
  \n\
48
- if (positionEC.z > frustumLength)\n\
60
+ // Exit if we are too close to the back of the frustum, where the depth value is invalid.\n\
61
+ float maxValidDepth = czm_currentFrustum.y - lengthCap;\n\
62
+ if (-positionEC.z > maxValidDepth)\n\
49
63
  {\n\
50
64
  out_FragColor = vec4(1.0);\n\
51
65
  return;\n\
52
66
  }\n\
53
67
  \n\
54
- vec3 normalEC = getNormalXEdge(positionEC);\n\
68
+ vec3 normalEC = getNormalXEdge(positionEC.xyz);\n\
69
+ float gaussianVariance = lengthCap * sqrt(-positionEC.z);\n\
70
+ // Choose a step length such that the marching stops just before 3 * variance.\n\
71
+ float stepLength = 3.0 * gaussianVariance / (float(stepCount) + 1.0);\n\
72
+ float metersPerPixel = czm_metersPerPixel(positionEC, 1.0);\n\
73
+ // Minimum step is 1 pixel to avoid double sampling\n\
74
+ float pixelsPerStep = max(stepLength / metersPerPixel, 1.0);\n\
75
+ stepLength = pixelsPerStep * metersPerPixel;\n\
55
76
  \n\
56
- float ao = 0.0;\n\
57
- \n\
58
- const int ANGLE_STEPS = 4;\n\
59
- float angleStepScale = 1.0 / float(ANGLE_STEPS);\n\
77
+ float angleStepScale = 1.0 / float(directionCount);\n\
60
78
  float angleStep = angleStepScale * czm_twoPi;\n\
61
79
  float cosStep = cos(angleStep);\n\
62
80
  float sinStep = sin(angleStep);\n\
@@ -68,48 +86,59 @@ void main(void)\n\
68
86
  float randomVal = texture(randomTexture, randomTexCoord).x;\n\
69
87
  vec2 sampleDirection = vec2(cos(angleStep * randomVal), sin(angleStep * randomVal));\n\
70
88
  \n\
89
+ float ao = 0.0;\n\
71
90
  // Loop over sampling directions\n\
72
- for (int i = 0; i < ANGLE_STEPS; i++)\n\
91
+ #if __VERSION__ == 300\n\
92
+ for (int i = 0; i < directionCount; i++)\n\
93
+ {\n\
94
+ #else\n\
95
+ for (int i = 0; i < 16; i++)\n\
73
96
  {\n\
97
+ if (i >= directionCount) {\n\
98
+ break;\n\
99
+ }\n\
100
+ #endif\n\
74
101
  sampleDirection = rotateStep * sampleDirection;\n\
75
102
  \n\
76
103
  float localAO = 0.0;\n\
77
- vec2 radialStep = stepSize * sampleDirection;\n\
104
+ vec2 radialStep = pixelsPerStep * sampleDirection;\n\
78
105
  \n\
79
- for (int j = 0; j < 6; j++)\n\
106
+ #if __VERSION__ == 300\n\
107
+ for (int j = 0; j < stepCount; j++)\n\
108
+ {\n\
109
+ #else\n\
110
+ for (int j = 0; j < 64; j++)\n\
80
111
  {\n\
112
+ if (j >= stepCount) {\n\
113
+ break;\n\
114
+ }\n\
115
+ #endif\n\
81
116
  // Step along sampling direction, away from output pixel\n\
82
- vec2 newCoords = floor(gl_FragCoord.xy + float(j + 1) * radialStep) + vec2(0.5);\n\
117
+ vec2 samplePixel = floor(gl_FragCoord.xy + float(j + 1) * radialStep) + vec2(0.5);\n\
83
118
  \n\
84
119
  // Exit if we stepped off the screen\n\
85
- if (clamp(newCoords, vec2(0.0), czm_viewport.zw) != newCoords)\n\
86
- {\n\
120
+ if (clamp(samplePixel, vec2(0.0), czm_viewport.zw) != samplePixel) {\n\
87
121
  break;\n\
88
122
  }\n\
89
123
  \n\
90
- vec3 stepPositionEC = pixelToEye(newCoords);\n\
91
- vec3 stepVector = stepPositionEC - positionEC;\n\
92
- float stepLength = length(stepVector);\n\
93
- \n\
94
- if (stepLength > lengthCap)\n\
95
- {\n\
96
- break;\n\
97
- }\n\
124
+ // Compute step vector from output point to sampled point\n\
125
+ vec4 samplePositionEC = pixelToEye(samplePixel);\n\
126
+ vec3 stepVector = samplePositionEC.xyz - positionEC.xyz;\n\
98
127
  \n\
128
+ // Estimate the angle from the surface normal.\n\
99
129
  float dotVal = clamp(dot(normalEC, normalize(stepVector)), 0.0, 1.0);\n\
100
- if (dotVal < bias)\n\
101
- {\n\
102
- dotVal = 0.0;\n\
103
- }\n\
130
+ dotVal = czm_branchFreeTernary(dotVal > bias, dotVal, 0.0);\n\
131
+ dotVal = czm_branchFreeTernary(-samplePositionEC.z <= maxValidDepth, dotVal, 0.0);\n\
104
132
  \n\
105
- float weight = stepLength / lengthCap;\n\
106
- weight = 1.0 - weight * weight;\n\
107
- localAO = max(localAO, dotVal * weight);\n\
133
+ // Weight contribution based on the distance from the output point\n\
134
+ float sampleDistance = length(stepVector);\n\
135
+ float weight = gaussian(sampleDistance, gaussianVariance);\n\
136
+ localAO += weight * dotVal;\n\
108
137
  }\n\
109
138
  ao += localAO;\n\
110
139
  }\n\
111
140
  \n\
112
- ao *= angleStepScale;\n\
141
+ ao *= angleStepScale * stepLength;\n\
113
142
  ao = 1.0 - clamp(ao, 0.0, 1.0);\n\
114
143
  ao = pow(ao, intensity);\n\
115
144
  out_FragColor = vec4(vec3(ao), 1.0);\n\