Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertical exaggeration for 3D Tiles #11655

Merged
merged 38 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
113140a
Compute eyeEllipsoidNormalEC for exaggeration calculations
Aug 10, 2023
e1c6cdc
Compute ellipsoid curvature and ENU transforms at camera position
Aug 14, 2023
8c57415
Add VerticalExaggerationPipelineStage
Sep 14, 2023
caebd18
Apply vertical exaggeration to ellipsoid voxel height bounds
Sep 15, 2023
fd75f85
Rename terrainExaggeration to verticalExaggeration in FrameState
Sep 15, 2023
70bb6ac
Fix failing spec
Sep 17, 2023
755234a
Fix AutomaticUniform specs for ellipsoid position and curvature
Sep 19, 2023
1a3fd4e
Fix size calculation for voxel megatextures
Oct 27, 2023
9a6bbbf
Merge branch 'main' into tileset-exaggerate
Oct 27, 2023
2e549d8
Apply vertical exaggeration to tile bounding regions
Oct 31, 2023
5c7b7e8
Merge branch 'main' into tileset-exaggerate
Nov 11, 2023
328b386
Merge branch 'main' into z-exaggeration
Nov 27, 2023
11d6906
Fix EntityClusterSpec
Nov 27, 2023
587d7d4
Fix mock globes for specs
Nov 27, 2023
fa1d943
Use azimuthal curvature to approximate ellipsoid normal for exaggeration
Nov 29, 2023
ce217d4
Exaggerate 3D Tiles bounding boxes and spheres
Nov 29, 2023
1f60eee
Fix failing specs
Nov 29, 2023
55d6dfa
Apply tile transform before exaggerating bounding volumes
Nov 30, 2023
3e63f3a
Fix precision issues in VerticalExaggerationStageVS
Nov 30, 2023
2448e52
Move curvature calculations to Ellipsoid
Dec 1, 2023
3796fd3
Add specs for czm_modelToEnu and czm_enuToModel
Dec 1, 2023
e79b31b
Add Scene-level control for vertical exaggeration
Dec 1, 2023
6953452
Update CHANGES.md
Dec 1, 2023
c4dfc59
Use globe.terrainExaggeration if scene.verticalExaggeration is not set
Dec 1, 2023
14dcfeb
Add Sandcastle for 3D Tiles Vertical Exaggeration
Dec 1, 2023
8cd5fb5
Add VerticalExaggerationSpec
Dec 1, 2023
74bb302
Fix small angle approximation in VerticalExaggerationStageVS
Dec 3, 2023
a219fc6
Fix typos in CHANGES.md
Dec 3, 2023
d48ddce
Deprecate Globe.terrainExaggeration
Dec 5, 2023
e413b16
Add specs for vertical exaggeration
Dec 6, 2023
a317307
Merge branch 'main' into z-exaggeration
Dec 6, 2023
f7dc167
Update CHANGES.md
Dec 6, 2023
533fe78
Fix overwritten Rectangle in tile bounding region
Dec 22, 2023
8ca7fed
Merge branch 'main' into z-exaggeration
Dec 22, 2023
b88bf86
Add VerticalExaggerationPipelineStageSpec
Dec 22, 2023
82738b3
Fix legacy terrainExaggeration, clarify comment
Dec 22, 2023
5c442c2
Check shader code in VerticalExaggerationPipelineStageSpec
Dec 22, 2023
631641b
Use new API in Terrain Exaggeration Sandcastle
Dec 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions Apps/Sandcastle/gallery/3D Tiles Vertical Exaggeration.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
/>
<meta
name="description"
content="Apply Vertical Exaggeration to 3D Tiles"
/>
<meta name="cesium-sandcastle-labels" content="Beginner, Showcases" />
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script type="module" src="../load-cesium-es6.js"></script>
</head>
<body
class="sandcastle-loading"
data-sandcastle-bucket="bucket-requirejs.html"
>
<style>
@import url(../templates/bucket.css);

#toolbar {
background: rgba(42, 42, 42, 0.8);
padding: 4px;
border-radius: 4px;
}

#toolbar input {
vertical-align: middle;
padding-top: 2px;
padding-bottom: 2px;
}

