Skip to content

Commit

Permalink
Merge pull request #8867 from CesiumGS/underground-color
Browse files Browse the repository at this point in the history
Globe underground color
  • Loading branch information
IanLilleyT authored May 21, 2020
2 parents 9eaf6a8 + f57b6ad commit c9dd6f6
Show file tree
Hide file tree
Showing 19 changed files with 608 additions and 22 deletions.
Binary file not shown.
11 changes: 8 additions & 3 deletions Apps/Sandcastle/gallery/Cartographic Limit Rectangle.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
terrainProvider: Cesium.createWorldTerrain(),
});

var scene = viewer.scene;
var globe = scene.globe;

// Tropics of Cancer and Capricorn
var coffeeBeltRectangle = Cesium.Rectangle.fromDegrees(
-180.0,
Expand All @@ -47,9 +50,11 @@
23.43687
);

viewer.scene.globe.cartographicLimitRectangle = coffeeBeltRectangle;
viewer.scene.globe.showSkirts = false;
viewer.scene.skyAtmosphere.show = false;
globe.cartographicLimitRectangle = coffeeBeltRectangle;
globe.showSkirts = false;
globe.backFaceCulling = false;
globe.undergroundColor = undefined;
scene.skyAtmosphere.show = false;

// Add rectangles to show bounds
var rectangles = [];
Expand Down
Binary file modified Apps/Sandcastle/gallery/Cartographic Limit Rectangle.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
230 changes: 230 additions & 0 deletions Apps/Sandcastle/gallery/Underground Color.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
<!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="Use Viewer to start building new applications or easily embed Cesium into existing applications."
/>
<meta name="cesium-sandcastle-labels" content="Beginner, Showcases" />
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script
type="text/javascript"
src="../../../Build/CesiumUnminified/Cesium.js"
nomodule
></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>Enabled</td>
<td>
<input type="checkbox" data-bind="checked: enabled" />
</td>
</tr>
<tr>
<td>Near distance</td>
<td>
<input
type="range"
min="0.0"
max="1000000.0"
step="1.0"
data-bind="value: nearDistance, valueUpdate: 'input'"
/>
<input type="text" size="5" data-bind="value: nearDistance" />
</td>
</tr>
<tr>
<td>Far distance</td>
<td>
<input
type="range"
min="100000.0"
max="3000000.0"
step="1.0"
data-bind="value: farDistance, valueUpdate: 'input'"
/>
<input type="text" size="5" data-bind="value: farDistance" />
</td>
</tr>
<tr>
<td>Near alpha</td>
<td>
<input
type="range"
min="0.0"
max="1.0"
step="0.01"
data-bind="value: nearAlpha, valueUpdate: 'input'"
/>
<input type="text" size="5" data-bind="value: nearAlpha" />
</td>
</tr>
<tr>
<td>Far alpha</td>
<td>
<input
type="range"
min="0.0"
max="1.0"
step="0.01"
data-bind="value: farAlpha, valueUpdate: 'input'"
/>
<input type="text" size="5" data-bind="value: farAlpha" />
</td>
</tr>
</tbody>
</table>
</div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
"use strict";
//Sandcastle_Begin
var viewer = new Cesium.Viewer("cesiumContainer");

var scene = viewer.scene;
var globe = scene.globe;

scene.screenSpaceCameraController.enableCollisionDetection = false;

var longitude = -3.82518;
var latitude = 53.11728;
var height = -500.0;
var position = Cesium.Cartesian3.fromDegrees(
longitude,
latitude,
height
);
var url = "../../SampleData/models/ParcLeadMine/ParcLeadMine.glb";

var entity = viewer.entities.add({
name: url,
position: position,
model: {
uri: url,
},
});

viewer.scene.camera.setView({
destination: new Cesium.Cartesian3(
3827058.651471591,
-256575.7981065622,
5078738.238484612
),
orientation: new Cesium.HeadingPitchRoll(
1.9765540737339418,
-0.17352018581162754,
0.0030147639151465455
),
endTransform: Cesium.Matrix4.IDENTITY,
});

var originalColor = Cesium.Color.BLACK;
var originalNearDistance = 1000.0;
var originalFarDistance = 1000000.0;
var originalNearAlpha = 0.0;
var originalFarAlpha = 1.0;

var color = originalColor;

var viewModel = {
enabled: true,
nearDistance: originalNearDistance,
farDistance: originalFarDistance,
nearAlpha: originalNearAlpha,
farAlpha: originalFarAlpha,
};

Cesium.knockout.track(viewModel);
var toolbar = document.getElementById("toolbar");
Cesium.knockout.applyBindings(viewModel, toolbar);
for (var name in viewModel) {
if (viewModel.hasOwnProperty(name)) {
Cesium.knockout.getObservable(viewModel, name).subscribe(update);
}
}

Sandcastle.addToolbarButton("Random color", function () {
color = Cesium.Color.fromRandom({
alpha: 1.0,
});
update();
});

Sandcastle.addToolbarButton("Clear", function () {
color = originalColor;
viewModel.enabled = true;
viewModel.nearDistance = originalNearDistance;
viewModel.farDistance = originalFarDistance;
viewModel.nearAlpha = originalNearAlpha;
viewModel.farAlpha = originalFarAlpha;
update();
});

