MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
symbol_icon.hpp
Go to the documentation of this file.
1 // Generated code, do not modify this file!
2 // Generated on 2023-04-05T16:25:15.886Z by mwilsnd using shaders/generate_shader_code.js
3 
4 #pragma once
6 
7 namespace mbgl {
8 namespace shaders {
9 
11  static constexpr const char* vertex = R"(const float PI = 3.141592653589793;
12 
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;
18 
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;
28 
29 uniform mat4 u_matrix;
30 uniform mat4 u_label_plane_matrix;
31 uniform mat4 u_coord_matrix;
32 
33 uniform bool u_is_text;
34 uniform bool u_pitch_with_map;
35 
36 uniform vec2 u_texsize;
37 
38 out vec2 v_tex;
39 out float v_fade_opacity;
40 
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;
45 #else
46 uniform lowp float u_opacity;
47 #endif
48 
49 void main() {
50  #ifndef HAS_UNIFORM_u_opacity
51 opacity = unpack_mix_vec2(a_opacity, u_opacity_t);
52 #else
53 lowp float opacity = u_opacity;
54 #endif
55 
56  vec2 a_pos = a_pos_offset.xy;
57  vec2 a_offset = a_pos_offset.zw;
58 
59  vec2 a_tex = a_data.xy;
60  vec2 a_size = a_data.zw;
61 
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;
65 
66  highp float segment_angle = -a_projected_pos[2];
67  float size;
68 
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;
73  } else {
74  size = u_size;
75  }
76 
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
86  4.0);
87 
88  size *= perspective_ratio;
89 
90  float fontScale = u_is_text ? size / 24.0 : size;
91 
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);
96 
97  vec2 a = projectedPoint.xy / projectedPoint.w;
98  vec2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
99 
100  symbol_rotation = atan((b.y - a.y) / u_aspect_ratio, b.x - a.x);
101  }
102 
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);
106 
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);
109 
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));
114 }
115 )";
116  static constexpr const char* fragment = R"(uniform sampler2D u_texture;
117 
118 in vec2 v_tex;
119 in float v_fade_opacity;
120 
121 #ifndef HAS_UNIFORM_u_opacity
122 in lowp float opacity;
123 #else
124 uniform lowp float u_opacity;
125 #endif
126 
127 void main() {
128  #ifdef HAS_UNIFORM_u_opacity
129 lowp float opacity = u_opacity;
130 #endif
131 
132  lowp float alpha = opacity * v_fade_opacity;
133  fragColor = texture(u_texture, v_tex) * alpha;
134 
135 #ifdef OVERDRAW_INSPECTOR
136  fragColor = vec4(1.0);
137 #endif
138 }
139 )";
140 };
141 
142 } // namespace shaders
143 } // namespace mbgl
@ OpenGL
The OpenGL API backend.
BuiltIn
This enum is used with the ShaderSource template to select source code for the desired program and gr...
Definition: actor.hpp:15
Select shader source based on a program type and a desired graphics API.