diff --git a/CHANGES.md b/CHANGES.md index b87b98b956ca..8983a1332f8b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ Change Log * Added `customTags` property to the UrlTemplateImageryProvider to allow custom keywords in the template URL. [#5696](https://github.com/AnalyticalGraphicsInc/cesium/pull/5696) * Improved CZML Reference Properties example [#5754](https://github.com/AnalyticalGraphicsInc/cesium/pull/5754) * Fixed bug with placemarks in imported KML: placemarks with no specified icon would be displayed with default icon. [#5819](https://github.com/AnalyticalGraphicsInc/cesium/issues/5819) +* Fixed bright fog when terrain lighting is enabled and added `Fog.minimumBrightness` to affect how bright the fog will be when in complete darkness. [#5934](https://github.com/AnalyticalGraphicsInc/cesium/pull/5934) ### 1.38 - 2017-10-02 diff --git a/Source/Scene/Fog.js b/Source/Scene/Fog.js index b06a34dbe147..e771a04a9a03 100644 --- a/Source/Scene/Fog.js +++ b/Source/Scene/Fog.js @@ -24,7 +24,6 @@ define([ * @default true */ this.enabled = true; - /** * A scalar that determines the density of the fog. Terrain that is in full fog are culled. * The density of the fog increases as this number approaches 1.0 and becomes less dense as it approaches zero. @@ -44,6 +43,13 @@ define([ * @default 2.0 */ this.screenSpaceErrorFactor = 2.0; + /** + * The minimum brightness of the fog color from lighting. A value of 0.0 can cause the fog to be completely black. A value of 1.0 will not affect + * the brightness at all. + * @type {Number} + * @default 0.1 + */ + this.minimumBrightness = 0.1; } // These values were found by sampling the density at certain views and finding at what point culled tiles impacted the view at the horizon. @@ -135,6 +141,7 @@ define([ frameState.fog.density = density; frameState.fog.sse = this.screenSpaceErrorFactor; + frameState.fog.minimumBrightness = this.minimumBrightness; }; return Fog; diff --git a/Source/Scene/FrameState.js b/Source/Scene/FrameState.js index 948a75d78637..64716d40440d 100644 --- a/Source/Scene/FrameState.js +++ b/Source/Scene/FrameState.js @@ -208,7 +208,14 @@ define([ * @type {Number} * @default undefined */ - sse : undefined + sse : undefined, + /** + * The minimum brightness of terrain with fog applied. + * + * @type {Number} + * @default undefined + */ + minimumBrightness : undefined }; /** diff --git a/Source/Scene/GlobeSurfaceTileProvider.js b/Source/Scene/GlobeSurfaceTileProvider.js index 801376f39439..2dc19b73ac65 100644 --- a/Source/Scene/GlobeSurfaceTileProvider.js +++ b/Source/Scene/GlobeSurfaceTileProvider.js @@ -849,6 +849,9 @@ define([ u_dayTextureSplit : function() { return this.properties.dayTextureSplit; }, + u_minimumBrightness : function() { + return frameState.fog.minimumBrightness; + }, // make a separate object so that changes to the properties are seen on // derived commands that combine another uniform map with this one. diff --git a/Source/Shaders/GlobeFS.glsl b/Source/Shaders/GlobeFS.glsl index 34f8bc02c4ca..998daae62d15 100644 --- a/Source/Shaders/GlobeFS.glsl +++ b/Source/Shaders/GlobeFS.glsl @@ -52,6 +52,10 @@ uniform sampler2D u_oceanNormalMap; uniform vec2 u_lightingFadeDistance; #endif +#if defined(FOG) && (defined(ENABLE_VERTEX_LIGHTING) || defined(ENABLE_DAYNIGHT_SHADING)) +uniform float u_minimumBrightness; +#endif + varying vec3 v_positionMC; varying vec3 v_positionEC; varying vec3 v_textureCoordinates; @@ -195,12 +199,16 @@ void main() vec4 finalColor = color; #endif - #ifdef FOG const float fExposure = 2.0; vec3 fogColor = v_mieColor + finalColor.rgb * v_rayleighColor; fogColor = vec3(1.0) - exp(-fExposure * fogColor); +#if defined(ENABLE_VERTEX_LIGHTING) || defined(ENABLE_DAYNIGHT_SHADING) + float darken = clamp(dot(normalize(czm_viewerPositionWC), normalize(czm_sunPositionWC)), u_minimumBrightness, 1.0); + fogColor *= darken; +#endif + gl_FragColor = vec4(czm_fog(v_distance, finalColor.rgb, fogColor), finalColor.a); #else gl_FragColor = finalColor;