Skip to content

Commit

Permalink
Ability to change atmosphere color CesiumGS#3439
Browse files Browse the repository at this point in the history
Change the atmoshphere color
  • Loading branch information
kepta committed Jan 27, 2016
1 parent f503c1a commit b4e8939
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
31 changes: 22 additions & 9 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 {Object} [options] Object with the following properties:
* @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid that the atmosphere is drawn around.
* @param {Color} [color=new Cesium.Color(1,1,1)] 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,18 @@ define([
* @default true
*/
this.show = true;

this._ellipsoid = ellipsoid;
this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);
this._color = defaultValue(options.color, new Color());
console.log(this._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 +115,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 @@ -126,7 +139,7 @@ define([
ellipsoid : {
get : function() {
return this._ellipsoid;
}
},
}
});

Expand Down Expand Up @@ -239,7 +252,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 compoenent
uniform float fGreenColor; // The atmosphere color's green compoenent
uniform float fBlueColor; // The atmosphere color's blue compoenent

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

0 comments on commit b4e8939

Please sign in to comment.