diff --git a/src/ol/webgl/map.js b/src/ol/webgl/map.js index bdff207a7d..268410e617 100644 --- a/src/ol/webgl/map.js +++ b/src/ol/webgl/map.js @@ -41,49 +41,57 @@ ol.webgl.map.shader.Fragment = function() { goog.base(this, [ 'precision mediump float;', '', - 'uniform mat4 uMatrix;', 'uniform float uBrightness;', 'uniform float uContrast;', 'uniform float uHue;', 'uniform float uOpacity;', + 'uniform mat4 uMatrix;', 'uniform float uSaturation;', 'uniform sampler2D uTexture;', '', 'varying vec2 vTexCoord;', '', 'void main(void) {', + '', ' vec4 texCoord = uMatrix * vec4(vTexCoord, 0., 1.);', ' vec4 color = texture2D(uTexture, texCoord.st);', '', - ' float angle = uHue * 3.14159265;', - ' float s = sin(angle), c = cos(angle);', - ' vec3 weights = (vec3(2.0 * c, -sqrt(3.0) * s - c, sqrt(3.0) * s - c)', - ' + 1.0) / 3.0;', - ' float len = length(color.rgb);', - ' color.rgb = vec3(', - ' dot(color.rgb, weights.xyz),', - ' dot(color.rgb, weights.zxy),', - ' dot(color.rgb, weights.yzx)', - ' );', - ' ', - ' float average = (color.r + color.g + color.b) / 3.0;', - ' if (uSaturation > 0.0) {', - ' color.rgb += (average - color.rgb)', - ' * (1.0 - 1.0 / (1.001 - uSaturation));', - ' } else if (uSaturation < 0.0) {', - ' color.rgb += (average - color.rgb) * (-uSaturation);', + ' if (uHue != 0.) {', + ' float angle = uHue * 3.14159265;', + ' float s = sin(angle), c = cos(angle);', + ' vec3 weights = (vec3(2. * c, -sqrt(3.) * s - c, sqrt(3.) * s - c)', + ' + 1.) / 3.;', + ' color.rgb = vec3(', + ' dot(color.rgb, weights.xyz),', + ' dot(color.rgb, weights.zxy),', + ' dot(color.rgb, weights.yzx)', + ' );', + ' }', + '', + ' if (uSaturation != 0.) {', + ' float average = (color.r + color.g + color.b) / 3.0;', + ' if (uSaturation > 0.0) {', + ' color.rgb += (average - color.rgb)', + ' * (1. - 1. / (1. - uSaturation));', + ' } else {', + ' color.rgb += (average - color.rgb) * -uSaturation;', + ' }', ' }', '', ' color.rgb += uBrightness;', - ' if (uContrast > 0.0) {', - ' color.rgb = (color.rgb - 0.5) / (1.0 - uContrast) + 0.5;', - ' } else {', - ' color.rgb = (color.rgb - 0.5) * (1.0 + uContrast) + 0.5;', + '', + ' if (uContrast != 0.) {', + ' if (uContrast > 0.0) {', + ' color.rgb = (color.rgb - 0.5) / (1. - uContrast) + 0.5;', + ' } else {', + ' color.rgb = (color.rgb - 0.5) * (1. + uContrast) + 0.5;', + ' }', ' }', '', ' color.a = color.a * uOpacity;', '', ' gl_FragColor = color;', + '', '}' ].join('\n')); };