Skip to content

Commit

Permalink
clearer pitched line antialiasing
Browse files Browse the repository at this point in the history
Project the extrusion and compare it's projected pixel length with the
actual pixel length and adjust antialiasing accordingly.

The previous approach calculated the adjustment much more indirectly and
had no intuitive explanation.
  • Loading branch information
ansis committed Dec 13, 2016
1 parent 540fc73 commit cb6a1de
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 14 deletions.
10 changes: 0 additions & 10 deletions js/geo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,16 +439,6 @@ class Transform {
if (!m) throw new Error("failed to invert matrix");
this.pixelMatrixInverse = m;

// line antialiasing matrix
m = mat2.create();
mat2.scale(m, m, [1, Math.cos(this._pitch)]);
mat2.rotate(m, m, this.angle);
this.lineAntialiasingMatrix = m;

// calculate how much longer the real world distance is at the top of the screen
// than at the middle of the screen.
const topEdgeLength = Math.sqrt((this.height * this.height + this.cameraToCenterDistance * this.cameraToCenterDistance) / 4);
this.lineStretch = (this.height / 2 * Math.tan(this._pitch)) / topEdgeLength;
}
}

Expand Down
5 changes: 2 additions & 3 deletions js/render/draw_line.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ function drawLineTile(program, painter, tile, buffers, layer, coord, layerData,
gl.uniform2f(program.u_pattern_size_a, imagePosA.size[0] * image.fromScale / tileRatio, imagePosB.size[1]);
gl.uniform2f(program.u_pattern_size_b, imagePosB.size[0] * image.toScale / tileRatio, imagePosB.size[1]);
}

gl.uniform2f(program.u_gl_units_to_pixels, 1 / painter.transform.pixelsToGLUnits[0], 1 / painter.transform.pixelsToGLUnits[1]);
}

if (programChanged) {
Expand All @@ -105,9 +107,6 @@ function drawLineTile(program, painter, tile, buffers, layer, coord, layerData,
gl.uniform1f(program.u_fade, image.t);
}
gl.uniform1f(program.u_width, layer.paint['line-width']);

gl.uniformMatrix2fv(program.u_antialiasingmatrix, false, painter.transform.lineAntialiasingMatrix);
gl.uniform1f(program.u_extra, painter.transform.lineStretch);
}

painter.enableTileClippingMask(coord);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"geojson-vt": "^2.4.0",
"grid-index": "^1.0.0",
"mapbox-gl-function": "mapbox/mapbox-gl-function#41c6724e2bbd7bd1eb5991451bbf118b7d02b525",
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#69a834aa6b3c58e0ee60335590b443ac7742ed8d",
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#a5401d074f2fb7a127f3fb4caff530ed2c6ad5a1",
"mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#e85407a377510acb647161de6be6357ab4f606dd",
"mapbox-gl-supported": "^1.2.0",
"package-json-versionify": "^1.0.2",
Expand Down

0 comments on commit cb6a1de

Please sign in to comment.