@cesium/engine 11.1.0 → 12.0.1

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 (159) hide show
  1. package/Build/Workers/{chunk-U72QNFOJ.js → chunk-22FZ334F.js} +10 -10
  2. package/Build/Workers/{chunk-GNBFYG7F.js → chunk-2F42VIW6.js} +13 -13
  3. package/Build/Workers/{chunk-K4GQUNB5.js → chunk-2IJZVFHY.js} +5 -5
  4. package/Build/Workers/{chunk-7KTQP4VB.js → chunk-2XOUWNPN.js} +5 -5
  5. package/Build/Workers/{chunk-IBLIYJZR.js → chunk-3Y4UGAYI.js} +6 -6
  6. package/Build/Workers/{chunk-VJZB3WAV.js → chunk-54NYY4U4.js} +7 -7
  7. package/Build/Workers/{chunk-DHYHSFFJ.js → chunk-647NL6VU.js} +2 -2
  8. package/Build/Workers/{chunk-CKY7HOHV.js → chunk-76KRKKEF.js} +9 -9
  9. package/Build/Workers/{chunk-BHQJ2NT7.js → chunk-7CKQ7PVJ.js} +6 -6
  10. package/Build/Workers/{chunk-5PTXS2GO.js → chunk-7D6T2WYT.js} +7 -7
  11. package/Build/Workers/{chunk-PRGYLLJT.js → chunk-7EBHNJTG.js} +1 -1
  12. package/Build/Workers/{chunk-YFXQECWV.js → chunk-AER5CLXD.js} +5 -5
  13. package/Build/Workers/{chunk-N5KJGGCM.js → chunk-AGYO4ZSF.js} +17 -17
  14. package/Build/Workers/{chunk-VU2MNO7L.js → chunk-BH5M522L.js} +7 -7
  15. package/Build/Workers/{chunk-MXIZJAPH.js → chunk-COHL4R3G.js} +1 -1
  16. package/Build/Workers/{chunk-FIGIZHAQ.js → chunk-DJ7K7EYK.js} +11 -11
  17. package/Build/Workers/{chunk-3Q2L65QU.js → chunk-DR56WFYZ.js} +7 -7
  18. package/Build/Workers/{chunk-AD63PIY6.js → chunk-EMCXAVSG.js} +2 -2
  19. package/Build/Workers/{chunk-YSGTGQQO.js → chunk-ENARO52I.js} +14 -14
  20. package/Build/Workers/{chunk-5OOFQLKF.js → chunk-ETXXXGMP.js} +7 -7
  21. package/Build/Workers/{chunk-E27BLMDD.js → chunk-GBPW65E3.js} +6 -6
  22. package/Build/Workers/{chunk-NGPPMXRM.js → chunk-GRQQHWMD.js} +7 -7
  23. package/Build/Workers/{chunk-SMDOP47J.js → chunk-GSJ6LWIS.js} +10 -10
  24. package/Build/Workers/{chunk-26GA3JAM.js → chunk-H3RMGG7L.js} +5 -5
  25. package/Build/Workers/{chunk-PGRPDNHG.js → chunk-IAX6MIST.js} +17 -17
  26. package/Build/Workers/{chunk-5ODQSF26.js → chunk-IJWXYSFC.js} +2 -2
  27. package/Build/Workers/{chunk-C6YYBQXW.js → chunk-IVCFTVYW.js} +4 -4
  28. package/Build/Workers/{chunk-JW4FOI6M.js → chunk-JAKTB6CE.js} +11 -11
  29. package/Build/Workers/{chunk-TKVT5GQM.js → chunk-JPNFQRN7.js} +13 -13
  30. package/Build/Workers/{chunk-E63IIM5T.js → chunk-K7QC3WDT.js} +1 -1
  31. package/Build/Workers/{chunk-TGONEMZO.js → chunk-KJ65M35B.js} +11 -11
  32. package/Build/Workers/{chunk-2ZGOQXYU.js → chunk-KKMH4BKN.js} +6 -6
  33. package/Build/Workers/{chunk-76BYBWHP.js → chunk-LBNGHEJY.js} +4 -4
  34. package/Build/Workers/{chunk-XY4BATBS.js → chunk-LVHHB5T6.js} +4 -4
  35. package/Build/Workers/{chunk-S6MRMMQU.js → chunk-MV7YO647.js} +6 -6
  36. package/Build/Workers/{chunk-6CHGCNMW.js → chunk-NELAPOO6.js} +2 -2
  37. package/Build/Workers/{chunk-GESF4OXQ.js → chunk-NL73INJS.js} +2 -2
  38. package/Build/Workers/{chunk-GGZJN2TI.js → chunk-PH3T7LNP.js} +15 -15
  39. package/Build/Workers/{chunk-YZ733KKS.js → chunk-PISTPJXS.js} +12 -12
  40. package/Build/Workers/{chunk-GWCFU2SA.js → chunk-PJHRB4YJ.js} +7 -7
  41. package/Build/Workers/{chunk-I2ITFFPX.js → chunk-PNA47CR7.js} +1 -1
  42. package/Build/Workers/{chunk-7JO7GPJN.js → chunk-Q7IIOKAT.js} +1 -1
  43. package/Build/Workers/{chunk-27HUZ7SA.js → chunk-U7SH6OK7.js} +4 -4
  44. package/Build/Workers/{chunk-M3GMB5OP.js → chunk-VHGI7D3P.js} +10 -10
  45. package/Build/Workers/{chunk-FDOV2LBJ.js → chunk-VO4SXJXT.js} +7 -7
  46. package/Build/Workers/{chunk-7BMOHCPM.js → chunk-VXVQITFC.js} +13 -13
  47. package/Build/Workers/{chunk-DI5NGJUP.js → chunk-WMHJAREU.js} +2 -2
  48. package/Build/Workers/{chunk-EJZTDTUH.js → chunk-X6YBZOOA.js} +4 -4
  49. package/Build/Workers/{chunk-472HQ3EH.js → chunk-XDJ7V4NZ.js} +5 -5
  50. package/Build/Workers/{chunk-E6V6SQZW.js → chunk-YT5PQMSP.js} +6 -6
  51. package/Build/Workers/{chunk-O3E4OAOE.js → chunk-ZCCI55EY.js} +13 -13
  52. package/Build/Workers/{chunk-7O373FFS.js → chunk-ZPTNVB3S.js} +8 -8
  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 +29 -29
  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/BoundingSphere.js +1 -1
  102. package/Source/Core/Color.js +1 -1
  103. package/Source/Core/CorridorGeometryLibrary.js +4 -4
  104. package/Source/Core/EllipseGeometry.js +1 -1
  105. package/Source/Core/EllipsoidGeodesic.js +1 -1
  106. package/Source/Core/FrustumGeometry.js +1 -1
  107. package/Source/Core/Ion.js +1 -1
  108. package/Source/Core/Math.js +2 -0
  109. package/Source/Core/PolylineVolumeGeometryLibrary.js +2 -2
  110. package/Source/Core/decodeGoogleEarthEnterpriseData.js +1 -1
  111. package/Source/DataSources/DataSourceDisplay.js +1 -1
  112. package/Source/DataSources/ModelGraphics.js +1 -0
  113. package/Source/Renderer/AutomaticUniforms.js +13 -0
  114. package/Source/Renderer/CubeMap.js +89 -12
  115. package/Source/Renderer/CubeMapFace.js +90 -13
  116. package/Source/Renderer/UniformState.js +13 -0
  117. package/Source/Scene/ArcGisMapService.js +1 -1
  118. package/Source/Scene/Atmosphere.js +22 -0
  119. package/Source/Scene/BingMapsImageryProvider.js +1 -1
  120. package/Source/Scene/Cesium3DTileset.js +39 -0
  121. package/Source/Scene/DynamicEnvironmentMapManager.js +894 -0
  122. package/Source/Scene/Fog.js +75 -82
  123. package/Source/Scene/FrameState.js +5 -3
  124. package/Source/Scene/ImageBasedLighting.js +7 -64
  125. package/Source/Scene/Model/AtmospherePipelineStage.js +10 -5
  126. package/Source/Scene/Model/ImageBasedLightingPipelineStage.js +43 -21
  127. package/Source/Scene/Model/Model.js +98 -25
  128. package/Source/Scene/Model/Model3DTileContent.js +5 -0
  129. package/Source/Scene/Model/ModelSceneGraph.js +1 -0
  130. package/Source/Scene/ScreenSpaceCameraController.js +20 -1
  131. package/Source/Shaders/Builtin/Functions/computeAtmosphereColor.glsl +44 -0
  132. package/Source/Shaders/Builtin/Functions/computeAtmosphereColor.js +44 -0
  133. package/Source/Shaders/Builtin/Functions/computeScattering.glsl +0 -1
  134. package/Source/Shaders/Builtin/Functions/computeScattering.js +0 -1
  135. package/Source/Shaders/Builtin/Functions/sphericalHarmonics.glsl +3 -1
  136. package/Source/Shaders/Builtin/Functions/sphericalHarmonics.js +3 -1
  137. package/Source/Shaders/ComputeIrradianceFS.glsl +103 -0
  138. package/Source/Shaders/ComputeIrradianceFS.js +105 -0
  139. package/Source/Shaders/ComputeRadianceMapFS.glsl +107 -0
  140. package/Source/Shaders/ComputeRadianceMapFS.js +109 -0
  141. package/Source/Shaders/ConvolveSpecularMapFS.glsl +70 -0
  142. package/Source/Shaders/ConvolveSpecularMapFS.js +72 -0
  143. package/Source/Shaders/ConvolveSpecularMapVS.glsl +24 -0
  144. package/Source/Shaders/ConvolveSpecularMapVS.js +26 -0
  145. package/Source/Shaders/GlobeFS.glsl +1 -2
  146. package/Source/Shaders/GlobeFS.js +1 -2
  147. package/Source/Shaders/Model/AtmosphereStageFS.glsl +1 -4
  148. package/Source/Shaders/Model/AtmosphereStageFS.js +1 -4
  149. package/Source/Shaders/Model/ImageBasedLightingStageFS.glsl +2 -155
  150. package/Source/Shaders/Model/ImageBasedLightingStageFS.js +3 -156
  151. package/Source/Shaders/Model/LightingStageFS.glsl +3 -22
  152. package/Source/Shaders/Model/LightingStageFS.js +3 -22
  153. package/Source/Shaders/SkyBoxVS.glsl +0 -1
  154. package/Source/Shaders/SkyBoxVS.js +0 -1
  155. package/Source/Widget/CesiumWidget.js +776 -1
  156. package/Source/Workers/decodeGoogleEarthEnterprisePacket.js +1 -1
  157. package/index.d.ts +281 -12
  158. package/index.js +62 -57
  159. package/package.json +2 -2
