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

Darken fog when terrain lighting is enabled. #5934

merged 4 commits into from
Oct 27, 2017

Conversation

bagnell
Copy link
Contributor

@bagnell bagnell commented Oct 25, 2017

Darkens the fog when viewer.scene.globe.enableLighting = true. Here is a Sandcastle example for testing:

var viewer = new Cesium.Viewer('cesiumContainer');

viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
    url : 'https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles',
    requestVertexNormals : true
});

viewer.scene.globe.enableLighting = true;

var camera = viewer.scene.camera;
camera.position = new Cesium.Cartesian3(305111.15252842277, 5635080.182335396, 2980739.393793938);
camera.direction = new Cesium.Cartesian3(-0.8922165975346716, 0.21339304915721466, -0.39801124312642266);
camera.up = new Cesium.Cartesian3(0.012013291290700188, 0.8922235826513757, 0.4514341141219929);
camera.right = Cesium.Cartesian3.cross(camera.direction, camera.up, new Cesium.Cartesian3());
viewer.clock.currentTime = new Cesium.JulianDate(2458052, 45720.28193048129);

CC @emackey

@cesium-concierge
Copy link

@bagnell, thanks for the pull request! Maintainers, we have a signed CLA from @bagnell, so you can review this at any time.

I noticed that CHANGES.md has not been updated. If this change updates the public API in any way, fixes a bug, or makes any non-trivial update, please add a bullet point to CHANGES.md and comment on this pull request so we know it was updated. For more info, see the Pull Request Guidelines.


I am a bot who helps you make Cesium awesome! Thanks again.

@bagnell
Copy link
Contributor Author

bagnell commented Oct 25, 2017

dark_fog

#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)), 0.1, 1.0);
fogColor = mix(vec3(0.0), fogColor, darken);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and where ever else just

fogColor *= darken;

?

Copy link
Contributor

@emackey emackey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an awesome change, much needed! I agree with Cozzi's optimization and added an additional suggestion below. I use enableLighting in a number of apps that will see automatic benefit from this.

#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)), 0.1, 1.0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.1 is a magic number that may not be ideal for all cases. Is it possible to add a user configuration setting for this? It won't need to change at runtime, I imagine any app that wanted to tweak it would just set their preferred value prior to initializing a viewer. But I think app authors will want control over this minimum terrain brightness value.

@bagnell
Copy link
Contributor Author

bagnell commented Oct 26, 2017

@pjcozzi @emackey This is ready for another look.

@pjcozzi
Copy link
Contributor

pjcozzi commented Oct 26, 2017

Thanks @bagnell! @emackey please merge when ready.

Copy link
Contributor

@emackey emackey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Thanks for viewer.scene.fog.minimumBrightness.

/ping @abwood

@emackey emackey merged commit 0526709 into master Oct 27, 2017
@emackey emackey deleted the dark-fog branch October 27, 2017 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants