summaryrefslogtreecommitdiff
path: root/src/mbgl/shaders
diff options
context:
space:
mode:
authorChris Loer <chris.loer@gmail.com>2017-07-11 11:22:39 -0700
committerChris Loer <chris.loer@mapbox.com>2017-07-12 14:14:09 -0700
commite8657becc56c2aee5b070357092da028e752d461 (patch)
tree21a877d6adacfc468b4d2c0223bffec49ea3f5dc /src/mbgl/shaders
parentaf10e2d3be5f24c1887622c63332a3cf67bc19d5 (diff)
downloadqtlocation-mapboxgl-e8657becc56c2aee5b070357092da028e752d461.tar.gz
[core] Update shaders.
Implements 'icon-pitch-alignment' (issue #9345) Fixes issue #9456 (map-aligned point label regression)
Diffstat (limited to 'src/mbgl/shaders')
-rw-r--r--src/mbgl/shaders/symbol_icon.cpp17
-rw-r--r--src/mbgl/shaders/symbol_sdf.cpp19
2 files changed, 32 insertions, 4 deletions
diff --git a/src/mbgl/shaders/symbol_icon.cpp b/src/mbgl/shaders/symbol_icon.cpp
index cb00cdad05..c0e3a0ac01 100644
--- a/src/mbgl/shaders/symbol_icon.cpp
+++ b/src/mbgl/shaders/symbol_icon.cpp
@@ -19,6 +19,8 @@ uniform highp float u_size_t; // used to interpolate between zoom stops when siz
uniform highp float u_size; // used when size is both zoom and feature constant
uniform highp float u_camera_to_center_distance;
uniform highp float u_pitch;
+uniform bool u_rotate_symbol;
+uniform highp float u_aspect_ratio;
uniform highp float u_collision_y_stretch;
@@ -83,8 +85,19 @@ void main() {
float fontScale = u_is_text ? size / 24.0 : size;
- highp float angle_sin = sin(segment_angle);
- highp float angle_cos = cos(segment_angle);
+ highp float symbol_rotation = 0.0;
+ if (u_rotate_symbol) {
+ // See comments in symbol_sdf.vertex
+ vec4 offsetProjectedPoint = u_matrix * vec4(a_pos + vec2(1, 0), 0, 1);
+
+ vec2 a = projectedPoint.xy / projectedPoint.w;
+ vec2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
+
+ symbol_rotation = atan((b.y - a.y) / u_aspect_ratio, b.x - a.x);
+ }
+
+ highp float angle_sin = sin(segment_angle + symbol_rotation);
+ highp float angle_cos = cos(segment_angle + symbol_rotation);
mat2 rotation_matrix = mat2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos);
vec4 projected_pos = u_label_plane_matrix * vec4(a_projected_pos.xy, 0.0, 1.0);
diff --git a/src/mbgl/shaders/symbol_sdf.cpp b/src/mbgl/shaders/symbol_sdf.cpp
index b4158bacc5..2050886957 100644
--- a/src/mbgl/shaders/symbol_sdf.cpp
+++ b/src/mbgl/shaders/symbol_sdf.cpp
@@ -73,6 +73,8 @@ uniform mat4 u_gl_coord_matrix;
uniform bool u_is_text;
uniform bool u_pitch_with_map;
uniform highp float u_pitch;
+uniform bool u_rotate_symbol;
+uniform highp float u_aspect_ratio;
uniform highp float u_camera_to_center_distance;
uniform highp float u_collision_y_stretch;
@@ -151,8 +153,21 @@ void main() {
float fontScale = u_is_text ? size / 24.0 : size;
- highp float angle_sin = sin(segment_angle);
- highp float angle_cos = cos(segment_angle);
+ highp float symbol_rotation = 0.0;
+ if (u_rotate_symbol) {
+ // Point labels with 'rotation-alignment: map' are horizontal with respect to tile units
+ // To figure out that angle in projected space, we draw a short horizontal line in tile
+ // space, project it, and measure its angle in projected space.
+ vec4 offsetProjectedPoint = u_matrix * vec4(a_pos + vec2(1, 0), 0, 1);
+
+ vec2 a = projectedPoint.xy / projectedPoint.w;
+ vec2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
+
+ symbol_rotation = atan((b.y - a.y) / u_aspect_ratio, b.x - a.x);
+ }
+
+ highp float angle_sin = sin(segment_angle + symbol_rotation);
+ highp float angle_cos = cos(segment_angle + symbol_rotation);
mat2 rotation_matrix = mat2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos);
vec4 projected_pos = u_label_plane_matrix * vec4(a_projected_pos.xy, 0.0, 1.0);