Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix line-pattern sampling from outside icon tex coords #6246

Merged
merged 5 commits into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/render/draw_line.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function drawLineTile(program, painter, tile, bucket, layer, coord, programConfi
imagePosB = painter.imageManager.getPattern(image.to);
if (!imagePosA || !imagePosB) return;

gl.uniform2f(program.uniforms.u_pattern_size_a, imagePosA.displaySize[0] * image.fromScale / tileRatio, imagePosB.displaySize[1]);
gl.uniform2f(program.uniforms.u_pattern_size_a, imagePosA.displaySize[0] * image.fromScale / tileRatio, imagePosA.displaySize[1]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

gl.uniform2f(program.uniforms.u_pattern_size_b, imagePosB.displaySize[0] * image.toScale / tileRatio, imagePosB.displaySize[1]);

const {width, height} = painter.imageManager.getPixelSize();
Expand Down
10 changes: 8 additions & 2 deletions src/shaders/line_pattern.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ void main() {

float x_a = mod(v_linesofar / u_pattern_size_a.x, 1.0);
float x_b = mod(v_linesofar / u_pattern_size_b.x, 1.0);
float y_a = 0.5 + (v_normal.y * v_width2.s / u_pattern_size_a.y);
float y_b = 0.5 + (v_normal.y * v_width2.s / u_pattern_size_b.y);

// v_normal.y is 0 at the midpoint of the line, -1 at the lower edge, 1 at the upper edge
// we clamp the line width outset to be between 0 and half the pattern height plus padding (2.0)
// to ensure we don't sample outside the designated symbol on the sprite sheet.
// 0.5 is added to shift the component to be bounded between 0 and 1 for interpolation of
// the texture coordinate
float y_a = 0.5 + (v_normal.y * clamp(v_width2.s, 0.0, (u_pattern_size_a.y + 2.0) / 2.0) / u_pattern_size_a.y);
float y_b = 0.5 + (v_normal.y * clamp(v_width2.s, 0.0, (u_pattern_size_b.y + 2.0) / 2.0) / u_pattern_size_b.y);
vec2 pos_a = mix(u_pattern_tl_a / u_texsize, u_pattern_br_a / u_texsize, vec2(x_a, y_a));
vec2 pos_b = mix(u_pattern_tl_b / u_texsize, u_pattern_br_b / u_texsize, vec2(x_b, y_b));

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"version": 8,
"metadata": {
"test": {
"width": 64,
"height": 64
}
},
"sprite": "local://sprites/emerald",
"sources": {
"a": {
"type": "geojson",
"data": {
"type": "LineString",
"coordinates": [
[
-180,
10
],
[
180,
10
]
]
}
},
"b": {
"type": "geojson",
"data": {
"type": "LineString",
"coordinates": [
[
-180,
-10
],
[
180,
-10
]
]
}
}
},
"layers": [
{
"id": "a",
"type": "line",
"source": "a",
"paint": {
"line-width": 4,
"line-pattern": "oneway_road"
}
},
{
"id": "b",
"type": "line",
"source": "b",
"paint": {
"line-width": 30,
"line-pattern": "default_3"
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.