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

Elevation Band Material #9132

Merged
merged 29 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2f457f3
initial implementation of ElevationBandMaterial
IanLilleyT Sep 3, 2020
507e470
Fixed premultiplied alpha bug and some cleanup
IanLilleyT Sep 3, 2020
8df4d4b
Fixed spec ordering problem
IanLilleyT Sep 3, 2020
e0c70b9
Updated CHANGES.md
IanLilleyT Sep 3, 2020
009dc17
Forgot period
IanLilleyT Sep 3, 2020
e6e3db8
typo in comment
IanLilleyT Sep 3, 2020
bc9b6ad
using different min and max height constants for createElevationBandM…
IanLilleyT Sep 5, 2020
c48aadc
Merge branch 'master' into elevationBand
lilleyse Sep 25, 2020
0baf495
Merge branch 'master' into elevationBand
IanLilleyT Dec 14, 2020
2f362af
improved duplicate removal check and added some more specs
IanLilleyT Dec 14, 2020
74c8554
better float pack
IanLilleyT Dec 15, 2020
3d37b28
Merge branch 'betterFloatPack' into elevationBand
IanLilleyT Dec 15, 2020
8d592d4
another layering fix
IanLilleyT Dec 15, 2020
b0d9f95
fixed documentation
IanLilleyT Dec 16, 2020
89a7477
fixed out of range f32
IanLilleyT Dec 16, 2020
74a8ef9
naming consistency
IanLilleyT Dec 16, 2020
8abeed7
Merge branch 'betterFloatPack' into elevationBand
IanLilleyT Dec 16, 2020
8a20d83
updated changes.md
IanLilleyT Dec 16, 2020
59180a6
better doc comment
IanLilleyT Dec 16, 2020
fe0a752
using packFloat correctly
IanLilleyT Dec 16, 2020
8e2980b
fixed gradient checkbox
IanLilleyT Dec 16, 2020
ed0db64
clarified constants
IanLilleyT Dec 16, 2020
e28b0dd
clamp to max f32 instead of error
IanLilleyT Dec 16, 2020
f049993
more concise
IanLilleyT Dec 16, 2020
3ed8564
brought back infinity for outside f32 range
IanLilleyT Dec 16, 2020
028b44b
Merge branch 'betterFloatPack' into elevationBand
IanLilleyT Dec 17, 2020
7aebe04
cleaner instantiation of material
IanLilleyT Dec 17, 2020
2f1cfe8
Merge branch 'master' into elevationBand
IanLilleyT Dec 18, 2020
3116533
Merge branch 'master' into elevationBand
IanLilleyT Dec 21, 2020
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
325 changes: 325 additions & 0 deletions Apps/Sandcastle/gallery/Elevation Band Material.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,325 @@
<!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 elevation band material to the globe."
/>
<meta name="cesium-sandcastle-labels" content="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);
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar">
<table>
<tbody>
<tr>
<td>Background Transparency</td>
<td>
<input
type="range"
min="0.0"
max="1.0"
step="0.01"
data-bind="value: backgroundTransparency, valueUpdate: 'input'"
/>
</td>
</tr>
<tr>
<td>Band Transparency</td>
<td>
<input
type="range"
min="0.0"
max="1.0"
step="0.01"
data-bind="value: bandTransparency, valueUpdate: 'input'"
/>
</td>
</tr>
<tr>
<td>Band Thickness</td>
<td>
<input
type="range"
min="10"
max="1000"
step="1"
data-bind="value: bandThickness, valueUpdate: 'input'"
/>
</td>
</tr>
<tr>
<td>Band 1 Position</td>
<td>
<input
type="range"
min="4000"
max="8848"
step="1"
data-bind="value: band1Position, valueUpdate: 'input'"
/>
</td>
</tr>
<tr>
<td>Band 2 Position</td>
<td>
<input
type="range"
min="4000"
max="8848"
step="1"
data-bind="value: band2Position, valueUpdate: 'input'"
/>
</td>
</tr>
<tr>
<td>Band 3 Position</td>
<td>
<input
type="range"
min="4000"
max="8848"
step="1"
data-bind="value: band3Position, valueUpdate: 'input'"
/>
</td>
</tr>
<tr>
<td>Gradient</td>
<td>
<input type="checkbox" data-bind="checked: gradient" />
IanLilleyT marked this conversation as resolved.
Show resolved Hide resolved
</td>
</tr>
</tbody>
</table>
</div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
"use strict";
//Sandcastle_Begin
var viewer = new Cesium.Viewer("cesiumContainer", {
terrainProvider: Cesium.createWorldTerrain({
requestVertexNormals: true, //Needed to visualize slope
}),
});

viewer.camera.setView({
destination: new Cesium.Cartesian3(
290637.5534733206,
5637471.593707632,
2978256.8126927214
),
orientation: {
heading: 4.747266966349747,
pitch: -0.2206998858596192,
roll: 6.280340554587955,
},
});

