Skip to content

fix anti-aliasing for fill-patterns - #2372

Merged
mollymerp merged 1 commit into
masterfrom
anti-alias-fill-pattern
Apr 4, 2016
Merged

mollymerp merged 1 commit into
masterfrom
anti-alias-fill-pattern

Conversation

@mollymerp

Copy link
Copy Markdown
Contributor

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. 😐

@mollymerp

Copy link
Copy Markdown
Contributor Author

looks like the anti-aliasing is fixed, but I still need to refactor and clean the code up, as well as adjust sensitivity for the test-suite (because as you can see they're still passing with this fix) and run a few more test cases.

fill pattern test on master branch
screen shot 2016-03-31 at 11 07 06 am

fill pattern test on this branch
screen shot 2016-03-31 at 11 07 27 am

Comment thread shaders/outlinepattern.fragment.glsl Outdated

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);

Copy link
Copy Markdown
Contributor

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.

@mollymerp
mollymerp force-pushed the anti-alias-fill-pattern branch 4 times, most recently from afbf454 to 7daa739 Compare March 31, 2016 21:30
@mollymerp

Copy link
Copy Markdown
Contributor Author

@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.
some updated screen shots:
master branch
screen shot 2016-03-31 at 2 34 00 pm

this branch
screen shot 2016-03-31 at 2 33 28 pm

@ansis

ansis commented Mar 31, 2016

Copy link
Copy Markdown
Contributor

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:

  • updating render tests
  • reducing duplication in draw_fill.js

Comment thread js/render/draw_fill.js Outdated
for (var j = 0; j < coords.length; j++) {
drawStroke(painter, source, layer, coords[j]);
}
} else if (layer.paint['fill-pattern']) {

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor

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
    }
}

@mollymerp
mollymerp force-pushed the anti-alias-fill-pattern branch from 7daa739 to f12493a Compare April 1, 2016 18:07
@mollymerp mollymerp changed the title [not ready] first pass on fixing anti-aliasing with fill-patterns fix anti-aliasing for fill-patterns Apr 1, 2016
@mollymerp

Copy link
Copy Markdown
Contributor Author

PR made in mapbox-gl-test-suite to update render tests

@mollymerp
mollymerp force-pushed the anti-alias-fill-pattern branch from f12493a to a088102 Compare April 1, 2016 19:29
Comment thread js/render/draw_fill.js Outdated
}


function imageOffset(image, opacity, tile, coord, painter, program) {

Copy link
Copy Markdown
Contributor

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?

@ansis

ansis commented Apr 1, 2016

Copy link
Copy Markdown
Contributor

This looks great to me! the remaining things I see are

  • renaming imageOffset
  • updating mapbox-gl-test-suite in package.json to your updated version (which should fix the failing tests)

Comment thread debug/site.js Outdated
mapboxgl.accessToken = getAccessToken();

var map = new mapboxgl.Map({
window.map = new mapboxgl.Map({

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

leading space

@mollymerp
mollymerp force-pushed the anti-alias-fill-pattern branch 3 times, most recently from 2b10f31 to 6a985a6 Compare April 4, 2016 17:47
@mollymerp
mollymerp force-pushed the anti-alias-fill-pattern branch from 6a985a6 to c5f154c Compare April 4, 2016 17:58
@mollymerp
mollymerp merged commit c5f154c into master Apr 4, 2016
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants