Skip to content

Commit

Permalink
Ability to change atmosphere color
Browse files Browse the repository at this point in the history
    Issue: CesiumGS#3439

    Change the atmoshphere color
  • Loading branch information
kepta committed Jan 27, 2016
1 parent f503c1a commit c1579a5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 21 deletions.
44 changes: 34 additions & 10 deletions Source/Scene/SkyAtmosphere.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*global define*/
define([
'../Core/Cartesian3',
'../Core/Color',
'../Core/defaultValue',
'../Core/defined',
'../Core/defineProperties',
Expand All @@ -22,6 +23,7 @@ define([
'./SceneMode'
], function(
Cartesian3,
Color,
defaultValue,
defined,
defineProperties,
Expand Down Expand Up @@ -54,15 +56,17 @@ define([
* @alias SkyAtmosphere
* @constructor
*
* @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid that the atmosphere is drawn around.
* @param {Object} [options] Object with the following properties:
* @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid that the atmosphere is drawn around.
* @param {Color} [options.color=Color(1.0, 1.0, 1.0, 1.0)] The color of atmosphere.
*
* @example
* scene.skyAtmosphere = new Cesium.SkyAtmosphere();
*
* @see Scene.skyAtmosphere
*/
function SkyAtmosphere(ellipsoid) {
ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);
function SkyAtmosphere(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);

/**
* Determines if the atmosphere is shown.
Expand All @@ -71,18 +75,17 @@ define([
* @default true
*/
this.show = true;

this._ellipsoid = ellipsoid;
this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);
this._color = defaultValue(options.color, new Color());
this._command = new DrawCommand({
owner : this
});
this._spSkyFromSpace = undefined;
this._spSkyFromAtmosphere = undefined;

this._fCameraHeight = undefined;
this._fCameraHeight2 = undefined;
this._outerRadius = Cartesian3.maximumComponent(Cartesian3.multiplyByScalar(ellipsoid.radii, 1.025, new Cartesian3()));
var innerRadius = ellipsoid.maximumRadius;
this._outerRadius = Cartesian3.maximumComponent(Cartesian3.multiplyByScalar(this._ellipsoid.radii, 1.025, new Cartesian3()));
var innerRadius = this._ellipsoid.maximumRadius;
var rayleighScaleDepth = 0.25;

var that = this;
Expand Down Expand Up @@ -111,6 +114,15 @@ define([
},
fScaleOverScaleDepth : function() {
return (1.0 / (that._outerRadius - innerRadius)) / rayleighScaleDepth;
},
fRedColor : function() {
return that._color.red;
},
fGreenColor : function() {
return that._color.green;
},
fBlueColor : function() {
return that._color.blue;
}
};
}
Expand All @@ -127,7 +139,19 @@ define([
get : function() {
return this._ellipsoid;
}
}
},
/**
* Gets the color of the atmosphere.
* @memberof SkyAtmosphere.prototype
*
* @type {Color}
* @readonly
*/
color : {
get : function() {
return this._color;
}
}
});

/**
Expand Down Expand Up @@ -239,7 +263,7 @@ define([
*
* @example
* skyAtmosphere = skyAtmosphere && skyAtmosphere.destroy();
*
*
* @see SkyAtmosphere#isDestroyed
*/
SkyAtmosphere.prototype.destroy = function() {
Expand Down
21 changes: 11 additions & 10 deletions Source/Shaders/SkyAtmosphereVS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* @license
* Copyright (c) 2000-2005, Sean O'Neil ([email protected])
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
Expand All @@ -15,7 +15,7 @@
* * Neither the name of the project nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Expand All @@ -29,10 +29,10 @@
*
* Modifications made by Analytical Graphics, Inc.
*/

// Code: http://sponeil.net/
// GPU Gems 2 Article: http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter16.html

attribute vec4 position;

uniform float fCameraHeight;
Expand All @@ -43,6 +43,9 @@ uniform float fInnerRadius; // The inner (planetary) radius
uniform float fScale; // 1 / (fOuterRadius - fInnerRadius)
uniform float fScaleDepth; // The scale depth (i.e. the altitude at which the atmosphere's average density is found)
uniform float fScaleOverScaleDepth; // fScale / fScaleDepth
uniform float fRedColor; // The atmosphere color's red component
uniform float fGreenColor; // The atmosphere color's green component
uniform float fBlueColor; // The atmosphere color's blue component

const float Kr = 0.0025;
const float fKr4PI = Kr * 4.0 * czm_pi;
Expand All @@ -51,12 +54,9 @@ const float fKm4PI = Km * 4.0 * czm_pi;
const float ESun = 15.0;
const float fKmESun = Km * ESun;
const float fKrESun = Kr * ESun;
const vec3 v3InvWavelength = vec3(
5.60204474633241, // Red = 1.0 / Math.pow(0.650, 4.0)
9.473284437923038, // Green = 1.0 / Math.pow(0.570, 4.0)
19.643802610477206); // Blue = 1.0 / Math.pow(0.475, 4.0)

const float rayleighScaleDepth = 0.25;

const int nSamples = 2;
const float fSamples = 2.0;

Expand Down Expand Up @@ -105,6 +105,7 @@ void main(void)
float fScaledLength = fSampleLength * fScale;
vec3 v3SampleRay = v3Ray * fSampleLength;
vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5;
vec3 v3InvWavelength = vec3(fRedColor / pow(0.650, 4.0), fGreenColor / pow(0.570, 4.0), fBlueColor / pow(0.475, 4.0));

// Now loop through the sample rays
vec3 v3FrontColor = vec3(0.0, 0.0, 0.0);
Expand Down
9 changes: 8 additions & 1 deletion Specs/Scene/SkyAtmosphereSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
defineSuite([
'Scene/SkyAtmosphere',
'Core/Cartesian3',
'Core/Color',
'Core/Ellipsoid',
'Renderer/ClearCommand',
'Scene/SceneMode',
Expand All @@ -11,6 +12,7 @@ defineSuite([
], function(
SkyAtmosphere,
Cartesian3,
Color,
Ellipsoid,
ClearCommand,
SceneMode,
Expand Down Expand Up @@ -130,10 +132,15 @@ defineSuite([
});

it('gets ellipsoid', function() {
var s = new SkyAtmosphere(Ellipsoid.UNIT_SPHERE);
var s = new SkyAtmosphere({ellipsoid: Ellipsoid.UNIT_SPHERE});
expect(s.ellipsoid).toEqual(Ellipsoid.UNIT_SPHERE);
});

it('gets color', function() {
var s = new SkyAtmosphere({color: new Color(10,0,0)});
expect(s.color).toEqual(new Color(10,0,0));
});

it('isDestroyed', function() {
var s = new SkyAtmosphere();
expect(s.isDestroyed()).toEqual(false);
Expand Down

0 comments on commit c1579a5

Please sign in to comment.