diff options
Diffstat (limited to 'src/mbgl/shader/linepattern.vertex.glsl')
-rw-r--r-- | src/mbgl/shader/linepattern.vertex.glsl | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/mbgl/shader/linepattern.vertex.glsl b/src/mbgl/shader/linepattern.vertex.glsl index 541c9fc3a7..5b3c468be0 100644 --- a/src/mbgl/shader/linepattern.vertex.glsl +++ b/src/mbgl/shader/linepattern.vertex.glsl @@ -17,6 +17,7 @@ uniform mat4 u_exmatrix; // shared uniform float u_ratio; uniform vec2 u_linewidth; +uniform float u_offset; uniform vec4 u_color; uniform float u_extra; @@ -28,7 +29,8 @@ varying float v_gamma_scale; void main() { vec2 a_extrude = a_data.xy; - float a_linesofar = a_data.z * 128.0 + a_data.w; + float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); + float a_linesofar = abs(floor(a_data.z / 2.0)) + a_data.w * 64.0; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 @@ -42,11 +44,19 @@ void main() { // of this vertex. vec2 dist = u_linewidth.s * a_extrude * scale; + // Calculate the offset when drawing a line that is to the side of the actual line. + // We do this by creating a vector that points towards the extrude, but rotate + // it when we're drawing round end points (a_direction = -1 or 1) since their + // extrude vector points in another direction. + float u = 0.5 * a_direction; + float t = 1.0 - abs(u); + vec2 offset = u_offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); + // Remove the texture normal bit of the position before scaling it with the // model/view matrix. Add the extrusion vector *after* the model/view matrix // because we're extruding the line in pixel space, regardless of the current // tile's zoom level. - gl_Position = u_matrix * vec4(floor(a_pos / 2.0) + dist.xy / u_ratio, 0.0, 1.0); + gl_Position = u_matrix * vec4(floor(a_pos / 2.0) + (offset + dist) / u_ratio, 0.0, 1.0); v_linesofar = a_linesofar; // position of y on the screen |