-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Fog #3154
Fog #3154
Changes from 14 commits
e0efc3a
7655844
7e59d39
60e8bd5
b05a074
9b690c7
7894da3
d397e32
8fd263d
41b9330
bebe65c
01f6a6c
9d3b07a
ca742f9
9d6a8e6
80f3f28
8a8c75d
d2df9a1
d2c927b
64a2be8
95048fd
582426a
dd54283
1a194b7
d84186f
f07d538
c5d7341
325d393
35295de
ff61da5
d11c50b
85cc52b
7902c29
5420561
64828bc
22de5d1
6f8fb41
403b049
10a3b97
c6ce4c2
333c8f0
186c63f
7d7c3b2
ed30aa0
28d15df
4cccade
3ba3717
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
<!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="Control fog parameters."> | ||
<meta name="cesium-sandcastle-labels" content="Development"> | ||
<title>Cesium Demo</title> | ||
<script type="text/javascript" src="../Sandcastle-header.js"></script> | ||
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.9/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); | ||
</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>start height</td> | ||
<td><input type="text" size="5" data-bind="value: startHeight"></td> | ||
</tr> | ||
<tr> | ||
<td>start density</td> | ||
<td><input type="text" size="5" data-bind="value: startDensity"></td> | ||
</tr> | ||
<tr> | ||
<td>end height</td> | ||
<td><input type="text" size="5" data-bind="value: endHeight"></td> | ||
</tr> | ||
<tr> | ||
<td>end density</td> | ||
<td><input type="text" size="5" data-bind="value: endDensity"></td> | ||
</tr> | ||
</tbody></table> | ||
<div id="zoomButtons"></div> | ||
</div> | ||
<script id="cesium_sandcastle_script"> | ||
function startup(Cesium) { | ||
"use strict"; | ||
//Sandcastle_Begin | ||
var viewer = new Cesium.Viewer('cesiumContainer'); | ||
viewer.terrainProvider = new Cesium.CesiumTerrainProvider({ | ||
url : '//assets.agi.com/stk-terrain/world', | ||
requestWaterMask : true, | ||
requestVertexNormals : true | ||
}); | ||
|
||
viewer.extend(Cesium.viewerCesiumInspectorMixin); | ||
|
||
/* | ||
viewer.imageryLayers.removeAll(); | ||
viewer.imageryLayers.addImageryProvider(new Cesium.TileMapServiceImageryProvider({ | ||
url : require.toUrl('Assets/Textures/NaturalEarthII') | ||
})); | ||
*/ | ||
|
||
//viewer.scene.globe.enableLighting = true; | ||
|
||
//The viewModel tracks the state of our mini application. | ||
var viewModel = { | ||
enabled : true, | ||
startDensity : 0, | ||
endDensity : 0, | ||
startHeight : 0, | ||
endHeight : 0 | ||
}; | ||
// 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); | ||
|
||
Cesium.knockout.getObservable(viewModel, 'enabled').subscribe( | ||
function(newValue) { | ||
viewer.scene.fogEnabled = newValue; | ||
} | ||
); | ||
|
||
Cesium.knockout.getObservable(viewModel, 'startDensity').subscribe( | ||
function(newValue) { | ||
viewer.scene.fogStartDensity = newValue; | ||
} | ||
); | ||
|
||
Cesium.knockout.getObservable(viewModel, 'endDensity').subscribe( | ||
function(newValue) { | ||
viewer.scene.fogEndDensity = newValue; | ||
} | ||
); | ||
|
||
Cesium.knockout.getObservable(viewModel, 'startHeight').subscribe( | ||
function(newValue) { | ||
viewer.scene.fogStartHeight = newValue; | ||
} | ||
); | ||
|
||
Cesium.knockout.getObservable(viewModel, 'endHeight').subscribe( | ||
function(newValue) { | ||
viewer.scene.fogEndHeight = newValue; | ||
} | ||
); | ||
|
||
viewModel.enabled = viewer.scene.fogEnabled; | ||
viewModel.startDensity = viewer.scene.fogStartDensity; | ||
viewModel.endDensity = viewer.scene.fogEndDensity; | ||
viewModel.startHeight = viewer.scene.fogStartHeight; | ||
viewModel.endHeight = viewer.scene.fogEndHeight; | ||
|
||
/* | ||
Sandcastle.addToolbarMenu([{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using the same views we used for OBBs: http://cesiumjs.org/2015/06/24/Oriented-Bounding-Boxes/ Instead of commenting them out, they could be in a drop down for future testing. |
||
text : 'Half Dome', | ||
onselect : function() { | ||
var target = new Cesium.Cartesian3(-2489625.0836225147, -4393941.44443024, 3882535.9454173897); | ||
var offset = new Cesium.Cartesian3(-6857.40902037546, 412.3284835694358, 2147.5545426812023); | ||
viewer.camera.lookAt(target, offset); | ||
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY); | ||
} | ||
}, { | ||
text : 'Mount Everest', | ||
onselect : function() { | ||
var target = new Cesium.Cartesian3(300770.50872389384, 5634912.131394585, 2978152.2865545116); | ||
var offset = new Cesium.Cartesian3(6344.974098678562, -793.3419798081741, 2499.9508860763162); | ||
viewer.camera.lookAt(target, offset); | ||
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY); | ||
} | ||
}, { | ||
text : 'San Francisco Bay', | ||
onselect : function() { | ||
var target = new Cesium.Cartesian3(-2708814.85583248, -4254159.450845907, 3891403.9457429945); | ||
var offset = new Cesium.Cartesian3(70642.66030209465, -31661.517948317807, 35505.179997143336); | ||
viewer.camera.lookAt(target, offset); | ||
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY); | ||
} | ||
}], 'zoomButtons'); | ||
*/ | ||
|
||
var scene = viewer.scene; | ||
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas); | ||
handler.setInputAction(function(movement) { | ||
var ray = scene.camera.getPickRay(movement.position); | ||
var pickedPosition = scene.globe.pick(ray, scene); | ||
if (Cesium.defined(pickedPosition)) { | ||
console.log(Cesium.Cartesian3.distance(pickedPosition, scene.camera.position)); | ||
} | ||
}, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK); | ||
|
||
scene.camera.setView({ | ||
destination : new Cesium.Cartesian3(-2467070.494299382, -4414079.174382873, 3880669.8976452565), | ||
orientation : { | ||
heading : 1.7833456822869636, | ||
pitch : -0.1764684555868994 | ||
} | ||
}); | ||
|
||
scene.globe._surface._debug.enableDebugOutput = true; | ||
|
||
//Sandcastle_End | ||
Sandcastle.finishedLoading(); | ||
} | ||
if (typeof Cesium !== "undefined") { | ||
startup(Cesium); | ||
} else if (typeof require === "function") { | ||
require(["Cesium"], startup); | ||
} | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,6 +135,9 @@ define([ | |
* @default false | ||
*/ | ||
this.scene3DOnly = false; | ||
|
||
this.fogEnabled = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps put these in one |
||
this.fogDensity = undefined; | ||
}; | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -438,10 +438,18 @@ define([ | |
* @returns {Visibility} The visibility of the tile. | ||
*/ | ||
GlobeSurfaceTileProvider.prototype.computeTileVisibility = function(tile, frameState, occluders) { | ||
var surfaceTile = tile.data; | ||
if (frameState.fogEnabled) { | ||
var distance = this.computeDistanceToTile(tile, frameState); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are now computing this distance more than once per frame, right? It burns a good bit of CPU (profile, but I bet it is non-trivial). Let's cache this like 3D Tiles: https://github.com/AnalyticalGraphicsInc/cesium/blob/3d-tiles/Source/Scene/Cesium3DTileset.js#L389 |
||
var scalar = distance * frameState.fogDensity; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move the fog equation to a |
||
var fog = 1.0 - Math.exp(-(scalar * scalar)); | ||
|
||
var cullingVolume = frameState.cullingVolume; | ||
if (fog >= 1.0) { | ||
return Visibility.NONE; | ||
} | ||
} | ||
|
||
var surfaceTile = tile.data; | ||
var cullingVolume = frameState.cullingVolume; | ||
var boundingVolume = defaultValue(surfaceTile.orientedBoundingBox, surfaceTile.boundingSphere3D); | ||
|
||
if (frameState.mode !== SceneMode.SCENE3D) { | ||
|
@@ -930,6 +938,7 @@ define([ | |
var oceanNormalMap = tileProvider.oceanNormalMap; | ||
var showOceanWaves = showReflectiveOcean && defined(oceanNormalMap); | ||
var hasVertexNormals = tileProvider.terrainProvider.ready && tileProvider.terrainProvider.hasVertexNormals; | ||
var enableFog = frameState.fogEnabled; | ||
|
||
if (showReflectiveOcean) { | ||
--maxTextures; | ||
|
@@ -1117,7 +1126,7 @@ define([ | |
uniformMap.waterMask = waterMaskTexture; | ||
Cartesian4.clone(surfaceTile.waterMaskTranslationAndScale, uniformMap.waterMaskTranslationAndScale); | ||
|
||
command.shaderProgram = tileProvider._surfaceShaderSet.getShaderProgram(context, frameState.mode, surfaceTile, numberOfDayTextures, applyBrightness, applyContrast, applyHue, applySaturation, applyGamma, applyAlpha, showReflectiveOcean, showOceanWaves, tileProvider.enableLighting, hasVertexNormals, useWebMercatorProjection); | ||
command.shaderProgram = tileProvider._surfaceShaderSet.getShaderProgram(context, frameState.mode, surfaceTile, numberOfDayTextures, applyBrightness, applyContrast, applyHue, applySaturation, applyGamma, applyAlpha, showReflectiveOcean, showOceanWaves, tileProvider.enableLighting, hasVertexNormals, useWebMercatorProjection, enableFog); | ||
command.renderState = renderState; | ||
command.primitiveType = PrimitiveType.TRIANGLES; | ||
command.vertexArray = surfaceTile.vertexArray; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -505,6 +505,12 @@ define([ | |
*/ | ||
this.copyGlobeDepth = false; | ||
|
||
this.fogEnabled = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should probably be on a new |
||
this.fogStartDensity = 0.00002; | ||
this.fogEndDensity = 9e-8; | ||
this.fogStartHeight = 2000.0; | ||
this.fogEndHeight = 100000.0; | ||
|
||
this._performanceDisplay = undefined; | ||
this._debugVolume = undefined; | ||
|
||
|
@@ -955,6 +961,24 @@ define([ | |
return undefined; | ||
} | ||
|
||
function updateFog(scene) { | ||
var frameState = scene.frameState; | ||
var enabled = frameState.fogEnabled = scene.fogEnabled; | ||
if (enabled) { | ||
var height = scene.camera.positionCartographic.height; | ||
|
||
var startHeight = scene.fogStartHeight; | ||
var endHeight = scene.fogEndHeight; | ||
|
||
var startDensity = scene.fogStartDensity; | ||
var endDensity = scene.fogEndDensity; | ||
|
||
var t = CesiumMath.smoothstep(startHeight, endHeight, height); | ||
t = CesiumMath.clamp(t, 0.0, 1.0); | ||
frameState.fogDensity = CesiumMath.lerp(startDensity, endDensity, t); | ||
} | ||
} | ||
|
||
function clearPasses(passes) { | ||
passes.render = false; | ||
passes.pick = false; | ||
|
@@ -975,6 +999,7 @@ define([ | |
frameState.occluder = getOccluder(scene); | ||
|
||
clearPasses(frameState.passes); | ||
updateFog(scene); | ||
} | ||
|
||
function updateFrustums(near, far, farToNearRatio, numFrustums, frustumCommandsList) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The globe is not visible in the default view. Should we update this?