Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
clearer pitched line antialiasing
Browse files Browse the repository at this point in the history
ported from -js: ef5582dd3bc5c15a3112e875ed66494dab8e9d0b

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 15, 2016
1 parent f5ccc38 commit b88fbe7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"ejs": "^2.4.1",
"express": "^4.11.1",
"lodash": "^4.16.4",
"mapbox-gl": "mapbox/mapbox-gl-js#eb6c6596c6a7a61363d30356674e0002153b1d19",
"mapbox-gl": "mapbox/mapbox-gl-js#ef5582dd3bc5c15a3112e875ed66494dab8e9d0b",
"mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#49e8b407bdbbe6f7c92dbcb56d3d51f425fc2653",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#66397c8ee0426537d25e8d4cfcac134ca21a021b",
"mkdirp": "^0.5.1",
Expand Down
22 changes: 9 additions & 13 deletions src/mbgl/programs/line_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,9 @@ template <class Values, class...Args>
Values makeValues(const LinePaintProperties::Evaluated& properties,
const RenderTile& tile,
const TransformState& state,
const std::array<float, 2>& pixelsToGLUnits,
Args&&... args) {

mat2 antialiasingMatrix;
matrix::identity(antialiasingMatrix);
matrix::scale(antialiasingMatrix, antialiasingMatrix, 1.0, std::cos(state.getPitch()));
matrix::rotate(antialiasingMatrix, antialiasingMatrix, state.getAngle());

// calculate how much longer the real world distance is at the top of the screen
// than at the middle of the screen.
float topedgelength = std::sqrt(std::pow(state.getSize().height, 2.0f) / 4.0f * (1.0f + std::pow(state.getCameraToCenterDistance(), 2.0f)));
float x = state.getSize().height / 2.0f * std::tan(state.getPitch());

return Values {
uniforms::u_matrix::Value{
tile.translatedMatrix(properties.get<LineTranslate>(),
Expand All @@ -39,21 +30,22 @@ Values makeValues(const LinePaintProperties::Evaluated& properties,
uniforms::u_gapwidth::Value{ properties.get<LineGapWidth>() },
uniforms::u_blur::Value{ properties.get<LineBlur>() },
uniforms::u_offset::Value{ properties.get<LineOffset>() },
uniforms::u_antialiasingmatrix::Value{ antialiasingMatrix },
uniforms::u_ratio::Value{ 1.0f / tile.id.pixelsToTileUnits(1.0, state.getZoom()) },
uniforms::u_extra::Value{ (topedgelength + x) / topedgelength - 1.0f },
uniforms::u_gl_units_to_pixels::Value{{{ 1.0f / pixelsToGLUnits[0], 1.0f / pixelsToGLUnits[1] }}},
std::forward<Args>(args)...
};
}

LineProgram::UniformValues
LineProgram::uniformValues(const LinePaintProperties::Evaluated& properties,
const RenderTile& tile,
const TransformState& state) {
const TransformState& state,
const std::array<float, 2>& pixelsToGLUnits) {
return makeValues<LineProgram::UniformValues>(
properties,
tile,
state,
pixelsToGLUnits,
uniforms::u_color::Value{ properties.get<LineColor>() }
);
}
Expand All @@ -63,6 +55,7 @@ LineSDFProgram::uniformValues(const LinePaintProperties::Evaluated& properties,
float pixelRatio,
const RenderTile& tile,
const TransformState& state,
const std::array<float, 2>& pixelsToGLUnits,
const LinePatternPos& posA,
const LinePatternPos& posB,
float dashLineWidth,
Expand All @@ -84,6 +77,7 @@ LineSDFProgram::uniformValues(const LinePaintProperties::Evaluated& properties,
properties,
tile,
state,
pixelsToGLUnits,
uniforms::u_color::Value{ properties.get<LineColor>() },
uniforms::u_patternscale_a::Value{ scaleA },
uniforms::u_patternscale_b::Value{ scaleB },
Expand All @@ -99,6 +93,7 @@ LinePatternProgram::UniformValues
LinePatternProgram::uniformValues(const LinePaintProperties::Evaluated& properties,
const RenderTile& tile,
const TransformState& state,
const std::array<float, 2>& pixelsToGLUnits,
const SpriteAtlasPosition& posA,
const SpriteAtlasPosition& posB) {
std::array<float, 2> sizeA {{
Expand All @@ -115,6 +110,7 @@ LinePatternProgram::uniformValues(const LinePaintProperties::Evaluated& properti
properties,
tile,
state,
pixelsToGLUnits,
uniforms::u_pattern_tl_a::Value{ posA.tl },
uniforms::u_pattern_br_a::Value{ posA.br },
uniforms::u_pattern_tl_b::Value{ posB.tl },
Expand Down
17 changes: 8 additions & 9 deletions src/mbgl/programs/line_program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ namespace uniforms {
MBGL_DEFINE_UNIFORM_SCALAR(float, u_ratio);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_width);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_gapwidth);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_extra);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_offset);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_tex_y_a);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_tex_y_b);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_sdfgamma);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_fade);
MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_patternscale_a);
MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_patternscale_b);
MBGL_DEFINE_UNIFORM_MATRIX(double, 2, u_antialiasingmatrix);
MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_gl_units_to_pixels);
} // namespace uniforms

