From 287a47bd04f1693f53524c8115ad927278117db8 Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Fri, 1 Jun 2018 13:48:48 -0700 Subject: [PATCH 1/2] fix zero-width line rendering --- src/render/draw_line.js | 3 +- src/shaders/line.vertex.glsl | 2 +- .../zero-width-function/expected.png | Bin 0 -> 130 bytes .../line-width/zero-width-function/style.json | 75 ++++++++++++++++++ .../line-width/zero-width/expected.png | Bin 0 -> 130 bytes .../line-width/zero-width/style.json | 73 +++++++++++++++++ 6 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 test/integration/render-tests/line-width/zero-width-function/expected.png create mode 100644 test/integration/render-tests/line-width/zero-width-function/style.json create mode 100644 test/integration/render-tests/line-width/zero-width/expected.png create mode 100644 test/integration/render-tests/line-width/zero-width/style.json diff --git a/src/render/draw_line.js b/src/render/draw_line.js index 692f52436d6..f6a0bf93287 100644 --- a/src/render/draw_line.js +++ b/src/render/draw_line.js @@ -16,7 +16,8 @@ export default function drawLine(painter: Painter, sourceCache: SourceCache, lay if (painter.renderPass !== 'translucent') return; const opacity = layer.paint.get('line-opacity'); - if (opacity.constantOr(1) === 0) return; + const width = layer.paint.get('line-width'); + if (opacity.constantOr(1) === 0 || width.constantOr(1) === 0) return; const context = painter.context; diff --git a/src/shaders/line.vertex.glsl b/src/shaders/line.vertex.glsl index 76519d1aa76..c8c55ce7bb6 100644 --- a/src/shaders/line.vertex.glsl +++ b/src/shaders/line.vertex.glsl @@ -58,7 +58,7 @@ void main() { offset = -1.0 * offset; float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); - float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; + float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + (halfwidth == 0.0 ? 0.0 : ANTIALIASING); // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. diff --git a/test/integration/render-tests/line-width/zero-width-function/expected.png b/test/integration/render-tests/line-width/zero-width-function/expected.png new file mode 100644 index 0000000000000000000000000000000000000000..ae9d962e081df568d69ce417691061c0c1771687 GIT binary patch literal 130 zcmeAS@N?(olHy`uVBq!ia0vp^DIm Date: Fri, 1 Jun 2018 16:11:06 -0700 Subject: [PATCH 2/2] fix other line types too: --- src/shaders/line_gradient.vertex.glsl | 2 +- src/shaders/line_pattern.vertex.glsl | 2 +- src/shaders/line_sdf.vertex.glsl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shaders/line_gradient.vertex.glsl b/src/shaders/line_gradient.vertex.glsl index cf791dfa522..25cf7175275 100644 --- a/src/shaders/line_gradient.vertex.glsl +++ b/src/shaders/line_gradient.vertex.glsl @@ -58,7 +58,7 @@ void main() { offset = -1.0 * offset; float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); - float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; + float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + (halfwidth == 0.0 ? 0.0 : ANTIALIASING); // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. diff --git a/src/shaders/line_pattern.vertex.glsl b/src/shaders/line_pattern.vertex.glsl index 0be73f30511..74170762613 100644 --- a/src/shaders/line_pattern.vertex.glsl +++ b/src/shaders/line_pattern.vertex.glsl @@ -57,7 +57,7 @@ void main() { offset = -1.0 * offset; float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); - float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; + float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + (halfwidth == 0.0 ? 0.0 : ANTIALIASING); // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. diff --git a/src/shaders/line_sdf.vertex.glsl b/src/shaders/line_sdf.vertex.glsl index a57a366d61e..84801c0e614 100644 --- a/src/shaders/line_sdf.vertex.glsl +++ b/src/shaders/line_sdf.vertex.glsl @@ -66,7 +66,7 @@ void main() { offset = -1.0 * offset; float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); - float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; + float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + (halfwidth == 0.0 ? 0.0 : ANTIALIASING); // Scale the extrusion vector down to a normal and then up by the line width // of this vertex.