Skip to content

Commit

Permalink
Merge pull request #3032 from AnalyticalGraphicsInc/sky-bug
Browse files Browse the repository at this point in the history
Fix disappearing terrain and sky
  • Loading branch information
pjcozzi committed Sep 16, 2015
2 parents 18a80ae + 174ff31 commit 0836231
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Change Log
* 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.
* Added a workaround for Chrome 45, where the first character in a label with a small font size would not appear. [#3011](https://github.com/AnalyticalGraphicsInc/cesium/pull/3011)
* 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)
* Changed the `ScreenSpaceCameraController.minimumZoomDistance` default from `20.0` to `1.0`.

### 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;
/**
* 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
10 changes: 5 additions & 5 deletions Specs/Scene/ScreenSpaceCameraControllerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ defineSuite([
moveMouse(MouseButtons.RIGHT, startPosition, endPosition);
updateController();
expect(position.x).toEqual(camera.position.x);
expect(position.y).toBeLessThan(camera.position.y);
expect(position.y).toEqual(camera.position.y);
expect(position.z).toEqual(camera.position.z);
expect(frustumDiff).toBeGreaterThan(camera.frustum.right - camera.frustum.left);
});
Expand Down Expand Up @@ -364,7 +364,7 @@ defineSuite([
moveMouse(MouseButtons.RIGHT, startPosition, endPosition);
updateController();
expect(position.x).toEqual(camera.position.x);
expect(position.y).toBeLessThan(camera.position.y);
expect(position.y).toEqual(camera.position.y);
expect(position.z).toEqual(camera.position.z);
expect(frustumDiff).toBeGreaterThan(camera.frustum.right - camera.frustum.left);
});
Expand Down Expand Up @@ -1051,7 +1051,7 @@ defineSuite([
updateController();

camera.setView({
position : Cartesian3.fromDegrees(-72.0, 40.0, 1.0)
position : Cartesian3.fromDegrees(-72.0, 40.0, -10.0)
});

updateController();
Expand All @@ -1067,7 +1067,7 @@ defineSuite([
updateController();

camera.setView({
position : Cartesian3.fromDegrees(-72.0, 40.0, 1.0)
position : Cartesian3.fromDegrees(-72.0, 40.0, -10.0)
});

updateController();
Expand Down Expand Up @@ -1098,7 +1098,7 @@ defineSuite([

updateController();

expect(camera.positionWC.x).toBeGreaterThanOrEqualTo(controller.minimumZoomDistance);
expect(camera.positionWC.x).toEqualEpsilon(controller.minimumZoomDistance, CesiumMath.EPSILON8);
});

it('is destroyed', function() {
Expand Down

0 comments on commit 0836231

Please sign in to comment.