summaryrefslogtreecommitdiff
path: root/src/mbgl/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/shaders')
-rw-r--r--src/mbgl/shaders/fill_extrusion_pattern.cpp5
-rw-r--r--src/mbgl/shaders/fill_outline.cpp2
-rw-r--r--src/mbgl/shaders/fill_outline_pattern.cpp7
-rw-r--r--src/mbgl/shaders/fill_pattern.cpp5
-rw-r--r--src/mbgl/shaders/line.cpp18
-rw-r--r--src/mbgl/shaders/line_pattern.cpp23
-rw-r--r--src/mbgl/shaders/line_sdf.cpp59
7 files changed, 97 insertions, 22 deletions
diff --git a/src/mbgl/shaders/fill_extrusion_pattern.cpp b/src/mbgl/shaders/fill_extrusion_pattern.cpp
index 66c24b1bb0..2681973af6 100644
--- a/src/mbgl/shaders/fill_extrusion_pattern.cpp
+++ b/src/mbgl/shaders/fill_extrusion_pattern.cpp
@@ -93,6 +93,7 @@ uniform vec2 u_pattern_tl_a;
uniform vec2 u_pattern_br_a;
uniform vec2 u_pattern_tl_b;
uniform vec2 u_pattern_br_b;
+uniform vec2 u_texsize;
uniform float u_mix;
uniform sampler2D u_image;
@@ -125,11 +126,11 @@ void main() {
#endif
vec2 imagecoord = mod(v_pos_a, 1.0);
- vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, imagecoord);
+ vec2 pos = mix(u_pattern_tl_a / u_texsize, u_pattern_br_a / u_texsize, imagecoord);
vec4 color1 = texture2D(u_image, pos);
vec2 imagecoord_b = mod(v_pos_b, 1.0);
- vec2 pos2 = mix(u_pattern_tl_b, u_pattern_br_b, imagecoord_b);
+ vec2 pos2 = mix(u_pattern_tl_b / u_texsize, u_pattern_br_b / u_texsize, imagecoord_b);
vec4 color2 = texture2D(u_image, pos2);
vec4 mixedColor = mix(color1, color2, u_mix);
diff --git a/src/mbgl/shaders/fill_outline.cpp b/src/mbgl/shaders/fill_outline.cpp
index 45bc716be3..18a4d8c0a8 100644
--- a/src/mbgl/shaders/fill_outline.cpp
+++ b/src/mbgl/shaders/fill_outline.cpp
@@ -77,7 +77,7 @@ void main() {
#endif
float dist = length(v_pos - gl_FragCoord.xy);
- float alpha = smoothstep(1.0, 0.0, dist);
+ float alpha = 1.0 - smoothstep(0.0, 1.0, dist);
gl_FragColor = outline_color * (alpha * opacity);
#ifdef OVERDRAW_INSPECTOR
diff --git a/src/mbgl/shaders/fill_outline_pattern.cpp b/src/mbgl/shaders/fill_outline_pattern.cpp
index 5315709e3a..68e69c2135 100644
--- a/src/mbgl/shaders/fill_outline_pattern.cpp
+++ b/src/mbgl/shaders/fill_outline_pattern.cpp
@@ -54,6 +54,7 @@ uniform vec2 u_pattern_tl_a;
uniform vec2 u_pattern_br_a;
uniform vec2 u_pattern_tl_b;
uniform vec2 u_pattern_br_b;
+uniform vec2 u_texsize;
uniform float u_mix;
uniform sampler2D u_image;
@@ -76,17 +77,17 @@ void main() {
#endif
vec2 imagecoord = mod(v_pos_a, 1.0);
- vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, imagecoord);
+ vec2 pos = mix(u_pattern_tl_a / u_texsize, u_pattern_br_a / u_texsize, imagecoord);
vec4 color1 = texture2D(u_image, pos);
vec2 imagecoord_b = mod(v_pos_b, 1.0);
- vec2 pos2 = mix(u_pattern_tl_b, u_pattern_br_b, imagecoord_b);
+ vec2 pos2 = mix(u_pattern_tl_b / u_texsize, u_pattern_br_b / u_texsize, imagecoord_b);
vec4 color2 = texture2D(u_image, pos2);
// find distance to outline for alpha interpolation
float dist = length(v_pos - gl_FragCoord.xy);
- float alpha = smoothstep(1.0, 0.0, dist);
+ float alpha = 1.0 - smoothstep(0.0, 1.0, dist);
gl_FragColor = mix(color1, color2, u_mix) * alpha * opacity;
diff --git a/src/mbgl/shaders/fill_pattern.cpp b/src/mbgl/shaders/fill_pattern.cpp
index dd99e4efff..f6f9e2fbff 100644
--- a/src/mbgl/shaders/fill_pattern.cpp
+++ b/src/mbgl/shaders/fill_pattern.cpp
@@ -50,6 +50,7 @@ uniform vec2 u_pattern_tl_a;
uniform vec2 u_pattern_br_a;
uniform vec2 u_pattern_tl_b;
uniform vec2 u_pattern_br_b;
+uniform vec2 u_texsize;
uniform float u_mix;
uniform sampler2D u_image;
@@ -71,11 +72,11 @@ void main() {
#endif
vec2 imagecoord = mod(v_pos_a, 1.0);
- vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, imagecoord);
+ vec2 pos = mix(u_pattern_tl_a / u_texsize, u_pattern_br_a / u_texsize, imagecoord);
vec4 color1 = texture2D(u_image, pos);
vec2 imagecoord_b = mod(v_pos_b, 1.0);
- vec2 pos2 = mix(u_pattern_tl_b, u_pattern_br_b, imagecoord_b);
+ vec2 pos2 = mix(u_pattern_tl_b / u_texsize, u_pattern_br_b / u_texsize, imagecoord_b);
vec4 color2 = texture2D(u_image, pos2);
gl_FragColor = mix(color1, color2, u_mix) * opacity;
diff --git a/src/mbgl/shaders/line.cpp b/src/mbgl/shaders/line.cpp
index dce6046257..1eb92c4b71 100644
--- a/src/mbgl/shaders/line.cpp
+++ b/src/mbgl/shaders/line.cpp
@@ -26,7 +26,6 @@ attribute vec4 a_data;
uniform mat4 u_matrix;
uniform mediump float u_ratio;
-uniform mediump float u_width;
uniform vec2 u_gl_units_to_pixels;
varying vec2 v_normal;
@@ -72,6 +71,13 @@ attribute lowp vec2 a_offset;
uniform lowp float u_offset;
#endif
+#ifndef HAS_UNIFORM_u_width
+uniform lowp float a_width_t;
+attribute mediump vec2 a_width;
+#else
+uniform mediump float u_width;
+#endif
+
void main() {
#ifndef HAS_UNIFORM_u_color
@@ -104,6 +110,12 @@ void main() {
lowp float offset = u_offset;
#endif
+#ifndef HAS_UNIFORM_u_width
+ mediump float width = unpack_mix_vec2(a_width, a_width_t);
+#else
+ mediump float width = u_width;
+#endif
+
vec2 a_extrude = a_data.xy - 128.0;
float a_direction = mod(a_data.z, 4.0) - 1.0;
@@ -119,11 +131,11 @@ void main() {
// these transformations used to be applied in the JS and native code bases.
// moved them into the shader for clarity and simplicity.
gapwidth = gapwidth / 2.0;
- float width = u_width / 2.0;
+ float halfwidth = width / 2.0;
offset = -1.0 * offset;
float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0);
- float outset = gapwidth + width * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING;
+ float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING;
// Scale the extrusion vector down to a normal and then up by the line width
// of this vertex.
diff --git a/src/mbgl/shaders/line_pattern.cpp b/src/mbgl/shaders/line_pattern.cpp
index 1c07b4f515..222042a13c 100644
--- a/src/mbgl/shaders/line_pattern.cpp
+++ b/src/mbgl/shaders/line_pattern.cpp
@@ -28,7 +28,6 @@ attribute vec4 a_data;
uniform mat4 u_matrix;
uniform mediump float u_ratio;
-uniform mediump float u_width;
uniform vec2 u_gl_units_to_pixels;
varying vec2 v_normal;
@@ -67,6 +66,13 @@ attribute mediump vec2 a_gapwidth;
uniform mediump float u_gapwidth;
#endif
+#ifndef HAS_UNIFORM_u_width
+uniform lowp float a_width_t;
+attribute mediump vec2 a_width;
+#else
+uniform mediump float u_width;
+#endif
+
void main() {
#ifndef HAS_UNIFORM_u_blur
@@ -93,6 +99,12 @@ void main() {
mediump float gapwidth = u_gapwidth;
#endif
+#ifndef HAS_UNIFORM_u_width
+ mediump float width = unpack_mix_vec2(a_width, a_width_t);
+#else
+ mediump float width = u_width;
+#endif
+
vec2 a_extrude = a_data.xy - 128.0;
float a_direction = mod(a_data.z, 4.0) - 1.0;
float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE;
@@ -108,11 +120,11 @@ void main() {
// these transformations used to be applied in the JS and native code bases.
// moved them into the shader for clarity and simplicity.
gapwidth = gapwidth / 2.0;
- float width = u_width / 2.0;
+ float halfwidth = width / 2.0;
offset = -1.0 * offset;
float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0);
- float outset = gapwidth + width * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING;
+ float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING;
// Scale the extrusion vector down to a normal and then up by the line width
// of this vertex.
@@ -149,6 +161,7 @@ uniform vec2 u_pattern_tl_a;
uniform vec2 u_pattern_br_a;
uniform vec2 u_pattern_tl_b;
uniform vec2 u_pattern_br_b;
+uniform vec2 u_texsize;
uniform float u_fade;
uniform sampler2D u_image;
@@ -194,8 +207,8 @@ void main() {
float x_b = mod(v_linesofar / u_pattern_size_b.x, 1.0);
float y_a = 0.5 + (v_normal.y * v_width2.s / u_pattern_size_a.y);
float y_b = 0.5 + (v_normal.y * v_width2.s / u_pattern_size_b.y);
- vec2 pos_a = mix(u_pattern_tl_a, u_pattern_br_a, vec2(x_a, y_a));
- vec2 pos_b = mix(u_pattern_tl_b, u_pattern_br_b, vec2(x_b, y_b));
+ vec2 pos_a = mix(u_pattern_tl_a / u_texsize, u_pattern_br_a / u_texsize, vec2(x_a, y_a));
+ vec2 pos_b = mix(u_pattern_tl_b / u_texsize, u_pattern_br_b / u_texsize, vec2(x_b, y_b));
vec4 color = mix(texture2D(u_image, pos_a), texture2D(u_image, pos_b), u_fade);
diff --git a/src/mbgl/shaders/line_sdf.cpp b/src/mbgl/shaders/line_sdf.cpp
index b37bf688d4..168f4ca98d 100644
--- a/src/mbgl/shaders/line_sdf.cpp
+++ b/src/mbgl/shaders/line_sdf.cpp
@@ -33,7 +33,6 @@ uniform float u_tex_y_a;
uniform vec2 u_patternscale_b;
uniform float u_tex_y_b;
uniform vec2 u_gl_units_to_pixels;
-uniform mediump float u_width;
varying vec2 v_normal;
varying vec2 v_width2;
@@ -80,6 +79,22 @@ attribute lowp vec2 a_offset;
uniform lowp float u_offset;
#endif
+#ifndef HAS_UNIFORM_u_width
+uniform lowp float a_width_t;
+attribute mediump vec2 a_width;
+varying mediump float width;
+#else
+uniform mediump float u_width;
+#endif
+
+#ifndef HAS_UNIFORM_u_floorwidth
+uniform lowp float a_floorwidth_t;
+attribute lowp vec2 a_floorwidth;
+varying lowp float floorwidth;
+#else
+uniform lowp float u_floorwidth;
+#endif
+
void main() {
#ifndef HAS_UNIFORM_u_color
@@ -112,6 +127,18 @@ void main() {
lowp float offset = u_offset;
#endif
+#ifndef HAS_UNIFORM_u_width
+ width = unpack_mix_vec2(a_width, a_width_t);
+#else
+ mediump float width = u_width;
+#endif
+
+#ifndef HAS_UNIFORM_u_floorwidth
+ floorwidth = unpack_mix_vec2(a_floorwidth, a_floorwidth_t);
+#else
+ lowp float floorwidth = u_floorwidth;
+#endif
+
vec2 a_extrude = a_data.xy - 128.0;
float a_direction = mod(a_data.z, 4.0) - 1.0;
float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE;
@@ -127,11 +154,11 @@ void main() {
// these transformations used to be applied in the JS and native code bases.
// moved them into the shader for clarity and simplicity.
gapwidth = gapwidth / 2.0;
- float width = u_width / 2.0;
+ float halfwidth = width / 2.0;
offset = -1.0 * offset;
float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0);
- float outset = gapwidth + width * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING;
+ float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING;
// Scale the extrusion vector down to a normal and then up by the line width
// of this vertex.
@@ -156,8 +183,8 @@ void main() {
float extrude_length_with_perspective = length(projected_extrude.xy / gl_Position.w * u_gl_units_to_pixels);
v_gamma_scale = extrude_length_without_perspective / extrude_length_with_perspective;
- v_tex_a = vec2(a_linesofar * u_patternscale_a.x, normal.y * u_patternscale_a.y + u_tex_y_a);
- v_tex_b = vec2(a_linesofar * u_patternscale_b.x, normal.y * u_patternscale_b.y + u_tex_y_b);
+ v_tex_a = vec2(a_linesofar * u_patternscale_a.x / floorwidth, normal.y * u_patternscale_a.y + u_tex_y_a);
+ v_tex_b = vec2(a_linesofar * u_patternscale_b.x / floorwidth, normal.y * u_patternscale_b.y + u_tex_y_b);
v_width2 = vec2(outset, inset);
}
@@ -194,6 +221,18 @@ varying lowp float opacity;
uniform lowp float u_opacity;
#endif
+#ifndef HAS_UNIFORM_u_width
+varying mediump float width;
+#else
+uniform mediump float u_width;
+#endif
+
+#ifndef HAS_UNIFORM_u_floorwidth
+varying lowp float floorwidth;
+#else
+uniform lowp float u_floorwidth;
+#endif
+
void main() {
#ifdef HAS_UNIFORM_u_color
@@ -208,6 +247,14 @@ void main() {
lowp float opacity = u_opacity;
#endif
+#ifdef HAS_UNIFORM_u_width
+ mediump float width = u_width;
+#endif
+
+#ifdef HAS_UNIFORM_u_floorwidth
+ lowp float floorwidth = u_floorwidth;
+#endif
+
// Calculate the distance of the pixel from the line in pixels.
float dist = length(v_normal) * v_width2.s;
@@ -220,7 +267,7 @@ void main() {
float sdfdist_a = texture2D(u_image, v_tex_a).a;
float sdfdist_b = texture2D(u_image, v_tex_b).a;
float sdfdist = mix(sdfdist_a, sdfdist_b, u_mix);
- alpha *= smoothstep(0.5 - u_sdfgamma, 0.5 + u_sdfgamma, sdfdist);
+ alpha *= smoothstep(0.5 - u_sdfgamma / floorwidth, 0.5 + u_sdfgamma / floorwidth, sdfdist);
gl_FragColor = color * (alpha * opacity);