Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into uniforms-2
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcozzi committed Feb 13, 2015
2 parents 3767e7a + e8f49fe commit a877a15
Show file tree
Hide file tree
Showing 16 changed files with 231 additions and 327 deletions.
5 changes: 3 additions & 2 deletions Apps/Sandcastle/gallery/Cesium Inspector.html
Expand Up @@ -38,8 +38,9 @@
var ellipsoid = globe.ellipsoid;

var cesiumTerrainProviderHeightmaps = new Cesium.CesiumTerrainProvider({
url : '//cesiumjs.org/smallterrain',
credit : 'Terrain data courtesy Analytical Graphics, Inc.'
url : '//assets.agi.com/stk-terrain/world',
requestWaterMask: true,
requestVertexNormals: true
});

viewer.terrainProvider = cesiumTerrainProviderHeightmaps;
Expand Down
106 changes: 67 additions & 39 deletions Apps/Sandcastle/gallery/Terrain.html
Expand Up @@ -25,6 +25,7 @@
<div id="toolbar">
<div id="terrainMenu"></div>
<div id="zoomButtons"></div>
<div id="toggleLighting"></div>
<div id="sampleButtons"></div>
</div>
<script id="cesium_sandcastle_script">
Expand All @@ -37,13 +38,10 @@
var globe = scene.globe;
globe.depthTestAgainstTerrain = true;

var cesiumTerrainProviderHeightmaps = new Cesium.CesiumTerrainProvider({
url : '//cesiumjs.org/smallterrain',
credit : 'Terrain data courtesy Analytical Graphics, Inc.'
});

var cesiumTerrainProviderMeshes = new Cesium.CesiumTerrainProvider({
url : '//cesiumjs.org/stk-terrain/tilesets/world/tiles'
url : '//assets.agi.com/stk-terrain/world',
requestWaterMask : true,
requestVertexNormals : true
});

var ellipsoidProvider = new Cesium.EllipsoidTerrainProvider();
Expand All @@ -56,14 +54,34 @@
viewer.terrainProvider = cesiumTerrainProviderMeshes;

Sandcastle.addToolbarMenu([{
text : 'CesiumTerrainProvider - STK World Terrain meshes',
text : 'CesiumTerrainProvider - STK World Terrain',
onselect : function() {
viewer.terrainProvider = cesiumTerrainProviderMeshes;
viewer.scene.globe.enableLighting = true;
}
}, {
text : 'CesiumTerrainProvider - STK World Terrain - no effects',
onselect : function() {
viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
url : '//assets.agi.com/stk-terrain/world'
});
}
}, {
text : 'CesiumTerrainProvider - Small Terrain heightmaps and water mask',
text : 'CesiumTerrainProvider - STK World Terrain w/ Lighting',
onselect : function() {
viewer.terrainProvider = cesiumTerrainProviderHeightmaps;
viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
url : '//assets.agi.com/stk-terrain/world',
requestVertexNormals : true
});
viewer.scene.globe.enableLighting = true;
}
}, {
text : 'CesiumTerrainProvider - STK World Terrain w/ Water',
onselect : function() {
viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
url : '//assets.agi.com/stk-terrain/world',
requestWaterMask : true
});
}
}, {
text : 'EllipsoidTerrainProvider',
Expand All @@ -77,38 +95,43 @@
}
}], 'terrainMenu');

Sandcastle.addToolbarButton('Mount Everest', function() {
if (scene.mode === Cesium.SceneMode.SCENE3D || scene.mode === Cesium.SceneMode.COLUMBUS_VIEW) {
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);
} else {
viewer.camera.viewRectangle(new Cesium.Rectangle(1.516102969, 0.48744464, 1.518102969, 0.48944464));
Sandcastle.addToolbarMenu([{
text : 'Mount Everest',
onselect : function() {
if (scene.mode === Cesium.SceneMode.SCENE3D || scene.mode === Cesium.SceneMode.COLUMBUS_VIEW) {
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);
} else {
viewer.camera.viewRectangle(new Cesium.Rectangle(1.516102969, 0.48744464, 1.518102969, 0.48944464));
}
}
}, 'zoomButtons');

Sandcastle.addToolbarButton('Half Dome', function() {
if (scene.mode === Cesium.SceneMode.SCENE3D || scene.mode === Cesium.SceneMode.COLUMBUS_VIEW) {
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);
} else {
viewer.camera.viewRectangle(new Cesium.Rectangle(-2.08724538, 0.6577939, -2.08524538, 0.6597939));
}, {
text : 'Half Dome',
onselect : function() {
if (scene.mode === Cesium.SceneMode.SCENE3D || scene.mode === Cesium.SceneMode.COLUMBUS_VIEW) {
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);
} else {
viewer.camera.viewRectangle(new Cesium.Rectangle(-2.08724538, 0.6577939, -2.08524538, 0.6597939));
}
}
}, 'zoomButtons');

Sandcastle.addToolbarButton('San Francisco Bay', function() {
if (scene.mode === Cesium.SceneMode.SCENE3D || scene.mode === Cesium.SceneMode.COLUMBUS_VIEW) {
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);
} else {
viewer.camera.viewRectangle(new Cesium.Rectangle(-2.147621889, 0.64829691, -2.125621889, 0.67029691));
}, {
text : 'San Francisco Bay',
onselect : function() {
if (scene.mode === Cesium.SceneMode.SCENE3D || scene.mode === Cesium.SceneMode.COLUMBUS_VIEW) {
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);
} else {
viewer.camera.viewRectangle(new Cesium.Rectangle(-2.147621889, 0.64829691, -2.125621889, 0.67029691));
}
}
}, 'zoomButtons');
}], 'zoomButtons');

