11 static constexpr
const char* vertex = R
"(layout (location = 0) in vec2 a_pos;
12 layout (location = 1) in vec2 a_anchor_pos;
13 layout (location = 2) in vec2 a_extrude;
14 layout (location = 3) in vec2 a_placed;
16 uniform mat4 u_matrix;
17 uniform vec2 u_extrude_scale;
18 uniform float u_camera_to_center_distance;
24 out vec2 v_extrude_scale;
27 vec4 projectedPoint = u_matrix * vec4(a_anchor_pos, 0, 1);
28 highp float camera_to_anchor_distance = projectedPoint.w;
29 highp float collision_perspective_ratio = clamp(
30 0.5 + 0.5 * (u_camera_to_center_distance / camera_to_anchor_distance),
31 0.0, // Prevents oversized near-field circles in pitched/overzoomed tiles
34 gl_Position = u_matrix * vec4(a_pos, 0.0, 1.0);
36 highp float padding_factor = 1.2; // Pad the vertices slightly to make room for anti-alias blur
37 gl_Position.xy += a_extrude * u_extrude_scale * padding_factor * gl_Position.w * collision_perspective_ratio;
39 v_placed = a_placed.x;
40 v_notUsed = a_placed.y;
41 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
43 v_extrude = a_extrude * padding_factor;
44 v_extrude_scale = u_extrude_scale * u_camera_to_center_distance * collision_perspective_ratio;
47 static constexpr
const char* fragment = R
"(uniform float u_overscale_factor;
53 in vec2 v_extrude_scale;
58 // Red = collision, hide label
59 vec4 color = vec4(1.0, 0.0, 0.0, 1.0) * alpha;
61 // Blue = no collision, label is showing
63 color = vec4(0.0, 0.0, 1.0, 0.5) * alpha;
66 if (v_notUsed > 0.5) {
67 // This box not used, fade it out
71 float extrude_scale_length = length(v_extrude_scale);
72 float extrude_length = length(v_extrude) * extrude_scale_length;
73 float stroke_width = 15.0 * extrude_scale_length / u_overscale_factor;
74 float radius = v_radius * extrude_scale_length;
76 float distance_to_edge = abs(extrude_length - radius);
77 float opacity_t = smoothstep(-stroke_width, 0.0, -distance_to_edge);
79 fragColor = opacity_t * color;
@ OpenGL
The OpenGL API backend.
BuiltIn
This enum is used with the ShaderSource template to select source code for the desired program and gr...
Select shader source based on a program type and a desired graphics API.