11 static constexpr
const char* vertex = R
"(const float PI = 3.141592653589793;
13 layout (location = 0) in vec4 a_pos_offset;
14 layout (location = 1) in vec4 a_data;
15 layout (location = 2) in vec4 a_pixeloffset;
16 layout (location = 3) in vec3 a_projected_pos;
17 layout (location = 4) in float a_fade_opacity;
19 uniform bool u_is_size_zoom_constant;
20 uniform bool u_is_size_feature_constant;
21 uniform highp float u_size_t; // used to interpolate between zoom stops when size is a composite function
22 uniform highp float u_size; // used when size is both zoom and feature constant
23 uniform highp float u_camera_to_center_distance;
24 uniform highp float u_pitch;
25 uniform bool u_rotate_symbol;
26 uniform highp float u_aspect_ratio;
27 uniform float u_fade_change;
29 uniform mat4 u_matrix;
30 uniform mat4 u_label_plane_matrix;
31 uniform mat4 u_coord_matrix;
33 uniform bool u_is_text;
34 uniform bool u_pitch_with_map;
36 uniform vec2 u_texsize;
39 out float v_fade_opacity;
41 #ifndef HAS_UNIFORM_u_opacity
42 uniform lowp float u_opacity_t;
43 layout (location = 5) in lowp vec2 a_opacity;
44 out lowp float opacity;
46 uniform lowp float u_opacity;
50 #ifndef HAS_UNIFORM_u_opacity
51 opacity = unpack_mix_vec2(a_opacity, u_opacity_t);
53 lowp float opacity = u_opacity;
56 vec2 a_pos = a_pos_offset.xy;
57 vec2 a_offset = a_pos_offset.zw;
59 vec2 a_tex = a_data.xy;
60 vec2 a_size = a_data.zw;
62 float a_size_min = floor(a_size[0] * 0.5);
63 vec2 a_pxoffset = a_pixeloffset.xy;
64 vec2 a_minFontScale = a_pixeloffset.zw / 256.0;
66 highp float segment_angle = -a_projected_pos[2];
69 if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {
70 size = mix(a_size_min, a_size[1], u_size_t) / 128.0;
71 } else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {
72 size = a_size_min / 128.0;
77 vec4 projectedPoint = u_matrix * vec4(a_pos, 0, 1);
78 highp float camera_to_anchor_distance = projectedPoint.w;
79 // See comments in symbol_sdf.vertex
80 highp float distance_ratio = u_pitch_with_map ?
81 camera_to_anchor_distance / u_camera_to_center_distance :
82 u_camera_to_center_distance / camera_to_anchor_distance;
83 highp float perspective_ratio = clamp(
84 0.5 + 0.5 * distance_ratio,
85 0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles
88 size *= perspective_ratio;
90 float fontScale = u_is_text ? size / 24.0 : size;
92 highp float symbol_rotation = 0.0;
93 if (u_rotate_symbol) {
94 // See comments in symbol_sdf.vertex
95 vec4 offsetProjectedPoint = u_matrix * vec4(a_pos + vec2(1, 0), 0, 1);
97 vec2 a = projectedPoint.xy / projectedPoint.w;
98 vec2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
100 symbol_rotation = atan((b.y - a.y) / u_aspect_ratio, b.x - a.x);
103 highp float angle_sin = sin(segment_angle + symbol_rotation);
104 highp float angle_cos = cos(segment_angle + symbol_rotation);
105 mat2 rotation_matrix = mat2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos);
107 vec4 projected_pos = u_label_plane_matrix * vec4(a_projected_pos.xy, 0.0, 1.0);
108 gl_Position = u_coord_matrix * vec4(projected_pos.xy / projected_pos.w + rotation_matrix * (a_offset / 32.0 * max(a_minFontScale, fontScale) + a_pxoffset / 16.0), 0.0, 1.0);
110 v_tex = a_tex / u_texsize;
111 vec2 fade_opacity = unpack_opacity(a_fade_opacity);
112 float fade_change = fade_opacity[1] > 0.5 ? u_fade_change : -u_fade_change;
113 v_fade_opacity = max(0.0, min(1.0, fade_opacity[0] + fade_change));
116 static constexpr
const char* fragment = R
"(uniform sampler2D u_texture;
119 in float v_fade_opacity;
121 #ifndef HAS_UNIFORM_u_opacity
122 in lowp float opacity;
124 uniform lowp float u_opacity;
128 #ifdef HAS_UNIFORM_u_opacity
129 lowp float opacity = u_opacity;
132 lowp float alpha = opacity * v_fade_opacity;
133 fragColor = texture(u_texture, v_tex) * alpha;
135 #ifdef OVERDRAW_INSPECTOR
136 fragColor = vec4(1.0);
@ 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.