From dc4aaf3841c3926ae3766e7274f5da7dd0f48f95 Mon Sep 17 00:00:00 2001 From: Kushan Joshi <0o3ko0@gmail.com> Date: Wed, 27 Jan 2016 12:58:09 +0530 Subject: [PATCH] Ability to change atmosphere color Issue: #3439 Change the atmoshphere color --- Source/Scene/SkyAtmosphere.js | 30 ++++++++++++++++++++--------- Source/Shaders/SkyAtmosphereVS.glsl | 21 ++++++++++---------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/Source/Scene/SkyAtmosphere.js b/Source/Scene/SkyAtmosphere.js index 7a37054f9f13..a2514ca23a9f 100644 --- a/Source/Scene/SkyAtmosphere.js +++ b/Source/Scene/SkyAtmosphere.js @@ -1,6 +1,7 @@ /*global define*/ define([ '../Core/Cartesian3', + '../Core/Color', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', @@ -22,6 +23,7 @@ define([ './SceneMode' ], function( Cartesian3, + Color, defaultValue, defined, defineProperties, @@ -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. @@ -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; @@ -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; } }; } @@ -239,7 +251,7 @@ define([ * * @example * skyAtmosphere = skyAtmosphere && skyAtmosphere.destroy(); - * + * * @see SkyAtmosphere#isDestroyed */ SkyAtmosphere.prototype.destroy = function() { diff --git a/Source/Shaders/SkyAtmosphereVS.glsl b/Source/Shaders/SkyAtmosphereVS.glsl index 96bd167356a7..506bf6122036 100644 --- a/Source/Shaders/SkyAtmosphereVS.glsl +++ b/Source/Shaders/SkyAtmosphereVS.glsl @@ -2,11 +2,11 @@ * @license * Copyright (c) 2000-2005, Sean O'Neil (s_p_oneil@hotmail.com) * 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, @@ -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 @@ -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; @@ -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; @@ -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; @@ -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);