MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
prelude.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"(#ifdef GL_ES
12 precision highp float;
13 #else
14 
15 #if !defined(lowp)
16 #define lowp
17 #endif
18 
19 #if !defined(mediump)
20 #define mediump
21 #endif
22 
23 #if !defined(highp)
24 #define highp
25 #endif
26 
27 #endif
28 
29 // Unpack a pair of values that have been packed into a single float.
30 // The packed values are assumed to be 8-bit unsigned integers, and are
31 // packed like so:
32 // packedValue = floor(input[0]) * 256 + input[1],
33 vec2 unpack_float(const float packedValue) {
34  int packedIntValue = int(packedValue);
35  int v0 = packedIntValue / 256;
36  return vec2(v0, packedIntValue - v0 * 256);
37 }
38 
39 vec2 unpack_opacity(const float packedOpacity) {
40  int intOpacity = int(packedOpacity) / 2;
41  return vec2(float(intOpacity) / 127.0, mod(packedOpacity, 2.0));
42 }
43 
44 // To minimize the number of attributes needed, we encode a 4-component
45 // color into a pair of floats (i.e. a vec2) as follows:
46 // [ floor(color.r * 255) * 256 + color.g * 255,
47 // floor(color.b * 255) * 256 + color.g * 255 ]
48 vec4 decode_color(const vec2 encodedColor) {
49  return vec4(
50  unpack_float(encodedColor[0]) / 255.0,
51  unpack_float(encodedColor[1]) / 255.0
52  );
53 }
54 
55 // Unpack a pair of paint values and interpolate between them.
56 float unpack_mix_vec2(const vec2 packedValue, const float t) {
57  return mix(packedValue[0], packedValue[1], t);
58 }
59 
60 // Unpack a pair of paint values and interpolate between them.
61 vec4 unpack_mix_color(const vec4 packedColors, const float t) {
62  vec4 minColor = decode_color(vec2(packedColors[0], packedColors[1]));
63  vec4 maxColor = decode_color(vec2(packedColors[2], packedColors[3]));
64  return mix(minColor, maxColor, t);
65 }
66 
67 // The offset depends on how many pixels are between the world origin and the edge of the tile:
68 // vec2 offset = mod(pixel_coord, size)
69 //
70 // At high zoom levels there are a ton of pixels between the world origin and the edge of the tile.
71 // The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that.
72 //
73 // The pixel_coord is passed in as two 16 bit values:
74 // pixel_coord_upper = floor(pixel_coord / 2^16)
75 // pixel_coord_lower = mod(pixel_coord, 2^16)
76 //
77 // The offset is calculated in a series of steps that should preserve this precision:
78 vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower,
79  const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) {
80 
81  vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size);
82  return (tile_units_to_pixels * pos + offset) / pattern_size;
83 }
84 )";
85  static constexpr const char* fragment = R"(#ifdef GL_ES
86 precision mediump float;
87 #else
88 
89 #if !defined(lowp)
90 #define lowp
91 #endif
92 
93 #if !defined(mediump)
94 #define mediump
95 #endif
96 
97 #if !defined(highp)
98 #define highp
99 #endif
100 
101 #endif
102 
103 out highp vec4 fragColor;
104 )";
105 };
106 
107 } // namespace shaders
108 } // 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.