Skip to content

Commit

Permalink
Merge pull request #5166 from AnalyticalGraphicsInc/billboard-depth-fail
Browse files Browse the repository at this point in the history
Billboard depth fail
  • Loading branch information
pjcozzi authored Apr 6, 2017
2 parents 0ba0178 + 9b0a846 commit 7cf1df8
Show file tree
Hide file tree
Showing 32 changed files with 631 additions and 93 deletions.
39 changes: 37 additions & 2 deletions Apps/Sandcastle/gallery/Billboards.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@

function sizeBillboardInMeters() {
Sandcastle.declare(sizeBillboardInMeters);

var entity = viewer.entities.add({
position : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
billboard : {
image : '../images/Cesium_Logo_overlay.png',
sizeInMeters : true
}
});

viewer.zoomTo(entity);
}

Expand Down Expand Up @@ -221,6 +221,29 @@
});
}

var terrainProvider;
function disableDepthTest() {
Sandcastle.declare(disableDepthTest);

terrainProvider = viewer.terrainProvider;
viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
url : 'https://assets.agi.com/stk-terrain/world',
requestWaterMask : true,
requestVertexNormals : true
});
viewer.scene.globe.depthTestAgainstTerrain = true;

viewer.entities.add({
position : Cesium.Cartesian3.fromDegrees(-122.1958, 46.1915),
billboard : {
image : '../images/facility.gif',
heightReference : Cesium.HeightReference.CLAMP_TO_GROUND,
disableDepthTestDistance : Number.POSITIVE_INFINITY
}
});
viewer.zoomTo(viewer.entities);
}

Sandcastle.addToolbarMenu([{
text : 'Add billboard',
onselect : function() {
Expand Down Expand Up @@ -275,11 +298,23 @@
addMarkerBillboards();
Sandcastle.highlight(addMarkerBillboards);
}
}, {
text : 'Disable the depth test when clamped to ground',
onselect : function() {
disableDepthTest();
Sandcastle.highlight(disableDepthTest);
}
}]);

Sandcastle.reset = function () {
viewer.camera.flyHome(0);
viewer.entities.removeAll();

if (Cesium.defined(terrainProvider)) {
viewer.terrainProvider = terrainProvider;
terrainProvider = undefined;
viewer.scene.globe.depthTestAgainstTerrain = false;
}
};
//Sandcastle_End
Sandcastle.finishedLoading();
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Change Log
==========

### 1.33 - 2017-05-01

