Skip to content

Commit 13816d6

Browse files
authored
Merge pull request #6844 from AnalyticalGraphicsInc/billboard-fixes
Billboard clamp to ground cleanup
2 parents cc41b8a + 21dd1ac commit 13816d6

9 files changed

+53
-52
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Change Log
2929
* Fixed a bug that caused polylines on terrain to render incorrectly in 2D and Columbus View with a `WebMercatorProjection`. [#6809](https://github.com/AnalyticalGraphicsInc/cesium/issues/6809)
3030
* Fixed bug where entities with a height reference weren't being updated correctly when the terrain provider was changed. [#6820](https://github.com/AnalyticalGraphicsInc/cesium/pull/6820)
3131
* Fixed the geocoder when `Viewer` is passed the option `geocoder: true` [#6833](https://github.com/AnalyticalGraphicsInc/cesium/pull/6833)
32+
* Improved performance for billboards and labels clamped to terrain [#6781](https://github.com/AnalyticalGraphicsInc/cesium/pull/6781) [#6844](https://github.com/AnalyticalGraphicsInc/cesium/pull/6844)
3233
* Fixed a bug that caused billboard positions to be set incorrectly when using a `CallbackProperty`. [#6815](https://github.com/AnalyticalGraphicsInc/cesium/pull/6815)
3334
* Improved support for generating a TypeScript typings file using `tsd-jsdoc` [#6767](https://github.com/AnalyticalGraphicsInc/cesium/pull/6767)
3435
* Updated viewBoundingSphere to use correct zoomOptions [#6848](https://github.com/AnalyticalGraphicsInc/cesium/issues/6848)

Source/DataSources/BillboardVisualizer.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ define([
4242
var defaultHorizontalOrigin = HorizontalOrigin.CENTER;
4343
var defaultVerticalOrigin = VerticalOrigin.CENTER;
4444
var defaultSizeInMeters = false;
45-
var defaultDisableDepthTestDistance = 0.0;
4645

4746
var positionScratch = new Cartesian3();
4847
var colorScratch = new Color();
@@ -156,7 +155,7 @@ define([
156155
billboard.pixelOffsetScaleByDistance = Property.getValueOrUndefined(billboardGraphics._pixelOffsetScaleByDistance, time, pixelOffsetScaleByDistanceScratch);
157156
billboard.sizeInMeters = Property.getValueOrDefault(billboardGraphics._sizeInMeters, time, defaultSizeInMeters);
158157
billboard.distanceDisplayCondition = Property.getValueOrUndefined(billboardGraphics._distanceDisplayCondition, time, distanceDisplayConditionScratch);
159-
billboard.disableDepthTestDistance = Property.getValueOrDefault(billboardGraphics._disableDepthTestDistance, time, defaultDisableDepthTestDistance);
158+
billboard.disableDepthTestDistance = Property.getValueOrUndefined(billboardGraphics._disableDepthTestDistance, time);
160159

161160
var subRegion = Property.getValueOrUndefined(billboardGraphics._imageSubRegion, time, boundingRectangleScratch);
162161
if (defined(subRegion)) {

Source/DataSources/LabelVisualizer.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ define([
4848
var defaultHeightReference = HeightReference.NONE;
4949
var defaultHorizontalOrigin = HorizontalOrigin.CENTER;
5050
var defaultVerticalOrigin = VerticalOrigin.CENTER;
51-
var defaultDisableDepthTestDistance = 0.0;
5251

5352
var positionScratch = new Cartesian3();
5453
var fillColorScratch = new Color();
@@ -164,7 +163,7 @@ define([
164163
label.pixelOffsetScaleByDistance = Property.getValueOrUndefined(labelGraphics._pixelOffsetScaleByDistance, time, pixelOffsetScaleByDistanceScratch);
165164
label.scaleByDistance = Property.getValueOrUndefined(labelGraphics._scaleByDistance, time, scaleByDistanceScratch);
166165
label.distanceDisplayCondition = Property.getValueOrUndefined(labelGraphics._distanceDisplayCondition, time, distanceDisplayConditionScratch);
167-
label.disableDepthTestDistance = Property.getValueOrDefault(labelGraphics._disableDepthTestDistance, time, defaultDisableDepthTestDistance);
166+
label.disableDepthTestDistance = Property.getValueOrUndefined(labelGraphics._disableDepthTestDistance, time);
168167
}
169168
return true;
170169
};

Source/Scene/Billboard.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ define([
141141
this._pixelOffsetScaleByDistance = pixelOffsetScaleByDistance;
142142
this._sizeInMeters = defaultValue(options.sizeInMeters, false);
143143
this._distanceDisplayCondition = distanceDisplayCondition;
144-
this._disableDepthTestDistance = defaultValue(options.disableDepthTestDistance, 0.0);
144+
this._disableDepthTestDistance = options.disableDepthTestDistance;
145145
this._id = options.id;
146146
this._collection = defaultValue(options.collection, billboardCollection);
147147

@@ -790,7 +790,6 @@ define([
790790
* When set to zero, the depth test is always applied. When set to Number.POSITIVE_INFINITY, the depth test is never applied.
791791
* @memberof Billboard.prototype
792792
* @type {Number}
793-
* @default 0.0
794793
*/
795794
disableDepthTestDistance : {
796795
get : function() {
@@ -799,7 +798,7 @@ define([
799798
set : function(value) {
800799
if (this._disableDepthTestDistance !== value) {
801800
//>>includeStart('debug', pragmas.debug);
802-
if (!defined(value) || value < 0.0) {
801+
if (defined(value) && value < 0.0) {
803802
throw new DeveloperError('disableDepthTestDistance must be greater than or equal to 0.0.');
804803
}
805804
//>>includeEnd('debug');

Source/Scene/BillboardCollection.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ define([
331331
this._removeCallbackFunc = scene.terrainProviderChanged.addEventListener(function() {
332332
var billboards = this._billboards;
333333
var length = billboards.length;
334-
for (var i=0;i<length;++i) {
334+
for (var i = 0; i < length; ++i) {
335335
billboards[i]._updateClamping();
336336
}
337337
}, this);
@@ -690,7 +690,7 @@ define([
690690
var usageChanged = false;
691691

692692
var properties = this._propertiesChanged;
693-
for ( var k = 0; k < NUMBER_OF_PROPERTIES; ++k) {
693+
for (var k = 0; k < NUMBER_OF_PROPERTIES; ++k) {
694694
var newUsage = (properties[k] === 0) ? BufferUsage.STATIC_DRAW : BufferUsage.STREAM_DRAW;
695695
usageChanged = usageChanged || (buffersUsage[k] !== newUsage);
696696
buffersUsage[k] = newUsage;
@@ -1194,12 +1194,13 @@ define([
11941194
}
11951195

11961196
var disableDepthTestDistance = billboard.disableDepthTestDistance;
1197-
if (billboard.heightReference === HeightReference.CLAMP_TO_GROUND && disableDepthTestDistance === 0.0 && billboardCollection._scene.context.depthTexture) {
1198-
disableDepthTestDistance = 2000.0;
1197+
var clampToGround = billboard.heightReference === HeightReference.CLAMP_TO_GROUND && billboardCollection._scene.context.depthTexture;
1198+
if (!defined(disableDepthTestDistance)) {
1199+
disableDepthTestDistance = clampToGround ? 5000.0 : 0.0;
11991200
}
12001201

12011202
disableDepthTestDistance *= disableDepthTestDistance;
1202-
if (disableDepthTestDistance > 0.0) {
1203+
if (clampToGround || disableDepthTestDistance > 0.0) {
12031204
billboardCollection._shaderDisableDepthDistance = true;
12041205
if (disableDepthTestDistance === Number.POSITIVE_INFINITY) {
12051206
disableDepthTestDistance = -1.0;
@@ -1358,7 +1359,7 @@ define([
13581359
}
13591360

13601361
var positions = [];
1361-
for ( var i = 0; i < length; ++i) {
1362+
for (var i = 0; i < length; ++i) {
13621363
var billboard = billboards[i];
13631364
var position = billboard.position;
13641365
var actualPosition = Billboard._computeActualPosition(billboard, position, frameState, modelMatrix);
@@ -1411,7 +1412,7 @@ define([
14111412
}
14121413

14131414
var size = pixelScale * collection._maxScale * collection._maxSize * 2.0;
1414-
if (collection._allHorizontalCenter && collection._allVerticalCenter ) {
1415+
if (collection._allHorizontalCenter && collection._allVerticalCenter) {
14151416
size *= 0.5;
14161417
}
14171418

@@ -1560,7 +1561,7 @@ define([
15601561
var b = billboardsToUpdate[m];
15611562
b._dirty = false;
15621563

1563-
for ( var n = 0; n < numWriters; ++n) {
1564+
for (var n = 0; n < numWriters; ++n) {
15641565
writers[n](this, context, textureAtlasCoordinates, vafWriters, b);
15651566
}
15661567
}
@@ -1570,7 +1571,7 @@ define([
15701571
var bb = billboardsToUpdate[h];
15711572
bb._dirty = false;
15721573

1573-
for ( var o = 0; o < numWriters; ++o) {
1574+
for (var o = 0; o < numWriters; ++o) {
15741575
writers[o](this, context, textureAtlasCoordinates, vafWriters, bb);
15751576
}
15761577

Source/Scene/Label.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ define([
143143
this._scaleByDistance = scaleByDistance;
144144
this._heightReference = defaultValue(options.heightReference, HeightReference.NONE);
145145
this._distanceDisplayCondition = distanceDisplayCondition;
146-
this._disableDepthTestDistance = defaultValue(options.disableDepthTestDistance, 0.0);
146+
this._disableDepthTestDistance = options.disableDepthTestDistance;
147147

148148
this._labelCollection = labelCollection;
149149
this._glyphs = [];
@@ -930,7 +930,6 @@ define([
930930
* When set to zero, the depth test is always applied. When set to Number.POSITIVE_INFINITY, the depth test is never applied.
931931
* @memberof Label.prototype
932932
* @type {Number}
933-
* @default 0.0
934933
*/
935934
disableDepthTestDistance : {
936935
get : function() {
@@ -939,7 +938,7 @@ define([
939938
set : function(value) {
940939
if (this._disableDepthTestDistance !== value) {
941940
//>>includeStart('debug', pragmas.debug);
942-
if (!defined(value) || value < 0.0) {
941+
if (defined(value) && value < 0.0) {
943942
throw new DeveloperError('disableDepthTestDistance must be greater than 0.0.');
944943
}
945944
//>>includeEnd('debug');

Source/Shaders/BillboardCollectionVS.glsl

+14-11
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,6 @@ void main()
195195

196196
depthOrigin = vec2(1.0) - (depthOrigin * 0.5);
197197
#endif
198-
#if defined(VERTEX_DEPTH_CHECK) || defined(FRAGMENT_DEPTH_CHECK)
199-
temp = compressedAttribute3.w;
200-
temp = temp * SHIFT_RIGHT12;
201-
202-
vec2 dimensions;
203-
dimensions.y = (temp - floor(temp)) * SHIFT_LEFT12;
204-
dimensions.x = floor(temp);
205-
#endif
206198

207199
#ifdef EYE_DISTANCE_TRANSLUCENCY
208200
vec4 translucencyByDistance;
@@ -215,6 +207,15 @@ void main()
215207
translucencyByDistance.w = ((temp - floor(temp)) * SHIFT_LEFT8) / 255.0;
216208
#endif
217209

210+
#if defined(VERTEX_DEPTH_CHECK) || defined(FRAGMENT_DEPTH_CHECK)
211+
temp = compressedAttribute3.w;
212+
temp = temp * SHIFT_RIGHT12;
213+
214+
vec2 dimensions;
215+
dimensions.y = (temp - floor(temp)) * SHIFT_LEFT12;
216+
dimensions.x = floor(temp);
217+
#endif
218+
218219
#ifdef ALIGNED_AXIS
219220
vec3 alignedAxis = czm_octDecode(floor(compressedAttribute1.y * SHIFT_RIGHT8));
220221
temp = compressedAttribute2.z * SHIFT_RIGHT5;
@@ -323,20 +324,22 @@ void main()
323324

324325
#ifdef VERTEX_DEPTH_CHECK
325326
if (lengthSq < disableDepthTestDistance) {
327+
float depthsilon = 10.0;
328+
326329
vec2 labelTranslate = textureCoordinateBoundsOrLabelTranslate.xy;
327330
vec4 pEC1 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(0.0), origin, labelTranslate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);
328331
float globeDepth1 = getGlobeDepth(pEC1);
329332

330-
if (globeDepth1 != 0.0 && pEC1.z < globeDepth1)
333+
if (globeDepth1 != 0.0 && pEC1.z + depthsilon < globeDepth1)
331334
{
332335
vec4 pEC2 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(0.0, 1.0), origin, labelTranslate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);
333336
float globeDepth2 = getGlobeDepth(pEC2);
334337

335-
if (globeDepth2 != 0.0 && pEC2.z < globeDepth2)
338+
if (globeDepth2 != 0.0 && pEC2.z + depthsilon < globeDepth2)
336339
{
337340
vec4 pEC3 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(1.0), origin, labelTranslate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);
338341
float globeDepth3 = getGlobeDepth(pEC3);
339-
if (globeDepth3 != 0.0 && pEC3.z < globeDepth3)
342+
if (globeDepth3 != 0.0 && pEC3.z + depthsilon < globeDepth3)
340343
{
341344
positionEC.xyz = vec3(0.0);
342345
}

Specs/Scene/BillboardCollectionSpec.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,23 @@ defineSuite([
113113
expect(b.horizontalOrigin).toEqual(HorizontalOrigin.CENTER);
114114
expect(b.verticalOrigin).toEqual(VerticalOrigin.CENTER);
115115
expect(b.scale).toEqual(1.0);
116-
expect(b.image).not.toBeDefined();
116+
expect(b.image).toBeUndefined();
117117
expect(b.color.red).toEqual(1.0);
118118
expect(b.color.green).toEqual(1.0);
119119
expect(b.color.blue).toEqual(1.0);
120120
expect(b.color.alpha).toEqual(1.0);
121121
expect(b.rotation).toEqual(0.0);
122122
expect(b.alignedAxis).toEqual(Cartesian3.ZERO);
123-
expect(b.scaleByDistance).not.toBeDefined();
124-
expect(b.translucencyByDistance).not.toBeDefined();
125-
expect(b.pixelOffsetScaleByDistance).not.toBeDefined();
126-
expect(b.width).not.toBeDefined();
127-
expect(b.height).not.toBeDefined();
128-
expect(b.id).not.toBeDefined();
123+
expect(b.scaleByDistance).toBeUndefined();
124+
expect(b.translucencyByDistance).toBeUndefined();
125+
expect(b.pixelOffsetScaleByDistance).toBeUndefined();
126+
expect(b.width).toBeUndefined();
127+
expect(b.height).toBeUndefined();
128+
expect(b.id).toBeUndefined();
129129
expect(b.heightReference).toEqual(HeightReference.NONE);
130130
expect(b.sizeInMeters).toEqual(false);
131-
expect(b.distanceDisplayCondition).not.toBeDefined();
132-
expect(b.disableDepthTestDistance).toEqual(0.0);
131+
expect(b.distanceDisplayCondition).toBeUndefined();
132+
expect(b.disableDepthTestDistance).toBeUndefined();
133133
});
134134

135135
it('can add and remove before first update.', function() {
@@ -287,23 +287,23 @@ defineSuite([
287287
scaleByDistance : new NearFarScalar(1.0, 3.0, 1.0e6, 0.0)
288288
});
289289
b.scaleByDistance = undefined;
290-
expect(b.scaleByDistance).not.toBeDefined();
290+
expect(b.scaleByDistance).toBeUndefined();
291291
});
292292

293293
it('disables billboard translucencyByDistance', function() {
294294
var b = billboards.add({
295295
translucencyByDistance : new NearFarScalar(1.0, 1.0, 1.0e6, 0.0)
296296
});
297297
b.translucencyByDistance = undefined;
298-
expect(b.translucencyByDistance).not.toBeDefined();
298+
expect(b.translucencyByDistance).toBeUndefined();
299299
});
300300

301301
it('disables billboard pixelOffsetScaleByDistance', function() {
302302
var b = billboards.add({
303303
pixelOffsetScaleByDistance : new NearFarScalar(1.0, 1.0, 1.0e6, 0.0)
304304
});
305305
b.pixelOffsetScaleByDistance = undefined;
306-
expect(b.pixelOffsetScaleByDistance).not.toBeDefined();
306+
expect(b.pixelOffsetScaleByDistance).toBeUndefined();
307307
});
308308

309309
it('renders billboard with scaleByDistance', function() {
@@ -620,7 +620,7 @@ defineSuite([
620620
});
621621

622622
it('sets and gets a texture atlas', function() {
623-
expect(billboards.textureAtlas).not.toBeDefined();
623+
expect(billboards.textureAtlas).toBeUndefined();
624624

625625
var atlas = new TextureAtlas({ context : scene.context });
626626
billboards.textureAtlas = atlas;
@@ -1864,7 +1864,7 @@ defineSuite([
18641864
scene.globe.removedCallback = false;
18651865
b.heightReference = HeightReference.NONE;
18661866
expect(scene.globe.removedCallback).toEqual(true);
1867-
expect(scene.globe.callback).not.toBeDefined();
1867+
expect(scene.globe.callback).toBeUndefined();
18681868
});
18691869

18701870
it('changing the position updates the callback', function() {

Specs/Scene/LabelCollectionSpec.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ defineSuite([
9494
expect(label.horizontalOrigin).toEqual(HorizontalOrigin.LEFT);
9595
expect(label.verticalOrigin).toEqual(VerticalOrigin.BASELINE);
9696
expect(label.scale).toEqual(1.0);
97-
expect(label.id).not.toBeDefined();
98-
expect(label.translucencyByDistance).not.toBeDefined();
99-
expect(label.pixelOffsetScaleByDistance).not.toBeDefined();
100-
expect(label.scaleByDistance).not.toBeDefined();
101-
expect(label.distanceDisplayCondition).not.toBeDefined();
102-
expect(label.disableDepthTestDistance).toEqual(0.0);
97+
expect(label.id).toBeUndefined();
98+
expect(label.translucencyByDistance).toBeUndefined();
99+
expect(label.pixelOffsetScaleByDistance).toBeUndefined();
100+
expect(label.scaleByDistance).toBeUndefined();
101+
expect(label.distanceDisplayCondition).toBeUndefined();
102+
expect(label.disableDepthTestDistance).toBeUndefined();
103103
});
104104

105105
it('can add a label with specified values', function() {
@@ -2321,7 +2321,7 @@ defineSuite([
23212321
scene.globe.removedCallback = false;
23222322
l.heightReference = HeightReference.NONE;
23232323
expect(scene.globe.removedCallback).toEqual(true);
2324-
expect(scene.globe.callback).not.toBeDefined();
2324+
expect(scene.globe.callback).toBeUndefined();
23252325
});
23262326

23272327
it('changing the position updates the callback', function() {
@@ -2384,7 +2384,7 @@ defineSuite([
23842384
var spy = spyOn(billboard, '_removeCallbackFunc');
23852385
labelsWithHeight.remove(l);
23862386
expect(spy).toHaveBeenCalled();
2387-
expect(labelsWithHeight._spareBillboards[0]._removeCallbackFunc).not.toBeDefined();
2387+
expect(labelsWithHeight._spareBillboards[0]._removeCallbackFunc).toBeUndefined();
23882388
});
23892389
});
23902390

0 commit comments

Comments
 (0)