-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 anti-aliasing for fill-patterns #2372
Conversation
@@ -21,5 +21,13 @@ void main() { | |||
vec2 pos2 = mix(u_pattern_tl_b, u_pattern_br_b, imagecoord_b); | |||
vec4 color2 = texture2D(u_image, pos2); | |||
|
|||
gl_FragColor = mix(color1, color2, u_mix) * u_opacity; | |||
// find distance to outline for alpha interpolation | |||
float dist_a = length(v_pos_a - gl_FragCoord.xy); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to fade the pixel appropriately we need the distance of the pixel from the center of the line. gl_FragCoord.xy
is the position of the pixel which we need to subtract from the position of the closest point on the line.
v_pos_a
is the position of texture pixel we need. I think we need another varying v_pos
that has the position of the nearest point on the line like in the outline shader.
afbf454
to
7daa739
Compare
@ansis pointed out that I was using incorrect variables to calculate the alpha value before. I have updated the shaders accordingly. the new changes cause 2 of the tests to fail, so I will have to update the test-suite once we confirm the output is what we expect. |
The rendering in 7daa739 looks right to me. The render test rendering is a bit off but that is a completely separate issue. The headless renderer we use only supports a gl.lineWidth of 1: #2080 We should still update render tests with the new rendering. I guess the remaining things are:
|
@@ -49,6 +50,39 @@ function draw(painter, source, layer, coords) { | |||
for (var j = 0; j < coords.length; j++) { | |||
drawStroke(painter, source, layer, coords[j]); | |||
} | |||
} else if (layer.paint['fill-pattern']) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the correct conditional to have here? I was thinking else if (layer.paint['fill-pattern'] && !strokeColor)
might make sense? do we even need another conditional at all or would simply else
suffice? I'm not super familiar with the possible permutations of the condition checked in L27.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drawFill
is called twice for each layer each frame: once for the opaque pass and once for the translucent pass. The opaque pass is only used to draw completely opaque geometry. All antialiasing strokes are translucent so they need to be drawn when painter.isOpaquePass
is false.
No antialiasing should be drawn if layer.paint['fill-antialias']
is false.
if (!painter.isOpaquePass && layer.paint['fill-antialias']) {
if (strokeColor || !layer.paint['fill-pattern']) {
// draw outline with either strokeColor or the fill color
} else {
// drawn the new patterned outline
}
}
7daa739
to
f12493a
Compare
PR made in mapbox-gl-test-suite to update render tests |
f12493a
to
a088102
Compare
@@ -221,3 +201,55 @@ function drawStroke(painter, source, layer, coord) { | |||
gl.drawElements(gl.LINES, count, gl.UNSIGNED_SHORT, elementOffset); | |||
} | |||
} | |||
|
|||
|
|||
function imageOffset(image, opacity, tile, coord, painter, program) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be renamed to something with a verb like usePattern
or setPattern
?
This looks great to me! the remaining things I see are
|
@@ -1,7 +1,7 @@ | |||
|
|||
mapboxgl.accessToken = getAccessToken(); | |||
|
|||
var map = new mapboxgl.Map({ | |||
window.map = new mapboxgl.Map({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leading space
2b10f31
to
6a985a6
Compare
6a985a6
to
c5f154c
Compare
update package.json with new test-suite sha, rename imageOffset -> setPattern include distance interpolation for opacity fix linting tests refactor image offset calculations use distance from line to calculate alpha, change to multiplication for combining u_opacity and alpha add u_world to use_program for outline pattern, refactor using new imageOffset function refactor draw_fill, fix conditionals
π |
a quick & dirty first attempt at resolving the problem with anti-aliasing when there is a fill-pattern β this code doesn't throw errors but also doesn't solve the problem. π