struct LineAttributes : gl::Attributes<
Expand Down Expand Up @@ -93,17 +92,17 @@ class LineProgram : public Program<
uniforms::u_gapwidth,
uniforms::u_blur,
uniforms::u_offset,
uniforms::u_antialiasingmatrix,
uniforms::u_ratio,
uniforms::u_extra,
uniforms::u_gl_units_to_pixels,
uniforms::u_color>>
{
public:
using Program::Program;

static UniformValues uniformValues(const style::LinePaintProperties::Evaluated&,
const RenderTile&,
const TransformState&);
const TransformState&,
const std::array<float, 2>& pixelsToGLUnits);
};

class LinePatternProgram : public Program<
Expand All @@ -117,9 +116,8 @@ class LinePatternProgram : public Program<
uniforms::u_gapwidth,
uniforms::u_blur,
uniforms::u_offset,
uniforms::u_antialiasingmatrix,
uniforms::u_ratio,
uniforms::u_extra,
uniforms::u_gl_units_to_pixels,
uniforms::u_pattern_tl_a,
uniforms::u_pattern_br_a,
uniforms::u_pattern_tl_b,
Expand All @@ -135,6 +133,7 @@ class LinePatternProgram : public Program<
static UniformValues uniformValues(const style::LinePaintProperties::Evaluated&,
const RenderTile&,
const TransformState&,
const std::array<float, 2>& pixelsToGLUnits,
const SpriteAtlasPosition& posA,
const SpriteAtlasPosition& posB);
};
Expand All @@ -150,9 +149,8 @@ class LineSDFProgram : public Program<
uniforms::u_gapwidth,
uniforms::u_blur,
uniforms::u_offset,
uniforms::u_antialiasingmatrix,
uniforms::u_ratio,
uniforms::u_extra,
uniforms::u_gl_units_to_pixels,
uniforms::u_color,
uniforms::u_patternscale_a,
uniforms::u_patternscale_b,
Expand All @@ -169,6 +167,7 @@ class LineSDFProgram : public Program<
float pixelRatio,
const RenderTile&,
const TransformState&,
const std::array<float, 2>& pixelsToGLUnits,
const LinePatternPos& posA,
const LinePatternPos& posB,
float dashLineWidth,
Expand Down
5 changes: 4 additions & 1 deletion src/mbgl/renderer/painter_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void Painter::renderLine(PaintParameters& parameters,
frame.pixelRatio,
tile,
state,
pixelsToGLUnits,
posA,
posB,
layer.impl->dashLineWidth,
Expand All @@ -72,6 +73,7 @@ void Painter::renderLine(PaintParameters& parameters,
properties,
tile,
state,
pixelsToGLUnits,
*posA,
*posB));

Expand All @@ -80,7 +82,8 @@ void Painter::renderLine(PaintParameters& parameters,
LineProgram::uniformValues(
properties,
tile,
state));
state,
pixelsToGLUnits));
}
}

Expand Down

0 comments on commit b88fbe7

Please sign in to comment.