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

Add ground atmosphere #6877

Merged
merged 39 commits into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b3aeee9
Add back ground atmosphere from space.
bagnell Jul 25, 2018
c052aa0
Fix fog.
bagnell Jul 25, 2018
381c0b2
Merge branch 'master' into atmosphere
bagnell Aug 1, 2018
75e14f7
Add option to enable disable ground atmosphere.
bagnell Aug 1, 2018
139a529
Fix sky atmosphere.
bagnell Aug 1, 2018
edc42fa
Revert sky atmosphere changes.
bagnell Aug 1, 2018
e642085
Remove unused code in sky atmosphere shader.
bagnell Aug 1, 2018
5f11c50
Fix night atmosphere color.
bagnell Aug 2, 2018
d3a9950
Use atmosphere with correct sun lighting.
bagnell Aug 2, 2018
bb402de
Make night fade in/out distances a uniform.
bagnell Aug 2, 2018
2e2b825
Update doc.
bagnell Aug 2, 2018
a708860
Fix 2D/CV.
bagnell Aug 2, 2018
31de234
Update CHANGES.md.
bagnell Aug 2, 2018
f6bf14c
Merge branch 'master' into atmosphere
bagnell Aug 3, 2018
dbccbd8
Merge branch 'master' into atmosphere
bagnell Aug 9, 2018
a7234d7
Merge branch 'master' into atmosphere
bagnell Aug 20, 2018
9d31730
Make ground atmosphere per-fragment for a smoother transition from ni…
bagnell Aug 20, 2018
2279eac
Only use per-fragment ground atmosphere when the camera is greater th…
bagnell Aug 20, 2018
f6a1522
Merge branch 'master' into atmosphere
bagnell Aug 23, 2018
1e6aafe
Merge branch 'master' into atmosphere
bagnell Aug 29, 2018
681fb0f
Merge branch 'master' into atmosphere
bagnell Sep 5, 2018
2225851
Update CHANGES.md after merge.
bagnell Sep 5, 2018
8da546f
Merge branch 'master' into atmosphere
bagnell Sep 6, 2018
fc3e0c7
Merge branch 'master' into atmosphere
bagnell Sep 11, 2018
4426bd2
Clean up globe shader parameters.
bagnell Sep 11, 2018
bfd11bd
More aggressive fade distances. Have enable lighting off by default.
bagnell Sep 11, 2018
7180803
Change water specular intensity when ground atmosphere is enabled.
bagnell Sep 11, 2018
80e591d
Fix day/night terrain shading.
bagnell Sep 11, 2018
e1005fe
Tweak params
lilleyse Sep 20, 2018
61cf20e
Merge branch 'master' into atmosphere
bagnell Sep 20, 2018
85b08e5
Fade water effect when zooming.
bagnell Sep 20, 2018
14e3114
Fix for when atmosphere is disabled.
bagnell Sep 20, 2018
3636dbb
Add atmosphere lighting example.
bagnell Sep 20, 2018
5e36c99
More tweaks
lilleyse Sep 21, 2018
a53cd15
Reset sliders and text box when the reset button is clicked in the at…
bagnell Sep 21, 2018
3fc5808
Update from review.
bagnell Sep 21, 2018
fe410fa
Remove input ids.
bagnell Sep 21, 2018
a623027
Fix fog.
bagnell Sep 21, 2018
b75d1cf
Update docs and changes a bit
lilleyse Sep 24, 2018
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
174 changes: 174 additions & 0 deletions Apps/Sandcastle/gallery/Atmosphere.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<!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="Adjust hue, saturation, and brightness of the sky/atmosphere.">
<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="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
<script type="text/javascript">
require.config({
baseUrl : '../../../Source',
waitSeconds : 60
});
</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;
}
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar">
<table><tbody>
<tr>
<td>Lighting Fade Out Distance</td>
<td>
<input type="range" min="1e6" max="1e8" step="1e6" data-bind="value: lightingFadeOutDistance, valueUpdate: 'input'">
<input type="text" size="10" data-bind="value: lightingFadeOutDistance">
</td>
</tr>
<tr>
<td>Lighting Fade In Distance</td>
<td>
<input type="range" min="1e6" max="1e8" step="1e6" data-bind="value: lightingFadeInDistance, valueUpdate: 'input'">
<input type="text" size="10" data-bind="value: lightingFadeInDistance">
</td>
</tr>
<tr>
<td>Night Fade Out Distance</td>
<td>
<input type="range" min="1e6" max="1e8" step="1e6" data-bind="value: nightFadeOutDistance, valueUpdate: 'input'">
<input type="text" size="10" data-bind="value: nightFadeOutDistance">
</td>
</tr>
<tr>
<td>Night Fade In Distance</td>
<td>
<input type="range" min="1e6" max="1e8" step="1e6" data-bind="value: nightFadeInDistance, valueUpdate: 'input'">
<input type="text" size="10" data-bind="value: nightFadeInDistance">
</td>
</tr>
</tbody></table>
</div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
'use strict';
//Sandcastle_Begin
var viewer = new Cesium.Viewer('cesiumContainer', {
sceneModePicker:false
});
var scene = viewer.scene;
var globe = scene.globe;

