Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Darken fog when terrain lighting is enabled. #5934

Merged
merged 4 commits into from
Oct 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion Source/Scene/Fog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -135,6 +141,7 @@ define([

frameState.fog.density = density;
frameState.fog.sse = this.screenSpaceErrorFactor;
frameState.fog.minimumBrightness = this.minimumBrightness;
};

return Fog;
Expand Down
9 changes: 8 additions & 1 deletion Source/Scene/FrameState.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

/**
Expand Down
3 changes: 3 additions & 0 deletions Source/Scene/GlobeSurfaceTileProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 9 additions & 1 deletion Source/Shaders/GlobeFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down