summaryrefslogtreecommitdiff
path: root/src/mbgl/shaders/collision_box.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/shaders/collision_box.cpp')
-rw-r--r--src/mbgl/shaders/collision_box.cpp45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/mbgl/shaders/collision_box.cpp b/src/mbgl/shaders/collision_box.cpp
index 5f733c6a1e..9d11640bf4 100644
--- a/src/mbgl/shaders/collision_box.cpp
+++ b/src/mbgl/shaders/collision_box.cpp
@@ -8,49 +8,52 @@ namespace shaders {
const char* collision_box::name = "collision_box";
const char* collision_box::vertexSource = R"MBGL_SHADER(
attribute vec2 a_pos;
+attribute vec2 a_anchor_pos;
attribute vec2 a_extrude;
-attribute vec2 a_data;
+attribute vec2 a_placed;
uniform mat4 u_matrix;
-uniform float u_scale;
+uniform vec2 u_extrude_scale;
+uniform float u_camera_to_center_distance;
-varying float v_max_zoom;
-varying float v_placement_zoom;
+varying float v_placed;
+varying float v_notUsed;
void main() {
- gl_Position = u_matrix * vec4(a_pos + a_extrude / u_scale, 0.0, 1.0);
+ 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 * (u_camera_to_center_distance / camera_to_anchor_distance);
- v_max_zoom = a_data.x;
- v_placement_zoom = a_data.y;
+ gl_Position = u_matrix * vec4(a_pos, 0.0, 1.0);
+ gl_Position.xy += a_extrude * u_extrude_scale * gl_Position.w * collision_perspective_ratio;
+
+ v_placed = a_placed.x;
+ v_notUsed = a_placed.y;
}
)MBGL_SHADER";
const char* collision_box::fragmentSource = R"MBGL_SHADER(
-uniform float u_zoom;
-uniform float u_maxzoom;
-varying float v_max_zoom;
-varying float v_placement_zoom;
+varying float v_placed;
+varying float v_notUsed;
void main() {
float alpha = 0.5;
- gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0) * alpha;
-
- if (v_placement_zoom > u_zoom) {
- gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0) * alpha;
- }
+ // Red = collision, hide label
+ gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0) * alpha;
- if (u_zoom >= v_max_zoom) {
- gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0) * alpha * 0.25;
+ // Blue = no collision, label is showing
+ if (v_placed > 0.5) {
+ gl_FragColor = vec4(0.0, 0.0, 1.0, 0.5) * alpha;
}
- if (v_placement_zoom >= u_maxzoom) {
- gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0) * alpha * 0.2;
+ if (v_notUsed > 0.5) {
+ // This box not used, fade it out
+ gl_FragColor *= .1;
}
}
-
)MBGL_SHADER";
} // namespace shaders