* Added `disableDepthTestDistance` to billboards, points and labels. This sets the distance to the camera where the depth test will be disabled. Setting it to zero (the default) will alwasy enable the depth test. Setting it to `Number.POSITVE_INFINITY` will never enabled the depth test. Also added `scene.minimumDisableDepthTestDistance` to change the default value from zero. [#5166](https://github.com/AnalyticalGraphicsInc/cesium/pull/5166)

### 1.32 - 2017-04-03

* Deprecated
Expand Down
14 changes: 13 additions & 1 deletion Source/DataSources/BillboardGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ define([
this._sizeInMetersSubscription = undefined;
this._distanceDisplayCondition = undefined;
this._distanceDisplayConditionSubscription = undefined;
this._disableDepthTestDistance = undefined;
this._disableDepthTestDistanceSubscription = undefined;
this._definitionChanged = new Event();

this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
Expand Down Expand Up @@ -316,7 +318,15 @@ define([
* @memberof BillboardGraphics.prototype
* @type {Property}
*/
distanceDisplayCondition : createPropertyDescriptor('distanceDisplayCondition')
distanceDisplayCondition : createPropertyDescriptor('distanceDisplayCondition'),

/**
* Gets or sets the distance from the camera at which to disable the depth test to, for example, prevent clipping against terrain.
* When set to zero, the depth test is always applied. When set to Number.POSITIVE_INFINITY, the depth test is never applied.
* @memberof BillboardGraphics.prototype
* @type {Property}
*/
disableDepthTestDistance : createPropertyDescriptor('disableDepthTestDistance')
});

/**
Expand Down Expand Up @@ -348,6 +358,7 @@ define([
result.pixelOffsetScaleByDistance = this._pixelOffsetScaleByDistance;
result.sizeInMeters = this._sizeInMeters;
result.distanceDisplayCondition = this._distanceDisplayCondition;
result.disableDepthTestDistance = this._disableDepthTestDistance;
return result;
};

Expand Down Expand Up @@ -383,6 +394,7 @@ define([
this.pixelOffsetScaleByDistance = defaultValue(this._pixelOffsetScaleByDistance, source.pixelOffsetScaleByDistance);
this.sizeInMeters = defaultValue(this._sizeInMeters, source.sizeInMeters);
this.distanceDisplayCondition = defaultValue(this._distanceDisplayCondition, source.distanceDisplayCondition);
this.disableDepthTestDistance = defaultValue(this._disableDepthTestDistance, source.disableDepthTestDistance);
};

return BillboardGraphics;
Expand Down
4 changes: 3 additions & 1 deletion Source/DataSources/BillboardVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ define([
var defaultHorizontalOrigin = HorizontalOrigin.CENTER;
var defaultVerticalOrigin = VerticalOrigin.CENTER;
var defaultSizeInMeters = false;
var defaultDisableDepthTestDistance = 0.0;

var position = new Cartesian3();
var color = new Color();
Expand Down Expand Up @@ -154,8 +155,9 @@ define([
billboard.scaleByDistance = Property.getValueOrUndefined(billboardGraphics._scaleByDistance, time, scaleByDistance);
billboard.translucencyByDistance = Property.getValueOrUndefined(billboardGraphics._translucencyByDistance, time, translucencyByDistance);
billboard.pixelOffsetScaleByDistance = Property.getValueOrUndefined(billboardGraphics._pixelOffsetScaleByDistance, time, pixelOffsetScaleByDistance);
billboard.sizeInMeters = Property.getValueOrDefault(billboardGraphics._sizeInMeters, defaultSizeInMeters);
billboard.sizeInMeters = Property.getValueOrDefault(billboardGraphics._sizeInMeters, time, defaultSizeInMeters);
billboard.distanceDisplayCondition = Property.getValueOrUndefined(billboardGraphics._distanceDisplayCondition, time, distanceDisplayCondition);
billboard.disableDepthTestDistance = Property.getValueOrDefault(billboardGraphics._disableDepthTestDistance, time, defaultDisableDepthTestDistance);

var subRegion = Property.getValueOrUndefined(billboardGraphics._imageSubRegion, time, boundingRectangle);
if (defined(subRegion)) {
Expand Down
20 changes: 16 additions & 4 deletions Source/DataSources/LabelGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ define([
this._scaleByDistanceSubscription = undefined;
this._distanceDisplayCondition = undefined;
this._distanceDisplayConditionSubscription = undefined;
this._disableDepthTestDistance = undefined;
this._disableDepthTestDistanceSubscription = undefined;
this._definitionChanged = new Event();

this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
Expand Down Expand Up @@ -309,7 +311,15 @@ define([
* @memberof LabelGraphics.prototype
* @type {Property}
*/
distanceDisplayCondition : createPropertyDescriptor('distanceDisplayCondition')
distanceDisplayCondition : createPropertyDescriptor('distanceDisplayCondition'),

/**
* Gets or sets the distance from the camera at which to disable the depth test to, for example, prevent clipping against terrain.
* When set to zero, the depth test is always applied. When set to Number.POSITIVE_INFINITY, the depth test is never applied.
* @memberof LabelGraphics.prototype
* @type {Property}
*/
disableDepthTestDistance : createPropertyDescriptor('disableDepthTestDistance')
});

/**
Expand Down Expand Up @@ -342,6 +352,7 @@ define([
result.pixelOffsetScaleByDistance = this.pixelOffsetScaleByDistance;
result.scaleByDistance = this.scaleByDistance;
result.distanceDisplayCondition = this.distanceDisplayCondition;
result.disableDepthTestDistance = this.disableDepthTestDistance;
return result;
};

Expand Down Expand Up @@ -374,10 +385,11 @@ define([
this.eyeOffset = defaultValue(this.eyeOffset, source.eyeOffset);
this.heightReference = defaultValue(this.heightReference, source.heightReference);
this.pixelOffset = defaultValue(this.pixelOffset, source.pixelOffset);
this.translucencyByDistance = defaultValue(this._translucencyByDistance, source.translucencyByDistance);
this.pixelOffsetScaleByDistance = defaultValue(this._pixelOffsetScaleByDistance, source.pixelOffsetScaleByDistance);
this.scaleByDistance = defaultValue(this._scaleByDistance, source.scaleByDistance);
this.translucencyByDistance = defaultValue(this.translucencyByDistance, source.translucencyByDistance);
this.pixelOffsetScaleByDistance = defaultValue(this.pixelOffsetScaleByDistance, source.pixelOffsetScaleByDistance);
this.scaleByDistance = defaultValue(this.scaleByDistance, source.scaleByDistance);
this.distanceDisplayCondition = defaultValue(this.distanceDisplayCondition, source.distanceDisplayCondition);
this.disableDepthTestDistance = defaultValue(this.disableDepthTestDistance, source.disableDepthTestDistance);
};

return LabelGraphics;
Expand Down
2 changes: 2 additions & 0 deletions Source/DataSources/LabelVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ define([
var defaultHeightReference = HeightReference.NONE;
var defaultHorizontalOrigin = HorizontalOrigin.CENTER;
var defaultVerticalOrigin = VerticalOrigin.CENTER;
var defaultDisableDepthTestDistance = 0.0;

var position = new Cartesian3();
var fillColor = new Color();
Expand Down Expand Up @@ -164,6 +165,7 @@ define([
label.pixelOffsetScaleByDistance = Property.getValueOrUndefined(labelGraphics._pixelOffsetScaleByDistance, time, pixelOffsetScaleByDistance);
label.scaleByDistance = Property.getValueOrUndefined(labelGraphics._scaleByDistance, time, scaleByDistance);
label.distanceDisplayCondition = Property.getValueOrUndefined(labelGraphics._distanceDisplayCondition, time, distanceDisplayCondition);
label.disableDepthTestDistance = Property.getValueOrDefault(labelGraphics._disableDepthTestDistance, time, defaultDisableDepthTestDistance);
}
return true;
};
Expand Down
14 changes: 13 additions & 1 deletion Source/DataSources/PointGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ define([
this._heightReferenceSubscription = undefined;
this._distanceDisplayCondition = undefined;
this._distanceDisplayConditionSubscription = undefined;
this._disableDepthTestDistance = undefined;
this._disableDepthTestDistanceSubscription = undefined;
this._definitionChanged = new Event();

this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
Expand Down Expand Up @@ -142,7 +144,15 @@ define([
* @memberof PointGraphics.prototype
* @type {Property}
*/
distanceDisplayCondition : createPropertyDescriptor('distanceDisplayCondition')
distanceDisplayCondition : createPropertyDescriptor('distanceDisplayCondition'),

/**
* Gets or sets the distance from the camera at which to disable the depth test to, for example, prevent clipping against terrain.
* When set to zero, the depth test is always applied. When set to Number.POSITIVE_INFINITY, the depth test is never applied.
* @memberof PointGraphics.prototype
* @type {Property}
*/
disableDepthTestDistance : createPropertyDescriptor('disableDepthTestDistance')
});