#toolbar .header {
font-weight: bold;
}
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay">
<h1>Loading...</h1>
</div>
<div id="toolbar">
<table>
<tbody>
<tr>
<td>Exaggeration</td>
<td>
<input
type="range"
min="1"
max="5"
step="0.01"
data-bind="value: exaggeration, valueUpdate: 'input'"
/>
<input type="text" size="5" data-bind="value: exaggeration" />
</td>
</tr>
<tr>
<td>Relative Height</td>
<td>
<input
type="range"
min="-1000"
max="9000"
step="1"
data-bind="value: relativeHeight, valueUpdate: 'input'"
/>
<input type="text" size="5" data-bind="value: relativeHeight" />
</td>
</tr>
</tbody>
</table>
</div>
<script id="cesium_sandcastle_script">
window.startup = async function (Cesium) {
"use strict";
//Sandcastle_Begin
const viewer = new Cesium.Viewer("cesiumContainer", {
timeline: false,
animation: false,
sceneModePicker: false,
baseLayerPicker: false,
// The globe does not need to be displayed,
// since the Photorealistic 3D Tiles include terrain
globe: false,
});

const { scene, camera } = viewer;
scene.verticalExaggeration = 3.0;

camera.setView({
destination: new Cesium.Cartesian3(
-2710292.813384663,
-4360657.061518585,
3793571.786860543
),
orientation: new Cesium.HeadingPitchRoll(
5.794062761901799,
-0.30293409742984756,
0.0009187098191985044
),
});

// Enable rendering the sky
scene.skyAtmosphere.show = true;

// Add Photorealistic 3D Tiles
try {
const tileset = await Cesium.createGooglePhotorealistic3DTileset();
scene.primitives.add(tileset);
} catch (error) {
console.log(`Error loading Photorealistic 3D Tiles tileset.
${error}`);
}

const viewModel = {
exaggeration: scene.verticalExaggeration,
relativeHeight: scene.verticalExaggerationRelativeHeight,
};

function updateExaggeration() {
scene.verticalExaggeration = Number(viewModel.exaggeration);
scene.verticalExaggerationRelativeHeight = Number(
viewModel.relativeHeight
);
}

Cesium.knockout.track(viewModel);
const toolbar = document.getElementById("toolbar");
Cesium.knockout.applyBindings(viewModel, toolbar);
for (const name in viewModel) {
if (viewModel.hasOwnProperty(name)) {
Cesium.knockout
.getObservable(viewModel, name)
.subscribe(updateExaggeration);
}
}
//Sandcastle_End
Sandcastle.finishedLoading();
};
if (typeof Cesium !== "undefined") {
window.startupCalled = true;
window.startup(Cesium).catch((error) => {
"use strict";
console.error(error);
});
}
</script>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions Apps/Sandcastle/gallery/Terrain Exaggeration.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@

const scene = viewer.scene;
const globe = scene.globe;
globe.terrainExaggeration = 2.0;
globe.terrainExaggerationRelativeHeight = 2400.0;
scene.verticalExaggeration = 2.0;
scene.verticalExaggerationRelativeHeight = 2400.0;