var defaultLightFadeOut = globe.lightingFadeOutDistance;
var defaultLightFadeIn = globe.lightingFadeInDistance;
var defaultNightFadeOut = globe.nightFadeOutDistance;
var defaultNightFadeIn = globe.nightFadeInDistance;

// The viewModel tracks the state of our mini application.
var viewModel = {
lightingFadeOutDistance : defaultLightFadeOut,
lightingFadeInDistance : defaultLightFadeIn,
nightFadeOutDistance : defaultNightFadeOut,
nightFadeInDistance : defaultNightFadeIn
};
// Convert the viewModel members into knockout observables.
Cesium.knockout.track(viewModel);

// Bind the viewModel to the DOM elements of the UI that call for it.
var toolbar = document.getElementById('toolbar');
Cesium.knockout.applyBindings(viewModel, toolbar);

// Make the skyAtmosphere's HSB parameters subscribers of the viewModel.
function subscribeParameter(name) {
Cesium.knockout.getObservable(viewModel, name).subscribe(
function(newValue) {
globe[name] = newValue;
}
);
}

subscribeParameter('lightingFadeOutDistance');
subscribeParameter('lightingFadeInDistance');
subscribeParameter('nightFadeOutDistance');
subscribeParameter('nightFadeInDistance');

Sandcastle.addToggleButton('Ground atmosphere', globe.showGroundAtmosphere, function(checked) {
globe.showGroundAtmosphere = checked;
});

Sandcastle.addToggleButton('Lighting', globe.enableLighting, function(checked) {
globe.enableLighting = checked;
});

Sandcastle.addToolbarMenu([{
text : 'Cesium World Terrain - no effects',
onselect : function() {
viewer.terrainProvider = Cesium.createWorldTerrain();
}
}, {
text : 'Cesium World Terrain w/ Vertex Normals',
onselect : function() {
viewer.terrainProvider = Cesium.createWorldTerrain({
requestVertexNormals : true
});
}
}, {
text : 'Cesium World Terrain w/ Water',
onselect : function() {
viewer.terrainProvider = Cesium.createWorldTerrain({
requestWaterMask : true
});
}
}, {
text : 'Cesium World Terrain w/ Vertex Normals and Water',
onselect : function() {
viewer.terrainProvider = Cesium.createWorldTerrain({
requestVertexNormals : true,
requestWaterMask : true
});
}
}, {
text : 'EllipsoidTerrainProvider',
onselect : function() {
viewer.terrainProvider = new Cesium.EllipsoidTerrainProvider();
}
}]);

Sandcastle.addToolbarButton('Reset Fade Distances', function() {
globe.lightingFadeOutDistance = defaultLightFadeOut;
globe.lightingFadeInDistance = defaultLightFadeIn;
globe.nightFadeOutDistance = defaultNightFadeOut;
globe.nightFadeInDistance = defaultNightFadeIn;

viewModel.lightingFadeOutDistance = defaultLightFadeOut;
viewModel.lightingFadeInDistance = defaultLightFadeIn;
viewModel.nightFadeOutDistance = defaultNightFadeOut;
viewModel.nightFadeInDistance = defaultNightFadeIn;
});

