summaryrefslogtreecommitdiff
path: root/src/mbgl/shaders/raster.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/shaders/raster.hpp')
-rw-r--r--src/mbgl/shaders/raster.hpp153
1 files changed, 153 insertions, 0 deletions
diff --git a/src/mbgl/shaders/raster.hpp b/src/mbgl/shaders/raster.hpp
new file mode 100644
index 0000000000..6f65a7a79d
--- /dev/null
+++ b/src/mbgl/shaders/raster.hpp
@@ -0,0 +1,153 @@
+#pragma once
+
+// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.
+
+#include <mbgl/gl/gl.hpp>
+
+namespace mbgl {
+namespace shaders {
+
+class raster {
+public:
+ static constexpr const char* name = "raster";
+ static constexpr const char* vertexSource = R"MBGL_SHADER(
+#ifdef GL_ES
+precision highp float;
+#else
+
+#if !defined(lowp)
+#define lowp
+#endif
+
+#if !defined(mediump)
+#define mediump
+#endif
+
+#if !defined(highp)
+#define highp
+#endif
+
+#endif
+
+float evaluate_zoom_function_1(const vec4 values, const float t) {
+ if (t < 1.0) {
+ return mix(values[0], values[1], t);
+ } else if (t < 2.0) {
+ return mix(values[1], values[2], t - 1.0);
+ } else {
+ return mix(values[2], values[3], t - 2.0);
+ }
+}
+vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) {
+ if (t < 1.0) {
+ return mix(value0, value1, t);
+ } else if (t < 2.0) {
+ return mix(value1, value2, t - 1.0);
+ } else {
+ return mix(value2, value3, t - 2.0);
+ }
+}
+
+// The offset depends on how many pixels are between the world origin and the edge of the tile:
+// vec2 offset = mod(pixel_coord, size)
+//
+// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile.
+// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that.
+//
+// The pixel_coord is passed in as two 16 bit values:
+// pixel_coord_upper = floor(pixel_coord / 2^16)
+// pixel_coord_lower = mod(pixel_coord, 2^16)
+//
+// The offset is calculated in a series of steps that should preserve this precision:
+vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower,
+ const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) {
+
+ vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size);
+ return (tile_units_to_pixels * pos + offset) / pattern_size;
+}
+uniform mat4 u_matrix;
+uniform vec2 u_tl_parent;
+uniform float u_scale_parent;
+uniform float u_buffer_scale;
+
+attribute vec2 a_pos;
+attribute vec2 a_texture_pos;
+
+varying vec2 v_pos0;
+varying vec2 v_pos1;
+
+void main() {
+ gl_Position = u_matrix * vec4(a_pos, 0, 1);
+ v_pos0 = (((a_texture_pos / 32767.0) - 0.5) / u_buffer_scale ) + 0.5;
+ v_pos1 = (v_pos0 * u_scale_parent) + u_tl_parent;
+}
+)MBGL_SHADER";
+ static constexpr const char* fragmentSource = R"MBGL_SHADER(
+#ifdef GL_ES
+precision mediump float;
+#else
+
+#if !defined(lowp)
+#define lowp
+#endif
+
+#if !defined(mediump)
+#define mediump
+#endif
+
+#if !defined(highp)
+#define highp
+#endif
+
+#endif
+uniform float u_fade_t;
+uniform float u_opacity;
+uniform sampler2D u_image0;
+uniform sampler2D u_image1;
+varying vec2 v_pos0;
+varying vec2 v_pos1;
+
+uniform float u_brightness_low;
+uniform float u_brightness_high;
+
+uniform float u_saturation_factor;
+uniform float u_contrast_factor;
+uniform vec3 u_spin_weights;
+
+void main() {
+
+ // read and cross-fade colors from the main and parent tiles
+ vec4 color0 = texture2D(u_image0, v_pos0);
+ vec4 color1 = texture2D(u_image1, v_pos1);
+ vec4 color = mix(color0, color1, u_fade_t);
+ color.a *= u_opacity;
+ vec3 rgb = color.rgb;
+
+ // spin
+ rgb = vec3(
+ dot(rgb, u_spin_weights.xyz),
+ dot(rgb, u_spin_weights.zxy),
+ dot(rgb, u_spin_weights.yzx));
+
+ // saturation
+ float average = (color.r + color.g + color.b) / 3.0;
+ rgb += (average - rgb) * u_saturation_factor;
+
+ // contrast
+ rgb = (rgb - 0.5) * u_contrast_factor + 0.5;
+
+ // brightness
+ vec3 u_high_vec = vec3(u_brightness_low, u_brightness_low, u_brightness_low);
+ vec3 u_low_vec = vec3(u_brightness_high, u_brightness_high, u_brightness_high);
+
+ gl_FragColor = vec4(mix(u_high_vec, u_low_vec, rgb) * color.a, color.a);
+
+#ifdef OVERDRAW_INSPECTOR
+ gl_FragColor = vec4(1.0);
+#endif
+}
+)MBGL_SHADER";
+};
+
+} // namespace shaders
+} // namespace mbgl