transition dashes when resetting their stretch

Dash patterns stretch from one integer zoom until the
next integer zoom where they reset. This transitions
those resets.

js: be5c7184bfd8cc9d47299041eb7fadbd41f6f6f0
This commit is contained in:
Ansis Brammanis
2015-01-23 17:25:31 -05:00
parent d0d33a3ee7
commit 5955ac3493
4 changed files with 34 additions and 10 deletions

View File

@@ -92,10 +92,23 @@ void Painter::renderLine(LineBucket& bucket, util::ptr<StyleLayer> layer_desc, c
float scaleX = patternratio / pos.width / properties.dash_line_width;
float scaleY = -pos.height / 2.0;
linesdfShader->u_patternscale = {{ scaleX, scaleY }};
linesdfShader->u_tex_y = pos.y;
float mix;
if (state.getZoom() > lastIntegerZoom) {
// zooming in
mix = fraction + (1.0f - fraction) * t;
scaleX /= 2.0;
} else {
// zooming out
mix = fraction - fraction * t;
}
linesdfShader->u_patternscale_a = {{ scaleX, scaleY }};
linesdfShader->u_tex_y_a = pos.y;
linesdfShader->u_patternscale_b = {{ scaleX * 2.0f, scaleY }};
linesdfShader->u_tex_y_b = pos.y;
linesdfShader->u_image = 0;
linesdfShader->u_sdfgamma = lineAtlas.width / (properties.dash_line_width * pos.width * 256.0 * state.getPixelRatio());
linesdfShader->u_mix = mix;
bucket.drawLineSDF(*linesdfShader);

View File

@@ -3,9 +3,11 @@ uniform vec4 u_color;
uniform float u_blur;
uniform sampler2D u_image;
uniform float u_sdfgamma;
uniform float u_mix;
varying vec2 v_normal;
varying vec2 v_tex;
varying vec2 v_tex_a;
varying vec2 v_tex_b;
void main() {
// Calculate the distance of the pixel from the line in pixels.
@@ -16,7 +18,9 @@ void main() {
// (v_linewidth.s)
float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0);
float sdfdist = texture2D(u_image, v_tex).a;
float sdfdist_a = texture2D(u_image, v_tex_a).a;
float sdfdist_b = texture2D(u_image, v_tex_b).a;
float sdfdist = mix(sdfdist_a, sdfdist_b, u_mix);
alpha *= smoothstep(0.5 - u_sdfgamma, 0.5 + u_sdfgamma, sdfdist);
gl_FragColor = u_color * alpha;

View File

@@ -17,11 +17,14 @@ uniform mat4 u_exmatrix;
// shared
uniform float u_ratio;
uniform vec2 u_linewidth;
uniform vec2 u_patternscale;
uniform float u_tex_y;
uniform vec2 u_patternscale_a;
uniform float u_tex_y_a;
uniform vec2 u_patternscale_b;
uniform float u_tex_y_b;
varying vec2 v_normal;
varying vec2 v_tex;
varying vec2 v_tex_a;
varying vec2 v_tex_b;
void main() {
vec2 a_extrude = a_data.xy;
@@ -45,5 +48,6 @@ void main() {
// tile's zoom level.
gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0.0, 1.0) + u_exmatrix * dist;
v_tex = vec2(a_linesofar * u_patternscale.x, normal.y * u_patternscale.y + u_tex_y);
v_tex_a = vec2(a_linesofar * u_patternscale_a.x, normal.y * u_patternscale_a.y + u_tex_y_a);
v_tex_b = vec2(a_linesofar * u_patternscale_b.x, normal.y * u_patternscale_b.y + u_tex_y_b);
}

View File

@@ -18,10 +18,13 @@ public:
Uniform<std::array<float, 2>> u_linewidth = {"u_linewidth", *this};
Uniform<float> u_ratio = {"u_ratio", *this};
Uniform<float> u_blur = {"u_blur", *this};
Uniform<std::array<float, 2>> u_patternscale = { "u_patternscale", *this };
Uniform<float> u_tex_y = {"u_tex_y", *this};
Uniform<std::array<float, 2>> u_patternscale_a = { "u_patternscale_a", *this };
Uniform<float> u_tex_y_a = {"u_tex_y_a", *this};
Uniform<std::array<float, 2>> u_patternscale_b = { "u_patternscale_b", *this };
Uniform<float> u_tex_y_b = {"u_tex_y_b", *this};
Uniform<int32_t> u_image = {"u_image", *this};
Uniform<float> u_sdfgamma = {"u_sdfgamma", *this};
Uniform<float> u_mix = {"u_mix", *this};
private:
int32_t a_pos = -1;