summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Loer <chris.loer@gmail.com>2018-01-04 13:37:41 -0800
committerChris Loer <chris.loer@mapbox.com>2018-01-04 14:24:37 -0800
commit5bfa20d71dc099416c5d715e7857ae836db160ed (patch)
tree1881ce247b0e4db8e490d41765a14315fc7ce109
parentc62b0af24fc76b4bb2eb34100611dd3ee9ee5536 (diff)
downloadqtlocation-mapboxgl-5bfa20d71dc099416c5d715e7857ae836db160ed.tar.gz
Fix distant collision perspective ratios (#10794).
Analog of GL JS issue #5911. Add native ignore for tilejson-bounds.
m---------mapbox-gl-js0
-rw-r--r--platform/node/test/ignores.json1
-rw-r--r--src/mbgl/shaders/collision_circle.cpp6
-rw-r--r--src/mbgl/text/collision_index.cpp21
-rw-r--r--src/mbgl/text/placement.cpp2
5 files changed, 18 insertions, 12 deletions
diff --git a/mapbox-gl-js b/mapbox-gl-js
-Subproject 2e6fc8901ec3937a0e71da40dff9d7d037dee74
+Subproject e877fa762b019ae434936047df4d020fe41f5e1
diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json
index 62e042cd4d..10e5e88e79 100644
--- a/platform/node/test/ignores.json
+++ b/platform/node/test/ignores.json
@@ -85,6 +85,7 @@
"render-tests/text-pitch-alignment/map-text-rotation-alignment-map": "https://github.com/mapbox/mapbox-gl-native/issues/9732",
"render-tests/text-pitch-alignment/viewport-text-rotation-alignment-map": "https://github.com/mapbox/mapbox-gl-native/issues/9732",
"render-tests/text-pitch-scaling/line-half": "https://github.com/mapbox/mapbox-gl-native/issues/9732",
+ "render-tests/tilejson-bounds/default": "https://github.com/mapbox/mapbox-gl-native/pull/10701",
"render-tests/video/default": "skip - https://github.com/mapbox/mapbox-gl-native/issues/601",
"render-tests/background-color/colorSpace-hcl": "needs issue",
"render-tests/hillshade-accent-color/default": "skip - https://github.com/mapbox/mapbox-gl-native/pull/10642",
diff --git a/src/mbgl/shaders/collision_circle.cpp b/src/mbgl/shaders/collision_circle.cpp
index 1e85d99a33..ac2d71d7fc 100644
--- a/src/mbgl/shaders/collision_circle.cpp
+++ b/src/mbgl/shaders/collision_circle.cpp
@@ -26,19 +26,19 @@ varying vec2 v_extrude_scale;
void main() {
vec4 projectedPoint = u_matrix * vec4(a_anchor_pos, 0, 1);
highp float camera_to_anchor_distance = projectedPoint.w;
- highp float collision_perspective_ratio = 0.5 + 0.5 * (camera_to_anchor_distance / u_camera_to_center_distance);
+ highp float collision_perspective_ratio = 0.5 + 0.5 * (u_camera_to_center_distance / camera_to_anchor_distance);
gl_Position = u_matrix * vec4(a_pos, 0.0, 1.0);
highp float padding_factor = 1.2; // Pad the vertices slightly to make room for anti-alias blur
- gl_Position.xy += a_extrude * u_extrude_scale * padding_factor * gl_Position.w / collision_perspective_ratio;
+ gl_Position.xy += a_extrude * u_extrude_scale * padding_factor * gl_Position.w * collision_perspective_ratio;
v_placed = a_placed.x;
v_notUsed = a_placed.y;
v_radius = abs(a_extrude.y); // We don't pitch the circles, so both units of the extrusion vector are equal in magnitude to the radius
v_extrude = a_extrude * padding_factor;
- v_extrude_scale = u_extrude_scale * u_camera_to_center_distance / collision_perspective_ratio;
+ v_extrude_scale = u_extrude_scale * u_camera_to_center_distance * collision_perspective_ratio;
}
)MBGL_SHADER";
diff --git a/src/mbgl/text/collision_index.cpp b/src/mbgl/text/collision_index.cpp
index 8014efe6c7..833658c33e 100644
--- a/src/mbgl/text/collision_index.cpp
+++ b/src/mbgl/text/collision_index.cpp
@@ -78,10 +78,10 @@ std::pair<bool,bool> CollisionIndex::placeFeature(CollisionFeature& feature,
CollisionBox& box = feature.boxes.front();
const auto projectedPoint = projectAndGetPerspectiveRatio(posMatrix, box.anchor);
const float tileToViewport = textPixelRatio * projectedPoint.second;
- box.px1 = box.x1 / tileToViewport + projectedPoint.first.x;
- box.py1 = box.y1 / tileToViewport + projectedPoint.first.y;
- box.px2 = box.x2 / tileToViewport + projectedPoint.first.x;
- box.py2 = box.y2 / tileToViewport + projectedPoint.first.y;
+ box.px1 = box.x1 * tileToViewport + projectedPoint.first.x;
+ box.py1 = box.y1 * tileToViewport + projectedPoint.first.y;
+ box.px2 = box.x2 * tileToViewport + projectedPoint.first.x;
+ box.py2 = box.y2 * tileToViewport + projectedPoint.first.y;
if (!isInsideGrid(box) ||
(!allowOverlap && collisionGrid.hitTest({{ box.px1, box.py1 }, { box.px2, box.py2 }}))) {
@@ -130,8 +130,10 @@ std::pair<bool,bool> CollisionIndex::placeLineFeature(CollisionFeature& feature,
bool entirelyOffscreen = true;
const auto tileToViewport = projectedAnchor.first * textPixelRatio;
+ // pixelsToTileUnits is used for translating line geometry to tile units
+ // ... so we care about 'scale' but not 'perspectiveRatio'
// equivalent to pixel_to_tile_units
- const auto pixelsToTileUnits = tileToViewport / scale;
+ const auto pixelsToTileUnits = 1 / (textPixelRatio * scale);
float firstTileDistance = 0, lastTileDistance = 0;
if (firstAndLastGlyph) {
@@ -155,7 +157,7 @@ std::pair<bool,bool> CollisionIndex::placeLineFeature(CollisionFeature& feature,
const auto projectedPoint = projectPoint(posMatrix, circle.anchor);
const float tileUnitRadius = (circle.x2 - circle.x1) / 2;
- const float radius = tileUnitRadius / tileToViewport;
+ const float radius = tileUnitRadius * tileToViewport;
if (atLeastOneCirclePlaced) {
const CollisionBox& previousCircle = feature.boxes[i - 1];
@@ -330,7 +332,7 @@ std::pair<float,float> CollisionIndex::projectAnchor(const mat4& posMatrix, cons
vec4 p = {{ point.x, point.y, 0, 1 }};
matrix::transformMat4(p, p, posMatrix);
return std::make_pair(
- 0.5 + 0.5 * (p[3] / transformState.getCameraToCenterDistance()),
+ 0.5 + 0.5 * (transformState.getCameraToCenterDistance() / p[3]),
p[3]
);
}
@@ -343,7 +345,10 @@ std::pair<Point<float>,float> CollisionIndex::projectAndGetPerspectiveRatio(cons
(((p[0] / p[3] + 1) / 2) * transformState.getSize().width) + viewportPadding,
(((-p[1] / p[3] + 1) / 2) * transformState.getSize().height) + viewportPadding
),
- 0.5 + 0.5 * (p[3] / transformState.getCameraToCenterDistance())
+ // See perspective ratio comment in symbol_sdf.vertex
+ // We're doing collision detection in viewport space so we need
+ // to scale down boxes in the distance
+ 0.5 + 0.5 * (transformState.getCameraToCenterDistance() / p[3])
);
}
diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp
index 334748dda6..b27d8f5baf 100644
--- a/src/mbgl/text/placement.cpp
+++ b/src/mbgl/text/placement.cpp
@@ -59,7 +59,7 @@ void Placement::placeLayer(RenderSymbolLayer& symbolLayer, const mat4& projMatri
const float pixelsToTileUnits = renderTile.id.pixelsToTileUnits(1, state.getZoom());
const float scale = std::pow(2, state.getZoom() - renderTile.tile.id.overscaledZ);
- const float textPixelRatio = util::EXTENT / (util::tileSize * renderTile.tile.id.overscaleFactor());
+ const float textPixelRatio = (util::tileSize * renderTile.tile.id.overscaleFactor()) / util::EXTENT;
mat4 posMatrix;
state.matrixFor(posMatrix, renderTile.id);