[core] De-duplicate shader prelude source
This commit is contained in:
@@ -205,6 +205,8 @@ set(MBGL_CORE_FILES
|
||||
src/mbgl/shaders/line_pattern.hpp
|
||||
src/mbgl/shaders/line_sdf.cpp
|
||||
src/mbgl/shaders/line_sdf.hpp
|
||||
src/mbgl/shaders/preludes.cpp
|
||||
src/mbgl/shaders/preludes.hpp
|
||||
src/mbgl/shaders/raster.cpp
|
||||
src/mbgl/shaders/raster.hpp
|
||||
src/mbgl/shaders/symbol_icon.cpp
|
||||
|
||||
@@ -8,6 +8,41 @@ const outputPath = 'src/mbgl/shaders';
|
||||
|
||||
require('./style-code');
|
||||
|
||||
const vertexPrelude = fs.readFileSync(path.join(inputPath, '_prelude.vertex.glsl'));
|
||||
const fragmentPrelude = fs.readFileSync(path.join(inputPath, '_prelude.fragment.glsl'));
|
||||
|
||||
writeIfModified(path.join(outputPath, 'preludes.hpp'), `// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
extern const char* vertexPrelude;
|
||||
extern const char* fragmentPrelude;
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
`);
|
||||
|
||||
writeIfModified(path.join(outputPath, 'preludes.cpp'), `// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.
|
||||
|
||||
#include <mbgl/shaders/preludes.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* vertexPrelude = R"MBGL_SHADER(
|
||||
${vertexPrelude}
|
||||
)MBGL_SHADER";
|
||||
const char* fragmentPrelude = R"MBGL_SHADER(
|
||||
${fragmentPrelude}
|
||||
)MBGL_SHADER";
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
`);
|
||||
|
||||
[
|
||||
'circle',
|
||||
'collision_box',
|
||||
@@ -34,9 +69,8 @@ require('./style-code');
|
||||
}
|
||||
|
||||
function vertexSource() {
|
||||
const prelude = fs.readFileSync(path.join(inputPath, '_prelude.vertex.glsl'));
|
||||
const source = fs.readFileSync(path.join(inputPath, shaderName + '.vertex.glsl'), 'utf8');
|
||||
return prelude + applyPragmas(source, {
|
||||
return applyPragmas(source, {
|
||||
define: [
|
||||
"uniform lowp float a_{name}_t;",
|
||||
"attribute {precision} {type} a_{name}_min;",
|
||||
@@ -50,9 +84,8 @@ require('./style-code');
|
||||
}
|
||||
|
||||
function fragmentSource() {
|
||||
const prelude = fs.readFileSync(path.join(inputPath, '_prelude.fragment.glsl'));
|
||||
const source = fs.readFileSync(path.join(inputPath, shaderName + '.fragment.glsl'), 'utf8');
|
||||
return prelude + applyPragmas(source, {
|
||||
return applyPragmas(source, {
|
||||
define: [
|
||||
"varying {precision} {type} {name};"
|
||||
],
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <mbgl/programs/program_parameters.hpp>
|
||||
#include <mbgl/programs/attributes.hpp>
|
||||
#include <mbgl/style/paint_property.hpp>
|
||||
#include <mbgl/shaders/preludes.hpp>
|
||||
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
@@ -45,7 +46,7 @@ public:
|
||||
}
|
||||
|
||||
static std::string fragmentSource(const ProgramParameters& parameters) {
|
||||
std::string source = pixelRatioDefine(parameters) + Shaders::fragmentSource;
|
||||
std::string source = pixelRatioDefine(parameters) + shaders::fragmentPrelude + Shaders::fragmentSource;
|
||||
if (parameters.overdraw) {
|
||||
assert(source.find("#ifdef OVERDRAW_INSPECTOR") != std::string::npos);
|
||||
source.replace(source.find_first_of('\n'), 1, "\n#define OVERDRAW_INSPECTOR\n");
|
||||
@@ -54,7 +55,7 @@ public:
|
||||
}
|
||||
|
||||
static std::string vertexSource(const ProgramParameters& parameters) {
|
||||
return pixelRatioDefine(parameters) + Shaders::vertexSource;
|
||||
return pixelRatioDefine(parameters) + shaders::vertexPrelude + Shaders::vertexSource;
|
||||
}
|
||||
|
||||
template <class DrawMode>
|
||||
|
||||
@@ -7,60 +7,6 @@ namespace shaders {
|
||||
|
||||
const char* circle::name = "circle";
|
||||
const char* circle::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 bool u_scale_with_map;
|
||||
uniform vec2 u_extrude_scale;
|
||||
@@ -130,23 +76,6 @@ void main(void) {
|
||||
|
||||
)MBGL_SHADER";
|
||||
const char* circle::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 color;
|
||||
varying mediump float radius;
|
||||
varying lowp float blur;
|
||||
|
||||
@@ -7,60 +7,6 @@ namespace shaders {
|
||||
|
||||
const char* collision_box::name = "collision_box";
|
||||
const char* collision_box::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;
|
||||
attribute vec2 a_extrude;
|
||||
attribute vec2 a_data;
|
||||
@@ -80,23 +26,6 @@ void main() {
|
||||
|
||||
)MBGL_SHADER";
|
||||
const char* collision_box::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_zoom;
|
||||
uniform float u_maxzoom;
|
||||
|
||||
|
||||
@@ -7,60 +7,6 @@ namespace shaders {
|
||||
|
||||
const char* debug::name = "debug";
|
||||
const char* debug::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;
|
||||
@@ -71,23 +17,6 @@ void main() {
|
||||
|
||||
)MBGL_SHADER";
|
||||
const char* debug::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 lowp vec4 u_color;
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -7,60 +7,6 @@ namespace shaders {
|
||||
|
||||
const char* fill::name = "fill";
|
||||
const char* fill::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;
|
||||
@@ -83,23 +29,6 @@ void main() {
|
||||
|
||||
)MBGL_SHADER";
|
||||
const char* fill::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 color;
|
||||
varying lowp float opacity;
|
||||
|
||||
|
||||
@@ -7,60 +7,6 @@ namespace shaders {
|
||||
|
||||
const char* fill_outline::name = "fill_outline";
|
||||
const char* fill_outline::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;
|
||||
@@ -87,23 +33,6 @@ void main() {
|
||||
|
||||
)MBGL_SHADER";
|
||||
const char* fill_outline::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;
|
||||
|
||||
|
||||
@@ -7,60 +7,6 @@ namespace shaders {
|
||||
|
||||
const char* fill_outline_pattern::name = "fill_outline_pattern";
|
||||
const char* fill_outline_pattern::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_world;
|
||||
uniform vec2 u_pattern_size_a;
|
||||
@@ -95,23 +41,6 @@ void main() {
|
||||
|
||||
)MBGL_SHADER";
|
||||
const char* fill_outline_pattern::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 vec2 u_pattern_tl_a;
|
||||
uniform vec2 u_pattern_br_a;
|
||||
uniform vec2 u_pattern_tl_b;
|
||||
|
||||
@@ -7,60 +7,6 @@ namespace shaders {
|
||||
|
||||
const char* fill_pattern::name = "fill_pattern";
|
||||
const char* fill_pattern::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_pattern_size_a;
|
||||
uniform vec2 u_pattern_size_b;
|
||||
@@ -91,23 +37,6 @@ void main() {
|
||||
|
||||
)MBGL_SHADER";
|
||||
const char* fill_pattern::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 vec2 u_pattern_tl_a;
|
||||
uniform vec2 u_pattern_br_a;
|
||||
uniform vec2 u_pattern_tl_b;
|
||||
|
||||
@@ -7,60 +7,6 @@ namespace shaders {
|
||||
|
||||
const char* line::name = "line";
|
||||
const char* line::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;
|
||||
}
|
||||
|
||||
|
||||
// the distance over which the line edge fades out.
|
||||
@@ -164,23 +110,6 @@ void main() {
|
||||
|
||||
)MBGL_SHADER";
|
||||
const char* line::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 color;
|
||||
varying lowp float blur;
|
||||
varying lowp float opacity;
|
||||
|
||||
@@ -7,60 +7,6 @@ namespace shaders {
|
||||
|
||||
const char* line_pattern::name = "line_pattern";
|
||||
const char* line_pattern::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;
|
||||
}
|
||||
// floor(127 / 2) == 63.0
|
||||
// the maximum allowed miter limit is 2.0 at the moment. the extrude normal is
|
||||
// stored in a byte (-128..127). we scale regular normals up to length 63, but
|
||||
@@ -163,23 +109,6 @@ void main() {
|
||||
|
||||
)MBGL_SHADER";
|
||||
const char* line_pattern::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 vec2 u_pattern_size_a;
|
||||
uniform vec2 u_pattern_size_b;
|
||||
uniform vec2 u_pattern_tl_a;
|
||||
|
||||
@@ -7,60 +7,6 @@ namespace shaders {
|
||||
|
||||
const char* line_sdf::name = "line_sdf";
|
||||
const char* line_sdf::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;
|
||||
}
|
||||
// floor(127 / 2) == 63.0
|
||||
// the maximum allowed miter limit is 2.0 at the moment. the extrude normal is
|
||||
// stored in a byte (-128..127). we scale regular normals up to length 63, but
|
||||
@@ -175,23 +121,6 @@ void main() {
|
||||
|
||||
)MBGL_SHADER";
|
||||
const char* line_sdf::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 sampler2D u_image;
|
||||
uniform float u_sdfgamma;
|
||||
|
||||
87
src/mbgl/shaders/preludes.cpp
Normal file
87
src/mbgl/shaders/preludes.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.
|
||||
|
||||
#include <mbgl/shaders/preludes.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* vertexPrelude = 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;
|
||||
}
|
||||
|
||||
)MBGL_SHADER";
|
||||
const char* fragmentPrelude = 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
|
||||
|
||||
)MBGL_SHADER";
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
12
src/mbgl/shaders/preludes.hpp
Normal file
12
src/mbgl/shaders/preludes.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
extern const char* vertexPrelude;
|
||||
extern const char* fragmentPrelude;
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
@@ -7,60 +7,6 @@ namespace shaders {
|
||||
|
||||
const char* raster::name = "raster";
|
||||
const char* raster::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;
|
||||
@@ -80,23 +26,6 @@ void main() {
|
||||
|
||||
)MBGL_SHADER";
|
||||
const char* raster::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;
|
||||
|
||||
@@ -7,60 +7,6 @@ namespace shaders {
|
||||
|
||||
const char* symbol_icon::name = "symbol_icon";
|
||||
const char* symbol_icon::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;
|
||||
attribute vec2 a_offset;
|
||||
attribute vec2 a_texture_pos;
|
||||
@@ -109,23 +55,6 @@ void main() {
|
||||
|
||||
)MBGL_SHADER";
|
||||
const char* symbol_icon::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 sampler2D u_texture;
|
||||
uniform sampler2D u_fadetexture;
|
||||
|
||||
|
||||
@@ -7,60 +7,6 @@ namespace shaders {
|
||||
|
||||
const char* symbol_sdf::name = "symbol_sdf";
|
||||
const char* symbol_sdf::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;
|
||||
}
|
||||
const float PI = 3.141592653589793;
|
||||
|
||||
attribute vec2 a_pos;
|
||||
@@ -172,23 +118,6 @@ void main() {
|
||||
|
||||
)MBGL_SHADER";
|
||||
const char* symbol_sdf::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
|
||||
#define SDF_PX 8.0
|
||||
#define EDGE_GAMMA 0.105/DEVICE_PIXEL_RATIO
|
||||
|
||||
|
||||
Reference in New Issue
Block a user