scene.camera.setView({
destination: new Cesium.Cartesian3(
Expand Down Expand Up @@ -115,8 +115,8 @@

function updateMaterial() {
if (visualizeRelativeHeight) {
const height = globe.terrainExaggerationRelativeHeight;
const exaggeration = globe.terrainExaggeration;
const height = scene.verticalExaggerationRelativeHeight;
const exaggeration = scene.verticalExaggeration;
const alpha = Math.min(1.0, exaggeration * 0.25);
const layer = {
extendUpwards: true,
Expand Down Expand Up @@ -155,13 +155,13 @@
updateMaterial();

const viewModel = {
exaggeration: globe.terrainExaggeration,
relativeHeight: globe.terrainExaggerationRelativeHeight,
exaggeration: scene.verticalExaggeration,
relativeHeight: scene.verticalExaggerationRelativeHeight,
};

function updateExaggeration() {
globe.terrainExaggeration = Number(viewModel.exaggeration);
globe.terrainExaggerationRelativeHeight = Number(
scene.verticalExaggeration = Number(viewModel.exaggeration);
scene.verticalExaggerationRelativeHeight = Number(
viewModel.relativeHeight
);
updateMaterial();
Expand Down
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@

#### @cesium/engine

##### Additions :tada:

- Vertical exaggeration can now be applied to a `Cesium3DTileset`. Exaggeration of `Terrain` and `Cesium3DTileset` can be controlled simultaneously via the new `Scene` properties `Scene.verticalExaggeration` and `Scene.verticalExaggerationRelativeHeight`. [#11655](https://github.com/CesiumGS/cesium/pull/11655)

##### Fixes :wrench:

- Changes the default `RequestScheduler.maximumRequestsPerServer` from 6 to 18. This should improve performance on HTTP/2 servers and above [#11627](https://github.com/CesiumGS/cesium/issues/11627)
- Corrected JSDoc and Typescript definitions that marked optional arguments as required in `ImageryProvider` constructor [#11625](https://github.com/CesiumGS/cesium/issues/11625)
- The `Quaternion.computeAxis` function created an axis that was `(0,0,0)` for the unit quaternion, and an axis that was `(NaN,NaN,NaN)` for the quaternion `(0,0,0,-1)` (which describes a rotation about 360 degrees). Now, it returns the x-axis `(1,0,0)` in both of these cases.

##### Deprecated :hourglass_flowing_sand:

- `Globe.terrainExaggeration` and `Globe.terrainExaggerationRelativeHeight` have been deprecated in CesiumJS 1.113. They will be removed in 1.116. Use `Scene.verticalExaggeration` and `Scene.verticalExaggerationRelativeHeight` instead. [#11655](https://github.com/CesiumGS/cesium/pull/11655)

### 1.112 - 2023-12-01

#### @cesium/engine
Expand Down
4 changes: 2 additions & 2 deletions Specs/createFrameState.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ function createFrameState(context, camera, frameNumber, time) {
camera.up
);

frameState.terrainExaggeration = 1.0;
frameState.terrainExaggerationRelativeHeight = 0.0;
frameState.verticalExaggeration = 1.0;
frameState.verticalExaggerationRelativeHeight = 0.0;

frameState.passes.render = true;
frameState.passes.pick = false;
Expand Down
45 changes: 45 additions & 0 deletions packages/engine/Source/Core/Ellipsoid.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Cartesian2 from "./Cartesian2.js";
import Cartesian3 from "./Cartesian3.js";
import Cartographic from "./Cartographic.js";
import Check from "./Check.js";
Expand Down Expand Up @@ -694,6 +695,50 @@ Ellipsoid.prototype.getSurfaceNormalIntersectionWithZAxis = function (
return result;
};

const scratchEndpoint = new Cartesian3();

/**
* Computes the ellipsoid curvatures at a given position on the surface.
*
* @param {Cartesian3} surfacePosition The position on the ellipsoid surface where curvatures will be calculated.
* @param {Cartesian2} [result] The cartesian to which to copy the result, or undefined to create and return a new instance.
* @returns {Cartesian2} The local curvature of the ellipsoid surface at the provided position, in east and north directions.
*
* @exception {DeveloperError} position is required.
*/
Ellipsoid.prototype.getLocalCurvature = function (surfacePosition, result) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object("surfacePosition", surfacePosition);
//>>includeEnd('debug');

if (!defined(result)) {
result = new Cartesian2();
}

const primeVerticalEndpoint = this.getSurfaceNormalIntersectionWithZAxis(
surfacePosition,
0.0,
scratchEndpoint
);
const primeVerticalRadius = Cartesian3.distance(
surfacePosition,
primeVerticalEndpoint
);
// meridional radius = (1 - e^2) * primeVerticalRadius^3 / a^2
// where 1 - e^2 = b^2 / a^2,
// so meridional = b^2 * primeVerticalRadius^3 / a^4
// = (b * primeVerticalRadius / a^2)^2 * primeVertical
const radiusRatio =
(this.minimumRadius * primeVerticalRadius) / this.maximumRadius ** 2;
const meridionalRadius = primeVerticalRadius * radiusRatio ** 2;

return Cartesian2.fromElements(
1.0 / primeVerticalRadius,
1.0 / meridionalRadius,
result
);
};

const abscissas = [
0.14887433898163,
0.43339539412925,
Expand Down
6 changes: 2 additions & 4 deletions packages/engine/Source/Core/RectangleOutlineGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,9 @@ function constructRectangle(geometry, computedOptions) {
}

function constructExtrudedRectangle(rectangleGeometry, computedOptions) {
const surfaceHeight = rectangleGeometry._surfaceHeight;
const extrudedHeight = rectangleGeometry._extrudedHeight;
const maxHeight = rectangleGeometry._surfaceHeight;
const minHeight = rectangleGeometry._extrudedHeight;
const ellipsoid = rectangleGeometry._ellipsoid;
const minHeight = extrudedHeight;
const maxHeight = surfaceHeight;
const geo = constructRectangle(rectangleGeometry, computedOptions);

const height = computedOptions.height;
Expand Down
4 changes: 2 additions & 2 deletions packages/engine/Source/Core/TerrainEncoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import defaultValue from "./defaultValue.js";
import defined from "./defined.js";
import CesiumMath from "./Math.js";
import Matrix4 from "./Matrix4.js";
import TerrainExaggeration from "./TerrainExaggeration.js";
import VerticalExaggeration from "./VerticalExaggeration.js";
import TerrainQuantization from "./TerrainQuantization.js";

const cartesian3Scratch = new Cartesian3();
Expand Down Expand Up @@ -386,7 +386,7 @@ TerrainEncoding.prototype.getExaggeratedPosition = function (
);
const rawHeight = this.decodeHeight(buffer, index);
const heightDifference =
TerrainExaggeration.getHeight(
VerticalExaggeration.getHeight(
rawHeight,
exaggeration,
exaggerationRelativeHeight
Expand Down
49 changes: 0 additions & 49 deletions packages/engine/Source/Core/TerrainExaggeration.js

This file was deleted.

Loading