//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== 'undefined') {
startup(Cesium);
} else if (typeof require === 'function') {
require(['Cesium'], startup);
}
</script>
</body>
</html>
Binary file added Apps/Sandcastle/gallery/Atmosphere.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Change Log
* Update [gltf-pipeline](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/) to 2.0. [#6805](https://github.com/AnalyticalGraphicsInc/cesium/pull/6805)
* Added `cartographicLimitRectangle` to `Globe`. Use this to limit terrain and imagery to a specific `Rectangle` area. [#6987](https://github.com/AnalyticalGraphicsInc/cesium/pull/6987)
* Added `OpenCageGeocoderService`, which provides geocoding via [OpenCage](https://opencagedata.com/). [#7015](https://github.com/AnalyticalGraphicsInc/cesium/pull/7015)
* Added ground atmosphere lighting in 3D. This can be toggled with `Globe.showGroundAtmosphere`. [6877](https://github.com/AnalyticalGraphicsInc/cesium/pull/6877)
* Added `Globe.nightFadeOutDistance` and `Globe.nightFadeInDistance` to configure when ground atmosphere night lighting fades in and out. [6877](https://github.com/AnalyticalGraphicsInc/cesium/pull/6877)

##### Fixes :wrench:
* Fixed picking for overlapping translucent primitives. [#7039](https://github.com/AnalyticalGraphicsInc/cesium/pull/7039)
Expand Down
52 changes: 40 additions & 12 deletions Source/Scene/Globe.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,53 @@ define([
* Enable lighting the globe with the sun as a light source.
*
* @type {Boolean}
* @default false
* @default true
*/
this.enableLighting = false;

/**
* Enable the ground atmosphere.
*
* @type {Boolean}
* @default true
*/
this.showGroundAtmosphere = true;

/**
* The distance where everything becomes lit. This only takes effect
* when <code>enableLighting</code> is <code>true</code>.
*
* @type {Number}
* @default 6500000.0
* @default 10000000.0
*/
this.lightingFadeOutDistance = 6500000.0;
this.lightingFadeOutDistance = 1.0e7;

/**
* The distance where lighting resumes. This only takes effect
* when <code>enableLighting</code> is <code>true</code>.
*
* @type {Number}
* @default 9000000.0
* @default 20000000.0
*/
this.lightingFadeInDistance = 2.0e7;

/**
* The distance where the darkness of night from the ground atmosphere fades out to a lit ground atmosphere.
* This only takes effect when <code>showGroundAtmosphere</code> and <code>enableLighting</code> are <code>true</code>.
*
* @type {Number}
* @default 10000000.0
*/
this.nightFadeOutDistance = 1.0e7;

/**
* The distance where the darkness of night from the ground atmosphere fades in to an unlit ground atmosphere.
* This only takes effect when <code>showGroundAtmosphere</code> and <code>enableLighting</code> are <code>true</code>.
*
* @type {Number}
* @default 50000000.0
*/
this.lightingFadeInDistance = 9000000.0;
this.nightFadeInDistance = 5.0e7;

/**
* True if an animated wave effect should be shown in areas of the globe
Expand Down Expand Up @@ -187,7 +213,7 @@ define([
this.shadows = ShadowMode.RECEIVE_ONLY;

this._oceanNormalMap = undefined;
this._zoomedOutOceanSpecularIntensity = 0.5;
this._zoomedOutOceanSpecularIntensity = undefined;
}

defineProperties(Globe.prototype, {
Expand Down Expand Up @@ -372,7 +398,7 @@ define([

var requireNormals = defined(globe._material) && (globe._material.shaderSource.match(/slope/) || globe._material.shaderSource.match('normalEC'));

var fragmentSources = [];
var fragmentSources = [GroundAtmosphere];
if (defined(globe._material) && (!requireNormals || globe._terrainProvider.requestVertexNormals)) {
fragmentSources.push(globe._material.shaderSource);
defines.push('APPLY_MATERIAL');
Expand Down Expand Up @@ -640,11 +666,10 @@ define([
var mode = frameState.mode;

if (pass.render) {
// Don't show the ocean specular highlights when zoomed out in 2D and Columbus View.
if (mode === SceneMode.SCENE3D) {
this._zoomedOutOceanSpecularIntensity = 0.5;
if (this.showGroundAtmosphere) {
this._zoomedOutOceanSpecularIntensity = 0.4;
} else {
this._zoomedOutOceanSpecularIntensity = 0.0;
this._zoomedOutOceanSpecularIntensity = 0.5;
}

surface.maximumScreenSpaceError = this.maximumScreenSpaceError;
Expand All @@ -653,10 +678,13 @@ define([
tileProvider.terrainProvider = this.terrainProvider;
tileProvider.lightingFadeOutDistance = this.lightingFadeOutDistance;
tileProvider.lightingFadeInDistance = this.lightingFadeInDistance;
tileProvider.zoomedOutOceanSpecularIntensity = this._zoomedOutOceanSpecularIntensity;
tileProvider.nightFadeOutDistance = this.nightFadeOutDistance;
tileProvider.nightFadeInDistance = this.nightFadeInDistance;
tileProvider.zoomedOutOceanSpecularIntensity = mode === SceneMode.SCENE3D ? this._zoomedOutOceanSpecularIntensity : 0.0;
tileProvider.hasWaterMask = hasWaterMask;
tileProvider.oceanNormalMap = this._oceanNormalMap;
tileProvider.enableLighting = this.enableLighting;
tileProvider.showGroundAtmosphere = this.showGroundAtmosphere;
tileProvider.shadows = this.shadows;

surface.beginFrame(frameState);
Expand Down
50 changes: 41 additions & 9 deletions Source/Scene/GlobeSurfaceShaderSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,29 @@ define([
return useWebMercatorProjection ? get2DYPositionFractionMercatorProjection : get2DYPositionFractionGeographicProjection;
}

GlobeSurfaceShaderSet.prototype.getShaderProgram = function(frameState, surfaceTile, numberOfDayTextures, applyBrightness, applyContrast, applyHue, applySaturation, applyGamma, applyAlpha, applySplit, showReflectiveOcean, showOceanWaves, enableLighting, hasVertexNormals, useWebMercatorProjection, enableFog, enableClippingPlanes, clippingPlanes, clippedByBoundaries) {
GlobeSurfaceShaderSet.prototype.getShaderProgram = function(options) {
var frameState = options.frameState;
var surfaceTile = options.surfaceTile;
var numberOfDayTextures = options.numberOfDayTextures;
var applyBrightness = options.applyBrightness;
var applyContrast = options.applyContrast;
var applyHue = options.applyHue;
var applySaturation = options.applySaturation;
var applyGamma = options.applyGamma;
var applyAlpha = options.applyAlpha;
var applySplit = options.applySplit;
var showReflectiveOcean = options.showReflectiveOcean;
var showOceanWaves = options.showOceanWaves;
var enableLighting = options.enableLighting;
var showGroundAtmosphere = options.showGroundAtmosphere;
var perFragmentGroundAtmosphere = options.perFragmentGroundAtmosphere;
var hasVertexNormals = options.hasVertexNormals;
var useWebMercatorProjection = options.useWebMercatorProjection;
var enableFog = options.enableFog;
var enableClippingPlanes = options.enableClippingPlanes;
var clippingPlanes = options.clippingPlanes;
var clippedByBoundaries = options.clippedByBoundaries;

var quantization = 0;
var quantizationDefine = '';

Expand Down Expand Up @@ -102,14 +124,16 @@ define([
(showReflectiveOcean << 8) |
(showOceanWaves << 9) |
(enableLighting << 10) |
(hasVertexNormals << 11) |
(useWebMercatorProjection << 12) |
(enableFog << 13) |
(quantization << 14) |
(applySplit << 15) |
(enableClippingPlanes << 16) |
(vertexLogDepth << 17) |
(cartographicLimitRectangleFlag << 18);
(showGroundAtmosphere << 11) |
(perFragmentGroundAtmosphere << 12) |
(hasVertexNormals << 13) |
(useWebMercatorProjection << 14) |
(enableFog << 15) |
(quantization << 16) |
(applySplit << 17) |
(enableClippingPlanes << 18) |
(vertexLogDepth << 19) |
(cartographicLimitRectangleFlag << 20);

var currentClippingShaderState = 0;
if (defined(clippingPlanes)) {
Expand Down Expand Up @@ -180,6 +204,14 @@ define([
}
}

if (showGroundAtmosphere) {
vs.defines.push('GROUND_ATMOSPHERE');
fs.defines.push('GROUND_ATMOSPHERE');
if (perFragmentGroundAtmosphere) {
fs.defines.push('PER_FRAGMENT_GROUND_ATMOSPHERE');
}
}

vs.defines.push('INCLUDE_WEB_MERCATOR_Y');
fs.defines.push('INCLUDE_WEB_MERCATOR_Y');

Expand Down
Loading