Webgl / add a fixed fragment shader builder for symbols

This commit is contained in:
Olivier Guyot
2019-09-24 15:49:07 +02:00
parent 4de0c0b082
commit a6b8d920b7
2 changed files with 50 additions and 2 deletions

View File

@@ -26,7 +26,7 @@ export function formatNumber(v) {
*/
/**
* Generates a symbol shader, i.e. a shader intended to be used on point geometries.
* Generates a symbol vertex shader, i.e. a shader intended to be used on point geometries.
*
* Expected the following attributes to be present in the attribute array:
* `vec2 a_position`, `float a_index` (being the index of the vertex in the quad, 0 to 3).
@@ -80,3 +80,31 @@ void main(void) {
return body;
}
/**
* Generates a symbol fragment shader, i.e. a shader intended to be used on point geometries.
*
* Expected the following varyings to be transmitted by the vertex shader:
* `vec2 v_texCoord`, `float v_opacity`, `vec4 v_color`
*
* @returns {string} The full shader as a string.
*/
export function getSymbolFragmentShader() {
const body = `precision mediump float;
uniform sampler2D u_texture;
varying vec2 v_texCoord;
varying float v_opacity;
varying vec4 v_color;
void main(void) {
if (v_opacity == 0.0) {
discard;
}
vec4 textureColor = texture2D(u_texture, v_texCoord);
gl_FragColor = v_color * textureColor;
gl_FragColor.a *= v_opacity;
gl_FragColor.rgb *= gl_FragColor.a;
}`;
return body;
}