Skip to content

Commit fb7dbcf

Browse files
authored
Merge pull request #8351 from AnalyticalGraphicsInc/metersPerPixelFixes
Fixed resolution scale for globe lighting and labels
2 parents 4ca258e + f09045e commit fb7dbcf

File tree

7 files changed

+48
-53
lines changed

7 files changed

+48
-53
lines changed

CHANGES.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Change Log
22
==========
33

4+
### 1.63.1 - 2019-11-06
5+
6+
##### Fixes :wrench:
7+
* Fixed regression in 1.63 where ground atmosphere and labels rendered incorrectly on displays with `window.devicePixelRatio` greater than 1.0. [#8351](https://github.com/AnalyticalGraphicsInc/cesium/pull/8351)
8+
49
### 1.63 - 2019-11-01
510

611
##### Major Announcements :loudspeaker:

Source/Scene/Label.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1133,12 +1133,11 @@ import VerticalOrigin from './VerticalOrigin.js';
11331133
var width = 0;
11341134
var height = 0;
11351135
var scale = label.totalScale;
1136-
var resolutionScale = label._labelCollection._resolutionScale;
11371136

11381137
var backgroundBillboard = label._backgroundBillboard;
11391138
if (defined(backgroundBillboard)) {
1140-
x = screenSpacePosition.x + (backgroundBillboard._translate.x / resolutionScale);
1141-
y = screenSpacePosition.y - (backgroundBillboard._translate.y / resolutionScale);
1139+
x = screenSpacePosition.x + (backgroundBillboard._translate.x);
1140+
y = screenSpacePosition.y - (backgroundBillboard._translate.y);
11421141
width = backgroundBillboard.width * scale;
11431142
height = backgroundBillboard.height * scale;
11441143

@@ -1161,8 +1160,8 @@ import VerticalOrigin from './VerticalOrigin.js';
11611160
continue;
11621161
}
11631162

1164-
var glyphX = screenSpacePosition.x + (billboard._translate.x / resolutionScale);
1165-
var glyphY = screenSpacePosition.y - (billboard._translate.y / resolutionScale);
1163+
var glyphX = screenSpacePosition.x + (billboard._translate.x);
1164+
var glyphY = screenSpacePosition.y - (billboard._translate.y);
11661165
var glyphWidth = glyph.dimensions.width * scale;
11671166
var glyphHeight = glyph.dimensions.height * scale;
11681167

Source/Scene/LabelCollection.js

+12-25
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ import GraphemeSplitter from '../ThirdParty/graphemesplitter.js';
316316
var glyphPixelOffset = new Cartesian2();
317317
var scratchBackgroundPadding = new Cartesian2();
318318

319-
function repositionAllGlyphs(label, resolutionScale) {
319+
function repositionAllGlyphs(label) {
320320
var glyphs = label._glyphs;
321321
var text = label._renderedText;
322322
var glyph;
@@ -378,7 +378,7 @@ import GraphemeSplitter from '../ThirdParty/graphemesplitter.js';
378378
backgroundBillboard._labelHorizontalOrigin = horizontalOrigin;
379379
}
380380

381-
glyphPixelOffset.x = widthOffset * scale * resolutionScale;
381+
glyphPixelOffset.x = widthOffset * scale;
382382
glyphPixelOffset.y = 0;
383383

384384
var firstCharOfLine = true;
@@ -390,7 +390,7 @@ import GraphemeSplitter from '../ThirdParty/graphemesplitter.js';
390390
lineOffsetY += lineSpacing;
391391
lineWidth = lineWidths[lineIndex];
392392
widthOffset = calculateWidthOffset(lineWidth, horizontalOrigin, backgroundPadding);
393-
glyphPixelOffset.x = widthOffset * scale * resolutionScale;
393+
glyphPixelOffset.x = widthOffset * scale;
394394
firstCharOfLine = true;
395395
} else {
396396
glyph = glyphs[glyphIndex];
@@ -409,12 +409,12 @@ import GraphemeSplitter from '../ThirdParty/graphemesplitter.js';
409409
glyphPixelOffset.y = otherLinesHeight + maxGlyphDescent + backgroundPadding.y;
410410
glyphPixelOffset.y -= SDFSettings.PADDING;
411411
}
412-
glyphPixelOffset.y = (glyphPixelOffset.y - dimensions.descent - lineOffsetY) * scale * resolutionScale;
412+
glyphPixelOffset.y = (glyphPixelOffset.y - dimensions.descent - lineOffsetY) * scale;
413413

414414
// Handle any offsets for the first character of the line since the bounds might not be right on the bottom left pixel.
415415
if (firstCharOfLine)
416416
{
417-
glyphPixelOffset.x -= SDFSettings.PADDING * scale * resolutionScale;
417+
glyphPixelOffset.x -= SDFSettings.PADDING * scale;
418418
firstCharOfLine = false;
419419
}
420420

@@ -430,7 +430,7 @@ import GraphemeSplitter from '../ThirdParty/graphemesplitter.js';
430430
//as well as any applied scale.
431431
if (glyphIndex < glyphLength - 1) {
432432
var nextGlyph = glyphs[glyphIndex + 1];
433-
glyphPixelOffset.x += ((dimensions.width - dimensions.bounds.minx) + nextGlyph.dimensions.bounds.minx) * scale * resolutionScale;
433+
glyphPixelOffset.x += ((dimensions.width - dimensions.bounds.minx) + nextGlyph.dimensions.bounds.minx) * scale;
434434
}
435435
}
436436
}
@@ -443,7 +443,7 @@ import GraphemeSplitter from '../ThirdParty/graphemesplitter.js';
443443
} else {
444444
widthOffset = 0;
445445
}
446-
glyphPixelOffset.x = widthOffset * scale * resolutionScale;
446+
glyphPixelOffset.x = widthOffset * scale;
447447