@@ -1,5 +1,6 @@
1
1
  import Cartesian3 from "../Core/Cartesian3.js";
2
2
  import defined from "../Core/defined.js";
3
+ import DeveloperError from "../Core/DeveloperError.js";
3
4
  import CesiumMath from "../Core/Math.js";
4
5
  import SceneMode from "./SceneMode.js";
5
6
 
@@ -7,6 +8,8 @@ import SceneMode from "./SceneMode.js";
7
8
  * Blends the atmosphere to geometry far from the camera for horizon views. Allows for additional
8
9
  * performance improvements by rendering less geometry and dispatching less terrain requests.
9
10
  *
11
+ * @demo {@link https://sandcastle.cesium.com/index.html?src=Fog.html|Cesium Sandcastle Fog Demo}
12
+ *
10
13
  * @alias Fog
11
14
  * @constructor
12
15
  */
@@ -15,6 +18,9 @@ function Fog() {
15
18
  * <code>true</code> if fog is enabled, <code>false</code> otherwise.
16
19
  * @type {boolean}
17
20
  * @default true
21
+ * @example
22
+ * // Disable fog in the scene
23
+ * viewer.scene.fog.enabled = false;
18
24
  */
19
25
  this.enabled = true;
20
26
  /**
@@ -22,6 +28,10 @@ function Fog() {
22
28
  * This allows to benefits from optimized tile loading strategy based on fog density without the actual visual rendering.
23
29
  * @type {boolean}
24
30
  * @default true
31
+ * @example
32
+ * // Use fog culling but don't render it
33
+ * viewer.scene.fog.enabled = true;
34
+ * viewer.scene.fog.renderable = false;
25
35
  */
26
36
  this.renderable = true;
27
37
  /**
@@ -31,9 +41,36 @@ function Fog() {
31
41
  * 1000.0m above the ellipsoid, increasing the value to 3.0e-3 will cause many tiles close to the viewer be culled.
32
42
  * Decreasing the value will push the fog further from the viewer, but decrease performance as more of the terrain is rendered.
33
43
  * @type {number}
34
- * @default 2.0e-4
44
+ * @default 0.0006
45
+ * @example
46
+ * // Double the default fog density
47
+ * viewer.scene.fog.density = 0.0012;
48
+ */
49
+ this.density = 0.0006;
50
+ /**
51
+ * A scalar used in the function to adjust density based on the height of the camera above the terrain.
52
+ * @type {number}
53
+ * @default 0.001
35
54
  */
36
- this.density = 2.0e-4;
55
+ this.heightScalar = 0.001;
56
+ this._heightFalloff = 0.59;
57
+ /**
58
+ * The maximum height fog is applied. If the camera is above this height fog will be disabled.
59
+ * @type {number}
60
+ * @default 800000.0
61
+ */
62
+ this.maxHeight = 800000.0;
63
+ /**
64
+ * A scalar that impacts the visual density of fog. This value does not impact the culling of terrain.
65
+ * Use in combination with the {@link Fog.density} to make fog appear more or less dense.
66
+ * @type {number}
67
+ * @default 0.15
68
+ * @experimental The value of this scalar may not be final and is subject to change.
69
+ * @example
70
+ * // Increase fog appearance effect
71
+ * viewer.scene.fog.visualDensityScalar = 0.6;
72
+ */
73
+ this.visualDensityScalar = 0.15;
37
74
  /**
38
75
  * A factor used to increase the screen space error of terrain tiles when they are partially in fog. The effect is to reduce
39
76
  * the number of terrain tiles requested for rendering. If set to zero, the feature will be disabled. If the value is increased
@@ -52,76 +89,36 @@ function Fog() {
52
89
  this.minimumBrightness = 0.03;
53
90
  }
54
91
 
55
- // These values were found by sampling the density at certain views and finding at what point culled tiles impacted the view at the horizon.
56
- const heightsTable = [
57
- 359.393, 800.749, 1275.6501, 2151.1192, 3141.7763, 4777.5198, 6281.2493,
58
- 12364.307, 15900.765, 49889.0549, 78026.8259, 99260.7344, 120036.3873,
59
- 151011.0158, 156091.1953, 203849.3112, 274866.9803, 319916.3149, 493552.0528,
60
- 628733.5874,
61
- ];
62
- const densityTable = [
63
- 2.0e-5, 2.0e-4, 1.0e-4, 7.0e-5, 5.0e-5, 4.0e-5, 3.0e-5, 1.9e-5, 1.0e-5,
64
- 8.5e-6, 6.2e-6, 5.8e-6, 5.3e-6, 5.2e-6, 5.1e-6, 4.2e-6, 4.0e-6, 3.4e-6,
65
- 2.6e-6, 2.2e-6,
66
- ];
67
-
68
- // Scale densities by 1e6 to bring lowest value to ~1. Prevents divide by zero.
69
- for (let i = 0; i < densityTable.length; ++i) {
70
- densityTable[i] *= 1.0e6;
71
- }
72
- // Change range to [0, 1].
73
- const tableStartDensity = densityTable[1];
74
- const tableEndDensity = densityTable[densityTable.length - 1];
75
- for (let j = 0; j < densityTable.length; ++j) {
76
- densityTable[j] =
77
- (densityTable[j] - tableEndDensity) / (tableStartDensity - tableEndDensity);
78
- }
79
-
80
- let tableLastIndex = 0;
81
-
82
- function findInterval(height) {
83
- const heights = heightsTable;
84
- const length = heights.length;
85
-
86
- if (height < heights[0]) {
87
- tableLastIndex = 0;
88
- return tableLastIndex;
89
- } else if (height > heights[length - 1]) {
90
- tableLastIndex = length - 2;
91
- return tableLastIndex;
92
- }
93
-
94
- // Take advantage of temporal coherence by checking current, next and previous intervals
95
- // for containment of time.
96
- if (height >= heights[tableLastIndex]) {
97
- if (tableLastIndex + 1 < length && height < heights[tableLastIndex + 1]) {
98
- return tableLastIndex;
99
- } else if (
100
- tableLastIndex + 2 < length &&
101
- height < heights[tableLastIndex + 2]
102
- ) {
103
- ++tableLastIndex;
104
- return tableLastIndex;
105
- }
106
- } else if (tableLastIndex - 1 >= 0 && height >= heights[tableLastIndex - 1]) {
107
- --tableLastIndex;
108
- return tableLastIndex;
109
- }
110
-
111
- // The above failed so do a linear search.
112
- let i;
113
- for (i = 0; i < length - 2; ++i) {
114
- if (height >= heights[i] && height < heights[i + 1]) {
115
- break;
116
- }
117
- }
118
-
119
- tableLastIndex = i;
120
- return tableLastIndex;
121
- }
92
+ Object.defineProperties(Fog.prototype, {
93
+ /**
94
+ * Exponent factor used in the function to adjust how density changes based on the height of the camera above the ellipsoid. Smaller values produce a more gradual transition as camera height increases.
95
+ * Value must be greater than 0.
96
+ * @memberof Fog.prototype
97
+ * @type {number}
98
+ * @default 0.59
99
+ */
100
+ heightFalloff: {
101
+ get: function () {
102
+ return this._heightFalloff;
103
+ },
104
+ set: function (value) {
105
+ //>>includeStart('debug', pragmas.debug);
106
+ if (defined(value) && value < 0) {
107
+ throw new DeveloperError("value must be positive.");
108
+ }
109
+ //>>includeEnd('debug');
110
+
111
+ this._heightFalloff = value;
112
+ },
113
+ },
114
+ });
122
115
 
123
116
  const scratchPositionNormal = new Cartesian3();
124
117
 
118
+ /**
119
+ * @param {FrameState} frameState
120
+ * @private
121
+ */
125
122
  Fog.prototype.update = function (frameState) {
126
123
  const enabled = (frameState.fog.enabled = this.enabled);
127
124
  if (!enabled) {
@@ -136,7 +133,7 @@ Fog.prototype.update = function (frameState) {
136
133
  // Turn off fog in space.
137
134
  if (
138
135
  !defined(positionCartographic) ||
139
- positionCartographic.height > 800000.0 ||
136
+ positionCartographic.height > this.maxHeight ||
140
137
  frameState.mode !== SceneMode.SCENE3D
141
138
  ) {
142
139
  frameState.fog.enabled = false;
@@ -145,18 +142,13 @@ Fog.prototype.update = function (frameState) {
145
142
  }
146
143
 
147
144
  const height = positionCartographic.height;
148
- const i = findInterval(height);
149
- const t = CesiumMath.clamp(
150
- (height - heightsTable[i]) / (heightsTable[i + 1] - heightsTable[i]),
151
- 0.0,
152
- 1.0,
153
- );
154
- let density = CesiumMath.lerp(densityTable[i], densityTable[i + 1], t);
155
-
156
- // Again, scale value to be in the range of densityTable (prevents divide by zero) and change to new range.
157
- const startDensity = this.density * 1.0e6;
158
- const endDensity = (startDensity / tableStartDensity) * tableEndDensity;
159
- density = density * (startDensity - endDensity) * 1.0e-6;
145
+ let density =
146
+ this.density *
147
+ this.heightScalar *
148
+ Math.pow(
149
+ Math.max(height / this.maxHeight, CesiumMath.EPSILON4),
150
+ -Math.max(this._heightFalloff, 0.0),
151
+ );
160
152
 
161
153
  // Fade fog in as the camera tilts toward the horizon.
162
154
  const positionNormal = Cartesian3.normalize(
@@ -167,6 +159,7 @@ Fog.prototype.update = function (frameState) {
167
159
  density *= 1.0 - dot;
168
160
 
169
161
  frameState.fog.density = density;
162
+ frameState.fog.visualDensityScalar = this.visualDensityScalar;
170
163
  frameState.fog.sse = this.screenSpaceErrorFactor;
171
164
  frameState.fog.minimumBrightness = this.minimumBrightness;
172
165
  };
@@ -261,9 +261,10 @@ function FrameState(context, creditDisplay, jobScheduler) {
261
261
  * @type {object}
262
262
  * @property {boolean} enabled <code>true</code> if fog is enabled, <code>false</code> otherwise. This affects both fog culling and rendering.
263
263
  * @property {boolean} renderable <code>true</code> if fog should be rendered, <code>false</code> if not. This flag should be checked in combination with fog.enabled.
264
- * @property {number} density A positive number used to mix the color and fog color based on camera distance.
265
- * @property {number} sse A scalar used to modify the screen space error of geometry partially in fog.
266
- * @property {number} minimumBrightness The minimum brightness of terrain with fog applied.
264
+ * @property {number | undefined} density A positive number used to mix the color and fog color based on camera distance.
265
+ * @property {number | undefined} visualDensityScalar A positive number to modify how impactful the fog is based off the density
266
+ * @property {number | undefined} sse A scalar used to modify the screen space error of geometry partially in fog.
267
+ * @property {number | undefined} minimumBrightness The minimum brightness of terrain with fog applied.
267
268
  */
268
269
 
269
270
  /**
@@ -277,6 +278,7 @@ function FrameState(context, creditDisplay, jobScheduler) {
277
278
  enabled: false,
278
279
  renderable: false,
279
280
  density: undefined,
281
+ visualDensityScalar: undefined,
280
282
  sse: undefined,
281
283
  minimumBrightness: undefined,
282
284
  };
@@ -20,7 +20,6 @@ import SpecularEnvironmentCubeMap from "./SpecularEnvironmentCubeMap.js";
20
20
  * @constructor
21
21
  *
22
22
  * @param {Cartesian2} [options.imageBasedLightingFactor=Cartesian2(1.0, 1.0)] Scales diffuse and specular image-based lighting from the earth, sky, atmosphere and star skybox.
23
- * @param {number} [options.luminanceAtZenith=0.2] The sun's luminance at the zenith in kilo candela per meter squared to use for this model's procedural environment map.
24
23
  * @param {Cartesian3[]} [options.sphericalHarmonicCoefficients] The third order spherical harmonic coefficients used for the diffuse color of image-based lighting.
25
24
  * @param {string} [options.specularEnvironmentMaps] A URL to a KTX2 file that contains a cube map of the specular lighting and the convoluted specular mipmaps.
26
25
  */
@@ -59,14 +58,6 @@ function ImageBasedLighting(options) {
59
58
 
60
59
  this._imageBasedLightingFactor = imageBasedLightingFactor;
61
60
 
62
- const luminanceAtZenith = defaultValue(options.luminanceAtZenith, 0.2);
63
-
64
- //>>includeStart('debug', pragmas.debug);
65
- Check.typeOf.number("options.luminanceAtZenith", luminanceAtZenith);
66
- //>>includeEnd('debug');
67
-
68
- this._luminanceAtZenith = luminanceAtZenith;
69
-
70
61
  const sphericalHarmonicCoefficients = options.sphericalHarmonicCoefficients;
71
62
 
72
63
  //>>includeStart('debug', pragmas.debug);
@@ -100,7 +91,6 @@ function ImageBasedLighting(options) {
100
91
  this._previousImageBasedLightingFactor = Cartesian2.clone(
101
92
  imageBasedLightingFactor,
102
93
  );
103
- this._previousLuminanceAtZenith = luminanceAtZenith;
104
94
  this._previousSphericalHarmonicCoefficients = sphericalHarmonicCoefficients;
105
95
  this._removeErrorListener = undefined;
106
96
  }
@@ -156,27 +146,6 @@ Object.defineProperties(ImageBasedLighting.prototype, {
156
146
  },
157
147
  },
158
148
 
159
- /**
160
- * The sun's luminance at the zenith in kilo candela per meter squared
161
- * to use for this model's procedural environment map. This is used when
162
- * {@link ImageBasedLighting#specularEnvironmentMaps} and {@link ImageBasedLighting#sphericalHarmonicCoefficients}
163
- * are not defined.
164
- *
165
- * @memberof ImageBasedLighting.prototype
166
- *
167
- * @type {number}
168
- * @default 0.2
169
- */
170
- luminanceAtZenith: {
171
- get: function () {
172
- return this._luminanceAtZenith;
173
- },
174
- set: function (value) {
175
- this._previousLuminanceAtZenith = this._luminanceAtZenith;
176
- this._luminanceAtZenith = value;
177
- },
178
- },
179
-
180
149
  /**
181
150
  * The third order spherical harmonic coefficients used for the diffuse color of image-based lighting. When <code>undefined</code>, a diffuse irradiance
182
151
  * computed from the atmosphere color is used.
@@ -269,47 +238,30 @@ Object.defineProperties(ImageBasedLighting.prototype, {
269
238
  },
270
239
 
271
240
  /**
272
- * Whether or not to use the default spherical harmonic coefficients.
241
+ * The texture atlas for the specular environment maps.
273
242
  *
274
243
  * @memberof ImageBasedLighting.prototype
275
- * @type {boolean}
244
+ * @type {SpecularEnvironmentCubeMap}
276
245
  *
277
246
  * @private
278
247
  */
279
- useDefaultSphericalHarmonics: {
248
+ specularEnvironmentCubeMap: {
280
249
  get: function () {
281
- return this._useDefaultSphericalHarmonics;
250
+ return this._specularEnvironmentCubeMap;
282
251
  },
283
252
  },
284
253
 
285
254
  /**
286
- * Whether or not the image-based lighting settings use spherical harmonic coefficients.
255
+ * Whether or not to use the default spherical harmonics coefficients.
287
256
  *
288
257
  * @memberof ImageBasedLighting.prototype
289
258
  * @type {boolean}
290
259
  *
291
260
  * @private
292
261
  */
293
- useSphericalHarmonicCoefficients: {
294
- get: function () {
295
- return (
296
- defined(this._sphericalHarmonicCoefficients) ||
297
- this._useDefaultSphericalHarmonics
298
- );
299
- },
300
- },
301
-
302
- /**
303
- * The cube map for the specular environment maps.
304
- *
305
- * @memberof ImageBasedLighting.prototype
306
- * @type {SpecularEnvironmentCubeMap}
307
- *
308
- * @private
309
- */
310
- specularEnvironmentCubeMap: {
262
+ useDefaultSphericalHarmonics: {
311
263
  get: function () {
312
- return this._specularEnvironmentCubeMap;
264
+ return this._useDefaultSphericalHarmonics;
313
265
  },
314
266
  },
315
267
 
@@ -400,15 +352,6 @@ ImageBasedLighting.prototype.update = function (frameState) {
400
352
  );
401
353
  }
402
354
 
403
- if (this._luminanceAtZenith !== this._previousLuminanceAtZenith) {
404
- this._shouldRegenerateShaders =
405
- this._shouldRegenerateShaders ||
406
- defined(this._luminanceAtZenith) !==
407
- defined(this._previousLuminanceAtZenith);
408
-
409
- this._previousLuminanceAtZenith = this._luminanceAtZenith;
410
- }
411
-
412
355
  if (
413
356
  this._previousSphericalHarmonicCoefficients !==
414
357
  this._sphericalHarmonicCoefficients
@@ -16,12 +16,17 @@ const AtmospherePipelineStage = {
16
16
  name: "AtmospherePipelineStage", // Helps with debugging
17
17
  };
18
18
 
19
+ /**
20
+ * @param {ModelRenderResources} modelRenderResources
21
+ * @param {Model} model
22
+ * @param {FrameState} frameState
23
+ */
19
24
  AtmospherePipelineStage.process = function (
20
- renderResources,
25
+ modelRenderResources,
21
26
  model,
22
27
  frameState,
23
28
  ) {
24
- const shaderBuilder = renderResources.shaderBuilder;
29
+ const shaderBuilder = modelRenderResources.shaderBuilder;
25
30
 
26
31
  shaderBuilder.addDefine("HAS_ATMOSPHERE", undefined, ShaderDestination.BOTH);
27
32
  shaderBuilder.addDefine(
@@ -37,12 +42,12 @@ AtmospherePipelineStage.process = function (
37
42
  shaderBuilder.addVertexLines([AtmosphereStageVS]);
38
43
  shaderBuilder.addFragmentLines([AtmosphereStageFS]);
39
44
 
40
- // Add a uniform so fog is only calculated when the efcfect would
41
- // be non-negligible For example when the camera is in space, fog density decreases
45
+ // Add a uniform so fog is only calculated when the effect would
46
+ // be non-negligible. For example when the camera is in space, fog density decreases
42
47
  // to 0 so fog shouldn't be rendered. Since this state may change rapidly if
43
48
  // the camera is moving, this is implemented as a uniform, not a define.
44
49
  shaderBuilder.addUniform("bool", "u_isInFog", ShaderDestination.FRAGMENT);
45
- renderResources.uniformMap.u_isInFog = function () {
50
+ modelRenderResources.uniformMap.u_isInFog = function () {
46
51
  // We only need a rough measure of distance to the model, so measure
47
52
  // from the camera to the bounding sphere center.
48
53
  const distance = Cartesian3.distance(
@@ -3,11 +3,14 @@ import defined from "../../Core/defined.js";
3
3
  import ImageBasedLightingStageFS from "../../Shaders/Model/ImageBasedLightingStageFS.js";
4
4
  import ShaderDestination from "../../Renderer/ShaderDestination.js";
5
5
  import SpecularEnvironmentCubeMap from "../SpecularEnvironmentCubeMap.js";
6
+ import Cartesian2 from "../../Core/Cartesian2.js";
6
7
 
7
8
  const ImageBasedLightingPipelineStage = {
8
9
  name: "ImageBasedLightingPipelineStage", // Helps with debugging
9
10
  };
10
11
 
12
+ const scratchCartesian = new Cartesian2();
13
+
11
14
  /**
12
15
  * Add shader code, uniforms, and defines related to image based lighting
13
16
  * @param {ModelRenderResources} renderResources
@@ -21,8 +24,18 @@ ImageBasedLightingPipelineStage.process = function (
21
24
  frameState,
22
25
  ) {
23
26
  const imageBasedLighting = model.imageBasedLighting;
27
+ const environmentMapManager = model.environmentMapManager;
24
28
  const shaderBuilder = renderResources.shaderBuilder;
25
29
 
30
+ // If environment maps or spherical harmonics are not specifically provided, use procedural lighting.
31
+ let specularEnvironmentMapAtlas;
32
+ if (!defined(imageBasedLighting.specularEnvironmentMaps)) {
33
+ specularEnvironmentMapAtlas = environmentMapManager.radianceCubeMap;
34
+ }
35
+ const sphericalHarmonicCoefficients =
36
+ imageBasedLighting.sphericalHarmonicCoefficients ??
37
+ environmentMapManager.sphericalHarmonicCoefficients;
38
+
26
39
  shaderBuilder.addDefine(
27
40
  "USE_IBL_LIGHTING",
28
41
  undefined,
@@ -47,7 +60,18 @@ ImageBasedLightingPipelineStage.process = function (
47
60
  );
48
61
  }
49
62
 
50
- if (defined(imageBasedLighting.sphericalHarmonicCoefficients)) {
63
+ if (defined(specularEnvironmentMapAtlas)) {
64
+ shaderBuilder.addDefine(
65
+ "COMPUTE_POSITION_WC_ATMOSPHERE",
66
+ undefined,
67
+ ShaderDestination.BOTH,
68
+ );
69
+ }
70
+
71
+ if (
72
+ defined(sphericalHarmonicCoefficients) &&
73
+ defined(sphericalHarmonicCoefficients[0])
74
+ ) {
51
75
  shaderBuilder.addDefine(
52
76
  "DIFFUSE_IBL",
53
77
  undefined,
@@ -72,8 +96,9 @@ ImageBasedLightingPipelineStage.process = function (
72
96
  }
73
97
 
74
98
  if (
75
- defined(imageBasedLighting.specularEnvironmentCubeMap) &&
76
- imageBasedLighting.specularEnvironmentCubeMap.ready
99
+ (defined(imageBasedLighting.specularEnvironmentCubeMap) &&
100
+ imageBasedLighting.specularEnvironmentCubeMap.ready) ||
101
+ defined(specularEnvironmentMapAtlas)
77
102
  ) {
78
103
  shaderBuilder.addDefine(
79
104
  "SPECULAR_IBL",
@@ -104,33 +129,21 @@ ImageBasedLightingPipelineStage.process = function (
104
129
  }
105
130
  }
106
131
 
107
- if (defined(imageBasedLighting.luminanceAtZenith)) {
108
- shaderBuilder.addDefine(
109
- "USE_SUN_LUMINANCE",
110
- undefined,
111
- ShaderDestination.FRAGMENT,
112
- );
113
- shaderBuilder.addUniform(
114
- "float",
115
- "model_luminanceAtZenith",
116
- ShaderDestination.FRAGMENT,
117
- );
118
- }
119
-
120
132
  shaderBuilder.addFragmentLines(ImageBasedLightingStageFS);
121
133
 
122
134
  const uniformMap = {
123
135
  model_iblFactor: function () {
124
- return imageBasedLighting.imageBasedLightingFactor;
136
+ return Cartesian2.multiplyByScalar(
137
+ imageBasedLighting.imageBasedLightingFactor,
138
+ environmentMapManager?.intensity || 1.0,
139
+ scratchCartesian,
140
+ );
125
141
  },
126
142
  model_iblReferenceFrameMatrix: function () {
127
143
  return model._iblReferenceFrameMatrix;
128
144
  },
129
- model_luminanceAtZenith: function () {
130
- return imageBasedLighting.luminanceAtZenith;
131
- },
132
145
  model_sphericalHarmonicCoefficients: function () {
133
- return imageBasedLighting.sphericalHarmonicCoefficients;
146
+ return sphericalHarmonicCoefficients;
134
147
  },
135
148
  model_specularEnvironmentMaps: function () {
136
149
  return imageBasedLighting.specularEnvironmentCubeMap.texture;
@@ -140,6 +153,15 @@ ImageBasedLightingPipelineStage.process = function (
140
153
  },
141
154
  };
142
155
 
156
+ if (defined(specularEnvironmentMapAtlas)) {
157
+ uniformMap.model_specularEnvironmentMaps = function () {
158
+ return specularEnvironmentMapAtlas;
159
+ };
160
+ uniformMap.model_specularEnvironmentMapsMaximumLOD = function () {
161
+ return environmentMapManager.maximumMipmapLevel;
162
+ };
163
+ }
164
+
143
165
  renderResources.uniformMap = combine(uniformMap, renderResources.uniformMap);
144
166
  };
145
167