From 6f42d0082d242c1ee7ae23a4c0caa59284a3d2c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 18 Apr 2017 18:06:28 +0200 Subject: [PATCH] Fix undefined behavior in fill_outline shaders (#4600) --- src/shaders/fill_outline.fragment.glsl | 2 +- .../fill_outline_pattern.fragment.glsl | 2 +- .../fill-outline-color/fill/expected.png | Bin 0 -> 871 bytes .../fill-outline-color/fill/style.json | 55 ++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 test/integration/render-tests/fill-outline-color/fill/expected.png create mode 100644 test/integration/render-tests/fill-outline-color/fill/style.json diff --git a/src/shaders/fill_outline.fragment.glsl b/src/shaders/fill_outline.fragment.glsl index 1cb29259094..8af0d2b9a37 100644 --- a/src/shaders/fill_outline.fragment.glsl +++ b/src/shaders/fill_outline.fragment.glsl @@ -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 diff --git a/src/shaders/fill_outline_pattern.fragment.glsl b/src/shaders/fill_outline_pattern.fragment.glsl index 12c6bd3c27a..2c95c4c2e80 100644 --- a/src/shaders/fill_outline_pattern.fragment.glsl +++ b/src/shaders/fill_outline_pattern.fragment.glsl @@ -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; diff --git a/test/integration/render-tests/fill-outline-color/fill/expected.png b/test/integration/render-tests/fill-outline-color/fill/expected.png new file mode 100644 index 0000000000000000000000000000000000000000..c9a44190230c85165e93caa055cd3795fb36f7e7 GIT binary patch literal 871 zcmV-t1DO1YP)b1r&j=Y}*#8REk_KN3mGs{{Eib-Q6Eiz(T*zfei2x z*aBVvtFc%tF*P;C>gp=4>*BgDnM{UcGKmm^zuVi}Ln@RUGn)n3kwUx<8l5i-}jMTp@4-tKLF2xr(+9-CVjC}5$+%=Y#+I^5pgBHf^fAi6|6 z9*?0(yWK|m1w{nWtt~DtqRZjoA<`QZ5kyzY<#Om!sZ@~mQA7~kmg~CcQmfUF-k^ve zx)=F;9$nh)Hqx&sB8V=NPN&f!2m$J3{XfAo{&DXZ5tiV&(D$GqnIGPx#{U?bU8XYLi!oS z1mU@BYisD@c^*<3#RTDPIF5rZ)oK;#6^aSM+i)BQU7F1%QVqof;T1EP47yxiULyU0 zVuJ8eGcz;jaC38mbj1h=!g*rbwvf=_Cg1T4aNmd$2S zX*e9x?RKfx>v*1r=Xo?54SKyEK@fZZzGnn1!r63PmoTocuW7Yf_`Z+ldDLn(&d$zw zcz759r@%X4A1DJp&;g5+wOU+VT_ODm)PUE( zKJXT30U!AfScLQS^71mhUXMnjf$#fNDi!MWI-O33;c)m7cn`b<_JP+x4Y=Tui4jf! x1V9(40%f2K900!q0}R7348t%C!!V4;>n}%x^aD9+EDZnv002ovPDHLkV1j_CkKX_Q literal 0 HcmV?d00001 diff --git a/test/integration/render-tests/fill-outline-color/fill/style.json b/test/integration/render-tests/fill-outline-color/fill/style.json new file mode 100644 index 00000000000..54d7eca3c48 --- /dev/null +++ b/test/integration/render-tests/fill-outline-color/fill/style.json @@ -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" + } + } + ] +} \ No newline at end of file