var viewModel = {
gradient: false,
band1Position: 7000.0,
band2Position: 7500.0,
band3Position: 8000.0,
bandThickness: 100.0,
bandTransparency: 0.5,
backgroundTransparency: 0.75,
};

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(updateMaterial);
}
}

function updateMaterial() {
var gradient = Boolean(viewModel.gradient);
var band1Position = Number(viewModel.band1Position);
var band2Position = Number(viewModel.band2Position);
var band3Position = Number(viewModel.band3Position);
var bandThickness = Number(viewModel.bandThickness);
var bandTransparency = Number(viewModel.bandTransparency);
var backgroundTransparency = Number(viewModel.backgroundTransparency);

var layers = [];
var backgroundLayer = {
entries: [
{
height: 4200.0,
color: new Cesium.Color(0.0, 0.0, 0.2, backgroundTransparency),
},
{
height: 8000.0,
color: new Cesium.Color(1.0, 1.0, 1.0, backgroundTransparency),
},
{
height: 8500.0,
color: new Cesium.Color(1.0, 0.0, 0.0, backgroundTransparency),
},
],
extendDownwards: true,
extendUpwards: true,
};
layers.push(backgroundLayer);

var gridStartHeight = 4200.0;
var gridEndHeight = 8848.0;
var gridCount = 50;
for (var i = 0; i < gridCount; i++) {
var lerper = i / (gridCount - 1);
var heightBelow = Cesium.Math.lerp(
gridStartHeight,
gridEndHeight,
lerper
);
var heightAbove = heightBelow + 10.0;
var alpha =
Cesium.Math.lerp(0.2, 0.4, lerper) * backgroundTransparency;
layers.push({
entries: [
{
height: heightBelow,
color: new Cesium.Color(1.0, 1.0, 1.0, alpha),
},
{
height: heightAbove,
color: new Cesium.Color(1.0, 1.0, 1.0, alpha),
},
],
});
}

var antialias = Math.min(10.0, bandThickness * 0.1);

if (!gradient) {
var band1 = {
entries: [
{
height: band1Position - bandThickness * 0.5 - antialias,
color: new Cesium.Color(0.0, 0.0, 1.0, 0.0),
},
{
height: band1Position - bandThickness * 0.5,
color: new Cesium.Color(0.0, 0.0, 1.0, bandTransparency),
},
{
height: band1Position + bandThickness * 0.5,
color: new Cesium.Color(0.0, 0.0, 1.0, bandTransparency),
},
{
height: band1Position + bandThickness * 0.5 + antialias,
color: new Cesium.Color(0.0, 0.0, 1.0, 0.0),
},
],
};

var band2 = {
entries: [
{
height: band2Position - bandThickness * 0.5 - antialias,
color: new Cesium.Color(0.0, 1.0, 0.0, 0.0),
},
{
height: band2Position - bandThickness * 0.5,
color: new Cesium.Color(0.0, 1.0, 0.0, bandTransparency),
},
{
height: band2Position + bandThickness * 0.5,
color: new Cesium.Color(0.0, 1.0, 0.0, bandTransparency),
},
{
height: band2Position + bandThickness * 0.5 + antialias,
color: new Cesium.Color(0.0, 1.0, 0.0, 0.0),
},
],
};

var band3 = {
entries: [
{
height: band3Position - bandThickness * 0.5 - antialias,
color: new Cesium.Color(1.0, 0.0, 0.0, 0.0),
},
{
height: band3Position - bandThickness * 0.5,
color: new Cesium.Color(1.0, 0.0, 0.0, bandTransparency),
},
{
height: band3Position + bandThickness * 0.5,
color: new Cesium.Color(1.0, 0.0, 0.0, bandTransparency),
},
{
height: band3Position + bandThickness * 0.5 + antialias,
color: new Cesium.Color(1.0, 0.0, 0.0, 0.0),
},
],
};

layers.push(band1);
layers.push(band2);
layers.push(band3);
} else {
var combinedBand = {
entries: [
{
height: band1Position - bandThickness * 0.5,
color: new Cesium.Color(0.0, 0.0, 1.0, bandTransparency),
},
{
height: band2Position,
color: new Cesium.Color(0.0, 1.0, 0.0, bandTransparency),
},
{
height: band3Position + bandThickness * 0.5,
color: new Cesium.Color(1.0, 0.0, 0.0, bandTransparency),
},
],
};

layers.push(combinedBand);
}

var material = Cesium.createElevationBandMaterial({
scene: viewer.scene,
layers: layers,
});
viewer.scene.globe.material = material;
}

updateMaterial();
//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
window.startupCalled = true;
startup(Cesium);
}
</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.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

### 1.77 - 2020-01-04

##### Additions :tada:

- Added `ElevationBand` material, which maps colors / gradients to exact elevations. [#9132](https://github.com/CesiumGS/cesium/pull/9132)

##### Deprecated :hourglass_flowing_sand:

- `EasingFunction.QUADRACTIC_IN` was deprecated and will be removed in Cesium 1.79. It has been replaced with `EasingFunction.QUADRATIC_IN`. [#9220](https://github.com/CesiumGS/cesium/issues/9220)
Expand Down
Loading