MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fill_extrusion.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 vec3 u_lightcolor;
13 uniform lowp vec3 u_lightpos;
14 uniform lowp float u_lightintensity;
15 uniform float u_vertical_gradient;
16 uniform lowp float u_opacity;
17 
18 layout (location = 0) in vec2 a_pos;
19 layout (location = 1) in vec4 a_normal_ed;
20 out vec4 v_color;
21 
22 #ifndef HAS_UNIFORM_u_base
23 uniform lowp float u_base_t;
24 layout (location = 2) in highp vec2 a_base;
25 #else
26 uniform highp float u_base;
27 #endif
28 #ifndef HAS_UNIFORM_u_height
29 uniform lowp float u_height_t;
30 layout (location = 3) in highp vec2 a_height;
31 #else
32 uniform highp float u_height;
33 #endif
34 
35 #ifndef HAS_UNIFORM_u_color
36 uniform lowp float u_color_t;
37 layout (location = 4) in highp vec4 a_color;
38 #else
39 uniform highp vec4 u_color;
40 #endif
41 
42 void main() {
43  #ifndef HAS_UNIFORM_u_base
44 highp float base = unpack_mix_vec2(a_base, u_base_t);
45 #else
46 highp float base = u_base;
47 #endif
48  #ifndef HAS_UNIFORM_u_height
49 highp float height = unpack_mix_vec2(a_height, u_height_t);
50 #else
51 highp float height = u_height;
52 #endif
53  #ifndef HAS_UNIFORM_u_color
54 highp vec4 color = unpack_mix_color(a_color, u_color_t);
55 #else
56 highp vec4 color = u_color;
57 #endif
58 
59  vec3 normal = a_normal_ed.xyz;
60 
61  base = max(0.0, base);
62  height = max(0.0, height);
63 
64  float t = mod(normal.x, 2.0);
65 
66  gl_Position = u_matrix * vec4(a_pos, t > 0.0 ? height : base, 1);
67 
68  // Relative luminance (how dark/bright is the surface color?)
69  float colorvalue = color.r * 0.2126 + color.g * 0.7152 + color.b * 0.0722;
70 
71  v_color = vec4(0.0, 0.0, 0.0, 1.0);
72 
73  // Add slight ambient lighting so no extrusions are totally black
74  vec4 ambientlight = vec4(0.03, 0.03, 0.03, 1.0);
75  color += ambientlight;
76 
77  // Calculate cos(theta), where theta is the angle between surface normal and diffuse light ray
78  float directional = clamp(dot(normal / 16384.0, u_lightpos), 0.0, 1.0);
79 
80  // Adjust directional so that
81  // the range of values for highlight/shading is narrower
82  // with lower light intensity
83  // and with lighter/brighter surface colors
84  directional = mix((1.0 - u_lightintensity), max((1.0 - colorvalue + u_lightintensity), 1.0), directional);
85 
86  // Add gradient along z axis of side surfaces
87  if (normal.y != 0.0) {
88  // This avoids another branching statement, but multiplies by a constant of 0.84 if no vertical gradient,
89  // and otherwise calculates the gradient based on base + height
90  directional *= (
91  (1.0 - u_vertical_gradient) +
92  (u_vertical_gradient * clamp((t + base) * pow(height / 150.0, 0.5), mix(0.7, 0.98, 1.0 - u_lightintensity), 1.0)));
93  }
94 
95  // Assign final color based on surface + ambient light color, diffuse light directional, and light color
96  // with lower bounds adjusted to hue of light
97  // so that shading is tinted with the complementary (opposite) color to the light color
98  v_color.r += clamp(color.r * directional * u_lightcolor.r, mix(0.0, 0.3, 1.0 - u_lightcolor.r), 1.0);
99  v_color.g += clamp(color.g * directional * u_lightcolor.g, mix(0.0, 0.3, 1.0 - u_lightcolor.g), 1.0);
100  v_color.b += clamp(color.b * directional * u_lightcolor.b, mix(0.0, 0.3, 1.0 - u_lightcolor.b), 1.0);
101  v_color *= u_opacity;
102 }
103 )";
104  static constexpr const char* fragment = R"(in vec4 v_color;
105 
106 void main() {
107  fragColor = v_color;
108 
109 #ifdef OVERDRAW_INSPECTOR
110  fragColor = vec4(1.0);
111 #endif
112 }
113 )";
114 };
115 
116 } // namespace shaders
117 } // 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.