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

Improve how points with small radii or stroke widths are rendered. #1021

Merged
merged 1 commit into from
Sep 4, 2019
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## Unreleased

### Improvements
- Points with small radii or thin strokes are rendered better (#1021)

## Version 0.19.6

### Features
Expand Down
10 changes: 6 additions & 4 deletions src/webgl/pointFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,12 @@ var webgl_pointFeature = function (arg) {
}
s_updateStyleFromArray(key, styleArray, false);
});
if (m_this.visible() && needsRefresh) {
m_this.draw();
} else if (needsRender) {
m_this.renderer()._render();
if (refresh) {
if (m_this.visible() && needsRefresh) {
m_this.draw();
} else if (needsRender) {
m_this.renderer()._render();
}
}
return m_this;
};
Expand Down
18 changes: 10 additions & 8 deletions src/webgl/pointFeaturePoly.frag
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,26 @@ void main () {
discard;
// If there is no stroke, the fill region should transition to nothing
if (strokeVar == 0.0) {
strokeColor = vec4 (fillColorVar.rgb, 0.0);
strokeColor = vec4(fillColorVar.rgb, 0.0);
endStep = 1.0;
} else {
strokeColor = strokeColorVar;
endStep = radiusVar / (radiusVar + strokeWidthVar);
}
// Likewise, if there is no fill, the stroke should transition to nothing
if (fillVar == 0.0)
fillColor = vec4 (strokeColor.rgb, 0.0);
fillColor = vec4(strokeColor.rgb, 0.0);
else
fillColor = fillColorVar;
// Distance to antialias over
float antialiasDist = 3.0 / (2.0 * radiusVar);
// Distance to antialias over. First number is in pixels
float antialiasDist = 1.5 / (radiusVar + strokeWidthVar);
if (rad < endStep) {
float step = smoothstep (endStep - antialiasDist, endStep, rad);
gl_FragColor = mix (fillColor, strokeColor, step);
float step = smoothstep(max(0.0, endStep - antialiasDist), endStep, rad);
vec4 color = mix(fillColor, strokeColor, step);
float step2 = smoothstep(max(0.0, 1.0 - antialiasDist), 1.0, rad);
gl_FragColor = mix(color, vec4(color.rgb, 0.0), step2);
} else {
float step = smoothstep (1.0 - antialiasDist, 1.0, rad);
gl_FragColor = mix (strokeColor, vec4 (strokeColor.rgb, 0.0), step);
float step = smoothstep(max(0.0, 1.0 - antialiasDist), 1.0, rad);
gl_FragColor = mix(strokeColor, vec4(strokeColor.rgb, 0.0), step);
}
}
20 changes: 11 additions & 9 deletions src/webgl/pointFeatureSprite.frag
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,31 @@ void main () {
// No stroke or fill implies nothing to draw
if (fillVar == 0.0 && strokeVar == 0.0)
discard;
float rad = 2.0 * length (gl_PointCoord - vec2(0.5)); // distinct for sprite
float rad = 2.0 * length(gl_PointCoord - vec2(0.5)); // distinct for sprite
if (rad > 1.0)
discard;
// If there is no stroke, the fill region should transition to nothing
if (strokeVar == 0.0) {
strokeColor = vec4 (fillColorVar.rgb, 0.0);
strokeColor = vec4(fillColorVar.rgb, 0.0);
endStep = 1.0;
} else {
strokeColor = strokeColorVar;
endStep = radiusVar / (radiusVar + strokeWidthVar);
}
// Likewise, if there is no fill, the stroke should transition to nothing
if (fillVar == 0.0)
fillColor = vec4 (strokeColor.rgb, 0.0);
fillColor = vec4(strokeColor.rgb, 0.0);
else
fillColor = fillColorVar;
// Distance to antialias over
float antialiasDist = 3.0 / (2.0 * radiusVar);
// Distance to antialias over. First number is in pixels
float antialiasDist = 1.5 / (radiusVar + strokeWidthVar);
if (rad < endStep) {
float step = smoothstep (endStep - antialiasDist, endStep, rad);
gl_FragColor = mix (fillColor, strokeColor, step);
float step = smoothstep(max(0.0, endStep - antialiasDist), endStep, rad);
vec4 color = mix(fillColor, strokeColor, step);
float step2 = smoothstep(max(0.0, 1.0 - antialiasDist), 1.0, rad);
gl_FragColor = mix(color, vec4(color.rgb, 0.0), step2);
} else {
float step = smoothstep (1.0 - antialiasDist, 1.0, rad);
gl_FragColor = mix (strokeColor, vec4 (strokeColor.rgb, 0.0), step);
float step = smoothstep(max(0.0, 1.0 - antialiasDist), 1.0, rad);
gl_FragColor = mix(strokeColor, vec4(strokeColor.rgb, 0.0), step);
}
}