Const fragmentShaderText
fragmentShaderText: "precision highp float;uniform vec2 dataResolution;uniform vec2 range;uniform sampler2D vectors;uniform sampler2D colorScale;uniform float colored;varying vec2 pctPos;void main(void) {vec4 color;vec4 vectorColor = texture2D(vectors, pctPos);if (vectorColor.a < 1.0)discard;float u = mix(range.x, range.y, vectorColor.r);float v = mix(range.x, range.y, vectorColor.g);float speedPct = length(vec2(u, v)) / length(range);if (colored == 1.0)color = texture2D(colorScale, vec2(speedPct, 0.5));elsecolor = vec4(1.0, 1.0, 1.0, 1.0);// todo: find a nice generic way to calculate opacity or make it configurable somehowfloat alpha = smoothstep(0.02, 0.30, speedPct) * 1.1;color.a = alpha;gl_FragColor = color;}" = `precision highp float;uniform vec2 dataResolution;uniform vec2 range;uniform sampler2D vectors;uniform sampler2D colorScale;uniform float colored;varying vec2 pctPos;void main(void) {vec4 color;vec4 vectorColor = texture2D(vectors, pctPos);if (vectorColor.a < 1.0)discard;float u = mix(range.x, range.y, vectorColor.r);float v = mix(range.x, range.y, vectorColor.g);float speedPct = length(vec2(u, v)) / length(range);if (colored == 1.0)color = texture2D(colorScale, vec2(speedPct, 0.5));elsecolor = vec4(1.0, 1.0, 1.0, 1.0);// todo: find a nice generic way to calculate opacity or make it configurable somehowfloat alpha = smoothstep(0.02, 0.30, speedPct) * 1.1;color.a = alpha;gl_FragColor = color;}`
Const vertexShaderText
vertexShaderText: "precision highp float;attribute float particleIndex;varying vec2 pctPos;uniform vec4 extent;uniform vec2 delta;uniform float particlesRes;uniform sampler2D particles;uniform vec2 v0;uniform vec2 v1;uniform vec2 v2;const float RADIUS = 6378137.0;const float PI = 3.1415926535897932384626433832795;const float HALF_SIZE = PI * RADIUS;vec2 fromLonLat(const float lon, const float lat) {float x = HALF_SIZE * lon / 180.0;float y = RADIUS * log(tan(PI * (lat + 90.0) / 360.0));if (y > HALF_SIZE) {y = HALF_SIZE;}else if (y < -HALF_SIZE) {y = -HALF_SIZE;}return vec2(x, y);}void main(void) {vec4 color = texture2D(particles, vec2(fract(particleIndex / particlesRes),floor(particleIndex / particlesRes) / particlesRes));pctPos = vec2(color.r / 255.0 + color.b,color.g / 255.0 + color.a);vec2 particleCoords = vec2(mix(v0.x, v1.x, color.r / 255.0 + color.b),mix(v0.y, v2.y, color.g / 255.0 + color.a));vec2 posInMeters = fromLonLat(particleCoords.x, particleCoords.y);gl_Position = vec4(((posInMeters.x-extent.x) / delta.x) * 2.0 - 1.0,((posInMeters.y-extent.w) / delta.y) * -2.0 + 1.0,0.0, 1.0);gl_PointSize = 1.15;}" = `precision highp float;attribute float particleIndex;varying vec2 pctPos;uniform vec4 extent;uniform vec2 delta;uniform float particlesRes;uniform sampler2D particles;uniform vec2 v0;uniform vec2 v1;uniform vec2 v2;const float RADIUS = 6378137.0;const float PI = 3.1415926535897932384626433832795;const float HALF_SIZE = PI * RADIUS;vec2 fromLonLat(const float lon, const float lat) {float x = HALF_SIZE * lon / 180.0;float y = RADIUS * log(tan(PI * (lat + 90.0) / 360.0));if (y > HALF_SIZE) {y = HALF_SIZE;}else if (y < -HALF_SIZE) {y = -HALF_SIZE;}return vec2(x, y);}void main(void) {vec4 color = texture2D(particles, vec2(fract(particleIndex / particlesRes),floor(particleIndex / particlesRes) / particlesRes));pctPos = vec2(color.r / 255.0 + color.b,color.g / 255.0 + color.a);vec2 particleCoords = vec2(mix(v0.x, v1.x, color.r / 255.0 + color.b),mix(v0.y, v2.y, color.g / 255.0 + color.a));vec2 posInMeters = fromLonLat(particleCoords.x, particleCoords.y);gl_Position = vec4(((posInMeters.x-extent.x) / delta.x) * 2.0 - 1.0,((posInMeters.y-extent.w) / delta.y) * -2.0 + 1.0,0.0, 1.0);gl_PointSize = 1.15;}`