Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 156x 1x 1x 1x 92x 1x 1x 97x 3x 94x 94x 2x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 54x 54x 54x 92x 92x 55x 55x 55x 1x 55x 7x 55x 55x 55x 55x 55x 92x 92x 1x 1x 1x 150x 150x 150x 150x | import Cartesian3 from "../Core/Cartesian3.js";
import defined from "../Core/defined.js";
import destroyObject from "../Core/destroyObject.js";
import Ellipsoid from "../Core/Ellipsoid.js";
import EllipsoidGeometry from "../Core/EllipsoidGeometry.js";
import GeometryPipeline from "../Core/GeometryPipeline.js";
import CesiumMath from "../Core/Math.js";
import Matrix4 from "../Core/Matrix4.js";
import VertexFormat from "../Core/VertexFormat.js";
import BufferUsage from "../Renderer/BufferUsage.js";
import DrawCommand from "../Renderer/DrawCommand.js";
import RenderState from "../Renderer/RenderState.js";
import ShaderProgram from "../Renderer/ShaderProgram.js";
import ShaderSource from "../Renderer/ShaderSource.js";
import VertexArray from "../Renderer/VertexArray.js";
import AtmosphereCommon from "../Shaders/AtmosphereCommon.js";
import SkyAtmosphereCommon from "../Shaders/SkyAtmosphereCommon.js";
import SkyAtmosphereFS from "../Shaders/SkyAtmosphereFS.js";
import SkyAtmosphereVS from "../Shaders/SkyAtmosphereVS.js";
import Axis from "./Axis.js";
import BlendingState from "./BlendingState.js";
import CullFace from "./CullFace.js";
import SceneMode from "./SceneMode.js";
/**
* An atmosphere drawn around the limb of the provided ellipsoid. Based on
* {@link http://nishitalab.org/user/nis/cdrom/sig93_nis.pdf|Display of The Earth Taking Into Account Atmospheric Scattering}.
* <p>
* This is only supported in 3D. Atmosphere is faded out when morphing to 2D or Columbus view.
* </p>
*
* @alias SkyAtmosphere
* @constructor
*
* @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid that the atmosphere is drawn around.
*
* @example
* scene.skyAtmosphere = new Cesium.SkyAtmosphere();
*
* @see Scene.skyAtmosphere
*/
function SkyAtmosphere(ellipsoid) {
ellipsoid = ellipsoid ?? Ellipsoid.WGS84;
/**
* Determines if the atmosphere is shown.
*
* @type {boolean}
* @default true
*/
this.show = true;
/**
* Compute atmosphere per-fragment instead of per-vertex.
* This produces better looking atmosphere with a slight performance penalty.
*
* @type {boolean}
* @default false
*/
this.perFragmentAtmosphere = false;
this._ellipsoid = ellipsoid;
const outerEllipsoidScale = 1.025;
const scaleVector = Cartesian3.multiplyByScalar(
ellipsoid.radii,
outerEllipsoidScale,
new Cartesian3(),
);
this._scaleMatrix = Matrix4.fromScale(scaleVector);
this._modelMatrix = new Matrix4();
this._command = new DrawCommand({
owner: this,
modelMatrix: this._modelMatrix,
});
this._spSkyFromSpace = undefined;
this._spSkyFromAtmosphere = undefined;
this._flags = undefined;
/**
* The intensity of the light that is used for computing the sky atmosphere color.
*
* @type {number}
* @default 50.0
*/
this.atmosphereLightIntensity = 50.0;
/**
* The Rayleigh scattering coefficient used in the atmospheric scattering equations for the sky atmosphere.
*
* @type {Cartesian3}
* @default Cartesian3(5.5e-6, 13.0e-6, 28.4e-6)
*/
this.atmosphereRayleighCoefficient = new Cartesian3(5.5e-6, 13.0e-6, 28.4e-6);
/**
* The Mie scattering coefficient used in the atmospheric scattering equations for the sky atmosphere.
*
* @type {Cartesian3}
* @default Cartesian3(21e-6, 21e-6, 21e-6)
*/
this.atmosphereMieCoefficient = new Cartesian3(21e-6, 21e-6, 21e-6);
/**
* The Rayleigh scale height used in the atmospheric scattering equations for the sky atmosphere, in meters.
*
* @type {number}
* @default 10000.0
*/
this.atmosphereRayleighScaleHeight = 10000.0;
/**
* The Mie scale height used in the atmospheric scattering equations for the sky atmosphere, in meters.
*
* @type {number}
* @default 3200.0
*/
this.atmosphereMieScaleHeight = 3200.0;
/**
* The anisotropy of the medium to consider for Mie scattering.
* <p>
* Valid values are between -1.0 and 1.0.
* </p>
* @type {number}
* @default 0.9
*/
this.atmosphereMieAnisotropy = 0.9;
/**
* The hue shift to apply to the atmosphere. Defaults to 0.0 (no shift).
* A hue shift of 1.0 indicates a complete rotation of the hues available.
* @type {number}
* @default 0.0
*/
this.hueShift = 0.0;
/**
* The saturation shift to apply to the atmosphere. Defaults to 0.0 (no shift).
* A saturation shift of -1.0 is monochrome.
* @type {number}
* @default 0.0
*/
this.saturationShift = 0.0;
/**
* The brightness shift to apply to the atmosphere. Defaults to 0.0 (no shift).
* A brightness shift of -1.0 is complete darkness, which will let space show through.
* @type {number}
* @default 0.0
*/
this.brightnessShift = 0.0;
this._hueSaturationBrightness = new Cartesian3();
// outer radius, inner radius, dynamic atmosphere color flag
const radiiAndDynamicAtmosphereColor = new Cartesian3();
radiiAndDynamicAtmosphereColor.x =
ellipsoid.maximumRadius * outerEllipsoidScale;
radiiAndDynamicAtmosphereColor.y = ellipsoid.maximumRadius;
// Toggles whether the sun position is used. 0 treats the sun as always directly overhead.
radiiAndDynamicAtmosphereColor.z = 0;
this._radiiAndDynamicAtmosphereColor = radiiAndDynamicAtmosphereColor;
const that = this;
this._command.uniformMap = {
u_radiiAndDynamicAtmosphereColor: function () {
return that._radiiAndDynamicAtmosphereColor;
},
u_hsbShift: function () {
that._hueSaturationBrightness.x = that.hueShift;
that._hueSaturationBrightness.y = that.saturationShift;
that._hueSaturationBrightness.z = that.brightnessShift;
return that._hueSaturationBrightness;
},
u_atmosphereLightIntensity: function () {
return that.atmosphereLightIntensity;
},
u_atmosphereRayleighCoefficient: function () {
return that.atmosphereRayleighCoefficient;
},
u_atmosphereMieCoefficient: function () {
return that.atmosphereMieCoefficient;
},
u_atmosphereRayleighScaleHeight: function () {
return that.atmosphereRayleighScaleHeight;
},
u_atmosphereMieScaleHeight: function () {
return that.atmosphereMieScaleHeight;
},
u_atmosphereMieAnisotropy: function () {
return that.atmosphereMieAnisotropy;
},
};
}
Object.defineProperties(SkyAtmosphere.prototype, {
/**
* Gets the ellipsoid the atmosphere is drawn around.
* @memberof SkyAtmosphere.prototype
*
* @type {Ellipsoid}
* @readonly
*/
ellipsoid: {
get: function () {
return this._ellipsoid;
},
},
});
/**
* Set the dynamic lighting enum value for the shader
* @param {DynamicAtmosphereLightingType} lightingEnum The enum that determines the dynamic atmosphere light source
*
* @private
*/
SkyAtmosphere.prototype.setDynamicLighting = function (lightingEnum) {
this._radiiAndDynamicAtmosphereColor.z = lightingEnum;
};
const scratchModelMatrix = new Matrix4();
/**
* @private
*/
SkyAtmosphere.prototype.update = function (frameState, globe) {
if (!this.show) {
return undefined;
}
const mode = frameState.mode;
if (mode !== SceneMode.SCENE3D && mode !== SceneMode.MORPHING) {
return undefined;
}
// The atmosphere is only rendered during the render pass; it is not pickable, it doesn't cast shadows, etc.
Iif (!frameState.passes.render) {
return undefined;
}
// Align the ellipsoid geometry so it always faces the same direction as the
// camera to reduce artifacts when rendering atmosphere per-vertex
const rotationMatrix = Matrix4.fromRotationTranslation(
frameState.context.uniformState.inverseViewRotation,
Cartesian3.ZERO,
scratchModelMatrix,
);
const rotationOffsetMatrix = Matrix4.multiplyTransformation(
rotationMatrix,
Axis.Y_UP_TO_Z_UP,
scratchModelMatrix,
);
const modelMatrix = Matrix4.multiply(
this._scaleMatrix,
rotationOffsetMatrix,
scratchModelMatrix,
);
Matrix4.clone(modelMatrix, this._modelMatrix);
const context = frameState.context;
const colorCorrect = hasColorCorrection(this);
const translucent = frameState.globeTranslucencyState.translucent;
const perFragmentAtmosphere =
this.perFragmentAtmosphere || translucent || !defined(globe) || !globe.show;
const command = this._command;
if (!defined(command.vertexArray)) {
const geometry = EllipsoidGeometry.createGeometry(
new EllipsoidGeometry({
radii: new Cartesian3(1.0, 1.0, 1.0),
slicePartitions: 256,
stackPartitions: 256,
vertexFormat: VertexFormat.POSITION_ONLY,
}),
);
command.vertexArray = VertexArray.fromGeometry({
context: context,
geometry: geometry,
attributeLocations: GeometryPipeline.createAttributeLocations(geometry),
bufferUsage: BufferUsage.STATIC_DRAW,
});
command.renderState = RenderState.fromCache({
cull: {
enabled: true,
face: CullFace.FRONT,
},
blending: BlendingState.ALPHA_BLEND,
depthMask: false,
});
}
const flags =
colorCorrect | (perFragmentAtmosphere << 2) | (translucent << 3);
if (flags !== this._flags) {
this._flags = flags;
const defines = [];
if (colorCorrect) {
defines.push("COLOR_CORRECT");
}
if (perFragmentAtmosphere) {
defines.push("PER_FRAGMENT_ATMOSPHERE");
}
Iif (translucent) {
defines.push("GLOBE_TRANSLUCENT");
}
const vs = new ShaderSource({
defines: defines,
sources: [AtmosphereCommon, SkyAtmosphereCommon, SkyAtmosphereVS],
});
const fs = new ShaderSource({
defines: defines,
sources: [AtmosphereCommon, SkyAtmosphereCommon, SkyAtmosphereFS],
});
this._spSkyAtmosphere = ShaderProgram.fromCache({
context: context,
vertexShaderSource: vs,
fragmentShaderSource: fs,
});
command.shaderProgram = this._spSkyAtmosphere;
}
return command;
};
function hasColorCorrection(skyAtmosphere) {
return !(
CesiumMath.equalsEpsilon(
skyAtmosphere.hueShift,
0.0,
CesiumMath.EPSILON7,
) &&
CesiumMath.equalsEpsilon(
skyAtmosphere.saturationShift,
0.0,
CesiumMath.EPSILON7,
) &&
CesiumMath.equalsEpsilon(
skyAtmosphere.brightnessShift,
0.0,
CesiumMath.EPSILON7,
)
);
}
/**
* Returns true if this object was destroyed; otherwise, false.
* <br /><br />
* If this object was destroyed, it should not be used; calling any function other than
* <code>isDestroyed</code> will result in a {@link DeveloperError} exception.
*
* @returns {boolean} <code>true</code> if this object was destroyed; otherwise, <code>false</code>.
*
* @see SkyAtmosphere#destroy
*/
SkyAtmosphere.prototype.isDestroyed = function () {
return false;
};
/**
* Destroys the WebGL resources held by this object. Destroying an object allows for deterministic
* release of WebGL resources, instead of relying on the garbage collector to destroy this object.
* <br /><br />
* Once an object is destroyed, it should not be used; calling any function other than
* <code>isDestroyed</code> will result in a {@link DeveloperError} exception. Therefore,
* assign the return value (<code>undefined</code>) to the object as done in the example.
*
* @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
*
*
* @example
* skyAtmosphere = skyAtmosphere && skyAtmosphere.destroy();
*
* @see SkyAtmosphere#isDestroyed
*/
SkyAtmosphere.prototype.destroy = function () {
const command = this._command;
command.vertexArray = command.vertexArray && command.vertexArray.destroy();
this._spSkyAtmosphere =
this._spSkyAtmosphere && this._spSkyAtmosphere.destroy();
return destroyObject(this);
};
export default SkyAtmosphere;
|