Skip to content

Commit

Permalink
Merge pull request #816 from OpenGeoscience/image-test-stability
Browse files Browse the repository at this point in the history
Modify the webgl line feature shaders.
  • Loading branch information
manthey authored May 15, 2018
2 parents 193c14d + 682fa56 commit 4879f75
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 29 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ sudo: required
dist: trusty

node_js:
- 6
- 8

addons:
firefox: latest # version 55.0 - 57.x have an issue with screenshots.
Expand Down Expand Up @@ -38,8 +38,9 @@ before_install:
# Start xvfb with a specific resolution and pixel depth
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x24"
- CACHE="${HOME}/cache" CMAKE_VERSION=3.5.0 CMAKE_SHORT_VERSION=3.5 source ./scripts/install_cmake.sh
- npm install -g npm@latest
- npm install -g node-pre-gyp
- npm prune
- npm install -g npm

before_script:
- export DISPLAY=:99.0
Expand Down
2 changes: 1 addition & 1 deletion docs/provisioning.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ onward. They assume a basic installation, as, for instance, from the

Add nodejs to the sources so it can be installed ::

wget -qO- https://deb.nodesource.com/setup_6.x | sudo bash -
wget -qO- https://deb.nodesource.com/setup_8.x | sudo bash -

Install required packages (you may want to also include cmake-curses-gui for
convenience in configuring CMake options) ::
Expand Down
41 changes: 26 additions & 15 deletions src/gl/lineFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,24 @@ var gl_lineFeature = function (arg) {
'const float PI = 3.14159265358979323846264;',

'vec4 viewCoord(vec3 c) {',
' vec4 result = projectionMatrix * modelViewMatrix * vec4(c.xyz, 1);',
' vec4 result = projectionMatrix * modelViewMatrix * vec4(c.xyz, 1.0);',
' if (result.w != 0.0) result = result / result.w;',
' return result;',
'}',

'float atan2(float y, float x) {',
' if (x > 0.0) return atan(y / x);',
' if (x < 0.0 && y >= 0.0) return atan(y / x) + PI;',
' if (x < 0.0) return atan(y / x) - PI;',
' return sign(y) * 0.5 * PI;',
'}',

'void main(void)',
'{',
/* If any vertex has been deliberately set to a negative opacity,
* skip doing computations on it. */
' if (strokeOpacity < 0.0) {',
' gl_Position = vec4(2, 2, 0, 1);',
' gl_Position = vec4(2.0, 2.0, 0.0, 1.0);',
' return;',
' }',
/* convert coordinates. We have four values, since we need to
Expand All @@ -133,10 +140,10 @@ var gl_lineFeature = function (arg) {
// calculate line segment vector and angle
' vec2 deltaCB = C.xy - B.xy;',
' if (deltaCB == vec2(0.0, 0.0)) {',
' gl_Position = vec4(2, 2, 0, 1);',
' gl_Position = vec4(2.0, 2.0, 0.0, 1.0);',
' return;',
' }',
' float angleCB = atan(deltaCB.y / aspect, deltaCB.x);',
' float angleCB = atan2(deltaCB.y, deltaCB.x * aspect);',
// values we need to pass along
' strokeColorVar = vec4(strokeColor, strokeOpacity);',
// extract values from our flags field
Expand Down Expand Up @@ -169,22 +176,22 @@ var gl_lineFeature = function (arg) {
// offset, then the functional join angle is not simply half the
// angle between the two lines, but rather half the angle of the
// inside edge of the the two lines.
' float cosABC, sinABC, cosBCD, sinBCD;', // of half angles
' float cosABC = 1.0, sinABC = 0.0, cosBCD = 1.0, sinBCD = 0.0;', // of half angles
// handle near end
' if (nearMode >= 4) {',
' float angleBA = atan((B.y - A.y) / aspect, B.x - A.x);',
' float angleBA = atan2(B.y - A.y, (B.x - A.x) * aspect);',
' if (A.xy == B.xy) angleBA = angleCB;',
' float angleABC = angleCB - angleBA;',
// ensure angle is in the range [-PI, PI], then take the half angle
' angleABC = (mod(angleABC + PI, 2.0 * PI) - PI) / 2.0;',
' angleABC = (mod(angleABC + 3.0 * PI, 2.0 * PI) - PI) / 2.0;',
' cosABC = cos(angleABC); sinABC = sin(angleABC);',
// if this angle is close to flat, pass-through the join
' if (nearMode >= 4 && cosABC > 0.999999) {',
' nearMode = 3;',
' }',
// miter, miter-clip
' if (nearMode == 4 || nearMode == 7) {',
' if (cosABC == 0.0 || 1.0 / cosABC > miterLimit) {',
' if (cosABC < 0.000001 || 1.0 / cosABC > miterLimit) {',
' if (nearMode == 4) {',
' nearMode = 5;',
' } else {',
Expand All @@ -205,19 +212,19 @@ var gl_lineFeature = function (arg) {

// handle far end
' if (farMode >= 4) {',
' float angleDC = atan((D.y - C.y) / aspect, D.x - C.x);',
' float angleDC = atan2(D.y - C.y, (D.x - C.x) * aspect);',
' if (D.xy == C.xy) angleDC = angleCB;',
' float angleBCD = angleDC - angleCB;',
// ensure angle is in the range [-PI, PI], then take the half angle
' angleBCD = (mod(angleBCD + PI, 2.0 * PI) - PI) / 2.0;',
' angleBCD = (mod(angleBCD + 3.0 * PI, 2.0 * PI) - PI) / 2.0;',
' cosBCD = cos(angleBCD); sinBCD = sin(angleBCD);',
// if this angle is close to flat, pass-through the join
' if (farMode >= 4 && cosBCD > 0.999999) {',
' farMode = 3;',
' }',
// miter, miter-clip
' if (farMode == 4 || farMode == 7) {',
' if (cosBCD == 0.0 || 1.0 / cosBCD > miterLimit) {',
' if (cosBCD < 0.000001 || 1.0 / cosBCD > miterLimit) {',
' if (farMode == 4) farMode = 5;',
' } else {',
' farMode = 4;',
Expand All @@ -231,7 +238,7 @@ var gl_lineFeature = function (arg) {
' gl_Position = vec4(',
' B.x + (xOffset * cos(angleCB) - yOffset * sin(angleCB)) * pixelWidth,',
' B.y + (xOffset * sin(angleCB) + yOffset * cos(angleCB)) * pixelWidth * aspect,',
' B.z, 1);',
' B.z, 1.0);',
// store other values needed to determine which pixels to plot.
' float lineLength = length(vec2(deltaCB.x, deltaCB.y / aspect)) / pixelWidth;',

Expand Down Expand Up @@ -262,7 +269,11 @@ var gl_lineFeature = function (arg) {
function createFragmentShader(allowDebug) {
var fragmentShaderSource = [
'#ifdef GL_ES',
' precision highp float;',
' #ifdef GL_FRAGMENT_PRECISION_HIGH',
' precision highp float;',
' #else',
' precision mediump float;',
' #endif',
'#endif',
'varying vec4 strokeColorVar;',
'varying vec4 subpos;',
Expand All @@ -275,8 +286,8 @@ var gl_lineFeature = function (arg) {
' vec4 color = strokeColorVar;',
allowDebug ? ' bool debug = bool(mod(fixedFlags, 2.0));' : '',
' float opacity = 1.0;',
' int nearMode = int(info.x);',
' int farMode = int(info.y);',
' int nearMode = int(floor(info.x + 0.5));',
' int farMode = int(floor(info.y + 0.5));',
' float cosABC = angles.x;',
' float sinABC = angles.y;',
' float cosBCD = angles.z;',
Expand Down
2 changes: 1 addition & 1 deletion testing/test-data/base-images.tgz.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2333a69e96ce063d10862bd8d563eb3d
24a2ffe0807138fe13c33ddeccb2b426
2 changes: 1 addition & 1 deletion testing/test-data/base-images.tgz.url
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://data.kitware.com/api/v1/file/5a9ed5838d777f0685786207/download
https://data.kitware.com/api/v1/file/5af1fcff8d777f0685797d19/download
4 changes: 1 addition & 3 deletions tests/gl-cases/glLines.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions tests/gl-cases/glPolygons.js
Original file line number Diff line number Diff line change
Expand Up @@ -2446,9 +2446,7 @@ describe('glPolygons', function () {
layer: layer
}).read(JSON.stringify(data), function () {
myMap.draw();
// maximum error is 0.0030 because of a change in Chrome 65. When new
// versions are released, see if this can be moved back to 0.0015
imageTest.imageTest('glMultiPolygons', null, 0.0030, done, myMap.onIdle, 0, 2);
imageTest.imageTest('glMultiPolygons', null, 0.0015, done, myMap.onIdle, 0, 2);
});
});

Expand Down
4 changes: 1 addition & 3 deletions tests/headed-cases/lines.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ describe('lines example', function () {
it('more lines', function (done) {
base$ = $('iframe#map')[0].contentWindow.jQuery;
base$('#lines').val(100000).trigger('change');
// maximum error is 0.0030 because of a change in Chrome 65. When new
// versions are released, see if this can be moved back to 0.0015
imageTest.imageTest('exampleLines100k', '#map', 0.0030, done, null, 0, 2, '#map.ready[segments="100000"]');
imageTest.imageTest('exampleLines100k', '#map', 0.0015, done, null, 0, 2, '#map.ready[segments="100000"]');
}, 10000);
it('thin preset', function (done) {
base$('button.preset').eq(1).trigger('click');
Expand Down

0 comments on commit 4879f75

Please sign in to comment.