448448
if (verticalOrigin === VerticalOrigin.TOP) {
449449
glyphPixelOffset.y = maxLineHeight - maxGlyphY - maxGlyphDescent;
@@ -455,7 +455,7 @@ import GraphemeSplitter from '../ThirdParty/graphemesplitter.js';
455455
// VerticalOrigin.BOTTOM
456456
glyphPixelOffset.y = 0;
457457
}
458-
glyphPixelOffset.y = glyphPixelOffset.y * scale * resolutionScale;
458+
glyphPixelOffset.y = glyphPixelOffset.y * scale;
459459

460460
backgroundBillboard.width = totalLineWidth;
461461
backgroundBillboard.height = totalLineHeight;
@@ -566,7 +566,6 @@ import GraphemeSplitter from '../ThirdParty/graphemesplitter.js';
566566
this._labels = [];
567567
this._labelsToUpdate = [];
568568
this._totalGlyphCount = 0;
569-
this._resolutionScale = undefined;
570569

571570
this._highlightColor = Color.clone(Color.WHITE); // Only used by Vector3DTilePoints
572571

@@ -844,21 +843,9 @@ import GraphemeSplitter from '../ThirdParty/graphemesplitter.js';
844843
addWhitePixelCanvas(this._backgroundTextureAtlas, this);
845844
}
846845

847-
var uniformState = context.uniformState;
848-
var resolutionScale = uniformState.pixelRatio;
849-
var resolutionChanged = this._resolutionScale !== resolutionScale;
850-
this._resolutionScale = resolutionScale;
851-
852-
var labelsToUpdate;
853-
if (resolutionChanged) {
854-
labelsToUpdate = this._labels;
855-
} else {
856-
labelsToUpdate = this._labelsToUpdate;
857-
}
858-
859-
var len = labelsToUpdate.length;
846+
var len = this._labelsToUpdate.length;
860847
for (var i = 0; i < len; ++i) {
861-
var label = labelsToUpdate[i];
848+
var label = this._labelsToUpdate[i];
862849
if (label.isDestroyed()) {
863850
continue;
864851
}
@@ -870,8 +857,8 @@ import GraphemeSplitter from '../ThirdParty/graphemesplitter.js';
870857
label._rebindAllGlyphs = false;
871858
}
872859

