MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
raster.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 vec2 u_tl_parent;
13 uniform float u_scale_parent;
14 uniform float u_buffer_scale;
15 
16 layout (location = 0) in vec2 a_pos;
17 layout (location = 1) in vec2 a_texture_pos;
18 
19 out vec2 v_pos0;
20 out vec2 v_pos1;
21 
22 void main() {
23  gl_Position = u_matrix * vec4(a_pos, 0, 1);
24  // We are using Int16 for texture position coordinates to give us enough precision for
25  // fractional coordinates. We use 8192 to scale the texture coordinates in the buffer
26  // as an arbitrarily high number to preserve adequate precision when rendering.
27  // This is also the same value as the EXTENT we are using for our tile buffer pos coordinates,
28  // so math for modifying either is consistent.
29  v_pos0 = (((a_texture_pos / 8192.0) - 0.5) / u_buffer_scale ) + 0.5;
30  v_pos1 = (v_pos0 * u_scale_parent) + u_tl_parent;
31 }
32 )";
33  static constexpr const char* fragment = R"(uniform float u_fade_t;
34 uniform float u_opacity;
35 uniform sampler2D u_image0;
36 uniform sampler2D u_image1;
37 in vec2 v_pos0;
38 in vec2 v_pos1;
39 
40 uniform float u_brightness_low;
41 uniform float u_brightness_high;
42 
43 uniform float u_saturation_factor;
44 uniform float u_contrast_factor;
45 uniform vec3 u_spin_weights;
46 
47 void main() {
48 
49  // read and cross-fade colors from the main and parent tiles
50  vec4 color0 = texture(u_image0, v_pos0);
51  vec4 color1 = texture(u_image1, v_pos1);
52  if (color0.a > 0.0) {
53  color0.rgb = color0.rgb / color0.a;
54  }
55  if (color1.a > 0.0) {
56  color1.rgb = color1.rgb / color1.a;
57  }
58  vec4 color = mix(color0, color1, u_fade_t);
59  color.a *= u_opacity;
60  vec3 rgb = color.rgb;
61 
62  // spin
63  rgb = vec3(
64  dot(rgb, u_spin_weights.xyz),
65  dot(rgb, u_spin_weights.zxy),
66  dot(rgb, u_spin_weights.yzx));
67 
68  // saturation
69  float average = (color.r + color.g + color.b) / 3.0;
70  rgb += (average - rgb) * u_saturation_factor;
71 
72  // contrast
73  rgb = (rgb - 0.5) * u_contrast_factor + 0.5;
74 
75  // brightness
76  vec3 u_high_vec = vec3(u_brightness_low, u_brightness_low, u_brightness_low);
77  vec3 u_low_vec = vec3(u_brightness_high, u_brightness_high, u_brightness_high);
78 
79  fragColor = vec4(mix(u_high_vec, u_low_vec, rgb) * color.a, color.a);
80 
81 #ifdef OVERDRAW_INSPECTOR
82  fragColor = vec4(1.0);
83 #endif
84 }
85 )";
86 };
87 
88 } // namespace shaders
89 } // 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.