var terrainSamplePositions;

Expand Down Expand Up @@ -141,6 +164,11 @@
viewer.entities.resumeEvents();
}

Sandcastle.addToolbarButton('Toggle Lighting', function() {
viewer.scene.globe.enableLighting = !viewer.scene.globe.enableLighting;
}, 'toggleLighting');


Sandcastle.addToolbarButton('Sample Everest Terrain', function() {
var gridWidth = 41;
var gridHeight = 41;
Expand All @@ -161,7 +189,7 @@
Cesium.when(Cesium.sampleTerrain(viewer.terrainProvider, 9, terrainSamplePositions), sampleTerrainSuccess);
}, 'sampleButtons');
//Sandcastle_End
Sandcastle.finishedLoading();
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
startup(Cesium);
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -10,6 +10,7 @@ Change Log
* Removed `Camera.setPositionCartographic`, which was was deprecated in Cesium 1.6. Use `Camera.setView`.
* Fixed incorrect ellipse texture coordinates. [#2363](https://github.com/AnalyticalGraphicsInc/cesium/issues/2363) and [#2465](https://github.com/AnalyticalGraphicsInc/cesium/issues/2465)
* Fixed a bug in imagery loading that could cause some or all of the globe to be missing when using an imagery layer that does not cover the entire globe.
* Added support for rendering a water effect on Quantized-Mesh terrain tiles.
* Added `pack` and `unpack` functions to `Matrix2` and `Matrix3`.

### 1.6 - 2015-02-02
Expand Down
55 changes: 45 additions & 10 deletions Source/Core/CesiumTerrainProvider.js
Expand Up @@ -57,6 +57,7 @@ define([
* @param {String} options.url The URL of the Cesium terrain server.
* @param {Proxy} [options.proxy] A proxy to use for requests. This object is expected to have a getURL function which returns the proxied URL, if needed.
* @param {Boolean} [options.requestVertexNormals=false] Flag that indicates if the client should request additional lighting information from the server, in the form of per vertex normals if available.
* @param {Boolean} [options.requestWaterMask=false] Flag that indicates if the client should request per tile water masks from the server, if available.
* @param {Credit|String} [options.credit] A credit for the data source, which is displayed on the canvas.
*
* @see TerrainProvider
Expand Down Expand Up @@ -121,6 +122,13 @@ define([
*/
this._requestVertexNormals = defaultValue(options.requestVertexNormals, false);
this._littleEndianExtensionSize = true;
/**
* Boolean flag that indicates if the client should request tile watermasks from the server.
* @type {Boolean}
* @default false
* @private
*/
this._requestWaterMask = defaultValue(options.requestWaterMask, false);

this._errorEvent = new Event();

Expand Down Expand Up @@ -165,9 +173,8 @@ define([
isBigEndian : false
};
that._hasWaterMask = true;
} else if (data.format.indexOf('quantized-mesh-1.') === 0) {
that._hasWaterMask = false;
} else {
that._requestWaterMask = true;
} else if (data.format.indexOf('quantized-mesh-1.') !== 0) {
message = 'The tile format "' + data.format + '" is invalid or not supported.';
metadataError = TileProviderError.handleError(metadataError, that, that._errorEvent, message, undefined, undefined, undefined, requestMetadata);
return;
Expand Down Expand Up @@ -198,6 +205,9 @@ define([
that._hasVertexNormals = true;
that._littleEndianExtensionSize = false;
}
if (defined(data.extensions) && data.extensions.indexOf('watermask') !== -1) {
that._hasWaterMask = true;
}

that._ready = true;
}
Expand Down Expand Up @@ -245,7 +255,15 @@ define([
* @constant
* @default 1
*/
OCT_VERTEX_NORMALS: 1
OCT_VERTEX_NORMALS: 1,
/**
* A watermask is included as an extension to the tile mesh
*
* @type {Number}
* @constant
* @default 2
*/
WATER_MASK: 2
};

function getRequestHeader(extensionsList) {
Expand Down Expand Up @@ -380,14 +398,17 @@ define([
pos += northVertexCount * bytesPerIndex;

var encodedNormalBuffer;
var waterMaskBuffer;
while (pos < view.byteLength) {
var extensionId = view.getUint8(pos, true);
pos += Uint8Array.BYTES_PER_ELEMENT;
var extensionLength = view.getUint32(pos, provider._littleEndianExtensionSize);
pos += Uint32Array.BYTES_PER_ELEMENT;

if (extensionId === QuantizedMeshExtensionIds.OCT_VERTEX_NORMALS) {
if (extensionId === QuantizedMeshExtensionIds.OCT_VERTEX_NORMALS && provider._requestVertexNormals) {
encodedNormalBuffer = new Uint8Array(buffer, pos, vertexCount * 2);
} else if (extensionId === QuantizedMeshExtensionIds.WATER_MASK && provider._requestWaterMask) {
waterMaskBuffer = new Uint8Array(buffer, pos, extensionLength);
}
pos += extensionLength;
}
Expand All @@ -411,7 +432,8 @@ define([
southSkirtHeight : skirtHeight,
eastSkirtHeight : skirtHeight,
northSkirtHeight : skirtHeight,
childTileMask: getChildMaskForTile(provider, level, x, tmsY)
childTileMask: getChildMaskForTile(provider, level, x, tmsY),
waterMask: waterMaskBuffer
});
}

Expand Down Expand Up @@ -463,6 +485,9 @@ define([
if (this._requestVertexNormals && this._hasVertexNormals) {
extensionList.push(this._littleEndianExtensionSize ? "octvertexnormals" : "vertexnormals");
}
if (this._requestWaterMask && this._hasWaterMask) {
extensionList.push("watermask");
}

var tileLoader = function(tileUrl) {
return loadArrayBuffer(tileUrl, getRequestHeader(extensionList));
Expand Down Expand Up @@ -566,7 +591,7 @@ define([
}
//>>includeEnd('debug');

return this._hasWaterMask;
return this._hasWaterMask && this._requestWaterMask;
}
},

Expand Down Expand Up @@ -594,16 +619,26 @@ define([
* Boolean flag that indicates if the client should request vertex normals from the server.
* Vertex normals data is appended to the standard tile mesh data only if the client requests the vertex normals and
* if the server provides vertex normals.
*
* This property is read only. To change this value, a new CesiumTerrainProvider must be constructed that requests
* vertex normals to ensure that all existing tiles are requested that includes/excludes vertex normal extension data.
* @memberof CesiumTerrainProvider.prototype
* @type {Boolean}
*/
requestVertexNormals : {
get : function() {
return this._requestVertexNormals;
}
},

/**
* Boolean flag that indicates if the client should request a watermask from the server.
* Watermask data is appended to the standard tile mesh data only if the client requests the watermask and
* if the server provides a watermask.
* @memberof CesiumTerrainProvider.prototype
* @type {Boolean}
*/
requestWaterMask : {
get : function() {
return this._requestWaterMask;
}
}
});

Expand Down
3 changes: 2 additions & 1 deletion Source/Core/QuantizedMeshTerrainData.js
Expand Up @@ -41,7 +41,6 @@ define([
* @param {Uint16Array} options.quantizedVertices The buffer containing the quantized mesh.
* @param {Uint16Array|Uint32Array} options.indices The indices specifying how the quantized vertices are linked
* together into triangles. Each three indices specifies one triangle.
* @param {Uint8Array} options.encodedNormals The buffer containing per vertex normals, encoded using 'oct' encoding
* @param {Number} options.minimumHeight The minimum terrain height within the tile, in meters above the ellipsoid.
* @param {Number} options.maximumHeight The maximum terrain height within the tile, in meters above the ellipsoid.
* @param {BoundingSphere} options.boundingSphere A sphere bounding all of the vertices in the mesh.
Expand Down Expand Up @@ -69,6 +68,8 @@ define([
* </table>
* @param {Boolean} [options.createdByUpsampling=false] True if this instance was created by upsampling another instance;
* otherwise, false.
* @param {Uint8Array} [options.encodedNormals] The buffer containing per vertex normals, encoded using 'oct' encoding
* @param {Uint8Array} [options.waterMask] The buffer containing the watermask.
*
* @see TerrainData
* @see HeightmapTerrainData
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/sampleTerrain.js
Expand Up @@ -31,7 +31,7 @@ define([
* @example
* // Query the terrain height of two Cartographic positions
* var terrainProvider = new Cesium.CesiumTerrainProvider({
* url : '//cesiumjs.org/smallterrain'
* url : '//cesiumjs.org/stk-terrain/world'
* });
* var positions = [
* Cesium.Cartographic.fromDegrees(86.925145, 27.988257),
Expand Down
11 changes: 4 additions & 7 deletions Source/Shaders/GlobeFS.glsl
Expand Up @@ -134,9 +134,6 @@ void main()
#if defined(SHOW_REFLECTIVE_OCEAN) || defined(ENABLE_DAYNIGHT_SHADING)
vec3 normalMC = normalize(czm_geodeticSurfaceNormal(v_positionMC, vec3(0.0), vec3(1.0))); // normalized surface normal in model coordinates
vec3 normalEC = normalize(czm_normal3D * normalMC); // normalized surface normal in eye coordiantes
#elif defined(ENABLE_VERTEX_LIGHTING)
vec3 normalMC = normalize(v_normalMC); // normalized surface normal in model coordinates
vec3 normalEC = normalize(v_normalEC); // normalized surface normal in eye coordiantes
#endif

#ifdef SHOW_REFLECTIVE_OCEAN
Expand All @@ -160,7 +157,7 @@ void main()
#endif

#ifdef ENABLE_VERTEX_LIGHTING
float diffuseIntensity = clamp(czm_getLambertDiffuse(czm_sunDirectionEC, normalEC) * 0.9 + 0.3, 0.0, 1.0);
float diffuseIntensity = clamp(czm_getLambertDiffuse(czm_sunDirectionEC, normalize(v_normalEC)) * 0.9 + 0.3, 0.0, 1.0);
gl_FragColor = vec4(color.rgb * diffuseIntensity, color.a);
#elif defined(ENABLE_DAYNIGHT_SHADING)
float diffuseIntensity = clamp(czm_getLambertDiffuse(czm_sunDirectionEC, normalEC) * 5.0 + 0.3, 0.0, 1.0);
Expand Down Expand Up @@ -202,7 +199,7 @@ const float oceanFrequencyHighAltitude = 125000.0;
const float oceanAnimationSpeedHighAltitude = 0.008;
const float oceanOneOverAmplitudeHighAltitude = 1.0 / 2.0;

vec4 computeWaterColor(vec3 positionEyeCoordinates, vec2 textureCoordinates, mat3 enuToEye, vec4 imageryColor, float specularMapValue)
vec4 computeWaterColor(vec3 positionEyeCoordinates, vec2 textureCoordinates, mat3 enuToEye, vec4 imageryColor, float maskValue)
{
vec3 positionToEyeEC = -positionEyeCoordinates;
float positionToEyeECLength = length(positionToEyeEC);
Expand Down Expand Up @@ -244,7 +241,7 @@ vec4 computeWaterColor(vec3 positionEyeCoordinates, vec2 textureCoordinates, mat
const vec3 waveHighlightColor = vec3(0.3, 0.45, 0.6);

// Use diffuse light to highlight the waves
float diffuseIntensity = czm_getLambertDiffuse(czm_sunDirectionEC, normalEC);
float diffuseIntensity = czm_getLambertDiffuse(czm_sunDirectionEC, normalEC) * maskValue;
vec3 diffuseHighlight = waveHighlightColor * diffuseIntensity;

#ifdef SHOW_OCEAN_WAVES
Expand All @@ -258,7 +255,7 @@ vec4 computeWaterColor(vec3 positionEyeCoordinates, vec2 textureCoordinates, mat

// Add specular highlights in 3D, and in all modes when zoomed in.
float specularIntensity = czm_getSpecular(czm_sunDirectionEC, normalizedpositionToEyeEC, normalEC, 10.0) + 0.25 * czm_getSpecular(czm_moonDirectionEC, normalizedpositionToEyeEC, normalEC, 10.0);
float surfaceReflectance = mix(0.0, mix(u_zoomedOutOceanSpecularIntensity, oceanSpecularIntensity, waveIntensity), specularMapValue);
float surfaceReflectance = mix(0.0, mix(u_zoomedOutOceanSpecularIntensity, oceanSpecularIntensity, waveIntensity), maskValue);
float specular = specularIntensity * surfaceReflectance;

return vec4(imageryColor.rgb + diffuseHighlight + nonDiffuseHighlight + specular, imageryColor.a);
Expand Down

0 comments on commit a877a15

Please sign in to comment.