MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
circle.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"(uniform mat4 u_matrix;
12 uniform bool u_scale_with_map;
13 uniform bool u_pitch_with_map;
14 uniform vec2 u_extrude_scale;
15 uniform lowp float u_device_pixel_ratio;
16 uniform highp float u_camera_to_center_distance;
17 
18 layout (location = 0) in vec2 a_pos;
19 out vec3 v_data;
20 
21 #ifndef HAS_UNIFORM_u_color
22 uniform lowp float u_color_t;
23 layout (location = 1) in highp vec4 a_color;
24 out highp vec4 color;
25 #else
26 uniform highp vec4 u_color;
27 #endif
28 #ifndef HAS_UNIFORM_u_radius
29 uniform lowp float u_radius_t;
30 layout (location = 2) in mediump vec2 a_radius;
31 out mediump float radius;
32 #else
33 uniform mediump float u_radius;
34 #endif
35 #ifndef HAS_UNIFORM_u_blur
36 uniform lowp float u_blur_t;
37 layout (location = 3) in lowp vec2 a_blur;
38 out lowp float blur;
39 #else
40 uniform lowp float u_blur;
41 #endif
42 #ifndef HAS_UNIFORM_u_opacity
43 uniform lowp float u_opacity_t;
44 layout (location = 4) in lowp vec2 a_opacity;
45 out lowp float opacity;
46 #else
47 uniform lowp float u_opacity;
48 #endif
49 #ifndef HAS_UNIFORM_u_stroke_color
50 uniform lowp float u_stroke_color_t;
51 layout (location = 5) in highp vec4 a_stroke_color;
52 out highp vec4 stroke_color;
53 #else
54 uniform highp vec4 u_stroke_color;
55 #endif
56 #ifndef HAS_UNIFORM_u_stroke_width
57 uniform lowp float u_stroke_width_t;
58 layout (location = 6) in mediump vec2 a_stroke_width;
59 out mediump float stroke_width;
60 #else
61 uniform mediump float u_stroke_width;
62 #endif
63 #ifndef HAS_UNIFORM_u_stroke_opacity
64 uniform lowp float u_stroke_opacity_t;
65 layout (location = 7) in lowp vec2 a_stroke_opacity;
66 out lowp float stroke_opacity;
67 #else
68 uniform lowp float u_stroke_opacity;
69 #endif
70 
71 void main(void) {
72  #ifndef HAS_UNIFORM_u_color
73 color = unpack_mix_color(a_color, u_color_t);
74 #else
75 highp vec4 color = u_color;
76 #endif
77  #ifndef HAS_UNIFORM_u_radius
78 radius = unpack_mix_vec2(a_radius, u_radius_t);
79 #else
80 mediump float radius = u_radius;
81 #endif
82  #ifndef HAS_UNIFORM_u_blur
83 blur = unpack_mix_vec2(a_blur, u_blur_t);
84 #else
85 lowp float blur = u_blur;
86 #endif
87  #ifndef HAS_UNIFORM_u_opacity
88 opacity = unpack_mix_vec2(a_opacity, u_opacity_t);
89 #else
90 lowp float opacity = u_opacity;
91 #endif
92  #ifndef HAS_UNIFORM_u_stroke_color
93 stroke_color = unpack_mix_color(a_stroke_color, u_stroke_color_t);
94 #else
95 highp vec4 stroke_color = u_stroke_color;
96 #endif
97  #ifndef HAS_UNIFORM_u_stroke_width
98 stroke_width = unpack_mix_vec2(a_stroke_width, u_stroke_width_t);
99 #else
100 mediump float stroke_width = u_stroke_width;
101 #endif
102  #ifndef HAS_UNIFORM_u_stroke_opacity
103 stroke_opacity = unpack_mix_vec2(a_stroke_opacity, u_stroke_opacity_t);
104 #else
105 lowp float stroke_opacity = u_stroke_opacity;
106 #endif
107 
108  // unencode the extrusion vector that we snuck into the a_pos vector
109  vec2 extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0);
110 
111  // multiply a_pos by 0.5, since we had it * 2 in order to sneak
112  // in extrusion data
113  vec2 circle_center = floor(a_pos * 0.5);
114  if (u_pitch_with_map) {
115  vec2 corner_position = circle_center;
116  if (u_scale_with_map) {
117  corner_position += extrude * (radius + stroke_width) * u_extrude_scale;
118  } else {
119  // Pitching the circle with the map effectively scales it with the map
120  // To counteract the effect for pitch-scale: viewport, we rescale the
121  // whole circle based on the pitch scaling effect at its central point
122  vec4 projected_center = u_matrix * vec4(circle_center, 0, 1);
123  corner_position += extrude * (radius + stroke_width) * u_extrude_scale * (projected_center.w / u_camera_to_center_distance);
124  }
125 
126  gl_Position = u_matrix * vec4(corner_position, 0, 1);
127  } else {
128  gl_Position = u_matrix * vec4(circle_center, 0, 1);
129 
130  if (u_scale_with_map) {
131  gl_Position.xy += extrude * (radius + stroke_width) * u_extrude_scale * u_camera_to_center_distance;
132  } else {
133  gl_Position.xy += extrude * (radius + stroke_width) * u_extrude_scale * gl_Position.w;
134  }
135  }
136 
137  // This is a minimum blur distance that serves as a faux-antialiasing for
138  // the circle. since blur is a ratio of the circle's size and the intent is
139  // to keep the blur at roughly 1px, the two are inversely related.
140  lowp float antialiasblur = 1.0 / u_device_pixel_ratio / (radius + stroke_width);
141 
142  v_data = vec3(extrude.x, extrude.y, antialiasblur);
143 }
144 )";
145  static constexpr const char* fragment = R"(in vec3 v_data;
146 
147 #ifndef HAS_UNIFORM_u_color
148 in highp vec4 color;
149 #else
150 uniform highp vec4 u_color;
151 #endif
152 #ifndef HAS_UNIFORM_u_radius
153 in mediump float radius;
154 #else
155 uniform mediump float u_radius;
156 #endif
157 #ifndef HAS_UNIFORM_u_blur
158 in lowp float blur;
159 #else
160 uniform lowp float u_blur;
161 #endif
162 #ifndef HAS_UNIFORM_u_opacity
163 in lowp float opacity;
164 #else
165 uniform lowp float u_opacity;
166 #endif
167 #ifndef HAS_UNIFORM_u_stroke_color
168 in highp vec4 stroke_color;
169 #else
170 uniform highp vec4 u_stroke_color;
171 #endif
172 #ifndef HAS_UNIFORM_u_stroke_width
173 in mediump float stroke_width;
174 #else
175 uniform mediump float u_stroke_width;
176 #endif
177 #ifndef HAS_UNIFORM_u_stroke_opacity
178 in lowp float stroke_opacity;
179 #else
180 uniform lowp float u_stroke_opacity;
181 #endif
182 
183 void main() {
184  #ifdef HAS_UNIFORM_u_color
185 highp vec4 color = u_color;
186 #endif
187  #ifdef HAS_UNIFORM_u_radius
188 mediump float radius = u_radius;
189 #endif
190  #ifdef HAS_UNIFORM_u_blur
191 lowp float blur = u_blur;
192 #endif
193  #ifdef HAS_UNIFORM_u_opacity
194 lowp float opacity = u_opacity;
195 #endif
196  #ifdef HAS_UNIFORM_u_stroke_color
197 highp vec4 stroke_color = u_stroke_color;
198 #endif
199  #ifdef HAS_UNIFORM_u_stroke_width
200 mediump float stroke_width = u_stroke_width;
201 #endif
202  #ifdef HAS_UNIFORM_u_stroke_opacity
203 lowp float stroke_opacity = u_stroke_opacity;
204 #endif
205 
206  vec2 extrude = v_data.xy;
207  float extrude_length = length(extrude);
208 
209  lowp float antialiasblur = v_data.z;
210  float antialiased_blur = -max(blur, antialiasblur);
211 
212  float opacity_t = smoothstep(0.0, antialiased_blur, extrude_length - 1.0);
213 
214  float color_t = stroke_width < 0.01 ? 0.0 : smoothstep(
215  antialiased_blur,
216  0.0,
217  extrude_length - radius / (radius + stroke_width)
218  );
219 
220  fragColor = opacity_t * mix(color * opacity, stroke_color * stroke_opacity, color_t);
221 
222 #ifdef OVERDRAW_INSPECTOR
223  fragColor = vec4(1.0);
224 #endif
225 }
226 )";
227 };
228 
229 } // namespace shaders
230 } // 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.