diff --git a/src/render/draw_line.js b/src/render/draw_line.js index f1de1da9bd1..1316bd21439 100644 --- a/src/render/draw_line.js +++ b/src/render/draw_line.js @@ -11,7 +11,8 @@ module.exports = function drawLine(painter, sourceCache, layer, coords) { 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/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. 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 00000000000..ae9d962e081 Binary files /dev/null and b/test/integration/render-tests/line-width/zero-width-function/expected.png differ diff --git a/test/integration/render-tests/line-width/zero-width-function/style.json b/test/integration/render-tests/line-width/zero-width-function/style.json new file mode 100644 index 00000000000..a76540531ed --- /dev/null +++ b/test/integration/render-tests/line-width/zero-width-function/style.json @@ -0,0 +1,75 @@ +{ + "version": 8, + "metadata": { + "test": { + "width": 100, + "height": 100, + "diff": 0.00075 + } + }, + "zoom": 2, + "sources": { + "linesource": { + "type": "geojson", + "data": { + "type": "Feature", + "properties": { + "width": 0 + }, + "geometry": { + "type": "LineString", + "coordinates": [ + [ + -1, + 8 + ], + [ + 8, + 1 + ], + [ + 1, + -8 + ], + [ + -8, + -1 + ], + [ + 1, + 4 + ], + [ + 4, + -1 + ], + [ + -1, + -4 + ], + [ + -2, + 0 + ] + ] + } + }, + "lineMetrics": true + } + }, + "layers": [ + { + "id": "line", + "type": "line", + "source": "linesource", + "layout": { + "line-cap": "round", + "line-join": "round" + }, + "paint": { + "line-width": ["get", "width"], + "line-color": "red" + } + } + ] +} diff --git a/test/integration/render-tests/line-width/zero-width/expected.png b/test/integration/render-tests/line-width/zero-width/expected.png new file mode 100644 index 00000000000..ae9d962e081 Binary files /dev/null and b/test/integration/render-tests/line-width/zero-width/expected.png differ diff --git a/test/integration/render-tests/line-width/zero-width/style.json b/test/integration/render-tests/line-width/zero-width/style.json new file mode 100644 index 00000000000..bca9c45b6f9 --- /dev/null +++ b/test/integration/render-tests/line-width/zero-width/style.json @@ -0,0 +1,73 @@ +{ + "version": 8, + "metadata": { + "test": { + "width": 100, + "height": 100, + "diff": 0.00075 + } + }, + "zoom": 2, + "sources": { + "linesource": { + "type": "geojson", + "data": { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [ + [ + -1, + 8 + ], + [ + 8, + 1 + ], + [ + 1, + -8 + ], + [ + -8, + -1 + ], + [ + 1, + 4 + ], + [ + 4, + -1 + ], + [ + -1, + -4 + ], + [ + -2, + 0 + ] + ] + } + }, + "lineMetrics": true + } + }, + "layers": [ + { + "id": "line", + "type": "line", + "source": "linesource", + "layout": { + "line-cap": "round", + "line-join": "round" + }, + "paint": { + "line-width": 0, + "line-color": "red" + } + } + ] +}