/**
Expand All @@ -164,6 +174,7 @@ define([
result.translucencyByDistance = this._translucencyByDistance;
result.heightReference = this.heightReference;
result.distanceDisplayCondition = this.distanceDisplayCondition;
result.disableDepthTestDistance = this.disableDepthTestDistance;
return result;
};

Expand All @@ -189,6 +200,7 @@ define([
this.translucencyByDistance = defaultValue(this._translucencyByDistance, source.translucencyByDistance);
this.heightReference = defaultValue(this.heightReference, source.heightReference);
this.distanceDisplayCondition = defaultValue(this.distanceDisplayCondition, source.distanceDisplayCondition);
this.disableDepthTestDistance = defaultValue(this.disableDepthTestDistance, source.disableDepthTestDistance);
};

return PointGraphics;
Expand Down
3 changes: 3 additions & 0 deletions Source/DataSources/PointVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ define([
var defaultOutlineColor = Color.BLACK;
var defaultOutlineWidth = 0.0;
var defaultPixelSize = 1.0;
var defaultDisableDepthTestDistance = 0.0;

var color = new Color();
var position = new Cartesian3();
Expand Down Expand Up @@ -143,12 +144,14 @@ define([
pointPrimitive.outlineWidth = Property.getValueOrDefault(pointGraphics._outlineWidth, time, defaultOutlineWidth);
pointPrimitive.pixelSize = Property.getValueOrDefault(pointGraphics._pixelSize, time, defaultPixelSize);
pointPrimitive.distanceDisplayCondition = Property.getValueOrUndefined(pointGraphics._distanceDisplayCondition, time, distanceDisplayCondition);
pointPrimitive.disableDepthTestDistance = Property.getValueOrDefault(pointGraphics._disableDepthTestDistance, time, defaultDisableDepthTestDistance);
} else { // billboard
billboard.show = true;
billboard.position = position;
billboard.scaleByDistance = Property.getValueOrUndefined(pointGraphics._scaleByDistance, time, scaleByDistance);
billboard.translucencyByDistance = Property.getValueOrUndefined(pointGraphics._translucencyByDistance, time, translucencyByDistance);
billboard.distanceDisplayCondition = Property.getValueOrUndefined(pointGraphics._distanceDisplayCondition, time, distanceDisplayCondition);
billboard.disableDepthTestDistance = Property.getValueOrDefault(pointGraphics._disableDepthTestDistance, time, defaultDisableDepthTestDistance);
billboard.heightReference = heightReference;

var newColor = Property.getValueOrDefault(pointGraphics._color, time, defaultColor, color);
Expand Down
22 changes: 19 additions & 3 deletions Source/Renderer/AutomaticUniforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -1523,11 +1523,27 @@ define([
* @glslUniform
*/
czm_geometricToleranceOverMeter : new AutomaticUniform({
size: 1,
datatype: WebGLConstants.FLOAT,
getValue: function(uniformState) {
size : 1,
datatype : WebGLConstants.FLOAT,
getValue : function(uniformState) {
return uniformState.geometricToleranceOverMeter;
}
}),

/**
* An automatic GLSL uniform representing the distance from the camera at which to disable the depth test of billboards, labels and points
* to, for example, prevent clipping against terrain. When set to zero, the depth test should always be applied. When less than zero,
* the depth test should never be applied.
*
* @alias czm_minimumDisableDepthTestDistance
* @glslUniform
*/
czm_minimumDisableDepthTestDistance : new AutomaticUniform({
size : 1,
datatype : WebGLConstants.FLOAT,
getValue : function(uniformState) {
return uniformState.minimumDisableDepthTestDistance;
}
})
};

Expand Down
22 changes: 22 additions & 0 deletions Source/Renderer/UniformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ define([
this._imagerySplitPosition = 0.0;
this._pixelSizePerMeter = undefined;
this._geometricToleranceOverMeter = undefined;

this._minimumDisableDepthTestDistance = undefined;
}

defineProperties(UniformState.prototype, {
Expand Down Expand Up @@ -803,6 +805,20 @@ define([
get : function() {
return this._imagerySplitPosition;
}
},

/**
* The distance from the camera at which to disable the depth test of billboards, labels and points
* to, for example, prevent clipping against terrain. When set to zero, the depth test should always
* be applied. When less than zero, the depth test should never be applied.
*
* @memberof UniformState.prototype
* @type {Number}
*/
minimumDisableDepthTestDistance : {
get : function() {
return this._minimumDisableDepthTestDistance;
}
}
});

Expand Down Expand Up @@ -978,6 +994,12 @@ define([

this._geometricToleranceOverMeter = pixelSizePerMeter * frameState.maximumScreenSpaceError;
Color.clone(frameState.backgroundColor, this._backgroundColor);

this._minimumDisableDepthTestDistance = frameState.minimumDisableDepthTestDistance;
this._minimumDisableDepthTestDistance *= this._minimumDisableDepthTestDistance;
if (this._minimumDisableDepthTestDistance === Number.POSITIVE_INFINITY) {
this._minimumDisableDepthTestDistance = -1.0;
}
};

function cleanViewport(uniformState) {
Expand Down
Loading

0 comments on commit 7cf1df8

Please sign in to comment.