Skip to content

Commit

Permalink
Merge branch 'lighting' into terrainAndOcean
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcozzi committed Nov 27, 2012
2 parents 8f8929d + c85d043 commit 8669122
Show file tree
Hide file tree
Showing 18 changed files with 416 additions and 182 deletions.
3 changes: 0 additions & 3 deletions Apps/Sandcastle/gallery/Custom Rendering.html
Expand Up @@ -388,23 +388,20 @@
sceneMenu.addChild(new MenuItem({
label: '2D',
onClick: function() {
centralBody.showSkyAtmosphere = false;
transitioner.morphTo2D();
}
}));

sceneMenu.addChild(new MenuItem({
label: 'Columbus View',
onClick: function() {
centralBody.showSkyAtmosphere = false;
transitioner.morphToColumbusView();
}
}));

sceneMenu.addChild(new MenuItem({
label: '3D',
onClick: function() {
centralBody.showSkyAtmosphere = true;
transitioner.morphTo3D();
}
}));
Expand Down
6 changes: 1 addition & 5 deletions Apps/Sandcastle/gallery/Hello World.html
Expand Up @@ -77,9 +77,8 @@
var cb = new Cesium.CentralBody(ellipsoid);
cb.getImageryLayers().addImageryProvider(bing);

cb.showSkyAtmosphere = true;
primitives.setCentralBody(cb);

scene.skyAtmosphere = new Cesium.SkyAtmosphere();
scene.getCamera().getControllers().addCentralBody();

