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

Fix disappearing terrain and sky #3032

Merged
merged 11 commits into from
Sep 16, 2015
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Change Log
* Fixed an issue with drill picking at low frame rates that would cause a crash. [#3010](https://github.com/AnalyticalGraphicsInc/cesium/pull/3010)
* Fixed a bug that prevented `setView` from working across all scene modes.
* Fixed a bug that caused `camera.positionWC` to occasionally return the incorrect value.
* Fixed issues causing the terrain and sky to disappear when the camera is near the surface. [#2415](https://github.com/AnalyticalGraphicsInc/cesium/issues/2415) and [#2271](https://github.com/AnalyticalGraphicsInc/cesium/issues/2271)

### 1.13 - 2015-09-01

Expand Down
5 changes: 5 additions & 0 deletions Source/Core/EllipsoidalOccluder.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ define([
* occluder.isScaledSpacePointVisible(scaledSpacePoint); //returns true
*/
EllipsoidalOccluder.prototype.isScaledSpacePointVisible = function(occludeeScaledSpacePosition) {
// Disable occlusion culling when the viewer is under the ellipsoid to avoid false occulsion.
if (this._distanceToLimbInScaledSpaceSquared < 0.0) {
return true;
}

// See http://cesiumjs.org/2013/04/25/Horizon-culling/
var cv = this._cameraPositionInScaledSpace;
var vhMagnitudeSquared = this._distanceToLimbInScaledSpaceSquared;
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/ScreenSpaceCameraController.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ define([
* @type {Number}
* @default 20.0
*/
this.minimumZoomDistance = 20.0;
this.minimumZoomDistance = 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.

Mention this in CHANGES.md.

/**
* The maximum magnitude, in meters, of the camera position when zooming. Defaults to positive infinity.
* @type {Number}
Expand Down
35 changes: 32 additions & 3 deletions Source/Shaders/SkyAtmosphereFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
const float g = -0.95;
const float g2 = g * g;

uniform float fCameraHeight;
uniform float fInnerRadius;

varying vec3 v_rayleighColor;
varying vec3 v_mieColor;
varying vec3 v_toCamera;
Expand All @@ -49,9 +52,35 @@ void main (void)
vec3 direction = normalize(v_positionEC);
czm_ray ray = czm_ray(vec3(0.0), direction);

czm_raySegment intersection = czm_rayEllipsoidIntersectionInterval(ray, ellipsoid);
if (!czm_isEmpty(intersection)) {
discard;
if (fCameraHeight > fInnerRadius) {
czm_raySegment intersection = czm_rayEllipsoidIntersectionInterval(ray, ellipsoid);
if (!czm_isEmpty(intersection)) {
discard;
}
} else {
// The ellipsoid test above will discard fragments when the ray origin is
// inside the ellipsoid.
vec3 radii = ellipsoid.radii;
float maxRadius = max(radii.x, max(radii.y, radii.z));
vec3 ellipsoidCenter = czm_modelView[3].xyz;

float t1 = -1.0;
float t2 = -1.0;

float b = -2.0 * dot(direction, ellipsoidCenter);
float c = dot(ellipsoidCenter, ellipsoidCenter) - maxRadius * maxRadius;

float discriminant = b * b - 4.0 * c;
if (discriminant >= 0.0) {
t1 = (-b - sqrt(discriminant)) * 0.5;
t2 = (-b + sqrt(discriminant)) * 0.5;
}

if (t1 < 0.0 && t2 < 0.0) {
// The ray through the fragment intersected the sphere approximating
// the ellipsoid behind the ray origin.
discard;
}
}

// Extra normalize added for Android
Expand Down