diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-02-03 13:51:51 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-02-07 11:27:36 -0600 |
commit | 9f2f7ddd12a4aaab0faddbe60cfb7c1e526fa7ff (patch) | |
tree | 4350fce48dd97f6088dae94245265cd900f3de1f /src/mbgl/shaders/fill_outline.hpp | |
parent | d9f2cd5df50f5eee141b0a17e4e2ec8a4a7c4f78 (diff) | |
download | qtlocation-mapboxgl-9f2f7ddd12a4aaab0faddbe60cfb7c1e526fa7ff.tar.gz |
[core] Check in generated shader code
One step toward eliminating the node/npm dependency for platforms other than node.
Diffstat (limited to 'src/mbgl/shaders/fill_outline.hpp')
-rw-r--r-- | src/mbgl/shaders/fill_outline.hpp | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/src/mbgl/shaders/fill_outline.hpp b/src/mbgl/shaders/fill_outline.hpp new file mode 100644 index 0000000000..92e60b0328 --- /dev/null +++ b/src/mbgl/shaders/fill_outline.hpp @@ -0,0 +1,131 @@ +#pragma once + +// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED. + +#include <mbgl/gl/gl.hpp> + +namespace mbgl { +namespace shaders { + +class fill_outline { +public: + static constexpr const char* name = "fill_outline"; + 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; +} +attribute vec2 a_pos; + +uniform mat4 u_matrix; +uniform vec2 u_world; + +varying vec2 v_pos; + +uniform lowp float a_outline_color_t; +attribute lowp vec4 a_outline_color_min; +attribute lowp vec4 a_outline_color_max; +varying lowp vec4 outline_color; +uniform lowp float a_opacity_t; +attribute lowp float a_opacity_min; +attribute lowp float a_opacity_max; +varying lowp float opacity; + +void main() { + outline_color = mix(a_outline_color_min, a_outline_color_max, a_outline_color_t); + opacity = mix(a_opacity_min, a_opacity_max, a_opacity_t); + + gl_Position = u_matrix * vec4(a_pos, 0, 1); + v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world; +} +)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 +varying lowp vec4 outline_color; +varying lowp float opacity; + +varying vec2 v_pos; + +void main() { + + + + float dist = length(v_pos - gl_FragCoord.xy); + float alpha = smoothstep(1.0, 0.0, dist); + gl_FragColor = outline_color * (alpha * opacity); + +#ifdef OVERDRAW_INSPECTOR + gl_FragColor = vec4(1.0); +#endif +} +)MBGL_SHADER"; +}; + +} // namespace shaders +} // namespace mbgl |