summaryrefslogtreecommitdiff
path: root/src/mbgl/shaders/line_pattern.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/shaders/line_pattern.cpp')
-rw-r--r--src/mbgl/shaders/line_pattern.cpp23
1 files changed, 18 insertions, 5 deletions
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);