summaryrefslogtreecommitdiff
path: root/src/mbgl/shaders/symbol_icon.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/shaders/symbol_icon.cpp')
-rw-r--r--src/mbgl/shaders/symbol_icon.cpp44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/mbgl/shaders/symbol_icon.cpp b/src/mbgl/shaders/symbol_icon.cpp
index bc570cf361..8960e02c28 100644
--- a/src/mbgl/shaders/symbol_icon.cpp
+++ b/src/mbgl/shaders/symbol_icon.cpp
@@ -7,17 +7,20 @@ namespace shaders {
const char* symbol_icon::name = "symbol_icon";
const char* symbol_icon::vertexSource = R"MBGL_SHADER(
-
attribute vec4 a_pos_offset;
+attribute vec2 a_label_pos;
attribute vec4 a_data;
// icon-size data (see symbol_sdf.vertex.glsl for more)
attribute vec3 a_size;
uniform bool u_is_size_zoom_constant;
uniform bool u_is_size_feature_constant;
-uniform mediump float u_size_t; // used to interpolate between zoom stops when size is a composite function
-uniform mediump float u_size; // used when size is both zoom and feature constant
-uniform mediump float u_layout_size; // used when size is feature constant
+uniform highp float u_size_t; // used to interpolate between zoom stops when size is a composite function
+uniform highp float u_size; // used when size is both zoom and feature constant
+uniform highp float u_layout_size; // used when size is feature constant
+uniform highp float u_camera_to_center_distance;
+uniform highp float u_pitch;
+uniform highp float u_collision_y_stretch;
#ifndef HAS_UNIFORM_u_opacity
@@ -32,7 +35,7 @@ uniform lowp float u_opacity;
uniform mat4 u_matrix;
uniform bool u_is_text;
-uniform mediump float u_zoom;
+uniform highp float u_zoom;
uniform bool u_rotate_with_map;
uniform vec2 u_extrude_scale;
@@ -53,11 +56,11 @@ void main() {
vec2 a_offset = a_pos_offset.zw;
vec2 a_tex = a_data.xy;
- mediump vec2 label_data = unpack_float(a_data[2]);
- mediump float a_labelminzoom = label_data[0];
- mediump vec2 a_zoom = unpack_float(a_data[3]);
- mediump float a_minzoom = a_zoom[0];
- mediump float a_maxzoom = a_zoom[1];
+ highp vec2 label_data = unpack_float(a_data[2]);
+ highp float a_labelminzoom = label_data[0];
+ highp vec2 a_zoom = unpack_float(a_data[3]);
+ highp float a_minzoom = a_zoom[0];
+ highp float a_maxzoom = a_zoom[1];
float size;
// In order to accommodate placing labels around corners in
@@ -68,7 +71,7 @@ void main() {
// currently rendered zoom level if text-size is zoom-dependent.
// Thus, we compensate for this difference by calculating an adjustment
// based on the scale of rendered text size relative to layout text size.
- mediump float layoutSize;
+ highp float layoutSize;
if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {
size = mix(a_size[0], a_size[1], u_size_t) / 10.0;
layoutSize = a_size[2] / 10.0;
@@ -85,12 +88,16 @@ void main() {
float fontScale = u_is_text ? size / 24.0 : size;
- mediump float zoomAdjust = log2(size / layoutSize);
- mediump float adjustedZoom = (u_zoom - zoomAdjust) * 10.0;
+ highp float zoomAdjust = log2(size / layoutSize);
+ highp float adjustedZoom = (u_zoom - zoomAdjust) * 10.0;
// result: z = 0 if a_minzoom <= adjustedZoom < a_maxzoom, and 1 otherwise
- mediump float z = 2.0 - step(a_minzoom, adjustedZoom) - (1.0 - step(a_maxzoom, adjustedZoom));
+ highp float z = 2.0 - step(a_minzoom, adjustedZoom) - (1.0 - step(a_maxzoom, adjustedZoom));
+
+ vec4 projectedPoint = u_matrix * vec4(a_label_pos, 0, 1);
+ highp float camera_to_anchor_distance = projectedPoint.w;
+ highp float perspective_ratio = 1.0 + 0.5*((camera_to_anchor_distance / u_camera_to_center_distance) - 1.0);
- vec2 extrude = fontScale * u_extrude_scale * (a_offset / 64.0);
+ vec2 extrude = fontScale * u_extrude_scale * perspective_ratio * (a_offset / 64.0);
if (u_rotate_with_map) {
gl_Position = u_matrix * vec4(a_pos + extrude, 0, 1);
gl_Position.z += z * gl_Position.w;
@@ -99,7 +106,12 @@ void main() {
}
v_tex = a_tex / u_texsize;
- v_fade_tex = vec2(a_labelminzoom / 255.0, 0.0);
+ // See comments in symbol_sdf.vertex
+ highp float incidence_stretch = camera_to_anchor_distance / (u_camera_to_center_distance * cos(u_pitch));
+ highp float collision_adjustment = max(1.0, incidence_stretch / u_collision_y_stretch);
+
+ highp float perspective_zoom_adjust = log2(perspective_ratio * collision_adjustment) * 10.0;
+ v_fade_tex = vec2((a_labelminzoom + perspective_zoom_adjust) / 255.0, 0.0);
}
)MBGL_SHADER";