Webgl renderer / fix existing examples

The shaders were rewritten manually for those, althoughj eventually they
should use the shader builder utilities as well.
This commit is contained in:
Olivier Guyot
2019-09-25 10:36:40 +02:00
parent 2b36445ecc
commit 109f9718f9
4 changed files with 136 additions and 68 deletions
+22 -14
View File
@@ -177,38 +177,47 @@ class Heatmap extends VectorLayer {
*/
createRenderer() {
return new WebGLPointsLayerRenderer(this, {
attributes: [
{
name: 'weight',
callback: this.weightFunction_
}
],
vertexShader: `
precision mediump float;
attribute vec2 a_position;
attribute vec2 a_texCoord;
attribute vec2 a_offsets;
attribute float a_opacity;
uniform mat4 u_projectionMatrix;
uniform mat4 u_offsetScaleMatrix;
uniform float u_size;
attribute vec2 a_position;
attribute float a_index;
attribute float a_weight;
varying vec2 v_texCoord;
varying float v_opacity;
varying float v_weight;
void main(void) {
vec4 offsets = u_offsetScaleMatrix * vec4(a_offsets, 0.0, 0.0);
gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0) + offsets * u_size;
v_texCoord = a_texCoord;
v_opacity = a_opacity;
mat4 offsetMatrix = u_offsetScaleMatrix;
float offsetX = a_index == 0.0 || a_index == 3.0 ? -u_size / 2.0 : u_size / 2.0;
float offsetY = a_index == 0.0 || a_index == 1.0 ? -u_size / 2.0 : u_size / 2.0;
vec4 offsets = offsetMatrix * vec4(offsetX, offsetY, 0.0, 0.0);
gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0) + offsets;
float u = a_index == 0.0 || a_index == 3.0 ? 0.0 : 1.0;
float v = a_index == 0.0 || a_index == 1.0 ? 0.0 : 1.0;
v_texCoord = vec2(u, v);
v_weight = a_weight;
}`,
fragmentShader: `
precision mediump float;
uniform float u_blurSlope;
varying vec2 v_texCoord;
varying float v_opacity;
varying float v_weight;
void main(void) {
vec2 texCoord = v_texCoord * 2.0 - vec2(1.0, 1.0);
float sqRadius = texCoord.x * texCoord.x + texCoord.y * texCoord.y;
float value = (1.0 - sqrt(sqRadius)) * u_blurSlope;
float alpha = smoothstep(0.0, 1.0, value) * v_opacity;
float alpha = smoothstep(0.0, 1.0, value) * v_weight;
gl_FragColor = vec4(alpha, alpha, alpha, alpha);
}`,
uniforms: {
@@ -239,8 +248,7 @@ class Heatmap extends VectorLayer {
u_gradientTexture: this.gradient_
}
}
],
opacityCallback: this.weightFunction_
]
});
}
}