var transitioner = new Cesium.SceneTransitioner(scene, ellipsoid);
Expand Down Expand Up @@ -120,15 +119,12 @@
function keydownHandler(e) {
switch (e.keyCode) {
case '3'.charCodeAt(0): // '3' -> 3D globe
cb.showSkyAtmosphere = true;
transitioner.morphTo3D();
break;
case '2'.charCodeAt(0): // '2' -> Columbus View
cb.showSkyAtmosphere = false;
transitioner.morphToColumbusView();
break;
case '1'.charCodeAt(0): // '1' -> 2D map
cb.showSkyAtmosphere = false;
transitioner.morphTo2D();
break;
default:
Expand Down
1 change: 0 additions & 1 deletion Apps/Sandcastle/gallery/Map Projections.html
Expand Up @@ -105,7 +105,6 @@
widget.startup();
dom.byId('toolbar').innerHTML = '';

widget.showSkyAtmosphere(false);
var transitioner = new Cesium.SceneTransitioner(widget.scene);
transitioner.to2D();

Expand Down
3 changes: 1 addition & 2 deletions Apps/Sandcastle/gallery/Minimalist.html
Expand Up @@ -60,9 +60,8 @@

var cb = new Cesium.CentralBody(ellipsoid);
cb.getImageryLayers().addImageryProvider(imageryProvider);
cb.showSkyAtmosphere = true;
primitives.setCentralBody(cb);

scene.skyAtmosphere = new Cesium.SkyAtmosphere();
scene.getCamera().getControllers().addCentralBody();

scene.setAnimation(function () {
Expand Down
3 changes: 2 additions & 1 deletion Apps/Sandcastle/gallery/Two Canvases.html
Expand Up @@ -91,7 +91,6 @@
var cb = new Cesium.CentralBody(ellipsoid);
cb.getImageryLayers().addImageryProvider(imageryProvider);

cb.showSkyAtmosphere = (canvas === canvas3D);
primitives.setCentralBody(cb);

scene.getCamera().getControllers().addCentralBody();
Expand All @@ -111,6 +110,8 @@
var scene3D = createScene(canvas3D);
var scene2D = createScene(canvas2D);

scene3D.skyAtmosphere = new Cesium.SkyAtmosphere();

var transitioner = new Cesium.SceneTransitioner(scene2D);
transitioner.to2D();

Expand Down
6 changes: 1 addition & 5 deletions Apps/Sandcastle/gallery/jQuery UI Demo.html
Expand Up @@ -81,9 +81,8 @@
var cb = new Cesium.CentralBody(ellipsoid);
cb.getImageryLayers().addImageryProvider(bing);

cb.showSkyAtmosphere = true;
primitives.setCentralBody(cb);

scene.skyAtmosphere = new Cesium.SkyAtmosphere();
scene.getCamera().frustum.near = 1.0;
scene.getCamera().getControllers().addCentralBody();

Expand Down Expand Up @@ -119,17 +118,14 @@
// 3D is the default view
$('#mode3D').button("option", { icons: { primary: "ui-icon-check" }}
).click(function () {
cb.showSkyAtmosphere = true;
transitioner.morphTo3D();
});

$('#modeColumbus').click(function () {
cb.showSkyAtmosphere = false;
transitioner.morphToColumbusView();
});

$('#mode2D').click(function () {
cb.showSkyAtmosphere = false;
transitioner.morphTo2D();
});

Expand Down
4 changes: 3 additions & 1 deletion CHANGES.md
Expand Up @@ -19,9 +19,11 @@ Beta Releases
* Removed `affectedByLighting` property from `Polygon`, `EllipsoidPrimitive`, `RectangularPyramidSensorVolume`, `CustomSensorVolume`, and `ComplexConicSensorVolume`.
* Removed `DistanceIntervalMaterial`. This was not documented.
* `Matrix2.getElementIndex`, `Matrix3.getElementIndex`, and `Matrix4.getElementIndex` functions have had their parameters swapped and now take row first and column second. This is consistent with other class constants, such as Matrix2.COLUMN1ROW2.
* Replaced `CentralBody.showSkyAtmosphere` with `Scene.skyAtmosphere` and `SkyAtmosphere`. This has no impact for those using the Cesium widget.
* Improved lighting in Columbus view and on polygons, ellipsoids, and sensors.
* Added `Water` material. See the Materials Sandbox example.
* Fixed atmosphere rendering artifacts and improved Columbus view transition.
* Fixed jitter artifacts with billboards and polylines.
* Added `Water` material. See the Materials Sandbox example.
* Added `SkyBox` to draw stars. Added `CesiumWidget.showSkyBox` and `CesiumViewerWidget.showSkyBox`.
* Added new `Matrix4` functions: `Matrix4.multiplyByTranslation`, `multiplyByPoint`, and `Matrix4.fromScale`. Added `Matrix3.fromScale`.
* Added `EncodedCartesian3`, which is used to eliminate jitter when drawing primitives.
Expand Down
136 changes: 4 additions & 132 deletions Source/Scene/CentralBody.js
Expand Up @@ -20,7 +20,6 @@ define([
'../Core/MeshFilters',
'../Core/Occluder',
'../Core/PrimitiveType',
'../Core/RuntimeError',
'../Core/Transforms',
'../Renderer/BufferUsage',
'../Renderer/ClearCommand',
Expand All @@ -41,9 +40,7 @@ define([
'../Shaders/CentralBodyFSPole',
'../Shaders/CentralBodyVS',
'../Shaders/CentralBodyVSDepth',
'../Shaders/CentralBodyVSPole',
'../Shaders/SkyAtmosphereFS',
'../Shaders/SkyAtmosphereVS'
'../Shaders/CentralBodyVSPole'
], function(
combine,
defaultValue,
Expand All @@ -65,7 +62,6 @@ define([
MeshFilters,
Occluder,
PrimitiveType,
RuntimeError,
Transforms,
BufferUsage,
ClearCommand,
Expand All @@ -86,9 +82,7 @@ define([
CentralBodyFSPole,
CentralBodyVS,
CentralBodyVSDepth,
CentralBodyVSPole,
SkyAtmosphereFS,
SkyAtmosphereVS) {
CentralBodyVSPole) {
"use strict";

/**
Expand Down Expand Up @@ -119,13 +113,6 @@ define([
this._rsColor = undefined;
this._rsColorWithoutDepthTest = undefined;

this._spSkyFromSpace = undefined;
this._spSkyFromAtmosphere = undefined;

this._skyCommand = new DrawCommand();
this._skyCommand.primitiveType = PrimitiveType.TRIANGLES;
// this._skyCommand.shaderProgram references sky-from-space or sky-from-atmosphere

this._clearDepthCommand = new ClearCommand();

this._depthCommand = new DrawCommand();
Expand All @@ -137,12 +124,6 @@ define([
this._southPoleCommand = new DrawCommand();
this._southPoleCommand.primitiveType = PrimitiveType.TRIANGLE_FAN;

// this._northPoleCommand.shaderProgram and this.southPoleCommand.shaderProgram reference
// without-atmosphere, ground-from-space, or ground-from-atmosphere
this._spPolesWithoutAtmosphere = undefined;
this._spPolesGroundFromSpace = undefined;
this._spPolesGroundFromAtmosphere = undefined;

this._drawNorthPole = false;
this._drawSouthPole = false;

Expand Down Expand Up @@ -183,14 +164,6 @@ define([
*/
this.show = true;

/**
* Determines if the sky atmosphere will be shown.
*
* @type {Boolean}
* @default false
*/
this.showSkyAtmosphere = false;

/**
* The current morph transition time between 2D/Columbus View and 3D,
* with 0.0 being 2D or Columbus View and 1.0 being 3D.
Expand All @@ -204,44 +177,8 @@ define([
this._mode = SceneMode.SCENE3D;
this._projection = undefined;

this._fCameraHeight = undefined;
this._fCameraHeight2 = undefined;
this._outerRadius = ellipsoid.getRadii().multiplyByScalar(1.025).getMaximumComponent();
var innerRadius = ellipsoid.getMaximumRadius();
var rayleighScaleDepth = 0.25;

var that = this;

this._skyCommand.uniformMap = {
fCameraHeight : function() {
return that._fCameraHeight;
},
fCameraHeight2 : function() {
return that._fCameraHeight2;
},
fOuterRadius : function() {
return that._outerRadius;
},
fOuterRadius2 : function() {
return that._outerRadius * that._outerRadius;
},
fInnerRadius : function() {
return innerRadius;
},
fInnerRadius2 : function() {
return innerRadius * innerRadius;
},
fScale : function() {
return 1.0 / (that._outerRadius - innerRadius);
},
fScaleDepth : function() {
return rayleighScaleDepth;
},
fScaleOverScaleDepth : function() {
return (1.0 / (that._outerRadius - innerRadius)) / rayleighScaleDepth;
}
};

this._drawUniforms = {
u_mode : function() {
return that._mode;
Expand Down Expand Up @@ -516,48 +453,6 @@ define([
return;
}

var vs;
var fs;
var shaderCache = context.getShaderCache();

if (this.showSkyAtmosphere && !this._skyCommand.vertexArray) {
// PERFORMANCE_IDEA: Is 60 the right amount to tessellate? I think scaling the original
// geometry in a vertex is a bad idea; at least, because it introduces a draw call per tile.
var skyMesh = CubeMapEllipsoidTessellator.compute(Ellipsoid.fromCartesian3(this._ellipsoid.getRadii().multiplyByScalar(1.025)), 60);
this._skyCommand.vertexArray = context.createVertexArrayFromMesh({
mesh : skyMesh,
attributeIndices : MeshFilters.createAttributeIndices(skyMesh),
bufferUsage : BufferUsage.STATIC_DRAW
});

vs = '#define SKY_FROM_SPACE\n' +
'#line 0\n' +
SkyAtmosphereVS;

fs = '#line 0\n' +
SkyAtmosphereFS;

this._spSkyFromSpace = shaderCache.getShaderProgram(vs, fs);

vs = '#define SKY_FROM_ATMOSPHERE\n' +
'#line 0\n' +
SkyAtmosphereVS;

this._spSkyFromAtmosphere = shaderCache.getShaderProgram(vs, fs);
this._skyCommand.renderState = context.createRenderState({
cull : {
enabled : true,
face : CullFace.FRONT
},
depthTest : {
enabled : true
},
depthMask : false,
blending : BlendingState.ALPHA_BLEND
});
this._skyCommand.boundingVolume = new BoundingSphere(Cartesian3.ZERO, this._ellipsoid.getMaximumRadius() * 1.025);
}

var mode = frameState.mode;
var projection = frameState.scene2D.projection;
var modeChanged = false;
Expand Down Expand Up @@ -642,6 +537,8 @@ define([
this._depthCommand.vertexArray.getAttribute(0).vertexBuffer.copyFromArrayView(datatype.toTypedArray(depthQuad));
}

var shaderCache = context.getShaderCache();

if (!this._depthCommand.shaderProgram) {
this._depthCommand.shaderProgram = shaderCache.getShaderProgram(
CentralBodyVSDepth,
Expand All @@ -651,13 +548,6 @@ define([
});
}

// Throw exception if there was a problem asynchronously loading an image.
if (this._exception) {
var message = this._exception;
this._exception = undefined;
throw new RuntimeError(message);
}

// Initial compile or re-compile if uber-shader parameters changed
var projectionChanged = this._projection !== projection;

Expand Down Expand Up @@ -719,16 +609,6 @@ define([

var cameraPosition = frameState.camera.getPositionWC();

this._fCameraHeight2 = cameraPosition.magnitudeSquared();
this._fCameraHeight = Math.sqrt(this._fCameraHeight2);

if (this._fCameraHeight > this._outerRadius) {
// Viewer in space
this._skyCommand.shaderProgram = this._spSkyFromSpace;
} else {
this._skyCommand.shaderProgram = this._spSkyFromAtmosphere;
}

this._occluder.setCameraPosition(cameraPosition);

this._fillPoles(context, frameState);
Expand Down Expand Up @@ -774,10 +654,6 @@ define([
if (mode === SceneMode.SCENE3D) {
colorCommandList.push(this._depthCommand);
}

if (this.showSkyAtmosphere) {
colorCommandList.push(this._skyCommand);
}
}

if (pass.pick) {
Expand Down Expand Up @@ -835,10 +711,6 @@ define([
this._northPoleCommand.shaderProgram = this._northPoleCommand.shaderProgram && this._northPoleCommand.shaderProgram.release();
this._southPoleCommand.shaderProgram = this._northPoleCommand.shaderProgram;

this._skyCommand.vertexArray = this._skyCommand.vertexArray && this._skyCommand.vertexArray.destroy();
this._spSkyFromSpace = this._spSkyFromSpace && this._spSkyFromSpace.release();
this._spSkyFromAtmosphere = this._spSkyFromAtmosphere && this._spSkyFromAtmosphere.release();

this._depthCommand.shaderProgram = this._depthCommand.shaderProgram && this._depthCommand.shaderProgram.release();
this._depthCommand.vertexArray = this._depthCommand.vertexArray && this._depthCommand.vertexArray.destroy();

Expand Down

0 comments on commit 8669122

Please sign in to comment.