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 cracking between quantized terrain tiles in 2D. #3486

Merged
merged 3 commits into from
Jan 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Change Log
* Added a Sandcastle example to "star burst" overlapping billboards and labels.
* Added `Rectangle.union` and `Rectangle.expand`.
* Added `Math.logBase` function.
* Fixed a cracking between tiles in 2D. [#3486](https://github.com/AnalyticalGraphicsInc/cesium/pull/3486)

### 1.17 - 2016-01-04

Expand Down
18 changes: 17 additions & 1 deletion Source/Scene/GlobeSurfaceTileProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ define([
'../Core/PrimitiveType',
'../Core/Rectangle',
'../Core/SphereOutlineGeometry',
'../Core/TerrainQuantization',
'../Core/Visibility',
'../Core/WebMercatorProjection',
'../Renderer/Buffer',
Expand Down Expand Up @@ -68,6 +69,7 @@ define([
PrimitiveType,
Rectangle,
SphereOutlineGeometry,
TerrainQuantization,
Visibility,
WebMercatorProjection,
Buffer,
Expand Down Expand Up @@ -890,6 +892,7 @@ define([
}

var rtc = surfaceTile.center;
var encoding = surfaceTile.pickTerrain.mesh.encoding;

// Not used in 3D.
var tileRectangle = tileRectangleScratch;
Expand Down Expand Up @@ -924,6 +927,20 @@ define([
tileRectangle.w -= rtc.z;
}

if (frameState.mode === SceneMode.SCENE2D && encoding.quantization === TerrainQuantization.BITS12) {
// In 2D, the texture coordinates of the tile are interpolated over the rectangle to get the position in the vertex shader.
// When the texture coordinates are quantized, error is introduced. This can be seen through the 1px wide cracking
// between the quantized tiles in 2D. To compensate for the error, move the expand the rectangle in each direction by
// half the error amount.
var epsilon = (1.0 / (Math.pow(2.0, 12.0) - 1.0)) * 0.5;
var widthEpsilon = (tileRectangle.z - tileRectangle.x) * epsilon;
var heightEpsilon = (tileRectangle.w - tileRectangle.y) * epsilon;
tileRectangle.x -= widthEpsilon;
tileRectangle.y -= heightEpsilon;
tileRectangle.z += widthEpsilon;
tileRectangle.w += heightEpsilon;
}

if (projection instanceof WebMercatorProjection) {
southLatitude = tile.rectangle.south;
northLatitude = tile.rectangle.north;
Expand Down Expand Up @@ -1071,7 +1088,6 @@ define([
uniformMap.waterMask = waterMaskTexture;
Cartesian4.clone(surfaceTile.waterMaskTranslationAndScale, uniformMap.waterMaskTranslationAndScale);

var encoding = surfaceTile.pickTerrain.mesh.encoding;
uniformMap.minMaxHeight.x = encoding.minimumHeight;
uniformMap.minMaxHeight.y = encoding.maximumHeight;
Matrix4.clone(encoding.matrix, uniformMap.scaleAndBias);
Expand Down