MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
collision_box.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"(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;
15 layout (location = 4) in vec2 a_shift;
16 
17 uniform mat4 u_matrix;
18 uniform vec2 u_extrude_scale;
19 uniform float u_camera_to_center_distance;
20 
21 out float v_placed;
22 out float v_notUsed;
23 
24 void main() {
25  vec4 projectedPoint = u_matrix * vec4(a_anchor_pos, 0, 1);
26  highp float camera_to_anchor_distance = projectedPoint.w;
27  highp float collision_perspective_ratio = clamp(
28  0.5 + 0.5 * (u_camera_to_center_distance / camera_to_anchor_distance),
29  0.0, // Prevents oversized near-field boxes in pitched/overzoomed tiles
30  4.0);
31 
32  gl_Position = u_matrix * vec4(a_pos, 0.0, 1.0);
33  gl_Position.xy += (a_extrude + a_shift) * u_extrude_scale * gl_Position.w * collision_perspective_ratio;
34 
35  v_placed = a_placed.x;
36  v_notUsed = a_placed.y;
37 }
38 )";
39  static constexpr const char* fragment = R"(
40 in float v_placed;
41 in float v_notUsed;
42 
43 void main() {
44 
45  float alpha = 0.5;
46 
47  // Red = collision, hide label
48  fragColor = vec4(1.0, 0.0, 0.0, 1.0) * alpha;
49 
50  // Blue = no collision, label is showing
51  if (v_placed > 0.5) {
52  fragColor = vec4(0.0, 0.0, 1.0, 0.5) * alpha;
53  }
54 
55  if (v_notUsed > 0.5) {
56  // This box not used, fade it out
57  fragColor *= .1;
58  }
59 })";
60 };
61 
62 } // namespace shaders
63 } // 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.