diff options
Diffstat (limited to 'src/mbgl/shaders/line_sdf.cpp')
-rw-r--r-- | src/mbgl/shaders/line_sdf.cpp | 59 |
1 files changed, 53 insertions, 6 deletions
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); |