function update() {
globe.undergroundColor = viewModel.enabled ? color : undefined;

var nearDistance = Number(viewModel.nearDistance);
nearDistance = isNaN(nearDistance)
? originalNearDistance
: nearDistance;

var farDistance = Number(viewModel.farDistance);
farDistance = isNaN(farDistance) ? originalFarDistance : farDistance;

if (nearDistance > farDistance) {
nearDistance = farDistance;
}

var nearAlpha = Number(viewModel.nearAlpha);
nearAlpha = isNaN(nearAlpha) ? 0.0 : nearAlpha;

var farAlpha = Number(viewModel.farAlpha);
farAlpha = isNaN(farAlpha) ? 1.0 : farAlpha;

globe.undergroundColorAlphaByDistance.near = nearDistance;
globe.undergroundColorAlphaByDistance.far = farDistance;
globe.undergroundColorAlphaByDistance.nearValue = nearAlpha;
globe.undergroundColorAlphaByDistance.farValue = farAlpha;
}
update(); //Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
window.startupCalled = true;
startup(Cesium);
}
</script>
</body>
</html>
Binary file added Apps/Sandcastle/gallery/Underground Color.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Added `Cesium3DTileset.extensions` to get the extensions property from the tileset JSON. [#8829](https://github.com/CesiumGS/cesium/pull/8829)
- Added `frustumSplits` option to `DebugCameraPrimitive`. [8849](https://github.com/CesiumGS/cesium/pull/8849)
- Added `Globe.undergroundColor` and `Globe.undergroundColorAlphaByDistance` for controlling how the back side of the globe is rendered when the camera is underground or the globe is translucent. [#8867](https://github.com/CesiumGS/cesium/pull/8867)

##### Fixes :wrench:

Expand Down
6 changes: 6 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,12 @@ Creative Commons Attribution 3.0
(c) copyright 2012, Dennis Haupt
http://www.blendswap.com/blends/view/61653

### Perc Lead Mine

Creative Commons Attribution 4.0 International
(c) copyright 2019, Dr Edward Alan Lockhart
https://sketchfab.com/3d-models/parc-lead-mine-4759a23abbff454c8c682ff9b02ba111

### GitHub logo

https://github.com/logos
Expand Down
21 changes: 20 additions & 1 deletion Source/Renderer/AutomaticUniforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -1043,9 +1043,28 @@ var AutomaticUniforms = {
},
}),

/**
* An automatic GLSL uniform containing the height in meters of the
* eye (camera) above or below the ellipsoid.
*
* @alias czm_eyeHeight
* @namespace
* @glslUniform
*
* @see UniformState#eyeHeight
*/
czm_eyeHeight: new AutomaticUniform({
size: 1,
datatype: WebGLConstants.FLOAT,
getValue: function (uniformState) {
return uniformState.eyeHeight;
},
}),

/**
* An automatic GLSL uniform containing height (<code>x</code>) and height squared (<code>y</code>)
* of the eye (camera) in the 2D scene in meters.
* in meters of the eye (camera) above the 2D world plane. This uniform is only valid
* when the {@link SceneMode} is <code>SCENE2D</code>.
*
* @alias czm_eyeHeight2D
* @namespace
Expand Down
26 changes: 23 additions & 3 deletions Source/Renderer/UniformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ function UniformState() {
this._cameraRight = new Cartesian3();
this._cameraUp = new Cartesian3();
this._frustum2DWidth = 0.0;
this._eyeHeight = 0.0;
this._eyeHeight2D = new Cartesian2();
this._pixelRatio = 1.0;
this._orthographicIn3D = false;
Expand Down Expand Up @@ -672,9 +673,20 @@ Object.defineProperties(UniformState.prototype, {
},

/**
* The the height (<code>x</code>) and the height squared (<code>y</code>)
* in meters of the camera above the 2D world plane. This uniform is only valid
* when the {@link SceneMode} equal to <code>SCENE2D</code>.
* The height in meters of the eye (camera) above or below the ellipsoid.
* @memberof UniformState.prototype
* @type {Number}
*/
eyeHeight: {
get: function () {
return this._eyeHeight;
},
},

/**
* The height (<code>x</code>) and the height squared (<code>y</code>)
* in meters of the eye (camera) above the 2D world plane. This uniform is only valid
* when the {@link SceneMode} is <code>SCENE2D</code>.
* @memberof UniformState.prototype
* @type {Cartesian2}
*/
Expand Down Expand Up @@ -1060,6 +1072,14 @@ function setCamera(uniformState, camera) {
Cartesian3.clone(camera.directionWC, uniformState._cameraDirection);
Cartesian3.clone(camera.rightWC, uniformState._cameraRight);
Cartesian3.clone(camera.upWC, uniformState._cameraUp);

var positionCartographic = camera.positionCartographic;
if (!defined(positionCartographic)) {
uniformState._eyeHeight = -uniformState._ellipsoid.maximumRadius;
} else {
uniformState._eyeHeight = positionCartographic.height;
}

uniformState._encodedCameraPositionMCDirty = true;
}

Expand Down
Loading

0 comments on commit c9dd6f6

Please sign in to comment.