Skip to content

Commit

Permalink
Fix undefined behavior in fill_outline shaders (#4600)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaefer authored and mourner committed Apr 18, 2017
1 parent 0c3daa9 commit 6f42d00
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/shaders/fill_outline.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void main() {
#pragma mapbox: initialize lowp float opacity

float dist = length(v_pos - gl_FragCoord.xy);
float alpha = smoothstep(1.0, 0.0, dist);
float alpha = 1.0 - smoothstep(0.0, 1.0, dist);
gl_FragColor = outline_color * (alpha * opacity);

#ifdef OVERDRAW_INSPECTOR
Expand Down
2 changes: 1 addition & 1 deletion src/shaders/fill_outline_pattern.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void main() {
// find distance to outline for alpha interpolation

float dist = length(v_pos - gl_FragCoord.xy);
float alpha = smoothstep(1.0, 0.0, dist);
float alpha = 1.0 - smoothstep(0.0, 1.0, dist);


gl_FragColor = mix(color1, color2, u_mix) * alpha * opacity;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions test/integration/render-tests/fill-outline-color/fill/style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"version": 8,
"metadata": {
"test": {
"width": 64,
"height": 64,
"ignored": {
"js": "https://github.com/mapbox/mapbox-gl-js/issues/4601"
}
}
},
"sources": {
"geojson": {
"type": "geojson",
"data": {
"type": "Polygon",
"coordinates": [
[
[
-13,
-13
],
[
-10,
7
],
[
10,
10
],
[
7,
-10
],
[
-13,
-13
]
]
]
}
}
},
"layers": [
{
"id": "fill",
"type": "fill",
"source": "geojson",
"paint": {
"fill-color": "#CCC",
"fill-outline-color": "#000"
}
}
]
}

0 comments on commit 6f42d00

Please sign in to comment.