873-
if (resolutionChanged || label._repositionAllGlyphs) {
874-
repositionAllGlyphs(label, resolutionScale);
860+
if (label._repositionAllGlyphs) {
861+
repositionAllGlyphs(label);
875862
label._repositionAllGlyphs = false;
876863
}
877864

Source/Shaders/BillboardCollectionVS.glsl

+2-18
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,10 @@ vec4 addScreenSpaceOffset(vec4 positionEC, vec2 imageSize, float scale, vec2 dir
8383
}
8484
#endif
8585

86-
if (sizeInMeters)
87-
{
88-
positionEC.xy += halfSize;
89-
}
90-
9186
mpp = czm_metersPerPixel(positionEC);
87+
positionEC.xy += (originTranslate + halfSize) * czm_branchFreeTernary(sizeInMeters, 1.0, mpp);
88+
positionEC.xy += (translate + pixelOffset) * mpp;
9289

93-
if (!sizeInMeters)
94-
{
95-
originTranslate *= mpp;
96-
}
97-
98-
positionEC.xy += originTranslate;
99-
if (!sizeInMeters)
100-
{
101-
positionEC.xy += halfSize * mpp;
102-
}
103-
104-
positionEC.xy += translate * mpp;
105-
positionEC.xy += pixelOffset * mpp;
10690
return positionEC;
10791
}
10892

Source/Shaders/Builtin/Functions/metersPerPixel.glsl

+23-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
/**
22
* Computes the size of a pixel in meters at a distance from the eye.
3-
3+
* <p>
4+
* Use this version when passing in a custom pixel ratio. For example, passing in 1.0 will return meters per native device pixel.
5+
* </p>
46
* @name czm_metersPerPixel
57
* @glslFunction
68
*
79
* @param {vec3} positionEC The position to get the meters per pixel in eye coordinates.
10+
* @param {float} pixelRatio The scaling factor from pixel space to coordinate space
811
*
912
* @returns {float} The meters per pixel at positionEC.
1013
*/
11-
float czm_metersPerPixel(vec4 positionEC)
14+
float czm_metersPerPixel(vec4 positionEC, float pixelRatio)
1215
{
1316
float width = czm_viewport.z;
1417
float height = czm_viewport.w;
@@ -37,5 +40,22 @@ float czm_metersPerPixel(vec4 positionEC)
3740
pixelWidth = 2.0 * distanceToPixel * tanTheta / width;
3841
}
3942

40-
return max(pixelWidth, pixelHeight) * czm_pixelRatio;
43+
return max(pixelWidth, pixelHeight) * pixelRatio;
44+
}
45+
46+
/**
47+
* Computes the size of a pixel in meters at a distance from the eye.
48+
* <p>
49+
* Use this version when scaling by pixel ratio.
50+
* </p>
51+
* @name czm_metersPerPixel
52+
* @glslFunction
53+
*
54+
* @param {vec3} positionEC The position to get the meters per pixel in eye coordinates.
55+
*
56+
* @returns {float} The meters per pixel at positionEC.
57+
*/
58+
float czm_metersPerPixel(vec4 positionEC)
59+
{
60+
return czm_metersPerPixel(positionEC, czm_pixelRatio);
4161
}

Source/Shaders/Builtin/Functions/writeLogDepth.glsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ varying float v_logZ;
55
/**
66
* Writes the fragment depth to the logarithmic depth buffer.
77
* <p>
8-
* Use this when the vertex shader does not calls {@link czm_vertexlogDepth}, for example, when
8+
* Use this when the vertex shader does not call {@link czm_vertexlogDepth}, for example, when
99
* ray-casting geometry using a full screen quad.
1010
* </p>
1111
* @name czm_writeLogDepth

Source/Shaders/GlobeFS.glsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ void main()
376376
}
377377

378378
#if defined(PER_FRAGMENT_GROUND_ATMOSPHERE) && (defined(ENABLE_DAYNIGHT_SHADING) || defined(ENABLE_VERTEX_LIGHTING))
379-
float mpp = czm_metersPerPixel(vec4(0.0, 0.0, -czm_currentFrustum.x, 1.0));
379+
float mpp = czm_metersPerPixel(vec4(0.0, 0.0, -czm_currentFrustum.x, 1.0), 1.0);
380380
vec2 xy = gl_FragCoord.xy / czm_viewport.zw * 2.0 - vec2(1.0);
381381
xy *= czm_viewport.zw * mpp * 0.5;
382382

0 commit comments

Comments
 (0)