-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Add ground atmosphere #6877
Merged
Merged
Add ground atmosphere #6877
Changes from 23 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
b3aeee9
Add back ground atmosphere from space.
bagnell c052aa0
Fix fog.
bagnell 381c0b2
Merge branch 'master' into atmosphere
bagnell 75e14f7
Add option to enable disable ground atmosphere.
bagnell 139a529
Fix sky atmosphere.
bagnell edc42fa
Revert sky atmosphere changes.
bagnell e642085
Remove unused code in sky atmosphere shader.
bagnell 5f11c50
Fix night atmosphere color.
bagnell d3a9950
Use atmosphere with correct sun lighting.
bagnell bb402de
Make night fade in/out distances a uniform.
bagnell 2e2b825
Update doc.
bagnell a708860
Fix 2D/CV.
bagnell 31de234
Update CHANGES.md.
bagnell f6bf14c
Merge branch 'master' into atmosphere
bagnell dbccbd8
Merge branch 'master' into atmosphere
bagnell a7234d7
Merge branch 'master' into atmosphere
bagnell 9d31730
Make ground atmosphere per-fragment for a smoother transition from ni…
bagnell 2279eac
Only use per-fragment ground atmosphere when the camera is greater th…
bagnell f6a1522
Merge branch 'master' into atmosphere
bagnell 1e6aafe
Merge branch 'master' into atmosphere
bagnell 681fb0f
Merge branch 'master' into atmosphere
bagnell 2225851
Update CHANGES.md after merge.
bagnell 8da546f
Merge branch 'master' into atmosphere
bagnell fc3e0c7
Merge branch 'master' into atmosphere
bagnell 4426bd2
Clean up globe shader parameters.
bagnell bfd11bd
More aggressive fade distances. Have enable lighting off by default.
bagnell 7180803
Change water specular intensity when ground atmosphere is enabled.
bagnell 80e591d
Fix day/night terrain shading.
bagnell e1005fe
Tweak params
lilleyse 61cf20e
Merge branch 'master' into atmosphere
bagnell 85b08e5
Fade water effect when zooming.
bagnell 14e3114
Fix for when atmosphere is disabled.
bagnell 3636dbb
Add atmosphere lighting example.
bagnell 5e36c99
More tweaks
lilleyse a53cd15
Reset sliders and text box when the reset button is clicked in the at…
bagnell 3fc5808
Update from review.
bagnell fe410fa
Remove input ids.
bagnell a623027
Fix fog.
bagnell b75d1cf
Update docs and changes a bit
lilleyse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
//#define SHOW_TILE_BOUNDARIES | ||
uniform vec4 u_initialColor; | ||
|
||
#if TEXTURE_UNITS > 0 | ||
|
@@ -47,17 +46,21 @@ uniform float u_zoomedOutOceanSpecularIntensity; | |
uniform sampler2D u_oceanNormalMap; | ||
#endif | ||
|
||
#ifdef ENABLE_DAYNIGHT_SHADING | ||
#if defined(ENABLE_DAYNIGHT_SHADING) || defined(GROUND_ATMOSPHERE) | ||
uniform vec2 u_lightingFadeDistance; | ||
#endif | ||
|
||
#ifdef GROUND_ATMOSPHERE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, maybe not. |
||
uniform vec2 u_nightFadeDistance; | ||
#endif | ||
|
||
#ifdef ENABLE_CLIPPING_PLANES | ||
uniform sampler2D u_clippingPlanes; | ||
uniform mat4 u_clippingPlanesMatrix; | ||
uniform vec4 u_clippingPlanesEdgeStyle; | ||
#endif | ||
|
||
#if defined(FOG) && (defined(ENABLE_VERTEX_LIGHTING) || defined(ENABLE_DAYNIGHT_SHADING)) | ||
#if defined(FOG) && (defined(ENABLE_VERTEX_LIGHTING) || defined(ENABLE_DAYNIGHT_SHADING)) || defined(GROUND_ATMOSPHERE) | ||
uniform float u_minimumBrightness; | ||
#endif | ||
|
||
|
@@ -72,8 +75,13 @@ varying float v_height; | |
varying float v_slope; | ||
#endif | ||
|
||
#ifdef FOG | ||
#if defined(FOG) || defined(GROUND_ATMOSPHERE) | ||
varying float v_distance; | ||
varying vec3 v_fogRayleighColor; | ||
varying vec3 v_fogMieColor; | ||
#endif | ||
|
||
#ifdef GROUND_ATMOSPHERE | ||
varying vec3 v_rayleighColor; | ||
varying vec3 v_mieColor; | ||
#endif | ||
|
@@ -209,11 +217,7 @@ void main() | |
color.xyz = mix(color.xyz, material.diffuse, material.alpha); | ||
#endif | ||
|
||
#ifdef ENABLE_VERTEX_LIGHTING | ||
float diffuseIntensity = clamp(czm_getLambertDiffuse(czm_sunDirectionEC, normalize(v_normalEC)) * 0.9 + 0.3, 0.0, 1.0); | ||
vec4 finalColor = vec4(color.rgb * diffuseIntensity, color.a); | ||
#elif defined(ENABLE_DAYNIGHT_SHADING) | ||
float diffuseIntensity = clamp(czm_getLambertDiffuse(czm_sunDirectionEC, normalEC) * 5.0 + 0.3, 0.0, 1.0); | ||
#if defined(ENABLE_DAYNIGHT_SHADING) || defined(GROUND_ATMOSPHERE) | ||
float cameraDist; | ||
if (czm_sceneMode == czm_sceneMode2D) | ||
{ | ||
|
@@ -235,8 +239,15 @@ void main() | |
fadeOutDist -= maxRadii; | ||
fadeInDist -= maxRadii; | ||
} | ||
float t = clamp((cameraDist - fadeOutDist) / (fadeInDist - fadeOutDist), 0.0, 1.0); | ||
diffuseIntensity = mix(1.0, diffuseIntensity, t); | ||
float fade = clamp((cameraDist - fadeOutDist) / (fadeInDist - fadeOutDist), 0.0, 1.0); | ||
#endif | ||
|
||
#if defined(ENABLE_VERTEX_LIGHTING) && !defined(GROUND_ATMOSPHERE) | ||
float diffuseIntensity = clamp(czm_getLambertDiffuse(czm_sunDirectionEC, normalize(v_normalEC)) * 0.9 + 0.3, 0.0, 1.0); | ||
vec4 finalColor = vec4(color.rgb * diffuseIntensity, color.a); | ||
#elif defined(ENABLE_DAYNIGHT_SHADING) && !defined(GROUND_ATMOSPHERE) | ||
float diffuseIntensity = clamp(czm_getLambertDiffuse(czm_sunDirectionEC, normalEC) * 5.0 + 0.3, 0.0, 1.0); | ||
diffuseIntensity = mix(1.0, diffuseIntensity, fade); | ||
vec4 finalColor = vec4(color.rgb * diffuseIntensity, color.a); | ||
#else | ||
vec4 finalColor = color; | ||
|
@@ -253,20 +264,60 @@ void main() | |
} | ||
#endif | ||
|
||
#ifdef FOG | ||
#if defined(FOG) || defined(GROUND_ATMOSPHERE) | ||
const float fExposure = 2.0; | ||
vec3 fogColor = v_mieColor + finalColor.rgb * v_rayleighColor; | ||
vec3 fogColor = v_fogMieColor + finalColor.rgb * v_fogRayleighColor; | ||
fogColor = vec3(1.0) - exp(-fExposure * fogColor); | ||
#endif | ||
|
||
#if defined(ENABLE_VERTEX_LIGHTING) || defined(ENABLE_DAYNIGHT_SHADING) | ||
#ifdef FOG | ||
#if defined(ENABLE_VERTEX_LIGHTING) || defined(ENABLE_DAYNIGHT_SHADING) || defined(GROUND_ATMOSPHERE) | ||
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); | ||
finalColor = vec4(czm_fog(v_distance, finalColor.rgb, fogColor), finalColor.a); | ||
#endif | ||
|
||
#ifdef GROUND_ATMOSPHERE | ||
if (czm_sceneMode != czm_sceneMode3D) | ||
{ | ||
gl_FragColor = finalColor; | ||
return; | ||
} | ||
|
||
#ifdef PER_FRAGMENT_GROUND_ATMOSPHERE | ||
czm_ellipsoid ellipsoid = czm_getWgs84EllipsoidEC(); | ||
|
||
float mpp = czm_metersPerPixel(vec4(0.0, 0.0, -czm_currentFrustum.x, 1.0)); | ||
vec2 xy = gl_FragCoord.xy / czm_viewport.zw * 2.0 - vec2(1.0); | ||
xy *= czm_viewport.zw * mpp * 0.5; | ||
|
||
vec3 direction = normalize(vec3(xy, -czm_currentFrustum.x)); | ||
czm_ray ray = czm_ray(vec3(0.0), direction); | ||
|
||
czm_raySegment intersection = czm_rayEllipsoidIntersectionInterval(ray, ellipsoid); | ||
|
||
vec3 ellipsoidPosition = czm_pointAlongRay(ray, intersection.start); | ||
ellipsoidPosition = (czm_inverseView * vec4(ellipsoidPosition, 1.0)).xyz; | ||
AtmosphereColor atmosColor = computeGroundAtmosphereFromSpace(ellipsoidPosition, true); | ||
|
||
vec3 groundAtmosphereColor = atmosColor.mie + finalColor.rgb * atmosColor.rayleigh; | ||
groundAtmosphereColor = vec3(1.0) - exp(-fExposure * groundAtmosphereColor); | ||
|
||
fadeInDist = u_nightFadeDistance.x; | ||
fadeOutDist = u_nightFadeDistance.y; | ||
|
||
float sunlitAtmosphereIntensity = clamp((cameraDist - fadeOutDist) / (fadeInDist - fadeOutDist), 0.0, 1.0); | ||
groundAtmosphereColor = mix(groundAtmosphereColor, fogColor, sunlitAtmosphereIntensity); | ||
#else | ||
gl_FragColor = finalColor; | ||
vec3 groundAtmosphereColor = fogColor; | ||
#endif | ||
|
||
finalColor = vec4(mix(finalColor.rgb, groundAtmosphereColor, fade), finalColor.a); | ||
#endif | ||
|
||
gl_FragColor = finalColor; | ||
} | ||
|
||
#ifdef SHOW_REFLECTIVE_OCEAN | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, but batch this with
u_lightingFadeDistance
?