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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import Cartesian3 from "../Core/Cartesian3.js";
  2. import defined from "../Core/defined.js";
  3. import DeveloperError from "../Core/DeveloperError.js";
  4. import CesiumMath from "../Core/Math.js";
  5. import SceneMode from "./SceneMode.js";
  6. /**
  7. * Blends the atmosphere to geometry far from the camera for horizon views. Allows for additional
  8. * performance improvements by rendering less geometry and dispatching less terrain requests.
  9. *
  10. * @demo {@link https://sandcastle.cesium.com/index.html?id=fog|Cesium Sandcastle Fog Demo}
  11. *
  12. * @alias Fog
  13. * @constructor
  14. */
  15. function Fog() {
  16. /**
  17. * <code>true</code> if fog is enabled, <code>false</code> otherwise.
  18. * @type {boolean}
  19. * @default true
  20. * @example
  21. * // Disable fog in the scene
  22. * viewer.scene.fog.enabled = false;
  23. */
  24. this.enabled = true;
  25. /**
  26. * <code>true</code> if fog is renderable in shaders, <code>false</code> otherwise.
  27. * This allows to benefits from optimized tile loading strategy based on fog density without the actual visual rendering.
  28. * @type {boolean}
  29. * @default true
  30. * @example
  31. * // Use fog culling but don't render it
  32. * viewer.scene.fog.enabled = true;
  33. * viewer.scene.fog.renderable = false;
  34. */
  35. this.renderable = true;
  36. /**
  37. * A scalar that determines the density of the fog. Terrain that is in full fog are culled.
  38. * The density of the fog increases as this number approaches 1.0 and becomes less dense as it approaches zero.
  39. * The more dense the fog is, the more aggressively the terrain is culled. For example, if the camera is a height of
  40. * 1000.0m above the ellipsoid, increasing the value to 3.0e-3 will cause many tiles close to the viewer be culled.
  41. * Decreasing the value will push the fog further from the viewer, but decrease performance as more of the terrain is rendered.
  42. * @type {number}
  43. * @default 0.0006
  44. * @example
  45. * // Double the default fog density
  46. * viewer.scene.fog.density = 0.0012;
  47. */
  48. this.density = 0.0006;
  49. /**
  50. * A scalar used in the function to adjust density based on the height of the camera above the terrain.
  51. * @type {number}
  52. * @default 0.001
  53. */
  54. this.heightScalar = 0.001;
  55. this._heightFalloff = 0.59;
  56. /**
  57. * The maximum height fog is applied. If the camera is above this height fog will be disabled.
  58. * @type {number}
  59. * @default 800000.0
  60. */
  61. this.maxHeight = 800000.0;
  62. /**
  63. * A scalar that impacts the visual density of fog. This value does not impact the culling of terrain.
  64. * Use in combination with the {@link Fog.density} to make fog appear more or less dense.
  65. * @type {number}
  66. * @default 0.15
  67. * @experimental The value of this scalar may not be final and is subject to change.
  68. * @example
  69. * // Increase fog appearance effect
  70. * viewer.scene.fog.visualDensityScalar = 0.6;
  71. */
  72. this.visualDensityScalar = 0.15;
  73. /**
  74. * A factor used to increase the screen space error of terrain tiles when they are partially in fog. The effect is to reduce
  75. * the number of terrain tiles requested for rendering. If set to zero, the feature will be disabled. If the value is increased
  76. * for mountainous regions, less tiles will need to be requested, but the terrain meshes near the horizon may be a noticeably
  77. * lower resolution. If the value is increased in a relatively flat area, there will be little noticeable change on the horizon.
  78. * @type {number}
  79. * @default 2.0
  80. */
  81. this.screenSpaceErrorFactor = 2.0;
  82. /**
  83. * The minimum brightness of the fog color from lighting. A value of 0.0 can cause the fog to be completely black. A value of 1.0 will not affect
  84. * the brightness at all.
  85. * @type {number}
  86. * @default 0.03
  87. */
  88. this.minimumBrightness = 0.03;
  89. }
  90. Object.defineProperties(Fog.prototype, {
  91. /**
  92. * 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.
  93. * Value must be greater than 0.
  94. * @memberof Fog.prototype
  95. * @type {number}
  96. * @default 0.59
  97. */
  98. heightFalloff: {
  99. get: function () {
  100. return this._heightFalloff;
  101. },
  102. set: function (value) {
  103. //>>includeStart('debug', pragmas.debug);
  104. if (defined(value) && value < 0) {
  105. throw new DeveloperError("value must be positive.");
  106. }
  107. //>>includeEnd('debug');
  108. this._heightFalloff = value;
  109. },
  110. },
  111. });
  112. const scratchPositionNormal = new Cartesian3();
  113. /**
  114. * @param {FrameState} frameState
  115. * @private
  116. */
  117. Fog.prototype.update = function (frameState) {
  118. const enabled = (frameState.fog.enabled = this.enabled);
  119. if (!enabled) {
  120. return;
  121. }
  122. frameState.fog.renderable = this.renderable;
  123. const camera = frameState.camera;
  124. const positionCartographic = camera.positionCartographic;
  125. // Turn off fog in space.
  126. if (
  127. !defined(positionCartographic) ||
  128. positionCartographic.height > this.maxHeight ||
  129. frameState.mode !== SceneMode.SCENE3D
  130. ) {
  131. frameState.fog.enabled = false;
  132. frameState.fog.density = 0;
  133. return;
  134. }
  135. const height = positionCartographic.height;
  136. let density =
  137. this.density *
  138. this.heightScalar *
  139. Math.pow(
  140. Math.max(height / this.maxHeight, CesiumMath.EPSILON4),
  141. -Math.max(this._heightFalloff, 0.0),
  142. );
  143. // Fade fog in as the camera tilts toward the horizon.
  144. const positionNormal = Cartesian3.normalize(
  145. camera.positionWC,
  146. scratchPositionNormal,
  147. );
  148. const dot = Math.abs(Cartesian3.dot(camera.directionWC, positionNormal));
  149. density *= 1.0 - dot;
  150. frameState.fog.density = density;
  151. frameState.fog.visualDensityScalar = this.visualDensityScalar;
  152. frameState.fog.sse = this.screenSpaceErrorFactor;
  153. frameState.fog.minimumBrightness = this.minimumBrightness;
  154. };
  155. export default Fog;